mirror of
https://github.com/Instadapp/Gelato-automations.git
synced 2024-07-29 22:28:07 +00:00
Define provider in the payment connector
This commit is contained in:
parent
4f6b16b7da
commit
c76f495c9c
|
@ -68,8 +68,7 @@ contract ConnectGelatoDataForFullRefinance is ConnectorInterface {
|
|||
function getDataAndCastForFromMakerToMaker(
|
||||
uint256 _vaultId,
|
||||
address _token,
|
||||
string calldata _colType,
|
||||
address _provider
|
||||
string calldata _colType
|
||||
) public payable {
|
||||
(
|
||||
address[] memory targets,
|
||||
|
@ -77,8 +76,7 @@ contract ConnectGelatoDataForFullRefinance is ConnectorInterface {
|
|||
) = _execPayloadForFullRefinanceFromMakerToMaker(
|
||||
_vaultId,
|
||||
_token,
|
||||
_colType,
|
||||
_provider
|
||||
_colType
|
||||
);
|
||||
|
||||
_cast(targets, datas);
|
||||
|
@ -86,17 +84,12 @@ contract ConnectGelatoDataForFullRefinance is ConnectorInterface {
|
|||
|
||||
function getDataAndCastForFromMakerToCompound(
|
||||
uint256 _vaultId,
|
||||
address _token,
|
||||
address _provider
|
||||
address _token
|
||||
) public payable {
|
||||
(
|
||||
address[] memory targets,
|
||||
bytes[] memory datas
|
||||
) = _execPayloadForFullRefinanceFromMakerToCompound(
|
||||
_vaultId,
|
||||
_token,
|
||||
_provider
|
||||
);
|
||||
) = _execPayloadForFullRefinanceFromMakerToCompound(_vaultId, _token);
|
||||
|
||||
_cast(targets, datas);
|
||||
}
|
||||
|
@ -124,13 +117,11 @@ contract ConnectGelatoDataForFullRefinance is ConnectorInterface {
|
|||
/// @notice Generate Task for a full refinancing between Maker to Compound.
|
||||
/// @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 targets : flashloan contract address
|
||||
/// @return datas : calldata for flashloan
|
||||
function _execPayloadForFullRefinanceFromMakerToCompound(
|
||||
uint256 _vaultId,
|
||||
address _token,
|
||||
address _provider
|
||||
address _token
|
||||
) internal view returns (address[] memory targets, bytes[] memory datas) {
|
||||
targets = new address[](1);
|
||||
targets[0] = INSTA_POOL_V2;
|
||||
|
@ -159,13 +150,7 @@ contract ConnectGelatoDataForFullRefinance is ConnectorInterface {
|
|||
0
|
||||
);
|
||||
_datas[3] = _encodeBorrowCompound(DAI, wDaiDebtToMove, 0, 0);
|
||||
_datas[4] = _encodePayGelatoProvider(
|
||||
_provider,
|
||||
_token,
|
||||
gasFeesPaidFromCol,
|
||||
0,
|
||||
0
|
||||
);
|
||||
_datas[4] = _encodePayGelatoProvider(_token, gasFeesPaidFromCol, 0, 0);
|
||||
_datas[5] = _encodeFlashPayback(DAI, wDaiDebtToMove, 0, 0);
|
||||
|
||||
datas = new bytes[](1);
|
||||
|
@ -182,14 +167,12 @@ contract ConnectGelatoDataForFullRefinance is ConnectorInterface {
|
|||
/// @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 targets : flashloan contract address
|
||||
/// @return datas : calldata for flashloan
|
||||
function _execPayloadForFullRefinanceFromMakerToMaker(
|
||||
uint256 _vaultId,
|
||||
address _token,
|
||||
string calldata _colType,
|
||||
address _provider
|
||||
string calldata _colType
|
||||
) internal view returns (address[] memory targets, bytes[] memory datas) {
|
||||
targets = new address[](1);
|
||||
targets[0] = INSTA_POOL_V2;
|
||||
|
@ -220,13 +203,7 @@ contract ConnectGelatoDataForFullRefinance is ConnectorInterface {
|
|||
0
|
||||
);
|
||||
_datas[4] = _encodeBorrowDaiMakerVault(0, wDaiDebtToMove, 0, 0);
|
||||
_datas[5] = _encodePayGelatoProvider(
|
||||
_provider,
|
||||
_token,
|
||||
gasFeesPaidFromCol,
|
||||
0,
|
||||
0
|
||||
);
|
||||
_datas[5] = _encodePayGelatoProvider(_token, gasFeesPaidFromCol, 0, 0);
|
||||
_datas[6] = _encodeFlashPayback(DAI, wDaiDebtToMove, 0, 0);
|
||||
|
||||
datas = new bytes[](1);
|
||||
|
|
|
@ -52,7 +52,6 @@ contract ConnectGelatoDataForPartialRefinance is ConnectorInterface {
|
|||
uint256 wMinColRatioB;
|
||||
address priceOracle;
|
||||
bytes oraclePayload;
|
||||
address provider;
|
||||
}
|
||||
|
||||
using GelatoBytes for bytes;
|
||||
|
@ -182,7 +181,6 @@ contract ConnectGelatoDataForPartialRefinance is ConnectorInterface {
|
|||
);
|
||||
_datas[3] = _encodeBorrowCompound(DAI, wDaiDebtToMove, 0, 0);
|
||||
_datas[4] = _encodePayGelatoProvider(
|
||||
_payload.provider,
|
||||
_payload.token,
|
||||
gasFeesPaidFromCol,
|
||||
0,
|
||||
|
@ -264,7 +262,6 @@ contract ConnectGelatoDataForPartialRefinance is ConnectorInterface {
|
|||
);
|
||||
_datas[4] = _encodeBorrowDaiMakerVault(0, wDaiDebtToMove, 0, 0);
|
||||
_datas[5] = _encodePayGelatoProvider(
|
||||
_payload.provider,
|
||||
_payload.token,
|
||||
gasFeesPaidFromCol,
|
||||
0,
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity 0.7.4;
|
||||
|
||||
import {ConnectorInterface} from "../../interfaces/InstaDapp/IInstaDapp.sol";
|
||||
import {
|
||||
IConnectGelatoProviderPayment
|
||||
} from "../../interfaces/InstaDapp/connectors/IConnectGelatoProviderPayment.sol";
|
||||
import {Address} from "../../vendor/Address.sol";
|
||||
import {IERC20} from "../../interfaces/tokens/IERC20.sol";
|
||||
import {SafeERC20} from "../../vendor/SafeERC20.sol";
|
||||
import {getUint, setUint} from "../../functions/InstaDapp/FInstaDapp.sol";
|
||||
import {ETH} from "../../constants/CInstaDapp.sol";
|
||||
import {Ownable} from "../../lib/Ownable.sol";
|
||||
|
||||
/// @title ConnectGelatoProviderPayment
|
||||
/// @notice InstaDapp Connector to compensate Gelato automation-gas Providers.
|
||||
/// @author Gelato Team
|
||||
contract ConnectGelatoProviderPayment is ConnectorInterface {
|
||||
contract ConnectGelatoProviderPayment is
|
||||
IConnectGelatoProviderPayment,
|
||||
Ownable
|
||||
{
|
||||
using Address for address payable;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
|
@ -19,9 +25,13 @@ contract ConnectGelatoProviderPayment is ConnectorInterface {
|
|||
string public constant override name = "ConnectGelatoProviderPayment-v1.0";
|
||||
|
||||
uint256 internal immutable _id;
|
||||
address internal _providerAddress;
|
||||
address internal immutable _paymentConnectorAddr;
|
||||
|
||||
constructor(uint256 id) {
|
||||
constructor(uint256 id, address providerAddress) {
|
||||
_id = id;
|
||||
_providerAddress = providerAddress;
|
||||
_paymentConnectorAddr = address(this);
|
||||
}
|
||||
|
||||
/// @dev Connector Details
|
||||
|
@ -34,6 +44,17 @@ contract ConnectGelatoProviderPayment is ConnectorInterface {
|
|||
(_type, id) = (1, _id); // Should put specific value.
|
||||
}
|
||||
|
||||
/// @notice Retrieve provider address that will be paid for executing the task
|
||||
/// @return provider's address
|
||||
function getProvider() external view override returns (address) {
|
||||
return _providerAddress;
|
||||
}
|
||||
|
||||
/// @notice Set the provider address that will be paid for executing a task
|
||||
function setProvider(address providerAddress) external onlyOwner {
|
||||
_providerAddress = providerAddress;
|
||||
}
|
||||
|
||||
/// @notice Transfers automation gas fees to Gelato Provider
|
||||
/// @dev Gelato Provider risks:
|
||||
/// - _getId does not match actual InstaMemory provider payment slot
|
||||
|
@ -47,20 +68,21 @@ contract ConnectGelatoProviderPayment is ConnectorInterface {
|
|||
/// @param _getId The InstaMemory slot at which the payment amount was stored.
|
||||
/// @param _setId The InstaMemory slot to save the provider payout amound in.
|
||||
function payProvider(
|
||||
address _provider,
|
||||
address _token,
|
||||
uint256 _amt,
|
||||
uint256 _getId,
|
||||
uint256 _setId
|
||||
) public payable virtual {
|
||||
) public payable override {
|
||||
address provider = IConnectGelatoProviderPayment(_paymentConnectorAddr)
|
||||
.getProvider();
|
||||
require(
|
||||
_provider != address(0x0),
|
||||
provider != address(0x0),
|
||||
"ConnectGelatoProviderPayment.payProvider:!_provider"
|
||||
);
|
||||
uint256 amt = getUint(_getId, _amt);
|
||||
setUint(_setId, amt);
|
||||
_token == ETH
|
||||
? payable(_provider).sendValue(amt)
|
||||
: IERC20(_token).safeTransfer(_provider, amt);
|
||||
? payable(provider).sendValue(amt)
|
||||
: IERC20(_token).safeTransfer(provider, amt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,126 +0,0 @@
|
|||
// "SPDX-License-Identifier: UNLICENSED"
|
||||
pragma solidity 0.7.4;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {
|
||||
GelatoProviderModuleStandard
|
||||
} from "@gelatonetwork/core/contracts/provider_modules/GelatoProviderModuleStandard.sol";
|
||||
import {
|
||||
Task
|
||||
} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoCore.sol";
|
||||
import {AccountInterface} from "../../../interfaces/InstaDapp/IInstaDapp.sol";
|
||||
import {
|
||||
ConnectGelatoDataForFullRefinance
|
||||
} from "../../connectors/ConnectGelatoDataForFullRefinance.sol";
|
||||
|
||||
/// @notice Gelato Provider Module for the InstaDapp DSA
|
||||
/// @dev Used by Provider to sanity check any third-party Tasks they pay for
|
||||
/// @author Gelato Network Team
|
||||
contract ProviderModuleDsaFromMakerToCompound is GelatoProviderModuleStandard {
|
||||
/// @dev DSA must have gelatoCore as auth and gelatoCore is emitted as origin of cast
|
||||
address public immutable gelatoCore;
|
||||
|
||||
/// @notice A trusted Connector to pay Provider for e.g. User's Gelato gas usage.
|
||||
/// @dev Automated InstaDapp Use Cases that rely on a third-party Gelato Provider
|
||||
/// to pay for automation will likely have this Connector in their spells.
|
||||
address public immutable connectGelatoProviderPayment;
|
||||
|
||||
// TO DO: remove `public` after hardhat file import bugfix
|
||||
// https://github.com/nomiclabs/hardhat/issues/916
|
||||
constructor(address _gelatoCore, address _connectGelatoProviderPayment) {
|
||||
gelatoCore = _gelatoCore;
|
||||
connectGelatoProviderPayment = _connectGelatoProviderPayment;
|
||||
}
|
||||
|
||||
// ================= GELATO PROVIDER MODULE STANDARD ================
|
||||
/// @notice Standard Gelato function for Provider's Task sanity checks
|
||||
/// @dev For more Provider security we should also check:
|
||||
/// - ListInterface(index.list()).accountID(_userProxy)
|
||||
/// - if (shield) connectors.isStaticConnector(targets)
|
||||
/// - connectors.isConnector(targets)
|
||||
/// But we skip those here to save gas
|
||||
/// @param _userProxy The DSA which submitted the Task
|
||||
/// @return whether the Provider is pays for the Task.
|
||||
function isProvided(
|
||||
address _userProxy,
|
||||
address,
|
||||
Task calldata
|
||||
) public view virtual override returns (string memory) {
|
||||
try AccountInterface(_userProxy).isAuth(gelatoCore) returns (
|
||||
bool gelatoCoreIsAuth
|
||||
) {
|
||||
if (!gelatoCoreIsAuth)
|
||||
return
|
||||
"ProviderModuleDsaFromMakerToCompound.isProvided:GelatoCoreNotAuth";
|
||||
} catch Error(string memory err) {
|
||||
return
|
||||
string(
|
||||
abi.encodePacked(
|
||||
"ProviderModuleDsaFromMakerToCompound.isProvided:",
|
||||
err
|
||||
)
|
||||
);
|
||||
} catch {
|
||||
return "ProviderModuleDsaFromMakerToCompound.isProvided:undefined";
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// @notice Gelato Standard Provider function to retrieve payload for the DSA
|
||||
/// @dev This formats the Gelato Task into a DSA compatible payload and
|
||||
/// it also inserts the _provider into the ConnectGelatoProviderPayment payload,
|
||||
/// to make sure that it cannot be spoofed thus e.g. securing Provider payments.
|
||||
/// @param _provider the actual Provider address verified by GelatoCore system.
|
||||
/// @param _task The Task in Gelato format.
|
||||
/// @return The execution payload in DSA format
|
||||
/// @return bool=false because no execRevert checks must be handled on GelatoCore
|
||||
/// because the DSA reverts, if a spell revert is caught during delegatecall.
|
||||
function execPayload(
|
||||
uint256,
|
||||
address,
|
||||
address _provider,
|
||||
Task calldata _task,
|
||||
uint256
|
||||
) public view virtual override returns (bytes memory, bool) {
|
||||
require(
|
||||
_task.actions.length == 1,
|
||||
"ProviderModuleDsaFromMakerToCompound.execPayload: Task should 1 action."
|
||||
);
|
||||
address[] memory targets = new address[](_task.actions.length);
|
||||
targets[0] = _task.actions[0].addr;
|
||||
|
||||
bytes[] memory datas = new bytes[](_task.actions.length);
|
||||
datas[0] = _replaceProvider(_provider, _task.actions[0].data);
|
||||
|
||||
return (
|
||||
abi.encodeWithSelector(
|
||||
AccountInterface.cast.selector,
|
||||
targets,
|
||||
datas,
|
||||
gelatoCore
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
function _replaceProvider(address _provider, bytes calldata _data)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
(uint256 vaultId, address token, ) = abi.decode(
|
||||
_data[4:],
|
||||
(uint256, address, address)
|
||||
);
|
||||
return
|
||||
abi.encodeWithSelector(
|
||||
ConnectGelatoDataForFullRefinance
|
||||
.getDataAndCastForFromMakerToCompound
|
||||
.selector,
|
||||
vaultId,
|
||||
token,
|
||||
_provider
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
// "SPDX-License-Identifier: UNLICENSED"
|
||||
pragma solidity 0.7.4;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {
|
||||
GelatoProviderModuleStandard
|
||||
} from "@gelatonetwork/core/contracts/provider_modules/GelatoProviderModuleStandard.sol";
|
||||
import {
|
||||
Task
|
||||
} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoCore.sol";
|
||||
import {AccountInterface} from "../../../interfaces/InstaDapp/IInstaDapp.sol";
|
||||
import {
|
||||
ConnectGelatoDataForFullRefinance
|
||||
} from "../../connectors/ConnectGelatoDataForFullRefinance.sol";
|
||||
|
||||
/// @notice Gelato Provider Module for the InstaDapp DSA
|
||||
/// @dev Used by Provider to sanity check any third-party Tasks they pay for
|
||||
/// @author Gelato Network Team
|
||||
contract ProviderModuleDsaFromMakerToMaker is GelatoProviderModuleStandard {
|
||||
/// @dev DSA must have gelatoCore as auth and gelatoCore is emitted as origin of cast
|
||||
address public immutable gelatoCore;
|
||||
|
||||
/// @notice A trusted Connector to pay Provider for e.g. User's Gelato gas usage.
|
||||
/// @dev Automated InstaDapp Use Cases that rely on a third-party Gelato Provider
|
||||
/// to pay for automation will likely have this Connector in their spells.
|
||||
address public immutable connectGelatoProviderPayment;
|
||||
|
||||
// TO DO: remove `public` after hardhat file import bugfix
|
||||
// https://github.com/nomiclabs/hardhat/issues/916
|
||||
constructor(address _gelatoCore, address _connectGelatoProviderPayment) {
|
||||
gelatoCore = _gelatoCore;
|
||||
connectGelatoProviderPayment = _connectGelatoProviderPayment;
|
||||
}
|
||||
|
||||
// ================= GELATO PROVIDER MODULE STANDARD ================
|
||||
/// @notice Standard Gelato function for Provider's Task sanity checks
|
||||
/// @dev For more Provider security we should also check:
|
||||
/// - ListInterface(index.list()).accountID(_userProxy)
|
||||
/// - if (shield) connectors.isStaticConnector(targets)
|
||||
/// - connectors.isConnector(targets)
|
||||
/// But we skip those here to save gas
|
||||
/// @param _userProxy The DSA which submitted the Task
|
||||
/// @return whether the Provider is pays for the Task.
|
||||
function isProvided(
|
||||
address _userProxy,
|
||||
address,
|
||||
Task calldata
|
||||
) public view virtual override returns (string memory) {
|
||||
try AccountInterface(_userProxy).isAuth(gelatoCore) returns (
|
||||
bool gelatoCoreIsAuth
|
||||
) {
|
||||
if (!gelatoCoreIsAuth)
|
||||
return
|
||||
"ProviderModuleDsaFromMakerToMaker.isProvided:GelatoCoreNotAuth";
|
||||
} catch Error(string memory err) {
|
||||
return
|
||||
string(
|
||||
abi.encodePacked(
|
||||
"ProviderModuleDsaFromMakerToMaker.isProvided:",
|
||||
err
|
||||
)
|
||||
);
|
||||
} catch {
|
||||
return "ProviderModuleDsaFromMakerToMaker.isProvided:undefined";
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// @notice Gelato Standard Provider function to retrieve payload for the DSA
|
||||
/// @dev This formats the Gelato Task into a DSA compatible payload and
|
||||
/// it also inserts the _provider into the ConnectGelatoProviderPayment payload,
|
||||
/// to make sure that it cannot be spoofed thus e.g. securing Provider payments.
|
||||
/// @param _provider the actual Provider address verified by GelatoCore system.
|
||||
/// @param _task The Task in Gelato format.
|
||||
/// @return The execution payload in DSA format
|
||||
/// @return bool=false because no execRevert checks must be handled on GelatoCore
|
||||
/// because the DSA reverts, if a spell revert is caught during delegatecall.
|
||||
function execPayload(
|
||||
uint256,
|
||||
address,
|
||||
address _provider,
|
||||
Task calldata _task,
|
||||
uint256
|
||||
) public view virtual override returns (bytes memory, bool) {
|
||||
require(
|
||||
_task.actions.length == 1,
|
||||
"ProviderModuleDsaFromMakerToMaker.execPayload: Task should 1 action."
|
||||
);
|
||||
address[] memory targets = new address[](_task.actions.length);
|
||||
targets[0] = _task.actions[0].addr;
|
||||
|
||||
bytes[] memory datas = new bytes[](_task.actions.length);
|
||||
datas[0] = _replaceProvider(_provider, _task.actions[0].data);
|
||||
|
||||
return (
|
||||
abi.encodeWithSelector(
|
||||
AccountInterface.cast.selector,
|
||||
targets,
|
||||
datas,
|
||||
gelatoCore
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
function _replaceProvider(address _provider, bytes calldata _data)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
(uint256 vaultId, address token, string memory colType, ) = abi.decode(
|
||||
_data[4:],
|
||||
(uint256, address, string, address)
|
||||
);
|
||||
return
|
||||
abi.encodeWithSelector(
|
||||
ConnectGelatoDataForFullRefinance
|
||||
.getDataAndCastForFromMakerToMaker
|
||||
.selector,
|
||||
vaultId,
|
||||
token,
|
||||
colType,
|
||||
_provider
|
||||
);
|
||||
}
|
||||
}
|
|
@ -5,8 +5,8 @@ import {
|
|||
IConnectGelatoProviderPayment
|
||||
} from "../../../interfaces/InstaDapp/connectors/IConnectGelatoProviderPayment.sol";
|
||||
|
||||
// solhint-disable-next-line
|
||||
function _encodePayGelatoProvider(
|
||||
address _provider,
|
||||
address _token,
|
||||
uint256 _amt,
|
||||
uint256 _getId,
|
||||
|
@ -15,7 +15,6 @@ function _encodePayGelatoProvider(
|
|||
return
|
||||
abi.encodeWithSelector(
|
||||
IConnectGelatoProviderPayment.payProvider.selector,
|
||||
_provider,
|
||||
_token,
|
||||
_amt,
|
||||
_getId,
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity 0.7.4;
|
||||
|
||||
interface IConnectGelatoProviderPayment {
|
||||
import {ConnectorInterface} from "../IInstaDapp.sol";
|
||||
|
||||
interface IConnectGelatoProviderPayment is ConnectorInterface {
|
||||
function getProvider() external returns (address);
|
||||
|
||||
function payProvider(
|
||||
address _provider,
|
||||
address _token,
|
||||
uint256 _amt,
|
||||
uint256 _getId,
|
||||
|
|
82
contracts/lib/Ownable.sol
Normal file
82
contracts/lib/Ownable.sol
Normal file
|
@ -0,0 +1,82 @@
|
|||
// "SPDX-License-Identifier: UNLICENSED"
|
||||
pragma solidity 0.7.4;
|
||||
|
||||
/**
|
||||
* @dev Contract module which provides a basic access control mechanism, where
|
||||
* there is an account (an owner) that can be granted exclusive access to
|
||||
* specific functions.
|
||||
*
|
||||
* This module is used through inheritance. It will make available the modifier
|
||||
* `onlyOwner`, which can be applied to your functions to restrict their use to
|
||||
* the owner.
|
||||
*/
|
||||
contract Ownable {
|
||||
address private _owner;
|
||||
|
||||
event OwnershipTransferred(
|
||||
address indexed previousOwner,
|
||||
address indexed newOwner
|
||||
);
|
||||
|
||||
/**
|
||||
* @dev Initializes the contract setting the deployer as the initial owner.
|
||||
*/
|
||||
constructor() {
|
||||
_owner = msg.sender;
|
||||
emit OwnershipTransferred(address(0), _owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the address of the current owner.
|
||||
*/
|
||||
function owner() public view returns (address) {
|
||||
return _owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Throws if called by any account other than the owner.
|
||||
*/
|
||||
modifier onlyOwner() {
|
||||
require(isOwner(), "Ownable: caller is not the owner");
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if the caller is the current owner.
|
||||
*/
|
||||
function isOwner() public view returns (bool) {
|
||||
return msg.sender == _owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Leaves the contract without owner. It will not be possible to call
|
||||
* `onlyOwner` functions anymore. Can only be called by the current owner.
|
||||
*
|
||||
* NOTE: Renouncing ownership will leave the contract without an owner,
|
||||
* thereby removing any functionality that is only available to the owner.
|
||||
*/
|
||||
function renounceOwnership() public virtual onlyOwner {
|
||||
emit OwnershipTransferred(_owner, address(0));
|
||||
_owner = address(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
||||
* Can only be called by the current owner.
|
||||
*/
|
||||
function transferOwnership(address newOwner) public virtual onlyOwner {
|
||||
_transferOwnership(newOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers ownership of the contract to a new account (`newOwner`).
|
||||
*/
|
||||
function _transferOwnership(address newOwner) internal virtual {
|
||||
require(
|
||||
newOwner != address(0),
|
||||
"Ownable: new owner is the zero address"
|
||||
);
|
||||
emit OwnershipTransferred(_owner, newOwner);
|
||||
_owner = newOwner;
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ const userOpenDepositBorrowOnMakerVault = require("./setups/Open-Deposit-Borrow-
|
|||
const getWallets = require("./setups/Wallets.helper");
|
||||
const getConstants = require("./setups/Constants.helper");
|
||||
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.helper");
|
||||
const enableGelatoConnectorsForFromMaker = require("./setups/Enabling-New-Connectors-For-Full-Refinance.helper");
|
||||
|
||||
const ConnectGelatoDataForFullRefinanceABI = require("../../artifacts/contracts/contracts/connectors/ConnectGelatoDataForFullRefinance.sol/ConnectGelatoDataForFullRefinance.json")
|
||||
|
@ -20,7 +20,7 @@ const ConnectGelatoDataForFullRefinanceABI = require("../../artifacts/contracts/
|
|||
|
||||
async function makerToCompoundSetup() {
|
||||
const wallets = await getWallets();
|
||||
const contracts = await getAllContracts();
|
||||
const contracts = await getAllContracts(wallets.providerAddress);
|
||||
const constants = await getConstants();
|
||||
let vaultId;
|
||||
// Gelato Testing environment setup.
|
||||
|
@ -103,7 +103,7 @@ async function providerWhiteListTaskForMakerToCompound(
|
|||
data: await hre.run("abi-encode-withselector", {
|
||||
abi: ConnectGelatoDataForFullRefinanceABI,
|
||||
functionname: "getDataAndCastForFromMakerToCompound",
|
||||
inputs: [vaultId, constants.ETH, wallets.providerAddress],
|
||||
inputs: [vaultId, constants.ETH],
|
||||
}),
|
||||
operation: GelatoCoreLib.Operation.Delegatecall,
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ const userOpenDepositBorrowOnMakerVault = require("./setups/Open-Deposit-Borrow-
|
|||
const getWallets = require("./setups/Wallets.helper");
|
||||
const getConstants = require("./setups/Constants.helper");
|
||||
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.helper");
|
||||
const enableGelatoConnectorsForFromMaker = require("./setups/Enabling-New-Connectors-For-Full-Refinance.helper");
|
||||
|
||||
const ConnectGelatoDataForFullRefinanceABI = require("../../artifacts/contracts/contracts/connectors/ConnectGelatoDataForFullRefinance.sol/ConnectGelatoDataForFullRefinance.json")
|
||||
|
@ -21,7 +21,7 @@ const ConnectGelatoDataForFullRefinanceABI = require("../../artifacts/contracts/
|
|||
|
||||
async function makerETHAToMakerETHBSetup() {
|
||||
const wallets = await getWallets();
|
||||
const contracts = await getAllContracts();
|
||||
const contracts = await getAllContracts(wallets.providerAddress);
|
||||
const constants = await getConstants();
|
||||
let vaultAId;
|
||||
// Gelato Testing environment setup.
|
||||
|
@ -109,7 +109,7 @@ async function providerWhiteListTaskForMakerETHAToMakerETHB(
|
|||
data: await hre.run("abi-encode-withselector", {
|
||||
abi: ConnectGelatoDataForFullRefinanceABI,
|
||||
functionname: "getDataAndCastForFromMakerToMaker",
|
||||
inputs: [vaultId, constants.ETH, "ETH-B", wallets.providerAddress],
|
||||
inputs: [vaultId, constants.ETH, "ETH-B"],
|
||||
}),
|
||||
operation: GelatoCoreLib.Operation.Delegatecall,
|
||||
});
|
||||
|
|
|
@ -16,8 +16,9 @@ const GetCdps = require("../../../pre-compiles/GetCdps.json");
|
|||
const IERC20 = require("../../../pre-compiles/IERC20.json");
|
||||
const CTokenInterface = require("../../../pre-compiles/CTokenInterface.json");
|
||||
const CompoundResolver = require("../../../pre-compiles/InstaCompoundResolver.json");
|
||||
const DsaProviderModuleABI = require("../../../pre-compiles/ProviderModuleDsa_ABI.json");
|
||||
|
||||
async function getContracts() {
|
||||
async function getContracts(providerAddress) {
|
||||
// Deployed instances
|
||||
let connectGelato;
|
||||
let connectMaker;
|
||||
|
@ -35,6 +36,7 @@ async function getContracts() {
|
|||
let instaMapping;
|
||||
let instaConnectors;
|
||||
let compoundResolver;
|
||||
let dsaProviderModule;
|
||||
// Contracts to deploy and use for local testing
|
||||
let conditionMakerVaultUnsafe;
|
||||
let connectGelatoProviderPayment;
|
||||
|
@ -99,6 +101,10 @@ async function getContracts() {
|
|||
CompoundResolver.abi,
|
||||
hre.network.config.CompoundResolver
|
||||
);
|
||||
dsaProviderModule = await ethers.getContractAt(
|
||||
DsaProviderModuleABI,
|
||||
hre.network.config.ProviderModuleDsa
|
||||
);
|
||||
|
||||
// ===== Deploy Needed Contract ==================
|
||||
|
||||
|
@ -118,7 +124,8 @@ async function getContracts() {
|
|||
"ConnectGelatoProviderPayment"
|
||||
);
|
||||
connectGelatoProviderPayment = await ConnectGelatoProviderPayment.deploy(
|
||||
(await instaConnectors.connectorLength()).add(2)
|
||||
(await instaConnectors.connectorLength()).add(2),
|
||||
providerAddress
|
||||
);
|
||||
await connectGelatoProviderPayment.deployed();
|
||||
|
||||
|
@ -150,6 +157,7 @@ async function getContracts() {
|
|||
connectGelatoData,
|
||||
debtBridgeFromMakerForFullRefinance,
|
||||
makerResolver,
|
||||
dsaProviderModule,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
const hre = require("hardhat");
|
||||
const {ethers} = hre;
|
||||
|
||||
const getContracts = require("./Common-Contracts.helper");
|
||||
|
||||
async function getAllContracts() {
|
||||
let dsaProviderModule;
|
||||
let connectGelatoData;
|
||||
let contracts = await getContracts();
|
||||
|
||||
const ConnectGelatoData = await ethers.getContractFactory(
|
||||
"ConnectGelatoDataForFullRefinance"
|
||||
);
|
||||
connectGelatoData = await ConnectGelatoData.deploy(
|
||||
(await contracts.instaConnectors.connectorLength()).add(1),
|
||||
contracts.connectGelatoProviderPayment.address
|
||||
);
|
||||
await connectGelatoData.deployed();
|
||||
|
||||
const ProviderModuleDsa = await ethers.getContractFactory(
|
||||
"ProviderModuleDsaFromMakerToCompound"
|
||||
);
|
||||
dsaProviderModule = await ProviderModuleDsa.deploy(
|
||||
hre.network.config.GelatoCore,
|
||||
contracts.connectGelatoProviderPayment.address
|
||||
);
|
||||
await dsaProviderModule.deployed();
|
||||
|
||||
contracts.dsaProviderModule = dsaProviderModule;
|
||||
contracts.connectGelatoData = connectGelatoData;
|
||||
|
||||
return contracts;
|
||||
}
|
||||
|
||||
module.exports = getAllContracts;
|
|
@ -3,10 +3,9 @@ const {ethers} = hre;
|
|||
|
||||
const getContracts = require("./Common-Contracts.helper");
|
||||
|
||||
async function getAllContracts() {
|
||||
let dsaProviderModule;
|
||||
async function getAllContracts(providerAddress) {
|
||||
let connectGelatoData;
|
||||
let contracts = await getContracts();
|
||||
let contracts = await getContracts(providerAddress);
|
||||
|
||||
const ConnectGelatoData = await ethers.getContractFactory(
|
||||
"ConnectGelatoDataForFullRefinance"
|
||||
|
@ -17,16 +16,6 @@ async function getAllContracts() {
|
|||
);
|
||||
await connectGelatoData.deployed();
|
||||
|
||||
const ProviderModuleDsa = await ethers.getContractFactory(
|
||||
"ProviderModuleDsaFromMakerToMaker"
|
||||
);
|
||||
dsaProviderModule = await ProviderModuleDsa.deploy(
|
||||
hre.network.config.GelatoCore,
|
||||
contracts.connectGelatoProviderPayment.address
|
||||
);
|
||||
await dsaProviderModule.deployed();
|
||||
|
||||
contracts.dsaProviderModule = dsaProviderModule;
|
||||
contracts.connectGelatoData = connectGelatoData;
|
||||
|
||||
return contracts;
|
|
@ -94,7 +94,8 @@ describe("ConnectGelatoProviderPayment Unit Test", function () {
|
|||
"ConnectGelatoProviderPayment"
|
||||
);
|
||||
connectGelatoProviderPayment = await ConnectGelatoProviderPayment.deploy(
|
||||
connectorId
|
||||
connectorId,
|
||||
ethers.constants.AddressZero
|
||||
);
|
||||
connectGelatoProviderPayment.deployed();
|
||||
|
||||
|
@ -139,7 +140,50 @@ describe("ConnectGelatoProviderPayment Unit Test", function () {
|
|||
);
|
||||
});
|
||||
|
||||
it("#1: payProvider should pay to Provider 300 Dai", async function () {
|
||||
it("#1: payProvider should return error message ConnectGelatoProviderPayment.payProvider:INVALIDADDESS when provider is Zero Address", async function () {
|
||||
await expect(
|
||||
dsa.cast(
|
||||
[connectBasic.address, connectGelatoProviderPayment.address],
|
||||
[
|
||||
await hre.run("abi-encode-withselector", {
|
||||
abi: ConnectBasic.abi,
|
||||
functionname: "deposit",
|
||||
inputs: [
|
||||
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
ethers.utils.parseEther("1"),
|
||||
0,
|
||||
"105",
|
||||
],
|
||||
}),
|
||||
await hre.run("abi-encode-withselector", {
|
||||
abi: (
|
||||
await hre.artifacts.readArtifact("ConnectGelatoProviderPayment")
|
||||
).abi,
|
||||
functionname: "payProvider",
|
||||
inputs: ["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", 0, "105", 0],
|
||||
}),
|
||||
],
|
||||
userAddress,
|
||||
{
|
||||
value: ethers.utils.parseEther("1"),
|
||||
}
|
||||
)
|
||||
).to.be.revertedWith("ConnectGelatoProviderPayment.payProvider:!_provider");
|
||||
});
|
||||
|
||||
it("#2: setProvider should change the provider address", async function () {
|
||||
expect(await connectGelatoProviderPayment.getProvider()).to.be.equal(
|
||||
ethers.constants.AddressZero
|
||||
);
|
||||
|
||||
await connectGelatoProviderPayment.setProvider(providerAddress);
|
||||
|
||||
expect(await connectGelatoProviderPayment.getProvider()).to.be.equal(
|
||||
providerAddress
|
||||
);
|
||||
});
|
||||
|
||||
it("#3: payProvider should pay to Provider 300 Dai", async function () {
|
||||
const providerDAIBalanceBefore = await DAI.balanceOf(providerAddress);
|
||||
|
||||
await dsa.cast(
|
||||
|
@ -197,13 +241,7 @@ describe("ConnectGelatoProviderPayment Unit Test", function () {
|
|||
await hre.artifacts.readArtifact("ConnectGelatoProviderPayment")
|
||||
).abi,
|
||||
functionname: "payProvider",
|
||||
inputs: [
|
||||
providerAddress,
|
||||
DAI.address,
|
||||
ethers.utils.parseUnits("300", 18),
|
||||
0,
|
||||
0,
|
||||
],
|
||||
inputs: [DAI.address, ethers.utils.parseUnits("300", 18), 0, 0],
|
||||
}),
|
||||
],
|
||||
userAddress
|
||||
|
@ -214,7 +252,7 @@ describe("ConnectGelatoProviderPayment Unit Test", function () {
|
|||
);
|
||||
});
|
||||
|
||||
it("#2: payProvider should pay to Provider 1 ether", async function () {
|
||||
it("#4: payProvider should pay to Provider 1 ether", async function () {
|
||||
const providerBalanceBefore = await providerWallet.getBalance();
|
||||
|
||||
await dsa.cast(
|
||||
|
@ -235,13 +273,7 @@ describe("ConnectGelatoProviderPayment Unit Test", function () {
|
|||
await hre.artifacts.readArtifact("ConnectGelatoProviderPayment")
|
||||
).abi,
|
||||
functionname: "payProvider",
|
||||
inputs: [
|
||||
providerAddress,
|
||||
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
0,
|
||||
"105",
|
||||
0,
|
||||
],
|
||||
inputs: ["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", 0, "105", 0],
|
||||
}),
|
||||
],
|
||||
userAddress,
|
||||
|
@ -254,41 +286,4 @@ describe("ConnectGelatoProviderPayment Unit Test", function () {
|
|||
providerBalanceBefore.add(ethers.utils.parseEther("1"))
|
||||
);
|
||||
});
|
||||
|
||||
it("#3: payProvider should return error message ConnectGelatoProviderPayment.payProvider:INVALIDADDESS when provider is Zero Address", async function () {
|
||||
await expect(
|
||||
dsa.cast(
|
||||
[connectBasic.address, connectGelatoProviderPayment.address],
|
||||
[
|
||||
await hre.run("abi-encode-withselector", {
|
||||
abi: ConnectBasic.abi,
|
||||
functionname: "deposit",
|
||||
inputs: [
|
||||
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
ethers.utils.parseEther("1"),
|
||||
0,
|
||||
"105",
|
||||
],
|
||||
}),
|
||||
await hre.run("abi-encode-withselector", {
|
||||
abi: (
|
||||
await hre.artifacts.readArtifact("ConnectGelatoProviderPayment")
|
||||
).abi,
|
||||
functionname: "payProvider",
|
||||
inputs: [
|
||||
ethers.constants.AddressZero,
|
||||
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||
0,
|
||||
"105",
|
||||
0,
|
||||
],
|
||||
}),
|
||||
],
|
||||
userAddress,
|
||||
{
|
||||
value: ethers.utils.parseEther("1"),
|
||||
}
|
||||
)
|
||||
).to.be.revertedWith("ConnectGelatoProviderPayment.payProvider:!_provider");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user