Add VAT fees

This commit is contained in:
Shivva 2020-11-25 08:47:48 +01:00 committed by Luis Schliesske
parent 20e82596b7
commit a7a204be5e
10 changed files with 97 additions and 50 deletions

View File

@ -4,3 +4,6 @@ pragma solidity 0.7.4;
function GAS_COSTS_FOR_FULL_REFINANCE() pure returns (uint256[4] memory) {
return [uint256(2519000), 3140500, 3971000, 4345000];
}
uint256 constant VAT = 20;
uint256 constant VAULT_CREATION_COST = 100000;

View File

@ -2,12 +2,16 @@
pragma solidity 0.7.4;
pragma experimental ABIEncoderV2;
import {add, sub, wmul, wdiv} from "../../vendor/DSMath.sol";
import {add, sub, mul, wmul, wdiv} from "../../vendor/DSMath.sol";
import {
INSTA_POOL_RESOLVER,
ROUTE_1_TOLERANCE
} from "../../constants/CInstaDapp.sol";
import {GAS_COSTS_FOR_FULL_REFINANCE} from "../../constants/CDebtBridge.sol";
import {
GAS_COSTS_FOR_FULL_REFINANCE,
VAT,
VAULT_CREATION_COST
} from "../../constants/CDebtBridge.sol";
import {
IInstaPoolResolver
} from "../../interfaces/InstaDapp/resolvers/IInstaPoolResolver.sol";
@ -77,14 +81,23 @@ function _getGasCostMakerToMaker(bool _newVault, uint256 _route)
{
_checkRouteIndex(_route);
return
_newVault
? add(GAS_COSTS_FOR_FULL_REFINANCE()[_route], 0)
: GAS_COSTS_FOR_FULL_REFINANCE()[_route];
_getGasCostVAT(
_newVault
? add(
GAS_COSTS_FOR_FULL_REFINANCE()[_route],
VAULT_CREATION_COST
)
: GAS_COSTS_FOR_FULL_REFINANCE()[_route]
);
}
function _getGasCostMakerToCompound(uint256 _route) pure returns (uint256) {
_checkRouteIndex(_route);
return GAS_COSTS_FOR_FULL_REFINANCE()[_route];
return _getGasCostVAT(GAS_COSTS_FOR_FULL_REFINANCE()[_route]);
}
function _getGasCostVAT(uint256 _rawGasCost) pure returns (uint256) {
return mul(_rawGasCost, add(100, VAT)) / 100;
}
function _getRealisedDebt(uint256 _debtToMove) pure returns (uint256) {

View File

@ -0,0 +1,6 @@
module.exports = async () => {
return {
VAT: 20,
VAULT_CREATION_COST: 100000,
};
};

View File

@ -0,0 +1,26 @@
const gasConstants = require("../../constants/GasConstant");
module.exports = async function (route, withVaultCreation) {
let rawGasCost;
const gasCons = await gasConstants();
switch (route) {
case 0:
rawGasCost = 2519000; // 2290000 * 1,1 // gas left method measure : 2290000 - 2106637 = 183363 | gas reporter : 2290000 - 1789126 = 500874
break;
case 1:
rawGasCost = 3140500; // 2855000 * 1,1 // gas left method measure : 2855000 - 2667325 = 187675 | gas reporter : 2855000 - 2244814 = 610186
break;
case 2:
rawGasCost = 3971000; // 3610000 * 1,1 // gas left method measure : 3610000 - 3423279 = 186721 | gas reporter : 3610000 - 3031103 = 578897
break;
case 3:
rawGasCost = 4345000; // 3950000 * 1,1 // gas left method measure : 3950000 - 3764004 = 185996 | gas reporter : 3950000 - 3313916 = 636084
break;
default:
break;
}
return withVaultCreation
? ((rawGasCost + gasCons.VAULT_CREATION_COST) * (100 + gasCons.VAT)) / 100
: (rawGasCost * (100 + gasCons.VAT)) / 100;
};

View File

@ -6,7 +6,7 @@ const GelatoCoreLib = require("@gelatonetwork/core");
const setupFullRefinanceMakerToCompound = require("./helpers/setupFullRefinanceMakerToCompound");
const getInstaPoolV2Route = require("../../../../helpers/services/InstaDapp/getInstaPoolV2Route");
const getGasCostForFullRefinance = require("./helpers/services/getGasCostForFullRefinance");
const getGasCostForFullRefinance = require("../../../../helpers/services/gelato/getGasCostForFullRefinance");
// This test showcases how to submit a task refinancing a Users debt position from
// Maker to Compound using Gelato

View File

@ -5,7 +5,7 @@ const GelatoCoreLib = require("@gelatonetwork/core");
const setupFullRefinanceMakerToMakerWithVaultBCreation = require("./helpers/setupFullRefinanceMakerToMakerWithVaultBCreation");
const getInstaPoolV2Route = require("../../../../helpers/services/InstaDapp/getInstaPoolV2Route");
const getGasCostForFullRefinance = require("./helpers/services/getGasCostForFullRefinance");
const getGasCostForFullRefinance = require("./../../../../helpers/services/gelato/getGasCostForFullRefinance");
// This test showcases how to submit a task refinancing a Users debt position from
// Maker to Compound using Gelato
@ -223,7 +223,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat
);
}
const gasCost = await getGasCostForFullRefinance(route);
const gasCost = await getGasCostForFullRefinance(route, true);
const gasFeesPaidFromCol = ethers.BigNumber.from(gasCost).mul(
gelatoGasPrice

View File

@ -5,7 +5,7 @@ const GelatoCoreLib = require("@gelatonetwork/core");
const setupFullRefinanceMakerToMaker = require("./helpers/setupFullRefinanceMakerToMaker");
const getInstaPoolV2Route = require("../../../../helpers/services/InstaDapp/getInstaPoolV2Route");
const getGasCostForFullRefinance = require("./helpers/services/getGasCostForFullRefinance");
const getGasCostForFullRefinance = require("../../../../helpers/services/gelato/getGasCostForFullRefinance");
// This test showcases how to submit a task refinancing a Users debt position from
// Maker to Compound using Gelato

View File

@ -5,7 +5,7 @@ const GelatoCoreLib = require("@gelatonetwork/core");
const setupFullRefinanceMakerToMaker = require("./helpers/setupFullRefinanceMakerToMaker");
const getInstaPoolV2Route = require("../../../../helpers/services/InstaDapp/getInstaPoolV2Route");
const getGasCostForFullRefinance = require("./helpers/services/getGasCostForFullRefinance");
const getGasCostForFullRefinance = require("../../../../helpers/services/gelato/getGasCostForFullRefinance");
// This test showcases how to submit a task refinancing a Users debt position from
// Maker to Compound using Gelato
@ -244,7 +244,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with Vault B cre
);
}
const gasCost = await getGasCostForFullRefinance(route);
const gasCost = await getGasCostForFullRefinance(route, true);
const gasFeesPaidFromCol = ethers.BigNumber.from(gasCost).mul(
gelatoGasPrice

View File

@ -1,14 +0,0 @@
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
case 1:
return 3140500; // 2855000 * 1,1 // gas left method measure : 2855000 - 2667325 = 187675 | gas reporter : 2855000 - 2244814 = 610186
case 2:
return 3971000; // 3610000 * 1,1 // gas left method measure : 3610000 - 3423279 = 186721 | gas reporter : 3610000 - 3031103 = 578897
case 3:
return 4345000; // 3950000 * 1,1 // gas left method measure : 3950000 - 3764004 = 185996 | gas reporter : 3950000 - 3313916 = 636084
default:
break;
}
};

