From b47dd26c54495be2b708eb78d0bc4900f914b778 Mon Sep 17 00:00:00 2001 From: duelinggalois Date: Tue, 3 Feb 2026 16:57:07 +0000 Subject: [PATCH] Updated contract docs for synchronize pull request fix/saturation-update-division-by-zero --- .../AmmalgamPair.sol/contract.AmmalgamPair.md | 33 +++--- ...ontract.SaturationAndGeometricTWAPState.md | 29 ++++- .../contract.AmmalgamFactory.md | 2 +- ...contract.ERC20DebtLiquidityTokenFactory.md | 2 +- .../contract.ERC20LiquidityTokenFactory.md | 2 +- .../contract.ERC4626DebtTokenFactory.md | 2 +- .../contract.ERC4626DepositTokenFactory.md | 2 +- .../interface.IAmmalgamPair.md | 2 +- ...erface.ISaturationAndGeometricTWAPState.md | 29 ++++- .../interface.IBorrowCallback.md | 2 +- .../interface.ICallback.md | 2 +- .../interface.ISwapCallback.md | 2 +- .../interface.ITransferValidator.md | 2 +- .../interface.IAmmalgamFactory.md | 2 +- .../interface.IBeaconCallback.md | 2 +- .../interface.IFactoryCallback.md | 2 +- .../interface.ITokenFactory.md | 2 +- .../interface.IAmmalgamERC20.md | 2 +- .../interface.IERC20DebtToken.md | 2 +- .../interface.IHookRegistry.md | 2 +- .../constants.ITokenController.md | 2 +- .../interface.ITokenController.md | 8 +- .../libraries/Convert.sol/library.Convert.md | 2 +- .../library.GeometricTWAP.md | 2 +- .../Interest.sol/library.Interest.md | 2 +- .../Liquidation.sol/library.Liquidation.md | 56 ++++------ .../library.PartialLiquidations.md | 2 +- .../library.QuadraticSwapFees.md | 2 +- .../Saturation.sol/library.Saturation.md | 101 +++++++++++++++--- .../TickMath.sol/library.TickMath.md | 2 +- .../TokenSymbol.sol/library.TokenSymbol.md | 2 +- .../Uint16Set.sol/library.Uint16Set.md | 2 +- .../Validation.sol/library.Validation.md | 98 ++--------------- .../constants.sol/constants.constants.md | 2 +- .../contract.BeaconController.md | 2 +- .../interface.IBeaconController.md | 2 +- .../contract.InitializablePair.md | 2 +- .../contract.PairBeaconProxy.md | 2 +- .../interface.IPairInitializable.md | 2 +- .../contract.PairBlockAllTransfers.md | 2 +- .../PairFrozen.sol/contract.PairFrozen.md | 2 +- .../contract.PairLockedLoans.md | 2 +- .../ERC20Base.sol/abstract.ERC20Base.md | 2 +- .../ERC20Base.sol/struct.ERC20BaseConfig.md | 2 +- .../abstract.ERC20DebtBase.md | 7 +- .../contract.ERC20DebtLiquidityToken.md | 2 +- .../contract.ERC20LiquidityToken.md | 2 +- .../contract.ERC4626DebtToken.md | 4 +- .../contract.ERC4626DepositToken.md | 2 +- .../HookRegistry.sol/contract.HookRegistry.md | 2 +- .../contract.TokenController.md | 31 +++--- .../function.deployFactory.md | 2 +- 52 files changed, 253 insertions(+), 227 deletions(-) diff --git a/docs/developer-guide/contracts/AmmalgamPair.sol/contract.AmmalgamPair.md b/docs/developer-guide/contracts/AmmalgamPair.sol/contract.AmmalgamPair.md index 45ac2ef2..8b7b6d7e 100644 --- a/docs/developer-guide/contracts/AmmalgamPair.sol/contract.AmmalgamPair.md +++ b/docs/developer-guide/contracts/AmmalgamPair.sol/contract.AmmalgamPair.md @@ -1,5 +1,5 @@ # AmmalgamPair -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/AmmalgamPair.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/AmmalgamPair.sol) **Inherits:** [IAmmalgamPair](/docs/developer-guide/contracts/interfaces/IAmmalgamPair.sol/interface.IAmmalgamPair.md), [TokenController](/docs/developer-guide/contracts/tokens/TokenController.sol/contract.TokenController.md) @@ -369,14 +369,7 @@ Liquidation based on change of saturation because of time. ```solidity -function resetSaturation( - Validation.InputParams memory inputParams, - address borrower, - address to, - uint256 depositLToBeTransferredInLAssets, - uint256 depositXToBeTransferredInXAssets, - uint256 depositYToBeTransferredInYAssets -) private; +function resetSaturation(Validation.InputParams memory inputParams, address borrower, address to) private; ``` **Parameters** @@ -385,9 +378,6 @@ function resetSaturation( |`inputParams`|`Validation.InputParams`|| |`borrower`|`address`|The account being liquidated.| |`to`|`address`|The account to send the liquidated deposit to| -|`depositLToBeTransferredInLAssets`|`uint256`|The amount of L to be transferred to the liquidator.| -|`depositXToBeTransferredInXAssets`|`uint256`|The amount of X to be transferred to the liquidator.| -|`depositYToBeTransferredInYAssets`|`uint256`|The amount of Y to be transferred to the liquidator.| ### liquidateLeverage @@ -510,12 +500,27 @@ function validateOnUpdate(address validate, address update, bool alwaysUpdate) p function validateSolvency(address validate, bool alwaysUpdate) private; ``` -### getInputParamsAndUpdateSaturation +### updateSaturationIfNeeded + +Update saturation state for an account if it already exists in saturation. + +*Note that during a repay of debt, we may not have an entry in saturation if +1. The position is a straddle with a payout that never reaches zero +2. Repay is occurring during a callback of a flash loan, saturation will not be updated +until the end of the borrow call after the callback concludes.* ```solidity -function getInputParamsAndUpdateSaturation(address toUpdate, bool alwaysUpdate) private; +function updateSaturationIfNeeded( + address toUpdate +) private; ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`toUpdate`|`address`|The account to update saturation for.| + ### getInputParams diff --git a/docs/developer-guide/contracts/SaturationAndGeometricTWAPState.sol/contract.SaturationAndGeometricTWAPState.md b/docs/developer-guide/contracts/SaturationAndGeometricTWAPState.sol/contract.SaturationAndGeometricTWAPState.md index 2989d0d2..fdd5300c 100644 --- a/docs/developer-guide/contracts/SaturationAndGeometricTWAPState.sol/contract.SaturationAndGeometricTWAPState.md +++ b/docs/developer-guide/contracts/SaturationAndGeometricTWAPState.sol/contract.SaturationAndGeometricTWAPState.md @@ -1,5 +1,5 @@ # SaturationAndGeometricTWAPState -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/SaturationAndGeometricTWAPState.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/SaturationAndGeometricTWAPState.sol) **Inherits:** Initializable, [ISaturationAndGeometricTWAPState](/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md), OwnableUpgradeable @@ -151,6 +151,28 @@ function getAccount( ) external view returns (Saturation.Account memory); ``` +### accountExistsInSaturation + +Check if an account exists in either netX or netY saturation tree + + +```solidity +function accountExistsInSaturation(address pairAddress, address accountAddress) external view returns (bool exists); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pairAddress`|`address`|The address of the pair| +|`accountAddress`|`address`|The address of the account to check| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`exists`|`bool`|True if the account exists in either tree| + + ### update update the borrow position of an account and potentially check (and revert) if the @@ -249,7 +271,7 @@ function calcSatChangeRatioBips( uint256 liqSqrtPriceInYInQ72, address pairAddress, address account -) external view virtual isInitialized returns (uint256 ratioNetXBips, uint256 ratioNetYBips); +) external view virtual isInitialized returns (uint256 ratioBips); ``` **Parameters** @@ -265,8 +287,7 @@ function calcSatChangeRatioBips( |Name|Type|Description| |----|----|-----------| -|`ratioNetXBips`|`uint256`|The ratio representing the change in netX saturation for account.| -|`ratioNetYBips`|`uint256`|The ratio representing the change in netY saturation for account.| +|`ratioBips`|`uint256`|The ratio representing the change saturation for account.| ### getObservations diff --git a/docs/developer-guide/contracts/factories/AmmalgamFactory.sol/contract.AmmalgamFactory.md b/docs/developer-guide/contracts/factories/AmmalgamFactory.sol/contract.AmmalgamFactory.md index 66322b97..0343f1da 100644 --- a/docs/developer-guide/contracts/factories/AmmalgamFactory.sol/contract.AmmalgamFactory.md +++ b/docs/developer-guide/contracts/factories/AmmalgamFactory.sol/contract.AmmalgamFactory.md @@ -1,5 +1,5 @@ # AmmalgamFactory -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/AmmalgamFactory.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/factories/AmmalgamFactory.sol) **Inherits:** [IAmmalgamFactory](/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IAmmalgamFactory.md) diff --git a/docs/developer-guide/contracts/factories/ERC20DebtLiquidityTokenFactory.sol/contract.ERC20DebtLiquidityTokenFactory.md b/docs/developer-guide/contracts/factories/ERC20DebtLiquidityTokenFactory.sol/contract.ERC20DebtLiquidityTokenFactory.md index dd4d9e02..c9812627 100644 --- a/docs/developer-guide/contracts/factories/ERC20DebtLiquidityTokenFactory.sol/contract.ERC20DebtLiquidityTokenFactory.md +++ b/docs/developer-guide/contracts/factories/ERC20DebtLiquidityTokenFactory.sol/contract.ERC20DebtLiquidityTokenFactory.md @@ -1,5 +1,5 @@ # ERC20DebtLiquidityTokenFactory -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/ERC20DebtLiquidityTokenFactory.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/factories/ERC20DebtLiquidityTokenFactory.sol) **Inherits:** [ITokenFactory](/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md) diff --git a/docs/developer-guide/contracts/factories/ERC20LiquidityTokenFactory.sol/contract.ERC20LiquidityTokenFactory.md b/docs/developer-guide/contracts/factories/ERC20LiquidityTokenFactory.sol/contract.ERC20LiquidityTokenFactory.md index 158afd54..42f1a8e4 100644 --- a/docs/developer-guide/contracts/factories/ERC20LiquidityTokenFactory.sol/contract.ERC20LiquidityTokenFactory.md +++ b/docs/developer-guide/contracts/factories/ERC20LiquidityTokenFactory.sol/contract.ERC20LiquidityTokenFactory.md @@ -1,5 +1,5 @@ # ERC20LiquidityTokenFactory -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/ERC20LiquidityTokenFactory.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/factories/ERC20LiquidityTokenFactory.sol) **Inherits:** [ITokenFactory](/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md) diff --git a/docs/developer-guide/contracts/factories/ERC4626DebtTokenFactory.sol/contract.ERC4626DebtTokenFactory.md b/docs/developer-guide/contracts/factories/ERC4626DebtTokenFactory.sol/contract.ERC4626DebtTokenFactory.md index 44479635..cb05a502 100644 --- a/docs/developer-guide/contracts/factories/ERC4626DebtTokenFactory.sol/contract.ERC4626DebtTokenFactory.md +++ b/docs/developer-guide/contracts/factories/ERC4626DebtTokenFactory.sol/contract.ERC4626DebtTokenFactory.md @@ -1,5 +1,5 @@ # ERC4626DebtTokenFactory -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/ERC4626DebtTokenFactory.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/factories/ERC4626DebtTokenFactory.sol) **Inherits:** [ITokenFactory](/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md) diff --git a/docs/developer-guide/contracts/factories/ERC4626DepositTokenFactory.sol/contract.ERC4626DepositTokenFactory.md b/docs/developer-guide/contracts/factories/ERC4626DepositTokenFactory.sol/contract.ERC4626DepositTokenFactory.md index 7b34e7a4..10a5a9ce 100644 --- a/docs/developer-guide/contracts/factories/ERC4626DepositTokenFactory.sol/contract.ERC4626DepositTokenFactory.md +++ b/docs/developer-guide/contracts/factories/ERC4626DepositTokenFactory.sol/contract.ERC4626DepositTokenFactory.md @@ -1,5 +1,5 @@ # ERC4626DepositTokenFactory -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/ERC4626DepositTokenFactory.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/factories/ERC4626DepositTokenFactory.sol) **Inherits:** [ITokenFactory](/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md) diff --git a/docs/developer-guide/contracts/interfaces/IAmmalgamPair.sol/interface.IAmmalgamPair.md b/docs/developer-guide/contracts/interfaces/IAmmalgamPair.sol/interface.IAmmalgamPair.md index a130c3f6..94b5a5f2 100644 --- a/docs/developer-guide/contracts/interfaces/IAmmalgamPair.sol/interface.IAmmalgamPair.md +++ b/docs/developer-guide/contracts/interfaces/IAmmalgamPair.sol/interface.IAmmalgamPair.md @@ -1,5 +1,5 @@ # IAmmalgamPair -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/IAmmalgamPair.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/IAmmalgamPair.sol) **Inherits:** [ITransferValidator](/docs/developer-guide/contracts/interfaces/callbacks/ITransferValidator.sol/interface.ITransferValidator.md) diff --git a/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md b/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md index b6a1508f..e6d02bd1 100644 --- a/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md +++ b/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md @@ -1,5 +1,5 @@ # ISaturationAndGeometricTWAPState -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/ISaturationAndGeometricTWAPState.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/ISaturationAndGeometricTWAPState.sol) ## Functions @@ -99,6 +99,28 @@ function getAccount( ) external view returns (Saturation.Account memory); ``` +### accountExistsInSaturation + +Check if an account exists in either netX or netY saturation tree + + +```solidity +function accountExistsInSaturation(address pairAddress, address accountAddress) external view returns (bool exists); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`pairAddress`|`address`|The address of the pair| +|`accountAddress`|`address`|The address of the account to check| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`exists`|`bool`|True if the account exists in either tree| + + ### update update the borrow position of an account and potentially check (and revert) if the @@ -156,7 +178,7 @@ function calcSatChangeRatioBips( uint256 liqSqrtPriceInYInQ72, address pairAddress, address account -) external view returns (uint256 ratioNetXBips, uint256 ratioNetYBips); +) external view returns (uint256 ratioBips); ``` **Parameters** @@ -172,8 +194,7 @@ function calcSatChangeRatioBips( |Name|Type|Description| |----|----|-----------| -|`ratioNetXBips`|`uint256`|The ratio representing the change in netX saturation for account.| -|`ratioNetYBips`|`uint256`|The ratio representing the change in netY saturation for account.| +|`ratioBips`|`uint256`|The ratio representing the change in saturation for account.| ### configLongTermInterval diff --git a/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.IBorrowCallback.md b/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.IBorrowCallback.md index d0f03544..0d61a667 100644 --- a/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.IBorrowCallback.md +++ b/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.IBorrowCallback.md @@ -1,5 +1,5 @@ # IBorrowCallback -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/callbacks/IAmmalgamCallee.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/callbacks/IAmmalgamCallee.sol) ## Functions diff --git a/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ICallback.md b/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ICallback.md index 7dda2492..8aedb482 100644 --- a/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ICallback.md +++ b/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ICallback.md @@ -1,5 +1,5 @@ # ICallback -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/callbacks/IAmmalgamCallee.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/callbacks/IAmmalgamCallee.sol) **Inherits:** [ISwapCallback](/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ISwapCallback.md), [IBorrowCallback](/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.IBorrowCallback.md) diff --git a/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ISwapCallback.md b/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ISwapCallback.md index d6519fa9..a9e52e38 100644 --- a/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ISwapCallback.md +++ b/docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.ISwapCallback.md @@ -1,5 +1,5 @@ # ISwapCallback -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/callbacks/IAmmalgamCallee.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/callbacks/IAmmalgamCallee.sol) *This interface should be implemented by anyone wishing to use callbacks in the `swap`, `borrow`, and `borrowLiquidity` functions in the IAmmalgamPair interface.* diff --git a/docs/developer-guide/contracts/interfaces/callbacks/ITransferValidator.sol/interface.ITransferValidator.md b/docs/developer-guide/contracts/interfaces/callbacks/ITransferValidator.sol/interface.ITransferValidator.md index 5dd7fcee..760d17d5 100644 --- a/docs/developer-guide/contracts/interfaces/callbacks/ITransferValidator.sol/interface.ITransferValidator.md +++ b/docs/developer-guide/contracts/interfaces/callbacks/ITransferValidator.sol/interface.ITransferValidator.md @@ -1,5 +1,5 @@ # ITransferValidator -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/callbacks/ITransferValidator.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/callbacks/ITransferValidator.sol) This interface is intended for validating the solvency of an account when transfers occur. diff --git a/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IAmmalgamFactory.md b/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IAmmalgamFactory.md index 56841a14..676f58b3 100644 --- a/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IAmmalgamFactory.md +++ b/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IAmmalgamFactory.md @@ -1,5 +1,5 @@ # IAmmalgamFactory -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/factories/IAmmalgamFactory.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/factories/IAmmalgamFactory.sol) **Inherits:** [IFactoryCallback](/docs/developer-guide/contracts/interfaces/factories/IFactoryCallback.sol/interface.IFactoryCallback.md), [IBeaconCallback](/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IBeaconCallback.md) diff --git a/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IBeaconCallback.md b/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IBeaconCallback.md index 21404d6c..361c08c4 100644 --- a/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IBeaconCallback.md +++ b/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IBeaconCallback.md @@ -1,5 +1,5 @@ # IBeaconCallback -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/factories/IAmmalgamFactory.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/factories/IAmmalgamFactory.sol) ## Functions diff --git a/docs/developer-guide/contracts/interfaces/factories/IFactoryCallback.sol/interface.IFactoryCallback.md b/docs/developer-guide/contracts/interfaces/factories/IFactoryCallback.sol/interface.IFactoryCallback.md index 832f69ae..f324322b 100644 --- a/docs/developer-guide/contracts/interfaces/factories/IFactoryCallback.sol/interface.IFactoryCallback.md +++ b/docs/developer-guide/contracts/interfaces/factories/IFactoryCallback.sol/interface.IFactoryCallback.md @@ -1,5 +1,5 @@ # IFactoryCallback -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/factories/IFactoryCallback.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/factories/IFactoryCallback.sol) This interface provides methods for getting the token factory configuration. diff --git a/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md b/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md index 44db468d..f9ad44a1 100644 --- a/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md +++ b/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md @@ -1,5 +1,5 @@ # ITokenFactory -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/factories/ITokenFactory.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/factories/ITokenFactory.sol) ## Functions diff --git a/docs/developer-guide/contracts/interfaces/tokens/IAmmalgamERC20.sol/interface.IAmmalgamERC20.md b/docs/developer-guide/contracts/interfaces/tokens/IAmmalgamERC20.sol/interface.IAmmalgamERC20.md index 39383c87..60d6f1a4 100644 --- a/docs/developer-guide/contracts/interfaces/tokens/IAmmalgamERC20.sol/interface.IAmmalgamERC20.md +++ b/docs/developer-guide/contracts/interfaces/tokens/IAmmalgamERC20.sol/interface.IAmmalgamERC20.md @@ -1,5 +1,5 @@ # IAmmalgamERC20 -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/tokens/IAmmalgamERC20.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/tokens/IAmmalgamERC20.sol) **Inherits:** IERC20, IERC20Metadata, IERC20Permit diff --git a/docs/developer-guide/contracts/interfaces/tokens/IERC20DebtToken.sol/interface.IERC20DebtToken.md b/docs/developer-guide/contracts/interfaces/tokens/IERC20DebtToken.sol/interface.IERC20DebtToken.md index c77dd330..69a40538 100644 --- a/docs/developer-guide/contracts/interfaces/tokens/IERC20DebtToken.sol/interface.IERC20DebtToken.md +++ b/docs/developer-guide/contracts/interfaces/tokens/IERC20DebtToken.sol/interface.IERC20DebtToken.md @@ -1,5 +1,5 @@ # IERC20DebtToken -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/tokens/IERC20DebtToken.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/tokens/IERC20DebtToken.sol) **Inherits:** [IAmmalgamERC20](/docs/developer-guide/contracts/interfaces/tokens/IAmmalgamERC20.sol/interface.IAmmalgamERC20.md) diff --git a/docs/developer-guide/contracts/interfaces/tokens/IHookRegistry.sol/interface.IHookRegistry.md b/docs/developer-guide/contracts/interfaces/tokens/IHookRegistry.sol/interface.IHookRegistry.md index e9e8be77..5a685796 100644 --- a/docs/developer-guide/contracts/interfaces/tokens/IHookRegistry.sol/interface.IHookRegistry.md +++ b/docs/developer-guide/contracts/interfaces/tokens/IHookRegistry.sol/interface.IHookRegistry.md @@ -1,5 +1,5 @@ # IHookRegistry -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/tokens/IHookRegistry.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/tokens/IHookRegistry.sol) ## Functions diff --git a/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/constants.ITokenController.md b/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/constants.ITokenController.md index 4dfba71e..079a6487 100644 --- a/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/constants.ITokenController.md +++ b/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/constants.ITokenController.md @@ -1,5 +1,5 @@ # Constants -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/tokens/ITokenController.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/tokens/ITokenController.sol) ### DEPOSIT_L diff --git a/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/interface.ITokenController.md b/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/interface.ITokenController.md index 85f1e34c..c918c0a8 100644 --- a/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/interface.ITokenController.md +++ b/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/interface.ITokenController.md @@ -1,5 +1,5 @@ # ITokenController -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/tokens/ITokenController.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/interfaces/tokens/ITokenController.sol) The interface of a ERC20 facade for multiple token types with functionality similar to ERC1155. @@ -199,7 +199,8 @@ event BurnBadDebt(address indexed borrower, uint256 indexed tokenType, uint256 b ```solidity event InterestAccrued( - uint112 depositLAssets, + uint256 reserveXAssets, + uint256 reserveYAssets, uint112 depositXAssets, uint112 depositYAssets, uint112 borrowLAssets, @@ -212,7 +213,8 @@ event InterestAccrued( |Name|Type|Description| |----|----|-----------| -|`depositLAssets`|`uint112`|The amount of total `DEPOSIT_L` assets in the pool after interest accrual| +|`reserveXAssets`|`uint256`|The amount reserve X assets in the pool after interest accrual| +|`reserveYAssets`|`uint256`|The amount reserve Y assets in the pool after interest accrual| |`depositXAssets`|`uint112`|The amount of total `DEPOSIT_X` assets in the pool after interest accrual| |`depositYAssets`|`uint112`|The amount of total `DEPOSIT_Y` assets in the pool after interest accrual| |`borrowLAssets`|`uint112`|The amount of total `BORROW_L` assets in the pool after interest accrual| diff --git a/docs/developer-guide/contracts/libraries/Convert.sol/library.Convert.md b/docs/developer-guide/contracts/libraries/Convert.sol/library.Convert.md index ecb9c701..9c19dea6 100644 --- a/docs/developer-guide/contracts/libraries/Convert.sol/library.Convert.md +++ b/docs/developer-guide/contracts/libraries/Convert.sol/library.Convert.md @@ -1,5 +1,5 @@ # Convert -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/Convert.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/Convert.sol) ## Functions diff --git a/docs/developer-guide/contracts/libraries/GeometricTWAP.sol/library.GeometricTWAP.md b/docs/developer-guide/contracts/libraries/GeometricTWAP.sol/library.GeometricTWAP.md index 0c5cc002..46c0c597 100644 --- a/docs/developer-guide/contracts/libraries/GeometricTWAP.sol/library.GeometricTWAP.md +++ b/docs/developer-guide/contracts/libraries/GeometricTWAP.sol/library.GeometricTWAP.md @@ -1,5 +1,5 @@ # GeometricTWAP -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/GeometricTWAP.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/GeometricTWAP.sol) ## State Variables diff --git a/docs/developer-guide/contracts/libraries/Interest.sol/library.Interest.md b/docs/developer-guide/contracts/libraries/Interest.sol/library.Interest.md index f3d19359..6ee632c3 100644 --- a/docs/developer-guide/contracts/libraries/Interest.sol/library.Interest.md +++ b/docs/developer-guide/contracts/libraries/Interest.sol/library.Interest.md @@ -1,5 +1,5 @@ # Interest -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/Interest.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/Interest.sol) This library is used for calculating and accruing interest. diff --git a/docs/developer-guide/contracts/libraries/Liquidation.sol/library.Liquidation.md b/docs/developer-guide/contracts/libraries/Liquidation.sol/library.Liquidation.md index 670ab145..948f0d50 100644 --- a/docs/developer-guide/contracts/libraries/Liquidation.sol/library.Liquidation.md +++ b/docs/developer-guide/contracts/libraries/Liquidation.sol/library.Liquidation.md @@ -1,5 +1,5 @@ # Liquidation -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/Liquidation.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/Liquidation.sol) ## State Variables @@ -45,13 +45,13 @@ uint256 private constant POSITIVE_PREMIUM_INTERCEPT_IN_BIPS = 4444; ``` -### LEVERAGE_LIQUIDATION_BREAK_EVEN_FACTOR +### LEVERAGE_LIQUIDATION_BREAK_EVEN_FACTOR_MAG2 The factor to controls the pace of the increase in the premium the leverage liquidation premium function. ```solidity -uint256 private constant LEVERAGE_LIQUIDATION_BREAK_EVEN_FACTOR = 5; +uint256 internal constant LEVERAGE_LIQUIDATION_BREAK_EVEN_FACTOR_MAG2 = 10; ``` @@ -114,7 +114,6 @@ function checkHardPremiums( ```solidity function calculateNetDebtAndSeizedDeposits( uint256[6] memory proposedLiquidation, - uint256 activeLiquidityScalerInQ72, uint256 sqrtPriceMinInQ72, uint256 sqrtPriceMaxInQ72 ) internal pure returns (uint256 netDebtInLAssets, uint256 netCollateralInLAssets, bool netDebtX); @@ -127,11 +126,8 @@ function calculateNetDebtAndSeizedDeposits( function checkSaturationPremiums( ISaturationAndGeometricTWAPState saturationAndGeometricTWAPState, Validation.InputParams memory inputParams, - address borrower, - uint256 depositLToTransferInLAssets, - uint256 depositXToTransferInXAssets, - uint256 depositYToTransferInYAssets -) external view; + address borrower +) external view returns (uint256 seizeLAssets, uint256 seizeXAssets, uint256 seizeYAssets); ``` ### liquidateLeverageCalcDeltaAndPremium @@ -139,7 +135,7 @@ function checkSaturationPremiums( Calculate the amount to be closed (from both deposit and borrow) and premium to be paid. The formula for the premium is calculated with the average net borrow of X and Y $$B$$ and the net deposit of X and Y $$B$$ and a scaler $$S$$ that sets the pace at which -the premium increased, in code we call this `LEVERAGE_LIQUIDATION_BREAK_EVEN_FACTOR`, and +the premium increased, in code we call this `LEVERAGE_LIQUIDATION_BREAK_EVEN_FACTOR_MAG2`, and allowed leverage $$AL$$, `ALLOWED_LIQUIDITY_LEVERAGE`: ```math premium = \begin{cases} @@ -195,7 +191,6 @@ Calculate the maximum premium the liquidator may receive given the LTV of the bo function calcHardMaxPremiumInBips( uint256[6] memory validatedLiquidation, uint256 activeLiquidityAssets, - uint256 activeLiquidityScalerInQ72, uint256 sqrtPriceMinInQ72, uint256 sqrtPriceMaxInQ72 ) internal pure returns (uint256 maxPremiumInBips); @@ -268,36 +263,17 @@ function convertLtvToPremium( |`maxPremiumInBips`|`uint256`|The maximum premium for the liquidator.| -### calcSaturationPremiumBips - -Calculate the premium the saturation liquidator is receiving given the borrowers deposit and the depositToTransfer to the liquidator. -The end premium is the max of the premiums in L, X, Y -If no saturation liq is requested (liquidationParams.saturationDepositLToBeTransferred==liquidationParams.saturationDepositXToBeTransferred==liquidationParams.saturationDepositYToBeTransferred==0), the premium will be 0 +### calcSaturationSeizedAssets ```solidity -function calcSaturationPremiumBips( - Validation.InputParams memory inputParams, - uint256 depositLToTransferInLAssets, - uint256 depositXToTransferInXAssets, - uint256 depositYToTransferInYAssets -) internal pure returns (uint256 premiumInBips); +function calcSaturationSeizedAssets( + uint256 depositedLAssets, + uint256 depositedXAssets, + uint256 depositedYAssets, + uint256 premiumInBips +) internal pure returns (uint256 seizedLAssets, uint256 seizedXAssets, uint256 seizedYAssets); ``` -**Parameters** - -|Name|Type|Description| -|----|----|-----------| -|`inputParams`|`Validation.InputParams`|The params containing the position of the borrower.| -|`depositLToTransferInLAssets`|`uint256`|| -|`depositXToTransferInXAssets`|`uint256`|| -|`depositYToTransferInYAssets`|`uint256`|| - -**Returns** - -|Name|Type|Description| -|----|----|-----------| -|`premiumInBips`|`uint256`|The premium being received by the liquidator.| - ### calcSaturationMaxPremiumInBips @@ -334,6 +310,12 @@ function calcSaturationMaxPremiumInBips( error LiquidationPremiumTooHigh(); ``` +### LiquidationZeroPremium + +```solidity +error LiquidationZeroPremium(); +``` + ### NotEnoughRepaidForLiquidation ```solidity diff --git a/docs/developer-guide/contracts/libraries/PartialLiquidations.sol/library.PartialLiquidations.md b/docs/developer-guide/contracts/libraries/PartialLiquidations.sol/library.PartialLiquidations.md index 77d125ee..828021f3 100644 --- a/docs/developer-guide/contracts/libraries/PartialLiquidations.sol/library.PartialLiquidations.md +++ b/docs/developer-guide/contracts/libraries/PartialLiquidations.sol/library.PartialLiquidations.md @@ -1,5 +1,5 @@ # PartialLiquidations -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/PartialLiquidations.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/PartialLiquidations.sol) We allow liquidations to happen in parts when the position is spread across more than one tranche. These partial liquidations allow the liquidator to specify how many tranches they diff --git a/docs/developer-guide/contracts/libraries/QuadraticSwapFees.sol/library.QuadraticSwapFees.md b/docs/developer-guide/contracts/libraries/QuadraticSwapFees.sol/library.QuadraticSwapFees.md index 22a74753..198c7a1c 100644 --- a/docs/developer-guide/contracts/libraries/QuadraticSwapFees.sol/library.QuadraticSwapFees.md +++ b/docs/developer-guide/contracts/libraries/QuadraticSwapFees.sol/library.QuadraticSwapFees.md @@ -1,5 +1,5 @@ # QuadraticSwapFees -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/QuadraticSwapFees.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/QuadraticSwapFees.sol) **Author:** Will diff --git a/docs/developer-guide/contracts/libraries/Saturation.sol/library.Saturation.md b/docs/developer-guide/contracts/libraries/Saturation.sol/library.Saturation.md index a73338f0..c90d1756 100644 --- a/docs/developer-guide/contracts/libraries/Saturation.sol/library.Saturation.md +++ b/docs/developer-guide/contracts/libraries/Saturation.sol/library.Saturation.md @@ -1,5 +1,5 @@ # Saturation -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/Saturation.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/Saturation.sol) **Authors:** imi@1m1.io, Will duelingGalois@protonmail.com @@ -181,6 +181,18 @@ uint256 internal constant EXPECTED_SATURATION_LTV_PLUS_ONE_MAG2 = 185; ``` +### SAT_RESET_FOR_STRADDLE_SLOPE_BIPS +Slope for calculating premium when resetting saturation for straddle positions +where $$L^2 < X \cdot Y$$ transitions to $$L^2 > X \cdot Y$$. The current value is +50 * BIPS which allows for the premium to grow quickly as the straddle's window of +insolvency grows rapidly once they reach this transition point. + + +```solidity +uint256 internal constant SAT_RESET_FOR_STRADDLE_SLOPE_BIPS = 500_000; +``` + + ### SAT_CHANGE_OF_BASE_Q128 a constant used to change the log base from the tick math base to the saturation to leaf base. @@ -387,16 +399,6 @@ uint256 private constant NUMBER_OF_QUARTERS = 4; ``` -### SATURATION_LIQUIDATION_SCALER -We make the penalty slightly larger to hit our desired premium for exceeding the -time buffer. - - -```solidity -uint256 private constant SATURATION_LIQUIDATION_SCALER = 10_020; -``` - - ### TWO_Q72 $$2 * 2**72 * 2$$, used in saturation formula. @@ -1211,7 +1213,46 @@ function findHighestSetLeafDownwards( ### calcLiqSqrtPriceQ72 -Calc sqrt price at which positions' LTV would reach LTV_MAX +Calc sqrt price at which positions' LTV would reach LTV_MAX. Given the net $$L$$, +$$X$$, and Y, we define the the sqrt price $$s_p$$ at which the position would be at the +expected loan to value of liquidation $$k$$, then the following formulas are what we are +calculating, +```math +\begin{align} +k &= +\begin{cases} +-\frac{L + \frac{X}{s_p}}{L + Y \cdot s_p} +\text{ if } L+ \frac{X}{s_p} < 0 +\\ +-\frac{L + Y \cdot s_p}{L + \frac{X}{s_p}} +\text{ if } L + Y \cdot s_p < 0 +\end{cases} +\\ +s_p &= +\begin{cases} +\frac{ +-(k+1)L + +\sqrt{\left((k+1)L\right)^2 - 4 \left( k\cdot Y \right) \left(X \right)} +}{ +2 \cdot k \cdot Y +} +\text{ if } L + \frac{X}{s_p} < 0 +\\ +\frac{ +-(k+1)L - +\sqrt{((k+1)L)^2-4(Y)(k\cdot X)} +}{ +2\cdot k +} +\text{ if } L + Y \cdot s_p < 0 +\end{cases} +\end{align} +``` +The equation gives four solutions due to the plus minus of the radical, but we choose the +direction due to the conditions. When we have a net debt of x, $$L + \frac{X}{s_p} < 0$$, +the loan to value will be increasing as the price decreases, thus we choose the positive +value of the radical. For the net debt of y, $$L + Y \cdot s_p < 0$$ we have the loan to +value increasing as the price increases, thus we use the negative value of the radical. Output guarantees $$0 \le liqSqrtPriceXInQ72 \le uint256(type(uint56).max) << 72$$ (fuzz tested and logic) @@ -1283,7 +1324,7 @@ function calcSatChangeRatioBips( uint256 liqSqrtPriceInYInQ72, address account, uint256 desiredSaturationMAG2 -) internal view returns (uint256 ratioNetXBips, uint256 ratioNetYBips); +) internal view returns (uint256 ratioBips); ``` **Parameters** @@ -1300,8 +1341,38 @@ function calcSatChangeRatioBips( |Name|Type|Description| |----|----|-----------| -|`ratioNetXBips`|`uint256`|The ratio representing the change in netX saturation for account.| -|`ratioNetYBips`|`uint256`|The ratio representing the change in netY saturation for account.| +|`ratioBips`|`uint256`|The ratio representing the change in saturation for account.| + + +### calcStraddlePremiumRatioBips + +Calculate the ratio bips for a straddle position transitioning from zero to positive saturation. +```math +r = \max\left(0, \left \lceil \frac{L^{2}-YX}{Y\cdot X} \cdot {S_{BIPS}}\right\rceil\right) +``` +The ratioBips encodes premium for downstream consumption: +```math +\text{ratioBips} = \text{premiumBips} \cdot \text{MAG1} + \text{BIPS} +``` +and premium is recovered as: `(ratioBips - BIPS) / MAG1`. + + +```solidity +function calcStraddlePremiumRatioBips( + uint256[6] memory userAssets +) private pure returns (uint256 ratioBips); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`userAssets`|`uint256[6]`|The user's position parameters.| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|`ratioBips`|`uint256`|The ratio in bips, or 0 if $$L^2 <= X \cdot Y$$.| ### calculateEndOfLiquidationAdjustment diff --git a/docs/developer-guide/contracts/libraries/TickMath.sol/library.TickMath.md b/docs/developer-guide/contracts/libraries/TickMath.sol/library.TickMath.md index 6f547b0b..bc27ce74 100644 --- a/docs/developer-guide/contracts/libraries/TickMath.sol/library.TickMath.md +++ b/docs/developer-guide/contracts/libraries/TickMath.sol/library.TickMath.md @@ -1,5 +1,5 @@ # TickMath -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/TickMath.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/TickMath.sol) Computes sqrt price for ticks of size B=(1-2^-9)^-1 as fixed point Q72 numbers. Supports prices between 2**-112 and 2**112-1 diff --git a/docs/developer-guide/contracts/libraries/TokenSymbol.sol/library.TokenSymbol.md b/docs/developer-guide/contracts/libraries/TokenSymbol.sol/library.TokenSymbol.md index 92328998..cf0a0bed 100644 --- a/docs/developer-guide/contracts/libraries/TokenSymbol.sol/library.TokenSymbol.md +++ b/docs/developer-guide/contracts/libraries/TokenSymbol.sol/library.TokenSymbol.md @@ -1,5 +1,5 @@ # TokenSymbol -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/TokenSymbol.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/TokenSymbol.sol) ## Functions diff --git a/docs/developer-guide/contracts/libraries/Uint16Set.sol/library.Uint16Set.md b/docs/developer-guide/contracts/libraries/Uint16Set.sol/library.Uint16Set.md index c1872326..1364ae0e 100644 --- a/docs/developer-guide/contracts/libraries/Uint16Set.sol/library.Uint16Set.md +++ b/docs/developer-guide/contracts/libraries/Uint16Set.sol/library.Uint16Set.md @@ -1,5 +1,5 @@ # Uint16Set -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/Uint16Set.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/Uint16Set.sol) based on https://github.com/rob-Hitchens/SetTypes/blob/master/contracts/UintSet.sol diff --git a/docs/developer-guide/contracts/libraries/Validation.sol/library.Validation.md b/docs/developer-guide/contracts/libraries/Validation.sol/library.Validation.md index af34a9d1..bd6407f4 100644 --- a/docs/developer-guide/contracts/libraries/Validation.sol/library.Validation.md +++ b/docs/developer-guide/contracts/libraries/Validation.sol/library.Validation.md @@ -1,5 +1,5 @@ # Validation -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/Validation.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/Validation.sol) SPDX-License-Identifier: GPL-3.0-only @@ -12,62 +12,6 @@ uint256 private constant MAX_BORROW_PERCENTAGE = 90; ``` -### ONE_HUNDRED_TIMES_N - -```solidity -uint256 private constant ONE_HUNDRED_TIMES_N = 2000; -``` - - -### TWO_Q64 - -```solidity -uint256 private constant TWO_Q64 = 0x20000000000000000; -``` - - -### FIVE_Q64 - -```solidity -uint256 private constant FIVE_Q64 = 0x50000000000000000; -``` - - -### NINE_Q64 - -```solidity -uint256 private constant NINE_Q64 = 0x90000000000000000; -``` - - -### FIFTY_Q64 - -```solidity -uint256 private constant FIFTY_Q64 = 0x320000000000000000; -``` - - -### TWO_TIMES_N_Q64 - -```solidity -uint256 private constant TWO_TIMES_N_Q64 = 0x280000000000000000; -``` - - -### TWO_Q128 - -```solidity -uint256 private constant TWO_Q128 = 0x200000000000000000000000000000000; -``` - - -### TWO_THOUSAND_FIVE_HUNDRED_Q128 - -```solidity -uint256 private constant TWO_THOUSAND_FIVE_HUNDRED_Q128 = 0x9c400000000000000000000000000000000; -``` - - ## Functions ### getInputParams @@ -118,7 +62,6 @@ to switch them as needed in liquidation and other cases.* ```solidity function getCheckLtvParams( uint256[6] memory userAssets, - uint256 activeLiquidityScalerInQ72, uint256 sqrtPriceMinInQ72, uint256 sqrtPriceMaxInQ72 ) internal pure returns (CheckLtvParams memory checkLtvParams); @@ -128,7 +71,6 @@ function getCheckLtvParams( |Name|Type|Description| |----|----|-----------| |`userAssets`|`uint256[6]`|User asset array| -|`activeLiquidityScalerInQ72`|`uint256`|The active liquidity scaler in Q72| |`sqrtPriceMinInQ72`|`uint256`|The minimum sqrt price in Q72| |`sqrtPriceMaxInQ72`|`uint256`|The maximum sqrt price in Q72| @@ -162,7 +104,6 @@ function validateSolvency( uint256[6] memory userAssets, uint256 sqrtPriceMinInQ72, uint256 sqrtPriceMaxInQ72, - uint256 activeLiquidityScalerInQ72, uint256 activeLiquidityAssets ) internal pure; ``` @@ -194,7 +135,6 @@ function verifyMaxBorrow( ```solidity function getDepositsInL( uint256[6] memory userAssets, - uint256 activeLiquidityScalerInQ72, uint256 sqrtPriceMinInQ72, uint256 sqrtPriceMaxInQ72 ) private pure returns (uint256 netDepositedXinLAssets, uint256 netDepositedYinLAssets); @@ -206,7 +146,6 @@ function getDepositsInL( ```solidity function getBorrowedInL( uint256[6] memory userAssets, - uint256 activeLiquidityScalerInQ72, uint256 sqrtPriceMinInQ72, uint256 sqrtPriceMaxInQ72 ) private pure returns (uint256 netBorrowedXinLAssets, uint256 netBorrowedYinLAssets); @@ -214,70 +153,56 @@ function getBorrowedInL( ### convertXToL -The original math: -L * activeLiquidityScalerInQ72 = x / sqrt(p) -previous equation: -amountLAssets = mulDiv(amount, Q72, sqrtPriceInXInQ72, rounding); -adding activeLiquidityScalerInQ72: -amountLAssets = (amount * Q72 / sqrtPriceInXInQ72) / (activeLiquidityScalerInQ72 / Q72); -simplify to: -(amount * Q72 * Q72) / (sqrtPriceInXInQ72 * activeLiquidityScalerInQ72) -final equation: -amountLAssets = mulDiv(mulDiv(amount, Q72, sqrtPriceInXInQ72, rounding), Q72, activeLiquidityScalerInQ72, rounding); -or more simplified (failed for some tests) -amountLAssets = mulDiv(amount, Q72 * Q72, sqrtPriceInQ72 * activeLiquidityScalerInQ72); +Convert X assets to L assets: L = x / sqrt(p) +amountLAssets = amountInXAssets * Q72 / sqrtPriceInXInQ72 ```solidity function convertXToL( uint256 amountInXAssets, uint256 sqrtPriceInXInQ72, - uint256 activeLiquidityScalerInQ72, bool roundUp ) internal pure returns (uint256 amountLAssets); ``` ### convertLToX +Convert L assets to X assets: x = L * sqrt(p) +amountXAssets = amount * sqrtPriceQ72 / Q72 + ```solidity function convertLToX( uint256 amount, uint256 sqrtPriceQ72, - uint256 activeLiquidityScalerInQ72, bool roundUp ) internal pure returns (uint256 amountXAssets); ``` ### convertYToL -The simplified math: L = y * sqrt(p) -mulDiv(amount, sqrtPriceInXInQ72, rounding); -amountLAssets = amount * sqrtPriceInXInQ72Scaled / Q72; -sqrtPriceInXInQ72Scaled = sqrtPriceInXInQ72 / activeLiquidityScalerInQ72 / Q72; -simplify to: -amount * sqrtPriceInXInQ72 / activeLiquidityScalerInQ72 -final equation: -amountLAssets = mulDiv(amount, sqrtPriceInXInQ72, activeLiquidityScalerInQ72, rounding); +Convert Y assets to L assets: L = y * sqrt(p) +amountLAssets = amountInYAssets * sqrtPriceInXInQ72 / Q72 ```solidity function convertYToL( uint256 amountInYAssets, uint256 sqrtPriceInXInQ72, - uint256 activeLiquidityScalerInQ72, bool roundUp ) internal pure returns (uint256 amountInLAssets); ``` ### convertLToY +Convert L assets to Y assets: y = L / sqrt(p) +amountYAssets = amount * Q72 / sqrtPriceQ72 + ```solidity function convertLToY( uint256 amount, uint256 sqrtPriceQ72, - uint256 activeLiquidityScalerInQ72, bool roundUp ) internal pure returns (uint256 amountYAssets); ``` @@ -432,7 +357,6 @@ struct InputParams { int16 maxTick; uint256 sqrtPriceMinInQ72; uint256 sqrtPriceMaxInQ72; - uint256 activeLiquidityScalerInQ72; uint256 activeLiquidityAssets; uint256 reservesXAssets; uint256 reservesYAssets; diff --git a/docs/developer-guide/contracts/libraries/constants.sol/constants.constants.md b/docs/developer-guide/contracts/libraries/constants.sol/constants.constants.md index f0fc46f4..6a398572 100644 --- a/docs/developer-guide/contracts/libraries/constants.sol/constants.constants.md +++ b/docs/developer-guide/contracts/libraries/constants.sol/constants.constants.md @@ -1,5 +1,5 @@ # Constants -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/libraries/constants.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/libraries/constants.sol) ### B_IN_Q72 *This basis was a modification to Uniswap V3's basis, to fit ticks into int16 instead of diff --git a/docs/developer-guide/contracts/proxy/BeaconController.sol/contract.BeaconController.md b/docs/developer-guide/contracts/proxy/BeaconController.sol/contract.BeaconController.md index 6ccb1f0e..1ea5956d 100644 --- a/docs/developer-guide/contracts/proxy/BeaconController.sol/contract.BeaconController.md +++ b/docs/developer-guide/contracts/proxy/BeaconController.sol/contract.BeaconController.md @@ -1,5 +1,5 @@ # BeaconController -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/proxy/BeaconController.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/proxy/BeaconController.sol) **Inherits:** [IBeaconController](/docs/developer-guide/contracts/proxy/BeaconController.sol/interface.IBeaconController.md), AccessControl diff --git a/docs/developer-guide/contracts/proxy/BeaconController.sol/interface.IBeaconController.md b/docs/developer-guide/contracts/proxy/BeaconController.sol/interface.IBeaconController.md index b6e532dc..0543dc69 100644 --- a/docs/developer-guide/contracts/proxy/BeaconController.sol/interface.IBeaconController.md +++ b/docs/developer-guide/contracts/proxy/BeaconController.sol/interface.IBeaconController.md @@ -1,5 +1,5 @@ # IBeaconController -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/proxy/BeaconController.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/proxy/BeaconController.sol) ## Functions diff --git a/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.InitializablePair.md b/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.InitializablePair.md index b125b4fd..7a39e833 100644 --- a/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.InitializablePair.md +++ b/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.InitializablePair.md @@ -1,5 +1,5 @@ # InitializablePair -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/proxy/PairBeaconProxy.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/proxy/PairBeaconProxy.sol) **Inherits:** [IPairInitializable](/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/interface.IPairInitializable.md), Initializable diff --git a/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.PairBeaconProxy.md b/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.PairBeaconProxy.md index b43beede..cc4336d1 100644 --- a/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.PairBeaconProxy.md +++ b/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.PairBeaconProxy.md @@ -1,5 +1,5 @@ # PairBeaconProxy -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/proxy/PairBeaconProxy.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/proxy/PairBeaconProxy.sol) **Inherits:** BeaconProxy diff --git a/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/interface.IPairInitializable.md b/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/interface.IPairInitializable.md index 3d13d075..f10ac0eb 100644 --- a/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/interface.IPairInitializable.md +++ b/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/interface.IPairInitializable.md @@ -1,5 +1,5 @@ # IPairInitializable -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/proxy/PairBeaconProxy.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/proxy/PairBeaconProxy.sol) ## Functions diff --git a/docs/developer-guide/contracts/proxy/PairBlockAllTransfers.sol/contract.PairBlockAllTransfers.md b/docs/developer-guide/contracts/proxy/PairBlockAllTransfers.sol/contract.PairBlockAllTransfers.md index 0d836be5..fc20a8d7 100644 --- a/docs/developer-guide/contracts/proxy/PairBlockAllTransfers.sol/contract.PairBlockAllTransfers.md +++ b/docs/developer-guide/contracts/proxy/PairBlockAllTransfers.sol/contract.PairBlockAllTransfers.md @@ -1,5 +1,5 @@ # PairBlockAllTransfers -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/proxy/PairBlockAllTransfers.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/proxy/PairBlockAllTransfers.sol) **Inherits:** [AmmalgamPair](/docs/developer-guide/contracts/AmmalgamPair.sol/contract.AmmalgamPair.md) diff --git a/docs/developer-guide/contracts/proxy/PairFrozen.sol/contract.PairFrozen.md b/docs/developer-guide/contracts/proxy/PairFrozen.sol/contract.PairFrozen.md index 1cfa72a3..fc202a83 100644 --- a/docs/developer-guide/contracts/proxy/PairFrozen.sol/contract.PairFrozen.md +++ b/docs/developer-guide/contracts/proxy/PairFrozen.sol/contract.PairFrozen.md @@ -1,5 +1,5 @@ # PairFrozen -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/proxy/PairFrozen.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/proxy/PairFrozen.sol) **Inherits:** [InitializablePair](/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.InitializablePair.md) diff --git a/docs/developer-guide/contracts/proxy/PairLockedLoans.sol/contract.PairLockedLoans.md b/docs/developer-guide/contracts/proxy/PairLockedLoans.sol/contract.PairLockedLoans.md index b092e973..4586548a 100644 --- a/docs/developer-guide/contracts/proxy/PairLockedLoans.sol/contract.PairLockedLoans.md +++ b/docs/developer-guide/contracts/proxy/PairLockedLoans.sol/contract.PairLockedLoans.md @@ -1,5 +1,5 @@ # PairLockedLoans -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/proxy/PairLockedLoans.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/proxy/PairLockedLoans.sol) **Inherits:** [AmmalgamPair](/docs/developer-guide/contracts/AmmalgamPair.sol/contract.AmmalgamPair.md) diff --git a/docs/developer-guide/contracts/tokens/ERC20Base.sol/abstract.ERC20Base.md b/docs/developer-guide/contracts/tokens/ERC20Base.sol/abstract.ERC20Base.md index ba4da0ce..65e45e05 100644 --- a/docs/developer-guide/contracts/tokens/ERC20Base.sol/abstract.ERC20Base.md +++ b/docs/developer-guide/contracts/tokens/ERC20Base.sol/abstract.ERC20Base.md @@ -1,5 +1,5 @@ # ERC20Base -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/ERC20Base.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/ERC20Base.sol) **Inherits:** ERC20Hooks, Ownable, ERC20Permit, [IAmmalgamERC20](/docs/developer-guide/contracts/interfaces/tokens/IAmmalgamERC20.sol/interface.IAmmalgamERC20.md) diff --git a/docs/developer-guide/contracts/tokens/ERC20Base.sol/struct.ERC20BaseConfig.md b/docs/developer-guide/contracts/tokens/ERC20Base.sol/struct.ERC20BaseConfig.md index c60f834d..fb5e281c 100644 --- a/docs/developer-guide/contracts/tokens/ERC20Base.sol/struct.ERC20BaseConfig.md +++ b/docs/developer-guide/contracts/tokens/ERC20Base.sol/struct.ERC20BaseConfig.md @@ -1,5 +1,5 @@ # ERC20BaseConfig -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/ERC20Base.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/ERC20Base.sol) ```solidity diff --git a/docs/developer-guide/contracts/tokens/ERC20DebtBase.sol/abstract.ERC20DebtBase.md b/docs/developer-guide/contracts/tokens/ERC20DebtBase.sol/abstract.ERC20DebtBase.md index 35b8764b..48649d51 100644 --- a/docs/developer-guide/contracts/tokens/ERC20DebtBase.sol/abstract.ERC20DebtBase.md +++ b/docs/developer-guide/contracts/tokens/ERC20DebtBase.sol/abstract.ERC20DebtBase.md @@ -1,5 +1,5 @@ # ERC20DebtBase -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/ERC20DebtBase.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/ERC20DebtBase.sol) **Inherits:** [ERC20Base](/docs/developer-guide/contracts/tokens/ERC20Base.sol/abstract.ERC20Base.md), [IERC20DebtToken](/docs/developer-guide/contracts/interfaces/tokens/IERC20DebtToken.sol/interface.IERC20DebtToken.md) @@ -26,12 +26,9 @@ function nonces( ### approve -*Standard ERC20 approve is disabled for debt tokens. -Allowances must be set via approveDebt using debt-specific semantics.* - ```solidity -function approve(address, uint256) public pure virtual override(ERC20, IERC20) returns (bool); +function approve(address spender, uint256 amount) public virtual override(ERC20, IERC20) returns (bool); ``` ### allowance diff --git a/docs/developer-guide/contracts/tokens/ERC20DebtLiquidityToken.sol/contract.ERC20DebtLiquidityToken.md b/docs/developer-guide/contracts/tokens/ERC20DebtLiquidityToken.sol/contract.ERC20DebtLiquidityToken.md index 49c58f0a..6b7c0241 100644 --- a/docs/developer-guide/contracts/tokens/ERC20DebtLiquidityToken.sol/contract.ERC20DebtLiquidityToken.md +++ b/docs/developer-guide/contracts/tokens/ERC20DebtLiquidityToken.sol/contract.ERC20DebtLiquidityToken.md @@ -1,5 +1,5 @@ # ERC20DebtLiquidityToken -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/ERC20DebtLiquidityToken.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/ERC20DebtLiquidityToken.sol) **Inherits:** [ERC20DebtBase](/docs/developer-guide/contracts/tokens/ERC20DebtBase.sol/abstract.ERC20DebtBase.md) diff --git a/docs/developer-guide/contracts/tokens/ERC20LiquidityToken.sol/contract.ERC20LiquidityToken.md b/docs/developer-guide/contracts/tokens/ERC20LiquidityToken.sol/contract.ERC20LiquidityToken.md index 8f51988b..324842a3 100644 --- a/docs/developer-guide/contracts/tokens/ERC20LiquidityToken.sol/contract.ERC20LiquidityToken.md +++ b/docs/developer-guide/contracts/tokens/ERC20LiquidityToken.sol/contract.ERC20LiquidityToken.md @@ -1,5 +1,5 @@ # ERC20LiquidityToken -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/ERC20LiquidityToken.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/ERC20LiquidityToken.sol) **Inherits:** [ERC20Base](/docs/developer-guide/contracts/tokens/ERC20Base.sol/abstract.ERC20Base.md) diff --git a/docs/developer-guide/contracts/tokens/ERC4626DebtToken.sol/contract.ERC4626DebtToken.md b/docs/developer-guide/contracts/tokens/ERC4626DebtToken.sol/contract.ERC4626DebtToken.md index 3cbef634..dc974f9c 100644 --- a/docs/developer-guide/contracts/tokens/ERC4626DebtToken.sol/contract.ERC4626DebtToken.md +++ b/docs/developer-guide/contracts/tokens/ERC4626DebtToken.sol/contract.ERC4626DebtToken.md @@ -1,5 +1,5 @@ # ERC4626DebtToken -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/ERC4626DebtToken.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/ERC4626DebtToken.sol) **Inherits:** ERC4626, [ERC20DebtBase](/docs/developer-guide/contracts/tokens/ERC20DebtBase.sol/abstract.ERC20DebtBase.md) @@ -149,7 +149,7 @@ function _withdraw( ```solidity -function approve(address account, uint256 balance) public pure override(ERC20, ERC20DebtBase, IERC20) returns (bool); +function approve(address spender, uint256 amount) public override(ERC20, ERC20DebtBase, IERC20) returns (bool); ``` ### allowance diff --git a/docs/developer-guide/contracts/tokens/ERC4626DepositToken.sol/contract.ERC4626DepositToken.md b/docs/developer-guide/contracts/tokens/ERC4626DepositToken.sol/contract.ERC4626DepositToken.md index a7ee1db6..f6c909fd 100644 --- a/docs/developer-guide/contracts/tokens/ERC4626DepositToken.sol/contract.ERC4626DepositToken.md +++ b/docs/developer-guide/contracts/tokens/ERC4626DepositToken.sol/contract.ERC4626DepositToken.md @@ -1,5 +1,5 @@ # ERC4626DepositToken -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/ERC4626DepositToken.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/ERC4626DepositToken.sol) **Inherits:** ERC4626, [ERC20Base](/docs/developer-guide/contracts/tokens/ERC20Base.sol/abstract.ERC20Base.md) diff --git a/docs/developer-guide/contracts/tokens/HookRegistry.sol/contract.HookRegistry.md b/docs/developer-guide/contracts/tokens/HookRegistry.sol/contract.HookRegistry.md index fcc54896..b96c912c 100644 --- a/docs/developer-guide/contracts/tokens/HookRegistry.sol/contract.HookRegistry.md +++ b/docs/developer-guide/contracts/tokens/HookRegistry.sol/contract.HookRegistry.md @@ -1,5 +1,5 @@ # HookRegistry -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/HookRegistry.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/HookRegistry.sol) **Inherits:** [IHookRegistry](/docs/developer-guide/contracts/interfaces/tokens/IHookRegistry.sol/interface.IHookRegistry.md), Ownable diff --git a/docs/developer-guide/contracts/tokens/TokenController.sol/contract.TokenController.md b/docs/developer-guide/contracts/tokens/TokenController.sol/contract.TokenController.md index 443f0516..8b00e661 100644 --- a/docs/developer-guide/contracts/tokens/TokenController.sol/contract.TokenController.md +++ b/docs/developer-guide/contracts/tokens/TokenController.sol/contract.TokenController.md @@ -1,5 +1,5 @@ # TokenController -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/tokens/TokenController.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/tokens/TokenController.sol) **Inherits:** [InitializablePair](/docs/developer-guide/contracts/proxy/PairBeaconProxy.sol/contract.InitializablePair.md), [ITokenController](/docs/developer-guide/contracts/interfaces/tokens/ITokenController.sol/interface.ITokenController.md) @@ -86,9 +86,14 @@ uint112[6] private allShares; ### allAssets +The first position in this array is never stored because it is instead computed as +$$\sqrt{reserveX * reserveY} + borrowedLAssets$$. We keep this storage spot because +we heavily use DEPOSIT_L, DEPOSIT_X, DEPOSIT_Y, BORROW_L, BORROW_X, BORROW_Y to look +up positions throughout the code and didn't want to change all those references. + ```solidity -uint112[6] internal allAssets; +uint112[6] private allAssets; ``` @@ -134,13 +139,6 @@ uint32 internal lastLendingTimestamp; ``` -### lastReserveLiquidity - -```solidity -uint112 internal lastReserveLiquidity; -``` - - ### externalLiquidity ```solidity @@ -204,6 +202,13 @@ uint112 internal transient totalBorrowYAssets; ``` +### activeLiquidityAssets + +```solidity +uint112 internal transient activeLiquidityAssets; +``` + + ## Functions ### _initialize @@ -237,7 +242,7 @@ function underlyingTokens() public view virtual override returns (IERC20, IERC20 ```solidity -function updateAssets(uint256 tokenType, uint112 assets) private; +function updateAssets(uint256 tokenType, uint112 assets) internal; ``` ### updateExternalLiquidity @@ -294,7 +299,7 @@ function totalShares( ```solidity function rawTotalAssets( uint256 tokenType -) internal view returns (uint112); +) internal view returns (uint256 assetAmount); ``` ### getRawReserves @@ -494,9 +499,7 @@ function missingAssets() internal view returns (uint112 missingXAssets, uint112 ### getDepositAndActiveLiquidityAssets -Get the deposit, borrow, and active liquidity assets. - -*This function is used to get the deposit liquidity assets, borrow liquidity assets (BLA), last active liquidity assets (ALA_0), and current active liquidity assets (ALA_1).* +Get the deposit, and active liquidity assets. ```solidity diff --git a/docs/developer-guide/contracts/utils/deployHelper.sol/function.deployFactory.md b/docs/developer-guide/contracts/utils/deployHelper.sol/function.deployFactory.md index 10f5adf2..2d4bbdc9 100644 --- a/docs/developer-guide/contracts/utils/deployHelper.sol/function.deployFactory.md +++ b/docs/developer-guide/contracts/utils/deployHelper.sol/function.deployFactory.md @@ -1,5 +1,5 @@ # function deployFactory -[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/utils/deployHelper.sol) +[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/db1bd664139b76231c80c884ad98cd40352ccebf/contracts/utils/deployHelper.sol) ### deployFactory(address)