diff --git a/docs/docs/alephium/collections.md b/docs/docs/alephium/collections.md index cb2f1dd9..71778450 100644 --- a/docs/docs/alephium/collections.md +++ b/docs/docs/alephium/collections.md @@ -292,19 +292,19 @@ Retrieves a pool associated with the specified pool key. ## Fee Tiers ```rust -Abstract Contract FeeTiers() {...} +struct FeeTiers { + mut feeTiers: [FeeTier; 32] +} -Contract Invariant(mut feeTierCount: U256) extends FeeTiers(), ...{ - ... - mapping[U256, FeeTier] feeTiers - ... +Contract Invariant(mut feeTiers: FeeTiers, feeTierCount: U256, ...){ + const MaxFeeTiers = 32 } ``` -The `FeeTiers` Abstract Contract is designed to manage fee tiers. It utilizes a mapping data structure, where each element corresponds to a different fee tier represented by a `FeeTier` object. The provided functions allow you to add, retrieve, update, and remove fee tiers within the collection. Each fee tier is uniquely identified within the mapping, and you can perform operations on these fee tiers based on their index. The current maximal index is stored in the `feeTierCount` variable. +The `FeeTiers` struct is designed to manage fee tiers. It utilizes an array of `FeeTier` objects. The provided functions allow you to add, retrieve, update, and remove fee tiers within the collection. You can perform operations on these fee tiers based on their index. The current highest index is stored in the `feeTierCount` variable. Our protocol stores at most 32 active fee tiers. -| Type | Key | Value | -| ---------------------- | --------------------------------- | ------------------------------------- | -| mapping[PoolKey, Pool] | The pool key of a specified pool. | Pool struct holding the pool's data. | +| Type | Value | +| ---------------------- | ------------------------------------- | +| [FeeTier; 32] | FeeTier struct holding the fee tier's data. | ### Add fee tier @@ -344,7 +344,7 @@ Removes a fee tier associated with the specified FeeTier. Throws an exception if pub fn containsFeeTier(feeTier: FeeTier) -> Bool; ``` -Verifies if specified fee tier exist. +Verifies if specified fee tier exists. #### Input parameters @@ -558,7 +558,7 @@ The `Reserves` Abstract Contract is designed to overcome the challenge of being | Type | Key | Value | | ---------------------- | --------------------------------- | ------------------------------------- | -| mapping[ByteVec, ByteVec] | The ContractId of a given token. | The ContractId of the reserve containing the given token. | +| mapping[ByteVec, ByteVec] | The ContractId of a given token. | The Contract ID of the reserve containing the given token. | ### Add reserve @@ -593,7 +593,7 @@ This function employs the token[X|Y] naming convention, indicating that arrangin ```rust @using(updateFields = true, preapprovedAssets = true) -fn handleReserves(caller: Address, subPath: ByteVec, tokenX: ByteVec, tokenY: ByteVec) -> (ByteVec, ByteVec); +fn handleReserves(caller: Address, tokenX: ByteVec, tokenY: ByteVec) -> (ByteVec, ByteVec); ``` Retrieves the ids of `Reserve`s for both tokens. If a token isn't stored in a Reserve yet allocates space for it. @@ -603,7 +603,6 @@ Retrieves the ids of `Reserve`s for both tokens. If a token isn't stored in a Re | Name | Type | Description | | ----- | ------- | --------------------- | | caller | Address | Address of the user who wants to know where the Token is or will be stored. They are required to pay the eventual fee.| -| subPath | ByteVec | Unique path to be used in case a new Reserve has to be created.| | tokenX | ByteVec | Id of the first token.| | tokenY | ByteVec | Id of the second token.| diff --git a/docs/docs/alephium/entrypoints.md b/docs/docs/alephium/entrypoints.md index 7e4067a9..60985931 100644 --- a/docs/docs/alephium/entrypoints.md +++ b/docs/docs/alephium/entrypoints.md @@ -16,8 +16,8 @@ Contract Invariant( mut lastReserveId: ByteVec, mut feeTierCount: U256, mut poolKeyCount: U256 -) extends PoolKeyHelper(), Decimal(), FeeTiers(), PoolKeys(), - Pools(clamm), Ticks(), Tickmap(), Positions(clamm), FeeTierHelper(), Reserves(); +) extends PoolKeyHelper(), Decimal(), PoolKeys(), Pools(clamm), + Ticks(), Tickmap(), Positions(clamm), FeeTierHelper(), Reserves(); ``` This constructor method initializes the contract with the specified protocol fee and administrator. @@ -143,11 +143,11 @@ This action is only available to the administrator. ::: ```rust -@using(preapprovedAssets = true) +@using(preapprovedAssets = true, updateFields = true) pub fn addFeeTier(feeTier: FeeTier) -> (); ``` -This function enables the addition of a new fee tier, which users can subsequently utilize when creating pools. +This function enables the addition of a new fee tier, which users can subsequently utilize when creating pools. Up to 32 fee tiers can exist. #### Input parameters @@ -163,6 +163,8 @@ This function enables the addition of a new fee tier, which users can subsequent | `InvalidTickSpacing` | Fails if the tick spacing is invalid. | | `FeeTierAlreadyExist` | Fails if the fee tier already exists. | | `InvalidFee` | Fails if fee is invalid. | +| `FeeTierLimitReached` | Fails if the maximal number of fee tiers (32) already exists.| + ### Fee Tier exists @@ -254,14 +256,14 @@ This function employs the token[0|1] naming convention, indicating that arrangin pub fn createPool(token0: ByteVec, token1: ByteVec, feeTier: FeeTier, initSqrtPrice: U256, initTick: I256) -> (); ``` -This function creates a pool based on a pair of tokens and the specified fee tier. Only one pool can exist with a specific combination of two tokens and a fee tier. +This function creates a pool based on a pair of tokens and the specified fee tier. Only one pool can exist with an unique combination of two tokens and a fee tier. #### Input parameters | Name | Type | Description | | --------------- | --------- | ---------------------------------------------------------------------- | -| token0 | AccountId | Address of the first token in the pair. | -| token1 | AccountId | Address of the second token in the pair. | +| token0 | ByteVec | Contract ID of the first token in the pair.| +| token1 | ByteVec | Contract ID of the second token in the pair. | | feeTier | FeeTier | The fee tier to be applied. | | initSqrtPrice | U256 | The square root of the price for the initial pool related to initTick. | | initTick | I256 | The initial tick value for the pool. | @@ -304,19 +306,33 @@ This function retrieves a pool based on PoolKey. It returns false as the first t | Bool | If true the pool was found and retrieved successfully, false otherwise.| | Pool | A struct containing pool data. | -### Get pools +### Get pools for a token pair + +:::info token sorting + +This function employs the token[0|1] naming convention, indicating that arranging these tokens in ascending order by `contractId` is not necessary. + +::: ```rust -pub fn getPools() -> ByteVec; +pub fn getAllPoolsForPair(token0: ByteVec, token1: ByteVec) -> ByteVec; ``` -This function retrieves listed pool keys. +This function retrieves all pools for the given token pair. + +#### Input parameters + +| Name | Type | Description | +| -------- | --------- | ---------------------------------------------- | +| token0 | ByteVec | Contract ID of the first token in the pair.| +| token1 | ByteVec | Contract ID of the second token in the pair.| + #### Output parameters | Type | Description | | ------------- | ------------------------------------------------------ | -| ByteVec | ByteVec containing all pool keys that indicate all pools listed. | +| ByteVec | ByteVec containing all pools for a given key pair that indicate all pools listed. | ## Position @@ -694,27 +710,28 @@ Retrieves the amount of liquidity ticks of a specified pool. | Type | Description | | ---- | ------------------------------------ | | u32 | Number of ticks on a specified pool. | --> - +| ByteVec| ByteVec containing tickmap chunk index and value. | diff --git a/docs/docs/alephium/installation.md b/docs/docs/alephium/installation.md index 4c14f94c..58dc9aee 100644 --- a/docs/docs/alephium/installation.md +++ b/docs/docs/alephium/installation.md @@ -69,8 +69,8 @@ sudo apt-get update sudo apt-get install docker-compose-plugin ``` - -## Build Protocol +## Protocol +### Build #### Clone repository @@ -96,11 +96,25 @@ cd alephium-stack && make start-devnet npm run compile ``` -#### Run tests +### Test + +##### All ```bash npm run test ``` + +##### Contracts + +```bash +npm run test:contract +``` + +##### SDK + +```bash +npm run test:sdk +```