diff --git a/.changeset/grumpy-toys-check.md b/.changeset/grumpy-toys-check.md new file mode 100644 index 0000000..e921343 --- /dev/null +++ b/.changeset/grumpy-toys-check.md @@ -0,0 +1,5 @@ +--- +"@oak-network/adapter": patch +--- + +Remove keyringPair param from crossChainTransfer diff --git a/packages/adapter/src/chains/astar.ts b/packages/adapter/src/chains/astar.ts index c6b27cc..9c3d6a2 100644 --- a/packages/adapter/src/chains/astar.ts +++ b/packages/adapter/src/chains/astar.ts @@ -8,6 +8,7 @@ import { u8aToHex } from "@polkadot/util"; import type { KeyringPair } from "@polkadot/keyring/types"; import { Weight, XcmInstructionNetworkType, contracts } from "@oak-network/config"; import { ethers } from "ethers"; +import { ISubmittableResult } from "@polkadot/types/types"; import { ChainAdapter, TaskScheduler } from "./chainAdapter"; import { convertAbsoluteLocationToRelative, getDerivativeAccountV3, sendExtrinsic, isValidAddress, getAccountTypeFromAddress } from "../utils"; import { convertLocationToPrecompileMultiLocation } from "../contract-utils"; @@ -192,20 +193,20 @@ export class AstarAdapter extends ChainAdapter implements TaskScheduler { } /** - * Execute a cross-chain transfer + * Create an extrinsic call to transfer asset to a recipient through XCM message * @param destination The location of the destination chain * @param recipient recipient account * @param assetLocation Asset location * @param assetAmount Asset amount * @param keyringPair Operator's keyring pair + * @returns extrinsic */ - async crossChainTransfer( + crossChainTransfer( destination: any, recipient: HexString, assetLocation: any, assetAmount: BN, - keyringPair: KeyringPair, - ): Promise { + ): SubmittableExtrinsic<"promise", ISubmittableResult> { const { key } = this.chainConfig; if (_.isUndefined(key)) throw new Error("chainConfig.key not set"); const api = this.getApi(); @@ -240,12 +241,11 @@ export class AstarAdapter extends ChainAdapter implements TaskScheduler { ); console.log(`Transfer from ${key}, extrinsic:`, extrinsic.method.toHex()); - const result = await sendExtrinsic(api, extrinsic, keyringPair); - return result; + return extrinsic; } /** - * Execute a cross-chain transfer + * Create an extrinsic call to transfer asset to a recipient through XCM message * @param destination The location of the destination chain * @param recipient recipient account * @param assetLocation Asset location diff --git a/packages/adapter/src/chains/chainAdapter.ts b/packages/adapter/src/chains/chainAdapter.ts index 0193fad..cfc4cd5 100644 --- a/packages/adapter/src/chains/chainAdapter.ts +++ b/packages/adapter/src/chains/chainAdapter.ts @@ -7,6 +7,7 @@ import type { SubmittableExtrinsic, AddressOrPair } from "@polkadot/api/types"; import type { u32 } from "@polkadot/types"; import type { HexString } from "@polkadot/util/types"; import type { Weight, Chain } from "@oak-network/config"; +import { ISubmittableResult } from "@polkadot/types/types"; import { SendExtrinsicResult } from "../types"; export abstract class ChainAdapter { @@ -37,11 +38,7 @@ export abstract class ChainAdapter { * @param options Optional operation options: { locationType, network } * @returns Derivative account */ - public abstract getDerivativeAccount( - accountId: HexString, - paraId: number, - options?: any, - ): HexString; + public abstract getDerivativeAccount(accountId: HexString, paraId: number, options?: any): HexString; /** * Get extrinsic weight for transact an extrinsic call through XCM message @@ -49,10 +46,7 @@ export abstract class ChainAdapter { * @param account * @returns Extrinsic weight */ - public abstract getExtrinsicWeight( - extrinsic: SubmittableExtrinsic<"promise">, - account: AddressOrPair, - ): Promise; + public abstract getExtrinsicWeight(extrinsic: SubmittableExtrinsic<"promise">, account: AddressOrPair): Promise; /** * Calculate XCM overall weight for transact an extrinsic call through XCM message @@ -60,10 +54,7 @@ export abstract class ChainAdapter { * @param instructionCount The number of XCM instructions * @returns XCM overall weight */ - public abstract calculateXcmOverallWeight( - transactCallWeight: Weight, - instructionCount: number, - ): Promise; + public abstract calculateXcmOverallWeight(transactCallWeight: Weight, instructionCount: number): Promise; /** * Calculate XCM execution fee based on weight @@ -74,7 +65,7 @@ export abstract class ChainAdapter { public abstract weightToFee(weight: Weight, assetLocation: any): Promise; /** - * Execute a cross-chain transfer + * Create an extrinsic call to transfer asset to a recipient through XCM message * @param destination The location of the destination chain * @param recipient recipient account * @param assetLocation Asset location @@ -87,7 +78,7 @@ export abstract class ChainAdapter { assetLocation: any, assetAmount: BN, keyringPair: KeyringPair, - ): Promise; + ): SubmittableExtrinsic<"promise", ISubmittableResult>; /** * Get polkadot API @@ -103,9 +94,7 @@ export abstract class ChainAdapter { */ public async fetchAndUpdateConfigs(): Promise { const api = this.getApi(); - this.chainConfig.ss58Prefix = ( - api.consts.system.ss58Prefix as unknown as u32 - ).toNumber(); + this.chainConfig.ss58Prefix = (api.consts.system.ss58Prefix as unknown as u32).toNumber(); const storageValue = await api.query.parachainInfo.parachainId(); this.chainConfig.paraId = (storageValue as unknown as u32).toNumber(); } diff --git a/packages/adapter/src/chains/mangata.ts b/packages/adapter/src/chains/mangata.ts index 0d72bc9..3ac5b4f 100644 --- a/packages/adapter/src/chains/mangata.ts +++ b/packages/adapter/src/chains/mangata.ts @@ -4,12 +4,12 @@ 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 { HexString } from "@polkadot/util/types"; -import type { KeyringPair } from "@polkadot/keyring/types"; import { Weight } from "@oak-network/config"; +import { ISubmittableResult } from "@polkadot/types/types"; import { ChainAdapter } from "./chainAdapter"; -import { getDerivativeAccountV2, sendExtrinsic, isValidAddress, getAccountTypeFromAddress } from "../utils"; +import { getDerivativeAccountV2, isValidAddress, getAccountTypeFromAddress } from "../utils"; import { WEIGHT_REF_TIME_PER_NANOS, WEIGHT_REF_TIME_PER_SECOND, WEIGHT_PROOF_SIZE_PER_MB } from "../constants"; -import { AccountType, SendExtrinsicResult } from "../types"; +import { AccountType } from "../types"; import { InvalidAddress } from "../errors"; // MangataAdapter implements ChainAdapter @@ -107,21 +107,20 @@ export class MangataAdapter extends ChainAdapter { } /** - * Execute a cross-chain transfer + * Create an extrinsic call to transfer asset to a recipient through XCM message * @param destination The location of the destination chain * @param recipient recipient account * @param assetLocation Asset location * @param assetAmount Asset amount * @param keyringPair Operator's keyring pair - * @returns SendExtrinsicResult + * @returns extrinsic */ - async crossChainTransfer( + crossChainTransfer( destination: any, recipient: HexString, assetLocation: any, assetAmount: BN, - keyringPair: KeyringPair, - ): Promise { + ): SubmittableExtrinsic<"promise", ISubmittableResult> { const { key } = this.chainConfig; if (_.isUndefined(key)) throw new Error("chainConfig.key not set"); @@ -154,7 +153,6 @@ export class MangataAdapter extends ChainAdapter { ); console.log(`Transfer from ${key}, extrinsic:`, extrinsic.method.toHex()); - const result = await sendExtrinsic(api, extrinsic, keyringPair); - return result; + return extrinsic; } } diff --git a/packages/adapter/src/chains/moonbeam.ts b/packages/adapter/src/chains/moonbeam.ts index 4ea98a5..29c3911 100644 --- a/packages/adapter/src/chains/moonbeam.ts +++ b/packages/adapter/src/chains/moonbeam.ts @@ -7,6 +7,7 @@ import type { HexString } from "@polkadot/util/types"; import type { KeyringPair } from "@polkadot/keyring/types"; import { Weight, contracts } from "@oak-network/config"; import { ethers } from "ethers"; +import { ISubmittableResult } from "@polkadot/types/types"; import { ChainAdapter, TaskScheduler } from "./chainAdapter"; import { convertAbsoluteLocationToRelative, getDerivativeAccountV3, sendExtrinsic, isValidAddress, getAccountTypeFromAddress } from "../utils"; import { convertLocationToPrecompileMultiLocation } from "../contract-utils"; @@ -178,21 +179,20 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { } /** - * Execute a cross-chain transfer + * Create an extrinsic call to transfer asset to a recipient through XCM message * @param destination The location of the destination chain * @param recipient recipient account * @param assetLocation Asset location * @param assetAmount Asset amount * @param keyringPair Operator's keyring pair - * @returns SendExtrinsicResult + * @returns extrinsic */ - async crossChainTransfer( + crossChainTransfer( destination: any, recipient: HexString, assetLocation: any, assetAmount: BN, - keyringPair: KeyringPair, - ): Promise { + ): SubmittableExtrinsic<"promise", ISubmittableResult> { const { key } = this.chainConfig; if (_.isUndefined(key)) throw new Error("chainConfig.key not set"); @@ -227,8 +227,7 @@ export class MoonbeamAdapter extends ChainAdapter implements TaskScheduler { ); console.log(`Transfer from ${key}, extrinsic:`, extrinsic.method.toHex()); - const result = await sendExtrinsic(api, extrinsic, keyringPair); - return result; + return extrinsic; } /** diff --git a/packages/adapter/src/chains/oak.ts b/packages/adapter/src/chains/oak.ts index a39c665..fda3047 100644 --- a/packages/adapter/src/chains/oak.ts +++ b/packages/adapter/src/chains/oak.ts @@ -144,21 +144,20 @@ export class OakAdapter extends ChainAdapter { } /** - * Execute a cross-chain transfer + * Create an extrinsic call to transfer asset to a recipient through XCM message * @param destination The location of the destination chain * @param recipient recipient account * @param assetLocation Asset location * @param assetAmount Asset amount * @param keyringPair Operator's keyring pair - * @returns SendExtrinsicResult + * @returns extrinsic */ - async crossChainTransfer( + crossChainTransfer( destination: any, recipient: HexString, assetLocation: any, assetAmount: BN, - keyringPair: KeyringPair, - ): Promise { + ): SubmittableExtrinsic<"promise", ISubmittableResult> { const { key } = this.chainConfig; if (_.isUndefined(key)) throw new Error("chainConfig.key not set"); const api = this.getApi(); @@ -191,8 +190,7 @@ export class OakAdapter extends ChainAdapter { ); console.log(`Transfer from ${key}, extrinsic:`, extrinsic.method.toHex()); - const result = await sendExtrinsic(api, extrinsic, keyringPair); - return result; + return extrinsic; } /**