Skip to content

Commit

Permalink
Merge pull request #2 from maple-labs/release
Browse files Browse the repository at this point in the history
Release v1.1.0
  • Loading branch information
JGcarv committed Dec 20, 2023
2 parents db96bb2 + 329be5f commit a1cf7f9
Show file tree
Hide file tree
Showing 27 changed files with 645 additions and 342 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/CODEOWNERS
Validating CODEOWNERS rules …
@@ -0,0 +1,2 @@
# These owners will be the default owners for everything in the repo.
* @maple-labs/smart-contracts-admin
57 changes: 54 additions & 3 deletions .github/workflows/forge-pr.yml
@@ -1,20 +1,71 @@
name: Forge Tests (PR)

on:
pull_request:
on: [pull_request]

jobs:
test:
name: Test with "deep" profile
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 "git@github.com:"
git submodule update --init --recursive
- name: Run Forge tests
run: ./scripts/test.sh -p shallow
run: ./scripts/test.sh -p deep

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 "git@github.com:"
git submodule update --init --recursive
- name: Generate coverage report
run: |
forge coverage --report lcov
sudo apt-get install lcov
lcov --remove lcov.info -o lcov.info 'tests/*'
- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@v1
with:
coverage-files: lcov.info
minimum-coverage: 90
artifact-name: code-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ./

size_check:
name: Check contracts sizes
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 "git@github.com:"
git submodule update --init --recursive
- name: Check contract sizes
run: ./scripts/check-sizes.sh
54 changes: 53 additions & 1 deletion .github/workflows/forge.yml
Expand Up @@ -6,16 +6,68 @@ on:

jobs:
test:
name: Test with "deep" profile
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 "git@github.com:"
git submodule update --init --recursive
- name: Run Forge tests
run: ./scripts/test.sh -p deep
run: ./scripts/test.sh -p super_deep

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 "git@github.com:"
git submodule update --init --recursive
- name: Generate coverage report
run: |
forge coverage --report lcov
sudo apt-get install lcov
lcov --remove lcov.info -o lcov.info 'tests/*'
- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@v1
with:
coverage-files: lcov.info
minimum-coverage: 90
artifact-name: code-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ./

size_check:
name: Check contracts sizes
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 "git@github.com:"
git submodule update --init --recursive
- name: Check contract sizes
run: ./scripts/check-sizes.sh
12 changes: 6 additions & 6 deletions .gitmodules
@@ -1,12 +1,12 @@
[submodule "modules/contract-test-utils"]
path = modules/contract-test-utils
url = https://github.com/maple-labs/contract-test-utils
[submodule "modules/erc20"]
path = modules/erc20
url = https://github.com/maple-labs/erc20
url = git@github.com:maple-labs/erc20.git
[submodule "modules/erc20-helper"]
path = modules/erc20-helper
url = https://github.com/maple-labs/erc20-helper
url = git@github.com:maple-labs/erc20-helper.git
[submodule "modules/maple-proxy-factory"]
path = modules/maple-proxy-factory
url = https://github.com/maple-labs/maple-proxy-factory.git
url = git@github.com:maple-labs/maple-proxy-factory.git
[submodule "modules/forge-std"]
path = modules/forge-std
url = git@github.com:foundry-rs/forge-std.git
16 changes: 5 additions & 11 deletions Makefile
@@ -1,17 +1,11 @@
install:
@git submodule update --init --recursive

update:
@forge update

build:
@scripts/build.sh
@scripts/build.sh -p production

release:
@scripts/release.sh

test:
@scripts/test.sh
size:
@scripts/check-sizes.sh

clean:
@forge clean
test:
@scripts/test.sh -p default
10 changes: 6 additions & 4 deletions README.md
@@ -1,9 +1,9 @@
# Withdrawal Manager

