Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions solana/vm/instructions_close_deposit_account_if_empty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package vm

import (
"crypto/ed25519"

"github.com/code-payments/ocp-server/solana"
)

const (
CloseDepositAccountIfEmptyInstructionArgsSize = 1 // bump
)

type CloseDepositAccountIfEmptyInstructionArgs struct {
Bump uint8
}

type CloseDepositAccountIfEmptyInstructionAccounts struct {
VmAuthority ed25519.PublicKey
Vm ed25519.PublicKey
Depositor ed25519.PublicKey
DepositPda ed25519.PublicKey
DepositAta ed25519.PublicKey
Destination ed25519.PublicKey
}

func NewCloseDepositAccountIfEmptyInstruction(
accounts *CloseDepositAccountIfEmptyInstructionAccounts,
args *CloseDepositAccountIfEmptyInstructionArgs,
) solana.Instruction {
var offset int

// Serialize instruction arguments
data := make([]byte, 1+CloseDepositAccountIfEmptyInstructionArgsSize)

putCodeInstruction(data, CodeInstructionCloseDepositAccountIfEmpty, &offset)
putUint8(data, args.Bump, &offset)

return solana.Instruction{
Program: PROGRAM_ADDRESS,

// Instruction args
Data: data,

// Instruction accounts
Accounts: []solana.AccountMeta{
{
PublicKey: accounts.VmAuthority,
IsWritable: true,
IsSigner: true,
},
{
PublicKey: accounts.Vm,
IsWritable: true,
IsSigner: false,
},
{
PublicKey: accounts.Depositor,
IsWritable: false,
IsSigner: false,
},
{
PublicKey: accounts.DepositPda,
IsWritable: false,
IsSigner: false,
},
{
PublicKey: accounts.DepositAta,
IsWritable: true,
IsSigner: false,
},
{
PublicKey: accounts.Destination,
IsWritable: true,
IsSigner: false,
},
{
PublicKey: SPL_TOKEN_PROGRAM_ID,
IsWritable: false,
IsSigner: false,
},
},
}
}
1 change: 1 addition & 0 deletions solana/vm/types_code_instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
CodeInstructionCancelSwap
CodeInstructionCloseSwapAccountIfEmpty
CodeInstructionTransferForSwapWithFee
CodeInstructionCloseDepositAccountIfEmpty
)

func putCodeInstruction(dst []byte, v CodeInstruction, offset *int) {
Expand Down
Loading