Wardenswap first swap
Updated on
WardenSwap is a decentralized exchange aggregator. When a source token requires a spending allowance, approval sets how much the WardenSwap contract may spend. A separate swap instruction specifies the input amount and the minimum destination-token amount to accept.
- Documented approval default
-
In
WardenBestRate.approve, omittingallowedAmountselectsethers.constants.MaxUint256. This default belongs to the documented SDK method; inspect the amount that a particular wallet request actually asks you to authorize. - Destination wallet
-
In
WardenBestRate.swap, the optionalreceiveridentifies the wallet that receives the destination token. When omitted, it defaults to the transaction sender.
What does a token approval authorize?
The SDK’s
approve
method identifies the source token through
src
and sets its spending allowance through
allowedAmount
. The permission concerns that token and spender contract for the authorizing wallet on the selected network.
MaxUint256
is the maximum unsigned 256-bit integer, so the documented default permits a very large token allowance. It isn’t automatically limited to the amount of an individual swap. An SDK integration can instead pass an explicit
allowedAmount
; check the actual authorization amount before signing.
A token approval changes spending permission. It doesn’t itself carry out the quoted exchange or establish that destination tokens have arrived.
What should the swap specify?
The documented
getQuote
method returns route information for the requested source asset, destination asset, and input amount. The separate
swap
method accepts that
quoteResult
alongside the trade’s token addresses and amounts.
amountIn
specifies the quantity of the source token to exchange.
minDestAmount
specifies the minimum quantity of the destination token. These parameters refer to different assets, and the output minimum is an amount, not a percentage. Approval doesn’t set this minimum.
The receiving address is another part of the swap instruction. Where an integration supplies
receiver
, review that address; where it omits the parameter, the documented method uses the transaction sender. The spender authorized by an approval and the wallet receiving the output have different roles.
Does a returned transaction establish completion?
The
WardenBestRate
reference marks both
approve
and
swap
as returning a
ContractTransaction
without waiting for confirmation. That response alone doesn’t establish on-chain success.
If a token swap depends on a new allowance, that approval must take effect before the dependent swap executes. Check the swap’s own on-chain outcome and destination-token transfers before treating the exchange as completed.
What should you check before signing?
- If an approval is requested, verify its network, source token, spender contract, and allowance amount. Stop if you can’t establish what you’re authorizing.
- If a swap needs a new allowance, confirm that the approval succeeded on-chain before submitting the dependent swap.
- Before authorizing the swap, check its source amount, minimum destination amount, and receiving wallet. Stop if any differs from your intended trade.