Skip to main content

Trading Operations: Executing Swaps

The Renesis Vault is designed to perform trades by interacting with an external swap router contract (Soroswap). All swap functions are permissioned and can only be called by the Owner or the authorized Trader.

Router Integration

The vault itself does not contain liquidity; instead, it acts as a secure wrapper that interacts with a dedicated router for all trades.
The vault holds the address of a trusted Router contract, set immutably at deployment. All swap operations are routed through this contract, which is responsible for finding liquidity pools and executing the trade. The router address cannot be changed after construction, preventing router replacement attacks.

Supported Swap Operations

The contract supports a variety of swap types to accommodate different trading strategies.

Exact Input Swaps

Function: handle_swap_exact_inYou specify the exact amount of the input token you want to sell, and the contract swaps it for a minimum acceptable amount of the output token.

Exact Output Swaps

Function: handle_swap_exact_outYou specify the exact amount of the output token you want to receive, and the contract swaps the required input amount to achieve it, respecting a maximum spend limit.

Multi-Hop Swaps

Functions: multi_swap_exact_in, multi_swap_exact_outFor complex trades between tokens without a direct liquidity pool, you can provide a custom token path (e.g., XLM → USDC → BTC). Maximum 5 hops per path, with validation against consecutive duplicate tokens.

Keeper Execution Path

In addition to manual swaps, the vault supports automated execution through the keeper system. The OrderManager contract (configured as the vault’s trader) can call execute_keeper_swap() to execute orders on behalf of users.
1

OrderManager Pre-Authorization

The OrderManager uses authorize_as_current_contract() to pre-authorize the vault call, allowing it to act as the vault’s trader without requiring a separate user signature.
2

Token Approval

The vault internally approves the router to spend tokens using approve_for_swap(). Approvals expire after approximately 300 ledgers (~5 minutes) to limit exposure.
3

Swap Execution

The vault routes the swap through Soroswap and returns the output amount back to the OrderManager for tracking.
Multi-hop swap paths are limited to a maximum of 5 hops to prevent gas exhaustion attacks. The contract validates that no consecutive tokens in the path are duplicates.

Next Steps

Monitoring: Events & Auditability

Discover how the vault emits on-chain events for transparency and tracking.