Jump to content
Onchain Report

Crypto news from every chain

Token custody during a routed DEX swap

Who holds your crypto during a DEX swap? Your tokens stay in your wallet before and after; smart contracts move them through the route in one transaction.

Onchain Report Newsroom#ed1e563 min read

Token custody during a routed DEX swap

During a decentralized exchange swap, your tokens stay in your wallet before and after the trade; smart contracts move them through the chosen liquidity sources while the swap runs. The aggregator finds a route, but it does not hold your tokens in an exchange account.

A wallet connection lets a DEX read information needed to prepare a trade; it does not deposit your tokens. KyberSwap Aggregator is a useful example of what non-custodial custody changes: its route-finding feature selects liquidity sources while your wallet remains the source of the tokens.

Approval lets a contract spend tokens

For many tokens, including ERC-20 tokens, a smart contract needs an allowance before it can transfer tokens from your wallet. An allowance is permission to spend up to a set amount. Giving approval is a separate transaction, and that transaction grants permission without moving the tokens.

The approval is for a selected contract, and the exact contract depends on the swap route. Read the wallet prompt to see what you are approving and which allowance it requests. Connecting your wallet alone does not grant this spending permission.

The route moves tokens during the swap

When you confirm a same-chain swap, your wallet signs a transaction. The route’s contracts use the approved allowance to transfer the input tokens through the selected liquidity pools or other liquidity sources. The contracts then send the output tokens to your wallet address.

Say you want to swap one token for another and KyberSwap Aggregator finds a route through more than one liquidity source. The route determines which contracts handle the tokens as they pass through. You do not need to send the tokens to an aggregator account first; the transaction executes the route on-chain.

The routed transfers happen as one transaction. If execution reverts, the token exchange is rolled back, so the swap’s transfers do not remain in place. Gas already used to attempt the transaction is still charged.

After a successful swap, the output tokens are at your wallet address. The contracts handled them during execution, but your wallet is where the result arrives.

Related

Do you have to deposit tokens to use a DEX?

No. For a same-chain swap, tokens stay at your wallet address until the swap transaction uses them. You approve spending when the token requires it, then confirm the transaction.

Can a DEX spend tokens after you disconnect your wallet?

Disconnecting stops the site from using its active wallet connection, but it does not erase an allowance already granted on-chain. A contract can use an allowance when a transaction calls it. Review the allowance in your wallet or a trusted token allowance tool if you want to revoke it.

Before swapping, check the contract and allowance in the approval prompt. Afterward, confirm the output token has arrived at your wallet address.