@piprail/sdk 1.0.0 → 1.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/CHAINS.md +152 -0
- package/CHANGELOG.md +81 -0
- package/ERRORS.md +57 -5
- package/README.md +75 -13
- package/dist/{chunk-3TQJJ4SQ.js → chunk-DTIJYDG6.js} +16 -0
- package/dist/chunk-NK64H3RM.cjs +173 -0
- package/dist/index.cjs +77 -62
- package/dist/index.d.cts +75 -17
- package/dist/index.d.ts +75 -17
- package/dist/index.js +39 -24
- package/dist/{near-RVXGF7TW.js → near-RJUETWY3.js} +99 -12
- package/dist/{near-4P5XNMMB.cjs → near-VZ6XGVNJ.cjs} +116 -29
- package/dist/{solana-F7H4YDW5.cjs → solana-CRLWAM7C.cjs} +14 -14
- package/dist/{solana-7PZG3CDO.js → solana-USZHRZFN.js} +1 -1
- package/dist/{stellar-PAZ352JL.js → stellar-JZBVCLNV.js} +19 -4
- package/dist/{stellar-BPPQTLNI.cjs → stellar-LIGJKRRK.cjs} +36 -21
- package/dist/{sui-XV4YYSGV.cjs → sui-JLVWFDOS.cjs} +17 -17
- package/dist/{sui-6N4ZPAGD.js → sui-UBDATSQV.js} +1 -1
- package/dist/{ton-EFZKQAAK.js → ton-2N74GKNB.js} +2 -2
- package/dist/{ton-E5RLUPD2.cjs → ton-OVSQZ4OM.cjs} +15 -15
- package/dist/{tron-243DT6PF.js → tron-N3EAAKU7.js} +123 -5
- package/dist/{tron-3UDH7KGF.cjs → tron-V3A6L3X3.cjs} +148 -30
- package/dist/{xrpl-6NRFT5CA.cjs → xrpl-QECPQCFS.cjs} +42 -26
- package/dist/{xrpl-7GWXDAVZ.js → xrpl-RTT3UOLX.js} +25 -9
- package/package.json +5 -1
- package/dist/chunk-WQWNPAYQ.cjs +0 -157
|
@@ -10,7 +10,8 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
var _chunkNK64H3RMcjs = require('./chunk-NK64H3RM.cjs');
|
|
14
15
|
|
|
15
16
|
// src/drivers/stellar/index.ts
|
|
16
17
|
var _stellarsdk = require('@stellar/stellar-sdk');
|
|
@@ -93,19 +94,33 @@ function assetForAccept(accept) {
|
|
|
93
94
|
}
|
|
94
95
|
function mapSubmitError(err) {
|
|
95
96
|
const codes = extractResultCodes(err);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
const seen = codes.join(", ");
|
|
98
|
+
const has = (re) => codes.some((c) => re.test(c));
|
|
99
|
+
if (has(/op_no_destination/i)) {
|
|
100
|
+
return new (0, _chunkNK64H3RMcjs.RecipientNotReadyError)(
|
|
101
|
+
`Stellar destination account doesn't exist yet \u2014 create it with \u22651 XLM (the base reserve) before it can receive. (Stellar: ${seen})`,
|
|
102
|
+
{ cause: err }
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (has(/op_(no_trust|line_full|not_authorized)/i) && !has(/src_no_trust/i)) {
|
|
106
|
+
return new (0, _chunkNK64H3RMcjs.RecipientNotReadyError)(
|
|
107
|
+
`Stellar destination can't hold this asset \u2014 it needs a trustline for it (and to be authorized) before it can receive. (Stellar: ${seen})`,
|
|
108
|
+
{ cause: err }
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (has(/underfunded|insufficient|low_reserve|src_no_trust/i)) {
|
|
112
|
+
return new (0, _chunkNK64H3RMcjs.InsufficientFundsError)(
|
|
113
|
+
`Stellar payment failed: the sender can't cover it \u2014 balance, base reserve, or no trustline to send this asset. (Stellar: ${seen})`,
|
|
99
114
|
{ cause: err }
|
|
100
115
|
);
|
|
101
116
|
}
|
|
102
117
|
if (isAccountNotFound(err)) {
|
|
103
|
-
return new (0,
|
|
104
|
-
"Stellar source account not found on-chain \u2014 fund
|
|
118
|
+
return new (0, _chunkNK64H3RMcjs.InsufficientFundsError)(
|
|
119
|
+
"Stellar source account not found on-chain \u2014 fund the sender (\u2265 base reserve) before it can pay.",
|
|
105
120
|
{ cause: err }
|
|
106
121
|
);
|
|
107
122
|
}
|
|
108
|
-
return _nullishCoalesce(
|
|
123
|
+
return _nullishCoalesce(_chunkNK64H3RMcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
109
124
|
}
|
|
110
125
|
function isAccountNotFound(err) {
|
|
111
126
|
const e = err;
|
|
@@ -202,7 +217,7 @@ function assetMatches(p, want) {
|
|
|
202
217
|
}
|
|
203
218
|
function parseAmount(amount, decimals) {
|
|
204
219
|
try {
|
|
205
|
-
return
|
|
220
|
+
return _chunkNK64H3RMcjs.parseUnits.call(void 0, amount, decimals);
|
|
206
221
|
} catch (e4) {
|
|
207
222
|
return 0n;
|
|
208
223
|
}
|
|
@@ -226,22 +241,22 @@ function rpcFailed(nonce) {
|
|
|
226
241
|
|
|
227
242
|
function assertStellarWallet(wallet, network) {
|
|
228
243
|
if (typeof wallet !== "object" || wallet === null) {
|
|
229
|
-
throw new (0,
|
|
244
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
230
245
|
`chain ${network} is Stellar; wallet must be { secret } (S\u2026 seed) or { keypair }.`
|
|
231
246
|
);
|
|
232
247
|
}
|
|
233
248
|
if ("privateKey" in wallet || "walletClient" in wallet) {
|
|
234
|
-
throw new (0,
|
|
249
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
235
250
|
`chain ${network} is Stellar; an EVM wallet can't be used \u2014 pass { secret } (S\u2026 seed) or { keypair }.`
|
|
236
251
|
);
|
|
237
252
|
}
|
|
238
253
|
if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet) {
|
|
239
|
-
throw new (0,
|
|
254
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
240
255
|
`chain ${network} is Stellar; that looks like a Solana/TON wallet \u2014 pass { secret } (S\u2026 seed) or { keypair }.`
|
|
241
256
|
);
|
|
242
257
|
}
|
|
243
258
|
if (!("secret" in wallet) && !("keypair" in wallet)) {
|
|
244
|
-
throw new (0,
|
|
259
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
245
260
|
`chain ${network} is Stellar; wallet must be { secret } (S\u2026 seed) or { keypair }.`
|
|
246
261
|
);
|
|
247
262
|
}
|
|
@@ -251,13 +266,13 @@ function resolveStellarWallet(config) {
|
|
|
251
266
|
if (config.keypair) return config.keypair;
|
|
252
267
|
if (config.secret) {
|
|
253
268
|
if (!_stellarsdk.StrKey.isValidEd25519SecretSeed(config.secret)) {
|
|
254
|
-
throw new (0,
|
|
269
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
255
270
|
"Stellar wallet { secret } is not a valid S\u2026 secret seed."
|
|
256
271
|
);
|
|
257
272
|
}
|
|
258
273
|
return _stellarsdk.Keypair.fromSecret(config.secret);
|
|
259
274
|
}
|
|
260
|
-
throw new (0,
|
|
275
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)("Stellar wallet needs { secret } (S\u2026 seed) or { keypair }.");
|
|
261
276
|
}
|
|
262
277
|
|
|
263
278
|
// src/drivers/stellar/index.ts
|
|
@@ -308,7 +323,7 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
308
323
|
const info = preset.tokens[token.toUpperCase()];
|
|
309
324
|
if (!info) {
|
|
310
325
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
311
|
-
throw new (0,
|
|
326
|
+
throw new (0, _chunkNK64H3RMcjs.UnknownTokenError)(
|
|
312
327
|
`token "${token}" isn't built in for Stellar (known: ${known}). Pass { issuer, code, decimals } for a custom asset, or use 'native'.`
|
|
313
328
|
);
|
|
314
329
|
}
|
|
@@ -318,10 +333,10 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
318
333
|
symbol: info.symbol
|
|
319
334
|
};
|
|
320
335
|
}
|
|
321
|
-
|
|
336
|
+
_chunkNK64H3RMcjs.rejectForeignToken.call(void 0, token, "stellar", network);
|
|
322
337
|
const t = token;
|
|
323
338
|
if (!t.issuer || !t.code || typeof t.decimals !== "number") {
|
|
324
|
-
throw new (0,
|
|
339
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
325
340
|
`chain ${network} is Stellar; a custom token must be { issuer, code, decimals }.`
|
|
326
341
|
);
|
|
327
342
|
}
|
|
@@ -342,12 +357,12 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
342
357
|
},
|
|
343
358
|
assertValidPayTo(payTo) {
|
|
344
359
|
if (payTo.startsWith("0x")) {
|
|
345
|
-
throw new (0,
|
|
360
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
346
361
|
`chain ${network} is Stellar, but payTo "${payTo}" looks like an EVM address.`
|
|
347
362
|
);
|
|
348
363
|
}
|
|
349
364
|
if (!_stellarsdk.StrKey.isValidEd25519PublicKey(payTo)) {
|
|
350
|
-
throw new (0,
|
|
365
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
351
366
|
`chain ${network} is Stellar, but payTo "${payTo}" is not a valid Stellar account (G\u2026).`
|
|
352
367
|
);
|
|
353
368
|
}
|
|
@@ -368,10 +383,10 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
368
383
|
await _chunkCQREG5LEcjs.delay.call(void 0, 1500);
|
|
369
384
|
}
|
|
370
385
|
}
|
|
371
|
-
throw new (0,
|
|
386
|
+
throw new (0, _chunkNK64H3RMcjs.ConfirmationTimeoutError)(`Stellar tx ${ref} not visible on Horizon in time.`);
|
|
372
387
|
},
|
|
373
388
|
async estimateCost() {
|
|
374
|
-
return
|
|
389
|
+
return _chunkNK64H3RMcjs.nativeCost.call(void 0, {
|
|
375
390
|
symbol: XLM_SYMBOL,
|
|
376
391
|
decimals: STELLAR_DECIMALS,
|
|
377
392
|
fee: 100n,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkNK64H3RMcjs = require('./chunk-NK64H3RM.cjs');
|
|
10
10
|
|
|
11
11
|
// src/drivers/sui/index.ts
|
|
12
12
|
var _jsonRpc = require('@mysten/sui/jsonRpc');
|
|
@@ -45,7 +45,7 @@ async function paySui(params) {
|
|
|
45
45
|
} else {
|
|
46
46
|
const coins = await client.getCoins({ owner: sender, coinType: accept.asset });
|
|
47
47
|
if (!coins.data.length) {
|
|
48
|
-
throw new (0,
|
|
48
|
+
throw new (0, _chunkNK64H3RMcjs.InsufficientFundsError)(
|
|
49
49
|
`Sui wallet holds no ${accept.asset} coin objects to pay from.`
|
|
50
50
|
);
|
|
51
51
|
}
|
|
@@ -64,14 +64,14 @@ async function paySui(params) {
|
|
|
64
64
|
});
|
|
65
65
|
return res.digest;
|
|
66
66
|
} catch (err) {
|
|
67
|
-
if (err instanceof
|
|
67
|
+
if (err instanceof _chunkNK64H3RMcjs.InsufficientFundsError) throw err;
|
|
68
68
|
if (isSuiAffordability(err)) {
|
|
69
|
-
throw new (0,
|
|
69
|
+
throw new (0, _chunkNK64H3RMcjs.InsufficientFundsError)(
|
|
70
70
|
err instanceof Error ? err.message : "Insufficient SUI/coin balance for the payment.",
|
|
71
71
|
{ cause: err }
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
|
-
throw _nullishCoalesce(
|
|
74
|
+
throw _nullishCoalesce(_chunkNK64H3RMcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
function isSuiAffordability(err) {
|
|
@@ -151,22 +151,22 @@ function txNotFound(digest) {
|
|
|
151
151
|
var _ed25519 = require('@mysten/sui/keypairs/ed25519');
|
|
152
152
|
function assertSuiWallet(wallet, network) {
|
|
153
153
|
if (typeof wallet !== "object" || wallet === null) {
|
|
154
|
-
throw new (0,
|
|
154
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
155
155
|
`chain ${network} is Sui; wallet must be { privateKey } (suiprivkey1\u2026 ) or { keypair }.`
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
158
|
if ("walletClient" in wallet) {
|
|
159
|
-
throw new (0,
|
|
159
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
160
160
|
`chain ${network} is Sui; a viem { walletClient } can't be used \u2014 pass { privateKey } (suiprivkey1\u2026) or { keypair }.`
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet || "secret" in wallet || "seed" in wallet || "accountId" in wallet) {
|
|
164
|
-
throw new (0,
|
|
164
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
165
165
|
`chain ${network} is Sui; that looks like another family's wallet \u2014 pass { privateKey } (suiprivkey1\u2026) or { keypair }.`
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
if (!("privateKey" in wallet) && !("keypair" in wallet)) {
|
|
169
|
-
throw new (0,
|
|
169
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
170
170
|
`chain ${network} is Sui; wallet must be { privateKey } (suiprivkey1\u2026) or { keypair }.`
|
|
171
171
|
);
|
|
172
172
|
}
|
|
@@ -178,13 +178,13 @@ function resolveSuiKeypair(config) {
|
|
|
178
178
|
try {
|
|
179
179
|
return _ed25519.Ed25519Keypair.fromSecretKey(config.privateKey);
|
|
180
180
|
} catch (cause) {
|
|
181
|
-
throw new (0,
|
|
181
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
182
182
|
"Sui wallet { privateKey } is not a valid suiprivkey1\u2026 secret (or 32-byte key).",
|
|
183
183
|
{ cause }
|
|
184
184
|
);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
throw new (0,
|
|
187
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)("Sui wallet needs { privateKey } (suiprivkey1\u2026) or { keypair }.");
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
// src/drivers/sui/index.ts
|
|
@@ -236,16 +236,16 @@ function makeSuiNetwork(preset, rpcUrl) {
|
|
|
236
236
|
const info = preset.tokens[token.toUpperCase()];
|
|
237
237
|
if (!info) {
|
|
238
238
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
239
|
-
throw new (0,
|
|
239
|
+
throw new (0, _chunkNK64H3RMcjs.UnknownTokenError)(
|
|
240
240
|
`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'.`
|
|
241
241
|
);
|
|
242
242
|
}
|
|
243
243
|
return { asset: info.coinType, decimals: info.decimals, symbol: info.symbol };
|
|
244
244
|
}
|
|
245
|
-
|
|
245
|
+
_chunkNK64H3RMcjs.rejectForeignToken.call(void 0, token, "sui", network);
|
|
246
246
|
const t = token;
|
|
247
247
|
if (!t.coinType || typeof t.decimals !== "number") {
|
|
248
|
-
throw new (0,
|
|
248
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
249
249
|
`chain ${network} is Sui; a custom token must be { coinType, decimals }.`
|
|
250
250
|
);
|
|
251
251
|
}
|
|
@@ -264,7 +264,7 @@ function makeSuiNetwork(preset, rpcUrl) {
|
|
|
264
264
|
},
|
|
265
265
|
assertValidPayTo(payTo) {
|
|
266
266
|
if (!_utils.isValidSuiAddress.call(void 0, payTo)) {
|
|
267
|
-
throw new (0,
|
|
267
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
268
268
|
`chain ${network} is Sui, but payTo "${payTo}" is not a valid Sui address (0x + 32 bytes).`
|
|
269
269
|
);
|
|
270
270
|
}
|
|
@@ -281,11 +281,11 @@ function makeSuiNetwork(preset, rpcUrl) {
|
|
|
281
281
|
const tx = await client.waitForTransaction({ digest: ref, options: { showEffects: true } });
|
|
282
282
|
return { height: String(_nullishCoalesce(tx.checkpoint, () => ( "0"))) };
|
|
283
283
|
} catch (err) {
|
|
284
|
-
throw new (0,
|
|
284
|
+
throw new (0, _chunkNK64H3RMcjs.ConfirmationTimeoutError)(`Sui tx ${ref} did not finalize in time.`, { cause: err });
|
|
285
285
|
}
|
|
286
286
|
},
|
|
287
287
|
async estimateCost() {
|
|
288
|
-
return
|
|
288
|
+
return _chunkNK64H3RMcjs.nativeCost.call(void 0, {
|
|
289
289
|
symbol: SUI_SYMBOL,
|
|
290
290
|
decimals: SUI_DECIMALS,
|
|
291
291
|
fee: 3000000n,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
nativeCost,
|
|
9
9
|
rejectForeignToken,
|
|
10
10
|
toInsufficientFundsError
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-DTIJYDG6.js";
|
|
12
12
|
|
|
13
13
|
// src/drivers/ton/index.ts
|
|
14
14
|
import { Address as Address2 } from "@ton/core";
|
|
@@ -99,7 +99,7 @@ async function verifyTon(params) {
|
|
|
99
99
|
for (const tx of txs) {
|
|
100
100
|
const incoming = extractIncoming(tx);
|
|
101
101
|
if (!incoming || incoming.comment !== nonce) continue;
|
|
102
|
-
if (!txSucceeded(tx)) {
|
|
102
|
+
if (accept.asset !== "native" && !txSucceeded(tx)) {
|
|
103
103
|
return { ok: false, error: "tx_reverted", detail: `TON payment for nonce ${nonce} failed on-chain.` };
|
|
104
104
|
}
|
|
105
105
|
if (incoming.amount < required) {
|
|
@@ -8,7 +8,7 @@ var _chunkCQREG5LEcjs = require('./chunk-CQREG5LE.cjs');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkNK64H3RMcjs = require('./chunk-NK64H3RM.cjs');
|
|
12
12
|
|
|
13
13
|
// src/drivers/ton/index.ts
|
|
14
14
|
var _core = require('@ton/core');
|
|
@@ -74,7 +74,7 @@ async function waitForSeqno(opened, from, { tries = 30, intervalMs = 2e3 } = {})
|
|
|
74
74
|
}
|
|
75
75
|
if (current > from) return;
|
|
76
76
|
}
|
|
77
|
-
throw new (0,
|
|
77
|
+
throw new (0, _chunkNK64H3RMcjs.ConfirmationTimeoutError)(
|
|
78
78
|
`TON wallet seqno did not advance past ${from} \u2014 the payment may not have been accepted.`
|
|
79
79
|
);
|
|
80
80
|
}
|
|
@@ -99,7 +99,7 @@ async function verifyTon(params) {
|
|
|
99
99
|
for (const tx of txs) {
|
|
100
100
|
const incoming = extractIncoming(tx);
|
|
101
101
|
if (!incoming || incoming.comment !== nonce) continue;
|
|
102
|
-
if (!txSucceeded(tx)) {
|
|
102
|
+
if (accept.asset !== "native" && !txSucceeded(tx)) {
|
|
103
103
|
return { ok: false, error: "tx_reverted", detail: `TON payment for nonce ${nonce} failed on-chain.` };
|
|
104
104
|
}
|
|
105
105
|
if (incoming.amount < required) {
|
|
@@ -202,17 +202,17 @@ var _crypto = require('@ton/crypto');
|
|
|
202
202
|
|
|
203
203
|
function assertTonWallet(wallet, network) {
|
|
204
204
|
if (typeof wallet !== "object" || wallet === null) {
|
|
205
|
-
throw new (0,
|
|
205
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
206
206
|
`chain ${network} is TON; wallet must be { mnemonic } (24 words) or { keyPair }.`
|
|
207
207
|
);
|
|
208
208
|
}
|
|
209
209
|
if ("privateKey" in wallet || "walletClient" in wallet) {
|
|
210
|
-
throw new (0,
|
|
210
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
211
211
|
`chain ${network} is TON; an EVM wallet can't be used \u2014 pass { mnemonic } (24 words) or { keyPair }.`
|
|
212
212
|
);
|
|
213
213
|
}
|
|
214
214
|
if (!("mnemonic" in wallet) && !("keyPair" in wallet)) {
|
|
215
|
-
throw new (0,
|
|
215
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
216
216
|
`chain ${network} is TON; wallet must be { mnemonic } (24 words) or { keyPair }.`
|
|
217
217
|
);
|
|
218
218
|
}
|
|
@@ -227,7 +227,7 @@ async function resolveTonWallet(config) {
|
|
|
227
227
|
} else if (config.keyPair) {
|
|
228
228
|
keyPair = config.keyPair;
|
|
229
229
|
} else {
|
|
230
|
-
throw new (0,
|
|
230
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)("TON wallet needs { mnemonic } (24 words) or { keyPair }.");
|
|
231
231
|
}
|
|
232
232
|
const contract = version === "v5r1" ? _ton.WalletContractV5R1.create({ workchain: 0, publicKey: keyPair.publicKey }) : _ton.WalletContractV4.create({ workchain: 0, publicKey: keyPair.publicKey });
|
|
233
233
|
return { keyPair, contract };
|
|
@@ -270,15 +270,15 @@ function makeTonNetwork(preset, rpcUrl) {
|
|
|
270
270
|
const info = preset.tokens[token.toUpperCase()];
|
|
271
271
|
if (!info) {
|
|
272
272
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
273
|
-
throw new (0,
|
|
273
|
+
throw new (0, _chunkNK64H3RMcjs.UnknownTokenError)(
|
|
274
274
|
`token "${token}" isn't built in for TON (known: ${known}). Note: native USDC doesn't exist on TON. Pass { master, decimals } for a custom jetton, or use 'native'.`
|
|
275
275
|
);
|
|
276
276
|
}
|
|
277
277
|
return { asset: info.master, decimals: info.decimals, symbol: info.symbol };
|
|
278
278
|
}
|
|
279
|
-
|
|
279
|
+
_chunkNK64H3RMcjs.rejectForeignToken.call(void 0, token, "ton", network);
|
|
280
280
|
if (!("master" in token)) {
|
|
281
|
-
throw new (0,
|
|
281
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
282
282
|
`chain ${network} is TON; a custom token must be { master, decimals }.`
|
|
283
283
|
);
|
|
284
284
|
}
|
|
@@ -297,14 +297,14 @@ function makeTonNetwork(preset, rpcUrl) {
|
|
|
297
297
|
},
|
|
298
298
|
assertValidPayTo(payTo) {
|
|
299
299
|
if (payTo.startsWith("0x")) {
|
|
300
|
-
throw new (0,
|
|
300
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
301
301
|
`chain ${network} is TON, but payTo "${payTo}" looks like an EVM address.`
|
|
302
302
|
);
|
|
303
303
|
}
|
|
304
304
|
try {
|
|
305
305
|
_core.Address.parse(payTo);
|
|
306
306
|
} catch (e6) {
|
|
307
|
-
throw new (0,
|
|
307
|
+
throw new (0, _chunkNK64H3RMcjs.WrongFamilyError)(
|
|
308
308
|
`chain ${network} is TON, but payTo "${payTo}" is not a valid TON address.`
|
|
309
309
|
);
|
|
310
310
|
}
|
|
@@ -320,7 +320,7 @@ function makeTonNetwork(preset, rpcUrl) {
|
|
|
320
320
|
const watch = await watchAccountFor(accept);
|
|
321
321
|
return encodeRef(watch, accept.extra.nonce);
|
|
322
322
|
} catch (err) {
|
|
323
|
-
throw _nullishCoalesce(
|
|
323
|
+
throw _nullishCoalesce(_chunkNK64H3RMcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
324
324
|
}
|
|
325
325
|
},
|
|
326
326
|
async confirm(ref) {
|
|
@@ -339,12 +339,12 @@ function makeTonNetwork(preset, rpcUrl) {
|
|
|
339
339
|
if (inc && inc.comment === nonce) return { height: tx.lt.toString() };
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
|
-
throw new (0,
|
|
342
|
+
throw new (0, _chunkNK64H3RMcjs.ConfirmationTimeoutError)(`TON payment for nonce ${nonce} did not settle in time.`);
|
|
343
343
|
},
|
|
344
344
|
async estimateCost(accept) {
|
|
345
345
|
const fee = accept.asset === "native" ? 10000000n : 50000000n;
|
|
346
346
|
const detail = accept.asset === "native" ? "~0.01 TON network fee" : "~0.05 TON attached for the jetton transfer (leftover refunded)";
|
|
347
|
-
return
|
|
347
|
+
return _chunkNK64H3RMcjs.nativeCost.call(void 0, { symbol: "TON", decimals: TON_DECIMALS, fee, basis: "heuristic", detail });
|
|
348
348
|
},
|
|
349
349
|
async verify(_ref, accept) {
|
|
350
350
|
const watch = await watchAccountFor(accept);
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
nativeCost,
|
|
10
10
|
rejectForeignToken,
|
|
11
11
|
toInsufficientFundsError
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-DTIJYDG6.js";
|
|
13
13
|
|
|
14
14
|
// src/drivers/tron/index.ts
|
|
15
15
|
import { TronWeb } from "tronweb";
|
|
@@ -73,6 +73,28 @@ async function payTron(params) {
|
|
|
73
73
|
throw toInsufficientFundsError(err) ?? err;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
async function payTronNative(params) {
|
|
77
|
+
const { client, from, privateKey, accept } = params;
|
|
78
|
+
try {
|
|
79
|
+
const unsigned = await client.transactionBuilder.sendTrx(accept.payTo, Number(accept.amount), from);
|
|
80
|
+
const signed = await client.trx.sign(unsigned, privateKey);
|
|
81
|
+
const broadcast = await client.trx.sendRawTransaction(signed);
|
|
82
|
+
if (broadcast.result === true || broadcast.txid || broadcast.transaction?.txID) {
|
|
83
|
+
return broadcast.txid ?? broadcast.transaction?.txID ?? signed.txID;
|
|
84
|
+
}
|
|
85
|
+
if (isTronAffordability(broadcast.code, broadcast.message)) {
|
|
86
|
+
throw new InsufficientFundsError(
|
|
87
|
+
`Tron TRX payment rejected (${broadcast.code ?? "broadcast"}): not enough TRX for the amount plus bandwidth (and the ~1 TRX account-creation fee if the recipient is new).`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Tron TRX broadcast failed: ${broadcast.code ?? ""} ${decodeMaybeHex(broadcast.message)}`.trim()
|
|
92
|
+
);
|
|
93
|
+
} catch (err) {
|
|
94
|
+
if (err instanceof InsufficientFundsError) throw err;
|
|
95
|
+
throw toInsufficientFundsError(err) ?? err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
76
98
|
function decodeMaybeHex(message) {
|
|
77
99
|
if (!message) return "";
|
|
78
100
|
if (/^[0-9a-fA-F]+$/.test(message) && message.length % 2 === 0) {
|
|
@@ -142,6 +164,74 @@ async function verifyTron(params) {
|
|
|
142
164
|
}
|
|
143
165
|
};
|
|
144
166
|
}
|
|
167
|
+
async function verifyTronNative(params) {
|
|
168
|
+
const { reader, accept, txid, payToHex41, toBase58 } = params;
|
|
169
|
+
const required = BigInt(accept.amount);
|
|
170
|
+
let info;
|
|
171
|
+
try {
|
|
172
|
+
info = await reader.getTransactionInfo(txid);
|
|
173
|
+
} catch {
|
|
174
|
+
return txNotFound(txid);
|
|
175
|
+
}
|
|
176
|
+
if (!info || !info.id) return txNotFound(txid);
|
|
177
|
+
const ageSeconds = Math.floor(Date.now() / 1e3) - Math.floor(info.blockTimeStamp / 1e3);
|
|
178
|
+
if (Number.isFinite(ageSeconds) && ageSeconds > accept.maxTimeoutSeconds) {
|
|
179
|
+
return {
|
|
180
|
+
ok: false,
|
|
181
|
+
error: "payment_expired",
|
|
182
|
+
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
let tx;
|
|
186
|
+
try {
|
|
187
|
+
tx = await reader.getTransaction(txid);
|
|
188
|
+
} catch {
|
|
189
|
+
return txNotFound(txid);
|
|
190
|
+
}
|
|
191
|
+
if (!tx) return txNotFound(txid);
|
|
192
|
+
const ret = tx.ret?.[0]?.contractRet;
|
|
193
|
+
if (ret && ret !== "SUCCESS") {
|
|
194
|
+
return { ok: false, error: "tx_reverted", detail: `Tron tx ${txid} did not succeed (contractRet=${ret}).` };
|
|
195
|
+
}
|
|
196
|
+
const contract = (tx.raw_data?.contract ?? [])[0];
|
|
197
|
+
if (!contract || contract.type !== "TransferContract") {
|
|
198
|
+
return {
|
|
199
|
+
ok: false,
|
|
200
|
+
error: "transfer_not_found",
|
|
201
|
+
detail: `Tron tx ${txid} is not a native TRX transfer (TransferContract).`
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
const value = contract.parameter?.value ?? {};
|
|
205
|
+
const to = String(value.to_address ?? "").toLowerCase().replace(/^0x/, "");
|
|
206
|
+
if (to !== payToHex41) {
|
|
207
|
+
return { ok: false, error: "wrong_recipient", detail: `Native TRX in ${txid} was not sent to ${accept.payTo}.` };
|
|
208
|
+
}
|
|
209
|
+
const amount = (() => {
|
|
210
|
+
try {
|
|
211
|
+
return BigInt(value.amount ?? 0);
|
|
212
|
+
} catch {
|
|
213
|
+
return 0n;
|
|
214
|
+
}
|
|
215
|
+
})();
|
|
216
|
+
if (amount < required) {
|
|
217
|
+
return { ok: false, error: "amount_too_low", detail: `Sent ${amount} sun, required ${required}.` };
|
|
218
|
+
}
|
|
219
|
+
const from = String(value.owner_address ?? "").toLowerCase().replace(/^0x/, "");
|
|
220
|
+
return {
|
|
221
|
+
ok: true,
|
|
222
|
+
receipt: {
|
|
223
|
+
scheme: "onchain-proof",
|
|
224
|
+
success: true,
|
|
225
|
+
network: accept.network,
|
|
226
|
+
transaction: txid,
|
|
227
|
+
asset: "native",
|
|
228
|
+
amount: accept.amount,
|
|
229
|
+
payer: from ? toBase58(from) : "",
|
|
230
|
+
payTo: accept.payTo,
|
|
231
|
+
verifiedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
145
235
|
function sumTransfersTo(logs, tokenHex20, payToHex20) {
|
|
146
236
|
let total = 0n;
|
|
147
237
|
let from = null;
|
|
@@ -227,6 +317,15 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
227
317
|
const info = await tronWeb.trx.getTransactionInfo(txid);
|
|
228
318
|
if (!info || !info.id) return null;
|
|
229
319
|
return info;
|
|
320
|
+
},
|
|
321
|
+
// Raw tx (contracts + per-contract ret) for the native-TRX path. getTransaction
|
|
322
|
+
// throws on an unknown tx, so swallow → null; native verify gates finality on
|
|
323
|
+
// getTransactionInfo first anyway.
|
|
324
|
+
async getTransaction(txid) {
|
|
325
|
+
const tx = await tronWeb.trx.getTransaction(txid).catch(() => null);
|
|
326
|
+
const raw = tx;
|
|
327
|
+
if (!raw || !raw.raw_data) return null;
|
|
328
|
+
return raw;
|
|
230
329
|
}
|
|
231
330
|
};
|
|
232
331
|
return {
|
|
@@ -235,9 +334,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
235
334
|
supports: (n) => n === network,
|
|
236
335
|
resolveToken(token) {
|
|
237
336
|
if (token === "native") {
|
|
238
|
-
|
|
239
|
-
`Tron payments are TRC-20 only \u2014 native TRX isn't a built-in asset. Use 'USDT' or a custom { address, decimals }.`
|
|
240
|
-
);
|
|
337
|
+
return { asset: "native", decimals: TRX_DECIMALS, symbol: "TRX" };
|
|
241
338
|
}
|
|
242
339
|
if (typeof token === "string") {
|
|
243
340
|
const info = preset.tokens[token.toUpperCase()];
|
|
@@ -268,7 +365,7 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
268
365
|
};
|
|
269
366
|
},
|
|
270
367
|
describeAsset(asset) {
|
|
271
|
-
if (asset === "native") return
|
|
368
|
+
if (asset === "native") return { symbol: "TRX", decimals: TRX_DECIMALS };
|
|
272
369
|
for (const info of Object.values(preset.tokens)) {
|
|
273
370
|
if (info.address === asset) return { symbol: info.symbol, decimals: info.decimals };
|
|
274
371
|
}
|
|
@@ -295,6 +392,9 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
295
392
|
if (!from) {
|
|
296
393
|
throw new WrongFamilyError("Tron wallet { privateKey } could not derive an address.");
|
|
297
394
|
}
|
|
395
|
+
if (accept.asset === "native") {
|
|
396
|
+
return payTronNative({ client: tronWeb, from, privateKey, accept });
|
|
397
|
+
}
|
|
298
398
|
return payTron({
|
|
299
399
|
client: tronWeb,
|
|
300
400
|
from,
|
|
@@ -316,6 +416,15 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
316
416
|
throw new ConfirmationTimeoutError(`Tron tx ${txid} did not solidify in time.`);
|
|
317
417
|
},
|
|
318
418
|
async estimateCost(accept, opts) {
|
|
419
|
+
if (accept.asset === "native") {
|
|
420
|
+
return nativeCost({
|
|
421
|
+
symbol: "TRX",
|
|
422
|
+
decimals: TRX_DECIMALS,
|
|
423
|
+
fee: 1300000n,
|
|
424
|
+
basis: "heuristic",
|
|
425
|
+
detail: "\u22480.27 TRX bandwidth (sender unstaked) + up to ~1 TRX if the recipient account is new"
|
|
426
|
+
});
|
|
427
|
+
}
|
|
319
428
|
const ENERGY_PRICE = 420n;
|
|
320
429
|
const BANDWIDTH_SUN = 345000n;
|
|
321
430
|
if (opts?.from) {
|
|
@@ -353,6 +462,15 @@ function makeTronNetwork(preset, rpcUrl) {
|
|
|
353
462
|
},
|
|
354
463
|
async verify(ref, accept) {
|
|
355
464
|
const txid = stripTronPrefix(ref);
|
|
465
|
+
if (accept.asset === "native") {
|
|
466
|
+
return verifyTronNative({
|
|
467
|
+
reader,
|
|
468
|
+
accept,
|
|
469
|
+
txid,
|
|
470
|
+
payToHex41: tronWeb.address.toHex(accept.payTo).toLowerCase(),
|
|
471
|
+
toBase58: (h) => tronWeb.address.fromHex(h)
|
|
472
|
+
});
|
|
473
|
+
}
|
|
356
474
|
return verifyTron({
|
|
357
475
|
reader,
|
|
358
476
|
accept,
|