Skip to content

Commit

Permalink
remove rent account and move constraints to fix stack issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Vanderwaal committed Feb 19, 2024
1 parent 2e762b4 commit 33cb6ed
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
2 changes: 0 additions & 2 deletions programs/mmm/src/ata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ pub fn init_if_needed_ata<'a>(
associated_token: AccountInfo<'a>,
token_program: AccountInfo<'a>,
system_program: AccountInfo<'a>,
rent: AccountInfo<'a>,
) -> Result<spl_token_2022::state::Account> {
let token_program_id = token_program.key();

Expand All @@ -87,7 +86,6 @@ pub fn init_if_needed_ata<'a>(
mint.to_account_info(),
associated_token,
system_program,
rent,
token_program,
],
)?;
Expand Down
23 changes: 16 additions & 7 deletions programs/mmm/src/instructions/mip1/sol_mip1_fulfill_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,17 @@ pub struct SolMip1FulfillBuy<'info> {
/// CHECK: checked by address and in CPI
#[account(address = mpl_token_metadata::ID)]
pub token_metadata_program: UncheckedAccount<'info>,
/// CHECK: checked by address and in cpi
#[account(address = MPL_TOKEN_AUTH_RULES)]
/// CHECK: checked by address in handler and in cpi
/// Address constraint not used here because of stack issues.
pub authorization_rules_program: UncheckedAccount<'info>,
/// CHECK: will be checked in cpi
pub authorization_rules: UncheckedAccount<'info>,
/// CHECK: will be checked in cpi
#[account(address = sysvar::instructions::id())]
/// CHECK: checked by address in handler and in cpi
/// Address constraint not used here because of stack issues.
pub instructions: UncheckedAccount<'info>,
pub system_program: Program<'info, System>,
pub token_program: Interface<'info, TokenInterface>,
pub associated_token_program: Program<'info, AssociatedToken>,
pub rent: Sysvar<'info, Rent>,
// Remaining accounts
// Branch: using shared escrow accounts
// 0: m2_program
Expand Down Expand Up @@ -171,13 +170,24 @@ pub fn handler<'info>(
let pool_token_record = &ctx.accounts.pool_token_record;
let pool_owner_token_record = &ctx.accounts.pool_owner_token_record;
let instructions = &ctx.accounts.instructions;

// Check moved here to avoid stack frame limit issues.
if *instructions.key != sysvar::instructions::id() {
return Err(ProgramError::IncorrectProgramId.into());
}

let associated_token_program = &ctx.accounts.associated_token_program;
let authorization_rules = &ctx.accounts.authorization_rules;
let authorization_rules_program = &ctx.accounts.authorization_rules_program;

// Check moved here to avoid stack frame limit issues.
if *authorization_rules_program.key != MPL_TOKEN_AUTH_RULES {
return Err(ProgramError::IncorrectProgramId.into());
}

let token_metadata_program_ai = &ctx.accounts.token_metadata_program.to_account_info();
let remaining_accounts = ctx.remaining_accounts;

let rent = &ctx.accounts.rent;
let pool_key = pool.key();
let pool_uuid = pool.uuid;
let buyside_sol_escrow_account_seeds: &[&[&[u8]]] = &[&[
Expand Down Expand Up @@ -309,7 +319,6 @@ pub fn handler<'info>(
associated_token_program.to_account_info(),
token_program.to_account_info(),
system_program.to_account_info(),
rent.to_account_info(),
)?;

let payload = Payload {
Expand Down
3 changes: 0 additions & 3 deletions programs/mmm/src/instructions/vanilla/sol_fulfill_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ pub fn handler<'info>(
let token_program = &ctx.accounts.token_program;
let system_program = &ctx.accounts.system_program;
let associated_token_program = &ctx.accounts.associated_token_program;
let rent = &ctx.accounts.rent;
let pool = &mut ctx.accounts.pool;
let sell_state = &mut ctx.accounts.sell_state;
let owner = &ctx.accounts.owner;
Expand Down Expand Up @@ -217,7 +216,6 @@ pub fn handler<'info>(
associated_token_program.to_account_info(),
token_program.to_account_info(),
system_program.to_account_info(),
rent.to_account_info(),
)?;
let sellside_escrow_token_account =
ctx.accounts.sellside_escrow_token_account.to_account_info();
Expand Down Expand Up @@ -256,7 +254,6 @@ pub fn handler<'info>(
associated_token_program.to_account_info(),
token_program.to_account_info(),
system_program.to_account_info(),
rent.to_account_info(),
)?;

#[allow(deprecated)]
Expand Down
30 changes: 16 additions & 14 deletions sdk/src/idl/mmm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,10 @@ export type Mmm = {
{
"name": "authorizationRulesProgram",
"isMut": false,
"isSigner": false
"isSigner": false,
"docs": [
"Address constraint not used here because of stack issues."
]
},
{
"name": "authorizationRules",
Expand All @@ -1656,7 +1659,10 @@ export type Mmm = {
{
"name": "instructions",
"isMut": false,
"isSigner": false
"isSigner": false,
"docs": [
"Address constraint not used here because of stack issues."
]
},
{
"name": "systemProgram",
Expand All @@ -1673,11 +1679,6 @@ export type Mmm = {
"isMut": false,
"isSigner": false
},
{
"name": "rent",
"isMut": false,
"isSigner": false
},
{
"name": "eventAuthority",
"isMut": false,
Expand Down Expand Up @@ -4089,7 +4090,10 @@ export const IDL: Mmm = {
{
"name": "authorizationRulesProgram",
"isMut": false,
"isSigner": false
"isSigner": false,
"docs": [
"Address constraint not used here because of stack issues."
]
},
{
"name": "authorizationRules",
Expand All @@ -4099,7 +4103,10 @@ export const IDL: Mmm = {
{
"name": "instructions",
"isMut": false,
"isSigner": false
"isSigner": false,
"docs": [
"Address constraint not used here because of stack issues."
]
},
{
"name": "systemProgram",
Expand All @@ -4116,11 +4123,6 @@ export const IDL: Mmm = {
"isMut": false,
"isSigner": false
},
{
"name": "rent",
"isMut": false,
"isSigner": false
},
{
"name": "eventAuthority",
"isMut": false,
Expand Down
1 change: 0 additions & 1 deletion sdk/src/mmmClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ export class MMMClient {
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
systemProgram: SystemProgram.programId,
tokenProgram: tokenProgramId,
rent: SYSVAR_RENT_PUBKEY,
tokenOwnerTokenRecord,
poolOwnerTokenRecord,
poolTokenRecord,
Expand Down
File renamed without changes.

0 comments on commit 33cb6ed

Please sign in to comment.