From 21869c208d9d6366989180c95ce246b4ccec0bb9 Mon Sep 17 00:00:00 2001 From: armaniferrante Date: Fri, 9 Apr 2021 23:00:59 -0700 Subject: [PATCH 1/2] spl: Add token initialize_account instruction --- spl/src/token.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spl/src/token.rs b/spl/src/token.rs index 643eb7fdef..e4d768d106 100644 --- a/spl/src/token.rs +++ b/spl/src/token.rs @@ -104,6 +104,27 @@ pub fn approve<'a, 'b, 'c, 'info>( ) } +pub fn initialize_account<'a, 'b, 'c, 'info>( + ctx: CpiContext<'a, 'b, 'c, 'info, InitializeAccount<'info>>, +) -> ProgramResult { + let ix = spl_token::instruction::initialize_account( + &spl_token::ID, + ctx.accounts.account.key, + ctx.accounts.mint.key, + ctx.accounts.authority.key, + )?; + solana_program::program::invoke_signed( + &ix, + &[ + ctx.accounts.account.clone(), + ctx.accounts.mint.clone(), + ctx.accounts.authority.clone(), + ctx.program.clone(), + ], + ctx.signer_seeds, + ) +} + #[derive(Accounts)] pub struct Transfer<'info> { pub from: AccountInfo<'info>, @@ -132,6 +153,13 @@ pub struct Approve<'info> { pub authority: AccountInfo<'info>, } +#[derive(Accounts)] +pub struct InitializeAccount<'info> { + pub account: AccountInfo<'info>, + pub mint: AccountInfo<'info>, + pub authority: AccountInfo<'info>, +} + #[derive(Clone)] pub struct TokenAccount(spl_token::state::Account); From 3e43b621bcc249f28384faae89496df3fed0d34b Mon Sep 17 00:00:00 2001 From: armaniferrante Date: Fri, 9 Apr 2021 23:02:09 -0700 Subject: [PATCH 2/2] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 442f0e3ec0..0422edecf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ incremented for features. ## Features * cli: Fund Anchor.toml configured wallet when testing ([#164](https://github.com/project-serum/anchor/pull/164)). +* spl: Add initialize_account instruction for spl tokens ([#166](https://github.com/project-serum/anchor/pull/166)). ## [0.4.1] - 2021-04-06