Submitted by 0xA5DF, also found by sseefried
addInterest() always multiplies the interest rate by the time delta, and then multiplies the total borrow amount by the results (newTotalBorrowAmount = interestRate * timeDelta * totalBorrowAmount). This can lead to different interest amounts, depending on how frequently its called.
This will mostly affect custom pairs with stable interest rates (e.g. using linear rate with same min/max/vertex interest) which dont have much activity (e.g. whitelisted borrowers and lenders with long term loan).
The higher the interest rate, the higher the difference will be, for example:
Lenders might end up gaining less interest than expected.
The following test shows a case of 50% annual rate, comparing calling it once in 3 days and only once after a year, the difference would be about 4.5% of the final debt.
At src/test/e2e/BorrowPairTest.t.sol Ive modified _fuzzySetupBorrowToken() to this and then ran source .env && forge test --fork-url $MAINNET_URL --fork-block-number $DEFAULT_FORK_BLOCK -m testFuzzyMaxLTVBorrowToken -vvv.
And Ive also modified src/test/e2e/BasePairTest.sol a bit so that each pair can have a different name for salt (see diff below).
Output:
Also, heres a JS function Ive used to calculate the rate depending on frequency:
Something along these lines (this shouldnt cost much more gas, as its mostly math operations):
DrakeEvans (Frax) acknowledged
