@verified-network/verified-sdk 2.5.3 → 2.5.5

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.
@@ -32,6 +32,7 @@ export declare class VerifiedContract {
32
32
  private signer;
33
33
  private contract;
34
34
  private abiInterface;
35
+ private abiRaw;
35
36
  constructor(address: string, abi: string, signer: VerifiedWallet | Signer);
36
37
  protected validateInput(type: DATATYPES, data: any): Promise<boolean>;
37
38
  protected sanitiseInput(type: DATATYPES, data: any): any;
@@ -60,15 +61,24 @@ export declare class VerifiedContract {
60
61
  /** Constructs and call function as userop for biconomy gassless(sponsored/erc20 mode) */
61
62
  callFunctionAsUserOp(smartAccount: any, tx: any, functionName: string, paymentToken: string, ...args: any): Promise<SCResponse>;
62
63
  /** 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>;
64
+ callFunctionWithMEEClient(nexusAccount: any, chainId: number, rpc: string, tx: any, functionName: string, paymentToken: `0x${string}`, isSponsor?: boolean, _apiKey?: string, ...args: any): Promise<SCResponse>;
64
65
  callContract(functionName: string, ...args: any): Promise<SCResponse>;
65
66
  getQuote(paymentTokenAddress: string, functionName: string, args: any[], rpc?: string, _apiKey?: string, isReactNative?: boolean): Promise<{
67
+ tokenAddress: string;
68
+ amount: string;
69
+ amountInWei: string;
70
+ amountValue: string;
71
+ chainId: number;
72
+ functionName: string;
73
+ amouuntValue?: undefined;
74
+ } | {
66
75
  tokenAddress: string;
67
76
  amount: string;
68
77
  amountInWei: string;
69
78
  amouuntValue: string;
70
79
  chainId: number;
71
80
  functionName: string;
81
+ amountValue?: undefined;
72
82
  }>;
73
83
  protected getEvent(eventName: string, callback: any): void;
74
84
  }
@@ -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_json_1 = __importDefault(require("../abi/payments/ERC20.json"));
12
16
  var STATUS;
13
17
  (function (STATUS) {
14
18
  STATUS[STATUS["SUCCESS"] = 0] = "SUCCESS";
@@ -28,6 +32,7 @@ class VerifiedContract {
28
32
  constructor(address, abi, signer) {
29
33
  this.signer = signer;
30
34
  this.abiInterface = new ethers_1.utils.Interface(abi);
35
+ this.abiRaw = JSON.parse(abi);
31
36
  this.contract = new ethers_1.ethers.Contract(address, this.abiInterface, signer);
32
37
  }
33
38
  async validateInput(type, data) {
@@ -322,37 +327,6 @@ class VerifiedContract {
322
327
  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
328
  //wait up to max round to fetch receipt ???
324
329
  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
330
  for (let i = 0; i < Number(constants_1.PaymasterConstants.MAX_WAITING_ROUND); i++) {
357
331
  await new Promise((resolve) => setTimeout(resolve, 6000)); // 6 second delay
358
332
  console.log("Gassless timeout exceeded, fetching receipt for round:", i + 1, "out of", Number(constants_1.PaymasterConstants.MAX_WAITING_ROUND));
@@ -405,8 +379,8 @@ class VerifiedContract {
405
379
  }
406
380
  }
407
381
  /** 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;
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, _u;
410
384
  let res = {};
411
385
  let txHash = "";
412
386
  let recp;
@@ -428,41 +402,191 @@ class VerifiedContract {
428
402
  calls: [tx],
429
403
  },
430
404
  });
431
- const quote = await meeClient.getQuote({
432
- instructions: [transactionInstruction],
433
- feeToken: { address: paymentToken, chainId },
434
- simulation: {
435
- simulate: true,
436
- },
437
- });
405
+ let transferInstruction, transferTx;
406
+ if (!isSponsor) {
407
+ const signerAny = this.signer;
408
+ const tokenContract = new ethers_1.ethers.Contract(paymentToken, new ethers_1.utils.Interface(ERC20_json_1.default === null || ERC20_json_1.default === void 0 ? void 0 : ERC20_json_1.default.abi), signerAny);
409
+ const tokenDecimals = await tokenContract.decimals();
410
+ const fn = tokenContract.populateTransaction["transfer"];
411
+ const amountFmt = ethers_1.ethers.utils.parseUnits(constants_1.PaymasterConstants.COMPENSATION_AMOUNT, Number(tokenDecimals));
412
+ const transferArgs = [
413
+ constants_1.PaymasterConstants.ADMIN_WALLET_ADDRESS,
414
+ amountFmt === null || amountFmt === void 0 ? void 0 : amountFmt.toString(),
415
+ ];
416
+ const transferFunc = await fn(...transferArgs);
417
+ const _transferTx = {
418
+ to: paymentToken,
419
+ data: transferFunc.data,
420
+ };
421
+ transferTx = _transferTx;
422
+ transferInstruction = await nexusAccount.build({
423
+ type: "default",
424
+ data: {
425
+ chainId,
426
+ calls: [_transferTx],
427
+ },
428
+ });
429
+ }
430
+ const isTestnet = (_b = constants_1.PaymasterConstants.TEST_CHAINS) === null || _b === void 0 ? void 0 : _b.includes(chainId);
431
+ let sponsorInfo;
432
+ //Use constant gas tanks instead of fetching from server to reduce tx time???
433
+ if (isSponsor) {
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 = constants_1.PaymasterConstants.HOSTED_SPONSOR_URL;
443
+ let quote, cmpQuote;
444
+ if (isSponsor) {
445
+ quote = await meeClient.getQuote({
446
+ instructions: [transactionInstruction],
447
+ sponsorship: true,
448
+ sponsorshipOptions: {
449
+ url: sponsorUrl,
450
+ customHeaders: {
451
+ "cnt-tx": JSON.stringify(tx),
452
+ "cnt-chainid": chainId === null || chainId === void 0 ? void 0 : chainId.toString(),
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,
464
+ },
465
+ });
466
+ }
467
+ else {
468
+ cmpQuote = await meeClient.getQuote({
469
+ instructions: [transferInstruction],
470
+ feeToken: { address: paymentToken, chainId },
471
+ simulation: {
472
+ simulate: true,
473
+ },
474
+ });
475
+ quote = await meeClient.getQuote({
476
+ instructions: [transactionInstruction],
477
+ feeToken: { address: paymentToken, chainId },
478
+ simulation: {
479
+ simulate: true,
480
+ },
481
+ });
482
+ }
438
483
  const nowInSec = Math.floor(Date.now() / 1000);
439
484
  const transactionInstructionFinal = await nexusAccount.build({
440
485
  type: "default",
441
486
  data: {
442
487
  chainId,
443
488
  calls: [
444
- Object.assign(Object.assign({}, tx), { gasLimit: (_c = quote === null || quote === void 0 ? void 0 : quote.userOps[((_b = quote === null || quote === void 0 ? void 0 : quote.userOps) === null || _b === void 0 ? void 0 : _b.length) - 1]) === null || _c === void 0 ? void 0 : _c.maxGasLimit }),
489
+ Object.assign(Object.assign({}, tx), { gasLimit: (_g = quote === null || quote === void 0 ? void 0 : quote.userOps[((_f = quote === null || quote === void 0 ? void 0 : quote.userOps) === null || _f === void 0 ? void 0 : _f.length) - 1]) === null || _g === void 0 ? void 0 : _g.maxGasLimit }),
445
490
  ],
446
491
  },
447
492
  });
493
+ let transferInstructionFinal;
494
+ if (!isSponsor) {
495
+ transferInstructionFinal = await nexusAccount.build({
496
+ type: "default",
497
+ data: {
498
+ chainId,
499
+ calls: [
500
+ Object.assign(Object.assign({}, transferTx), { gasLimit: (_j = cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.userOps[((_h = cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.userOps) === null || _h === void 0 ? void 0 : _h.length) - 1]) === null || _j === void 0 ? void 0 : _j.maxGasLimit }),
501
+ ],
502
+ },
503
+ });
504
+ }
448
505
  // Execute the transaction using passed paymentToken
449
- const { hash } = await meeClient.execute({
450
- feeToken: {
451
- chainId,
452
- address: paymentToken,
453
- },
454
- instructions: [transactionInstructionFinal],
455
- upperBoundTimestamp: nowInSec + 299, //highest is 5 minutes???
456
- });
457
- txHash = hash;
458
- console.log(`MEE transaction hash: ${hash}`);
506
+ let _txHash;
507
+ if (isSponsor) {
508
+ let res;
509
+ const response = await fetch(`${sponsorUrl}/sponsorship/sign/${(_k = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _k === void 0 ? void 0 : _k.chainId}/${(_l = sponsorInfo[isTestnet ? "84532" : "8453"]) === null || _l === void 0 ? void 0 : _l.account}`, {
510
+ method: "POST",
511
+ headers: {
512
+ "cnt-tx": JSON.stringify(Object.assign(Object.assign({}, tx), { gasLimit: (_o = quote === null || quote === void 0 ? void 0 : quote.userOps[((_m = quote === null || quote === void 0 ? void 0 : quote.userOps) === null || _m === void 0 ? void 0 : _m.length) - 1]) === null || _o === void 0 ? void 0 : _o.maxGasLimit })),
513
+ "cnt-chainid": chainId === null || chainId === void 0 ? void 0 : chainId.toString(),
514
+ "cnt-rpc": rpc,
515
+ "cnt-isquote": "false",
516
+ },
517
+ body: null,
518
+ });
519
+ if (!response.ok) {
520
+ res = { hash: "" };
521
+ }
522
+ else {
523
+ res = await response.json();
524
+ }
525
+ _txHash = res === null || res === void 0 ? void 0 : res.hash;
526
+ }
527
+ else {
528
+ //handle it seperately as batch kept failing???
529
+ const { hash: cmpHash } = await meeClient.execute({
530
+ feeToken: {
531
+ chainId,
532
+ address: paymentToken,
533
+ },
534
+ instructions: [transferInstructionFinal], //take conpensation first???
535
+ upperBoundTimestamp: nowInSec + 299, //highest is 5 minutes???
536
+ });
537
+ // console.log("Compensation tx MEE hash: ", cmpHash);
538
+ const cmpReceipt = await meeClient.waitForSupertransactionReceipt({
539
+ hash: cmpHash,
540
+ });
541
+ if (((_p = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts) === null || _p === void 0 ? void 0 : _p.length) > 0) {
542
+ //always pick last receipt????
543
+ const txReceipt = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[((_q = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts) === null || _q === void 0 ? void 0 : _q.length) - 1];
544
+ if ((txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.status) === "success") {
545
+ // console.log(
546
+ // "Compensation tx successful will move to regular transaction...",
547
+ // );
548
+ const { hash } = await meeClient.execute({
549
+ feeToken: {
550
+ chainId,
551
+ address: paymentToken,
552
+ },
553
+ instructions: [transactionInstructionFinal],
554
+ upperBoundTimestamp: nowInSec + 299, //highest is 5 minutes???
555
+ });
556
+ _txHash = hash;
557
+ }
558
+ else {
559
+ res.status = STATUS.ERROR;
560
+ res.response = {
561
+ hash: txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.transactionHash,
562
+ result: txReceipt,
563
+ }; //TODO: update result on response
564
+ res.message = "";
565
+ return res;
566
+ }
567
+ }
568
+ else {
569
+ console.error("MEE client transaction failed with error: ", "Invalid receipts length");
570
+ res.status = STATUS.ERROR;
571
+ res.response = {
572
+ hash: (_r = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[0]) === null || _r === void 0 ? void 0 : _r.transactionHash,
573
+ result: cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[0],
574
+ }; //TODO: update result on response
575
+ res.message = "";
576
+ return res;
577
+ }
578
+ }
579
+ txHash = _txHash;
580
+ console.log(`MEE transaction hash: ${_txHash}`);
459
581
  // Wait for transaction to complete
460
- const receipt = await meeClient.waitForSupertransactionReceipt({ hash });
582
+ const receipt = await meeClient.waitForSupertransactionReceipt({
583
+ hash: _txHash,
584
+ });
461
585
  // console.log("receipts: ", receipt);
462
- // console.log("receipt: ", receipt?.receipts);
463
- if (((_d = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _d === void 0 ? void 0 : _d.length) > 0) {
586
+ // console.log("receiptsss...: ", receipt?.receipts);
587
+ if (((_s = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _s === void 0 ? void 0 : _s.length) > 0) {
464
588
  //always pick last receipt????
465
- const txReceipt = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[((_e = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _e === void 0 ? void 0 : _e.length) - 1];
589
+ const txReceipt = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[((_t = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _t === void 0 ? void 0 : _t.length) - 1];
466
590
  if ((txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.status) === "success") {
467
591
  res.status = STATUS.SUCCESS;
468
592
  res.response = {
@@ -471,40 +595,58 @@ class VerifiedContract {
471
595
  }; //TODO: update result on response
472
596
  res.message = "";
473
597
  }
598
+ else {
599
+ if (isSponsor) {
600
+ console.log("Will use ethers...");
601
+ return await this.callFunctionWithEthers(functionName, ...args);
602
+ }
603
+ else {
604
+ res.status = STATUS.ERROR;
605
+ res.response = {
606
+ hash: txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.transactionHash,
607
+ result: txReceipt,
608
+ }; //TODO: update result on response
609
+ res.message = "";
610
+ }
611
+ }
612
+ return res;
613
+ }
614
+ else {
615
+ console.error("MEE client transaction failed with error: ", "Invalid receipts length");
616
+ if (isSponsor) {
617
+ console.log("Will use ethers...");
618
+ return await this.callFunctionWithEthers(functionName, ...args);
619
+ }
474
620
  else {
475
621
  res.status = STATUS.ERROR;
476
622
  res.response = {
477
- hash: txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.transactionHash,
478
- result: txReceipt,
623
+ hash: (_u = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[0]) === null || _u === void 0 ? void 0 : _u.transactionHash,
624
+ result: receipt === null || receipt === void 0 ? void 0 : receipt.receipts[0],
479
625
  }; //TODO: update result on response
480
626
  res.message = "";
627
+ return res;
481
628
  }
482
- return res;
629
+ }
630
+ }
631
+ catch (err) {
632
+ console.error("MEE client transaction failed with error: ", err === null || err === void 0 ? void 0 : err.message);
633
+ if (isSponsor) {
634
+ console.log("Will use ethers...");
635
+ return await this.callFunctionWithEthers(functionName, ...args);
483
636
  }
484
637
  else {
485
- console.error("MEE client transaction failed with error: ", "Invalid receipts length");
486
638
  res.status = STATUS.ERROR;
487
639
  res.response = {
488
- hash: (_f = receipt === null || receipt === void 0 ? void 0 : receipt.receipts[0]) === null || _f === void 0 ? void 0 : _f.transactionHash,
489
- result: receipt === null || receipt === void 0 ? void 0 : receipt.receipts[0],
640
+ hash: txHash,
641
+ result: {},
490
642
  }; //TODO: update result on response
491
643
  res.message = "";
492
644
  return res;
493
645
  }
494
646
  }
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
647
  }
506
648
  async callContract(functionName, ...args) {
507
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
649
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
508
650
  // Check if the function is a read function
509
651
  if (this.isReadFunction(functionName)) {
510
652
  console.log("read function will use ethers");
@@ -512,7 +654,7 @@ class VerifiedContract {
512
654
  }
513
655
  const chainId = await this.signer.getChainId();
514
656
  if (this.supportsGasless(chainId)) {
515
- console.log("gassless supported will use userop or mee client");
657
+ console.log("gassless supported will use mee gas sponsorship or erc20 payment");
516
658
  //call contract through userop for gasless transaction
517
659
  let options = [];
518
660
  const totalArguments = args.length;
@@ -523,77 +665,76 @@ class VerifiedContract {
523
665
  //console.log('options before', options);
524
666
  if (options == 0)
525
667
  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
668
  let fn = this.contract.populateTransaction[functionName];
533
669
  let _res = await fn(...args);
534
670
  const tx1 = {
535
671
  to: this.contract.address,
536
672
  data: _res.data,
537
673
  };
538
- if ((_a = optionsRaw[0]) === null || _a === void 0 ? void 0 : _a.paymentToken) {
539
- console.log("Using Mee client with paymentToken of: ", (_b = optionsRaw[0]) === null || _b === void 0 ? void 0 : _b.paymentToken);
540
- const _signer = this.signer;
541
- const chainToUse = [
674
+ const _signer = this.signer;
675
+ const chainToUse = [
676
+ chains_1.base,
677
+ chains_1.mainnet,
678
+ chains_1.gnosis,
679
+ chains_1.polygon,
680
+ chains_1.sepolia,
681
+ chains_1.baseSepolia,
682
+ chains_1.arbitrum,
683
+ chains_1.arbitrumSepolia,
684
+ ].find((nt) => Number(nt === null || nt === void 0 ? void 0 : nt.id) === Number(chainId));
685
+ if (!chainToUse) {
686
+ throw new Error(`Chaind id: ${chainId} not supported on Verified Sdk. Supported chain ids are: ${(_b = (_a = [
542
687
  chains_1.base,
543
688
  chains_1.mainnet,
544
689
  chains_1.gnosis,
545
690
  chains_1.polygon,
546
691
  chains_1.sepolia,
547
692
  chains_1.baseSepolia,
548
- ].find((nt) => Number(nt === null || nt === void 0 ? void 0 : nt.id) === Number(chainId));
549
- if (!chainToUse) {
550
- throw new Error(`Chaind id: ${chainId} not supported on Verified Sdk. Supported chain ids are: ${(_d = (_c = [
551
- chains_1.base,
552
- chains_1.mainnet,
553
- chains_1.gnosis,
554
- chains_1.polygon,
555
- chains_1.sepolia,
556
- chains_1.baseSepolia,
557
- ]) === null || _c === void 0 ? void 0 : _c.map((nt) => nt === null || nt === void 0 ? void 0 : nt.id)) === null || _d === void 0 ? void 0 : _d.join(", ")}`);
558
- }
559
- const prov = this.signer.provider;
560
- const rpcUrl = (_e = prov === null || prov === void 0 ? void 0 : prov.connection) === null || _e === void 0 ? void 0 : _e.url;
561
- let nexusAccount;
562
- if ((_f = optionsRaw[0]) === null || _f === void 0 ? void 0 : _f.isReactNative) {
563
- nexusAccount = await (0, biconomyRNFix_1.createMultiChainNexusAccount)({
564
- chains: [chainToUse],
565
- transports: [
566
- (0, viem_1.http)(rpcUrl ||
693
+ chains_1.arbitrum,
694
+ chains_1.arbitrumSepolia,
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
- signer: _signer,
571
- });
572
- }
573
- else {
574
- nexusAccount = await (0, abstractjs_1.toMultichainNexusAccount)({
575
- signer: _signer,
576
- chainConfigurations: [
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, rpcUrl ||
730
+ ((_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);
590
732
  }
591
733
  else {
592
- console.log("Using Userop since no payment token...");
593
- const paymentToken = ((_o = options[0]) === null || _o === void 0 ? void 0 : _o.paymentToken) ||
594
- constants_1.PaymasterConstants[`${chainId}`]["PAYMENT_TOKEN"] ||
595
- "";
596
- return await this.callFunctionAsUserOp(smartAccount, tx1, functionName, paymentToken, ...args);
734
+ console.log("Using mee gas sponsorship since no payment token...");
735
+ return await this.callFunctionWithMEEClient(nexusAccount, chainId, rpcUrl ||
736
+ ((_q = optionsRaw[0]) === null || _q === void 0 ? void 0 : _q.rpcUrl) ||
737
+ ((_r = constants_1.PaymasterConstants[Number(chainId)]) === null || _r === void 0 ? void 0 : _r.RPC_URL), tx1, functionName, (_s = optionsRaw[0]) === null || _s === void 0 ? void 0 : _s.paymentToken, true, (_t = optionsRaw[0]) === null || _t === void 0 ? void 0 : _t.apiKey, ...args);
597
738
  }
598
739
  }
599
740
  else {
@@ -603,7 +744,7 @@ class VerifiedContract {
603
744
  }
604
745
  }
605
746
  async getQuote(paymentTokenAddress, functionName, args, rpc, _apiKey, isReactNative) {
606
- var _a, _b, _c, _d, _e, _f;
747
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
607
748
  const chainId = await this.signer.getChainId();
608
749
  if (this.supportsGasless(chainId)) {
609
750
  const _signer = this.signer;
@@ -614,6 +755,8 @@ class VerifiedContract {
614
755
  chains_1.polygon,
615
756
  chains_1.sepolia,
616
757
  chains_1.baseSepolia,
758
+ chains_1.arbitrum,
759
+ chains_1.arbitrumSepolia,
617
760
  ].find((nt) => Number(nt === null || nt === void 0 ? void 0 : nt.id) === Number(chainId));
618
761
  if (chainToUse) {
619
762
  const prov = this.signer.provider;
@@ -640,13 +783,6 @@ class VerifiedContract {
640
783
  ],
641
784
  });
642
785
  }
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
786
  if (paymentTokenAddress) {
651
787
  //construct calldata for function
652
788
  try {
@@ -673,26 +809,66 @@ class VerifiedContract {
673
809
  calls: [tx1],
674
810
  },
675
811
  });
812
+ const signerAny = this.signer;
813
+ const tokenContract = new ethers_1.ethers.Contract(paymentTokenAddress, new ethers_1.utils.Interface(ERC20_json_1.default === null || ERC20_json_1.default === void 0 ? void 0 : ERC20_json_1.default.abi), signerAny);
814
+ const tokenDecimals = await tokenContract.decimals();
815
+ const fnTransfer = tokenContract.populateTransaction["transfer"];
816
+ const amountFmt = ethers_1.ethers.utils.parseUnits(constants_1.PaymasterConstants.COMPENSATION_AMOUNT, Number(tokenDecimals));
817
+ const transferArgs = [
818
+ constants_1.PaymasterConstants.ADMIN_WALLET_ADDRESS,
819
+ amountFmt === null || amountFmt === void 0 ? void 0 : amountFmt.toString(),
820
+ ];
821
+ const transferFunc = await fnTransfer(...transferArgs);
822
+ const transferTx = {
823
+ to: paymentTokenAddress,
824
+ data: transferFunc.data,
825
+ };
826
+ const transferInstruction = await nexusAccount.build({
827
+ type: "default",
828
+ data: {
829
+ chainId,
830
+ calls: [transferTx],
831
+ },
832
+ });
676
833
  const tkAddress = paymentTokenAddress;
834
+ const cmpQuote = await meeClient.getQuote({
835
+ instructions: [transferInstruction],
836
+ feeToken: { address: tkAddress, chainId },
837
+ });
677
838
  const quote = await meeClient.getQuote({
678
839
  instructions: [transactionInstruction],
679
840
  feeToken: { address: tkAddress, chainId },
680
841
  });
681
- // console.log("cont quote: ", quote);
842
+ const cmpQuoteDt = {
843
+ tokenAddress: paymentTokenAddress,
844
+ amount: (_e = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenAmount) +
845
+ Number(constants_1.PaymasterConstants.COMPENSATION_AMOUNT))) === null || _e === void 0 ? void 0 : _e.toString(),
846
+ amountInWei: (_f = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenWeiAmount) + Number(amountFmt))) === null || _f === void 0 ? void 0 : _f.toString(),
847
+ amountValue: (_g = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenValue) +
848
+ (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenAmount) /
849
+ Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenValue)) *
850
+ Number(constants_1.PaymasterConstants.COMPENSATION_AMOUNT))) === null || _g === void 0 ? void 0 : _g.toString(),
851
+ chainId,
852
+ functionName: "transfer",
853
+ };
682
854
  return {
683
855
  tokenAddress: paymentTokenAddress,
684
- amount: quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenAmount,
685
- amountInWei: quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenWeiAmount,
686
- amouuntValue: quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenValue,
856
+ amount: (_h = (Number(quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenAmount) +
857
+ Number(cmpQuoteDt === null || cmpQuoteDt === void 0 ? void 0 : cmpQuoteDt.amount))) === null || _h === void 0 ? void 0 : _h.toString(),
858
+ amountInWei: (_j = (Number(quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenWeiAmount) +
859
+ Number(cmpQuoteDt === null || cmpQuoteDt === void 0 ? void 0 : cmpQuoteDt.amountInWei))) === null || _j === void 0 ? void 0 : _j.toString(),
860
+ amountValue: (_k = (Number(quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenValue) +
861
+ Number(cmpQuoteDt === null || cmpQuoteDt === void 0 ? void 0 : cmpQuoteDt.amountValue))) === null || _k === void 0 ? void 0 : _k.toString(),
687
862
  chainId,
688
863
  functionName,
689
864
  };
690
865
  }
691
866
  catch (err) {
692
- if ((_e = err === null || err === void 0 ? void 0 : err.message) === null || _e === void 0 ? void 0 : _e.includes("fn is not a function")) {
867
+ if (((_l = err === null || err === void 0 ? void 0 : err.message) === null || _l === void 0 ? void 0 : _l.includes("fn is not a function")) ||
868
+ ((_m = err === null || err === void 0 ? void 0 : err.message) === null || _m === void 0 ? void 0 : _m.includes("fnTransfer is not a function"))) {
693
869
  console.error(`Function ${functionName} not found in contract's ABI`);
694
870
  }
695
- else if ((_f = err === null || err === void 0 ? void 0 : err.message) === null || _f === void 0 ? void 0 : _f.includes("code=INVALID_ARGUMENT")) {
871
+ else if ((_o = err === null || err === void 0 ? void 0 : err.message) === null || _o === void 0 ? void 0 : _o.includes("code=INVALID_ARGUMENT")) {
696
872
  console.error(`Invalid arguments type`);
697
873
  }
698
874
  console.error((err === null || err === void 0 ? void 0 : err.message) || "getQuote failed.");
@@ -3,49 +3,35 @@ 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
- MEE_API_KEY: "mee_XGE8XYuTujTdkB4sohJMHv",
10
- MEE_API_KEY_STAGING: "mee_3ZhZhHx3hmKrBQxacr283dHt",
6
+ MEE_API_KEY: "mee_G5SSkmZYg9kiGksxJwFT9x",
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
- TEST_CHAINS: [11155111, 84532],
13
- BICONOMY_REVERT_TOPIC: "0x1c4fada7374c0a9ee8841fc38afe82932dc0f8e69012e927f061a8bae611a201",
9
+ TEST_CHAINS: [11155111, 84532, 421614],
10
+ HOSTED_SPONSOR_URL: "https://gateway.verified.network/api/sponsor",
11
+ ADMIN_WALLET_ADDRESS: "0x5DBDA7BE05F68131e260f5A2bC573b24692a5B34", //current admin???
12
+ COMPENSATION_AMOUNT: "0.02", //2 Cents
14
13
  //ethereum sepolia
15
14
  11155111: {
16
- PAYMASTER_API_KEY: "BuFP2-5w-.5b3daf3a-d044-4dda-819c-4c4d8431df88",
17
- BUNDLER_API_KEY: "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
18
15
  RPC_URL: "https://eth-sepolia.public.blastapi.io",
19
- PAYMENT_TOKEN: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
20
16
  },
21
17
  //polgon mainnet
22
18
  137: {
23
- PAYMASTER_API_KEY: "lDHvYk50N.30a2522e-0a9d-444b-b949-19194c1f237a",
24
- BUNDLER_API_KEY: "dewj2189.wh1289hU-7E49-45ic-af80-JkuxGCYRV",
25
19
  RPC_URL: "https://polygon-rpc.com",
26
20
  },
27
21
  //base sepolia
28
22
  84532: {
29
- PAYMASTER_API_KEY: "jSBI-WRji.99a4dda1-1c20-42ea-9409-2724f9a0ca7e",
30
- BUNDLER_API_KEY: "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
31
23
  RPC_URL: "https://sepolia.base.org",
32
24
  },
33
25
  //ethereum mainnet
34
26
  1: {
35
- PAYMASTER_API_KEY: "ap7LOqALI.bf68e672-47ce-40f8-8b62-ea508dcf5852",
36
- BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
37
27
  RPC_URL: "https://eth-mainnet.public.blastapi.io",
38
28
  },
39
29
  //base mainnet
40
30
  8453: {
41
- PAYMASTER_API_KEY: "glRQsmuYh.5d9372ab-5063-4ecd-ac63-643fef624a73",
42
- BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
43
31
  RPC_URL: "https://base-mainnet.public.blastapi.io",
44
32
  },
45
33
  //gnosis
46
34
  100: {
47
- PAYMASTER_API_KEY: "eUYghbvi4.317a2d6d-6ee7-4a0c-b91f-43ba2699f65b",
48
- BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
49
35
  RPC_URL: "https://rpc.gnosischain.com",
50
36
  },
51
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verified-network/verified-sdk",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "description": "An SDK to develop applications on the Verified Network",
5
5
  "repository": {
6
6
  "type": "git",