Skip to content

Commit c1320ed

Browse files
committed
feat: use xcm v5
1 parent f5093ac commit c1320ed

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

src/api/clients/pasAh.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createClient } from "polkadot-api"
22
import { getSmProvider } from "polkadot-api/sm-provider"
33
import { smoldot } from "./smoldot"
44
import { pasRelayChain } from "./pas"
5+
import { withLogsRecorder } from "polkadot-api/logs-provider"
56

67
const smoldotParaChain = Promise.all([
78
pasRelayChain,
@@ -10,4 +11,8 @@ const smoldotParaChain = Promise.all([
1011
smoldot.addChain({ chainSpec, potentialRelayChains: [relayChain] }),
1112
)
1213

13-
export const pasAhClient = createClient(getSmProvider(smoldotParaChain))
14+
export const pasAhClient = createClient(
15+
withLogsRecorder((l) => {
16+
console.log(l)
17+
}, getSmProvider(smoldotParaChain)),
18+
)

src/api/common.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { AccountId, PolkadotSigner, TypedApi } from "polkadot-api"
22
import {
3-
XcmV3Junction,
4-
XcmV3JunctionNetworkId,
5-
XcmV3Junctions,
63
XcmV3MultiassetFungibility,
74
XcmV3WeightLimit,
5+
XcmV5Junction,
6+
XcmV5Junctions,
7+
XcmV5NetworkId,
88
XcmVersionedAssets,
99
XcmVersionedLocation,
1010
dotAh,
@@ -15,10 +15,10 @@ import { combineLatest, from, map } from "rxjs"
1515
const encodeAccount = AccountId().enc
1616

1717
export const getBeneficiary = (address: SS58String | Uint8Array) =>
18-
XcmVersionedLocation.V4({
18+
XcmVersionedLocation.V5({
1919
parents: 0,
20-
interior: XcmV3Junctions.X1(
21-
XcmV3Junction.AccountId32({
20+
interior: XcmV5Junctions.X1(
21+
XcmV5Junction.AccountId32({
2222
network: undefined,
2323
id: Binary.fromBytes(
2424
address instanceof Uint8Array ? address : encodeAccount(address),
@@ -28,11 +28,11 @@ export const getBeneficiary = (address: SS58String | Uint8Array) =>
2828
})
2929

3030
export const getNativeAsset = (parents: number, amount: bigint) =>
31-
XcmVersionedAssets.V4([
31+
XcmVersionedAssets.V5([
3232
{
3333
id: {
3434
parents,
35-
interior: XcmV3Junctions.Here(),
35+
interior: XcmV5Junctions.Here(),
3636
},
3737
fun: XcmV3MultiassetFungibility.Fungible(amount),
3838
},
@@ -50,9 +50,9 @@ export const fromRelayToParachain = (
5050
amount: bigint,
5151
to?: SS58String,
5252
) => ({
53-
dest: XcmVersionedLocation.V4({
53+
dest: XcmVersionedLocation.V5({
5454
parents: 0,
55-
interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(paraId)),
55+
interior: XcmV5Junctions.X1(XcmV5Junction.Parachain(paraId)),
5656
}),
5757
beneficiary: getBeneficiary(to ?? from.publicKey),
5858
assets: getNativeAsset(0, amount),
@@ -65,9 +65,9 @@ export const fromAssetHubToRelay = (
6565
amount: bigint,
6666
to?: SS58String,
6767
) => ({
68-
dest: XcmVersionedLocation.V4({
68+
dest: XcmVersionedLocation.V5({
6969
parents: 1,
70-
interior: XcmV3Junctions.Here(),
70+
interior: XcmV5Junctions.Here(),
7171
}),
7272
beneficiary: getBeneficiary(to ?? from.publicKey),
7373
assets: getNativeAsset(1, amount),
@@ -76,17 +76,17 @@ export const fromAssetHubToRelay = (
7676
})
7777

7878
export const fromAssetHubToForeign = (
79-
network: XcmV3JunctionNetworkId,
79+
network: XcmV5NetworkId,
8080
parachainId: number,
8181
assets: XcmVersionedAssets,
8282
from: PolkadotSigner,
8383
to?: SS58String,
8484
) => ({
85-
dest: XcmVersionedLocation.V4({
85+
dest: XcmVersionedLocation.V5({
8686
parents: 2,
87-
interior: XcmV3Junctions.X2([
88-
XcmV3Junction.GlobalConsensus(network),
89-
XcmV3Junction.Parachain(parachainId),
87+
interior: XcmV5Junctions.X2([
88+
XcmV5Junction.GlobalConsensus(network),
89+
XcmV5Junction.Parachain(parachainId),
9090
]),
9191
}),
9292
beneficiary: getBeneficiary(to ?? from.publicKey),
@@ -137,7 +137,7 @@ export const watchForeingAssetAccoutFreeBalance =
137137
}
138138
}
139139
},
140-
asset: { parents: number; interior: XcmV3Junctions },
140+
asset: { parents: number; interior: XcmV5Junctions },
141141
) =>
142142
(account: SS58String) =>
143143
api.query.ForeignAssets.Account.watchValue(asset, account, "best").pipe(

src/api/dot/ah.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2-
XcmV3Junction,
3-
XcmV3JunctionNetworkId,
4-
XcmV3Junctions,
2+
XcmV5Junction,
3+
XcmV5Junctions,
4+
XcmV5NetworkId,
55
XcmVersionedLocation,
66
dotAh,
77
} from "@polkadot-api/descriptors"
@@ -27,7 +27,7 @@ const dot: AssetInChain = {
2727
ksmAh: (from, amount, to) =>
2828
api.tx.PolkadotXcm.transfer_assets(
2929
fromAssetHubToForeign(
30-
XcmV3JunctionNetworkId.Kusama(),
30+
XcmV5NetworkId.Kusama(),
3131
1000,
3232
getNativeAsset(1, amount),
3333
from,
@@ -37,10 +37,10 @@ const dot: AssetInChain = {
3737
},
3838
}
3939

40-
const ksmInDotAh: Parameters<typeof XcmVersionedLocation.V4>[0] = {
40+
const ksmInDotAh: Parameters<typeof XcmVersionedLocation.V5>[0] = {
4141
parents: 2,
42-
interior: XcmV3Junctions.X1(
43-
XcmV3Junction.GlobalConsensus(XcmV3JunctionNetworkId.Kusama()),
42+
interior: XcmV5Junctions.X1(
43+
XcmV5Junction.GlobalConsensus(XcmV5NetworkId.Kusama()),
4444
),
4545
}
4646

src/api/ksm/ah.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2-
XcmV3Junction,
3-
XcmV3JunctionNetworkId,
4-
XcmV3Junctions,
2+
XcmV5Junction,
3+
XcmV5Junctions,
4+
XcmV5NetworkId,
55
XcmVersionedLocation,
66
ksmAh,
77
} from "@polkadot-api/descriptors"
@@ -27,7 +27,7 @@ const ksm: AssetInChain = {
2727
dotAh: (from, amount, to) =>
2828
api.tx.PolkadotXcm.transfer_assets(
2929
fromAssetHubToForeign(
30-
XcmV3JunctionNetworkId.Polkadot(),
30+
XcmV5NetworkId.Polkadot(),
3131
1000,
3232
getNativeAsset(1, amount),
3333
from,
@@ -37,10 +37,10 @@ const ksm: AssetInChain = {
3737
},
3838
}
3939

40-
const dotInKsmAh: Parameters<typeof XcmVersionedLocation.V4>[0] = {
40+
const dotInKsmAh: Parameters<typeof XcmVersionedLocation.V5>[0] = {
4141
parents: 2,
42-
interior: XcmV3Junctions.X1(
43-
XcmV3Junction.GlobalConsensus(XcmV3JunctionNetworkId.Polkadot()),
42+
interior: XcmV5Junctions.X1(
43+
XcmV5Junction.GlobalConsensus(XcmV5NetworkId.Polkadot()),
4444
),
4545
}
4646

0 commit comments

Comments
 (0)