Giter Club home page Giter Club logo

core-v2's Introduction

gearbox

Gearbox protocol

Gearbox is a generalized leverage protocol: it allows you to take leverage in one place and then use it across various DeFi protocols and platforms in a composable way. The protocol has two sides to it: passive liquidity providers who earn higher APY by providing liquidity to the protocol; and active traders or farmers who can borrow those assets to trade or farm with x4+ leverage.

features

Gearbox aims to enhance capital efficiency in DeFi with the introduction of Credit Accounts - a new primitive for leveraged interactions with other DeFi protocols. Credit Accounts are isolated smart contracts with specific whitelisted actions and assets. Such an architecture ensures a higher degree of safety of both the user funds and the borrowed funds per account, through liquidation of a user's Credit Account portfolio under a certain health factor threshold.

features

Gearbox does not silo the assets within its own platform. Needless to say, your assets never end up in any custody or under anyone’s control. All trades and operations happen on third-party protocols, which could apply to:

  • margin trading on Uniswap;
  • leverage farming on Yearn;
  • arbitraging pegged assets on Curve;
  • using your DAO treasury to optimize the holdings, and more!

The core vision is to become a backend leverage provider which all kinds of users have but don’t even need to interact directly with. You can envision building your own DeFi protocol and just making a “take leverage from Gearbox” as a button.

Gearbox protocol is Marketmake ETHGlobal hackathon finalist.

Twitter https://twitter.com/GearboxProtocol
GitHub https://github.com/Gearbox-Protocol
Discord https://discord.gg/jJuABVH9Pg
Blog: https://medium.com/gearbox-protocol
Website https://gearbox.fi/

Disclaimer

This application is provided "as is" and "with all faults." Me as developer makes no representations or warranties of any kind concerning the safety, suitability, lack of viruses, inaccuracies, typographical errors, or other harmful components of this software. There are inherent dangers in the use of any software, and you are solely responsible for determining whether this software product is compatible with your equipment and other software installed on your equipment. You are also solely responsible for the protection of your equipment and backup of your data, and THE PROVIDER will not be liable for any damages you may suffer in connection with using, modifying, or distributing this software product.

core-v2's People

Contributors

0xmikko avatar apeir99n avatar doomsower avatar l3wi avatar lekhovitsky avatar manylov avatar van0k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

core-v2's Issues

Fair liquidation price

At the moment, credit manager provides liquidation premium = totalValue * liquidationPremium.
For some cases, if account has very valkid assets with low LT (for example 25%), such account could be liquidation and the premium would be unfairly high.

Idea is to change the formula to liquidation premium = min(totalValue; borrowedAmount) * liquidationPremium. At this case, bad accounts will have the same amount, however healthy accs which keep assets in token with low LT would get more fair amount

USDC blacklisting breaks liquidations

Issue:
CreditManager.closeCreditAccount(), which is invoked during liquidations, has the following line:

   // transfer remaining funds to the borrower [liquidations only]
        if (remainingFunds > 1) {
            _safeTokenTransfer(
                creditAccount,
                underlying,
                borrower,
                remainingFunds,
                false
            ); // F:[CM-13,18]
        }

Since this is always executed when there are remaining funds, liquidations on an account will fail if the borrower cannot be transferred to - such as when the borrower is blacklisted by USDC. While the account can be liquidated after some time due to account value dropping relative to borrowed amount (which leads to remainingFunds = 0), this can lead to a temporary freezing of LP funds and break "Expirable" Credit Manager logic used for fixed rate loans.

There are two proposed solutions:

  1. Modify the USDC CreditFacade to check the borrower address being in the blacklist on liquidation. If the borrower is in the blacklist, the CF will transfer the Credit Account to the treasury / a treasury-controlled contract before liquidation - this will send the remaining funds to the treasury, so the borrower can recover them on a different address by contacting the DAO.
  2. Change the CreditManager logic so that the borrower retains their Credit Account after liquidation. Note that the borrower would be able to close their account normally, since they can pass a different recipient address for their USDC. In addition to solving this issue, this has UX benefits. However, this requires updating Credit Managers, which is more disruptive than updating the Credit Facade.

should update pausable admin in acl contract

Hi, I've noticed an issue in the v2.1 of the Dai credit contract. The Credit Facade in this version has not been added as a pauseable admin in the ACL contract. This can be observed in the image linked below:
image
Due to this omission, liquidations cannot proceed without adding the Credit Facade contract (0x5BcB06c56e8F28da0b038a373199240ca3F5a2f4) to the ACL contract.

