diff --git a/CLAUDE.md b/CLAUDE.md index 21438fb..ae8e1e5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -90,7 +90,6 @@ create_escrow (seller) → deposit (buyer) → complete (buyer) cancel (seller, only from AwaitingDeposit) ``` -**SOL transfers** use raw `invoke` / `invoke_signed` (not Anchor's CPI helpers) because Anchor 1.0.x changed `CpiContext::new` to take `Pubkey` instead of `AccountInfo`. ### Resolver Registry (`descro_ext_resolvers`) @@ -102,7 +101,7 @@ cancel (seller, only from AwaitingDeposit) ### Anchor / SDK Notes -- **Anchor 1.0.x:** `CpiContext::new` takes `Pubkey` not `AccountInfo`; use `UncheckedAccount<'info>` with `/// CHECK:` instead of `AccountInfo<'info>` in account structs; `#[derive(InitSpace)]` + `#[max_len(N)]` for strings. +- **Anchor 1.0.x:** use `UncheckedAccount<'info>` with `/// CHECK:` instead of `AccountInfo<'info>` in account structs; `#[derive(InitSpace)]` + `#[max_len(N)]` for strings. - **`@coral-xyz/anchor@0.32.x`:** Use `new Program(idl, provider)` — the IDL's `address` field provides the program ID. The 3-argument form `new Program(idl, programId, provider)` is broken in 0.32.x. - **LiteSVM tests:** each `tests/common/mod.rs` has `setup()`, PDA helpers, `send()`/`try_send()`, `ix_*` builders, and `read_*` deserializers. `test_resolve_with_registry.rs` loads both `.so` files to test the full CPI flow. diff --git a/programs/descro/src/instructions/complete.rs b/programs/descro/src/instructions/complete.rs index 7b7d814..ec68310 100644 --- a/programs/descro/src/instructions/complete.rs +++ b/programs/descro/src/instructions/complete.rs @@ -1,5 +1,5 @@ use anchor_lang::prelude::*; -use anchor_lang::solana_program::{program::invoke_signed, system_instruction}; +use anchor_lang::system_program::{self, Transfer}; use crate::state::{EscrowAccount, EscrowState}; use crate::error::EscrowError; @@ -42,17 +42,16 @@ pub fn handler(ctx: Context) -> Result<()> { let vault_bump = ctx.accounts.escrow_account.vault_bump; let vault_balance = ctx.accounts.vault.to_account_info().lamports(); - invoke_signed( - &system_instruction::transfer( - ctx.accounts.vault.to_account_info().key, - ctx.accounts.seller.to_account_info().key, - vault_balance, + system_program::transfer( + CpiContext::new_with_signer( + system_program::ID, + Transfer { + from: ctx.accounts.vault.to_account_info(), + to: ctx.accounts.seller.to_account_info(), + }, + &[&[b"vault", escrow_key.as_ref(), &[vault_bump]]], ), - &[ - ctx.accounts.vault.to_account_info(), - ctx.accounts.seller.to_account_info(), - ], - &[&[b"vault", escrow_key.as_ref(), &[vault_bump]]], + vault_balance, )?; Ok(()) diff --git a/programs/descro/src/instructions/deposit.rs b/programs/descro/src/instructions/deposit.rs index f92b449..db2a5b9 100644 --- a/programs/descro/src/instructions/deposit.rs +++ b/programs/descro/src/instructions/deposit.rs @@ -1,5 +1,5 @@ use anchor_lang::prelude::*; -use anchor_lang::solana_program::{program::invoke, system_instruction}; +use anchor_lang::system_program::{self, Transfer}; use crate::state::{EscrowAccount, EscrowState}; use crate::error::EscrowError; @@ -31,16 +31,15 @@ pub struct Deposit<'info> { pub fn handler(ctx: Context) -> Result<()> { let amount = ctx.accounts.escrow_account.amount; - invoke( - &system_instruction::transfer( - ctx.accounts.buyer.to_account_info().key, - ctx.accounts.vault.to_account_info().key, - amount, + system_program::transfer( + CpiContext::new( + system_program::ID, + Transfer { + from: ctx.accounts.buyer.to_account_info(), + to: ctx.accounts.vault.to_account_info(), + }, ), - &[ - ctx.accounts.buyer.to_account_info(), - ctx.accounts.vault.to_account_info(), - ], + amount, )?; ctx.accounts.escrow_account.state = EscrowState::Active; diff --git a/programs/descro/src/instructions/resolve.rs b/programs/descro/src/instructions/resolve.rs index a9e196c..b549523 100644 --- a/programs/descro/src/instructions/resolve.rs +++ b/programs/descro/src/instructions/resolve.rs @@ -1,8 +1,7 @@ use crate::error::EscrowError; use crate::state::{EscrowAccount, EscrowState, Winner}; -use anchor_lang::solana_program::{program::invoke_signed, system_instruction}; -use anchor_lang::system_program::Transfer; -use anchor_lang::{prelude::*, system_program}; +use anchor_lang::system_program::{self, Transfer}; +use anchor_lang::prelude::*; use descro_ext_resolvers::state::Ruling; #[derive(Accounts)]