🚚Migration

Migration part of the SDK provides abstractions to assist you with migrating tokens between ICON and the hub chain (Sonic). The service supports multiple migration types including ICX/wICX β†’ SODA, bnUSD legacy β†’ new bnUSD, BALN β†’ SODA, and their reverse operations.

Using SDK Config and Constants

SDK includes predefined configurations of supported chains, tokens and other relevant information for the client to consume.

import { 
  ICON_MAINNET_CHAIN_ID, 
  SONIC_MAINNET_CHAIN_ID,
  type HubChainId,
  type SpokeChainId 
} from "@sodax/sdk"

// Supported migration chains
const hubChainId: HubChainId = SONIC_MAINNET_CHAIN_ID;
const iconChainId: SpokeChainId = ICON_MAINNET_CHAIN_ID;

// Migration tokens
const migrationTokens = ['ICX', 'bnUSD', 'BALN'] as const;

Please refer to SDK constants.tsarrow-up-right for more.

Initialising Providers

Refer to Initialising Spoke Provider section to see how IconSpokeProvider and SonicSpokeProvider can be created.

Migration Types

The MigrationService supports multiple types of migrations:

  1. ICX/wICX β†’ SODA: Migrate ICX or wICX tokens from ICON to SODA tokens on the hub chain

  2. SODA β†’ wICX: Revert SODA tokens from the hub chain back to wICX tokens on ICON

  3. bnUSD Legacy ↔ New bnUSD: Unified migration between legacy and new bnUSD tokens across supported chains

  4. BALN β†’ SODA: Migrate BALN tokens to SODA tokens on the hub chain

Common Operations

Check Allowance

Before creating migration intents, you should check if the allowance is valid. For forward migrations (ICX/wICX, bnUSD, BALN), no allowance is required as these tokens do not require approval.

Note: For Stellar-based operations, the allowance system works differently:

  • Source Chain (Stellar): The standard isAllowanceValid method works as expected for EVM chains, but for Stellar as the source chain, this method checks and establishes trustlines instead.

  • Destination Chain (Stellar): When Stellar is specified as the destination chain, frontends/clients need to manually check trustlines using StellarSpokeService.hasSufficientTrustline before executing migration operations.

Approve Tokens

For reverse migrations, if the allowance check returns false, you need to approve the tokens before creating the revert migration intent.

Note: For Stellar-based operations, the approval system works differently:

  • Source Chain (Stellar): The standard approve method works as expected for EVM chains, but for Stellar as the source chain, this method establishes trustlines instead.

  • Destination Chain (Stellar): When Stellar is specified as the destination chain, frontends/clients need to manually establish trustlines using StellarSpokeService.requestTrustline before executing migration operations.

Stellar Trustline Requirements

For Stellar-based migration operations, you need to handle trustlines differently depending on whether Stellar is the source or destination chain. See Stellar Trustline Requirements for detailed information and code examples.

ICX Migration (ICX/wICX β†’ SODA)

Migrate ICX to SODA

Migrate ICX or wICX tokens to SODA tokens on the hub chain.

Reverse ICX Migration (SODA β†’ wICX)

Revert SODA to ICX

Revert SODA tokens back to wICX tokens on ICON.

bnUSD Migration (Legacy ↔ New bnUSD)

The bnUSD migration now uses a unified API that handles both forward (legacy β†’ new) and reverse (new β†’ legacy) migrations. The system automatically determines the migration direction based on the token addresses provided.

bnUSD Constants and Helper Functions

The SDK provides several constants and helper functions to work with legacy and new bnUSD tokens across different chains:

Migrate Legacy bnUSD to New bnUSD

Migrate legacy bnUSD tokens to new bnUSD tokens on any spoke chain (besides Icon - which has only legacy bnUSD).

Note: When migrating to Stellar as the destination chain, ensure you have established the necessary trustlines using StellarSpokeService.hasSufficientTrustline and StellarSpokeService.requestTrustline before executing the migration.

Reverse Migrate New bnUSD to Legacy bnUSD

Revert new bnUSD tokens back to legacy bnUSD tokens. Legacy bnUSD exists on Icon, Sui or Stellar chains.

Note: When migrating to Stellar as the destination chain, ensure you have established the necessary trustlines using StellarSpokeService.hasSufficientTrustline and StellarSpokeService.requestTrustline before executing the migration.

BALN Migration (BALN β†’ SODA)

Migrate BALN to SODA

Migrate BALN tokens to SODA tokens on the hub chain.

Complete Examples

ICX Migration Example

Reverse ICX Migration Example

bnUSD Migration Example

BALN Migration Example

Error Handling

The MigrationService returns Result types that can contain various error codes:

  • MIGRATION_FAILED: General migration failure

  • CREATE_MIGRATION_INTENT_FAILED: Failed to create migration intent

  • CREATE_REVERT_MIGRATION_INTENT_FAILED: Failed to create revert migration intent

  • REVERT_MIGRATION_FAILED: General revert migration failure

  • RelayError: Errors from the relay service

Each error includes the original parameters and the underlying error for debugging purposes.

Configuration

The MigrationService can be configured with custom relay API endpoints and timeouts:

Default configuration:

  • relayerApiEndpoint: https://relay.soniclabs.com

  • timeout: 60000ms (60 seconds)

Last updated