Elastic Peripheral Library Contracts

AntiSnipingAttackarrow-up-right

The motivation and explanation of the mechanism can be found herearrow-up-right. The function containing the bulk of the logic is update().

Struct: Dataarrow-up-right

Field
Type
Formula Variable
Explanation

lastActionTime

uint32

tlastt_{last}

timestamp of last action performed

lockTime

uint32

tlockt_{lock}

average start time of lock schedule

unlockTime

uint32

tunlockt_{unlock}

average unlock time of locked fees

feesLocked

uint32

feelockedfee_{locked}

locked rToken qty since last update

initialize()arrow-up-right

Initializes Data values for a new position. The time variables are set to the current timestamp, while feesLocked is set to zero.

Updates Data values for an existing position. Calculates the amount of claimable reinvestment tokens to be sent to the user and, in the case of liquidity removal, the amount of burnable reinvestment tokens as well.

Formulaarrow-up-right

claimBpsnew=min(BPS,tnowtlockttarget)claimBps_{new} = min(BPS, \frac{t_{now}-t_{lock}}{t_{target}})

claimBpscurrent=min(BPS,tnowtlasttunlockttarget)claimBps_{current} = min(BPS, \frac{t_{now}-t_{last}}{t_{unlock} - t_{target}})

if tunlock>ttargett_{unlock} > t_{target}, BPSBPS otherwise feeharvestfee_{harvest} and feelockfee_{lock} updated through calcFeeProportions()arrow-up-right

tunlock=(tlock+ttarget)(BPSclaimBpsnew)feecollect+tunlock(BPSclaimBpscurrent)feelockedfeelockBPSt_{unlock} = \frac{(t_{lock} + t_{target}) * (BPS - claimBps_{new}) * fee_{collect} + t_{unlock} * (BPS - claimBps_{current}) * fee_{locked}}{fee_{lock} * BPS}

  • If adding liquidity, update tlock=ceil(max(tlock,tnowttarget)L+tnowΔLL+ΔL)t_{lock} = ceil(\frac{max(t_{lock}, t_{now} - t_{target})*L + t_{now} * \Delta{L}}{L + \Delta{L}})

  • If removing liquidity,

    • feeburn=feeharvestΔLLfee_{burn} = fee_{harvest} * \frac{\Delta{L}}{L}

    • feeharvestfee_{harvest} -= feeburnfee_{burn}

Inputarrow-up-right

Field
Type
Formula Variable
Explanation

self

N.A.

stored data values for an existing position

currentLiquidity

uint128

LL

current position liquidity

liquidityDelta

uint128

ΔL\Delta{L}

quantity change to be applied

currentTime

uint32

tnowt_{now}

current block timestamp

isAddLiquidity

bool

N.A.

true = add liquidity, false = remove liquidity

feesSinceLastAction

uint256

feecollectfee_{collect}

fees accrued since last action

vestingPeriod

uint256

ttargett_{target}

maximum time duration for which LP fees are proportionally burnt upon LP removals

Outputarrow-up-right

Field
Type
Formula Variable
Explanation

feesClaimable

uint256

feeharvestfee_{harvest}

claimable reinvestment token amount

feesBurnable

uint256

feeburnfee_{burn}

reinvestment token amount to burn

calcFeeProportions()arrow-up-right

Calculates the proportion of locked fees and claimable fees given the fee amounts and claimable fee basis points.

Formulaarrow-up-right

feeharvest=claimBpscurrentBPSfeelocked+claimBpsnewBPSfeecollectfee_{harvest} = \frac{claimBps_{current}}{BPS} * fee_{locked} + \frac{claimBps_{new}}{BPS} * fee_{collect} feelock=feelocked+feecollectfeeharvestfee_{lock} = fee_{locked} + fee_{collect} - fee_{harvest}

Inputarrow-up-right

Field
Type
Formula Variable
Explanation

currentFees

uint256

feelockedfee_{locked}

currently locked fees

nextFees

uint256

feecollectfee_{collect}

fees since last action

currentClaimableBps

uint256

claimBpscurrentclaimBps_{current}

proportion of claimable / unlocked currentFees in basis points

nextClaimableBps

uint256

claimBpsnewclaimBps_{new}

proportion of claimable nextFees in basis points

Outputarrow-up-right

Field
Type
Formula Variable
Explanation

feesLockedNew

uint256

feelockfee_{lock}

new fee amount to be locked

feesClaimable

uint256

feeharvestfee_{harvest}

claimable fees to be sent to user

Solidity Bytes Arrays Utils @author Gonçalo Sá [email protected]envelope

Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. The library lets you slice and type cast bytes arrays both in memory and storage.

LiquidityMatharrow-up-right

Contract to calculate the expected amount of liquidity given the amounts of tokens.

getLiquidityFromQty0()arrow-up-right

Get liquidity from qty0 of the first token given the price range.

getLiquidityFromQty1()arrow-up-right

Get liquidity from qty1 of the second token given the price range.

getLiquidityFromQties()arrow-up-right

Get liquidity given the price range and amounts of 2 tokens

Functions for manipulating path data for multihop swaps

hasMultiplePools()arrow-up-right

Return true if the path contains 2 or more pools, false otherwise

Returns the number of pools in the path.

decodeFirstPool()arrow-up-right

Return the first pool's data from the path, including tokenA, tokenB and fee.

getFirstPool()arrow-up-right

Return the segment corresponding to the first pool in the path.

Skip a token + fee from the buffer and returns the remainder.

Provides a function for deriving a pool address from the factory, tokens, and swap fee

computeAddress()arrow-up-right

Deterministically computes the pool address from the given data.

PoolTicksCounterarrow-up-right

countInitializedTicksCrossed()arrow-up-right

Count the number of initialized ticks have been crossed given the previous/current nearest initialized ticks to the current tick.

A helper contract to transfer token/ETH.

transferToken()arrow-up-right

Transfer an amount of ERC20 token from the sender to the receiver.

transferEth()arrow-up-right

Transfer an amount of ETH to the receiver.

Last updated

Was this helpful?