PairParameterHelper
Last updated
Last updated
Author: Trader Joe
This library contains functions to get and set parameters of a pair The parameters are stored in a single bytes32 variable in the following format: [0 - 16[: base factor (16 bits) [16 - 28[: filter period (12 bits) [28 - 40[: decay period (12 bits) [40 - 54[: reduction factor (14 bits) [54 - 78[: variable fee control (24 bits) [78 - 92[: protocol share (14 bits) [92 - 112[: max volatility accumulator (20 bits) [112 - 132[: volatility accumulator (20 bits) [132 - 152[: volatility reference (20 bits) [152 - 176[: index reference (24 bits) [176 - 216[: time of last update (40 bits) [216 - 232[: oracle index (16 bits) [232 - 256[: active index (24 bits)
Get the base factor from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 16[: base factor (16 bits) [16 - 256[: other parameters
Returns
baseFactor
uint16
The base factor
Get the filter period from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 16[: other parameters [16 - 28[: filter period (12 bits) [28 - 256[: other parameters
Returns
filterPeriod
uint16
The filter period
Get the decay period from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 28[: other parameters [28 - 40[: decay period (12 bits) [40 - 256[: other parameters
Returns
decayPeriod
uint16
The decay period
Get the reduction factor from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 40[: other parameters [40 - 54[: reduction factor (14 bits) [54 - 256[: other parameters
Returns
reductionFactor
uint16
The reduction factor
Get the variable fee control from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 54[: other parameters [54 - 78[: variable fee control (24 bits) [78 - 256[: other parameters
Returns
variableFeeControl
uint24
The variable fee control
Get the protocol share from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 78[: other parameters [78 - 92[: protocol share (14 bits) [92 - 256[: other parameters
Returns
protocolShare
uint16
The protocol share
Get the max volatility accumulator from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 92[: other parameters [92 - 112[: max volatility accumulator (20 bits) [112 - 256[: other parameters
Returns
maxVolatilityAccumulator
uint24
The max volatility accumulator
Get the volatility accumulator from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 112[: other parameters [112 - 132[: volatility accumulator (20 bits) [132 - 256[: other parameters
Returns
volatilityAccumulator
uint24
The volatility accumulator
Get the volatility reference from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 132[: other parameters [132 - 152[: volatility reference (20 bits) [152 - 256[: other parameters
Returns
volatilityReference
uint24
The volatility reference
Get the index reference from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 152[: other parameters [152 - 176[: index reference (24 bits) [176 - 256[: other parameters
Returns
idReference
uint24
The index reference
Get the time of last update from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 176[: other parameters [176 - 216[: time of last update (40 bits) [216 - 256[: other parameters
Returns
timeOflastUpdate
uint40
The time of last update
Get the oracle id from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 216[: other parameters [216 - 232[: oracle id (16 bits) [232 - 256[: other parameters
Returns
oracleId
uint16
The oracle id
Get the active index from the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 232[: other parameters [232 - 256[: active index (24 bits)
Returns
activeId
uint24
The active index
Get the delta between the current active index and the cached active index
Parameters
params
bytes32
The encoded pair parameters, as follows: [0 - 232[: other parameters [232 - 256[: active index (24 bits)
activeId
uint24
The current active index
Returns
<none>
uint24
The delta
Calculates the base fee, with 18 decimals
Parameters
params
bytes32
The encoded pair parameters
binStep
uint16
The bin step (in basis points)
Returns
<none>
uint256
baseFee The base fee
Calculates the variable fee
Parameters
params
bytes32
The encoded pair parameters
binStep
uint16
The bin step (in basis points)
Returns
variableFee
uint256
The variable fee
Calculates the total fee, which is the sum of the base fee and the variable fee
Parameters
params
bytes32
The encoded pair parameters
binStep
uint16
The bin step (in basis points)
Returns
<none>
uint128
totalFee The total fee
Set the oracle id in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
oracleId
uint16
The oracle id
Returns
<none>
bytes32
The updated encoded pair parameters
Set the volatility reference in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
volRef
uint24
The volatility reference
Returns
<none>
bytes32
The updated encoded pair parameters
Set the volatility accumulator in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
volAcc
uint24
The volatility accumulator
Returns
<none>
bytes32
The updated encoded pair parameters
Set the active id in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
activeId
uint24
The active id
Returns
newParams
bytes32
The updated encoded pair parameters
Sets the static fee parameters in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
baseFactor
uint16
The base factor
filterPeriod
uint16
The filter period
decayPeriod
uint16
The decay period
reductionFactor
uint16
The reduction factor
variableFeeControl
uint24
The variable fee control
protocolShare
uint16
The protocol share
maxVolatilityAccumulator
uint24
The max volatility accumulator
Returns
newParams
bytes32
The updated encoded pair parameters
Updates the index reference in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
Returns
newParams
bytes32
The updated encoded pair parameters
Updates the time of last update in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
timestamp
uint256
The timestamp
Returns
newParams
bytes32
The updated encoded pair parameters
Updates the volatility reference in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
Returns
<none>
bytes32
The updated encoded pair parameters
Updates the volatility accumulator in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
activeId
uint24
The active id
Returns
<none>
bytes32
The updated encoded pair parameters
Updates the volatility reference and the volatility accumulator in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
timestamp
uint256
The timestamp
Returns
<none>
bytes32
The updated encoded pair parameters
Updates the volatility reference and the volatility accumulator in the encoded pair parameters
Parameters
params
bytes32
The encoded pair parameters
activeId
uint24
The active id
timestamp
uint256
The timestamp
Returns
<none>
bytes32
The updated encoded pair parameters