mirror of
https://github.com/Instadapp/Gelato-automations.git
synced 2024-07-29 22:28:07 +00:00
Alternative implementation of new instadapp flashloan
This commit is contained in:
parent
9e951120e8
commit
e5e627ee29
|
@ -1,63 +0,0 @@
|
||||||
// SPDX-License-Identifier: UNLICENSED
|
|
||||||
pragma solidity 0.7.4;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import {GelatoBytes} from "../../lib/GelatoBytes.sol";
|
|
||||||
import {
|
|
||||||
AccountInterface,
|
|
||||||
ConnectorInterface
|
|
||||||
} from "../../interfaces/InstaDapp/IInstaDapp.sol";
|
|
||||||
import {
|
|
||||||
IConnectInstaPoolV2
|
|
||||||
} from "../../interfaces/InstaDapp/connectors/IConnectInstaPoolV2.sol";
|
|
||||||
|
|
||||||
contract ConnectGelatoData is ConnectorInterface {
|
|
||||||
using GelatoBytes for bytes;
|
|
||||||
|
|
||||||
// solhint-disable-next-line const-name-snakecase
|
|
||||||
string public constant override name = "ConnectGelatoData-v1.0";
|
|
||||||
uint256 internal immutable _id;
|
|
||||||
|
|
||||||
constructor(uint256 id) {
|
|
||||||
_id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Connector Details
|
|
||||||
function connectorID()
|
|
||||||
public
|
|
||||||
view
|
|
||||||
override
|
|
||||||
returns (uint256 _type, uint256 id)
|
|
||||||
{
|
|
||||||
(_type, id) = (1, _id); // Should put specific value.
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDataAndCast(address _target, bytes calldata _data)
|
|
||||||
public
|
|
||||||
payable
|
|
||||||
{
|
|
||||||
(bool success, bytes memory returndata) = _target.staticcall(_data);
|
|
||||||
if (!success) {
|
|
||||||
returndata.revertWithError(
|
|
||||||
"ConnectGelatoData.getDataAndCast._target:"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
(address[] memory targets, bytes[] memory datas) = abi.decode(
|
|
||||||
returndata,
|
|
||||||
(address[], bytes[])
|
|
||||||
);
|
|
||||||
|
|
||||||
// Instapool V2 / FlashLoan call
|
|
||||||
bytes memory castData = abi.encodeWithSelector(
|
|
||||||
AccountInterface.cast.selector,
|
|
||||||
targets,
|
|
||||||
datas,
|
|
||||||
msg.sender // msg.sender == GelatoCore
|
|
||||||
);
|
|
||||||
|
|
||||||
(success, returndata) = address(this).delegatecall(castData);
|
|
||||||
if (!success)
|
|
||||||
returndata.revertWithError("ConnectGelatoData.getDataAndCast:");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,53 +2,122 @@
|
||||||
pragma solidity 0.7.4;
|
pragma solidity 0.7.4;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import {sub} from "../../../vendor/DSMath.sol";
|
import {GelatoBytes} from "../../lib/GelatoBytes.sol";
|
||||||
|
import {sub} from "../../vendor/DSMath.sol";
|
||||||
import {
|
import {
|
||||||
_getMakerVaultDebt,
|
AccountInterface,
|
||||||
_getMakerVaultCollateralBalance
|
ConnectorInterface
|
||||||
} from "../../../functions/dapps/FMaker.sol";
|
} from "../../interfaces/InstaDapp/IInstaDapp.sol";
|
||||||
|
import {
|
||||||
|
IConnectInstaPoolV2
|
||||||
|
} from "../../interfaces/InstaDapp/connectors/IConnectInstaPoolV2.sol";
|
||||||
import {
|
import {
|
||||||
DAI,
|
DAI,
|
||||||
CONNECT_MAKER,
|
CONNECT_MAKER,
|
||||||
CONNECT_COMPOUND,
|
CONNECT_COMPOUND,
|
||||||
INSTA_POOL_V2
|
INSTA_POOL_V2
|
||||||
} from "../../../constants/CInstaDapp.sol";
|
} from "../../constants/CInstaDapp.sol";
|
||||||
|
import {
|
||||||
|
_getMakerVaultDebt,
|
||||||
|
_getMakerVaultCollateralBalance
|
||||||
|
} from "../../functions/dapps/FMaker.sol";
|
||||||
|
import {
|
||||||
|
_encodeFlashPayback
|
||||||
|
} from "../../functions/InstaDapp/connectors/FInstaPoolV2.sol";
|
||||||
import {
|
import {
|
||||||
_encodePaybackMakerVault,
|
_encodePaybackMakerVault,
|
||||||
_encodedWithdrawMakerVault,
|
_encodedWithdrawMakerVault,
|
||||||
_encodeOpenMakerVault,
|
_encodeOpenMakerVault,
|
||||||
_encodedDepositMakerVault,
|
_encodedDepositMakerVault,
|
||||||
_encodeBorrowDaiMakerVault
|
_encodeBorrowDaiMakerVault
|
||||||
} from "../../../functions/InstaDapp/connectors/FConnectMaker.sol";
|
} from "../../functions/InstaDapp/connectors/FConnectMaker.sol";
|
||||||
|
import {
|
||||||
|
_encodePayGelatoProvider
|
||||||
|
} from "../../functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol";
|
||||||
import {
|
import {
|
||||||
_encodeDepositCompound,
|
_encodeDepositCompound,
|
||||||
_encodeBorrowCompound
|
_encodeBorrowCompound
|
||||||
} from "../../../functions/InstaDapp/connectors/FConnectCompound.sol";
|
} from "../../functions/InstaDapp/connectors/FConnectCompound.sol";
|
||||||
import {
|
import {_getGelatoProviderFees} from "../../functions/gelato/FGelato.sol";
|
||||||
_encodePayGelatoProvider
|
|
||||||
} from "../../../functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol";
|
|
||||||
import {
|
|
||||||
_encodeFlashPayback
|
|
||||||
} from "../../../functions/InstaDapp/connectors/FInstaPoolV2.sol";
|
|
||||||
import {_getGelatoProviderFees} from "../../../functions/gelato/FGelato.sol";
|
|
||||||
import {
|
|
||||||
IConnectInstaPoolV2
|
|
||||||
} from "../../../interfaces/InstaDapp/connectors/IConnectInstaPoolV2.sol";
|
|
||||||
|
|
||||||
/// @title DebtBridgeFromMakerForFullRefinance
|
contract ConnectGelatoDataForFullRefinance is ConnectorInterface {
|
||||||
/// @notice Task Generator contract that generate task for a full refinancing from maker protocol to another protocol (can be Maker).
|
using GelatoBytes for bytes;
|
||||||
/// @author Gelato Team
|
|
||||||
contract DebtBridgeFromMakerForFullRefinance {
|
|
||||||
uint256 public constant GAS_COST = 1490779 + (14908 * 2); // 1933080 + ~2% (Estimated Value)
|
|
||||||
|
|
||||||
// To retrieve when the connector is deployed and replace with the address of the deployed instance
|
// solhint-disable-next-line const-name-snakecase
|
||||||
address public immutable connectGelatoProviderPayment;
|
string public constant override name = "ConnectGelatoData-v1.0";
|
||||||
|
uint256 internal immutable _id;
|
||||||
|
address internal immutable _connectGelatoProviderPayment;
|
||||||
|
|
||||||
constructor(address _connectGelatoProviderPayment) {
|
uint256 public constant GAS_COST = 1490779 + (14908 * 2); // 1490779 + ~2% (Estimated Value)
|
||||||
connectGelatoProviderPayment = _connectGelatoProviderPayment;
|
|
||||||
|
constructor(uint256 id, address connectGelatoProviderPayment) {
|
||||||
|
_id = id;
|
||||||
|
_connectGelatoProviderPayment = connectGelatoProviderPayment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* solhint-disable function-max-lines */
|
/// @dev Connector Details
|
||||||
|
function connectorID()
|
||||||
|
public
|
||||||
|
view
|
||||||
|
override
|
||||||
|
returns (uint256 _type, uint256 id)
|
||||||
|
{
|
||||||
|
(_type, id) = (1, _id); // Should put specific value.
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataAndCastForFromMakerToMaker(
|
||||||
|
uint256 _vaultId,
|
||||||
|
address _token,
|
||||||
|
string memory _colType,
|
||||||
|
address _provider
|
||||||
|
) public payable {
|
||||||
|
(
|
||||||
|
address[] memory targets,
|
||||||
|
bytes[] memory datas
|
||||||
|
) = _execPayloadForFullRefinanceFromMakerToMaker(
|
||||||
|
_vaultId,
|
||||||
|
_token,
|
||||||
|
_colType,
|
||||||
|
_provider
|
||||||
|
);
|
||||||
|
|
||||||
|
_cast(targets, datas);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataAndCastForFromMakerToCompound(
|
||||||
|
uint256 _vaultId,
|
||||||
|
address _token,
|
||||||
|
address _provider
|
||||||
|
) public payable {
|
||||||
|
(
|
||||||
|
address[] memory targets,
|
||||||
|
bytes[] memory datas
|
||||||
|
) = _execPayloadForFullRefinanceFromMakerToCompound(
|
||||||
|
_vaultId,
|
||||||
|
_token,
|
||||||
|
_provider
|
||||||
|
);
|
||||||
|
|
||||||
|
_cast(targets, datas);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _cast(address[] memory targets, bytes[] memory datas) internal {
|
||||||
|
// Instapool V2 / FlashLoan call
|
||||||
|
bytes memory castData = abi.encodeWithSelector(
|
||||||
|
AccountInterface.cast.selector,
|
||||||
|
targets,
|
||||||
|
datas,
|
||||||
|
msg.sender // msg.sender == GelatoCore
|
||||||
|
);
|
||||||
|
|
||||||
|
(bool success, bytes memory returndata) = address(this).delegatecall(
|
||||||
|
castData
|
||||||
|
);
|
||||||
|
if (!success)
|
||||||
|
returndata.revertWithError(
|
||||||
|
"ConnectGelatoDataForFullRefinance._cast:"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// @notice Generate Task for a full refinancing between Maker to Compound.
|
/// @notice Generate Task for a full refinancing between Maker to Compound.
|
||||||
/// @param _vaultId Id of the unsafe vault of the client.
|
/// @param _vaultId Id of the unsafe vault of the client.
|
||||||
|
@ -56,11 +125,11 @@ contract DebtBridgeFromMakerForFullRefinance {
|
||||||
/// @param _provider address of the paying provider.
|
/// @param _provider address of the paying provider.
|
||||||
/// @return targets : flashloan contract address
|
/// @return targets : flashloan contract address
|
||||||
/// @return datas : calldata for flashloan
|
/// @return datas : calldata for flashloan
|
||||||
function execPayloadForFullRefinanceFromMakerToCompound(
|
function _execPayloadForFullRefinanceFromMakerToCompound(
|
||||||
uint256 _vaultId,
|
uint256 _vaultId,
|
||||||
address _token,
|
address _token,
|
||||||
address _provider
|
address _provider
|
||||||
) public view returns (address[] memory targets, bytes[] memory datas) {
|
) internal view returns (address[] memory targets, bytes[] memory datas) {
|
||||||
targets = new address[](1);
|
targets = new address[](1);
|
||||||
targets[0] = INSTA_POOL_V2;
|
targets[0] = INSTA_POOL_V2;
|
||||||
|
|
||||||
|
@ -75,7 +144,7 @@ contract DebtBridgeFromMakerForFullRefinance {
|
||||||
_targets[1] = CONNECT_MAKER; // withdraw
|
_targets[1] = CONNECT_MAKER; // withdraw
|
||||||
_targets[2] = CONNECT_COMPOUND; // deposit
|
_targets[2] = CONNECT_COMPOUND; // deposit
|
||||||
_targets[3] = CONNECT_COMPOUND; // borrow
|
_targets[3] = CONNECT_COMPOUND; // borrow
|
||||||
_targets[4] = connectGelatoProviderPayment;
|
_targets[4] = _connectGelatoProviderPayment;
|
||||||
_targets[5] = INSTA_POOL_V2;
|
_targets[5] = INSTA_POOL_V2;
|
||||||
|
|
||||||
bytes[] memory _datas = new bytes[](6);
|
bytes[] memory _datas = new bytes[](6);
|
||||||
|
@ -114,12 +183,12 @@ contract DebtBridgeFromMakerForFullRefinance {
|
||||||
/// @param _provider address of the paying provider.
|
/// @param _provider address of the paying provider.
|
||||||
/// @return targets : flashloan contract address
|
/// @return targets : flashloan contract address
|
||||||
/// @return datas : calldata for flashloan
|
/// @return datas : calldata for flashloan
|
||||||
function execPayloadForFullRefinanceFromMakerToMaker(
|
function _execPayloadForFullRefinanceFromMakerToMaker(
|
||||||
uint256 _vaultId,
|
uint256 _vaultId,
|
||||||
address _token,
|
address _token,
|
||||||
string memory _colType,
|
string memory _colType,
|
||||||
address _provider
|
address _provider
|
||||||
) public view returns (address[] memory targets, bytes[] memory datas) {
|
) internal view returns (address[] memory targets, bytes[] memory datas) {
|
||||||
targets = new address[](1);
|
targets = new address[](1);
|
||||||
targets[0] = INSTA_POOL_V2;
|
targets[0] = INSTA_POOL_V2;
|
||||||
|
|
||||||
|
@ -135,7 +204,7 @@ contract DebtBridgeFromMakerForFullRefinance {
|
||||||
_targets[2] = CONNECT_MAKER; // open ETH-B vault
|
_targets[2] = CONNECT_MAKER; // open ETH-B vault
|
||||||
_targets[3] = CONNECT_MAKER; // deposit
|
_targets[3] = CONNECT_MAKER; // deposit
|
||||||
_targets[4] = CONNECT_MAKER; // borrow
|
_targets[4] = CONNECT_MAKER; // borrow
|
||||||
_targets[5] = connectGelatoProviderPayment;
|
_targets[5] = _connectGelatoProviderPayment;
|
||||||
_targets[6] = targets[0];
|
_targets[6] = targets[0];
|
||||||
|
|
||||||
bytes[] memory _datas = new bytes[](7);
|
bytes[] memory _datas = new bytes[](7);
|
||||||
|
@ -167,47 +236,4 @@ contract DebtBridgeFromMakerForFullRefinance {
|
||||||
abi.encode(_targets, _datas)
|
abi.encode(_targets, _datas)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* solhint-enable function-max-lines */
|
|
||||||
|
|
||||||
/// @notice Generate Data for calling execPayloadForFullRefinanceFromMakerToMaker via a static call.
|
|
||||||
/// @param _vaultId Id of the unsafe vault of the client.
|
|
||||||
/// @param _token vault's col token address .
|
|
||||||
/// @param _colType colType of the new vault, exemple : ETH-B, ETH-A.
|
|
||||||
/// @param _provider address of the paying provider.
|
|
||||||
/// @return a call data for a static call of execPayloadForFullRefinanceFromMakerToMaker.
|
|
||||||
function getDebtBridgeFullRefinanceMakerToMakerData(
|
|
||||||
uint256 _vaultId,
|
|
||||||
address _token,
|
|
||||||
string memory _colType,
|
|
||||||
address _provider
|
|
||||||
) public pure returns (bytes memory) {
|
|
||||||
return
|
|
||||||
abi.encodeWithSelector(
|
|
||||||
this.execPayloadForFullRefinanceFromMakerToMaker.selector,
|
|
||||||
_vaultId,
|
|
||||||
_token,
|
|
||||||
_colType,
|
|
||||||
_provider
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @notice Generate Data for calling execPayloadForFullRefinanceFromMakerToCompound via a static call.
|
|
||||||
/// @param _vaultId Id of the unsafe vault of the client.
|
|
||||||
/// @param _token vault's col token address .
|
|
||||||
/// @param _provider address of the paying provider.
|
|
||||||
/// @return a call data for a static call of execPayloadForFullRefinanceFromMakerToMaker.
|
|
||||||
function getDebtBridgeFullRefinanceMakerToCompoundData(
|
|
||||||
uint256 _vaultId,
|
|
||||||
address _token,
|
|
||||||
address _provider
|
|
||||||
) public pure returns (bytes memory) {
|
|
||||||
return
|
|
||||||
abi.encodeWithSelector(
|
|
||||||
this.execPayloadForFullRefinanceFromMakerToCompound.selector,
|
|
||||||
_vaultId,
|
|
||||||
_token,
|
|
||||||
_provider
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -2,50 +2,49 @@
|
||||||
pragma solidity 0.7.4;
|
pragma solidity 0.7.4;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import {GelatoBytes} from "../../../lib/GelatoBytes.sol";
|
import {GelatoBytes} from "../../lib/GelatoBytes.sol";
|
||||||
import {sub, wmul} from "../../../vendor/DSMath.sol";
|
import {sub, wmul} from "../../vendor/DSMath.sol";
|
||||||
import {
|
import {
|
||||||
_getMakerVaultDebt,
|
AccountInterface,
|
||||||
_getMakerVaultCollateralBalance
|
ConnectorInterface
|
||||||
} from "../../../functions/dapps/FMaker.sol";
|
} from "../../interfaces/InstaDapp/IInstaDapp.sol";
|
||||||
|
import {
|
||||||
|
IConnectInstaPoolV2
|
||||||
|
} from "../../interfaces/InstaDapp/connectors/IConnectInstaPoolV2.sol";
|
||||||
import {
|
import {
|
||||||
DAI,
|
DAI,
|
||||||
CONNECT_MAKER,
|
CONNECT_MAKER,
|
||||||
CONNECT_COMPOUND,
|
CONNECT_COMPOUND,
|
||||||
INSTA_POOL_V2
|
INSTA_POOL_V2
|
||||||
} from "../../../constants/CInstaDapp.sol";
|
} from "../../constants/CInstaDapp.sol";
|
||||||
|
import {
|
||||||
|
_getMakerVaultDebt,
|
||||||
|
_getMakerVaultCollateralBalance
|
||||||
|
} from "../../functions/dapps/FMaker.sol";
|
||||||
|
import {
|
||||||
|
_encodeFlashPayback
|
||||||
|
} from "../../functions/InstaDapp/connectors/FInstaPoolV2.sol";
|
||||||
import {
|
import {
|
||||||
_encodePaybackMakerVault,
|
_encodePaybackMakerVault,
|
||||||
_encodedWithdrawMakerVault,
|
_encodedWithdrawMakerVault,
|
||||||
_encodeOpenMakerVault,
|
_encodeOpenMakerVault,
|
||||||
_encodedDepositMakerVault,
|
_encodedDepositMakerVault,
|
||||||
_encodeBorrowDaiMakerVault
|
_encodeBorrowDaiMakerVault
|
||||||
} from "../../../functions/InstaDapp/connectors/FConnectMaker.sol";
|
} from "../../functions/InstaDapp/connectors/FConnectMaker.sol";
|
||||||
|
import {
|
||||||
|
_encodePayGelatoProvider
|
||||||
|
} from "../../functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol";
|
||||||
import {
|
import {
|
||||||
_encodeDepositCompound,
|
_encodeDepositCompound,
|
||||||
_encodeBorrowCompound
|
_encodeBorrowCompound
|
||||||
} from "../../../functions/InstaDapp/connectors/FConnectCompound.sol";
|
} from "../../functions/InstaDapp/connectors/FConnectCompound.sol";
|
||||||
import {
|
import {_getGelatoProviderFees} from "../../functions/gelato/FGelato.sol";
|
||||||
_encodePayGelatoProvider
|
|
||||||
} from "../../../functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol";
|
|
||||||
import {
|
|
||||||
_encodeFlashPayback
|
|
||||||
} from "../../../functions/InstaDapp/connectors/FInstaPoolV2.sol";
|
|
||||||
import {_getGelatoProviderFees} from "../../../functions/gelato/FGelato.sol";
|
|
||||||
import {
|
import {
|
||||||
_wCalcCollateralToWithdraw,
|
_wCalcCollateralToWithdraw,
|
||||||
_wCalcDebtToRepay
|
_wCalcDebtToRepay
|
||||||
} from "../../../functions/gelato/FGelatoDebtBridge.sol";
|
} from "../../functions/gelato/FGelatoDebtBridge.sol";
|
||||||
import {
|
|
||||||
IConnectInstaPoolV2
|
|
||||||
} from "../../../interfaces/InstaDapp/connectors/IConnectInstaPoolV2.sol";
|
|
||||||
|
|
||||||
/// @title DebtBridgeFromMakerForPartialRefinance
|
|
||||||
/// @notice Task Generator contract that generate task for a full refinancing from maker protocol to another protocol (can be Maker).
|
|
||||||
/// @author Gelato Team
|
|
||||||
contract DebtBridgeFromMakerForPartialRefinance {
|
|
||||||
using GelatoBytes for bytes;
|
|
||||||
|
|
||||||
|
contract ConnectGelatoDataForPartialRefinance is ConnectorInterface {
|
||||||
struct PartialDebtBridgePayload {
|
struct PartialDebtBridgePayload {
|
||||||
uint256 vaultId;
|
uint256 vaultId;
|
||||||
address token;
|
address token;
|
||||||
|
@ -56,16 +55,70 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
address provider;
|
address provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 public constant GAS_COST = 1490779 + (14908 * 2); // 1933080 + ~2% (Estimated Value)
|
using GelatoBytes for bytes;
|
||||||
|
|
||||||
// To retrieve when the connector is deployed and replace with the address of the deployed instance
|
// solhint-disable-next-line const-name-snakecase
|
||||||
address public immutable connectGelatoProviderPayment;
|
string public constant override name = "ConnectGelatoData-v1.0";
|
||||||
|
uint256 internal immutable _id;
|
||||||
|
address internal immutable _connectGelatoProviderPayment;
|
||||||
|
|
||||||
constructor(address _connectGelatoProviderPayment) {
|
uint256 public constant GAS_COST = 1490779 + (14908 * 2); // 1490779 + ~2% (Estimated Value)
|
||||||
connectGelatoProviderPayment = _connectGelatoProviderPayment;
|
|
||||||
|
constructor(uint256 id, address connectGelatoProviderPayment) {
|
||||||
|
_id = id;
|
||||||
|
_connectGelatoProviderPayment = connectGelatoProviderPayment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* solhint-disable function-max-lines */
|
/// @dev Connector Details
|
||||||
|
function connectorID()
|
||||||
|
public
|
||||||
|
view
|
||||||
|
override
|
||||||
|
returns (uint256 _type, uint256 id)
|
||||||
|
{
|
||||||
|
(_type, id) = (1, _id); // Should put specific value.
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataAndCastForFromMakerToMaker(
|
||||||
|
PartialDebtBridgePayload calldata _payload,
|
||||||
|
string memory _colType
|
||||||
|
) public payable {
|
||||||
|
(
|
||||||
|
address[] memory targets,
|
||||||
|
bytes[] memory datas
|
||||||
|
) = _execPayloadForPartialRefinanceFromMakerToMaker(_payload, _colType);
|
||||||
|
|
||||||
|
_cast(targets, datas);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataAndCastForFromMakerToCompound(
|
||||||
|
PartialDebtBridgePayload calldata _payload
|
||||||
|
) public payable {
|
||||||
|
(
|
||||||
|
address[] memory targets,
|
||||||
|
bytes[] memory datas
|
||||||
|
) = _execPayloadForPartialRefinanceFromMakerToCompound(_payload);
|
||||||
|
|
||||||
|
_cast(targets, datas);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _cast(address[] memory targets, bytes[] memory datas) internal {
|
||||||
|
// Instapool V2 / FlashLoan call
|
||||||
|
bytes memory castData = abi.encodeWithSelector(
|
||||||
|
AccountInterface.cast.selector,
|
||||||
|
targets,
|
||||||
|
datas,
|
||||||
|
msg.sender // msg.sender == GelatoCore
|
||||||
|
);
|
||||||
|
|
||||||
|
(bool success, bytes memory returndata) = address(this).delegatecall(
|
||||||
|
castData
|
||||||
|
);
|
||||||
|
if (!success)
|
||||||
|
returndata.revertWithError(
|
||||||
|
"ConnectGelatoDataForPartialRefinance._cast:"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// @notice Generate Task for a full refinancing between Maker to Compound.
|
/// @notice Generate Task for a full refinancing between Maker to Compound.
|
||||||
/// @param _payload contain :
|
/// @param _payload contain :
|
||||||
|
@ -80,9 +133,9 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
// @param _provider address of the paying provider.
|
// @param _provider address of the paying provider.
|
||||||
/// @return targets : flashloan contract address
|
/// @return targets : flashloan contract address
|
||||||
/// @return datas : calldata for flashloan
|
/// @return datas : calldata for flashloan
|
||||||
function execPayloadForPartialRefinanceFromMakerToCompound(
|
function _execPayloadForPartialRefinanceFromMakerToCompound(
|
||||||
PartialDebtBridgePayload calldata _payload
|
PartialDebtBridgePayload calldata _payload
|
||||||
) public view returns (address[] memory targets, bytes[] memory datas) {
|
) internal view returns (address[] memory targets, bytes[] memory datas) {
|
||||||
targets = new address[](1);
|
targets = new address[](1);
|
||||||
targets[0] = INSTA_POOL_V2;
|
targets[0] = INSTA_POOL_V2;
|
||||||
|
|
||||||
|
@ -90,7 +143,7 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
uint256 wDaiDebtToMove,
|
uint256 wDaiDebtToMove,
|
||||||
uint256 wColToWithdrawFromMaker,
|
uint256 wColToWithdrawFromMaker,
|
||||||
uint256 gasFeesPaidFromCol
|
uint256 gasFeesPaidFromCol
|
||||||
) = computeDebtBridge(
|
) = _computeDebtBridge(
|
||||||
_payload.vaultId,
|
_payload.vaultId,
|
||||||
_payload.wMinColRatioMaker,
|
_payload.wMinColRatioMaker,
|
||||||
_payload.wMinColRatioB,
|
_payload.wMinColRatioB,
|
||||||
|
@ -103,7 +156,7 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
_targets[1] = CONNECT_MAKER; // withdraw
|
_targets[1] = CONNECT_MAKER; // withdraw
|
||||||
_targets[2] = CONNECT_COMPOUND; // deposit
|
_targets[2] = CONNECT_COMPOUND; // deposit
|
||||||
_targets[3] = CONNECT_COMPOUND; // borrow
|
_targets[3] = CONNECT_COMPOUND; // borrow
|
||||||
_targets[4] = connectGelatoProviderPayment;
|
_targets[4] = _connectGelatoProviderPayment;
|
||||||
_targets[5] = INSTA_POOL_V2;
|
_targets[5] = INSTA_POOL_V2;
|
||||||
|
|
||||||
bytes[] memory _datas = new bytes[](6);
|
bytes[] memory _datas = new bytes[](6);
|
||||||
|
@ -159,10 +212,10 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
/// @param _colType colType of the new vault, exemple : ETH-B, ETH-A.
|
/// @param _colType colType of the new vault, exemple : ETH-B, ETH-A.
|
||||||
/// @return targets : flashloan contract address
|
/// @return targets : flashloan contract address
|
||||||
/// @return datas : calldata for flashloan
|
/// @return datas : calldata for flashloan
|
||||||
function execPayloadForPartialRefinanceFromMakerToMaker(
|
function _execPayloadForPartialRefinanceFromMakerToMaker(
|
||||||
PartialDebtBridgePayload calldata _payload,
|
PartialDebtBridgePayload calldata _payload,
|
||||||
string memory _colType
|
string memory _colType
|
||||||
) public view returns (address[] memory targets, bytes[] memory datas) {
|
) internal view returns (address[] memory targets, bytes[] memory datas) {
|
||||||
targets = new address[](1);
|
targets = new address[](1);
|
||||||
targets[0] = INSTA_POOL_V2;
|
targets[0] = INSTA_POOL_V2;
|
||||||
|
|
||||||
|
@ -170,7 +223,7 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
uint256 wDaiDebtToMove,
|
uint256 wDaiDebtToMove,
|
||||||
uint256 wColToWithdrawFromMaker,
|
uint256 wColToWithdrawFromMaker,
|
||||||
uint256 gasFeesPaidFromCol
|
uint256 gasFeesPaidFromCol
|
||||||
) = computeDebtBridge(
|
) = _computeDebtBridge(
|
||||||
_payload.vaultId,
|
_payload.vaultId,
|
||||||
_payload.wMinColRatioMaker,
|
_payload.wMinColRatioMaker,
|
||||||
_payload.wMinColRatioB,
|
_payload.wMinColRatioB,
|
||||||
|
@ -184,7 +237,7 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
_targets[2] = CONNECT_MAKER; // open ETH-B vault
|
_targets[2] = CONNECT_MAKER; // open ETH-B vault
|
||||||
_targets[3] = CONNECT_MAKER; // deposit
|
_targets[3] = CONNECT_MAKER; // deposit
|
||||||
_targets[4] = CONNECT_MAKER; // borrow
|
_targets[4] = CONNECT_MAKER; // borrow
|
||||||
_targets[5] = connectGelatoProviderPayment;
|
_targets[5] = _connectGelatoProviderPayment;
|
||||||
_targets[6] = INSTA_POOL_V2;
|
_targets[6] = INSTA_POOL_V2;
|
||||||
|
|
||||||
bytes[] memory _datas = new bytes[](7);
|
bytes[] memory _datas = new bytes[](7);
|
||||||
|
@ -227,8 +280,6 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* solhint-enable function-max-lines */
|
|
||||||
|
|
||||||
/// @notice Computes values needed for DebtBridge Maker->ProtocolB
|
/// @notice Computes values needed for DebtBridge Maker->ProtocolB
|
||||||
/// @dev Use wad for colRatios.
|
/// @dev Use wad for colRatios.
|
||||||
/// @param _vaultId The id of the makerDAO vault.
|
/// @param _vaultId The id of the makerDAO vault.
|
||||||
|
@ -242,16 +293,15 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
/// @return wColToWithdrawFromMaker (wad) to: withdraw from Maker and deposit on B.
|
/// @return wColToWithdrawFromMaker (wad) to: withdraw from Maker and deposit on B.
|
||||||
/// @return gasFeesPaidFromCol Gelato automation-gas-fees paid from user's collateral
|
/// @return gasFeesPaidFromCol Gelato automation-gas-fees paid from user's collateral
|
||||||
// solhint-disable function-max-lines
|
// solhint-disable function-max-lines
|
||||||
function computeDebtBridge(
|
function _computeDebtBridge(
|
||||||
uint256 _vaultId,
|
uint256 _vaultId,
|
||||||
uint256 _wMinColRatioMaker,
|
uint256 _wMinColRatioMaker,
|
||||||
uint256 _wMinColRatioB,
|
uint256 _wMinColRatioB,
|
||||||
address _priceOracle,
|
address _priceOracle,
|
||||||
bytes calldata _oraclePayload
|
bytes calldata _oraclePayload
|
||||||
)
|
)
|
||||||
public
|
internal
|
||||||
view
|
view
|
||||||
virtual
|
|
||||||
returns (
|
returns (
|
||||||
uint256 wDaiDebtToMove,
|
uint256 wDaiDebtToMove,
|
||||||
uint256 wColToWithdrawFromMaker,
|
uint256 wColToWithdrawFromMaker,
|
||||||
|
@ -267,7 +317,8 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
returndata.revertWithError(
|
GelatoBytes.revertWithError(
|
||||||
|
returndata,
|
||||||
"ConnectGelatoPartialDebtBridgeFromMaker.computeDebtBridge:oracle:"
|
"ConnectGelatoPartialDebtBridgeFromMaker.computeDebtBridge:oracle:"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -286,7 +337,7 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
|
|
||||||
uint256 wDaiDebtOnMaker = _getMakerVaultDebt(_vaultId);
|
uint256 wDaiDebtOnMaker = _getMakerVaultDebt(_vaultId);
|
||||||
|
|
||||||
wColToWithdrawFromMaker = wCalcCollateralToWithdraw(
|
wColToWithdrawFromMaker = _wCalcCollateralToWithdraw(
|
||||||
_wMinColRatioMaker,
|
_wMinColRatioMaker,
|
||||||
_wMinColRatioB,
|
_wMinColRatioB,
|
||||||
wColPrice,
|
wColPrice,
|
||||||
|
@ -294,131 +345,11 @@ contract DebtBridgeFromMakerForPartialRefinance {
|
||||||
wDaiDebtOnMaker
|
wDaiDebtOnMaker
|
||||||
);
|
);
|
||||||
|
|
||||||
wDaiDebtToMove = wCalcDebtToRepay(
|
wDaiDebtToMove = _wCalcDebtToRepay(
|
||||||
_wMinColRatioMaker,
|
_wMinColRatioMaker,
|
||||||
_wMinColRatioB,
|
_wMinColRatioB,
|
||||||
wPricedCol,
|
wPricedCol,
|
||||||
wDaiDebtOnMaker
|
wDaiDebtOnMaker
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Compute collateral (wad) to move from Maker to B.
|
|
||||||
/// @dev Convenience API for frontends - check _wCalcDebtToRepay for implementation
|
|
||||||
/// @param _wMinColRatioMaker Min col ratio (wad) on Maker debt position
|
|
||||||
/// @param _wMinColRatioB Min col ratio (wad) on debt position B (e.g. Compound, Maker, ...)
|
|
||||||
/// @param _wColPrice Price of the collateral (wad) in oracle price units.
|
|
||||||
/// @param _wPricedCol Collateral to move (wad) valued in oracle price.
|
|
||||||
/// @param _wDaiDebtOnMaker Amount of DAI (wad) borrowed from Maker.
|
|
||||||
/// @return collateral to withdraw from A in wad
|
|
||||||
function wCalcCollateralToWithdraw(
|
|
||||||
uint256 _wMinColRatioMaker,
|
|
||||||
uint256 _wMinColRatioB,
|
|
||||||
uint256 _wColPrice,
|
|
||||||
uint256 _wPricedCol,
|
|
||||||
uint256 _wDaiDebtOnMaker
|
|
||||||
) public pure virtual returns (uint256) {
|
|
||||||
return
|
|
||||||
_wCalcCollateralToWithdraw(
|
|
||||||
_wMinColRatioMaker,
|
|
||||||
_wMinColRatioB,
|
|
||||||
_wColPrice,
|
|
||||||
_wPricedCol,
|
|
||||||
_wDaiDebtOnMaker
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @notice Compute debt (wad) to flashBorrow->repay Maker->withdraw from B->flashPayback
|
|
||||||
/// @dev Convenience API for frontends - check _wCalcDebtToRepay for implementation.
|
|
||||||
/// @param _wMinColRatioMaker Min col ratio (wad) on Maker debt position
|
|
||||||
/// @param _wMinColRatioB Min col ratio (wad) on debt position B (e.g. Compound, Maker, ...)
|
|
||||||
/// @param _wPricedCol Collateral to move (wad) valued in oracle price.
|
|
||||||
/// @param _wDaiDebtOnMaker Amount of DAI (wad) borrowed from Maker.
|
|
||||||
/// @return amount of borrowed token to pay back in wad
|
|
||||||
function wCalcDebtToRepay(
|
|
||||||
uint256 _wMinColRatioMaker,
|
|
||||||
uint256 _wMinColRatioB,
|
|
||||||
uint256 _wPricedCol,
|
|
||||||
uint256 _wDaiDebtOnMaker
|
|
||||||
) public pure virtual returns (uint256) {
|
|
||||||
return
|
|
||||||
_wCalcDebtToRepay(
|
|
||||||
_wMinColRatioMaker,
|
|
||||||
_wMinColRatioB,
|
|
||||||
_wPricedCol,
|
|
||||||
_wDaiDebtOnMaker
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @notice Generate Data for calling execPayloadForPartialRefinanceFromMakerToMaker via a static call.
|
|
||||||
/// @param _vaultId Id of the unsafe vault of the client.
|
|
||||||
/// @param _token vault's col token address .
|
|
||||||
/// @param _wMinColRatioMaker Min col ratio (wad) on Maker debt position
|
|
||||||
/// @param _wMinColRatioB Min col ratio (wad) on debt position B (e.g. Compound, Maker, ...)
|
|
||||||
/// @param _priceOracle The price oracle contract to supply the collateral price
|
|
||||||
/// e.g. Maker's ETH/USD oracle for ETH collateral pricing.
|
|
||||||
/// @param _oraclePayload The data for making the staticcall to the oracle's read
|
|
||||||
/// method e.g. the function selector of MakerOracle's read function.
|
|
||||||
/// @param _colType colType of the new vault, exemple : ETH-B, ETH-A.
|
|
||||||
/// @param _provider address of the paying provider.
|
|
||||||
/// @return payload for execPayloadForPartialRefinanceFromMakerToMaker.
|
|
||||||
function getDebtBridgePartialRefinanceMakerToMakerData(
|
|
||||||
uint256 _vaultId,
|
|
||||||
address _token,
|
|
||||||
uint256 _wMinColRatioMaker,
|
|
||||||
uint256 _wMinColRatioB,
|
|
||||||
address _priceOracle,
|
|
||||||
bytes calldata _oraclePayload,
|
|
||||||
string memory _colType,
|
|
||||||
address _provider
|
|
||||||
) public pure returns (bytes memory) {
|
|
||||||
return
|
|
||||||
abi.encodeWithSelector(
|
|
||||||
this.execPayloadForPartialRefinanceFromMakerToMaker.selector,
|
|
||||||
PartialDebtBridgePayload({
|
|
||||||
vaultId: _vaultId,
|
|
||||||
token: _token,
|
|
||||||
wMinColRatioMaker: _wMinColRatioMaker,
|
|
||||||
wMinColRatioB: _wMinColRatioB,
|
|
||||||
priceOracle: _priceOracle,
|
|
||||||
oraclePayload: _oraclePayload,
|
|
||||||
provider: _provider
|
|
||||||
}),
|
|
||||||
_colType
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @notice Generate Data for calling execPayloadForPartialRefinanceFromMakerToCompound via a static call.
|
|
||||||
/// @param _vaultId Id of the unsafe vault of the client.
|
|
||||||
/// @param _token vault's col token address .
|
|
||||||
/// @param _wMinColRatioMaker Min col ratio (wad) on Maker debt position
|
|
||||||
/// @param _wMinColRatioB Min col ratio (wad) on debt position B (e.g. Compound, Maker, ...)
|
|
||||||
/// @param _priceOracle The price oracle contract to supply the collateral price
|
|
||||||
/// e.g. Maker's ETH/USD oracle for ETH collateral pricing.
|
|
||||||
/// @param _oraclePayload The data for making the staticcall to the oracle's read
|
|
||||||
/// method e.g. the function selector of MakerOracle's read function.
|
|
||||||
/// @param _provider address of the paying provider.
|
|
||||||
/// @return a call data for a static call of execPayloadForPartialRefinanceFromMakerToMaker.
|
|
||||||
function getDebtBridgePartialRefinanceMakerToCompoundData(
|
|
||||||
uint256 _vaultId,
|
|
||||||
address _token,
|
|
||||||
uint256 _wMinColRatioMaker,
|
|
||||||
uint256 _wMinColRatioB,
|
|
||||||
address _priceOracle,
|
|
||||||
bytes calldata _oraclePayload,
|
|
||||||
address _provider
|
|
||||||
) public pure returns (bytes memory) {
|
|
||||||
return
|
|
||||||
abi.encodeWithSelector(
|
|
||||||
this.execPayloadForPartialRefinanceFromMakerToCompound.selector,
|
|
||||||
PartialDebtBridgePayload({
|
|
||||||
vaultId: _vaultId,
|
|
||||||
token: _token,
|
|
||||||
wMinColRatioMaker: _wMinColRatioMaker,
|
|
||||||
wMinColRatioB: _wMinColRatioB,
|
|
||||||
priceOracle: _priceOracle,
|
|
||||||
oraclePayload: _oraclePayload,
|
|
||||||
provider: _provider
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -10,9 +10,8 @@ import {
|
||||||
} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoCore.sol";
|
} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoCore.sol";
|
||||||
import {AccountInterface} from "../../../interfaces/InstaDapp/IInstaDapp.sol";
|
import {AccountInterface} from "../../../interfaces/InstaDapp/IInstaDapp.sol";
|
||||||
import {
|
import {
|
||||||
DebtBridgeFromMakerForFullRefinance
|
ConnectGelatoDataForFullRefinance
|
||||||
} from "../../gelato/data_generators/DebtBridgeFromMakerForFullRefinance.sol";
|
} from "../../connectors/ConnectGelatoDataForFullRefinance.sol";
|
||||||
import {ConnectGelatoData} from "../../connectors/ConnectGelatoData.sol";
|
|
||||||
|
|
||||||
/// @notice Gelato Provider Module for the InstaDapp DSA
|
/// @notice Gelato Provider Module for the InstaDapp DSA
|
||||||
/// @dev Used by Provider to sanity check any third-party Tasks they pay for
|
/// @dev Used by Provider to sanity check any third-party Tasks they pay for
|
||||||
|
@ -110,23 +109,18 @@ contract ProviderModuleDsaFromMakerToCompound is GelatoProviderModuleStandard {
|
||||||
pure
|
pure
|
||||||
returns (bytes memory)
|
returns (bytes memory)
|
||||||
{
|
{
|
||||||
address target = abi.decode(_data[4:36], (address));
|
|
||||||
(uint256 vaultId, address token, ) = abi.decode(
|
(uint256 vaultId, address token, ) = abi.decode(
|
||||||
_data[104:],
|
_data[4:],
|
||||||
(uint256, address, address)
|
(uint256, address, address)
|
||||||
);
|
);
|
||||||
return
|
return
|
||||||
abi.encodeWithSelector(
|
abi.encodeWithSelector(
|
||||||
ConnectGelatoData.getDataAndCast.selector,
|
ConnectGelatoDataForFullRefinance
|
||||||
target,
|
.getDataAndCastForFromMakerToCompound
|
||||||
abi.encodeWithSelector(
|
|
||||||
DebtBridgeFromMakerForFullRefinance
|
|
||||||
.execPayloadForFullRefinanceFromMakerToCompound
|
|
||||||
.selector,
|
.selector,
|
||||||
vaultId,
|
vaultId,
|
||||||
token,
|
token,
|
||||||
_provider
|
_provider
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,9 +10,8 @@ import {
|
||||||
} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoCore.sol";
|
} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoCore.sol";
|
||||||
import {AccountInterface} from "../../../interfaces/InstaDapp/IInstaDapp.sol";
|
import {AccountInterface} from "../../../interfaces/InstaDapp/IInstaDapp.sol";
|
||||||
import {
|
import {
|
||||||
DebtBridgeFromMakerForFullRefinance
|
ConnectGelatoDataForFullRefinance
|
||||||
} from "../../gelato/data_generators/DebtBridgeFromMakerForFullRefinance.sol";
|
} from "../../connectors/ConnectGelatoDataForFullRefinance.sol";
|
||||||
import {ConnectGelatoData} from "../../connectors/ConnectGelatoData.sol";
|
|
||||||
|
|
||||||
/// @notice Gelato Provider Module for the InstaDapp DSA
|
/// @notice Gelato Provider Module for the InstaDapp DSA
|
||||||
/// @dev Used by Provider to sanity check any third-party Tasks they pay for
|
/// @dev Used by Provider to sanity check any third-party Tasks they pay for
|
||||||
|
@ -110,26 +109,19 @@ contract ProviderModuleDsaFromMakerToMaker is GelatoProviderModuleStandard {
|
||||||
pure
|
pure
|
||||||
returns (bytes memory)
|
returns (bytes memory)
|
||||||
{
|
{
|
||||||
address target = abi.decode(_data[4:36], (address));
|
|
||||||
|
|
||||||
(uint256 vaultId, address token, string memory colType, ) = abi.decode(
|
(uint256 vaultId, address token, string memory colType, ) = abi.decode(
|
||||||
_data[104:],
|
_data[4:],
|
||||||
(uint256, address, string, address)
|
(uint256, address, string, address)
|
||||||
);
|
);
|
||||||
|
|
||||||
return
|
return
|
||||||
abi.encodeWithSelector(
|
abi.encodeWithSelector(
|
||||||
ConnectGelatoData.getDataAndCast.selector,
|
ConnectGelatoDataForFullRefinance
|
||||||
target,
|
.getDataAndCastForFromMakerToMaker
|
||||||
abi.encodeWithSelector(
|
|
||||||
DebtBridgeFromMakerForFullRefinance
|
|
||||||
.execPayloadForFullRefinanceFromMakerToMaker
|
|
||||||
.selector,
|
.selector,
|
||||||
vaultId,
|
vaultId,
|
||||||
token,
|
token,
|
||||||
colType,
|
colType,
|
||||||
_provider
|
_provider
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
41
contracts/mocks/FGelatoDebtBridgeMock.sol
Normal file
41
contracts/mocks/FGelatoDebtBridgeMock.sol
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
// SPDX-License-Identifier: UNLICENSED
|
||||||
|
pragma solidity 0.7.4;
|
||||||
|
|
||||||
|
import {
|
||||||
|
_wCalcCollateralToWithdraw,
|
||||||
|
_wCalcDebtToRepay
|
||||||
|
} from "../functions/gelato/FGelatoDebtBridge.sol";
|
||||||
|
|
||||||
|
contract FGelatoDebtBridgeMock {
|
||||||
|
function wCalcCollateralToWithdraw(
|
||||||
|
uint256 _wMinColRatioMaker,
|
||||||
|
uint256 _wMinColRatioB,
|
||||||
|
uint256 _wColPrice,
|
||||||
|
uint256 _wPricedCol,
|
||||||
|
uint256 _wDaiDebtOnMaker
|
||||||
|
) public pure returns (uint256) {
|
||||||
|
return
|
||||||
|
_wCalcCollateralToWithdraw(
|
||||||
|
_wMinColRatioMaker,
|
||||||
|
_wMinColRatioB,
|
||||||
|
_wColPrice,
|
||||||
|
_wPricedCol,
|
||||||
|
_wDaiDebtOnMaker
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wCalcDebtToRepay(
|
||||||
|
uint256 _wMinColRatioMaker,
|
||||||
|
uint256 _wMinColRatioB,
|
||||||
|
uint256 _wPricedCol,
|
||||||
|
uint256 _wDaiDebtOnMaker
|
||||||
|
) public pure returns (uint256) {
|
||||||
|
return
|
||||||
|
_wCalcDebtToRepay(
|
||||||
|
_wMinColRatioMaker,
|
||||||
|
_wMinColRatioB,
|
||||||
|
_wPricedCol,
|
||||||
|
_wDaiDebtOnMaker
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ const getABI = require("./setups/ABI.helper");
|
||||||
const getAllContracts = require("./setups/Contracts-For-Full-Refinancing-Maker-To-Compound.helper");
|
const getAllContracts = require("./setups/Contracts-For-Full-Refinancing-Maker-To-Compound.helper");
|
||||||
const enableGelatoConnectorsForFromMaker = require("./setups/Enabling-New-Connectors-For-Full-Refinance.helper");
|
const enableGelatoConnectorsForFromMaker = require("./setups/Enabling-New-Connectors-For-Full-Refinance.helper");
|
||||||
|
|
||||||
const ConnectGelatoDataABI = require("../../artifacts/contracts/contracts/connectors/ConnectGelatoData.sol/ConnectGelatoData.json")
|
const ConnectGelatoDataForFullRefinance = require("../../artifacts/contracts/contracts/connectors/ConnectGelatoDataForFullRefinance.sol/ConnectGelatoDataForFullRefinance.json")
|
||||||
.abi;
|
.abi;
|
||||||
|
|
||||||
async function makerToCompoundSetup() {
|
async function makerToCompoundSetup() {
|
||||||
|
@ -96,20 +96,14 @@ async function providerWhiteListTaskForMakerToCompound(
|
||||||
|
|
||||||
//#region Actions
|
//#region Actions
|
||||||
|
|
||||||
const data = await contracts.debtBridgeFromMakerForFullRefinance.getDebtBridgeFullRefinanceMakerToCompoundData(
|
|
||||||
vaultId,
|
|
||||||
constants.ETH,
|
|
||||||
wallets.providerAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const spells = [];
|
const spells = [];
|
||||||
|
|
||||||
const debtBridgeCalculationForFullRefinance = new GelatoCoreLib.Action({
|
const debtBridgeCalculationForFullRefinance = new GelatoCoreLib.Action({
|
||||||
addr: contracts.connectGelatoData.address,
|
addr: contracts.connectGelatoData.address,
|
||||||
data: await hre.run("abi-encode-withselector", {
|
data: await hre.run("abi-encode-withselector", {
|
||||||
abi: ConnectGelatoDataABI,
|
abi: ConnectGelatoDataForFullRefinance,
|
||||||
functionname: "getDataAndCast",
|
functionname: "getDataAndCastForFromMakerToCompound",
|
||||||
inputs: [contracts.debtBridgeFromMakerForFullRefinance.address, data],
|
inputs: [vaultId, constants.ETH, wallets.providerAddress],
|
||||||
}),
|
}),
|
||||||
operation: GelatoCoreLib.Operation.Delegatecall,
|
operation: GelatoCoreLib.Operation.Delegatecall,
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,7 +16,7 @@ const getABI = require("./setups/ABI.helper");
|
||||||
const getAllContracts = require("./setups/Contracts-For-Full-Refinancing-Maker-To-Maker.helper");
|
const getAllContracts = require("./setups/Contracts-For-Full-Refinancing-Maker-To-Maker.helper");
|
||||||
const enableGelatoConnectorsForFromMaker = require("./setups/Enabling-New-Connectors-For-Full-Refinance.helper");
|
const enableGelatoConnectorsForFromMaker = require("./setups/Enabling-New-Connectors-For-Full-Refinance.helper");
|
||||||
|
|
||||||
const ConnectGelatoDataABI = require("../../artifacts/contracts/contracts/connectors/ConnectGelatoData.sol/ConnectGelatoData.json")
|
const ConnectGelatoDataForFullRefinance = require("../../artifacts/contracts/contracts/connectors/ConnectGelatoDataForFullRefinance.sol/ConnectGelatoDataForFullRefinance.json")
|
||||||
.abi;
|
.abi;
|
||||||
|
|
||||||
async function makerETHAToMakerETHBSetup() {
|
async function makerETHAToMakerETHBSetup() {
|
||||||
|
@ -102,21 +102,14 @@ async function providerWhiteListTaskForMakerETHAToMakerETHB(
|
||||||
|
|
||||||
//#region Actions
|
//#region Actions
|
||||||
|
|
||||||
const data = await contracts.debtBridgeFromMakerForFullRefinance.getDebtBridgeFullRefinanceMakerToMakerData(
|
|
||||||
vaultId,
|
|
||||||
constants.ETH,
|
|
||||||
"ETH-B",
|
|
||||||
wallets.providerAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const spells = [];
|
const spells = [];
|
||||||
|
|
||||||
const debtBridgeCalculationForFullRefinance = new GelatoCoreLib.Action({
|
const debtBridgeCalculationForFullRefinance = new GelatoCoreLib.Action({
|
||||||
addr: contracts.connectGelatoData.address,
|
addr: contracts.connectGelatoData.address,
|
||||||
data: await hre.run("abi-encode-withselector", {
|
data: await hre.run("abi-encode-withselector", {
|
||||||
abi: ConnectGelatoDataABI,
|
abi: ConnectGelatoDataForFullRefinance,
|
||||||
functionname: "getDataAndCast",
|
functionname: "getDataAndCastForFromMakerToMaker",
|
||||||
inputs: [contracts.debtBridgeFromMakerForFullRefinance.address, data],
|
inputs: [vaultId, constants.ETH, "ETH-B", wallets.providerAddress],
|
||||||
}),
|
}),
|
||||||
operation: GelatoCoreLib.Operation.Delegatecall,
|
operation: GelatoCoreLib.Operation.Delegatecall,
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,26 +4,18 @@ const {ethers} = hre;
|
||||||
const getContracts = require("./Common-Contracts.helper");
|
const getContracts = require("./Common-Contracts.helper");
|
||||||
|
|
||||||
async function getAllContracts() {
|
async function getAllContracts() {
|
||||||
let connectGelatoData;
|
|
||||||
let debtBridgeFromMakerForFullRefinance;
|
|
||||||
let dsaProviderModule;
|
let dsaProviderModule;
|
||||||
|
let connectGelatoData;
|
||||||
let contracts = await getContracts();
|
let contracts = await getContracts();
|
||||||
|
|
||||||
const ConnectGelatoData = await ethers.getContractFactory(
|
const ConnectGelatoData = await ethers.getContractFactory(
|
||||||
"ConnectGelatoData"
|
"ConnectGelatoDataForFullRefinance"
|
||||||
);
|
);
|
||||||
connectGelatoData = await ConnectGelatoData.deploy(
|
connectGelatoData = await ConnectGelatoData.deploy(
|
||||||
(await contracts.instaConnectors.connectorLength()).add(1)
|
(await contracts.instaConnectors.connectorLength()).add(1),
|
||||||
);
|
|
||||||
await connectGelatoData.deployed();
|
|
||||||
|
|
||||||
const DebtBridgeFromMakerForFullRefinance = await ethers.getContractFactory(
|
|
||||||
"DebtBridgeFromMakerForFullRefinance"
|
|
||||||
);
|
|
||||||
debtBridgeFromMakerForFullRefinance = await DebtBridgeFromMakerForFullRefinance.deploy(
|
|
||||||
contracts.connectGelatoProviderPayment.address
|
contracts.connectGelatoProviderPayment.address
|
||||||
);
|
);
|
||||||
await debtBridgeFromMakerForFullRefinance.deployed();
|
await connectGelatoData.deployed();
|
||||||
|
|
||||||
const ProviderModuleDsa = await ethers.getContractFactory(
|
const ProviderModuleDsa = await ethers.getContractFactory(
|
||||||
"ProviderModuleDsaFromMakerToCompound"
|
"ProviderModuleDsaFromMakerToCompound"
|
||||||
|
@ -34,9 +26,8 @@ async function getAllContracts() {
|
||||||
);
|
);
|
||||||
await dsaProviderModule.deployed();
|
await dsaProviderModule.deployed();
|
||||||
|
|
||||||
contracts.connectGelatoData = connectGelatoData;
|
|
||||||
contracts.debtBridgeFromMakerForFullRefinance = debtBridgeFromMakerForFullRefinance;
|
|
||||||
contracts.dsaProviderModule = dsaProviderModule;
|
contracts.dsaProviderModule = dsaProviderModule;
|
||||||
|
contracts.connectGelatoData = connectGelatoData;
|
||||||
|
|
||||||
return contracts;
|
return contracts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,26 +4,18 @@ const {ethers} = hre;
|
||||||
const getContracts = require("./Common-Contracts.helper");
|
const getContracts = require("./Common-Contracts.helper");
|
||||||
|
|
||||||
async function getAllContracts() {
|
async function getAllContracts() {
|
||||||
let connectGelatoData;
|
|
||||||
let debtBridgeFromMakerForFullRefinance;
|
|
||||||
let dsaProviderModule;
|
let dsaProviderModule;
|
||||||
|
let connectGelatoData;
|
||||||
let contracts = await getContracts();
|
let contracts = await getContracts();
|
||||||
|
|
||||||
const ConnectGelatoData = await ethers.getContractFactory(
|
const ConnectGelatoData = await ethers.getContractFactory(
|
||||||
"ConnectGelatoData"
|
"ConnectGelatoDataForFullRefinance"
|
||||||
);
|
);
|
||||||
connectGelatoData = await ConnectGelatoData.deploy(
|
connectGelatoData = await ConnectGelatoData.deploy(
|
||||||
(await contracts.instaConnectors.connectorLength()).add(1)
|
(await contracts.instaConnectors.connectorLength()).add(1),
|
||||||
);
|
|
||||||
await connectGelatoData.deployed();
|
|
||||||
|
|
||||||
const DebtBridgeFromMakerForFullRefinance = await ethers.getContractFactory(
|
|
||||||
"DebtBridgeFromMakerForFullRefinance"
|
|
||||||
);
|
|
||||||
debtBridgeFromMakerForFullRefinance = await DebtBridgeFromMakerForFullRefinance.deploy(
|
|
||||||
contracts.connectGelatoProviderPayment.address
|
contracts.connectGelatoProviderPayment.address
|
||||||
);
|
);
|
||||||
await debtBridgeFromMakerForFullRefinance.deployed();
|
await connectGelatoData.deployed();
|
||||||
|
|
||||||
const ProviderModuleDsa = await ethers.getContractFactory(
|
const ProviderModuleDsa = await ethers.getContractFactory(
|
||||||
"ProviderModuleDsaFromMakerToMaker"
|
"ProviderModuleDsaFromMakerToMaker"
|
||||||
|
@ -34,9 +26,8 @@ async function getAllContracts() {
|
||||||
);
|
);
|
||||||
await dsaProviderModule.deployed();
|
await dsaProviderModule.deployed();
|
||||||
|
|
||||||
contracts.connectGelatoData = connectGelatoData;
|
|
||||||
contracts.debtBridgeFromMakerForFullRefinance = debtBridgeFromMakerForFullRefinance;
|
|
||||||
contracts.dsaProviderModule = dsaProviderModule;
|
contracts.dsaProviderModule = dsaProviderModule;
|
||||||
|
contracts.connectGelatoData = connectGelatoData;
|
||||||
|
|
||||||
return contracts;
|
return contracts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,15 +23,16 @@ describe("Debt Partial Refinance Math Unit Test", function () {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let debtBridgeFromMakerForPartialRefinance;
|
let fGelatoDebtBridgeMock;
|
||||||
before(async function () {
|
before(async function () {
|
||||||
const DebtBridgeFromMakerForPartialRefinance = await ethers.getContractFactory(
|
const FGelatoDebtBridgeMock = await ethers.getContractFactory(
|
||||||
"DebtBridgeFromMakerForPartialRefinance"
|
"FGelatoDebtBridgeMock"
|
||||||
);
|
);
|
||||||
debtBridgeFromMakerForPartialRefinance = await DebtBridgeFromMakerForPartialRefinance.deploy(
|
fGelatoDebtBridgeMock = await FGelatoDebtBridgeMock
|
||||||
ethers.constants.AddressZero
|
.deploy
|
||||||
);
|
//ethers.constants.AddressZero
|
||||||
debtBridgeFromMakerForPartialRefinance.deployed();
|
();
|
||||||
|
fGelatoDebtBridgeMock.deployed();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("#1: wCalcCollateralToWithdraw should return the amount of collateral to withdraw on protocol 1 and to put on protocol 2", async function () {
|
it("#1: wCalcCollateralToWithdraw should return the amount of collateral to withdraw on protocol 1 and to put on protocol 2", async function () {
|
||||||
|
@ -73,7 +74,7 @@ describe("Debt Partial Refinance Math Unit Test", function () {
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await debtBridgeFromMakerForPartialRefinance.wCalcCollateralToWithdraw(
|
await fGelatoDebtBridgeMock.wCalcCollateralToWithdraw(
|
||||||
minColRatioOnMaker,
|
minColRatioOnMaker,
|
||||||
minColRatioOnPositionB,
|
minColRatioOnPositionB,
|
||||||
collateralPrice,
|
collateralPrice,
|
||||||
|
@ -123,7 +124,7 @@ describe("Debt Partial Refinance Math Unit Test", function () {
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
await debtBridgeFromMakerForPartialRefinance.wCalcDebtToRepay(
|
await fGelatoDebtBridgeMock.wCalcDebtToRepay(
|
||||||
minColRatioOnMaker,
|
minColRatioOnMaker,
|
||||||
minColRatioOnPositionB,
|
minColRatioOnPositionB,
|
||||||
collateral,
|
collateral,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user