multidelegatecall
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

multidelegatecall

npm package Build Status Downloads Issues Commitizen Friendly Semantic Release

🛣️ 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:

  1. Calculate whatever you need to submit your execution
  2. Chain calls / delegatecalls as needed to execute whatever you want to execute atomically onchain (using ethers-v6)
  3. Optionally prepend any ERC20/ERC721 approval via a third-party bundling service (such as Flashbots)
  4. Submit your execution transaction (or bundle)
  5. 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();

Package Sidebar

Install

npm i multidelegatecall

Weekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

64.2 kB

Total Files

25

Last publish

Collaborators

  • rubilmax