Skip to content

Commit bf53165

Browse files
authored
STINK integration with Moonbeam (#266)
* stink initial configuration * add function to determine feeAsset position repsecting asset * add chanset
1 parent 193957e commit bf53165

File tree

7 files changed

+92
-7
lines changed

7 files changed

+92
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@moonbeam-network/xcm-builder': patch
3+
'@moonbeam-network/xcm-config': patch
4+
'@moonbeam-network/xcm-sdk': patch
5+
---
6+
7+
STINK integration with Moonbeam

packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* eslint-disable sort-keys */
22
import { ExtrinsicConfigBuilder } from '../../ExtrinsicBuilder.interfaces';
33
import { ExtrinsicConfig } from '../../ExtrinsicConfig';
4-
import { getPolkadotXcmExtrinsicArgs } from './polkadotXcm.util';
4+
import {
5+
getPolkadotXcmExtrinsicArgs,
6+
shouldFeeAssetPrecedeAsset,
7+
} from './polkadotXcm.util';
58

69
const pallet = 'polkadotXcm';
710

@@ -73,7 +76,7 @@ export function polkadotXcm() {
7376
getArgs: (extrinsicFunction) => {
7477
const isAssetDifferent =
7578
!!params.feeAsset && params.asset !== params.feeAsset;
76-
const asset = [
79+
const assets = [
7780
{
7881
id: {
7982
Concrete: {
@@ -96,8 +99,11 @@ export function polkadotXcm() {
9699
},
97100
];
98101

102+
const shouldFeeAssetPrecede =
103+
shouldFeeAssetPrecedeAsset(params);
104+
99105
if (isAssetDifferent) {
100-
asset.push({
106+
const feeAsset = {
101107
id: {
102108
Concrete: {
103109
parents: 0,
@@ -116,14 +122,20 @@ export function polkadotXcm() {
116122
fun: {
117123
Fungible: params.fee,
118124
},
119-
});
125+
};
126+
127+
if (shouldFeeAssetPrecede) {
128+
assets.unshift(feeAsset);
129+
} else {
130+
assets.push(feeAsset);
131+
}
120132
}
121133

122134
return getPolkadotXcmExtrinsicArgs({
123135
...params,
124136
func: extrinsicFunction,
125-
asset,
126-
feeIndex: isAssetDifferent ? 1 : 0,
137+
asset: assets,
138+
feeIndex: isAssetDifferent && !shouldFeeAssetPrecede ? 1 : 0,
127139
});
128140
},
129141
}),

packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ export function getPolkadotXcmExtrinsicArgs({
5555
'Unlimited',
5656
];
5757
}
58+
59+
export function shouldFeeAssetPrecedeAsset({
60+
asset,
61+
feeAsset,
62+
}: ExtrinsicConfigBuilderPrams): boolean {
63+
const assetIdNumber = Number(asset);
64+
const feeAssetIdNumber = Number(feeAsset);
65+
66+
if (Number.isNaN(assetIdNumber) || Number.isNaN(feeAssetIdNumber)) {
67+
return false;
68+
}
69+
70+
return assetIdNumber > feeAssetIdNumber;
71+
}

packages/config/src/assets.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ export const soon = new Asset({
250250
originSymbol: 'SOON',
251251
});
252252

253+
export const stink = new Asset({
254+
key: 'stink',
255+
originSymbol: 'STINK',
256+
});
257+
253258
export const sub = new Asset({
254259
key: 'sub',
255260
originSymbol: 'SUB',
@@ -421,6 +426,7 @@ export const assetsList: Asset[] = [
421426
rmrk,
422427
sdn,
423428
soon,
429+
stink,
424430
sub,
425431
teer,
426432
tnkr,

packages/config/src/chains.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
ring,
5656
rmrk,
5757
sdn,
58+
stink,
5859
sub,
5960
teer,
6061
tnkr,
@@ -1062,6 +1063,10 @@ export const moonbeam = new EvmParachain({
10621063
asset: pink,
10631064
id: '64174511183114006009298114091987195453',
10641065
},
1066+
{
1067+
asset: stink,
1068+
id: '112679793397406599376365943185137098326',
1069+
},
10651070
],
10661071
ecosystem: Ecosystem.Polkadot,
10671072
genesisHash:
@@ -1685,6 +1690,11 @@ export const polkadotAssetHub = new Parachain({
16851690
id: 23,
16861691
palletInstance: 50,
16871692
},
1693+
{
1694+
asset: stink,
1695+
id: 42069,
1696+
palletInstance: 50,
1697+
},
16881698
],
16891699
ecosystem: Ecosystem.Polkadot,
16901700
genesisHash:

packages/config/src/configs/moonbeam.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
pha,
2727
pink,
2828
ring,
29+
stink,
2930
sub,
3031
usdc,
3132
usdcwh,
@@ -519,6 +520,21 @@ export const moonbeamConfig = new ChainConfig({
519520
balance: BalanceBuilder().substrate().system().account(),
520521
},
521522
}),
523+
new AssetConfig({
524+
asset: stink,
525+
balance: BalanceBuilder().substrate().assets().account(),
526+
contract: ContractBuilder().Xtokens().transferMultiCurrencies(),
527+
destination: polkadotAssetHub,
528+
destinationFee: {
529+
amount: 0.2,
530+
asset: usdt,
531+
balance: BalanceBuilder().substrate().assets().account(),
532+
},
533+
fee: {
534+
asset: glmr,
535+
balance: BalanceBuilder().substrate().system().account(),
536+
},
537+
}),
522538
new AssetConfig({
523539
asset: hdx,
524540
balance: BalanceBuilder().substrate().assets().account(),

packages/config/src/configs/polkadotAssetHub.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
ExtrinsicBuilder,
55
FeeBuilder,
66
} from '@moonbeam-network/xcm-builder';
7-
import { ded, dot, pink, usdc, usdt } from '../assets';
7+
import { ded, dot, pink, stink, usdc, usdt } from '../assets';
88
import { moonbeam, polkadotAssetHub } from '../chains';
99
import { AssetConfig } from '../types/AssetConfig';
1010
import { ChainConfig } from '../types/ChainConfig';
@@ -93,6 +93,26 @@ export const polkadotAssetHubConfig = new ChainConfig({
9393
},
9494
min: AssetMinBuilder().assets().asset(),
9595
}),
96+
new AssetConfig({
97+
asset: stink,
98+
balance: BalanceBuilder().substrate().assets().account(),
99+
destination: moonbeam,
100+
destinationFee: {
101+
amount: 0.03,
102+
asset: usdt,
103+
balance: BalanceBuilder().substrate().assets().account(),
104+
},
105+
extrinsic: ExtrinsicBuilder()
106+
.polkadotXcm()
107+
.limitedReserveTransferAssets()
108+
.X2(),
109+
fee: {
110+
asset: dot,
111+
balance: BalanceBuilder().substrate().system().account(),
112+
xcmDeliveryFeeAmount,
113+
},
114+
min: AssetMinBuilder().assets().asset(),
115+
}),
96116
],
97117
chain: polkadotAssetHub,
98118
});

0 commit comments

Comments
 (0)