Skip to content

Commit 80fbf48

Browse files
committed
updated reminder math
1 parent f77ddc5 commit 80fbf48

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

contracts/ACash.sol

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,20 @@ contract PerpetualTranche is ERC20, Initializable, Ownable {
166166
}
167167

168168
uint256 tranchePrice = pricingStrategy.computeTranchePrice(t);
169-
uint256 trancheAmtRequired = (((r.remainder * (10**YIELD_DECIMALS)) / trancheYield) *
169+
// Ie) the tranche amount required for burning the all the remainder
170+
uint256 trancheAmtForRemainder = (((r.remainder * (10**YIELD_DECIMALS)) / trancheYield) *
170171
(10**PRICE_DECIMALS)) / tranchePrice;
171172

172173
// If tranche balance doesn't cover the tranche amount required
173174
// burn the entire tranche balance and continue to the next tranche.
174-
uint256 trancheAmtUsed = (trancheAmtRequired <= trancheBalance) ? trancheAmtRequired : trancheBalance;
175+
uint256 trancheAmtUsed = (trancheAmtForRemainder < trancheBalance) ? trancheAmtForRemainder: trancheBalance;
175176
t.safeTransferFrom(address(this), _msgSender(), trancheAmtUsed);
176177
syncTranche(t);
178+
177179
r.tranches[r.burntTrancheCount] = t;
178180
r.trancheAmts[r.burntTrancheCount] = trancheAmtUsed;
179-
// NOTE we assume that tranche to burnAmt back to tranche will be lossless
180-
// TODO: check numeric stability here.
181-
r.remainder -=
182-
(((trancheAmtUsed * trancheYield) / (10**YIELD_DECIMALS)) * tranchePrice) /
183-
(10**PRICE_DECIMALS);
181+
// NOTE: we assume that tranche to burnAmt back to tranche will be lossless
182+
r.remainder = r.remainder * (trancheAmtForRemainder - trancheAmtUsed) / trancheAmtForRemainder;
184183
r.burntTrancheCount++;
185184
}
186185

0 commit comments

Comments
 (0)