[Unstoppable] is convertToShares the right function? #54
-
Hello everyone ! There's something I don't understand about the flashLoan function in the Unstoppable problem! Here, Thanks for helping me!! function flashLoan(
IERC3156FlashBorrower receiver,
address _token,
uint256 amount,
bytes calldata data
) external returns (bool) {
if (amount == 0) revert InvalidAmount(0); // fail early
if (address(asset) != _token) revert UnsupportedCurrency(); // enforce ERC3156 requirement
uint256 balanceBefore = totalAssets();
if (convertToShares(totalSupply) != balanceBefore) revert InvalidBalance(); // enforce ERC4626 requirement
uint256 fee = flashFee(_token, amount);
// transfer tokens out + execute callback on receiver
ERC20(_token).safeTransfer(address(receiver), amount);
// callback must return magic value, otherwise assume it failed
if (receiver.onFlashLoan(msg.sender, address(asset), amount, fee, data) != keccak256("IERC3156FlashBorrower.onFlashLoan"))
revert CallbackFailed();
// pull amount + fee from receiver, then pay the fee to the recipient
ERC20(_token).safeTransferFrom(address(receiver), address(this), amount + fee);
ERC20(_token).safeTransfer(feeRecipient, fee);
return true;
}
I've seen this discussion but can't understand it... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @bshyuunn, it's common to find yourself in these situations when you start playing Damn Vulnerable DeFi. The code is full of this kind of cases, where you don't know if what you're seeing is a problem. That's the challenge! Figuring out whether it is a problem or not. And if it is, whether it may open a path to solving the challenge. I know I'm not answering your question directly. I don't want to spoil any answers here. Keep digging! |
Beta Was this translation helpful? Give feedback.
Hi @bshyuunn, it's common to find yourself in these situations when you start playing Damn Vulnerable DeFi.
The code is full of this kind of cases, where you don't know if what you're seeing is a problem. That's the challenge! Figuring out whether it is a problem or not. And if it is, whether it may open a path to solving the challenge.
I know I'm not answering your question directly. I don't want to spoil any answers here. Keep digging!