Skip to content

Swapping

It is your responsibility to find the best list of pools for executing a trade. This is equivalent to finding the best route for arbitrage. The easiest way to get a route is the Quoter API, which returns block-pinned split routes ready to execute.

Every interaction that moves tokens starts with ICore#lock (see the “till” pattern). Core then calls back into your contract: on Starknet via ILocker#locked(id, data), and on EVM via the zero function selector 0x00000000, which the reference implementations expose as locked_6416899205(uint256) — the numeric suffix is mined so that the selector is zero. Inside the callback you execute the swap(s), pay the input, and withdraw the output tokens, in any order. You typically call swap several times in a single locked callback so that you only settle the net differences.

Production swaps go through the Yul Router — a gas-optimized router deployed deterministically at the same address on each chain it has been released to, with routes encoded by @ekubo/yul-router-sdk. Release v0.8.0 is deployed on all 13 mainnets in the EVM supported chains table and on 13 testnets; the release manifest lists each of the 26 networks. See the Yul Router guide for the calldata model, hop types, and SDK usage.

To execute swaps from your own contract, see the reference Router implementations on Starknet and EVM. On EVM, a contract that already holds a Core lock can also run a Yul Router route through Core.forward and settle the net result itself; see forwarded mode.