mirror of
https://github.com/Instadapp/dsa-connectors-2.0.git
synced 2024-07-29 21:57:39 +00:00
feat: update fluid
This commit is contained in:
parent
936d366c3c
commit
0eb6f1d9c2
|
|
@ -3,6 +3,13 @@ pragma solidity ^0.8.2;
|
||||||
|
|
||||||
contract Events {
|
contract Events {
|
||||||
event LogOperate(
|
event LogOperate(
|
||||||
|
address vaultAddress,
|
||||||
|
uint256 nftId,
|
||||||
|
int256 newCol,
|
||||||
|
int256 newDebt
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogOperateWithIds(
|
||||||
address vaultAddress,
|
address vaultAddress,
|
||||||
uint256 nftId,
|
uint256 nftId,
|
||||||
int256 newCol,
|
int256 newCol,
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ abstract contract FluidConnector is Events, Stores {
|
||||||
* @param newDebt_ New debt. If positive then borrow, if negative then payback, if 0 then do nothing
|
* @param newDebt_ New debt. If positive then borrow, if negative then payback, if 0 then do nothing
|
||||||
* For max payback use type(uint25).min.
|
* For max payback use type(uint25).min.
|
||||||
* @param repayApproveAmt_ In case of max amount for payback, this amount will be approved for spending.
|
* @param repayApproveAmt_ In case of max amount for payback, this amount will be approved for spending.
|
||||||
|
* Should always be positive.
|
||||||
* @param getIds_ Array of 5 elements to retrieve IDs:
|
* @param getIds_ Array of 5 elements to retrieve IDs:
|
||||||
* Nft Id, Supply amount, Withdraw amount, Borrow Amount, Payback Amount
|
* Nft Id, Supply amount, Withdraw amount, Borrow Amount, Payback Amount
|
||||||
* @param setIds_ Array of 5 elements to store IDs generated:
|
* @param setIds_ Array of 5 elements to store IDs generated:
|
||||||
|
|
@ -85,6 +86,7 @@ abstract contract FluidConnector is Events, Stores {
|
||||||
|
|
||||||
bool isColMax_ = newCol_ == type(int256).max;
|
bool isColMax_ = newCol_ == type(int256).max;
|
||||||
|
|
||||||
|
// Deposit
|
||||||
if (newCol_ > 0) {
|
if (newCol_ > 0) {
|
||||||
if (vaultDetails_.supplyToken == getMaticAddr()) {
|
if (vaultDetails_.supplyToken == getMaticAddr()) {
|
||||||
ethAmount_ = isColMax_
|
ethAmount_ = isColMax_
|
||||||
|
|
@ -108,8 +110,10 @@ abstract contract FluidConnector is Events, Stores {
|
||||||
|
|
||||||
bool isPaybackMax_ = newDebt_ == type(int256).min;
|
bool isPaybackMax_ = newDebt_ == type(int256).min;
|
||||||
|
|
||||||
|
// Payback
|
||||||
if (newDebt_ < 0) {
|
if (newDebt_ < 0) {
|
||||||
if (vaultDetails_.borrowToken == getMaticAddr()) {
|
if (vaultDetails_.borrowToken == getMaticAddr()) {
|
||||||
|
// Needs to be positive as it will be send in msg.value
|
||||||
ethAmount_ = isPaybackMax_
|
ethAmount_ = isPaybackMax_
|
||||||
? repayApproveAmt_
|
? repayApproveAmt_
|
||||||
: uint256(-1 * newDebt_);
|
: uint256(-1 * newDebt_);
|
||||||
|
|
@ -126,6 +130,7 @@ abstract contract FluidConnector is Events, Stores {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note max withdraw will be handled by Fluid contract
|
||||||
(nftId_, newCol_, newDebt_) = vault_.operate{value: ethAmount_}(
|
(nftId_, newCol_, newDebt_) = vault_.operate{value: ethAmount_}(
|
||||||
nftId_,
|
nftId_,
|
||||||
newCol_,
|
newCol_,
|
||||||
|
|
@ -142,7 +147,7 @@ abstract contract FluidConnector is Events, Stores {
|
||||||
? setUint(setIds_[3], uint256(newDebt_))
|
? setUint(setIds_[3], uint256(newDebt_))
|
||||||
: setUint(setIds_[4], uint256(newDebt_)); // If setIds_[4] != 0, it will set the ID.
|
: setUint(setIds_[4], uint256(newDebt_)); // If setIds_[4] != 0, it will set the ID.
|
||||||
|
|
||||||
_eventName = "LogOperate(address,uint256,int256,int256,uint256[],uint256[])";
|
_eventName = "LogOperateWithIds(address,uint256,int256,int256,uint256[],uint256[])";
|
||||||
_eventParam = abi.encode(
|
_eventParam = abi.encode(
|
||||||
vaultAddress_,
|
vaultAddress_,
|
||||||
nftId_,
|
nftId_,
|
||||||
|
|
@ -152,6 +157,98 @@ abstract contract FluidConnector is Events, Stores {
|
||||||
setIds_
|
setIds_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit, borrow, payback and withdraw asset from the vault.
|
||||||
|
* @notice Single function which handles supply, withdraw, borrow & payback
|
||||||
|
* @param vaultAddress_ Vault address.
|
||||||
|
* @param nftId_ NFT ID for interaction. If 0 then create new NFT/position.
|
||||||
|
* @param newCol_ New collateral. If positive then deposit, if negative then withdraw, if 0 then do nothing.
|
||||||
|
* For max deposit use type(uint25).max, for max withdraw use type(uint25).min.
|
||||||
|
* @param newDebt_ New debt. If positive then borrow, if negative then payback, if 0 then do nothing
|
||||||
|
* For max payback use type(uint25).min.
|
||||||
|
* @param repayApproveAmt_ In case of max amount for payback, this amount will be approved for spending.
|
||||||
|
* Should always be positive.
|
||||||
|
*/
|
||||||
|
function operate(
|
||||||
|
address vaultAddress_,
|
||||||
|
uint256 nftId_,
|
||||||
|
int256 newCol_,
|
||||||
|
int256 newDebt_,
|
||||||
|
uint256 repayApproveAmt_
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
IVault vault_ = IVault(vaultAddress_);
|
||||||
|
|
||||||
|
IVault.ConstantViews memory vaultDetails_ = vault_.constantsView();
|
||||||
|
|
||||||
|
uint256 ethAmount_;
|
||||||
|
|
||||||
|
bool isColMax_ = newCol_ == type(int256).max;
|
||||||
|
|
||||||
|
// Deposit
|
||||||
|
if (newCol_ > 0) {
|
||||||
|
if (vaultDetails_.supplyToken == getMaticAddr()) {
|
||||||
|
ethAmount_ = isColMax_
|
||||||
|
? address(this).balance
|
||||||
|
: uint256(newCol_);
|
||||||
|
} else {
|
||||||
|
if (isColMax_) {
|
||||||
|
newCol_ = int256(
|
||||||
|
TokenInterface(vaultDetails_.supplyToken).balanceOf(
|
||||||
|
address(this)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TokenInterface(vaultDetails_.supplyToken).approve(
|
||||||
|
vaultAddress_,
|
||||||
|
uint256(newCol_)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isPaybackMax_ = newDebt_ == type(int256).min;
|
||||||
|
|
||||||
|
// Payback
|
||||||
|
if (newDebt_ < 0) {
|
||||||
|
if (vaultDetails_.borrowToken == getMaticAddr()) {
|
||||||
|
// Needs to be positive as it will be send in msg.value
|
||||||
|
ethAmount_ = isPaybackMax_
|
||||||
|
? repayApproveAmt_
|
||||||
|
: uint256(-1 * newDebt_);
|
||||||
|
} else {
|
||||||
|
isPaybackMax_
|
||||||
|
? TokenInterface(vaultDetails_.borrowToken).approve(
|
||||||
|
vaultAddress_,
|
||||||
|
repayApproveAmt_
|
||||||
|
)
|
||||||
|
: TokenInterface(vaultDetails_.borrowToken).approve(
|
||||||
|
vaultAddress_,
|
||||||
|
uint256(-1 * newDebt_)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note max withdraw will be handled by Fluid contract
|
||||||
|
(nftId_, newCol_, newDebt_) = vault_.operate{value: ethAmount_}(
|
||||||
|
nftId_,
|
||||||
|
newCol_,
|
||||||
|
newDebt_,
|
||||||
|
address(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
_eventName = "LogOperate(address,uint256,int256,int256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
vaultAddress_,
|
||||||
|
nftId_,
|
||||||
|
newCol_,
|
||||||
|
newDebt_
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV2FluidPolygon is FluidConnector {
|
contract ConnectV2FluidPolygon is FluidConnector {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import hre from "hardhat";
|
import hre from "hardhat";
|
||||||
import { abis } from "../../../scripts/constant/abis";
|
import { abis } from "../../../scripts/constant/abis";
|
||||||
import { addresses } from "../../../scripts/tests/mainnet/addresses";
|
import { addresses } from "../../../scripts/tests/polygon/addresses";
|
||||||
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
|
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
|
||||||
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
||||||
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
|
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
|
||||||
|
|
@ -20,7 +20,7 @@ describe("Fluid", function () {
|
||||||
let dsaWallet0: any;
|
let dsaWallet0: any;
|
||||||
let instaConnectorsV2: any;
|
let instaConnectorsV2: any;
|
||||||
let masterSigner: Signer;
|
let masterSigner: Signer;
|
||||||
const setIdMaticUsdc = "83478237";
|
const setIdMaticUsdc = ethers.BigNumber.from("83478237");
|
||||||
const setIdWethUsdc = "83478249";
|
const setIdWethUsdc = "83478249";
|
||||||
const setId3 = "85478249";
|
const setId3 = "85478249";
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ describe("Fluid", function () {
|
||||||
const vaultWethMatic = "0x553437CB882E3aFbB67Abd135E067AFB0721fbf1";
|
const vaultWethMatic = "0x553437CB882E3aFbB67Abd135E067AFB0721fbf1";
|
||||||
|
|
||||||
const wethHolder = "0xdeD8C5159CA3673f543D0F72043E4c655b35b96A";
|
const wethHolder = "0xdeD8C5159CA3673f543D0F72043E4c655b35b96A";
|
||||||
const usdcHolder = "0xEc4Db437ADEE0420A28Afa8B87c74D3901F56AC4";
|
const usdcHolder = "0xA67EFB69A4f58F568aAB1b9d51110102985835b0";
|
||||||
|
|
||||||
const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
||||||
const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
||||||
|
|
@ -127,7 +127,7 @@ describe("Fluid", function () {
|
||||||
forking: {
|
forking: {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
|
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
|
||||||
blockNumber: 12796965,
|
blockNumber: 53327050,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -140,6 +140,7 @@ describe("Fluid", function () {
|
||||||
addresses.core.connectorsV2,
|
addresses.core.connectorsV2,
|
||||||
masterSigner
|
masterSigner
|
||||||
);
|
);
|
||||||
|
|
||||||
connector = await deployAndEnableConnector({
|
connector = await deployAndEnableConnector({
|
||||||
connectorName,
|
connectorName,
|
||||||
contractArtifact: ConnectV2FluidPolygon__factory,
|
contractArtifact: ConnectV2FluidPolygon__factory,
|
||||||
|
|
@ -186,8 +187,7 @@ describe("Fluid", function () {
|
||||||
|
|
||||||
await wethToken.connect(wethHolderSigner).transfer(dsaWallet0.address, ethers.utils.parseEther("20"));
|
await wethToken.connect(wethHolderSigner).transfer(dsaWallet0.address, ethers.utils.parseEther("20"));
|
||||||
|
|
||||||
expect(await wethToken.balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("20"));
|
expect(await wethToken.connect(wethHolderSigner).balanceOf(dsaWallet0.address)).to.be.gte(ethers.utils.parseEther("20"));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Deposit 20 Usdc into DSA wallet", async function () {
|
it("Deposit 20 Usdc into DSA wallet", async function () {
|
||||||
|
|
@ -205,7 +205,7 @@ describe("Fluid", function () {
|
||||||
|
|
||||||
await usdcToken.connect(usdcHolderSigner).transfer(dsaWallet0.address, parseUnits("20", 6));
|
await usdcToken.connect(usdcHolderSigner).transfer(dsaWallet0.address, parseUnits("20", 6));
|
||||||
|
|
||||||
expect(await usdcToken.balanceOf(dsaWallet0.address)).to.be.gte(parseUnits("20", 6));
|
expect(await usdcToken.connect(usdcHolderSigner).balanceOf(dsaWallet0.address)).to.be.gte(parseUnits("20", 6));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -221,12 +221,12 @@ describe("Fluid", function () {
|
||||||
method: "operate",
|
method: "operate",
|
||||||
args: [
|
args: [
|
||||||
vaultMaticUsdc,
|
vaultMaticUsdc,
|
||||||
0, // new nft
|
'0', // new nft
|
||||||
amtDeposit, // +1000 collateral
|
amtDeposit, // +1000 collateral
|
||||||
0, // 0 debt
|
'0', // 0 debt
|
||||||
dsaWallet0.address,
|
'0',
|
||||||
0,
|
['0','0','0','0','0'],
|
||||||
setIdMaticUsdc
|
['0',setIdMaticUsdc,'0','0','0']
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -243,407 +243,407 @@ describe("Fluid", function () {
|
||||||
});
|
});
|
||||||
// 1000 matic
|
// 1000 matic
|
||||||
|
|
||||||
it("should deposit max Matic in Fluid", async function () {
|
// it("should deposit max Matic in Fluid", async function () {
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultMaticUsdc, // matic-usdc vault
|
// vaultMaticUsdc, // matic-usdc vault
|
||||||
0, // setIdMaticUsdc
|
// 0, // setIdMaticUsdc
|
||||||
ethers.constants.MaxUint256, // + max collateral
|
// ethers.constants.MaxUint256, // + max collateral
|
||||||
0, // 0 debt
|
// 0, // 0 debt
|
||||||
dsaWallet0.address,
|
// 0,
|
||||||
setIdMaticUsdc,
|
// [0,setIdMaticUsdc,0,0,0],
|
||||||
0
|
// [0,0,0,0,0]
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.lte(
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.lte(
|
||||||
parseEther("1")
|
// parseEther("1")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 0 matic
|
// // 0 matic
|
||||||
|
|
||||||
it("should deposit 10 Weth in Fluid", async function () {
|
// it("should deposit 10 Weth in Fluid", async function () {
|
||||||
const amtDeposit = parseEther("10");
|
// const amtDeposit = parseEther("10");
|
||||||
|
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultWethUsdc,
|
// vaultWethUsdc,
|
||||||
0, // new nft
|
// 0, // new nft
|
||||||
amtDeposit, // +10 collateral
|
// amtDeposit, // +10 collateral
|
||||||
0, // 0 debt
|
// 0, // 0 debt
|
||||||
dsaWallet0.address,
|
// 0,
|
||||||
0,
|
// [0,0,0,0,0],
|
||||||
setIdWethUsdc
|
// [0,setIdWethUsdc,0,0,0]
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await wethToken.balanceOf(dsaWallet0.address)).to.lte(
|
// expect(await wethToken.balanceOf(dsaWallet0.address)).to.lte(
|
||||||
parseEther("10")
|
// parseEther("10")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 10 weth
|
// // 10 weth
|
||||||
|
|
||||||
it("should deposit max Weth in Fluid", async function () {
|
// it("should deposit max Weth in Fluid", async function () {
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultWethUsdc,
|
// vaultWethUsdc,
|
||||||
0, // get id nft
|
// 0, // get id nft
|
||||||
ethers.constants.MaxUint256, // + max collateral
|
// ethers.constants.MaxUint256, // + max collateral
|
||||||
0, // 0 debt
|
// 0, // 0 debt
|
||||||
dsaWallet0.address,
|
// 0,
|
||||||
setIdWethUsdc,
|
// [0,setIdWethUsdc,0,0,0],
|
||||||
0
|
// [0,0,0,0,0]
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.lte(
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.lte(
|
||||||
parseEther("1")
|
// parseEther("1")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 0 weth
|
// // 0 weth
|
||||||
|
|
||||||
it("Should borrow USDC from Fluid", async function () {
|
// it("Should borrow USDC from Fluid", async function () {
|
||||||
const amtBorrow = parseUnits("100", 6); // 100 USDC
|
// const amtBorrow = parseUnits("100", 6); // 100 USDC
|
||||||
|
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultMaticUsdc,
|
// vaultMaticUsdc,
|
||||||
0, // nft id from getID
|
// 0, // nft id from getID
|
||||||
0, // 0 collateral
|
// 0, // 0 collateral
|
||||||
amtBorrow, // +100 debt
|
// amtBorrow, // +100 debt
|
||||||
dsaWallet0.address,
|
// 0,
|
||||||
setIdMaticUsdc,
|
// [0,0,0,0,0],
|
||||||
0
|
// [0,0,0,0,0]
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await usdcToken.balanceOf(dsaWallet0.address)).to.be.gte(
|
// expect(await usdcToken.balanceOf(dsaWallet0.address)).to.be.gte(
|
||||||
parseUnits("120", 6)
|
// parseUnits("120", 6)
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 120 usdc
|
// // 120 usdc
|
||||||
|
|
||||||
it("Should deposit WETH and borrow MATIC from Fluid", async function () {
|
// it("Should deposit WETH and borrow MATIC from Fluid", async function () {
|
||||||
await hre.network.provider.request({
|
// await hre.network.provider.request({
|
||||||
method: "hardhat_impersonateAccount",
|
// method: "hardhat_impersonateAccount",
|
||||||
params: [wethHolder]
|
// params: [wethHolder]
|
||||||
});
|
// });
|
||||||
|
|
||||||
wethHolderSigner = await ethers.getSigner(wethHolder);
|
// wethHolderSigner = await ethers.getSigner(wethHolder);
|
||||||
|
|
||||||
await wethToken.connect(wethHolderSigner).transfer(dsaWallet0.address, ethers.utils.parseEther("11"));
|
// await wethToken.connect(wethHolderSigner).transfer(dsaWallet0.address, ethers.utils.parseEther("11"));
|
||||||
|
|
||||||
const amtDeposit = parseEther("10"); // 10 Weth
|
// const amtDeposit = parseEther("10"); // 10 Weth
|
||||||
const amtBorrow = parseEther("100"); // 100 Matic
|
// const amtBorrow = parseEther("100"); // 100 Matic
|
||||||
|
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultWethMatic,
|
// vaultWethMatic,
|
||||||
0, // new nft id
|
// 0, // new nft id
|
||||||
amtDeposit, // 10 collateral
|
// amtDeposit, // 10 collateral
|
||||||
amtBorrow, // +100 debt
|
// amtBorrow, // +100 debt
|
||||||
dsaWallet0.address,
|
// 0,
|
||||||
0,
|
// [0,0,0,0,0],
|
||||||
setId3
|
// [0,0,0,setId3,0]
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(
|
||||||
parseEther("100")
|
// parseEther("100")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 120 usdc, 100 matic
|
// // 120 usdc, 100 matic
|
||||||
|
|
||||||
it("Should payback Matic in Fluid", async function () {
|
// it("Should payback Matic in Fluid", async function () {
|
||||||
const amtPayback = ethers.BigNumber.from(parseEther("50")).mul(-1); // 50 Matic
|
// const amtPayback = ethers.BigNumber.from(parseEther("50")).mul(-1); // 50 Matic
|
||||||
|
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultWethMatic,
|
// vaultWethMatic,
|
||||||
0, // nft id from setId3
|
// 0, // nft id from setId3
|
||||||
0, // 0 collateral
|
// 0, // 0 collateral
|
||||||
amtPayback, // - 50 debt
|
// amtPayback, // - 50 debt
|
||||||
dsaWallet0.address,
|
// ethers.BigNumber.from(parseEther("50")),
|
||||||
setId3,
|
// [0,0,0,0,setId3],
|
||||||
0
|
// [0,0,0,0,0]
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
|
||||||
ethers.utils.parseEther("50")
|
// ethers.utils.parseEther("50")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 120 usdc, 50 matic
|
// // 120 usdc, 50 matic
|
||||||
|
|
||||||
it("Should payback max Matic in Fluid", async function () {
|
// it("Should payback max Matic in Fluid", async function () {
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultWethMatic,
|
// vaultWethMatic,
|
||||||
0, // nft id from setId3
|
// 0, // nft id from setId3
|
||||||
0, // 0 collateral
|
// 0, // 0 collateral
|
||||||
ethers.constants.MinInt256, // min Int
|
// ethers.constants.MinInt256, // min Int
|
||||||
dsaWallet0.address,
|
// ethers.BigNumber.from(parseEther("50")),
|
||||||
setId3,
|
// [0,0,0,0,0],
|
||||||
0
|
// [0,0,0,0,0]
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
|
||||||
ethers.utils.parseEther("1")
|
// ethers.utils.parseEther("1")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 120 usdc, 0 matic
|
// 120 usdc, 0 matic/////////
|
||||||
|
|
||||||
it("Should payback Usdc in Fluid", async function () {
|
// it("Should payback Usdc in Fluid", async function () {
|
||||||
const amtPayback = ethers.BigNumber.from(parseUnits("60", 6)).mul(-1); // 60 usdc
|
// const amtPayback = ethers.BigNumber.from(parseUnits("60", 6)).mul(-1); // 60 usdc
|
||||||
|
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultMaticUsdc,
|
// vaultMaticUsdc,
|
||||||
0, // nft id from setIdWethUsdc
|
// 0, // nft id from setIdWethUsdc
|
||||||
0, // 0 collateral
|
// 0, // 0 collateral
|
||||||
amtPayback, // - 60 debt
|
// amtPayback, // - 60 debt
|
||||||
dsaWallet0.address,
|
// dsaWallet0.address,
|
||||||
setIdMaticUsdc,
|
// setIdMaticUsdc,
|
||||||
0
|
// 0
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await usdcToken.balanceOf(dsaWallet0.address)).to.be.lte(parseUnits("60", 6));
|
// expect(await usdcToken.balanceOf(dsaWallet0.address)).to.be.lte(parseUnits("60", 6));
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 60 usdc, 0 matic
|
// // 60 usdc, 0 matic
|
||||||
|
|
||||||
it("Should payback max Matic in Fluid", async function () {
|
// it("Should payback max Matic in Fluid", async function () {
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultMaticUsdc,
|
// vaultMaticUsdc,
|
||||||
0, // nft id from setIdWethUsdc
|
// 0, // nft id from setIdWethUsdc
|
||||||
0, // 0 collateral
|
// 0, // 0 collateral
|
||||||
ethers.constants.MinInt256, // min Int
|
// ethers.constants.MinInt256, // min Int
|
||||||
dsaWallet0.address,
|
// dsaWallet0.address,
|
||||||
setIdMaticUsdc,
|
// setIdMaticUsdc,
|
||||||
0
|
// 0
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await usdcToken.balanceOf(dsaWallet0.address)).to.be.lte(parseUnits("1", 6));
|
// expect(await usdcToken.balanceOf(dsaWallet0.address)).to.be.lte(parseUnits("1", 6));
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 0 usdc, 0 matic
|
// // 0 usdc, 0 matic
|
||||||
|
|
||||||
it("Should withdraw Matic from Fluid", async function () {
|
// it("Should withdraw Matic from Fluid", async function () {
|
||||||
const amt = ethers.BigNumber.from(parseEther("100")).mul(-1); // 100 Matic
|
// const amt = ethers.BigNumber.from(parseEther("100")).mul(-1); // 100 Matic
|
||||||
|
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultMaticUsdc,
|
// vaultMaticUsdc,
|
||||||
0, // nft id from setIdMaticUsdc
|
// 0, // nft id from setIdMaticUsdc
|
||||||
amt, // - 100 collateral
|
// amt, // - 100 collateral
|
||||||
0, // 0 debt
|
// 0, // 0 debt
|
||||||
dsaWallet0.address,
|
// dsaWallet0.address,
|
||||||
setIdMaticUsdc,
|
// setIdMaticUsdc,
|
||||||
0
|
// 0
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(
|
||||||
parseEther("100")
|
// parseEther("100")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 0 usdc, 100 matic
|
// // 0 usdc, 100 matic
|
||||||
|
|
||||||
it("Should withdraw max Matic from Fluid", async function () {
|
// it("Should withdraw max Matic from Fluid", async function () {
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultMaticUsdc,
|
// vaultMaticUsdc,
|
||||||
0, // nft id from setIdMaticUsdc
|
// 0, // nft id from setIdMaticUsdc
|
||||||
ethers.constants.MinInt256, // min integer value
|
// ethers.constants.MinInt256, // min integer value
|
||||||
0, // 0 debt
|
// 0, // 0 debt
|
||||||
dsaWallet0.address,
|
// dsaWallet0.address,
|
||||||
setIdMaticUsdc,
|
// setIdMaticUsdc,
|
||||||
0
|
// 0
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(
|
||||||
parseEther("1000")
|
// parseEther("1000")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 0 usdc, 1000 matic
|
// // 0 usdc, 1000 matic
|
||||||
|
|
||||||
it("Should withdraw WETH from Fluid", async function () {
|
// it("Should withdraw WETH from Fluid", async function () {
|
||||||
const amt = ethers.BigNumber.from(parseEther("10")).mul(-1); // 10 Weth
|
// const amt = ethers.BigNumber.from(parseEther("10")).mul(-1); // 10 Weth
|
||||||
|
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultWethUsdc,
|
// vaultWethUsdc,
|
||||||
0, // nft id from setIdWethUsdc
|
// 0, // nft id from setIdWethUsdc
|
||||||
amt, // -10 collateral
|
// amt, // -10 collateral
|
||||||
0, // 0 debt
|
// 0, // 0 debt
|
||||||
dsaWallet0.address,
|
// dsaWallet0.address,
|
||||||
setIdWethUsdc,
|
// setIdWethUsdc,
|
||||||
0
|
// 0
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await wethToken.balanceOf(dsaWallet0.address)).to.eq(
|
// expect(await wethToken.balanceOf(dsaWallet0.address)).to.eq(
|
||||||
parseEther("10")
|
// parseEther("10")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 0 usdc, 1000 matic, 10 weth
|
// // 0 usdc, 1000 matic, 10 weth
|
||||||
|
|
||||||
it("Should withdraw max WETH from Fluid", async function () {
|
// it("Should withdraw max WETH from Fluid", async function () {
|
||||||
const spells = [
|
// const spells = [
|
||||||
{
|
// {
|
||||||
connector: connectorName,
|
// connector: connectorName,
|
||||||
method: "operate",
|
// method: "operate",
|
||||||
args: [
|
// args: [
|
||||||
vaultWethUsdc,
|
// vaultWethUsdc,
|
||||||
0, // nft id from setIdWethUsdc
|
// 0, // nft id from setIdWethUsdc
|
||||||
ethers.constants.MinInt256, // min integer value
|
// ethers.constants.MinInt256, // min integer value
|
||||||
0, // 0 debt
|
// 0, // 0 debt
|
||||||
dsaWallet0.address,
|
// dsaWallet0.address,
|
||||||
setIdWethUsdc,
|
// setIdWethUsdc,
|
||||||
0
|
// 0
|
||||||
],
|
// ],
|
||||||
},
|
// },
|
||||||
];
|
// ];
|
||||||
|
|
||||||
const tx = await dsaWallet0
|
// const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
// .connect(wallet0)
|
||||||
.cast(...encodeSpells(spells), wallet1.getAddress());
|
// .cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await tx.wait();
|
// await tx.wait();
|
||||||
|
|
||||||
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(
|
// expect(await ethers.provider.getBalance(dsaWallet0.address)).to.eq(
|
||||||
parseEther("29")
|
// parseEther("29")
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
// 0 usdc, 1000 matic, 30 weth
|
// 0 usdc, 1000 matic, 30 weth
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user