Clipper's Formula Market Maker (FMM) is implemented similar to a typical Request For Quotes (RFQ) system. In an , 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.
It's essential to obtain the credentials in order to proceed with the guide for API usage. Please reach out to us to acquire the necessary credentials for API access, please refer to the section to know details.
You can see the supported networks
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).
Request a quote
const fetch = require('node-fetch');
const params = {
output_asset_symbol: 'USDC',
input_asset_symbol: 'DAI',
chain_id: 137, // Should be set to the appropriate chain ID. Polygon is 137.
input_amount: '2000000000000000000', // XOR: output_amount: '2000000000000000000'
time_in_seconds: 30. // A good suggestion for Polygon is 30 seconds. As this value increases, the quote will get worse for the user.
};
const authorizationHeader = 'Basic YXBpLXVzZXI6dXNlci1wYXNz'; // This is a placeholder
const requestOptions = {
method: 'POST',
headers: {
'Authorization': authorizationHeader,
'Content-Type': 'application/json'
},
body: JSON.stringify(params)
};
const response = await fetch('https://api.clipper.exchange/rfq/quote', requestOptions);
const data = await response.json();
console.log(data);
input_asset_symbol and output_asset_symbol should correspond to the asset name returned from the /rfq/poolcall in the step 1.
The API response will look like the following (some fields omitted):
For assets like ETH and MATIC Clipper exchange uses the wrapped version of these assets, a distinction made clear and unambiguous by the inclusion of the contract addresses in the response.
Sign the quote
Our quotes are firm. If a signed order make it onchain by the good_until time it will generally be honored as explicitly written. Note that, on some chains, if other orders frontrun the signed quote it may be rejected - this is a security precaution to prevent sybil attacks.
const fetch = require('node-fetch');
const params = {
quote_id: "590d7956-c7cc-45da-83ed-23f6901f74e9", // id we get get in first step
destination_address: "0x5901920A7b8cb1Bba39220FAC138Ffb3800dD212", // it will receive the output token
sender_address: "0x5901920A7b8cb1Bba39220FAC138Ffb3800dD212". // Optional: it is for DEX aggregator partners that are using their own smart contract
};
const authorizationHeader = 'Basic YXBpLXVzZXI6dXNlci1wYXNz'; // This is a placeholder
const requestOptions = {
method: 'POST',
headers: {
'Authorization': authorizationHeader,
'Content-Type': 'application/json'
},
body: JSON.stringify(params)
};
const response = await fetch('https://api.clipper.exchange/rfq/sign', requestOptions);
const data = await response.json();
console.log(data);
import ethers from "ethers";
import exchangeAbi from "./exchangeAbi.json";
async function executeSwap(signResponse) {
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const exchangeContract = new ethers.Contract(
signResponse.clipper_exchange_address,
exchangeAbi,
provider
);
// Any 32 bytes identifier
const auxData = "0x00000000000000000000000000000000000000000000000000";
const result = await exchangeContract.swap(
signResponse.input_asset_address,
signResponse.output_asset_address,
signResponse.input_amount,
signResponse.outputAmount,
signRespose.good_until,
signResponse.destination_address,
[signResponse.signature.v, signResponse.signature.r, signResponse.signature.s],
auxData
)
💡 To obtain more details about the endpoint, its parameters, and the response, please refer to the API Reference in the section.
You should estimate clipper prices using the offchain state information for better performance. Review the section to know more about it.
💡 To obtain more details about the endpoint, its parameters, and the response, please refer to the API Reference in the section.
Only members of the Clipper Community and DEX aggregator partners can get their quotes signed. If you're building a DEX aggregator, please reach out to the team on for access (MNDA required).
If you want to get the bytes representation of the swap to be sent directly to the pool contract you can review our
💡 To obtain more details about the endpoint, its parameters, and the response, please refer to the API Reference in the section
💡 You can review the guide to know more ways of interact with Clipper. You can also review code examples in the section