Swaps
Swaps are exchange operations between two tokens. The platform uses an Automated Market Maker (AMM) system to facilitate these trades in a decentralized manner.
How it works on the Trade screen?
On the Trade page (/trade), the user selects two tokens: one they own (Token A) and another they wish to receive (Token B).
Swap Route Types
The intelligent system (smart-functions/swap.js) automatically determines the best route for the exchange:
-
Direct Swap:
- Occurs when there is a direct liquidity pool between Token A and Token B.
- Example: Swap from KLV to USDT (if the KLV/USDT pair exists).
- Execution: Calls the
swapTokensFixedInputfunction on the pair contract.
-
Composite Swap:
- Occurs when there is no direct pair, but both have parity with a common token (usually KLV).
- Example: Swap from Token A to Token B (no direct pair).
- Route: Token A -> KLV -> Token B.
- Execution: The system executes a
multiPairSwap, internally performing two swaps in a single atomic transaction. First, it swaps A for KLV, and then uses those KLV to buy B.
Adding Liquidity vs. Swap
It is important not to confuse Adding Liquidity with Making a Swap:
- Swap: You sell a token to buy another. The balance of one decreases and the other increases. The token price is affected by supply and demand in the pool.
- Adding Liquidity: You deposit both tokens (the pair) into the pool. You are not selling, you are providing funds so that others can trade. In DeFi, you receive LP tokens representing your share of the pool and earn fees on transactions.