-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created new fixture contracts for testing
- Loading branch information
Showing
29 changed files
with
731 additions
and
469 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
test/fixture-projects/hardhat-project-minimal-ethers/contracts/Contracts.sol
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
test/fixture-projects/hardhat-project-minimal-ethers/contracts/GovToken.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; | ||
import {ERC20Votes, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol"; | ||
|
||
import {VotingPowerLib} from "./libs/VotingPowerLib.sol"; | ||
import {TimestampClockLib} from "./libs/TimestampClockLib.sol"; | ||
|
||
/** | ||
* @title GovToken | ||
* | ||
* @notice This is an ERC20 token that includes vote delegation. | ||
* It is intentionally designed with added complexity for testing purposes. | ||
*/ | ||
contract GovToken is ERC20Votes, Ownable { | ||
using VotingPowerLib for uint256; | ||
|
||
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) EIP712(name_, version()) Ownable(msg.sender) { | ||
_mint(msg.sender, 1000000); | ||
} | ||
|
||
function decimals() public pure override returns (uint8) { | ||
return 3; | ||
} | ||
|
||
function version() public pure returns (string memory) { | ||
return "1"; | ||
} | ||
|
||
function mint(address to_, uint256 amount_) external onlyOwner { | ||
_mint(to_, amount_); | ||
} | ||
|
||
function burn(address from_, uint256 amount_) external onlyOwner { | ||
_burn(from_, amount_); | ||
} | ||
|
||
function getUserVotingPower(address account_) public view returns (uint256) { | ||
return getVotes(account_).calculateUserVotingPower(decimals()); | ||
} | ||
|
||
function getPastUserVotingPower(address account_, uint256 timestamp_) public view returns (uint256) { | ||
return getPastVotes(account_, timestamp_).calculateUserVotingPower(decimals()); | ||
} | ||
|
||
function getVotingPowerThreshold() public view returns (uint256) { | ||
return _getTotalSupply().calculateVotingPowerThreshold(decimals()); | ||
} | ||
|
||
function getPastVotingPowerThreshold(uint256 timestamp_) public view returns (uint256) { | ||
return getPastTotalSupply(timestamp_).calculateVotingPowerThreshold(decimals()); | ||
} | ||
|
||
function clock() public view override returns (uint48) { | ||
return TimestampClockLib.clock(); | ||
} | ||
|
||
function CLOCK_MODE() public view override returns (string memory) { | ||
return TimestampClockLib.CLOCK_MODE(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/fixture-projects/hardhat-project-minimal-ethers/contracts/libs/TimestampClockLib.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
import {Time} from "@openzeppelin/contracts/utils/types/Time.sol"; | ||
import {Votes} from "@openzeppelin/contracts/governance/utils/Votes.sol"; | ||
|
||
library TimestampClockLib { | ||
using Time for *; | ||
|
||
function clock() public view returns (uint48) { | ||
return Time.timestamp(); | ||
} | ||
|
||
function CLOCK_MODE() public view returns (string memory) { | ||
if (clock() != Time.timestamp()) { | ||
revert Votes.ERC6372InconsistentClock(); | ||
} | ||
return "mode=timestamp"; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test/fixture-projects/hardhat-project-minimal-ethers/contracts/libs/VotingPowerLib.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
import "@openzeppelin/contracts/utils/math/Math.sol"; | ||
|
||
library VotingPowerLib { | ||
using Math for *; | ||
|
||
function calculateUserVotingPower(uint256 tokenAmount_, uint8 decimals_) external pure returns (uint256) { | ||
uint256 oneToken_ = 10 ** decimals_; | ||
|
||
if (tokenAmount_ <= oneToken_) { | ||
return 0; | ||
} | ||
|
||
return (tokenAmount_ / oneToken_).log2(); | ||
} | ||
|
||
function calculateVotingPowerThreshold(uint256 totalSupply_, uint8 decimals_) external pure returns (uint256) { | ||
uint256 oneToken_ = 10 ** decimals_; | ||
|
||
if (totalSupply_ <= oneToken_) { | ||
return 0; | ||
} | ||
|
||
return (totalSupply_ / oneToken_).log10(); | ||
} | ||
} |
56 changes: 0 additions & 56 deletions
56
test/fixture-projects/hardhat-project-minimal-truffle/contracts/Contracts.sol
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.