Skip to content

Commit

Permalink
Update node pallets - monthly check 🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldev5 committed Dec 22, 2023
1 parent 2e228f9 commit e0d4f37
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 168 deletions.
103 changes: 51 additions & 52 deletions docs/supportedNodes.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
}
},
"dependencies": {
"@mangata-finance/sdk": "^2.1.1",
"@mangata-finance/type-definitions": "^2.1.2",
"ethers": "^5.7.1"
},
"peerDependencies": {
Expand Down
35 changes: 6 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion scripts/updateAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const nodeToQuery: NodeToAssetModuleMap = {
Darwinia: null, // No assets metadata query
HydraDX: 'assetRegistry.assetMetadataMap',
Interlay: 'assetRegistry.metadata',
Kylin: 'assets.metadata',
Litentry: null, // Assets query returns empty array
Moonbeam: 'assets.metadata',
Parallel: 'assets.metadata',
Expand Down
17 changes: 0 additions & 17 deletions src/maps/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -906,23 +906,6 @@
}
]
},
"Kylin": {
"paraId": 2052,
"relayChainAssetSymbol": "DOT",
"nativeAssets": [
{
"symbol": "KYL",
"decimals": 18
}
],
"otherAssets": [
{
"assetId": "1",
"symbol": "DOT",
"decimals": 0
}
]
},
"Litentry": {
"paraId": 2013,
"relayChainAssetSymbol": "DOT",
Expand Down
3 changes: 0 additions & 3 deletions src/maps/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Clover from '../nodes/supported/Clover'
import ComposableFinance from '../nodes/supported/ComposableFinance'
import HydraDX from '../nodes/supported/HydraDX'
import Interlay from '../nodes/supported/Interlay'
import Kylin from '../nodes/supported/Kylin'
import Litentry from '../nodes/supported/Litentry'
import Moonbeam from '../nodes/supported/Moonbeam'
import Parallel from '../nodes/supported/Parallel'
Expand Down Expand Up @@ -65,7 +64,6 @@ export const NODE_NAMES = [
'Darwinia',
'HydraDX',
'Interlay',
'Kylin',
'Litentry',
'Moonbeam',
'Parallel',
Expand Down Expand Up @@ -123,7 +121,6 @@ export const nodes: Record<TNode, ParachainNode> = {
Darwinia: new Darwinia(),
HydraDX: new HydraDX(),
Interlay: new Interlay(),
Kylin: new Kylin(),
Litentry: new Litentry(),
Moonbeam: new Moonbeam(),
Parallel: new Parallel(),
Expand Down
4 changes: 0 additions & 4 deletions src/maps/pallets.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
"defaultPallet": "XTokens",
"supportedPallets": ["PolkadotXcm", "XTokens"]
},
"Kylin": {
"defaultPallet": "OrmlXTokens",
"supportedPallets": ["PolkadotXcm", "OrmlXTokens"]
},
"Litentry": {
"defaultPallet": "XTokens",
"supportedPallets": ["PolkadotXcm", "XTokens"]
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/ParachainNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import {
} from '../utils'
import { constructRelayToParaParameters } from '../pallets/xcmPallet/utils'

const supportsXTokens = (obj: any): obj is IXTokensTransfer => {
export const supportsXTokens = (obj: any): obj is IXTokensTransfer => {
return 'transferXTokens' in obj
}

const supportsPolkadotXCM = (obj: any): obj is IPolkadotXCMTransfer => {
export const supportsPolkadotXCM = (obj: any): obj is IPolkadotXCMTransfer => {
return 'transferPolkadotXCM' in obj
}

Expand Down
81 changes: 78 additions & 3 deletions src/nodes/supported/Astar.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
// Contains detailed structure of XCM call construction for Astar Parachain

import { type ApiPromise } from '@polkadot/api'
import { NoXCMSupportImplementedError } from '../../errors'
import { getParaId } from '../../pallets/assets'
import {
type IPolkadotXCMTransfer,
type PolkadotXCMTransferInput,
Version,
type Extrinsic,
type TSerializedApiCall
type TSerializedApiCall,
type TNode,
type TScenario,
type IXTokensTransfer,
type XTokensTransferInput
} from '../../types'
import ParachainNode from '../ParachainNode'
import {
generateAddressPayload,
getFees,
createHeaderPolkadotXCM,
createCurrencySpecification
} from '../../utils'
import ParachainNode, { supportsPolkadotXCM, supportsXTokens } from '../ParachainNode'
import PolkadotXCMTransferImpl from '../PolkadotXCMTransferImpl'
import XTokensTransferImpl from '../XTokensTransferImpl'

class Astar extends ParachainNode implements IPolkadotXCMTransfer {
class Astar extends ParachainNode implements IPolkadotXCMTransfer, IXTokensTransfer {
constructor() {
super('Astar', 'astar', 'polkadot', Version.V3)
}
Expand All @@ -21,6 +35,67 @@ class Astar extends ParachainNode implements IPolkadotXCMTransfer {
input.scenario === 'ParaToPara' ? 'reserveTransferAssets' : 'reserveWithdrawAssets'
return PolkadotXCMTransferImpl.transferPolkadotXCM(input, method)
}

transferXTokens(input: XTokensTransferInput): Extrinsic | TSerializedApiCall {
return XTokensTransferImpl.transferXTokens(input, input.currencyID)
}

transfer(
api: ApiPromise,
currencySymbol: string | undefined,
currencyId: string | undefined,
amount: string,
to: string,
destination?: TNode,
serializedApiCallEnabled = false
): Extrinsic | TSerializedApiCall {
const scenario: TScenario = destination !== undefined ? 'ParaToPara' : 'ParaToRelay'
const paraId = destination !== undefined ? getParaId(destination) : undefined
const node = this.node
if (supportsXTokens(this) && currencySymbol !== 'ASTR') {
return this.transferXTokens({
api,
currency: currencySymbol,
currencyID: currencyId,
amount,
addressSelection: generateAddressPayload(
api,
scenario,
'XTokens',
to,
this.version,
paraId
),
fees: getFees(scenario),
scenario,
serializedApiCallEnabled
})
} else if (supportsPolkadotXCM(this)) {
return this.transferPolkadotXCM({
api,
header: createHeaderPolkadotXCM(scenario, this.version, paraId),
addressSelection: generateAddressPayload(
api,
scenario,
'PolkadotXcm',
to,
this.version,
paraId
),
currencySelection: createCurrencySpecification(
amount,
scenario,
this.version,
node,
currencyId
),
scenario,
currencySymbol,
serializedApiCallEnabled
})
}
throw new NoXCMSupportImplementedError(node)
}
}

export default Astar
22 changes: 10 additions & 12 deletions src/nodes/supported/Darwinia.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
// Contains detailed structure of XCM call construction for Darwinia Parachain

import {
type IPolkadotXCMTransfer,
type PolkadotXCMTransferInput,
Version,
type Extrinsic,
type TSerializedApiCall
type TSerializedApiCall,
type IXTokensTransfer,
type XTokensTransferInput
} from '../../types'
import { ScenarioNotSupportedError } from '../../errors/ScenarioNotSupportedError'
import ParachainNode from '../ParachainNode'
import PolkadotXCMTransferImpl from '../PolkadotXCMTransferImpl'
import { NodeNotSupportedError } from '../../errors'
import XTokensTransferImpl from '../XTokensTransferImpl'

class Darwinia extends ParachainNode implements IPolkadotXCMTransfer {
class Darwinia extends ParachainNode implements IXTokensTransfer {
constructor() {
super('Darwinia', 'darwinia', 'polkadot', Version.V3)
}

transferPolkadotXCM(input: PolkadotXCMTransferInput): Extrinsic | TSerializedApiCall {
// TESTED https://polkadot.subscan.io/xcm_message/polkadot-55c5c36c8fe8794c8cfbea725c9f8bc5984c6b05
if (input.scenario === 'ParaToPara') {
return PolkadotXCMTransferImpl.transferPolkadotXCM(input, 'reserveTransferAssets')
}
throw new ScenarioNotSupportedError(this.node, input.scenario)
transferXTokens(input: XTokensTransferInput): Extrinsic | TSerializedApiCall {
return XTokensTransferImpl.transferXTokens(
input,
input.currency === 'RING' ? 'SelfReserve' : { ForeignAsset: input.currencyID }
)
}

transferRelayToPara(): TSerializedApiCall {
Expand Down
24 changes: 0 additions & 24 deletions src/nodes/supported/Kylin.ts

This file was deleted.

28 changes: 24 additions & 4 deletions src/nodes/supported/Mangata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Contains detailed structure of XCM call construction for Mangata Parachain

import { type ApiPromise } from '@polkadot/api'
import { WsProvider, ApiPromise } from '@polkadot/api'
import {
type IXTokensTransfer,
Version,
Expand All @@ -10,6 +10,20 @@ import {
} from '../../types'
import ParachainNode from '../ParachainNode'
import XTokensTransferImpl from '../XTokensTransferImpl'
import { type ApiOptions } from '@polkadot/api/types'
import { mTypes, mRpc } from '@mangata-finance/type-definitions'

const options = ({ types = {}, rpc = {}, ...otherOptions }: ApiOptions = {}): ApiOptions => ({
types: {
...mTypes,
...types
},
rpc: {
...mRpc,
...rpc
},
...otherOptions
})

class Mangata extends ParachainNode implements IXTokensTransfer {
constructor() {
Expand All @@ -21,9 +35,15 @@ class Mangata extends ParachainNode implements IXTokensTransfer {
}

async createApiInstance(): Promise<ApiPromise> {
const MangataSDK = await import('@mangata-finance/sdk')
const instance = MangataSDK.Mangata.instance([this.getProvider()])
return await instance.api()
const provider = new WsProvider(this.getProvider())
return await ApiPromise.create(
options({
provider,
throwOnConnect: true,
throwOnUnknown: true,
noInitWarn: true
})
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/supported/Pendulum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import XTokensTransferImpl from '../XTokensTransferImpl'

class Pendulum extends ParachainNode implements IXTokensTransfer {
constructor() {
super('Pendulum', 'pendulum', 'polkadot', Version.V1)
super('Pendulum', 'pendulum', 'polkadot', Version.V3)
}

transferXTokens(input: XTokensTransferInput): Extrinsic | TSerializedApiCall {
Expand Down
Loading

0 comments on commit e0d4f37

Please sign in to comment.