![Foundry CI](https://github.com/maple-labs/withdrawal-manager/actions/workflows/forge.yml/badge.svg)
![Foundry CI](https://github.com/maple-labs/withdrawal-manager-cyclical/actions/workflows/forge.yml/badge.svg)
[![GitBook - Documentation](https://img.shields.io/badge/GitBook-Documentation-orange?logo=gitbook&logoColor=white)](https://maplefinance.gitbook.io/maple/maple-for-developers/protocol-overview)
[![Foundry][foundry-badge]][foundry]
[![License: BUSL 1.1](https://img.shields.io/badge/License-BUSL%201.1-blue.svg)](https://github.com/maple-labs/withdrawal-manager/blob/main/LICENSE)
[![License: BUSL 1.1](https://img.shields.io/badge/License-BUSL%201.1-blue.svg)](https://github.com/maple-labs/withdrawal-manager-cyclical/blob/main/LICENSE)

[foundry]: https://getfoundry.sh/
[foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg
Expand Down Expand Up @@ -31,8 +31,8 @@ Versions of dependencies can be checked with `git submodule status`.
This project was built using [Foundry](https://book.getfoundry.sh/). Refer to installation instructions [here](https://github.com/foundry-rs/foundry#installation).

```sh
git clone git@github.com:maple-labs/withdrawal-manager.git
cd withdrawal-manager
git clone git@github.com:maple-labs/withdrawal-manager-cyclical.git
cd withdrawal-manager-cyclical
forge install
```

Expand All @@ -50,6 +50,8 @@ forge install
| Trail of Bits | [`2022-08-24 - Trail of Bits Report`](https://docs.google.com/viewer?url=https://github.com/maple-labs/maple-v2-audits/files/10246688/Maple.Finance.v2.-.Final.Report.-.Fixed.-.2022.pdf) |
| Spearbit | [`2022-10-17 - Spearbit Report`](https://docs.google.com/viewer?url=https://github.com/maple-labs/maple-v2-audits/files/10223545/Maple.Finance.v2.-.Spearbit.pdf) |
| Three Sigma | [`2022-10-24 - Three Sigma Report`](https://docs.google.com/viewer?url=https://github.com/maple-labs/maple-v2-audits/files/10223541/three-sigma_maple-finance_code-audit_v1.1.1.pdf) |
| Three Sigma | [`2023-11-06 - Three Sigma Report`](https://docs.google.com/viewer?url=https://github.com/maple-labs/maple-v2-audits/files/13707288/Maple-Q4-Three-Sigma-Audit.pdf) |
| 0xMacro | [`2023-11-27 - 0xMacro Report`](https://docs.google.com/viewer?url=https://github.com/maple-labs/maple-v2-audits/files/13707291/Maple-Q4-0xMacro-Audit.pdf) |

## Bug Bounty

Expand Down
16 changes: 7 additions & 9 deletions configs/package.yaml
@@ -1,13 +1,11 @@
name: withdrawal-manager
version: 1.0.0-beta.0
version: 1.0.1
source: contracts
packages:
- path: contracts/WithdrawalManager.sol
contractName: WithdrawalManager
- path: contracts/WithdrawalManagerFactory.sol
contractName: WithdrawalManagerFactory
- path: contracts/WithdrawalManagerInitializer.sol
contractName: WithdrawalManagerInitializer
- path: contracts/WithdrawalManagerStorage.sol
contractName: WithdrawalManagerStorage
- path: contracts/MapleWithdrawalManager.sol
contractName: MapleWithdrawalManager
- path: contracts/MapleWithdrawalManagerFactory.sol
contractName: MapleWithdrawalManagerFactory
- path: contracts/MapleWithdrawalManagerInitializer.sol
contractName: MapleWithdrawalManagerInitializer
customDescription: Withdrawal Manager Artifacts and ABIs
Expand Up @@ -5,14 +5,22 @@ import { ERC20Helper } from "../modules/erc20-helper/src/ERC20Helper.s
import { IMapleProxyFactory } from "../modules/maple-proxy-factory/contracts/interfaces/IMapleProxyFactory.sol";
import { MapleProxiedInternals } from "../modules/maple-proxy-factory/contracts/MapleProxiedInternals.sol";

import { IERC20Like, IMapleGlobalsLike, IPoolLike, IPoolManagerLike } from "./interfaces/Interfaces.sol";
import { IERC20Like, IGlobalsLike, IPoolLike, IPoolManagerLike } from "./interfaces/Interfaces.sol";

import { IWithdrawalManager } from "./interfaces/IWithdrawalManager.sol";
import { IMapleWithdrawalManager } from "./interfaces/IMapleWithdrawalManager.sol";

import { WithdrawalManagerStorage } from "./WithdrawalManagerStorage.sol";
import { MapleWithdrawalManagerStorage } from "./MapleWithdrawalManagerStorage.sol";

/*
███╗ ███╗ █████╗ ██████╗ ██╗ ███████╗
████╗ ████║██╔══██╗██╔══██╗██║ ██╔════╝
██╔████╔██║███████║██████╔╝██║ █████╗
██║╚██╔╝██║██╔══██║██╔═══╝ ██║ ██╔══╝
██║ ╚═╝ ██║██║ ██║██║ ███████╗███████╗
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝
██╗ ██╗██╗████████╗██╗ ██╗██████╗ ██████╗ █████╗ ██╗ ██╗ █████╗ ██╗
██║ ██║██║╚══██╔══╝██║ ██║██╔══██╗██╔══██╗██╔══██╗██║ ██║██╔══██╗██║
██║ █╗ ██║██║ ██║ ███████║██║ ██║██████╔╝███████║██║ █╗ ██║███████║██║
Expand Down Expand Up @@ -58,14 +66,27 @@ import { WithdrawalManagerStorage } from "./WithdrawalManagerStorage.sol";
*/

contract WithdrawalManager is IWithdrawalManager, WithdrawalManagerStorage, MapleProxiedInternals {
contract MapleWithdrawalManager is IMapleWithdrawalManager, MapleWithdrawalManagerStorage, MapleProxiedInternals {

// NOTE: The following functions already check for paused state in the pool, therefore no need to check here.
// * addShares
// * removeShares
// * processExit
modifier whenProtocolNotPaused() {
require(!IMapleGlobalsLike(globals()).protocolPaused(), "WM:PROTOCOL_PAUSED");
require(!IGlobalsLike(globals()).protocolPaused(), "WM:PROTOCOL_PAUSED");
_;
}

modifier onlyPoolDelegateOrProtocolAdmins {
address globals_ = globals();

require(
msg.sender == IPoolManagerLike(poolManager).poolDelegate() ||
msg.sender == IGlobalsLike(globals_).governor() ||
msg.sender == IGlobalsLike(globals_).operationalAdmin(),
"WM:NOT_PD_OR_GOV_OR_OA"
);

_;
}

Expand All @@ -86,9 +107,9 @@ contract WithdrawalManager is IWithdrawalManager, WithdrawalManagerStorage, Mapl
function upgrade(uint256 version_, bytes calldata arguments_) external override {
address poolDelegate_ = poolDelegate();

require(msg.sender == poolDelegate_ || msg.sender == governor(), "WM:U:NOT_AUTHORIZED");
IGlobalsLike mapleGlobals_ = IGlobalsLike(globals());

IMapleGlobalsLike mapleGlobals_ = IMapleGlobalsLike(globals());
require(msg.sender == poolDelegate_ || msg.sender == mapleGlobals_.securityAdmin(), "WM:U:NOT_AUTHORIZED");

if (msg.sender == poolDelegate_) {
require(mapleGlobals_.isValidScheduledCall(msg.sender, address(this), "WM:UPGRADE", msg.data), "WM:U:INVALID_SCHED_CALL");
Expand All @@ -103,8 +124,12 @@ contract WithdrawalManager is IWithdrawalManager, WithdrawalManagerStorage, Mapl
/*** Administrative Functions ***/
/**************************************************************************************************************************************/

function setExitConfig(uint256 cycleDuration_, uint256 windowDuration_) external override whenProtocolNotPaused {
require(msg.sender == poolDelegate(), "WM:SEC:NOT_AUTHORIZED");
function setExitConfig(
uint256 cycleDuration_,
uint256 windowDuration_
)
external override whenProtocolNotPaused onlyPoolDelegateOrProtocolAdmins
{
require(windowDuration_ != 0, "WM:SEC:ZERO_WINDOW");
require(windowDuration_ <= cycleDuration_, "WM:SEC:WINDOW_OOB");

Expand Down Expand Up @@ -321,17 +346,22 @@ contract WithdrawalManager is IWithdrawalManager, WithdrawalManagerStorage, Mapl
function getCurrentConfig() public view override returns (CycleConfig memory config_) {
uint256 configId_ = latestConfigId;

while (block.timestamp < cycleConfigs[configId_].initialCycleTime) {
while (configId_ != 0 && block.timestamp < cycleConfigs[configId_].initialCycleTime) {
--configId_;
}

config_ = cycleConfigs[configId_];
}

// NOTE: If the first cycle has not been reached yet it will still be returned as the current one.
function getCurrentCycleId() public view override returns (uint256 cycleId_) {
CycleConfig memory config_ = getCurrentConfig();

cycleId_ = config_.initialCycleId + (block.timestamp - config_.initialCycleTime) / config_.cycleDuration;
cycleId_ = config_.initialCycleId;

if (block.timestamp > config_.initialCycleTime) {
cycleId_ += (block.timestamp - config_.initialCycleTime) / config_.cycleDuration;
}
}

function getRedeemableAmounts(uint256 lockedShares_, address owner_)
Expand Down Expand Up @@ -386,7 +416,7 @@ contract WithdrawalManager is IWithdrawalManager, WithdrawalManagerStorage, Mapl
}

function governor() public view override returns (address governor_) {
governor_ = IMapleGlobalsLike(globals()).governor();
governor_ = IGlobalsLike(globals()).governor();
}

function implementation() external view override returns (address implementation_) {
Expand Down
Expand Up @@ -3,14 +3,14 @@ pragma solidity 0.8.7;

import { MapleProxyFactory } from "../modules/maple-proxy-factory/contracts/MapleProxyFactory.sol";

import { IMapleGlobalsLike } from "./interfaces/Interfaces.sol";
import { IGlobalsLike } from "./interfaces/Interfaces.sol";

contract WithdrawalManagerFactory is MapleProxyFactory {
contract MapleWithdrawalManagerFactory is MapleProxyFactory {

constructor(address globals_) MapleProxyFactory(globals_) {}

function createInstance(bytes calldata arguments_, bytes32 salt_) public override(MapleProxyFactory) returns (address instance_) {
require(IMapleGlobalsLike(mapleGlobals).isPoolDeployer(msg.sender), "WMF:CI:NOT_DEPLOYER");
require(IGlobalsLike(mapleGlobals).isPoolDeployer(msg.sender), "WMF:CI:NOT_DEPLOYER");

isInstance[instance_ = super.createInstance(arguments_, salt_)] = true;
}
Expand Down

0 comments on commit a1cf7f9

Please sign in to comment.