@piprail/sdk 1.3.0 → 1.4.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 +51 -0
- package/ERRORS.md +2 -2
- package/README.md +15 -9
- package/dist/algorand-IDFUG5CI.cjs +363 -0
- package/dist/algorand-XJ5OVWQB.js +363 -0
- package/dist/{aptos-MQY7KOOJ.js → aptos-AWWSCPDH.js} +6 -3
- package/dist/{aptos-T3MNKUPB.cjs → aptos-TPSOQ2VL.cjs} +21 -18
- package/dist/{chunk-YJPWIK5L.cjs → chunk-IQGT65WS.cjs} +4 -2
- package/dist/{chunk-AGKC3C7Y.js → chunk-QDS6FBZP.js} +4 -2
- package/dist/index.cjs +61 -48
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +22 -9
- package/dist/{near-DISWUB7Y.cjs → near-KDA5DPTX.cjs} +19 -19
- package/dist/{near-YX3XOASO.js → near-NOJTO4GX.js} +1 -1
- package/dist/{solana-RJPNEFSN.cjs → solana-DVA6I55L.cjs} +14 -14
- package/dist/{solana-37F2PR5H.js → solana-HNRTS4KM.js} +1 -1
- package/dist/{stellar-SUGNX52Z.cjs → stellar-4D5EWT3V.cjs} +20 -20
- package/dist/{stellar-ALOVOMFD.js → stellar-4TDVVJYO.js} +1 -1
- package/dist/{sui-HZWPHVU4.cjs → sui-5HMIHOZK.cjs} +17 -17
- package/dist/{sui-OLC5ID4X.js → sui-ALUTM5GX.js} +1 -1
- package/dist/{ton-NIDWF77T.js → ton-3XMIM2FU.js} +1 -1
- package/dist/{ton-C4KTFXDL.cjs → ton-TVK4TEDX.cjs} +14 -14
- package/dist/{tron-LPMK57H7.js → tron-6D65YJEU.js} +1 -1
- package/dist/{tron-DTU7NPEM.cjs → tron-Y5RZJZRT.cjs} +24 -24
- package/dist/{xrpl-N6ZAJRGC.cjs → xrpl-ICO6G7UK.cjs} +20 -20
- package/dist/{xrpl-6ODQS7JR.js → xrpl-ISFG3SSN.js} +1 -1
- package/package.json +9 -2
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfirmationTimeoutError,
|
|
3
|
+
InsufficientFundsError,
|
|
4
|
+
RecipientNotReadyError,
|
|
5
|
+
UnknownTokenError,
|
|
6
|
+
WrongFamilyError,
|
|
7
|
+
nativeCost,
|
|
8
|
+
rejectForeignToken,
|
|
9
|
+
toInsufficientFundsError
|
|
10
|
+
} from "./chunk-QDS6FBZP.js";
|
|
11
|
+
|
|
12
|
+
// src/drivers/algorand/index.ts
|
|
13
|
+
import algosdk2 from "algosdk";
|
|
14
|
+
|
|
15
|
+
// src/drivers/algorand/chains.ts
|
|
16
|
+
var ALGO_DECIMALS = 6;
|
|
17
|
+
var ALGO_SYMBOL = "ALGO";
|
|
18
|
+
var ALGORAND_MAINNET = {
|
|
19
|
+
caip2: "algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73k",
|
|
20
|
+
defaultAlgod: "https://mainnet-api.algonode.cloud",
|
|
21
|
+
defaultIndexer: "https://mainnet-idx.algonode.cloud",
|
|
22
|
+
tokens: {
|
|
23
|
+
// Circle USDC — ASA id + 6 decimals verified live on mainnet algod
|
|
24
|
+
// (/v2/assets/31566704 → unit-name "USDC", decimals 6, creator = Circle) before shipping.
|
|
25
|
+
// USDC-only: Tether deprecated USDT on Algorand, so it's intentionally omitted.
|
|
26
|
+
USDC: { assetId: 31566704, decimals: 6, symbol: "USDC" }
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
function algorandAssetId(assetId) {
|
|
30
|
+
return String(assetId);
|
|
31
|
+
}
|
|
32
|
+
function parseAlgorandAssetId(asset) {
|
|
33
|
+
if (asset === "native") return null;
|
|
34
|
+
if (!/^\d+$/.test(asset)) return null;
|
|
35
|
+
const n = Number(asset);
|
|
36
|
+
return Number.isSafeInteger(n) && n > 0 ? n : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/drivers/algorand/pay.ts
|
|
40
|
+
async function payAlgorand(params) {
|
|
41
|
+
const { client, sk, sender, accept } = params;
|
|
42
|
+
const note = new TextEncoder().encode(accept.extra.nonce);
|
|
43
|
+
const amount = BigInt(accept.amount);
|
|
44
|
+
const assetId = parseAlgorandAssetId(accept.asset);
|
|
45
|
+
try {
|
|
46
|
+
const { txn, txId } = await client.build({
|
|
47
|
+
sender,
|
|
48
|
+
receiver: accept.payTo,
|
|
49
|
+
amount,
|
|
50
|
+
note,
|
|
51
|
+
...assetId === null ? {} : { assetId }
|
|
52
|
+
});
|
|
53
|
+
await client.signSend({ txn, sk });
|
|
54
|
+
return txId;
|
|
55
|
+
} catch (err) {
|
|
56
|
+
const mapped = mapAlgorandError(err, accept.payTo);
|
|
57
|
+
if (mapped) throw mapped;
|
|
58
|
+
throw toInsufficientFundsError(err) ?? err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function mapAlgorandError(err, payTo) {
|
|
62
|
+
const m = err instanceof Error ? err.message : String(err);
|
|
63
|
+
if (/must optin/i.test(m) || /missing from/i.test(m) && m.includes(payTo)) {
|
|
64
|
+
return new RecipientNotReadyError(
|
|
65
|
+
`Algorand recipient ${payTo} hasn't opted into this asset \u2014 it must opt in (a 0-amount asset transfer to itself) before it can receive. (Algorand: ${firstLine(m)})`,
|
|
66
|
+
{ cause: err }
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
if (/overspend|below min|min(imum)? balance|tried to spend|balance \d+ below|asset \d+ missing from|insufficient|underflow/i.test(
|
|
70
|
+
m
|
|
71
|
+
)) {
|
|
72
|
+
return new InsufficientFundsError(
|
|
73
|
+
`Algorand payment failed: the sender can't cover it \u2014 token balance, ALGO for fees, the 0.1-ALGO minimum balance, or a missing asset opt-in on the sender. (Algorand: ${firstLine(m)})`,
|
|
74
|
+
{ cause: err }
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
function firstLine(message) {
|
|
80
|
+
return message.split("\n")[0].slice(0, 160);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/drivers/algorand/verify.ts
|
|
84
|
+
async function verifyAlgorand(params) {
|
|
85
|
+
const { reader, accept } = params;
|
|
86
|
+
const nonce = accept.extra.nonce;
|
|
87
|
+
const required = BigInt(accept.amount);
|
|
88
|
+
const wantAssetId = parseAlgorandAssetId(accept.asset);
|
|
89
|
+
let txs;
|
|
90
|
+
try {
|
|
91
|
+
txs = await reader.transactionsForAccount(accept.payTo, 50);
|
|
92
|
+
} catch {
|
|
93
|
+
return rpcFailed(nonce);
|
|
94
|
+
}
|
|
95
|
+
const tx = txs.find((t) => typeof t.note === "string" && t.note === nonce);
|
|
96
|
+
if (!tx) return notFound(nonce);
|
|
97
|
+
if (typeof tx.roundTime === "number") {
|
|
98
|
+
const ageSeconds = Math.floor(Date.now() / 1e3) - tx.roundTime;
|
|
99
|
+
if (Number.isFinite(ageSeconds) && ageSeconds > accept.maxTimeoutSeconds) {
|
|
100
|
+
return {
|
|
101
|
+
ok: false,
|
|
102
|
+
error: "payment_expired",
|
|
103
|
+
detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const isNative = wantAssetId === null;
|
|
108
|
+
const typeOk = isNative ? tx.txType === "pay" : tx.txType === "axfer";
|
|
109
|
+
const assetOk = isNative ? tx.assetId == null : tx.assetId === wantAssetId;
|
|
110
|
+
if (!typeOk || tx.receiver !== accept.payTo || !assetOk) {
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
error: "transfer_not_found",
|
|
114
|
+
detail: `Algorand tx ${tx.id} carries our nonce but has no matching ${isNative ? "ALGO" : `ASA ${wantAssetId}`} transfer to ${accept.payTo}.`
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
let paid = 0n;
|
|
118
|
+
try {
|
|
119
|
+
paid = tx.amount ? BigInt(tx.amount) : 0n;
|
|
120
|
+
} catch {
|
|
121
|
+
paid = 0n;
|
|
122
|
+
}
|
|
123
|
+
if (paid < required) {
|
|
124
|
+
return { ok: false, error: "amount_too_low", detail: `Paid ${paid}, required ${required}.` };
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
ok: true,
|
|
128
|
+
receipt: {
|
|
129
|
+
scheme: "onchain-proof",
|
|
130
|
+
success: true,
|
|
131
|
+
network: accept.network,
|
|
132
|
+
transaction: tx.id,
|
|
133
|
+
asset: accept.asset,
|
|
134
|
+
amount: accept.amount,
|
|
135
|
+
payer: tx.sender ?? "",
|
|
136
|
+
payTo: accept.payTo,
|
|
137
|
+
verifiedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function notFound(nonce) {
|
|
142
|
+
return {
|
|
143
|
+
ok: false,
|
|
144
|
+
error: "transfer_not_found",
|
|
145
|
+
detail: `No matching Algorand payment found for nonce ${nonce} (not yet settled, or wrong recipient/amount/asset/note).`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function rpcFailed(nonce) {
|
|
149
|
+
return {
|
|
150
|
+
ok: false,
|
|
151
|
+
error: "tx_not_found",
|
|
152
|
+
detail: `Could not read the Algorand indexer for nonce ${nonce} (transient RPC failure) \u2014 retry.`
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/drivers/algorand/wallet.ts
|
|
157
|
+
import algosdk from "algosdk";
|
|
158
|
+
function assertAlgorandWallet(wallet, network) {
|
|
159
|
+
if (typeof wallet !== "object" || wallet === null) {
|
|
160
|
+
throw new WrongFamilyError(
|
|
161
|
+
`chain ${network} is Algorand; wallet must be { mnemonic } (25 words) or { account }.`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
if ("privateKey" in wallet || "walletClient" in wallet) {
|
|
165
|
+
throw new WrongFamilyError(
|
|
166
|
+
`chain ${network} is Algorand; an EVM/Aptos wallet can't be used \u2014 pass { mnemonic } (25 words) or { account }.`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
if ("secretKey" in wallet || "signer" in wallet || "secret" in wallet || "keypair" in wallet || "keyPair" in wallet || "seed" in wallet || "accountId" in wallet) {
|
|
170
|
+
throw new WrongFamilyError(
|
|
171
|
+
`chain ${network} is Algorand; that looks like another family's wallet \u2014 pass { mnemonic } (25 words) or { account }.`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
if (!("mnemonic" in wallet) && !("account" in wallet)) {
|
|
175
|
+
throw new WrongFamilyError(
|
|
176
|
+
`chain ${network} is Algorand; wallet must be { mnemonic } (25 words) or { account }.`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return wallet;
|
|
180
|
+
}
|
|
181
|
+
function resolveAlgorandWallet(config) {
|
|
182
|
+
if (config.account) {
|
|
183
|
+
return { addr: String(config.account.addr), sk: config.account.sk };
|
|
184
|
+
}
|
|
185
|
+
if (config.mnemonic != null) {
|
|
186
|
+
try {
|
|
187
|
+
const { addr, sk } = algosdk.mnemonicToSecretKey(config.mnemonic);
|
|
188
|
+
return { addr: addr.toString(), sk };
|
|
189
|
+
} catch (cause) {
|
|
190
|
+
throw new WrongFamilyError(
|
|
191
|
+
"Algorand wallet { mnemonic } is not a valid 25-word Algorand mnemonic.",
|
|
192
|
+
{ cause }
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
throw new WrongFamilyError("Algorand wallet needs { mnemonic } (25 words) or { account }.");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/drivers/algorand/index.ts
|
|
200
|
+
var algorandDriver = {
|
|
201
|
+
family: "algorand",
|
|
202
|
+
resolve(opts) {
|
|
203
|
+
if (opts.chain !== "algorand") return null;
|
|
204
|
+
const algodUrl = opts.rpcUrl ?? ALGORAND_MAINNET.defaultAlgod;
|
|
205
|
+
return makeAlgorandNetwork(ALGORAND_MAINNET, algodUrl);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
function makeAlgorandNetwork(preset, algodUrl) {
|
|
209
|
+
const algod = new algosdk2.Algodv2("", algodUrl, "");
|
|
210
|
+
const indexer = new algosdk2.Indexer("", preset.defaultIndexer, "");
|
|
211
|
+
const network = preset.caip2;
|
|
212
|
+
const reader = {
|
|
213
|
+
async transactionsForAccount(account, limit) {
|
|
214
|
+
const res = await indexer.lookupAccountTransactions(account).limit(limit).do();
|
|
215
|
+
return (res.transactions ?? []).map((t) => adaptTxn(t)).filter((r) => r !== null);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
const payClient = {
|
|
219
|
+
async build(transfer) {
|
|
220
|
+
const suggestedParams = await algod.getTransactionParams().do();
|
|
221
|
+
const common = {
|
|
222
|
+
sender: transfer.sender,
|
|
223
|
+
receiver: transfer.receiver,
|
|
224
|
+
amount: transfer.amount,
|
|
225
|
+
note: transfer.note,
|
|
226
|
+
suggestedParams
|
|
227
|
+
};
|
|
228
|
+
const txn = transfer.assetId === void 0 ? algosdk2.makePaymentTxnWithSuggestedParamsFromObject(common) : algosdk2.makeAssetTransferTxnWithSuggestedParamsFromObject({
|
|
229
|
+
...common,
|
|
230
|
+
assetIndex: transfer.assetId
|
|
231
|
+
});
|
|
232
|
+
return { txn, txId: txn.txID() };
|
|
233
|
+
},
|
|
234
|
+
async signSend({ txn, sk }) {
|
|
235
|
+
const signed = txn.signTxn(sk);
|
|
236
|
+
await algod.sendRawTransaction(signed).do();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
family: "algorand",
|
|
241
|
+
network,
|
|
242
|
+
supports: (n) => n === network,
|
|
243
|
+
resolveToken(token) {
|
|
244
|
+
if (token === "native") {
|
|
245
|
+
return { asset: "native", decimals: ALGO_DECIMALS, symbol: ALGO_SYMBOL };
|
|
246
|
+
}
|
|
247
|
+
if (typeof token === "string") {
|
|
248
|
+
const info = preset.tokens[token.toUpperCase()];
|
|
249
|
+
if (!info) {
|
|
250
|
+
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
251
|
+
throw new UnknownTokenError(
|
|
252
|
+
`token "${token}" isn't built in for Algorand (known: ${known}). Pass { assetId, decimals } for a custom ASA, or use 'native'.`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
return { asset: algorandAssetId(info.assetId), decimals: info.decimals, symbol: info.symbol };
|
|
256
|
+
}
|
|
257
|
+
rejectForeignToken(token, "algorand", network);
|
|
258
|
+
const t = token;
|
|
259
|
+
if (typeof t.assetId !== "number" || typeof t.decimals !== "number") {
|
|
260
|
+
throw new WrongFamilyError(
|
|
261
|
+
`chain ${network} is Algorand; a custom token must be { assetId, decimals }.`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
asset: algorandAssetId(t.assetId),
|
|
266
|
+
decimals: t.decimals,
|
|
267
|
+
...t.symbol ? { symbol: t.symbol } : {}
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
describeAsset(asset) {
|
|
271
|
+
if (asset === "native") return { symbol: ALGO_SYMBOL, decimals: ALGO_DECIMALS };
|
|
272
|
+
for (const info of Object.values(preset.tokens)) {
|
|
273
|
+
if (algorandAssetId(info.assetId) === asset) {
|
|
274
|
+
return { symbol: info.symbol, decimals: info.decimals };
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return null;
|
|
278
|
+
},
|
|
279
|
+
assertValidPayTo(payTo) {
|
|
280
|
+
if (payTo.startsWith("0x")) {
|
|
281
|
+
throw new WrongFamilyError(
|
|
282
|
+
`chain ${network} is Algorand, but payTo "${payTo}" looks like an EVM address.`
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
if (!algosdk2.isValidAddress(payTo)) {
|
|
286
|
+
throw new WrongFamilyError(
|
|
287
|
+
`chain ${network} is Algorand, but payTo "${payTo}" is not a valid Algorand address.`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
bindWallet(wallet) {
|
|
292
|
+
return { _native: assertAlgorandWallet(wallet, network) };
|
|
293
|
+
},
|
|
294
|
+
async send(wallet, accept) {
|
|
295
|
+
const signer = resolveAlgorandWallet(wallet._native);
|
|
296
|
+
return payAlgorand({ client: payClient, sk: signer.sk, sender: signer.addr, accept });
|
|
297
|
+
},
|
|
298
|
+
async confirm(ref) {
|
|
299
|
+
try {
|
|
300
|
+
const info = await algosdk2.waitForConfirmation(algod, ref, 10);
|
|
301
|
+
return { height: String(info.confirmedRound ?? 0) };
|
|
302
|
+
} catch (err) {
|
|
303
|
+
throw new ConfirmationTimeoutError(`Algorand tx ${ref} did not confirm in time.`, {
|
|
304
|
+
cause: err
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
async estimateCost() {
|
|
309
|
+
return nativeCost({
|
|
310
|
+
symbol: ALGO_SYMBOL,
|
|
311
|
+
decimals: ALGO_DECIMALS,
|
|
312
|
+
fee: 1000n,
|
|
313
|
+
basis: "heuristic",
|
|
314
|
+
detail: "min fee 1000 \xB5Algos (1 transaction)"
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
async verify(_ref, accept) {
|
|
318
|
+
return verifyAlgorand({ reader, accept });
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function adaptTxn(raw) {
|
|
323
|
+
const t = raw;
|
|
324
|
+
if (!t || typeof t.id !== "string") return null;
|
|
325
|
+
const note = t.note && t.note.length ? decodeNote(t.note) : void 0;
|
|
326
|
+
const base = {
|
|
327
|
+
id: t.id,
|
|
328
|
+
txType: String(t.txType ?? ""),
|
|
329
|
+
...note !== void 0 ? { note } : {},
|
|
330
|
+
...t.sender != null ? { sender: String(t.sender) } : {},
|
|
331
|
+
...typeof t.roundTime === "number" ? { roundTime: t.roundTime } : {}
|
|
332
|
+
};
|
|
333
|
+
if (t.paymentTransaction) {
|
|
334
|
+
const pt = t.paymentTransaction;
|
|
335
|
+
return {
|
|
336
|
+
...base,
|
|
337
|
+
txType: "pay",
|
|
338
|
+
...pt.receiver != null ? { receiver: String(pt.receiver) } : {},
|
|
339
|
+
...pt.amount != null ? { amount: String(pt.amount) } : {}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
if (t.assetTransferTransaction) {
|
|
343
|
+
const att = t.assetTransferTransaction;
|
|
344
|
+
return {
|
|
345
|
+
...base,
|
|
346
|
+
txType: "axfer",
|
|
347
|
+
...att.receiver != null ? { receiver: String(att.receiver) } : {},
|
|
348
|
+
...att.amount != null ? { amount: String(att.amount) } : {},
|
|
349
|
+
...att.assetId != null ? { assetId: Number(att.assetId) } : {}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return base;
|
|
353
|
+
}
|
|
354
|
+
function decodeNote(bytes) {
|
|
355
|
+
try {
|
|
356
|
+
return new TextDecoder().decode(bytes);
|
|
357
|
+
} catch {
|
|
358
|
+
return void 0;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
export {
|
|
362
|
+
algorandDriver
|
|
363
|
+
};
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
nativeCost,
|
|
7
7
|
rejectForeignToken,
|
|
8
8
|
toInsufficientFundsError
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-QDS6FBZP.js";
|
|
10
10
|
|
|
11
11
|
// src/drivers/aptos/index.ts
|
|
12
12
|
import { Aptos, AptosConfig, Network, AccountAddress } from "@aptos-labs/ts-sdk";
|
|
@@ -37,6 +37,7 @@ var APTOS_MAINNET = {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// src/drivers/aptos/pay.ts
|
|
40
|
+
var MAX_GAS_AMOUNT = 5e4;
|
|
40
41
|
async function payAptos(params) {
|
|
41
42
|
const { client, signer, sender, accept } = params;
|
|
42
43
|
const metadata = accept.asset === "native" ? APT_FA_METADATA : accept.asset;
|
|
@@ -48,7 +49,8 @@ async function payAptos(params) {
|
|
|
48
49
|
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
49
50
|
// u64 amount goes as a base-unit string; the FA metadata object + recipient are addresses.
|
|
50
51
|
functionArguments: [metadata, accept.payTo, accept.amount]
|
|
51
|
-
}
|
|
52
|
+
},
|
|
53
|
+
options: { maxGasAmount: MAX_GAS_AMOUNT }
|
|
52
54
|
});
|
|
53
55
|
const res = await client.signSubmit({ signer, transaction });
|
|
54
56
|
return res.hash;
|
|
@@ -227,7 +229,8 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
227
229
|
build: (input) => aptos.transaction.build.simple({
|
|
228
230
|
sender: input.sender,
|
|
229
231
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
|
-
data: input.data
|
|
232
|
+
data: input.data,
|
|
233
|
+
...input.options ? { options: input.options } : {}
|
|
231
234
|
}),
|
|
232
235
|
signSubmit: (input) => aptos.signAndSubmitTransaction({
|
|
233
236
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkIQGT65WScjs = require('./chunk-IQGT65WS.cjs');
|
|
10
10
|
|
|
11
11
|
// src/drivers/aptos/index.ts
|
|
12
12
|
var _tssdk = require('@aptos-labs/ts-sdk');
|
|
@@ -37,6 +37,7 @@ var APTOS_MAINNET = {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// src/drivers/aptos/pay.ts
|
|
40
|
+
var MAX_GAS_AMOUNT = 5e4;
|
|
40
41
|
async function payAptos(params) {
|
|
41
42
|
const { client, signer, sender, accept } = params;
|
|
42
43
|
const metadata = accept.asset === "native" ? APT_FA_METADATA : accept.asset;
|
|
@@ -48,19 +49,20 @@ async function payAptos(params) {
|
|
|
48
49
|
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
49
50
|
// u64 amount goes as a base-unit string; the FA metadata object + recipient are addresses.
|
|
50
51
|
functionArguments: [metadata, accept.payTo, accept.amount]
|
|
51
|
-
}
|
|
52
|
+
},
|
|
53
|
+
options: { maxGasAmount: MAX_GAS_AMOUNT }
|
|
52
54
|
});
|
|
53
55
|
const res = await client.signSubmit({ signer, transaction });
|
|
54
56
|
return res.hash;
|
|
55
57
|
} catch (err) {
|
|
56
|
-
if (err instanceof
|
|
58
|
+
if (err instanceof _chunkIQGT65WScjs.InsufficientFundsError) throw err;
|
|
57
59
|
if (isAptosAffordability(err)) {
|
|
58
|
-
throw new (0,
|
|
60
|
+
throw new (0, _chunkIQGT65WScjs.InsufficientFundsError)(
|
|
59
61
|
err instanceof Error ? err.message : "Insufficient APT/token balance for the payment.",
|
|
60
62
|
{ cause: err }
|
|
61
63
|
);
|
|
62
64
|
}
|
|
63
|
-
throw _nullishCoalesce(
|
|
65
|
+
throw _nullishCoalesce(_chunkIQGT65WScjs.toInsufficientFundsError.call(void 0, err), () => ( err));
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
function isAptosAffordability(err) {
|
|
@@ -144,22 +146,22 @@ function txNotFound(hash) {
|
|
|
144
146
|
|
|
145
147
|
function assertAptosWallet(wallet, network) {
|
|
146
148
|
if (typeof wallet !== "object" || wallet === null) {
|
|
147
|
-
throw new (0,
|
|
149
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
148
150
|
`chain ${network} is Aptos; wallet must be { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
149
151
|
);
|
|
150
152
|
}
|
|
151
153
|
if ("walletClient" in wallet) {
|
|
152
|
-
throw new (0,
|
|
154
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
153
155
|
`chain ${network} is Aptos; a viem { walletClient } can't be used \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
154
156
|
);
|
|
155
157
|
}
|
|
156
158
|
if ("secretKey" in wallet || "signer" in wallet || "mnemonic" in wallet || "keypair" in wallet || "keyPair" in wallet || "secret" in wallet || "seed" in wallet || "accountId" in wallet) {
|
|
157
|
-
throw new (0,
|
|
159
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
158
160
|
`chain ${network} is Aptos; that looks like another family's wallet \u2014 pass { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
159
161
|
);
|
|
160
162
|
}
|
|
161
163
|
if (!("privateKey" in wallet) && !("account" in wallet)) {
|
|
162
|
-
throw new (0,
|
|
164
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
163
165
|
`chain ${network} is Aptos; wallet must be { privateKey } (ed25519-priv-0x\u2026) or { account }.`
|
|
164
166
|
);
|
|
165
167
|
}
|
|
@@ -171,13 +173,13 @@ function resolveAptosAccount(config) {
|
|
|
171
173
|
try {
|
|
172
174
|
return _tssdk.Account.fromPrivateKey({ privateKey: new (0, _tssdk.Ed25519PrivateKey)(config.privateKey) });
|
|
173
175
|
} catch (cause) {
|
|
174
|
-
throw new (0,
|
|
176
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
175
177
|
"Aptos wallet { privateKey } is not a valid ed25519 secret (ed25519-priv-0x\u2026 or 0x\u2026 hex).",
|
|
176
178
|
{ cause }
|
|
177
179
|
);
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
|
-
throw new (0,
|
|
182
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)("Aptos wallet needs { privateKey } (ed25519-priv-0x\u2026) or { account }.");
|
|
181
183
|
}
|
|
182
184
|
|
|
183
185
|
// src/drivers/aptos/index.ts
|
|
@@ -227,7 +229,8 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
227
229
|
build: (input) => aptos.transaction.build.simple({
|
|
228
230
|
sender: input.sender,
|
|
229
231
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
230
|
-
data: input.data
|
|
232
|
+
data: input.data,
|
|
233
|
+
...input.options ? { options: input.options } : {}
|
|
231
234
|
}),
|
|
232
235
|
signSubmit: (input) => aptos.signAndSubmitTransaction({
|
|
233
236
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -248,16 +251,16 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
248
251
|
const info = preset.tokens[token.toUpperCase()];
|
|
249
252
|
if (!info) {
|
|
250
253
|
const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
|
|
251
|
-
throw new (0,
|
|
254
|
+
throw new (0, _chunkIQGT65WScjs.UnknownTokenError)(
|
|
252
255
|
`token "${token}" isn't built in for Aptos (known: ${known}). Pass { metadata, decimals } for a custom Fungible Asset, or use 'native'.`
|
|
253
256
|
);
|
|
254
257
|
}
|
|
255
258
|
return { asset: info.metadata, decimals: info.decimals, symbol: info.symbol };
|
|
256
259
|
}
|
|
257
|
-
|
|
260
|
+
_chunkIQGT65WScjs.rejectForeignToken.call(void 0, token, "aptos", network);
|
|
258
261
|
const t = token;
|
|
259
262
|
if (!t.metadata || typeof t.decimals !== "number") {
|
|
260
|
-
throw new (0,
|
|
263
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
261
264
|
`chain ${network} is Aptos; a custom token must be { metadata, decimals }.`
|
|
262
265
|
);
|
|
263
266
|
}
|
|
@@ -284,7 +287,7 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
284
287
|
valid = false;
|
|
285
288
|
}
|
|
286
289
|
if (!valid || evmLike) {
|
|
287
|
-
throw new (0,
|
|
290
|
+
throw new (0, _chunkIQGT65WScjs.WrongFamilyError)(
|
|
288
291
|
`chain ${network} is Aptos, but payTo "${payTo}" is not a valid Aptos address (0x + 32 bytes).`
|
|
289
292
|
);
|
|
290
293
|
}
|
|
@@ -306,11 +309,11 @@ function makeAptosNetwork(preset, rpcUrl) {
|
|
|
306
309
|
const tx = await aptos.waitForTransaction({ transactionHash: ref });
|
|
307
310
|
return { height: String(_nullishCoalesce(tx.version, () => ( "0"))) };
|
|
308
311
|
} catch (err) {
|
|
309
|
-
throw new (0,
|
|
312
|
+
throw new (0, _chunkIQGT65WScjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
|
|
310
313
|
}
|
|
311
314
|
},
|
|
312
315
|
async estimateCost() {
|
|
313
|
-
return
|
|
316
|
+
return _chunkIQGT65WScjs.nativeCost.call(void 0, {
|
|
314
317
|
symbol: APT_SYMBOL,
|
|
315
318
|
decimals: APT_DECIMALS,
|
|
316
319
|
fee: 100000n,
|
|
@@ -82,7 +82,8 @@ var FAMILY_LABEL = {
|
|
|
82
82
|
tron: "Tron",
|
|
83
83
|
sui: "Sui",
|
|
84
84
|
near: "NEAR",
|
|
85
|
-
aptos: "Aptos"
|
|
85
|
+
aptos: "Aptos",
|
|
86
|
+
algorand: "Algorand"
|
|
86
87
|
};
|
|
87
88
|
var FAMILY_TOKEN = {
|
|
88
89
|
evm: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
|
|
@@ -93,7 +94,8 @@ var FAMILY_TOKEN = {
|
|
|
93
94
|
tron: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
|
|
94
95
|
sui: { key: "coinType", shape: "{ coinType }", hint: "{ coinType, decimals }" },
|
|
95
96
|
near: { key: "contractId", shape: "{ contractId }", hint: "{ contractId, decimals }" },
|
|
96
|
-
aptos: { key: "metadata", shape: "{ metadata }", hint: "{ metadata, decimals }" }
|
|
97
|
+
aptos: { key: "metadata", shape: "{ metadata }", hint: "{ metadata, decimals }" },
|
|
98
|
+
algorand: { key: "assetId", shape: "{ assetId }", hint: "{ assetId, decimals }" }
|
|
97
99
|
};
|
|
98
100
|
function rejectForeignToken(token, family, network) {
|
|
99
101
|
const own = FAMILY_TOKEN[family];
|
|
@@ -82,7 +82,8 @@ var FAMILY_LABEL = {
|
|
|
82
82
|
tron: "Tron",
|
|
83
83
|
sui: "Sui",
|
|
84
84
|
near: "NEAR",
|
|
85
|
-
aptos: "Aptos"
|
|
85
|
+
aptos: "Aptos",
|
|
86
|
+
algorand: "Algorand"
|
|
86
87
|
};
|
|
87
88
|
var FAMILY_TOKEN = {
|
|
88
89
|
evm: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
|
|
@@ -93,7 +94,8 @@ var FAMILY_TOKEN = {
|
|
|
93
94
|
tron: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
|
|
94
95
|
sui: { key: "coinType", shape: "{ coinType }", hint: "{ coinType, decimals }" },
|
|
95
96
|
near: { key: "contractId", shape: "{ contractId }", hint: "{ contractId, decimals }" },
|
|
96
|
-
aptos: { key: "metadata", shape: "{ metadata }", hint: "{ metadata, decimals }" }
|
|
97
|
+
aptos: { key: "metadata", shape: "{ metadata }", hint: "{ metadata, decimals }" },
|
|
98
|
+
algorand: { key: "assetId", shape: "{ assetId }", hint: "{ assetId, decimals }" }
|
|
97
99
|
};
|
|
98
100
|
function rejectForeignToken(token, family, network) {
|
|
99
101
|
const own = FAMILY_TOKEN[family];
|