diff --git a/README.md b/README.md index 8fab449b..2133c8f6 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,82 @@ User-end bundlers are provided in each chain-specific folder, instanciating all ## Getting Started +### Installation + +```bash +npm install @morpho-org/morpho-blue-bundlers +``` + +```bash +yarn add @morpho-org/morpho-blue-bundlers +``` + +### Usage + +```typescript +import { Signature } from "ethers"; + +import { BundlerAction } from "@morpho-org/morpho-blue-bundlers"; + +const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; + +const permit2Config = { + domain: { + name: "Permit2", + chainId: "0x1", + verifyingContract: permit2Address, + }, + types: { + PermitSingle: [ + { + name: "details", + type: "PermitDetails", + }, + { + name: "spender", + type: "address", + }, + { + name: "sigDeadline", + type: "uint256", + }, + ], + PermitDetails: [ + { + name: "token", + type: "address", + }, + { + name: "amount", + type: "uint160", + }, + { + name: "expiration", + type: "uint48", + }, + { + name: "nonce", + type: "uint48", + }, + ], + }, +}; + +await bundler + .connect(supplier) + .multicall([ + BundlerAction.approve2( + approve2, + Signature.from(await supplier.signTypedData(permit2Config.domain, permit2Config.types, approve2)), + false, + ), + BundlerAction.transferFrom2(collateralAddress, assets), + BundlerAction.erc4626Deposit(erc4626Address, assets, 0, supplier.address), + ]); +``` + +## Development + Install dependencies with `yarn`. Run tests with `yarn test:forge --chain ` (chainid can be 1 or 8453). diff --git a/package.json b/package.json index ed3d55e5..eeccd00a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@morpho-org/morpho-blue-bundlers", "description": "Morpho Blue Bundlers", "license": "GPL-2.0-or-later", - "version": "1.1.2", + "version": "1.2.0", "repository": { "type": "git", "url": "git+https://github.com/morpho-labs/morpho-blue-bundlers.git" diff --git a/pkg/BundlerAction.ts b/pkg/BundlerAction.ts index 4956ffda..678abc9f 100644 --- a/pkg/BundlerAction.ts +++ b/pkg/BundlerAction.ts @@ -22,48 +22,75 @@ import { AuthorizationStruct, MarketParamsStruct, WithdrawalStruct } from "../ty export type BundlerCall = string; -export class BundlerAction { - private static TRANSFER_BUNDLER_IFC = TransferBundler__factory.createInterface(); - private static PERMIT_BUNDLER_IFC = PermitBundler__factory.createInterface(); - private static PERMIT2_BUNDLER_IFC = Permit2Bundler__factory.createInterface(); - private static ERC20_WRAPPER_BUNDLER_IFC = ERC20WrapperBundler__factory.createInterface(); - private static ERC4626_BUNDLER_IFC = ERC4626Bundler__factory.createInterface(); - private static MORPHO_BUNDLER_IFC = MorphoBundler__factory.createInterface(); - private static URD_BUNDLER_IFC = UrdBundler__factory.createInterface(); - private static WNATIVE_BUNDLER_IFC = WNativeBundler__factory.createInterface(); - private static ST_ETH_BUNDLER_IFC = StEthBundler__factory.createInterface(); - private static ETHEREUM_PERMIT_BUNDLER_IFC = EthereumPermitBundler__factory.createInterface(); - - private static AAVE_V2_BUNDLER_IFC = AaveV2MigrationBundlerV2__factory.createInterface(); - private static AAVE_V3_BUNDLER_IFC = AaveV3MigrationBundlerV2__factory.createInterface(); - private static AAVE_V3_OPTIMIZER_BUNDLER_IFC = AaveV3OptimizerMigrationBundlerV2__factory.createInterface(); - private static COMPOUND_V2_BUNDLER_IFC = CompoundV2MigrationBundlerV2__factory.createInterface(); - private static COMPOUND_V3_BUNDLER_IFC = CompoundV3MigrationBundlerV2__factory.createInterface(); - +const TRANSFER_BUNDLER_IFC = TransferBundler__factory.createInterface(); +const PERMIT_BUNDLER_IFC = PermitBundler__factory.createInterface(); +const PERMIT2_BUNDLER_IFC = Permit2Bundler__factory.createInterface(); +const ERC20_WRAPPER_BUNDLER_IFC = ERC20WrapperBundler__factory.createInterface(); +const ERC4626_BUNDLER_IFC = ERC4626Bundler__factory.createInterface(); +const MORPHO_BUNDLER_IFC = MorphoBundler__factory.createInterface(); +const URD_BUNDLER_IFC = UrdBundler__factory.createInterface(); +const WNATIVE_BUNDLER_IFC = WNativeBundler__factory.createInterface(); +const ST_ETH_BUNDLER_IFC = StEthBundler__factory.createInterface(); +const ETHEREUM_PERMIT_BUNDLER_IFC = EthereumPermitBundler__factory.createInterface(); + +const AAVE_V2_BUNDLER_IFC = AaveV2MigrationBundlerV2__factory.createInterface(); +const AAVE_V3_BUNDLER_IFC = AaveV3MigrationBundlerV2__factory.createInterface(); +const AAVE_V3_OPTIMIZER_BUNDLER_IFC = AaveV3OptimizerMigrationBundlerV2__factory.createInterface(); +const COMPOUND_V2_BUNDLER_IFC = CompoundV2MigrationBundlerV2__factory.createInterface(); +const COMPOUND_V3_BUNDLER_IFC = CompoundV3MigrationBundlerV2__factory.createInterface(); + +/** + * Namespace to easily encode calls to the Bundler contract, using ethers. + */ +export namespace BundlerAction { /* ERC20 */ - static nativeTransfer(recipient: string, amount: BigNumberish): BundlerCall { - return BundlerAction.TRANSFER_BUNDLER_IFC.encodeFunctionData("nativeTransfer", [recipient, amount]); + /** + * Encodes a call to the Bundler to transfer native tokens (ETH on ethereum, MATIC on polygon, etc). + * @param recipient The address to send native tokens to. + * @param amount The amount of native tokens to send (in wei). + */ + export function nativeTransfer(recipient: string, amount: BigNumberish): BundlerCall { + return TRANSFER_BUNDLER_IFC.encodeFunctionData("nativeTransfer", [recipient, amount]); } - static erc20Transfer(asset: string, recipient: string, amount: BigNumberish): BundlerCall { - return BundlerAction.TRANSFER_BUNDLER_IFC.encodeFunctionData("erc20Transfer", [asset, recipient, amount]); + /** + * Encodes a call to the Bundler to transfer ERC20 tokens. + * @param asset The address of the ERC20 token to transfer. + * @param recipient The address to send tokens to. + * @param amount The amount of tokens to send. + */ + export function erc20Transfer(asset: string, recipient: string, amount: BigNumberish): BundlerCall { + return TRANSFER_BUNDLER_IFC.encodeFunctionData("erc20Transfer", [asset, recipient, amount]); } - static erc20TransferFrom(asset: string, amount: BigNumberish): BundlerCall { - return BundlerAction.TRANSFER_BUNDLER_IFC.encodeFunctionData("erc20TransferFrom", [asset, amount]); + /** + * Encodes a call to the Bundler to transfer ERC20 tokens from the sender to the Bundler. + * @param asset The address of the ERC20 token to transfer. + * @param amount The amount of tokens to send. + */ + export function erc20TransferFrom(asset: string, amount: BigNumberish): BundlerCall { + return TRANSFER_BUNDLER_IFC.encodeFunctionData("erc20TransferFrom", [asset, amount]); } /* Permit */ - static permit( + /** + * Encodes a call to the Bundler to permit an ERC20 token. + * @param asset The address of the ERC20 token to permit. + * @param amount The amount of tokens to permit. + * @param deadline The timestamp until which the signature is valid. + * @param signature The Ethers signature to permit the tokens. + * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert. + */ + export function permit( asset: string, amount: BigNumberish, deadline: BigNumberish, signature: Signature, skipRevert: boolean, ): BundlerCall { - return BundlerAction.PERMIT_BUNDLER_IFC.encodeFunctionData("permit", [ + return PERMIT_BUNDLER_IFC.encodeFunctionData("permit", [ asset, amount, deadline, @@ -74,14 +101,22 @@ export class BundlerAction { ]); } - static permitDai( + /** + * Encodes a call to the Bundler to permit DAI. + * @param nonce The permit nonce used. + * @param expiry The timestamp until which the signature is valid. + * @param allowed The amount of DAI to permit. + * @param signature The Ethers signature to permit the tokens. + * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert. + */ + export function permitDai( nonce: BigNumberish, expiry: BigNumberish, allowed: boolean, signature: Signature, skipRevert: boolean, ): BundlerCall { - return BundlerAction.ETHEREUM_PERMIT_BUNDLER_IFC.encodeFunctionData("permitDai", [ + return ETHEREUM_PERMIT_BUNDLER_IFC.encodeFunctionData("permitDai", [ nonce, expiry, allowed, @@ -94,98 +129,148 @@ export class BundlerAction { /* Permit2 */ - static approve2( + /** + * Encodes a call to the Bundler to permit ERC20 tokens via Permit2. + * @param permitSingle The permit details to submit to Permit2. + * @param signature The Ethers signature to permit the tokens. + * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert. + */ + export function approve2( permitSingle: IAllowanceTransfer.PermitSingleStruct, signature: Signature, skipRevert: boolean, ): BundlerCall { - return BundlerAction.PERMIT2_BUNDLER_IFC.encodeFunctionData("approve2", [ - permitSingle, - signature.serialized, - skipRevert, - ]); + return PERMIT2_BUNDLER_IFC.encodeFunctionData("approve2", [permitSingle, signature.serialized, skipRevert]); } - static transferFrom2(asset: string, amount: BigNumberish): BundlerCall { - return BundlerAction.PERMIT2_BUNDLER_IFC.encodeFunctionData("transferFrom2", [asset, amount]); + /** + * Encodes a call to the Bundler to transfer ERC20 tokens via Permit2 from the sender to the Bundler. + * @param asset The address of the ERC20 token to transfer. + * @param amount The amount of tokens to send. + */ + export function transferFrom2(asset: string, amount: BigNumberish): BundlerCall { + return PERMIT2_BUNDLER_IFC.encodeFunctionData("transferFrom2", [asset, amount]); } /* ERC20 Wrapper */ - static erc20WrapperDepositFor(wrapper: string, amount: BigNumberish): BundlerCall { - return BundlerAction.ERC20_WRAPPER_BUNDLER_IFC.encodeFunctionData("erc20WrapperDepositFor", [wrapper, amount]); + /** + * Encodes a call to the Bundler to wrap ERC20 tokens via the provided ERC20Wrapper. + * @param wrapper The address of the ERC20 wrapper token. + * @param amount The amount of tokens to send. + */ + export function erc20WrapperDepositFor(wrapper: string, amount: BigNumberish): BundlerCall { + return ERC20_WRAPPER_BUNDLER_IFC.encodeFunctionData("erc20WrapperDepositFor", [wrapper, amount]); } - static erc20WrapperWithdrawTo(wrapper: string, account: string, amount: BigNumberish): BundlerCall { - return BundlerAction.ERC20_WRAPPER_BUNDLER_IFC.encodeFunctionData("erc20WrapperWithdrawTo", [ - wrapper, - account, - amount, - ]); + /** + * Encodes a call to the Bundler to unwrap ERC20 tokens from the provided ERC20Wrapper. + * @param wrapper The address of the ERC20 wrapper token. + * @param account The address to send the underlying ERC20 tokens. + * @param amount The amount of tokens to send. + */ + export function erc20WrapperWithdrawTo(wrapper: string, account: string, amount: BigNumberish): BundlerCall { + return ERC20_WRAPPER_BUNDLER_IFC.encodeFunctionData("erc20WrapperWithdrawTo", [wrapper, account, amount]); } /* ERC4626 */ - static erc4626Mint(erc4626: string, shares: BigNumberish, maxAssets: BigNumberish, receiver: string): BundlerCall { - return BundlerAction.ERC4626_BUNDLER_IFC.encodeFunctionData("erc4626Mint", [erc4626, shares, maxAssets, receiver]); + /** + * Encodes a call to the Bundler to mint shares of the provided ERC4626 vault. + * @param erc4626 The address of the ERC4626 vault. + * @param shares The amount of shares to mint. + * @param maxAssets The maximum amount of assets to deposit (protects the sender from unexpected slippage). + * @param receiver The address to send the shares to. + */ + export function erc4626Mint( + erc4626: string, + shares: BigNumberish, + maxAssets: BigNumberish, + receiver: string, + ): BundlerCall { + return ERC4626_BUNDLER_IFC.encodeFunctionData("erc4626Mint", [erc4626, shares, maxAssets, receiver]); } - static erc4626Deposit(erc4626: string, assets: BigNumberish, minShares: BigNumberish, receiver: string): BundlerCall { - return BundlerAction.ERC4626_BUNDLER_IFC.encodeFunctionData("erc4626Deposit", [ - erc4626, - assets, - minShares, - receiver, - ]); + /** + * Encodes a call to the Bundler to deposit assets into the provided ERC4626 vault. + * @param erc4626 The address of the ERC4626 vault. + * @param assets The amount of assets to deposit. + * @param minShares The minimum amount of shares to mint (protects the sender from unexpected slippage). + * @param receiver The address to send the shares to. + */ + export function erc4626Deposit( + erc4626: string, + assets: BigNumberish, + minShares: BigNumberish, + receiver: string, + ): BundlerCall { + return ERC4626_BUNDLER_IFC.encodeFunctionData("erc4626Deposit", [erc4626, assets, minShares, receiver]); } - static erc4626Withdraw( + /** + * Encodes a call to the Bundler to withdraw assets from the provided ERC4626 vault. + * @param erc4626 The address of the ERC4626 vault. + * @param assets The amount of assets to withdraw. + * @param maxShares The maximum amount of shares to redeem (protects the sender from unexpected slippage). + * @param receiver The address to send the assets to. + */ + export function erc4626Withdraw( erc4626: string, assets: BigNumberish, maxShares: BigNumberish, receiver: string, owner: string, ): BundlerCall { - return BundlerAction.ERC4626_BUNDLER_IFC.encodeFunctionData("erc4626Withdraw", [ - erc4626, - assets, - maxShares, - receiver, - owner, - ]); + return ERC4626_BUNDLER_IFC.encodeFunctionData("erc4626Withdraw", [erc4626, assets, maxShares, receiver, owner]); } - static erc4626Redeem( + /** + * Encodes a call to the Bundler to redeem shares from the provided ERC4626 vault. + * @param erc4626 The address of the ERC4626 vault. + * @param shares The amount of shares to redeem. + * @param minAssets The minimum amount of assets to withdraw (protects the sender from unexpected slippage). + * @param receiver The address to send the assets to. + */ + export function erc4626Redeem( erc4626: string, shares: BigNumberish, minAssets: BigNumberish, receiver: string, owner: string, ): BundlerCall { - return BundlerAction.ERC4626_BUNDLER_IFC.encodeFunctionData("erc4626Redeem", [ - erc4626, - shares, - minAssets, - receiver, - owner, - ]); + return ERC4626_BUNDLER_IFC.encodeFunctionData("erc4626Redeem", [erc4626, shares, minAssets, receiver, owner]); } /* Morpho */ - static morphoSetAuthorizationWithSig( + /** + * Encodes a call to the Bundler to authorize an account on Morpho Blue. + * @param authorization The authorization details to submit to Morpho Blue. + * @param signature The Ethers signature to authorize the account. + * @param skipRevert Whether to allow the authorization call to revert without making the whole multicall revert. + */ + export function morphoSetAuthorizationWithSig( authorization: AuthorizationStruct, signature: Signature, skipRevert: boolean, ): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("morphoSetAuthorizationWithSig", [ + return MORPHO_BUNDLER_IFC.encodeFunctionData("morphoSetAuthorizationWithSig", [ authorization, { v: signature.v, r: signature.r, s: signature.s }, skipRevert, ]); } - static morphoSupply( + /** + * Encodes a call to the Bundler to supply to a Morpho Blue market. + * @param market The market params to supply to. + * @param assets The amount of assets to supply. + * @param shares The amount of supply shares to mint. + * @param slippageAmount The maximum (resp. minimum) amount of assets (resp. supply shares) to supply (resp. mint) (protects the sender from unexpected slippage). + * @param onBehalf The address to supply on behalf of. + * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback. + */ + export function morphoSupply( market: MarketParamsStruct, assets: BigNumberish, shares: BigNumberish, @@ -193,47 +278,65 @@ export class BundlerAction { onBehalf: string, callbackCalls: BundlerCall[], ): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("morphoSupply", [ + return MORPHO_BUNDLER_IFC.encodeFunctionData("morphoSupply", [ market, assets, shares, slippageAmount, onBehalf, - BundlerAction.MORPHO_BUNDLER_IFC.getAbiCoder().encode(["bytes[]"], [callbackCalls]), + MORPHO_BUNDLER_IFC.getAbiCoder().encode(["bytes[]"], [callbackCalls]), ]); } - static morphoSupplyCollateral( + /** + * Encodes a call to the Bundler to supply collateral to a Morpho Blue market. + * @param market The market params to supply to. + * @param assets The amount of assets to supply. + * @param onBehalf The address to supply on behalf of. + * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupplyCollateral` callback. + */ + export function morphoSupplyCollateral( market: MarketParamsStruct, assets: BigNumberish, onBehalf: string, callbackCalls: BundlerCall[], ): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("morphoSupplyCollateral", [ + return MORPHO_BUNDLER_IFC.encodeFunctionData("morphoSupplyCollateral", [ market, assets, onBehalf, - BundlerAction.MORPHO_BUNDLER_IFC.getAbiCoder().encode(["bytes[]"], [callbackCalls]), + MORPHO_BUNDLER_IFC.getAbiCoder().encode(["bytes[]"], [callbackCalls]), ]); } - static morphoBorrow( + /** + * Encodes a call to the Bundler to borrow from a Morpho Blue market. + * @param market The market params to borrow from. + * @param assets The amount of assets to borrow. + * @param shares The amount of borrow shares to mint. + * @param slippageAmount The minimum (resp. maximum) amount of assets (resp. borrow shares) to borrow (resp. mint) (protects the sender from unexpected slippage). + * @param receiver The address to send borrowed tokens to. + */ + export function morphoBorrow( market: MarketParamsStruct, assets: BigNumberish, shares: BigNumberish, slippageAmount: BigNumberish, receiver: string, ): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("morphoBorrow", [ - market, - assets, - shares, - slippageAmount, - receiver, - ]); - } - - static morphoRepay( + return MORPHO_BUNDLER_IFC.encodeFunctionData("morphoBorrow", [market, assets, shares, slippageAmount, receiver]); + } + + /** + * Encodes a call to the Bundler to repay to a Morpho Blue market. + * @param market The market params to repay to. + * @param assets The amount of assets to repay. + * @param shares The amount of borrow shares to redeem. + * @param slippageAmount The maximum (resp. minimum) amount of assets (resp. borrow shares) to repay (resp. redeem) (protects the sender from unexpected slippage). + * @param onBehalf The address to repay on behalf of. + * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback. + */ + export function morphoRepay( market: MarketParamsStruct, assets: BigNumberish, shares: BigNumberish, @@ -241,52 +344,78 @@ export class BundlerAction { onBehalf: string, callbackCalls: BundlerCall[], ): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("morphoRepay", [ + return MORPHO_BUNDLER_IFC.encodeFunctionData("morphoRepay", [ market, assets, shares, slippageAmount, onBehalf, - BundlerAction.MORPHO_BUNDLER_IFC.getAbiCoder().encode(["bytes[]"], [callbackCalls]), + MORPHO_BUNDLER_IFC.getAbiCoder().encode(["bytes[]"], [callbackCalls]), ]); } - static morphoWithdraw( + /** + * Encodes a call to the Bundler to withdraw from a Morpho Blue market. + * @param market The market params to withdraw from. + * @param assets The amount of assets to withdraw. + * @param shares The amount of supply shares to redeem. + * @param slippageAmount The minimum (resp. maximum) amount of assets (resp. supply shares) to withdraw (resp. redeem) (protects the sender from unexpected slippage). + * @param receiver The address to send withdrawn tokens to. + */ + export function morphoWithdraw( market: MarketParamsStruct, assets: BigNumberish, shares: BigNumberish, slippageAmount: BigNumberish, receiver: string, ): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("morphoWithdraw", [ - market, - assets, - shares, - slippageAmount, - receiver, - ]); + return MORPHO_BUNDLER_IFC.encodeFunctionData("morphoWithdraw", [market, assets, shares, slippageAmount, receiver]); } - static morphoWithdrawCollateral(market: MarketParamsStruct, assets: BigNumberish, receiver: string): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("morphoWithdrawCollateral", [market, assets, receiver]); + /** + * Encodes a call to the Bundler to withdraw collateral from a Morpho Blue market. + * @param market The market params to withdraw from. + * @param assets The amount of assets to withdraw. + * @param receiver The address to send withdrawn tokens to. + */ + export function morphoWithdrawCollateral( + market: MarketParamsStruct, + assets: BigNumberish, + receiver: string, + ): BundlerCall { + return MORPHO_BUNDLER_IFC.encodeFunctionData("morphoWithdrawCollateral", [market, assets, receiver]); } - static morphoFlashLoan(asset: string, amount: BigNumberish, callbackCalls: BundlerCall[]): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("morphoFlashLoan", [ + /** + * Encodes a call to the Bundler to flash loan from Morpho Blue. + * @param asset The address of the ERC20 token to flash loan. + * @param amount The amount of tokens to flash loan. + * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoFlashLoan` callback. + */ + export function morphoFlashLoan(asset: string, amount: BigNumberish, callbackCalls: BundlerCall[]): BundlerCall { + return MORPHO_BUNDLER_IFC.encodeFunctionData("morphoFlashLoan", [ asset, amount, - BundlerAction.MORPHO_BUNDLER_IFC.getAbiCoder().encode(["bytes[]"], [callbackCalls]), + MORPHO_BUNDLER_IFC.getAbiCoder().encode(["bytes[]"], [callbackCalls]), ]); } - static metaMorphoReallocateTo( + /** + * Encodes a call to the Bundler to trigger a public reallocation on the PublicAllocator. + * @param publicAllocator The address of the PublicAllocator to use. + * @param vault The vault to reallocate. + * @param value The value of the call. Can be used to pay the vault reallocation fees. + * @param withdrawals The array of withdrawals to perform, before supplying everything to the supply market. + * @param supplyMarketParams The market params to reallocate to. + */ + export function metaMorphoReallocateTo( publicAllocator: string, vault: string, value: BigNumberish, withdrawals: WithdrawalStruct[], supplyMarketParams: MarketParamsStruct, ): BundlerCall { - return BundlerAction.MORPHO_BUNDLER_IFC.encodeFunctionData("reallocateTo", [ + return MORPHO_BUNDLER_IFC.encodeFunctionData("reallocateTo", [ publicAllocator, vault, value, @@ -297,7 +426,16 @@ export class BundlerAction { /* Universal Rewards Distributor */ - static urdClaim( + /** + * Encodes a call to the Bundler to claim rewards from the Universal Rewards Distributor. + * @param distributor The address of the distributor to claim rewards from. + * @param account The address to claim rewards for. + * @param reward The address of the reward token to claim. + * @param amount The amount of rewards to claim. + * @param proof The Merkle proof to claim the rewards. + * @param skipRevert Whether to allow the claim to revert without making the whole multicall revert. + */ + export function urdClaim( distributor: string, account: string, reward: string, @@ -305,91 +443,162 @@ export class BundlerAction { proof: BytesLike[], skipRevert: boolean, ): BundlerCall { - return BundlerAction.URD_BUNDLER_IFC.encodeFunctionData("urdClaim", [ - distributor, - account, - reward, - amount, - proof, - skipRevert, - ]); + return URD_BUNDLER_IFC.encodeFunctionData("urdClaim", [distributor, account, reward, amount, proof, skipRevert]); } /* Wrapped Native */ - static wrapNative(amount: BigNumberish): BundlerCall { - return BundlerAction.WNATIVE_BUNDLER_IFC.encodeFunctionData("wrapNative", [amount]); + /** + * Encodes a call to the Bundler to wrap native tokens (ETH to WETH on ethereum, MATIC to WMATIC on polygon, etc). + * @param amount The amount of native tokens to wrap (in wei). + */ + export function wrapNative(amount: BigNumberish): BundlerCall { + return WNATIVE_BUNDLER_IFC.encodeFunctionData("wrapNative", [amount]); } - static unwrapNative(amount: BigNumberish): BundlerCall { - return BundlerAction.WNATIVE_BUNDLER_IFC.encodeFunctionData("unwrapNative", [amount]); + /** + * Encodes a call to the Bundler to unwrap native tokens (WETH to ETH on ethereum, WMATIC to MATIC on polygon, etc). + * @param amount The amount of native tokens to unwrap (in wei). + */ + export function unwrapNative(amount: BigNumberish): BundlerCall { + return WNATIVE_BUNDLER_IFC.encodeFunctionData("unwrapNative", [amount]); } /* stETH */ - static stakeEth(amount: BigNumberish, minShares: BigNumberish, referral: string): BundlerCall { - return BundlerAction.ST_ETH_BUNDLER_IFC.encodeFunctionData("stakeEth", [amount, minShares, referral]); + /** + * Encodes a call to the Bundler to stake native tokens using Lido (ETH to stETH on ethereum). + * @param amount The amount of native tokens to stake (in wei). + * @param minShares The minimum amount of shares to mint (protects the sender from unexpected slippage). + * @param referral The referral address to use. + */ + export function stakeEth(amount: BigNumberish, minShares: BigNumberish, referral: string): BundlerCall { + return ST_ETH_BUNDLER_IFC.encodeFunctionData("stakeEth", [amount, minShares, referral]); } /* Wrapped stETH */ - static wrapStEth(amount: BigNumberish): BundlerCall { - return BundlerAction.ST_ETH_BUNDLER_IFC.encodeFunctionData("wrapStEth", [amount]); + /** + * Encodes a call to the Bundler to wrap stETH (stETH to wstETH on ethereum). + * @param amount The amount of stETH to wrap (in wei). + */ + export function wrapStEth(amount: BigNumberish): BundlerCall { + return ST_ETH_BUNDLER_IFC.encodeFunctionData("wrapStEth", [amount]); } - static unwrapStEth(amount: BigNumberish): BundlerCall { - return BundlerAction.ST_ETH_BUNDLER_IFC.encodeFunctionData("unwrapStEth", [amount]); + /** + * Encodes a call to the Bundler to unwrap wstETH (wstETH to stETH on ethereum). + * @param amount The amount of wstETH to unwrap (in wei). + */ + export function unwrapStEth(amount: BigNumberish): BundlerCall { + return ST_ETH_BUNDLER_IFC.encodeFunctionData("unwrapStEth", [amount]); } /* AaveV2 */ - static aaveV2Repay(asset: string, amount: BigNumberish, rateMode: BigNumberish): BundlerCall { - return BundlerAction.AAVE_V2_BUNDLER_IFC.encodeFunctionData("aaveV2Repay", [asset, amount, rateMode]); + /** + * ! Only available on AaveV2MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to repay a debt on AaveV2. + * @param asset The debt asset to repay. + * @param amount The amount of debt to repay. + * @param rateMode The interest rate mode used by the debt to repay. + */ + export function aaveV2Repay(asset: string, amount: BigNumberish, rateMode: BigNumberish): BundlerCall { + return AAVE_V2_BUNDLER_IFC.encodeFunctionData("aaveV2Repay", [asset, amount, rateMode]); } - static aaveV2Withdraw(asset: string, amount: BigNumberish): BundlerCall { - return BundlerAction.AAVE_V2_BUNDLER_IFC.encodeFunctionData("aaveV2Withdraw", [asset, amount]); + /** + * ! Only available on AaveV2MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to withdrawn from AaveV2. + * @param asset The asset to withdraw. + * @param amount The amount of asset to withdraw. + */ + export function aaveV2Withdraw(asset: string, amount: BigNumberish): BundlerCall { + return AAVE_V2_BUNDLER_IFC.encodeFunctionData("aaveV2Withdraw", [asset, amount]); } /* AaveV3 */ - static aaveV3Repay(asset: string, amount: BigNumberish, rateMode: BigNumberish): BundlerCall { - return BundlerAction.AAVE_V3_BUNDLER_IFC.encodeFunctionData("aaveV3Repay", [asset, amount, rateMode]); + /** + * ! Only available on AaveV3MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to repay a debt on AaveV3. + * @param asset The debt asset to repay. + * @param amount The amount of debt to repay. + * @param rateMode The interest rate mode used by the debt to repay. + */ + export function aaveV3Repay(asset: string, amount: BigNumberish, rateMode: BigNumberish): BundlerCall { + return AAVE_V3_BUNDLER_IFC.encodeFunctionData("aaveV3Repay", [asset, amount, rateMode]); } - static aaveV3Withdraw(asset: string, amount: BigNumberish): BundlerCall { - return BundlerAction.AAVE_V3_BUNDLER_IFC.encodeFunctionData("aaveV3Withdraw", [asset, amount]); + /** + * ! Only available on AaveV3MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to withdrawn from AaveV3. + * @param asset The asset to withdraw. + * @param amount The amount of asset to withdraw. + */ + export function aaveV3Withdraw(asset: string, amount: BigNumberish): BundlerCall { + return AAVE_V3_BUNDLER_IFC.encodeFunctionData("aaveV3Withdraw", [asset, amount]); } /* AaveV3 Optimizer */ - static aaveV3OptimizerRepay(underlying: string, amount: BigNumberish): BundlerCall { - return BundlerAction.AAVE_V3_OPTIMIZER_BUNDLER_IFC.encodeFunctionData("aaveV3OptimizerRepay", [underlying, amount]); - } - - static aaveV3OptimizerWithdraw(underlying: string, amount: BigNumberish, maxIterations: BigNumberish): BundlerCall { - return BundlerAction.AAVE_V3_OPTIMIZER_BUNDLER_IFC.encodeFunctionData("aaveV3OptimizerWithdraw", [ + /** + * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to repay a debt on Morpho's AaveV3Optimizer. + * @param underlying The underlying debt asset to repay. + * @param amount The amount of debt to repay. + * @param maxIterations The maximum amount of iterations to use for the repayment. + */ + export function aaveV3OptimizerRepay(underlying: string, amount: BigNumberish): BundlerCall { + return AAVE_V3_OPTIMIZER_BUNDLER_IFC.encodeFunctionData("aaveV3OptimizerRepay", [underlying, amount]); + } + + /** + * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to withdraw from Morpho's AaveV3Optimizer. + * @param underlying The underlying asset to withdraw. + * @param amount The amount to withdraw. + * @param maxIterations The maximum amount of iterations to use for the withdrawal. + */ + export function aaveV3OptimizerWithdraw( + underlying: string, + amount: BigNumberish, + maxIterations: BigNumberish, + ): BundlerCall { + return AAVE_V3_OPTIMIZER_BUNDLER_IFC.encodeFunctionData("aaveV3OptimizerWithdraw", [ underlying, amount, maxIterations, ]); } - static aaveV3OptimizerWithdrawCollateral(underlying: string, amount: BigNumberish): BundlerCall { - return BundlerAction.AAVE_V3_OPTIMIZER_BUNDLER_IFC.encodeFunctionData("aaveV3OptimizerWithdrawCollateral", [ - underlying, - amount, - ]); - } - - static aaveV3OptimizerApproveManagerWithSig( + /** + * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to withdraw collateral from Morpho's AaveV3Optimizer. + * @param underlying The underlying asset to withdraw. + * @param amount The amount to withdraw. + */ + export function aaveV3OptimizerWithdrawCollateral(underlying: string, amount: BigNumberish): BundlerCall { + return AAVE_V3_OPTIMIZER_BUNDLER_IFC.encodeFunctionData("aaveV3OptimizerWithdrawCollateral", [underlying, amount]); + } + + /** + * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to approve the Bundler as the sender's manager on Morpho's AaveV3Optimizer. + * @param isApproved Whether the manager is approved. + * @param nonce The nonce used to sign. + * @param deadline The timestamp until which the signature is valid. + * @param signature The Ethers signature to submit. + * @param skipRevert Whether to allow the signature to revert without making the whole multicall revert. + */ + export function aaveV3OptimizerApproveManagerWithSig( isApproved: boolean, nonce: BigNumberish, deadline: BigNumberish, signature: Signature, skipRevert: boolean, ): BundlerCall { - return BundlerAction.AAVE_V3_OPTIMIZER_BUNDLER_IFC.encodeFunctionData("aaveV3OptimizerApproveManagerWithSig", [ + return AAVE_V3_OPTIMIZER_BUNDLER_IFC.encodeFunctionData("aaveV3OptimizerApproveManagerWithSig", [ isApproved, nonce, deadline, @@ -400,29 +609,59 @@ export class BundlerAction { /* CompoundV2 */ - static compoundV2Repay(cToken: string, amount: BigNumberish): BundlerCall { - return BundlerAction.COMPOUND_V2_BUNDLER_IFC.encodeFunctionData("compoundV2Repay", [cToken, amount]); + /** + * ! Only available on CompoundV2MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to repay a debt on CompoundV2. + * @param cToken The cToken on which to repay the debt. + * @param amount The amount of debt to repay. + */ + export function compoundV2Repay(cToken: string, amount: BigNumberish): BundlerCall { + return COMPOUND_V2_BUNDLER_IFC.encodeFunctionData("compoundV2Repay", [cToken, amount]); } - static compoundV2Redeem(cToken: string, amount: BigNumberish): BundlerCall { - return BundlerAction.COMPOUND_V2_BUNDLER_IFC.encodeFunctionData("compoundV2Redeem", [cToken, amount]); + /** + * ! Only available on CompoundV2MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to withdraw collateral from CompoundV2. + * @param cToken The cToken on which to withdraw. + * @param amount The amount to withdraw. + */ + export function compoundV2Redeem(cToken: string, amount: BigNumberish): BundlerCall { + return COMPOUND_V2_BUNDLER_IFC.encodeFunctionData("compoundV2Redeem", [cToken, amount]); } /* CompoundV3 */ - static compoundV3Repay(instance: string, amount: BigNumberish): BundlerCall { - return BundlerAction.COMPOUND_V3_BUNDLER_IFC.encodeFunctionData("compoundV3Repay", [instance, amount]); - } - - static compoundV3WithdrawFrom(instance: string, asset: string, amount: BigNumberish): BundlerCall { - return BundlerAction.COMPOUND_V3_BUNDLER_IFC.encodeFunctionData("compoundV3WithdrawFrom", [ - instance, - asset, - amount, - ]); - } - - static compoundV3AllowBySig( + /** + * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to repay a debt on CompoundV3. + * @param instance The CompoundV3 instance on which to repay the debt. + * @param amount The amount of debt to repay. + */ + export function compoundV3Repay(instance: string, amount: BigNumberish): BundlerCall { + return COMPOUND_V3_BUNDLER_IFC.encodeFunctionData("compoundV3Repay", [instance, amount]); + } + + /** + * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to withdraw collateral from CompoundV3. + * @param instance The CompoundV3 instance on which to withdraw. + * @param amount The amount to withdraw. + */ + export function compoundV3WithdrawFrom(instance: string, asset: string, amount: BigNumberish): BundlerCall { + return COMPOUND_V3_BUNDLER_IFC.encodeFunctionData("compoundV3WithdrawFrom", [instance, asset, amount]); + } + + /** + * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!). + * Encodes a call to the Bundler to allow the Bundler to act on the sender's position on CompoundV3. + * @param instance The CompoundV3 instance on which to submit the signature. + * @param isAllowed Whether the manager is allowed. + * @param nonce The nonce used to sign. + * @param expiry The timestamp until which the signature is valid. + * @param signature The Ethers signature to submit. + * @param skipRevert Whether to allow the signature to revert without making the whole multicall revert. + */ + export function compoundV3AllowBySig( instance: string, isAllowed: boolean, nonce: BigNumberish, @@ -430,7 +669,7 @@ export class BundlerAction { signature: Signature, skipRevert: boolean, ): BundlerCall { - return BundlerAction.COMPOUND_V3_BUNDLER_IFC.encodeFunctionData("compoundV3AllowBySig", [ + return COMPOUND_V3_BUNDLER_IFC.encodeFunctionData("compoundV3AllowBySig", [ instance, isAllowed, nonce,