@bulletxyz/bullet-sdk 0.21.0-rc.7 → 0.22.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.
- package/dist/browser/index.js +124 -70
- package/dist/browser/index.js.map +3 -3
- package/dist/node/index.js +124 -70
- package/dist/node/index.js.map +3 -3
- package/dist/types/client.d.ts +4 -1
- package/dist/types/connection.d.ts +1 -1
- package/dist/types/constants.d.ts +5 -4
- package/dist/types/exchange.d.ts +7 -2
- package/dist/types/utils.d.ts +6 -0
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -2409,6 +2409,47 @@ LN10 = new Decimal(LN10);
|
|
|
2409
2409
|
PI = new Decimal(PI);
|
|
2410
2410
|
var decimal_default = Decimal;
|
|
2411
2411
|
|
|
2412
|
+
// src/constants.ts
|
|
2413
|
+
var TOKEN_ADDRESSES = {
|
|
2414
|
+
GAS: "token_1nyl0e0yweragfsatygt24zmd8jrr2vqtvdfptzjhxkguz2xxx3vs0y07u7",
|
|
2415
|
+
USDC: "token_1zh04r2k3kk0jf3xzr8cfpcm6qntumxwdvglq75g2ynwcu7daca0qm9ccg3",
|
|
2416
|
+
SOL: "token_1djhak8xt5326dgq8urtean5xtsv6hawcn9cy9wvsdtptu2eqj40q0qjxr7",
|
|
2417
|
+
BTC: "token_1g09xywefypxxx5exvxuqy0v3c5a7jwpnq4kkl85wxu9pkhgnrtqszlm4n8",
|
|
2418
|
+
ETH: "token_1gxvm2vkwqw40q9d4djxhrk66mukgrhdtqljeq5qa7jm3ajyksmmqwervaa",
|
|
2419
|
+
DOGE: "token_1y0xpw76f4nlscy0g50j0n7vyt6cemza96p4gj7a3hj548a3tmcrspfjmr3",
|
|
2420
|
+
WIF: "token_1kwcvtrg0k4xllu8ylxukquckmlh273u8eufvqtx30e07gm8c3lpsuxv8j6",
|
|
2421
|
+
XRP: "token_1jezvz43ldt6vqgycch077qqa4m8e97enrqww93vzgqra7v7rhxpqz4j3rm",
|
|
2422
|
+
HYPE: "token_1caey4sxtejtmf3q0djxkuztx6up4f66dkudgmw2ev0slhafx09kqj9qxcf",
|
|
2423
|
+
ADA: "token_1xgppquwlmyxsp9ecrqtu2feucecjkcfryvm6uhxsegvqn494mywsm75spg",
|
|
2424
|
+
TRUMP: "token_1pmd3hja4m4jewfjfcxl3zt6vlmphyyh0nlr4cn3kfs0pkdqx4wwq76053k",
|
|
2425
|
+
SUI: "token_1kxyfvmf7mxr5256kx8cjrg6whvau54wpq30n5j805h64z0wyzzpswhmz36",
|
|
2426
|
+
JUP: "token_18saxwfuma39ks3gafmqtql5y57qpd6yh2r6s4uawak8c8pe6xrzspw5gtv",
|
|
2427
|
+
JTO: "token_1ecdw04ht4xh5hkhx37dshz7gpjgkrww56e53tqx4nkhmau55p5yswazeej",
|
|
2428
|
+
ENA: "token_120xgtxhl5uwp9p20k8yjd5plshr9fdvsn5afj7cqazh5csuduj8q9nmy42",
|
|
2429
|
+
BERA: "token_133zykxvsvq8u8eq2j67n63gc08dpc4zudrch9vl7028rahcvss3s42ywhs",
|
|
2430
|
+
TIA: "token_185jxgchq6kpxskn4eggjfeju3t4sjxxfxj5mx9dn6wgydud7mtys4glllf",
|
|
2431
|
+
ZEX: "token_1g3hhmzp0c358t0s2dxht8jqqrfnnrgerk423mgs4cxd96u8ux24stetj0c"
|
|
2432
|
+
};
|
|
2433
|
+
var NETWORKS = {
|
|
2434
|
+
Localnet: {
|
|
2435
|
+
rest: "http://127.0.0.1:12346",
|
|
2436
|
+
ws: "ws://127.0.0.1:3000/ws"
|
|
2437
|
+
},
|
|
2438
|
+
Staging: {
|
|
2439
|
+
rest: "https://rollup-staging.zeta.markets",
|
|
2440
|
+
ws: "wss://zx-feed.zeta.markets/staging/ws"
|
|
2441
|
+
},
|
|
2442
|
+
Testnet: {
|
|
2443
|
+
rest: "https://rollup-testnet.zeta.markets",
|
|
2444
|
+
ws: "wss://zx-feed.zeta.markets/testnet/ws"
|
|
2445
|
+
},
|
|
2446
|
+
Mainnet: {
|
|
2447
|
+
rest: "https://rollup-mainnet.zeta.markets",
|
|
2448
|
+
ws: "wss://zx-feed.zeta.markets/mainnet/ws"
|
|
2449
|
+
}
|
|
2450
|
+
};
|
|
2451
|
+
var GLOBAL_DEFAULT_MAX_LEVERAGE = 1e3;
|
|
2452
|
+
|
|
2412
2453
|
// src/utils.ts
|
|
2413
2454
|
function bytesToHex(bytes2) {
|
|
2414
2455
|
return Array.from(bytes2).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
@@ -2467,6 +2508,33 @@ function serialize(value) {
|
|
|
2467
2508
|
}
|
|
2468
2509
|
return value;
|
|
2469
2510
|
}
|
|
2511
|
+
var isNetwork = (value) => {
|
|
2512
|
+
return value in NETWORKS;
|
|
2513
|
+
};
|
|
2514
|
+
var isValidHttpUrl = (url) => {
|
|
2515
|
+
try {
|
|
2516
|
+
const u = new URL(url);
|
|
2517
|
+
return u.protocol === "http:" || u.protocol === "https:";
|
|
2518
|
+
} catch {
|
|
2519
|
+
return false;
|
|
2520
|
+
}
|
|
2521
|
+
};
|
|
2522
|
+
var isValidWsUrl = (url) => {
|
|
2523
|
+
try {
|
|
2524
|
+
const u = new URL(url);
|
|
2525
|
+
return u.protocol === "ws:" || u.protocol === "wss:";
|
|
2526
|
+
} catch {
|
|
2527
|
+
return false;
|
|
2528
|
+
}
|
|
2529
|
+
};
|
|
2530
|
+
var validateEndpoints = (endpoints) => {
|
|
2531
|
+
if (!isValidHttpUrl(endpoints.rest)) {
|
|
2532
|
+
throw new Error(`Invalid REST URL: ${endpoints.rest}`);
|
|
2533
|
+
}
|
|
2534
|
+
if (endpoints.ws && !isValidWsUrl(endpoints.ws)) {
|
|
2535
|
+
throw new Error(`Invalid WebSocket URL: ${endpoints.ws}`);
|
|
2536
|
+
}
|
|
2537
|
+
};
|
|
2470
2538
|
|
|
2471
2539
|
// ../node_modules/.pnpm/zod@3.24.2/node_modules/zod/lib/index.mjs
|
|
2472
2540
|
var util;
|
|
@@ -6864,15 +6932,12 @@ var ResponseSchemas = {
|
|
|
6864
6932
|
|
|
6865
6933
|
// src/connection.ts
|
|
6866
6934
|
var BaseConnection = class {
|
|
6867
|
-
constructor(rawEndpoint
|
|
6935
|
+
constructor(rawEndpoint) {
|
|
6868
6936
|
__publicField(this, "endpoint");
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
const sanitizedEndpoint = `${parsedUrl.protocol}//${parsedUrl.hostname}${parsedUrl.port ? `:${parsedUrl.port}` : ""}`;
|
|
6872
|
-
this.endpoint = sanitizedEndpoint;
|
|
6873
|
-
} catch (error) {
|
|
6874
|
-
throw new Error(`Invalid URL provided: ${error}`);
|
|
6937
|
+
if (!isValidHttpUrl(rawEndpoint)) {
|
|
6938
|
+
throw new Error(`Invalid HTTP URL provided: ${rawEndpoint}`);
|
|
6875
6939
|
}
|
|
6940
|
+
this.endpoint = rawEndpoint;
|
|
6876
6941
|
}
|
|
6877
6942
|
async fetchApiResource(path, params) {
|
|
6878
6943
|
const url = new URL(path, this.endpoint);
|
|
@@ -6883,7 +6948,6 @@ var BaseConnection = class {
|
|
|
6883
6948
|
}
|
|
6884
6949
|
}
|
|
6885
6950
|
}
|
|
6886
|
-
console.debug("Fetching resource: ", url.toString());
|
|
6887
6951
|
const response = await fetch(url.toString());
|
|
6888
6952
|
if (!response.ok) {
|
|
6889
6953
|
throw await ApiError.fromResponse(response);
|
|
@@ -6937,47 +7001,6 @@ var Connection = class extends BaseConnection {
|
|
|
6937
7001
|
}
|
|
6938
7002
|
};
|
|
6939
7003
|
|
|
6940
|
-
// src/constants.ts
|
|
6941
|
-
var TOKEN_ADDRESSES = {
|
|
6942
|
-
GAS: "token_1nyl0e0yweragfsatygt24zmd8jrr2vqtvdfptzjhxkguz2xxx3vs0y07u7",
|
|
6943
|
-
USDC: "token_1zh04r2k3kk0jf3xzr8cfpcm6qntumxwdvglq75g2ynwcu7daca0qm9ccg3",
|
|
6944
|
-
SOL: "token_1djhak8xt5326dgq8urtean5xtsv6hawcn9cy9wvsdtptu2eqj40q0qjxr7",
|
|
6945
|
-
BTC: "token_1g09xywefypxxx5exvxuqy0v3c5a7jwpnq4kkl85wxu9pkhgnrtqszlm4n8",
|
|
6946
|
-
ETH: "token_1gxvm2vkwqw40q9d4djxhrk66mukgrhdtqljeq5qa7jm3ajyksmmqwervaa",
|
|
6947
|
-
DOGE: "token_1y0xpw76f4nlscy0g50j0n7vyt6cemza96p4gj7a3hj548a3tmcrspfjmr3",
|
|
6948
|
-
WIF: "token_1kwcvtrg0k4xllu8ylxukquckmlh273u8eufvqtx30e07gm8c3lpsuxv8j6",
|
|
6949
|
-
XRP: "token_1jezvz43ldt6vqgycch077qqa4m8e97enrqww93vzgqra7v7rhxpqz4j3rm",
|
|
6950
|
-
HYPE: "token_1caey4sxtejtmf3q0djxkuztx6up4f66dkudgmw2ev0slhafx09kqj9qxcf",
|
|
6951
|
-
ADA: "token_1xgppquwlmyxsp9ecrqtu2feucecjkcfryvm6uhxsegvqn494mywsm75spg",
|
|
6952
|
-
TRUMP: "token_1pmd3hja4m4jewfjfcxl3zt6vlmphyyh0nlr4cn3kfs0pkdqx4wwq76053k",
|
|
6953
|
-
SUI: "token_1kxyfvmf7mxr5256kx8cjrg6whvau54wpq30n5j805h64z0wyzzpswhmz36",
|
|
6954
|
-
JUP: "token_18saxwfuma39ks3gafmqtql5y57qpd6yh2r6s4uawak8c8pe6xrzspw5gtv",
|
|
6955
|
-
JTO: "token_1ecdw04ht4xh5hkhx37dshz7gpjgkrww56e53tqx4nkhmau55p5yswazeej",
|
|
6956
|
-
ENA: "token_120xgtxhl5uwp9p20k8yjd5plshr9fdvsn5afj7cqazh5csuduj8q9nmy42",
|
|
6957
|
-
BERA: "token_133zykxvsvq8u8eq2j67n63gc08dpc4zudrch9vl7028rahcvss3s42ywhs",
|
|
6958
|
-
TIA: "token_185jxgchq6kpxskn4eggjfeju3t4sjxxfxj5mx9dn6wgydud7mtys4glllf",
|
|
6959
|
-
ZEX: "token_1g3hhmzp0c358t0s2dxht8jqqrfnnrgerk423mgs4cxd96u8ux24stetj0c"
|
|
6960
|
-
};
|
|
6961
|
-
var NETWORK_CONFIG = {
|
|
6962
|
-
Localnet: {
|
|
6963
|
-
restEndpoint: "http://127.0.0.1:12346",
|
|
6964
|
-
wsEndpoint: "ws://127.0.0.1:3000/ws"
|
|
6965
|
-
},
|
|
6966
|
-
Staging: {
|
|
6967
|
-
restEndpoint: "https://rollup-staging.zeta.markets",
|
|
6968
|
-
wsEndpoint: "wss://zx-feed.zeta.markets/staging/ws"
|
|
6969
|
-
},
|
|
6970
|
-
Testnet: {
|
|
6971
|
-
restEndpoint: "https://rollup-testnet.zeta.markets",
|
|
6972
|
-
wsEndpoint: "wss://zx-feed.zeta.markets/testnet/ws"
|
|
6973
|
-
},
|
|
6974
|
-
Mainnet: {
|
|
6975
|
-
restEndpoint: "https://rollup-mainnet.zeta.markets",
|
|
6976
|
-
wsEndpoint: "wss://zx-feed.zeta.markets/mainnet/ws"
|
|
6977
|
-
}
|
|
6978
|
-
};
|
|
6979
|
-
var GLOBAL_DEFAULT_MAX_LEVERAGE = 1e3;
|
|
6980
|
-
|
|
6981
7004
|
// ../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.mjs
|
|
6982
7005
|
var import_index = __toESM(require_eventemitter3(), 1);
|
|
6983
7006
|
|
|
@@ -7265,12 +7288,27 @@ var WebSocketManager = class {
|
|
|
7265
7288
|
};
|
|
7266
7289
|
|
|
7267
7290
|
// src/exchange.ts
|
|
7268
|
-
var ExchangeConnection = class extends BaseConnection {
|
|
7269
|
-
constructor(
|
|
7270
|
-
|
|
7271
|
-
super(
|
|
7291
|
+
var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
|
|
7292
|
+
constructor(endpoints) {
|
|
7293
|
+
validateEndpoints(endpoints);
|
|
7294
|
+
super(endpoints.rest);
|
|
7272
7295
|
__publicField(this, "wsManager");
|
|
7273
|
-
|
|
7296
|
+
if (endpoints.ws) {
|
|
7297
|
+
this.wsManager = new WebSocketManager(endpoints.ws);
|
|
7298
|
+
}
|
|
7299
|
+
}
|
|
7300
|
+
// Static convenience constructors
|
|
7301
|
+
static fromEndpoints(endpoints) {
|
|
7302
|
+
return new _ExchangeConnection(endpoints);
|
|
7303
|
+
}
|
|
7304
|
+
static fromNetwork(network) {
|
|
7305
|
+
if (!isNetwork(network)) {
|
|
7306
|
+
throw new Error(`Invalid network: ${network}`);
|
|
7307
|
+
}
|
|
7308
|
+
return new _ExchangeConnection(NETWORKS[network]);
|
|
7309
|
+
}
|
|
7310
|
+
static fromRestUrl(restUrl) {
|
|
7311
|
+
return new _ExchangeConnection({ rest: restUrl });
|
|
7274
7312
|
}
|
|
7275
7313
|
async getValue() {
|
|
7276
7314
|
const response = await this.fetchApiResource(
|
|
@@ -7397,11 +7435,17 @@ var ExchangeConnection = class extends BaseConnection {
|
|
|
7397
7435
|
const parsed = ResponseSchemas.Assets.parse(response);
|
|
7398
7436
|
return parsed.data.assets;
|
|
7399
7437
|
}
|
|
7438
|
+
getWebSocketManager() {
|
|
7439
|
+
if (!this.wsManager) {
|
|
7440
|
+
throw new Error("WebSocket connection not configured");
|
|
7441
|
+
}
|
|
7442
|
+
return this.wsManager;
|
|
7443
|
+
}
|
|
7400
7444
|
async *subscribeOrderbook(assetId) {
|
|
7401
|
-
yield* this.
|
|
7445
|
+
yield* this.getWebSocketManager().subscribeOrderbook(assetId);
|
|
7402
7446
|
}
|
|
7403
7447
|
async unsubscribeOrderbook(assetId) {
|
|
7404
|
-
await this.
|
|
7448
|
+
await this.getWebSocketManager().unsubscribeOrderbook(assetId);
|
|
7405
7449
|
}
|
|
7406
7450
|
};
|
|
7407
7451
|
|
|
@@ -8989,7 +9033,7 @@ var DEFAULT_TRANSACTION_OPTS = {
|
|
|
8989
9033
|
chainId: 4321
|
|
8990
9034
|
};
|
|
8991
9035
|
var Client = class _Client {
|
|
8992
|
-
constructor(
|
|
9036
|
+
constructor(endpoints, wallet, rollup) {
|
|
8993
9037
|
__publicField(this, "connection");
|
|
8994
9038
|
__publicField(this, "exchange");
|
|
8995
9039
|
__publicField(this, "address");
|
|
@@ -8998,21 +9042,18 @@ var Client = class _Client {
|
|
|
8998
9042
|
// This serializes all transaction submissions to avoid nonce conflicts
|
|
8999
9043
|
__publicField(this, "queue", new PQueue({ concurrency: 1 }));
|
|
9000
9044
|
__publicField(this, "generationOverride");
|
|
9001
|
-
|
|
9045
|
+
validateEndpoints(endpoints);
|
|
9046
|
+
console.debug("Endpoints:", endpoints);
|
|
9002
9047
|
this.wallet = wallet;
|
|
9003
9048
|
this.rollup = rollup;
|
|
9004
|
-
this.
|
|
9005
|
-
this.
|
|
9049
|
+
this.exchange = ExchangeConnection.fromEndpoints(endpoints);
|
|
9050
|
+
this.connection = new Connection(endpoints.rest);
|
|
9006
9051
|
this.address = wallet.address;
|
|
9007
9052
|
}
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
throw new Error(`Invalid network: ${network}`);
|
|
9011
|
-
}
|
|
9012
|
-
const { restEndpoint } = NETWORK_CONFIG[network];
|
|
9013
|
-
console.debug("Endpoint:", restEndpoint);
|
|
9053
|
+
// Static convenience constructors
|
|
9054
|
+
static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
|
|
9014
9055
|
const rollup = await createStandardRollup({
|
|
9015
|
-
url:
|
|
9056
|
+
url: endpoints.rest,
|
|
9016
9057
|
context: {
|
|
9017
9058
|
defaultTxDetails: {
|
|
9018
9059
|
max_priority_fee_bips: txOpts.maxPriorityFeeBps,
|
|
@@ -9022,7 +9063,16 @@ var Client = class _Client {
|
|
|
9022
9063
|
}
|
|
9023
9064
|
}
|
|
9024
9065
|
});
|
|
9025
|
-
return new _Client(
|
|
9066
|
+
return new _Client(endpoints, wallet, rollup);
|
|
9067
|
+
}
|
|
9068
|
+
static async fromNetwork(network, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
|
|
9069
|
+
if (!isNetwork(network)) {
|
|
9070
|
+
throw new Error(`Invalid network: ${network}`);
|
|
9071
|
+
}
|
|
9072
|
+
return await _Client.fromEndpoints(NETWORKS[network], wallet, txOpts);
|
|
9073
|
+
}
|
|
9074
|
+
static async fromRestUrl(restUrl, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
|
|
9075
|
+
return await _Client.fromEndpoints({ rest: restUrl }, wallet, txOpts);
|
|
9026
9076
|
}
|
|
9027
9077
|
setGenerationOverride(generation) {
|
|
9028
9078
|
this.generationOverride = generation;
|
|
@@ -9689,7 +9739,7 @@ export {
|
|
|
9689
9739
|
Connection,
|
|
9690
9740
|
ExchangeConnection,
|
|
9691
9741
|
GLOBAL_DEFAULT_MAX_LEVERAGE,
|
|
9692
|
-
|
|
9742
|
+
NETWORKS,
|
|
9693
9743
|
Orderbook,
|
|
9694
9744
|
ResponseSchemas,
|
|
9695
9745
|
Schemas,
|
|
@@ -9720,12 +9770,16 @@ export {
|
|
|
9720
9770
|
hexToBase58,
|
|
9721
9771
|
hexToBase64,
|
|
9722
9772
|
hexToBytes,
|
|
9773
|
+
isNetwork,
|
|
9723
9774
|
isNode,
|
|
9775
|
+
isValidHttpUrl,
|
|
9776
|
+
isValidWsUrl,
|
|
9724
9777
|
serialize,
|
|
9725
9778
|
simulateEstimatedLiquidationPriceOnOrder,
|
|
9726
9779
|
simulateUsedMarginOnBorrow,
|
|
9727
9780
|
simulateUsedMarginOnOrder,
|
|
9728
|
-
sleep
|
|
9781
|
+
sleep,
|
|
9782
|
+
validateEndpoints
|
|
9729
9783
|
};
|
|
9730
9784
|
/*! Bundled license information:
|
|
9731
9785
|
|