Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 90 additions & 101 deletions docs/developer-guide/contracts/AmmalgamPair.sol/contract.AmmalgamPair.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SaturationAndGeometricTWAPState
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/82dff11576b9df76b675736dba889653cf737de9/contracts/SaturationAndGeometricTWAPState.sol)
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/974388d084e9a0078440a75c2b625a4b268d530b/contracts/SaturationAndGeometricTWAPState.sol)

**Inherits:**
[ISaturationAndGeometricTWAPState](/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md), Ownable
Expand Down Expand Up @@ -41,6 +41,13 @@ mapping(address => mapping(address => uint256)) maxNewPositionSaturationInMAG2;
```


### lastUsedActiveLiquidityInLAssets

```solidity
mapping(address => mapping(address => uint256)) lastUsedActiveLiquidityInLAssets;
```


### isPairInitialized

```solidity
Expand Down Expand Up @@ -107,11 +114,11 @@ function getNewPositionSaturation(
function getTree(address pairAddress, bool netDebtX) private view returns (Saturation.Tree storage);
```

### getLeafDetails
### getTreeLeafDetails


```solidity
function getLeafDetails(
function getTreeLeafDetails(
address pairAddress,
bool netDebtX,
uint256 leafIndex
Expand All @@ -121,17 +128,12 @@ function getLeafDetails(
returns (
Saturation.SaturationPair memory saturation,
uint256 currentPenaltyInBorrowLSharesPerSatInQ72,
uint128 totalSatInLAssets,
uint16 highestSetLeaf,
uint16[] memory tranches
);
```

### getTreeDetails


```solidity
function getTreeDetails(address pairAddress, bool netDebtX) external view returns (uint16, uint128);
```

### getTrancheDetails


Expand All @@ -156,28 +158,76 @@ function getAccount(

### update

update the borrow position of an account and potentially check (and revert) if the resulting sat is too high
update the borrow position of an account and potentially check (and revert) if the
resulting sat is too high

*run accruePenalties before running this function*


```solidity
function update(Validation.InputParams memory inputParams, address account) external virtual;
function update(
Validation.InputParams memory inputParams,
address account,
uint256 fragileLiquidityAssets,
bool skipMinOrMaxTickCheck
) external virtual;
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`inputParams`|`Validation.InputParams`| contains the position and pair params, like account borrows/deposits, current price and active liquidity|
|`account`|`address`| for which is position is being updated|
|`fragileLiquidityAssets`|`uint256`| the amount of fragile liquidity that should be excluded from active liquidity assets since it may need to be liquidated.|
|`skipMinOrMaxTickCheck`|`bool`||


### _update


```solidity
function _update(Validation.InputParams memory inputParams, address account) internal isInitialized;
function _update(
Validation.InputParams memory inputParams,
address account,
uint256 fragileLiquidityAssets,
bool skipMinOrMaxTickCheck
) internal isInitialized;
```

### scaleDesiredSaturation

Scales the desired saturation threshold based on changes in Active Liquidity Assets (ALA).

*When liquidity is burned from the pool, ALA decreases. Without scaling, this would cause
existing positions to appear more saturated (since saturation = borrows / ALA), potentially
triggering unwarranted liquidation premiums. This function scales the desired saturation
proportionally to ALA changes to maintain the position's relative health.
The scaling formula: scaled = lastUsedALA * desiredSat / currentALA*


```solidity
function scaleDesiredSaturation(
address pair,
address account,
uint256 currentALA,
bool capAtPenaltyStart
) internal view returns (uint256 desiredSaturationInMAG2);
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`pair`|`address`|The address of the pair contract.|
|`account`|`address`|The account whose saturation threshold is being scaled.|
|`currentALA`|`uint256`|The current active liquidity assets in the pool.|
|`capAtPenaltyStart`|`bool`|If `true`, caps the scaled value at START_SATURATION_PENALTY_RATIO_IN_MAG2. Used in _update() to prevent excessive. Set to `false` in calcSatChangeRatioBips() for accurate premium calculations.|

**Returns**

|Name|Type|Description|
|----|----|-----------|
|`desiredSaturationInMAG2`|`uint256`|The scaled desired saturation threshold.|


### accruePenalties

Expand Down Expand Up @@ -278,7 +328,7 @@ provided block timestamp is less than or equal to the last recorded timestamp.*


```solidity
function recordObservation(int16 newTick, uint32 timeElapsed) external isInitialized returns (bool);
function recordObservation(int16 newTick, uint32 timeElapsed) external virtual isInitialized returns (bool);
```
**Parameters**

Expand All @@ -294,6 +344,13 @@ function recordObservation(int16 newTick, uint32 timeElapsed) external isInitial
|`<none>`|`bool`|bool indicating whether the observation was recorded or not.|


### _recordObservation


```solidity
function _recordObservation(int16 newTick, uint32 timeElapsed) internal isInitialized returns (bool);
```

### getTickRange

Gets the min and max range of tick values from the stored oracle observations.
Expand Down Expand Up @@ -390,30 +447,6 @@ function getObservedMidTermTick(
|`<none>`|`int16`|midTermTick The mid-term tick value.|


### boundTick

*The function ensures that `newTick` stays within the bounds
determined by `lastTick` and a dynamically calculated factor.*


```solidity
function boundTick(
int16 newTick
) external view returns (int16);
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`newTick`|`int16`|The proposed new tick value to be adjusted within valid bounds.|

**Returns**

|Name|Type|Description|
|----|----|-----------|
|`<none>`|`int16`|The adjusted tick value constrained within the allowable range.|


### getLendingStateTick

Gets the tick value representing the TWAP since the last lending update.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
# AmmalgamFactory
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/82dff11576b9df76b675736dba889653cf737de9/contracts/factories/AmmalgamFactory.sol)
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/974388d084e9a0078440a75c2b625a4b268d530b/contracts/factories/AmmalgamFactory.sol)

**Inherits:**
[IAmmalgamFactory](/docs/developer-guide/contracts/interfaces/factories/IAmmalgamFactory.sol/interface.IAmmalgamFactory.md)


## State Variables
### tokenFactory
### pairBeacon

```solidity
address public immutable tokenFactory;
IBeacon public immutable override pairBeacon;
```


### pairFactory
### hookRegistry

```solidity
address public immutable pairFactory;
```


### pluginRegistry

```solidity
address public immutable pluginRegistry;
IHookRegistry public immutable hookRegistry;
```


Expand All @@ -48,6 +41,34 @@ ISaturationAndGeometricTWAPState public immutable saturationAndGeometricTWAPStat
```


### liquidityTokenFactory

```solidity
ITokenFactory private immutable liquidityTokenFactory;
```


### depositTokenFactory

```solidity
ITokenFactory private immutable depositTokenFactory;
```


### debtTokenFactory

```solidity
ITokenFactory private immutable debtTokenFactory;
```


### liquidityDebtTokenFactory

```solidity
ITokenFactory private immutable liquidityDebtTokenFactory;
```


### config

```solidity
Expand Down Expand Up @@ -83,10 +104,13 @@ modifier onlyFeeToSetter();
```solidity
constructor(
address _feeToSetter,
address _tokenFactory,
address _pairFactory,
address _pluginRegistry,
address _saturationAndGeometricTWAPState
IBeacon _pairBeacon,
IHookRegistry _hookRegistry,
ISaturationAndGeometricTWAPState _saturationAndGeometricTWAPState,
ITokenFactory _liquidityTokenFactory,
ITokenFactory _depositTokenFactory,
ITokenFactory _borrowTokenFactory,
ITokenFactory _liquidityDebtTokenFactory
);
```

Expand Down Expand Up @@ -118,6 +142,17 @@ function getConfig() private view returns (IFactoryCallback.TokenFactoryConfig m
function generateTokensWithinFactory() external returns (IERC20, IERC20, IAmmalgamERC20[6] memory);
```

### createAllTokens


```solidity
function createAllTokens(
address pair,
address tokenX,
address tokenY
) private returns (IAmmalgamERC20[6] memory tokens);
```

### setFeeTo


Expand All @@ -136,6 +171,26 @@ function setFeeToSetter(
) external onlyFeeToSetter;
```

### createPairFromSalt


```solidity
function createPairFromSalt(
bytes32 salt
) private returns (address pair);
```

### createToken


```solidity
function createToken(
address tokenFactory,
address asset,
ERC20BaseConfig memory _config
) private returns (IAmmalgamERC20);
```

## Events
### NewFeeTo

Expand Down Expand Up @@ -204,3 +259,9 @@ error Forbidden();
error NewTokensFailed();
```

### ERC20TokenFactoryFailed

```solidity
error ERC20TokenFactoryFailed();
```

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ERC20DebtLiquidityTokenFactory
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/82dff11576b9df76b675736dba889653cf737de9/contracts/factories/ERC20DebtLiquidityTokenFactory.sol)
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/974388d084e9a0078440a75c2b625a4b268d530b/contracts/factories/ERC20DebtLiquidityTokenFactory.sol)

**Inherits:**
[ITokenFactory](/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ERC20LiquidityTokenFactory
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/82dff11576b9df76b675736dba889653cf737de9/contracts/factories/ERC20LiquidityTokenFactory.sol)
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/974388d084e9a0078440a75c2b625a4b268d530b/contracts/factories/ERC20LiquidityTokenFactory.sol)

**Inherits:**
[ITokenFactory](/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ERC4626DebtTokenFactory
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/82dff11576b9df76b675736dba889653cf737de9/contracts/factories/ERC4626DebtTokenFactory.sol)
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/974388d084e9a0078440a75c2b625a4b268d530b/contracts/factories/ERC4626DebtTokenFactory.sol)

**Inherits:**
[ITokenFactory](/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ERC4626DepositTokenFactory
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/82dff11576b9df76b675736dba889653cf737de9/contracts/factories/ERC4626DepositTokenFactory.sol)
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/974388d084e9a0078440a75c2b625a4b268d530b/contracts/factories/ERC4626DepositTokenFactory.sol)

**Inherits:**
[ITokenFactory](/docs/developer-guide/contracts/interfaces/factories/ITokenFactory.sol/interface.ITokenFactory.md)
Expand Down
Loading