@pod-network/trade-sdk 0.1.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.
Files changed (102) hide show
  1. package/README.md +113 -0
  2. package/dist/client.d.ts +93 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +168 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/codec/decode.d.ts +22 -0
  7. package/dist/codec/decode.d.ts.map +1 -0
  8. package/dist/codec/decode.js +251 -0
  9. package/dist/codec/decode.js.map +1 -0
  10. package/dist/codec/fixed.d.ts +11 -0
  11. package/dist/codec/fixed.d.ts.map +1 -0
  12. package/dist/codec/fixed.js +37 -0
  13. package/dist/codec/fixed.js.map +1 -0
  14. package/dist/codec/resolution.d.ts +14 -0
  15. package/dist/codec/resolution.d.ts.map +1 -0
  16. package/dist/codec/resolution.js +35 -0
  17. package/dist/codec/resolution.js.map +1 -0
  18. package/dist/codec/units.d.ts +35 -0
  19. package/dist/codec/units.d.ts.map +1 -0
  20. package/dist/codec/units.js +86 -0
  21. package/dist/codec/units.js.map +1 -0
  22. package/dist/datafeed.d.ts +4 -0
  23. package/dist/datafeed.d.ts.map +1 -0
  24. package/dist/datafeed.js +73 -0
  25. package/dist/datafeed.js.map +1 -0
  26. package/dist/index.d.ts +20 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +19 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/stores/resource.d.ts +50 -0
  31. package/dist/stores/resource.d.ts.map +1 -0
  32. package/dist/stores/resource.js +154 -0
  33. package/dist/stores/resource.js.map +1 -0
  34. package/dist/sync/account-metrics.d.ts +26 -0
  35. package/dist/sync/account-metrics.d.ts.map +1 -0
  36. package/dist/sync/account-metrics.js +41 -0
  37. package/dist/sync/account-metrics.js.map +1 -0
  38. package/dist/sync/candles.d.ts +68 -0
  39. package/dist/sync/candles.d.ts.map +1 -0
  40. package/dist/sync/candles.js +318 -0
  41. package/dist/sync/candles.js.map +1 -0
  42. package/dist/sync/order-preview.d.ts +74 -0
  43. package/dist/sync/order-preview.d.ts.map +1 -0
  44. package/dist/sync/order-preview.js +86 -0
  45. package/dist/sync/order-preview.js.map +1 -0
  46. package/dist/sync/orders.d.ts +49 -0
  47. package/dist/sync/orders.d.ts.map +1 -0
  48. package/dist/sync/orders.js +210 -0
  49. package/dist/sync/orders.js.map +1 -0
  50. package/dist/sync/positions-live.d.ts +3 -0
  51. package/dist/sync/positions-live.d.ts.map +1 -0
  52. package/dist/sync/positions-live.js +86 -0
  53. package/dist/sync/positions-live.js.map +1 -0
  54. package/dist/sync/sources.d.ts +40 -0
  55. package/dist/sync/sources.d.ts.map +1 -0
  56. package/dist/sync/sources.js +197 -0
  57. package/dist/sync/sources.js.map +1 -0
  58. package/dist/transport/rest.d.ts +83 -0
  59. package/dist/transport/rest.d.ts.map +1 -0
  60. package/dist/transport/rest.js +146 -0
  61. package/dist/transport/rest.js.map +1 -0
  62. package/dist/transport/ws.d.ts +60 -0
  63. package/dist/transport/ws.d.ts.map +1 -0
  64. package/dist/transport/ws.js +235 -0
  65. package/dist/transport/ws.js.map +1 -0
  66. package/dist/types/public.d.ts +292 -0
  67. package/dist/types/public.d.ts.map +1 -0
  68. package/dist/types/public.js +4 -0
  69. package/dist/types/public.js.map +1 -0
  70. package/dist/types/wire.d.ts +283 -0
  71. package/dist/types/wire.d.ts.map +1 -0
  72. package/dist/types/wire.js +6 -0
  73. package/dist/types/wire.js.map +1 -0
  74. package/dist/write/delegation.d.ts +54 -0
  75. package/dist/write/delegation.d.ts.map +1 -0
  76. package/dist/write/delegation.js +81 -0
  77. package/dist/write/delegation.js.map +1 -0
  78. package/dist/write/index.d.ts +261 -0
  79. package/dist/write/index.d.ts.map +1 -0
  80. package/dist/write/index.js +428 -0
  81. package/dist/write/index.js.map +1 -0
  82. package/package.json +43 -0
  83. package/src/client.ts +229 -0
  84. package/src/codec/decode.ts +277 -0
  85. package/src/codec/fixed.ts +41 -0
  86. package/src/codec/resolution.ts +39 -0
  87. package/src/codec/units.ts +100 -0
  88. package/src/datafeed.ts +94 -0
  89. package/src/index.ts +49 -0
  90. package/src/stores/resource.ts +172 -0
  91. package/src/sync/account-metrics.ts +71 -0
  92. package/src/sync/candles.ts +326 -0
  93. package/src/sync/order-preview.ts +152 -0
  94. package/src/sync/orders.ts +205 -0
  95. package/src/sync/positions-live.ts +102 -0
  96. package/src/sync/sources.ts +239 -0
  97. package/src/transport/rest.ts +213 -0
  98. package/src/transport/ws.ts +255 -0
  99. package/src/types/public.ts +335 -0
  100. package/src/types/wire.ts +301 -0
  101. package/src/write/delegation.ts +113 -0
  102. package/src/write/index.ts +642 -0
