Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove payment mint enforcement from close pool endpoint #101

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
86 changes: 86 additions & 0 deletions tests/mmm-admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
AllowlistKind,
getMMMPoolPDA,
MMMProgramID,
getMMMBuysideSolEscrowPDA,
} from '../sdk/src';
import { airdrop, getEmptyAllowLists } from './utils';

Expand Down Expand Up @@ -235,6 +236,91 @@ 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 () => {
await expect(
program.account.pool.fetchNullable(poolKey),
).resolves.not.toBeNull();
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();
await expect(
program.account.pool.fetchNullable(poolKey),
).resolves.toBeNull();
};

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 () => {
beforeAll(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
Loading