wip:feat: GelatoTaskResolver and TaskGenerators

This commit is contained in:
gitpusha 2020-10-28 19:18:01 +01:00 committed by Twin Fish
parent 9fb2c4aaac
commit 1b8ad50845
9 changed files with 458 additions and 130 deletions

View File

@ -0,0 +1,300 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.7.4;
pragma experimental ABIEncoderV2;
/* solhint-disable */
interface ConnectorInterface {
function connectorID() external view returns (uint256 _type, uint256 _id);
function name() external view returns (string memory);
}
interface MemoryInterface {
function setUint(uint256 _id, uint256 _val) external;
function getUint(uint256 _id) external returns (uint256);
}
interface GelatoGasPriceOracle {
function latestAnswer() external view returns (int256);
}
interface ManagerLike {
function ilks(uint256) external view returns (bytes32);
function urns(uint256) external view returns (address);
function vat() external view returns (address);
}
interface VatLike {
function ilks(bytes32)
external
view
returns (
uint256,
uint256,
uint256,
uint256,
uint256
);
function dai(address) external view returns (uint256);
function urns(bytes32, address) external view returns (uint256, uint256);
}
abstract contract DSMath {
// _add, _sub, _mul to avoid clash with Inline Assembly op naming
function _add(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x + y) >= x, "ds-math-add-overflow");
}
function _sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
require((z = x - y) <= x, "ds-math-sub-underflow");
}
function _mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
require(y == 0 || (z = x * y) / y == x, "ds-math-_mul-overflow");
}
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
return x <= y ? x : y;
}
function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
return x >= y ? x : y;
}
function imin(int256 x, int256 y) internal pure returns (int256 z) {
return x <= y ? x : y;
}
function imax(int256 x, int256 y) internal pure returns (int256 z) {
return x >= y ? x : y;
}
uint256 constant WAD = 10**18;
uint256 constant RAY = 10**27;
//rounds to zero if x*y < WAD / 2
function wmul(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = _add(_mul(x, y), WAD / 2) / WAD;
}
//rounds to zero if x*y < WAD / 2
function rmul(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = _add(_mul(x, y), RAY / 2) / RAY;
}
//rounds to zero if x*y < WAD / 2
function wdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = _add(_mul(x, WAD), y / 2) / y;
}
//rounds to zero if x*y < RAY / 2
function rdiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = _add(_mul(x, RAY), y / 2) / y;
}
// This famous algorithm is called "exponentiation by squaring"
// and calculates x^n with x as fixed-point and n as regular unsigned.
//
// It's O(log n), instead of O(n) for naive repeated multiplication.
//
// These facts are why it works:
//
// If n is even, then x^n = (x^2)^(n/2).
// If n is odd, then x^n = x * x^(n-1),
// and applying the equation for even x gives
// x^n = x * (x^2)^((n-1) / 2).
//
// Also, EVM division is flooring and
// floor[(n-1) / 2] = floor[n / 2].
//
function rpow(uint256 x, uint256 n) internal pure returns (uint256 z) {
z = n % 2 != 0 ? x : RAY;
for (n /= 2; n != 0; n /= 2) {
x = rmul(x, x);
if (n % 2 != 0) {
z = rmul(z, x);
}
}
}
}
abstract contract Helpers is ConnectorInterface, DSMath {
uint256 internal __id;
/**
* @dev Return Maker MCD Manager Address.
*/
function getMcdManager() internal pure returns (address) {
return 0x5ef30b9986345249bc32d8928B7ee64DE9435E39;
}
/**
* @dev Return ethereum address
*/
function getAddressETH() internal pure returns (address) {
return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address
}
/**
* @dev Return Memory Variable Address
*/
function getMemoryAddr() internal pure returns (address) {
return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address
}
/**
* @dev Set Uint value in InstaMemory Contract.
*/
function setUint(uint256 setId, uint256 val) internal {
if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val);
}
/**
* @dev Get Uint value from InstaMemory Contract.
*/
function getUint(uint256 getId, uint256 val)
internal
returns (uint256 returnVal)
{
returnVal = getId == 0
? val
: MemoryInterface(getMemoryAddr()).getUint(getId);
}
/**
* @dev Connector Details
*/
function connectorID()
public
view
override
returns (uint256 _type, uint256 id)
{
(_type, id) = (1, __id); // Should put specific value.
}
function stringToBytes32(string memory str)
internal
pure
returns (bytes32 result)
{
require(bytes(str).length != 0, "String-Empty");
// solium-disable-next-line security/no-inline-assembly
assembly {
result := mload(add(str, 32))
}
}
}
/* solhint-enable */
abstract contract GelatoHelpers is Helpers {
function _getGelatoGasPriceOracle() internal pure returns (address) {
return 0x169E633A2D1E6c10dD91238Ba11c4A708dfEF37C;
}
function _getGelatoGasPrice() internal view returns (uint256) {
return
uint256(
GelatoGasPriceOracle(_getGelatoGasPriceOracle()).latestAnswer()
);
}
}
abstract contract MakerResolver is GelatoHelpers {
function getMakerVaultDebt(uint256 _vaultId)
public
view
returns (uint256 wad)
{
ManagerLike cdpManager = _getManager();
(bytes32 ilk, address urn) = _getVaultData(cdpManager, _vaultId);
VatLike vat = VatLike(cdpManager.vat());
(, uint256 rate, , , ) = VatLike(vat).ilks(ilk);
(, uint256 art) = VatLike(vat).urns(ilk, urn);
uint256 dai = VatLike(vat).dai(urn);
uint256 rad = _sub(_mul(art, rate), dai);
wad = rad / RAY;
wad = _mul(wad, RAY) < rad ? wad + 1 : wad;
}
function getMakerVaultCollateralBalance(uint256 _vaultId)
public
view
returns (uint256)
{
ManagerLike cdpManager = _getManager();
VatLike vat = VatLike(cdpManager.vat());
(bytes32 ilk, address urn) = _getVaultData(cdpManager, _vaultId);
(uint256 ink, ) = vat.urns(ilk, urn);
return ink;
}
function _getVaultData(ManagerLike cdpManager, uint256 vault)
internal
view
returns (bytes32 ilk, address urn)
{
ilk = cdpManager.ilks(vault);
urn = cdpManager.urns(vault);
}
function _getManager() internal pure returns (ManagerLike) {
return ManagerLike(getMcdManager());
}
}
/// @title ConnectGelatoFullDebtBridgeFromMaker
/// @notice InstaDapp connector for full refinancing of Maker debt positions.
/// @author Gelato Team
contract ConnectGelatoFullDebtBridgeFromMaker is MakerResolver {
// solhint-disable-next-line const-name-snakecase
string public constant override name = "GelatoDebtBridge-v1.0";
uint256 public constant GAS_COST = 1933090 + (19331 * 2); // 1933080 + ~2% (Estimated Value)
constructor(uint256 _id) {
__id = _id;
}
/// @notice Stores payload for full refinancing from a Maker position in InstaMemory.
/// @param _vaultID The ID of the makerDAO vault.
// @param _getID Id for writting in instaMemory.
// @param _setID Id for loading from instaMemory.
function saveFullRefinanceDataToMemory(
uint256 _vaultID,
uint256, /*_getId,*/
uint256 /*_setId*/
) public payable virtual {
uint256 wDaiDebtToMove = getMakerVaultDebt(_vaultID);
uint256 wColToWithdrawFromMaker = getMakerVaultCollateralBalance(
_vaultID
);
uint256 gasFeesPaidFromCol = _getGelatoProviderFees();
setUint(600, wDaiDebtToMove); // borrow flashloan
setUint(601, _sub(wColToWithdrawFromMaker, gasFeesPaidFromCol)); // deposit B
setUint(602, wDaiDebtToMove); // borrow B
setUint(603, gasFeesPaidFromCol); // pay the provider
}
function _getGelatoProviderFees()
internal
view
virtual
returns (uint256 gasCost)
{
gasCost = _mul(GAS_COST, _getGelatoGasPrice());
}
}

