import { BN, Program } from "@project-serum/anchor"; import { PublicKey, Signer } from "@solana/web3.js"; import { PsyStake } from "../../psy_stake"; import * as pdas from "../../pdas"; const getMethodBuilder = async ( program: Program, recordOwner: PublicKey, stakePool: PublicKey, ownerTokenAccount: PublicKey, amount: BN ) => { const [stakingRecord] = await pdas.deriveStakingRecord( program.programId, recordOwner, stakePool ); const [stakingTokenAccount] = await pdas.deriveStakingTokenAccount( program.programId, stakePool ); return await program.methods.unstakeToken(amount).accounts({ recordOwner, stakePool, stakingRecord, ownerTokenAccount, stakingTokenAccount, }); }; export const unstakeTokenInstruction = async ( program: Program, recordOwner: PublicKey, stakePool: PublicKey, ownerTokenAccount: PublicKey, unstakeAmount: BN ) => { return ( await getMethodBuilder( program, recordOwner, stakePool, ownerTokenAccount, unstakeAmount ) ).instruction(); }; export const unstakeTokenRpc = async ( program: Program, recordOwner: PublicKey, stakePool: PublicKey, ownerTokenAccount: PublicKey, unstakeAmount: BN, signers: Signer[] ) => { return ( await getMethodBuilder( program, recordOwner, stakePool, ownerTokenAccount, unstakeAmount ) ) .signers(signers) .rpc(); };