Skip to main content

ButtonswapFactory

Inherits: IButtonswapFactory

State Variables

feeTo

Returns the current address for feeTo. The owner of this address receives the protocol fee as it is collected over time.

address public feeTo;

feeToSetter

Returns the current address for feeToSetter. The owner of this address has the power to update both feeToSetter and feeTo.

address public feeToSetter;

getPair

Get the (unique) Pair address created for the given combination of tokenA and tokenB. If the Pair does not exist then zero address is returned.

mapping(address => mapping(address => address)) public getPair;

allPairs

Get the Pair address at the given index, ordered chronologically.

address[] public allPairs;

lastToken0

address internal lastToken0;

lastToken1

address internal lastToken1;

paramSetter

Returns the current address for paramSetter. The owner of this address has the power to update paramSetter, default parameters, and current parameters on existing pairs

address public paramSetter;

tokenName

The name of the ERC20 liquidity token.

string public tokenName;

tokenSymbol

The symbol of the ERC20 liquidity token.

string public tokenSymbol;

MAX_DURATION_BOUND

The upper limit on what duration parameters can be set to.

uint32 public constant MAX_DURATION_BOUND = 12 weeks;

MAX_BPS_BOUND

The upper limit on what BPS denominated parameters can be set to.

uint16 public constant MAX_BPS_BOUND = 10_000;

MIN_MOVING_AVERAGE_WINDOW_BOUND

The lower limit on what the movingAverageWindow can be set to.

uint32 public constant MIN_MOVING_AVERAGE_WINDOW_BOUND = 1 seconds;

MIN_SWAPPABLE_RESERVOIR_GROWTH_WINDOW_BOUND

The lower limit on what the swappableReservoirGrowthWindow can be set to.

uint32 public constant MIN_SWAPPABLE_RESERVOIR_GROWTH_WINDOW_BOUND = 1 seconds;

defaultMovingAverageWindow

Returns the default value of movingAverageWindow used for new pairs.

uint32 public defaultMovingAverageWindow = 24 hours;

defaultMaxVolatilityBps

Returns the default value of maxVolatilityBps used for new pairs.

uint16 public defaultMaxVolatilityBps = 700;

defaultMinTimelockDuration

Returns the default value of minTimelockDuration used for new pairs.

uint32 public defaultMinTimelockDuration = 24 seconds;

defaultMaxTimelockDuration

Returns the default value of maxTimelockDuration used for new pairs.

uint32 public defaultMaxTimelockDuration = 24 hours;

defaultMaxSwappableReservoirLimitBps

Returns the default value of maxSwappableReservoirLimitBps used for new pairs.

uint16 public defaultMaxSwappableReservoirLimitBps = 500;

defaultSwappableReservoirGrowthWindow

Returns the default value of swappableReservoirGrowthWindow used for new pairs.

uint32 public defaultSwappableReservoirGrowthWindow = 24 hours;

isCreationRestricted

Returns the current state of restricted creation. If true, then no new pairs, only feeToSetter can create new pairs

bool public isCreationRestricted;

isCreationRestrictedSetter

Returns the current address for isCreationRestrictedSetter. The owner of this address has the power to update both isCreationRestrictedSetter and isCreationRestricted.

address public isCreationRestrictedSetter;

isPausedSetter

Returns the current address for isPausedSetter. The owner of this address has the power to update both isPausedSetter and call setIsPaused.

address public isPausedSetter;

Functions

constructor

feeTo is not initialised during deployment, and must be set separately by a call to {setFeeTo}.

constructor(
address _feeToSetter,
address _isCreationRestrictedSetter,
address _isPausedSetter,
address _paramSetter,
string memory _tokenName,
string memory _tokenSymbol
);

Parameters

NameTypeDescription
_feeToSetteraddressThe account that has the ability to set feeToSetter and feeTo
_isCreationRestrictedSetteraddressThe account that has the ability to set isCreationRestrictedSetter and isCreationRestricted
_isPausedSetteraddressThe account that has the ability to set isPausedSetter and isPaused
_paramSetteraddressThe account that has the ability to set paramSetter, default parameters, and current parameters on existing pairs
_tokenNamestringThe name of the ERC20 liquidity token
_tokenSymbolstringThe symbol of the ERC20 liquidity token

allPairsLength

Get the current total number of Pairs created

