1

This is my account struct

pub struct ClaimRewards<'info> {
    #[account(init_if_needed, payer = payer, seeds = [OKUSEED.as_ref()], bump, mint::decimals = 6, mint::authority = mint)]
    pub mint: Box<Account<'info, Mint>>,
    #[account(init_if_needed, payer = payer, associated_token::mint = mint, associated_token::authority = payer)]
    pub destination: Box<Account<'info, TokenAccount>>,
    #[account(mut)]
    pub payer: Signer<'info>,
    #[account(mut, seeds = [COUNTSSEED], bump = countsbump)]
    pub counts_account: AccountLoader<'info, Counts>,
    #[account(mut, seeds = [MYNODESSEED, payer.key().as_ref()], bump = nodesbump)]
    pub mnd: AccountLoader<'info, Mnd>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>,
    pub associated_token_program: Program<'info, AssociatedToken>,
    pub rent: Sysvar<'info, Rent>,
    #[account(mut,seeds = [VESTERSEED],bump = vesterbump)]
    pub vester: AccountLoader<'info, Vester>,
    #[account(init_if_needed,space =16, payer=payer,seeds = [ESCROWSEED],bump)]
    pub store_escrow : AccountLoader<'info,Escrow>,
    #[account(
        init_if_needed,
        payer = payer,
        associated_token::mint = mint,
        associated_token::authority = store_escrow,
    )]
    pub sender_tokens: Box<Account<'info, TokenAccount>>,
    #[account(mut)]
    /// CHECK: The account holding the vesting parameters.
    pub metadata: UncheckedAccount<'info>,
    #[account(
        mut,
        seeds = [b"strm", metadata.key().to_bytes().as_ref()],
        bump,
        seeds::program = streamflow_program
    )]
    /// CHECK: The escrow account holding the funds
    pub escrow_tokens: UncheckedAccount<'info>,
    #[account(mut)]
    /// CHECK: Streamflow treasury account.
    pub streamflow_treasury: UncheckedAccount<'info>,
    #[account(
        init_if_needed,
        payer = payer,
        associated_token::mint = mint,
        associated_token::authority = streamflow_treasury,
    )]
    /// CHECK: Associated token account address of `streamflow_treasury`.
    pub streamflow_treasury_tokens: Box<Account<'info, TokenAccount>>,
    #[account(mut)]
    /// CHECK: Delegate account for automatically withdrawing contracts.
    pub withdrawor: UncheckedAccount<'info>,
  ///CHECK
    pub streamflow_program: UncheckedAccount<'info>,
    //  / CHECK: Partner treasury account.
    //  pub partner_strm: UncheckedAccount<'info>,
    ///CHECK
    pub fee_oracle: AccountInfo<'info>,
}

