From dba4a9dd41975a208517d28af879250242597120 Mon Sep 17 00:00:00 2001 From: Erik Yu Date: Wed, 3 Jul 2024 10:49:52 -0500 Subject: [PATCH] remove payment mint enforcement from close pool endpoint --- .../src/instructions/admin/sol_close_pool.rs | 2 +- tests/mmm-admin.spec.ts | 82 +++++++++++++++++++ tests/mmm-fulfill-exp.spec.ts | 10 +-- tests/utils/mmm.ts | 6 +- 4 files changed, 91 insertions(+), 9 deletions(-) diff --git a/programs/mmm/src/instructions/admin/sol_close_pool.rs b/programs/mmm/src/instructions/admin/sol_close_pool.rs index e6fb96a..716cb87 100644 --- a/programs/mmm/src/instructions/admin/sol_close_pool.rs +++ b/programs/mmm/src/instructions/admin/sol_close_pool.rs @@ -8,8 +8,8 @@ pub struct SolClosePool<'info> { #[account( mut, seeds = [POOL_PREFIX.as_bytes(), owner.key().as_ref(), pool.uuid.as_ref()], - constraint = pool.payment_mint.eq(&Pubkey::default()) @ MMMErrorCode::InvalidPaymentMint, constraint = pool.sellside_asset_amount == 0 @ MMMErrorCode::NotEmptySellsideAssetAmount, + constraint = pool.buyside_payment_amount == 0 @ MMMErrorCode::NotEmptyEscrowAccount, bump, has_one = owner @ MMMErrorCode::InvalidOwner, has_one = cosigner @ MMMErrorCode::InvalidCosigner, diff --git a/tests/mmm-admin.spec.ts b/tests/mmm-admin.spec.ts index 337f6ff..3cae26b 100644 --- a/tests/mmm-admin.spec.ts +++ b/tests/mmm-admin.spec.ts @@ -14,6 +14,7 @@ import { AllowlistKind, getMMMPoolPDA, MMMProgramID, + getMMMBuysideSolEscrowPDA, } from '../sdk/src'; import { airdrop, getEmptyAllowLists } from './utils'; @@ -241,6 +242,87 @@ describe('mmm-admin', () => { }); }); + describe('Can close pool', () => { + it('happy path', async () => { + const referral = Keypair.generate(); + const uuid = Keypair.generate(); + const { key: poolKey } = getMMMPoolPDA( + program.programId, + wallet.publicKey, + uuid.publicKey, + ); + + const createPoolArgs = { + spotPrice: new anchor.BN(1 * LAMPORTS_PER_SOL), + curveType: CurveKind.linear, + curveDelta: new anchor.BN(0), + reinvestFulfillBuy: true, + reinvestFulfillSell: true, + expiry: new anchor.BN(42), + lpFeeBp: 200, + referral: referral.publicKey, + cosignerAnnotation: new Array(32).fill(0), + buysideCreatorRoyaltyBp: 0, + + uuid: uuid.publicKey, + paymentMint: PublicKey.default, + allowlists: getEmptyAllowLists(6), + }; + + const closeAndCheckPool = async () => { + assert.isNotNull(await program.account.pool.fetchNullable(poolKey)); + const { key: buysideSolEscrowAccount } = getMMMBuysideSolEscrowPDA( + MMMProgramID, + poolKey, + ); + await program.methods + .solClosePool() + .accountsStrict({ + pool: poolKey, + owner: wallet.publicKey, + systemProgram: SystemProgram.programId, + buysideSolEscrowAccount, + cosigner: cosigner.publicKey, + }) + .signers([cosigner]) + .rpc(); + assert.isNull(await program.account.pool.fetchNullable(poolKey)); + }; + + await program.methods + .createPool({ + ...createPoolArgs, + }) + .accountsStrict({ + owner: wallet.publicKey, + cosigner: cosigner.publicKey, + pool: poolKey, + systemProgram: SystemProgram.programId, + }) + .signers([cosigner]) + .rpc(); + + await closeAndCheckPool(); + + // create pool again, but payment mint is not default + await program.methods + .createPool({ + ...createPoolArgs, + paymentMint: Keypair.generate().publicKey, + }) + .accountsStrict({ + owner: wallet.publicKey, + cosigner: cosigner.publicKey, + pool: poolKey, + systemProgram: SystemProgram.programId, + }) + .signers([cosigner]) + .rpc(); + + await closeAndCheckPool(); + }); + }); + describe('Can update allowlists', () => { it('happy path', async () => { // Ensure cosigner is the only signer of the transaction. diff --git a/tests/mmm-fulfill-exp.spec.ts b/tests/mmm-fulfill-exp.spec.ts index dcead34..3caf421 100644 --- a/tests/mmm-fulfill-exp.spec.ts +++ b/tests/mmm-fulfill-exp.spec.ts @@ -55,16 +55,16 @@ describe('mmm-fulfill-exp', () => { ) as anchor.Program; const cosigner = Keypair.generate(); - beforeEach(async () => { + before(async () => { await airdrop(connection, wallet.publicKey, 50); }); // Run our tests for both Tokenkeg and Token2022. TOKEN_PROGRAM_IDS.forEach((tokenProgramId) => { it(`Sellside only ${tokenProgramId}`, async () => { - const umi = (await createUmi('http://127.0.0.1:8899')).use( - mplTokenMetadata(), - ); + const umi = ( + await createUmi('http://127.0.0.1:8899', { commitment: 'processed' }) + ).use(mplTokenMetadata()); const token2022Program: UmiProgram = { name: 'splToken2022', @@ -977,7 +977,7 @@ describe('mmm-fulfill-exp', () => { ); }); - it('Two sides', async () => { + it(`Two sides ${tokenProgramId}`, async () => { const seller = Keypair.generate(); const buyer = Keypair.generate(); const [poolData] = await Promise.all([ diff --git a/tests/utils/mmm.ts b/tests/utils/mmm.ts index 4e0b168..d62419a 100644 --- a/tests/utils/mmm.ts +++ b/tests/utils/mmm.ts @@ -761,9 +761,9 @@ export async function createPoolWithExampleDepositsUmi( tokenProgramId: PublicKey, nftRecipient: PublicKey, ): Promise { - const umi = (await createUmi('http://127.0.0.1:8899')).use( - mplTokenMetadata(), - ); + const umi = ( + await createUmi('http://127.0.0.1:8899', { commitment: 'processed' }) + ).use(mplTokenMetadata()); const creator = generateSigner(umi);