-
Notifications
You must be signed in to change notification settings - Fork 32
chore: wrapper improvements #159
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
Open
sogipec
wants to merge
7
commits into
main
Choose a base branch
from
feat-wrappers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2a97fe5
chore: new wrappers
sogipec 250ca64
fix: lint
sogipec 63434e8
fix: change existing wrappers
sogipec 121e475
fix: lint
sogipec 7619ab5
fix: linting tokens
sogipec db91a88
fee recipient tests
sogipec 1c5726b
fix: script deployment
sogipec 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 hidden or 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,72 @@ | ||
| // SPDX-License-Identifier: GPL-3.0 | ||
|
|
||
| pragma solidity ^0.8.17; | ||
|
|
||
| import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
| import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
| import { IERC20, IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | ||
|
|
||
| import { PullTokenWrapperImmutableBase } from "./PullTokenWrapperImmutableBase.sol"; | ||
| import { Errors } from "../../utils/Errors.sol"; | ||
|
|
||
| interface IMezoStaking { | ||
| function createLockFor(uint256 _value, uint256 _lockDuration, address _to) external returns (uint256); | ||
| } | ||
|
|
||
| /// @title MezoWrapper | ||
| /// @notice Non-upgradeable wrapper that creates Mezo locks for claimed tokens | ||
| /// @dev On claim, underlying tokens are approved and locked via `createLockFor` on the Mezo staking contract | ||
| contract MezoWrapper is PullTokenWrapperImmutableBase { | ||
| using SafeERC20 for IERC20; | ||
|
|
||
| /// @notice Mezo staking contract | ||
| address public immutable mezoStaking; | ||
| /// @notice Duration used when creating locks | ||
| uint256 public lockDuration; | ||
|
|
||
| event LockDurationUpdated(uint256 newLockDuration); | ||
|
|
||
| constructor( | ||
| address _token, | ||
| address _distributionCreator, | ||
| address _holder, | ||
| address _mezoStaking, | ||
| uint256 _lockDuration, | ||
| string memory _name, | ||
| string memory _symbol | ||
| ) ERC20(_name, _symbol) PullTokenWrapperImmutableBase(_token, _distributionCreator, _holder) { | ||
| if (_mezoStaking == address(0)) revert Errors.ZeroAddress(); | ||
| mezoStaking = _mezoStaking; | ||
| lockDuration = _lockDuration; | ||
| IERC20(_token).safeApprove(_mezoStaking, type(uint256).max); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MEZO does not implement |
||
| } | ||
|
|
||
| /// @notice Hook called before every transfer: on claim, pulls tokens from holder and creates a Mezo lock; | ||
| /// on fee transfer, pulls tokens from holder and sends them directly to the fee recipient | ||
| function _beforeTokenTransfer(address from, address to, uint256 amount) internal override { | ||
| if (to == feeRecipient) { | ||
| IERC20(token).safeTransferFrom(holder, to, amount); | ||
| } else if (from == distributor) { | ||
| if (lockDuration == 0) { | ||
| IERC20(token).safeTransferFrom(holder, to, amount); | ||
| } else { | ||
| IERC20(token).safeTransferFrom(holder, address(this), amount); | ||
| IMezoStaking(mezoStaking).createLockFor(amount, lockDuration, to); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ================================= ADMIN ================================= | ||
|
|
||
| /// @notice Updates the lock duration used for future claims | ||
| function setLockDuration(uint256 _newLockDuration) external onlyHolderOrGovernor { | ||
| lockDuration = _newLockDuration; | ||
| emit LockDurationUpdated(_newLockDuration); | ||
| } | ||
|
|
||
| /// @notice Resets the token allowance granted to the Mezo staking contract | ||
| function setStakingAllowance(uint256 _allowance) external onlyHolderOrGovernor { | ||
| IERC20(token).safeApprove(mezoStaking, 0); | ||
| IERC20(token).safeApprove(mezoStaking, _allowance); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.17; | ||
|
|
||
| import { console } from "forge-std/console.sol"; | ||
|
|
||
| import { BaseScript } from "./utils/Base.s.sol"; | ||
|
|
||
| import { MezoWrapper } from "../contracts/partners/tokenWrappers/MezoWrapper.sol"; | ||
|
|
||
| contract DeployMezoWrapper is BaseScript { | ||
| // forge script scripts/deployMezoWrapper.s.sol --rpc-url mezo --sender 0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701 --broadcast --verify | ||
| function run() public { | ||
| uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY"); | ||
| vm.startBroadcast(deployerPrivateKey); | ||
|
|
||
| address distributionCreator = 0x8BB4C975Ff3c250e0ceEA271728547f3802B36Fd; | ||
|
|
||
| // ------------------------------------------------------------------------ | ||
| // TO EDIT | ||
| address underlying = 0x7B7c000000000000000000000000000000000001; | ||
| address holder = 0x6b57b0Ef5594a5820fD473353180442764d8601D; | ||
| address mezoStaking = 0xb90fdAd3DFD180458D62Cc6acedc983D78E20122; | ||
| uint256 lockDuration = 0; | ||
| string memory name = "veMEZO (wrapped)"; | ||
| string memory symbol = "veMEZO"; | ||
| // ------------------------------------------------------------------------ | ||
|
|
||
| MezoWrapper wrapper = new MezoWrapper( | ||
| underlying, | ||
| distributionCreator, | ||
| holder, | ||
| mezoStaking, | ||
| lockDuration, | ||
| name, | ||
| symbol | ||
| ); | ||
|
|
||
| console.log("MezoWrapper:", address(wrapper)); | ||
|
|
||
| vm.stopBroadcast(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Can you please clarify who is
_holder? Is it a contract with a pre-approved wrapper or a multisig?