How to use clipper RFQ API?

Clipper's Formula Market Maker (FMM) is implemented similar to a typical Request For Quotes (RFQ) system. In an RFQ architecture, you first ask our offchain server to quote a transaction price, specifying the buy and sell tokens and either a target input or output amount. You then have a short amount of time to accept that quote, and receive back a signed certificate from our offchain server. Then, you must pass that transaction and signed certificate to our onchain smart contracts to execute the swap.

Clipper supports a “send, then swap" modality and is designed to be as simple as possible to chain within a larger set of transactions, or to automate trading with bots.

You can see the supported networks here

  1. Get exchange address and asset information.

const fetch = require('node-fetch');

const chainId = 137;  // You can use a different network. Look for our supported networks
const fieldset = 'offchain-data';
const authorizationHeader = 'Basic YXBpLXVzZXI6dXNlci1wYXNz';  // This is a placeholder 

const requestOptions = {
  method: 'GET',
  headers: {
    'Authorization': authorizationHeader,
    'Content-Type': 'application/json'
  }
};

const response = await fetch(`https://api.clipper.exchange/rfq/pool?chain_id=${chainId}&fieldset=${fieldset}`, requestOptions);
const data = await response.json();
console.log(data);

The API response will look like the following (some fields omitted):

💡 You can include the query param time_in_seconds to the GET call if you intend to get quotes for values other than the default_time_in_seconds for a chain. As you lower the time you will see lower fees (and therefore better prices).

💡 To obtain more details about the endpoint, its parameters, and the response, please refer to the API Reference in the pool section.

  1. Request a quote

The API response will look like the following (some fields omitted):

💡 To obtain more details about the endpoint, its parameters, and the response, please refer to the API Reference in the quote section.

  1. Sign the quote

The API response will look like the following:

If you want to get the bytes representation of the swap to be sent directly to the pool contract you can review our calldata swap feature

💡 To obtain more details about the endpoint, its parameters, and the response, please refer to the API Reference in the sign section

  1. Send the transaction

Using ether.js

💡 You can review the guide Interacting with the Clipper Exchange to know more ways of interact with Clipper. You can also review code examples in the section Integration Examples

You can find a complete swap flow example here

Last updated

Was this helpful?