Skip to content

Instantly share code, notes, and snippets.

@nagydani
Last active August 2, 2022 16:54
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save nagydani/d5c09c331224bfbffbcbe28b347ceb8e to your computer and use it in GitHub Desktop.
Save nagydani/d5c09c331224bfbffbcbe28b347ceb8e to your computer and use it in GitHub Desktop.
Initial utility token sale for project financing with a fixed-leverage bonding curve contract
#! /usr/bin/bc -q
# Usual scale on Ethereum for DAI
scl=10^18
# scale for BZZ
bzzscl=10^16
# log2 of asymptotic reserve ratio
n=5
# Asymptotic reserve ratio 32
res=2^n
# initial supply in BZZ (atomic units)
initial=62500000*bzzscl
# Maximal supply in BZZ atomic units
max=initial*2
# Helper function
define prfh(x) {
auto i
for(i=1;i<=n;i=i+1){
x=(x*x)/initial
}
return x
}
# Primitive function of price function
define prf(x) {
return x+prfh(x)
}
# Price of 1 token in DAI (atomic units) at supply x (in atomic BZZ units)
define pr(x) {
return prf(x+bzzscl)-prf(x)
}
# Market cap at supply x in DAI (atomic units)
define cap(x) {
return (prf(x+1)-prf(x))*x
}
# Effective reserve ratio (market cap / locked amount) at supply x
define rr(x) {
return cap(x)/prf(x)
}
# Initial DAI in reserve (atomic units)
prefund = prf(initial)

Initial Utility Token Sale for Project Financing with a Fixed-Leverage Bonding Curve Contract

The Model

Suppose, we would like to issue a token with an initial supply of dev + inv to be pre-allocated to developers and investors, respectively. Investors obtain their tokens at a pre-sale price p after which the price is free-floating, subject to market forces of available supply and demand.

Further Conditions

  • If the sale of inv tokens is unsuccessful, investors are refunded in full.
  • If the initial sale is successful, most of the collected funds must be available for developers, without them having to sell their tokens.
  • The rest is used for funding the bonding curve contracts market making.

This is a fairly standard arrangement, similar to how Ethereum got funded.

The Bonding Curve

For a constant ratio n of market capitalization to liquidity tied up for market making, a polynomial price function f(x) = cxⁿ⁻¹ should be used where c is a constant depending on the above parameters and x is the total number of tokens issued by the contract.

However, in the initial sale phase, while x < inv, a different, constant function, f(x) = p is used and no other tokens are allowed to exist. When the sale concludes successfully (i.e. x = inv), dev tokens are allocated to developers and the final price function is activated. At this point the price should still be p to prevent discontinuities. Thus, we have c(inv + dev)⁻¹ = p, which yields c = p / (inv + dev)⁻¹.

The total amount that can be withdrawn from the bonding curve contract is ∫(0,inv + dev) c * xⁿ⁻¹ dx = cxⁿ/n = p(inv + dev)/n but the balance of the contract is p * inv. Thus, without causing any discontinuity, developers can withdraw the difference: p(inv - (inv + dev)/n) for funding development.

Choosing the Leverage Ratio

The parameter n is the leverage ratio of the bonding curve contract. The benefits of increasing n are obvious, but there are also risks associated with it. The higher the leverage ratio, the cheaper it is to move the price of the token downwards by dumping it. Thus, n should be chosen in accordance to expectations about immediate sales of developer tokens.

If we follow Ethereum's playbook, part of dev tokens will be kept by the Foundation, while the rest will be made available to individual developers at pre-sale price p. Thus, the Foundation is motivated to maintain the value of the token by doing a good job of developing the application for which it is used, as a large part of its assets are in this token. Individual developers and investors, however, may choose to cash out early, depending on their trust in the continued success of the project reflected in the appreciation of its utility token, though both will incur a loss, if they sell below the price of p, i.e. more than what users or speculators are willing to buy. The choice of n limits the amount of damage an individual seller can incur.

Example: If the largest individual holder holds 20% of the tokens. It means that q=5. If they sell it all, the price will go down to 0.8⁻¹. If we wish for them not to be able to crash the price to half, we should keep n ≤ 4, since 0.8⁴⁻¹=0.512, barely above 0.5.

Practical Parameter Selection for Swarm's BZZ Token

The attached bc file has the formulae implemented in integer arithmetics (i.e. directly applicable to EVM-based smart contracts) for the primitive function prf(x) of bonding curve of the 31st order (n=31). While these calculations assume that the scaling factor scl is the same for both the backing asset (DAI in the example) and the issued token (called BZZ), in an actual implementation they can differ.

Since for each transaction, it is the primitive function of the bonding curve that needs to be evaluated, the bonding curve needs to be selected in such a way that this calculation can be implemented efficiently in EVM. If the degree of the primitive function is a power of two, the dominant component in the polynomial can be calculated by subsequent squarings. In order to keep the scale of the function values manageable, it is worth inserting scaling operations into this. Finally, we must also maintain strict monotonity for the primitive function, as otherwise the price of certain tokens will be zero. The least intrusive way to achieve this is to add an x term to the primitive function that is completely dominated by the higher-order term for most values, yet guarantees that neighboring values of the primitive function differ by at least one.

The particular choice of reserve ratio of 31 is motivated by a similar ratio of market capitalization to orderbook value in well-functioning markets. Numerical experiments with the attached bc script confirmed the desirable properties of this selection by resulting in reasonable outcomes for various regular and extreme scenarios.

As a safety measure against numeric overflows and to address investor concerns about a possibly unlimited token supply, it is worth adding a hard upper limit for the number of tokens the contract can emit. In numerical experiments, I used twice the initial amount. In practice, this limit will probably not be reached, as it would correspond to a market capitalization of about 4 billion times the original, but even in this unlikely case, all this limit does is that it forces market participants to trade through secondary markets, as the consensus price moves beyond this hard limit. With a market capitalization of that magnitude, it will surely not be a problem to find exchanges willing to list the token.

Developer Incentives and Vesting

In order to ensure medium-term developer commitment, is is advisable to disburse the BZZ tokens set pre-mined for financing development in a gradual fashion, perhaps even throttled by a smart contract. This way, the developing organization can credibly commit to building the system and upholding the value of the token.

In particular, following Ethereum's playbook, invididual developers (subcontractors) can ask part or all of their compensation in the token and have an option to purchase at the pre-sale price. The developing organization (i.e. Swarm Foundation) should also be barred from dumping their part of the premined on the market over a short time.

Investors participating in the presale do not need such restrictions, as they have no incentive to do that, given that they could only sell at a loss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment