@venusprotocol/oracle 1.6.1 → 1.6.2

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 (129) hide show
  1. package/LICENSE +11 -0
  2. package/README.md +107 -0
  3. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +1 -1
  4. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +1 -1
  5. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +1 -1
  6. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +4 -0
  7. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +215 -0
  8. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +4 -0
  9. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +183 -0
  10. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
  11. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
  12. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
  13. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
  14. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +4 -0
  15. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +10 -0
  16. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +4 -0
  17. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +30 -0
  18. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +4 -0
  19. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +30 -0
  20. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +4 -0
  21. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +10 -0
  22. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +1 -1
  23. package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.dbg.json +1 -1
  24. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
  25. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +4 -0
  26. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +115 -0
  27. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
  28. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
  29. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +1 -1
  30. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
  31. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
  32. package/artifacts/build-info/a47a69a8f108d3e7113faf89771988ff.json +1 -0
  33. package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +4 -0
  34. package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +369 -0
  35. package/artifacts/contracts/Governance/AccessControlled.sol/AccessControlled.dbg.json +4 -0
  36. package/artifacts/contracts/Governance/AccessControlled.sol/AccessControlled.json +181 -0
  37. package/artifacts/contracts/Governance/IAccessControlManager.sol/IAccessControlManager.dbg.json +4 -0
  38. package/artifacts/contracts/Governance/IAccessControlManager.sol/IAccessControlManager.json +282 -0
  39. package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +1 -1
  40. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
  41. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +130 -2
  42. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
  43. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +1 -1
  44. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +1 -1
  45. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
  46. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
  47. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +4 -0
  48. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +30 -0
  49. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +1 -1
  50. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +1 -1
  51. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +1 -1
  52. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +4 -0
  53. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +30 -0
  54. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
  55. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +1 -1
  56. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +1 -1
  57. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
  58. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
  59. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +37 -6
  60. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
  61. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +131 -2
  62. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
  63. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +122 -6
  64. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
  65. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +130 -2
  66. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
  67. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +132 -3
  68. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
  69. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
  70. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
  71. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +2 -2
  72. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
  73. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +2 -2
  74. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +1 -1
  75. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +1 -1
  76. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
  77. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
  78. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
  79. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
  80. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
  81. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
  82. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
  83. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
  84. package/contracts/Governance/AccessControlManager.sol +99 -0
  85. package/contracts/Governance/AccessControlled.sol +75 -0
  86. package/contracts/Governance/IAccessControlManager.sol +22 -0
  87. package/contracts/ResilientOracle.sol +44 -14
  88. package/contracts/interfaces/PublicResolverInterface.sol +7 -0
  89. package/contracts/interfaces/SIDRegistryInterface.sol +7 -0
  90. package/contracts/oracles/BinanceOracle.sol +35 -7
  91. package/contracts/oracles/BoundValidator.sol +36 -8
  92. package/contracts/oracles/ChainlinkOracle.sol +31 -21
  93. package/contracts/oracles/PythOracle.sol +23 -8
  94. package/contracts/oracles/TwapOracle.sol +41 -11
  95. package/deploy/1-deploy-oracles.ts +149 -0
  96. package/deploy/2-configure-feeds.ts +208 -0
  97. package/deployments/bsctestnet/AccessControlManager.json +563 -0
  98. package/deployments/bsctestnet/BinanceOracle.json +66 -40
  99. package/deployments/bsctestnet/BinanceOracle_Implementation.json +84 -38
  100. package/deployments/bsctestnet/BinanceOracle_Proxy.json +34 -34
  101. package/deployments/bsctestnet/BoundValidator.json +177 -39
  102. package/deployments/bsctestnet/BoundValidator_Implementation.json +248 -40
  103. package/deployments/bsctestnet/BoundValidator_Proxy.json +51 -37
  104. package/deployments/bsctestnet/ChainlinkOracle.json +161 -50
  105. package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +239 -47
  106. package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +44 -44
  107. package/deployments/bsctestnet/DefaultProxyAdmin.json +18 -18
  108. package/deployments/bsctestnet/PythOracle.json +178 -45
  109. package/deployments/bsctestnet/PythOracle_Implementation.json +246 -43
  110. package/deployments/bsctestnet/PythOracle_Proxy.json +53 -43
  111. package/deployments/bsctestnet/ResilientOracle.json +167 -48
  112. package/deployments/bsctestnet/ResilientOracle_Implementation.json +254 -51
  113. package/deployments/bsctestnet/ResilientOracle_Proxy.json +42 -46
  114. package/deployments/bsctestnet/TwapOracle.json +178 -40
  115. package/deployments/bsctestnet/TwapOracle_Implementation.json +270 -58
  116. package/deployments/bsctestnet/TwapOracle_Proxy.json +51 -37
  117. package/deployments/bsctestnet/solcInputs/{6153c675ce838eebb6442d63350712be.json → 30f2cb3e89e183b8669f05bddf9426d9.json} +46 -7
  118. package/package.json +3 -2
  119. package/artifacts/build-info/1d7bedd9b14544f287811332b9a539d7.json +0 -1
  120. package/artifacts/build-info/57da5d39a9f98618d0dcf1f6d4ff6b0d.json +0 -1
  121. package/artifacts/build-info/f6af69795174616b8b4a6373f9f1c538.json +0 -1
  122. package/deploy/1-deploy-oracles.d.ts +0 -2
  123. package/deploy/1-deploy-oracles.d.ts.map +0 -1
  124. package/deploy/1-deploy-oracles.js +0 -128
  125. package/deploy/1-deploy-oracles.js.map +0 -1
  126. package/deploy/2-configure-feeds.d.ts +0 -2
  127. package/deploy/2-configure-feeds.d.ts.map +0 -1
  128. package/deploy/2-configure-feeds.js +0 -139
  129. package/deploy/2-configure-feeds.js.map +0 -1
