@bulletxyz/bullet-sdk 0.21.0-rc.8 → 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 -69
- package/dist/browser/index.js.map +3 -3
- package/dist/node/index.js +124 -69
- 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/node/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);
|
|
@@ -6936,47 +7001,6 @@ var Connection = class extends BaseConnection {
|
|
|
6936
7001
|
}
|
|
6937
7002
|
};
|
|
6938
7003
|
|
|
6939
|
-
// src/constants.ts
|
|
6940
|
-
var TOKEN_ADDRESSES = {
|
|
6941
|
-
GAS: "token_1nyl0e0yweragfsatygt24zmd8jrr2vqtvdfptzjhxkguz2xxx3vs0y07u7",
|
|
6942
|
-
USDC: "token_1zh04r2k3kk0jf3xzr8cfpcm6qntumxwdvglq75g2ynwcu7daca0qm9ccg3",
|
|
6943
|
-
SOL: "token_1djhak8xt5326dgq8urtean5xtsv6hawcn9cy9wvsdtptu2eqj40q0qjxr7",
|
|
6944
|
-
BTC: "token_1g09xywefypxxx5exvxuqy0v3c5a7jwpnq4kkl85wxu9pkhgnrtqszlm4n8",
|
|
6945
|
-
ETH: "token_1gxvm2vkwqw40q9d4djxhrk66mukgrhdtqljeq5qa7jm3ajyksmmqwervaa",
|
|
6946
|
-
DOGE: "token_1y0xpw76f4nlscy0g50j0n7vyt6cemza96p4gj7a3hj548a3tmcrspfjmr3",
|
|
6947
|
-
WIF: "token_1kwcvtrg0k4xllu8ylxukquckmlh273u8eufvqtx30e07gm8c3lpsuxv8j6",
|
|
6948
|
-
XRP: "token_1jezvz43ldt6vqgycch077qqa4m8e97enrqww93vzgqra7v7rhxpqz4j3rm",
|
|
6949
|
-
HYPE: "token_1caey4sxtejtmf3q0djxkuztx6up4f66dkudgmw2ev0slhafx09kqj9qxcf",
|
|
6950
|
-
ADA: "token_1xgppquwlmyxsp9ecrqtu2feucecjkcfryvm6uhxsegvqn494mywsm75spg",
|
|
6951
|
-
TRUMP: "token_1pmd3hja4m4jewfjfcxl3zt6vlmphyyh0nlr4cn3kfs0pkdqx4wwq76053k",
|
|
6952
|
-
SUI: "token_1kxyfvmf7mxr5256kx8cjrg6whvau54wpq30n5j805h64z0wyzzpswhmz36",
|
|
6953
|
-
JUP: "token_18saxwfuma39ks3gafmqtql5y57qpd6yh2r6s4uawak8c8pe6xrzspw5gtv",
|
|
6954
|
-
JTO: "token_1ecdw04ht4xh5hkhx37dshz7gpjgkrww56e53tqx4nkhmau55p5yswazeej",
|
|
6955
|
-
ENA: "token_120xgtxhl5uwp9p20k8yjd5plshr9fdvsn5afj7cqazh5csuduj8q9nmy42",
|
|
6956
|
-
BERA: "token_133zykxvsvq8u8eq2j67n63gc08dpc4zudrch9vl7028rahcvss3s42ywhs",
|
|
6957
|
-
TIA: "token_185jxgchq6kpxskn4eggjfeju3t4sjxxfxj5mx9dn6wgydud7mtys4glllf",
|
|
6958
|
-
ZEX: "token_1g3hhmzp0c358t0s2dxht8jqqrfnnrgerk423mgs4cxd96u8ux24stetj0c"
|
|
6959
|
-
};
|
|
6960
|
-
var NETWORK_CONFIG = {
|
|
6961
|
-
Localnet: {
|
|
6962
|
-
restEndpoint: "http://127.0.0.1:12346",
|
|
6963
|
-
wsEndpoint: "ws://127.0.0.1:3000/ws"
|
|
6964
|
-
},
|
|
6965
|
-
Staging: {
|
|
6966
|
-
restEndpoint: "https://rollup-staging.zeta.markets",
|
|
6967
|
-
wsEndpoint: "wss://zx-feed.zeta.markets/staging/ws"
|
|
6968
|
-
},
|
|
6969
|
-
Testnet: {
|
|
6970
|
-
restEndpoint: "https://rollup-testnet.zeta.markets",
|
|
6971
|
-
wsEndpoint: "wss://zx-feed.zeta.markets/testnet/ws"
|
|
6972
|
-
},
|
|
6973
|
-
Mainnet: {
|
|
6974
|
-
restEndpoint: "https://rollup-mainnet.zeta.markets",
|
|
6975
|
-
wsEndpoint: "wss://zx-feed.zeta.markets/mainnet/ws"
|
|
6976
|
-
}
|
|
6977
|
-
};
|
|
6978
|
-
var GLOBAL_DEFAULT_MAX_LEVERAGE = 1e3;
|
|
6979
|
-
|
|
6980
7004
|
// ../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.mjs
|
|
6981
7005
|
var import_index = __toESM(require_eventemitter3(), 1);
|
|
6982
7006
|
|
|
@@ -7264,12 +7288,27 @@ var WebSocketManager = class {
|
|
|
7264
7288
|
};
|
|
7265
7289
|
|
|
7266
7290
|
// src/exchange.ts
|
|
7267
|
-
var ExchangeConnection = class extends BaseConnection {
|
|
7268
|
-
constructor(
|
|
7269
|
-
|
|
7270
|
-
super(
|
|
7291
|
+
var ExchangeConnection = class _ExchangeConnection extends BaseConnection {
|
|
7292
|
+
constructor(endpoints) {
|
|
7293
|
+
validateEndpoints(endpoints);
|
|
7294
|
+
super(endpoints.rest);
|
|
7271
7295
|
__publicField(this, "wsManager");
|
|
7272
|
-
|
|
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 });
|
|
7273
7312
|
}
|
|
7274
7313
|
async getValue() {
|
|
7275
7314
|
const response = await this.fetchApiResource(
|
|
@@ -7396,11 +7435,17 @@ var ExchangeConnection = class extends BaseConnection {
|
|
|
7396
7435
|
const parsed = ResponseSchemas.Assets.parse(response);
|
|
7397
7436
|
return parsed.data.assets;
|
|
7398
7437
|
}
|
|
7438
|
+
getWebSocketManager() {
|
|
7439
|
+
if (!this.wsManager) {
|
|
7440
|
+
throw new Error("WebSocket connection not configured");
|
|
7441
|
+
}
|
|
7442
|
+
return this.wsManager;
|
|
7443
|
+
}
|
|
7399
7444
|
async *subscribeOrderbook(assetId) {
|
|
7400
|
-
yield* this.
|
|
7445
|
+
yield* this.getWebSocketManager().subscribeOrderbook(assetId);
|
|
7401
7446
|
}
|
|
7402
7447
|
async unsubscribeOrderbook(assetId) {
|
|
7403
|
-
await this.
|
|
7448
|
+
await this.getWebSocketManager().unsubscribeOrderbook(assetId);
|
|
7404
7449
|
}
|
|
7405
7450
|
};
|
|
7406
7451
|
|
|
@@ -9002,7 +9047,7 @@ var DEFAULT_TRANSACTION_OPTS = {
|
|
|
9002
9047
|
chainId: 4321
|
|
9003
9048
|
};
|
|
9004
9049
|
var Client = class _Client {
|
|
9005
|
-
constructor(
|
|
9050
|
+
constructor(endpoints, wallet, rollup) {
|
|
9006
9051
|
__publicField(this, "connection");
|
|
9007
9052
|
__publicField(this, "exchange");
|
|
9008
9053
|
__publicField(this, "address");
|
|
@@ -9011,21 +9056,18 @@ var Client = class _Client {
|
|
|
9011
9056
|
// This serializes all transaction submissions to avoid nonce conflicts
|
|
9012
9057
|
__publicField(this, "queue", new PQueue({ concurrency: 1 }));
|
|
9013
9058
|
__publicField(this, "generationOverride");
|
|
9014
|
-
|
|
9059
|
+
validateEndpoints(endpoints);
|
|
9060
|
+
console.debug("Endpoints:", endpoints);
|
|
9015
9061
|
this.wallet = wallet;
|
|
9016
9062
|
this.rollup = rollup;
|
|
9017
|
-
this.
|
|
9018
|
-
this.
|
|
9063
|
+
this.exchange = ExchangeConnection.fromEndpoints(endpoints);
|
|
9064
|
+
this.connection = new Connection(endpoints.rest);
|
|
9019
9065
|
this.address = wallet.address;
|
|
9020
9066
|
}
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
throw new Error(`Invalid network: ${network}`);
|
|
9024
|
-
}
|
|
9025
|
-
const { restEndpoint } = NETWORK_CONFIG[network];
|
|
9026
|
-
console.debug("Endpoint:", restEndpoint);
|
|
9067
|
+
// Static convenience constructors
|
|
9068
|
+
static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
|
|
9027
9069
|
const rollup = await createStandardRollup({
|
|
9028
|
-
url:
|
|
9070
|
+
url: endpoints.rest,
|
|
9029
9071
|
context: {
|
|
9030
9072
|
defaultTxDetails: {
|
|
9031
9073
|
max_priority_fee_bips: txOpts.maxPriorityFeeBps,
|
|
@@ -9035,7 +9077,16 @@ var Client = class _Client {
|
|
|
9035
9077
|
}
|
|
9036
9078
|
}
|
|
9037
9079
|
});
|
|
9038
|
-
return new _Client(
|
|
9080
|
+
return new _Client(endpoints, wallet, rollup);
|
|
9081
|
+
}
|
|
9082
|
+
static async fromNetwork(network, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
|
|
9083
|
+
if (!isNetwork(network)) {
|
|
9084
|
+
throw new Error(`Invalid network: ${network}`);
|
|
9085
|
+
}
|
|
9086
|
+
return await _Client.fromEndpoints(NETWORKS[network], wallet, txOpts);
|
|
9087
|
+
}
|
|
9088
|
+
static async fromRestUrl(restUrl, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
|
|
9089
|
+
return await _Client.fromEndpoints({ rest: restUrl }, wallet, txOpts);
|
|
9039
9090
|
}
|
|
9040
9091
|
setGenerationOverride(generation) {
|
|
9041
9092
|
this.generationOverride = generation;
|
|
@@ -9755,7 +9806,7 @@ export {
|
|
|
9755
9806
|
Connection,
|
|
9756
9807
|
ExchangeConnection,
|
|
9757
9808
|
GLOBAL_DEFAULT_MAX_LEVERAGE,
|
|
9758
|
-
|
|
9809
|
+
NETWORKS,
|
|
9759
9810
|
NodeWallet,
|
|
9760
9811
|
Orderbook,
|
|
9761
9812
|
ResponseSchemas,
|
|
@@ -9787,12 +9838,16 @@ export {
|
|
|
9787
9838
|
hexToBase58,
|
|
9788
9839
|
hexToBase64,
|
|
9789
9840
|
hexToBytes,
|
|
9841
|
+
isNetwork,
|
|
9790
9842
|
isNode,
|
|
9843
|
+
isValidHttpUrl,
|
|
9844
|
+
isValidWsUrl,
|
|
9791
9845
|
serialize,
|
|
9792
9846
|
simulateEstimatedLiquidationPriceOnOrder,
|
|
9793
9847
|
simulateUsedMarginOnBorrow,
|
|
9794
9848
|
simulateUsedMarginOnOrder,
|
|
9795
|
-
sleep
|
|
9849
|
+
sleep,
|
|
9850
|
+
validateEndpoints
|
|
9796
9851
|
};
|
|
9797
9852
|
/*! Bundled license information:
|
|
9798
9853
|
|