Account Lifecycle
Prerequisites
- User has a Freighter wallet with testnet XLM
- SDK setup from Getting Started
invokeContractutility from Transaction Flow
Step 1: Create a Margin Account
If the user already has a closed account,
create_account() will reuse it. The same Registry call will return the reactivated address.Step 2: Check Health Factor Before Any Operation
Always check health factor before borrows and withdrawals:HF < 1.1
Step 3: Deposit Collateral
Step 4: Borrow
Step 5: Atomic Deposit + Borrow
For better UX, combine deposit and borrow in a single transaction:Step 6: Deploy to External Protocols
After borrowing, the SmartAccount holds the borrowed assets. Route them to Blend or Aquarius viaAccountManager.execute().
The
execute() function routes through AccountManager → SmartAccount → external protocol. This is how the protocol tracks external positions via TrackingTokens.Deploy to Blend (Earn Yield on Borrowed XLM)
Add Liquidity to Aquarius
Step 7: Read Outstanding Debt
Step 8: Repay
Step 9: Withdraw Collateral
Step 10: Close Account
Common Pitfalls
Related
- AccountManager Reference — full function reference
- Risk Engine Reference — health factor computation
- Math Reference — health factor formula
- Liquidation Bots — monitor accounts you built

