From 282c394666a389ba9e086f974db39de7a6194028 Mon Sep 17 00:00:00 2001 From: Pierre Date: Mon, 25 Apr 2022 19:39:35 +0200 Subject: [PATCH] feat: add sync native to anchor_spl::token (#1833) --- CHANGELOG.md | 1 + spl/src/token.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fa71f4d2..a4b34138d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The minor version will be incremented upon a breaking change and the patch versi * cli: `build` now adds docs to idl. This can be turned off with `--no-docs` ([#1561](https://github.com/project-serum/anchor/pull/1561)). * lang: Add `PartialEq` and `Eq` for `anchor_lang::Error` ([#1544](https://github.com/project-serum/anchor/pull/1544)). * cli: Add `b` and `t` aliases for `build` and `test` respectively ([#1823](https://github.com/project-serum/anchor/pull/1823)). +* spl: Add `sync_native` token program CPI wrapper function ([#1833](https://github.com/project-serum/anchor/pull/1833)). ### Fixes diff --git a/spl/src/token.rs b/spl/src/token.rs index 8520d3e9d..abbd5ce0b 100644 --- a/spl/src/token.rs +++ b/spl/src/token.rs @@ -258,6 +258,14 @@ pub fn set_authority<'a, 'b, 'c, 'info>( .map_err(Into::into) } +pub fn sync_native<'a, 'b, 'c, 'info>( + ctx: CpiContext<'a, 'b, 'c, 'info, SyncNative<'info>>, +) -> Result<()> { + let ix = spl_token::instruction::sync_native(&spl_token::ID, ctx.accounts.account.key)?; + solana_program::program::invoke_signed(&ix, &[ctx.accounts.account.clone()], ctx.signer_seeds) + .map_err(Into::into) +} + #[derive(Accounts)] pub struct Transfer<'info> { pub from: AccountInfo<'info>, @@ -333,6 +341,11 @@ pub struct SetAuthority<'info> { pub account_or_mint: AccountInfo<'info>, } +#[derive(Accounts)] +pub struct SyncNative<'info> { + pub account: AccountInfo<'info>, +} + #[derive(Clone, Debug, Default, PartialEq)] pub struct TokenAccount(spl_token::state::Account);