Skip to content

Commit

Permalink
feat: create MapleTokenProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
JGcarv committed Jun 19, 2023
1 parent b0e1851 commit 51087f8
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 59 deletions.
59 changes: 33 additions & 26 deletions .github/workflows/forge-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,36 @@ jobs:
- name: Run tests
run: forge test

# coverage_report:
# name: Generate coverage report
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2

# - name: Install Foundry
# uses: onbjerg/foundry-toolchain@v1
# with:
# version: nightly

# - name: Install submodules
# run: |
# git config --global url."https://github.com/".insteadOf "[email protected]:"
# git submodule update --init --recursive
# - name: Generate coverage report
# run: |
# forge coverage --report lcov
# - name: Report code coverage
# uses: zgosalvez/github-actions-report-lcov@v1
# with:
# coverage-files: lcov.info
# minimum-coverage: 95
# artifact-name: code-coverage-report
# github-token: ${{ secrets.GITHUB_TOKEN }}
# working-directory: ./
coverage_report:
name: Generate coverage report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Install submodules
run: |
git config --global url."https://github.com/".insteadOf "[email protected]:"
git submodule update --init --recursive
- name: Generate coverage report
run: |
forge coverage --report lcov
- name: Install lcov
run: sudo apt-get install lcov

- name: Remove Tests from coverage
run: lcov --remove ./lcov.info -o ./lcov.info.pruned 'tests/*'

- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@v1
with:
coverage-files: lcov.info.pruned
minimum-coverage: 90
artifact-name: code-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ./
59 changes: 33 additions & 26 deletions .github/workflows/forge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,36 @@ jobs:
env:
FOUNDRY_PROFILE: production

# coverage_report:
# name: Generate coverage report
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2

# - name: Install Foundry
# uses: onbjerg/foundry-toolchain@v1
# with:
# version: nightly

# - name: Install submodules
# run: |
# git config --global url."https://github.com/".insteadOf "[email protected]:"
# git submodule update --init --recursive
# - name: Generate coverage report
# run: |
# forge coverage --report lcov
# - name: Report code coverage
# uses: zgosalvez/github-actions-report-lcov@v1
# with:
# coverage-files: lcov.info
# minimum-coverage: 95
# artifact-name: code-coverage-report
# github-token: ${{ secrets.GITHUB_TOKEN }}
# working-directory: ./
coverage_report:
name: Generate coverage report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Install submodules
run: |
git config --global url."https://github.com/".insteadOf "[email protected]:"
git submodule update --init --recursive
- name: Generate coverage report
run: |
forge coverage --report lcov
- name: Install lcov
run: sudo apt-get install lcov

- name: Remove Tests from coverage
run: lcov --remove ./lcov.info -o ./lcov.info.pruned 'tests/*'

- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@v1
with:
coverage-files: lcov.info.pruned
minimum-coverage: 90
artifact-name: code-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ./
71 changes: 68 additions & 3 deletions contracts/MapleToken.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,74 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.18;

import { ERC20 } from "../modules/erc20/contracts/ERC20.sol";
import { ERC20Proxied } from "../modules/erc20/contracts/ERC20Proxied.sol";
import { NonTransparentProxied } from "../modules/ntp/contracts/NonTransparentProxied.sol";

import { IMapleToken } from "./interfaces/IMapleToken.sol";
import { IGlobalsLike } from "./interfaces/Interfaces.sol";
import { IMapleToken, IERC20 } from "./interfaces/IMapleToken.sol";

abstract contract MapleToken is IMapleToken, ERC20, NonTransparentProxied { }
contract MapleToken is IMapleToken, ERC20Proxied, NonTransparentProxied {

bytes32 internal constant GLOBALS_SLOT = bytes32(uint256(keccak256("eip1967.proxy.globals")) - 1);

mapping(address => bool) public isBurner;
mapping(address => bool) public isMinter;

modifier onlyGovernor {
require(msg.sender == IGlobalsLike(globals()).governor(), "MT:NOT_GOVERNOR");
_;
}

/**************************************************************************************************************************************/
/*** External Functions ***/
/**************************************************************************************************************************************/

// Note: technically, a module can be removed with this function, but that's alright, since it's more restrictive than removeModule()
function addModule(address module, bool burner, bool minter) external onlyGovernor {
require(burner || minter, "MT:AM:INVALID_MODULE");
// TODO: add scheduling

isBurner[module] = burner;
isMinter[module] = minter;
}

function removeModule(address module) external onlyGovernor {
delete isBurner[module];
delete isMinter[module];
}

function burn(address from_, uint256 amount_) external {
require(isBurner[msg.sender], "MT:B:NOT_BURNER");
_burn(from_, amount_);
}

function mint(address to_, uint256 amount_) external {
require(isMinter[msg.sender], "MT:M:NOT_MINTER");
_mint(to_, amount_);
}

/**************************************************************************************************************************************/
/*** Pure Functions ***/
/**************************************************************************************************************************************/

function decimals() public pure override(ERC20Proxied, IERC20) returns (uint8 decimals_) {
decimals_ = 18;
}

function name() public pure override(ERC20Proxied, IERC20) returns (string memory name_) {
name_ = "MPL";
}

function symbol() public pure override(ERC20Proxied, IERC20) returns (string memory symbol_) {
symbol_ = "MPL";
}

/**************************************************************************************************************************************/
/*** View Functions ***/
/**************************************************************************************************************************************/

function globals() public view override returns (address globals_) {
globals_ = _getAddress(GLOBALS_SLOT);
}

}
24 changes: 24 additions & 0 deletions contracts/MapleTokenProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.18;

import { NonTransparentProxy } from "../modules/ntp/contracts/NonTransparentProxy.sol";

contract MapleTokenProxy is NonTransparentProxy {

bytes32 internal constant GLOBALS_SLOT = bytes32(uint256(keccak256("eip1967.proxy.globals")) - 1);

constructor(address admin_, address implementation_, address globals_) NonTransparentProxy(admin_, implementation_) {
_setAddress(GLOBALS_SLOT, globals_);
}

/**************************************************************************************************************************************/
/*** Overridden Functions ***/
/**************************************************************************************************************************************/

function setImplementation(address newImplementation_) override external {
// TODO: Check globals for scheduled call
require(msg.sender == _admin(), "NTP:SI:NOT_ADMIN");
_setAddress(IMPLEMENTATION_SLOT, newImplementation_);
}

}
8 changes: 8 additions & 0 deletions contracts/interfaces/Interfaces.sol
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.18;

interface IGlobalsLike {

function governor() external view returns (address governor);

function mapleTreasury() external view returns (address mapleTreasury);

}
2 changes: 1 addition & 1 deletion modules/erc20
2 changes: 1 addition & 1 deletion modules/ntp
Loading

0 comments on commit 51087f8

Please sign in to comment.