# Introduction to Functionalities
GateBridge provides a cross-chain protocol based on liquidity pool, which redefines the concept of liquidity pool in a more broad sense, with brand new market marking model and unique order book pattern.
# Function Modules
GateBridge is designed a four-layer cross-chain structure:
- Network: GateBridge supports almost all smart chains in the market based on EVM, ensures fast and secure assts transfers between all supported chains.
- Market Liquidity: GateBridge defines the liquidity pool in a broad sense, bringing in Cross-Chain Automated Market Maker role within the cross-chain transfer or swap.
- Settlement: Transactions are settled via smart contracts with the authorisation and signature performed using the private keys, which help to achieve safe, fast and low-cost cross-chain transfers and settlements on a three-layer ledger model.
- Application: GateBrige provides an easy-to-use and intuitive interface to facilitate a better user experience.
# Core Modules
# System Roles
- User: Who use GateBridge to transfer asset cross-chain.
- Relayer: A relayer comprises of multiple nodes, responsible for data transition from one chain to another.
- Liquidity Pool: A series of smart contracts deployed on every smart chain, responsible for asset exchange between chains.
- Ledger: A series of smart contracts deployed on every smart chain, responsible for maintaining the ledger and security of the entire system.
- Liquidity Provider:
- AMMs from different chains and tokens;
- LPs that provides liquidity for the cross-chain liquidity pool.
# Ledger Model
- User Tx Ledger: The ledger for user transactions, which records the user’s operation related to the liquidity pool. User ledger is implemented using smart contracts deployed on smart chains.
- System Ledger: The ledger of the entire cross-chain system, which is a smart contract deployed on the GateChain mainnet, ensuring safety at a minimal maintenance cost.
- Result Ledger: Tx execution result on System Ledger will be sent to every smart chains and execute, the result will be recorded in the LP Ledger, which are deployed on every smart chains.
# Pricing Model
In a cross-chain transfer, the assets exchanged are generally same taken, so a fixed 1:1 price will fits this definition better. Assuming two assets: X and Y, sale dx of X would get dy of Y, at this time $dx = $dy. This can be described as a linear invariant arbitrary amount of asset X, the Constant Sum model:
The asset price in this model can be determined as $dx_i / $dx_j; assuming $dx_i = $dx_j, the price would always be 1, which means all tokens in the pool have the same price. However, this model is unlikely to fit into an exchange market where the assets should be auto-adjustable, one asset reserve in the pair will easily to be drained and the cross-chain transfer would fail. Many well known decentralised exchanges, like Uniswap, or Balancer, are using a Constant Product model instead to allow price volatility according to market conditions. The formula is as below:
The formula can be expanded to a liquidity pool with tokens at any allocation and amount; such as model used in Balancer:
But when model is used to tokens of stable price, it will incur huge slippage. So we look into the pricing model of stableswap, or Hybrid Constant Sum and Constant Product instead, which resembles a constant sum curve when the two tokens reach balance, and a constant product curve when the balance is broken. The slippage in this model looks like a pan, almost zero slippage at the flat bottom, and large slippage as data falling outside of the flat area. See figure below:
The formula of the StableSwap model;
For an asset portfolio
- For small value pool, adding or removing liquidity can easily incur excessive slippage outside of the flat bottom area, causing significant slippage loss.
- For asset that has imbalanced popularities in some chains, the asset amount formats in a pool is likely unfairly allocated, thus causing a drastic price deviation in pools.
To solve these issues, we have improved the Stableswap model:
- When the assets value in a pool under threshold, Constant Sum model is use; Hybrid Constant Sum and Constant Product model is used only when a pre-set threshold is reached.
- When the assets allocation is drastically imbalanced in a pool, the price is limited with upper and lower limits, to ensure a manageable slippage for liquidity provider. When the balance is restored again with arbitragers joining in later, the price will resume.
- When adding liquidity to one side, which enlarge slippage outside the flat bottom area, an extra fee will be charged to offset the slippage loss of LPs in the pool.
# Cross-Chain Transfer Process
# Add Liquidity Example:
- Liquidity Provider Alice wanted to add 100 BTC into the pool on Etheruem. On GateBridge interface, Alice selected Add Liquidity, and then deposite 100 BTC. The User Ledger will add a record that Alice added 100 BTC in the liquidity pool was added.
- Every Relayer monitored that Alice added 100 BTC to the liquidity pool, it would pack this message and other user events, send to System Ledger in GateChain.
- System Ledger will receive the package from relayers, then verify if the package was approved by a certain number of relayers (POA); if yes, then the transactions in the package would be sent to related liquidity pools for computing, BTC pool in this case.
- When the liquidity pool finishes computing, the result would be recorded on System Ledger.
- Relayers detect execution results on the System Ledger, they would pack the computing result and send to certain chain to execute them. Etheruem in this case.
- Result Ledger on Ethereum had received the results from the relayer, it would check the execute result, if succeed, then sent 100 BTC worth LP tokens to Alice; otherwise sent 100 BTC back to Alice.
- The process of removing liquidity is quite similar.
# User Cross-Chain Example:
- Bob wanted to send 10 BTC to BSC from Ethereum, so Bob selected a Cross-Chain Swap on the GateBridge interface, and input 10 BTC. When the operation was successfully done, a record of sending 10 BTC from Ethereum to BSC would be recorded on the User Ledger.
- Relayers monitor Bob's operation, and all relayers would packed this and other user events, send in pack to the System Ledger on GateChain.
- After receiving transactions package from different relayers, the System Ledger verify to see if the package was approved by a certain number of relayers; if yes, then the transactions would be sent to liquidity pools for computing, BTC liquidity pool in this case.
- After the liquidity pool completed calculation, the result would be recorded on the System Ledger.
- When the relayer monitored results of System Ledger, they would pack results and send to object chain for execution: if the result was a success, then the calculation result would be packed and sent to BSC; if failure(the main reason of failure was insufficient liquidity on the BSC, resulting insufficient funds to withdraw 10 BTC), the calculation result would be sent back to the Ethereum.
- If Result Ledger on the BSC received results from the Relayer, then the execution was a success; the 10 BTC less liquidity fee would be sent to Bob;if Result Ledger of the Ethereum received the result, then the execution was a failure, 10 BTC would be returned to Bob.
← GateSwap How to use →