diff --git a/.github/pull-request-template.md b/.github/pull-request-template.md index deb59ab4..a6c07ace 100644 --- a/.github/pull-request-template.md +++ b/.github/pull-request-template.md @@ -4,7 +4,7 @@ Please explain the changes this PR addresses here. ### Checklist -- [ ] If this requires a documentation change, I have created a PR in [moonbeam-docs](https://github.com/moonbeam-foundation/moonbeam-docs) repository. +- [ ] If this requires a documentation change, I have created a PR that updates the `mkdocs/docs` directory - [ ] If this requires it, I have updated the Readme - [ ] If necessary, I have updated the examples - [ ] I have verified if I need to create/update unit tests diff --git a/.gitignore b/.gitignore index 7137c53b..5750d4b3 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,6 @@ dist # IntelliJ Idea .idea + +# Docs - Site directory +mkdocs/site \ No newline at end of file diff --git a/mkdocs/README.md b/mkdocs/README.md new file mode 100644 index 00000000..d6dd9c8c --- /dev/null +++ b/mkdocs/README.md @@ -0,0 +1,39 @@ +# Documentation for the XCM SDK + +## Publishing New Versions + +To add the very first version, you’ll need to push the latest changes to the `main` branch and then in your terminal run: + +```bash +mike deploy --push INSERT_NEW_VERSION latest +``` + +Where the version should be formatted like `v0`, as we only need to worry about maintaining documentation for major version changes. + +For additional versions, you'll need to run: + +```bash +mike deploy --push --update-aliases INSERT_NEW_VERSION latest +``` + +## Publishing Changes to a Specific Version + +To make minor updates to the current version or an older version, you’ll need to make the changes to the `main` branch and then in your terminal run: + +```bash +mike deploy --push INSERT_VERSION +``` + +If using the latest version, you can cross-reference the live website, or the `gh-pages` branch to get the version that needs to be provided to the above command. + +Please note that modifying a previous version is possible, but should not be done unless necessary. It will require you to roll back changes to that version. For example, if the current version is v2 and you make a change and want to apply it to v0, the rest of the pages must be on v0, otherwise, the v2 changes will be applied to v0. + +## Setting a Default Version + +After setting the `latest` alias as the default version, and when publishing a new version, always update the alias to point to the latest version by running: + +```bash +mike set-default --push latest +``` + +When publishing a new version, this will create a redirect in the root of the documentation to the version associated with the alias. So, `https://moonbeam-foundation.github.io/xcm-sdk/` will redirect to `https://moonbeam-foundation.github.io/xcm-sdk/latest/`. diff --git a/mkdocs/docs/.pages b/mkdocs/docs/.pages new file mode 100644 index 00000000..2ad76777 --- /dev/null +++ b/mkdocs/docs/.pages @@ -0,0 +1,5 @@ +nav: + - 'index.md' + - 'SDK Reference': 'reference' + - 'Using the XCM SDK': 'example-usage.md' + - 'Contribute': 'contribute.md' diff --git a/mkdocs/docs/.snippets/text/endpoint-setup.md b/mkdocs/docs/.snippets/text/endpoint-setup.md new file mode 100644 index 00000000..6a9ecd95 --- /dev/null +++ b/mkdocs/docs/.snippets/text/endpoint-setup.md @@ -0,0 +1 @@ +To configure your project for Moonbeam or Moonriver, you will need to have your own endpoint and API key, which you can get from one of the supported [Endpoint Providers](https://docs.moonbeam.network/builders/get-started/endpoints){target=\_blank}. diff --git a/mkdocs/docs/.snippets/text/third-party-content.md b/mkdocs/docs/.snippets/text/third-party-content.md new file mode 100644 index 00000000..182579fd --- /dev/null +++ b/mkdocs/docs/.snippets/text/third-party-content.md @@ -0,0 +1,3 @@ +
+The information presented herein has been provided by third parties and is made available solely for general information purposes. Moonbeam does not endorse any project listed and described on the Moonbeam Doc Website (https://docs.moonbeam.network/). Moonbeam Foundation does not warrant the accuracy, completeness or usefulness of this information. Any reliance you place on such information is strictly at your own risk. Moonbeam Foundation disclaims all liability and responsibility arising from any reliance placed on this information by you or by anyone who may be informed of any of its contents. All statements and/or opinions expressed in these materials are solely the responsibility of the person or entity providing those materials and do not necessarily represent the opinion of Moonbeam Foundation. The information should not be construed as professional or financial advice of any kind. Advice from a suitably qualified professional should always be sought in relation to any particular matter or circumstance. The information herein may link to or integrate with other websites operated or content provided by third parties, and such other websites may link to this website. Moonbeam Foundation has no control over any such other websites or their content and will have no liability arising out of or related to such websites or their content. The existence of any such link does not constitute an endorsement of such websites, the content of the websites, or the operators of the websites. These links are being provided to you only as a convenience and you release and hold Moonbeam Foundation harmless from any and all liability arising from your use of this information or the information provided by any third-party website or service. +
diff --git a/mkdocs/docs/contribute.md b/mkdocs/docs/contribute.md new file mode 100644 index 00000000..d52c00ea --- /dev/null +++ b/mkdocs/docs/contribute.md @@ -0,0 +1,370 @@ +--- +title: Add Assets or Chains to the XCM SDK +description: Learn how to add an asset or chain within the Polkadot or Kusama ecosystems to the Moonbeam XCM SDK. +template: tutorial.html +--- + +# Contribute to the XCM SDK + +## Get Started + +To contribute to the XCM SDK, you'll first need to clone the GitHub repository: + +```bash +git clone git@github.com:moonbeam-foundation/xcm-sdk.git +``` + +Then, install dependencies: + +```bash +npm install +``` + +## Add an Asset + +The first step in adding support for a new asset is to define the asset in the [assets configuration file](https://github.com/moonbeam-foundation/xcm-sdk/blob/main/packages/config/src/assets.ts){target=\_blank}. At this stage, assets are not bound to any chain, you are only creating a representation of the asset. + +Follow these steps: + +1. Open the `xcm-sdk/packages/config/src/assets.ts` file +2. Create a new variable for your asset. You'll need to create an [Asset Object](./reference/interfaces.md#the-asset-object), providing the `key` and `originSymbol` of the asset + + ```ts + export const INSERT_ASSET_NAME = new Asset({ + key: 'INSERT_KEY', + originSymbol: 'INSERT_ORIGIN_SYMBOL', + }); + ``` + + For example, this is the configuration used for USDT: + + ```ts + export const usdt = new Asset({ + key: 'usdt', + originSymbol: 'USDT', + }); + ``` + +3. Add your asset to the `assetsList` array at the end of the file + +!!! note + Assets are listed in alphabetical order. Please make sure you follow this order when adding new assets. + +## Add a Chain + +The next step to support an asset integration is to add chain information for the chains in which your asset can be sent to and from to the [chains configuration file](https://github.com/moonbeam-foundation/xcm-sdk/blob/main/packages/config/src/chains.ts){target=\_blank}. + +To add a chain, take the following steps: + +1. Open the `xcm-sdk/packages/config/src/chains.ts` file +2. Add your asset to the list of imported assets from the assets configuration file (`./assets.ts`) +3. Create a new variable for each chain if an entry doesn't already exist. You'll need to create a [Chain Object](./reference/interfaces.md#the-chain-object), providing metadata related to the chain + + === "Parachain" + + ```ts + new Parachain({ + assetsData: [], // Optional - In the next step, you'll add assets here + ecosystem: Ecosystem.INSERT_ECOSYSTEM_TYPE, // Optional + genesisHash: 'INSERT_GENESIS_HASH', + isTestChain: INSERT_BOOLEAN, // Optional + key: 'INSERT_KEY', + name: 'INSERT_NAME', + parachainId: INSERT_PARACHAIN_ID, + ss58Format: INSERT_SS58_FORMAT, + usesChainDecimals: INSERT_BOOLEAN, // Optional + ws: 'INSERT_WSS_ENDPOINT', + }) + ``` + + === "EVM Parachain" + + ```ts + new EvmParachain({ + assetsData: [], // Optional - In the next step, you'll add assets here + ecosystem: Ecosystem.INSERT_ECOSYSTEM_TYPE, // Optional + genesisHash: 'INSERT_GENESIS_HASH', + id: INSERT_EVM_CHAIN_ID, + isTestChain: INSERT_BOOLEAN, // Optional + key: 'INSERT_KEY', + name: 'INSERT_NAME', + nativeCurrency: { + decimals: INSERT_ASSET_DECIMALS, + name: 'INSERT_ASSET_NAME', + symbol: 'INSERT_ASSET_SYMBOL', + }, + parachainId: INSERT_PARACHAIN_ID, + rpc: 'INSERT_RPC_ENDPOINT', + ss58Format: INSERT_SS58_FORMAT, + usesChainDecimals: INSERT_BOOLEAN, // Optional + ws: 'INSERT_WSS_ENDPOINT', + }) + ``` + + For example, this is the configuration for the Polkadot Asset Hub: + + ```ts + export const polkadotAssetHub = new Parachain({ + assetsData: [ ... ], + ecosystem: Ecosystem.Polkadot, + genesisHash: + '0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f', + key: 'Polkadot-asset-hub', + name: 'Polkadot Asset Hub', + parachainId: 1000, + ss58Format: 42, + ws: 'wss://polkadot-asset-hub-rpc.polkadot.io', + }); + ``` + +4. Add the newly created chain to the `chainsList` array at the end of the file + +!!! note + Chains are listed in alphabetical order. Please make sure you follow this order when adding new chains. + +Now that you've added the chain, you can continue to the next section to add the assets that this chain supports. + +## Configure a Chain's Assets + +To designate a chain as a destination or source chain for an asset, you must specify the asset within the `assetsData` array of the chain's configuration. This array outlines the supported assets on the chain, and the asset information within it determines how the asset is identified or targeted on that specific chain. For example, when adding a chain's native asset, you'll need to define how the chain sees its own asset, and when adding the asset to a destination chain, you'll need to define how the destination chain sees the asset. + +To enable an asset to move between chains, follow these steps to configure the source and destination chains of an asset: + +1. In the `assetsData` array of the source chain, you'll need to create a [Chain Asset Data Object](./reference/interfaces.md#the-chain-assets-data-object) for the asset, specifying how the asset is seen on that chain + + ```ts + { + asset: INSERT_IMPORTED_ASSET, // The asset created in the previous section + balanceId: INSERT_CHAIN_ASSET_ID, // (Optional) The balance ID of the asset + decimals: INSERT_ASSET_DECIMALS // (Optional) The decimals of the asset + id: INSERT_CHAIN_ASSET_ID, // (Optional) Location of the asset on the chain. Different for every chain + metadata: INSERT_CHAIN_ASSET_ID // (Optional) The metadata of the asset + min: INSERT_MIN // (Optional) The minimum amount of the asset that is required to be left in the account + minId: INSERT_CHAIN_ASSET_ID // (Optional) The minimum ID of the asset + palletInstance: INSERT_PALLET_INSTANCE // (Optional) The pallet instance the asset belongs to + } + ``` + + For example, this is the configuration for USDT on the Polkadot Asset Hub: + + ```ts + export const polkadotAssetHub = new Parachain({ + assetsData: [ + { + asset: usdt, + id: 1984, // The asset ID for USDT + palletInstance: 50, // The index of the Assets pallet (where USDT lives) + }, + ], + ... + }); + ``` + +2. In the destination chain's `assetsData` array, create a [Chain Asset Data Object](./reference/interfaces.md#the-chain-assets-data-object) that defines the asset as seen on the destination chain. This will be different than the source chain's configurations, as every chain manages assets differently + + For example, to add support for USDT on Moonbeam, Moonbeam's chain configuration needs to include the configuration for USDT: + + ```ts + export const moonbeam = new EvmParachain({ + assetsData: [ + ... + { + asset: usdt, + id: '311091173110107856861649819128533077277', // The asset ID of USDT on Moonbeam + }, + ... + ] + ... + }); + ``` + +The integration isn't complete yet; you'll need to define the methods used for cross-chain transfers for any new chains added. This will be covered in the following section. + +## Configure a Chain's Extrinsics + +In this step, you have to create or update the configuration files of the chains between which you can transfer the asset. These files define the asset being transferred, the destination chain, information associated to fees, and builder functions. These builders define the pallets and methods necessary to achieve the specific goals of each type. They are as follows: + +- **Minimum Asset Builder** - builds a query to retrieve the minimum amount of an asset required to be left in an account +- **Balance Builder** - builds a query to retrieve the balance of an asset for a given account +- **Contract Builder** - builds the contract call for the cross-chain transfer. This is specific to EVM chains that use contracts to interact with Substrate pallets for cross-chain transfers, such as [Moonbeam's X-Tokens precompiled contract](https://docs.moonbeam.network/builders/interoperability/xcm/xc20/send-xc20s/xtokens-precompile/){target=\_blank} +- **Extrinsic Builder** - builds the extrinsic for the cross-chain transfer +- **Fee Builder** - builds the query to retrieve the fee for the execution of the cross-chain transfer + +You will need to know which pallet and method each chain is using for its XCM transactions and for fetching asset balances, and make sure that said pallets and methods are already available in the [xcm-builder package](https://github.com/moonbeam-foundation/xcm-sdk/tree/main/packages/builder){target=\_blank}. + +If they aren't available, feel free to open a PR or [submit an issue on GitHub](https://github.com/moonbeam-foundation/xcm-sdk/issues/new){target=\_blank}. + +Assuming that all of the required pallets and methods are already supported, you can create the configuration file for the source chain: + +1. In the `xcm-sdk/packages/config/src/configs/` directory, add a TypeScript file for the new chain +2. Use the following snippet as a starting point for adding the chain configuration: + + ```ts + import { INSERT_REQUIRED_BUILDERS } from '@moonbeam-network/xcm-builder'; + import { INSERT_REQUIRED_ASSETS } from '../assets'; + import { INSERT_SOURCE_CHAIN, INSERT_DESTINATION_CHAIN } from '../chains'; + import { AssetConfig } from '../types/AssetConfig'; + import { ChainConfig } from '../types/ChainConfig'; + + // The chain config name should be formatted as: 'chainName' + 'Config' + export const INSERT_CHAIN_CONFIG_NAME = new ChainConfig({ + assets: [], // In the next step, you'll add asset configs here + chain: INSERT_SOURCE_CHAIN, // The source chain + }); + ``` + +3. As seen in the above example, an `assets` array contains the chain's asset configurations. The asset configuration defines the asset being transferred, the destination chain, information associated with fees, and the builder functions. The builder functions must be used to build the queries or calls as if they were being executed from this chain. + + You'll need to create an Asset Config object for each asset, for example: + + ```ts + new AssetConfig({ + asset: INSERT_ASSET, + balance: INSERT_BALANCE_BUILDER, + contract: INSERT_CONTRACT_BUILDER, // Optional + destination: INSERT_DESTINATION_CHAIN, + destinationFee: { + amount: INSERT_FEE_BUILDER, + asset: INSERT_ASSET, + balance: INSERT_BALANCE_BUILDER, + }, + extrinsic: INSERT_EXTRINSIC_BUILDER, // Optional + fee: { + // Optional + asset: INSERT_ASSET, + balance: INSERT_BALANCE_BUILDER, + xcmDeliveryFeeAmount: INSERT_FEE_AMOUNT, // Optional + }, + min: INSERT_MIN_ASSET_BUILDER, // Optional + }); + ``` + +4. Add the newly created chain configurations to the `chainsConfigList` in the `xcm-sdk/blob/main/packages/config/src/configs/index.ts` file + +!!! note + Chain configurations are listed in alphabetical order. Please follow this order when adding new chain configurations. + +For example, to add support to transfer USDT from the Polkadot Asset Hub to Moonbeam, the Polkadot Asset Hub configuration file is as follows: + +```ts +import { + AssetMinBuilder, + BalanceBuilder, + ExtrinsicBuilder, + FeeBuilder, +} from '@moonbeam-network/xcm-builder'; +import { usdt } from '../assets'; +import { moonbeam, polkadotAssetHub } from '../chains'; +import { AssetConfig } from '../types/AssetConfig'; +import { ChainConfig } from '../types/ChainConfig'; + +const xcmDeliveryFeeAmount = 0.036; + +export const polkadotAssetHubConfig = new ChainConfig({ + assets: [ + ...new AssetConfig({ + asset: usdt, + balance: BalanceBuilder().substrate().assets().account(), + destination: moonbeam, + destinationFee: { + amount: FeeBuilder().assetManager().assetTypeUnitsPerSecond(), + asset: usdt, + balance: BalanceBuilder().substrate().assets().account(), + }, + extrinsic: ExtrinsicBuilder() + .polkadotXcm() + .limitedReserveTransferAssets() + .X2(), + fee: { + asset: dot, + balance: BalanceBuilder().substrate().system().account(), + xcmDeliveryFeeAmount, + }, + min: AssetMinBuilder().assets().asset(), + }), + ], + chain: polkadotAssetHub, +}); +``` + +You're almost there. With this configuration, you can send the asset one-way from the configured chain to the asset's specified destination chain. To send the asset back to the original source chain, you must update (or create) the specified destination chain's configurations. Considering the above example, the Moonbeam configuration file would need to be updated to transfer USDT from Moonbeam back to the Polkadot Asset Hub. + +You must take the same steps in the destination chain's configuration file. If a configuration file does not exist, you must create one. Otherwise, update the chain's configuration file to include the asset configuration, as step three outlines. + +For example, enabling USDT transfers from Moonbeam back to the Polkadot Asset Hub requires the following Moonbeam chain configuration: + +```ts +import { BalanceBuilder, ContractBuilder } from '@moonbeam-network/xcm-builder'; +import { + ... + usdt, +} from '../assets'; +import { + ... + polkadotAssetHub, +} from '../chains'; +import { AssetConfig } from '../types/AssetConfig'; +import { ChainConfig } from '../types/ChainConfig'; + +export const moonbeamConfig = new ChainConfig({ + assets: [ + ... + new AssetConfig({ + asset: usdt, + balance: BalanceBuilder().substrate().assets().account(), + contract: ContractBuilder().Xtokens().transfer(), + destination: polkadotAssetHub, + destinationFee: { + amount: 0.7, + asset: usdt, + balance: BalanceBuilder().substrate().assets().account(), + }, + fee: { + asset: glmr, + balance: BalanceBuilder().substrate().system().account(), + }, + }), + ], + chain: moonbeam, +}); +``` + +And that's it! You now know how to add new assets and chains and configure the chains that an asset can be sent to and from. To ensure that you've properly set everything up, read on to the next section. + +## Test New Configurations + +The SDK is configured to work for most parachains in the Polkadot ecosystem. However, any given chain might have a different or particular way of requesting a specific piece of information, for example, if it uses unconventional pallets or different methods for existing pallets. + +You can use the following queries to ensure that the new configurations have been properly set up. + +- `assetRegistry.assetMetadatas` - From here, we extract the `decimals` and the `minBalance` for + `aSEED`: + + ```js + { + name: aUSD SEED + symbol: aSEED + decimals: 12 + minimalBalance: 100,0 + } + ``` + +- `assets.metadata` - Here, we get the `decimals` for `DOT` + + ```js + { + deposit: 0; + name: xcDOT; + symbol: xcDOT; + decimals: 10; + isFrozen: false; + } + ``` + +- `balances.existentialDeposit` - This is the standard way of querying the existential deposit for most chains + + ```js + 100000000000; + ``` + +Most cases are considered already, but for newly integrated chains, this data might be queried by a different pallet or function. You can check if the pallet is supported in the [Polkadot Service file](https://github.com/moonbeam-foundation/xcm-sdk/blob/main/packages/sdk/src/polkadot/PolkadotService.ts). diff --git a/mkdocs/docs/example-usage.md b/mkdocs/docs/example-usage.md new file mode 100644 index 00000000..0aa16c5d --- /dev/null +++ b/mkdocs/docs/example-usage.md @@ -0,0 +1,892 @@ +--- +title: Using the XCM SDK v2 +description: Use the Moonbeam XCM SDK to easily transfer cross-chain assets between parachains or between a parachain and relay chain within the Polkadot/Kusama ecosystems. +template: tutorial.html +--- + +# Using the Moonbeam XCM SDK + +## Introduction {: #introduction } + +The Moonbeam XCM SDK enables developers to easily transfer assets between chains, either between parachains or between a parachain and the relay chain, within the Polkadot/Kusama ecosystem. With the SDK, you don't need to worry about determining the multilocation of the origin or destination assets or which extrinsics are used on which networks to send XCM transfers. + +The XCM SDK offers helper functions that provide a very simple interface for executing XCM transfers between chains in the Polkadot/Kusama ecosystem. In addition, the XCM config package allows any parachain project to [add their information](./contribute.md) in a standard way, so the XCM SDK can immediately support them. + +For an overview of the available methods and interfaces in the Moonbeam XCM SDK, please refer to the [Reference](./reference/interfaces.md){target=\_blank} page. + +This guide shows how to transfer DOT from Polkadot to Moonbeam. + +## Install the XCM SDK {: #install-the-xcm-sdk } + +To get started with the Moonbeam XCM SDK, you'll need first to install the SDK: + +```bash +npm install @moonbeam-network/xcm-sdk +``` + +You'll also need to install a few additional dependencies that you'll use to interact with the SDK in this guide. You'll need the Polkadot.js API to create a Polkadot signer: + +```bash +npm install @polkadot/api @polkadot/util-crypto +``` + +You'll also need an Ethereum signer if you're interacting with an Ethereum-compatible chain like Moonbeam. This guide will cover using Ethers.js and viem. You'll need to install whichever library you want to use: + +=== "Ethers.js" + + ```bash + npm install ethers@6 + ``` + +=== "viem" + + ```bash + npm install viem@2 + ``` + +## Create Signers {: #create-signers } + +When transferring assets between chains, you'll need signers in place to sign the transactions. If you're interacting with an Ethereum-compatible chain that uses standard Ethereum-style H160 addresses, such as Moonbeam, you'll need to have an Ethereum signer, which can be an [Ethers.js](https://docs.ethers.org/v5/){target=\_blank} signer or a [viem Wallet Client](https://viem.sh/docs/clients/wallet.html){target=\_blank}. To interact with the relay chain or other parachains, you'll need a [Polkadot](https://polkadot.js.org/docs/api/){target=\_blank} signer. + +You can pass, for example, a [browser extension wallet as a signer into Ethers](https://docs.ethers.org/v5/getting-started/#getting-started--connecting){target=\_blank} or [viem](https://viem.sh/docs/clients/wallet.html#json-rpc-accounts){target=\_blank}, such as MetaMask. Similarly, with Polkadot, you can [pass a compatible wallet to the signer using the `@polkadot/extension-dapp` library](https://polkadot.js.org/docs/extension/){target=\_blank}. + +To create an EVM signer and a Polkadot signer, you can refer to the following sections. + +!!! warning + **Never store your private key or mnemonic in a JavaScript or TypeScript file.** + +### Create an EVM Signer {: #create-a-evm-signer } + +To create an Ethers signer, you can use the following code snippet: + +```js +import { ethers } from 'ethers'; + +const privateKey = 'INSERT_PRIVATE_KEY'; +const provider = new ethers.WebSocketProvider('INSERT_WS_ENDPOINT', { + chainId: INSERT_CHAIN_ID, + name: 'INSERT_CHAIN_NAME', +}); +const evmSigner = new ethers.Wallet(privateKey, provider); +``` + +For Moonbeam specifically, you can use the following configurations: + +=== "Moonbeam" + + ```js + import { ethers } from 'ethers'; + + const privateKey = 'INSERT_PRIVATE_KEY'; + const provider = new ethers.WebSocketProvider( + '{{ networks.moonbeam.wss_url }}', + { + chainId: {{ networks.moonbeam.chain_id }}, + name: 'moonbeam', + } + ); + const evmSigner = new ethers.Wallet(privateKey, provider); + ``` + +=== "Moonriver" + + ```js + import { ethers } from 'ethers'; + + const privateKey = 'INSERT_PRIVATE_KEY'; + const provider = new ethers.WebSocketProvider( + '{{ networks.moonriver.wss_url }}', + { + chainId: {{ networks.moonriver.chain_id }}, + name: 'moonriver', + } + ); + const evmSigner = new ethers.Wallet(privateKey, provider); + ``` + +=== "Moonbase Alpha" + + ```js + import { ethers } from 'ethers'; + + const privateKey = 'INSERT_PRIVATE_KEY'; + const provider = new ethers.WebSocketProvider( + '{{ networks.moonbase.wss_url }}', + { + chainId: {{ networks.moonbase.chain_id }}, + name: 'moonbase', + } + ); + const evmSigner = new ethers.Wallet(privateKey, provider); + ``` + +Alternatively, you can create a viem Wallet Client to pass as an EVM signer: + +=== "Moonbeam" + + ```js + import { createWalletClient, http } from 'viem'; + import { privateKeyToAccount } from 'viem/accounts' + import { moonbeam } from 'viem/chains'; + + const privateKey = 'INSERT_PRIVATE_KEY'; + const account = privateKeyToAccount(privateKey); + + const evmSigner = createWalletClient({ + account, + chain: moonbeam, + transport: http(), + }); + ``` + +=== "Moonriver" + + ```js + import { createWalletClient, http } from 'viem'; + import { privateKeyToAccount } from 'viem/accounts' + import { moonriver } from 'viem/chains'; + + const privateKey = 'INSERT_PRIVATE_KEY'; + const account = privateKeyToAccount(privateKey); + + const evmSigner = createWalletClient({ + account, + chain: moonriver, + transport: http(), + }); + ``` + +=== "Moonbase Alpha" + + ```js + import { createWalletClient, http } from 'viem'; + import { privateKeyToAccount } from 'viem/accounts' + import { moonbaseAlpha } from 'viem/chains'; + + const privateKey = 'INSERT_PRIVATE_KEY'; + const account = privateKeyToAccount(privateKey); + + const evmSigner = createWalletClient({ + account, + chain: moonbaseAlpha, + transport: http(), + }); + ``` + +If you want to pass in a browser extension wallet to viem, you can use the following code: + +=== "Moonbeam" + + ```js + import { createWalletClient, custom } from 'viem'; + import { moonbeam } from 'viem/chains'; + + const evmSigner = createWalletClient({ + chain: moonbeam, + transport: custom(window.ethereum), + }); + ``` + +=== "Moonriver" + + ```js + import { createWalletClient, custom } from 'viem'; + import { moonriver } from 'viem/chains'; + + const evmSigner = createWalletClient({ + chain: moonriver, + transport: custom(window.ethereum), + }); + ``` + +=== "Moonbase Alpha" + + ```js + import { createWalletClient, custom } from 'viem'; + import { moonbaseAlpha } from 'viem/chains'; + + const evmSigner = createWalletClient({ + chain: moonbaseAlpha, + transport: custom(window.ethereum), + }); + ``` + +!!! note + --8<-- 'text/endpoint-setup.md' + +### Create a Polkadot Signer {: #create-a-polkadot-signer } + +In this example, you can use a [Polkadot.js Keyring](https://polkadot.js.org/docs/api/start/keyring/){target=\_blank} to sign transactions. Please note that this approach is not recommended for production applications. + +```js +import { Keyring } from '@polkadot/api'; +import { cryptoWaitReady } from '@polkadot/util-crypto'; + +const privateKey = 'INSERT_PRIVATE_KEY'; + +const createPolkadotSigner = async () => { + await cryptoWaitReady(); + const keyring = new Keyring({ + ss58Format: 'INSERT_SS58_FORMAT', + type: 'sr25519', + }); + const pair = keyring.createFromUri(privateKey); +}; + +createPolkadotSigner(); +``` + +!!! note + In the above `INSERT_PRIVATE_KEY` field, you can specify a seed phrase instead of a private key. + +## Get Asset and Chain Data {: #asset-chain-data } + +You can use any of the following code examples to retrieve information on the supported assets and the chains that support these assets. + +### Get List of Supported Assets {: #get-list-of-supported-assets } + +To get a list of all of the assets supported by the XCM SDK, you can instantiate the XCM SDK and call the [`assets`](./reference/methods.md#the-assets-method) function. + +```js +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const assets = sdkInstance.assets(); + +console.log('The supported assets are as follows:'); +assets.assets.forEach((asset) => { + console.log(`- ${asset.originSymbol}`); +}); +``` + +### Get List of Supported Assets by Ecosystem {: #get-supported-assets-by-ecosystem } + +To get a list of the supported assets for a particular [ecosystem](./reference/interfaces.md#the-ecosystem-type), you can pass in the ecosystem name: `polkadot`, `kusama`, or `alphanet-relay`. For example, the following snippet will get all of the Polkadot assets supported: + +```js +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const assets = sdkInstance.assets('polkadot'); + +console.log( + 'The supported assets within the Polkadot ecosystem are as follows:', +); +assets.assets.forEach((asset) => { + console.log(`- ${asset.originSymbol}`); +}); +``` + +### Get List of Supported Chains by Asset {: #get-list-of-supported-assets-by-chain } + +To get a list of the supported [source](./reference/methods.md#the-source-method) and [destination](./reference/methods.md#the-destination-method) chains for a given asset, you can use the following code snippet, which logs the supported chains by asset for all of the supported assets in the Polkadot ecosystem: + +```js +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const assets = sdkInstance.assets('polkadot'); + +assets.assets.forEach((asset) => { + const { sourceChains, source } = assets.asset(asset); + console.log(`You can send ${asset.originSymbol}...`); + if (sourceChains.length > 1) { + sourceChains.forEach((sourceChain) => { + const { destinationChains } = source(sourceChain); + if (destinationChains.length > 0) { + destinationChains.forEach((destination) => { + console.log(`- From ${source.name} to ${destination.name}`); + }); + } + }); + } +}); +``` + +## Build XCM Transfer Data {: #build-xcm-transfer-data } + +To transfer an asset from one chain to another, you'll need to first build the transfer data, which defines the asset to be transferred, the source chain and address, the destination chain and address, and the associated signer for the transaction. Building the transfer data is the first step; in the next section, you'll learn how to use it to actually transfer the asset. + +To get started, you'll use the [`Sdk`](./reference/methods.md#initialize-the-sdk) function, which will expose two methods for building the XCM transfer data: [`assets`](./reference/methods.md#the-assets-method) and [`getTransferData`](./reference/methods.md#the-get-transfer-data-method). + +```js +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +``` + +You can choose either method, as both will return the data necessary to initiate an asset transfer between the source and destination chains. Using `assets` will provide additional data along the way, including the list of supported assets and, once an asset is selected, the supported source and destination chains that can send and receive it. + +The process for using `assets` to build the transfer data is as follows: + +1. Call the `assets` function and optionally pass in the ecosystem that you want to retrieve a list of assets for or that the asset you want to transfer belongs to. The available ecosystems are: `polkadot`, `kusama`, and `alphanet-relay`. For example: + + ```js + const { assets, asset } = sdkInstance.assets('polkadot'); + ``` + + This will return a list of the supported assets and the [`asset`](./reference/methods.md#the-asset-method) function that can be used to define the asset to be transferred + +2. Call the `asset` function and pass in the key or asset object (which includes the key and the origin symbol) to define the asset to be transferred. For example: + + ```js + // Using the key + const { sourceChains, source } = asset('dot'); + ``` + + This will return a list of the supported source chains and the [`source`](./reference/methods.md#the-source-method) function, which is used to define the source chain to transfer the asset from + +3. Call the `source` function and pass in the key or the chain object (which includes the key, name, and chain type). For example: + + ```js + // Using the key + const { destinationChains, destination } = source('polkadot'); + ``` + + This will return a list of the supported destination chains where there is an open XCM channel from the source chain for the given asset and the [`destination`](./reference/methods.md#the-destination-method) function, which is used to define the destination chain to transfer the asset to + +4. Call the `destination` function and pass in the key or the chain object (which includes the key, name, and chain type). For example: + + ```js + // Using the key + const { accounts } = destination('moonbeam'); + ``` + + This will return the [`accounts`](./reference/methods.md#the-accounts-method) function, which is used to define the source and destination addresses and the associated signers for each address + +The asset and chain objects are managed within the `@moonbeam-network/xcm-config` package. You do not need to directly interact with this package as the SDK exposes this data, but there you can find the list of [assets](https://github.com/moonbeam-foundation/xcm-sdk/blob/main/packages/config/src/assets.ts){target=\_blank} and [chain data](https://github.com/moonbeam-foundation/xcm-sdk/blob/main/packages/config/src/chains.ts){target=\_blank}. + +An example of the steps described above to build the transfer data to transfer DOT from the Polkadot relay chain to Moonbeam is as follows: + +```js +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); + +const fromPolkadot = async () => { + const { assets, asset } = sdkInstance.assets(); + console.log( + `The supported assets are: ${assets.map((asset) => asset.originSymbol)}`, + ); + + const { sourceChains, source } = asset('dot'); + console.log( + `The supported source chains are: ${sourceChains.map( + (chain) => chain.name, + )}`, + ); + + const { destinationChains, destination } = source('polkadot'); + console.log( + `The supported destination chains are: ${destinationChains.map( + (chain) => chain.name, + )}`, + ); + + const { accounts } = destination('moonbeam'); + const data = await accounts( + pair.address, + evmSigner.address, // If using viem, use evmSigner.account.address + { + evmSigner, + polkadotSigner: pair, + }, + ); +}; + +fromPolkadot(); +``` + +!!! note + For more information on each of the `Sdk().assets()` builder functions, including the parameters and returned data, please refer to the [XCM SDK Reference](./reference/methods.md#build-the-transfer-data-starting-with-assets){target=\_blank}. + +If you don't need any of the asset or chain information, you can use the `getTransferData` function: + +```js +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); + +const fromPolkadot = async () => { + const data = await sdkInstance.getTransferData({ + destinationAddress: evmSigner.address, // If using viem, use evmSigner.account.address + destinationKeyOrChain: 'moonbeam', + keyOrAsset: 'dot', + polkadotSigner: pair, + sourceAddress: pair.address, + sourceKeyOrChain: 'polkadot', + evmSigner, + }); +}; + +fromPolkadot(); +``` + +!!! note + For more information on the `Sdk().getTransferData()` function, including the parameters and returned data, please refer to the [XCM SDK Reference](./reference/methods.md#the-get-transfer-data-method){target=\_blank}. + +As previously mentioned, the same output will be generated regardless of which method you use to build the transfer data. + +??? code "Example response" + + ```js + // Send DOT from Polkadot to Moonbeam + // data + { + destination: { + balance: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: l { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: [Map], + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network' + }, + existentialDeposit: e { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + fee: e { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + }, + min: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + getEstimate: [Function: getEstimate], + isSwapPossible: true, + max: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: e { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + }, + source: { + balance: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: m { + ecosystem: 'polkadot', + isTestChain: false, + key: 'polkadot', + name: 'Polkadot', + type: 'parachain', + assetsData: Map(0) {}, + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + parachainId: 0, + ss58Format: 0, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://rpc.polkadot.io' + }, + destinationFeeBalance: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + existentialDeposit: e { + key: 'dot', + originSymbol: 'DOT', + amount: 10000000000n, + decimals: 10, + symbol: 'DOT' + }, + fee: e { + key: 'dot', + originSymbol: 'DOT', + amount: 169328990n, + decimals: 10, + symbol: 'DOT' + }, + feeBalance: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + max: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + swap: [AsyncFunction: swap], + transfer: [AsyncFunction: transfer] + } + ``` + +As you may have noticed in the example response, the transfer data contains information on the asset, source, and destination chain. In addition, a few functions have been exposed: + +- [`swap`](./reference/methods.md#the-swap-method) - returns the transfer data necessary to swap the asset from the destination chain back to the source chain +- [`transfer`](./reference/methods.md#the-transfer-method) - transfers a given amount of the asset from the source chain to the destination chain +- [`getEstimate`](./reference/methods.md#the-get-estimate-method) - returns an estimated amount of the asset that will be received on the destination chain, less any destination fees + +## Transfer an Asset {: #transfer-an-asset } + +Now that you've built the transfer data, you can transfer the asset from the source chain to the destination chain. To do so, you can use the [`transfer`](./reference/methods.md#the-transfer-method) function, but first, you'll need to specify an amount to send. You can specify the amount in integer or decimal format. For example, if you wanted to send 0.1 DOT, you could use `1000000000n` or `'0.1'`. You can use [asset conversion methods](./reference/methods.md#asset-utilities){target=\_blank}, like [`toDecimal`](./reference/methods.md#the-to-decimal-method) to convert the asset to decimal format. + +For this example, you can transfer twice the minimum amount required of DOT: + +```js +... + +const amount = data.min.toDecimal() * 2; +console.log(`Sending from ${data.source.chain.name} amount: ${amount}`); +const hash = await data.transfer(amount); +console.log(`${data.source.chain.name} tx hash: ${hash}`); +``` + +As the above snippet shows, the `transfer` function returns a transaction hash on the source chain. + +!!! note + For more information on the parameters and returned data for `transfer`, please refer to the [XCM SDK Reference](./reference/methods.md#the-transfer-method){target=\_blank}. + +## Swap an Asset {: #swap-an-asset} + +To swap an asset, you can use the same transfer data and call `data.swap()` to switch the source and destination chain information. You can call the `transfer` function to execute the swap from there. + +```js +... + +const swapData = await data.swap(); +const amount = swapData.min.toDecimal() * 2; +console.log(`Sending from ${swapData.source.chain.name} amount: ${amount}`); +const hash = await swapData.transfer(amount); +console.log(`${swapData.source.chain.name} tx hash: ${hash}`); +``` + +The `swap` function returns the transfer data with the original source chain and destination chains swapped. Using the previous example of sending DOT from Polkadot to Moonbeam, the swap transfer data would send DOT from Moonbeam to Polkadot. + +??? code "Example response" + + ```js + // swapData + { + destination: { + balance: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: m { + ecosystem: 'polkadot', + isTestChain: false, + key: 'polkadot', + name: 'Polkadot', + type: 'parachain', + assetsData: Map(0) {}, + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + parachainId: 0, + ss58Format: 0, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://rpc.polkadot.io' + }, + existentialDeposit: e { + key: 'dot', + originSymbol: 'DOT', + amount: 10000000000n, + decimals: 10, + symbol: 'DOT' + }, + fee: e { + key: 'dot', + originSymbol: 'DOT', + amount: 169328990n, + decimals: 10, + symbol: 'DOT' + }, + feeBalance: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + max: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + getEstimate: [Function: getEstimate], + isSwapPossible: true, + max: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: e { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + }, + source: { + balance: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: l { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: [Map], + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network' + }, + destinationFeeBalance: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + existentialDeposit: e { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + fee: e { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + }, + min: e { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + swap: [AsyncFunction: swap], + transfer: [AsyncFunction: transfer] + } + ``` + +!!! note + For more information on the parameters and returned data for `swap`, please refer to the [XCM SDK Reference](./reference/methods.md#the-swap-method){target=\_blank}. + +## Get an Estimate of the Asset to Be Received on the Destination Chain {: #get-estimate } + +When you send an XCM message, you typically pay fees on the destination chain to execute the XCM instructions. Before you transfer the asset, you can use the [`getEstimate`](./reference/methods.md#the-get-estimate-method) function to calculate an estimated amount of the asset that will be received on the destination chain minus any fees. + +The `getEstimate` function is tied to a specific transfer request as it is based on the asset being transferred and the destination chain fees, so you'll need to create the [transfer data](#build-xcm-transfer-data) first. + +You must provide the amount to be transferred to the `getEstimate` function. In the following example, you'll get the estimated amount of DOT that will be received on Moonbeam when 0.1 DOT is transferred. You can specify the amount in integer (`1000000000n`) or decimal (`'0.1'`) format. + +```js +... + +const amount = '0.1'; +const estimatedAmount = data.getEstimate(amount); + +console.log( + `The estimated amount of ${ + data.source.balance.originSymbol + } to be received on ${ + data.destination.chain.name + } is: ${estimatedAmount.toDecimal()} ${data.destination.balance.symbol}` +); +``` + +The `getEstimate` function returns the estimated amount along with information on the asset being transferred. + +??? code "Example response" + + ```js + // estimatedAmount + { + key: 'dot', + originSymbol: 'DOT', + amount: 966931217n, + decimals: 10, + symbol: 'DOT' + } + ``` + +!!! note + For more information on the parameters and returned data for `getEstimate`, please refer to the [XCM SDK Reference](./reference/methods.md#the-get-estimate-method){target=\_blank}. + +## Get Transfer Minimum and Maximum Amounts {: #transfer-min-max-amounts } + +You can use [transfer data](#build-xcm-transfer-data) to retrieve the minimum and maximum amount of an asset that can be transferred. To do so, you'll access the `min` and `max` properties of the asset being transferred: + +=== "Minimum" + + ```js + ... + + const amount = data.min.toDecimal(); + const symbol = data.min.originSymbol; + + console.log(`You can send min: ${amount} ${symbol}`); + ``` + +=== "Maximum" + + ```js + ... + + const amount = data.max.toDecimal(); + const symbol = data.max.originSymbol; + + console.log(`You can send max: ${amount} ${symbol}`); + ``` + +The `min` and `max` properties return the minimum and maximum amount of the asset that can be transferred, along with information on the asset. If the source account does not hold a balance of the chosen asset, the `data.max` amount will be `0n`. + +??? code "Example response" + + ```js + // data.min + { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + } + // data.max + { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + ``` + +!!! note + For more information on assets and asset amounts, please refer to the [XCM SDK Reference](./reference/interfaces.md#assets){target=\_blank}. + +## Get Transfer Fees {: #get-transfer-fees } + +The [transfer data](#build-xcm-transfer-data) provides information on transfer fees for the source and destination chains. You can retrieve the fees using the following snippet: + +```js +... +const sourceChain = data.source.chain.name; +const sourceFee = data.source.fee; + +const destinationChain = data.destination.chain.name; +const destinationFee = data.destination.fee; + +console.log( + `You will pay ${sourceFee.toDecimal()} ${ + sourceFee.symbol + } fee on ${ + sourceChain + } and ${destinationFee.toDecimal()} ${ + destinationFee.symbol + } fee on ${destinationChain}.` +); +``` + +The `fee` property returns the fees to be paid along with information on the asset. + +??? code "Example response" + + ```js + // sourceFee + { + key: 'dot', + originSymbol: 'DOT', + amount: 169328990n, + decimals: 10, + symbol: 'DOT' + } + // destinationFee + { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + } + ``` + +!!! note + For more information on assets and asset amounts, including fees, please refer to the [XCM SDK Reference](./reference/interfaces.md#assets){target=\_blank}. + +--8<-- 'text/third-party-content.md' diff --git a/mkdocs/docs/index.md b/mkdocs/docs/index.md new file mode 100644 index 00000000..bfe4eaa2 --- /dev/null +++ b/mkdocs/docs/index.md @@ -0,0 +1,8 @@ +--- +title: Home +description: Discover comprehensive guides and examples for integrating your dApp with the Moonbeam Foundation's XCM SDK, enabling seamless cross-chain communication. +template: home.html +hide: + - navigation + - toc +--- diff --git a/mkdocs/docs/reference/.pages b/mkdocs/docs/reference/.pages new file mode 100644 index 00000000..2d90e78b --- /dev/null +++ b/mkdocs/docs/reference/.pages @@ -0,0 +1,3 @@ +nav: + - 'Types and Interfaces': 'interfaces.md' + - 'Methods': 'methods.md' diff --git a/mkdocs/docs/reference/interfaces.md b/mkdocs/docs/reference/interfaces.md new file mode 100644 index 00000000..19fd5509 --- /dev/null +++ b/mkdocs/docs/reference/interfaces.md @@ -0,0 +1,839 @@ +--- +title: XCM SDK Reference - Interfaces - v2 +description: A reference for the types and interfaces in the Moonbeam XCM SDK that can be used to send XCM transfers between chains within the Polkadot/Kusama ecosystems. +--- + +# Moonbeam XCM SDK Reference: Types and Interfaces + +The XCM SDK is based on defining an asset to transfer, then the source chain to send the asset from, and the destination chain to send the asset to, which, together, build the transfer data. + +The following sections cover the types and interfaces you'll encounter when working with assets, chains, and transfer data. + +## Assets + +### The Asset Object + +
+
+Defines an asset's key and symbol used on the asset's origin chain. + +**Attributes** + +- `key` ++"string"++ - Identifies an asset +- `originSymbol` ++"string"++ - The symbol of the asset on the asset's origin chain + +
+ +```js title="Example" +// The Asset object +// For GLMR on Moonbeam +{ + key: 'glmr', + originSymbol: 'GLMR' +} +``` + +
+ +--- + +### The Asset Amount Object + +
+
+Defines properties related to an asset, including `Asset` properties, the decimals and symbol of the asset, and the amount an associated source or destination address has of the asset. + +!!! note + A few utility methods are available for working with the `AssetAmount` class that converts the amount to various formats. Please refer to the [Methods for Asset Conversions](./methods.md#asset-utilities) section. + +**Attributes** + +- `key` ++"string"++ - Identifies an asset +- `originSymbol` ++"string"++ - The symbol of the asset on the asset's origin chain +- `amount` ++"bigint"++ - Identifies a particular amount of the asset (i.e., balance, minimum, maximum, etc.) +- `decimals` ++"number"++ - The number of decimals the asset has +- `symbol` ++"string"++ - The symbol of the asset + +
+ +```js title="Example" +// The Asset Amount object +// For GLMR on Moonbeam +{ + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' +} +``` + +
+ +--- + +## Chains + +### The Ecosystem Type + +
+
+Specifies the relay chain ecosystem a chain belongs to. Can be any of the following ecosystems as defined by the `Ecosystem` enum: + +```ts +enum Ecosystem { + Polkadot = 'polkadot', + Kusama = 'kusama', + AlphanetRelay = 'alphanet-relay', +} +``` + +
+ +```js title="Example" +// The Ecosystem Type +{ + ecosystem: 'polkadot', +} +``` + +
+ +--- + +### The Chain Type + +
+
+Specifies what kind of parachain a chain is. + +```ts +enum ChainType { + 'Parachain' = 'parachain', + 'EvmParachain' = 'evm-parachain', +} +``` + +
+ +```js title="Example" +// The Chain Type +{ + type: 'evm-parachain', +} +``` + +
+ +--- + +### The Chain Asset ID Type + +
+
+A generic type used to specify the location of the asset on the chain, which is different on every chain. + +```ts +type ChainAssetId = string | number | bigint | { [key: string]: ChainAssetId }; +``` + +
+ +```js title="Example" +// The Chain Asset ID Type +// To target DOT on Moonbeam +{ + id: '42259045809535163221576417993425387648', +} +``` + +
+ +--- + +### The Chain Object + +
+
+Defines properties related to a chain and is used to define the source and destination chains. If a chain is an EVM parachain, there are a couple of additional properties. + +**Attributes** + +- `ecosystem` ++"Ecosystem"++ [:material-link-variant:](#the-ecosystem-type) - Identifies the ecosystem the chain belongs to: `polkadot`, `kusama`, or `alphanet-relay` +- `isTestChain` ++"boolean"++ - Whether the chain is a testnet +- `key` ++"string"++ - Identifies a chain +- `name` ++"string"++ - The name of the chain +- `type` ++"ChainType"++ [:material-link-variant:](#the-chain-type) - The type of the chain: `parachain` or `evm-parachain` +- `assetsData` ++"Map"++ [:material-link-variant:](#the-chain-assets-data-object) - A list of the assets that the chain supports +- `genesisHash` ++"string"++ - The hash of the genesis block +- `parachainId` ++"number"++ - The ID of the parachain (not the EVM chain ID) +- `ss58Format` ++"number"++ - The [ss58 format](https://polkadot.js.org/docs/keyring/start/ss58/){target=\_blank} for the chain +- `usesChainDecimals` ++"boolean"++ - A flag indicating if the chain uses its own decimals in balance queries for all the assets. defaults to `false` +- `ws` ++"string"++ - The WebSocket endpoint for the chain +- `id` ++"number"++ - **For EVM parachains only** - The chain ID +- `rpc` ++"string"++ - **For EVM parachains only** - The HTTP RPC endpoint for the chain + +
+ +```js title="Example" +// The Chain object +// Moonbeam's Chain Object +{ + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: [Map], + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network' +} +``` + +
+ +--- + +### The Chain Assets Data Object + +
+
+Defines the information needed to target the asset on the chain. This is mostly for internal usage to accommodate how chains store their assets. The SDK defaults to the asset ID if certain properties do not apply to the given chain. + +**Attributes** + +- `asset` ++"Asset"++ - The asset's key and origin symbol +- `balanceId` ++"ChainAssetId"++ [:material-link-variant:](#the-chain-asset-id-type) - The balance ID of the asset. Defaults to the asset ID +- `decimals` ++"number"++ - The number of decimals the asset has +- `id` ++"ChainAssetId"++ [:material-link-variant:](#the-chain-asset-id-type) - The asset ID +- `metadataId` ++"ChainAssetId"++ [:material-link-variant:](#the-chain-asset-id-type) - The metadata ID of the asset +- `minId` ++"ChainAssetId"++ [:material-link-variant:](#the-chain-asset-id-type) - The minimum ID of the asset +- `palletInstance` ++"number"++ - The number of the pallet instance the asset belongs to +- `min` ++"number"++ - The minimum amount of the asset that is required to be left in the account for it to be active. Similar to the existential deposit, except it is for non-native assets + +
+ +```js title="Example" +// The Chain Assets Data object +// To target DOT on Moonbeam +{ + asset: dot, + id: '42259045809535163221576417993425387648', +} +``` + +
+ +--- + +## Transfer Data + +### The Transfer Data Object + +
+
+Defines the complete transfer data for transferring an asset, including asset, source chain, and destination chain information, as well as a few helper functions for the transfer process. + +**Attributes** + +- `destination` ++"DestinationChainTransferData"++ [:material-link-variant:](#the-destination-chain-transfer-data-object) - The assembled destination chain and address information +- `getEstimate` ++"function"++ [:material-link-variant:](./methods.md#the-get-estimate-method) - Gets the estimated amount of the asset that the destination address will receive +- `isSwapPossible` ++"boolean"++ - Returns whether or not the swap is possible +- `max` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The maximum amount of the asset that _can_ be transferred +- `min` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The minimum amount of the asset that _can_ be transferred +- `source` ++"SourceChainTransferData"++ [:material-link-variant:](#the-source-chain-transfer-data-object) - The assembled source chain and address information +- `swap` ++"function"++ [:material-link-variant:](./methods.md#the-swap-method) - Swaps the destination and the source chains and returns the swapped transfer data +- `transfer` ++"function"++ [:material-link-variant:](./methods.md#the-transfer-method) - Transfers a given amount of the asset from the source chain to the destination chain + +
+ +```js title="Example" +// The Transfer Data object +// For sending DOT from Polkadot to Moonbeam +{ + destination: { + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: [Map], + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network' + }, + existentialDeposit: { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + getEstimate: [Function: getEstimate], + isSwapPossible: true, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + }, + source: { + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'polkadot', + name: 'Polkadot', + type: 'parachain', + assetsData: Map(0) {}, + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + parachainId: 0, + ss58Format: 0, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://rpc.polkadot.io' + }, + destinationFeeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + existentialDeposit: { + key: 'dot', + originSymbol: 'DOT', + amount: 10000000000n, + decimals: 10, + symbol: 'DOT' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 169328990n, + decimals: 10, + symbol: 'DOT' + }, + feeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + swap: [AsyncFunction: swap], + transfer: [AsyncFunction: transfer] +} +``` + +
+ +--- + +### The Destination Chain Transfer Data Object + +
+
+Defines the destination chain data for the transfer. + +**Attributes** + +- `balance` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The balance of the asset being transferred on the destination address +- `chain` ++"AnyChain"++ [:material-link-variant:](#the-chain-object) - The destination chain information +- `existentialDeposit` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The existential deposit for the asset being transferred on the destination chain +- `fee` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The amount of fees for the asset being transferred on the destination chain +- `min` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The minimum amount of the asset to transfer. This is different than `TransferData.min`, as this dictates the minimum amount that should be received on the destination chain + +
+ +```js title="Example" +// The Destination Chain Transfer Data object +// For sending DOT from Polkadot to Moonbeam +{ + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: [Map], + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network' + }, + existentialDeposit: { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 33068783n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } +} +``` + +
+ +--- + +### The Source Chain Transfer Data Object + +
+
+Defines the source chain data for the transfer. + +**Attributes** + +- `balance` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The balance of the asset being transferred for the source address +- `chain` ++"AnyChain"++ [:material-link-variant:](#the-chain-object) - The source chain information +- `destinationFeeBalance` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The balance of the asset used to pay for fees in the destination chain +- `existentialDeposit` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The existential deposit for the asset being transferred on the source chain +- `fee` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The amount of fees for the asset being transferred on the source chain +- `feeBalance` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The balance of the asset being transferred on the source chain +- `min` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The minimum amount of the asset that should be kept on the source chain, taking into consideration the `existentialDeposit` and `fee` for the transfer +- `max` ++"AssetAmount"++ [:material-link-variant:](#the-asset-amount-object) - The maximum amount of the asset that _can_ be transferred + +
+ +```js title="Example" +// The Source Chain Transfer Data object +// For sending DOT from Polkadot to Moonbeam +{ + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'polkadot', + name: 'Polkadot', + type: 'parachain', + assetsData: Map(0) {}, + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + parachainId: 0, + ss58Format: 0, + usesChainDecimals: false, + weight: 1000000000, + ws: 'wss://rpc.polkadot.io' + }, + destinationFeeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + existentialDeposit: { + key: 'dot', + originSymbol: 'DOT', + amount: 10000000000n, + decimals: 10, + symbol: 'DOT' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 169328990n, + decimals: 10, + symbol: 'DOT' + }, + feeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } +} +``` + +
+ +--- + +## SDK Options + +### The SDK Options Object + +
+
+Defines options to initialize the SDK, including EVM and Polkadot signers and a custom configuration service. + +**Attributes** + +- `evmSigner` ++"EvmSigner"++ [:material-link-variant:](#the-evm-signer-type) - The signer for transfers involving EVM chains +- `polkadotSigner` ++"Signer | IKeyringPair"++ [:material-link-variant:](#the-polkadot-signer-type) - The signer for transfers involving non-EVM chains +- `configService` ++"IConfigService"++ [:material-link-variant:](#the-config-service-object) - The custom configuration service + +
+ +```js title="Example" +// The Sdk Options object +{ + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + configService: { + assets: INSERT_ASSETS_MAPPING, + chains: INSERT_CHAINS_MAPPING, + chainsConfig: INSERT_CHAIN_CONFIG_MAPPING, + } +} +``` + +
+ +--- + +## Signers + +### The EVM Signer Type + +
+
+Defines the EVM signer for transfers involving EVM chains. Can be an [Ethers signer](https://docs.ethers.org/v6/api/wallet/#Wallet) or [viem Wallet Client](https://viem.sh/docs/clients/wallet). + +
+ +```js title="Example" +import { ethers } from 'ethers'; + +const provider = new ethers.WebSocketProvider( + 'wss://wss.api.moonbeam.network', + { + chainId: 1284, + name: 'moonbeam', + }, +); +const evmSigner = new ethers.Wallet('INSERT_PRIVATE_KEY', provider); +``` + +
+ +--- + +### The Polkadot Signer Type + +
+
+Defines the signer for transfers involving non-EVM chains. Can be a [signer](https://github.com/polkadot-js/api/blob/v11.0.2/packages/types/src/types/extrinsic.ts#L135) or a [Keyring pair](https://polkadot.js.org/docs/keyring/start/create). + +
+ +```js title="Example" +import { Keyring } from '@polkadot/api'; +import { cryptoWaitReady } from '@polkadot/util-crypto'; + +await cryptoWaitReady(); +const keyring = new Keyring({ type: 'sr25519' }); +const pair = keyring.addFromUri('INSERT_MNEMONIC'); +``` + +
+ +--- + +## Configurations + +The interfaces in this section are primarily used for defining your own custom configuration source and adding or updating new asset and chain configurations to the XCM SDK. To learn how to add new configurations, please refer to the [Contribute to the XCM SDK](./../contribute.md) guide. + +### The Config Service Object + +
+
+Defines a custom configuration service. This overrides the asset and chain configurations in the [xcm-config package](https://github.com/moonbeam-foundation/xcm-sdk/tree/main/packages/config){target=\_blank}, which is exposed by default by the SDK. + +**Attributes** + +- `assets` ++"Map"++ [:material-link-variant:](#the-asset-object) - A list of the supported assets mapping each asset key to its corresponding `Asset` object +- `chains` ++"Map"++ [:material-link-variant:](#the-chain-object) - A list of the supported assets mapping each chain key to its corresponding `Chain` object +- `chainsConfig` ++"Map"++ [:material-link-variant:](#the-chain-config-object) - A list of the supported chain configurations mapping each chain key to its corresponding `ChainConfig` object + +
+ +```js title="Example" +import { Keyring } from '@polkadot/api'; +import { cryptoWaitReady } from '@polkadot/util-crypto'; + +await cryptoWaitReady(); +const keyring = new Keyring({ type: 'sr25519' }); +const pair = keyring.addFromUri('INSERT_MNEMONIC'); +``` + +
+ +--- + +### The Chain Config Object + +
+
+Defines a chain's configurations, including information for each chain's supported assets. + +**Attributes** + +- `assets` ++"AssetConfig[]"++ [:material-link-variant:](#the-asset-object) - The supported asset configurations +- `chain` ++"AnyChain"++ [:material-link-variant:](#the-chain-object) - The chain's properties + +
+ +```js title="Example" +// The Chain Config object +// For configuring the Polkadot Asset Hub +{ + assets: [ + ...new AssetConfig({ + asset: usdt, + balance: BalanceBuilder().substrate().assets().account(), + destination: moonbeam, + destinationFee: { + amount: FeeBuilder().assetManager().assetTypeUnitsPerSecond(), + asset: usdt, + balance: BalanceBuilder().substrate().assets().account(), + }, + extrinsic: ExtrinsicBuilder() + .polkadotXcm() + .limitedReserveTransferAssets() + .X2(), + fee: { + asset: dot, + balance: BalanceBuilder().substrate().system().account(), + xcmDeliveryFeeAmount, + }, + min: AssetMinBuilder().assets().asset(), + }), + ... + ], + chain: new Parachain({ + assetsData: [ + { + asset: usdt, + id: 1984, + palletInstance: 50, + }, + ... + ], + ecosystem: Ecosystem.Polkadot, + genesisHash: + '0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f', + key: 'Polkadot-asset-hub', + name: 'Polkadot Asset Hub', + parachainId: 1000, + ss58Format: 42, + ws: 'wss://polkadot-asset-hub-rpc.polkadot.io', + }) +} +``` + +
+ +--- + +### The Asset Config Object + +
+
+Defines an asset's configurations for a source chain and includes information about the destination chain, associated fees for transferring the asset from the source chain to the destination chain, and builder functions that define how to transfer the asset. + +**Attributes** + +- `asset` ++"Asset"++ [:material-link-variant:](#the-asset-object) - The asset's key and origin symbol +- `balance` ++"BalanceConfigBuilder"++ [:material-link-variant:](https://github.com/moonbeam-foundation/xcm-sdk/blob/@moonbeam-network/xcm-sdk@2.2.3/packages/builder/src/balance/BalanceBuilder.interfaces.ts){target=\_blank} - The query builder for retrieving the balance of an asset for a given account +- `contract` ++"ContractConfigBuilder"++ [:material-link-variant:](https://github.com/moonbeam-foundation/xcm-sdk/blob/@moonbeam-network/xcm-sdk@2.2.3/packages/builder/src/contract/ContractBuilder.interfaces.ts){target=\_blank} - The contract call builder for a cross-chain transfer. This is specific to EVM chains that use contracts to interact with Substrate pallets for cross-chain transfers, such as [Moonbeam's X-Tokens precompiled contract](https://docs.moonbeam.network/builders/interoperability/xcm/xc20/send-xc20s/xtokens-precompile/) +- `destination` ++"AnyChain"++ [:material-link-variant:](#the-chain-object) - The destination chain information +- `destinationFee` ++"DestinationFeeConfig"++ - The destination chain fees +- `extrinsic` ++"ExtrinsicConfigBuilder"++ [:material-link-variant:](https://github.com/moonbeam-foundation/xcm-sdk/blob/@moonbeam-network/xcm-sdk@2.2.3/packages/builder/src/extrinsic/ExtrinsicBuilder.interfaces.ts){target=\_blank} - The extrinsic builder for a cross-chain transfer +- `fee` ++"FeeAssetConfig"++ [:material-link-variant:](#the-fee-asset-config) - The source chain fees +- `min` ++"AssetMinConfigBuilder"++ [:material-link-variant:](https://github.com/moonbeam-foundation/xcm-sdk/blob/@moonbeam-network/xcm-sdk@2.2.3/packages/builder/src/asset-min/AssetMinBuilder.interfaces.ts){target=\_blank} - The query builder for retrieving the minimum amount of an asset required to be left in an account + +
+ +```js title="Example" +// The Asset Config object +// For configuring USDT to be sent from +// the Polkadot Asset Hub to Moonbeam +{ + asset: usdt, + balance: BalanceBuilder().substrate().assets().account(), + destination: moonbeam, + destinationFee: { + amount: FeeBuilder().assetManager().assetTypeUnitsPerSecond(), + asset: usdt, + balance: BalanceBuilder().substrate().assets().account(), + }, + extrinsic: ExtrinsicBuilder() + .polkadotXcm() + .limitedReserveTransferAssets() + .X2(), + fee: { + asset: dot, + balance: BalanceBuilder().substrate().system().account(), + xcmDeliveryFeeAmount, + }, + min: AssetMinBuilder().assets().asset(), +} +``` + +
+ +--- + +### The Fee Asset Config + +
+
+Defines the fees for a particular asset on the source chain. + +**Attributes** + +- `asset` ++"Asset"++ [:material-link-variant:](#the-asset-object) - The asset's key and origin symbol +- `balance` ++"BalanceConfigBuilder"++ [:material-link-variant:](https://github.com/moonbeam-foundation/xcm-sdk/blob/@moonbeam-network/xcm-sdk@2.2.3/packages/builder/src/balance/BalanceBuilder.interfaces.ts){target=\_blank} - The query builder for retrieving the balance of an asset for a given account +- `xcmDeliveryFeeAmount` ++"number"++ - The delivery fee amount for the cross-chain transfer + +
+ +```js title="Example" +// The Fee Asset Config object +// For configuring USDT to be sent from +// the Polkadot Asset Hub to Moonbeam +{ + asset: dot, + balance: BalanceBuilder().substrate().system().account(), + xcmDeliveryFeeAmount: 0.036, +} +``` + +
+ +### The Destination Fee Asset Config + +
+
+Defines the fees for a particular asset on the destination chain. + +**Attributes** + +- `asset` ++"Asset"++ [:material-link-variant:](#the-asset-object) - The asset's key and origin symbol +- `balance` ++"BalanceConfigBuilder"++ [:material-link-variant:](https://github.com/moonbeam-foundation/xcm-sdk/blob/@moonbeam-network/xcm-sdk@2.2.3/packages/builder/src/balance/BalanceBuilder.interfaces.ts){target=\_blank} - The query builder for retrieving the balance of an asset for a given account +- `xcmDeliveryFeeAmount` ++"number"++ - The delivery fee amount for the cross-chain transfer +- `amount` ++"number | FeeConfigBuilder"++ [:material-link-variant:](https://github.com/moonbeam-foundation/xcm-sdk/blob/@moonbeam-network/xcm-sdk@2.2.3/packages/builder/src/fee/FeeBuilder.interfaces.ts){target=\_blank} - The fee amount or the query builder for retrieving the fee amount for the execution of the cross-chain transfer + +
+ +```js title="Example" +// The Desintation Fee Asset Config object +// For configuring USDT to be sent from +// the Polkadot Asset Hub to Moonbeam +{ + asset: dot, + balance: BalanceBuilder().substrate().system().account(), + amount: FeeBuilder().assetManager().assetTypeUnitsPerSecond(), +} +``` + +
diff --git a/mkdocs/docs/reference/methods.md b/mkdocs/docs/reference/methods.md new file mode 100644 index 00000000..c7c22936 --- /dev/null +++ b/mkdocs/docs/reference/methods.md @@ -0,0 +1,1365 @@ +--- +title: XCM SDK Reference - Methods - v2 +description: A reference for the available methods in the Moonbeam XCM SDK that can be used to send XCM transfers between chains within the Polkadot/Kusama ecosystems. +--- + +# Moonbeam XCM SDK Reference: Methods + +The SDK provides an API that enables you to get asset information for each supported asset, the source chains where a given asset can be sent from, and, given a source chain, the supported destination chains where the given asset can be sent. The SDK also includes helper methods related to transferring cross-chain assets, such as getting an estimated amount of the asset the destination account will receive, less any execution fees, and asset conversion methods based on the asset and the number of decimals it has. All of these enable you to transfer assets across chains easily and seamlessly. + +The following sections cover the available methods in the XCM SDK. + +## Initialize the SDK + +
+
+ +`Sdk()` - Exposes the methods of the XCM SDK. **Must be called first to access other SDK methods**. + +**Parameters** + +- `options?` ++"SdkOptions"++ - Allows you to specify an `evmSigner` or `polkadotSigner` + +**Returns** + +- `assets` ++"function"++ [:material-link-variant:](#the-assets-method) - Provides an entry point to building the data necessary to transfer an asset between a source chain and a destination chain +- `getTransferData` ++"function"++ [:material-link-variant:](#the-get-transfer-data-method) - Builds the data necessary to transfer an asset between a source chain and a destination chain + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +console.log(sdkInstance); +``` + +```js title="Response" +{ + assets: [Function: assets], + getTransferData: [AsyncFunction: getTransferData] +} +``` + +
+
+ +--- + +### The Get Transfer Data Method + +
+
+ +`getTransferData()` - Builds the data necessary to transfer an asset between a source chain and a destination chain. + +**Parameters** + +- `destinationAddress` ++"string"++ - The address of the receiving account on the destination chain +- `destinationKeyorChain` ++"string | AnyChain"++ [:material-link-variant:](./interfaces.md#the-chain-object) - The key or `Chain` data for the destination chain +- `evmSigner?` ++"EvmSigner"++ [:material-link-variant:](./interfaces.md#the-evm-signer-type) - The signer for Ethereum-compatible chains that use H160 Ethereum-style accounts. Can be an Ethers signer or a viem Wallet Client +- `keyOrAsset` ++"string | Asset"++ [:material-link-variant:](./interfaces.md#the-asset-object) - The key or `Asset` data for the asset being transferred +- `polkadotSigner?` ++"PolkadotSigner | IKeyringPair"++ [:material-link-variant:](./interfaces.md#the-polkadot-signer-type) - The Polkadot signer or Keyring pair +- `sourceAddress` ++"string"++ - The address of the sending account on the source chain +- `sourceKeyOrChain` ++"string | AnyChain"++ [:material-link-variant:](./interfaces.md#the-chain-object) - The key or `Chain` data for the source chain + +**Returns** + +- ++"Promise"++ - The assembled transfer data, which includes the following: + + - `destination` ++"DestinationChainTransferData"++ [:material-link-variant:](./interfaces.md#the-destination-chain-transfer-data-object) - The assembled destination chain and address information + - `getEstimate` ++"function"++ [:material-link-variant:](#the-get-estimate-method) - Gets the estimated amount of the asset that the destination address will receive + - `isSwapPossible` ++"boolean"++ - Returns whether or not the swap is possible + - `max` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - The maximum amount of the asset that can be transferred + - `min` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - The minimum amount of the asset that can be transferred + - `source` ++"SourceChainTransferData"++ [:material-link-variant:](./interfaces.md#the-source-chain-transfer-data-object) - The assembled source chain and address information + - `swap` ++"function"++ [:material-link-variant:](#the-swap-method) - Swaps the destination and the source chains and returns the swapped transfer data + - `transfer` ++"function"++ [:material-link-variant:](#the-transfer-method) - Transfers a given amount of the asset from the source chain to the destination chain + +
+
+ +```js title="Example Usage" +const transferData = await Sdk().getTransferData({ + destinationAddress: 'INSERT_MOONBEAM_ADDRESS', + destinationKeyOrChain: 'moonbeam', + evmSigner: INSERT_EVM_SIGNER, + keyOrAsset: 'dot', + polkadotSigner: INSERT_POLKADOT_SIGNER, + sourceAddress: 'INSERT_POLKADOT_ADDRESS', + sourceKeyOrChain: { + key: 'polkadot', + name: 'polkadot', + type: 'parachain', + }, +}); +console.log(transferData); +``` + +```js title="Response" +{ + destination: { + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: [Map], + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network' + }, + existentialDeposit: { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 20080321n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + getEstimate: [Function: getEstimate], + isSwapPossible: true, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 20080321n, + decimals: 10, + symbol: 'DOT' + }, + source: { + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'polkadot', + name: 'Polkadot', + type: 'parachain', + assetsData: Map(0) {}, + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + parachainId: 0, + ss58Format: 0, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://polkadot-rpc.dwellir.com' + }, + destinationFeeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + existentialDeposit: { + key: 'dot', + originSymbol: 'DOT', + amount: 10000000000n, + decimals: 10, + symbol: 'DOT' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 163633495n, + decimals: 10, + symbol: 'DOT' + }, + feeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + swap: [AsyncFunction: swap], + transfer: [AsyncFunction: transfer] +} +``` + +
+
+ +--- + +### The Assets Method + +
+
+ +`assets()` - Provides an entry point for building the data necessary to transfer an asset between a source chain and a destination chain. + +**Parameters** + +- `ecosystem?` ++"Ecosystem"++ - Specify the ecosystem for a set of assets: `polkadot`, `kusama`, or `alphanet-relay` + +**Returns** + +- `assets` ++"Asset[]"++ - A list of the supported assets +- `asset` ++"function"++ [:material-link-variant:](#the-asset-method) - Sets the asset to be transferred. Refer to the following section on how to continue to build the transfer data using the `asset` function + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const assets = sdkInstance.assets(); +console.log(assets); +``` + +```js title="Response" +{ + assets: [ + { key: 'aca', originSymbol: 'ACA' }, + { key: 'alan', originSymbol: 'ALAN' }, + { key: 'ampe', originSymbol: 'AMPE' }, + { key: 'aseed', originSymbol: 'aSEED' }, + { key: 'astr', originSymbol: 'ASTR' }, + ... + ], + asset: [Function: asset] +} +``` + +
+
+ +--- + +## Build the Transfer Data Starting with Assets + +When building transfer data with the `Sdk().assets()` function, you'll use multiple methods to build and send the underlying XCM message. + +### The Asset Method + +
+
+ +`asset()` - Sets the asset to be transferred. **Must call `assets()` first**. + +**Parameters** + +- `keyOrAsset` ++"string | Asset"++ [:material-link-variant:](./interfaces.md#the-asset-object) - The key or `Asset` data for the asset being transferred + +**Returns** + +- `sourceChains` ++"AnyChain[]"++ [:material-link-variant:](./interfaces.md#the-chain-object) - A list of the supported source chains for the specified asset +- `source` ++"function"++ [:material-link-variant:](#the-source-method) - Sets the source chain to transfer the asset from + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const sourceData = sdkInstance.assets().asset('dot'); +console.log(sourceData); +``` + +```js title="Response" +{ + sourceChains: [ + { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: { + 'aca' => { + asset: { key: 'aca', originSymbol: 'ACA' }, + id: '224821240862170613278369189818311486111' + }, + 'astr' => { + asset: { key: 'astr', originSymbol: 'ASTR' }, + id: '224077081838586484055667086558292981199' + }, + ... + }, + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network', + nativeCurrency: { + decimals: 18, + name: 'GLMR', + symbol: 'GLMR' + } + }, + { + ecosystem: 'polkadot', + isTestChain: false, + key: 'polkadot', + name: 'Polkadot', + type: 'parachain', + assetsData: Map(0) {}, + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + parachainId: 0, + ss58Format: 0, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://polkadot-rpc.dwellir.com' + } + ], + source: [Function: source] +} +``` + +
+
+ +--- + +### The Source Method + +
+
+ +`source()` - Sets the source chain from which to transfer the asset. **Must call `asset()` first**. + +**Parameters** + +- `keyOrChain` ++"string | AnyChain"++ [:material-link-variant:](./interfaces.md#the-chain-object) - The key or `Chain` data for the source chain + +**Returns** + +- `destinationChains` ++"AnyChain[]"++ [:material-link-variant:](./interfaces.md#the-chain-object) - A list of the supported destination chains for the specified asset and source chain +- `destination` ++"function"++ [:material-link-variant:](#the-destination-method) - Sets the destination chain to transfer the asset from + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const destinationData = sdkInstance.assets().asset('dot').source('polkadot'); +console.log(destinationData); +``` + +```js title="Response" +{ + destinationChains: [ + { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: { + 'aca' => { + asset: { key: 'aca', originSymbol: 'ACA' }, + id: '224821240862170613278369189818311486111' + }, + 'astr' => { + asset: { key: 'astr', originSymbol: 'ASTR' }, + id: '224077081838586484055667086558292981199' + }, + ... + }, + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network', + nativeCurrency: { + decimals: 18, + name: 'GLMR', + symbol: 'GLMR' + } + } + ], + destination: [Function: destination] +} +``` + +
+
+ +--- + +### The Destination Method + +
+
+ +`destination()` - Sets the destination chain to which to transfer the asset. **Must call `source()` first**. + +**Parameters** + +- `keyOrChain` ++"string | AnyChain"++ [:material-link-variant:](./interfaces.md#the-chain-object) - The key or `Chain` data for the destination chain + +**Returns** + +- `accounts` ++"function"++ [:material-link-variant:](#the-accounts-method) - Sets the source address, the destination address, and the signer(s) required for the transfer + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferDataWithoutAccounts = sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam'); +console.log(transferDataWithoutAccounts); +``` + +```js title="Response" +{ accounts: [AsyncFunction: accounts] } +``` + +
+
+ +--- + +### The Accounts Method + +
+
+ +`accounts()` - Sets the source address, the destination address, and the signer(s) required for the transfer. **Must call `destination()` first**. + +**Parameters** + +- `sourceAddress` ++"string"++ - The address of the sending account on the source chain +- `destinationAddress` ++"string"++ - The address of the receiving account on the destination chain +- `signers?` ++"Partial(signers)"++ [:material-link-variant:](./interfaces.md#signers) - The EVM or Polkadot signers required to sign transactions + +**Returns** + +- ++"Promise"++ - The assembled transfer data, which includes the following: + + - `destination` ++"DestinationChainTransferData"++ [:material-link-variant:](./interfaces.md#the-destination-chain-transfer-data-object) - The assembled destination chain and address information + - `getEstimate` ++"function"++ [:material-link-variant:](#the-get-estimate-method) - Gets the estimated amount of the asset that the destination address will receive + - `isSwapPossible` ++"boolean"++ - Returns whether or not the swap is possible + - `max` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - The maximum amount of the asset that can be transferred + - `min` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - The minimum amount of the asset that can be transferred + - `source` ++"SourceChainTransferData"++ [:material-link-variant:](./interfaces.md#the-source-chain-transfer-data-object) - The assembled source chain and address information + - `swap` ++"function"++ [:material-link-variant:](#the-swap-method) - Swaps the destination and the source chains and returns the swapped transfer data + - `transfer` ++"function"++ [:material-link-variant:](#the-transfer-method) - Transfers a given amount of the asset from the source chain to the destination chain + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); +console.log(transferData); +``` + +```js title="Response" +{ + destination: { + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: [Map], + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network' + }, + existentialDeposit: { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 20080321n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + getEstimate: [Function: getEstimate], + isSwapPossible: true, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 20080321n, + decimals: 10, + symbol: 'DOT' + }, + source: { + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'polkadot', + name: 'Polkadot', + type: 'parachain', + assetsData: Map(0) {}, + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + parachainId: 0, + ss58Format: 0, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://polkadot-rpc.dwellir.com' + }, + destinationFeeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + existentialDeposit: { + key: 'dot', + originSymbol: 'DOT', + amount: 10000000000n, + decimals: 10, + symbol: 'DOT' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 163633495n, + decimals: 10, + symbol: 'DOT' + }, + feeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + swap: [AsyncFunction: swap], + transfer: [AsyncFunction: transfer] +} +``` + +
+
+ +--- + +## Consume Transfer Data + +### The Swap Method + +
+
+ +`swap()` - Returns the transfer data necessary to swap the asset from the destination chain back to the source chain. + +**Parameters** + +None. + +**Returns** + +- ++"Promise"++ - If the swap is not possible, `undefined` is returned. If the swap is possible, the assembled transfer data is returned, which includes the following: + + - `destination` ++"DestinationChainTransferData"++ [:material-link-variant:](./interfaces.md#the-destination-chain-transfer-data-object) - The assembled destination chain and address information + - `getEstimate` ++"function"++ [:material-link-variant:](#the-get-estimate-method) - Gets the estimated amount of the asset that the destination address will receive + - `isSwapPossible` ++"boolean"++ - Returns whether or not the swap is possible + - `max` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - The maximum amount of the asset that can be transferred + - `min` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - The minimum amount of the asset that can be transferred + - `source` ++"SourceChainTransferData"++ [:material-link-variant:](./interfaces.md#the-source-chain-transfer-data-object) - The assembled source chain and address information + - `swap` ++"function"++ [:material-link-variant:](#the-swap-method) - Swaps the destination and the source chains and returns the swapped transfer data + - `transfer` ++"function"++ [:material-link-variant:](#the-transfer-method) - Transfers a given amount of the asset from the source chain to the destination chain + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const swapData = await transferData.swap(); +console.log(swapData); +``` + +```js title="Response" +{ + destination: { + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'polkadot', + name: 'Polkadot', + type: 'parachain', + assetsData: Map(0) {}, + genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + parachainId: 0, + ss58Format: 0, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://polkadot-rpc.dwellir.com' + }, + existentialDeposit: { + key: 'dot', + originSymbol: 'DOT', + amount: 10000000000n, + decimals: 10, + symbol: 'DOT' + }, + fee: { + key: 'dot', + originSymbol: 'DOT', + amount: 520000000n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + getEstimate: [Function: getEstimate], + isSwapPossible: true, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 10520000000n, + decimals: 10, + symbol: 'DOT' + }, + source: { + balance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + chain: { + ecosystem: 'polkadot', + isTestChain: false, + key: 'moonbeam', + name: 'Moonbeam', + type: 'evm-parachain', + assetsData: { + 'aca' => { + asset: { key: 'aca', originSymbol: 'ACA' }, + id: '224821240862170613278369189818311486111' + }, + 'astr' => { + asset: { key: 'astr', originSymbol: 'ASTR' }, + id: '224077081838586484055667086558292981199' + }, + ... + }, + genesisHash: '0xfe58ea77779b7abda7da4ec526d14db9b1e9cd40a217c34892af80a9b332b76d', + parachainId: 2004, + ss58Format: 1284, + usesChainDecimals: false, + weight: undefined, + ws: 'wss://wss.api.moonbeam.network', + id: 1284, + rpc: 'https://rpc.api.moonbeam.network', + nativeCurrency: { + decimals: 18, + name: 'GLMR', + symbol: 'GLMR' + } + }, + destinationFeeBalance: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + existentialDeposit: { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + fee: { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + feeBalance: { + key: 'glmr', + originSymbol: 'GLMR', + amount: 0n, + decimals: 18, + symbol: 'GLMR' + }, + max: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + }, + min: { + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' + } + }, + swap: [AsyncFunction: swap], + transfer: [AsyncFunction: transfer] +} +``` + +
+
+ +--- + +### The Transfer Method + +
+
+ +`transfer()` - Transfers a given amount of the asset from the source chain to the destination chain. + +**Parameters** + +- `amount` ++"bigint | number| string"++ - The amount of the asset to transfer between the source and destination chains + +**Returns** + +- ++"Promise(string)"++ - The transaction hash for the transfer on the source chain + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const transferTxHash = await transferData.transfer(); +console.log(transferTxHash); +``` + +```js title="Response" +0x2a1ec19aa360111c0e499c90b5a2747f2e87f49966e280daf831b856996f3952; +``` + +
+
+ +--- + +### The Get Estimate Method + +
+
+ +`getEstimate()` - Returns an estimated amount of the asset that will be received on the destination chain, less any destination fees. + +**Parameters** + +- `amount` ++"number | string"++ - The amount of the asset to transfer between the source and destination chains + +**Returns** + +- ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - An estimated amount of the asset that the destination address will receive + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const estimate = transferData.getEstimate(1); +console.log(estimate); +``` + +```js title="Response" +{ + key: 'dot', + originSymbol: 'DOT', + amount: 9979919679n, + decimals: 10, + symbol: 'DOT' +} +``` + +
+
+ +--- + +## Asset Utilities + +The `AssetAmount` class contains the following utility functions. + +### The From Asset Method + +
+
+ +`fromAsset()` - Creates an [`AssetAmount`](./interfaces.md#the-asset-amount-object) instance from an [`Asset`](./interfaces.md#the-asset-object) and some additional parameters. + +!!! note + To use the `fromAsset` method, you'll need to import it from the [xcm-types package](https://github.com/moonbeam-foundation/xcm-sdk/tree/main/packages/types){target=\_blank}. To install the xcm-types package, run the following: + + ```bash + npm i @moonbeam-network/xcm-types + ``` + +**Parameters** + +- `asset` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - An `AssetAmount` instance to compare +- `params` ++"AssetAmountParams"++ - Additional parameters needed to create the `AssetAmount` instance. The `AssetAmountParams` are as follows: + - `amount` ++"bigint"++ - Identifies a particular amount of the asset (i.e., balance, minimum, maximum, etc.) + - `decimals` ++"number"++ - The number of decimals the asset has + - `symbol` ++"string"++ - The symbol of the asset + +**Returns** + +**Returns** + +- ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - The new `AssetAmount` instance + +
+
+ +```js title="Example Usage" +import { Asset, AssetAmount } from '@moonbeam-network/xcm-types'; + +const dot = new Asset({ + key: 'dot', + originSymbol: 'DOT', +}); +const zeroAmount = AssetAmount.fromAsset(dot, { + amount: 0n, + decimals: 10, +}); +``` + +```js title="Response" +{ + key: 'dot', + originSymbol: 'DOT', + amount: 0n, + decimals: 10, + symbol: 'DOT' +} +``` + +
+
+ +--- + +### The Is Same Method + +
+
+ +`isSame()` - Compares two instances of [`AssetAmount`](./interfaces.md#the-asset-amount-object) and checks whether they have the same `name`, `symbol`, and `decimals` properties. This method does not compare the `amount` properties. + +**Parameters** + +- `asset` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - An `AssetAmount` instance to compare + +**Returns** + +- ++"boolean"++ - `true` if the `AssetAmount` instances are the same or `false` if they are different + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const isSame = transferData.max.isSame(transferData.min); +console.log(isSame); +``` + +```js title="Response" +true; +``` + +
+
+ +--- + +### The Is Equal Method + +
+
+ +`isEqual()` - Compares two instances of [`AssetAmount`](./interfaces.md#the-asset-amount-object) and checks whether they have all of the same properties. This compares the `name`, `symbol`, `decimals`, and `amount` properties. + +**Parameters** + +- `asset` ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - An `AssetAmount` instance to compare + +**Returns** + +- ++"boolean"++ - `true` if the `AssetAmount` instances are the same or `false` if they are different + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const isEqual = transferData.max.isEqual(transferData.min); +console.log(isEqual); +``` + +```js title="Response" +false; +``` + +
+
+ +--- + +### The Copy With Method + +
+
+ +`copyWith()` - Creates a new instance of [`AssetAmount`](./interfaces.md#the-asset-amount-object) with properties of the original instance and overrides properties that are passed as options. + +**Parameters** + +- `params` ++"Partial"++ - The properties to apply to the new `AssetAmount` instance. The `AssetAmountConstructorParams` are as follows: + - `amount` ++"bigint"++ - Identifies a particular amount of the asset (i.e., balance, minimum, maximum, etc.) + - `decimals` ++"number"++ - The number of decimals the asset has + - `symbol` ++"string"++ - The symbol of the asset + +**Returns** + +- ++"AssetAmount"++ [:material-link-variant:](./interfaces.md#the-asset-amount-object) - The new `AssetAmount` instance + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const estimate = transferData.getEstimate(1); +const estimateCopy = estimate.copyWith({ amount: 2 }); +console.log(estimateCopy); +``` + +```js title="Response" +{ + key: 'dot', + originSymbol: 'DOT', + amount: 2n, + decimals: 10, + symbol: 'DOT' +} +``` + +
+
+ +--- + +### The To Decimal Method + +
+
+ +`toDecimal()` - Converts an [`AssetAmount`](./interfaces.md#the-asset-amount-object) to a decimal. The number to convert to decimal format and the number of decimals the asset uses are pulled automatically from the `AssetAmount`. + +**Parameters** + +- `maxDecimal?` ++"number"++ - The maximum number of decimal places to use. the default is `6` +- `roundType?` ++"RoundingMode"++ - Accepts an index that dictates the [rounding method](https://mikemcl.github.io/big.js/#rm){target=\_blank} to use based on the `RoundingMode` enum: + + ```js + enum RoundingMode { + RoundDown = 0, + RoundHalfUp = 1, + RoundHalfEven = 2, + RoundUp = 3 + } + ``` + +**Returns** + +- ++"string"++ - The given amount in decimal format + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const estimate = transferData.getEstimate(1); +const estimateAmount = estimate.toDecimal(); +console.log(estimateAmount); +``` + +```js title="Response" +0.997992; +``` + +
+
+ +--- + +### The To Big Number Method + +
+
+ +`toBig()` - Converts an [`AssetAmount`](./interfaces.md#the-asset-amount-object) to a big number. + +**Parameters** + +None. + +**Returns** + +- ++"Big"++ - The given amount in big number format + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const fee = transferData.destination.fee.toBig(); +console.log(fee); +``` + +```js title="Response" +20080321; +``` + +
+
+ +--- + +### The To Big Decimal Method + +
+
+ +`toBigDecimal()` - Converts an [`AssetAmount`](./interfaces.md#the-asset-amount-object) to a decimal and then to a big number. The number to convert to decimal format and the number of decimals the asset uses are pulled automatically from the `AssetAmount`. + +**Parameters** + +- `maxDecimal?` ++"number"++ - The maximum number of decimal places to use. the default is `6` +- `roundType?` ++"RoundingMode"++ - Accepts an index that dictates the [rounding method](https://mikemcl.github.io/big.js/#rm){target=\_blank} to use based on the `RoundingMode` enum: + + ```js + enum RoundingMode { + RoundDown = 0, + RoundHalfUp = 1, + RoundHalfEven = 2, + RoundUp = 3 + } + ``` + +**Returns** + +- ++"Big"++ - The given amount in big number decimal format + +
+
+ +```js title="Example Usage" +import { Sdk } from '@moonbeam-network/xcm-sdk'; + +const sdkInstance = Sdk(); +const transferData = await sdkInstance + .assets() + .asset('dot') + .source('polkadot') + .destination('moonbeam') + .accounts( + INSERT_POLKADOT_ADDRESS, // Source chain address + INSERT_MOONBEAM_ADDRESS, // Destination chain address + { + evmSigner: INSERT_EVM_SIGNER, + polkadotSigner: INSERT_POLKADOT_SIGNER, + }, + ); + +const fee = transferData.destination.fee.toBigDecimal(); +console.log(fee); +``` + +```js title="Response" +0.002008; +``` + +
+
diff --git a/mkdocs/material-overrides/assets/images/code.svg b/mkdocs/material-overrides/assets/images/code.svg new file mode 100644 index 00000000..09cee987 --- /dev/null +++ b/mkdocs/material-overrides/assets/images/code.svg @@ -0,0 +1,56 @@ + + diff --git a/mkdocs/material-overrides/assets/images/code.webp b/mkdocs/material-overrides/assets/images/code.webp new file mode 100644 index 00000000..717c50bf Binary files /dev/null and b/mkdocs/material-overrides/assets/images/code.webp differ diff --git a/mkdocs/material-overrides/assets/images/contribute.svg b/mkdocs/material-overrides/assets/images/contribute.svg new file mode 100644 index 00000000..d4184123 --- /dev/null +++ b/mkdocs/material-overrides/assets/images/contribute.svg @@ -0,0 +1,56 @@ + + diff --git a/mkdocs/material-overrides/assets/images/contribute.webp b/mkdocs/material-overrides/assets/images/contribute.webp new file mode 100644 index 00000000..d5801216 Binary files /dev/null and b/mkdocs/material-overrides/assets/images/contribute.webp differ diff --git a/mkdocs/material-overrides/assets/images/learn.svg b/mkdocs/material-overrides/assets/images/learn.svg new file mode 100644 index 00000000..df10b785 --- /dev/null +++ b/mkdocs/material-overrides/assets/images/learn.svg @@ -0,0 +1,52 @@ + + diff --git a/mkdocs/material-overrides/assets/images/learn.webp b/mkdocs/material-overrides/assets/images/learn.webp new file mode 100644 index 00000000..9e9b45e2 Binary files /dev/null and b/mkdocs/material-overrides/assets/images/learn.webp differ diff --git a/mkdocs/material-overrides/assets/images/logo-dark.webp b/mkdocs/material-overrides/assets/images/logo-dark.webp new file mode 100644 index 00000000..cef14f39 Binary files /dev/null and b/mkdocs/material-overrides/assets/images/logo-dark.webp differ diff --git a/mkdocs/material-overrides/assets/images/logo.webp b/mkdocs/material-overrides/assets/images/logo.webp new file mode 100644 index 00000000..7c89a7e0 Binary files /dev/null and b/mkdocs/material-overrides/assets/images/logo.webp differ diff --git a/mkdocs/material-overrides/assets/images/moonbeam-foundation-dark.webp b/mkdocs/material-overrides/assets/images/moonbeam-foundation-dark.webp new file mode 100644 index 00000000..5979d83d Binary files /dev/null and b/mkdocs/material-overrides/assets/images/moonbeam-foundation-dark.webp differ diff --git a/mkdocs/material-overrides/assets/images/moonbeam-foundation-light.webp b/mkdocs/material-overrides/assets/images/moonbeam-foundation-light.webp new file mode 100644 index 00000000..61b9699e Binary files /dev/null and b/mkdocs/material-overrides/assets/images/moonbeam-foundation-light.webp differ diff --git a/mkdocs/material-overrides/assets/stylesheets/custom.css b/mkdocs/material-overrides/assets/stylesheets/custom.css new file mode 100644 index 00000000..66a3cafd --- /dev/null +++ b/mkdocs/material-overrides/assets/stylesheets/custom.css @@ -0,0 +1,394 @@ +:root { + /* Brand colors */ + --purple-dark: #2b1d3c; + --purple-dark-tint-20: #554a63; + --purple-dark-transparent-15: rgba(140, 132, 245, 0.15); + --purple-dark-transparent-10: rgba(140, 132, 245, 0.1); + --purple-light: #958fdc; + --teal-dark: #06353d; + --teal-dark-transparent-15: rgba(7, 211, 186, 0.15); + --teal-light: #07d3ba; + --teal-light-shade-50: #059482; + --teal-light-transparent-15: rgba(7 211, 186, 0.15); + --pink-dark: #d9254d; + --pink-dark-transparent: rgba(217, 37, 77, 0.75); + --pink-light: #d5b8d3; + --light: #ffffff; + --light-transparent-15: rgba(255, 255, 255, 0.15); + --light-transparent-40: rgba(255, 255, 255, 0.4); + --light-transparent-60: rgba(255, 255, 255, 0.6); + --dark: #000000; + --dark-transparent-60: rgba(0, 0, 0, 0.6); + + /** Material theme overrides **/ + /* Fonts */ + --header-font: 'Banana Grotesk', sans-serif; + --label-font: 'Space Mono', monospace; + + /* Borders */ + --border-width-thin: 0.5px; + --border-width: 1px; + --border-radius: 0.3em; + + /* Link hover opacity */ + --hover-opacity: 0.7; + + /** Admonition */ + --md-admonition-icon--code: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTE0LjYsMTYuNkwxOS4yLDEyTDE0LjYsNy40TDE2LDZMMjIsMTJMMTYsMThMMTQuNiwxNi42TTkuNCwxNi42TDQuOCwxMkw5LjQsNy40TDgsNkwyLDEyTDgsMThMOS40LDE2LjZaIiAvPjwvc3ZnPg=='); +} + +:root, +[data-md-color-scheme='default'] { + --md-accent-fg-color: var(--teal-light); + + /** Code highlighting color shades **/ + /* Numbers */ + --md-code-hl-number-color: #e1147b; + /* Python function names */ + --md-code-hl-function-color: #42a2a1; + /* JavaScript booleans, Python variable names */ + --md-code-hl-name-color: #9356e9; + /* Strings */ + --md-code-hl-string-color: #e1147b; + /* Python print */ + --md-code-hl-constant-color: #42a2a1; + /* Imports, const, let, var, async, await, function, etc. */ + --md-code-hl-keyword-color: #42a2a1; + /* Comments */ + --md-code-hl-comment-color: #9356e9; + /* Code highlighting */ + --md-code-hl-color: #e1147b; + /* Backslashes */ + --md-code-hl-special-color: #262626; + + /** Footer color */ + --md-footer-bg-color: #ffffff; + --md-footer-bg-color--dark: #ffffff; + --md-footer-fg-color: #000000; + --md-footer-fg-color--light: #000000; + + /** Link color */ + --md-typeset-a-color: var(--teal-light-shade-50); + + /** Badge color */ + --md-typeset-kbd-color: #e9e9e9; + + /** Version dropdown */ + --md-version-bg-color: var(--teal-dark-transparent-15); + + /** Border color */ + --border-color: var(--dark-transparent-60); + --border-grid: var(--border-width-thin) solid var(--border-color); +} + +:root, +[data-md-color-scheme='slate'], +[data-md-color-scheme='slate'][data-md-color-primary='black'] { + --md-default-bg-color: var(--dark); + --md-accent-fg-color: var(--teal-light); + + /** Code highlighting color shades **/ + --md-code-bg-color: var(--purple-dark-transparent-10); + /* Numbers */ + --md-code-hl-number-color: var(--purple-light); + /* Python function names */ + --md-code-hl-function-color: var(--teal-light); + /* JavaScript booleans, Python variable names */ + --md-code-hl-name-color: var(--purple-light); + /* Strings */ + --md-code-hl-string-color: var(--pink-light); + /* Python print */ + --md-code-hl-constant-color: var(--light); + /* Imports, const, let, var, async, await, function, etc. */ + --md-code-hl-keyword-color: var(--teal-light); + /* Comments */ + --md-code-hl-comment-color: var(--light-transparent-60); + /* Code highlighting */ + --md-code-hl-color: var(--pink-dark); + /* Backslashes */ + --md-code-hl-special-color: var(--light); + + /** Footer color */ + --md-footer-fg-color: var(--light); + --md-footer-fg-color--light: var(--light); + --md-footer-bg-color: var(--dark); + --md-footer-bg-color--dark: var(--dark); + + /** Link color */ + --md-typeset-a-color: var(--teal-light-shade-50); + + /** Version dropdown */ + --md-version-bg-color: var(--teal-dark); + + /** Border color */ + --border-color: var(--light-transparent-40); + --border-grid: var(--border-width-thin) solid var(--border-color); +} + +[data-md-color-primary='black'] .md-tabs, +[data-md-color-primary='black'] .md-header { + background-color: var(--dark); +} + +body { + max-width: 97%; + margin: auto; + border-left: var(--border-grid); + border-right: var(--border-grid); +} + +.md-main { + border-top: var(--border-grid); + border-bottom: var(--border-grid); +} + +/* Font size */ +.md-typeset { + font-size: 0.7rem; +} + +.md-nav { + font-size: 0.6rem; +} + +/* Page styling */ +.tutorial { + max-width: 36.8rem; +} + +.md-sidebar__scrollwrap { + margin: 0; + margin-right: 4em; +} + +/* Header styling */ +.md-header__topic:first-child { + font-weight: 400; +} + +.md-social__link { + height: unset; + margin-left: 0.6rem; +} + +.md-social__link svg { + max-height: 1.2rem; + max-width: 1.2rem; +} + +.md-social__link:hover svg { + opacity: var(--hover-opacity); +} + +@media screen and (min-width: 76.25em) { + [dir='ltr'] .md-header__source { + margin-left: 0; + } +} + +[data-md-color-scheme=slate] .md-nav__button.md-logo img[src$="#only-light"], +[data-md-color-scheme='default'] .md-nav__button.md-logo img[src$='#only-dark'], +[data-md-color-scheme=slate] .md-header__button.md-logo img[src$="#only-light"], +[data-md-color-scheme='default'] .md-header__button.md-logo img[src$='#only-dark'] { + display: none; +} + +.md-tabs__link { + font-family: var(--label-font); + text-transform: uppercase; +} + +.md-version__list { + border: var(--border-grid); + border-color: var(--teal-dark); +} + +.md-version__link:focus, +.md-version__link:hover { + color: var(--md-default-fg-color); + background-color: var(--teal-dark-transparent-15); +} + +.md-header--shadow { + box-shadow: unset; + border-bottom: var(--border-grid); +} + +[dir=ltr] .md-search__input::placeholder { + font-family: var(--label-font); + text-transform: uppercase; +} + +.md-header__title--active .md-header__topic+.md-header__topic, +.md-header__topic+.md-header__topic { + transition: none; +} + +/* Footer styling */ +.md-footer-meta__inner { + gap: 1em; +} + +.md-footer-meta__inner .logo { + align-content: center; +} + +.md-footer-copyright { + padding: 0.1em; + margin: auto; + font-size: 0.54rem; + font-family: var(--label-font); + text-transform: uppercase; +} + +.column { + display: flex; + flex-direction: column; + margin: 0.5em; +} + +.moonbeam-foundation-logo { + padding: 1em; + vertical-align: middle; +} + +@media screen and (max-width: 35.2em) { + .md-footer-meta__inner { + justify-content: center; + gap: 0; + } + + .md-footer-copyright { + text-align: center; + } +} + + +/* Reference page styling */ +/* Grid styling */ +.grid>div:last-child { + max-height: 1000px; + overflow: auto; +} + +.md-typeset .grid { + grid-gap: 3rem; +} + +.md-typeset .grid>div:first-child>p:first-child { + margin-top: 0; +} + +.grid .highlight span.filename { + margin-top: 0; +} + +/* Type styling */ +.md-typeset kbd { + border-radius: 1em; + vertical-align: baseline; + box-shadow: none; +} + +/* For links to definitions on reference pages */ +.md-typeset .twemoji { + vertical-align: middle; +} + +/* Add arrows to left navigation sections */ +@media screen and (min-width: 76.25em) { + + .md-nav__item--active .md-nav__link[href='../interfaces/'] .md-ellipsis:after, + .md-nav__item--active .md-nav__link[href='../methods/'] .md-ellipsis:after { + background-color: currentcolor; + content: ''; + display: inline-block; + -webkit-mask-position: center; + mask-position: center; + -webkit-mask-repeat: no-repeat; + mask-repeat: no-repeat; + -webkit-mask-size: contain; + mask-size: contain; + mask-image: url('data:image/svg+xml;charset=utf-8,'); + /* Unicode character for a downward-pointing triangle */ + -webkit-mask-image: url('data:image/svg+xml;charset=utf-8,'); + /* Unicode character for a downward-pointing triangle */ + transition: transform 0.25s; + height: 24px; + width: 24px; + vertical-align: middle; + } + + .md-nav__item--active .md-nav__link.md-nav__link--active[href='./'] .md-ellipsis:after { + transform: rotate(90deg); + background-color: currentcolor; + content: ''; + display: inline-block; + -webkit-mask-position: center; + mask-position: center; + -webkit-mask-repeat: no-repeat; + mask-repeat: no-repeat; + -webkit-mask-size: contain; + mask-size: contain; + mask-image: url('data:image/svg+xml;charset=utf-8,'); + /* Unicode character for a downward-pointing triangle */ + -webkit-mask-image: url('data:image/svg+xml;charset=utf-8,'); + /* Unicode character for a downward-pointing triangle */ + transition: transform 0.25s; + height: 24px; + width: 24px; + vertical-align: middle; + } + + [dir='ltr'] .md-nav--integrated>.md-nav__list>.md-nav__item--active .md-nav--secondary { + border-left: 0.05rem solid var(--md-default-fg-color--lightest); + } + + [dir='ltr'] .md-sidebar--primary:not([hidden])~.md-content>.md-content__inner { + margin-left: 0; + margin-right: 0; + } +} + +/* Disclaimer styling */ +.page-disclaimer { + font-size: x-small; + font-style: italic; + margin-top: 3em; +} + +/* Admonition styling */ +.md-typeset details.note, +.md-typeset .admonition.note { + border-color: var(--teal-light-shade-50); +} + +.md-typeset .note>.admonition-title { + background-color: var(--teal-dark-transparent-15); +} + +.md-typeset .note>.admonition-title:before { + background-color: var(--teal-light-shade-50); +} + +.md-typeset details.code, +.md-typeset .admonition.code { + border-color: var(--purple-light); +} + +.md-typeset .code>.admonition-title, +.md-typeset .code>summary { + background-color: var(--purple-dark-transparent-15); +} + +.md-typeset .code>.admonition-title::before, +.md-typeset .code>summary::before { + background-color: var(--purple-light); + -webkit-mask-image: var(--md-admonition-icon--code); + mask-image: var(--md-admonition-icon--code); +} + +/* Tab styling */ +.js .md-typeset .tabbed-labels:before { + background-color: var(--purple-light); +} \ No newline at end of file diff --git a/mkdocs/material-overrides/assets/stylesheets/fonts/BananaGrotesk-Regular.otf b/mkdocs/material-overrides/assets/stylesheets/fonts/BananaGrotesk-Regular.otf new file mode 100644 index 00000000..12afc2dd Binary files /dev/null and b/mkdocs/material-overrides/assets/stylesheets/fonts/BananaGrotesk-Regular.otf differ diff --git a/mkdocs/material-overrides/assets/stylesheets/home.css b/mkdocs/material-overrides/assets/stylesheets/home.css new file mode 100644 index 00000000..3dcd6e7c --- /dev/null +++ b/mkdocs/material-overrides/assets/stylesheets/home.css @@ -0,0 +1,136 @@ +/* Background image on home page */ +[data-md-color-scheme='slate'] .md-main { + /* Set gradient background */ + background: linear-gradient(#000, #291E3A); + /* For older browsers */ + background: -webkit-linear-gradient(#000, #291E3A); + background: -moz-linear-gradient(#000, #291E3A); + background: -o-linear-gradient(#000, #291E3A); +} + +/* Background image on home page */ +[data-md-color-scheme='default'] .md-main { + /* Set gradient background */ + background: linear-gradient(#958fdc, #fff); + /* For older browsers */ + background: -webkit-linear-gradient(#958fdc, #fff); + background: -moz-linear-gradient(#958fdc, #fff); + background: -o-linear-gradient(#958fdc, #fff); +} + +/* Styles for the hero section */ +.hero { + text-align: center; + padding: 10px 0; + color: var(--md-default-fg-color); +} + +.hero-content { + width: fit-content; + max-width: 800px; + margin: 0 auto; + padding: 0 3em; + background: var(--md-home-hero-bg-color); +} + +.hero h1 { + font-size: 36px; + color: var(--md-default-fg-color); +} + +.hero p { + font-size: 18px; + margin-top: 20px; +} + +.md-typeset .hero-content hr { + border-color: #958fdc; + width: 70%; + margin: auto; +} + +.hero p.note { + font-size: 15px; +} + +/* Styles for the featured content section */ +.featured-content { + display: flex; + flex-wrap: wrap; + justify-content: space-between; +} + +.feature { + text-align: center; + padding: 20px; + box-shadow: 0px 0px 1px var(--md-default-fg-color); + border-radius: var(--border-radius); + width: 30%; + margin: 1em; +} + +.feature a { + margin-top: auto; +} + +.feature img { + width: 60px; + max-width: 100%; + height: auto; +} + +.feature h2 { + font-size: 24px; + margin-top: 10px; + margin-bottom: 10px; + color: var(--md-default-fg-color); +} + +.feature p { + font-size: 16px; + color: var(--md-default-fg-color); +} + +.md-clipboard { + top: 2em; +} + +.install { + margin: auto; + display: flex; + justify-content: center; +} + +.md-typeset pre>code { + display: flex; + height: 4em; + padding: 0; +} + +.md-typeset pre { + margin: 0; +} + +@media screen and (max-width: 76.234375em) { + .code { + display: none + } +} + +@media screen and (max-width: 56em) { + .feature { + width: 46%; + } +} + +@media screen and (max-width: 45.125em) { + .feature { + width: 100%; + } +} + +@media screen and (max-width: 38.125em) { + .feature { + width: 100%; + } +} \ No newline at end of file diff --git a/mkdocs/material-overrides/home.html b/mkdocs/material-overrides/home.html new file mode 100644 index 00000000..27538579 --- /dev/null +++ b/mkdocs/material-overrides/home.html @@ -0,0 +1,49 @@ +{% extends "main.html" %} + +{% block htmltitle %} +XCM SDK Docs +{% endblock %} + +{% block styles %} +{{ super() }} + +{% endblock %} + +{% block content %} +
+
+
+

Documentation for the XCM SDK

+

Dive into our comprehensive XCM SDK documentation to streamline your development journey, enabling you to + effortlessly integrate cross-chain functionality into your projects within the Polkadot ecosystem.

+
+
+            
+              npm install @moonbeam-foundation/xcm-sdk
+            
+          
+
+
+
+ +
+{% endblock %} \ No newline at end of file diff --git a/mkdocs/material-overrides/main.html b/mkdocs/material-overrides/main.html new file mode 100644 index 00000000..718241bf --- /dev/null +++ b/mkdocs/material-overrides/main.html @@ -0,0 +1,11 @@ +{#- +This file was automatically generated - do not edit +-#} + +{% extends "base.html" %} + +{% block fonts %} +{{ super() }} + + +{% endblock %} \ No newline at end of file diff --git a/mkdocs/material-overrides/partials/footer.html b/mkdocs/material-overrides/partials/footer.html new file mode 100644 index 00000000..eda0da0d --- /dev/null +++ b/mkdocs/material-overrides/partials/footer.html @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/mkdocs/material-overrides/partials/header.html b/mkdocs/material-overrides/partials/header.html new file mode 100644 index 00000000..37107431 --- /dev/null +++ b/mkdocs/material-overrides/partials/header.html @@ -0,0 +1,64 @@ +{#- +This file was automatically generated - do not edit +-#} +{% set class = "md-header" %} +{% if "navigation.tabs.sticky" in features %} +{% set class = class ~ " md-header--shadow md-header--lifted" %} +{% elif "navigation.tabs" not in features %} +{% set class = class ~ " md-header--shadow" %} +{% endif %} +
+ + {% if "navigation.tabs.sticky" in features %} + {% if "navigation.tabs" in features %} + {% include "partials/tabs.html" %} + {% endif %} + {% endif %} +
\ No newline at end of file diff --git a/mkdocs/material-overrides/partials/logo.html b/mkdocs/material-overrides/partials/logo.html new file mode 100644 index 00000000..96fc1183 --- /dev/null +++ b/mkdocs/material-overrides/partials/logo.html @@ -0,0 +1,10 @@ +{#- +This file was automatically generated - do not edit +-#} +{% if config.theme.logo %} + logo + logo +{% else %} + {% set icon = config.theme.icon.logo or "material/library" %} + {% include ".icons/" ~ icon ~ ".svg" %} +{% endif %} \ No newline at end of file diff --git a/mkdocs/material-overrides/tutorial.html b/mkdocs/material-overrides/tutorial.html new file mode 100644 index 00000000..402a4dac --- /dev/null +++ b/mkdocs/material-overrides/tutorial.html @@ -0,0 +1,7 @@ +{% extends "main.html" %} + +{% block content %} +
+ {{ super() }} +
+{% endblock %} diff --git a/mkdocs/mkdocs.yml b/mkdocs/mkdocs.yml new file mode 100644 index 00000000..c1027ee0 --- /dev/null +++ b/mkdocs/mkdocs.yml @@ -0,0 +1,72 @@ +site_name: XCM SDK Docs +site_url: https://moonbeam-foundation.github.io/xcm-sdk/ +docs_dir: docs +copyright: © 2024 Moonbeam Foundation. All Rights Reserved. +repo_name: moonbeam-foundation/xcm-sdk +repo_url: https://github.com/moonbeam-foundation/xcm-sdk +theme: + name: material + custom_dir: material-overrides + favicon: assets/images/logo.webp + logo: assets/images/logo.webp + logo_dark_mode: assets/images/logo-dark.webp + icon: + repo: fontawesome/brands/github + font: + text: Banana Grotesk + palette: + # Palette toggle for light mode + - media: '(prefers-color-scheme: light)' + scheme: default + primary: white + toggle: + icon: material/weather-night + name: Switch to dark mode + # Palette toggle for dark mode + - media: '(prefers-color-scheme: dark)' + scheme: slate + primary: black + toggle: + icon: material/weather-sunny + name: Switch to light mode + features: + - content.code.copy + - navigation.indexes + - navigation.tabs + - toc.follow + - toc.integrate +extra_css: + - assets/stylesheets/custom.css +plugins: + - search + - awesome-pages + - mike: + canonical_version: latest +markdown_extensions: + - admonition + - attr_list + - md_in_html + - pymdownx.details + - pymdownx.emoji: + emoji_index: !!python/name:material.extensions.emoji.twemoji + emoji_generator: !!python/name:material.extensions.emoji.to_svg + - pymdownx.highlight: + anchor_linenums: true + line_spans: __span + pygments_lang_class: true + - pymdownx.inlinehilite + - pymdownx.keys + - pymdownx.snippets: + base_path: docs/.snippets + - pymdownx.superfences + - pymdownx.tabbed: + alternate_style: true +extra: + generator: false + version: + provider: mike + social: + - icon: fontawesome/brands/discord + link: https://discord.gg/PfpUATX + name: Discord + diff --git a/mkdocs/requirements.txt b/mkdocs/requirements.txt new file mode 100644 index 00000000..61cdb579 --- /dev/null +++ b/mkdocs/requirements.txt @@ -0,0 +1,6 @@ +mkdocs==1.5.3 +mkdocs-awesome-pages-plugin==2.9.2 +mkdocs-git-revision-date-localized-plugin==1.2.2 +mkdocs-material==9.5.3 +mkdocs-redirects==1.2.1 +mike==2.0.0 \ No newline at end of file diff --git a/packages/sdk/README.md b/packages/sdk/README.md index a4b153f8..f462d939 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -4,17 +4,7 @@ The XCM SDK offers helper functions, that provide a very simple interface to exe # Documentation -## v2 (current) - -- [readme](https://github.com/moonbeam-foundation/xcm-sdk/tree/main) -- [usage](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v1/xcm-sdk/) (Updated docs coming soon...) -- [reference](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v1/reference/) (Updated docs coming soon...) - -## v1 (previous) - -- [readme](https://github.com/moonbeam-foundation/xcm-sdk/tree/v1) -- [usage](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v1/xcm-sdk/) -- [reference](https://docs.moonbeam.network/builders/interoperability/xcm/xcm-sdk/v1/reference/) +You can find the documentation at [https://moonbeam-foundation.github.io/xcm-sdk-mkdocs/latest/reference/interfaces/](https://moonbeam-foundation.github.io/xcm-sdk-mkdocs/latest/reference/interfaces/). # Installation