1.1.1 • Published 10 days ago

@paraspell/xcm-router v1.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
10 days ago

Introduction

XCM Router (Codenamed SpellRouter) is ParaSpell's latest innovation, that allows for seamless XCM Exchanges. Send one token type and receive a different one you choose on the destination chain cross-chain. All within one call and three signatures. This seamless operation allows for a better user experience, limiting the possibility of user errors. The router currently implements the 9 largest Parachain DEXes and is easy to extend as the number of DEXes with public SDKs increases. Together, there are 579 asset pools to choose from, making XCM Router the largest liquidity bridging tool in the ecosystem.

Exchanges implemented:

  • Acala / 36 Pools available
  • Basilisk / 15 Pools available
  • BifrostKusama / 66 Pools available / Requires native token for swaps
  • BifrostPolkadot / 45 Pools available / Requires native token for swaps
  • HydraDX / 210 Pools available
  • Interlay / 10 Pools available / Requires native token for swaps
  • Karura / 136 Pools available
  • Kintsugi / 6 Pools available / Requires native token for swaps
  • Mangata / 55 Pools available / Requires native token for swaps

NOTE: Some exchanges require native tokens in order to proceed with swaps.

Installation

Install dependencies

//PNPM temporarily unsupported
npm install || yarn add @polkadot/api @polkadot/types @polkadot/api-base @polkadot/apps-config @polkadot/util

Install XCM Router

//PNPM temporarily unsupported
npm install || yarn add @paraspell/xcm-router

Importing package to your project

Builder pattern:

import { RouterBuilder } from '@paraspell/xcm-router'

Other patterns:

// ESM
import * as xcmRouter from '@paraspell/xcm-router'

//Multiple import options
import { transfer, 
         TransactionType, 
         TTransferOptions, 
         TTxProgressInfo } from '@paraspell/xcm-router'

//As Polkadot moves to ESM only, our Router also moves to ESM only. CJS is not supported anymore.

Implementation

Builder pattern with automatic exchange selection (Based on best price)

If you wish to have an exchange chain selection based on the best price outcome, you can opt for an automatic exchange selection method. This method can be selected by not using the .exchange() parameter in the call. The router will then automatically select the best exchange chain for you based on the best price outcome.

await RouterBuilder
       .from('Polkadot')   //Origin Parachain/Relay chain
       .to('Astar')    //Destination Parachain/Relay chain
       .currencyFrom('DOT')    // Currency to send
       .currencyTo('ASTR')    // Currency to receive
       .amount('1000000')  // Amount to send
       .slippagePct('1')   // Max slipppage percentage
       .injectorAddress(injectorAddress)   //Injector address
       .recipientAddress(recipientAddress) //Recipient address
       .signer(injector.signer)    //Signer
       .onStatusChange((status: TTxProgressInfo) => {  //This is how we subscribe to calls that need signing
         console.log(status.hashes);   //Transaction hashes
         console.log(status.status);   //Transaction statuses
         console.log(status.type);    //Transaction types
       })
       .buildAndSend()

Builder pattern with manual exchange selection

If you wish to select your exchange chain manually, you can provide the additional .exchange() parameter to the call. The router will then use the exchange chain of your choice.

await RouterBuilder
       .from('Polkadot')   //Origin Parachain/Relay chain
       .exchange('HydraDDex')    //Exchange Parachain
       .to('Astar')    //Destination Parachain/Relay chain
       .currencyFrom('DOT')    // Currency to send
       .currencyTo('ASTR')    // Currency to receive
       .amount('1000000')  // Amount to send
       .slippagePct('1')   // Max slipppage percentage
       .injectorAddress(selectedAccount.address)   //Injector address
       .recipientAddress(recipientAddress) //Recipient address
       .signer(injector.signer)    //Signer
       .onStatusChange((status: TTxProgressInfo) => {  //This is how we subscribe to calls that need signing
         console.log(status.hashes);   //Transaction hashes
         console.log(status.status);   //Transaction statuses
         console.log(status.type);    //Transaction types
       })
       .buildAndSend()

Function pattern with automatic exchange selection (Based on best price)

If you wish to have an exchange chain selection based on the best price outcome, you can opt for an automatic exchange selection method. This method can be selected by not using exchange: parameter in the call. The router will then automatically select the best exchange chain for you based on the best price outcome.

