Skip to content

Weiroll Integration

Weiroll allows you to chain commands where the output of one command (e.g., a swap return amount) becomes the input of another.

WHEN TO USE

Use this for Complex Chaining.

  • Example: "Swap ETH -> USDC, then deposit all received USDC into Aave."
  • Example: "Flashloan -> Arbitrage -> Repay."

Use this when you don't know the inputs of Step 2 until Step 1 has executed.

Why Weiroll?

It turns CommissionRoad into a programmable scripting environment. You can build complex "Recipes" (Zap-ins, leveraged positions) without deploying a custom contract for every new strategy.

Implementation

You use the @cowprotocol/sdk-weiroll to plan your execution off-chain.

1. Plan the commands

typescript
import { WeirollPlanner } from "@cowprotocol/sdk-weiroll";
const planner = new WeirollPlanner();

// 1. Swap ETH for USDC (returns amount)
const returnAmount = planner.add(
  uniswapWeiroll.functions["swap(...)"](...)
);

// 2. Lend USDC (uses the return value from step 1!)
planner.add(
  aaveWeiroll.functions["supply(address,uint256,...)"](
    usdcAddress,
    returnAmount, // <--- Magic chaining: Pass the future result as an argument
    ...
  )
);

const { commands, state } = planner.plan();

2. Execute commissionCallVm

typescript
await commissionRoad.write.commissionCallVm([
  commands,
  state,
  nftId,
  ethAddress,
  commission
], { value: totalValue });