IProtocol

liquidityCallback

function liquidityCallback(address token_, uint256 amount_, bytes data_) external

CoreInternals

_supplyOrWithdraw

function _supplyOrWithdraw(address token_, int256 amount_, uint256 supplyExchangePrice_) internal returns (int256 newSupplyInterestRaw_, int256 newSupplyInterestFree_)

_supply or withdraw for both with interest & interest free. positive amount_is deposit, negativeamount* is withdraw.*

_borrowOrPayback

function _borrowOrPayback(address token_, int256 amount_, uint256 borrowExchangePrice_) internal returns (int256 newBorrowInterestRaw_, int256 newBorrowInterestFree_)

_borrow or payback for both with interest & interest free. positive amount_is borrow, negativeamount* is payback.*

_isInOutBalancedOut

function _isInOutBalancedOut(int256 supplyAmount_, address withdrawTo_, address borrowTo_, bytes callbackData_) internal view returns (bool)

_checks if supplyAmount_ & borrowAmount amounts balance themselves out (checked before calling this method):

  • supply(+) == borrow(+), withdraw(-) == payback(-). (DEX protocol use-case)
  • withdrawTo_ / borrowTo_ must be msg.sender (protocol)
  • callbackData_ MUST be encoded so that "from" address is at last 20 bytes (if this optimization is desired), also for native token operations where liquidityCallback is not triggered! from address must come at last position if there is more data. I.e. encode like: abi.encode(otherVar1, otherVar2, FROMADDRESS). Note dynamic types used with abi.encode come at the end so if dynamic types are needed, you must use abi.encodePacked to ensure the from address is at the end.

FluidLiquidityUserModule

Fluid Liquidity public facing endpoint logic contract that implements the operate() method. operate can be used to deposit, withdraw, borrow & payback funds, given that they have the necessary user config allowance. Interacting users must be allowed via the Fluid Liquidity AdminModule first. Intended users are thus allow-listed protocols, e.g. the Lending protocol (fTokens), Vault protocol etc.

For view methods / accessing data, use the "LiquidityResolver" periphery contract.

OperateMemoryVars

struct for vars used in operate() that would otherwise cause a Stack too deep error

struct OperateMemoryVars {
  bool skipTransfers;
  uint256 supplyExchangePrice;
  uint256 borrowExchangePrice;
  uint256 supplyRawInterest;
  uint256 supplyInterestFree;
  uint256 borrowRawInterest;
  uint256 borrowInterestFree;
  uint256 totalAmounts;
  uint256 exchangePricesAndConfig;
}

operate

function operate(address token_, int256 supplyAmount_, int256 borrowAmount_, address withdrawTo_, address borrowTo_, bytes callbackData_) external payable returns (uint256 memVar3_, uint256 memVar4_)

inheritdoc IFluidLiquidity