Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more fixes and configuration adjustments #387

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ExtrinsicConfigBuilder } from '../../ExtrinsicBuilder.interfaces';
import {
getExtrinsicArgumentVersion,
normalizeConcrete,
normalizeX1,
} from '../../ExtrinsicBuilder.utils';
import {
getPolkadotXcmExtrinsicArgs,
Expand All @@ -22,54 +23,58 @@ export function polkadotXcm() {
new ExtrinsicConfig({
module: pallet,
func,
getArgs: (extrinsicFunction) =>
getPolkadotXcmExtrinsicArgs({
getArgs: (extrinsicFunction) => {
const version = getExtrinsicArgumentVersion(extrinsicFunction);
return getPolkadotXcmExtrinsicArgs({
...params,
func: extrinsicFunction,
asset: [
{
id: {
Concrete: {
parents: 0,
interior: 'Here',
},
},
id: normalizeConcrete(version, {
parents: 0,
interior: 'Here',
}),
fun: {
Fungible: params.asset.amount,
},
},
],
}),
});
},
}),
}),
X1: (): ExtrinsicConfigBuilder => ({
build: (params) =>
new ExtrinsicConfig({
module: pallet,
func,
getArgs: (extrinsicFunction) =>
getPolkadotXcmExtrinsicArgs({
getArgs: (extrinsicFunction) => {
const version = getExtrinsicArgumentVersion(extrinsicFunction);

return getPolkadotXcmExtrinsicArgs({
...params,
func: extrinsicFunction,
asset: [
{
id: {
Concrete: {
id: normalizeConcrete(
version,
normalizeX1(version, {
parents: 0,
interior: {
X1: {
PalletInstance:
params.asset.getAssetPalletInstance(),
},
},
},
},
}),
),
fun: {
Fungible: params.asset.amount,
},
},
],
}),
});
},
}),
}),
X2: (): ExtrinsicConfigBuilder => ({
Expand Down
51 changes: 26 additions & 25 deletions packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
type ExtrinsicConfigBuilder,
XcmVersion,
} from '../../ExtrinsicBuilder.interfaces';
import { getExtrinsicArgumentVersion } from '../../ExtrinsicBuilder.utils';
import {
getExtrinsicArgumentVersion,
normalizeConcrete,
normalizeX1,
} from '../../ExtrinsicBuilder.utils';
import { getDestination, getWeight } from './xTokens.utils';

const pallet = 'xTokens';
Expand Down Expand Up @@ -44,12 +48,10 @@ export function xTokens() {
return [
{
[version]: {
id: {
Concrete: {
parents: 0,
interior: 'Here',
},
},
id: normalizeConcrete(version, {
parents: 0,
interior: 'Here',
}),
fun: {
Fungible: asset.amount,
},
Expand All @@ -72,16 +74,17 @@ export function xTokens() {
return [
{
[version]: {
id: {
Concrete: {
id: normalizeConcrete(
version,
normalizeX1(version, {
parents: 1,
interior: {
X1: {
Parachain: originParachainId,
},
},
},
},
}),
),
fun: {
Fungible: asset.amount,
},
Expand All @@ -104,21 +107,19 @@ export function xTokens() {
return [
{
[version]: {
id: {
Concrete: {
parents: 1,
interior: {
X2: [
{
Parachain: originParachainId,
},
{
GeneralKey: asset.getAssetId(),
},
],
},
id: normalizeConcrete(version, {
parents: 1,
interior: {
X2: [
{
Parachain: originParachainId,
},
{
GeneralKey: asset.getAssetId(),
},
],
},
},
}),
fun: {
Fungible: asset.amount,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export function buildSendExtrinsic({

return sourceApi.tx.polkadotXcm.send(
{
// TODO apply XCM versioning
V3: {
parents: 1,
interior: { X1: { Parachain: moonChain.parachainId } },
Expand Down
7 changes: 7 additions & 0 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,9 @@ export const moonbaseAlpha = new EvmParachain({
ChainAsset.fromAsset(ftmwh, {
address: '0x566c1cebc6A4AFa1C122E039C4BEBe77043148Ee',
decimals: 18,
ids: {
palletInstance: 48,
},
}),
ChainAsset.fromAsset(hdx, {
address: '0xFFFfFfff345Dc44DDAE98Df024Eb494321E73FcC',
Expand All @@ -943,6 +946,9 @@ export const moonbaseAlpha = new EvmParachain({
ChainAsset.fromAsset(usdcwh, {
address: '0xE5dE10C4b744bac6b783fAF8d9B9fDFF14Acc3c9',
decimals: 6,
ids: {
palletInstance: 48,
},
}),
ChainAsset.fromAsset(agng, {
address: '0xFFfFFFFF38794F8c53fC7325ea07463dc6965e20',
Expand Down Expand Up @@ -2228,6 +2234,7 @@ export const chainsList: AnyChain[] = [
moonriver,
neuroweb,
originTrailAlphanet,
peaqAlphanet,
peaqChain,
peaqEvm,
peaqEvmAlphanet,
Expand Down
52 changes: 1 addition & 51 deletions packages/config/src/xcm-configs/moonbaseBeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ExtrinsicBuilder,
FeeBuilder,
} from '@moonbeam-network/xcm-builder';
import { alan, betaDEV, dev, ftmwh, usdcwh } from '../assets';
import { alan, betaDEV, dev } from '../assets';
import { moonbaseAlpha, moonbaseBeta } from '../chains';
import { ChainRoutes } from '../types/ChainRoutes';

Expand Down Expand Up @@ -60,55 +60,5 @@ export const moonbaseBetaRoutes = new ChainRoutes({
},
extrinsic: ExtrinsicBuilder().xTokens().transferMultiCurrencies(),
},
{
source: {
asset: usdcwh,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
asset: betaDEV,
balance: BalanceBuilder().substrate().system().account(),
},
destinationFee: {
balance: BalanceBuilder().substrate().system().account(),
},
},
destination: {
asset: usdcwh,
chain: moonbaseAlpha,
balance: BalanceBuilder().evm().erc20(),
fee: {
amount: FeeBuilder()
.xcmPaymentApi()
.xcmPaymentFee({ isAssetReserveChain: true }),
asset: dev,
},
},
extrinsic: ExtrinsicBuilder().xTokens().transferMultiCurrencies(),
},
{
source: {
asset: ftmwh,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
asset: betaDEV,
balance: BalanceBuilder().substrate().system().account(),
},
destinationFee: {
balance: BalanceBuilder().substrate().system().account(),
},
},
destination: {
asset: ftmwh,
chain: moonbaseAlpha,
balance: BalanceBuilder().evm().erc20(),
fee: {
amount: FeeBuilder()
.xcmPaymentApi()
.xcmPaymentFee({ isAssetReserveChain: true }),
asset: dev,
},
},
extrinsic: ExtrinsicBuilder().xTokens().transferMultiCurrencies(),
},
],
});
2 changes: 1 addition & 1 deletion packages/config/src/xcm-configs/moonbeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ export const moonbeamRoutes = new ChainRoutes({
chain: darwinia,
balance: BalanceBuilder().substrate().system().account(),
fee: {
amount: 4,
amount: 0.1,
asset: ring,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/xcm-configs/moonriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const moonriverRoutes = new ChainRoutes({
chain: darwiniaCrab,
balance: BalanceBuilder().substrate().system().account(),
fee: {
amount: 4,
amount: 0.1,
asset: crab,
},
},
Expand Down
38 changes: 6 additions & 32 deletions packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ exports[`sdk > getParachainBalances > on 'Moonbase Alpha' for address: '0x4E8214
"address": "0x566c1cebc6A4AFa1C122E039C4BEBe77043148Ee",
"amount": 1234567890000000000n,
"decimals": 18,
"ids": undefined,
"ids": {
"palletInstance": 48,
},
"key": "ftmwh",
"min": undefined,
"originSymbol": "FTM.wh",
Expand All @@ -358,7 +360,9 @@ exports[`sdk > getParachainBalances > on 'Moonbase Alpha' for address: '0x4E8214
"address": "0xE5dE10C4b744bac6b783fAF8d9B9fDFF14Acc3c9",
"amount": 10000n,
"decimals": 6,
"ids": undefined,
"ids": {
"palletInstance": 48,
},
"key": "usdcwh",
"min": undefined,
"originSymbol": "USDC.Wh",
Expand Down Expand Up @@ -475,36 +479,6 @@ exports[`sdk > getParachainBalances > on 'Moonbase Alpha' for address: '0x4E8214

exports[`sdk > getParachainBalances > on 'Moonbase Beta' for address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e8…' > should get expected balances 1`] = `
[
_AssetAmount {
"address": undefined,
"amount": 100000000000000000n,
"decimals": 18,
"ids": {
"balanceId": "198801030527939140930753142903035039136",
"id": {
"ForeignAsset": "198801030527939140930753142903035039136",
},
},
"key": "ftmwh",
"min": undefined,
"originSymbol": "FTM.wh",
"symbol": undefined,
},
_AssetAmount {
"address": undefined,
"amount": 0n,
"decimals": 6,
"ids": {
"balanceId": "319794858556516669238969276945382613133",
"id": {
"ForeignAsset": "319794858556516669238969276945382613133",
},
},
"key": "usdcwh",
"min": undefined,
"originSymbol": "USDC.Wh",
"symbol": undefined,
},
_AssetAmount {
"address": undefined,
"amount": 1100000000000000000n,
Expand Down