What it offers
- swap: Swap tokens via the CrocSwapDex contract with base/quote pair addressing
Notes
- Single contract holds ALL liquidity (similar to Balancer V2 Vault and Uniswap V4 PoolManager)
- The contract address differs on Ethereum and Scroll
poolIdxidentifies the pool type: different pool indices have different fee rates and tick spacing- Common pool indices:
420(standard on Ethereum),36000(stable pairs on Scroll) - Exact-input:
isBuy: true, inBaseQty: truespecifies base paid;isBuy: false, inBaseQty: falsespecifies quote paid - Exact-output:
isBuy: true, inBaseQty: falsespecifies quote received;isBuy: false, inBaseQty: truespecifies base received tip: Optional tip in basis points for priority execution (usually0)limitPrice: Price limit as sqrt price Q64.64 fixed-point (0is no limit, which leavesminOutas the only bound)reserveFlags: Bitmask for using surplus collateral (set to0for standard swaps)userCmdis the universal command interface for all non-swap operations (adding/removing liquidity, etc.)- callpath
1= liquidity operations,3= warm path operations - Gas-efficient for simple swaps; more complex for LP operations via
userCmd - Input token must be ERC20-approved to the CrocSwapDex contract
Its names in a program
On Ethereum,Ambient is a namespace: its contracts need no import.
Deployments
ABI
CrocSwapDexABI
import CrocSwapDexABI from "./protocols/ambient/CrocSwapDexABI.json"; Speaks for: crocSwapDex.
swap(address base, address quote, uint256 poolIdx, bool isBuy, bool inBaseQty, uint128 qty, uint16 tip, uint128 limitPrice, uint128 minOut, uint8 reserveFlags) payable returns (int128 baseFlow, int128 quoteFlow)userCmd(uint16 callpath, bytes cmd) payable returns (bytes result)
Next steps
- Protocols: the other protocols, by what they do.
- Protocols and tokens: calling a contract by its namespace, or through its ABI.
- Glossary: the words these pages use, in plain terms.
