follow us on twitter . like us on facebook . follow us on instagram . subscribe to our youtube channel . announcements on telegram channel . ask urgent question ONLY . Subscribe to our reddit . Altcoins Talks Shop Shop


This is an Ad. Advertised sites are not endorsement by our Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise Here Ads bidding Bidding Open

Author Topic: Bonding Curve for Swapping Stablecoins — A Theory Behind Smoothy.finance  (Read 1610 times)

Offline z3r0

  • 1st Step
  • *
  • Activity: 4
  • points:
    260
  • Karma: 0
  • Trade Count: (0)
  • Referrals: 0
  • Last Active: October 28, 2020, 08:06:15 AM
    • View Profile

  • Total Badges: 6
    Badges: (View All)
    First Post Third year Anniversary Second year Anniversary
Short Introduction to Bonding Curve
A bonding curve defines a mathematical relationship between the price of a token and other token parameters, mostly total supply. The basic idea is to define such a function so that as the more the token is supplied, the higher price of the token should be (otherwise there is no incentive to buy the token). An example of the bonding curve is as below (Bancor):



where ReserveTokenBalance is the number of reserve token in the pool, and ReserveRatio is a pre-defined constant.

Note that the function is a continuous price function, while to obtain the actual price to buy/sell some amount of the token, we need to take the integral of the price from pre-tokenSupply to post-tokenSupply after a trade.



Here is the short introduction, which is sufficient to describe the rest of the article, but if you are interested in more details in bonding curves, you could find more details online.

Bonding Curve for Swapping Stablecoins
When comes to swapping stablecoins, e.g., tokens USDC and USDT, we have prior information that both tokens should have the same intrinsic value and most of the trades should be 1:1. However, the actual price varies around 1:1, and sometimes due to some extreme events, the price may fluctuate a lot. The question now is that could we also use bonding curves to price stablecoins so that most of the time the trades are 1:1, while the price may vary if a large number of such token are sold/bought in the market?

To design such a curve, first of all, we need to determine the token parameter of the price function. Clearly, using total supply is a bad choice — total supply does not reflect the intrinsic value of the token. Instead, we use a pooled method and price a token using its percentage in the pool as the pricing parameter:
  • 1:1 trade is guaranteed if a token’s percentage is under a pre-defined value, or
  • the price of the token reduces if the token’s percentage exceeds the threshold.

Setup
Assuming we have a list of stablecoins with amounts [x_1, x_2, … , x_N] in the pool, so that S = sum(x_i). Furthermore, the liquidity providers that supply the tokens have S amount of sUSD — the LP token to buy/sell the stablecoins in the pool:

Buy LP tokens: A user can sell a stablecoin for sUSD by calling mint(), which will deposit x’ amount of a stablecoin k and return s’ sUSD back. s’ must <= x’, and If s’ < x’, x’ — s’ sUSD will be evenly distributed to existing LPs.

Sell LP tokens: A user can buy a stablecoin k with s amount of sUSD by calling redeem(), which will deposit s’ sUSD and return x’ amount of stablecoin k. x’ must <= s’, and if x’ < s’, s’ — x’ sUSD will be evenly distributed to existing LPs.

Bonding Curve for Buying LP Tokens
Similar to Bancor, let us define the curve as follows:

ContinuousLPTokenPrice = 1 if ContinousTokenPercentage_k < Weight_k or 1 + (ContinousTokenPercentage_k — Weight_k) / (1 — ContinousTokenPercentage_k)

where ContinousTokenPercentage_k = x_k / S, and Weight_k is the pre-defined threshold so that the swap between LP token (sUSD) and the stablecoin is 1:1, or if the threshold is exceeded, the LP token will be more expensive and the price grows to infinite if the percentage approaches 1.



The above graph shows the bonding curve with Weight_k = 0.5. To obtain the price of a swap, similar to Bancor, we could apply integral (the red part) to the bonding curve to calculate the area as the price of swap.

Bonding Curve for Selling LP Tokens
Selling LP tokens can be formulated as if a user wants to retrieve back x’ amount of stablecoin k, how much LP token the user should offer? This is a bit more complicated as the percentage of stablecoin k decreases, while all other stablecoins’ percentage increases, where the curve should account for. Let us define the curve as follows:

ContinunousLPTokenPrice = 1 + sum_{j \neq k} 0 if ContinousTokenPercentage_j < Weight_j or (ContinousTokenPercentage_j — Weight_j) / (1 — ContinousTokenPercentage_ — j)

The curve is very similar to the mint one, except that it uses all stablecoins’ percentages other than percentage kth stablecoin as a pricing parameter.

Special Case for Swapping a Stablecoin to Another
If a user wants to swap a stablecoin A to another B directly, one way is to use A to buy LP tokens and then sell the LP tokens for B sequentially, which will need all percentages of the stablecoins as pricing parameter. One observation is that, based on the model, the output amount of B must <= the input amount of A — this means that all tokens’ percentages will be decreased except A. As a result, we could only perform the bonding curve using stablecoin A’s percentage as pricing parameter, which can save a lot of gas cost (calculation and storage read).

The Experiment
We have implemented the idea of the bonding curve for swapping stablecoins and launch a testnet product at beta.smoothy.finance. Besides the bonding curve, smoothy.finance has the following unique features:
  • Extremely low gas fee with about 77k gas vs 127k gas of Curve (sPool)
  • One pool for all stablecoins (10+) without increasing the gas cost of gas fee — this prevents diverged liquidity of multiple pools.
  • Dynamic cash reserve algorithm for LPs to earn both interest and swap fee with low gas cost swapping.

If you are interested in it, you can find more details about the project at smoothy.finance/#/. Welcome to join and provide valuable feedback.

About Smoothy:
Twitter: @smoothswap
Telegram: t.me/Smoothy_finance

Altcoins Talks - Cryptocurrency Forum


This is an Ad. Advertised sites are not endorsement by our Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise Here Ads bidding Bidding Open


 

ETH & ERC20 Tokens Donations: 0x2143F7146F0AadC0F9d85ea98F23273Da0e002Ab
BNB & BEP20 Tokens Donations: 0xcbDAB774B5659cB905d4db5487F9e2057b96147F
BTC Donations: bc1qjf99wr3dz9jn9fr43q28x0r50zeyxewcq8swng
BTC Tips for Moderators: 1Pz1S3d4Aiq7QE4m3MmuoUPEvKaAYbZRoG
Powered by SMFPacks Social Login Mod