-
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
feat: add ERC20FlashMint extension #407
base: main
Are you sure you want to change the base?
feat: add ERC20FlashMint extension #407
Conversation
✅ Deploy Preview for contracts-stylus canceled.
|
✅ Deploy Preview for contracts-stylus canceled.
|
This is my initial draft |
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.
Hi @Ifechukwudaniel!
Thanks for the contribution!
The PR overall looks good, let's polish it a bit
pub fn _flash_fee_receiver(&self) -> Address { | ||
Address::ZERO | ||
} | ||
} |
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.
Missing unit tests
pub fn _flash_fee_receiver(&self) -> Address { | ||
Address::ZERO | ||
} | ||
} |
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.
Missing integration tests
Co-authored-by: Nenad <[email protected]>
Co-authored-by: Nenad <[email protected]>
chore: fixed tab
Create erc20-flashloan.adoc
chore: fixes
@0xNeshi what do you think about the new implementation for the extension |
fn flash_fee( | ||
&self, | ||
token: Address, | ||
amount: U256, |
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.
It is not clear which terminology to use here:
The Solidity team had the same problem. They opted for keeping things consistent with ERC20. Our implementation does not; instead it is consistent with the EIP.
Wdyt?
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.
Isn't it in solidity value
is used?
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.
Yea, I mentioned that above:
They opted for keeping things consistent with ERC20
Should we align with the Solidity team or with official EIP, wdyt?
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.
Good job!
I have a few comments and I'm also concerned about solidity files, that we copied from solidity repo.
Can we use a url instead of copying?
fn flash_fee( | ||
&self, | ||
token: Address, | ||
amount: U256, |
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.
Isn't it in solidity value
is used?
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import "../../solidity-contracts/contracts/interfaces/IERC3156FlashBorrower.sol"; |
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't we import them from by url like here
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.
solc
doesn't work with urls. The reason we can do this in other Solidity files is that those files are, to be frank, useless - they're never used anywhere, so no builds are crashed.
I'm not even sure why we have them in the repo tbh 🤔
/** | ||
* @dev Interface of the ERC-20 standard as defined in the ERC. | ||
*/ | ||
interface IERC20 { |
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.
I hope we should avoid to copy sol files from solidity library and just use url references
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.
The problem is having to deploy ERC3156FlashBorrowerMock
contract to be able to run in bench for flash_loan
(see bench); and to be able to implement this contract locally, it seems necessary to have all the dependencies locally as well...
Do you if there's a way to import existing examples/erc20-flash-mint/tests/mock/borrower.rs implementation into benches and reuse it? 🤔 This would make the duplicate here redundant.
address!("dce82b5f92c98f27f116f70491a487effdb6a2aa"); | ||
|
||
#[motsu::test] | ||
#[ignore] |
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.
I see that we can check these test cases with approach similar to Erc721 Metadata. Declare a contract that contains Erc20
and Erc20FlashMint
inside. Similar to what you have in FlashMintExample.
Then test cases should work
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.
Otherwise we cannot use two contract's storages in motsu test case
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.
Since FlashMint relies upon contract::address()
make sense to wait a bit, when motsu can support it
deb20ec
to
d0b5343
Compare
# The `erc20-flash-mint-example` package enables the `reentrant` feature | ||
# on `openzeppelin-stylus`, which combined with `--all-targets` seems to | ||
# cause a linker issue "error: undefined symbol: storage_flush_cache". | ||
# | ||
# This is a known problem with workspace feature unification: | ||
# https://github.com/rust-lang/cargo/issues/4463 | ||
# | ||
# To deal with this, we simply ignore `erc20-flash-mint-example` from the compilation. | ||
run: cargo nextest run --locked --features std --all-targets --workspace --exclude erc20-flash-mint-example |
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.
I think we could omit the whole of examples/* directory for this step, as we're only interested in unit tests, it would speed up the step's execution
NOTE: It is impossible to write any unit tests until it is possible to mock
contract::address()
in tests (see OpenZeppelin/stylus-test-helpers#5).Resolves #355
PR Checklist