-
Notifications
You must be signed in to change notification settings - Fork 481
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
Add wrap, unwrap functionality #369
base: main
Are you sure you want to change the base?
Conversation
src/base/NativeWrapper.sol
Outdated
} | ||
|
||
function wrap(uint256 _amount) external payable { | ||
uint256 amount = _amount == ActionConstants.CONTRACT_BALANCE ? address(this).balance : _amount; |
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.
might be worth added 2 extra checks to each of these functions
- if
amount > balance
revert - so that theres a nice custom error? - only deposit (or withdraw) if
amount != 0
. As someone might pass inCONTRACT_BALANCE
and the current balance is 0 so then deposit/withdraw shouldnt be called
So maybe like
if (amount == ActionConstants.CONTRACT_BALANCE) {
amount = address(this).balance;
} else if (amount > address(this).balance) {
revert InsufficientETH();
}
if (amount > 0) WETH9.deposit{value: amount}();
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 call out!
/// @notice Calculates the sanitized amount before wrapping/unwrapping. | ||
/// @param inputCurrency The currency, either native or wrapped native, that the contract holds | ||
/// @param amount The amount to wrap or unwrap. Can be CONTRACT_BALANCE or OPEN_DELTA or a specific amount | ||
/// @param outputCurrency The currency after the wrap/unwrap that the user may owe a balance in on the poolManager |
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.
/// @param outputCurrency The currency after the wrap/unwrap that the user may owe a balance in on the poolManager | |
/// @param outputCurrency The currency after the wrap/unwrap |
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.
They also could be wrapping/unwrapping before sweeping to themselves etc. I feel like theres a few valid use-cases so shouldnt single one out
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.
yeah but outputCurrency is only used to get the OPEN_DELTA balance on the contract
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 didn't change this but lmk i can change if you still think so after reading this comment above^
@@ -241,6 +241,13 @@ library CalldataDecoder { | |||
} | |||
} | |||
|
|||
/// @dev equivalent to: abi.decode(params, (uint256)) in calldata | |||
function decodeUint256(bytes calldata params) internal pure returns (uint256 amount) { |
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.
add fuzz test
@@ -308,4 +329,114 @@ contract PositionManagerModifyLiquiditiesTest is Test, PosmTestSetup, LiquidityF | |||
); | |||
lpm.modifyLiquidities(calls, _deadline); | |||
} | |||
|
|||
function test_weth_wrap_increaseLiquidity() public { |
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.
would love to see a test case that uses OPEN_DELTA to test that flow works too
Related Issue
Which issue does this pull request resolve?
Description of changes