@bulletxyz/bullet-sdk 0.33.0-rc.1 → 0.34.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 +45 -23
- package/dist/browser/index.js.map +3 -3
- package/dist/node/index.js +45 -23
- package/dist/node/index.js.map +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/client.d.ts +1 -1
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/error.d.ts +83 -17
- package/dist/types/error.d.ts.map +1 -1
- package/dist/types/websocket.d.ts.map +1 -1
- package/package.json +1 -14
package/dist/types/error.d.ts
CHANGED
|
@@ -2,17 +2,24 @@ import { SovereignError } from "@sovereign-sdk/web3";
|
|
|
2
2
|
/**
|
|
3
3
|
* Structured error details from rollup responses.
|
|
4
4
|
*
|
|
5
|
-
* Standard fields:
|
|
6
|
-
*
|
|
5
|
+
* Standard fields: domain, code, detail
|
|
6
|
+
* All other fields are dynamic and specific to each error type.
|
|
7
7
|
*/
|
|
8
8
|
export interface RollupErrorDetails {
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
/**
|
|
9
|
+
/** Error domain/category (e.g., 'risk_engine', 'account', 'order') */
|
|
10
|
+
domain: string;
|
|
11
|
+
/** Specific error code (e.g., 'stale_price', 'insufficient_margin') */
|
|
12
|
+
code: string;
|
|
13
|
+
/** Detailed error message from the rollup (thiserror Display) */
|
|
14
|
+
detail: string;
|
|
15
|
+
/**
|
|
16
|
+
* Additional dynamic fields specific to each error type.
|
|
17
|
+
*
|
|
18
|
+
* Examples:
|
|
19
|
+
* - StalePrice: id, price_kind, last_update_timestamp, current_timestamp
|
|
20
|
+
* - InsufficientMargin: address, available_margin, required_margin, margin_type
|
|
21
|
+
* - OrderNotFound: order_id, market_id, market_type
|
|
22
|
+
*/
|
|
16
23
|
[key: string]: unknown;
|
|
17
24
|
}
|
|
18
25
|
/**
|
|
@@ -28,22 +35,35 @@ export interface RollupErrorDetails {
|
|
|
28
35
|
* } catch (error) {
|
|
29
36
|
* if (isBulletError(error)) {
|
|
30
37
|
* console.log(error.code); // 'stale_price'
|
|
31
|
-
* console.log(error.
|
|
38
|
+
* console.log(error.domain); // 'risk_engine'
|
|
39
|
+
* console.log(error.message); // 'Stale price - mark 1, last_update: 0, current: 1762425013275'
|
|
40
|
+
*
|
|
41
|
+
* // Access error-specific fields via details
|
|
42
|
+
* console.log(error.details.id);
|
|
43
|
+
* console.log(error.details.price_kind);
|
|
44
|
+
* console.log(error.details.current_timestamp);
|
|
32
45
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
46
|
+
* // Type-safe error handling
|
|
47
|
+
* if (error.domain === 'account' && error.code === 'insufficient_margin') {
|
|
48
|
+
* const { available_margin, required_margin } = error.details;
|
|
49
|
+
* showDepositModal(Number(required_margin) - Number(available_margin));
|
|
35
50
|
* }
|
|
36
51
|
* }
|
|
37
52
|
* }
|
|
38
53
|
* ```
|
|
39
54
|
*/
|
|
40
55
|
export declare class BulletError extends SovereignError {
|
|
41
|
-
/**
|
|
56
|
+
/** Specific error code (e.g., 'stale_price', 'insufficient_margin') */
|
|
42
57
|
readonly code: string;
|
|
58
|
+
/** Error domain/category (e.g., 'risk_engine', 'account', 'order') */
|
|
59
|
+
readonly domain: string;
|
|
43
60
|
/** HTTP status code */
|
|
44
61
|
readonly status?: number;
|
|
45
|
-
/**
|
|
46
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Structured error details from the rollup.
|
|
64
|
+
* Contains all error-specific fields.
|
|
65
|
+
*/
|
|
66
|
+
readonly details: RollupErrorDetails;
|
|
47
67
|
/** Original error that caused this */
|
|
48
68
|
readonly cause?: Error;
|
|
49
69
|
private constructor();
|
|
@@ -63,11 +83,18 @@ export declare class BulletError extends SovereignError {
|
|
|
63
83
|
toJSON(): {
|
|
64
84
|
name: string;
|
|
65
85
|
code: string;
|
|
86
|
+
domain: string;
|
|
66
87
|
message: string;
|
|
67
88
|
status: number | undefined;
|
|
68
|
-
details: RollupErrorDetails
|
|
89
|
+
details: RollupErrorDetails;
|
|
69
90
|
stack: string | undefined;
|
|
70
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Returns a developer-friendly string representation.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* "[risk_engine:stale_price] Stale price - mark 1, last_update: 0, current: 1762425013275"
|
|
97
|
+
*/
|
|
71
98
|
toString(): string;
|
|
72
99
|
}
|
|
73
100
|
/**
|
|
@@ -77,10 +104,49 @@ export declare class BulletError extends SovereignError {
|
|
|
77
104
|
* ```typescript
|
|
78
105
|
* catch (error) {
|
|
79
106
|
* if (isBulletError(error)) {
|
|
80
|
-
* console.log(error.code, error.details);
|
|
107
|
+
* console.log(error.code, error.domain, error.details);
|
|
81
108
|
* }
|
|
82
109
|
* }
|
|
83
110
|
* ```
|
|
84
111
|
*/
|
|
85
112
|
export declare function isBulletError(error: unknown): error is BulletError;
|
|
113
|
+
/**
|
|
114
|
+
* Helper to create type-safe error handlers for specific error types.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const handleStalePrice = createErrorHandler(
|
|
119
|
+
* 'risk_engine',
|
|
120
|
+
* 'stale_price',
|
|
121
|
+
* (error) => {
|
|
122
|
+
* // Access fields via error.details
|
|
123
|
+
* console.log(`Stale price for ${error.details.id}`);
|
|
124
|
+
* console.log(`Price kind: ${error.details.price_kind}`);
|
|
125
|
+
* retryWithFreshData();
|
|
126
|
+
* }
|
|
127
|
+
* );
|
|
128
|
+
*
|
|
129
|
+
* try {
|
|
130
|
+
* await client.placeOrder(...);
|
|
131
|
+
* } catch (error) {
|
|
132
|
+
* if (isBulletError(error)) {
|
|
133
|
+
* handleStalePrice(error);
|
|
134
|
+
* }
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function createErrorHandler(domain: string, code: string, handler: (error: BulletError) => void): (error: BulletError) => boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Type guard with specific domain/code check.
|
|
141
|
+
* Useful for narrowing error types in conditional logic.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* if (isErrorType(error, 'risk_engine', 'stale_price')) {
|
|
146
|
+
* // error is BulletError with domain='risk_engine' and code='stale_price'
|
|
147
|
+
* const { id, price_kind } = error.details;
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function isErrorType(error: unknown, domain: string, code: string): error is BulletError;
|
|
86
152
|
//# sourceMappingURL=error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IAEf,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IAEb,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;;OAOG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,WAAY,SAAQ,cAAc;IAC7C,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,uBAAuB;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IAErC,sCAAsC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAEvB,OAAO;IAsBP;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW;IA8CxC;;OAEG;IACH,MAAM;;;;;;;;;IAYN;;;;;OAKG;IACH,QAAQ,IAAI,MAAM;CAGnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GACpC,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAQjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,KAAK,IAAI,WAAW,CAItB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/websocket.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/websocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,UAAU,CAAuC;IACzD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,iBAAiB,CAA+B;IACxD,OAAO,CAAC,aAAa,CAAoC;IACzD,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAK;IAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,YAAY,CAAsB;gBAE9B,GAAG,EAAE,MAAM;YAIT,OAAO;YA8CP,eAAe;IAuB7B,OAAO,CAAC,aAAa;IA+DrB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,gBAAgB;IAMjB,WAAW,CAAC,OAAO,EAAE,MAAM;IAOpB,kBAAkB,CAC9B,QAAQ,EAAE,QAAQ,GACjB,aAAa,CAAC,SAAS,CAAC;IAgBd,oBAAoB,CAAC,QAAQ,EAAE,QAAQ;CAQrD"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "git+https://github.com/zetamarkets/bullet-sdk.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.34.0-rc.0",
|
|
8
8
|
"description": "Bullet SDK",
|
|
9
9
|
"author": "@bulletxyz",
|
|
10
10
|
"license": "Apache-2.0",
|
|
@@ -64,26 +64,17 @@
|
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@biomejs/biome": "^2.3.2",
|
|
67
|
-
"@eslint/js": "^9.38.0",
|
|
68
67
|
"@jest/globals": "^30.2.0",
|
|
69
|
-
"@types/collections": "^5.1.5",
|
|
70
68
|
"@types/jest": "^30.0.0",
|
|
71
69
|
"@types/node": "^24.9.2",
|
|
72
|
-
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
73
|
-
"@typescript-eslint/parser": "^8.46.2",
|
|
74
70
|
"decimal.js": "^10.6.0",
|
|
75
71
|
"dotenv": "^17.2.3",
|
|
76
72
|
"esbuild": "^0.25.11",
|
|
77
73
|
"esbuild-jest": "^0.5.0",
|
|
78
74
|
"esbuild-register": "^3.6.0",
|
|
79
|
-
"eslint": "^9.38.0",
|
|
80
|
-
"globals": "^16.4.0",
|
|
81
75
|
"jest": "^30.2.0",
|
|
82
|
-
"ts-loader": "^9.5.4",
|
|
83
|
-
"ts-node": "^10.9.2",
|
|
84
76
|
"tsx": "^4.20.6",
|
|
85
77
|
"typescript": "^5.9.3",
|
|
86
|
-
"typescript-eslint": "^8.46.2",
|
|
87
78
|
"zod": "^4.1.12"
|
|
88
79
|
},
|
|
89
80
|
"dependencies": {
|
|
@@ -93,11 +84,7 @@
|
|
|
93
84
|
"@sovereign-sdk/types": "0.1.2",
|
|
94
85
|
"@sovereign-sdk/web3": "0.11.1",
|
|
95
86
|
"bs58": "^6.0.0",
|
|
96
|
-
"collections": "^5.1.13",
|
|
97
87
|
"eventemitter3": "^5.0.1",
|
|
98
|
-
"isows": "^1.0.7",
|
|
99
|
-
"p-queue": "^8.1.1",
|
|
100
|
-
"path": "^0.12.7",
|
|
101
88
|
"upgrade": "^1.1.0"
|
|
102
89
|
},
|
|
103
90
|
"peerDependencies": {
|