Data Flows
API indexing and sponsoring
This flow is used by all write actions, that create transactions on chain, as creation/registration of TradeAccounts, initialization of sessions, creation/cancelation of orders. So we don't explicitly mention again this flow on the other flows and instead it will be encapsulated as just API.
sequenceDiagram
participant User
participant API
participant GasSponsor
participant Indexer
participant Blockchain
User->>API: Submits a requests
API->>GasSponsor: Adds Resources to pay for Gas
GasSponsor->>Blockchain: Forwards Transaction to the Chain
Blockchain-->>API: Return Transaction Id
API-->>User: Return Transaction Id
Blockchain-->>Indexer: Listen pre-confs `Events` like (OrderCreation, AccountCreation,...)
Indexer-->>API: Update State
API-->>User: Send Websocket NotificationsTrade Account - Create Account
On this flow users request the creation of a trading account, this process deploys a contract for users that, can be upgraded later by the users enforced by a Oracle system. For better convenience it uses the sponsor mechanism, in this way users do not need to pay for transactions. The address owner of this trade accounts, can be a EVM address or a Fuel address, allowing to use any of this two signatures.
sequenceDiagram
participant User
participant API
participant Blockchain
User->>API: Request Account Creation
API->>Blockchain: Deploy Trade Account Proxy
Blockchain-->>API: Transaction Id
API-->>API: Wait finalization
API->>Blockchain: Register Trade Account on Registry.`Registry.register_trade_account(...)`
Blockchain-->>API: Emit event `TradeAccountRegistered`
API-->>User: Return trade_account_idTrade Account - Register Session
Session keys, can execute any action on the contract, this is really permissive, so users should not use their trade accounts, to interact with other contracts, this is not enforced on the contract logic. A session id, is equal to a EOA public key, where the private key, can be store in a less safe environment as LocalStorage, due to the nature of time bond, and revoke mechanims.
sequenceDiagram
participant User
participant API
participant Blockchain
User->>User: Create payload for `TradeAccount.set_session` <br /> including signature and address for session address.
User->>API: Send payload to be executed on chain.
API->>Blockchain: Call `TradeAccount.set_session(signature, session)`
Blockchain-->>API: Transaction Id
API-->>User: Transaction IdTrade Account - Order Placement
Orders on o2, can be posted directly OnChain or though sponsred API, for this flow we focus mainly on the usage of Tranding Accounts, with sponsor transactions.
sequenceDiagram
participant User
participant API
box Gray Blockchain
participant TradeAccount
participant OrderBook
end
User->>User: Create payload for `TradeAccount.session_call_contract(..)` <br /> including signature over `OrderBook.create_order(...)`.
User->>User: Sign over ContractCall args
User->>API: Submit Order Creation Request
API->>TradeAccount: Call `TradeAccount.session_call_contract`
TradeAccount->>OrderBook: Call `OrderBook.create_order(...)`
OrderBook->>OrderBook: Emits `OrderCreatedEvent`, <br /> `OrderMatchedEvent` and `OrderCancelledEvent`
OrderBook-->>API: Index events and update state
API-->>User: Return transaction_id and orders created
API-->>User: Send Websocket Notifications