@venusprotocol/oracle 1.10.0-dev.4 → 1.10.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +1 -1
- package/artifacts/build-info/cdd56e5e725d884c2b45e24d2c35e787.json +1 -0
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/IStETH.sol/IStETH.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +1 -1
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/WstETHOracle.sol/WstETHOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +1 -1
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +1 -1
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
- package/deployments/bscmainnet/solcInputs/aae9f1601b873a5a4704ede73ede10cb.json +0 -3
- package/deployments/bscmainnet/solcInputs/d647123072ba05451b756817f39951df.json +0 -6
- package/deployments/bscmainnet.json +0 -1560
- package/deployments/bscmainnet_addresses.json +1 -4
- package/deployments/bsctestnet/solcInputs/131f58942628e21632de19506977a910.json +0 -3
- package/deployments/bsctestnet/solcInputs/d647123072ba05451b756817f39951df.json +0 -6
- package/deployments/bsctestnet.json +0 -1560
- package/deployments/bsctestnet_addresses.json +1 -4
- package/deployments/ethereum/solcInputs/2675f6933965af498101c80cb5610aca.json +0 -6
- package/deployments/ethereum/solcInputs/61a63fbc062c2591c6768138f59373e1.json +0 -6
- package/deployments/opbnbmainnet/solcInputs/1e37f6e5d619feb70cefe47611ec524e.json +0 -6
- package/deployments/opbnbtestnet/solcInputs/3c996a10e894dc6fe519573ed39fc60f.json +0 -6
- package/deployments/sepolia/solcInputs/61a63fbc062c2591c6768138f59373e1.json +0 -6
- package/deployments/sepolia/solcInputs/f5d4d6aee7a4e630f36ae4eef8377cf3.json +0 -6
- package/dist/deploy/1-deploy-oracles.d.ts.map +1 -1
- package/dist/deploy/1-deploy-oracles.js +0 -24
- package/dist/deploy/1-deploy-oracles.js.map +1 -1
- package/dist/deploy/3-vip-based-configuration.d.ts.map +1 -1
- package/dist/deploy/3-vip-based-configuration.js +0 -1
- package/dist/deploy/3-vip-based-configuration.js.map +1 -1
- package/dist/typechain-types/contracts/index.d.ts +0 -2
- package/dist/typechain-types/contracts/index.d.ts.map +1 -1
- package/dist/typechain-types/contracts/oracles/index.d.ts +0 -1
- package/dist/typechain-types/contracts/oracles/index.d.ts.map +1 -1
- package/dist/typechain-types/contracts/oracles/mocks/index.d.ts +0 -1
- package/dist/typechain-types/contracts/oracles/mocks/index.d.ts.map +1 -1
- package/dist/typechain-types/factories/contracts/index.d.ts +0 -1
- package/dist/typechain-types/factories/contracts/index.d.ts.map +1 -1
- package/dist/typechain-types/factories/contracts/index.js +1 -2
- package/dist/typechain-types/factories/contracts/index.js.map +1 -1
- package/dist/typechain-types/factories/contracts/oracles/index.d.ts +0 -1
- package/dist/typechain-types/factories/contracts/oracles/index.d.ts.map +1 -1
- package/dist/typechain-types/factories/contracts/oracles/index.js +1 -3
- package/dist/typechain-types/factories/contracts/oracles/index.js.map +1 -1
- package/dist/typechain-types/factories/contracts/oracles/mocks/index.d.ts +0 -1
- package/dist/typechain-types/factories/contracts/oracles/mocks/index.d.ts.map +1 -1
- package/dist/typechain-types/factories/contracts/oracles/mocks/index.js +1 -3
- package/dist/typechain-types/factories/contracts/oracles/mocks/index.js.map +1 -1
- package/dist/typechain-types/index.d.ts +0 -6
- package/dist/typechain-types/index.d.ts.map +1 -1
- package/dist/typechain-types/index.js +1 -8
- package/dist/typechain-types/index.js.map +1 -1
- package/package.json +1 -1
- package/artifacts/build-info/1f32e9df7d74fc5f6586169f27f8b186.json +0 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -640
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
- package/contracts/libraries/PancakeLibrary.sol +0 -68
- package/contracts/oracles/TwapOracle.sol +0 -300
- package/contracts/oracles/mocks/MockTwapOracle.sol +0 -30
- package/deployments/bscmainnet/TwapOracle.json +0 -887
- package/deployments/bscmainnet/TwapOracle_Implementation.json +0 -1111
- package/deployments/bscmainnet/TwapOracle_Proxy.json +0 -251
- package/deployments/bsctestnet/TwapOracle.json +0 -887
- package/deployments/bsctestnet/TwapOracle_Implementation.json +0 -1111
- package/deployments/bsctestnet/TwapOracle_Proxy.json +0 -251
- package/dist/typechain-types/contracts/libraries/PancakeLibrary.sol/IPancakePair.d.ts +0 -83
- package/dist/typechain-types/contracts/libraries/PancakeLibrary.sol/IPancakePair.d.ts.map +0 -1
- package/dist/typechain-types/contracts/libraries/PancakeLibrary.sol/IPancakePair.js +0 -3
- package/dist/typechain-types/contracts/libraries/PancakeLibrary.sol/IPancakePair.js.map +0 -1
- package/dist/typechain-types/contracts/libraries/PancakeLibrary.sol/index.d.ts +0 -2
- package/dist/typechain-types/contracts/libraries/PancakeLibrary.sol/index.d.ts.map +0 -1
- package/dist/typechain-types/contracts/libraries/PancakeLibrary.sol/index.js +0 -3
- package/dist/typechain-types/contracts/libraries/PancakeLibrary.sol/index.js.map +0 -1
- package/dist/typechain-types/contracts/libraries/index.d.ts +0 -3
- package/dist/typechain-types/contracts/libraries/index.d.ts.map +0 -1
- package/dist/typechain-types/contracts/libraries/index.js +0 -3
- package/dist/typechain-types/contracts/libraries/index.js.map +0 -1
- package/dist/typechain-types/contracts/oracles/TwapOracle.d.ts +0 -450
- package/dist/typechain-types/contracts/oracles/TwapOracle.d.ts.map +0 -1
- package/dist/typechain-types/contracts/oracles/TwapOracle.js +0 -3
- package/dist/typechain-types/contracts/oracles/TwapOracle.js.map +0 -1
- package/dist/typechain-types/contracts/oracles/mocks/MockTwapOracle.d.ts +0 -155
- package/dist/typechain-types/contracts/oracles/mocks/MockTwapOracle.d.ts.map +0 -1
- package/dist/typechain-types/contracts/oracles/mocks/MockTwapOracle.js +0 -3
- package/dist/typechain-types/contracts/oracles/mocks/MockTwapOracle.js.map +0 -1
- package/dist/typechain-types/factories/contracts/libraries/PancakeLibrary.sol/IPancakePair__factory.d.ts +0 -47
- package/dist/typechain-types/factories/contracts/libraries/PancakeLibrary.sol/IPancakePair__factory.d.ts.map +0 -1
- package/dist/typechain-types/factories/contracts/libraries/PancakeLibrary.sol/IPancakePair__factory.js +0 -66
- package/dist/typechain-types/factories/contracts/libraries/PancakeLibrary.sol/IPancakePair__factory.js.map +0 -1
- package/dist/typechain-types/factories/contracts/libraries/PancakeLibrary.sol/index.d.ts +0 -2
- package/dist/typechain-types/factories/contracts/libraries/PancakeLibrary.sol/index.d.ts.map +0 -1
- package/dist/typechain-types/factories/contracts/libraries/PancakeLibrary.sol/index.js +0 -6
- package/dist/typechain-types/factories/contracts/libraries/PancakeLibrary.sol/index.js.map +0 -1
- package/dist/typechain-types/factories/contracts/libraries/index.d.ts +0 -2
- package/dist/typechain-types/factories/contracts/libraries/index.d.ts.map +0 -1
- package/dist/typechain-types/factories/contracts/libraries/index.js +0 -28
- package/dist/typechain-types/factories/contracts/libraries/index.js.map +0 -1
- package/dist/typechain-types/factories/contracts/oracles/TwapOracle__factory.d.ts +0 -509
- package/dist/typechain-types/factories/contracts/oracles/TwapOracle__factory.d.ts.map +0 -1
- package/dist/typechain-types/factories/contracts/oracles/TwapOracle__factory.js +0 -669
- package/dist/typechain-types/factories/contracts/oracles/TwapOracle__factory.js.map +0 -1
- package/dist/typechain-types/factories/contracts/oracles/mocks/MockTwapOracle__factory.d.ts +0 -139
- package/dist/typechain-types/factories/contracts/oracles/mocks/MockTwapOracle__factory.d.ts.map +0 -1
- package/dist/typechain-types/factories/contracts/oracles/mocks/MockTwapOracle__factory.js +0 -192
- package/dist/typechain-types/factories/contracts/oracles/mocks/MockTwapOracle__factory.js.map +0 -1
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"_format": "hh-sol-artifact-1",
|
|
3
|
-
"contractName": "MockTwapOracle",
|
|
4
|
-
"sourceName": "contracts/oracles/mocks/MockTwapOracle.sol",
|
|
5
|
-
"abi": [
|
|
6
|
-
{
|
|
7
|
-
"inputs": [],
|
|
8
|
-
"stateMutability": "nonpayable",
|
|
9
|
-
"type": "constructor"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"anonymous": false,
|
|
13
|
-
"inputs": [
|
|
14
|
-
{
|
|
15
|
-
"indexed": false,
|
|
16
|
-
"internalType": "uint8",
|
|
17
|
-
"name": "version",
|
|
18
|
-
"type": "uint8"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"name": "Initialized",
|
|
22
|
-
"type": "event"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"anonymous": false,
|
|
26
|
-
"inputs": [
|
|
27
|
-
{
|
|
28
|
-
"indexed": true,
|
|
29
|
-
"internalType": "address",
|
|
30
|
-
"name": "previousOwner",
|
|
31
|
-
"type": "address"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"indexed": true,
|
|
35
|
-
"internalType": "address",
|
|
36
|
-
"name": "newOwner",
|
|
37
|
-
"type": "address"
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
"name": "OwnershipTransferred",
|
|
41
|
-
"type": "event"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"inputs": [
|
|
45
|
-
{
|
|
46
|
-
"internalType": "address",
|
|
47
|
-
"name": "",
|
|
48
|
-
"type": "address"
|
|
49
|
-
}
|
|
50
|
-
],
|
|
51
|
-
"name": "assetPrices",
|
|
52
|
-
"outputs": [
|
|
53
|
-
{
|
|
54
|
-
"internalType": "uint256",
|
|
55
|
-
"name": "",
|
|
56
|
-
"type": "uint256"
|
|
57
|
-
}
|
|
58
|
-
],
|
|
59
|
-
"stateMutability": "view",
|
|
60
|
-
"type": "function"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"inputs": [
|
|
64
|
-
{
|
|
65
|
-
"internalType": "address",
|
|
66
|
-
"name": "token",
|
|
67
|
-
"type": "address"
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
|
-
"name": "getPrice",
|
|
71
|
-
"outputs": [
|
|
72
|
-
{
|
|
73
|
-
"internalType": "uint256",
|
|
74
|
-
"name": "",
|
|
75
|
-
"type": "uint256"
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
"stateMutability": "view",
|
|
79
|
-
"type": "function"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"inputs": [
|
|
83
|
-
{
|
|
84
|
-
"internalType": "address",
|
|
85
|
-
"name": "vBNB_",
|
|
86
|
-
"type": "address"
|
|
87
|
-
}
|
|
88
|
-
],
|
|
89
|
-
"name": "initialize",
|
|
90
|
-
"outputs": [],
|
|
91
|
-
"stateMutability": "nonpayable",
|
|
92
|
-
"type": "function"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"inputs": [],
|
|
96
|
-
"name": "owner",
|
|
97
|
-
"outputs": [
|
|
98
|
-
{
|
|
99
|
-
"internalType": "address",
|
|
100
|
-
"name": "",
|
|
101
|
-
"type": "address"
|
|
102
|
-
}
|
|
103
|
-
],
|
|
104
|
-
"stateMutability": "view",
|
|
105
|
-
"type": "function"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
"inputs": [],
|
|
109
|
-
"name": "renounceOwnership",
|
|
110
|
-
"outputs": [],
|
|
111
|
-
"stateMutability": "nonpayable",
|
|
112
|
-
"type": "function"
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
"inputs": [
|
|
116
|
-
{
|
|
117
|
-
"internalType": "address",
|
|
118
|
-
"name": "asset",
|
|
119
|
-
"type": "address"
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"internalType": "uint256",
|
|
123
|
-
"name": "price",
|
|
124
|
-
"type": "uint256"
|
|
125
|
-
}
|
|
126
|
-
],
|
|
127
|
-
"name": "setPrice",
|
|
128
|
-
"outputs": [],
|
|
129
|
-
"stateMutability": "nonpayable",
|
|
130
|
-
"type": "function"
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
"inputs": [
|
|
134
|
-
{
|
|
135
|
-
"internalType": "address",
|
|
136
|
-
"name": "newOwner",
|
|
137
|
-
"type": "address"
|
|
138
|
-
}
|
|
139
|
-
],
|
|
140
|
-
"name": "transferOwnership",
|
|
141
|
-
"outputs": [],
|
|
142
|
-
"stateMutability": "nonpayable",
|
|
143
|
-
"type": "function"
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
"inputs": [],
|
|
147
|
-
"name": "vBNB",
|
|
148
|
-
"outputs": [
|
|
149
|
-
{
|
|
150
|
-
"internalType": "address",
|
|
151
|
-
"name": "",
|
|
152
|
-
"type": "address"
|
|
153
|
-
}
|
|
154
|
-
],
|
|
155
|
-
"stateMutability": "view",
|
|
156
|
-
"type": "function"
|
|
157
|
-
}
|
|
158
|
-
],
|
|
159
|
-
"bytecode": "0x608060405234801561001057600080fd5b50610678806100206000396000f3fe608060405234801561001057600080fd5b50600436106100875760003560e01c8063715018a61161005b578063715018a6146101375780638da5cb5b1461013f578063c4d66de814610150578063f2fde38b1461016357600080fd5b8062e4768b1461008c57806333e1567f146100b857806341976e09146100e15780635e9a523c14610117575b600080fd5b6100b661009a3660046103f7565b6001600160a01b03909116600090815260656020526040902055565b005b6066546100cb906001600160a01b031681565b6040516100d89190610443565b60405180910390f35b61010a6100ef366004610451565b6001600160a01b031660009081526065602052604090205490565b6040516100d89190610480565b61010a610125366004610451565b60656020526000908152604090205481565b6100b6610176565b6033546001600160a01b03166100cb565b6100b661015e366004610451565b61018a565b6100b6610171366004610451565b6102a4565b61017e6102de565b6101886000610308565b565b600054610100900460ff16158080156101aa5750600054600160ff909116105b806101c45750303b1580156101c4575060005460ff166001145b6101e95760405162461bcd60e51b81526004016101e0906104dc565b60405180910390fd5b6000805460ff19166001179055801561020c576000805461ff0019166101001790555b61021461035a565b6001600160a01b03821661023a5760405162461bcd60e51b81526004016101e090610523565b606680546001600160a01b0319166001600160a01b03841617905580156102a0576000805461ff00191690556040517f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989061029790600190610547565b60405180910390a15b5050565b6102ac6102de565b6001600160a01b0381166102d25760405162461bcd60e51b81526004016101e090610598565b6102db81610308565b50565b6033546001600160a01b031633146101885760405162461bcd60e51b81526004016101e0906105da565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff166103815760405162461bcd60e51b81526004016101e090610632565b610188600054610100900460ff166103ab5760405162461bcd60e51b81526004016101e090610632565b61018833610308565b60006001600160a01b0382165b92915050565b6103d0816103b4565b81146102db57600080fd5b80356103c1816103c7565b806103d0565b80356103c1816103e6565b6000806040838503121561040d5761040d600080fd5b600061041985856103db565b925050602061042a858286016103ec565b9150509250929050565b61043d816103b4565b82525050565b602081016103c18284610434565b60006020828403121561046657610466600080fd5b600061047284846103db565b949350505050565b8061043d565b602081016103c1828461047a565b602e81526000602082017f496e697469616c697a61626c653a20636f6e747261637420697320616c72656181526d191e481a5b9a5d1a585b1a5e995960921b602082015291505b5060400190565b602080825281016103c18161048e565b601a81526000602082017f76424e422063616e2774206265207a65726f2061646472657373000000000000815291505b5060200190565b602080825281016103c1816104ec565b600060ff82166103c1565b61043d81610533565b602081016103c1828461053e565b602681526000602082017f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206181526564647265737360d01b602082015291506104d5565b602080825281016103c181610555565b60208082527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65729101908152600061051c565b602080825281016103c1816105a8565b602b81526000602082017f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206981526a6e697469616c697a696e6760a81b602082015291506104d5565b602080825281016103c1816105ea56fea26469706673582212202796c88d47c4076db5ae533beb125776d9fc10487c1f6bd2050296994e300cef64736f6c634300080d0033",
|
|
160
|
-
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100875760003560e01c8063715018a61161005b578063715018a6146101375780638da5cb5b1461013f578063c4d66de814610150578063f2fde38b1461016357600080fd5b8062e4768b1461008c57806333e1567f146100b857806341976e09146100e15780635e9a523c14610117575b600080fd5b6100b661009a3660046103f7565b6001600160a01b03909116600090815260656020526040902055565b005b6066546100cb906001600160a01b031681565b6040516100d89190610443565b60405180910390f35b61010a6100ef366004610451565b6001600160a01b031660009081526065602052604090205490565b6040516100d89190610480565b61010a610125366004610451565b60656020526000908152604090205481565b6100b6610176565b6033546001600160a01b03166100cb565b6100b661015e366004610451565b61018a565b6100b6610171366004610451565b6102a4565b61017e6102de565b6101886000610308565b565b600054610100900460ff16158080156101aa5750600054600160ff909116105b806101c45750303b1580156101c4575060005460ff166001145b6101e95760405162461bcd60e51b81526004016101e0906104dc565b60405180910390fd5b6000805460ff19166001179055801561020c576000805461ff0019166101001790555b61021461035a565b6001600160a01b03821661023a5760405162461bcd60e51b81526004016101e090610523565b606680546001600160a01b0319166001600160a01b03841617905580156102a0576000805461ff00191690556040517f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989061029790600190610547565b60405180910390a15b5050565b6102ac6102de565b6001600160a01b0381166102d25760405162461bcd60e51b81526004016101e090610598565b6102db81610308565b50565b6033546001600160a01b031633146101885760405162461bcd60e51b81526004016101e0906105da565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff166103815760405162461bcd60e51b81526004016101e090610632565b610188600054610100900460ff166103ab5760405162461bcd60e51b81526004016101e090610632565b61018833610308565b60006001600160a01b0382165b92915050565b6103d0816103b4565b81146102db57600080fd5b80356103c1816103c7565b806103d0565b80356103c1816103e6565b6000806040838503121561040d5761040d600080fd5b600061041985856103db565b925050602061042a858286016103ec565b9150509250929050565b61043d816103b4565b82525050565b602081016103c18284610434565b60006020828403121561046657610466600080fd5b600061047284846103db565b949350505050565b8061043d565b602081016103c1828461047a565b602e81526000602082017f496e697469616c697a61626c653a20636f6e747261637420697320616c72656181526d191e481a5b9a5d1a585b1a5e995960921b602082015291505b5060400190565b602080825281016103c18161048e565b601a81526000602082017f76424e422063616e2774206265207a65726f2061646472657373000000000000815291505b5060200190565b602080825281016103c1816104ec565b600060ff82166103c1565b61043d81610533565b602081016103c1828461053e565b602681526000602082017f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206181526564647265737360d01b602082015291506104d5565b602080825281016103c181610555565b60208082527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65729101908152600061051c565b602080825281016103c1816105a8565b602b81526000602082017f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206981526a6e697469616c697a696e6760a81b602082015291506104d5565b602080825281016103c1816105ea56fea26469706673582212202796c88d47c4076db5ae533beb125776d9fc10487c1f6bd2050296994e300cef64736f6c634300080d0033",
|
|
161
|
-
"linkReferences": {},
|
|
162
|
-
"deployedLinkReferences": {}
|
|
163
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
-
pragma solidity 0.8.13;
|
|
3
|
-
|
|
4
|
-
interface IPancakePair {
|
|
5
|
-
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
|
|
6
|
-
|
|
7
|
-
function price0CumulativeLast() external view returns (uint256);
|
|
8
|
-
|
|
9
|
-
function price1CumulativeLast() external view returns (uint256);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
library FixedPoint {
|
|
13
|
-
// range: [0, 2**112 - 1]
|
|
14
|
-
// resolution: 1 / 2**112
|
|
15
|
-
struct uq112x112 {
|
|
16
|
-
uint224 _x;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// returns a uq112x112 which represents the ratio of the numerator to the denominator
|
|
20
|
-
// equivalent to encode(numerator).div(denominator)
|
|
21
|
-
function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) {
|
|
22
|
-
require(denominator > 0, "FixedPoint: DIV_BY_ZERO");
|
|
23
|
-
return uq112x112((uint224(numerator) << 112) / denominator);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// decode a uq112x112 into a uint with 18 decimals of precision
|
|
27
|
-
function decode112with18(uq112x112 memory self) internal pure returns (uint256) {
|
|
28
|
-
// we only have 256 - 224 = 32 bits to spare, so scaling up by ~60 bits is dangerous
|
|
29
|
-
// instead, get close to:
|
|
30
|
-
// (x * 1e18) >> 112
|
|
31
|
-
// without risk of overflowing, e.g.:
|
|
32
|
-
// (x) / 2 ** (112 - lg(1e18))
|
|
33
|
-
return uint256(self._x) / 5192296858534827;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// library with helper methods for oracles that are concerned with computing average prices
|
|
38
|
-
library PancakeOracleLibrary {
|
|
39
|
-
using FixedPoint for *;
|
|
40
|
-
|
|
41
|
-
// helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1]
|
|
42
|
-
function currentBlockTimestamp() internal view returns (uint32) {
|
|
43
|
-
return uint32(block.timestamp % 2 ** 32);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// produces the cumulative price using counterfactuals to save gas and avoid a call to sync.
|
|
47
|
-
function currentCumulativePrices(
|
|
48
|
-
address pair
|
|
49
|
-
) internal view returns (uint256 price0Cumulative, uint256 price1Cumulative, uint32 blockTimestamp) {
|
|
50
|
-
blockTimestamp = currentBlockTimestamp();
|
|
51
|
-
price0Cumulative = IPancakePair(pair).price0CumulativeLast();
|
|
52
|
-
price1Cumulative = IPancakePair(pair).price1CumulativeLast();
|
|
53
|
-
|
|
54
|
-
// if time has elapsed since the last update on the pair, mock the accumulated price values
|
|
55
|
-
(uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IPancakePair(pair).getReserves();
|
|
56
|
-
if (blockTimestampLast != blockTimestamp) {
|
|
57
|
-
unchecked {
|
|
58
|
-
// subtraction overflow is desired
|
|
59
|
-
uint32 timeElapsed = blockTimestamp - blockTimestampLast;
|
|
60
|
-
// addition overflow is desired
|
|
61
|
-
// counterfactual
|
|
62
|
-
price0Cumulative += uint256(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed;
|
|
63
|
-
// counterfactual
|
|
64
|
-
price1Cumulative += uint256(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
-
pragma solidity 0.8.13;
|
|
3
|
-
|
|
4
|
-
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
5
|
-
import "../libraries/PancakeLibrary.sol";
|
|
6
|
-
import "../interfaces/OracleInterface.sol";
|
|
7
|
-
import "../interfaces/VBep20Interface.sol";
|
|
8
|
-
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @title TwapOracle
|
|
12
|
-
* @author Venus
|
|
13
|
-
* @notice This oracle fetches price of assets from PancakeSwap.
|
|
14
|
-
*/
|
|
15
|
-
contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
16
|
-
using FixedPoint for *;
|
|
17
|
-
|
|
18
|
-
struct Observation {
|
|
19
|
-
uint256 timestamp;
|
|
20
|
-
uint256 acc;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
struct TokenConfig {
|
|
24
|
-
/// @notice Asset address, which can't be zero address and can be used for existance check
|
|
25
|
-
address asset;
|
|
26
|
-
/// @notice Decimals of asset represented as 1e{decimals}
|
|
27
|
-
uint256 baseUnit;
|
|
28
|
-
/// @notice The address of Pancake pair
|
|
29
|
-
address pancakePool;
|
|
30
|
-
/// @notice Whether the token is paired with WBNB
|
|
31
|
-
bool isBnbBased;
|
|
32
|
-
/// @notice A flag identifies whether the Pancake pair is reversed
|
|
33
|
-
/// e.g. XVS-WBNB is reversed, while WBNB-XVS is not.
|
|
34
|
-
bool isReversedPool;
|
|
35
|
-
/// @notice The minimum window in seconds required between TWAP updates
|
|
36
|
-
uint256 anchorPeriod;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
40
|
-
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
41
|
-
|
|
42
|
-
/// @notice WBNB address
|
|
43
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
44
|
-
address public immutable WBNB;
|
|
45
|
-
|
|
46
|
-
/// @notice the base unit of WBNB and BUSD, which are the paired tokens for all assets
|
|
47
|
-
uint256 public constant BNB_BASE_UNIT = 1e18;
|
|
48
|
-
uint256 public constant BUSD_BASE_UNIT = 1e18;
|
|
49
|
-
|
|
50
|
-
/// @notice Configs by token
|
|
51
|
-
mapping(address => TokenConfig) public tokenConfigs;
|
|
52
|
-
|
|
53
|
-
/// @notice Stored price by token
|
|
54
|
-
mapping(address => uint256) public prices;
|
|
55
|
-
|
|
56
|
-
/// @notice Keeps a record of token observations mapped by address, updated on every updateTwap invocation.
|
|
57
|
-
mapping(address => Observation[]) public observations;
|
|
58
|
-
|
|
59
|
-
/// @notice Observation array index which probably falls in current anchor period mapped by asset address
|
|
60
|
-
mapping(address => uint256) public windowStart;
|
|
61
|
-
|
|
62
|
-
/// @notice Emit this event when TWAP window is updated
|
|
63
|
-
event TwapWindowUpdated(
|
|
64
|
-
address indexed asset,
|
|
65
|
-
uint256 oldTimestamp,
|
|
66
|
-
uint256 oldAcc,
|
|
67
|
-
uint256 newTimestamp,
|
|
68
|
-
uint256 newAcc
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
/// @notice Emit this event when TWAP price is updated
|
|
72
|
-
event AnchorPriceUpdated(address indexed asset, uint256 price, uint256 oldTimestamp, uint256 newTimestamp);
|
|
73
|
-
|
|
74
|
-
/// @notice Emit this event when new token configs are added
|
|
75
|
-
event TokenConfigAdded(address indexed asset, address indexed pancakePool, uint256 indexed anchorPeriod);
|
|
76
|
-
|
|
77
|
-
modifier notNullAddress(address someone) {
|
|
78
|
-
if (someone == address(0)) revert("can't be zero address");
|
|
79
|
-
_;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
83
|
-
/// @param wBnbAddress The address of the WBNB
|
|
84
|
-
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
85
|
-
constructor(address wBnbAddress) notNullAddress(wBnbAddress) {
|
|
86
|
-
WBNB = wBnbAddress;
|
|
87
|
-
_disableInitializers();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @notice Initializes the owner of the contract
|
|
92
|
-
* @param accessControlManager_ Address of the access control manager contract
|
|
93
|
-
*/
|
|
94
|
-
function initialize(address accessControlManager_) external initializer {
|
|
95
|
-
__AccessControlled_init(accessControlManager_);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @notice Adds multiple token configs at the same time
|
|
100
|
-
* @param configs Config array
|
|
101
|
-
* @custom:error Zero length error thrown, if length of the config array is 0
|
|
102
|
-
*/
|
|
103
|
-
function setTokenConfigs(TokenConfig[] memory configs) external {
|
|
104
|
-
if (configs.length == 0) revert("length can't be 0");
|
|
105
|
-
uint256 numTokenConfigs = configs.length;
|
|
106
|
-
for (uint256 i; i < numTokenConfigs; ) {
|
|
107
|
-
setTokenConfig(configs[i]);
|
|
108
|
-
unchecked {
|
|
109
|
-
++i;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* @notice Get the TWAP price for the given asset
|
|
116
|
-
* @param asset asset address
|
|
117
|
-
* @return price asset price in USD
|
|
118
|
-
* @custom:error Missing error is thrown if the token config does not exist
|
|
119
|
-
* @custom:error Range error is thrown if TWAP price is not greater than zero
|
|
120
|
-
*/
|
|
121
|
-
function getPrice(address asset) external view override returns (uint256) {
|
|
122
|
-
uint256 decimals;
|
|
123
|
-
|
|
124
|
-
if (asset == BNB_ADDR) {
|
|
125
|
-
decimals = 18;
|
|
126
|
-
asset = WBNB;
|
|
127
|
-
} else {
|
|
128
|
-
IERC20Metadata token = IERC20Metadata(asset);
|
|
129
|
-
decimals = token.decimals();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
|
|
133
|
-
uint256 price = prices[asset];
|
|
134
|
-
|
|
135
|
-
// if price is 0, it means the price hasn't been updated yet and it's meaningless, revert
|
|
136
|
-
if (price == 0) revert("TWAP price must be positive");
|
|
137
|
-
return (price * (10 ** (18 - decimals)));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* @notice Adds a single token config
|
|
142
|
-
* @param config token config struct
|
|
143
|
-
* @custom:access Only Governance
|
|
144
|
-
* @custom:error Range error is thrown if anchor period is not greater than zero
|
|
145
|
-
* @custom:error Range error is thrown if base unit is not greater than zero
|
|
146
|
-
* @custom:error Value error is thrown if base unit decimals is not the same as asset decimals
|
|
147
|
-
* @custom:error NotNullAddress error is thrown if address of asset is null
|
|
148
|
-
* @custom:error NotNullAddress error is thrown if PancakeSwap pool address is null
|
|
149
|
-
* @custom:event Emits TokenConfigAdded event if new token config are added with
|
|
150
|
-
* asset address, PancakePool address, anchor period address
|
|
151
|
-
*/
|
|
152
|
-
function setTokenConfig(
|
|
153
|
-
TokenConfig memory config
|
|
154
|
-
) public notNullAddress(config.asset) notNullAddress(config.pancakePool) {
|
|
155
|
-
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
156
|
-
|
|
157
|
-
if (config.anchorPeriod == 0) revert("anchor period must be positive");
|
|
158
|
-
if (config.baseUnit != 10 ** IERC20Metadata(config.asset).decimals())
|
|
159
|
-
revert("base unit decimals must be same as asset decimals");
|
|
160
|
-
|
|
161
|
-
uint256 cumulativePrice = currentCumulativePrice(config);
|
|
162
|
-
|
|
163
|
-
// Initialize observation data
|
|
164
|
-
observations[config.asset].push(Observation(block.timestamp, cumulativePrice));
|
|
165
|
-
tokenConfigs[config.asset] = config;
|
|
166
|
-
emit TokenConfigAdded(config.asset, config.pancakePool, config.anchorPeriod);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
|
|
171
|
-
* @return anchorPrice anchor price of the asset
|
|
172
|
-
* @custom:error Missing error is thrown if token config does not exist
|
|
173
|
-
*/
|
|
174
|
-
function updateTwap(address asset) public returns (uint256) {
|
|
175
|
-
if (asset == BNB_ADDR) {
|
|
176
|
-
asset = WBNB;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
|
|
180
|
-
// Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
|
|
181
|
-
if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
|
|
182
|
-
if (tokenConfigs[WBNB].asset == address(0)) revert("WBNB not exist");
|
|
183
|
-
_updateTwapInternal(tokenConfigs[WBNB]);
|
|
184
|
-
}
|
|
185
|
-
return _updateTwapInternal(tokenConfigs[asset]);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @notice Fetches the current token/WBNB and token/BUSD price accumulator from PancakeSwap.
|
|
190
|
-
* @return cumulative price of target token regardless of pair order
|
|
191
|
-
*/
|
|
192
|
-
function currentCumulativePrice(TokenConfig memory config) public view returns (uint256) {
|
|
193
|
-
(uint256 price0, uint256 price1, ) = PancakeOracleLibrary.currentCumulativePrices(config.pancakePool);
|
|
194
|
-
if (config.isReversedPool) {
|
|
195
|
-
return price1;
|
|
196
|
-
} else {
|
|
197
|
-
return price0;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @notice Fetches the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
|
|
203
|
-
* @return price Asset price in USD, with 18 decimals
|
|
204
|
-
* @custom:error Timing error is thrown if current time is not greater than old observation timestamp
|
|
205
|
-
* @custom:error Zero price error is thrown if token is BNB based and price is zero
|
|
206
|
-
* @custom:error Zero price error is thrown if fetched anchorPriceMantissa is zero
|
|
207
|
-
* @custom:event Emits AnchorPriceUpdated event on successful update of observation with assset address,
|
|
208
|
-
* AnchorPrice, old observation timestamp and current timestamp
|
|
209
|
-
*/
|
|
210
|
-
function _updateTwapInternal(TokenConfig memory config) private returns (uint256) {
|
|
211
|
-
// pokeWindowValues already handled reversed pool cases,
|
|
212
|
-
// priceAverage will always be Token/BNB or Token/BUSD *twap** price.
|
|
213
|
-
(uint256 nowCumulativePrice, uint256 oldCumulativePrice, uint256 oldTimestamp) = pokeWindowValues(config);
|
|
214
|
-
|
|
215
|
-
if (block.timestamp == oldTimestamp) return prices[config.asset];
|
|
216
|
-
|
|
217
|
-
// This should be impossible, but better safe than sorry
|
|
218
|
-
if (block.timestamp < oldTimestamp) revert("now must come after before");
|
|
219
|
-
|
|
220
|
-
uint256 timeElapsed;
|
|
221
|
-
unchecked {
|
|
222
|
-
timeElapsed = block.timestamp - oldTimestamp;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Calculate Pancake *twap**
|
|
226
|
-
FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112(
|
|
227
|
-
uint224((nowCumulativePrice - oldCumulativePrice) / timeElapsed)
|
|
228
|
-
);
|
|
229
|
-
// *twap** price with 1e18 decimal mantissa
|
|
230
|
-
uint256 priceAverageMantissa = priceAverage.decode112with18();
|
|
231
|
-
|
|
232
|
-
// To cancel the decimals in cumulative price, we need to mulitply the average price with
|
|
233
|
-
// tokenBaseUnit / (BNB_BASE_UNIT or BUSD_BASE_UNIT, which is 1e18)
|
|
234
|
-
uint256 pairedTokenBaseUnit = config.isBnbBased ? BNB_BASE_UNIT : BUSD_BASE_UNIT;
|
|
235
|
-
uint256 anchorPriceMantissa = (priceAverageMantissa * config.baseUnit) / pairedTokenBaseUnit;
|
|
236
|
-
|
|
237
|
-
// if this token is paired with BNB, convert its price to USD
|
|
238
|
-
if (config.isBnbBased) {
|
|
239
|
-
uint256 bnbPrice = prices[WBNB];
|
|
240
|
-
if (bnbPrice == 0) revert("bnb price is invalid");
|
|
241
|
-
anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) / BNB_BASE_UNIT;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (anchorPriceMantissa == 0) revert("twap price cannot be 0");
|
|
245
|
-
|
|
246
|
-
emit AnchorPriceUpdated(config.asset, anchorPriceMantissa, oldTimestamp, block.timestamp);
|
|
247
|
-
|
|
248
|
-
// save anchor price, which is 1e18 decimals
|
|
249
|
-
prices[config.asset] = anchorPriceMantissa;
|
|
250
|
-
|
|
251
|
-
return anchorPriceMantissa;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* @notice Appends current observation and pick an observation with a timestamp equal
|
|
256
|
-
* or just greater than the window start timestamp. If one is not available,
|
|
257
|
-
* then pick the last availableobservation. The window start index is updated in both the cases.
|
|
258
|
-
* Only the current observation is saved, prior observations are deleted during this operation.
|
|
259
|
-
* @return Tuple of cumulative price, old observation and timestamp
|
|
260
|
-
* @custom:event Emits TwapWindowUpdated on successful calculation of cumulative price with asset address,
|
|
261
|
-
* new observation timestamp, current timestamp, new observation price and cumulative price
|
|
262
|
-
*/
|
|
263
|
-
function pokeWindowValues(
|
|
264
|
-
TokenConfig memory config
|
|
265
|
-
) private returns (uint256, uint256 startCumulativePrice, uint256 startCumulativeTimestamp) {
|
|
266
|
-
uint256 cumulativePrice = currentCumulativePrice(config);
|
|
267
|
-
uint256 currentTimestamp = block.timestamp;
|
|
268
|
-
uint256 windowStartTimestamp = currentTimestamp - config.anchorPeriod;
|
|
269
|
-
Observation[] memory storedObservations = observations[config.asset];
|
|
270
|
-
|
|
271
|
-
uint256 storedObservationsLength = storedObservations.length;
|
|
272
|
-
for (uint256 windowStartIndex = windowStart[config.asset]; windowStartIndex < storedObservationsLength; ) {
|
|
273
|
-
if (
|
|
274
|
-
(storedObservations[windowStartIndex].timestamp >= windowStartTimestamp) ||
|
|
275
|
-
(windowStartIndex == storedObservationsLength - 1)
|
|
276
|
-
) {
|
|
277
|
-
startCumulativePrice = storedObservations[windowStartIndex].acc;
|
|
278
|
-
startCumulativeTimestamp = storedObservations[windowStartIndex].timestamp;
|
|
279
|
-
windowStart[config.asset] = windowStartIndex;
|
|
280
|
-
break;
|
|
281
|
-
} else {
|
|
282
|
-
delete observations[config.asset][windowStartIndex];
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
unchecked {
|
|
286
|
-
++windowStartIndex;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
observations[config.asset].push(Observation(currentTimestamp, cumulativePrice));
|
|
291
|
-
emit TwapWindowUpdated(
|
|
292
|
-
config.asset,
|
|
293
|
-
startCumulativeTimestamp,
|
|
294
|
-
startCumulativePrice,
|
|
295
|
-
block.timestamp,
|
|
296
|
-
cumulativePrice
|
|
297
|
-
);
|
|
298
|
-
return (cumulativePrice, startCumulativePrice, startCumulativeTimestamp);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
-
pragma solidity 0.8.13;
|
|
3
|
-
|
|
4
|
-
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
5
|
-
import { OracleInterface } from "../../interfaces/OracleInterface.sol";
|
|
6
|
-
|
|
7
|
-
contract MockTwapOracle is OwnableUpgradeable {
|
|
8
|
-
mapping(address => uint256) public assetPrices;
|
|
9
|
-
|
|
10
|
-
/// @notice vBNB address
|
|
11
|
-
address public vBNB;
|
|
12
|
-
|
|
13
|
-
//set price in 6 decimal precision
|
|
14
|
-
constructor() {}
|
|
15
|
-
|
|
16
|
-
function initialize(address vBNB_) public initializer {
|
|
17
|
-
__Ownable_init();
|
|
18
|
-
if (vBNB_ == address(0)) revert("vBNB can't be zero address");
|
|
19
|
-
vBNB = vBNB_;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function setPrice(address asset, uint256 price) external {
|
|
23
|
-
assetPrices[asset] = price;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//https://compound.finance/docs/prices
|
|
27
|
-
function getPrice(address token) public view returns (uint256) {
|
|
28
|
-
return assetPrices[token];
|
|
29
|
-
}
|
|
30
|
-
}
|