Swaps

Swaps are the execution phase of cross-chain transactions in the Aori protocol. After obtaining a quote and signing an order, you submit the swap to initiate the cross-chain transfer. This page covers everything you need to know about submitting and managing swaps.


Swap Types

SwapRequesttype

The SwapRequest interface contains the data needed to submit a signed order for execution.

  • Name
    orderHash
    Type
    string
    Description

    The unique identifier of the order to execute

  • Name
    signature
    Type
    string
    Description

    The cryptographic signature authorizing the swap

SwapRequest Interface

interface SwapRequest {
  orderHash: string;
  signature: string;
}

Example

const swapRequest: SwapRequest = {
  orderHash: "0x1234567890abcdef1234567890abcdef12345678",
  signature: "0x1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef01"
};

SwapResponsetype

The SwapResponse interface contains the details of a submitted swap order.

  • Name
    orderHash
    Type
    string
    Description

    Unique identifier for the order

  • Name
    offerer
    Type
    string
    Description

    The address that initiated the swap

  • Name
    recipient
    Type
    string
    Description

    The address receiving the output tokens

  • Name
    inputToken
    Type
    string
    Description

    The token address being sold

  • Name
    outputToken
    Type
    string
    Description

    The token address being bought

  • Name
    inputAmount
    Type
    string
    Description

    The amount of input tokens

  • Name
    outputAmount
    Type
    string
    Description

    The amount of output tokens

  • Name
    inputChain
    Type
    string
    Description

    The source chain identifier

  • Name
    outputChain
    Type
    string
    Description

    The destination chain identifier

  • Name
    startTime
    Type
    number
    Description

    Unix timestamp when the order became valid

  • Name
    endTime
    Type
    number
    Description

    Unix timestamp when the order expires

  • Name
    status
    Type
    string
    Description

    Current status of the swap

  • Name
    createdAt
    Type
    number
    Description

    Unix timestamp when the swap was created

SwapResponse Interface

interface SwapResponse {
  orderHash: string;
  offerer: string;
  recipient: string;
  inputToken: string;
  outputToken: string;
  inputAmount: string;
  outputAmount: string;
  inputChain: string;
  outputChain: string;
  startTime: number;
  endTime: number;
  status: string;
  createdAt: number;
}

Example

const swapResponse: SwapResponse = {
  orderHash: "0x1234567890abcdef1234567890abcdef12345678",
  offerer: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b",
  recipient: "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b",
  inputToken: "0x4200000000000000000000000000000000000006",
  outputToken: "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
  inputAmount: "1000000000000000000", // 1 WETH
  outputAmount: "3200000000", // 3200 USDC
  inputChain: "base",
  outputChain: "arbitrum",
  startTime: 1703001600,
  endTime: 1703005200,
  status: "pending",
  createdAt: 1703001600
};

Submitting a Swap

submitSwapfunction

Submit a signed swap order for execution on the Aori protocol.

  • Name
    request
    Type
    SwapRequest
    Description

    The swap request with order hash and signature

  • Name
    baseUrl
    Type
    string
    Description

    API base URL (defaults to https://api.aori.io)

  • Name
    apiKey
    Type
    string
    Description

    API key for authentication

Returns: SwapResponse

Usage

import { getQuote, signOrder, submitSwap } from '@aori/aori-ts';

// 1. Get a quote
const quote = await getQuote({
  offerer: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b',
  recipient: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b',
  inputToken: '0x4200000000000000000000000000000000000006',
  outputToken: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
  inputAmount: '1000000000000000000',
  inputChain: 'base',
  outputChain: 'arbitrum'
});

// 2. Sign the order
const signature = await signOrder(quote, { privateKey: 'your-private-key' });

// 3. Submit the swap
const swap = await submitSwap(
  {
    orderHash: '0x1234567890abcdef1234567890abcdef12345678',
    signature: '0x1b2c3d4e5f6789abcdef...'
  },
  'https://api.aori.io',
  process.env.AORI_API_KEY
);

console.log('Swap submitted:', swap.orderHash);
console.log('Status:', swap.status);

Response

{
  "orderHash": "0x1234567890abcdef1234567890abcdef12345678",
  "offerer": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b",
  "recipient": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b",
  "inputToken": "0x4200000000000000000000000000000000000006",
  "outputToken": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
  "inputAmount": "1000000000000000000",
  "outputAmount": "3200000000",
  "inputChain": "base",
  "outputChain": "arbitrum",
  "startTime": 1703001600,
  "endTime": 1703005200,
  "status": "pending",
  "createdAt": 1703001600
}