@venusprotocol/oracle 1.0.0-dev.1

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 (78) hide show
  1. package/LICENSE +11 -0
  2. package/README.md +117 -0
  3. package/contracts/ResilientOracle.sol +376 -0
  4. package/contracts/interfaces/FeedRegistryInterface.sol +14 -0
  5. package/contracts/interfaces/OracleInterface.sol +22 -0
  6. package/contracts/interfaces/PublicResolverInterface.sol +7 -0
  7. package/contracts/interfaces/PythInterface.sol +249 -0
  8. package/contracts/interfaces/SIDRegistryInterface.sol +7 -0
  9. package/contracts/interfaces/VBep20Interface.sol +11 -0
  10. package/contracts/libraries/PancakeLibrary.sol +68 -0
  11. package/contracts/oracles/BinanceOracle.sol +125 -0
  12. package/contracts/oracles/BoundValidator.sol +149 -0
  13. package/contracts/oracles/ChainlinkOracle.sol +214 -0
  14. package/contracts/oracles/PythOracle.sol +174 -0
  15. package/contracts/oracles/TwapOracle.sol +309 -0
  16. package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +29 -0
  17. package/contracts/oracles/mocks/MockBinanceOracle.sol +22 -0
  18. package/contracts/oracles/mocks/MockChainlinkOracle.sol +27 -0
  19. package/contracts/oracles/mocks/MockPythOracle.sol +32 -0
  20. package/contracts/oracles/mocks/MockTwapOracle.sol +31 -0
  21. package/contracts/test/AccessControlManager.sol +6 -0
  22. package/contracts/test/BEP20Harness.sol +16 -0
  23. package/contracts/test/MockPyth.sol +123 -0
  24. package/contracts/test/MockSimpleOracle.sol +41 -0
  25. package/contracts/test/MockV3Aggregator.sol +76 -0
  26. package/contracts/test/PancakePairHarness.sol +90 -0
  27. package/contracts/test/VBEP20Harness.sol +20 -0
  28. package/deploy/1-deploy-oracles.ts +195 -0
  29. package/deploy/2-configure-feeds.ts +324 -0
  30. package/deployments/.gitkeep +0 -0
  31. package/deployments/bscmainnet/.chainId +1 -0
  32. package/deployments/bscmainnet/BinanceOracle.json +329 -0
  33. package/deployments/bscmainnet/BinanceOracle_Implementation.json +259 -0
  34. package/deployments/bscmainnet/BinanceOracle_Proxy.json +227 -0
  35. package/deployments/bscmainnet/BoundValidator.json +621 -0
  36. package/deployments/bscmainnet/BoundValidator_Implementation.json +714 -0
  37. package/deployments/bscmainnet/BoundValidator_Proxy.json +251 -0
  38. package/deployments/bscmainnet/ChainlinkOracle.json +683 -0
  39. package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +826 -0
  40. package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +237 -0
  41. package/deployments/bscmainnet/DefaultProxyAdmin.json +257 -0
  42. package/deployments/bscmainnet/PythOracle.json +681 -0
  43. package/deployments/bscmainnet/PythOracle_Implementation.json +798 -0
  44. package/deployments/bscmainnet/PythOracle_Proxy.json +264 -0
  45. package/deployments/bscmainnet/ResilientOracle.json +832 -0
  46. package/deployments/bscmainnet/ResilientOracle_Implementation.json +1047 -0
  47. package/deployments/bscmainnet/ResilientOracle_Proxy.json +237 -0
  48. package/deployments/bscmainnet/TwapOracle.json +900 -0
  49. package/deployments/bscmainnet/TwapOracle_Implementation.json +1124 -0
  50. package/deployments/bscmainnet/TwapOracle_Proxy.json +251 -0
  51. package/deployments/bscmainnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
  52. package/deployments/bscmainnet/solcInputs/68ea814c0d6925581f2bda5deba8ce4a.json +60 -0
  53. package/deployments/bscmainnet/solcInputs/8658c669dade0e9ab80874eab3bf3468.json +117 -0
  54. package/deployments/bsctestnet/.chainId +1 -0
  55. package/deployments/bsctestnet/BinanceOracle.json +571 -0
  56. package/deployments/bsctestnet/BinanceOracle_Implementation.json +629 -0
  57. package/deployments/bsctestnet/BinanceOracle_Proxy.json +251 -0
  58. package/deployments/bsctestnet/BoundValidator.json +621 -0
  59. package/deployments/bsctestnet/BoundValidator_Implementation.json +714 -0
  60. package/deployments/bsctestnet/BoundValidator_Proxy.json +251 -0
  61. package/deployments/bsctestnet/ChainlinkOracle.json +697 -0
  62. package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +826 -0
  63. package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +251 -0
  64. package/deployments/bsctestnet/DefaultProxyAdmin.json +257 -0
  65. package/deployments/bsctestnet/PythOracle.json +681 -0
  66. package/deployments/bsctestnet/PythOracle_Implementation.json +798 -0
  67. package/deployments/bsctestnet/PythOracle_Proxy.json +264 -0
  68. package/deployments/bsctestnet/ResilientOracle.json +846 -0
  69. package/deployments/bsctestnet/ResilientOracle_Implementation.json +1047 -0
  70. package/deployments/bsctestnet/ResilientOracle_Proxy.json +251 -0
  71. package/deployments/bsctestnet/TwapOracle.json +887 -0
  72. package/deployments/bsctestnet/TwapOracle_Implementation.json +1111 -0
  73. package/deployments/bsctestnet/TwapOracle_Proxy.json +251 -0
  74. package/deployments/bsctestnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
  75. package/deployments/bsctestnet/solcInputs/4769dd98af512bf3b6b6504ad0c3bd74.json +78 -0
  76. package/deployments/bsctestnet/solcInputs/f35da22a430a956ee338e720b5898e3d.json +126 -0
  77. package/networks/mainnet.json +1 -0
  78. package/package.json +127 -0
