Unit Definition
DYSON.sol
decimals is set to be the number
18uint8 public constant decimals = 18;
sDYSON.sol
decimals is set to be the number
18uint8 public constant decimals = 18;
STAKING_RATE_BASE_UNIT
uint private constant STAKING_RATE_BASE_UNIT = 1e18;In the
sDYSON.solcontract, obtaining the staking rate for staking DYSON in exchange for sDYSON involves adjusting the scale. The staking rate returned bygetStakingRateis scaled at 1e18, and to correct this scale, it needs to be divided bySTAKING_RATE_BASE_UNIT. For instance, when callinggetStakingRatewith 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
int128 private constant MAX_AP_RATIO = 2**64;When using the
_calcRewardAmountfunction in theFarmcontract, the formula is defined as:reward = reserve * (1 - 2^(-amount/w))The result of2^(-amount/w)will be scaled in2**64because theexp_2ofABDKMath64x64library 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_RATIOinstead of1to 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
uint private constant BONUS_BASE_UNIT = 1e18;When utilizing the
grantSPfunction in theFarmcontract, the bonus of the user obtained from theGaugecontract is scaled in1e18, so we useBONUS_BASE_UNITto align the scale during the calculation.
Gauge.sol
REWARD_RATE_BASE_UNIT
uint private constant REWARD_RATE_BASE_UNIT = 1e18;When utilizing the
newRewardRatefunction in theGaugecontract, the formula for the new reward rate is defined as follows:newRewardRate = totalSupply * slope / REWARD_RATE_BASE_UNIT + base;Because thetotalSupplyandslopeare scaled in1e18, we need to divide the result by1e18after the multiplication calculation to maintain the correct scale.
Pair.sol & Router.sol
MAX_FEE_RATIO
uint internal constant MAX_FEE_RATIO = 2**64;When utilizing the
calcNewFeeRatiofunction in thePaircontract, the formula is defined as:newFeeRatio = oldFeeRatio / 2^(elapsedTime / halfLife)The result of2^(elapsedTime / halfLife)will be scaled in2**64because theexp_2ofABDKMath64x64library 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_swap0inor_swap1infunctions, we have to divide the feeRatio byMAX_FEE_RATIOto maintain the correct scale.Similarly, when utilizing the
fairPricefunction in theRoutercontract, it applies the same logic as described above.
Last updated