diff --git a/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/close_verify.rs b/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/close_verify.rs new file mode 100644 index 0000000..0511bce --- /dev/null +++ b/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/close_verify.rs @@ -0,0 +1,33 @@ +use crate::*; + +#[derive(Accounts)] +#[instruction(params: CloseVerifyParams)] +pub struct CloseVerify<'info> { + pub dvn: Signer<'info>, + #[account(mut)] + pub receiver: AccountInfo<'info>, + #[account( + mut, + seeds = [ + CONFIRMATIONS_SEED, + ¶ms.packet_header_hash[..], + ¶ms.payload_hash[..], + dvn.key.as_ref() + ], + bump = confirmations.bump, + close = receiver + )] + pub confirmations: Account<'info, Confirmations>, +} + +impl CloseVerify<'_> { + pub fn apply() -> Result<()> { + Ok(()) + } +} + +#[derive(Clone, AnchorSerialize, AnchorDeserialize)] +pub struct CloseVerifyParams { + pub packet_header_hash: [u8; 32], + pub payload_hash: [u8; 32], +} diff --git a/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/commit_verification.rs b/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/commit_verification.rs index e1af67d..4806565 100644 --- a/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/commit_verification.rs +++ b/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/commit_verification.rs @@ -1,5 +1,5 @@ use crate::*; -use anchor_lang::{solana_program::keccak::hash as keccak256, system_program}; +use anchor_lang::solana_program::keccak::hash as keccak256; use messagelib_helper::{ endpoint_verify, packet_v1_codec::{self, PACKET_HEADER_SIZE}, @@ -23,8 +23,7 @@ pub struct CommitVerification<'info> { bump = default_receive_config.bump, )] pub default_receive_config: Account<'info, ReceiveConfig>, - /// This account is mutable for receiving the reclaimed lamports - #[account(mut, seeds = [ULN_SEED], bump = uln.bump)] + #[account(seeds = [ULN_SEED], bump = uln.bump)] pub uln: Account<'info, UlnSettings>, } @@ -66,11 +65,7 @@ impl CommitVerification<'_> { params.payload_hash, &[ULN_SEED, &[ctx.accounts.uln.bump]], &ctx.remaining_accounts[dvns_size..], - )?; - - // need to reclaim storage after verification, otherwise the lamports of uln account will be changed - // and endpoint_verify::verify() will fail - reclaim_storage(confirmation_accounts, ctx.accounts.uln.as_ref()) + ) } } @@ -82,28 +77,6 @@ fn get_receive_config( UlnConfig::get_config(&default_config.uln, &custom_config.uln) } -fn reclaim_storage(confirmation_accounts: &[AccountInfo], sol_dest: &AccountInfo) -> Result<()> { - // close accounts - for acc in confirmation_accounts { - // skip if account already closed - if *acc.owner == system_program::ID { - continue; - } - - // check if the account is writable to reclaim storage - require!(acc.is_writable, UlnError::InvalidConfirmation); - - let lamports = acc.lamports(); - sol_dest.add_lamports(lamports)?; - acc.sub_lamports(lamports)?; - - acc.assign(&system_program::ID); - acc.realloc(0, false)?; - } - - Ok(()) -} - pub fn check_verifiable( config: &UlnConfig, accounts: &[AccountInfo], diff --git a/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/mod.rs b/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/mod.rs index d3c1b9a..ba3f76d 100644 --- a/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/mod.rs +++ b/packages/layerzero-v2/solana/programs/programs/uln/src/instructions/dvn/mod.rs @@ -1,7 +1,9 @@ +pub mod close_verify; pub mod commit_verification; pub mod init_verify; pub mod verify; +pub use close_verify::*; pub use commit_verification::*; pub use init_verify::*; pub use verify::*; diff --git a/packages/layerzero-v2/solana/programs/programs/uln/src/lib.rs b/packages/layerzero-v2/solana/programs/programs/uln/src/lib.rs index 001d3a1..1a4bbf8 100644 --- a/packages/layerzero-v2/solana/programs/programs/uln/src/lib.rs +++ b/packages/layerzero-v2/solana/programs/programs/uln/src/lib.rs @@ -108,6 +108,10 @@ pub mod uln { Verify::apply(&mut ctx, ¶ms) } + pub fn close_verify(_ctx: Context, _params: CloseVerifyParams) -> Result<()> { + CloseVerify::apply() + } + pub fn commit_verification( mut ctx: Context, params: CommitVerificationParams,