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.
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 Authorization section to know details.
constfetch=require('node-fetch');constchainId=137; // You can use a different network. Look for our supported networksconstfieldset='offchain-data';constauthorizationHeader='Basic YXBpLXVzZXI6dXNlci1wYXNz'; // This is a placeholder constrequestOptions= { 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);
constdata=awaitresponse.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.
You should estimate clipper prices using the offchain state information for better performance. Review the section Estimate Clipper Prices to know more about it.
Request a quote
constfetch=require('node-fetch');constparams= { 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.
};constauthorizationHeader='Basic YXBpLXVzZXI6dXNlci1wYXNz'; // This is a placeholder constrequestOptions= { method:'POST', headers: {'Authorization': authorizationHeader,'Content-Type':'application/json' }, body:JSON.stringify(params)};constresponse=awaitfetch('https://api.clipper.exchange/rfq/quote', requestOptions);constdata=awaitresponse.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.
💡 To obtain more details about the endpoint, its parameters, and the response, please refer to the API Reference in the quote section.
Sign the quote
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 Discord for access (MNDA required).
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.
constfetch=require('node-fetch');constparams= { 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
};constauthorizationHeader='Basic YXBpLXVzZXI6dXNlci1wYXNz'; // This is a placeholderconstrequestOptions= { method:'POST', headers: {'Authorization': authorizationHeader,'Content-Type':'application/json' }, body:JSON.stringify(params)};constresponse=awaitfetch('https://api.clipper.exchange/rfq/sign', requestOptions);constdata=awaitresponse.json();console.log(data);