@verified-network/verified-sdk 2.5.3 → 2.5.4
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/dist/contract/index.d.ts +10 -1
- package/dist/contract/index.js +313 -141
- package/dist/utils/constants.js +8 -41
- package/package.json +1 -1
package/dist/contract/index.d.ts
CHANGED
|
@@ -60,15 +60,24 @@ export declare class VerifiedContract {
|
|
|
60
60
|
/** Constructs and call function as userop for biconomy gassless(sponsored/erc20 mode) */
|
|
61
61
|
callFunctionAsUserOp(smartAccount: any, tx: any, functionName: string, paymentToken: string, ...args: any): Promise<SCResponse>;
|
|
62
62
|
/** Constructs and call function using MEE client that allows gas payment in ERC20 tokens */
|
|
63
|
-
callFunctionWithMEEClient(nexusAccount: any, chainId: number, tx: any, paymentToken: `0x${string}`, _apiKey?: string): Promise<SCResponse>;
|
|
63
|
+
callFunctionWithMEEClient(nexusAccount: any, chainId: number, tx: any, functionName: string, paymentToken: `0x${string}`, isSponsor?: boolean, _apiKey?: string, ...args: any): Promise<SCResponse>;
|
|
64
64
|
callContract(functionName: string, ...args: any): Promise<SCResponse>;
|
|
65
65
|
getQuote(paymentTokenAddress: string, functionName: string, args: any[], rpc?: string, _apiKey?: string, isReactNative?: boolean): Promise<{
|
|
66
|
+
tokenAddress: string;
|
|
67
|
+
amount: string;
|
|
68
|
+
amountInWei: string;
|
|
69
|
+
amountValue: string;
|
|
70
|
+
chainId: number;
|
|
71
|
+
functionName: string;
|
|
72
|
+
amouuntValue?: undefined;
|
|
73
|
+
} | {
|
|
66
74
|
tokenAddress: string;
|
|
67
75
|
amount: string;
|
|
68
76
|
amountInWei: string;
|
|
69
77
|
amouuntValue: string;
|
|
70
78
|
chainId: number;
|
|
71
79
|
functionName: string;
|
|
80
|
+
amountValue?: undefined;
|
|
72
81
|
}>;
|
|
73
82
|
protected getEvent(eventName: string, callback: any): void;
|
|
74
83
|
}
|
package/dist/contract/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
2
|
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
7
|
exports.VerifiedContract = exports.DATATYPES = void 0;
|
|
5
8
|
const ethers_1 = require("ethers");
|
|
@@ -9,6 +12,7 @@ const abstractjs_1 = require("@biconomy/abstractjs");
|
|
|
9
12
|
const chains_1 = require("viem/chains");
|
|
10
13
|
const viem_1 = require("viem");
|
|
11
14
|
const biconomyRNFix_1 = require("../lib/biconomyRNFix");
|
|
15
|
+
const erc20_1 = __importDefault(require("./erc20"));
|
|
12
16
|
var STATUS;
|
|
13
17
|
(function (STATUS) {
|
|
14
18
|
STATUS[STATUS["SUCCESS"] = 0] = "SUCCESS";
|
|
@@ -322,37 +326,6 @@ class VerifiedContract {
|
|
|
322
326
|
const txHash = (_c = messageArray === null || messageArray === void 0 ? void 0 : messageArray.find((msg) => msg === null || msg === void 0 ? void 0 : msg.startsWith("0x"))) === null || _c === void 0 ? void 0 : _c.replace(".", "");
|
|
323
327
|
//wait up to max round to fetch receipt ???
|
|
324
328
|
if (txHash) {
|
|
325
|
-
// for (
|
|
326
|
-
// let i = 0;
|
|
327
|
-
// i < Number(PaymasterConstants.MAX_WAITING_ROUND);
|
|
328
|
-
// i++
|
|
329
|
-
// ) {
|
|
330
|
-
// await new Promise((resolve) => {
|
|
331
|
-
// setTimeout(resolve, 6000); //1 minute delay per round
|
|
332
|
-
// });
|
|
333
|
-
// console.log(
|
|
334
|
-
// "Gassless timeout exceeded, fetching receipt for round: ",
|
|
335
|
-
// i + 1,
|
|
336
|
-
// "out of ",
|
|
337
|
-
// Number(PaymasterConstants.MAX_WAITING_ROUND)
|
|
338
|
-
// );
|
|
339
|
-
// return await this.fetchUserOpReceipt(txHash).then(async (_res) => {
|
|
340
|
-
// if (_res && !_res?.failed) {
|
|
341
|
-
// //if receipt received stop and configure return
|
|
342
|
-
// res.status = STATUS.SUCCESS;
|
|
343
|
-
// res.response = {
|
|
344
|
-
// hash: _res?.transactionHash || txHash,
|
|
345
|
-
// result: _res,
|
|
346
|
-
// }; //TODO: update result on response
|
|
347
|
-
// res.message = "";
|
|
348
|
-
// return res;
|
|
349
|
-
// } else if (_res && _res?.failed) {
|
|
350
|
-
// //if receipt failed stop and use ethers
|
|
351
|
-
// console.log("will use ethers....");
|
|
352
|
-
// return await this.callFunctionWithEthers(functionName, ...args);
|
|
353
|
-
// }
|
|
354
|
-
// });
|
|
355
|
-
// }
|
|
356
329
|
for (let i = 0; i < Number(constants_1.PaymasterConstants.MAX_WAITING_ROUND); i++) {
|
|
357
330
|
await new Promise((resolve) => setTimeout(resolve, 6000)); // 6 second delay
|
|
358
331
|
console.log("Gassless timeout exceeded, fetching receipt for round:", i + 1, "out of", Number(constants_1.PaymasterConstants.MAX_WAITING_ROUND));
|
|
@@ -405,8 +378,8 @@ class VerifiedContract {
|
|
|
405
378
|
}
|
|
406
379
|
}
|
|
407
380
|
/** Constructs and call function using MEE client that allows gas payment in ERC20 tokens */
|
|
408
|
-
async callFunctionWithMEEClient(nexusAccount, chainId, tx, paymentToken, _apiKey) {
|
|
409
|
-
var _a, _b, _c, _d, _e, _f;
|
|
381
|
+
async callFunctionWithMEEClient(nexusAccount, chainId, tx, functionName, paymentToken, isSponsor, _apiKey, ...args) {
|
|
382
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
410
383
|
let res = {};
|
|
411
384
|
let txHash = "";
|
|
412
385
|
let recp;
|
|
@@ -428,41 +401,196 @@ class VerifiedContract {
|
|
|
428
401
|
calls: [tx],
|
|
429
402
|
},
|
|
430
403
|
});
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
404
|
+
let transferInstruction, transferTx;
|
|
405
|
+
if (!isSponsor) {
|
|
406
|
+
const signerAny = this.signer;
|
|
407
|
+
const tokenContract = new erc20_1.default(signerAny, paymentToken);
|
|
408
|
+
const tokenDecimals = await tokenContract
|
|
409
|
+
.decimals()
|
|
410
|
+
.then((res) => { var _a; return (_a = res === null || res === void 0 ? void 0 : res.response) === null || _a === void 0 ? void 0 : _a.result[0]; });
|
|
411
|
+
const fn = tokenContract.contract.populateTransaction["transfer"];
|
|
412
|
+
const amountFmt = ethers_1.ethers.utils.parseUnits(constants_1.PaymasterConstants.COMPENSATION_AMOUNT, Number(tokenDecimals));
|
|
413
|
+
const transferArgs = [
|
|
414
|
+
constants_1.PaymasterConstants.ADMIN_WALLET_ADDRESS,
|
|
415
|
+
amountFmt === null || amountFmt === void 0 ? void 0 : amountFmt.toString(),
|
|
416
|
+
];
|
|
417
|
+
const transferFunc = await fn(...transferArgs);
|
|
418
|
+
const _transferTx = {
|
|
419
|
+
to: paymentToken,
|
|
420
|
+
data: transferFunc.data,
|
|
421
|
+
};
|
|
422
|
+
transferTx = _transferTx;
|
|
423
|
+
transferInstruction = await nexusAccount.build({
|
|
424
|
+
type: "default",
|
|
425
|
+
data: {
|
|
426
|
+
chainId,
|
|
427
|
+
calls: [_transferTx],
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
const isTestnet = (_b = constants_1.PaymasterConstants.TEST_CHAINS) === null || _b === void 0 ? void 0 : _b.includes(chainId);
|
|
432
|
+
let sponsorInfo;
|
|
433
|
+
if (!isTestnet) {
|
|
434
|
+
const response = await fetch("https://network.biconomy.io/v1/sponsorship/info", { method: "GET" });
|
|
435
|
+
if (!response.ok) {
|
|
436
|
+
sponsorInfo = {};
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
sponsorInfo = await response.json();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
const sponsorUrl = isTestnet
|
|
443
|
+
? abstractjs_1.DEFAULT_PATHFINDER_URL
|
|
444
|
+
: constants_1.PaymasterConstants.HOSTED_SPONSOR_URL;
|
|
445
|
+
let quote, cmpQuote;
|
|
446
|
+
if (isSponsor) {
|
|
447
|
+
quote = await meeClient.getQuote({
|
|
448
|
+
instructions: [transactionInstruction],
|
|
449
|
+
sponsorship: true,
|
|
450
|
+
sponsorshipOptions: {
|
|
451
|
+
url: sponsorUrl,
|
|
452
|
+
gasTank: {
|
|
453
|
+
address: isTestnet
|
|
454
|
+
? abstractjs_1.DEFAULT_MEE_TESTNET_SPONSORSHIP_PAYMASTER_ACCOUNT
|
|
455
|
+
: (_c = sponsorInfo[chainId === null || chainId === void 0 ? void 0 : chainId.toString()]) === null || _c === void 0 ? void 0 : _c.account,
|
|
456
|
+
token: isTestnet
|
|
457
|
+
? abstractjs_1.DEFAULT_MEE_TESTNET_SPONSORSHIP_TOKEN_ADDRESS
|
|
458
|
+
: (_d = sponsorInfo[chainId === null || chainId === void 0 ? void 0 : chainId.toString()]) === null || _d === void 0 ? void 0 : _d.token,
|
|
459
|
+
chainId: isTestnet
|
|
460
|
+
? abstractjs_1.DEFAULT_MEE_TESTNET_SPONSORSHIP_CHAIN_ID
|
|
461
|
+
: Number(chainId),
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
simulation: {
|
|
465
|
+
simulate: true,
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
cmpQuote = await meeClient.getQuote({
|
|
471
|
+
instructions: [transferInstruction],
|
|
472
|
+
feeToken: { address: paymentToken, chainId },
|
|
473
|
+
simulation: {
|
|
474
|
+
simulate: true,
|
|
475
|
+
},
|
|
476
|
+
});
|
|
477
|
+
quote = await meeClient.getQuote({
|
|
478
|
+
instructions: [transactionInstruction],
|
|
479
|
+
feeToken: { address: paymentToken, chainId },
|
|
480
|
+
simulation: {
|
|
481
|
+
simulate: true,
|
|
482
|
+
},
|
|
483
|
+
});
|
|
484
|
+
}
|
|
438
485
|
const nowInSec = Math.floor(Date.now() / 1000);
|
|
439
486
|
const transactionInstructionFinal = await nexusAccount.build({
|
|
440
487
|
type: "default",
|
|
441
488
|
data: {
|
|
442
489
|
chainId,
|
|
443
490
|
calls: [
|
|
444
|
-
Object.assign(Object.assign({}, tx), { gasLimit: (
|
|
491
|
+
Object.assign(Object.assign({}, tx), { gasLimit: (_f = quote === null || quote === void 0 ? void 0 : quote.userOps[((_e = quote === null || quote === void 0 ? void 0 : quote.userOps) === null || _e === void 0 ? void 0 : _e.length) - 1]) === null || _f === void 0 ? void 0 : _f.maxGasLimit }),
|
|
445
492
|
],
|
|
446
493
|
},
|
|
447
494
|
});
|
|
495
|
+
let transferInstructionFinal;
|
|
496
|
+
if (!isSponsor) {
|
|
497
|
+
transferInstructionFinal = await nexusAccount.build({
|
|
498
|
+
type: "default",
|
|
499
|
+
data: {
|
|
500
|
+
chainId,
|
|
501
|
+
calls: [
|
|
502
|
+
Object.assign(Object.assign({}, transferTx), { gasLimit: (_h = cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.userOps[((_g = cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.userOps) === null || _g === void 0 ? void 0 : _g.length) - 1]) === null || _h === void 0 ? void 0 : _h.maxGasLimit }),
|
|
503
|
+
],
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
}
|
|
448
507
|
// Execute the transaction using passed paymentToken
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
508
|
+
let _txHash;
|
|
509
|
+
if (isSponsor) {
|
|
510
|
+
const { hash } = await meeClient.execute({
|
|
511
|
+
sponsorship: true,
|
|
512
|
+
sponsorshipOptions: {
|
|
513
|
+
url: sponsorUrl,
|
|
514
|
+
gasTank: {
|
|
515
|
+
address: isTestnet
|
|
516
|
+
? abstractjs_1.DEFAULT_MEE_TESTNET_SPONSORSHIP_PAYMASTER_ACCOUNT
|
|
517
|
+
: (_j = sponsorInfo[chainId === null || chainId === void 0 ? void 0 : chainId.toString()]) === null || _j === void 0 ? void 0 : _j.account,
|
|
518
|
+
token: isTestnet
|
|
519
|
+
? abstractjs_1.DEFAULT_MEE_TESTNET_SPONSORSHIP_TOKEN_ADDRESS
|
|
520
|
+
: (_k = sponsorInfo[chainId === null || chainId === void 0 ? void 0 : chainId.toString()]) === null || _k === void 0 ? void 0 : _k.token,
|
|
521
|
+
chainId: isTestnet
|
|
522
|
+
? abstractjs_1.DEFAULT_MEE_TESTNET_SPONSORSHIP_CHAIN_ID
|
|
523
|
+
: Number(chainId),
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
instructions: [transactionInstructionFinal],
|
|
527
|
+
upperBoundTimestamp: nowInSec + 299, //highest is 5 minutes???
|
|
528
|
+
});
|
|
529
|
+
_txHash = hash;
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
//handle it seperately as batch kept failing???
|
|
533
|
+
const { hash: cmpHash } = await meeClient.execute({
|
|
534
|
+
feeToken: {
|
|
535
|
+
chainId,
|
|
536
|
+
address: paymentToken,
|
|
537
|
+
},
|
|
538
|
+
instructions: [transferInstructionFinal], //take conpensation first???
|
|
539
|
+
upperBoundTimestamp: nowInSec + 299, //highest is 5 minutes???
|
|
540
|
+
});
|
|
541
|
+
// console.log("Compensation tx MEE hash: ", cmpHash);
|
|
542
|
+
const cmpReceipt = await meeClient.waitForSupertransactionReceipt({
|
|
543
|
+
hash: cmpHash,
|
|
544
|
+
});
|
|
545
|
+
if (((_l = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts) === null || _l === void 0 ? void 0 : _l.length) > 0) {
|
|
546
|
+
//always pick last receipt????
|
|
547
|
+
const txReceipt = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[((_m = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts) === null || _m === void 0 ? void 0 : _m.length) - 1];
|
|
548
|
+
if ((txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.status) === "success") {
|
|
549
|
+
// console.log(
|
|
550
|
+
// "Compensation tx successful will move to regular transaction...",
|
|
551
|
+
// );
|
|
552
|
+
const { hash } = await meeClient.execute({
|
|
553
|
+
feeToken: {
|
|
554
|
+
chainId,
|
|
555
|
+
address: paymentToken,
|
|
556
|
+
},
|
|
557
|
+
instructions: [transactionInstructionFinal],
|
|
558
|
+
upperBoundTimestamp: nowInSec + 299, //highest is 5 minutes???
|
|
559
|
+
});
|
|
560
|
+
_txHash = hash;
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
res.status = STATUS.ERROR;
|
|
564
|
+
res.response = {
|
|
565
|
+
hash: txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.transactionHash,
|
|
566
|
+
result: txReceipt,
|
|
567
|
+
}; //TODO: update result on response
|
|
568
|
+
res.message = "";
|
|
569
|
+
return res;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
console.error("MEE client transaction failed with error: ", "Invalid receipts length");
|
|
574
|
+
res.status = STATUS.ERROR;
|
|
575
|
+
res.response = {
|
|
576
|
+
hash: (_o = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[0]) === null || _o === void 0 ? void 0 : _o.transactionHash,
|
|
577
|
+
result: cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[0],
|
|
578
|
+
}; //TODO: update result on response
|
|
579
|
+
res.message = "";
|
|
580
|
+
return res;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
txHash = _txHash;
|
|
584
|
+
console.log(`MEE transaction hash: ${_txHash}`);
|
|
459
585
|
// Wait for transaction to complete
|
|
460
|
-
const receipt = await meeClient.waitForSupertransactionReceipt({
|
|
586
|
+
const receipt = await meeClient.waitForSupertransactionReceipt({
|
|
587
|
+
hash: _txHash,
|
|
588
|
+
});
|
|
461
589
|
// console.log("receipts: ", receipt);
|
|
462
|
-
// console.log("
|
|
463
|
-
if (((
|
|
590
|
+
// console.log("receiptsss...: ", receipt?.receipts);
|
|
591
|
+
if (((_p = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _p === void 0 ? void 0 : _p.length) > 0) {
|
|
464
592
|
//always pick last receipt????
|
|
465
|
-
const txReceipt = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[((
|
|
593
|
+
const txReceipt = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[((_q = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _q === void 0 ? void 0 : _q.length) - 1];
|
|
466
594
|
if ((txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.status) === "success") {
|
|
467
595
|
res.status = STATUS.SUCCESS;
|
|
468
596
|
res.response = {
|
|
@@ -471,40 +599,58 @@ class VerifiedContract {
|
|
|
471
599
|
}; //TODO: update result on response
|
|
472
600
|
res.message = "";
|
|
473
601
|
}
|
|
602
|
+
else {
|
|
603
|
+
if (isSponsor) {
|
|
604
|
+
console.log("Will use ethers...");
|
|
605
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
res.status = STATUS.ERROR;
|
|
609
|
+
res.response = {
|
|
610
|
+
hash: txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.transactionHash,
|
|
611
|
+
result: txReceipt,
|
|
612
|
+
}; //TODO: update result on response
|
|
613
|
+
res.message = "";
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return res;
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
console.error("MEE client transaction failed with error: ", "Invalid receipts length");
|
|
620
|
+
if (isSponsor) {
|
|
621
|
+
console.log("Will use ethers...");
|
|
622
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
623
|
+
}
|
|
474
624
|
else {
|
|
475
625
|
res.status = STATUS.ERROR;
|
|
476
626
|
res.response = {
|
|
477
|
-
hash:
|
|
478
|
-
result:
|
|
627
|
+
hash: (_r = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[0]) === null || _r === void 0 ? void 0 : _r.transactionHash,
|
|
628
|
+
result: receipt === null || receipt === void 0 ? void 0 : receipt.receipts[0],
|
|
479
629
|
}; //TODO: update result on response
|
|
480
630
|
res.message = "";
|
|
631
|
+
return res;
|
|
481
632
|
}
|
|
482
|
-
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
catch (err) {
|
|
636
|
+
console.error("MEE client transaction failed with error: ", err === null || err === void 0 ? void 0 : err.message);
|
|
637
|
+
if (isSponsor) {
|
|
638
|
+
console.log("Will use ethers...");
|
|
639
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
483
640
|
}
|
|
484
641
|
else {
|
|
485
|
-
console.error("MEE client transaction failed with error: ", "Invalid receipts length");
|
|
486
642
|
res.status = STATUS.ERROR;
|
|
487
643
|
res.response = {
|
|
488
|
-
hash:
|
|
489
|
-
result:
|
|
644
|
+
hash: txHash,
|
|
645
|
+
result: {},
|
|
490
646
|
}; //TODO: update result on response
|
|
491
647
|
res.message = "";
|
|
492
648
|
return res;
|
|
493
649
|
}
|
|
494
650
|
}
|
|
495
|
-
catch (err) {
|
|
496
|
-
console.error("MEE client transaction failed with error: ", err === null || err === void 0 ? void 0 : err.message);
|
|
497
|
-
res.status = STATUS.ERROR;
|
|
498
|
-
res.response = {
|
|
499
|
-
hash: txHash,
|
|
500
|
-
result: {},
|
|
501
|
-
}; //TODO: update result on response
|
|
502
|
-
res.message = "";
|
|
503
|
-
return res;
|
|
504
|
-
}
|
|
505
651
|
}
|
|
506
652
|
async callContract(functionName, ...args) {
|
|
507
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
653
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
508
654
|
// Check if the function is a read function
|
|
509
655
|
if (this.isReadFunction(functionName)) {
|
|
510
656
|
console.log("read function will use ethers");
|
|
@@ -512,7 +658,7 @@ class VerifiedContract {
|
|
|
512
658
|
}
|
|
513
659
|
const chainId = await this.signer.getChainId();
|
|
514
660
|
if (this.supportsGasless(chainId)) {
|
|
515
|
-
console.log("gassless supported will use
|
|
661
|
+
console.log("gassless supported will use mee gas sponsorship or erc20 payment");
|
|
516
662
|
//call contract through userop for gasless transaction
|
|
517
663
|
let options = [];
|
|
518
664
|
const totalArguments = args.length;
|
|
@@ -523,77 +669,68 @@ class VerifiedContract {
|
|
|
523
669
|
//console.log('options before', options);
|
|
524
670
|
if (options == 0)
|
|
525
671
|
options[0] = {};
|
|
526
|
-
//create smart account for signer
|
|
527
|
-
const smartAccount = await this.createSmartAccount(chainId);
|
|
528
|
-
const account = await smartAccount.getAccountAddress();
|
|
529
|
-
// console.log("smart account address: ", account);
|
|
530
|
-
// const signerAddress = await this.signer.getAddress();
|
|
531
|
-
//construct calldata for function
|
|
532
672
|
let fn = this.contract.populateTransaction[functionName];
|
|
533
673
|
let _res = await fn(...args);
|
|
534
674
|
const tx1 = {
|
|
535
675
|
to: this.contract.address,
|
|
536
676
|
data: _res.data,
|
|
537
677
|
};
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
678
|
+
const _signer = this.signer;
|
|
679
|
+
const chainToUse = [
|
|
680
|
+
chains_1.base,
|
|
681
|
+
chains_1.mainnet,
|
|
682
|
+
chains_1.gnosis,
|
|
683
|
+
chains_1.polygon,
|
|
684
|
+
chains_1.sepolia,
|
|
685
|
+
chains_1.baseSepolia,
|
|
686
|
+
].find((nt) => Number(nt === null || nt === void 0 ? void 0 : nt.id) === Number(chainId));
|
|
687
|
+
if (!chainToUse) {
|
|
688
|
+
throw new Error(`Chaind id: ${chainId} not supported on Verified Sdk. Supported chain ids are: ${(_b = (_a = [
|
|
542
689
|
chains_1.base,
|
|
543
690
|
chains_1.mainnet,
|
|
544
691
|
chains_1.gnosis,
|
|
545
692
|
chains_1.polygon,
|
|
546
693
|
chains_1.sepolia,
|
|
547
694
|
chains_1.baseSepolia,
|
|
548
|
-
].
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
695
|
+
]) === null || _a === void 0 ? void 0 : _a.map((nt) => nt === null || nt === void 0 ? void 0 : nt.id)) === null || _b === void 0 ? void 0 : _b.join(", ")}`);
|
|
696
|
+
}
|
|
697
|
+
const prov = this.signer.provider;
|
|
698
|
+
const rpcUrl = (_c = prov === null || prov === void 0 ? void 0 : prov.connection) === null || _c === void 0 ? void 0 : _c.url;
|
|
699
|
+
let nexusAccount;
|
|
700
|
+
if ((_d = optionsRaw[0]) === null || _d === void 0 ? void 0 : _d.isReactNative) {
|
|
701
|
+
nexusAccount = await (0, biconomyRNFix_1.createMultiChainNexusAccount)({
|
|
702
|
+
chains: [chainToUse],
|
|
703
|
+
transports: [
|
|
704
|
+
(0, viem_1.http)(rpcUrl ||
|
|
705
|
+
((_e = optionsRaw[0]) === null || _e === void 0 ? void 0 : _e.rpcUrl) ||
|
|
706
|
+
((_f = constants_1.PaymasterConstants[Number(chainId)]) === null || _f === void 0 ? void 0 : _f.RPC_URL)),
|
|
707
|
+
],
|
|
708
|
+
signer: _signer,
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
nexusAccount = await (0, abstractjs_1.toMultichainNexusAccount)({
|
|
713
|
+
signer: _signer,
|
|
714
|
+
chainConfigurations: [
|
|
715
|
+
{
|
|
716
|
+
chain: chainToUse,
|
|
717
|
+
transport: (0, viem_1.http)(rpcUrl ||
|
|
567
718
|
((_g = optionsRaw[0]) === null || _g === void 0 ? void 0 : _g.rpcUrl) ||
|
|
568
719
|
((_h = constants_1.PaymasterConstants[Number(chainId)]) === null || _h === void 0 ? void 0 : _h.RPC_URL)),
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
{
|
|
578
|
-
chain: chainToUse,
|
|
579
|
-
transport: (0, viem_1.http)(rpcUrl ||
|
|
580
|
-
((_j = optionsRaw[0]) === null || _j === void 0 ? void 0 : _j.rpcUrl) ||
|
|
581
|
-
((_k = constants_1.PaymasterConstants[Number(chainId)]) === null || _k === void 0 ? void 0 : _k.RPC_URL)),
|
|
582
|
-
version: (0, abstractjs_1.getMEEVersion)(abstractjs_1.MEEVersion.V2_0_0),
|
|
583
|
-
},
|
|
584
|
-
],
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
const meeAddress = nexusAccount.addressOn(chainId);
|
|
720
|
+
version: (0, abstractjs_1.getMEEVersion)(abstractjs_1.MEEVersion.V2_0_0),
|
|
721
|
+
},
|
|
722
|
+
],
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
// const meeAddress = nexusAccount.addressOn(chainId);
|
|
726
|
+
if ((_j = optionsRaw[0]) === null || _j === void 0 ? void 0 : _j.paymentToken) {
|
|
727
|
+
console.log("Using Mee erc20 payment with paymentToken of: ", (_k = optionsRaw[0]) === null || _k === void 0 ? void 0 : _k.paymentToken);
|
|
588
728
|
// console.log("nexus account address: ", meeAddress);
|
|
589
|
-
return await this.callFunctionWithMEEClient(nexusAccount, chainId, tx1, (_l = optionsRaw[0]) === null || _l === void 0 ? void 0 : _l.paymentToken, (_m = optionsRaw[0]) === null || _m === void 0 ? void 0 : _m.apiKey);
|
|
729
|
+
return await this.callFunctionWithMEEClient(nexusAccount, chainId, tx1, functionName, (_l = optionsRaw[0]) === null || _l === void 0 ? void 0 : _l.paymentToken, false, (_m = optionsRaw[0]) === null || _m === void 0 ? void 0 : _m.apiKey, ...args);
|
|
590
730
|
}
|
|
591
731
|
else {
|
|
592
|
-
console.log("Using
|
|
593
|
-
|
|
594
|
-
constants_1.PaymasterConstants[`${chainId}`]["PAYMENT_TOKEN"] ||
|
|
595
|
-
"";
|
|
596
|
-
return await this.callFunctionAsUserOp(smartAccount, tx1, functionName, paymentToken, ...args);
|
|
732
|
+
console.log("Using mee gas sponsorship since no payment token...");
|
|
733
|
+
return await this.callFunctionWithMEEClient(nexusAccount, chainId, tx1, functionName, (_o = optionsRaw[0]) === null || _o === void 0 ? void 0 : _o.paymentToken, true, (_p = optionsRaw[0]) === null || _p === void 0 ? void 0 : _p.apiKey, ...args);
|
|
597
734
|
}
|
|
598
735
|
}
|
|
599
736
|
else {
|
|
@@ -603,7 +740,7 @@ class VerifiedContract {
|
|
|
603
740
|
}
|
|
604
741
|
}
|
|
605
742
|
async getQuote(paymentTokenAddress, functionName, args, rpc, _apiKey, isReactNative) {
|
|
606
|
-
var _a, _b, _c, _d, _e, _f;
|
|
743
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
607
744
|
const chainId = await this.signer.getChainId();
|
|
608
745
|
if (this.supportsGasless(chainId)) {
|
|
609
746
|
const _signer = this.signer;
|
|
@@ -640,13 +777,6 @@ class VerifiedContract {
|
|
|
640
777
|
],
|
|
641
778
|
});
|
|
642
779
|
}
|
|
643
|
-
// const nexusAccount = await toMultichainNexusAccount({
|
|
644
|
-
// chains: [chainToUse],
|
|
645
|
-
// transports: [
|
|
646
|
-
// http(rpcUrl || rpc || PaymasterConstants[Number(chainId)]?.RPC_URL),
|
|
647
|
-
// ],
|
|
648
|
-
// signer: _signer,
|
|
649
|
-
// });
|
|
650
780
|
if (paymentTokenAddress) {
|
|
651
781
|
//construct calldata for function
|
|
652
782
|
try {
|
|
@@ -673,26 +803,68 @@ class VerifiedContract {
|
|
|
673
803
|
calls: [tx1],
|
|
674
804
|
},
|
|
675
805
|
});
|
|
806
|
+
const signerAny = this.signer;
|
|
807
|
+
const tokenContract = new erc20_1.default(signerAny, paymentTokenAddress);
|
|
808
|
+
const tokenDecimals = await tokenContract
|
|
809
|
+
.decimals()
|
|
810
|
+
.then((res) => { var _a; return (_a = res === null || res === void 0 ? void 0 : res.response) === null || _a === void 0 ? void 0 : _a.result[0]; });
|
|
811
|
+
const fnTransfer = tokenContract.contract.populateTransaction["transfer"];
|
|
812
|
+
const amountFmt = ethers_1.ethers.utils.parseUnits(constants_1.PaymasterConstants.COMPENSATION_AMOUNT, Number(tokenDecimals));
|
|
813
|
+
const transferArgs = [
|
|
814
|
+
constants_1.PaymasterConstants.ADMIN_WALLET_ADDRESS,
|
|
815
|
+
amountFmt === null || amountFmt === void 0 ? void 0 : amountFmt.toString(),
|
|
816
|
+
];
|
|
817
|
+
const transferFunc = await fnTransfer(...transferArgs);
|
|
818
|
+
const transferTx = {
|
|
819
|
+
to: paymentTokenAddress,
|
|
820
|
+
data: transferFunc.data,
|
|
821
|
+
};
|
|
822
|
+
const transferInstruction = await nexusAccount.build({
|
|
823
|
+
type: "default",
|
|
824
|
+
data: {
|
|
825
|
+
chainId,
|
|
826
|
+
calls: [transferTx],
|
|
827
|
+
},
|
|
828
|
+
});
|
|
676
829
|
const tkAddress = paymentTokenAddress;
|
|
830
|
+
const cmpQuote = await meeClient.getQuote({
|
|
831
|
+
instructions: [transferInstruction],
|
|
832
|
+
feeToken: { address: tkAddress, chainId },
|
|
833
|
+
});
|
|
677
834
|
const quote = await meeClient.getQuote({
|
|
678
835
|
instructions: [transactionInstruction],
|
|
679
836
|
feeToken: { address: tkAddress, chainId },
|
|
680
837
|
});
|
|
681
|
-
|
|
838
|
+
const cmpQuoteDt = {
|
|
839
|
+
tokenAddress: paymentTokenAddress,
|
|
840
|
+
amount: (_e = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenAmount) +
|
|
841
|
+
Number(constants_1.PaymasterConstants.COMPENSATION_AMOUNT))) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
842
|
+
amountInWei: (_f = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenWeiAmount) + Number(amountFmt))) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
843
|
+
amountValue: (_g = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenValue) +
|
|
844
|
+
(Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenAmount) /
|
|
845
|
+
Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenValue)) *
|
|
846
|
+
Number(constants_1.PaymasterConstants.COMPENSATION_AMOUNT))) === null || _g === void 0 ? void 0 : _g.toString(),
|
|
847
|
+
chainId,
|
|
848
|
+
functionName: "transfer",
|
|
849
|
+
};
|
|
682
850
|
return {
|
|
683
851
|
tokenAddress: paymentTokenAddress,
|
|
684
|
-
amount: quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenAmount
|
|
685
|
-
|
|
686
|
-
|
|
852
|
+
amount: (_h = (Number(quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenAmount) +
|
|
853
|
+
Number(cmpQuoteDt === null || cmpQuoteDt === void 0 ? void 0 : cmpQuoteDt.amount))) === null || _h === void 0 ? void 0 : _h.toString(),
|
|
854
|
+
amountInWei: (_j = (Number(quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenWeiAmount) +
|
|
855
|
+
Number(cmpQuoteDt === null || cmpQuoteDt === void 0 ? void 0 : cmpQuoteDt.amountInWei))) === null || _j === void 0 ? void 0 : _j.toString(),
|
|
856
|
+
amountValue: (_k = (Number(quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenValue) +
|
|
857
|
+
Number(cmpQuoteDt === null || cmpQuoteDt === void 0 ? void 0 : cmpQuoteDt.amountValue))) === null || _k === void 0 ? void 0 : _k.toString(),
|
|
687
858
|
chainId,
|
|
688
859
|
functionName,
|
|
689
860
|
};
|
|
690
861
|
}
|
|
691
862
|
catch (err) {
|
|
692
|
-
if ((
|
|
863
|
+
if (((_l = err === null || err === void 0 ? void 0 : err.message) === null || _l === void 0 ? void 0 : _l.includes("fn is not a function")) ||
|
|
864
|
+
((_m = err === null || err === void 0 ? void 0 : err.message) === null || _m === void 0 ? void 0 : _m.includes("fnTransfer is not a function"))) {
|
|
693
865
|
console.error(`Function ${functionName} not found in contract's ABI`);
|
|
694
866
|
}
|
|
695
|
-
else if ((
|
|
867
|
+
else if ((_o = err === null || err === void 0 ? void 0 : err.message) === null || _o === void 0 ? void 0 : _o.includes("code=INVALID_ARGUMENT")) {
|
|
696
868
|
console.error(`Invalid arguments type`);
|
|
697
869
|
}
|
|
698
870
|
console.error((err === null || err === void 0 ? void 0 : err.message) || "getQuote failed.");
|
package/dist/utils/constants.js
CHANGED
|
@@ -3,49 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PaymasterConstants = void 0;
|
|
4
4
|
//Todo: add more network paymaster details for gasless
|
|
5
5
|
exports.PaymasterConstants = {
|
|
6
|
-
MAX_WAITING_ROUND: 10, //number of rounds gassless transactions will wait to fetch receipt. Note: each round is 6 seconds, so 10 for example is 1 minute
|
|
7
|
-
BUNDLER_URL_FIRST_SECTION: "https://bundler.biconomy.io/api/v2",
|
|
8
|
-
GENERAL_PAYMASTER_URL: "https://paymaster.biconomy.io/api/v1",
|
|
9
6
|
MEE_API_KEY: "mee_XGE8XYuTujTdkB4sohJMHv",
|
|
10
|
-
MEE_API_KEY_STAGING: "
|
|
7
|
+
MEE_API_KEY_STAGING: "mee_3Zmc7H6Pbd5wUfUGu27aGzdf", //Biconomy sponsorship enabled staging api key???
|
|
11
8
|
MEE_URL_STAGING: "https://staging-network.biconomy.io/v1",
|
|
12
9
|
TEST_CHAINS: [11155111, 84532],
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
BUNDLER_API_KEY: "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
|
|
18
|
-
RPC_URL: "https://eth-sepolia.public.blastapi.io",
|
|
19
|
-
PAYMENT_TOKEN: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
|
|
20
|
-
},
|
|
21
|
-
//polgon mainnet
|
|
22
|
-
137: {
|
|
23
|
-
PAYMASTER_API_KEY: "lDHvYk50N.30a2522e-0a9d-444b-b949-19194c1f237a",
|
|
24
|
-
BUNDLER_API_KEY: "dewj2189.wh1289hU-7E49-45ic-af80-JkuxGCYRV",
|
|
25
|
-
RPC_URL: "https://polygon-rpc.com",
|
|
26
|
-
},
|
|
27
|
-
//base sepolia
|
|
28
|
-
84532: {
|
|
29
|
-
PAYMASTER_API_KEY: "jSBI-WRji.99a4dda1-1c20-42ea-9409-2724f9a0ca7e",
|
|
30
|
-
BUNDLER_API_KEY: "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
|
|
31
|
-
RPC_URL: "https://sepolia.base.org",
|
|
32
|
-
},
|
|
33
|
-
//ethereum mainnet
|
|
34
|
-
1: {
|
|
35
|
-
PAYMASTER_API_KEY: "ap7LOqALI.bf68e672-47ce-40f8-8b62-ea508dcf5852",
|
|
36
|
-
BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
|
|
37
|
-
RPC_URL: "https://eth-mainnet.public.blastapi.io",
|
|
38
|
-
},
|
|
39
|
-
//base mainnet
|
|
40
|
-
8453: {
|
|
41
|
-
PAYMASTER_API_KEY: "glRQsmuYh.5d9372ab-5063-4ecd-ac63-643fef624a73",
|
|
42
|
-
BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
|
|
43
|
-
RPC_URL: "https://base-mainnet.public.blastapi.io",
|
|
44
|
-
},
|
|
45
|
-
//gnosis
|
|
46
|
-
100: {
|
|
47
|
-
PAYMASTER_API_KEY: "eUYghbvi4.317a2d6d-6ee7-4a0c-b91f-43ba2699f65b",
|
|
48
|
-
BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
|
|
49
|
-
RPC_URL: "https://rpc.gnosischain.com",
|
|
10
|
+
SPONSORSHIP_GASTANK_TEST: {
|
|
11
|
+
chainId: 11155111,
|
|
12
|
+
token: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
|
|
13
|
+
address: "0x8a2997ba9B9A51aF7C63914829450260B12B75e5",
|
|
50
14
|
},
|
|
15
|
+
HOSTED_SPONSOR_URL: "https://gateway.verified.network/api/sponsor", //TODO: update to hosted sponsor url
|
|
16
|
+
ADMIN_WALLET_ADDRESS: "0x5DBDA7BE05F68131e260f5A2bC573b24692a5B34", //test admin
|
|
17
|
+
COMPENSATION_AMOUNT: "0.02", //2 Cents
|
|
51
18
|
};
|