From be93f209724ddf3f14c5cdb8922c901000ed5138 Mon Sep 17 00:00:00 2001 From: weixiang Date: Tue, 28 Jun 2022 16:25:35 +0800 Subject: [PATCH 1/3] chore: add params to initStakingPool ix --- src/instructions/staking/initStakingPool.ts | 50 +++++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/instructions/staking/initStakingPool.ts b/src/instructions/staking/initStakingPool.ts index 7a0126f..7cec2b3 100644 --- a/src/instructions/staking/initStakingPool.ts +++ b/src/instructions/staking/initStakingPool.ts @@ -8,9 +8,9 @@ import * as BufferLayout from "@solana/buffer-layout"; import BN from "bn.js"; import * as Layout from "../../serialization/layout"; -import { PORT_STAKING } from "../../constants"; import { StakingInstructions } from "./instruction"; import { AccessType, getAccess } from "../../utils/Instructions"; +import { Optional } from "../../serialization"; // interface Data { // instruction: number; @@ -25,6 +25,7 @@ import { AccessType, getAccess } from "../../utils/Instructions"; const DataLayout = BufferLayout.struct([ BufferLayout.u8("instruction"), Layout.uint64("supply"), + Optional.of(Layout.uint64("subSupply")), Layout.uint64("duration"), Layout.uint64("earliestRewardTime"), BufferLayout.u8("bumpSeed"), @@ -41,6 +42,9 @@ const DataLayout = BufferLayout.struct([ // 5. `[]` Staking program derived that owns reward token pool. // 6. `[]` Rent sysvar . // 7. `[]` Token program. +// 8. `[writable, optional]` Sub Reward token supply. +// 9. `[writable, optional]` Sub Reward token pool - uninitialized. +// 10. `[optional]` Sub Reward token mint. export const initStakingPoolInstruction = ( supply: number | BN, duration: number | BN, @@ -54,21 +58,31 @@ export const initStakingPoolInstruction = ( derivedStakingProgram: PublicKey, poolOwnerAuthority: PublicKey, adminAuthority: PublicKey, - stakingProgramId: PublicKey = PORT_STAKING + stakingProgramId: PublicKey, + subReward?: { + supply: number | BN; + tokenSupply: PublicKey; + tokenPool: PublicKey; + rewardTokenMint: PublicKey; + } ): TransactionInstruction => { const data = Buffer.alloc(DataLayout.span); - DataLayout.encode( - { - instruction: StakingInstructions.InitStakingPool, - supply: new BN(supply), - duration: new BN(duration), - earliestRewardTime: new BN(earliestRewardTime), - bumpSeed, - poolOwnerAuthority, - adminAuthority, - }, - data - ); + + const params = { + instruction: StakingInstructions.InitStakingPool, + supply: new BN(supply), + duration: new BN(duration), + earliestRewardTime: new BN(earliestRewardTime), + bumpSeed, + poolOwnerAuthority, + adminAuthority, + }; + + if (subReward) { + params["subSupply"] = subReward.supply; + } + + DataLayout.encode(params, data); const keys = [ // signer @@ -84,6 +98,14 @@ export const initStakingPoolInstruction = ( getAccess(TOKEN_PROGRAM_ID, AccessType.READ), ]; + if (subReward) { + keys.push( + getAccess(subReward.tokenSupply, AccessType.WRITE), + getAccess(subReward.tokenPool, AccessType.WRITE), + getAccess(subReward.rewardTokenMint, AccessType.READ) + ); + } + return new TransactionInstruction({ keys, programId: stakingProgramId, From 9d918e7e617adb545a82e6ca9578e2566affbeb4 Mon Sep 17 00:00:00 2001 From: weixiang Date: Tue, 28 Jun 2022 16:26:46 +0800 Subject: [PATCH 2/3] fix: type --- src/instructions/staking/initStakingPool.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/instructions/staking/initStakingPool.ts b/src/instructions/staking/initStakingPool.ts index 7cec2b3..bebbc57 100644 --- a/src/instructions/staking/initStakingPool.ts +++ b/src/instructions/staking/initStakingPool.ts @@ -79,7 +79,7 @@ export const initStakingPoolInstruction = ( }; if (subReward) { - params["subSupply"] = subReward.supply; + params["subSupply"] = new BN(subReward.supply); } DataLayout.encode(params, data); From 49ecc8f99b1e55977b725aeaaf66cd9a646a9090 Mon Sep 17 00:00:00 2001 From: weixiang Date: Wed, 29 Jun 2022 18:25:01 +0800 Subject: [PATCH 3/3] fix: fill necessary accounts --- src/instructions/staking/initStakingPool.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/instructions/staking/initStakingPool.ts b/src/instructions/staking/initStakingPool.ts index bebbc57..a8f6cce 100644 --- a/src/instructions/staking/initStakingPool.ts +++ b/src/instructions/staking/initStakingPool.ts @@ -1,5 +1,6 @@ import { TOKEN_PROGRAM_ID } from "@solana/spl-token"; import { + Keypair, PublicKey, SYSVAR_RENT_PUBKEY, TransactionInstruction, @@ -84,28 +85,25 @@ export const initStakingPoolInstruction = ( DataLayout.encode(params, data); + const dummy = () => Keypair.generate().publicKey; + const keys = [ // signer getAccess(transferRewardSupply, AccessType.SIGNER), // write accounts getAccess(rewardTokenSupply, AccessType.WRITE), getAccess(rewardTokenPool, AccessType.WRITE), + getAccess(subReward?.tokenSupply ?? dummy(), AccessType.WRITE), + getAccess(subReward?.tokenPool ?? dummy(), AccessType.WRITE), getAccess(stakingPool, AccessType.WRITE), // read accounts getAccess(rewardTokenMint, AccessType.READ), + getAccess(subReward?.rewardTokenMint ?? dummy(), AccessType.READ), getAccess(derivedStakingProgram, AccessType.READ), getAccess(SYSVAR_RENT_PUBKEY, AccessType.READ), getAccess(TOKEN_PROGRAM_ID, AccessType.READ), ]; - if (subReward) { - keys.push( - getAccess(subReward.tokenSupply, AccessType.WRITE), - getAccess(subReward.tokenPool, AccessType.WRITE), - getAccess(subReward.rewardTokenMint, AccessType.READ) - ); - } - return new TransactionInstruction({ keys, programId: stakingProgramId,