Skip to content

Commit

Permalink
add seeds checks for asset metadata (#78)
Browse files Browse the repository at this point in the history
* add seeds checks to mip-1 endpoints

* add seeds checks to rest of the handlers
  • Loading branch information
Samuel Vanderwaal authored Jan 3, 2024
1 parent 982e00f commit d22346f
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 4 deletions.
10 changes: 9 additions & 1 deletion programs/mmm/src/instructions/mip1/mip1_deposit_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ pub struct Mip1DepositSell<'info> {
)]
pub pool: Box<Account<'info, Pool>>,
/// CHECK: we will check the metadata in check_allowlists_for_mint(), also checked in cpi
#[account(mut)]
#[account(mut,
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidMip1AssetParams,
Expand Down
10 changes: 9 additions & 1 deletion programs/mmm/src/instructions/mip1/mip1_withdraw_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ pub struct Mip1WithdrawSell<'info> {
/// CHECK: will be checked in cpi
asset_master_edition: UncheckedAccount<'info>,
/// CHECK: will be checked in cpi
#[account(mut)]
#[account(mut,
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
#[account(
init_if_needed,
Expand Down
10 changes: 9 additions & 1 deletion programs/mmm/src/instructions/mip1/sol_mip1_fulfill_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ pub struct SolMip1FulfillBuy<'info> {
)]
pub buyside_sol_escrow_account: UncheckedAccount<'info>,
/// CHECK: we will check the metadata in check_allowlists_for_mint()
#[account(mut)]
#[account(mut,
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidMip1AssetParams,
Expand Down
10 changes: 9 additions & 1 deletion programs/mmm/src/instructions/mip1/sol_mip1_fulfill_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ pub struct SolMip1FulfillSell<'info> {
)]
pub buyside_sol_escrow_account: AccountInfo<'info>,
/// CHECK: we will check the metadata in check_allowlists_for_mint()
#[account(mut)]
#[account(mut,
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidMip1AssetParams,
Expand Down
9 changes: 9 additions & 0 deletions programs/mmm/src/instructions/ocp/ocp_deposit_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ pub struct OcpDepositSell<'info> {
)]
pub pool: Box<Account<'info, Pool>>,
/// CHECK: we will check the metadata in check_allowlists_for_mint()
#[account(
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidOcpAssetParams,
Expand Down
9 changes: 9 additions & 0 deletions programs/mmm/src/instructions/ocp/ocp_withdraw_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ pub struct OcpWithdrawSell<'info> {
)]
pub asset_mint: Account<'info, Mint>,
/// CHECK: will be checked in cpi
#[account(
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
/// CHECK: checked in init_if_needed_ocp_ata
#[account(mut)]
Expand Down
9 changes: 9 additions & 0 deletions programs/mmm/src/instructions/ocp/sol_ocp_fulfill_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ pub struct SolOcpFulfillBuy<'info> {
)]
pub buyside_sol_escrow_account: UncheckedAccount<'info>,
/// CHECK: we will check the metadata in check_allowlists_for_mint()
#[account(
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidOcpAssetParams,
Expand Down
9 changes: 9 additions & 0 deletions programs/mmm/src/instructions/ocp/sol_ocp_fulfill_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ pub struct SolOcpFulfillSell<'info> {
)]
pub buyside_sol_escrow_account: AccountInfo<'info>,
/// CHECK: we will check the metadata in check_allowlists_for_mint()
#[account(
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
#[account(
constraint = asset_mint.supply == 1 && asset_mint.decimals == 0 @ MMMErrorCode::InvalidOcpAssetParams,
Expand Down
9 changes: 9 additions & 0 deletions programs/mmm/src/instructions/vanilla/deposit_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ pub struct DepositSell<'info> {
)]
pub pool: Box<Account<'info, Pool>>,
/// CHECK: we will check the metadata in check_allowlists_for_mint()
#[account(
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
/// CHECK: we will check the master_edition in check_allowlists_for_mint()
pub asset_master_edition: UncheckedAccount<'info>,
Expand Down
9 changes: 9 additions & 0 deletions programs/mmm/src/instructions/vanilla/sol_fulfill_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ pub struct SolFulfillBuy<'info> {
)]
pub buyside_sol_escrow_account: UncheckedAccount<'info>,
/// CHECK: we will check the metadata in check_allowlists_for_mint()
#[account(
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
/// CHECK: we will check the master_edtion in check_allowlists_for_mint()
pub asset_master_edition: UncheckedAccount<'info>,
Expand Down
9 changes: 9 additions & 0 deletions programs/mmm/src/instructions/vanilla/sol_fulfill_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ pub struct SolFulfillSell<'info> {
)]
pub buyside_sol_escrow_account: AccountInfo<'info>,
/// CHECK: we will check the metadata in check_allowlists_for_mint()
#[account(
seeds = [
"metadata".as_bytes(),
mpl_token_metadata::ID.as_ref(),
asset_mint.key().as_ref(),
],
bump,
seeds::program = mpl_token_metadata::ID,
)]
pub asset_metadata: UncheckedAccount<'info>,
/// CHECK: we will check the master_edtion in check_allowlists_for_mint()
pub asset_master_edition: UncheckedAccount<'info>,
Expand Down

0 comments on commit d22346f

Please sign in to comment.