Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long prefixes #65

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/data/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface BalanceV3 {
export interface ClaimingBalance extends BalanceV3 {
dmdv4Address: string;
signature: string;
postfix?: string;
}

export interface ClaimingDataSet {
Expand Down
20 changes: 20 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const config: HardhatUserConfig = {
mnemonic
},

allowUnlimitedContractSize: true,
hardfork: "istanbul",
minGasPrice: 1000000000
},
alpha4: {
url: "http://62.171.133.46:54100",
accounts: {
count: 10,
path: "m/44'/60'/0'/0",
mnemonic
},

allowUnlimitedContractSize: true,
hardfork: "istanbul",
minGasPrice: 1000000000
Expand Down Expand Up @@ -90,6 +102,14 @@ const config: HardhatUserConfig = {
browserURL: "http://62.171.133.46:4000",
},
},
{
network: "alpha4",
chainId: 777018,
urls: {
apiURL: "http://62.171.133.46:4400/api",
browserURL: "http://62.171.133.46:4400",
},
},
],
},
mocha: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"test-deploy-and-fill": "ts-node scripts/test-fill.ts",
"test-claim": "ts-node scripts/test-claim.ts",
"fill-alpha3": "ts-node scripts/fill-alpha3.ts",
"fill-alpha4": "ts-node scripts/fill-alpha4.ts",
"solhint": "solhint 'contracts/**/*.sol'"
},
"repository": {
Expand Down
145 changes: 145 additions & 0 deletions scripts/fill-alpha4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
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 = "TESTNET dmd v4 coins are voluntary distributed towards DMD v3 snapshot coin balance owners based on the ruleset described in the open source contracts and whitepaper by using the claiming dapp u agree to this rulesets. target dmd v4 claiming address: ";
// const prefix = "";
const prefix = "claim alpha4 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 hour = 60 * 60;
const day = hour * 24;
const dillute1 = now + 7 * day;
const dillute2 = dillute1 + 7 * day;
const dillute3 = dillute2 + 7 * 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 alpha4 ${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",
"dHN8MdcZQVedNp3xY5mFvr8gLDeRkxR116",
"dSKqzw53y8Jgk4Y82usx3PWGx38yScpm7T",
"dDrm7QnGkLubQyNtnbbg7ZvkTEfTwAFaoq",
"dQVvs2Kjnhijge1BvHmejhV6GJRsiw8DCc"
];

// let unclaimed = [
// "dEx99xwAmqZtZtL6VrtxNv5pH2dtk6kTMH",
// "dTmpgqgC2qoc9bitKCdVMM19gyJNfMudBR",
// "dFQHpmkSScf9WXcyzDWK25BM62N218ViS7",
// "dHN8MdcZQVedNp3xY5mFvr8gLDeRkxR116",
// "dSKqzw53y8Jgk4Y82usx3PWGx38yScpm7T",
// "dDrm7QnGkLubQyNtnbbg7ZvkTEfTwAFaoq",
// "dQVvs2Kjnhijge1BvHmejhV6GJRsiw8DCc"
// ];


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 hre.run("verify:verify", {
address: claimContractAddress,
constructorArguments: [
claimBeneficorAddress,
beneficorDAOAddress,
prefixHex,
dillute1,
dillute2,
dillute3,
],
});
}

main();


6 changes: 6 additions & 0 deletions slither.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

solc-select install 0.8.26
solc-select use 0.8.26

slither contracts/*.sol
25 changes: 10 additions & 15 deletions test/ClaimContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,28 +329,14 @@ describe('ClaimContract', () => {

for (const balance of balances.balances) {
let balanceBeforeClaim = await ethers.provider.getBalance(balance.dmdv4Address);
await cryptoSol.claim(balance.dmdv3Address, balance.dmdv4Address, balance.signature, "");
await cryptoSol.claim(balance.dmdv3Address, balance.dmdv4Address, balance.signature, balance.postfix ?? "");
let balanceAfterClaim = await ethers.provider.getBalance(balance.dmdv4Address);

let expectedBalance = ethers.toBigInt(balance.value) + balanceBeforeClaim;
expect(balanceAfterClaim).to.equal(expectedBalance, 'Balance of DMDv4 adress matches defined Balance.');
}
}

describe("cryptographics with defined message prefix", async function () {
const claimToString = stringToUTF8Hex('claim to ');

async function deployWithPrefixFixture(): Promise<{ claimContract: ClaimContract }> {
const claimContract = await deployClaiming(
lateClaimBeneficorAddress,
lateClaimBeneficorDAO,
claimToString
);

return { claimContract };
}
});

describe("balance", async function () {

it('fill() a balance testset', async () => {
Expand Down Expand Up @@ -466,6 +452,14 @@ describe('ClaimContract', () => {
await runAddAndClaimTests(getTestBalancesFromTestdata("known_y_00"));
});

it("Claiming DMD with postfixes", async () => {
await runAddAndClaimTests(getTestBalancesFromTestdata("with_postfixes"));
});

it("Claiming DMD with long prefix", async () => {
await runAddAndClaimTests(getTestBalancesFromTestdata("long_prefix"));
});

if (runLargeTests) {
it("Claiming DMD large test: balances_1k", async () => {
await runAddAndClaimTests(getTestBalancesFromTestdata("balances_1k"));
Expand All @@ -474,6 +468,7 @@ describe('ClaimContract', () => {
it("Claiming DMD large test: balances_50k", async () => {
await runAddAndClaimTests(getTestBalancesFromTestdata("balances_50k"));
}).timeout(60_000 * 60); // maximum 1 hour for this test.

}
});

Expand Down
Loading
Loading