From 69e7209c7524cc86008698900fecb97c3e66f3ef Mon Sep 17 00:00:00 2001 From: Code Cowboy <40577281+C-o-d-e-C-o-w-b-o-y@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:42:32 +0800 Subject: [PATCH] Update max LP fee to 20% (#89) --- programs/mmm/src/constants.rs | 2 +- programs/mmm/src/errors.rs | 2 +- .../mmm/src/instructions/admin/create_pool.rs | 2 +- .../mmm/src/instructions/admin/update_pool.rs | 2 +- sdk/src/idl/mmm.ts | 4 +- tests/mmm-admin.spec.ts | 51 +++++++++++++++++++ 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/programs/mmm/src/constants.rs b/programs/mmm/src/constants.rs index ae9b919..b3654fa 100644 --- a/programs/mmm/src/constants.rs +++ b/programs/mmm/src/constants.rs @@ -7,7 +7,7 @@ pub const SELL_STATE_PREFIX: &str = "mmm_sell_state"; pub const MAX_TOTAL_PRICE: u64 = 8_000_000 * 1_000_000_000; // 8_000_000 SOL pub const MAX_METADATA_CREATOR_ROYALTY_BP: u16 = 3000; pub const MAX_REFERRAL_FEE_BP: i16 = 500; -pub const MAX_LP_FEE_BP: u16 = 1000; +pub const MAX_LP_FEE_BP: u16 = 2_000; pub const ALLOWLIST_MAX_LEN: usize = 6; pub const MIN_SOL_ESCROW_BALANCE_BP: u16 = 100; diff --git a/programs/mmm/src/errors.rs b/programs/mmm/src/errors.rs index 56c1ac0..f4dea86 100644 --- a/programs/mmm/src/errors.rs +++ b/programs/mmm/src/errors.rs @@ -2,7 +2,7 @@ use anchor_lang::prelude::*; #[error_code] pub enum MMMErrorCode { - #[msg("lp fee bp must be between 0 and 10000")] + #[msg("lp fee bp must be between 0 and 2000")] InvalidLPFee, // 0x1770 #[msg("invalid allowlists")] InvalidAllowLists, // 0x1771 diff --git a/programs/mmm/src/instructions/admin/create_pool.rs b/programs/mmm/src/instructions/admin/create_pool.rs index c06d68f..bf594c8 100644 --- a/programs/mmm/src/instructions/admin/create_pool.rs +++ b/programs/mmm/src/instructions/admin/create_pool.rs @@ -33,7 +33,7 @@ pub struct CreatePool<'info> { seeds = [POOL_PREFIX.as_bytes(), owner.key().as_ref(), args.uuid.as_ref()], bump, space = Pool::LEN, - constraint = args.lp_fee_bp <= MAX_LP_FEE_BP @ MMMErrorCode::InvalidBP, + constraint = args.lp_fee_bp <= MAX_LP_FEE_BP @ MMMErrorCode::InvalidLPFee, constraint = args.buyside_creator_royalty_bp <= 10000 @ MMMErrorCode::InvalidBP, constraint = args.spot_price > 0 @ MMMErrorCode::InvalidSpotPrice, constraint = pool.payment_mint.eq(&Pubkey::default()) @ MMMErrorCode::InvalidPaymentMint, // remove this when we have spl token support diff --git a/programs/mmm/src/instructions/admin/update_pool.rs b/programs/mmm/src/instructions/admin/update_pool.rs index a936fd5..3bf09e7 100644 --- a/programs/mmm/src/instructions/admin/update_pool.rs +++ b/programs/mmm/src/instructions/admin/update_pool.rs @@ -27,7 +27,7 @@ pub struct UpdatePool<'info> { bump, has_one = owner @ MMMErrorCode::InvalidOwner, has_one = cosigner @ MMMErrorCode::InvalidCosigner, - constraint = args.lp_fee_bp <= MAX_LP_FEE_BP @ MMMErrorCode::InvalidBP, + constraint = args.lp_fee_bp <= MAX_LP_FEE_BP @ MMMErrorCode::InvalidLPFee, constraint = args.buyside_creator_royalty_bp <= 10000 @ MMMErrorCode::InvalidBP, constraint = args.spot_price > 0 @ MMMErrorCode::InvalidSpotPrice, constraint = args.referral.ne(owner.key) @ MMMErrorCode::InvalidReferral, diff --git a/sdk/src/idl/mmm.ts b/sdk/src/idl/mmm.ts index 89e04b2..e91e7c6 100644 --- a/sdk/src/idl/mmm.ts +++ b/sdk/src/idl/mmm.ts @@ -2411,7 +2411,7 @@ export type Mmm = { { "code": 6000, "name": "InvalidLPFee", - "msg": "lp fee bp must be between 0 and 10000" + "msg": "lp fee bp must be between 0 and 2000" }, { "code": 6001, @@ -4984,7 +4984,7 @@ export const IDL: Mmm = { { "code": 6000, "name": "InvalidLPFee", - "msg": "lp fee bp must be between 0 and 10000" + "msg": "lp fee bp must be between 0 and 2000" }, { "code": 6001, diff --git a/tests/mmm-admin.spec.ts b/tests/mmm-admin.spec.ts index 03e8166..337f6ff 100644 --- a/tests/mmm-admin.spec.ts +++ b/tests/mmm-admin.spec.ts @@ -101,6 +101,57 @@ describe('mmm-admin', () => { assert.deepEqual(poolAccountInfo.paymentMint, PublicKey.default); assert.deepEqual(poolAccountInfo.allowlists, allowlists); }); + + it('lp fee cannot be too large', async () => { + const referral = Keypair.generate(); + const uuid = Keypair.generate(); + const { key: poolKey } = getMMMPoolPDA( + program.programId, + wallet.publicKey, + uuid.publicKey, + ); + const allowlists = [ + { kind: AllowlistKind.fvca, value: referral.publicKey }, + { kind: AllowlistKind.mint, value: cosigner.publicKey }, + { kind: AllowlistKind.mcc, value: wallet.publicKey }, + ...getEmptyAllowLists(3), + ]; + + try { + await program.methods + .createPool({ + 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: 2_001, + referral: referral.publicKey, + cosignerAnnotation: new Array(32).fill(0), + buysideCreatorRoyaltyBp: 0, + + uuid: uuid.publicKey, + paymentMint: PublicKey.default, + allowlists, + }) + .accountsStrict({ + owner: wallet.publicKey, + cosigner: cosigner.publicKey, + pool: poolKey, + systemProgram: SystemProgram.programId, + }) + .signers([cosigner]) + .rpc(); + + assert.ok(false, 'Should have thrown error'); + } catch (e) { + // Should be an AnchorError and force convert the type. + expect(e).to.be.instanceOf(AnchorError); + const err = e as AnchorError; + assert.strictEqual(err.error.errorCode.number, 6000); + } + }); }); describe('Can update sol mmm', () => {