View File

@ -240,19 +240,6 @@ abstract contract GelatoHelpers is Helpers {
}
abstract contract MakerResolver is GelatoHelpers {
function _getVaultData(ManagerLike cdpManager, uint256 vault)
internal
view
returns (bytes32 ilk, address urn)
{
ilk = cdpManager.ilks(vault);
urn = cdpManager.urns(vault);
}
function _getManager() internal pure returns (ManagerLike) {
return ManagerLike(getMcdManager());
}
function getMakerVaultDebt(uint256 _vaultId)
public
view
@ -285,16 +272,30 @@ abstract contract MakerResolver is GelatoHelpers {
return ink;
}
function _getVaultData(ManagerLike cdpManager, uint256 vault)
internal
view
returns (bytes32 ilk, address urn)
{
ilk = cdpManager.ilks(vault);
urn = cdpManager.urns(vault);
}
function _getManager() internal pure returns (ManagerLike) {
return ManagerLike(getMcdManager());
}
}
/// @title ConnectGelatoDebtBridgeFromMaker
/// @notice InstaDapp connector for full or partial refinancing of Maker debt positions.
/// @title ConnectGelatoPartialDebtBridgeFromMaker
/// @notice InstaDapp connector for partial refinancing of Maker debt positions.
/// @author Gelato Team
contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
contract ConnectGelatoPartialDebtBridgeFromMaker is MakerResolver {
using GelatoBytes for bytes;
// solhint-disable-next-line const-name-snakecase
string public constant override name = "GelatoDebtBridge-v1.0";
string
public constant
override name = "ConnectGelatoPartialDebtBridgeFromMaker-v1.0"; // solhint-disable-line const-name-snakecase
uint256 public constant GAS_COST = 1933090 + (19331 * 2); // 1933080 + ~2% (Estimated Value)
constructor(uint256 _id) {
@ -333,39 +334,13 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
_oraclePayload
);
_setInstaMemoryUints(
wDaiDebtToMove,
_sub(wColToWithdrawFromMaker, gasFeesPaidFromCol), // _wColToDepositInB
wDaiDebtToMove,
gasFeesPaidFromCol
);
// For partial refinance we need to store exact values (no uint(-1) functionality)
setUint(600, wDaiDebtToMove); // borrow flashloan
setUint(601, wDaiDebtToMove); // payback maker
setUint(602, wColToWithdrawFromMaker); // withdraw maker
}
/// @notice Stores payload for full refinancing from a Maker position in InstaMemory.
/// @param _vaultID The ID of the makerDAO vault.
// @param _getID Id for writting in instaMemory.
// @param _setID Id for loading from instaMemory.
function saveFullRefinanceDataToMemory(
uint256 _vaultID,
uint256, /*_getId,*/
uint256 /*_setId*/
) public payable virtual {
uint256 wDaiDebtToMove = getMakerVaultDebt(_vaultID);
uint256 wColToWithdrawFromMaker = getMakerVaultCollateralBalance(
_vaultID
);
uint256 gasFeesPaidFromCol = _getGelatoProviderFees();
_setInstaMemoryUints(
_add(wDaiDebtToMove, 1), // 1 wei DAI buffer: MakerResolver debt inaccuracy
_sub(wColToWithdrawFromMaker, gasFeesPaidFromCol), // _wColToDepositInB
wDaiDebtToMove,
gasFeesPaidFromCol
);
setUint(603, _sub(wColToWithdrawFromMaker, gasFeesPaidFromCol)); // deposit B
setUint(604, wDaiDebtToMove); // borrow B
setUint(605, gasFeesPaidFromCol); // pay the provider
}
/// @notice Computes values needed for DebtBridge Maker->ProtocolB
@ -407,7 +382,7 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
if (!success) {
returndata.revertWithErrorString(
"ConnectGelatoDebtBridgeFromMaker.computeDebtBridge:oracle:"
"ConnectGelatoPartialDebtBridgeFromMaker.computeDebtBridge:oracle:"
);
}
@ -507,22 +482,6 @@ contract ConnectGelatoDebtBridgeFromMaker is MakerResolver {
);
}
// _gasFeesPaidFromCol == _wColToWithdrawFromMaker - _wColToDepositInB
function _setInstaMemoryUints(
uint256 _wDaiToBorrowFromInstaPool,
uint256 _wColToDepositInB,
uint256 _wDaiDebtToMove,
uint256 _gasFeesPaidFromCol
) internal virtual {
setUint(600, _wDaiToBorrowFromInstaPool); // borrow flashloan
// For full refinance we do NOT need to store exact values: uint(-1) functionality
// setUint(601, wDaiDebtToMove); // for partialRefinancing: payback maker
// setUint(602, wColToWithdrawFromMaker); // for partialRefinancing: withdraw maker
setUint(603, _wColToDepositInB); // deposit B
setUint(604, _wDaiDebtToMove); // borrow B
setUint(605, _gasFeesPaidFromCol); // pay the provider
}
function _getGelatoProviderFees()
internal
view

