Flux Protocol
Search…
Implementation and Architecture
This section of the whitepaper describes the implementation and architecture of Flux Protocol
Flux Protocol is coded in Solidity, and all Conflux Network accounts can interact with the platform. Flux Protocol provides interfaces to market participants such as borrowers, depositors, and liquidators, etc. Flux Protocol is built on Conflux Network and utilizes ShuttleFlow to interact with cross-chained Ethereum or Bitcoin assets. The advantages of using Conflux blockchain are:
The advantages of using Conflux Network are:
  1. 1.
    The performance of Conflux Network is superior and the transaction fees lower than Ethereum
  2. 2.
    Improved liquidity possibility. E.g. wBTC, imBTC and alike are supplied/ collateralized through fBTC, and enjoy shared liquidity through this method

Money Market

Flux Protocol creates an independent money market for each asset, also known as the lending market. Assets on Flux Protocol are mapped into ERC-777 tokens on Conflux Network: fToken. The borrowers transfer their assets to the contract, and their assets can be converted into fToken; over time, the borrowers can gain fToken interest returns. Table 2 list the initial batch of assets launched by Flux and the corresponding fToken information:
Asset
Type
ctoken (ERC777)
ftoken (ERC777)
BTC
Cross-Chain
cBTC
fBTC
ETH
Cross-Chain
cETH
fETH
USDT
Cross-Chain
cUSDT
fUSDT
DAI
Cross-Chain
cDAI
fDAI
CFX
Conflux native
-
fCFX
FC
Conflux native
-
fFC
Table 2: Initial Lending Assets

Interest Rate

Similar Compound, Flux’ money markets are defined by a pair of current interest rates (supply and borrowing interest rates), which are applicable to all users. Over time, this pair of interest rates will be adjusted once changes in supply and demand take place.
For every money market, every change in interest rates is controlled by the Interest Rate Index. The change of the interest rate is a result of user actions such as supply, withdrawal, borrow, repayment or liquidation of assets. User balance includes accrued interest, which is the ratio of the current interest rate index divided by the interest rate index when the user balance was last updated.
The balance of each account address in the money market is stored as an account checkpoint. The account checkpoint is a Solidity tuple <uint256 borrows, uint256 interestIndex> that describes the interest rate index and the borrowing balance when the account was last updated. The current interest rate index of the money market is also stored globally.
Each time a transaction occurs, the asset's supply interest rate and borrowing interest rate index will be updated to the compound interest from the previous period of the index. The interest is priced at r∗ t during the period of use, and calculated at the interest rate of each period.
Index(a,n)=Index(a,n1)(1+rt)Index_{(a,n)} = Index_{(a,n-1)}*(1+r*t)

Market Exchange Rate

Assets circulate in the money market a, therefore the amount of fToken will continue to grow with market interest. We set the exchange rate of fToken according to market supply and demand, which is the market exchange rate of fToken as well.
ExchangeRatea=(Casha+Borrowsa0.9)/Supplya Exchange Rate_a = (Cash_a + Borrows_a *0.9) / Supply_a
ExchangeRatea=(Casha+Borrowsa0.8)/Supplya Exchange Rate_a = (Cash_a + Borrows_a *0.8) / Supply_a
More borrowings result in a higher market exchange rate when the deposit remains unchanged. The depositor's fToken balance can be exchanged for more assets, and the assets that are exchanged by the fToken balance are the deposit interest. The constant 0.9 is to express the difference between the supply interest and the borrow interest rate of non-stablecoins and that 10% of the borrowing interest is distributed to orz Protocol’s team. The constant 0.8 is to express the difference between the supply interest and the borrow interest rate of stablecoins and that 20% of the borrowing interest is distributed to orz Protocol’s team.
cTokensa=fTokensa/ExchangeRateacTokens_a = fTokens_a / Exchange Rate_a

Supply (Mint)

Any Conflux account can obtain minted fTokens by supplying assets. Once the assets are deposited into the smart contract of the money market, and the number of minted fTokens is equal to the number of the supplied assets divided by its present market exchange rate. There are three types of assets in the Flux Protocol, and there are different ways to supply these assets:
1. Conflux token – CFX:
  • Depositing assets through: function mint() payable
2. Cross-chain assets – cTokens:
  • Supplying assets to the money market contract through: cToken.operatorSend(minter,market,amount,0x0,0x1)
  • Supplying assets from the Ethereum or Bitcoin network to the money market through the ShuttleFlow Protocol. ShuttleFlow mints new cTokens into the smart contract through: cToken.mint(market,amount,minter,"")
3. Non-cross-chain ERC777 assets:
  • Supplying assets to the money market smart contract through: cToken.operatorSend(minter,market,amount,0x0,0x1)
The key steps to process supply function are:
  1. 1.
    Minting new fTokens to minter;
  2. 2.
    Updating minter balance;
  3. 3.
    Updating interest rate model
Please note: the process of repaying ERC777 assets to the money market is not executed via the repayment function, but when ERC777 assets are successfully deposited, the tokensReceived will trigger the repayment function.

