@piprail/sdk 2.16.2 → 3.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +343 -0
  2. package/README.md +1 -0
  3. package/dist/{algorand-25FMBCT3.js → algorand-HL57PQHE.js} +157 -2
  4. package/dist/{algorand-Q3TUQLPK.cjs → algorand-W776EEM2.cjs} +205 -50
  5. package/dist/{aptos-VBJONBFY.cjs → aptos-5QBXJ6NV.cjs} +255 -39
  6. package/dist/{aptos-SBV6SGDP.js → aptos-H5VLH2QL.js} +217 -1
  7. package/dist/{chunk-QONQSZHJ.cjs → chunk-6XTNI2OQ.cjs} +44 -44
  8. package/dist/{chunk-OXEFPLZA.cjs → chunk-6ZRAIQXF.cjs} +4 -4
  9. package/dist/chunk-GVCGUSTE.js +30 -0
  10. package/dist/{chunk-V2IJ5HUW.cjs → chunk-MZAJQYM3.cjs} +1 -0
  11. package/dist/chunk-MZXVXC3C.cjs +30 -0
  12. package/dist/{chunk-2CX7XRZK.js → chunk-TZDVZCTC.js} +1 -0
  13. package/dist/{chunk-C52H5TYB.js → chunk-YXBQKBDH.js} +2 -2
  14. package/dist/index.cjs +2929 -1444
  15. package/dist/index.d.cts +625 -13
  16. package/dist/index.d.ts +625 -13
  17. package/dist/index.js +2506 -1021
  18. package/dist/{near-OLKCMTBI.js → near-5X2CQGML.js} +197 -1
  19. package/dist/{near-5LTTDU6G.cjs → near-XSQXEIHT.cjs} +242 -46
  20. package/dist/{solana-AI2G7V33.cjs → solana-EBV6PUCU.cjs} +211 -52
  21. package/dist/{solana-HTKDRTD3.js → solana-O6Q6QILH.js} +167 -8
  22. package/dist/{stellar-E2KWEV2E.cjs → stellar-5C7FQLPS.cjs} +191 -29
  23. package/dist/{stellar-EUFZLX6J.js → stellar-YF5LOJEM.js} +163 -1
  24. package/dist/{sui-KCIITCYH.js → sui-JFQSDNSZ.js} +165 -3
  25. package/dist/{sui-Q3NJOJZS.cjs → sui-WIZEAO7E.cjs} +185 -23
  26. package/dist/{ton-J7TQWRN4.cjs → ton-AGTKLQA5.cjs} +264 -22
  27. package/dist/{ton-WH2JVQOO.js → ton-OZKFNRLT.js} +244 -2
  28. package/dist/{tron-FXBXDNEY.js → tron-HG3IOOCG.js} +283 -1
  29. package/dist/{tron-HIPMOX7S.cjs → tron-S4WX7OHY.cjs} +323 -41
  30. package/dist/{xrpl-RUOB37QH.js → xrpl-GOVHMYYK.js} +222 -5
  31. package/dist/{xrpl-SVVS445B.cjs → xrpl-YS3IXPLV.cjs} +273 -56
  32. package/package.json +12 -2
  33. package/dist/{chunk-QU25LSVS.js → chunk-5GRBEMCA.js} +44 -44
@@ -1,5 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
+ var _chunkMZXVXC3Ccjs = require('./chunk-MZXVXC3C.cjs');
3
4
 
4
5
 
5
6
 
@@ -7,7 +8,10 @@
7
8
 
8
9
 
9
10
 
10
- var _chunkQONQSZHJcjs = require('./chunk-QONQSZHJ.cjs');
11
+
12
+
13
+
14
+ var _chunk6XTNI2OQcjs = require('./chunk-6XTNI2OQ.cjs');
11
15
 
12
16
  // src/drivers/sui/index.ts
13
17
  var _jsonRpc = require('@mysten/sui/jsonRpc');
@@ -61,7 +65,7 @@ async function paySui(params) {
61
65
  cursor = page.hasNextPage ? page.nextCursor : null;
62
66
  } while (gathered < amount && cursor);
