@verified-network/verified-sdk 1.5.6 → 1.5.7
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 +90 -8
- package/dist/contract/index.js +30 -19
- package/dist/utils/constants.js +13 -0
- package/package.json +1 -1
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 = 'ropsten' // or any other network of your choice.
|
|
27
|
+
const defaultProvider = 'ropsten' // 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 = 3 // where number 3 is chain id for ropsten, 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 = 'ropsten' // 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 = 3 // where number 3 is chain id for ropsten, 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,45 @@ 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
|
+
# Verified Sdk also provides ERC 4337-compliant solution and enable account abstraction using Biconomy Smart Accounts.
|
|
121
|
+
|
|
122
|
+
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
|
|
123
|
+
|
|
124
|
+
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.
|
|
125
|
+
|
|
126
|
+
# How Verified Sdk Gasless transactions work
|
|
127
|
+
|
|
128
|
+
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.
|
|
129
|
+
|
|
130
|
+
# Verified Sdk checks for every transaction:
|
|
131
|
+
|
|
132
|
+
# Check 1: is Biconomy Paymaster supported for the network/chain the contract is on?
|
|
133
|
+
If yes:
|
|
134
|
+
# Check 2: is the smart contract called part of smart contracts that support gasless or Erc 20 gas payments?
|
|
135
|
+
If yes:
|
|
136
|
+
# Check 3: is the function called parts of functions selected to support gasless or ERC 20 payments?
|
|
137
|
+
If yes:
|
|
138
|
+
# Check 4: what type of paymaster was set? Gasless or ERC 20
|
|
139
|
+
If gasless:
|
|
140
|
+
# Check 5: is the deposited gas enough to pay for transaction?
|
|
141
|
+
if yes: Transaction is sposored(user does not pay for gas fee)
|
|
142
|
+
if ERC 20:
|
|
143
|
+
# User pay for transaction using ERC 20 tokens
|
|
144
|
+
# If no: User will pay for transaction using native tokens(Eth, Matic e.t.c)
|
package/dist/contract/index.js
CHANGED
|
@@ -6,13 +6,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.VerifiedContract = exports.DATATYPES = void 0;
|
|
8
8
|
const dotenv_1 = require("dotenv");
|
|
9
|
+
dotenv_1.config({ path: "../../.env" });
|
|
9
10
|
const ethers_1 = require("ethers");
|
|
10
11
|
const web3_1 = __importDefault(require("web3"));
|
|
11
12
|
const account_1 = require("@biconomy/account");
|
|
12
13
|
const modules_1 = require("@biconomy/modules");
|
|
13
14
|
const bundler_1 = require("@biconomy/bundler");
|
|
14
15
|
const paymaster_1 = require("@biconomy/paymaster");
|
|
15
|
-
|
|
16
|
+
const constants_1 = require("../utils/constants");
|
|
16
17
|
var STATUS;
|
|
17
18
|
(function (STATUS) {
|
|
18
19
|
STATUS[STATUS["SUCCESS"] = 0] = "SUCCESS";
|
|
@@ -143,17 +144,25 @@ class VerifiedContract {
|
|
|
143
144
|
tempOutput(data) {
|
|
144
145
|
const response = { hash: '', result: [] };
|
|
145
146
|
data.forEach(async (element) => {
|
|
146
|
-
if (element.hash !== undefined || element.transactionHash)
|
|
147
|
+
if (element.hash !== undefined || element.transactionHash) {
|
|
147
148
|
return response.hash = element.hash || element.transactionHash;
|
|
148
|
-
|
|
149
|
+
}
|
|
150
|
+
else if (element._isBigNumber) {
|
|
149
151
|
return response.result.push(element.toString());
|
|
150
|
-
|
|
152
|
+
}
|
|
153
|
+
else if (ethers_1.utils.isAddress(element)) {
|
|
151
154
|
return response.result.push(element);
|
|
155
|
+
}
|
|
152
156
|
//if (utils.isBytesLike(element)) return response.result.push(this.sanitiseOutput(DATATYPES.BYTE32, element))
|
|
153
|
-
if (ethers_1.utils.isBytesLike(element))
|
|
157
|
+
else if (ethers_1.utils.isBytesLike(element)) {
|
|
154
158
|
return response.result.push(element);
|
|
155
|
-
|
|
159
|
+
}
|
|
160
|
+
else if (typeof element === 'boolean') {
|
|
161
|
+
return response.result.push(element);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
156
164
|
return response.result.push(element);
|
|
165
|
+
}
|
|
157
166
|
});
|
|
158
167
|
return response;
|
|
159
168
|
}
|
|
@@ -167,7 +176,7 @@ class VerifiedContract {
|
|
|
167
176
|
/** Checks if a contract support gasless transaction */
|
|
168
177
|
supportsGasless(chainId) {
|
|
169
178
|
let isSupported = false;
|
|
170
|
-
const contractPaymasterUrl =
|
|
179
|
+
const contractPaymasterUrl = constants_1.PaymasterConstants[`${chainId}_PAYMASTER_API_KEY`];
|
|
171
180
|
if (contractPaymasterUrl && contractPaymasterUrl.length > 0)
|
|
172
181
|
isSupported = true;
|
|
173
182
|
return isSupported;
|
|
@@ -176,16 +185,14 @@ class VerifiedContract {
|
|
|
176
185
|
async createSmartAccount(chainId) {
|
|
177
186
|
//create bundler instance
|
|
178
187
|
const bundler = new bundler_1.Bundler({
|
|
179
|
-
bundlerUrl: `${
|
|
188
|
+
bundlerUrl: `${constants_1.PaymasterConstants.BUNDLER_URL_FIRST_SECTION}/${chainId}/${constants_1.PaymasterConstants.BUNDLER_URL_SECTION_SECTION}`,
|
|
180
189
|
chainId: chainId,
|
|
181
190
|
entryPointAddress: account_1.DEFAULT_ENTRYPOINT_ADDRESS,
|
|
182
191
|
});
|
|
183
|
-
// console.log("bd: ", bundler);
|
|
184
192
|
//create paymaster instance
|
|
185
193
|
const paymaster = new paymaster_1.BiconomyPaymaster({
|
|
186
|
-
paymasterUrl: `${
|
|
194
|
+
paymasterUrl: `${constants_1.PaymasterConstants.GENERAL_PAYMASTER_URL}/${chainId}/${constants_1.PaymasterConstants[`${chainId}_PAYMASTER_API_KEY`]}`,
|
|
187
195
|
});
|
|
188
|
-
// console.log("pm: ", paymaster);
|
|
189
196
|
const module = await modules_1.ECDSAOwnershipValidationModule.create({
|
|
190
197
|
signer: this.signer,
|
|
191
198
|
moduleAddress: modules_1.DEFAULT_ECDSA_OWNERSHIP_MODULE,
|
|
@@ -200,7 +207,6 @@ class VerifiedContract {
|
|
|
200
207
|
activeValidationModule: module,
|
|
201
208
|
});
|
|
202
209
|
// console.log("address", await biconomyAccount.getAccountAddress());
|
|
203
|
-
//return smart account
|
|
204
210
|
return biconomyAccount;
|
|
205
211
|
}
|
|
206
212
|
/** Constructs and call function with ethers.js */
|
|
@@ -221,10 +227,7 @@ class VerifiedContract {
|
|
|
221
227
|
*/
|
|
222
228
|
let fn = this.contract[functionName];
|
|
223
229
|
let _res = await fn(...args, ...options);
|
|
224
|
-
//console.log('_res', _res)
|
|
225
|
-
//console.log('_res.value.toString()',_res.value.toString())
|
|
226
230
|
let _resp = _res.wait !== undefined ? await _res.wait(_res) : _res;
|
|
227
|
-
//console.log('_resp', _resp)
|
|
228
231
|
res.response = this.tempOutput(this.convertToArray(ethers_1.utils.deepCopy(_resp)));
|
|
229
232
|
res.status = STATUS.SUCCESS;
|
|
230
233
|
res.message = "";
|
|
@@ -250,7 +253,7 @@ class VerifiedContract {
|
|
|
250
253
|
res.response = {
|
|
251
254
|
hash: transactionDetails.receipt.transactionHash,
|
|
252
255
|
result: [],
|
|
253
|
-
}; //TODO: update response
|
|
256
|
+
}; //TODO: update result on response
|
|
254
257
|
res.status = STATUS.SUCCESS;
|
|
255
258
|
res.message = "";
|
|
256
259
|
return res;
|
|
@@ -260,7 +263,7 @@ class VerifiedContract {
|
|
|
260
263
|
let reason = "";
|
|
261
264
|
const provider = this.contract.provider;
|
|
262
265
|
logs.map((log) => {
|
|
263
|
-
if (log.topics.includes(
|
|
266
|
+
if (log.topics.includes(constants_1.PaymasterConstants.BICONOMY_REVERT_TOPIC)) {
|
|
264
267
|
const web3 = new web3_1.default(provider);
|
|
265
268
|
reason = web3.utils.hexToAscii(log.data);
|
|
266
269
|
}
|
|
@@ -310,7 +313,15 @@ class VerifiedContract {
|
|
|
310
313
|
data: _res.data,
|
|
311
314
|
};
|
|
312
315
|
//build userop transaction
|
|
313
|
-
let partialUserOp
|
|
316
|
+
let partialUserOp;
|
|
317
|
+
try {
|
|
318
|
+
partialUserOp = await smartAccount.buildUserOp([tx1]);
|
|
319
|
+
}
|
|
320
|
+
catch (err) {
|
|
321
|
+
console.log("error while buiding gassless transaction: ", err);
|
|
322
|
+
console.log("will use ethers....");
|
|
323
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
324
|
+
}
|
|
314
325
|
//query paymaster for sponsored mode to get neccesary params and update userop
|
|
315
326
|
const biconomyPaymaster = smartAccount.paymaster;
|
|
316
327
|
try {
|
|
@@ -341,7 +352,7 @@ class VerifiedContract {
|
|
|
341
352
|
//get fee quote for network cash token
|
|
342
353
|
const feeQuotesResponse = await biconomyPaymaster.getPaymasterFeeQuotesOrData(partialUserOp, {
|
|
343
354
|
mode: paymaster_1.PaymasterMode.ERC20,
|
|
344
|
-
tokenList: [
|
|
355
|
+
tokenList: [constants_1.PaymasterConstants[`${chainId}_CASH_TOKEN_ADDRESS`]],
|
|
345
356
|
});
|
|
346
357
|
// console.log("fq: ", feeQuotesResponse);
|
|
347
358
|
const feeQuotes = feeQuotesResponse.feeQuotes;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
BUNDLER_URL_SECTION_SECTION: "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
|
|
8
|
+
GENERAL_PAYMASTER_URL: "https://paymaster.biconomy.io/api/v1",
|
|
9
|
+
BICONOMY_REVERT_TOPIC: "0x1c4fada7374c0a9ee8841fc38afe82932dc0f8e69012e927f061a8bae611a201",
|
|
10
|
+
"11155111_PAYMASTER_API_KEY": "BuFP2-5w-.5b3daf3a-d044-4dda-819c-4c4d8431df88",
|
|
11
|
+
"137_PAYMASTER_API_KEY": "lDHvYk50N.30a2522e-0a9d-444b-b949-19194c1f237a",
|
|
12
|
+
"80001_PAYMASTER_API_KEY": "3B83DXSwj.3b20bc68-6e09-4bf2-bff5-5a0d11989389"
|
|
13
|
+
};
|