@proof-labs/trading-sdk 4.0.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/LICENSE +201 -0
- package/README.md +391 -0
- package/dist/client.d.ts +640 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1730 -0
- package/dist/client.js.map +1 -0
- package/dist/codec-adapter.d.ts +33 -0
- package/dist/codec-adapter.d.ts.map +1 -0
- package/dist/codec-adapter.js +419 -0
- package/dist/codec-adapter.js.map +1 -0
- package/dist/codec.d.ts +137 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +229 -0
- package/dist/codec.js.map +1 -0
- package/dist/crypto.d.ts +78 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +145 -0
- package/dist/crypto.js.map +1 -0
- package/dist/errors.d.ts +122 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +397 -0
- package/dist/errors.js.map +1 -0
- package/dist/governance-query.d.ts +47 -0
- package/dist/governance-query.d.ts.map +1 -0
- package/dist/governance-query.js +525 -0
- package/dist/governance-query.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.d.ts +25 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +22 -0
- package/dist/testing.js.map +1 -0
- package/dist/trigger-history.d.ts +9 -0
- package/dist/trigger-history.d.ts.map +1 -0
- package/dist/trigger-history.js +442 -0
- package/dist/trigger-history.js.map +1 -0
- package/dist/triggers.d.ts +15 -0
- package/dist/triggers.d.ts.map +1 -0
- package/dist/triggers.js +399 -0
- package/dist/triggers.js.map +1 -0
- package/dist/tx-result.d.ts +53 -0
- package/dist/tx-result.d.ts.map +1 -0
- package/dist/tx-result.js +58 -0
- package/dist/tx-result.js.map +1 -0
- package/dist/types.d.ts +2085 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +121 -0
- package/dist/types.js.map +1 -0
- package/dist/wasm/proof_trading_sdk_wasm.d.ts +98 -0
- package/dist/wasm/proof_trading_sdk_wasm.js +698 -0
- package/dist/wasm/proof_trading_sdk_wasm_bg.wasm +0 -0
- package/dist/wasm/proof_trading_sdk_wasm_bg.wasm.d.ts +19 -0
- package/dist/wasm-loader.d.ts +42 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.js +95 -0
- package/dist/wasm-loader.js.map +1 -0
- package/package.json +72 -0
package/dist/triggers.js
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
2
|
+
const U32_MAX = 0xffff_ffff;
|
|
3
|
+
export const MAX_TRIGGER_SLIPPAGE_BPS = 9_999;
|
|
4
|
+
function assertU64(name, value, nonzero = false) {
|
|
5
|
+
if (typeof value !== "bigint" || value < 0n || value > U64_MAX) {
|
|
6
|
+
throw new Error(`${name} must be an unsigned 64-bit bigint`);
|
|
7
|
+
}
|
|
8
|
+
if (nonzero && value === 0n)
|
|
9
|
+
throw new Error(`${name} must be non-zero`);
|
|
10
|
+
}
|
|
11
|
+
function assertU32(name, value) {
|
|
12
|
+
if (!Number.isInteger(value) || value < 0 || value > U32_MAX) {
|
|
13
|
+
throw new Error(`${name} must be an unsigned 32-bit integer`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function validateLimb(name, limb) {
|
|
17
|
+
assertU64(`${name}.triggerPrice`, limb.triggerPrice, true);
|
|
18
|
+
if (!Number.isInteger(limb.maxSlippageBps) ||
|
|
19
|
+
limb.maxSlippageBps < 1 ||
|
|
20
|
+
limb.maxSlippageBps > MAX_TRIGGER_SLIPPAGE_BPS) {
|
|
21
|
+
throw new Error(`${name}.maxSlippageBps must be in 1..=9999`);
|
|
22
|
+
}
|
|
23
|
+
if (limb.clientTriggerId != null) {
|
|
24
|
+
assertU64(`${name}.clientTriggerId`, limb.clientTriggerId, true);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Validate all state-independent invariants for action 0x25. */
|
|
28
|
+
export function validateSetPositionTriggers(action) {
|
|
29
|
+
assertU32("market", action.market);
|
|
30
|
+
if (!(action.owner instanceof Uint8Array) || action.owner.length !== 20) {
|
|
31
|
+
throw new Error("owner must be exactly 20 bytes");
|
|
32
|
+
}
|
|
33
|
+
assertU64("expectedPositionEpoch", action.expectedPositionEpoch, true);
|
|
34
|
+
if (action.stopLoss == null && action.takeProfit == null) {
|
|
35
|
+
throw new Error("at least one of stopLoss or takeProfit is required");
|
|
36
|
+
}
|
|
37
|
+
if (action.stopLoss != null)
|
|
38
|
+
validateLimb("stopLoss", action.stopLoss);
|
|
39
|
+
if (action.takeProfit != null)
|
|
40
|
+
validateLimb("takeProfit", action.takeProfit);
|
|
41
|
+
if (action.clientGroupId != null) {
|
|
42
|
+
assertU64("clientGroupId", action.clientGroupId, true);
|
|
43
|
+
}
|
|
44
|
+
const stopId = action.stopLoss?.clientTriggerId;
|
|
45
|
+
const takeId = action.takeProfit?.clientTriggerId;
|
|
46
|
+
if (stopId != null && takeId != null && stopId === takeId) {
|
|
47
|
+
throw new Error("stopLoss and takeProfit clientTriggerId values must differ");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Validate all state-independent invariants for action 0x26. */
|
|
51
|
+
export function validateCancelPositionTriggers(action) {
|
|
52
|
+
assertU32("market", action.market);
|
|
53
|
+
if (!(action.owner instanceof Uint8Array) || action.owner.length !== 20) {
|
|
54
|
+
throw new Error("owner must be exactly 20 bytes");
|
|
55
|
+
}
|
|
56
|
+
assertU64("expectedPositionEpoch", action.expectedPositionEpoch, true);
|
|
57
|
+
}
|
|
58
|
+
/** Validate the state-independent portion of admin action tag 0x05. */
|
|
59
|
+
export function validateSetTriggerMarketConfig(config) {
|
|
60
|
+
assertU32("market", config.market);
|
|
61
|
+
if (typeof config.enabled !== "boolean") {
|
|
62
|
+
throw new Error("enabled must be boolean");
|
|
63
|
+
}
|
|
64
|
+
if (config.expectedCurrentVersion != null) {
|
|
65
|
+
assertU64("expectedCurrentVersion", config.expectedCurrentVersion);
|
|
66
|
+
}
|
|
67
|
+
if (!Number.isInteger(config.maxTriggerSlippageBps) ||
|
|
68
|
+
config.maxTriggerSlippageBps < 0 ||
|
|
69
|
+
config.maxTriggerSlippageBps > MAX_TRIGGER_SLIPPAGE_BPS) {
|
|
70
|
+
throw new Error("maxTriggerSlippageBps must be in 0..=9999");
|
|
71
|
+
}
|
|
72
|
+
assertU64("maxMarkAgeMs", config.maxMarkAgeMs);
|
|
73
|
+
assertU64("maxFuturePublishSkewMs", config.maxFuturePublishSkewMs);
|
|
74
|
+
assertU64("maxActiveBrackets", config.maxActiveBrackets);
|
|
75
|
+
if (config.enabled &&
|
|
76
|
+
(config.maxTriggerSlippageBps === 0 ||
|
|
77
|
+
config.maxMarkAgeMs === 0n ||
|
|
78
|
+
config.maxFuturePublishSkewMs === 0n ||
|
|
79
|
+
config.maxActiveBrackets === 0n)) {
|
|
80
|
+
throw new Error("enabled trigger config requires non-zero slippage, mark-age, future-skew and bracket bounds");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function tuple(value, name, size) {
|
|
84
|
+
if (!Array.isArray(value) || value.length !== size) {
|
|
85
|
+
throw new Error(`trigger decode: ${name} must be exactly a ${size}-field tuple`);
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
function uint(value, name) {
|
|
90
|
+
if (typeof value === "bigint") {
|
|
91
|
+
if (value >= 0n && value <= U64_MAX)
|
|
92
|
+
return value;
|
|
93
|
+
}
|
|
94
|
+
else if (typeof value === "string" && /^\d+$/.test(value)) {
|
|
95
|
+
const parsed = BigInt(value);
|
|
96
|
+
if (parsed <= U64_MAX)
|
|
97
|
+
return parsed;
|
|
98
|
+
}
|
|
99
|
+
else if (typeof value === "number" &&
|
|
100
|
+
Number.isSafeInteger(value) &&
|
|
101
|
+
value >= 0) {
|
|
102
|
+
return BigInt(value);
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`trigger decode: ${name} is not an exact u64`);
|
|
105
|
+
}
|
|
106
|
+
function uint32(value, name) {
|
|
107
|
+
const n = Number(uint(value, name));
|
|
108
|
+
if (n > U32_MAX)
|
|
109
|
+
throw new Error(`trigger decode: ${name} exceeds u32`);
|
|
110
|
+
return n;
|
|
111
|
+
}
|
|
112
|
+
function bytes20(value, name) {
|
|
113
|
+
if (Array.isArray(value) &&
|
|
114
|
+
!value.every((byte) => typeof byte === "number" &&
|
|
115
|
+
Number.isInteger(byte) &&
|
|
116
|
+
byte >= 0 &&
|
|
117
|
+
byte <= 255)) {
|
|
118
|
+
throw new Error(`trigger decode: ${name} contains a non-byte value`);
|
|
119
|
+
}
|
|
120
|
+
const bytes = value instanceof Uint8Array
|
|
121
|
+
? value
|
|
122
|
+
: Array.isArray(value)
|
|
123
|
+
? Uint8Array.from(value)
|
|
124
|
+
: null;
|
|
125
|
+
if (bytes === null || bytes.length !== 20) {
|
|
126
|
+
throw new Error(`trigger decode: ${name} must be exactly 20 bytes`);
|
|
127
|
+
}
|
|
128
|
+
return bytes;
|
|
129
|
+
}
|
|
130
|
+
const KINDS = new Set(["StopLoss", "TakeProfit"]);
|
|
131
|
+
const STATES = new Set([
|
|
132
|
+
"Armed",
|
|
133
|
+
"Filled",
|
|
134
|
+
"Partial",
|
|
135
|
+
"NoFill",
|
|
136
|
+
"Rejected",
|
|
137
|
+
"Cancelled",
|
|
138
|
+
"Invalidated",
|
|
139
|
+
]);
|
|
140
|
+
const REASONS = new Set([
|
|
141
|
+
"PositionClosed",
|
|
142
|
+
"PositionEpochChanged",
|
|
143
|
+
"PositionSideChanged",
|
|
144
|
+
"BelowMaintenance",
|
|
145
|
+
"IndeterminateAccount",
|
|
146
|
+
"MarketDisabled",
|
|
147
|
+
"MarkUnavailable",
|
|
148
|
+
"MarkStale",
|
|
149
|
+
"MarkFutureDated",
|
|
150
|
+
"NoEligibleLiquidity",
|
|
151
|
+
"SelfTradePrevention",
|
|
152
|
+
"WorkLimitReached",
|
|
153
|
+
"ExecutionRejected",
|
|
154
|
+
]);
|
|
155
|
+
function exactEnum(value, allowed, name) {
|
|
156
|
+
if (typeof value !== "string" || !allowed.has(value)) {
|
|
157
|
+
throw new Error(`trigger decode: unknown ${name} ${String(value)}`);
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
function decodeEvaluation(value) {
|
|
162
|
+
if (value == null)
|
|
163
|
+
return null;
|
|
164
|
+
const row = tuple(value, "TriggerEvaluation", 7);
|
|
165
|
+
const requestedQuantity = uint(row[3], "evaluation.requested_quantity");
|
|
166
|
+
const filledQuantity = uint(row[4], "evaluation.filled_quantity");
|
|
167
|
+
const residualQuantity = uint(row[5], "evaluation.residual_quantity");
|
|
168
|
+
if (filledQuantity + residualQuantity !== requestedQuantity) {
|
|
169
|
+
throw new Error("trigger decode: evaluation quantities do not conserve");
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
height: uint(row[0], "evaluation.height"),
|
|
173
|
+
frozenMark: uint(row[1], "evaluation.frozen_mark"),
|
|
174
|
+
limitPrice: row[2] == null ? null : uint(row[2], "evaluation.limit_price"),
|
|
175
|
+
requestedQuantity,
|
|
176
|
+
filledQuantity,
|
|
177
|
+
residualQuantity,
|
|
178
|
+
reason: row[6] == null
|
|
179
|
+
? null
|
|
180
|
+
: exactEnum(row[6], REASONS, "TriggerOutcomeReason"),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function decodeStoredLimb(value) {
|
|
184
|
+
if (value == null)
|
|
185
|
+
return null;
|
|
186
|
+
const row = tuple(value, "StoredTriggerLimb", 7);
|
|
187
|
+
const limbId = uint(row[0], "limb_id");
|
|
188
|
+
const triggerPrice = uint(row[2], "trigger_price");
|
|
189
|
+
if (limbId === 0n || triggerPrice === 0n) {
|
|
190
|
+
throw new Error("trigger decode: limb id and trigger price must be non-zero");
|
|
191
|
+
}
|
|
192
|
+
const maxSlippageBps = uint32(row[3], "max_slippage_bps");
|
|
193
|
+
if (maxSlippageBps < 1 || maxSlippageBps > MAX_TRIGGER_SLIPPAGE_BPS) {
|
|
194
|
+
throw new Error("trigger decode: limb slippage is outside 1..=9999");
|
|
195
|
+
}
|
|
196
|
+
const clientTriggerId = row[4] == null ? null : uint(row[4], "client_trigger_id");
|
|
197
|
+
if (clientTriggerId === 0n) {
|
|
198
|
+
throw new Error("trigger decode: client trigger id must be non-zero");
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
limbId,
|
|
202
|
+
kind: exactEnum(row[1], KINDS, "TriggerKind"),
|
|
203
|
+
triggerPrice,
|
|
204
|
+
maxSlippageBps,
|
|
205
|
+
clientTriggerId,
|
|
206
|
+
state: exactEnum(row[5], STATES, "TriggerLimbState"),
|
|
207
|
+
lastEvaluation: decodeEvaluation(row[6]),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function decodeConfig(value) {
|
|
211
|
+
if (value == null)
|
|
212
|
+
return null;
|
|
213
|
+
const row = tuple(value, "TriggerMarketConfig", 6);
|
|
214
|
+
if (typeof row[1] !== "boolean") {
|
|
215
|
+
throw new Error("trigger decode: config.enabled is not boolean");
|
|
216
|
+
}
|
|
217
|
+
const version = uint(row[0], "config.version");
|
|
218
|
+
if (version === 0n)
|
|
219
|
+
throw new Error("trigger decode: config version is zero");
|
|
220
|
+
const config = {
|
|
221
|
+
version,
|
|
222
|
+
enabled: row[1],
|
|
223
|
+
maxTriggerSlippageBps: uint32(row[2], "config.max_trigger_slippage_bps"),
|
|
224
|
+
maxMarkAgeMs: uint(row[3], "config.max_mark_age_ms"),
|
|
225
|
+
maxFuturePublishSkewMs: uint(row[4], "config.max_future_publish_skew_ms"),
|
|
226
|
+
maxActiveBrackets: uint(row[5], "config.max_active_brackets"),
|
|
227
|
+
};
|
|
228
|
+
validateSetTriggerMarketConfig({
|
|
229
|
+
market: 0,
|
|
230
|
+
expectedCurrentVersion: null,
|
|
231
|
+
enabled: config.enabled,
|
|
232
|
+
maxTriggerSlippageBps: config.maxTriggerSlippageBps,
|
|
233
|
+
maxMarkAgeMs: config.maxMarkAgeMs,
|
|
234
|
+
maxFuturePublishSkewMs: config.maxFuturePublishSkewMs,
|
|
235
|
+
maxActiveBrackets: config.maxActiveBrackets,
|
|
236
|
+
});
|
|
237
|
+
return config;
|
|
238
|
+
}
|
|
239
|
+
function decodeConfigState(value) {
|
|
240
|
+
const row = tuple(value, "TriggerMarketConfigState", 2);
|
|
241
|
+
const current = decodeConfig(row[0]);
|
|
242
|
+
let pending = null;
|
|
243
|
+
if (row[1] != null) {
|
|
244
|
+
const pendingRow = tuple(row[1], "PendingTriggerMarketConfig", 3);
|
|
245
|
+
const config = decodeConfig(pendingRow[0]);
|
|
246
|
+
if (config === null) {
|
|
247
|
+
throw new Error("trigger decode: pending config is null");
|
|
248
|
+
}
|
|
249
|
+
const acceptedHeight = uint(pendingRow[1], "pending.accepted_height");
|
|
250
|
+
const effectiveHeight = uint(pendingRow[2], "pending.effective_height");
|
|
251
|
+
if (acceptedHeight === 0n ||
|
|
252
|
+
acceptedHeight === U64_MAX ||
|
|
253
|
+
effectiveHeight !== acceptedHeight + 1n) {
|
|
254
|
+
throw new Error("trigger decode: invalid pending effective height");
|
|
255
|
+
}
|
|
256
|
+
const expectedVersion = current === null ? 1n : current.version + 1n;
|
|
257
|
+
if (config.version !== expectedVersion) {
|
|
258
|
+
throw new Error("trigger decode: pending config version is not next");
|
|
259
|
+
}
|
|
260
|
+
pending = { config, acceptedHeight, effectiveHeight };
|
|
261
|
+
}
|
|
262
|
+
if (current === null && pending === null) {
|
|
263
|
+
throw new Error("trigger decode: empty trigger market config state");
|
|
264
|
+
}
|
|
265
|
+
return { current, pending };
|
|
266
|
+
}
|
|
267
|
+
/** Decode the canonical, market-sorted trigger-policy registry. */
|
|
268
|
+
export function decodeTriggerMarketConfigInfos(value) {
|
|
269
|
+
if (!Array.isArray(value)) {
|
|
270
|
+
throw new Error("trigger decode: market configs response is not an array");
|
|
271
|
+
}
|
|
272
|
+
let previousMarket = -1;
|
|
273
|
+
return value.map((entry) => {
|
|
274
|
+
const row = tuple(entry, "TriggerMarketConfigInfo", 2);
|
|
275
|
+
const market = uint32(row[0], "market");
|
|
276
|
+
if (market <= previousMarket) {
|
|
277
|
+
throw new Error("trigger decode: market configs are not strictly market-sorted");
|
|
278
|
+
}
|
|
279
|
+
previousMarket = market;
|
|
280
|
+
return { market, state: decodeConfigState(row[1]) };
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function decodeAvailability(value) {
|
|
284
|
+
const simple = new Set([
|
|
285
|
+
"Available",
|
|
286
|
+
"TriggerActionsInactive",
|
|
287
|
+
"PendingActivation",
|
|
288
|
+
"MigrationIncomplete",
|
|
289
|
+
"ConfigurationMissing",
|
|
290
|
+
"MarketDisabled",
|
|
291
|
+
]);
|
|
292
|
+
if (typeof value === "string" && simple.has(value)) {
|
|
293
|
+
return { kind: value };
|
|
294
|
+
}
|
|
295
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
296
|
+
const reason = value.Deferred;
|
|
297
|
+
if (reason !== undefined) {
|
|
298
|
+
return {
|
|
299
|
+
kind: "Deferred",
|
|
300
|
+
reason: exactEnum(reason, REASONS, "TriggerOutcomeReason"),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
throw new Error("trigger decode: unknown TriggerEffectiveAvailability");
|
|
305
|
+
}
|
|
306
|
+
function decodeBracket(value) {
|
|
307
|
+
const row = tuple(value, "PositionTriggerBracket", 10);
|
|
308
|
+
const side = row[4];
|
|
309
|
+
if (side !== "Buy" && side !== "Sell") {
|
|
310
|
+
throw new Error(`trigger decode: unknown position side ${String(side)}`);
|
|
311
|
+
}
|
|
312
|
+
const groupId = uint(row[0], "group_id");
|
|
313
|
+
const positionEpoch = uint(row[3], "position_epoch");
|
|
314
|
+
const acceptedHeight = uint(row[5], "accepted_height");
|
|
315
|
+
const activeFromHeight = uint(row[6], "active_from_height");
|
|
316
|
+
if (groupId === 0n || positionEpoch === 0n || acceptedHeight === 0n) {
|
|
317
|
+
throw new Error("trigger decode: bracket ids/heights must be non-zero");
|
|
318
|
+
}
|
|
319
|
+
if (activeFromHeight !== acceptedHeight + 1n) {
|
|
320
|
+
throw new Error("trigger decode: invalid active_from_height");
|
|
321
|
+
}
|
|
322
|
+
const stopLoss = decodeStoredLimb(row[8]);
|
|
323
|
+
const takeProfit = decodeStoredLimb(row[9]);
|
|
324
|
+
if (stopLoss === null && takeProfit === null) {
|
|
325
|
+
throw new Error("trigger decode: bracket has no limbs");
|
|
326
|
+
}
|
|
327
|
+
if (stopLoss !== null && stopLoss.kind !== "StopLoss") {
|
|
328
|
+
throw new Error("trigger decode: stopLoss has wrong kind");
|
|
329
|
+
}
|
|
330
|
+
if (takeProfit !== null && takeProfit.kind !== "TakeProfit") {
|
|
331
|
+
throw new Error("trigger decode: takeProfit has wrong kind");
|
|
332
|
+
}
|
|
333
|
+
if (stopLoss !== null &&
|
|
334
|
+
takeProfit !== null &&
|
|
335
|
+
(stopLoss.limbId === takeProfit.limbId ||
|
|
336
|
+
(stopLoss.clientTriggerId !== null &&
|
|
337
|
+
stopLoss.clientTriggerId === takeProfit.clientTriggerId))) {
|
|
338
|
+
throw new Error("trigger decode: bracket has duplicate limb identity");
|
|
339
|
+
}
|
|
340
|
+
const clientGroupId = row[7] == null ? null : uint(row[7], "client_group_id");
|
|
341
|
+
if (clientGroupId === 0n) {
|
|
342
|
+
throw new Error("trigger decode: client group id must be non-zero");
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
groupId,
|
|
346
|
+
owner: bytes20(row[1], "owner"),
|
|
347
|
+
market: uint32(row[2], "market"),
|
|
348
|
+
positionEpoch,
|
|
349
|
+
positionSide: side,
|
|
350
|
+
acceptedHeight,
|
|
351
|
+
activeFromHeight,
|
|
352
|
+
clientGroupId,
|
|
353
|
+
stopLoss,
|
|
354
|
+
takeProfit,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
/** Decode the engine's positional `Vec<PositionTriggerInfo>` response. */
|
|
358
|
+
export function decodePositionTriggerInfos(value) {
|
|
359
|
+
if (!Array.isArray(value)) {
|
|
360
|
+
throw new Error("trigger decode: response is not an array");
|
|
361
|
+
}
|
|
362
|
+
return value.map((entry) => {
|
|
363
|
+
const row = tuple(entry, "PositionTriggerInfo", 3);
|
|
364
|
+
return {
|
|
365
|
+
bracket: decodeBracket(row[0]),
|
|
366
|
+
marketConfig: decodeConfig(row[1]),
|
|
367
|
+
availability: decodeAvailability(row[2]),
|
|
368
|
+
};
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/** Parse trigger-status JSON without routing 64-bit heights through Number. */
|
|
372
|
+
export function decodeTriggerStatusJson(text) {
|
|
373
|
+
const protectedText = text.replace(/("(?:finalized_height|admission_height)"\s*:\s*)(-?\d+)/g, '$1"$2"');
|
|
374
|
+
let value;
|
|
375
|
+
try {
|
|
376
|
+
value = JSON.parse(protectedText);
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
throw new Error("trigger status decode: malformed JSON");
|
|
380
|
+
}
|
|
381
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
382
|
+
throw new Error("trigger status decode: expected an object");
|
|
383
|
+
}
|
|
384
|
+
const row = value;
|
|
385
|
+
if (typeof row.actions_active !== "boolean") {
|
|
386
|
+
throw new Error("trigger status decode: actions_active is not boolean");
|
|
387
|
+
}
|
|
388
|
+
const finalizedHeight = uint(row.finalized_height, "finalized_height");
|
|
389
|
+
const admissionHeight = uint(row.admission_height, "admission_height");
|
|
390
|
+
if (admissionHeight !== finalizedHeight + 1n) {
|
|
391
|
+
throw new Error("trigger status decode: admission height is not next height");
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
finalizedHeight,
|
|
395
|
+
admissionHeight,
|
|
396
|
+
actionsActive: row.actions_active,
|
|
397
|
+
};
|
|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;AACL,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAChC,0DAA0D,EAC1D,QAAQ,CACT,CAAC;IACF,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,IAAI,OAAO,GAAG,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IACvE,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;IACvE,IAAI,eAAe,KAAK,eAAe,GAAG,EAAE,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IACD,OAAO;QACL,eAAe;QACf,eAAe;QACf,aAAa,EAAE,GAAG,CAAC,cAAc;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { TxEvent, TxResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Constructors for {@link TxResult}. Centralising them keeps the `ok` /
|
|
4
|
+
* `outcome` / `error` tags consistent across every submission path (gateway,
|
|
5
|
+
* CometBFT, inclusion polling) and makes the classification unit-testable
|
|
6
|
+
* without a live node — see `tx-result.test.ts`.
|
|
7
|
+
*
|
|
8
|
+
* The numeric `code` field continues to carry 0 for success, engine
|
|
9
|
+
* `ExecError` values 1..53/255 (codes 51-53 added in SDK 3.0.0),
|
|
10
|
+
* synthesized HTTP 401/429/413/500/1, or `-1` for timeout. The `outcome` tag
|
|
11
|
+
* lets callers tell an engine rejection apart from a transport failure that
|
|
12
|
+
* happens to reuse a small integer `code`.
|
|
13
|
+
*/
|
|
14
|
+
/** Optional fields shared by success and post-execution error results. */
|
|
15
|
+
export interface TxResultBody {
|
|
16
|
+
/** Transaction hash (hex). Defaults to `""` when the tx never got one. */
|
|
17
|
+
hash?: string;
|
|
18
|
+
/** Block height at inclusion, when known. */
|
|
19
|
+
height?: number;
|
|
20
|
+
/** Human-readable log line. */
|
|
21
|
+
log?: string;
|
|
22
|
+
/** ABCI events emitted by the tx. */
|
|
23
|
+
events?: TxEvent[];
|
|
24
|
+
}
|
|
25
|
+
/** CheckTx accepted the transaction (`code === 0`). */
|
|
26
|
+
export declare function txOk(body?: TxResultBody): TxResult;
|
|
27
|
+
/**
|
|
28
|
+
* The engine rejected the transaction with an `ExecError` `code`. The decoded
|
|
29
|
+
* `{ name, description }` is attached automatically so callers do not have to
|
|
30
|
+
* call `decodeExecError` themselves; it is `null` for codes not in the table.
|
|
31
|
+
*/
|
|
32
|
+
export declare function txEngineError(code: number, body?: TxResultBody): TxResult;
|
|
33
|
+
/**
|
|
34
|
+
* A gateway / HTTP-level failure (auth, rate-limit, oversized body, 5xx,
|
|
35
|
+
* non-JSON body). `code` is the synthesized HTTP status — NOT an engine code,
|
|
36
|
+
* which is exactly why `outcome` is `"transport"`: callers must not read `code`
|
|
37
|
+
* as an `ExecError` here.
|
|
38
|
+
*/
|
|
39
|
+
export declare function txTransportError(code: number, log: string, hash?: string): TxResult;
|
|
40
|
+
/**
|
|
41
|
+
* No final chain verdict is available yet (`code === -1`). This covers both a
|
|
42
|
+
* hash-only ambiguous gateway response and inclusion polling that expired; the
|
|
43
|
+
* transaction may still commit and should be reconciled by `hash`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function txTimeout(hash: string, log: string): TxResult;
|
|
46
|
+
/**
|
|
47
|
+
* Classify a raw status code that came from an *executed* transaction (a
|
|
48
|
+
* CheckTx result or a `/v1/tx` poll): `0` → success, anything else → engine
|
|
49
|
+
* error. Do NOT use this for transport failures — their HTTP status must be
|
|
50
|
+
* tagged with {@link txTransportError} so it is not mistaken for an engine code.
|
|
51
|
+
*/
|
|
52
|
+
export declare function txFromEngineCode(code: number, body?: TxResultBody): TxResult;
|
|
53
|
+
//# sourceMappingURL=tx-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx-result.d.ts","sourceRoot":"","sources":["../src/tx-result.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;;;;;;GAWG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,YAAY;IAC3B,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+BAA+B;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED,uDAAuD;AACvD,wBAAgB,IAAI,CAAC,IAAI,GAAE,YAAiB,GAAG,QAAQ,CAWtD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,QAAQ,CAW7E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,IAAI,SAAK,GACR,QAAQ,CAEV;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,QAAQ,CAE7D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,YAAiB,GACtB,QAAQ,CAEV"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { decodeExecError } from "./errors.js";
|
|
2
|
+
/** CheckTx accepted the transaction (`code === 0`). */
|
|
3
|
+
export function txOk(body = {}) {
|
|
4
|
+
return {
|
|
5
|
+
ok: true,
|
|
6
|
+
outcome: "ok",
|
|
7
|
+
code: 0,
|
|
8
|
+
error: null,
|
|
9
|
+
hash: body.hash ?? "",
|
|
10
|
+
height: body.height,
|
|
11
|
+
log: body.log,
|
|
12
|
+
events: body.events,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The engine rejected the transaction with an `ExecError` `code`. The decoded
|
|
17
|
+
* `{ name, description }` is attached automatically so callers do not have to
|
|
18
|
+
* call `decodeExecError` themselves; it is `null` for codes not in the table.
|
|
19
|
+
*/
|
|
20
|
+
export function txEngineError(code, body = {}) {
|
|
21
|
+
return {
|
|
22
|
+
ok: false,
|
|
23
|
+
outcome: "engine",
|
|
24
|
+
code,
|
|
25
|
+
error: decodeExecError(code, body.log),
|
|
26
|
+
hash: body.hash ?? "",
|
|
27
|
+
height: body.height,
|
|
28
|
+
log: body.log,
|
|
29
|
+
events: body.events,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A gateway / HTTP-level failure (auth, rate-limit, oversized body, 5xx,
|
|
34
|
+
* non-JSON body). `code` is the synthesized HTTP status — NOT an engine code,
|
|
35
|
+
* which is exactly why `outcome` is `"transport"`: callers must not read `code`
|
|
36
|
+
* as an `ExecError` here.
|
|
37
|
+
*/
|
|
38
|
+
export function txTransportError(code, log, hash = "") {
|
|
39
|
+
return { ok: false, outcome: "transport", code, error: null, hash, log };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* No final chain verdict is available yet (`code === -1`). This covers both a
|
|
43
|
+
* hash-only ambiguous gateway response and inclusion polling that expired; the
|
|
44
|
+
* transaction may still commit and should be reconciled by `hash`.
|
|
45
|
+
*/
|
|
46
|
+
export function txTimeout(hash, log) {
|
|
47
|
+
return { ok: false, outcome: "timeout", code: -1, error: null, hash, log };
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Classify a raw status code that came from an *executed* transaction (a
|
|
51
|
+
* CheckTx result or a `/v1/tx` poll): `0` → success, anything else → engine
|
|
52
|
+
* error. Do NOT use this for transport failures — their HTTP status must be
|
|
53
|
+
* tagged with {@link txTransportError} so it is not mistaken for an engine code.
|
|
54
|
+
*/
|
|
55
|
+
export function txFromEngineCode(code, body = {}) {
|
|
56
|
+
return code === 0 ? txOk(body) : txEngineError(code, body);
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=tx-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx-result.js","sourceRoot":"","sources":["../src/tx-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA4B9C,uDAAuD;AACvD,MAAM,UAAU,IAAI,CAAC,OAAqB,EAAE;IAC1C,OAAO;QACL,EAAE,EAAE,IAAI;QACR,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE;QACrB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAAqB,EAAE;IACjE,OAAO;QACL,EAAE,EAAE,KAAK;QACT,OAAO,EAAE,QAAQ;QACj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