- Resolve the trader’s existing account using
MarginAccountService.discoverExistingAccount. Account discovery in this app includes Registry storage and fallback reads; do not invent a Registry getter. - If needed, call AccountManager
create_account(trader_address)with trader authorization. - Resolve the exact token and pool. Deposit using
deposit_collateral_tokens(smart_account, symbol, amount)in the signature order shown in the reference. - Borrow only after inspecting account health, spendable balances, pool cash, utilization, permissions, and fee. Use the current builder for atomic same-asset or cross-asset operations.
- For external strategies, call typed
execwith the registered target, action, token addresses, protocol-specific amount units, and minima. - Repay with
repay(amount_wad, symbol, smart_account)from SmartAccount-held tokens. Unwind external assets or transfer collateral in first if required. - To exit the account, settle recognized debt, verify
has_debt, and callclose_accountafter the activation ledger.
lib/margin-utils.ts and the wallet adapter. Its normalization keeps BLUSDC/USDC aliases within the Blend token identity, separate from AQUSDC and SOUSDC. Read AccountManager and Transaction Flow before encoding calls.
Source reference
mercury-stellar-backend/lib/margin-utils.tsProtocol_V1_Soroban_testnet/contracts/AccountManagerContract/src/account_manager.rs

