Skip to content

Commit

Permalink
Dividend contract use block timestamp instead of block number.
Browse files Browse the repository at this point in the history
Upload dmc2.0 deploy script.
Adjust exchange and bridge param
  • Loading branch information
weiqiushi committed May 14, 2024
1 parent 2193ee6 commit 663ae5c
Show file tree
Hide file tree
Showing 5 changed files with 696 additions and 649 deletions.
18 changes: 8 additions & 10 deletions contracts/dividend.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ contract DividendContract is Initializable, UUPSUpgradeable, ReentrancyGuardUpgr
// current cycle index, start at 0
uint256 public currentCycleIndex;

// the start block of the cycle of the contract
uint256 public cycleStartBlock;

struct RewardInfo {
address token;
uint256 amount;
Expand All @@ -35,7 +32,7 @@ contract DividendContract is Initializable, UUPSUpgradeable, ReentrancyGuardUpgr

struct CycleInfo {
// The start block of the cycle
uint256 startBlock;
uint256 startBlocktime;

// the total stake amount of the curent cycle
uint256 totalStaked;
Expand Down Expand Up @@ -87,12 +84,13 @@ contract DividendContract is Initializable, UUPSUpgradeable, ReentrancyGuardUpgr
function __DividendContractUpgradable_init(address _stakingToken, uint256 _cycleMaxLength, address[] memory _tokenList) public onlyInitializing {
stakingToken = _stakingToken;
cycleMaxLength = _cycleMaxLength;
cycleStartBlock = block.number;

for (uint i = 0; i < _tokenList.length; i++) {
tokenWhiteList[_tokenList[i]] = true;
tokenWhiteListArray.push(_tokenList[i]);
}

cycles[0].startBlocktime = block.timestamp;
}

function getCurrentCycleIndex() public view returns (uint256) {
Expand Down Expand Up @@ -333,21 +331,21 @@ contract DividendContract is Initializable, UUPSUpgradeable, ReentrancyGuardUpgr

// check point for the new cycle
function tryNewCycle() public {
uint256 currentBlock = block.number;
uint256 currentBlocktime = block.timestamp;

CycleInfo storage currentCycle = cycles[currentCycleIndex];
if (currentBlock - currentCycle.startBlock >= cycleMaxLength) {
if (currentBlocktime - currentCycle.startBlocktime >= cycleMaxLength) {
currentCycleIndex = currentCycleIndex + 1;
// console.log("enter new cycle %d, totalStaked %d", currentCycleIndex, totalStaked);
console.log("enter new cycle %d, totalStaked %d", currentCycleIndex, totalStaked);
CycleInfo storage newCycle = cycles[currentCycleIndex];
newCycle.startBlock = currentBlock;
newCycle.startBlocktime = currentBlocktime;
newCycle.totalStaked = totalStaked;

if (currentCycle.totalStaked == 0) {
newCycle.rewards = currentCycle.rewards;
}

emit NewCycle(currentCycleIndex, currentBlock);
emit NewCycle(currentCycleIndex, currentBlocktime);
}
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/dmc_bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract DMCBridge is Ownable {
}

function getClaimableDMC2(string calldata cookie) public view returns (uint256) {
return dmc1_to_dmc2[keccak256(abi.encodePacked(msg.sender, cookie))] * 79 / 100;
return dmc1_to_dmc2[keccak256(abi.encodePacked(msg.sender, cookie))];
}

function registerDMC1(address[] calldata recvAddress, string[] calldata cookie, uint256[] calldata dmc1Amount) onlyOwner public {
Expand All @@ -28,7 +28,7 @@ contract DMCBridge is Ownable {
function claimDMC2(string calldata cookie) public {
bytes32 key = keccak256(abi.encodePacked(msg.sender, cookie));
require(dmc1_to_dmc2[key] > 0, "no dmc1 amount");
uint256 dmc2Amount = dmc1_to_dmc2[key] * 79 / 100;
uint256 dmc2Amount = dmc1_to_dmc2[key];
dmc1_to_dmc2[key] = 0;

dmc2.transfer(msg.sender, dmc2Amount);
Expand Down
2 changes: 1 addition & 1 deletion contracts/exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract Exchange is Initializable, UUPSUpgradeable, OwnableUpgradeable {

dmc2gwt_rate = 210;
adjust_period = 21;
initial_dmc_balance = 768242.27 ether;
initial_dmc_balance = 972459 ether;

test_mode = true;

Expand Down
49 changes: 49 additions & 0 deletions scripts/deploy_dmc2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ethers, upgrades } from "hardhat";
import { DividendContract, Exchange } from "../typechain-types";

async function main() {
let signers = await ethers.getSigners();
let dmc = await (await ethers.deployContract("DMC", [
ethers.parseEther("1000000000"), // 总量10亿
["0x000000000EefEA4e8A67d7434a02054b955Da62c", "0xDDDDDdDd91f172a0ceA030d20f68348E0370fE66", "0xCcCCCCCC5b74A876dB192d55ef8e4A60EfA1Eb5C", "0xad82A5fb394a525835A3a6DC34C1843e19160CFA"],
[ethers.parseEther("450000000"), ethers.parseEther("4500000"), ethers.parseEther("45000000"), ethers.parseEther("500000")]])).waitForDeployment()

let dmcAddress = await dmc.getAddress();
console.log("DMC address:", dmcAddress);

let gwt = await (await ethers.deployContract("GWT", [[], []])).waitForDeployment();
let gwtAddress = await gwt.getAddress();
console.log("GWT address:", gwtAddress);

let dividend = (await (
await upgrades.deployProxy(
await ethers.getContractFactory("DividendContract"),
[dmcAddress, 7 * 24 * 60 * 60, [gwtAddress, ethers.ZeroAddress]],
{
initializer: "initialize",
kind: "uups",
timeout: 0
}
)
).waitForDeployment()) as unknown as DividendContract;

let dividendAddress = await dividend.getAddress();
console.log("Dividend address:", dividendAddress);

let exchange = await (await upgrades.deployProxy(await ethers.getContractFactory("Exchange"),
[await dmc.getAddress(), await gwt.getAddress(), dividendAddress, 7 * 24 * 60 * 60],
{
initializer: "initialize",
kind: "uups",
timeout: 0
})).waitForDeployment() as unknown as Exchange;
let exchangeAddr = await exchange.getAddress();
console.log("exchange address:", exchangeAddr);

console.log("enable mint");

await (await dmc.enableMinter([exchangeAddr])).wait();
await (await gwt.enableMinter([exchangeAddr])).wait();
}

main().then(() => process.exit(0));
Loading

0 comments on commit 663ae5c

Please sign in to comment.