-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add gas capped gov chain and voting chain robots
- Loading branch information
1 parent
de3198c
commit 057ac20
Showing
13 changed files
with
562 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/contracts/gasprice-capped-robots/GasCappedGovernanceChainRobotKeeper.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import {GovernanceChainRobotKeeper} from '../GovernanceChainRobotKeeper.sol'; | ||
import {AutomationCompatibleInterface} from 'chainlink/src/v0.8/interfaces/automation/AutomationCompatibleInterface.sol'; | ||
import {GasCappedRobotBase} from './GasCappedRobotBase.sol'; | ||
|
||
/** | ||
* @title GasCappedGovernanceChainRobotKeeper | ||
* @author BGD Labs | ||
* @notice Contract to perform automation on governance contract for goveranance v3. | ||
* The difference from GovernanceChainRobotKeeper is that automation is only | ||
* performed when the network gas price in within the maximum configured range. | ||
*/ | ||
contract GasCappedGovernanceChainRobotKeeper is GasCappedRobotBase, GovernanceChainRobotKeeper { | ||
/** | ||
* @param governance address of the governance contract. | ||
* @param gasPriceOracle address of the gas price oracle contract. | ||
*/ | ||
constructor( | ||
address governance, | ||
address gasPriceOracle | ||
) GovernanceChainRobotKeeper(governance) GasCappedRobotBase(gasPriceOracle) {} | ||
|
||
/** | ||
* @inheritdoc AutomationCompatibleInterface | ||
* @dev run off-chain, checks if payload should be executed | ||
* also checks that the gas price of the network in within range to perform actions | ||
*/ | ||
function checkUpkeep(bytes memory) public view override returns (bool, bytes memory) { | ||
if (!isGasPriceInRange()) return (false, ''); | ||
|
||
return super.checkUpkeep(''); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/contracts/gasprice-capped-robots/GasCappedRobotBase.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import {IGasPriceCappedRobot} from '../../interfaces/IGasPriceCappedRobot.sol'; | ||
import {AggregatorInterface} from 'aave-address-book/AaveV3.sol'; | ||
import {Ownable} from 'solidity-utils/contracts/oz-common/Ownable.sol'; | ||
|
||
/** | ||
* @title GasCappedRobotBase | ||
* @author BGD Labs | ||
* @notice Abstract contract to be inherited by robots to limit actions by configured gasPrice. | ||
*/ | ||
abstract contract GasCappedRobotBase is Ownable, IGasPriceCappedRobot { | ||
/// @inheritdoc IGasPriceCappedRobot | ||
address public immutable GAS_PRICE_ORACLE; | ||
|
||
uint256 internal _maxGasPrice; | ||
|
||
/** | ||
* @param gasPriceOracle address of the gas price oracle contract. | ||
*/ | ||
constructor(address gasPriceOracle) { | ||
GAS_PRICE_ORACLE = gasPriceOracle; | ||
} | ||
|
||
/// @inheritdoc IGasPriceCappedRobot | ||
function setMaxGasPrice(uint256 maxGasPrice) external onlyOwner { | ||
_maxGasPrice = maxGasPrice; | ||
emit MaxGasPriceSet(maxGasPrice); | ||
} | ||
|
||
/// @inheritdoc IGasPriceCappedRobot | ||
function getMaxGasPrice() external view returns (uint256) { | ||
return _maxGasPrice; | ||
} | ||
|
||
/// @inheritdoc IGasPriceCappedRobot | ||
function isGasPriceInRange() public view virtual returns (bool) { | ||
if (uint256(AggregatorInterface(GAS_PRICE_ORACLE).latestAnswer()) > _maxGasPrice) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/contracts/gasprice-capped-robots/GasCappedVotingChainRobotKeeper.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.0; | ||
|
||
import {VotingChainRobotKeeper} from '../VotingChainRobotKeeper.sol'; | ||
import {AutomationCompatibleInterface} from 'chainlink/src/v0.8/interfaces/automation/AutomationCompatibleInterface.sol'; | ||
import {GasCappedRobotBase} from './GasCappedRobotBase.sol'; | ||
|
||
/** | ||
* @title GasCappedVotingChainRobotKeeper | ||
* @author BGD Labs | ||
* @notice Contract to perform automation on voting machine and data warehouse contract for goveranance v3. | ||
* The difference from VotingChainRobotKeeper is that automation is only | ||
* performed when the network gas price in within the maximum configured range. | ||
*/ | ||
contract GasCappedVotingChainRobotKeeper is GasCappedRobotBase, VotingChainRobotKeeper { | ||
/** | ||
* @param votingMachine address of the voting machine contract. | ||
* @param rootsConsumer address of the roots consumer contract to registers the roots. | ||
* @param gasPriceOracle address of the gas price oracle contract. | ||
*/ | ||
constructor( | ||
address votingMachine, | ||
address rootsConsumer, | ||
address gasPriceOracle | ||
) VotingChainRobotKeeper(votingMachine, rootsConsumer) GasCappedRobotBase(gasPriceOracle) {} | ||
|
||
/** | ||
* @inheritdoc AutomationCompatibleInterface | ||
* @dev run off-chain, checks if payload should be executed | ||
* also checks that the gas price of the network in within range to perform actions | ||
*/ | ||
function checkUpkeep(bytes memory) public view override returns (bool, bytes memory) { | ||
if (!isGasPriceInRange()) return (false, ''); | ||
|
||
return super.checkUpkeep(''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.