Skip to main content

BalancerLBPSwapper

an auction contract which cyclically sells one token for another using Balancer LBP

Functions

constructor

function constructor(
address _core,
struct BalancerLBPSwapper.OracleData oracleData,
uint256 _frequency,
uint256 _weightSmall,
uint256 _weightLarge,
address _tokenSpent,
address _tokenReceived,
address _tokenReceivingAddress,
uint256 _minTokenSpentBalance
) public

constructor for BalancerLBPSwapper @param _core Core contract to reference @param oracleData The parameters needed to initialize the OracleRef @param _frequency minimum time between auctions and duration of auction @param _weightSmall the small weight of weight changes (e.g. 5%) @param _weightLarge the large weight of weight changes (e.g. 95%) @param _tokenSpent the token to be auctioned @param _tokenReceived the token to buy @param _tokenReceivingAddress the address to send tokenReceived @param _minTokenSpentBalance the minimum amount of tokenSpent to kick off a new auction on swap()

Parameters

NameTypeDescription
_coreaddress
oracleDatastruct BalancerLBPSwapper.OracleData
_frequencyuint256
_weightSmalluint256
_weightLargeuint256
_tokenSpentaddress
_tokenReceivedaddress
_tokenReceivingAddressaddress
_minTokenSpentBalanceuint256

init

function init(
contract IWeightedPool _pool
) external

initialize Balancer LBP Needs to be a separate method because this contract needs to be deployed and supplied as the owner of the pool on construction. Includes various checks to ensure the pool contract is correct and initialization can only be done once @param _pool the Balancer LBP used for swapping

Parameters

NameTypeDescription
_poolcontract IWeightedPool

swap

function swap() external

Swap algorithm

    1. Withdraw existing LP tokens
2. Reset weights
3. Provide new liquidity
4. Trigger gradual weight change
5. Transfer remaining tokenReceived to tokenReceivingAddress
@dev assumes tokenSpent balance of contract exceeds minTokenSpentBalance to kick off a new auction

forceSwap

function forceSwap() external

Force a swap() call, without waiting afterTime. This should only be callable after init() call, when no other swap is happening (call reverts if weight change is in progress).

exitPool

function exitPool(
address to
) external

redeeem all assets from LP pool

Parameters

NameTypeDescription
toaddressdestination for withdrawn tokens

withdrawERC20

function withdrawERC20(
address token,
address to,
uint256 amount
) public

withdraw ERC20 from the contract

Parameters

NameTypeDescription
tokenaddressaddress of the ERC20 to send
toaddressaddress destination of the ERC20
amountuint256quantity of ERC20 to send

swapEndTime

function swapEndTime() public returns (uint256 endTime)

returns when the next auction ends

setSwapFrequency

function setSwapFrequency(
uint256 _frequency
) external

sets the minimum time between swaps

Parameters

NameTypeDescription
_frequencyuint256minimum time between swaps in seconds

setMinTokenSpent

function setMinTokenSpent(
uint256 newMinTokenSpentBalance
) external

sets the minimum token spent balance

Parameters

NameTypeDescription
newMinTokenSpentBalanceuint256minimum amount of FEI to trigger a new auction

setReceivingAddress

function setReceivingAddress(
address newTokenReceivingAddress
) external

Sets the address receiving swap's inbound tokens

Parameters

NameTypeDescription
newTokenReceivingAddressaddressthe address that will receive tokens

getTokensIn

function getTokensIn(
uint256 spentTokenBalance
) external returns (address[] tokens, uint256[] amountsIn)

return the amount of tokens needed to seed the next auction

Parameters

NameTypeDescription
spentTokenBalanceuint256

_swap

function _swap() internal

Swap algorithm

    1. Withdraw existing LP tokens
2. Reset weights
3. Provide new liquidity
4. Trigger gradual weight change
5. Transfer remaining tokenReceived to tokenReceivingAddress
@dev assumes tokenSpent balance of contract exceeds minTokenSpentBalance to kick off a new auction

_exitPool

function _exitPool() internal

_transferAll

function _transferAll(
address token,
address to
) internal

Parameters

NameTypeDescription
tokenaddress
toaddress

_setReceivingAddress

function _setReceivingAddress(
address newTokenReceivingAddress
) internal

Parameters

NameTypeDescription
newTokenReceivingAddressaddress

_initializePool

function _initializePool() internal

_getTokensIn

function _getTokensIn(
uint256 spentTokenBalance
) internal returns (uint256[] amountsIn)

Parameters

NameTypeDescription
spentTokenBalanceuint256

_setMinTokenSpent

function _setMinTokenSpent(
uint256 newMinTokenSpentBalance
) internal

Parameters

NameTypeDescription
newMinTokenSpentBalanceuint256

Events

WithdrawERC20

event WithdrawERC20(
address _caller,
address _token,
address _to,
uint256 _amount
)

Parameters

NameTypeDescription
_calleraddress
_tokenaddress
_toaddress
_amountuint256

ExitPool

event ExitPool(
)

MinTokenSpentUpdate

event MinTokenSpentUpdate(
uint256 oldMinTokenSpentBalance,
uint256 newMinTokenSpentBalance
)

Parameters

NameTypeDescription
oldMinTokenSpentBalanceuint256
newMinTokenSpentBalanceuint256