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

F/pots #28

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"rules": {
"prettier/prettier": "error",
"compiler-version": "off",
"func-visibility": ["warn", { "ignoreConstructors": true }]
"func-visibility": ["warn", { "ignoreConstructors": true }],
"not-rely-on-time": "off"
},
"plugins": ["prettier"]
}
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"name": "@buttergov/molten-core",
"version": "0.1.0",
"description": "Molten core contracts",
"files": ["out/"],
"files": [
"out/"
],
"directories": {
"lib": "lib",
"test": "test"
Expand Down
2 changes: 1 addition & 1 deletion script/SetupTestEnv.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
pragma solidity ^0.8.17;

import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/MToken.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
// solhint-disable no-empty-blocks
pragma solidity ^0.8.13;
pragma solidity ^0.8.17;

import {ERC20, ERC20Pausable, Pausable} from "openzeppelin/token/ERC20/extensions/ERC20Pausable.sol";
import {Owned} from "solmate/auth/Owned.sol";
Expand Down
106 changes: 106 additions & 0 deletions src/MoltenCampaign.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// SPDX-License-Identifier: UNLICENSED
// solhint-disable not-rely-on-time
pragma solidity ^0.8.17;

import {MToken} from "./MToken.sol";
import {IERC20Votes} from "./interfaces/IERC20Votes.sol";

contract MoltenElection {
IERC20Votes public daoToken;
// Threshold in daoToken-weis.
uint256 public threshold;
uint128 public duration;
uint128 public cooldownDuration;

constructor(
address daoTokenAddress,
uint256 _threshold,
uint128 _duration,
uint128 _cooldownDuration
) {
daoToken = IERC20Votes(daoTokenAddress);
threshold = _threshold;
duration = _duration;
cooldownDuration = _cooldownDuration;
}

// 🎨 We could further dependency-inject by having a separate libs
// MTokenDeployer and MoltenCampaignDeployer which addresses are passed as
// argument of the constructor/function.
function makeCampaign(string calldata delegateName)
external
returns (MoltenCampaign)
{
MToken mToken = new MToken(
string.concat("Molten ", daoToken.name()),
string.concat("m", daoToken.symbol(), "-", delegateName),
address(this)
);
MoltenCampaign campaign = new MoltenCampaign(
msg.sender,
address(this),
address(mToken)
);
mToken.transferOwnership(address(campaign));
return campaign;
}
}

contract MoltenCampaign {
// Immutable props.
address public representative;
MoltenElection public election;
MToken public mToken;
Comment on lines +108 to +110
Copy link
Contributor

Choose a reason for hiding this comment

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

You can further enforce immutability of these system variables by adding the immutable modifier to these variables:

    address public immutable representative;
    MoltenElection public immutable election;
    MToken public immutable mToken;

also:

Compared to regular state variables, the gas costs of constant and immutable variables are much lower.
Immutable variables are evaluated once at construction time and their value is copied to all the places in the code where they are accessed.


// Mutable props.
uint256 public totalStaked;
mapping(address => uint256) public staked;
uint256 public cooldownEnd;

constructor(
address _representative,
address electionAddress,
address mTokenAddress
) {
representative = _representative;
election = MoltenElection(electionAddress);
mToken = MToken(mTokenAddress);
}

function _getDaoToken() private view returns (IERC20Votes) {
return IERC20Votes(election.daoToken());
}

function _resetCooldown() internal {
cooldownEnd = block.timestamp + election.cooldownDuration();
}

function stake(uint256 amount) public {
staked[msg.sender] += amount;
totalStaked += amount;

mToken.mint(msg.sender, amount);
_resetCooldown();
_getDaoToken().transferFrom(msg.sender, address(this), amount);
}

function unstake() public {
uint256 _staked = staked[msg.sender];
require(_staked > 0, "Molten: unstake 0");

staked[msg.sender] = 0;
totalStaked -= _staked;

mToken.burn(msg.sender, _staked);
_resetCooldown();
_getDaoToken().transferFrom(address(this), msg.sender, _staked);
}

function takeOffice() public {
require(
totalStaked >= election.threshold(),
"Molten: threshold not reached"
);
require(block.timestamp >= cooldownEnd, "Molten: cooldown ongoing");
}
}
2 changes: 1 addition & 1 deletion src/MoltenFunding.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
// solhint-disable not-rely-on-time
pragma solidity ^0.8.13;
pragma solidity ^0.8.17;

import {IERC20} from "openzeppelin/token/ERC20/ERC20.sol";
import {ReentrancyGuard} from "solmate/utils/ReentrancyGuard.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/UniswapV3Adapter.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.8.13;
pragma solidity ^0.8.17;

import {IUniswapV3OracleConsulter} from "molten-oracle/interfaces/IUniswapV3OracleConsulter.sol";

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IERC20Votes.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
pragma solidity ^0.8.17;

import {IERC20} from "openzeppelin/token/ERC20/ERC20.sol";

Expand Down
Loading