View File

@ -3,6 +3,7 @@ const hre = require("hardhat");
const { deployments, ethers } = hre;
const InstaPoolResolver = require("../../../artifacts/contracts/interfaces/InstaDapp/resolvers/IInstaPoolResolver.sol/IInstaPoolResolver.json");
const getGasCostForFullRefinance = require("./../../helpers/services/gelato/getGasCostForFullRefinance");
const DAI = hre.network.config.DAI;
describe("FGelatoDebtBridge Unit Tests", function () {
@ -74,52 +75,60 @@ describe("FGelatoDebtBridge Unit Tests", function () {
).to.be.revertedWith("FGelatoDebtBridge._getFlashLoanRoute: illiquid");
});
it("getGasCostMakerToMaker should return 2519000 gas limit for route 0 (Dydx) and new vault", async function () {
it("getGasCostMakerToMaker should return 3142800 gas limit for route 0 (Dydx) and new vault", async function () {
const expectedGasCost = await getGasCostForFullRefinance(0, true);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToMaker(true, 0)
).to.be.equal(2519000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToMaker should return 2519000 gas limit for route 0 (Dydx)", async function () {
it("getGasCostMakerToMaker should return 3022800 gas limit for route 0 (Dydx)", async function () {
const expectedGasCost = await getGasCostForFullRefinance(0);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToMaker(false, 0)
).to.be.equal(2519000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToMaker should return 3140500 gas limit for route 1 (maker) and new vault", async function () {
it("getGasCostMakerToMaker should return 3888600 gas limit for route 1 (maker) and new vault", async function () {
const expectedGasCost = await getGasCostForFullRefinance(1, true);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToMaker(true, 1)
).to.be.equal(3140500);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToMaker should return 3140500 gas limit for route 1 (maker)", async function () {
it("getGasCostMakerToMaker should return 3768600 gas limit for route 1 (maker)", async function () {
const expectedGasCost = await getGasCostForFullRefinance(1);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToMaker(false, 1)
).to.be.equal(3140500);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToMaker should return 3971000 gas limit for route 2 (compound) and new vault", async function () {
it("getGasCostMakerToMaker should return 4885200 gas limit for route 2 (compound) and new vault", async function () {
const expectedGasCost = await getGasCostForFullRefinance(2, true);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToMaker(true, 2)
).to.be.equal(3971000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToMaker should return 3971000 gas limit for route 2 (compound)", async function () {
it("getGasCostMakerToMaker should return 4765200 gas limit for route 2 (compound)", async function () {
const expectedGasCost = await getGasCostForFullRefinance(2);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToMaker(false, 2)
).to.be.equal(3971000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToMaker should return 4345000 gas limit for route 3 (aave) and new vault", async function () {
it("getGasCostMakerToMaker should return 5334000 gas limit for route 3 (aave) and new vault", async function () {
const expectedGasCost = await getGasCostForFullRefinance(3, true);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToMaker(true, 3)
).to.be.equal(4345000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToMaker should return 4345000 gas limit for route 3 (aave)", async function () {
it("getGasCostMakerToMaker should return 5214000 gas limit for route 3 (aave)", async function () {
const expectedGasCost = await getGasCostForFullRefinance(3);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToMaker(false, 3)
).to.be.equal(4345000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToMaker should revert with invalid route index when the inputed route exceed 4", async function () {
@ -130,28 +139,32 @@ describe("FGelatoDebtBridge Unit Tests", function () {
);
});
it("getGasCostMakerToCompound should return 2519000 gas limit for route 0 (Dydx)", async function () {
it("getGasCostMakerToCompound should return 3022800 gas limit for route 0 (Dydx)", async function () {
const expectedGasCost = await getGasCostForFullRefinance(0);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToCompound(0)
).to.be.equal(2519000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToCompound should return 3140500 gas limit for route 1 (Maker)", async function () {
it("getGasCostMakerToCompound should return 3768600 gas limit for route 1 (Maker)", async function () {
const expectedGasCost = await getGasCostForFullRefinance(1);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToCompound(1)
).to.be.equal(3140500);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToCompound should return 3971000 gas limit for route 2 (Compound)", async function () {
it("getGasCostMakerToCompound should return 4765200 gas limit for route 2 (Compound)", async function () {
const expectedGasCost = await getGasCostForFullRefinance(2);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToCompound(2)
).to.be.equal(3971000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToCompound should return 4345000 gas limit for route 3 (Aave)", async function () {
it("getGasCostMakerToCompound should return 5214000 gas limit for route 3 (Aave)", async function () {
const expectedGasCost = await getGasCostForFullRefinance(3);
expect(
await fGelatoDebtBridgeMock.getGasCostMakerToCompound(3)
).to.be.equal(4345000);
).to.be.equal(expectedGasCost);
});
it("getGasCostMakerToCompound should revert with invalid route index when the inputed route exceed 4", async function () {