Quoting
Quotes are read-only simulations from the v2 backend. They accept symbols or
class keys, and an omitted fee compares all available pools (0, 500,
3000, and 10000).
The examples on this page continue from the gSwap client built in
Getting started: reads need no signer, writes need a signer (and liquidity
confirmations a walletAddress), and the code runs in an ES module (top-level await).
const quote = await gSwap.quoting.quoteExactInput('GALA', 'GUSDC', '100');
console.log(`Tier: ${quote.feeTier}`);
console.log(`Input: ${quote.amountIn}`);
console.log(`Output: ${quote.amountOut}`);
console.log(`Fees to liquidity providers: ${quote.tradingFees}`); // the protocol's share is quote.protocolFees
console.log(`Total fees: ${quote.totalFees}`);
Use exact output when the received amount is fixed:
const quote = await gSwap.quoting.quoteExactOutput('GALA', 'GUSDC', '50', 3000);
console.log(`Quoted input: ${quote.amountIn} GALA for 50 GUSDC`); // a bound on the write comes from this, plus a tolerance
The quote includes the selected fee, canonical token0Symbol and
token1Symbol, current and post-trade square-root prices, and the protocol,
trading, and total fee amounts. The square-root prices are present when the backend
sends them; check for undefined before using them. It also reports tokenInIsToken0, which is
useful when building a lower-level RequestTrade DTO. Prices can change between a
quote and a write, so always set a slippage bound on the write and refresh
large or delayed quotes.
import BigNumber from 'bignumber.js'; // a dependency of the SDK; install it in your own app too
const quote = await gSwap.quoting.quoteExactInput('GALA', 'GUSDC', '100');
const tx = await gSwap.swaps.swap('GALA', 'GUSDC', quote.feeTier, {
exactIn: '100',
amountOutMinimum: new BigNumber(quote.amountOut).multipliedBy('0.99').toFixed(), // accept 1% less than quoted
});
An exact-input trade uses amountOutMinimum; an exact-output trade uses
amountInMaximum. Each is the limit you accept, not the quote itself: a swap is applied a few
seconds after the quote, and a bound equal to the quote is rejected whenever the price moves in
between. Both values are optional, but omitting them removes
slippage protection. A missing pool or insufficient liquidity is reported as
an SDK error.
wallet address token0 symbol token1 token in is amount out minimum maximum