-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * deposit sell contract change * add sdk support * format * add tests * remove only * add missing metadata allowlist * format * address comments
- Loading branch information
1 parent
a9302c1
commit 33c5fc3
Showing
19 changed files
with
864 additions
and
7 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#![allow(missing_docs)] | ||
|
||
pub mod mpl_core_deposit_sell; | ||
pub mod mpl_core_wrap; | ||
|
||
pub use mpl_core_deposit_sell::*; | ||
pub use mpl_core_wrap::*; |
113 changes: 113 additions & 0 deletions
113
programs/mmm/src/instructions/mpl_core_asset/mpl_core_deposit_sell.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use anchor_lang::prelude::*; | ||
use mpl_core::instructions::TransferV1Builder; | ||
use mpl_core::types::UpdateAuthority; | ||
use solana_program::program::invoke; | ||
|
||
use crate::{ | ||
constants::*, | ||
errors::MMMErrorCode, | ||
state::{Pool, SellState}, | ||
util::{check_allowlists_for_mpl_core, log_pool}, | ||
AssetInterface, IndexableAsset, | ||
}; | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize)] | ||
pub struct MplCoreDepositSellArgs { | ||
pub allowlist_aux: Option<String>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(args:MplCoreDepositSellArgs)] | ||
pub struct MplCoreDepositSell<'info> { | ||
#[account(mut)] | ||
pub owner: Signer<'info>, | ||
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<Account<'info, Pool>>, | ||
#[account( | ||
mut, | ||
constraint = asset.to_account_info().owner == asset_program.key, | ||
)] | ||
pub asset: Box<Account<'info, IndexableAsset>>, | ||
#[account( | ||
init_if_needed, | ||
payer = owner, | ||
seeds = [ | ||
SELL_STATE_PREFIX.as_bytes(), | ||
pool.key().as_ref(), | ||
asset.key().as_ref(), | ||
], | ||
space = SellState::LEN, | ||
bump | ||
)] | ||
pub sell_state: Account<'info, SellState>, | ||
/// CHECK: check collection later | ||
collection: UncheckedAccount<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
pub asset_program: Interface<'info, AssetInterface>, | ||
} | ||
|
||
pub fn handler(ctx: Context<MplCoreDepositSell>, args: MplCoreDepositSellArgs) -> Result<()> { | ||
let owner = &ctx.accounts.owner; | ||
let asset = &ctx.accounts.asset; | ||
let pool = &mut ctx.accounts.pool; | ||
let sell_state = &mut ctx.accounts.sell_state; | ||
let collection = &ctx.accounts.collection; | ||
|
||
if pool.using_shared_escrow() { | ||
return Err(MMMErrorCode::InvalidAccountState.into()); | ||
} | ||
|
||
let _ = check_allowlists_for_mpl_core(&pool.allowlists, asset, args.allowlist_aux)?; | ||
|
||
let transfer_asset_builder = TransferV1Builder::new() | ||
.asset(asset.key()) | ||
.payer(owner.key()) | ||
.collection( | ||
if let UpdateAuthority::Collection(collection_address) = asset.update_authority { | ||
Some(collection_address) | ||
} else { | ||
None | ||
}, | ||
) | ||
.new_owner(pool.key()) | ||
.instruction(); | ||
|
||
let mut account_infos = vec![ | ||
asset.to_account_info(), | ||
owner.to_account_info(), | ||
pool.to_account_info(), | ||
]; | ||
if collection.key != &Pubkey::default() { | ||
if UpdateAuthority::Collection(collection.key()) != asset.update_authority { | ||
return Err(MMMErrorCode::InvalidAssetCollection.into()); | ||
} | ||
account_infos.push(collection.to_account_info()); | ||
} | ||
|
||
invoke(&transfer_asset_builder, account_infos.as_slice())?; | ||
|
||
pool.sellside_asset_amount = pool | ||
.sellside_asset_amount | ||
.checked_add(1) | ||
.ok_or(MMMErrorCode::NumericOverflow)?; | ||
|
||
sell_state.pool = pool.key(); | ||
sell_state.pool_owner = owner.key(); | ||
sell_state.asset_mint = asset.key(); | ||
sell_state.cosigner_annotation = pool.cosigner_annotation; | ||
sell_state.asset_amount = sell_state | ||
.asset_amount | ||
.checked_add(1) | ||
.ok_or(MMMErrorCode::NumericOverflow)?; | ||
log_pool("post_mpl_core_deposit_sell", pool)?; | ||
|
||
Ok(()) | ||
} |
39 changes: 39 additions & 0 deletions
39
programs/mmm/src/instructions/mpl_core_asset/mpl_core_wrap.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use mpl_core::ID; | ||
use solana_program::pubkey::Pubkey; | ||
use std::ops::Deref; | ||
|
||
#[derive(Clone)] | ||
pub struct AssetInterface; | ||
|
||
impl anchor_lang::Ids for AssetInterface { | ||
fn ids() -> &'static [Pubkey] { | ||
&[ID] | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct IndexableAsset(mpl_core::IndexableAsset); | ||
|
||
impl anchor_lang::AccountDeserialize for IndexableAsset { | ||
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> { | ||
mpl_core::IndexableAsset::fetch(mpl_core::types::Key::AssetV1, buf) | ||
.map(IndexableAsset) | ||
.map_err(Into::into) | ||
} | ||
} | ||
|
||
impl anchor_lang::AccountSerialize for IndexableAsset {} | ||
|
||
impl anchor_lang::Owner for IndexableAsset { | ||
fn owner() -> Pubkey { | ||
ID | ||
} | ||
} | ||
|
||
impl Deref for IndexableAsset { | ||
type Target = mpl_core::IndexableAsset; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ export enum AllowlistKind { | |
mcc = 3, | ||
metadata = 4, | ||
group = 5, | ||
mpl_core_collection = 6, | ||
any = 255, | ||
} | ||
|
||
|
Oops, something went wrong.