From ac51215a39a294c3e1de4f028c9c6445d3e5779c Mon Sep 17 00:00:00 2001 From: "roman.rolgin" Date: Mon, 18 Nov 2024 14:30:21 +0100 Subject: [PATCH 1/3] - off curve ATAs (multisig cases); - allow passing reward pools claim delta --- packages/staking/package.json | 4 +-- packages/staking/solana/client.ts | 22 +++++++------- .../solana/descriptor/idl/reward_pool.json | 30 +++++++++++++++++-- .../staking/solana/descriptor/reward_pool.ts | 30 +++++++++++++++++-- packages/staking/solana/types.ts | 3 ++ packages/stream/package.json | 4 +-- 6 files changed, 75 insertions(+), 18 deletions(-) diff --git a/packages/staking/package.json b/packages/staking/package.json index 734a1f5..eebce14 100644 --- a/packages/staking/package.json +++ b/packages/staking/package.json @@ -25,7 +25,7 @@ "pack": "pnpm build && pnpm pack", "lint": "eslint --fix .", "test": "vitest", - "prepublishOnly": "npm run lint && npm run build" + "prepublishOnly": "pnpm run lint && pnpm run test run && pnpm run build" }, "gitHead": "a37306eba0e762af096db642fa22f07194014cfd", "devDependencies": { @@ -46,4 +46,4 @@ "bs58": "5.0.0", "p-queue": "^8.0.1" } -} +} \ No newline at end of file diff --git a/packages/staking/solana/client.ts b/packages/staking/solana/client.ts index 52eb324..84a22aa 100644 --- a/packages/staking/solana/client.ts +++ b/packages/staking/solana/client.ts @@ -258,8 +258,8 @@ export class SolanaStakingClient { const staker = extParams.invoker.publicKey; invariant(staker, "Undefined invoker publicKey"); const mint = deriveStakeMintPDA(stakePoolProgram.programId, pk(stakePool)); - const stakeMintAccountKey = getAssociatedTokenAddressSync(mint, staker, false, pk(tokenProgramId)); - const poolMintAccountKey = getAssociatedTokenAddressSync(pk(stakePoolMint), staker, false, pk(tokenProgramId)); + const stakeMintAccountKey = getAssociatedTokenAddressSync(mint, staker, true, pk(tokenProgramId)); + const poolMintAccountKey = getAssociatedTokenAddressSync(pk(stakePoolMint), staker, true, pk(tokenProgramId)); const instruction = await stakePoolProgram.methods .stake(nonce, amount, duration) .accounts({ @@ -296,8 +296,8 @@ export class SolanaStakingClient { invariant(staker, "Undefined invoker publicKey"); const stakeMintKey = deriveStakeMintPDA(stakePoolProgram.programId, pk(stakePool)); const stakeEntryKey = deriveStakeEntryPDA(stakePoolProgram.programId, pk(stakePool), staker, nonce); - const poolMintAccountKey = getAssociatedTokenAddressSync(pk(stakePoolMint), staker, false, pk(tokenProgramId)); - const stakeMintAccountKey = getAssociatedTokenAddressSync(stakeMintKey, staker, false, pk(tokenProgramId)); + const poolMintAccountKey = getAssociatedTokenAddressSync(pk(stakePoolMint), staker, true, pk(tokenProgramId)); + const stakeMintAccountKey = getAssociatedTokenAddressSync(stakeMintKey, staker, true, pk(tokenProgramId)); const instruction = await stakePoolProgram.methods .unstake() .accounts({ @@ -331,6 +331,7 @@ export class SolanaStakingClient { rewardMint, permissionless = false, stakePool, + lastClaimPeriodOpt, tokenProgramId = TOKEN_PROGRAM_ID, }: CreateRewardPoolArgs, extParams: IInteractSolanaExt, @@ -339,7 +340,7 @@ export class SolanaStakingClient { const creator = extParams.invoker.publicKey; invariant(creator, "Undefined invoker publicKey"); const instruction = await rewardPoolProgram.methods - .createPool(nonce, rewardAmount, rewardPeriod, permissionless) + .createPool(nonce, rewardAmount, rewardPeriod, permissionless, lastClaimPeriodOpt) .accounts({ creator, stakePool, @@ -377,7 +378,7 @@ export class SolanaStakingClient { rewardPool: deriveRewardPoolPDA(rewardPoolProgram.programId, pk(stakePool), pk(rewardMint), rewardPoolNonce), claimant: staker, tokenProgram: tokenProgramId, - to: getAssociatedTokenAddressSync(pk(rewardMint), staker, false, pk(tokenProgramId)), + to: getAssociatedTokenAddressSync(pk(rewardMint), staker, true, pk(tokenProgramId)), }) .instruction(); @@ -420,7 +421,7 @@ export class SolanaStakingClient { .accountsPartial({ funder: staker, rewardPool: rewardPoolPda, - from: getAssociatedTokenAddressSync(rewardMintPk, staker, false, tokenProgramPk), + from: getAssociatedTokenAddressSync(rewardMintPk, staker, true, tokenProgramPk), tokenProgram: tokenProgramId, vault: deriveRewardVaultPDA(rewardPoolProgram.programId, rewardPoolPda), mint: rewardMint, @@ -442,7 +443,7 @@ export class SolanaStakingClient { } async prepareCreateRewardEntryInstructions( - { stakePoolMint, stakePool, rewardPoolNonce, depositNonce }: CreateRewardEntryArgs, + { stakePool, rewardPoolNonce, depositNonce, rewardMint }: CreateRewardEntryArgs, extParams: IInteractSolanaExt, ) { const { stakePoolProgram, rewardPoolProgram } = this.programs; @@ -454,7 +455,7 @@ export class SolanaStakingClient { payer: staker, authority: staker, stakeEntry: deriveStakeEntryPDA(stakePoolProgram.programId, pk(stakePool), staker, depositNonce), - rewardPool: deriveRewardPoolPDA(rewardPoolProgram.programId, pk(stakePool), pk(stakePoolMint), rewardPoolNonce), + rewardPool: deriveRewardPoolPDA(rewardPoolProgram.programId, pk(stakePool), pk(rewardMint), rewardPoolNonce), }) .instruction(); @@ -472,7 +473,7 @@ export class SolanaStakingClient { } async prepareUpdateRewardPoolInstructions( - { rewardPool, rewardAmount, rewardPeriod }: UpdateRewardPoolArgs, + { rewardPool, rewardAmount, rewardPeriod, stakePool }: UpdateRewardPoolArgs, extParams: IInteractSolanaExt, ) { const { rewardPoolProgram } = this.programs; @@ -481,6 +482,7 @@ export class SolanaStakingClient { const instruction = await rewardPoolProgram.methods .updatePool(rewardAmount, rewardPeriod) .accountsPartial({ + stakePool, authority: invoker, rewardPool, }) diff --git a/packages/staking/solana/descriptor/idl/reward_pool.json b/packages/staking/solana/descriptor/idl/reward_pool.json index 6e06423..3370285 100644 --- a/packages/staking/solana/descriptor/idl/reward_pool.json +++ b/packages/staking/solana/descriptor/idl/reward_pool.json @@ -278,6 +278,12 @@ { "name": "permissionless", "type": "bool" + }, + { + "name": "last_claim_period_opt", + "type": { + "option": "u64" + } } ] }, @@ -407,9 +413,14 @@ "signer": true, "relations": ["reward_pool"] }, + { + "name": "stake_pool", + "docs": ["Stake Pool to Which Reward Pool belongs"], + "relations": ["reward_pool"] + }, { "name": "reward_pool", - "docs": ["Stake Pool"], + "docs": ["Reward Pool"], "writable": true } ], @@ -520,6 +531,16 @@ "code": 6012, "name": "RewardPoolDrained", "msg": "Reward Pool does not have enough Rewards for Claiming" + }, + { + "code": 6013, + "name": "UpdateTooSoon", + "msg": "Repeated update can not happen sooner than the stake pool max duration" + }, + { + "code": 6014, + "name": "InvalidLastClaimPeriod", + "msg": "Invalid last claim period provided" } ], "types": [ @@ -731,11 +752,16 @@ "docs": ["Time when Reward Pool was created"], "type": "u64" }, + { + "name": "last_claim_period", + "docs": ["For how much seconds after unstake user should be able to claim rewards"], + "type": "u64" + }, { "name": "_buffer", "docs": ["Buffer for additional fields"], "type": { - "array": ["u8", 56] + "array": ["u8", 48] } } ] diff --git a/packages/staking/solana/descriptor/reward_pool.ts b/packages/staking/solana/descriptor/reward_pool.ts index 5df0096..e0a4147 100644 --- a/packages/staking/solana/descriptor/reward_pool.ts +++ b/packages/staking/solana/descriptor/reward_pool.ts @@ -285,6 +285,12 @@ export type RewardPool = { name: "permissionless"; type: "bool"; }, + { + name: "lastClaimPeriodOpt"; + type: { + option: "u64"; + }; + }, ]; }, { @@ -443,9 +449,14 @@ export type RewardPool = { signer: true; relations: ["rewardPool"]; }, + { + name: "stakePool"; + docs: ["Stake Pool to Which Reward Pool belongs"]; + relations: ["rewardPool"]; + }, { name: "rewardPool"; - docs: ["Stake Pool"]; + docs: ["Reward Pool"]; writable: true; }, ]; @@ -557,6 +568,16 @@ export type RewardPool = { name: "rewardPoolDrained"; msg: "Reward Pool does not have enough Rewards for Claiming"; }, + { + code: 6013; + name: "updateTooSoon"; + msg: "Repeated update can not happen sooner than the stake pool max duration"; + }, + { + code: 6014; + name: "invalidLastClaimPeriod"; + msg: "Invalid last claim period provided"; + }, ]; types: [ { @@ -767,11 +788,16 @@ export type RewardPool = { docs: ["Time when Reward Pool was created"]; type: "u64"; }, + { + name: "lastClaimPeriod"; + docs: ["For how much seconds after unstake user should be able to claim rewards"]; + type: "u64"; + }, { name: "buffer"; docs: ["Buffer for additional fields"]; type: { - array: ["u8", 56]; + array: ["u8", 48]; }; }, ]; diff --git a/packages/staking/solana/types.ts b/packages/staking/solana/types.ts index bcc8e3b..a370b1e 100644 --- a/packages/staking/solana/types.ts +++ b/packages/staking/solana/types.ts @@ -51,6 +51,7 @@ export interface FundPoolArgs extends BaseStakePoolArgs, TokenProgram { export interface CreateRewardEntryArgs extends BaseStakePoolArgs, TokenProgram { depositNonce: number; rewardPoolNonce: number; + rewardMint: Address; } export interface CreateRewardPoolArgs extends BaseStakePoolArgs, TokenProgram { @@ -60,9 +61,11 @@ export interface CreateRewardPoolArgs extends BaseStakePoolArgs, TokenProgram { rewardAmount: BN; rewardPeriod: BN; permissionless: boolean; + lastClaimPeriodOpt: BN | null; } export interface UpdateRewardPoolArgs { + stakePool: Address; rewardAmount: BN | null; rewardPeriod: BN | null; rewardPool: Address; diff --git a/packages/stream/package.json b/packages/stream/package.json index 6ea9588..4ca509c 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -40,7 +40,7 @@ "pack": "pnpm build && pnpm pack", "test": "vitest", "lint": "eslint --fix .", - "prepublishOnly": "npm run lint && npm test && npm run build" + "prepublishOnly": "pnpm run lint && pnpm run test run && pnpm run build" }, "gitHead": "a37306eba0e762af096db642fa22f07194014cfd", "devDependencies": { @@ -69,4 +69,4 @@ "ethers": "5.7.2", "p-queue": "^8.0.1" } -} +} \ No newline at end of file From eadb9d51b2f4300ef95529ff3d5dc97453085a60 Mon Sep 17 00:00:00 2001 From: "roman.rolgin" Date: Mon, 18 Nov 2024 14:52:50 +0100 Subject: [PATCH 2/3] b 7.0.3-alpha.0 --- lerna.json | 2 +- packages/common/package.json | 2 +- packages/distributor/package.json | 2 +- packages/eslint-config/package.json | 2 +- packages/staking/package.json | 4 ++-- packages/stream/package.json | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lerna.json b/lerna.json index 630312c..8c9fe84 100644 --- a/lerna.json +++ b/lerna.json @@ -2,6 +2,6 @@ "packages": [ "packages/*" ], - "version": "7.0.2", + "version": "7.0.3-alpha.0", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/common/package.json b/packages/common/package.json index 81ca277..2d519cd 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/common", - "version": "7.0.2", + "version": "7.0.3-alpha.0", "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 fbc3893..46563a9 100644 --- a/packages/distributor/package.json +++ b/packages/distributor/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/distributor", - "version": "7.0.2", + "version": "7.0.3-alpha.0", "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 6bc2ce8..26aabd0 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/eslint-config", - "version": "7.0.2", + "version": "7.0.3-alpha.0", "license": "ISC", "main": "index.js", "files": [ diff --git a/packages/staking/package.json b/packages/staking/package.json index eebce14..8e61c96 100644 --- a/packages/staking/package.json +++ b/packages/staking/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/staking", - "version": "7.0.2", + "version": "7.0.3-alpha.0", "description": "JavaScript SDK to interact with Streamflow Staking protocol.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "dist/esm/index.js", @@ -46,4 +46,4 @@ "bs58": "5.0.0", "p-queue": "^8.0.1" } -} \ No newline at end of file +} diff --git a/packages/stream/package.json b/packages/stream/package.json index 4ca509c..a869e3e 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/stream", - "version": "7.0.2", + "version": "7.0.3-alpha.0", "description": "JavaScript SDK to interact with Streamflow protocol.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "./dist/esm/index.js", @@ -69,4 +69,4 @@ "ethers": "5.7.2", "p-queue": "^8.0.1" } -} \ No newline at end of file +} From 0a0bf72d80dd16c5ce4cb8af92bf9b738b0f1258 Mon Sep 17 00:00:00 2001 From: "roman.rolgin" Date: Tue, 19 Nov 2024 12:29:10 +0100 Subject: [PATCH 3/3] bump 7.0.3 --- 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/stream/package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lerna.json b/lerna.json index 8c9fe84..d51dd73 100644 --- a/lerna.json +++ b/lerna.json @@ -2,6 +2,6 @@ "packages": [ "packages/*" ], - "version": "7.0.3-alpha.0", + "version": "7.0.3", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/packages/common/package.json b/packages/common/package.json index 2d519cd..4ed62ae 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/common", - "version": "7.0.3-alpha.0", + "version": "7.0.3", "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 46563a9..9e27026 100644 --- a/packages/distributor/package.json +++ b/packages/distributor/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/distributor", - "version": "7.0.3-alpha.0", + "version": "7.0.3", "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 26aabd0..1436c4f 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/eslint-config", - "version": "7.0.3-alpha.0", + "version": "7.0.3", "license": "ISC", "main": "index.js", "files": [ diff --git a/packages/staking/package.json b/packages/staking/package.json index 8e61c96..6706f56 100644 --- a/packages/staking/package.json +++ b/packages/staking/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/staking", - "version": "7.0.3-alpha.0", + "version": "7.0.3", "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/stream/package.json b/packages/stream/package.json index a869e3e..ed6cbc7 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -1,6 +1,6 @@ { "name": "@streamflow/stream", - "version": "7.0.3-alpha.0", + "version": "7.0.3", "description": "JavaScript SDK to interact with Streamflow protocol.", "homepage": "https://github.com/streamflow-finance/js-sdk/", "main": "./dist/esm/index.js",