@bulletxyz/bullet-sdk 0.25.4 → 0.26.0-rc.1

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.
@@ -7,7 +7,6 @@ export * from "./zod-types/rest";
7
7
  export * from "./zod-types/ws";
8
8
  export * from "./zod-types/wasm";
9
9
  export * from "./constants";
10
- export * from "./calc";
11
10
  export * from "./error";
12
11
  export { Wallet } from "./wallet";
13
12
  export { Connection } from "./connection";
@@ -14,7 +14,7 @@ export class BulletWasm {
14
14
  static calculate_account_equity(user_account: any, conservative: boolean, equity_type: EquityType, margin_calculation_state: any): string;
15
15
  static calculate_account_leverage(user_account: any, margin_calculation_state: any): string;
16
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;
17
+ static calculate_used_margin(user_account: any, withdrawal: boolean, margin_type: MarginType, margin_calculation_state: any): string;
18
18
  static calculate_withdrawable_amount_of_asset(user_account: any, asset_id: number, margin_calculation_state: any): string;
19
19
  static calculate_estimated_liquidation_price(user_account: any, market_id: number, base_asset_id: number, margin_calculation_state: any): string;
20
20
  static calculate_liquidation_risk_percentage(user_account: any, margin_calculation_state: any): string;
@@ -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 Asset, type MarkPriceUpdateArgs, type Market, type Network, type OraclePriceUpdateArgs, type PlaceOrderArgs, type PlacePositionTpslArgs, type TokenId } from "./types";
7
+ import { type Address, type AssetName, type MarkPriceUpdateArgs, type MarketName, type Network, type OraclePriceUpdateArgs, type PlaceOrderArgs, type PlacePositionTpslArgs, type TokenId } from "./types";
8
8
  import type { Wallet } from "./wallet";
