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
  • Query
  • AMM

Was this helpful?

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

Coding Guide

A coding overview to XChainJS.

PreviousPackages BreakdownNextSwapKit SDK

Last updated 1 year ago

Was this helpful?

General

The foundation of xchainjs is defined in the package

  • Address: a crypto address as a string.

  • BaseAmount: a bigNumber in 1e8 format. E.g. 1 BTC = 100,000,000 in BaseAmount

  • AssetAmount: a BaseAmount*10^8. E.g. 1 BTC = 1 in Asset Amount.

  • Asset: Asset details {Chain, symbol, ticker, isSynth}

All Assets must conform to the assetFromString() is used to quickly create assets and will assign chain and synth.

  • CryptoAmount: is a class that has:

baseAmount: BaseAmount
readonly asset: Asset

All crypto should use the CryptoAmount object with the understanding they are in BaseAmount format. An example to switch between them:

// Define 1 BTC as CryptoAmount
oneBtc = new CryptoAmount(assetToBase(assetAmount(1)), assetFromStringEx(`BTC.BTC`))
// Print 1 BTC in BaseAmount 
console.log(oneBtc.amount().toNumber().toFixed()) // 100000000
// Print 1 BTC in Asset Amount 
console.log(oneBtc.AssetAmount().amount().toNumber().toFixed()) // 1

Query

Major data types for the mayarchain-query package.

EstimateSwapParams

The input Type for estimateSwap. This is designed to be created by interfaces and passed into EstimateSwap. Also see Swap Memo for more information.

Variable

Data Type

Comments

input

CryptoAmount

inbound asset and amount

destinationAsset

Asset

outbound asset

destinationAddress

String

outbound asset address

slipLimit

BigNumber

Optional: Used to set LIM

affiliateFeePercent

number

Optional: 0-0.1 allowed

affiliateAddress

Address

Optional: thor address

interfaceID

string

Optional: assigned interface ID

SwapEstimate

The internal return type is used within estimateSwap after the calculation is done.

Variable

Data Type

Comments

totalFees

TotalFees

All fees for swap

slipPercentage

BigNumber

Actual slip of the swap

netOutput

CryptoAmount

input - totalFees

waitTimeSeconds

number

Estimated time for the swap

canSwap

boolean

false if there is an issue

errors

string array

contains info if canSwap is false

TxDetails

Return type of estimateSwap. This is designed to be used by interfaces to give them all the information they need to display to the user.

Variable

Data Type

Comments

txEstimate

SwapEstimate

swap details

memo

string

constructed memo MAYAChain will understand

expiry

DateTime

when the SwapEstimate information will no longer be valid.

toAddress

string

current Asgard Vault address From inbound_address

Do not use toAddress after expiry as the Asgard vault rotates

AMM

Major data types for the thorchain-query package.

  • Package description

  • Code examples

  • Install procedures

ExecuteSwap

Input Type for doSwap where a swap will be actually conducted. Based on EstimateSwapParams.

TxSubmitted

Variable

Text

Text

hash

string

inbound Tx Hash

url

string

Block exploer url

waitTimeSeconds

number

Estimated time for the swap

xchain-util
Asset Notation
Package description
Github source code
Code examples
Github source code
Install procedures