ERC-7815: Swap Order Routing Interface

This ERC proposes a standardized interface for on-chain swap liquidity. It defines methods to calculate price, swap tokens, retrieve trading limits, and query capabilities of liquidity pools.

The standard simplifies access to defi liquidity sources – to improve composability and make routing (solving) easier.

ERC:

4 Likes

This interface doesn’t compile.

You need to decide if the Fraction limit in swapToPrice(...) is calldata or memory. IMO, calldata is preferable for a two-slot struct that is expected to be read-only.

Also, a slightly pedantic suggestion to use the precise mathematical term Rational instead of Fraction, since both the numerator and denominator are integers.

May I also suggest using a bit field instead of a dynamic array for the capabilities? Seems awkward and gassy for clients to iterate a list when a single bitmask would suffice.

Current example client code:

Capability[] private _capabilities;

function hasCapability(Capability c) internal view returns (bool) {
  for( uint256 i=0; i<_capabilities.length; i++ )
    if( _capabilities[i] == c )
      return true;
  return false;
}

Compare with bitfields:

uint256 private _capabilities;
uint256 constant public CAPABILITY_SELLORDER = 1<<0;
uint256 constant public CAPABILITY_BUYORDER = 1<<1;
uint256 constant public CAPABILITY_PRICEFUNCTION = 1<<2;
[...]

function hasCapability(uint256 c) internal view returns (bool) {
  return _capabilities & c != 0;
}