From 4ef0c8aa6435682f150122fc6689cd8c26bd4422 Mon Sep 17 00:00:00 2001 From: jeffyanta Date: Thu, 30 Apr 2026 09:49:14 -0400 Subject: [PATCH] Close swap ATA on recovery flow if it's empty --- ocp/worker/swap/util.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ocp/worker/swap/util.go b/ocp/worker/swap/util.go index 6fcdd27..e32f452 100644 --- a/ocp/worker/swap/util.go +++ b/ocp/worker/swap/util.go @@ -234,11 +234,26 @@ func (p *runtime) buildCancelSwapTransaction( }, ) + closeInstr := vm.NewCloseSwapAccountIfEmptyInstruction( + &vm.CloseSwapAccountIfEmptyInstructionAccounts{ + VmAuthority: sourceVmConfig.Authority.PublicKey().ToBytes(), + Vm: sourceVmConfig.Vm.PublicKey().ToBytes(), + Swapper: owner.PublicKey().ToBytes(), + SwapPda: sourceTimelockAccounts.VmSwapAccounts.Pda.PublicKey().ToBytes(), + SwapAta: sourceTimelockAccounts.VmSwapAccounts.Ata.PublicKey().ToBytes(), + Destination: subsidizer.PublicKey().ToBytes(), + }, + &vm.CloseSwapAccountIfEmptyInstructionArgs{ + Bump: sourceTimelockAccounts.VmSwapAccounts.PdaBump, + }, + ) + instructions := []solana.Instruction{ system.AdvanceNonce(selectedNonce.Account.PublicKey().ToBytes(), subsidizer.PublicKey().ToBytes()), - compute_budget.SetComputeUnitLimit(75_000), + compute_budget.SetComputeUnitLimit(80_000), compute_budget.SetComputeUnitPrice(10_000), cancelInstr, + closeInstr, } txn := solana.NewLegacyTransaction(subsidizer.PublicKey().ToBytes(), instructions...)