The Ajna protocol is a non-custodial, peer-to-peer, permissionless lending, borrowing and trading system that requires no governance or external price feeds to function.
Kick with deposit reverts due to rounding: calculated unscaled amount to remove from deposit (for amount to debit from deposit to cover bond) could be bigger than actual unscaled amount of deposit (since ceilWdiv is used). This results in tx reverting and kick with deposit failure
Fixed by using floorWdiv and adding extra check for remove amount to be the min of calculated amount and deposit amount. Used floorWmul to round down scaled amount
Applied same fix for remove quote token: round down when calculate scaled amount and round up ( ceilWdiv) unscaled amount to remove. Check the unscaled amount to remove from deposit to not exceed amount in deposit
Added similar protection (make sure amount to remove does not exceed deposit amount) for remove on bucket take
Invariants changes:
set F1 and F2 deviation back to 1e12 (were changed to quote token scale but this lowers deviation to 1 in case of 18 decimals)
Description of change
High level
ceilWdiv
is used). This results in tx reverting and kick with deposit failurefloorWdiv
and adding extra check for remove amount to be the min of calculated amount and deposit amount. UsedfloorWmul
to round down scaled amountceilWdiv
) unscaled amount to remove. Check the unscaled amount to remove from deposit to not exceed amount in depositF1
andF2
deviation back to1e12
(were changed to quote token scale but this lowers deviation to 1 in case of 18 decimals)ceilMul
when computing amount forF3
(since Fenwick change to allow higher debt but lower precision https://github.com/ajna-finance/contracts/pull/857)1e13
, inline withQT1
invariant deviationContract size
Pre Change
Post Change
Gas usage
Pre Change
Post Change