@bulletxyz/bullet-sdk 0.27.1-rc.0 → 0.27.2-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.
@@ -3315,6 +3315,12 @@ var NETWORKS = {
3315
3315
  ws: "wss://ws.mainnet.bullet.xyz/ws"
3316
3316
  }
3317
3317
  };
3318
+ var CHAIN_IDS = {
3319
+ Localnet: 4321,
3320
+ Staging: 4323,
3321
+ Testnet: 4322,
3322
+ Mainnet: 4321
3323
+ };
3318
3324
  var GLOBAL_DEFAULT_MAX_LEVERAGE = 1e3;
3319
3325
 
3320
3326
  // src/utils.ts
@@ -7769,38 +7775,7 @@ var Schemas = {
7769
7775
  })
7770
7776
  )
7771
7777
  }),
7772
- last_trade_price: DecimalSchema,
7773
- taker_fees_tenth_bps: z.array(z.number()),
7774
- maker_fees_tenth_bps: z.array(z.number())
7775
- }),
7776
- SpotMarket: z.object({
7777
- market_id: MarketId,
7778
- is_active: z.boolean(),
7779
- base_asset_id: AssetId,
7780
- quote_asset_id: AssetId,
7781
- base_min_lot_size: DecimalSchema,
7782
- quote_min_lot_size: DecimalSchema,
7783
- max_orders_per_side: U16Schema,
7784
- orderbook: z.object({
7785
- market_id: MarketId,
7786
- bids: createJsonMap(
7787
- z.string(),
7788
- z.object({
7789
- order_ids: z.array(OrderId),
7790
- total_size: DecimalSchema
7791
- })
7792
- ),
7793
- asks: createJsonMap(
7794
- z.string(),
7795
- z.object({
7796
- order_ids: z.array(OrderId),
7797
- total_size: DecimalSchema
7798
- })
7799
- )
7800
- }),
7801
- last_trade_price: DecimalSchema,
7802
- taker_fees_tenth_bps: z.array(z.number()),
7803
- maker_fees_tenth_bps: z.array(z.number())
7778
+ last_trade_price: DecimalSchema
7804
7779
  }),
7805
7780
  MarginConfig: z.object({
7806
7781
  perp_liquidation_config: PerpLiquidationConfig,
@@ -7900,18 +7875,6 @@ var ResponseSchemas = {
7900
7875
  not_found: z.array(MarketId)
7901
7876
  })
7902
7877
  ),
7903
- SpotMarket: createBaseResponse(
7904
- z.object({
7905
- market_id: MarketId,
7906
- market: Schemas.SpotMarket
7907
- })
7908
- ),
7909
- SpotMarketBulk: createBaseResponse(
7910
- z.object({
7911
- found: createJsonMap(MarketId, Schemas.SpotMarket),
7912
- not_found: z.array(MarketId)
7913
- })
7914
- ),
7915
7878
  MarginConfig: StateResponseSchemas.StateValue(Schemas.MarginConfig),
7916
7879
  AccountAddresses: createBaseResponse(Schemas.AccountAddresses)
7917
7880
  };
@@ -8313,7 +8276,6 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8313
8276
  __publicField(this, "assetRegistry");
8314
8277
  __publicField(this, "assetRegistryReverse");
8315
8278
  __publicField(this, "marketRegistry");
8316
- // ID and type
8317
8279
  __publicField(this, "marketRegistryReverse");
8318
8280
  if (endpoints.ws) {
8319
8281
  this.wsManager = new WebSocketManager(endpoints.ws);
@@ -8364,12 +8326,7 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8364
8326
  this.marketRegistryReverse = /* @__PURE__ */ new Map();
8365
8327
  for (const info of rawMarketRegistry.metas.values()) {
8366
8328
  if (info && typeof info.name === "string") {
8367
- this.marketRegistry.set(info.name, {
8368
- id: info.id,
8369
- kind: info.kind,
8370
- baseAssetId: info.base_asset_id,
8371
- name: info.name
8372
- });
8329
+ this.marketRegistry.set(info.name, info.id);
8373
8330
  this.marketRegistryReverse.set(info.id, info.name);
8374
8331
  }
8375
8332
  }
@@ -8429,9 +8386,6 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8429
8386
  return assetName;
8430
8387
  }
