diff --git a/programs/mmm/src/instructions/cnft/cnft_deposit_sell.rs b/programs/mmm/src/instructions/cnft/cnft_deposit_sell.rs new file mode 100644 index 0000000..237d02c --- /dev/null +++ b/programs/mmm/src/instructions/cnft/cnft_deposit_sell.rs @@ -0,0 +1,77 @@ +use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize}; + +use crate::{ + constants::*, + errors::MMMErrorCode, + state::{Pool, SellState}, + util::{check_allowlists_for_mint, log_pool}, +}; + +#[derive(AnchorSerialize, AnchorDeserialize)] +pub struct CnftDepositSellArgs { + pub asset_amount: u64, + pub allowlist_aux: Option, // TODO: use it for future allowlist_aux +} + +#[derive(Accounts)] +#[instruction(args:CnftDepositSellArgs)] +pub struct CnftDepositSell<'info> { + #[account(mut)] + pub owner: Signer<'info>, + #[account(constraint = owner.key() != cosigner.key() @ MMMErrorCode::InvalidCosigner)] + pub cosigner: Signer<'info>, + #[account( + mut, + seeds = [POOL_PREFIX.as_bytes(), owner.key().as_ref(), pool.uuid.as_ref()], + has_one = owner @ MMMErrorCode::InvalidOwner, + has_one = cosigner @ MMMErrorCode::InvalidCosigner, + bump + )] + pub pool: Box>, + + // TODO: Add CNFT specific accounts + pub sell_state: Account<'info, SellState>, + /// CHECK: will be used for allowlist checks + pub allowlist_aux_account: UncheckedAccount<'info>, + pub system_program: Program<'info, System>, + pub rent: Sysvar<'info, Rent>, +} + +pub fn handler(ctx: Context, args: CnftDepositSellArgs) -> Result<()> { + let owner = &ctx.accounts.owner; + let pool = &mut ctx.accounts.pool; + let sell_state = &mut ctx.accounts.sell_state; + + if pool.using_shared_escrow() { + return Err(MMMErrorCode::InvalidAccountState.into()); + } + + // Need to do check allowlist against cnft metadata args + // check_allowlists_for_mint( + // &pool.allowlists, + // asset_mint, + // asset_metadata, + // Some(asset_master_edition), + // args.allowlist_aux, + // )?; + + // Do Cnft transfer logic here + + pool.sellside_asset_amount = pool + .sellside_asset_amount + .checked_add(args.asset_amount) + .ok_or(MMMErrorCode::NumericOverflow)?; + + 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.cosigner_annotation = pool.cosigner_annotation; + sell_state.asset_amount = sell_state + .asset_amount + .checked_add(args.asset_amount) + .ok_or(MMMErrorCode::NumericOverflow)?; + log_pool("post_cnft_deposit_sell", pool)?; + + Ok(()) +} diff --git a/programs/mmm/src/instructions/cnft/mod.rs b/programs/mmm/src/instructions/cnft/mod.rs new file mode 100644 index 0000000..3adb846 --- /dev/null +++ b/programs/mmm/src/instructions/cnft/mod.rs @@ -0,0 +1,3 @@ +pub mod cnft_deposit_sell; + +pub use cnft_deposit_sell::*; \ No newline at end of file diff --git a/programs/mmm/src/instructions/mod.rs b/programs/mmm/src/instructions/mod.rs index a12cc04..f6157d7 100644 --- a/programs/mmm/src/instructions/mod.rs +++ b/programs/mmm/src/instructions/mod.rs @@ -6,6 +6,7 @@ pub mod mip1; pub mod mpl_core_asset; pub mod ocp; pub mod vanilla; +pub mod cnft; pub use admin::*; pub use ext_vanilla::*; @@ -13,6 +14,7 @@ pub use mip1::*; pub use mpl_core_asset::*; pub use ocp::*; pub use vanilla::*; +pub use cnft::*; use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize}; diff --git a/programs/mmm/src/lib.rs b/programs/mmm/src/lib.rs index f750238..3a9cc27 100644 --- a/programs/mmm/src/lib.rs +++ b/programs/mmm/src/lib.rs @@ -181,4 +181,11 @@ pub mod mmm { ) -> Result<()> { instructions::sol_mpl_core_fulfill_buy::handler(ctx, args) } + + pub fn cnft_deposit_sell<'info>( + ctx: Context<'_, '_, '_, 'info, CnftDepositSell<'info>>, + args: CnftDepositSellArgs, + ) -> Result<()> { + instructions::cnft_deposit_sell::handler(ctx, args) + } }