Skip to content

Commit

Permalink
Merge pull request #233 from streamflow-finance/v7
Browse files Browse the repository at this point in the history
off curve ATAs (multisig cases) - allow passing reward pools claim delta
  • Loading branch information
RolginRoman authored Nov 19, 2024
2 parents 7e27392 + 0a0bf72 commit 9b87d1b
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"packages": [
"packages/*"
],
"version": "7.0.2",
"version": "7.0.3",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/common",
"version": "7.0.2",
"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",
Expand Down
2 changes: 1 addition & 1 deletion packages/distributor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/distributor",
"version": "7.0.2",
"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",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/eslint-config",
"version": "7.0.2",
"version": "7.0.3",
"license": "ISC",
"main": "index.js",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions packages/staking/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/staking",
"version": "7.0.2",
"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",
Expand All @@ -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": {
Expand Down
22 changes: 12 additions & 10 deletions packages/staking/solana/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -331,6 +331,7 @@ export class SolanaStakingClient {
rewardMint,
permissionless = false,
stakePool,
lastClaimPeriodOpt,
tokenProgramId = TOKEN_PROGRAM_ID,
}: CreateRewardPoolArgs,
extParams: IInteractSolanaExt,
Expand All @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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();

Expand All @@ -472,7 +473,7 @@ export class SolanaStakingClient {
}

async prepareUpdateRewardPoolInstructions(
{ rewardPool, rewardAmount, rewardPeriod }: UpdateRewardPoolArgs,
{ rewardPool, rewardAmount, rewardPeriod, stakePool }: UpdateRewardPoolArgs,
extParams: IInteractSolanaExt,
) {
const { rewardPoolProgram } = this.programs;
Expand All @@ -481,6 +482,7 @@ export class SolanaStakingClient {
const instruction = await rewardPoolProgram.methods
.updatePool(rewardAmount, rewardPeriod)
.accountsPartial({
stakePool,
authority: invoker,
rewardPool,
})
Expand Down
30 changes: 28 additions & 2 deletions packages/staking/solana/descriptor/idl/reward_pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@
{
"name": "permissionless",
"type": "bool"
},
{
"name": "last_claim_period_opt",
"type": {
"option": "u64"
}
}
]
},
Expand Down Expand Up @@ -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
}
],
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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]
}
}
]
Expand Down
30 changes: 28 additions & 2 deletions packages/staking/solana/descriptor/reward_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ export type RewardPool = {
name: "permissionless";
type: "bool";
},
{
name: "lastClaimPeriodOpt";
type: {
option: "u64";
};
},
];
},
{
Expand Down Expand Up @@ -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;
},
];
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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];
};
},
];
Expand Down
3 changes: 3 additions & 0 deletions packages/staking/solana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/stream",
"version": "7.0.2",
"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",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 9b87d1b

Please sign in to comment.