Skip to content

Commit 23f7d06

Browse files
Updated contract docs for synchronize pull request poc/testTwapLag
1 parent 776e9d0 commit 23f7d06

54 files changed

Lines changed: 537 additions & 241 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/developer-guide/contracts/AmmalgamPair.sol/contract.AmmalgamPair.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AmmalgamPair
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/AmmalgamPair.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/AmmalgamPair.sol)
33

44
**Inherits:**
55
[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.
369369

370370

371371
```solidity
372-
function resetSaturation(
373-
Validation.InputParams memory inputParams,
374-
address borrower,
375-
address to,
376-
uint256 depositLToBeTransferredInLAssets,
377-
uint256 depositXToBeTransferredInXAssets,
378-
uint256 depositYToBeTransferredInYAssets
379-
) private;
372+
function resetSaturation(Validation.InputParams memory inputParams, address borrower, address to) private;
380373
```
381374
**Parameters**
382375

@@ -385,9 +378,6 @@ function resetSaturation(
385378
|`inputParams`|`Validation.InputParams`||
386379
|`borrower`|`address`|The account being liquidated.|
387380
|`to`|`address`|The account to send the liquidated deposit to|
388-
|`depositLToBeTransferredInLAssets`|`uint256`|The amount of L to be transferred to the liquidator.|
389-
|`depositXToBeTransferredInXAssets`|`uint256`|The amount of X to be transferred to the liquidator.|
390-
|`depositYToBeTransferredInYAssets`|`uint256`|The amount of Y to be transferred to the liquidator.|
391381

392382

393383
### liquidateLeverage
@@ -510,11 +500,37 @@ function validateOnUpdate(address validate, address update, bool alwaysUpdate) p
510500
function validateSolvency(address validate, bool alwaysUpdate) private;
511501
```
512502

513-
### getInputParamsAndUpdateSaturation
503+
### updateSaturationIfNeeded
504+
505+
Update saturation state for an account if it already exists in saturation.
506+
507+
*Note that during a repay of debt, we may not have an entry in saturation if
508+
1. The position is a straddle with a payout that never reaches zero
509+
2. Repay is occurring during a callback of a flash loan, saturation will not be updated
510+
until the end of the borrow call after the callback concludes.*
514511

515512

516513
```solidity
517-
function getInputParamsAndUpdateSaturation(address toUpdate, bool alwaysUpdate) private;
514+
function updateSaturationIfNeeded(
515+
address toUpdate
516+
) private;
517+
```
518+
**Parameters**
519+
520+
|Name|Type|Description|
521+
|----|----|-----------|
522+
|`toUpdate`|`address`|The account to update saturation for.|
523+
524+
525+
### updateSaturationAndBorrowCap
526+
527+
528+
```solidity
529+
function updateSaturationAndBorrowCap(
530+
Validation.InputParams memory inputParams,
531+
address account,
532+
bool skipMinOrMaxTickCheck
533+
) private;
518534
```
519535

520536
### getInputParams

docs/developer-guide/contracts/SaturationAndGeometricTWAPState.sol/contract.SaturationAndGeometricTWAPState.md

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SaturationAndGeometricTWAPState
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/SaturationAndGeometricTWAPState.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/SaturationAndGeometricTWAPState.sol)
33

44
**Inherits:**
55
Initializable, [ISaturationAndGeometricTWAPState](/docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md), OwnableUpgradeable
@@ -55,6 +55,13 @@ mapping(address => bool) internal isPairInitialized;
5555
```
5656

5757

58+
### borrowCapStateGivenPair
59+
60+
```solidity
61+
mapping(address => BorrowCap.State) internal borrowCapStateGivenPair;
62+
```
63+
64+
5865
## Functions
5966
### constructor
6067

@@ -151,10 +158,32 @@ function getAccount(
151158
) external view returns (Saturation.Account memory);
152159
```
153160

161+
### accountExistsInSaturation
162+
163+
Check if an account exists in either netX or netY saturation tree
164+
165+
166+
```solidity
167+
function accountExistsInSaturation(address pairAddress, address accountAddress) external view returns (bool exists);
168+
```
169+
**Parameters**
170+
171+
|Name|Type|Description|
172+
|----|----|-----------|
173+
|`pairAddress`|`address`|The address of the pair|
174+
|`accountAddress`|`address`|The address of the account to check|
175+
176+
**Returns**
177+
178+
|Name|Type|Description|
179+
|----|----|-----------|
180+
|`exists`|`bool`|True if the account exists in either tree|
181+
182+
154183
### update
155184

156-
update the borrow position of an account and potentially check (and revert) if the
157-
resulting sat is too high
185+
update the borrow position of an account, check the per-block borrow cap,
186+
and potentially check (and revert) if the resulting saturation is too high
158187

159188
*run accruePenalties before running this function*
160189

@@ -163,7 +192,10 @@ resulting sat is too high
163192
function update(
164193
Validation.InputParams memory inputParams,
165194
address account,
166-
bool skipMinOrMaxTickCheck
195+
bool skipMinOrMaxTickCheck,
196+
uint256 totalBorrowLAssets,
197+
uint256 totalBorrowXAssets,
198+
uint256 totalBorrowYAssets
167199
) public virtual isInitialized;
168200
```
169201
**Parameters**
@@ -172,7 +204,10 @@ function update(
172204
|----|----|-----------|
173205
|`inputParams`|`Validation.InputParams`| contains the position and pair params, like account borrows/deposits, current price and active liquidity|
174206
|`account`|`address`| for which is position is being updated|
175-
|`skipMinOrMaxTickCheck`|`bool`||
207+
|`skipMinOrMaxTickCheck`|`bool`| whether to skip the min/max tick check during validation|
208+
|`totalBorrowLAssets`|`uint256`| pair-level total BORROW_L assets (for borrow cap)|
209+
|`totalBorrowXAssets`|`uint256`| pair-level total BORROW_X assets (for borrow cap)|
210+
|`totalBorrowYAssets`|`uint256`| pair-level total BORROW_Y assets (for borrow cap)|
176211

177212

178213
### scaleDesiredSaturation
@@ -249,7 +284,7 @@ function calcSatChangeRatioBips(
249284
uint256 liqSqrtPriceInYInQ72,
250285
address pairAddress,
251286
address account
252-
) external view virtual isInitialized returns (uint256 ratioNetXBips, uint256 ratioNetYBips);
287+
) external view virtual isInitialized returns (uint256 ratioBips);
253288
```
254289
**Parameters**
255290

@@ -265,8 +300,7 @@ function calcSatChangeRatioBips(
265300

266301
|Name|Type|Description|
267302
|----|----|-----------|
268-
|`ratioNetXBips`|`uint256`|The ratio representing the change in netX saturation for account.|
269-
|`ratioNetYBips`|`uint256`|The ratio representing the change in netY saturation for account.|
303+
|`ratioBips`|`uint256`|The ratio representing the change saturation for account.|
270304

271305

272306
### getObservations
@@ -278,6 +312,13 @@ function getObservations(
278312
) external view returns (GeometricTWAP.Observations memory);
279313
```
280314

315+
### configBorrowCap
316+
317+
318+
```solidity
319+
function configBorrowCap(address pairAddress, uint16 _borrowCapBips) external onlyOwner;
320+
```
321+
281322
### configLongTermInterval
282323

283324
Configures the interval of long-term observations.

docs/developer-guide/contracts/factories/AmmalgamFactory.sol/contract.AmmalgamFactory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AmmalgamFactory
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/AmmalgamFactory.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/factories/AmmalgamFactory.sol)
33

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

docs/developer-guide/contracts/factories/ERC20DebtLiquidityTokenFactory.sol/contract.ERC20DebtLiquidityTokenFactory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ERC20DebtLiquidityTokenFactory
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/ERC20DebtLiquidityTokenFactory.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/factories/ERC20DebtLiquidityTokenFactory.sol)
33

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

