From 6e321c062b155a3a9502e0bd4f85892f9e08ecf7 Mon Sep 17 00:00:00 2001 From: Alexandru Stefan Date: Wed, 7 Feb 2024 10:03:25 +0200 Subject: [PATCH] fix: remove vote ix from stake tx --- CHANGELOG.md | 6 +++ package.json | 2 +- src/marinade.ts | 62 ++++------------------ src/marinade.types.ts | 11 ---- test/marinade-finance-instructions.spec.ts | 18 +++++-- 5 files changed, 30 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76033a3..5a7d024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v5.0.10 + +### Fix: + + - Remove directed vote instruction from stake transaction to prevent accidental vote reset + ## v5.0.9 ### Fix: diff --git a/package.json b/package.json index a7cf83f..2e806f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@marinade.finance/marinade-ts-sdk", - "version": "5.0.9", + "version": "5.0.10", "description": "Marinade SDK for Typescript", "main": "dist/src/index.js", "repository": { diff --git a/src/marinade.ts b/src/marinade.ts index c2944d9..75fc4e1 100644 --- a/src/marinade.ts +++ b/src/marinade.ts @@ -15,7 +15,6 @@ import { } from './util/anchor' import { DepositOptions, - DepositStakeAccountOptions, ErrorMessage, MarinadeResult, ValidatorStats, @@ -366,13 +365,6 @@ export class Marinade { transaction.add(depositInstruction) - const directedStakeInstruction = await this.createDirectedStakeVoteIx( - options.directedTarget - ) - if (directedStakeInstruction) { - transaction.add(directedStakeInstruction) - } - return { associatedMSolTokenAccountAddress, transaction, @@ -440,11 +432,9 @@ export class Marinade { * Note that the stake must be fully activated and the validator must be known to Marinade * * @param {web3.PublicKey} stakeAccountAddress - The account to be deposited - * @param {DepositStakeAccountOptions} options - Additional deposit options */ async depositStakeAccount( - stakeAccountAddress: web3.PublicKey, - options: DepositStakeAccountOptions = {} + stakeAccountAddress: web3.PublicKey ): Promise { const stakeAccountInfo = await getParsedStakeAccountInfo( this.provider, @@ -459,8 +449,7 @@ export class Marinade { return this.depositStakeAccountByAccount( stakeAccountInfo, rent, - marinadeState, - options + marinadeState ) } @@ -472,11 +461,9 @@ export class Marinade { * Note that the stake must be deactivating and the validator must be known to Marinade * * @param {web3.PublicKey} stakeAccountAddress - The account to be deposited - * @param {DepositStakeAccountOptions} options - Additional deposit options */ async depositDeactivatingStakeAccount( - stakeAccountAddress: web3.PublicKey, - options: DepositStakeAccountOptions = {} + stakeAccountAddress: web3.PublicKey ): Promise { const ownerAddress = assertNotNullAndReturn( this.config.publicKey, @@ -541,13 +528,6 @@ export class Marinade { delegateTransaction.instructions.push(depositInstruction) - const directedStakeInstruction = await this.createDirectedStakeVoteIx( - options.directedTarget - ) - if (directedStakeInstruction) { - delegateTransaction.add(directedStakeInstruction) - } - return { transaction: delegateTransaction, associatedMSolTokenAccountAddress, @@ -562,13 +542,11 @@ export class Marinade { * @param {ParsedStakeAccountInfo} stakeAccountInfo - Parsed Stake Account info * @param {number} rent - Rent needed for a stake account * @param {MarinadeState} marinadeState - Marinade State needed for retrieving validator info - * @param {DepositStakeAccountOptions} options - Additional deposit options */ async depositStakeAccountByAccount( stakeAccountInfo: ParsedStakeAccountInfo, rent: number, - marinadeState: MarinadeState, - options: DepositStakeAccountOptions = {} + marinadeState: MarinadeState ): Promise { const ownerAddress = assertNotNullAndReturn( this.config.publicKey, @@ -671,13 +649,6 @@ export class Marinade { transaction.add(depositStakeAccountInstruction) - const directedStakeInstruction = await this.createDirectedStakeVoteIx( - options.directedTarget - ) - if (directedStakeInstruction) { - transaction.add(directedStakeInstruction) - } - return { associatedMSolTokenAccountAddress, voterAddress, @@ -699,12 +670,10 @@ export class Marinade { * * @param {web3.PublicKey} stakeAccountAddress - The account to be deposited * @param {BN} solToKeep - Amount of SOL lamports to keep - * @param {DepositStakeAccountOptions} options - Additional deposit options */ async partiallyDepositStakeAccount( stakeAccountAddress: web3.PublicKey, - solToKeep: BN, - options: DepositStakeAccountOptions = {} + solToKeep: BN ): Promise { const ownerAddress = assertNotNullAndReturn( this.config.publicKey, @@ -745,8 +714,7 @@ export class Marinade { } = await this.depositStakeAccountByAccount( stakeAccountInfo, rent, - marinadeState, - options + marinadeState ) splitStakeTx.instructions.push(...depositTx.instructions) @@ -771,12 +739,10 @@ export class Marinade { * * @param {web3.PublicKey} stakeAccountAddress - The account to be deposited * @param {BN} solToKeep - Amount of SOL lamports to keep as a stake account - * @param {DepositStakeAccountOptions} options - Additional deposit options */ async depositActivatingStakeAccount( stakeAccountAddress: web3.PublicKey, - solToKeep: BN, - options: DepositStakeAccountOptions = {} + solToKeep: BN ): Promise { const ownerAddress = assertNotNullAndReturn( this.config.publicKey, @@ -830,9 +796,7 @@ export class Marinade { transaction.add(...withdrawTx.instructions) const { transaction: depositTx, associatedMSolTokenAccountAddress } = - await this.deposit(lamportsToWithdraw, { - directedTarget: options.directedTarget, - }) + await this.deposit(lamportsToWithdraw) transaction.instructions.push(...depositTx.instructions) @@ -1167,8 +1131,7 @@ export class Marinade { async depositStakePoolToken( stakePoolTokenAddress: web3.PublicKey, amountToDeposit: number, - validators: ValidatorStats[], - options: DepositOptions = {} + validators: ValidatorStats[] ): Promise { const marinadeState = await this.getMarinadeState() const ownerAddress = assertNotNullAndReturn( @@ -1249,13 +1212,6 @@ export class Marinade { instructions.push(depositInstruction) - const directedStakeInstruction = await this.createDirectedStakeVoteIx( - options.directedTarget - ) - if (directedStakeInstruction) { - instructions.push(directedStakeInstruction) - } - const { blockhash: recentBlockhash } = await this.config.connection.getLatestBlockhash('finalized') diff --git a/src/marinade.types.ts b/src/marinade.types.ts index 497c67c..4153a85 100644 --- a/src/marinade.types.ts +++ b/src/marinade.types.ts @@ -77,17 +77,6 @@ export interface DepositOptions { * The address of the owner account for the associated mSOL account. */ mintToOwnerAddress?: web3.PublicKey - /** - * The vote address of the validator or Marinade Algorithmic Delegation strategy to direct your stake to. - */ - directedTarget?: web3.PublicKey -} - -export interface DepositStakeAccountOptions { - /** - * The vote address of the validator or Marinade Algorithmic Delegation strategy to direct your stake to. - */ - directedTarget?: web3.PublicKey } export interface ValidatorStats { diff --git a/test/marinade-finance-instructions.spec.ts b/test/marinade-finance-instructions.spec.ts index 4599443..755880d 100644 --- a/test/marinade-finance-instructions.spec.ts +++ b/test/marinade-finance-instructions.spec.ts @@ -120,9 +120,14 @@ describe('Marinade Finance', () => { }) const { transaction } = await marinade.deposit( - MarinadeUtils.solToLamports(0.01), - { directedTarget: validatorVoteAddress } + MarinadeUtils.solToLamports(0.01) + ) + + const voteIx = await marinade.createDirectedStakeVoteIx( + validatorVoteAddress ) + if (voteIx) transaction.instructions.push(voteIx) + let transactionSignature: string try { transactionSignature = await TestWorld.PROVIDER.sendAndConfirm( @@ -171,9 +176,14 @@ describe('Marinade Finance', () => { }) const { transaction } = await marinade.deposit( - MarinadeUtils.solToLamports(0.01), - { directedTarget: validatorVoteAddress2 } + MarinadeUtils.solToLamports(0.01) + ) + + const voteIx = await marinade.createDirectedStakeVoteIx( + validatorVoteAddress2 ) + if (voteIx) transaction.instructions.push(voteIx) + const transactionSignature = await TestWorld.PROVIDER.sendAndConfirm( transaction, [],