Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: distribute initial tokens only after launch and buy them fr…
…om ekubo pool (if applicable) (#184) # PR - Distribute tokens only after launch PR to prevent malicious interactions with ekubo by creating pools without any counterparty and risking the supply to dry up. ## Memecoin - Holders before launch is no longer a concept. The initial holders receive their tokens (for “free” ) once the coin is launched. As such, `pre_launch_holders_count` does not need to be tracked and enforcement of prelaunch holder count no longer makes sense. - Allocation of team supply has moved from **memecoin.cairo** to **factory.cairo** - All the initial tokens are minted to the factory - The amount for the team allocation is written to the memecoin by the factory when finalising the launch. ## Factory - Factorized the assertions upon launch to avoid code duplication. - Introduced the calculation of the supply held by the team, capped to 10%, by iterating through each allocation of the initial holders. - The `launch` functions now take as argument the `initial_holders` and `initial_holders_amount`. The MAX_HOLDERS_LAUNCH const is set to 10. - The `launch` function calculate the total team allocation, and supply liquidity equal to the `total_supply - team_allocation`, and after launch distribute the team_allocation to the initial holders - <!> IMPORTANT - The Ekubo launch flow has been entirely reworked to avoid vulnerabilities. It now works as follows: - The owner of the memecoin will need to provide liquidity upon launch to cover for its initial allocation. For example, if it launches a coin at a price of 0.01ETH / MEME and the team is allocated 10% of the total supply, he needs to provide `quote_tokens = 0.1 * total_supply) * 0.01`. - The liquidity providing is done in two steps: - 1. Put the `team_allocation` in the LP, between bounds [initial_tick, initial_tick +1] - 2. Put the `lp_supply`(public liquidity) between bounds [initial_tick, +inf] - This ensures that the team can get its allocation from the pool at a price corresponding to the interval [starting_tick, starting_tick+1] - Once the LP is provided, the funds sent to the factory are used to buy the initial holders tokens using an exact output swap. Considering the tick spacing and fees, it is recommended to send 1.02 * quote_tokens to ensure that the swap passes - this needs to be tested more # Utils - fn sum() to sum the value of an array - Ekubo util functions # Tests to implement Some of these tests are already partially implemented - and the way they are implemented is not necessarily 100% compatible with the current architecture (e.g. the reserve in quote tokens after a swap-in/swap-out is not 0 but not also contains the liquidity the team used to buy). ## Unit tests - Fix failing unit tests. - Test the distribute_team_allocation function ## Ekubo Test the launch flow for these scenarios. - Memecoin is token0 in the pool, with a price MEME/ETH < 1 - Memecoin is token0 in the pool, with a price MEME/ETH > 1 - Memecoin is token1 in the pool, with a price MEME/ETH < 1 - Memecoin is token1 in the pool, with a price MEME/ETH > 1 - Test a launch with a pool with a 1% fee parameter Each one of these tests will perform the following - Launch the memecoin - Assert that the reserve in quote tokens corresponds roughly (~ 0.5% uncertainty) to the amount sent by the team to buy tokens, which itself corresponds to the % of tokens to buy * the price to buy the tokens at. Example: The team allocates itself 10% of the total supply. The price is 0.01ETH/MEME. Thus, the team must send an amount of roughly 0.1 * total_supply * 0.01. Add an uncertainty of the size of the tick space and fee, because the execution will not happen at the launch price precisely. I observed that 1.2% should be enough So if `total_supply = 21M & price=0.01ETH/MEME`, send ~ `1.012*0.1*21M*0.01` - Verify that the reserve in meme tokens is in the interval [0.99 * lp_tokens, 0.995 * lp_tokens] where lp_tokens is the total_supply of the coin - the amount allocated to the team - Check that the LP position is tracked in the launcher - Check that the initial holders have been allocated the correct amount of tokens. - Check that events were emitted correctly - Check that swaps work correctly - Can do a swap in / swap out - Withdraw fees - The amount collected of quote fees must be roughly pool_fee * amount_swapped - The amount of collected memecoin fee must be 0 - Important: test that if someone initialises an Ekubo pool with the wrong initial_price, the person that launches can still add liauidity to the pool at the right price
- Loading branch information