@venusprotocol/oracle 1.6.11-dev.8 → 1.6.11

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.
Files changed (172) hide show
  1. package/README.md +33 -10
  2. package/contracts/ResilientOracle.sol +60 -18
  3. package/contracts/oracles/BinanceOracle.sol +22 -17
  4. package/contracts/oracles/BoundValidator.sol +43 -38
  5. package/contracts/oracles/ChainlinkOracle.sol +35 -34
  6. package/contracts/oracles/PythOracle.sol +30 -27
  7. package/contracts/oracles/TwapOracle.sol +61 -56
  8. package/deployments/bscmainnet/BinanceOracle.json +45 -45
  9. package/deployments/bscmainnet/BinanceOracle_Implementation.json +34 -34
  10. package/deployments/bscmainnet/BinanceOracle_Proxy.json +43 -43
  11. package/deployments/bscmainnet/BoundValidator.json +46 -46
  12. package/deployments/bscmainnet/BoundValidator_Implementation.json +44 -52
  13. package/deployments/bscmainnet/BoundValidator_Proxy.json +43 -43
  14. package/deployments/bscmainnet/ChainlinkOracle.json +46 -52
  15. package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +45 -51
  16. package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +43 -43
  17. package/deployments/bscmainnet/DefaultProxyAdmin.json +15 -15
  18. package/deployments/bscmainnet/PythOracle.json +61 -54
  19. package/deployments/bscmainnet/PythOracle_Implementation.json +54 -48
  20. package/deployments/bscmainnet/PythOracle_Proxy.json +52 -51
  21. package/deployments/bscmainnet/ResilientOracle.json +47 -52
  22. package/deployments/bscmainnet/ResilientOracle_Implementation.json +62 -65
  23. package/deployments/bscmainnet/ResilientOracle_Proxy.json +45 -45
  24. package/deployments/bscmainnet/TwapOracle.json +67 -67
  25. package/deployments/bscmainnet/TwapOracle_Implementation.json +83 -83
  26. package/deployments/bscmainnet/TwapOracle_Proxy.json +44 -44
  27. package/deployments/bscmainnet/solcInputs/{3c9df0f4b407c3d8079629dd6ddb913e.json → aae9f1601b873a5a4704ede73ede10cb.json} +9 -54
  28. package/deployments/bsctestnet/BinanceOracle.json +35 -35
  29. package/deployments/bsctestnet/BinanceOracle_Implementation.json +31 -31
  30. package/deployments/bsctestnet/BinanceOracle_Proxy.json +33 -33
  31. package/deployments/bsctestnet/BoundValidator.json +36 -36
  32. package/deployments/bsctestnet/BoundValidator_Implementation.json +44 -52
  33. package/deployments/bsctestnet/BoundValidator_Proxy.json +33 -33
  34. package/deployments/bsctestnet/ChainlinkOracle.json +36 -42
  35. package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +42 -48
  36. package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +33 -33
  37. package/deployments/bsctestnet/DefaultProxyAdmin.json +11 -11
  38. package/deployments/bsctestnet/PythOracle.json +48 -41
  39. package/deployments/bsctestnet/PythOracle_Implementation.json +51 -45
  40. package/deployments/bsctestnet/PythOracle_Proxy.json +39 -38
  41. package/deployments/bsctestnet/ResilientOracle.json +36 -41
  42. package/deployments/bsctestnet/ResilientOracle_Implementation.json +63 -66
  43. package/deployments/bsctestnet/ResilientOracle_Proxy.json +34 -34
  44. package/deployments/bsctestnet/TwapOracle.json +56 -56
  45. package/deployments/bsctestnet/TwapOracle_Implementation.json +81 -81
  46. package/deployments/bsctestnet/TwapOracle_Proxy.json +33 -33
  47. package/deployments/bsctestnet/solcInputs/{f35da22a430a956ee338e720b5898e3d.json → 131f58942628e21632de19506977a910.json} +7 -13
  48. package/deployments/bsctestnet/solcInputs/{4769dd98af512bf3b6b6504ad0c3bd74.json → 144b49e8aec3add79553ba273ea32d00.json} +4 -10
  49. package/deployments/bsctestnet/solcInputs/503f2e4e766f3be923fadf8030a5470f.json +78 -0
  50. package/deployments/bsctestnet/solcInputs/b39d33092f7dd383ae3a042566194132.json +75 -0
  51. package/dist/deploy/1-deploy-oracles.js +2 -2
  52. package/dist/deploy/1-deploy-oracles.js.map +1 -1
  53. package/package.json +1 -1
  54. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +0 -4
  55. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +0 -138
  56. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
  57. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +0 -249
  58. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +0 -4
  59. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +0 -122
  60. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
  61. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -215
  62. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
  63. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -183
  64. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +0 -4
  65. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +0 -297
  66. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +0 -4
  67. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +0 -194
  68. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +0 -4
  69. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +0 -233
  70. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
  71. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
  72. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
  73. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -10
  74. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
  75. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
  76. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
  77. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
  78. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
  79. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
  80. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
  81. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -10
  82. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
  83. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
  84. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +0 -4
  85. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -115
  86. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +0 -4
  87. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +0 -76
  88. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +0 -4
  89. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +0 -24
  90. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +0 -4
  91. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +0 -63
  92. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +0 -4
  93. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +0 -10
  94. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +0 -4
  95. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +0 -24
  96. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
  97. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
  98. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +0 -4
  99. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +0 -181
  100. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +0 -4
  101. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +0 -282
  102. package/artifacts/build-info/0fa2b75b56480052b72f8190a534e534.json +0 -1
  103. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +0 -4
  104. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +0 -617
  105. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +0 -4
  106. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +0 -79
  107. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +0 -4
  108. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +0 -40
  109. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +0 -4
  110. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +0 -30
  111. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +0 -4
  112. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +0 -43
  113. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +0 -4
  114. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +0 -49
  115. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +0 -4
  116. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +0 -30
  117. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +0 -4
  118. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +0 -545
  119. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +0 -4
  120. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +0 -446
  121. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +0 -4
  122. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +0 -10
  123. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +0 -4
  124. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +0 -30
  125. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +0 -4
  126. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +0 -246
  127. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
  128. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
  129. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
  130. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
  131. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
  132. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
  133. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +0 -4
  134. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +0 -342
  135. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +0 -4
  136. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +0 -392
  137. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +0 -4
  138. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +0 -468
  139. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +0 -4
  140. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +0 -439
  141. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
  142. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -663
  143. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +0 -4
  144. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +0 -116
  145. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +0 -4
  146. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +0 -144
  147. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +0 -4
  148. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +0 -144
  149. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +0 -4
  150. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +0 -163
  151. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
  152. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
  153. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +0 -4
  154. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +0 -364
  155. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +0 -4
  156. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +0 -328
  157. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +0 -4
  158. package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +0 -684
  159. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +0 -4
  160. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +0 -95
  161. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +0 -4
  162. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +0 -72
  163. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +0 -4
  164. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +0 -306
  165. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +0 -4
  166. package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +0 -10
  167. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +0 -4
  168. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +0 -158
  169. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +0 -4
  170. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +0 -10
  171. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +0 -4
  172. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +0 -346
