-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathILiquidityAccumulator.sol
57 lines (49 loc) · 3.09 KB
/
ILiquidityAccumulator.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "./IAccumulator.sol";
import "../libraries/AccumulationLibrary.sol";
import "../libraries/ObservationLibrary.sol";
/**
* @title ILiquidityAccumulator
* @notice An interface that defines a "liquidity accumulator" - that is, cumulative liquidity levels - with a
* single quote token and many exchange tokens.
* @dev Liquidity accumulators are used to calculate time-weighted average liquidity levels.
*/
abstract contract ILiquidityAccumulator is IAccumulator {
/// @notice Emitted when the accumulator is updated.
/// @dev The accumulator's observation and cumulative values are updated when this is emitted.
/// @param token The address of the token that the update is for.
/// @param tokenLiquidity The amount of the token that is liquid in the underlying pool, in wei.
/// @param quoteTokenLiquidity The amount of the quote token that is liquid in the underlying pool, in wei.
/// @param timestamp The epoch timestamp of the update (in seconds).
event Updated(address indexed token, uint256 tokenLiquidity, uint256 quoteTokenLiquidity, uint256 timestamp);
/**
* @notice Calculates a liquidity levels from two different cumulative liquidity levels.
* @param firstAccumulation The first cumulative liquidity levels.
* @param secondAccumulation The last cumulative liquidity levels.
* @dev Reverts if the timestamp of the first accumulation is 0, or if it's not strictly less than the timestamp of
* the second.
* @return tokenLiquidity A time-weighted average liquidity level for a token, in wei, derived from two cumulative
* liquidity levels.
* @return quoteTokenLiquidity A time-weighted average liquidity level for the quote token, in wei, derived from two
* cumulative liquidity levels.
*/
function calculateLiquidity(
AccumulationLibrary.LiquidityAccumulator calldata firstAccumulation,
AccumulationLibrary.LiquidityAccumulator calldata secondAccumulation
) external view virtual returns (uint112 tokenLiquidity, uint112 quoteTokenLiquidity);
/// @notice Gets the last cumulative liquidity levels for the token and quote token that was stored.
/// @param token The address of the token to get the cumulative liquidity levels for (with the quote token).
/// @return The last cumulative liquidity levels (in wei) along with the timestamp of those levels.
function getLastAccumulation(
address token
) public view virtual returns (AccumulationLibrary.LiquidityAccumulator memory);
/// @notice Gets the current cumulative liquidity levels for the token and quote token.
/// @param token The address of the token to get the cumulative liquidity levels for (with the quote token).
/// @return The current cumulative liquidity levels (in wei) along with the timestamp of those levels.
function getCurrentAccumulation(
address token
) public view virtual returns (AccumulationLibrary.LiquidityAccumulator memory);
function liquidityDecimals() public view virtual returns (uint8);
}