moltspay 1.5.0 → 1.6.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/README.md +142 -0
- package/dist/cli/index.js +476 -144
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +473 -141
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/index.d.mts +5 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +235 -108
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +231 -106
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/web/index.d.mts +418 -0
- package/dist/client/web/index.mjs +1289 -0
- package/dist/client/web/index.mjs.map +1 -0
- package/dist/facilitators/index.d.mts +24 -2
- package/dist/facilitators/index.d.ts +24 -2
- package/dist/facilitators/index.js +127 -13
- package/dist/facilitators/index.js.map +1 -1
- package/dist/facilitators/index.mjs +127 -13
- package/dist/facilitators/index.mjs.map +1 -1
- package/dist/index.js +453 -141
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +450 -138
- package/dist/index.mjs.map +1 -1
- package/dist/mcp/index.js +234 -109
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/index.mjs +231 -106
- package/dist/mcp/index.mjs.map +1 -1
- package/dist/server/index.d.mts +43 -1
- package/dist/server/index.d.ts +43 -1
- package/dist/server/index.js +205 -18
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +205 -18
- package/dist/server/index.mjs.map +1 -1
- package/package.json +9 -2
package/dist/mcp/index.js
CHANGED
|
@@ -33,11 +33,11 @@ var import_path3 = require("path");
|
|
|
33
33
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
34
34
|
var import_zod = require("zod");
|
|
35
35
|
|
|
36
|
-
// src/client/index.ts
|
|
36
|
+
// src/client/node/index.ts
|
|
37
37
|
var import_fs2 = require("fs");
|
|
38
38
|
var import_os2 = require("os");
|
|
39
39
|
var import_path2 = require("path");
|
|
40
|
-
var
|
|
40
|
+
var import_ethers2 = require("ethers");
|
|
41
41
|
|
|
42
42
|
// src/chains/index.ts
|
|
43
43
|
var CHAINS = {
|
|
@@ -278,16 +278,16 @@ function loadSolanaWallet(configDir = DEFAULT_CONFIG_DIR) {
|
|
|
278
278
|
// src/facilitators/solana.ts
|
|
279
279
|
var import_web33 = require("@solana/web3.js");
|
|
280
280
|
var import_spl_token2 = require("@solana/spl-token");
|
|
281
|
-
async function createSolanaPaymentTransaction(senderPubkey, recipientPubkey, amount, chain, feePayerPubkey) {
|
|
281
|
+
async function createSolanaPaymentTransaction(senderPubkey, recipientPubkey, amount, chain, feePayerPubkey, connection) {
|
|
282
282
|
const chainConfig = SOLANA_CHAINS[chain];
|
|
283
|
-
const
|
|
283
|
+
const conn = connection ?? new import_web33.Connection(chainConfig.rpc, "confirmed");
|
|
284
284
|
const mint = new import_web33.PublicKey(chainConfig.tokens.USDC.mint);
|
|
285
285
|
const actualFeePayer = feePayerPubkey || senderPubkey;
|
|
286
286
|
const senderATA = await (0, import_spl_token2.getAssociatedTokenAddress)(mint, senderPubkey);
|
|
287
287
|
const recipientATA = await (0, import_spl_token2.getAssociatedTokenAddress)(mint, recipientPubkey);
|
|
288
288
|
const transaction = new import_web33.Transaction();
|
|
289
289
|
try {
|
|
290
|
-
await (0, import_spl_token2.getAccount)(
|
|
290
|
+
await (0, import_spl_token2.getAccount)(conn, recipientATA);
|
|
291
291
|
} catch {
|
|
292
292
|
transaction.add(
|
|
293
293
|
(0, import_spl_token2.createAssociatedTokenAccountInstruction)(
|
|
@@ -318,17 +318,178 @@ async function createSolanaPaymentTransaction(senderPubkey, recipientPubkey, amo
|
|
|
318
318
|
// decimals
|
|
319
319
|
)
|
|
320
320
|
);
|
|
321
|
-
const { blockhash, lastValidBlockHeight } = await
|
|
321
|
+
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
322
322
|
transaction.recentBlockhash = blockhash;
|
|
323
323
|
transaction.feePayer = actualFeePayer;
|
|
324
324
|
return transaction;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
// src/client/index.ts
|
|
328
|
-
var
|
|
327
|
+
// src/client/node/index.ts
|
|
328
|
+
var import_web35 = require("@solana/web3.js");
|
|
329
|
+
|
|
330
|
+
// src/client/core/types.ts
|
|
329
331
|
var X402_VERSION = 2;
|
|
330
332
|
var PAYMENT_REQUIRED_HEADER = "x-payment-required";
|
|
331
333
|
var PAYMENT_HEADER = "x-payment";
|
|
334
|
+
|
|
335
|
+
// src/client/core/chain-map.ts
|
|
336
|
+
var NETWORK_TO_CHAIN = {
|
|
337
|
+
"eip155:8453": "base",
|
|
338
|
+
"eip155:137": "polygon",
|
|
339
|
+
"eip155:84532": "base_sepolia",
|
|
340
|
+
"eip155:42431": "tempo_moderato",
|
|
341
|
+
"eip155:56": "bnb",
|
|
342
|
+
"eip155:97": "bnb_testnet",
|
|
343
|
+
"solana:mainnet": "solana",
|
|
344
|
+
"solana:devnet": "solana_devnet"
|
|
345
|
+
};
|
|
346
|
+
var CHAIN_TO_NETWORK = Object.fromEntries(
|
|
347
|
+
Object.entries(NETWORK_TO_CHAIN).map(([network, chain]) => [chain, network])
|
|
348
|
+
);
|
|
349
|
+
function networkToChainName(network) {
|
|
350
|
+
return NETWORK_TO_CHAIN[network] ?? null;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/client/core/base64.ts
|
|
354
|
+
var BufferCtor = globalThis.Buffer;
|
|
355
|
+
|
|
356
|
+
// src/client/core/eip3009.ts
|
|
357
|
+
var EIP3009_TYPES = {
|
|
358
|
+
TransferWithAuthorization: [
|
|
359
|
+
{ name: "from", type: "address" },
|
|
360
|
+
{ name: "to", type: "address" },
|
|
361
|
+
{ name: "value", type: "uint256" },
|
|
362
|
+
{ name: "validAfter", type: "uint256" },
|
|
363
|
+
{ name: "validBefore", type: "uint256" },
|
|
364
|
+
{ name: "nonce", type: "bytes32" }
|
|
365
|
+
]
|
|
366
|
+
};
|
|
367
|
+
function buildEIP3009TypedData(args) {
|
|
368
|
+
const validAfter = args.validAfter ?? "0";
|
|
369
|
+
const validBefore = args.validBefore ?? (Math.floor(Date.now() / 1e3) + 3600).toString();
|
|
370
|
+
const authorization = {
|
|
371
|
+
from: args.from,
|
|
372
|
+
to: args.to,
|
|
373
|
+
value: args.value,
|
|
374
|
+
validAfter,
|
|
375
|
+
validBefore,
|
|
376
|
+
nonce: args.nonce
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
domain: {
|
|
380
|
+
name: args.tokenName,
|
|
381
|
+
version: args.tokenVersion,
|
|
382
|
+
chainId: args.chainId,
|
|
383
|
+
verifyingContract: args.tokenAddress
|
|
384
|
+
},
|
|
385
|
+
types: EIP3009_TYPES,
|
|
386
|
+
primaryType: "TransferWithAuthorization",
|
|
387
|
+
message: authorization
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/client/core/bnb-intent.ts
|
|
392
|
+
var BNB_INTENT_TYPES = {
|
|
393
|
+
PaymentIntent: [
|
|
394
|
+
{ name: "from", type: "address" },
|
|
395
|
+
{ name: "to", type: "address" },
|
|
396
|
+
{ name: "amount", type: "uint256" },
|
|
397
|
+
{ name: "token", type: "address" },
|
|
398
|
+
{ name: "service", type: "string" },
|
|
399
|
+
{ name: "nonce", type: "uint256" },
|
|
400
|
+
{ name: "deadline", type: "uint256" }
|
|
401
|
+
]
|
|
402
|
+
};
|
|
403
|
+
var BNB_DOMAIN_NAME = "MoltsPay";
|
|
404
|
+
var BNB_DOMAIN_VERSION = "1";
|
|
405
|
+
function buildBnbIntentTypedData(args) {
|
|
406
|
+
const intent = {
|
|
407
|
+
from: args.from,
|
|
408
|
+
to: args.to,
|
|
409
|
+
amount: args.amount,
|
|
410
|
+
token: args.tokenAddress,
|
|
411
|
+
service: args.service,
|
|
412
|
+
nonce: args.nonce,
|
|
413
|
+
deadline: args.deadline
|
|
414
|
+
};
|
|
415
|
+
return {
|
|
416
|
+
domain: {
|
|
417
|
+
name: BNB_DOMAIN_NAME,
|
|
418
|
+
version: BNB_DOMAIN_VERSION,
|
|
419
|
+
chainId: args.chainId
|
|
420
|
+
},
|
|
421
|
+
types: BNB_INTENT_TYPES,
|
|
422
|
+
primaryType: "PaymentIntent",
|
|
423
|
+
message: intent
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// src/client/node/signer.ts
|
|
428
|
+
var import_ethers = require("ethers");
|
|
429
|
+
var import_web34 = require("@solana/web3.js");
|
|
430
|
+
var NodeSigner = class {
|
|
431
|
+
evmWallet;
|
|
432
|
+
getSolanaKeypair;
|
|
433
|
+
constructor(evmWallet, options = {}) {
|
|
434
|
+
this.evmWallet = evmWallet;
|
|
435
|
+
this.getSolanaKeypair = options.getSolanaKeypair ?? (() => null);
|
|
436
|
+
}
|
|
437
|
+
async getEvmAddress() {
|
|
438
|
+
return this.evmWallet.address;
|
|
439
|
+
}
|
|
440
|
+
async getSolanaAddress() {
|
|
441
|
+
const kp = this.getSolanaKeypair();
|
|
442
|
+
return kp ? kp.publicKey.toBase58() : null;
|
|
443
|
+
}
|
|
444
|
+
async signTypedData(envelope) {
|
|
445
|
+
const mutableTypes = {};
|
|
446
|
+
for (const [key, fields] of Object.entries(envelope.types)) {
|
|
447
|
+
mutableTypes[key] = [...fields];
|
|
448
|
+
}
|
|
449
|
+
return this.evmWallet.signTypedData(
|
|
450
|
+
envelope.domain,
|
|
451
|
+
mutableTypes,
|
|
452
|
+
envelope.message
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
async sendEvmTransaction(args) {
|
|
456
|
+
const chain = findChainByChainId(args.chainId);
|
|
457
|
+
if (!chain) {
|
|
458
|
+
throw new Error(`sendEvmTransaction: unknown chainId ${args.chainId}`);
|
|
459
|
+
}
|
|
460
|
+
const provider = new import_ethers.ethers.JsonRpcProvider(chain.rpc);
|
|
461
|
+
const connected = this.evmWallet.connect(provider);
|
|
462
|
+
const tx = await connected.sendTransaction({
|
|
463
|
+
to: args.to,
|
|
464
|
+
data: args.data,
|
|
465
|
+
value: args.value ? BigInt(args.value) : 0n
|
|
466
|
+
});
|
|
467
|
+
return tx.hash;
|
|
468
|
+
}
|
|
469
|
+
async signSolanaTransaction(args) {
|
|
470
|
+
const kp = this.getSolanaKeypair();
|
|
471
|
+
if (!kp) {
|
|
472
|
+
throw new Error("signSolanaTransaction: no Solana wallet configured");
|
|
473
|
+
}
|
|
474
|
+
const tx = import_web34.Transaction.from(Buffer.from(args.transactionBase64, "base64"));
|
|
475
|
+
if (args.partialSign) {
|
|
476
|
+
tx.partialSign(kp);
|
|
477
|
+
} else {
|
|
478
|
+
tx.sign(kp);
|
|
479
|
+
}
|
|
480
|
+
return tx.serialize({ requireAllSignatures: false }).toString("base64");
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
function findChainByChainId(chainId) {
|
|
484
|
+
for (const cfg of Object.values(CHAINS)) {
|
|
485
|
+
if (cfg.chainId === chainId) {
|
|
486
|
+
return cfg;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// src/client/node/index.ts
|
|
332
493
|
var DEFAULT_CONFIG = {
|
|
333
494
|
chain: "base",
|
|
334
495
|
limits: {
|
|
@@ -341,6 +502,7 @@ var MoltsPayClient = class {
|
|
|
341
502
|
config;
|
|
342
503
|
walletData = null;
|
|
343
504
|
wallet = null;
|
|
505
|
+
signer = null;
|
|
344
506
|
todaySpending = 0;
|
|
345
507
|
lastSpendingReset = 0;
|
|
346
508
|
constructor(options = {}) {
|
|
@@ -349,7 +511,11 @@ var MoltsPayClient = class {
|
|
|
349
511
|
this.walletData = this.loadWallet();
|
|
350
512
|
this.loadSpending();
|
|
351
513
|
if (this.walletData) {
|
|
352
|
-
this.wallet = new
|
|
514
|
+
this.wallet = new import_ethers2.Wallet(this.walletData.privateKey);
|
|
515
|
+
const configDir = this.configDir;
|
|
516
|
+
this.signer = new NodeSigner(this.wallet, {
|
|
517
|
+
getSolanaKeypair: () => loadSolanaWallet(configDir)
|
|
518
|
+
});
|
|
353
519
|
}
|
|
354
520
|
}
|
|
355
521
|
/**
|
|
@@ -477,20 +643,6 @@ var MoltsPayClient = class {
|
|
|
477
643
|
} catch {
|
|
478
644
|
throw new Error("Invalid x-payment-required header");
|
|
479
645
|
}
|
|
480
|
-
const networkToChainName = (network2) => {
|
|
481
|
-
if (network2 === "solana:mainnet") return "solana";
|
|
482
|
-
if (network2 === "solana:devnet") return "solana_devnet";
|
|
483
|
-
const match = network2.match(/^eip155:(\d+)$/);
|
|
484
|
-
if (!match) return null;
|
|
485
|
-
const chainId = parseInt(match[1]);
|
|
486
|
-
if (chainId === 8453) return "base";
|
|
487
|
-
if (chainId === 137) return "polygon";
|
|
488
|
-
if (chainId === 84532) return "base_sepolia";
|
|
489
|
-
if (chainId === 42431) return "tempo_moderato";
|
|
490
|
-
if (chainId === 56) return "bnb";
|
|
491
|
-
if (chainId === 97) return "bnb_testnet";
|
|
492
|
-
return null;
|
|
493
|
-
};
|
|
494
646
|
const serverChains = requirements.map((r) => networkToChainName(r.network)).filter((c) => c !== null);
|
|
495
647
|
const userSpecifiedChain = options.chain;
|
|
496
648
|
let selectedChain;
|
|
@@ -719,14 +871,14 @@ Please specify: --chain <chain_name>`
|
|
|
719
871
|
async handleBNBPayment(executeUrl, service, params, paymentDetails, options = {}) {
|
|
720
872
|
const { to, amount, token, chainName, chain, spender } = paymentDetails;
|
|
721
873
|
const tokenConfig = chain.tokens[token];
|
|
722
|
-
const provider = new
|
|
874
|
+
const provider = new import_ethers2.ethers.JsonRpcProvider(chain.rpc);
|
|
723
875
|
const allowance = await this.checkAllowance(tokenConfig.address, spender, provider);
|
|
724
876
|
const amountWeiCheck = BigInt(Math.floor(amount * 10 ** tokenConfig.decimals));
|
|
725
877
|
if (allowance < amountWeiCheck) {
|
|
726
878
|
const nativeBalance = await provider.getBalance(this.wallet.address);
|
|
727
|
-
const minGasBalance =
|
|
879
|
+
const minGasBalance = import_ethers2.ethers.parseEther("0.0005");
|
|
728
880
|
if (nativeBalance < minGasBalance) {
|
|
729
|
-
const nativeBNB = parseFloat(
|
|
881
|
+
const nativeBNB = parseFloat(import_ethers2.ethers.formatEther(nativeBalance)).toFixed(4);
|
|
730
882
|
const isTestnet = chainName === "bnb_testnet";
|
|
731
883
|
if (isTestnet) {
|
|
732
884
|
throw new Error(
|
|
@@ -760,35 +912,21 @@ Run: npx moltspay approve --chain ${chainName} --spender ${spender}`
|
|
|
760
912
|
);
|
|
761
913
|
}
|
|
762
914
|
const amountWei = BigInt(Math.floor(amount * 10 ** tokenConfig.decimals)).toString();
|
|
763
|
-
const
|
|
915
|
+
const intentNonce = Date.now();
|
|
916
|
+
const intentDeadline = Date.now() + 36e5;
|
|
917
|
+
const envelope = buildBnbIntentTypedData({
|
|
764
918
|
from: this.wallet.address,
|
|
765
919
|
to,
|
|
766
920
|
amount: amountWei,
|
|
767
|
-
|
|
921
|
+
tokenAddress: tokenConfig.address,
|
|
768
922
|
service,
|
|
769
|
-
nonce:
|
|
770
|
-
|
|
771
|
-
deadline: Date.now() + 36e5
|
|
772
|
-
// 1 hour
|
|
773
|
-
};
|
|
774
|
-
const domain = {
|
|
775
|
-
name: "MoltsPay",
|
|
776
|
-
version: "1",
|
|
923
|
+
nonce: intentNonce,
|
|
924
|
+
deadline: intentDeadline,
|
|
777
925
|
chainId: chain.chainId
|
|
778
|
-
};
|
|
779
|
-
const types = {
|
|
780
|
-
PaymentIntent: [
|
|
781
|
-
{ name: "from", type: "address" },
|
|
782
|
-
{ name: "to", type: "address" },
|
|
783
|
-
{ name: "amount", type: "uint256" },
|
|
784
|
-
{ name: "token", type: "address" },
|
|
785
|
-
{ name: "service", type: "string" },
|
|
786
|
-
{ name: "nonce", type: "uint256" },
|
|
787
|
-
{ name: "deadline", type: "uint256" }
|
|
788
|
-
]
|
|
789
|
-
};
|
|
926
|
+
});
|
|
790
927
|
console.log(`[MoltsPay] Signing BNB payment intent...`);
|
|
791
|
-
const signature = await this.
|
|
928
|
+
const signature = await this.signer.signTypedData(envelope);
|
|
929
|
+
const intent = envelope.message;
|
|
792
930
|
const network = `eip155:${chain.chainId}`;
|
|
793
931
|
const payload = {
|
|
794
932
|
x402Version: 2,
|
|
@@ -849,11 +987,11 @@ Run: npx moltspay approve --chain ${chainName} --spender ${spender}`
|
|
|
849
987
|
throw new Error("Missing payTo address in payment requirements");
|
|
850
988
|
}
|
|
851
989
|
const solanaFeePayer = requirements.extra?.solanaFeePayer;
|
|
852
|
-
const feePayerPubkey = solanaFeePayer ? new
|
|
990
|
+
const feePayerPubkey = solanaFeePayer ? new import_web35.PublicKey(solanaFeePayer) : void 0;
|
|
853
991
|
if (feePayerPubkey) {
|
|
854
992
|
console.log(`[MoltsPay] Gasless mode: server pays fees`);
|
|
855
993
|
}
|
|
856
|
-
const recipientPubkey = new
|
|
994
|
+
const recipientPubkey = new import_web35.PublicKey(requirements.payTo);
|
|
857
995
|
const transaction = await createSolanaPaymentTransaction(
|
|
858
996
|
solanaWallet.publicKey,
|
|
859
997
|
recipientPubkey,
|
|
@@ -862,12 +1000,11 @@ Run: npx moltspay approve --chain ${chainName} --spender ${spender}`
|
|
|
862
1000
|
feePayerPubkey
|
|
863
1001
|
// Optional fee payer for gasless mode
|
|
864
1002
|
);
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
}
|
|
870
|
-
const signedTx = transaction.serialize({ requireAllSignatures: false }).toString("base64");
|
|
1003
|
+
const unsignedBase64 = transaction.serialize({ requireAllSignatures: false, verifySignatures: false }).toString("base64");
|
|
1004
|
+
const signedTx = await this.signer.signSolanaTransaction({
|
|
1005
|
+
transactionBase64: unsignedBase64,
|
|
1006
|
+
partialSign: !!feePayerPubkey
|
|
1007
|
+
});
|
|
871
1008
|
console.log(`[MoltsPay] Transaction signed, sending to server...`);
|
|
872
1009
|
const network = chain === "solana" ? "solana:mainnet" : "solana:devnet";
|
|
873
1010
|
const payload = {
|
|
@@ -914,7 +1051,7 @@ Run: npx moltspay approve --chain ${chainName} --spender ${spender}`
|
|
|
914
1051
|
* Check ERC20 allowance for a spender
|
|
915
1052
|
*/
|
|
916
1053
|
async checkAllowance(tokenAddress, spender, provider) {
|
|
917
|
-
const contract = new
|
|
1054
|
+
const contract = new import_ethers2.ethers.Contract(
|
|
918
1055
|
tokenAddress,
|
|
919
1056
|
["function allowance(address owner, address spender) view returns (uint256)"],
|
|
920
1057
|
provider
|
|
@@ -925,41 +1062,29 @@ Run: npx moltspay approve --chain ${chainName} --spender ${spender}`
|
|
|
925
1062
|
* Sign EIP-3009 transferWithAuthorization (GASLESS)
|
|
926
1063
|
* This only signs - no on-chain transaction, no gas needed.
|
|
927
1064
|
* Supports both USDC and USDT.
|
|
1065
|
+
*
|
|
1066
|
+
* Delegates typed-data construction to `core/eip3009.ts` and the signature
|
|
1067
|
+
* itself to `this.signer`. That way Web Client (Phase 4) can reuse the same
|
|
1068
|
+
* flow with an EIP-1193 signer without duplicating typed-data layout.
|
|
928
1069
|
*/
|
|
929
1070
|
async signEIP3009(to, amount, chain, token = "USDC", domainOverride) {
|
|
930
|
-
const validAfter = 0;
|
|
931
|
-
const validBefore = Math.floor(Date.now() / 1e3) + 3600;
|
|
932
|
-
const nonce = import_ethers.ethers.hexlify(import_ethers.ethers.randomBytes(32));
|
|
933
1071
|
const tokenConfig = chain.tokens[token];
|
|
934
1072
|
const value = BigInt(Math.floor(amount * 10 ** tokenConfig.decimals)).toString();
|
|
935
|
-
const
|
|
1073
|
+
const nonce = import_ethers2.ethers.hexlify(import_ethers2.ethers.randomBytes(32));
|
|
1074
|
+
const tokenName = domainOverride?.name || tokenConfig.eip712Name || (token === "USDC" ? "USD Coin" : "Tether USD");
|
|
1075
|
+
const tokenVersion = domainOverride?.version || "2";
|
|
1076
|
+
const envelope = buildEIP3009TypedData({
|
|
936
1077
|
from: this.wallet.address,
|
|
937
1078
|
to,
|
|
938
1079
|
value,
|
|
939
|
-
|
|
940
|
-
validBefore: validBefore.toString(),
|
|
941
|
-
nonce
|
|
942
|
-
};
|
|
943
|
-
const tokenName = domainOverride?.name || tokenConfig.eip712Name || (token === "USDC" ? "USD Coin" : "Tether USD");
|
|
944
|
-
const tokenVersion = domainOverride?.version || "2";
|
|
945
|
-
const domain = {
|
|
946
|
-
name: tokenName,
|
|
947
|
-
version: tokenVersion,
|
|
1080
|
+
nonce,
|
|
948
1081
|
chainId: chain.chainId,
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
{ name: "value", type: "uint256" },
|
|
956
|
-
{ name: "validAfter", type: "uint256" },
|
|
957
|
-
{ name: "validBefore", type: "uint256" },
|
|
958
|
-
{ name: "nonce", type: "bytes32" }
|
|
959
|
-
]
|
|
960
|
-
};
|
|
961
|
-
const signature = await this.wallet.signTypedData(domain, types, authorization);
|
|
962
|
-
return { authorization, signature };
|
|
1082
|
+
tokenAddress: tokenConfig.address,
|
|
1083
|
+
tokenName,
|
|
1084
|
+
tokenVersion
|
|
1085
|
+
});
|
|
1086
|
+
const signature = await this.signer.signTypedData(envelope);
|
|
1087
|
+
return { authorization: envelope.message, signature };
|
|
963
1088
|
}
|
|
964
1089
|
/**
|
|
965
1090
|
* Check spending limits
|
|
@@ -1063,7 +1188,7 @@ Run: npx moltspay approve --chain ${chainName} --spender ${spender}`
|
|
|
1063
1188
|
*/
|
|
1064
1189
|
static init(configDir, options) {
|
|
1065
1190
|
(0, import_fs2.mkdirSync)(configDir, { recursive: true });
|
|
1066
|
-
const wallet =
|
|
1191
|
+
const wallet = import_ethers2.Wallet.createRandom();
|
|
1067
1192
|
const walletData = {
|
|
1068
1193
|
address: wallet.address,
|
|
1069
1194
|
privateKey: wallet.privateKey,
|
|
@@ -1095,17 +1220,17 @@ Run: npx moltspay approve --chain ${chainName} --spender ${spender}`
|
|
|
1095
1220
|
} catch {
|
|
1096
1221
|
throw new Error(`Unknown chain: ${this.config.chain}`);
|
|
1097
1222
|
}
|
|
1098
|
-
const provider = new
|
|
1223
|
+
const provider = new import_ethers2.ethers.JsonRpcProvider(chain.rpc);
|
|
1099
1224
|
const tokenAbi = ["function balanceOf(address) view returns (uint256)"];
|
|
1100
1225
|
const [nativeBalance, usdcBalance, usdtBalance] = await Promise.all([
|
|
1101
1226
|
provider.getBalance(this.wallet.address),
|
|
1102
|
-
new
|
|
1103
|
-
new
|
|
1227
|
+
new import_ethers2.ethers.Contract(chain.tokens.USDC.address, tokenAbi, provider).balanceOf(this.wallet.address),
|
|
1228
|
+
new import_ethers2.ethers.Contract(chain.tokens.USDT.address, tokenAbi, provider).balanceOf(this.wallet.address)
|
|
1104
1229
|
]);
|
|
1105
1230
|
return {
|
|
1106
|
-
usdc: parseFloat(
|
|
1107
|
-
usdt: parseFloat(
|
|
1108
|
-
native: parseFloat(
|
|
1231
|
+
usdc: parseFloat(import_ethers2.ethers.formatUnits(usdcBalance, chain.tokens.USDC.decimals)),
|
|
1232
|
+
usdt: parseFloat(import_ethers2.ethers.formatUnits(usdtBalance, chain.tokens.USDT.decimals)),
|
|
1233
|
+
native: parseFloat(import_ethers2.ethers.formatEther(nativeBalance))
|
|
1109
1234
|
};
|
|
1110
1235
|
}
|
|
1111
1236
|
/**
|
|
@@ -1128,38 +1253,38 @@ Run: npx moltspay approve --chain ${chainName} --spender ${spender}`
|
|
|
1128
1253
|
supportedChains.map(async (chainName) => {
|
|
1129
1254
|
try {
|
|
1130
1255
|
const chain = getChain(chainName);
|
|
1131
|
-
const provider = new
|
|
1256
|
+
const provider = new import_ethers2.ethers.JsonRpcProvider(chain.rpc);
|
|
1132
1257
|
if (chainName === "tempo_moderato") {
|
|
1133
1258
|
const [nativeBalance, pathUSD, alphaUSD, betaUSD, thetaUSD] = await Promise.all([
|
|
1134
1259
|
provider.getBalance(this.wallet.address),
|
|
1135
|
-
new
|
|
1136
|
-
new
|
|
1137
|
-
new
|
|
1138
|
-
new
|
|
1260
|
+
new import_ethers2.ethers.Contract(tempoTokens.pathUSD, tokenAbi, provider).balanceOf(this.wallet.address),
|
|
1261
|
+
new import_ethers2.ethers.Contract(tempoTokens.alphaUSD, tokenAbi, provider).balanceOf(this.wallet.address),
|
|
1262
|
+
new import_ethers2.ethers.Contract(tempoTokens.betaUSD, tokenAbi, provider).balanceOf(this.wallet.address),
|
|
1263
|
+
new import_ethers2.ethers.Contract(tempoTokens.thetaUSD, tokenAbi, provider).balanceOf(this.wallet.address)
|
|
1139
1264
|
]);
|
|
1140
1265
|
results[chainName] = {
|
|
1141
|
-
usdc: parseFloat(
|
|
1266
|
+
usdc: parseFloat(import_ethers2.ethers.formatUnits(pathUSD, 6)),
|
|
1142
1267
|
// pathUSD as default USDC
|
|
1143
|
-
usdt: parseFloat(
|
|
1268
|
+
usdt: parseFloat(import_ethers2.ethers.formatUnits(alphaUSD, 6)),
|
|
1144
1269
|
// alphaUSD as default USDT
|
|
1145
|
-
native: parseFloat(
|
|
1270
|
+
native: parseFloat(import_ethers2.ethers.formatEther(nativeBalance)),
|
|
1146
1271
|
tempo: {
|
|
1147
|
-
pathUSD: parseFloat(
|
|
1148
|
-
alphaUSD: parseFloat(
|
|
1149
|
-
betaUSD: parseFloat(
|
|
1150
|
-
thetaUSD: parseFloat(
|
|
1272
|
+
pathUSD: parseFloat(import_ethers2.ethers.formatUnits(pathUSD, 6)),
|
|
1273
|
+
alphaUSD: parseFloat(import_ethers2.ethers.formatUnits(alphaUSD, 6)),
|
|
1274
|
+
betaUSD: parseFloat(import_ethers2.ethers.formatUnits(betaUSD, 6)),
|
|
1275
|
+
thetaUSD: parseFloat(import_ethers2.ethers.formatUnits(thetaUSD, 6))
|
|
1151
1276
|
}
|
|
1152
1277
|
};
|
|
1153
1278
|
} else {
|
|
1154
1279
|
const [nativeBalance, usdcBalance, usdtBalance] = await Promise.all([
|
|
1155
1280
|
provider.getBalance(this.wallet.address),
|
|
1156
|
-
new
|
|
1157
|
-
new
|
|
1281
|
+
new import_ethers2.ethers.Contract(chain.tokens.USDC.address, tokenAbi, provider).balanceOf(this.wallet.address),
|
|
1282
|
+
new import_ethers2.ethers.Contract(chain.tokens.USDT.address, tokenAbi, provider).balanceOf(this.wallet.address)
|
|
1158
1283
|
]);
|
|
1159
1284
|
results[chainName] = {
|
|
1160
|
-
usdc: parseFloat(
|
|
1161
|
-
usdt: parseFloat(
|
|
1162
|
-
native: parseFloat(
|
|
1285
|
+
usdc: parseFloat(import_ethers2.ethers.formatUnits(usdcBalance, chain.tokens.USDC.decimals)),
|
|
1286
|
+
usdt: parseFloat(import_ethers2.ethers.formatUnits(usdtBalance, chain.tokens.USDT.decimals)),
|
|
1287
|
+
native: parseFloat(import_ethers2.ethers.formatEther(nativeBalance))
|
|
1163
1288
|
};
|
|
1164
1289
|
}
|
|
1165
1290
|
} catch (err2) {
|