Maya Protocol One-Stop-Shop
  • Introduction
    • 🍫What is Maya Protocol?
      • Getting Started
      • Roles
        • Liquidity Providers
        • Swappers
        • Arbitrageurs
        • Node Operators
      • Maya Protocol Native Assets
    • 🌐Maya Ecosystem
      • User interfaces & Wallets
      • Tools
    • 🍫How to buy CACAO?
    • πŸ›£οΈRoadmap 2025
  • Deep Dive
    • πŸšΆβ€β™‚οΈStep-by-Step Guides
      • Set up a MAYAChain wallet
        • Using El Dorito Club
        • Using THORWallet web APP
        • Using THORWallet Mobile APP
        • Through MAYANode cli
        • By importing Ledger hard wallet into Ctrl Wallet
      • Custom Memos
        • Swap
        • Add Liquidity
        • Withdraw Liquidity
    • πŸ› οΈHow It Works
      • Technology
      • Incentive Curve
      • Fees
      • Governance
      • Constants and Mimir
      • Security
      • Dynamic Inflation
      • Liquidity Nodes
      • Impermanent Loss Protection (ILP)
      • ELI5
        • What is Threshold Signature Scheme (TSS)?
    • πŸ’΅DeFi Products
      • Synthetics
      • Liquidity
    • πŸ”Audits
    • 🎭Maya Masks
    • ❓FAQs
  • Blockchain Explorer
    • πŸ”ŽMayaScan
      • πŸͺ™MRC-20 Tokens
      • πŸ–ΌοΈM-NFTS
  • Airdrop
    • πŸͺ‚$MAYA Airdrops Guide
  • Media
    • πŸ“½οΈAaluxx Interviews
    • 🐦Twitter Spaces
    • πŸ”—Links
  • Contribute
    • 😎Ambassador Program
    • 🎨Content Creators Guide
  • Node Docs
    • πŸ–₯️MAYANodes
      • MAYANode Overview
      • Cluster Launcher
        • Setup - Linode
        • Setup - Azure
        • Setup - Hetzner Bare Metal
        • Setup - Google Cloud
        • Setup - HCloud
        • Setup - Digital Ocean
        • Setup - AWS
      • Deploying
      • Joining
      • Managing
      • Pooled MAYANodes
      • Alerting
      • Leaving
      • πŸ›‘Emergency Procedures
      • βœ”οΈ CHECKLIST
      • Multi-node Deployment
      • Fullnode Installation Guide
    • Bonding & Unbonding Guide
    • Bare Metal Node Guides
  • MAYACHAIN DEV DOCS
    • Introduction
      • MAYAName Guide
      • Swapping Guide
        • Quickstart Guide
        • Fees and Wait Times
        • Streaming Swaps
      • Add MAYAChain to your Wallet
    • Examples
      • Tutorials
      • Typescript (XChainJS) WIP
        • Query Package
        • AMM Package
        • Client Packages
        • Packages Breakdown
        • Coding Guide
      • SwapKit SDK
    • Concepts
      • Connecting to MAYAChain
      • Querying MAYAChain
      • Transaction Memos
      • Asset Notation
      • Memo Length Reduction
      • Network Halts
      • Fees
      • Delays
      • Sending Transactions
      • Math
    • Aggregators
      • Memos
      • EVM Implementation
    • CLI
      • Multisig
      • Offline Ledger Support
    • Protocol Development
      • Adding New Chains
      • Chain Clients
        • UTXO
        • EVM Chains
        • Cosmos Chains
      • ERC-20 Tokens
      • THORChain Version Updates I
      • THORChain Version Updates II
  • White Paper
    • πŸ“–Maya Whitepaper 2.0
      • Introduction
      • 🍫Fair Launch
        • Philosophical perspective FL
        • Economic overview FL
        • Technical overview FL
      • πŸͺ™$MAYA token
        • Philosophical perspective MT
        • Economic overview MT
        • Technical overview MT
      • 🌊Liquidity Nodes
        • Philosophical perspective LN
        • Economic overview LN
        • Technical overview LN
      • πŸ”’Security Nodes
        • Philosophical perspective SN
        • Economic overview SN
        • Technical overview SN
      • πŸ”΄Aztec Chain & $AZTEC token
        • Philosophical perspective AC
        • Economic overview AC
        • Technical overview AC
      • βš–οΈStable Pools & Route Optimization
        • Philosophical perspective RO
        • Economic overview RO
        • Technical overview RO
      • πŸ‘£Roadmap. Maya 3.0
        • Philosophical perspective 3.0
        • Economic overview 3.0
        • Technical overview 3.0
  • Website
  • GitLab
  • Archive
    • Liquidity Auction
    • THORChads Airdrop
    • Add ETH, USDC, or USDT through THORWallet using Metamask + Ledger
    • $MAYA Airdrop for Maya Mask Holders
    • Maya Integration Guide
    • Roadmap 2023
Powered by GitBook

Social Media

  • Twitter
  • Telegram
  • Discord
