Overview

Yield Migrator is a React/Vite web application that simplifies the process of moving funds between yield-generating protocols. The application leverages Enso’s Router API to execute complex multi-step transactions in a single operation.

Features

  • Position Discovery: Automatically detects user’s current yield-bearing positions across protocols
  • APY Comparison: Displays potential yield improvements across alternative protocols
  • One-Click Migration: Executes the entire migration process in a single transaction
  • Transaction Preview: Shows expected APY improvement, fees, gas costs, and price impact before execution
  • Cross-Protocol Support: Works with major lending, staking, and liquidity protocols

Technology Stack

  • Frontend: React, Chakra UI
  • Web3: wagmi, viem, RainbowKit
  • DeFi Integration: Enso Finance SDK
  • Build Tools: Vite, TypeScript

Implementation Example

import { useEnsoBundleApi } from '@ensofinance/sdk-react';

function MigratePosition({ currentPosition, targetPosition }) {
  const { createBundleTransaction } = useEnsoBundleApi();
  
  async function handleMigrate() {
    // Create migration bundle with Enso SDK
    const bundleTransaction = await createBundleTransaction({
      actions: [
        // Withdraw from current position
        {
          protocol: currentPosition.protocol,
          action: "withdraw",
          args: {
            tokenIn: currentPosition.address,
            amountIn: currentPosition.balance,
            primaryAddress: currentPosition.contractAddress
          }
        },
        // Deposit into new position
        {
          protocol: targetPosition.protocol,
          action: "deposit",
          args: {
            tokenIn: "0x...", // Underlying token
            tokenOut: targetPosition.address,
            // Use output from previous action
            amountIn: { useOutputOfCallAt: 0 },
            primaryAddress: targetPosition.contractAddress
          }
        }
      ]
    });
    
    // Execute the transaction
    await bundleTransaction.execute();
  }
  
  return (
    <Button onClick={handleMigrate}>
      Migrate Position
    </Button>
  );
}