Skip to content

Commit

Permalink
fix: remove vote ix from stake tx
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStefan committed Feb 7, 2024
1 parent f327b88 commit 6e321c0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 69 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v5.0.10

### Fix:

- Remove directed vote instruction from stake transaction to prevent accidental vote reset

## v5.0.9

### Fix:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
62 changes: 9 additions & 53 deletions src/marinade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from './util/anchor'
import {
DepositOptions,
DepositStakeAccountOptions,
ErrorMessage,
MarinadeResult,
ValidatorStats,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<MarinadeResult.DepositStakeAccount> {
const stakeAccountInfo = await getParsedStakeAccountInfo(
this.provider,
Expand All @@ -459,8 +449,7 @@ export class Marinade {
return this.depositStakeAccountByAccount(
stakeAccountInfo,
rent,
marinadeState,
options
marinadeState
)
}

Expand All @@ -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<MarinadeResult.DepositDeactivatingStakeAccount> {
const ownerAddress = assertNotNullAndReturn(
this.config.publicKey,
Expand Down Expand Up @@ -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,
Expand All @@ -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<MarinadeResult.DepositStakeAccount> {
const ownerAddress = assertNotNullAndReturn(
this.config.publicKey,
Expand Down Expand Up @@ -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,
Expand All @@ -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<MarinadeResult.PartiallyDepositStakeAccount> {
const ownerAddress = assertNotNullAndReturn(
this.config.publicKey,
Expand Down Expand Up @@ -745,8 +714,7 @@ export class Marinade {
} = await this.depositStakeAccountByAccount(
stakeAccountInfo,
rent,
marinadeState,
options
marinadeState
)

splitStakeTx.instructions.push(...depositTx.instructions)
Expand All @@ -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<MarinadeResult.PartiallyDepositStakeAccount> {
const ownerAddress = assertNotNullAndReturn(
this.config.publicKey,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -1167,8 +1131,7 @@ export class Marinade {
async depositStakePoolToken(
stakePoolTokenAddress: web3.PublicKey,
amountToDeposit: number,
validators: ValidatorStats[],
options: DepositOptions = {}
validators: ValidatorStats[]
): Promise<MarinadeResult.LiquidateStakePoolToken> {
const marinadeState = await this.getMarinadeState()
const ownerAddress = assertNotNullAndReturn(
Expand Down Expand Up @@ -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')

Expand Down
11 changes: 0 additions & 11 deletions src/marinade.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 14 additions & 4 deletions test/marinade-finance-instructions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
[],
Expand Down

0 comments on commit 6e321c0

Please sign in to comment.