Skip to content

Commit

Permalink
apply PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Sep 24, 2024
1 parent 59925ef commit 2b96c57
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/builder/src/fee/FeeBuilder.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export interface FeeConfigBuilder {

export interface FeeConfigBuilderPrams {
address: string;
asset: ChainAssetId;
api: ApiPromise;
feeAsset: ChainAssetId;
transferAsset: ChainAssetId;
chain: AnyParachain;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/builder/src/fee/FeeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function xcmPaymentApi() {
isAssetReserveChain,
shouldTransferAssetPrecedeAsset = false,
}: XcmPaymentFeeProps): FeeConfigBuilder => ({
build: ({ address, api, asset, chain, transferAsset }) =>
build: ({ address, api, feeAsset, chain, transferAsset }) =>
new SubstrateCallConfig({
api,
call: async (): Promise<bigint> => {
const versionedAssetId = await getVersionedAssetId(
api,
asset,
feeAsset,
chain,
);
const versionedTransferAssetId = await getVersionedAssetId(
Expand All @@ -45,7 +45,7 @@ function xcmPaymentApi() {
: [versionedAssetId, versionedTransferAssetId];

const assets =
asset === transferAsset ? [versionedAssetId] : versionedAssets;
feeAsset === transferAsset ? [versionedAssetId] : versionedAssets;

const instructions = [
isAssetReserveChain
Expand Down
19 changes: 8 additions & 11 deletions packages/builder/src/fee/FeeBuilder.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable sort-keys */
import { AnyParachain, ChainAssetId } from '@moonbeam-network/xcm-types';
import { isHexString } from '@moonbeam-network/xcm-utils';
import { ApiPromise } from '@polkadot/api';
import { Option, Result, u128 } from '@polkadot/types';
import { Error as PolkadotError, Weight } from '@polkadot/types/interfaces';
Expand All @@ -11,14 +12,14 @@ const DEFAULT_AMOUNT = 10 ** 6;
const DEFALUT_HEX_STRING =
'0xabcdef1234567890fedcba0987654321abcdef1234567890fedcba0987654321';

const moonChainNativeAssetId = '0x0000000000000000000000000000000000000802';
const MOON_CHAIN_NATIVE_ASSET_ID = '0x0000000000000000000000000000000000000802';

const moonChainBalancesPalletInstance: Record<string, string> = {
const MOON_CHAIN_BALANCES_PALLET_INSTANCE: Record<string, string> = {
moonbeam: '10',
moonriver: '10',
'moonbase-alpha': '3',
};
const moonChainERC20PalletPalletInstance: Record<string, string> = {
const MOON_CHIAN_ERC20_PALLET_INSTANCE: Record<string, string> = {
moonbeam: '110',
moonriver: '110',
'moonbase-alpha': '48',
Expand All @@ -31,7 +32,7 @@ function isXcmV4() {
}

function normalizeX1(assetType: Record<string, AnyJson>) {
if (!isXcmV4) {
if (!isXcmV4()) {
return assetType;
}
const normalizedAssetType = { ...assetType };
Expand Down Expand Up @@ -136,7 +137,7 @@ function applyConcreteWrapper(id: object) {
// TODO this is for Moonbeam
function getNativeAssetId(chainKey: string): object {
const palletInstance = {
PalletInstance: moonChainBalancesPalletInstance[chainKey],
PalletInstance: MOON_CHAIN_BALANCES_PALLET_INSTANCE[chainKey],
};
const id = {
interior: {
Expand All @@ -148,10 +149,6 @@ function getNativeAssetId(chainKey: string): object {
return isXcmV4() ? id : applyConcreteWrapper(id);
}

function isHexString(asset: ChainAssetId): boolean {
return typeof asset === 'string' && asset.startsWith('0x');
}

function getConcreteAssetIdWithAccountKey20(
asset: ChainAssetId,
chainKey: string,
Expand All @@ -160,7 +157,7 @@ function getConcreteAssetIdWithAccountKey20(
interior: {
X2: [
{
PalletInstance: moonChainERC20PalletPalletInstance[chainKey],
PalletInstance: MOON_CHIAN_ERC20_PALLET_INSTANCE[chainKey],
},
{
AccountKey20: {
Expand Down Expand Up @@ -195,7 +192,7 @@ export async function getVersionedAssetId(
asset: ChainAssetId,
chain: AnyParachain,
): Promise<object> {
if (asset === moonChainNativeAssetId) {
if (asset === MOON_CHAIN_NATIVE_ASSET_ID) {
return getNativeAssetId(chain.key);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/getTransferData/getDestinationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ export async function getFee({
const cfg = (amount as FeeConfigBuilder).build({
address,
api: polkadot.api,
asset: polkadot.chain.getRegisteredAssetIdOrAddress(asset),
chain: polkadot.chain,
feeAsset: polkadot.chain.getRegisteredAssetIdOrAddress(asset),
transferAsset: polkadot.chain.getRegisteredAssetIdOrAddress(config.asset),
});

Expand Down
3 changes: 3 additions & 0 deletions packages/utils/src/format/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isHexString(asset: unknown): boolean {
return typeof asset === 'string' && asset.startsWith('0x');
}
1 change: 1 addition & 0 deletions packages/utils/src/format/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './address';
export * from './asset';

0 comments on commit 2b96c57

Please sign in to comment.