@verified-network/verified-sdk 2.5.5 → 2.5.6
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 +1 -1
- package/dist/contract/index.js +73 -66
- package/dist/utils/constants.js +1 -1
- package/package.json +1 -1
package/dist/contract/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export declare class VerifiedContract {
|
|
|
61
61
|
/** Constructs and call function as userop for biconomy gassless(sponsored/erc20 mode) */
|
|
62
62
|
callFunctionAsUserOp(smartAccount: any, tx: any, functionName: string, paymentToken: string, ...args: any): Promise<SCResponse>;
|
|
63
63
|
/** Constructs and call function using MEE client that allows gas payment in ERC20 tokens */
|
|
64
|
-
callFunctionWithMEEClient(nexusAccount: any, chainId: number, rpc: string, tx: any, functionName: string, paymentToken: `0x${string}`, isSponsor?: boolean, _apiKey?: string, ...args: any): Promise<SCResponse>;
|
|
64
|
+
callFunctionWithMEEClient(nexusAccount: any, chainId: number, rpc: string, tx: any, functionName: string, paymentToken: `0x${string}`, isSponsor?: boolean, signerPk?: string, _apiKey?: string, ...args: any): Promise<SCResponse>;
|
|
65
65
|
callContract(functionName: string, ...args: any): Promise<SCResponse>;
|
|
66
66
|
getQuote(paymentTokenAddress: string, functionName: string, args: any[], rpc?: string, _apiKey?: string, isReactNative?: boolean): Promise<{
|
|
67
67
|
tokenAddress: string;
|
package/dist/contract/index.js
CHANGED
|
@@ -195,12 +195,14 @@ class VerifiedContract {
|
|
|
195
195
|
}
|
|
196
196
|
/** Checks if a contract support gasless transaction */
|
|
197
197
|
supportsGasless(chainId) {
|
|
198
|
-
let isSupported = false;
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
198
|
+
// let isSupported = false;
|
|
199
|
+
// if (
|
|
200
|
+
// PaymasterConstants[`${chainId}`] &&
|
|
201
|
+
// PaymasterConstants[`${chainId}`]["PAYMASTER_API_KEY"] &&
|
|
202
|
+
// PaymasterConstants[`${chainId}`]["BUNDLER_API_KEY"]
|
|
203
|
+
// )
|
|
204
|
+
// isSupported = true;
|
|
205
|
+
return true;
|
|
204
206
|
}
|
|
205
207
|
/** Creates Biconomy smart account */
|
|
206
208
|
async createSmartAccount(chainId) {
|
|
@@ -379,8 +381,8 @@ class VerifiedContract {
|
|
|
379
381
|
}
|
|
380
382
|
}
|
|
381
383
|
/** Constructs and call function using MEE client that allows gas payment in ERC20 tokens */
|
|
382
|
-
async callFunctionWithMEEClient(nexusAccount, chainId, rpc, tx, functionName, paymentToken, isSponsor, _apiKey, ...args) {
|
|
383
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t
|
|
384
|
+
async callFunctionWithMEEClient(nexusAccount, chainId, rpc, tx, functionName, paymentToken, isSponsor, signerPk, _apiKey, ...args) {
|
|
385
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
384
386
|
let res = {};
|
|
385
387
|
let txHash = "";
|
|
386
388
|
let recp;
|
|
@@ -442,27 +444,23 @@ class VerifiedContract {
|
|
|
442
444
|
const sponsorUrl = constants_1.PaymasterConstants.HOSTED_SPONSOR_URL;
|
|
443
445
|
let quote, cmpQuote;
|
|
444
446
|
if (isSponsor) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
"cnt-rpc": rpc,
|
|
454
|
-
"cnt-isquote": "true",
|
|
455
|
-
},
|
|
456
|
-
gasTank: {
|
|
457
|
-
address: (_c = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _c === void 0 ? void 0 : _c.account,
|
|
458
|
-
token: (_d = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _d === void 0 ? void 0 : _d.token,
|
|
459
|
-
chainId: (_e = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _e === void 0 ? void 0 : _e.chainId,
|
|
460
|
-
},
|
|
461
|
-
},
|
|
462
|
-
simulation: {
|
|
463
|
-
simulate: true,
|
|
447
|
+
const response = await fetch(`${sponsorUrl}/sponsorship/sign/${(_c = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _c === void 0 ? void 0 : _c.chainId}/${(_d = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _d === void 0 ? void 0 : _d.account}`, {
|
|
448
|
+
method: "POST",
|
|
449
|
+
headers: {
|
|
450
|
+
"cnt-tx": JSON.stringify(tx),
|
|
451
|
+
"cnt-chainid": chainId === null || chainId === void 0 ? void 0 : chainId.toString(),
|
|
452
|
+
"cnt-rpc": rpc,
|
|
453
|
+
"cnt-isquote": "true",
|
|
454
|
+
"cnt-pk": signerPk,
|
|
464
455
|
},
|
|
456
|
+
body: null,
|
|
465
457
|
});
|
|
458
|
+
if (!response.ok) {
|
|
459
|
+
quote = null;
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
quote = await response.json();
|
|
463
|
+
}
|
|
466
464
|
}
|
|
467
465
|
else {
|
|
468
466
|
cmpQuote = await meeClient.getQuote({
|
|
@@ -486,7 +484,7 @@ class VerifiedContract {
|
|
|
486
484
|
data: {
|
|
487
485
|
chainId,
|
|
488
486
|
calls: [
|
|
489
|
-
Object.assign(Object.assign({}, tx), { gasLimit: (
|
|
487
|
+
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 }),
|
|
490
488
|
],
|
|
491
489
|
},
|
|
492
490
|
});
|
|
@@ -497,22 +495,23 @@ class VerifiedContract {
|
|
|
497
495
|
data: {
|
|
498
496
|
chainId,
|
|
499
497
|
calls: [
|
|
500
|
-
Object.assign(Object.assign({}, transferTx), { gasLimit: (
|
|
498
|
+
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 }),
|
|
501
499
|
],
|
|
502
500
|
},
|
|
503
501
|
});
|
|
504
502
|
}
|
|
505
|
-
// Execute the transaction using passed paymentToken
|
|
503
|
+
// Execute the transaction using passed paymentToken or gasless details
|
|
506
504
|
let _txHash;
|
|
507
505
|
if (isSponsor) {
|
|
508
506
|
let res;
|
|
509
|
-
const response = await fetch(`${sponsorUrl}/sponsorship/sign/${(
|
|
507
|
+
const response = await fetch(`${sponsorUrl}/sponsorship/sign/${(_j = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _j === void 0 ? void 0 : _j.chainId}/${(_k = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _k === void 0 ? void 0 : _k.account}`, {
|
|
510
508
|
method: "POST",
|
|
511
509
|
headers: {
|
|
512
|
-
"cnt-tx": JSON.stringify(Object.assign(Object.assign({}, tx), { gasLimit: (
|
|
510
|
+
"cnt-tx": JSON.stringify(Object.assign(Object.assign({}, tx), { gasLimit: (_m = quote === null || quote === void 0 ? void 0 : quote.userOps[((_l = quote === null || quote === void 0 ? void 0 : quote.userOps) === null || _l === void 0 ? void 0 : _l.length) - 1]) === null || _m === void 0 ? void 0 : _m.maxGasLimit })),
|
|
513
511
|
"cnt-chainid": chainId === null || chainId === void 0 ? void 0 : chainId.toString(),
|
|
514
512
|
"cnt-rpc": rpc,
|
|
515
513
|
"cnt-isquote": "false",
|
|
514
|
+
"cnt-pk": signerPk,
|
|
516
515
|
},
|
|
517
516
|
body: null,
|
|
518
517
|
});
|
|
@@ -538,9 +537,9 @@ class VerifiedContract {
|
|
|
538
537
|
const cmpReceipt = await meeClient.waitForSupertransactionReceipt({
|
|
539
538
|
hash: cmpHash,
|
|
540
539
|
});
|
|
541
|
-
if (((
|
|
540
|
+
if (((_o = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts) === null || _o === void 0 ? void 0 : _o.length) > 0) {
|
|
542
541
|
//always pick last receipt????
|
|
543
|
-
const txReceipt = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[((
|
|
542
|
+
const txReceipt = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[((_p = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts) === null || _p === void 0 ? void 0 : _p.length) - 1];
|
|
544
543
|
if ((txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.status) === "success") {
|
|
545
544
|
// console.log(
|
|
546
545
|
// "Compensation tx successful will move to regular transaction...",
|
|
@@ -569,7 +568,7 @@ class VerifiedContract {
|
|
|
569
568
|
console.error("MEE client transaction failed with error: ", "Invalid receipts length");
|
|
570
569
|
res.status = STATUS.ERROR;
|
|
571
570
|
res.response = {
|
|
572
|
-
hash: (
|
|
571
|
+
hash: (_q = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[0]) === null || _q === void 0 ? void 0 : _q.transactionHash,
|
|
573
572
|
result: cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[0],
|
|
574
573
|
}; //TODO: update result on response
|
|
575
574
|
res.message = "";
|
|
@@ -584,9 +583,9 @@ class VerifiedContract {
|
|
|
584
583
|
});
|
|
585
584
|
// console.log("receipts: ", receipt);
|
|
586
585
|
// console.log("receiptsss...: ", receipt?.receipts);
|
|
587
|
-
if (((
|
|
586
|
+
if (((_r = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _r === void 0 ? void 0 : _r.length) > 0) {
|
|
588
587
|
//always pick last receipt????
|
|
589
|
-
const txReceipt = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[((
|
|
588
|
+
const txReceipt = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[((_s = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _s === void 0 ? void 0 : _s.length) - 1];
|
|
590
589
|
if ((txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.status) === "success") {
|
|
591
590
|
res.status = STATUS.SUCCESS;
|
|
592
591
|
res.response = {
|
|
@@ -620,7 +619,7 @@ class VerifiedContract {
|
|
|
620
619
|
else {
|
|
621
620
|
res.status = STATUS.ERROR;
|
|
622
621
|
res.response = {
|
|
623
|
-
hash: (
|
|
622
|
+
hash: (_t = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[0]) === null || _t === void 0 ? void 0 : _t.transactionHash,
|
|
624
623
|
result: receipt === null || receipt === void 0 ? void 0 : receipt.receipts[0],
|
|
625
624
|
}; //TODO: update result on response
|
|
626
625
|
res.message = "";
|
|
@@ -646,7 +645,7 @@ class VerifiedContract {
|
|
|
646
645
|
}
|
|
647
646
|
}
|
|
648
647
|
async callContract(functionName, ...args) {
|
|
649
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
648
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
650
649
|
// Check if the function is a read function
|
|
651
650
|
if (this.isReadFunction(functionName)) {
|
|
652
651
|
console.log("read function will use ethers");
|
|
@@ -697,44 +696,52 @@ class VerifiedContract {
|
|
|
697
696
|
const prov = this.signer.provider;
|
|
698
697
|
const rpcUrl = (_c = prov === null || prov === void 0 ? void 0 : prov.connection) === null || _c === void 0 ? void 0 : _c.url;
|
|
699
698
|
let nexusAccount;
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
(
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
699
|
+
try {
|
|
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 ||
|
|
718
|
+
((_g = optionsRaw[0]) === null || _g === void 0 ? void 0 : _g.rpcUrl) ||
|
|
719
|
+
((_h = constants_1.PaymasterConstants[Number(chainId)]) === null || _h === void 0 ? void 0 : _h.RPC_URL)),
|
|
720
|
+
version: (0, abstractjs_1.getMEEVersion)(abstractjs_1.MEEVersion.V2_0_0),
|
|
721
|
+
},
|
|
722
|
+
],
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
// const meeAddress = nexusAccount.addressOn(chainId);
|
|
710
726
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
chainConfigurations: [
|
|
715
|
-
{
|
|
716
|
-
chain: chainToUse,
|
|
717
|
-
transport: (0, viem_1.http)(rpcUrl ||
|
|
718
|
-
((_g = optionsRaw[0]) === null || _g === void 0 ? void 0 : _g.rpcUrl) ||
|
|
719
|
-
((_h = constants_1.PaymasterConstants[Number(chainId)]) === null || _h === void 0 ? void 0 : _h.RPC_URL)),
|
|
720
|
-
version: (0, abstractjs_1.getMEEVersion)(abstractjs_1.MEEVersion.V2_0_0),
|
|
721
|
-
},
|
|
722
|
-
],
|
|
723
|
-
});
|
|
727
|
+
catch (err) {
|
|
728
|
+
console.log("Gas sponsorship failed will use ethers...");
|
|
729
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
724
730
|
}
|
|
725
|
-
// const meeAddress = nexusAccount.addressOn(chainId);
|
|
726
731
|
if ((_j = optionsRaw[0]) === null || _j === void 0 ? void 0 : _j.paymentToken) {
|
|
727
732
|
console.log("Using Mee erc20 payment with paymentToken of: ", (_k = optionsRaw[0]) === null || _k === void 0 ? void 0 : _k.paymentToken);
|
|
728
733
|
// console.log("nexus account address: ", meeAddress);
|
|
729
734
|
return await this.callFunctionWithMEEClient(nexusAccount, chainId, rpcUrl ||
|
|
730
735
|
((_l = optionsRaw[0]) === null || _l === void 0 ? void 0 : _l.rpcUrl) ||
|
|
731
|
-
((_m = constants_1.PaymasterConstants[Number(chainId)]) === null || _m === void 0 ? void 0 : _m.RPC_URL), tx1, functionName, (_o = optionsRaw[0]) === null || _o === void 0 ? void 0 : _o.paymentToken, false, (_p = optionsRaw[0]) === null || _p === void 0 ? void 0 : _p.apiKey, ...args);
|
|
736
|
+
((_m = constants_1.PaymasterConstants[Number(chainId)]) === null || _m === void 0 ? void 0 : _m.RPC_URL), tx1, functionName, (_o = optionsRaw[0]) === null || _o === void 0 ? void 0 : _o.paymentToken, false, undefined, (_p = optionsRaw[0]) === null || _p === void 0 ? void 0 : _p.apiKey, ...args);
|
|
732
737
|
}
|
|
733
738
|
else {
|
|
734
739
|
console.log("Using mee gas sponsorship since no payment token...");
|
|
740
|
+
const signerAny = this.signer;
|
|
741
|
+
const signerPk = (_q = signerAny === null || signerAny === void 0 ? void 0 : signerAny._signingKey()) === null || _q === void 0 ? void 0 : _q.privateKey;
|
|
735
742
|
return await this.callFunctionWithMEEClient(nexusAccount, chainId, rpcUrl ||
|
|
736
|
-
((
|
|
737
|
-
((
|
|
743
|
+
((_r = optionsRaw[0]) === null || _r === void 0 ? void 0 : _r.rpcUrl) ||
|
|
744
|
+
((_s = constants_1.PaymasterConstants[Number(chainId)]) === null || _s === void 0 ? void 0 : _s.RPC_URL), tx1, functionName, (_t = optionsRaw[0]) === null || _t === void 0 ? void 0 : _t.paymentToken, true, signerPk, (_u = optionsRaw[0]) === null || _u === void 0 ? void 0 : _u.apiKey, ...args);
|
|
738
745
|
}
|
|
739
746
|
}
|
|
740
747
|
else {
|
package/dist/utils/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
-
MEE_API_KEY: "mee_G5SSkmZYg9kiGksxJwFT9x",
|
|
6
|
+
MEE_API_KEY: "mee_G5SSkmZYg9kiGksxJwFT9x", //Non sponsored key from dashboard
|
|
7
7
|
MEE_API_KEY_STAGING: "mee_3Zmc7H6Pbd5wUfUGu27aGzdf", //Biconomy sponsorship enabled staging api key???
|
|
8
8
|
MEE_URL_STAGING: "https://staging-network.biconomy.io/v1",
|
|
9
9
|
TEST_CHAINS: [11155111, 84532, 421614],
|