Overview
In this version of the ALTBC we incorporate liquidity additions and liquidity withdrawals. Trading works in a similar way as in the ALTBC v1.1. In order to process liquidity additions and liquidity withdrawals we will need to mint and burn NFTs that have two fields:amount and
last_revenue_claim. These NFT will play the role of the LP tokens.
Definitions
Initialization Parameters
| Description | Variable | Definition or bounds |
|---|---|---|
| Initial amount of tokens to be deposited into the TBC | ||
| The -intercept upon initialization of the TBC | ||
| Vector Field Parameter | ||
| Initial Concentration parameter | ||
| The initial minimum value of the variable | ||
| The quantity of liquidity units assigned to the deployer at pool initialization | ||
| The quantity of the deployer’s inactive liquidity units at launch | ||
| Initial trading fee | ||
| Initial protocol fee |
Functions
We will now define some functions that will be used several times throughout the spec. In the formula for , the denotes the natural logarithm function.State variables (TBC maintained quantities)
| Description | Variable | Initial value |
|---|---|---|
| Vector Field Parameter | , Note: In this spec, this variable remains constant. We omit the subscript n. | |
| Value of the variable before the –th transaction | ||
| Area under the TBC curve over the interval before the –th transaction | ||
| Value of the parameter before the –th transaction | ||
| Value of the parameter before the –th transaction | ||
| Spot price before the –th transaction | ||
| Concentration parameter | ||
| Minimum value of the variable | ||
| Maximum value of the variable | ||
| Sum of the amount fields of all the NFTs minted by the pool | ||
| The quantity of the deployer’s inactive liquidity units | ||
| A balancing quantity that needs to be added to for fair LP fee accounting | ||
| Trading fee ratio | , Note: In this spec, this variable remains constant. We omit the subscript n. | |
| Protocol fee ratio | , Note: In this spec, this variable remains constant. We omit the subscript n. | |
| Claimable trading fee per liquidity unit | ||
| Total protocol fee |
Notation related to the NFTs
The NFT withamount field value equal to and
last_revenue_claim field value equal to will be denoted by
In addition, the value of the last_revenue_claim field of the NFT
at step will usually be denoted by . Recall
that these values are not tracked by the pool since they are stored in
the corresponding NFT.
Transactions
Pool initialization
When the pool is initialized, the state variables are defined as described in the previous table. In addition, an amount of tokens must be deposited into the pool. For reference in what follows, Two NFTs must be minted and given to the pool deployer (or game owner) upon initialization of the pool. The first will haveamount field value equal to and
last_revenue_claim field value equal to . With our notation, this
NFT is
The second, which will henceforth be referred to as the inactive-fee NFT (and which is unique in this way), will have amount field value equal to and
last_revenue_claim field value equal to . With our notation, this
NFT is
Note that can be replaced by any appropriate number or object that handles the following three actions appropriately for the
inactive-fee NFT:
1. Extracting revenue: the transaction should be immediately reverted (described below).
2. Withdrawing liquidity: the transaction is allowed with some modifications (described below - for example, step 8
in Liquidity withdrawals).
3. Adding liquidity: the transaction should be immediately reverted (described below).
We emphasize that a pool may have at most one inactive-fee NFT at any stage in its lifetime. The deployer must mint one at inception and if this inactive-fee NFT is liquidated by the deployer, there will never be another.
Trades
Suppose that the -th trade comes into the pool, and that the current values of the state variables is . We perform the trade using the algorithm defined by the following steps. Step 1. We update the state variables and according to four different situations as described below.- If the user submits an order to buy an amount of token , we check that
- If the user submits an order to sell an amount of token , we check that
- If the user submits an order to buy an amount of token (collateral), we define
- If the user submits an order to sell an amount of token (collateral), we define the trading fee and protocol fee, respectively, by
The revenue parameter
In order to enable liquidity providers to collect their corresponding share of revenue and fees from the pool, we introduce the revenue parameter function, which is defined by Now, if are the current values of the corresponding pool variables, we define the current revenue parameter (per unit of amount) as It is important to mention that this parameter is invariant with respect to proportional liquidity deposits and liquidity withdrawals.Liquidity deposits
Let be the current values of all state variables. Suppose that a user wants to provide liquidity to the pool approving up to amounts of token and of collateral, with . Before proceeding, check if the deposit is associated with the inactive-fee NFT. If so, revert the transaction. In all other cases, in order to process this liquidity deposit we proceed as follows. Step 1. We will determine the amounts and of the respective tokens that will actually be taken so that the liquidity deposit is proportional. Let . If then set If then set Note that and . If , the deposit should be reverted. In all other cases, move through the remaining steps with the computed values for , , and Step 2. Now we update the variables and of the TBC, as follows. Step 3. We update the parameters and of the pool in the following way. Step 4. We update the parameter of the pool, as follows. Step 5. We update the parameters and of the ALTBC as follows: and Note that and that . We also update the spot price as Note that . Step 6. We update the parameters and of the TBC in the following way. Step 7. We update (recall computed at the beginning of this section) we define and we update Step 8. We transfer the amounts of token and of collateral to the pool. Step 9.- Case 1. If the liquidity provider has provided an NFT to which the new deposit should be added we proceed in the following way. Let
- Case 2. If the liquidity provider has not provided an NFT to which the new deposit should be added, we mint the NFT defined by
Extracting revenue
We need to define a pool function that enables the game developers and liquidity providers to extract, at any moment, any excess of collateral from the pool as revenue. In order to give a liquidity provider the fair amount of collateral that his/her NFT accrued we do the following. Before proceeding, check if we are dealing with the inactive-fee NFT. If so, revert the transaction. In all other cases, we proceed as follows. Suppose that liquidity provider owns the NFT defined by Let be the current values of the state variables, and let be the current value of the revenue parameter. Then, the maximum amount of collateral that the liquidity provider is entitled to collect is given by the formula If the liquidity provider intends to extract an amount of revenue we proceed as follows. Step 1. We check that If so, we proceed. Otherwise we reject the transaction. Step 2. We update the value of the variable (of the last_revenue_claim field of the liquidity provider’s NFT) as This is, the NFT that the liquidity provider owns is updated to Step 3. We transfer an amount of collateral to the liquidity provider’s account.Liquidity withdrawals
Let be the current values of the state variables. Suppose that liquidity provider wants to redeem liquidity corresponding to the NFT defined by Suppose, in addition, that the liquidity provider wants to redeem the part of the liquidity corresponding to the previous NFT given by an amount value of with . In order to process the liquidity withdrawal, we proceed as follows. First, determine whether the NFT in question is the inactive-fee NFT. Step 1. We define and Note that if we are dealing with the inactive-fee NFT, does not need to be computed. Step 2. Using our computed value of from the previous step (obtained when computing ), define Then, define the amounts of token and collateral that the liquidity provider will receive by Step 3. We update the variables and of the TBC, as follows. Step 4. We update the parameters and of the pool in the following way. Step 5. We update the parameter of the pool, as follows. Step 6. We update the parameter of the ALTBC as follows. The parameter and the spot price do not need to be updated. This is, we define Step 7. We update the parameter of the TBC in the following way: If we are dealing with the inactive-fee NFT, we must also update of the TBC in the following way: Otherwise, define Finally, if and , revert the transaction. Otherwise, proceed. Step 8. If we are dealing with the inactive-fee NFT, this step must be skipped. We give the liquidity provider the remaining revenue to which he/she is entitled (if there is any left) corresponding to the amount value , which is given by the formula Step 9. The NFT used by the liquidity provider is updated to (or burned if ), and the liquidity provider receives an amount of token and an amount of collateral. Note that if we are dealing with the inactive-fee NFT, thelast_revenue_claim persists at (this is just noted for emphasis, not because a different action is
required).
Note that only the amount field of the NFT is updated.
Step 10.
If we are dealing with the inactive-fee NFT, we will update as
In all other cases (i.e. whenever we are dealing with an active-fee NFT), we update as