@@ -0,0 +1,76 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol";
5
+
6
+ /**
7
+ * @title MockV3Aggregator
8
+ * @notice Based on the FluxAggregator contract
9
+ * @notice Use this contract when you need to test
10
+ * other contract's ability to read data from an
11
+ * aggregator contract, but how the aggregator got
12
+ * its answer is unimportant
13
+ */
14
+ contract MockV3Aggregator is AggregatorV2V3Interface {
15
+ uint256 public constant version = 0;
16
+
17
+ uint8 public decimals;
18
+ int256 public latestAnswer;
19
+ uint256 public latestTimestamp;
20
+ uint256 public latestRound;
21
+
22
+ mapping(uint256 => int256) public getAnswer;
23
+ mapping(uint256 => uint256) public getTimestamp;
24
+ mapping(uint256 => uint256) private getStartedAt;
25
+
26
+ constructor(uint8 _decimals, int256 _initialAnswer) {
27
+ decimals = _decimals;
28
+ updateAnswer(_initialAnswer);
29
+ }
30
+
31
+ function getRoundData(
32
+ uint80 _roundId
33
+ )
34
+ external
35
+ view
36
+ returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
37
+ {
38
+ return (_roundId, getAnswer[_roundId], getStartedAt[_roundId], getTimestamp[_roundId], _roundId);
39
+ }
40
+
41
+ function latestRoundData()
42
+ external
43
+ view
44
+ returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
45
+ {
46
+ return (
47
+ uint80(latestRound),
48
+ getAnswer[latestRound],
49
+ getStartedAt[latestRound],
50
+ getTimestamp[latestRound],
51
+ uint80(latestRound)
52
+ );
53
+ }
54
+
55
+ function description() external pure returns (string memory) {
56
+ return "v0.6/tests/MockV3Aggregator.sol";
57
+ }
58
+
59
+ function updateAnswer(int256 _answer) public {
60
+ latestAnswer = _answer;
61
+ latestTimestamp = block.timestamp;
62
+ latestRound++;
63
+ getAnswer[latestRound] = _answer;
64
+ getTimestamp[latestRound] = block.timestamp;
65
+ getStartedAt[latestRound] = block.timestamp;
66
+ }
67
+
68
+ function updateRoundData(uint80 _roundId, int256 _answer, uint256 _timestamp, uint256 _startedAt) public {
69
+ latestRound = _roundId;
70
+ latestAnswer = _answer;
71
+ latestTimestamp = _timestamp;
72
+ getAnswer[latestRound] = _answer;
73
+ getTimestamp[latestRound] = _timestamp;
74
+ getStartedAt[latestRound] = _startedAt;
75
+ }
76
+ }
@@ -0,0 +1,90 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ // a library for performing various math operations
5
+
6
+ library Math {
7
+ function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
8
+ z = x < y ? x : y;
9
+ }
10
+
11
+ // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
12
+ function sqrt(uint256 y) internal pure returns (uint256 z) {
13
+ if (y > 3) {
14
+ z = y;
15
+ uint256 x = y / 2 + 1;
16
+ while (x < z) {
17
+ z = x;
18
+ x = (y / x + x) / 2;
19
+ }
20
+ } else if (y != 0) {
21
+ z = 1;
22
+ }
23
+ }
24
+ }
25
+
26
+ // range: [0, 2**112 - 1]
27
+ // resolution: 1 / 2**112
28
+
29
+ library UQ112x112 {
30
+ //solhint-disable-next-line state-visibility
31
+ uint224 constant Q112 = 2 ** 112;
32
+
33
+ // encode a uint112 as a UQ112x112
34
+ function encode(uint112 y) internal pure returns (uint224 z) {
35
+ z = uint224(y) * Q112; // never overflows
36
+ }
37
+
38
+ // divide a UQ112x112 by a uint112, returning a UQ112x112
39
+ function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
40
+ z = x / uint224(y);
41
+ }
42
+ }
43
+
44
+ contract PancakePairHarness {
45
+ using UQ112x112 for uint224;
46
+
47
+ address public token0;
48
+ address public token1;
49
+
50
+ uint112 private reserve0; // uses single storage slot, accessible via getReserves
51
+ uint112 private reserve1; // uses single storage slot, accessible via getReserves
52
+ uint32 private blockTimestampLast; // uses single storage slot, accessible via getReserves
53
+
54
+ uint256 public price0CumulativeLast;
55
+ uint256 public price1CumulativeLast;
56
+ uint256 public kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event
57
+
58
+ // called once by the factory at time of deployment
59
+ function initialize(address _token0, address _token1) external {
60
+ token0 = _token0;
61
+ token1 = _token1;
62
+ }
63
+
64
+ // update reserves and, on the first call per block, price accumulators
65
+ function update(uint256 balance0, uint256 balance1, uint112 _reserve0, uint112 _reserve1) external {
66
+ require(balance0 <= type(uint112).max && balance1 <= type(uint112).max, "PancakeV2: OVERFLOW");
67
+ uint32 blockTimestamp = uint32(block.timestamp % 2 ** 32);
68
+ unchecked {
69
+ uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
70
+ if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
71
+ // * never overflows, and + overflow is desired
72
+ price0CumulativeLast += uint256(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;
73
+ price1CumulativeLast += uint256(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;
74
+ }
75
+ }
76
+ reserve0 = uint112(balance0);
77
+ reserve1 = uint112(balance1);
78
+ blockTimestampLast = blockTimestamp;
79
+ }
80
+
81
+ function currentBlockTimestamp() external view returns (uint32) {
82
+ return uint32(block.timestamp % 2 ** 32);
83
+ }
84
+
85
+ function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
86
+ _reserve0 = reserve0;
87
+ _reserve1 = reserve1;
88
+ _blockTimestampLast = blockTimestampLast;
89
+ }
90
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+
4
+ import "./BEP20Harness.sol";
5
+
6
+ contract VBEP20Harness is BEP20Harness {
7
+ /**
8
+ * @notice Underlying asset for this VToken
9
+ */
10
+ address public underlying;
11
+
12
+ constructor(
13
+ string memory name_,
14
+ string memory symbol_,
15
+ uint8 decimals,
16
+ address underlying_
17
+ ) BEP20Harness(name_, symbol_, decimals) {
18
+ underlying = underlying_;
19
+ }
20
+ }
@@ -0,0 +1,195 @@
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
+ acm: "0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA",
15
+ timelock: testnetDeployments.Contracts.Timelock,
16
+ },
17
+ bscmainnet: {
18
+ vBNBAddress: mainnetDeployments.Contracts.vBNB,
19
+ WBNBAddress: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
20
+ VAIAddress: mainnetDeployments.Contracts.VAI,
21
+ pythOracleAddress: "0x4D7E825f80bDf85e913E0DD2A2D54927e9dE1594",
22
+ sidRegistryAddress: "0x08CEd32a7f3eeC915Ba84415e9C07a7286977956",
23
+ acm: "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555",
24
+ timelock: mainnetDeployments.Contracts.Timelock,
25
+ },
26
+ };
27
+
28
+ const func: DeployFunction = async function ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) {
29
+ const { deploy } = deployments;
30
+ const { deployer } = await getNamedAccounts();
31
+
32
+ const networkName = network.name === "bscmainnet" ? "bscmainnet" : "bsctestnet";
33
+
34
+ const { vBNBAddress } = ADDRESSES[networkName];
35
+ const { VAIAddress } = ADDRESSES[networkName];
36
+ const { WBNBAddress } = ADDRESSES[networkName];
37
+
38
+ let accessControlManager;
39
+ if (!network.live) {
40
+ await deploy("AccessControlManagerScenario", {
41
+ from: deployer,
42
+ args: [],
43
+ log: true,
44
+ autoMine: true,
45
+ });
46
+
47
+ accessControlManager = await hre.ethers.getContract("AccessControlManagerScenario");
48
+ }
49
+ const accessControlManagerAddress = network.live ? ADDRESSES[networkName].acm : accessControlManager?.address;
50
+ const proxyOwnerAddress = network.live ? ADDRESSES[networkName].timelock : deployer;
51
+
52
+ await deploy("BoundValidator", {
53
+ from: deployer,
54
+ log: true,
55
+ deterministicDeployment: false,
56
+ args: [vBNBAddress, VAIAddress],
57
+ proxy: {
58
+ owner: proxyOwnerAddress,
59
+ proxyContract: "OptimizedTransparentProxy",
60
+ execute: {
61
+ methodName: "initialize",
62
+ args: [accessControlManagerAddress],
63
+ },
64
+ },
65
+ });
66
+
67
+ const boundValidator = await hre.ethers.getContract("BoundValidator");
68
+
69
+ await deploy("ResilientOracle", {
70
+ from: deployer,
71
+ log: true,
72
+ deterministicDeployment: false,
73
+ args: [vBNBAddress, VAIAddress],
74
+ proxy: {
75
+ owner: proxyOwnerAddress,
76
+ proxyContract: "OptimizedTransparentProxy",
77
+ execute: {
78
+ methodName: "initialize",
79
+ args: [boundValidator.address, accessControlManagerAddress],
80
+ },
81
+ },
82
+ });
83
+
84
+ await deploy("ChainlinkOracle", {
85
+ contract: network.live ? "ChainlinkOracle" : "MockChainlinkOracle",
86
+ from: deployer,
87
+ log: true,
88
+ deterministicDeployment: false,
89
+ args: network.live ? [vBNBAddress, VAIAddress] : [],
90
+ proxy: {
91
+ owner: proxyOwnerAddress,
92
+ proxyContract: "OptimizedTransparentProxy",
93
+ execute: {
94
+ methodName: "initialize",
95
+ args: network.live ? [accessControlManagerAddress] : [],
96
+ },
97
+ },
98
+ });
99
+
100
+ await deploy("TwapOracle", {
101
+ contract: network.live ? "TwapOracle" : "MockTwapOracle",
102
+ from: deployer,
103
+ log: true,
104
+ deterministicDeployment: false,
105
+ args: network.live ? [vBNBAddress, WBNBAddress, VAIAddress] : [],
106
+ proxy: {
107
+ owner: proxyOwnerAddress,
108
+ proxyContract: "OptimizedTransparentProxy",
109
+ execute: {
110
+ methodName: "initialize",
111
+ args: network.live ? [accessControlManagerAddress] : [vBNBAddress],
112
+ },
113
+ },
114
+ });
115
+
116
+ const { pythOracleAddress } = ADDRESSES[networkName];
117
+
118
+ await deploy("PythOracle", {
119
+ contract: network.live ? "PythOracle" : "MockPythOracle",
120
+ from: deployer,
121
+ log: true,
122
+ deterministicDeployment: false,
123
+ args: network.live ? [vBNBAddress, VAIAddress] : [],
124
+ proxy: {
125
+ owner: proxyOwnerAddress,
126
+ proxyContract: "OptimizedTransparentProxy",
127
+ execute: {
128
+ methodName: "initialize",
129
+ args: network.live ? [pythOracleAddress, accessControlManagerAddress] : [pythOracleAddress],
130
+ },
131
+ },
132
+ });
133
+
134
+ const { sidRegistryAddress } = ADDRESSES[networkName];
135
+
136
+ await deploy("BinanceOracle", {
137
+ contract: network.live ? "BinanceOracle" : "MockBinanceOracle",
138
+ from: deployer,
139
+ log: true,
140
+ deterministicDeployment: false,
141
+ args: network.live ? [vBNBAddress, VAIAddress] : [],
142
+ proxy: {
143
+ owner: proxyOwnerAddress,
144
+ proxyContract: "OptimizedTransparentProxy",
145
+ execute: {
146
+ methodName: "initialize",
147
+ args: network.live ? [sidRegistryAddress, accessControlManagerAddress] : [],
148
+ },
149
+ },
150
+ });
151
+
152
+ const resilientOracle = await hre.ethers.getContract("ResilientOracle");
153
+ const pythOracle = await hre.ethers.getContract("PythOracle");
154
+ const chainlinkOracle = await hre.ethers.getContract("ChainlinkOracle");
155
+ const binanceOracle = await hre.ethers.getContract("BinanceOracle");
156
+ const twapOracle = await hre.ethers.getContract("TwapOracle");
157
+
158
+ await accessControlManager?.giveCallPermission(chainlinkOracle.address, "setTokenConfig(TokenConfig)", deployer);
159
+ await accessControlManager?.giveCallPermission(pythOracle.address, "setTokenConfig(TokenConfig)", deployer);
160
+ await accessControlManager?.giveCallPermission(resilientOracle.address, "setTokenConfig(TokenConfig)", deployer);
161
+
162
+ const resilientOracleOwner = await resilientOracle.owner();
163
+ const pythOracleOwner = await pythOracle.owner();
164
+ const binanceOracleOwner = await binanceOracle.owner();
165
+ const chainlinkOracleOwner = await chainlinkOracle.owner();
166
+ const twapOracleOwner = await twapOracle.owner();
167
+ const boundValidatorOwner = await boundValidator.owner();
168
+
169
+ if (resilientOracleOwner === deployer) {
170
+ await resilientOracle.transferOwnership(ADDRESSES[networkName].timelock);
171
+ }
172
+
173
+ if (pythOracleOwner === deployer) {
174
+ await pythOracle.transferOwnership(ADDRESSES[networkName].timelock);
175
+ }
176
+
177
+ if (binanceOracleOwner === deployer) {
178
+ await binanceOracle.transferOwnership(ADDRESSES[networkName].timelock);
179
+ }
180
+
181
+ if (chainlinkOracleOwner === deployer) {
182
+ await chainlinkOracle.transferOwnership(ADDRESSES[networkName].timelock);
183
+ }
184
+
185
+ if (twapOracleOwner === deployer) {
186
+ await twapOracle.transferOwnership(ADDRESSES[networkName].timelock);
187
+ }
188
+
189
+ if (boundValidatorOwner === deployer) {
190
+ await boundValidator.transferOwnership(ADDRESSES[networkName].timelock);
191
+ }
192
+ };
193
+
194
+ export default func;
195
+ export const tags = ["deploy"];
@@ -0,0 +1,324 @@
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
+ getStalePeriodConfig?: (asset: Asset) => string[];
31
+ }
32
+
33
+ interface Oracles {
34
+ [key: string]: Oracle;
35
+ }
36
+
37
+ const chainlinkFeed: Config = {
38
+ bsctestnet: {
39
+ BNX: "0xf51492DeD1308Da8195C3bfcCF4a7c70fDbF9daE",
40
+ BTCB: "0x5741306c21795FdCBb9b265Ea0255F499DFe515C",
41
+ TRX: "0x135deD16bFFEB51E01afab45362D3C4be31AA2B0",
42
+ AAVE: "0x298619601ebCd58d0b526963Deb2365B485Edc74",
43
+ MATIC: "0x957Eb0316f02ba4a9De3D308742eefd44a3c1719",
44
+ CAKE: "0x81faeDDfeBc2F8Ac524327d70Cf913001732224C",
45
+ DOGE: "0x963D5e7f285Cc84ed566C486c3c1bC911291be38",
46
+ ADA: "0x5e66a1775BbC249b5D51C13d29245522582E671C",
47
+ BTC: "0x5741306c21795FdCBb9b265Ea0255F499DFe515C",
48
+ XRP: "0x4046332373C24Aed1dC8bAd489A04E187833B28d",
49
+ ETH: "0x143db3CEEfbdfe5631aDD3E50f7614B6ba708BA7",
50
+ XVS: "0xCfA786C17d6739CBC702693F23cA4417B5945491",
51
+ SXP: "0x678AC35ACbcE272651874E782DB5343F9B8a7D66",
52
+ BUSD: "0x9331b55D9830EF609A2aBCfAc0FBCE050A52fdEa",
53
+ USDT: "0xEca2605f0BCF2BA5966372C99837b1F182d3D620",
54
+ USDC: "0x90c069C4538adAc136E051052E14c1cD799C41B7",
55
+ BNB: "0x2514895c72f50D8bd4B4F9b1110F0D6bD2c97526",
56
+ LTC: "0x9Dcf949BCA2F4A8a62350E0065d18902eE87Dca3",
57
+ },
58
+ };
59
+
60
+ const pythID: Config = {
61
+ bsctestnet: {
62
+ AUTO: "0xd954e9a88c7f97b4645b535869aba8a1e50697270a0afb09891accc031f03880",
63
+ },
64
+ };
65
+
66
+ export const assets: Assets = {
67
+ bsctestnet: [
68
+ {
69
+ token: "BNX",
70
+ address: "0xa8062D2bd49D1D2C6376B444bde19402B38938d0",
71
+ oracle: "chainlink",
72
+ price: "159990000000000000000",
73
+ },
74
+ {
75
+ token: "BTCB",
76
+ address: "0xA808e341e8e723DC6BA0Bb5204Bafc2330d7B8e4",
77
+ oracle: "chainlink",
78
+ price: "208000000000000000",
79
+ },
80
+ {
81
+ token: "XVS",
82
+ address: "0xB9e0E753630434d7863528cc73CB7AC638a7c8ff",
83
+ oracle: "binance",
84
+ price: "208000000000000000",
85
+ },
86
+ {
87
+ token: "BUSD",
88
+ address: "0x8301F2213c0eeD49a7E28Ae4c3e91722919B8B47",
89
+ oracle: "binance",
90
+ price: "159990000000000000000",
91
+ },
92
+ {
93
+ token: "ANKR",
94
+ address: "0xe4a90EB942CF2DA7238e8F6cC9EF510c49FC8B4B",
95
+ oracle: "binance",
96
+ price: "159990000000000000000",
97
+ },
98
+ {
99
+ token: "ankrBNB",
100
+ address: "0x167F1F9EF531b3576201aa3146b13c57dbEda514",
101
+ oracle: "binance",
102
+ price: "159990000000000000000",
103
+ },
104
+ {
105
+ token: "MBOX",
106
+ address: "0x523027fFdf9B18Aa652dBcd6B92f885009153dA3",
107
+ oracle: "binance",
108
+ price: "159990000000000000000",
109
+ },
110
+ {
111
+ token: "NFT",
112
+ address: "0xc440e4F21AFc2C3bDBA1Af7D0E338ED35d3e25bA",
113
+ oracle: "binance",
114
+ price: "159990000000000000000",
115
+ },
116
+ {
117
+ token: "RACA",
118
+ address: "0xD60cC803d888A3e743F21D0bdE4bF2cAfdEA1F26",
119
+ oracle: "binance",
120
+ price: "159990000000000000000",
121
+ },
122
+ {
123
+ token: "stkBNB",
124
+ address: "0x2999C176eBf66ecda3a646E70CeB5FF4d5fCFb8C",
125
+ oracle: "binance",
126
+ price: "159990000000000000000",
127
+ },
128
+ {
129
+ token: "USDD",
130
+ address: "0x2E2466e22FcbE0732Be385ee2FBb9C59a1098382",
131
+ oracle: "binance",
132
+ price: "159990000000000000000",
133
+ },
134
+ {
135
+ token: "AUTO",
136
+ address: "0xD9FAc4092e795c26f5F23803FA855A975bfC9973",
137
+ oracle: "pyth",
138
+ price: "159990000000000000000",
139
+ },
140
+ {
141
+ token: "TRX",
142
+ address: "0x7D21841DC10BA1C5797951EFc62fADBBDD06704B",
143
+ oracle: "chainlink",
144
+ price: "159990000000000000000",
145
+ },
146
+ {
147
+ token: "TRX", // OLD TRX
148
+ address: "0x19E7215abF8B2716EE807c9f4b83Af0e7f92653F",
149
+ oracle: "chainlink",
150
+ price: "159990000000000000000",
151
+ },
152
+ {
153
+ token: "AAVE",
154
+ address: "0x4B7268FC7C727B88c5Fc127D41b491BfAe63e144",
155
+ oracle: "chainlink",
156
+ price: "159990000000000000000",
157
+ },
158
+ {
159
+ token: "MATIC",
160
+ address: "0xcfeb0103d4BEfa041EA4c2dACce7B3E83E1aE7E3",
161
+ oracle: "chainlink",
162
+ price: "159990000000000000000",
163
+ },
164
+ {
165
+ token: "CAKE",
166
+ address: "0xe8bd7cCC165FAEb9b81569B05424771B9A20cbEF",
167
+ oracle: "chainlink",
168
+ price: "159990000000000000000",
169
+ },
170
+ {
171
+ token: "DOGE",
172
+ address: "0x67D262CE2b8b846d9B94060BC04DC40a83F0e25B",
173
+ oracle: "chainlink",
174
+ price: "159990000000000000000",
175
+ },
176
+ {
177
+ token: "ADA",
178
+ address: "0xcD34BC54106bd45A04Ed99EBcC2A6a3e70d7210F",
179
+ oracle: "chainlink",
180
+ price: "159990000000000000000",
181
+ },
182
+ {
183
+ token: "XRP",
184
+ address: "0x3022A32fdAdB4f02281E8Fab33e0A6811237aab0",
185
+ oracle: "chainlink",
186
+ price: "159990000000000000000",
187
+ },
188
+ {
189
+ token: "LTC",
190
+ address: "0x969F147B6b8D81f86175de33206A4FD43dF17913",
191
+ oracle: "chainlink",
192
+ price: "159990000000000000000",
193
+ },
194
+ {
195
+ token: "ETH",
196
+ address: "0x98f7A83361F7Ac8765CcEBAB1425da6b341958a7",
197
+ oracle: "chainlink",
198
+ price: "159990000000000000000",
199
+ },
200
+ {
201
+ token: "XVS",
202
+ address: "0xB9e0E753630434d7863528cc73CB7AC638a7c8ff",
203
+ oracle: "chainlink",
204
+ price: "159990000000000000000",
205
+ },
206
+ {
207
+ token: "SXP",
208
+ address: "0x75107940Cf1121232C0559c747A986DEfbc69DA9",
209
+ oracle: "chainlink",
210
+ price: "159990000000000000000",
211
+ },
212
+ {
213
+ token: "USDT",
214
+ address: "0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c",
215
+ oracle: "chainlink",
216
+ price: "159990000000000000000",
217
+ },
218
+ {
219
+ token: "USDC",
220
+ address: "0x16227D60f7a0e586C66B005219dfc887D13C9531",
221
+ oracle: "chainlink",
222
+ price: "159990000000000000000",
223
+ },
224
+ {
225
+ token: "BNB",
226
+ address: "0x2E7222e51c0f6e98610A1543Aa3836E092CDe62c",
227
+ oracle: "chainlink",
228
+ price: "159990000000000000000",
229
+ },
230
+ ],
231
+ };
232
+
233
+ const addr0000 = "0x0000000000000000000000000000000000000000";
234
+ const DEFAULT_STALE_PERIOD = 24 * 60 * 60; // 24 hrs
235
+
236
+ const func: DeployFunction = async function ({ network }: HardhatRuntimeEnvironment) {
237
+ const networkName: string = network.name === "bscmainnet" ? "bscmainnet" : "bsctestnet";
238
+
239
+ const resilientOracle = await hre.ethers.getContract("ResilientOracle");
240
+ const binanceOracle = await hre.ethers.getContract("BinanceOracle");
241
+ const chainlinkOracle = await hre.ethers.getContract("ChainlinkOracle");
242
+ const pythOracle = await hre.ethers.getContract("PythOracle");
243
+
244
+ const oraclesData: Oracles = {
245
+ chainlink: {
246
+ oracles: [chainlinkOracle.address, addr0000, addr0000],
247
+ enableFlagsForOracles: [true, false, false],
248
+ underlyingOracle: chainlinkOracle,
249
+ getTokenConfig: (asset: Asset, name: string) => ({
250
+ asset: asset.address,
251
+ feed: chainlinkFeed[name][asset.token],
252
+ maxStalePeriod: DEFAULT_STALE_PERIOD,
253
+ }),
254
+ },
255
+ binance: {
256
+ oracles: [binanceOracle.address, addr0000, addr0000],
257
+ enableFlagsForOracles: [true, false, false],
258
+ underlyingOracle: binanceOracle,
259
+ getStalePeriodConfig: (asset: Asset) => [asset.token, DEFAULT_STALE_PERIOD.toString()],
260
+ },
261
+ pyth: {
262
+ oracles: [pythOracle.address, addr0000, addr0000],
263
+ enableFlagsForOracles: [true, false, false],
264
+ underlyingOracle: pythOracle,
265
+ getTokenConfig: (asset: Asset, name: string) => ({
266
+ pythId: pythID[name][asset.token],
267
+ asset: asset.address,
268
+ maxStalePeriod: DEFAULT_STALE_PERIOD,
269
+ }),
270
+ },
271
+ };
272
+
273
+ for (const asset of assets[networkName]) {
274
+ const { oracle } = asset;
275
+ console.log(`Configuring ${asset.token}`);
276
+
277
+ if (network.live) {
278
+ console.log(`Configuring ${oracle} oracle for ${asset.token}`);
279
+
280
+ const { getTokenConfig } = oraclesData[oracle];
281
+ if (oraclesData[oracle].underlyingOracle.address !== binanceOracle.address && getTokenConfig !== undefined) {
282
+ const tx = await oraclesData[oracle].underlyingOracle?.setTokenConfig(getTokenConfig(asset, networkName));
283
+ tx.wait(1);
284
+ }
285
+
286
+ const { getStalePeriodConfig } = oraclesData[oracle];
287
+ if (
288
+ oraclesData[oracle].underlyingOracle.address === binanceOracle.address &&
289
+ getStalePeriodConfig !== undefined
290
+ ) {
291
+ const tx = await oraclesData[oracle].underlyingOracle?.setTokenConfig(...getStalePeriodConfig(asset));
292
+ tx.wait(1);
293
+ }
294
+
295
+ console.log(`Configuring resillient oracle for ${asset.token}`);
296
+ const tx = await resilientOracle.setTokenConfig({
297
+ asset: asset.address,
298
+ oracles: oraclesData[oracle].oracles,
299
+ enableFlagsForOracles: oraclesData[oracle].enableFlagsForOracles,
300
+ });
301
+
302
+ await tx.wait(1);
303
+ } else {
304
+ const MockToken = await hre.ethers.getContractFactory("BEP20Harness");
305
+ const mock = await MockToken.deploy(`Mock${asset.token}`, `Mock${asset.token}`, 18);
306
+
307
+ console.log(`Configuring resillient oracle for ${asset.token}`);
308
+ let tx = await resilientOracle.setTokenConfig({
309
+ asset: mock.address,
310
+ oracles: oraclesData[oracle].oracles,
311
+ enableFlagsForOracles: oraclesData[oracle].enableFlagsForOracles,
312
+ });
313
+
314
+ await tx.wait(1);
315
+
316
+ console.log(`Configuring ${oracle} oracle for ${asset.token}`);
317
+ tx = await oraclesData[oracle].underlyingOracle?.setPrice(mock.address, asset.price);
318
+ await tx.wait(1);
319
+ }
320
+ }
321
+ };
322
+
323
+ export default func;
324
+ export const tags = ["configure"];