Created
February 1, 2023 19:12
-
-
Save orangemio/335303264e3fda61f3ea9ca96c576d88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anchor_lang::prelude::*; | |
use anchor_spl::token::{self, Mint, Token, TokenAccount}; | |
use mpl_token_metadata::state::{Metadata, PREFIX}; | |
use solana_program::msg; | |
declare_id!("7MtivSEXSi7gKjGYvrLd4cLQhkT381P17BJnufzPEzfA"); | |
#[program] | |
pub mod sol_nft_wallet { | |
use super::*; | |
pub fn depositNFT(ctx: Context<DepositNFT>) -> Result<()> { | |
let sender = &ctx.accounts.sender; | |
let sender_token = &ctx.accounts.sender_token; | |
let receiver = &ctx.accounts.receiver; | |
let token_program = &ctx.accounts.token_program; | |
let metadata: Metadata = | |
Metadata::from_account_info(&ctx.accounts.nft_metadata.to_account_info())?; | |
msg!("Instruction: Metadata -> {}", &metadata.collection[key]); | |
token::transfer( | |
CpiContext::new( | |
token_program.to_account_info(), | |
token::Transfer { | |
from: sender_token.to_account_info(), | |
to: receiver.to_account_info(), | |
authority: sender.to_account_info(), | |
}, | |
), | |
1, | |
); | |
return Ok(()); | |
} | |
} | |
#[derive(Accounts)] | |
pub struct DepositNFT<'info> { | |
#[account(mut)] | |
pub sender: Signer<'info>, | |
#[account(mut)] | |
pub sender_token: Account<'info, TokenAccount>, | |
#[account( | |
constraint = nft_mint.supply == 1, | |
constraint = nft_mint.decimals == 0 | |
)] | |
pub nft_mint: Box<Account<'info, Mint>>, | |
/// CHECK: This is not dangerous because we don't read or write from this account | |
#[account( | |
seeds = [PREFIX.as_bytes(), mpl_token_metadata::ID.as_ref(), nft_mint.key().as_ref()], | |
seeds::program = mpl_token_metadata::ID, | |
bump | |
)] | |
pub nft_metadata: AccountInfo<'info>, | |
#[account(mut)] | |
pub receiver: AccountInfo<'info>, | |
#[account(address = token::ID)] | |
pub token_program: Program<'info, Token>, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment