You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ladle.roll could save money for users by buying fyToken of the old series before maturity #3
// Buy the base required to pay off the debt in series 1, and find out the debt in series 2
newDebt = pool.buyBase(address(baseJoin), base, max);
baseJoin.join(address(baseJoin), base); // Repay the old series debt
Before maturity, it could buy base off the new series pool, and with that base buy fyToken off the old series pool, and roll at more advantageous terms for the user.
// Calculate debt in fyToken terms
uint128 base = oldPool.buyFYTokenPreview(balances.art);
// Mint fyToken to the pool, as a kind of flash loan
fyToken.mint(address(pool), base * loan); // Loan is the size of the flash loan relative to the debt amount, 2 should be safe most of the time
// Buy the base required to pay off the debt in series 1, and find out the debt in series 2
newDebt = pool.buyBase(address(oldPool), base, max);
oldPool.buyFYToken(address(oldFYToken), balances.art); // Buy old fyToken to repay debt
oldFYToken.burn(address(oldFYToken), balances.art); // Old debt is repaid, we will update accounting with the new debt once we calculate the fee
pool.retrieveFYToken(address(fyToken)); // Get the surplus fyToken from the flash loan
fyToken.burn(address(fyToken), (base * loan) - newDebt); // Burn the surplus
Activity