I am making a cpi call to solend DepositReserveLiquidity instruction found here link
which calls then calls this code to unpack the data and execute the instruction link
However , I keep getting this error
thread 'test_deposit_reserve_liquidity::test_update_balance_native' panicked at tests/src/test_deposit_reserve_liquidity.rs:118:7:
: SolanaClientError(Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(0, Custom(0))), logs: Some(["Program So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo invoke [1]", "Program log: Instruction cannot be unpacked", "Program log: Failed to unpack instruction data", "Program So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo consumed 3787 of 200000 compute units", "Program So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo failed: custom program error: 0x0"]), accounts: None, units_consumed: Some(3787), return_data: None, inner_instructions: None }) }) })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Below is the code to my anchor program which i am using to make the cpi call to the above solend protocol.
use anchor_lang::prelude::*;
use anchor_lang::solana_program::instruction::{AccountMeta, Instruction};
use anchor_lang::solana_program::program::invoke;
pub fn deposit_reserve_liquidity(ctx: Context<DepositReserveLiquidity>, amount: u64) -> Result<()> {
let lending_program_id = ctx.accounts.lending_program_id.key();
let accounts = vec![
AccountMeta::new(ctx.accounts.source_liquidity.key(), false),
AccountMeta::new(ctx.accounts.destination_collateral.key(), false),
AccountMeta::new(ctx.accounts.reserve.key(), false),
AccountMeta::new(ctx.accounts.reserve_liquidity_supply.key(), false),
AccountMeta::new(ctx.accounts.reserve_collateral_mint.key(), false),
AccountMeta::new_readonly(ctx.accounts.lending_market.key(), false),
AccountMeta::new_readonly(ctx.accounts.lending_market_authority.key(), false),
AccountMeta::new_readonly(ctx.accounts.user_transfer_authority.key(), true),
AccountMeta::new_readonly(ctx.accounts.clock.key(), false),
AccountMeta::new_readonly(ctx.accounts.token_program_id.key(), false),
];
let mut data = vec![4];
data.extend_from_slice(&amount.to_le_bytes());
let ix = Instruction {
program_id: lending_program_id,
accounts,
data,
};
invoke(
&ix,
&[
ctx.accounts.source_liquidity.to_account_info(),
ctx.accounts.destination_collateral.to_account_info(),
ctx.accounts.reserve.to_account_info(),
ctx.accounts.reserve_liquidity_supply.to_account_info(),
ctx.accounts.reserve_collateral_mint.to_account_info(),
ctx.accounts.lending_market.to_account_info(),
ctx.accounts.lending_market_authority.to_account_info(),
ctx.accounts.user_transfer_authority.to_account_info(),
ctx.accounts.clock.to_account_info(),
ctx.accounts.token_program_id.to_account_info(),
],
);
msg!("cpi:deposit_reserve_liquidity");
Ok(())
}
#[derive(Accounts)]
pub struct DepositReserveLiquidity<'info> {
#[account(mut)]
pub payer: Signer<'info>,
/// CHECK: Checked in the lending program
#[account(mut)]
pub source_liquidity: AccountInfo<'info>,
/// CHECK: Checked in the lending program
#[account(mut)]
pub destination_collateral: AccountInfo<'info>,
/// CHECK: Checked in the lending program
#[account(mut)]
pub reserve: AccountInfo<'info>,
/// CHECK: Checked in the lending program
#[account(mut)]
pub reserve_liquidity_supply: AccountInfo<'info>,
/// CHECK: Checked in the lending program
#[account(mut)]
pub reserve_collateral_mint: AccountInfo<'info>,
/// CHECK: Checked in the lending program
pub lending_market: AccountInfo<'info>,
/// CHECK: Checked in the lending program
pub lending_market_authority: AccountInfo<'info>,
pub user_transfer_authority: Signer<'info>,
pub clock: Sysvar<'info, Clock>,
/// CHECK: Checked in the lending program
pub token_program_id: AccountInfo<'info>,
/// CHECK: Lending program ID
pub lending_program_id: AccountInfo<'info>,
}
And this is my test code
use std::str::FromStr;
use anchor_client::{
anchor_lang::{accounts::sysvar, system_program}, solana_sdk::{
clock, commitment_config::CommitmentConfig, instruction::Instruction, pubkey::Pubkey, signature::read_keypair_file, signer::Signer, system_instruction, sysvar::SysvarId, transaction::{self, Transaction}
}, Client, Cluster
};
use anchor_spl::{
associated_token::{get_associated_token_address,
spl_associated_token_account::{
self,
instruction::create_associated_token_account
},
AssociatedToken
}, token::spl_token::{instruction::sync_native, native_mint}, token_2022::spl_token_2022::solana_zk_token_sdk::instruction::transfer, token_interface::{self, Mint, TokenAccount, TokenInterface, TransferChecked,
},
};
use crate::constants::{ LENDING_MARKET, LENDING_MARKET_AUTHORITY, RESERVE, RESERVE_COLLATERAL_MINT, RESERVE_LIQUIDITY_SUPPLY, SOLEND_PROGRAM_ID, TOKEN_PROGRAM_ID};
#[test]
fn test_update_balance_native() -> Result<(), Box<dyn std::error::Error>> {
let anchor_wallet = std::env::var("ANCHOR_WALLET").unwrap();
let payer = read_keypair_file(&anchor_wallet).unwrap();
let client = Client::new_with_options(Cluster::Localnet, &payer, CommitmentConfig::confirmed());
let program_id = Pubkey::from_str(SOLEND_PROGRAM_ID).unwrap();
let program = client.program(program_id).unwrap();
let token_program_id = anchor_spl::token::ID;
let associated_token_program_id = anchor_spl::associated_token::ID;
let collateral_mint = Pubkey::from_str(RESERVE_COLLATERAL_MINT).unwrap();
// destination_collateral_account -> BdgLzcRH36dJdm6Cz6YUeeUDoJzpEHjvVHATWJYJqo7j
let destination_collateral_account = get_associated_token_address(
&payer.pubkey(), // Owner
&collateral_mint,
);
// Create the Associated Token Account instruction
let create_associated_account_ix = create_associated_token_account(
&payer.pubkey(),
&payer.pubkey(),
&collateral_mint,
&token_program_id
);
let source_liquidity_wsol_ata = get_associated_token_address(&payer.pubkey(), &native_mint::id());
let create_associated_account_wrapped_sol_ix: Instruction = create_associated_token_account(
&payer.pubkey(),
&payer.pubkey(),
&native_mint::id(),
&token_program_id
);
let amount: u64 = 10_000_000_000_000;
let tx = program.request()
.accounts(defi_market::accounts::DepositReserveLiquidity{
payer: payer.pubkey(),
source_liquidity: source_liquidity_wsol_ata,
destination_collateral: destination_collateral_account,
reserve: Pubkey::from_str(RESERVE).unwrap(),
reserve_liquidity_supply: Pubkey::from_str(RESERVE_LIQUIDITY_SUPPLY).unwrap(),
reserve_collateral_mint: collateral_mint,
lending_market: Pubkey::from_str(LENDING_MARKET).unwrap(),
lending_market_authority: Pubkey::from_str(LENDING_MARKET_AUTHORITY).unwrap(),
user_transfer_authority: payer.pubkey(),
token_program_id, // Pubkey::from_str(TOKEN_PROGRAM_ID).unwrap(),
clock: clock::Clock::id(),
lending_program_id: Pubkey::from_str(SOLEND_PROGRAM_ID).unwrap(),
})
.args(defi_market::instruction::DepositReserveLiquidity{
amount ,
})
.signer(&payer)
.send()
.expect("");
Ok(())
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744863901a4597863.html
评论列表(0条)