CronV1Actions

ASSET_IN

uint256 ASSET_IN

ASSET_OUT

uint256 ASSET_OUT

FIVE_MIN_IN_SEC

uint256 FIVE_MIN_IN_SEC

ZERO_PCT_BP

uint256 ZERO_PCT_BP

TEN_PCT_BP

uint256 TEN_PCT_BP

MAX_BP

uint256 MAX_BP

Cron-Fi specific periphery relayer functionality for performing Time Weighted Average Market Maker (TWAMM) pool actions on a pool with some safety and convenience checks.

The periphery relayer is composed of two contracts: - CronV1Relayer contract, which acts as the point of entry into the system through convenience functions and a multicall function. - This library contract that defines the behaviors and checks allowed by the periphery relayer.

There are unchecked operations (this code targets Solidity 0.7.x which didn't yet feature implicit arithmetic checks or have the 'unchecked' block feature) herein for reasons of efficiency or desired overflow. Wherever they appear they will be documented and accompanied with one of the following tags: - #unchecked - #overUnderFlowIntended

NOTE: Only the entrypoint contract should be allowlisted by Balancer governance as a relayer, so that the Vault will reject calls from outside the entrypoint context.

WARNING: This contract should neither be allowlisted as a relayer, nor called directly by the user. No guarantees can be made about fund safety when calling this contract in an improper manner._

constructor

constructor(contract IVault _vault, contract ICronV1PoolFactory _factory) public

Creates an instance of the library contract and periphery relayer contract for convenient interactions with Cron-Fi TWAMM pools. The periphery relayer contract is created by this constructor and should not be separately be created.

Parameters

swap

function swap(address _tokenIn, uint256 _amountIn, address _tokenOut, uint256 _minTokenOut, uint256 _poolType, address _caller, address _recipient) external returns (uint256 amountOut)

see swap documentation in ICronV1Relayer.sol, except noted differences below:

Parameters

join

function join(address _tokenA, address _tokenB, uint256 _poolType, uint256 _liquidityA, uint256 _liquidityB, uint256 _minLiquidityA, uint256 _minAmountOutB, address _caller, address _recipient) external

see join documentation in ICronV1Relayer.sol, except noted differences below:

Parameters

exit

function exit(address _tokenA, address _tokenB, uint256 _poolType, uint256 _numLPTokens, uint256 _minAmountOutA, uint256 _minAmountOutB, address _caller, address _recipient) external

see exit documentation in ICronV1Relayer.sol, except noted differences below:

Parameters

longTermSwap

function longTermSwap(address _tokenIn, address _tokenOut, uint256 _poolType, uint256 _amountIn, uint256 _intervals, address _owner, address _delegate) external

see longTermSwap documentation in ICronV1Relayer.sol, except noted differences below:

Parameters

withdraw

function withdraw(address _tokenA, address _tokenB, uint256 _poolType, uint256 _orderId, address _caller, address _recipient) external

see withdraw documentation in ICronV1Relayer.sol, except noted differences below:

Parameters

cancel

function cancel(address _tokenA, address _tokenB, uint256 _poolType, uint256 _orderId, address _caller, address _recipient) external

cancel see documentation in ICronV1Relayer.sol, except noted differences below:

Parameters

getVault

function getVault() public view returns (contract IVault)

Gets the Balancer Vault instance this periphery relayer library is servicing.

Return Values

getEntrypoint

function getEntrypoint() public view returns (contract ICronV1Relayer)

Gets the periphery relayer contract instantiated by this library, that serves as the user relayer entrypoint to Cron-Fi Time-Weighted Average Market Maker (TWAMM) pools.

Return Values

getFactory

function getFactory() public view returns (contract ICronV1PoolFactory)

Gets the Cron-Fi Time-Weighted Average Market Maker (TWAMM) factory contract instance used by this periphery relayer library to select Cron-Fi TWAMM pools.

Return Values

_getPoolInfoAndCheckValid

function _getPoolInfoAndCheckValid(address _tokenIn, address _tokenOut, uint256 _poolType) internal view returns (address pool, bytes32 poolId)

Gets the Balancer pool address and pool id for the provided token addresses and pool type, if available. Reverts if the pool is not available with the reason why if possible.

Parameters

Return Values

_checkAmountIn

function _checkAmountIn(uint256 _amountIn, address _tokenIn, address _account) internal view

Checks the amount of token being sold by the user to the pool is within acceptable bounds, reverts otherwise. Also confirms that the user has sufficient amount of that token available in their account, reverts otherwise.

Parameters

_getPoolAssetsAndCheckBalances

function _getPoolAssetsAndCheckBalances(bytes32 _poolId, address _tokenIn) internal view returns (contract IAsset[] assetInOut)

Gets the tokens and balances for the pool specified by the pool id. Checks to ensure the balances are greater than the MINIMUM_LIQUIDITY constraint (reverts otherwise). Converts the token instances fetched from the pool into a sorted array of Asset instances; the sort order is that Asset instance 0 (the first instance) corresponds to the address specified for token in. Asset instance 1 (the second instance) corresponds to the address specified for token out (there's only two assets in all these pools).

    For convenience and clarity, the array of Asset instances should be indexed with the
    provided constants ASSET_IN (0) and ASSET_OUT (1).

Parameters

Return Values

_getEffectiveAmountInAndCheckIntervals

function _getEffectiveAmountInAndCheckIntervals(uint256 _amountIn, uint256 _orderIntervals, enum ICronV1PoolEnums.PoolType _poolType) internal view returns (uint256 effectiveAmountIn)

This method computes the effective amount of an order that the pool can process for a long-term swap verses a user specified amount. The difference between the two values results from a truncation error due to division of the user specified amount by the trade length. Losses due to this truncation are multiplied by the trade length.

Parameters

Return Values

_getDeadline

function _getDeadline() internal view returns (uint256 deadline)

Gets a deadline timestamp--a timestamp in the future used to cue the Balancer Vault to ignore a transaction that has sat in the mempool for an excessive amount of time.

Return Values

_getPoolAssets

function _getPoolAssets(bytes32 _poolId) internal view returns (contract IAsset[] assets)

Gets the pool's Asset instances in Balancer token sort order given the Balancer pool id.

Parameters

Return Values

_convertERC20sToAssets

function _convertERC20sToAssets(contract IERC20[] _tokens) internal pure returns (contract IAsset[] assets)

Converts an array of ERC20 instances to Asset instances.

Parameters

Return Values

Last updated