From be2e4271a600dbca6c9d467a32e6234f73173bf8 Mon Sep 17 00:00:00 2001 From: Samuel Vanderwaal Date: Sun, 26 Jan 2025 11:42:40 -0500 Subject: [PATCH 1/3] enforce pool starting price in edit --- program/idl.json | 5 +++++ program/src/instructions/create_pool.rs | 5 ----- program/src/state/mod.rs | 1 + program/src/state/pool.rs | 4 ++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/program/idl.json b/program/idl.json index 0ad6c847..2ee4d469 100644 --- a/program/idl.json +++ b/program/idl.json @@ -19,6 +19,11 @@ "name": "MAX_DELTA_BPS", "type": "u16", "value": "9999" + }, + { + "name": "MAX_EXPIRY_SEC", + "type": "i64", + "value": "365 * 24 * 60 * 60" } ], "instructions": [ diff --git a/program/src/instructions/create_pool.rs b/program/src/instructions/create_pool.rs index 0fcbdac9..3bb5d251 100644 --- a/program/src/instructions/create_pool.rs +++ b/program/src/instructions/create_pool.rs @@ -1,7 +1,6 @@ //! Create a new pool. use anchor_lang::prelude::*; use escrow_program::state::MarginAccount; -use tensor_vipers::throw_err; use whitelist_program::{self, WhitelistV2}; use crate::{ @@ -79,10 +78,6 @@ impl<'info> CreatePool<'info> { /// Create a new pool. #[access_control(ctx.accounts.validate(args.config))] pub fn process_create_pool(ctx: Context, args: CreatePoolArgs) -> Result<()> { - if args.config.starting_price < 1 { - throw_err!(ErrorCode::StartingPriceTooSmall); - } - let timestamp = Clock::get()?.unix_timestamp; let expiry = assert_expiry(args.expire_in_sec.unwrap_or(MAX_EXPIRY_SEC as u64))?; diff --git a/program/src/state/mod.rs b/program/src/state/mod.rs index 56b6b0e0..127e676b 100644 --- a/program/src/state/mod.rs +++ b/program/src/state/mod.rs @@ -14,6 +14,7 @@ use mpl_token_metadata::types::{AuthorizationData, Payload, PayloadType, ProofIn use std::collections::HashMap; /// Maximum expiration time for a pool--one year. +#[constant] pub const MAX_EXPIRY_SEC: i64 = 365 * 24 * 60 * 60; // --------------------------------------- replicating mplex type for anchor IDL export diff --git a/program/src/state/pool.rs b/program/src/state/pool.rs index 20173eff..a6c332a8 100644 --- a/program/src/state/pool.rs +++ b/program/src/state/pool.rs @@ -57,6 +57,10 @@ pub struct PoolConfig { impl PoolConfig { pub fn validate(&self) -> Result<()> { + if self.starting_price < 1 { + throw_err!(ErrorCode::StartingPriceTooSmall); + } + match self.pool_type { PoolType::NFT | PoolType::Token => { if self.mm_fee_bps > 0 { From 7114a35353895e6aa310378a823d2bd8215e9d01 Mon Sep 17 00:00:00 2001 From: Samuel Vanderwaal Date: Sun, 26 Jan 2025 11:44:43 -0500 Subject: [PATCH 2/3] patch bump program version --- Cargo.lock | 2 +- program/Cargo.toml | 2 +- program/idl.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7bde614..971763c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ dependencies = [ [[package]] name = "amm-program" -version = "1.0.0" +version = "1.0.1" dependencies = [ "anchor-lang", "anchor-spl", diff --git a/program/Cargo.toml b/program/Cargo.toml index dc4320fc..c0a2fe2b 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "amm-program" -version = "1.0.0" +version = "1.0.1" edition = "2021" readme = "./README.md" license-file = "../LICENSE" diff --git a/program/idl.json b/program/idl.json index 2ee4d469..d4fa34e2 100644 --- a/program/idl.json +++ b/program/idl.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.0.1", "name": "amm_program", "docs": [ "Program entrypoint" From 5d49786ffce778fce87938822f6418f583784636 Mon Sep 17 00:00:00 2001 From: Samuel Vanderwaal Date: Thu, 13 Feb 2025 07:54:27 -0900 Subject: [PATCH 3/3] remove unused function --- program/src/instructions/mod.rs | 30 +----------------------------- scripts/generate-idls.mjs | 2 +- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/program/src/instructions/mod.rs b/program/src/instructions/mod.rs index 7fe08a6e..246df7e3 100644 --- a/program/src/instructions/mod.rs +++ b/program/src/instructions/mod.rs @@ -12,7 +12,6 @@ pub mod t22; pub mod withdraw_sol; pub use admin::*; -use anchor_spl::token::Mint; pub use close_expired_pool::*; pub use close_pool::*; pub use create_pool::*; @@ -28,37 +27,10 @@ use crate::{error::ErrorCode, *}; use anchor_lang::prelude::*; use solana_program::pubkey; use tensor_vipers::throw_err; -use whitelist_program::{self, MintProof, MintProofV2, Whitelist, WhitelistV2}; +use whitelist_program::{self, MintProofV2, WhitelistV2}; pub static MPL_TOKEN_AUTH_RULES_ID: Pubkey = pubkey!("auth9SigNpDKz4sJJ1DfCTuZrZNSAgh9sFD3rboVmgg"); -#[inline(never)] -pub fn assert_decode_mint_proof( - whitelist: &Account, - nft_mint: &InterfaceAccount, - mint_proof: &UncheckedAccount, -) -> Result> { - let (key, _) = Pubkey::find_program_address( - &[ - b"mint_proof".as_ref(), - nft_mint.key().as_ref(), - whitelist.key().as_ref(), - ], - &whitelist_program::ID, - ); - if key != *mint_proof.key { - throw_err!(ErrorCode::BadMintProof); - } - // Check program owner (redundant because of find_program_address above, but why not). - if *mint_proof.owner != whitelist_program::ID { - throw_err!(ErrorCode::BadMintProof); - } - - let mut data: &[u8] = &mint_proof.try_borrow_data()?; - let mint_proof: Box = Box::new(AccountDeserialize::try_deserialize(&mut data)?); - Ok(mint_proof) -} - #[inline(never)] pub fn assert_decode_mint_proof_v2( whitelist: &Account, diff --git a/scripts/generate-idls.mjs b/scripts/generate-idls.mjs index 2d6e7fe7..12d7685d 100644 --- a/scripts/generate-idls.mjs +++ b/scripts/generate-idls.mjs @@ -1,6 +1,6 @@ #!/usr/bin/env zx -import "zx/globals"; import { generateIdl } from "@metaplex-foundation/shank-js"; +import "zx/globals"; import { getCargo, getProgramFolders } from "./utils.mjs"; const binaryInstallDir = path.join(__dirname, "..", ".cargo");