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
On this page
  • Introduction
  • 1. Determine the correct asset name.
  • 2. Query for a swap quote.
  • 3. Sign and send transactions on the from_asset chain.
  • 4. Receive tokens.
  • Additional Considerations
  • Affiliate Fees
  • Streaming Swaps

Was this helpful?

Export as PDF
  1. MAYACHAIN DEV DOCS
  2. Introduction
  3. Swapping Guide

Quickstart Guide

Make a cross-chain swap on MAYAChain in less than 5 minutes.

PreviousSwapping GuideNextFees and Wait Times

Last updated 8 months ago

Was this helpful?

Social Media

  • Twitter
  • Telegram
  • Discord

Introduction

MAYAChain allows native L1 Swaps. On-chain are used instruct MAYAChain how to swap, with the option to add and . MAYAChain nodes observe the inbound transactions and when the majority have observed the transactions, the transaction is processed by threshold-signature transactions from MAYAChain vaults.

Let's demonstrate decentralized, non-custodial cross-chain swaps. In this example, we will build a transaction that instructs MAYAChain to swap native Bitcoin to native Ethereum in one transaction.

The following examples use a free, hosted API provided by the Maya Protocol team. If you want to run your own full node, please see

1. Determine the correct asset name.

MAYAChain uses a specific Available assets are at: .

BTC => BTC.BTC

ETH => ETH.ETH

Only available pools can be used. (where 'status' == Available)

2. Query for a swap quote.

All amounts are 1e8. Multiply native asset amounts by 100000000 when dealing with amounts in THORChain. 1 BTC = 100,000,000.

Request: Swap 1 BTC to ETH and send the ETH to 0x3021c479f7f8c9f1d5c7d8523ba5e22c0bcb5430.

​​Response:

{
  "expected_amount_out": "1855545107",
  "fees": {
    "affiliate": "0",
    "asset": "ETH.ETH",
    "outbound": "840000"
  },
  "inbound_address": "bc1qqtemwlu9ju3ts3da5l82qejnzdl3xfs3lcl4wg",
  "inbound_confirmation_blocks": 1,
  "inbound_confirmation_seconds": 600,
  "memo": "=:ETH.ETH:0x86d526d6624AbC0178cF7296cD538Ecc080A95F1",
  "outbound_delay_blocks": 179,
  "outbound_delay_seconds": 2685,
  "slippage_bps": 168
}

If you send 1 BTC to bc1qlccxv985m20qvd8g5yp6g9lc0wlc70v6zlalz8 with the memo =:ETH.ETH:0x3021c479f7f8c9f1d5c7d8523ba5e22c0bcb5430, you can expect to receive 18.55545107 ETH.

For security reasons, your inbound transaction will be delayed by 600 seconds (1 BTC Block) and 2685 seconds (or 179 native MAYAChain blocks) for the outbound transaction, 3285 seconds all up. You will pay an outbound gas fee of 0.0085 ETH and will incur 168 basis points (1.68%) of slippage.

See an example implementation LINK HERE

3. Sign and send transactions on the from_asset chain.

Construct, sign and broadcast a transaction on the BTC network with the following parameters:

Amount => 1.0

Recipient => bc1qlccxv985m20qvd8g5yp6g9lc0wlc70v6zlalz8

Memo => =:ETH.ETH:0x3021c479f7f8c9f1d5c7d8523ba5e22c0bcb5430

Never cache inbound addresses! Quotes should only be considered valid for 10 minutes. Sending funds to an old inbound address will result in loss of funds.

4. Receive tokens.

Once a majority of nodes have observed your inbound BTC transaction, they will sign the Ethereum funds out of the network and send them to the address specified in your transaction. You have just completed a non-custodial, cross-chain swap by simply sending a native L1 transaction.

Additional Considerations

There is a rate limit of 1 request per second per IP address on /quote endpoints. It is advised to put a timeout on frontend components input fields, so that a request for quote only fires at most once per second. If not implemented correctly, you will receive 503 errors.

For best results, request a new quote right before the user submits a transaction. This will tell you whether the expected_amount_out has changed or if the inbound_address has changed. Ensuring that the expected_amount_out is still valid will lead to better user experience and less frequent failed transactions.

Price Limits

Specify tolerance_bps to give users control over the maximum slip they are willing to experience before canceling the trade. If not specified, users will pay an unbounded amount of slip.​​

Notice how a minimum amount (1822007296/ ~18.22 ETH) has been appended to the end of the memo. This tells THORChain to revert the transaction if the transacted amount is more than 500 basis points less than what the expected_amount_out returns.

Affiliate Fees

Specify affiliate_address and affiliate_bps to skim a percentage of the expected_amount_out.​​

{
  "expected_amount_out": "1851200268",
  "fees": {
    "affiliate": "1854014",
    "asset": "ETH.ETH",
    "outbound": "960000"
  },
  "inbound_address": "bc1qqtemwlu9ju3ts3da5l82qejnzdl3xfs3lcl4wg",
  "inbound_confirmation_blocks": 1,
  "inbound_confirmation_seconds": 600,
  "memo": "=:ETH.ETH:0x3021c479f7f8c9f1d5c7d8523ba5e22c0bcb5430::wr:10",
  "outbound_delay_blocks": 178,
  "outbound_delay_seconds": 2670,
  "slippage_bps": 168
}

Notice how wr:10 has been appended to the end of the memo. This instructs MAYAChain to skim 10 basis points from the swap. The user should still expect to receive the expected_amount_out, meaning the affiliate fee has already been subtracted from this number.

For more information on affiliate fees: Fees

Streaming Swaps

Specify streaming_interval to define the interval in which streaming swaps are swapped.​​

TBA

Notice how approx_streaming_savings shows the savings by using streaming swaps. total_swap_seconds also shows the amount of time the swap will take.

Error Handling

TBA

Support

Developers experiencing issues with these APIs can go to the Maya Protocol Discord server (LINK) for assistance. Interface developers should subscribe to the #interface-alerts channel for information pertinent to the endpoints and functionality discussed here.

Full quote swap endpoint specification can be found here: ​.

​If you'd prefer to calculate the swap yourself, see the section to understand what fees need to be accounted for in the output amount. Also, review the section to understand how to create the swap memos.

Learn more about how to construct inbound transactions for each chain type here: ​

can be used to break up the trade to reduce slip fees.

https://mayanode.mayachain.info/mayachain/doc
Fees
Transaction Memos
Sending Transactions
https://mayanode.mayachain.info/mayachain/quote/swap?amount=100000000&from_asset=BTC.BTC&to_asset=ETH.ETH&destination=0x3021c479f7f8c9f1d5c7d8523ba5e22c0bcb5430&tolerance_bps=500
https://mayanode.mayachain.info/mayachain/quote/swap?amount=100000000&from_asset=BTC.BTC&to_asset=ETH.ETH&destination=0x3021c479f7f8c9f1d5c7d8523ba5e22c0bcb5430&affiliate=wr&affiliate_bps=10
​Streaming Swaps
Memos
Connecting to MAYAChain.
asset notation.
​Pools Endpoint
https://mayanode.mayachain.info/mayachain/quote/swap?from_asset=BTC.BTC&to_asset=ETH.ETH&amount=100000000&destination=0x86d526d6624AbC0178cF7296cD538Ecc080A95F1
price limits
affiliate fees