@bulletxyz/bullet-sdk 0.27.2-rc.2 → 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.
- package/dist/browser/index.js +147 -67
- package/dist/browser/index.js.map +2 -2
- package/dist/node/index.js +149 -71
- package/dist/node/index.js.map +2 -2
- package/dist/types/client.d.ts +2 -2
- package/dist/types/constants.d.ts +0 -1
- package/dist/types/exchange.d.ts +6 -3
- package/dist/types/rollupTypes.d.ts +25 -0
- package/dist/types/types.d.ts +6 -0
- package/dist/types/wallet/nodeWallet.d.ts +1 -2
- package/dist/types/wallet/wallet.d.ts +1 -2
- package/dist/types/zod-types/rest.d.ts +577 -14
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -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,
|
|
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
|
|
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,24 +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, txOpts = DEFAULT_TRANSACTION_OPTS
|
|
9385
|
-
return await _Client.fromEndpoints({ rest: restUrl }, wallet, txOpts
|
|
9460
|
+
static async fromRestUrl(restUrl, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
|
|
9461
|
+
return await _Client.fromEndpoints({ rest: restUrl }, wallet, txOpts);
|
|
9386
9462
|
}
|
|
9387
9463
|
setGenerationOverride(generation) {
|
|
9388
9464
|
this.generationOverride = generation;
|
|
@@ -9489,51 +9565,58 @@ var Client = class _Client {
|
|
|
9489
9565
|
});
|
|
9490
9566
|
}
|
|
9491
9567
|
async placeOrder(placeOrderArgs) {
|
|
9492
|
-
const
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
|
|
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()
|
|
9500
9587
|
),
|
|
9501
|
-
|
|
9502
|
-
placeOrderArgs.
|
|
9588
|
+
trigger_price: BulletWasm.convert_rust_decimal_to_json(
|
|
9589
|
+
placeOrderArgs.tpsl.pendingTp.triggerPrice.toFixed()
|
|
9503
9590
|
),
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
|
|
9514
|
-
|
|
9515
|
-
|
|
9516
|
-
|
|
9517
|
-
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9521
|
-
order_price: BulletWasm.convert_rust_decimal_to_json(
|
|
9522
|
-
placeOrderArgs.tpsl.pendingSl.orderPrice.toFixed()
|
|
9523
|
-
),
|
|
9524
|
-
trigger_price: BulletWasm.convert_rust_decimal_to_json(
|
|
9525
|
-
placeOrderArgs.tpsl.pendingSl.triggerPrice.toFixed()
|
|
9526
|
-
),
|
|
9527
|
-
trigger_direction: placeOrderArgs.tpsl.pendingSl.triggerDirection,
|
|
9528
|
-
price_condition: placeOrderArgs.tpsl.pendingSl.priceCondition,
|
|
9529
|
-
order_type: placeOrderArgs.tpsl.pendingSl.orderType
|
|
9530
|
-
} : null,
|
|
9531
|
-
dynamic_size: placeOrderArgs.tpsl.dynamicSize
|
|
9532
|
-
} : null
|
|
9533
|
-
}
|
|
9534
|
-
}
|
|
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
|
|
9535
9608
|
}
|
|
9536
|
-
}
|
|
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);
|
|
9537
9620
|
}
|
|
9538
9621
|
async createPositionTpsl(market, tpslOrders) {
|
|
9539
9622
|
const marketId = this.exchange.getMarketId(market);
|
|
@@ -10025,14 +10108,12 @@ var Client = class _Client {
|
|
|
10025
10108
|
|
|
10026
10109
|
// src/wallet/wallet.ts
|
|
10027
10110
|
var Wallet = class {
|
|
10028
|
-
constructor(publicKey
|
|
10111
|
+
constructor(publicKey) {
|
|
10029
10112
|
// For now this is same as pubkey but b58 encoded
|
|
10030
10113
|
__publicField(this, "address");
|
|
10031
10114
|
__publicField(this, "publicKey");
|
|
10032
|
-
__publicField(this, "chainId");
|
|
10033
10115
|
this.publicKey = publicKey;
|
|
10034
10116
|
this.address = hexToBase58(this.publicKey);
|
|
10035
|
-
this.chainId = chainId;
|
|
10036
10117
|
console.info("Address:", this.address);
|
|
10037
10118
|
}
|
|
10038
10119
|
};
|
|
@@ -10040,7 +10121,6 @@ export {
|
|
|
10040
10121
|
ApiError,
|
|
10041
10122
|
BaseResponseSchemas,
|
|
10042
10123
|
BulletError,
|
|
10043
|
-
CHAIN_IDS,
|
|
10044
10124
|
Client,
|
|
10045
10125
|
Connection,
|
|
10046
10126
|
ExchangeConnection,
|