Skip to content

Commit af926cb

Browse files
Add whitelist task, use
Owner Wallet address: 0xc783df8a850f42e7F7e57013759C285caa701eB6 Looping until connection to network is made Connected to network for new holders
1 parent f751c61 commit af926cb

3 files changed

Lines changed: 80 additions & 1 deletion

File tree

hardhat-tasks/whitelistHolder.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { LiquidInfrastructureERC20 } from "../typechain-types";
2+
import { exit } from "process";
3+
4+
// const WxDAI_address = "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d";
5+
// const LiquidNFTExpectedAddress = "0x59ae6Db6e90488D645Cf0796a79C3A47b6B56ef5";
6+
// const LiquidERC20ExpectedAddress = "0x8c4460023f9a1c7f97c2bB96b4143a37af5EDA0f";
7+
8+
export async function whitelistHolder(
9+
hre: any,
10+
contract: string,
11+
toApprove: string
12+
) {
13+
const ethers = hre.ethers;
14+
var startTime = new Date();
15+
const signers = await ethers.getSigners();
16+
let wallet = signers[0];
17+
console.log("Owner Wallet address: ", wallet.address);
18+
19+
var success = false;
20+
while (!success) {
21+
console.log("Looping until connection to network is made");
22+
var present = new Date();
23+
var timeDiff: number = present.getTime() - startTime.getTime();
24+
timeDiff = timeDiff / 1000;
25+
try {
26+
const number = await ethers.provider.getBlockNumber();
27+
success = true;
28+
} catch (e) {
29+
console.log("Ethereum RPC error, trying again");
30+
}
31+
32+
if (timeDiff > 600) {
33+
console.log(
34+
"Could not contact Ethereum RPC after 10 minutes, check the URL!"
35+
);
36+
exit(1);
37+
}
38+
await sleep(1000);
39+
}
40+
console.log("Connected to network");
41+
42+
let liquidERC20: LiquidInfrastructureERC20;
43+
44+
let liquidERC20Address;
45+
let lerc20Factory = await ethers.getContractFactory(
46+
"LiquidInfrastructureERC20"
47+
);
48+
49+
let lerc20 = lerc20Factory.attach(
50+
contract
51+
) as unknown as LiquidInfrastructureERC20;
52+
53+
liquidERC20 = lerc20;
54+
liquidERC20Address = await liquidERC20.getAddress();
55+
console.log(
56+
"LiquidInfrastructureERC20 found at Address - ",
57+
liquidERC20Address
58+
);
59+
60+
if (!(await liquidERC20.isApprovedHolder(toApprove))) {
61+
console.log("Approving holder %s", toApprove);
62+
let receipt = await (await liquidERC20.approveHolder(toApprove)).wait();
63+
console.assert(receipt?.blockNumber != null);
64+
}
65+
let totalSupply = await liquidERC20.totalSupply();
66+
console.log("Total Supply: ", totalSupply.toString());
67+
68+
exit(0);
69+
}
70+
function sleep(ms: number) {
71+
return new Promise((resolve) => setTimeout(resolve, ms));
72+
}

hardhat.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import deployERC20 from "./hardhat-tasks/deployERC20";
77
import migrateERC20 from "./hardhat-tasks/migrateERC20";
88
import { json } from "hardhat/internal/core/params/argumentTypes";
99
import "@nomicfoundation/hardhat-verify";
10+
import { whitelistHolder } from "./hardhat-tasks/whitelistHolder";
1011

1112
// The following are set using `npx hardhat vars set <KEY>` and then the value is a prompt for a secret.
1213
// I provide a default value so that the call does not fail for regular hardhat network usage
@@ -63,6 +64,12 @@ task("deployERC20", "Deploy a LiquidInfrastructureERC20 token")
6364
args.multiclaimAddress
6465
);
6566
});
67+
task("whitelistHolder", "Approves a holder for a LiquidERC20 token")
68+
.addPositionalParam("contract")
69+
.addPositionalParam("toApprove")
70+
.setAction(async (taskArgs, hre) => {
71+
await whitelistHolder(hre, taskArgs["contract"], taskArgs["toApprove"]);
72+
});
6673

6774
task(
6875
"migrateERC20",

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"./src",
1818
"./test",
1919
"./scripts"
20-
, "hardhat-tasks/mint.ts" ],
20+
, "hardhat-tasks/mint.ts", "hardhat-tasks/whitelistHolder.ts" ],
2121
"files": [
2222
"./hardhat.config.ts"
2323
]

0 commit comments

Comments
 (0)