Skip to content

Commit

Permalink
remove payment mint enforcement from close pool endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
madergaser committed Jul 3, 2024
1 parent 5131044 commit dba4a9d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
2 changes: 1 addition & 1 deletion programs/mmm/src/instructions/admin/sol_close_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
82 changes: 82 additions & 0 deletions tests/mmm-admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
AllowlistKind,
getMMMPoolPDA,
MMMProgramID,
getMMMBuysideSolEscrowPDA,
} from '../sdk/src';
import { airdrop, getEmptyAllowLists } from './utils';

Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions tests/mmm-fulfill-exp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ describe('mmm-fulfill-exp', () => {
) as anchor.Program<Mmm>;
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',
Expand Down Expand Up @@ -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([
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/mmm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,9 @@ export async function createPoolWithExampleDepositsUmi(
tokenProgramId: PublicKey,
nftRecipient: PublicKey,
): Promise<PoolData> {
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);

Expand Down

0 comments on commit dba4a9d

Please sign in to comment.