Skip to content

Commit

Permalink
Max proposal duration and min stack can be set when initialize contract
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiushi committed Aug 2, 2024
1 parent 8875d58 commit 441242e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 7 additions & 3 deletions contracts/proposal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,28 @@ contract ProposalContract is Initializable, UUPSUpgradeable, ReentrancyGuardUpgr

mapping (uint256 => Proposal) public proposals;
uint256 curProposalId;
uint256 maxDuration;
uint256 minStack;

event CreateProposal(uint256 id);
event Vote(uint256 indexed id, address indexed voter, bool support, uint256 amount, string desc);

function initialize(address dividendAddress) public initializer {
function initialize(address dividendAddress, uint256 _maxDuration, uint256 _minStack) public initializer {
__UUPSUpgradeable_init();
__ReentrancyGuard_init();
__Ownable_init(msg.sender);

dividendContract = DividendContract(payable(dividendAddress));
maxDuration = _maxDuration;
minStack = _minStack;
}

function _authorizeUpgrade(address) internal override onlyOwner {}

function createProposal(string calldata _title, string calldata desc, uint256 duration) public {
require(duration <= 3 days, "Duration too long");
require(duration <= maxDuration, "Duration too long");
uint256 lockedAmount = dividendContract.updateLockState(msg.sender);
require(lockedAmount >= 50000 ether, "Locked amount not enough");
require(lockedAmount >= minStack, "Locked amount not enough");
uint256 proposalId = ++curProposalId;

proposals[proposalId].title = _title;
Expand Down
7 changes: 6 additions & 1 deletion test/test_proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Proposal", function () {

proposal = await upgrades.deployProxy(
await ethers.getContractFactory("ProposalContract"),
[await dividend.getAddress()]) as unknown as ProposalContract;
[await dividend.getAddress(), 3*24*60*60, ethers.parseEther("50000")]) as unknown as ProposalContract;

await (await dividend.updateProposalContract(await proposal.getAddress())).wait();
await (await dmc.transfer(signers[1].address, ethers.parseEther("100000"))).wait();
Expand Down Expand Up @@ -60,6 +60,11 @@ describe("Proposal", function () {

// cant unstack because lock time extended
await expect(dividend.unstake(ethers.parseEther("10000"))).to.be.revertedWith("Unstake is locked");

// pass 1 day again
await mine(2, {interval: 24*60*60})
await expect(dividend.unstake(ethers.parseEther("10000"))).to.emit(dividend, "Unstake").withArgs(signers[0].address, ethers.parseEther("10000"));

});

it("vote proposal", async () => {
Expand Down

0 comments on commit 441242e

Please sign in to comment.