9
9
  export interface TransactionOpts {
10
10
  maxPriorityFeeBps: number;
@@ -12,7 +12,7 @@ export interface TransactionOpts {
12
12
  gasLimit: number[] | null;
13
13
  chainId: number;
14
14
  }
15
- type ReplaceOrderOptions = {
15
+ type AmendOrderOptions = {
16
16
  existingOrderId: bigint;
17
17
  existingClientOrderId?: never;
18
18
  placeOrderArgs: PlaceOrderArgs;
@@ -111,30 +111,33 @@ export declare class Client {
111
111
  submitTransaction(runtimeCall: RuntimeCall): Promise<TransactionResult<Transaction<RuntimeCall>>>;
112
112
  transfer(to: Address, amount: bigint, tokenId: TokenId): Promise<TransactionResult<Transaction<RuntimeCall>>>;
113
113
  mint(to: Address, amount: bigint, tokenId: TokenId): Promise<TransactionResult<Transaction<RuntimeCall>>>;
114
- deposit(asset: Asset, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
115
- withdraw(asset: Asset, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
116
- borrowSpot(asset: Asset, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
114
+ deposit(asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
115
+ withdraw(asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
116
+ borrowSpot(asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
117
117
  placeOrder(placeOrderArgs: PlaceOrderArgs): Promise<TransactionResult<Transaction<RuntimeCall>>>;
118
- placeTpslsForMarket(market: Market, tpslOrders: PlacePositionTpslArgs): Promise<TransactionResult<Transaction<RuntimeCall>>>;
119
- replaceOrder(options: ReplaceOrderOptions): Promise<TransactionResult<Transaction<RuntimeCall>>>;
118
+ createPositionTpsl(market: MarketName, tpslOrders: PlacePositionTpslArgs): Promise<TransactionResult<Transaction<RuntimeCall>>>;
119
+ amendOrder(options: AmendOrderOptions): Promise<TransactionResult<Transaction<RuntimeCall>>>;
120
120
  cancelTpsl(tpslOrderId: bigint): Promise<TransactionResult<Transaction<RuntimeCall>>>;
121
121
  cancelOrder(orderId?: bigint, clientOrderId?: bigint): Promise<TransactionResult<Transaction<RuntimeCall>>>;
122
- cancelAllOrdersForMarket(market: Market): Promise<TransactionResult<Transaction<RuntimeCall>>>;
122
+ cancelAllOrdersForMarket(market: MarketName): Promise<TransactionResult<Transaction<RuntimeCall>>>;
123
123
  updateOraclePrices(pricesToUpdate: OraclePriceUpdateArgs[], publishTimestamp?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
124
124
  updateMarkPrices(pricesToUpdate: MarkPriceUpdateArgs[], publishTimestamp?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
125
- updateMaxLeverageForMarket(market: Market, maxLeverage: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
126
- updatePremiumIndexes(marketIds: Market[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
127
- processTpslBufferForMarket(market: Market): Promise<TransactionResult<Transaction<RuntimeCall>>>;
128
- updateFunding(marketIds: Market[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
125
+ updateMaxLeverageForMarket(market: MarketName, maxLeverage: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
126
+ updatePremiumIndexes(markets: MarketName[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
127
+ processTpslBufferForMarket(market: MarketName): Promise<TransactionResult<Transaction<RuntimeCall>>>;
128
+ updateFunding(markets: MarketName[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
129
129
  applyFunding(addresses: Address[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
130
130
  forceCancelOrders(address: Address): Promise<TransactionResult<Transaction<RuntimeCall>>>;
131
131
  forceClosePositions(address: Address): Promise<TransactionResult<Transaction<RuntimeCall>>>;
132
132
  liquidatePerpPositions(address: Address, positions?: {
133
- market: Market;
133
+ market: MarketName;
134
134
  size: Decimal;
135
135
  }[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
136
- liquidateSpotLiability(address: Address, liabilityAssetId: Asset, collateralAssetId: Asset, liabilityAmount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
136
+ liquidateSpotLiability(address: Address, liabilityAssetId: AssetName, collateralAssetId: AssetName, liabilityAmount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
137
137
  depositToUsdcPnlPool(amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
138
138
  depositToInsuranceFund(amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
139
+ initAssetMetadata(asset_id: number, assetName: string, tokenId: TokenId, decimals: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
140
+ initBorrowLendMarket(asset: AssetName, optimalUtilisationRate: Decimal, minBorrowRate: Decimal, maxBorrowRate: Decimal, optimalBorrowRate: Decimal, assetWeight: Decimal, initialLiabilityWeight: Decimal, maintenanceLiabilityWeight: Decimal, depositLimit: Decimal, borrowLimit: Decimal, liquidationRewardRatio: Decimal, liabilityLiquidationLimitRatio: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
141
+ updateBorrowLendMarket(asset: AssetName, optimalUtilisationRate: Decimal | null, minBorrowRate: Decimal | null, maxBorrowRate: Decimal | null, optimalBorrowRate: Decimal | null, assetWeight: Decimal | null, initialLiabilityWeight: Decimal | null, maintenanceLiabilityWeight: Decimal | null, depositLimit: Decimal | null, borrowLimit: Decimal | null, liquidationRewardRatio: Decimal | null, liabilityLiquidationLimitRatio: Decimal | null): Promise<TransactionResult<Transaction<RuntimeCall>>>;
139
142
  }
140
143
  export {};
@@ -1,19 +1,35 @@
1
+ import Decimal from "decimal.js";
2
+ import { type EquityType, type MarginType } from "./bullet-wasm";
1
3
  import { BaseConnection } from "./connection";
2
4
  import { type Endpoints } from "./constants";
3
5
  import type { Orderbook } from "./orderbook";
4
- import type { Address, Market, Network } from "./types";
6
+ import type { Address, AssetName, MarketName, Network } from "./types";
7
+ import type { OrderType, PlaceOrderArgs, Side } from "./types";
5
8
  import { type AccountAddresses, type AssetRegistry, type BorrowLendMarkets, type GlobalParameters, type MarginConfig, type MarketRegistry, type OraclePrices, type Order, type OrderbookL2, type PerpMarket, type PerpPrices, type TpslOrderIdsToExecute, type UsdcInsuranceFund, type UsdcPnlPool, type UserAccount } from "./zod-types/rest";
6
9
  export declare class ExchangeConnection extends BaseConnection {
7
10
  private wsManager?;
11
+ private assetRegistry?;
12
+ private assetRegistryReverse?;
13
+ private marketRegistry?;
14
+ private marketRegistryReverse?;
8
15
  private constructor();
9
- static fromEndpoints(endpoints: Endpoints): ExchangeConnection;
10
- static fromNetwork(network: Network): ExchangeConnection;
11
- static fromRestUrl(restUrl: string): ExchangeConnection;
12
- getOrder(order_id: bigint): Promise<Order | null>;
16
+ static fromEndpoints(endpoints: Endpoints): Promise<ExchangeConnection>;
17
+ static fromNetwork(network: Network): Promise<ExchangeConnection>;
18
+ static fromRestUrl(restUrl: string): Promise<ExchangeConnection>;
19
+ private initializeRegistries;
20
+ private initializeAssetRegistry;
21
+ private initializeMarketRegistry;
22
+ getOrder(orderId: bigint): Promise<Order | null>;
13
23
  getMarketRegistry(): Promise<MarketRegistry | null>;
14
24
  getAssetRegistry(): Promise<AssetRegistry | null>;
15
- getOrderbookL2(market: Market, levels?: number): Promise<OrderbookL2>;
16
- getOrderbookL2s(markets: Market[], levels?: number): Promise<Map<Market, OrderbookL2>>;
25
+ private getAssetMapping;
26
+ private getMarketMapping;
27
+ getAssetId(asset: AssetName): number;
28
+ getAssetName(assetId: number): AssetName;
29
+ getMarketId(market: MarketName): number;
30
+ getMarketName(marketId: number): string;
31
+ getOrderbookL2(market: MarketName, levels?: number): Promise<OrderbookL2>;
32
+ getOrderbookL2s(markets: MarketName[], levels?: number): Promise<Map<number, OrderbookL2>>;
17
33
  getUserAccountAddresses(offset?: number, limit?: number): Promise<AccountAddresses>;
18
34
  getUserAccount(address: Address): Promise<UserAccount>;
19
35
  getUserAccounts(addresses: Address[]): Promise<Map<string, UserAccount>>;
@@ -22,12 +38,121 @@ export declare class ExchangeConnection extends BaseConnection {
22
38
  getUsdcPnlPool(): Promise<UsdcPnlPool | null>;
23
39
  getUsdcInsuranceFund(): Promise<UsdcInsuranceFund | null>;
24
40
  getBorrowLendMarkets(): Promise<BorrowLendMarkets>;
25
- getPerpMarket(market: Market): Promise<PerpMarket>;
26
- getPerpMarkets(markets: Market[]): Promise<Map<Market, PerpMarket>>;
41
+ getPerpMarket(market: MarketName): Promise<PerpMarket>;
42
+ getPerpMarkets(markets: MarketName[]): Promise<Map<number, PerpMarket>>;
27
43
  getMarginConfig(): Promise<MarginConfig | null>;
28
- getTpslOrderIdsToExecute(market: Market): Promise<TpslOrderIdsToExecute | null>;
44
+ getTpslOrderIdsToExecute(market: MarketName): Promise<TpslOrderIdsToExecute | null>;
29
45
  getGlobalParameters(): Promise<GlobalParameters | null>;
46
+ calculateOrderbookMidpoint(orderbook: OrderbookL2): Decimal | undefined;
47
+ calculateEntryPrice(market: MarketName, userAccount: UserAccount): Promise<Decimal>;
48
+ calculateTotalPerpUnrealizedPnl(userAccount: UserAccount, MarginCalculationState: {
49
+ oracle_prices: OraclePrices;
50
+ perp_prices: PerpPrices;
51
+ margin_config: MarginConfig;
52
+ }): Decimal;
53
+ calculateAccountEquity(equityType: EquityType, conservative: boolean, userAccount: UserAccount, MarginCalculationState: {
54
+ oracle_prices: OraclePrices;
55
+ perp_prices: PerpPrices;
56
+ margin_config: MarginConfig;
57
+ }): Decimal;
58
+ calculateAccountLeverage(userAccount: UserAccount, MarginCalculationState: {
59
+ oracle_prices: OraclePrices;
60
+ perp_prices: PerpPrices;
61
+ margin_config: MarginConfig;
62
+ }): Decimal;
63
+ calculateAvailableMargin(marginType: MarginType, conservative: boolean, userAccount: UserAccount, MarginCalculationState: {
64
+ oracle_prices: OraclePrices;
65
+ perp_prices: PerpPrices;
66
+ margin_config: MarginConfig;
67
+ }): Decimal;
68
+ calculateUsedMargin(withdrawal: boolean, marginType: MarginType, userAccount: UserAccount, MarginCalculationState: {
69
+ oracle_prices: OraclePrices;
70
+ perp_prices: PerpPrices;
71
+ margin_config: MarginConfig;
72
+ }): Decimal;
73
+ calculateWithdrawableAmountOfAsset(asset: AssetName, userAccount: UserAccount, MarginCalculationState: {
74
+ oracle_prices: OraclePrices;
75
+ perp_prices: PerpPrices;
76
+ margin_config: MarginConfig;
77
+ }): Promise<Decimal>;
78
+ calculateEstimatedLiquidationPrice(market: MarketName, asset: AssetName, userAccount: UserAccount, MarginCalculationState: {
79
+ oracle_prices: OraclePrices;
80
+ perp_prices: PerpPrices;
81
+ margin_config: MarginConfig;
82
+ }): Promise<Decimal>;
83
+ calculateLiquidationRiskPercentage(userAccount: UserAccount, MarginCalculationState: {
84
+ oracle_prices: OraclePrices;
85
+ perp_prices: PerpPrices;
86
+ margin_config: MarginConfig;
87
+ }): Decimal;
88
+ calculateForceCancelRiskPercentage(userAccount: UserAccount, MarginCalculationState: {
89
+ oracle_prices: OraclePrices;
90
+ perp_prices: PerpPrices;
91
+ margin_config: MarginConfig;
92
+ }): Decimal;
93
+ calculateMaxBorrowAmount(asset: AssetName, userAccount: UserAccount, MarginCalculationState: {
94
+ oracle_prices: OraclePrices;
95
+ perp_prices: PerpPrices;
96
+ margin_config: MarginConfig;
97
+ }): Promise<Decimal>;
98
+ calculateMaxOrderSize(market: MarketName, price: Decimal, side: Side, order_type: OrderType, reduce_only: boolean, userAccount: UserAccount, MarginCalculationState: {
99
+ oracle_prices: OraclePrices;
100
+ perp_prices: PerpPrices;
101
+ margin_config: MarginConfig;
102
+ }, orderbook: OrderbookL2, n_iterations?: number, error_tolerance?: Decimal): Promise<Decimal>;
103
+ simulateUsedMarginOnBorrow(asset: AssetName, borrowAmount: Decimal, userAccount: UserAccount, marginType: MarginType, MarginCalculationState: {
104
+ oracle_prices: OraclePrices;
105
+ perp_prices: PerpPrices;
106
+ margin_config: MarginConfig;
107
+ }): Promise<{
108
+ current: Decimal;
109
+ updated: Decimal;
110
+ }>;
111
+ simulateUsedMarginOnOrder(placeOrderArgs: PlaceOrderArgs, userAccount: UserAccount, MarginCalculationState: {
112
+ oracle_prices: OraclePrices;
113
+ perp_prices: PerpPrices;
114
+ margin_config: MarginConfig;
115
+ }, orderbook: OrderbookL2): Promise<{
116
+ current: Decimal;
117
+ updated: Decimal;
118
+ }>;
119
+ simulateEstimatedLiquidationPriceOnOrder(placeOrderArgs: PlaceOrderArgs, baseAsset: AssetName, userAccount: UserAccount, MarginCalculationState: {
120
+ oracle_prices: OraclePrices;
121
+ perp_prices: PerpPrices;
122
+ margin_config: MarginConfig;
123
+ }, orderbook: OrderbookL2): Promise<{
124
+ current: Decimal;
125
+ updated: Decimal;
126
+ }>;
127
+ calculatePositionsAdditionalMetadata(userAccount: UserAccount, MarginCalculationState: {
128
+ oracle_prices: OraclePrices;
129
+ perp_prices: PerpPrices;
130
+ margin_config: MarginConfig;
131
+ }): Promise<Map<number, {
132
+ projected_funding_payment: Decimal;
133
+ unrealized_pnl: Decimal;
134
+ liquidation_price: Decimal;
135
+ liquidation_risk_percentage: Decimal;
136
+ max_leverage_to_use: number;
137
+ }>>;
138
+ calculateBorrowLendMarketAdditionalMetadata(borrowLendMarkets: BorrowLendMarkets, asset: AssetName): Promise<{
139
+ utilisation_rate: Decimal;
140
+ current_deposit_rate: Decimal;
141
+ current_borrow_rate: Decimal;
142
+ }>;
143
+ calculateAccountSummaryBatch(userAccounts: UserAccount[], MarginCalculationState: {
144
+ oracle_prices: OraclePrices;
145
+ perp_prices: PerpPrices;
146
+ margin_config: MarginConfig;
147
+ }, useWeightedEquity?: boolean): Promise<{
148
+ address: string;
149
+ unrealized_pnl: Decimal;
150
+ equity: Decimal;
151
+ available_initial_margin: Decimal;
152
+ available_maintenance_margin: Decimal;
153
+ leverage: Decimal;
154
+ }[]>;
30
155
  private getWebSocketManager;
31
- subscribeOrderbook(marketId: Market): AsyncIterable<Orderbook>;
32
- unsubscribeOrderbook(marketId: Market): Promise<void>;
156
+ subscribeOrderbook(market: MarketName): AsyncIterable<Orderbook>;
157
+ unsubscribeOrderbook(market: MarketName): Promise<void>;
33
158
  }
@@ -9,6 +9,5 @@ export * from "./zod-types/ws";
9
9
  export * from "./zod-types/wasm";
10
10
  export * from "./constants";
11
11
  export * from "./wallet/nodeWallet";
12
- export * from "./calc";
13
12
  export * from "./error";
14
13
  export { Connection } from "./connection";
@@ -1,12 +1,11 @@
1
1
  import Decimal from "decimal.js";
2
- import type { Market } from "./types";
3
2
  import type { OrderbookL2, PriceLevel } from "./zod-types/rest";
4
3
  import type { OrderbookUpdate } from "./zod-types/ws";
5
4
  type Size = Decimal;
6
5
  export declare class Orderbook {
7
6
  bids: Map<string, Size>;
8
7
  asks: Map<string, Size>;
9
- market: Market;
8
+ marketId: number;
10
9
  lastUpdated: number;
11
10
  constructor(marketId: number, snapshot?: OrderbookUpdate);
12
11
  protected updateBid(price: string, size: Size): void;
@@ -22,6 +22,27 @@ type BankCallMessage = {
22
22
  };
23
23
  };
24
24
  };
25
+ type WarpCallMessage = {
26
+ Register: {
27
+ admin: {
28
+ InsecureOwner: Address;
29
+ };
30
+ ism: {
31
+ MessageIdMultisig: {
32
+ threshold: number;
33
+ validators: string[];
34
+ };
35
+ };
36
+ token_source: {
37
+ Synthetic: {
38
+ remote_token_id: string;
39
+ local_decimals: number;
40
+ remote_decimals: number;
41
+ };
42
+ };
43
+ remote_routers: [number, string][];
44
+ };
45
+ };
25
46
  type TriggerOrderArgs = {
26
47
  order_price: number;
27
48
  trigger_price: number;
@@ -65,11 +86,11 @@ type ExchangeCallMessage = {
65
86
  tpsl: PendingTriggerOrderArgs | null;
66
87
  };
67
88
  };
68
- place_tpsl_for_market: {
89
+ create_position_tpsl: {
69
90
  market_id: MarketId;
70
91
  tpsl: PlacePositionTpslArgs;
71
92
  };
72
- replace_order: {
93
+ amend_order: {
73
94
  existing_order_id: string | null;
74
95
  existing_client_order_id: string | null;
75
96
  order_args: {
@@ -149,9 +170,50 @@ type ExchangeCallMessage = {
149
170
  deposit_to_insurance_fund: {
150
171
  usdc_amount: number;
151
172
  };
173
+ init_asset_metadata: {
174
+ args: {
175
+ asset_id: AssetId;
176
+ asset_name: string;
177
+ token_id: TokenId;
178
+ decimals: number;
179
+ };
180
+ };
181
+ init_borrow_lend_market: {
182
+ args: {
183
+ asset_id: AssetId;
184
+ optimal_utilisation_rate: number;
185
+ min_borrow_rate: number;
186
+ max_borrow_rate: number;
187
+ optimal_borrow_rate: number;
188
+ asset_weight: number;
189
+ initial_liability_weight: number;
190
+ maintenance_liability_weight: number;
191
+ deposit_limit: number;
192
+ borrow_limit: number;
193
+ liquidation_reward_ratio: number;
194
+ liability_liquidation_limit_ratio: number;
195
+ };
196
+ };
197
+ update_borrow_lend_market: {
198
+ args: {
199
+ asset_id: AssetId;
200
+ optimal_utilisation_rate: number | null;
201
+ min_borrow_rate: number | null;
202
+ max_borrow_rate: number | null;
203
+ optimal_borrow_rate: number | null;
204
+ asset_weight: number | null;
205
+ initial_liability_weight: number | null;
206
+ maintenance_liability_weight: number | null;
207
+ deposit_limit: number | null;
208
+ borrow_limit: number | null;
209
+ liquidation_reward_ratio: number | null;
210
+ liability_liquidation_limit_ratio: number | null;
211
+ };
212
+ };
152
213
  };
153
214
  export type RuntimeCall = ExactlyOne<{
154
215
  exchange: ExactlyOne<ExchangeCallMessage>;
155
216
  bank: ExactlyOne<BankCallMessage>;
217
+ warp: ExactlyOne<WarpCallMessage>;
156
218
  }>;
157
219
  export {};
@@ -3,47 +3,12 @@ export type PrivateKey = string;
3
3
  export type PublicKey = string;
4
4
  export type Address = string;
5
5
  export type TokenId = string;
6
+ export type AssetName = string;
7
+ export type MarketName = string;
6
8
  export type AssetId = number;
7
9
  export type MarketId = number;
8
10
  export type OrderId = bigint;
9
11
  export type ClientOrderId = bigint;
10
- export declare enum Asset {
11
- USDC = 0,
12
- SOL = 1,
13
- BTC = 2,
14
- ETH = 3,
15
- DOGE = 4,
16
- WIF = 5,
17
- XRP = 6,
18
- HYPE = 7,
19
- ADA = 8,
20
- TRUMP = 9,
21
- SUI = 10,
22
- JUP = 11,
23
- JTO = 12,
24
- ENA = 13,
25
- BERA = 14,
26
- TIA = 15,
27
- ZEX = 16
28
- }
29
- export declare enum Market {
30
- SOL_USD = 0,
31
- BTC_USD = 1,
32
- ETH_USD = 2,
33
- DOGE_USD = 3,
34
- WIF_USD = 4,
35
- XRP_USD = 5,
36
- HYPE_USD = 6,
37
- ADA_USD = 7,
38
- TRUMP_USD = 8,
39
- SUI_USD = 9,
40
- JUP_USD = 10,
41
- JTO_USD = 11,
42
- ENA_USD = 12,
43
- BERA_USD = 13,
44
- TIA_USD = 14,
45
- ZEX_USD = 15
46
- }
47
12
  export type MarketKind = "Perp" | "Spot";
48
13
  export type Side = "Bid" | "Ask";
49
14
  export type TriggerDirection = "GreaterThanOrEqual" | "LessThanOrEqual";
@@ -53,7 +18,7 @@ export type MarginType = "Initial" | "Maintenance";
53
18
  export type EquityType = "Unweighted" | "WeightedInitial" | "WeightedMaintenance";
54
19
  export type Network = "Localnet" | "Staging" | "Testnet" | "Mainnet";
55
20
  export type PlaceOrderArgs = {
56
- marketId: MarketId;
21
+ market: MarketName;
57
22
  price: Decimal;
58
23
  size: Decimal;
59
24
  side: Side;
@@ -63,11 +28,11 @@ export type PlaceOrderArgs = {
63
28
  tpsl?: PendingTriggerOrderArgs;
64
29
  };
65
30
  export type OraclePriceUpdateArgs = {
66
- assetId: AssetId;
31
+ asset: AssetName;
67
32
  oraclePrice: Decimal;
68
33
  };
69
34
  export type MarkPriceUpdateArgs = {
70
- marketId: MarketId;
35
+ market: MarketName;
71
36
  medianCexPrice: Decimal;
72
37
  diffEma: Decimal;
73
38
  };
@@ -1,5 +1,5 @@
1
1
  import { Orderbook } from "./orderbook";
2
- import type { AssetId } from "./types";
2
+ import type { MarketId } from "./types";
3
3
  export declare class WebSocketManager {
4
4
  private socket;
5
5
  private orderbooks;
@@ -19,6 +19,6 @@ export declare class WebSocketManager {
19
19
  private stopHeartbeat;
20
20
  private sendSubscription;
21
21
  sendMessage(message: string): void;
22
- subscribeOrderbook(assetId: AssetId): AsyncIterable<Orderbook>;
23
- unsubscribeOrderbook(assetId: AssetId): Promise<void>;
22
+ subscribeOrderbook(marketId: MarketId): AsyncIterable<Orderbook>;
23
+ unsubscribeOrderbook(marketId: MarketId): Promise<void>;
24
24
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "git+https://github.com/zetamarkets/bullet-sdk.git"
6
6
  },
7
- "version": "0.25.4",
7
+ "version": "0.26.0-rc.1",
8
8
  "description": "Bullet SDK",
9
9
  "author": "@bulletxyz",
10
10
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  "build:js": "node build.mjs",
32
32
  "clean": "rm -rf dist",
33
33
  "build": "pnpm clean && pnpm build:types && pnpm build:js",
34
- "dev": "tsx --experimental-wasm-modules examples/test.ts",
34
+ "dev": "tsx --experimental-wasm-modules scripts/test.ts",
35
35
  "package": "pnpm build && pnpm pack",
36
36
  "prepublishOnly": "pnpm build",
37
37
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
@@ -1,54 +0,0 @@
1
- import Decimal from "decimal.js";
2
- import { type EquityType, type MarginType } from "./bullet-wasm";
3
- import type { Asset, Market, OrderType, PlaceOrderArgs, Side } from "./types";
4
- import type { BorrowLendMarkets, MarginConfig, OraclePrices, OrderbookL2, PerpPrices, UserAccount } from "./zod-types/rest";
5
- export declare function calculateOrderbookMidpoint(orderbook: OrderbookL2): Decimal | undefined;
6
- export declare function calculateEntryPrice(market: Market, userAccount: UserAccount): Decimal;
7
- export interface MarginCalculationState {
8
- oracle_prices: OraclePrices;
9
- perp_prices: PerpPrices;
10
- margin_config: MarginConfig;
11
- }
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: Asset, userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
18
- export declare function calculateEstimatedLiquidationPrice(market: Market, asset: Asset, 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: Asset, userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Decimal;
22
- export declare function calculateMaxOrderSize(market: Market, 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: Asset, borrowAmount: Decimal, userAccount: UserAccount, marginType: MarginType, MarginCalculationState: MarginCalculationState): {
24
- current: Decimal;
25
- updated: Decimal;
26
- };
27
- export declare function simulateUsedMarginOnOrder(placeOrderArgs: PlaceOrderArgs, userAccount: UserAccount, MarginCalculationState: MarginCalculationState, orderbook: OrderbookL2): {
28
- current: Decimal;
29
- updated: Decimal;
30
- };
31
- export declare function simulateEstimatedLiquidationPriceOnOrder(placeOrderArgs: PlaceOrderArgs, baseAsset: Asset, userAccount: UserAccount, MarginCalculationState: MarginCalculationState, orderbook: OrderbookL2): {
32
- current: Decimal;
33
- updated: Decimal;
34
- };
35
- export declare function calculatePositionsAdditionalMetadata(userAccount: UserAccount, MarginCalculationState: MarginCalculationState): Map<number, {
36
- projected_funding_payment: Decimal;
37
- unrealized_pnl: Decimal;
38
- liquidation_price: Decimal;
39
- liquidation_risk_percentage: Decimal;
40
- max_leverage_to_use: number;
41
- }>;
42
- export declare function calculateBorrowLendMarketAdditionalMetadata(borrowLendMarkets: BorrowLendMarkets, asset: Asset): {
43
- utilisation_rate: Decimal;
44
- current_deposit_rate: Decimal;
45
- current_borrow_rate: Decimal;
46
- };
47
- export declare function calculateAccountSummaryBatch(userAccounts: UserAccount[], MarginCalculationState: MarginCalculationState, useWeightedEquity?: boolean): {
48
- address: string;
49
- unrealized_pnl: Decimal;
50
- equity: Decimal;
51
- available_initial_margin: Decimal;
52
- available_maintenance_margin: Decimal;
53
- leverage: Decimal;
54
- }[];