Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyLi28 committed Apr 25, 2024
1 parent 755fc22 commit c53c0a9
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ use crate::{
errors::MMMErrorCode,
state::{Pool, SellState},
util::{check_allowlists_for_mpl_core, log_pool},
AssetInterface, DepositSellArgs, IndexableAsset,
AssetInterface, IndexableAsset,
};

#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct MplCoreDepositSellArgs {
pub allowlist_aux: Option<String>,
}

#[derive(Accounts)]
#[instruction(args:DepositSellArgs)]
#[instruction(args:MplCoreDepositSellArgs)]
pub struct MplCoreDepositSell<'info> {
#[account(mut)]
pub owner: Signer<'info>,
Expand Down Expand Up @@ -49,7 +54,7 @@ pub struct MplCoreDepositSell<'info> {
pub asset_program: Interface<'info, AssetInterface>,
}

pub fn handler(ctx: Context<MplCoreDepositSell>, args: DepositSellArgs) -> Result<()> {
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;
Expand Down Expand Up @@ -91,7 +96,7 @@ pub fn handler(ctx: Context<MplCoreDepositSell>, args: DepositSellArgs) -> Resul

pool.sellside_asset_amount = pool
.sellside_asset_amount
.checked_add(args.asset_amount)
.checked_add(1)
.ok_or(MMMErrorCode::NumericOverflow)?;

sell_state.pool = pool.key();
Expand All @@ -100,7 +105,7 @@ pub fn handler(ctx: Context<MplCoreDepositSell>, args: DepositSellArgs) -> Resul
sell_state.cosigner_annotation = pool.cosigner_annotation;
sell_state.asset_amount = sell_state
.asset_amount
.checked_add(args.asset_amount)
.checked_add(1)
.ok_or(MMMErrorCode::NumericOverflow)?;
log_pool("post_mpl_core_deposit_sell", pool)?;

Expand Down
2 changes: 1 addition & 1 deletion programs/mmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub mod mmm {

pub fn mpl_core_deposit_sell(
ctx: Context<MplCoreDepositSell>,
args: DepositSellArgs,
args: MplCoreDepositSellArgs,
) -> Result<()> {
instructions::mpl_core_deposit_sell::handler(ctx, args)
}
Expand Down
5 changes: 2 additions & 3 deletions programs/mmm/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ pub const ALLOWLIST_KIND_MINT: u8 = 2;
pub const ALLOWLIST_KIND_MCC: u8 = 3;
pub const ALLOWLIST_KIND_METADATA: u8 = 4;
pub const ALLOWLIST_KIND_GROUP: u8 = 5;
// this is should only be used by mpl core with update_authority as collection.
pub const ALLOWLIST_KIND_UPDATE_AUTHORITY: u8 = 6;
pub const ALLOWLIST_KIND_MPL_CORE_COLLECTION: u8 = 6;
// ANY nft will pass the allowlist check, please make sure to use cosigner to check NFT validity
pub const ALLOWLIST_KIND_ANY: u8 = u8::MAX;

Expand All @@ -33,7 +32,7 @@ impl Allowlist {
// kind == 7,8,... will be supported in the future
// kind == 255: any
pub fn valid(&self) -> bool {
if self.kind > ALLOWLIST_KIND_UPDATE_AUTHORITY && self.kind != ALLOWLIST_KIND_ANY {
if self.kind > ALLOWLIST_KIND_MPL_CORE_COLLECTION && self.kind != ALLOWLIST_KIND_ANY {
return false;
}
if self.kind != 0 && self.kind != ALLOWLIST_KIND_ANY {
Expand Down
11 changes: 3 additions & 8 deletions programs/mmm/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,9 @@ pub fn check_allowlists_for_mint_ext(
Err(MMMErrorCode::InvalidAllowLists.into())
}

pub fn check_allowlists_for_mpl_core<'info>(
pub fn check_allowlists_for_mpl_core(
allowlists: &[Allowlist],
asset: &Box<Account<'info, IndexableAsset>>,
asset: &IndexableAsset,
allowlist_aux: Option<String>,
) -> Result<()> {
if allowlists
Expand Down Expand Up @@ -817,7 +817,7 @@ pub fn check_allowlists_for_mpl_core<'info>(
// any is a special case, we don't need to check anything else
return Ok(());
}
ALLOWLIST_KIND_UPDATE_AUTHORITY => {
ALLOWLIST_KIND_MPL_CORE_COLLECTION => {
if let UpdateAuthority::Collection(collection_address) = asset.update_authority {
if collection_address != allowlist_val.value {
return Err(MMMErrorCode::InvalidAllowLists.into());
Expand All @@ -827,11 +827,6 @@ pub fn check_allowlists_for_mpl_core<'info>(
return Err(MMMErrorCode::InvalidAllowLists.into());
}
}
ALLOWLIST_KIND_MINT => {
if asset.key() != allowlist_val.value {
return Err(MMMErrorCode::InvalidAllowLists.into());
}
}
ALLOWLIST_KIND_METADATA => {
// Do not validate URI here, as we already did it above.
// These checks are separate since allowlist values are unioned together.
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export enum AllowlistKind {
mcc = 3,
metadata = 4,
group = 5,
update_authority = 6,
mpl_core_collection = 6,
any = 255,
}

Expand Down
32 changes: 30 additions & 2 deletions sdk/src/idl/mmm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ export type Mmm = {
{
"name": "args",
"type": {
"defined": "DepositSellArgs"
"defined": "MplCoreDepositSellArgs"
}
}
]
Expand Down Expand Up @@ -2289,6 +2289,20 @@ export type Mmm = {
]
}
},
{
"name": "MplCoreDepositSellArgs",
"type": {
"kind": "struct",
"fields": [
{
"name": "allowlistAux",
"type": {
"option": "string"
}
}
]
}
},
{
"name": "SolOcpFulfillSellArgs",
"type": {
Expand Down Expand Up @@ -4588,7 +4602,7 @@ export const IDL: Mmm = {
{
"name": "args",
"type": {
"defined": "DepositSellArgs"
"defined": "MplCoreDepositSellArgs"
}
}
]
Expand Down Expand Up @@ -4920,6 +4934,20 @@ export const IDL: Mmm = {
]
}
},
{
"name": "MplCoreDepositSellArgs",
"type": {
"kind": "struct",
"fields": [
{
"name": "allowlistAux",
"type": {
"option": "string"
}
}
]
}
},
{
"name": "SolOcpFulfillSellArgs",
"type": {
Expand Down
33 changes: 19 additions & 14 deletions sdk/src/mmmClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,20 +702,25 @@ export class MMMClient {
const asset = deserializeAssetV1(
convertAccountInfoToRpcAccount(assetMint, mintOrCoreAsset),
);
builder = this.program.methods.mplCoreDepositSell(args).accountsStrict({
owner: this.poolData.owner,
cosigner: this.poolData.cosigner,
pool: this.poolData.pool,
asset: assetMint,
sellState: getMMMSellStatePDA(
MMMProgramID,
this.poolData.pool,
assetMint,
).key,
collection: collectionAddress(asset) || PublicKey.default,
systemProgram: SystemProgram.programId,
assetProgram: MPL_CORE_PROGRAM_ID,
});
const mplCoreArgs = {
allowlistAux: args.allowlistAux,
} as anchor.IdlTypes<Mmm>['MplCoreDepositSellArgs'];
builder = this.program.methods
.mplCoreDepositSell(mplCoreArgs)
.accountsStrict({
owner: this.poolData.owner,
cosigner: this.poolData.cosigner,
pool: this.poolData.pool,
asset: assetMint,
sellState: getMMMSellStatePDA(
MMMProgramID,
this.poolData.pool,
assetMint,
).key,
collection: collectionAddress(asset) || PublicKey.default,
systemProgram: SystemProgram.programId,
assetProgram: MPL_CORE_PROGRAM_ID,
});

return await builder.instruction();
}
Expand Down
7 changes: 2 additions & 5 deletions tests/mmm-mpl-core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('mmm-mpl-core', () => {
const allowlists = [
{
value: toWeb3JsPublicKey(collection!.publicKey),
kind: AllowlistKind.update_authority,
kind: AllowlistKind.mpl_core_collection,
},
...getEmptyAllowLists(5),
];
Expand All @@ -68,7 +68,6 @@ describe('mmm-mpl-core', () => {

await program.methods
.mplCoreDepositSell({
assetAmount: new anchor.BN(1),
allowlistAux: null,
})
.accountsStrict({
Expand Down Expand Up @@ -119,7 +118,7 @@ describe('mmm-mpl-core', () => {
allowlists: [
{
value: Keypair.generate().publicKey, // different collection
kind: AllowlistKind.update_authority,
kind: AllowlistKind.mpl_core_collection,
},
...getEmptyAllowLists(5),
],
Expand All @@ -134,7 +133,6 @@ describe('mmm-mpl-core', () => {
try {
await program.methods
.mplCoreDepositSell({
assetAmount: new anchor.BN(1),
allowlistAux: null,
})
.accountsStrict({
Expand Down Expand Up @@ -191,7 +189,6 @@ describe('mmm-mpl-core', () => {
try {
await program.methods
.mplCoreDepositSell({
assetAmount: new anchor.BN(1),
allowlistAux: null,
})
.accountsStrict({
Expand Down

0 comments on commit c53c0a9

Please sign in to comment.