Skip to content

Commit

Permalink
Refactor relay to para scenario 🧹
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldev5 committed Nov 24, 2023
1 parent 2ec2723 commit ccac9f1
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 88 deletions.
4 changes: 2 additions & 2 deletions src/errors/NodeNotSupportedError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Used to inform user, that Parachain they wish to use is not supported yet

export class NodeNotSupportedError extends Error {
constructor(message: string) {
super(message)
constructor(message?: string) {
super(message ?? 'These nodes do not support XCM transfers from Relay / to Relay chain.')
this.name = 'NodeNotSupported'
}
}
14 changes: 12 additions & 2 deletions src/nodes/ParachainNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import {
type TScenario,
type IXTokensTransfer,
type IPolkadotXCMTransfer,
type Version,
type TSerializedApiCall
Version,
type TSerializedApiCall,
type TTransferRelayToParaOptions
} from '../types'
import {
generateAddressPayload,
getFees,
createHeaderPolkadotXCM,
createCurrencySpecification
} from '../utils'
import { constructRelayToParaParameters } from '../pallets/xcmPallet/utils'

const supportsXTokens = (obj: any): obj is IXTokensTransfer => {
return 'transferXTokens' in obj
Expand Down Expand Up @@ -127,6 +129,14 @@ abstract class ParachainNode {
throw new NoXCMSupportImplementedError(this._node)
}
}

transferRelayToPara(options: TTransferRelayToParaOptions): TSerializedApiCall {
return {
module: 'xcmPallet',
section: 'reserveTransferAssets',
parameters: constructRelayToParaParameters(options, Version.V3)
}
}
}

export default ParachainNode
12 changes: 11 additions & 1 deletion src/nodes/supported/AssetHubKusama.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Contains detailed structure of XCM call construction for AssetHubKusama Parachain

import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils'
import {
type IPolkadotXCMTransfer,
type PolkadotXCMTransferInput,
Version,
type Extrinsic,
type TSerializedApiCall
type TSerializedApiCall,
type TTransferRelayToParaOptions
} from '../../types'
import ParachainNode from '../ParachainNode'
import PolkadotXCMTransferImpl from '../PolkadotXCMTransferImpl'
Expand All @@ -20,6 +22,14 @@ class AssetHubKusama extends ParachainNode implements IPolkadotXCMTransfer {
// TESTED https://kusama.subscan.io/xcm_message/kusama-8e423130a4d8b61679af95dbea18a55124f99672
return PolkadotXCMTransferImpl.transferPolkadotXCM(input, 'limitedTeleportAssets', 'Unlimited')
}

transferRelayToPara(options: TTransferRelayToParaOptions): TSerializedApiCall {
return {
module: 'xcmPallet',
section: 'limitedTeleportAssets',
parameters: constructRelayToParaParameters(options, Version.V3, true)
}
}
}

export default AssetHubKusama
12 changes: 11 additions & 1 deletion src/nodes/supported/AssetHubPolkadot.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Contains detailed structure of XCM call construction for Statemint Parachain

import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils'
import {
type IPolkadotXCMTransfer,
type PolkadotXCMTransferInput,
Version,
type Extrinsic,
type TSerializedApiCall
type TSerializedApiCall,
type TTransferRelayToParaOptions
} from '../../types'
import ParachainNode from '../ParachainNode'
import PolkadotXCMTransferImpl from '../PolkadotXCMTransferImpl'
Expand All @@ -20,6 +22,14 @@ class AssetHubPolkadot extends ParachainNode implements IPolkadotXCMTransfer {
// TESTED https://polkadot.subscan.io/xcm_message/polkadot-c01158ff1a5c5a596138ed9d0f0f2bccc1d9c51d
return PolkadotXCMTransferImpl.transferPolkadotXCM(input, 'limitedTeleportAssets', 'Unlimited')
}

transferRelayToPara(options: TTransferRelayToParaOptions): TSerializedApiCall {
return {
module: 'xcmPallet',
section: 'limitedTeleportAssets',
parameters: constructRelayToParaParameters(options, Version.V3, true)
}
}
}

export default AssetHubPolkadot
5 changes: 5 additions & 0 deletions src/nodes/supported/Crab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { ScenarioNotSupportedError } from '../../errors/ScenarioNotSupportedError'
import ParachainNode from '../ParachainNode'
import PolkadotXCMTransferImpl from '../PolkadotXCMTransferImpl'
import { NodeNotSupportedError } from '../../errors'

class Crab extends ParachainNode implements IPolkadotXCMTransfer {
constructor() {
Expand All @@ -23,6 +24,10 @@ class Crab extends ParachainNode implements IPolkadotXCMTransfer {
}
throw new ScenarioNotSupportedError(this.node, input.scenario)
}

transferRelayToPara(): TSerializedApiCall {
throw new NodeNotSupportedError()
}
}

export default Crab
5 changes: 5 additions & 0 deletions src/nodes/supported/Darwinia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { ScenarioNotSupportedError } from '../../errors/ScenarioNotSupportedError'
import ParachainNode from '../ParachainNode'
import PolkadotXCMTransferImpl from '../PolkadotXCMTransferImpl'
import { NodeNotSupportedError } from '../../errors'

class Darwinia extends ParachainNode implements IPolkadotXCMTransfer {
constructor() {
Expand All @@ -23,6 +24,10 @@ class Darwinia extends ParachainNode implements IPolkadotXCMTransfer {
}
throw new ScenarioNotSupportedError(this.node, input.scenario)
}

transferRelayToPara(): TSerializedApiCall {
throw new NodeNotSupportedError()
}
}