function allPairsLength() external view returns (uint256 count);

Returns

NameTypeDescription
countuint256The total number of Pairs created

createPair

Creates a new {ButtonswapPair} instance for the given unsorted tokens tokenA and tokenB.

The tokens are sorted later, but can be provided to this method in either order.

function createPair(address tokenA, address tokenB) external returns (address pair);

Parameters

NameTypeDescription
tokenAaddressThe first unsorted token address
tokenBaddressThe second unsorted token address

Returns

NameTypeDescription
pairaddressThe address of the new {ButtonswapPair} instance

setFeeTo

Updates the address that receives the protocol fee. This can only be called by the feeToSetter address.

function setFeeTo(address _feeTo) external;

Parameters

NameTypeDescription
_feeToaddressThe new address

setFeeToSetter

Updates the address that has the power to set the feeToSetter and feeTo addresses. This can only be called by the feeToSetter address.

function setFeeToSetter(address _feeToSetter) external;

Parameters

NameTypeDescription
_feeToSetteraddressThe new address

setIsCreationRestricted

Updates the state of restricted creation. This can only be called by the feeToSetter address.

function setIsCreationRestricted(bool _isCreationRestricted) external;

Parameters

NameTypeDescription
_isCreationRestrictedboolThe new state

setIsCreationRestrictedSetter

Updates the address that has the power to set the isCreationRestrictedSetter and isCreationRestricted. This can only be called by the isCreationRestrictedSetter address.

function setIsCreationRestrictedSetter(address _isCreationRestrictedSetter) external;

Parameters

NameTypeDescription
_isCreationRestrictedSetteraddressThe new address

setIsPaused

Updates the pause state of given Pairs. This can only be called by the feeToSetter address.

function setIsPaused(address[] calldata pairs, bool isPausedNew) external;

Parameters

NameTypeDescription
pairsaddress[]A list of addresses for the pairs that should be updated
isPausedNewboolThe new pause state

setIsPausedSetter

Updates the address that has the power to set the isPausedSetter and call setIsPaused. This can only be called by the isPausedSetter address.

function setIsPausedSetter(address _isPausedSetter) external;

Parameters

NameTypeDescription
_isPausedSetteraddressThe new address

setParamSetter

Updates the address that has the power to set the paramSetter and update the default params. This can only be called by the paramSetter address.

function setParamSetter(address _paramSetter) external;

Parameters

NameTypeDescription
_paramSetteraddressThe new address

_validateNewMovingAverageWindow

movingAverageWindow must be in interval [MIN_MOVING_AVERAGE_WINDOW_BOUND, MAX_DURATION_BOUND] Refer to parameters.md for more detail.

function _validateNewMovingAverageWindow(uint32 newMovingAverageWindow) internal pure;

_validateNewMaxVolatilityBps

maxVolatilityBps must be in interval [0, MAX_BPS_BOUND] Refer to parameters.md for more detail.

function _validateNewMaxVolatilityBps(uint16 newMaxVolatilityBps) internal pure;

_validateNewMinTimelockDuration

minTimelockDuration must be in interval [0, MAX_DURATION_BOUND] Refer to parameters.md for more detail.

function _validateNewMinTimelockDuration(uint32 newMinTimelockDuration) internal pure;

_validateNewMaxTimelockDuration

maxTimelockDuration must be in interval [0, MAX_DURATION_BOUND] Refer to parameters.md for more detail.

function _validateNewMaxTimelockDuration(uint32 newMaxTimelockDuration) internal pure;

_validateNewMaxSwappableReservoirLimitBps

maxSwappableReservoirLimitBps must be in interval [0, MAX_BPS_BOUND] Refer to parameters.md for more detail.

function _validateNewMaxSwappableReservoirLimitBps(uint32 newMaxSwappableReservoirLimitBps) internal pure;

_validateNewSwappableReservoirGrowthWindow

swappableReservoirGrowthWindow must be in interval [MIN_SWAPPABLE_RESERVOIR_GROWTH_WINDOW_BOUND, MAX_DURATION_BOUND] Refer to parameters.md for more detail.

function _validateNewSwappableReservoirGrowthWindow(uint32 newSwappableReservoirGrowthWindow) internal pure;

setDefaultParameters

Updates the default parameters used for new pairs. This can only be called by the paramSetter address.