@@ -0,0 +1,428 @@
1
+ // Write helpers: build unsigned CLOB transactions and derive order ids. These
2
+ // are pure encoding — no wallet, no key, no nonce ownership. The consumer signs
3
+ // + broadcasts the returned request with whatever wallet it has
4
+ // (walletClient.sendTransaction / eth_sendTransaction / Privy).
5
+ //
6
+ // Two deliberate exceptions hold keys, both scoped to this `/write` entry so
7
+ // read-only consumers never bundle signing code:
8
+ // - `mint` (below): the faucet is gas-exempt and signer-irrelevant, so it
9
+ // signs with a one-shot throwaway key.
10
+ // - `createDelegatedWallet` (./delegation.js): custody of the ephemeral
11
+ // trading key, closed over — see the invariant there.
12
+ import { decodeAbiParameters, encodeAbiParameters, encodeFunctionData, keccak256, parseAbi } from "viem";
13
+ import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
14
+ /** The CLOB precompile (chain id 1293 / 0x50d). */
15
+ export const CLOB_ADDRESS = "0x50d0000000000000000000000000000000000002";
16
+ const CLOB_ABI = parseAbi([
17
+ "function submitOrder(bytes32 orderbookId, int256 size, uint256 price, uint8 orderType, uint128 deadline, uint128 ttl, bool reduceOnly, bool ioc)",
18
+ "function cancel(bytes32 orderbookId, bytes32 canceledOrder, uint128 deadline)",
19
+ "function update(bytes32 orderbookId, bytes32 updatedOrder, uint256 newSize, uint256 newPrice, address token, uint128 deadline)",
20
+ // TriggerType { TakeProfit=0, StopLoss=1 } ; TriggerGrouping { None=0, Position=1 }
21
+ "function submitTrigger(bytes32 orderbookId, int256 size, uint256 limitPrice, uint256 triggerPrice, uint8 triggerType, uint8 grouping, uint128 deadline, uint128 ttl, bool reduceOnly, bool ioc)",
22
+ "function cancelTrigger(bytes32 orderbookId, bytes32 triggerOrder, uint128 deadline)",
23
+ "function updateTrigger(bytes32 orderbookId, bytes32 triggerOrder, int256 newSize, uint256 newLimitPrice, uint256 newTriggerPrice, uint128 deadline)",
24
+ "function submitBatch(bytes[] inner)",
25
+ ]);
26
+ /** ~10 years in microseconds — default far-future expiry for resting orders. */
27
+ const FAR_US = 10n * 365n * 24n * 3600n * 1000000n;
28
+ /** Floor a price to a multiple of the tick. */
29
+ export function alignPrice(price, tick) {
30
+ return tick > 0n ? (price / tick) * tick : price;
31
+ }
32
+ /** Floor a microsecond timestamp to a multiple of the auction interval. */
33
+ export function alignDeadline(us, intervalUs) {
34
+ return intervalUs > 0n ? (us / intervalUs) * intervalUs : us;
35
+ }
36
+ function us(ms, fallback) {
37
+ return ms === undefined ? fallback : BigInt(Math.trunc(ms)) * 1000n;
38
+ }
39
+ export function buildSubmitOrder(p) {
40
+ const nowUs = BigInt(Date.now()) * 1000n;
41
+ const signedSize = p.side === "sell" ? -p.size : p.size;
42
+ const price = p.tickPrecision ? alignPrice(p.price, p.tickPrecision) : p.price;
43
+ const interval = p.auctionIntervalUs ? BigInt(p.auctionIntervalUs) : 0n;
44
+ const deadline = alignDeadline(us(p.deadline, nowUs + FAR_US), interval);
45
+ const ttl = alignDeadline(us(p.ttl, nowUs + FAR_US + 30n * 24n * 3600n * 1000000n), interval);
46
+ const data = encodeFunctionData({
47
+ abi: CLOB_ABI,
48
+ functionName: "submitOrder",
49
+ args: [
50
+ p.orderbookId,
51
+ signedSize,
52
+ price,
53
+ p.orderType === "market" ? 1 : 0, // OrderType { Limit=0, Market=1 }
54
+ deadline,
55
+ ttl,
56
+ p.reduceOnly ?? false,
57
+ // A market order must not outlive its batch — the CLOB rejects a non-IOC
58
+ // market order outright (`validate_order_shape`, trading/src/book.rs), so
59
+ // default it on rather than making every caller remember.
60
+ p.ioc ?? p.orderType === "market",
61
+ ],
62
+ });
63
+ return { to: CLOB_ADDRESS, data, value: 0n, type: "eip1559", maxPriorityFeePerGas: 0n, gas: 1000000n };
64
+ }
65
+ export function buildCancelOrder(orderbookId, orderId, opts) {
66
+ const nowUs = BigInt(Date.now()) * 1000n;
67
+ const interval = opts?.auctionIntervalUs ? BigInt(opts.auctionIntervalUs) : 0n;
68
+ const deadline = alignDeadline(us(opts?.deadline, nowUs + FAR_US), interval);
69
+ const data = encodeFunctionData({
70
+ abi: CLOB_ABI,
71
+ functionName: "cancel",
72
+ args: [orderbookId, orderId, deadline],
73
+ });
74
+ return { to: CLOB_ADDRESS, data, value: 0n, type: "eip1559", maxPriorityFeePerGas: 0n, gas: 1000000n };
75
+ }
76
+ // --- broadcasting ---
77
+ //
78
+ // Signing stays with the consumer's wallet (viem / Privy / MetaMask). What IS
79
+ // pod-specific — and worth centralizing — is how a reverted CLOB tx surfaces:
80
+ // the CLOB validates orders only on execution, so a high-level send returns
81
+ // "execution reverted for an unknown reason" with the revert data dropped. We
82
+ // broadcast the already-signed tx with a raw eth_sendRawTransaction (which
83
+ // preserves the Solidity `Error(string)` payload) and decode the real message.
84
+ /** Solidity `Error(string)` selector — `bytes4(keccak256("Error(string)"))`. */
85
+ const ERROR_SELECTOR = "0x08c379a0";
86
+ /** A reverted pod transaction, carrying the decoded CLOB reason. */
87
+ export class PodTxRevertError extends Error {
88
+ reason;
89
+ data;
90
+ constructor(reason, data) {
91
+ super(reason);
92
+ this.reason = reason;
93
+ this.data = data;
94
+ this.name = "PodTxRevertError";
95
+ }
96
+ }
97
+ /**
98
+ * Decode a Solidity `Error(string)` revert payload into its message (e.g.
99
+ * "Deadline is not aligned to auction interval"). Returns undefined when `data`
100
+ * isn't an `Error(string)` payload — use this directly if you broadcast through
101
+ * your own provider and just want to translate the revert data.
102
+ */
103
+ export function decodeRevertReason(data) {
104
+ if (!data || !data.startsWith(ERROR_SELECTOR))
105
+ return undefined;
106
+ try {
107
+ return decodeAbiParameters([{ type: "string" }], `0x${data.slice(10)}`)[0];
108
+ }
109
+ catch {
110
+ return undefined;
111
+ }
112
+ }
113
+ /**
114
+ * Broadcast a SIGNED, serialized transaction via raw `eth_sendRawTransaction`
115
+ * and return its hash, throwing a {@link PodTxRevertError} with the decoded CLOB
116
+ * reason on revert. Transport-only — the consumer signs with its own wallet
117
+ * (`walletClient.signTransaction(...)`), then hands the serialized tx here.
118
+ */
119
+ export async function sendRawTransaction(rpcUrl, signedTx, opts) {
120
+ const doFetch = opts?.fetch ?? fetch;
121
+ const res = await doFetch(rpcUrl, {
122
+ method: "POST",
123
+ headers: { "content-type": "application/json" },
124
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_sendRawTransaction", params: [signedTx] }),
125
+ });
126
+ const json = (await res.json());
127
+ if (json.error) {
128
+ const reason = decodeRevertReason(json.error.data) ?? json.error.message ?? "transaction failed";
129
+ throw new PodTxRevertError(reason, json.error.data);
130
+ }
131
+ return json.result;
132
+ }
133
+ /**
134
+ * Amend a resting order's price and/or size in place via the CLOB's native
135
+ * `update` (no cancel+resubmit, so the order keeps its id and queue identity).
136
+ * Aligns price to the tick and deadline to the auction interval, like
137
+ * {@link buildSubmitOrder}.
138
+ */
139
+ export function buildUpdateOrder(p) {
140
+ const nowUs = BigInt(Date.now()) * 1000n;
141
+ const price = p.tickPrecision ? alignPrice(p.price, p.tickPrecision) : p.price;
142
+ const size = p.size < 0n ? -p.size : p.size; // contract takes an unsigned magnitude
143
+ const interval = p.auctionIntervalUs ? BigInt(p.auctionIntervalUs) : 0n;
144
+ const deadline = alignDeadline(us(p.deadline, nowUs + FAR_US), interval);
145
+ const data = encodeFunctionData({
146
+ abi: CLOB_ABI,
147
+ functionName: "update",
148
+ args: [p.orderbookId, p.orderId, size, price, p.token, deadline],
149
+ });
150
+ return { to: CLOB_ADDRESS, data, value: 0n, type: "eip1559", maxPriorityFeePerGas: 0n, gas: 1000000n };
151
+ }
152
+ // --- TP/SL triggers (perp-only) ---------------------------------------------
153
+ //
154
+ // A trigger is an *armed* limit order: when the pair's mark price crosses
155
+ // `triggerPrice` in the direction implied by `triggerType` and the sign of the
156
+ // size, the venue emits a regular limit order. To attach a TP/SL to a position,
157
+ // the trigger's side is the CLOSING side (opposite the position), `reduceOnly`,
158
+ // and `grouping: "position"` so it's auto-cancelled when the position closes.
159
+ //
160
+ // Direction matrix (is_buy = size > 0):
161
+ // buy + take_profit → fires when mark <= triggerPrice
162
+ // buy + stop_loss → fires when mark >= triggerPrice
163
+ // sell + take_profit → fires when mark >= triggerPrice
164
+ // sell + stop_loss → fires when mark <= triggerPrice
165
+ /** Triggers expire at most this long after their deadline (CLOB TRIGGER_MAX_TTL). */
166
+ const TRIGGER_TTL_US = 29n * 24n * 3600n * 1000000n; // 29d, just under the 30d cap
167
+ export function buildSubmitTrigger(p) {
168
+ const nowUs = BigInt(Date.now()) * 1000n;
169
+ const signedSize = p.side === "sell" ? -p.size : p.size;
170
+ const align = (v) => (p.tickPrecision ? alignPrice(v, p.tickPrecision) : v);
171
+ const triggerPrice = align(p.triggerPrice);
172
+ const limitPrice = align(p.limitPrice ?? p.triggerPrice);
173
+ const interval = p.auctionIntervalUs ? BigInt(p.auctionIntervalUs) : 0n;
174
+ const deadline = alignDeadline(us(p.deadline, nowUs + FAR_US), interval);
175
+ // ttl as a RELATIVE duration (< deadline ⇒ the CLOB reads it relative to the deadline).
176
+ const ttl = p.ttlMs !== undefined ? BigInt(Math.trunc(p.ttlMs)) * 1000n : TRIGGER_TTL_US;
177
+ const data = encodeFunctionData({
178
+ abi: CLOB_ABI,
179
+ functionName: "submitTrigger",
180
+ args: [
181
+ p.orderbookId,
182
+ signedSize,
183
+ limitPrice,
184
+ triggerPrice,
185
+ p.triggerType === "stop_loss" ? 1 : 0, // TriggerType
186
+ (p.grouping ?? "position") === "position" ? 1 : 0, // TriggerGrouping
187
+ deadline,
188
+ ttl,
189
+ p.reduceOnly ?? true,
190
+ p.ioc ?? false,
191
+ ],
192
+ });
193
+ return { to: CLOB_ADDRESS, data, value: 0n, type: "eip1559", maxPriorityFeePerGas: 0n, gas: 1000000n };
194
+ }
195
+ export function buildCancelTrigger(orderbookId, triggerOrderId, opts) {
196
+ const nowUs = BigInt(Date.now()) * 1000n;
197
+ const interval = opts?.auctionIntervalUs ? BigInt(opts.auctionIntervalUs) : 0n;
198
+ const deadline = alignDeadline(us(opts?.deadline, nowUs + FAR_US), interval);
199
+ const data = encodeFunctionData({
200
+ abi: CLOB_ABI,
201
+ functionName: "cancelTrigger",
202
+ args: [orderbookId, triggerOrderId, deadline],
203
+ });
204
+ return { to: CLOB_ADDRESS, data, value: 0n, type: "eip1559", maxPriorityFeePerGas: 0n, gas: 1000000n };
205
+ }
206
+ export function buildUpdateTrigger(p) {
207
+ const nowUs = BigInt(Date.now()) * 1000n;
208
+ const signedSize = p.side === "sell" ? -p.size : p.size;
209
+ const align = (v) => (p.tickPrecision ? alignPrice(v, p.tickPrecision) : v);
210
+ const interval = p.auctionIntervalUs ? BigInt(p.auctionIntervalUs) : 0n;
211
+ const deadline = alignDeadline(us(p.deadline, nowUs + FAR_US), interval);
212
+ const data = encodeFunctionData({
213
+ abi: CLOB_ABI,
214
+ functionName: "updateTrigger",
215
+ args: [p.orderbookId, p.triggerOrderId, signedSize, align(p.limitPrice ?? p.triggerPrice), align(p.triggerPrice), deadline],
216
+ });
217
+ return { to: CLOB_ADDRESS, data, value: 0n, type: "eip1559", maxPriorityFeePerGas: 0n, gas: 1000000n };
218
+ }
219
+ // --- batching (submitBatch) -------------------------------------------------
220
+ //
221
+ // `submitBatch(bytes[] inner)` carries several single-intent calls in ONE signed
222
+ // tx. Each `inner[i]` is the ABI-encoded calldata of an existing intent
223
+ // (submitOrder, submitTrigger, cancel, …); its `sequence` (the index in `inner`)
224
+ // feeds `OrderId::new(signer, nonce, sequence)`. The CLOB requires every
225
+ // deadline-bearing leg to share ONE deadline — build the legs with the same
226
+ // `deadline` (see `buildOrderWithTriggers`, which does this for you).
227
+ /** ~10 years in ms — default far-future deadline shared by batched legs. */
228
+ const FAR_MS = 10 * 365 * 24 * 3600 * 1000;
229
+ /** Scale a 1e18 size by a 0..1 fraction (e.g. close 50% of a position). */
230
+ function scaleSize(size, fraction) {
231
+ const f = Math.max(0, Math.min(1, fraction));
232
+ return (size * BigInt(Math.round(f * 1_000_000))) / 1000000n;
233
+ }
234
+ /** Wrap already-built legs into one `submitBatch` tx. Pass leg requests (their
235
+ * `data` is used) or raw calldata. Legs must share a deadline (the CLOB enforces
236
+ * it). Gas scales with the leg count. */
237
+ export function buildSubmitBatch(legs, opts) {
238
+ const inner = legs.map((l) => (typeof l === "string" ? l : l.data));
239
+ const data = encodeFunctionData({
240
+ abi: CLOB_ABI,
241
+ functionName: "submitBatch",
242
+ args: [inner],
243
+ });
244
+ return {
245
+ to: CLOB_ADDRESS,
246
+ data,
247
+ value: 0n,
248
+ type: "eip1559",
249
+ maxPriorityFeePerGas: 0n,
250
+ gas: opts?.gas ?? BigInt(Math.max(1, inner.length)) * 1000000n,
251
+ };
252
+ }
253
+ /**
254
+ * Build ONE transaction that places an entry order and arms its TP/SL together.
255
+ * With either trigger present it batches `submitOrder` + `submitTrigger`(s) via
256
+ * `submitBatch` under a shared deadline; with neither it's a plain `submitOrder`.
257
+ *
258
+ * Triggers close the entry position: opposite side, `reduceOnly`,
259
+ * `grouping: "position"` (so a partial fill — and the eventual close — keep the
260
+ * triggers consistent), size = entry size × `sizeFraction`.
261
+ */
262
+ export function buildOrderWithTriggers(p) {
263
+ const deadline = p.deadline ?? Date.now() + FAR_MS;
264
+ const order = buildSubmitOrder({
265
+ orderbookId: p.orderbookId,
266
+ side: p.side,
267
+ orderType: p.orderType,
268
+ price: p.price,
269
+ size: p.size,
270
+ tickPrecision: p.tickPrecision,
271
+ auctionIntervalUs: p.auctionIntervalUs,
272
+ reduceOnly: p.reduceOnly,
273
+ ioc: p.ioc,
274
+ deadline,
275
+ ttl: p.orderTtl,
276
+ });
277
+ const closeSide = p.side === "buy" ? "sell" : "buy";
278
+ const trigLeg = (t, triggerType) => buildSubmitTrigger({
279
+ orderbookId: p.orderbookId,
280
+ side: closeSide,
281
+ size: scaleSize(p.size, t.sizeFraction ?? 1),
282
+ triggerType,
283
+ triggerPrice: t.triggerPrice,
284
+ limitPrice: t.limitPrice,
285
+ grouping: "position",
286
+ reduceOnly: true,
287
+ tickPrecision: p.tickPrecision,
288
+ auctionIntervalUs: p.auctionIntervalUs,
289
+ deadline,
290
+ ttlMs: p.triggerTtlMs,
291
+ });
292
+ const legs = [order];
293
+ if (p.takeProfit)
294
+ legs.push(trigLeg(p.takeProfit, "take_profit"));
295
+ if (p.stopLoss)
296
+ legs.push(trigLeg(p.stopLoss, "stop_loss"));
297
+ return legs.length === 1 ? order : buildSubmitBatch(legs);
298
+ }
299
+ /**
300
+ * Protective bound for a market order: the worst price it may fill at. A CLOB
301
+ * market order's `price` IS its slippage bound, so submit at the reference
302
+ * price padded by `slippageBps` (buy pays up to +bps, sell accepts down to
303
+ * −bps) — tight enough to protect, loose enough to actually cross.
304
+ */
305
+ export function protectivePrice(price, side, slippageBps) {
306
+ const bps = BigInt(Math.trunc(slippageBps));
307
+ const SCALE = 10000n;
308
+ return (price * (side === "buy" ? SCALE + bps : SCALE - bps)) / SCALE;
309
+ }
310
+ /**
311
+ * Close (flatten) a perp position: a reduce-only **market** order on the
312
+ * opposite side for the full size. A market order's `price` is a slippage
313
+ * bound, so it's set to mark ∓ `slippageBps` (sell accepts lower, buy pays
314
+ * higher) to guarantee it crosses and fills. `reduceOnly` guarantees it only
315
+ * shrinks the position, never flips it. Batch several with
316
+ * {@link buildSubmitBatch} (shared `deadline`) to close everything in one tx.
317
+ */
318
+ export function buildClosePosition(p) {
319
+ const closeSide = p.side === "long" ? "sell" : "buy";
320
+ const price = protectivePrice(p.price, closeSide, p.slippageBps ?? 500); // tick-aligned in build
321
+ return buildSubmitOrder({
322
+ orderbookId: p.orderbookId,
323
+ side: closeSide,
324
+ orderType: "market",
325
+ price,
326
+ size: p.size < 0n ? -p.size : p.size,
327
+ reduceOnly: true,
328
+ tickPrecision: p.tickPrecision,
329
+ auctionIntervalUs: p.auctionIntervalUs,
330
+ deadline: p.deadline,
331
+ });
332
+ }
333
+ /**
334
+ * Poll `eth_getTransactionReceipt` until the tx is mined, then report whether it
335
+ * executed or reverted. A hash from {@link sendRawTransaction} only means the
336
+ * node accepted the tx into its pool — it is NOT yet confirmed. Await this to
337
+ * know the on-chain outcome. Throws on timeout. Like the rest of this module
338
+ * it's transport-only (raw JSON-RPC), so it needs no viem client.
339
+ */
340
+ export async function waitForReceipt(rpcUrl, hash, opts) {
341
+ const doFetch = opts?.fetch ?? fetch;
342
+ const timeoutMs = opts?.timeoutMs ?? 30_000;
343
+ const pollMs = opts?.pollMs ?? 250;
344
+ const deadline = Date.now() + timeoutMs;
345
+ for (;;) {
346
+ const res = await doFetch(rpcUrl, {
347
+ method: "POST",
348
+ headers: { "content-type": "application/json" },
349
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "eth_getTransactionReceipt", params: [hash] }),
350
+ });
351
+ const json = (await res.json());
352
+ const r = json.result;
353
+ if (r) {
354
+ return {
355
+ status: r.status === "0x1" ? "success" : "reverted",
356
+ transactionHash: r.transactionHash,
357
+ blockNumber: BigInt(r.blockNumber),
358
+ gasUsed: BigInt(r.gasUsed),
359
+ };
360
+ }
361
+ if (Date.now() > deadline)
362
+ throw new Error(`timed out waiting for receipt ${hash}`);
363
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
364
+ }
365
+ }
366
+ // --- mint faucet (test environments — node/src/mint.rs) ----------------------
367
+ //
368
+ // Anyone may mint tokens to any address when the node's `minting_allowed` flag
369
+ // is set (and its mint-admin list is empty). Mint txs are gas-exempt and the
370
+ // signer is irrelevant — only the recipient matters — so this signs with a
371
+ // fresh throwaway key per call; no wallet, no funds, no delegation needed.
372
+ /** The Mint contract (`node/src/mint.rs`). */
373
+ export const MINT_ADDRESS = "0x00000000000000000000000000000000000fFFFf";
374
+ /** The native USD (cash) token — `trading/src/constants.rs` NATIVE_ADDRESS. */
375
+ export const NATIVE_USD_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
376
+ const MINT_ABI = parseAbi([
377
+ "function mint(address to, (address token, uint256 amount)[] tokens, bool depositToClob)",
378
+ ]);
379
+ /** Mint tokens to `to` and wait for the receipt. Throws {@link PodTxRevertError}
380
+ * on rejection (e.g. "Minting is disabled") and Error on on-chain revert. */
381
+ export async function mint(p) {
382
+ const doFetch = p.fetch ?? fetch;
383
+ const rpc = async (method) => {
384
+ const res = await doFetch(p.rpcUrl, {
385
+ method: "POST",
386
+ headers: { "content-type": "application/json" },
387
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params: [] }),
388
+ });
389
+ const json = (await res.json());
390
+ if (json.error || json.result === undefined)
391
+ throw new Error(json.error?.message ?? `${method} failed`);
392
+ return json.result;
393
+ };
394
+ const chainId = p.chainId ?? Number(await rpc("eth_chainId"));
395
+ const maxFeePerGas = BigInt(await rpc("eth_gasPrice"));
396
+ const signer = privateKeyToAccount(generatePrivateKey());
397
+ const data = encodeFunctionData({
398
+ abi: MINT_ABI,
399
+ functionName: "mint",
400
+ args: [
401
+ p.to,
402
+ p.tokens.map((t) => ({ token: t.token ?? NATIVE_USD_ADDRESS, amount: t.amount })),
403
+ p.depositToClob ?? true,
404
+ ],
405
+ });
406
+ const serialized = await signer.signTransaction({
407
+ to: MINT_ADDRESS, data, value: 0n, chainId, type: "eip1559",
408
+ maxFeePerGas, maxPriorityFeePerGas: 0n, gas: 1000000n, nonce: 0,
409
+ });
410
+ const hash = await sendRawTransaction(p.rpcUrl, serialized, { fetch: doFetch });
411
+ p.onSubmitted?.(hash);
412
+ const receipt = await waitForReceipt(p.rpcUrl, hash, { fetch: doFetch });
413
+ if (receipt.status === "reverted")
414
+ throw new Error(`mint reverted on-chain (${hash.slice(0, 10)}…)`);
415
+ return receipt;
416
+ }
417
+ /**
418
+ * Deterministic order id: `keccak256(abi.encode(signer, nonce, sequence))`,
419
+ * matching the engine (`trading/src/lib.rs`). `sequence` is the 0-based index
420
+ * of the intent within a `submitBatch` (0 for a single-intent tx). Needs the
421
+ * nonce, so it's only known up-front in managed mode; in advisory mode reconcile
422
+ * by `tx_hash` from the `pod_orders` stream instead.
423
+ */
424
+ export function deriveOrderId(signer, nonce, sequence = 0) {
425
+ return keccak256(encodeAbiParameters([{ type: "address" }, { type: "uint64" }, { type: "uint32" }], [signer, BigInt(nonce), sequence]));
426
+ }
427
+ export { createDelegatedWallet, delegationTypedData, } from "./delegation.js";
428
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/write/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,gEAAgE;AAChE,gEAAgE;AAChE,EAAE;AACF,6EAA6E;AAC7E,iDAAiD;AACjD,2EAA2E;AAC3E,0CAA0C;AAC1C,yEAAyE;AACzE,yDAAyD;AAEzD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACzG,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGxE,mDAAmD;AACnD,MAAM,CAAC,MAAM,YAAY,GAAY,4CAA4C,CAAC;AAElF,MAAM,QAAQ,GAAG,QAAQ,CAAC;IACxB,kJAAkJ;IAClJ,+EAA+E;IAC/E,gIAAgI;IAChI,oFAAoF;IACpF,iMAAiM;IACjM,qFAAqF;IACrF,qJAAqJ;IACrJ,qCAAqC;CACtC,CAAC,CAAC;AAEH,gFAAgF;AAChF,MAAM,MAAM,GAA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CAAC,CAAC;IACrG,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe,EAAE,KAAa,EAAE,QAAQ,GAAG,CAAC;IACxE,OAAO,SAAS,CACd,mBAAmB,CACjB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAC7D,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAClC,CACM,CAAC;AACZ,CAAC;AAED,OAAO,EACL,qBAAqB,EAAE,mBAAmB,GAE3C,MAAM,iBAAiB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@pod-network/trade-sdk",
3
+ "version": "0.1.0-rc.0",
4
+ "description": "Read/stream TypeScript SDK for the pod trading indexer: cacheable REST seeds + one multiplexed WebSocket, kept in memory. Framework-agnostic.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ },
12
+ "./write": {
13
+ "types": "./dist/write/index.d.ts",
14
+ "import": "./dist/write/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "src"
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/podnetwork/pod-sdk.git",
24
+ "directory": "ts-sdk"
25
+ },
26
+ "homepage": "https://github.com/podnetwork/pod-sdk/tree/main/ts-sdk#readme",
27
+ "bugs": "https://github.com/podnetwork/pod-sdk/issues",
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.build.json",
33
+ "typecheck": "tsc -p tsconfig.json --noEmit",
34
+ "prepublishOnly": "npm run build"
35
+ },
36
+ "dependencies": {
37
+ "viem": "^2.21.0"
38
+ },
39
+ "devDependencies": {
40
+ "typescript": "^5.5.0"
41
+ },
42
+ "license": "MIT"
43
+ }