chore: test folder cleanup

This commit is contained in:
gitpusha 2020-11-15 15:08:12 +01:00 committed by Twin Fish
parent a79a785fa7
commit 2cebab9fe5
50 changed files with 1112 additions and 1165 deletions

View File

@ -2,4 +2,5 @@ node_modules/
contracts/constants
contracts/dependencies
contracts/functions
contracts/__mocks__/__dependencies__
contracts/vendor

View File

@ -4,6 +4,6 @@ pragma solidity 0.6.10;
import "@gelatonetwork/core/contracts/gelato_core/GelatoCore.sol";
// solhint-disable-next-line no-empty-blocks
contract GelatoTestDependencies {
contract DGelatoCore {
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.0;
pragma solidity >=0.6.0;
interface CTokenInterface {
function mint(uint256 mintAmount) external returns (uint256);
@ -188,7 +188,7 @@ contract CompoundHelpers is Helpers {
}
/**
* @dev Return InstaDApp Mapping Addresses
* @dev Return InstaDapp Mapping Addresses
*/
function getMappingAddr() internal pure returns (address) {
return 0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88; // InstaMapping Address
@ -263,7 +263,7 @@ contract BasicResolver is CompoundHelpers {
enterMarket(cToken);
if (token == getAddressETH()) {
_amt = _amt == uint256(-1) ? address(this).balance : _amt;
CETHInterface(cToken).mint.value(_amt)();
CETHInterface(cToken).mint{value: _amt}();
} else {
TokenInterface tokenContract = TokenInterface(token);
_amt = _amt == uint256(-1)
@ -398,7 +398,7 @@ contract BasicResolver is CompoundHelpers {
if (token == getAddressETH()) {
require(address(this).balance >= _amt, "not-enough-eth");
CETHInterface(cToken).repayBorrow.value(_amt)();
CETHInterface(cToken).repayBorrow{value: _amt}();
} else {
TokenInterface tokenContract = TokenInterface(token);
require(
@ -498,7 +498,7 @@ contract ExtraResolver is BasicResolver {
if (token == getAddressETH()) {
_amt = _amt == uint256(-1) ? address(this).balance : _amt;
CETHInterface(cToken).mint.value(_amt)();
CETHInterface(cToken).mint{value: _amt}();
} else {
TokenInterface tokenContract = TokenInterface(token);
_amt = _amt == uint256(-1)
@ -601,7 +601,7 @@ contract ExtraResolver is BasicResolver {
: _amt;
if (tokenToPay == getAddressETH()) {
require(address(this).balance >= _amt, "not-enought-eth");
CETHInterface(cTokenPay).liquidateBorrow.value(_amt)(
CETHInterface(cTokenPay).liquidateBorrow{value: _amt}(
borrower,
cTokenColl
);

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.0;
pragma solidity >=0.6.0;
interface TokenInterface {
function approve(address, uint256) external;
@ -589,7 +589,7 @@ contract BasicResolver is EventHelper {
if (isEth(address(tokenContract))) {
_amt = _amt == uint256(-1) ? address(this).balance : _amt;
tokenContract.deposit.value(_amt)();
tokenContract.deposit{value: _amt}();
} else {
_amt = _amt == uint256(-1)
? tokenContract.balanceOf(address(this))
@ -883,7 +883,7 @@ contract BasicExtraResolver is BasicResolver {
_amtDeposit = _amtDeposit == uint256(-1)
? address(this).balance
: _amtDeposit;
makerData.tokenContract.deposit.value(_amtDeposit)();
makerData.tokenContract.deposit{value: _amtDeposit}();
} else {
_amtDeposit = _amtDeposit == uint256(-1)
? makerData.tokenContract.balanceOf(address(this))

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.0;
pragma solidity >=0.6.0;
pragma experimental ABIEncoderV2;
/**

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.0;
pragma solidity >=0.6.0;
/**
* @title InstaConnectors

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.0;
pragma solidity >=0.6.0;
pragma experimental ABIEncoderV2;
/**
@ -197,7 +197,7 @@ contract InstaIndex is CloneFactory {
) external payable returns (address _account) {
_account = build(_owner, accountVersion, _origin);
if (_targets.length > 0)
AccountInterface(_account).cast.value(msg.value)(
AccountInterface(_account).cast{value: msg.value}(
_targets,
_datas,
_origin

View File

@ -1,4 +1,4 @@
pragma solidity ^0.6.0;
pragma solidity >=0.6.0;
/**
* @title InstaList

View File

@ -2,7 +2,7 @@
pragma solidity 0.7.4;
pragma experimental ABIEncoderV2;
// import "hardhat/console.sol"; // Uncomment this line for using gasLeft Method
// import {console} from "hardhat/console.sol"; // Uncomment this line for using gasLeft Method
import {
TaskReceipt
} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoCore.sol";
@ -22,12 +22,10 @@ contract MockGelatoExecutor {
gelatoCore = _gelatoCore;
}
// solhint-disable-next-line
function exec(TaskReceipt memory _TR) external {
// uint256 gasLeft = gasleft(); // Uncomment this line for using gasleft Method
IGelatoCore(gelatoCore).exec(_TR);
// solhint-disable-next-line
// console.log("Gas Cost for Task Execution %s", gasLeft - gasleft());// Uncomment this line for using gasleft Method
function exec(TaskReceipt memory _taskReceipt) external {
// uint256 gasLeft = gasleft();
IGelatoCore(gelatoCore).exec(_taskReceipt);
// console.log("Gas Cost for Task Execution %s", gasLeft - gasleft());
}
function stakeExecutor() external payable {
@ -35,11 +33,15 @@ contract MockGelatoExecutor {
}
function canExec(
// solhint-disable-next-line
TaskReceipt calldata _TR,
TaskReceipt calldata _taskReceipt,
uint256 _gasLimit,
uint256 _execTxGasPrice
) external view returns (string memory) {
return IGelatoCore(gelatoCore).canExec(_TR, _gasLimit, _execTxGasPrice);
return
IGelatoCore(gelatoCore).canExec(
_taskReceipt,
_gasLimit,
_execTxGasPrice
);
}
}

View File

@ -4,8 +4,8 @@ const { deployments, ethers } = hre;
const GelatoCoreLib = require("@gelatonetwork/core");
const setupFullRefinanceMakerToMakerWithVaultBCreationMock = require("./helpers/setupFullRefinanceMakerToMakerWithVaultBCreationMock");
const getRoute = require("./helpers/services/getRoute");
const getGasCostForFullRefinance = require("./helpers/services/getGasCostForFullRefinance");
const getInstaPoolV2Route = require("../helpers/services/InstaDapp/getInstaPoolV2Route");
const getGasCostForFullRefinance = require("../integration/debt_bridge/from_maker/full/helpers/services/getGasCostForFullRefinance");
// This test showcases how to submit a task refinancing a Users debt position from
// Maker to Compound using Gelato
@ -201,7 +201,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B For Gas Measurem
vaultAId
);
const route = await getRoute(
const route = await getInstaPoolV2Route(
contracts.DAI.address,
debtOnMakerBefore,
contracts.instaPoolResolver

View File

@ -1,8 +1,6 @@
const hre = require("hardhat");
const { ethers } = hre;
async function getMockGelato() {
module.exports = async function () {
return await ethers.getContract("MockGelatoExecutor");
}
module.exports = getMockGelato;
};

View File

@ -1,6 +1,6 @@
const { expect } = require("chai");
async function stakeExecutor(
module.exports = async function (
gelatoExecutorWallet,
gelatoExecutorMock,
gelatoCore
@ -23,6 +23,4 @@ async function stakeExecutor(
.true;
//#endregion
}
module.exports = stakeExecutor;
};

View File

@ -1,26 +1,26 @@
const getWallets = require("./services/getWallets");
const getContracts = require("./services/getContracts");
const getConstants = require("./services/getConstants");
const getMockGelato = require("./services/getMockGelato");
const getWallets = require("../../helpers/services/getWallets");
const getContracts = require("../../helpers/services/getContracts");
const getDebtBridgeFromMakerConstants = require("../../integration/debt_bridge/from_maker/services/getDebtBridgeFromMakerConstants");
const getMockGelatoExecutor = require("../helpers/services/getMockGelatoExecutor");
const stakeExecutorMock = require("./services/stakeExecutorMock");
const provideFunds = require("./services/provideFunds");
const providerAssignsExecutor = require("./services/providerAssignsExecutor");
const addProviderModuleDSA = require("./services/addProviderModuleDSA");
const createDSA = require("./services/createDSA");
const addETHBGemJoinMapping = require("./services/addETHBGemJoinMapping");
const initializeMakerCdp = require("./services/initializeMakerCdp");
const createVaultForETHB = require("./services/createVaultForETHB");
const providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB = require("./services/providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB");
const getABI = require("./services/getABI");
const provideFunds = require("../../helpers/services/gelato/provideFunds");
const providerAssignsExecutor = require("../../helpers/services/gelato/providerAssignsExecutor");
const addProviderModuleDSA = require("../../helpers/services/gelato/addProviderModuleDSA");
const createDSA = require("../../helpers/services/InstaDapp/createDSA");
const addETHBGemJoinMapping = require("../../helpers/services/maker/addETHBGemJoinMapping");
const initializeMakerCdp = require("../../helpers/services/maker/initializeMakerCdp");
const createVaultForETHB = require("../../helpers/services/maker/createVaultForETHB");
const providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB = require("../../integration/debt_bridge/from_maker/full/helpers/services/providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB");
const getABI = require("../../helpers/services/getABI");
async function setupFullRefinanceMakerToMakerWithVaultBCreation() {
const wallets = await getWallets();
const contracts = await getContracts();
const constants = await getConstants();
const constants = await getDebtBridgeFromMakerConstants();
//#region Mock
contracts.mockGelatoExecutor = await getMockGelato();
contracts.mockGelatoExecutor = await getMockGelatoExecutor();
//#endregion Mock

View File

@ -2,9 +2,9 @@ const { expect } = require("chai");
const hre = require("hardhat");
const { ethers } = hre;
const InstaAccount = require("../../../pre-compiles/InstaAccount.json");
const InstaAccount = require("../../../../pre-compiles/InstaAccount.json");
async function createDSA(userAddress, instaIndex, instaList) {
module.exports = async function (userAddress, instaIndex, instaList) {
//#region User create a DeFi Smart Account
// User create a Instadapp DeFi Smart Account
@ -30,6 +30,4 @@ async function createDSA(userAddress, instaIndex, instaList) {
return dsa;
//#endregion
}
module.exports = createDSA;
};

View File

@ -1,10 +1,8 @@
async function getRoute(token, tokenDebtToMove, instaPoolResolver) {
module.exports = async function (token, tokenDebtToMove, instaPoolResolver) {
const rData = await instaPoolResolver.getTokenLimit(token);
if (rData.dydx > tokenDebtToMove) return 0;
if (rData.maker > tokenDebtToMove) return 1;
if (rData.compound > tokenDebtToMove) return 2;
if (rData.aave > tokenDebtToMove) return 3;
}
module.exports = getRoute;
};

View File

@ -1,6 +1,6 @@
const { expect } = require("chai");
async function addProviderModuleDSA(
module.exports = async function (
gelatoProviderWallet,
gelatoCore,
dsaProviderModuleAddr
@ -26,6 +26,4 @@ async function addProviderModuleDSA(
).to.be.true;
//#endregion
}
module.exports = addProviderModuleDSA;
};

View File

@ -1,6 +1,6 @@
const { expect } = require("chai");
async function provideFunds(
module.exports = async function (
gelatoProviderWallet,
gelatoCore,
gasLimit,
@ -33,6 +33,4 @@ async function provideFunds(
);
//#endregion
}
module.exports = provideFunds;
};

View File

@ -1,6 +1,6 @@
const { expect } = require("chai");
async function providerAssignsExecutor(
module.exports = async function (
gelatoProviderWallet,
gelatoExecutorAddress,
gelatoCore
@ -23,6 +23,4 @@ async function providerAssignsExecutor(
).to.be.equal(gelatoExecutorAddress);
//#endregion
}
module.exports = providerAssignsExecutor;
};

View File

@ -1,6 +1,6 @@
const { expect } = require("chai");
async function stakeExecutor(gelatoExecutorWallet, gelatoCore) {
module.exports = async function (gelatoExecutorWallet, gelatoCore) {
//#region Executor Stake on Gelato
// For task execution provider will ask a executor to watch the
@ -20,6 +20,4 @@ async function stakeExecutor(gelatoExecutorWallet, gelatoCore) {
.true;
//#endregion
}
module.exports = stakeExecutor;
};

View File

@ -2,11 +2,9 @@ const ConnectGelatoABI = require("../../../pre-compiles/ConnectGelato.json")
.abi;
const ConnectAuthABI = require("../../../pre-compiles/ConnectAuth.json").abi;
function getABI() {
module.exports = function () {
return {
ConnectGelatoABI: ConnectGelatoABI,
ConnectAuthABI: ConnectAuthABI,
};
}
module.exports = getABI;
};

View File

@ -19,7 +19,7 @@ const CompoundResolver = require("../../../pre-compiles/InstaCompoundResolver.js
const DsaProviderModuleABI = require("../../../pre-compiles/ProviderModuleDsa_ABI.json");
const InstaPoolResolver = require("../../../artifacts/contracts/interfaces/InstaDapp/resolvers/IInstaPoolResolver.sol/IInstaPoolResolver.json");
async function getContracts() {
module.exports = async function () {
const instaMaster = await ethers.provider.getSigner(
hre.network.config.InstaMaster
);
@ -134,6 +134,4 @@ async function getContracts() {
dsaProviderModule,
conditionDebtBridgeIsAffordable,
};
}
module.exports = getContracts;
};

View File

@ -2,7 +2,7 @@ const { expect } = require("chai");
const hre = require("hardhat");
const { ethers } = hre;
async function getWallets() {
module.exports = async function () {
let userWallet;
let userAddress;
let gelatoProviderWallet;
@ -30,6 +30,4 @@ async function getWallets() {
gelatoExecutorWallet: gelatoExecutorWallet,
gelatoExecutorAddress: gelatoExecutorAddress,
};
}
module.exports = getWallets;
};

View File

@ -2,7 +2,7 @@ const { expect } = require("chai");
const hre = require("hardhat");
const { ethers } = hre;
async function addETHBGemJoinMapping(userWallet, instaMapping, instaMaster) {
module.exports = async function (userWallet, instaMapping, instaMaster) {
await userWallet.sendTransaction({
to: hre.network.config.InstaMaster,
value: ethers.utils.parseEther("0.1"),
@ -22,6 +22,4 @@ async function addETHBGemJoinMapping(userWallet, instaMapping, instaMaster) {
method: "hardhat_stopImpersonatingAccount",
params: [await instaMaster.getAddress()],
});
}
module.exports = addETHBGemJoinMapping;
};

View File

@ -1,9 +1,9 @@
const { expect } = require("chai");
const hre = require("hardhat");
const ConnectMaker = require("../../../pre-compiles/ConnectMaker.json");
const ConnectMaker = require("../../../../pre-compiles/ConnectMaker.json");
async function createVaultForETHB(
module.exports = async function (
userAddress,
DAI,
dsa,
@ -30,6 +30,4 @@ async function createVaultForETHB(
//#endregion
return vaultId;
}
module.exports = createVaultForETHB;
};

View File

@ -1,9 +1,9 @@
const { expect } = require("chai");
const hre = require("hardhat");
const ConnectMaker = require("../../../pre-compiles/ConnectMaker.json");
const ConnectMaker = require("../../../../pre-compiles/ConnectMaker.json");
async function initializeMakerCdp(
module.exports = async function (
userAddress,
DAI,
dsa,
@ -61,6 +61,4 @@ async function initializeMakerCdp(
//#endregion
return vaultId;
}
module.exports = initializeMakerCdp;
};

View File

@ -10,13 +10,13 @@ const GelatoCoreLib = require("@gelatonetwork/core");
const ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
// Contracts
const InstaIndex = require("../pre-compiles/InstaIndex.json");
const InstaList = require("../pre-compiles/InstaList.json");
const InstaConnectors = require("../pre-compiles/InstaConnectors.json");
const InstaAccount = require("../pre-compiles/InstaAccount.json");
const ConnectAuth = require("../pre-compiles/ConnectAuth.json");
const ConnectBasic = require("../pre-compiles/ConnectBasic.json");
const ProviderModuleDsa_ABI = require("../pre-compiles/ProviderModuleDsa_ABI.json");
const InstaIndex = require("../../pre-compiles/InstaIndex.json");
const InstaList = require("../../pre-compiles/InstaList.json");
const InstaConnectors = require("../../pre-compiles/InstaConnectors.json");
const InstaAccount = require("../../pre-compiles/InstaAccount.json");
const ConnectAuth = require("../../pre-compiles/ConnectAuth.json");
const ConnectBasic = require("../../pre-compiles/ConnectBasic.json");
const ProviderModuleDsa_ABI = require("../../pre-compiles/ProviderModuleDsa_ABI.json");
describe("DSA setup with Gelato Tests", function () {
this.timeout(50000);

View File

@ -5,7 +5,7 @@ const { deployments, ethers } = hre;
const GelatoCoreLib = require("@gelatonetwork/core");
const setupFullRefinanceMakerToCompound = require("./helpers/setupFullRefinanceMakerToCompound");
const getRoute = require("./helpers/services/getRoute");
const getInstaPoolV2Route = require("../../../../helpers/services/InstaDapp/getInstaPoolV2Route");
const getGasCostForFullRefinance = require("./helpers/services/getGasCostForFullRefinance");
// This test showcases how to submit a task refinancing a Users debt position from
@ -199,7 +199,7 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function ()
vaultId
);
const route = await getRoute(
const route = await getInstaPoolV2Route(
contracts.DAI.address,
debtOnMakerBefore,
contracts.instaPoolResolver

View File

@ -4,7 +4,7 @@ const { deployments, ethers } = hre;
const GelatoCoreLib = require("@gelatonetwork/core");
const setupFullRefinanceMakerToMaker = require("./helpers/setupFullRefinanceMakerToMaker");
const getRoute = require("./helpers/services/getRoute");
const getInstaPoolV2Route = require("../../../../helpers/services/InstaDapp/getInstaPoolV2Route");
const getGasCostForFullRefinance = require("./helpers/services/getGasCostForFullRefinance");
// This test showcases how to submit a task refinancing a Users debt position from
@ -201,7 +201,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat
vaultAId
);
const route = await getRoute(
const route = await getInstaPoolV2Route(
contracts.DAI.address,
debtOnMakerBefore,
contracts.instaPoolResolver

View File

@ -4,7 +4,7 @@ const { deployments, ethers } = hre;
const GelatoCoreLib = require("@gelatonetwork/core");
const setupFullRefinanceMakerToMakerWithVaultBCreation = require("./helpers/setupFullRefinanceMakerToMakerWithVaultBCreation");
const getRoute = require("./helpers/services/getRoute");
const getInstaPoolV2Route = require("../../../../helpers/services/InstaDapp/getInstaPoolV2Route");
const getGasCostForFullRefinance = require("./helpers/services/getGasCostForFullRefinance");
// This test showcases how to submit a task refinancing a Users debt position from
@ -201,7 +201,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () {
vaultAId
);
const route = await getRoute(
const route = await getInstaPoolV2Route(
contracts.DAI.address,
debtOnMakerBefore,
contracts.instaPoolResolver

View File

@ -1,4 +1,4 @@
async function getGasCostForFullRefinance(route) {
module.exports = async function (route) {
switch (route) {
case 0:
return 2519000; // 2290000 * 1,1 // gas left method measure : 2290000 - 2106637 = 183363 | gas reporter : 2290000 - 1789126 = 500874
@ -11,6 +11,4 @@ async function getGasCostForFullRefinance(route) {
default:
break;
}
}
module.exports = getGasCostForFullRefinance;
};

View File

@ -4,12 +4,7 @@ const { deployments, ethers } = hre;
const GelatoCoreLib = require("@gelatonetwork/core");
// Instadapp UI should do the same implementation for submitting debt bridge task
async function providerWhiteListTaskForMakerETHAToMakerETHB(
wallets,
contracts,
constants,
vaultId
) {
module.exports = async function (wallets, contracts, constants, vaultId) {
//#region Step 9 Provider should whitelist task
// By WhiteList task, the provider can constrain the type
@ -75,6 +70,4 @@ async function providerWhiteListTaskForMakerETHAToMakerETHB(
//#endregion
return spells;
}
module.exports = providerWhiteListTaskForMakerETHAToMakerETHB;
};

View File

@ -4,7 +4,7 @@ const { deployments, ethers } = hre;
const GelatoCoreLib = require("@gelatonetwork/core");
// Instadapp UI should do the same implementation for submitting debt bridge task
async function providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB(
module.exports = async function (
wallets,
contracts,
constants,
@ -76,6 +76,4 @@ async function providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB(
//#endregion
return spells;
}
module.exports = providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB;
};

View File

@ -4,12 +4,7 @@ const { ethers, deployments } = hre;
const GelatoCoreLib = require("@gelatonetwork/core");
// Instadapp UI should do the same implementation for submitting debt bridge task
async function providerWhiteListTaskForMakerToCompound(
wallets,
contracts,
constants,
vaultId
) {
module.exports = async function (wallets, contracts, constants, vaultId) {
//#region Step 9 Provider should whitelist task
// By WhiteList task, the provider can constrain the type
@ -75,6 +70,4 @@ async function providerWhiteListTaskForMakerToCompound(
//#endregion
return spells;
}
module.exports = providerWhiteListTaskForMakerToCompound;
};

View File

@ -1,19 +1,19 @@
const getWallets = require("./services/getWallets");
const getConstants = require("./services/getConstants");
const getContracts = require("./services/getContracts");
const stakeExecutor = require("./services/stakeExecutor");
const provideFunds = require("./services/provideFunds");
const providerAssignsExecutor = require("./services/providerAssignsExecutor");
const addProviderModuleDSA = require("./services/addProviderModuleDSA");
const createDSA = require("./services/createDSA");
const initializeMakerCdp = require("./services/initializeMakerCdp");
const getWallets = require("../../../../../helpers/services/getWallets");
const getDebtBridgeFromMakerConstants = require("../../services/getDebtBridgeFromMakerConstants");
const getContracts = require("../../../../../helpers/services/getContracts");
const stakeExecutor = require("../../../../../helpers/services/gelato/stakeExecutor");
const provideFunds = require("../../../../../helpers/services/gelato/provideFunds");
const providerAssignsExecutor = require("../../../../../helpers/services/gelato/providerAssignsExecutor");
const addProviderModuleDSA = require("../../../../../helpers/services/gelato/addProviderModuleDSA");
const createDSA = require("../../../../../helpers/services/InstaDapp/createDSA");
const initializeMakerCdp = require("../../../../../helpers/services/maker/initializeMakerCdp");
const providerWhiteListTaskForMakerToCompound = require("./services/providerWhiteListTaskForMakerToCompound");
const getABI = require("./services/getABI");
const getABI = require("../../../../../helpers/services/getABI");
async function setupFullRefinanceMakerToCompound() {
module.exports = async function () {
const wallets = await getWallets();
const contracts = await getContracts();
const constants = await getConstants();
const constants = await getDebtBridgeFromMakerConstants();
// Gelato Testing environment setup.
await stakeExecutor(wallets.gelatoExecutorWallet, contracts.gelatoCore);
@ -65,6 +65,4 @@ async function setupFullRefinanceMakerToCompound() {
spells,
ABI,
};
}
module.exports = setupFullRefinanceMakerToCompound;
};

View File

@ -1,20 +1,20 @@
const getWallets = require("./services/getWallets");
const getContracts = require("./services/getContracts");
const getConstants = require("./services/getConstants");
const stakeExecutor = require("./services/stakeExecutor");
const provideFunds = require("./services/provideFunds");
const providerAssignsExecutor = require("./services/providerAssignsExecutor");
const addProviderModuleDSA = require("./services/addProviderModuleDSA");
const createDSA = require("./services/createDSA");
const addETHBGemJoinMapping = require("./services/addETHBGemJoinMapping");
const initializeMakerCdp = require("./services/initializeMakerCdp");
const getWallets = require("../../../../../helpers/services/getWallets");
const getContracts = require("../../../../../helpers/services/getContracts");
const getDebtBridgeFromMakerConstants = require("../../services/getDebtBridgeFromMakerConstants");
const stakeExecutor = require("../../../../../helpers/services/gelato/stakeExecutor");
const provideFunds = require("../../../../../helpers/services/gelato/provideFunds");
const providerAssignsExecutor = require("../../../../../helpers/services/gelato/providerAssignsExecutor");
const addProviderModuleDSA = require("../../../../../helpers/services/gelato/addProviderModuleDSA");
const createDSA = require("../../../../../helpers/services/InstaDapp/createDSA");
const addETHBGemJoinMapping = require("../../../../../helpers/services/maker/addETHBGemJoinMapping");
const initializeMakerCdp = require("../../../../../helpers/services/maker/initializeMakerCdp");
const providerWhiteListTaskForMakerETHAToMakerETHB = require("./services/providerWhiteListTaskForMakerETHAToMakerETHB");
const getABI = require("./services/getABI");
const getABI = require("../../../../../helpers/services/getABI");
async function setupFullRefinanceMakerToMaker() {
module.exports = async function () {
const wallets = await getWallets();
const contracts = await getContracts();
const constants = await getConstants();
const constants = await getDebtBridgeFromMakerConstants();
// Gelato Testing environment setup.
await stakeExecutor(wallets.gelatoExecutorWallet, contracts.gelatoCore);
@ -71,6 +71,4 @@ async function setupFullRefinanceMakerToMaker() {
spells,
ABI,
};
}
module.exports = setupFullRefinanceMakerToMaker;
};

View File

@ -1,21 +1,21 @@
const getWallets = require("./services/getWallets");
const getContracts = require("./services/getContracts");
const getConstants = require("./services/getConstants");
const stakeExecutor = require("./services/stakeExecutor");
const provideFunds = require("./services/provideFunds");
const providerAssignsExecutor = require("./services/providerAssignsExecutor");
const addProviderModuleDSA = require("./services/addProviderModuleDSA");
const createDSA = require("./services/createDSA");
const addETHBGemJoinMapping = require("./services/addETHBGemJoinMapping");
const initializeMakerCdp = require("./services/initializeMakerCdp");
const createVaultForETHB = require("./services/createVaultForETHB");
const getWallets = require("../../../../../helpers/services/getWallets");
const getContracts = require("../../../../../helpers/services/getContracts");
const getDebtBridgeFromMakerConstants = require("../../services/getDebtBridgeFromMakerConstants");
const stakeExecutor = require("../../../../../helpers/services/gelato/stakeExecutor");
const provideFunds = require("../../../../../helpers/services/gelato/provideFunds");
const providerAssignsExecutor = require("../../../../../helpers/services/gelato/providerAssignsExecutor");
const addProviderModuleDSA = require("../../../../../helpers/services/gelato/addProviderModuleDSA");
const createDSA = require("../../../../../helpers/services/InstaDapp/createDSA");
const addETHBGemJoinMapping = require("../../../../../helpers/services/maker/addETHBGemJoinMapping");
const initializeMakerCdp = require("../../../../../helpers/services/maker/initializeMakerCdp");
const createVaultForETHB = require("../../../../../helpers/services/maker/createVaultForETHB");
const providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB = require("./services/providerWhiteListTaskForMakerETHAToMakerETHBWithVaultB");
const getABI = require("./services/getABI");
const getABI = require("../../../../../helpers/services/getABI");
async function setupFullRefinanceMakerToMakerWithVaultBCreation() {
module.exports = async function () {
const wallets = await getWallets();
const contracts = await getContracts();
const constants = await getConstants();
const constants = await getDebtBridgeFromMakerConstants();
// Gelato Testing environment setup.
await stakeExecutor(wallets.gelatoExecutorWallet, contracts.gelatoCore);
@ -80,6 +80,4 @@ async function setupFullRefinanceMakerToMakerWithVaultBCreation() {
spells,
ABI,
};
}
module.exports = setupFullRefinanceMakerToMakerWithVaultBCreation;
};

View File

@ -0,0 +1,935 @@
// const { expect } = require("chai");
// const hre = require("hardhat");
// const { deployments, ethers } = hre;
// const GelatoCoreLib = require("@gelatonetwork/core");
// // #region Contracts ABI and Constants
// const InstaIndex = require("../../../../pre-compiles/InstaIndex.json");
// const InstaList = require("../../../../pre-compiles/InstaList.json");
// const InstaAccount = require("../../../../pre-compiles/InstaAccount.json");
// const ConnectGelato = require("../../../../pre-compiles/ConnectGelato.json");
// const ConnectMaker = require("../../../../pre-compiles/ConnectMaker.json");
// const ConnectCompound = require("../../../../pre-compiles/ConnectCompound.json");
// const ConnectInstaPool = require("../../../../pre-compiles/ConnectInstaPool.json");
// const ConnectAuth = require("../../../../pre-compiles/ConnectAuth.json");
// const ConnectGelatoFullDebtBridgeFromMakerABI = require("../artifacts/contracts/contracts/connectors/ConnectGelatoPartialDebtBridgeFromMaker.sol/ConnectGelatoPartialDebtBridgeFromMaker.json")
// .abi;
// const ConnectGelatoProviderPaymentABI = require("../../../../artifacts/contracts/contracts/connectors/ConnectGelatoProviderPayment.sol/ConnectGelatoProviderPayment.json")
// .abi;
// const InstaConnector = require("../../../../pre-compiles/InstaConnectors.json");
// const DssCdpManager = require("../../../../pre-compiles/DssCdpManager.json");
// const GetCdps = require("../../../../pre-compiles/GetCdps.json");
// const IERC20 = require("../../../../pre-compiles/IERC20.json");
// const CTokenInterface = require("../../../../pre-compiles/CTokenInterface.json");
// const CompoundResolver = require("../../../../pre-compiles/InstaCompoundResolver.json");
// const ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
// const GAS_LIMIT = "4000000";
// const GAS_PRICE_CEIL = ethers.utils.parseUnits("1000", "gwei");
// const WAD = ethers.utils.parseUnits("1", 18);
// // const ORACLE_MAKER_ETH_USD = "ETH/USD-Maker-v1";
// // const ORACLE_MAKER_ETH_USD_ADDR = "0x729D19f657BD0614b4985Cf1D82531c67569197B";
// // const PRICE_ORACLE_MAKER_PAYLOAD = "0x57de26a4"; // IMakerOracle.read()
// const MIN_COL_RATIO_MAKER = ethers.utils.parseUnits("3", 18);
// const MIN_COL_RATIO_B = ethers.utils.parseUnits("19", 17);
// // TO DO: make dynamic based on real time Collateral Price and Ratios
// const MAKER_INITIAL_ETH = ethers.utils.parseEther("10");
// const MAKER_INITIAL_DEBT = ethers.utils.parseUnits("1000", 18);
// // #endregion
// //#region Mock Math Function
// function wdiv(x, y) {
// return x.mul(WAD).add(y.div(2)).div(y);
// }
// function wmul(x, y) {
// return x.mul(y).add(WAD.div(2)).div(WAD);
// }
// function wCalcCollateralToWithdraw(
// minColRatioOnMaker,
// minColRatioOnPositionB,
// collateralPrice,
// pricedCollateral,
// daiDebtOnMaker
// ) {
// //#region CALCULATION REPLICATION
// let expectedColToWithdraw = wmul(
// wmul(minColRatioOnMaker, minColRatioOnPositionB),
// daiDebtOnMaker
// ); // doc ref : c_r x comp_r x d_2
// expectedColToWithdraw = expectedColToWithdraw.sub(
// wmul(minColRatioOnMaker, pricedCollateral)
// ); // doc ref : c_r x comp_r x d_2 - c_r x e_2
// expectedColToWithdraw = wdiv(
// expectedColToWithdraw,
// minColRatioOnPositionB.sub(minColRatioOnMaker)
// ); // doc ref : (c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r)
// expectedColToWithdraw = pricedCollateral.sub(expectedColToWithdraw); // doc ref : e_2 - ((c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r))
// // Extra step to convert back to col type
// expectedColToWithdraw = wdiv(expectedColToWithdraw, collateralPrice);
// //#endregion
// return expectedColToWithdraw;
// }
// function wCalcDebtToRepay(
// minColRatioOnMaker,
// minColRatioOnPositionB,
// pricedCollateral,
// daiDebtOnMaker
// ) {
// //#region CALCULATION REPLICATION
// let expectedBorToPayBack = wmul(
// wmul(minColRatioOnMaker, minColRatioOnPositionB),
// daiDebtOnMaker
// ); // doc ref : c_r x comp_r x d_2
// expectedBorToPayBack = expectedBorToPayBack.sub(
// wmul(minColRatioOnMaker, pricedCollateral)
// ); // doc ref : c_r x comp_r x d_2 - c_r x e_2
// expectedBorToPayBack = wdiv(
// expectedBorToPayBack,
// minColRatioOnPositionB.sub(minColRatioOnMaker)
// ); // doc ref : (c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r)
// expectedBorToPayBack = wmul(
// wdiv(ethers.utils.parseUnits("1", 18), minColRatioOnMaker),
// expectedBorToPayBack
// ); // doc ref : (1/c_r)((c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r))
// expectedBorToPayBack = daiDebtOnMaker.sub(expectedBorToPayBack); // doc ref : d_2 - (1/c_r)((c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r))
// //#endregion
// return expectedBorToPayBack;
// }
// //#endregion
// describe("Debt Bridge with External Provider", function () {
// this.timeout(0);
// if (hre.network.name !== "hardhat") {
// console.error("Test Suite is meant to be run on hardhat only");
// process.exit(1);
// }
// // Wallet to use for local testing
// let userWallet;
// let userAddress;
// let gelatoProviderWallet;
// let gelatoProviderAddress;
// let gelatoExecutorWallet;
// let gelatoExecutorAddress;
// // Deployed instances
// let connectGelato;
// let connectMaker;
// let connectInstaPool;
// let connectCompound;
// let instaIndex;
// let instaList;
// let dssCdpManager;
// let getCdps;
// let DAI;
// let gelatoCore;
// let cDaiToken;
// let cEthToken;
// let instaMaster;
// let instaConnectors;
// let compoundResolver;
// // Contracts to deploy and use for local testing
// let conditionMakerVaultUnsafe;
// let connectGelatoPartialDebtBridgeFromMaker;
// let connectGelatoProviderPayment;
// let priceOracleResolver;
// let dsaProviderModule;
// // Creation during test
// let dsa;
// // Payload Params for ConnectGelatoPartialDebtBridgeFromMaker and ConditionMakerVaultUnsafe
// let vaultId;
// // For TaskSpec and for Task
// let spells = [];
// before(async function () {
// // Get Test Wallet for local testnet
// [
// userWallet,
// gelatoProviderWallet,
// gelatoExecutorWallet,
// ] = await ethers.getSigners();
// userAddress = await userWallet.getAddress();
// gelatoProviderAddress = await gelatoProviderWallet.getAddress();
// gelatoExecutorAddress = await gelatoExecutorWallet.getAddress();
// instaMaster = await ethers.provider.getSigner(
// hre.network.config.InstaMaster
// );
// // Hardhat default accounts prefilled with 100 ETH
// expect(await userWallet.getBalance()).to.be.gt(
// ethers.utils.parseEther("10")
// );
// // ===== Get Deployed Contract Instance ==================
// instaIndex = await ethers.getContractAt(
// InstaIndex.abi,
// hre.network.config.InstaIndex
// );
// instaList = await ethers.getContractAt(
// InstaList.abi,
// hre.network.config.InstaList
// );
// connectGelato = await ethers.getContractAt(
// ConnectGelato.abi,
// hre.network.config.ConnectGelato
// );
// connectMaker = await ethers.getContractAt(
// ConnectMaker.abi,
// hre.network.config.ConnectMaker
// );
// connectInstaPool = await ethers.getContractAt(
// ConnectInstaPool.abi,
// hre.network.config.ConnectInstaPool
// );
// connectCompound = await ethers.getContractAt(
// ConnectCompound.abi,
// hre.network.config.ConnectCompound
// );
// dssCdpManager = await ethers.getContractAt(
// DssCdpManager.abi,
// hre.network.config.DssCdpManager
// );
// getCdps = await ethers.getContractAt(
// GetCdps.abi,
// hre.network.config.GetCdps
// );
// DAI = await ethers.getContractAt(IERC20.abi, hre.network.config.DAI);
// gelatoCore = await ethers.getContractAt(
// GelatoCoreLib.GelatoCore.abi,
// hre.network.config.GelatoCore
// );
// cDaiToken = await ethers.getContractAt(
// CTokenInterface.abi,
// hre.network.config.CDAI
// );
// cEthToken = await ethers.getContractAt(
// CTokenInterface.abi,
// hre.network.config.CETH
// );
// instaConnectors = await ethers.getContractAt(
// InstaConnector.abi,
// hre.network.config.InstaConnectors
// );
// compoundResolver = await ethers.getContractAt(
// CompoundResolver.abi,
// hre.network.config.CompoundResolver
// );
// // instaEvent = await ethers.getContractAt(
// // InstaEvent.abi,
// // hre.network.config.InstaEvent
// // )
// // ===== Deploy Needed Contract ==================
// const PriceOracleResolver = await ethers.getContractFactory(
// "PriceOracleResolver"
// );
// priceOracleResolver = await PriceOracleResolver.deploy();
// await priceOracleResolver.deployed();
// const ConditionMakerVaultUnsafe = await ethers.getContractFactory(
// "ConditionMakerVaultUnsafe"
// );
// conditionMakerVaultUnsafe = await ConditionMakerVaultUnsafe.deploy();
// await conditionMakerVaultUnsafe.deployed();
// const ConnectGelatoPartialDebtBridgeFromMaker = await ethers.getContractFactory(
// "ConnectGelatoPartialDebtBridgeFromMaker"
// );
// connectGelatoPartialDebtBridgeFromMaker = await ConnectGelatoPartialDebtBridgeFromMaker.deploy(
// (await instaConnectors.connectorLength()).add(1)
// );
// await connectGelatoPartialDebtBridgeFromMaker.deployed();
// const ConnectGelatoProviderPayment = await ethers.getContractFactory(
// "ConnectGelatoProviderPayment"
// );
// connectGelatoProviderPayment = await ConnectGelatoProviderPayment.deploy(
// (await instaConnectors.connectorLength()).add(2)
// );
// await connectGelatoProviderPayment.deployed();
// const ProviderModuleDsa = await ethers.getContractFactory(
// "ProviderModuleDsa"
// );
// dsaProviderModule = await ProviderModuleDsa.deploy(
// hre.network.config.GelatoCore,
// connectGelatoProviderPayment.address
// );
// await dsaProviderModule.deployed();
// ///////////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////// After Contracts Deployement : Setup ///////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////////
// // Gelato Testing environment setup.
// // Step 1 : Add EUR/USD Maker Medianizer in the PriceOracleResolver
// // Step 2 : Enable Debt Bridge Connector and Gelato Provider Payment Connector
// // Step 3 : Executor Staking on Gelato
// // Step 4 : Provider put some fund on gelato for paying future tasks executions
// // Step 5 : Provider choose a executor
// // Step 6 : Provider will add a module
// // Step 7 : User create a DeFi Smart Account
// // Step 8 : User open a Vault, put some ether on it and borrow some dai
// // Step 9 : User give authorization to gelato to use his DSA on his behalf.
// // Step 10 : Provider should whitelist task
// //#region Step 1 Add EUR/USD Maker Medianizer in the PriceOracleResolver
// // PriceOracleResolver is a price feeder aggregator
// // You will be able to query price from multiple source through this aggregator
// // For the demo we add the ETH/USD Medianizer to the aggregator
// // MakerDAO price oracle are called Medianizer
// // await priceOracleResolver.addOracle(
// // ORACLE_MAKER_ETH_USD,
// // ORACLE_MAKER_ETH_USD_ADDR,
// // PRICE_ORACLE_MAKER_PAYLOAD
// // );
// //#endregion
// //#region Step 2 Enable Debt Bridge Connector and Gelato Provider Payment Connector
// // Debt Bridge Connector is used during refinancing of debt
// // This Connect help the user to split a position in one protocol.
// // to 2 protocol in a safe way. Both debt position will be safe.
// // Gelato Provider Payment Connector is used for paying the provider
// // for task execution. So when futur task will be executed, through a self financing
// // transaction (user will pay during the execution of the task) task will
// // be executed. Improvind user experience.
// await userWallet.sendTransaction({
// to: hre.network.config.InstaMaster,
// value: ethers.utils.parseEther("0.1"),
// });
// await hre.network.provider.request({
// method: "hardhat_impersonateAccount",
// params: [await instaMaster.getAddress()],
// });
// await instaConnectors
// .connect(instaMaster)
// .enable(connectGelatoPartialDebtBridgeFromMaker.address);
// await instaConnectors
// .connect(instaMaster)
// .enable(connectGelatoProviderPayment.address);
// await hre.network.provider.request({
// method: "hardhat_stopImpersonatingAccount",
// params: [await instaMaster.getAddress()],
// });
// expect(
// await instaConnectors.isConnector([
// connectGelatoPartialDebtBridgeFromMaker.address,
// ])
// ).to.be.true;
// expect(
// await instaConnectors.isConnector([connectGelatoProviderPayment.address])
// ).to.be.true;
// //#endregion
// //#region Step 3 Executor Staking on Gelato
// // For task execution provider will ask a executor to watch the
// // blockchain for possible execution autorization given by
// // the condition that user choose when submitting the task.
// // And if all condition are meet executor will execute the task.
// // For safety measure Gelato ask the executor to stake a minimum
// // amount.
// await gelatoCore.connect(gelatoExecutorWallet).stakeExecutor({
// value: await gelatoCore.minExecutorStake(),
// });
// expect(
// await gelatoCore.isExecutorMinStaked(gelatoExecutorAddress)
// ).to.be.true;
// //#endregion
// //#region Step 4 Provider put some fund on gelato for paying future tasks executions
// // Provider put some funds in gelato system for paying the
// // Executor when this one will execute task on behalf of the
// // Provider. At each provider's task execution, some funds (approximatively
// // the gas cost value) will be transfered to the Executor stake.
// const TASK_AUTOMATION_FUNDS = await gelatoCore.minExecProviderFunds(
// GAS_LIMIT,
// GAS_PRICE_CEIL
// );
// await expect(
// gelatoCore
// .connect(gelatoProviderWallet)
// .provideFunds(gelatoProviderAddress, {
// value: TASK_AUTOMATION_FUNDS,
// })
// ).to.emit(gelatoCore, "LogFundsProvided");
// expect(await gelatoCore.providerFunds(gelatoProviderAddress)).to.be.equal(
// TASK_AUTOMATION_FUNDS
// );
// //#endregion
// //#region Step 5 Provider choose a executor
// // Provider choose a executor who will execute futur task
// // for the provider, it will be compensated by the provider.
// await expect(
// gelatoCore
// .connect(gelatoProviderWallet)
// .providerAssignsExecutor(gelatoExecutorAddress)
// ).to.emit(gelatoCore, "LogProviderAssignedExecutor");
// expect(
// await gelatoCore.executorByProvider(gelatoProviderAddress)
// ).to.be.equal(gelatoExecutorAddress);
// //#endregion
// //#region Step 6 Provider will add a module
// // By adding a module the provider will format future task's
// // payload by adding some specificity like his address to the
// // Payment connector for receiving payment of User.
// await expect(
// gelatoCore
// .connect(gelatoProviderWallet)
// .addProviderModules([dsaProviderModule.address])
// ).to.emit(gelatoCore, "LogProviderModuleAdded");
// expect(
// await gelatoCore
// .connect(gelatoProviderWallet)
// .isModuleProvided(gelatoProviderAddress, dsaProviderModule.address)
// ).to.be.true;
// //#endregion
// //#region Step 7 User create a DeFi Smart Account
// // User create a Instadapp DeFi Smart Account
// // who give him the possibility to interact
// // with a large list of DeFi protocol through one
// // Proxy account.
// const dsaAccountCount = await instaList.accounts();
// await expect(instaIndex.build(userAddress, 1, userAddress)).to.emit(
// instaIndex,
// "LogAccountCreated"
// );
// const dsaID = dsaAccountCount.add(1);
// await expect(await instaList.accounts()).to.be.equal(dsaID);
// // Instantiate the DSA
// dsa = await ethers.getContractAt(
// InstaAccount.abi,
// await instaList.accountAddr(dsaID)
// );
// //#endregion
// //#region Step 8 User open a Vault, put some ether on it and borrow some dai
// // User open a maker vault
// // He deposit 10 Eth on it
// // He borrow a 1000 DAI
// const openVault = await hre.run("abi-encode-withselector", {
// abi: ConnectMaker.abi,
// functionname: "open",
// inputs: ["ETH-A"],
// });
// await dsa.cast([hre.network.config.ConnectMaker], [openVault], userAddress);
// const cdps = await getCdps.getCdpsAsc(dssCdpManager.address, dsa.address);
// vaultId = String(cdps.ids[0]);
// expect(cdps.ids[0].isZero()).to.be.false;
// await dsa.cast(
// [hre.network.config.ConnectMaker],
// [
// await hre.run("abi-encode-withselector", {
// abi: ConnectMaker.abi,
// functionname: "deposit",
// inputs: [vaultId, MAKER_INITIAL_ETH, 0, 0],
// }),
// ],
// userAddress,
// {
// value: MAKER_INITIAL_ETH,
// }
// );
// await dsa.cast(
// [hre.network.config.ConnectMaker],
// [
// await hre.run("abi-encode-withselector", {
// abi: ConnectMaker.abi,
// functionname: "borrow",
// inputs: [vaultId, MAKER_INITIAL_DEBT, 0, 0],
// }),
// ],
// userAddress
// );
// expect(await DAI.balanceOf(dsa.address)).to.be.equal(MAKER_INITIAL_DEBT);
// //#endregion
// //#region Step 9 User give authorization to gelato to use his DSA on his behalf.
// // Instadapp DSA contract give the possibility to the user to delegate
// // action by giving authorization.
// // In this case user give authorization to gelato to execute
// // task for him if needed.
// await dsa.cast(
// [hre.network.config.ConnectAuth],
// [
// await hre.run("abi-encode-withselector", {
// abi: ConnectAuth.abi,
// functionname: "add",
// inputs: [gelatoCore.address],
// }),
// ],
// userAddress
// );
// expect(await dsa.isAuth(gelatoCore.address)).to.be.true;
// //#endregion
// //#region Step 10 Provider should whitelist task
// // By WhiteList task, the provider can constrain the type
// // of task the user can submitting.
// //#region Actions
// const debtBridgeCalculation = new GelatoCoreLib.Action({
// addr: connectGelatoPartialDebtBridgeFromMaker.address,
// data: await hre.run("abi-encode-withselector", {
// abi: ConnectGelatoFullDebtBridgeFromMakerABI,
// functionname: "savePartialRefinanceDataToMemory",
// inputs: [
// vaultId,
// MIN_COL_RATIO_MAKER,
// MIN_COL_RATIO_B,
// priceOracleResolver.address,
// await hre.run("abi-encode-withselector", {
// abi: (await deployments.getArtifcat("PriceOracleResolver")).abi,
// functionname: "getMockPrice",
// inputs: [userAddress],
// }),
// 0,
// 0,
// ],
// }),
// operation: GelatoCoreLib.Operation.Delegatecall,
// });
// spells.push(debtBridgeCalculation);
// const flashBorrow = new GelatoCoreLib.Action({
// addr: connectInstaPool.address,
// data: await hre.run("abi-encode-withselector", {
// abi: ConnectInstaPool.abi,
// functionname: "flashBorrow",
// inputs: [hre.network.config.DAI, 0, "600", 0],
// }),
// operation: GelatoCoreLib.Operation.Delegatecall,
// });
// spells.push(flashBorrow);
// const paybackMaker = new GelatoCoreLib.Action({
// addr: connectMaker.address,
// data: await hre.run("abi-encode-withselector", {
// abi: ConnectMaker.abi,
// functionname: "payback",
// inputs: [vaultId, 0, "601", 0],
// }),
// operation: GelatoCoreLib.Operation.Delegatecall,
// });
// spells.push(paybackMaker);
// const withdrawMaker = new GelatoCoreLib.Action({
// addr: connectMaker.address,
// data: await hre.run("abi-encode-withselector", {
// abi: ConnectMaker.abi,
// functionname: "withdraw",
// inputs: [vaultId, 0, "602", 0],
// }),
// operation: GelatoCoreLib.Operation.Delegatecall,
// });
// spells.push(withdrawMaker);
// const depositCompound = new GelatoCoreLib.Action({
// addr: connectCompound.address,
// data: await hre.run("abi-encode-withselector", {
// abi: ConnectCompound.abi,
// functionname: "deposit",
// inputs: [ETH, 0, "603", 0],
// }),
// operation: GelatoCoreLib.Operation.Delegatecall,
// });
// spells.push(depositCompound);
// const borrowCompound = new GelatoCoreLib.Action({
// addr: connectCompound.address,
// data: await hre.run("abi-encode-withselector", {
// abi: ConnectCompound.abi,
// functionname: "borrow",
// inputs: [hre.network.config.DAI, 0, "604", 0],
// }),
// operation: GelatoCoreLib.Operation.Delegatecall,
// });
// spells.push(borrowCompound);
// const flashPayBack = new GelatoCoreLib.Action({
// addr: connectInstaPool.address,
// data: await hre.run("abi-encode-withselector", {
// abi: ConnectInstaPool.abi,
// functionname: "flashPayback",
// inputs: [hre.network.config.DAI, 0, 0],
// }),
// operation: GelatoCoreLib.Operation.Delegatecall,
// });
// spells.push(flashPayBack);
// const payProvider = new GelatoCoreLib.Action({
// addr: connectGelatoProviderPayment.address,
// data: await hre.run("abi-encode-withselector", {
// abi: ConnectGelatoProviderPaymentABI,
// functionname: "payProvider",
// inputs: [gelatoProviderAddress, ETH, 0, "605", 0],
// }),
// operation: GelatoCoreLib.Operation.Delegatecall,
// });
// spells.push(payProvider);
// const gasPriceCeil = ethers.constants.MaxUint256;
// const connectGelatoFullDebtBridgeFromMakerTaskSpec = new GelatoCoreLib.TaskSpec(
// {
// conditions: [conditionMakerVaultUnsafe.address],
// actions: spells,
// gasPriceCeil,
// }
// );
// await expect(
// gelatoCore
// .connect(gelatoProviderWallet)
// .provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec])
// ).to.emit(gelatoCore, "LogTaskSpecProvided");
// expect(
// await gelatoCore
// .connect(gelatoProviderWallet)
// .isTaskSpecProvided(
// gelatoProviderAddress,
// connectGelatoFullDebtBridgeFromMakerTaskSpec
// )
// ).to.be.equal("OK");
// expect(
// await gelatoCore
// .connect(gelatoProviderWallet)
// .taskSpecGasPriceCeil(
// gelatoProviderAddress,
// await gelatoCore
// .connect(gelatoProviderWallet)
// .hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec)
// )
// ).to.be.equal(gasPriceCeil);
// //#endregion
// //#endregion
// });
// it("#1: Use Maker Compound refinancing if the maker vault become unsafe after a market move.", async function () {
// // User Actions
// // Step 1: User submit a Debt Refinancing task if market move against him
// // Step 2: Market Move against the user (Mock)
// // Step 3: Executor execute the user's task
// //#region Step 1 User submit a Debt Refinancing task if market move against him
// // User submit the refinancing task if market move against him.
// // So in this case if the maker vault go to the unsafe area
// // the refinancing task will be executed and the position
// // will be split on two position on maker and compound.
// // It will be done through a algorithm that will optimize the
// // total borrow rate.
// const conditionMakerVaultUnsafeObj = new GelatoCoreLib.Condition({
// inst: conditionMakerVaultUnsafe.address,
// data: await conditionMakerVaultUnsafe.getConditionData(
// vaultId,
// priceOracleResolver.address,
// await hre.run("abi-encode-withselector", {
// abi: (await deployments.getArtifact("PriceOracleResolver")).abi,
// functionname: "getMockPrice",
// inputs: [userAddress],
// }),
// MIN_COL_RATIO_MAKER
// ),
// });
// // ======= GELATO TASK SETUP ======
// const refinanceIfVaultUnsafe = new GelatoCoreLib.Task({
// conditions: [conditionMakerVaultUnsafeObj],
// actions: spells,
// });
// const gelatoExternalProvider = new GelatoCoreLib.GelatoProvider({
// addr: gelatoProviderAddress,
// module: dsaProviderModule.address,
// });
// const expiryDate = 0;
// await expect(
// dsa.cast(
// [connectGelato.address], // targets
// [
// await hre.run("abi-encode-withselector", {
// abi: ConnectGelato.abi,
// functionname: "submitTask",
// inputs: [
// gelatoExternalProvider,
// refinanceIfVaultUnsafe,
// expiryDate,
// ],
// }),
// ], // datas
// userAddress, // origin
// {
// gasLimit: 5000000,
// }
// )
// ).to.emit(gelatoCore, "LogTaskSubmitted");
// const taskReceipt = new GelatoCoreLib.TaskReceipt({
// id: await gelatoCore.currentTaskReceiptId(),
// userProxy: dsa.address,
// provider: gelatoExternalProvider,
// tasks: [refinanceIfVaultUnsafe],
// expiryDate,
// });
// //#endregion
// //#region Step 2 Market Move against the user (Mock)
// // Ether market price went from the current price to 250$
// const gelatoGasPrice = await hre.run("fetchGelatoGasPrice");
// expect(gelatoGasPrice).to.be.lte(GAS_PRICE_CEIL);
// // TO DO: base mock price off of real price data
// await priceOracleResolver.setMockPrice(ethers.utils.parseUnits("400", 18));
// expect(
// await gelatoCore
// .connect(gelatoExecutorWallet)
// .canExec(taskReceipt, GAS_LIMIT, gelatoGasPrice)
// ).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe");
// // TO DO: base mock price off of real price data
// await priceOracleResolver.setMockPrice(ethers.utils.parseUnits("250", 18));
// expect(
// await gelatoCore
// .connect(gelatoExecutorWallet)
// .canExec(taskReceipt, GAS_LIMIT, gelatoGasPrice)
// ).to.be.equal("OK");
// //#endregion
// //#region Step 3 Executor execute the user's task
// // The market move make the vault unsafe, so the executor
// // will execute the user's task to make the user position safe
// // by a debt refinancing in compound.
// //#region EXPECTED OUTCOME
// const latestPrice = await priceOracleResolver.getMockPrice(userAddress);
// const gasFeesPaidFromCol = ethers.utils
// .parseUnits(String(1933090 + 19331 * 2), 0)
// .mul(gelatoGasPrice);
// const debtOnMakerBefore = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultDebt(
// vaultId
// );
// const pricedCollateral = wmul(
// (
// await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultCollateralBalance(
// vaultId
// )
// ).sub(gasFeesPaidFromCol),
// latestPrice
// );
// const expectedColWithdrawAmount = wCalcCollateralToWithdraw(
// MIN_COL_RATIO_MAKER,
// MIN_COL_RATIO_B,
// latestPrice,
// pricedCollateral,
// debtOnMakerBefore
// );
// const expectedBorAmountToPayBack = wCalcDebtToRepay(
// MIN_COL_RATIO_MAKER,
// MIN_COL_RATIO_B,
// pricedCollateral,
// debtOnMakerBefore
// );
// //console.log(String(wdiv(pricedCollateral.sub(wmul(expectedColWithdrawAmount, latestPrice).add(gasFeesPaidFromCol)),debt.sub(expectedBorAmountToPayBack))));
// //#endregion
// const providerBalanceBeforeExecution = await gelatoProviderWallet.getBalance();
// await expect(
// gelatoCore.connect(gelatoExecutorWallet).exec(taskReceipt, {
// gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei)
// gasLimit: GAS_LIMIT,
// })
// ).to.emit(gelatoCore, "LogExecSuccess");
// // 🚧 For Debugging:
// // const txResponse2 = await gelatoCore
// // .connect(gelatoProviderWallet)
// // .exec(taskReceipt, {
// // gasPrice: gelatoGasPrice,
// // gasLimit: GAS_LIMIT,
// // });
// // const {blockHash} = await txResponse2.wait();
// // const logs = await ethers.provider.getLogs({blockHash});
// // const iFace = new ethers.utils.Interface(GelatoCoreLib.GelatoCore.abi);
// // for (const log of logs) {
// // console.log(iFace.parseLog(log).args.reason);
// // }
// // await GelatoCoreLib.sleep(10000);
// expect(await gelatoProviderWallet.getBalance()).to.be.gt(
// providerBalanceBeforeExecution
// );
// // compound position of DSA on cDai and cEth
// const compoundPosition = await compoundResolver.getCompoundData(
// dsa.address,
// [cDaiToken.address, cEthToken.address]
// );
// // https://compound.finance/docs/ctokens#exchange-rate
// // calculate cEth/ETH rate to convert back cEth to ETH
// // for comparing with the withdrew Ether to the deposited one.
// const exchangeRateCethToEth = (await cEthToken.getCash())
// .add(await cEthToken.totalBorrows())
// .sub(await cEthToken.totalReserves())
// .div(await cEthToken.totalSupply());
// // Estimated amount to borrowed token should be equal to the actual one read on compound contracts
// expect(expectedBorAmountToPayBack).to.be.equal(
// compoundPosition[0].borrowBalanceStoredUser
// );
// // Estimated amount of pricedCollateral should be equal to the actual one read on compound contracts
// expect(
// expectedColWithdrawAmount.sub(
// compoundPosition[1].balanceOfUser.mul(exchangeRateCethToEth)
// )
// ).to.be.lt(ethers.utils.parseUnits("1", 12));
// const debtOnMakerAfter = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultDebt(
// vaultId
// );
// const collateralOnMakerAfter = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultCollateralBalance(
// vaultId
// ); // in Ether.
// // Total Borrowed Amount on both protocol should equal to the initial borrowed amount on maker vault.
// expect(
// debtOnMakerAfter
// .add(compoundPosition[0].borrowBalanceStoredUser)
// .sub(MAKER_INITIAL_DEBT)
// ).to.be.lte(ethers.utils.parseUnits("1", 0));
// // Total Ether col on Maker and Compound (+ gasFeesPaidFromCol) should equal to the initial col on maker vault
// expect(
// compoundPosition[1].balanceOfUser
// .mul(exchangeRateCethToEth)
// .add(gasFeesPaidFromCol)
// .add(collateralOnMakerAfter)
// .sub(ethers.utils.parseEther("10"))
// ).to.be.lt(ethers.utils.parseUnits("1", 12));
// // Check Collaterization Ratio of Maker and Compound
// expect(
// wdiv(
// wmul(
// compoundPosition[1].balanceOfUser.mul(exchangeRateCethToEth),
// latestPrice
// ),
// compoundPosition[0].borrowBalanceStoredUser
// ).sub(MIN_COL_RATIO_MAKER)
// ).to.be.lt(ethers.utils.parseUnits("1", 12));
// expect(
// wdiv(
// wmul(
// collateralOnMakerAfter,
// await priceOracleResolver.getMockPrice(userAddress)
// ),
// debtOnMakerAfter
// ).sub(MIN_COL_RATIO_MAKER)
// ).to.be.lt(ethers.utils.parseUnits("1", 1));
// // DSA contain 1000 DAI
// expect(await DAI.balanceOf(dsa.address)).to.be.equal(MAKER_INITIAL_DEBT);
// //#endregion
// });
// });

View File

@ -2,7 +2,7 @@ const { expect } = require("chai");
const hre = require("hardhat");
const { ethers } = hre;
async function enableGelatoConnectorsForFromMaker(
module.exports = async function (
userWallet,
connectGelatoProviderPaymentAddr,
connectGelatoDataAddr,
@ -46,6 +46,4 @@ async function enableGelatoConnectorsForFromMaker(
.to.be.true;
//#endregion
}
module.exports = enableGelatoConnectorsForFromMaker;
};

View File

@ -13,7 +13,7 @@ const MAKER_INITIAL_DEBT = ethers.utils.parseUnits("1000", 18);
const MAX_FEES_IN_PERCENT = ethers.utils.parseUnits("1", 17);
async function getConstants() {
module.exports = async function () {
return {
ETH: ETH,
MIN_COL_RATIO_MAKER: MIN_COL_RATIO_MAKER,
@ -23,6 +23,4 @@ async function getConstants() {
MAKER_INITIAL_ETH: MAKER_INITIAL_ETH,
MAX_FEES_IN_PERCENT: MAX_FEES_IN_PERCENT,
};
}
module.exports = getConstants;
};

View File

@ -11,15 +11,15 @@ const GelatoCoreLib = require("@gelatonetwork/core");
const DAI_100 = ethers.utils.parseUnits("100", 18);
// Contracts
const InstaIndex = require("../pre-compiles/InstaIndex.json");
const InstaList = require("../pre-compiles/InstaList.json");
const InstaAccount = require("../pre-compiles/InstaAccount.json");
const ConnectAuth = require("../pre-compiles/ConnectAuth.json");
const ConnectGelato_ABI = require("../pre-compiles/ConnectGelato_ABI.json");
const ConnectMaker = require("../pre-compiles/ConnectMaker.json");
const ConnectCompound = require("../pre-compiles/ConnectCompound.json");
const IERC20 = require("../pre-compiles/IERC20.json");
const IUniswapExchange = require("../pre-compiles/IUniswapExchange.json");
const InstaIndex = require("../../../pre-compiles/InstaIndex.json");
const InstaList = require("../../../pre-compiles/InstaList.json");
const InstaAccount = require("../../../pre-compiles/InstaAccount.json");
const ConnectAuth = require("../../../pre-compiles/ConnectAuth.json");
const ConnectGelato_ABI = require("../../../pre-compiles/ConnectGelato_ABI.json");
const ConnectMaker = require("../../../pre-compiles/ConnectMaker.json");
const ConnectCompound = require("../../../pre-compiles/ConnectCompound.json");
const IERC20 = require("../../../pre-compiles/IERC20.json");
const IUniswapExchange = require("../../../pre-compiles/IUniswapExchange.json");
describe("Move DAI lending from DSR to Compound", function () {
this.timeout(0);

View File

@ -4,13 +4,13 @@ const { deployments, ethers } = hre;
// #region Contracts ABI
const ConnectMaker = require("../../pre-compiles/ConnectMaker.json");
const GetCdps = require("../../pre-compiles/GetCdps.json");
const DssCdpManager = require("../../pre-compiles/DssCdpManager.json");
const InstaList = require("../../pre-compiles/InstaList.json");
const InstaAccount = require("../../pre-compiles/InstaAccount.json");
const InstaIndex = require("../../pre-compiles/InstaIndex.json");
const IERC20 = require("../../pre-compiles/IERC20.json");
const ConnectMaker = require("../../../pre-compiles/ConnectMaker.json");
const GetCdps = require("../../../pre-compiles/GetCdps.json");
const DssCdpManager = require("../../../pre-compiles/DssCdpManager.json");
const InstaList = require("../../../pre-compiles/InstaList.json");
const InstaAccount = require("../../../pre-compiles/InstaAccount.json");
const InstaIndex = require("../../../pre-compiles/InstaIndex.json");
const IERC20 = require("../../../pre-compiles/IERC20.json");
const ORACLE_MAKER_ETH_USD = "ETH/USD-Maker-v1";
const ORACLE_MAKER_ETH_USD_ADDR = "0x729D19f657BD0614b4985Cf1D82531c67569197B";

View File

@ -4,13 +4,13 @@ const { deployments, ethers } = hre;
// #region Contracts ABI
const ConnectMaker = require("../../pre-compiles/ConnectMaker.json");
const GetCdps = require("../../pre-compiles/GetCdps.json");
const DssCdpManager = require("../../pre-compiles/DssCdpManager.json");
const InstaList = require("../../pre-compiles/InstaList.json");
const InstaAccount = require("../../pre-compiles/InstaAccount.json");
const InstaIndex = require("../../pre-compiles/InstaIndex.json");
const IERC20 = require("../../pre-compiles/IERC20.json");
const ConnectMaker = require("../../../pre-compiles/ConnectMaker.json");
const GetCdps = require("../../../pre-compiles/GetCdps.json");
const DssCdpManager = require("../../../pre-compiles/DssCdpManager.json");
const InstaList = require("../../../pre-compiles/InstaList.json");
const InstaAccount = require("../../../pre-compiles/InstaAccount.json");
const InstaIndex = require("../../../pre-compiles/InstaIndex.json");
const IERC20 = require("../../../pre-compiles/IERC20.json");
// #endregion

View File

@ -6,14 +6,14 @@ const GelatoCoreLib = require("@gelatonetwork/core");
// #region Contracts ABI
const ConnectMaker = require("../../pre-compiles/ConnectMaker.json");
const GetCdps = require("../../pre-compiles/GetCdps.json");
const DssCdpManager = require("../../pre-compiles/DssCdpManager.json");
const ConnectBasic = require("../../pre-compiles/ConnectBasic.json");
const InstaList = require("../../pre-compiles/InstaList.json");
const InstaAccount = require("../../pre-compiles/InstaAccount.json");
const InstaIndex = require("../../pre-compiles/InstaIndex.json");
const IERC20 = require("../../pre-compiles/IERC20.json");
const ConnectMaker = require("../../../pre-compiles/ConnectMaker.json");
const GetCdps = require("../../../pre-compiles/GetCdps.json");
const DssCdpManager = require("../../../pre-compiles/DssCdpManager.json");
const ConnectBasic = require("../../../pre-compiles/ConnectBasic.json");
const InstaList = require("../../../pre-compiles/InstaList.json");
const InstaAccount = require("../../../pre-compiles/InstaAccount.json");
const InstaIndex = require("../../../pre-compiles/InstaIndex.json");
const IERC20 = require("../../../pre-compiles/IERC20.json");
// #endregion

View File

@ -2,10 +2,10 @@ const { expect } = require("chai");
const hre = require("hardhat");
const { deployments, ethers } = hre;
const InstaPoolResolver = require("../../artifacts/contracts/interfaces/InstaDapp/resolvers/IInstaPoolResolver.sol/IInstaPoolResolver.json");
const InstaPoolResolver = require("../../../artifacts/contracts/interfaces/InstaDapp/resolvers/IInstaPoolResolver.sol/IInstaPoolResolver.json");
const DAI = hre.network.config.DAI;
describe("Debt Partial Refinance Math Unit Test", function () {
describe("FGelatoDebtBridge Unit Tests", function () {
this.timeout(0);
if (hre.network.name !== "hardhat") {
console.error("Test Suite is meant to be run on hardhat only");

View File

@ -1,935 +0,0 @@
const { expect } = require("chai");
const hre = require("hardhat");
const { deployments, ethers } = hre;
const GelatoCoreLib = require("@gelatonetwork/core");
// #region Contracts ABI and Constants
const InstaIndex = require("../pre-compiles/InstaIndex.json");
const InstaList = require("../pre-compiles/InstaList.json");
const InstaAccount = require("../pre-compiles/InstaAccount.json");
const ConnectGelato = require("../pre-compiles/ConnectGelato.json");
const ConnectMaker = require("../pre-compiles/ConnectMaker.json");
const ConnectCompound = require("../pre-compiles/ConnectCompound.json");
const ConnectInstaPool = require("../pre-compiles/ConnectInstaPool.json");
const ConnectAuth = require("../pre-compiles/ConnectAuth.json");
const ConnectGelatoFullDebtBridgeFromMakerABI = require("../artifacts/contracts/contracts/connectors/ConnectGelatoPartialDebtBridgeFromMaker.sol/ConnectGelatoPartialDebtBridgeFromMaker.json")
.abi;
const ConnectGelatoProviderPaymentABI = require("../artifacts/contracts/contracts/connectors/ConnectGelatoProviderPayment.sol/ConnectGelatoProviderPayment.json")
.abi;
const InstaConnector = require("../pre-compiles/InstaConnectors.json");
const DssCdpManager = require("../pre-compiles/DssCdpManager.json");
const GetCdps = require("../pre-compiles/GetCdps.json");
const IERC20 = require("../pre-compiles/IERC20.json");
const CTokenInterface = require("../pre-compiles/CTokenInterface.json");
const CompoundResolver = require("../pre-compiles/InstaCompoundResolver.json");
const ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
const GAS_LIMIT = "4000000";
const GAS_PRICE_CEIL = ethers.utils.parseUnits("1000", "gwei");
const WAD = ethers.utils.parseUnits("1", 18);
// const ORACLE_MAKER_ETH_USD = "ETH/USD-Maker-v1";
// const ORACLE_MAKER_ETH_USD_ADDR = "0x729D19f657BD0614b4985Cf1D82531c67569197B";
// const PRICE_ORACLE_MAKER_PAYLOAD = "0x57de26a4"; // IMakerOracle.read()
const MIN_COL_RATIO_MAKER = ethers.utils.parseUnits("3", 18);
const MIN_COL_RATIO_B = ethers.utils.parseUnits("19", 17);
// TO DO: make dynamic based on real time Collateral Price and Ratios
const MAKER_INITIAL_ETH = ethers.utils.parseEther("10");
const MAKER_INITIAL_DEBT = ethers.utils.parseUnits("1000", 18);
// #endregion
//#region Mock Math Function
function wdiv(x, y) {
return x.mul(WAD).add(y.div(2)).div(y);
}
function wmul(x, y) {
return x.mul(y).add(WAD.div(2)).div(WAD);
}
function wCalcCollateralToWithdraw(
minColRatioOnMaker,
minColRatioOnPositionB,
collateralPrice,
pricedCollateral,
daiDebtOnMaker
) {
//#region CALCULATION REPLICATION
let expectedColToWithdraw = wmul(
wmul(minColRatioOnMaker, minColRatioOnPositionB),
daiDebtOnMaker
); // doc ref : c_r x comp_r x d_2
expectedColToWithdraw = expectedColToWithdraw.sub(
wmul(minColRatioOnMaker, pricedCollateral)
); // doc ref : c_r x comp_r x d_2 - c_r x e_2
expectedColToWithdraw = wdiv(
expectedColToWithdraw,
minColRatioOnPositionB.sub(minColRatioOnMaker)
); // doc ref : (c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r)
expectedColToWithdraw = pricedCollateral.sub(expectedColToWithdraw); // doc ref : e_2 - ((c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r))
// Extra step to convert back to col type
expectedColToWithdraw = wdiv(expectedColToWithdraw, collateralPrice);
//#endregion
return expectedColToWithdraw;
}
function wCalcDebtToRepay(
minColRatioOnMaker,
minColRatioOnPositionB,
pricedCollateral,
daiDebtOnMaker
) {
//#region CALCULATION REPLICATION
let expectedBorToPayBack = wmul(
wmul(minColRatioOnMaker, minColRatioOnPositionB),
daiDebtOnMaker
); // doc ref : c_r x comp_r x d_2
expectedBorToPayBack = expectedBorToPayBack.sub(
wmul(minColRatioOnMaker, pricedCollateral)
); // doc ref : c_r x comp_r x d_2 - c_r x e_2
expectedBorToPayBack = wdiv(
expectedBorToPayBack,
minColRatioOnPositionB.sub(minColRatioOnMaker)
); // doc ref : (c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r)
expectedBorToPayBack = wmul(
wdiv(ethers.utils.parseUnits("1", 18), minColRatioOnMaker),
expectedBorToPayBack
); // doc ref : (1/c_r)((c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r))
expectedBorToPayBack = daiDebtOnMaker.sub(expectedBorToPayBack); // doc ref : d_2 - (1/c_r)((c_r x comp_r x d_2 - c_r x e_2)/ (comp_r - c_r))
//#endregion
return expectedBorToPayBack;
}
//#endregion
describe("Debt Bridge with External Provider", function () {
this.timeout(0);
if (hre.network.name !== "hardhat") {
console.error("Test Suite is meant to be run on hardhat only");
process.exit(1);
}
// Wallet to use for local testing
let userWallet;
let userAddress;
let gelatoProviderWallet;
let gelatoProviderAddress;
let gelatoExecutorWallet;
let gelatoExecutorAddress;
// Deployed instances
let connectGelato;
let connectMaker;
let connectInstaPool;
let connectCompound;
let instaIndex;
let instaList;
let dssCdpManager;
let getCdps;
let DAI;
let gelatoCore;
let cDaiToken;
let cEthToken;
let instaMaster;
let instaConnectors;
let compoundResolver;
// Contracts to deploy and use for local testing
let conditionMakerVaultUnsafe;
let connectGelatoPartialDebtBridgeFromMaker;
let connectGelatoProviderPayment;
let priceOracleResolver;
let dsaProviderModule;
// Creation during test
let dsa;
// Payload Params for ConnectGelatoPartialDebtBridgeFromMaker and ConditionMakerVaultUnsafe
let vaultId;
// For TaskSpec and for Task
let spells = [];
before(async function () {
// Get Test Wallet for local testnet
[
userWallet,
gelatoProviderWallet,
gelatoExecutorWallet,
] = await ethers.getSigners();
userAddress = await userWallet.getAddress();
gelatoProviderAddress = await gelatoProviderWallet.getAddress();
gelatoExecutorAddress = await gelatoExecutorWallet.getAddress();
instaMaster = await ethers.provider.getSigner(
hre.network.config.InstaMaster
);
// Hardhat default accounts prefilled with 100 ETH
expect(await userWallet.getBalance()).to.be.gt(
ethers.utils.parseEther("10")
);
// ===== Get Deployed Contract Instance ==================
instaIndex = await ethers.getContractAt(
InstaIndex.abi,
hre.network.config.InstaIndex
);
instaList = await ethers.getContractAt(
InstaList.abi,
hre.network.config.InstaList
);
connectGelato = await ethers.getContractAt(
ConnectGelato.abi,
hre.network.config.ConnectGelato
);
connectMaker = await ethers.getContractAt(
ConnectMaker.abi,
hre.network.config.ConnectMaker
);
connectInstaPool = await ethers.getContractAt(
ConnectInstaPool.abi,
hre.network.config.ConnectInstaPool
);
connectCompound = await ethers.getContractAt(
ConnectCompound.abi,
hre.network.config.ConnectCompound
);
dssCdpManager = await ethers.getContractAt(
DssCdpManager.abi,
hre.network.config.DssCdpManager
);
getCdps = await ethers.getContractAt(
GetCdps.abi,
hre.network.config.GetCdps
);
DAI = await ethers.getContractAt(IERC20.abi, hre.network.config.DAI);
gelatoCore = await ethers.getContractAt(
GelatoCoreLib.GelatoCore.abi,
hre.network.config.GelatoCore
);
cDaiToken = await ethers.getContractAt(
CTokenInterface.abi,
hre.network.config.CDAI
);
cEthToken = await ethers.getContractAt(
CTokenInterface.abi,
hre.network.config.CETH
);
instaConnectors = await ethers.getContractAt(
InstaConnector.abi,
hre.network.config.InstaConnectors
);
compoundResolver = await ethers.getContractAt(
CompoundResolver.abi,
hre.network.config.CompoundResolver
);
// instaEvent = await ethers.getContractAt(
// InstaEvent.abi,
// hre.network.config.InstaEvent
// )
// ===== Deploy Needed Contract ==================
const PriceOracleResolver = await ethers.getContractFactory(
"PriceOracleResolver"
);
priceOracleResolver = await PriceOracleResolver.deploy();
await priceOracleResolver.deployed();
const ConditionMakerVaultUnsafe = await ethers.getContractFactory(
"ConditionMakerVaultUnsafe"
);
conditionMakerVaultUnsafe = await ConditionMakerVaultUnsafe.deploy();
await conditionMakerVaultUnsafe.deployed();
const ConnectGelatoPartialDebtBridgeFromMaker = await ethers.getContractFactory(
"ConnectGelatoPartialDebtBridgeFromMaker"
);
connectGelatoPartialDebtBridgeFromMaker = await ConnectGelatoPartialDebtBridgeFromMaker.deploy(
(await instaConnectors.connectorLength()).add(1)
);
await connectGelatoPartialDebtBridgeFromMaker.deployed();
const ConnectGelatoProviderPayment = await ethers.getContractFactory(
"ConnectGelatoProviderPayment"
);
connectGelatoProviderPayment = await ConnectGelatoProviderPayment.deploy(
(await instaConnectors.connectorLength()).add(2)
);
await connectGelatoProviderPayment.deployed();
const ProviderModuleDsa = await ethers.getContractFactory(
"ProviderModuleDsa"
);
dsaProviderModule = await ProviderModuleDsa.deploy(
hre.network.config.GelatoCore,
connectGelatoProviderPayment.address
);
await dsaProviderModule.deployed();
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// After Contracts Deployement : Setup ///////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
// Gelato Testing environment setup.
// Step 1 : Add EUR/USD Maker Medianizer in the PriceOracleResolver
// Step 2 : Enable Debt Bridge Connector and Gelato Provider Payment Connector
// Step 3 : Executor Staking on Gelato
// Step 4 : Provider put some fund on gelato for paying future tasks executions
// Step 5 : Provider choose a executor
// Step 6 : Provider will add a module
// Step 7 : User create a DeFi Smart Account
// Step 8 : User open a Vault, put some ether on it and borrow some dai
// Step 9 : User give authorization to gelato to use his DSA on his behalf.
// Step 10 : Provider should whitelist task
//#region Step 1 Add EUR/USD Maker Medianizer in the PriceOracleResolver
// PriceOracleResolver is a price feeder aggregator
// You will be able to query price from multiple source through this aggregator
// For the demo we add the ETH/USD Medianizer to the aggregator
// MakerDAO price oracle are called Medianizer
// await priceOracleResolver.addOracle(
// ORACLE_MAKER_ETH_USD,
// ORACLE_MAKER_ETH_USD_ADDR,
// PRICE_ORACLE_MAKER_PAYLOAD
// );
//#endregion
//#region Step 2 Enable Debt Bridge Connector and Gelato Provider Payment Connector
// Debt Bridge Connector is used during refinancing of debt
// This Connect help the user to split a position in one protocol.
// to 2 protocol in a safe way. Both debt position will be safe.
// Gelato Provider Payment Connector is used for paying the provider
// for task execution. So when futur task will be executed, through a self financing
// transaction (user will pay during the execution of the task) task will
// be executed. Improvind user experience.
await userWallet.sendTransaction({
to: hre.network.config.InstaMaster,
value: ethers.utils.parseEther("0.1"),
});
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [await instaMaster.getAddress()],
});
await instaConnectors
.connect(instaMaster)
.enable(connectGelatoPartialDebtBridgeFromMaker.address);
await instaConnectors
.connect(instaMaster)
.enable(connectGelatoProviderPayment.address);
await hre.network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [await instaMaster.getAddress()],
});
expect(
await instaConnectors.isConnector([
connectGelatoPartialDebtBridgeFromMaker.address,
])
).to.be.true;
expect(
await instaConnectors.isConnector([connectGelatoProviderPayment.address])
).to.be.true;
//#endregion
//#region Step 3 Executor Staking on Gelato
// For task execution provider will ask a executor to watch the
// blockchain for possible execution autorization given by
// the condition that user choose when submitting the task.
// And if all condition are meet executor will execute the task.
// For safety measure Gelato ask the executor to stake a minimum
// amount.
await gelatoCore.connect(gelatoExecutorWallet).stakeExecutor({
value: await gelatoCore.minExecutorStake(),
});
expect(
await gelatoCore.isExecutorMinStaked(gelatoExecutorAddress)
).to.be.true;
//#endregion
//#region Step 4 Provider put some fund on gelato for paying future tasks executions
// Provider put some funds in gelato system for paying the
// Executor when this one will execute task on behalf of the
// Provider. At each provider's task execution, some funds (approximatively
// the gas cost value) will be transfered to the Executor stake.
const TASK_AUTOMATION_FUNDS = await gelatoCore.minExecProviderFunds(
GAS_LIMIT,
GAS_PRICE_CEIL
);
await expect(
gelatoCore
.connect(gelatoProviderWallet)
.provideFunds(gelatoProviderAddress, {
value: TASK_AUTOMATION_FUNDS,
})
).to.emit(gelatoCore, "LogFundsProvided");
expect(await gelatoCore.providerFunds(gelatoProviderAddress)).to.be.equal(
TASK_AUTOMATION_FUNDS
);
//#endregion
//#region Step 5 Provider choose a executor
// Provider choose a executor who will execute futur task
// for the provider, it will be compensated by the provider.
await expect(
gelatoCore
.connect(gelatoProviderWallet)
.providerAssignsExecutor(gelatoExecutorAddress)
).to.emit(gelatoCore, "LogProviderAssignedExecutor");
expect(
await gelatoCore.executorByProvider(gelatoProviderAddress)
).to.be.equal(gelatoExecutorAddress);
//#endregion
//#region Step 6 Provider will add a module
// By adding a module the provider will format future task's
// payload by adding some specificity like his address to the
// Payment connector for receiving payment of User.
await expect(
gelatoCore
.connect(gelatoProviderWallet)
.addProviderModules([dsaProviderModule.address])
).to.emit(gelatoCore, "LogProviderModuleAdded");
expect(
await gelatoCore
.connect(gelatoProviderWallet)
.isModuleProvided(gelatoProviderAddress, dsaProviderModule.address)
).to.be.true;
//#endregion
//#region Step 7 User create a DeFi Smart Account
// User create a Instadapp DeFi Smart Account
// who give him the possibility to interact
// with a large list of DeFi protocol through one
// Proxy account.
const dsaAccountCount = await instaList.accounts();
await expect(instaIndex.build(userAddress, 1, userAddress)).to.emit(
instaIndex,
"LogAccountCreated"
);
const dsaID = dsaAccountCount.add(1);
await expect(await instaList.accounts()).to.be.equal(dsaID);
// Instantiate the DSA
dsa = await ethers.getContractAt(
InstaAccount.abi,
await instaList.accountAddr(dsaID)
);
//#endregion
//#region Step 8 User open a Vault, put some ether on it and borrow some dai
// User open a maker vault
// He deposit 10 Eth on it
// He borrow a 1000 DAI
const openVault = await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "open",
inputs: ["ETH-A"],
});
await dsa.cast([hre.network.config.ConnectMaker], [openVault], userAddress);
const cdps = await getCdps.getCdpsAsc(dssCdpManager.address, dsa.address);
vaultId = String(cdps.ids[0]);
expect(cdps.ids[0].isZero()).to.be.false;
await dsa.cast(
[hre.network.config.ConnectMaker],
[
await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "deposit",
inputs: [vaultId, MAKER_INITIAL_ETH, 0, 0],
}),
],
userAddress,
{
value: MAKER_INITIAL_ETH,
}
);
await dsa.cast(
[hre.network.config.ConnectMaker],
[
await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "borrow",
inputs: [vaultId, MAKER_INITIAL_DEBT, 0, 0],
}),
],
userAddress
);
expect(await DAI.balanceOf(dsa.address)).to.be.equal(MAKER_INITIAL_DEBT);
//#endregion
//#region Step 9 User give authorization to gelato to use his DSA on his behalf.
// Instadapp DSA contract give the possibility to the user to delegate
// action by giving authorization.
// In this case user give authorization to gelato to execute
// task for him if needed.
await dsa.cast(
[hre.network.config.ConnectAuth],
[
await hre.run("abi-encode-withselector", {
abi: ConnectAuth.abi,
functionname: "add",
inputs: [gelatoCore.address],
}),
],
userAddress
);
expect(await dsa.isAuth(gelatoCore.address)).to.be.true;
//#endregion
//#region Step 10 Provider should whitelist task
// By WhiteList task, the provider can constrain the type
// of task the user can submitting.
//#region Actions
const debtBridgeCalculation = new GelatoCoreLib.Action({
addr: connectGelatoPartialDebtBridgeFromMaker.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectGelatoFullDebtBridgeFromMakerABI,
functionname: "savePartialRefinanceDataToMemory",
inputs: [
vaultId,
MIN_COL_RATIO_MAKER,
MIN_COL_RATIO_B,
priceOracleResolver.address,
await hre.run("abi-encode-withselector", {
abi: (await deployments.getArtifcat("PriceOracleResolver")).abi,
functionname: "getMockPrice",
inputs: [userAddress],
}),
0,
0,
],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
spells.push(debtBridgeCalculation);
const flashBorrow = new GelatoCoreLib.Action({
addr: connectInstaPool.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectInstaPool.abi,
functionname: "flashBorrow",
inputs: [hre.network.config.DAI, 0, "600", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
spells.push(flashBorrow);
const paybackMaker = new GelatoCoreLib.Action({
addr: connectMaker.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "payback",
inputs: [vaultId, 0, "601", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
spells.push(paybackMaker);
const withdrawMaker = new GelatoCoreLib.Action({
addr: connectMaker.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "withdraw",
inputs: [vaultId, 0, "602", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
spells.push(withdrawMaker);
const depositCompound = new GelatoCoreLib.Action({
addr: connectCompound.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectCompound.abi,
functionname: "deposit",
inputs: [ETH, 0, "603", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
spells.push(depositCompound);
const borrowCompound = new GelatoCoreLib.Action({
addr: connectCompound.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectCompound.abi,
functionname: "borrow",
inputs: [hre.network.config.DAI, 0, "604", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
spells.push(borrowCompound);
const flashPayBack = new GelatoCoreLib.Action({
addr: connectInstaPool.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectInstaPool.abi,
functionname: "flashPayback",
inputs: [hre.network.config.DAI, 0, 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
spells.push(flashPayBack);
const payProvider = new GelatoCoreLib.Action({
addr: connectGelatoProviderPayment.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectGelatoProviderPaymentABI,
functionname: "payProvider",
inputs: [gelatoProviderAddress, ETH, 0, "605", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
spells.push(payProvider);
const gasPriceCeil = ethers.constants.MaxUint256;
const connectGelatoFullDebtBridgeFromMakerTaskSpec = new GelatoCoreLib.TaskSpec(
{
conditions: [conditionMakerVaultUnsafe.address],
actions: spells,
gasPriceCeil,
}
);
await expect(
gelatoCore
.connect(gelatoProviderWallet)
.provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec])
).to.emit(gelatoCore, "LogTaskSpecProvided");
expect(
await gelatoCore
.connect(gelatoProviderWallet)
.isTaskSpecProvided(
gelatoProviderAddress,
connectGelatoFullDebtBridgeFromMakerTaskSpec
)
).to.be.equal("OK");
expect(
await gelatoCore
.connect(gelatoProviderWallet)
.taskSpecGasPriceCeil(
gelatoProviderAddress,
await gelatoCore
.connect(gelatoProviderWallet)
.hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec)
)
).to.be.equal(gasPriceCeil);
//#endregion
//#endregion
});
it("#1: Use Maker Compound refinancing if the maker vault become unsafe after a market move.", async function () {
// User Actions
// Step 1: User submit a Debt Refinancing task if market move against him
// Step 2: Market Move against the user (Mock)
// Step 3: Executor execute the user's task
//#region Step 1 User submit a Debt Refinancing task if market move against him
// User submit the refinancing task if market move against him.
// So in this case if the maker vault go to the unsafe area
// the refinancing task will be executed and the position
// will be split on two position on maker and compound.
// It will be done through a algorithm that will optimize the
// total borrow rate.
const conditionMakerVaultUnsafeObj = new GelatoCoreLib.Condition({
inst: conditionMakerVaultUnsafe.address,
data: await conditionMakerVaultUnsafe.getConditionData(
vaultId,
priceOracleResolver.address,
await hre.run("abi-encode-withselector", {
abi: (await deployments.getArtifact("PriceOracleResolver")).abi,
functionname: "getMockPrice",
inputs: [userAddress],
}),
MIN_COL_RATIO_MAKER
),
});
// ======= GELATO TASK SETUP ======
const refinanceIfVaultUnsafe = new GelatoCoreLib.Task({
conditions: [conditionMakerVaultUnsafeObj],
actions: spells,
});
const gelatoExternalProvider = new GelatoCoreLib.GelatoProvider({
addr: gelatoProviderAddress,
module: dsaProviderModule.address,
});
const expiryDate = 0;
await expect(
dsa.cast(
[connectGelato.address], // targets
[
await hre.run("abi-encode-withselector", {
abi: ConnectGelato.abi,
functionname: "submitTask",
inputs: [
gelatoExternalProvider,
refinanceIfVaultUnsafe,
expiryDate,
],
}),
], // datas
userAddress, // origin
{
gasLimit: 5000000,
}
)
).to.emit(gelatoCore, "LogTaskSubmitted");
const taskReceipt = new GelatoCoreLib.TaskReceipt({
id: await gelatoCore.currentTaskReceiptId(),
userProxy: dsa.address,
provider: gelatoExternalProvider,
tasks: [refinanceIfVaultUnsafe],
expiryDate,
});
//#endregion
//#region Step 2 Market Move against the user (Mock)
// Ether market price went from the current price to 250$
const gelatoGasPrice = await hre.run("fetchGelatoGasPrice");
expect(gelatoGasPrice).to.be.lte(GAS_PRICE_CEIL);
// TO DO: base mock price off of real price data
await priceOracleResolver.setMockPrice(ethers.utils.parseUnits("400", 18));
expect(
await gelatoCore
.connect(gelatoExecutorWallet)
.canExec(taskReceipt, GAS_LIMIT, gelatoGasPrice)
).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe");
// TO DO: base mock price off of real price data
await priceOracleResolver.setMockPrice(ethers.utils.parseUnits("250", 18));
expect(
await gelatoCore
.connect(gelatoExecutorWallet)
.canExec(taskReceipt, GAS_LIMIT, gelatoGasPrice)
).to.be.equal("OK");
//#endregion
//#region Step 3 Executor execute the user's task
// The market move make the vault unsafe, so the executor
// will execute the user's task to make the user position safe
// by a debt refinancing in compound.
//#region EXPECTED OUTCOME
const latestPrice = await priceOracleResolver.getMockPrice(userAddress);
const gasFeesPaidFromCol = ethers.utils
.parseUnits(String(1933090 + 19331 * 2), 0)
.mul(gelatoGasPrice);
const debtOnMakerBefore = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultDebt(
vaultId
);
const pricedCollateral = wmul(
(
await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultId
)
).sub(gasFeesPaidFromCol),
latestPrice
);
const expectedColWithdrawAmount = wCalcCollateralToWithdraw(
MIN_COL_RATIO_MAKER,
MIN_COL_RATIO_B,
latestPrice,
pricedCollateral,
debtOnMakerBefore
);
const expectedBorAmountToPayBack = wCalcDebtToRepay(
MIN_COL_RATIO_MAKER,
MIN_COL_RATIO_B,
pricedCollateral,
debtOnMakerBefore
);
//console.log(String(wdiv(pricedCollateral.sub(wmul(expectedColWithdrawAmount, latestPrice).add(gasFeesPaidFromCol)),debt.sub(expectedBorAmountToPayBack))));
//#endregion
const providerBalanceBeforeExecution = await gelatoProviderWallet.getBalance();
await expect(
gelatoCore.connect(gelatoExecutorWallet).exec(taskReceipt, {
gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei)
gasLimit: GAS_LIMIT,
})
).to.emit(gelatoCore, "LogExecSuccess");
// 🚧 For Debugging:
// const txResponse2 = await gelatoCore
// .connect(gelatoProviderWallet)
// .exec(taskReceipt, {
// gasPrice: gelatoGasPrice,
// gasLimit: GAS_LIMIT,
// });
// const {blockHash} = await txResponse2.wait();
// const logs = await ethers.provider.getLogs({blockHash});
// const iFace = new ethers.utils.Interface(GelatoCoreLib.GelatoCore.abi);
// for (const log of logs) {
// console.log(iFace.parseLog(log).args.reason);
// }
// await GelatoCoreLib.sleep(10000);
expect(await gelatoProviderWallet.getBalance()).to.be.gt(
providerBalanceBeforeExecution
);
// compound position of DSA on cDai and cEth
const compoundPosition = await compoundResolver.getCompoundData(
dsa.address,
[cDaiToken.address, cEthToken.address]
);
// https://compound.finance/docs/ctokens#exchange-rate
// calculate cEth/ETH rate to convert back cEth to ETH
// for comparing with the withdrew Ether to the deposited one.
const exchangeRateCethToEth = (await cEthToken.getCash())
.add(await cEthToken.totalBorrows())
.sub(await cEthToken.totalReserves())
.div(await cEthToken.totalSupply());
// Estimated amount to borrowed token should be equal to the actual one read on compound contracts
expect(expectedBorAmountToPayBack).to.be.equal(
compoundPosition[0].borrowBalanceStoredUser
);
// Estimated amount of pricedCollateral should be equal to the actual one read on compound contracts
expect(
expectedColWithdrawAmount.sub(
compoundPosition[1].balanceOfUser.mul(exchangeRateCethToEth)
)
).to.be.lt(ethers.utils.parseUnits("1", 12));
const debtOnMakerAfter = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultDebt(
vaultId
);
const collateralOnMakerAfter = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultId
); // in Ether.
// Total Borrowed Amount on both protocol should equal to the initial borrowed amount on maker vault.
expect(
debtOnMakerAfter
.add(compoundPosition[0].borrowBalanceStoredUser)
.sub(MAKER_INITIAL_DEBT)
).to.be.lte(ethers.utils.parseUnits("1", 0));
// Total Ether col on Maker and Compound (+ gasFeesPaidFromCol) should equal to the initial col on maker vault
expect(
compoundPosition[1].balanceOfUser
.mul(exchangeRateCethToEth)
.add(gasFeesPaidFromCol)
.add(collateralOnMakerAfter)
.sub(ethers.utils.parseEther("10"))
).to.be.lt(ethers.utils.parseUnits("1", 12));
// Check Collaterization Ratio of Maker and Compound
expect(
wdiv(
wmul(
compoundPosition[1].balanceOfUser.mul(exchangeRateCethToEth),
latestPrice
),
compoundPosition[0].borrowBalanceStoredUser
).sub(MIN_COL_RATIO_MAKER)
).to.be.lt(ethers.utils.parseUnits("1", 12));
expect(
wdiv(
wmul(
collateralOnMakerAfter,
await priceOracleResolver.getMockPrice(userAddress)
),
debtOnMakerAfter
).sub(MIN_COL_RATIO_MAKER)
).to.be.lt(ethers.utils.parseUnits("1", 1));
// DSA contain 1000 DAI
expect(await DAI.balanceOf(dsa.address)).to.be.equal(MAKER_INITIAL_DEBT);
//#endregion
});
});