Skip to content

Commit

Permalink
Update max LP fee to 20% (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
C-o-d-e-C-o-w-b-o-y authored Mar 28, 2024
1 parent 5fd1531 commit 69e7209
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion programs/mmm/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion programs/mmm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion programs/mmm/src/instructions/admin/create_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion programs/mmm/src/instructions/admin/update_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/idl/mmm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
51 changes: 51 additions & 0 deletions tests/mmm-admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 69e7209

Please sign in to comment.