Skip to content

Commit

Permalink
Merge pull request #41 from DMDcoin/i40-claiming-balances-alpha3
Browse files Browse the repository at this point in the history
I40 claiming balances alpha3
  • Loading branch information
SurfingNerd authored Aug 14, 2024
2 parents d78e3ff + 7b15cb2 commit 10065b1
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 23 deletions.
15 changes: 4 additions & 11 deletions api/src/cryptoSol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
// }
Expand All @@ -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[] = [];
Expand All @@ -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());
Expand Down
29 changes: 21 additions & 8 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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",
},
},
],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
133 changes: 133 additions & 0 deletions scripts/fill-alpha3.ts
Original file line number Diff line number Diff line change
@@ -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();


6 changes: 3 additions & 3 deletions test/ClaimContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 10065b1

Please sign in to comment.