Skip to content

Commit

Permalink
deposit sell without metadata check
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyLi28 committed Oct 16, 2024
1 parent 3237ae7 commit dad57f8
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions programs/mmm/src/instructions/cnft/cnft_deposit_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ use crate::{

#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct CnftDepositSellArgs {
// === cNFT transfer args === //
// The Merkle root for the tree. Can be retrieved from off-chain data store.
root: [u8; 32],
// The Keccak256 hash of the NFTs existing metadata (without the verified flag for the creator changed).
// The metadata is retrieved from off-chain data store.
data_hash: [u8; 32],
// The Keccak256 hash of the NFTs existing creators array (without the verified flag for the creator changed).
// The creators array is retrieved from off-chain data store.
creator_hash: [u8; 32],
// A nonce ("number used once") value used to make the Merkle tree leaves unique.
// This is the value of num_minted for the tree stored in the TreeConfig account at the time the NFT was minted.
// The unique value for each asset can be retrieved from off-chain data store.
nonce: u64,
// The index of the leaf in the merkle tree. Can be retrieved from off-chain store.
index: u32,
// === Contract args === //
// Price of the NFT in the payment_mint.
buyer_price: u64,
// The mint of the SPL token used to pay for the NFT, currently not used and default to SOL.
payment_mint: Pubkey,
// The asset amount to deposit, default to 1.
pub asset_amount: u64,
pub allowlist_aux: Option<String>, // TODO: use it for future allowlist_aux
}
Expand All @@ -29,7 +50,30 @@ pub struct CnftDepositSell<'info> {
)]
pub pool: Box<Account<'info, Pool>>,

// TODO: Add CNFT specific accounts
// ==== cNFT transfer args ==== //
#[account(
mut,
seeds = [merkle_tree.key().as_ref()],
seeds::program = bubblegum_program.key(),
bump,
)]
/// CHECK: This account is neither written to nor read from.
pub tree_authority: Account<'info, TreeConfigAnchor>,
// The NFT delegate. Transfers must be signed by either the NFT owner or NFT delegate.
/// CHECK: This account is checked in the Bubblegum transfer instruction
leaf_delegate: UncheckedAccount<'info>,
// The account that contains the Merkle tree, initialized by create_tree.
/// CHECK: This account is modified in the downstream Bubblegum program
#[account(mut)]
merkle_tree: UncheckedAccount<'info>,
// Used by bubblegum for logging (CPI)
log_wrapper: Program<'info, Noop>,

bubblegum_program: Program<'info, BubblegumProgram>,

// The Solana Program Library spl-account-compression program ID.
compression_program: Program<'info, SplAccountCompression>,

pub sell_state: Account<'info, SellState>,
/// CHECK: will be used for allowlist checks
pub allowlist_aux_account: UncheckedAccount<'info>,
Expand All @@ -41,11 +85,14 @@ pub fn handler(ctx: Context<CnftDepositSell>, args: CnftDepositSellArgs) -> Resu
let owner = &ctx.accounts.owner;
let pool = &mut ctx.accounts.pool;
let sell_state = &mut ctx.accounts.sell_state;
let merkle_tree = &ctx.accounts.merkle_tree.clone();

if pool.using_shared_escrow() {
return Err(MMMErrorCode::InvalidAccountState.into());
}

let asset_id = get_asset_id(&merkle_tree.key(), args.nonce);

// Need to do check allowlist against cnft metadata args
// check_allowlists_for_mint(
// &pool.allowlists,
Expand All @@ -56,6 +103,28 @@ pub fn handler(ctx: Context<CnftDepositSell>, args: CnftDepositSellArgs) -> Resu
// )?;

// Do Cnft transfer logic here
msg!(
"Transferring asset to: {}",
ctx.accounts.program_as_signer.key
);
transfer_compressed_nft(
&ctx.accounts.tree_authority.to_account_info(),
&wallet.to_account_info(),
&ctx.accounts.leaf_delegate.to_account_info(), // delegate
&ctx.accounts.program_as_signer.to_account_info(),
&ctx.accounts.merkle_tree,
&ctx.accounts.log_wrapper,
&ctx.accounts.compression_program,
&ctx.accounts.system_program,
ctx.remaining_accounts,
ctx.accounts.bubblegum_program.key(),
args.root,
args.data_hash,
args.creator_hash,
args.nonce,
args.index,
None, // signer passed through from ctx
)?;

pool.sellside_asset_amount = pool
.sellside_asset_amount
Expand All @@ -65,7 +134,7 @@ pub fn handler(ctx: Context<CnftDepositSell>, args: CnftDepositSellArgs) -> Resu
sell_state.pool = pool.key();
sell_state.pool_owner = owner.key();
// TODO: asset_mint can be get from tree.
// sell_state.asset_mint = asset_mint.key();
sell_state.asset_mint = asset_id;
sell_state.cosigner_annotation = pool.cosigner_annotation;
sell_state.asset_amount = sell_state
.asset_amount
Expand Down

0 comments on commit dad57f8

Please sign in to comment.