ts: match client class definitions 1-1 to program state struct definitions (#268)
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com> Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
286563b0ef
commit
a66177a77e
|
@ -84,7 +84,7 @@ pub struct MangoAccount {
|
|||
pub net_settled: i64,
|
||||
|
||||
/// Init health as calculated during HealthReginBegin, rounded up.
|
||||
pub health_region_pre_init_health: i64,
|
||||
pub health_region_begin_init_health: i64,
|
||||
|
||||
pub reserved: [u8; 240],
|
||||
|
||||
|
@ -120,7 +120,7 @@ impl MangoAccount {
|
|||
padding: Default::default(),
|
||||
net_deposits: 0,
|
||||
net_settled: 0,
|
||||
health_region_pre_init_health: 0,
|
||||
health_region_begin_init_health: 0,
|
||||
reserved: [0; 240],
|
||||
header_version: DEFAULT_MANGO_ACCOUNT_VERSION,
|
||||
padding3: Default::default(),
|
||||
|
@ -1065,7 +1065,7 @@ mod tests {
|
|||
account.bump = 4;
|
||||
account.net_deposits = 5;
|
||||
account.net_settled = 6;
|
||||
account.health_region_pre_init_health = 7;
|
||||
account.health_region_begin_init_health = 7;
|
||||
account.tokens.resize(8, TokenPosition::default());
|
||||
account.tokens[0].token_index = 8;
|
||||
account.serum3.resize(8, Serum3Orders::default());
|
||||
|
@ -1091,7 +1091,7 @@ mod tests {
|
|||
assert_eq!(account.net_deposits, account2.fixed.net_deposits);
|
||||
assert_eq!(account.net_settled, account2.fixed.net_settled);
|
||||
assert_eq!(
|
||||
account.health_region_pre_init_health,
|
||||
account.health_region_begin_init_health,
|
||||
account2.fixed.health_region_begin_init_health
|
||||
);
|
||||
assert_eq!(
|
||||
|
|
|
@ -12,12 +12,11 @@ import { HealthCache } from './healthCache';
|
|||
import { PerpMarket, PerpMarketIndex, PerpOrder, PerpOrderSide } from './perp';
|
||||
import { MarketIndex, Serum3Side } from './serum3';
|
||||
export class MangoAccount {
|
||||
public name: string;
|
||||
public tokens: TokenPosition[];
|
||||
public serum3: Serum3Orders[];
|
||||
public perps: PerpPosition[];
|
||||
public perpOpenOrders: PerpOo[];
|
||||
public name: string;
|
||||
public netDeposits: BN;
|
||||
|
||||
static from(
|
||||
publicKey: PublicKey,
|
||||
|
@ -26,29 +25,31 @@ export class MangoAccount {
|
|||
owner: PublicKey;
|
||||
name: number[];
|
||||
delegate: PublicKey;
|
||||
beingLiquidated: number;
|
||||
accountNum: number;
|
||||
bump: number;
|
||||
beingLiquidated: number;
|
||||
inHealthRegion: number;
|
||||
netDeposits: BN;
|
||||
netSettled: BN;
|
||||
healthRegionBeginInitHealth: BN;
|
||||
headerVersion: number;
|
||||
tokens: unknown;
|
||||
serum3: unknown;
|
||||
perps: unknown;
|
||||
perpOpenOrders: unknown;
|
||||
},
|
||||
) {
|
||||
): MangoAccount {
|
||||
return new MangoAccount(
|
||||
publicKey,
|
||||
obj.group,
|
||||
obj.owner,
|
||||
obj.name,
|
||||
obj.delegate,
|
||||
obj.beingLiquidated,
|
||||
obj.accountNum,
|
||||
obj.bump,
|
||||
obj.beingLiquidated == 1,
|
||||
obj.inHealthRegion == 1,
|
||||
obj.netDeposits,
|
||||
obj.netSettled,
|
||||
obj.healthRegionBeginInitHealth,
|
||||
obj.headerVersion,
|
||||
obj.tokens as TokenPositionDto[],
|
||||
obj.serum3 as Serum3PositionDto[],
|
||||
|
@ -64,12 +65,13 @@ export class MangoAccount {
|
|||
public owner: PublicKey,
|
||||
name: number[],
|
||||
public delegate: PublicKey,
|
||||
beingLiquidated: number,
|
||||
public accountNum: number,
|
||||
bump: number,
|
||||
netDeposits: BN,
|
||||
netSettled: BN,
|
||||
headerVersion: number,
|
||||
public beingLiquidated: boolean,
|
||||
public inHealthRegion: boolean,
|
||||
public netDeposits: BN,
|
||||
public netSettled: BN,
|
||||
public healthRegionBeginInitHealth: BN,
|
||||
public headerVersion: number,
|
||||
tokens: TokenPositionDto[],
|
||||
serum3: Serum3PositionDto[],
|
||||
perps: PerpPositionDto[],
|
||||
|
@ -81,7 +83,6 @@ export class MangoAccount {
|
|||
this.serum3 = serum3.map((dto) => Serum3Orders.from(dto));
|
||||
this.perps = perps.map((dto) => PerpPosition.from(dto));
|
||||
this.perpOpenOrders = perpOpenOrders.map((dto) => PerpOo.from(dto));
|
||||
this.netDeposits = netDeposits;
|
||||
}
|
||||
|
||||
async reload(client: MangoClient): Promise<MangoAccount> {
|
||||
|
|
|
@ -5,7 +5,7 @@ import Big from 'big.js';
|
|||
import { MangoClient } from '../client';
|
||||
import { I80F48, I80F48Dto } from '../numbers/I80F48';
|
||||
import { As, toNative, U64_MAX_BN } from '../utils';
|
||||
import { OracleConfig, QUOTE_DECIMALS } from './bank';
|
||||
import { OracleConfig, QUOTE_DECIMALS, TokenIndex } from './bank';
|
||||
|
||||
export type PerpMarketIndex = number & As<'perp-market-index'>;
|
||||
|
||||
|
@ -22,21 +22,24 @@ export class PerpMarket {
|
|||
public maxFunding: I80F48;
|
||||
public longFunding: I80F48;
|
||||
public shortFunding: I80F48;
|
||||
public openInterest: BN;
|
||||
public seqNum: BN;
|
||||
public feesAccrued: I80F48;
|
||||
priceLotsToUiConverter: number;
|
||||
baseLotsToUiConverter: number;
|
||||
quoteLotsToUiConverter: number;
|
||||
public feesSettled: I80F48;
|
||||
|
||||
public _price: I80F48;
|
||||
public _uiPrice: number;
|
||||
|
||||
private priceLotsToUiConverter: number;
|
||||
private baseLotsToUiConverter: number;
|
||||
private quoteLotsToUiConverter: number;
|
||||
|
||||
static from(
|
||||
publicKey: PublicKey,
|
||||
obj: {
|
||||
group: PublicKey;
|
||||
settleTokenIndex: number;
|
||||
perpMarketIndex: number;
|
||||
trustedMarket: number;
|
||||
groupInsuranceFund: number;
|
||||
name: number[];
|
||||
oracle: PublicKey;
|
||||
oracleConfig: OracleConfig;
|
||||
|
@ -61,16 +64,22 @@ export class PerpMarket {
|
|||
openInterest: BN;
|
||||
seqNum: BN;
|
||||
feesAccrued: I80F48Dto;
|
||||
bump: number;
|
||||
baseDecimals: number;
|
||||
registrationTime: BN;
|
||||
feesSettled: I80F48Dto;
|
||||
feePenalty: number;
|
||||
settleFeeFlat: number;
|
||||
settleFeeAmountThreshold: number;
|
||||
settleFeeFractionLowHealth: number;
|
||||
},
|
||||
): PerpMarket {
|
||||
return new PerpMarket(
|
||||
publicKey,
|
||||
obj.group,
|
||||
obj.settleTokenIndex as TokenIndex,
|
||||
obj.perpMarketIndex as PerpMarketIndex,
|
||||
obj.trustedMarket == 1,
|
||||
obj.groupInsuranceFund == 1,
|
||||
obj.name,
|
||||
obj.oracle,
|
||||
obj.oracleConfig,
|
||||
|
@ -95,17 +104,23 @@ export class PerpMarket {
|
|||
obj.openInterest,
|
||||
obj.seqNum,
|
||||
obj.feesAccrued,
|
||||
obj.bump,
|
||||
obj.baseDecimals,
|
||||
obj.registrationTime,
|
||||
obj.feesSettled,
|
||||
obj.feePenalty,
|
||||
obj.settleFeeFlat,
|
||||
obj.settleFeeAmountThreshold,
|
||||
obj.settleFeeFractionLowHealth,
|
||||
);
|
||||
}
|
||||
|
||||
constructor(
|
||||
public publicKey: PublicKey,
|
||||
public group: PublicKey,
|
||||
public settleTokenIndex: TokenIndex,
|
||||
public perpMarketIndex: PerpMarketIndex, // TODO rename to marketIndex?
|
||||
public trustedMarket: boolean,
|
||||
public groupInsuranceFund: boolean,
|
||||
name: number[],
|
||||
public oracle: PublicKey,
|
||||
oracleConfig: OracleConfig,
|
||||
|
@ -126,13 +141,17 @@ export class PerpMarket {
|
|||
public impactQuantity: BN,
|
||||
longFunding: I80F48Dto,
|
||||
shortFunding: I80F48Dto,
|
||||
fundingLastUpdated: BN,
|
||||
openInterest: BN,
|
||||
seqNum: BN,
|
||||
public fundingLastUpdated: BN,
|
||||
public openInterest: BN,
|
||||
public seqNum: BN,
|
||||
feesAccrued: I80F48Dto,
|
||||
bump: number,
|
||||
public baseDecimals: number,
|
||||
public registrationTime: BN,
|
||||
feesSettled: I80F48Dto,
|
||||
public feePenalty: number,
|
||||
public settleFeeFlat: number,
|
||||
public settleFeeAmountThreshold: number,
|
||||
public settleFeeFractionLowHealth: number,
|
||||
) {
|
||||
this.name = utf8.decode(new Uint8Array(name)).split('\x00')[0];
|
||||
this.maintAssetWeight = I80F48.from(maintAssetWeight);
|
||||
|
@ -146,9 +165,8 @@ export class PerpMarket {
|
|||
this.maxFunding = I80F48.from(maxFunding);
|
||||
this.longFunding = I80F48.from(longFunding);
|
||||
this.shortFunding = I80F48.from(shortFunding);
|
||||
this.openInterest = openInterest;
|
||||
this.seqNum = seqNum;
|
||||
this.feesAccrued = I80F48.from(feesAccrued);
|
||||
this.feesSettled = I80F48.from(feesSettled);
|
||||
|
||||
this.priceLotsToUiConverter = new Big(10)
|
||||
.pow(baseDecimals - QUOTE_DECIMALS)
|
||||
|
|
|
@ -4,10 +4,10 @@ import { Cluster, PublicKey } from '@solana/web3.js';
|
|||
import BN from 'bn.js';
|
||||
import { MangoClient } from '../client';
|
||||
import { SERUM3_PROGRAM_ID } from '../constants';
|
||||
import { MAX_I80F48, ONE_I80F48, ZERO_I80F48 } from '../numbers/I80F48';
|
||||
import { As } from '../utils';
|
||||
import { TokenIndex } from './bank';
|
||||
import { Group } from './group';
|
||||
import { MAX_I80F48, ONE_I80F48, ZERO_I80F48 } from '../numbers/I80F48';
|
||||
|
||||
export type MarketIndex = number & As<'market-index'>;
|
||||
|
||||
|
@ -23,7 +23,6 @@ export class Serum3Market {
|
|||
serumProgram: PublicKey;
|
||||
serumMarketExternal: PublicKey;
|
||||
marketIndex: number;
|
||||
bump: number;
|
||||
registrationTime: BN;
|
||||
},
|
||||
): Serum3Market {
|
||||
|
|
|
@ -3630,7 +3630,7 @@ export type MangoV4 = {
|
|||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "healthRegionPreInitHealth",
|
||||
"name": "healthRegionBeginInitHealth",
|
||||
"docs": [
|
||||
"Init health as calculated during HealthReginBegin, rounded up."
|
||||
],
|
||||
|
@ -9906,7 +9906,7 @@ export const IDL: MangoV4 = {
|
|||
"type": "i64"
|
||||
},
|
||||
{
|
||||
"name": "healthRegionPreInitHealth",
|
||||
"name": "healthRegionBeginInitHealth",
|
||||
"docs": [
|
||||
"Init health as calculated during HealthReginBegin, rounded up."
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue