Skip to content

Commit 9fcaea7

Browse files
authored
Merge pull request #17 from darcys22/investor-scripts
Investor scripts
2 parents e4c965b + 34e8f3a commit 9fcaea7

File tree

2 files changed

+117
-10
lines changed

2 files changed

+117
-10
lines changed

scripts/deploy-investor-vesting.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const fs = require('fs');
33
const csv = require('csv-parse/sync');
44
const chalk = require('chalk');
55

6+
67
// This script will deploy many investor contract, it takes as input a CSV "investors.csv" which is required to have
78
// these headers: beneficiary,revoker,start,end,transferableBeneficiary,amount
89
//
@@ -16,6 +17,10 @@ const seshAddress = "0x7D7fD4E91834A96cD9Fb2369E7f4EB72383bbdEd";
1617
const rewardsAddress = "0x9d8aB00880CBBdc2Dcd29C179779469A82E7be35";
1718
const multiContributorAddress = "0x36Ee2Da54a7E727cC996A441826BBEdda6336B71";
1819

20+
// Configuration constants
21+
const SHOULD_VERIFY_CONTRACTS = true;
22+
const SHOULD_TRANSFER_FUNDS = false;
23+
1924
async function verifyContract(address, constructorArgs) {
2025
console.log(chalk.yellow("\nVerifying contract on Etherscan..."));
2126
try {
@@ -88,6 +93,8 @@ async function main() {
8893
}
8994

9095
const deployedContracts = [];
96+
97+
const seshContract = await hre.ethers.getContractAt("SESH", seshAddress);
9198

9299
// Deploy contracts for each investor
93100
for (const record of records) {
@@ -130,17 +137,19 @@ async function main() {
130137

131138
console.log(chalk.green("Vesting contract deployed to:"), chalk.yellow(vestingAddress));
132139

133-
console.log("Waiting for deployment to be confirmed...");
134-
await vestingContract.deploymentTransaction().wait(5);
135-
136-
await verifyContract(vestingAddress, constructorArgs);
140+
if (SHOULD_VERIFY_CONTRACTS) {
141+
console.log("Waiting for deployment to be confirmed...");
142+
await vestingContract.deploymentTransaction().wait(5);
143+
await verifyContract(vestingAddress, constructorArgs);
144+
}
137145

138-
const seshContract = await hre.ethers.getContractAt("SESH", seshAddress);
139-
const amount = hre.ethers.parseUnits(record.amount, 9); // Assuming 9 decimals for SESH
140-
const transferTx = await seshContract.transfer(vestingAddress, amount);
141-
await transferTx.wait();
142-
143-
console.log(chalk.green("Tokens transferred:"), chalk.yellow(record.amount), "SESH");
146+
if (SHOULD_TRANSFER_FUNDS) {
147+
const amount = hre.ethers.parseUnits(record.amount, 9); // Assuming 9 decimals for SESH
148+
const transferTx = await seshContract.transfer(vestingAddress, amount);
149+
await transferTx.wait();
150+
151+
console.log(chalk.green("Tokens transferred:"), chalk.yellow(record.amount), "SESH");
152+
}
144153

145154
deployedContracts.push({
146155
beneficiary: record.beneficiary,
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
const hre = require("hardhat");
2+
const fs = require('fs');
3+
const chalk = require('chalk');
4+
5+
// Constants
6+
const seshAddress = "0x6C9D6d6FB69927e3CED37374d820121c7c5b77e1";
7+
// Load this jsonFilePath based on what is output when running deploy-investor-vesting.js script. Its default
8+
// output path is: `deployments/vesting-${networkName}-${Date.now()}.json`
9+
const jsonFilePath = "./deployments/vesting-sepolia-1747608242040.json";
10+
11+
async function main() {
12+
const [deployer] = await hre.ethers.getSigners();
13+
console.log("Transferring tokens with account:", chalk.yellow(deployer.address));
14+
15+
const networkName = hre.network.name;
16+
console.log("Network:", chalk.cyan(networkName));
17+
console.log("SESH token address:", chalk.yellow(seshAddress));
18+
console.log("JSON file:", chalk.yellow(jsonFilePath));
19+
20+
if (!fs.existsSync(jsonFilePath)) {
21+
console.error(chalk.red(`Error: JSON file not found at ${jsonFilePath}`));
22+
process.exit(1);
23+
}
24+
25+
if (!hre.ethers.isAddress(seshAddress)) {
26+
console.error(chalk.red(`Error: Invalid SESH token address: ${seshAddress}`));
27+
process.exit(1);
28+
}
29+
30+
const fileContent = fs.readFileSync(jsonFilePath, 'utf8');
31+
let deployments;
32+
33+
try {
34+
deployments = JSON.parse(fileContent);
35+
} catch (error) {
36+
console.error(chalk.red(`Error parsing JSON file: ${error.message}`));
37+
process.exit(1);
38+
}
39+
40+
if (!deployments || !Array.isArray(deployments['contracts']) || deployments['contracts'].length === 0) {
41+
console.error(chalk.red("Error: JSON file is empty or invalid"));
42+
process.exit(1);
43+
}
44+
45+
const seshContract = await hre.ethers.getContractAt("SESH", seshAddress);
46+
47+
const deployerBalance = await seshContract.balanceOf(deployer.address);
48+
const totalRequired = deployments['contracts'].reduce((sum, deployment) => {
49+
return sum + hre.ethers.parseUnits(deployment.amount, 9); // Assuming 9 decimals for SESH
50+
}, 0n);
51+
52+
console.log("Your balance:", chalk.yellow(hre.ethers.formatUnits(deployerBalance, 9)), "SESH");
53+
console.log("Total required:", chalk.yellow(hre.ethers.formatUnits(totalRequired, 9)), "SESH");
54+
55+
if (deployerBalance < totalRequired) {
56+
console.error(chalk.red("Error: Insufficient SESH balance for transfers"));
57+
console.error(`You have ${hre.ethers.formatUnits(deployerBalance, 9)} SESH, but need ${hre.ethers.formatUnits(totalRequired, 9)} SESH`);
58+
process.exit(1);
59+
}
60+
61+
console.log(chalk.yellow("Starting transfers...\n"));
62+
63+
let successful = 0;
64+
let failed = 0;
65+
66+
for (const deployment of deployments['contracts']) {
67+
try {
68+
if (!hre.ethers.isAddress(deployment['vestingAddress'])) {
69+
throw new Error(`Invalid vesting contract address: ${deployment['vestingAddress']}`);
70+
}
71+
72+
const amount = hre.ethers.parseUnits(deployment['amount'], 9); // Assuming 9 decimals for SESH
73+
console.log(chalk.cyan(`Transferring ${deployment['amount']} SESH to ${deployment['vestingAddress']}...`));
74+
75+
const transferTx = await seshContract.transfer(deployment['vestingAddress'], amount);
76+
await transferTx.wait();
77+
78+
console.log(chalk.green("✓ Transfer successful! Tx hash:"), transferTx.hash);
79+
successful++;
80+
} catch (error) {
81+
console.error(chalk.red(`Error transferring to ${deployment['vestingAddress']}:`), error.message);
82+
failed++;
83+
}
84+
}
85+
86+
console.log(chalk.cyan("\nTransfer Summary:"));
87+
console.log("Total contracts:", chalk.yellow(deployments['contracts'].length));
88+
console.log("Successful:", chalk.green(successful));
89+
console.log("Failed:", failed > 0 ? chalk.red(failed) : chalk.green(failed));
90+
}
91+
92+
main()
93+
.then(() => process.exit(0))
94+
.catch((error) => {
95+
console.error(chalk.red("Unhandled error:"));
96+
console.error(error);
97+
process.exit(1);
98+
});

0 commit comments

Comments
 (0)