import { BN, Program } from "@project-serum/anchor"; import { PublicKey, Signer } from "@solana/web3.js"; import { PsyStake } from "../psy_stake"; import * as pdas from "../pdas"; import { DistributionType } from "../types"; import { convertDistributionType } from "../utils"; const getMethodBuilder = async ( program: Program, rewardPoolAuthority: PublicKey, stakePool: PublicKey, poolId: number, distributionType: DistributionType, rewardPerEpoch: BN, isActive: boolean, payer?: PublicKey ) => { const [rewardPool] = await pdas.deriveRewardPool( program.programId, stakePool, poolId ); let accounts: any = { rewardPoolAuthority, stakePool, rewardPool, }; if (payer) accounts.payer = payer; return await program.methods .updateRewardPool( convertDistributionType(distributionType), rewardPerEpoch, isActive ) .accounts(accounts); }; export const updateRewardPoolInstruction = async ( program: Program, rewardPoolAuthority: PublicKey, stakePool: PublicKey, poolId: number, distributionType: DistributionType, rewardPerEpoch: BN, isActive: boolean, payer?: PublicKey ) => { return ( await getMethodBuilder( program, rewardPoolAuthority, stakePool, poolId, distributionType, rewardPerEpoch, isActive, payer ) ).instruction(); }; export const updateRewardPoolRpc = async ( program: Program, rewardPoolAuthority: PublicKey, stakePool: PublicKey, poolId: number, distributionType: DistributionType, rewardPerEpoch: BN, isActive: boolean, signers: Signer[], payer?: PublicKey ) => { return ( await getMethodBuilder( program, rewardPoolAuthority, stakePool, poolId, distributionType, rewardPerEpoch, isActive, payer ) ) .signers(signers) .rpc(); };