@venusprotocol/oracle 1.6.9 → 1.6.11-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +11 -0
- package/README.md +117 -0
- package/contracts/ResilientOracle.sol +45 -37
- package/contracts/interfaces/PythInterface.sol +4 -1
- package/contracts/oracles/BinanceOracle.sol +65 -24
- package/contracts/oracles/BoundValidator.sol +51 -54
- package/contracts/oracles/ChainlinkOracle.sol +54 -54
- package/contracts/oracles/PythOracle.sol +48 -47
- package/contracts/oracles/TwapOracle.sol +85 -83
- package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +1 -1
- package/contracts/oracles/mocks/MockBinanceOracle.sol +1 -7
- package/contracts/oracles/mocks/MockPythOracle.sol +1 -1
- package/contracts/oracles/mocks/MockTwapOracle.sol +1 -1
- package/contracts/test/AccessControlManager.sol +6 -0
- package/contracts/test/BEP20Harness.sol +4 -0
- package/contracts/test/MockPyth.sol +9 -2
- package/deployments/bscmainnet/.chainId +1 -0
- package/deployments/bscmainnet/BinanceOracle.json +571 -0
- package/deployments/bscmainnet/BinanceOracle_Implementation.json +629 -0
- package/deployments/bscmainnet/BinanceOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/BoundValidator.json +621 -0
- package/deployments/bscmainnet/BoundValidator_Implementation.json +706 -0
- package/deployments/bscmainnet/BoundValidator_Proxy.json +251 -0
- package/deployments/bscmainnet/ChainlinkOracle.json +691 -0
- package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +820 -0
- package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/DefaultProxyAdmin.json +257 -0
- package/deployments/bscmainnet/PythOracle.json +688 -0
- package/deployments/bscmainnet/PythOracle_Implementation.json +804 -0
- package/deployments/bscmainnet/PythOracle_Proxy.json +265 -0
- package/deployments/bscmainnet/ResilientOracle.json +841 -0
- package/deployments/bscmainnet/ResilientOracle_Implementation.json +1044 -0
- package/deployments/bscmainnet/ResilientOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/TwapOracle.json +887 -0
- package/deployments/bscmainnet/TwapOracle_Implementation.json +1111 -0
- package/deployments/bscmainnet/TwapOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
- package/deployments/bscmainnet/solcInputs/aae9f1601b873a5a4704ede73ede10cb.json +135 -0
- package/deployments/bsctestnet/BinanceOracle.json +273 -31
- package/deployments/bsctestnet/BinanceOracle_Implementation.json +398 -28
- package/deployments/bsctestnet/BinanceOracle_Proxy.json +52 -28
- package/deployments/bsctestnet/BoundValidator.json +40 -40
- package/deployments/bsctestnet/BoundValidator_Implementation.json +43 -51
- package/deployments/bsctestnet/BoundValidator_Proxy.json +35 -35
- package/deployments/bsctestnet/ChainlinkOracle.json +57 -49
- package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +46 -52
- package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +50 -36
- package/deployments/bsctestnet/DefaultProxyAdmin.json +18 -18
- package/deployments/bsctestnet/PythOracle.json +52 -45
- package/deployments/bsctestnet/PythOracle_Implementation.json +53 -47
- package/deployments/bsctestnet/PythOracle_Proxy.json +41 -40
- package/deployments/bsctestnet/ResilientOracle.json +51 -42
- package/deployments/bsctestnet/ResilientOracle_Implementation.json +65 -68
- package/deployments/bsctestnet/ResilientOracle_Proxy.json +48 -34
- package/deployments/bsctestnet/TwapOracle.json +70 -83
- package/deployments/bsctestnet/TwapOracle_Implementation.json +84 -97
- package/deployments/bsctestnet/TwapOracle_Proxy.json +46 -46
- package/deployments/bsctestnet/solcInputs/131f58942628e21632de19506977a910.json +120 -0
- package/deployments/bsctestnet/solcInputs/144b49e8aec3add79553ba273ea32d00.json +72 -0
- package/deployments/bsctestnet/solcInputs/503f2e4e766f3be923fadf8030a5470f.json +78 -0
- package/deployments/bsctestnet/solcInputs/b39d33092f7dd383ae3a042566194132.json +75 -0
- package/dist/deploy/1-deploy-oracles.d.ts +5 -0
- package/dist/deploy/1-deploy-oracles.d.ts.map +1 -0
- package/{deploy → dist/deploy}/1-deploy-oracles.js +66 -24
- package/dist/deploy/1-deploy-oracles.js.map +1 -0
- package/dist/deploy/2-configure-feeds.d.ts +15 -0
- package/dist/deploy/2-configure-feeds.d.ts.map +1 -0
- package/{deploy → dist/deploy}/2-configure-feeds.js +140 -17
- package/dist/deploy/2-configure-feeds.js.map +1 -0
- package/dist/hardhat.config.d.ts +13 -0
- package/dist/hardhat.config.d.ts.map +1 -0
- package/dist/hardhat.config.js +158 -0
- package/dist/hardhat.config.js.map +1 -0
- package/package.json +26 -19
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +0 -138
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +0 -249
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +0 -122
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -215
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -183
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +0 -297
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +0 -194
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +0 -233
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -115
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +0 -76
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +0 -24
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +0 -63
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +0 -10
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +0 -24
- package/artifacts/build-info/a47a69a8f108d3e7113faf89771988ff.json +0 -1
- package/artifacts/build-info/cc300b55b814df48229058e829c7c3c6.json +0 -1
- package/artifacts/build-info/de79b2637546f6f7d38c8f655549d9e2.json +0 -1
- package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
- package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
- package/artifacts/contracts/Governance/AccessControlled.sol/AccessControlled.dbg.json +0 -4
- package/artifacts/contracts/Governance/AccessControlled.sol/AccessControlled.json +0 -181
- package/artifacts/contracts/Governance/IAccessControlManager.sol/IAccessControlManager.dbg.json +0 -4
- package/artifacts/contracts/Governance/IAccessControlManager.sol/IAccessControlManager.json +0 -282
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +0 -4
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.json +0 -43
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +0 -4
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +0 -617
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +0 -79
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +0 -40
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +0 -30
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +0 -43
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +0 -49
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +0 -30
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +0 -545
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +0 -446
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +0 -10
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +0 -30
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +0 -246
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +0 -124
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +0 -4
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +0 -392
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +0 -468
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +0 -439
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -676
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +0 -116
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +0 -163
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +0 -144
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +0 -163
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +0 -4
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +0 -315
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +0 -4
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +0 -684
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +0 -4
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +0 -95
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +0 -4
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +0 -72
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +0 -4
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +0 -306
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +0 -10
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +0 -158
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +0 -10
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +0 -4
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +0 -333
- package/contracts/Governance/AccessControlManager.sol +0 -99
- package/contracts/Governance/AccessControlled.sol +0 -75
- package/contracts/Governance/IAccessControlManager.sol +0 -22
- package/contracts/PriceOracle.sol +0 -16
- package/deploy/1-deploy-oracles.d.ts +0 -2
- package/deploy/1-deploy-oracles.d.ts.map +0 -1
- package/deploy/1-deploy-oracles.js.map +0 -1
- package/deploy/2-configure-feeds.d.ts +0 -2
- package/deploy/2-configure-feeds.d.ts.map +0 -1
- package/deploy/2-configure-feeds.js.map +0 -1
- package/deployments/bsctestnet/AccessControlManager.json +0 -563
- package/deployments/bsctestnet/solcInputs/30f2cb3e89e183b8669f05bddf9426d9.json +0 -183
package/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright 2022 Venus Protocol.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
+
|
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Venus Oracle
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
### Prerequisites
|
|
6
|
+
|
|
7
|
+
- NodeJS - 14.x
|
|
8
|
+
|
|
9
|
+
- Solc - v0.8.13 (https://github.com/ethereum/solidity/releases/tag/v0.8.13)
|
|
10
|
+
|
|
11
|
+
### Installing
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
yarn install
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Linting and code formatting
|
|
20
|
+
|
|
21
|
+
Linting is done using eslint for typescript and solhint for solidity. Prettier is used to format solidity and typescript files.
|
|
22
|
+
|
|
23
|
+
To check linting and formatting on all files run:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
$ yarn lint
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Linting command can be run with the fix flag to fix eligible errors automatically
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
$ yarn lint:sol --fix
|
|
33
|
+
$ yarn lint:ts --fix
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
To pretty all files run:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
$ yarn prettier
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Run Tests
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
npx hardhat test
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- To run fork tests add FORK_MAINNET=true PRIVATE_KEY and QUICK_NODE_KEY in the .env file.
|
|
51
|
+
|
|
52
|
+
## Releases and Versioning
|
|
53
|
+
|
|
54
|
+
Releases are automatically managed using semantic-release and commit messages.
|
|
55
|
+
|
|
56
|
+
### Deployment
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
npx hardhat deploy
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- This command will execute all the deployment scripts in `./deploy` directory
|
|
65
|
+
- The default network will be `hardhat`
|
|
66
|
+
- Deployment to another network: - Make sure the desired network is configured in `hardhat.config.ts` - Add `PRIVATE_KEY` variable in `.env` file - Execute deploy command by adding `--network <network_name>` in the deploy command above - E.g. `npx hardhat deploy --network bsctestnet`
|
|
67
|
+
- Execution of single or custom set of scripts is possible, if:
|
|
68
|
+
- In the deployment scripts you have added `tags` for example: - `func.tags = ["MockTokens"];`
|
|
69
|
+
- Once this is done, adding `--tags "<tag_name>,<tag_name>..."` to the deployment command will execute only the scripts containing the tags.
|
|
70
|
+
|
|
71
|
+
### Verify Contracts
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
npx hardhat etherscan-verify --network <network-name>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Hardhat Commands
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
npx hardhat accounts
|
|
82
|
+
|
|
83
|
+
npx hardhat compile
|
|
84
|
+
|
|
85
|
+
npx hardhat clean
|
|
86
|
+
|
|
87
|
+
npx hardhat test
|
|
88
|
+
|
|
89
|
+
npx hardhat node
|
|
90
|
+
|
|
91
|
+
npx hardhat help
|
|
92
|
+
|
|
93
|
+
REPORT_GAS=true npx hardhat test
|
|
94
|
+
|
|
95
|
+
npx hardhat coverage
|
|
96
|
+
|
|
97
|
+
TS_NODE_FILES=true npx ts-node scripts/deploy.ts
|
|
98
|
+
|
|
99
|
+
npx eslint '**/*.{js,ts}'
|
|
100
|
+
|
|
101
|
+
npx eslint '**/*.{js,ts}' --fix
|
|
102
|
+
|
|
103
|
+
npx prettier '**/*.{json,sol,md}' --check
|
|
104
|
+
|
|
105
|
+
npx prettier '**/*.{json,sol,md}' --write
|
|
106
|
+
|
|
107
|
+
npx solhint 'contracts/**/*.sol'
|
|
108
|
+
|
|
109
|
+
npx solhint 'contracts/**/*.sol' --fix
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Documentation
|
|
114
|
+
|
|
115
|
+
Documentation is autogenerated using [solidity-docgen](https://github.com/OpenZeppelin/solidity-docgen).
|
|
116
|
+
|
|
117
|
+
They can be generated by running `yarn docgen`
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2022 Venus
|
|
3
3
|
pragma solidity 0.8.13;
|
|
4
4
|
|
|
5
|
-
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
|
|
6
5
|
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
|
|
7
6
|
import "./interfaces/VBep20Interface.sol";
|
|
8
7
|
import "./interfaces/OracleInterface.sol";
|
|
9
|
-
import "
|
|
8
|
+
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
10
9
|
|
|
11
|
-
contract ResilientOracle is PausableUpgradeable,
|
|
10
|
+
contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOracleInterface {
|
|
12
11
|
/**
|
|
13
12
|
* @dev Oracle roles:
|
|
14
13
|
* **main**: The most trustworthy price source
|
|
@@ -46,7 +45,9 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
46
45
|
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
47
46
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
/// @notice Bound validator contract address
|
|
49
|
+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
50
|
+
BoundValidatorInterface public immutable boundValidator;
|
|
50
51
|
|
|
51
52
|
mapping(address => TokenConfig) private tokenConfigs;
|
|
52
53
|
|
|
@@ -67,7 +68,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
67
68
|
* @notice Checks whether an address is null or not
|
|
68
69
|
*/
|
|
69
70
|
modifier notNullAddress(address someone) {
|
|
70
|
-
|
|
71
|
+
if (someone == address(0)) revert("can't be zero address");
|
|
71
72
|
_;
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -76,21 +77,37 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
76
77
|
* @dev vToken can't be null, so it's suitable to be used to check the validity of the config
|
|
77
78
|
* @param asset asset address
|
|
78
79
|
*/
|
|
79
|
-
modifier
|
|
80
|
-
|
|
80
|
+
modifier checkTokenConfigExistence(address asset) {
|
|
81
|
+
if (tokenConfigs[asset].asset == address(0)) revert("token config must exist");
|
|
81
82
|
_;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
85
86
|
/// @param vBnbAddress The address of the vBNB
|
|
86
87
|
/// @param vaiAddress The address of the VAI
|
|
88
|
+
/// @param _boundValidator Address of the bound validator contract
|
|
87
89
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
88
|
-
constructor(
|
|
90
|
+
constructor(
|
|
91
|
+
address vBnbAddress,
|
|
92
|
+
address vaiAddress,
|
|
93
|
+
BoundValidatorInterface _boundValidator
|
|
94
|
+
) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) notNullAddress(address(_boundValidator)) {
|
|
89
95
|
vBnb = vBnbAddress;
|
|
90
96
|
vai = vaiAddress;
|
|
97
|
+
boundValidator = _boundValidator;
|
|
98
|
+
|
|
91
99
|
_disableInitializers();
|
|
92
100
|
}
|
|
93
101
|
|
|
102
|
+
/**
|
|
103
|
+
* @notice Initializes the contract admin and sets the BoundValidator contract address
|
|
104
|
+
* @param accessControlManager_ Address of the access control manager contract
|
|
105
|
+
*/
|
|
106
|
+
function initialize(address accessControlManager_) external initializer {
|
|
107
|
+
__AccessControlled_init(accessControlManager_);
|
|
108
|
+
__Pausable_init();
|
|
109
|
+
}
|
|
110
|
+
|
|
94
111
|
/**
|
|
95
112
|
* @notice Pauses oracle
|
|
96
113
|
* @custom:access Only Governance
|
|
@@ -113,14 +130,16 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
113
130
|
* @notice Batch sets token configs
|
|
114
131
|
* @param tokenConfigs_ Token config array
|
|
115
132
|
* @custom:access Only Governance
|
|
116
|
-
* @custom:error Throws a length error if the
|
|
133
|
+
* @custom:error Throws a length error if the length of the token configs array is 0
|
|
117
134
|
*/
|
|
118
135
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
|
|
119
|
-
|
|
120
|
-
require(tokenConfigs_.length != 0, "length can't be 0");
|
|
136
|
+
if (tokenConfigs_.length == 0) revert("length can't be 0");
|
|
121
137
|
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
122
|
-
for (uint256 i; i < numTokenConfigs;
|
|
138
|
+
for (uint256 i; i < numTokenConfigs; ) {
|
|
123
139
|
setTokenConfig(tokenConfigs_[i]);
|
|
140
|
+
unchecked {
|
|
141
|
+
++i;
|
|
142
|
+
}
|
|
124
143
|
}
|
|
125
144
|
}
|
|
126
145
|
|
|
@@ -140,9 +159,9 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
140
159
|
address asset,
|
|
141
160
|
address oracle,
|
|
142
161
|
OracleRole role
|
|
143
|
-
) external notNullAddress(asset)
|
|
144
|
-
_checkAccessAllowed("setOracle(address,address,
|
|
145
|
-
|
|
162
|
+
) external notNullAddress(asset) checkTokenConfigExistence(asset) {
|
|
163
|
+
_checkAccessAllowed("setOracle(address,address,uint8)");
|
|
164
|
+
if (oracle == address(0) && role == OracleRole.MAIN) revert("can't set zero address to main oracle");
|
|
146
165
|
tokenConfigs[asset].oracles[uint256(role)] = oracle;
|
|
147
166
|
emit OracleSet(asset, oracle, uint256(role));
|
|
148
167
|
}
|
|
@@ -160,21 +179,21 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
160
179
|
address asset,
|
|
161
180
|
OracleRole role,
|
|
162
181
|
bool enable
|
|
163
|
-
) external notNullAddress(asset)
|
|
164
|
-
_checkAccessAllowed("enableOracle(address,
|
|
182
|
+
) external notNullAddress(asset) checkTokenConfigExistence(asset) {
|
|
183
|
+
_checkAccessAllowed("enableOracle(address,uint8,bool)");
|
|
165
184
|
tokenConfigs[asset].enableFlagsForOracles[uint256(role)] = enable;
|
|
166
185
|
emit OracleEnabled(asset, uint256(role), enable);
|
|
167
186
|
}
|
|
168
187
|
|
|
169
188
|
/**
|
|
170
|
-
* @notice Updates the pivot oracle price.
|
|
189
|
+
* @notice Updates the TWAP pivot oracle price.
|
|
171
190
|
* @dev This function should always be called before calling getUnderlyingPrice
|
|
172
191
|
* @param vToken vToken address
|
|
173
192
|
*/
|
|
174
193
|
function updatePrice(address vToken) external override {
|
|
175
194
|
(address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
|
|
176
195
|
if (pivotOracle != address(0) && pivotOracleEnabled) {
|
|
177
|
-
//if
|
|
196
|
+
//if pivot oracle is not TwapOracle it will revert so we need to catch the revert
|
|
178
197
|
try TwapInterface(pivotOracle).updateTwap(vToken) {} catch {}
|
|
179
198
|
}
|
|
180
199
|
}
|
|
@@ -193,7 +212,8 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
193
212
|
* @notice Gets price of the underlying asset for a given vToken. Validation flow:
|
|
194
213
|
* - Check if the oracle is paused globally
|
|
195
214
|
* - Validate price from main oracle against pivot oracle
|
|
196
|
-
* - Validate price from fallback oracle against pivot oracle
|
|
215
|
+
* - Validate price from fallback oracle against pivot oracle if the first validation failed
|
|
216
|
+
* - Validate price from main oracle against fallback oracle if the second validation failed
|
|
197
217
|
* In the case that the pivot oracle is not available but main price is available and validation is successful,
|
|
198
218
|
* main oracle price is returned.
|
|
199
219
|
* @param vToken vToken address
|
|
@@ -202,7 +222,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
202
222
|
* @custom:error Invalid resilient oracle price error is thrown if fetched prices from oracle is invalid
|
|
203
223
|
*/
|
|
204
224
|
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
205
|
-
|
|
225
|
+
if (paused()) revert("resilient oracle is paused");
|
|
206
226
|
uint256 pivotPrice = INVALID_PRICE;
|
|
207
227
|
|
|
208
228
|
// Get pivot oracle price, Invalid price if not available or error
|
|
@@ -232,7 +252,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
232
252
|
if (
|
|
233
253
|
mainPrice != INVALID_PRICE &&
|
|
234
254
|
fallbackPrice != INVALID_PRICE &&
|
|
235
|
-
boundValidator.validatePriceWithAnchorPrice(vToken,
|
|
255
|
+
boundValidator.validatePriceWithAnchorPrice(vToken, mainPrice, fallbackPrice)
|
|
236
256
|
) {
|
|
237
257
|
return mainPrice;
|
|
238
258
|
}
|
|
@@ -240,18 +260,6 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
240
260
|
revert("invalid resilient oracle price");
|
|
241
261
|
}
|
|
242
262
|
|
|
243
|
-
/**
|
|
244
|
-
* @notice Initializes the contract admin and sets the BoundValidator contract address
|
|
245
|
-
* @param _boundValidator Address of the bound validator contract
|
|
246
|
-
* @param accessControlManager_ Address of the access control manager contract
|
|
247
|
-
*/
|
|
248
|
-
function initialize(BoundValidatorInterface _boundValidator, address accessControlManager_) public initializer {
|
|
249
|
-
require(address(_boundValidator) != address(0), "invalid bound validator address");
|
|
250
|
-
boundValidator = _boundValidator;
|
|
251
|
-
|
|
252
|
-
__AccessControlled_init_unchained(accessControlManager_);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
263
|
/**
|
|
256
264
|
* @notice Sets/resets single token configs.
|
|
257
265
|
* @dev main oracle **must not** be a null address
|
|
@@ -308,7 +316,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
308
316
|
address vToken,
|
|
309
317
|
uint256 pivotPrice,
|
|
310
318
|
bool pivotEnabled
|
|
311
|
-
)
|
|
319
|
+
) private view returns (uint256, bool) {
|
|
312
320
|
(address mainOracle, bool mainOracleEnabled) = getOracle(vToken, OracleRole.MAIN);
|
|
313
321
|
if (mainOracleEnabled && mainOracle != address(0)) {
|
|
314
322
|
try OracleInterface(mainOracle).getUnderlyingPrice(vToken) returns (uint256 mainOraclePrice) {
|
|
@@ -340,7 +348,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
340
348
|
* @custom:error Invalid price error is thrown if fallback oracle is not enabled or fallback oracle
|
|
341
349
|
* address is null
|
|
342
350
|
*/
|
|
343
|
-
function _getFallbackOraclePrice(address vToken, uint256 pivotPrice)
|
|
351
|
+
function _getFallbackOraclePrice(address vToken, uint256 pivotPrice) private view returns (uint256, bool) {
|
|
344
352
|
(address fallbackOracle, bool fallbackEnabled) = getOracle(vToken, OracleRole.FALLBACK);
|
|
345
353
|
if (fallbackEnabled && fallbackOracle != address(0)) {
|
|
346
354
|
try OracleInterface(fallbackOracle).getUnderlyingPrice(vToken) returns (uint256 fallbackOraclePrice) {
|
|
@@ -364,7 +372,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
|
|
|
364
372
|
* @param vToken vToken address
|
|
365
373
|
* @return asset underlying asset address
|
|
366
374
|
*/
|
|
367
|
-
function _getUnderlyingAsset(address vToken)
|
|
375
|
+
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
|
|
368
376
|
if (address(vToken) == vBnb) {
|
|
369
377
|
asset = BNB_ADDR;
|
|
370
378
|
} else if (address(vToken) == vai) {
|
|
@@ -235,11 +235,14 @@ abstract contract AbstractPyth is IPyth {
|
|
|
235
235
|
require(priceIds.length == publishTimes.length, "priceIds and publishTimes arrays should have same length");
|
|
236
236
|
|
|
237
237
|
bool updateNeeded = false;
|
|
238
|
-
for (uint256 i = 0; i < priceIds.length;
|
|
238
|
+
for (uint256 i = 0; i < priceIds.length; ) {
|
|
239
239
|
if (!priceFeedExists(priceIds[i]) || queryPriceFeed(priceIds[i]).price.publishTime < publishTimes[i]) {
|
|
240
240
|
updateNeeded = true;
|
|
241
241
|
break;
|
|
242
242
|
}
|
|
243
|
+
unchecked {
|
|
244
|
+
i++;
|
|
245
|
+
}
|
|
243
246
|
}
|
|
244
247
|
|
|
245
248
|
require(updateNeeded, "no prices in the submitted batch have fresh prices, so this update will have no effect");
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
2
|
pragma solidity 0.8.13;
|
|
3
3
|
|
|
4
|
-
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
5
4
|
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
6
5
|
import "../interfaces/VBep20Interface.sol";
|
|
7
6
|
import "../interfaces/SIDRegistryInterface.sol";
|
|
8
7
|
import "../interfaces/FeedRegistryInterface.sol";
|
|
9
8
|
import "../interfaces/PublicResolverInterface.sol";
|
|
9
|
+
import "../interfaces/OracleInterface.sol";
|
|
10
|
+
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
10
11
|
|
|
11
|
-
contract BinanceOracle is
|
|
12
|
+
contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
12
13
|
address public sidRegistryAddress;
|
|
13
14
|
|
|
14
15
|
/// @notice vBNB address
|
|
@@ -19,38 +20,45 @@ contract BinanceOracle is Initializable {
|
|
|
19
20
|
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
20
21
|
address public immutable vai;
|
|
21
22
|
|
|
23
|
+
/// @notice Max stale period configuration for assets
|
|
24
|
+
mapping(string => uint256) public maxStalePeriod;
|
|
25
|
+
|
|
26
|
+
event MaxStalePeriodAdded(string indexed asset, uint256 maxStalePeriod);
|
|
27
|
+
|
|
22
28
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
23
29
|
/// @param vBnbAddress The address of the vBNB
|
|
24
30
|
/// @param vaiAddress The address of the VAI
|
|
25
31
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
26
32
|
constructor(address vBnbAddress, address vaiAddress) {
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
if (vBnbAddress == address(0)) revert("vBNB can't be zero address");
|
|
34
|
+
if (vaiAddress == address(0)) revert("VAI can't be zero address");
|
|
29
35
|
vBnb = vBnbAddress;
|
|
30
36
|
vai = vaiAddress;
|
|
31
37
|
_disableInitializers();
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
/**
|
|
35
|
-
* @notice
|
|
36
|
-
* @param
|
|
41
|
+
* @notice Used to set the max stale period of an asset
|
|
42
|
+
* @param symbol The symbol of the asset
|
|
43
|
+
* @param _maxStalePeriod The max stake period
|
|
37
44
|
*/
|
|
38
|
-
function
|
|
39
|
-
|
|
45
|
+
function setMaxStalePeriod(string memory symbol, uint256 _maxStalePeriod) external {
|
|
46
|
+
_checkAccessAllowed("setMaxStalePeriod(string,uint256)");
|
|
47
|
+
if (_maxStalePeriod == 0) revert("stale period can't be zero");
|
|
48
|
+
if (bytes(symbol).length == 0) revert("symbol cannot be empty");
|
|
49
|
+
|
|
50
|
+
maxStalePeriod[symbol] = _maxStalePeriod;
|
|
51
|
+
emit MaxStalePeriodAdded(symbol, _maxStalePeriod);
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
/**
|
|
43
|
-
* @notice
|
|
44
|
-
* @
|
|
55
|
+
* @notice Sets the contracts required to fetch prices
|
|
56
|
+
* @param _sidRegistryAddress Address of SID registry
|
|
57
|
+
* @param _accessControlManager Address of the access control manager contract
|
|
45
58
|
*/
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
|
|
50
|
-
address publicResolverAddress = sidRegistry.resolver(nodeHash);
|
|
51
|
-
PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
|
|
52
|
-
|
|
53
|
-
return publicResolver.addr(nodeHash);
|
|
59
|
+
function initialize(address _sidRegistryAddress, address _accessControlManager) external initializer {
|
|
60
|
+
sidRegistryAddress = _sidRegistryAddress;
|
|
61
|
+
__AccessControlled_init(_accessControlManager);
|
|
54
62
|
}
|
|
55
63
|
|
|
56
64
|
/**
|
|
@@ -58,32 +66,65 @@ contract BinanceOracle is Initializable {
|
|
|
58
66
|
* @param vToken Address of the vToken
|
|
59
67
|
* @return Price in USD
|
|
60
68
|
*/
|
|
61
|
-
function getUnderlyingPrice(
|
|
69
|
+
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
62
70
|
string memory symbol;
|
|
63
71
|
uint256 decimals;
|
|
64
72
|
|
|
65
73
|
// VBNB token doesn't have `underlying` method
|
|
66
|
-
if (
|
|
74
|
+
if (vToken == vBnb) {
|
|
67
75
|
symbol = "BNB";
|
|
68
76
|
decimals = 18;
|
|
69
|
-
} else if (
|
|
77
|
+
} else if (vToken == vai) {
|
|
70
78
|
symbol = "VAI";
|
|
71
79
|
decimals = 18;
|
|
72
80
|
} else {
|
|
73
|
-
IERC20Metadata underlyingToken = IERC20Metadata(vToken.underlying());
|
|
81
|
+
IERC20Metadata underlyingToken = IERC20Metadata(VBep20Interface(vToken).underlying());
|
|
74
82
|
symbol = underlyingToken.symbol();
|
|
75
83
|
decimals = underlyingToken.decimals();
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
if (
|
|
86
|
+
if (compare(symbol, "WBNB")) {
|
|
79
87
|
symbol = "BNB";
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
FeedRegistryInterface feedRegistry = FeedRegistryInterface(getFeedRegistryAddress());
|
|
83
91
|
|
|
84
|
-
(, int256 answer, , , ) = feedRegistry.latestRoundDataByName(symbol, "USD");
|
|
92
|
+
(, int256 answer, , uint256 updatedAt, ) = feedRegistry.latestRoundDataByName(symbol, "USD");
|
|
93
|
+
if (answer <= 0) revert("invalid binance oracle price");
|
|
94
|
+
if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
|
|
95
|
+
|
|
96
|
+
uint256 deltaTime;
|
|
97
|
+
unchecked {
|
|
98
|
+
deltaTime = block.timestamp - updatedAt;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (deltaTime > maxStalePeriod[symbol]) revert("binance oracle price expired");
|
|
85
102
|
|
|
86
103
|
uint256 decimalDelta = feedRegistry.decimalsByName(symbol, "USD");
|
|
87
104
|
return (uint256(answer) * (10 ** (18 - decimalDelta))) * (10 ** (18 - decimals));
|
|
88
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @notice Uses Space ID to fetch the feed registry address
|
|
109
|
+
* @return feedRegistryAddress Address of binance oracle feed registry.
|
|
110
|
+
*/
|
|
111
|
+
function getFeedRegistryAddress() public view returns (address) {
|
|
112
|
+
bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
|
|
113
|
+
|
|
114
|
+
SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
|
|
115
|
+
address publicResolverAddress = sidRegistry.resolver(nodeHash);
|
|
116
|
+
PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
|
|
117
|
+
|
|
118
|
+
return publicResolver.addr(nodeHash);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @notice Used to compare if two strings are equal or not
|
|
123
|
+
* @param str1 The first string
|
|
124
|
+
* @param str2 The second string
|
|
125
|
+
* @return equal Returns true if both are equal or else false.
|
|
126
|
+
*/
|
|
127
|
+
function compare(string memory str1, string memory str2) private pure returns (bool) {
|
|
128
|
+
return keccak256(bytes(str1)) == keccak256(bytes(str2));
|
|
129
|
+
}
|
|
89
130
|
}
|