@bulletxyz/bullet-sdk 0.31.0-rc.2 → 0.32.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,28 +11,28 @@ export class BulletWasm {
11
11
  static dummy(a: number): number;
12
12
  static convert_token_id_to_bytes(token_id: string): Uint8Array;
13
13
  static convert_rust_decimal_to_json(decimal_str: string): any;
14
- static calculate_total_perp_unrealized_pnl(user_account: any, margin_calculation_state: any): string;
15
- static calculate_account_equity(user_account: any, conservative: boolean, equity_type: EquityType, margin_calculation_state: any): string;
16
- static calculate_account_leverage(user_account: any, margin_calculation_state: any): string;
17
- static calculate_available_margin(user_account: any, conservative: boolean, margin_type: MarginType, margin_calculation_state: any): string;
18
- static calculate_used_margin(user_account: any, withdrawal: boolean, margin_type: MarginType, margin_calculation_state: any): string;
19
- static calculate_used_perp_margin(user_account: any, margin_type: MarginType, margin_calculation_state: any): string;
20
- static calculate_used_spot_margin(user_account: any, margin_type: MarginType, margin_calculation_state: any): string;
21
- static calculate_withdrawable_amount_of_asset(user_account: any, asset_id: number, margin_calculation_state: any, asset_registry: any): string;
22
- static calculate_estimated_liquidation_price(user_account: any, market_id: number, base_asset_id: number, margin_calculation_state: any): string;
23
- static calculate_liquidation_risk_percentage(user_account: any, margin_calculation_state: any): string;
24
- static calculate_margin_balance(user_account: any, margin_calculation_state: any): string;
25
- static calculate_force_cancel_risk_percentage(user_account: any, margin_calculation_state: any): string;
14
+ static calculate_total_perp_unrealized_pnl(user_account: any, risk_engine: any): string;
15
+ static calculate_account_equity(user_account: any, conservative: boolean, equity_type: EquityType, risk_engine: any): string;
16
+ static calculate_account_leverage(user_account: any, risk_engine: any): string;
17
+ static calculate_available_margin(user_account: any, conservative: boolean, margin_type: MarginType, risk_engine: any): string;
18
+ static calculate_used_margin(user_account: any, withdrawal: boolean, margin_type: MarginType, risk_engine: any): string;
19
+ static calculate_used_perp_margin(user_account: any, margin_type: MarginType, risk_engine: any): string;
20
+ static calculate_used_spot_margin(user_account: any, margin_type: MarginType, risk_engine: any): string;
21
+ static calculate_withdrawable_amount_of_asset(user_account: any, asset_id: number, risk_engine: any, exchange_info: any): string;
22
+ static calculate_estimated_liquidation_price(user_account: any, market_id: number, base_asset_id: number, risk_engine: any): string;
23
+ static calculate_liquidation_risk_percentage(user_account: any, risk_engine: any): string;
24
+ static calculate_margin_balance(user_account: any, risk_engine: any): string;
25
+ static calculate_force_cancel_risk_percentage(user_account: any, risk_engine: any): string;
26
26
  /**
27
27
  * Calculates the maximum amount that can be borrowed for a given asset
28
28
  * @param initial_liability_weight The initial liability weight for the market must be passed in separately since the user may not have a spot ledger for this asset yet
29
29
  */
30
- static calculate_max_borrow_amount(asset_id: number, user_account: any, margin_calculation_state: any): string;
31
- static calculate_max_order_size(market_id: number, price: string, side: Side, order_type: OrderType, reduce_only: boolean, user_account: any, margin_calculation_state: any, orderbook: any, n_iterations: number, error_tolerance: string): string;
32
- static simulate_used_margin_on_borrow(asset_id: number, borrow_amount: string, user_account: any, margin_type: MarginType, margin_calculation_state: any): any;
33
- static simulate_used_margin_on_order(market_id: number, new_order_args: any, user_account: any, margin_calculation_state: any, orderbook: any): any;
34
- static simulate_estimated_liquidation_price_on_order(market_id: number, new_order_args: any, base_asset: number, user_account: any, margin_calculation_state: any, orderbook: any): any;
35
- static calculate_positions_additional_metadata(user_account: any, margin_calculation_state: any): any;
30
+ static calculate_max_borrow_amount(asset_id: number, user_account: any, risk_engine: any): string;
31
+ static calculate_max_order_size(market_id: number, price: string, side: Side, order_type: OrderType, reduce_only: boolean, user_account: any, risk_engine: any, orderbook: any, n_iterations: number, error_tolerance: string): string;
32
+ static simulate_used_margin_on_borrow(asset_id: number, borrow_amount: string, user_account: any, margin_type: MarginType, risk_engine: any): any;
33
+ static simulate_used_margin_on_order(market_id: number, new_order_args: any, user_account: any, risk_engine: any, orderbook: any): any;
34
+ static simulate_estimated_liquidation_price_on_order(market_id: number, new_order_args: any, base_asset: number, user_account: any, risk_engine: any, orderbook: any): any;
35
+ static calculate_positions_additional_metadata(user_account: any, risk_engine: any): any;
36
36
  static calculate_borrow_lend_additional_metadata(borrow_lend_market: any): any;
37
- static calculate_account_summary_batch(user_accounts: any, margin_calculation_state: any, use_weighted_equity: boolean): any;
37
+ static calculate_account_summary_batch(user_accounts: any, risk_engine: any, use_weighted_equity: boolean): any;
38
38
  }