Withdraw (Redeem)

Redeem is similar to withdrawal and once the redemption takes place, rights like interest income are no longer entitled to the withdrawer. The redeem function is responsible for transferring assets from the money market to users in exchange for the previously minted fToken. The amount of assets redeemed is equal to the amount of fTokens to be redeemed multiplied by the current exchange rate. The redemption amount must be smaller than the available liquidity of the user account and the available liquidity of the market. There are three types of assets in the Flux protocol, and there are different ways to redeem different assets:
  1. 1.
    Conflux token CFX:
  • Redeem assets to your Conflux address through: function redeem(uint256 ftokens)
  1. 1.
    Cross-chain assets – cTokens (Support redemption to Ethereum or Bitcoin address):
  • Redeem assets to Conflux address through: function redeem(uint256 ftokens)
  • Receiver shall enter Ethereum or Bitcoin address to redeem assets to Ethereum or Bitcoin network: function redeem(uint256 ftokens, address receiver)
  1. 1.
    Non-cross-chain ERC777 assets:
  • Redeem assets to Conflux wallet through: function redeem(uint256 ftokens)
The key steps to process redeem functions are:
  1. 1.
    Transferring ERC777 assets to msg.sender or receiver (through cross-chain system)
  2. 2.
    Burn fToken
  3. 3.
    Updating msg.sender balance
  4. 4.
    Updating interest rate model

Borrow

The borrow function is responsible for transferring the assets from the money market to the users, and creating a borrowing balance that is compounded based on the asset's borrowing rate. The amount of borrowing must be smaller than the user’s borrowing capacity and the market’s available liquidity. The user must maintain the collateral requirement in order to avoid liquidation. Note that the borrower will receive an asset through a transaction, e.g. ETH for the fETH money market. Therefore, the borrower must be repay the same asset.There are three types of assets in the Flux Protocol, and there are different ways to borrow different assets:
  1. 1.
    Conflux token CFX:
  • Borrow assets to Conflux address through: function borrow(uint256 ctokens)
  1. 1.
    Cross-chain assets – cTokens (Supports borrowing assets to Ethereum or Bitcoin address):
  • Borrow assets to Conflux address through: function redeem(uint256 ftokens)
  • Borrow assets to the Ethereum or Bitcoin network, the receiver needs to enter the Ethereum or Bitcoin address through: function borrow(uint256 ctokens, address receiver)
  1. 1.
    Non-cross-chain ERC777 assets:
  • Borrow assets to Conflux wallet: function borrow(uint256 ctokens)
The key steps to process borrowing functions are:
  1. 1.
    Transferring ERC777 assets to msg.sender or receiver (through cross-chain system)
  2. 2.
    Updating interest rate index
  3. 3.
    Updating msg.sender borrowing balance
  4. 4.
    Updating interest rate model

Borrow Repay

The borrower deposits the borrowed assets back to the money market through the repay function to reduce the user's outstanding borrowing. If the borrower's repayment of assets exceeds the actual amount of assets that have been borrowed, the excesses will be credited to the account via deposit. There are three types of assets in the Flux Protocol, and the way to repay the assets is similar to the way of depositing assets:
  1. 1.
    Conflux token CFX:
  • Repay assets through: function repay() payable
  1. 1.
    Cross-chain cTokens:
  • Repay assets to the money market contract, regarding it as repayment by default, through: cToken.operatorSend(borrower,market,amount,0x0,0x0)
  • Repay assets from the Ethereum or Bitcoin network to the money market through the ShuttleFlow. ShuttleFlow mints new cTokens into the borrowing smart contract, regarding it as repayment by default, through: cToken.mint(market,amount,borrower, "")
  1. 1.
    Non-cross-chain ERC777 assets:
  • Transferring assets to the money market through: cToken.operatorSend(borrower,market,amount,0x0,0x0)
The key steps to process repayment functions are:
  1. 1.
    Updating interest rate index;
  2. 2.
    Updating borrower or msg.sender borrowing balance;
  3. 3.
    Updating borrower or msg.sender balance (possibly);
  4. 4.
    Updating interest rate model.
Please note: the process of repaying ERC777 assets to the money market is not executed via the repayment function, but when ERC777 assets are successfully deposited, the tokensReceived will trigger the repayment function.

Borrow Liquidation

Liquidator can repay outstanding borrowing of an account with negative liquidity to restore the liquidity of the borrower's account. Liquidation utilizes the Flux Guardian Smart Contract: Guard. Before the liquidation, Guard will need to be authorized to repay the outstanding borrowings from the liquidators account into the money market
Liquidation function:
function liquidate(address borrower) external
The key steps to process liquidation functions are:
  1. 1.
    Check whether the borrower’s collateral rate is lower than the liquidation collateral rate
  2. 2.
    Repay outstanding borrowings into the money market
  3. 3.
    Update borrower's borrowing outstanding
  4. 4.
    sender will receive the borrower collateral ftoken assets
  5. 5.
    Update interest rate model
Last modified 6mo ago