function setDefaultParameters(
uint32 newDefaultMovingAverageWindow,
uint16 newDefaultMaxVolatilityBps,
uint32 newDefaultMinTimelockDuration,
uint32 newDefaultMaxTimelockDuration,
uint16 newDefaultMaxSwappableReservoirLimitBps,
uint32 newDefaultSwappableReservoirGrowthWindow
) external;

Parameters

NameTypeDescription
newDefaultMovingAverageWindowuint32The new defaultMovingAverageWindow
newDefaultMaxVolatilityBpsuint16The new defaultMaxVolatilityBps
newDefaultMinTimelockDurationuint32The new defaultMinTimelockDuration
newDefaultMaxTimelockDurationuint32The new defaultMaxTimelockDuration
newDefaultMaxSwappableReservoirLimitBpsuint16The new defaultMaxSwappableReservoirLimitBps
newDefaultSwappableReservoirGrowthWindowuint32The new defaultSwappableReservoirGrowthWindow

setMovingAverageWindow

Updates the movingAverageWindow value of given Pairs. This can only be called by the paramSetter address.

function setMovingAverageWindow(address[] calldata pairs, uint32 newMovingAverageWindow) external;

Parameters

NameTypeDescription
pairsaddress[]A list of addresses for the pairs that should be updated
newMovingAverageWindowuint32The new movingAverageWindow value

setMaxVolatilityBps

Updates the maxVolatilityBps value of given Pairs. This can only be called by the paramSetter address.

function setMaxVolatilityBps(address[] calldata pairs, uint16 newMaxVolatilityBps) external;

Parameters

NameTypeDescription
pairsaddress[]A list of addresses for the pairs that should be updated
newMaxVolatilityBpsuint16The new maxVolatilityBps value

setMinTimelockDuration

Updates the minTimelockDuration value of given Pairs. This can only be called by the paramSetter address.

function setMinTimelockDuration(address[] calldata pairs, uint32 newMinTimelockDuration) external;

Parameters

NameTypeDescription
pairsaddress[]A list of addresses for the pairs that should be updated
newMinTimelockDurationuint32The new minTimelockDuration value

setMaxTimelockDuration

Updates the maxTimelockDuration value of given Pairs. This can only be called by the paramSetter address.

function setMaxTimelockDuration(address[] calldata pairs, uint32 newMaxTimelockDuration) external;

Parameters

NameTypeDescription
pairsaddress[]A list of addresses for the pairs that should be updated
newMaxTimelockDurationuint32The new maxTimelockDuration value

setMaxSwappableReservoirLimitBps

Updates the maxSwappableReservoirLimitBps value of given Pairs. This can only be called by the paramSetter address.

function setMaxSwappableReservoirLimitBps(address[] calldata pairs, uint16 newMaxSwappableReservoirLimitBps) external;

Parameters

NameTypeDescription
pairsaddress[]A list of addresses for the pairs that should be updated
newMaxSwappableReservoirLimitBpsuint16The new maxSwappableReservoirLimitBps value

setSwappableReservoirGrowthWindow

Updates the swappableReservoirGrowthWindow value of given Pairs. This can only be called by the paramSetter address.

function setSwappableReservoirGrowthWindow(address[] calldata pairs, uint32 newSwappableReservoirGrowthWindow)
external;

Parameters

NameTypeDescription
pairsaddress[]A list of addresses for the pairs that should be updated
newSwappableReservoirGrowthWindowuint32The new swappableReservoirGrowthWindow value

lastCreatedTokensAndParameters

Returns the last token pair created and the parameters used.

function lastCreatedTokensAndParameters()
external
view
returns (
address token0,
address token1,
uint32 movingAverageWindow,
uint16 maxVolatilityBps,
uint32 minTimelockDuration,
uint32 maxTimelockDuration,
uint16 maxSwappableReservoirLimitBps,
uint32 swappableReservoirGrowthWindow
);

Returns

NameTypeDescription
token0addressThe first token address
token1addressThe second token address
movingAverageWindowuint32The moving average window
maxVolatilityBpsuint16The max volatility bps
minTimelockDurationuint32The minimum time lock duration
maxTimelockDurationuint32The maximum time lock duration
maxSwappableReservoirLimitBpsuint16The max swappable reservoir limit bps
swappableReservoirGrowthWindowuint32The swappable reservoir growth window