Skip to content

Commit

Permalink
Merge pull request #63 from marinade-finance/fix/update-directed-stak…
Browse files Browse the repository at this point in the history
…e-sdk

Fix/update directed stake sdk
  • Loading branch information
AlexStefan authored Feb 1, 2024
2 parents 96f3c28 + 8b63ca0 commit 5186d89
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v5.0.8

### Fix:

- Update directed stake sdk and method call
- Add warning about low liquidity on unstake via our pool

## v5.0.7

### Feat:
Expand Down
Binary file modified fixtures/programs/directed_stake.so
100755 → 100644
Binary file not shown.
4 changes: 2 additions & 2 deletions 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.7",
"version": "5.0.8",
"description": "Marinade SDK for Typescript",
"main": "dist/src/index.js",
"repository": {
Expand Down Expand Up @@ -36,7 +36,7 @@
"license": "ISC",
"dependencies": {
"@coral-xyz/anchor": "^0.28.0",
"@marinade.finance/directed-stake-sdk": "^0.0.4",
"@marinade.finance/directed-stake-sdk": "^0.1.0",
"@marinade.finance/native-staking-sdk": "^1.0.0",
"@solana/spl-stake-pool": "^0.6.5",
"@solana/spl-token-3.x": "npm:@solana/spl-token@^0.3.8",
Expand Down
14 changes: 8 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions src/marinade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class Marinade {
return (
await withCreateVote({
sdk: this.directedStakeSdk,
validatorVote: validatorVoteAddress,
target: validatorVoteAddress,
})
).instruction
}
Expand All @@ -306,7 +306,7 @@ export class Marinade {
return (
await withUpdateVote({
sdk: this.directedStakeSdk,
validatorVote: validatorVoteAddress,
target: validatorVoteAddress,
voteRecord: voteRecord.publicKey,
})
).instruction
Expand Down Expand Up @@ -367,7 +367,7 @@ export class Marinade {
transaction.add(depositInstruction)

const directedStakeInstruction = await this.createDirectedStakeVoteIx(
options.directToValidatorVoteAddress
options.directedTarget
)
if (directedStakeInstruction) {
transaction.add(directedStakeInstruction)
Expand All @@ -380,6 +380,10 @@ export class Marinade {
}

/**
* * ⚠️ WARNING ⚠️ The liquidity in the pool for this swap is typically low,
* which can result in high transaction fees. It is advisable to consider
* Jup swap API or proceed with caution.
*
* Returns a transaction with the instructions to
* Swap your mSOL to get back SOL immediately using the liquidity pool
*
Expand Down Expand Up @@ -827,7 +831,7 @@ export class Marinade {

const { transaction: depositTx, associatedMSolTokenAccountAddress } =
await this.deposit(lamportsToWithdraw, {
directToValidatorVoteAddress: options.directToValidatorVoteAddress,
directedTarget: options.directToValidatorVoteAddress,
})

transaction.instructions.push(...depositTx.instructions)
Expand Down Expand Up @@ -1072,7 +1076,10 @@ export class Marinade {
* @param {BN} msolAmount - The amount of mSOL in lamports to order for unstaking
* @param {PublicKey} ticketAccountPublicKey - The public key of the ticket account that will sign the transaction
*/
async orderUnstakeWithPublicKey(msolAmount: BN, ticketAccountPublicKey: PublicKey): Promise<MarinadeResult.OrderUnstakeWithPublicKey> {
async orderUnstakeWithPublicKey(
msolAmount: BN,
ticketAccountPublicKey: PublicKey
): Promise<MarinadeResult.OrderUnstakeWithPublicKey> {
const ownerAddress = assertNotNullAndReturn(
this.config.publicKey,
ErrorMessage.NO_PUBLIC_KEY
Expand Down Expand Up @@ -1243,7 +1250,7 @@ export class Marinade {
instructions.push(depositInstruction)

const directedStakeInstruction = await this.createDirectedStakeVoteIx(
options.directToValidatorVoteAddress
options.directedTarget
)
if (directedStakeInstruction) {
instructions.push(directedStakeInstruction)
Expand Down
4 changes: 2 additions & 2 deletions src/marinade.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export interface DepositOptions {
*/
mintToOwnerAddress?: web3.PublicKey
/**
* The vote address of the validator to direct your stake to.
* The vote address of the validator or Marinade Algorithmic Delegation strategy to direct your stake to.
*/
directToValidatorVoteAddress?: web3.PublicKey
directedTarget?: web3.PublicKey
}

export interface DepositStakeAccountOptions {
Expand Down
8 changes: 4 additions & 4 deletions test/marinade-finance-instructions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Marinade Finance', () => {

const { transaction } = await marinade.deposit(
MarinadeUtils.solToLamports(0.01),
{ directToValidatorVoteAddress: validatorVoteAddress }
{ directedTarget: validatorVoteAddress }
)
let transactionSignature: string
try {
Expand All @@ -147,7 +147,7 @@ describe('Marinade Finance', () => {
})
)[0]

expect(voteRecord.account.validatorVote).toEqual(validatorVoteAddress)
expect(voteRecord.account.target).toEqual(validatorVoteAddress)
})

it('deposit SOL and redirect the stake', async () => {
Expand All @@ -172,7 +172,7 @@ describe('Marinade Finance', () => {

const { transaction } = await marinade.deposit(
MarinadeUtils.solToLamports(0.01),
{ directToValidatorVoteAddress: validatorVoteAddress2 }
{ directedTarget: validatorVoteAddress2 }
)
const transactionSignature = await TestWorld.PROVIDER.sendAndConfirm(
transaction,
Expand All @@ -192,7 +192,7 @@ describe('Marinade Finance', () => {
})
)[0]

expect(voteRecord?.account.validatorVote).toEqual(validatorVoteAddress2)
expect(voteRecord?.account.target).toEqual(validatorVoteAddress2)
})

it('deposit SOL and undirect the stake', async () => {
Expand Down

0 comments on commit 5186d89

Please sign in to comment.