mirror of https://github.com/logos-co/staking.git
refactor: migrate repository to foundry-template (#6)
This commit migrates the repo to our foundry template, which ensures we have consistent tooling across smart contract repositories that are maintained by Vac. This removes all hardhat related files and workflows and replaces them with more perfomant foundry workflows. It also sets up tests, CI and linting.
This commit is contained in:
parent
39071e49fe
commit
2e7c5148b4
|
@ -0,0 +1,20 @@
|
|||
# EditorConfig http://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# All files
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.sol]
|
||||
indent_size = 4
|
||||
|
||||
[*.tree]
|
||||
indent_size = 1
|
||||
|
20
.env.example
20
.env.example
|
@ -1,9 +1,11 @@
|
|||
INFURA_API_KEY=""
|
||||
ETHERSCAN_API_KEY=""
|
||||
ETHERSCAN_OPT_API_KEY=""
|
||||
|
||||
GOERLI_MNEMONIC=""
|
||||
MAINNET_MNEMONIC=""
|
||||
|
||||
GOERLI_ALCHEMY_KEY=""
|
||||
OP_GOERLI_ALCHEMY_KEY=""
|
||||
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY"
|
||||
export API_KEY_ARBISCAN="YOUR_API_KEY_ARBISCAN"
|
||||
export API_KEY_BSCSCAN="YOUR_API_KEY_BSCSCAN"
|
||||
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN"
|
||||
export API_KEY_GNOSISSCAN="YOUR_API_KEY_GNOSISSCAN"
|
||||
export API_KEY_INFURA="YOUR_API_KEY_INFURA"
|
||||
export API_KEY_OPTIMISTIC_ETHERSCAN="YOUR_API_KEY_OPTIMISTIC_ETHERSCAN"
|
||||
export API_KEY_POLYGONSCAN="YOUR_API_KEY_POLYGONSCAN"
|
||||
export API_KEY_SNOWTRACE="YOUR_API_KEY_SNOWTRACE"
|
||||
export MNEMONIC="YOUR_MNEMONIC"
|
||||
export FOUNDRY_PROFILE="default"
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
lib/** linguist-vendored
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
## Description
|
||||
|
||||
Describe the changes made in your pull request here.
|
||||
|
||||
## Checklist
|
||||
|
||||
Ensure you completed **all of the steps** below before submitting your pull request:
|
||||
|
||||
- [ ] Added natspec comments?
|
||||
- [ ] Ran `forge snapshot`?
|
||||
- [ ] Ran `yarn lint`?
|
||||
- [ ] Ran `forge test`?
|
|
@ -0,0 +1,119 @@
|
|||
name: "CI"
|
||||
|
||||
env:
|
||||
API_KEY_ALCHEMY: ${{ secrets.API_KEY_ALCHEMY }}
|
||||
FOUNDRY_PROFILE: "ci"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: "Check out the repo"
|
||||
uses: "actions/checkout@v3"
|
||||
with:
|
||||
submodules: "recursive"
|
||||
|
||||
- name: "Install Foundry"
|
||||
uses: "foundry-rs/foundry-toolchain@v1"
|
||||
|
||||
- name: "Install Pnpm"
|
||||
uses: "pnpm/action-setup@v2"
|
||||
with:
|
||||
version: "8"
|
||||
|
||||
- name: "Install Node.js"
|
||||
uses: "actions/setup-node@v3"
|
||||
with:
|
||||
cache: "pnpm"
|
||||
node-version: "lts/*"
|
||||
|
||||
- name: "Install the Node.js dependencies"
|
||||
run: "pnpm install"
|
||||
|
||||
- name: "Lint the contracts"
|
||||
run: "pnpm lint"
|
||||
|
||||
- name: "Add lint summary"
|
||||
run: |
|
||||
echo "## Lint result" >> $GITHUB_STEP_SUMMARY
|
||||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
build:
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: "Check out the repo"
|
||||
uses: "actions/checkout@v3"
|
||||
with:
|
||||
submodules: "recursive"
|
||||
|
||||
- name: "Install Foundry"
|
||||
uses: "foundry-rs/foundry-toolchain@v1"
|
||||
|
||||
- name: "Build the contracts and print their size"
|
||||
run: "forge build --sizes"
|
||||
|
||||
- name: "Add build summary"
|
||||
run: |
|
||||
echo "## Build result" >> $GITHUB_STEP_SUMMARY
|
||||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
test:
|
||||
needs: ["lint", "build"]
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: "Check out the repo"
|
||||
uses: "actions/checkout@v3"
|
||||
with:
|
||||
submodules: "recursive"
|
||||
|
||||
- name: "Install Foundry"
|
||||
uses: "foundry-rs/foundry-toolchain@v1"
|
||||
|
||||
- name: "Show the Foundry config"
|
||||
run: "forge config"
|
||||
|
||||
- name: "Generate a fuzz seed that changes weekly to avoid burning through RPC allowance"
|
||||
run: >
|
||||
echo "FOUNDRY_FUZZ_SEED=$(
|
||||
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800))
|
||||
)" >> $GITHUB_ENV
|
||||
|
||||
- name: "Run the tests"
|
||||
run: "forge test"
|
||||
|
||||
- name: "Add test summary"
|
||||
run: |
|
||||
echo "## Tests result" >> $GITHUB_STEP_SUMMARY
|
||||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
coverage:
|
||||
needs: ["lint", "build"]
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: "Check out the repo"
|
||||
uses: "actions/checkout@v3"
|
||||
with:
|
||||
submodules: "recursive"
|
||||
|
||||
- name: "Install Foundry"
|
||||
uses: "foundry-rs/foundry-toolchain@v1"
|
||||
|
||||
- name: "Generate the coverage report using the unit and the integration tests"
|
||||
run: 'forge coverage --match-path "test/**/*.sol" --report lcov'
|
||||
|
||||
- name: "Upload coverage report to Codecov"
|
||||
uses: "codecov/codecov-action@v3"
|
||||
with:
|
||||
files: "./lcov.info"
|
||||
|
||||
- name: "Add coverage summary"
|
||||
run: |
|
||||
echo "## Coverage result" >> $GITHUB_STEP_SUMMARY
|
||||
echo "✅ Uploaded to Codecov" >> $GITHUB_STEP_SUMMARY
|
|
@ -1,13 +1,24 @@
|
|||
|
||||
# directories
|
||||
cache
|
||||
node_modules
|
||||
.env
|
||||
coverage
|
||||
coverage.json
|
||||
typechain
|
||||
typechain-types
|
||||
out
|
||||
|
||||
# files
|
||||
*.env
|
||||
*.log
|
||||
.DS_Store
|
||||
.pnp.*
|
||||
lcov.info
|
||||
yarn.lock
|
||||
|
||||
# broadcasts
|
||||
!broadcast
|
||||
broadcast/*
|
||||
broadcast/*/31337/
|
||||
|
||||
# Hardhat files
|
||||
cache
|
||||
artifacts
|
||||
|
||||
typechain
|
||||
typechain-types
|
||||
gmx-contracts
|
||||
node_modules
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[submodule "lib/forge-std"]
|
||||
branch = "v1"
|
||||
path = lib/forge-std
|
||||
url = https://github.com/foundry-rs/forge-std
|
||||
|
||||
[submodule "lib/openzeppelin-contracts"]
|
||||
path = lib/openzeppelin-contracts
|
||||
url = https://github.com/OpenZeppelin/openzeppelin-contracts
|
|
@ -0,0 +1,7 @@
|
|||
bracketSpacing: true
|
||||
printWidth: 120
|
||||
proseWrap: "always"
|
||||
singleQuote: false
|
||||
tabWidth: 2
|
||||
trailingComma: "all"
|
||||
useTabs: false
|
|
@ -0,0 +1,19 @@
|
|||
# directories
|
||||
broadcast
|
||||
cache
|
||||
lib
|
||||
node_modules
|
||||
out
|
||||
|
||||
# files
|
||||
*.env
|
||||
*.log
|
||||
.DS_Store
|
||||
.pnp.*
|
||||
lcov.info
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
yarn.lock
|
||||
|
||||
slither.config.json
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"extends": "solhint:recommended",
|
||||
"rules": {
|
||||
"code-complexity": ["error", 8],
|
||||
"compiler-version": ["error", ">=0.8.19"],
|
||||
"func-name-mixedcase": "off",
|
||||
"func-visibility": ["error", { "ignoreConstructors": true }],
|
||||
"max-line-length": ["error", 120],
|
||||
"named-parameters-mapping": "warn",
|
||||
"no-console": "off",
|
||||
"not-rely-on-time": "off"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"[solidity]": {
|
||||
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
|
||||
},
|
||||
"[toml]": {
|
||||
"editor.defaultFormatter": "tamasfe.even-better-toml"
|
||||
},
|
||||
"npm.exclude": "**/lib/**",
|
||||
"solidity.formatter": "forge"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
## Protocol properties and invariants
|
||||
|
||||
Below is a list of all documented properties and invariants of this project that must hold true.
|
||||
|
||||
- **Property** - Describes the property of the project / protocol that should ultimately be tested and formaly verified.
|
||||
- **Type** - Properties are split into 5 main types: **Valid State**, **State Transition**, **Variable Transition**,
|
||||
**High-Level Property**, **Unit Test**
|
||||
- **Risk** - One of **High**, **Medium** and **Low**, depending on the property's risk factor
|
||||
- **Tested** - Whether this property has been (fuzz) tested
|
||||
|
||||
| **Property** | **Type** | **Risk** | **Tested** |
|
||||
| ------------ | -------- | -------- | ---------- |
|
||||
| | | | |
|
||||
| | | | |
|
||||
| | | | |
|
|
@ -0,0 +1,195 @@
|
|||
# SNT Staking contracts [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry]
|
||||
|
||||
[gha]: https://github.com/vacp2p/foundry-template/actions
|
||||
[gha-badge]: https://github.com/vacp2p/foundry-template/actions/workflows/ci.yml/badge.svg
|
||||
[foundry]: https://getfoundry.sh/
|
||||
[foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg
|
||||
|
||||
A Foundry-based template for developing Solidity smart contracts, with sensible defaults.
|
||||
|
||||
This is a fork of [PaulRBerg's template](https://github.com/PaulRBerg/foundry-template) and adjusted to Vac's smart
|
||||
contracts unit's needs. See [Upstream differences](#upstream-differences) to learn more about how this template differs
|
||||
from Paul's.
|
||||
|
||||
## What's Inside
|
||||
|
||||
- [Forge](https://github.com/foundry-rs/foundry/blob/master/forge): compile, test, fuzz, format, and deploy smart
|
||||
contracts
|
||||
- [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and cheatcodes for testing
|
||||
- [Solhint Community](https://github.com/solhint-community/solhint-community): linter for Solidity code
|
||||
|
||||
## Getting Started
|
||||
|
||||
Click the [`Use this template`](https://github.com/vacp2p/foundry-template/generate) button at the top of the page to
|
||||
create a new repository with this repo as the initial state.
|
||||
|
||||
Or, if you prefer to install the template manually:
|
||||
|
||||
```sh
|
||||
$ mkdir my-project
|
||||
$ cd my-project
|
||||
$ forge init --template vacp2p/foundry-template
|
||||
$ pnpm install # install Solhint, Prettier, and other Node.js deps
|
||||
```
|
||||
|
||||
If this is your first time with Foundry, check out the
|
||||
[installation](https://github.com/foundry-rs/foundry#installation) instructions.
|
||||
|
||||
## Features
|
||||
|
||||
This template builds upon the frameworks and libraries mentioned above, so for details about their specific features,
|
||||
please consult their respective documentation.
|
||||
|
||||
For example, if you're interested in exploring Foundry in more detail, you should look at the
|
||||
[Foundry Book](https://book.getfoundry.sh/). In particular, you may be interested in reading the
|
||||
[Writing Tests](https://book.getfoundry.sh/forge/writing-tests.html) tutorial.
|
||||
|
||||
### Upstream differences
|
||||
|
||||
As mentioned above, this template is a fork with adjustments specific to the needs of Vac's smart contract service unit.
|
||||
These differences are:
|
||||
|
||||
- **Removal of [PRBTest](https://github.com/PaulRBerg/prb-test)** - In an attempt to keep dependence on third-party code
|
||||
low, we've decided to remove this library as a standard dependency of every project within Vac. If we do see a need
|
||||
for it, we might bring it back in the future.
|
||||
- \*\*`PROPERTIES.md` - For invariant testing and formal verification, we've introduced a `PROPERTIES.md` to document
|
||||
all protocol properties that must hold true.
|
||||
|
||||
### Sensible Defaults
|
||||
|
||||
This template comes with a set of sensible default configurations for you to use. These defaults can be found in the
|
||||
following files:
|
||||
|
||||
```text
|
||||
├── .editorconfig
|
||||
├── .gitignore
|
||||
├── .prettierignore
|
||||
├── .prettierrc.yml
|
||||
├── .solhint.json
|
||||
├── foundry.toml
|
||||
├── remappings.txt
|
||||
└── slither.config.json
|
||||
```
|
||||
|
||||
### VSCode Integration
|
||||
|
||||
This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic
|
||||
Foundation's [Solidity extension](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity).
|
||||
|
||||
For guidance on how to integrate a Foundry project in VSCode, please refer to this
|
||||
[guide](https://book.getfoundry.sh/config/vscode).
|
||||
|
||||
### GitHub Actions
|
||||
|
||||
This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull
|
||||
request made to the `main` branch.
|
||||
|
||||
You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).
|
||||
|
||||
## Writing Tests
|
||||
|
||||
If you would like to view the logs in the terminal output you can add the `-vvv` flag and use
|
||||
[console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog).
|
||||
|
||||
This template comes with an example test contract [Foo.t.sol](./test/Foo.t.sol)
|
||||
|
||||
## Usage
|
||||
|
||||
This is a list of the most frequently needed commands.
|
||||
|
||||
### Build
|
||||
|
||||
Build the contracts:
|
||||
|
||||
```sh
|
||||
$ forge build
|
||||
```
|
||||
|
||||
### Clean
|
||||
|
||||
Delete the build artifacts and cache directories:
|
||||
|
||||
```sh
|
||||
$ forge clean
|
||||
```
|
||||
|
||||
### Compile
|
||||
|
||||
Compile the contracts:
|
||||
|
||||
```sh
|
||||
$ forge build
|
||||
```
|
||||
|
||||
### Coverage
|
||||
|
||||
Get a test coverage report:
|
||||
|
||||
```sh
|
||||
$ forge coverage
|
||||
```
|
||||
|
||||
### Deploy
|
||||
|
||||
Deploy to Anvil:
|
||||
|
||||
```sh
|
||||
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545
|
||||
```
|
||||
|
||||
For this script to work, you need to have a `MNEMONIC` environment variable set to a valid
|
||||
[BIP39 mnemonic](https://iancoleman.io/bip39/).
|
||||
|
||||
For instructions on how to deploy to a testnet or mainnet, check out the
|
||||
[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial.
|
||||
|
||||
### Format
|
||||
|
||||
Format the contracts:
|
||||
|
||||
```sh
|
||||
$ forge fmt
|
||||
```
|
||||
|
||||
### Gas Usage
|
||||
|
||||
Get a gas report:
|
||||
|
||||
```sh
|
||||
$ forge test --gas-report
|
||||
```
|
||||
|
||||
### Lint
|
||||
|
||||
Lint the contracts:
|
||||
|
||||
```sh
|
||||
$ pnpm lint
|
||||
```
|
||||
|
||||
### Test
|
||||
|
||||
Run the tests:
|
||||
|
||||
```sh
|
||||
$ forge test
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
1. Foundry uses [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to manage dependencies. For
|
||||
detailed instructions on working with dependencies, please refer to the
|
||||
[guide](https://book.getfoundry.sh/projects/dependencies.html) in the book
|
||||
2. You don't have to create a `.env` file, but filling in the environment variables may be useful when debugging and
|
||||
testing against a fork.
|
||||
|
||||
## Related Efforts
|
||||
|
||||
- [abigger87/femplate](https://github.com/abigger87/femplate)
|
||||
- [cleanunicorn/ethereum-smartcontract-template](https://github.com/cleanunicorn/ethereum-smartcontract-template)
|
||||
- [foundry-rs/forge-template](https://github.com/foundry-rs/forge-template)
|
||||
- [FrankieIsLost/forge-template](https://github.com/FrankieIsLost/forge-template)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under MIT.
|
|
@ -0,0 +1,28 @@
|
|||
codecov:
|
||||
require_ci_to_pass: false
|
||||
comment: false
|
||||
ignore:
|
||||
- "script"
|
||||
- "test"
|
||||
coverage:
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
# advanced settings
|
||||
|
||||
# Prevents PR from being blocked with a reduction in coverage.
|
||||
# Note, if we want to re-enable this, a `threshold` value can be used
|
||||
# allow coverage to drop by x% while still posting a success status.
|
||||
# `informational`: https://docs.codecov.com/docs/commit-status#informational
|
||||
# `threshold`: https://docs.codecov.com/docs/commit-status#threshold
|
||||
informational: true
|
||||
patch:
|
||||
default:
|
||||
# advanced settings
|
||||
|
||||
# Prevents PR from being blocked with a reduction in coverage.
|
||||
# Note, if we want to re-enable this, a `threshold` value can be used
|
||||
# allow coverage to drop by x% while still posting a success status.
|
||||
# `informational`: https://docs.codecov.com/docs/commit-status#informational
|
||||
# `threshold`: https://docs.codecov.com/docs/commit-status#threshold
|
||||
informational: true
|
|
@ -2,12 +2,11 @@
|
|||
|
||||
pragma solidity ^0.8.18;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "./StakeVault.sol";
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import { StakeVault } from "./StakeVault.sol";
|
||||
|
||||
contract StakeManager is Ownable {
|
||||
|
||||
struct Account {
|
||||
uint256 lockUntil;
|
||||
uint256 balance;
|
||||
|
@ -19,21 +18,19 @@ contract StakeManager is Ownable {
|
|||
|
||||
struct Epoch {
|
||||
uint256 startTime;
|
||||
uint256 epochReward;
|
||||
uint256 totalSupply;
|
||||
uint256 epochReward;
|
||||
uint256 totalSupply;
|
||||
}
|
||||
|
||||
uint256 public constant EPOCH_SIZE = 1 weeks;
|
||||
uint256 public constant YEAR = 365 days;
|
||||
uint256 public constant MP_APY = 1;
|
||||
uint256 public constant MAX_BOOST = 4;
|
||||
|
||||
uint256 public constant YEAR = 365 days;
|
||||
uint256 public constant MP_APY = 1;
|
||||
uint256 public constant MAX_BOOST = 4;
|
||||
|
||||
mapping (address => Account) accounts;
|
||||
mapping (uint256 => Epoch) epochs;
|
||||
mapping (bytes32 => bool) isVault;
|
||||
mapping(address => Account) accounts;
|
||||
mapping(uint256 => Epoch) epochs;
|
||||
mapping(bytes32 => bool) isVault;
|
||||
|
||||
|
||||
uint256 public currentEpoch;
|
||||
uint256 public pendingReward;
|
||||
uint256 public multiplierSupply;
|
||||
|
@ -41,15 +38,16 @@ contract StakeManager is Ownable {
|
|||
StakeManager public migration;
|
||||
StakeManager public immutable oldManager;
|
||||
ERC20 public immutable stakedToken;
|
||||
modifier onlyVault {
|
||||
|
||||
modifier onlyVault() {
|
||||
require(isVault[msg.sender.codehash], "Not a vault");
|
||||
_;
|
||||
}
|
||||
|
||||
constructor(ERC20 _stakedToken, StakeManager _oldManager) Ownable() {
|
||||
constructor(address _stakedToken, address _oldManager) {
|
||||
epochs[0].startTime = block.timestamp;
|
||||
oldManager = _oldManager;
|
||||
stakedToken = _stakedToken;
|
||||
oldManager = StakeManager(_oldManager);
|
||||
stakedToken = ERC20(_stakedToken);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,19 +114,20 @@ contract StakeManager is Ownable {
|
|||
* @param _limitEpoch Until what epoch it should be executed
|
||||
*/
|
||||
function executeAccount(address _vault, uint256 _limitEpoch) external {
|
||||
processAccount(accounts[_vault], _limitEpoch);
|
||||
processAccount(accounts[_vault], _limitEpoch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notice Enables a contract class to interact with staking functions
|
||||
* @param _codehash bytecode hash of contract
|
||||
*/
|
||||
function setVault(bytes32 _codehash) external onlyOwner {
|
||||
isVault[_codehash] = true;
|
||||
isVault[_codehash] = true;
|
||||
}
|
||||
/**
|
||||
* @notice Migrate account to new manager.
|
||||
*/
|
||||
|
||||
function migrate() external onlyVault returns (StakeManager newManager) {
|
||||
require(address(migration) != address(0), "Migration not available");
|
||||
Account storage account = accounts[msg.sender];
|
||||
|
@ -148,22 +147,30 @@ contract StakeManager is Ownable {
|
|||
require(msg.sender == address(oldManager), "Unauthorized");
|
||||
stakedToken.transferFrom(address(oldManager), address(this), _account.balance);
|
||||
accounts[_vault] = _account;
|
||||
}
|
||||
}
|
||||
|
||||
function calcMaxMultiplierIncrease(uint256 _increasedMultiplier, uint256 _currentMp, uint256 _lockUntil, uint256 _stake) private view returns(uint256 _maxToIncrease) {
|
||||
function calcMaxMultiplierIncrease(
|
||||
uint256 _increasedMultiplier,
|
||||
uint256 _currentMp,
|
||||
uint256 _lockUntil,
|
||||
uint256 _stake
|
||||
)
|
||||
private
|
||||
view
|
||||
returns (uint256 _maxToIncrease)
|
||||
{
|
||||
uint256 newMp = _increasedMultiplier + _currentMp;
|
||||
if(block.timestamp > _lockUntil){
|
||||
if (block.timestamp > _lockUntil) {
|
||||
//not locked, limit to max_boost
|
||||
return newMp > _stake*MAX_BOOST ? _stake*MAX_BOOST - _currentMp : _increasedMultiplier;
|
||||
return newMp > _stake * MAX_BOOST ? _stake * MAX_BOOST - _currentMp : _increasedMultiplier;
|
||||
} else {
|
||||
// locked, ignore cap
|
||||
return _increasedMultiplier;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function processEpoch() private {
|
||||
if(block.timestamp >= epochEnd()){
|
||||
if (block.timestamp >= epochEnd()) {
|
||||
//finalize current epoch
|
||||
epochs[currentEpoch].epochReward = epochReward();
|
||||
epochs[currentEpoch].totalSupply = totalSupply();
|
||||
|
@ -184,35 +191,44 @@ contract StakeManager is Ownable {
|
|||
//mint multipliers to that epoch
|
||||
mintMultiplier(account, iEpoch.startTime + EPOCH_SIZE);
|
||||
uint256 userSupply = account.balance + account.multiplier;
|
||||
uint256 userShare = userSupply / iEpoch.totalSupply; //TODO: might lose precision, multiply by 100 and divide back later?
|
||||
userReward += userShare * iEpoch.epochReward;
|
||||
uint256 userShare = userSupply / iEpoch.totalSupply; //TODO: might lose precision, multiply by 100 and
|
||||
// divide back later?
|
||||
userReward += userShare * iEpoch.epochReward;
|
||||
}
|
||||
account.epoch = userEpoch;
|
||||
if(userReward > 0){
|
||||
if (userReward > 0) {
|
||||
pendingReward -= userReward;
|
||||
stakedToken.transfer(account.rewardAddress, userReward);
|
||||
}
|
||||
mintMultiplier(account, block.timestamp);
|
||||
}
|
||||
|
||||
|
||||
function mintMultiplier(Account storage account, uint256 processTime) private {
|
||||
uint256 deltaTime = processTime - account.lastMint;
|
||||
uint256 deltaTime = processTime - account.lastMint;
|
||||
account.lastMint = processTime;
|
||||
uint256 increasedMultiplier = calcMaxMultiplierIncrease(
|
||||
account.balance * (MP_APY/YEAR * deltaTime),
|
||||
account.multiplier, account.lockUntil, account.balance);
|
||||
account.balance * (MP_APY / YEAR * deltaTime), account.multiplier, account.lockUntil, account.balance
|
||||
);
|
||||
account.multiplier += increasedMultiplier;
|
||||
multiplierSupply += increasedMultiplier;
|
||||
}
|
||||
|
||||
function mintIntialMultiplier(Account storage account, uint256 lockTime, uint256 amount, uint256 initMint) private {
|
||||
function mintIntialMultiplier(
|
||||
Account storage account,
|
||||
uint256 lockTime,
|
||||
uint256 amount,
|
||||
uint256 initMint
|
||||
)
|
||||
private
|
||||
{
|
||||
//if balance still locked, multipliers must be minted from difference of time.
|
||||
uint256 dT = account.lockUntil > block.timestamp ? block.timestamp + lockTime - account.lockUntil : lockTime;
|
||||
account.lockUntil = block.timestamp + lockTime;
|
||||
uint256 increasedMultiplier = amount * ((dT/YEAR)+initMint);
|
||||
uint256 dT = account.lockUntil > block.timestamp ? block.timestamp + lockTime - account.lockUntil : lockTime;
|
||||
account.lockUntil = block.timestamp + lockTime;
|
||||
uint256 increasedMultiplier = amount * ((dT / YEAR) + initMint);
|
||||
account.lastMint = block.timestamp;
|
||||
increasedMultiplier = account.multiplier+increasedMultiplier > (account.balance*(MAX_BOOST+(dT/YEAR))) ? account.balance*(MAX_BOOST+(dT/YEAR))-account.multiplier : increasedMultiplier; // checks if MPs are within (lock_time_in_years+MAX_BOOST)*stake
|
||||
increasedMultiplier = account.multiplier + increasedMultiplier > (account.balance * (MAX_BOOST + (dT / YEAR)))
|
||||
? account.balance * (MAX_BOOST + (dT / YEAR)) - account.multiplier
|
||||
: increasedMultiplier; // checks if MPs are within (lock_time_in_years+MAX_BOOST)*stake
|
||||
multiplierSupply += increasedMultiplier;
|
||||
account.multiplier += increasedMultiplier;
|
||||
}
|
||||
|
@ -228,5 +244,4 @@ contract StakeManager is Ownable {
|
|||
function epochEnd() public view returns (uint256) {
|
||||
return epochs[currentEpoch].startTime + EPOCH_SIZE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,17 @@
|
|||
|
||||
pragma solidity ^0.8.18;
|
||||
|
||||
import "./StakeManager.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import { StakeManager } from "./StakeManager.sol";
|
||||
|
||||
/**
|
||||
* @title StakeVault
|
||||
* @author Ricardo Guilherme Schmidt <ricardo3@status.im>
|
||||
* @notice Secures user stake
|
||||
*/
|
||||
contract StakeVault is Ownable {
|
||||
|
||||
contract StakeVault is Ownable {
|
||||
StakeManager private stakeManager;
|
||||
ERC20 immutable stakedToken;
|
||||
|
||||
|
@ -52,5 +53,4 @@ contract StakeVault is Ownable {
|
|||
require(address(migrated) != address(0), "Migration not available.");
|
||||
stakeManager = migrated;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity ^0.8.18;
|
||||
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract Token is Ownable, ERC20 {
|
||||
|
||||
constructor() ERC20("Status", "SNT") {
|
||||
|
||||
}
|
||||
|
||||
function mint(address _destination, uint256 _amount) external onlyOwner {
|
||||
_mint(_destination, _amount);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
/// @dev `Owned` is a base level contract that assigns an `owner` that can be
|
||||
/// later changed
|
||||
contract Owned {
|
||||
|
||||
/// @dev `owner` is the only address that can call a function with this
|
||||
/// modifier
|
||||
modifier onlyOwner() {
|
||||
require(msg.sender == owner);
|
||||
_;
|
||||
}
|
||||
|
||||
address public owner;
|
||||
|
||||
/// @notice The Constructor assigns the message sender to be `owner`
|
||||
constructor() {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
address public newOwner;
|
||||
|
||||
/// @notice `owner` can step down and assign some other address to this role
|
||||
/// @param _newOwner The address of the new owner. 0x0 can be used to create
|
||||
/// an unowned neutral vault, however that cannot be undone
|
||||
function changeOwner(address _newOwner) external onlyOwner {
|
||||
newOwner = _newOwner;
|
||||
}
|
||||
|
||||
|
||||
function acceptOwnership() external {
|
||||
if (msg.sender == newOwner) {
|
||||
owner = newOwner;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
|
||||
import "./SNTPlaceHolder.sol";
|
||||
|
||||
contract SNTFaucet is SNTPlaceHolder {
|
||||
|
||||
bool public open = true;
|
||||
|
||||
constructor(address _owner, address payable _snt) SNTPlaceHolder(_owner, _snt) {
|
||||
|
||||
}
|
||||
|
||||
fallback() external {
|
||||
generateTokens(msg.sender, 1000* (10 ** uint(snt.decimals())));
|
||||
}
|
||||
|
||||
function mint(uint256 _amount) external {
|
||||
require(open);
|
||||
generateTokens(msg.sender, _amount);
|
||||
}
|
||||
|
||||
function setOpen(bool _open) external onlyOwner {
|
||||
open = _open;
|
||||
}
|
||||
|
||||
function destroyTokens(address _who, uint _amount) onlyOwner public {
|
||||
snt.destroyTokens(_who, _amount);
|
||||
}
|
||||
|
||||
function generateTokens(address _who, uint _amount) public {
|
||||
require(msg.sender == owner || open);
|
||||
snt.generateTokens(_who, _amount);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
import "./token/TokenController.sol";
|
||||
import "./token/MiniMeToken.sol";
|
||||
import "./SafeMath.sol";
|
||||
import "./Owned.sol";
|
||||
|
||||
/*
|
||||
Copyright 2017, Jordi Baylina
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// @title SNTPlaceholder Contract
|
||||
/// @author Jordi Baylina
|
||||
/// @dev The SNTPlaceholder contract will take control over the SNT after the contribution
|
||||
/// is finalized and before the Status Network is deployed.
|
||||
/// The contract allows for SNT transfers and transferFrom and implements the
|
||||
/// logic for transferring control of the token to the network when the offering
|
||||
/// asks it to do so.
|
||||
contract SNTPlaceHolder is TokenController, Owned {
|
||||
using SafeMath for uint256;
|
||||
MiniMeToken public snt;
|
||||
|
||||
constructor(address _owner, address payable _snt) {
|
||||
owner = _owner;
|
||||
snt = MiniMeToken(_snt);
|
||||
}
|
||||
|
||||
/// @notice The owner of this contract can change the controller of the SNT token
|
||||
/// Please, be sure that the owner is a trusted agent or 0x0 address.
|
||||
/// @param _newController The address of the new controller
|
||||
function changeController(address _newController) public onlyOwner {
|
||||
snt.changeController(_newController);
|
||||
emit ControllerChanged(_newController);
|
||||
}
|
||||
|
||||
//////////
|
||||
// MiniMe Controller Interface functions
|
||||
//////////
|
||||
|
||||
// In between the offering and the network. Default settings for allowing token transfers.
|
||||
function proxyPayment(address) override public payable returns (bool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function onTransfer(address, address, uint256) override public pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function onApprove(address, address, uint256) override public pure returns (bool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
event ClaimedTokens(address indexed _token, address indexed _controller, uint256 _amount);
|
||||
event ControllerChanged(address indexed _newController);
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
|
||||
/**
|
||||
* Math operations with safety checks
|
||||
*/
|
||||
library SafeMath {
|
||||
function mul(uint a, uint b) internal pure returns (uint) {
|
||||
uint c = a * b;
|
||||
assert(a == 0 || c / a == b);
|
||||
return c;
|
||||
}
|
||||
|
||||
function div(uint a, uint b) internal pure returns (uint) {
|
||||
// assert(b > 0); // Solidity automatically throws when dividing by 0
|
||||
uint c = a / b;
|
||||
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
|
||||
return c;
|
||||
}
|
||||
|
||||
function sub(uint a, uint b) internal pure returns (uint) {
|
||||
assert(b <= a);
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function add(uint a, uint b) internal pure returns (uint) {
|
||||
uint c = a + b;
|
||||
assert(c >= a);
|
||||
return c;
|
||||
}
|
||||
|
||||
function max64(uint64 a, uint64 b) internal pure returns (uint64) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min64(uint64 a, uint64 b) internal pure returns (uint64) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
function max256(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min256(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
||||
|
||||
/**
|
||||
* @title IOptimismMintableERC20
|
||||
* @notice This interface is available on the OptimismMintableERC20 contract. We declare it as a
|
||||
* separate interface so that it can be used in custom implementations of
|
||||
* OptimismMintableERC20.
|
||||
*/
|
||||
interface IOptimismMintableERC20 is IERC165 {
|
||||
function remoteToken() external view returns (address);
|
||||
|
||||
function bridge() external returns (address);
|
||||
|
||||
function mint(address _to, uint256 _amount) external;
|
||||
|
||||
function burn(address _from, uint256 _amount) external;
|
||||
}
|
||||
|
||||
/**
|
||||
* @custom:legacy
|
||||
* @title ILegacyMintableERC20
|
||||
* @notice This interface was available on the legacy L2StandardERC20 contract. It remains available
|
||||
* on the OptimismMintableERC20 contract for backwards compatibility.
|
||||
*/
|
||||
interface ILegacyMintableERC20 is IERC165 {
|
||||
function l1Token() external view returns (address);
|
||||
|
||||
function mint(address _to, uint256 _amount) external;
|
||||
|
||||
function burn(address _from, uint256 _amount) external;
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
|
||||
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.18;
|
||||
|
||||
import { MiniMeToken } from "../token/MiniMeToken.sol";
|
||||
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
||||
import { ILegacyMintableERC20, IOptimismMintableERC20 } from "./IOptimismMintableERC20.sol";
|
||||
import { Semver } from "./Semver.sol";
|
||||
|
||||
/// @title OptimismMintableMiniMeToken
|
||||
/// @notice OptimismMintableMiniMeToken is a standard extension of the base MiniMeToken token contract designed
|
||||
/// to allow the StandardBridge contracts to mint and burn tokens. This makes it possible to
|
||||
/// use an OptimismMintablERC20 as the L2 representation of an L1 token, or vice-versa.
|
||||
/// Designed to be backwards compatible with the older StandardL2ERC20 token which was only
|
||||
/// meant for use on L2.
|
||||
contract OptimismMintableMiniMeToken is IOptimismMintableERC20, ILegacyMintableERC20, MiniMeToken, Semver {
|
||||
/// @notice Address of the corresponding version of this token on the remote chain.
|
||||
address public immutable REMOTE_TOKEN;
|
||||
|
||||
/// @notice Address of the StandardBridge on this network.
|
||||
address public immutable BRIDGE;
|
||||
|
||||
/// @notice Emitted whenever tokens are minted for an account.
|
||||
/// @param account Address of the account tokens are being minted for.
|
||||
/// @param amount Amount of tokens minted.
|
||||
event Mint(address indexed account, uint256 amount);
|
||||
|
||||
/// @notice Emitted whenever tokens are burned from an account.
|
||||
/// @param account Address of the account tokens are being burned from.
|
||||
/// @param amount Amount of tokens burned.
|
||||
event Burn(address indexed account, uint256 amount);
|
||||
|
||||
/// @notice A modifier that only allows the bridge to call
|
||||
modifier onlyBridge() {
|
||||
require(msg.sender == BRIDGE, "OptimismMintableMiniMeToken: only bridge can mint and burn");
|
||||
_;
|
||||
}
|
||||
|
||||
/// @custom:semver 1.0.1
|
||||
/// @param _bridge Address of the L2 standard bridge.
|
||||
/// @param _remoteToken Address of the corresponding L1 token.
|
||||
/// @param _tokenName ERC20 name.
|
||||
/// @param _tokenSymbol ERC20 symbol.
|
||||
constructor(
|
||||
address _bridge,
|
||||
address _remoteToken,
|
||||
address _tokenFactory,
|
||||
address payable _parentToken,
|
||||
uint _parentSnapShotBlock,
|
||||
string memory _tokenName,
|
||||
uint8 _decimalUnits,
|
||||
string memory _tokenSymbol,
|
||||
bool _transfersEnabled
|
||||
) MiniMeToken(_tokenFactory, _parentToken, _parentSnapShotBlock, _tokenName, _decimalUnits, _tokenSymbol, _transfersEnabled) Semver(1, 0, 1) {
|
||||
REMOTE_TOKEN = _remoteToken;
|
||||
BRIDGE = _bridge;
|
||||
}
|
||||
|
||||
/// @notice Allows the StandardBridge on this network to mint tokens.
|
||||
/// @param _to Address to mint tokens to.
|
||||
/// @param _amount Amount of tokens to mint.
|
||||
function mint(address _to, uint256 _amount)
|
||||
external
|
||||
override(IOptimismMintableERC20, ILegacyMintableERC20)
|
||||
onlyBridge
|
||||
{
|
||||
_mint(_to, _amount);
|
||||
emit Mint(_to, _amount);
|
||||
}
|
||||
|
||||
/// @notice Allows the StandardBridge on this network to burn tokens.
|
||||
/// @param _from Address to burn tokens from.
|
||||
/// @param _amount Amount of tokens to burn.
|
||||
function burn(address _from, uint256 _amount)
|
||||
external
|
||||
override(IOptimismMintableERC20, ILegacyMintableERC20)
|
||||
onlyBridge
|
||||
{
|
||||
_burn(_from, _amount);
|
||||
emit Burn(_from, _amount);
|
||||
}
|
||||
|
||||
/// @notice ERC165 interface check function.
|
||||
/// @param _interfaceId Interface ID to check.
|
||||
/// @return Whether or not the interface is supported by this contract.
|
||||
function supportsInterface(bytes4 _interfaceId) external pure returns (bool) {
|
||||
bytes4 iface1 = type(IERC165).interfaceId;
|
||||
// Interface corresponding to the legacy L2StandardERC20.
|
||||
bytes4 iface2 = type(ILegacyMintableERC20).interfaceId;
|
||||
// Interface corresponding to the updated OptimismMintableMiniMeToken (this contract).
|
||||
bytes4 iface3 = type(IOptimismMintableERC20).interfaceId;
|
||||
return _interfaceId == iface1 || _interfaceId == iface2 || _interfaceId == iface3;
|
||||
}
|
||||
|
||||
/// @custom:legacy
|
||||
/// @notice Legacy getter for the remote token. Use REMOTE_TOKEN going forward.
|
||||
function l1Token() public view returns (address) {
|
||||
return REMOTE_TOKEN;
|
||||
}
|
||||
|
||||
/// @custom:legacy
|
||||
/// @notice Legacy getter for the bridge. Use BRIDGE going forward.
|
||||
function l2Bridge() public view returns (address) {
|
||||
return BRIDGE;
|
||||
}
|
||||
|
||||
/// @custom:legacy
|
||||
/// @notice Legacy getter for REMOTE_TOKEN.
|
||||
function remoteToken() public view returns (address) {
|
||||
return REMOTE_TOKEN;
|
||||
}
|
||||
|
||||
/// @custom:legacy
|
||||
/// @notice Legacy getter for BRIDGE.
|
||||
function bridge() public view returns (address) {
|
||||
return BRIDGE;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
|
||||
|
||||
/// @title Semver
|
||||
/// @notice Semver is a simple contract for managing contract versions.
|
||||
contract Semver {
|
||||
/// @notice Contract version number (major).
|
||||
uint256 private immutable MAJOR_VERSION;
|
||||
|
||||
/// @notice Contract version number (minor).
|
||||
uint256 private immutable MINOR_VERSION;
|
||||
|
||||
/// @notice Contract version number (patch).
|
||||
uint256 private immutable PATCH_VERSION;
|
||||
|
||||
/// @param _major Version number (major).
|
||||
/// @param _minor Version number (minor).
|
||||
/// @param _patch Version number (patch).
|
||||
constructor(
|
||||
uint256 _major,
|
||||
uint256 _minor,
|
||||
uint256 _patch
|
||||
) {
|
||||
MAJOR_VERSION = _major;
|
||||
MINOR_VERSION = _minor;
|
||||
PATCH_VERSION = _patch;
|
||||
}
|
||||
|
||||
/// @notice Returns the full semver contract version.
|
||||
/// @return Semver contract version as a string.
|
||||
function version() public view returns (string memory) {
|
||||
return
|
||||
string(
|
||||
abi.encodePacked(
|
||||
Strings.toString(MAJOR_VERSION),
|
||||
".",
|
||||
Strings.toString(MINOR_VERSION),
|
||||
".",
|
||||
Strings.toString(PATCH_VERSION)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
abstract contract ApproveAndCallFallBack {
|
||||
function receiveApproval(address from, uint256 _amount, address _token, bytes memory _data) virtual public;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
|
||||
contract Controlled {
|
||||
string internal constant ERR_BAD_PARAMETER = "Bad parameter";
|
||||
string internal constant ERR_UNAUTHORIZED = "Unauthorized";
|
||||
event NewController(address controller);
|
||||
/// @notice The address of the controller is the only address that can call
|
||||
/// a function with this modifier
|
||||
modifier onlyController {
|
||||
require(msg.sender == controller, "Unauthorized");
|
||||
_;
|
||||
}
|
||||
|
||||
address public controller;
|
||||
|
||||
constructor(address _initController) {
|
||||
require(_initController != address(0), ERR_BAD_PARAMETER);
|
||||
controller = _initController;
|
||||
}
|
||||
|
||||
/// @notice Changes the controller of the contract
|
||||
/// @param _newController The new controller of the contract
|
||||
function changeController(address _newController) public onlyController {
|
||||
controller = _newController;
|
||||
emit NewController(_newController);
|
||||
}
|
||||
}
|
|
@ -1,651 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
/*
|
||||
Copyright 2016, Jordi Baylina
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @title MiniMeToken Contract
|
||||
* @author Jordi Baylina
|
||||
* @dev This token contract's goal is to make it easy for anyone to clone this
|
||||
* token using the token distribution at a given block, this will allow DAO's
|
||||
* and DApps to upgrade their features in a decentralized manner without
|
||||
* affecting the original token
|
||||
* @dev It is ERC20 compliant, but still needs to under go further testing.
|
||||
*/
|
||||
|
||||
import "./Controlled.sol";
|
||||
import "./TokenController.sol";
|
||||
import "./ApproveAndCallFallBack.sol";
|
||||
import "./MiniMeTokenFactory.sol";
|
||||
|
||||
/**
|
||||
* @dev The actual token contract, the default controller is the msg.sender
|
||||
* that deploys the contract, so usually this token will be deployed by a
|
||||
* token controller contract, which Giveth will call a "Campaign"
|
||||
*/
|
||||
contract MiniMeToken is Controlled {
|
||||
|
||||
string public name; //The Token's name: e.g. DigixDAO Tokens
|
||||
uint8 public decimals; //Number of decimals of the smallest unit
|
||||
string public symbol; //An identifier: e.g. REP
|
||||
string public token_version = "MMT_0.1"; //An arbitrary versioning scheme
|
||||
|
||||
/**
|
||||
* @dev `Checkpoint` is the structure that attaches a block number to a
|
||||
* given value, the block number attached is the one that last changed the
|
||||
* value
|
||||
*/
|
||||
struct Checkpoint {
|
||||
|
||||
// `fromBlock` is the block number that the value was generated from
|
||||
uint128 fromBlock;
|
||||
|
||||
// `value` is the amount of tokens at a specific block number
|
||||
uint128 value;
|
||||
}
|
||||
|
||||
// `parentToken` is the Token address that was cloned to produce this token;
|
||||
// it will be 0x0 for a token that was not cloned
|
||||
MiniMeToken public parentToken;
|
||||
|
||||
// `parentSnapShotBlock` is the block number from the Parent Token that was
|
||||
// used to determine the initial distribution of the Clone Token
|
||||
uint public parentSnapShotBlock;
|
||||
|
||||
// `creationBlock` is the block number that the Clone Token was created
|
||||
uint public creationBlock;
|
||||
|
||||
// `balances` is the map that tracks the balance of each address, in this
|
||||
// contract when the balance changes the block number that the change
|
||||
// occurred is also included in the map
|
||||
mapping (address => Checkpoint[]) balances;
|
||||
|
||||
// `allowed` tracks any extra transfer rights as in all ERC20 tokens
|
||||
mapping (address => mapping (address => uint256)) allowed;
|
||||
|
||||
// Tracks the history of the `totalSupply` of the token
|
||||
Checkpoint[] totalSupplyHistory;
|
||||
|
||||
// Flag that determines if the token is transferable or not.
|
||||
bool public transfersEnabled;
|
||||
|
||||
// The factory used to create new clone tokens
|
||||
MiniMeTokenFactory public tokenFactory;
|
||||
|
||||
////////////////
|
||||
// Constructor
|
||||
////////////////
|
||||
|
||||
/**
|
||||
* @notice Constructor to create a MiniMeToken
|
||||
* @param _tokenFactory The address of the MiniMeTokenFactory contract that
|
||||
* will create the Clone token contracts, the token factory needs to be
|
||||
* deployed first
|
||||
* @param _parentToken Address of the parent token, set to 0x0 if it is a
|
||||
* new token
|
||||
* @param _parentSnapShotBlock Block of the parent token that will
|
||||
* determine the initial distribution of the clone token, set to 0 if it
|
||||
* is a new token
|
||||
* @param _tokenName Name of the new token
|
||||
* @param _decimalUnits Number of decimals of the new token
|
||||
* @param _tokenSymbol Token Symbol for the new token
|
||||
* @param _transfersEnabled If true, tokens will be able to be transferred
|
||||
*/
|
||||
constructor(
|
||||
address _tokenFactory,
|
||||
address payable _parentToken,
|
||||
uint _parentSnapShotBlock,
|
||||
string memory _tokenName,
|
||||
uint8 _decimalUnits,
|
||||
string memory _tokenSymbol,
|
||||
bool _transfersEnabled
|
||||
)
|
||||
Controlled(msg.sender)
|
||||
{
|
||||
tokenFactory = MiniMeTokenFactory(_tokenFactory);
|
||||
name = _tokenName; // Set the name
|
||||
decimals = _decimalUnits; // Set the decimals
|
||||
symbol = _tokenSymbol; // Set the symbol
|
||||
parentToken = MiniMeToken(_parentToken);
|
||||
parentSnapShotBlock = _parentSnapShotBlock;
|
||||
transfersEnabled = _transfersEnabled;
|
||||
creationBlock = block.number;
|
||||
}
|
||||
|
||||
|
||||
///////////////////
|
||||
// ERC20 Methods
|
||||
///////////////////
|
||||
|
||||
/**
|
||||
* @notice Send `_amount` tokens to `_to` from `msg.sender`
|
||||
* @param _to The address of the recipient
|
||||
* @param _amount The amount of tokens to be transferred
|
||||
* @return success Whether the transfer was successful or not
|
||||
*/
|
||||
function transfer(address _to, uint256 _amount) public returns (bool success) {
|
||||
require(transfersEnabled, "Transfers disabled");
|
||||
return doTransfer(msg.sender, _to, _amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Send `_amount` tokens to `_to` from `_from` on the condition it
|
||||
* is approved by `_from`
|
||||
* @param _from The address holding the tokens being transferred
|
||||
* @param _to The address of the recipient
|
||||
* @param _amount The amount of tokens to be transferred
|
||||
* @return success True if the transfer was successful
|
||||
*/
|
||||
function transferFrom(
|
||||
address _from,
|
||||
address _to,
|
||||
uint256 _amount
|
||||
)
|
||||
public
|
||||
returns (bool success)
|
||||
{
|
||||
|
||||
// The controller of this contract can move tokens around at will,
|
||||
// this is important to recognize! Confirm that you trust the
|
||||
// controller of this contract, which in most situations should be
|
||||
// another open source smart contract or 0x0
|
||||
if (msg.sender != controller) {
|
||||
require(transfersEnabled, "Transfers disabled");
|
||||
|
||||
// The standard ERC 20 transferFrom functionality
|
||||
if (allowed[_from][msg.sender] < _amount) {
|
||||
return false;
|
||||
}
|
||||
allowed[_from][msg.sender] -= _amount;
|
||||
}
|
||||
return doTransfer(_from, _to, _amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev This is the actual transfer function in the token contract, it can
|
||||
* only be called by other functions in this contract.
|
||||
* @param _from The address holding the tokens being transferred
|
||||
* @param _to The address of the recipient
|
||||
* @param _amount The amount of tokens to be transferred
|
||||
* @return True if the transfer was successful
|
||||
*/
|
||||
function doTransfer(
|
||||
address _from,
|
||||
address _to,
|
||||
uint _amount
|
||||
)
|
||||
internal
|
||||
returns(bool)
|
||||
{
|
||||
|
||||
if (_amount == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
require(parentSnapShotBlock < block.number, "Invalid block.number");
|
||||
|
||||
// Do not allow transfer to 0x0 or the token contract itself
|
||||
require((_to != address(0)) && (_to != address(this)), "Invalid _to");
|
||||
|
||||
// If the amount being transfered is more than the balance of the
|
||||
// account the transfer returns false
|
||||
uint256 previousBalanceFrom = balanceOfAt(_from, block.number);
|
||||
if (previousBalanceFrom < _amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Alerts the token controller of the transfer
|
||||
if (isContract(controller)) {
|
||||
require(TokenController(controller).onTransfer(_from, _to, _amount), "Unauthorized transfer");
|
||||
}
|
||||
|
||||
// First update the balance array with the new value for the address
|
||||
// sending the tokens
|
||||
updateValueAtNow(balances[_from], previousBalanceFrom - _amount);
|
||||
|
||||
// Then update the balance array with the new value for the address
|
||||
// receiving the tokens
|
||||
uint256 previousBalanceTo = balanceOfAt(_to, block.number);
|
||||
require(previousBalanceTo + _amount >= previousBalanceTo, "Balance overflow"); // Check for overflow
|
||||
updateValueAtNow(balances[_to], previousBalanceTo + _amount);
|
||||
|
||||
// An event to make the transfer easy to find on the blockchain
|
||||
emit Transfer(_from, _to, _amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function doApprove(
|
||||
address _from,
|
||||
address _spender,
|
||||
uint256 _amount
|
||||
)
|
||||
internal
|
||||
returns (bool)
|
||||
{
|
||||
require(transfersEnabled, "Transfers disabled");
|
||||
|
||||
// To change the approve amount you first have to reduce the addresses`
|
||||
// allowance to zero by calling `approve(_spender,0)` if it is not
|
||||
// already 0 to mitigate the race condition described here:
|
||||
// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
|
||||
require((_amount == 0) || (allowed[_from][_spender] == 0), "Reset allowance first");
|
||||
|
||||
// Alerts the token controller of the approve function call
|
||||
if (isContract(controller)) {
|
||||
require(TokenController(controller).onApprove(_from, _spender, _amount), "Unauthorized approve");
|
||||
}
|
||||
|
||||
allowed[_from][_spender] = _amount;
|
||||
emit Approval(_from, _spender, _amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
function _mint(
|
||||
address _owner,
|
||||
uint _amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
uint curTotalSupply = totalSupplyAt(block.number);
|
||||
require(curTotalSupply + _amount >= curTotalSupply, "Total overflow"); // Check for overflow
|
||||
uint previousBalanceTo = balanceOfAt(_owner, block.number);
|
||||
require(previousBalanceTo + _amount >= previousBalanceTo, "Balance overflow"); // Check for overflow
|
||||
updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
|
||||
updateValueAtNow(balances[_owner], previousBalanceTo + _amount);
|
||||
emit Transfer(address(0), _owner, _amount);
|
||||
}
|
||||
|
||||
function _burn(
|
||||
address _owner,
|
||||
uint _amount
|
||||
)
|
||||
internal
|
||||
{
|
||||
uint curTotalSupply = totalSupplyAt(block.number);
|
||||
require(curTotalSupply >= _amount, "No enough supply");
|
||||
uint previousBalanceFrom = balanceOfAt(_owner, block.number);
|
||||
require(previousBalanceFrom >= _amount, "No enough balance");
|
||||
updateValueAtNow(totalSupplyHistory, curTotalSupply - _amount);
|
||||
updateValueAtNow(balances[_owner], previousBalanceFrom - _amount);
|
||||
emit Transfer(_owner, address(0), _amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _owner The address that's balance is being requested
|
||||
* @return balance The balance of `_owner` at the current block
|
||||
*/
|
||||
function balanceOf(address _owner) external view returns (uint256 balance) {
|
||||
return balanceOfAt(_owner, block.number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice `msg.sender` approves `_spender` to spend `_amount` tokens on
|
||||
* its behalf. This is a modified version of the ERC20 approve function
|
||||
* to be a little bit safer
|
||||
* @param _spender The address of the account able to transfer the tokens
|
||||
* @param _amount The amount of tokens to be approved for transfer
|
||||
* @return success True if the approval was successful
|
||||
*/
|
||||
function approve(address _spender, uint256 _amount) external returns (bool success) {
|
||||
return doApprove(msg.sender, _spender, _amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev This function makes it easy to read the `allowed[]` map
|
||||
* @param _owner The address of the account that owns the token
|
||||
* @param _spender The address of the account able to transfer the tokens
|
||||
* @return remaining Amount of remaining tokens of _owner that _spender is allowed
|
||||
* to spend
|
||||
*/
|
||||
function allowance(
|
||||
address _owner,
|
||||
address _spender
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256 remaining)
|
||||
{
|
||||
return allowed[_owner][_spender];
|
||||
}
|
||||
/**
|
||||
* @notice `msg.sender` approves `_spender` to send `_amount` tokens on
|
||||
* its behalf, and then a function is triggered in the contract that is
|
||||
* being approved, `_spender`. This allows users to use their tokens to
|
||||
* interact with contracts in one function call instead of two
|
||||
* @param _spender The address of the contract able to transfer the tokens
|
||||
* @param _amount The amount of tokens to be approved for transfer
|
||||
* @return success True if the function call was successful
|
||||
*/
|
||||
function approveAndCall(
|
||||
address _spender,
|
||||
uint256 _amount,
|
||||
bytes memory _extraData
|
||||
)
|
||||
public
|
||||
returns (bool success)
|
||||
{
|
||||
require(doApprove(msg.sender, _spender, _amount), "Approve failed");
|
||||
|
||||
ApproveAndCallFallBack(_spender).receiveApproval(
|
||||
msg.sender,
|
||||
_amount,
|
||||
address(this),
|
||||
_extraData
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev This function makes it easy to get the total number of tokens
|
||||
* @return The total number of tokens
|
||||
*/
|
||||
function totalSupply() external view returns (uint) {
|
||||
return totalSupplyAt(block.number);
|
||||
}
|
||||
|
||||
|
||||
////////////////
|
||||
// Query balance and totalSupply in History
|
||||
////////////////
|
||||
|
||||
/**
|
||||
* @dev Queries the balance of `_owner` at a specific `_blockNumber`
|
||||
* @param _owner The address from which the balance will be retrieved
|
||||
* @param _blockNumber The block number when the balance is queried
|
||||
* @return The balance at `_blockNumber`
|
||||
*/
|
||||
function balanceOfAt(
|
||||
address _owner,
|
||||
uint _blockNumber
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (uint)
|
||||
{
|
||||
|
||||
// These next few lines are used when the balance of the token is
|
||||
// requested before a check point was ever created for this token, it
|
||||
// requires that the `parentToken.balanceOfAt` be queried at the
|
||||
// genesis block for that token as this contains initial balance of
|
||||
// this token
|
||||
if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
|
||||
if (address(parentToken) != address(0)) {
|
||||
return parentToken.balanceOfAt(_owner, min(_blockNumber, parentSnapShotBlock));
|
||||
} else {
|
||||
// Has no parent
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This will return the expected balance during normal situations
|
||||
} else {
|
||||
return getValueAt(balances[_owner], _blockNumber);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Total amount of tokens at a specific `_blockNumber`.
|
||||
* @param _blockNumber The block number when the totalSupply is queried
|
||||
* @return The total amount of tokens at `_blockNumber`
|
||||
*/
|
||||
function totalSupplyAt(uint _blockNumber) public view returns(uint) {
|
||||
|
||||
// These next few lines are used when the totalSupply of the token is
|
||||
// requested before a check point was ever created for this token, it
|
||||
// requires that the `parentToken.totalSupplyAt` be queried at the
|
||||
// genesis block for this token as that contains totalSupply of this
|
||||
// token at this block number.
|
||||
if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) {
|
||||
if (address(parentToken) != address(0)) {
|
||||
return parentToken.totalSupplyAt(min(_blockNumber, parentSnapShotBlock));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This will return the expected totalSupply during normal situations
|
||||
} else {
|
||||
return getValueAt(totalSupplyHistory, _blockNumber);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////
|
||||
// Clone Token Method
|
||||
////////////////
|
||||
|
||||
/**
|
||||
* @notice Creates a new clone token with the initial distribution being
|
||||
* this token at `snapshotBlock`
|
||||
* @param _cloneTokenName Name of the clone token
|
||||
* @param _cloneDecimalUnits Number of decimals of the smallest unit
|
||||
* @param _cloneTokenSymbol Symbol of the clone token
|
||||
* @param _snapshotBlock Block when the distribution of the parent token is
|
||||
* copied to set the initial distribution of the new clone token;
|
||||
* if the block is zero than the actual block, the current block is used
|
||||
* @param _transfersEnabled True if transfers are allowed in the clone
|
||||
* @return The address of the new MiniMeToken Contract
|
||||
*/
|
||||
function createCloneToken(
|
||||
string memory _cloneTokenName,
|
||||
uint8 _cloneDecimalUnits,
|
||||
string memory _cloneTokenSymbol,
|
||||
uint _snapshotBlock,
|
||||
bool _transfersEnabled
|
||||
)
|
||||
public
|
||||
returns(address)
|
||||
{
|
||||
uint snapshotBlock = _snapshotBlock;
|
||||
if (snapshotBlock == 0) {
|
||||
snapshotBlock = block.number;
|
||||
}
|
||||
MiniMeToken cloneToken = tokenFactory.createCloneToken(
|
||||
payable(this),
|
||||
snapshotBlock,
|
||||
_cloneTokenName,
|
||||
_cloneDecimalUnits,
|
||||
_cloneTokenSymbol,
|
||||
_transfersEnabled
|
||||
);
|
||||
|
||||
cloneToken.changeController(msg.sender);
|
||||
|
||||
// An event to make the token easy to find on the blockchain
|
||||
emit NewCloneToken(address(cloneToken), snapshotBlock);
|
||||
return address(cloneToken);
|
||||
}
|
||||
|
||||
////////////////
|
||||
// Generate and destroy tokens
|
||||
////////////////
|
||||
|
||||
/**
|
||||
* @notice Generates `_amount` tokens that are assigned to `_owner`
|
||||
* @param _owner The address that will be assigned the new tokens
|
||||
* @param _amount The quantity of tokens generated
|
||||
* @return True if the tokens are generated correctly
|
||||
*/
|
||||
function generateTokens(
|
||||
address _owner,
|
||||
uint _amount
|
||||
)
|
||||
public
|
||||
onlyController
|
||||
returns (bool)
|
||||
{
|
||||
_mint(_owner, _amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Burns `_amount` tokens from `_owner`
|
||||
* @param _owner The address that will lose the tokens
|
||||
* @param _amount The quantity of tokens to burn
|
||||
* @return True if the tokens are burned correctly
|
||||
*/
|
||||
function destroyTokens(
|
||||
address _owner,
|
||||
uint _amount
|
||||
)
|
||||
public
|
||||
onlyController
|
||||
returns (bool)
|
||||
{
|
||||
_burn(_owner, _amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////
|
||||
// Enable tokens transfers
|
||||
////////////////
|
||||
|
||||
/**
|
||||
* @notice Enables token holders to transfer their tokens freely if true
|
||||
* @param _transfersEnabled True if transfers are allowed in the clone
|
||||
*/
|
||||
function enableTransfers(bool _transfersEnabled) public onlyController {
|
||||
transfersEnabled = _transfersEnabled;
|
||||
}
|
||||
|
||||
////////////////
|
||||
// Internal helper functions to query and set a value in a snapshot array
|
||||
////////////////
|
||||
|
||||
/**
|
||||
* @dev `getValueAt` retrieves the number of tokens at a given block number
|
||||
* @param checkpoints The history of values being queried
|
||||
* @param _block The block number to retrieve the value at
|
||||
* @return The number of tokens being queried
|
||||
*/
|
||||
function getValueAt(
|
||||
Checkpoint[] storage checkpoints,
|
||||
uint _block
|
||||
)
|
||||
internal
|
||||
view
|
||||
returns (uint)
|
||||
{
|
||||
if (checkpoints.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Shortcut for the actual value
|
||||
if (_block >= checkpoints[checkpoints.length-1].fromBlock) {
|
||||
return checkpoints[checkpoints.length-1].value;
|
||||
}
|
||||
if (_block < checkpoints[0].fromBlock) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Binary search of the value in the array
|
||||
uint _min = 0;
|
||||
uint max = checkpoints.length-1;
|
||||
while (max > _min) {
|
||||
uint mid = (max + _min + 1) / 2;
|
||||
if (checkpoints[mid].fromBlock<=_block) {
|
||||
_min = mid;
|
||||
} else {
|
||||
max = mid-1;
|
||||
}
|
||||
}
|
||||
return checkpoints[_min].value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev `updateValueAtNow` used to update the `balances` map and the
|
||||
* `totalSupplyHistory`
|
||||
* @param checkpoints The history of data being updated
|
||||
* @param _value The new number of tokens
|
||||
*/
|
||||
function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value) internal {
|
||||
if ((checkpoints.length == 0) || (checkpoints[checkpoints.length -1].fromBlock < block.number)) {
|
||||
Checkpoint storage newCheckPoint = checkpoints.push();
|
||||
newCheckPoint.fromBlock = uint128(block.number);
|
||||
newCheckPoint.value = uint128(_value);
|
||||
} else {
|
||||
Checkpoint storage oldCheckPoint = checkpoints[checkpoints.length-1];
|
||||
oldCheckPoint.value = uint128(_value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal function to determine if an address is a contract
|
||||
* @param _addr The address being queried
|
||||
* @return True if `_addr` is a contract
|
||||
*/
|
||||
function isContract(address _addr) internal view returns(bool) {
|
||||
uint size;
|
||||
if (_addr == address(0)){
|
||||
return false;
|
||||
}
|
||||
assembly {
|
||||
size := extcodesize(_addr)
|
||||
}
|
||||
return size>0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Helper function to return a min betwen the two uints
|
||||
*/
|
||||
function min(uint a, uint b) internal pure returns (uint) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice The fallback function: If the contract's controller has not been
|
||||
* set to 0, then the `proxyPayment` method is called which relays the
|
||||
* ether and creates tokens as described in the token controller contract
|
||||
*/
|
||||
receive() payable external {
|
||||
require(isContract(controller), "Deposit unallowed");
|
||||
require(TokenController(controller).proxyPayment{value: msg.value}(msg.sender), "Deposit denied");
|
||||
}
|
||||
|
||||
//////////
|
||||
// Safety Methods
|
||||
//////////
|
||||
|
||||
/**
|
||||
* @notice This method can be used by the controller to extract mistakenly
|
||||
* sent tokens to this contract.
|
||||
* @param _token The address of the token contract that you want to recover
|
||||
* set to 0 in case you want to extract ether.
|
||||
*/
|
||||
function claimTokens(address payable _token) public onlyController {
|
||||
if (_token == address(0)) {
|
||||
payable(controller).transfer(address(this).balance);
|
||||
return;
|
||||
}
|
||||
|
||||
MiniMeToken token = MiniMeToken(_token);
|
||||
uint balance = token.balanceOf(address(this));
|
||||
token.transfer(controller, balance);
|
||||
emit ClaimedTokens(_token, controller, balance);
|
||||
}
|
||||
|
||||
////////////////
|
||||
// Events
|
||||
////////////////
|
||||
event ClaimedTokens(address indexed _token, address indexed _controller, uint _amount);
|
||||
event Transfer(address indexed _from, address indexed _to, uint256 _amount);
|
||||
event NewCloneToken(address indexed _cloneToken, uint snapshotBlock);
|
||||
event Approval(
|
||||
address indexed _owner,
|
||||
address indexed _spender,
|
||||
uint256 _amount
|
||||
);
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
import "./MiniMeToken.sol";
|
||||
|
||||
////////////////
|
||||
// MiniMeTokenFactory
|
||||
////////////////
|
||||
|
||||
/**
|
||||
* @dev This contract is used to generate clone contracts from a contract.
|
||||
* In solidity this is the way to create a contract from a contract of the
|
||||
* same class
|
||||
*/
|
||||
contract MiniMeTokenFactory {
|
||||
|
||||
/**
|
||||
* @notice Update the DApp by creating a new token with new functionalities
|
||||
* the msg.sender becomes the controller of this clone token
|
||||
* @param _parentToken Address of the token being cloned
|
||||
* @param _snapshotBlock Block of the parent token that will
|
||||
* determine the initial distribution of the clone token
|
||||
* @param _tokenName Name of the new token
|
||||
* @param _decimalUnits Number of decimals of the new token
|
||||
* @param _tokenSymbol Token Symbol for the new token
|
||||
* @param _transfersEnabled If true, tokens will be able to be transferred
|
||||
* @return The address of the new token contract
|
||||
*/
|
||||
function createCloneToken(
|
||||
address payable _parentToken,
|
||||
uint _snapshotBlock,
|
||||
string memory _tokenName,
|
||||
uint8 _decimalUnits,
|
||||
string memory _tokenSymbol,
|
||||
bool _transfersEnabled
|
||||
) public returns (MiniMeToken) {
|
||||
MiniMeToken newToken = new MiniMeToken(
|
||||
address(this),
|
||||
_parentToken,
|
||||
_snapshotBlock,
|
||||
_tokenName,
|
||||
_decimalUnits,
|
||||
_tokenSymbol,
|
||||
_transfersEnabled
|
||||
);
|
||||
|
||||
newToken.changeController(msg.sender);
|
||||
return newToken;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.18;
|
||||
/**
|
||||
* @dev The token controller contract must implement these functions
|
||||
*/
|
||||
interface TokenController {
|
||||
/**
|
||||
* @notice Called when `_owner` sends ether to the MiniMe Token contract
|
||||
* @param _owner The address that sent the ether to create tokens
|
||||
* @return True if the ether is accepted, false if it throws
|
||||
*/
|
||||
function proxyPayment(address _owner) external payable returns(bool);
|
||||
|
||||
/**
|
||||
* @notice Notifies the controller about a token transfer allowing the
|
||||
* controller to react if desired
|
||||
* @param _from The origin of the transfer
|
||||
* @param _to The destination of the transfer
|
||||
* @param _amount The amount of the transfer
|
||||
* @return False if the controller does not authorize the transfer
|
||||
*/
|
||||
function onTransfer(address _from, address _to, uint _amount) external returns(bool);
|
||||
|
||||
/**
|
||||
* @notice Notifies the controller about an approval allowing the
|
||||
* controller to react if desired
|
||||
* @param _owner The address that calls `approve()`
|
||||
* @param _spender The spender in the `approve()` call
|
||||
* @param _amount The amount in the `approve()` call
|
||||
* @return False if the controller does not authorize the approval
|
||||
*/
|
||||
function onApprove(address _owner, address _spender, uint _amount) external
|
||||
returns(bool);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
# Full reference https://github.com/foundry-rs/foundry/tree/master/config
|
||||
|
||||
[profile.default]
|
||||
auto_detect_solc = false
|
||||
block_timestamp = 1_680_220_800 # March 31, 2023 at 00:00 GMT
|
||||
bytecode_hash = "none"
|
||||
cbor_metadata = false
|
||||
evm_version = "paris"
|
||||
fuzz = { runs = 1_000 }
|
||||
gas_reports = ["*"]
|
||||
libs = ["lib"]
|
||||
optimizer = true
|
||||
optimizer_runs = 10_000
|
||||
out = "out"
|
||||
script = "script"
|
||||
solc = "0.8.20"
|
||||
src = "contracts"
|
||||
test = "test"
|
||||
|
||||
[profile.ci]
|
||||
fuzz = { runs = 10_000 }
|
||||
verbosity = 4
|
||||
|
||||
[etherscan]
|
||||
arbitrum_one = { key = "${API_KEY_ARBISCAN}" }
|
||||
avalanche = { key = "${API_KEY_SNOWTRACE}" }
|
||||
bnb_smart_chain = { key = "${API_KEY_BSCSCAN}" }
|
||||
gnosis_chain = { key = "${API_KEY_GNOSISSCAN}" }
|
||||
goerli = { key = "${API_KEY_ETHERSCAN}" }
|
||||
mainnet = { key = "${API_KEY_ETHERSCAN}" }
|
||||
optimism = { key = "${API_KEY_OPTIMISTIC_ETHERSCAN}" }
|
||||
polygon = { key = "${API_KEY_POLYGONSCAN}" }
|
||||
sepolia = { key = "${API_KEY_ETHERSCAN}" }
|
||||
|
||||
[fmt]
|
||||
bracket_spacing = true
|
||||
int_types = "long"
|
||||
line_length = 120
|
||||
multiline_func_header = "all"
|
||||
number_underscore = "thousands"
|
||||
quote_style = "double"
|
||||
tab_width = 4
|
||||
wrap_comments = true
|
||||
|
||||
[rpc_endpoints]
|
||||
arbitrum_one = "https://arbitrum-mainnet.infura.io/v3/${API_KEY_INFURA}"
|
||||
avalanche = "https://avalanche-mainnet.infura.io/v3/${API_KEY_INFURA}"
|
||||
bnb_smart_chain = "https://bsc-dataseed.binance.org"
|
||||
gnosis_chain = "https://rpc.gnosischain.com"
|
||||
goerli = "https://goerli.infura.io/v3/${API_KEY_INFURA}"
|
||||
localhost = "http://localhost:8545"
|
||||
mainnet = "https://eth-mainnet.g.alchemy.com/v2/${API_KEY_ALCHEMY}"
|
||||
optimism = "https://optimism-mainnet.infura.io/v3/${API_KEY_INFURA}"
|
||||
polygon = "https://polygon-mainnet.infura.io/v3/${API_KEY_INFURA}"
|
||||
sepolia = "https://sepolia.infura.io/v3/${API_KEY_INFURA}"
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
require("@nomicfoundation/hardhat-toolbox");
|
||||
require("dotenv").config();
|
||||
|
||||
const INFURA_API_KEY = process.env.INFURA_API_KEY;
|
||||
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
|
||||
const ETHERSCAN_OPT_API_KEY = process.env.ETHERSCAN_OPT_API_KEY;
|
||||
const MAINNET_PRIVATE_KEY = process.env.MAINNET_PRIVATE_KEY;
|
||||
const GOERLI_PRIVATE_KEY = process.env.GOERLI_PRIVATE_KEY;
|
||||
const OP_GOERLI_ALCHEMY_KEY = process.env.GOERLI_PRIVATE_KEY;
|
||||
|
||||
/** @type import('hardhat/config').HardhatUserConfig */
|
||||
module.exports = {
|
||||
solidity: "0.8.18",
|
||||
networks: {
|
||||
'mainnet': {
|
||||
url: `https://goerli.infura.io/v3/${INFURA_API_KEY}`,
|
||||
accounts: { mnemonic: process.env.MAINNET_MNEMONIC },
|
||||
},
|
||||
'goerli': {
|
||||
url: `https://goerli.infura.io/v3/${INFURA_API_KEY}`,
|
||||
accounts: { mnemonic: process.env.GOERLI_MNEMONIC },
|
||||
},
|
||||
'optimism-goerli': {
|
||||
chainId: 420,
|
||||
url: `https://opt-goerli.g.alchemy.com/v2/${process.env.OP_GOERLI_ALCHEMY_KEY}`,
|
||||
accounts: { mnemonic: process.env.GOERLI_MNEMONIC },
|
||||
saveDeployments: true
|
||||
},
|
||||
'optimism-mainnet': {
|
||||
chainId: 10,
|
||||
url: `https://opt-mainnet.g.alchemy.com/v2/${process.env.MAINNET_ALCHEMY_KEY}`,
|
||||
accounts: { mnemonic: process.env.MAINNET_MNEMONIC }
|
||||
}
|
||||
},
|
||||
etherscan: {
|
||||
apiKey: {
|
||||
mainnet: ETHERSCAN_API_KEY,
|
||||
optimisticEthereum: ETHERSCAN_OPT_API_KEY,
|
||||
optimisticGoerli: ETHERSCAN_OPT_API_KEY
|
||||
}
|
||||
},
|
||||
mocha: {
|
||||
timeout: 100000000,
|
||||
}
|
||||
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 1d9650e951204a0ddce9ff89c32f1997984cef4d
|
|
@ -0,0 +1 @@
|
|||
Subproject commit fd81a96f01cc42ef1c9a5399364968d0e07e9e90
|
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
|
@ -1,20 +1,27 @@
|
|||
{
|
||||
"name": "staking",
|
||||
"name": "@logos-co/staking",
|
||||
"description": "SNT staking contracts",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "hardhat.config.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"author": {},
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
|
||||
"@openzeppelin/contracts": "^4.9.2",
|
||||
"dotenv": "^16.3.1",
|
||||
"hardhat": "^2.16.1"
|
||||
"prettier": "^3.0.0",
|
||||
"solhint-community": "^3.6.0"
|
||||
},
|
||||
"keywords": [
|
||||
"blockchain",
|
||||
"ethereum",
|
||||
"forge",
|
||||
"foundry",
|
||||
"smart-contracts",
|
||||
"solidity",
|
||||
"template"
|
||||
],
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"clean": "rm -rf cache out",
|
||||
"lint": "pnpm lint:sol && pnpm prettier:check",
|
||||
"lint:sol": "forge fmt --check && pnpm solhint {script,src,test}/**/*.sol",
|
||||
"prettier:check": "prettier --check **/*.{json,md,yml} --ignore-path=.prettierignore",
|
||||
"prettier:write": "prettier --write **/*.{json,md,yml} --ignore-path=.prettierignore"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,452 @@
|
|||
lockfileVersion: '6.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
devDependencies:
|
||||
prettier:
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0
|
||||
solhint-community:
|
||||
specifier: ^3.6.0
|
||||
version: 3.6.0
|
||||
|
||||
packages:
|
||||
|
||||
/@babel/code-frame@7.22.5:
|
||||
resolution: {integrity: sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
dependencies:
|
||||
'@babel/highlight': 7.22.5
|
||||
dev: true
|
||||
|
||||
/@babel/helper-validator-identifier@7.22.5:
|
||||
resolution: {integrity: sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
dev: true
|
||||
|
||||
/@babel/highlight@7.22.5:
|
||||
resolution: {integrity: sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
dependencies:
|
||||
'@babel/helper-validator-identifier': 7.22.5
|
||||
chalk: 2.4.2
|
||||
js-tokens: 4.0.0
|
||||
dev: true
|
||||
|
||||
/@solidity-parser/parser@0.16.1:
|
||||
resolution: {integrity: sha512-PdhRFNhbTtu3x8Axm0uYpqOy/lODYQK+MlYSgqIsq2L8SFYEHJPHNUiOTAJbDGzNjjr1/n9AcIayxafR/fWmYw==}
|
||||
dependencies:
|
||||
antlr4ts: 0.5.0-alpha.4
|
||||
dev: true
|
||||
|
||||
/ajv@6.12.6:
|
||||
resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==}
|
||||
dependencies:
|
||||
fast-deep-equal: 3.1.3
|
||||
fast-json-stable-stringify: 2.1.0
|
||||
json-schema-traverse: 0.4.1
|
||||
uri-js: 4.4.1
|
||||
dev: true
|
||||
|
||||
/ajv@8.12.0:
|
||||
resolution: {integrity: sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==}
|
||||
dependencies:
|
||||
fast-deep-equal: 3.1.3
|
||||
json-schema-traverse: 1.0.0
|
||||
require-from-string: 2.0.2
|
||||
uri-js: 4.4.1
|
||||
dev: true
|
||||
|
||||
/ansi-regex@5.0.1:
|
||||
resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/ansi-styles@3.2.1:
|
||||
resolution: {integrity: sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==}
|
||||
engines: {node: '>=4'}
|
||||
dependencies:
|
||||
color-convert: 1.9.3
|
||||
dev: true
|
||||
|
||||
/ansi-styles@4.3.0:
|
||||
resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==}
|
||||
engines: {node: '>=8'}
|
||||
dependencies:
|
||||
color-convert: 2.0.1
|
||||
dev: true
|
||||
|
||||
/antlr4@4.13.0:
|
||||
resolution: {integrity: sha512-zooUbt+UscjnWyOrsuY/tVFL4rwrAGwOivpQmvmUDE22hy/lUA467Rc1rcixyRwcRUIXFYBwv7+dClDSHdmmew==}
|
||||
engines: {node: '>=16'}
|
||||
dev: true
|
||||
|
||||
/antlr4ts@0.5.0-alpha.4:
|
||||
resolution: {integrity: sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ==}
|
||||
dev: true
|
||||
|
||||
/argparse@2.0.1:
|
||||
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
|
||||
dev: true
|
||||
|
||||
/ast-parents@0.0.1:
|
||||
resolution: {integrity: sha512-XHusKxKz3zoYk1ic8Un640joHbFMhbqneyoZfoKnEGtf2ey9Uh/IdpcQplODdO/kENaMIWsD0nJm4+wX3UNLHA==}
|
||||
dev: true
|
||||
|
||||
/astral-regex@2.0.0:
|
||||
resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/balanced-match@1.0.2:
|
||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||
dev: true
|
||||
|
||||
/brace-expansion@2.0.1:
|
||||
resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==}
|
||||
dependencies:
|
||||
balanced-match: 1.0.2
|
||||
dev: true
|
||||
|
||||
/callsites@3.1.0:
|
||||
resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==}
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/chalk@2.4.2:
|
||||
resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==}
|
||||
engines: {node: '>=4'}
|
||||
dependencies:
|
||||
ansi-styles: 3.2.1
|
||||
escape-string-regexp: 1.0.5
|
||||
supports-color: 5.5.0
|
||||
dev: true
|
||||
|
||||
/chalk@4.1.2:
|
||||
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
supports-color: 7.2.0
|
||||
dev: true
|
||||
|
||||
/color-convert@1.9.3:
|
||||
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
|
||||
dependencies:
|
||||
color-name: 1.1.3
|
||||
dev: true
|
||||
|
||||
/color-convert@2.0.1:
|
||||
resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==}
|
||||
engines: {node: '>=7.0.0'}
|
||||
dependencies:
|
||||
color-name: 1.1.4
|
||||
dev: true
|
||||
|
||||
/color-name@1.1.3:
|
||||
resolution: {integrity: sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==}
|
||||
dev: true
|
||||
|
||||
/color-name@1.1.4:
|
||||
resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==}
|
||||
dev: true
|
||||
|
||||
/commander@10.0.1:
|
||||
resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==}
|
||||
engines: {node: '>=14'}
|
||||
dev: true
|
||||
|
||||
/cosmiconfig@8.2.0:
|
||||
resolution: {integrity: sha512-3rTMnFJA1tCOPwRxtgF4wd7Ab2qvDbL8jX+3smjIbS4HlZBagTlpERbdN7iAbWlrfxE3M8c27kTwTawQ7st+OQ==}
|
||||
engines: {node: '>=14'}
|
||||
dependencies:
|
||||
import-fresh: 3.3.0
|
||||
js-yaml: 4.1.0
|
||||
parse-json: 5.2.0
|
||||
path-type: 4.0.0
|
||||
dev: true
|
||||
|
||||
/emoji-regex@8.0.0:
|
||||
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
|
||||
dev: true
|
||||
|
||||
/error-ex@1.3.2:
|
||||
resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==}
|
||||
dependencies:
|
||||
is-arrayish: 0.2.1
|
||||
dev: true
|
||||
|
||||
/escape-string-regexp@1.0.5:
|
||||
resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==}
|
||||
engines: {node: '>=0.8.0'}
|
||||
dev: true
|
||||
|
||||
/fast-deep-equal@3.1.3:
|
||||
resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==}
|
||||
dev: true
|
||||
|
||||
/fast-diff@1.3.0:
|
||||
resolution: {integrity: sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==}
|
||||
dev: true
|
||||
|
||||
/fast-json-stable-stringify@2.1.0:
|
||||
resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==}
|
||||
dev: true
|
||||
|
||||
/fs.realpath@1.0.0:
|
||||
resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==}
|
||||
dev: true
|
||||
|
||||
/glob@8.1.0:
|
||||
resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==}
|
||||
engines: {node: '>=12'}
|
||||
dependencies:
|
||||
fs.realpath: 1.0.0
|
||||
inflight: 1.0.6
|
||||
inherits: 2.0.4
|
||||
minimatch: 5.1.6
|
||||
once: 1.4.0
|
||||
dev: true
|
||||
|
||||
/has-flag@3.0.0:
|
||||
resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==}
|
||||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/has-flag@4.0.0:
|
||||
resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/ignore@5.2.4:
|
||||
resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==}
|
||||
engines: {node: '>= 4'}
|
||||
dev: true
|
||||
|
||||
/import-fresh@3.3.0:
|
||||
resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==}
|
||||
engines: {node: '>=6'}
|
||||
dependencies:
|
||||
parent-module: 1.0.1
|
||||
resolve-from: 4.0.0
|
||||
dev: true
|
||||
|
||||
/inflight@1.0.6:
|
||||
resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==}
|
||||
dependencies:
|
||||
once: 1.4.0
|
||||
wrappy: 1.0.2
|
||||
dev: true
|
||||
|
||||
/inherits@2.0.4:
|
||||
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
|
||||
dev: true
|
||||
|
||||
/is-arrayish@0.2.1:
|
||||
resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==}
|
||||
dev: true
|
||||
|
||||
/is-fullwidth-code-point@3.0.0:
|
||||
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/js-tokens@4.0.0:
|
||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||
dev: true
|
||||
|
||||
/js-yaml@4.1.0:
|
||||
resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
argparse: 2.0.1
|
||||
dev: true
|
||||
|
||||
/json-parse-even-better-errors@2.3.1:
|
||||
resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==}
|
||||
dev: true
|
||||
|
||||
/json-schema-traverse@0.4.1:
|
||||
resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==}
|
||||
dev: true
|
||||
|
||||
/json-schema-traverse@1.0.0:
|
||||
resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==}
|
||||
dev: true
|
||||
|
||||
/lines-and-columns@1.2.4:
|
||||
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
|
||||
dev: true
|
||||
|
||||
/lodash.truncate@4.4.2:
|
||||
resolution: {integrity: sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==}
|
||||
dev: true
|
||||
|
||||
/lodash@4.17.21:
|
||||
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
|
||||
dev: true
|
||||
|
||||
/minimatch@5.1.6:
|
||||
resolution: {integrity: sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
brace-expansion: 2.0.1
|
||||
dev: true
|
||||
|
||||
/once@1.4.0:
|
||||
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
|
||||
dependencies:
|
||||
wrappy: 1.0.2
|
||||
dev: true
|
||||
|
||||
/parent-module@1.0.1:
|
||||
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
|
||||
engines: {node: '>=6'}
|
||||
dependencies:
|
||||
callsites: 3.1.0
|
||||
dev: true
|
||||
|
||||
/parse-json@5.2.0:
|
||||
resolution: {integrity: sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==}
|
||||
engines: {node: '>=8'}
|
||||
dependencies:
|
||||
'@babel/code-frame': 7.22.5
|
||||
error-ex: 1.3.2
|
||||
json-parse-even-better-errors: 2.3.1
|
||||
lines-and-columns: 1.2.4
|
||||
dev: true
|
||||
|
||||
/path-type@4.0.0:
|
||||
resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/pluralize@8.0.0:
|
||||
resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==}
|
||||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/prettier@2.8.8:
|
||||
resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==}
|
||||
engines: {node: '>=10.13.0'}
|
||||
hasBin: true
|
||||
requiresBuild: true
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/prettier@3.0.0:
|
||||
resolution: {integrity: sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==}
|
||||
engines: {node: '>=14'}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/punycode@2.3.0:
|
||||
resolution: {integrity: sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==}
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/require-from-string@2.0.2:
|
||||
resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: true
|
||||
|
||||
/resolve-from@4.0.0:
|
||||
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
|
||||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/semver@6.3.1:
|
||||
resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/slice-ansi@4.0.0:
|
||||
resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
astral-regex: 2.0.0
|
||||
is-fullwidth-code-point: 3.0.0
|
||||
dev: true
|
||||
|
||||
/solhint-community@3.6.0:
|
||||
resolution: {integrity: sha512-3WGi8nB9VSdC7B3xawktFoQkJEgX6rsUe7jWZJteDBdix+tAOGN+2ZhRr7Cyv1s+h5BRLSsNOXoh7Vg9KEeQbg==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
'@solidity-parser/parser': 0.16.1
|
||||
ajv: 6.12.6
|
||||
antlr4: 4.13.0
|
||||
ast-parents: 0.0.1
|
||||
chalk: 4.1.2
|
||||
commander: 10.0.1
|
||||
cosmiconfig: 8.2.0
|
||||
fast-diff: 1.3.0
|
||||
glob: 8.1.0
|
||||
ignore: 5.2.4
|
||||
js-yaml: 4.1.0
|
||||
lodash: 4.17.21
|
||||
pluralize: 8.0.0
|
||||
semver: 6.3.1
|
||||
strip-ansi: 6.0.1
|
||||
table: 6.8.1
|
||||
text-table: 0.2.0
|
||||
optionalDependencies:
|
||||
prettier: 2.8.8
|
||||
dev: true
|
||||
|
||||
/string-width@4.2.3:
|
||||
resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==}
|
||||
engines: {node: '>=8'}
|
||||
dependencies:
|
||||
emoji-regex: 8.0.0
|
||||
is-fullwidth-code-point: 3.0.0
|
||||
strip-ansi: 6.0.1
|
||||
dev: true
|
||||
|
||||
/strip-ansi@6.0.1:
|
||||
resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==}
|
||||
engines: {node: '>=8'}
|
||||
dependencies:
|
||||
ansi-regex: 5.0.1
|
||||
dev: true
|
||||
|
||||
/supports-color@5.5.0:
|
||||
resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==}
|
||||
engines: {node: '>=4'}
|
||||
dependencies:
|
||||
has-flag: 3.0.0
|
||||
dev: true
|
||||
|
||||
/supports-color@7.2.0:
|
||||
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
|
||||
engines: {node: '>=8'}
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
dev: true
|
||||
|
||||
/table@6.8.1:
|
||||
resolution: {integrity: sha512-Y4X9zqrCftUhMeH2EptSSERdVKt/nEdijTOacGD/97EKjhQ/Qs8RTlEGABSJNNN8lac9kheH+af7yAkEWlgneA==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
dependencies:
|
||||
ajv: 8.12.0
|
||||
lodash.truncate: 4.4.2
|
||||
slice-ansi: 4.0.0
|
||||
string-width: 4.2.3
|
||||
strip-ansi: 6.0.1
|
||||
dev: true
|
||||
|
||||
/text-table@0.2.0:
|
||||
resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==}
|
||||
dev: true
|
||||
|
||||
/uri-js@4.4.1:
|
||||
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
|
||||
dependencies:
|
||||
punycode: 2.3.0
|
||||
dev: true
|
||||
|
||||
/wrappy@1.0.2:
|
||||
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
|
||||
dev: true
|
|
@ -0,0 +1,2 @@
|
|||
forge-std/=lib/forge-std/src/
|
||||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts
|
|
@ -0,0 +1,41 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity >=0.8.19 <=0.9.0;
|
||||
|
||||
import { Script } from "forge-std/Script.sol";
|
||||
|
||||
abstract contract BaseScript is Script {
|
||||
/// @dev Included to enable compilation of the script without a $MNEMONIC environment variable.
|
||||
string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk";
|
||||
|
||||
/// @dev Needed for the deterministic deployments.
|
||||
bytes32 internal constant ZERO_SALT = bytes32(0);
|
||||
|
||||
/// @dev The address of the transaction broadcaster.
|
||||
address internal broadcaster;
|
||||
|
||||
/// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined.
|
||||
string internal mnemonic;
|
||||
|
||||
/// @dev Initializes the transaction broadcaster like this:
|
||||
///
|
||||
/// - If $ETH_FROM is defined, use it.
|
||||
/// - Otherwise, derive the broadcaster address from $MNEMONIC.
|
||||
/// - If $MNEMONIC is not defined, default to a test mnemonic.
|
||||
///
|
||||
/// The use case for $ETH_FROM is to specify the broadcaster key and its address via the command line.
|
||||
constructor() {
|
||||
address from = vm.envOr({ name: "ETH_FROM", defaultValue: address(0) });
|
||||
if (from != address(0)) {
|
||||
broadcaster = from;
|
||||
} else {
|
||||
mnemonic = vm.envOr({ name: "MNEMONIC", defaultValue: TEST_MNEMONIC });
|
||||
(broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: 0 });
|
||||
}
|
||||
}
|
||||
|
||||
modifier broadcast() {
|
||||
vm.startBroadcast(broadcaster);
|
||||
_;
|
||||
vm.stopBroadcast();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity >=0.8.19 <=0.9.0;
|
||||
|
||||
import { BaseScript } from "./Base.s.sol";
|
||||
import { DeploymentConfig } from "./DeploymentConfig.s.sol";
|
||||
import { StakeManager } from "../contracts/StakeManager.sol";
|
||||
|
||||
contract Deploy is BaseScript {
|
||||
function run() public returns (StakeManager, DeploymentConfig) {
|
||||
DeploymentConfig deploymentConfig = new DeploymentConfig(broadcaster);
|
||||
(address token,) = deploymentConfig.activeNetworkConfig();
|
||||
|
||||
vm.startBroadcast(broadcaster);
|
||||
StakeManager stakeManager = new StakeManager(token, address(0));
|
||||
vm.stopBroadcast();
|
||||
|
||||
return (stakeManager, deploymentConfig);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
//// SPDX-License-Identifier: UNLICENSED
|
||||
|
||||
pragma solidity >=0.8.19 <=0.9.0;
|
||||
|
||||
import { Script } from "forge-std/Script.sol";
|
||||
import { MockERC20 } from "../test/mocks/MockERC20.sol";
|
||||
|
||||
contract DeploymentConfig is Script {
|
||||
error DeploymentConfig_InvalidDeployerAddress();
|
||||
error DeploymentConfig_NoConfigForChain(uint256);
|
||||
|
||||
struct NetworkConfig {
|
||||
address deployer;
|
||||
address token;
|
||||
}
|
||||
|
||||
NetworkConfig public activeNetworkConfig;
|
||||
|
||||
address private deployer;
|
||||
|
||||
constructor(address _broadcaster) {
|
||||
if (block.chainid == 31_337) {
|
||||
activeNetworkConfig = getOrCreateAnvilEthConfig(_broadcaster);
|
||||
} else {
|
||||
revert DeploymentConfig_NoConfigForChain(block.chainid);
|
||||
}
|
||||
if (_broadcaster == address(0)) revert DeploymentConfig_InvalidDeployerAddress();
|
||||
deployer = _broadcaster;
|
||||
}
|
||||
|
||||
function getOrCreateAnvilEthConfig(address _deployer) public returns (NetworkConfig memory) {
|
||||
vm.startBroadcast();
|
||||
MockERC20 token = new MockERC20();
|
||||
vm.stopBroadcast();
|
||||
return NetworkConfig({ token: address(token), deployer: _deployer });
|
||||
}
|
||||
|
||||
// This function is a hack to have it excluded by `forge coverage` until
|
||||
// https://github.com/foundry-rs/foundry/issues/2988 is fixed.
|
||||
// See: https://github.com/foundry-rs/foundry/issues/2988#issuecomment-1437784542
|
||||
// for more info.
|
||||
// solhint-disable-next-line
|
||||
function test() public { }
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"detectors_to_exclude": "naming-convention,reentrancy-events,solc-version,timestamp",
|
||||
"filter_paths": "(lib|test)",
|
||||
"solc_remaps": [
|
||||
"@openzeppelin/contracts=lib/openzeppelin-contracts/contracts/",
|
||||
"forge-std/=lib/forge-std/src/"
|
||||
]
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
const { expect } = require("chai");
|
||||
const { ethers } = require("hardhat");
|
||||
const {
|
||||
loadFixture
|
||||
} = require("@nomicfoundation/hardhat-network-helpers");
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
describe("StakeManager contract", function () {
|
||||
async function deployTokenFixture() {
|
||||
const [owner, addr1, addr2, addr3] = await ethers.getSigners();
|
||||
const testToken = await ethers.deployContract("Token");
|
||||
await Promise.all([ testToken.mint(addr1.address, 12 * 10^18),
|
||||
testToken.mint(addr2.address, 24 * 10^18),
|
||||
testToken.mint(addr3.address, 36 * 10^18)]);
|
||||
return { testToken, owner, addr1, addr2, addr3 };
|
||||
}
|
||||
|
||||
async function deployStakeManager() {
|
||||
const { testToken, owner } = await loadFixture(deployTokenFixture);
|
||||
console.log(testToken)
|
||||
const stakeManager = await ethers.deployContract("StakeManager", [testToken.target, "0x0000000000000000000000000000000000000000"]);
|
||||
return { stakeManager, testToken, owner };
|
||||
}
|
||||
|
||||
|
||||
it("Deployment should be initialized zero", async function () {
|
||||
const { stakeManager, testToken, owner } = await loadFixture(deployStakeManager);
|
||||
expect(await stakeManager.totalSupply()).to.equal(0);
|
||||
expect(await stakeManager.totalSupply()).to.equal(0);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import { Test } from "forge-std/Test.sol";
|
||||
import { Deploy } from "../script/Deploy.s.sol";
|
||||
import { DeploymentConfig } from "../script/DeploymentConfig.s.sol";
|
||||
import { StakeManager } from "../contracts/StakeManager.sol";
|
||||
|
||||
contract StakeManagerTest is Test {
|
||||
address internal deployer;
|
||||
|
||||
DeploymentConfig internal deploymentConfig;
|
||||
StakeManager internal stakeManager;
|
||||
|
||||
function setUp() public virtual {
|
||||
Deploy deployment = new Deploy();
|
||||
(stakeManager, deploymentConfig) = deployment.run();
|
||||
(deployer,) = deploymentConfig.activeNetworkConfig();
|
||||
}
|
||||
|
||||
function testDeployment() public {
|
||||
assertEq(stakeManager.owner(), deployer);
|
||||
assertEq(stakeManager.totalSupply(), 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.19;
|
||||
|
||||
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
contract MockERC20 is ERC20 {
|
||||
constructor() ERC20("Mock SNT", "SNT") {
|
||||
_mint(msg.sender, 1_000_000_000_000_000_000);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue