Lending Swap

Swap DAI & USDC Lent on Compound

Step 1

Installation or just use your browser console.

Step 2

Setup Account

Step 3

Trigger the following uniquely designed spells to fulfill this use case. Check this section for generic details around casting spells.

The DSA will cast the spells across the Compound and OasisDEX connectors in the specified sequence.

DAI -> USDC

Benefits
  • When DAI > $1. Arbitrage benefit due to price difference of DAI & USDC.
  • Help make DAI stable.
Recipe
  1. Compound: withdraw DAI
  2. Oasis: Swap DAI for USDC
  3. Compound: deposit USDC
Requirements
  • User must have some DAI deposited.
let withdrawAmount = 20; // 20 DAI
let withdrawAmtInWei = dsa.tokens.fromDecimal(withdrawAmount, "dai"); // borrow flash loan and swap via Oasis

let slippage = 0.1; // 0.1% slippage.
let dai_address = dsa.tokens.info.dai.address
let usdc_address = dsa.tokens.info.usdc.address

let buyAmount = await dsa.oasis.getBuyAmount("USDC", "DAI", withdrawAmount, slippage);

let spells = dsa.Spell();

spells.add({
  connector: "compound",
  method: "withdraw",
  args: [dai_address, withdrawAmtInWei, 0, 0]
});

spells.add({
  connector: "oasis",
  method: "sell",
  args: [usdc_address, dai_address, withdrawAmtInWei, buyAmount.unitAmt, 0, "423"] // setting USDC amount with id 423
});

spells.add({
  connector: "compound",
  method: "deposit",
  args: [usdc_address, 0, "423", 0] // get Payback amount with id 423
});

dsa.cast(spells).then(console.log)

USDC -> DAI

Benefits
  • When DAI < $1. Arbitrage benefit due to price difference of DAI & USDC.
  • Help make DAI stable.
Recipe
  1. Compound: withdraw USDC
  2. Oasis: Swap USDC for DAI
  3. Compound: deposit DAI
Requirements
  • User must have some USDC deposited.
let withdrawAmount = 20; // 20 USDC
let withdrawAmtInWei = dsa.tokens.fromDecimal(withdrawAmount, "usdc"); // borrow flash loan and swap via Oasis

let slippage = 0.2; // 0.2% slippage.
let dai_address = dsa.tokens.info.dai.address
let usdc_address = dsa.tokens.info.usdc.address

let buyAmount = await dsa.oasis.getBuyAmount("DAI", "USDC", withdrawAmount, slippage);

let spells = dsa.Spell();

spells.add({
  connector: "compound",
  method: "withdraw",
  args: [usdc_address, withdrawAmount, 0, 0]
});

spells.add({
  connector: "oasis",
  method: "sell",
  args: [dai_address, usdc_address, withdrawAmtInWei, buyAmount.unitAmt, 0, "924"] // setting DAI amount with id 924
});

spells.add({
  connector: "compound",
  method: "deposit",
  args: [dai_address, 0, "924", 0] // get Payback amount with id 924
});

dsa.cast(spells).then(console.log)

If you still can't find something you're looking for or have any questions, ask them at our developers community on Telegram, Discord or simply send an Email.

Our team is excited about assisting you to build an application using Instadapp Developer Platform. Your questions and feedback help us make a better development environment for future developers.

Best way to stay connected with our progress.