OracleHelper
Last updated
Last updated
Author: Trader Joe
This library contains functions to manage the oracle The oracle samples are stored in a single bytes32 array. Each sample is encoded as follows: 0 - 16: oracle length (16 bits) 16 - 80: cumulative id (64 bits) 80 - 144: cumulative volatility accumulator (64 bits) 144 - 208: cumulative bin crossed (64 bits) 208 - 216: sample lifetime (8 bits) 216 - 256: sample creation timestamp (40 bits)
Modifier to check that the oracle id is valid
Parameters
oracleId
uint16
The oracle id
Returns the sample at the given oracleId
Parameters
oracle
Oracle
The oracle
oracleId
uint16
The oracle id
Returns
sample
bytes32
The sample
Returns the active sample and the active size of the oracle
Parameters
oracle
Oracle
The oracle
oracleId
uint16
The oracle id
Returns
activeSample
bytes32
The active sample
activeSize
uint16
The active size of the oracle
Returns the sample at the given timestamp. If the timestamp is not in the oracle, it returns the closest sample
Parameters
oracle
Oracle
The oracle
oracleId
uint16
The oracle id
lookUpTimestamp
uint40
The timestamp to look up
Returns
lastUpdate
uint40
The last update timestamp
cumulativeId
uint64
The cumulative id
cumulativeVolatility
uint64
The cumulative volatility
cumulativeBinCrossed
uint64
The cumulative bin crossed
Binary search to find the 2 samples surrounding the given timestamp
Parameters
oracle
Oracle
The oracle
oracleId
uint16
The oracle id
lookUpTimestamp
uint40
The timestamp to look up
length
uint16
The oracle length
Returns
<none>
bytes32
prevSample The previous sample
<none>
bytes32
nextSample The next sample
Sets the sample at the given oracleId
Parameters
oracle
Oracle
The oracle
oracleId
uint16
The oracle id
sample
bytes32
The sample
Updates the oracle
Parameters
oracle
Oracle
The oracle
parameters
bytes32
The parameters
activeId
uint24
The active id
Returns
<none>
bytes32
The updated parameters
Increases the oracle length
Parameters
oracle
Oracle
The oracle
oracleId
uint16
The oracle id
newLength
uint16
The new length
Checks that the oracle id is valid
Parameters
oracleId
uint16
The oracle id