Skip to content
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

Specify type(uint256).max behaviors #394

Merged
merged 7 commits into from
Dec 22, 2023
5 changes: 2 additions & 3 deletions src/ERC20WrapperBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ abstract contract ERC20WrapperBundler is BaseBundler {
/// @dev Initiator must have previously transferred their tokens to the bundler.
/// @dev Assumes that `wrapper` implements the `ERC20Wrapper` interface.
/// @param wrapper The address of the ERC20 wrapper contract.
/// @param amount The amount of underlying tokens to deposit. Pass `type(uint256).max` to deposit the bundler's
/// balance.
/// @param amount The amount of underlying tokens to deposit. Capped at the bundler's balance.
function erc20WrapperDepositFor(address wrapper, uint256 amount) external payable protected {
ERC20 underlying = ERC20(address(ERC20Wrapper(wrapper).underlying()));

Expand All @@ -43,7 +42,7 @@ abstract contract ERC20WrapperBundler is BaseBundler {
/// @dev Assumes that `wrapper` implements the `ERC20Wrapper` interface.
/// @param wrapper The address of the ERC20 wrapper contract.
/// @param account The address receiving the underlying tokens.
/// @param amount The amount of wrapped tokens to burn. Pass `type(uint256).max` to burn the bundler's balance.
/// @param amount The amount of wrapped tokens to burn. Capped at the bundler's balance.
function erc20WrapperWithdrawTo(address wrapper, address account, uint256 amount) external payable protected {
require(account != address(0), ErrorsLib.ZERO_ADDRESS);

Expand Down
6 changes: 3 additions & 3 deletions src/ERC4626Bundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract contract ERC4626Bundler is BaseBundler {
/// @dev Initiator must have previously transferred their assets to the bundler.
/// @dev Assumes the given `vault` implements EIP-4626.
/// @param vault The address of the vault.
/// @param assets The amount of assets to deposit. Pass `type(uint256).max` to deposit the bundler's assets.
/// @param assets The amount of assets to deposit. Capped at the bundler's assets.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @param assets The amount of assets to deposit. Capped at the bundler's assets.
/// @param assets The amount of assets to deposit. Capped at the bundler's balance.

Copy link
Contributor

@QGarchery QGarchery Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we use balance for the ERC20.balanceOf elsewhere, but here I think it's useful to make the distinction between assets and shares (since shares are returned by ERC4626.balanceOf below)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it's inconsistent with the other contracts right ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is inconsistent but still it is clearer in the context of ERC4626

/// @param minShares The minimum amount of shares to mint in exchange for `assets`. This parameter is proportionally
/// scaled down in case there are fewer assets than `assets` on the bundler.
/// @param receiver The address to which shares will be minted.
Expand Down Expand Up @@ -95,9 +95,9 @@ abstract contract ERC4626Bundler is BaseBundler {
/// @notice Redeems the given amount of `shares` from the given ERC4626 `vault`, transferring assets to `receiver`.
/// @dev Assumes the given `vault` implements EIP-4626.
/// @param vault The address of the vault.
/// @param shares The amount of shares to burn. Pass `type(uint256).max` to redeem the bundler's shares.
/// @param shares The amount of shares to redeem. Capped at the owner's shares.
/// @param minAssets The minimum amount of assets to withdraw in exchange for `shares`. This parameter is
/// proportionally scaled down in case there are fewer shares than `shares` on the bundler.
/// proportionally scaled down in case the owner holds fewer shares than `shares`.
/// @param receiver The address that will receive the withdrawn assets.
/// @param owner The address on behalf of which the shares are redeemed. Can only be the bundler or the initiator.
/// If `owner` is the initiator, they must have previously approved the bundler to spend their vault shares.
Expand Down
3 changes: 1 addition & 2 deletions src/Permit2Bundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ abstract contract Permit2Bundler is BaseBundler {

/// @notice Transfers the given `amount` of `asset` from the initiator to the bundler via Permit2.
/// @param asset The address of the ERC20 token to transfer.
/// @param amount The amount of `asset` to transfer from the initiator. Pass `type(uint256).max` to transfer the
/// initiator's balance.
/// @param amount The amount of `asset` to transfer from the initiator. Capped at the initiator's balance.
function transferFrom2(address asset, uint256 amount) external payable protected {
address _initiator = initiator();
amount = Math.min(amount, ERC20(asset).balanceOf(_initiator));
Expand Down
6 changes: 3 additions & 3 deletions src/StEthBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract contract StEthBundler is BaseBundler {
/// @notice Stakes the given `amount` of ETH via Lido, using the `referral` id.
/// @notice stETH tokens are received by the bundler and should be used afterwards.
/// @dev Initiator must have previously transferred their ETH to the bundler.
/// @param amount The amount of ETH to stake. Pass `type(uint256).max` to stake all.
/// @param amount The amount of ETH to stake. Capped at the bundler's ETH balance.
/// @param minShares The minimum amount of shares to mint in exchange for `amount`. This parameter is
/// proportionally scaled down in case there is fewer ETH than `amount` on the bundler.
/// @param referral The address of the referral regarding the Lido Rewards-Share Program.
Expand All @@ -58,7 +58,7 @@ abstract contract StEthBundler is BaseBundler {
/// @notice Wraps the given `amount` of stETH to wstETH.
/// @notice wstETH tokens are received by the bundler and should be used afterwards.
/// @dev Initiator must have previously transferred their stETH tokens to the bundler.
/// @param amount The amount of stEth to wrap. Pass `type(uint256).max` to wrap all.
/// @param amount The amount of stEth to wrap. Capped at the bundler's stETH balance.
function wrapStEth(uint256 amount) external payable protected {
amount = Math.min(amount, ERC20(ST_ETH).balanceOf(address(this)));

Expand All @@ -70,7 +70,7 @@ abstract contract StEthBundler is BaseBundler {
/// @notice Unwraps the given `amount` of wstETH to stETH.
/// @notice stETH tokens are received by the bundler and should be used afterwards.
/// @dev Initiator must have previously transferred their wstETH tokens to the bundler.
/// @param amount The amount of wstEth to unwrap. Pass `type(uint256).max` to unwrap all.
/// @param amount The amount of wstEth to unwrap. Capped at the bundler's wstETH balance.
function unwrapStEth(uint256 amount) external payable protected {
amount = Math.min(amount, ERC20(WST_ETH).balanceOf(address(this)));

Expand Down
8 changes: 3 additions & 5 deletions src/TransferBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ abstract contract TransferBundler is BaseBundler {
/// bundler to `recipient`.
/// @dev If the minimum happens to be zero, the transfer is silently skipped.
/// @param recipient The address that will receive the native tokens.
/// @param amount The amount of native tokens to transfer. Pass `type(uint256).max` to transfer
/// the initiator's balance.
/// @param amount The amount of native tokens to transfer. Capped at the bundler's balance.
function nativeTransfer(address recipient, uint256 amount) external payable protected {
require(recipient != address(0), ErrorsLib.ZERO_ADDRESS);
require(recipient != address(this), ErrorsLib.BUNDLER_ADDRESS);
Expand All @@ -39,7 +38,7 @@ abstract contract TransferBundler is BaseBundler {
/// @dev If the minimum happens to be zero, the transfer is silently skipped.
/// @param asset The address of the ERC20 token to transfer.
/// @param recipient The address that will receive the tokens.
/// @param amount The amount of `asset` to transfer. Pass `type(uint256).max` to transfer the bundler's balance.
/// @param amount The amount of `asset` to transfer. Capped at the bundler's balance.
function erc20Transfer(address asset, address recipient, uint256 amount) external payable protected {
require(recipient != address(0), ErrorsLib.ZERO_ADDRESS);
require(recipient != address(this), ErrorsLib.BUNDLER_ADDRESS);
Expand All @@ -54,8 +53,7 @@ abstract contract TransferBundler is BaseBundler {
/// @notice Transfers the given `amount` of `asset` from sender to this contract via ERC20 transferFrom.
/// @notice User must have given sufficient allowance to the Bundler to spend their tokens.
/// @param asset The address of the ERC20 token to transfer.
/// @param amount The amount of `asset` to transfer from the initiator. Pass `type(uint256).max` to transfer the
/// initiator's balance.
/// @param amount The amount of `asset` to transfer from the initiator. Capped at the initiator's balance.
function erc20TransferFrom(address asset, uint256 amount) external payable protected {
address _initiator = initiator();
amount = Math.min(amount, ERC20(asset).balanceOf(_initiator));
Expand Down
4 changes: 2 additions & 2 deletions src/WNativeBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract contract WNativeBundler is BaseBundler {
/// @notice Wraps the given `amount` of the native token to wNative.
/// @notice Wrapped native tokens are received by the bundler and should be used afterwards.
/// @dev Initiator must have previously transferred their native tokens to the bundler.
/// @param amount The amount of native token to wrap. Pass `type(uint256).max` to wrap all.
/// @param amount The amount of native token to wrap. Capped at the bundler's native token balance.
function wrapNative(uint256 amount) external payable protected {
amount = Math.min(amount, address(this).balance);

Expand All @@ -55,7 +55,7 @@ abstract contract WNativeBundler is BaseBundler {
/// @notice Unwraps the given `amount` of wNative to the native token.
/// @notice Unwrapped native tokens are received by the bundler and should be used afterwards.
/// @dev Initiator must have previously transferred their wrapped native tokens to the bundler.
/// @param amount The amount of wrapped native token to unwrap. Pass `type(uint256).max` to unwrap all.
/// @param amount The amount of wrapped native token to unwrap. Capped at the bundler's wNative balance.
function unwrapNative(uint256 amount) external payable protected {
amount = Math.min(amount, ERC20(WRAPPED_NATIVE).balanceOf(address(this)));

Expand Down
2 changes: 1 addition & 1 deletion src/migration/AaveV2MigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract AaveV2MigrationBundler is MigrationBundler, StEthBundler {
/// @notice Repays `amount` of `asset` on AaveV2, on behalf of the initiator.
/// @dev Initiator must have previously transferred their assets to the bundler.
/// @param asset The address of the token to repay.
/// @param amount The amount of `asset` to repay. Pass `type(uint256).max` to repay the maximum repayable debt
/// @param amount The amount of `asset` to repay. Capped at the maximum repayable debt
/// (mininimum of the bundler's balance and the initiator's debt).
/// @param interestRateMode The interest rate mode of the position.
function aaveV2Repay(address asset, uint256 amount, uint256 interestRateMode) external payable protected {
Expand Down
2 changes: 1 addition & 1 deletion src/migration/AaveV3MigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract AaveV3MigrationBundler is MigrationBundler {
/// @notice Repays `amount` of `asset` on AaveV3, on behalf of the initiator.
/// @dev Initiator must have previously transferred their assets to the bundler.
/// @param asset The address of the token to repay.
/// @param amount The amount of `asset` to repay. Pass `type(uint256).max` to repay the maximum repayable debt
/// @param amount The amount of `asset` to repay. Capped at the maximum repayable debt
/// (mininimum of the bundler's balance and the initiator's debt).
/// @param interestRateMode The interest rate mode of the position.
function aaveV3Repay(address asset, uint256 amount, uint256 interestRateMode) external payable protected {
Expand Down
2 changes: 1 addition & 1 deletion src/migration/AaveV3OptimizerMigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract AaveV3OptimizerMigrationBundler is MigrationBundler {
/// @notice Repays `amount` of `underlying` on the AaveV3 Optimizer, on behalf of the initiator.
/// @dev Initiator must have previously transferred their assets to the bundler.
/// @param underlying The address of the underlying asset to repay.
/// @param amount The amount of `underlying` to repay. Pass `type(uint256).max` to repay the maximum repayable debt
/// @param amount The amount of `underlying` to repay. Capped at the maximum repayable debt
/// (mininimum of the bundler's balance and the initiator's debt).
function aaveV3OptimizerRepay(address underlying, uint256 amount) external payable protected {
amount = Math.min(amount, ERC20(underlying).balanceOf(address(this)));
Expand Down
4 changes: 2 additions & 2 deletions src/migration/CompoundV2MigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ contract CompoundV2MigrationBundler is WNativeBundler, MigrationBundler {

/// @notice Repays `amount` of `cToken`'s underlying asset, on behalf of the initiator.
/// @dev Initiator must have previously transferred their assets to the bundler.
/// @param cToken The address of the cToken contract
/// @param amount The amount of `cToken` to repay. Pass `type(uint256).max` to repay the maximum repayable debt
/// @param cToken The address of the cToken contract.
/// @param amount The amount of `cToken` to repay. Capped at the maximum repayable debt
/// (mininimum of the bundler's balance and the initiator's debt).
function compoundV2Repay(address cToken, uint256 amount) external payable protected {
address _initiator = initiator();
Expand Down
2 changes: 1 addition & 1 deletion src/migration/CompoundV3MigrationBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract CompoundV3MigrationBundler is MigrationBundler {
/// @dev Initiator must have previously transferred their assets to the bundler.
/// @dev Assumes the given `instance` is a CompoundV3 instance.
/// @param instance The address of the CompoundV3 instance to call.
/// @param amount The amount of `asset` to repay. Pass `type(uint256).max` to repay the maximum repayable debt
/// @param amount The amount of `asset` to repay. Capped at the maximum repayable debt
/// (mininimum of the bundler's balance and the initiator's debt).
function compoundV3Repay(address instance, uint256 amount) external payable protected {
address _initiator = initiator();
Expand Down
Loading