Skip to content

Commit

Permalink
Scaling Price Oracle Sets Chainlink Token (volt-protocol#81)
Browse files Browse the repository at this point in the history
* Scaling Price Oracle sets chainlink token when not on local network

* update with new params from may numbers

* update ScalingPriceOracle to use chainlink token provided in constructor rather than function setPublicChainlinkToken

* add arbitrum chainlink token to config

* add test to verify cl token address, expose getter method in SPO to get cl token address

* add new scaling price oracle to mainnet addresses file, remove unnecessary comment
  • Loading branch information
ElliotFriedman authored Jun 27, 2022
1 parent 1d036fa commit 0157558
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 27 deletions.
2 changes: 2 additions & 0 deletions contracts/mock/MockL2ScalingPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contract MockL2ScalingPriceOracle is L2ScalingPriceOracle {
uint256 _fee,
uint128 _currentMonth,
uint128 _previousMonth,
address _chainlinkToken,
uint256 _actualStartTime,
uint256 _startingOraclePrice
)
Expand All @@ -24,6 +25,7 @@ contract MockL2ScalingPriceOracle is L2ScalingPriceOracle {
_fee,
_currentMonth,
_previousMonth,
_chainlinkToken,
_actualStartTime,
_startingOraclePrice
)
Expand Down
14 changes: 12 additions & 2 deletions contracts/mock/MockScalingPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ contract MockScalingPriceOracle is ScalingPriceOracle {
bytes32 _jobid,
uint256 _fee,
uint128 _currentMonth,
uint128 _previousMonth
) ScalingPriceOracle(_oracle, _jobid, _fee, _currentMonth, _previousMonth) {
uint128 _previousMonth,
address _chainlinkToken
)
ScalingPriceOracle(
_oracle,
_jobid,
_fee,
_currentMonth,
_previousMonth,
_chainlinkToken
)
{
owner = msg.sender;
}

Expand Down
13 changes: 12 additions & 1 deletion contracts/oracle/L2ScalingPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract L2ScalingPriceOracle is ScalingPriceOracle {
/// @param _fee maximum fee paid to chainlink data provider
/// @param _currentMonth current month's inflation data
/// @param _previousMonth previous month's inflation data
/// @param _chainlinkToken address of the chainlink token
/// @param _actualStartTime unix timestamp of Oracle Price interpolation starting time
/// @param _startingOraclePrice starting oracle price
constructor(
Expand All @@ -27,9 +28,19 @@ contract L2ScalingPriceOracle is ScalingPriceOracle {
uint256 _fee,
uint128 _currentMonth,
uint128 _previousMonth,
address _chainlinkToken,
uint256 _actualStartTime,
uint256 _startingOraclePrice
) ScalingPriceOracle(_oracle, _jobid, _fee, _currentMonth, _previousMonth) {
)
ScalingPriceOracle(
_oracle,
_jobid,
_fee,
_currentMonth,
_previousMonth,
_chainlinkToken
)
{
/// ensure start time is not more than 28 days ago
require(
_actualStartTime > block.timestamp - TIMEFRAME,
Expand Down
19 changes: 9 additions & 10 deletions contracts/oracle/ScalingPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,16 @@ contract ScalingPriceOracle is
/// @param _fee maximum fee paid to chainlink data provider
/// @param _currentMonth current month's inflation data
/// @param _previousMonth previous month's inflation data
/// @param _chainlinkToken address of the chainlink token
constructor(
address _oracle,
bytes32 _jobid,
uint256 _fee,
uint128 _currentMonth,
uint128 _previousMonth
uint128 _previousMonth,
address _chainlinkToken
) Timed(TIMEFRAME) {
uint256 chainId;
// solhint-disable-next-line no-inline-assembly
assembly {
chainId := chainid()
}

if (chainId == 1 || chainId == 42) {
setPublicChainlinkToken();
}
setChainlinkToken(_chainlinkToken);

oracle = _oracle;
jobId = _jobid;
Expand Down Expand Up @@ -124,6 +118,11 @@ contract ScalingPriceOracle is
percentageChange = (delta * Constants.BP_INT) / int128(previousMonth);
}

/// @notice return the address of the chainlink token referenced by this contract
function getChainlinkTokenAddress() public view returns (address) {
return chainlinkTokenAddress();
}

/// ------------- Public API To Request Chainlink Data -------------

/// @notice Create a Chainlink request to retrieve API response, find the target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ contract IntegrationTestL2ScalingPriceOracle is DSTest {
ScalingPriceOracle(0x79412660E95F94a4D2d02a050CEA776200939917);
L2ScalingPriceOracle private l2scalingPriceOracle;

/// @notice address of chainlink token on arbitrum
address public constant chainlinkToken =
0xf97f4df75117a78c1A5a0DBb814Af92458539FB4;

/// @notice increase price by x% per month
int256 public monthlyChangeRateBasisPoints =
scalingPriceOracle.monthlyChangeRateBasisPoints();
Expand Down Expand Up @@ -58,6 +62,7 @@ contract IntegrationTestL2ScalingPriceOracle is DSTest {
fee,
currentMonth,
previousMonth,
chainlinkToken,
startTime,
startOraclePrice
);
Expand Down Expand Up @@ -99,6 +104,10 @@ contract IntegrationTestL2ScalingPriceOracle is DSTest {
scalingPriceOracle.getCurrentOraclePrice(),
l2scalingPriceOracle.getCurrentOraclePrice()
);
assertEq(
l2scalingPriceOracle.getChainlinkTokenAddress(),
chainlinkToken
);
}

function _testOraclePriceEquivalence() internal {
Expand All @@ -125,14 +134,17 @@ contract IntegrationTestL2ScalingPriceOracle is DSTest {
jobId,
fee,
previousMonth, /// flip current and previous months so that rate is -3%
currentMonth
currentMonth,
chainlinkToken
);

l2scalingPriceOracle = new MockL2ScalingPriceOracle(
oracle,
jobId,
fee,
previousMonth, /// flip current and previous months so that rate is -3%
currentMonth,
chainlinkToken,
scalingPriceOracle.startTime(),
1e18
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ contract IntegrationTestVoltDeployment is DSTest, StdLib {
address public immutable feiDAOTimelock =
0xd51dbA7a94e1adEa403553A8235C302cEbF41a3c;

/// @notice address of chainlink token on mainnet
address public constant chainlinkToken =
0x514910771AF9Ca656af840dff83E8264EcF986CA;

/// @notice Oracle Pass Through contract
OraclePassThrough public oracle;

Expand All @@ -70,7 +74,8 @@ contract IntegrationTestVoltDeployment is DSTest, StdLib {
jobId,
10e18,
101,
100
100,
address(0)
);

oracle = new OraclePassThrough(
Expand Down
18 changes: 16 additions & 2 deletions contracts/test/unit/oracle/L2ScalingPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ contract L2ScalingPriceOracleTest is DSTest {
jobId,
fee,
currentMonth,
previousMonth
previousMonth,
address(0)
);

vm.warp(block.timestamp + 20 days); /// now 70 days have passed
Expand All @@ -66,6 +67,7 @@ contract L2ScalingPriceOracleTest is DSTest {
fee,
currentMonth,
previousMonth,
address(0),
50 days,
1e18
);
Expand All @@ -86,6 +88,11 @@ contract L2ScalingPriceOracleTest is DSTest {
scalingPriceOracle.getMonthlyAPR(),
monthlyChangeRateBasisPoints
);
assertEq(
scalingPriceOracle.getChainlinkTokenAddress(),
l2scalingPriceOracle.getChainlinkTokenAddress()
);
assertEq(l2scalingPriceOracle.getChainlinkTokenAddress(), address(0));
}

function testOracleSetupEquivalence() public {
Expand Down Expand Up @@ -135,14 +142,16 @@ contract L2ScalingPriceOracleTest is DSTest {
jobId,
fee,
previousMonth, /// flip current and previous months so that rate is -3%
currentMonth
currentMonth,
address(0)
);
l2scalingPriceOracle = new MockL2ScalingPriceOracle(
oracle,
jobId,
fee,
previousMonth, /// flip current and previous months so that rate is -3%
currentMonth,
address(0),
block.timestamp,
1e18
);
Expand Down Expand Up @@ -321,6 +330,7 @@ contract L2ScalingPriceOracleTest is DSTest {
fee,
currentMonth,
previousMonth,
address(0),
0, /// cause first check to fail as 0 < 1
1e18
);
Expand All @@ -336,6 +346,7 @@ contract L2ScalingPriceOracleTest is DSTest {
fee,
currentMonth,
previousMonth,
address(0),
block.timestamp,
99e16
);
Expand All @@ -348,6 +359,7 @@ contract L2ScalingPriceOracleTest is DSTest {
fee,
currentMonth,
previousMonth,
address(0),
block.timestamp,
2e18
);
Expand All @@ -363,6 +375,7 @@ contract L2ScalingPriceOracleTest is DSTest {
fee,
currentMonth,
previousMonth,
address(0),
block.timestamp,
2e18
);
Expand Down Expand Up @@ -418,6 +431,7 @@ contract L2ScalingPriceOracleTest is DSTest {
fee,
currentMonth,
previousMonth,
address(0),
block.timestamp,
x
);
Expand Down
6 changes: 4 additions & 2 deletions contracts/test/unit/oracle/OraclePassThrough.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ contract OraclePassThroughTest is DSTest {
jobId,
fee,
currentMonth,
previousMonth
previousMonth,
address(0)
);

oraclePassThrough = new OraclePassThrough(
Expand Down Expand Up @@ -96,7 +97,8 @@ contract OraclePassThroughTest is DSTest {
jobId,
fee,
currentMonth,
previousMonth
previousMonth,
address(0)
)
)
);
Expand Down
7 changes: 5 additions & 2 deletions contracts/test/unit/oracle/ScalingPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ contract ScalingPriceOracleTest is DSTest {
jobId,
fee,
currentMonth,
previousMonth
previousMonth,
address(0)
);
}

Expand All @@ -65,6 +66,7 @@ contract ScalingPriceOracleTest is DSTest {
scalingPriceOracle.getMonthlyAPR(),
monthlyChangeRateBasisPoints
);
assertEq(scalingPriceOracle.getChainlinkTokenAddress(), address(0));
}

/// positive price action from oracle -- inflation case
Expand All @@ -80,7 +82,8 @@ contract ScalingPriceOracleTest is DSTest {
jobId,
fee,
previousMonth, /// flip current and previous months so that rate is -3%
currentMonth
currentMonth,
address(0)
);

vm.warp(block.timestamp + 28 days);
Expand Down
3 changes: 2 additions & 1 deletion contracts/test/unit/psm/NonCustodialPSM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ contract NonCustodialPSMTest is DSTest {
keccak256(abi.encodePacked("test")),
10e18,
101,
100
100,
address(0)
);

oracle = new OraclePassThrough(
Expand Down
2 changes: 1 addition & 1 deletion protocol-configuration/mainnetAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const MainnetAddresses: MainnetAddresses = {
network: Network.Arbitrum
},
arbitrumScalingPriceOracle: {
address: '0x0313a76AD2cE70A35eC95066f942becab6A64893',
address: '0x138F30D35557FA72478663b601f0f0FD7cc4E39E',
artifactName: 'L2ScalingPriceOracle',
category: AddressCategory.Oracle,
network: Network.Arbitrum
Expand Down
9 changes: 5 additions & 4 deletions scripts/L2Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ const l2config = {
ADDRESS_ONE: '0x0000000000000000000000000000000000000001',
L2_REDEEM_FEE_BASIS_POINTS: 5,

ACTUAL_START_TIME: '1652575642',
STARTING_L2_ORACLE_PRICE: '1028069999088399458',
ACTUAL_START_TIME: '1655251723',
STARTING_L2_ORACLE_PRICE: '1033724384083385655',

/// Chainlink
L2_ARBITRUM_JOB_ID: ethers.utils.toUtf8Bytes('db685451903340c590d22eb505d49946'),
L2_ARBITRUM_CHAINLINK_FEE: ethers.utils.parseEther('1'), /// 1 Link to request data on L2
L2_ARBITRUM_CHAINLINK_ORACLE_ADDRESS: '0xf76F586F6aAC0c8dE147Eea75D76AB7c2f23eDC2',
L2_ARBITRUM_CHAINLINK_TOKEN: '0xf97f4df75117a78c1A5a0DBb814Af92458539FB4',

L2_ARBITRUM_PREVIOUS_MONTH: '287504',
L2_ARBITRUM_CURRENT_MONTH: '289109',
L2_ARBITRUM_PREVIOUS_MONTH: '289109',
L2_ARBITRUM_CURRENT_MONTH: '292296',

L2_ARBITRUM_PROTOCOL_MULTISIG_ADDRESS: '0x1A1075cef632624153176CCf19Ae0175953CF010',
L2_ARBITRUM_VOLT: '0x6Ba6f18a290Cd55cf1B00be2bEc5c954cb29fAc5',
Expand Down
Loading

0 comments on commit 0157558

Please sign in to comment.