Skip to content

Commit

Permalink
fix: do better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStefan committed Sep 16, 2022
1 parent 847fc87 commit 7a3adcd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/marinade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MarinadeReferralPartnerState } from './marinade-referral-state/marinade
import { MarinadeReferralGlobalState } from './marinade-referral-state/marinade-referral-global-state'
import { assertNotNullAndReturn } from './util/assert'
import { TicketAccount } from './marinade-state/borsh/ticket-account'
import { getExpectedMsol } from './util'
import { computeMsolAmount } from './util'

export class Marinade {
constructor(public readonly config: MarinadeConfig = new MarinadeConfig()) { }
Expand Down Expand Up @@ -302,7 +302,7 @@ export class Marinade {

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

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

Expand Down
6 changes: 3 additions & 3 deletions src/util/state-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BN } from '@project-serum/anchor'
import { MarinadeConfig } from '../config/marinade-config'
import { Marinade } from '../marinade'
import * as TestWorld from '../../test/test-world'
import { getExpectedMsol, proportionalBN, unstakeNowFeeBp } from './state-helpers'
import { computeMsolAmount, proportionalBN, unstakeNowFeeBp } from './state-helpers'

describe('state-helpers', () => {
describe('unstakeNowFeeBp', () => {
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('state-helpers', () => {
)
})

describe('getExpectedMsol', () => {
describe('computeMsolAmount', () => {
it('apply napkin math', async() => {
const config = new MarinadeConfig({
connection: TestWorld.CONNECTION,
Expand All @@ -61,7 +61,7 @@ describe('state-helpers', () => {
marinadeState.state.circulatingTicketBalance = new BN(14301681747495)
marinadeState.state.msolSupply = new BN(6978141264398309)

const actualResult = getExpectedMsol(new BN('10230883291'), marinadeState)
const actualResult = computeMsolAmount(new BN('10230883291'), marinadeState)

expect(actualResult.toString()).toBe('9611384974')
})
Expand Down
2 changes: 1 addition & 1 deletion src/util/state-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function proportionalBN(amount: BN, numerator: BN, denominator: BN): BN {
* @param {BN} solAmount
* @param {MarinadeState} marinadeState
*/
export function getExpectedMsol(solAmount: BN, marinadeState: MarinadeState): BN {
export function computeMsolAmount(solAmount: BN, marinadeState: MarinadeState): BN {
const total_cooling_down = marinadeState.state.stakeSystem.delayedUnstakeCoolingDown.add(marinadeState.state.emergencyCoolingDown)
const total_lamports_under_control = marinadeState.state.validatorSystem.totalActiveBalance.add(total_cooling_down).add(marinadeState.state.availableReserveBalance)
const total_virtual_staked_lamports = total_lamports_under_control.sub(marinadeState.state.circulatingTicketBalance)
Expand Down

0 comments on commit 7a3adcd

Please sign in to comment.