@verified-network/verified-sdk 1.9.5 → 1.9.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.
Binary file
@@ -46,11 +46,12 @@ export declare class VerifiedContract {
46
46
  supportsGasless(chainId: number): boolean;
47
47
  /** Creates Biconomy smart account */
48
48
  createSmartAccount(chainId: number): Promise<import("@biconomy/account").BiconomySmartAccountV2>;
49
+ fetchUserOpReceipt(userOpHash: string): Promise<any>;
49
50
  /** Constructs and call function with ethers.js */
50
51
  callFunctionWithEthers(functionName: string, ...args: any): Promise<SCResponse>;
51
52
  /** Constructs and call function as userop for biconomy gassless(sponsored/erc20 mode) */
52
- callFunctionAsUserOp(smartAccount: any, tx: any, functionName: string, paymentToken: string, ...args: any): Promise<SCResponse>;
53
- callContract(functionName: string, ...args: any): Promise<SCResponse>;
53
+ callFunctionAsUserOp(smartAccount: any, tx: any, functionName: string, paymentToken: string, ...args: any): Promise<SCResponse | undefined>;
54
+ callContract(functionName: string, ...args: any): Promise<SCResponse | undefined>;
54
55
  protected getEvent(eventName: string, callback: any): void;
55
56
  }
56
57
  export {};
@@ -27,7 +27,7 @@ class VerifiedContract {
27
27
  this.contract = new ethers_1.ethers.Contract(address, this.abiInterface, signer);
28
28
  }
