Skip to content

Commit

Permalink
remove id
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSilva committed Mar 21, 2024
1 parent 9007875 commit 77a51e0
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 49 deletions.
8 changes: 4 additions & 4 deletions packages/contracts/allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266,ID
0x70997970C51812dc3A010C7d01b50e0d17dc79C8,ID
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC,ID
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC,ID
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
0x70997970C51812dc3A010C7d01b50e0d17dc79C8
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
3 changes: 1 addition & 2 deletions packages/contracts/contracts/discovery/Project.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ contract Project is IProject, ERC165 {
function invest(
uint256 _peoplesAmount,
uint256 _stakersAmount,
string calldata _id,
bytes32[] calldata _merkleProof
) public override(IProject) {
bytes32 leaf = keccak256(abi.encodePacked(msg.sender, _id));
bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
bool isValidLeaf = MerkleProof.verify(_merkleProof, merkleRoot, leaf);
if (!isValidLeaf) revert InvalidLeaf();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface IProject {
function invest(
uint256 _peoplesAmount,
uint256 _stakersAmount,
string calldata _id,
bytes32[] calldata _merkleProof
) external;

Expand Down
1 change: 0 additions & 1 deletion packages/contracts/contracts/test/MockProject.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ contract MockProject is IProject {
function invest(
uint256 _peoplesAmount,
uint256 _stakersAmount,
string calldata _id,
bytes32[] calldata _merkleProof
) external {
if (stakersPool != address(0)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/deploy/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const func: DeployFunction = async function (hre) {
const citizend = await get("Citizend");
const staking = await get("Staking");
const merkleRoot =
"0x8e7ccfa471d15a7917e49017f94715d09cb940a6d5f088f516e16b0da32ff610";
"0xa5c09e2a9128afef7246a5900cfe02c4bd2cfcac8ac4286f0159a699c8455a49";

await acalaDeploy(hre, "Controller", {
from: deployer,
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/script/DevDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract DevDeployScript is Script {
Citizend citizend = new Citizend(alice);
Staking staking = new Staking(address(citizend));

bytes32 merkleRoot = 0x8e7ccfa471d15a7917e49017f94715d09cb940a6d5f088f516e16b0da32ff610;
bytes32 merkleRoot = 0xa5c09e2a9128afef7246a5900cfe02c4bd2cfcac8ac4286f0159a699c8455a49;
Project project = new Project("token sale project", address(citizend), 1000, 1, address(0), merkleRoot);

for (uint256 i; i < testAccounts.length; i++) {
Expand Down
23 changes: 10 additions & 13 deletions packages/contracts/script/generateMerkleTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import fs from "fs";
import { keccak256, encodePacked } from "viem";

let test_addresses = [
["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "ID"],
["0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "ID"],
["0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", "ID"],
["0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", "ID"],
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
];

async function main(address: string, credential: string) {
async function main(address: string) {
let addresses: string[][];

if (process.env.TEST_MODE) {
Expand All @@ -20,18 +20,15 @@ async function main(address: string, credential: string) {
.readFileSync("allowlist.txt")
.toString()
.split("\n")
.filter((s: string) => s.length > 0)
.map((s: string) => {
return s.split(",");
});
.filter((s: string) => s.length > 0);
}

console.log("Addresses: ", addresses);

const data = addresses.map((addr: string) => {
return {
address: addr,
leaf: keccak256(encodePacked(["address", "string"], addr)),
leaf: keccak256(encodePacked(["address"], [addr])),
};
});

Expand All @@ -40,14 +37,14 @@ async function main(address: string, credential: string) {

console.log(`Merkle root: ${merkleTree.getHexRoot()}`);

const key = [address, credential];
const key = [address];
console.log(`\n\nProof for ${key}:`);
console.log(
merkleTree.getHexProof(keccak256(encodePacked(["address", "string"], key)))
merkleTree.getHexProof(keccak256(encodePacked(["address"], key)))
);
}

main(process.argv[2], process.argv[3])
main(process.argv[2])
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/contracts/discovery/Batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("Batch", () => {
registry.address,
staking.address,
citizend.address,
"0x8e7ccfa471d15a7917e49017f94715d09cb940a6d5f088f516e16b0da32ff610"
"0xa5c09e2a9128afef7246a5900cfe02c4bd2cfcac8ac4286f0159a699c8455a49"
);
aUSD = await new MockERC20__factory(owner).deploy("aUSD", "aUSD", 12);

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/contracts/discovery/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("Controller", () => {
registry.address,
staking.address,
citizend.address,
"0x8e7ccfa471d15a7917e49017f94715d09cb940a6d5f088f516e16b0da32ff610"
"0xa5c09e2a9128afef7246a5900cfe02c4bd2cfcac8ac4286f0159a699c8455a49"
);
});

Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/test/contracts/discovery/Project.d.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ contract ProjectTest is Test {
function setUp() public {
vm.startPrank(alice);

bytes32 merkleRoot = 0x8e7ccfa471d15a7917e49017f94715d09cb940a6d5f088f516e16b0da32ff610;
bytes32 merkleRoot = 0xa5c09e2a9128afef7246a5900cfe02c4bd2cfcac8ac4286f0159a699c8455a49;
proofs[alice] = [
bytes32(0xd3f793615f8d887594ece7ec035678d9b82bc492d243cdf3d4d54a007dfab520),
bytes32(0x6c31f90dc2f54aacc0a676de83d706f1e0fdd99e31867640d8c87a6af1a1dd86)
bytes32(0x00314e565e0574cb412563df634608d76f5c59d9f817e85966100ec1d48005c0),
bytes32(0x347dce04eb339ca70588960730ef0cada966bb1d5e10a9b9489a3e0ba47dc1b6)
];

citizend = new Citizend(alice);
Expand All @@ -37,16 +37,16 @@ contract ProjectTest is Test {
function testInvest() public {
vm.startPrank(alice);

project.invest(1,1,"ID", proofs[alice]);
project.invest(1,1, proofs[alice]);

vm.stopPrank();
}

function testInvestShouldRevertWithInvalidCrendetial() public {
function testInvestShouldRevertWithInvalidProof() public {
vm.startPrank(alice);

vm.expectRevert();
project.invest(1,1,"NOID", proofs[alice]);
project.invest(1,1, proofs[bob]);

vm.stopPrank();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe("ProjectVoting", () => {
1000,
10,
aUSD.address,
"0x8e7ccfa471d15a7917e49017f94715d09cb940a6d5f088f516e16b0da32ff610"
"0xa5c09e2a9128afef7246a5900cfe02c4bd2cfcac8ac4286f0159a699c8455a49"
);
}
});
32 changes: 15 additions & 17 deletions packages/contracts/test/contracts/discovery/pool/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ describe("Pool", () => {

let pool: TestPool;

let id: string;
let merkleProof: BytesLike[];

beforeEach(async () => {
[owner, alice, bob] = await ethers.getSigners();

id = "ID";
merkleProof = [
"0xd3f793615f8d887594ece7ec035678d9b82bc492d243cdf3d4d54a007dfab520",
"0x6c31f90dc2f54aacc0a676de83d706f1e0fdd99e31867640d8c87a6af1a1dd86",
"0x00314e565e0574cb412563df634608d76f5c59d9f817e85966100ec1d48005c0",
"0x347dce04eb339ca70588960730ef0cada966bb1d5e10a9b9489a3e0ba47dc1b6",
];

aUSD = await new MockERC20__factory(owner).deploy("aUSD", "aUSD", 12);
Expand Down Expand Up @@ -64,7 +62,7 @@ describe("Pool", () => {

describe("setIndividualCap", () => {
it("allows me to set the cap after investment period is over", async () => {
await project.connect(alice).invest(0, 100, id, merkleProof);
await project.connect(alice).invest(0, 100, merkleProof);

await pool.setIndividualCap(100, { gasLimit: 10000000 });

Expand All @@ -73,7 +71,7 @@ describe("Pool", () => {
});

it("fails to validate the cap for the wrong value", async () => {
await project.connect(alice).invest(0, 100, id, merkleProof);
await project.connect(alice).invest(0, 100, merkleProof);

await pool.setIndividualCap(50, { gasLimit: 10000000 });

Expand All @@ -84,7 +82,7 @@ describe("Pool", () => {

describe("refund", () => {
it("fails if individual cap is not yet set", async () => {
await project.connect(alice).invest(0, 100, id, merkleProof);
await project.connect(alice).invest(0, 100, merkleProof);

await expect(pool.refund(alice.address)).to.be.revertedWith(
"cap not yet set"
Expand All @@ -94,7 +92,7 @@ describe("Pool", () => {
it("refunds the correct amount once the cap is set", async () => {
const cap = 1000;
const amount = cap + 1000;
await project.connect(alice).invest(0, amount, id, merkleProof);
await project.connect(alice).invest(0, amount, merkleProof);
await pool.setIndividualCap(cap, { gasLimit: 10000000 });

await expect(() => pool.refund(alice.address)).to.changeTokenBalance(
Expand All @@ -107,7 +105,7 @@ describe("Pool", () => {
it("emits an event", async () => {
const cap = 1000;
const amount = cap + 1000;
await project.connect(alice).invest(0, amount, id, merkleProof);
await project.connect(alice).invest(0, amount, merkleProof);
await pool.setIndividualCap(cap, { gasLimit: 10000000 });

await expect(pool.refund(alice.address))
Expand All @@ -118,7 +116,7 @@ describe("Pool", () => {
it("does not allow double refunds", async () => {
const cap = 1000;
const amount = cap + 1000;
await project.connect(alice).invest(0, amount, id, merkleProof);
await project.connect(alice).invest(0, amount, merkleProof);
await pool.setIndividualCap(cap, { gasLimit: 10000000 });

await pool.refund(alice.address);
Expand All @@ -139,16 +137,16 @@ describe("Pool", () => {
});

it("is 0 if the individual cap is higher than the invested total", async () => {
await project.connect(alice).invest(0, 200, id, merkleProof);
await project.connect(bob).invest(0, 200, id, merkleProof);
await project.connect(alice).invest(0, 200, merkleProof);
await project.connect(bob).invest(0, 200, merkleProof);

await pool.setIndividualCap(800, { gasLimit: 10000000 });

expect(await pool.refundableAmount(alice.address)).to.equal(0);
});

it("is the difference between the cap and the invested total", async () => {
await project.connect(alice).invest(0, 1001, id, merkleProof);
await project.connect(alice).invest(0, 1001, merkleProof);

await pool.setIndividualCap(1000, { gasLimit: 10000000 });

Expand All @@ -158,7 +156,7 @@ describe("Pool", () => {

describe("uncappedAllocation", () => {
it("is the amount that was invested", async () => {
await project.connect(alice).invest(0, 100, id, merkleProof);
await project.connect(alice).invest(0, 100, merkleProof);

expect(await pool.uncappedAllocation(alice.address)).to.equal(100);
});
Expand All @@ -170,16 +168,16 @@ describe("Pool", () => {
});

it("is the amount that was invested if below cap", async () => {
await project.connect(alice).invest(0, 50, id, merkleProof);
await project.connect(bob).invest(0, 1000, id, merkleProof);
await project.connect(alice).invest(0, 50, merkleProof);
await project.connect(bob).invest(0, 1000, merkleProof);

await pool.setIndividualCap(950, { gasLimit: 10000000 });

expect(await pool.allocation(alice.address)).to.equal(50);
});

it("is the amount that was invested if above cap", async () => {
await project.connect(alice).invest(0, 1001, id, merkleProof);
await project.connect(alice).invest(0, 1001, merkleProof);

await pool.setIndividualCap(1000, { gasLimit: 10000000 });

Expand Down

0 comments on commit 77a51e0

Please sign in to comment.