-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/cantina 0.4 bulk informational #665
Feat/cantina 0.4 bulk informational #665
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint256 maxRedeemableEBTC = EbtcMath._min(vars.remainingEbtcToRedeem, currentCdpDebt); | ||
|
||
uint256 newColl; | ||
uint256 newCollShare; | ||
uint256 _oldIndex = cdpManager.stEthIndex(); | ||
uint256 _newIndex = collateral.getPooledEthByShares(DECIMAL_PRECISION); | ||
|
||
if (_oldIndex < _newIndex) { | ||
newColl = _getCollateralWithSplitFeeApplied(vars.currentCdpId, _newIndex, _oldIndex); | ||
newCollShare = _getCollateralWithSplitFeeApplied( | ||
vars.currentCdpId, | ||
_newIndex, | ||
_oldIndex | ||
); | ||
} else { | ||
(, newColl, ) = cdpManager.getDebtAndCollShares(vars.currentCdpId); | ||
(, newCollShare, ) = cdpManager.getDebtAndCollShares(vars.currentCdpId); | ||
} | ||
|
||
vars.remainingEbtcToRedeem = vars.remainingEbtcToRedeem - maxRedeemableEBTC; | ||
uint256 collToReceive = collateral.getSharesByPooledEth( | ||
uint256 collShareToReceive = collateral.getSharesByPooledEth( | ||
(maxRedeemableEBTC * DECIMAL_PRECISION) / _price | ||
); | ||
|
||
uint256 _newCollAfter = newColl - collToReceive; | ||
uint256 _newCollShareAfter = newCollShare - collShareToReceive; | ||
return ( | ||
_newCollAfter, | ||
LiquityMath._computeNominalCR(_newCollAfter, currentCdpDebt - maxRedeemableEBTC) | ||
_newCollShareAfter, | ||
EbtcMath._computeNominalCR(_newCollShareAfter, currentCdpDebt - maxRedeemableEBTC) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Way better with the change
@GalloDaSballo we've got to clear out this foundty failure before merging. I'm puzzled at the moment. |
@dapp-whisperer I pushed the fix by adding missing "indexed" keyword to related events |
Breaking Changes
Function Renames
In CdpManager
stEthFeePerUnitIndex
->cdpStEthFeePerUnitIndex
debtRedistributionIndex
→cdpDebtRedistributionIndex
Description:
This issue includes a list of informational issues I have found and noted while reviewing the PR that would merge the Release 0.4 PR into the main branch.
The issues are not sorted by type or files.
Inside
CdpManagerStorage.getICR
currentETH
are not ETH but SHARESagree, simple fix | ✅ fixed
Inside
CdpManagerStorage.getNominalICR
currentETH
are not ETH but SHARESagree, simple fix | ✅ fixed
LiquityMath
_computeNominalCR
and_computeCR
should specify if_coll
isstETH
or shares_computeNominalCR
should be collShares_computeCR
should be stEthBalance✅ fixed
In general, there are other places where the term
collateral
/coll
is used in a mixed way. Sometimes it's aboutstETH
shares, sometimes it's aboutstETH
. I think that the best thing to do is toNot use anymore the term
coll
/collateral
and always usestETH
orstETHShares
Decide which is the collateral and use the other as the secondary term. So, for example, you define that
stETH
is the collateral and so by default when you see the termcoll
you know you are referring tostETH
and everything else that is notcoll
orstETH
should be explicitly defined asstETHShares
Agree, the previous idea was to rename it
collShares
andstEthBalance
These are visually and sonically distinct, clearly separating the concept
My fix would be to apply these two universally throughout the codebase as there are many missed instances
♾️ in progress
missing full-natspec for functions like
_calcSyncedAccounting
,_getSyncedCdpDebtAndRedistribution
and so on (I assume there are more where the natspec miss or is incomplete). Try to fully cover the functions with@notice
,@dev
,@param
and@return
when needed.syncGlobalAccounting
@dev
comment is unfinishedif a grace period starts, it won't be bound to the current value of
recoveryModeGracePeriod
. The caller could callsetGracePeriod
and change the grace period that has already started by making it smaller or bigger. See Governance can to end or extend the grace period even when a grace period is already ongoing #30Consider changing
recoveryModeGracePeriod
torecoveryModeGracePeriodDuration
✅ fixed
Refactor
CdpManagerStorage
to have constants, storage layouts and so on as the first thing and function after (with a proper order). Please follow the Solidity Style guide https://docs.soliditylang.org/en/latest/style-guide.htmlAgree, we will do the style guide pass as a final commit as it’ll make a mess of the diff
⏱️ defer to later commit
In
CdpManagerStorage
stEthFeePerUnitIndex
was more meaningful before (stFeePerUnitcdp
). Now it has lost the information that it's about CDP. Consider changing the name to be a reference to the single CDP index.Agree, changing to
cdpStEthFeePerUnitIndex
(as opposed to
systemStEthFeePerUnitIndex
)✅ fixed
Same thing for
debtRedistributionIndex
inCdpManagerStorage
(not that before was more meaningful). Consider renaming to something that is related to the CDPAgree, changing to
cdpDebtRedistributionIndex
(as opposed to
systemDebtRedistributionIndex
)✅ fixed
In
CdpManagerStorage
lastEBTCDebtErrorRedistribution
has "lost" the_
in the name, butlastETHError_Redistribution
still has it. Use the same naming standard.lastETHError_Redistribution
is vestigal and will be removed✅ fixed
In
CdpManagerStorage
there are multiple occurrences of the variableCdpIdsArrayLength
that is declared with the first letter uppercase. Follow the Solidity style guide and declare it with the first letter lowercase.Agree, uncapitalized to
cdpIdsArrayLength
✅ fixed
In
CdpManagerStorage
use the same order for the input parameters (bothstETH
index) for_syncStEthIndex
and_calcSyncedGlobalAccounting
. In those function, the order is inverted and could cause confusion. Try to always stick with the same order.CdpManagerStorage
getSyncedICR
andgetSyncedTCR
can be declaredexternal
because are not used by any contractAgree, fixed
I would also consider removing the external getTCR() and getICR()
For internal use, we are assuming the state is already synced
For external use, we virtually sync
CdpManagerStorage
getNominalICR
andgetICR
uses the variablecurrentETH
but inside that variable you don't haveETH
orstETH
butstETHShares
returned bygetDebtAndCollShares
. Change the name of the variable accordingly[from @rayeaster : seems invalid, the variable there already remove
ETH
naming]In general, it seems that the name
EBTC
has been replaced in many places with the general term "Debt". For example,getPendingEBTCDebtReward
has been renamedgetPendingRedistributedDebt
. There are still many instances in the whole codebase where variables and functions refer toeBTC
instead ofdebt
(same forstETH
/ETH
forcoll
orcollateral
). Badger should define a very strict standard for the naming convention and apply broadly to the whole codebase. Having a mixture of both creates confusion and could lead to errors.Agree, moving everything to debt
In
CdpManagerStorage
_getPendingRedistributedDebt
explicitly return set or return a value forpendingEBTCDebtReward
because right now theelse
case is not handled and could lead to error/create confusion ✅ fixedIEBTCToken
EBTCTokenBalanceUpdated
event can be removed because it's not used anywhere in the codebase ✅ fixedIn
HintHelpers
_calculateCdpStateAfterPartialRedemption
the variable names should be updated to clarify when they storestETH
orshares
. ✅ fixedIn
LiquidationLibrary
use the same style to declare the revert message. Sometimes they start with "LiquidationLibrary: ", sometimes with "CdpManager:" and sometimes like in_reInsertPartialLiquidation
they do not have the reference to the source at all ✅ fixedAvoid using "magic number"
1e18
inLiquidationLibrary._liquidateIndividualCdpSetupCDPInNormalMode
. UseBaseMath.DECIMAL_PRECISION
. ✅ fixedAvoid using "magic number"
1e18
inLiquidationLibrary._liquidateIndividualCdpSetupCDPInRecoveryMode
. UseBaseMath.DECIMAL_PRECISION
. ✅ fixedIn
LiquidationLibrary
the function is passingstETH shares
and notstETH
to the eventCdpLiquidated
for the parameter_coll
. Please verify that it is implemented as intended ✅ fixed by adding documentIn
LiquidationLibrary
to the eventCdpLiquidated
_premiumToLiquidator
is defined as_cappedColl > _debtToColl ? (_cappedColl - _debtToColl) : 0
where_cappedColl
is calculated ascollateral.getPooledEthByShares(_cappedColPortion + _liquidatorReward)
The
_liquidatorReward
(the reward given to the liquidator as the gas stipend) should be outside the calculation of the_cappedColl
and should be always added to the final value passed to the_premiumToLiquidator
parameter. Here's an example:[from @rayeaster : IMO no change needed, current implementation is expected and discussed in discord channel]
27 .
LiquidationSequencer
does not check if the grace period has passed (if we are in RM). See The liquidation logic is not always using the same requirement when the system is in RM #32✅ fixed by another related PR65428.
LiquidationSequencer
does not perform the same check done inLiquidationLibrary
when we are inRM
. Over there_liquidateIndividualCdpSetup
require that_ICR <= _TCR
instead in the helper_canLiquidateInCurrentMode
check that_icr < _TCR
. See The liquidation logic is not always using the same requirement when the system is in RM #32 ✅ fixed by another related PR654Update the revert message in
LiquidationSequencer
because now they say "LiquidationLibrary:" ✅ fixedImprovement: create a common library for the checks done by
LiquidationSequencer
andLiquidationLibrary
to be sure to implement both of them correctlyIn
LiquidationLibrary
avoid using the direct value of the Cdp Status, use the Enum instead (example_cdpStatus == 1
)[from @rayeaster : seems invalid now, there is no usage of direct integer of Cdp Status in
LiquidationLibrary
]Remove
public
visibility from theMultiCdpGetter
constructor (it's ignored by solidity) ✅ fixedIn
ICdpManagerData
rename thedebtToOffset
attribute of the structLiquidationValues
todebtToBurn
. The current name used is a concept related toLiquity
and could create confusion ineBTC
✅ fixedIn
ICdpManagerData
rename thetotalDebtToOffset
attribute of the structLiquidationTotals
todebtToBurn
. The current name used is a concept related toLiquity
and could create confusion ineBTC
✅ fixedIn
CdpManager.redeemCollateral
therequire(redemptionsPaused == false, ...)
check can be moved at the very beginning of the function to save gas if the redemption process has been paused. ✅ fixedRecommendation from cantina/spearbit:
Badger should consider solving the issues listed in the description section.
The main suggestion would be to:
stETH
andshares
In addition, all references to Liquity should be removed.
This includes the LiquityBase and LiquityMath contract names
✅ fixed