Skip to content

Commit 290a72b

Browse files
gtg7784ayumitkimpelcrypto
authored
Fix portal compatibility with XCM V5 upgrade (#1483)
* remove astar 2.0 and tech stack link (#1455) * Fix `fetchAssetConfigById` for XCM v5 compatibility * Update all XCM message constructions from V3 to V5 * refactor: centralize XCM version management in base repository - Add protected readonly xcmVersion property to base XcmRepository class - Replace all hardcoded 'V5' strings with dynamic this.xcmVersion references - Remove unnecessary intermediate version variable assignments - Enable version override capability for child repositories when needed This change provides a single source of truth for XCM version configuration, making future version updates easier and maintaining consistency across all XCM repository implementations. * update to keep using `V3` for Pendulum and Interlay * Update to set V5 only for Astar * fix: updated XCM logix to apply V5 for withdrawal transactions (#1485) * fix: updated XCM logix to apply V5 * fix: removed non-used endpoint * fix: updated Phala endpoint --------- Co-authored-by: Ayumi Takahashi <[email protected]> Co-authored-by: Roy <[email protected]>
1 parent 399c281 commit 290a72b

File tree

11 files changed

+29363
-21542
lines changed

11 files changed

+29363
-21542
lines changed

src/components/header/mobile/AstarDomains.vue

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ export default defineComponent({
3838
img: icon_img.home,
3939
link: 'https://astar.network/',
4040
},
41-
{
42-
title: 'Astar 2.0',
43-
img: icon_img.astar2,
44-
link: 'https://astar.network/astar2',
45-
},
46-
{
47-
title: 'Tech Stack',
48-
img: icon_img.tech_stack,
49-
link: 'https://astar.network/developers/techstack',
50-
},
5141
{
5242
title: 'Astar Docs',
5343
img: icon_img.docs,

src/modules/xcm/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ export let xcmChainObj: XcmChainObj = {
286286
img: require('/src/assets/img/token/pha.png'),
287287
parachainId: parachainIds.PHALA,
288288
endpoints: [
289-
'wss://api.phala.network/ws',
290289
'wss://phala-rpc.dwellir.com',
291290
'wss://phala.api.onfinality.io/public-ws',
291+
'wss://rpc.helikon.io/phala',
292292
],
293293
subscan: 'https://phala.subscan.io',
294294
isAstarNativeToken: true,
@@ -298,10 +298,7 @@ export let xcmChainObj: XcmChainObj = {
298298
relayChain: Chain.POLKADOT,
299299
img: require('/src/assets/img/token/bnc.svg'),
300300
parachainId: parachainIds.BIFROST_POLKADOT,
301-
endpoints: [
302-
'wss://hk.p.bifrost-rpc.liebi.com/ws',
303-
'wss://bifrost-polkadot.api.onfinality.io/public-ws',
304-
],
301+
endpoints: ['wss://hk.p.bifrost-rpc.liebi.com/ws'],
305302
chopsticksEndpoint: 'ws://localhost:9947',
306303
subscan: 'https://bifrost.subscan.io',
307304
isAstarNativeToken: true,

src/v2/repositories/implementations/XcmRepository.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export const ASTAR_ADDRESS_PREFIX = 5;
4646

4747
@injectable()
4848
export class XcmRepository implements IXcmRepository {
49+
// XCM version to use for all message constructions
50+
protected readonly xcmVersion: 'V3' | 'V5' = 'V3';
51+
4952
// Ids of Astar tokens on foreign network. To be initialized in iherited class.
5053
protected astarTokens: TokenId;
5154

@@ -128,10 +131,9 @@ export class XcmRepository implements IXcmRepository {
128131
throw `Parachain id for ${to.name} is not defined`;
129132
}
130133

131-
const version = 'V3';
132134
// the target parachain connected to the current relaychain
133135
const destination = {
134-
[version]: {
136+
[this.xcmVersion]: {
135137
interior: {
136138
X1: {
137139
Parachain: new BN(to.parachainId),
@@ -149,7 +151,7 @@ export class XcmRepository implements IXcmRepository {
149151
};
150152

151153
const beneficiary = {
152-
[version]: {
154+
[this.xcmVersion]: {
153155
interior: {
154156
X1: {
155157
AccountId32,
@@ -160,7 +162,7 @@ export class XcmRepository implements IXcmRepository {
160162
};
161163

162164
const assets = {
163-
[version]: [
165+
[this.xcmVersion]: [
164166
{
165167
fun: {
166168
Fungible: amount,
@@ -210,7 +212,7 @@ export class XcmRepository implements IXcmRepository {
210212
};
211213

212214
const assets = {
213-
V3: {
215+
[this.xcmVersion]: {
214216
fun: {
215217
Fungible: new BN(amount),
216218
},
@@ -219,7 +221,7 @@ export class XcmRepository implements IXcmRepository {
219221
};
220222

221223
const destination = {
222-
V3: {
224+
[this.xcmVersion]: {
223225
interior: {
224226
X1: {
225227
AccountId32: {
@@ -305,7 +307,14 @@ export class XcmRepository implements IXcmRepository {
305307
const api = await this.apiFactory.get(endpoint);
306308
const config = await api.query.xcAssetConfig.assetIdToLocation<Option<AssetConfig>>(tokenId);
307309
const formattedAssetConfig = JSON.parse(config.toString());
308-
return formattedAssetConfig.v3;
310+
311+
// Get the first available version (v3, v4, v5, etc.)
312+
const versionKey = Object.keys(formattedAssetConfig)[0];
313+
if (!versionKey) {
314+
throw new Error('No version found in asset config');
315+
}
316+
317+
return formattedAssetConfig[versionKey];
309318
}
310319

311320
protected async fetchAssetConfig(

src/v2/repositories/implementations/xcm/AcalaXcmRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class AcalaXcmRepository extends XcmRepository {
4747
const tokenData = this.getTokenData(token);
4848

4949
const destination = {
50-
V3: {
50+
[this.xcmVersion]: {
5151
parents: '1',
5252
interior: {
5353
X2: [

src/v2/repositories/implementations/xcm/AstarXcmRepository.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getPubkeyFromSS58Addr } from '@astar-network/astar-sdk-core';
44
import { XcmTokenInformation } from 'src/modules/xcm';
55
import { container } from 'src/v2/common';
66
import { ExtrinsicPayload, IApi, IApiFactory } from 'src/v2/integration';
7-
import { Asset, Chain, ethWalletChains, XcmChain } from 'src/v2/models';
7+
import { Asset, ethWalletChains, XcmChain } from 'src/v2/models';
88
import { Symbols } from 'src/v2/symbols';
99
import { XcmRepository } from '../XcmRepository';
1010

@@ -13,6 +13,7 @@ import { XcmRepository } from '../XcmRepository';
1313
*/
1414
export class AstarXcmRepository extends XcmRepository {
1515
private astarNativeTokenId;
16+
protected readonly xcmVersion = 'V5';
1617

1718
constructor() {
1819
const defaultApi = container.get<IApi>(Symbols.DefaultApi);
@@ -39,18 +40,14 @@ export class AstarXcmRepository extends XcmRepository {
3940
const isWithdrawAssets = token.id !== this.astarNativeTokenId;
4041

4142
const asset = isWithdrawAssets
42-
? {
43-
Concrete: await this.fetchAssetConfig(from, token, endpoint),
44-
}
43+
? await this.fetchAssetConfig(from, token, endpoint)
4544
: {
46-
Concrete: {
47-
interior: 'Here',
48-
parents: new BN(0),
49-
},
45+
interior: 'Here',
46+
parents: new BN(0),
5047
};
5148

5249
const assets = {
53-
V3: {
50+
[this.xcmVersion]: {
5451
fun: {
5552
Fungible: new BN(amount),
5653
},
@@ -73,7 +70,7 @@ export class AstarXcmRepository extends XcmRepository {
7370
};
7471

7572
const destination = {
76-
V3: {
73+
[this.xcmVersion]: {
7774
interior: {
7875
X2: [
7976
{
@@ -97,7 +94,7 @@ export class AstarXcmRepository extends XcmRepository {
9794
if (feeAssetInformation.feeAssetIsRequired) {
9895
// we need to use another token for the fee
9996
const fee = {
100-
V3: {
97+
[this.xcmVersion]: {
10198
fun: {
10299
Fungible: new BN(feeAssetInformation.feeAmount),
103100
},

src/v2/repositories/implementations/xcm/BifrostXcmRepository.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ export class BifrostXcmRepository extends XcmRepository {
5858
throw `Token name for ${token.originAssetId} is not defined`;
5959
}
6060

61-
const version = 'V3';
62-
6361
const AccountId32 = {
6462
id: decodeAddress(recipientAddress),
6563
};
6664

6765
const destination = {
68-
[version]: {
66+
[this.xcmVersion]: {
6967
parents: '1',
7068
interior: {
7169
X2: [

src/v2/repositories/implementations/xcm/HydrationXcmRepository.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ export class HydrationXcmRepository extends XcmRepository {
4343
throw `Token name for ${token.originAssetId} is not defined`;
4444
}
4545

46-
const version = 'V3';
47-
4846
const AccountId32 = {
4947
id: decodeAddress(recipientAddress),
5048
};
5149

5250
const destination = {
53-
[version]: {
51+
[this.xcmVersion]: {
5452
parents: '1',
5553
interior: {
5654
X2: [

src/v2/repositories/implementations/xcm/InterlayXcmRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class InterlayXcmRepository extends XcmRepository {
3535
const tokenData = { Token: token.originAssetId };
3636

3737
const destination = {
38-
V3: {
38+
[this.xcmVersion]: {
3939
parents: '1',
4040
interior: {
4141
X2: [

src/v2/repositories/implementations/xcm/PendulumXcmRepository.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ export class PendulumXcmRepository extends XcmRepository {
4040
throw `Token name for ${token.originAssetId} is not defined`;
4141
}
4242

43-
const version = 'V3';
44-
4543
const AccountId32 = {
4644
id: decodeAddress(recipientAddress),
4745
};
4846

4947
const destination = {
50-
[version]: {
48+
[this.xcmVersion]: {
5149
parents: '1',
5250
interior: {
5351
X2: [

src/v2/repositories/implementations/xcm/StatemintXcmRepository.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ export class StatemintXcmRepository extends XcmRepository {
3535
throw `Parachain id for ${to.name} is not defined`;
3636
}
3737

38-
const version = 'V3';
3938
const destination = {
40-
[version]: {
39+
[this.xcmVersion]: {
4140
interior: {
4241
X1: {
4342
Parachain: to.parachainId,
@@ -52,7 +51,7 @@ export class StatemintXcmRepository extends XcmRepository {
5251
};
5352

5453
const beneficiary = {
55-
[version]: {
54+
[this.xcmVersion]: {
5655
interior: {
5756
X1: {
5857
AccountId32,
@@ -68,7 +67,7 @@ export class StatemintXcmRepository extends XcmRepository {
6867
const instance = 50;
6968

7069
const assets = {
71-
[version]: [
70+
[this.xcmVersion]: [
7271
{
7372
fun: {
7473
Fungible: new BN(amount),

0 commit comments

Comments
 (0)