@verified-network/verified-sdk 1.5.6 → 1.5.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/.env +1 -0
- package/README.md +230 -8
- package/dist/contract/index.js +45 -36
- package/dist/utils/constants.js +15 -0
- package/package.json +2 -4
package/.env
CHANGED
|
@@ -5,4 +5,5 @@ GENERAL_PAYMASTER_URL="https://paymaster.biconomy.io/api/v1"
|
|
|
5
5
|
80001_PAYMASTER_API_KEY="aoDXoLOsa.b941e672-e98f-4d56-b9f6-733dca59a87e"
|
|
6
6
|
# 5_CASH_TOKEN_ADDRESS="0x07865c6E87B9F70255377e024ace6630C1Eaa37F" //goerli(chainid 5) not workith biconomy
|
|
7
7
|
80001_CASH_TOKEN_ADDRESS="0xda5289fcaaf71d52a80a254da614a192b693e977"
|
|
8
|
+
11155111_PAYMASTER_API_KEY="BuFP2-5w-.5b3daf3a-d044-4dda-819c-4c4d8431df88"
|
|
8
9
|
BICONOMY_REVERT_TOPIC="0x1c4fada7374c0a9ee8841fc38afe82932dc0f8e69012e927f061a8bae611a201"
|
package/README.md
CHANGED
|
@@ -1,34 +1,88 @@
|
|
|
1
1
|
# The Verified SDK
|
|
2
|
+
|
|
2
3
|
The Verified SDK provides access to the issuing, trading and servicing of tokenized securities on the Verified Network.
|
|
3
4
|
|
|
4
5
|
# installing using npm
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
`npm install @verified-network/verified-sdk`
|
|
6
8
|
|
|
7
9
|
# creating new wallet
|
|
10
|
+
|
|
8
11
|
```
|
|
9
12
|
const {VerifiedWallet} = require('@verified-network/verified-sdk');
|
|
10
13
|
let mnemonics = await VerifiedWallet.generateMnemonics()
|
|
11
14
|
let wallet = await VerifiedWallet.importWallet(menmonics)
|
|
12
15
|
```
|
|
16
|
+
|
|
13
17
|
# setProvider
|
|
18
|
+
|
|
19
|
+
Provider can be set for wallet using 2 options:
|
|
20
|
+
|
|
21
|
+
# using default providers
|
|
22
|
+
|
|
23
|
+
Default providers are available for networks like: mainnet/homestead, ropsten, sepolia e.t.c and are mainly used for development(it is also robust enough for use in production)
|
|
24
|
+
|
|
14
25
|
```
|
|
15
26
|
const {Provider} = require('@verified-network/verified-sdk');
|
|
16
|
-
const defaultProvider = '
|
|
27
|
+
const defaultProvider = 'sepolia' // or any other default provider network of your choice.
|
|
28
|
+
Network/chain id(number) can be used in place of network name, for example:
|
|
29
|
+
const defaultProvider = 11155111 // where number 11155111 is chain id for sepolia, any other chain id of default provider network can be used.
|
|
17
30
|
let walletWithProvider = wallet.setProvider(
|
|
18
31
|
Provider.defaultProvider(defaultProvider)
|
|
19
32
|
)
|
|
20
33
|
```
|
|
34
|
+
|
|
35
|
+
# using custom providers
|
|
36
|
+
|
|
37
|
+
Verified Sdk supports Infura and Alchemy to provide custom providers for any network.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
const {Provider} = require('@verified-network/verified-sdk');
|
|
41
|
+
const network = 'sepolia' // or any other network of your choice.
|
|
42
|
+
Network/chain id(number) can be used in place of network name, for example:
|
|
43
|
+
const network = 11155111 // where number 11155111 is chain id for sepolia, any other chain id can be used.
|
|
44
|
+
//For infura; to get api key and enable networks checout: https://www.infura.io/
|
|
45
|
+
const INFURA_API_KEY = 'your infura api key'
|
|
46
|
+
let walletWithProvider = wallet.setProvider(
|
|
47
|
+
Provider.infuraProvider(network, INFURA_API_KEY)
|
|
48
|
+
)
|
|
49
|
+
//For Alchemy; to get api key and enable networks checout: https://www.alchemy.com/
|
|
50
|
+
const ALCHEMY_KEY = 'your alchemy api key'
|
|
51
|
+
let walletWithProvider = wallet.setProvider(
|
|
52
|
+
Provider.alchemyProvider(network, ALCHEMY_KEY)
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
21
56
|
# interacting with Smart contracts
|
|
22
|
-
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
cosnt {Client} = require('@verified-network/verified-sdk');
|
|
60
|
+
let clientContract = new Client(walletWithProvider);
|
|
61
|
+
```
|
|
23
62
|
|
|
24
63
|
This will create an instance of Client contract and you can access all the functions within the clientContract using this object.
|
|
25
64
|
|
|
26
65
|
Now you can call a function in clientContract like:
|
|
27
|
-
|
|
66
|
+
`clientContract.setAccess("true")` // to set the access to True/False.
|
|
67
|
+
|
|
68
|
+
Some contracts requires additional parameters to create their instances, for example:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
cosnt {SecurityContract, PrimaryIssueManager} = require('@verified-network/verified-sdk');
|
|
72
|
+
// securityContract
|
|
73
|
+
const securityContractAddress = 'security address for any verified security'
|
|
74
|
+
let securityContract = new SecurityContract(walletWithProvider, securityContractAddress);
|
|
75
|
+
|
|
76
|
+
//primaryIssueManager
|
|
77
|
+
const primaryIssueManagerAddress = 'primary issue manager address'
|
|
78
|
+
const primaryIssueManagerplatform = 'primary issue manager platform' //e.g 'balancer'
|
|
79
|
+
let primaryIssueManagerContract = new PrimaryIssueManager(walletWithProvider, primaryIssueManagerAddress, primaryIssueManagerplatform);
|
|
80
|
+
```
|
|
28
81
|
|
|
29
82
|
Similarly you can create different Contracts instances available:
|
|
83
|
+
|
|
30
84
|
```
|
|
31
|
-
|
|
85
|
+
Client,
|
|
32
86
|
BondContract,
|
|
33
87
|
CashContract,
|
|
34
88
|
TokenContract,
|
|
@@ -46,17 +100,185 @@ DistributionContract
|
|
|
46
100
|
```
|
|
47
101
|
|
|
48
102
|
# VerifiedContract
|
|
103
|
+
|
|
49
104
|
src/contract/index.ts is the base class for all Contracts created.
|
|
50
105
|
It has the logic to validate the Input, Sanitise the Input and Output, call the contract functions etc.
|
|
51
106
|
All the contracts trigger smart contract calls and go through the callContract function.
|
|
52
107
|
|
|
53
108
|
Optionally, all the contractCalls take in an additional parameter:
|
|
54
|
-
|
|
109
|
+
`options?: { gasPrice: number, gasLimit: number }`
|
|
55
110
|
You can configure the gasPrice and gasLimit using this parameter as the last parameter to the contractCall function.
|
|
56
|
-
Example:
|
|
111
|
+
Example: `this.callContract(FUNCTIONS.GETORDERS, originator, options)`
|
|
57
112
|
Where, options = {gasPrice: XXX, gasLimit: YYY}
|
|
58
113
|
|
|
59
114
|
# This is how you can integrate with any Dapp.
|
|
115
|
+
|
|
60
116
|
1. Install and Import the SDK
|
|
61
117
|
2. Create a wallet instance and fund it
|
|
62
|
-
3. Create instances of the Contract that you want to interact with using the above wallet and call their functions.
|
|
118
|
+
3. Create instances of the Contract that you want to interact with using the above wallet and call their functions.
|
|
119
|
+
|
|
120
|
+
# Common Error(s) with Verified Sdk integration with Dapp
|
|
121
|
+
|
|
122
|
+
Due to webpack version > 5 that no longer includes NodeJS polyfills by default, it is causing issues for developers that use React(create-react-app), React-native, Vite with webpack version > 5 to build applications with web3.js, ethers.js, alchemy libraries e.t.c. Many of this libraries and dependencies are used by Verified Sdk.
|
|
123
|
+
|
|
124
|
+
There are various ways to solve this error, from updating webpack config to babel config e.t.c. and can be overwhelming for developers. Verified Network Team recommend ed using best solutions that are easy to use and beginner friendly.
|
|
125
|
+
|
|
126
|
+
# How to resolve React error(s) with Verified Sdk integration
|
|
127
|
+
|
|
128
|
+
Step 1: Install react-app-rewired
|
|
129
|
+
with npm: `npm install --save-dev react-app-rewired`
|
|
130
|
+
with yarn: `yarn add --dev react-app-rewired`
|
|
131
|
+
|
|
132
|
+
Step 2: Install needed dependencies
|
|
133
|
+
// with npm:
|
|
134
|
+
`npm install --save-dev crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process`
|
|
135
|
+
// with yarn:
|
|
136
|
+
`yarn add crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process`
|
|
137
|
+
|
|
138
|
+
note: the above dependencies are needed dependencies to make verified sdk works, more dependencies can be added to handle any other nodeJs polyfills error.
|
|
139
|
+
|
|
140
|
+
Step 3: Override create-react-app webpack config file
|
|
141
|
+
In the root folder of your project, create a new file called 'config-overrides.js', and add the following code to it:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
const webpack = require("webpack");
|
|
145
|
+
module.exports = function override(config) {
|
|
146
|
+
const fallback = config.resolve.fallback || {};
|
|
147
|
+
Object.assign(fallback, {
|
|
148
|
+
crypto: require.resolve("crypto-browserify"),
|
|
149
|
+
stream: require.resolve("stream-browserify"),
|
|
150
|
+
assert: require.resolve("assert"),
|
|
151
|
+
http: require.resolve("stream-http"),
|
|
152
|
+
https: require.resolve("https-browserify"),
|
|
153
|
+
os: require.resolve("os-browserify"),
|
|
154
|
+
url: require.resolve("url"),
|
|
155
|
+
path: require.resolve("path-browserify"),
|
|
156
|
+
fs: false, //assumed fs module will not be used(to use fs module download dependency to handle it)
|
|
157
|
+
});
|
|
158
|
+
config.plugins = (config.plugins || []).concat([
|
|
159
|
+
new webpack.ProvidePlugin({
|
|
160
|
+
process: "process/browser",
|
|
161
|
+
Buffer: ["buffer", "Buffer"],
|
|
162
|
+
}),
|
|
163
|
+
]);
|
|
164
|
+
config.module.rules = [
|
|
165
|
+
...config.module.rules,
|
|
166
|
+
{
|
|
167
|
+
test: /\.m?js/,
|
|
168
|
+
resolve: {
|
|
169
|
+
fullySpecified: false,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
]; // rules are optional can be customised to fit your usecase
|
|
173
|
+
config.resolve.fallback = fallback;
|
|
174
|
+
config.ignoreWarnings = [/Failed to parse source map/]; // optional can be customised to fit your usecase
|
|
175
|
+
return config;
|
|
176
|
+
};
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
This 'config-overrides.js' code snippet is telling webpack how to resolve the missing dependencies that are needed to support web3, ethers libraries and wallet providers in the browser/server side.
|
|
180
|
+
|
|
181
|
+
Step 4: Override package.json to use react-app-rewired
|
|
182
|
+
Within the package.json file, replace react-scripts with react-app-rewired scripts for 'start', 'build', 'test'
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
"scripts": {
|
|
186
|
+
"start": "react-app-rewired start",
|
|
187
|
+
"build": "react-app-rewired build",
|
|
188
|
+
"test": "react-app-rewired test",
|
|
189
|
+
"eject": "react-scripts eject"
|
|
190
|
+
},
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
note: start changed from "react-scripts start" to "react-app-rewired start", build from "react-scripts build" to "react-app-rewired build" and test from "react-scripts test" to "react-app-rewired test" while eject remains the same.
|
|
194
|
+
|
|
195
|
+
The polyfill node core module error should be fixed any missing NodeJS polyfills should be included in your app, and your app should work well with Verified Sdk
|
|
196
|
+
|
|
197
|
+
# How to resolve Vite error(s) with Verified Sdk integration
|
|
198
|
+
|
|
199
|
+
Step 1: install @esbuild-plugins/node-modules-polyfill and rollup-plugin-polyfill-node
|
|
200
|
+
with npm: `npm i @esbuild-plugins/node-modules-polyfill rollup-plugin-polyfill-node`
|
|
201
|
+
with yarn: `yarn add @esbuild-plugins/node-modules-polyfill rollup-plugin-polyfill-node`
|
|
202
|
+
|
|
203
|
+
Step 2: Install needed dependencies
|
|
204
|
+
with npm:
|
|
205
|
+
`npm install --save-dev crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process`
|
|
206
|
+
with yarn:
|
|
207
|
+
`yarn add crypto-browserify stream-browserify assert stream-http https-browserify os-browserify url buffer process`
|
|
208
|
+
|
|
209
|
+
Step 3: update vite.config.js file
|
|
210
|
+
From the root folder of your project update 'vite.config.js' to resolve missing dependencies
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
|
|
214
|
+
import nodePolyfills from "rollup-plugin-polyfill-node";
|
|
215
|
+
|
|
216
|
+
// https://vitejs.dev/config/
|
|
217
|
+
export default defineConfig({
|
|
218
|
+
build: {
|
|
219
|
+
target: ["es2020"], //optional can be customised
|
|
220
|
+
rollupOptions: {
|
|
221
|
+
plugins: [nodePolyfills()],
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
resolve: {
|
|
225
|
+
alias: {
|
|
226
|
+
process: "process/browser",
|
|
227
|
+
stream: "stream-browserify",
|
|
228
|
+
zlib: "browserify-zlib",
|
|
229
|
+
util: "util/",
|
|
230
|
+
path: "path-browserify",
|
|
231
|
+
"@": resolve(__dirname, "./src"), //optional
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
optimizeDeps: {
|
|
235
|
+
esbuildOptions: {
|
|
236
|
+
// Node.js global to browser globalThis
|
|
237
|
+
define: {
|
|
238
|
+
global: "globalThis",
|
|
239
|
+
},
|
|
240
|
+
supported: {
|
|
241
|
+
bigint: true, //optional
|
|
242
|
+
},
|
|
243
|
+
// Enable esbuild polyfill plugins
|
|
244
|
+
plugins: [
|
|
245
|
+
NodeGlobalsPolyfillPlugin({
|
|
246
|
+
buffer: true,
|
|
247
|
+
protocolImports: true,
|
|
248
|
+
}),
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
This 'vite.config.js' code snippet is telling webpack how to resolve the missing dependencies that are needed to support web3, ethers libraries and wallet providers in the browser/server side.
|
|
257
|
+
|
|
258
|
+
The polyfill node core module error should be fixed any missing NodeJS polyfills should be included in your app, and your app should work well with Verified Sdk.
|
|
259
|
+
|
|
260
|
+
# Verified Sdk also provides ERC 4337-compliant solution and enable account abstraction using Biconomy Smart Accounts.
|
|
261
|
+
|
|
262
|
+
Verified Sdk follows ERC 4337 standard and implement pseudo-transaction object(userOperation) to enable transaction sponsorship allowing smart contract creators to sponsor some set of transactions on smart contract for users when certain functions are called and allow multiple transaction to be called in batch
|
|
263
|
+
|
|
264
|
+
With this unique feature of Verified Sdk creators can pay gas fee for users/entity interaction with smart contract in ERC 20 token or Native tokens(Eth, Matic e.t.c) and also enable users/entity interacting with the contract to pay for gas fee using ERC 20 tokens.
|
|
265
|
+
|
|
266
|
+
# How Verified Sdk Gasless transactions work
|
|
267
|
+
|
|
268
|
+
For every transactions/interactions with verified smart contracts, various checks are made to determine if the transaction will be gasless(will be sponsored) or not. For gasless transactions, contract creators have pre deposited certain amount of native tokens(Eth, Matic e.t.c) or ERC 20 tokens(USDC, VUSDC e.t.c) on Biconomy paymaster dashboard to cover gas fees for set of functions on smart contract.
|
|
269
|
+
|
|
270
|
+
# Verified Sdk checks for every transaction:
|
|
271
|
+
|
|
272
|
+
# Check 1: is Biconomy Paymaster supported for the network/chain the contract is on?
|
|
273
|
+
If yes:
|
|
274
|
+
# Check 2: is the smart contract called part of smart contracts that support gasless or Erc 20 gas payments?
|
|
275
|
+
If yes:
|
|
276
|
+
# Check 3: is the function called parts of functions selected to support gasless or ERC 20 payments?
|
|
277
|
+
If yes:
|
|
278
|
+
# Check 4: what type of paymaster was set? Gasless or ERC 20
|
|
279
|
+
If gasless:
|
|
280
|
+
# Check 5: is the deposited gas enough to pay for transaction?
|
|
281
|
+
if yes: Transaction is sposored(user does not pay for gas fee)
|
|
282
|
+
if ERC 20:
|
|
283
|
+
# User pay for transaction using ERC 20 tokens
|
|
284
|
+
# If no: User will pay for transaction using native tokens(Eth, Matic e.t.c)
|
package/dist/contract/index.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
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
|
-
const dotenv_1 = require("dotenv");
|
|
9
5
|
const ethers_1 = require("ethers");
|
|
10
|
-
const web3_1 = __importDefault(require("web3"));
|
|
11
6
|
const account_1 = require("@biconomy/account");
|
|
12
7
|
const modules_1 = require("@biconomy/modules");
|
|
13
8
|
const bundler_1 = require("@biconomy/bundler");
|
|
14
9
|
const paymaster_1 = require("@biconomy/paymaster");
|
|
15
|
-
|
|
10
|
+
const constants_1 = require("../utils/constants");
|
|
16
11
|
var STATUS;
|
|
17
12
|
(function (STATUS) {
|
|
18
13
|
STATUS[STATUS["SUCCESS"] = 0] = "SUCCESS";
|
|
@@ -143,17 +138,25 @@ class VerifiedContract {
|
|
|
143
138
|
tempOutput(data) {
|
|
144
139
|
const response = { hash: '', result: [] };
|
|
145
140
|
data.forEach(async (element) => {
|
|
146
|
-
if (element.hash !== undefined || element.transactionHash)
|
|
141
|
+
if (element.hash !== undefined || element.transactionHash) {
|
|
147
142
|
return response.hash = element.hash || element.transactionHash;
|
|
148
|
-
|
|
143
|
+
}
|
|
144
|
+
else if (element._isBigNumber) {
|
|
149
145
|
return response.result.push(element.toString());
|
|
150
|
-
|
|
146
|
+
}
|
|
147
|
+
else if (ethers_1.utils.isAddress(element)) {
|
|
151
148
|
return response.result.push(element);
|
|
149
|
+
}
|
|
152
150
|
//if (utils.isBytesLike(element)) return response.result.push(this.sanitiseOutput(DATATYPES.BYTE32, element))
|
|
153
|
-
if (ethers_1.utils.isBytesLike(element))
|
|
151
|
+
else if (ethers_1.utils.isBytesLike(element)) {
|
|
152
|
+
return response.result.push(element);
|
|
153
|
+
}
|
|
154
|
+
else if (typeof element === 'boolean') {
|
|
154
155
|
return response.result.push(element);
|
|
155
|
-
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
156
158
|
return response.result.push(element);
|
|
159
|
+
}
|
|
157
160
|
});
|
|
158
161
|
return response;
|
|
159
162
|
}
|
|
@@ -167,7 +170,7 @@ class VerifiedContract {
|
|
|
167
170
|
/** Checks if a contract support gasless transaction */
|
|
168
171
|
supportsGasless(chainId) {
|
|
169
172
|
let isSupported = false;
|
|
170
|
-
const contractPaymasterUrl =
|
|
173
|
+
const contractPaymasterUrl = constants_1.PaymasterConstants[`${chainId}_PAYMASTER_API_KEY`];
|
|
171
174
|
if (contractPaymasterUrl && contractPaymasterUrl.length > 0)
|
|
172
175
|
isSupported = true;
|
|
173
176
|
return isSupported;
|
|
@@ -176,16 +179,14 @@ class VerifiedContract {
|
|
|
176
179
|
async createSmartAccount(chainId) {
|
|
177
180
|
//create bundler instance
|
|
178
181
|
const bundler = new bundler_1.Bundler({
|
|
179
|
-
bundlerUrl: `${
|
|
182
|
+
bundlerUrl: `${constants_1.PaymasterConstants.BUNDLER_URL_FIRST_SECTION}/${chainId}/${constants_1.PaymasterConstants[`${chainId}_URL_SECOND_SECTION`]}`,
|
|
180
183
|
chainId: chainId,
|
|
181
184
|
entryPointAddress: account_1.DEFAULT_ENTRYPOINT_ADDRESS,
|
|
182
185
|
});
|
|
183
|
-
// console.log("bd: ", bundler);
|
|
184
186
|
//create paymaster instance
|
|
185
187
|
const paymaster = new paymaster_1.BiconomyPaymaster({
|
|
186
|
-
paymasterUrl: `${
|
|
188
|
+
paymasterUrl: `${constants_1.PaymasterConstants.GENERAL_PAYMASTER_URL}/${chainId}/${constants_1.PaymasterConstants[`${chainId}_PAYMASTER_API_KEY`]}`,
|
|
187
189
|
});
|
|
188
|
-
// console.log("pm: ", paymaster);
|
|
189
190
|
const module = await modules_1.ECDSAOwnershipValidationModule.create({
|
|
190
191
|
signer: this.signer,
|
|
191
192
|
moduleAddress: modules_1.DEFAULT_ECDSA_OWNERSHIP_MODULE,
|
|
@@ -200,7 +201,6 @@ class VerifiedContract {
|
|
|
200
201
|
activeValidationModule: module,
|
|
201
202
|
});
|
|
202
203
|
// console.log("address", await biconomyAccount.getAccountAddress());
|
|
203
|
-
//return smart account
|
|
204
204
|
return biconomyAccount;
|
|
205
205
|
}
|
|
206
206
|
/** Constructs and call function with ethers.js */
|
|
@@ -221,10 +221,7 @@ class VerifiedContract {
|
|
|
221
221
|
*/
|
|
222
222
|
let fn = this.contract[functionName];
|
|
223
223
|
let _res = await fn(...args, ...options);
|
|
224
|
-
//console.log('_res', _res)
|
|
225
|
-
//console.log('_res.value.toString()',_res.value.toString())
|
|
226
224
|
let _resp = _res.wait !== undefined ? await _res.wait(_res) : _res;
|
|
227
|
-
//console.log('_resp', _resp)
|
|
228
225
|
res.response = this.tempOutput(this.convertToArray(ethers_1.utils.deepCopy(_resp)));
|
|
229
226
|
res.status = STATUS.SUCCESS;
|
|
230
227
|
res.message = "";
|
|
@@ -240,7 +237,7 @@ class VerifiedContract {
|
|
|
240
237
|
}
|
|
241
238
|
}
|
|
242
239
|
/** Constructs and call function as userop for biconomy gassless(sponsored/erc20 mode) */
|
|
243
|
-
async callFunctionAsUserOp(smartAccount, userOp) {
|
|
240
|
+
async callFunctionAsUserOp(smartAccount, userOp, functionName, ...args) {
|
|
244
241
|
//send userops transaction and construct transaction response
|
|
245
242
|
let res = {};
|
|
246
243
|
try {
|
|
@@ -250,7 +247,7 @@ class VerifiedContract {
|
|
|
250
247
|
res.response = {
|
|
251
248
|
hash: transactionDetails.receipt.transactionHash,
|
|
252
249
|
result: [],
|
|
253
|
-
}; //TODO: update response
|
|
250
|
+
}; //TODO: update result on response
|
|
254
251
|
res.status = STATUS.SUCCESS;
|
|
255
252
|
res.message = "";
|
|
256
253
|
return res;
|
|
@@ -258,23 +255,27 @@ class VerifiedContract {
|
|
|
258
255
|
else {
|
|
259
256
|
const logs = transactionDetails.receipt.logs;
|
|
260
257
|
let reason = "";
|
|
261
|
-
const provider = this.contract.provider;
|
|
262
258
|
logs.map((log) => {
|
|
263
|
-
if (log.topics.includes(
|
|
264
|
-
|
|
265
|
-
|
|
259
|
+
if (log.topics.includes(constants_1.PaymasterConstants.BICONOMY_REVERT_TOPIC)) {
|
|
260
|
+
try {
|
|
261
|
+
reason = ethers_1.utils.formatBytes32String(log.data);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
reason = reason;
|
|
265
|
+
}
|
|
266
266
|
}
|
|
267
267
|
});
|
|
268
268
|
throw Error(`execution reverted: ${reason}`);
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
catch (err) {
|
|
272
|
-
console.
|
|
273
|
-
|
|
274
|
-
res.
|
|
275
|
-
res.
|
|
276
|
-
res.
|
|
277
|
-
|
|
272
|
+
console.error("gasless transaction failed with error: ", err);
|
|
273
|
+
console.log("will use ethers....");
|
|
274
|
+
// res.status = STATUS.ERROR;
|
|
275
|
+
// res.reason = err.reason;
|
|
276
|
+
// res.message = err.message;
|
|
277
|
+
// res.code = err.code;
|
|
278
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
278
279
|
}
|
|
279
280
|
}
|
|
280
281
|
async callContract(functionName, ...args) {
|
|
@@ -310,7 +311,15 @@ class VerifiedContract {
|
|
|
310
311
|
data: _res.data,
|
|
311
312
|
};
|
|
312
313
|
//build userop transaction
|
|
313
|
-
let partialUserOp
|
|
314
|
+
let partialUserOp;
|
|
315
|
+
try {
|
|
316
|
+
partialUserOp = await smartAccount.buildUserOp([tx1]);
|
|
317
|
+
}
|
|
318
|
+
catch (err) {
|
|
319
|
+
console.log("error while buiding gassless transaction: ", err);
|
|
320
|
+
console.log("will use ethers....");
|
|
321
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
322
|
+
}
|
|
314
323
|
//query paymaster for sponsored mode to get neccesary params and update userop
|
|
315
324
|
const biconomyPaymaster = smartAccount.paymaster;
|
|
316
325
|
try {
|
|
@@ -331,7 +340,7 @@ class VerifiedContract {
|
|
|
331
340
|
paymasterAndDataResponse.preVerificationGas;
|
|
332
341
|
}
|
|
333
342
|
}
|
|
334
|
-
return await this.callFunctionAsUserOp(smartAccount, partialUserOp);
|
|
343
|
+
return await this.callFunctionAsUserOp(smartAccount, partialUserOp, functionName, ...args);
|
|
335
344
|
}
|
|
336
345
|
catch (err) {
|
|
337
346
|
console.log("sponsored failed will try erc20");
|
|
@@ -341,7 +350,7 @@ class VerifiedContract {
|
|
|
341
350
|
//get fee quote for network cash token
|
|
342
351
|
const feeQuotesResponse = await biconomyPaymaster.getPaymasterFeeQuotesOrData(partialUserOp, {
|
|
343
352
|
mode: paymaster_1.PaymasterMode.ERC20,
|
|
344
|
-
tokenList: [
|
|
353
|
+
tokenList: [constants_1.PaymasterConstants[`${chainId}_CASH_TOKEN_ADDRESS`]],
|
|
345
354
|
});
|
|
346
355
|
// console.log("fq: ", feeQuotesResponse);
|
|
347
356
|
const feeQuotes = feeQuotesResponse.feeQuotes;
|
|
@@ -372,7 +381,7 @@ class VerifiedContract {
|
|
|
372
381
|
const _paymasterAndDataWithLimits = await biconomyPaymaster.getPaymasterAndData(finalUserOp, paymasterServiceData);
|
|
373
382
|
finalUserOp.paymasterAndData =
|
|
374
383
|
_paymasterAndDataWithLimits.paymasterAndData;
|
|
375
|
-
return await this.callFunctionAsUserOp(smartAccount, finalUserOp);
|
|
384
|
+
return await this.callFunctionAsUserOp(smartAccount, finalUserOp, functionName, ...args);
|
|
376
385
|
}
|
|
377
386
|
catch (_err) {
|
|
378
387
|
//if erc20 mode didn't work use ethers.js
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymasterConstants = void 0;
|
|
4
|
+
//Todo: add more network paymaster details for gasless
|
|
5
|
+
exports.PaymasterConstants = {
|
|
6
|
+
BUNDLER_URL_FIRST_SECTION: "https://bundler.biconomy.io/api/v2",
|
|
7
|
+
GENERAL_PAYMASTER_URL: "https://paymaster.biconomy.io/api/v1",
|
|
8
|
+
BICONOMY_REVERT_TOPIC: "0x1c4fada7374c0a9ee8841fc38afe82932dc0f8e69012e927f061a8bae611a201",
|
|
9
|
+
"11155111_PAYMASTER_API_KEY": "BuFP2-5w-.5b3daf3a-d044-4dda-819c-4c4d8431df88",
|
|
10
|
+
"11155111_URL_SECOND_SECTION": "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
|
|
11
|
+
// "137_PAYMASTER_API_KEY": "lDHvYk50N.30a2522e-0a9d-444b-b949-19194c1f237a",
|
|
12
|
+
// "137_URL_SECOND_SECTION": "dewj2189.wh1289hU-7E49-45ic-af80-JkuxGCYRV",
|
|
13
|
+
"80001_PAYMASTER_API_KEY": "3B83DXSwj.3b20bc68-6e09-4bf2-bff5-5a0d11989389",
|
|
14
|
+
"80001_URL_SECOND_SECTION": "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44"
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verified-network/verified-sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"description": "An SDK to develop applications on the Verified Network",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,12 +38,10 @@
|
|
|
38
38
|
"@biconomy/modules": "^3.1.1",
|
|
39
39
|
"@biconomy/paymaster": "^3.1.1",
|
|
40
40
|
"ethereumjs-tx": "^2.1.2",
|
|
41
|
-
"ethers": "^5.7.2"
|
|
42
|
-
"web3": "1.10.2"
|
|
41
|
+
"ethers": "^5.7.2"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/mocha": "^10.0.6",
|
|
46
|
-
"dotenv": "^10.0.0",
|
|
47
45
|
"mocha": "^10.2.0",
|
|
48
46
|
"ts-node": "^10.9.1",
|
|
49
47
|
"typescript": "^4.3.4"
|