LBFactory
Last updated
Last updated
Inherits: Ownable2Step, AccessControl,
Author: Trader Joe
Contract used to deploy and register new LBPairs.
Enables setting fee parameters, flashloan fees and LBPair implementation.
Unless the isOpen
is true
, only the owner of the factory can create pairs.
Mapping from a (tokenA, tokenB, binStep) to a LBPair. The tokens are ordered to save gas, but they can be in the reverse order in the actual pair. Always query one of the 2 tokens of the pair to assert the order of the 2 tokens
Mapping from a (tokenA, tokenB) to a set of available bin steps, this is used to keep track of the bin steps that are already used for a pair. The tokens are ordered to save gas, but they can be in the reverse order in the actual pair. Always query one of the 2 tokens of the pair to assert the order of the 2 tokens
Constructor
Parameters
feeRecipient
address
The address of the fee recipient
initialOwner
address
flashLoanFee
uint256
The value of the fee for flash loan
Get the minimum bin step a pair can have
Returns
minBinStep
uint256
minBinStep
Get the protocol fee recipient
Returns
feeRecipient
address
feeRecipient
Get the maximum fee percentage for flashLoans
Returns
maxFee
uint256
maxFee
Get the fee for flash loans, in 1e18
Returns
flashLoanFee
uint256
The fee for flash loans, in 1e18
Get the address of the LBPair implementation
Returns
lbPairImplementation
address
The address of the LBPair implementation
View function to return the number of LBPairs created
Returns
lbPairNumber
uint256
lbPairNumber
View function to return the LBPair created at index index
Parameters
index
uint256
The index
Returns
lbPair
ILBPair
The address of the LBPair at index index
View function to return the number of quote assets whitelisted
Returns
numberOfQuoteAssets
uint256
The number of quote assets
View function to return the quote asset whitelisted at index index
Parameters
index
uint256
The index
Returns
asset
IERC20
The address of the quoteAsset at index index
View function to return whether a token is a quotedAsset (true) or not (false)
Parameters
token
IERC20
The address of the asset
Returns
isQuote
bool
Whether the token is a quote asset or not
Returns the LBPairInformation if it exists, if not, then the address 0 is returned. The order doesn't matter
Parameters
tokenA
IERC20
The address of the first token of the pair
tokenB
IERC20
The address of the second token of the pair
binStep
uint256
The bin step of the LBPair
Returns
lbPairInformation
LBPairInformation
The LBPairInformation
View function to return the different parameters of the preset Will revert if the preset doesn't exist
Parameters
binStep
uint256
The bin step of the preset
Returns
baseFactor
uint256
The base factor
filterPeriod
uint256
The filter period of the preset
decayPeriod
uint256
The decay period of the preset
reductionFactor
uint256
The reduction factor of the preset
variableFeeControl
uint256
The variable fee control of the preset
protocolShare
uint256
The protocol share of the preset
maxVolatilityAccumulator
uint256
The max volatility accumulator of the preset
isOpen
bool
Whether the preset is open or not
View function to return the list of available binStep with a preset
Returns
binStepWithPreset
uint256[]
The list of binStep
View function to return the list of open binSteps
Returns
openBinStep
uint256[]
The list of open binSteps
View function to return all the LBPair of a pair of tokens
Parameters
tokenX
IERC20
The first token of the pair
tokenY
IERC20
The second token of the pair
Returns
lbPairsAvailable
LBPairInformation[]
The list of available LBPairs
Set the LBPair implementation address
Needs to be called by the owner
Parameters
newLBPairImplementation
address
The address of the implementation
Create a liquidity bin LBPair for tokenX and tokenY
Parameters
tokenX
IERC20
The address of the first token
tokenY
IERC20
The address of the second token
activeId
uint24
The active id of the pair
binStep
uint16
The bin step in basis point, used to calculate log(1 + binStep / 10_000)
Returns
pair
ILBPair
The address of the newly created LBPair
Function to set whether the pair is ignored or not for routing, it will make the pair unusable by the router
*Needs to be called by the owner Reverts if:
The pair doesn't exist
The ignored state is already in the same state*
Parameters
tokenX
IERC20
The address of the first token of the pair
tokenY
IERC20
The address of the second token of the pair
binStep
uint16
The bin step in basis point of the pair
ignored
bool
Whether to ignore (true) or not (false) the pair for routing
Sets the preset parameters of a bin step
*Needs to be called by the owner Reverts if:
The binStep is lower than the minimum bin step*
Parameters
binStep
uint16
The bin step in basis point, used to calculate the price
baseFactor
uint16
The base factor, used to calculate the base fee, baseFee = baseFactor * binStep
filterPeriod
uint16
The period where the accumulator value is untouched, prevent spam
decayPeriod
uint16
The period where the accumulator value is decayed, by the reduction factor
reductionFactor
uint16
The reduction factor, used to calculate the reduction of the accumulator
variableFeeControl
uint24
The variable fee control, used to control the variable fee, can be 0 to disable it
protocolShare
uint16
The share of the fees received by the protocol
maxVolatilityAccumulator
uint24
The max value of the volatility accumulator
isOpen
bool
Sets if the preset is open or not to be used by users
*Needs to be called by the owner Reverts if:
The binStep doesn't have a preset
The preset is already in the same state*
Parameters
binStep
uint16
The bin step in basis point, used to calculate the price
isOpen
bool
Whether the preset is open or not
Remove the preset linked to a binStep
*Needs to be called by the owner Reverts if:
The binStep doesn't have a preset*
Parameters
binStep
uint16
The bin step to remove
Function to set the fee parameter of a LBPair
*Needs to be called by the owner Reverts if:
The pair doesn't exist*
Parameters
tokenX
IERC20
The address of the first token
tokenY
IERC20
The address of the second token
binStep
uint16
The bin step in basis point, used to calculate the price
baseFactor
uint16
The base factor, used to calculate the base fee, baseFee = baseFactor * binStep
filterPeriod
uint16
The period where the accumulator value is untouched, prevent spam
decayPeriod
uint16
The period where the accumulator value is decayed, by the reduction factor
reductionFactor
uint16
The reduction factor, used to calculate the reduction of the accumulator
variableFeeControl
uint24
The variable fee control, used to control the variable fee, can be 0 to disable it
protocolShare
uint16
The share of the fees received by the protocol
maxVolatilityAccumulator
uint24
The max value of volatility accumulator
Function to set the hooks parameters of a pair
*Needs to be called by an address with the LB_HOOKS_MANAGER_ROLE Reverts if:
The pair doesn't exist
The hooks is address(0)
or the hooks flags are all false*
Parameters
tokenX
IERC20
The address of the first token
tokenY
IERC20
The address of the second token
binStep
uint16
The bin step in basis point, used to calculate the price
hooksParameters
bytes32
The hooks parameters
onHooksSetData
bytes
The data to pass to the onHooksSet function
Function to remove the hooks contract from the pair
*Needs to be called by an address with the LB_HOOKS_MANAGER_ROLE Reverts if:
The pair doesn't exist*
Parameters
tokenX
IERC20
The address of the first token
tokenY
IERC20
The address of the second token
binStep
uint16
The bin step in basis point, used to calculate the price
Function to set the recipient of the fees. This address needs to be able to receive ERC20s
*Needs to be called by the owner Reverts if:
The feeRecipient is address(0)
The feeRecipient is the same as the current one*
Parameters
feeRecipient
address
The address of the recipient
Function to set the flash loan fee
*Needs to be called by the owner Reverts if:
The flashLoanFee is the same as the current one
The flashLoanFee is above the maximum flash loan fee*
Parameters
flashLoanFee
uint256
The value of the fee for flash loan
Function to add an asset to the whitelist of quote assets
*Needs to be called by the owner Reverts if:
The quoteAsset is already whitelisted*
Parameters
quoteAsset
IERC20
The quote asset (e.g: NATIVE, USDC...)
Function to remove an asset from the whitelist of quote assets
*Needs to be called by the owner Reverts if:
The quoteAsset was not whitelisted*
Parameters
quoteAsset
IERC20
The quote asset (e.g: NATIVE, USDC...)
Internal function to set the recipient of the fee
Parameters
feeRecipient
address
The address of the recipient
Function to force the decay of the volatility accumulator of a pair
Needs to be called by the owner
Parameters
pair
ILBPair
The pair to force the decay
Returns the LBPairInformation if it exists, if not, then the address 0 is returned. The order doesn't matter
Parameters
tokenA
IERC20
The address of the first token of the pair
tokenB
IERC20
The address of the second token of the pair
binStep
uint256
The bin step of the LBPair
Returns
<none>
LBPairInformation
The LBPairInformation
Private view function to sort 2 tokens in ascending order
Parameters
tokenA
IERC20
The first token
tokenB
IERC20
The second token
Returns
<none>
IERC20
The sorted first token
<none>
IERC20
The sorted second token
Internal function to set a hooks contract to the pair
Parameters
tokenX
IERC20
The address of the first token
tokenY
IERC20
The address of the second token
binStep
uint16
The bin step in basis point, used to calculate the price
hooksParameters
bytes32
The hooks parameters
onHooksSetData
bytes
The data to pass to the onHooksSet function
Returns whether the caller has the role or not, only the owner has the DEFAULT_ADMIN_ROLE
Parameters
role
bytes32
The role to check
account
address
The address to check
Returns
<none>
bool
Whether the account has the role or not
Grants a role to an address, the DEFAULT_ADMIN_ROLE can not be granted
Parameters
role
bytes32
The role to grant
account
address
The address to grant the role to
Returns
<none>
bool
Whether the role has been granted or not