View File

@ -0,0 +1,7 @@
// "SPDX-License-Identifier: UNLICENSED"
pragma solidity 0.7.4;
interface IGelatoTaskGenerator {
// solhint-disable-next-line func-name-mixedcase
function SELECTOR() external pure returns (bytes4);
}

View File

@ -0,0 +1,62 @@
// "SPDX-License-Identifier: UNLICENSED"
pragma solidity 0.7.4;
pragma experimental ABIEncoderV2;
import {Ownable} from "../vendor/Ownable.sol";
import {GelatoBytes} from "../lib/GelatoBytes.sol";
import {IGelatoTaskGenerator} from "../interfaces/IGelatoTaskGenerator.sol";
import {
Task
} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoCore.sol";
/// @title GelatoTaskResolver
/// @notice Convenience contract with methods to retrieve Task objects from Task Generators.
/// @dev Can be used by Frontends and Maintainers to:
/// - Frontends: Retrieve Task structs from Task Generators for submission to GelatoCore
/// - Maintainer: Add new version of Task Generators
contract GelatoTaskResolver is Ownable {
using GelatoBytes for bytes;
/// @notice The contract that has the function returning a Task object
mapping(string => IGelatoTaskGenerator) public taskGenerator;
/// @notice Adds a new TaskGenerator address
/// @dev Only owner can call this, but existing taskGenerator entries are immutable
/// @param _taskGenerator The descriptor of the taskGenerator e.g. GelatoDebtBridgeFromMaker
/// @param _taskGeneratorAddr The address of the taskGenerator contract
function addTaskGenerator(
string memory _taskGenerator,
IGelatoTaskGenerator _taskGeneratorAddr
) external onlyOwner {
require(
taskGenerator[_taskGenerator] == IGelatoTaskGenerator(0),
"GelatoTaskResolver.addTaskGenerator: set"
);
taskGenerator[_taskGenerator] = _taskGeneratorAddr;
}
/// @notice A generelized getter for a price supplied by an taskGenerator contract.
/// @dev The taskGenerator returndata must be formatted as a single uint256.
/// @param _taskGenerator The descriptor of our taskGenerator e.g. ETH/USD-Maker-v1
/// @return The uint256 taskGenerator price
function getTask(
string calldata _taskGenerator,
bytes calldata _abiEncodedParams
) external view returns (Task memory) {
address taskGeneratorAddr = address(taskGenerator[_taskGenerator]);
if (taskGeneratorAddr == address(0))
revert("GelatoTaskResolver.getTask: !taskGenerator");
(bool success, bytes memory returndata) = taskGeneratorAddr.staticcall(
abi.encodePacked(
taskGenerator[_taskGenerator].SELECTOR(),
_abiEncodedParams
)
);
if (!success)
returndata.revertWithErrorString("GelatoTaskResolver.getTask:");
return abi.decode(returndata, (Task));
}
}

