-
Notifications
You must be signed in to change notification settings - Fork 0
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 migrator contract and tests (SC-4769) #1
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
78a241f
feat: added migrator contract and tests
JGcarv 56abc5a
fix: adjust slither target
JGcarv e1068b7
fix: PR ci
JGcarv 35f3b88
fix: increase runs for push to main
JGcarv f257ea9
fix: PR comments
JGcarv 36db0a2
fix readme
JGcarv ecf33f1
fix readme
JGcarv 14ba45a
feat: update README, test.sh, add newlines
lucas-manuel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,19 @@ jobs: | |
run-ci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install Foundry | ||
uses: onbjerg/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
- name: Install Foundry | ||
uses: onbjerg/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Pull library deps | ||
run: forge update | ||
|
||
- name: Run forge tests | ||
run: ./test.sh -r 1000 | ||
- name: Checkout submodules | ||
shell: bash | ||
run: | | ||
git config --global url."https://github.com/".insteadOf "[email protected]:" | ||
forge update | ||
- name: Run forge tests | ||
env: | ||
ETH_RPC_URL: ${{ secrets.ETH_RPC_URL }} | ||
run: ./test.sh -r 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: 50k fuzz run test on push to main | ||
name: SC Tests | ||
|
||
on: | ||
push: | ||
|
@@ -9,15 +9,19 @@ jobs: | |
run-ci: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install Foundry | ||
uses: onbjerg/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
- name: Install Foundry | ||
uses: onbjerg/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Pull library deps | ||
run: forge update | ||
|
||
- name: Run forge tests | ||
run: ./test.sh -r 50000 | ||
- name: Checkout submodules | ||
shell: bash | ||
run: | | ||
git config --global url."https://github.com/".insteadOf "[email protected]:" | ||
forge update | ||
- name: Run forge tests | ||
env: | ||
ETH_RPC_URL: ${{ secrets.ETH_RPC_URL }} | ||
run: ./test.sh -r 1000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[submodule "modules/erc20"] | ||
path = modules/erc20 | ||
url = [email protected]:maple-labs/erc20.git | ||
[submodule "modules/erc20-helper"] | ||
path = modules/erc20-helper | ||
url = [email protected]:maple-labs/erc20-helper.git | ||
[submodule "modules/contract-test-utils"] | ||
path = modules/contract-test-utils | ||
url = [email protected]:maple-labs/contract-test-utils.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# MPLMigration | ||
# MPL Migration | ||
|
||
![Foundry CI](https://github.com/maple-labs/loan/actions/workflows/push-to-main.yml/badge.svg) [![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0) | ||
|
||
**DISCLAIMER: This code has NOT been externally audited and is actively being developed. Please do not use in production without taking the appropriate steps to ensure maximum security.** | ||
|
||
This repo contains a set of contracts to facilitate on-chain distribution of vesting earnings on an aggregated schedule. This allows for multiple deposits to be made to the same contract on a recurring basis with custom vesting parameters. | ||
This repo contains a set of contracts to facilitate MPL token migration. | ||
|
||
## Testing and Development | ||
#### Setup | ||
```sh | ||
git clone [email protected]:maple-labs/revenue-distribution-token.git | ||
cd revenue-distribution-token | ||
git clone [email protected]:maple-labs/mpl-migration.git | ||
cd mpl-migration | ||
forge update | ||
``` | ||
#### Running Tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity 0.8.7; | ||
|
||
import { ERC20Helper } from "../modules/erc20-helper/src/ERC20Helper.sol"; | ||
|
||
contract Migrator { | ||
|
||
address immutable oldToken; | ||
address immutable newToken; | ||
|
||
constructor(address oldToken_, address newToken_) { | ||
oldToken = oldToken_; | ||
newToken = newToken_; | ||
} | ||
|
||
function migrate(uint256 amount_) external { | ||
require(amount_ > 0, "M:M:ZERO_AMOUNT"); | ||
|
||
require(ERC20Helper.transferFrom(oldToken, msg.sender, address(this), amount_), "M:M:TRANSFER_FROM_FAILED"); | ||
require(ERC20Helper.transfer(newToken, msg.sender, amount_), "M:M:TRANSFER_FAILED"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity 0.8.7; | ||
|
||
import { TestUtils } from "../../modules/contract-test-utils/contracts/test.sol"; | ||
|
||
import { MockERC20 } from "../../modules/erc20/src/test/mocks/MockERC20.sol"; | ||
|
||
import { Migrator } from "../Migrator.sol"; | ||
|
||
contract MigratorTest is TestUtils { | ||
|
||
uint256 public constant OLD_SUPPLY = 10_000_000 ether; | ||
|
||
Migrator migrator; | ||
MockERC20 oldToken; | ||
MockERC20 newToken; | ||
|
||
function setUp() external { | ||
oldToken = new MockERC20("Old Token", "OT", 18); | ||
newToken = new MockERC20("New Token", "NT", 18); | ||
|
||
migrator = new Migrator(address(oldToken), address(newToken)); | ||
|
||
// Mint new token to migrator | ||
newToken.mint(address(migrator), OLD_SUPPLY); | ||
} | ||
|
||
function test_migration(uint256 amount_) external { | ||
amount_ = constrictToRange(amount_, 1, OLD_SUPPLY); | ||
|
||
// Mint amount of old token | ||
oldToken.mint(address(this), amount_); | ||
|
||
// Approve | ||
oldToken.approve(address(migrator), amount_); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), amount_); | ||
assertEq(oldToken.balanceOf(address(migrator)), 0); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), amount_); | ||
assertEq(newToken.balanceOf(address(this)), 0); | ||
assertEq(newToken.balanceOf(address(migrator)), OLD_SUPPLY); | ||
|
||
migrator.migrate(amount_); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), 0); | ||
assertEq(oldToken.balanceOf(address(migrator)), amount_); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), 0); | ||
assertEq(newToken.balanceOf(address(this)), amount_); | ||
assertEq(newToken.balanceOf(address(migrator)), OLD_SUPPLY - amount_); | ||
} | ||
|
||
function test_partialMigration(uint256 amount_, uint256 partialAmount_) external { | ||
amount_ = constrictToRange(amount_, 2, OLD_SUPPLY); | ||
partialAmount_ = constrictToRange(partialAmount_, 1, amount_ - 1); | ||
|
||
// Mint amount of old token | ||
oldToken.mint(address(this), amount_); | ||
|
||
// Approve partial | ||
oldToken.approve(address(migrator), partialAmount_); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), amount_); | ||
assertEq(oldToken.balanceOf(address(migrator)), 0); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), partialAmount_); | ||
assertEq(newToken.balanceOf(address(this)), 0); | ||
assertEq(newToken.balanceOf(address(migrator)), OLD_SUPPLY); | ||
|
||
migrator.migrate(partialAmount_); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), amount_ - partialAmount_); | ||
assertEq(oldToken.balanceOf(address(migrator)), partialAmount_); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), 0); | ||
assertEq(newToken.balanceOf(address(this)), partialAmount_); | ||
assertEq(newToken.balanceOf(address(migrator)), OLD_SUPPLY - partialAmount_); | ||
|
||
uint256 remaining = amount_ - partialAmount_; | ||
|
||
oldToken.approve(address(migrator), remaining); | ||
|
||
migrator.migrate(remaining); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), 0); | ||
assertEq(oldToken.balanceOf(address(migrator)), amount_); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), 0); | ||
assertEq(newToken.balanceOf(address(this)), amount_); | ||
assertEq(newToken.balanceOf(address(migrator)), OLD_SUPPLY - amount_); | ||
} | ||
|
||
function test_zeroAmount() external { | ||
uint256 amount_ = 0; | ||
|
||
vm.expectRevert("M:M:ZERO_AMOUNT"); | ||
migrator.migrate(amount_); | ||
|
||
amount_ = 1; | ||
|
||
oldToken.mint(address(this), amount_); | ||
oldToken.approve(address(migrator), amount_); | ||
|
||
migrator.migrate(amount_); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), 0); | ||
assertEq(oldToken.balanceOf(address(migrator)), amount_); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), 0); | ||
assertEq(newToken.balanceOf(address(this)), amount_); | ||
assertEq(newToken.balanceOf(address(migrator)), OLD_SUPPLY - amount_); | ||
} | ||
|
||
function test_failWithoutApprove(uint256 amount_) external { | ||
amount_ = constrictToRange(amount_, 1, OLD_SUPPLY); | ||
|
||
// Mint amount of old token | ||
oldToken.mint(address(this), amount_); | ||
|
||
vm.expectRevert("M:M:TRANSFER_FROM_FAILED"); | ||
migrator.migrate(amount_); | ||
|
||
// Approve | ||
oldToken.approve(address(migrator), amount_); | ||
|
||
migrator.migrate(amount_); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), 0); | ||
assertEq(oldToken.balanceOf(address(migrator)), amount_); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), 0); | ||
assertEq(newToken.balanceOf(address(this)), amount_); | ||
assertEq(newToken.balanceOf(address(migrator)), OLD_SUPPLY - amount_); | ||
} | ||
|
||
function test_failWithoutBalance(uint256 amount_) external { | ||
amount_ = constrictToRange(amount_, 1, OLD_SUPPLY); | ||
|
||
oldToken.mint(address(this), amount_ - 1); | ||
|
||
oldToken.approve(address(migrator), amount_); | ||
|
||
vm.expectRevert("M:M:TRANSFER_FROM_FAILED"); | ||
migrator.migrate(amount_); | ||
|
||
// Mint | ||
oldToken.mint(address(this), 1); | ||
|
||
migrator.migrate(amount_); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), 0); | ||
assertEq(oldToken.balanceOf(address(migrator)), amount_); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), 0); | ||
assertEq(newToken.balanceOf(address(this)), amount_); | ||
assertEq(newToken.balanceOf(address(migrator)), OLD_SUPPLY - amount_); | ||
} | ||
|
||
function test_failWithoutNewToken(uint256 amount_) external { | ||
amount_ = constrictToRange(amount_, 1, OLD_SUPPLY); | ||
|
||
// Burn new supply that was added in setUp | ||
newToken.burn(address(migrator), OLD_SUPPLY - amount_ + 1); | ||
|
||
// Mint amount of old token | ||
oldToken.mint(address(this), amount_); | ||
|
||
// Approve | ||
oldToken.approve(address(migrator), amount_); | ||
|
||
vm.expectRevert("M:M:TRANSFER_FAILED"); | ||
migrator.migrate(amount_); | ||
|
||
newToken.mint(address(migrator), 1); | ||
|
||
migrator.migrate(amount_); | ||
|
||
assertEq(oldToken.balanceOf(address(this)), 0); | ||
assertEq(oldToken.balanceOf(address(migrator)), amount_); | ||
assertEq(oldToken.allowance(address(this), address(migrator)), 0); | ||
assertEq(newToken.balanceOf(address(this)), amount_); | ||
assertEq(newToken.balanceOf(address(migrator)), 0); | ||
} | ||
|
||
} |
Submodule contract-test-utils
added at
f00859
Submodule erc20-helper
added at
d674c6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should include all below assertions above this to reflect "before" state