Architecture

Position mechanics
Untangled Loop is deployed as two Soroban contracts working together:
- Entrypoint: per-pair strategy initiator (e.g., XLM/USDC). Builds the flash loan + request bundle.
- MarginManager: flash-loan callback handler. Executes swaps via Aquarius and leaves swapped tokens with the caller for Blend requests.
Architecture (open position)
- User calls
Entrypoint.open_long()orEntrypoint.open_short() - Entrypoint calls
MarginManager.set_swap_config(...) - Entrypoint calls Blend Pool
flash_loan(caller, FlashLoan{...}, requests) - Blend transfers flash loan tokens to MarginManager and calls
MarginManager.exec_op(...) - MarginManager:
- transfers flash-loaned tokens to caller
- swaps via Aquarius using the configured route and
min_amount_out - clears swap config
- Blend executes
requests(supply collateral, borrow, repay) - Position is opened
Long position
A long Base/Quote position means:
- Collateral = Base
- Debt = Quote
- Profit when Base/Quote increases
Quote currency as margin
If a trader longs Base using Quote as margin, Loop:
- flash loans Quote
- swaps Quote → Base
- supplies Base as collateral
- borrows Quote
- repays flash loan
This is implemented by:
Entrypoint.open_long(...)- swap config token_out = Base
- Blend requests:
SUPPLY_COLLATERAL(Base),BORROW(Quote),REPAY(Quote)
Base currency as margin
If a trader longs Base using Base as margin, Loop:
- flash loans Quote
- swaps Quote → Base
- supplies (swapped Base + margin Base) as collateral (depending on
margin_from_quote) - borrows Quote
- repays flash loan
The contracts support margin being either side of the pair via
margin_from_quoteandinitial_margin.
Short position
A short Base/Quote position means:
- Collateral = Quote
- Debt = Base
- Profit when Base/Quote decreases
Quote currency as margin
If a trader shorts Base using Quote as margin, Loop:
- flash loans Base
- swaps Base → Quote
- supplies (swapped Quote + margin Quote) as collateral
- borrows Base
- repays flash loan
This is implemented by:
Entrypoint.open_short(...)- swap config token_out = Quote
- Blend requests:
SUPPLY_COLLATERAL(Quote),BORROW(Base),REPAY(Base)
In the UI example (XLM/USDC short):
- User inputs USDC as margin
- Loop borrows/owes XLM (debt) and holds USDC as collateral
- Leverage controls how much Base is flash loaned and swapped into additional collateral
Base currency as margin
If a trader shorts Base using Base as margin, Loop:
- flash loans Base
- swaps Base → Quote
- supplies swapped Quote as collateral
- borrows Base (reduced by margin if margin is Base)
- repays flash loan