await transfer({
        from: 'Polkadot', //Origin Parachain/Relay chain
        to: 'Interlay', //Destination Parachain/Relay chain
        currencyFrom: 'DOT', // Currency to send
        currencyTo: 'INTR', // Currency to receive
        amount: '100000', // Amount to send
        slippagePct: '1', // Max slipppage percentage
        injectorAddress: selectedAccount.address, //Injector address
        address: recipientAddress, //Recipient address
        signer: injector.signer,  //Signer
        onStatusChange: (status: TTxProgressInfo) => {  //This is how we subscribe to calls that need signing
          console.log(status.hashes);   //Transaction hashes
          console.log(status.status);   //Transaction statuses
          console.log(status.type);     //Transaction types
        },
});

Function pattern with manual exchange selection

If you wish to select your exchange chain manually, you can provide the additional exchange: parameter to the call. The router will then use the exchange chain of your choice.

await transfer({
        from: 'Polkadot', //Origin Parachain/Relay chain
        exchange: 'AcalaDex', //Exchange Parachain
        to: 'Interlay', //Destination Parachain/Relay chain
        currencyFrom: 'DOT', // Currency to send
        currencyTo: 'INTR', // Currency to receive
        amount: '100000', // Amount to send
        slippagePct: '1', // Max slipppage percentage
        injectorAddress: selectedAccount.address, //Injector address
        address: recipientAddress, //Recipient address
        signer: injector.signer,  //Signer
        onStatusChange: (status: TTxProgressInfo) => {  //This is how we subscribe to calls that need signing
          console.log(status.hashes);   //Transaction hashes
          console.log(status.status);   //Transaction statuses
          console.log(status.type);     //Transaction types
        },
});

List of DEX chains, assets, and Parachains supported by XCM Router

DEXCan send to/receive fromSupported assetsNotes
Acala DEXPolkadot Relay, Astar, HydraDX, Interlay, Moonbeam, Parallel, AssetHubPolkadot, Unique networkACA, DOT, aSEED, USDCet, UNQ, IBTC, INTR, lcDOT, LDOTFees are paid by either ACA or DOT
Karura DEXKusama Relay, Altair, Basilisk, BifrostKusama, Calamari, Crab, Parallel Heiko, Kintsugi, Moonriver, Quartz, Crust Shadow, Shiden, AssetHubKusamaBNC, USDCet, RMRK, ARIS, AIR, QTZ, CSM, USDT, KAR, KBTC, KINT, KSM, aSEED, LKSM, PHA, tKSM, TAIFees are paid by either KAR or KSM
HydraDX DEXPolkadot Relay, Acala, Interlay, AssetHubPolkadot, Zeitgeist, Astar, Centrifuge, BifrostPolkadotUSDT, HDX, WETH, GLMR, IBTC, BNC, WBTC, vDOT, DAI, CFG, DOT, DAI, ZTG, WBTC, INTR, ASTR, LRNA, USDCChain automatically gives you native asset to pay for fees.
Basilisk DEXKusama Relay, Karura, AssetHubKusama, Tinkernet, RobonomicsBSX, USDT, aSEED, XRT, KSM, TNKRChain automatically gives you native asset to pay for fees.
Mangata DEXKusama Relay, AssetHubKusama, BifrostPolkadot, Moonriver, Turing, ImbueMGX, IMBU, TUR, ZLK, BNC, USDT, RMRK, MOVR, vsKSM, KSM, vKSMChain requires native MGX asset to pay for fees.
Bifrost Kusama DEXKusama Relay, AssetHubKusama, Karura, Moonriver, Kintsugi, MangataBNC, vBNC, vsKSM, vKSM, USDT, aSEED, KAR, ZLK, RMRK, KBTC, MOVR, vMOVRChain requires native BNC asset for fees.
Bifrost Polkadot DEXPolkadot Relay, AssetHubPolkadot, Moonbeam, Astar, InterlayBNC, vDOT, vsDOT, USDT, FIL, vFIL, ASTR, vASTR, GLMR, vGLMR, MANTA, vMANTAChain requires native BNC asset for fees.
Interlay DEXPolkadot Relay, Acala, Astar, Parallel, PolkadotAssetHub, HydraDX, BifrostPolkadotINTR, DOT, IBTC, USDT, VDOTChain requires native INTR asset for fees.
Kintsugi DEXKusama Relay, Karura, KusamaAssetHub, Parallel Heiko, BifrostKusamaKINT,KSM,KBTC,USDTChain requires native KINT asset for fees.

💻 Testing

  • Run compilation using yarn compile

  • Run linting test using yarn lint

  • Run unit tests using yarn test

  • Run integration tests using yarn test:integration

XCM Router can be tested in Playground.

License

Made with 💛 by ParaSpell✨

Published under MIT License.

Support