Dex
// This is a duplicate of features/dex.md. Please keep only one copy in the future.
DEX Integration
JuliaOS provides functionality for interacting with Decentralized Exchanges (DEXes) to enable automated trading strategies for agents and swarms.
Concept
DEXes allow users to trade cryptocurrency assets directly on the blockchain without relying on a centralized intermediary. They typically use Automated Market Maker (AMM) models based on liquidity pools.
Functionality in JuliaOS (DEX.jl
)
DEX.jl
)The core DEX logic resides in the Julia backend module /julia/src/DEX.jl
. Its main capabilities include:
Listing Supported DEXes: Identifying which DEXes are configured for specific chains (e.g., Uniswap V3 on Ethereum, Raydium on Solana).
Getting Swap Quotes: Calculating the expected output amount for a potential swap, considering available liquidity and fees. This is partially implemented for Uniswap V3 (using on-chain calls) but mocked for others like 1inch and Jupiter (which would require API integration).
Encoding Swap Data: Generating the correct
calldata
needed to execute a swap transaction on a specific DEX contract (partially implemented for Uniswap V3exactInputSingle
).Preparing Unsigned Transactions: Combining the quote, encoded data, nonce, gas estimates, etc., into a complete, unsigned transaction object. This is the primary output of the
execute_swap
function.
Important: The DEX.jl
module prepares swap transactions but does not sign or send them. Signing is handled client-side (see Wallets and Architecture Overview).
Supported DEXes
Configuration exists for DEXes including:
EVM: Uniswap V3, Sushiswap, Curve, Balancer, 1inch, PancakeSwap, QuickSwap, Trader Joe, SpookySwap, etc.
Solana: Raydium, Orca, Saber, Jupiter (aggregator).
(Note: While configured, quote and execution logic might only be fully implemented for a subset, like Uniswap V3).
Using DEX Features
Direct interaction with DEX.jl
is usually done internally via the Bridge.jl
module.
Agents/Swarms: Trigger trades based on their logic.
Bridge (
execute_trade
): CallsDEX.execute_swap
to get the unsigned transaction.Client (JS/Python/CLI): Receives the unsigned transaction, gets user signature via WalletManager/Wallet, and sends the signed transaction back via
Bridge.submit_signed_transaction
.
See:
Swap Execution Flow in DEX API
Bridge API (Backend)