Documentation Index
Fetch the complete documentation index at: https://tech.ramses.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Introduction
This guide will cover how to get the current quotes for any token pair on Ramses. The examples use the@kingdomdotone/v3-sdk package, Ramses’ fork of the Uniswap V3 SDK.
If you need a briefer on the SDK and to learn more about how these guides connect to the examples repository, please visit our background page!
quoteExactInputSingle to get a quote for the pair USDC - WETH.
The inputs are the token in, the token out, the amount in and the fee.
The fee input parameter represents the swap fee that is distributed to all in-range liquidity at the time of the swap. It is one of the identifiers of a Pool, along with tokenIn and tokenOut.
The guide will cover:
- Computing the Pool’s deployment address
- Referencing the Pool contract and fetching metadata
- Referencing the Quoter contract and getting a quote
quote.ts.
Example configuration
We will use the example configurationCurrentConfig in most code snippets of this guide. It has the format:
CurrentConfig object.
To connect to mainnet directly, set the mainnet field in the config:
constants.ts.
You can also change these two tokens and the fee of the pool in the config, just make sure a Pool actually exists for your configuration on Ramses.
Computing the Pool’s deployment address
To interact with the USDC - WETH Pool contract, we first need to compute its deployment address. If you haven’t worked directly with smart contracts yet, check out this guide from Alchemy. The SDK provides a utility method for that:constants.ts file:
config.ts file, as mentioned in the Introduction.
We can find the Pool Factory Contract address for our chain here.
Referencing the Pool contract and fetching metadata
Now that we have the deployment address of the USDC - ETH Pool, we can construct an instance of an ethersContract to interact with it:
Promise call. This approach queries state data concurrently, rather than sequentially, to minimize the chance of fetching out of sync data that may be returned if sequential queries are executed over the span of two blocks:
token0 and token1 variables are the addresses of the tokens in the Pool and should not be mistaken for Token objects from the sdk.
For the full code, check out the getPoolConstants() function in quote.ts.
In this example, the metadata we fetch is already present in our inputs. This guide fetches this information first in order to show how to fetch any metadata, which will be expanded on in future guides.
Referencing the Quoter contract and getting a quote
To get quotes for trades, Ramses has deployed a Quoter Contract. We will use this contract to fetch the output amount we can expect for our trade, without actually executing the trade. Like we did for the Pool contract, we need to construct an instance of an ethersContract for our Quoter contract in order to interact with it:
view functions, which would make them very easy to query on-chain with minimal gas costs. However, the Quoter contracts rely on state-changing calls designed to be reverted to return the desired data. This means calling the quoter will be very expensive and should not be called on-chain.
To get around this difficulty, we can use the callStatic method provided by the ethers.js Contract instances.
This is a useful method that submits a state-changing transaction to an Ethereum node, but asks the node to simulate the state change, rather than to execute it. Our script can then return the result of the simulated state change:
fromReadableAmount() function creates the amount of the smallest unit of a token from the full unit amount and the decimals.
The result of the call is the number of output tokens you’d receive for the quoted swap.
It should be noted that quoteExactInputSingle is only 1 of 4 different methods that the quoter offers:
quoteExactInputSingle- given the amount you want to swap, produces a quote for the amount out for a swap of a single poolquoteExactInput- given the amount you want to swap, produces a quote for the amount out for a swap over multiple poolsquoteExactOutputSingle- given the amount you want to get out, produces a quote for the amount in for a swap over a single poolquoteExactOutput- given the amount you want to get out, produces a quote for the amount in for a swap over multiple pools
quoteExactInput and quoteExactOutput methods come in.
We will dive deeper into routing in the routing guide.
For the exactOutput and exactOutputSingle methods, we need to keep in mind that a pool can not give us more than the amount of Tokens it holds.
If we try to get a quote on an output of 100 WETH from a Pool that only holds 50 WETH, the function call will fail.
Referencing the QuoterV2 contract and getting a quote
- AmountOut: The tokens or cryptocurrency received in the swap transaction.
- Gas Estimate: Estimated amount of gas required for executing the transaction.
- InitializedTicksCrossed: Indicates whether liquidity has crossed certain price thresholds within a liquidity range.
- SqrtPriceX96After: Square root of the price after the transaction, essential for determining pricing accuracy.