@@ -4,7 +4,7 @@ import { Connection } from "./connection";
4
4
  import { type Endpoints } from "./constants";
5
5
  import { ExchangeConnection } from "./exchange";
6
6
  import type { RuntimeCall } from "./rollupTypes";
7
- import { type Address, type AssetId, type AssetName, type MarkPriceUpdateArgs, type MarketName, type Network, type NewOrderArgs, type OraclePriceUpdateArgs, SpotCollateralTransferDirection, type TokenId, type TpslPair } from "./types";
7
+ import { type Address, type AssetId, type AssetName, type MarkPriceUpdateArgs, type MarketName, type Network, type NewOrderArgs, type OraclePriceUpdateArgs, type SpotCollateralTransferDirection, type TokenId, type TpslPair } from "./types";
8
8
  import type { Wallet } from "./wallet";
9
9
  export interface TransactionOpts {
10
10
  maxPriorityFeeBps: number;
@@ -3,10 +3,11 @@ import { type EquityType, type MarginType } from "./bullet-wasm";
3
3
  import { BaseConnection } from "./connection";
4
4
  import { type Endpoints } from "./constants";
5
5
  import type { Orderbook } from "./orderbook";
6
- import type { Address, AssetName, MarketMetadata, MarketName, Network, NewOrderArgs, OrderType, Side } from "./types";
7
- import { type AccountAddresses, type AssetRegistry, type BorrowLendPools, type ExecutionIds, type GlobalParameters, type MarginConfig, type MarketRegistry, type OraclePrices, type Order, type OrderbookL2, type PerpMarket, type PerpPrices, type SpotMarket, type UsdcInsuranceFund, type UsdcPnlPool, type UserAccount } from "./zod-types/rest";
6
+ import type { Address, AssetId, AssetName, MarketMetadata, MarketName, Network, NewOrderArgs, OrderType, Side } from "./types";
7
+ import { type AccountAddresses, type BorrowLendPool, type ExchangeAssets, type ExchangeInfo, type ExecutionIds, type Order, type OrderbookL2, type PerpMarket, type RiskEngine, type SpotMarket, type UserAccount } from "./zod-types/rest";
8
8
  export declare class ExchangeConnection extends BaseConnection {
9
9
  private wsManager?;
10
+ private exchangeInfo?;
10
11
  private assetInfoRegistry?;
11
12
  private assetInfoRegistryReverse?;
12
13
  private marketRegistry?;
@@ -15,12 +16,9 @@ export declare class ExchangeConnection extends BaseConnection {
15
16
  static fromEndpoints(endpoints: Endpoints): Promise<ExchangeConnection>;
16
17
  static fromNetwork(network: Network): Promise<ExchangeConnection>;
17
18
  static fromRestUrl(restUrl: string): Promise<ExchangeConnection>;
18
- private initializeRegistries;
19
- private initializeAssetRegistry;
20
- private initializeMarketRegistry;
19
+ private initializeExchangeInfo;
21
20
  getOrder(orderId: bigint): Promise<Order | null>;
22
- getMarketRegistry(): Promise<MarketRegistry | null>;
23
- getAssetRegistry(): Promise<AssetRegistry | null>;
21
+ getExchangeInfo(): Promise<ExchangeInfo | null>;
24
22
  private getAssetMapping;
25
23
  private getMarketMapping;
26
24
  getAssetId(asset: AssetName): number;
@@ -36,135 +34,54 @@ export declare class ExchangeConnection extends BaseConnection {
36
34
  getUserAccountAddresses(offset?: number, limit?: number): Promise<AccountAddresses>;
37
35
  getUserAccount(address: Address): Promise<UserAccount>;
38
36
  getUserAccounts(addresses: Address[]): Promise<Map<string, UserAccount>>;
39
- getOraclePrices(): Promise<OraclePrices | null>;
40
- getPerpPrices(): Promise<PerpPrices | null>;
41
- getUsdcPnlPool(): Promise<UsdcPnlPool | null>;
42
- getUsdcInsuranceFund(): Promise<UsdcInsuranceFund | null>;
43
- getBorrowLendMarkets(): Promise<BorrowLendPools>;
37
+ getExchangeAssets(): Promise<ExchangeAssets | null>;
38
+ getRiskEngine(): Promise<RiskEngine | null>;
44
39
  getPerpMarket(market: MarketName): Promise<PerpMarket>;
45
40
  getPerpMarkets(markets: MarketName[]): Promise<Map<number, PerpMarket>>;
46
41
  getSpotMarket(market: MarketName): Promise<SpotMarket>;
47
42
  getSpotMarkets(markets: MarketName[]): Promise<Map<number, SpotMarket>>;
48
- getMarginConfig(): Promise<MarginConfig | null>;
49
43
  getExecutionIds(): Promise<ExecutionIds | null>;
50
- getGlobalParameters(): Promise<GlobalParameters | null>;
51
44
  calculateOrderbookMidpoint(orderbook: OrderbookL2): Decimal | undefined;
52
45
  calculateEntryPrice(market: MarketName, userAccount: UserAccount): Decimal;
53
- calculateTotalPerpUnrealizedPnl(userAccount: UserAccount, marginCalculationState: {
54
- oracle_prices: OraclePrices;
55
- perp_prices: PerpPrices;
56
- margin_config: MarginConfig;
57
- }): Decimal;
58
- calculateAccountEquity(equityType: EquityType, conservative: boolean, userAccount: UserAccount, marginCalculationState: {
59
- oracle_prices: OraclePrices;
60
- perp_prices: PerpPrices;
61
- margin_config: MarginConfig;
62
- }): Decimal;
63
- calculateAccountLeverage(userAccount: UserAccount, marginCalculationState: {
64
- oracle_prices: OraclePrices;
65
- perp_prices: PerpPrices;
66
- margin_config: MarginConfig;
67
- }): Decimal;
68
- calculateAvailableMargin(marginType: MarginType, conservative: boolean, userAccount: UserAccount, marginCalculationState: {
69
- oracle_prices: OraclePrices;
70
- perp_prices: PerpPrices;
71
- margin_config: MarginConfig;
72
- }): Decimal;
73
- calculateUsedMargin(withdrawal: boolean, marginType: MarginType, userAccount: UserAccount, marginCalculationState: {
74
- oracle_prices: OraclePrices;
75
- perp_prices: PerpPrices;
76
- margin_config: MarginConfig;
77
- }): Decimal;
78
- calculateUsedPerpMargin(userAccount: UserAccount, marginType: MarginType, marginCalculationState: {
79
- oracle_prices: OraclePrices;
80
- perp_prices: PerpPrices;
81
- margin_config: MarginConfig;
82
- }): Decimal;
83
- calculateUsedSpotMargin(userAccount: UserAccount, marginType: MarginType, marginCalculationState: {
84
- oracle_prices: OraclePrices;
85
- perp_prices: PerpPrices;
86
- margin_config: MarginConfig;
87
- }): Decimal;
88
- calculateWithdrawableAmountOfAsset(asset: AssetName, userAccount: UserAccount, marginCalculationState: {
89
- oracle_prices: OraclePrices;
90
- perp_prices: PerpPrices;
91
- margin_config: MarginConfig;
92
- }): Promise<Decimal>;
93
- calculateEstimatedLiquidationPrice(market: MarketName, asset: AssetName, userAccount: UserAccount, marginCalculationState: {
94
- oracle_prices: OraclePrices;
95
- perp_prices: PerpPrices;
96
- margin_config: MarginConfig;
97
- }): Decimal;
98
- calculateLiquidationRiskPercentage(userAccount: UserAccount, marginCalculationState: {
99
- oracle_prices: OraclePrices;
100
- perp_prices: PerpPrices;
101
- margin_config: MarginConfig;
102
- }): Decimal;
103
- calculateMarginBalance(userAccount: UserAccount, marginCalculationState: {
104
- oracle_prices: OraclePrices;
105
- perp_prices: PerpPrices;
106
- margin_config: MarginConfig;
107
- }): Decimal;
108
- calculateForceCancelRiskPercentage(userAccount: UserAccount, marginCalculationState: {
109
- oracle_prices: OraclePrices;
110
- perp_prices: PerpPrices;
111
- margin_config: MarginConfig;
112
- }): Decimal;
113
- calculateMaxBorrowAmount(asset: AssetName, userAccount: UserAccount, marginCalculationState: {
114
- oracle_prices: OraclePrices;
115
- perp_prices: PerpPrices;
116
- margin_config: MarginConfig;
117
- }): Decimal;
118
- calculateMaxOrderSize(market: MarketName, price: Decimal, side: Side, order_type: OrderType, reduce_only: boolean, userAccount: UserAccount, marginCalculationState: {
119
- oracle_prices: OraclePrices;
120
- perp_prices: PerpPrices;
121
- margin_config: MarginConfig;
122
- }, orderbook: OrderbookL2, n_iterations?: number, error_tolerance?: Decimal): Decimal;
123
- simulateUsedMarginOnBorrow(asset: AssetName, borrowAmount: Decimal, userAccount: UserAccount, marginType: MarginType, marginCalculationState: {
124
- oracle_prices: OraclePrices;
125
- perp_prices: PerpPrices;
126
- margin_config: MarginConfig;
127
- }): {
46
+ calculateTotalPerpUnrealizedPnl(userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
47
+ calculateAccountEquity(equityType: EquityType, conservative: boolean, userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
48
+ calculateAccountLeverage(userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
49
+ calculateAvailableMargin(marginType: MarginType, conservative: boolean, userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
50
+ calculateUsedMargin(withdrawal: boolean, marginType: MarginType, userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
51
+ calculateUsedPerpMargin(userAccount: UserAccount, marginType: MarginType, riskEngine: RiskEngine): Decimal;
52
+ calculateUsedSpotMargin(userAccount: UserAccount, marginType: MarginType, riskEngine: RiskEngine): Decimal;
53
+ calculateWithdrawableAmountOfAsset(asset: AssetName, userAccount: UserAccount, riskEngine: RiskEngine): Promise<Decimal>;
54
+ calculateEstimatedLiquidationPrice(market: MarketName, asset: AssetName, userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
55
+ calculateLiquidationRiskPercentage(userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
56
+ calculateMarginBalance(userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
57
+ calculateForceCancelRiskPercentage(userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
58
+ calculateMaxBorrowAmount(asset: AssetName, userAccount: UserAccount, riskEngine: RiskEngine): Decimal;
59
+ calculateMaxOrderSize(market: MarketName, price: Decimal, side: Side, order_type: OrderType, reduce_only: boolean, userAccount: UserAccount, riskEngine: RiskEngine, orderbook: OrderbookL2, n_iterations?: number, error_tolerance?: Decimal): Decimal;
60
+ simulateUsedMarginOnBorrow(asset: AssetName, borrowAmount: Decimal, userAccount: UserAccount, marginType: MarginType, riskEngine: RiskEngine): {
128
61
  current: Decimal;
129
62
  updated: Decimal;
130
63
  };
131
- simulateUsedMarginOnOrder(market: MarketName, newOrderArgs: NewOrderArgs, userAccount: UserAccount, marginCalculationState: {
132
- oracle_prices: OraclePrices;
133
- perp_prices: PerpPrices;
134
- margin_config: MarginConfig;
135
- }, orderbook: OrderbookL2): {
64
+ simulateUsedMarginOnOrder(market: MarketName, newOrderArgs: NewOrderArgs, userAccount: UserAccount, riskEngine: RiskEngine, orderbook: OrderbookL2): {
136
65
  current: Decimal;
137
66
  updated: Decimal;
138
67
  };
139
- simulateEstimatedLiquidationPriceOnOrder(market: MarketName, newOrderArgs: NewOrderArgs, baseAsset: AssetName, userAccount: UserAccount, marginCalculationState: {
140
- oracle_prices: OraclePrices;
141
- perp_prices: PerpPrices;
142
- margin_config: MarginConfig;
143
- }, orderbook: OrderbookL2): {
68
+ simulateEstimatedLiquidationPriceOnOrder(market: MarketName, newOrderArgs: NewOrderArgs, baseAsset: AssetName, userAccount: UserAccount, riskEngine: RiskEngine, orderbook: OrderbookL2): {
144
69
  current: Decimal;
145
70
  updated: Decimal;
146
71
  };
147
- calculatePositionsAdditionalMetadata(userAccount: UserAccount, marginCalculationState: {
148
- oracle_prices: OraclePrices;
149
- perp_prices: PerpPrices;
150
- margin_config: MarginConfig;
151
- }): Map<number, {
72
+ calculatePositionsAdditionalMetadata(userAccount: UserAccount, riskEngine: RiskEngine): Map<number, {
152
73
  projected_funding_payment: Decimal;
153
74
  unrealized_pnl: Decimal;
154
75
  liquidation_price: Decimal;
155
76
  liquidation_risk_percentage: Decimal;
156
77
  max_leverage_to_use: number;
157
78
  }>;
158
- calculateBorrowLendMarketAdditionalMetadata(borrowLendMarkets: BorrowLendPools, asset: AssetName): {
79
+ calculateBorrowLendPoolAdditionalMetadata(borrowLendPools: Map<AssetId, BorrowLendPool>, asset: AssetName): {
159
80
  utilisation_rate: Decimal;
160
81
  current_deposit_rate: Decimal;
161
82
  current_borrow_rate: Decimal;
162
83
  };
163
- calculateAccountSummaryBatch(userAccounts: UserAccount[], marginCalculationState: {
164
- oracle_prices: OraclePrices;
165
- perp_prices: PerpPrices;
166
- margin_config: MarginConfig;
167
- }, useWeightedEquity?: boolean): {
84
+ calculateAccountSummaryBatch(userAccounts: UserAccount[], riskEngine: RiskEngine, useWeightedEquity?: boolean): {
168
85
  address: string;
169
86
  unrealized_pnl: Decimal;
170
87
  equity: Decimal;
@@ -11,7 +11,7 @@ export type OrderId = bigint;
11
11
  export type ClientOrderId = bigint;
12
12
  export type MarketKind = "perp" | "spot";
13
13
  export type Side = "bid" | "ask";
14
- export type SpotCollateralTransferDirection = "margin_to_spot" | "spot_to_margin";
14
+ export type SpotCollateralTransferDirection = "spot_to_margin" | "margin_to_spot";
15
15
  export type TriggerDirection = "greater_than_or_equal" | "less_than_or_equal";
16
16
  export type TriggerPriceCondition = "mark" | "oracle" | "last_trade";
17
17
  export type OrderType = "limit" | "post_only" | "fill_or_kill" | "immediate_or_cancel" | "post_only_slide" | "post_only_front";