@@ -4,10 +4,10 @@ pragma solidity 0.8.13;
4
4
  import "@openzeppelin/contracts/utils/math/SafeMath.sol";
5
5
  import "@openzeppelin/contracts/utils/math/SafeCast.sol";
6
6
  import "@openzeppelin/contracts/utils/math/SignedMath.sol";
7
- import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
8
7
  import "../interfaces/PythInterface.sol";
9
8
  import "../interfaces/OracleInterface.sol";
10
9
  import "../interfaces/VBep20Interface.sol";
10
+ import "../Governance/AccessControlled.sol";
11
11
 
12
12
  struct TokenConfig {
13
13
  bytes32 pythId;
@@ -19,7 +19,7 @@ struct TokenConfig {
19
19
  * PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores the
20
20
  * updated prices from external sources
21
21
  */
22
- contract PythOracle is OwnableUpgradeable, OracleInterface {
22
+ contract PythOracle is AccessControlled, OracleInterface {
23
23
  using SafeMath for uint256;
24
24
 
25
25
  // To calculate 10 ** n(which is a signed type)
@@ -35,6 +35,10 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
35
35
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
36
36
  address public immutable vBnb;
37
37
 
38
+ /// @notice VAI address
39
+ /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
40
+ address public immutable vai;
41
+
38
42
  /// @notice Set this as asset address for BNB. This is the underlying for vBNB
39
43
  address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
40
44
 
@@ -57,9 +61,11 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
57
61
 
58
62
  /// @notice Constructor for the implementation contract. Sets immutable variables.
59
63
  /// @param vBnbAddress The address of the vBNB
64
+ /// @param vaiAddress The address of the VAI
60
65
  /// @custom:oz-upgrades-unsafe-allow constructor
61
- constructor(address vBnbAddress) notNullAddress(vBnbAddress) {
66
+ constructor(address vBnbAddress, address vaiAddress) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) {
62
67
  vBnb = vBnbAddress;
68
+ vai = vaiAddress;
63
69
  _disableInitializers();
64
70
  }
65
71
 
@@ -69,7 +75,8 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
69
75
  * @custom:access Only Governance
70
76
  * @custom:error Zero length error is thrown if length of the array in parameter is 0
71
77
  */
72
- function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external onlyOwner {
78
+ function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
79
+ _checkAccessAllowed("setTokenConfigs(TokenConfig[])");
73
80
  require(tokenConfigs_.length != 0, "length can't be 0");
74
81
  uint256 numTokenConfigs = tokenConfigs_.length;
75
82
  for (uint256 i; i < numTokenConfigs; ++i) {
@@ -86,7 +93,8 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
86
93
  */
87
94
  function setUnderlyingPythOracle(
88
95
  IPyth underlyingPythOracle_
89
- ) external onlyOwner notNullAddress(address(underlyingPythOracle_)) {
96
+ ) external notNullAddress(address(underlyingPythOracle_)) {
97
+ _checkAccessAllowed("setUnderlyingPythOracle(IPyth)");
90
98
  underlyingPythOracle = underlyingPythOracle_;
91
99
  emit PythOracleSet(address(underlyingPythOracle_));
92
100
  }
@@ -94,9 +102,12 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
94
102
  /**
95
103
  * @notice Initializes the owner of the contract and sets required contracts
96
104
  * @param underlyingPythOracle_ Address of the Pyth oracle
105
+ * @param accessControlManager_ Address of the access control manager contract
97
106
  */
98
- function initialize(address underlyingPythOracle_) public initializer {
99
- __Ownable_init();
107
+ function initialize(address underlyingPythOracle_, address accessControlManager_) public initializer {
108
+ __Ownable2Step_init();
109
+ __AccessControlled_init_unchained(accessControlManager_);
110
+
100
111
  require(underlyingPythOracle_ != address(0), "pyth oracle cannot be zero address");
101
112
  underlyingPythOracle = IPyth(underlyingPythOracle_);
102
113
  emit PythOracleSet(underlyingPythOracle_);
@@ -109,7 +120,8 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
109
120
  * @custom:error Range error is thrown if max stale period is zero
110
121
  * @custom:error NotNullAddress error is thrown if asset address is null
111
122
  */
112
- function setTokenConfig(TokenConfig memory tokenConfig) public onlyOwner notNullAddress(tokenConfig.asset) {
123
+ function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
124
+ _checkAccessAllowed("setTokenConfig(TokenConfig)");
113
125
  require(tokenConfig.maxStalePeriod != 0, "max stale period cannot be 0");
114
126
  tokenConfigs[tokenConfig.asset] = tokenConfig;
115
127
  emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
@@ -134,6 +146,9 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
134
146
  if (address(vToken) == vBnb) {
135
147
  asset = BNB_ADDR;
136
148
  decimals = 18;
149
+ } else if (address(vToken) == vai) {
150
+ asset = vai;
151
+ decimals = 18;
137
152
  } else {
138
153
  asset = VBep20Interface(vToken).underlying();
139
154
  decimals = VBep20Interface(asset).decimals();
@@ -1,11 +1,11 @@
1
1
  // SPDX-License-Identifier: BSD-3-Clause
2
2
  pragma solidity 0.8.13;
3
3
 
4
- import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
5
4
  import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
6
5
  import "../libraries/PancakeLibrary.sol";
7
6
  import "../interfaces/OracleInterface.sol";
8
7
  import "../interfaces/VBep20Interface.sol";
8
+ import "../Governance/AccessControlled.sol";
9
9
 
10
10
  struct Observation {
11
11
  uint256 timestamp;
@@ -28,7 +28,7 @@ struct TokenConfig {
28
28
  uint256 anchorPeriod;
29
29
  }
30
30
 
31
- contract TwapOracle is OwnableUpgradeable, TwapInterface {
31
+ contract TwapOracle is AccessControlled, TwapInterface {
32
32
  using FixedPoint for *;
33
33
 
34
34
  /// @notice WBNB address
@@ -39,6 +39,10 @@ contract TwapOracle is OwnableUpgradeable, TwapInterface {
39
39
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
40
40
  address public immutable vBnb;
41
41
 
42
+ /// @notice VAI address
43
+ /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
44
+ address public immutable vai;
45
+
42
46
  /// @notice the base unit of WBNB and BUSD, which are the paired tokens for all assets
43
47
  uint256 public constant bnbBaseUnit = 1e18;
44
48
  uint256 public constant busdBaseUnit = 1e18;
@@ -80,10 +84,16 @@ contract TwapOracle is OwnableUpgradeable, TwapInterface {
80
84
  /// @notice Constructor for the implementation contract. Sets immutable variables.
81
85
  /// @param vBnbAddress The address of the VBNB
82
86
  /// @param wBnbAddress The address of the WBNB
87
+ /// @param vaiAddress The address of the WBNB
83
88
  /// @custom:oz-upgrades-unsafe-allow constructor
84
- constructor(address vBnbAddress, address wBnbAddress) notNullAddress(vBnbAddress) notNullAddress(wBnbAddress) {
89
+ constructor(
90
+ address vBnbAddress,
91
+ address wBnbAddress,
92
+ address vaiAddress
93
+ ) notNullAddress(vBnbAddress) notNullAddress(wBnbAddress) notNullAddress(vaiAddress) {
85
94
  vBnb = vBnbAddress;
86
95
  WBNB = wBnbAddress;
96
+ vai = vaiAddress;
87
97
  _disableInitializers();
88
98
  }
89
99
 
@@ -93,6 +103,7 @@ contract TwapOracle is OwnableUpgradeable, TwapInterface {
93
103
  * @custom:error Zero length error thrown, if length of the config array is 0
94
104
  */
95
105
  function setTokenConfigs(TokenConfig[] memory configs) external onlyOwner {
106
+ _checkAccessAllowed("setTokenConfigsTokenConfig[])");
96
107
  require(configs.length > 0, "length can't be 0");
97
108
  uint256 numTokenConfigs = configs.length;
98
109
  for (uint256 i; i < numTokenConfigs; ++i) {
@@ -108,8 +119,8 @@ contract TwapOracle is OwnableUpgradeable, TwapInterface {
108
119
  * @custom:error Range error is thrown if TWAP price is not greater than zero
109
120
  */
110
121
  function getUnderlyingPrice(address vToken) external view override returns (uint256) {
111
- // VBNB token doesn't have `underlying` method, vBNB's underlying token is wBNB
112
- address asset = address(vToken) == vBnb ? WBNB : VBep20Interface(vToken).underlying();
122
+ address asset = _getUnderlyingAsset(vToken);
123
+
113
124
  require(tokenConfigs[asset].asset != address(0), "asset not exist");
114
125
  uint256 price = prices[asset];
115
126
 
@@ -119,10 +130,12 @@ contract TwapOracle is OwnableUpgradeable, TwapInterface {
119
130
  }
120
131
 
121
132
  /**
122
- * @notice Initializes the owner of the contract and sets the contracts required
133
+ * @notice Initializes the owner of the contract
134
+ * @param accessControlManager_ Address of the access control manager contract
123
135
  */
124
- function initialize() public initializer {
125
- __Ownable_init();
136
+ function initialize(address accessControlManager_) public initializer {
137
+ __Ownable2Step_init();
138
+ __AccessControlled_init_unchained(accessControlManager_);
126
139
  }
127
140
 
128
141
  /**
@@ -139,7 +152,9 @@ contract TwapOracle is OwnableUpgradeable, TwapInterface {
139
152
  */
140
153
  function setTokenConfig(
141
154
  TokenConfig memory config
142
- ) public onlyOwner notNullAddress(config.asset) notNullAddress(config.pancakePool) {
155
+ ) public notNullAddress(config.asset) notNullAddress(config.pancakePool) {
156
+ _checkAccessAllowed("setTokenConfig(TokenConfig)");
157
+
143
158
  require(config.anchorPeriod > 0, "anchor period must be positive");
144
159
  require(config.baseUnit > 0, "base unit must be positive");
145
160
  require(
@@ -161,8 +176,8 @@ contract TwapOracle is OwnableUpgradeable, TwapInterface {
161
176
  * @custom:error Missing error is thrown if token config does not exist
162
177
  */
163
178
  function updateTwap(address vToken) public returns (uint256) {
164
- // VBNB token doesn't have `underlying` method, vBNB's underlying token is wBNB
165
- address asset = address(vToken) == vBnb ? WBNB : VBep20Interface(vToken).underlying();
179
+ address asset = _getUnderlyingAsset(vToken);
180
+
166
181
  require(tokenConfigs[asset].asset != address(0), "asset not exist");
167
182
  // Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
168
183
  if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
@@ -278,4 +293,19 @@ contract TwapOracle is OwnableUpgradeable, TwapInterface {
278
293
  );
279
294
  return (cumulativePrice, startCumulativePrice, startCumulativeTimestamp);
280
295
  }
296
+
297
+ /**
298
+ * @dev This function returns the underlying asset of a vToken
299
+ * @param vToken vToken address
300
+ * @return asset underlying asset address
301
+ */
302
+ function _getUnderlyingAsset(address vToken) internal view returns (address asset) {
303
+ if (address(vToken) == vBnb) {
304
+ asset = WBNB;
305
+ } else if (address(vToken) == vai) {
306
+ asset = vai;
307
+ } else {
308
+ asset = VBep20Interface(vToken).underlying();
309
+ }
310
+ }
281
311
  }
@@ -0,0 +1,149 @@
1
+ import mainnetDeployments from "@venusprotocol/venus-protocol/networks/mainnet.json";
2
+ import testnetDeployments from "@venusprotocol/venus-protocol/networks/testnet.json";
3
+ import hre from "hardhat";
4
+ import { DeployFunction } from "hardhat-deploy/dist/types";
5
+ import { HardhatRuntimeEnvironment } from "hardhat/types";
6
+
7
+ const ADDRESSES = {
8
+ bsctestnet: {
9
+ vBNBAddress: testnetDeployments.Contracts.vBNB,
10
+ WBNBAddress: "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",
11
+ VAIAddress: testnetDeployments.Contracts.VAI,
12
+ pythOracleAddress: "0xd7308b14BF4008e7C7196eC35610B1427C5702EA",
13
+ sidRegistryAddress: "0xfFB52185b56603e0fd71De9de4F6f902f05EEA23",
14
+ },
15
+ bscmainnet: {
16
+ vBNBAddress: mainnetDeployments.Contracts.vBNB,
17
+ WBNBAddress: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
18
+ VAIAddress: mainnetDeployments.Contracts.VAI,
19
+ pythOracleAddress: "0x4D7E825f80bDf85e913E0DD2A2D54927e9dE1594",
20
+ sidRegistryAddress: "0x08CEd32a7f3eeC915Ba84415e9C07a7286977956",
21
+ },
22
+ };
23
+
24
+ const func: DeployFunction = async function ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) {
25
+ const { deploy } = deployments;
26
+ const { deployer } = await getNamedAccounts();
27
+
28
+ const networkName = network.name === "bscmainnet" ? "bscmainnet" : "bsctestnet";
29
+
30
+ const vBNBAddress = ADDRESSES[networkName].vBNBAddress;
31
+ const VAIAddress = ADDRESSES[networkName].VAIAddress;
32
+ const WBNBAddress = ADDRESSES[networkName].WBNBAddress;
33
+
34
+ await deploy("AccessControlManager", {
35
+ from: deployer,
36
+ args: [],
37
+ log: true,
38
+ autoMine: true,
39
+ });
40
+
41
+ const accessControlManager = await hre.ethers.getContract("AccessControlManager");
42
+
43
+ await deploy("BoundValidator", {
44
+ from: deployer,
45
+ log: true,
46
+ deterministicDeployment: false,
47
+ args: [vBNBAddress, VAIAddress],
48
+ proxy: {
49
+ proxyContract: "OptimizedTransparentProxy",
50
+ execute: {
51
+ methodName: "initialize",
52
+ args: [accessControlManager.address],
53
+ },
54
+ },
55
+ });
56
+
57
+ const boundValidator = await hre.ethers.getContract("BoundValidator");
58
+
59
+ await deploy("ResilientOracle", {
60
+ from: deployer,
61
+ log: true,
62
+ deterministicDeployment: false,
63
+ args: [vBNBAddress, VAIAddress],
64
+ proxy: {
65
+ proxyContract: "OptimizedTransparentProxy",
66
+ execute: {
67
+ methodName: "initialize",
68
+ args: [boundValidator.address, accessControlManager.address],
69
+ },
70
+ },
71
+ });
72
+
73
+ await deploy("ChainlinkOracle", {
74
+ contract: network.live ? "ChainlinkOracle" : "MockChainlinkOracle",
75
+ from: deployer,
76
+ log: true,
77
+ deterministicDeployment: false,
78
+ args: network.live ? [vBNBAddress, VAIAddress] : [],
79
+ proxy: {
80
+ proxyContract: "OptimizedTransparentProxy",
81
+ execute: {
82
+ methodName: "initialize",
83
+ args: network.live ? [accessControlManager.address] : [],
84
+ },
85
+ },
86
+ });
87
+
88
+ await deploy("TwapOracle", {
89
+ contract: network.live ? "TwapOracle" : "MockTwapOracle",
90
+ from: deployer,
91
+ log: true,
92
+ deterministicDeployment: false,
93
+ args: network.live ? [vBNBAddress, WBNBAddress, VAIAddress] : [],
94
+ proxy: {
95
+ proxyContract: "OptimizedTransparentProxy",
96
+ execute: {
97
+ methodName: "initialize",
98
+ args: network.live ? [accessControlManager.address] : [vBNBAddress],
99
+ },
100
+ },
101
+ });
102
+
103
+ const pythOracleAddress = ADDRESSES[networkName].pythOracleAddress;
104
+
105
+ await deploy("PythOracle", {
106
+ contract: network.live ? "PythOracle" : "MockPythOracle",
107
+ from: deployer,
108
+ log: true,
109
+ deterministicDeployment: false,
110
+ args: network.live ? [vBNBAddress, VAIAddress] : [],
111
+ proxy: {
112
+ proxyContract: "OptimizedTransparentProxy",
113
+ execute: {
114
+ methodName: "initialize",
115
+ args: network.live ? [pythOracleAddress, accessControlManager.address] : [pythOracleAddress],
116
+ },
117
+ },
118
+ });
119
+
120
+ const sidRegistryAddress = ADDRESSES[networkName].sidRegistryAddress;
121
+
122
+ await deploy("BinanceOracle", {
123
+ contract: network.live ? "BinanceOracle" : "MockBinanceOracle",
124
+ from: deployer,
125
+ log: true,
126
+ deterministicDeployment: false,
127
+ args: network.live ? [vBNBAddress, VAIAddress] : [],
128
+ proxy: {
129
+ proxyContract: "OptimizedTransparentProxy",
130
+ execute: {
131
+ methodName: "initialize",
132
+ args: [sidRegistryAddress],
133
+ },
134
+ },
135
+ });
136
+
137
+ const resilientOracle = await hre.ethers.getContract("ResilientOracle");
138
+ const pythOracle = await hre.ethers.getContract("PythOracle");
139
+ const chainlinkOracle = await hre.ethers.getContract("ChainlinkOracle");
140
+
141
+ await accessControlManager.giveCallPermission(chainlinkOracle.address, "setTokenConfig(TokenConfig)", deployer);
142
+
143
+ await accessControlManager.giveCallPermission(pythOracle.address, "setTokenConfig(TokenConfig)", deployer);
144
+
145
+ await accessControlManager.giveCallPermission(resilientOracle.address, "setTokenConfig(TokenConfig)", deployer);
146
+ };
147
+
148
+ module.exports = func;
149
+ module.exports.tags = ["deploy"];
@@ -0,0 +1,208 @@
1
+ import { Contract } from "ethers";
2
+ import hre from "hardhat";
3
+ import { DeployFunction } from "hardhat-deploy/dist/types";
4
+ import { HardhatRuntimeEnvironment } from "hardhat/types";
5
+
6
+ interface Feed {
7
+ [key: string]: string;
8
+ }
9
+
10
+ interface Config {
11
+ [key: string]: Feed;
12
+ }
13
+
14
+ interface Asset {
15
+ token: string;
16
+ address: string;
17
+ oracle: string;
18
+ price: string;
19
+ }
20
+
21
+ interface Assets {
22
+ [key: string]: Asset[];
23
+ }
24
+
25
+ interface Oracle {
26
+ oracles: [string, string, string];
27
+ enableFlagsForOracles: [boolean, boolean, boolean];
28
+ underlyingOracle: Contract;
29
+ getTokenConfig?: (asset: Asset, networkName: string) => void;
30
+ }
31
+
32
+ interface Oracles {
33
+ [key: string]: Oracle;
34
+ }
35
+
36
+ const chainlinkFeed: Config = {
37
+ bsctestnet: {
38
+ BNX: "0xf51492DeD1308Da8195C3bfcCF4a7c70fDbF9daE",
39
+ BTCB: "0x5741306c21795FdCBb9b265Ea0255F499DFe515C",
40
+ },
41
+ };
42
+
43
+ const pythID: Config = {
44
+ bsctestnet: {
45
+ AUTO: "0xd954e9a88c7f97b4645b535869aba8a1e50697270a0afb09891accc031f03880",
46
+ },
47
+ };
48
+
49
+ const assets: Assets = {
50
+ bsctestnet: [
51
+ {
52
+ token: "BNX",
53
+ address: "0xa8062D2bd49D1D2C6376B444bde19402B38938d0",
54
+ oracle: "chainlink",
55
+ price: "159990000000000000000",
56
+ },
57
+ {
58
+ token: "BTCB",
59
+ address: "0xA808e341e8e723DC6BA0Bb5204Bafc2330d7B8e4",
60
+ oracle: "chainlink",
61
+ price: "159990000000000000000",
62
+ },
63
+ {
64
+ token: "XVS",
65
+ address: "0xB9e0E753630434d7863528cc73CB7AC638a7c8ff",
66
+ oracle: "binance",
67
+ price: "208000000000000000",
68
+ },
69
+ {
70
+ token: "BUSD",
71
+ address: "0x8301F2213c0eeD49a7E28Ae4c3e91722919B8B47",
72
+ oracle: "binance",
73
+ price: "159990000000000000000",
74
+ },
75
+ {
76
+ token: "ANKR",
77
+ address: "0xe4a90EB942CF2DA7238e8F6cC9EF510c49FC8B4B",
78
+ oracle: "binance",
79
+ price: "159990000000000000000",
80
+ },
81
+ {
82
+ token: "ankrBNB",
83
+ address: "0x167F1F9EF531b3576201aa3146b13c57dbEda514",
84
+ oracle: "binance",
85
+ price: "159990000000000000000",
86
+ },
87
+ {
88
+ token: "MBOX",
89
+ address: "0x523027fFdf9B18Aa652dBcd6B92f885009153dA3",
90
+ oracle: "binance",
91
+ price: "159990000000000000000",
92
+ },
93
+ {
94
+ token: "NFT",
95
+ address: "0xc440e4F21AFc2C3bDBA1Af7D0E338ED35d3e25bA",
96
+ oracle: "binance",
97
+ price: "159990000000000000000",
98
+ },
99
+ {
100
+ token: "RACA",
101
+ address: "0xD60cC803d888A3e743F21D0bdE4bF2cAfdEA1F26",
102
+ oracle: "binance",
103
+ price: "159990000000000000000",
104
+ },
105
+ {
106
+ token: "stkBNB",
107
+ address: "0x2999C176eBf66ecda3a646E70CeB5FF4d5fCFb8C",
108
+ oracle: "binance",
109
+ price: "159990000000000000000",
110
+ },
111
+ {
112
+ token: "USDD",
113
+ address: "0x2E2466e22FcbE0732Be385ee2FBb9C59a1098382",
114
+ oracle: "binance",
115
+ price: "159990000000000000000",
116
+ },
117
+ {
118
+ token: "AUTO",
119
+ address: "0xD9FAc4092e795c26f5F23803FA855A975bfC9973",
120
+ oracle: "pyth",
121
+ price: "159990000000000000000",
122
+ },
123
+ ],
124
+ };
125
+
126
+ const addr0000 = "0x0000000000000000000000000000000000000000";
127
+ const DEFAULT_STALE_PERIOD = 3600; //60 min
128
+
129
+ const func: DeployFunction = async function ({ network }: HardhatRuntimeEnvironment) {
130
+ const networkName: string = network.name === "bscmainnet" ? "bscmainnet" : "bsctestnet";
131
+
132
+ const resilientOracle = await hre.ethers.getContract("ResilientOracle");
133
+ const binanceOracle = await hre.ethers.getContract("BinanceOracle");
134
+ const chainlinkOracle = await hre.ethers.getContract("ChainlinkOracle");
135
+ const pythOracle = await hre.ethers.getContract("PythOracle");
136
+
137
+ const oraclesData: Oracles = {
138
+ chainlink: {
139
+ oracles: [chainlinkOracle.address, addr0000, addr0000],
140
+ enableFlagsForOracles: [true, false, false],
141
+ underlyingOracle: chainlinkOracle,
142
+ getTokenConfig: (asset: Asset, networkName: string) => ({
143
+ asset: asset.address,
144
+ feed: chainlinkFeed[networkName][asset.token],
145
+ maxStalePeriod: DEFAULT_STALE_PERIOD,
146
+ }),
147
+ },
148
+ binance: {
149
+ oracles: [binanceOracle.address, addr0000, addr0000],
150
+ enableFlagsForOracles: [true, false, false],
151
+ underlyingOracle: binanceOracle,
152
+ },
153
+ pyth: {
154
+ oracles: [pythOracle.address, addr0000, addr0000],
155
+ enableFlagsForOracles: [true, false, false],
156
+ underlyingOracle: pythOracle,
157
+ getTokenConfig: (asset: Asset, networkName: string) => ({
158
+ pythId: pythID[networkName][asset.token],
159
+ asset: asset.address,
160
+ maxStalePeriod: DEFAULT_STALE_PERIOD,
161
+ }),
162
+ },
163
+ };
164
+
165
+ for (let i = 0; i < assets[networkName].length; i++) {
166
+ const asset = assets[networkName][i];
167
+ const oracle = asset.oracle;
168
+ console.log(`Configuring ${asset.token}`);
169
+
170
+ if (network.live) {
171
+ console.log(`Configuring ${oracle} oracle for ${asset.token}`);
172
+
173
+ if (oraclesData[oracle].underlyingOracle.address != binanceOracle.address) {
174
+ const tx = await oraclesData[oracle].underlyingOracle?.setTokenConfig(
175
+ oraclesData[oracle].getTokenConfig(asset, networkName),
176
+ );
177
+ tx.wait(1);
178
+ }
179
+
180
+ console.log(`Configuring resillient oracle for ${asset.token}`);
181
+ const tx = await resilientOracle.setTokenConfig({
182
+ asset: asset.address,
183
+ oracles: oraclesData[oracle].oracles,
184
+ enableFlagsForOracles: oraclesData[oracle].enableFlagsForOracles,
185
+ });
186
+
187
+ await tx.wait(1);
188
+ } else {
189
+ const mock = await hre.ethers.getContract(`Mock${asset.token}`);
190
+
191
+ console.log(`Configuring resillient oracle for ${asset.token}`);
192
+ let tx = await resilientOracle.setTokenConfig({
193
+ asset: mock.address,
194
+ oracles: oraclesData[oracle].oracles,
195
+ enableFlagsForOracles: oraclesData[oracle].enableFlagsForOracles,
196
+ });
197
+
198
+ await tx.wait(1);
199
+
200
+ console.log(`Configuring ${oracle} oracle for ${asset.token}`);
201
+ tx = await oraclesData[oracle].underlyingOracle?.setPrice(mock.address, asset.price);
202
+ await tx.wait(1);
203
+ }
204
+ }
205
+ };
206
+
207
+ module.exports = func;
208
+ module.exports.tags = ["configure"];