@verified-network/verified-sdk 1.3.8 → 1.4.0
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/contract/index.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
2
|
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
7
|
exports.VerifiedContract = exports.DATATYPES = void 0;
|
|
8
|
+
const dotenv_1 = require("dotenv");
|
|
5
9
|
const ethers_1 = require("ethers");
|
|
10
|
+
const web3_1 = __importDefault(require("web3"));
|
|
11
|
+
const account_1 = require("@biconomy/account");
|
|
12
|
+
const modules_1 = require("@biconomy/modules");
|
|
13
|
+
const bundler_1 = require("@biconomy/bundler");
|
|
14
|
+
const paymaster_1 = require("@biconomy/paymaster");
|
|
15
|
+
dotenv_1.config();
|
|
6
16
|
var STATUS;
|
|
7
17
|
(function (STATUS) {
|
|
8
18
|
STATUS[STATUS["SUCCESS"] = 0] = "SUCCESS";
|
|
@@ -132,7 +142,7 @@ class VerifiedContract {
|
|
|
132
142
|
*/
|
|
133
143
|
tempOutput(data) {
|
|
134
144
|
const response = { hash: '', result: [] };
|
|
135
|
-
data.forEach((element) => {
|
|
145
|
+
data.forEach(async (element) => {
|
|
136
146
|
if (element.hash !== undefined || element.transactionHash)
|
|
137
147
|
return response.hash = element.hash || element.transactionHash;
|
|
138
148
|
if (element._isBigNumber)
|
|
@@ -142,7 +152,7 @@ class VerifiedContract {
|
|
|
142
152
|
//if (utils.isBytesLike(element)) return response.result.push(this.sanitiseOutput(DATATYPES.BYTE32, element))
|
|
143
153
|
if (ethers_1.utils.isBytesLike(element))
|
|
144
154
|
return response.result.push(element);
|
|
145
|
-
if (typeof element === 'boolean' || (this.validateInput(DATATYPES.ADDRESS, element)))
|
|
155
|
+
if (typeof element === 'boolean' || (await this.validateInput(DATATYPES.ADDRESS, element)))
|
|
146
156
|
return response.result.push(element);
|
|
147
157
|
});
|
|
148
158
|
return response;
|
|
@@ -154,7 +164,47 @@ class VerifiedContract {
|
|
|
154
164
|
else
|
|
155
165
|
return [data];
|
|
156
166
|
}
|
|
157
|
-
|
|
167
|
+
/** Checks if a contract support gasless transaction */
|
|
168
|
+
supportsGasless(chainId) {
|
|
169
|
+
let isSupported = false;
|
|
170
|
+
const contractPaymasterUrl = process.env[`${chainId}_PAYMASTER_API_KEY`];
|
|
171
|
+
if (contractPaymasterUrl && contractPaymasterUrl.length > 0)
|
|
172
|
+
isSupported = true;
|
|
173
|
+
return isSupported;
|
|
174
|
+
}
|
|
175
|
+
/** Creates Biconomy smart account */
|
|
176
|
+
async createSmartAccount(chainId) {
|
|
177
|
+
//create bundler instance
|
|
178
|
+
const bundler = new bundler_1.Bundler({
|
|
179
|
+
bundlerUrl: `${process.env.BUNDLER_URL_FIRST_SECTION}/${chainId}/${process.env.BUNDLER_URL_SECTION_SECTION}`,
|
|
180
|
+
chainId: chainId,
|
|
181
|
+
entryPointAddress: account_1.DEFAULT_ENTRYPOINT_ADDRESS,
|
|
182
|
+
});
|
|
183
|
+
// console.log("bd: ", bundler);
|
|
184
|
+
//create paymaster instance
|
|
185
|
+
const paymaster = new paymaster_1.BiconomyPaymaster({
|
|
186
|
+
paymasterUrl: `${process.env.GENERAL_PAYMASTER_URL}/${chainId}/${process.env[`${chainId}_PAYMASTER_API_KEY`]}`,
|
|
187
|
+
});
|
|
188
|
+
// console.log("pm: ", paymaster);
|
|
189
|
+
const module = await modules_1.ECDSAOwnershipValidationModule.create({
|
|
190
|
+
signer: this.signer,
|
|
191
|
+
moduleAddress: modules_1.DEFAULT_ECDSA_OWNERSHIP_MODULE,
|
|
192
|
+
});
|
|
193
|
+
//create biconomy smart account
|
|
194
|
+
let biconomyAccount = await account_1.BiconomySmartAccountV2.create({
|
|
195
|
+
chainId: chainId,
|
|
196
|
+
bundler: bundler,
|
|
197
|
+
paymaster: paymaster,
|
|
198
|
+
entryPointAddress: account_1.DEFAULT_ENTRYPOINT_ADDRESS,
|
|
199
|
+
defaultValidationModule: module,
|
|
200
|
+
activeValidationModule: module,
|
|
201
|
+
});
|
|
202
|
+
// console.log("address", await biconomyAccount.getAccountAddress());
|
|
203
|
+
//return smart account
|
|
204
|
+
return biconomyAccount;
|
|
205
|
+
}
|
|
206
|
+
/** Constructs and call function with ethers.js */
|
|
207
|
+
async callFunctionWithEthers(functionName, ...args) {
|
|
158
208
|
let res = {};
|
|
159
209
|
try {
|
|
160
210
|
let options = [];
|
|
@@ -177,7 +227,7 @@ class VerifiedContract {
|
|
|
177
227
|
//console.log('_resp', _resp)
|
|
178
228
|
res.response = this.tempOutput(this.convertToArray(ethers_1.utils.deepCopy(_resp)));
|
|
179
229
|
res.status = STATUS.SUCCESS;
|
|
180
|
-
res.message =
|
|
230
|
+
res.message = "";
|
|
181
231
|
return res;
|
|
182
232
|
}
|
|
183
233
|
catch (error) {
|
|
@@ -189,6 +239,154 @@ class VerifiedContract {
|
|
|
189
239
|
return res;
|
|
190
240
|
}
|
|
191
241
|
}
|
|
242
|
+
/** Constructs and call function as userop for biconomy gassless(sponsored/erc20 mode) */
|
|
243
|
+
async callFunctionAsUserOp(smartAccount, userOp) {
|
|
244
|
+
//send userops transaction and construct transaction response
|
|
245
|
+
let res = {};
|
|
246
|
+
try {
|
|
247
|
+
const userOpResponse = await smartAccount.sendUserOp(userOp);
|
|
248
|
+
const transactionDetails = await userOpResponse.wait();
|
|
249
|
+
if (transactionDetails.success === "true") {
|
|
250
|
+
res.response = {
|
|
251
|
+
hash: transactionDetails.receipt.transactionHash,
|
|
252
|
+
result: [],
|
|
253
|
+
}; //TODO: update response
|
|
254
|
+
res.status = STATUS.SUCCESS;
|
|
255
|
+
res.message = "";
|
|
256
|
+
return res;
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
const logs = transactionDetails.receipt.logs;
|
|
260
|
+
let reason = "";
|
|
261
|
+
const provider = this.contract.provider;
|
|
262
|
+
logs.map((log) => {
|
|
263
|
+
if (log.topics.includes(process.env.BICONOMY_REVERT_TOPIC)) {
|
|
264
|
+
const web3 = new web3_1.default(provider);
|
|
265
|
+
reason = web3.utils.hexToAscii(log.data);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
throw Error(`execution reverted: ${reason}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
console.log(err);
|
|
273
|
+
res.status = STATUS.ERROR;
|
|
274
|
+
res.reason = err.reason;
|
|
275
|
+
res.message = err.message;
|
|
276
|
+
res.code = err.code;
|
|
277
|
+
return res;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
async callContract(functionName, ...args) {
|
|
281
|
+
const chainId = await this.signer.getChainId();
|
|
282
|
+
if (this.supportsGasless(chainId)) {
|
|
283
|
+
console.log("gassless supported will use userop");
|
|
284
|
+
//call contract through userop for gasless transaction
|
|
285
|
+
let options = [];
|
|
286
|
+
const totalArguments = args.length;
|
|
287
|
+
//reduce args to exclude options
|
|
288
|
+
if (totalArguments > 1)
|
|
289
|
+
options = args.splice(-1);
|
|
290
|
+
//console.log('options before', options);
|
|
291
|
+
if (options == 0)
|
|
292
|
+
options[0] = {};
|
|
293
|
+
//create smart account for signer
|
|
294
|
+
const smartAccount = await this.createSmartAccount(chainId);
|
|
295
|
+
const account = await smartAccount.getAccountAddress();
|
|
296
|
+
const signerAddress = await this.signer.getAddress();
|
|
297
|
+
//sanitize arguments to use smartaccount address
|
|
298
|
+
const newArgs = args.map((_arg) => {
|
|
299
|
+
if (typeof _arg === "string" &&
|
|
300
|
+
_arg.toLowerCase() === signerAddress.toLowerCase()) {
|
|
301
|
+
_arg = account;
|
|
302
|
+
}
|
|
303
|
+
return _arg;
|
|
304
|
+
});
|
|
305
|
+
//construct calldata for function
|
|
306
|
+
let fn = this.contract.populateTransaction[functionName];
|
|
307
|
+
let _res = await fn(...newArgs);
|
|
308
|
+
const tx1 = {
|
|
309
|
+
to: this.contract.address,
|
|
310
|
+
data: _res.data,
|
|
311
|
+
};
|
|
312
|
+
//build userop transaction
|
|
313
|
+
let partialUserOp = await smartAccount.buildUserOp([tx1]);
|
|
314
|
+
//query paymaster for sponsored mode to get neccesary params and update userop
|
|
315
|
+
const biconomyPaymaster = smartAccount.paymaster;
|
|
316
|
+
try {
|
|
317
|
+
const paymasterAndDataResponse = await biconomyPaymaster.getPaymasterAndData(partialUserOp, {
|
|
318
|
+
mode: paymaster_1.PaymasterMode.SPONSORED,
|
|
319
|
+
});
|
|
320
|
+
// console.log("pmR: ", paymasterAndDataResponse);
|
|
321
|
+
if (paymasterAndDataResponse) {
|
|
322
|
+
partialUserOp.paymasterAndData =
|
|
323
|
+
paymasterAndDataResponse.paymasterAndData;
|
|
324
|
+
if (paymasterAndDataResponse.callGasLimit &&
|
|
325
|
+
paymasterAndDataResponse.verificationGasLimit &&
|
|
326
|
+
paymasterAndDataResponse.preVerificationGas) {
|
|
327
|
+
partialUserOp.callGasLimit = paymasterAndDataResponse.callGasLimit;
|
|
328
|
+
partialUserOp.verificationGasLimit =
|
|
329
|
+
paymasterAndDataResponse.verificationGasLimit;
|
|
330
|
+
partialUserOp.preVerificationGas =
|
|
331
|
+
paymasterAndDataResponse.preVerificationGas;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return await this.callFunctionAsUserOp(smartAccount, partialUserOp);
|
|
335
|
+
}
|
|
336
|
+
catch (err) {
|
|
337
|
+
console.log("sponsored failed will try erc20");
|
|
338
|
+
//if userop can't be sponsored use ERC20 mode
|
|
339
|
+
try {
|
|
340
|
+
let finalUserOp = partialUserOp;
|
|
341
|
+
//get fee quote for network cash token
|
|
342
|
+
const feeQuotesResponse = await biconomyPaymaster.getPaymasterFeeQuotesOrData(partialUserOp, {
|
|
343
|
+
mode: paymaster_1.PaymasterMode.ERC20,
|
|
344
|
+
tokenList: [process.env[`${chainId}_CASH_TOKEN_ADDRESS`]],
|
|
345
|
+
});
|
|
346
|
+
// console.log("fq: ", feeQuotesResponse);
|
|
347
|
+
const feeQuotes = feeQuotesResponse.feeQuotes;
|
|
348
|
+
const spender = feeQuotesResponse.tokenPaymasterAddress || "";
|
|
349
|
+
const tokenFeeQuotes = feeQuotes[0];
|
|
350
|
+
finalUserOp = await smartAccount.buildTokenPaymasterUserOp(partialUserOp, {
|
|
351
|
+
feeQuote: tokenFeeQuotes,
|
|
352
|
+
spender: spender,
|
|
353
|
+
maxApproval: false,
|
|
354
|
+
});
|
|
355
|
+
let paymasterServiceData = {
|
|
356
|
+
mode: paymaster_1.PaymasterMode.ERC20,
|
|
357
|
+
feeTokenAddress: tokenFeeQuotes.tokenAddress,
|
|
358
|
+
calculateGasLimits: true,
|
|
359
|
+
};
|
|
360
|
+
const paymasterAndDataWithLimits = await biconomyPaymaster.getPaymasterAndData(finalUserOp, paymasterServiceData);
|
|
361
|
+
finalUserOp.paymasterAndData =
|
|
362
|
+
paymasterAndDataWithLimits.paymasterAndData;
|
|
363
|
+
if (paymasterAndDataWithLimits.callGasLimit &&
|
|
364
|
+
paymasterAndDataWithLimits.verificationGasLimit &&
|
|
365
|
+
paymasterAndDataWithLimits.preVerificationGas) {
|
|
366
|
+
finalUserOp.callGasLimit = paymasterAndDataWithLimits.callGasLimit;
|
|
367
|
+
finalUserOp.verificationGasLimit =
|
|
368
|
+
paymasterAndDataWithLimits.verificationGasLimit;
|
|
369
|
+
finalUserOp.preVerificationGas =
|
|
370
|
+
paymasterAndDataWithLimits.preVerificationGas;
|
|
371
|
+
}
|
|
372
|
+
const _paymasterAndDataWithLimits = await biconomyPaymaster.getPaymasterAndData(finalUserOp, paymasterServiceData);
|
|
373
|
+
finalUserOp.paymasterAndData =
|
|
374
|
+
_paymasterAndDataWithLimits.paymasterAndData;
|
|
375
|
+
return await this.callFunctionAsUserOp(smartAccount, finalUserOp);
|
|
376
|
+
}
|
|
377
|
+
catch (_err) {
|
|
378
|
+
//if erc20 mode didn't work use ethers.js
|
|
379
|
+
console.log("both sponsored and erc20 failed will use ethers: ");
|
|
380
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
//call contract through normal ether.js
|
|
386
|
+
console.log("gassless not supported will use ethers");
|
|
387
|
+
return await this.callFunctionWithEthers(functionName, ...args);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
192
390
|
getEvent(eventName, callback) {
|
|
193
391
|
let res = {};
|
|
194
392
|
this.contract.once(eventName, (...data) => {
|
|
@@ -7,6 +7,25 @@ const Security_json_1 = require("../../abi/securities/Security.json");
|
|
|
7
7
|
var FUNCTIONS;
|
|
8
8
|
(function (FUNCTIONS) {
|
|
9
9
|
FUNCTIONS["WHITELIST"] = "whiteList";
|
|
10
|
+
FUNCTIONS["TRANSFER"] = "transfer";
|
|
11
|
+
FUNCTIONS["APPROVE"] = "approve";
|
|
12
|
+
FUNCTIONS["TRANSFERFROM"] = "transferFrom";
|
|
13
|
+
FUNCTIONS["INCREASEALLOWANCE"] = "increaseAllowance";
|
|
14
|
+
FUNCTIONS["DECREASEALLOWANCE"] = "decreaseAllowance";
|
|
15
|
+
FUNCTIONS["FREEZE"] = "freeze";
|
|
16
|
+
FUNCTIONS["UNFREEZE"] = "unfreeze";
|
|
17
|
+
FUNCTIONS["FROZEN"] = "frozen";
|
|
18
|
+
FUNCTIONS["BURN"] = "burn";
|
|
19
|
+
FUNCTIONS["BURNALL"] = "burnAll";
|
|
20
|
+
FUNCTIONS["SCHEDULE"] = "scheduleSnapshot";
|
|
21
|
+
FUNCTIONS["RESCHEDULE"] = "rescheduleSnapshot";
|
|
22
|
+
FUNCTIONS["UNSCHEDULE"] = "unscheduleSnapshot";
|
|
23
|
+
FUNCTIONS["CREATERESOLUTION"] = "createResolution";
|
|
24
|
+
FUNCTIONS["COUNTVOTES"] = "countVotes";
|
|
25
|
+
FUNCTIONS["PAYOUTPRORATA"] = "payoutProrata";
|
|
26
|
+
FUNCTIONS["PAYOUT"] = "payout";
|
|
27
|
+
FUNCTIONS["PAUSE"] = "pause";
|
|
28
|
+
FUNCTIONS["UNPAUSE"] = "unpause";
|
|
10
29
|
})(FUNCTIONS || (FUNCTIONS = {}));
|
|
11
30
|
class Security extends index_1.VerifiedContract {
|
|
12
31
|
constructor(signer, tokenAddress) {
|
|
@@ -19,5 +38,96 @@ class Security extends index_1.VerifiedContract {
|
|
|
19
38
|
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
20
39
|
return this.callContract(FUNCTIONS.WHITELIST, _spender, _amount, options);
|
|
21
40
|
}
|
|
41
|
+
async transfer(_recipient, _amount, options) {
|
|
42
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _recipient);
|
|
43
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
44
|
+
return this.callContract(FUNCTIONS.TRANSFER, _recipient, _amount, options);
|
|
45
|
+
}
|
|
46
|
+
async approve(_spender, _amount, options) {
|
|
47
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _spender);
|
|
48
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
49
|
+
return this.callContract(FUNCTIONS.APPROVE, _spender, _amount, options);
|
|
50
|
+
}
|
|
51
|
+
async transferFrom(_spender, _recipient, _amount, options) {
|
|
52
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _spender);
|
|
53
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _recipient);
|
|
54
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
55
|
+
return this.callContract(FUNCTIONS.TRANSFERFROM, _spender, _recipient, _amount, options);
|
|
56
|
+
}
|
|
57
|
+
async increaseAllowance(_spender, _amount, options) {
|
|
58
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _spender);
|
|
59
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
60
|
+
return this.callContract(FUNCTIONS.INCREASEALLOWANCE, _spender, _amount, options);
|
|
61
|
+
}
|
|
62
|
+
async decreaseAllowance(_spender, _amount, options) {
|
|
63
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _spender);
|
|
64
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
65
|
+
return this.callContract(FUNCTIONS.DECREASEALLOWANCE, _spender, _amount, options);
|
|
66
|
+
}
|
|
67
|
+
async freeze(_holder, _amount, options) {
|
|
68
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _holder);
|
|
69
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
70
|
+
return this.callContract(FUNCTIONS.FREEZE, _holder, _amount, options);
|
|
71
|
+
}
|
|
72
|
+
async unfreeze(_holder, options) {
|
|
73
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _holder);
|
|
74
|
+
return this.callContract(FUNCTIONS.UNFREEZE, _holder, options);
|
|
75
|
+
}
|
|
76
|
+
async frozen(_account, options) {
|
|
77
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _holder);
|
|
78
|
+
return this.callContract(FUNCTIONS.FROZEN, _account, options);
|
|
79
|
+
}
|
|
80
|
+
async burn(_holder, _amount, options) {
|
|
81
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _holder);
|
|
82
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
83
|
+
return this.callContract(FUNCTIONS.BURN, _holder, _amount, options);
|
|
84
|
+
}
|
|
85
|
+
async burnAll(options) {
|
|
86
|
+
return this.callContract(FUNCTIONS.BURNALL, options);
|
|
87
|
+
}
|
|
88
|
+
async schedule(_time, options) {
|
|
89
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _time);
|
|
90
|
+
return this.callContract(FUNCTIONS.SCHEDULE, _time, options);
|
|
91
|
+
}
|
|
92
|
+
async reschedule(_oldtime, _newtime, options) {
|
|
93
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _oldtime);
|
|
94
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _newtime);
|
|
95
|
+
return this.callContract(FUNCTIONS.RESCHEDULE, _oldtime, _newtime, options);
|
|
96
|
+
}
|
|
97
|
+
async unschedule(_time, options) {
|
|
98
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _time);
|
|
99
|
+
return this.callContract(FUNCTIONS.UNSCHEDULE, _time, options);
|
|
100
|
+
}
|
|
101
|
+
async createResolution(_time, _votes, _ipfslink, options) {
|
|
102
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _time);
|
|
103
|
+
await this.validateInput(index_1.DATATYPES.BOOLEAN, _votes);
|
|
104
|
+
await this.validateInput(index_1.DATATYPES.STRING, _ipfslink);
|
|
105
|
+
return this.callContract(FUNCTIONS.CREATERESOLUTION, _time, _votes, _ipfslink, options);
|
|
106
|
+
}
|
|
107
|
+
async countVotes(_time, options) {
|
|
108
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _time);
|
|
109
|
+
return this.callContract(FUNCTIONS.COUNTVOTES, _time, options);
|
|
110
|
+
}
|
|
111
|
+
async payoutProrata(_time, _wallet, _token, _amount, options) {
|
|
112
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _time);
|
|
113
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _wallet);
|
|
114
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _token);
|
|
115
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
116
|
+
return this.callContract(FUNCTIONS.PAYOUTPRORATA, _time, _wallet, _token, _amount, options);
|
|
117
|
+
}
|
|
118
|
+
async payout(_time, _holder, _wallet, _token, _amount, options) {
|
|
119
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _time);
|
|
120
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _holder);
|
|
121
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _wallet);
|
|
122
|
+
await this.validateInput(index_1.DATATYPES.ADDRESS, _token);
|
|
123
|
+
await this.validateInput(index_1.DATATYPES.NUMBER, _amount);
|
|
124
|
+
return this.callContract(FUNCTIONS.PAYOUT, _time, _holder, _wallet, _token, _amount, options);
|
|
125
|
+
}
|
|
126
|
+
async pause(options) {
|
|
127
|
+
return this.callContract(FUNCTIONS.PAUSE, options);
|
|
128
|
+
}
|
|
129
|
+
async unpause(options) {
|
|
130
|
+
return this.callContract(FUNCTIONS.UNPAUSE, options);
|
|
131
|
+
}
|
|
22
132
|
}
|
|
23
133
|
exports.default = Security;
|
|
@@ -69,6 +69,40 @@ const contractAddress = {
|
|
|
69
69
|
'VBINR': ''
|
|
70
70
|
},
|
|
71
71
|
},
|
|
72
|
+
80001: {
|
|
73
|
+
'Client': '0x8009B03BbaBD09B9C1EADCaBC7D27197AC251F44',
|
|
74
|
+
'Factory': '0xaE16E00380450617E7D96Bdee3c242a8a83CF474',
|
|
75
|
+
'Cash': '0xE6aF6F4d0DD2c4d6F46cdF02be016d7352AF8594',
|
|
76
|
+
'Bond': '0x035ad7060e366e7d619d3394d667c4F9Fa8fbFFc',
|
|
77
|
+
'Token': '0x937d8b7A5b36E3573f4B909D742A1afc46998914',
|
|
78
|
+
'Oracle': '0x3d85758f26866D0D0cd7f3a8f4740cCfE341CBf3',
|
|
79
|
+
'Rates': '0xFA674a58063bAfD52ce5981DB137B01c2504B312',
|
|
80
|
+
'Security': '0x2D76FE6DdC229a482eDeb6E86d12c733A05Af55b',
|
|
81
|
+
'SecuritiesFactory': '0xf1f349C2CBDA5BCAfD7F95b20C812b4A17c9333D',
|
|
82
|
+
'Vitta': '0x2D5d7F6a1065C1D47c333cacb0ea02f4e25c268C',
|
|
83
|
+
'Liquidity': '0x9322e3002403C6f13d567d85FF72eC69733a57ab',
|
|
84
|
+
'Distribution': '0x009B5BAd3C3b8E58f71321e149b22F2Ae080089a',
|
|
85
|
+
'PrimaryIssuePoolFactory': '',
|
|
86
|
+
'BalancerPrimaryIssueManager': '',
|
|
87
|
+
'SecondaryIssuePoolFactory': '',
|
|
88
|
+
'BalancerSecondaryIssueManager': '',
|
|
89
|
+
'MarginTradingPoolFactory': '',
|
|
90
|
+
'BalancerMarginIssueManager': '',
|
|
91
|
+
'Custody': '0x27006b68b3594EF5Ae04C5457c24F0c7CF1E5553',
|
|
92
|
+
'Compound': '',
|
|
93
|
+
'CASH': {
|
|
94
|
+
'VCUSD': '0x2643ea32A3c231327556739C2a88C1eA943A90A9',
|
|
95
|
+
'VCEUR': '0x8D7365d51D6e2fF6BffEa00FDacdd96f86d147A0',
|
|
96
|
+
'VCCHF': '0x1b2f81171300f3DCF70F2A3BC90fc307588212fC',
|
|
97
|
+
'VCINR': '0x515bC2e51B0824759B3A64fD3659CCC5c8E35D96'
|
|
98
|
+
},
|
|
99
|
+
'BOND': {
|
|
100
|
+
'VBUSD': '0x55E7F13020F85bA8855c0639fD384e2CF319E30A',
|
|
101
|
+
'VBEUR': '0x00A4eF03Dd625F5778e2a17407952444B3A97008',
|
|
102
|
+
'VCCHF': '0x0f2570339af7896f78a47730386d51d8CBDD8D0F',
|
|
103
|
+
'VBINR': '0xFe83AD465cD61FE8f82241b23199043f41079109'
|
|
104
|
+
},
|
|
105
|
+
},
|
|
72
106
|
137: {
|
|
73
107
|
'Client': '0x2C5718206b37b8744784ce44f374DE13dd7BC2d1',
|
|
74
108
|
'Factory': '',
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("../utils/index");
|
|
4
|
+
const index_2 = require("../wallet/index");
|
|
5
|
+
const index_3 = require("../index");
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
7
|
+
const testSecurityFactoryIssueProduct = async (securityFactoryAddress) => {
|
|
8
|
+
const INFURA_API_KEY = "95c1322d7c0e44de9ea77cc9eea18534";
|
|
9
|
+
const SECURITY_HOLDER_MNEMONICS = "correct galaxy various swap chair assault blue improve ivory pear infant oak";
|
|
10
|
+
const sender = index_2.VerifiedWallet.importWallet(SECURITY_HOLDER_MNEMONICS);
|
|
11
|
+
const signer = sender.setProvider(index_1.Provider.infuraProvider(80001, INFURA_API_KEY));
|
|
12
|
+
const securityFactoryContract = new index_3.SecuritiesFactory(signer, securityFactoryAddress);
|
|
13
|
+
const zeroAddress = "0x0000000000000000000000000000000000000000";
|
|
14
|
+
const BTCShortBytes = "0x425443";
|
|
15
|
+
const currency = "0x07865c6E87B9F70255377e024ace6630C1Eaa37F"; //usdc
|
|
16
|
+
const defaultBytes = "0x4346440000000000000000000000000000000000000000000000000000000000";
|
|
17
|
+
const indiaBytes = "0x496e646961000000000000000000000000000000000000000000000000000000";
|
|
18
|
+
const restrictions = [];
|
|
19
|
+
const abiCoder = ethers_1.ethers.utils.defaultAbiCoder;
|
|
20
|
+
const encodedArray = abiCoder.encode(["bytes32[]"], [restrictions]);
|
|
21
|
+
await securityFactoryContract
|
|
22
|
+
.issueSecurity(zeroAddress, defaultBytes, BTCShortBytes, BTCShortBytes, currency, sender.address, sender.address, encodedArray, indiaBytes, "false")
|
|
23
|
+
.then(async (res) => {
|
|
24
|
+
console.log("Security Issued Succesfully with hash: ", res.response.hash);
|
|
25
|
+
securityFactoryContract.notifySecuritiesAdded(async (evnt) => {
|
|
26
|
+
const security = evnt.response.result[0];
|
|
27
|
+
console.log("added security : ", security, "succesfully");
|
|
28
|
+
if (security) {
|
|
29
|
+
await securityFactoryContract
|
|
30
|
+
.addBalance(security, zeroAddress, sender.address, "1000000000000000000000000")
|
|
31
|
+
.then(async (_res) => {
|
|
32
|
+
console.log("Security Minted succesfully with hash: ", _res.response.hash);
|
|
33
|
+
})
|
|
34
|
+
.catch((_err) => {
|
|
35
|
+
console.error("Mint security failed with error: ", _err);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
})
|
|
40
|
+
.catch((err) => {
|
|
41
|
+
console.error("issueSecurity failed with error: ", err);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
testSecurityFactoryIssueProduct("0xf1f349C2CBDA5BCAfD7F95b20C812b4A17c9333D");
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("../utils/index");
|
|
4
|
+
const index_2 = require("../wallet/index");
|
|
5
|
+
const index_3 = require("../index");
|
|
6
|
+
const testSecurityTransfer = async (securityAddress, amount, receiverAddress) => {
|
|
7
|
+
const INFURA_API_KEY = "95c1322d7c0e44de9ea77cc9eea18534";
|
|
8
|
+
const SECURITY_HOLDER_MNEMONICS = "correct galaxy various swap chair assault blue improve ivory pear infant oak";
|
|
9
|
+
const sender = index_2.VerifiedWallet.importWallet(SECURITY_HOLDER_MNEMONICS);
|
|
10
|
+
const signer = sender.setProvider(index_1.Provider.infuraProvider(80001, INFURA_API_KEY));
|
|
11
|
+
const securityContract = new index_3.Security(signer, securityAddress);
|
|
12
|
+
await securityContract
|
|
13
|
+
.transfer(receiverAddress, amount)
|
|
14
|
+
.then((res) => {
|
|
15
|
+
console.log("Transfer succesful with hash: ", res.response.hash);
|
|
16
|
+
})
|
|
17
|
+
.catch((err) => {
|
|
18
|
+
console.log("Transfer failed with error: ", err);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
// testSecurityTransfer(
|
|
22
|
+
// "0xd7252bfa14C0Dca5A72d90a28Bb513E0f989Ee1e",
|
|
23
|
+
// 1000000000000000000n,
|
|
24
|
+
// "0x286a759DACfd0C533B88E42b9e7571040008D778"
|
|
25
|
+
// );
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verified-network/verified-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "An SDK to develop applications on the Verified Network",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,18 +25,27 @@
|
|
|
25
25
|
"build": "tsc",
|
|
26
26
|
"dev": "tsc && npm link",
|
|
27
27
|
"publish": "tsc && npm publish",
|
|
28
|
-
"test": "mocha"
|
|
28
|
+
"test": "mocha 'src/test/**/*.ts' --recursive --timeout 300000 -r ts-node/register"
|
|
29
29
|
},
|
|
30
30
|
"bin": {
|
|
31
31
|
"greet": "./bin/index.bin.js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@biconomy/account": "^3.1.1",
|
|
35
|
+
"@biconomy/bundler": "^3.1.1",
|
|
36
|
+
"@biconomy/common": "^3.1.1",
|
|
37
|
+
"@biconomy/core-types": "^3.1.1",
|
|
38
|
+
"@biconomy/modules": "^3.1.1",
|
|
39
|
+
"@biconomy/paymaster": "^3.1.1",
|
|
34
40
|
"ethereumjs-tx": "^2.1.2",
|
|
35
|
-
"ethers": "^5.
|
|
41
|
+
"ethers": "^5.7.2",
|
|
42
|
+
"web3": "1.10.2"
|
|
36
43
|
},
|
|
37
44
|
"devDependencies": {
|
|
45
|
+
"@types/mocha": "^10.0.6",
|
|
38
46
|
"dotenv": "^10.0.0",
|
|
39
|
-
"mocha": "^
|
|
47
|
+
"mocha": "^10.2.0",
|
|
48
|
+
"ts-node": "^10.9.1",
|
|
40
49
|
"typescript": "^4.3.4"
|
|
41
50
|
}
|
|
42
51
|
}
|
package/tsconfig.json
CHANGED
|
@@ -47,7 +47,10 @@
|
|
|
47
47
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
48
48
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
49
49
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
50
|
-
|
|
50
|
+
"typeRoots": [
|
|
51
|
+
"./node_modules/@types",
|
|
52
|
+
"./node_modules/@0x/typescript-typings/types"
|
|
53
|
+
], /* List of folders to include type definitions from. */
|
|
51
54
|
// "types": [], /* Type declaration files to be included in compilation. */
|
|
52
55
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
53
56
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
@@ -63,7 +66,7 @@
|
|
|
63
66
|
/* Experimental Options */
|
|
64
67
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
65
68
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
66
|
-
|
|
69
|
+
|
|
67
70
|
/* Advanced Options */
|
|
68
71
|
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
69
72
|
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|