UNPKG

@kamino-finance/scope-sdk

Version:
56 lines (51 loc) 1.66 kB
/* eslint-disable @typescript-eslint/no-unused-vars */ import { Address, isSome, IAccountMeta, IAccountSignerMeta, IInstruction, Option, TransactionSigner, } from "@solana/kit" /* eslint-enable @typescript-eslint/no-unused-vars */ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars import { borshAddress } from "../utils" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars import { PROGRAM_ID } from "../programId" export interface WithdrawFromTopupArgs { amount: BN } export interface WithdrawFromTopupAccounts { adminAuthority: TransactionSigner topupVault: Address system: Address } export const layout = borsh.struct([borsh.u64("amount")]) export function withdrawFromTopup( args: WithdrawFromTopupArgs, accounts: WithdrawFromTopupAccounts, programAddress: Address = PROGRAM_ID ) { const keys: Array<IAccountMeta | IAccountSignerMeta> = [ { address: accounts.adminAuthority.address, role: 3, signer: accounts.adminAuthority, }, { address: accounts.topupVault, role: 1 }, { address: accounts.system, role: 0 }, ] const identifier = Buffer.from([95, 227, 138, 220, 240, 95, 150, 113]) const buffer = Buffer.alloc(1000) const len = layout.encode( { amount: args.amount, }, buffer ) const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) const ix: IInstruction = { accounts: keys, programAddress, data } return ix }