Maple
Search…
PoolLib
PoolLib is a library of utility functions used by Pool.

Functions

BPTVal

Calculates the value of BPT in units of Liquidity Asset. Vulnerable to flash-loan attacks where the attacker can artificially inflate the BPT price by swapping a large amount of Liquidity Asset into the Pool and swapping back after this function is called.
1
function BPTVal(
2
address _bPool,
3
address liquidityAsset,
4
address staker,
5
address stakeLocker
6
) view returns (
7
uint256
8
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
_bPool
address
address
The address of Balancer pool.
1
liquidityAsset
address
address
The asset used by Pool for liquidity to fund Loans.
2
staker
address
address
The address that deposited BPTs to StakeLocker.
3
stakeLocker
address
address
The contract that escrows the BPTs deposited by Staker.

Return Values:

Index
Name
Type
Internal Type
Description
0
uint256
uint256
The USDC value of Staker BPTs.

DL_FACTORY

1
function DL_FACTORY(
2
) view returns (
3
uint8
4
)
Copied!

Return Values:

Index
Name
Type
Internal Type
Description
0
uint8
uint8

MAX_UINT256

1
function MAX_UINT256(
2
) view returns (
3
uint256
4
)
Copied!

Return Values:

Index
Name
Type
Internal Type
Description
0
uint256
uint256

WAD

1
function WAD(
2
) view returns (
3
uint256
4
)
Copied!

Return Values:

Index
Name
Type
Internal Type
Description
0
uint256
uint256

calculateClaimAndPortions

Calculates portions of claim from DebtLocker to be used by Pool `claim` function.
1
function calculateClaimAndPortions(
2
uint256[7] claimInfo,
3
uint256 delegateFee,
4
uint256 stakingFee
5
) pure returns (
6
uint256 poolDelegatePortion,
7
uint256 stakeLockerPortion,
8
uint256 principalClaim,
9
uint256 interestClaim
10
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
claimInfo
uint256[7]
uint256[7]
[0] => Total Claimed, [1] => Interest Claimed, [2] => Principal Claimed, [3] => Fee Claimed, [4] => Excess Returned Claimed, [5] => Amount Recovered (from Liquidation), [6] => Default Suffered.
1
delegateFee
uint256
uint256
The portion of interest (basis points) that goes to the Pool Delegate.
2
stakingFee
uint256
uint256
The portion of interest (basis points) that goes to the StakeLocker.

Return Values:

Index
Name
Type
Internal Type
Description
0
poolDelegatePortion
uint256
uint256
The total funds to send to the Pool Delegate.
1
stakeLockerPortion
uint256
uint256
The total funds to send to the StakeLocker.
2
principalClaim
uint256
uint256
The total principal claim.
3
interestClaim
uint256
uint256
The total interest claim.

fromWad

Converts from WAD precision to Liquidity Asset precision.
1
function fromWad(
2
uint256 amt,
3
uint256 liquidityAssetDecimals
4
) pure returns (
5
uint256
6
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
amt
uint256
uint256
The amount to convert.
1
liquidityAssetDecimals
uint256
uint256
The Liquidity Asset decimal.

Return Values:

Index
Name
Type
Internal Type
Description
0
uint256
uint256

getInitialStakeRequirements

Returns information on the stake requirements.
1
function getInitialStakeRequirements(
2
IMapleGlobals globals,
3
address balancerPool,
4
address liquidityAsset,
5
address poolDelegate,
6
address stakeLocker
7
) view returns (
8
uint256 swapOutAmountRequired,
9
uint256 currentPoolDelegateCover,
10
bool enoughStakeForFinalization,
11
uint256 poolAmountInRequired,
12
uint256 poolAmountPresent
13
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
globals
IMapleGlobals
contract IMapleGlobals
The instance of a MapleGlobals.
1
balancerPool
address
address
The address of Balancer pool.
2
liquidityAsset
address
address
The address of Liquidity Asset, to be returned from swap out.
3
poolDelegate
address
address
The address of Pool Delegate.
4
stakeLocker
address
address
The address of StakeLocker.

Return Values:

Index
Name
Type
Internal Type
Description
0
swapOutAmountRequired
uint256
uint256
The minimum amount of Liquidity Asset coverage from staking required (in Liquidity Asset units).
1
currentPoolDelegateCover
uint256
uint256
The present amount of Liquidity Asset coverage from Pool Delegate stake (in Liquidity Asset units).
2
enoughStakeForFinalization
bool
bool
Whether enough stake is present from Pool Delegate for Pool finalization.
3
poolAmountInRequired
uint256
uint256
The BPTs required for minimum Liquidity Asset coverage.
4
poolAmountPresent
uint256
uint256
The current staked BPTs.

getPoolSharesRequired

Calculates BPTs required if burning BPTs for liquidityAsset, given supplied tokenAmountOutRequired. Vulnerable to flash-loan attacks where the attacker can artificially inflate the BPT price by swapping a large amount of liquidityAsset into the pool and swapping back after this function is called.
1
function getPoolSharesRequired(
2
address _bPool,
3
address liquidityAsset,
4
address staker,
5
address stakeLocker,
6
uint256 liquidityAssetAmountRequired
7
) view returns (
8
uint256 poolAmountInRequired,
9
uint256 stakerBalance
10
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
_bPool
address
address
The Balancer pool that issues the BPTs.
1
liquidityAsset
address
address
The swap out asset (e.g. USDC) to receive when burning BPTs.
2
staker
address
address
The address that deposited BPTs to stakeLocker.
3
stakeLocker
address
address
The contract that escrows BPTs deposited by staker.
4
liquidityAssetAmountRequired
uint256
uint256
The amount of liquidityAsset required to recover.

Return Values:

Index
Name
Type
Internal Type
Description
0
poolAmountInRequired
uint256
uint256
The required poolAmountIn.
1
stakerBalance
uint256
uint256
The poolAmountIn currently staked.

getSwapOutValue

Calculates Liquidity Asset swap out value of staker BPT balance escrowed in StakeLocker.
1
function getSwapOutValue(
2
address _bPool,
3
address liquidityAsset,
4
address staker,
5
address stakeLocker
6
) view returns (
7
uint256
8
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
_bPool
address
address
The Balancer pool that issues the BPTs.
1
liquidityAsset
address
address
The Swap out asset (e.g. USDC) to receive when burning BPTs.
2
staker
address
address
The address that deposited BPTs to StakeLocker.
3
stakeLocker
address
address
The contract that escrows BPTs deposited by Staker.

Return Values:

Index
Name
Type
Internal Type
Description
0
uint256
uint256
liquidityAsset The swap out value of staker BPTs.

getSwapOutValueLocker

Calculates Liquidity Asset swap out value of entire BPT balance escrowed in StakeLocker.
1
function getSwapOutValueLocker(
2
address _bPool,
3
address liquidityAsset,
4
address stakeLocker
5
) view returns (
6
uint256
7
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
_bPool
address
address
The Balancer pool that issues the BPTs.
1
liquidityAsset
address
address
The swap out asset (e.g. USDC) to receive when burning BPTs.
2
stakeLocker
address
address
The contract that escrows BPTs deposited by Staker.

Return Values:

Index
Name
Type
Internal Type
Description
0
uint256
uint256
liquidityAsset The swap out value of StakeLocker BPTs.

increaseCustodyAllowanceChecks

Performs all necessary checks for an `increaseCustodyAllowance` call.
1
function increaseCustodyAllowanceChecks(
2
address custodian,
3
uint256 amount,
4
uint256 newTotalAllowance,
5
uint256 fdtBal
6
) pure
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
custodian
address
address
The custodian where the funds will be locked to.
1
amount
uint256
uint256
The additional amount to custody.
2
newTotalAllowance
uint256
uint256
The new total amount in custody, for some account.
3
fdtBal
uint256
uint256
The the total FDT balance of some account.

poolSanityChecks

Conducts sanity checks for Pools in the constructor.
1
function poolSanityChecks(
2
IMapleGlobals globals,
3
address liquidityAsset,
4
address stakeAsset,
5
uint256 stakingFee,
6
uint256 delegateFee
7
) view
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
globals
IMapleGlobals
contract IMapleGlobals
The instance of a MapleGlobals.
1
liquidityAsset
address
address
The asset used by Pool for liquidity to fund loans.
2
stakeAsset
address
address
The asset escrowed in StakeLocker.
3
stakingFee
uint256
uint256
The fee that the Stakers earn on interest, in basis points.
4
delegateFee
uint256
uint256
The fee that the Pool Delegate earns on interest, in basis points.

transferByCustodianChecks

Performs all necessary checks for a `transferByCustodian` call. From and to must always be equal.
1
function transferByCustodianChecks(
2
address from,
3
address to,
4
uint256 amount
5
) pure
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
from
address
address
The address of the source of funds.
1
to
address
address
The address of the destination of funds.
2
amount
uint256
uint256
The amount of funds transfer.

validateDeactivation

Checks that the deactivation is allowed.
1
function validateDeactivation(
2
IMapleGlobals globals,
3
uint256 principalOut,
4
address liquidityAsset
5
) view
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
globals
IMapleGlobals
contract IMapleGlobals
The instance of a MapleGlobals.
1
principalOut
uint256
uint256
The amount of funds that are already funded to Loans.
2
liquidityAsset
address
address
The Liquidity Asset of the Pool.

Events

DepositDateUpdated

1
event DepositDateUpdated(
2
address liquidityProvider,
3
uint256 depositDate
4
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
liquidityProvider
address
address
1
depositDate
uint256
uint256

LoanFunded

1
event LoanFunded(
2
address loan,
3
address debtLocker,
4
uint256 amountFunded
5
)
Copied!

Parameters:

Index
Name
Type
Internal Type
Description
0
loan
address
address
1
debtLocker
address
address
2
amountFunded
uint256
uint256
Last modified 3mo ago