This repository has been archived by the owner on Sep 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brendan Chou
committed
Mar 30, 2020
1 parent
935a206
commit 4c5dd42
Showing
14 changed files
with
376 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2020 dYdX Trading Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity 0.5.16; | ||
pragma experimental ABIEncoderV2; | ||
|
||
|
||
/** | ||
* @title I_MakerOracle | ||
* @author dYdX | ||
* | ||
* Interface for the price oracles run by MakerDao | ||
*/ | ||
interface I_MakerOracle { | ||
// returns the current value (ETH/USD * 10**18) as a bytes32 | ||
function peek() | ||
external | ||
view | ||
returns (bytes32, bool); | ||
|
||
// requires a fresh price and then returns the current value | ||
function read() | ||
external | ||
view | ||
returns (bytes32); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2020 dYdX Trading Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity 0.5.16; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { I_MakerOracle } from "../../../external/maker/I_MakerOracle.sol"; | ||
import { I_P1Oracle } from "../intf/I_P1Oracle.sol"; | ||
|
||
|
||
/** | ||
* @title P1MakerOracle | ||
* @author dYdX | ||
* | ||
* P1Oracle that reads the price directly from a Maker V2 Oracle. | ||
*/ | ||
contract P1MakerOracle is | ||
I_P1Oracle | ||
{ | ||
// ============ Storage ============ | ||
|
||
address public _ORACLE_ADDRESS_; | ||
|
||
address public _PERPETUAL_V1_; | ||
|
||
// ============ Constructor ============ | ||
|
||
constructor( | ||
address perpetualV1, | ||
address oracleAddress | ||
) | ||
public | ||
{ | ||
_PERPETUAL_V1_ = perpetualV1; | ||
_ORACLE_ADDRESS_ = oracleAddress; | ||
} | ||
|
||
// ============ Public Functions ============ | ||
|
||
/** | ||
* Returns the price of the underlying asset relative to the margin token. | ||
*/ | ||
function getPrice() | ||
external | ||
view | ||
returns (uint256) | ||
{ | ||
require( | ||
msg.sender == _PERPETUAL_V1_, | ||
"msg.sender must be PerpetualV1" | ||
); | ||
return uint256(I_MakerOracle(_ORACLE_ADDRESS_).read()); | ||
} | ||
} |
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,77 @@ | ||
/* | ||
Copyright 2020 dYdX Trading Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity 0.5.16; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { I_MakerOracle } from "../../external/maker/I_MakerOracle.sol"; | ||
|
||
|
||
/** | ||
* @title Test_MakerOracle | ||
* @author dYdX | ||
* | ||
* MakerOracle for testing | ||
*/ | ||
/* solium-disable-next-line camelcase */ | ||
contract Test_MakerOracle is | ||
I_MakerOracle | ||
{ | ||
uint256 public _PRICE_ = 0; | ||
bool public _VALID_ = true; | ||
|
||
// ============ Set Functions ============ | ||
|
||
function setPrice( | ||
uint256 newPrice | ||
) | ||
external | ||
{ | ||
_PRICE_ = newPrice; | ||
} | ||
|
||
function setValidity( | ||
bool valid | ||
) | ||
external | ||
{ | ||
_VALID_ = valid; | ||
} | ||
|
||
// ============ Get Functions ============ | ||
|
||
function read() | ||
external | ||
view | ||
returns (bytes32) | ||
{ | ||
require( | ||
_VALID_, | ||
"Median/invalid-price-feed" | ||
); | ||
return bytes32(_PRICE_); | ||
} | ||
|
||
function peek() | ||
external | ||
view | ||
returns (bytes32, bool) | ||
{ | ||
return (bytes32(_PRICE_), _VALID_); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
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
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.