Ethereum: Solidity
Swap/Exchange Protocol Guide
Implementing the Protocol
To integrate an EVM exchange protocol:
Implement the
ISwapAdapter.sol
interface.Create a manifest file summarizing the protocol's metadata.
The Manifest File
The manifest file contains author information and additional static details about the protocol and its testing. Here's a list of all valid keys:
Key Functions
Price (optional)
Calculates pool prices for specified amounts.
Return prices in buyToken/sellToken units.
Include all protocol fees (use minimum fee for dynamic fees).
Implement this method as
view
for efficiency and parallel execution.If you don't implement this function, flag it accordingly in capabilities and make it revert using the
NotImplemented
error.While optional, we highly recommend implementing this function. If unavailable, we'll numerically estimate the price function from the swap function.
Swap
Simulates token swapping on a given pool.
Execute the swap and change the VM state accordingly.
Include a gas usage estimate for each amount (use
gasleft()
function).Return a
Trade
struct with aprice
attribute containingprice(specifiedAmount)
.If the price function isn't supported, return
Fraction(0, 1)
for the price (we'll estimate it numerically).
GetLimits
Retrieves token trading limits.
Return the maximum tradeable amount for each token.
The limit is reached when the change in received amounts is zero or close to zero.
Overestimate the limit if in doubt.
Ensure the swap function doesn't error with
LimitExceeded
for amounts below the limit.
getCapabilities
Retrieves pool capabilities.
getTokens (optional)
Retrieves tokens for a given pool.
We mainly use this for testing, as it's redundant with the required substreams implementation.
getPoolIds (optional)
Retrieves a range of pool IDs.
We mainly use this for testing. It's okay not to return all available pools here.
This function helps us test against the substreams implementation.
If you implement it, it saves us time writing custom tests.
Last updated