Skip to content

Exact input and exact output

Pass exactly one of amount_in or amount_out. Both are raw integers in the token’s smallest unit (use the token’s decimals from ft_metadata).

“I pay exactly this much, how much do I get?” This is the most common mode, and every DEX supports it.

amount_in=1000000000000000000000000

Quotes come back with output amounts:

"estimated_amount": { "amount_out": "4880007" },
"worst_case_amount": { "amount_out": "4831206" }

worst_case_amount is the minimum output the transactions accept. If the pools move so that the output would be lower, the swap fails and the input is refunded.

“I want to receive exactly this much, how much do I pay?”

amount_out=1000000

Quotes come back with input amounts:

"estimated_amount": { "amount_in": "205495745391126196067546" },
"worst_case_amount": { "amount_in": "210222147535122098577099" }

worst_case_amount is the most the trader can pay. The transactions send up to this much and return whatever isn’t used, so the trader needs to hold the worst-case amount, not just the estimate.

Not every DEX supports exact output:

DEX Exact output
Rhea ❌ No
Rhea DCL ✅ Yes
Plach, Aidols, Wrap, Meta Pool, LiNEAR, rNEAR, xRHEA ✅ Yes

DEXs that don’t support it just don’t return a quote, so you may get fewer quotes than with amount_in.