Elastic Core Contracts
Last updated
Last updated
Handles deployment of Kyberswap Elastic pools and where administrative configurations are held, such as the whitelisting of NFT position managers, and government fee settings.
parameters
Used by the Pool's constructor to fetch the parameters. The reason why they are not passed directly is for the automatic contract verification on Etherscan.
Field | Type | Explanation |
---|---|---|
poolInitHash
Type | Explanation |
---|---|
configMaster
Type | Explanation |
---|---|
whitelistDisabled
Type | Explanation |
---|---|
vestingPeriod
feeAmountTickDistance()
Returns the tick distance for a specified fee. Once added, cannot be updated or removed.
feeConfiguration()
getPool()
Returns the pool address for a given pair of tokens and a swap fee. Note that the token order does not matter.
Input
createPool()
Creates a pool for the given two tokens and fee. The token order does not matter.
The call reverts under the following conditions:
Pool already exists
Invalid swap fee (tickDistance is zero)
Invalid token arguments
Input
Output
isWhitelistedNFTManager()
Checks if an address is a whitelisted NFT manager. Returns true if it is, false if it is not.
getWhitelistedNFTManagers()
Returns an array of addresses of all whitelisted NFT managers.
updateConfigMaster()
To update the address of configMaster
. Can only be changed by configMaster
.
enableWhitelist()
Sets whitelistDisabled
to false, meaning, only whitelisted addresses are able to call the Pool's mint method. Can only be called by configMaster
.
disableWhitelist()
Sets whitelistDisabled
to true. Will allow anyone to call the Pool's mint method. Can only be called by configMaster
.
addNFTManager()
Whitelists an NFT manager. Returns true if addition was successful, that is if it was not already present. Can only be called by configMaster
.
removeNFTManager()
Removes a whitelisted NFT manager. Returns true if removal was successful, that is if it was not already present. Can only be called by configMaster
.
updateVestingPeriod()
Updates the value of vestingPeriod
. Can only be called by configMaster
.
enableSwapFee()
Enables a fee amount with the given tickDistance. The value cannot be updated or removed after setting. Can only be called by configMaster
.
updateFeeConfiguration()
Updates the address receiving government fees and government fee to be charged (taken out of swap fee).
Primarily contains the implementation of actionable items by users, such as adding or removing liquidity, executing swaps or flash loans, and burning reinvestment tokens in exchange for fees collected.
unlockPool()
Provides initial liquidity and sets initial price for the pool. All other actions cannot be performed prior to the execution of this function.
Note that this function should also be called at most once.
Input
Output
mint()
Adds liquidity to a specified recipient/tickLower/tickUpper position. Any token0 or token1 owed for the liquidity provision have to be paid for in the callback function.
Also sends reinvestment tokens (fees) to the recipient for any fees collected by the position. Reinvestment tokens have to be burnt via burnRTokens in exchange for token0 and token1.
Input
Output
burn()
Removes liquidity from the caller. In other words, the caller is treated as the position owner.
Also sends reinvestment tokens (fees) to the caller for any fees collected by the position. Reinvestment tokens have to be burnt via burnRTokens in exchange for token0 and token1.
Input
Output
burnRTokens()
Burns reinvestment tokens in exchange to receive the fees collected in token0 and token1.
Input
The use-case for burning tokens whilst leaving the collected fees in the pool is the anti-snipping attack mechanism.
Output
swap()
Swap token0 -> token1, or vice versa. Note that swaps will either fully use up the specified swap quantity, or swap up to the specified price limit, depending on whichever condition is satisfied first.
Input
Note
To specify an unlimited price limit for a swap, use the following values.
Output
flash()
Request for token0 and/or token1 and pay it back in the same transaction, plus a fee, in the callback. Fees collected are distributed to all rToken holders since no rTokens are minted from it.
Input
Contains all variables and getter methods to be used by the Pool contract. Inherited by PoolTickState.
factory
token0
token1
maxTickLiquidity
swapFeeBps
tickDistance
For instance, a tickDistance of 5 means ticks can be initialized every 5th tick, i.e., ..., -10, -5, 0, 5, 10, ...
ticks()
Retrieve information about a specified int24
tick.
initializedTicks()
Returns the previous and next initialized ticks from the specified tick.
Note
If the specified tick is uninitialized, the returned values are zero.
getPositions()
Returns the information about a position.
Inputs
Outputs
getPoolState()
Primarily returns the pool's current price and ticks, and whether it is locked.
getLiquidityState()
Fetches the pool's liquidity values.
getFeeGrowthGlobal()
Returns the all-time fee growth per unit of liquidity of the pool. More information can be found here.
getSecondsPerLiquidityData()
getSecondsPerLiquidityInside()
Calculates and returns the active time per unit of liquidity until up to the current timestamp.
Input
Output
_initPoolStorage()
Used by the pool to initialize relevant pool variables.
_positionKey()
Calculates the key to the positions mapping. It is simply the keccak256 hash of a specified address and lower and upper ticks.
Inherits PoolStorage. Contains functions for updating a tick's, position's or pool's state.
_updatePosition()
Calls _updateTick
on a position's lower and upper tick, calculates the fee growth inside between the 2 ticks and updates the position by calling _updatePositionData()
.
Returns the calculated reinvestment tokens to be minted for the position's accumulated fees.
_updateLiquidityAndCrossTick()
Called by the pool when crossing a tick. Updates the tick's outside values (read more here), and applies any change in liquidity to the pool's base liquidity.
Returns the new base liquidity and next tick values.
_updatePoolData()
Called after a pool swap's calculations are completed, and new values are to be assigned to the pool's price, liquidity and tick values.
_getInitialSwapData()
Returns the stored pool's price, liquidity and tick values before swap calculations are to be performed.
_updatePositionData()
Updates a position's liquidity and feeGrowthInside value. Also calculates the reinvestment tokens to be minted for the position's accumulated fees.
_updateTick()
Initializes / updates / deletes a tick's state (liquidity, outside values) and if required, inserts and removes the tick from the linked list by calling _updateTickList()
.
_updateTickList()
Add / remove a specified tick to / from the linked list. No changes are applied if the specified tick is either the MIN_TICK
or MAX_TICK
.
Type | Explanation |
---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Type | Explanation |
---|---|
Type | Explanation |
---|---|
Type | Explanation |
---|---|
Type | Explanation |
---|---|
Type | Explanation |
---|---|
Type | Explanation |
---|---|
Output Field | Type | Explanation |
---|---|---|
Output Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
Field | Type | Explanation |
---|---|---|
factory
address
this contract's address
token0
address
first pool token by address sort order
token1
address
second pool token by address sort order
swapFeeBps
uint16
fee to be collected upon every swap in the pool, in basis points
_tickDistance
int24
Minimum number of ticks between initialized ticks
bytes32
keccak256 hash of the pool's creation code. This is accessed by periphery contracts for the deterministic computation of a pool's address
address
The address that is able to modify different settings and parameters
bool
If true, anyone can directly mint liquidity from the pool. Otherwise, only whitelisted addresses are able to do so
uint32
The maximum time duration for which LP fees are proportionally burnt upon LP removals
Input, swapFeeBps
uint16
swap fee, in basis points
Output
int24
configured tick distance
_feeTo
address
recipient of government fees
_governmentFeeBps
uint16
current government fee charged in basis points. Taken out of swap fee
tokenA
address
contract address of either token0 or token1
tokenB
address
contract address of the other token
swapFeeBps
uint16
swap fee, in basis points
pool
address
The pool address. Returns null address if it does not exist
tokenA
address
contract address of either token0 or token1
tokenB
address
contract address of the other token
swapFeeBps
uint16
swap fee, in basis points
pool
address
created pool address
sender
address
address to be checked
_configMaster
address
new config master address
_nftManager
address
address to be whitelisted
_nftManager
address
whitelisted address to be removed
swapFeeBps
uint16
swap fee, in basis points
tickDistance
int24
desired tick distance
feeTo
address
recipient of government fees
governmentFeeBps
uint16
government fee charged in basis points
qty0
uint256
token0 quantity permanently locked in the pool
qty1
uint256
token1 quantity permanently locked in the pool
recipient
address
address for which the added liquidity is credited to. Equivalent to position owner
tickLower
int24
position's lower tick
tickUpper
int24
position's upper tick
ticksPrevious
int24[2]
an array containing 2 values tickLowerPrevious
and tickUpperPrevious
which are expected to be the nearest initialized tick <= tickLower
and tickUpper
respectively
qty
uint128
Liquidity quantity to mint
data
bytes
Data, if any, to be passed into the callback function
qty0
uint256
token0 quantity sent to the pool in exchange for specified liquidity quantity
qty1
uint256
token1 quantity sent to the pool in exchange for specified liquidity quantity
feeGrowthInside
uint256
position's updated feeGrowthInside value
tickLower
int24
position's lower tick
tickUpper
int24
position's upper tick
qty
uint128
Liquidity quantity to burn
qty0
uint256
token0 quantity sent to the caller
qty1
uint256
token1 quantity sent to the caller
feeGrowthInside
uint256
position's updated feeGrowthInside value
qty
uint256
Reinvestment token quantity to burn
bool
isLogicalBurn
false
= burning tokens without receiving any fees in exchange. true
= fees should be calculated and sent
qty0
uint256
token0 quantity sent to the caller
qty1
uint256
token1 quantity sent to the caller
recipient
address
address to receive the swap output
swapQty
int256
swap quantity, which implicitly configures the swap as exact input (>0), or exact output (<0)
isToken0
bool
whether the swapQty is specified in token0 (true) or token1 (false)
limitSqrtP
uint160
sqrt price limit to reach
data
bytes
Data, if any, to be passed into the callback function
isToken0
swapQty
Value
true
> 0
MIN_SQRT_RATIO + 1
true
< 0
MAX_SQRT_RATIO - 1
false
> 0
MAX_SQRT_RATIO - 1
false
< 0
MIN_SQRT_RATIO + 1
qty0
int256
exact token0 qty sent to recipient if < 0. Minimally received quantity if > 0
qty1
int256
exact token1 qty sent to recipient if < 0. Minimally received quantity if > 0
recipient
address
address which will receive the token0 and token1 quantities
qty0
uint256
token0 quantity to be loaned to the recipient
qty1
uint256
token1 quantity to be loaned to the recipient
data
bytes
Data, if any, to be passed into the callback function
IFactory
Canonical factory address fetched upon pool creation
IERC20
First of the two tokens of the pool, sorted by address
IERC20
Second of the two tokens of the pool, sorted by address
uint128
Maximum gross liquidity that an initialized tick can have. This is to prevent overflow the pool's active base liquidity (uint128)
uint16
fee to be charged for a swap in basis points
int24
Ticks can only be initialized and used at multiples of this value
liquidityGross
uint128
total liquidity amount from positions that uses this tick as a lower or upper tick
liquidityNet
int128
how much liquidity changes when the pool tick crosses up this tick
feeGrowthOutside
uint256
fee growth on the other side of the tick relative to the current tick. Appendix-A
secondsPerLiquidityOutside
uint128
seconds spent on the other side of the tick relative to the current tick. Appendix-A
previous
int24
Next initalized tick below the specified tick
next
int24
Next initalized tick above the specified tick
owner
address
position owner
tickLower
int24
position's lower tick
tickUpper
int24
position's upper tick
liquidity
uint128
position's liquidity amount
feeGrowthInsideLast
uint256
last cached fee growth inside the position as of the last action performed
baseL
uint128
total liquidity provided by active positions
reinvestL
uint128
liquidity is reinvested into the pool
reinvestLLast
uint128
last cached value of reinvestL
, used for calculating reinvestment token qty
secondsPerLiquidityGlobal
uint128
all-time seconds per unit of liquidity of the pool.
lastUpdateTime
uint32
timestamp of last performed updated to secondsPerLiquidityGlobal
tickLower
int24
a lower tick
tickUpper
int24
an upper tick
initialSqrtP
uint160
data
bytes
Data, if any, to be passed into the callback function
sqrtP
uint160
currentTick
int24
current tick that closely reflects sqrtP
nearestCurrentTick
int24
nearest initialized tick that is <= currentTick
locked
bool
true if pool is locked, false otherwise
secondsPerLiquidityInside
uint128
Initial sqrt price, multiplied by
current sqrt price, multiplied by
active time between tickLower
and tickUpper
. Note that its value is multiplied by .