@piprail/sdk 2.16.2 → 3.1.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/CHANGELOG.md +448 -0
- package/README.md +1 -0
- package/dist/{algorand-Q3TUQLPK.cjs → algorand-4FTTEV7X.cjs} +212 -51
- package/dist/{algorand-25FMBCT3.js → algorand-KJ5XHSMT.js} +164 -3
- package/dist/{aptos-VBJONBFY.cjs → aptos-5QBXJ6NV.cjs} +255 -39
- package/dist/{aptos-SBV6SGDP.js → aptos-H5VLH2QL.js} +217 -1
- package/dist/{chunk-QONQSZHJ.cjs → chunk-6XTNI2OQ.cjs} +44 -44
- package/dist/{chunk-OXEFPLZA.cjs → chunk-6ZRAIQXF.cjs} +4 -4
- package/dist/chunk-GVCGUSTE.js +30 -0
- package/dist/{chunk-V2IJ5HUW.cjs → chunk-MZAJQYM3.cjs} +1 -0
- package/dist/chunk-MZXVXC3C.cjs +30 -0
- package/dist/{chunk-2CX7XRZK.js → chunk-TZDVZCTC.js} +1 -0
- package/dist/{chunk-C52H5TYB.js → chunk-YXBQKBDH.js} +2 -2
- package/dist/index.cjs +2906 -1262
- package/dist/index.d.cts +679 -21
- package/dist/index.d.ts +679 -21
- package/dist/index.js +2678 -1034
- package/dist/{ledger-Crc1bZox.d.cts → ledger-DkHUORUe.d.cts} +7 -0
- package/dist/{ledger-Crc1bZox.d.ts → ledger-DkHUORUe.d.ts} +7 -0
- package/dist/{near-OLKCMTBI.js → near-5X2CQGML.js} +197 -1
- package/dist/{near-5LTTDU6G.cjs → near-XSQXEIHT.cjs} +242 -46
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/{solana-AI2G7V33.cjs → solana-TIEJV742.cjs} +218 -53
- package/dist/{solana-HTKDRTD3.js → solana-WRXL54MR.js} +174 -9
- package/dist/{stellar-E2KWEV2E.cjs → stellar-5GMZJBTA.cjs} +200 -30
- package/dist/{stellar-EUFZLX6J.js → stellar-YQLOIFDD.js} +172 -2
- package/dist/{sui-KCIITCYH.js → sui-JFQSDNSZ.js} +165 -3
- package/dist/{sui-Q3NJOJZS.cjs → sui-WIZEAO7E.cjs} +185 -23
- package/dist/{ton-J7TQWRN4.cjs → ton-AGTKLQA5.cjs} +264 -22
- package/dist/{ton-WH2JVQOO.js → ton-OZKFNRLT.js} +244 -2
- package/dist/{tron-FXBXDNEY.js → tron-HG3IOOCG.js} +283 -1
- package/dist/{tron-HIPMOX7S.cjs → tron-S4WX7OHY.cjs} +323 -41
- package/dist/{xrpl-RUOB37QH.js → xrpl-5K444RGX.js} +238 -6
- package/dist/{xrpl-SVVS445B.cjs → xrpl-G2FKFXRI.cjs} +289 -57
- package/package.json +12 -2
- 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
|
|
|
@@ -9,7 +10,10 @@
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunk6XTNI2OQcjs = require('./chunk-6XTNI2OQ.cjs');
|
|
13
17
|
|
|
14
18
|
// src/drivers/aptos/index.ts
|
|
15
19
|
var _tssdk = require('@aptos-labs/ts-sdk');
|
|
@@ -58,14 +62,14 @@ async function payAptos(params) {
|
|
|
58
62
|
const res = await client.signSubmit({ signer, transaction });
|
|
59
63
|
return res.hash;
|
|
60
64
|
} catch (err) {
|
|
61
|
-
if (err instanceof
|
|
65
|
+
if (err instanceof _chunk6XTNI2OQcjs.InsufficientFundsError) throw err;
|
|
62
66
|
if (isAptosAffordability(err)) {
|
|
63
|
-
throw new (0,
|
|
67
|
+
throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
|
|
64
68
|
err instanceof Error ? err.message : "Insufficient APT/token balance for the payment.",
|
|
65
69
|
{ cause: err }
|
|
66
70
|
);
|
|
67
71
|
}
|
|
68
|
-
throw _nullishCoalesce(
|
|
72
|
+
throw _nullishCoalesce(_chunk6XTNI2OQcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
function isAptosAffordability(err) {
|
|
@@ -103,24 +107,24 @@ function parseAddr(addr) {
|
|
|
103
107
|
async function payExactAptos(input) {
|
|
104
108
|
const { client, sender, accept } = input;
|
|
105
109
|
if (accept.asset === "native") {
|
|
106
|
-
throw new (0,
|
|
110
|
+
throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(
|
|
107
111
|
"Aptos exact is Fungible-Asset only (a primary_fungible_store transfer); native APT is not exact-payable. Pay via onchain-proof."
|
|
108
112
|
);
|
|
109
113
|
}
|
|
110
114
|
const feePayer = _optionalChain([accept, 'access', _ => _.extra, 'optionalAccess', _2 => _2.feePayer]);
|
|
111
115
|
if (!feePayer) {
|
|
112
|
-
throw new (0,
|
|
116
|
+
throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)("Aptos exact rail must advertise extra.feePayer (the gas sponsor address).");
|
|
113
117
|
}
|
|
114
118
|
const feePayerAddr = parseAddr(feePayer);
|
|
115
|
-
if (!feePayerAddr) throw new (0,
|
|
119
|
+
if (!feePayerAddr) throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`Aptos exact: extra.feePayer "${feePayer}" is not a valid Aptos address.`);
|
|
116
120
|
const payToAddr = parseAddr(accept.payTo);
|
|
117
|
-
if (!payToAddr) throw new (0,
|
|
121
|
+
if (!payToAddr) throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`Aptos exact: payTo "${accept.payTo}" is not a valid Aptos address.`);
|
|
118
122
|
const metadataAddr = parseAddr(accept.asset);
|
|
119
|
-
if (!metadataAddr) throw new (0,
|
|
123
|
+
if (!metadataAddr) throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`Aptos exact: asset "${accept.asset}" is not a valid FA metadata address.`);
|
|
120
124
|
const senderAddr = parseAddr(sender);
|
|
121
|
-
if (!senderAddr) throw new (0,
|
|
125
|
+
if (!senderAddr) throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(`Aptos exact: payer "${sender}" is not a valid Aptos address.`);
|
|
122
126
|
if (feePayerAddr.equals(senderAddr)) {
|
|
123
|
-
throw new (0,
|
|
127
|
+
throw new (0, _chunk6XTNI2OQcjs.UnsupportedSchemeError)(
|
|
124
128
|
"Aptos exact: the fee payer must differ from the payer \u2014 the buyer must pay ZERO APT (the sponsor pays gas)."
|
|
125
129
|
);
|
|
126
130
|
}
|
|
@@ -158,16 +162,16 @@ function argBytes(arg) {
|
|
|
158
162
|
async function verifyAndSettleExactAptos(input) {
|
|
159
163
|
const { client, feePayerAddr, payload, accept } = input;
|
|
160
164
|
const railFeePayer = _optionalChain([accept, 'access', _5 => _5.extra, 'optionalAccess', _6 => _6.feePayer]);
|
|
161
|
-
if (!railFeePayer) throw new (0,
|
|
165
|
+
if (!railFeePayer) throw new (0, _chunk6XTNI2OQcjs.SettlementError)("Aptos exact: rail is missing extra.feePayer.");
|
|
162
166
|
if (railFeePayer !== feePayerAddr) {
|
|
163
|
-
throw new (0,
|
|
167
|
+
throw new (0, _chunk6XTNI2OQcjs.SettlementError)("Aptos exact: the gate relayer address does not match the rail extra.feePayer \u2014 misconfigured rail.");
|
|
164
168
|
}
|
|
165
|
-
if (accept.asset === "native") throw new (0,
|
|
169
|
+
if (accept.asset === "native") throw new (0, _chunk6XTNI2OQcjs.SettlementError)("Aptos exact: native APT is not exact-payable (misconfigured rail).");
|
|
166
170
|
const railFeePayerAddr = parseAddr(railFeePayer);
|
|
167
171
|
const railPayTo = parseAddr(accept.payTo);
|
|
168
172
|
const railMetadata = parseAddr(accept.asset);
|
|
169
173
|
if (!railFeePayerAddr || !railPayTo || !railMetadata) {
|
|
170
|
-
throw new (0,
|
|
174
|
+
throw new (0, _chunk6XTNI2OQcjs.SettlementError)("Aptos exact: rail feePayer/payTo/asset is not a valid Aptos address (misconfigured rail).");
|
|
171
175
|
}
|
|
172
176
|
let tx;
|
|
173
177
|
let senderAuth;
|
|
@@ -241,7 +245,7 @@ async function verifyAndSettleExactAptos(input) {
|
|
|
241
245
|
try {
|
|
242
246
|
feePayerAuth = client.signAsFeePayer({ transaction: tx });
|
|
243
247
|
} catch (err) {
|
|
244
|
-
throw new (0,
|
|
248
|
+
throw new (0, _chunk6XTNI2OQcjs.SettlementError)(`Aptos exact settle: the gate could not sign as fee payer (${shorten(err instanceof Error ? err.message : String(err))}).`, { cause: err });
|
|
245
249
|
}
|
|
246
250
|
if (senderAuth instanceof _tssdk.AccountAuthenticatorEd25519) {
|
|
247
251
|
try {
|
|
@@ -264,7 +268,7 @@ async function verifyAndSettleExactAptos(input) {
|
|
|
264
268
|
if (/signature|invalid.*auth|INVALID_SIGNATURE/i.test(m)) return fail("signature_invalid", `Settle rejected \u2014 bad signature: ${shorten(m)}.`);
|
|
265
269
|
if (/SEQUENCE_NUMBER_TOO_OLD|already.*(committed|ledger)|duplicate/i.test(m)) return fail("tx_already_used", `This payment was already settled: ${shorten(m)}.`);
|
|
266
270
|
if (/EXPIRED|expired|TOO_NEW/i.test(m)) return fail("payment_expired", `Settle rejected \u2014 expired/stale: ${shorten(m)}.`);
|
|
267
|
-
throw new (0,
|
|
271
|
+
throw new (0, _chunk6XTNI2OQcjs.SettlementError)(
|
|
268
272
|
`Aptos exact settle: the transaction failed to submit (${shorten(m)}). The buyer's signed transaction is still valid \u2014 fund/fix the fee payer (${railFeePayer}) and the buyer can re-present it.`,
|
|
269
273
|
{ cause: err }
|
|
270
274
|
);
|
|
@@ -273,10 +277,10 @@ async function verifyAndSettleExactAptos(input) {
|
|
|
273
277
|
try {
|
|
274
278
|
confirmed = await client.waitForConfirmation(hash);
|
|
275
279
|
} catch (err) {
|
|
276
|
-
throw new (0,
|
|
280
|
+
throw new (0, _chunk6XTNI2OQcjs.SettlementError)(`Aptos exact settle: submitted ${hash} but confirmation read failed (${shorten(err instanceof Error ? err.message : String(err))}). It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`, { cause: err });
|
|
277
281
|
}
|
|
278
282
|
if (confirmed === null) {
|
|
279
|
-
throw new (0,
|
|
283
|
+
throw new (0, _chunk6XTNI2OQcjs.SettlementError)(`Aptos exact settle: submitted ${hash} but it did not confirm in time. It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`);
|
|
280
284
|
}
|
|
281
285
|
if (!confirmed.success) {
|
|
282
286
|
return fail("tx_reverted", `Settle tx ${hash} reverted on-chain (a post-simulate race).`);
|
|
@@ -368,17 +372,194 @@ function txNotFound(hash) {
|
|
|
368
372
|
};
|
|
369
373
|
}
|
|
370
374
|
|
|
375
|
+
// src/drivers/aptos/swap.ts
|
|
376
|
+
var HYPERION = "0x8b4a2c4bb53857c718a04c020b98f8c2e1f99a68b0f57389a8bf5434cd22e05c";
|
|
377
|
+
var FEE_TIERS = [0, 1, 2, 3, 4];
|
|
378
|
+
var DEADLINE_SECONDS = 120;
|
|
379
|
+
var MAX_GAS_AMOUNT2 = 8e4;
|
|
380
|
+
var MIN_SQRT_PRICE = 4295048016n;
|
|
381
|
+
var MAX_SQRT_PRICE = 79226673515401279992447579055n;
|
|
382
|
+
function sourceFor(feeRate) {
|
|
383
|
+
const pct = feeRate > 0n ? `${(Number(feeRate) / 1e4).toFixed(4)}%` : "the pool fee";
|
|
384
|
+
return {
|
|
385
|
+
kind: "provider",
|
|
386
|
+
name: "Hyperion",
|
|
387
|
+
note: `Third-party Aptos DEX (Hyperion), called contract-to-contract with no API and no API key: the quote is an on-chain view and the swap is an entry function your own account signs. Cost on this route: ${pct}, which is the pool's own fee. PipRail adds nothing, and the entry function has no fee parameter to add.`
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function sameAddress(a, b) {
|
|
391
|
+
return padAddress(a) === padAddress(b);
|
|
392
|
+
}
|
|
393
|
+
function padAddress(x) {
|
|
394
|
+
return x.replace(/^0x/i, "").padStart(64, "0").toLowerCase();
|
|
395
|
+
}
|
|
396
|
+
function sellingToken0(from, to) {
|
|
397
|
+
return BigInt("0x" + padAddress(from)) < BigInt("0x" + padAddress(to));
|
|
398
|
+
}
|
|
399
|
+
function metadataFor(t) {
|
|
400
|
+
return t.asset === "native" ? APT_FA_METADATA : t.asset;
|
|
401
|
+
}
|
|
402
|
+
function side(t, amount) {
|
|
403
|
+
const decimals = t.asset === "native" ? APT_DECIMALS : t.decimals;
|
|
404
|
+
return {
|
|
405
|
+
asset: t.asset,
|
|
406
|
+
symbol: _nullishCoalesce(t.symbol, () => ( (t.asset === "native" ? APT_SYMBOL : t.asset))),
|
|
407
|
+
decimals,
|
|
408
|
+
amount: amount.toString(),
|
|
409
|
+
amountFormatted: _chunk6XTNI2OQcjs.formatUnits.call(void 0, amount, decimals)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function u64(v) {
|
|
413
|
+
try {
|
|
414
|
+
const n = BigInt(String(v));
|
|
415
|
+
return n >= 0n ? n : null;
|
|
416
|
+
} catch (e7) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async function quoteAptosSwap(p) {
|
|
421
|
+
if (p.wantAmount <= 0n) return null;
|
|
422
|
+
const fromMeta = metadataFor(p.from);
|
|
423
|
+
const toMeta = metadataFor(p.to);
|
|
424
|
+
if (sameAddress(fromMeta, toMeta)) return null;
|
|
425
|
+
const candidates = [];
|
|
426
|
+
for (const feeTier of FEE_TIERS) {
|
|
427
|
+
let pool;
|
|
428
|
+
let feeRate = 0n;
|
|
429
|
+
try {
|
|
430
|
+
const [info] = await p.client.view({
|
|
431
|
+
payload: {
|
|
432
|
+
function: `${HYPERION}::pool_v3::liquidity_pool_info_both_fa`,
|
|
433
|
+
functionArguments: [fromMeta, toMeta, feeTier]
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
pool = String(_nullishCoalesce(_optionalChain([info, 'optionalAccess', _10 => _10[4]]), () => ( "")));
|
|
437
|
+
const liquidity = _nullishCoalesce(u64(_optionalChain([info, 'optionalAccess', _11 => _11[7]])), () => ( 0n));
|
|
438
|
+
feeRate = _nullishCoalesce(u64(_optionalChain([info, 'optionalAccess', _12 => _12[9]])), () => ( 0n));
|
|
439
|
+
if (!pool || liquidity === 0n) continue;
|
|
440
|
+
} catch (e8) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
const [inRaw] = await p.client.view({
|
|
445
|
+
payload: {
|
|
446
|
+
function: `${HYPERION}::router_v3::get_batch_amount_in`,
|
|
447
|
+
functionArguments: [[pool], p.wantAmount.toString(), fromMeta, toMeta]
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
const amountIn = u64(inRaw);
|
|
451
|
+
if (amountIn === null || amountIn === 0n) continue;
|
|
452
|
+
candidates.push({ feeTier, pool, amountIn, feeRate, fromIsToken0: sellingToken0(fromMeta, toMeta) });
|
|
453
|
+
} catch (e9) {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (!candidates.length) return null;
|
|
458
|
+
const best = candidates.reduce((a, b) => b.amountIn < a.amountIn ? b : a);
|
|
459
|
+
const maxSpend = _chunkMZXVXC3Ccjs.applySlippage.call(void 0, best.amountIn, p.slippageBps);
|
|
460
|
+
return {
|
|
461
|
+
source: sourceFor(best.feeRate),
|
|
462
|
+
network: p.network,
|
|
463
|
+
from: side(p.from, best.amountIn),
|
|
464
|
+
to: side(p.to, p.wantAmount),
|
|
465
|
+
maxSpend: maxSpend.toString(),
|
|
466
|
+
maxSpendFormatted: _chunk6XTNI2OQcjs.formatUnits.call(void 0, maxSpend, p.from.asset === "native" ? APT_DECIMALS : p.from.decimals),
|
|
467
|
+
slippageBps: p.slippageBps,
|
|
468
|
+
route: {
|
|
469
|
+
feeTier: best.feeTier,
|
|
470
|
+
pool: best.pool,
|
|
471
|
+
fromMetadata: fromMeta,
|
|
472
|
+
toMetadata: toMeta,
|
|
473
|
+
recipient: p.owner,
|
|
474
|
+
fromIsToken0: best.fromIsToken0
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
async function swapAptos(p) {
|
|
479
|
+
const route = p.quote.route;
|
|
480
|
+
if (!_optionalChain([route, 'optionalAccess', _13 => _13.pool]) || !route.fromMetadata || !route.toMetadata) {
|
|
481
|
+
throw new Error("Aptos: swap quote is missing its Hyperion routing data \u2014 re-quote before swapping.");
|
|
482
|
+
}
|
|
483
|
+
const amountOut = BigInt(p.quote.to.amount);
|
|
484
|
+
const amountInMax = BigInt(p.quote.maxSpend);
|
|
485
|
+
const deadline = Math.floor(Date.now() / 1e3) + DEADLINE_SECONDS;
|
|
486
|
+
let hash;
|
|
487
|
+
try {
|
|
488
|
+
const transaction = await p.client.build({
|
|
489
|
+
sender: p.sender,
|
|
490
|
+
data: {
|
|
491
|
+
function: `${HYPERION}::router_v3::exact_output_swap_entry`,
|
|
492
|
+
/*
|
|
493
|
+
* 🔴 Argument order: (fee_tier, FROM amount, TO amount, …). Both the exact-input and
|
|
494
|
+
* exact-output entry functions share one signature, and the two amount slots are
|
|
495
|
+
* "what leaves" then "what arrives" — NOT "the exact one" then "the limit". So here
|
|
496
|
+
* p2 is the input CAP and p3 is the exact output, which is the opposite of what the
|
|
497
|
+
* names suggest. Getting it backwards aborts with `fungible_asset::EINSUFFICIENT_BALANCE`,
|
|
498
|
+
* which reads like a funding problem and is not one. Established by simulating every
|
|
499
|
+
* candidate ordering against mainnet rather than by guessing.
|
|
500
|
+
*/
|
|
501
|
+
functionArguments: [
|
|
502
|
+
route.feeTier,
|
|
503
|
+
amountInMax.toString(),
|
|
504
|
+
// ← the on-chain slippage cap; the trade aborts above it
|
|
505
|
+
amountOut.toString(),
|
|
506
|
+
// ← the exact amount we require to arrive
|
|
507
|
+
// Selling token0 pushes the price DOWN, so bound it below; otherwise bound above.
|
|
508
|
+
(route.fromIsToken0 ? MIN_SQRT_PRICE + 1n : MAX_SQRT_PRICE - 1n).toString(),
|
|
509
|
+
route.fromMetadata,
|
|
510
|
+
route.toMetadata,
|
|
511
|
+
/*
|
|
512
|
+
* 🔴 The SIGNER receives, always. `route.recipient` records who quoted, and is not
|
|
513
|
+
* used here: it was captured at quote time, so a quote carried across wallets (or
|
|
514
|
+
* simply held while the client rebound) would have paid the output to whoever asked
|
|
515
|
+
* for the price rather than whoever signed. Every other family already derives this
|
|
516
|
+
* from the signing wallet at swap time; this one did not, and the comment claiming
|
|
517
|
+
* "the funds never leave the wallet" was only true by luck of them matching.
|
|
518
|
+
*/
|
|
519
|
+
p.sender,
|
|
520
|
+
deadline.toString()
|
|
521
|
+
]
|
|
522
|
+
},
|
|
523
|
+
options: { maxGasAmount: MAX_GAS_AMOUNT2 }
|
|
524
|
+
});
|
|
525
|
+
const res = await p.client.signSubmit({ signer: p.signer, transaction });
|
|
526
|
+
hash = res.hash;
|
|
527
|
+
} catch (err) {
|
|
528
|
+
const msg = String(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _14 => _14.message]), () => ( err)));
|
|
529
|
+
if (/EINSUFFICIENT|insufficient|balance/i.test(msg)) {
|
|
530
|
+
throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
|
|
531
|
+
`Aptos swap could not be submitted: the account cannot cover it (token balance or APT gas). (${msg.slice(0, 160)})`,
|
|
532
|
+
{ cause: err }
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
throw err;
|
|
536
|
+
}
|
|
537
|
+
const out = await p.client.waitFor({ hash });
|
|
538
|
+
if (_optionalChain([out, 'optionalAccess', _15 => _15.success]) === false) {
|
|
539
|
+
throw new (0, _chunk6XTNI2OQcjs.InsufficientFundsError)(
|
|
540
|
+
`Aptos swap failed on-chain (tx ${hash}): ${_nullishCoalesce(out.vm_status, () => ( "unknown status"))}. Nothing was swapped. The usual cause is the price moving past the input cap \u2014 re-quote and retry.`
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
return {
|
|
544
|
+
transaction: hash,
|
|
545
|
+
network: p.quote.network,
|
|
546
|
+
source: p.quote.source,
|
|
547
|
+
from: p.quote.from,
|
|
548
|
+
to: p.quote.to
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
371
552
|
// src/drivers/aptos/wallet.ts
|
|
372
553
|
|
|
373
554
|
function assertAptosWallet(wallet, network) {
|
|
374
555
|
if (typeof wallet !== "object" || wallet === null) {
|
|
375
|
-
throw new (0,
|
|
556
|
+
throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
|
|
376
557
|
`chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
|
|
377
558
|
);
|
|
378
559
|
}
|
|
379
|
-
|
|
560
|
+
_chunk6XTNI2OQcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Aptos");
|
|
380
561
|
if (!("key" in wallet) && !("account" in wallet)) {
|
|
381
|
-
throw new (0,
|
|
562
|
+
throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
|
|
382
563
|
`chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
|
|
383
564
|
);
|
|
384
565
|
}
|
|
@@ -390,13 +571,13 @@ function resolveAptosAccount(config) {
|
|
|
390
571
|
try {
|
|
391
572
|
return _tssdk.Account.fromPrivateKey({ privateKey: new (0, _tssdk.Ed25519PrivateKey)(config.key) });
|
|
392
573
|
} catch (cause) {
|
|
393
|
-
throw new (0,
|
|
574
|
+
throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
|
|
394
575
|
"Aptos wallet { key } is not a valid ed25519 secret (ed25519-priv-0x\u2026 or 0x\u2026 hex).",
|
|
395
576
|
{ cause }
|
|
396
577
|
);
|
|
397
578
|
}
|
|
398
579
|
}
|
|
399
|
-
throw new (0,
|
|
580
|
+
throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)("Aptos wallet needs { key } (ed25519-priv-0x\u2026) or { account }.");
|
|
400
581
|
}
|
|
401
582
|
|
|
402
583
|
// src/drivers/aptos/index.ts
|
|
@@ -411,7 +592,7 @@ var aptosDriver = {
|
|
|
411
592
|
function norm(addr) {
|
|
412
593
|
try {
|
|
413
594
|
return _tssdk.AccountAddress.from(addr).toString();
|
|
414
|
-
} catch (
|
|
595
|
+
} catch (e10) {
|
|
415
596
|
return addr;
|
|
416
597
|
}
|
|
417
598
|
}
|
|
@@ -442,6 +623,22 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
442
623
|
return norm(String(addr));
|
|
443
624
|
}
|
|
444
625
|
};
|
|
626
|
+
const swapClient = {
|
|
627
|
+
view: (input) => aptos.view(input),
|
|
628
|
+
build: (input) => aptos.transaction.build.simple({
|
|
629
|
+
sender: input.sender,
|
|
630
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
631
|
+
data: input.data,
|
|
632
|
+
...input.options ? { options: input.options } : {}
|
|
633
|
+
}),
|
|
634
|
+
signSubmit: (input) => aptos.signAndSubmitTransaction({
|
|
635
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
636
|
+
signer: input.signer,
|
|
637
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
638
|
+
transaction: input.transaction
|
|
639
|
+
}),
|
|
640
|
+
waitFor: async ({ hash }) => await aptos.waitForTransaction({ transactionHash: hash })
|
|
641
|
+
};
|
|
445
642
|
const payClient = {
|
|
446
643
|
build: (input) => aptos.transaction.build.simple({
|
|
447
644
|
sender: input.sender,
|
|
@@ -468,16 +665,16 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
468
665
|
const info = preset.tokens[token.toUpperCase()];
|
|
469
666
|
if (!info) {
|
|
470
667
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
471
|
-
throw new (0,
|
|
668
|
+
throw new (0, _chunk6XTNI2OQcjs.UnknownTokenError)(
|
|
472
669
|
`token "${token}" isn't built in for Aptos (known: ${known}). Pass { metadata, decimals } for a custom Fungible Asset, or use 'native'.`
|
|
473
670
|
);
|
|
474
671
|
}
|
|
475
672
|
return { asset: info.metadata, decimals: info.decimals, symbol: info.symbol };
|
|
476
673
|
}
|
|
477
|
-
|
|
674
|
+
_chunk6XTNI2OQcjs.rejectForeignToken.call(void 0, token, "aptos", network);
|
|
478
675
|
const t = token;
|
|
479
676
|
if (!t.metadata || typeof t.decimals !== "number") {
|
|
480
|
-
throw new (0,
|
|
677
|
+
throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
|
|
481
678
|
`chain ${network} is Aptos; a custom token must be { metadata, decimals }.`
|
|
482
679
|
);
|
|
483
680
|
}
|
|
@@ -500,11 +697,11 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
500
697
|
try {
|
|
501
698
|
_tssdk.AccountAddress.from(payTo);
|
|
502
699
|
valid = true;
|
|
503
|
-
} catch (
|
|
700
|
+
} catch (e11) {
|
|
504
701
|
valid = false;
|
|
505
702
|
}
|
|
506
703
|
if (!valid || evmLike) {
|
|
507
|
-
throw new (0,
|
|
704
|
+
throw new (0, _chunk6XTNI2OQcjs.WrongFamilyError)(
|
|
508
705
|
`chain ${network} is Aptos, but payTo "${payTo}" is not a valid Aptos address (0x + 32 bytes).`
|
|
509
706
|
);
|
|
510
707
|
}
|
|
@@ -526,12 +723,12 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
526
723
|
const tx = await aptos.waitForTransaction({ transactionHash: ref });
|
|
527
724
|
return { height: String(_nullishCoalesce(tx.version, () => ( "0"))) };
|
|
528
725
|
} catch (err) {
|
|
529
|
-
throw new (0,
|
|
726
|
+
throw new (0, _chunk6XTNI2OQcjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
|
|
530
727
|
}
|
|
531
728
|
},
|
|
532
729
|
async estimateCost(accept) {
|
|
533
730
|
if (accept.scheme === "exact") {
|
|
534
|
-
return
|
|
731
|
+
return _chunk6XTNI2OQcjs.nativeCost.call(void 0, {
|
|
535
732
|
symbol: APT_SYMBOL,
|
|
536
733
|
decimals: APT_DECIMALS,
|
|
537
734
|
fee: 0n,
|
|
@@ -539,7 +736,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
539
736
|
detail: "gasless \u2014 the fee payer (facilitator/relayer) sponsors gas; the buyer pays 0 APT"
|
|
540
737
|
});
|
|
541
738
|
}
|
|
542
|
-
return
|
|
739
|
+
return _chunk6XTNI2OQcjs.nativeCost.call(void 0, {
|
|
543
740
|
symbol: APT_SYMBOL,
|
|
544
741
|
decimals: APT_DECIMALS,
|
|
545
742
|
fee: 100000n,
|
|
@@ -548,11 +745,16 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
548
745
|
detail: "\u22480.001 APT (a simple Fungible-Asset transfer; Aptos gas is sub-cent)"
|
|
549
746
|
});
|
|
550
747
|
},
|
|
748
|
+
/** The bound wallet's own address — where THIS wallet gets paid. Derived from the key
|
|
749
|
+
* material only: no RPC, nothing moved. See {@link ResolvedNetwork.addressOf}. */
|
|
750
|
+
async addressOf(wallet) {
|
|
751
|
+
return resolveAptosAccount(wallet._native).accountAddress.toString();
|
|
752
|
+
},
|
|
551
753
|
async balanceOf(wallet, asset) {
|
|
552
754
|
let owner;
|
|
553
755
|
try {
|
|
554
756
|
owner = resolveAptosAccount(wallet._native).accountAddress.toString();
|
|
555
|
-
} catch (
|
|
757
|
+
} catch (e12) {
|
|
556
758
|
return { token: null, native: null };
|
|
557
759
|
}
|
|
558
760
|
const native = await aptos.getAccountAPTAmount({ accountAddress: owner }).then((n) => BigInt(n)).catch(() => null);
|
|
@@ -567,7 +769,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
567
769
|
}
|
|
568
770
|
});
|
|
569
771
|
token = BigInt(String(bal));
|
|
570
|
-
} catch (
|
|
772
|
+
} catch (e13) {
|
|
571
773
|
token = null;
|
|
572
774
|
}
|
|
573
775
|
return { token, native };
|
|
@@ -576,6 +778,20 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
576
778
|
async recipientReady() {
|
|
577
779
|
return { ready: "n/a" };
|
|
578
780
|
},
|
|
781
|
+
/* ---- swap (OPTIONAL, opt-in): via Hyperion, no API, no key, no added fee. See ./swap.ts ---- */
|
|
782
|
+
async quoteSwap({ from, to, wantAmount, slippageBps, wallet }) {
|
|
783
|
+
const owner = resolveAptosAccount(wallet._native).accountAddress.toString();
|
|
784
|
+
return quoteAptosSwap({ client: swapClient, network, from, to, wantAmount, slippageBps, owner });
|
|
785
|
+
},
|
|
786
|
+
async swap(wallet, quote) {
|
|
787
|
+
const account = resolveAptosAccount(wallet._native);
|
|
788
|
+
return swapAptos({
|
|
789
|
+
client: swapClient,
|
|
790
|
+
signer: account,
|
|
791
|
+
sender: account.accountAddress.toString(),
|
|
792
|
+
quote
|
|
793
|
+
});
|
|
794
|
+
},
|
|
579
795
|
async verify(ref, accept) {
|
|
580
796
|
return verifyAptos({ reader, hash: ref, accept });
|
|
581
797
|
},
|
|
@@ -620,7 +836,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
620
836
|
feePayerPublicKey: feePayerAccount.publicKey,
|
|
621
837
|
transaction
|
|
622
838
|
});
|
|
623
|
-
return { success: _optionalChain([sim, 'optionalAccess',
|
|
839
|
+
return { success: _optionalChain([sim, 'optionalAccess', _16 => _16.success]) === true, vmStatus: String(_nullishCoalesce(_optionalChain([sim, 'optionalAccess', _17 => _17.vm_status]), () => ( ""))) };
|
|
624
840
|
},
|
|
625
841
|
async submit({ transaction, senderAuthenticator, feePayerAuthenticator }) {
|
|
626
842
|
const res = await aptos.transaction.submit.simple({ transaction, senderAuthenticator, feePayerAuthenticator });
|
|
@@ -633,7 +849,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
633
849
|
options: { checkSuccess: false }
|
|
634
850
|
});
|
|
635
851
|
return { success: tx.success === true };
|
|
636
|
-
} catch (
|
|
852
|
+
} catch (e14) {
|
|
637
853
|
return null;
|
|
638
854
|
}
|
|
639
855
|
}
|
|
@@ -655,14 +871,14 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
655
871
|
if (!fp && relayer) {
|
|
656
872
|
try {
|
|
657
873
|
fp = resolveAptosAccount(relayer._native).accountAddress.toString();
|
|
658
|
-
} catch (
|
|
874
|
+
} catch (e15) {
|
|
659
875
|
return null;
|
|
660
876
|
}
|
|
661
877
|
}
|
|
662
878
|
if (!fp) return null;
|
|
663
879
|
try {
|
|
664
880
|
_tssdk.AccountAddress.fromString(fp);
|
|
665
|
-
} catch (
|
|
881
|
+
} catch (e16) {
|
|
666
882
|
return null;
|
|
667
883
|
}
|
|
668
884
|
return { method: "aptos", extra: { feePayer: fp } };
|