From d55f4684c7fa3bd1221563cf46b0d26d217615dc Mon Sep 17 00:00:00 2001 From: "roman.rolgin" Date: Thu, 31 Oct 2024 21:35:51 +0100 Subject: [PATCH] Staking API - update reward pool instructions --- lerna.json | 2 +- packages/common/package.json | 2 +- packages/distributor/package.json | 2 +- packages/eslint-config/package.json | 2 +- packages/staking/package.json | 2 +- packages/staking/solana/client.ts | 28 ++++++++++++++++++++++++++++ packages/staking/solana/types.ts | 6 ++++++ packages/stream/package.json | 2 +- 8 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lerna.json b/lerna.json index 6f14ab4..1ebe2f2 100644 --- a/lerna.json +++ b/lerna.json @@ -2,6 +2,6 @@ "packages": [ "packages/*" ], - "version": "7.0.0-alpha.18", + "version": "7.0.0-alpha.19", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/common/package.json b/packages/common/package.json index d3383ec..440785e 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/common", - "version": "7.0.0-alpha.18", + "version": "7.0.0-alpha.19", "description": "Common utilities and types used by streamflow packages.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "./dist/esm/index.js", diff --git a/packages/distributor/package.json b/packages/distributor/package.json index 30d2868..627a399 100644 --- a/packages/distributor/package.json +++ b/packages/distributor/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/distributor", - "version": "7.0.0-alpha.18", + "version": "7.0.0-alpha.19", "description": "JavaScript SDK to interact with Streamflow Airdrop protocol.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "dist/esm/index.js", diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index fabeb8d..eb2aff3 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/eslint-config", - "version": "7.0.0-alpha.18", + "version": "7.0.0-alpha.19", "license": "ISC", "main": "index.js", "files": [ diff --git a/packages/staking/package.json b/packages/staking/package.json index aefb0f4..20956b1 100644 --- a/packages/staking/package.json +++ b/packages/staking/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/staking", - "version": "7.0.0-alpha.18", + "version": "7.0.0-alpha.19", "description": "JavaScript SDK to interact with Streamflow Staking protocol.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "dist/esm/index.js", diff --git a/packages/staking/solana/client.ts b/packages/staking/solana/client.ts index d7990fe..28b825a 100644 --- a/packages/staking/solana/client.ts +++ b/packages/staking/solana/client.ts @@ -61,6 +61,7 @@ import { StakeEntry, StakePool, UnstakeArgs, + UpdateRewardPoolArgs, } from "./types.js"; interface Programs { @@ -460,6 +461,33 @@ export class SolanaStakingClient { return { ixs: [instruction] }; } + async updateRewardPool(data: UpdateRewardPoolArgs, extParams: IInteractSolanaExt) { + const { ixs } = await this.prepareUpdateRewardPoolInstructions(data, extParams); + const { signature } = await this.execute(ixs, extParams); + + return { + ixs, + txId: signature, + }; + } + + async prepareUpdateRewardPoolInstructions( + { rewardPool, rewardAmount, rewardPeriod }: UpdateRewardPoolArgs, + extParams: IInteractSolanaExt, + ) { + const { rewardPoolProgram } = this.programs; + const invoker = extParams.invoker.publicKey; + invariant(invoker, "Undefined invoker publicKey"); + const instruction = await rewardPoolProgram.methods + .updatePool(rewardAmount, rewardPeriod) + .accounts({ + rewardPool, + }) + .instruction(); + + return { ixs: [instruction] }; + } + decode< ProgramName extends keyof Programs = keyof Programs, DecodingProgram = Programs[ProgramName], diff --git a/packages/staking/solana/types.ts b/packages/staking/solana/types.ts index d9a6f15..bcc8e3b 100644 --- a/packages/staking/solana/types.ts +++ b/packages/staking/solana/types.ts @@ -62,6 +62,12 @@ export interface CreateRewardPoolArgs extends BaseStakePoolArgs, TokenProgram { permissionless: boolean; } +export interface UpdateRewardPoolArgs { + rewardAmount: BN | null; + rewardPeriod: BN | null; + rewardPool: Address; +} + export interface ClaimRewardPoolArgs extends BaseStakePoolArgs, TokenProgram { depositNonce: number; rewardMint: Address; diff --git a/packages/stream/package.json b/packages/stream/package.json index 30c4e86..87720fa 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/stream", - "version": "7.0.0-alpha.18", + "version": "7.0.0-alpha.19", "description": "JavaScript SDK to interact with Streamflow protocol.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "./dist/esm/index.js",