Swap USDT to BAT and deposit into Compound then borrow WBTC

My first Instadapp recipe https://gist.github.com/leckylao/fd663486b18a0019529f912634fec304

async function oneInchSwapQuote(fromToken, toToken, dsa){
  const oneInchSwapQuote = await (await fetch(`https://api.1inch.exchange/v1.1/swapQuote?fromTokenSymbol=${fromToken.symbol}&toTokenSymbol=${toToken.symbol}&amount=${fromToken.balance.toString()}&fromAddress=${dsa.instance.address}&slippage=1&disableEstimate=true`)).json();
  console.log(`Estimate exchange: ${oneInchSwapQuote.toTokenAmount / (10 ** toToken.decimals)}`)
  return oneInchSwapQuote;

// Set DSA instance
await dsa.setInstance((await dsa.getAccounts())[0].id);

// Set up tokens
const info = dsa.erc20.tokens.info;
const usdtInfo = info.usdt;
const batInfo = info.bat;
const wbtcInfo = info.wbtc;
const zrxInfo = info.zrx;

// Get balances
const balances = await dsa.balances.getBalances();
const usdtBalance = balances.usdt;
console.log(`USDT balance: ${usdtBalance}`);

// Get 1inch swapQuote USDT to BAT
let fromToken = {...usdtInfo, ...{balance: BigInt(usdtBalance * 10 ** usdtInfo.decimals)}}
let toToken = batInfo;
const usdtBat = await oneInchSwapQuote(fromToken, toToken, dsa)

// Set up Spell
let spells = dsa.Spell();

// USDT to BAT
  connector: "oneInch",
  method: "sellThree",
  args: [toToken.address, fromToken.address, fromToken.balance.toString(), ((usdtBat.toTokenAmount / (10 ** usdtBat.toToken.decimals)) / (usdtBat.fromTokenAmount / (10 ** usdtBat.fromToken.decimals)) * 1e18).toString(), usdtBat.data, 0]

// Deposit BAT
  connector: "compound",
  method: "deposit",
  args: [batInfo.address, -1, 0, 0]

// Get 1inch swapQuote 30% BAT to WBTC to borrow
fromToken = {...batInfo, ...{balance: BigInt(usdtBat.toTokenAmount * 0.3)}}
toToken = wbtcInfo;
const batWbtc = await oneInchSwapQuote(fromToken, toToken, dsa);

// Borrow WBTC
   connector: "compound",
   method: "borrow",
   args: [wbtcInfo.address, batWbtc.toTokenAmount, 0, 0]

let estimateGas = await dsa.estimateCastGas(spells);
console.log(`Estimate Gas: ${estimateGas}`);

let tx = await dsa.cast(spells);

This looks great - curious what use-cases you’re trying to achieve here?

Also, there’s a caveat with BAT swaps - the slippage is relatively higher to swap USDT<>BAT on high volumes. Although, it may work good with small volumes.

This recipe is to farm Comp by using supplying BAT and borrowing WBTC. Then can deposit wbtc to Balancer pool to farm BAL.

looks like having a BAL recipe could do wonders.

1 Like