Skip to content

Instantly share code, notes, and snippets.

@leckylao
Last active Sep 6, 2020
Embed
What would you like to do?
instadapp save
let borrowAmount = 3880;
let borrowAmtInWei = dsa.tokens.fromDecimal(borrowAmount, "usdc"); // borrow flash loan and swap via OasisDEX
console.log("borrowAmtInWei: ", borrowAmtInWei)
let position = await dsa.compound.getPosition();
let wbtcDebtAmount = position.wbtc.borrow;
let wbtcDebtAmtInWei = dsa.tokens.fromDecimal(wbtcDebtAmount, "wbtc");
console.log("wbtcDebtAmount: ", wbtcDebtAmount)
let daiDebtAmount = position.dai.borrow;
let daiDebtAmtInWei = dsa.tokens.fromDecimal(daiDebtAmount, "dai");
console.log("daiDebtAmount: ", daiDebtAmount)
let slippage = 1;
let dai_address = dsa.tokens.info.dai.address
let usdc_address = dsa.tokens.info.usdc.address
let wbtc_address = dsa.tokens.info.wbtc.address
let wbtcBuyAmount = await dsa.kyber.getBuyAmount("WBTC", "USDC", 5, slippage);
// let wbtcSellAmount = await dsa.oasis.getSellAmount("WBTC", "USDC", wbtcDebtAmount, slippage);
let daiSellAmount = await dsa.oasis.getSellAmount("DAI", "USDC", daiDebtAmount, slippage);
console.log("wbtcBuyAmount: ", wbtcBuyAmount)
console.log("daiSellAmount: ", daiSellAmount)
let spells = dsa.Spell();
spells.add({
connector: "instapool",
method: "flashBorrow",
args: [usdc_address, borrowAmtInWei, 0, 0]
});
// spells.add({
// connector: "curve",
// method: "sell",
// args: [usdc_address, dai_address, borrowAmtInWei, buyAmount.unitAmt, 0, 0]
// });
spells.add({
connector: "oasis",
method: "buy",
args: [dai_address, usdc_address, daiDebtAmtInWei, daiSellAmount.unitAmt, 0, 0]
});
spells.add({
connector: "compound",
method: "payback",
args: [dai_address, dsa.maxValue, 0, 0]
});
spells.add({
connector: "compound",
method: "withdraw",
args: [usdc_address, dsa.maxValue, 0, 0]
});
spells.add({
connector: "instapool",
method: "flashPayback",
args: [usdc_address, 0, 0]
});
dsa.cast(spells).then(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment