Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): Add MultiLocation override feature ⛓️ #199

Merged
merged 1 commit into from
Apr 13, 2024

Conversation

michaeldev5
Copy link
Collaborator

@michaeldev5 michaeldev5 commented Apr 12, 2024

This PR request adds a feature to allow integration of MultiLocation objects in the transfer process. Instead of passing currency, address and destination traditionally, you can pass a MultiLocation object instead which will override default behaviour. This brings flexibility and customization to our SDK.

The Builder methods to(), currency() and address() have been modified to accept a MultiLocation type.

The MultiLocation object has the following structure:

export interface TMultiLocation {
  parents: StringOrNumber
  interior: Junctions
}

The interior has to have one of the following keys: X1, X2, X3, X4, X5, X6, X7, X8. The Junctions enum can represent zero to eight steps down the hierarchy.

When using X1 ,pass the object as the value: X1: {}, otherwise use array X2: [].

Then in the object or array we can specify the junction type. We can only choose as many junctions as the number after X says. Otherwise a TS error will be thrown. These are available junctions:

interface JunctionParachain {
  Parachain: StringOrNumber
}

interface JunctionAccountId32 {
  AccountId32: {
    network: NetworkId
    id: HexString
  }
}

interface JunctionAccountIndex64 {
  AccountIndex64: {
    network: NetworkId
    index: StringOrNumber
  }
}

interface JunctionAccountKey20 {
  AccountKey20: {
    network: NetworkId
    key: HexString
  }
}

interface JunctionPalletInstance {
  PalletInstance: StringOrNumber
}

interface JunctionGeneralIndex {
  GeneralIndex: StringOrNumber
}

interface JunctionGeneralKey {
  GeneralKey: {
    length: StringOrNumber
    data: HexString
  }
}

interface JunctionOnlyChild {
  OnlyChild: string
}

interface JunctionPlurality {
  Plurality: {
    id: BodyId
    part: BodyPart
  }
}

interface JunctionGlobalConsensus {
  GlobalConsensus: NetworkId
}

An example of overriding address in ParaToPara call:

return Builder(api)
        .from(from)
        .to(to)
        .currency(currency)
        .amount(amount)
        .address({
          parents: 1,
          interior: {
            X2: [
              {
                Parachain: 200,
              },
              {
                GeneralIndex: 0,
              },
            ],
          },
        })
        .build();

We can do the same with currency() and to()(destination).

An example of overriding currency in ParaToPara call:

return Builder(api)
        .from(from)
        .to(to)
        .currency({
          parents: 1,
          interior: {
            X2: [
              { PalletInstance: '50' }, { GeneralIndex: currencyId }
            ],
          },
        })
        .amount(amount)
        .address(address)
        .build();

An example of overriding destination in ParaToPara call:

return Builder(api)
        .from(from)
        .to({
          parents: 1,
          interior: {
            X1: {
            Parachain: nodeId
          }
          },
        })
        .currency(currency)
        .amount(amount)
        .address(address)
        .build();

However when the origin Parachain uses XTokens or XTransfer pallet MultiLocation destinations are not supported. In this case you need to use the address multilocation for both destination and address. Here is an example of such MultiLocation:

{
    parents: 1,
    interior: {
        X2: [{
                Parachain: nodeId
            },
            {
                AccountId32: {
                    network: 'any',
                    id: createAccountId(api, recipientAddress)
                }
            }
        ]
    }
}

For PolkadotXCM you can use all 3 options separately.

@michaeldev5 michaeldev5 self-assigned this Apr 12, 2024
Copy link

netlify bot commented Apr 12, 2024

Deploy Preview for light-spell ready!

Name Link
🔨 Latest commit 1326a0d
🔍 Latest deploy log https://app.netlify.com/sites/light-spell/deploys/6619a97f4d6e790008918435
😎 Deploy Preview https://deploy-preview-199--light-spell.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 97
Accessibility: 83
Best Practices: 100
SEO: 69
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Apr 12, 2024

Deploy Preview for poetic-heliotrope-212f1c ready!

Name Link
🔨 Latest commit 1326a0d
🔍 Latest deploy log https://app.netlify.com/sites/poetic-heliotrope-212f1c/deploys/6619a97f53a319000709fa0e
😎 Deploy Preview https://deploy-preview-199--poetic-heliotrope-212f1c.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@michaeldev5 michaeldev5 force-pushed the feature/override-multilocation branch 4 times, most recently from 79b4f60 to 8079c17 Compare April 12, 2024 19:58
@michaeldev5 michaeldev5 marked this pull request as ready for review April 12, 2024 20:00
@michaeldev5 michaeldev5 force-pushed the feature/override-multilocation branch from 8079c17 to 1ac0541 Compare April 12, 2024 20:09
@michaeldev5 michaeldev5 force-pushed the feature/override-multilocation branch from 1ac0541 to 1326a0d Compare April 12, 2024 21:37
@dudo50 dudo50 merged commit eb6cdbe into main Apr 13, 2024
9 checks passed
@dudo50 dudo50 deleted the feature/override-multilocation branch April 18, 2024 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants