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, stakeAmount: BN, lockupPeriod: number ) => { const [stakingRecord] = await pdas.deriveStakingRecord( program.programId, recordOwner, stakePool ); const [stakingTokenAccount] = await pdas.deriveStakingTokenAccount( program.programId, stakePool ); return await program.methods.stakeToken(stakeAmount, lockupPeriod).accounts({ recordOwner, stakePool, stakingRecord, ownerTokenAccount, stakingTokenAccount, }); }; export const stakeTokenInstruction = async ( program: Program, recordOwner: PublicKey, stakePool: PublicKey, ownerTokenAccount: PublicKey, stakeAmount: BN, lockupPeriod: number ) => { return ( await getMethodBuilder( program, recordOwner, stakePool, ownerTokenAccount, stakeAmount, lockupPeriod ) ).instruction(); }; export const stakeTokenRpc = async ( program: Program, recordOwner: PublicKey, stakePool: PublicKey, ownerTokenAccount: PublicKey, stakeAmount: BN, lockupPeriod: number, signers: Signer[] ) => { return ( await getMethodBuilder( program, recordOwner, stakePool, ownerTokenAccount, stakeAmount, lockupPeriod ) ) .signers(signers) .rpc(); };