contracts/adapters/soroswap/src/protocol_interface.rs
in the aggregator repository.
Import the router client
Generate a typed client from the router’s WASM withcontractimport!:
Call it
path, not just the final output amount.
Authorization
The router callsto.require_auth() inside the swap. That means the address receiving the
output has to authorize the call, so your contract cannot swap on a user’s behalf unless
that user authorized the invocation, or to is your own contract address and your
contract authorizes it. Design your flow around one of those two, not around holding user
keys.
Getting the router address
Take it from Deployed Addresses, or read it at runtime from the API:The rest of the interface
swap_tokens_for_exact_tokens, add_liquidity and remove_liquidity are called the same
way through the same client. Their signatures are on the
SoroswapRouter page. If you only
need a price and not an execution, router_get_amounts_out and router_quote are
read-only and cost you no state.