63
67
  if (!ids.length) {
64
- throw new (0, _chunkQONQSZHJcjs.InsufficientFundsError)(
68
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
65
69
  `Sui wallet holds no ${accept.asset} coin objects to pay from.`
66
70
  );
67
71
  }
@@ -79,14 +83,14 @@ async function paySui(params) {
79
83
  });
80
84
  return res.digest;
81
85
  } catch (err) {
82
- if (err instanceof _chunkQONQSZHJcjs.InsufficientFundsError) throw err;
86
+ if (err instanceof _chunk6XTNI2OQcjs.InsufficientFundsError) throw err;
83
87
  if (isSuiAffordability(err)) {
84
- throw new (0, _chunkQONQSZHJcjs.InsufficientFundsError)(
88
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
85
89
  err instanceof Error ? err.message : "Insufficient SUI/coin balance for the payment.",
86
90
  { cause: err }
87
91
  );
88
92
  }
89
- throw _nullishCoalesce(_chunkQONQSZHJcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
93
+ throw _nullishCoalesce(_chunk6XTNI2OQcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
90
94
  }
91
95
  }
92
96
  function isSuiAffordability(err) {
@@ -94,6 +98,151 @@ function isSuiAffordability(err) {
94
98
  return /no valid gas|gas.*(balance|coin)|insufficient|balance is too low|GasBalanceTooLow/i.test(m);
95
99
  }
96
100
 
101
+ // src/drivers/sui/swap.ts
102
+
103
+ var AFTERMATH_API = "https://aftermath.finance/api/router";
104
+ function sourceFor(netFeePct) {
105
+ const pct = typeof netFeePct === "number" ? `${(netFeePct * 100).toFixed(4)}%` : "the underlying pool fee";
106
+ return {
107
+ kind: "provider",
108
+ name: "Aftermath",
109
+ note: `Third-party Sui DEX aggregator (aftermath.finance), used keyless. It routes and returns a complete transaction block; your own keypair signs it locally and Aftermath never holds your funds. Cost on this route: ${pct}, which is the underlying pool fee. PipRail adds nothing.`
110
+ };
111
+ }
112
+ function coinType(t) {
113
+ return t.asset === "native" ? SUI_NATIVE_COINTYPE : t.asset;
114
+ }
115
+ function side(t, amount) {
116
+ const decimals = t.asset === "native" ? SUI_DECIMALS : t.decimals;
117
+ return {
118
+ asset: t.asset,
119
+ symbol: _nullishCoalesce(t.symbol, () => ( (t.asset === "native" ? SUI_SYMBOL : t.asset))),
120
+ decimals,
121
+ amount: amount.toString(),
122
+ amountFormatted: _chunk6XTNI2OQcjs.formatUnits.call(void 0, amount, decimals)
123
+ };
124
+ }
125
+ function toBig(v) {
126
+ try {
127
+ if (typeof v === "bigint") return v;
128
+ const s = String(_nullishCoalesce(v, () => ( ""))).replace(/n$/, "");
129
+ return s ? BigInt(s) : null;
130
+ } catch (e) {
131
+ return null;
132
+ }
133
+ }
134
+ async function postJson(url, body) {
135
+ const ctrl = new AbortController();
136
+ const timer = setTimeout(() => ctrl.abort(), 15e3);
137
+ try {
138
+ const res = await fetch(url, {
139
+ method: "POST",
140
+ headers: { "content-type": "application/json" },
141
+ body: JSON.stringify(body),
142
+ signal: ctrl.signal
143
+ });
144
+ if (!res.ok) return null;
145
+ return await res.json();
146
+ } catch (e2) {
147
+ return null;
148
+ } finally {
149
+ clearTimeout(timer);
150
+ }
151
+ }
152
+ async function quoteSuiSwap(p) {
153
+ if (p.wantAmount <= 0n) return null;
154
+ const coinInType = coinType(p.from);
155
+ const coinOutType = coinType(p.to);
156
+ if (coinInType === coinOutType) return null;
157
+ const route = (amountIn) => postJson(`${AFTERMATH_API}/trade-route`, {
158
+ coinInType,
159
+ coinOutType,
160
+ coinInAmount: amountIn.toString()
161
+ });
162
+ const fromDecimals = p.from.asset === "native" ? SUI_DECIMALS : p.from.decimals;
163
+ const probeIn = 10n ** BigInt(Math.max(fromDecimals - 2, 1));
164
+ const probe = await route(probeIn);
165
+ const probeOut = toBig(_optionalChain([probe, 'optionalAccess', _ => _.coinOut, 'optionalAccess', _2 => _2.amount]));
166
+ if (probeOut === null || probeOut <= 0n) return null;
167
+ let needIn = (probeIn * p.wantAmount + probeOut - 1n) / probeOut;
168
+ needIn = _chunkMZXVXC3Ccjs.applySlippage.call(void 0, needIn, p.slippageBps);
169
+ const real = await route(needIn);
170
+ const realOut = toBig(_optionalChain([real, 'optionalAccess', _3 => _3.coinOut, 'optionalAccess', _4 => _4.amount]));
171
+ if (realOut === null) return null;
172
+ if (realOut < p.wantAmount) return null;
173
+ return {
174
+ source: sourceFor(_optionalChain([real, 'optionalAccess', _5 => _5.netTradeFeePercentage])),
175
+ network: p.network,
176
+ from: side(p.from, needIn),
177
+ to: side(p.to, realOut),
178
+ // Exact-in: the input IS the cap. It cannot spend more than this.
179
+ maxSpend: needIn.toString(),
180
+ maxSpendFormatted: _chunk6XTNI2OQcjs.formatUnits.call(void 0, needIn, fromDecimals),
181
+ slippageBps: p.slippageBps,
182
+ // Aftermath needs its own route object back verbatim to build the transaction.
183
+ route: { completeRoute: real, slippage: p.slippageBps / 1e4 }
184
+ };
185
+ }
186
+ async function swapSui(p) {
187
+ const { client, keypair, quote } = p;
188
+ const route = quote.route;
189
+ if (!_optionalChain([route, 'optionalAccess', _6 => _6.completeRoute])) {
190
+ throw new Error("Sui: swap quote is missing its Aftermath routing data \u2014 re-quote before swapping.");
191
+ }
192
+ const built = await postJson(
193
+ `${AFTERMATH_API}/transactions/trade`,
194
+ {
195
+ walletAddress: keypair.getPublicKey().toSuiAddress(),
196
+ completeRoute: route.completeRoute,
197
+ slippage: _nullishCoalesce(route.slippage, () => ( 0.01))
198
+ }
199
+ );
200
+ const serialized = typeof built === "string" ? built : _optionalChain([built, 'optionalAccess', _7 => _7.serializedTx]);
201
+ if (!serialized) {
202
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
203
+ "Aftermath could not build this swap (the route went stale, or the market moved). Nothing was spent \u2014 re-quote and retry."
204
+ );
205
+ }
206
+ let tx;
207
+ try {
208
+ tx = _transactions.Transaction.from(serialized);
209
+ } catch (cause) {
210
+ throw new Error("Sui: Aftermath returned a transaction this SDK could not decode.", { cause });
211
+ }
212
+ try {
213
+ const res = await client.signAndExecuteTransaction({ transaction: tx, signer: keypair });
214
+ const status = _optionalChain([res, 'access', _8 => _8.effects, 'optionalAccess', _9 => _9.status, 'optionalAccess', _10 => _10.status]);
215
+ if (status && status !== "success") {
216
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
217
+ `Sui swap failed on-chain: ${_nullishCoalesce(_optionalChain([res, 'access', _11 => _11.effects, 'optionalAccess', _12 => _12.status, 'optionalAccess', _13 => _13.error]), () => ( status))}. Re-quote and retry.`
218
+ );
219
+ }
220
+ return {
221
+ transaction: res.digest,
222
+ network: quote.network,
223
+ source: quote.source,
224
+ from: quote.from,
225
+ to: quote.to
226
+ };
227
+ } catch (err) {
228
+ if (err instanceof _chunk6XTNI2OQcjs.InsufficientFundsError) throw err;
229
+ const msg = String(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _14 => _14.message]), () => ( err)));
230
+ if (/insufficient|balance|GasBalanceTooLow/i.test(msg)) {
231
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
232
+ `Sui swap failed: the wallet can't cover it (coin balance or SUI for gas). (${msg.slice(0, 160)})`,
233
+ { cause: err }
234
+ );
235
+ }
236
+ if (/slippage|SlippageExceeded/i.test(msg)) {
237
+ throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
238
+ "Sui swap refused: the price moved past your slippage cap, so nothing was spent. Re-quote and retry.",
239
+ { cause: err }
240
+ );
241
+ }
242
+ throw err;
243
+ }
244
+ }
245
+
97
246
  // src/drivers/sui/verify.ts
