-
Notifications
You must be signed in to change notification settings - Fork 24
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
Erc4626 extension #465
base: main
Are you sure you want to change the base?
Erc4626 extension #465
Conversation
✅ Deploy Preview for contracts-stylus canceled.
|
I just stared this |
I'll convert this to a draft, so that the team does not invest time reviewing a WIP |
|
||
fn _deposit(&mut self,caller:Address,receiver:Address, assets:U256, shares:U256) -> Result<(), Error> { | ||
// _SafeERC20.safeTransferFrom(_asset, caller, address(this), assets); | ||
self._asset._mint(receiver, shares)?; |
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.
Be careful, you should not be calling _mint
on the asset, but on the contract itself (see Solidity version).
Maybe it would be helpful to take inspiration from the Erc20FlashMint extension PR, as it has a similar design problem as ERC4626, namely that you need to extend ERC20, but still leverage ERC20's functions (which is a problem in Stylus due to lack of proper inheritance).
One way to solve this is to make each ERC4626 function that needs to call base contract's functions (e.g. _mint
) accept an erc20: &mut Erc20
parameter, which acts as a reference to the base/parent contract.
Note that you'll still need _asset: Erc20
as a storage field. But you can make it a generic IErc20
type, so that users of the library are free to define their own Erc20 implementation (as is done in Solidity) (@bidzyyys @qalisander wdyt about this approach?):
#[storage] // this is the new convention we use for defining storage
#[allow(clippy::pub_underscore_fields)]
pub struct ERC4626<T: IErc20 + StorageType> {
pub _asset: T,
pub _underlying_decimals: StorageU8,
}
NOTE: although _asset
and _underlying_decimals
should be private, we're making them public for the purposes of testing. This will be changed at some point.
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.
Thanks you
@0xNeshi SafeERC20.safeTransferFrom(_asset, caller, address(this), assets); In the Solidity implementation, |
See how VestingWallet handles this |
Should I implement something like mulDiv for U256 MATH? function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {
return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
}
|
Should I add the security concerns like docs erc4626 |
Resolves #356
PR Checklist