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:

Return values:

coverInfo

function coverInfo(
    uint256 coverId_
) external view returns (CoverRead memory)

Returns the up to date cover data of a token

Parameters:

Return values:

poolInfo

function poolInfo(
    uint64 poolId_
) external view returns (VPoolRead memory)

Returns the virtual pool's storage

Parameters:

Return values:

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:

Return values:

coverInfos

function coverInfos(
    uint256[] calldata coverIds
) external view returns (CoverRead[] memory)

Returns up to date data for an array of covers

Parameters:

Return values:

poolInfos

function poolInfos(
    uint256[] calldata poolIds
) external view returns (VPoolRead[] memory)

Returns up to date data for an array of pools

Parameters:

Return values:

isCoverActive

function isCoverActive(uint256 coverId_) public view returns (bool)

Returns if the cover is still active or has expired

Parameters:

Return values:

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:

Return values:


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:

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:

takeInterests

function takeInterests(
    uint256 positionId_
) public onlyPositionOwner(positionId_) nonReentrant

Takes the interests of a position

Parameters:

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:

uncommitRemoveLiquidity

function uncommitRemoveLiquidity(
    uint256 positionId_
) external onlyPositionOwner(positionId_) nonReentrant

Cancels a position's commit to withdraw its liquidity

Parameters:

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:

openCover

function openCover(
    uint64 poolId_,
    uint256 coverAmount_,
    uint256 premiums_
) external nonReentrant

Buys a cover

Parameters:

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:


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