98
247
  async function verifySui(params) {
99
248
  const { reader, digest, accept } = params;
@@ -102,7 +251,7 @@ async function verifySui(params) {
102
251
  let tx;
103
252
  try {
104
253
  tx = await reader.getTransaction(digest);
105
- } catch (e) {
254
+ } catch (e3) {
106
255
  return txNotFound(digest);
107
256
  }
108
257
  if (!tx) return txNotFound(digest);
@@ -128,7 +277,7 @@ async function verifySui(params) {
128
277
  let v;
129
278
  try {
130
279
  v = BigInt(bc.amount);
131
- } catch (e2) {
280
+ } catch (e4) {
132
281
  continue;
133
282
  }
134
283
  if (bc.owner && normalizeSuiAddress(bc.owner) === want && v > 0n) paid += v;
@@ -174,13 +323,13 @@ function normalizeSuiAddress(value) {
174
323
  var _ed25519 = require('@mysten/sui/keypairs/ed25519');
175
324
  function assertSuiWallet(wallet, network) {
176
325
  if (typeof wallet !== "object" || wallet === null) {
177
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
326
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
178
327
  `chain ${network} is Sui; wallet must be { key } (suiprivkey1\u2026 ) or { keypair }.`
179
328
  );
180
329
  }
181
- _chunkQONQSZHJcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Sui");
330
+ _chunk6XTNI2OQcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Sui");
182
331
  if (!("key" in wallet) && !("keypair" in wallet)) {
183
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
332
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
184
333
  `chain ${network} is Sui; wallet must be { key } (suiprivkey1\u2026) or { keypair }.`
185
334
  );
186
335
  }
@@ -192,13 +341,13 @@ function resolveSuiKeypair(config) {
192
341
  try {
193
342
  return _ed25519.Ed25519Keypair.fromSecretKey(config.key);
194
343
  } catch (cause) {
195
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
344
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
196
345
  "Sui wallet { key } is not a valid suiprivkey1\u2026 secret (or 32-byte key).",
197
346
  { cause }
198
347
  );
199
348
  }
200
349
  }
201
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)("Sui wallet needs { key } (suiprivkey1\u2026) or { keypair }.");
350
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)("Sui wallet needs { key } (suiprivkey1\u2026) or { keypair }.");
202
351
  }
