Provides functionality to fetch and cache pairs from a backend API, based on the specified blockchain network.

const pairProvider = new PairProvider(Networks.TESTNET, "https://api.example.com", "api-key", 20);

Constructors

  • Initializes a new instance of the PairProvider.

    Parameters

    • opts: PairProviderOptions

    Returns PairProvider

Properties

_cache: {
    [x: string]: {
        pairs: Pair[];
        timestamp: number;
    };
}

Type declaration

  • [x: string]: {
        pairs: Pair[];
        timestamp: number;
    }
    • pairs: Pair[]
    • timestamp: number
_cacheInSeconds: number
_network: Networks
getPairsFns?: GetPairsFns

Methods

  • Returns pairs wether from backend or blockchain If the network is testnet or public and shouldUseBackend is true, it will try to fetch from the backend first, and if it fails, it will fetch from the blockchain If the network is standalone or futurenet, it will fetch from the blockchain

    Parameters

    • address0: string

      The address of the first token in the pair.

    • address1: string

      The address of the second token in the pair.

    • factoryAddress: undefined | string

      The address of the factory contract.

    • sorobanContext: undefined | SorobanContextType

      The Soroban context to use for the contract invocation.

    • protocols: Protocol[]

      (Optional) The protocols to fetch pairs for, defaulting to SOROSWAP.

    Returns Promise<null | Pair[]>

    A promise that resolves to an array of Pair instances representing the pair fetched from the backend or blockchain, or null in case of an error.

  • Fetches a pair from the blockchain, caching it to reduce API calls. If cached pair is still valid, returns it instead of fetching anew.

    Parameters

    • address0: string

      The address of the first token in the pair.

    • address1: string

      The address of the second token in the pair.

    • factoryAddress: undefined | string

      The address of the factory contract.

    • sorobanContext: undefined | SorobanContextType

      The Soroban context to use for the contract invocation.

    Returns Promise<null | Pair[]>

    A promise that resolves to an array of Pair instances representing the pair fetched from the blockchain, or null in case of an error.

  • Returns void