8431
8388
  getMarketId(market) {
8432
- return this.getMarketMeta(market).id;
8433
- }
8434
- getMarketMeta(market) {
8435
8389
  const marketRegistry = this.getMarketMapping();
8436
8390
  const marketId = marketRegistry.get(market);
8437
8391
  if (marketId === void 0) {
@@ -8541,24 +8495,6 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8541
8495
  const parsed = ResponseSchemas.PerpMarketBulk.parse(response);
8542
8496
  return parsed.found;
8543
8497
  }
8544
- async getSpotMarket(market) {
8545
- const marketId = this.getMarketId(market);
8546
- const path = `/modules/exchange/api/v1/spot-market/${marketId}`;
8547
- const response = await this.fetchApiResource(path);
8548
- const parsed = ResponseSchemas.SpotMarket.parse(response);
8549
- return parsed.market;
8550
- }
8551
- async getSpotMarkets(markets) {
8552
- const marketIds = markets.map((market) => {
8553
- return this.getMarketId(market);
8554
- });
8555
- const path = "/modules/exchange/api/v1/spot-market/bulk";
8556
- const response = await this.fetchBulkApiResource(path, {
8557
- market_ids: marketIds
8558
- });
8559
- const parsed = ResponseSchemas.SpotMarketBulk.parse(response);
8560
- return parsed.found;
8561
- }
8562
8498
  async getMarginConfig() {
8563
8499
  const path = "/modules/exchange/state/margin-config";
8564
8500
  const response = await this.fetchApiResource(path);
@@ -9411,8 +9347,7 @@ onEvent_fn = async function(event, filter) {
9411
9347
  var DEFAULT_TRANSACTION_OPTS = {
9412
9348
  maxPriorityFeeBps: 0,
9413
9349
  maxFee: "1000000000",
9414
- gasLimit: null,
9415
- chainId: 4321
9350
+ gasLimit: null
9416
9351
  };
9417
9352
  var Client = class _Client {
9418
9353
  constructor(endpoints, exchange, wallet, rollup) {
@@ -9431,7 +9366,7 @@ var Client = class _Client {
9431
9366
  this.address = wallet.address;
9432
9367
  }
9433
9368
  // Static convenience constructors
9434
- static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
9369
+ static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS, chainId = 4321) {
9435
9370
  const rollup = await createStandardRollup({
9436
9371
  url: endpoints.rest,
9437
9372
  getSerializer: (schema) => new WasmSerializer(schema),
@@ -9440,7 +9375,7 @@ var Client = class _Client {
9440
9375
  max_priority_fee_bips: txOpts.maxPriorityFeeBps,
9441
9376
  max_fee: txOpts.maxFee,
9442
9377
  gas_limit: txOpts.gasLimit,
9443
- chain_id: txOpts.chainId
9378
+ chain_id: chainId
9444
9379
  }
9445
9380
  }
9446
9381
  });
@@ -9453,7 +9388,12 @@ var Client = class _Client {
9453
9388
  if (!isNetwork(network)) {
9454
9389
  throw new Error(`Invalid network: ${network}`);
9455
9390
  }
9456
- return await _Client.fromEndpoints(NETWORKS[network], wallet, txOpts);
9391
+ return await _Client.fromEndpoints(
9392
+ NETWORKS[network],
9393
+ wallet,
9394
+ txOpts,
9395
+ CHAIN_IDS[network]
9396
+ );
9457
9397
  }
9458
9398
  static async fromRestUrl(restUrl, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
9459
9399
  return await _Client.fromEndpoints({ rest: restUrl }, wallet, txOpts);
@@ -9563,58 +9503,51 @@ var Client = class _Client {
9563
9503
  });
9564
9504
  }
9565
9505
  async placeOrder(placeOrderArgs) {
9566
- const marketMeta = this.exchange.getMarketMeta(placeOrderArgs.market);
9567
- const marketId = marketMeta.id;
9568
- const innerArgsObject = {
9569
- args: {
9570
- market_id: marketId,
9571
- price: BulletWasm.convert_rust_decimal_to_json(
9572
- placeOrderArgs.price.toFixed()
9573
- ),
9574
- size: BulletWasm.convert_rust_decimal_to_json(
9575
- placeOrderArgs.size.toFixed()
9576
- ),
9577
- side: placeOrderArgs.side,
9578
- order_type: placeOrderArgs.orderType,
9579
- reduce_only: placeOrderArgs.reduceOnly,
9580
- client_order_id: placeOrderArgs.clientOrderId ? placeOrderArgs.clientOrderId.toString() : null,
9581
- tpsl: placeOrderArgs.tpsl ? {
9582
- pending_tp: placeOrderArgs.tpsl.pendingTp ? {
9583
- order_price: BulletWasm.convert_rust_decimal_to_json(
9584
- placeOrderArgs.tpsl.pendingTp.orderPrice.toFixed()
9585
- ),
9586
- trigger_price: BulletWasm.convert_rust_decimal_to_json(
9587
- placeOrderArgs.tpsl.pendingTp.triggerPrice.toFixed()
9588
- ),
9589
- trigger_direction: placeOrderArgs.tpsl.pendingTp.triggerDirection,
9590
- price_condition: placeOrderArgs.tpsl.pendingTp.priceCondition,
9591
- order_type: placeOrderArgs.tpsl.pendingTp.orderType
9592
- } : null,
9593
- pending_sl: placeOrderArgs.tpsl.pendingSl ? {
9594
- order_price: BulletWasm.convert_rust_decimal_to_json(
9595
- placeOrderArgs.tpsl.pendingSl.orderPrice.toFixed()
9506
+ const marketId = this.exchange.getMarketId(placeOrderArgs.market);
9507
+ return await this.submitTransaction({
9508
+ exchange: {
9509
+ place_order: {
9510
+ args: {
9511
+ market_id: marketId,
9512
+ price: BulletWasm.convert_rust_decimal_to_json(
9513
+ placeOrderArgs.price.toFixed()
9596
9514
  ),
9597
- trigger_price: BulletWasm.convert_rust_decimal_to_json(
9598
- placeOrderArgs.tpsl.pendingSl.triggerPrice.toFixed()
9515
+ size: BulletWasm.convert_rust_decimal_to_json(
9516
+ placeOrderArgs.size.toFixed()
9599
9517
  ),
9600
- trigger_direction: placeOrderArgs.tpsl.pendingSl.triggerDirection,
9601
- price_condition: placeOrderArgs.tpsl.pendingSl.priceCondition,
9602
- order_type: placeOrderArgs.tpsl.pendingSl.orderType
9603
- } : null,
9604
- dynamic_size: placeOrderArgs.tpsl.dynamicSize
9605
- } : null
9606
- }
9607
- };
9608
- const outerArgsObject = marketMeta.kind === "Spot" ? {
9609
- exchange: {
9610
- place_spot_order: innerArgsObject
9611
- }
9612
- } : {
9613
- exchange: {
9614
- place_order: innerArgsObject
9518
+ side: placeOrderArgs.side,
9519
+ order_type: placeOrderArgs.orderType,
9520
+ reduce_only: placeOrderArgs.reduceOnly,
9521
+ client_order_id: placeOrderArgs.clientOrderId ? placeOrderArgs.clientOrderId.toString() : null,
9522
+ tpsl: placeOrderArgs.tpsl ? {
9523
+ pending_tp: placeOrderArgs.tpsl.pendingTp ? {
9524
+ order_price: BulletWasm.convert_rust_decimal_to_json(
9525
+ placeOrderArgs.tpsl.pendingTp.orderPrice.toFixed()
9526
+ ),
9527
+ trigger_price: BulletWasm.convert_rust_decimal_to_json(
9528
+ placeOrderArgs.tpsl.pendingTp.triggerPrice.toFixed()
9529
+ ),
9530
+ trigger_direction: placeOrderArgs.tpsl.pendingTp.triggerDirection,
9531
+ price_condition: placeOrderArgs.tpsl.pendingTp.priceCondition,
9532
+ order_type: placeOrderArgs.tpsl.pendingTp.orderType
9533
+ } : null,
9534
+ pending_sl: placeOrderArgs.tpsl.pendingSl ? {
9535
+ order_price: BulletWasm.convert_rust_decimal_to_json(
9536
+ placeOrderArgs.tpsl.pendingSl.orderPrice.toFixed()
9537
+ ),
9538
+ trigger_price: BulletWasm.convert_rust_decimal_to_json(
9539
+ placeOrderArgs.tpsl.pendingSl.triggerPrice.toFixed()
9540
+ ),
9541
+ trigger_direction: placeOrderArgs.tpsl.pendingSl.triggerDirection,
9542
+ price_condition: placeOrderArgs.tpsl.pendingSl.priceCondition,
9543
+ order_type: placeOrderArgs.tpsl.pendingSl.orderType
9544
+ } : null,
9545
+ dynamic_size: placeOrderArgs.tpsl.dynamicSize
9546
+ } : null
9547
+ }
9548
+ }
9615
9549
  }
9616
- };
9617
- return await this.submitTransaction(outerArgsObject);
9550
+ });
9618
9551
  }
9619
9552
  async createPositionTpsl(market, tpslOrders) {
9620
9553
  const marketId = this.exchange.getMarketId(market);
@@ -10167,6 +10100,7 @@ export {
10167
10100
  ApiError,
10168
10101
  BaseResponseSchemas,
10169
10102
  BulletError,
10103
+ CHAIN_IDS,
10170
10104
  Client,
10171
10105
  Connection,
10172
10106
  ExchangeConnection,