Skip to content

Commit

Permalink
-wip- fix some types
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Sep 18, 2024
1 parent 3859d60 commit b552b63
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
19 changes: 10 additions & 9 deletions packages/builder/src/fee/FeeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ function xcmPaymentApi() {
// TODO mjm rename assetId?
const versionedAssetId = await getVersionedAssetId(api, asset);
console.log('versionedAssetId', versionedAssetId);

Check warning on line 58 in packages/builder/src/fee/FeeBuilder.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
const assets = [versionedAssetId];

const instructions = [
getWithdrawAssetInstruction([versionedAssetId]),
getWithdrawAssetInstruction(assets),
getClearOriginInstruction(),
getBuyExecutionInstruction(versionedAssetId),
getDepositAssetInstruction(address),
getDepositAssetInstruction(address, assets),
];

return getFeeForXcmInstructionsAndAsset(
Expand All @@ -78,12 +79,13 @@ function xcmPaymentApi() {
api,
call: async (): Promise<bigint> => {
const versionedAssetId = await getVersionedAssetId(api, asset);
const assets = [versionedAssetId];

const instructions = [
getWithdrawAssetInstruction([versionedAssetId]),
getWithdrawAssetInstruction(assets),
getClearOriginInstruction(),
getBuyExecutionInstruction(versionedAssetId),
getDepositAssetInstruction(address),
getDepositAssetInstruction(address, assets),
];

return getFeeForXcmInstructionsAndAsset(
Expand All @@ -105,14 +107,13 @@ function xcmPaymentApi() {
transferAsset,
);

const assets = [versionedAssetId, versionedTransferAssetId];

const instructions = [
getWithdrawAssetInstruction([
versionedAssetId,
versionedTransferAssetId,
]),
getWithdrawAssetInstruction(assets),
getClearOriginInstruction(),
getBuyExecutionInstruction(versionedAssetId),
getDepositAssetInstruction(address),
getDepositAssetInstruction(address, assets),
];

return getFeeForXcmInstructionsAndAsset(
Expand Down
50 changes: 28 additions & 22 deletions packages/builder/src/fee/FeeBuilder.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const DEFAULT_AMOUNT = 10 * 18;

const moonChainNativeAssetId = '0x0000000000000000000000000000000000000802';

export function getWithdrawAssetInstruction(assetTypes: any[]) {
export function getWithdrawAssetInstruction(assetTypes: object[]) {
return {
WithdrawAsset: assetTypes.map((assetType) => ({
fun: {
Expand All @@ -21,12 +21,12 @@ export function getWithdrawAssetInstruction(assetTypes: any[]) {
};
}

export function getReserveAssetDepositedInstruction(assetType) {
export function getReserveAssetDepositedInstruction(assetType: object) {
return {
ReserveAssetDeposited: [
{
fun: {
Fungible: '1',
Fungible: DEFAULT_AMOUNT,
},
id: { ...assetType },
},
Expand All @@ -40,7 +40,7 @@ export function getClearOriginInstruction() {
};
}

export function getBuyExecutionInstruction(assetType) {
export function getBuyExecutionInstruction(assetType: object) {
return {
BuyExecution: {
fees: {
Expand All @@ -58,12 +58,12 @@ export function getBuyExecutionInstruction(assetType) {
};
}

export function getDepositAssetInstruction(address: string) {
export function getDepositAssetInstruction(address: string, assets: object[]) {
return {
DepositAsset: {
assets: {
Wild: {
AllCounted: 1,
AllCounted: assets.length,
},
},
beneficiary: {
Expand All @@ -86,9 +86,10 @@ export async function getAssetIdType(
api: ApiPromise,
asset: ChainAssetId,
): Promise<Option<MoonbeamRuntimeXcmConfigAssetType>> {
const type = (await api.query.assetManager.assetIdType(
asset,
)) as unknown as Option<MoonbeamRuntimeXcmConfigAssetType>;
const type =
await api.query.assetManager.assetIdType<
Option<MoonbeamRuntimeXcmConfigAssetType>
>(asset);

if (type.isNone || !type.unwrap().isXcm) {
throw new Error(`No asset type found for asset ${asset}`);
Expand All @@ -101,15 +102,17 @@ export async function getVersionedAssetId(
api: ApiPromise,
asset: ChainAssetId,
) {
const acceptablePaymentAssetsResult: Result<
Vec<XcmVersionedAssetId>,
PolkadotError
> = await api.call.xcmPaymentApi.queryAcceptablePaymentAssets(3);
const acceptablePaymentAssetsResult =
await api.call.xcmPaymentApi.queryAcceptablePaymentAssets<
Result<Vec<XcmVersionedAssetId>, PolkadotError>
>(3);
const acceptablePaymentAssets = acceptablePaymentAssetsResult.isOk
? acceptablePaymentAssetsResult.asOk.map((value) => value.asV3)
: [];

// console.log('acceptablePaymentAssets', acceptablePaymentAssets);
console.log(

Check warning on line 112 in packages/builder/src/fee/FeeBuilder.utils.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
'acceptablePaymentAssets',
acceptablePaymentAssets.map((value) => value.toHuman()),
);
// TODO mjm verify that the assets Id are in the acceptablePaymentAssets

if (asset === moonChainNativeAssetId) {
Expand Down Expand Up @@ -156,12 +159,13 @@ export async function getVersionedAssetId(
export async function getFeeForXcmInstructionsAndAsset(
api: ApiPromise,
instructions: AnyJson,
versionedAssetId: any, // TODO mjm
versionedAssetId: object, // TODO mjm
) {
const xcmToWeightResult: Result<Weight, PolkadotError> =
await api.call.xcmPaymentApi.queryXcmWeight({
V3: instructions,
});
const xcmToWeightResult = await api.call.xcmPaymentApi.queryXcmWeight<
Result<Weight, PolkadotError>
>({
V3: instructions,
});
console.log('xcmToWeightResult', xcmToWeightResult.toHuman());

Check warning on line 169 in packages/builder/src/fee/FeeBuilder.utils.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
if (!xcmToWeightResult.isOk) {
throw new Error(
Expand All @@ -170,8 +174,10 @@ export async function getFeeForXcmInstructionsAndAsset(
}
const xcmToWeight = xcmToWeightResult.asOk;

const weightToForeingAssets: Result<u128, PolkadotError> =
await api.call.xcmPaymentApi.queryWeightToAssetFee(xcmToWeight, {
const weightToForeingAssets =
await api.call.xcmPaymentApi.queryWeightToAssetFee<
Result<u128, PolkadotError>
>(xcmToWeight, {
V3: {
...versionedAssetId,
},
Expand Down

0 comments on commit b552b63

Please sign in to comment.