On this page
  • How xChainjs is constructed
  • xchain-[chain] clients
  • xchain-mayachain-amm
  • xchain-mayachain-query
  • xchain-midgard
  • xchain-mayanode

Was this helpful?

Export as PDF
  1. MAYACHAIN DEV DOCS
  2. Examples
  3. Typescript (XChainJS) WIP

Packages Breakdown

How xChainjs is constructed

xchain-[chain] clients

Each blockchain that is integrated into MAYAChain has a corresponding xchain client with a suite of functionality to work with that chain. They all extend the xchain-client class.

xchain-mayachain-amm

MAYAChain automatic market maker that uses MAYANode & Midgard Api's AMM functions like swapping, adding and removing liquidity. It wraps xchain clients and creates a new wallet class and balance collection.

xchain-mayachain-query

Uses midgard and mayanode Api's to query MAYAChain for information. This module should be used as the starting place get any MAYAChain information that resides in MAYANode or Midgard as it does the heaving lifting and configuration.

Default endpoints are provided with redundancy, custom MAYANode or Midgard endpoints can be provided in the constructor.

xchain-midgard

This package is built from OpenAPI-generator. It is used by the mayachain-query.

Thorchain-query contains midgard class that uses xchain-midgard and the following end points:

  • /v2/mayachain/mimir

  • /v2/mayachain/inbound_addresses

  • /v2/mayachain/constants

  • /v2/mayachain/queue

For simplicity, is recommended to use the midgard class within mayachain-query instead of using the midgard package directly.

Midgard Configuration in mayachain-query

Default endpoints defaultMidgardConfig are provided with redundancy within the Midgard class.

// How mayachain-query constructs midgard
const defaultMidgardConfig: Record<Network, MidgardConfig> = {
  mainnet: {
    apiRetries: 3,
    midgardBaseUrls: [
      'https://midgard.ninerealms.com',
      'https://midgard.thorchain.info',
      'https://midgard.thorswap.net',
    ],
  },
  ...
  export class Midgard {
  private config: MidgardConfig
  readonly network: Network
  private midgardApis: MidgardApi[]

  constructor(network: Network = Network.Mainnet, config?: MidgardConfig) {
    this.network = network
    this.config = config ?? defaultMidgardConfig[this.network]
    axiosRetry(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry.exponentialDelay })
    this.midgardApis = this.config.midgardBaseUrls.map((url) => new MidgardApi(new Configuration({ basePath: url })))
  }

Custom Midgard endpoints can be provided in the constructor using the MidgardConfig type.

// adding custom endpoints
  const network = Network.Mainnet
  const customMidgardConfig: MidgardConfig = {
    apiRetries: 3,
    midgardBaseUrls: [
      'https://midgard.customURL.com',
    ],
  }  
  const midgard = new Midgard(network, customMidgardConfig)  
}

See ListPools for a working example.

xchain-mayanode

This package is built from OpenAPI-generator and is also used by the thorchain-query. The design is similar to the midgard. MAYANode should only be used when time-sensitive data is required else midgard should be used.

// How thorchain-query constructs thornode
const defaultThornodeConfig: Record<Network, ThornodeConfig> = {
  mainnet: {
    apiRetries: 3,
    thornodeBaseUrls: [
      `https://thornode.ninerealms.com`,
      `https://thornode.thorswap.net`,
      `https://thornode.thorchain.info`,
    ],
  },
  ...
  export class Thornode {
  private config: ThornodeConfig
  private network: Network
 ...
  constructor(network: Network = Network.Mainnet, config?: ThornodeConfig) {
    this.network = network
    this.config = config ?? defaultThornodeConfig[this.network]
    axiosRetry(axios, { retries: this.config.apiRetries, retryDelay: axiosRetry.exponentialDelay })
    this.transactionsApi = this.config.thornodeBaseUrls.map(
      (url) => new TransactionsApi(new Configuration({ basePath: url })),
    )
    this.queueApi = this.config.thornodeBaseUrls.map((url) => new QueueApi(new Configuration({ basePath: url })))
    this.networkApi = this.config.thornodeBaseUrls.map((url) => new NetworkApi(new Configuration({ basePath: url })))
    this.poolsApi = this.config.thornodeBaseUrls.map((url) => new PoolsApi(new Configuration({ basePath: url })))
    this.liquidityProvidersApi = this.config.thornodeBaseUrls.map(
      (url) => new LiquidityProvidersApi(new Configuration({ basePath: url })),
    )
  }

MAYANode Configuration in mayachain-query

As with the midgard package, MAYANode can also be given custom end points via theMayanodeConfig type.

xchain-util

A helper packager used by all the other packages. It has the following modules:

  • asset - Utilities for handling assets

  • async - Utitilies for async handling

  • bn - Utitilies for using bignumber.js

  • chain - Utilities for multi-chain

  • string - Utilities for strings

PreviousClient PackagesNextCoding Guide

Last updated 1 year ago

Was this helpful?