Skip to content

Ladle.roll could save money for users by buying fyToken of the old series before maturity #3

Open

Description

@alcueca

Roll buys base to repay debt:

            // 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsmart contracts

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions