Unit Definition
DYSON.sol
decimals is set to be the number
18
sDYSON.sol
decimals is set to be the number
18
STAKING_RATE_BASE_UNIT
In the
sDYSON.sol
contract, obtaining the staking rate for staking DYSON in exchange for sDYSON involves adjusting the scale. The staking rate returned bygetStakingRate
is scaled at 1e18, and to correct this scale, it needs to be divided bySTAKING_RATE_BASE_UNIT
. For instance, when callinggetStakingRate
with a lock duration of 86400, the returned value might be71087213555991969
. To obtain the accurate staking rate, we perform the division:71087213555991969 / 1e18 = 0.071
. Therefore, the corrected staking rate is7.1%
.
Farm.sol
MAX_AP_RATIO
When using the
_calcRewardAmount
function in theFarm
contract, the formula is defined as:reward = reserve * (1 - 2^(-amount/w))
The result of2^(-amount/w)
will be scaled in2**64
because theexp_2
ofABDKMath64x64
library is used to execute a binary exponent calculation, which returns the result in a 64.64 fixed point number. Therefore, at this point, we useMAX_AP_RATIO
instead of1
to align the scale, resulting in the modified formula:reward = reserve * (MAX_AP_RATIO - 2^(-amount/w))
This adjustment ensures that the scaling is consistent throughout the calculation.
BONUS_BASE_UNIT
When utilizing the
grantSP
function in theFarm
contract, the bonus of the user obtained from theGauge
contract is scaled in1e18
, so we useBONUS_BASE_UNIT
to align the scale during the calculation.
Gauge.sol
REWARD_RATE_BASE_UNIT
When utilizing the
newRewardRate
function in theGauge
contract, the formula for the new reward rate is defined as follows:newRewardRate = totalSupply * slope / REWARD_RATE_BASE_UNIT + base;
Because thetotalSupply
andslope
are scaled in1e18
, we need to divide the result by1e18
after the multiplication calculation to maintain the correct scale.
Pair.sol & Router.sol
MAX_FEE_RATIO
When utilizing the
calcNewFeeRatio
function in thePair
contract, the formula is defined as:newFeeRatio = oldFeeRatio / 2^(elapsedTime / halfLife)
The result of2^(elapsedTime / halfLife)
will be scaled in2**64
because theexp_2
ofABDKMath64x64
library is used to execute a binary exponent calculation, which returns the result in a 64.64 fixed point number. It means that the feeRatio is stored in 2**64 scale. Therefore, when we calculate the swap fee in_swap0in
or_swap1in
functions, we have to divide the feeRatio byMAX_FEE_RATIO
to maintain the correct scale.Similarly, when utilizing the
fairPrice
function in theRouter
contract, it applies the same logic as described above.
Last updated