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, stakePoolAuthority: PublicKey, rewardPoolAuthority: PublicKey, stakePool: PublicKey, rewardTokenMint: PublicKey, poolId: number, startingEpoch: number, distributionType: DistributionType, rewardPerEpoch: BN, epochRewardDecimals: number, payer?: PublicKey ) => { const poolAccounts = await pdas.deriveRewardPoolPdas( program.programId, stakePool, poolId, startingEpoch ); let accounts: any = { stakePoolAuthority, rewardPoolAuthority, stakePool, rewardPool: poolAccounts.rewardPool, rewardRecord: poolAccounts.rewardRecord, rewardTokenMint, rewardTokenAccount: poolAccounts.rewardTokenAccount, allocatedTokenAccount: poolAccounts.allocatedTokenAccount, }; if (payer) accounts.payer = payer; return await program.methods .createRewardPool( startingEpoch, convertDistributionType(distributionType), rewardPerEpoch, epochRewardDecimals ) .accounts(accounts); }; export const createRewardPoolInstruction = async ( program: Program, stakePoolAuthority: PublicKey, rewardPoolAuthority: PublicKey, stakePool: PublicKey, rewardTokenMint: PublicKey, poolId: number, startingEpoch: number, distributionType: DistributionType, rewardPerEpoch: BN, epochRewardDecimals: number, payer?: PublicKey ) => { return ( await getMethodBuilder( program, stakePoolAuthority, rewardPoolAuthority, stakePool, rewardTokenMint, poolId, startingEpoch, distributionType, rewardPerEpoch, epochRewardDecimals, payer ) ).instruction(); }; export const createRewardPoolRpc = async ( program: Program, stakePoolAuthority: PublicKey, rewardPoolAuthority: PublicKey, stakePool: PublicKey, rewardTokenMint: PublicKey, poolId: number, startingEpoch: number, distributionType: DistributionType, rewardPerEpoch: BN, epochRewardDecimals: number, signers: Signer[], payer?: PublicKey ) => { return ( await getMethodBuilder( program, stakePoolAuthority, rewardPoolAuthority, stakePool, rewardTokenMint, poolId, startingEpoch, distributionType, rewardPerEpoch, epochRewardDecimals, payer ) ) .signers(signers) .rpc(); };