AccountManager is the first contract a user or integrator calls for any margin operation. It authenticates callers, coordinates with RiskEngine and LendingPool, and delegates state mutations to the user’s SmartAccount.
Testnet address: CAK2IJIO2SKZWUODY4G7ZRIUUIIMJUUAIXE3I5YTQ5QYNSS2RYJ3P4CV
Account Lifecycle
create_account
SmartAccount contract for trader_addr (or reuses a closed one from the inactive pool) and marks it as active.
Authorization: trader_addr.require_auth()
Returns: Address of the new (or reused) SmartAccount
Storage written:
UsersList— appendstrader_addrif not already presentSmartAccounts(trader_addr)— stores the active SmartAccount addressTraderAddress(smart_account)— reverse mapping from SmartAccount → trader- Registry is updated with the new account
close_account
smart_account) must sign
Panics if: The account has any outstanding debt (has_debt == true)
Returns: true on success
Events emitted:
Collateral Operations
deposit_collateral_tokens
amount (in WAD) of the token identified by symbol from the caller’s wallet to the SmartAccount.
Authorization: Trader must sign; caller must approve token transfer
Parameters:
| Parameter | Type | Description |
|---|---|---|
smart_account | Address | The user’s margin account |
symbol | Symbol | Token symbol (e.g., "XLM", "USDC") |
amount | U256 | Amount in WAD (10¹⁸ = 1 token) |
withdraw_collateral_balance
RiskEngine.is_withdraw_allowed(symbol, amount, smart_account) must return true
Panics if: Health factor would drop below 1.1× after withdrawal
Borrow Operations
borrow
amount of symbol from the corresponding LendingPool into the SmartAccount.
Authorization: Trader must sign
Risk check: RiskEngine.is_borrow_allowed(symbol, amount, smart_account) must return true
Parameters:
| Parameter | Type | Description |
|---|---|---|
smart_account | Address | The user’s margin account |
amount | U256 | Amount to borrow in WAD |
symbol | Symbol | Asset to borrow ("XLM", "USDC") |
- RiskEngine validates the borrow
- LendingPool accrues interest (
update_state()) - Origination fee is deducted and sent to treasury
- Borrowed amount is transferred to SmartAccount
- SmartAccount records the new borrow in
BorrowedTokensList
deposit_and_borrow
deposit_and_borrow_cross
deposit_borrow_and_deploy_blend
Repay
repay
repay_amt of symbol debt. Caller (trader) transfers funds back to the LendingPool. If the full debt is repaid, the symbol is removed from BorrowedTokensList.
Authorization: Trader must sign
Events emitted:
Liquidation
liquidate
RiskEngine.is_account_healthy(collateral_usd, debt_usd) must return false
What happens:
- Validates the account is unhealthy
- For each borrowed token: reads outstanding debt, calls
LendingPool.collect_from()to repay it - Calls
SmartAccount.sweep_to(trader_address)to return remaining collateral - Emits event
settle_account
liquidate(), this is intended for voluntary debt settlement by the account owner.
External Protocol Execution
execute (via SmartAccount routing)
External protocol calls are routed through the SmartAccount’sexecute() function. The AccountManager orchestrates:
- Auth of the trader
- SmartAccount executes the external call (Blend, Aquarius, Soroswap)
- AccountManager mints/burns TrackingTokens based on the returned token delta
Supported Assets
| Symbol | Asset | Pool |
|---|---|---|
XLM | Stellar Lumens (native) | LendingPoolXLM |
USDC | USD Coin | LendingPoolUSDC |
BLUSDC | Blend-wrapped USDC | LendingPoolUSDC |
| AQUSDC | Aquarius-wrapped USDC | LendingPoolAquariusUSDC |
| SOUSDC | Soroswap-wrapped USDC | LendingPoolSoroswapUSDC |
Error Codes
Key Storage
| Key | Type | Description |
|---|---|---|
UsersList | Vec<Address> | All traders with accounts |
SmartAccounts(trader) | Address | Trader’s active SmartAccount |
InactiveAccountOf(trader) | Vec<Address> | Closed accounts available for reuse |
TraderAddress(account) | Address | Reverse: SmartAccount → trader |
IsCollateralAllowed(symbol) | bool | Whether symbol is accepted as collateral |
AssetCap | U256 | Maximum total asset cap for the protocol |
Admin | Address | Admin address |
RegistryContract | Address | Registry address |

