Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactoring-more-modu…
Browse files Browse the repository at this point in the history
…larity
  • Loading branch information
AlexStefan committed Feb 11, 2024
2 parents f9361d8 + 47d08aa commit 3ac3543
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 100 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
## v5.0.10

### Fix:

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

## v5.0.9

### Fix:

- Naming consistency

## 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:

- Add method to support delayed unstake with PublicKey instead of Keypair

## v5.0.6

### 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.6",
"version": "5.0.10",
"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.7.0",
"@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.

135 changes: 60 additions & 75 deletions src/marinade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
} from './util/anchor'
import {
DepositOptions,
DepositStakeAccountOptions,
MarinadeResult,
ValidatorStats,
} from './marinade.types'
Expand Down Expand Up @@ -43,10 +42,6 @@ import {
validatorDuplicationFlag,
} from './marinade-state/marinade-state'
import BN from 'bn.js'
import {
createDirectedStakeVoteIx,
getDirectedStakeSdk,
} from './marinade-directed-stake'
import { MarinadeProgram } from './programs/marinade-program'
import {
depositInstructionBuilder as marinadeDepositInstructionBuilder,
Expand Down Expand Up @@ -211,18 +206,6 @@ export async function deposit(

transaction.add(depositInstruction)

const directedStakeSdk = getDirectedStakeSdk(
marinadeProgram.provider.connection,
ownerAddress
)
const directedStakeInstruction = await createDirectedStakeVoteIx(
directedStakeSdk,
options.directToValidatorVoteAddress
)
if (directedStakeInstruction) {
transaction.add(directedStakeInstruction)
}

return {
associatedMSolTokenAccountAddress,
transaction,
Expand Down Expand Up @@ -304,13 +287,11 @@ export async function liquidUnstake(
* @param {MarinadeProgram} marinadeProgram - Instance providing marinade methods, backed by Anchor program
* @param {PublicKey} ownerAddress - The owner (staker authority) of the stake account to be deposited
* @param {PublicKey} stakeAccountAddress - The account to be deposited
* @param {DepositStakeAccountOptions} options - Additional deposit options
*/
export async function depositStakeAccount(
marinadeProgram: MarinadeProgram,
ownerAddress: PublicKey,
stakeAccountAddress: PublicKey,
options: DepositStakeAccountOptions = {}
stakeAccountAddress: PublicKey
): Promise<MarinadeResult.DepositStakeAccount> {
const stakeAccountInfo = await getParsedStakeAccountInfo(
marinadeProgram.provider.connection,
Expand All @@ -325,8 +306,7 @@ export async function depositStakeAccount(
marinadeProgram,
ownerAddress,
stakeAccountInfo,
rent,
options
rent
)
}

Expand All @@ -341,13 +321,11 @@ export async function depositStakeAccount(
* @param {MarinadeProgram} marinadeProgram - Instance providing marinade methods, backed by Anchor program
* @param {PublicKey} ownerAddress - The owner of the stake account to be deposited
* @param {PublicKey} stakeAccountAddress - The account to be deposited
* @param {DepositStakeAccountOptions} options - Additional deposit options
*/
export async function depositDeactivatingStakeAccount(
marinadeProgram: MarinadeProgram,
ownerAddress: PublicKey,
stakeAccountAddress: PublicKey,
options: DepositStakeAccountOptions = {}
stakeAccountAddress: PublicKey
): Promise<MarinadeResult.DepositDeactivatingStakeAccount> {
const stakeAccountInfo = await getParsedStakeAccountInfo(
marinadeProgram.provider.connection,
Expand Down Expand Up @@ -423,18 +401,6 @@ export async function depositDeactivatingStakeAccount(

delegateTransaction.instructions.push(depositInstruction)

const directedStakeSdk = getDirectedStakeSdk(
marinadeProgram.provider.connection,
ownerAddress
)
const directedStakeInstruction = await createDirectedStakeVoteIx(
directedStakeSdk,
options.directToValidatorVoteAddress
)
if (directedStakeInstruction) {
delegateTransaction.add(directedStakeInstruction)
}

return {
transaction: delegateTransaction,
associatedMSolTokenAccountAddress,
Expand All @@ -450,14 +416,12 @@ export async function depositDeactivatingStakeAccount(
* @param {PublicKey} ownerAddress - The owner (staker authority) of the stake account to be deposited
* @param {ParsedStakeAccountInfo} stakeAccountInfo - Parsed Stake Account info
* @param {number} rent - Rent needed for a stake account
* @param {DepositStakeAccountOptions} options - Additional deposit options
*/
export async function depositStakeAccountByAccount(
marinadeProgram: MarinadeProgram,
ownerAddress: PublicKey,
stakeAccountInfo: ParsedStakeAccountInfo,
rent: number,
options: DepositStakeAccountOptions = {}
rent: number
): Promise<MarinadeResult.DepositStakeAccount> {
const transaction = new Transaction()
const currentEpoch = await marinadeProgram.provider.connection.getEpochInfo()
Expand Down Expand Up @@ -576,18 +540,6 @@ export async function depositStakeAccountByAccount(

transaction.add(depositStakeAccountInstruction)

const directedStakeSdk = getDirectedStakeSdk(
marinadeProgram.provider.connection,
ownerAddress
)
const directedStakeInstruction = await createDirectedStakeVoteIx(
directedStakeSdk,
options.directToValidatorVoteAddress
)
if (directedStakeInstruction) {
transaction.add(directedStakeInstruction)
}

return {
associatedMSolTokenAccountAddress,
voterAddress,
Expand Down Expand Up @@ -617,8 +569,7 @@ export async function partiallyDepositStakeAccount(
marinadeProgram: MarinadeProgram,
ownerAddress: PublicKey,
stakeAccountAddress: PublicKey,
solToKeep: BN,
options: DepositStakeAccountOptions = {}
solToKeep: BN
): Promise<MarinadeResult.PartiallyDepositStakeAccount> {
const stakeAccountInfo = await getParsedStakeAccountInfo(
marinadeProgram.provider.connection,
Expand Down Expand Up @@ -654,8 +605,7 @@ export async function partiallyDepositStakeAccount(
marinadeProgram,
ownerAddress,
stakeAccountInfo,
rent,
options
rent
)

splitStakeTx.instructions.push(...depositTx.instructions)
Expand Down Expand Up @@ -688,8 +638,7 @@ export async function depositActivatingStakeAccount(
marinadeProgram: MarinadeProgram,
ownerAddress: PublicKey,
stakeAccountAddress: PublicKey,
solToKeep: BN,
options: DepositStakeAccountOptions = {}
solToKeep: BN
): Promise<MarinadeResult.PartiallyDepositStakeAccount> {
const stakeAccountInfo = await getParsedStakeAccountInfo(
marinadeProgram.provider.connection,
Expand Down Expand Up @@ -738,9 +687,7 @@ export async function depositActivatingStakeAccount(
transaction.add(...withdrawTx.instructions)

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

transaction.instructions.push(...depositTx.instructions)

Expand Down Expand Up @@ -962,6 +909,57 @@ export async function orderUnstake(
}
}

/**
* Returns a transaction with the instructions to
* Order Unstake to create a ticket which can be claimed later (with {@link claim}).
*
* @param {MarinadeProgram} marinadeProgram - Instance providing marinade methods, backed by Anchor program
* @param {PublicKey} ownerAddress - The owner of the tokens to be un-staked
* @param {PublicKey} ticketAccountPublicKey - ticketAccountPublicKey - The public key of the ticket account that will sign the transaction
* @param {BN} msolAmount - The amount of mSOL in lamports to order for unstaking
*/
export async function orderUnstakeWithPublicKey(
marinadeProgram: MarinadeProgram,
ownerAddress: PublicKey,
ticketAccountPublicKey: PublicKey,
msolAmount: BN
): Promise<MarinadeResult.OrderUnstakeWithPublicKey> {
const associatedMSolTokenAccountAddress = utils.token.associatedAddress({
mint: marinadeProgram.marinadeState.msolMint,
owner: ownerAddress,
})
const rent =
await marinadeProgram.provider.connection.getMinimumBalanceForRentExemption(
TICKET_ACCOUNT_SIZE
)
const createAccountInstruction = SystemProgram.createAccount({
fromPubkey: ownerAddress,
newAccountPubkey: ticketAccountPublicKey,
lamports: rent,
space: TICKET_ACCOUNT_SIZE,
programId: marinadeProgram.program.programId,
})

const orderUnstakeInstruction = await orderUnstakeInstructionBuilder({
program: marinadeProgram.program,
marinadeState: marinadeProgram.marinadeState,
msolAmount,
ownerAddress,
associatedMSolTokenAccountAddress,
newTicketAccount: ticketAccountPublicKey,
})

const transaction = new Transaction().add(
createAccountInstruction,
orderUnstakeInstruction
)

return {
transaction,
associatedMSolTokenAccountAddress,
}
}

/**
* Returns a transaction with the instructions to
* claim a ticket (created by {@link orderUnstake} beforehand).
Expand Down Expand Up @@ -1008,8 +1006,7 @@ export async function depositStakePoolToken(
lookupTableAddress: PublicKey,
stakePoolTokenAddress: PublicKey,
amountToDeposit: number,
validators: ValidatorStats[],
options: DepositOptions = {}
validators: ValidatorStats[]
): Promise<MarinadeResult.LiquidateStakePoolToken> {
const lookupTable = (
await marinadeProgram.provider.connection.getAddressLookupTable(
Expand Down Expand Up @@ -1097,18 +1094,6 @@ export async function depositStakePoolToken(

instructions.push(depositInstruction)

const directedStakeSdk = getDirectedStakeSdk(
marinadeProgram.provider.connection,
ownerAddress
)
const directedStakeInstruction = await createDirectedStakeVoteIx(
directedStakeSdk,
options.directToValidatorVoteAddress
)
if (directedStakeInstruction) {
instructions.push(directedStakeInstruction)
}

const { blockhash: recentBlockhash } =
await marinadeProgram.provider.connection.getLatestBlockhash('finalized')

Expand Down
16 changes: 5 additions & 11 deletions src/marinade.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export namespace MarinadeResult {
transaction: Transaction
}

export interface OrderUnstakeWithPublicKey {
associatedMSolTokenAccountAddress: PublicKey
transaction: Transaction
}

export interface Claim {
transaction: Transaction
}
Expand All @@ -73,17 +78,6 @@ export interface DepositOptions {
* The address of the owner account for the associated mSOL account.
*/
mintToOwnerAddress?: PublicKey
/**
* The vote address of the validator to direct your stake to.
*/
directToValidatorVoteAddress?: PublicKey
}

export interface DepositStakeAccountOptions {
/**
* The vote address of the validator to direct your stake to.
*/
directToValidatorVoteAddress?: PublicKey
}

export interface ValidatorStats {
Expand Down
Loading

0 comments on commit 3ac3543

Please sign in to comment.