Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added proxy infra #2

Merged
merged 9 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
JGcarv marked this conversation as resolved.
Show resolved Hide resolved
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: ./
34 changes: 31 additions & 3 deletions contracts/MapleToken.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
// 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";
JGcarv marked this conversation as resolved.
Show resolved Hide resolved
import { NonTransparentProxied } from "../modules/ntp/contracts/NonTransparentProxied.sol";

import { IMapleToken } from "./interfaces/IMapleToken.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);

/**************************************************************************************************************************************/
/*** 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";
JGcarv marked this conversation as resolved.
Show resolved Hide resolved
}

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_);
}

}
2 changes: 1 addition & 1 deletion modules/ntp
54 changes: 52 additions & 2 deletions tests/MapleToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,57 @@ pragma solidity 0.8.18;

import { TestBase } from "./utils/TestBase.sol";

// TODO: Potentially split up into multiple test files.
contract MapleTokenTests is TestBase {
import { MapleTokenProxy } from "../contracts/MapleTokenProxy.sol";
import { MapleToken } from "../contracts/MapleToken.sol";

import { MockGlobals } from "./utils/Mocks.sol";

contract MapleTokenTestsBase is TestBase {

address governor = makeAddr("governor");

address implementation;
address token;

MockGlobals globals;

function setUp() public virtual {
globals = new MockGlobals();
globals.__setGovernor(governor);

implementation = address(new MapleToken());
token = address(new MapleTokenProxy(governor, (implementation), address(globals)));
JGcarv marked this conversation as resolved.
Show resolved Hide resolved
}

}

contract ProxyTests is MapleTokenTestsBase {

function test_proxySetup() external {
MapleToken token_ = MapleToken(token);

assertEq(token_.implementation(), address(implementation));
assertEq(token_.globals(), address(globals));
assertEq(token_.admin(), governor);

assertEq(token_.name(), "MPL");
assertEq(token_.symbol(), "MPL");
assertEq(token_.decimals(), 18);
}

}

contract SetImplementationTests is MapleTokenTestsBase {

function test_setImplementation_notAdmin() external {
vm.expectRevert("NTP:SI:NOT_ADMIN");
MapleTokenProxy(token).setImplementation(address(0x1));
}

function test_setImplementation_success() external {
address newImplementation = address(new MapleToken());

vm.prank(governor);
MapleTokenProxy(token).setImplementation(newImplementation);
}
}
10 changes: 10 additions & 0 deletions tests/utils/Mocks.sol
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.18;

contract MockGlobals {

address public governor;

function __setGovernor(address governor_) external {
governor = governor_;
}

}