Browse Source

feat: add sync native to anchor_spl::token (#1833)

Pierre 3 years ago
parent
commit
282c394666
2 changed files with 14 additions and 0 deletions
  1. 1 0
      CHANGELOG.md
  2. 13 0
      spl/src/token.rs

+ 1 - 0
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
 

+ 13 - 0
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);