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

Adds correct fractal root wallet for mandala #134

Merged
merged 7 commits into from May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,7 +5,7 @@ pragma solidity >=0.7.0 <0.9.0;
/// @author Antoni Dikov and Shelby Doolittle
contract FractalRegistry {
address root;
mapping(address => bool) delegates;
mapping(address => bool) public delegates;

mapping(address => bytes32) fractalIdForAddress;
mapping(string => mapping(bytes32 => bool)) userLists;
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/deploy/ctnd/sale1.deploy.ts
Expand Up @@ -2,11 +2,10 @@ import type { DeployFunction } from "hardhat-deploy/types";
import { ethers } from "hardhat";

import { acalaDeploy } from "../../src/acala";
import { getNetworkConfig } from "../../src/deployConfigs";

const { parseUnits } = ethers.utils;

import { getNetworkConfig } from "../../src/deployConfigs";

const func: DeployFunction = async function (hre) {
const { deployer } = await hre.getNamedAccounts();
const { get, read } = hre.deployments;
Expand Down
18 changes: 0 additions & 18 deletions packages/contracts/deploy/fractalRegistry.ts

This file was deleted.

35 changes: 35 additions & 0 deletions packages/contracts/deploy/registry/registry.addDelegate.ts
@@ -0,0 +1,35 @@
import { DeployFunction } from "hardhat-deploy/types";

import { getNetworkName } from "../../src/deployConfigs";

const func: DeployFunction = async function (hre) {
const { deployer } = await hre.getNamedAccounts();
const { execute, read } = hre.deployments;

if (getNetworkName() != "mandala") {
return;
}

const alreadyDelegate = await read(
"FractalRegistry",
{},
"delegates",
deployer
);

if (alreadyDelegate) {
return;
}

await execute(
"FractalRegistry",
{ from: deployer, log: true },
"addDelegate",
deployer
);
};

func.id = "fractal-registry.delegate";
func.dependencies = ["fractal-registry", "fractal-registry.registry"];

export default func;
21 changes: 21 additions & 0 deletions packages/contracts/deploy/registry/registry.deploy.ts
@@ -0,0 +1,21 @@
import { DeployFunction } from "hardhat-deploy/types";

import { acalaDeploy } from "../../src/acala";
import { getNetworkConfig } from "../../src/deployConfigs";

const func: DeployFunction = async function (hre) {
const { deployer } = await hre.getNamedAccounts();

const { registry } = await getNetworkConfig();

await acalaDeploy(hre, "FractalRegistry", {
log: true,
from: deployer,
args: [registry.root],
});
};

func.id = "fractal-registry.deploy";
func.tags = ["fractal-registry", "fractal-registry.deploy"];

export default func;
73 changes: 43 additions & 30 deletions packages/contracts/src/deployConfigs.ts
Expand Up @@ -2,6 +2,8 @@ import { network, ethers } from "hardhat";
import type { BigNumber } from "ethers";
import dayjs from "dayjs";

const MANDALA_REGISTRY_ROOT = "0xC3e923e0CE5125088cDa62935056d6B5F14F234c";

interface CTNDSale {
start: number;
end: number;
Expand All @@ -12,75 +14,68 @@ interface CTNDVesting {
start: number;
}

interface Registry {
root: string;
}

interface Config {
ctndSale1: CTNDSale;
ctndSale2?: CTNDSale;
ctndVesting: CTNDVesting;
registry: Registry;
}

const { parseUnits } = ethers.utils;

async function networkConfigs(chainId: number): Promise<Config> {
const network = await chainIdToNetwork(chainId);
const [owner] = await ethers.getSigners();

const now = currentTimestamp();

switch (network) {
case "hardhat": {
const date = new Date();
const beginningOfNextMonth = new Date(
date.getFullYear(),
date.getMonth() + 1,
1,
12
);
const now = Math.floor(date.getTime() / 1000);
const oneDay = 60 * 60 * 24;

return {
ctndSale1: {
start: now,
end: now + oneDay,
end: now + THIRTY_MIN,
supply: parseUnits("10"),
},
ctndVesting: {
start: beginningOfNextMonth.getTime() / 1000,
start: now + THIRTY_MIN * 2,
},
ctndSale2: {
start: now + 60 * 60 * 24 * 2,
end: now + 60 * 60 * 24 * 3,
supply: parseUnits("15"),
start: now + THIRTY_MIN,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need the two sales for mandala? Want to test all of that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is on hardhat, not mandala

end: now + THIRTY_MIN * 2,
supply: parseUnits("10"),
},
registry: {
root: owner.address,
},
};
}

case "mandala":
const date = new Date();
const beginningOfNextMonth = new Date(
date.getFullYear(),
date.getMonth() + 1,
1,
12
);
const now = Math.floor(new Date(2022, 4, 9, 10, 10).getTime() / 1000);
// const now = Math.floor(date.getTime() / 1000);
const thirtyMinutes = 30 * 60;
const oneDay = 60 * 60 * 24;
const start = Math.floor(new Date(2022, 4, 6, 17, 30).getTime() / 1000);

return {
ctndSale1: {
start: now,
end: now + 20 * 60,
start: start,
end: start + THIRTY_MIN,
supply: parseUnits("10"),
},
ctndVesting: {
start: now + thirtyMinutes,
start: start + THIRTY_MIN,
},
ctndSale2: undefined,
registry: {
root: MANDALA_REGISTRY_ROOT,
},
};

case "acala":
case "karura":
throw "not yet implemented";
const saleStart = dayjs("2022-04-26");
// return {
// ctndSale1: {
// start: saleStart.unix(),
Expand All @@ -107,6 +102,24 @@ const chainIdToNetwork = (chainId: number): string => {
]!;
};

export const getNetworkName = (): string => {
return chainIdToNetwork(network.config.chainId!);
};

export const getNetworkConfig = async () => {
return await networkConfigs(network.config.chainId!);
};

function currentTimestamp(): number {
const date = new Date();
return Math.floor(date.getTime() / 1000);
}

function beginningOfNextMonthTimestamp(): number {
const date = new Date();
const nextMonth = new Date(date.getFullYear(), date.getMonth() + 1, 1, 12);

return Math.floor(nextMonth.getTime() / 1000);
}

const THIRTY_MIN = 30 * 60;