@bulletxyz/bullet-sdk 0.27.2-rc.3 → 0.27.2

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,12 +3315,6 @@ 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
- };
3324
3318
  var GLOBAL_DEFAULT_MAX_LEVERAGE = 1e3;
3325
3319
 
3326
3320
  // src/utils.ts
@@ -7527,6 +7521,7 @@ var ORDER_TYPES = [
7527
7521
  ];
7528
7522
  var createBaseResponse = (schema) => schema;
7529
7523
  var StateResponseSchemas = {
7524
+ RollupSchema: (valueSchema) => createBaseResponse(z.object({ schema: valueSchema })),
7530
7525
  StateValue: (valueSchema) => createBaseResponse(z.object({ value: valueSchema.nullable() })),
7531
7526
  CustomRouteValue: (valueSchema) => createBaseResponse(valueSchema),
7532
7527
  StateMapElement: (keySchema, valueSchema) => createBaseResponse(
@@ -7775,7 +7770,38 @@ var Schemas = {
7775
7770
  })
7776
7771
  )
7777
7772
  }),
7778
- last_trade_price: DecimalSchema
7773
+ last_trade_price: DecimalSchema,
7774
+ taker_fees_tenth_bps: z.array(z.number()),
7775
+ maker_fees_tenth_bps: z.array(z.number())
7776
+ }),
7777
+ SpotMarket: z.object({
7778
+ market_id: MarketId,
7779
+ is_active: z.boolean(),
7780
+ base_asset_id: AssetId,
7781
+ quote_asset_id: AssetId,
7782
+ base_min_lot_size: DecimalSchema,
7783
+ quote_min_lot_size: DecimalSchema,
7784
+ max_orders_per_side: U16Schema,
7785
+ orderbook: z.object({
7786
+ market_id: MarketId,
7787
+ bids: createJsonMap(
7788
+ z.string(),
7789
+ z.object({
7790
+ order_ids: z.array(OrderId),
7791
+ total_size: DecimalSchema
7792
+ })
7793
+ ),
7794
+ asks: createJsonMap(
7795
+ z.string(),
7796
+ z.object({
7797
+ order_ids: z.array(OrderId),
7798
+ total_size: DecimalSchema
7799
+ })
7800
+ )
7801
+ }),
7802
+ last_trade_price: DecimalSchema,
7803
+ taker_fees_tenth_bps: z.array(z.number()),
7804
+ maker_fees_tenth_bps: z.array(z.number())
7779
7805
  }),
7780
7806
  MarginConfig: z.object({
7781
7807
  perp_liquidation_config: PerpLiquidationConfig,
@@ -7875,8 +7901,28 @@ var ResponseSchemas = {
7875
7901
  not_found: z.array(MarketId)
7876
7902
  })
7877
7903
  ),
7904
+ SpotMarket: createBaseResponse(
7905
+ z.object({
7906
+ market_id: MarketId,
7907
+ market: Schemas.SpotMarket
7908
+ })
7909
+ ),
7910
+ SpotMarketBulk: createBaseResponse(
7911
+ z.object({
7912
+ found: createJsonMap(MarketId, Schemas.SpotMarket),
7913
+ not_found: z.array(MarketId)
7914
+ })
7915
+ ),
7878
7916
  MarginConfig: StateResponseSchemas.StateValue(Schemas.MarginConfig),
7879
- AccountAddresses: createBaseResponse(Schemas.AccountAddresses)
7917
+ AccountAddresses: createBaseResponse(Schemas.AccountAddresses),
7918
+ ChainData: StateResponseSchemas.RollupSchema(
7919
+ z.object({
7920
+ chain_data: z.object({
7921
+ chain_id: z.number(),
7922
+ chain_name: z.string()
7923
+ })
7924
+ })
7925
+ )
7880
7926
  };
7881
7927
 
7882
7928
  // src/connection.ts
@@ -8276,6 +8322,7 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8276
8322
  __publicField(this, "assetRegistry");
8277
8323
  __publicField(this, "assetRegistryReverse");
8278
8324
  __publicField(this, "marketRegistry");
