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

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);
@@ -8821,14 +8900,12 @@ var BulletError = class _BulletError extends Error {
8821
8900
 
8822
8901
  // src/wallet/wallet.ts
8823
8902
  var Wallet = class {
8824
- constructor(publicKey, chainId = 4321) {
8903
+ constructor(publicKey) {
8825
8904
  // For now this is same as pubkey but b58 encoded
8826
8905
  __publicField(this, "address");
8827
8906
  __publicField(this, "publicKey");
8828
- __publicField(this, "chainId");
8829
8907
  this.publicKey = publicKey;
8830
8908
  this.address = hexToBase58(this.publicKey);
8831
- this.chainId = chainId;
8832
8909
  console.info("Address:", this.address);
8833
8910
  }
8834
8911
  };
@@ -9366,7 +9443,12 @@ var Client = class _Client {
9366
9443
  this.address = wallet.address;
9367
9444
  }
9368
9445
  // Static convenience constructors
9369
- static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS, chainId = 4321) {
9446
+ static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
9447
+ validateEndpoints(endpoints);
9448
+ console.debug("Endpoints:", endpoints);
9449
+ const exchange = await ExchangeConnection.fromEndpoints(endpoints);
9450
+ const chainId = await exchange.getChainId();
9451
+ console.debug("Chain ID:", chainId);
9370
9452
  const rollup = await createStandardRollup({
9371
9453
  url: endpoints.rest,
9372
9454
  getSerializer: (schema) => new WasmSerializer(schema),
@@ -9379,29 +9461,16 @@ var Client = class _Client {
9379
9461
  }
9380
9462
  }
9381
9463
  });
9382
- validateEndpoints(endpoints);
9383
- console.debug("Endpoints:", endpoints);
9384
- const exchange = await ExchangeConnection.fromEndpoints(endpoints);
9385
9464
  return new _Client(endpoints, exchange, wallet, rollup);
9386
9465
  }
9387
9466
  static async fromNetwork(network, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
9388
9467
  if (!isNetwork(network)) {
9389
9468
  throw new Error(`Invalid network: ${network}`);
9390
9469
  }
9391
- return await _Client.fromEndpoints(
9392
- NETWORKS[network],
9393
- wallet,
9394
- txOpts,
9395
- CHAIN_IDS[network]
9396
- );
9470
+ return await _Client.fromEndpoints(NETWORKS[network], wallet, txOpts);
9397
9471
  }
9398
- static async fromRestUrl(restUrl, wallet, network, txOpts = DEFAULT_TRANSACTION_OPTS) {
9399
- return await _Client.fromEndpoints(
9400
- { rest: restUrl },
9401
- wallet,
9402
- txOpts,
9403
- CHAIN_IDS[network]
9404
- );
9472
+ static async fromRestUrl(restUrl, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
9473
+ return await _Client.fromEndpoints({ rest: restUrl }, wallet, txOpts);
9405
9474
  }
9406
9475
  setGenerationOverride(generation) {
9407
9476
  this.generationOverride = generation;
@@ -9508,51 +9577,58 @@ var Client = class _Client {
9508
9577
  });
9509
9578
  }
