-
Notifications
You must be signed in to change notification settings - Fork 51
sdk: add calculateClientCollateralSize #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
d376bac
26358ff
468d206
6641c47
fdca480
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { MarketsAccount, StateAccount } from '../types'; | ||
| import BN from 'bn.js'; | ||
| import { Connection } from '@solana/web3.js'; | ||
|
|
||
| /** | ||
| * Client collateral is represented by the balance of the collateral wallet, as specified in the state, minus the sum of | ||
| * each markets undistributed fees. | ||
| * | ||
| * @param connection | ||
| * @param state | ||
| * @param marketsAccount | ||
| * @returns Precision : QUOTE_ASSET_PRECISION | ||
| */ | ||
| export async function calculateClientCollateralSize( | ||
| connection: Connection, | ||
| state: StateAccount, | ||
| marketsAccount: MarketsAccount | ||
| ): Promise<BN> { | ||
| const collateralVaultPublicKey = state.collateralVault; | ||
| const collateralVaultAmount = new BN( | ||
| ( | ||
| await connection.getTokenAccountBalance(collateralVaultPublicKey) | ||
| ).value.amount | ||
| ); | ||
| return marketsAccount.markets.reduce((collateralVaultAmount, market) => { | ||
| return collateralVaultAmount.sub(market.amm.totalFee.div(new BN(2))); | ||
|
||
| }, collateralVaultAmount); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.