8325
+ // ID and type
8279
8326
  __publicField(this, "marketRegistryReverse");
8280
8327
  if (endpoints.ws) {
8281
8328
  this.wsManager = new WebSocketManager(endpoints.ws);
@@ -8326,7 +8373,12 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8326
8373
  this.marketRegistryReverse = /* @__PURE__ */ new Map();
8327
8374
  for (const info of rawMarketRegistry.metas.values()) {
8328
8375
  if (info && typeof info.name === "string") {
8329
- this.marketRegistry.set(info.name, info.id);
8376
+ this.marketRegistry.set(info.name, {
8377
+ id: info.id,
8378
+ kind: info.kind,
8379
+ baseAssetId: info.base_asset_id,
8380
+ name: info.name
8381
+ });
8330
8382
  this.marketRegistryReverse.set(info.id, info.name);
8331
8383
  }
8332
8384
  }
@@ -8386,6 +8438,9 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8386
8438
  return assetName;
8387
8439
  }
8388
8440
  getMarketId(market) {
8441
+ return this.getMarketMeta(market).id;
8442
+ }
8443
+ getMarketMeta(market) {
8389
8444
  const marketRegistry = this.getMarketMapping();
8390
8445
  const marketId = marketRegistry.get(market);
8391
8446
  if (marketId === void 0) {
@@ -8424,6 +8479,12 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8424
8479
  const parsed = ResponseSchemas.OrderbookL2Bulk.parse(response);
8425
8480
  return parsed.found;
8426
8481
  }
8482
+ async getChainId() {
8483
+ const path = "/rollup/schema/";
8484
+ const response = await this.fetchApiResource(path);
8485
+ const parsed = ResponseSchemas.ChainData.parse(response);
8486
+ return parsed.schema.chain_data.chain_id;
8487
+ }
8427
8488
  async getUserAccountAddresses(offset, limit) {
8428
8489
  const path = "/modules/exchange/api/v1/account/addresses";
8429
8490
  const response = await this.fetchApiResource(path, {
@@ -8495,6 +8556,24 @@ var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
8495
8556
  const parsed = ResponseSchemas.PerpMarketBulk.parse(response);
8496
8557
  return parsed.found;
8497
8558
  }
8559
+ async getSpotMarket(market) {
8560
+ const marketId = this.getMarketId(market);
8561
+ const path = `/modules/exchange/api/v1/spot-market/${marketId}`;
8562
+ const response = await this.fetchApiResource(path);
8563
+ const parsed = ResponseSchemas.SpotMarket.parse(response);
8564
+ return parsed.market;
8565
+ }
8566
+ async getSpotMarkets(markets) {
8567
+ const marketIds = markets.map((market) => {
8568
+ return this.getMarketId(market);
8569
+ });
8570
+ const path = "/modules/exchange/api/v1/spot-market/bulk";
8571
+ const response = await this.fetchBulkApiResource(path, {
8572
+ market_ids: marketIds
8573
+ });
8574
+ const parsed = ResponseSchemas.SpotMarketBulk.parse(response);
8575
+ return parsed.found;
8576
+ }
8498
8577
  async getMarginConfig() {
8499
8578
  const path = "/modules/exchange/state/margin-config";
8500
8579
  const response = await this.fetchApiResource(path);
@@ -9352,7 +9431,12 @@ var Client = class _Client {
9352
9431
  this.address = wallet.address;
9353
9432
  }
9354
9433
  // Static convenience constructors
9355
- static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS, chainId = 4321) {
9434
+ static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
9435
+ validateEndpoints(endpoints);
9436
+ console.debug("Endpoints:", endpoints);
9437
+ const exchange = await ExchangeConnection.fromEndpoints(endpoints);
9438
+ const chainId = await exchange.getChainId();
9439
+ console.debug("Chain ID:", chainId);
9356
9440
  const rollup = await createStandardRollup({
9357
9441
  url: endpoints.rest,
9358
9442
  getSerializer: (schema) => new WasmSerializer(schema),
@@ -9365,29 +9449,16 @@ var Client = class _Client {
9365
9449
  }
9366
9450
  }
9367
9451
  });
9368
- validateEndpoints(endpoints);
9369
- console.debug("Endpoints:", endpoints);
9370
- const exchange = await ExchangeConnection.fromEndpoints(endpoints);
9371
9452
  return new _Client(endpoints, exchange, wallet, rollup);
9372
9453
  }
9373
9454
  static async fromNetwork(network, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
9374
9455
  if (!isNetwork(network)) {
9375
9456
  throw new Error(`Invalid network: ${network}`);
9376
9457
  }
9377
- return await _Client.fromEndpoints(
9378
- NETWORKS[network],
9379
- wallet,
9380
- txOpts,
9381
- CHAIN_IDS[network]
9382
- );
9458
+ return await _Client.fromEndpoints(NETWORKS[network], wallet, txOpts);
9383
9459
  }
9384
- static async fromRestUrl(restUrl, wallet, network, txOpts = DEFAULT_TRANSACTION_OPTS) {
9385
- return await _Client.fromEndpoints(
9386
- { rest: restUrl },
9387
- wallet,
9388
- txOpts,
9389
- CHAIN_IDS[network]
9390
- );
9460
+ static async fromRestUrl(restUrl, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
9461
+ return await _Client.fromEndpoints({ rest: restUrl }, wallet, txOpts);
9391
9462
  }
9392
9463
  setGenerationOverride(generation) {
9393
9464
  this.generationOverride = generation;
@@ -9494,51 +9565,58 @@ var Client = class _Client {
9494
9565
  });
9495
9566
  }
9496
9567
  async placeOrder(placeOrderArgs) {
9497
- const marketId = this.exchange.getMarketId(placeOrderArgs.market);
9498
- return await this.submitTransaction({
9499
- exchange: {
9500
- place_order: {
9501
- args: {
9502
- market_id: marketId,
9503
- price: BulletWasm.convert_rust_decimal_to_json(
9504
- placeOrderArgs.price.toFixed()
9568
+ const marketMeta = this.exchange.getMarketMeta(placeOrderArgs.market);
9569
+ const marketId = marketMeta.id;
9570
+ const innerArgsObject = {
9571
+ args: {
9572
+ market_id: marketId,
9573
+ price: BulletWasm.convert_rust_decimal_to_json(
9574
+ placeOrderArgs.price.toFixed()
9575
+ ),
9576
+ size: BulletWasm.convert_rust_decimal_to_json(
9577
+ placeOrderArgs.size.toFixed()
9578
+ ),
9579
+ side: placeOrderArgs.side,
9580
+ order_type: placeOrderArgs.orderType,
9581
+ reduce_only: placeOrderArgs.reduceOnly,
9582
+ client_order_id: placeOrderArgs.clientOrderId ? placeOrderArgs.clientOrderId.toString() : null,
9583
+ tpsl: placeOrderArgs.tpsl ? {
9584
+ pending_tp: placeOrderArgs.tpsl.pendingTp ? {
9585
+ order_price: BulletWasm.convert_rust_decimal_to_json(
9586
+ placeOrderArgs.tpsl.pendingTp.orderPrice.toFixed()
9505
9587
  ),
9506
- size: BulletWasm.convert_rust_decimal_to_json(
9507
- placeOrderArgs.size.toFixed()
9588
+ trigger_price: BulletWasm.convert_rust_decimal_to_json(
9589
+ placeOrderArgs.tpsl.pendingTp.triggerPrice.toFixed()
9508
9590
  ),
9509
- side: placeOrderArgs.side,
9510
- order_type: placeOrderArgs.orderType,
9511
- reduce_only: placeOrderArgs.reduceOnly,
9512
- client_order_id: placeOrderArgs.clientOrderId ? placeOrderArgs.clientOrderId.toString() : null,
9513
- tpsl: placeOrderArgs.tpsl ? {
9514
- pending_tp: placeOrderArgs.tpsl.pendingTp ? {
9515
- order_price: BulletWasm.convert_rust_decimal_to_json(
9516
- placeOrderArgs.tpsl.pendingTp.orderPrice.toFixed()
9517
- ),
9518
- trigger_price: BulletWasm.convert_rust_decimal_to_json(
9519
- placeOrderArgs.tpsl.pendingTp.triggerPrice.toFixed()
9520
- ),
9521
- trigger_direction: placeOrderArgs.tpsl.pendingTp.triggerDirection,
9522
- price_condition: placeOrderArgs.tpsl.pendingTp.priceCondition,
9523
- order_type: placeOrderArgs.tpsl.pendingTp.orderType
9524
- } : null,
9525
- pending_sl: placeOrderArgs.tpsl.pendingSl ? {
9526
- order_price: BulletWasm.convert_rust_decimal_to_json(
9527
- placeOrderArgs.tpsl.pendingSl.orderPrice.toFixed()
9528
- ),
9529
- trigger_price: BulletWasm.convert_rust_decimal_to_json(
9530
- placeOrderArgs.tpsl.pendingSl.triggerPrice.toFixed()
9531
- ),
9532
- trigger_direction: placeOrderArgs.tpsl.pendingSl.triggerDirection,
9533
- price_condition: placeOrderArgs.tpsl.pendingSl.priceCondition,
9534
- order_type: placeOrderArgs.tpsl.pendingSl.orderType
9535
- } : null,
9536
- dynamic_size: placeOrderArgs.tpsl.dynamicSize
9537
- } : null
9538
- }
9539
- }
9591
+ trigger_direction: placeOrderArgs.tpsl.pendingTp.triggerDirection,
9592
+ price_condition: placeOrderArgs.tpsl.pendingTp.priceCondition,
9593
+ order_type: placeOrderArgs.tpsl.pendingTp.orderType
9594
+ } : null,
9595
+ pending_sl: placeOrderArgs.tpsl.pendingSl ? {
9596
+ order_price: BulletWasm.convert_rust_decimal_to_json(
9597
+ placeOrderArgs.tpsl.pendingSl.orderPrice.toFixed()
9598
+ ),
9599
+ trigger_price: BulletWasm.convert_rust_decimal_to_json(
9600
+ placeOrderArgs.tpsl.pendingSl.triggerPrice.toFixed()
9601
+ ),
9602
+ trigger_direction: placeOrderArgs.tpsl.pendingSl.triggerDirection,
9603
+ price_condition: placeOrderArgs.tpsl.pendingSl.priceCondition,
9604
+ order_type: placeOrderArgs.tpsl.pendingSl.orderType
9605
+ } : null,
9606
+ dynamic_size: placeOrderArgs.tpsl.dynamicSize
9607
+ } : null
9540
9608
  }
9541
- });
9609
+ };
9610
+ const outerArgsObject = marketMeta.kind === "Spot" ? {
9611
+ exchange: {
9612
+ place_spot_order: innerArgsObject
9613
+ }
9614
+ } : {
9615
+ exchange: {
9616
+ place_order: innerArgsObject
9617
+ }
9618
+ };
9619
+ return await this.submitTransaction(outerArgsObject);
9542
9620
  }
9543
9621
  async createPositionTpsl(market, tpslOrders) {
9544
9622
  const marketId = this.exchange.getMarketId(market);
@@ -10030,14 +10108,12 @@ var Client = class _Client {
10030
10108
 
10031
10109
  // src/wallet/wallet.ts
10032
10110
  var Wallet = class {
10033
- constructor(publicKey, chainId = 4321) {
10111
+ constructor(publicKey) {
10034
10112
  // For now this is same as pubkey but b58 encoded
10035
10113
  __publicField(this, "address");
10036
10114
  __publicField(this, "publicKey");
10037
- __publicField(this, "chainId");
10038
10115
  this.publicKey = publicKey;
10039
10116
  this.address = hexToBase58(this.publicKey);
10040
- this.chainId = chainId;
10041
10117
  console.info("Address:", this.address);
10042
10118
  }
10043
10119
  };
@@ -10045,7 +10121,6 @@ export {
10045
10121
  ApiError,
10046
10122
  BaseResponseSchemas,
10047
10123
  BulletError,
10048
- CHAIN_IDS,
10049
10124
  Client,
10050
10125
  Connection,
10051
10126
  ExchangeConnection,