203
352
 
204
353
  // src/drivers/sui/index.ts
@@ -232,7 +381,7 @@ function makeSuiNetwork(preset, rpcUrl) {
232
381
  amount: bc.amount
233
382
  }));
234
383
  return {
235
- status: _nullishCoalesce(_optionalChain([tx, 'access', _ => _.effects, 'optionalAccess', _2 => _2.status, 'optionalAccess', _3 => _3.status]), () => ( "unknown")),
384
+ status: _nullishCoalesce(_optionalChain([tx, 'access', _15 => _15.effects, 'optionalAccess', _16 => _16.status, 'optionalAccess', _17 => _17.status]), () => ( "unknown")),
236
385
  timestampMs: tx.timestampMs != null ? Number(tx.timestampMs) : void 0,
237
386
  balanceChanges
238
387
  };
@@ -250,16 +399,16 @@ function makeSuiNetwork(preset, rpcUrl) {
250
399
  const info = preset.tokens[token.toUpperCase()];
251
400
  if (!info) {
252
401
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
253
- throw new (0, _chunkQONQSZHJcjs.UnknownTokenError)(
402
+ throw new (0, _chunk6XTNI2OQcjs.UnknownTokenError)(
254
403
  `token "${token}" isn't built in for Sui (known: ${known}). Note: no native USDT on Sui. Pass { coinType, decimals } for a custom coin, or use 'native'.`
255
404
  );
256
405
  }
257
406
  return { asset: info.coinType, decimals: info.decimals, symbol: info.symbol };
258
407
  }
259
- _chunkQONQSZHJcjs.rejectForeignToken.call(void 0, token, "sui", network);
408
+ _chunk6XTNI2OQcjs.rejectForeignToken.call(void 0, token, "sui", network);
260
409
  const t = token;
261
410
  if (!t.coinType || typeof t.decimals !== "number") {
262
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
411
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
263
412
  `chain ${network} is Sui; a custom token must be { coinType, decimals }.`
264
413
  );
265
414
  }
