LiquidityManager
The LiquidityManager contract is the main component of Athena's decentralized cover protocol. It serves as the core liquidity and cover management system, enabling users to provide liquidity, purchase cover, and participate in the protocol's risk-sharing mechanism.
The diamond proxy pattern is used to access its computation and storage manipulation libraries. Its VirtualPool library allows it to manage several liquidity layers within its storage in order to handle cross-pool liquidity distribution.
Structs info
CoverRead
struct CoverRead {
uint256 coverId;
uint64 poolId;
uint256 coverAmount;
bool isActive;
uint256 premiumsLeft;
uint256 dailyCost;
uint256 premiumRate;
uint32 lastTick;
}
PositionRead
struct PositionRead {
uint256 positionId;
uint256 supplied;
uint256 suppliedWrapped;
uint256 commitWithdrawalTimestamp;
uint256 strategyRewardIndex;
uint64[] poolIds;
uint256 newUserCapital;
uint256 newUserCapitalWrapped;
uint256[] coverRewards;
uint256 strategyRewards;
}
Position
struct Position {
uint256 supplied;
uint256 commitWithdrawalTimestamp;
uint256 strategyRewardIndex;
uint64[] poolIds;
}
PoolOverlap
struct PoolOverlap {
uint64 poolId;
uint256 amount;
}
VPoolRead
struct VPoolRead {
uint64 poolId;
uint256 feeRate;
uint256 leverageFeePerPool;
IEcclesiaDao dao;
IStrategyManager strategyManager;
PoolMath.Formula formula;
DataTypes.Slot0 slot0;
uint256 strategyId;
uint256 strategyRewardRate;
address paymentAsset;
address underlyingAsset;
address wrappedAsset;
bool isPaused;
uint64[] overlappedPools;
uint256 ongoingClaims;
uint256[] compensationIds;
uint256[] overlappedCapital;
uint256 utilizationRate;
uint256 totalLiquidity;
uint256 availableLiquidity;
uint256 strategyRewardIndex;
uint256 lastOnchainUpdateTimestamp;
uint256 premiumRate;
uint256 liquidityIndexLead;
}
State variables info
positionToken
contract IAthenaPositionToken positionToken
coverToken
contract IAthenaCoverToken coverToken
ecclesiaDao
contract IEcclesiaDao ecclesiaDao
strategyManager
contract IStrategyManager strategyManager
claimManager
address claimManager
yieldRewarder
address yieldRewarder
withdrawDelay
uint256 withdrawDelay
The delay after commiting before a position can be withdrawn
maxLeverage
uint256 maxLeverage
The maximum amount of pools a position can supply liquidity to
leverageFeePerPool
uint256 leverageFeePerPool
The fee paid out to the DAO for each leveraged pool in a position
arePoolCompatible
mapping(uint64 => mapping(uint64 => bool)) arePoolCompatible
coverToPool
mapping(uint256 => uint64) coverToPool
Maps a cover ID to the ID of the pool storing the cover data
nextCompensationId
uint256 nextCompensationId
The ID of the next claim to be
nextPoolId
uint64 nextPoolId
The token ID position data
Read Functions info
positions
function positions(
uint256 tokenId_
) external view returns (Position memory)
positionInfo
function positionInfo(
uint256 positionId_
) external view returns (PositionRead memory)
Returns the up to date position data of a token
Parameters:
positionId_
uint256
The ID of the position
Return values:
--
struct PositionRead
The position data
coverInfo
function coverInfo(
uint256 coverId_
) external view returns (CoverRead memory)
Returns the up to date cover data of a token
Parameters:
coverId_
uint256
The ID of the cover
Return values:
--
struct CoverRead
The cover data formatted for reading
poolInfo
function poolInfo(
uint64 poolId_
) external view returns (VPoolRead memory)
Returns the virtual pool's storage
Parameters:
poolId_
uint64
The ID of the pool
Return values:
--
struct VPoolRead
The virtual pool's storage
positionInfos
function positionInfos(
uint256[] calldata positionIds
) external view returns (PositionRead[] memory)
Returns the up to date data of an array of positions
Moved to LiquidityManager since cannot pass array of storage pointers in memory
Parameters:
positionIds
uint256[]
The IDs of the positions
Return values:
--
struct PositionRead[]
The positions data
coverInfos
function coverInfos(
uint256[] calldata coverIds
) external view returns (CoverRead[] memory)
Returns up to date data for an array of covers
Parameters:
coverIds
uint256[]
The IDs of the covers
Return values:
--
struct CoverRead[]
The array of covers data
poolInfos
function poolInfos(
uint256[] calldata poolIds
) external view returns (VPoolRead[] memory)
Returns up to date data for an array of pools
Parameters:
poolIds
uint256[]
The IDs of the pools
Return values:
--
struct VPoolRead[]
The array of pools data
isCoverActive
function isCoverActive(uint256 coverId_) public view returns (bool)
Returns if the cover is still active or has expired
Parameters:
coverId_
uint256
The ID of the cover
Return values:
--
bool
True if the cover is still active, otherwise false
poolOverlaps
function poolOverlaps(
uint64 poolIdA_,
uint64 poolIdB_
) public view returns (uint256)
Returns amount liquidity overlap between two pools
The overlap is always stored in the pool with the lowest ID
Parameters:
poolIdA_
uint64
The ID of the first pool
poolIdB_
uint64
The ID of the second pool
Return values:
--
uint256
The amount of liquidity overlap
Write Functions info
openPosition
function openPosition(
uint256 amount,
bool isWrapped,
uint64[] calldata poolIds
) external nonReentrant
Creates a new LP position
Wrapped tokens are tokens representing a position in a strategy, it allows the user to reinvest DeFi liquidity without having to withdraw
Parameters:
amount
uint256
The amount of tokens to supply
isWrapped
bool
True if the user can & wants to provide strategy tokens
poolIds
uint64[]
The IDs of the pools to provide liquidity to
addLiquidity
function addLiquidity(
uint256 positionId_,
uint256 amount,
bool isWrapped
) external onlyPositionOwner(positionId_) nonReentrant
Increases the position's provided liquidity
Wrapped tokens are tokens representing a position in a strategy, it allows the user to reinvest DeFi liquidity without having to withdraw
Parameters:
positionId_
uint256
The ID of the position
amount
uint256
The amount of tokens to supply
isWrapped
bool
True if the user can & wants to provide strategy tokens
takeInterests
function takeInterests(
uint256 positionId_
) public onlyPositionOwner(positionId_) nonReentrant
Takes the interests of a position
Parameters:
positionId_
uint256
The ID of the position
commitRemoveLiquidity
function commitRemoveLiquidity(
uint256 positionId_
) external onlyPositionOwner(positionId_) nonReentrant
Commits to withdraw the position's liquidity
Ongoing claims must be resolved before being able to commit
Parameters:
positionId_
uint256
The ID of the position
uncommitRemoveLiquidity
function uncommitRemoveLiquidity(
uint256 positionId_
) external onlyPositionOwner(positionId_) nonReentrant
Cancels a position's commit to withdraw its liquidity
Parameters:
positionId_
uint256
The ID of the position
removeLiquidity
function removeLiquidity(
uint256 positionId_,
uint256 amount_,
bool keepWrapped_
) external onlyPositionOwner(positionId_) nonReentrant
Closes a position and withdraws its liquidity
The position must be committed and the delay elapsed to withdrawal
Parameters:
positionId_
uint256
The ID of the position
keepWrapped_
bool
True if the user wants to keep the strategy tokens
openCover
function openCover(
uint64 poolId_,
uint256 coverAmount_,
uint256 premiums_
) external nonReentrant
Buys a cover
Parameters:
poolId_
uint64
The ID of the pool
coverAmount_
uint256
The amount of cover to buy
premiums_
uint256
The amount of premiums to pay
updateCover
function updateCover(
uint256 coverId_,
uint256 coverToAdd_,
uint256 coverToRemove_,
uint256 premiumsToAdd_,
uint256 premiumsToRemove_
) external onlyCoverOwner(coverId_) nonReentrant
Updates or closes a cover
If premiumsToRemove_ is max uint256 then withdraw premiums & closes the cover
Parameters:
coverId_
uint256
The ID of the cover
coverToAdd_
uint256
The amount of cover to add
coverToRemove_
uint256
The amount of cover to remove
premiumsToAdd_
uint256
The amount of premiums to add
premiumsToRemove_
uint256
The amount of premiums to remove
Events info
PoolCreated
event PoolCreated(uint64 indexed poolId)
Emitted when a new pool is created
PositionOpenned
event PositionOpenned(uint256 indexed positionId)
Emitted when a position is opened
InterestsTaken
event InterestsTaken(uint256 indexed positionId)
Emitted when a position's liquidity is updated
PositionLiquidityUpdated
event PositionLiquidityUpdated(uint256 indexed positionId, uint256 amountAdded, uint256 amountRemoved)
Emitted when a position's liquidity is updated
CoverOpenned
event CoverOpenned(uint64 indexed poolId, uint256 indexed coverId)
Emits when a new cover is bought
CoverUpdated
event CoverUpdated(uint256 indexed coverId)
Emits when a cover is updated
CoverClosed
event CoverClosed(uint256 indexed coverId)
Emits when a cover is closed
CompensationPaid
event CompensationPaid(uint256 indexed poolId, uint256 indexed compensationId)
Compensation is paid out for a claim
Last updated
Was this helpful?