docs/developer-guide/contracts/factories/ERC20LiquidityTokenFactory.sol/contract.ERC20LiquidityTokenFactory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ERC20LiquidityTokenFactory
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/ERC20LiquidityTokenFactory.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/factories/ERC20LiquidityTokenFactory.sol)
33

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

docs/developer-guide/contracts/factories/ERC4626DebtTokenFactory.sol/contract.ERC4626DebtTokenFactory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ERC4626DebtTokenFactory
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/ERC4626DebtTokenFactory.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/factories/ERC4626DebtTokenFactory.sol)
33

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

docs/developer-guide/contracts/factories/ERC4626DepositTokenFactory.sol/contract.ERC4626DepositTokenFactory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ERC4626DepositTokenFactory
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/factories/ERC4626DepositTokenFactory.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/factories/ERC4626DepositTokenFactory.sol)
33

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

docs/developer-guide/contracts/interfaces/IAmmalgamPair.sol/interface.IAmmalgamPair.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# IAmmalgamPair
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/IAmmalgamPair.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/interfaces/IAmmalgamPair.sol)
33

44
**Inherits:**
55
[ITransferValidator](/docs/developer-guide/contracts/interfaces/callbacks/ITransferValidator.sol/interface.ITransferValidator.md)

docs/developer-guide/contracts/interfaces/ISaturationAndGeometricTWAPState.sol/interface.ISaturationAndGeometricTWAPState.md

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ISaturationAndGeometricTWAPState
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/ISaturationAndGeometricTWAPState.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/interfaces/ISaturationAndGeometricTWAPState.sol)
33

