Skip to main content

Proxy

Proxy Functions

batchSwapExactIn

  function batchSwapExactIn(
struct ProxyStruct.Swap[] swaps,
address tokenIn,
address tokenOut,
uint256 totalAmountIn,
uint256 minTotalAmountOut,
uint256 deadline
) external returns (uint256 totalAmountOut)

Swap the same tokenIn/tokenOut pair from multiple pools given the amount of tokenIn on each swap

totalAmountIn should be equal to the sum of tokenAmountIn on each swap

Parameters:

NameTypeDescription
swapsstruct ProxyStruct.Swap[]Array of swaps
tokenInaddressAddress of tokenIn
tokenOutaddressAddress of tokenOut
totalAmountInuint256Maximum amount of tokenIn that the user is willing to trade
minTotalAmountOutuint256Minimum amount of tokenOut that the user wants to receive
deadlineuint256Maximum deadline for accepting the trade

Return Values:

NameTypeDescription
totalAmountOutstruct ProxyStruct.Swap[]Total amount of tokenOut received

batchSwapExactOut

  function batchSwapExactOut(
struct ProxyStruct.Swap[] swaps,
address tokenIn,
address tokenOut,
uint256 totalAmountIn,
uint256 deadline
) external returns (uint256 totalAmountIn)

Swap the same tokenIn/tokenOut pair from multiple pools given the amount of tokenOut on each swap

Parameters:

NameTypeDescription
swapsstruct ProxyStruct.Swap[]Array of swaps
tokenInaddressAddress of tokenIn
tokenOutaddressAddress of tokenOut
totalAmountInuint256Maximum amount of tokenIn that the user is willing to trade
deadlineuint256Maximum deadline for accepting the trade

Return Values:

NameTypeDescription
totalAmountInstruct ProxyStruct.Swap[]Total amount of traded tokenIn

multihopBatchSwapExactIn

  function multihopBatchSwapExactIn(
struct ProxyStruct.Swap[][] swapSequences,
address tokenIn,
address tokenOut,
uint256 totalAmountIn,
uint256 minTotalAmountOut,
uint256 deadline
) external returns (uint256 totalAmountOut)

Performs multiple swapSequences given the amount of tokenIn on each swap

Few considerations:

  • swapSequences[i][j]: a) i: represents a swap sequence (swapSequences[i] : tokenIn --> B --> C --> tokenOut) b) j: represents a swap (swapSequences[i][0]: tokenIn --> B)
  • rows 'i' could be of varying lengths for ex:
  • swapSequences = {swapSequence 1: tokenIn --> B --> C --> tokenOut, swapSequence 2: tokenIn --> tokenOut}
  • each swap sequence should have the same starting tokenIn and finishing tokenOut
  • totalAmountIn should be equal to the sum of tokenAmountIn on each swapSequence

Parameters:

NameTypeDescription
swapSequencesstruct ProxyStruct.Swap[][]Array of swapSequences
tokenInaddressAddress of tokenIn
tokenOutaddressAddress of tokenOut
totalAmountInuint256Maximum amount of tokenIn that the user is willing to trade
minTotalAmountOutuint256Minimum amount of tokenOut that the user must receive
deadlineuint256Maximum deadline for accepting the trade

Return Values:

NameTypeDescription
totalAmountOutstruct ProxyStruct.Swap[][]Total amount of tokenOut received

multihopBatchSwapExactOut

  function multihopBatchSwapExactOut(
struct ProxyStruct.Swap[][] swapSequences,
address tokenIn,
address tokenOut,
uint256 maxTotalAmountIn,
uint256 deadline
) external returns (uint256 totalAmountIn)

Performs multiple swapSequences given the amount of tokenOut on each swapSequence

Few considerations:

  • swapSequences[i][j]: a) i: represents a swap sequence (swapSequences[i] : tokenIn --> B --> tokenOut) b) j: represents a swap (swapSequences[i][0]: tokenIn --> B)
  • rows 'i' could be of varying lengths for ex:
  • swapSequences = {swapSequence 1: tokenIn --> B --> tokenOut, swapSequence 2: tokenIn --> tokenOut}
  • each swap sequence should have the same starting tokenIn and finishing tokenOut
  • maxTotalAmountIn can be differennt than the sum of tokenAmountIn on each swapSequence
  • totalAmountOut is equal to the sum of the amount of tokenOut on each swap sequence
  • /!\ /!\ a swap sequence should have 1 multihop at most (swapSequences[i].length <= 2) /!\ /!\

Parameters:

NameTypeDescription
swapSequencesstruct ProxyStruct.Swap[][]Array of swapSequences
tokenInaddressAddress of tokenIn
tokenOutaddressAddress of tokenOut
maxTotalAmountInuint256Maximum amount of tokenIn that the user is willing to trade
deadlineuint256Maximum deadline for accepting the trade

Return Values:

NameTypeDescription
totalAmountInstruct ProxyStruct.Swap[][]Total amount of traded tokenIn

createBalancedPoolWithParams

  function createBalancedPoolWithParams(
struct ProxyStruct.BindToken[] bindTokens,
struct ProxyStruct.Params params,
contract IFactory finalize,
bool deadline
) external returns (address poolAddress)

Creates a balanced pool with customized parameters where oracle-spot-price == pool-spot-price

A pool is balanced if (balanceI weight_j) / (balance_j weight_i) = oraclePrice_j / oraclePrice_i, for all i != j as a result: balanceI = (oraclePrice_j balance_j weight_i) / (oraclePrice_i * weight_j)

