-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb3.ts
More file actions
63 lines (52 loc) · 1.8 KB
/
web3.ts
File metadata and controls
63 lines (52 loc) · 1.8 KB
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
import * as ethers from 'ethers';
import Web3 from 'web3';
import { log } from '@arken/node/log';
import HDWalletProvider from '@truffle/hdwallet-provider';
import { getAddress, getRandomProvider } from '@arken/node/web3';
import contractInfo from '@arken/node/legacy/contractInfo';
import BEP20Contract from '@arken/node/legacy/contracts/BEP20.json';
function _initProvider(ctx) {
try {
log('Setting up provider');
ctx.secrets = {
mnemonic: process.env.SECRET_MNEMONIC,
address: process.env.SECRET_ADDRESS,
key: process.env.SECRET_KEY,
};
ctx.web3Provider = getRandomProvider(HDWalletProvider, ctx.secrets);
ctx.web3 = new Web3(ctx.web3Provider); // TODO: make this ctx.web3 = { bsc: } just like seer (if needed?)
ctx.ethersProvider = new ethers.providers.Web3Provider(ctx.web3Provider, 'any');
ctx.ethersProvider.pollingInterval = 15000;
ctx.signers = {};
ctx.signers.read = ctx.ethersProvider.getSigner();
ctx.signers.write = ctx.ethersProvider.getSigner();
ctx.contracts = {};
ctx.contracts.wbnb = new ethers.Contract(
getAddress(ctx.contractInfo.wbnb),
ctx.contractMetadata.BEP20.abi,
ctx.signers.read
);
} catch (e) {
log(`Couldn't setup provider.`, e);
setTimeout(() => _initProvider(ctx), 60 * 1000);
}
}
export function initProvider(ctx) {
_initProvider(ctx);
// setInterval(() => {
// // Something hctxened, lets restart the provider
// if (new Date().getTime() > ctx.config.trades.updatedTimestamp + 10 * 60 * 1000) {
// _initProvider(ctx)
// }
// }, 15 * 60 * 1000)
}
export function initWeb3(ctx) {
ctx.contractInfo = contractInfo;
ctx.contractMetadata = {};
ctx.contractMetadata.BEP20 = BEP20Contract;
ctx.signers = {
read: undefined,
write: undefined,
};
initProvider(ctx);
}