Skip to content

Commit

Permalink
Merge, new V4.0.0, uses referral v2
Browse files Browse the repository at this point in the history
new V4.0.0, uses referral v2
  • Loading branch information
luciotato authored Sep 23, 2022
2 parents 337b6a6 + 832023e commit 2bb6806
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 66 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
scripts
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

v4.0.0

Uses Referral-Program V2
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": "3.1.4",
"version": "4.0.0",
"description": "Marinade SDK for Typescript",
"main": "dist/src/index.js",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/config/marinade-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const DEFAULT_PROVIDER_URL = 'https://api.devnet.solana.com'

export class MarinadeConfig {
marinadeFinanceProgramId = new web3.PublicKey('MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD')
marinadeReferralProgramId = new web3.PublicKey('mRefx8ypXNxE59NhoBqwqb3vTvjgf8MYECp4kgJWiDY')
marinadeReferralProgramId = new web3.PublicKey('MR2LqxoSbw831bNy68utpu5n4YqBH3AzDmddkgk9LQv')

marinadeStateAddress = new web3.PublicKey('8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC')
marinadeReferralGlobalStateAddress = new web3.PublicKey('mRg6bDsAd5uwERAdNTynoUeRbqQsLa7yzuK2kkCUPGW')
marinadeReferralGlobalStateAddress = new web3.PublicKey('MRSh4rUNrpn7mjAq9ENHV4rvwwPKMij113ScZq3twp2')

stakeWithdrawAuthPDA = new web3.PublicKey('9eG63CdHjsfhHmobHgLtESGC8GabbmRcaSpHAZrtmhco')

Expand Down
21 changes: 16 additions & 5 deletions src/marinade-referral-state/marinade-referral-state.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ export const enum ProgramDerivedAddressSeed {
export namespace MarinadeReferralStateResponse {
export interface GlobalState {
adminAccount: web3.PublicKey
treasuryMsolAccount: web3.PublicKey
treasuryMsolAuthBump: number
msolMintAccount: web3.PublicKey
foreman1: web3.PublicKey
foreman2: web3.PublicKey
minKeepPct: number
maxKeepPct: number
}

export interface ReferralState {
partnerName: string
validatorVoteKey: web3.PublicKey|null
keepSelfStakePct: number
partnerAccount: web3.PublicKey
tokenPartnerAccount: web3.PublicKey
transferDuration: number
lastTransferTime: BN
msolTokenPartnerAccount: web3.PublicKey
depositSolAmount: BN
depositSolOperations: BN
depositStakeAccountAmount: BN
Expand All @@ -32,5 +35,13 @@ export namespace MarinadeReferralStateResponse {
maxFee: number
maxNetStake: BN
pause: boolean
operationDepositSolFee: number
operationDepositStakeAccountFee: number
operationLiquidUnstakeFee: number
operationDelayedUnstakeFee: number
accumDepositSolFee: BN
accumDepositStakeAccountFee: BN
accumLiquidUnstakeFee: BN
accumDelayedUnstakeFee: BN
}
}
17 changes: 9 additions & 8 deletions src/marinade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export class Marinade {
this.config.marinadeReferralProgramId,
this.provider,
this.config.referralCode,
this,
)

private provideReferralOrMainProgram(): MarinadeFinanceProgram | MarinadeReferralProgram {
return this.config.referralCode ? this.marinadeReferralProgram: this.marinadeFinanceProgram
return this.config.referralCode ? this.marinadeReferralProgram : this.marinadeFinanceProgram
}

/**
Expand Down Expand Up @@ -193,7 +194,7 @@ export class Marinade {
const associatedTokenAccountInfos = await getOrCreateAssociatedTokenAccount(this.provider, marinadeState.mSolMintAddress, ownerAddress)
const createAssociateTokenInstruction = associatedTokenAccountInfos.createAssociateTokenInstruction
associatedMSolTokenAccountAddress = associatedTokenAccountInfos.associatedTokenAccountAddress

if (createAssociateTokenInstruction) {
transaction.add(createAssociateTokenInstruction)
}
Expand Down Expand Up @@ -289,8 +290,8 @@ export class Marinade {
* Returns a transaction with the instructions to
* Liquidate a delegated stake account.
* Note that the stake must be fully activated and the validator must be known to Marinade
* and that the transaction should be executed immidiately after creation.
*
* and that the transaction should be executed immediately after creation.
*
* @param {web3.PublicKey} stakeAccountAddress - The account to be deposited
* @param {BN} mSolToKeep - Optional amount of mSOL lamports to keep
*/
Expand All @@ -300,11 +301,11 @@ export class Marinade {
const stakeBalance = new BN(totalBalance - rent)
const marinadeState = await this.getMarinadeState()

const {transaction: depositTx, associatedMSolTokenAccountAddress, voterAddress} = await this.depositStakeAccount(stakeAccountAddress)
const { transaction: depositTx, associatedMSolTokenAccountAddress, voterAddress } = await this.depositStakeAccount(stakeAccountAddress)

const availableMsol = computeMsolAmount(stakeBalance, marinadeState)
const unstakeAmount = availableMsol.sub(mSolToKeep ?? new BN(0))
const {transaction: unstakeTx} = await this.liquidUnstake(unstakeAmount, associatedMSolTokenAccountAddress)
const { transaction: unstakeTx } = await this.liquidUnstake(unstakeAmount, associatedMSolTokenAccountAddress)

return {
transaction: depositTx.add(unstakeTx),
Expand All @@ -317,13 +318,13 @@ export class Marinade {
* @todo
*/
async getDelayedUnstakeTickets(beneficiary?: web3.PublicKey): Promise<Map<web3.PublicKey, TicketAccount>> {

return this.marinadeFinanceProgram.getDelayedUnstakeTickets(beneficiary)
}

/**
* Returns estimated Due date for an unstake ticket created now
*
*
*/
async getEstimatedUnstakeTicketDueDate() {
const marinadeState = await this.getMarinadeState()
Expand Down
Loading

0 comments on commit 2bb6806

Please sign in to comment.