Inspired by this topic, I created another simple demo to showcase what a bonding curve pool looks like on CKB.
A bonding curve pool is an automated market-making mechanism, where the price of a token is defined purely by math. And the best thing (for the token issuer, I guess) is that if you set the formula to something like Price = K · ln(Circulating Supply), the token price will always go up! The trick is that earlier buyers can buy a lot of tokens with less money, while later buyers must pay more. That’s basically how bonding curves work in crypto.
Sounds pretty FOMO, right? This is a fundamental piece that a large ecosystem of DeFi/GameFi applications is built on. It is mostly explored on Ethereum. While it sounds FOMO, the bonding curve pool does solve some problems: If you create a brand new token today, there is always a way to create a market for it by using a bonding curve, even if no CEX will list it.
In ecosystems like the UTXO/Cell model, similar things are less explored due to the shared state problem. The nature of using a pool to make a market comes with a caveat: the pool must know all the token information, including how much has been minted, etc. That requires creating a global state that can be read by the pool. Unlike the account model, the UTXO/Cell model is hard to implement any sort of global state.
So how does the demo solve this problem?
The answer is simple—we don’t!
The inspiration from FairLaunchCell is that instead of solving the global/shared state problem (essentially, that’s really a performance problem), let’s just create a real demo to see if it gathers interest in the first place.
The bonding curve demo just creates a very low-concurrency marketplace—one pool per Cell. This means that only one transaction interacting with the pool can be included in each block, which is pretty easy to implement. By creating N of the same pool cells, theoretically, we achieve N concurrency for the token market to work for multiple users. As interactions go by, each pool (even starting with the same status) will show a different price and supply. There will be arbitrage traders seeking profit and making the pools match the same status. Hopefully.
That’s a wrap for this demo. If you find it interesting, any feedback is welcome.
The code is fully open-source: GitHub - RetricSu/simple-bonding-curve
Preview: https://simple-bonding-curve-app.vercel.app/
P.S. the smart contract and the app is all built using Typescript, so it should be pretty easy to understand.
Chinese Version:
受这个 Topic 的启发,我又做了一个简单的 Demo,用来演示在 CKB 上实现联合曲线池(Bonding Curve Pool)是什么样子。
联合曲线池本质上是一种自动做市机制,代币的价格完全由数学公式定义。最棒的一点(对于代币发行方而言)是,如果你把公式设定为类似 价格 = K · ln(流通量) 的形式,代币价格就会一哭上涨!秘诀在于,早期买家可以用很少的钱买到大量代币,而后期入场的人则必须支付更高的价格。这基本上就是加密领域中联合曲线的运作方式。
听起来很 FOMO 对吧?但这其实是庞大的 DeFi/GameFi 应用生态构建的基石,目前主要是在以太坊上被广泛探索。虽然听起来很 FOMO,但联合曲线池确实解决了一些实际问题:如果你今天创建了一个全新的代币,哪怕没有中心化交易所(CEX)愿意上币,你依然可以通过联合曲线为它创造一个交易市场。
在像 UTXO/Cell 模型这样的生态系统中,由于“共享状态”(Shared State)问题,类似的探索相对较少。使用流动性池来进行做市有一个天然的限制:池子必须知晓代币的所有信息,比如当前铸造了多少等等。这就要求创建一个能被池子读取的全局状态。与账户模型不同,在 UTXO/Cell 模型上很难实现某种形式的全局状态。
那么,这个 Demo 是如何解决这个问题的呢?
答案很简单——我们不解决它!
FairLaunchCell 给我的启发是,与其费劲去解决全局/共享状态问题(这本质上其实是个性能问题),不如先直接做一个,看看能不能先引起大家的兴趣。
这个联合曲线 Demo 仅仅创建了一个极低并发的市场——即“一个 Cell 对应一个池子”。这意味着在每个区块中,只能有一笔交易与该池子进行交互,这在实现上非常简单。而通过创建 N 个相同的池子 Cell,理论上我们就为代币市场提供了 N 倍的并发能力,可以服务更多用户。当然,随着交互的进行,每个池子(即使初始状态相同)都会呈现出不同的价格和供应量。此时,理论上来说,套利交易者(Arbitrageurs)就会为了获利而进场,最终将各个池子的状态抹平。
关于这个 Demo 的介绍就到这里。如果你觉得有意思,欢迎任何反馈。
代码完全开源:GitHub - RetricSu/simple-bonding-curve
预览地址:https://simple-bonding-curve-app.vercel.app/
P.S. 整个合约端和前端都是用 typescript 写的,所以应该很容易看懂,不需要懂 rust 就能动手。
