Native is an infratrusture that supports different kinds of pricing and liquidity models. For pricing models, Native supports both on-chain pricing (AMM) and off-chain pricing (professional market making, PMM). For liquidity source, Native supports private liquidity source (EOA), public liquidity source (liquidty pool contracts).
- Project owner deploys a
NativePool
, decide the pricing model, fee and other pool configs. - Project owner needs to provide liquidity support to the
NativePool
by giving allowance to theNativePool
contract. It can either be project's own treasury EOA wallet, or can by smart contract. Native also provide a variety of liquidity pool contracts to support getting liquidity from community. - Each
NativePool
has a signer. Signer is a wallet to sign on the orders. Only signed order can be executed on Native pools. It's a mean to protect the treasury, especially for off-chain pricing. The signer is created and hosted by Native by default, but project owner can also run their own signer.
- Trader will give allowance to
NativeRouter
and talk to Native off-chain API to get the signed order. (example for calling API can be found here: https://docs.native.org/native-dev) - Native off-chain router will check different liquidity sources, and decide the route by price, and return the signed order. For the hop using off-chain pricing (e.g. PMM pricing model), the off-chain router will get the qutoe from market maker and fill in the amountIn and amountOut in the order and sign it.
- Native employ a feature of widget fee. Authorized partners can register the fee recipient with Native (off-chain). And they can charge a fee from the traders for using their swap widget. The widgetFee signer hosted by Native will sign the order to ensure the authenticity of fee recipient and fee rate.
- With the signed order trader can call
NativeRouter
functionsexactInput
(for multi-hop) orexactInputSingle
(for single hop) to exectue the transaction on-chain. NativeRouter
will decode the order and callNativePool
for Native supported liquidity from projects, or other liquidity sources such as uniswap v3, 1inch, pancakeswap.
NativeRouter.sol
: Receive the order from trader with the 2 functionsexactInput
orexactInputSingle
. Verify the order signature, process the widget fee and call corresponding liquidity source according to the order.ExternalSwapRouterUpgradable.sol
: Implement the external liquidity source thatNativeRouter
could call. Including pancakeswap, uniswapV3 and 1inch.PeripheryPayments.sol
: Include the logic for payment related toNativeRouter
and also wrapping, unwrapping ETH.NativePoolFactory.sol
: Deploy the new NativePool with the configurations usingcreateNewPool
NativePool.sol
: Define the pairs it supports and pricing model it uses.swap
is called byNativeRouter
. Treasury (EOA wallet or smart contract) will need to give allowance to this contract to support the swap.
CME is a liquidity providing system for RFQ providers. It is built on top of the Compound model and existing Native RFQ system. It consists of the following contracts
CreditVault
contract holding user assets, serving as the treasury for aNativePool
instance. It inheritsComptroller
contract from Compound.- A list of LP token contracts
CreditLpToken
that allow liquidity providers to deposit asset to vault, mint LP token that earns the interest from borrowers and RFQ providers open positions fee. It inheritsCErc20
(which inheritsCToken
contract) contract from Compound.
- It has the exact functionalities as Compound
- Liquidity providers interact with LP token contracts to mint, redeem, borrow and repay. The only difference here is that the underlying asset does not lie in LP token contracts, but in
CreditVault
- The interest accrual mechanism for liquidity provider operations are exactly identical as Compound.
- When there's an unhealthy borrowing positions, liquidate function in
CreditVault
is open to anyone to repay the debt and claim the collateral. - Special Note: Besides major tokens, CME powers altcoin trading. For major tokens with reliable oracle prices, the LP token is exactly like Compound with full functionalities. For altcoins, liquidity providers can deposit asset and mint the LP token, the asset could be used by RFQ providers to fill the swap and LP can earn fee. But liquidity provider cannot borrow altcoins, and LP token of altcoins cannot serve as collateral to borrow other tokens.
- The RFQ provider's address would be added to the
NativePool
as a valid signer for RFQ. - When a swapper send swap request to Native off-chain API, Native checks with the RFQ providers for their quote and if they want to fill the order with Credit liquidity. If so, they return the quote and signature. The signature would be verified in
NativePool
. - Native off-chain system verifies the quote and generate the signature for approving borrowing from CME. The signature would be verified in
CreditVault
. - Native API returns the quote and the 2 signatures (1 from RFQ provider, 1 from Native) to the swapper. And swapper calls
NativeRouter
to execute the trade. NativeRouter
process the calldata and callsNativePool
for swapping.NativePool
will verify the signature of the RFQ provider, and transfer the tokens fromCreditVault
to swapper, also send callback toNativeRouter
to transfer tokens from swapper toCreditVault
.- In the end,
NativePool
sends a callback toCreditVault
to account the position change for the RFQ provider. Tokens transfer away fromCreditVault
to swapper would be short position and tokens transferred intoCreditVault
would be long position. All the live positions for the RFQ provider are recorded on-chain. CreditVault
calls the 2 LP tokens involved to update the varibalenetSwapBorrow
. For long postion, the borrow amount decreases (could be negative). For short position, it's the other way round. The update of the borrow amounts would cancel out the change of the actual asset. Thus the exchange rate wouldn't change before and after the trade.
- Native admin has the right to update the RFQ providers' open positions by the fees calculated off-chain.
- After the update, the
netSwapBorrow
of each LP token contract should increase, and the exchange rate for LP token increases.
- RFQ provider can permissionlessly call
repay
function ofCreditVault
to close short positions. The contract transfers asset from RFQ provider to the vault and update the positions. - For settlement request that requires claiming long positions, RFQ provider needs to call Native API with the settlement proposal (how much of short positions to repay, how much of long positions to claim). Native off-chain system would validate the settlement proposal and returns singature.
- RFQ provider calls
settle
function ofCreditVault
to execute the settlement.
- RFQ providers can put in collateral to get more borrowing credit. They mint LP tokens and calls
addCollateral
inCreditVault
to stake the LP tokens to serve as collateral. - When RFQ providers want to remove collateral, they call Native off-chain API. Native system validate that the withdraw amount for RFQ providers doesn't make the open positions default and returns the signature. With the signature the collateral can be withdrawn.
- A whitelist of liquidators can liquidate the RFQ provider's postions if it's unhealthy. It needs the Native off-chain API to do so.