dsa-connectors-2.0/test/polygon/fluid/fluid.test.ts

716 lines
20 KiB
TypeScript
Raw Normal View History

2024-01-10 16:01:52 +00:00
import { expect } from "chai";
import hre from "hardhat";
import { abis } from "../../../scripts/constant/abis";
2024-02-10 14:17:02 +00:00
import { addresses } from "../../../scripts/tests/polygon/addresses";
2024-01-10 16:01:52 +00:00
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
import { ConnectV2FluidPolygon, ConnectV2FluidPolygon__factory } from "../../../typechain";
import { parseEther, parseUnits } from "@ethersproject/units";
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
import { constants } from "../../../scripts/constant/constant";
import { network, ethers } from "hardhat";
import type { Signer, Contract } from "ethers";
2024-02-11 21:02:33 +00:00
import { BigNumber } from "bignumber.js";
2024-01-10 16:01:52 +00:00
describe("Fluid", function () {
const connectorName = "FLUID";
let connector: any;
let wallet0: Signer, wallet1: Signer, wethHolderSigner: Signer, usdcHolderSigner: Signer;
let dsaWallet0: any;
let instaConnectorsV2: any;
let masterSigner: Signer;
2024-02-11 21:02:33 +00:00
const setIdMaticUsdc = "83478237";
2024-01-10 16:01:52 +00:00
const setIdWethUsdc = "83478249";
const setId3 = "85478249";
2024-02-11 21:02:33 +00:00
const setId4 = "55478249";
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
const vaultMaticUsdc = "0xAf047A21CE590B36FE894dd6fa350b57Ea5Cb0aa";
const vaultWethUsdc = "0xEad5D80db075a905c141b37cE903d621952eA3f6";
const vaultWethMatic = "0x23918014AF7610e31e58A9DC9f9A7DdbfcA4087e";
const vaultUsdcMatic = "0x6395Ddb6161CeF6e64D4c027fbBa26CC76F18148";
2024-01-10 16:01:52 +00:00
const wethHolder = "0xdeD8C5159CA3673f543D0F72043E4c655b35b96A";
2024-02-10 14:17:02 +00:00
const usdcHolder = "0xA67EFB69A4f58F568aAB1b9d51110102985835b0";
2024-01-10 16:01:52 +00:00
const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
const erc20Abi = [
{
constant: false,
inputs: [
{
name: "_spender",
type: "address"
},
{
name: "_value",
type: "uint256"
}
],
name: "approve",
outputs: [
{
name: "",
type: "bool"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [],
name: "totalSupply",
outputs: [
{
name: "",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "_owner",
type: "address"
}
],
name: "balanceOf",
outputs: [
{
name: "balance",
type: "uint256"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{
name: "_to",
type: "address"
},
{
name: "_value",
type: "uint256"
}
],
name: "transfer",
outputs: [
{
name: "",
type: "bool"
}
],
payable: false,
stateMutability: "nonpayable",
type: "function"
}
];
const wethToken = new ethers.Contract(WETH, erc20Abi);
const usdcToken = new ethers.Contract(USDC, erc20Abi);
before(async () => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
// @ts-ignore
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
2024-02-10 14:17:02 +00:00
blockNumber: 53327050,
2024-01-10 16:01:52 +00:00
},
},
],
});
[wallet0, wallet1] = await ethers.getSigners();
masterSigner = await getMasterSigner();
instaConnectorsV2 = await ethers.getContractAt(
abis.core.connectorsV2,
addresses.core.connectorsV2,
masterSigner
);
2024-02-10 14:17:02 +00:00
2024-01-10 16:01:52 +00:00
connector = await deployAndEnableConnector({
connectorName,
contractArtifact: ConnectV2FluidPolygon__factory,
signer: masterSigner,
connectors: instaConnectorsV2,
});
console.log("Connector address", connector.address);
});
it("should have contracts deployed", async () => {
expect(!!instaConnectorsV2.address).to.be.true;
expect(!!connector.address).to.be.true;
expect(!!(await masterSigner.getAddress())).to.be.true;
});
describe("DSA wallet setup", function () {
it("Should build DSA v2", async function () {
dsaWallet0 = await buildDSAv2(wallet0.getAddress());
expect(!!dsaWallet0.address).to.be.true;
});
it("Deposit 2000 Matic into DSA wallet", async function () {
await wallet0.sendTransaction({
to: dsaWallet0.address,
value: parseEther("2000"),
});
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("2000"));
});
it("Deposit 20 Weth into DSA wallet", async function () {
await wallet0.sendTransaction({
to: wethHolder,
value: parseEther("200"),
});
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [wethHolder]
});
wethHolderSigner = await ethers.getSigner(wethHolder);
await wethToken.connect(wethHolderSigner).transfer(dsaWallet0.address, ethers.utils.parseEther("20"));
2024-02-10 14:17:02 +00:00
expect(await wethToken.connect(wethHolderSigner).balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("20"));
2024-01-10 16:01:52 +00:00
});
it("Deposit 20 Usdc into DSA wallet", async function () {
await wallet0.sendTransaction({
to: usdcHolder,
value: parseEther("200"),
});
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [usdcHolder]
});
usdcHolderSigner = await ethers.getSigner(usdcHolder);
await usdcToken.connect(usdcHolderSigner).transfer(dsaWallet0.address, parseUnits("20", 6));
2024-02-10 14:17:02 +00:00
expect(await usdcToken.connect(usdcHolderSigner).balanceOf(dsaWallet0.address)).to.be.gte(parseUnits("20", 6));
2024-01-10 16:01:52 +00:00
});
});
// 2000 matic, 20 weth, 20 usdc
describe("Main", function () {
2024-02-11 21:02:33 +00:00
it("should deposit 1000 Matic in Fluid in MATIC-USDC", async function () {
2024-01-10 16:01:52 +00:00
const amtDeposit = parseEther("1000");
const spells = [
{
connector: connectorName,
2024-02-11 21:02:33 +00:00
method: "operateWithIds",
2024-01-10 16:01:52 +00:00
args: [
vaultMaticUsdc,
2024-02-10 14:17:02 +00:00
'0', // new nft
2024-01-10 16:01:52 +00:00
amtDeposit, // +1000 collateral
2024-02-10 14:17:02 +00:00
'0', // 0 debt
'0',
2024-02-11 21:02:33 +00:00
['0', '0', '0', '0', '0'],
[setIdMaticUsdc, '0', '0', '0', '0'] // set NFT ID of position
2024-01-10 16:01:52 +00:00
],
},
];
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
await tx.wait();
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.gte(
parseEther("1000")
);
});
2024-02-11 21:02:33 +00:00
// 1000 matic, 20 weth, 20 usdc
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
it("should deposit max Matic in Fluid in MATIC-USDC", async function () {
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultMaticUsdc, // matic-usdc vault
0, // NFT ID from setIdMaticUsdc
ethers.constants.MaxInt256, // + max collateral
0, // 0 debt
0,
[setIdMaticUsdc, '0', '0', '0', '0'],
[setIdMaticUsdc, '0', '0', '0', '0']
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
await tx.wait();
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.lte(
parseEther("1")
);
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 0 matic, 20 weth, 20 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
it("should deposit 9 Weth in Fluid in WETH-USDC", async function () {
const amtDeposit = parseEther("9");
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethUsdc,
0, // New nft for WETH-USDC market
amtDeposit, // +10 collateral
0, // 0 debt
0, // 0 repay
['0', '0', '0', '0', '0'],
[setIdWethUsdc, '0', '0', '0', '0']
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
await tx.wait();
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
expect(await wethToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.lte(
parseEther("11")
);
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 0 matic, 11 weth, 20 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
it("should deposit max Weth in Fluid in WETH-USDC", async function () {
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethUsdc,
0, // get nft id
ethers.constants.MaxInt256, // + max collateral
0, // 0 debt
0,
[setIdWethUsdc, '0', '0', '0', '0'],
[setIdWethUsdc, '0', '0', '0', '0']
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
await tx.wait();
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
expect(await wethToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.lte(
parseEther("1")
);
});
// // 0 matic, 0 weth, 20 usdc
it("should deposit 10 USDC in Fluid in USDC-MATIC", async function () {
const spells = [
{
connector: connectorName,
method: "operate",
args: [
vaultUsdcMatic,
0, // get nft id
parseUnits("10", 6), // + max collateral
0, // 0 debt
0
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
await tx.wait();
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
expect(await usdcToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.lte(
parseEther("10")
);
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 0 matic, 0 weth, 10 usdc
it("Should borrow 0.1 USDC from Fluid in WETH-USDC", async function () {
const amtBorrow = parseUnits("0.1", 6); // 0.1 USDC
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethUsdc,
0, // nft ID from getID
0, // 0 collateral
amtBorrow, // +0.1 debt
0,
[setIdWethUsdc, '0', '0', '0', '0'],
[setIdWethUsdc, '0', '0', '0', '0']
],
},
];
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
await tx.wait();
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
expect(await usdcToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.gte(
parseUnits("10", 6)
);
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 0 matic, 0 weth, 10.1 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
it("Should deposit 5 WETH and borrow 0.1 MATIC from Fluid in WETH-MATIC", async function () {
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [wethHolder]
});
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
wethHolderSigner = await ethers.getSigner(wethHolder);
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
await wethToken.connect(wethHolderSigner).transfer(dsaWallet0.address, ethers.utils.parseEther("10"));
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
const amtDeposit = parseEther("5"); // 5 Weth
const amtBorrow = parseEther("0.1"); // 100 Matic
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethMatic,
0, // new nft id
amtDeposit, // 10 collateral
amtBorrow, // +100 debt
0,
['0', '0', '0', '0', '0'],
[setId3, '0', '0', '0', '0']
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
await tx.wait();
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(
parseEther("0.099")
);
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
expect(await wethToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.lte(
parseEther("6")
);
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 0.1 matic, 5 weth, 10.1 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
it("Should deposit 5 WETH and borrow 0.1 MATIC from Fluid in WETH-MATIC", async function () {
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [wethHolder]
});
wethHolderSigner = await ethers.getSigner(wethHolder);
await wethToken.connect(wethHolderSigner).transfer(dsaWallet0.address, ethers.utils.parseEther("10"));
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const amtDeposit = parseEther("5"); // 5 Weth
const amtBorrow = parseEther("0.1"); // 0.1 Matic
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethMatic,
0, // new nft id
amtDeposit, // 10 collateral
amtBorrow, // +0.1 debt
0,
['0', '0', '0', '0', '0'],
[setId4, '0', '0', '0', '0']
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
await tx.wait();
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(
parseEther("0.19")
);
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
expect(await wethToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.lte(
parseEther("11")
);
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 0.2 matic, 10 weth, 10.1 usdc
it("Should payback 0.04 Matic in Fluid in WETH-MATIC", async function () {
const amtPayback = new BigNumber(parseEther("0.04").toString()).multipliedBy(-1); // 0.04 Matic
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethMatic,
0, // nft id from setId3
0, // 0 collateral
amtPayback, // - 0.04 debt
new BigNumber(parseEther("0.04").toString()),
[setId3, '0', '0', '0', '0'],
[setId3, '0', '0', '0', '0']
],
},
];
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
await tx.wait();
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
ethers.utils.parseEther("0.2")
);
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 0.16 matic, 10 weth, 10.1 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// it("Should payback max Matic in Fluid in WETH-MATIC", async function () {
// await wallet0.sendTransaction({
// to: dsaWallet0.address,
// value: parseEther("1"),
// });
2024-02-10 14:17:02 +00:00
// const spells = [
// {
// connector: connectorName,
2024-02-11 21:02:33 +00:00
// method: "operateWithIds",
2024-02-10 14:17:02 +00:00
// args: [
2024-02-11 21:02:33 +00:00
// vaultWethMatic,
// 0, // nft id from setId3
2024-02-10 14:17:02 +00:00
// 0, // 0 collateral
2024-02-11 21:02:33 +00:00
// ethers.constants.MinInt256, // min Int
// new BigNumber(parseEther("0.7").toString()),
// [setId3, '0', '0', '0', '0'],
// ['0', '0', '0', '0', '0']
2024-02-10 14:17:02 +00:00
// ],
// },
// ];
// const tx = await dsaWallet0
// .connect(wallet0)
// .cast(...encodeSpells(spells), wallet1.getAddress());
// await tx.wait();
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
// // expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
// // ethers.utils.parseEther("0.97")
// // );
2024-02-10 14:17:02 +00:00
// });
2024-02-11 21:02:33 +00:00
// // 0.96 matic, 10 weth, 10.1 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
it("Should payback 0.05 Usdc in Fluid in WETH-USDC", async function () {
const amtPayback = new BigNumber(parseUnits("0.05", 6).toString()).multipliedBy(-1); // 0.05 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethUsdc,
0, // nft id from setIdWethUsdc
0, // 0 collateral
amtPayback, // - 0.05 debt
new BigNumber(parseUnits("0.05", 6).toString()),
[setIdWethUsdc, '0', '0', '0', '0'],
[setIdWethUsdc, '0', '0', '0', '0']
],
},
];
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
await tx.wait();
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
expect(await usdcToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte(parseUnits("10.05", 6));
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 0.96 matic, 10 weth, 10.05 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
it("Should withdraw 100 Matic from Fluid in MATIC-USDC", async function () {
const amt = new BigNumber(parseEther("100").toString()).multipliedBy(-1); // 100 Matic
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultMaticUsdc,
0, // nft id from setIdMaticUsdc
amt, // - 100 collateral
0, // 0 debt
0,
[setIdMaticUsdc, '0', '0', '0', '0'],
[setIdMaticUsdc, '0', '0', '0', '0']
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
await tx.wait();
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.gte(
parseEther("100")
);
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 100.96 matic, 10 weth, 10.05 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// it("Should withdraw max Matic from Fluid in MATIC-USDC", async function () {
2024-02-10 14:17:02 +00:00
// const spells = [
// {
// connector: connectorName,
2024-02-11 21:02:33 +00:00
// method: "operateWithIds",
2024-02-10 14:17:02 +00:00
// args: [
// vaultMaticUsdc,
// 0, // nft id from setIdMaticUsdc
// ethers.constants.MinInt256, // min integer value
// 0, // 0 debt
2024-02-11 21:02:33 +00:00
// 0,
// [setIdMaticUsdc, '0', '0', '0', '0'],
// ['0', '0', '0', '0', '0']
2024-02-10 14:17:02 +00:00
// ],
// },
// ];
// const tx = await dsaWallet0
// .connect(wallet0)
// .cast(...encodeSpells(spells), wallet1.getAddress());
// await tx.wait();
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(
2024-02-11 21:02:33 +00:00
// parseEther("2000")
2024-02-10 14:17:02 +00:00
// );
// });
2024-02-11 21:02:33 +00:00
// // 2000.96 matic, 10 weth, 10.05 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
it("Should withdraw 0.4 WETH from Fluid in WETH-USDC", async function () {
const amt = new BigNumber(parseEther("0.4").toString()).multipliedBy(-1); // 1 Weth
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethUsdc,
0, // nft id from setIdWethUsdc
amt, // -1 collateral
0, // 0 debt
0,
[setIdWethUsdc, '0', '0', '0', '0'],
[setIdWethUsdc, '0', '0', '0', '0']
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
await tx.wait();
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// expect(await wethToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.gte(
// parseEther("11")
// );
});
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
// // 2000.96 matic, 11 weth, 10.05 usdc
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
it("Should payback 0.02 and withdraw 0.5 WETH from Fluid in WETH-USDC", async function () {
const amt = new BigNumber(parseEther("0.5").toString()).multipliedBy(-1); // 1 Weth
const paybackAmt = new BigNumber(parseUnits("0.02", 6).toString()).multipliedBy(-1); // 1 Weth
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const spells = [
{
connector: connectorName,
method: "operateWithIds",
args: [
vaultWethUsdc,
0, // nft id from setIdWethUsdc
amt, // -1 collateral
paybackAmt, // 0 debt
new BigNumber(parseUnits("0.03", 6).toString()),
[setIdWethUsdc, '0', '0', '0', '0'],
[setIdWethUsdc, '0', '0', '0', '0']
],
},
];
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
const tx = await dsaWallet0
.connect(wallet0)
.cast(...encodeSpells(spells), wallet1.getAddress());
2024-02-10 14:17:02 +00:00
2024-02-11 21:02:33 +00:00
await tx.wait();
2024-01-10 16:01:52 +00:00
2024-02-11 21:02:33 +00:00
// expect(await wethToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.gte(
// parseEther("12")
// );
// expect(await usdcToken.connect(wallet0).balanceOf(dsaWallet0.address)).to.gte(
// parseEther("11")
// );
});
2024-01-10 16:01:52 +00:00
// todo: add a (payback and withdraw case)
});
});