Skip to content

Commit

Permalink
Work out how to integrate forwarder address
Browse files Browse the repository at this point in the history
  • Loading branch information
crispymangoes committed Oct 16, 2023
1 parent 9b32d9f commit 4113cd2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/base/ERC4626SharePriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ERC4626 } from "@solmate/mixins/ERC4626.sol";
import { Math } from "src/utils/Math.sol";
import { Owned } from "@solmate/auth/Owned.sol";
import { AutomationCompatibleInterface } from "@chainlink/contracts/src/v0.8/interfaces/AutomationCompatibleInterface.sol";
import { IRegistrar } from "src/interfaces/external/Chainlink/IRegistrar.sol";
import { IRegistry } from "src/interfaces/external/Chainlink/IRegistry.sol";

contract ERC4626SharePriceOracle is AutomationCompatibleInterface {
using Math for uint256;
Expand Down Expand Up @@ -121,10 +123,12 @@ contract ERC4626SharePriceOracle is AutomationCompatibleInterface {
*/
uint256 public immutable ONE_SHARE;

// TODO
/**
* @notice Chainlink's Automation Registry contract address.
* @notice For mainnet use 0x02777053d6764996e594c3E88AF1D58D5363a2e6.
*/
// address public immutable automationForwarder;
address public immutable automationRegistry;

/**
Expand Down Expand Up @@ -160,7 +164,10 @@ contract ERC4626SharePriceOracle is AutomationCompatibleInterface {
uint64 _deviationTrigger,
uint64 _gracePeriod,
uint16 _observationsToUse,
// address _automationRegistrar,
address _automationRegistry,
// address _admin,
// uint96 _initialUpkeepFunds,
uint216 _startingAnswer,
uint256 _allowedAnswerChangeLower,
uint256 _allowedAnswerChangeUpper
Expand All @@ -171,7 +178,6 @@ contract ERC4626SharePriceOracle is AutomationCompatibleInterface {
heartbeat = _heartbeat;
deviationTrigger = _deviationTrigger;
gracePeriod = _gracePeriod;
automationRegistry = _automationRegistry;
// Add 1 to observations to use.
_observationsToUse = _observationsToUse + 1;
observationsLength = _observationsToUse;
Expand All @@ -187,6 +193,30 @@ contract ERC4626SharePriceOracle is AutomationCompatibleInterface {
allowedAnswerChangeLower = _allowedAnswerChangeLower;
if (_allowedAnswerChangeUpper < 1e4) revert("Illogical Upper");
allowedAnswerChangeUpper = _allowedAnswerChangeUpper;

automationRegistry = _automationRegistry;

// Create the upkeep.

// IRegistrar registrar = IRegistrar(_automationRegistrar);
// IRegistry registry = IRegistry(_automationRegistry);
// IRegistrar.RegistrationParams memory params = IRegistrar.RegistrationParams{
// name: string.concat(_target.name(), " Share Price Oracle"),
// encryptedEmail: hex"",
// upkeepContract: address(this),
// gasLimit: 50_000,
// adminAddress: _admin,
// triggerType: 0,
// checkData: hex"",
// triggerConfig: hex"",
// offchainConfig: hex"",
// amount: _initialUpkeepFunds
// };

// // TODO need to approve registrar to spend LINK.
// uint256 upkeepID = registrar.registerUpkeep(params);
// automationForwarder = registry.getForwarder(upkeepID);
// msg.data;
}

//============================== CHAINLINK AUTOMATION ===============================
Expand Down
19 changes: 19 additions & 0 deletions src/interfaces/external/Chainlink/IRegistrar.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.21;

interface IRegistrar {
struct RegistrationParams {
string name;
bytes encryptedEmail;
address upkeepContract;
uint32 gasLimit;
address adminAddress;
uint8 triggerType;
bytes checkData;
bytes triggerConfig;
bytes offchainConfig;
uint96 amount;
}

function registerUpkeep(RegistrationParams calldata requestParams) external returns (uint256 id);
}
6 changes: 6 additions & 0 deletions src/interfaces/external/Chainlink/IRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.21;

interface IRegistry {
function getForwarder(uint256 upkeepID) external view returns (address forwarder);
}

0 comments on commit 4113cd2

Please sign in to comment.