Parameters:

NameTypeDescription
bindTokensstruct ProxyStruct.BindToken[]Array containing the information of the tokens to bind [tokenAddress, balance, weight, oracleAddress]
paramsstruct ProxyStruct.ParamsCustomized parameters of the pool
finalizecontract IFactoryBool to finalize the pool or not
deadlineboolMaximum deadline for accepting the creation of the pool

Return Values:

NameTypeDescription
poolAddressstruct ProxyStruct.BindToken[]The created pool's address

createPoolWithParams

  function createPoolWithParams(
struct ProxyStruct.BindToken[] bindTokens,
struct ProxyStruct.Params params,
contract IFactory finalize,
bool deadline
) external returns (address poolAddress)

Creates a pool with customized parameters

Parameters:

NameTypeDescription
bindTokensstruct ProxyStruct.BindToken[]Array containing the information of the tokens to bind [tokenAddress, balance, weight, oracleAddress]
paramsstruct ProxyStruct.ParamsCustomized parameters of the pool
finalizecontract IFactoryBool to finalize the pool or not
deadlineboolMaximum deadline for accepting the creation of the pool

Return Values:

NameTypeDescription
poolAddressstruct ProxyStruct.BindToken[]The created pool's address

createPool

  function createPool(
struct ProxyStruct.BindToken[] bindTokens,
contract IFactory finalize,
bool deadline
) external returns (address poolAddress)

Creates a pool with default parameters

Parameters:

NameTypeDescription
bindTokensstruct ProxyStruct.BindToken[]Array containing the information of the tokens to bind [tokenAddress, balance, weight, oracleAddress]
finalizecontract IFactoryBool to finalize the pool or not
deadlineboolMaximum deadline for accepting the creation of the pool

Return Values:

NameTypeDescription
poolAddressstruct ProxyStruct.BindToken[]The created pool's address

joinPoolVia0x

  function joinPoolVia0x(
address[] bindedTokens,
uint256[] maxAmountsIn,
struct ZeroExStruct.Quote[] fillQuotes,
address joiningAsset,
uint256 joiningAmount,
address pool,
uint256 poolAmountOut,
uint256 deadline
) external returns (uint256)

Joins the pool after externally trading an input token with the necessary tokens for the pool

The bindedTokens and maxAmountsIn should be in the same order of the output of pool.getTokens() when joining the pool using the native token, the wrapped address should be specified on 0x's API

Parameters:

NameTypeDescription
bindedTokensaddress[]The addresses of the binded tokens to the pool
maxAmountsInuint256[]The maximum amount of tokens that can be used to join the pool
fillQuotesstruct ZeroExStruct.Quote[]The trades needed before joining the pool (uses 0x's API)
joiningAssetaddressThe address of the input token
joiningAmountuint256The amount of the input token
pooladdressThe pool's address
poolAmountOutuint256The amount of pool shares expected to be received
deadlineuint256Maximum deadline for accepting the joinswapExternAmountIn

Return Values:

NameTypeDescription
poolAmountOutaddress[]The amount of pool shares received

externalSwap

  function externalSwap(
contract IERC20 tokenIn,
uint256 amountIn,
contract IERC20 tokenOut,
uint256 amountOut,
address spender,
enum Proxy.Aggregator swapCallData
) external

Performs a swap using 0x, paraswap or 1inch's sdk

Parameters:

NameTypeDescription
tokenIncontract IERC20The address of tokenIn
amountInuint256The maximum amount of tokenIn
tokenOutcontract IERC20The address of tokenOut
amountOutuint256The minimum expected amount of tokenOut
spenderaddressThe SC's address that will spender the input token
swapCallDataenum Proxy.AggregatorThe swap call data

joinPool

  function joinPool(
address pool,
uint256 poolAmountOut,
uint256[] maxAmountsIn,
uint256 deadline
) external

Join a pool with a fixed poolAmountOut

Joining a pool could be done using the native token or its wrapped token, but not with both at the same time. In both cases, the wrapped token's address should be specified as an input (tokenIn).

Parameters:

NameTypeDescription
pooladdressPool's address
poolAmountOutuint256Pool tokens (shares) to be receives
maxAmountsInuint256[]Maximum amounts of each token
deadlineuint256Maximum deadline for accepting the joinPool

joinswapExternAmountIn

  function joinswapExternAmountIn(
address pool,
address tokenIn,
uint256 tokenAmountIn,
uint256 minPoolAmountOut,
uint256 deadline
) external returns (uint256 poolAmountOut)

Joins a pool with 1 tokenIn

When joining a with the native token, msg.value should be equal to tokenAmountIn

Parameters:

NameTypeDescription
pooladdressPool's address
tokenInaddressTokenIn's address
tokenAmountInuint256Amount of token In
minPoolAmountOutuint256Minimum pool tokens (shares) expected to receive
deadlineuint256Maximum deadline for accepting the joinswapExternAmountIn

Return Values:

NameTypeDescription
poolAmountOutaddressThe pool tokens received

pauseProxy

  function pauseProxy(
) external

Pause the proxy

Pause disables all of the proxy's functionalities

resumeProxy

  function resumeProxy(
) external

Resume the factory's pools

Unpausing re-enables all the proxy's functionalities

transferOwnership

  function transferOwnership(
address _to
) external

Allows an owner to begin transferring ownership to a new address, pending.

Parameters:

NameTypeDescription
_toaddressThe new pending owner's address

acceptOwnership

  function acceptOwnership(
) external

Allows an ownership transfer to be completed by the recipient.