@bulletxyz/bullet-sdk 0.20.0-rc.0 → 0.21.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.
@@ -10,25 +10,25 @@ export class BulletWasm {
10
10
  static dummy(a: number): number;
11
11
  static convert_token_id_to_bytes(token_id: string): Uint8Array;
12
12
  static convert_rust_decimal_to_json(decimal_str: string): any;
13
- static calculate_total_perp_unrealized_pnl(user_account: any, margin_context: any): string;
14
- static calculate_account_equity(user_account: any, conservative: boolean, equity_type: EquityType, margin_context: any): string;
15
- static calculate_account_leverage(user_account: any, margin_context: any): string;
16
- static calculate_available_margin(user_account: any, conservative: boolean, margin_type: MarginType, margin_context: any): string;
17
- static calculate_used_margin(user_account: any, margin_type: MarginType, margin_context: any): string;
18
- static calculate_withdrawable_amount_of_asset(user_account: any, asset_id: number, margin_context: any): string;
19
- static calculate_estimated_liquidation_price(user_account: any, asset_id: number, margin_context: any): string;
20
- static calculate_liquidation_risk_percentage(user_account: any, margin_context: any): string;
21
- static calculate_force_cancel_risk_percentage(user_account: any, margin_context: any): string;
13
+ static calculate_total_perp_unrealized_pnl(user_account: any, margin_calculation_state: any): string;
14
+ static calculate_account_equity(user_account: any, conservative: boolean, equity_type: EquityType, margin_calculation_state: any): string;
15
+ static calculate_account_leverage(user_account: any, margin_calculation_state: any): string;
16
+ static calculate_available_margin(user_account: any, conservative: boolean, margin_type: MarginType, margin_calculation_state: any): string;
17
+ static calculate_used_margin(user_account: any, margin_type: MarginType, margin_calculation_state: any): string;
18
+ static calculate_withdrawable_amount_of_asset(user_account: any, asset_id: number, margin_calculation_state: any): string;
19
+ static calculate_estimated_liquidation_price(user_account: any, asset_id: number, margin_calculation_state: any): string;
20
+ static calculate_liquidation_risk_percentage(user_account: any, margin_calculation_state: any): string;
21
+ static calculate_force_cancel_risk_percentage(user_account: any, margin_calculation_state: any): string;
22
22
  /**
23
23
  * Calculates the maximum amount that can be borrowed for a given asset
24
24
  * @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
25
25
  */
26
- static calculate_max_borrow_amount(asset_id: number, initial_liability_weight: string, user_account: any, margin_context: any): string;
27
- static calculate_max_order_size(asset_id: number, price: string, side: Side, order_type: OrderType, reduce_only: boolean, user_account: any, margin_context: any, maker_book: any, n_iterations: number, error_tolerance: string): string;
28
- static simulate_used_margin_on_borrow(asset_id: number, borrow_amount: string, user_account: any, margin_type: MarginType, margin_context: any): any;
29
- static simulate_used_margin_on_order(place_order_args: any, user_account: any, margin_context: any, maker_book: any): any;
30
- static simulate_estimated_liquidation_price_on_order(place_order_args: any, user_account: any, margin_context: any, maker_book: any): any;
31
- static calculate_positions_additional_metadata(user_account: any, margin_context: any, funding_parameters: any): any;
26
+ static calculate_max_borrow_amount(asset_id: number, initial_liability_weight: string, user_account: any, margin_calculation_state: any): string;
27
+ static calculate_max_order_size(asset_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;
28
+ static simulate_used_margin_on_borrow(asset_id: number, borrow_amount: string, user_account: any, margin_type: MarginType, margin_calculation_state: any): any;
29
+ static simulate_used_margin_on_order(place_order_args: any, user_account: any, margin_calculation_state: any, orderbook: any): any;
30
+ static simulate_estimated_liquidation_price_on_order(place_order_args: any, user_account: any, margin_calculation_state: any, orderbook: any): any;
31
+ static calculate_positions_additional_metadata(user_account: any, margin_calculation_state: any, funding_parameters: any): any;
32
32
  static calculate_borrow_lend_additional_metadata(borrow_lend_market: any): any;
33
- static calculate_account_summary_batch(user_accounts: any, margin_context: any): any;
33
+ static calculate_account_summary_batch(user_accounts: any, margin_calculation_state: any): any;
34
34
  }
@@ -1,37 +1,38 @@
1
1
  import Decimal from "decimal.js";
2
2
  import { type EquityType, type MarginType } from "./bullet-wasm";
3
3
  import type { Asset, AssetId, OrderType, PlaceOrderArgs, Side } from "./types";
4
- import type { BorrowLendMarket, MarginConfig, OrderbookL2, PerpMarket, Pricing, UserAccount } from "./zod-types/rest";
4
+ import type { BorrowLendMarket, MarginConfig, OraclePrices, OrderbookL2, PerpMarket, PerpPrices, UserAccount } from "./zod-types/rest";
5
5
  export declare function calculateOrderbookMidpoint(orderbook: OrderbookL2): Decimal | undefined;
6
6
  export declare function calculateEntryPrice(asset: Asset, userAccount: UserAccount): Decimal;
7
- export interface MarginContext {
8
- pricing: Pricing;
7
+ export interface MarginCalculationState {
8
+ oracle_prices: OraclePrices;
9
+ perp_prices: PerpPrices;
9
10
  margin_config: MarginConfig;
10
11
  }
11
- export declare function calculateTotalPerpUnrealizedPnl(userAccount: UserAccount, marginContext: MarginContext): Decimal;
12
- export declare function calculateAccountEquity(equityType: EquityType, conservative: boolean, userAccount: UserAccount, marginContext: MarginContext): Decimal;
13
- export declare function calculateAccountLeverage(userAccount: UserAccount, marginContext: MarginContext): Decimal;
14
- export declare function calculateAvailableMargin(marginType: MarginType, conservative: boolean, userAccount: UserAccount, marginContext: MarginContext): Decimal;
15
- export declare function calculateUsedMargin(marginType: MarginType, userAccount: UserAccount, marginContext: MarginContext): Decimal;
16
- export declare function calculateWithdrawableAmountOfAsset(assetId: AssetId, userAccount: UserAccount, marginContext: MarginContext): Decimal;
17
- export declare function calculateEstimatedLiquidationPrice(assetId: AssetId, userAccount: UserAccount, marginContext: MarginContext): Decimal;
18
- export declare function calculateLiquidationRiskPercentage(userAccount: UserAccount, marginContext: MarginContext): Decimal;
19
- export declare function calculateForceCancelRiskPercentage(userAccount: UserAccount, marginContext: MarginContext): Decimal;
20
- export declare function calculateMaxBorrowAmount(assetId: AssetId, initialLiabilityWeight: Decimal, userAccount: UserAccount, marginContext: MarginContext): Decimal;
21
- export declare function calculateMaxOrderSize(asset_id: AssetId, price: Decimal, side: Side, order_type: OrderType, reduce_only: boolean, userAccount: UserAccount, marginContext: MarginContext, orderbook: OrderbookL2, n_iterations?: number, error_tolerance?: Decimal): Decimal;
22
- export declare function simulateUsedMarginOnBorrow(assetId: AssetId, borrowAmount: Decimal, userAccount: UserAccount, marginType: MarginType, marginContext: MarginContext): {
12
+ export declare function calculateTotalPerpUnrealizedPnl(userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
13
+ export declare function calculateAccountEquity(equityType: EquityType, conservative: boolean, userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
14
+ export declare function calculateAccountLeverage(userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
15
+ export declare function calculateAvailableMargin(marginType: MarginType, conservative: boolean, userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
16
+ export declare function calculateUsedMargin(marginType: MarginType, userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
17
+ export declare function calculateWithdrawableAmountOfAsset(asset_id: AssetId, userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
18
+ export declare function calculateEstimatedLiquidationPrice(asset_id: AssetId, userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
19
+ export declare function calculateLiquidationRiskPercentage(userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
20
+ export declare function calculateForceCancelRiskPercentage(userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
21
+ export declare function calculateMaxBorrowAmount(asset_id: AssetId, initialLiabilityWeight: Decimal, userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
22
+ export declare function calculateMaxOrderSize(asset: Asset, price: Decimal, side: Side, order_type: OrderType, reduce_only: boolean, userAccount: UserAccount, MarginCalculationState: MarginCalculationState, orderbook: OrderbookL2, n_iterations?: number, error_tolerance?: Decimal): Decimal;
23
+ export declare function simulateUsedMarginOnBorrow(asset_id: AssetId, borrowAmount: Decimal, userAccount: UserAccount, marginType: MarginType, MarginCalculationState: MarginCalculationState): {
23
24
  current: Decimal;
24
25
  updated: Decimal;
25
26
  };
26
- export declare function simulateUsedMarginOnOrder(placeOrderArgs: PlaceOrderArgs, userAccount: UserAccount, marginContext: MarginContext, orderbook: OrderbookL2): {
27
+ export declare function simulateUsedMarginOnOrder(placeOrderArgs: PlaceOrderArgs, userAccount: UserAccount, MarginCalculationState: MarginCalculationState, orderbook: OrderbookL2): {
27
28
  current: Decimal;
28
29
  updated: Decimal;
29
30
  };
30
- export declare function simulateEstimatedLiquidationPriceOnOrder(placeOrderArgs: PlaceOrderArgs, userAccount: UserAccount, marginContext: MarginContext, orderbook: OrderbookL2): {
31
+ export declare function simulateEstimatedLiquidationPriceOnOrder(placeOrderArgs: PlaceOrderArgs, userAccount: UserAccount, MarginCalculationState: MarginCalculationState, orderbook: OrderbookL2): {
31
32
  current: Decimal;
32
33
  updated: Decimal;
33
34
  };
34
- export declare function calculatePositionsAdditionalMetadata(userAccount: UserAccount, marginContext: MarginContext, perpMarkets: Map<Asset, PerpMarket>): Map<number, {
35
+ export declare function calculatePositionsAdditionalMetadata(userAccount: UserAccount, MarginCalculationState: MarginCalculationState, perpMarkets: Map<Asset, PerpMarket>): Map<number, {
35
36
  projected_funding_payment: Decimal;
36
37
  unrealized_pnl: Decimal;
37
38
  liquidation_price: Decimal;
@@ -43,7 +44,7 @@ export declare function calculateBorrowLendMarketAdditionalMetadata(borrowLendMa
43
44
  current_deposit_rate: Decimal;
44
45
  current_borrow_rate: Decimal;
45
46
  };
46
- export declare function calculateAccountSummaryBatch(userAccounts: UserAccount[], marginContext: MarginContext): {
47
+ export declare function calculateAccountSummaryBatch(userAccounts: UserAccount[], MarginCalculationState: MarginCalculationState): {
47
48
  unrealized_pnl: Decimal;
48
49
  equity: Decimal;
49
50
  available_initial_margin: Decimal;
@@ -3,7 +3,7 @@ import type Decimal from "decimal.js";
3
3
  import { Connection } from "./connection";
4
4
  import { ExchangeConnection } from "./exchange";
5
5
  import type { RuntimeCall } from "./rollupTypes";
6
- import { type Address, type Asset, type Network, type PlaceOrderArgs, type TokenId, type TpslOrder } from "./types";
6
+ import { type Address, type Asset, type MarkPriceUpdateArgs, type Network, type OraclePriceUpdateArgs, type PlaceOrderArgs, type TokenId, type TpslOrder } from "./types";
7
7
  import type { Wallet } from "./wallet";
8
8
  export interface TransactionOpts {
9
9
  maxPriorityFeeBps: number;
@@ -25,6 +25,7 @@ export declare class Client {
25
25
  getNonce(): Promise<import("@sovereign-sdk/web3").Dedup>;
26
26
  getTokenBalance(tokenId: string): Promise<bigint>;
27
27
  getUserAccount(): Promise<{
28
+ address: string;
28
29
  usdc_ledger: {
29
30
  ledger: {
30
31
  weights: {
@@ -49,13 +50,15 @@ export declare class Client {
49
50
  }>;
50
51
  perp_ledgers: Map<number, {
51
52
  orders: Map<bigint, {
52
- size: Decimal;
53
- price: Decimal;
54
53
  side: "Bid" | "Ask";
54
+ asset_id: number;
55
55
  order_id: bigint;
56
+ price: Decimal;
57
+ remaining_size: Decimal;
56
58
  reduce_only: boolean;
57
59
  filled_size: Decimal;
58
60
  average_filled_price: Decimal;
61
+ owner: string;
59
62
  tpsl_order_ids: bigint[];
60
63
  }>;
61
64
  position: {
@@ -70,6 +73,8 @@ export declare class Client {
70
73
  user_selected_max_leverage: number;
71
74
  tpsls: Map<bigint, {
72
75
  side: "Bid" | "Ask";
76
+ asset_id: number;
77
+ owner: string;
73
78
  tpsl_order_id: bigint;
74
79
  order_price: Decimal;
75
80
  trigger_price: Decimal;
@@ -82,7 +87,7 @@ export declare class Client {
82
87
  linked_tpsl_order_ids: bigint[];
83
88
  }>;
84
89
  }>;
85
- } | undefined>;
90
+ }>;
86
91
  submitTransaction(runtimeCall: RuntimeCall): Promise<TransactionResult<Transaction<RuntimeCall>>>;
87
92
  transfer(to: Address, amount: bigint, tokenId: TokenId): Promise<TransactionResult<Transaction<RuntimeCall>>>;
88
93
  mint(to: Address, amount: bigint, tokenId: TokenId): Promise<TransactionResult<Transaction<RuntimeCall>>>;
@@ -96,12 +101,8 @@ export declare class Client {
96
101
  cancelTpsl(tpslOrderId: bigint): Promise<TransactionResult<Transaction<RuntimeCall>>>;
97
102
  cancelOrder(orderId: bigint): Promise<TransactionResult<Transaction<RuntimeCall>>>;
98
103
  cancelAllOrders(asset: Asset): Promise<TransactionResult<Transaction<RuntimeCall>>>;
99
- updatePricing(pricing_updates: {
100
- asset: Asset;
101
- medianCexPrice: Decimal;
102
- oraclePrice: Decimal;
103
- diffEma: Decimal;
104
- }[], publishTimestamp?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
104
+ updateOraclePrices(pricesToUpdate: OraclePriceUpdateArgs[], publishTimestamp?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
105
+ updateMarkPrices(pricesToUpdate: MarkPriceUpdateArgs[], publishTimestamp?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
105
106
  updateAssetMaxLeverage(asset: Asset, maxLeverage: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
106
107
  updatePremiumIndexes(assetIds: Asset[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
107
108
  updateFunding(assetIds: Asset[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
@@ -3,6 +3,7 @@ export declare class BaseConnection {
3
3
  endpoint: string;
4
4
  constructor(rawEndpoint?: string);
5
5
  protected fetchApiResource<T>(path: string, params?: Record<string, string>): Promise<T>;
6
+ protected fetchBulkApiResource<T>(path: string, body: Record<string, unknown>, params?: Record<string, string>): Promise<T>;
6
7
  }
7
8
  export declare class Connection extends BaseConnection {
8
9
  getNonce(address: Address): Promise<number>;
@@ -1,23 +1,28 @@
1
1
  import { BaseConnection } from "./connection";
2
2
  import type { Orderbook } from "./orderbook";
3
- import type { AssetId, Network } from "./types";
4
- import { type BorrowLendMarket, type MarginConfig, type Order, type OrderbookL2, type PerpMarket, type Pricing, type UsdcInsuranceFund, type UsdcPnlPool, type UserAccount } from "./zod-types/rest";
3
+ import type { Address, Asset, AssetId, Network } from "./types";
4
+ import { type BorrowLendMarket, type MarginConfig, type OraclePrices, type Order, type OrderbookL2, type PerpMarket, type PerpPrices, type UsdcInsuranceFund, type UsdcPnlPool, type UserAccount } from "./zod-types/rest";
5
5
  export declare class ExchangeConnection extends BaseConnection {
6
6
  private wsManager;
7
7
  constructor(network: Network);
8
8
  getValue(): Promise<number | null>;
9
9
  getOrder(order_id: bigint): Promise<Order | null>;
10
- getOrderbookL2(asset_id: number, levels?: number): Promise<OrderbookL2>;
11
- getUserAccountAddresses(start?: number, limit?: number): Promise<string[]>;
12
- getUserAccounts(addresses: string[]): Promise<Map<string, UserAccount>>;
13
- getPricing(): Promise<Pricing | null>;
10
+ getOrderbookL2(asset: Asset, levels?: number): Promise<OrderbookL2>;
11
+ getOrderbookL2s(assets: Asset[], levels?: number): Promise<Map<Asset, OrderbookL2>>;
12
+ getUserAccountAddresses(start?: number, limit?: number): Promise<Address[]>;
13
+ getUserAccount(address: Address): Promise<UserAccount>;
14
+ getUserAccounts(addresses: Address[]): Promise<Map<string, UserAccount>>;
15
+ getOraclePrices(): Promise<OraclePrices | null>;
16
+ getPerpPrices(): Promise<PerpPrices | null>;
14
17
  getUsdcPnlPool(): Promise<UsdcPnlPool | null>;
15
18
  getUsdcInsuranceFund(): Promise<UsdcInsuranceFund | null>;
16
- getBorrowLendMarkets(asset_ids: AssetId[]): Promise<Map<AssetId, BorrowLendMarket>>;
17
- getPerpMarkets(asset_ids: AssetId[]): Promise<Map<AssetId, PerpMarket>>;
19
+ getBorrowLendMarket(asset: Asset): Promise<BorrowLendMarket>;
20
+ getBorrowLendMarkets(assets: Asset[]): Promise<Map<Asset, BorrowLendMarket>>;
21
+ getPerpMarket(asset: Asset): Promise<PerpMarket>;
22
+ getPerpMarkets(assets: Asset[]): Promise<Map<Asset, PerpMarket>>;
18
23
  getMarginConfig(): Promise<MarginConfig | null>;
19
- getPerpAssets(): Promise<Map<AssetId, string>>;
20
- getBorrowLendAssets(): Promise<Map<AssetId, string>>;
24
+ getPerpAssets(): Promise<Map<Asset, string>>;
25
+ getBorrowLendAssets(): Promise<Map<Asset, string>>;
21
26
  subscribeOrderbook(assetId: AssetId): AsyncIterable<Orderbook>;
22
27
  unsubscribeOrderbook(assetId: AssetId): Promise<void>;
23
28
  }
@@ -80,11 +80,17 @@ type ExchangeCallMessage = {
80
80
  cancel_all_orders: {
81
81
  asset_id: AssetId;
82
82
  };
83
- update_pricing: {
83
+ update_oracle_prices: {
84
84
  prices_to_update: {
85
85
  asset_id: AssetId;
86
- median_cex_price: number;
87
86
  oracle_price: number;
87
+ }[];
88
+ publish_timestamp: number;
89
+ };
90
+ update_mark_prices: {
91
+ prices_to_update: {
92
+ asset_id: AssetId;
93
+ median_cex_price: number;
88
94
  diff_ema: number;
89
95
  }[];
90
96
  publish_timestamp: number;
@@ -32,12 +32,21 @@ export type MarginType = "Initial" | "Maintenance";
32
32
  export type EquityType = "Unweighted" | "WeightedInitial" | "WeightedMaintenance";
33
33
  export type Network = "Localnet" | "Staging" | "Testnet" | "Mainnet";
34
34
  export type PlaceOrderArgs = {
35
- asset_id: AssetId;
35
+ asset: Asset;
36
36
  price: Decimal;
37
37
  size: Decimal;
38
38
  side: Side;
39
- order_type: OrderType;
40
- reduce_only: boolean;
39
+ orderType: OrderType;
40
+ reduceOnly: boolean;
41
+ };
42
+ export type OraclePriceUpdateArgs = {
43
+ asset: Asset;
44
+ oraclePrice: Decimal;
45
+ };
46
+ export type MarkPriceUpdateArgs = {
47
+ asset: Asset;
48
+ medianCexPrice: Decimal;
49
+ diffEma: Decimal;
41
50
  };
42
51
  export type TpslOrder = {
43
52
  orderPrice: Decimal;