Additionally, there seems to be an inconsistency in the developer documentation found at https://dev.gearbox.fi/. The Credit Facade address listed there is outdated. Refer to the image for clarification:
image

The correct address should be updated as can be verified on Etherscan. The relevant Etherscan image is included for reference:
image

more detail:

When the cumulative loss from liquidation exceeds the limit, the Credit Facade attempts to pause the credit manager, as detailed in the code snippet from the Credit Facade contract:

if (loss > 0) {
params.isIncreaseDebtForbidden = true; // F: [FA-15A]
lossParams.currentCumulativeLoss += loss.toUint128();
if (
lossParams.currentCumulativeLoss > lossParams.maxCumulativeLoss
) {
_pauseCreditManager(); // F: [FA-15B]
}

However, as mentioned earlier, since the Credit Facade does not have the required permissions, this action results in the failure of the liquidation process.

This issue is evident in the simulation: the _pauseCreditManager() function cannot be executed because the Credit Facade at 0x5BcB06c56e8F28da0b038a373199240ca3F5a2f4 lacks the necessary permissions.
image

Liquidation that breaks the cumulative loss limit will revert if credit manager is paused

Once cumulative loss from liquidation breaks the limit, the credit facade tries to pause the credit manager:

if (loss > 0) {
params.isIncreaseDebtForbidden = true; // F: [FA-15A]
lossParams.currentCumulativeLoss += loss.toUint128();
if (
lossParams.currentCumulativeLoss > lossParams.maxCumulativeLoss
) {
_pauseCreditManager(); // F: [FA-15B]
}

The issue with this is that underlying Pausable implementation doesn't allow to pause an already paused contract: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/ecd2ca2cd7cac116f7a37d0e474bbb3d7d5e1c4d/contracts/security/Pausable.sol#L89

This issue is fixed in V3: https://github.com/Gearbox-protocol/core-v3/blob/main/contracts/credit/CreditFacadeV3.sol#L338-L346

CompositeETHPriceFeed support for WBTC

We plan to suggest the community to use a WBTC price oracle that compose BTC/USD and WBTC/BTC prices.
This is very much in favour to how the current stETH price is implemented.

On first look it seems that the code could be used as is, but a review is needed, and one might consider to change the variable names in order to make it more generic.

CreditFacade is immutable in adapters and is not correctly updated

Issue:
creditFacade is currently only set once in AbstractAdapter in constructor, based on the current Credit Facade attached to the corresponding Credit Manager:

constructor(address _creditManager, address _targetContract) {
        if (_creditManager == address(0) || _targetContract == address(0))
            revert ZeroAddressException(); // F:[AA-2]

        creditManager = ICreditManagerV2(_creditManager); // F:[AA-1]
        creditFacade = ICreditManagerV2(_creditManager).creditFacade(); // F:[AA-1]
        targetContract = _targetContract; // F:[AA-1]
    }

This causes issues when the Credit Facade is updated in the CM, since the adapter no longer recognizes calls from the CF, and performs all health checks, even during a multicall.

Proposed solution:
AbstractAdapter must be updated to retrieve the CreditFacade dynamically from CreditManager each time it is needed, so the current Credit Facade is always recognized. E.g., _fastCheck() would be modified as follows:

    function _fastCheck(
        address creditAccount,
        address tokenIn,
        address tokenOut,
        uint256 balanceInBefore,
        uint256 balanceOutBefore,
        bool disableTokenIn
    ) private {
        address creditFacade = creditManager.creditFacade();
        
        if (msg.sender != creditFacade) {
            creditManager.fastCollateralCheck(
                creditAccount,
                tokenIn,
                tokenOut,
                balanceInBefore,
                balanceOutBefore
            );
        } else {
            if (disableTokenIn)
                creditManager.disableToken(creditAccount, tokenIn);
            creditManager.checkAndEnableToken(creditAccount, tokenOut);
        }
    }

Make pools EIP-4626 compatible

Problem:
Current design requires 2 different contracts for pools: diesel token & pool itself. It's not optimal for gas consumption and do not support modern standards like 4626

Solution:
Combine pool & dieselToken as one contract and make it 4626 compatible

Make credit manager feeToken compartible

Current implementation doesn't take into account how much tokens were sent to pool back, which is okay for current underlying tokens. However, if someone will decide a pool with fee token (for example USDT), it could be a problem, because pool will get less money amountToPool * (1 -fee).

Suggestion: add functionality to CreditManager to be able to work with fee tokens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.