TwapRelayer Upgrades: Multihop Support (coming soon)

Changes are not live yet, and no changes to TwapRelayer integration should be made until further notice.

The upcoming TwapRelayer upgrade adds support for trades between tokensalong whitelisted paths that involve one or more pairs. For example, usdc-wbtc is a new path that has been whitelisted in the system that allows trades between usdc and wbtc (bidirectionally) via the existing weth-usdc and weth-wbtc pairs.

As a result of this upgrade, aggregators and solvers who have integrated the TwapRelayer using the following events or functions, please make the recommended changes below. No changes needed if the current integration does not directly use any of the following events or functions.

  • function isPairEnabled

  • event TokenLimitMinSet

  • event TokenLimitMaxMultiplierSet

  • function tokenLimitMin

  • function tokenLimitMaxMultiplier

  • function getTokenLimitMin

  • function getTokenLimitMaxMultiplier

How to Upgrade

Common functions have been automatically updated to take advantage of paths without the need for developers to make any changes:

  • sell, buy, quoteBuy, quoteSell, getPoolState still take the parameters:tokenIn and tokenOut and now automatically route using paths under the hood when available.

If you rely on any of the events or functions below, please make the recommended changes. If your current integration does not directly use any of the following events or functions, you should not have to make any changes:

  • Replace calls to function isPairEnabled(bool pairAddress) returns (bool isEnabled) with function isPathEnabled(address tokenIn, address tokenOut) returns (bool isEnabled)

  • Replace event listeners event TokenLimitMinSet(address token, uint256 limit)and event TokenLimitMaxMultiplierSet(address token, uint256 limit)with event TokenLimitsSet(address token, uint256 min, uint256 max)

  • Replace calls to function tokenLimitMin(address token) returns (uint256),function tokenLimitMaxMultiplier(address token) returns (uint256), function getTokenLimitMin(address token) returns (uint256), and function getTokenLimitMaxMultiplier(address token) returns (uint256)with function getTokenLimits(address token) returns (uint256 min, uint256 max)

    • Note:

      • tokenLimitMin now applies to the input token amount

      • tokenLimitMax now applies to the input token amount

  • We will provide an updated list of tradable paths based on the network

    • Existing pairs will still be tradable and unchanged

    • New paths, which involve trading across multiple pairs atomically will be added

Summary

Adds Multihop Support

The TwapRelayer update adds support for trades between tokensalong whitelisted paths that involve one or more pairs. For example, usdc-wbtc is a new path that has been whitelisted in our system that allows trades between usdc and wbtc (bidirectionally) via the existing weth-usdc and weth-wbtc pairs.

  • The original set of tradable tokens has been expanded by the addition of new paths; original pairs are still tradable.

    • paths are composed of one or more pairs

    • all original pairs are still tradable via a path that only contains one pair

  • Functions for trading and quoting have not changed and are 100% backwards compatible.

  • Common functions have been automatically updated to take advantage of paths without the need for developers to make any changes:

    • sell, buy, quoteBuy, quoteSell, getPoolState still take the parameters:tokenIn and tokenOut and now automatically route using paths under the hood when available.

  • isPairEnabled is still available but is now deprecated in favor of isPathEnabled, which tells developers if any pathor any pair is available while the former only tells users if a pair is enabled.

Refactors Token Limits

In addition, token limits have been refactored to take on new meaning and use:

  • TokenLimitMin remains but now only applies to the input token, instead of the output token.

  • TokenLimitMaxMultiplier has been removed and replaced by TokenLimitMax, which checks the input token amount does not exceed a certain limit.

Smart Contract Changes

Removed from SCs or Deprecated

Deprecated:

  • mapping(address => bool) public override isPairEnabled;

Removed:

  • event TokenLimitMinSet(address token, uint256 limit);

  • event TokenLimitMaxMultiplierSet(address token, uint256 limit);

  • function tokenLimitMin(address token) external pure returns (uint256);

  • function tokenLimitMaxMultiplier(address token) external pure returns (uint256);

  • function getTokenLimitMin(address token) external pure returns (uint256);

  • function getTokenLimitMaxMultiplier(address token) external pure returns (uint256);

Moved:

These events have been refactored to the RelayerMacros library but will still be emitted from TwapRelayer, so no developer changes should need to be made

  • event EthTransferGasCostSet(uint256 gasCost);

  • event TwapIntervalSet(address pair, uint32 interval);

  • event ToleranceSet(address pair, uint16 tolerance);

Added to SCs

  • event TokenLimitsSet(address token, uint256 min, uint256 max);

  • function getTokenLimits(address token) external pure returns (uint256 min, uint256 max);

  • function isPathEnabled(address tokenIn, address tokenOut) external view returns (bool);

Last updated