9510
9579
  async placeOrder(placeOrderArgs) {
9511
- const marketId = this.exchange.getMarketId(placeOrderArgs.market);
9512
- return await this.submitTransaction({
9513
- exchange: {
9514
- place_order: {
9515
- args: {
9516
- market_id: marketId,
9517
- price: BulletWasm.convert_rust_decimal_to_json(
9518
- placeOrderArgs.price.toFixed()
9580
+ const marketMeta = this.exchange.getMarketMeta(placeOrderArgs.market);
9581
+ const marketId = marketMeta.id;
9582
+ const innerArgsObject = {
9583
+ args: {
9584
+ market_id: marketId,
9585
+ price: BulletWasm.convert_rust_decimal_to_json(
9586
+ placeOrderArgs.price.toFixed()
9587
+ ),
9588
+ size: BulletWasm.convert_rust_decimal_to_json(
9589
+ placeOrderArgs.size.toFixed()
9590
+ ),
9591
+ side: placeOrderArgs.side,
9592
+ order_type: placeOrderArgs.orderType,
9593
+ reduce_only: placeOrderArgs.reduceOnly,
9594
+ client_order_id: placeOrderArgs.clientOrderId ? placeOrderArgs.clientOrderId.toString() : null,
9595
+ tpsl: placeOrderArgs.tpsl ? {
9596
+ pending_tp: placeOrderArgs.tpsl.pendingTp ? {
9597
+ order_price: BulletWasm.convert_rust_decimal_to_json(
9598
+ placeOrderArgs.tpsl.pendingTp.orderPrice.toFixed()
9519
9599
  ),
9520
- size: BulletWasm.convert_rust_decimal_to_json(
9521
- placeOrderArgs.size.toFixed()
9600
+ trigger_price: BulletWasm.convert_rust_decimal_to_json(
9601
+ placeOrderArgs.tpsl.pendingTp.triggerPrice.toFixed()
9522
9602
  ),
9523
- side: placeOrderArgs.side,
9524
- order_type: placeOrderArgs.orderType,
9525
- reduce_only: placeOrderArgs.reduceOnly,
9526
- client_order_id: placeOrderArgs.clientOrderId ? placeOrderArgs.clientOrderId.toString() : null,
9527
- tpsl: placeOrderArgs.tpsl ? {
9528
- pending_tp: placeOrderArgs.tpsl.pendingTp ? {
9529
- order_price: BulletWasm.convert_rust_decimal_to_json(
9530
- placeOrderArgs.tpsl.pendingTp.orderPrice.toFixed()
9531
- ),
9532
- trigger_price: BulletWasm.convert_rust_decimal_to_json(
9533
- placeOrderArgs.tpsl.pendingTp.triggerPrice.toFixed()
9534
- ),
9535
- trigger_direction: placeOrderArgs.tpsl.pendingTp.triggerDirection,
9536
- price_condition: placeOrderArgs.tpsl.pendingTp.priceCondition,
9537
- order_type: placeOrderArgs.tpsl.pendingTp.orderType
9538
- } : null,
9539
- pending_sl: placeOrderArgs.tpsl.pendingSl ? {
9540
- order_price: BulletWasm.convert_rust_decimal_to_json(
9541
- placeOrderArgs.tpsl.pendingSl.orderPrice.toFixed()
9542
- ),
9543
- trigger_price: BulletWasm.convert_rust_decimal_to_json(
9544
- placeOrderArgs.tpsl.pendingSl.triggerPrice.toFixed()
9545
- ),
9546
- trigger_direction: placeOrderArgs.tpsl.pendingSl.triggerDirection,
9547
- price_condition: placeOrderArgs.tpsl.pendingSl.priceCondition,
9548
- order_type: placeOrderArgs.tpsl.pendingSl.orderType
9549
- } : null,
9550
- dynamic_size: placeOrderArgs.tpsl.dynamicSize
9551
- } : null
9552
- }
9553
- }
9603
+ trigger_direction: placeOrderArgs.tpsl.pendingTp.triggerDirection,
9604
+ price_condition: placeOrderArgs.tpsl.pendingTp.priceCondition,
9605
+ order_type: placeOrderArgs.tpsl.pendingTp.orderType
9606
+ } : null,
9607
+ pending_sl: placeOrderArgs.tpsl.pendingSl ? {
9608
+ order_price: BulletWasm.convert_rust_decimal_to_json(
9609
+ placeOrderArgs.tpsl.pendingSl.orderPrice.toFixed()
9610
+ ),
9611
+ trigger_price: BulletWasm.convert_rust_decimal_to_json(
9612
+ placeOrderArgs.tpsl.pendingSl.triggerPrice.toFixed()
9613
+ ),
9614
+ trigger_direction: placeOrderArgs.tpsl.pendingSl.triggerDirection,
9615
+ price_condition: placeOrderArgs.tpsl.pendingSl.priceCondition,
9616
+ order_type: placeOrderArgs.tpsl.pendingSl.orderType
9617
+ } : null,
9618
+ dynamic_size: placeOrderArgs.tpsl.dynamicSize
9619
+ } : null
9554
9620
  }
9555
- });
9621
+ };
9622
+ const outerArgsObject = marketMeta.kind === "Spot" ? {
9623
+ exchange: {
9624
+ place_spot_order: innerArgsObject
9625
+ }
9626
+ } : {
9627
+ exchange: {
9628
+ place_order: innerArgsObject
9629
+ }
9630
+ };
9631
+ return await this.submitTransaction(outerArgsObject);
9556
9632
  }
9557
9633
  async createPositionTpsl(market, tpslOrders) {
9558
9634
  const marketId = this.exchange.getMarketId(market);
@@ -10047,16 +10123,14 @@ import { readFileSync } from "node:fs";
10047
10123
  import * as ed from "@noble/ed25519";
10048
10124
  import { Ed25519Signer } from "@sovereign-sdk/signers";
10049
10125
  var NodeWallet = class _NodeWallet extends Wallet {
10050
- constructor(privateKey, publicKey, chainId = 4321) {
10126
+ constructor(privateKey, publicKey) {
10051
10127
  if (typeof window !== "undefined") {
10052
10128
  throw new Error("NodeWallet is not supported in browser environments");
10053
10129
  }
10054
- super(publicKey, chainId);
10130
+ super(publicKey);
10055
10131
  // All hex strings - may eventually add a class
10056
10132
  __publicField(this, "privateKey");
10057
- __publicField(this, "chainId");
10058
10133
  this.privateKey = privateKey;
10059
- this.chainId = chainId;
10060
10134
  }
10061
10135
  static async fromPrivateKeyBytes(privateKeyBytes) {
10062
10136
  const privateKey = bytesToHex(privateKeyBytes.slice(0, 32)).replace(
@@ -10105,7 +10179,6 @@ export {
10105
10179
  ApiError,
10106
10180
  BaseResponseSchemas,
10107
10181
  BulletError,
10108
- CHAIN_IDS,
10109
10182
  Client,
10110
10183
  Connection,
10111
10184
  ExchangeConnection,