44

55
## Functions
@@ -99,14 +99,43 @@ function getAccount(
9999
) external view returns (Saturation.Account memory);
100100
```
101101

102+
### accountExistsInSaturation
103+
104+
Check if an account exists in either netX or netY saturation tree
105+
106+
107+
```solidity
108+
function accountExistsInSaturation(address pairAddress, address accountAddress) external view returns (bool exists);
109+
```
110+
**Parameters**
111+
112+
|Name|Type|Description|
113+
|----|----|-----------|
114+
|`pairAddress`|`address`|The address of the pair|
115+
|`accountAddress`|`address`|The address of the account to check|
116+
117+
**Returns**
118+
119+
|Name|Type|Description|
120+
|----|----|-----------|
121+
|`exists`|`bool`|True if the account exists in either tree|
122+
123+
102124
### update
103125

104-
update the borrow position of an account and potentially check (and revert) if the
105-
resulting sat is too high
126+
update the borrow position of an account, check the per-block borrow cap,
127+
and potentially check (and revert) if the resulting saturation is too high
106128

107129

108130
```solidity
109-
function update(Validation.InputParams memory inputParams, address account, bool skipMinOrMaxTickCheck) external;
131+
function update(
132+
Validation.InputParams memory inputParams,
133+
address account,
134+
bool skipMinOrMaxTickCheck,
135+
uint256 totalBorrowLAssets,
136+
uint256 totalBorrowXAssets,
137+
uint256 totalBorrowYAssets
138+
) external;
110139
```
111140
**Parameters**
112141

@@ -115,6 +144,9 @@ function update(Validation.InputParams memory inputParams, address account, bool
115144
|`inputParams`|`Validation.InputParams`| contains the position and pair params, like account borrows/deposits, current price and active liquidity|
116145
|`account`|`address`| for which is position is being updated|
117146
|`skipMinOrMaxTickCheck`|`bool`| whether to skip the min/max tick check during validation|
147+
|`totalBorrowLAssets`|`uint256`| pair-level total BORROW_L assets (for borrow cap)|
148+
|`totalBorrowXAssets`|`uint256`| pair-level total BORROW_X assets (for borrow cap)|
149+
|`totalBorrowYAssets`|`uint256`| pair-level total BORROW_Y assets (for borrow cap)|
118150

119151

120152
### accruePenalties
@@ -156,7 +188,7 @@ function calcSatChangeRatioBips(
156188
uint256 liqSqrtPriceInYInQ72,
157189
address pairAddress,
158190
address account
159-
) external view returns (uint256 ratioNetXBips, uint256 ratioNetYBips);
191+
) external view returns (uint256 ratioBips);
160192
```
161193
**Parameters**
162194

@@ -172,10 +204,16 @@ function calcSatChangeRatioBips(
172204

173205
|Name|Type|Description|
174206
|----|----|-----------|
175-
|`ratioNetXBips`|`uint256`|The ratio representing the change in netX saturation for account.|
176-
|`ratioNetYBips`|`uint256`|The ratio representing the change in netY saturation for account.|
207+
|`ratioBips`|`uint256`|The ratio representing the change in saturation for account.|
208+
209+
210+
### configBorrowCap
177211

178212

213+
```solidity
214+
function configBorrowCap(address pairAddress, uint16 borrowCapBips) external;
215+
```
216+
179217
### configLongTermInterval
180218

181219
Configures the interval of long-term observations.

docs/developer-guide/contracts/interfaces/callbacks/IAmmalgamCallee.sol/interface.IBorrowCallback.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# IBorrowCallback
2-
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/2b185eab2df708b55f7ffa534655c69f626e73b3/contracts/interfaces/callbacks/IAmmalgamCallee.sol)
2+
[Git Source](https://github.com/Ammalgam-Protocol/core-v1/blob/4d2f4d795e41c416369cdfb007849b5c034fc068/contracts/interfaces/callbacks/IAmmalgamCallee.sol)
33

44

55
## Functions

0 commit comments

Comments
 (0)