From 4e0e133763b44f274e60acd58ee2da49f45bbb44 Mon Sep 17 00:00:00 2001 From: imstar15 Date: Tue, 5 Dec 2023 11:14:21 +0800 Subject: [PATCH] Add .prettierrc --- .prettierrc | 6 + packages/adapter/src/chains/mangata.ts | 48 +--- packages/adapter/src/chains/moonbeam.ts | 51 +--- packages/adapter/src/chains/oak.ts | 167 +++---------- packages/adapter/src/util.ts | 110 +++------ packages/config/src/chains/index.ts | 9 +- packages/config/src/tokens/dev.ts | 12 +- packages/config/src/tokens/index.ts | 9 +- packages/config/src/tokens/kusama.ts | 12 +- packages/config/src/tokens/moonbase.ts | 2 +- packages/config/src/tokens/polkadot.ts | 2 +- packages/config/src/tokens/rococo.ts | 10 +- packages/config/src/tokens/types/Token.ts | 14 +- packages/sdk/src/index.ts | 277 +++++++--------------- 14 files changed, 213 insertions(+), 516 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..1841652 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "tabWidth": 2, + "useTabs": false, + "trailingComma": "all", + "printWidth": 150 +} diff --git a/packages/adapter/src/chains/mangata.ts b/packages/adapter/src/chains/mangata.ts index b82b0e9..61af5ed 100644 --- a/packages/adapter/src/chains/mangata.ts +++ b/packages/adapter/src/chains/mangata.ts @@ -8,11 +8,7 @@ import type { KeyringPair } from "@polkadot/keyring/types"; import { Weight } from "@oak-network/config"; import { ChainAdapter } from "./chainAdapter"; import { getDerivativeAccountV2, sendExtrinsic } from "../util"; -import { - WEIGHT_REF_TIME_PER_NANOS, - WEIGHT_REF_TIME_PER_SECOND, - WEIGHT_PROOF_SIZE_PER_MB, -} from "../constants"; +import { WEIGHT_REF_TIME_PER_NANOS, WEIGHT_REF_TIME_PER_SECOND, WEIGHT_PROOF_SIZE_PER_MB } from "../constants"; import { SendExtrinsicResult } from "../types"; // MangataAdapter implements ChainAdapter @@ -31,12 +27,8 @@ export class MangataAdapter extends ChainAdapter { * @returns Extrinsic weight */ // eslint-disable-next-line class-methods-use-this - async getExtrinsicWeight( - extrinsic: SubmittableExtrinsic<"promise">, - account: AddressOrPair, - ): Promise { - const { refTime, proofSize } = (await extrinsic.paymentInfo(account)) - .weight as unknown as WeightV2; + async getExtrinsicWeight(extrinsic: SubmittableExtrinsic<"promise">, account: AddressOrPair): Promise { + const { refTime, proofSize } = (await extrinsic.paymentInfo(account)).weight as unknown as WeightV2; return new Weight(new BN(refTime.unwrap()), new BN(proofSize.unwrap())); } @@ -46,15 +38,10 @@ export class MangataAdapter extends ChainAdapter { * @param instructionCount The number of XCM instructions * @returns XCM overall weight */ - async calculateXcmOverallWeight( - transactCallWeight: Weight, - instructionCount: number, - ): Promise { + async calculateXcmOverallWeight(transactCallWeight: Weight, instructionCount: number): Promise { const { xcm } = this.chainConfig; if (_.isUndefined(xcm)) throw new Error("chainConfig.xcm not set"); - const overallWeight = transactCallWeight.add( - xcm.instructionWeight.muln(instructionCount), - ); + const overallWeight = transactCallWeight.add(xcm.instructionWeight.muln(instructionCount)); return overallWeight; } @@ -66,32 +53,24 @@ export class MangataAdapter extends ChainAdapter { */ async weightToFee(weight: Weight, assetLocation: any): Promise { const [defaultAsset] = this.chainConfig.assets; - if (_.isUndefined(defaultAsset)) - throw new Error("chainConfig.defaultAsset not set"); + if (_.isUndefined(defaultAsset)) throw new Error("chainConfig.defaultAsset not set"); const api = this.getApi(); if (_.isEqual(defaultAsset.location, assetLocation)) { const unit = new BN(10).pow(new BN(defaultAsset.decimals)); // ExtrinsicBaseWeight benchmark value: 114756 nano seconds const extrinsicBaseWeight = WEIGHT_REF_TIME_PER_NANOS.mul(new BN(114756)); - const feePerSecond = - WEIGHT_REF_TIME_PER_SECOND.div(extrinsicBaseWeight).mul(unit); - const refTimeFee = weight.refTime - .mul(feePerSecond) - .div(WEIGHT_REF_TIME_PER_SECOND); - const proofSizeFee = weight.proofSize - .mul(feePerSecond) - .div(WEIGHT_PROOF_SIZE_PER_MB); + const feePerSecond = WEIGHT_REF_TIME_PER_SECOND.div(extrinsicBaseWeight).mul(unit); + const refTimeFee = weight.refTime.mul(feePerSecond).div(WEIGHT_REF_TIME_PER_SECOND); + const proofSizeFee = weight.proofSize.mul(feePerSecond).div(WEIGHT_PROOF_SIZE_PER_MB); return refTimeFee.add(proofSizeFee); } - const storageValue = - await api.query.assetRegistry.locationToAssetId(assetLocation); + const storageValue = await api.query.assetRegistry.locationToAssetId(assetLocation); const item = storageValue as unknown as Option; if (item.isNone) throw new Error("AssetTypeUnitsPerSecond is null"); const assetId = item.unwrap(); - const metadataStorageValue = - await api.query.assetRegistry.metadata(assetId); + const metadataStorageValue = await api.query.assetRegistry.metadata(assetId); const metadataItem = metadataStorageValue as unknown as Option; if (metadataItem.isNone) throw new Error("Metadata is null"); @@ -156,10 +135,7 @@ export class MangataAdapter extends ChainAdapter { { V3: { interior: { - X2: [ - destination.interior.X1, - { AccountId32: { id: recipient, network: null } }, - ], + X2: [destination.interior.X1, { AccountId32: { id: recipient, network: null } }], }, parents: 1, }, diff --git a/packages/adapter/src/chains/moonbeam.ts b/packages/adapter/src/chains/moonbeam.ts index fa8bbaa..5da6d2c 100644 --- a/packages/adapter/src/chains/moonbeam.ts +++ b/packages/adapter/src/chains/moonbeam.ts @@ -7,11 +7,7 @@ import type { HexString } from "@polkadot/util/types"; import type { KeyringPair } from "@polkadot/keyring/types"; import { Weight } from "@oak-network/config"; import { ChainAdapter, TaskScheduler } from "./chainAdapter"; -import { - convertAbsoluteLocationToRelative, - getDerivativeAccountV3, - sendExtrinsic, -} from "../util"; +import { convertAbsoluteLocationToRelative, getDerivativeAccountV3, sendExtrinsic } from "../util"; import { AccountType, SendExtrinsicResult } from "../types"; import { WEIGHT_REF_TIME_PER_SECOND } from "../constants"; @@ -74,12 +70,8 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { * @returns Extrinsic weight */ // eslint-disable-next-line class-methods-use-this - async getExtrinsicWeight( - extrinsic: SubmittableExtrinsic<"promise">, - account: AddressOrPair, - ): Promise { - const { refTime, proofSize } = (await extrinsic.paymentInfo(account)) - .weight as unknown as WeightV2; + async getExtrinsicWeight(extrinsic: SubmittableExtrinsic<"promise">, account: AddressOrPair): Promise { + const { refTime, proofSize } = (await extrinsic.paymentInfo(account)).weight as unknown as WeightV2; return new Weight(new BN(refTime.unwrap()), new BN(proofSize.unwrap())); } @@ -89,15 +81,10 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { * @param instructionCount * @returns XCM overall weight */ - async calculateXcmOverallWeight( - transactCallWeight: Weight, - instructionCount: number, - ): Promise { + async calculateXcmOverallWeight(transactCallWeight: Weight, instructionCount: number): Promise { const { xcm } = this.chainConfig; if (_.isUndefined(xcm)) throw new Error("chainConfig.xcm not set"); - const overallWeight = transactCallWeight.add( - xcm.instructionWeight.muln(instructionCount), - ); + const overallWeight = transactCallWeight.add(xcm.instructionWeight.muln(instructionCount)); return overallWeight; } @@ -109,13 +96,10 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { */ async weightToFee(weight: Weight, assetLocation: any): Promise { const [defaultAsset] = this.chainConfig.assets; - if (_.isUndefined(defaultAsset)) - throw new Error("chainConfig.defaultAsset not set"); + if (_.isUndefined(defaultAsset)) throw new Error("chainConfig.defaultAsset not set"); const api = this.getApi(); if (_.isEqual(defaultAsset.location, assetLocation)) { - const fee = (await api.call.transactionPaymentApi.queryWeightToFee( - weight, - )) as u64; + const fee = (await api.call.transactionPaymentApi.queryWeightToFee(weight)) as u64; return fee; } const storageValue = await api.query.assetManager.assetTypeUnitsPerSecond({ @@ -159,11 +143,8 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { if (_.isUndefined(key)) throw new Error("chainConfig.key not set"); const [defaultAsset] = this.chainConfig.assets; - if (_.isUndefined(defaultAsset)) - throw new Error("chainConfig.defaultAsset not set"); - const currency = _.isEqual(feeLocation, defaultAsset.location) - ? { AsCurrencyId: "SelfReserve" } - : { AsMultiLocation: { V3: feeLocation } }; + if (_.isUndefined(defaultAsset)) throw new Error("chainConfig.defaultAsset not set"); + const currency = _.isEqual(feeLocation, defaultAsset.location) ? { AsCurrencyId: "SelfReserve" } : { AsMultiLocation: { V3: feeLocation } }; const extrinsic = this.getApi().tx.xcmTransactor.transactThroughSigned( { V3: destination }, { currency, feeAmount }, @@ -172,10 +153,7 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { false, ); - console.log( - `Send extrinsic from ${key} to schedule task. extrinsic:`, - extrinsic.method.toHex(), - ); + console.log(`Send extrinsic from ${key} to schedule task. extrinsic:`, extrinsic.method.toHex()); const result = await sendExtrinsic(api, extrinsic, keyringPair); return result; } @@ -221,9 +199,7 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { const { key } = this.chainConfig; if (_.isUndefined(key)) throw new Error("chainConfig.key not set"); - const transferAssetLocation = this.isNativeAsset(assetLocation) - ? convertAbsoluteLocationToRelative(assetLocation) - : assetLocation; + const transferAssetLocation = this.isNativeAsset(assetLocation) ? convertAbsoluteLocationToRelative(assetLocation) : assetLocation; const api = this.getApi(); const extrinsic = api.tx.xTokens.transferMultiasset( @@ -236,10 +212,7 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { { V3: { interior: { - X2: [ - destination.interior.X1, - { AccountId32: { id: recipient, network: null } }, - ], + X2: [destination.interior.X1, { AccountId32: { id: recipient, network: null } }], }, parents: 1, }, diff --git a/packages/adapter/src/chains/oak.ts b/packages/adapter/src/chains/oak.ts index 9ffd695..ec12f2c 100644 --- a/packages/adapter/src/chains/oak.ts +++ b/packages/adapter/src/chains/oak.ts @@ -6,20 +6,10 @@ import type { SubmittableExtrinsic, AddressOrPair } from "@polkadot/api/types"; import type { u32, u128, Option } from "@polkadot/types"; import type { WeightV2 } from "@polkadot/types/interfaces"; import type { KeyringPair } from "@polkadot/keyring/types"; -import { - Weight, - XcmInstructionNetworkType, - Chain, - XToken, -} from "@oak-network/config"; +import { Weight, XcmInstructionNetworkType, Chain, XToken } from "@oak-network/config"; import { ISubmittableResult } from "@polkadot/types/types"; import { ChainAdapter } from "./chainAdapter"; -import { - getDerivativeAccountV2, - isValidAddress, - sendExtrinsic, - getDecimalBN, -} from "../util"; +import { getDerivativeAccountV2, isValidAddress, sendExtrinsic, getDecimalBN } from "../util"; import { AccountType, SendExtrinsicResult } from "../types"; import { WEIGHT_REF_TIME_PER_SECOND } from "../constants"; import { InvalidAddress } from "../errors"; @@ -55,12 +45,8 @@ export class OakAdapter extends ChainAdapter { * @returns Extrinsic weight */ // eslint-disable-next-line class-methods-use-this - async getExtrinsicWeight( - extrinsic: SubmittableExtrinsic<"promise">, - account: AddressOrPair, - ): Promise { - const { refTime, proofSize } = (await extrinsic.paymentInfo(account)) - .weight as unknown as WeightV2; + async getExtrinsicWeight(extrinsic: SubmittableExtrinsic<"promise">, account: AddressOrPair): Promise { + const { refTime, proofSize } = (await extrinsic.paymentInfo(account)).weight as unknown as WeightV2; return new Weight(new BN(refTime.unwrap()), new BN(proofSize.unwrap())); } @@ -70,15 +56,10 @@ export class OakAdapter extends ChainAdapter { * @param instructionCount The number of XCM instructions * @returns XCM overall weight */ - async calculateXcmOverallWeight( - transactCallWeight: Weight, - instructionCount: number, - ): Promise { + async calculateXcmOverallWeight(transactCallWeight: Weight, instructionCount: number): Promise { const { xcm } = this.chainConfig; if (_.isUndefined(xcm)) throw new Error("chainConfig.xcm not set"); - const overallWeight = transactCallWeight.add( - xcm.instructionWeight.muln(instructionCount), - ); + const overallWeight = transactCallWeight.add(xcm.instructionWeight.muln(instructionCount)); return overallWeight; } @@ -90,21 +71,16 @@ export class OakAdapter extends ChainAdapter { */ async weightToFee(weight: Weight, assetLocation: any): Promise { const [defaultAsset] = this.chainConfig.assets; - if (_.isUndefined(defaultAsset)) - throw new Error("chainConfig.defaultAsset not set"); + if (_.isUndefined(defaultAsset)) throw new Error("chainConfig.defaultAsset not set"); const api = this.getApi(); - const location = _.isEqual(assetLocation, defaultAsset.location) - ? { interior: "Here", parents: 0 } - : assetLocation; - const storageValue = - await api.query.assetRegistry.locationToAssetId(location); + const location = _.isEqual(assetLocation, defaultAsset.location) ? { interior: "Here", parents: 0 } : assetLocation; + const storageValue = await api.query.assetRegistry.locationToAssetId(location); const item = storageValue as unknown as Option; if (item.isNone) throw new Error("AssetId not set"); const assetId = item.unwrap(); - const metadataStorageValue = - await api.query.assetRegistry.metadata(assetId); + const metadataStorageValue = await api.query.assetRegistry.metadata(assetId); const metadataItem = metadataStorageValue as unknown as Option; if (metadataItem.isNone) throw new Error("Metadata not set"); @@ -112,9 +88,7 @@ export class OakAdapter extends ChainAdapter { const feePerSecond = additional.feePerSecond as unknown as Option; if (feePerSecond.isNone) throw new Error("feePerSecond is null"); - return weight.refTime - .mul(feePerSecond.unwrap()) - .div(WEIGHT_REF_TIME_PER_SECOND); + return weight.refTime.mul(feePerSecond.unwrap()).div(WEIGHT_REF_TIME_PER_SECOND); } /** @@ -130,10 +104,7 @@ export class OakAdapter extends ChainAdapter { token: string, recipient: string, amount: string | number, - ): - | SubmittableExtrinsic<"promise", ISubmittableResult> - | SubmittableExtrinsic<"rxjs", ISubmittableResult> - | undefined { + ): SubmittableExtrinsic<"promise", ISubmittableResult> | SubmittableExtrinsic<"rxjs", ISubmittableResult> | undefined { const asset = _.find(this.chainConfig.assets, (item) => item.key === token); if (_.isUndefined(asset)) throw new Error(`Asset ${token} not found`); @@ -207,10 +178,7 @@ export class OakAdapter extends ChainAdapter { { V3: { interior: { - X2: [ - destination.interior.X1, - { AccountId32: { id: recipient, network: null } }, - ], + X2: [destination.interior.X1, { AccountId32: { id: recipient, network: null } }], }, parents: 1, }, @@ -233,10 +201,7 @@ export class OakAdapter extends ChainAdapter { */ // eslint-disable-next-line class-methods-use-this getTransactXcmInstructionCount(transactType: OakAdapterTransactType) { - return transactType === - OakAdapterTransactType.PayThroughRemoteDerivativeAccount - ? 4 - : 6; + return transactType === OakAdapterTransactType.PayThroughRemoteDerivativeAccount ? 4 : 6; } /** @@ -275,10 +240,7 @@ export class OakAdapter extends ChainAdapter { overallWeight, ); - console.log( - `Send extrinsic from ${key} to schedule task. extrinsic:`, - extrinsic.method.toHex(), - ); + console.log(`Send extrinsic from ${key} to schedule task. extrinsic:`, extrinsic.method.toHex()); const result = await sendExtrinsic(api, extrinsic, keyringPair); return result; } @@ -325,10 +287,7 @@ export class OakAdapter extends ChainAdapter { overallWeight, ); - console.log( - `Send extrinsic from ${key} to schedule price task. extrinsic:`, - extrinsic.method.toHex(), - ); + console.log(`Send extrinsic from ${key} to schedule price task. extrinsic:`, extrinsic.method.toHex()); const result = await sendExtrinsic(api, extrinsic, keyringPair); return result; } @@ -378,8 +337,7 @@ export class OakAdapter extends ChainAdapter { */ async getDelegatorState(delegator: HexString): Promise { const api = this.getApi(); - const delegatorStateCodec = - await api.query.parachainStaking.delegatorState(delegator); + const delegatorStateCodec = await api.query.parachainStaking.delegatorState(delegator); const delegatorState = delegatorStateCodec as unknown as Option; return delegatorState.isSome ? delegatorState.unwrap() : undefined; } @@ -396,10 +354,7 @@ export class OakAdapter extends ChainAdapter { return undefined; } const { delegations } = delegatorState; - const foundDelegation = _.find( - delegations, - ({ owner }) => owner.toHex() === collator, - ); + const foundDelegation = _.find(delegations, ({ owner }) => owner.toHex() === collator); return foundDelegation; } @@ -408,14 +363,10 @@ export class OakAdapter extends ChainAdapter { * @param collator * @returns */ - async getAutoCompoundingDelegationsLength( - collator: HexString, - ): Promise { + async getAutoCompoundingDelegationsLength(collator: HexString): Promise { const api = this.getApi(); - const autoCompoundingDelegationsCodec = - await api.query.parachainStaking.autoCompoundingDelegations(collator); - const autoCompoundingDelegations = - autoCompoundingDelegationsCodec as unknown as any[]; + const autoCompoundingDelegationsCodec = await api.query.parachainStaking.autoCompoundingDelegations(collator); + const autoCompoundingDelegations = autoCompoundingDelegationsCodec as unknown as any[]; return autoCompoundingDelegations.length; } @@ -427,12 +378,7 @@ export class OakAdapter extends ChainAdapter { * @param keyringPair * @returns */ - async delegateWithAutoCompound( - collator: HexString, - amount: BN, - percentage: number, - keyringPair: KeyringPair, - ): Promise { + async delegateWithAutoCompound(collator: HexString, amount: BN, percentage: number, keyringPair: KeyringPair): Promise { const api = this.getApi(); // Check if delegation exists const delegatorWalletAddress = u8aToHex(keyringPair.addressRaw); @@ -443,10 +389,7 @@ export class OakAdapter extends ChainAdapter { let delegationsLength = 0; if (!_.isUndefined(delegatorState)) { const { delegations } = delegatorState; - const foundDelegation = _.find( - delegations, - ({ owner }) => owner.toHex() === collator, - ); + const foundDelegation = _.find(delegations, ({ owner }) => owner.toHex() === collator); delegationsLength = delegations.length; if (!_.isUndefined(foundDelegation)) { throw new Error("Delegation already exists"); @@ -456,28 +399,20 @@ export class OakAdapter extends ChainAdapter { const { minDelegation: minDelegationCodec } = api.consts.parachainStaking; const minDelegation = minDelegationCodec as u128; if (amount.lt(minDelegation)) { - throw new Error( - `Amount must be greater than or equal to ${minDelegation}`, - ); + throw new Error(`Amount must be greater than or equal to ${minDelegation}`); } - const candidateInfoCodec = - await api.query.parachainStaking.candidateInfo(collator); + const candidateInfoCodec = await api.query.parachainStaking.candidateInfo(collator); const candidateInfo = candidateInfoCodec as unknown as Option; if (candidateInfo.isNone) { throw new Error("Candidate info not found"); } - const { delegationCount: candidateDelegationCount } = - candidateInfo.unwrap(); + const { delegationCount: candidateDelegationCount } = candidateInfo.unwrap(); console.log("collator: ", collator); - const autoCompoundingDelegationsLength = - await this.getAutoCompoundingDelegationsLength(collator); - console.log( - "autoCompoundingDelegationsLength: ", - autoCompoundingDelegationsLength, - ); + const autoCompoundingDelegationsLength = await this.getAutoCompoundingDelegationsLength(collator); + console.log("autoCompoundingDelegationsLength: ", autoCompoundingDelegationsLength); // Delegate to collator const delegateExtrinsic = api.tx.parachainStaking.delegateWithAutoCompound( @@ -500,19 +435,11 @@ export class OakAdapter extends ChainAdapter { * @param collator * @returns */ - async getAutoCompoundingDelegationPercentage( - collator: HexString, - delegator: HexString, - ): Promise { + async getAutoCompoundingDelegationPercentage(collator: HexString, delegator: HexString): Promise { const api = this.getApi(); - const autoCompoundingDelegationsCodec = - await api.query.parachainStaking.autoCompoundingDelegations(collator); - const autoCompoundingDelegations = - autoCompoundingDelegationsCodec as unknown as any[]; - const delegation = _.find( - autoCompoundingDelegations, - (item) => item.delegator.toHex() === delegator, - ); + const autoCompoundingDelegationsCodec = await api.query.parachainStaking.autoCompoundingDelegations(collator); + const autoCompoundingDelegations = autoCompoundingDelegationsCodec as unknown as any[]; + const delegation = _.find(autoCompoundingDelegations, (item) => item.delegator.toHex() === delegator); return delegation?.value?.toNumber(); } @@ -523,19 +450,12 @@ export class OakAdapter extends ChainAdapter { * @param keyringPair * @returns */ - async setAutoCompound( - collator: HexString, - percentage: number, - keyringPair: KeyringPair, - ): Promise { + async setAutoCompound(collator: HexString, percentage: number, keyringPair: KeyringPair): Promise { const api = this.getApi(); - const autoCompoundingDelegationsLength = - await this.getAutoCompoundingDelegationsLength(collator); + const autoCompoundingDelegationsLength = await this.getAutoCompoundingDelegationsLength(collator); - const delegatorState = await this.getDelegatorState( - u8aToHex(keyringPair.addressRaw), - ); + const delegatorState = await this.getDelegatorState(u8aToHex(keyringPair.addressRaw)); if (_.isUndefined(delegatorState)) { throw new Error("Delegator state not found"); } @@ -548,11 +468,7 @@ export class OakAdapter extends ChainAdapter { autoCompoundingDelegationsLength + 1, delegationsLength + 1, ); - const result = await sendExtrinsic( - api, - setAutoCompoundExtrinsic, - keyringPair, - ); + const result = await sendExtrinsic(api, setAutoCompoundExtrinsic, keyringPair); return result; } @@ -563,20 +479,13 @@ export class OakAdapter extends ChainAdapter { * @param keyringPair * @returns */ - async bondMore( - collator: HexString, - amount: BN, - keyringPair: KeyringPair, - ): Promise { + async bondMore(collator: HexString, amount: BN, keyringPair: KeyringPair): Promise { const api = this.getApi(); if (!this.hasEnoughFreeBalance(u8aToHex(keyringPair.addressRaw), amount)) { throw new Error("Insufficient balance"); } // Create bondMoreExtrinsic - const bondMoreExtrinsic = api.tx.parachainStaking.delegatorBondMore( - collator, - amount, - ); + const bondMoreExtrinsic = api.tx.parachainStaking.delegatorBondMore(collator, amount); const result = await sendExtrinsic(api, bondMoreExtrinsic, keyringPair); return result; diff --git a/packages/adapter/src/util.ts b/packages/adapter/src/util.ts index 169c638..9a97d0a 100644 --- a/packages/adapter/src/util.ts +++ b/packages/adapter/src/util.ts @@ -5,11 +5,7 @@ import { KeyringPair } from "@polkadot/keyring/types"; import type { SubmittableExtrinsic } from "@polkadot/api/types"; import type { HexString } from "@polkadot/util/types"; import { TypeRegistry } from "@polkadot/types"; -import { - blake2AsU8a, - encodeAddress, - decodeAddress, -} from "@polkadot/util-crypto"; +import { blake2AsU8a, encodeAddress, decodeAddress } from "@polkadot/util-crypto"; import { isAddress as isEthereumAddress } from "web3-validator"; import BN from "bn.js"; import { AccountType, SendExtrinsicResult } from "./types"; @@ -30,45 +26,39 @@ export const sendExtrinsic = async ( ): Promise => new Promise((resolve) => { const newExtrinsic = isSudo ? api.tx.sudo.sudo(extrinsic) : extrinsic; - newExtrinsic.signAndSend( - keyringPair, - { nonce: -1 }, - ({ status, events }: any) => { - console.log("status.type", status.type); - if (status.isInBlock || status.isFinalized) { - events - // find/filter for failed events - .filter(({ event }: any) => - api.events.system.ExtrinsicFailed.is(event), - ) - // we know that data for system.ExtrinsicFailed is - // (DispatchError, DispatchInfo) - .forEach( - ({ - event: { - data: [error], - }, - }: { - event: any; - }) => { - if (error.isModule) { - // for module errors, we have the section indexed, lookup - const decoded = api.registry.findMetaError(error.asModule); - const { docs, method, section } = decoded; - console.log(`${section}.${method}: ${docs.join(" ")}`); - } else { - // Other, CannotLookup, BadOrigin, no extra info - console.log(error.toString()); - } + newExtrinsic.signAndSend(keyringPair, { nonce: -1 }, ({ status, events }: any) => { + console.log("status.type", status.type); + if (status.isInBlock || status.isFinalized) { + events + // find/filter for failed events + .filter(({ event }: any) => api.events.system.ExtrinsicFailed.is(event)) + // we know that data for system.ExtrinsicFailed is + // (DispatchError, DispatchInfo) + .forEach( + ({ + event: { + data: [error], }, - ); + }: { + event: any; + }) => { + if (error.isModule) { + // for module errors, we have the section indexed, lookup + const decoded = api.registry.findMetaError(error.asModule); + const { docs, method, section } = decoded; + console.log(`${section}.${method}: ${docs.join(" ")}`); + } else { + // Other, CannotLookup, BadOrigin, no extra info + console.log(error.toString()); + } + }, + ); - if (status.isFinalized) { - resolve({ blockHash: status.asFinalized.toString(), events }); - } + if (status.isFinalized) { + resolve({ blockHash: status.asFinalized.toString(), events }); } - }, - ); + } + }); }); /** @@ -85,21 +75,14 @@ export const getDerivativeAccountV2 = ( paraId: number, { locationType = "XcmV2MultiLocation", network = "Any" } = {}, ): HexString => { - const account = - hexToU8a(accountId).length === 20 - ? { AccountKey20: { key: accountId, network } } - : { AccountId32: { id: accountId, network } }; + const account = hexToU8a(accountId).length === 20 ? { AccountKey20: { key: accountId, network } } : { AccountId32: { id: accountId, network } }; const location = { interior: { X2: [{ Parachain: paraId }, account] }, parents: 1, }; const multilocation = api.createType(locationType, location); - const toHash = new Uint8Array([ - ...new Uint8Array([32]), - ...new TextEncoder().encode("multiloc"), - ...multilocation.toU8a(), - ]); + const toHash = new Uint8Array([...new Uint8Array([32]), ...new TextEncoder().encode("multiloc"), ...multilocation.toU8a()]); return u8aToHex(api.registry.hash(toHash).slice(0, 32)); }; @@ -111,13 +94,8 @@ export const getDerivativeAccountV2 = ( * @param deriveAccountType Specify the derive account type returned by the function * @returns Derivative account */ -export const getDerivativeAccountV3 = ( - accountId: HexString, - paraId: number, - deriveAccountType: AccountType = AccountType.AccountId32, -): HexString => { - const accountType = - hexToU8a(accountId).length === 20 ? "AccountKey20" : "AccountId32"; +export const getDerivativeAccountV3 = (accountId: HexString, paraId: number, deriveAccountType: AccountType = AccountType.AccountId32): HexString => { + const accountType = hexToU8a(accountId).length === 20 ? "AccountKey20" : "AccountId32"; const decodedAddress = hexToU8a(accountId); // Calculate Hash Component @@ -125,22 +103,12 @@ export const getDerivativeAccountV3 = ( const toHash = new Uint8Array([ ...new TextEncoder().encode("SiblingChain"), ...registry.createType("Compact", paraId).toU8a(), - ...registry - .createType( - "Compact", - accountType.length + hexToU8a(accountId).length, - ) - .toU8a(), + ...registry.createType("Compact", accountType.length + hexToU8a(accountId).length).toU8a(), ...new TextEncoder().encode(accountType), ...decodedAddress, ]); - return u8aToHex( - blake2AsU8a(toHash).slice( - 0, - deriveAccountType === AccountType.AccountKey20 ? 20 : 32, - ), - ); + return u8aToHex(blake2AsU8a(toHash).slice(0, deriveAccountType === AccountType.AccountKey20 ? 20 : 32)); }; /** @@ -159,9 +127,7 @@ export function convertAbsoluteLocationToRelative(absoluteLocation: any): any { return { interior: "Here", parents: 0 }; } const newInterior: Record = {}; - const newArray = interior[key].filter( - (item: any) => !_.has(item, "Parachain"), - ); + const newArray = interior[key].filter((item: any) => !_.has(item, "Parachain")); if (newArray.length > 0) { const newXKey = `X${newArray.length}`; newInterior[newXKey] = newArray.length === 1 ? newArray[0] : newArray; diff --git a/packages/config/src/chains/index.ts b/packages/config/src/chains/index.ts index 73d1517..0f18c38 100644 --- a/packages/config/src/chains/index.ts +++ b/packages/config/src/chains/index.ts @@ -6,13 +6,6 @@ import RococoChains from "./rococo"; import KusamaChains from "./kusama"; import PolkadotChains from "./polkadot"; -export { - DevChains, - MoonbaseChains, - RococoChains, - KusamaChains, - PolkadotChains, - Weight, -}; +export { DevChains, MoonbaseChains, RococoChains, KusamaChains, PolkadotChains, Weight }; export type { Chain, XcmConfig }; diff --git a/packages/config/src/tokens/dev.ts b/packages/config/src/tokens/dev.ts index d3f85ed..df4c971 100644 --- a/packages/config/src/tokens/dev.ts +++ b/packages/config/src/tokens/dev.ts @@ -16,24 +16,24 @@ const sby = createToken({ }); const moonbaseLocal = createToken({ decimals: 18, + interior: { palletInstance: 3 }, key: "unit", network: "moonbase", parachainId: 1000, symbol: "UNIT", - x2Params: { palletInstance: 3 }, }); const mgr = createToken({ decimals: 18, - key: "mgr", - network: "mangata", - parachainId: 2110, - symbol: "MGR", - x2Params: { + interior: { GeneralKey: { data: "0x0000000000000000000000000000000000000000000000000000000000000000", length: 4, }, }, + key: "mgr", + network: "mangata", + parachainId: 2110, + symbol: "MGR", }); // eslint-disable-next-line import/no-default-export diff --git a/packages/config/src/tokens/index.ts b/packages/config/src/tokens/index.ts index 53b9ece..f1509e2 100644 --- a/packages/config/src/tokens/index.ts +++ b/packages/config/src/tokens/index.ts @@ -5,11 +5,4 @@ import RococoTokens from "./rococo"; import KusamaTokens from "./kusama"; import PolkadotTokens from "./polkadot"; -export { - XToken, - DevTokens, - MoonbaseTokens, - RococoTokens, - KusamaTokens, - PolkadotTokens, -}; +export { XToken, DevTokens, MoonbaseTokens, RococoTokens, KusamaTokens, PolkadotTokens }; diff --git a/packages/config/src/tokens/kusama.ts b/packages/config/src/tokens/kusama.ts index 76529a5..13ed086 100644 --- a/packages/config/src/tokens/kusama.ts +++ b/packages/config/src/tokens/kusama.ts @@ -18,11 +18,11 @@ const xcTur = createToken({ // TODO: movr is not defined in the original file; need to double check its value const movr = createToken({ decimals: 18, + interior: { palletInstance: 10 }, key: "movr", network: "kusama", parachainId: 2023, symbol: "MOVR", - x2Params: { palletInstance: 10 }, }); const sdn = createToken({ decimals: 18, @@ -33,16 +33,16 @@ const sdn = createToken({ }); const mgx = createToken({ decimals: 18, - key: "mangata", - network: "kusama", - parachainId: 2110, - symbol: "MGX", - x2Params: { + interior: { GeneralKey: { data: "0x0000000000000000000000000000000000000000000000000000000000000000", length: 4, }, }, + key: "mangata", + network: "kusama", + parachainId: 2110, + symbol: "MGX", }); // eslint-disable-next-line import/no-default-export diff --git a/packages/config/src/tokens/moonbase.ts b/packages/config/src/tokens/moonbase.ts index e9d8bac..6e73e87 100644 --- a/packages/config/src/tokens/moonbase.ts +++ b/packages/config/src/tokens/moonbase.ts @@ -10,11 +10,11 @@ const tur = createToken({ const dev = createToken({ decimals: 10, + interior: { palletInstance: 3 }, key: "dev", network: "moonbase", parachainId: 1000, symbol: "DEV", - x2Params: { palletInstance: 3 }, }); // eslint-disable-next-line import/no-default-export diff --git a/packages/config/src/tokens/polkadot.ts b/packages/config/src/tokens/polkadot.ts index c97c1fe..bf1693c 100644 --- a/packages/config/src/tokens/polkadot.ts +++ b/packages/config/src/tokens/polkadot.ts @@ -2,11 +2,11 @@ import { createToken } from "./types/Token"; const glmr = createToken({ decimals: 10, + interior: { palletInstance: 10 }, key: "glmr", network: "kusama", parachainId: 2023, symbol: "GLMR", - x2Params: { palletInstance: 10 }, }); // eslint-disable-next-line import/no-default-export diff --git a/packages/config/src/tokens/rococo.ts b/packages/config/src/tokens/rococo.ts index e6a3acc..a27c6b1 100644 --- a/packages/config/src/tokens/rococo.ts +++ b/packages/config/src/tokens/rococo.ts @@ -17,16 +17,16 @@ const rstr = createToken({ }); const mgr = createToken({ decimals: 18, - key: "mangata-rococo", - network: "rococo", - parachainId: 2110, - symbol: "MGR", - x2Params: { + interior: { GeneralKey: { data: "0x0000000000000000000000000000000000000000000000000000000000000000", length: 4, }, }, + key: "mangata-rococo", + network: "rococo", + parachainId: 2110, + symbol: "MGR", }); // eslint-disable-next-line import/no-default-export diff --git a/packages/config/src/tokens/types/Token.ts b/packages/config/src/tokens/types/Token.ts index 480ca81..653099b 100644 --- a/packages/config/src/tokens/types/Token.ts +++ b/packages/config/src/tokens/types/Token.ts @@ -41,25 +41,23 @@ interface TokenParams { decimals: number; network: string; parachainId: number; - x2Params?: any; + interior?: any; } // Function to construct the 'location' object based on the parameters. -function constructLocation(parachainId: number, x2Params?: any): Location { - const interior = x2Params - ? { X2: [{ Parachain: parachainId }, { ...x2Params }] } - : { X1: { Parachain: parachainId } }; +function constructLocation(parachainId: number, interior?: any): Location { + const interiorObj = interior ? { X2: [{ Parachain: parachainId }, interior] } : { X1: { Parachain: parachainId } }; return { - interior, + interior: interiorObj, parents: 1, }; } // Simplify the asset creation function. function createToken(params: TokenParams): Token { - const { key, symbol, decimals, network, parachainId, x2Params } = params; - const location = constructLocation(parachainId, x2Params); + const { key, symbol, decimals, network, parachainId, interior } = params; + const location = constructLocation(parachainId, interior); return new Token({ decimals, key, location, network, symbol }); } diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 8ad38f1..360eee9 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -28,13 +28,11 @@ interface ScheduleXcmpTaskParams { keyringPair: KeyringPair; } -interface ScheduleXcmpTaskWithPayThroughSoverignAccountFlowParams - extends ScheduleXcmpTaskParams { +interface ScheduleXcmpTaskWithPayThroughSoverignAccountFlowParams extends ScheduleXcmpTaskParams { destinationChainAdapter: ChainAdapter; } -interface ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams - extends ScheduleXcmpTaskParams { +interface ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams extends ScheduleXcmpTaskParams { destinationChainAdapter: TaskSchedulerChainAdapter; } @@ -55,17 +53,9 @@ interface CreateTaskFuncParams { const scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow = async ( params: ScheduleXcmpTaskParams, destinationChainAdapter: TaskSchedulerChainAdapter, - createTaskFunc: ( - params: CreateTaskFuncParams, - ) => SubmittableExtrinsic<"promise">, + createTaskFunc: (params: CreateTaskFuncParams) => SubmittableExtrinsic<"promise">, ): Promise => { - const { - oakAdapter, - taskPayloadExtrinsic, - executionFeeLocation, - keyringPair, - xcmOptions, - } = params; + const { oakAdapter, taskPayloadExtrinsic, executionFeeLocation, keyringPair, xcmOptions } = params; const [defaultAsset] = oakAdapter.getChainConfig().assets; if (_.isUndefined(defaultAsset)) { @@ -84,38 +74,20 @@ const scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow = async ( const destination = { V3: destinationChainAdapter.getLocation() }; const encodedCall = taskPayloadExtrinsic.method.toHex(); const oakTransactXcmInstructionCount = - xcmOptions?.instructionCount || - oakAdapter.getTransactXcmInstructionCount( - OakAdapterTransactType.PayThroughRemoteDerivativeAccount, - ); - const taskPayloadEncodedCallWeight = - await destinationChainAdapter.getExtrinsicWeight( - taskPayloadExtrinsic, - keyringPair, - ); + xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount(OakAdapterTransactType.PayThroughRemoteDerivativeAccount); + const taskPayloadEncodedCallWeight = await destinationChainAdapter.getExtrinsicWeight(taskPayloadExtrinsic, keyringPair); const taskPayloadOverallWeight = xcmOptions?.overallWeight || - (await destinationChainAdapter.calculateXcmOverallWeight( - taskPayloadEncodedCallWeight, - oakTransactXcmInstructionCount, - )); + (await destinationChainAdapter.calculateXcmOverallWeight(taskPayloadEncodedCallWeight, oakTransactXcmInstructionCount)); const executionFeeAmout = - xcmOptions?.executionFeeAmount || - (await destinationChainAdapter.weightToFee( - taskPayloadOverallWeight, - executionFeeLocation, - )); + xcmOptions?.executionFeeAmount || (await destinationChainAdapter.weightToFee(taskPayloadOverallWeight, executionFeeLocation)); const executionFee = { amount: executionFeeAmout, assetLocation: { V3: executionFeeLocation }, }; // Calculate derive account on Turing/OAK - const deriveAccountId = oakAdapter.getDerivativeAccount( - u8aToHex(keyringPair.addressRaw), - paraId, - xcm.instructionNetworkType, - ); + const deriveAccountId = oakAdapter.getDerivativeAccount(u8aToHex(keyringPair.addressRaw), paraId, xcm.instructionNetworkType); // Create task extrinsic const taskExtrinsic = createTaskFunc({ @@ -129,31 +101,20 @@ const scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow = async ( // Schedule task through XCM const taskEncodedCall = taskExtrinsic.method.toHex(); - const destinationTransactXcmInstructionCount = - destinationChainAdapter.getTransactXcmInstructionCount(); - const taskEncodedCallWeight = await oakAdapter.getExtrinsicWeight( - taskExtrinsic, - deriveAccountId, - ); - const taskOverallWeight = await oakAdapter.calculateXcmOverallWeight( + const destinationTransactXcmInstructionCount = destinationChainAdapter.getTransactXcmInstructionCount(); + const taskEncodedCallWeight = await oakAdapter.getExtrinsicWeight(taskExtrinsic, deriveAccountId); + const taskOverallWeight = await oakAdapter.calculateXcmOverallWeight(taskEncodedCallWeight, destinationTransactXcmInstructionCount); + const taskExecutionFee = await oakAdapter.weightToFee(taskOverallWeight, executionFeeLocation); + const oakLocation = oakAdapter.getLocation(); + const sendExtrinsicResult = await destinationChainAdapter.scheduleTaskThroughXcm( + oakLocation, + taskEncodedCall, + executionFeeLocation, + taskExecutionFee, taskEncodedCallWeight, - destinationTransactXcmInstructionCount, - ); - const taskExecutionFee = await oakAdapter.weightToFee( taskOverallWeight, - executionFeeLocation, + keyringPair, ); - const oakLocation = oakAdapter.getLocation(); - const sendExtrinsicResult = - await destinationChainAdapter.scheduleTaskThroughXcm( - oakLocation, - taskEncodedCall, - executionFeeLocation, - taskExecutionFee, - taskEncodedCallWeight, - taskOverallWeight, - keyringPair, - ); return sendExtrinsicResult; }; @@ -168,58 +129,40 @@ export function Sdk() { params: ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams, automationPriceTriggerParams: AutomationPriceTriggerParams, ): Promise => { - const { - oakAdapter, - destinationChainAdapter, - taskPayloadExtrinsic, - scheduleFeeLocation, - executionFeeLocation, - keyringPair, - xcmOptions, - } = params; - const createTaskFunc = ( - funcParams: CreateTaskFuncParams, - ): SubmittableExtrinsic<"promise"> => { - const { - oakApi, + const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, keyringPair, xcmOptions } = + params; + const createTaskFunc = (funcParams: CreateTaskFuncParams): SubmittableExtrinsic<"promise"> => { + const { oakApi, destination, executionFee, encodedCall, encodedCallWeight, overallWeight } = funcParams; + const taskExtrinsic = oakApi.tx.automationPrice.scheduleXcmpTaskThroughProxy( + automationPriceTriggerParams.chain, + automationPriceTriggerParams.exchange, + automationPriceTriggerParams.asset1, + automationPriceTriggerParams.asset2, + automationPriceTriggerParams.submittedAt, + automationPriceTriggerParams.triggerFunction, + automationPriceTriggerParams.triggerParam, destination, + { V3: scheduleFeeLocation }, executionFee, encodedCall, encodedCallWeight, overallWeight, - } = funcParams; - const taskExtrinsic = - oakApi.tx.automationPrice.scheduleXcmpTaskThroughProxy( - automationPriceTriggerParams.chain, - automationPriceTriggerParams.exchange, - automationPriceTriggerParams.asset1, - automationPriceTriggerParams.asset2, - automationPriceTriggerParams.submittedAt, - automationPriceTriggerParams.triggerFunction, - automationPriceTriggerParams.triggerParam, - destination, - { V3: scheduleFeeLocation }, - executionFee, - encodedCall, - encodedCallWeight, - overallWeight, - u8aToHex(keyringPair.addressRaw), - ); + u8aToHex(keyringPair.addressRaw), + ); return taskExtrinsic; }; - const sendExtrinsicResult = - scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow( - { - executionFeeLocation, - keyringPair, - oakAdapter, - scheduleFeeLocation, - taskPayloadExtrinsic, - xcmOptions, - }, - destinationChainAdapter, - createTaskFunc, - ); + const sendExtrinsicResult = scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow( + { + executionFeeLocation, + keyringPair, + oakAdapter, + scheduleFeeLocation, + taskPayloadExtrinsic, + xcmOptions, + }, + destinationChainAdapter, + createTaskFunc, + ); return sendExtrinsicResult; }, @@ -227,15 +170,8 @@ export function Sdk() { params: ScheduleXcmpTaskWithPayThroughSoverignAccountFlowParams, automationPriceTriggerParams: AutomationPriceTriggerParams, ): Promise => { - const { - oakAdapter, - destinationChainAdapter, - taskPayloadExtrinsic, - scheduleFeeLocation, - executionFeeLocation, - keyringPair, - xcmOptions, - } = params; + const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, keyringPair, xcmOptions } = + params; const [defaultAsset] = oakAdapter.getChainConfig().assets; if (_.isUndefined(defaultAsset)) { throw new Error("chainConfig.defaultAsset not set"); @@ -245,27 +181,13 @@ export function Sdk() { const destination = { V3: destinationChainAdapter.getLocation() }; const encodedCall = taskPayloadExtrinsic.method.toHex(); const oakTransactXcmInstructionCount = - xcmOptions?.instructionCount || - oakAdapter.getTransactXcmInstructionCount( - OakAdapterTransactType.PayThroughSoverignAccount, - ); - const taskPayloadEncodedCallWeight = - await destinationChainAdapter.getExtrinsicWeight( - taskPayloadExtrinsic, - keyringPair, - ); + xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount(OakAdapterTransactType.PayThroughSoverignAccount); + const taskPayloadEncodedCallWeight = await destinationChainAdapter.getExtrinsicWeight(taskPayloadExtrinsic, keyringPair); const taskPayloadOverallWeight = xcmOptions?.overallWeight || - (await destinationChainAdapter.calculateXcmOverallWeight( - taskPayloadEncodedCallWeight, - oakTransactXcmInstructionCount, - )); + (await destinationChainAdapter.calculateXcmOverallWeight(taskPayloadEncodedCallWeight, oakTransactXcmInstructionCount)); const executionFeeAmout = - xcmOptions?.executionFeeAmount || - (await destinationChainAdapter.weightToFee( - taskPayloadOverallWeight, - executionFeeLocation, - )); + xcmOptions?.executionFeeAmount || (await destinationChainAdapter.weightToFee(taskPayloadOverallWeight, executionFeeLocation)); const executionFee = { amount: executionFeeAmout, assetLocation: { V3: executionFeeLocation }, @@ -296,52 +218,34 @@ export function Sdk() { destinationChainAdapter: TaskSchedulerChainAdapter, schedule: any, ): Promise => { - const { - oakAdapter, - taskPayloadExtrinsic, - scheduleFeeLocation, - executionFeeLocation, - keyringPair, - xcmOptions, - } = scheduleXcmpTaskParams; - const createTaskFunc = ( - funcParams: CreateTaskFuncParams, - ): SubmittableExtrinsic<"promise"> => { - const { - oakApi, + const { oakAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, keyringPair, xcmOptions } = scheduleXcmpTaskParams; + const createTaskFunc = (funcParams: CreateTaskFuncParams): SubmittableExtrinsic<"promise"> => { + const { oakApi, destination, executionFee, encodedCall, encodedCallWeight, overallWeight } = funcParams; + console.log("scheduleFeeLocation: ", scheduleFeeLocation); + const taskExtrinsic = oakApi.tx.automationTime.scheduleXcmpTaskThroughProxy( + schedule, destination, + { V3: scheduleFeeLocation }, executionFee, encodedCall, encodedCallWeight, overallWeight, - } = funcParams; - console.log("scheduleFeeLocation: ", scheduleFeeLocation); - const taskExtrinsic = - oakApi.tx.automationTime.scheduleXcmpTaskThroughProxy( - schedule, - destination, - { V3: scheduleFeeLocation }, - executionFee, - encodedCall, - encodedCallWeight, - overallWeight, - u8aToHex(keyringPair.addressRaw), - ); + u8aToHex(keyringPair.addressRaw), + ); return taskExtrinsic; }; - const sendExtrinsicResult = - scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow( - { - executionFeeLocation, - keyringPair, - oakAdapter, - scheduleFeeLocation, - taskPayloadExtrinsic, - xcmOptions, - }, - destinationChainAdapter, - createTaskFunc, - ); + const sendExtrinsicResult = scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow( + { + executionFeeLocation, + keyringPair, + oakAdapter, + scheduleFeeLocation, + taskPayloadExtrinsic, + xcmOptions, + }, + destinationChainAdapter, + createTaskFunc, + ); return sendExtrinsicResult; }, @@ -354,15 +258,8 @@ export function Sdk() { scheduleXcmpTaskParams: ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams, schedule: any, ): Promise => { - const { - oakAdapter, - destinationChainAdapter, - taskPayloadExtrinsic, - scheduleFeeLocation, - executionFeeLocation, - keyringPair, - xcmOptions, - } = scheduleXcmpTaskParams; + const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, keyringPair, xcmOptions } = + scheduleXcmpTaskParams; const [defaultAsset] = oakAdapter.getChainConfig().assets; if (_.isUndefined(defaultAsset)) { throw new Error("chainData.defaultAsset not set"); @@ -372,27 +269,13 @@ export function Sdk() { const destination = { V3: destinationChainAdapter.getLocation() }; const encodedCall = taskPayloadExtrinsic.method.toHex(); const oakTransactXcmInstructionCount = - xcmOptions?.instructionCount || - oakAdapter.getTransactXcmInstructionCount( - OakAdapterTransactType.PayThroughSoverignAccount, - ); - const taskPayloadEncodedCallWeight = - await destinationChainAdapter.getExtrinsicWeight( - taskPayloadExtrinsic, - keyringPair, - ); + xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount(OakAdapterTransactType.PayThroughSoverignAccount); + const taskPayloadEncodedCallWeight = await destinationChainAdapter.getExtrinsicWeight(taskPayloadExtrinsic, keyringPair); const taskPayloadOverallWeight = xcmOptions?.overallWeight || - (await destinationChainAdapter.calculateXcmOverallWeight( - taskPayloadEncodedCallWeight, - oakTransactXcmInstructionCount, - )); + (await destinationChainAdapter.calculateXcmOverallWeight(taskPayloadEncodedCallWeight, oakTransactXcmInstructionCount)); const executionFeeAmout = - xcmOptions?.executionFeeAmount || - (await destinationChainAdapter.weightToFee( - taskPayloadOverallWeight, - executionFeeLocation, - )); + xcmOptions?.executionFeeAmount || (await destinationChainAdapter.weightToFee(taskPayloadOverallWeight, executionFeeLocation)); const executionFee = { amount: executionFeeAmout, assetLocation: { V3: executionFeeLocation },