export default Darwinia
12 changes: 11 additions & 1 deletion src/nodes/supported/Encointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
type PolkadotXCMTransferInput,
Version,
type Extrinsic,
type TSerializedApiCall
type TSerializedApiCall,
type TTransferRelayToParaOptions
} from '../../types'
import { ScenarioNotSupportedError } from '../../errors/ScenarioNotSupportedError'
import ParachainNode from '../ParachainNode'
import PolkadotXCMTransferImpl from '../PolkadotXCMTransferImpl'
import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils'

class Encointer extends ParachainNode implements IPolkadotXCMTransfer {
constructor() {
Expand All @@ -28,6 +30,14 @@ class Encointer extends ParachainNode implements IPolkadotXCMTransfer {
}
throw new ScenarioNotSupportedError(this.node, input.scenario)
}

transferRelayToPara(options: TTransferRelayToParaOptions): TSerializedApiCall {
return {
module: 'xcmPallet',
section: 'limitedTeleportAssets',
parameters: constructRelayToParaParameters(options, Version.V1, true)
}
}
}

export default Encointer
6 changes: 5 additions & 1 deletion src/nodes/supported/Integritee.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Contains detailed structure of XCM call construction for Integritee Parachain

import { InvalidCurrencyError } from '../../errors'
import { InvalidCurrencyError, NodeNotSupportedError } from '../../errors'
import {
type IXTokensTransfer,
Version,
Expand All @@ -21,6 +21,10 @@ class Integritee extends ParachainNode implements IXTokensTransfer {
throw new InvalidCurrencyError(`Node ${this.node} does not support currency KSM`)
return XTokensTransferImpl.transferXTokens(input, input.currency)
}

transferRelayToPara(): TSerializedApiCall {
throw new NodeNotSupportedError()
}
}

export default Integritee
12 changes: 11 additions & 1 deletion src/nodes/supported/Moonbeam.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Contains detailed structure of XCM call construction for Moonbeam Parachain

import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils'
import {
type IXTokensTransfer,
Version,
type XTokensTransferInput,
type Extrinsic,
type TSerializedApiCall
type TSerializedApiCall,
type TTransferRelayToParaOptions
} from '../../types'
import ParachainNode from '../ParachainNode'
import XTokensTransferImpl from '../XTokensTransferImpl'
Expand All @@ -20,6 +22,14 @@ class Moonbeam extends ParachainNode implements IXTokensTransfer {
const currencySelection = currency === 'GLMR' ? 'SelfReserve ' : { ForeignAsset: currencyID }
return XTokensTransferImpl.transferXTokens(input, currencySelection)
}

transferRelayToPara(options: TTransferRelayToParaOptions): TSerializedApiCall {
return {
module: 'xcmPallet',
section: 'limitedReserveTransferAssets',
parameters: constructRelayToParaParameters(options, Version.V3, true)
}
}
}

export default Moonbeam
12 changes: 11 additions & 1 deletion src/nodes/supported/Moonriver.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Contains detailed structure of XCM call construction for Moonriver Parachain

import { constructRelayToParaParameters } from '../../pallets/xcmPallet/utils'
import {
type IXTokensTransfer,
Version,
type XTokensTransferInput,
type Extrinsic,
type TSerializedApiCall
type TSerializedApiCall,
type TTransferRelayToParaOptions
} from '../../types'
import ParachainNode from '../ParachainNode'
import XTokensTransferImpl from '../XTokensTransferImpl'
Expand All @@ -20,6 +22,14 @@ class Moonriver extends ParachainNode implements IXTokensTransfer {
const currencySelection = currency === 'MOVR' ? 'SelfReserve ' : { ForeignAsset: currencyID }
return XTokensTransferImpl.transferXTokens(input, currencySelection)
}

transferRelayToPara(options: TTransferRelayToParaOptions): TSerializedApiCall {
return {
module: 'xcmPallet',
section: 'limitedReserveTransferAssets',
parameters: constructRelayToParaParameters(options, Version.V3, true)
}
}
}

export default Moonriver
10 changes: 9 additions & 1 deletion src/nodes/supported/Nodle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Contains detailed structure of XCM call construction for Nodle Parachain

import { InvalidCurrencyError, ScenarioNotSupportedError } from '../../errors'
import {
InvalidCurrencyError,
NodeNotSupportedError,
ScenarioNotSupportedError
} from '../../errors'
import {
type IXTokensTransfer,
Version,
Expand Down Expand Up @@ -29,6 +33,10 @@ class Nodle extends ParachainNode implements IXTokensTransfer {

return XTokensTransferImpl.transferXTokens(input, 'NodleNative')
}

transferRelayToPara(): TSerializedApiCall {
throw new NodeNotSupportedError()
}
}

export default Nodle
10 changes: 9 additions & 1 deletion src/nodes/supported/Pendulum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Contains detailed structure of XCM call construction for Pendulum Parachain

import { InvalidCurrencyError, ScenarioNotSupportedError } from '../../errors'
import {
InvalidCurrencyError,
NodeNotSupportedError,
ScenarioNotSupportedError
} from '../../errors'
import {
type IXTokensTransfer,
Version,
Expand Down Expand Up @@ -29,6 +33,10 @@ class Pendulum extends ParachainNode implements IXTokensTransfer {

return XTokensTransferImpl.transferXTokens(input, { XCM: input.currencyID })
}

transferRelayToPara(): TSerializedApiCall {
throw new NodeNotSupportedError()
}
}

export default Pendulum
Loading

0 comments on commit ccac9f1

Please sign in to comment.