multidelegatecall
v1.0.1
Published
[![npm package][npm-img]][npm-url] [![Build Status][build-img]][build-url] [![Downloads][downloads-img]][downloads-url] [![Issues][issues-img]][issues-url] [![Commitizen Friendly][commitizen-img]][commitizen-url] [![Semantic Release][semantic-release-img]
Downloads
13
Maintainers
Readme
multidelegatecall
🛣️ Batch multiple calls to any onchain smart contract in a single transaction, handling any callback, without writing and deploying any contract!
Ethereum's environment evolves fast. So fast that you can't keep up writing and deploying a new contract everytime you want to do something atomically onchain (not mentioning you also have to approve this freshly deployed contract to spend your favorite ERC20/ERC721!).
Welcome multidelegatecall
's Executor
contract:
- Calculate whatever you need to submit your execution
- Chain calls / delegatecalls as needed to execute whatever you want to execute atomically onchain (using
ethers-v6
) - Optionally prepend any ERC20/ERC721 approval via a third-party bundling service (such as Flashbots)
- Submit your execution transaction (or bundle)
- For MEV out there: tip the bundler
Installation
npm install multidelegatecall
yarn add multidelegatecall
Usage
Deployment
Deploy your very own Executor
contract with the owner address you want, once and for all.
Using ethers-v6
Create an ExecutorEncoder
instance and chain any calls wanted. Then, submit the transaction using exec
(or populate the transaction using populateExec
!).
import { ExecutorEncoder } from "multidelegatecall";
const encoder = new ExecutorEncoder(executorAddress, signer);
await encoder
// Flash loan some tokens on Balancer (0% fee).
.balancerFlashLoan(
balancerVaultAddress,
[{ asset: dai, amount: collateralAmount }],
// Chain calls executed inside Balancer's flash loan callback then flush it.
encoder
.erc20Approve(dai, aaveV2PoolAddress, collateralAmount)
.aaveV2Supply(aaveV2PoolAddress, dai, collateralAmount)
.aaveV2Borrow(aaveV2PoolAddress, weth, borrowedAmount, 2)
.unwrapETH(weth, borrowedAmount)
.wrapETH(weth, borrowedAmount)
.erc20Approve(weth, aaveV2PoolAddress, borrowedAmount)
.aaveV2Repay(aaveV2PoolAddress, weth, borrowedAmount, 2)
.aaveV2Withdraw(aaveV2PoolAddress, dai, MaxUint256)
.flush(),
)
// Execute the transaction.
.exec();