mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Migrating tests to typescript
This commit is contained in:
parent
f5ac85692e
commit
ffbdafbbc2
|
@ -98,7 +98,7 @@ const ERC20_TOKEN_ABI = [
|
|||
"function approve(address spender, uint256 amount) external returns (bool)",
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
NOTIONAL_CONTRACT_ADDRESS,
|
||||
NOTIONAL_CONTRACT_ABI,
|
||||
WETH_TOKEN_ADDRESS,
|
||||
|
@ -106,4 +106,4 @@ module.exports = {
|
|||
CDAI_TOKEN_ADDRESS,
|
||||
CETH_TOKEN_ADDRESS,
|
||||
ERC20_TOKEN_ABI
|
||||
};
|
||||
};
|
|
@ -1,6 +1,14 @@
|
|||
const encodeSpells = require("../../scripts/encodeSpells.js")
|
||||
import { BigNumber } from "ethers";
|
||||
import { encodeSpells } from "../../../scripts/tests/encodeSpells"
|
||||
|
||||
const depositCollteral = async (dsa, authority, referrer, currencyId, amount, underlying) => {
|
||||
const depositCollteral = async (
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
currencyId: number,
|
||||
amount: BigNumber,
|
||||
underlying: boolean
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
connector: "NOTIONAL-TEST-A",
|
||||
|
@ -13,7 +21,14 @@ const depositCollteral = async (dsa, authority, referrer, currencyId, amount, un
|
|||
await tx.wait()
|
||||
};
|
||||
|
||||
const depositAndMintNToken = async (dsa, authority, referrer, currencyId, amount, underlying) => {
|
||||
const depositAndMintNToken = async (
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
currencyId: number,
|
||||
amount: BigNumber,
|
||||
underlying: boolean
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
connector: "NOTIONAL-TEST-A",
|
||||
|
@ -26,20 +41,36 @@ const depositAndMintNToken = async (dsa, authority, referrer, currencyId, amount
|
|||
await tx.wait()
|
||||
}
|
||||
|
||||
const depositAndLend = async (dsa, authority, referrer, currencyId, underlying, amount, market, fcash, minRate) => {
|
||||
const depositAndLend = async (
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
currencyId: number,
|
||||
underlying: boolean,
|
||||
amount: BigNumber,
|
||||
market: number,
|
||||
fcash: BigNumber
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
connector: "NOTIONAL-TEST-A",
|
||||
method: "depositAndLend",
|
||||
args: [currencyId, amount, underlying, market, fcash, minRate, 0]
|
||||
args: [currencyId, amount, underlying, market, fcash, 0, 0]
|
||||
}
|
||||
];
|
||||
|
||||
const tx = await dsa.connect(authority).cast(...encodeSpells(spells), referrer.address);
|
||||
await tx.wait()
|
||||
await tx.wait()
|
||||
};
|
||||
|
||||
const withdrawCollateral = async (dsa, authority, referrer, currencyId, amount, underlying) => {
|
||||
const withdrawCollateral = async (
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
currencyId: number,
|
||||
amount: BigNumber,
|
||||
underlying: boolean
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
connector: "NOTIONAL-TEST-A",
|
||||
|
@ -52,7 +83,14 @@ const withdrawCollateral = async (dsa, authority, referrer, currencyId, amount,
|
|||
await tx.wait()
|
||||
};
|
||||
|
||||
const redeemNTokenRaw = async (dsa, authority, referrer, currencyId, sellTokenAssets, tokensToRedeem) => {
|
||||
const redeemNTokenRaw = async (
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
currencyId: number,
|
||||
sellTokenAssets: boolean,
|
||||
tokensToRedeem: BigNumber
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
connector: "NOTIONAL-TEST-A",
|
||||
|
@ -65,7 +103,15 @@ const redeemNTokenRaw = async (dsa, authority, referrer, currencyId, sellTokenAs
|
|||
await tx.wait()
|
||||
};
|
||||
|
||||
const redeemNTokenAndWithdraw = async (dsa, authority, referrer, currencyId, tokensToRedeem, amountToWithdraw, redeemToUnderlying) => {
|
||||
const redeemNTokenAndWithdraw = async (
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
currencyId: number,
|
||||
tokensToRedeem: BigNumber,
|
||||
amountToWithdraw: BigNumber,
|
||||
redeemToUnderlying: boolean
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
connector: "NOTIONAL-TEST-A",
|
||||
|
@ -78,12 +124,20 @@ const redeemNTokenAndWithdraw = async (dsa, authority, referrer, currencyId, tok
|
|||
await tx.wait()
|
||||
};
|
||||
|
||||
const redeemNTokenAndDeleverage = async (dsa, authority, referrer, currencyId, tokensToRedeem, marketIndex, fCashAmount, minLendRate) => {
|
||||
const redeemNTokenAndDeleverage = async (
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
currencyId: number,
|
||||
tokensToRedeem: BigNumber,
|
||||
marketIndex: number,
|
||||
fCashAmount: BigNumber
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
connector: "NOTIONAL-TEST-A",
|
||||
method: "redeemNTokenAndDeleverage",
|
||||
args: [currencyId, tokensToRedeem, marketIndex, fCashAmount, minLendRate, 0]
|
||||
args: [currencyId, tokensToRedeem, marketIndex, fCashAmount, 0, 0]
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -92,17 +146,16 @@ const redeemNTokenAndDeleverage = async (dsa, authority, referrer, currencyId, t
|
|||
};
|
||||
|
||||
const depositCollateralBorrowAndWithdraw = async (
|
||||
dsa,
|
||||
authority,
|
||||
referrer,
|
||||
depositCurrencyId,
|
||||
depositUnderlying,
|
||||
depositAmount,
|
||||
borrowCurrencyId,
|
||||
marketIndex,
|
||||
fCashAmount,
|
||||
maxBorrowRate,
|
||||
redeedmUnderlying
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
depositCurrencyId: number,
|
||||
depositType: number,
|
||||
depositAmount: BigNumber,
|
||||
borrowCurrencyId: number,
|
||||
marketIndex: number,
|
||||
fCashAmount: BigNumber,
|
||||
redeedmUnderlying: boolean
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
|
@ -110,12 +163,12 @@ const depositCollateralBorrowAndWithdraw = async (
|
|||
method: "depositCollateralBorrowAndWithdraw",
|
||||
args: [
|
||||
depositCurrencyId,
|
||||
depositUnderlying,
|
||||
depositType,
|
||||
depositAmount,
|
||||
borrowCurrencyId,
|
||||
marketIndex,
|
||||
fCashAmount,
|
||||
maxBorrowRate,
|
||||
0,
|
||||
redeedmUnderlying,
|
||||
0,
|
||||
0
|
||||
|
@ -127,12 +180,19 @@ const depositCollateralBorrowAndWithdraw = async (
|
|||
await tx.wait()
|
||||
};
|
||||
|
||||
const withdrawLend = async (dsa, authority, referrer, currencyId, marketIndex, fCashAmount, maxBorrowRate) => {
|
||||
const withdrawLend = async (
|
||||
dsa: any,
|
||||
authority: any,
|
||||
referrer: any,
|
||||
currencyId: number,
|
||||
marketIndex: number,
|
||||
fCashAmount: BigNumber
|
||||
) => {
|
||||
const spells = [
|
||||
{
|
||||
connector: "NOTIONAL-TEST-A",
|
||||
method: "withdrawLend",
|
||||
args: [currencyId, marketIndex, fCashAmount, maxBorrowRate, 0]
|
||||
args: [currencyId, marketIndex, fCashAmount, 0, 0]
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -140,7 +200,7 @@ const withdrawLend = async (dsa, authority, referrer, currencyId, marketIndex, f
|
|||
await tx.wait()
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
depositCollteral,
|
||||
depositAndMintNToken,
|
||||
depositAndLend,
|
|
@ -1,23 +1,18 @@
|
|||
const { expect } = require("chai");
|
||||
const hre = require("hardhat");
|
||||
const { web3, deployments, waffle, ethers } = hre;
|
||||
import { expect } from "chai";
|
||||
import hre from "hardhat";
|
||||
const { waffle, ethers } = hre;
|
||||
const { provider, deployContract } = waffle
|
||||
|
||||
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js")
|
||||
const buildDSAv2 = require("../../scripts/buildDSAv2")
|
||||
const encodeSpells = require("../../scripts/encodeSpells.js")
|
||||
const getMasterSigner = require("../../scripts/getMasterSigner")
|
||||
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
|
||||
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"
|
||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"
|
||||
import { addresses } from "../../../scripts/tests/mainnet/addresses";
|
||||
import { abis } from "../../../scripts/constant/abis";
|
||||
import contracts from "./notional.contracts";
|
||||
import helpers from "./notional.helpers";
|
||||
|
||||
const addresses = require("../../scripts/constant/addresses");
|
||||
const abis = require("../../scripts/constant/abis");
|
||||
const constants = require("../../scripts/constant/constant");
|
||||
const tokens = require("../../scripts/constant/tokens");
|
||||
|
||||
const contracts = require("./notional.contracts");
|
||||
const helpers = require("./notional.helpers");
|
||||
|
||||
const connectV2NotionalArtifacts = require("../../artifacts/contracts/mainnet/connectors/notional/main.sol/ConnectV2Notional.json");
|
||||
const { BigNumber } = require("ethers");
|
||||
import { ConnectV2Notional__factory } from "../../../typechain";
|
||||
import { BigNumber } from "ethers";
|
||||
|
||||
const DAI_WHALE = "0x6dfaf865a93d3b0b5cfd1b4db192d1505676645b";
|
||||
const CDAI_WHALE = "0x33b890d6574172e93e58528cd99123a88c0756e9";
|
||||
|
@ -35,17 +30,17 @@ const MARKET_3M = 1;
|
|||
describe("Notional", function () {
|
||||
const connectorName = "NOTIONAL-TEST-A"
|
||||
|
||||
let dsaWallet0
|
||||
let masterSigner;
|
||||
let instaConnectorsV2;
|
||||
let connector;
|
||||
let notional;
|
||||
let daiToken;
|
||||
let cdaiToken;
|
||||
let cethToken;
|
||||
let daiWhale;
|
||||
let cdaiWhale;
|
||||
let cethWhale;
|
||||
let dsaWallet0: any;
|
||||
let masterSigner: any;
|
||||
let instaConnectorsV2: any;
|
||||
let connector: any;
|
||||
let notional: any;
|
||||
let daiToken: any;
|
||||
let cdaiToken: any;
|
||||
let cethToken: any;
|
||||
let daiWhale: any;
|
||||
let cdaiWhale: any;
|
||||
let cethWhale: any;
|
||||
|
||||
const wallets = provider.getWallets()
|
||||
const [wallet0, wallet1, wallet2, wallet3] = wallets
|
||||
|
@ -55,6 +50,7 @@ describe("Notional", function () {
|
|||
params: [
|
||||
{
|
||||
forking: {
|
||||
//@ts-ignore
|
||||
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
|
||||
blockNumber: 13798624,
|
||||
},
|
||||
|
@ -78,11 +74,11 @@ describe("Notional", function () {
|
|||
params: [CETH_WHALE]
|
||||
})
|
||||
|
||||
masterSigner = await getMasterSigner(wallet3)
|
||||
masterSigner = await getMasterSigner()
|
||||
instaConnectorsV2 = await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2);
|
||||
connector = await deployAndEnableConnector({
|
||||
connectorName,
|
||||
contractArtifact: connectV2NotionalArtifacts,
|
||||
contractArtifact: ConnectV2Notional__factory,
|
||||
signer: masterSigner,
|
||||
connectors: instaConnectorsV2
|
||||
})
|
||||
|
@ -109,11 +105,6 @@ describe("Notional", function () {
|
|||
ethers.provider
|
||||
);
|
||||
cethWhale = await ethers.getSigner(CETH_WHALE);
|
||||
weth = new ethers.Contract(
|
||||
contracts.WETH_TOKEN_ADDRESS,
|
||||
contracts.ERC20_TOKEN_ABI,
|
||||
ethers.provider
|
||||
);
|
||||
dsaWallet0 = await buildDSAv2(wallet0.address)
|
||||
});
|
||||
|
||||
|
@ -181,7 +172,8 @@ describe("Notional", function () {
|
|||
value: ethers.utils.parseEther("10")
|
||||
});
|
||||
const depositAmount = ethers.utils.parseEther("10");
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, ETH_ID, true, depositAmount, MARKET_3M, 9e8, 0);
|
||||
const fcash = ethers.utils.parseUnits("9", 8);
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, ETH_ID, true, depositAmount, MARKET_3M, fcash);
|
||||
const portfolio = await notional.getAccountPortfolio(dsaWallet0.address);
|
||||
expect(portfolio.length, "expect 1 lending position").to.be.equal(1);
|
||||
expect(portfolio[0][3], "expect 9 fETH").to.be.gte(ethers.utils.parseUnits("900000000", 0));
|
||||
|
@ -190,7 +182,8 @@ describe("Notional", function () {
|
|||
it("test_deposit_ETH_asset_and_lend", async function () {
|
||||
const depositAmount = ethers.utils.parseUnits("1", 8);
|
||||
await cethToken.connect(cethWhale).transfer(dsaWallet0.address, depositAmount);
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, ETH_ID, false, depositAmount, MARKET_3M, 0.01e8, 0);
|
||||
const fcash = ethers.utils.parseUnits("0.01", 8);
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, ETH_ID, false, depositAmount, MARKET_3M, fcash);
|
||||
const portfolio = await notional.getAccountPortfolio(dsaWallet0.address);
|
||||
expect(portfolio.length, "expect 1 lending position").to.be.equal(1);
|
||||
expect(portfolio[0][3], "expect 0.01 fETH").to.be.gte(ethers.utils.parseUnits("1000000", 0));
|
||||
|
@ -199,7 +192,8 @@ describe("Notional", function () {
|
|||
it("test_deposit_DAI_underlying_and_lend", async function () {
|
||||
const depositAmount = ethers.utils.parseUnits("1000", 18);
|
||||
await daiToken.connect(daiWhale).transfer(dsaWallet0.address, depositAmount);
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, DAI_ID, true, depositAmount, MARKET_3M, 100e8, 0);
|
||||
const fcash = ethers.utils.parseUnits("100", 8);
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, DAI_ID, true, depositAmount, MARKET_3M, fcash);
|
||||
const portfolio = await notional.getAccountPortfolio(dsaWallet0.address);
|
||||
expect(portfolio.length, "expect 1 lending position").to.be.equal(1);
|
||||
expect(portfolio[0][3], "expect 100 fDAI").to.be.gte(ethers.utils.parseUnits("10000000000", 0));
|
||||
|
@ -208,7 +202,8 @@ describe("Notional", function () {
|
|||
it("test_deposit_DAI_asset_and_lend", async function () {
|
||||
const depositAmount = ethers.utils.parseUnits("1000", 8);
|
||||
await cdaiToken.connect(cdaiWhale).transfer(dsaWallet0.address, depositAmount);
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, DAI_ID, false, depositAmount, MARKET_3M, 10e8, 0);
|
||||
const fcash = ethers.utils.parseUnits("10", 8);
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, DAI_ID, false, depositAmount, MARKET_3M, fcash);
|
||||
const portfolio = await notional.getAccountPortfolio(dsaWallet0.address);
|
||||
expect(portfolio.length, "expect 1 lending position").to.be.equal(1);
|
||||
expect(portfolio[0][3], "expect 10 fDAI").to.be.gte(ethers.utils.parseUnits("1000000000", 0));
|
||||
|
@ -220,11 +215,12 @@ describe("Notional", function () {
|
|||
value: ethers.utils.parseEther("10")
|
||||
});
|
||||
const depositAmount = ethers.utils.parseEther("10");
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, ETH_ID, true, depositAmount, MARKET_3M, 9e8, 0);
|
||||
const fcash = ethers.utils.parseUnits("9", 8);
|
||||
await helpers.depositAndLend(dsaWallet0, wallet0, wallet1, ETH_ID, true, depositAmount, MARKET_3M, fcash);
|
||||
const before = await notional.getAccountPortfolio(dsaWallet0.address);
|
||||
expect(before.length, "expect 1 lending position").to.be.equal(1);
|
||||
expect(before[0][3], "expect 9 fETH").to.be.gte(ethers.utils.parseUnits("900000000", 0));
|
||||
await helpers.withdrawLend(dsaWallet0, wallet0, wallet1, ETH_ID, MARKET_3M, 9e8, 0);
|
||||
await helpers.withdrawLend(dsaWallet0, wallet0, wallet1, ETH_ID, MARKET_3M, fcash);
|
||||
const after = await notional.getAccountPortfolio(dsaWallet0.address);
|
||||
expect(after.length, "expect lending position to be closed out").to.be.equal(0);
|
||||
});
|
||||
|
@ -237,11 +233,12 @@ describe("Notional", function () {
|
|||
value: ethers.utils.parseEther("10")
|
||||
});
|
||||
const depositAmount = ethers.utils.parseEther("10");
|
||||
const fcash = ethers.utils.parseUnits("1000", 8);
|
||||
await helpers.depositCollateralBorrowAndWithdraw(
|
||||
dsaWallet0, wallet0, wallet1, ETH_ID, DEPOSIT_UNDERLYING, depositAmount, DAI_ID, MARKET_3M, 1000e8, 0, true
|
||||
dsaWallet0, wallet0, wallet1, ETH_ID, DEPOSIT_UNDERLYING, depositAmount, DAI_ID, MARKET_3M, fcash, true
|
||||
);
|
||||
expect(
|
||||
await daiToken.balanceOf(dsaWallet0.address),
|
||||
await daiToken.balanceOf(dsaWallet0.address),
|
||||
"expect DSA wallet to contain borrowed balance minus fees"
|
||||
).to.be.gte(ethers.utils.parseEther("990"));
|
||||
});
|
||||
|
@ -252,8 +249,9 @@ describe("Notional", function () {
|
|||
value: ethers.utils.parseEther("10")
|
||||
});
|
||||
const depositAmount = ethers.utils.parseEther("10");
|
||||
const fcash = ethers.utils.parseUnits("1000", 8);
|
||||
await helpers.depositCollateralBorrowAndWithdraw(
|
||||
dsaWallet0, wallet0, wallet1, ETH_ID, DEPOSIT_UNDERLYING, depositAmount, DAI_ID, MARKET_3M, 1000e8, 0, false
|
||||
dsaWallet0, wallet0, wallet1, ETH_ID, DEPOSIT_UNDERLYING, depositAmount, DAI_ID, MARKET_3M, fcash, false
|
||||
);
|
||||
expect(
|
||||
await cdaiToken.balanceOf(dsaWallet0.address),
|
||||
|
@ -264,8 +262,9 @@ describe("Notional", function () {
|
|||
it("test_deposit_DAI_underlying_and_borrow_ETH", async function () {
|
||||
const depositAmount = ethers.utils.parseUnits("20000", 18);
|
||||
await daiToken.connect(daiWhale).transfer(dsaWallet0.address, depositAmount);
|
||||
const fcash = ethers.utils.parseUnits("1", 8);
|
||||
await helpers.depositCollateralBorrowAndWithdraw(
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_UNDERLYING, depositAmount, ETH_ID, MARKET_3M, 1e8, 0, true
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_UNDERLYING, depositAmount, ETH_ID, MARKET_3M, fcash, true
|
||||
);
|
||||
expect(
|
||||
await ethers.provider.getBalance(dsaWallet0.address),
|
||||
|
@ -276,11 +275,12 @@ describe("Notional", function () {
|
|||
it("test_deposit_DAI_asset_and_borrow_ETH", async function () {
|
||||
const depositAmount = ethers.utils.parseUnits("1000000", 8);
|
||||
await cdaiToken.connect(cdaiWhale).transfer(dsaWallet0.address, depositAmount);
|
||||
const fcash = ethers.utils.parseUnits("1", 8);
|
||||
await helpers.depositCollateralBorrowAndWithdraw(
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_ASSET, depositAmount, ETH_ID, MARKET_3M, 1e8, 0, true
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_ASSET, depositAmount, ETH_ID, MARKET_3M, fcash, true
|
||||
);
|
||||
expect(
|
||||
await ethers.provider.getBalance(dsaWallet0.address),
|
||||
await ethers.provider.getBalance(dsaWallet0.address),
|
||||
"expect DSA wallet to contain borrowed balance minus fees"
|
||||
).to.be.gte(ethers.utils.parseEther("0.99"));
|
||||
});
|
||||
|
@ -288,8 +288,9 @@ describe("Notional", function () {
|
|||
it("test_mint_nDAI_underlying_and_borrow_ETH", async function () {
|
||||
const depositAmount = ethers.utils.parseUnits("20000", 18);
|
||||
await daiToken.connect(daiWhale).transfer(dsaWallet0.address, depositAmount);
|
||||
const fcash = ethers.utils.parseUnits("1", 8);
|
||||
await helpers.depositCollateralBorrowAndWithdraw(
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_UNDERLYING_MINT_NTOKEN, depositAmount, ETH_ID, MARKET_3M, 1e8, 0, true
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_UNDERLYING_MINT_NTOKEN, depositAmount, ETH_ID, MARKET_3M, fcash, true
|
||||
);
|
||||
expect(
|
||||
await ethers.provider.getBalance(dsaWallet0.address),
|
||||
|
@ -300,8 +301,9 @@ describe("Notional", function () {
|
|||
it("test_mint_nDAI_asset_and_borrow_ETH", async function () {
|
||||
const depositAmount = ethers.utils.parseUnits("1000000", 8);
|
||||
await cdaiToken.connect(cdaiWhale).transfer(dsaWallet0.address, depositAmount);
|
||||
const fcash = ethers.utils.parseUnits("1", 8);
|
||||
await helpers.depositCollateralBorrowAndWithdraw(
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_ASSET_MINT_NTOKEN, depositAmount, ETH_ID, MARKET_3M, 1e8, 0, true
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_ASSET_MINT_NTOKEN, depositAmount, ETH_ID, MARKET_3M, fcash, true
|
||||
);
|
||||
expect(
|
||||
await ethers.provider.getBalance(dsaWallet0.address),
|
||||
|
@ -377,15 +379,17 @@ describe("Notional", function () {
|
|||
it("test_redeem_DAI_and_deleverage", async function () {
|
||||
const depositAmount = ethers.utils.parseUnits("20000", 18);
|
||||
await daiToken.connect(daiWhale).transfer(dsaWallet0.address, depositAmount);
|
||||
const fcash = ethers.utils.parseUnits("1", 8);
|
||||
await helpers.depositCollateralBorrowAndWithdraw(
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_UNDERLYING, depositAmount, ETH_ID, MARKET_3M, 1e8, 0, true
|
||||
dsaWallet0, wallet0, wallet1, DAI_ID, DEPOSIT_UNDERLYING, depositAmount, ETH_ID, MARKET_3M, fcash, true
|
||||
);
|
||||
const bal = await ethers.provider.getBalance(dsaWallet0.address);
|
||||
await helpers.depositAndMintNToken(dsaWallet0, wallet0, wallet1, ETH_ID, bal, true);
|
||||
const before = await notional.getAccountPortfolio(dsaWallet0.address);
|
||||
expect(before.length, "expect 1 fDAI debt position").to.be.equal(1);
|
||||
expect(before[0][3], "expect fDAI debt position to equal borrow amount").to.be.lte(ethers.utils.parseUnits("-100000000", 0));
|
||||
await helpers.redeemNTokenAndDeleverage(dsaWallet0, wallet0, wallet1, ETH_ID, MaxUint96, MARKET_3M, 0.98e8, 0);
|
||||
const fcash2 = ethers.utils.parseUnits("0.98", 8);
|
||||
await helpers.redeemNTokenAndDeleverage(dsaWallet0, wallet0, wallet1, ETH_ID, MaxUint96, MARKET_3M, fcash2);
|
||||
const after = await notional.getAccountPortfolio(dsaWallet0.address);
|
||||
expect(after.length, "expect 1 fDAI debt position after deleverage").to.be.equal(1);
|
||||
expect(after[0][3], "expect fDAI debt balance to go down after deleverage").to.be.lte(ethers.utils.parseUnits("-2000000", 0));
|
Loading…
Reference in New Issue
Block a user