瀏覽代碼

spl: add feature memo to support cpi to spl-memo (#2661)

0xWoo 2 年之前
父節點
當前提交
23eeb1ec2d
共有 5 個文件被更改,包括 37 次插入0 次删除
  1. 1 0
      CHANGELOG.md
  2. 1 0
      Cargo.lock
  3. 2 0
      spl/Cargo.toml
  4. 3 0
      spl/src/lib.rs
  5. 30 0
      spl/src/memo.rs

+ 1 - 0
CHANGELOG.md

@@ -32,6 +32,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - lang: Add support for type aliases in IDLs ([#2637](https://github.com/coral-xyz/anchor/pull/2637)).
 - cli: Add `test.upgradeable`, `test.genesis.upgradeable` setting in anchor.toml to support testing upgradeable programs ([#2641](https://github.com/coral-xyz/anchor/pull/2642)).
 - cli, client, lang, spl: Update Solana toolchain and dependencies to `1.17.0`, `1.16` remains supported ([#2645](https://github.com/coral-xyz/anchor/pull/2645)).
+- spl: Add support for memo program ([#2660](https://github.com/coral-xyz/anchor/issues/2660)).
 
 ### Fixes
 

+ 1 - 0
Cargo.lock

@@ -290,6 +290,7 @@ dependencies = [
  "serum_dex",
  "solana-program",
  "spl-associated-token-account",
+ "spl-memo",
  "spl-token 4.0.0",
  "spl-token-2022",
 ]

+ 2 - 0
spl/Cargo.toml

@@ -20,6 +20,7 @@ shmem = []
 stake = ["borsh"]
 token = ["spl-token"]
 token_2022 = ["spl-token-2022"]
+memo = ["spl-memo"]
 
 [dependencies]
 anchor-lang = { path = "../lang", version = "0.28.0", features = ["derive"] }
@@ -30,3 +31,4 @@ solana-program = ">=1.16, <1.18"
 spl-associated-token-account = { version = "2.2", features = ["no-entrypoint"], optional = true }
 spl-token = { version = "4", features = ["no-entrypoint"], optional = true }
 spl-token-2022 = { version = "0.9", features = ["no-entrypoint"], optional = true }
+spl-memo = { version = "4", features = ["no-entrypoint"], optional = true }

+ 3 - 0
spl/src/lib.rs

@@ -27,3 +27,6 @@ pub mod stake;
 
 #[cfg(feature = "metadata")]
 pub mod metadata;
+
+#[cfg(feature = "memo")]
+pub mod memo;

+ 30 - 0
spl/src/memo.rs

@@ -0,0 +1,30 @@
+use anchor_lang::solana_program::pubkey::Pubkey;
+use anchor_lang::Result;
+use anchor_lang::{context::CpiContext, Accounts};
+
+pub use spl_memo;
+pub use spl_memo::ID;
+
+pub fn build_memo<'info>(ctx: CpiContext<'_, '_, '_, 'info, BuildMemo>, memo: &[u8]) -> Result<()> {
+    let ix = spl_memo::build_memo(
+        memo,
+        &ctx.remaining_accounts
+            .iter()
+            .map(|account| account.key)
+            .collect::<Vec<_>>(),
+    );
+    solana_program::program::invoke_signed(&ix, &ctx.remaining_accounts, ctx.signer_seeds)
+        .map_err(Into::into)
+}
+
+#[derive(Accounts)]
+pub struct BuildMemo {}
+
+#[derive(Clone)]
+pub struct Memo;
+
+impl anchor_lang::Id for Memo {
+    fn id() -> Pubkey {
+        ID
+    }
+}