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,22 +1,22 @@
# 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/61b1ab7701fa14fd2a7118a53d1bf31ffec17c1a/contracts/SaturationAndGeometricTWAPState.sol)

**Inherits:**
[ISaturationAndGeometricTWAPState](/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md), Ownable
Initializable, [ISaturationAndGeometricTWAPState](/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md), OwnableUpgradeable


## State Variables
### midTermIntervalConfig

```solidity
uint24 public immutable midTermIntervalConfig;
uint24 public midTermIntervalConfig;
```


### longTermIntervalConfig

```solidity
uint24 public immutable longTermIntervalConfig;
uint24 public longTermIntervalConfig;
```


Expand All @@ -41,6 +41,13 @@ mapping(address => mapping(address => uint256)) maxNewPositionSaturationInMAG2;
```


### lastUsedActiveLiquidityInLAssets

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


### isPairInitialized

```solidity
Expand All @@ -53,7 +60,14 @@ mapping(address => bool) internal isPairInitialized;


```solidity
constructor(uint24 _midTermIntervalConfig, uint24 _longTermIntervalConfig) Ownable(msg.sender);
constructor();
```

### initialize


```solidity
function initialize(uint24 _midTermIntervalConfig, uint24 _longTermIntervalConfig, address _owner) public initializer;
```

### isInitialized
Expand Down Expand Up @@ -90,28 +104,18 @@ function init(
function setNewPositionSaturation(address pair, uint256 maxDesiredSaturationMag2) external;
```

### getNewPositionSaturation


```solidity
function getNewPositionSaturation(
address pair,
address account
) internal view returns (uint256 maxDesiredSaturationInMAG2);
```

### getTree


```solidity
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 +125,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 Down Expand Up @@ -162,22 +161,55 @@ update the borrow position of an account and potentially check (and revert) if t


```solidity
function update(Validation.InputParams memory inputParams, address account) external virtual;
function update(
Validation.InputParams memory inputParams,
address account,
bool skipMinOrMaxTickCheck
) public virtual isInitialized;
```
**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|
|`skipMinOrMaxTickCheck`|`bool`||


### _update
### 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 _update(Validation.InputParams memory inputParams, address account) internal isInitialized;
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 +310,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) public virtual isInitialized returns (bool);
```
**Parameters**

Expand Down Expand Up @@ -325,17 +357,6 @@ function getTickRange(
|`<none>`|`int16`|maxTick The maximum tick value among the three observed ticks.|


### _getTickRange


```solidity
function _getTickRange(
address pair,
int16 currentTick,
bool includeLongTermTick
) internal view returns (int16, int16);
```

### getLendingStateTickAndCheckpoint

Gets the tick value representing the TWAP since the last
Expand Down Expand Up @@ -390,30 +411,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,43 +1,50 @@
# 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/61b1ab7701fa14fd2a7118a53d1bf31ffec17c1a/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;
IHookRegistry public immutable hookRegistry;
```


### pluginRegistry
### liquidityTokenFactory

```solidity
address public immutable pluginRegistry;
ITokenFactory private immutable liquidityTokenFactory;
```


### feeTo
### depositTokenFactory

```solidity
address public feeTo;
ITokenFactory private immutable depositTokenFactory;
```


### feeToSetter
### debtTokenFactory

```solidity
address public feeToSetter;
ITokenFactory private immutable debtTokenFactory;
```


### liquidityDebtTokenFactory

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


Expand All @@ -55,6 +62,20 @@ IFactoryCallback.TokenFactoryConfig private config;
```


### feeTo

```solidity
address public feeTo;
```


### feeToSetter

```solidity
address public feeToSetter;
```


### getPair

```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 @@ -186,6 +241,12 @@ error PairExists();
error BytecodeLengthZero();
```

### NewSatProxyIsZeroAddress

```solidity
error NewSatProxyIsZeroAddress();
```

### FailedOnDeploy

```solidity
Expand All @@ -204,3 +265,9 @@ error Forbidden();
error NewTokensFailed();
```

### ERC20TokenFactoryFailed

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

Loading