Skip to content

Commit

Permalink
priority pool oracle contract
Browse files Browse the repository at this point in the history
  • Loading branch information
BkChoy committed Aug 29, 2023
1 parent d1f32dc commit 6544179
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 7 deletions.
15 changes: 15 additions & 0 deletions contracts/core/interfaces/IPriorityPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;

interface IPriorityPool {
function paused() external view returns (bool);

function pauseForUpdate() external;

function updateDistribution(
bytes32 _merkleRoot,
bytes32 _ipfsHash,
uint256 _amountDistributed,
uint256 _sharesAmountDistributed
) external;
}
97 changes: 97 additions & 0 deletions contracts/core/priorityPool/DistributionOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

import "../interfaces/IPriorityPool.sol";

contract DistributionOracle is ChainlinkClient, Ownable {
using Chainlink for Chainlink.Request;

IPriorityPool public priorityPool;

bytes32 public jobId;
uint256 public fee;

uint256 public minBlockConfirmations;
uint256 public pausedAtBlockNumber;

error NotPaused();
error InsufficientBlockConfirmations();
error InsufficientBalance();

/**
* @notice Initialize the contract
* @param _chainlinkToken address of LINK token
* @param _chainlinkOracle address of operator contract
* @param _jobId id of job
* @param _fee fee charged for each request paid in LINK
* @param _minBlockConfirmations min # of blocks to wait to request update after pausing priority pool
* @param _priorityPool address of priority pool
*/
constructor(
address _chainlinkToken,
address _chainlinkOracle,
bytes32 _jobId,
uint256 _fee,
uint256 _minBlockConfirmations,
address _priorityPool
) {
setChainlinkToken(_chainlinkToken);
setChainlinkOracle(_chainlinkOracle);
jobId = _jobId;
fee = _fee;
minBlockConfirmations = _minBlockConfirmations;
priorityPool = IPriorityPool(_priorityPool);
}

/**
* @notice Pauses the priority pool so a new merkle tree can be calculated
* @dev must always be called before requestUpdate()
*/
function pauseForUpdate() external onlyOwner {
priorityPool.pauseForUpdate();
pausedAtBlockNumber = block.number;
}

/**
* @notice Requests a new update which will calculate a new merkle tree, post the data to IPFS, and update
* the priority pool
* @dev pauseForUpdate() must be called before calling this function
*/
function requestUpdate() external onlyOwner {
if (!priorityPool.paused()) revert NotPaused();
if (block.number < pausedAtBlockNumber + minBlockConfirmations) revert InsufficientBlockConfirmations();
Chainlink.Request memory req = buildChainlinkRequest(jobId, address(this), this.fulfillRequest.selector);
req.addUint("blockNumber", pausedAtBlockNumber);
sendChainlinkRequest(req, fee);
}

/**
* @notice Fulfills an update request
* @param _requestId id of the request to fulfill
* @param _merkleRoot new merkle root for the distribution tree
* @param _ipfsHash new ipfs hash for the distribution tree (CIDv0, no prefix - only hash)
* @param _amountDistributed amount of LSD tokens distributed in this distribution
* @param _sharesAmountDistributed amount of LSD shares distributed in this distribution
*/
function fulfillRequest(
bytes32 _requestId,
bytes32 _merkleRoot,
bytes32 _ipfsHash,
uint256 _amountDistributed,
uint256 _sharesAmountDistributed
) public recordChainlinkFulfillment(_requestId) {
priorityPool.updateDistribution(_merkleRoot, _ipfsHash, _amountDistributed, _sharesAmountDistributed);
}

/**
* @notice Withdraws LINK tokens
* @param _amount amount to withdraw
*/
function withdrawLink(uint256 _amount) public onlyOwner {
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
if (link.transfer(msg.sender, _amount) != true) revert InsufficientBalance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import "@openzeppelin/contracts-upgradeable/utils/cryptography/MerkleProofUpgrad
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";

import "./interfaces/IStakingPool.sol";
import "./interfaces/ISDLPool.sol";
import "../interfaces/IStakingPool.sol";
import "../interfaces/ISDLPool.sol";

/**
* @title Priority Pool
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"typescript": "^4.5.5"
},
"dependencies": {
"@chainlink/contracts": "^0.4.2",
"@chainlink/contracts": "0.6.1",
"@openzeppelin/contracts": "^4.7.0",
"@openzeppelin/contracts-upgradeable": "^4.9.2",
"@prb/math": "^2.5.0",
Expand Down
26 changes: 22 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,15 @@
"@babel/helper-validator-identifier" "^7.16.7"
to-fast-properties "^2.0.0"

"@chainlink/contracts@^0.4.2":
version "0.4.2"
resolved "https://registry.yarnpkg.com/@chainlink/contracts/-/contracts-0.4.2.tgz#2928a35e8da94664b8ffeb8f5a54b1a3f14d5b3f"
integrity sha512-wVI/KZ9nIH0iqoebVxYrZfNVWO23vwds1UrHdbF+S0JwyixtT+54xYGlot723jCrAeBeQHsDRQXnEhhbUEHpgQ==
"@chainlink/contracts@0.6.1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@chainlink/contracts/-/contracts-0.6.1.tgz#8842b57e755793cbdbcbc45277fb5d179c993e19"
integrity sha512-EuwijGexttw0UjfrW+HygwhQIrGAbqpf1ue28R55HhWMHBzphEH0PhWm8DQmFfj5OZNy8Io66N4L0nStkZ3QKQ==
dependencies:
"@eth-optimism/contracts" "^0.5.21"
"@openzeppelin/contracts" "~4.3.3"
"@openzeppelin/contracts-upgradeable" "^4.7.3"
"@openzeppelin/contracts-v0.7" "npm:@openzeppelin/[email protected]"

"@cspotcode/[email protected]":
version "0.8.0"
Expand Down Expand Up @@ -1513,16 +1516,31 @@
"@types/sinon-chai" "^3.2.3"
"@types/web3" "1.0.19"

"@openzeppelin/contracts-upgradeable@^4.7.3":
version "4.9.3"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.3.tgz#ff17a80fb945f5102571f8efecb5ce5915cc4811"
integrity sha512-jjaHAVRMrE4UuZNfDwjlLGDxTHWIOwTJS2ldnc278a0gevfXfPr8hxKEVBGFBE96kl2G3VHDZhUimw/+G3TG2A==

"@openzeppelin/contracts-upgradeable@^4.9.2":
version "4.9.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.9.2.tgz#a817c75688f8daede420052fbcb34e52482e769e"
integrity sha512-siviV3PZV/fHfPaoIC51rf1Jb6iElkYWnNYZ0leO23/ukXuvOyoC/ahy8jqiV7g+++9Nuo3n/rk5ajSN/+d/Sg==

"@openzeppelin/contracts-v0.7@npm:@openzeppelin/[email protected]":
version "3.4.2"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-3.4.2.tgz#d81f786fda2871d1eb8a8c5a73e455753ba53527"
integrity sha512-z0zMCjyhhp4y7XKAcDAi3Vgms4T2PstwBdahiO0+9NaGICQKjynK3wduSRplTgk4LXmoO1yfDGO5RbjKYxtuxA==

"@openzeppelin/contracts@^4.7.0":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.7.0.tgz#3092d70ea60e3d1835466266b1d68ad47035a2d5"
integrity sha512-52Qb+A1DdOss8QvJrijYYPSf32GUg2pGaG/yCxtaA3cu4jduouTdg4XZSMLW9op54m1jH7J8hoajhHKOPsoJFw==

"@openzeppelin/contracts@~4.3.3":
version "4.3.3"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.3.tgz#ff6ee919fc2a1abaf72b22814bfb72ed129ec137"
integrity sha512-tDBopO1c98Yk7Cv/PZlHqrvtVjlgK5R4J6jxLwoO7qxK4xqOiZG+zSkIvGFpPZ0ikc3QOED3plgdqjgNTnBc7g==

"@openzeppelin/defender-base-client@^1.46.0":
version "1.46.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-base-client/-/defender-base-client-1.46.0.tgz#aa5177f8fbad23fd03d78f3dbe06664bbe9333ff"
Expand Down

0 comments on commit 6544179

Please sign in to comment.