From a7a7ba76280f6798e6613bf4877b5c3ccf85ea6a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Aug 2024 21:58:04 +0200 Subject: [PATCH 1/4] removed addBalance from cryptoSol since it does not exist anymore. --- api/src/cryptoSol.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/api/src/cryptoSol.ts b/api/src/cryptoSol.ts index ab45342..157609a 100644 --- a/api/src/cryptoSol.ts +++ b/api/src/cryptoSol.ts @@ -114,15 +114,6 @@ export class CryptoSol { return new TextDecoder("utf-8").decode(buffer); } - public async addBalance(dmdV3Address: string, value: string) { - - const signers = await ethers.getSigners(); - const fromAccount = signers[0]; - const ripe = this.cryptoJS.dmdAddressToRipeResult(dmdV3Address); - - return (await this.instance.connect(fromAccount).addBalance(ensure0x(ripe), { value: value })).wait(); - } - // public async claim(dmdv3Address: string, payoutAddress: string, signature: string ) { // ensurePrefixCache() // } @@ -141,8 +132,10 @@ export class CryptoSol { } - public async fillBalances(claimContract: ClaimContract, sponsor: SignerWithAddress, balances: BalanceV3[]) { + public async fillBalances(sponsor: SignerWithAddress, balances: BalanceV3[]) { + + let totalBalance = ethers.toBigInt('0'); let accounts: string[] = []; let balancesForContract: string[] = []; @@ -156,7 +149,7 @@ export class CryptoSol { // console.log(accounts); // console.log(balancesForContract); // console.log(totalBalance); - await (await claimContract.connect(sponsor).fill(accounts, balancesForContract, { value: totalBalance })).wait(); + await (await this.instance.connect(sponsor).fill(accounts, balancesForContract, { value: totalBalance })).wait(); // console.log("result status", txResult?.status); //console.log(await txResult?.getResult()); From 59a1e539b62b44456511545060bda289e66e03cd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Aug 2024 21:58:54 +0200 Subject: [PATCH 2/4] tests: fillBalances does not require a "contract" instance anymore. --- test/ClaimContract.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/ClaimContract.spec.ts b/test/ClaimContract.spec.ts index ceecd60..9fc044c 100644 --- a/test/ClaimContract.spec.ts +++ b/test/ClaimContract.spec.ts @@ -344,7 +344,7 @@ describe('ClaimContract', () => { let cryptoSol = new CryptoSol(claimContract); - await cryptoSol.fillBalances(claimContract, caller, balances.balances); + await cryptoSol.fillBalances(caller, balances.balances); for (const balance of balances.balances) { let balanceBeforeClaim = await ethers.provider.getBalance(balance.dmdv4Address); @@ -382,7 +382,7 @@ describe('ClaimContract', () => { let cryptoSol = new CryptoSol(claimContract); - let expectedTotalBalance = await cryptoSol.fillBalances(claimContract, caller, testbalances); + let expectedTotalBalance = await cryptoSol.fillBalances(caller, testbalances); const totalBalance = await ethers.provider.getBalance(await claimContract.getAddress()); expect(totalBalance).to.equal(expectedTotalBalance, 'Balance of contract should be the total of all added funds.'); @@ -494,7 +494,7 @@ describe('ClaimContract', () => { let sol = new CryptoSol(claimContract); // sol.setLogDebug(true); - totalAmountInClaimingPot = await sol.fillBalances(claimContract, sponsor, testBalances.balances); + totalAmountInClaimingPot = await sol.fillBalances(sponsor, testBalances.balances); // Try to dilute before first dilution period - should fail await expect(claimContract.dilute1()).to.be.revertedWithCustomError( From b1b19aade2196d7c132b2492b590aa7cac8843c9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Aug 2024 22:30:15 +0200 Subject: [PATCH 3/4] config for alpha3 --- hardhat.config.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index e149721..287e552 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -9,10 +9,11 @@ import fs from "fs"; let mnemonic = 'inspire school random normal account steel strike shove close album produce cube bounce memory before'; if (fs.existsSync(".mnemonic")) { mnemonic = fs.readFileSync(".mnemonic").toString().trim(); + console.log("did read mnemonic from FS"); } const config: HardhatUserConfig = { - defaultNetwork: "alpha2", + defaultNetwork: "alpha3", networks: { hardhat: { accounts: { @@ -25,8 +26,8 @@ const config: HardhatUserConfig = { minGasPrice: 0, blockGasLimit: 1199511627775 }, - alpha2: { - url: "https://rpc.uniq.diamonds", + local: { + url: "http://127.0.0.1:8540", accounts: { count: 100, mnemonic @@ -35,6 +36,18 @@ const config: HardhatUserConfig = { hardfork: "istanbul", minGasPrice: 1000000000 }, + alpha3: { + url: "https://alpha3.uniq.domains/rpc", + accounts: { + count: 10, + path: "m/44'/60'/0'/0", + mnemonic + }, + + allowUnlimitedContractSize: true, + hardfork: "istanbul", + minGasPrice: 1000000000 + }, }, solidity: { version: "0.8.20", @@ -63,18 +76,18 @@ const config: HardhatUserConfig = { customChains: [ { network: "local", - chainId: 777012, + chainId: 777000, urls: { apiURL: "http://127.0.0.1:4000/api", browserURL: "http://127.0.0.1:4000", }, }, { - network: "alpha2", - chainId: 777012, + network: "alpha3", + chainId: 777017, urls: { - apiURL: "https://explorer.uniq.diamonds/api", - browserURL: "http://explorer.uniq.diamonds", + apiURL: "http://62.171.133.46:4000/api", + browserURL: "http://62.171.133.46:4000", }, }, ], From 7b15cb21f632bf697b7723d296b2118ce99b7807 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 12 Aug 2024 22:31:48 +0200 Subject: [PATCH 4/4] fill script for alpha3 --- package.json | 3 +- scripts/fill-alpha3.ts | 133 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 scripts/fill-alpha3.ts diff --git a/package.json b/package.json index 9fdd49b..2260c94 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "coverage": "export SOLIDITY_COVERAGE=true && npx hardhat coverage", "test-deploy": "ts-node scripts/deploy-raw.ts", "test-deploy-and-fill": "ts-node scripts/test-fill.ts", - "test-claim": "ts-node scripts/test-claim.ts" + "test-claim": "ts-node scripts/test-claim.ts", + "fill-alpha3": "ts-node scripts/fill-alpha3.ts" }, "repository": { "type": "git", diff --git a/scripts/fill-alpha3.ts b/scripts/fill-alpha3.ts new file mode 100644 index 0000000..b7508eb --- /dev/null +++ b/scripts/fill-alpha3.ts @@ -0,0 +1,133 @@ +import hre from "hardhat"; +import { CryptoSol } from "../api/src/cryptoSol"; +import { ClaimContract, ClaimContract__factory } from "../typechain-types"; +import { stringToUTF8Hex } from "../api/src/cryptoHelpers"; +import { BalanceV3 } from "../api/data/interfaces"; + +let ethers = hre.ethers; + +const prefix = "claim alpha3 to: "; + +async function main() { + + let claimBeneficorAddress = "0x2000000000000000000000000000000000000001"; + let beneficorDAOAddress = "0xDA0da0da0Da0Da0Da0DA00DA0da0da0DA0DA0dA0"; + + //let dillute1 = + let now = (Date.now() / 1000).toFixed(0); + + let signer = (await hre.ethers.getSigners())[0]; + + + + console.log("using signer:", signer.address); + const signerBalance = await ethers.provider.getBalance(signer.address); + console.log("balance:", signerBalance); + + if (signerBalance == BigInt(0)) { + console.error("No Balance for this signer"); + return; + } + + const day = 60 * 60 * 24; + const dillute1 = now + 7 * day; + const dillute2 = dillute1 + 7 * day; + const dillute3 = dillute2 + 14 * day; + + const contractFactory = await ethers.getContractFactory("ClaimContract"); + + const prefixHex = stringToUTF8Hex(prefix); + console.log("prefixHex", prefixHex); + const claimContractAny : any = await contractFactory.deploy(claimBeneficorAddress, beneficorDAOAddress, prefixHex, dillute1, dillute2, dillute3); + const claimContract = claimContractAny as ClaimContract; + + await claimContract.waitForDeployment(); + let claimContractAddress = await claimContract.getAddress(); + console.log('claim contract deployed to:', claimContractAddress); + console.log(`trying to verify.`); + console.log(`npx command to verify localy - if the automated command fails:`); + console.log(`npx hardhat verify --network alpha3 ${claimContractAddress} ${claimBeneficorAddress} ${beneficorDAOAddress} ${prefixHex} ${dillute1} ${dillute2} ${dillute3}` ); + + + let cryptoSol = new CryptoSol(claimContract); + cryptoSol.setLogDebug(true); + // it doesnt need to be super accurate, we can work with floating point numbers here. + //let allCoins = 3824716; + + let allCoins = 1; + // - 75% early + // - 5% mid + // - 5% late + // - 15% never + + let totalEarly = allCoins * 0.75; + let totalMid = allCoins * 0.05; + let totalLate = allCoins * 0.05; + let totalNever = allCoins * 0.15; + + let earlyAccounts = [ + "dbnJAWXKYvmoqV5bonJdgY3yuzHgrdHJQs", + "dEaTZND5nXeZRZgJt1z6HVmP7mtZ3demQK", + "dEx99xwAmqZtZtL6VrtxNv5pH2dtk6kTMH", + "dc71fVvE17UEZEZb7qbQmaLWm3D15QkB4V", + "dTmpgqgC2qoc9bitKCdVMM19gyJNfMudBR", + "dFQHpmkSScf9WXcyzDWK25BM62N218ViS7", + "dJU7z5oXd5ZsXZybRWadHnUzFgCY5ukZU5", + "dYUyrALxXrzpwyE41cntKHgPS4BYSB3rQX", + "dY3DefvBW4ySwfqJdPUVrmMyqDVW6cPJbd", + "dQkNJHJtow742w1Pmm3txRJQ6xt9bQaxb7" + ]; + + let toWeiString = (value: number) => { + + let num = value * Number(ethers.WeiPerEther); + console.log(num); + let big = BigInt(num); + console.log(big); + let result = ethers.formatUnits(big, 0); + console.log(result); + return result; + } + + let earlyBalances : BalanceV3[] = earlyAccounts.map((a) => { return {dmdv3Address: a, value: toWeiString(totalEarly / earlyAccounts.length) }; }); + + + // 0xbC81e4c79447F73022B02203b14a526f64B821E0 + let balances : BalanceV3[] = [ + // designed for early. + ...earlyBalances, + // designed for mid. + { dmdv3Address: "dNddYBwd1xeu2snmJt4YxMcG2qWChcHCNt", value: toWeiString(totalMid) }, + // designed for late. + { dmdv3Address: "dPmptc1PYyNn4kpMgqNz5S1Wj3JFEs6fqk", value: toWeiString(totalLate)}, + // designed for never. + { dmdv3Address: "dHRKrnhhtGTiNRrCpLkmvhUKUWNB247mah", value: toWeiString(totalNever)}, + ]; + + let sponsor = (await ethers.getSigners())[0]; + + + await cryptoSol.fillBalances(sponsor, balances); + + // await cryptoSol.claim(balanceRow.dmdv3Address, balanceRow.dmdv4Address, balanceRow.signature, "", true + // let signature = "IG8j0HGlWUh4SUpd4hgjFaumIPKybGxAevm35RnMwEkYZ+HWYD0IKODVkldrzfqJWdh+26y4fR5Ihmyzht+FdSM="; + // let dmdV4Address = "0xdd37EA7bA22500A43D28378b62A0fCA89bCCFd6F"; + + //await cryptoSol.claim(dmdV3Address, dmdV4Address, signature); + + await hre.run("verify:verify", { + address: claimContractAddress, + constructorArguments: [ + claimBeneficorAddress, + beneficorDAOAddress, + prefixHex, + dillute1, + dillute2, + dillute3, + ], + }); +} + +main(); + +