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

PoolOverlap

VPoolRead


State variables info

positionToken

coverToken

ecclesiaDao

strategyManager

claimManager

yieldRewarder

withdrawDelay

The delay after commiting before a position can be withdrawn

maxLeverage

The maximum amount of pools a position can supply liquidity to

leverageFeePerPool

The fee paid out to the DAO for each leveraged pool in a position

arePoolCompatible

coverToPool

Maps a cover ID to the ID of the pool storing the cover data

nextCompensationId

The ID of the next claim to be

nextPoolId

The token ID position data


Read Functions info

positions

positionInfo

Returns the up to date position data of a token

Parameters:

Name
Type
Description

positionId_

uint256

The ID of the position

Return values:

Name
Type
Description

--

struct PositionRead

The position data

coverInfo

Returns the up to date cover data of a token

Parameters:

Name
Type
Description

coverId_

uint256

The ID of the cover

Return values:

Name
Type
Description

--

struct CoverRead

The cover data formatted for reading

poolInfo

Returns the virtual pool's storage

Parameters:

Name
Type
Description

poolId_

uint64

The ID of the pool

Return values:

Name
Type
Description

--

struct VPoolRead

The virtual pool's storage

positionInfos

Returns the up to date data of an array of positions

Moved to LiquidityManager since cannot pass array of storage pointers in memory

Parameters:

Name
Type
Description

positionIds

uint256[]

The IDs of the positions

Return values:

Name
Type
Description

--

struct PositionRead[]

The positions data

coverInfos

Returns up to date data for an array of covers

Parameters:

Name
Type
Description

coverIds

uint256[]

The IDs of the covers

Return values:

Name
Type
Description

--

struct CoverRead[]

The array of covers data

poolInfos

Returns up to date data for an array of pools

Parameters:

Name
Type
Description

poolIds

uint256[]

The IDs of the pools

Return values:

Name
Type
Description

--

struct VPoolRead[]

The array of pools data

isCoverActive

Returns if the cover is still active or has expired

Parameters:

Name
Type
Description

coverId_

uint256

The ID of the cover

Return values:

Name
Type
Description

--

bool

True if the cover is still active, otherwise false

poolOverlaps

Returns amount liquidity overlap between two pools

The overlap is always stored in the pool with the lowest ID

Parameters:

Name
Type
Description

poolIdA_

uint64

The ID of the first pool

poolIdB_

uint64

The ID of the second pool

Return values:

Name
Type
Description

--

uint256

The amount of liquidity overlap


Write Functions info

openPosition

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:

Name
Type
Description

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

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:

Name
Type
Description

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

Takes the interests of a position

Parameters:

Name
Type
Description

positionId_

uint256

The ID of the position

commitRemoveLiquidity

Commits to withdraw the position's liquidity

Ongoing claims must be resolved before being able to commit

Parameters:

Name
Type
Description

positionId_

uint256

The ID of the position

uncommitRemoveLiquidity

Cancels a position's commit to withdraw its liquidity

Parameters:

Name
Type
Description

positionId_

uint256

The ID of the position

removeLiquidity

Closes a position and withdraws its liquidity

The position must be committed and the delay elapsed to withdrawal

Parameters:

Name
Type
Description

positionId_

uint256

The ID of the position

keepWrapped_

bool

True if the user wants to keep the strategy tokens

openCover

Buys a cover

Parameters:

Name
Type
Description

poolId_

uint64

The ID of the pool

coverAmount_

uint256

The amount of cover to buy

premiums_

uint256

The amount of premiums to pay

updateCover

Updates or closes a cover

If premiumsToRemove_ is max uint256 then withdraw premiums & closes the cover

Parameters:

Name
Type
Description

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

Emitted when a new pool is created

PositionOpenned

Emitted when a position is opened

InterestsTaken

Emitted when a position's liquidity is updated

PositionLiquidityUpdated

Emitted when a position's liquidity is updated

CoverOpenned

Emits when a new cover is bought

CoverUpdated

Emits when a cover is updated

CoverClosed

Emits when a cover is closed

CompensationPaid

Compensation is paid out for a claim

Last updated

Was this helpful?