@verified-network/verified-sdk 2.7.6 → 2.7.8
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/abi/payments/Rates.json +121 -0
- package/dist/contract/index.d.ts +7 -13
- package/dist/contract/index.js +84 -513
- package/dist/contract/rates/index.d.ts +2 -0
- package/dist/contract/rates/index.js +9 -0
- package/dist/contractAddress/index.js +19 -19
- package/dist/lib/biconomyRNFix.d.ts +18 -18
- package/dist/lib/biconomyRNFix.js +104 -80
- package/dist/utils/constants.js +1 -6
- package/package.json +2 -5
- package/tsconfig.json +3 -3
package/dist/contract/index.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
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
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
4
|
exports.VerifiedContract = exports.DATATYPES = void 0;
|
|
8
5
|
const ethers_1 = require("ethers");
|
|
9
|
-
const account_1 = require("@biconomy/account");
|
|
10
6
|
const constants_1 = require("../utils/constants");
|
|
11
|
-
const abstractjs_1 = require("@biconomy/abstractjs");
|
|
12
7
|
const chains_1 = require("viem/chains");
|
|
13
|
-
const viem_1 = require("viem");
|
|
14
|
-
const biconomyRNFix_1 = require("../lib/biconomyRNFix");
|
|
15
|
-
const ERC20_json_1 = __importDefault(require("../abi/payments/ERC20.json"));
|
|
16
8
|
var STATUS;
|
|
17
9
|
(function (STATUS) {
|
|
18
10
|
STATUS[STATUS["SUCCESS"] = 0] = "SUCCESS";
|
|
@@ -32,7 +24,6 @@ class VerifiedContract {
|
|
|
32
24
|
constructor(address, abi, signer) {
|
|
33
25
|
this.signer = signer;
|
|
34
26
|
this.abiInterface = new ethers_1.utils.Interface(abi);
|
|
35
|
-
this.abiRaw = JSON.parse(abi);
|
|
36
27
|
this.contract = new ethers_1.ethers.Contract(address, this.abiInterface, signer);
|
|
37
28
|
}
|
|
38
29
|
async validateInput(type, data) {
|
|
@@ -195,51 +186,8 @@ class VerifiedContract {
|
|
|
195
186
|
}
|
|
196
187
|
/** Checks if a contract support gasless transaction */
|
|
197
188
|
supportsGasless(chainId) {
|
|
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
189
|
return true;
|
|
206
190
|
}
|
|
207
|
-
/** Creates Biconomy smart account */
|
|
208
|
-
async createSmartAccount(chainId) {
|
|
209
|
-
// Create Biconomy Smart Account instance
|
|
210
|
-
const signer = this.signer;
|
|
211
|
-
const smartAccount = await (0, account_1.createSmartAccountClient)({
|
|
212
|
-
signer,
|
|
213
|
-
biconomyPaymasterApiKey: constants_1.PaymasterConstants[`${chainId}`]["PAYMASTER_API_KEY"],
|
|
214
|
-
bundlerUrl: `${constants_1.PaymasterConstants.BUNDLER_URL_FIRST_SECTION}/${chainId}/${constants_1.PaymasterConstants[`${chainId}`]["BUNDLER_API_KEY"]}`,
|
|
215
|
-
});
|
|
216
|
-
return smartAccount;
|
|
217
|
-
}
|
|
218
|
-
async fetchUserOpReceipt(userOpHash) {
|
|
219
|
-
var _a;
|
|
220
|
-
try {
|
|
221
|
-
const chainId = await this.signer.getChainId();
|
|
222
|
-
const requestData = {
|
|
223
|
-
jsonrpc: "2.0",
|
|
224
|
-
method: "eth_getUserOperationReceipt",
|
|
225
|
-
id: Date.now(),
|
|
226
|
-
params: [userOpHash],
|
|
227
|
-
};
|
|
228
|
-
const response = await fetch(`${constants_1.PaymasterConstants.BUNDLER_URL_FIRST_SECTION}/${chainId}/${constants_1.PaymasterConstants[`${chainId}`]["BUNDLER_API_KEY"]}`, {
|
|
229
|
-
method: "POST",
|
|
230
|
-
headers: {
|
|
231
|
-
"Content-Type": "application/json",
|
|
232
|
-
},
|
|
233
|
-
body: JSON.stringify(requestData),
|
|
234
|
-
});
|
|
235
|
-
const data = await response.json();
|
|
236
|
-
return (_a = data === null || data === void 0 ? void 0 : data.result) === null || _a === void 0 ? void 0 : _a.receipt;
|
|
237
|
-
}
|
|
238
|
-
catch (err) {
|
|
239
|
-
console.error("Error trying to fetch gassless receipt", (err === null || err === void 0 ? void 0 : err.message) || err);
|
|
240
|
-
return { failed: true };
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
191
|
/** Constructs and call function with ethers.js */
|
|
244
192
|
async callFunctionWithEthers(functionName, ...args) {
|
|
245
193
|
let res = {};
|
|
@@ -248,11 +196,8 @@ class VerifiedContract {
|
|
|
248
196
|
const totalArguments = args.length;
|
|
249
197
|
if (totalArguments > 1)
|
|
250
198
|
options = args.splice(-1);
|
|
251
|
-
//console.log('options before', options);
|
|
252
199
|
if (options == 0)
|
|
253
200
|
options[0] = {};
|
|
254
|
-
//console.log('*********', ...args)
|
|
255
|
-
//console.log('options after', options);
|
|
256
201
|
/**
|
|
257
202
|
* Actual Function call using Ethers.js
|
|
258
203
|
*/
|
|
@@ -273,187 +218,25 @@ class VerifiedContract {
|
|
|
273
218
|
return res;
|
|
274
219
|
}
|
|
275
220
|
}
|
|
276
|
-
/** Constructs and call function
|
|
277
|
-
async
|
|
278
|
-
var _a, _b, _c;
|
|
279
|
-
//send userops transaction and construct transaction response
|
|
280
|
-
let res = {};
|
|
281
|
-
try {
|
|
282
|
-
const userOpResponse = await smartAccount.sendTransaction(tx, {
|
|
283
|
-
paymasterServiceData: { mode: "SPONSORED" },
|
|
284
|
-
});
|
|
285
|
-
const { transactionHash } = await userOpResponse.waitForTxHash();
|
|
286
|
-
console.log("Gassless Transaction Hash", transactionHash);
|
|
287
|
-
const userOpReceipt = await userOpResponse.wait();
|
|
288
|
-
if (userOpReceipt.success == "true") {
|
|
289
|
-
res.status = STATUS.SUCCESS;
|
|
290
|
-
res.response = {
|
|
291
|
-
hash: (userOpReceipt === null || userOpReceipt === void 0 ? void 0 : userOpReceipt.transactionHash) || transactionHash,
|
|
292
|
-
result: userOpReceipt.receipt.result ||
|
|
293
|
-
userOpReceipt.receipt.response ||
|
|
294
|
-
userOpReceipt.receipt,
|
|
295
|
-
}; //TODO: update result on response
|
|
296
|
-
res.message = "";
|
|
297
|
-
return res;
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
console.log("Gassless failed will try ERC20...");
|
|
301
|
-
const ERC20userOpResponse = await smartAccount.sendTransaction(tx, {
|
|
302
|
-
paymasterServiceData: { mode: "ERC20", preferredToken: paymentToken },
|
|
303
|
-
});
|
|
304
|
-
const { ERC20transactionHash } = await ERC20userOpResponse.waitForTxHash();
|
|
305
|
-
console.log("ERC20 Transaction Hash", ERC20transactionHash);
|
|
306
|
-
const userOpReceipt = await ERC20userOpResponse.wait();
|
|
307
|
-
if (userOpReceipt.success == "true") {
|
|
308
|
-
res.status = STATUS.SUCCESS;
|
|
309
|
-
res.response = {
|
|
310
|
-
hash: (userOpReceipt === null || userOpReceipt === void 0 ? void 0 : userOpReceipt.transactionHash) || ERC20transactionHash,
|
|
311
|
-
result: ERC20userOpResponse.receipt.result ||
|
|
312
|
-
ERC20userOpResponse.receipt.response ||
|
|
313
|
-
ERC20userOpResponse.receipt,
|
|
314
|
-
}; //TODO: update result on response
|
|
315
|
-
res.message = "";
|
|
316
|
-
return res;
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
console.error("ERC20 failed");
|
|
320
|
-
console.log("will use ethers....");
|
|
321
|
-
return await this.callFunctionWithEthers(functionName, ...args);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
catch (err) {
|
|
326
|
-
if ((_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.includes("Try getting the receipt manually using eth_getUserOperationReceipt rpc method on bundler")) {
|
|
327
|
-
//extract hash from message due to difference in hash???
|
|
328
|
-
const messageArray = (_b = err === null || err === void 0 ? void 0 : err.message) === null || _b === void 0 ? void 0 : _b.split(" ");
|
|
329
|
-
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(".", "");
|
|
330
|
-
//wait up to max round to fetch receipt ???
|
|
331
|
-
if (txHash) {
|
|
332
|
-
for (let i = 0; i < Number(constants_1.PaymasterConstants.MAX_WAITING_ROUND); i++) {
|
|
333
|
-
await new Promise((resolve) => setTimeout(resolve, 6000)); // 6 second delay
|
|
334
|
-
console.log("Gassless timeout exceeded, fetching receipt for round:", i + 1, "out of", Number(constants_1.PaymasterConstants.MAX_WAITING_ROUND));
|
|
335
|
-
const _res = await this.fetchUserOpReceipt(txHash);
|
|
336
|
-
if (_res && !(_res === null || _res === void 0 ? void 0 : _res.failed) && (_res === null || _res === void 0 ? void 0 : _res.status) === "0x1") {
|
|
337
|
-
res.status = STATUS.SUCCESS;
|
|
338
|
-
res.response = {
|
|
339
|
-
hash: (_res === null || _res === void 0 ? void 0 : _res.transactionHash) || txHash,
|
|
340
|
-
result: _res,
|
|
341
|
-
};
|
|
342
|
-
res.message = "";
|
|
343
|
-
break; // Exit the loop
|
|
344
|
-
}
|
|
345
|
-
else if (_res && !(_res === null || _res === void 0 ? void 0 : _res.failed) && (_res === null || _res === void 0 ? void 0 : _res.status) !== "0x1") {
|
|
346
|
-
res.status = STATUS.ERROR;
|
|
347
|
-
res.response = {
|
|
348
|
-
hash: (_res === null || _res === void 0 ? void 0 : _res.transactionHash) || txHash,
|
|
349
|
-
result: _res,
|
|
350
|
-
};
|
|
351
|
-
res.message = (_res === null || _res === void 0 ? void 0 : _res.reason) || (_res === null || _res === void 0 ? void 0 : _res.message) || "";
|
|
352
|
-
break; // Exit the loop
|
|
353
|
-
}
|
|
354
|
-
else if (_res && (_res === null || _res === void 0 ? void 0 : _res.failed)) {
|
|
355
|
-
console.log("will use ethers....");
|
|
356
|
-
return await this.callFunctionWithEthers(functionName, ...args);
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
//no receipt found?? don't call with ethers transaction may get mined???
|
|
360
|
-
res.status = STATUS.ERROR; //create additional status to mark this???
|
|
361
|
-
res.response = {
|
|
362
|
-
hash: txHash,
|
|
363
|
-
result: [],
|
|
364
|
-
};
|
|
365
|
-
res.message = "Transaction Pending.";
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
return res;
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
console.error("gasless transaction failed with error: ", "No TX-hash from error message.");
|
|
372
|
-
console.log("will use ethers....");
|
|
373
|
-
return await this.callFunctionWithEthers(functionName, ...args);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
console.error("gasless transaction failed with error: ", (err === null || err === void 0 ? void 0 : err.message) || err);
|
|
378
|
-
console.log("will use ethers....");
|
|
379
|
-
return await this.callFunctionWithEthers(functionName, ...args);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
/** Constructs and call function using MEE client that allows gas payment in ERC20 tokens */
|
|
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;
|
|
221
|
+
/** Constructs and call function using Alchemy client that allows gassless sponsorship and payment in ERC20 tokens */
|
|
222
|
+
async callFunctionWithAlchemyClient(chainId, tx, functionName, paymentToken, pk, isSponsor, ...args) {
|
|
386
223
|
let res = {};
|
|
387
224
|
let txHash = "";
|
|
388
|
-
let recp;
|
|
389
225
|
try {
|
|
390
|
-
const meeClient = ((_a = constants_1.PaymasterConstants.TEST_CHAINS) === null || _a === void 0 ? void 0 : _a.includes(chainId))
|
|
391
|
-
? await (0, abstractjs_1.createMeeClient)({
|
|
392
|
-
account: nexusAccount,
|
|
393
|
-
url: constants_1.PaymasterConstants.MEE_URL_STAGING,
|
|
394
|
-
apiKey: constants_1.PaymasterConstants.MEE_API_KEY_STAGING,
|
|
395
|
-
})
|
|
396
|
-
: await (0, abstractjs_1.createMeeClient)({
|
|
397
|
-
account: nexusAccount,
|
|
398
|
-
apiKey: _apiKey || constants_1.PaymasterConstants.MEE_API_KEY,
|
|
399
|
-
});
|
|
400
|
-
const transactionInstruction = await nexusAccount.build({
|
|
401
|
-
type: "default",
|
|
402
|
-
data: {
|
|
403
|
-
chainId,
|
|
404
|
-
calls: [tx],
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
|
-
let transferInstruction, transferTx;
|
|
408
|
-
if (!isSponsor) {
|
|
409
|
-
const signerAny = this.signer;
|
|
410
|
-
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);
|
|
411
|
-
const tokenDecimals = await tokenContract.decimals();
|
|
412
|
-
const fn = tokenContract.populateTransaction["transfer"];
|
|
413
|
-
const amountFmt = ethers_1.ethers.utils.parseUnits(constants_1.PaymasterConstants.COMPENSATION_AMOUNT, Number(tokenDecimals));
|
|
414
|
-
const transferArgs = [
|
|
415
|
-
constants_1.PaymasterConstants.ADMIN_WALLET_ADDRESS,
|
|
416
|
-
amountFmt === null || amountFmt === void 0 ? void 0 : amountFmt.toString(),
|
|
417
|
-
];
|
|
418
|
-
const transferFunc = await fn(...transferArgs);
|
|
419
|
-
const _transferTx = {
|
|
420
|
-
to: paymentToken,
|
|
421
|
-
data: transferFunc.data,
|
|
422
|
-
};
|
|
423
|
-
transferTx = _transferTx;
|
|
424
|
-
transferInstruction = await nexusAccount.build({
|
|
425
|
-
type: "default",
|
|
426
|
-
data: {
|
|
427
|
-
chainId,
|
|
428
|
-
calls: [_transferTx],
|
|
429
|
-
},
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
const isTestnet = (_b = constants_1.PaymasterConstants.TEST_CHAINS) === null || _b === void 0 ? void 0 : _b.includes(chainId);
|
|
433
|
-
let sponsorInfo;
|
|
434
|
-
//Use constant gas tanks instead of fetching from server to reduce tx time???
|
|
435
|
-
if (isSponsor) {
|
|
436
|
-
const response = await fetch("https://network.biconomy.io/v1/sponsorship/info", { method: "GET" });
|
|
437
|
-
if (!response.ok) {
|
|
438
|
-
sponsorInfo = {};
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
sponsorInfo = await response.json();
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
226
|
const sponsorUrl = constants_1.PaymasterConstants.HOSTED_SPONSOR_URL;
|
|
445
|
-
let quote
|
|
227
|
+
let quote;
|
|
228
|
+
// Execute the transaction using passed paymentToken or sponsored gasless
|
|
446
229
|
if (isSponsor) {
|
|
447
|
-
const response = await fetch(`${sponsorUrl}/sponsorship/sign/${
|
|
230
|
+
const response = await fetch(`${sponsorUrl}/sponsorship/sign/${chainId?.toString()}`, {
|
|
448
231
|
method: "POST",
|
|
449
232
|
headers: {
|
|
450
|
-
"
|
|
451
|
-
"cnt-chainid": chainId === null || chainId === void 0 ? void 0 : chainId.toString(),
|
|
452
|
-
"cnt-rpc": rpc,
|
|
453
|
-
"cnt-isquote": "true",
|
|
454
|
-
"cnt-pk": signerPk,
|
|
233
|
+
"Content-Type": "application/json",
|
|
455
234
|
},
|
|
456
|
-
body:
|
|
235
|
+
body: JSON.stringify({
|
|
236
|
+
isSponsored: true,
|
|
237
|
+
pk,
|
|
238
|
+
tx,
|
|
239
|
+
}),
|
|
457
240
|
});
|
|
458
241
|
if (!response.ok) {
|
|
459
242
|
quote = null;
|
|
@@ -463,133 +246,32 @@ class VerifiedContract {
|
|
|
463
246
|
}
|
|
464
247
|
}
|
|
465
248
|
else {
|
|
466
|
-
|
|
467
|
-
instructions: [transferInstruction],
|
|
468
|
-
feeToken: { address: paymentToken, chainId },
|
|
469
|
-
simulation: {
|
|
470
|
-
simulate: true,
|
|
471
|
-
},
|
|
472
|
-
});
|
|
473
|
-
quote = await meeClient.getQuote({
|
|
474
|
-
instructions: [transactionInstruction],
|
|
475
|
-
feeToken: { address: paymentToken, chainId },
|
|
476
|
-
simulation: {
|
|
477
|
-
simulate: true,
|
|
478
|
-
},
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
const nowInSec = Math.floor(Date.now() / 1000);
|
|
482
|
-
const transactionInstructionFinal = await nexusAccount.build({
|
|
483
|
-
type: "default",
|
|
484
|
-
data: {
|
|
485
|
-
chainId,
|
|
486
|
-
calls: [
|
|
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 }),
|
|
488
|
-
],
|
|
489
|
-
},
|
|
490
|
-
});
|
|
491
|
-
let transferInstructionFinal;
|
|
492
|
-
if (!isSponsor) {
|
|
493
|
-
transferInstructionFinal = await nexusAccount.build({
|
|
494
|
-
type: "default",
|
|
495
|
-
data: {
|
|
496
|
-
chainId,
|
|
497
|
-
calls: [
|
|
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 }),
|
|
499
|
-
],
|
|
500
|
-
},
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
// Execute the transaction using passed paymentToken or gasless details
|
|
504
|
-
let _txHash;
|
|
505
|
-
if (isSponsor) {
|
|
506
|
-
let res;
|
|
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}`, {
|
|
249
|
+
const response = await fetch(`${sponsorUrl}/sponsorship/sign/${chainId?.toString()}`, {
|
|
508
250
|
method: "POST",
|
|
509
251
|
headers: {
|
|
510
|
-
"
|
|
511
|
-
"cnt-chainid": chainId === null || chainId === void 0 ? void 0 : chainId.toString(),
|
|
512
|
-
"cnt-rpc": rpc,
|
|
513
|
-
"cnt-isquote": "false",
|
|
514
|
-
"cnt-pk": signerPk,
|
|
252
|
+
"Content-Type": "application/json",
|
|
515
253
|
},
|
|
516
|
-
body:
|
|
254
|
+
body: JSON.stringify({
|
|
255
|
+
isSponsored: false,
|
|
256
|
+
paymentToken,
|
|
257
|
+
pk,
|
|
258
|
+
tx,
|
|
259
|
+
}),
|
|
517
260
|
});
|
|
518
261
|
if (!response.ok) {
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
else {
|
|
522
|
-
res = await response.json();
|
|
523
|
-
}
|
|
524
|
-
_txHash = res === null || res === void 0 ? void 0 : res.hash;
|
|
525
|
-
}
|
|
526
|
-
else {
|
|
527
|
-
//handle it seperately as batch kept failing???
|
|
528
|
-
const { hash: cmpHash } = await meeClient.execute({
|
|
529
|
-
feeToken: {
|
|
530
|
-
chainId,
|
|
531
|
-
address: paymentToken,
|
|
532
|
-
},
|
|
533
|
-
instructions: [transferInstructionFinal], //take conpensation first???
|
|
534
|
-
upperBoundTimestamp: nowInSec + 299, //highest is 5 minutes???
|
|
535
|
-
});
|
|
536
|
-
// console.log("Compensation tx MEE hash: ", cmpHash);
|
|
537
|
-
const cmpReceipt = await meeClient.waitForSupertransactionReceipt({
|
|
538
|
-
hash: cmpHash,
|
|
539
|
-
});
|
|
540
|
-
if (((_o = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts) === null || _o === void 0 ? void 0 : _o.length) > 0) {
|
|
541
|
-
//always pick last receipt????
|
|
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];
|
|
543
|
-
if ((txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.status) === "success") {
|
|
544
|
-
// console.log(
|
|
545
|
-
// "Compensation tx successful will move to regular transaction...",
|
|
546
|
-
// );
|
|
547
|
-
const { hash } = await meeClient.execute({
|
|
548
|
-
feeToken: {
|
|
549
|
-
chainId,
|
|
550
|
-
address: paymentToken,
|
|
551
|
-
},
|
|
552
|
-
instructions: [transactionInstructionFinal],
|
|
553
|
-
upperBoundTimestamp: nowInSec + 299, //highest is 5 minutes???
|
|
554
|
-
});
|
|
555
|
-
_txHash = hash;
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
res.status = STATUS.ERROR;
|
|
559
|
-
res.response = {
|
|
560
|
-
hash: txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.transactionHash,
|
|
561
|
-
result: txReceipt,
|
|
562
|
-
}; //TODO: update result on response
|
|
563
|
-
res.message = "";
|
|
564
|
-
return res;
|
|
565
|
-
}
|
|
262
|
+
quote = null;
|
|
566
263
|
}
|
|
567
264
|
else {
|
|
568
|
-
|
|
569
|
-
res.status = STATUS.ERROR;
|
|
570
|
-
res.response = {
|
|
571
|
-
hash: (_q = cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[0]) === null || _q === void 0 ? void 0 : _q.transactionHash,
|
|
572
|
-
result: cmpReceipt === null || cmpReceipt === void 0 ? void 0 : cmpReceipt.receipts[0],
|
|
573
|
-
}; //TODO: update result on response
|
|
574
|
-
res.message = "";
|
|
575
|
-
return res;
|
|
265
|
+
quote = await response.json();
|
|
576
266
|
}
|
|
577
267
|
}
|
|
578
|
-
|
|
579
|
-
console.log(`MEE transaction hash: ${_txHash}`);
|
|
580
|
-
// Wait for transaction to complete
|
|
581
|
-
const receipt = await meeClient.waitForSupertransactionReceipt({
|
|
582
|
-
hash: _txHash,
|
|
583
|
-
});
|
|
584
|
-
// console.log("receipts: ", receipt);
|
|
585
|
-
// console.log("receiptsss...: ", receipt?.receipts);
|
|
586
|
-
if (((_r = receipt === null || receipt === void 0 ? void 0 : receipt.receipts) === null || _r === void 0 ? void 0 : _r.length) > 0) {
|
|
268
|
+
if (quote && quote?.receipts?.length > 0) {
|
|
587
269
|
//always pick last receipt????
|
|
588
|
-
const txReceipt =
|
|
589
|
-
if (
|
|
270
|
+
const txReceipt = quote?.receipts[quote?.receipts?.length - 1];
|
|
271
|
+
if (txReceipt?.status === "success") {
|
|
590
272
|
res.status = STATUS.SUCCESS;
|
|
591
273
|
res.response = {
|
|
592
|
-
hash: txReceipt
|
|
274
|
+
hash: txReceipt?.transactionHash,
|
|
593
275
|
result: txReceipt,
|
|
594
276
|
}; //TODO: update result on response
|
|
595
277
|
res.message = "";
|
|
@@ -602,7 +284,7 @@ class VerifiedContract {
|
|
|
602
284
|
else {
|
|
603
285
|
res.status = STATUS.ERROR;
|
|
604
286
|
res.response = {
|
|
605
|
-
hash: txReceipt
|
|
287
|
+
hash: txReceipt?.transactionHash,
|
|
606
288
|
result: txReceipt,
|
|
607
289
|
}; //TODO: update result on response
|
|
608
290
|
res.message = "";
|
|
@@ -611,7 +293,7 @@ class VerifiedContract {
|
|
|
611
293
|
return res;
|
|
612
294
|
}
|
|
613
295
|
else {
|
|
614
|
-
console.error("
|
|
296
|
+
console.error("Gassless/ERC20 transaction failed with error: ", "Invalid receipts length");
|
|
615
297
|
if (isSponsor) {
|
|
616
298
|
console.log("Will use ethers...");
|
|
617
299
|
return await this.callFunctionWithEthers(functionName, ...args);
|
|
@@ -619,8 +301,8 @@ class VerifiedContract {
|
|
|
619
301
|
else {
|
|
620
302
|
res.status = STATUS.ERROR;
|
|
621
303
|
res.response = {
|
|
622
|
-
hash:
|
|
623
|
-
result:
|
|
304
|
+
hash: "",
|
|
305
|
+
result: {},
|
|
624
306
|
}; //TODO: update result on response
|
|
625
307
|
res.message = "";
|
|
626
308
|
return res;
|
|
@@ -628,8 +310,9 @@ class VerifiedContract {
|
|
|
628
310
|
}
|
|
629
311
|
}
|
|
630
312
|
catch (err) {
|
|
631
|
-
console.error("
|
|
313
|
+
console.error("Gassless/ERC20 payment transaction failed with error: ", err?.message);
|
|
632
314
|
if (isSponsor) {
|
|
315
|
+
//for sponsored transaction. Fallback to ethers
|
|
633
316
|
console.log("Will use ethers...");
|
|
634
317
|
return await this.callFunctionWithEthers(functionName, ...args);
|
|
635
318
|
}
|
|
@@ -645,15 +328,14 @@ class VerifiedContract {
|
|
|
645
328
|
}
|
|
646
329
|
}
|
|
647
330
|
async callContract(functionName, ...args) {
|
|
648
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
|
|
649
331
|
// Check if the function is a read function
|
|
650
332
|
if (this.isReadFunction(functionName)) {
|
|
651
|
-
console.log("read function will use ethers");
|
|
333
|
+
console.log("read function will use ethers...");
|
|
652
334
|
return await this.callFunctionWithEthers(functionName, ...args);
|
|
653
335
|
}
|
|
654
336
|
const chainId = await this.signer.getChainId();
|
|
655
337
|
if (this.supportsGasless(chainId)) {
|
|
656
|
-
console.log("gassless supported will use
|
|
338
|
+
console.log("gassless supported will use gassless sponsorship or erc20 payment");
|
|
657
339
|
//call contract through userop for gasless transaction
|
|
658
340
|
let options = [];
|
|
659
341
|
const totalArguments = args.length;
|
|
@@ -661,7 +343,6 @@ class VerifiedContract {
|
|
|
661
343
|
//reduce args to exclude options
|
|
662
344
|
if (totalArguments > 1)
|
|
663
345
|
options = optionsRaw;
|
|
664
|
-
//console.log('options before', options);
|
|
665
346
|
if (options == 0)
|
|
666
347
|
options[0] = {};
|
|
667
348
|
let fn = this.contract.populateTransaction[functionName];
|
|
@@ -670,7 +351,6 @@ class VerifiedContract {
|
|
|
670
351
|
to: this.contract.address,
|
|
671
352
|
data: _res.data,
|
|
672
353
|
};
|
|
673
|
-
const _signer = this.signer;
|
|
674
354
|
const chainToUse = [
|
|
675
355
|
chains_1.base,
|
|
676
356
|
chains_1.mainnet,
|
|
@@ -680,9 +360,9 @@ class VerifiedContract {
|
|
|
680
360
|
chains_1.baseSepolia,
|
|
681
361
|
chains_1.arbitrum,
|
|
682
362
|
chains_1.arbitrumSepolia,
|
|
683
|
-
].find((nt) => Number(nt
|
|
363
|
+
].find((nt) => Number(nt?.id) === Number(chainId));
|
|
684
364
|
if (!chainToUse) {
|
|
685
|
-
throw new Error(`Chaind id: ${chainId} not supported on Verified Sdk. Supported chain ids are: ${
|
|
365
|
+
throw new Error(`Chaind id: ${chainId} not supported on Verified Sdk. Supported chain ids are: ${[
|
|
686
366
|
chains_1.base,
|
|
687
367
|
chains_1.mainnet,
|
|
688
368
|
chains_1.gnosis,
|
|
@@ -691,70 +371,38 @@ class VerifiedContract {
|
|
|
691
371
|
chains_1.baseSepolia,
|
|
692
372
|
chains_1.arbitrum,
|
|
693
373
|
chains_1.arbitrumSepolia,
|
|
694
|
-
]
|
|
374
|
+
]
|
|
375
|
+
?.map((nt) => nt?.id)
|
|
376
|
+
?.join(", ")}`);
|
|
695
377
|
}
|
|
696
|
-
const
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
signer: _signer,
|
|
709
|
-
});
|
|
378
|
+
const signerAny = this.signer;
|
|
379
|
+
const signerPk = signerAny?._signingKey()?.privateKey;
|
|
380
|
+
if (!signerPk) {
|
|
381
|
+
//no pk on signer. Assume it's web wallets and use ethers
|
|
382
|
+
console.log("Signer incomplete, will use ethers");
|
|
383
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
384
|
+
}
|
|
385
|
+
else if (signerPk) {
|
|
386
|
+
//pk exists signer. try gassless/erc20 first then ethers if they failed
|
|
387
|
+
if (optionsRaw[0]?.paymentToken) {
|
|
388
|
+
console.log("Using ERC20 payment with paymentToken of: ", optionsRaw[0]?.paymentToken);
|
|
389
|
+
return await this.callFunctionWithAlchemyClient(chainId, tx1, functionName, optionsRaw[0]?.paymentToken, signerPk, undefined, ...args);
|
|
710
390
|
}
|
|
711
391
|
else {
|
|
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
|
-
});
|
|
392
|
+
console.log("Using gassless sponsorship since no payment token");
|
|
393
|
+
return await this.callFunctionWithAlchemyClient(chainId, tx1, functionName, "0x", signerPk, true, ...args);
|
|
724
394
|
}
|
|
725
|
-
// const meeAddress = nexusAccount.addressOn(chainId);
|
|
726
|
-
}
|
|
727
|
-
catch (err) {
|
|
728
|
-
console.log("Gas sponsorship failed will use ethers...");
|
|
729
|
-
return await this.callFunctionWithEthers(functionName, ...args);
|
|
730
|
-
}
|
|
731
|
-
if ((_j = optionsRaw[0]) === null || _j === void 0 ? void 0 : _j.paymentToken) {
|
|
732
|
-
console.log("Using Mee erc20 payment with paymentToken of: ", (_k = optionsRaw[0]) === null || _k === void 0 ? void 0 : _k.paymentToken);
|
|
733
|
-
// console.log("nexus account address: ", meeAddress);
|
|
734
|
-
return await this.callFunctionWithMEEClient(nexusAccount, chainId, rpcUrl ||
|
|
735
|
-
((_l = optionsRaw[0]) === null || _l === void 0 ? void 0 : _l.rpcUrl) ||
|
|
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);
|
|
737
|
-
}
|
|
738
|
-
else {
|
|
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;
|
|
742
|
-
return await this.callFunctionWithMEEClient(nexusAccount, chainId, rpcUrl ||
|
|
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);
|
|
745
395
|
}
|
|
746
396
|
}
|
|
747
397
|
else {
|
|
748
398
|
//call contract through normal ether.js
|
|
749
|
-
console.log("
|
|
399
|
+
console.log("Gassless not supported for this chain will use ethers");
|
|
750
400
|
return await this.callFunctionWithEthers(functionName, ...args);
|
|
751
401
|
}
|
|
752
402
|
}
|
|
753
403
|
async getQuote(paymentTokenAddress, functionName, args, rpc, _apiKey, isReactNative) {
|
|
754
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
755
404
|
const chainId = await this.signer.getChainId();
|
|
756
405
|
if (this.supportsGasless(chainId)) {
|
|
757
|
-
const _signer = this.signer;
|
|
758
406
|
const chainToUse = [
|
|
759
407
|
chains_1.base,
|
|
760
408
|
chains_1.mainnet,
|
|
@@ -764,122 +412,45 @@ class VerifiedContract {
|
|
|
764
412
|
chains_1.baseSepolia,
|
|
765
413
|
chains_1.arbitrum,
|
|
766
414
|
chains_1.arbitrumSepolia,
|
|
767
|
-
].find((nt) => Number(nt
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
})
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
chainConfigurations: [
|
|
785
|
-
{
|
|
786
|
-
chain: chainToUse,
|
|
787
|
-
transport: (0, viem_1.http)(rpcUrl || rpc || ((_c = constants_1.PaymasterConstants[Number(chainId)]) === null || _c === void 0 ? void 0 : _c.RPC_URL)),
|
|
788
|
-
version: (0, abstractjs_1.getMEEVersion)(abstractjs_1.MEEVersion.V2_1_0),
|
|
789
|
-
},
|
|
790
|
-
],
|
|
415
|
+
].find((nt) => Number(nt?.id) === Number(chainId));
|
|
416
|
+
const signerAny = this.signer;
|
|
417
|
+
const signerPk = signerAny?._signingKey()?.privateKey;
|
|
418
|
+
if (chainToUse && paymentTokenAddress && signerPk) {
|
|
419
|
+
try {
|
|
420
|
+
let fn = this.contract.populateTransaction[functionName];
|
|
421
|
+
let _res = await fn(...args);
|
|
422
|
+
const tx1 = {
|
|
423
|
+
to: this.contract.address,
|
|
424
|
+
data: _res.data,
|
|
425
|
+
};
|
|
426
|
+
const sponsorUrl = constants_1.PaymasterConstants.HOSTED_SPONSOR_URL;
|
|
427
|
+
const response = await fetch(`${sponsorUrl}/sponsorship/fee/${chainId?.toString()}?paymentToken=${paymentTokenAddress}&pk=${signerPk}&tx=${JSON.stringify(tx1)}`, {
|
|
428
|
+
method: "GET",
|
|
429
|
+
headers: {
|
|
430
|
+
"Content-Type": "application/json",
|
|
431
|
+
},
|
|
791
432
|
});
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
//construct calldata for function
|
|
795
|
-
try {
|
|
796
|
-
let fn = this.contract.populateTransaction[functionName];
|
|
797
|
-
let _res = await fn(...args);
|
|
798
|
-
const tx1 = {
|
|
799
|
-
to: this.contract.address,
|
|
800
|
-
data: _res.data,
|
|
801
|
-
};
|
|
802
|
-
const meeClient = ((_d = constants_1.PaymasterConstants.TEST_CHAINS) === null || _d === void 0 ? void 0 : _d.includes(chainId))
|
|
803
|
-
? await (0, abstractjs_1.createMeeClient)({
|
|
804
|
-
account: nexusAccount,
|
|
805
|
-
url: constants_1.PaymasterConstants.MEE_URL_STAGING,
|
|
806
|
-
apiKey: constants_1.PaymasterConstants.MEE_API_KEY_STAGING,
|
|
807
|
-
})
|
|
808
|
-
: await (0, abstractjs_1.createMeeClient)({
|
|
809
|
-
account: nexusAccount,
|
|
810
|
-
apiKey: _apiKey || constants_1.PaymasterConstants.MEE_API_KEY,
|
|
811
|
-
});
|
|
812
|
-
const transactionInstruction = await nexusAccount.build({
|
|
813
|
-
type: "default",
|
|
814
|
-
data: {
|
|
815
|
-
chainId,
|
|
816
|
-
calls: [tx1],
|
|
817
|
-
},
|
|
818
|
-
});
|
|
819
|
-
const signerAny = this.signer;
|
|
820
|
-
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);
|
|
821
|
-
const tokenDecimals = await tokenContract.decimals();
|
|
822
|
-
const fnTransfer = tokenContract.populateTransaction["transfer"];
|
|
823
|
-
const amountFmt = ethers_1.ethers.utils.parseUnits(constants_1.PaymasterConstants.COMPENSATION_AMOUNT, Number(tokenDecimals));
|
|
824
|
-
const transferArgs = [
|
|
825
|
-
constants_1.PaymasterConstants.ADMIN_WALLET_ADDRESS,
|
|
826
|
-
amountFmt === null || amountFmt === void 0 ? void 0 : amountFmt.toString(),
|
|
827
|
-
];
|
|
828
|
-
const transferFunc = await fnTransfer(...transferArgs);
|
|
829
|
-
const transferTx = {
|
|
830
|
-
to: paymentTokenAddress,
|
|
831
|
-
data: transferFunc.data,
|
|
832
|
-
};
|
|
833
|
-
const transferInstruction = await nexusAccount.build({
|
|
834
|
-
type: "default",
|
|
835
|
-
data: {
|
|
836
|
-
chainId,
|
|
837
|
-
calls: [transferTx],
|
|
838
|
-
},
|
|
839
|
-
});
|
|
840
|
-
const tkAddress = paymentTokenAddress;
|
|
841
|
-
const cmpQuote = await meeClient.getQuote({
|
|
842
|
-
instructions: [transferInstruction],
|
|
843
|
-
feeToken: { address: tkAddress, chainId },
|
|
844
|
-
});
|
|
845
|
-
const quote = await meeClient.getQuote({
|
|
846
|
-
instructions: [transactionInstruction],
|
|
847
|
-
feeToken: { address: tkAddress, chainId },
|
|
848
|
-
});
|
|
849
|
-
const cmpQuoteDt = {
|
|
850
|
-
tokenAddress: paymentTokenAddress,
|
|
851
|
-
amount: (_e = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenAmount) +
|
|
852
|
-
Number(constants_1.PaymasterConstants.COMPENSATION_AMOUNT))) === null || _e === void 0 ? void 0 : _e.toString(),
|
|
853
|
-
amountInWei: (_f = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenWeiAmount) + Number(amountFmt))) === null || _f === void 0 ? void 0 : _f.toString(),
|
|
854
|
-
amountValue: (_g = (Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenValue) +
|
|
855
|
-
(Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenAmount) /
|
|
856
|
-
Number(cmpQuote === null || cmpQuote === void 0 ? void 0 : cmpQuote.paymentInfo.tokenValue)) *
|
|
857
|
-
Number(constants_1.PaymasterConstants.COMPENSATION_AMOUNT))) === null || _g === void 0 ? void 0 : _g.toString(),
|
|
858
|
-
chainId,
|
|
859
|
-
functionName: "transfer",
|
|
860
|
-
};
|
|
433
|
+
if (response.ok) {
|
|
434
|
+
const feeRes = (await response.json()) || { maxAmount: "0" };
|
|
861
435
|
return {
|
|
862
436
|
tokenAddress: paymentTokenAddress,
|
|
863
|
-
amount:
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
Number(cmpQuoteDt === null || cmpQuoteDt === void 0 ? void 0 : cmpQuoteDt.amountInWei))) === null || _j === void 0 ? void 0 : _j.toString(),
|
|
867
|
-
amountValue: (_k = (Number(quote === null || quote === void 0 ? void 0 : quote.paymentInfo.tokenValue) +
|
|
868
|
-
Number(cmpQuoteDt === null || cmpQuoteDt === void 0 ? void 0 : cmpQuoteDt.amountValue))) === null || _k === void 0 ? void 0 : _k.toString(),
|
|
437
|
+
amount: feeRes?.maxAmount,
|
|
438
|
+
amountInWei: feeRes?.maxAmount,
|
|
439
|
+
amountValue: feeRes?.maxAmount,
|
|
869
440
|
chainId,
|
|
870
441
|
functionName,
|
|
871
442
|
};
|
|
872
443
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
console.error((err === null || err === void 0 ? void 0 : err.message) || "getQuote failed.");
|
|
444
|
+
}
|
|
445
|
+
catch (err) {
|
|
446
|
+
if (err?.message?.includes("fn is not a function") ||
|
|
447
|
+
err?.message?.includes("fnTransfer is not a function")) {
|
|
448
|
+
console.error(`Function ${functionName} not found in contract's ABI`);
|
|
449
|
+
}
|
|
450
|
+
else if (err?.message?.includes("code=INVALID_ARGUMENT")) {
|
|
451
|
+
console.error(`Invalid arguments type`);
|
|
882
452
|
}
|
|
453
|
+
console.error(err?.message || "getQuote failed.");
|
|
883
454
|
}
|
|
884
455
|
}
|
|
885
456
|
}
|