modified 2020-08-27
- break down 2 milestones to 3 milestone with rebase work for stargate
- adjust budget for 3 milestones(no change on total budget)
- add milestone continuation condition and payment timing
- add detailed schedule
The liquidity module lets the Hub to possess complete backend utility-flow of simple AMM(Automated Market Makers) functionality for liquidity providers and swap requestors.
While general structure of the implementation comes from Uniswap, we customize several designs to improve economic incentive system, provide better user experience, and fit in existing Cosmos-SDK environment.
We want to emphasize that B-Harvest's vision on Cosmos Liquidity is not bounded by this liquidity module v1, but we hope to invest our energy fully to maintain, grow, improve and expand utilities in a much longer time scale to provide the best liquidity utility for the entire blockchain ecosystem.
1) Universal Swap Price : All swaps in one batch are executed with one universal swap price
- tx ordering in a block doesn't matter!
2) Max Swap Price : Swap requestors can protect themselves from swap execution with significantly higher price
3) Self-Matched Swap : Self-matched swaps without consuming liquidity pool pay less fee than pool-matched swaps
- better fair-game for swap users
4) Passive Swap : New type of swap which does not consume liquidity from the pool
- providing instant liquidity to the swap market to absorb big swap orders
5) Dynamic Batch Size : Extended period of batch size only when significant swap price movement happens
- gives more time for arbitrageurs to participate with passive swap so that they can absorb big swap orders
- in most cases with non-significant swap price movement, it provides one block execution
6) Alternative Swap Function for Stable vs Stable Pool
LiquidityPool
creation
- Perminssionless
- Unique pool for each token pair
BaseToken
: at least one of the token pair should be an element ofBaseTokenList
PoolCreationPrice
(in Atom) : to create aLiquidityPool
, one needs to payPoolCreationPrice
- Paid Atoms are sent to
LiquidityFund
- Paid Atoms are sent to
PoolToken
creation upon creation of aLiquidityPool
: representing ownership of shares of aLiquidityPool
LiquidityPool
deposit/withdrawal
PoolToken
minting(deposit) and burning(withdrawal)- Transferable
PoolToken
: ownership belongs to thePoolToken
owner
Swap request to a LiquidityPool
- Safety features
MaxSwapPrice
: the swap request cancelled if executable swap price exceedsMaxSwapPrice
MaxSwapPriceAtoB
:MaxSwapPrice
for swap request fromTokenA
toTokenB
MaxSwapPriceBtoA
:MaxSwapPrice
for swap request fromTokenB
toTokenA
MaxSwapAmtPercent
(%) : the swap request failed if requested swap amount exceedsMaxSwapAmtPercent
(%) of theLiquidityPool
amount
Fee
- Swap fee
SwapFeeRate
(%) of total executed swap amounts are payed by all matched swapsLiquidityFeeRate
(%) of total executed swap amounts are payed by the pool-matched swaps- it is accumulated in the
LiquidityPool
where the swap happens
- Pool withdraw fee
PoolWithdrawFeeRate
(%) of total withdrawn pool assets are payed to theLiquidityPool
- this is a spam prevention methods to prevent too frequent deposits/withdrawals
Swap execution : universal swap ratio for all swap requests
- Basic concept
- every swap request seen as a bid/ask limit order with order price
MaxSwapPriceAtoB
- unit swap price
UnitSwapPriceAtoB
: unit swap price of B from AUnitSwapPriceBtoA
: unit swap price of A from BUnitSwapPriceAtoB
= 1/UnitSwapPriceBtoA
- this is our ultimate goal to be calculated in swap execution process
- self-matching
- one side of swap requests will be completely self-matched with the other side of swap requests with
UnitSwapPrice
, which is not calculated yetSelfMatchedSwapAmtTokenA
: total amount of self-matched swap amount inTokenA
SelfMatchedSwapAmtTokenB
: total amount of self-matched swap amount inTokenB
SelfMatchedSwapAmtTokenA
=SelfMatchedSwapAmtTokenB
*UnitSwapPriceBtoA
- remaining swap amount : the remaining swap request amount which is not self-matched
RemainingA
: remaining swap amount ofTokenA
RemainingB
: remaining swap amount ofTokenB
- one side of swap requests will be completely self-matched with the other side of swap requests with
- constant product equation(CDE)
PoolA
*PoolB
= (PoolA
+RemainingA
-RemainingB
*UnitSwapPriceBtoA
) * (PoolB
+RemainingB
-RemainingA
*UnitSwapPriceAtoB
)CDEDev
: deviation between left side and right side of CDE (absolute value)
- pool-matching
- subset of
RemainingA
orRemainingB
are matched by pool from calculatedUnitSwapPriceAtoB
- pool only can match
RemainingA
withMaxSwapPrice
≥UnitSwapPriceAtoB
- pool only can match
RemainingB
withMaxSwapPrice
≥UnitSwapPriceBtoA
- pool only can match
- subset of
- every swap request seen as a bid/ask limit order with order price
- Finding
UnitSwapPriceAtoB
: to findUnitSwapPriceAtoB
which results in smallestCDEDev
- sort swap requests with
UniSwapPriceAtoB
- let
UnitSwapPriceAtoB
=LastSwapPriceAtoB
- calculate
CDEDev
by processing matching with givenUnitSwapPriceAtoB
- let
UnitSwapPriceAtoB
= lowestMaxSwapPriceAtoB
which is higher thanLastSwapPriceAtoB
- calculate
CDEDev
by processing matching with givenUnitSwapPriceAtoB
- if it decreases from 2)
- iterate 3) with next lowest
MaxSwapPriceAtoB
untilCDEDev
increases- final
UnitSwapPriceAtoB
= the lastMaxSwapPriceAtoB
whereCDEDev
decreases - calculate the exact portion of pool-matched amount for the swaps with final
UnitSwapPriceAtoB
so thatCDEDev
becomes zero - done
- final
- iterate 3) with next lowest
- if it increases from 2)
- go to 4)
- if it decreases from 2)
- let
UnitSwapPriceBtoA
= highestMaxSwapPriceAtoB
which is lower thanLastSwapPriceAtoB
- calculate
CDEDev
by processing matching with givenUnitSwapPriceAtoB
- if it decreases from 2)
- iterate 4) with next highest
MaxSwapPriceAtoB
untilCDEDev
increases- final
UnitSwapPriceAtoB
= the lastMaxSwapPriceAtoB
whereCDEDev
decreases - calculate the exact portion of pool-matched amount for the swaps with final
UnitSwapPriceAtoB
so thatCDEDev
becomes zero - done
- final
- iterate 4) with next highest
- if it increases from 2)
UnitSwapPriceAtoB
=LastSwapPriceAtoB
- if it decreases from 2)
- fee deduction
- every self-matched swaps pay
SwapFeeRate
(%) of executed swap amount - every pool-matched swaps pay
SwapFeeRate
(%)+LiquidityFeeRate
(%) of executed swap amount
- swap execution
- all matchable swap requests are executed and unmatched swap requests are removed
- Provides test codes for each unit functionality to be used for verification
- Complete spec documentation of the implementation and its reasoning
- Documents for testing procedure
- A complete mathematical guide documentation which explains whole computation processes
- Provide AiB frontend integration guide documentation for web interface implementation
- Improve codebase to production-level
- Adjust codebase aligned with modified spec during implementation process in Milestone 1
- Rebase codebase to Cosmos-SDK stargate version
- Operate testnets with multiple blockchains to test liquidity module utility with ibc-transfered tokens
- Invite community members on testnets to accelerate debugging process
- Deal with issues and pull requests on the repository from AiB crews or other community members
- Provide simple web interface for entire utility flow testing of liquidity module
- Encourage community to participate on testing via web interface
- Add up and improve documents for spec, testing, and mathematical explanation
- Web interface for liquidity pool deposit/withdraw and swap request
- Keplr integration for signing transactions
- Web explorer to view basic liquidity status and transactions
- To test and find bugs in the liquidity module
- Community efforts to advise joining the testnet to test utilities
- Quickly comply with bugs, issues, PR, and minor fixes for better stability and security
- Organize community discussion channel to discuss about liquidity module enhancement
Passive Swap
- New swap request type "passive" introduced (Original swap requests become "immediate" type)
- Passive swap requests are executable only if there exists remaining available swap requests(immediate or passive)
- passive swap requests entered into passive swap queue when there exists no available swap requests to be matched
- queued passive swap requests will try to be executed for next block
- queued passive swap requests can be canceled from the origin of the order
- passive swap requests do not consume liquidity from liquidity pool
- passive swap requests do not pay swap fee nor liquidity fee
Dynamic Batch Size
- Extended number of blocks for a batch when the swap price changes more than
BatchTriggerPriceChange
(%) - When batch extension happens, orders are accumulated for
ExtendedBatchSize
number of blocks before swap execution
Stable VS Stable Pool
- Different swap price function(constant sum function) and fee rate for stable vs stable pool
Swap tax (Optional, depends on community governace)
SwapTaxRate
(%) of total executed swap amounts are payed and accumulated inLiquidityFund
- Apply new passive swap request option into the web interface
- Allow nano-ledger integration on web interface
- 1st month
- Finalize detail spec document including most core data structures
- Build skeleton codebase and necessary tool functions for liquidity module
- 2nd month
- Build core functions regarding pool deposit/withdraw, swap order, swap execution
- Write mathematical design report which expalains important calculation in liquidity module
- 3rd month
- Testcodes for each core unit functions and write testing guide documentation
- Add minimal frontend interface and write frontend documentation
- Perform testing and debugging, adjust minor modification
- 4th month
- Rebase codebase to Cosmos-SDK Stargate version
- Complete frontend interfaces including CLI,RPC,LCD
- Adjust minor changes in functionalities
- 5th month
- Adjust documentation for spec modification, rebase and additional frontend interfaces
- Operate testnet and comply with issues and bugs
- 6th~10th month
- Upgrade liquidity module with several additional features
- Maintain liquidity module codebase by complying with issues and bugs
Continuous version upgrades for liquidity module
- to improve user experience
- to expand liquidity utilities via IBC
- to come up with more reasonable economic design
Continuous efforts to operate and maintain
- operation and quality management for overall service flow
- continuous efforts for community coordination and governance activities
- Total budget : $95K + $60K + $75K = $230K
- Each milestone can be continued under reasonable quality of deliverable on each milestone
- Each budget is paid upon completion of each milestone
- Period : 3 months
- Participants : 1 spec/doc, 2 backend, 1 UX and frontend support(1 month)
- Cost : $10K/month per person($5K/month for UX and frontend support)
- Budget : 3months * (3pp * $10K) + 1month * (1pp * $5K) = $95K
- Period : 2 months
- Participants : 1 spec/doc, 2 backend
- Cost : $10K/month per person
- Budget : 2months * (3pp * $10K) = $60K
- Period : 5 months
- Participants : 1 spec/doc/community, 2 backend
- Cost : $5K/month per person
- Budget : 5months * 3pp * $5K = $75K