On-Chain Integration
How to submit on-chain transactions to open and close leveraged positions, and what the backend handles automatically after each step.
Position lifecycle
User action Backend (automatic)
─────────── ───────────────────
1. Approve pUSD
2. Call createPosition() ──────────► Detect event
Place exchange order
Finalize on-chain
──► position.opened WebSocket event
3. Call requestClose() ────────────► Detect event
Sell tokens on exchange
Distribute proceeds on-chain
──► position.closed WebSocket event
Shrink without closing (owner-initiated):
4. Call requestPartialClose() ─────► Detect event
Sell the slice on the exchange
Repay proportional capital, finalize on-chain
──► position stays open at reduced size
Other exits (no user action needed):
Market resolves ─────────────────► Settle all positions
Price breaches threshold ────────► Liquidate positionWallet types
Opening a position (Direct EOA)
1. Approve pUSD
2. Call createPosition
createPosition3. What happens next (automatic)
Closing a position
Partially closing a position
Other exit paths
Contract ABIs
Vault
Last updated

