Skip to content

Commit

Permalink
Remove keyringPair param from crossChainTransfer function (#149)
Browse files Browse the repository at this point in the history
* Remove keyringPair param from crossChainTransfer

* docs(changeset): Remove keyringPair param from crossChainTransfer
  • Loading branch information
imstar15 authored Jan 18, 2024
1 parent 9dbcc07 commit 583b160
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-toys-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@oak-network/adapter": patch
---

Remove keyringPair param from crossChainTransfer
14 changes: 7 additions & 7 deletions packages/adapter/src/chains/astar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<SendExtrinsicResult> {
): SubmittableExtrinsic<"promise", ISubmittableResult> {
const { key } = this.chainConfig;
if (_.isUndefined(key)) throw new Error("chainConfig.key not set");
const api = this.getApi();
Expand Down Expand Up @@ -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
Expand Down
25 changes: 7 additions & 18 deletions packages/adapter/src/chains/chainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -37,33 +38,23 @@ 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
* @param extrinsic
* @param account
* @returns Extrinsic weight
*/
public abstract getExtrinsicWeight(
extrinsic: SubmittableExtrinsic<"promise">,
account: AddressOrPair,
): Promise<Weight>;
public abstract getExtrinsicWeight(extrinsic: SubmittableExtrinsic<"promise">, account: AddressOrPair): Promise<Weight>;

/**
* Calculate XCM overall weight for transact an extrinsic call through XCM message
* @param transactCallWeight
* @param instructionCount The number of XCM instructions
* @returns XCM overall weight
*/
public abstract calculateXcmOverallWeight(
transactCallWeight: Weight,
instructionCount: number,
): Promise<Weight>;
public abstract calculateXcmOverallWeight(transactCallWeight: Weight, instructionCount: number): Promise<Weight>;

/**
* Calculate XCM execution fee based on weight
Expand All @@ -74,7 +65,7 @@ export abstract class ChainAdapter {
public abstract weightToFee(weight: Weight, assetLocation: any): Promise<BN>;

/**
* 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
Expand All @@ -87,7 +78,7 @@ export abstract class ChainAdapter {
assetLocation: any,
assetAmount: BN,
keyringPair: KeyringPair,
): Promise<SendExtrinsicResult>;
): SubmittableExtrinsic<"promise", ISubmittableResult>;

/**
* Get polkadot API
Expand All @@ -103,9 +94,7 @@ export abstract class ChainAdapter {
*/
public async fetchAndUpdateConfigs(): Promise<void> {
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();
}
Expand Down
18 changes: 8 additions & 10 deletions packages/adapter/src/chains/mangata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<SendExtrinsicResult> {
): SubmittableExtrinsic<"promise", ISubmittableResult> {
const { key } = this.chainConfig;
if (_.isUndefined(key)) throw new Error("chainConfig.key not set");

Expand Down Expand Up @@ -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;
}
}
13 changes: 6 additions & 7 deletions packages/adapter/src/chains/moonbeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<SendExtrinsicResult> {
): SubmittableExtrinsic<"promise", ISubmittableResult> {
const { key } = this.chainConfig;
if (_.isUndefined(key)) throw new Error("chainConfig.key not set");

Expand Down Expand Up @@ -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;
}

/**
Expand Down
12 changes: 5 additions & 7 deletions packages/adapter/src/chains/oak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SendExtrinsicResult> {
): SubmittableExtrinsic<"promise", ISubmittableResult> {
const { key } = this.chainConfig;
if (_.isUndefined(key)) throw new Error("chainConfig.key not set");
const api = this.getApi();
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 583b160

Please sign in to comment.