-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (46 loc) · 1.7 KB
/
index.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
require("dotenv").config();
const { ethers } = require("ethers");
const ERC20ABI = require("./ERC20ABI.json");
const ERC721ABI = require("./ERC721ABI.json");
const provider = new ethers.providers.JsonRpcProvider(
process.env.PROVIDER_URL
);
const COIN_CONTRACT_ADDRESS = process.env.ERC20_CONTRACT_ADDRESS;
const NFT_CONTRACT_ADDRESS = process.env.ERC721_NFT_CONTRACT_ADDRESS;
const depositWallet = new ethers.Wallet(
process.env.DEPOSIT_WALLET_PRIVATE_KEY,
provider
);
const COIN = new ethers.Contract(COIN_CONTRACT_ADDRESS, ERC20ABI, provider);
const NFT = new ethers.Contract(NFT_CONTRACT_ADDRESS, ERC721ABI, provider);
const bot = async () => {
const depositWalletAddress = await depositWallet.getAddress();
console.log(`Withdraw from address: ${depositWalletAddress}`);
provider.on("block", async () => {
console.log(">>> Checking ...");
const balance = await COIN.balanceOf(depositWalletAddress);
const balanceFormatted = ethers.utils.formatUnits(balance, 18);
// const getNFT = await NFT.balanceOf(depositWalletAddress);
if (Number(balanceFormatted) > 0) {
const contractSigner = COIN.connect(depositWallet);
console.log(`Balance : ${balanceFormatted}`);
const gasPrice = await provider.getGasPrice();
const amount = ethers.utils.parseUnits(balanceFormatted.toString(), 18);
try {
await contractSigner.transfer(
process.env.VAULT_WALLET_ADDRESS,
amount,
{
gasPrice: gasPrice,
}
);
console.log(`Withdraw success -->${balanceFormatted}`);
} catch (e) {
console.log(`Withdraw failed -->${balanceFormatted}`);
}
} else {
// console.log("!");
}
});
};
bot();