Vault Smart Contract: API Reference
This document provides a detailed breakdown of all public functions available in the Vault smart contract. Functions are grouped by their purpose: Configuration, Asset Management, Token Approvals, and Swap Operations.Configuration & Role Management
Configuration & Role Management
These functions are used to set up and manage the administrative settings of the vault.
| Function | Description | Authorization |
|---|---|---|
__constructor(owner, router) | Initializes the vault with an owner and an immutable router address. The router cannot be changed after deployment. | Deploy transaction |
get_owner() | Returns the vault owner’s address. | Public |
change_owner(current_owner, new_owner) | Transfers vault ownership. Requires the current owner to authorize. | Owner (current_owner) |
set_trader(owner, trader) | Sets the authorized trader address. | Owner |
get_trader() | Returns the current trader’s address, if set. | Public |
remove_trader(owner) | Removes the authorized trader. | Owner |
get_router() | Returns the immutable router address. | Public |
Asset Management
Asset Management
These functions handle the movement of tokens into and out of the vault.
| Function | Description | Authorization |
|---|---|---|
deposit(depositor, token, amount) | Deposits a specified amount of a token into the vault. | Depositor |
withdraw(owner, token, to, amount) | Withdraws a specified amount of a token from the vault. Validates sufficient balance. | Owner |
total_balance(token) | Returns the vault’s current balance for a specific token. | Public |
Token Approvals
Token Approvals
These functions manage token spending approvals for the router.
| Function | Description | Authorization |
|---|---|---|
approve_for_swap(invoker_trader, token, spender, amount, expiration_ledger) | Approves the router to spend vault tokens for a swap. The spender must match the configured router. Expiration is typically ~300 ledgers (~5 minutes). | Trader (invoker_trader) |
The
approve_for_swap function enforces that only the immutable router can be approved as a spender, preventing token approval to arbitrary addresses.Swap Operations
Swap Operations
These functions are used to execute trades through the configured router contract.
| Function | Description | Authorization |
|---|---|---|
handle_swap_exact_in(...) | Swaps a fixed input amount for a minimum output amount. | Owner or Trader |
multi_swap_exact_in(...) | Swaps a fixed input amount along a multi-token path (max 5 hops). | Owner or Trader |
handle_swap_exact_out(...) | Swaps a maximum input amount for a fixed output amount. | Owner or Trader |
multi_swap_exact_out(...) | Swaps a maximum input amount for a fixed output amount along a multi-token path (max 5 hops). | Owner or Trader |
Keeper Execution
Keeper Execution
This function enables automated order execution by the OrderManager contract.
| Function | Description | Authorization |
|---|---|---|
execute_keeper_swap(order_manager, token_in, token_out, amount_in, amount_out_min, deadline) | Executes a swap on behalf of the OrderManager for keeper-driven order execution. Pre-authorizes token transfer via authorize_as_current_contract(). Returns the output amount. | OrderManager contract (must be configured as trader) |
The
execute_keeper_swap function requires that the calling order_manager address matches the vault’s configured trader. It also enforces a positive amount_out_min to prevent slippage bypass attacks.