@@ -278,7 +427,7 @@ function makeSuiNetwork(preset, rpcUrl) {
278
427
  },
279
428
  assertValidPayTo(payTo) {
280
429
  if (!_utils.isValidSuiAddress.call(void 0, payTo)) {
281
- throw new (0, _chunkQONQSZHJcjs.WrongFamilyError)(
430
+ throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
282
431
  `chain ${network} is Sui, but payTo "${payTo}" is not a valid Sui address (0x + 32 bytes).`
283
432
  );
284
433
  }
@@ -295,11 +444,11 @@ function makeSuiNetwork(preset, rpcUrl) {
295
444
  const tx = await client.waitForTransaction({ digest: ref, options: { showEffects: true } });
296
445
  return { height: String(_nullishCoalesce(tx.checkpoint, () => ( "0"))) };
297
446
  } catch (err) {
298
- throw new (0, _chunkQONQSZHJcjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
447
+ throw new (0, _chunk6XTNI2OQcjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
299
448
  }
300
449
  },
301
450
  async estimateCost() {
302
- return _chunkQONQSZHJcjs.nativeCost.call(void 0, {
451
+ return _chunk6XTNI2OQcjs.nativeCost.call(void 0, {
303
452
  symbol: SUI_SYMBOL,
304
453
  decimals: SUI_DECIMALS,
305
454
  fee: 3000000n,
@@ -308,17 +457,22 @@ function makeSuiNetwork(preset, rpcUrl) {
308
457
  detail: "\u22480.003 SUI (computation + storage; storage is largely rebated on success)"
309
458
  });
310
459
  },
460
+ /** The bound wallet's own address — where THIS wallet gets paid. Derived from the key
461
+ * material only: no RPC, nothing moved. See {@link ResolvedNetwork.addressOf}. */
462
+ async addressOf(wallet) {
463
+ return resolveSuiKeypair(wallet._native).toSuiAddress();
464
+ },
311
465
  async balanceOf(wallet, asset) {
312
466
  let owner;
313
467
  try {
314
468
  owner = resolveSuiKeypair(wallet._native).toSuiAddress();
315
- } catch (e3) {
469
+ } catch (e5) {
316
470
  return { token: null, native: null };
317
471
  }
318
- const readBal = async (coinType) => {
472
+ const readBal = async (coinType2) => {
319
473
  try {
320
- return BigInt((await client.getBalance({ owner, coinType })).totalBalance);
321
- } catch (e4) {
474
+ return BigInt((await client.getBalance({ owner, coinType: coinType2 })).totalBalance);
475
+ } catch (e6) {
322
476
  return null;
323
477
  }
324
478
  };
@@ -331,6 +485,14 @@ function makeSuiNetwork(preset, rpcUrl) {
331
485
  async recipientReady() {
332
486
  return { ready: "n/a" };
333
487
  },
488
+ /* ---- swap (OPTIONAL, opt-in): via Aftermath, keyless + no added fee. See ./swap.ts ---- */
489
+ async quoteSwap({ from, to, wantAmount, slippageBps }) {
490
+ return quoteSuiSwap({ network, from, to, wantAmount, slippageBps });
491
+ },
492
+ async swap(wallet, quote) {
493
+ const keypair = resolveSuiKeypair(wallet._native);
494
+ return swapSui({ client, keypair, quote });
495
+ },
334
496
  async verify(ref, accept) {
335
497
  return verifySui({ reader, digest: ref, accept });
336
498
  }