Skip to content

Liquidity Pool

Bette edited this page Oct 22, 2019 · 2 revisions

Introduction

Anyone can implement the LiquidityPoolInterface and deploy their own liquidity pool to participate in the synthetic asset and margin trading protocols.

Liquidity Pool Interface

Get Bid Spread

The getBidSpread function returns the bid spread in percent of this liquidity pool.

function getBidSpread(address fToken) external view returns (uint)
  • fToken: the account for the fToken
  • return: spread in percent e.g. 1 as 1%, return 0 if this fToken is not supported

The bid price is the exchange rate for selling fToken provided by a given liquidity pool.

bidPrice = oraclePrice * (1 - bidSpread)

Get Ask Spread

The getAskSpread function returns the ask spread in percent of this liquidity pool.

function getAskSpread(address fToken) external view returns (uint)
  • fToken: the account for the fToken
  • return: spread in percent e.g. 1 as 1%, return 0 if this fToken is not supported

The ask price is the exchange rate for buying fToken provided by a given liquidity pool.

askPrice = oraclePrice * (1 + askSpread)

Get Additional Collateral Ratio

The getAdditionalCollateralRatio function returns the additional collateral ratio for a fToken. A liquidity pool can set a higher collateral ratio than the fToken default to achieve a higher level of security.

function getAdditionalCollateralRatio(address fToken) external view returns (uint);
  • fToken: the account for the fToken
  • return: the collateral ratio in percent

Liquidity Pool Reference Implementation

Enable fToken

The enableToken function registers a supported fToken.

function enableToken(address token) external onlyOwner

Disable fToken

The disableToken function removes a fToken from supported list.

function disableToken(address token) external onlyOwner 

Add Liquidity

The depositLiquidity functions injects liquidity in base token DAI for the liquidity pool to be used as collaterals.

function depositLiquidity(uint amount) external 

Withdraw Liquidity

The withdrawLiquidity functions allows the liquidity pool owner withdraw excessive liquidity from the pool.

function withdrawLiquidity(uint amount) external onlyOwner

Add Collateral

The addCollateral function increases the collateral of given fToken for given liquidity pool. Liquidity pool owner can use this function to strengthen a fToken position, to rescue a dangerous or liquidating fToken.

function addCollateral(FlowProtocol protocol, FlowToken token, uint baseTokenAmount)
  • token: the account of a fToken, e.g. address of deployed fEUR or fJPY
  • pool: the account of a liquidity pool chosen to add collateral to
  • flowTokenAmount: amount of fToken to exchange

Withdraw Collateral

The addCollateral function withdraws collateral of given fToken for given liquidity pool. Pool owner can use this function to withdraw excessive collateral (when current collateral ratio is higher than required).

function withdrawCollateral(FlowProtocol protocol, FlowToken token)