package/README.md CHANGED
@@ -1,14 +1,37 @@
1
- # Venus Oracle
1
+ # Resilient Price Feeds
2
2
 
3
- ## Usage
3
+ Resilient Price Feeds is a set of smart contracts that uses multiple oracles and a price validation algorithm to fetch asset prices for the [Venus Protocol](https://app.venus.io).
4
4
 
5
- ### Prerequisites
5
+ DeFi protocols are vulnerable to incorrectly reported prices which can lead to lost money. A price oracle can be manipulated,fail, or suffer other attacks depending on the type of price oracle. It creates a single point of failure, opening attack vectors to the protocol if not mitigated.
6
+
7
+ The Resilient Price Feeds uses multiple oracle sources and fallback mechanisms to return accurate prices and protect from oracle failures. Currently, it includes integrations with Chainlink, Pyth, Binance Oracle and TWAP (Time-Weighted Average Price) oracles. TWAP uses PancakeSwap as the on-chain price source.
8
+
9
+ ## Details
10
+
11
+ The Resilient Price Feeds configures a main, pivot and fallback oracle for every asset. The main oracle is the most trustworthy price source, the pivot oracle is used as a loose sanity checker and the fallback oracle is used as a backup price source.
12
+
13
+ ![Resilient Price Feeds](./marketing-assets/oracles.png)
14
+
15
+ Oracle prices are validated using an **upper** and **lower** bound ratio, which is set for every market. The **upper bound ratio** represents the **deviation** between the **reported price** (price from oracle that’s being validated) and anchor price (price from oracle we are validating against) beyond which the reported price will be invalidated. The **lower bound ratio** presents the **deviation** between **reported price and anchor price** below which the reported price will be invalidated. For an oracle price to be considered valid the below statement should be true:
16
+
17
+ ```
18
+ anchorRatio = anchorPrice/reporterPrice
19
+ isValid = anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio
20
+ ```
21
+
22
+ The default configuration uses Chainlink as the main oracle, TWAP or Pyth oracle as pivot oracle depending on which supports the given market and Binance oracle as the fallback oracle. For some markets we may use Pyth as the main oracle if the token price is not supported by Chainlink or Binance oracles.
23
+
24
+ When fetching an oracle price, for the price to be valid it must be positive and not stagnant. If the price is invalid or stagnant it is ignored and a fallback oracle is used.
25
+
26
+ # Development
27
+
28
+ ## Prerequisites
6
29
 
7
30
  - NodeJS - 14.x
8
31
 
9
32
  - Solc - v0.8.13 (https://github.com/ethereum/solidity/releases/tag/v0.8.13)
10
33
 
11
- ### Installing
34
+ ## Installing
12
35
 
13
36
  ```
14
37
 
@@ -16,7 +39,7 @@ yarn install
16
39
 
17
40
  ```
18
41
 
19
- ### Linting and code formatting
42
+ ## Linting and code formatting
20
43
 
21
44
  Linting is done using eslint for typescript and solhint for solidity. Prettier is used to format solidity and typescript files.
22
45
 
@@ -39,7 +62,7 @@ To pretty all files run:
39
62
  $ yarn prettier
40
63
  ```
41
64
 
42
- ### Run Tests
65
+ ## Run Tests
43
66
 
44
67
  ```
45
68
 
@@ -53,7 +76,7 @@ npx hardhat test
53
76
 
54
77
  Releases are automatically managed using semantic-release and commit messages.
55
78
 
56
- ### Deployment
79
+ ## Deployment
57
80
 
58
81
  ```
59
82
 
@@ -68,13 +91,13 @@ npx hardhat deploy
68
91
  - In the deployment scripts you have added `tags` for example: - `func.tags = ["MockTokens"];`
69
92
  - Once this is done, adding `--tags "<tag_name>,<tag_name>..."` to the deployment command will execute only the scripts containing the tags.
70
93
 
71
- ### Verify Contracts
94
+ ## Verify Contracts
72
95
 
73
96
  ```
74
97
  npx hardhat etherscan-verify --network <network-name>
75
98
  ```
76
99
 
77
- ### Hardhat Commands
100
+ ## Hardhat Commands
78
101
 
79
102
  ```
80
103
 
@@ -110,7 +133,7 @@ npx solhint 'contracts/**/*.sol' --fix
110
133
 
111
134
  ```
112
135
 
113
- ### Documentation
136
+ ## Documentation
114
137
 
115
138
  Documentation is autogenerated using [solidity-docgen](https://github.com/OpenZeppelin/solidity-docgen).
116
139
 
@@ -7,6 +7,43 @@ import "./interfaces/VBep20Interface.sol";
7
7
  import "./interfaces/OracleInterface.sol";
8
8
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
9
9
 
10
+ /**
11
+ * @title ResilientOracle
12
+ * @author Venus
13
+ * @notice Resillient oracle is the price oracle that the protocol interacts with for fetching price of assets.
14
+ *
15
+ * DeFi Protocols are usually vulnerable to price oracles reporting incorrect prices. There are various ways in which
16
+ * oracle prices can be manipulated depending on the type of price oracle used which can create a single point of
17
+ * failure and opens several ways for attacking the protocol.
18
+ *
19
+ * Keeping this in mind, we have designed a resilient oracle which uses multiple oracle sources to validate prices
20
+ * and fallback mechanisms to provide accurate prices and protect from oracle attacks. Currently it includes
21
+ * integrations with Chainlink, Pyth, Binance Oracle and TWAP (Time-Weighted Average Price) oracles. TWAP uses
22
+ * PancakeSwap as the on-chain price source.
23
+ *
24
+ * The way the Resilient Oracle works is for every market (vToken) we configure the main, pivot and fallback oracles.
25
+ * The main oracle oracle is the most trustworthy price source, the pivot oracle is is used as a loose sanity
26
+ * checker and the fallback oracle is used as a backup price source.
27
+ *
28
+ * To validate the price between two oracles we set an **upper** and **lower** bound ratio for every market. The
29
+ * **upper bound ratio** represents the **deviation** between **reported prices** (price from oracle that’s being
30
+ * validated) and anchor price (price from oracle we are validating against) beyond which the reported price will
31
+ * be invalidated. And the **lower bound ratio** presents the **deviation** between **reported price and anchor price**
32
+ * below which the reported price will be invalidated. So for oracle price to be considered valid the below statement
33
+ * should be true:
34
+
35
+ ```
36
+ anchorRatio = anchorPrice/reporterPrice
37
+ isValid = anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio
38
+ ```
39
+
40
+ * We usually use Chainlink as the main oracle, TWAP or Pyth oracle as pivot oracle depending on which supports the
41
+ * given market and Binance oracle is used as the fallback oracle. For some markets we may use Pyth or TWAP as the
42
+ * main oracle if the token price is not supported by Chainlink or Binance oracle.
43
+ *
44
+ * When fetching an oracle price, for the price to be valid it must be positive and not stagnant. If the price is
45
+ * invalid then we consider the oracle to be stagnant and treat it like it's disabled.
46
+ */
10
47
  contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOracleInterface {
11
48
  /**
12
49
  * @dev Oracle roles:
@@ -45,7 +82,9 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
45
82
  /// @notice Set this as asset address for BNB. This is the underlying for vBNB
46
83
  address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
47
84
 
48
- BoundValidatorInterface public boundValidator;
85
+ /// @notice Bound validator contract address
86
+ /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
87
+ BoundValidatorInterface public immutable boundValidator;
49
88
 
50
89
  mapping(address => TokenConfig) private tokenConfigs;
51
90
 
@@ -83,13 +122,29 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
83
122
  /// @notice Constructor for the implementation contract. Sets immutable variables.
84
123
  /// @param vBnbAddress The address of the vBNB
85
124
  /// @param vaiAddress The address of the VAI
125
+ /// @param _boundValidator Address of the bound validator contract
86
126
  /// @custom:oz-upgrades-unsafe-allow constructor
87
- constructor(address vBnbAddress, address vaiAddress) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) {
127
+ constructor(
128
+ address vBnbAddress,
129
+ address vaiAddress,
130
+ BoundValidatorInterface _boundValidator
131
+ ) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) notNullAddress(address(_boundValidator)) {
88
132
  vBnb = vBnbAddress;
89
133
  vai = vaiAddress;
134
+ boundValidator = _boundValidator;
135
+
90
136
  _disableInitializers();
91
137
  }
92
138
 
139
+ /**
140
+ * @notice Initializes the contract admin and sets the BoundValidator contract address
141
+ * @param accessControlManager_ Address of the access control manager contract
142
+ */
143
+ function initialize(address accessControlManager_) external initializer {
144
+ __AccessControlled_init(accessControlManager_);
145
+ __Pausable_init();
146
+ }
147
+
93
148
  /**
94
149
  * @notice Pauses oracle
95
150
  * @custom:access Only Governance
@@ -242,19 +297,6 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
242
297
  revert("invalid resilient oracle price");
243
298
  }
244
299
 
245
- /**
246
- * @notice Initializes the contract admin and sets the BoundValidator contract address
247
- * @param _boundValidator Address of the bound validator contract
248
- * @param accessControlManager_ Address of the access control manager contract
249
- */
250
- function initialize(BoundValidatorInterface _boundValidator, address accessControlManager_) public initializer {
251
- if (address(_boundValidator) == address(0)) revert("invalid bound validator address");
252
- boundValidator = _boundValidator;
253
-
254
- __AccessControlled_init(accessControlManager_);
255
- __Pausable_init();
256
- }
257
-
258
300
  /**
259
301
  * @notice Sets/resets single token configs.
260
302
  * @dev main oracle **must not** be a null address
@@ -311,7 +353,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
311
353
  address vToken,
312
354
  uint256 pivotPrice,
313
355
  bool pivotEnabled
314
- ) internal view returns (uint256, bool) {
356
+ ) private view returns (uint256, bool) {
315
357
  (address mainOracle, bool mainOracleEnabled) = getOracle(vToken, OracleRole.MAIN);
316
358
  if (mainOracleEnabled && mainOracle != address(0)) {
317
359
  try OracleInterface(mainOracle).getUnderlyingPrice(vToken) returns (uint256 mainOraclePrice) {
@@ -343,7 +385,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
343
385
  * @custom:error Invalid price error is thrown if fallback oracle is not enabled or fallback oracle
344
386
  * address is null
345
387
  */
346
- function _getFallbackOraclePrice(address vToken, uint256 pivotPrice) internal view returns (uint256, bool) {
388
+ function _getFallbackOraclePrice(address vToken, uint256 pivotPrice) private view returns (uint256, bool) {
347
389
  (address fallbackOracle, bool fallbackEnabled) = getOracle(vToken, OracleRole.FALLBACK);
348
390
  if (fallbackEnabled && fallbackOracle != address(0)) {
349
391
  try OracleInterface(fallbackOracle).getUnderlyingPrice(vToken) returns (uint256 fallbackOraclePrice) {
@@ -367,7 +409,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
367
409
  * @param vToken vToken address
368
410
  * @return asset underlying asset address
369
411
  */
370
- function _getUnderlyingAsset(address vToken) internal view returns (address asset) {
412
+ function _getUnderlyingAsset(address vToken) private view returns (address asset) {
371
413
  if (address(vToken) == vBnb) {
372
414
  asset = BNB_ADDR;
373
415
  } else if (address(vToken) == vai) {
@@ -9,6 +9,11 @@ import "../interfaces/PublicResolverInterface.sol";
9
9
  import "../interfaces/OracleInterface.sol";
10
10
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
11
11
 
12
+ /**
13
+ * @title BinanceOracle
14
+ * @author Venus
15
+ * @notice This oracle fetches price of assets from Binance.
16
+ */
12
17
  contract BinanceOracle is AccessControlledV8, OracleInterface {
13
18
  address public sidRegistryAddress;
14
19
 
@@ -56,31 +61,17 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
56
61
  * @param _sidRegistryAddress Address of SID registry
57
62
  * @param _accessControlManager Address of the access control manager contract
58
63
  */
59
- function initialize(address _sidRegistryAddress, address _accessControlManager) public initializer {
64
+ function initialize(address _sidRegistryAddress, address _accessControlManager) external initializer {
60
65
  sidRegistryAddress = _sidRegistryAddress;
61
66
  __AccessControlled_init(_accessControlManager);
62
67
  }
63
68
 
64
- /**
65
- * @notice Uses Space ID to fetch the feed registry address
66
- * @return feedRegistryAddress Address of binance oracle feed registry.
67
- */
68
- function getFeedRegistryAddress() public view returns (address) {
69
- bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
70
-
71
- SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
72
- address publicResolverAddress = sidRegistry.resolver(nodeHash);
73
- PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
74
-
75
- return publicResolver.addr(nodeHash);
76
- }
77
-
78
69
  /**
79
70
  * @notice Gets the price of a vToken from the binance oracle
80
71
  * @param vToken Address of the vToken
81
72
  * @return Price in USD
82
73
  */
83
- function getUnderlyingPrice(address vToken) public view override returns (uint256) {
74
+ function getUnderlyingPrice(address vToken) external view override returns (uint256) {
84
75
  string memory symbol;
85
76
  uint256 decimals;
86
77
 
@@ -118,13 +109,27 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
118
109
  return (uint256(answer) * (10 ** (18 - decimalDelta))) * (10 ** (18 - decimals));
119
110
  }
120
111
 
112
+ /**
113
+ * @notice Uses Space ID to fetch the feed registry address
114
+ * @return feedRegistryAddress Address of binance oracle feed registry.
115
+ */
116
+ function getFeedRegistryAddress() public view returns (address) {
117
+ bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
118
+
119
+ SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
120
+ address publicResolverAddress = sidRegistry.resolver(nodeHash);
121
+ PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
122
+
123
+ return publicResolver.addr(nodeHash);
124
+ }
125
+
121
126
  /**
122
127
  * @notice Used to compare if two strings are equal or not
123
128
  * @param str1 The first string
124
129
  * @param str2 The second string
125
130
  * @return equal Returns true if both are equal or else false.
126
131
  */
127
- function compare(string memory str1, string memory str2) internal pure returns (bool) {
132
+ function compare(string memory str1, string memory str2) private pure returns (bool) {
128
133
  return keccak256(bytes(str1)) == keccak256(bytes(str2));
129
134
  }
130
135
  }
@@ -5,20 +5,24 @@ import "../interfaces/VBep20Interface.sol";
5
5
  import "../interfaces/OracleInterface.sol";
6
6
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
7
7
 
8
- struct ValidateConfig {
9
- /// @notice asset address
10
- address asset;
11
- /// @notice Upper bound of deviation between reported price and anchor price,
12
- /// beyond which the reported price will be invalidated
13
- uint256 upperBoundRatio;
14
- /// @notice Lower bound of deviation between reported price and anchor price,
15
- /// below which the reported price will be invalidated
16
- uint256 lowerBoundRatio;
17
- }
18
-
19
- // BoundValidator provides some common functions and can be used
20
- // to wrap up other contracts to form pivot oracles
8
+ /**
9
+ * @title BoundValidator
10
+ * @author Venus
11
+ * @notice This contracts is used to validate prices from two different sources. We need to set upper
12
+ * and lower bound ratios config for each vToken in this contract.
13
+ */
21
14
  contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
15
+ struct ValidateConfig {
16
+ /// @notice asset address
17
+ address asset;
18
+ /// @notice Upper bound of deviation between reported price and anchor price,
19
+ /// beyond which the reported price will be invalidated
20
+ uint256 upperBoundRatio;
21
+ /// @notice Lower bound of deviation between reported price and anchor price,
22
+ /// below which the reported price will be invalidated
23
+ uint256 lowerBoundRatio;
24
+ }
25
+
22
26
  /// @notice validation configs by asset
23
27
  mapping(address => ValidateConfig) public validateConfigs;
24
28
 
@@ -55,7 +59,7 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
55
59
  * @custom:error Zero length error is thrown if length of the config array is 0
56
60
  * @custom:event Emits ValidateConfigAdded for each validation config that is successfully set
57
61
  */
58
- function setValidateConfigs(ValidateConfig[] memory configs) external virtual {
62
+ function setValidateConfigs(ValidateConfig[] memory configs) external {
59
63
  uint256 length = configs.length;
60
64
  if (length == 0) revert("invalid validate config length");
61
65
  for (uint256 i; i < length; ) {
@@ -70,29 +74,10 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
70
74
  * @notice Initializes the owner of the contract
71
75
  * @param accessControlManager_ Address of the access control manager contract
72
76
  */
73
- function initialize(address accessControlManager_) public initializer {
77
+ function initialize(address accessControlManager_) external initializer {
74
78
  __AccessControlled_init(accessControlManager_);
75
79
  }
76
80
 
77
- /**
78
- * @notice Add a single validation config
79
- * @param config Validation config struct
80
- * @custom:access Only Governance
81
- * @custom:error Null address error is thrown if asset address is null
82
- * @custom:error Range error thrown if bound ratio is not positive
83
- * @custom:error Range error thrown if lower bound is greater than upper bound
84
- * @custom:event Emits ValidateConfigAdded when a validation config is successfully set
85
- */
86
- function setValidateConfig(ValidateConfig memory config) public virtual {
87
- _checkAccessAllowed("setValidateConfig(ValidateConfig)");
88
-
89
- if (config.asset == address(0)) revert("asset can't be zero address");
90
- if (config.upperBoundRatio == 0 || config.lowerBoundRatio == 0) revert("bound must be positive");
91
- if (config.upperBoundRatio <= config.lowerBoundRatio) revert("upper bound must be higher than lowner bound");
92
- validateConfigs[config.asset] = config;
93
- emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
94
- }
95
-
96
81
  /**
97
82
  * @notice Test reported asset price against anchor price
98
83
  * @param vToken vToken address
@@ -104,7 +89,7 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
104
89
  address vToken,
105
90
  uint256 reportedPrice,
106
91
  uint256 anchorPrice
107
- ) public view virtual override returns (bool) {
92
+ ) external view override returns (bool) {
108
93
  address asset = _getUnderlyingAsset(vToken);
109
94
 
110
95
  if (validateConfigs[asset].upperBoundRatio == 0) revert("validation config not exist");
@@ -112,15 +97,35 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
112
97
  return _isWithinAnchor(asset, reportedPrice, anchorPrice);
113
98
  }
114
99
 
100
+ /**
101
+ * @notice Add a single validation config
102
+ * @param config Validation config struct
103
+ * @custom:access Only Governance
104
+ * @custom:error Null address error is thrown if asset address is null
105
+ * @custom:error Range error thrown if bound ratio is not positive
106
+ * @custom:error Range error thrown if lower bound is greater than or equal to upper bound
107
+ * @custom:event Emits ValidateConfigAdded when a validation config is successfully set
108
+ */
109
+ function setValidateConfig(ValidateConfig memory config) public {
110
+ _checkAccessAllowed("setValidateConfig(ValidateConfig)");
111
+
112
+ if (config.asset == address(0)) revert("asset can't be zero address");
113
+ if (config.upperBoundRatio == 0 || config.lowerBoundRatio == 0) revert("bound must be positive");
114
+ if (config.upperBoundRatio <= config.lowerBoundRatio) revert("upper bound must be higher than lowner bound");
115
+ validateConfigs[config.asset] = config;
116
+ emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
117
+ }
118
+
115
119
  /**
116
120
  * @notice Test whether the reported price is within the valid bounds
117
121
  * @param asset Asset address
118
122
  * @param reportedPrice The price to be tested
119
123
  * @param anchorPrice The reported price must be within the the valid bounds of this price
120
124
  */
121
- function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) internal view returns (bool) {
125
+ function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) private view returns (bool) {
122
126
  if (reportedPrice != 0) {
123
- uint256 anchorRatio = (anchorPrice * 100e16) / reportedPrice;
127
+ // we need to multiply anchorPrice by 1e18 to make the ratio 18 decimals
128
+ uint256 anchorRatio = (anchorPrice * 1e18) / reportedPrice;
124
129
  uint256 upperBoundAnchorRatio = validateConfigs[asset].upperBoundRatio;
125
130
  uint256 lowerBoundAnchorRatio = validateConfigs[asset].lowerBoundRatio;
126
131
  return anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio;
@@ -133,7 +138,7 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
133
138
  * @param vToken vToken address
134
139
  * @return asset underlying asset address
135
140
  */
136
- function _getUnderlyingAsset(address vToken) internal view returns (address asset) {
141
+ function _getUnderlyingAsset(address vToken) private view returns (address asset) {
137
142
  if (address(vToken) == vBnb) {
138
143
  asset = BNB_ADDR;
139
144
  } else if (address(vToken) == vai) {
@@ -3,20 +3,26 @@ pragma solidity 0.8.13;
3
3
 
4
4
  import "../interfaces/VBep20Interface.sol";
5
5
  import "../interfaces/OracleInterface.sol";
6
- import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol";
6
+ import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
7
7
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
8
8
 
9
- struct TokenConfig {
10
- /// @notice Underlying token address, which can't be a null address and can be used to check if a token is supported
11
- /// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
12
- address asset;
13
- /// @notice Chainlink feed address
14
- address feed;
15
- /// @notice Price expiration period of this asset
16
- uint256 maxStalePeriod;
17
- }
18
-
9
+ /**
10
+ * @title ChainlinkOracle
11
+ * @author Venus
12
+ * @notice This oracle fetches price of assets from Chainlink.
13
+ */
19
14
  contract ChainlinkOracle is AccessControlledV8, OracleInterface {
15
+ struct TokenConfig {
16
+ /// @notice Underlying token address, which can't be a null address
17
+ /// @notice Used to check if a token is supported
18
+ /// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
19
+ address asset;
20
+ /// @notice Chainlink feed address
21
+ address feed;
22
+ /// @notice Price expiration period of this asset
23
+ uint256 maxStalePeriod;
24
+ }
25
+
20
26
  /// @notice vBNB address
21
27
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
22
28
  address public immutable vBnb;
@@ -35,12 +41,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
35
41
  mapping(address => TokenConfig) public tokenConfigs;
36
42
 
37
43
  /// @notice Emit when a price is manually set
38
- event PricePosted(
39
- address indexed asset,
40
- uint256 previousPriceMantissa,
41
- uint256 requestedPriceMantissa,
42
- uint256 newPriceMantissa
43
- );
44
+ event PricePosted(address indexed asset, uint256 previousPriceMantissa, uint256 newPriceMantissa);
44
45
 
45
46
  /// @notice Emit when a token config is added
46
47
  event TokenConfigAdded(address indexed asset, address feed, uint256 maxStalePeriod);
@@ -77,7 +78,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
77
78
  address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
78
79
  uint256 previousPriceMantissa = prices[asset];
79
80
  prices[asset] = underlyingPriceMantissa;
80
- emit PricePosted(asset, previousPriceMantissa, prices[asset], prices[asset]);
81
+ emit PricePosted(asset, previousPriceMantissa, prices[asset]);
81
82
  }
82
83
 
83
84
  /**
@@ -92,7 +93,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
92
93
 
93
94
  uint256 previousPriceMantissa = prices[asset];
94
95
  prices[asset] = price;
95
- emit PricePosted(asset, previousPriceMantissa, price, price);
96
+ emit PricePosted(asset, previousPriceMantissa, price);
96
97
  }
97
98
 
98
99
  /**
@@ -116,10 +117,19 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
116
117
  * @notice Initializes the owner of the contract
117
118
  * @param accessControlManager_ Address of the access control manager contract
118
119
  */
119
- function initialize(address accessControlManager_) public initializer {
120
+ function initialize(address accessControlManager_) external initializer {
120
121
  __AccessControlled_init(accessControlManager_);
121
122
  }
122
123
 
124
+ /**
125
+ * @notice Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
126
+ * @param vToken vToken address
127
+ * @return price Underlying price in USD
128
+ */
129
+ function getUnderlyingPrice(address vToken) external view override returns (uint256) {
130
+ return _getUnderlyingPriceInternal(VBep20Interface(vToken));
131
+ }
132
+
123
133
  /**
124
134
  * @notice Add single token config. vToken & feed cannot be null addresses and maxStalePeriod must be positive
125
135
  * @param tokenConfig Token config struct
@@ -139,15 +149,6 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
139
149
  emit TokenConfigAdded(tokenConfig.asset, tokenConfig.feed, tokenConfig.maxStalePeriod);
140
150
  }
141
151
 
142
- /**
143
- * @notice Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
144
- * @param vToken vToken address
145
- * @return price Underlying price in USD
146
- */
147
- function getUnderlyingPrice(address vToken) public view override returns (uint256) {
148
- return _getUnderlyingPriceInternal(VBep20Interface(vToken));
149
- }
150
-
151
152
  /**
152
153
  * @notice Gets the Chainlink price for the underlying asset of a given vToken
153
154
  * or the manually set price if it's been set
@@ -156,7 +157,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
156
157
  * @param vToken vToken address
157
158
  * @return price Underlying price in USD
158
159
  */
159
- function _getUnderlyingPriceInternal(VBep20Interface vToken) internal view returns (uint256 price) {
160
+ function _getUnderlyingPriceInternal(VBep20Interface vToken) private view returns (uint256 price) {
160
161
  address token;
161
162
  uint256 decimals;
162
163
 
@@ -179,7 +180,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
179
180
  price = _getChainlinkPrice(token);
180
181
  }
181
182
 
182
- uint256 decimalDelta = uint256(18) - uint256(decimals);
183
+ uint256 decimalDelta = 18 - uint256(decimals);
183
184
  return price * (10 ** decimalDelta);
184
185
  }
185
186
 
@@ -196,15 +197,15 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
196
197
  */
197
198
  function _getChainlinkPrice(
198
199
  address asset
199
- ) internal view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
200
+ ) private view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
200
201
  TokenConfig memory tokenConfig = tokenConfigs[asset];
201
- AggregatorV2V3Interface feed = AggregatorV2V3Interface(tokenConfig.feed);
202
+ AggregatorV3Interface feed = AggregatorV3Interface(tokenConfig.feed);
202
203
 
203
204
  // note: maxStalePeriod cannot be 0
204
205
  uint256 maxStalePeriod = tokenConfig.maxStalePeriod;
205
206
 
206
207
  // Chainlink USD-denominated feeds store answers at 8 decimals, mostly
207
- uint256 decimalDelta = uint256(18) - feed.decimals();
208
+ uint256 decimalDelta = 18 - feed.decimals();
208
209
 
209
210
  (, int256 answer, , uint256 updatedAt, ) = feed.latestRoundData();
210
211
  if (answer <= 0) revert("chainlink price must be positive");