and i use it like this

 let acc = &mut ctx.accounts.counts_account.load_mut()?;
        let nds = &mut ctx.accounts.mnd.load_mut()?;
        // Check if the account is xandified of not, error if not xandified 
        require!(xandified(nds.collected),ErrorCode::NotXandified);

      ;
       
        require!(amount <= max, ErrorCode::TooMuchOku);
        anchor_spl::token::mint_to(
            CpiContext::new_with_signer(
                ctx.accounts.token_program.to_account_info(),
                anchor_spl::token::MintTo {
                    mint: ctx.accounts.mint.to_account_info(),
                    to: ctx.accounts.destination.to_account_info(),
                    authority: ctx.accounts.mint.to_account_info(),
                },
                &[&[SEED, &[bump]]],
            ),
            amount,
        )?;
        nds.collected -= amount;
        acc.oku_claimed += amount;

        let clock = Clock::get()?;
        let now = clock.unix_timestamp as i64;

        let vester = ctx.accounts.vester.load()?;
        let vesting_info = get_vesting_info(&vester.schedule,ctx.accounts.payer.key().clone());
        let is_team_wallet = is_team_wallet(ctx.accounts.payer.key().clone(),&vester.schedule);

        msg!("team :{}",is_team_wallet);

        if is_team_wallet {

            
            //They only collect vested rewards
            let vesting = &mut vesting_info.unwrap();
            // let to_be_vested = vesting.to_be_vested;
            let to_be_vested = 1000;
            let time_left = vesting.start_time +(1460 * 24 * 60 * 60) - now;
            msg!("{}",to_be_vested);
            // if time_left >0 {
                if true {
                if to_be_vested > 0  {
                   
                    msg!("{}",to_be_vested);
                    anchor_spl::token::mint_to(
                        CpiContext::new_with_signer(
                            ctx.accounts.token_program.to_account_info().clone(),
                            anchor_spl::token::MintTo {
                                mint: ctx.accounts.mint.to_account_info().clone(),
                                to: ctx.accounts.sender_tokens.to_account_info().clone(),
                                authority: ctx.accounts.mint.to_account_info().clone(),
                            },
                            &[&[SEED, &[bump]]],
                        ),
                        to_be_vested,
                    )?;
                    vesting.to_be_vested -= to_be_vested; 
                    if vesting.metadata == None {
                        msg!("create");
                        // create_schedule(&ctx,to_be_vested,vesting.start_time as u64,now as u64)?;
                        let accs = CreateUncheckedWithPayer {
                            payer: ctx.accounts.payer.to_account_info().clone(),
                            sender: ctx.accounts.store_escrow.to_account_info(),
                            sender_tokens: ctx.accounts.sender_tokens.to_account_info().clone(),
                            // recipient: ctx.accounts.recipient.to_account_info(),
                            // recipient_tokens: ctx.accounts.recipient_tokens.to_account_info(),
                            metadata: ctx.accounts.metadata.to_account_info(),
                            escrow_tokens: ctx.accounts.escrow_tokens.to_account_info(),
                            // streamflow_treasury: ctx.accounts.streamflow_treasury.to_account_info(),
                            // streamflow_treasury_tokens: ctx.accounts.streamflow_treasury_tokens.to_account_info(),
                            withdrawor: ctx.accounts.withdrawor.to_account_info(),
                            // partner: ctx.accounts.partner.to_account_info(),
                            // partner_tokens: ctx.accounts.partner_tokens.to_account_info(),
                            mint: ctx.accounts.mint.to_account_info().clone(),
                            fee_oracle: ctx.accounts.fee_oracle.to_account_info(),
                            rent: ctx.accounts.rent.to_account_info(),
                            timelock_program: ctx.accounts.streamflow_program.to_account_info().clone(),
                            token_program: ctx.accounts.token_program.to_account_info().clone(),
                            // associated_token_program: ctx.accounts.associated_token_program.to_account_info(),
                            system_program: ctx.accounts.system_program.to_account_info(),
                        };
                    
                        let cpi_ctx = CpiContext::new(ctx.accounts.streamflow_program.to_account_info().clone(), accs);
                    
                        streamflow_sdk::cpi::create_unchecked_with_payer(
                            cpi_ctx,
                            0, //start_time - immidiate start,
                            to_be_vested,
                            1,
                            1,
                            0,
                            0,
                            false,
                            false,
                            false,
                            false,
                            false,
                            true,
                            [0; 64],
                            35,
                            ctx.accounts.payer.key().clone(),
                            ctx.accounts.streamflow_program.key().clone(),
                            false,
                            true,
                        )?;

                        vesting.metadata = Some (ctx.accounts.metadata.key());
                    }
    

i have clone some account here , cause if i don't do that i get

ProgramError occurred. Error Code: AccountBorrowFailed. Error Number: 51539607552. Error Message: Failed to borrow a reference to account data, already borrowed

Update : I tried to Box the Vester account

#[derive(Accounts)]
pub struct CreateVester<'info> {
    #[account(mut)]
    pub user: Signer<'info>,
    #[account(init, payer = user, space = 1928, seeds = [VESTERSEED], bump)]
    pub vester: Box<Account<'info, Vester>>,
    pub system_program: Program<'info, System>,
}

this only initializes the account, now i get the stack error here.what could be the issue?

1 Answer 1

3

Unfortunately, this isn't a clear answer, but you should look at all of the stack variables that you're using, like CreateUncheckedWithPayer or vesting, and see if you can refactor some of your logic into separate functions to reduce the stack size.

You only get 4KB, so you have to be careful: https://docs.solana.com/developing/on-chain-programs/faq#stack

If the compiler isn't warning you about stack size violations during build, it could be that everything is ok, but then the compiler inlines some functions, which blows up your stack size. For your refactored functions, you should use #[inline(never)] to be sure that you get a fresh stack.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.