-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug_web3.js
144 lines (110 loc) · 6.58 KB
/
debug_web3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const { network, configuration, user1, user2, tokens } = require("./config");
const { LxLyClient, use, Converter } = require("@maticnetwork/lxlyjs");
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3");
const HDWalletProvider = require("@truffle/hdwallet-provider");
use(Web3ClientPlugin);
const execute = async () => {
console.log("start executing");
const from = user1.address;
const to = user2.address;
const client = new LxLyClient();
await client.init({
log: true,
network: network,
providers: {
0: {
provider: new HDWalletProvider([user1.privateKey], configuration[0].rpc),
configuration: {
bridgeAddress: configuration[0].bridgeAddress,
wrapperAddress: configuration[0].wrapperAddress,
isEIP1559Supported: false
},
defaultConfig: {
from
}
},
1: {
provider: new HDWalletProvider([user1.privateKey], configuration[1].rpc),
configuration: {
bridgeAddress: configuration[1].bridgeAddress,
isEIP1559Supported: false
},
defaultConfig: {
from
}
}
}
});
const N0ERC20Token = client.erc20(tokens[0].erc20, 0);
const N0EtherToken = client.erc20(tokens[0].ether, 0);
const N1ERC20Token = client.erc20(tokens[1].erc20, 1);
const N1EtherToken = client.erc20(tokens[1].ether, 1);
// // getBalance on network 0
// console.log('balance of N0ERC20Token is', await N0ERC20Token.getBalance(from));
// getEtherBalance on network 0
console.log('balance of N0EtherToken is', await N0EtherToken.getBalance(from));
// // getBalance on network 1
// console.log('balance of N1ERC20Token is', await N1ERC20Token.getBalance(from));
// // getEtherBalance on network 1
// console.log('balance of N1EtherToken is', await N1EtherToken.getBalance(from));
// // Allowance ERC20 for 0
// var allowance = await N0ERC20Token.getAllowance(from);
// return console.log("allowance", allowance);
// // approve ERC20 for 0
// var tx = await N0ERC20Token.approve("100000000000000000000", {spenderAddress:"0x0f04f8434bac2e1db8fca8a34d3e177b6c7ccaba"});
// return console.log("approve txHash", await tx.getTransactionHash());
// // Bridge Ether from 0 to 1
// var tx = await N0EtherToken.bridgeAsset("100000000000000000", from, 1, {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // Bridge ERC20 from 0 to 1
// var tx = await N0ERC20Token.bridgeAsset("10000000000000000000", from, 1, {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // isBridgeClaimable
// var result = await client.isBridgeClaimable('0x15f028fc6b2e9aff6ada9fc557c9666b99c238ae9b24739770cab3ec532292e2', 1);
// return console.log('result', result);
// // isBridgeClaimed
// var result = await client.isBridged('0xdb4147ed0db73a52099b4136e39b9df4de92d74b5ecb864f367446baddbacdae', 0, 1);
// return console.log('result', result);
// // claim ETHER from 0 to 1
// var tx = await N1EtherToken.claimAsset('0xdb4147ed0db73a52099b4136e39b9df4de92d74b5ecb864f367446baddbacdae', 0, {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // Bridge ERC20 from 0 to 1 with gas
// var tx = await N0ERC20Token.bridgeAssetWithGas("10000000000000000000", from, '100000000000000000', 1, {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // Bridge Ether from 1 to 0
// var tx = await N1EtherToken.bridgeAsset("1000000000000000", from, 0, {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // claim ETHER from 1 to 0
// var tx = await N0EtherToken.claimAsset('0x15f028fc6b2e9aff6ada9fc557c9666b99c238ae9b24739770cab3ec532292e2', 1, {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // transfer ERC20
// var tx = await N0ERC20Token.transfer("1", to);
// return console.log("hash", await tx.getTransactionHash());
// // transfer Ether
// var tx = await N0EtherToken.transfer("1", to);
// return console.log("hash", await tx.getTransactionHash());
// // Get Permit Data
// var tx = await N0ERC20Token.getPermitData('2000000000000000000', {returnTransaction: false});
// return console.log("hash", tx);
// // bridge with Permit
// var tx = await N0ERC20Token.bridgeAssetWithPermit("10", from, 1, {returnTransaction: true});
// return console.log("hash", tx);
// // CUSTOM CONTRACT
// let abi = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"addValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"number","type":"uint256"}],"name":"addValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimableAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"drain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"randomValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"number","type":"uint256"}],"name":"randomValueByNumber","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"stateMutability":"payable","type":"receive"}]
// const customContract = client.contract(abi, "0xbe264257Be052BF867524D2640F6d5305d4263C8", 0);
// console.log('claimableAmount', await customContract.read('claimableAmount'))
// console.log('owner', await customContract.read('owner'))
// console.log('random value', await customContract.read('randomValue'))
// console.log('random value by number', await customContract.read('randomValueByNumber', 4))
// const tx = await customContract.write({returnTransaction: false}, 'addValue');
// console.log('addValue', await tx.getTransactionHash());
// const tx = await customContract.write({returnTransaction: false}, 'addValue', 3);
// // console.log('addValue', tx);
// console.log('addValue', await tx.getTransactionHash());
}
execute().then(_ => {
process.exit(0);
}).catch(err => {
console.error(err);
process.exit(0);
})