@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/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);
|
|
@@ -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
|
|
|
@@ -8988,7 +9033,7 @@ var DEFAULT_TRANSACTION_OPTS = {
|
|
|
8988
9033
|
chainId: 4321
|
|
8989
9034
|
};
|
|
8990
9035
|
var Client = class _Client {
|
|
8991
|
-
constructor(
|
|
9036
|
+
constructor(endpoints, wallet, rollup) {
|
|
8992
9037
|
__publicField(this, "connection");
|
|
8993
9038
|
__publicField(this, "exchange");
|
|
8994
9039
|
__publicField(this, "address");
|
|
@@ -8997,21 +9042,18 @@ var Client = class _Client {
|
|
|
8997
9042
|
// This serializes all transaction submissions to avoid nonce conflicts
|
|
8998
9043
|
__publicField(this, "queue", new PQueue({ concurrency: 1 }));
|
|
8999
9044
|
__publicField(this, "generationOverride");
|
|
9000
|
-
|
|
9045
|
+
validateEndpoints(endpoints);
|
|
9046
|
+
console.debug("Endpoints:", endpoints);
|
|
9001
9047
|
this.wallet = wallet;
|
|
9002
9048
|
this.rollup = rollup;
|
|
9003
|
-
this.
|
|
9004
|
-
this.
|
|
9049
|
+
this.exchange = ExchangeConnection.fromEndpoints(endpoints);
|
|
9050
|
+
this.connection = new Connection(endpoints.rest);
|
|
9005
9051
|
this.address = wallet.address;
|
|
9006
9052
|
}
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
throw new Error(`Invalid network: ${network}`);
|
|
9010
|
-
}
|
|
9011
|
-
const { restEndpoint } = NETWORK_CONFIG[network];
|
|
9012
|
-
console.debug("Endpoint:", restEndpoint);
|
|
9053
|
+
// Static convenience constructors
|
|
9054
|
+
static async fromEndpoints(endpoints, wallet, txOpts = DEFAULT_TRANSACTION_OPTS) {
|
|
9013
9055
|
const rollup = await createStandardRollup({
|
|
9014
|
-
url:
|
|
9056
|
+
url: endpoints.rest,
|
|
9015
9057
|
context: {
|
|
9016
9058
|
defaultTxDetails: {
|
|
9017
9059
|
max_priority_fee_bips: txOpts.maxPriorityFeeBps,
|
|
@@ -9021,7 +9063,16 @@ var Client = class _Client {
|
|
|
9021
9063
|
}
|
|
9022
9064
|
}
|
|
9023
9065
|
});
|
|
9024
|
-
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);
|
|
9025
9076
|
}
|
|
9026
9077
|
setGenerationOverride(generation) {
|
|
9027
9078
|
this.generationOverride = generation;
|
|
@@ -9688,7 +9739,7 @@ export {
|
|
|
9688
9739
|
Connection,
|
|
9689
9740
|
ExchangeConnection,
|
|
9690
9741
|
GLOBAL_DEFAULT_MAX_LEVERAGE,
|
|
9691
|
-
|
|
9742
|
+
NETWORKS,
|
|
9692
9743
|
Orderbook,
|
|
9693
9744
|
ResponseSchemas,
|
|
9694
9745
|
Schemas,
|
|
@@ -9719,12 +9770,16 @@ export {
|
|
|
9719
9770
|
hexToBase58,
|
|
9720
9771
|
hexToBase64,
|
|
9721
9772
|
hexToBytes,
|
|
9773
|
+
isNetwork,
|
|
9722
9774
|
isNode,
|
|
9775
|
+
isValidHttpUrl,
|
|
9776
|
+
isValidWsUrl,
|
|
9723
9777
|
serialize,
|
|
9724
9778
|
simulateEstimatedLiquidationPriceOnOrder,
|
|
9725
9779
|
simulateUsedMarginOnBorrow,
|
|
9726
9780
|
simulateUsedMarginOnOrder,
|
|
9727
|
-
sleep
|
|
9781
|
+
sleep,
|
|
9782
|
+
validateEndpoints
|
|
9728
9783
|
};
|
|
9729
9784
|
/*! Bundled license information:
|
|
9730
9785
|
|