Skip to content

Commit ce25960

Browse files
committed
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.
1 parent 4300de7 commit ce25960

File tree

9 files changed

+20
-24
lines changed

9 files changed

+20
-24
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Astar Portal is the hub of a multi-chain, one-stop platform for managing assets and dApp Staking - build2earn protocol.",
55
"productName": "Astar Portal - Astar & Shiden Network",
66
"author": "Astar Network",
7+
"private": false,
78
"license": "GPL-3.0-only",
89
"scripts": {
910
"dev": "quasar dev",

src/v2/repositories/implementations/XcmRepository.ts

Lines changed: 8 additions & 6 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 = 'V5';
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 = 'V5';
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-
V5: {
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-
V5: {
224+
[this.xcmVersion]: {
223225
interior: {
224226
X1: {
225227
AccountId32: {

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-
V5: {
50+
[this.xcmVersion]: {
5151
parents: '1',
5252
interior: {
5353
X2: [

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class AstarXcmRepository extends XcmRepository {
5050
};
5151

5252
const assets = {
53-
V5: {
53+
[this.xcmVersion]: {
5454
fun: {
5555
Fungible: new BN(amount),
5656
},
@@ -73,7 +73,7 @@ export class AstarXcmRepository extends XcmRepository {
7373
};
7474

7575
const destination = {
76-
V5: {
76+
[this.xcmVersion]: {
7777
interior: {
7878
X2: [
7979
{
@@ -97,7 +97,7 @@ export class AstarXcmRepository extends XcmRepository {
9797
if (feeAssetInformation.feeAssetIsRequired) {
9898
// we need to use another token for the fee
9999
const fee = {
100-
V5: {
100+
[this.xcmVersion]: {
101101
fun: {
102102
Fungible: new BN(feeAssetInformation.feeAmount),
103103
},

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 = 'V5';
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 = 'V5';
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-
V5: {
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 = 'V5';
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 = 'V5';
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)