Prices and Fee

BSC protocol is based on the β€œConstant Product” formula: xβˆ—y=kx * y = k where xx and y y are reserve balances, and k is the invariant that remains unchanged during the trading operation. This formula underlies how the exchange price is calculated.

For example, the case where the initial reserves are xx of token AAA and yy of token BBB and the user sells aaa of token AAA. If no fees are charged, then the received amount of bb is:

{xβˆ—y=k(x+a)βˆ—(yβˆ’b)=kxβˆ—y=(x+a)βˆ—(yβˆ’b)xβˆ—y=xβˆ—y+aβˆ—yβˆ’bβˆ—(x+a)bβˆ—(x+a)=aβˆ—yb=aβˆ—y/(x+a)\begin{cases} x*y=k \\ (x+a)*(y-b)=k \end{cases}\\ x*y=(x+a)*(y-b) \\ x*y=x*y+a*y-b*(x+a) \\ b*(x+a)=a*y \\ b=a*y/(x+a)

Then the price is p=(x+a)/yp=(x+a)/y tokens AAA per token BBB. With fee charge things will be slightly different:

{xβˆ—y=k(x+0.997βˆ—a)βˆ—(yβˆ’b)=kxβˆ—y=(x+0.997βˆ—a)βˆ—(yβˆ’b)xβˆ—y=xβˆ—y+0.997βˆ—aβˆ—yβˆ’bβˆ—(x+0.997βˆ—a)bβˆ—(x+0.997βˆ—a)=0.997βˆ—aβˆ—yb=0.997βˆ—aβˆ—y/(x+0.997βˆ—a)\begin{cases} x*y=k \\ (x+0.997*a)*(y-b)=k \end{cases}\\ x*y=(x+0.997*a)*(y-b) \\ x*y=x*y+0.997*a*y-b*(x+0.997*a) \\ b*(x+0.997*a)=0.997*a*y \\ b=0.997*a*y/(x+0.997*a)

The price is then p=(x+0.997a)/(0.997y)p=(x+0.997a)/(0.997y) tokens AAA per token BBB. The fee goes to the pool, increases the reserves, and thereby increases the k k invariant. It entails the growth of the value underlying each share and becomes the source of LP providers' gains.

If price altering results in significant differences between internal and external market prices, arbitrage opportunities will push the price back to the rational value.

Last updated