@piprail/sdk 1.3.1 → 1.5.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 +31 -7
- package/CHANGELOG.md +74 -0
- package/ERRORS.md +13 -2
- package/README.md +46 -12
- package/dist/algorand-B67G4335.js +397 -0
- package/dist/algorand-IJJKE35X.cjs +397 -0
- package/dist/{aptos-MKZ5MAGL.cjs → aptos-X3G2UBYW.cjs} +44 -16
- package/dist/{aptos-DTAONNMM.js → aptos-YQWTGFRZ.js} +29 -1
- package/dist/{chunk-YJPWIK5L.cjs → chunk-IQGT65WS.cjs} +4 -2
- package/dist/{chunk-AGKC3C7Y.js → chunk-QDS6FBZP.js} +4 -2
- package/dist/index.cjs +358 -67
- package/dist/index.d.cts +162 -4
- package/dist/index.d.ts +162 -4
- package/dist/index.js +308 -17
- package/dist/{near-YX3XOASO.js → near-7MBBCDUE.js} +51 -1
- package/dist/{near-DISWUB7Y.cjs → near-GGUHLXAF.cjs} +76 -26
- package/dist/{solana-37F2PR5H.js → solana-7WJVZGDW.js} +23 -1
- package/dist/{solana-RJPNEFSN.cjs → solana-W24TCJV4.cjs} +39 -17
- package/dist/{stellar-ALOVOMFD.js → stellar-HV6VGZX3.js} +51 -1
- package/dist/{stellar-SUGNX52Z.cjs → stellar-YMY3K2YB.cjs} +70 -20
- package/dist/{sui-OLC5ID4X.js → sui-2WFWVFJX.js} +24 -1
- package/dist/{sui-HZWPHVU4.cjs → sui-32KVESR5.cjs} +40 -17
- package/dist/{ton-NIDWF77T.js → ton-DGZB7W4U.js} +24 -1
- package/dist/{ton-C4KTFXDL.cjs → ton-FIQGV2LC.cjs} +37 -14
- package/dist/{tron-LPMK57H7.js → tron-RLIL2FDI.js} +29 -1
- package/dist/{tron-DTU7NPEM.cjs → tron-ZSXAPZ2C.cjs} +52 -24
- package/dist/{xrpl-N6ZAJRGC.cjs → xrpl-2PKP7HOI.cjs} +81 -21
- package/dist/{xrpl-6ODQS7JR.js → xrpl-UEC2GYVV.js} +61 -1
- package/package.json +9 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
|
|
11
11
|
|
|
12
12
|
// src/drivers/near/index.ts
|
|
13
13
|
var _nearapijs = require('near-api-js');
|
|
@@ -53,18 +53,18 @@ async function payNear(params) {
|
|
|
53
53
|
return res.hash;
|
|
54
54
|
} catch (err) {
|
|
55
55
|
if (isNearRegistrationError(err)) {
|
|
56
|
-
throw new (0,
|
|
56
|
+
throw new (0, _chunkIQGT65WScjs.RecipientNotReadyError)(
|
|
57
57
|
`NEAR recipient ${accept.payTo} isn't registered on token ${accept.asset} (NEP-145 storage_deposit) \u2014 register it once (\u22480.00125 NEAR) before it can receive. (NEAR: not registered)`,
|
|
58
58
|
{ cause: err }
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
if (isNearAffordability(err)) {
|
|
62
|
-
throw new (0,
|
|
62
|
+
throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
|
|
63
63
|
err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
|
|
64
64
|
{ cause: err }
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
|
-
throw _nullishCoalesce(
|
|
67
|
+
throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
async function payNearNative(params) {
|
|
@@ -74,12 +74,12 @@ async function payNearNative(params) {
|
|
|
74
74
|
return res.hash;
|
|
75
75
|
} catch (err) {
|
|
76
76
|
if (isNearAffordability(err)) {
|
|
77
|
-
throw new (0,
|
|
77
|
+
throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
|
|
78
78
|
err instanceof Error ? err.message : "Insufficient NEAR balance for the payment.",
|
|
79
79
|
{ cause: err }
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
|
-
throw _nullishCoalesce(
|
|
82
|
+
throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
function isNearRegistrationError(err) {
|
|
@@ -101,7 +101,7 @@ function parseFtTransferEvent(line) {
|
|
|
101
101
|
if (ev.standard === "nep141" && ev.event === "ft_transfer" && Array.isArray(ev.data)) {
|
|
102
102
|
return ev.data;
|
|
103
103
|
}
|
|
104
|
-
} catch (
|
|
104
|
+
} catch (e2) {
|
|
105
105
|
}
|
|
106
106
|
return null;
|
|
107
107
|
}
|
|
@@ -112,7 +112,7 @@ async function verifyNear(params) {
|
|
|
112
112
|
let tx;
|
|
113
113
|
try {
|
|
114
114
|
tx = await reader.txStatus(hash, senderId);
|
|
115
|
-
} catch (
|
|
115
|
+
} catch (e3) {
|
|
116
116
|
return txNotFound(hash);
|
|
117
117
|
}
|
|
118
118
|
if (!tx) return txNotFound(hash);
|
|
@@ -133,7 +133,7 @@ async function verifyNear(params) {
|
|
|
133
133
|
let paid2;
|
|
134
134
|
try {
|
|
135
135
|
paid2 = BigInt(_nullishCoalesce(tx.nativeDeposit, () => ( "0")));
|
|
136
|
-
} catch (
|
|
136
|
+
} catch (e4) {
|
|
137
137
|
paid2 = 0n;
|
|
138
138
|
}
|
|
139
139
|
if (paid2 < required) {
|
|
@@ -175,7 +175,7 @@ async function verifyNear(params) {
|
|
|
175
175
|
if (d.new_owner_id === accept.payTo && (_nullishCoalesce(d.memo, () => ( ""))) === nonce) {
|
|
176
176
|
try {
|
|
177
177
|
paid += BigInt(_nullishCoalesce(d.amount, () => ( "0")));
|
|
178
|
-
} catch (
|
|
178
|
+
} catch (e5) {
|
|
179
179
|
}
|
|
180
180
|
if (!payer) payer = _nullishCoalesce(d.old_owner_id, () => ( ""));
|
|
181
181
|
}
|
|
@@ -216,22 +216,22 @@ function txNotFound(hash) {
|
|
|
216
216
|
|
|
217
217
|
function assertNearWallet(wallet, network) {
|
|
218
218
|
if (typeof wallet !== "object" || wallet === null) {
|
|
219
|
-
throw new (0,
|
|
219
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
220
220
|
`chain ${network} is NEAR; wallet must be { accountId, privateKey } (privateKey = ed25519:\u2026).`
|
|
221
221
|
);
|
|
222
222
|
}
|
|
223
223
|
if ("walletClient" in wallet) {
|
|
224
|
-
throw new (0,
|
|
224
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
225
225
|
`chain ${network} is NEAR; a viem { walletClient } can't be used \u2014 pass { accountId, privateKey }.`
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keyPair" in wallet || "secret" in wallet || "seed" in wallet || "keypair" in wallet) {
|
|
229
|
-
throw new (0,
|
|
229
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
230
230
|
`chain ${network} is NEAR; that looks like another family's wallet \u2014 pass { accountId, privateKey }.`
|
|
231
231
|
);
|
|
232
232
|
}
|
|
233
233
|
if (!("accountId" in wallet) || !("privateKey" in wallet)) {
|
|
234
|
-
throw new (0,
|
|
234
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
235
235
|
`chain ${network} is NEAR; wallet must be { accountId, privateKey } (privateKey = ed25519:\u2026).`
|
|
236
236
|
);
|
|
237
237
|
}
|
|
@@ -239,13 +239,13 @@ function assertNearWallet(wallet, network) {
|
|
|
239
239
|
}
|
|
240
240
|
function resolveNearWallet(config) {
|
|
241
241
|
if (!config.accountId || !config.privateKey) {
|
|
242
|
-
throw new (0,
|
|
242
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("NEAR wallet needs { accountId, privateKey } (privateKey = ed25519:\u2026).");
|
|
243
243
|
}
|
|
244
244
|
let signer;
|
|
245
245
|
try {
|
|
246
246
|
signer = _nearapijs.KeyPairSigner.fromSecretKey(config.privateKey);
|
|
247
247
|
} catch (cause) {
|
|
248
|
-
throw new (0,
|
|
248
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("NEAR wallet { privateKey } is not a valid ed25519:\u2026 secret key.", {
|
|
249
249
|
cause
|
|
250
250
|
});
|
|
251
251
|
}
|
|
@@ -295,7 +295,7 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
295
295
|
const ns = _nullishCoalesce(_optionalChain([header, 'optionalAccess', _5 => _5.timestamp_nanosec]), () => ( (_optionalChain([header, 'optionalAccess', _6 => _6.timestamp]) != null ? String(header.timestamp) : void 0)));
|
|
296
296
|
if (ns != null) timestampMs = Number(BigInt(ns) / 1000000n);
|
|
297
297
|
}
|
|
298
|
-
} catch (
|
|
298
|
+
} catch (e6) {
|
|
299
299
|
}
|
|
300
300
|
return { success, receipts, receiverId, nativeDeposit, timestampMs };
|
|
301
301
|
}
|
|
@@ -312,16 +312,16 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
312
312
|
const info = preset.tokens[token.toUpperCase()];
|
|
313
313
|
if (!info) {
|
|
314
314
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
315
|
-
throw new (0,
|
|
315
|
+
throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
|
|
316
316
|
`token "${token}" isn't built in for NEAR (known: ${known}). Pass { contractId, decimals } for a custom NEP-141.`
|
|
317
317
|
);
|
|
318
318
|
}
|
|
319
319
|
return { asset: info.contractId, decimals: info.decimals, symbol: info.symbol };
|
|
320
320
|
}
|
|
321
|
-
|
|
321
|
+
_chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "near", network);
|
|
322
322
|
const t = token;
|
|
323
323
|
if (!t.contractId || typeof t.decimals !== "number") {
|
|
324
|
-
throw new (0,
|
|
324
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
325
325
|
`chain ${network} is NEAR; a custom token must be { contractId, decimals }.`
|
|
326
326
|
);
|
|
327
327
|
}
|
|
@@ -340,12 +340,12 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
340
340
|
},
|
|
341
341
|
assertValidPayTo(payTo) {
|
|
342
342
|
if (payTo.startsWith("0x")) {
|
|
343
|
-
throw new (0,
|
|
343
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
344
344
|
`chain ${network} is NEAR, but payTo "${payTo}" looks like an EVM/Sui 0x address.`
|
|
345
345
|
);
|
|
346
346
|
}
|
|
347
347
|
if (!isValidNearAccountId(payTo)) {
|
|
348
|
-
throw new (0,
|
|
348
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
349
349
|
`chain ${network} is NEAR, but payTo "${payTo}" is not a valid NEAR account id.`
|
|
350
350
|
);
|
|
351
351
|
}
|
|
@@ -387,12 +387,12 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
387
387
|
try {
|
|
388
388
|
const tx = await reader.txStatus(hash, senderId);
|
|
389
389
|
if (tx && tx.success) return { height: "0" };
|
|
390
|
-
} catch (
|
|
390
|
+
} catch (e7) {
|
|
391
391
|
}
|
|
392
|
-
throw new (0,
|
|
392
|
+
throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`NEAR tx ${hash} not confirmed in time.`);
|
|
393
393
|
},
|
|
394
394
|
async estimateCost() {
|
|
395
|
-
return
|
|
395
|
+
return _chunkIQGT65WScjs.nativeCost.call(void 0, {
|
|
396
396
|
symbol: "NEAR",
|
|
397
397
|
decimals: NEAR_DECIMALS,
|
|
398
398
|
fee: 1500000000000000000000n,
|
|
@@ -400,6 +400,56 @@ function makeNearNetwork(preset, rpcUrl) {
|
|
|
400
400
|
detail: "~14 TGas for ft_transfer (\u22480.0015 NEAR) + 1 yoctoNEAR deposit"
|
|
401
401
|
});
|
|
402
402
|
},
|
|
403
|
+
async balanceOf(wallet, asset) {
|
|
404
|
+
let accountId;
|
|
405
|
+
try {
|
|
406
|
+
accountId = resolveNearWallet(wallet._native).accountId;
|
|
407
|
+
} catch (e8) {
|
|
408
|
+
return { token: null, native: null };
|
|
409
|
+
}
|
|
410
|
+
let native = null;
|
|
411
|
+
try {
|
|
412
|
+
const r = await provider.query({
|
|
413
|
+
request_type: "view_account",
|
|
414
|
+
finality: "final",
|
|
415
|
+
account_id: accountId
|
|
416
|
+
});
|
|
417
|
+
native = r.amount != null ? BigInt(r.amount) : null;
|
|
418
|
+
} catch (e) {
|
|
419
|
+
native = /does not exist|UNKNOWN_ACCOUNT/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _9 => _9.message]), () => ( e)))) ? 0n : null;
|
|
420
|
+
}
|
|
421
|
+
if (asset === "native") return { token: native, native };
|
|
422
|
+
let token = null;
|
|
423
|
+
try {
|
|
424
|
+
const r = await provider.query({
|
|
425
|
+
request_type: "call_function",
|
|
426
|
+
finality: "final",
|
|
427
|
+
account_id: asset,
|
|
428
|
+
method_name: "ft_balance_of",
|
|
429
|
+
args_base64: Buffer.from(JSON.stringify({ account_id: accountId })).toString("base64")
|
|
430
|
+
});
|
|
431
|
+
token = r.result ? BigInt(JSON.parse(Buffer.from(r.result).toString())) : null;
|
|
432
|
+
} catch (e) {
|
|
433
|
+
token = /does not exist|not registered|UNKNOWN_ACCOUNT/i.test(String(_nullishCoalesce(_optionalChain([e, 'optionalAccess', _10 => _10.message]), () => ( e)))) ? 0n : null;
|
|
434
|
+
}
|
|
435
|
+
return { token, native };
|
|
436
|
+
},
|
|
437
|
+
async recipientReady(payTo, asset) {
|
|
438
|
+
if (asset === "native") return { ready: "n/a" };
|
|
439
|
+
try {
|
|
440
|
+
const r = await provider.query({
|
|
441
|
+
request_type: "call_function",
|
|
442
|
+
finality: "final",
|
|
443
|
+
account_id: asset,
|
|
444
|
+
method_name: "storage_balance_of",
|
|
445
|
+
args_base64: Buffer.from(JSON.stringify({ account_id: payTo })).toString("base64")
|
|
446
|
+
});
|
|
447
|
+
const parsed = r.result ? JSON.parse(Buffer.from(r.result).toString()) : null;
|
|
448
|
+
return parsed == null ? { ready: false, reason: "NOT_REGISTERED" } : { ready: true };
|
|
449
|
+
} catch (e9) {
|
|
450
|
+
return { ready: "unknown" };
|
|
451
|
+
}
|
|
452
|
+
},
|
|
403
453
|
async verify(ref, accept) {
|
|
404
454
|
const { senderId, hash } = decodeRef(ref);
|
|
405
455
|
return verifyNear({ reader, hash, senderId, accept });
|
|
@@ -422,7 +472,7 @@ function sumTransferDeposits(actions2) {
|
|
|
422
472
|
if (t && t.deposit != null) {
|
|
423
473
|
try {
|
|
424
474
|
sum += BigInt(t.deposit);
|
|
425
|
-
} catch (
|
|
475
|
+
} catch (e10) {
|
|
426
476
|
}
|
|
427
477
|
}
|
|
428
478
|
}
|
|
@@ -5,10 +5,15 @@ import {
|
|
|
5
5
|
nativeCost,
|
|
6
6
|
rejectForeignToken,
|
|
7
7
|
toInsufficientFundsError
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-QDS6FBZP.js";
|
|
9
9
|
|
|
10
10
|
// src/drivers/solana/index.ts
|
|
11
11
|
import { Connection, PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
12
|
+
import {
|
|
13
|
+
getAccount,
|
|
14
|
+
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2,
|
|
15
|
+
TokenAccountNotFoundError
|
|
16
|
+
} from "@solana/spl-token";
|
|
12
17
|
|
|
13
18
|
// src/drivers/solana/chains.ts
|
|
14
19
|
var SOL_DECIMALS = 9;
|
|
@@ -332,6 +337,23 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
332
337
|
detail: "1 signature + recipient token-account rent (~0.00204 SOL, if not already created)"
|
|
333
338
|
});
|
|
334
339
|
},
|
|
340
|
+
async balanceOf(wallet, asset) {
|
|
341
|
+
const owner = wallet._native.publicKey;
|
|
342
|
+
const native = await connection.getBalance(owner).then((n) => BigInt(n)).catch(() => null);
|
|
343
|
+
if (asset === "native") return { token: native, native };
|
|
344
|
+
let token;
|
|
345
|
+
try {
|
|
346
|
+
const ata = getAssociatedTokenAddressSync2(new PublicKey2(asset), owner);
|
|
347
|
+
token = (await getAccount(connection, ata, "confirmed")).amount;
|
|
348
|
+
} catch (e) {
|
|
349
|
+
token = e instanceof TokenAccountNotFoundError ? 0n : null;
|
|
350
|
+
}
|
|
351
|
+
return { token, native };
|
|
352
|
+
},
|
|
353
|
+
// No receive prerequisite — the payer's tx idempotently creates the recipient's ATA (pay.ts).
|
|
354
|
+
async recipientReady() {
|
|
355
|
+
return { ready: "n/a" };
|
|
356
|
+
},
|
|
335
357
|
async verify(ref, accept) {
|
|
336
358
|
return verifySolana({ connection, signature: ref, accept });
|
|
337
359
|
}
|
|
@@ -5,11 +5,16 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
|
|
9
9
|
|
|
10
10
|
// src/drivers/solana/index.ts
|
|
11
11
|
var _web3js = require('@solana/web3.js');
|
|
12
12
|
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _spltoken = require('@solana/spl-token');
|
|
17
|
+
|
|
13
18
|
// src/drivers/solana/chains.ts
|
|
14
19
|
var SOL_DECIMALS = 9;
|
|
15
20
|
var SOLANA_MAINNET = {
|
|
@@ -39,7 +44,7 @@ var SOLANA_MAINNET = {
|
|
|
39
44
|
|
|
40
45
|
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
|
|
43
48
|
async function paySolana(params) {
|
|
44
49
|
const { connection, keypair, accept } = params;
|
|
45
50
|
const payTo = new (0, _web3js.PublicKey)(accept.payTo);
|
|
@@ -102,7 +107,7 @@ async function verifySolana(params) {
|
|
|
102
107
|
commitment: "confirmed",
|
|
103
108
|
maxSupportedTransactionVersion: 0
|
|
104
109
|
});
|
|
105
|
-
} catch (
|
|
110
|
+
} catch (e2) {
|
|
106
111
|
return notFound(signature);
|
|
107
112
|
}
|
|
108
113
|
if (!tx) return notFound(signature);
|
|
@@ -199,12 +204,12 @@ function notFound(signature) {
|
|
|
199
204
|
var _bs58 = require('bs58'); var _bs582 = _interopRequireDefault(_bs58);
|
|
200
205
|
function toKeypair(wallet, network) {
|
|
201
206
|
if (typeof wallet !== "object" || wallet === null) {
|
|
202
|
-
throw new (0,
|
|
207
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
203
208
|
`chain ${network} is Solana; wallet must be { secretKey } or { signer }.`
|
|
204
209
|
);
|
|
205
210
|
}
|
|
206
211
|
if ("privateKey" in wallet || "walletClient" in wallet) {
|
|
207
|
-
throw new (0,
|
|
212
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
208
213
|
`chain ${network} is Solana; an EVM wallet can't be used \u2014 pass { secretKey } or { signer }.`
|
|
209
214
|
);
|
|
210
215
|
}
|
|
@@ -216,7 +221,7 @@ function toKeypair(wallet, network) {
|
|
|
216
221
|
const bytes = typeof sk === "string" ? _bs582.default.decode(sk) : sk;
|
|
217
222
|
return _web3js.Keypair.fromSecretKey(bytes);
|
|
218
223
|
}
|
|
219
|
-
throw new (0,
|
|
224
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
220
225
|
`chain ${network} is Solana; wallet must be { secretKey } or { signer }.`
|
|
221
226
|
);
|
|
222
227
|
}
|
|
@@ -245,15 +250,15 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
245
250
|
const info = preset.tokens[token.toUpperCase()];
|
|
246
251
|
if (!info) {
|
|
247
252
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
248
|
-
throw new (0,
|
|
253
|
+
throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
|
|
249
254
|
`token "${token}" isn't built in for Solana (known: ${known}). Pass { mint, decimals } instead, or use 'native'.`
|
|
250
255
|
);
|
|
251
256
|
}
|
|
252
257
|
return { asset: info.mint, decimals: info.decimals, symbol: info.symbol };
|
|
253
258
|
}
|
|
254
|
-
|
|
259
|
+
_chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "solana", network);
|
|
255
260
|
if (!("mint" in token)) {
|
|
256
|
-
throw new (0,
|
|
261
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
257
262
|
`chain ${network} is Solana; a custom token must be { mint, decimals }.`
|
|
258
263
|
);
|
|
259
264
|
}
|
|
@@ -272,14 +277,14 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
272
277
|
},
|
|
273
278
|
assertValidPayTo(payTo) {
|
|
274
279
|
if (payTo.startsWith("0x")) {
|
|
275
|
-
throw new (0,
|
|
280
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
276
281
|
`chain ${network} is Solana, but payTo "${payTo}" looks like an EVM address.`
|
|
277
282
|
);
|
|
278
283
|
}
|
|
279
284
|
try {
|
|
280
285
|
new (0, _web3js.PublicKey)(payTo);
|
|
281
|
-
} catch (
|
|
282
|
-
throw new (0,
|
|
286
|
+
} catch (e3) {
|
|
287
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
283
288
|
`chain ${network} is Solana, but payTo "${payTo}" is not a base58 address.`
|
|
284
289
|
);
|
|
285
290
|
}
|
|
@@ -291,7 +296,7 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
291
296
|
try {
|
|
292
297
|
return await paySolana({ connection, keypair: wallet._native, accept });
|
|
293
298
|
} catch (err) {
|
|
294
|
-
throw _nullishCoalesce(
|
|
299
|
+
throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
295
300
|
}
|
|
296
301
|
},
|
|
297
302
|
async confirm(ref) {
|
|
@@ -302,20 +307,20 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
302
307
|
});
|
|
303
308
|
info = value[0];
|
|
304
309
|
} catch (err) {
|
|
305
|
-
throw new (0,
|
|
310
|
+
throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(
|
|
306
311
|
`Solana payment ${ref} could not be confirmed (RPC read failed).`,
|
|
307
312
|
{ cause: err }
|
|
308
313
|
);
|
|
309
314
|
}
|
|
310
315
|
if (!info || info.err || info.confirmationStatus !== "confirmed" && info.confirmationStatus !== "finalized") {
|
|
311
|
-
throw new (0,
|
|
316
|
+
throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`Solana payment ${ref} did not confirm in time.`);
|
|
312
317
|
}
|
|
313
318
|
return { height: String(info.slot) };
|
|
314
319
|
},
|
|
315
320
|
async estimateCost(accept) {
|
|
316
321
|
const base = 5000n;
|
|
317
322
|
if (accept.asset === "native") {
|
|
318
|
-
return
|
|
323
|
+
return _chunkIQGT65WScjs.nativeCost.call(void 0, {
|
|
319
324
|
symbol: "SOL",
|
|
320
325
|
decimals: SOL_DECIMALS,
|
|
321
326
|
fee: base,
|
|
@@ -324,7 +329,7 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
324
329
|
});
|
|
325
330
|
}
|
|
326
331
|
const ataRent = 2039280n;
|
|
327
|
-
return
|
|
332
|
+
return _chunkIQGT65WScjs.nativeCost.call(void 0, {
|
|
328
333
|
symbol: "SOL",
|
|
329
334
|
decimals: SOL_DECIMALS,
|
|
330
335
|
fee: base + ataRent,
|
|
@@ -332,6 +337,23 @@ function makeSolanaNetwork(preset, rpcUrl) {
|
|
|
332
337
|
detail: "1 signature + recipient token-account rent (~0.00204 SOL, if not already created)"
|
|
333
338
|
});
|
|
334
339
|
},
|
|
340
|
+
async balanceOf(wallet, asset) {
|
|
341
|
+
const owner = wallet._native.publicKey;
|
|
342
|
+
const native = await connection.getBalance(owner).then((n) => BigInt(n)).catch(() => null);
|
|
343
|
+
if (asset === "native") return { token: native, native };
|
|
344
|
+
let token;
|
|
345
|
+
try {
|
|
346
|
+
const ata = _spltoken.getAssociatedTokenAddressSync.call(void 0, new (0, _web3js.PublicKey)(asset), owner);
|
|
347
|
+
token = (await _spltoken.getAccount.call(void 0, connection, ata, "confirmed")).amount;
|
|
348
|
+
} catch (e) {
|
|
349
|
+
token = e instanceof _spltoken.TokenAccountNotFoundError ? 0n : null;
|
|
350
|
+
}
|
|
351
|
+
return { token, native };
|
|
352
|
+
},
|
|
353
|
+
// No receive prerequisite — the payer's tx idempotently creates the recipient's ATA (pay.ts).
|
|
354
|
+
async recipientReady() {
|
|
355
|
+
return { ready: "n/a" };
|
|
356
|
+
},
|
|
335
357
|
async verify(ref, accept) {
|
|
336
358
|
return verifySolana({ connection, signature: ref, accept });
|
|
337
359
|
}
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
parseUnits,
|
|
12
12
|
rejectForeignToken,
|
|
13
13
|
toInsufficientFundsError
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-QDS6FBZP.js";
|
|
15
15
|
|
|
16
16
|
// src/drivers/stellar/index.ts
|
|
17
17
|
import { Horizon, StrKey as StrKey2 } from "@stellar/stellar-sdk";
|
|
@@ -276,6 +276,10 @@ function resolveStellarWallet(config) {
|
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
// src/drivers/stellar/index.ts
|
|
279
|
+
function isStellarNotFound(e) {
|
|
280
|
+
const x = e;
|
|
281
|
+
return x?.response?.status === 404 || x?.name === "NotFoundError";
|
|
282
|
+
}
|
|
279
283
|
var stellarDriver = {
|
|
280
284
|
family: "stellar",
|
|
281
285
|
resolve(opts) {
|
|
@@ -394,6 +398,52 @@ function makeStellarNetwork(preset, rpcUrl) {
|
|
|
394
398
|
detail: "base fee 100 stroops (1 operation)"
|
|
395
399
|
});
|
|
396
400
|
},
|
|
401
|
+
async balanceOf(wallet, asset) {
|
|
402
|
+
let owner;
|
|
403
|
+
try {
|
|
404
|
+
owner = resolveStellarWallet(wallet._native).publicKey();
|
|
405
|
+
} catch {
|
|
406
|
+
return { token: null, native: null };
|
|
407
|
+
}
|
|
408
|
+
let lines;
|
|
409
|
+
try {
|
|
410
|
+
const account = await server.loadAccount(owner);
|
|
411
|
+
lines = account.balances;
|
|
412
|
+
} catch (e) {
|
|
413
|
+
return isStellarNotFound(e) ? { token: 0n, native: 0n } : { token: null, native: null };
|
|
414
|
+
}
|
|
415
|
+
const toBase = (s) => {
|
|
416
|
+
try {
|
|
417
|
+
return s != null ? parseUnits(s, STELLAR_DECIMALS) : 0n;
|
|
418
|
+
} catch {
|
|
419
|
+
return 0n;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
const native = toBase(lines.find((b) => b.asset_type === "native")?.balance);
|
|
423
|
+
if (asset === "native") return { token: native, native };
|
|
424
|
+
const parts = parseStellarAssetId(asset);
|
|
425
|
+
const line = parts ? lines.find(
|
|
426
|
+
(b) => (b.asset_type === "credit_alphanum4" || b.asset_type === "credit_alphanum12") && b.asset_code === parts.code && b.asset_issuer === parts.issuer
|
|
427
|
+
) : void 0;
|
|
428
|
+
return { token: toBase(line?.balance), native };
|
|
429
|
+
},
|
|
430
|
+
async recipientReady(payTo, asset) {
|
|
431
|
+
let lines;
|
|
432
|
+
try {
|
|
433
|
+
const account = await server.loadAccount(payTo);
|
|
434
|
+
lines = account.balances;
|
|
435
|
+
} catch (e) {
|
|
436
|
+
if (isStellarNotFound(e)) return { ready: false, reason: "INACTIVE" };
|
|
437
|
+
return { ready: "unknown" };
|
|
438
|
+
}
|
|
439
|
+
if (asset === "native") return { ready: true };
|
|
440
|
+
const parts = parseStellarAssetId(asset);
|
|
441
|
+
if (!parts) return { ready: "unknown" };
|
|
442
|
+
const hasTrustline = lines.some(
|
|
443
|
+
(b) => (b.asset_type === "credit_alphanum4" || b.asset_type === "credit_alphanum12") && b.asset_code === parts.code && b.asset_issuer === parts.issuer
|
|
444
|
+
);
|
|
445
|
+
return hasTrustline ? { ready: true } : { ready: false, reason: "NO_TRUSTLINE" };
|
|
446
|
+
},
|
|
397
447
|
async verify(_ref, accept) {
|
|
398
448
|
return verifyStellar({ reader, accept });
|
|
399
449
|
}
|