From 7bbbe0d15831ef6653dfcf264ae94d56dc0823c0 Mon Sep 17 00:00:00 2001 From: gitpusha Date: Fri, 27 Nov 2020 13:38:13 +0100 Subject: [PATCH] feat: replace ConnectGelatoProviderPayment with ConnectGelatoExecutorPayment --- README.md | 4 +- ...ockConnectGelatoDataFullRefinanceMaker.sol | 43 +++---- .../ConnectGelatoDataFullMakerToCompound.sol | 23 ++-- .../ConnectGelatoDataFullMakerToMaker.sol | 32 ++--- ...ConnectGelatoDataPartialRefinanceMaker.sol | 22 ++-- .../ConnectGelatoExecutorPayment.sol | 60 +++++++++ .../ConnectGelatoProviderPayment.sol | 115 ------------------ .../ConditionDebtBridgeIsAffordable.sol | 4 +- .../ConditionDestVaultWillBeSafe.sol | 4 +- ....sol => FConnectGelatoExecutorPayment.sol} | 8 +- contracts/functions/gelato/FGelato.sol | 2 +- .../IConnectGelatoExecutorPayment.sol | 13 ++ .../IConnectGelatoProviderPayment.sol | 20 --- ...onnectGelatoDataForFullRefinance.deploy.js | 6 +- ...ectGelatoDataForPartialRefinance.deploy.js | 6 +- ...ectGelatoDataFullMakerToCompound.deploy.js | 6 +- ...onnectGelatoDataFullMakerToMaker.deploy.js | 6 +- ...=> ConnectGelatoExecutorPayment.deploy.js} | 23 ++-- hardhat.config.js | 6 +- package.json | 2 +- .../services/exec-ETHA-newETHB.mock.js | 14 +-- .../services/getSpells-ETHA-newETHB.mock.js | 8 +- .../setupFullRefinanceMakerToNewMaker.mock.js | 6 +- .../services/gelato/addProviderModuleDSA.js | 8 +- test/helpers/services/gelato/provideFunds.js | 12 +- .../gelato/providerAssignsExecutor.js | 6 +- test/helpers/services/gelato/stakeExecutor.js | 6 +- test/helpers/services/getContracts.js | 6 +- test/helpers/services/getWallets.js | 18 ++- .../full/functionality/0_To-Compound.test.js | 34 +++--- .../full/functionality/1_ETHA-newETHB.test.js | 30 ++--- .../full/functionality/2_ETHA-ETHB.test.js | 30 ++--- .../functionality/3_ETHA-closedETHB.test.js | 30 ++--- .../helpers/services/getSpells-ETHA-ETHB.js | 8 +- .../services/getSpells-ETHA-newETHB.js | 8 +- .../helpers/services/getSpells-To-Compound.js | 8 +- .../full/helpers/setupMakerToCompound.js | 8 +- .../full/helpers/setupMakerToMaker.js | 8 +- .../full/helpers/setupMakerToNewMaker.js | 8 +- .../from_maker/full/security/_cast.test.js | 18 +-- ...artial-Refinance-External-Provider.test.js | 70 +++++------ .../enableGelatoConnectorsForFromMaker.js | 6 +- ...=> 0_ConnectGelatoExecutorPayment.test.js} | 90 ++++---------- yarn.lock | 49 +++++--- 44 files changed, 363 insertions(+), 531 deletions(-) create mode 100644 contracts/contracts/connectors/ConnectGelatoExecutorPayment.sol delete mode 100644 contracts/contracts/connectors/ConnectGelatoProviderPayment.sol rename contracts/functions/InstaDapp/connectors/{FConnectGelatoProviderPayment.sol => FConnectGelatoExecutorPayment.sol} (59%) create mode 100644 contracts/interfaces/InstaDapp/connectors/IConnectGelatoExecutorPayment.sol delete mode 100644 contracts/interfaces/InstaDapp/connectors/IConnectGelatoProviderPayment.sol rename deploy/connectors/{ConnectGelatoProviderPayment.deploy.js => ConnectGelatoExecutorPayment.deploy.js} (73%) rename test/unit/connectors/{0_ConnectGelatoProviderPayment.test.js => 0_ConnectGelatoExecutorPayment.test.js} (63%) diff --git a/README.md b/README.md index 92df63f..340fc87 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ Debt Bridge is a financial process that aims to make the user position safer. In ### Full Refinancing from Maker's Vault to Compound. -Based on the [debt bridge](https://docs.instadapp.io/usecases/debt-bridge/) documentation of Instadapp, we automated this process by adding two connectors `ConnectGelatoDataFullRefinanceMaker`, `ConnectGelatoProviderPayment` and a Gelato condition contract. +Based on the [debt bridge](https://docs.instadapp.io/usecases/debt-bridge/) documentation of Instadapp, we automated this process by adding two connectors `ConnectGelatoDataFullRefinanceMaker`, `ConnectGelatoExecutorPayment` and a Gelato condition contract. - `ConditionMakerVaultIsSafe.sol`: determine if a specific vault is on an unsafe position. - `ConnectGelatoDataFullRefinanceMaker.sol`: generates the required data which will be assigned to the different inputs needed by `ConnectMaker` and `ConnectCompound`. Examples are the amount of DAI to pay back or the amount of Ether to withdraw from Maker. He will create the chain of connectors call needed to perform the debt refinance, he will generate the data wanted by the flashloan connector and he will call this flashloan connector through the cast function of Dsa. -- `ConnectGelatoProviderPayment.sol`: makes sure part of the moved collateral is used to pay the Gelato provider for the incurred transaction fee. The Gelato Provider will in turn pay the executor who executed the task. +- `ConnectGelatoExecutorPayment.sol`: makes sure part of the moved collateral is used to pay the Gelato provider for the incurred transaction fee. The Gelato Provider will in turn pay the executor who executed the task. In this example, the executor will be refunded for the incurred transaction fees by subtracting the estimated gas costs from the collateral which is moved from Maker to Compound. This means the user does not have to pre pay in order to incentivize the execution of the task. diff --git a/contracts/__mocks__/connectors/MockConnectGelatoDataFullRefinanceMaker.sol b/contracts/__mocks__/connectors/MockConnectGelatoDataFullRefinanceMaker.sol index a7ce444..ff8e264 100644 --- a/contracts/__mocks__/connectors/MockConnectGelatoDataFullRefinanceMaker.sol +++ b/contracts/__mocks__/connectors/MockConnectGelatoDataFullRefinanceMaker.sol @@ -32,13 +32,13 @@ import { _encodeBorrowMakerVault } from "../../functions/InstaDapp/connectors/FConnectMaker.sol"; import { - _encodePayGelatoProvider -} from "../../functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol"; + _encodePayExecutor +} from "../../functions/InstaDapp/connectors/FConnectGelatoExecutorPayment.sol"; import { _encodeDepositCompound, _encodeBorrowCompound } from "../../functions/InstaDapp/connectors/FConnectCompound.sol"; -import {_getGelatoProviderFees} from "../../functions/gelato/FGelato.sol"; +import {_getGelatoExecutorFees} from "../../functions/gelato/FGelato.sol"; import { _getGasCostMakerToMaker, _getGasCostMakerToCompound, @@ -52,11 +52,11 @@ contract MockConnectGelatoDataFullRefinanceMaker is ConnectorInterface { string public constant override name = "MockConnectGelatoDataFullRefinanceMaker-v1.0"; uint256 internal immutable _id; - address internal immutable _connectGelatoProviderPayment; + address internal immutable _connectGelatoExecutorPayment; - constructor(uint256 id, address connectGelatoProviderPayment) { + constructor(uint256 id, address connectGelatoExecutorPayment) { _id = id; - _connectGelatoProviderPayment = connectGelatoProviderPayment; + _connectGelatoExecutorPayment = connectGelatoExecutorPayment; } /// @dev Connector Details @@ -147,7 +147,7 @@ contract MockConnectGelatoDataFullRefinanceMaker is ConnectorInterface { _getMakerVaultCollateralBalance(_vaultAId); uint256 route = _route; uint256 gasCost = _getGasCostMakerToMaker(_vaultBId == 0, route); - uint256 gasFeesPaidFromCol = _getGelatoProviderFees(gasCost); + uint256 gasFeesPaidFromCol = _getGelatoExecutorFees(gasCost); (address[] memory _targets, bytes[] memory _datas) = _vaultBId == 0 @@ -192,7 +192,7 @@ contract MockConnectGelatoDataFullRefinanceMaker is ConnectorInterface { targets[2] = CONNECT_MAKER; // open new B vault targets[3] = CONNECT_MAKER; // deposit targets[4] = CONNECT_MAKER; // borrow - targets[5] = _connectGelatoProviderPayment; // payProvider + targets[5] = _connectGelatoExecutorPayment; // payExecutor targets[6] = INSTA_POOL_V2; // flashPayback datas = new bytes[](7); @@ -206,12 +206,7 @@ contract MockConnectGelatoDataFullRefinanceMaker is ConnectorInterface { 0 ); datas[4] = _encodeBorrowMakerVault(0, 0, 600, 0); - datas[5] = _encodePayGelatoProvider( - _colToken, - _gasFeesPaidFromCol, - 0, - 0 - ); + datas[5] = _encodePayExecutor(_colToken, _gasFeesPaidFromCol, 0, 0); datas[6] = _encodeFlashPayback(DAI, _wDaiToBorrow, 0, 0); } @@ -228,7 +223,7 @@ contract MockConnectGelatoDataFullRefinanceMaker is ConnectorInterface { targets[1] = CONNECT_MAKER; // withdraw targets[2] = CONNECT_MAKER; // deposit targets[3] = CONNECT_MAKER; // borrow - targets[4] = _connectGelatoProviderPayment; // payProvider + targets[4] = _connectGelatoExecutorPayment; // payExecutor targets[5] = INSTA_POOL_V2; // flashPayback datas = new bytes[](6); @@ -241,12 +236,7 @@ contract MockConnectGelatoDataFullRefinanceMaker is ConnectorInterface { 0 ); datas[3] = _encodeBorrowMakerVault(_vaultBId, 0, 600, 0); - datas[4] = _encodePayGelatoProvider( - _colToken, - _gasFeesPaidFromCol, - 0, - 0 - ); + datas[4] = _encodePayExecutor(_colToken, _gasFeesPaidFromCol, 0, 0); datas[5] = _encodeFlashPayback(DAI, _wDaiToBorrow, 0, 0); } @@ -264,14 +254,14 @@ contract MockConnectGelatoDataFullRefinanceMaker is ConnectorInterface { _getMakerVaultCollateralBalance(_vaultId); uint256 route = _route; uint256 gasCost = _getGasCostMakerToCompound(route); - uint256 gasFeesPaidFromCol = _getGelatoProviderFees(gasCost); + uint256 gasFeesPaidFromCol = _getGelatoExecutorFees(gasCost); address[] memory _targets = new address[](6); _targets[0] = CONNECT_MAKER; // payback _targets[1] = CONNECT_MAKER; // withdraw _targets[2] = CONNECT_COMPOUND; // deposit _targets[3] = CONNECT_COMPOUND; // borrow - _targets[4] = _connectGelatoProviderPayment; // payProvider + _targets[4] = _connectGelatoExecutorPayment; // payExecutor _targets[5] = INSTA_POOL_V2; // flashPayback bytes[] memory _datas = new bytes[](6); @@ -284,12 +274,7 @@ contract MockConnectGelatoDataFullRefinanceMaker is ConnectorInterface { 0 ); _datas[3] = _encodeBorrowCompound(DAI, 0, 600, 0); - _datas[4] = _encodePayGelatoProvider( - _colToken, - gasFeesPaidFromCol, - 0, - 0 - ); + _datas[4] = _encodePayExecutor(_colToken, gasFeesPaidFromCol, 0, 0); _datas[5] = _encodeFlashPayback(DAI, wDaiToBorrow, 0, 0); datas = new bytes[](1); diff --git a/contracts/contracts/connectors/ConnectGelatoDataFullMakerToCompound.sol b/contracts/contracts/connectors/ConnectGelatoDataFullMakerToCompound.sol index 3a6e99d..30d4dd5 100644 --- a/contracts/contracts/connectors/ConnectGelatoDataFullMakerToCompound.sol +++ b/contracts/contracts/connectors/ConnectGelatoDataFullMakerToCompound.sol @@ -33,13 +33,13 @@ import { _encodeBorrowMakerVault } from "../../functions/InstaDapp/connectors/FConnectMaker.sol"; import { - _encodePayGelatoProvider -} from "../../functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol"; + _encodePayExecutor +} from "../../functions/InstaDapp/connectors/FConnectGelatoExecutorPayment.sol"; import { _encodeDepositCompound, _encodeBorrowCompound } from "../../functions/InstaDapp/connectors/FConnectCompound.sol"; -import {_getGelatoProviderFees} from "../../functions/gelato/FGelato.sol"; +import {_getGelatoExecutorFees} from "../../functions/gelato/FGelato.sol"; import { _getFlashLoanRoute, _getGasCostMakerToMaker, @@ -59,11 +59,11 @@ contract ConnectGelatoDataFullMakerToCompound is ConnectorInterface { string public constant override name = "ConnectGelatoDataFullMakerToCompound-v1.0"; uint256 internal immutable _id; - address internal immutable _connectGelatoProviderPayment; + address internal immutable _connectGelatoExecutorPayment; - constructor(uint256 id, address connectGelatoProviderPayment) { + constructor(uint256 id, address connectGelatoExecutorPayment) { _id = id; - _connectGelatoProviderPayment = connectGelatoProviderPayment; + _connectGelatoExecutorPayment = connectGelatoExecutorPayment; } /// @dev Connector Details @@ -146,14 +146,14 @@ contract ConnectGelatoDataFullMakerToCompound is ConnectorInterface { _getMakerVaultCollateralBalance(_vaultId); uint256 route = _getFlashLoanRoute(DAI, wDaiToBorrow); uint256 gasCost = _getGasCostMakerToCompound(route); - uint256 gasFeesPaidFromCol = _getGelatoProviderFees(gasCost); + uint256 gasFeesPaidFromCol = _getGelatoExecutorFees(gasCost); address[] memory _targets = new address[](6); _targets[0] = CONNECT_MAKER; // payback _targets[1] = CONNECT_MAKER; // withdraw _targets[2] = CONNECT_COMPOUND; // deposit _targets[3] = CONNECT_COMPOUND; // borrow - _targets[4] = _connectGelatoProviderPayment; // payProvider + _targets[4] = _connectGelatoExecutorPayment; // payExecutor _targets[5] = INSTA_POOL_V2; // flashPayback bytes[] memory _datas = new bytes[](6); @@ -166,12 +166,7 @@ contract ConnectGelatoDataFullMakerToCompound is ConnectorInterface { 0 ); _datas[3] = _encodeBorrowCompound(DAI, 0, 600, 0); - _datas[4] = _encodePayGelatoProvider( - _colToken, - gasFeesPaidFromCol, - 0, - 0 - ); + _datas[4] = _encodePayExecutor(_colToken, gasFeesPaidFromCol, 0, 0); _datas[5] = _encodeFlashPayback(DAI, wDaiToBorrow, 0, 0); datas = new bytes[](1); diff --git a/contracts/contracts/connectors/ConnectGelatoDataFullMakerToMaker.sol b/contracts/contracts/connectors/ConnectGelatoDataFullMakerToMaker.sol index df3faaa..8f7f053 100644 --- a/contracts/contracts/connectors/ConnectGelatoDataFullMakerToMaker.sol +++ b/contracts/contracts/connectors/ConnectGelatoDataFullMakerToMaker.sol @@ -33,13 +33,13 @@ import { _encodeBorrowMakerVault } from "../../functions/InstaDapp/connectors/FConnectMaker.sol"; import { - _encodePayGelatoProvider -} from "../../functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol"; + _encodePayExecutor +} from "../../functions/InstaDapp/connectors/FConnectGelatoExecutorPayment.sol"; import { _encodeDepositCompound, _encodeBorrowCompound } from "../../functions/InstaDapp/connectors/FConnectCompound.sol"; -import {_getGelatoProviderFees} from "../../functions/gelato/FGelato.sol"; +import {_getGelatoExecutorFees} from "../../functions/gelato/FGelato.sol"; import { _getFlashLoanRoute, _getGasCostMakerToMaker, @@ -59,11 +59,11 @@ contract ConnectGelatoDataFullMakerToMaker is ConnectorInterface { string public constant override name = "ConnectGelatoDataFullMakerToMaker-v1.0"; uint256 internal immutable _id; - address internal immutable _connectGelatoProviderPayment; + address internal immutable _connectGelatoExecutorPayment; - constructor(uint256 id, address connectGelatoProviderPayment) { + constructor(uint256 id, address connectGelatoExecutorPayment) { _id = id; - _connectGelatoProviderPayment = connectGelatoProviderPayment; + _connectGelatoExecutorPayment = connectGelatoExecutorPayment; } /// @dev Connector Details @@ -152,7 +152,7 @@ contract ConnectGelatoDataFullMakerToMaker is ConnectorInterface { _getMakerVaultCollateralBalance(_vaultAId); uint256 route = _getFlashLoanRoute(DAI, wDaiToBorrow); uint256 gasCost = _getGasCostMakerToMaker(_vaultBId == 0, route); - uint256 gasFeesPaidFromCol = _getGelatoProviderFees(gasCost); + uint256 gasFeesPaidFromCol = _getGelatoExecutorFees(gasCost); (address[] memory _targets, bytes[] memory _datas) = _vaultBId == 0 @@ -197,7 +197,7 @@ contract ConnectGelatoDataFullMakerToMaker is ConnectorInterface { targets[2] = CONNECT_MAKER; // open new B vault targets[3] = CONNECT_MAKER; // deposit targets[4] = CONNECT_MAKER; // borrow - targets[5] = _connectGelatoProviderPayment; // payProvider + targets[5] = _connectGelatoExecutorPayment; // payExecutor targets[6] = INSTA_POOL_V2; // flashPayback datas = new bytes[](7); @@ -211,12 +211,7 @@ contract ConnectGelatoDataFullMakerToMaker is ConnectorInterface { 0 ); datas[4] = _encodeBorrowMakerVault(0, 0, 600, 0); - datas[5] = _encodePayGelatoProvider( - _colToken, - _gasFeesPaidFromCol, - 0, - 0 - ); + datas[5] = _encodePayExecutor(_colToken, _gasFeesPaidFromCol, 0, 0); datas[6] = _encodeFlashPayback(DAI, _wDaiToBorrow, 0, 0); } @@ -233,7 +228,7 @@ contract ConnectGelatoDataFullMakerToMaker is ConnectorInterface { targets[1] = CONNECT_MAKER; // withdraw targets[2] = CONNECT_MAKER; // deposit targets[3] = CONNECT_MAKER; // borrow - targets[4] = _connectGelatoProviderPayment; // payProvider + targets[4] = _connectGelatoExecutorPayment; // payExecutor targets[5] = INSTA_POOL_V2; // flashPayback datas = new bytes[](6); @@ -246,12 +241,7 @@ contract ConnectGelatoDataFullMakerToMaker is ConnectorInterface { 0 ); datas[3] = _encodeBorrowMakerVault(_vaultBId, 0, 600, 0); - datas[4] = _encodePayGelatoProvider( - _colToken, - _gasFeesPaidFromCol, - 0, - 0 - ); + datas[4] = _encodePayExecutor(_colToken, _gasFeesPaidFromCol, 0, 0); datas[5] = _encodeFlashPayback(DAI, _wDaiToBorrow, 0, 0); } diff --git a/contracts/contracts/connectors/ConnectGelatoDataPartialRefinanceMaker.sol b/contracts/contracts/connectors/ConnectGelatoDataPartialRefinanceMaker.sol index f0b0af4..6060b51 100644 --- a/contracts/contracts/connectors/ConnectGelatoDataPartialRefinanceMaker.sol +++ b/contracts/contracts/connectors/ConnectGelatoDataPartialRefinanceMaker.sol @@ -32,13 +32,13 @@ import { _encodeBorrowMakerVault } from "../../functions/InstaDapp/connectors/FConnectMaker.sol"; import { - _encodePayGelatoProvider -} from "../../functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol"; + _encodePayExecutor +} from "../../functions/InstaDapp/connectors/FConnectGelatoExecutorPayment.sol"; import { _encodeDepositCompound, _encodeBorrowCompound } from "../../functions/InstaDapp/connectors/FConnectCompound.sol"; -import {_getGelatoProviderFees} from "../../functions/gelato/FGelato.sol"; +import {_getGelatoExecutorFees} from "../../functions/gelato/FGelato.sol"; import { _wCalcCollateralToWithdraw, _wCalcDebtToRepay @@ -69,13 +69,13 @@ contract ConnectGelatoDataPartialRefinanceMaker is ConnectorInterface { string public constant override name = "ConnectGelatoDataPartialRefinanceMaker-v1.0"; uint256 internal immutable _id; - address internal immutable _connectGelatoProviderPayment; + address internal immutable _connectGelatoExecutorPayment; uint256 public constant GAS_COST = 1850000; - constructor(uint256 id, address connectGelatoProviderPayment) { + constructor(uint256 id, address connectGelatoExecutorPayment) { _id = id; - _connectGelatoProviderPayment = connectGelatoProviderPayment; + _connectGelatoExecutorPayment = connectGelatoExecutorPayment; } /// @dev Connector Details @@ -159,7 +159,7 @@ contract ConnectGelatoDataPartialRefinanceMaker is ConnectorInterface { _targets[2] = CONNECT_MAKER; // open ETH-B vault _targets[3] = CONNECT_MAKER; // deposit _targets[4] = CONNECT_MAKER; // borrow - _targets[5] = _connectGelatoProviderPayment; // payProvider + _targets[5] = _connectGelatoExecutorPayment; // payExecutor _targets[6] = INSTA_POOL_V2; // flashPayback bytes[] memory _datas = new bytes[](7); @@ -183,7 +183,7 @@ contract ConnectGelatoDataPartialRefinanceMaker is ConnectorInterface { 0 ); _datas[4] = _encodeBorrowMakerVault(0, wDaiDebtToMove, 0, 0); - _datas[5] = _encodePayGelatoProvider( + _datas[5] = _encodePayExecutor( _payload.colToken, gasFeesPaidFromCol, 0, @@ -227,7 +227,7 @@ contract ConnectGelatoDataPartialRefinanceMaker is ConnectorInterface { _targets[1] = CONNECT_MAKER; // withdraw _targets[2] = CONNECT_COMPOUND; // deposit _targets[3] = CONNECT_COMPOUND; // borrow - _targets[4] = _connectGelatoProviderPayment; // payProvider + _targets[4] = _connectGelatoExecutorPayment; // payExecutor _targets[5] = INSTA_POOL_V2; // flashPayback bytes[] memory _datas = new bytes[](6); @@ -250,7 +250,7 @@ contract ConnectGelatoDataPartialRefinanceMaker is ConnectorInterface { 0 ); _datas[3] = _encodeBorrowCompound(DAI, wDaiDebtToMove, 0, 0); - _datas[4] = _encodePayGelatoProvider( + _datas[4] = _encodePayExecutor( _payload.colToken, gasFeesPaidFromCol, 0, @@ -315,7 +315,7 @@ contract ConnectGelatoDataPartialRefinanceMaker is ConnectorInterface { // TO DO: add fee mechanism for non-ETH collateral debt bridge // uint256 gasFeesPaidFromCol = _mul(GAS_COST, wmul(_getGelatoGasPrice(), latestPrice)); - gasFeesPaidFromCol = _getGelatoProviderFees(GAS_COST); + gasFeesPaidFromCol = _getGelatoExecutorFees(GAS_COST); uint256 wPricedCol = wmul( diff --git a/contracts/contracts/connectors/ConnectGelatoExecutorPayment.sol b/contracts/contracts/connectors/ConnectGelatoExecutorPayment.sol new file mode 100644 index 0000000..02fbb27 --- /dev/null +++ b/contracts/contracts/connectors/ConnectGelatoExecutorPayment.sol @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.7.4; + +import { + IConnectGelatoExecutorPayment +} from "../../interfaces/InstaDapp/connectors/IConnectGelatoExecutorPayment.sol"; +import {Address} from "../../vendor/Address.sol"; +import {IERC20} from "../../vendor/IERC20.sol"; +import {SafeERC20} from "../../vendor/SafeERC20.sol"; +import {_getUint, _setUint} from "../../functions/InstaDapp/FInstaDapp.sol"; +import {ETH} from "../../constants/CInstaDapp.sol"; + +/// @title ConnectGelatoExecutorPayment +/// @notice InstaDapp Connector to compensate Gelato Executors for automation-gas. +/// @author Gelato Team +contract ConnectGelatoExecutorPayment is IConnectGelatoExecutorPayment { + using Address for address payable; + using SafeERC20 for IERC20; + + // solhint-disable-next-line const-name-snakecase + string public constant override name = "ConnectGelatoExecutorPayment-v1.0"; + + uint256 internal immutable _id; + + constructor(uint256 id) { + _id = id; + } + + /// @dev Connector Details + function connectorID() + external + view + override + returns (uint256 _type, uint256 id) + { + (_type, id) = (1, _id); // Should put specific value. + } + + /// @notice Transfers automation gas fees to Gelato Executor + /// @dev Gelato Executor risks: + /// - _getId does not match actual InstaMemory executor payment slot + /// - _token balance not in DSA + /// - worthless _token risk + /// payable to be compatible in conjunction with DSA.cast payable target + /// @param _token The token used to pay the Executor. + /// @param _amt The amount of _token to pay the Gelato Executor. + /// @param _getId The InstaMemory slot at which the payment amount was stored. + /// @param _setId The InstaMemory slot to save the executor payout amound in. + function payExecutor( + address _token, + uint256 _amt, + uint256 _getId, + uint256 _setId + ) external payable override { + uint256 amt = _getUint(_getId, _amt); + _setUint(_setId, amt); + if (_token == ETH) payable(tx.origin).sendValue(amt); + else IERC20(_token).safeTransfer(tx.origin, amt); + } +} diff --git a/contracts/contracts/connectors/ConnectGelatoProviderPayment.sol b/contracts/contracts/connectors/ConnectGelatoProviderPayment.sol deleted file mode 100644 index c48ca43..0000000 --- a/contracts/contracts/connectors/ConnectGelatoProviderPayment.sol +++ /dev/null @@ -1,115 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity 0.7.4; - -import { - IConnectGelatoProviderPayment -} from "../../interfaces/InstaDapp/connectors/IConnectGelatoProviderPayment.sol"; -import {Ownable} from "../../vendor/Ownable.sol"; -import {Address} from "../../vendor/Address.sol"; -import {GelatoString} from "../../lib/GelatoString.sol"; -import {IERC20} from "../../vendor/IERC20.sol"; -import {SafeERC20} from "../../vendor/SafeERC20.sol"; -import {_getUint, _setUint} from "../../functions/InstaDapp/FInstaDapp.sol"; -import {ETH} from "../../constants/CInstaDapp.sol"; -import { - IGelatoProviders -} from "@gelatonetwork/core/contracts/gelato_core/interfaces/IGelatoProviders.sol"; - -/// @title ConnectGelatoProviderPayment -/// @notice InstaDapp Connector to compensate Gelato automation-gas Providers. -/// @author Gelato Team -contract ConnectGelatoProviderPayment is - IConnectGelatoProviderPayment, - Ownable -{ - using Address for address payable; - using GelatoString for string; - using SafeERC20 for IERC20; - - // solhint-disable-next-line const-name-snakecase - string public constant override name = "ConnectGelatoProviderPayment-v1.0"; - - address public constant override GELATO_CORE = - 0x1d681d76ce96E4d70a88A00EBbcfc1E47808d0b8; - - address public override gelatoProvider; - - uint256 internal immutable _id; - address internal immutable _this; - - constructor(uint256 id, address _gelatoProvider) - noAddressZeroProvider(_gelatoProvider) - { - _id = id; - _this = address(this); - gelatoProvider = _gelatoProvider; - } - - modifier noAddressZeroProvider(address _gelatoProvider) { - require( - _gelatoProvider != address(0x0), - "ConnectGelatoProviderPayment.noAddressZeroProvider" - ); - _; - } - - /// @dev Connector Details - function connectorID() - external - view - override - returns (uint256 _type, uint256 id) - { - (_type, id) = (1, _id); // Should put specific value. - } - - /// @notice Set the gelatoProvider address that will be paid for executing a task - function setProvider(address _gelatoProvider) - external - override - onlyOwner - noAddressZeroProvider(_gelatoProvider) - { - gelatoProvider = _gelatoProvider; - } - - /// @notice Transfers automation gas fees to Gelato Provider - /// @dev Gelato Provider risks: - /// - _getId does not match actual InstaMemory gelatoProvider payment slot - /// - _token balance not in DSA - /// - worthless _token risk - /// payable to be compatible in conjunction with DSA.cast payable target - /// @param _token The token used to pay the Provider. - /// @param _amt The amount of _token to pay the Gelato Provider. - /// @param _getId The InstaMemory slot at which the payment amount was stored. - /// @param _setId The InstaMemory slot to save the gelatoProvider payout amound in. - function payProvider( - address _token, - uint256 _amt, - uint256 _getId, - uint256 _setId - ) external payable override { - address provider = - IConnectGelatoProviderPayment(_this).gelatoProvider(); - - uint256 amt = _getUint(_getId, _amt); - _setUint(_setId, amt); - - if (_token == ETH) { - // solhint-disable no-empty-blocks - try - IGelatoProviders(GELATO_CORE).provideFunds{value: amt}(provider) - {} catch Error(string memory error) { - error.revertWithInfo( - "ConnectGelatoProviderPayment.payProvider.provideFunds:" - ); - } catch { - revert( - "ConnectGelatoProviderPayment.payProvider.provideFunds:undefined" - ); - } - } else { - IERC20(_token).safeTransfer(provider, amt); - } - } -} diff --git a/contracts/contracts/gelato/conditions/ConditionDebtBridgeIsAffordable.sol b/contracts/contracts/gelato/conditions/ConditionDebtBridgeIsAffordable.sol index 57c0025..8f98712 100644 --- a/contracts/contracts/gelato/conditions/ConditionDebtBridgeIsAffordable.sol +++ b/contracts/contracts/gelato/conditions/ConditionDebtBridgeIsAffordable.sol @@ -18,7 +18,7 @@ import { _getGasCostMakerToMaker, _getRealisedDebt } from "../../../functions/gelato/FGelatoDebtBridge.sol"; -import {_getGelatoProviderFees} from "../../../functions/gelato/FGelato.sol"; +import {_getGelatoExecutorFees} from "../../../functions/gelato/FGelato.sol"; import {DAI} from "../../../constants/CInstaDapp.sol"; import {wdiv} from "../../../vendor/DSMath.sol"; @@ -76,7 +76,7 @@ contract ConditionDebtBridgeIsAffordable is GelatoConditionsStandard { uint256 wColToWithdrawFromMaker = _getMakerVaultCollateralBalance(_vaultId); uint256 gasFeesPaidFromCol = - _getGelatoProviderFees( + _getGelatoExecutorFees( _getGasCostMakerToMaker( false, _getFlashLoanRoute( diff --git a/contracts/contracts/gelato/conditions/ConditionDestVaultWillBeSafe.sol b/contracts/contracts/gelato/conditions/ConditionDestVaultWillBeSafe.sol index 92c2070..67d9c04 100644 --- a/contracts/contracts/gelato/conditions/ConditionDestVaultWillBeSafe.sol +++ b/contracts/contracts/gelato/conditions/ConditionDestVaultWillBeSafe.sol @@ -18,7 +18,7 @@ import { _getGasCostMakerToMaker, _getRealisedDebt } from "../../../functions/gelato/FGelatoDebtBridge.sol"; -import {_getGelatoProviderFees} from "../../../functions/gelato/FGelato.sol"; +import {_getGelatoExecutorFees} from "../../../functions/gelato/FGelato.sol"; import {GelatoBytes} from "../../../lib/GelatoBytes.sol"; import {sub} from "../../../vendor/DSMath.sol"; @@ -70,7 +70,7 @@ contract ConditionDestVaultWillBeSafe is GelatoConditionsStandard { uint256 wColToDeposit = sub( _getMakerVaultCollateralBalance(_fromVaultId), - _getGelatoProviderFees( + _getGelatoExecutorFees( _getGasCostMakerToMaker( _destVaultId == 0, _getFlashLoanRoute(DAI, wDaiToBorrow) diff --git a/contracts/functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol b/contracts/functions/InstaDapp/connectors/FConnectGelatoExecutorPayment.sol similarity index 59% rename from contracts/functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol rename to contracts/functions/InstaDapp/connectors/FConnectGelatoExecutorPayment.sol index 36a69f2..1466dde 100644 --- a/contracts/functions/InstaDapp/connectors/FConnectGelatoProviderPayment.sol +++ b/contracts/functions/InstaDapp/connectors/FConnectGelatoExecutorPayment.sol @@ -2,10 +2,10 @@ pragma solidity 0.7.4; import { - IConnectGelatoProviderPayment -} from "../../../interfaces/InstaDapp/connectors/IConnectGelatoProviderPayment.sol"; + IConnectGelatoExecutorPayment +} from "../../../interfaces/InstaDapp/connectors/IConnectGelatoExecutorPayment.sol"; -function _encodePayGelatoProvider( +function _encodePayExecutor( address _token, uint256 _amt, uint256 _getId, @@ -13,7 +13,7 @@ function _encodePayGelatoProvider( ) pure returns (bytes memory) { return abi.encodeWithSelector( - IConnectGelatoProviderPayment.payProvider.selector, + IConnectGelatoExecutorPayment.payExecutor.selector, _token, _amt, _getId, diff --git a/contracts/functions/gelato/FGelato.sol b/contracts/functions/gelato/FGelato.sol index bf262a5..5c9d9e2 100644 --- a/contracts/functions/gelato/FGelato.sol +++ b/contracts/functions/gelato/FGelato.sol @@ -10,6 +10,6 @@ function _getGelatoGasPrice() view returns (uint256) { return uint256(oracleGasPrice); } -function _getGelatoProviderFees(uint256 _gas) view returns (uint256) { +function _getGelatoExecutorFees(uint256 _gas) view returns (uint256) { return mul(_gas, _getGelatoGasPrice()); } diff --git a/contracts/interfaces/InstaDapp/connectors/IConnectGelatoExecutorPayment.sol b/contracts/interfaces/InstaDapp/connectors/IConnectGelatoExecutorPayment.sol new file mode 100644 index 0000000..b659b3c --- /dev/null +++ b/contracts/interfaces/InstaDapp/connectors/IConnectGelatoExecutorPayment.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.7.4; + +import {ConnectorInterface} from "../IInstaDapp.sol"; + +interface IConnectGelatoExecutorPayment is ConnectorInterface { + function payExecutor( + address _token, + uint256 _amt, + uint256 _getId, + uint256 _setId + ) external payable; +} diff --git a/contracts/interfaces/InstaDapp/connectors/IConnectGelatoProviderPayment.sol b/contracts/interfaces/InstaDapp/connectors/IConnectGelatoProviderPayment.sol deleted file mode 100644 index 4a86aff..0000000 --- a/contracts/interfaces/InstaDapp/connectors/IConnectGelatoProviderPayment.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity 0.7.4; - -import {ConnectorInterface} from "../IInstaDapp.sol"; - -interface IConnectGelatoProviderPayment is ConnectorInterface { - function setProvider(address _provider) external; - - function payProvider( - address _token, - uint256 _amt, - uint256 _getId, - uint256 _setId - ) external payable; - - function gelatoProvider() external view returns (address); - - // solhint-disable-next-line func-name-mixedcase - function GELATO_CORE() external pure returns (address); -} diff --git a/deploy/__mocks__/connectors/MockConnectGelatoDataForFullRefinance.deploy.js b/deploy/__mocks__/connectors/MockConnectGelatoDataForFullRefinance.deploy.js index 8babd0b..da2cd48 100644 --- a/deploy/__mocks__/connectors/MockConnectGelatoDataForFullRefinance.deploy.js +++ b/deploy/__mocks__/connectors/MockConnectGelatoDataForFullRefinance.deploy.js @@ -43,7 +43,7 @@ module.exports = async (hre) => { from: deployer, args: [ connectorId, - (await deployments.get("ConnectGelatoProviderPayment")).address, + (await deployments.get("ConnectGelatoExecutorPayment")).address, ], }); @@ -65,7 +65,7 @@ module.exports = async (hre) => { from: deployer, args: [ parseInt(process.env.ConnectGelatoDataFullRefinanceMakerId), - (await deployments.get("ConnectGelatoProviderPayment")).address, + (await deployments.get("ConnectGelatoExecutorPayment")).address, ], gasPrice: hre.network.config.gasPrice, log: true, @@ -79,5 +79,5 @@ module.exports.skip = async (hre) => { return process.env.ConnectGelatoDataFullRefinanceMakerId === undefined; return false; }; -module.exports.dependencies = ["ConnectGelatoProviderPayment"]; +module.exports.dependencies = ["ConnectGelatoExecutorPayment"]; module.exports.tags = ["MockConnectGelatoDataFullRefinanceMaker"]; diff --git a/deploy/connectors/ConnectGelatoDataForPartialRefinance.deploy.js b/deploy/connectors/ConnectGelatoDataForPartialRefinance.deploy.js index 4ed6669..309e33e 100644 --- a/deploy/connectors/ConnectGelatoDataForPartialRefinance.deploy.js +++ b/deploy/connectors/ConnectGelatoDataForPartialRefinance.deploy.js @@ -44,7 +44,7 @@ module.exports = async (hre) => { from: deployer, args: [ connectorId, - (await deployments.get("ConnectGelatoProviderPayment")).address, + (await deployments.get("ConnectGelatoExecutorPayment")).address, ], }); @@ -68,7 +68,7 @@ module.exports = async (hre) => { from: deployer, args: [ parseInt(process.env.ConnectGelatoDataPartialRefinanceMakerId), - (await deployments.get("ConnectGelatoProviderPayment")).address, + (await deployments.get("ConnectGelatoExecutorPayment")).address, ], gasPrice: hre.network.config.gasPrice, log: true, @@ -83,4 +83,4 @@ module.exports.skip = async (hre) => { return false; }; module.exports.tags = ["ConnectGelatoDataPartialRefinanceMaker"]; -module.exports.dependencies = ["ConnectGelatoProviderPayment"]; +module.exports.dependencies = ["ConnectGelatoExecutorPayment"]; diff --git a/deploy/connectors/ConnectGelatoDataFullMakerToCompound.deploy.js b/deploy/connectors/ConnectGelatoDataFullMakerToCompound.deploy.js index 033ff96..164ed42 100644 --- a/deploy/connectors/ConnectGelatoDataFullMakerToCompound.deploy.js +++ b/deploy/connectors/ConnectGelatoDataFullMakerToCompound.deploy.js @@ -43,7 +43,7 @@ module.exports = async (hre) => { from: deployer, args: [ connectorId, - (await deployments.get("ConnectGelatoProviderPayment")).address, + (await deployments.get("ConnectGelatoExecutorPayment")).address, ], }); @@ -65,7 +65,7 @@ module.exports = async (hre) => { from: deployer, args: [ parseInt(process.env.ConnectGelatoDataFullMakerToCompoundId), - (await deployments.get("ConnectGelatoProviderPayment")).address, + (await deployments.get("ConnectGelatoExecutorPayment")).address, ], gasPrice: hre.network.config.gasPrice, log: true, @@ -79,5 +79,5 @@ module.exports.skip = async (hre) => { return process.env.ConnectGelatoDataFullMakerToCompoundId === undefined; return false; }; -module.exports.dependencies = ["ConnectGelatoProviderPayment"]; +module.exports.dependencies = ["ConnectGelatoExecutorPayment"]; module.exports.tags = ["ConnectGelatoDataFullMakerToCompound"]; diff --git a/deploy/connectors/ConnectGelatoDataFullMakerToMaker.deploy.js b/deploy/connectors/ConnectGelatoDataFullMakerToMaker.deploy.js index dfbe25e..291e0b0 100644 --- a/deploy/connectors/ConnectGelatoDataFullMakerToMaker.deploy.js +++ b/deploy/connectors/ConnectGelatoDataFullMakerToMaker.deploy.js @@ -42,7 +42,7 @@ module.exports = async (hre) => { from: deployer, args: [ connectorId, - (await deployments.get("ConnectGelatoProviderPayment")).address, + (await deployments.get("ConnectGelatoExecutorPayment")).address, ], }); @@ -63,7 +63,7 @@ module.exports = async (hre) => { from: deployer, args: [ parseInt(process.env.ConnectGelatoDataFullMakerToMakerId), - (await deployments.get("ConnectGelatoProviderPayment")).address, + (await deployments.get("ConnectGelatoExecutorPayment")).address, ], gasPrice: hre.network.config.gasPrice, log: true, @@ -77,5 +77,5 @@ module.exports.skip = async (hre) => { return process.env.ConnectGelatoDataFullMakerToMakerId === undefined; return false; }; -module.exports.dependencies = ["ConnectGelatoProviderPayment"]; +module.exports.dependencies = ["ConnectGelatoExecutorPayment"]; module.exports.tags = ["ConnectGelatoDataFullMakerToMaker"]; diff --git a/deploy/connectors/ConnectGelatoProviderPayment.deploy.js b/deploy/connectors/ConnectGelatoExecutorPayment.deploy.js similarity index 73% rename from deploy/connectors/ConnectGelatoProviderPayment.deploy.js rename to deploy/connectors/ConnectGelatoExecutorPayment.deploy.js index f31b47b..f47615e 100644 --- a/deploy/connectors/ConnectGelatoProviderPayment.deploy.js +++ b/deploy/connectors/ConnectGelatoExecutorPayment.deploy.js @@ -5,14 +5,14 @@ const { sleep } = require("@gelatonetwork/core"); module.exports = async (hre) => { if (hre.network.name === "mainnet") { console.log( - "Deploying ConnectGelatoProviderPayment to mainnet. Hit ctrl + c to abort" + "Deploying ConnectGelatoExecutorPayment to mainnet. Hit ctrl + c to abort" ); console.log("❗ CONNECTOR DEPLOYMENT: VERIFY & HARDCODE CONNECTOR ID"); await sleep(10000); } const { deployments } = hre; const { deploy } = deployments; - const { deployer, gelatoProvider } = await hre.getNamedAccounts(); + const { deployer } = await hre.getNamedAccounts(); if (hre.network.name === "hardhat") { const deployerWallet = await ethers.provider.getSigner(deployer); @@ -37,15 +37,15 @@ module.exports = async (hre) => { const connectorLength = await instaConnectors.connectorLength(); const connectorId = connectorLength.add(1); - await deploy("ConnectGelatoProviderPayment", { + await deploy("ConnectGelatoExecutorPayment", { from: deployer, - args: [connectorId, gelatoProvider], + args: [connectorId], }); await instaConnectors .connect(instaMaster) .enable( - (await ethers.getContract("ConnectGelatoProviderPayment")).address + (await ethers.getContract("ConnectGelatoExecutorPayment")).address ); await hre.network.provider.request({ @@ -53,14 +53,11 @@ module.exports = async (hre) => { params: [await instaMaster.getAddress()], }); } else { - // the following will only deploy "ConnectGelatoProviderPayment" + // the following will only deploy "ConnectGelatoExecutorPayment" // if the contract was never deployed or if the code changed since last deployment - await deploy("ConnectGelatoProviderPayment", { + await deploy("ConnectGelatoExecutorPayment", { from: deployer, - args: [ - parseInt(process.env.ConnectGelatoProviderPaymentId), - gelatoProvider, - ], + args: [parseInt(process.env.ConnectGelatoExecutorPaymentId)], gasPrice: hre.network.config.gasPrice, log: true, }); @@ -70,7 +67,7 @@ module.exports = async (hre) => { module.exports.skip = async (hre) => { if (hre.network.name === "mainnet") return true; if (hre.network.name !== "hardhat") - return process.env.ConnectGelatoProviderPaymentId === undefined; + return process.env.ConnectGelatoExecutorPaymentId === undefined; return false; }; -module.exports.tags = ["ConnectGelatoProviderPayment"]; +module.exports.tags = ["ConnectGelatoExecutorPayment"]; diff --git a/hardhat.config.js b/hardhat.config.js index f7f9795..b27bd94 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -41,12 +41,8 @@ module.exports = { user: { default: 0, }, - gelatoProvider: { + executor: { default: 1, - mainnet: DEPLOYER, - }, - gelatoExecutor: { - default: 2, }, }, networks: { diff --git a/package.json b/package.json index 22a0c72..4ccbe4f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "eslint": "7.14.0", "eslint-config-prettier": "6.15.0", "ethereum-waffle": "3.2.1", - "ethers": "5.0.22", + "ethers": "5.0.23", "hardhat": "2.0.3", "hardhat-deploy": "0.7.0-beta.30", "hardhat-deploy-ethers": "0.3.0-beta.6", diff --git a/test/gas/debt_bridge/full/from_maker/helpers/services/exec-ETHA-newETHB.mock.js b/test/gas/debt_bridge/full/from_maker/helpers/services/exec-ETHA-newETHB.mock.js index 857a9e0..db8f79d 100644 --- a/test/gas/debt_bridge/full/from_maker/helpers/services/exec-ETHA-newETHB.mock.js +++ b/test/gas/debt_bridge/full/from_maker/helpers/services/exec-ETHA-newETHB.mock.js @@ -30,7 +30,7 @@ module.exports = async function ( expect( await contracts.mockDebtBridgeETHBExecutor - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe"); @@ -41,7 +41,7 @@ module.exports = async function ( expect( await contracts.mockDebtBridgeETHBExecutor - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("OK"); @@ -52,7 +52,7 @@ module.exports = async function ( if (mockRoute === 0) { await expect( contracts.mockDebtBridgeETHBExecutor - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .execViaRoute0AndOpenVault(taskReceipt, { gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) gasLimit: constants.GAS_LIMIT, @@ -61,7 +61,7 @@ module.exports = async function ( } else if (mockRoute === 1) { await expect( contracts.mockDebtBridgeETHBExecutor - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .execViaRoute1AndOpenVault(taskReceipt, { gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) gasLimit: constants.GAS_LIMIT, @@ -70,7 +70,7 @@ module.exports = async function ( } else if (mockRoute === 2) { await expect( contracts.mockDebtBridgeETHBExecutor - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .execViaRoute2AndOpenVault(taskReceipt, { gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) gasLimit: constants.GAS_LIMIT, @@ -79,7 +79,7 @@ module.exports = async function ( } else if (mockRoute === 3) { await expect( contracts.mockDebtBridgeETHBExecutor - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .execViaRoute3AndOpenVAult(taskReceipt, { gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) gasLimit: constants.GAS_LIMIT, @@ -91,7 +91,7 @@ module.exports = async function ( // 🚧 For Debugging: // const txResponse2 = await contracts.gelatoCore - // .connect(wallets.gelatoExecutorWallet) + // .connect(wallets.executor) // .exec(taskReceipt, { // gasPrice: gelatoGasPrice, // gasLimit: constants.GAS_LIMIT, diff --git a/test/gas/debt_bridge/full/from_maker/helpers/services/getSpells-ETHA-newETHB.mock.js b/test/gas/debt_bridge/full/from_maker/helpers/services/getSpells-ETHA-newETHB.mock.js index 6fb5866..a677ee2 100644 --- a/test/gas/debt_bridge/full/from_maker/helpers/services/getSpells-ETHA-newETHB.mock.js +++ b/test/gas/debt_bridge/full/from_maker/helpers/services/getSpells-ETHA-newETHB.mock.js @@ -50,13 +50,13 @@ module.exports = async function ( await expect( contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec]) ).to.emit(contracts.gelatoCore, "LogTaskSpecProvided"); expect( await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .isTaskSpecProvided( wallets.gelatoProviderAddress, connectGelatoFullDebtBridgeFromMakerTaskSpec @@ -65,11 +65,11 @@ module.exports = async function ( expect( await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .taskSpecGasPriceCeil( wallets.gelatoProviderAddress, await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec) ) ).to.be.equal(gasPriceCeil); diff --git a/test/gas/debt_bridge/full/from_maker/helpers/setupFullRefinanceMakerToNewMaker.mock.js b/test/gas/debt_bridge/full/from_maker/helpers/setupFullRefinanceMakerToNewMaker.mock.js index 9820b75..1adad4a 100644 --- a/test/gas/debt_bridge/full/from_maker/helpers/setupFullRefinanceMakerToNewMaker.mock.js +++ b/test/gas/debt_bridge/full/from_maker/helpers/setupFullRefinanceMakerToNewMaker.mock.js @@ -18,18 +18,18 @@ module.exports = async function (mockRoute) { // Gelato Testing environment setup. await provideFunds( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.gelatoCore, constants.GAS_LIMIT, constants.GAS_PRICE_CEIL ); await providerAssignsExecutor( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.mockDebtBridgeETHBExecutor.address, contracts.gelatoCore ); await addProviderModuleDSA( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.gelatoCore, contracts.dsaProviderModule.address ); diff --git a/test/helpers/services/gelato/addProviderModuleDSA.js b/test/helpers/services/gelato/addProviderModuleDSA.js index 29230b5..7a5d97c 100644 --- a/test/helpers/services/gelato/addProviderModuleDSA.js +++ b/test/helpers/services/gelato/addProviderModuleDSA.js @@ -1,7 +1,7 @@ const { expect } = require("chai"); module.exports = async function ( - gelatoProviderWallet, + gelatoProvider, gelatoCore, dsaProviderModuleAddr ) { @@ -11,17 +11,17 @@ module.exports = async function ( // payload by adding some specificity like his address to the // Payment connector for receiving payment of User. - const gelatoProviderAddress = await gelatoProviderWallet.getAddress(); + const gelatoProviderAddress = await gelatoProvider.getAddress(); await expect( gelatoCore - .connect(gelatoProviderWallet) + .connect(gelatoProvider) .addProviderModules([dsaProviderModuleAddr]) ).to.emit(gelatoCore, "LogProviderModuleAdded"); expect( await gelatoCore - .connect(gelatoProviderWallet) + .connect(gelatoProvider) .isModuleProvided(gelatoProviderAddress, dsaProviderModuleAddr) ).to.be.true; diff --git a/test/helpers/services/gelato/provideFunds.js b/test/helpers/services/gelato/provideFunds.js index 31d4406..3368483 100644 --- a/test/helpers/services/gelato/provideFunds.js +++ b/test/helpers/services/gelato/provideFunds.js @@ -1,7 +1,7 @@ const { expect } = require("chai"); module.exports = async function ( - gelatoProviderWallet, + gelatoProvider, gelatoCore, gasLimit, gasPriceCeil @@ -13,7 +13,7 @@ module.exports = async function ( // Provider. At each provider's task execution, some funds (approximatively // the gas cost value) will be transfered to the Executor stake. - let gelatoProviderAddress = await gelatoProviderWallet.getAddress(); + let gelatoProviderAddress = await gelatoProvider.getAddress(); const TASK_AUTOMATION_FUNDS = await gelatoCore.minExecProviderFunds( gasLimit, @@ -21,11 +21,9 @@ module.exports = async function ( ); await expect( - gelatoCore - .connect(gelatoProviderWallet) - .provideFunds(gelatoProviderAddress, { - value: TASK_AUTOMATION_FUNDS, - }) + gelatoCore.connect(gelatoProvider).provideFunds(gelatoProviderAddress, { + value: TASK_AUTOMATION_FUNDS, + }) ).to.emit(gelatoCore, "LogFundsProvided"); expect(await gelatoCore.providerFunds(gelatoProviderAddress)).to.be.equal( diff --git a/test/helpers/services/gelato/providerAssignsExecutor.js b/test/helpers/services/gelato/providerAssignsExecutor.js index b46c97d..cd4a534 100644 --- a/test/helpers/services/gelato/providerAssignsExecutor.js +++ b/test/helpers/services/gelato/providerAssignsExecutor.js @@ -1,7 +1,7 @@ const { expect } = require("chai"); module.exports = async function ( - gelatoProviderWallet, + gelatoProvider, gelatoExecutorAddress, gelatoCore ) { @@ -10,11 +10,11 @@ module.exports = async function ( // Provider choose a executor who will execute futur task // for the provider, it will be compensated by the provider. - const gelatoProviderAddress = await gelatoProviderWallet.getAddress(); + const gelatoProviderAddress = await gelatoProvider.getAddress(); await expect( gelatoCore - .connect(gelatoProviderWallet) + .connect(gelatoProvider) .providerAssignsExecutor(gelatoExecutorAddress) ).to.emit(gelatoCore, "LogProviderAssignedExecutor"); diff --git a/test/helpers/services/gelato/stakeExecutor.js b/test/helpers/services/gelato/stakeExecutor.js index f5d4eee..ab962bd 100644 --- a/test/helpers/services/gelato/stakeExecutor.js +++ b/test/helpers/services/gelato/stakeExecutor.js @@ -1,6 +1,6 @@ const { expect } = require("chai"); -module.exports = async function (gelatoExecutorWallet, gelatoCore) { +module.exports = async function (executor, gelatoCore) { //#region Executor Stake on Gelato // For task execution provider will ask a executor to watch the @@ -10,9 +10,9 @@ module.exports = async function (gelatoExecutorWallet, gelatoCore) { // For safety measure Gelato ask the executor to stake a minimum // amount. - const gelatoExecutorAddress = await gelatoExecutorWallet.getAddress(); + const gelatoExecutorAddress = await executor.getAddress(); - await gelatoCore.connect(gelatoExecutorWallet).stakeExecutor({ + await gelatoCore.connect(executor).stakeExecutor({ value: await gelatoCore.minExecutorStake(), }); diff --git a/test/helpers/services/getContracts.js b/test/helpers/services/getContracts.js index 4242da9..e4eb08c 100644 --- a/test/helpers/services/getContracts.js +++ b/test/helpers/services/getContracts.js @@ -99,8 +99,8 @@ module.exports = async function () { const conditionDebtBridgeIsAffordable = await ethers.getContract( "ConditionDebtBridgeIsAffordable" ); - const connectGelatoProviderPayment = await ethers.getContract( - "ConnectGelatoProviderPayment" + const connectGelatoExecutorPayment = await ethers.getContract( + "ConnectGelatoExecutorPayment" ); const makerResolver = await ethers.getContract("MakerResolver"); const connectGelatoDataFullMakerToMaker = await ethers.getContract( @@ -140,7 +140,7 @@ module.exports = async function () { instaConnectors, compoundResolver, conditionMakerVaultUnsafe, - connectGelatoProviderPayment, + connectGelatoExecutorPayment, priceOracleResolver, dsa: ethers.constants.AddressZero, makerResolver, diff --git a/test/helpers/services/getWallets.js b/test/helpers/services/getWallets.js index f6933e3..a1c13d0 100644 --- a/test/helpers/services/getWallets.js +++ b/test/helpers/services/getWallets.js @@ -5,19 +5,15 @@ const { ethers } = hre; module.exports = async function () { let userWallet; let userAddress; - let gelatoProviderWallet; + let gelatoProvider; let gelatoProviderAddress; - let gelatoExecutorWallet; + let executor; let gelatoExecutorAddress; - [ - userWallet, - gelatoProviderWallet, - gelatoExecutorWallet, - ] = await ethers.getSigners(); + [userWallet, gelatoProvider, executor] = await ethers.getSigners(); userAddress = await userWallet.getAddress(); - gelatoProviderAddress = await gelatoProviderWallet.getAddress(); - gelatoExecutorAddress = await gelatoExecutorWallet.getAddress(); + gelatoProviderAddress = await gelatoProvider.getAddress(); + gelatoExecutorAddress = await executor.getAddress(); // Hardhat default wallets prefilled with 100 ETH expect(await userWallet.getBalance()).to.be.gt(ethers.utils.parseEther("10")); @@ -25,9 +21,9 @@ module.exports = async function () { return { userWallet: userWallet, userAddress: userAddress, - gelatoProviderWallet: gelatoProviderWallet, + gelatoProvider: gelatoProvider, gelatoProviderAddress: gelatoProviderAddress, - gelatoExecutorWallet: gelatoExecutorWallet, + executor: executor, gelatoExecutorAddress: gelatoExecutorAddress, }; }; diff --git a/test/integration/debt_bridge/from_maker/full/functionality/0_To-Compound.test.js b/test/integration/debt_bridge/from_maker/full/functionality/0_To-Compound.test.js index 09f17a9..336cb7c 100644 --- a/test/integration/debt_bridge/from_maker/full/functionality/0_To-Compound.test.js +++ b/test/integration/debt_bridge/from_maker/full/functionality/0_To-Compound.test.js @@ -170,7 +170,7 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function () expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe"); @@ -181,7 +181,7 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function () expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("OK"); @@ -216,22 +216,18 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function () ).sub(gasFeesPaidFromCol); //#endregion - const providerBalanceBeforeExecution = await contracts.gelatoCore.providerFunds( - wallets.gelatoProviderAddress - ); + const executorBalanceBeforeExecution = await wallets.executor.getBalance(); await expect( - contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) - .exec(taskReceipt, { - gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) - gasLimit: constants.GAS_LIMIT, - }) + contracts.gelatoCore.connect(wallets.executor).exec(taskReceipt, { + gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) + gasLimit: constants.GAS_LIMIT, + }) ).to.emit(contracts.gelatoCore, "LogExecSuccess"); // 🚧 For Debugging: // const txResponse2 = await contracts.gelatoCore - // .connect(wallets.gelatoExecutorWallet) + // .connect(wallets.executor) // .exec(taskReceipt, { // gasPrice: gelatoGasPrice, // gasLimit: constants.GAS_LIMIT, @@ -244,14 +240,12 @@ describe("Full Debt Bridge refinancing loan from Maker to Compound", function () // } // await GelatoCoreLib.sleep(10000); - expect( - await contracts.gelatoCore.providerFunds(wallets.gelatoProviderAddress) - ).to.be.gt( - providerBalanceBeforeExecution.sub( - gasFeesPaidFromCol - .mul(await contracts.gelatoCore.totalSuccessShare()) - .div(100) - ) + expect(await wallets.executor.getBalance()).to.be.gt( + executorBalanceBeforeExecution + ); + + expect(await wallets.executor.getBalance()).to.be.gt( + executorBalanceBeforeExecution ); // compound position of DSA on cDai and cEth diff --git a/test/integration/debt_bridge/from_maker/full/functionality/1_ETHA-newETHB.test.js b/test/integration/debt_bridge/from_maker/full/functionality/1_ETHA-newETHB.test.js index ec52b1c..c39eecd 100644 --- a/test/integration/debt_bridge/from_maker/full/functionality/1_ETHA-newETHB.test.js +++ b/test/integration/debt_bridge/from_maker/full/functionality/1_ETHA-newETHB.test.js @@ -184,7 +184,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe"); @@ -195,7 +195,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("OK"); @@ -235,22 +235,18 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat ).sub(gasFeesPaidFromCol); //#endregion - const providerBalanceBeforeExecution = await contracts.gelatoCore.providerFunds( - wallets.gelatoProviderAddress - ); + const executorBalanceBeforeExecution = await wallets.executor.getBalance(); await expect( - contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) - .exec(taskReceipt, { - gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) - gasLimit: constants.GAS_LIMIT, - }) + contracts.gelatoCore.connect(wallets.executor).exec(taskReceipt, { + gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) + gasLimit: constants.GAS_LIMIT, + }) ).to.emit(contracts.gelatoCore, "LogExecSuccess"); // 🚧 For Debugging: // const txResponse2 = await contracts.gelatoCore - // .connect(wallets.gelatoExecutorWallet) + // .connect(wallets.executor) // .exec(taskReceipt, { // gasPrice: gelatoGasPrice, // gasLimit: constants.GAS_LIMIT, @@ -285,14 +281,8 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with vault creat vaultBId ); - expect( - await contracts.gelatoCore.providerFunds(wallets.gelatoProviderAddress) - ).to.be.gt( - providerBalanceBeforeExecution.sub( - gasFeesPaidFromCol - .mul(await contracts.gelatoCore.totalSuccessShare()) - .div(100) - ) + expect(await wallets.executor.getBalance()).to.be.gt( + executorBalanceBeforeExecution ); // Estimated amount to borrowed token should be equal to the actual one read on compound contracts diff --git a/test/integration/debt_bridge/from_maker/full/functionality/2_ETHA-ETHB.test.js b/test/integration/debt_bridge/from_maker/full/functionality/2_ETHA-ETHB.test.js index 501e29b..77bd802 100644 --- a/test/integration/debt_bridge/from_maker/full/functionality/2_ETHA-ETHB.test.js +++ b/test/integration/debt_bridge/from_maker/full/functionality/2_ETHA-ETHB.test.js @@ -186,7 +186,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () { expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe"); @@ -197,7 +197,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () { expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("OK"); @@ -237,22 +237,18 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () { ).sub(gasFeesPaidFromCol); //#endregion - const providerBalanceBeforeExecution = await contracts.gelatoCore.providerFunds( - wallets.gelatoProviderAddress - ); + const executorBalanceBeforeExecution = await wallets.executor.getBalance(); await expect( - contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) - .exec(taskReceipt, { - gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) - gasLimit: constants.GAS_LIMIT, - }) + contracts.gelatoCore.connect(wallets.executor).exec(taskReceipt, { + gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) + gasLimit: constants.GAS_LIMIT, + }) ).to.emit(contracts.gelatoCore, "LogExecSuccess"); // 🚧 For Debugging: // const txResponse2 = await contracts.gelatoCore - // .connect(wallets.gelatoExecutorWallet) + // .connect(wallets.executor) // .exec(taskReceipt, { // gasPrice: gelatoGasPrice, // gasLimit: constants.GAS_LIMIT, @@ -287,14 +283,8 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B", function () { vaultBId ); - expect( - await contracts.gelatoCore.providerFunds(wallets.gelatoProviderAddress) - ).to.be.gt( - providerBalanceBeforeExecution.sub( - gasFeesPaidFromCol - .mul(await contracts.gelatoCore.totalSuccessShare()) - .div(100) - ) + expect(await wallets.executor.getBalance()).to.be.gt( + executorBalanceBeforeExecution ); // Estimated amount to borrowed token should be equal to the actual one read on compound contracts diff --git a/test/integration/debt_bridge/from_maker/full/functionality/3_ETHA-closedETHB.test.js b/test/integration/debt_bridge/from_maker/full/functionality/3_ETHA-closedETHB.test.js index e25d7b8..8e4f0cb 100644 --- a/test/integration/debt_bridge/from_maker/full/functionality/3_ETHA-closedETHB.test.js +++ b/test/integration/debt_bridge/from_maker/full/functionality/3_ETHA-closedETHB.test.js @@ -205,7 +205,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with Vault B cre expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe"); @@ -216,7 +216,7 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with Vault B cre expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("OK"); @@ -256,22 +256,18 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with Vault B cre ).sub(gasFeesPaidFromCol); //#endregion - const providerBalanceBeforeExecution = await contracts.gelatoCore.providerFunds( - wallets.gelatoProviderAddress - ); + const executorBalanceBeforeExecution = await wallets.executor.getBalance(); await expect( - contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) - .exec(taskReceipt, { - gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) - gasLimit: constants.GAS_LIMIT, - }) + contracts.gelatoCore.connect(wallets.executor).exec(taskReceipt, { + gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) + gasLimit: constants.GAS_LIMIT, + }) ).to.emit(contracts.gelatoCore, "LogExecSuccess"); // 🚧 For Debugging: // const txResponse2 = await contracts.gelatoCore - // .connect(wallets.gelatoExecutorWallet) + // .connect(wallets.executor) // .exec(taskReceipt, { // gasPrice: gelatoGasPrice, // gasLimit: constants.GAS_LIMIT, @@ -309,14 +305,8 @@ describe("Full Debt Bridge refinancing loan from ETH-A to ETH-B with Vault B cre vaultBId ); - expect( - await contracts.gelatoCore.providerFunds(wallets.gelatoProviderAddress) - ).to.be.gt( - providerBalanceBeforeExecution.sub( - gasFeesPaidFromCol - .mul(await contracts.gelatoCore.totalSuccessShare()) - .div(100) - ) + expect(await wallets.executor.getBalance()).to.be.gt( + executorBalanceBeforeExecution ); // Estimated amount to borrowed token should be equal to the actual one read on compound contracts diff --git a/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-ETHA-ETHB.js b/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-ETHA-ETHB.js index c2fa29c..1bc14a4 100644 --- a/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-ETHA-ETHB.js +++ b/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-ETHA-ETHB.js @@ -50,13 +50,13 @@ module.exports = async function ( await expect( contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec]) ).to.emit(contracts.gelatoCore, "LogTaskSpecProvided"); expect( await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .isTaskSpecProvided( wallets.gelatoProviderAddress, connectGelatoFullDebtBridgeFromMakerTaskSpec @@ -65,11 +65,11 @@ module.exports = async function ( expect( await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .taskSpecGasPriceCeil( wallets.gelatoProviderAddress, await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec) ) ).to.be.equal(gasPriceCeil); diff --git a/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-ETHA-newETHB.js b/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-ETHA-newETHB.js index c8342c7..2fbfa3e 100644 --- a/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-ETHA-newETHB.js +++ b/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-ETHA-newETHB.js @@ -43,13 +43,13 @@ module.exports = async function (wallets, contracts, constants, vaultId) { await expect( contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec]) ).to.emit(contracts.gelatoCore, "LogTaskSpecProvided"); expect( await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .isTaskSpecProvided( wallets.gelatoProviderAddress, connectGelatoFullDebtBridgeFromMakerTaskSpec @@ -58,11 +58,11 @@ module.exports = async function (wallets, contracts, constants, vaultId) { expect( await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .taskSpecGasPriceCeil( wallets.gelatoProviderAddress, await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec) ) ).to.be.equal(gasPriceCeil); diff --git a/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-To-Compound.js b/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-To-Compound.js index 4f11d37..81d06af 100644 --- a/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-To-Compound.js +++ b/test/integration/debt_bridge/from_maker/full/helpers/services/getSpells-To-Compound.js @@ -44,13 +44,13 @@ module.exports = async function (wallets, contracts, constants, vaultId) { await expect( contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec]) ).to.emit(contracts.gelatoCore, "LogTaskSpecProvided"); expect( await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .isTaskSpecProvided( wallets.gelatoProviderAddress, connectGelatoFullDebtBridgeFromMakerTaskSpec @@ -59,11 +59,11 @@ module.exports = async function (wallets, contracts, constants, vaultId) { expect( await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .taskSpecGasPriceCeil( wallets.gelatoProviderAddress, await contracts.gelatoCore - .connect(wallets.gelatoProviderWallet) + .connect(wallets.gelatoProvider) .hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec) ) ).to.be.equal(gasPriceCeil); diff --git a/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToCompound.js b/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToCompound.js index 98eded0..d8d28e2 100644 --- a/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToCompound.js +++ b/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToCompound.js @@ -17,20 +17,20 @@ module.exports = async function () { const ABI = getABI(); // Gelato Testing environment setup. - await stakeExecutor(wallets.gelatoExecutorWallet, contracts.gelatoCore); + await stakeExecutor(wallets.executor, contracts.gelatoCore); await provideFunds( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.gelatoCore, constants.GAS_LIMIT, constants.GAS_PRICE_CEIL ); await providerAssignsExecutor( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, wallets.gelatoExecutorAddress, contracts.gelatoCore ); await addProviderModuleDSA( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.gelatoCore, contracts.dsaProviderModule.address ); diff --git a/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToMaker.js b/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToMaker.js index c1e88cf..59f73a0 100644 --- a/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToMaker.js +++ b/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToMaker.js @@ -18,20 +18,20 @@ module.exports = async function () { const ABI = getABI(); // Gelato Testing environment setup. - await stakeExecutor(wallets.gelatoExecutorWallet, contracts.gelatoCore); + await stakeExecutor(wallets.executor, contracts.gelatoCore); await provideFunds( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.gelatoCore, constants.GAS_LIMIT, constants.GAS_PRICE_CEIL ); await providerAssignsExecutor( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, wallets.gelatoExecutorAddress, contracts.gelatoCore ); await addProviderModuleDSA( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.gelatoCore, contracts.dsaProviderModule.address ); diff --git a/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToNewMaker.js b/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToNewMaker.js index 036b92c..60bdcb0 100644 --- a/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToNewMaker.js +++ b/test/integration/debt_bridge/from_maker/full/helpers/setupMakerToNewMaker.js @@ -17,20 +17,20 @@ module.exports = async function () { const ABI = getABI(); // Gelato Testing environment setup. - await stakeExecutor(wallets.gelatoExecutorWallet, contracts.gelatoCore); + await stakeExecutor(wallets.executor, contracts.gelatoCore); await provideFunds( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.gelatoCore, constants.GAS_LIMIT, constants.GAS_PRICE_CEIL ); await providerAssignsExecutor( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, wallets.gelatoExecutorAddress, contracts.gelatoCore ); await addProviderModuleDSA( - wallets.gelatoProviderWallet, + wallets.gelatoProvider, contracts.gelatoCore, contracts.dsaProviderModule.address ); diff --git a/test/integration/debt_bridge/from_maker/full/security/_cast.test.js b/test/integration/debt_bridge/from_maker/full/security/_cast.test.js index 9573cf1..30aaefa 100644 --- a/test/integration/debt_bridge/from_maker/full/security/_cast.test.js +++ b/test/integration/debt_bridge/from_maker/full/security/_cast.test.js @@ -7,7 +7,7 @@ const setupMakerToMaker = require("../helpers/setupMakerToMaker"); // This test showcases how to submit a task refinancing a Users debt position from // Maker to Compound using Gelato -describe("Security: _cast function by example of ETHA-ETHB with disabled ConnectGelatoProviderPayment", function () { +describe("Security: _cast function by example of ETHA-ETHB with disabled ConnectGelatoExecutorPayment", function () { this.timeout(0); if (hre.network.name !== "hardhat") { console.error("Test Suite is meant to be run on hardhat only"); @@ -184,7 +184,7 @@ describe("Security: _cast function by example of ETHA-ETHB with disabled Connect expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe"); @@ -195,7 +195,7 @@ describe("Security: _cast function by example of ETHA-ETHB with disabled Connect expect( await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .canExec(taskReceipt, constants.GAS_LIMIT, gelatoGasPrice) ).to.be.equal("OK"); @@ -206,11 +206,11 @@ describe("Security: _cast function by example of ETHA-ETHB with disabled Connect hre.network.config.InstaConnectors ); - const { address: connectGelatoProviderPayment } = await ethers.getContract( - "ConnectGelatoProviderPayment" + const { address: connectGelatoExecutorPayment } = await ethers.getContract( + "ConnectGelatoExecutorPayment" ); - expect(await instaConnectors.isConnector([connectGelatoProviderPayment])).to + expect(await instaConnectors.isConnector([connectGelatoExecutorPayment])).to .be.true; const instaMaster = await ethers.provider.getSigner( @@ -229,7 +229,7 @@ describe("Security: _cast function by example of ETHA-ETHB with disabled Connect await instaConnectors .connect(instaMaster) - .disable(connectGelatoProviderPayment); + .disable(connectGelatoExecutorPayment); await hre.network.provider.request({ method: "hardhat_stopImpersonatingAccount", @@ -238,7 +238,7 @@ describe("Security: _cast function by example of ETHA-ETHB with disabled Connect // await expect( // contracts.gelatoCore - // .connect(wallets.gelatoExecutorWallet) + // .connect(wallets.executor) // .exec(taskReceipt, { // gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) // gasLimit: constants.GAS_LIMIT, @@ -246,7 +246,7 @@ describe("Security: _cast function by example of ETHA-ETHB with disabled Connect // ).to.emit(contracts.gelatoCore, "LogExecReverted"); const txResponse = await contracts.gelatoCore - .connect(wallets.gelatoExecutorWallet) + .connect(wallets.executor) .exec(taskReceipt, { gasPrice: gelatoGasPrice, gasLimit: constants.GAS_LIMIT, diff --git a/test/integration/debt_bridge/from_maker/partial/3_Partial-Refinance-External-Provider.test.js b/test/integration/debt_bridge/from_maker/partial/3_Partial-Refinance-External-Provider.test.js index eebb263..c305e16 100644 --- a/test/integration/debt_bridge/from_maker/partial/3_Partial-Refinance-External-Provider.test.js +++ b/test/integration/debt_bridge/from_maker/partial/3_Partial-Refinance-External-Provider.test.js @@ -15,7 +15,7 @@ // const ConnectAuth = require("../../../../pre-compiles/ConnectAuth.json"); // const ConnectGelatoFullDebtBridgeFromMakerABI = require("../artifacts/contracts/contracts/connectors/ConnectGelatoPartialDebtBridgeFromMaker.sol/ConnectGelatoPartialDebtBridgeFromMaker.json") // .abi; -// const ConnectGelatoProviderPaymentABI = require("../../../../artifacts/contracts/contracts/connectors/ConnectGelatoProviderPayment.sol/ConnectGelatoProviderPayment.json") +// const ConnectGelatoExecutorPaymentABI = require("../../../../artifacts/contracts/contracts/connectors/ConnectGelatoExecutorPayment.sol/ConnectGelatoExecutorPayment.json") // .abi; // const InstaConnector = require("../../../../pre-compiles/InstaConnectors.json"); // const DssCdpManager = require("../../../../pre-compiles/DssCdpManager.json"); @@ -121,9 +121,9 @@ // // Wallet to use for local testing // let userWallet; // let userAddress; -// let gelatoProviderWallet; +// let gelatoProvider; // let gelatoProviderAddress; -// let gelatoExecutorWallet; +// let executor; // let gelatoExecutorAddress; // // Deployed instances @@ -146,7 +146,7 @@ // // Contracts to deploy and use for local testing // let conditionMakerVaultUnsafe; // let connectGelatoPartialDebtBridgeFromMaker; -// let connectGelatoProviderPayment; +// let connectGelatoExecutorPayment; // let priceOracleResolver; // let dsaProviderModule; @@ -163,12 +163,12 @@ // // Get Test Wallet for local testnet // [ // userWallet, -// gelatoProviderWallet, -// gelatoExecutorWallet, +// gelatoProvider, +// executor, // ] = await ethers.getSigners(); // userAddress = await userWallet.getAddress(); -// gelatoProviderAddress = await gelatoProviderWallet.getAddress(); -// gelatoExecutorAddress = await gelatoExecutorWallet.getAddress(); +// gelatoProviderAddress = await gelatoProvider.getAddress(); +// gelatoExecutorAddress = await executor.getAddress(); // instaMaster = await ethers.provider.getSigner( // hre.network.config.InstaMaster @@ -260,20 +260,20 @@ // ); // await connectGelatoPartialDebtBridgeFromMaker.deployed(); -// const ConnectGelatoProviderPayment = await ethers.getContractFactory( -// "ConnectGelatoProviderPayment" +// const ConnectGelatoExecutorPayment = await ethers.getContractFactory( +// "ConnectGelatoExecutorPayment" // ); -// connectGelatoProviderPayment = await ConnectGelatoProviderPayment.deploy( +// connectGelatoExecutorPayment = await ConnectGelatoExecutorPayment.deploy( // (await instaConnectors.connectorLength()).add(2) // ); -// await connectGelatoProviderPayment.deployed(); +// await connectGelatoExecutorPayment.deployed(); // const ProviderModuleDsa = await ethers.getContractFactory( // "ProviderModuleDsa" // ); // dsaProviderModule = await ProviderModuleDsa.deploy( // hre.network.config.GelatoCore, -// connectGelatoProviderPayment.address +// connectGelatoExecutorPayment.address // ); // await dsaProviderModule.deployed(); @@ -337,7 +337,7 @@ // await instaConnectors // .connect(instaMaster) -// .enable(connectGelatoProviderPayment.address); +// .enable(connectGelatoExecutorPayment.address); // await hre.network.provider.request({ // method: "hardhat_stopImpersonatingAccount", @@ -350,7 +350,7 @@ // ]) // ).to.be.true; // expect( -// await instaConnectors.isConnector([connectGelatoProviderPayment.address]) +// await instaConnectors.isConnector([connectGelatoExecutorPayment.address]) // ).to.be.true; // //#endregion @@ -364,7 +364,7 @@ // // For safety measure Gelato ask the executor to stake a minimum // // amount. -// await gelatoCore.connect(gelatoExecutorWallet).stakeExecutor({ +// await gelatoCore.connect(executor).stakeExecutor({ // value: await gelatoCore.minExecutorStake(), // }); @@ -388,7 +388,7 @@ // await expect( // gelatoCore -// .connect(gelatoProviderWallet) +// .connect(gelatoProvider) // .provideFunds(gelatoProviderAddress, { // value: TASK_AUTOMATION_FUNDS, // }) @@ -407,7 +407,7 @@ // await expect( // gelatoCore -// .connect(gelatoProviderWallet) +// .connect(gelatoProvider) // .providerAssignsExecutor(gelatoExecutorAddress) // ).to.emit(gelatoCore, "LogProviderAssignedExecutor"); @@ -425,13 +425,13 @@ // await expect( // gelatoCore -// .connect(gelatoProviderWallet) +// .connect(gelatoProvider) // .addProviderModules([dsaProviderModule.address]) // ).to.emit(gelatoCore, "LogProviderModuleAdded"); // expect( // await gelatoCore -// .connect(gelatoProviderWallet) +// .connect(gelatoProvider) // .isModuleProvided(gelatoProviderAddress, dsaProviderModule.address) // ).to.be.true; @@ -636,17 +636,17 @@ // spells.push(flashPayBack); -// const payProvider = new GelatoCoreLib.Action({ -// addr: connectGelatoProviderPayment.address, +// const payExecutor = new GelatoCoreLib.Action({ +// addr: connectGelatoExecutorPayment.address, // data: await hre.run("abi-encode-withselector", { -// abi: ConnectGelatoProviderPaymentABI, -// functionname: "payProvider", +// abi: ConnectGelatoExecutorPaymentABI, +// functionname: "payExecutor", // inputs: [gelatoProviderAddress, ETH, 0, "605", 0], // }), // operation: GelatoCoreLib.Operation.Delegatecall, // }); -// spells.push(payProvider); +// spells.push(payExecutor); // const gasPriceCeil = ethers.constants.MaxUint256; @@ -660,13 +660,13 @@ // await expect( // gelatoCore -// .connect(gelatoProviderWallet) +// .connect(gelatoProvider) // .provideTaskSpecs([connectGelatoFullDebtBridgeFromMakerTaskSpec]) // ).to.emit(gelatoCore, "LogTaskSpecProvided"); // expect( // await gelatoCore -// .connect(gelatoProviderWallet) +// .connect(gelatoProvider) // .isTaskSpecProvided( // gelatoProviderAddress, // connectGelatoFullDebtBridgeFromMakerTaskSpec @@ -675,11 +675,11 @@ // expect( // await gelatoCore -// .connect(gelatoProviderWallet) +// .connect(gelatoProvider) // .taskSpecGasPriceCeil( // gelatoProviderAddress, // await gelatoCore -// .connect(gelatoProviderWallet) +// .connect(gelatoProvider) // .hashTaskSpec(connectGelatoFullDebtBridgeFromMakerTaskSpec) // ) // ).to.be.equal(gasPriceCeil); @@ -774,7 +774,7 @@ // expect( // await gelatoCore -// .connect(gelatoExecutorWallet) +// .connect(executor) // .canExec(taskReceipt, GAS_LIMIT, gelatoGasPrice) // ).to.be.equal("ConditionNotOk:MakerVaultNotUnsafe"); @@ -783,7 +783,7 @@ // expect( // await gelatoCore -// .connect(gelatoExecutorWallet) +// .connect(executor) // .canExec(taskReceipt, GAS_LIMIT, gelatoGasPrice) // ).to.be.equal("OK"); @@ -831,10 +831,10 @@ // //console.log(String(wdiv(pricedCollateral.sub(wmul(expectedColWithdrawAmount, latestPrice).add(gasFeesPaidFromCol)),debt.sub(expectedBorAmountToPayBack)))); // //#endregion -// const providerBalanceBeforeExecution = await gelatoProviderWallet.getBalance(); +// const providerBalanceBeforeExecution = await gelatoProvider.getBalance(); // await expect( -// gelatoCore.connect(gelatoExecutorWallet).exec(taskReceipt, { +// gelatoCore.connect(executor).exec(taskReceipt, { // gasPrice: gelatoGasPrice, // Exectutor must use gelatoGasPrice (Chainlink fast gwei) // gasLimit: GAS_LIMIT, // }) @@ -842,7 +842,7 @@ // // 🚧 For Debugging: // // const txResponse2 = await gelatoCore -// // .connect(gelatoProviderWallet) +// // .connect(gelatoProvider) // // .exec(taskReceipt, { // // gasPrice: gelatoGasPrice, // // gasLimit: GAS_LIMIT, @@ -855,7 +855,7 @@ // // } // // await GelatoCoreLib.sleep(10000); -// expect(await gelatoProviderWallet.getBalance()).to.be.gt( +// expect(await gelatoProvider.getBalance()).to.be.gt( // providerBalanceBeforeExecution // ); diff --git a/test/integration/debt_bridge/from_maker/services/enableGelatoConnectorsForFromMaker.js b/test/integration/debt_bridge/from_maker/services/enableGelatoConnectorsForFromMaker.js index 39fcc76..74b96af 100644 --- a/test/integration/debt_bridge/from_maker/services/enableGelatoConnectorsForFromMaker.js +++ b/test/integration/debt_bridge/from_maker/services/enableGelatoConnectorsForFromMaker.js @@ -4,7 +4,7 @@ const { ethers } = hre; module.exports = async function ( userWallet, - connectGelatoProviderPaymentAddr, + connectGelatoExecutorPaymentAddr, connectGelatoDataAddr, instaMaster, instaConnectors @@ -34,7 +34,7 @@ module.exports = async function ( await instaConnectors .connect(instaMaster) - .enable(connectGelatoProviderPaymentAddr); + .enable(connectGelatoExecutorPaymentAddr); await hre.network.provider.request({ method: "hardhat_stopImpersonatingAccount", @@ -42,7 +42,7 @@ module.exports = async function ( }); expect(await instaConnectors.isConnector([connectGelatoDataAddr])).to.be.true; - expect(await instaConnectors.isConnector([connectGelatoProviderPaymentAddr])) + expect(await instaConnectors.isConnector([connectGelatoExecutorPaymentAddr])) .to.be.true; //#endregion diff --git a/test/unit/connectors/0_ConnectGelatoProviderPayment.test.js b/test/unit/connectors/0_ConnectGelatoExecutorPayment.test.js similarity index 63% rename from test/unit/connectors/0_ConnectGelatoProviderPayment.test.js rename to test/unit/connectors/0_ConnectGelatoExecutorPayment.test.js index e9cf225..f5ee18e 100644 --- a/test/unit/connectors/0_ConnectGelatoProviderPayment.test.js +++ b/test/unit/connectors/0_ConnectGelatoExecutorPayment.test.js @@ -2,10 +2,6 @@ const { expect } = require("chai"); const hre = require("hardhat"); const { ethers, deployments } = hre; -const GelatoCoreLib = require("@gelatonetwork/core"); - -// #region Contracts ABI - const ConnectMaker = require("../../../pre-compiles/ConnectMaker.json"); const GetCdps = require("../../../pre-compiles/GetCdps.json"); const DssCdpManager = require("../../../pre-compiles/DssCdpManager.json"); @@ -15,9 +11,7 @@ const InstaAccount = require("../../../pre-compiles/InstaAccount.json"); const InstaIndex = require("../../../pre-compiles/InstaIndex.json"); const IERC20 = require("../../../pre-compiles/IERC20.json"); -// #endregion - -describe("ConnectGelatoProviderPayment Unit Test", function () { +describe("ConnectGelatoExecutorPayment Unit Test", function () { this.timeout(0); if (hre.network.name !== "hardhat") { console.error("Test Suite is meant to be run on hardhat only"); @@ -26,19 +20,15 @@ describe("ConnectGelatoProviderPayment Unit Test", function () { let userWallet; let userAddress; - let gelatoProviderWallet; - let gelatoProviderAddress; - - let gelatoCore; let instaList; let instaIndex; - let DAI; + let dai; let connectBasic; let getCdps; let dssCdpManager; - let connectGelatoProviderPayment; + let connectGelatoExecutorPayment; let dsa; let cdpId; @@ -48,14 +38,8 @@ describe("ConnectGelatoProviderPayment Unit Test", function () { await deployments.fixture(); // Get Test Wallet for local testnet - [userWallet, gelatoProviderWallet] = await ethers.getSigners(); + [userWallet] = await ethers.getSigners(); userAddress = await userWallet.getAddress(); - gelatoProviderAddress = await gelatoProviderWallet.getAddress(); - - gelatoCore = await ethers.getContractAt( - GelatoCoreLib.GelatoCore.abi, - hre.network.config.GelatoCore - ); // Hardhat default accounts prefilled with 100 ETH expect(await userWallet.getBalance()).to.be.gt( @@ -82,11 +66,11 @@ describe("ConnectGelatoProviderPayment Unit Test", function () { DssCdpManager.abi, hre.network.config.DssCdpManager ); - DAI = await ethers.getContractAt(IERC20.abi, hre.network.config.DAI); + dai = await ethers.getContractAt(IERC20.abi, hre.network.config.DAI); // ========== Test Setup ============ - connectGelatoProviderPayment = await ethers.getContract( - "ConnectGelatoProviderPayment" + connectGelatoExecutorPayment = await ethers.getContract( + "ConnectGelatoExecutorPayment" ); // ========== Create DeFi Smart Account for User account ============ @@ -107,29 +91,7 @@ describe("ConnectGelatoProviderPayment Unit Test", function () { ); }); - it("#1: ConnectGelatoProviderPayment should have been deployed with providerAddress", async function () { - expect(await connectGelatoProviderPayment.gelatoProvider()).to.be.eq( - gelatoProviderAddress - ); - }); - - it("#2: setProvider should revert for AddressZero", async function () { - await expect( - connectGelatoProviderPayment.setProvider(ethers.constants.AddressZero) - ).to.be.revertedWith("ConnectGelatoProviderPayment.noAddressZeroProvider"); - }); - - it("#3: setProvider should change the provider address", async function () { - await connectGelatoProviderPayment.setProvider(userAddress); - - expect(await connectGelatoProviderPayment.gelatoProvider()).to.be.equal( - userAddress - ); - }); - - it("#4: payProvider should pay to Provider 300 Dai", async function () { - const providerDAIBalanceBefore = await DAI.balanceOf(gelatoProviderAddress); - + it("#1: payExecutor should pay to Executor 300 dai", async function () { await dsa.cast( [hre.network.config.ConnectMaker], [ @@ -173,36 +135,36 @@ describe("ConnectGelatoProviderPayment Unit Test", function () { userAddress ); - expect(await DAI.balanceOf(dsa.address)).to.be.equal( + expect(await dai.balanceOf(dsa.address)).to.be.equal( ethers.utils.parseEther("1000") ); + const executorDaiBalanceBefore = await dai.balanceOf(userAddress); + await dsa.cast( - [connectGelatoProviderPayment.address], + [connectGelatoExecutorPayment.address], [ await hre.run("abi-encode-withselector", { abi: ( - await hre.artifacts.readArtifact("ConnectGelatoProviderPayment") + await hre.artifacts.readArtifact("ConnectGelatoExecutorPayment") ).abi, - functionname: "payProvider", - inputs: [DAI.address, ethers.utils.parseUnits("300", 18), 0, 0], + functionname: "payExecutor", + inputs: [dai.address, ethers.utils.parseUnits("300", 18), 0, 0], }), ], userAddress ); - expect(await DAI.balanceOf(gelatoProviderAddress)).to.be.equal( - providerDAIBalanceBefore.add(ethers.utils.parseUnits("300", 18)) + expect(await dai.balanceOf(userAddress)).to.be.equal( + executorDaiBalanceBefore.add(ethers.utils.parseUnits("300", 18)) ); }); - it("#5: payProvider should pay to Provider 1 ether", async function () { - const providerBalanceOnGelatoCoreBefore = await gelatoCore.providerFunds( - gelatoProviderAddress - ); + it("#2: payExecutor should pay to Executor 1 ether", async function () { + const executorBalanceBefore = await userWallet.getBalance(); - await dsa.cast( - [connectBasic.address, connectGelatoProviderPayment.address], + const { gasPrice, wait } = await dsa.cast( + [connectBasic.address, connectGelatoExecutorPayment.address], [ await hre.run("abi-encode-withselector", { abi: ConnectBasic.abi, @@ -216,9 +178,9 @@ describe("ConnectGelatoProviderPayment Unit Test", function () { }), await hre.run("abi-encode-withselector", { abi: ( - await hre.artifacts.readArtifact("ConnectGelatoProviderPayment") + await hre.artifacts.readArtifact("ConnectGelatoExecutorPayment") ).abi, - functionname: "payProvider", + functionname: "payExecutor", inputs: ["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", 0, "105", 0], }), ], @@ -228,8 +190,10 @@ describe("ConnectGelatoProviderPayment Unit Test", function () { } ); - expect(await gelatoCore.providerFunds(gelatoProviderAddress)).to.be.equal( - providerBalanceOnGelatoCoreBefore.add(ethers.utils.parseEther("1")) + const { gasUsed } = await wait(); + + expect(await userWallet.getBalance()).to.be.eq( + executorBalanceBefore.sub(gasUsed.mul(gasPrice)) ); }); }); diff --git a/yarn.lock b/yarn.lock index 0805d6d..48c19c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -288,12 +288,12 @@ "@ethersproject/bytes" "^5.0.4" "@ethersproject/properties" "^5.0.3" -"@ethersproject/bignumber@5.0.11", "@ethersproject/bignumber@^5.0.10": - version "5.0.11" - resolved "https://registry.yarnpkg.com/@ethersproject/bignumber/-/bignumber-5.0.11.tgz#0d89c1c42439e04ab85013e6d437e428914fcbb2" - integrity sha512-6mS55WZDceEFZHaWKlRTKwOUmw8sU51Ar1Tbdt3qfk1HNf7i60d6MQVAWJswzCfKWx+E2gCBob8ywajgTZ7zMw== +"@ethersproject/bignumber@5.0.12": + version "5.0.12" + resolved "https://registry.yarnpkg.com/@ethersproject/bignumber/-/bignumber-5.0.12.tgz#fe4a78667d7cb01790f75131147e82d6ea7e7cba" + integrity sha512-mbFZjwthx6vFlHG9owXP/C5QkNvsA+xHpDCkPPPdG2n1dS9AmZAL5DI0InNLid60rQWL3MXpEl19tFmtL7Q9jw== dependencies: - "@ethersproject/bytes" "^5.0.4" + "@ethersproject/bytes" "^5.0.8" "@ethersproject/logger" "^5.0.5" bn.js "^4.4.0" @@ -306,6 +306,15 @@ "@ethersproject/logger" "^5.0.5" bn.js "^4.4.0" +"@ethersproject/bignumber@^5.0.10": + version "5.0.11" + resolved "https://registry.yarnpkg.com/@ethersproject/bignumber/-/bignumber-5.0.11.tgz#0d89c1c42439e04ab85013e6d437e428914fcbb2" + integrity sha512-6mS55WZDceEFZHaWKlRTKwOUmw8sU51Ar1Tbdt3qfk1HNf7i60d6MQVAWJswzCfKWx+E2gCBob8ywajgTZ7zMw== + dependencies: + "@ethersproject/bytes" "^5.0.4" + "@ethersproject/logger" "^5.0.5" + bn.js "^4.4.0" + "@ethersproject/bytes@5.0.5", "@ethersproject/bytes@>=5.0.0-beta.129", "@ethersproject/bytes@^5.0.2", "@ethersproject/bytes@^5.0.4": version "5.0.5" resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.0.5.tgz#688b70000e550de0c97a151a21f15b87d7f97d7c" @@ -313,10 +322,10 @@ dependencies: "@ethersproject/logger" "^5.0.5" -"@ethersproject/bytes@5.0.7": - version "5.0.7" - resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.0.7.tgz#a3e23281ea05b4bfaa769894a18ce5cfc6842dd6" - integrity sha512-AxTEe6ucwifQiauelO/cpbm14coJTFPl/1uXTXclUO7zBy1HHpNRzspUZlJmozZ/vE6/yNsNq82vy+UmoTDF7g== +"@ethersproject/bytes@5.0.8", "@ethersproject/bytes@^5.0.8": + version "5.0.8" + resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.0.8.tgz#cf1246a6a386086e590063a4602b1ffb6cc43db1" + integrity sha512-O+sJNVGzzuy51g+EMK8BegomqNIg+C2RO6vOt0XP6ac4o4saiq69FnjlsrNslaiMFVO7qcEHBsWJ9hx1tj1lMw== dependencies: "@ethersproject/logger" "^5.0.5" @@ -557,10 +566,10 @@ bech32 "1.1.4" ws "7.2.3" -"@ethersproject/providers@5.0.16": - version "5.0.16" - resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.0.16.tgz#23892ea140180f22051801b1a2177ee9c1cc3f75" - integrity sha512-OCo0NH7VC8hfr7ESuZDMQl2Jdz2jpWulNGsWgnxXZT0tuPrrKHO+5BADS5s1W+YsovL3mKFkQjwGcOP2arvhzw== +"@ethersproject/providers@5.0.17": + version "5.0.17" + resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.0.17.tgz#f380e7831149e24e7a1c6c9b5fb1d6dfc729d024" + integrity sha512-bJnvs5X7ttU5x2ekGJYG7R3Z+spZawLFfR0IDsbaMDLiCwZOyrgk+VTBU7amSFLT0WUhWFv8WwSUB+AryCQG1Q== dependencies: "@ethersproject/abstract-provider" "^5.0.4" "@ethersproject/abstract-signer" "^5.0.4" @@ -3970,10 +3979,10 @@ ethereumjs-wallet@0.6.5: utf8 "^3.0.0" uuid "^3.3.2" -ethers@5.0.22: - version "5.0.22" - resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.0.22.tgz#0d7d9b195a6818494ee75f6b2db88b060664cb3a" - integrity sha512-hfpsfQf9b6JITeMULOCJDhWAowS9e6fxCBJfDuFDE3yYZlW0q/U2k3xfSK/q+g8twkRM01uZvUHJN/9zXwrrzQ== +ethers@5.0.23: + version "5.0.23" + resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.0.23.tgz#461a6e63c4906d5ea64126d53975ddf2ca81a979" + integrity sha512-f3pTcgYpMhtmMTMG9KO6pWHYjrCiGz7yVnvMsTQgAYfAVAeUxKy2H1cxQJyqyghRjtAvgVYJlnXQo8mMCD63BA== dependencies: "@ethersproject/abi" "5.0.9" "@ethersproject/abstract-provider" "5.0.7" @@ -3981,8 +3990,8 @@ ethers@5.0.22: "@ethersproject/address" "5.0.8" "@ethersproject/base64" "5.0.6" "@ethersproject/basex" "5.0.6" - "@ethersproject/bignumber" "5.0.11" - "@ethersproject/bytes" "5.0.7" + "@ethersproject/bignumber" "5.0.12" + "@ethersproject/bytes" "5.0.8" "@ethersproject/constants" "5.0.7" "@ethersproject/contracts" "5.0.8" "@ethersproject/hash" "5.0.8" @@ -3993,7 +4002,7 @@ ethers@5.0.22: "@ethersproject/networks" "5.0.6" "@ethersproject/pbkdf2" "5.0.6" "@ethersproject/properties" "5.0.6" - "@ethersproject/providers" "5.0.16" + "@ethersproject/providers" "5.0.17" "@ethersproject/random" "5.0.6" "@ethersproject/rlp" "5.0.6" "@ethersproject/sha2" "5.0.6"