View File

@ -20,7 +20,7 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function ()
let constants;
let ABI;
// Payload Params for ConnectGelatoDebtBridgeFromMaker and ConditionMakerVaultUnsafe
// Payload Params for ConnectGelatoFullDebtBridgeFromMaker and ConditionMakerVaultUnsafe
let vaultId;
// For TaskSpec and for Task
@ -186,11 +186,11 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function ()
const gasFeesPaidFromCol = ethers.utils
.parseUnits(String(1933090 + 19331 * 2), 0)
.mul(gelatoGasPrice);
const debtOnMakerBefore = await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultDebt(
const debtOnMakerBefore = await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultDebt(
vaultId
);
const pricedCollateral = (
await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultCollateralBalance(
await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultId
)
).sub(gasFeesPaidFromCol);
@ -250,10 +250,10 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function ()
)
).to.be.lt(ethers.utils.parseUnits("1", 12));
const debtOnMakerAfter = await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultDebt(
const debtOnMakerAfter = await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultDebt(
vaultId
);
const collateralOnMakerAfter = await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultCollateralBalance(
const collateralOnMakerAfter = await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultId
); // in Ether.

View File

@ -20,7 +20,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () {
let constants;
let ABI;
// Payload Params for ConnectGelatoDebtBridgeFromMaker and ConditionMakerVaultUnsafe
// Payload Params for ConnectGelatoFullDebtBridgeFromMaker and ConditionMakerVaultUnsafe
let vaultAId;
// For TaskSpec and for Task
@ -188,11 +188,11 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () {
const gasFeesPaidFromCol = ethers.utils
.parseUnits(String(1933090 + 19331 * 2), 0)
.mul(gelatoGasPrice);
const debtOnMakerBefore = await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultDebt(
const debtOnMakerBefore = await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultDebt(
vaultAId
);
const pricedCollateral = (
await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultCollateralBalance(
await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultAId
)
).sub(gasFeesPaidFromCol);
@ -229,10 +229,10 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () {
let vaultBId = String(cdps.ids[1]);
expect(cdps.ids[1].isZero()).to.be.false;
const debtOnMakerVaultB = await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultDebt(
const debtOnMakerVaultB = await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultDebt(
vaultBId
);
const pricedCollateralOnVaultB = await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultCollateralBalance(
const pricedCollateralOnVaultB = await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultBId
);
@ -246,10 +246,10 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () {
// Estimated amount of collateral should be equal to the actual one read on compound contracts
expect(pricedCollateral).to.be.equal(pricedCollateralOnVaultB);
const debtOnMakerOnVaultAAfter = await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultDebt(
const debtOnMakerOnVaultAAfter = await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultDebt(
vaultAId
);
const collateralOnMakerOnVaultAAfter = await contracts.connectGelatoDebtBridgeFromMaker.getMakerVaultCollateralBalance(
const collateralOnMakerOnVaultAAfter = await contracts.connectGelatoFullDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultAId
); // in Ether.

View File

@ -23,7 +23,7 @@ const PriceOracleResolverABI = require("../../artifacts/contracts/resolvers/Pric
.abi;
const ConnectGelatoProviderPaymentABI = require("../../artifacts/contracts/connectors/ConnectGelatoProviderPayment.sol/ConnectGelatoProviderPayment.json")
.abi;
const ConnectGelatoDebtBridgeFromMakerABI = require("../../artifacts/contracts/connectors/ConnectGelatoDebtBridgeFromMaker.sol/ConnectGelatoDebtBridgeFromMaker.json")
const ConnectGelatoFullDebtBridgeFromMakerABI = require("../../artifacts/contracts/connectors/ConnectGelatoFullDebtBridgeFromMaker.sol/ConnectGelatoFullDebtBridgeFromMaker.json")
.abi;
const ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
@ -87,7 +87,7 @@ class Helper {
let compoundResolver;
// Contracts to deploy and use for local testing
let conditionMakerVaultUnsafe;
let connectGelatoDebtBridgeFromMaker;
let connectGelatoFullDebtBridgeFromMaker;
let connectGelatoProviderPayment;
let priceOracleResolver;
let dsaProviderModule;
@ -169,13 +169,13 @@ class Helper {
conditionMakerVaultUnsafe = await ConditionMakerVaultUnsafe.deploy();
await conditionMakerVaultUnsafe.deployed();
const ConnectGelatoDebtBridgeFromMaker = await ethers.getContractFactory(
"ConnectGelatoDebtBridgeFromMaker"
const ConnectGelatoFullDebtBridgeFromMaker = await ethers.getContractFactory(
"ConnectGelatoFullDebtBridgeFromMaker"
);
connectGelatoDebtBridgeFromMaker = await ConnectGelatoDebtBridgeFromMaker.deploy(
connectGelatoFullDebtBridgeFromMaker = await ConnectGelatoFullDebtBridgeFromMaker.deploy(
(await instaConnectors.connectorLength()).add(1)
);
await connectGelatoDebtBridgeFromMaker.deployed();
await connectGelatoFullDebtBridgeFromMaker.deployed();
const ConnectGelatoProviderPayment = await ethers.getContractFactory(
"ConnectGelatoProviderPayment"
@ -212,7 +212,7 @@ class Helper {
instaConnectors: instaConnectors,
compoundResolver: compoundResolver,
conditionMakerVaultUnsafe: conditionMakerVaultUnsafe,
connectGelatoDebtBridgeFromMaker: connectGelatoDebtBridgeFromMaker,
connectGelatoFullDebtBridgeFromMaker: connectGelatoFullDebtBridgeFromMaker,
connectGelatoProviderPayment: connectGelatoProviderPayment,
priceOracleResolver: priceOracleResolver,
dsaProviderModule: dsaProviderModule,
@ -299,7 +299,7 @@ class Helper {
await contracts.instaConnectors
.connect(contracts.instaMaster)
.enable(contracts.connectGelatoDebtBridgeFromMaker.address);
.enable(contracts.connectGelatoFullDebtBridgeFromMaker.address);
await contracts.instaConnectors
.connect(contracts.instaMaster)
@ -312,7 +312,7 @@ class Helper {
expect(
await contracts.instaConnectors.isConnector([
contracts.connectGelatoDebtBridgeFromMaker.address,
contracts.connectGelatoFullDebtBridgeFromMaker.address,
])
).to.be.true;
expect(
@ -537,9 +537,9 @@ class Helper {
let spells = [];
const debtBridgeCalculationForFullRefinance = new GelatoCoreLib.Action({
addr: contracts.connectGelatoDebtBridgeFromMaker.address,
addr: contracts.connectGelatoFullDebtBridgeFromMaker.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectGelatoDebtBridgeFromMakerABI,
abi: ConnectGelatoFullDebtBridgeFromMakerABI,
functionname: "saveFullRefinanceDataToMemory",
inputs: [vaultId, 0, 0],
}),
@ -589,7 +589,7 @@ class Helper {
data: await hre.run("abi-encode-withselector", {
abi: ConnectCompound.abi,
functionname: "deposit",
inputs: [ETH, 0, "603", 0],
inputs: [ETH, 0, "601", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
@ -601,7 +601,7 @@ class Helper {
data: await hre.run("abi-encode-withselector", {
abi: ConnectCompound.abi,
functionname: "borrow",
inputs: [hre.network.config.DAI, 0, "604", 0],
inputs: [hre.network.config.DAI, 0, "602", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
@ -625,7 +625,7 @@ class Helper {
data: await hre.run("abi-encode-withselector", {
abi: ConnectGelatoProviderPaymentABI,
functionname: "payProvider",
inputs: [wallets.providerAddress, ETH, 0, "605", 0],
inputs: [wallets.providerAddress, ETH, 0, "603", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
@ -634,7 +634,7 @@ class Helper {
const gasPriceCeil = ethers.constants.MaxUint256;
const connectGelatoDebtBridgeFromMakerTaskSpec = new GelatoCoreLib.TaskSpec(
const connectGelatoFullDebtBridgeFromMakerTaskSpec = new GelatoCoreLib.TaskSpec(
{
conditions: [contracts.conditionMakerVaultUnsafe.address],
actions: spells,
@ -645,7 +645,7 @@ class Helper {
await expect(
contracts.gelatoCore
.connect(wallets.providerWallet)
.provideTaskSpecs([connectGelatoDebtBridgeFromMakerTaskSpec])
.provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec])
).to.emit(contracts.gelatoCore, "LogTaskSpecProvided");
expect(
@ -653,7 +653,7 @@ class Helper {
.connect(wallets.providerWallet)
.isTaskSpecProvided(
wallets.providerAddress,
connectGelatoDebtBridgeFromMakerTaskSpec
connectGelatoFullDebtBridgeFromMakerTaskSpec
)
).to.be.equal("OK");
@ -664,7 +664,7 @@ class Helper {
wallets.providerAddress,
await contracts.gelatoCore
.connect(wallets.providerWallet)
.hashTaskSpec(connectGelatoDebtBridgeFromMakerTaskSpec)
.hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec)
)
).to.be.equal(gasPriceCeil);
@ -689,9 +689,9 @@ class Helper {
const spells = [];
const debtBridgeCalculationForFullRefinance = new GelatoCoreLib.Action({
addr: contracts.connectGelatoDebtBridgeFromMaker.address,
addr: contracts.connectGelatoFullDebtBridgeFromMaker.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectGelatoDebtBridgeFromMakerABI,
abi: ConnectGelatoFullDebtBridgeFromMakerABI,
functionname: "saveFullRefinanceDataToMemory",
inputs: [vaultId, 0, 0],
}),
@ -753,7 +753,7 @@ class Helper {
data: await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "deposit",
inputs: [0, 0, "603", 0],
inputs: [0, 0, "601", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
@ -765,7 +765,7 @@ class Helper {
data: await hre.run("abi-encode-withselector", {
abi: ConnectMaker.abi,
functionname: "borrow",
inputs: [0, 0, "604", 0],
inputs: [0, 0, "602", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
@ -789,7 +789,7 @@ class Helper {
data: await hre.run("abi-encode-withselector", {
abi: ConnectGelatoProviderPaymentABI,
functionname: "payProvider",
inputs: [wallets.providerAddress, ETH, 0, "605", 0],
inputs: [wallets.providerAddress, ETH, 0, "603", 0],
}),
operation: GelatoCoreLib.Operation.Delegatecall,
});
@ -798,7 +798,7 @@ class Helper {
const gasPriceCeil = ethers.constants.MaxUint256;
const connectGelatoDebtBridgeFromMakerTaskSpec = new GelatoCoreLib.TaskSpec(
const connectGelatoFullDebtBridgeFromMakerTaskSpec = new GelatoCoreLib.TaskSpec(
{
conditions: [contracts.conditionMakerVaultUnsafe.address],
actions: spells,
@ -809,7 +809,7 @@ class Helper {
await expect(
contracts.gelatoCore
.connect(wallets.providerWallet)
.provideTaskSpecs([connectGelatoDebtBridgeFromMakerTaskSpec])
.provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec])
).to.emit(contracts.gelatoCore, "LogTaskSpecProvided");
expect(
@ -817,7 +817,7 @@ class Helper {
.connect(wallets.providerWallet)
.isTaskSpecProvided(
wallets.providerAddress,
connectGelatoDebtBridgeFromMakerTaskSpec
connectGelatoFullDebtBridgeFromMakerTaskSpec
)
).to.be.equal("OK");
@ -828,7 +828,7 @@ class Helper {
wallets.providerAddress,
await contracts.gelatoCore
.connect(wallets.providerWallet)
.hashTaskSpec(connectGelatoDebtBridgeFromMakerTaskSpec)
.hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec)
)
).to.be.equal(gasPriceCeil);

View File

@ -23,15 +23,15 @@ describe("Gelato Debt Bridge Connector Unit Test", function () {
process.exit(1);
}
let connectGelatoDebtBridgeFromMaker;
let connectGelatoPartialDebtBridgeFromMaker;
before(async function () {
const ConnectGelatoDebtBridgeFromMaker = await ethers.getContractFactory(
"ConnectGelatoDebtBridgeFromMaker"
const ConnectGelatoPartialDebtBridgeFromMaker = await ethers.getContractFactory(
"ConnectGelatoPartialDebtBridgeFromMaker"
);
connectGelatoDebtBridgeFromMaker = await ConnectGelatoDebtBridgeFromMaker.deploy(
connectGelatoPartialDebtBridgeFromMaker = await ConnectGelatoPartialDebtBridgeFromMaker.deploy(
0
);
connectGelatoDebtBridgeFromMaker.deployed();
connectGelatoPartialDebtBridgeFromMaker.deployed();
});
it("#1: wCalcCollateralToWithdraw should return the amount of collateral to withdraw on protocol 1 and to put on protocol 2", async function () {
@ -73,7 +73,7 @@ describe("Gelato Debt Bridge Connector Unit Test", function () {
//#endregion
expect(
await connectGelatoDebtBridgeFromMaker.wCalcCollateralToWithdraw(
await connectGelatoPartialDebtBridgeFromMaker.wCalcCollateralToWithdraw(
minColRatioOnMaker,
minColRatioOnPositionB,
collateralPrice,
@ -123,7 +123,7 @@ describe("Gelato Debt Bridge Connector Unit Test", function () {
//#endregion
expect(
await connectGelatoDebtBridgeFromMaker.wCalcDebtToRepay(
await connectGelatoPartialDebtBridgeFromMaker.wCalcDebtToRepay(
minColRatioOnMaker,
minColRatioOnPositionB,
collateral,

View File

@ -13,7 +13,7 @@ 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 ConnectGelatoDebtBridgeFromMakerABI = require("../artifacts/contracts/connectors/ConnectGelatoDebtBridgeFromMaker.sol/ConnectGelatoDebtBridgeFromMaker.json")
const ConnectGelatoFullDebtBridgeFromMakerABI = require("../artifacts/contracts/connectors/ConnectGelatoPartialDebtBridgeFromMaker.sol/ConnectGelatoPartialDebtBridgeFromMaker.json")
.abi;
const ConnectGelatoProviderPaymentABI = require("../artifacts/contracts/connectors/ConnectGelatoProviderPayment.sol/ConnectGelatoProviderPayment.json")
.abi;
@ -148,7 +148,7 @@ describe("Debt Bridge with External Provider", function () {
// Contracts to deploy and use for local testing
let conditionMakerVaultUnsafe;
let connectGelatoDebtBridgeFromMaker;
let connectGelatoPartialDebtBridgeFromMaker;
let connectGelatoProviderPayment;
let priceOracleResolver;
let dsaProviderModule;
@ -156,7 +156,7 @@ describe("Debt Bridge with External Provider", function () {
// Creation during test
let dsa;
// Payload Params for ConnectGelatoDebtBridgeFromMaker and ConditionMakerVaultUnsafe
// Payload Params for ConnectGelatoPartialDebtBridgeFromMaker and ConditionMakerVaultUnsafe
let vaultId;
// For TaskSpec and for Task
@ -251,13 +251,13 @@ describe("Debt Bridge with External Provider", function () {
conditionMakerVaultUnsafe = await ConditionMakerVaultUnsafe.deploy();
await conditionMakerVaultUnsafe.deployed();
const ConnectGelatoDebtBridgeFromMaker = await ethers.getContractFactory(
"ConnectGelatoDebtBridgeFromMaker"
const ConnectGelatoPartialDebtBridgeFromMaker = await ethers.getContractFactory(
"ConnectGelatoPartialDebtBridgeFromMaker"
);
connectGelatoDebtBridgeFromMaker = await ConnectGelatoDebtBridgeFromMaker.deploy(
connectGelatoPartialDebtBridgeFromMaker = await ConnectGelatoPartialDebtBridgeFromMaker.deploy(
(await instaConnectors.connectorLength()).add(1)
);
await connectGelatoDebtBridgeFromMaker.deployed();
await connectGelatoPartialDebtBridgeFromMaker.deployed();
const ConnectGelatoProviderPayment = await ethers.getContractFactory(
"ConnectGelatoProviderPayment"
@ -332,7 +332,7 @@ describe("Debt Bridge with External Provider", function () {
await instaConnectors
.connect(instaMaster)
.enable(connectGelatoDebtBridgeFromMaker.address);
.enable(connectGelatoPartialDebtBridgeFromMaker.address);
await instaConnectors
.connect(instaMaster)
@ -345,7 +345,7 @@ describe("Debt Bridge with External Provider", function () {
expect(
await instaConnectors.isConnector([
connectGelatoDebtBridgeFromMaker.address,
connectGelatoPartialDebtBridgeFromMaker.address,
])
).to.be.true;
expect(
@ -538,9 +538,9 @@ describe("Debt Bridge with External Provider", function () {
//#region Actions
const debtBridgeCalculation = new GelatoCoreLib.Action({
addr: connectGelatoDebtBridgeFromMaker.address,
addr: connectGelatoPartialDebtBridgeFromMaker.address,
data: await hre.run("abi-encode-withselector", {
abi: ConnectGelatoDebtBridgeFromMakerABI,
abi: ConnectGelatoFullDebtBridgeFromMakerABI,
functionname: "savePartialRefinanceDataToMemory",
inputs: [
vaultId,
@ -647,7 +647,7 @@ describe("Debt Bridge with External Provider", function () {
const gasPriceCeil = ethers.constants.MaxUint256;
const connectGelatoDebtBridgeFromMakerTaskSpec = new GelatoCoreLib.TaskSpec(
const connectGelatoFullDebtBridgeFromMakerTaskSpec = new GelatoCoreLib.TaskSpec(
{
conditions: [conditionMakerVaultUnsafe.address],
actions: spells,
@ -658,7 +658,7 @@ describe("Debt Bridge with External Provider", function () {
await expect(
gelatoCore
.connect(providerWallet)
.provideTaskSpecs([connectGelatoDebtBridgeFromMakerTaskSpec])
.provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec])
).to.emit(gelatoCore, "LogTaskSpecProvided");
expect(
@ -666,7 +666,7 @@ describe("Debt Bridge with External Provider", function () {
.connect(providerWallet)
.isTaskSpecProvided(
providerAddress,
connectGelatoDebtBridgeFromMakerTaskSpec
connectGelatoFullDebtBridgeFromMakerTaskSpec
)
).to.be.equal("OK");
@ -677,7 +677,7 @@ describe("Debt Bridge with External Provider", function () {
providerAddress,
await gelatoCore
.connect(providerWallet)
.hashTaskSpec(connectGelatoDebtBridgeFromMakerTaskSpec)
.hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec)
)
).to.be.equal(gasPriceCeil);
@ -798,12 +798,12 @@ describe("Debt Bridge with External Provider", function () {
const gasFeesPaidFromCol = ethers.utils
.parseUnits(String(1933090 + 19331 * 2), 0)
.mul(gelatoGasPrice);
const debtOnMakerBefore = await connectGelatoDebtBridgeFromMaker.getMakerVaultDebt(
const debtOnMakerBefore = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultDebt(
vaultId
);
const pricedCollateral = wmul(
(
await connectGelatoDebtBridgeFromMaker.getMakerVaultCollateralBalance(
await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultId
)
).sub(gasFeesPaidFromCol),
@ -882,10 +882,10 @@ describe("Debt Bridge with External Provider", function () {
)
).to.be.lt(ethers.utils.parseUnits("1", 12));
const debtOnMakerAfter = await connectGelatoDebtBridgeFromMaker.getMakerVaultDebt(
const debtOnMakerAfter = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultDebt(
vaultId
);
const collateralOnMakerAfter = await connectGelatoDebtBridgeFromMaker.getMakerVaultCollateralBalance(
const collateralOnMakerAfter = await connectGelatoPartialDebtBridgeFromMaker.getMakerVaultCollateralBalance(
vaultId
); // in Ether.