chain_idset to the appropriate (integer) chain ID. The JSON response will include the pool's address and list of contract addresses on that chain. Example response:
num_assetswill be an integer value with the number of assets in the pool.
assetskey at the top level is a list of length
num_assetsdescribing the pool assets. The
addressof each asset are the most important fields.
https://api.clipper.exchange/rfq/quoteendpoint a JSON body with the following keys.
output_amountshould be specified, and that value should be a string.
time_in_secondsrefers to the amount of time between accepting a quote and receiving the quote on the blockchain. A good suggestion for Polygon is 30 seconds. As this value increases, the quote will get worse for the user.
output_asset_symbolshould correspond to the asset
namereturned from the
/rfq/poolcall above. Observe that "ETH" and "MATIC" are both assets, but that the 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.
must_accept_byis a human-readable UTC timestamp by which you must accept the quote and should be expected to be a short duration. If this time has passed already, request a new quote - the server will not sign a quote after
https://api.clipper.exchange/rfq/signendpoint with the following JSON body:
quote_idshould be set to the ID field of the quote requested above
destination_addresswill receive the output token.
externalfunctions for interacting with the Clipper exchange onchain, depending on your use case. In all of these functions,
Signatureis a struct defined by:
auxiliaryDatawhich can be set to any string and is used for identification purposes in the event logs.
transmitAndSwapstarts by transferring
msg.senderto the exchange, while
swapassumes that the appropriate amount of the input token has already been transmitted. Which function you should use depends on if and how you are connecting the Clipper swap to other operations.
inputTokenhas already been sent, while the second pulls that input token directly from
msg.sender. Observe further that:
outputTokenargument is not present (since it will be native currency)
Ethregardless of chain
msg.valueor by transferring that native currency to the exchange contract prior to the function call.
calldatain order to lower transactions costs. These functions are:
packedTransmitAndSwapto transmit the token from
packedSwapif tokens have already been transmitted.
uint256value. The packed format puts the address as the (first, lowest order) 160 bits (= 40 hex values = 20 bytes) and the amount as the (second, highest order) 96 bits (= 24 hex values = 12 bytes). To created a packed value, leftshift the integer amount by 160 bits and add it to the binary representation of the contract address. The three packed arguments into this function, and the values they encode, are:
packedInput: input amount and contract address
packedOutput: output amount and contract address
packedDestination: destination address and good until