29
29
  async validateInput(type, data) {
30
- let error = '';
30
+ let error = "";
31
31
  let status = true;
32
32
  switch (type) {
33
33
  case DATATYPES.ADDRESS:
@@ -38,7 +38,7 @@ class VerifiedContract {
38
38
  break;
39
39
  case DATATYPES.NUMBER:
40
40
  if (data !== Number(data))
41
- error = 'Invalid numerical value';
41
+ error = "Invalid numerical value";
42
42
  else
43
43
  status = false;
44
44
  break;
@@ -50,8 +50,10 @@ class VerifiedContract {
50
50
  status = false;
51
51
  break;
52
52
  case DATATYPES.STRING:
53
- if ((typeof data === 'string' || data instanceof String || Object.prototype.toString.call(data) === '[object String]'))
54
- error = 'Invalid string value';
53
+ if (typeof data === "string" ||
54
+ data instanceof String ||
55
+ Object.prototype.toString.call(data) === "[object String]")
56
+ error = "Invalid string value";
55
57
  else
56
58
  status = false;
57
59
  break;
@@ -88,8 +90,10 @@ class VerifiedContract {
88
90
  */
89
91
  return ethers_1.utils.parseUnits(data);
90
92
  case DATATYPES.BOOLEAN:
91
- const arr = [true, false, "true", "false", 'TRUE', 'FALSE'];
92
- return arr.indexOf(data) !== -1 ? true : new Error("Invalid Boolean value");
93
+ const arr = [true, false, "true", "false", "TRUE", "FALSE"];
94
+ return arr.indexOf(data) !== -1
95
+ ? true
96
+ : new Error("Invalid Boolean value");
93
97
  default:
94
98
  return data;
95
99
  }
@@ -137,8 +141,8 @@ class VerifiedContract {
137
141
  if (!functionFragment) {
138
142
  throw new Error(`Function ${functionName} not found in ABI`);
139
143
  }
140
- return (functionFragment.stateMutability === 'view' ||
141
- functionFragment.stateMutability === 'pure');
144
+ return (functionFragment.stateMutability === "view" ||
145
+ functionFragment.stateMutability === "pure");
142
146
  }
143
147
  /**
144
148
  * Parses output to standard response
@@ -146,10 +150,13 @@ class VerifiedContract {
146
150
  * @returns
147
151
  */
148
152
  tempOutput(data) {
149
- const response = { hash: '', result: [] };
153
+ const response = {
154
+ hash: "",
155
+ result: [],
156
+ };
150
157
  data.forEach(async (element) => {
151
158
  if (element.hash !== undefined || element.transactionHash) {
152
- return response.hash = element.hash || element.transactionHash;
159
+ return (response.hash = element.hash || element.transactionHash);
153
160
  }
154
161
  else if (element._isBigNumber) {
155
162
  return response.result.push(element.toString());
@@ -161,7 +168,7 @@ class VerifiedContract {
161
168
  else if (ethers_1.utils.isBytesLike(element)) {
162
169
  return response.result.push(element);
163
170
  }
164
- else if (typeof element === 'boolean') {
171
+ else if (typeof element === "boolean") {
165
172
  return response.result.push(element);
166
173
  }
167
174
  else {
@@ -180,7 +187,9 @@ class VerifiedContract {
180
187
  /** Checks if a contract support gasless transaction */
181
188
  supportsGasless(chainId) {
182
189
  let isSupported = false;
183
- if (constants_1.PaymasterConstants[`${chainId}`] && constants_1.PaymasterConstants[`${chainId}`]["PAYMASTER_API_KEY"] && constants_1.PaymasterConstants[`${chainId}`]["BUNDLER_API_KEY"])
190
+ if (constants_1.PaymasterConstants[`${chainId}`] &&
191
+ constants_1.PaymasterConstants[`${chainId}`]["PAYMASTER_API_KEY"] &&
192
+ constants_1.PaymasterConstants[`${chainId}`]["BUNDLER_API_KEY"])
184
193
  isSupported = true;
185
194
  return isSupported;
186
195
  }
@@ -196,6 +205,31 @@ class VerifiedContract {
196
205
  // console.log("smart account address", await smartAccount.getAccountAddress());
197
206
  return smartAccount;
198
207
  }
208
+ async fetchUserOpReceipt(userOpHash) {
209
+ var _a;
210
+ try {
211
+ const chainId = await this.signer.getChainId();
212
+ const requestData = {
213
+ jsonrpc: "2.0",
214
+ method: "eth_getUserOperationReceipt",
215
+ id: Date.now(),
216
+ params: [userOpHash],
217
+ };
218
+ const response = await fetch(`${constants_1.PaymasterConstants.BUNDLER_URL_FIRST_SECTION}/${chainId}/${constants_1.PaymasterConstants[`${chainId}`]["BUNDLER_API_KEY"]}`, {
219
+ method: "POST",
220
+ headers: {
221
+ "Content-Type": "application/json",
222
+ },
223
+ body: JSON.stringify(requestData),
224
+ });
225
+ const data = await response.json();
226
+ return (_a = data === null || data === void 0 ? void 0 : data.result) === null || _a === void 0 ? void 0 : _a.receipt;
227
+ }
228
+ catch (err) {
229
+ console.error("Error trying to fetch gassless receipt", (err === null || err === void 0 ? void 0 : err.message) || err);
230
+ return { failed: true };
231
+ }
232
+ }
199
233
  /** Constructs and call function with ethers.js */
200
234
  async callFunctionWithEthers(functionName, ...args) {
201
235
  let res = {};
@@ -231,6 +265,7 @@ class VerifiedContract {
231
265
  }
232
266
  /** Constructs and call function as userop for biconomy gassless(sponsored/erc20 mode) */
233
267
  async callFunctionAsUserOp(smartAccount, tx, functionName, paymentToken, ...args) {
268
+ var _a, _b, _c;
234
269
  //send userops transaction and construct transaction response
235
270
  let res = {};
236
271
  try {
@@ -240,11 +275,13 @@ class VerifiedContract {
240
275
  const { transactionHash } = await userOpResponse.waitForTxHash();
241
276
  console.log("Gassless Transaction Hash", transactionHash);
242
277
  const userOpReceipt = await userOpResponse.wait();
243
- if (userOpReceipt.success == 'true') {
278
+ if (userOpReceipt.success == "true") {
244
279
  res.status = STATUS.SUCCESS;
245
280
  res.response = {
246
- hash: transactionHash,
247
- result: userOpReceipt.receipt.result || userOpReceipt.receipt.response || userOpReceipt.receipt,
281
+ hash: (userOpReceipt === null || userOpReceipt === void 0 ? void 0 : userOpReceipt.transactionHash) || transactionHash,
282
+ result: userOpReceipt.receipt.result ||
283
+ userOpReceipt.receipt.response ||
284
+ userOpReceipt.receipt,
248
285
  }; //TODO: update result on response
249
286
  res.message = "";
250
287
  return res;
@@ -252,17 +289,19 @@ class VerifiedContract {
252
289
  else {
253
290
  console.log("Gassless failed will try ERC20...");
254
291
  const ERC20userOpResponse = await smartAccount.sendTransaction(tx, {
255
- paymasterServiceData: { mode: "ERC20", preferredToken: paymentToken, },
292
+ paymasterServiceData: { mode: "ERC20", preferredToken: paymentToken },
256
293
  });
257
294
  const { ERC20transactionHash } = await ERC20userOpResponse.waitForTxHash();
258
295
  console.log("ERC20 Transaction Hash", ERC20transactionHash);
259
296
  const userOpReceipt = await ERC20userOpResponse.wait();
260
- if (userOpReceipt.success == 'true') {
297
+ if (userOpReceipt.success == "true") {
261
298
  res.status = STATUS.SUCCESS;
262
299
  res.response = {
263
- hash: ERC20transactionHash,
264
- result: ERC20userOpResponse.receipt.result || ERC20userOpResponse.receipt.response || ERC20userOpResponse.receipt,
265
- }; //TODO: update result on response
300
+ hash: (userOpReceipt === null || userOpReceipt === void 0 ? void 0 : userOpReceipt.transactionHash) || ERC20transactionHash,
301
+ result: ERC20userOpResponse.receipt.result ||
302
+ ERC20userOpResponse.receipt.response ||
303
+ ERC20userOpResponse.receipt,
304
+ }; //TODO: update result on response
266
305
  res.message = "";
267
306
  return res;
268
307
  }
@@ -274,13 +313,53 @@ class VerifiedContract {
274
313
  }
275
314
  }
276
315
  catch (err) {
277
- console.error("gasless transaction failed with error: ", err);
278
- console.log("will use ethers....");
279
- // res.status = STATUS.ERROR;
280
- // res.reason = err.reason;
281
- // res.message = err.message;
282
- // res.code = err.code;
283
- return await this.callFunctionWithEthers(functionName, ...args);
316
+ 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")) {
317
+ //extract hash from message due to difference in hash???
318
+ const messageArray = (_b = err === null || err === void 0 ? void 0 : err.message) === null || _b === void 0 ? void 0 : _b.split(" ");
319
+ 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(".", "");
320
+ //wait up to max round to fetch receipt ???
321
+ if (txHash) {
322
+ for (let i = 0; i < Number(constants_1.PaymasterConstants.MAX_WAITING_ROUND); i++) {
323
+ await new Promise((resolve) => {
324
+ setTimeout(resolve, 6000); //1 minute delay per round
325
+ });
326
+ console.log("Gassless timeout exceeded, fetching receipt for round: ", i + 1, "out of ", Number(constants_1.PaymasterConstants.MAX_WAITING_ROUND));
327
+ return await this.fetchUserOpReceipt(txHash).then(async (_res) => {
328
+ if (_res && !(_res === null || _res === void 0 ? void 0 : _res.failed) && (_res === null || _res === void 0 ? void 0 : _res.status) == "0x1") {
329
+ //if receipt received stop and configure return
330
+ res.status = STATUS.SUCCESS;
331
+ res.response = {
332
+ hash: (_res === null || _res === void 0 ? void 0 : _res.transactionHash) || txHash,
333
+ result: _res,
334
+ }; //TODO: update result on response
335
+ res.message = "";
336
+ return res;
337
+ }
338
+ else if (_res && !(_res === null || _res === void 0 ? void 0 : _res.failed) && (_res === null || _res === void 0 ? void 0 : _res.status) != "0x1") {
339
+ //if transaction failed
340
+ console.error("gasless transaction failed with error: ", "False receipt status");
341
+ console.log("will use ethers....");
342
+ return await this.callFunctionWithEthers(functionName, ...args);
343
+ }
344
+ else if (_res && (_res === null || _res === void 0 ? void 0 : _res.failed)) {
345
+ //if receipt failed stop and use ethers
346
+ console.log("will use ethers....");
347
+ return await this.callFunctionWithEthers(functionName, ...args);
348
+ }
349
+ });
350
+ }
351
+ }
352
+ else {
353
+ console.error("gasless transaction failed with error: ", "No TX-hash from error message.");
354
+ console.log("will use ethers....");
355
+ return await this.callFunctionWithEthers(functionName, ...args);
356
+ }
357
+ }
358
+ else {
359
+ console.error("gasless transaction failed with error: ", err);
360
+ console.log("will use ethers....");
361
+ return await this.callFunctionWithEthers(functionName, ...args);
362
+ }
284
363
  }
285
364
  }
286
365
  async callContract(functionName, ...args) {
@@ -337,7 +416,7 @@ class VerifiedContract {
337
416
  const dataToBeFormatted = data.splice(0, data.length - 1);
338
417
  res.response = this.tempOutput(ethers_1.utils.deepCopy(dataToBeFormatted));
339
418
  res.status = STATUS.SUCCESS;
340
- res.message = '';
419
+ res.message = "";
341
420
  callback(res);
342
421
  });
343
422
  }
package/dist/index.d.ts CHANGED
@@ -1,22 +1,23 @@
1
- import { VerifiedWallet } from './wallet';
2
- import { Provider } from './utils';
3
- import ERC20 from './contract/erc20';
4
- import Bond from './contract/bond';
5
- import Cash from './contract/cash';
6
- import Factory from './contract/factory';
7
- import Token from './contract/token';
8
- import Pool from './contract/pool';
9
- import Custody from './contract/custody';
10
- import Liquidity from './contract/liquidity';
11
- import Rates from './contract/rates';
12
- import PrimaryIssueManager from './contract/amm/primary';
13
- import SecondaryIssueManager from './contract/amm/secondary';
14
- import MarginIssueManager from './contract/amm/margin';
15
- import Security from './contract/security';
16
- import SecuritiesFactory from './contract/securitiesfactory';
17
- import Distribution from './contract/distribution';
18
- import Client from './contract/client';
19
- import Compound from './contract/loans/compound';
1
+ import { VerifiedWallet } from "./wallet";
2
+ import { Provider } from "./utils";
3
+ import ERC20 from "./contract/erc20";
4
+ import Bond from "./contract/bond";
5
+ import Cash from "./contract/cash";
6
+ import Factory from "./contract/factory";
7
+ import Token from "./contract/token";
8
+ import Pool from "./contract/pool";
9
+ import Custody from "./contract/custody";
10
+ import Liquidity from "./contract/liquidity";
11
+ import Rates from "./contract/rates";
12
+ import PrimaryIssueManager from "./contract/amm/primary";
13
+ import SecondaryIssueManager from "./contract/amm/secondary";
14
+ import MarginIssueManager from "./contract/amm/margin";
15
+ import Security from "./contract/security";
16
+ import SecuritiesFactory from "./contract/securitiesfactory";
17
+ import Distribution from "./contract/distribution";
18
+ import Client from "./contract/client";
19
+ import Compound from "./contract/loans/compound";
20
20
  import { utils } from "ethers";
21
21
  import contractAddress from "./contractAddress";
22
- export { VerifiedWallet, Provider, ERC20, Bond, Cash, Factory, Token, Pool, Custody, Liquidity, Rates, PrimaryIssueManager, SecondaryIssueManager, MarginIssueManager, Security, SecuritiesFactory, Distribution, Client, Compound, utils, contractAddress };
22
+ import { PaymasterConstants } from "./utils/constants";
23
+ export { VerifiedWallet, Provider, ERC20, Bond, Cash, Factory, Token, Pool, Custody, Liquidity, Rates, PrimaryIssueManager, SecondaryIssueManager, MarginIssueManager, Security, SecuritiesFactory, Distribution, Client, Compound, utils, contractAddress, PaymasterConstants, };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
- // SPDX-License-Identifier: BUSL-1.1
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
4
  };
6
5
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.contractAddress = exports.utils = exports.Compound = exports.Client = exports.Distribution = exports.SecuritiesFactory = exports.Security = exports.MarginIssueManager = exports.SecondaryIssueManager = exports.PrimaryIssueManager = exports.Rates = exports.Liquidity = exports.Custody = exports.Pool = exports.Token = exports.Factory = exports.Cash = exports.Bond = exports.ERC20 = exports.Provider = exports.VerifiedWallet = void 0;
6
+ exports.PaymasterConstants = exports.contractAddress = exports.utils = exports.Compound = exports.Client = exports.Distribution = exports.SecuritiesFactory = exports.Security = exports.MarginIssueManager = exports.SecondaryIssueManager = exports.PrimaryIssueManager = exports.Rates = exports.Liquidity = exports.Custody = exports.Pool = exports.Token = exports.Factory = exports.Cash = exports.Bond = exports.ERC20 = exports.Provider = exports.VerifiedWallet = void 0;
7
+ // SPDX-License-Identifier: BUSL-1.1
8
8
  const wallet_1 = require("./wallet");
9
9
  Object.defineProperty(exports, "VerifiedWallet", { enumerable: true, get: function () { return wallet_1.VerifiedWallet; } });
10
10
  const utils_1 = require("./utils");
@@ -47,3 +47,5 @@ const ethers_1 = require("ethers");
47
47
  Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return ethers_1.utils; } });
48
48
  const contractAddress_1 = __importDefault(require("./contractAddress"));
49
49
  exports.contractAddress = contractAddress_1.default;
50
+ const constants_1 = require("./utils/constants");
51
+ Object.defineProperty(exports, "PaymasterConstants", { enumerable: true, get: function () { return constants_1.PaymasterConstants; } });
@@ -3,6 +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
+ MAX_WAITING_ROUND: 3, //number of rounds gassless transactions will wait to fetch receipt. Note: each round is 1 minute, so 3 for example is 3 minutes
6
7
  BUNDLER_URL_FIRST_SECTION: "https://bundler.biconomy.io/api/v2",
7
8
  GENERAL_PAYMASTER_URL: "https://paymaster.biconomy.io/api/v1",
8
9
  BICONOMY_REVERT_TOPIC: "0x1c4fada7374c0a9ee8841fc38afe82932dc0f8e69012e927f061a8bae611a201",
@@ -10,36 +11,36 @@ exports.PaymasterConstants = {
10
11
  11155111: {
11
12
  PAYMASTER_API_KEY: "BuFP2-5w-.5b3daf3a-d044-4dda-819c-4c4d8431df88",
12
13
  BUNDLER_API_KEY: "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
13
- RPC_URL: "https://rpc.sepolia.org"
14
+ RPC_URL: "https://rpc.sepolia.org",
14
15
  },
15
16
  //polgon mainnet
16
17
  137: {
17
18
  PAYMASTER_API_KEY: "lDHvYk50N.30a2522e-0a9d-444b-b949-19194c1f237a",
18
19
  BUNDLER_API_KEY: "dewj2189.wh1289hU-7E49-45ic-af80-JkuxGCYRV",
19
- RPC_URL: "https://polygon-rpc.com"
20
+ RPC_URL: "https://polygon-rpc.com",
20
21
  },
21
22
  //base sepolia
22
23
  84532: {
23
24
  PAYMASTER_API_KEY: "jSBI-WRji.99a4dda1-1c20-42ea-9409-2724f9a0ca7e",
24
25
  BUNDLER_API_KEY: "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
25
- RPC_URL: "https://sepolia.base.org"
26
+ RPC_URL: "https://sepolia.base.org",
26
27
  },
27
28
  //ethereum mainnet
28
29
  1: {
29
30
  PAYMASTER_API_KEY: "ap7LOqALI.bf68e672-47ce-40f8-8b62-ea508dcf5852",
30
31
  BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
31
- RPC_URL: "https://eth-mainnet.g.alchemy.com/v2/82hkNrfu6ZZ8Wms2vr1U331ml3FtS7AZ"
32
+ RPC_URL: "https://eth-mainnet.g.alchemy.com/v2/82hkNrfu6ZZ8Wms2vr1U331ml3FtS7AZ",
32
33
  },
33
34
  //base mainnet
34
35
  8453: {
35
36
  PAYMASTER_API_KEY: "glRQsmuYh.5d9372ab-5063-4ecd-ac63-643fef624a73",
36
37
  BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
37
- RPC_URL: "https://mainnet.base.org"
38
+ RPC_URL: "https://mainnet.base.org",
38
39
  },
39
40
  //gnosis
40
41
  100: {
41
42
  PAYMASTER_API_KEY: "eUYghbvi4.317a2d6d-6ee7-4a0c-b91f-43ba2699f65b",
42
43
  BUNDLER_API_KEY: "dewj402.wh1289hU-7E49-85b-af80-t6XmQ4yJs",
43
- RPC_URL: "https://rpc.gnosischain.com"
44
- }
44
+ RPC_URL: "https://rpc.gnosischain.com",
45
+ },
45
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verified-network/verified-sdk",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "An SDK to develop applications on the Verified Network",
5
5
  "repository": {
6
6
  "type": "git",