1LAYER Tech Documentation
  • Intro
  • 1LAYER AI
    • AI Cognitive Framework
  • 1LAYER DeFi
    • Smart Contract System
      • Flows
        • Swap Flow
          • Interchain Swap
          • Intrachain Swap
        • Vault Flow
      • Smart Contracts
        • Broadcaster Components Diagram
        • User Components Diagram
        • Admin Components Diagram
Powered by GitBook
On this page
  1. 1LAYER DeFi
  2. Smart Contract System
  3. Flows
  4. Swap Flow

Intrachain Swap

Sequence diagram and description of the intrachain swap. (Swaps within a chain)

PreviousInterchain SwapNextVault Flow

Last updated 9 months ago

This sequence diagram illustrates the process of an intrachain swap:

  1. The User initiates the swap through the Frontend.

  2. The Frontend constructs the swap transaction based on the user's input. Any swap protocol available on the chain and supported by the Frontend can be utilized.

  3. The Frontend requests the User to sign the transaction.

  4. The User signs the transaction and broadcasts the signed transaction to the blockchain.

  5. The Executor contract participates in the transaction execution.

  6. The Executor validates the transaction.

  7. If the transaction is valid:

    a. The Executor sends a request to the Swap Protocol (thirdparty) to execute the swap.

    b. The Swap Protocol executes the swap.

    c. The Swap Protocol returns the swap result to the Executor.

    e. The Executor transfers fees to the system wallet.

    f. The Executor returns the transaction result to the Frontend.

  8. If the transaction is invalid the Executor returns an error to the Frontend.

  9. The Frontend displays the swap result or the error to the User.

Diagram code
sequenceDiagram
    actor User
    participant Frontend
    participant Executor
    participant SwapProtocol as Swap Protocol (Thirdparty)

    User->>Frontend: Initiate swap
    Frontend->>Frontend: Construct swap transaction
    Frontend->>User: Request transaction signature
    User->>Frontend: Sign transaction
    Frontend->>Executor: Broadcast signed transaction
    Executor->>Executor: Validate transaction
    alt Transaction is valid
        Executor->>SwapProtocol: Request swap execution
        SwapProtocol->>SwapProtocol: Execute swap
        SwapProtocol-->>Executor: Return swap result
        Executor->>Executor: Get the protocol fee
        Executor-->>Frontend: Return transaction result
    else Transaction is invalid
        Executor-->>Frontend: Return error
    end
    Frontend->>User: Display swap result or error