@bulletxyz/bullet-sdk 0.29.0-rc.1 → 0.31.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,3 +10,4 @@ export * from "./constants";
10
10
  export * from "./error";
11
11
  export { Wallet } from "./wallet";
12
12
  export { Connection } from "./connection";
13
+ export { BulletWasm } from "./bullet-wasm";
@@ -6,6 +6,7 @@ type OrderType = "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "Po
6
6
  type Side = "Bid" | "Ask";
7
7
  export class BulletWasm {
8
8
  free(): void;
9
+ [Symbol.dispose](): void;
9
10
  constructor();
10
11
  static dummy(a: number): number;
11
12
  static convert_token_id_to_bytes(token_id: string): Uint8Array;
@@ -15,9 +16,12 @@ export class BulletWasm {
15
16
  static calculate_account_leverage(user_account: any, margin_calculation_state: any): string;
16
17
  static calculate_available_margin(user_account: any, conservative: boolean, margin_type: MarginType, margin_calculation_state: any): string;
17
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;
18
21
  static calculate_withdrawable_amount_of_asset(user_account: any, asset_id: number, margin_calculation_state: any, asset_registry: any): string;
19
22
  static calculate_estimated_liquidation_price(user_account: any, market_id: number, base_asset_id: number, margin_calculation_state: any): string;
20
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;
21
25
  static calculate_force_cancel_risk_percentage(user_account: any, margin_calculation_state: any): string;
22
26
  /**
23
27
  * Calculates the maximum amount that can be borrowed for a given asset
@@ -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 CreatePositionTpslArgs, type MarkPriceUpdateArgs, type MarketName, type Network, type NewOrderArgs, type OraclePriceUpdateArgs, type TokenId } from "./types";
7
+ import { type Address, type AssetId, type AssetName, type MarkPriceUpdateArgs, type MarketName, type Network, type NewOrderArgs, type OraclePriceUpdateArgs, type TokenId, type TpslPair } from "./types";
8
8
  import type { Wallet } from "./wallet";
9
9
  export interface TransactionOpts {
10
10
  maxPriorityFeeBps: number;
@@ -43,6 +43,15 @@ export declare class Client {
43
43
  getNonce(): Promise<import("@sovereign-sdk/web3").Dedup>;
44
44
  getTokenBalance(tokenId: string): Promise<bigint>;
45
45
  getUserAccount(): Promise<{
46
+ account_variant: {
47
+ Master: number[];
48
+ } | {
49
+ Sub: null;
50
+ } | {
51
+ Vault: null;
52
+ } | {
53
+ ProtocolVault: null;
54
+ };
46
55
  address: string;
47
56
  usdc_ledger: {
48
57
  ledger: {
@@ -69,26 +78,7 @@ export declare class Client {
69
78
  filled_size: Decimal;
70
79
  average_filled_price: Decimal;
71
80
  owner: string;
72
- pending_tpsl: {
73
- tp: {
74
- tpsl_order_id: bigint;
75
- order_price: Decimal;
76
- trigger_price: Decimal;
77
- trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
78
- price_condition: "Mark" | "Oracle" | "LastTrade";
79
- dynamic_size: boolean;
80
- order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
81
- } | null;
82
- sl: {
83
- tpsl_order_id: bigint;
84
- order_price: Decimal;
85
- trigger_price: Decimal;
86
- trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
87
- price_condition: "Mark" | "Oracle" | "LastTrade";
88
- dynamic_size: boolean;
89
- order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
90
- } | null;
91
- };
81
+ reserved_pending_tpsl_pair_ids: string | null;
92
82
  }>;
93
83
  position: {
94
84
  size: Decimal;
@@ -100,19 +90,19 @@ export declare class Client {
100
90
  funding_payments_on_position: Decimal;
101
91
  };
102
92
  user_selected_max_leverage: number;
103
- tpsls: Map<bigint, {
93
+ trigger_orders: Map<bigint, {
104
94
  size: Decimal | null;
105
- tpsl_order_id: bigint;
106
95
  order_price: Decimal;
107
96
  trigger_price: Decimal;
108
- trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
109
97
  price_condition: "Mark" | "Oracle" | "LastTrade";
110
98
  order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
111
99
  side: "Bid" | "Ask";
112
100
  market_id: number;
113
101
  owner: string;
102
+ trigger_order_id: bigint;
103
+ trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
114
104
  last_update_timestamp: bigint;
115
- linked_tpsl_order_id: bigint | null;
105
+ linked_trigger_order_id: bigint | null;
116
106
  }>;
117
107
  }>;
118
108
  spot_ledgers: Map<number, {
@@ -121,70 +111,72 @@ export declare class Client {
121
111
  market_id: number;
122
112
  order_id: bigint;
123
113
  client_order_id: bigint | null;
124
- price: Decimal;
125
- remaining_size: Decimal;
126
- reduce_only: boolean;
127
- filled_size: Decimal;
128
114
  average_filled_price: Decimal;
129
115
  owner: string;
130
- pending_tpsl: {
131
- tp: {
132
- tpsl_order_id: bigint;
133
- order_price: Decimal;
134
- trigger_price: Decimal;
135
- trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
136
- price_condition: "Mark" | "Oracle" | "LastTrade";
137
- dynamic_size: boolean;
138
- order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
139
- } | null;
140
- sl: {
141
- tpsl_order_id: bigint;
142
- order_price: Decimal;
143
- trigger_price: Decimal;
144
- trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
145
- price_condition: "Mark" | "Oracle" | "LastTrade";
146
- dynamic_size: boolean;
147
- order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
148
- } | null;
149
- };
116
+ quote_asset_id: number;
117
+ base_asset_id: number;
118
+ quote_lots: Decimal;
119
+ remaining_base_lots: Decimal;
120
+ filled_base_lots: Decimal;
150
121
  }>;
151
- tpsls: Map<bigint, {
122
+ trigger_orders: Map<bigint, {
152
123
  size: Decimal | null;
153
- tpsl_order_id: bigint;
154
124
  order_price: Decimal;
155
125
  trigger_price: Decimal;
156
- trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
157
126
  price_condition: "Mark" | "Oracle" | "LastTrade";
158
127
  order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
159
128
  side: "Bid" | "Ask";
160
129
  market_id: number;
161
130
  owner: string;
131
+ trigger_order_id: bigint;
132
+ trigger_direction: "GreaterThanOrEqual" | "LessThanOrEqual";
162
133
  last_update_timestamp: bigint;
163
- linked_tpsl_order_id: bigint | null;
134
+ linked_trigger_order_id: bigint | null;
164
135
  }>;
165
136
  }>;
166
137
  fee_tiers: Map<number, "Tier0" | "Tier1" | "Tier2" | "Tier3" | "Tier4">;
138
+ pending_tpsl_pairs: Map<string, {
139
+ tpsl_pair: {
140
+ tp: {
141
+ order_price: Decimal;
142
+ trigger_price: Decimal;
143
+ price_condition: "Mark" | "Oracle" | "LastTrade";
144
+ order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
145
+ } | null;
146
+ sl: {
147
+ order_price: Decimal;
148
+ trigger_price: Decimal;
149
+ price_condition: "Mark" | "Oracle" | "LastTrade";
150
+ order_type: "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
151
+ } | null;
152
+ };
153
+ dynamic_size: boolean;
154
+ }>;
155
+ spot_collateral: Map<number, Decimal>;
167
156
  }>;
168
- submitTransactionSync(runtimeCall: RuntimeCall): void;
169
157
  submitTransaction(runtimeCall: RuntimeCall): Promise<TransactionResult<Transaction<RuntimeCall>>>;
170
158
  transfer(to: Address, amount: bigint, tokenId: TokenId): Promise<TransactionResult<Transaction<RuntimeCall>>>;
171
159
  mint(to: Address, amount: bigint, tokenId: TokenId): Promise<TransactionResult<Transaction<RuntimeCall>>>;
172
160
  deposit(asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
173
161
  withdraw(asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
174
- borrowSpot(asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
175
- placeOrders(market: MarketName, newOrders: NewOrderArgs[], replace?: boolean, useSyncTxSending?: boolean): Promise<void | TransactionResult<Transaction<RuntimeCall>>>;
176
- createPerpPositionTpsl(market: MarketName, tpslOrders: CreatePositionTpslArgs): Promise<TransactionResult<Transaction<RuntimeCall>>>;
177
- amendOrders(market: MarketName, options: AmendOrderOptions[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
178
- cancelTpsls(market: MarketName, tpslOrderIds: bigint[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
179
- cancelOrders(market: MarketName, options: CancelOrderOptions[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
162
+ borrowSpot(asset: AssetName, amount: Decimal, subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
163
+ depositSpotCollateral(asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
164
+ withdrawSpotCollateral(asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
165
+ transferSpotCollateral(direction: "MarginToSpot" | "SpotToMargin", asset: AssetName, amount: Decimal, subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
166
+ placeOrders(market: MarketName, newOrders: NewOrderArgs[], replace?: boolean, subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
167
+ createPerpPositionTpsl(market: MarketName, tpslPair: TpslPair, size?: Decimal, subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
168
+ amendOrders(market: MarketName, options: AmendOrderOptions[], subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
169
+ cancelTriggerOrders(market: MarketName, triggerOrderIds: bigint[], subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
170
+ cancelOrders(market: MarketName, options: CancelOrderOptions[], subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
180
171
  adminCancelOrders(address: Address, market: MarketName, orderId: string): Promise<TransactionResult<Transaction<RuntimeCall>>>;
181
- adminCancelTpsls(address: Address, market: MarketName, tpslOrderId: string): Promise<TransactionResult<Transaction<RuntimeCall>>>;
182
- cancelAllOrders(market: MarketName): Promise<TransactionResult<Transaction<RuntimeCall>>>;
172
+ adminCancelTriggerOrder(address: Address, market: MarketName, triggerOrderId: string): Promise<TransactionResult<Transaction<RuntimeCall>>>;
173
+ cancelAllOrders(market: MarketName, subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
183
174
  updateOraclePrices(pricesToUpdate: OraclePriceUpdateArgs[], publishTimestamp?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
184
175
  updateMarkPrices(pricesToUpdate: MarkPriceUpdateArgs[], publishTimestamp?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
185
176
  updateMaxLeverageForMarket(market: MarketName, maxLeverage: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
186
177
  updatePremiumIndexes(markets: MarketName[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
187
- processTpslBufferForMarket(market: MarketName): Promise<TransactionResult<Transaction<RuntimeCall>>>;
178
+ executePerpActiveTriggerOrders(market: MarketName): Promise<TransactionResult<Transaction<RuntimeCall>>>;
179
+ executeSpotActiveTriggerOrders(market: MarketName): Promise<TransactionResult<Transaction<RuntimeCall>>>;
188
180
  updateFunding(markets: MarketName[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
189
181
  applyFunding(addresses: Address[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
190
182
  forceCancelOrders(address: Address): Promise<TransactionResult<Transaction<RuntimeCall>>>;
@@ -192,8 +184,8 @@ export declare class Client {
192
184
  liquidatePerpPositions(address: Address, positions?: {
193
185
  market: MarketName;
194
186
  size: Decimal;
195
- }[]): Promise<TransactionResult<Transaction<RuntimeCall>>>;
196
- liquidateSpotLiability(address: Address, liabilityAssetId: AssetName, collateralAssetId: AssetName, liabilityAmount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
187
+ }[], subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
188
+ liquidateSpotLiability(address: Address, liabilityAssetId: AssetName, collateralAssetId: AssetName, liabilityAmount: Decimal, subAccountIndex?: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
197
189
  depositToUsdcPnlPool(amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
198
190
  depositToInsuranceFund(amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
199
191
  initAssetMetadata(asset_id: number, assetName: string, tokenId: TokenId | null, decimals: number, withdrawFee: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
@@ -203,5 +195,7 @@ export declare class Client {
203
195
  initBorrowLendPool(assetId: number, optimalUtilisationRate: Decimal, minBorrowRate: Decimal, maxBorrowRate: Decimal, optimalBorrowRate: Decimal, assetWeight: Decimal, initialLiabilityWeight: Decimal, maintenanceLiabilityWeight: Decimal, depositLimit: Decimal, borrowLimit: Decimal, liquidationTotalRewardRatio: Decimal, protocolRewardRatio: Decimal, liabilityLiquidationLimitRatio: Decimal, interestFeeTenthBps: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
204
196
  updateBorrowLendPool(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>>>;
205
197
  updateLeverageTable(market: MarketName, leverageTable: Record<string, number>): Promise<TransactionResult<Transaction<RuntimeCall>>>;
198
+ createSubAccount(index: number): Promise<TransactionResult<Transaction<RuntimeCall>>>;
199
+ transferSubAccount(subAccountIndex: number, toSubAccount: boolean, asset: AssetName, amount: Decimal): Promise<TransactionResult<Transaction<RuntimeCall>>>;
206
200
  }
207
201
  export {};
@@ -4,7 +4,7 @@ import { BaseConnection } from "./connection";
4
4
  import { type Endpoints } from "./constants";
5
5
  import type { Orderbook } from "./orderbook";
6
6
  import type { Address, AssetName, MarketMetadata, MarketName, Network, NewOrderArgs, OrderType, Side } from "./types";
7
- import { type AccountAddresses, type AssetRegistry, type BorrowLendPools, type GlobalParameters, type MarginConfig, type MarketRegistry, type OraclePrices, type Order, type OrderbookL2, type PerpMarket, type PerpPrices, type SpotMarket, type Tpsl, type TpslOrderIdsToExecute, type UsdcInsuranceFund, type UsdcPnlPool, type UserAccount } from "./zod-types/rest";
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";
8
8
  export declare class ExchangeConnection extends BaseConnection {
9
9
  private wsManager?;
10
10
  private assetInfoRegistry?;
@@ -19,7 +19,6 @@ export declare class ExchangeConnection extends BaseConnection {
19
19
  private initializeAssetRegistry;
20
20
  private initializeMarketRegistry;
21
21
  getOrder(orderId: bigint): Promise<Order | null>;
22
- getTpslOrder(tpslOrderId: bigint): Promise<Tpsl | null>;
23
22
  getMarketRegistry(): Promise<MarketRegistry | null>;
24
23
  getAssetRegistry(): Promise<AssetRegistry | null>;
25
24
  private getAssetMapping;
@@ -47,7 +46,7 @@ export declare class ExchangeConnection extends BaseConnection {
47
46
  getSpotMarket(market: MarketName): Promise<SpotMarket>;
48
47
  getSpotMarkets(markets: MarketName[]): Promise<Map<number, SpotMarket>>;
49
48
  getMarginConfig(): Promise<MarginConfig | null>;
50
- getTpslOrderIdsToExecute(market: MarketName): Promise<TpslOrderIdsToExecute | null>;
49
+ getExecutionIds(): Promise<ExecutionIds | null>;
51
50
  getGlobalParameters(): Promise<GlobalParameters | null>;
52
51
  calculateOrderbookMidpoint(orderbook: OrderbookL2): Decimal | undefined;
53
52
  calculateEntryPrice(market: MarketName, userAccount: UserAccount): Decimal;
@@ -76,6 +75,16 @@ export declare class ExchangeConnection extends BaseConnection {
76
75
  perp_prices: PerpPrices;
77
76
  margin_config: MarginConfig;
78
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;
79
88
  calculateWithdrawableAmountOfAsset(asset: AssetName, userAccount: UserAccount, MarginCalculationState: {
80
89
  oracle_prices: OraclePrices;
81
90
  perp_prices: PerpPrices;
@@ -91,6 +100,11 @@ export declare class ExchangeConnection extends BaseConnection {
91
100
  perp_prices: PerpPrices;
92
101
  margin_config: MarginConfig;
93
102
  }): Decimal;
103
+ calculateMarginBalance(userAccount: UserAccount, MarginCalculationState: {
104
+ oracle_prices: OraclePrices;
105
+ perp_prices: PerpPrices;
106
+ margin_config: MarginConfig;
107
+ }): Decimal;
94
108
  calculateForceCancelRiskPercentage(userAccount: UserAccount, MarginCalculationState: {
95
109
  oracle_prices: OraclePrices;
96
110
  perp_prices: PerpPrices;
@@ -157,6 +171,7 @@ export declare class ExchangeConnection extends BaseConnection {
157
171
  available_initial_margin: Decimal;
158
172
  available_maintenance_margin: Decimal;
159
173
  leverage: Decimal;
174
+ account_variant?: string | undefined;
160
175
  }[];
161
176
  private getWebSocketManager;
162
177
  subscribeOrderbook(market: MarketName): AsyncIterable<Orderbook>;
@@ -11,3 +11,4 @@ export * from "./constants";
11
11
  export * from "./wallet/nodeWallet";
12
12
  export * from "./error";
13
13
  export { Connection } from "./connection";
14
+ export { BulletWasm } from "./bullet-wasm";
@@ -6,6 +6,37 @@ type ExactlyOne<T, Keys extends keyof T = keyof T> = {
6
6
  [P in Exclude<Keys, K>]?: never;
7
7
  };
8
8
  }[Keys];
9
+ type TpslOrder = {
10
+ order_price: number;
11
+ trigger_price: number;
12
+ price_condition: string;
13
+ order_type: string;
14
+ };
15
+ type TpslPair = {
16
+ tp: TpslOrder | null;
17
+ sl: TpslOrder | null;
18
+ };
19
+ type PendingTpslPair = {
20
+ tpsl_pair: TpslPair;
21
+ dynamic_size: boolean;
22
+ };
23
+ type NewOrderArgs = {
24
+ price: number;
25
+ size: number;
26
+ side: string;
27
+ order_type: string;
28
+ reduce_only: boolean;
29
+ client_order_id: string | null;
30
+ pending_tpsl_pair: PendingTpslPair | null;
31
+ };
32
+ type CancelOrderArgs = {
33
+ order_id: string | null;
34
+ client_order_id: string | null;
35
+ };
36
+ type AmendOrderArgs = {
37
+ cancel: CancelOrderArgs;
38
+ place: NewOrderArgs;
39
+ };
9
40
  type BankCallMessage = {
10
41
  transfer: {
11
42
  to: Address;
@@ -84,18 +115,6 @@ type InterchainGasPaymasterCallMessage = {
84
115
  beneficiary?: string;
85
116
  };
86
117
  };
87
- type TriggerOrderArgs = {
88
- order_price: number;
89
- trigger_price: number;
90
- trigger_direction: string;
91
- price_condition: string;
92
- order_type: string;
93
- };
94
- type PendingTriggerOrderArgs = {
95
- pending_tp: TriggerOrderArgs | null;
96
- pending_sl: TriggerOrderArgs | null;
97
- dynamic_size: boolean;
98
- };
99
118
  type ExchangeCallMessage = {
100
119
  set_value: number;
101
120
  deposit: {
@@ -115,110 +134,69 @@ type ExchangeCallMessage = {
115
134
  asset_id: AssetId;
116
135
  amount: number;
117
136
  };
137
+ sub_account_index: number | null;
118
138
  };
119
139
  place_perp_orders: {
120
140
  market_id: MarketId;
121
- args: {
122
- price: number;
123
- size: number;
124
- side: string;
125
- order_type: string;
126
- reduce_only: boolean;
127
- client_order_id: string | null;
128
- tpsl: PendingTriggerOrderArgs | null;
129
- }[];
141
+ args: NewOrderArgs[];
130
142
  replace: boolean;
143
+ sub_account_index: number | null;
131
144
  };
132
145
  place_spot_orders: {
133
146
  market_id: MarketId;
134
- args: {
135
- price: number;
136
- size: number;
137
- side: string;
138
- order_type: string;
139
- reduce_only: boolean;
140
- client_order_id: string | null;
141
- tpsl: PendingTriggerOrderArgs | null;
142
- }[];
147
+ args: NewOrderArgs[];
143
148
  replace: boolean;
149
+ sub_account_index: number | null;
144
150
  };
145
151
  create_perp_position_tpsl: {
146
152
  market_id: MarketId;
147
- args: {
148
- tp: TriggerOrderArgs | null;
149
- sl: TriggerOrderArgs | null;
150
- size: number | null;
151
- };
153
+ tpsl_pair: TpslPair;
154
+ size: number | null;
155
+ sub_account_index: number | null;
152
156
  };
153
157
  amend_perp_orders: {
154
158
  market_id: MarketId;
155
- args: {
156
- cancel: {
157
- order_id: string | null;
158
- client_order_id: string | null;
159
- };
160
- place: {
161
- price: number;
162
- size: number;
163
- side: string;
164
- order_type: string;
165
- reduce_only: boolean;
166
- client_order_id: string | null;
167
- tpsl: PendingTriggerOrderArgs | null;
168
- };
169
- }[];
159
+ args: AmendOrderArgs[];
160
+ sub_account_index: number | null;
170
161
  };
171
162
  amend_spot_orders: {
172
163
  market_id: MarketId;
173
- args: {
174
- cancel: {
175
- order_id: string | null;
176
- client_order_id: string | null;
177
- };
178
- place: {
179
- price: number;
180
- size: number;
181
- side: string;
182
- order_type: string;
183
- reduce_only: boolean;
184
- client_order_id: string | null;
185
- tpsl: PendingTriggerOrderArgs | null;
186
- };
187
- }[];
164
+ args: AmendOrderArgs[];
165
+ sub_account_index: number | null;
188
166
  };
189
- cancel_perp_tpsls: {
167
+ cancel_perp_trigger_orders: {
190
168
  market_id: MarketId;
191
- tpsl_order_ids: string[];
169
+ trigger_order_ids: string[];
170
+ sub_account_index: number | null;
192
171
  };
193
- cancel_spot_tpsls: {
172
+ cancel_spot_trigger_orders: {
194
173
  market_id: MarketId;
195
- tpsl_order_ids: string[];
174
+ trigger_order_ids: string[];
175
+ sub_account_index: number | null;
196
176
  };
197
177
  cancel_perp_orders: {
198
178
  market_id: MarketId;
199
- args: {
200
- order_id: string | null;
201
- client_order_id: string | null;
202
- }[];
179
+ args: CancelOrderArgs[];
180
+ sub_account_index: number | null;
203
181
  };
204
182
  cancel_spot_orders: {
205
183
  market_id: MarketId;
206
- args: {
207
- order_id: string | null;
208
- client_order_id: string | null;
209
- }[];
184
+ args: CancelOrderArgs[];
185
+ sub_account_index: number | null;
210
186
  };
211
187
  admin_cancel_orders: {
212
188
  args: [Address, MarketId, string][];
213
189
  };
214
- admin_cancel_tpsls: {
190
+ admin_cancel_trigger_orders: {
215
191
  args: [Address, MarketId, string][];
216
192
  };
217
193
  cancel_all_perp_orders: {
218
194
  market_id: MarketId;
195
+ sub_account_index: number | null;
219
196
  };
220
197
  cancel_all_spot_orders: {
221
198
  market_id: MarketId;
199
+ sub_account_index: number | null;
222
200
  };
223
201
  update_oracle_prices: {
224
202
  prices_to_update: {
@@ -242,10 +220,10 @@ type ExchangeCallMessage = {
242
220
  update_premium_indexes: {
243
221
  market_ids: MarketId[];
244
222
  };
245
- process_perp_tpsl_buffer: {
223
+ execute_perp_active_trigger_orders: {
246
224
  market_id: MarketId;
247
225
  };
248
- process_spot_tpsl_buffer: {
226
+ execute_spot_active_trigger_orders: {
249
227
  market_id: MarketId;
250
228
  };
251
229
  update_funding: {
@@ -266,12 +244,14 @@ type ExchangeCallMessage = {
266
244
  market_id: MarketId;
267
245
  size: number;
268
246
  }[] | null;
247
+ sub_account_index: number | null;
269
248
  };
270
249
  liquidate_spot_liability: {
271
250
  liquidatee_address: Address;
272
251
  liability_asset_id: AssetId;
273
252
  collateral_asset_id: AssetId;
274
253
  liability_amount: number;
254
+ sub_account_index: number | null;
275
255
  };
276
256
  deposit_to_usdc_pnl_pool: {
277
257
  usdc_amount: number;
@@ -377,6 +357,37 @@ type ExchangeCallMessage = {
377
357
  market_id: MarketId;
378
358
  args: Record<string, number>;
379
359
  };
360
+ deposit_spot_collateral: {
361
+ args: {
362
+ asset_id: AssetId;
363
+ amount: number;
364
+ };
365
+ };
366
+ withdraw_spot_collateral: {
367
+ args: {
368
+ asset_id: AssetId;
369
+ amount: number;
370
+ };
371
+ };
372
+ transfer_spot_collateral: {
373
+ direction: "MarginToSpot" | "SpotToMargin";
374
+ args: {
375
+ asset_id: AssetId;
376
+ amount: number;
377
+ };
378
+ sub_account_index: number | null;
379
+ };
380
+ create_sub_account: {
381
+ index: number;
382
+ };
383
+ transfer_sub_account: {
384
+ sub_account_index: number;
385
+ to_sub_account: boolean;
386
+ asset_operation_args: {
387
+ asset_id: AssetId;
388
+ amount: number;
389
+ };
390
+ };
380
391
  };
381
392
  export type RuntimeCall = ExactlyOne<{
382
393
  exchange: ExactlyOne<ExchangeCallMessage>;
@@ -12,7 +12,7 @@ export type ClientOrderId = bigint;
12
12
  export type MarketKind = "Perp" | "Spot";
13
13
  export type Side = "Bid" | "Ask";
14
14
  export type TriggerDirection = "GreaterThanOrEqual" | "LessThanOrEqual";
15
- export type TpslPriceCondition = "Mark" | "Oracle" | "LastTrade";
15
+ export type TriggerPriceCondition = "Mark" | "Oracle" | "LastTrade";
16
16
  export type OrderType = "Limit" | "PostOnly" | "FillOrKill" | "ImmediateOrCancel" | "PostOnlySlide" | "PostOnlyFront";
17
17
  export type MarginType = "Initial" | "Maintenance";
18
18
  export type EquityType = "Unweighted" | "WeightedInitial" | "WeightedMaintenance";
@@ -31,7 +31,14 @@ export type NewOrderArgs = {
31
31
  orderType: OrderType;
32
32
  reduceOnly: boolean;
33
33
  clientOrderId?: ClientOrderId;
34
- tpsl?: PendingTriggerOrderArgs;
34
+ pendingTpslPair?: PendingTpslPair;
35
+ };
36
+ export type AmendOrderArgs = {
37
+ cancel: {
38
+ order_id: string | null;
39
+ client_order_id: string | null;
40
+ };
41
+ place: NewOrderArgs;
35
42
  };
36
43
  export type OraclePriceUpdateArgs = {
37
44
  asset: AssetName;
@@ -42,22 +49,19 @@ export type MarkPriceUpdateArgs = {
42
49
  medianCexPrice: Decimal;
43
50
  diffEma: Decimal;
44
51
  };
45
- export type TriggerOrderArgs = {
52
+ export type Tpsl = {
46
53
  orderPrice: Decimal;
47
54
  triggerPrice: Decimal;
48
- triggerDirection: TriggerDirection;
49
- priceCondition: TpslPriceCondition;
55
+ priceCondition: TriggerPriceCondition;
50
56
  orderType: OrderType;
51
57
  };
52
- export type PendingTriggerOrderArgs = {
53
- pendingTp?: TriggerOrderArgs;
54
- pendingSl?: TriggerOrderArgs;
55
- dynamicSize: boolean;
58
+ export type TpslPair = {
59
+ tp?: Tpsl;
60
+ sl?: Tpsl;
56
61
  };
57
- export type CreatePositionTpslArgs = {
58
- tp?: TriggerOrderArgs;
59
- sl?: TriggerOrderArgs;
60
- size?: Decimal;
62
+ export type PendingTpslPair = {
63
+ tpslPair: TpslPair;
64
+ dynamicSize: boolean;
61
65
  };
62
66
  export type MarketMetadata = {
63
67
  id: number;
@@ -70,6 +74,17 @@ export declare class BulletError extends Error {
70
74
  code: string;
71
75
  shortMessage: string;
72
76
  verboseMessage: string;
73
- constructor(code: string, shortMessage: string, verboseMessage: string, originalError?: Error | undefined);
74
- static fromModuleError(error: unknown): Error;
77
+ httpStatus?: number;
78
+ responseData?: any;
79
+ constructor(code: string, shortMessage: string, verboseMessage: string, originalError?: Error | undefined, httpStatus?: number, responseData?: any);
80
+ static fromModuleError(error: unknown): BulletError;
81
+ toJSON(): {
82
+ name: string;
83
+ code: string;
84
+ message: string;
85
+ shortMessage: string;
86
+ verboseMessage: string;
87
+ httpStatus: number | undefined;
88
+ responseData: any;
89
+ };
75
90
  }
@@ -1,6 +1,7 @@
1
1
  import Decimal from "decimal.js";
2
2
  import { z } from "zod";
3
3
  export declare const I64Schema: z.ZodBigInt;
4
+ export declare const U8Schema: z.ZodNumber;
4
5
  export declare const U16Schema: z.ZodNumber;
5
6
  export declare const U32Schema: z.ZodNumber;
6
7
  export declare const U64Schema: z.ZodBigInt;
@@ -10,8 +11,9 @@ export declare const Base58Address: z.ZodString;
10
11
  export declare const AssetId: z.ZodNumber;
11
12
  export declare const MarketId: z.ZodNumber;
12
13
  export declare const OrderId: z.ZodBigInt;
14
+ export declare const TradeId: z.ZodBigInt;
13
15
  export declare const ClientOrderId: z.ZodBigInt;
14
- export declare const TpslOrderId: z.ZodBigInt;
16
+ export declare const TriggerOrderId: z.ZodBigInt;
15
17
  export declare const Amount: z.ZodBigInt;
16
18
  export declare const UnixTimestampMillis: z.ZodBigInt;
17
19
  type MapKeySchema = z.ZodString | z.ZodNumber | z.ZodUnknown | z.ZodBigInt;