# Architecture Source: https://docs.forteamm.io/concepts/architecture ## Libraries The pools make heavy use of internal libraries to carry out mathematical operations. Internal libraries avoid external calls. This choice makes the deployment more expensive, but makes individual user transactions cheaper. The math equations are encapsulated in their own libraries where they make use of another library which is an aggregation of math libraries: library dependency diagram ### Equation Library There are two equation libraries used, one for each curve type. Each equation library is utilized in the corresponding pool type. These libraries exist to encapsulate the different equations necessary to carry out a swap and preserve the state of the curve. They use the math libraries aggregated in the MathLibs library. see [ALTBCEquations.sol](/reference/amm/ALTBCEquations.sol/library.ALTBCEquations) ## ALTBC Equation Overview The ALTBCEquations Library contains functions for the following equations: ### Vector Field Parameter: V $V > 0$ note: V is a constant value that will not change once the AMM has been initialized. ### bn $b_n = \frac{V}{x_{n} + C}$ note: bn is a variable that will change over time and tracks the value of the parameter b before the n-th transaction. When combined with the cn parameter, it is used to calculate the price of the x token because bn and cn are used to define the TBC. bn is the slope of the TBC function f (which is a line), and it is related to the price impact of trades: if the slope is higher, a certain trade will move the price more. ### Concentration Parameter: C $C > 0$ note: C is a constant value that will not change once the AMM has been initialized. ### cn+1 $b_n <= b_{n+1} \implies c_{n+1} = c_n + \frac{b_n - b_{n+1}}{2}*X_n$ $b_{n+1} > b_n \implies c_{n+1} = c_n - \frac{b_{n+1} - b_n}{2}*X_n$ note: cn is a variable that will change over time and tracks the value of the parameter c before the n-th transaction. It is initialized to the lower price of the pool. When combined with the bn parameter, it is used to calculate the price of the x token because bn and cn are used to define the TBC. It is the y-intercept of the TBC function f (which is a line). ### Area under the TBC: Dn $D_n = \frac{1}{2} b_n x_{n+1}^2 + c_n x_{n+1}$ note: Dn is a variable that will change over time and tracks the value of the area under the TBC before the n-th transaction. ### Price Function: fn $f_n(x) = b_nx + c_n$ $f_n$ defines the price function for the TBC. ### New X coordinate: Xn+1 $X_{n+1} = \frac{2D_n}{c_n + \sqrt{c_n^2 + 2b_n D_n}}$ ## NFT Liquidity Equations and Variables Upon construction of the pool, two NFTs are minted. These NFTs are used to seed initial liquidity into the pool. One NFT is used to track the amount of liquidity that is active in the pool, and the other NFT is used to track the amount of liquidity that is inactive in the pool. ### Wactive note: Wactive is the initial amount of liquidity in the pool. Stored in initial minted NFT as wj. ### Winactive note: Winactive is the amount of liquidity that is inactive in the pool. Stored in initial minted NFT as wj. ### Total Revenue per unit of liquidity: hn $h_n = \frac{L_n + Z_n}{W_n - w_{\textnormal{inactive}}} + \phi$ ### Last Revenue Claim: rj $r_j = wj (hn - rj)$ note: This is a field stored in the LPToken contract. It is used to track the last revenue claim for a given LPToken. ### Sum of the amount fields of all the NFTs minted by the pool: Wn ### Ratio of xToken to yToken in liquidity: q note: Q is updated along with the variables of $\tilde A \geq 0$ and $\tilde B \geq 0$ which represent the proposed amount of xToken and yToken to be added to the pool. A and B are the actual amount of xToken and yToken added to the pool. If $\tilde B \cdot \left (x_{\textnormal{max}}^{(n)}- x_n\right ) \leq \tilde A \cdot \left (D_n - L_n \right )$ then set $\begin{aligned} B &= \tilde B \\ A &= \begin{cases} \frac{x_{\textnormal{max}}^{(n)}- x_n}{D_n - L_n} \cdot \tilde B, &\text{ if } D_n - L_n \neq 0 \\ \tilde A, &\text{ if } D_n - L_n = 0 \\ \end{cases} \\ q &= \begin{cases} \frac{B}{D_n - L_n}, &\text{ if } D_n - L_n \neq 0 \\ \frac{A}{x_{\textnormal{max}}^{(n)}- x_n}, &\text{ if } D_n - L_n = 0 \ . \\ \end{cases} \\ \end{aligned}$ If $\tilde B \cdot \left (x_{\textnormal{max}}^{(n)}- x_n\right ) > \tilde A \cdot \left (D_n - L_n \right )$ then set $\begin{aligned} A &= \tilde A \\ B &= \frac{D_n - L_n}{x_{\textnormal{max}}^{(n)}- x_n} \cdot \tilde A \\ q &= \frac{A}{x_{\textnormal{max}}^{(n)}- x_n} \ . \\ \end{aligned}$ ### Trading Fee Ratio: $\phi$ initial $\phi = 0$ note: This is updated by the pool owner. ### Protocol Fee Ratio: $\psi$ initial $\psi = 0$ note: This is updated by the pool owner. ### Calculates extra collateral: Ln ${\bf L}(x_n,b_n,c_n,x_{\textnormal{min}}^{(n)},C_n,V) = \frac{1}{2} x_{\textnormal{min}}^{(n)} \left( b_n x_n + 2 c_n + V \cdot \ln\left(\frac{x_{\textnormal{min}}^{(n)} + C_n}{x_n + C_n}\right) \right)$ note: The equation L computes the minimum value that the parameter D can have at a certain moment, regardless of the trade sequence that is performed afterwards (no liquidity deposits or withdrawals considered). It is used to compute the amount of "extra collateral" that the pool has, which then can be given as revenue to the liquidity providers. ### Balancing quantity added to L for fair LP fee accounting: Zn+1 if withdrawal: $q = q \cdot -1$ and then $Z_{n+1} = Z_n + ((\frac{WIn}{(Wn - WIn)} * q) * (Ln + Zn) + (q * Zn))$ *note: This function determines the max revenue, the extra collateral, a pool owner can extract at time $n$* *** ### Math Libraries These are libraries that carry out the actual math operation in the most optimal and precise way. The external libraries consist of: ### Float128 see [Float128.sol](https://github.com/forte-service-company-ltd/Float128) Our best effort to achieve high precision floating point numbers. ### Solidity\_Uint512 The Uint512 library provides the ability to perform different math functions with 512 bit integers (instead of the normal max of 256 bit). This allows for additional precision where it is needed in the equations. see [Uint512.sol](https://github.com/SimonSuckut/Solidity_Uint512/tree/main) ## Pool The pool architecture is a monolithic contract that makes use of the equation library. This monolithic and minimalistic style of architecture intends to save gas and increase maintainability. pool diagram The diagram shows that this is a single contract that has its libraries as internal libraries, and that the pool itself only deals directly with one library: the equation library of the curve type chosen. see [ALTBCPool.sol](/reference/amm/ALTBCPool.sol/contract.ALTBCPool) ## Factory The factory pattern ensures that a pool can be deployed properly: factory diagram #### AllowList Contracts The AllowList contracts are used for allowing appoved yTokens to be assigned as a pair to an xToken, as well as assigning allowed pool deployers. These allow lists are separated into their own contracts, one AllowList contract for approved yTokens and one AllowList contract for approved pool deployers. This was done in order to distinguish which address is on which allow list easily. see [ALTBCFactory.sol](/reference/factory/ALTBCFactory.sol/contract.ALTBCFactory) ## Bounds Please visit next page for [Bounds](/concepts/bounds). # Events Source: https://docs.forteamm.io/concepts/events This document explains all the events emitted by use of the product. Both the pool and the factory emit events to make it easier for offchain tools to monitor the state and activity of the contracts. See [IALTBCEvents.sol](/reference/common/IALTBCEvents.sol). ## Pool Events ### LP Fees Collected Emitted when LP fees have been collected by the *owner* of the pool. ```solidity theme={null} event LPFeesCollected(address indexed _collector, uint256 indexed _amount); ``` ### ALTBC Pool Deployed Emitted when an ALTBC pool has been deployed. ```solidity theme={null} event ALTBCPoolDeployed( address indexed _xToken, address indexed _yToken, string indexed _version, uint16 _lpFee, uint16 _protocolFee, address _protocolFeeCollector, uint256 _maxXTokenSupply, ALTBCInput _tbcInput, bool _liquidityRemovalAllowed, address sender ); ``` ### Protocol Fee Collector Confirmed Emitted when protocol fee collector has been confirmed. ```solidity theme={null} event ProtocolFeeCollectorConfirmed(address indexed _collector); ``` ### Protocol Fee Collector Proposed Emitted when protocol fee collector has been proposed. ```solidity theme={null} event ProtocolFeeCollectorProposed(address indexed _collector); ``` ### Swap Emitted when a swap has been made. ```solidity theme={null} event Swap(address indexed _tokenIn, uint256 indexed _amountIn, uint256 indexed _amountOut, uint256 _minOut); ``` ## Factory Events ### Address Allowed Emitted when a token or deployer is added to the allow list. ```solidity theme={null} event AddressAllowed(address indexed _address, bool indexed _allowed); ``` ### Pool Created Emitted when the factory has deployed a pool. ```solidity theme={null} event PoolCreated(address indexed _pool); ``` ### ALTBC Pool Factory Deployed Emitted when an ALTBC factory has been deployed. ```solidity theme={null} event ALTBCFactoryDeployed(string indexed _version); ``` ### Protocol Fee Collector Confirmed Emitted when protocol fee collector has been confirmed. ```solidity theme={null} event ProtocolFeeCollectorConfirmed(address indexed _collector); ``` ### Protocol Fee Collector Proposed Emitted when protocol fee collector has been proposed. ```solidity theme={null} event ProtocolFeeCollectorProposed(address indexed _collector); ``` ### Revenue Withdrawn Emitted when the owner of the pool withdraws revenue accrued. ```solidity theme={null} event RevenueWithdrawn(address indexed _collector, uint256 indexed _amount); ``` ### Liquidity Withdrawn Emitted when the owner of a position withdraws liquidity from the pool. ```solidity theme={null} event LiquidityWithdrawn(address indexed _collector, uint256 indexed tokenId, uint256 indexed amountOutXToken, uint256 indexed amountOutYToken, uint256 revenue); ``` ### LP Token Minted Emitted when a new LP token is minted. ```solidity theme={null} event LPTokenMinted(address indexed _lp, uint256 indexed tokenId, packedFloat wj, packedFloat hn); ``` ### LP Token Burned Emitted when an LP token is burned. ```solidity theme={null} event LPTokenBurned(address indexed _lp, uint256 indexed tokenId, uint256 indexed initialLiquidityWj); ``` ### Fees Generated Emitted when fees have been generated. Includes the amount of LP fees, protocol fees, and revenue generated. ```solidity theme={null} event FeesGenerated(uint256 indexed lpFee, uint256 indexed protocolFee, uint256 indexed revenue); ``` ### Allow List Deployed Emitted when the allow list is deployed. ```solidity theme={null} event AllowListDeployed(); ``` ### Set Deployer Allow List Emitted when the deployer allow list is set. ```solidity theme={null} event SetDeployerAllowList(address indexed _allowedList); ``` ### Fees Collected Emitted when fees have been collected. Includes the type of fee collected (LP or Protocol), the collector, and the amount collected. ```solidity theme={null} event FeeSet(FeeCollectionType indexed _feeType, address indexed _collector, uint256 indexed _amount); ``` ### Fee Set Emitted when the fee value for swaps has been updated. Includes the type of fee (LP or Protocol) and the new fee value. ```solidity theme={null} event FeeSet(FeeCollectionType indexed _feeType, uint16 indexed _fee); ``` ### Set Y Token Allow List Emitted when the Y token allow list is set. ```solidity theme={null} event SetYTokenAllowList(address indexed _allowedList); ``` ## Non Native Events These events are not native to the protocol but are emitted by the protocol, usually imported by other libraries. ### Initialized Emitted when the contract has been initialized. ```solidity theme={null} event Initialized(uint64 version); ``` ### Ownership Transferred Emitted when the ownership of the contract has been transferred. This is used in the Ownable2Step contract and the Ownable contract. ```solidity theme={null} event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); ``` ### Paused Emitted when the contract has been paused. ```solidity theme={null} event Paused(address account); ``` ### Unpaused Emitted when the contract has been unpaused. ```solidity theme={null} event Unpaused(address account); ``` ### Transfer ERC20 Emitted when a ERC20 token transfer occurs. ```solidity theme={null} event Transfer(address indexed from, address indexed to, uint256 value); ``` ### Approval ERC20 Emitted when a ERC20 token approval occurs. ```solidity theme={null} event Approval(address indexed owner, address indexed spender, uint256 value); ``` ### Transfer ERC721 Emitted when a ERC721 token transfer occurs. ```solidity theme={null} event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); ``` ### Approval ERC721 Emitted when a ERC721 token approval occurs. ```solidity theme={null} event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); ``` ### Approval For All ERC721 Emitted when a ERC721 token approval for all occurs. ```solidity theme={null} event ApprovalForAll(address indexed owner, address indexed operator, bool approved); ``` ## Architecture Please visit next page for [Architecture](/concepts/architecture). # LP Token Source: https://docs.forteamm.io/concepts/lp-token The LP token is a token that represents the liquidity in the pool. It is minted when liquidity is added to the pool and burned when liquidity is removed from the pool. The LP token is used to track the liquidity in the pool and to receive the LP fees. It conforms to an ERC721 enumerable token. It tracks 2 key variables: wj and rj. wj is the amount of liquidity provided by the liquidity provider. rj is the amount of revenue last claimed by the liquidity provider. ## Minting When liquidity is added to the pool, the LP token is minted to the liquidity provider. The amount of liquidity provided is the amount of liquidity added to the pool. The amount of revenue last claimed is set to hn which is the revenue parameter of the pool associated with the LP token. ## Withdrawal ```solidity theme={null} /** * @dev This is the function to withdraw liquidity from the pool. * @param tokenId The tokenId owned by the liquidity provider. * @param uj The amount of liquidity being withdrawn */ function withdrawLiquidity(uint256 tokenId, uint256 uj) external ``` When liquidity is removed from the pool, a parameter uj is passed in along with the token ID. uj is the desired amount of liquidity that an LP would like to withdraw from their position. A parameter q is produced dividing uj by w. In order to ensure an equal amount of LPs out, we calculate the amount of xTokens owed as q \_ (xmax - x). The amount of xTokens owed is then subtracted from the pool's x value. Concurrently for the amount of y tokens owed, we calculate the amount of y tokens owed as q \_ (Dn - L). The amount of y tokens owed is then subtracted from the pool's y value. If wj is less than uj, then this means that there is insufficient liquidity to withdraw and the transaction reverts. If wj is greater than uj, then uj is simply subtracted from wj, indicating that the LP is withdrawing a portion of their liquidity. If wj is equal to uj, then the LP token is burned and the liquidity is removed from the pool. After the amounts have been calculated, the pool's state is updated with a new value of h and w and the parameter Zn on the curve is updated to ensure proper accounting. ## Revenue Claiming Revenue withdrawal is initiated in the ALTBC by the function `withdrawRevenue`. ```solidity theme={null} function withdrawRevenue(uint256 tokenId, uint256 Q) external returns (uint256 revenue) ``` Q represents the amount of revenue being withdrawn. If Q is greater than the revenue available, the transaction reverts. A new value of revenue last claimed is then calculated as rj + Q/wj. Upon revenue being claimed, the updated rj is updated to add the amount of revenue claimed. The amount of revenue claimed is the amount of revenue that is being withdrawn. The amount of revenue being withdrawn is the amount of revenue that is being withdrawn from the pool. # Pool Source: https://docs.forteamm.io/concepts/pool A pool in this context is the medium through which users can exchange 2 different assets. In this case, these 2 assets are a pair of tokens where one is the collateral ERC20 token (aka *y*-axis token) and the other one is the *x*-axis ERC20 token. The following are the technical aspects of a pool in this product: See [Pool.sol](/reference/amm/ALTBCPool.sol/contract.ALTBCPool). ## Overview ### Assumptions * **The pool is the original source for all x-tokens**: it is assumed that the pool is the only source for originally getting x-tokens. Other markets such as constant-product AMMs can be used once the tokens are in circulation, but all tokens are originally purchased from the TBC. * **The pool has been deployed through the factory**: The factory automatically grants ownership of the pool to the deployer address. It also emits an event for the monitoring services to know when a pool has been deployed through it. ### Ownership *The owner* of the pool is granted initially to the deployer address. The pool uses the `Ownable` contract from [OpenZeppelin](https://www.openzeppelin.com/). Therefore, transfer of ownership is always allowed to *the current owner* of the pool. ### ALTBC Price Curve The price curve of an ALTBC pool obeys what we call an **adjustable linear token bonding curve**. For an individual transaction, the price is calculated according to a linear formula. After each transaction, the line that defines the price is updated. The slope of this line changes based on the amount of x-tokens out in circulation. The effective price curve (how the price evolves over time, across many swaps) will be a concave curve that tends to stabilize the more tokens are sold. animation of spot price animation of y liquidity price curve of adjustable linear TBC ### Access Control #### Owner *The owner* of the pool contract is the only one who can execute the following privileged functions: * enableSwaps(bool \_enable) * setLPFee(uint16 \_fee) * addXSupply(uint256 \_amount) * collectLPFees() * withdrawRevenue() #### Protocol Fee Collector *The protocol fee collector* account of the pool contract is the only one who can execute the following privileged functions: * setProtocolFee(uint16 \_fee) * proposeProtocolFeeCollector() There is a transitionary role which is the *proposed protocol fee collector*. This role is granted by the *The protocol fee collector* when calling `proposeProtocolFeeCollector`, and the only function that this transitionary role can call is: * confirmProtocolFeeCollector() In which case, the account loses this role to now become the *The protocol fee collector*. ### Security The pool can be paused at any point by the *owner* account which means that all trading is disabled. ### Revenue As a consequence of the mathematical design, the pool will generate a small revenue per trade, independently of any fees set on the pool. The size of this revenue is correlated with the size of `xMin`, and grows over time with each trade. This revenue can be collected by the pool owner. Note that there may be remaining dust in the pool which will only be extracted when the pool is closed. #### Artificial Price Manipulation Control The mathematical design of this pool is such that it would be possible to artificially increase the price of an asset at no cost if we allowed `x` to be zero. At low values of `x`, it is also possible to increase the price of the asset at a potentially low cost by wash trading. To mitigate this possible price manipulation, the pool initiates with a synthetic trade. The amount of this synthetic trade is defined as `xMin + w` and is stored in the contract as `xMax`, where `w` is the initial xTokens added to the pool expressed in a packedFloat format. #### Virtual Liquidity This synthetic trade will cause the pool to have a virtual liquidity which is stored in the contract as `wActive` which is the difference between `w` and `wInactive`. This synthetic trade will also generate revenue for the pool which will be accumulated as dust in the pool. ## Usage ### Deployment To deploy a pool please follow the guidelines in the [factory guideline](/concepts/pool-factory). ### Initialization After deployment, it is necessary to do the following step: 1. Add liquidity to the pool (see [Managing Liquidity](#managing-liquidity)). Notice that initial liquidity is only necessary for the *x-token* since the *y-token* will be provided through swaps by users. The amount of liquidity provided will be equal to the totalSupply of the token. The pool will start operating at **xMin**. See explanation below *note*: *Each pool will start with a synthetic trade in order to prevent an artificial price increase. This synthetic trade at the beginning of a fresh pool will help negate a malicious user from increasing the price of xToken in the pool. This also allows for a pool owner to extract collateral dust that accrues throughout the lifetime of the pool.* *see the [revenue equation](/concepts/architecture) here* ### Managing Fees #### LP Fees The liquidity-provider fees are a portion of the swap that would go towards the liquidity provider as a compensation for the service provided. In this pool, there can only be one liquidity provider who is the *owner* of the pool, and therefore, the liquidity-provider fees can be managed only by the *owner* of the contract. Here are the main features of the fees of the pool: * Fees can be updated at any time. * Fees can be 0. * Fees are expressed in basis points. * Fees can be 50% - protocol fees. * Fees are collected in the y-token. * Fees are kept inside the pool. * Fees can be collected by the owner of the NFT token ID that defines the position of the liquidity provider. Fees can be managed through the following functions: ```solidity theme={null} /** * @dev function to update the fees per trading * @param _fee percentage of the transaction that will get collected as fees (in percentage basis points: * 10000 -> 100.00%; 500 -> 5.00%; 1 -> 0.01%) */ function setLPFee(uint16 _fee) external; /** * @dev collects the fees from the Pool */ function collectLPFees() external; /** * @dev tells how much collected fees are available in the Pool */ function lpFee() external; ``` #### Protocol Fees Protocol fees are a portion of each swap that will go towards the protocol as a compensation for its service provided. The management of the protocol fees is under complete control of the protocol and not of the *owner* of the pool. The following are the properties of the pool's protocol fees: * Protocol fees can be updated at any time. * Protocol fees can be 0. * Protocol fees are expressed in basis points. * Protocol fees can be as high as 0.20%. * Protocol fees are collected in the y-token. * Protocol fees are kept inside the pool. * Protocol fees need a manual withdrawal by *the protocol fee collector* who then will receive the totality of the fees accumulated. #### Protocol fee value The protocol fee value can be set at any time only by the *protocol fee collector* account. The following functions are available to manage this value: ```solidity theme={null} /** * @dev fee percentage for swaps for the protocol * @return the percentage for swaps in basis points that will go towards the protocol */ function protocolFee() external returns (uint16); /** * @dev This is the function to update the protocol fees per trading. * @param _protocolFee percentage of the transaction that will get collected as fees (in percentage basis points: * 10000 -> 100.00%; 500 -> 5.00%; 1 -> 0.01%) */ function setProtocolFee(uint16 _protocolFee) external; ``` #### Protocol fee collector The protocol fee collector account of the pool can be updated at any time. Only the *protocol fee collector* account can update this value. The following functions are available to manage this address: ```solidity theme={null} /** * @dev protocol-fee collector address * @return the current protocolFeeCollector address */ function protocolFeeCollector() external returns (address); /** * @dev proposed protocol-fee collector address * @return the current proposedProtocolFeeCollector address */ function proposedProtocolFeeCollector() external returns (address); /** * @dev function to propose a new protocol fee collector * @param _protocolFeeCollector the new fee collector * @notice that only the current fee collector address can call this function */ function proposeProtocolFeeCollector(address _protocolFeeCollector) external; /** * @dev function to confirm a new protocol fee collector * @notice that only the already proposed fee collector can call this function */ function confirmProtocolFeeCollector() external; ``` Notice that the process of assigning a new protocol fee collector is a 2-step process in order to prevent human errors from setting the wrong address: 1. The current *protocol fee collector* account proposes a new protocol fee collector address through the function `proposeProtocolFeeCollector`. 2. The proposed protocol fee collector account then needs to call the `confirmProtocolFeeCollector` function to accept/confirm this role. ### Revenue Because of the mechanism to deter artificial price increase in a fresh pool, a synthetic trade is done when deploying a new pool. This new pool will start with its `x` at `xMin`. Therefore, the outstanding liquidity will always be `x - xMin`. This dust is accessible through the `withdrawRevenue` function, callable by the owner of the NFT token ID that defines the position of the liquidity provider. ```solidity theme={null} /** * @dev This function allows the owner of the pool to pull accrued revenue from the Pool. */ function withdrawRevenue(uint256 tokenId, uint256 Q) external returns (uint256 revenue); ``` *note: The dust remaining in the pool as revenue will also be extracted when closing the pool* ### Managing Swaps Swaps can be enabled and disabled. This functionality uses the standard `Pausable` contract found in projects like OpenZeppelin. To enable or disable swaps, use the following function: ```solidity theme={null} /** * @dev function to activate/deactivate trading * @param _enable pass True to enable or False to disable. */ function enableSwaps(bool _enable) external; ``` The functions affected by a disabled-swap state are limited to: * swap() ### Swaps The main feature of the pool is that it allows swaps. Swaps are permissionless meaning that anybody can use this feature. A vital factor of a swap is *price*, for which there are three different functions that can be used. These functions will be explained in the following sections. #### Spot price In the context of a TBC AMM, spot price refers to the current price for buying 1 full token assuming a flat price for the whole token (no price difference between the first wei and the last wei of the purchased token). ```solidity theme={null} /** * @dev This is the function to retrieve the current spot price of the x token. * @return sPrice the price in YToken Decimals */ function spotPrice() external view returns (uint256 sPrice); ``` Take into account that this is more of a theoretical price since in reality the price does change from the first wei to the last wei since this is a linear TBC, and therefore the price depends on the amount of *x token*s sold by the pool (value of *x*). To know an exact price of a transaction, it is necessary to know exactly how much to swap. For this, use the functions of the coming section. **📝** *WEI is being used to refer to the atomic unit of the ERC20 token. We find this terminology more intuitive since the decimals of ERC20 mimic the relationship between Ether and WEI but without a defined term for the atomic unit like we get for ETH* #### Swap simulations The pool offers two ways of simulating a swap to know either how much is needed to get a certain amount of tokens out of the pool (the output is known and the input is requested), or to know how much is going to be obtained from a swap after a certain amount of tokens are provided to the pool (the input is known and the output is requested). This is useful since this lets the user know the actual cost of a swap, and it can also give the user a point of reference to tell the pool how to calculate the slippage of the swap (in reality, the frontend usually handles this last step). To simulate a swap, these two functions are available: ```solidity theme={null} /** * @dev This is a simulation of the swap function. Useful to get marginal prices * @param _tokenIn the address of the token being sold * @param _amountIn the amount of the ERC20 _tokenIn to sell to the Pool * @return amountOut the amount of the token coming out of the Pool as result of the swap (main returned value) * @return lpFeeAmount the amount of the Y token that's being dedicated to fees for the LP * @return protocolFeeAmount the amount of the Y token that's being dedicated to fees for the protocol */ function simSwap( address _tokenIn, uint256 _amountIn ) public view returns (uint256 amountOut, uint256 lpFeeAmount, uint256 protocolFeeAmount); /** * @dev This is a simulation of the swap function from the perspective of purchasing a specific amount. Useful to get marginal price. * @param _tokenout the address of the token being bought * @param _amountOut the amount of the ERC20 _tokenOut to buy from the Pool * @return amountIn the amount necessary of the token coming into the Pool for the desired amountOut of the swap (main returned value) * @return lpFeeAmount the amount of the Y token that's being dedicated to fees for the LP * @return protocolFeeAmount the amount of the Y token that's being dedicated to fees for the protocol * @notice lpFeeAmount and protocolFeeAmount are already factored in the amountIn. This is useful only to know how much of the amountIn * will go towards fees. */ function simSwapReversed( address _tokenout, uint256 _amountOut ) public view returns (uint256 amountIn, uint256 lpFeeAmount, uint256 protocolFeeAmount); ``` Notice that in both functions we have a `lpFeeAmount` and the `protocolFeeAmount` values which are returned alongside the `amountIn`/`amountOut` (main returned value). These values are only informational as they have already been factored in the main returned value. Therefore, there is no need to carry out any addition/subtraction to use the `amountIn`/`amountOut` in the `swap` function. #### Slippage Slippage is defined as an absolute deviation value between an expected outcome and the actual outcome expressed as a minimum token result from the swap. This slippage calculation is done off-chain. The slippage check is used to ensure the outcome of the swap is greater than or equal to the minimum expected. Traders can set their own slippage tolerance when initiating the swap (see next section). #### Swaps Use the following function to carry out a swap. ```solidity theme={null} /** * @dev This is the main function of the pool to swap. * @param _tokenIn the address of the token being given to the pool in exchange for another token * @param _amountIn the amount of the ERC20 _tokenIn to exchange into the Pool * @param _minOut the amount of the other token in the pair minimum to be received for the * _amountIn of _tokenIn. * @return amountOut the actual amount of the token coming out of the Pool as result of the swap * @return lpFeeAmount the amount of the Y token that's being dedicated to fees for the LP * @return protocolFeeAmount the amount of the Y token that's being dedicated to fees for the protocol */ function swap( address _tokenIn, uint256 _amountIn, uint256 _minOut ) external returns (uint256 amountOut, uint256 lpFeeAmount, uint256 protocolFeeAmount); /** * @dev This function checks to verify the amount out will be greater than or equal to the minimum expected amount out. * @param _amountOut the actual amount being provided out by the swap * @param _minOut the expected amount out to compare against */ function _checkSlippage(uint256 _amountOut, uint256 _minOut) internal pure { if (_amountOut < (_minOut - 1)) revert MaxSlippageReached(); } ``` An important aspect to note is that the AMM expects the user to provide the amount of the token they're selling and the expected minimum amount out. In instances where the user's goal is to retrieve a specific amount out they can first use the 'simSwapReversed' function (defined above) to determine how much they'll need to sell to the AMM to receive the desired amount. ### Public Variables The pool has many public variables that expose aspects such as the curve characterization, the pair tokens, the state of the curve, etc.: ```solidity theme={null} /** * @dev A function to get the address of the x token of the pool. * @return the address of the x token of the pool * @notice this value is immutable */ function xToken() external returns (address); /** * @dev A function to get the address of the Y token of the pool. * @return the address of the Y token of the pool * @notice this value is immutable */ function yToken() external returns (address); /** * @dev tells pool yToken difference in the amount of decimals compared * to the pool native decimals * @return yDecimalDiff * @notice this value is immutable */ function yDecimalDiff() external returns (uint256); /** * @dev tells the minimum x that the pool is allowed to be at * @return xMin expressed in xToken decimals * @notice this value is immutable */ function xMin() external returns (uint256); /** * @dev tells the current values of the tbc * includes the parameters of the tbc * struct ALTBCDef { * packedFloat b; * packedFloat c; * packedFloat C; * packedFloat xMin; * packedFloat xMax; * packedFloat V; * packedFloat Zn; * } * @return tbc */ function tbc() returns (ALTBCDef); /** * @dev tells the current value of x. * @notice Outstanding liquidity can be calculated as x - xMin. * @return x expressed in xToken decimals */ function x() external returns (uint256); /** * @dev tells the lifetime claimed revenue of the pool * @return r expressed in the yToken native decimals */ function r() external returns (uint256); ``` ## Events Please visit next page for [Events](/concepts/events). # Pool Factory Source: https://docs.forteamm.io/concepts/pool-factory This contract is owned and managed by the product's team. It allows developers to deploy and set up their own pools. The following are the main technical aspects of this contract: See [FactoryBase.sol](). ## Deployers Allow List In order for a developer to be able to use the factory, they must first be added to the allow list in the Factory contract. Currently, only the product team can add or remove a deployer to the allow list. If you are interested in using our product and being added to the allow list, reach out at [liquidity@thrackle.io](mailto:liquidity@thrackle.io) . ## Pool Configurations For the pool to be properly setup, it is important to understand the parameters that it requires: ### Pairs A pool serves as a trading means for a pair of ERC20 tokens. This pair is composed of one ERC20 that we will call *the x-token* and another ERC20 that we will call *the y-token* aka **collateral token**. ### Available *y* Tokens This token can be chosen from a predetermined list which is maintained by the product's team. Currently available y-tokens are: | Network | Token | Address | | ---------------- | ----- | -------------------------------------------- | | Ethereum Mainnet | USDC | `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48` | | Base Mainnet | USDC | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` | | Ethereum Sepolia | USDC | `0x0BabdC1ef40e72C9D0ea04d831738cC923AdB9b4` | | Ethereum Sepolia | wETH | `0x177257fC3a214b8c2dD3142AaC7b0bb8a9fbD5a4` | | Base Sepolia | USDC | `0xfAAB528466868AAD7A5732F113De93f5133EF2ea` | | Base Sepolia | wETH | `0xe1d1a2C9e186D035E9d2c6a9c8a0B4025d76e7E7` | *Note:* The pool's default for decimals is 18. Upon creation of a pool an offset will be set for Collateral tokens with less than 18 decimals. The offset will be applied during swaps to make sure the difference in decimals is accounted for. ### *x* Token This can actually be any ERC20 token, even *y token*s, as long as it complies with the supply requirements: * **Max Supply For x-tokens**: The total supply of an x-token is set at construction, immutable, and must not be more than [100 billion tokens (assuming it has 18 decimals)](/concepts/bounds) to be part of a pool. * **Token uses 18 decimals**: It is an expectation for the x-token to use 18 decimals. Visit the [Token Support](/concepts/token-support) page for a more explicit list of token requirements. ### LP Fees Pools have an LP-fee feature which initial value must be set through the factory. Take into account that this fee value can also be updated at any time in the pool contract itself after deployed. The LP fee is the percentage of the swaps that the pool will set aside as a liquidity-provider fee. The fee will be collected and accumulated in y-tokens. This is a percentage expected to be in basis points (100 -> 1%). ### Curve Parameters * **b**: The slope of the tbc function. Related to the price impact of trades, if the slope is higher, a certain trade will move the price more. * **c**: The y-intercept of the tbc function. This is the price of the x-token when the pool is empty. * **C**: The concentration parameter of the tbc function. * **lowerPrice**: The initial lower price for an x-token. This is basically the initial price, in WAD, of the x-token to be bought from the pool. This value is expected in WAD (1 -> 1 \* 1e18). * **xMin**: The minimum value of variable x. * **xMax**: The highest price for an x-token. * **V**: Vector field parameter. * **Zn**: A balancing quantity that needs to be added to L for fair LP fee accounting. * **winactive**: The amount of liquidity that is inactive. It cannot extract revenue, cannot further add liquidity and removal of liquidity is on a modified flow. ## Protocol Fees Protocol fees are a portion of each swap that will go towards the protocol as a compensation for its service provided. The management of the protocol fee is under complete control of the protocol, and the factory plays a central role in this management. The following are the properties of the factory's protocol fees: * Protocol fees can be updated at any time only by the *owner* of the factory. * Protocol fees can be 0. * Protocol fees are expressed in basis points. * Protocol fees can be as high as 0.20%. ### Factory's protocol fee value The factory is in charge of setting the initial value of the protocol fees of the pools at deployment time. Only the *owner* of the factory can set this value. The following functions are available to manage the protocol fee: ```solidity theme={null} /** * @dev fee percentage for swaps for the protocol * @return the percentage for swaps in basis points that will go towards the protocol */ function protocolFee() external returns (uint16); /** * @dev This is the function to update the protocol fees per trading. * @param _protocolFee percentage of the transaction that will get collected as fees (in percentage basis points: * 10000 -> 100.00%; 500 -> 5.00%; 1 -> 0.01%) */ function setProtocolFee(uint16 _protocolFee) external; ``` ### Factory's protocol fee collector The factory is also in charge of setting the initial address of the protocol fee collector of the pools at deployment time. Only the *owner* of the factory can set this value. The following functions are available to manage this address: ```solidity theme={null} /** * @dev protocol-fee collector address * @return the current protocolFeeCollector address */ function protocolFeeCollector() external returns (address); /** * @dev proposed protocol-fee collector address * @return the current proposedProtocolFeeCollector address */ function proposedProtocolFeeCollector() external returns (address); /** * @dev function to propose a new protocol fee collector * @param _protocolFeeCollector the new fee collector * @notice that only the current fee collector address can call this function */ function proposeProtocolFeeCollector(address _protocolFeeCollector) external; /** * @dev function to confirm a new protocol fee collector * @notice that only the already proposed fee collector can call this function */ function confirmProtocolFeeCollector() external; ``` Notice that the process of assigning a new protocol fee collector is a 2-step process in order to prevent human errors from setting the wrong address: 1. The *owner* of the factory proposes a new protocol fee collector address through the function `proposeProtocolFeeCollector`. 2. The proposed protocol fee collector account then needs to call the `confirmProtocolFeeCollector` function to accept/confirm this role. ## Usage ### Deploy A New ALTBC Pool To deploy a new ALTBC pool, call the following function on the [ALTBCFactory](/reference/factory/ALTBCFactory.sol/contract.ALTBCFactory) contract: ```solidity theme={null} /** * @dev deploys an ALTBC pool * @param _xToken address of the X token (x axis) * @param _yToken address of the Y token (y axis) * @param _lpFee percentage of the fees in percentage basis points * @param _tbcInput input data for the pool * @param _xAdd the initial liquidity of xTokens that will be transferred to the pool * @param _name the name of the pool * @param _symbol the symbol of the pool * @return deployedPool the address of the deployed pool * @notice Only allowed deployers can deploy pools and only allowed yTokens are allowed */ function createPool( address _xToken, address _yToken, uint16 _lpFee, ALTBCInput memory _tbcInput, uint256 _xAdd, string memory _name, string memory _symbol ) external onlyAllowedDeployers onlyAllowedYTokens(_yToken) returns (address deployedPool) ``` This function returns the address of the new pool. *See [Pool documentation](/concepts/pool) for more details.* # Token Support Source: https://docs.forteamm.io/concepts/token-support The Forte Spot DEX AMM supports a subset of ERC20 tokens. This page outlines which tokens are supported and the requirements for compatibility. ## Supported X Tokens X tokens must meet the following requirements to be supported: * Tokens with exactly 18 decimals. * Tokens with a known maximum supply or upper limit on total supply. The tokens may be inflationary, but usage of this product assumes they have an upper limit on the supply. * Absent of fee-on-transfer mechanisms. * Standard ERC20 tokens with fixed supply mechanics (non-rebasing). ## Supported Y Tokens Y tokens must be selected from the approved list below. This list may be updated in the future. | Network | Token | Address | | ---------------- | ----- | -------------------------------------------- | | Ethereum Mainnet | USDC | `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48` | | Base Mainnet | USDC | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` | | Ethereum Sepolia | USDC | `0x0BabdC1ef40e72C9D0ea04d831738cC923AdB9b4` | | Ethereum Sepolia | wETH | `0x177257fC3a214b8c2dD3142AaC7b0bb8a9fbD5a4` | | Base Sepolia | USDC | `0xfAAB528466868AAD7A5732F113De93f5133EF2ea` | | Base Sepolia | wETH | `0xe1d1a2C9e186D035E9d2c6a9c8a0B4025d76e7E7` | # Add Liquidity Source: https://docs.forteamm.io/guides/add-liquidity Become an LP and add liquidity to existing pool Add liquidity to a Forte DEX pool to become a liquidity provider. You can deposit tokens through the hosted UI or integrate liquidity operations into your application. Choose your preferred method below to get started. Use the Forte AMM website to add liquidity Integrate liquidity operations into your application # Deploy Pool Source: https://docs.forteamm.io/guides/deploy-pool Create an AMM trading pool Deploy a new liquidity pool on Forte DEX. You can create pools using the hosted interface or deploy programmatically with code. Choose your preferred deployment method below. Use the Forte AMM website to create your pool Deploy pools programmatically using scripts # Overview Source: https://docs.forteamm.io/guides/overview How to use the guides These guides provide step-by-step instructions for the core operations on Forte DEX. Each guide is available in two formats: a UI-based walkthrough for using the Forte AMM interface, and a code-based guide for programmatic integration. Choose a guide below to get started. Execute token swaps through a pool Create and configure a new pool Add liquidity to your own or existing pools # Swap Tokens Source: https://docs.forteamm.io/guides/swap-tokens How to create swap transactions Swap tokens through a Forte DEX pool using either the hosted UI or by integrating swap functionality directly into your application. Choose your preferred method below to get started. Use the Forte AMM website to execute swaps Integrate swap functionality into your application # Introduction Source: https://docs.forteamm.io/introduction Welcome to the official Forte DEX documentation, where protocols **build sustainable liquid token economies**. ## Why Forte DEX? Traditional AMMs are expensive to operate and structurally volatile. They require large upfront capital deposits, ongoing incentive programs to retain liquidity, and produce *more* price volatility as trading increases. Healthy token economies need the opposite: markets that stabilize as they grow, where depth compounds over time and long-term participation is rewarded over speculation. Instead, projects are forced to choose between expensive liquidity programs that drain treasuries or thin markets that discourage adoption. Forte DEX solves this by treating **liquidity as a strategic asset, not an operational expense**: * **No Initial Collateral Required**: Launch a pool by depositing only the tokens you want to sell. Collateral accumulates naturally through trading activity. * **Protocol-Owned Liquidity**: Establish a permanent reserve that the project controls. No more renting liquidity that can disappear overnight. * **Zero Active Management**: Liquidity self adjusts with each trade. No rebalancing, no position management, no ongoing capital injections. * **Inverse Price Volatility**: Price impact *decreases* as more tokens circulate, creating stability as markets mature rather than amplifying speculation. * **Compounding Depth**: Trading revenue flows back into liquidity reserves through "smart fees," expanding market depth automatically over time. ## Our Distinguishing Factor Traditional AMMs use fixed invariants (like constant product) where the pricing rule never changes. Forte's Adjusting Linear Token Bonding Curve (ALTBC) is fundamentally different: **the pricing curve itself updates with every trade**. This creates three properties no fixed-curve AMM can achieve: 1. **Volatility decreases with adoption.** As more tokens circulate, our curve flattens and each subsequent trade moves the price less. Markets naturally stabilize as they grow. 2. **Collateral accrues regardless of direction.** Even when supply returns to previous levels after a round-trip of buys and sells, the protocol retains more collateral than before. Value accumulates with activity, not just with price appreciation. 3. **MEV is mathematically bounded.** Sandwich attacks have a maximum extractable profit defined by the curve mechanics and are not infinite like in constant-product AMMs. Large attacks become unprofitable. The result: markets that become **more stable, more liquid, and more resistant to manipulation** the longer they operate. ## Ideal For **Token Launches** Bootstrap liquidity from day one without locking treasury capital or diluting token supply. The protocol builds depth as trading occurs. No need for incentive programs or market maker agreements. **Community and Utility Tokens** Create economies designed for long-term participation. Decreasing volatility rewards holders and discourages speculation, aligning incentives around sustainable growth rather than short-term pumps. **Protocol-Owned Infrastructure** For DAOs and protocols that want to own their market infrastructure permanently. Liquidity becomes a compounding asset on the balance sheet, not a recurring expense. **Projects Exiting Mercenary LP Dynamics** Replace unreliable external liquidity with self-sustaining reserves. No more liquidity mining programs that drain treasuries or providers who exit during downturns. ## Dig Deeper Mathematical foundations and proofs Pool factory addresses and supported collateral tokens Step-by-step walkthroughs Core mechanics explained # Networks Source: https://docs.forteamm.io/networks Supported Networks for the Forte Spot DEX Factory | **Network** | **Pool Factory Address** | | :--------------- | -------------------------------------------- | | Base Mainnet | `0xd5a8965C648f0d0f0Dd5B15f042de5F32b3ff238` | | Ethereum Mainnet | `0x787ccd7fCD64d35E34DD7c16a2C6604755eecB76` | | Base Sepolia | `0x76F0EcD15f30c31B9347032e7A08045fB3b3E85b` | | Ethereum Sepolia | `0xCFA87f24b14F1A596809d5be34D00551f8a55661` | ### Supported Collateral Tokens | Network | Token | Address | | ---------------- | ----- | -------------------------------------------- | | Ethereum Mainnet | USDC | `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48` | | Base Mainnet | USDC | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` | | Ethereum Sepolia | USDC | `0x0BabdC1ef40e72C9D0ea04d831738cC923AdB9b4` | | Ethereum Sepolia | wETH | `0x177257fC3a214b8c2dD3142AaC7b0bb8a9fbD5a4` | | Base Sepolia | USDC | `0xfAAB528466868AAD7A5732F113De93f5133EF2ea` | | Base Sepolia | wETH | `0xe1d1a2C9e186D035E9d2c6a9c8a0B4025d76e7E7` | # ALTBCDef Source: https://docs.forteamm.io/reference/amm/ALTBC.sol/struct.ALTBCDef [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/amm/ALTBC.sol) **Author:** @oscarsernarosero @mpetersoCode55 @cirsteve ALTBC *All TBC definitions can be found here.* ```solidity theme={null} struct ALTBCDef { packedFloat b; packedFloat c; packedFloat C; packedFloat xMin; packedFloat xMax; packedFloat V; packedFloat Zn; } ``` # ALTBCInput Source: https://docs.forteamm.io/reference/amm/ALTBC.sol/struct.ALTBCInput [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/amm/ALTBC.sol) ```solidity theme={null} struct ALTBCInput { uint256 _lowerPrice; uint256 _V; uint256 _xMin; uint256 _C; } ``` # ALTBCEquations Source: https://docs.forteamm.io/reference/amm/ALTBCEquations.sol/library.ALTBCEquations [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/amm/ALTBCEquations.sol) **Author:** @oscarsernarosero @mpetersoCode55 @cirsteve @palmerg4 ## State Variables ### FLOAT\_2 ```solidity theme={null} packedFloat constant FLOAT_2 = packedFloat.wrap(0x7f6c00000000000000000000000000000f0bdc21abb48db201e86d4000000000); ``` ### FLOAT\_NEG\_1 ```solidity theme={null} packedFloat constant FLOAT_NEG_1 = packedFloat.wrap(0x7f6d00000000000000000000000000000785ee10d5da46d900f436a000000000); ``` ### FLOAT\_0 ```solidity theme={null} packedFloat constant FLOAT_0 = packedFloat.wrap(0); ``` ### FLOAT\_1 ```solidity theme={null} packedFloat constant FLOAT_1 = packedFloat.wrap(0x7f6c00000000000000000000000000000785ee10d5da46d900f436a000000000); ``` ### FLOAT\_WAD ```solidity theme={null} packedFloat constant FLOAT_WAD = packedFloat.wrap(57507338264406853159277167054180511853162945875507645848942038639672188469248); ``` ## Functions ### calculateBn The result will be a packedFloat Bn is equal to V / (Xn + C) in the spec *This function calculates B(n) and stores it in the tbc definition as b.* ```solidity theme={null} function calculateBn(ALTBCDef storage altbc, packedFloat Xn) internal; ``` **Parameters** | Name | Type | Description | | ------- | ------------- | ------------------ | | `altbc` | `ALTBCDef` | the tbc definition | | `Xn` | `packedFloat` | the X value at n | ### calculatefx The result for f(x) will be a packedFloat. This equation is used to calculate the spot price of the x token and is equal to (bn \* x) + cn *This function calculates f(x) at n.* ```solidity theme={null} function calculatefx(ALTBCDef storage altbc, packedFloat x) internal view returns (packedFloat result); ``` **Parameters** | Name | Type | Description | | ------- | ------------- | ------------------ | | `altbc` | `ALTBCDef` | the tbc definition | | `x` | `packedFloat` | value for x at n | **Returns** | Name | Type | Description | | -------- | ------------- | ----------------------------------------------------- | | `result` | `packedFloat` | the calculated f(x), this value will be a packedFloat | ### calculateDn The result for Dn will be a packedFloat This equation is used to calculate the area under the curve at n and is equal to (1/2)(bn*x^2) + cn*x *This function calculates D at n.* ```solidity theme={null} function calculateDn(ALTBCDef storage altbc, packedFloat x) internal view returns (packedFloat result); ``` **Parameters** | Name | Type | Description | | ------- | ------------- | ------------------ | | `altbc` | `ALTBCDef` | the tbc definition | | `x` | `packedFloat` | value for x at n | **Returns** | Name | Type | Description | | -------- | ------------- | ----------- | | `result` | `packedFloat` | result | ### calculateH This method is implemented using packedFloats and the float128 library This equation in the spec is equal to (Ln + Zn) / (Wn - wInactive) + phi *This function calculates h at n which is the total revenue per unit of liquidity at time n.* ```solidity theme={null} function calculateH(ALTBCDef storage altbc, packedFloat L, packedFloat W, packedFloat wInactive, packedFloat phi) internal view returns (packedFloat result); ``` **Parameters** | Name | Type | Description | | ----------- | ------------- | ----------------------------------------------------- | | `altbc` | `ALTBCDef` | | | `L` | `packedFloat` | the x coordinate | | `W` | `packedFloat` | the total amount of units of liquidity in circulation | | `wInactive` | `packedFloat` | | | `phi` | `packedFloat` | the total amount of units of liquidity in circulation | **Returns** | Name | Type | Description | | -------- | ------------- | ---------------- | | `result` | `packedFloat` | the calculated h | ### calculateXofNPlus1 This method is implemented using packedFloats and the float128 library This equation in the spec is equal to 2Dn / (c + sqrt(c^2 + 2bDn)) *This function calculates the value of Xn+1.* ```solidity theme={null} function calculateXofNPlus1(ALTBCDef storage altbc, packedFloat Dn) internal view returns (packedFloat newX); ``` **Parameters** | Name | Type | Description | | ------- | ------------- | ------------------------- | | `altbc` | `ALTBCDef` | the tbc definition | | `Dn` | `packedFloat` | the area under the curve. | **Returns** | Name | Type | Description | | ------ | ------------- | ------------------- | | `newX` | `packedFloat` | the calculated Xn+1 | ### calculateC *This function calculates the parameter c and stores it in the tbc definition.* ```solidity theme={null} function calculateC(ALTBCDef storage altbc, packedFloat Xn, packedFloat oldBn) internal; ``` **Parameters** | Name | Type | Description | | ------- | ------------- | ----------------------- | | `altbc` | `ALTBCDef` | the tbc definition. | | `Xn` | `packedFloat` | the x coordinate | | `oldBn` | `packedFloat` | the previous state of b | ### calculateLastRevenueClaim The result for last revenue claim will be a Float. *This function calculates the last revenue claim to be stored in the associated LPToken variable rj. The result will be a WAD value.* ```solidity theme={null} function calculateLastRevenueClaim(packedFloat hn, packedFloat wj, packedFloat r_hat, packedFloat w_hat) internal pure returns (packedFloat); ``` **Parameters** | Name | Type | Description | | ------- | ------------- | -------------------------------------------------------------------------------------------- | | `hn` | `packedFloat` | The revenue parameter. Expected to be a Float. | | `wj` | `packedFloat` | The share of the pool's liquidity the associated LPToken represents. Expected to be a Float. | | `r_hat` | `packedFloat` | The current last revenue claim value of the associated LPToken. Expected to be a Float. | | `w_hat` | `packedFloat` | The current liquidity amount of the associated LPToken. Expected to be a Float. | ### calculateL *This function calculates the parameter L.* ```solidity theme={null} function calculateL(ALTBCDef storage altbc, packedFloat Xn) internal view returns (packedFloat result); ``` **Parameters** | Name | Type | Description | | ------- | ------------- | ------------------- | | `altbc` | `ALTBCDef` | the tbc definition. | | `Xn` | `packedFloat` | the x coordinate | **Returns** | Name | Type | Description | | -------- | ------------- | -------------------------- | | `result` | `packedFloat` | the calculate L parameter. | ### calculateZ *This function calculates the parameter Z, which is a balancing quantity used to ensure fair LP accounting.* ```solidity theme={null} function calculateZ( ALTBCDef storage altbc, packedFloat Ln, packedFloat Wn, packedFloat WIn, packedFloat q, bool withdrawal ) internal; ``` **Parameters** | Name | Type | Description | | ------------ | ------------- | ------------------------------------------------------ | | `altbc` | `ALTBCDef` | the tbc definition. | | `Ln` | `packedFloat` | the liquidity parameter. | | `Wn` | `packedFloat` | the total amount of units of liquidity in circulation. | | `WIn` | `packedFloat` | the total amount of units of liquidity in circulation. | | `q` | `packedFloat` | the liquidity units to receive in exchange for A and B | | `withdrawal` | `bool` | the boolean value for withdrawal | ### calculateQ *This function calculates q.* ```solidity theme={null} function calculateQ( ALTBCDef storage altbc, packedFloat Xn, packedFloat _A, packedFloat _B, packedFloat L, packedFloat Dn ) internal view returns (packedFloat A, packedFloat B, packedFloat q); ``` **Parameters** | Name | Type | Description | | ------- | ------------- | ---------------------------------- | | `altbc` | `ALTBCDef` | the tbc definition. | | `Xn` | `packedFloat` | the x coordinate | | `_A` | `packedFloat` | The amount of incoming X Token. | | `_B` | `packedFloat` | The amount of incoming collateral. | | `L` | `packedFloat` | the liquidity parameter. | | `Dn` | `packedFloat` | The current area under the curve. | **Returns** | Name | Type | Description | | ---- | ------------- | ------------------------------------------------------ | | `A` | `packedFloat` | the actual amount to take for token x | | `B` | `packedFloat` | the actual amount to take for token y | | `q` | `packedFloat` | the liquidity units to receive in exchange for A and B | ### calculateRevenueAvailable *This function calculates the revenue available for a given LPToken.* ```solidity theme={null} function calculateRevenueAvailable(packedFloat wj, packedFloat hn, packedFloat rj) internal pure returns (packedFloat result); ``` **Parameters** | Name | Type | Description | | ---- | ------------- | -------------------------------------------------------------------- | | `wj` | `packedFloat` | The share of the pool's liquidity the associated LPToken represents. | | `hn` | `packedFloat` | The revenue parameter. | | `rj` | `packedFloat` | The last revenue claim for the associated LPToken. | **Returns** | Name | Type | Description | | -------- | ------------- | ------------------------------------------------- | | `result` | `packedFloat` | The calculated revenue available for the LPToken. | ### \_liquidityUpdateHelper *This function updates related tbc variables when a liquidity deposit or withdrawal is made* ```solidity theme={null} function _liquidityUpdateHelper(ALTBCDef storage altbc, packedFloat Xn, packedFloat multiplier) internal returns (packedFloat x); ``` **Parameters** | Name | Type | Description | | ------------ | ------------- | --------------------------------------- | | `altbc` | `ALTBCDef` | the tbc definition. | | `Xn` | `packedFloat` | the x coordinate. | | `multiplier` | `packedFloat` | The value for multiplier for pool state | **Returns** | Name | Type | Description | | ---- | ------------- | -------------------- | | `x` | `packedFloat` | The updated x value. | # ALTBCPool Source: https://docs.forteamm.io/reference/amm/ALTBCPool.sol/contract.ALTBCPool [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/amm/ALTBCPool.sol) **Inherits:** PoolBase, Initializable **Author:** @oscarsernarosero @mpetersoCode55 @cirsteve *This contract serves the purpose of facilitating swaps between a pair of tokens, where one is an xToken and the other one is a yToken.* ## State Variables ### tbc ```solidity theme={null} ALTBCDef public tbc; ``` ## Functions ### constructor *constructor* ```solidity theme={null} constructor( address _xToken, address _yToken, address _lpToken, uint256 _inactiveLpId, FeeInfo memory fees, ALTBCInput memory _tbcInput, string memory _VERSION ) PoolBase(_xToken, _yToken, _lpToken, _inactiveLpId, fees); ``` **Parameters** | Name | Type | Description | | --------------- | ------------ | ------------------------------- | | `_xToken` | `address` | address of the X token (x axis) | | `_yToken` | `address` | address of the Y token (y axis) | | `_lpToken` | `address` | | | `_inactiveLpId` | `uint256` | | | `fees` | `FeeInfo` | fee infomation | | `_tbcInput` | `ALTBCInput` | input parameters for the TBC | | `_VERSION` | `string` | | ### initializePool *This is the function to initialize the pool.* ```solidity theme={null} function initializePool(address deployer, uint256 initialLiq, uint256 ___wInactive) external onlyOwner initializer; ``` **Parameters** | Name | Type | Description | | -------------- | --------- | --------------------------------------- | | `deployer` | `address` | The address of the deployer | | `initialLiq` | `uint256` | | | `___wInactive` | `uint256` | initial inactive liquidity for the pool | ### simulateLiquidityDeposit *This is the function to simulate a liquidity deposit into the pool.* ```solidity theme={null} function simulateLiquidityDeposit(uint256 _A, uint256 _B) public view returns (uint256 A, uint256 B, uint256 Q, int256 ratio, packedFloat qFloat, packedFloat L); ``` **Parameters** | Name | Type | Description | | ---- | --------- | -------------------------------------------------------------------- | | `_A` | `uint256` | The amount of xToken being deposited as liquidity in the simulation. | | `_B` | `uint256` | The amount of yToken being deposited as liquidity in the simulation. | **Returns** | Name | Type | Description | | -------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------- | | `A` | `uint256` | calculated A value which is the amount of xToken that will be deposited | | `B` | `uint256` | calculated B value which is the amount of yToken that will be deposited | | `Q` | `uint256` | calculated Q value which is the ratio of this provided liquidity unit to the total liquidity of the pool | | `ratio` | `int256` | calculated ratio of xToken to yToken required for the deposit | | `qFloat` | `packedFloat` | calculated qFloat value which is the ratio of this provided liquidity unit to the total liquidity of the pool in packedFloat format | | `L` | `packedFloat` | | ### tokenDepositUpdate ```solidity theme={null} function tokenDepositUpdate(uint256 tokenId, packedFloat wj) internal returns (uint256); ``` ### depositLiquidity If the tokenId provided is owned by the lp, this tokenId will be updated based on liquidity deposit *This is the function to deposit liquidity into the pool.* ```solidity theme={null} function depositLiquidity(uint256 tokenId, uint256 _A, uint256 _B, uint256 _minA, uint256 _minB, uint256 expires) external whenNotPaused checkExpiration(expires) returns (uint256 A, uint256 B); ``` **Parameters** | Name | Type | Description | | --------- | --------- | ------------------------------------------------------------------------ | | `tokenId` | `uint256` | The tokenId owned by the liquidity provider. | | `_A` | `uint256` | The amount of xToken being deposited as liquidity. | | `_B` | `uint256` | The amount of yToken being deposited as liquidity. | | `_minA` | `uint256` | The minimum acceptable amount of xToken actually deposited as liquidity. | | `_minB` | `uint256` | The minimum acceptable amount of yToken actually deposited as liquidity. | | `expires` | `uint256` | Timestamp at which the deposit transaction will expire. | **Returns** | Name | Type | Description | | ---- | --------- | ------------------ | | `A` | `uint256` | calculated A value | | `B` | `uint256` | calculated B value | ### simulateWithdrawLiquidity *This is the function to simulate a liquidity withdrawal from the pool.* *To get rj and uj, call the getLPToken function and pass in the rj and uj values* ```solidity theme={null} function simulateWithdrawLiquidity(uint256 tokenId, uint256 uj, packedFloat _uj) public view returns ( uint256 Ax, uint256 Ay, uint256 revenueAccrued, packedFloat q, packedFloat L, packedFloat wj, packedFloat rj ); ``` **Parameters** | Name | Type | Description | | --------- | ------------- | ------------------------------------------------------------- | | `tokenId` | `uint256` | The tokenId owned by the liquidity provider. | | `uj` | `uint256` | The amount of liquidity being withdrawn | | `_uj` | `packedFloat` | The amount of liquidity being withdrawn in packedFloat format | **Returns** | Name | Type | Description | | ---------------- | ------------- | ---------------------------------------------------------------------------- | | `Ax` | `uint256` | The amount of xToken to be received | | `Ay` | `uint256` | The amount of yToken to be received | | `revenueAccrued` | `uint256` | The amount of revenue accrued to the liquidity position | | `q` | `packedFloat` | The ratio of this provided liquidity unit to the total liquidity of the pool | | `L` | `packedFloat` | | | `wj` | `packedFloat` | | | `rj` | `packedFloat` | | ### withdrawPartialLiquidity *This is the function to withdraw partial liquidity from the pool.* ```solidity theme={null} function withdrawPartialLiquidity( uint256 tokenId, uint256 uj, address recipient, uint256 _minAx, uint256 _minAy, uint256 expires ) external checkExpiration(expires); ``` **Parameters** | Name | Type | Description | | ----------- | --------- | -------------------------------------------------------------------------- | | `tokenId` | `uint256` | The tokenId owned by the liquidity provider. | | `uj` | `uint256` | The amount of liquidity being withdrawn | | `recipient` | `address` | address that receives withdrawn liquidity | | `_minAx` | `uint256` | The minimum acceptable amount of xToken actually withdrawn from liquidity. | | `_minAy` | `uint256` | The minimum acceptable amount of yToken actually withdrawn from liquidity. | | `expires` | `uint256` | Timestamp at which the withdraw transaction will expire. | ### withdrawAllLiquidity *This is the function to withdraw all token liquidity from the pool.* ```solidity theme={null} function withdrawAllLiquidity(uint256 tokenId, address recipient, uint256 _minAx, uint256 _minAy, uint256 expires) external checkExpiration(expires); ``` **Parameters** | Name | Type | Description | | ----------- | --------- | -------------------------------------------------------------------------- | | `tokenId` | `uint256` | The tokenId owned by the liquidity provider. | | `recipient` | `address` | address that receives withdrawn liquidity | | `_minAx` | `uint256` | The minimum acceptable amount of xToken actually withdrawn from liquidity. | | `_minAy` | `uint256` | The minimum acceptable amount of yToken actually withdrawn from liquidity. | | `expires` | `uint256` | Timestamp at which the withdraw transaction will expire. | ### \_withdrawLiquidity *This is the function to withdraw liquidity from the pool.* ```solidity theme={null} function _withdrawLiquidity(uint256 tokenId, packedFloat _uj, address recipient, uint256 _minAx, uint256 _minAy) internal; ``` **Parameters** | Name | Type | Description | | ----------- | ------------- | -------------------------------------------------------------------------- | | `tokenId` | `uint256` | The tokenId owned by the liquidity provider. | | `_uj` | `packedFloat` | The amount of liquidity being withdrawn | | `recipient` | `address` | address that receives withdrawn liquidity | | `_minAx` | `uint256` | The minimum acceptable amount of xToken actually withdrawn from liquidity. | | `_minAy` | `uint256` | The minimum acceptable amount of yToken actually withdrawn from liquidity. | ### \_emitLiquidityWithdrawn *This is the function to emit the LiquidityWithdrawn event.* ```solidity theme={null} function _emitLiquidityWithdrawn(uint256 tokenId, uint256 Ax, uint256 Ay, uint256 revenueAccrued, address recipient) private; ``` **Parameters** | Name | Type | Description | | ---------------- | --------- | ------------------------------------------------------- | | `tokenId` | `uint256` | The tokenId owned by the liquidity provider. | | `Ax` | `uint256` | The amount of xToken to be received | | `Ay` | `uint256` | The amount of yToken to be received | | `revenueAccrued` | `uint256` | The amount of revenue accrued to the liquidity position | | `recipient` | `address` | The address that receives the withdrawn liquidity | ### withdrawRevenue *This is the function to withdraw revenue from the pool.* ```solidity theme={null} function withdrawRevenue(uint256 tokenId, uint256 Q, address recipient) external returns (uint256 revenue); ``` **Parameters** | Name | Type | Description | | ----------- | --------- | -------------------------------------------- | | `tokenId` | `uint256` | The tokenId owned by the liquidity provider. | | `Q` | `uint256` | The amount of revenue being withdrawn | | `recipient` | `address` | | **Returns** | Name | Type | Description | | --------- | --------- | ------------------------------------- | | `revenue` | `uint256` | The amount of revenue being withdrawn | ### revenueAvailable *This is the function to get the revenue available for a liquidity position.* ```solidity theme={null} function revenueAvailable(uint256 tokenId) public view returns (uint256 _revenueAvailable); ``` **Parameters** | Name | Type | Description | | --------- | --------- | ----------------------------------------------- | | `tokenId` | `uint256` | The tokenId representing the liquidity position | **Returns** | Name | Type | Description | | ------------------- | --------- | ---------------------------------------------------------- | | `_revenueAvailable` | `uint256` | The amount of revenue available for the liquidity position | ### \_getRevenueAvailable *This is the function to get the revenue available for a liquidity provider.* ```solidity theme={null} function _getRevenueAvailable(uint256 tokenId) internal view returns ( packedFloat hn, packedFloat _wj, packedFloat _rj, packedFloat _revenueAvailable, uint256 revenueAvailableUint ); ``` **Parameters** | Name | Type | Description | | --------- | --------- | ------------------------------------------- | | `tokenId` | `uint256` | The tokenId owned by the liquidity provider | **Returns** | Name | Type | Description | | ---------------------- | ------------- | ---------------------------------------------------------- | | `hn` | `packedFloat` | The total revenue per liquidity unit for the pool | | `_wj` | `packedFloat` | The amount of liquidity units of the specified token | | `_rj` | `packedFloat` | The revenue accrued to the liquidity position | | `_revenueAvailable` | `packedFloat` | The amount of revenue available for the liquidity provider | | `revenueAvailableUint` | `uint256` | | ### \_spotPrice x + 1 is used for returning the price of the next token sold, not the price of the last token sold *This is the function to retrieve the current spot price of the x token.* ```solidity theme={null} function _spotPrice() internal view override returns (packedFloat sPrice); ``` **Returns** | Name | Type | Description | | -------- | ------------- | ---------------------------- | | `sPrice` | `packedFloat` | the price in YToken Decimals | ### \_updateParameters *This function updates the state of the math values of the pool.* ```solidity theme={null} function _updateParameters() internal override; ``` ### \_calculateAmountOfXRequiredBuyingY *This function calculates the amount of token X required for the user to purchase a specific amount of Token Y (buy y with x : out perspective).* ```solidity theme={null} function _calculateAmountOfXRequiredBuyingY(packedFloat _amountOfY) internal view override returns (packedFloat amountOfX); ``` **Parameters** | Name | Type | Description | | ------------ | ------------- | ------------------------- | | `_amountOfY` | `packedFloat` | desired amount of token Y | **Returns** | Name | Type | Description | | ----------- | ------------- | -------------------------- | | `amountOfX` | `packedFloat` | required amount of token X | ### \_calculateAmountOfYRequiredBuyingX *This function calculates the amount of token Y required for the user to purchase a specific amount of Token X (buy x with y : out perspective).* ```solidity theme={null} function _calculateAmountOfYRequiredBuyingX(packedFloat _amountOfX) internal view override returns (packedFloat amountOfY); ``` **Parameters** | Name | Type | Description | | ------------ | ------------- | -------------------------------------------------------- | | `_amountOfX` | `packedFloat` | desired amount of token X (also known as An in the spec) | **Returns** | Name | Type | Description | | ----------- | ------------- | -------------------------- | | `amountOfY` | `packedFloat` | required amount of token Y | ### \_calculateAmountOfYReceivedSellingX *This function calculates the amount of token Y the user will receive when selling token X (sell x for y : in perspective).* ```solidity theme={null} function _calculateAmountOfYReceivedSellingX(packedFloat _amountOfX) internal view override returns (packedFloat amountOfY); ``` **Parameters** | Name | Type | Description | | ------------ | ------------- | ---------------------------- | | `_amountOfX` | `packedFloat` | amount of token X to be sold | **Returns** | Name | Type | Description | | ----------- | ------------- | -------------------------------- | | `amountOfY` | `packedFloat` | amount of token Y to be received | ### \_calculateAmountOfXReceivedSellingY *This function calculates the amount of token X the user will receive when selling token Y (sell y for x : in perspective).* ```solidity theme={null} function _calculateAmountOfXReceivedSellingY(packedFloat _amountOfY) internal view override returns (packedFloat amountOfX); ``` **Parameters** | Name | Type | Description | | ------------ | ------------- | ---------------------------- | | `_amountOfY` | `packedFloat` | amount of token Y to be sold | **Returns** | Name | Type | Description | | ----------- | ------------- | -------------------------------- | | `amountOfX` | `packedFloat` | amount of token X to be received | ### \_validateTBC *A helper function to validate most of constructor's inputs.* ```solidity theme={null} function _validateTBC(ALTBCInput memory _tbcInput) internal pure; ``` **Parameters** | Name | Type | Description | | ----------- | ------------ | ---------------------------- | | `_tbcInput` | `ALTBCInput` | input parameters for the TBC | ### checkInactiveLiquidity The threshold is set to 1% of the active liquidity units *Check for ration of inactive to active (token Id 2) liquidity, reverts if ratio is above threshold* ```solidity theme={null} function checkInactiveLiquidity(packedFloat _active, packedFloat _inactive) internal pure; ``` **Parameters** | Name | Type | Description | | ----------- | ------------- | ------------------------ | | `_active` | `packedFloat` | active liquidity units | | `_inactive` | `packedFloat` | inactive liquidity units | ### retrieveH ```solidity theme={null} function retrieveH() public view returns (packedFloat h); ``` ### \_emitCurveState ```solidity theme={null} function _emitCurveState() internal override; ``` # null Source: https://docs.forteamm.io/reference/amm/README # Contents * [ALTBCDef](/reference/amm/ALTBC.sol/struct.ALTBCDef) * [ALTBCInput](/reference/amm/ALTBC.sol/struct.ALTBCInput) * [ALTBCEquations](/reference/amm/ALTBCEquations.sol/library.ALTBCEquations) * [ALTBCPool](/reference/amm/ALTBCPool.sol/contract.ALTBCPool) # FactoryDeployHelper Source: https://docs.forteamm.io/reference/common/FactoryDeployHelper.sol/contract.FactoryDeployHelper [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/common/FactoryDeployHelper.sol) ## Functions ### setPoolByteCode the setByteCode function is expected to receive only bytes as its only parameter the makeByteCodeImmutable function is expected to receive no parameters *helper function to send the byte code in chunks to the factory and then make it immutable* ```solidity theme={null} function setPoolByteCode( address factoryAddress, bytes memory bytecode, uint256 chunks, bytes4 setByteCodeSelector, bytes4 makeImmutableSelector ) internal; ``` **Parameters** | Name | Type | Description | | ----------------------- | --------- | ------------------------------------------------- | | `factoryAddress` | `address` | address of the factory where to set the byte code | | `bytecode` | `bytes` | the full byte code to set | | `chunks` | `uint256` | number of chunks to split the byte code into | | `setByteCodeSelector` | `bytes4` | selector of the setByteCode function | | `makeImmutableSelector` | `bytes4` | selector of the makeByteCodeImmutable function | ### slice this function was taken from [https://stackoverflow.com/questions/74443594/how-to-slice-bytes-memory-in-solidity](https://stackoverflow.com/questions/74443594/how-to-slice-bytes-memory-in-solidity) *helper function to slice bytes arrays* ```solidity theme={null} function slice(bytes memory _bytes, uint256 _start, uint256 _length) private pure returns (bytes memory); ``` **Parameters** | Name | Type | Description | | --------- | --------- | ------------------------ | | `_bytes` | `bytes` | the bytes array to slice | | `_start` | `uint256` | the starting index | | `_length` | `uint256` | the length of the slice | **Returns** | Name | Type | Description | | -------- | ------- | -------------------------------- | | `` | `bytes` | tempBytes the sliced bytes array | # ALTBCCurveState Source: https://docs.forteamm.io/reference/common/IALTBCEvents.sol/event.ALTBCCurveState [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/common/IALTBCEvents.sol) ```solidity theme={null} event ALTBCCurveState(ALTBCDef altbc, packedFloat x); ``` # ALTBCFactoryDeployed Source: https://docs.forteamm.io/reference/common/IALTBCEvents.sol/event.ALTBCFactoryDeployed [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/common/IALTBCEvents.sol) ```solidity theme={null} event ALTBCFactoryDeployed(string _version); ``` # ALTBCPoolDeployed Source: https://docs.forteamm.io/reference/common/IALTBCEvents.sol/event.ALTBCPoolDeployed [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/common/IALTBCEvents.sol) ```solidity theme={null} event ALTBCPoolDeployed( address indexed _xToken, address indexed _yToken, string _version, uint16 _lpFee, uint16 _protocolFee, address _protocolFeeCollector, ALTBCInput _tbcInput ); ``` # null Source: https://docs.forteamm.io/reference/common/README # Contents * [FactoryDeployHelper](/reference/common/FactoryDeployHelper.sol/contract.FactoryDeployHelper) * [ALTBCFactoryDeployed](/reference/common/IALTBCEvents.sol/event.ALTBCFactoryDeployed) * [ALTBCPoolDeployed](/reference/common/IALTBCEvents.sol/event.ALTBCPoolDeployed) * [ALTBCCurveState](/reference/common/IALTBCEvents.sol/event.ALTBCCurveState) # ALTBCFactory Source: https://docs.forteamm.io/reference/factory/ALTBCFactory.sol/contract.ALTBCFactory [Git Source](https://github.com/thrackle-io/liquidity-altbc/blob/a089af3d235b9241cf0ed6c700a259b616853515/src/factory/ALTBCFactory.sol) **Inherits:** FactoryBase **Author:** @oscarsernarosero @mpetersoCode55 @cirsteve *creates the pools in an automated and permissioned fashion* ## State Variables ### altbcBytecode ```solidity theme={null} bytes altbcBytecode; ``` ### isByteCodeImmutable ```solidity theme={null} bool public isByteCodeImmutable; ``` ### VERSION ```solidity theme={null} string public constant VERSION = "v1.0.0"; ``` ## Functions ### onlyIfByteCodeNotImmutable ```solidity theme={null} modifier onlyIfByteCodeNotImmutable(); ``` ### constructor *constructor receives and saves the ALTBCPool byte code to bypass contract side limit* ```solidity theme={null} constructor(); ``` ### createPool Only allowed deployers can deploy pools and only allowed yTokens are allowed *deploys an ALTBC pool* ```solidity theme={null} function createPool( address _xToken, address _yToken, uint16 _lpFee, ALTBCInput memory _tbcInput, uint256 _xAdd, uint256 _wInactive ) external onlyAllowedDeployers onlyAllowedYTokens(_yToken) returns (address deployedPool); ``` **Parameters** | Name | Type | Description | | ------------ | ------------ | --------------------------------------------------------------------- | | `_xToken` | `address` | address of the X token (x axis) | | `_yToken` | `address` | address of the Y token (y axis) | | `_lpFee` | `uint16` | percentage of the fees in percentage basis points | | `_tbcInput` | `ALTBCInput` | input data for the pool | | `_xAdd` | `uint256` | the initial liquidity of xTokens that will be transferred to the pool | | `_wInactive` | `uint256` | | **Returns** | Name | Type | Description | | -------------- | --------- | -------------------------------- | | `deployedPool` | `address` | the address of the deployed pool | ### setByteCode ```solidity theme={null} function setByteCode(bytes calldata _byteCode) external onlyOwner onlyIfByteCodeNotImmutable; ``` ### makeByteCodeImmutable ```solidity theme={null} function makeByteCodeImmutable() external onlyOwner onlyIfByteCodeNotImmutable; ``` # null Source: https://docs.forteamm.io/reference/factory/README # Contents * [ALTBCFactory](/reference/factory/ALTBCFactory.sol/contract.ALTBCFactory) # Overview Source: https://docs.forteamm.io/reference/overview * [❱ amm](/reference/amm/README) * [ALTBCDef](/reference/amm/ALTBC.sol/struct.ALTBCDef) * [ALTBCInput](/reference/amm/ALTBC.sol/struct.ALTBCInput) * [ALTBCEquations](/reference/amm/ALTBCEquations.sol/library.ALTBCEquations) * [ALTBCPool](/reference/amm/ALTBCPool.sol/contract.ALTBCPool) * [❱ common](/reference/common/README) * [FactoryDeployHelper](/reference/common/FactoryDeployHelper.sol/contract.FactoryDeployHelper) * [ALTBCFactoryDeployed](/reference/common/IALTBCEvents.sol/event.ALTBCFactoryDeployed) * [ALTBCPoolDeployed](/reference/common/IALTBCEvents.sol/event.ALTBCPoolDeployed) * [ALTBCCurveState](/reference/common/IALTBCEvents.sol/event.ALTBCCurveState) * [❱ factory](/reference/factory/README) * [ALTBCFactory](/reference/factory/ALTBCFactory.sol/contract.ALTBCFactory)