Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return different instruction numbers based on the transactType #110

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/adapter/src/chains/oak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { getDerivativeAccountV2, sendExtrinsic } from "../util";
import { SendExtrinsicResult } from "../types";
import { WEIGHT_REF_TIME_PER_SECOND } from "../constants";

const TRANSACT_XCM_INSTRUCTION_COUNT = 4;
export enum OakAdapterTransactType {
PayThroughRemoteDerivativeAccount,
PayThroughSoverignAccount,
}

// OakAdapter implements ChainAdapter
export class OakAdapter extends ChainAdapter {
Expand Down Expand Up @@ -140,10 +143,18 @@ export class OakAdapter extends ChainAdapter {

/**
* Get the instruction number of XCM instructions for transact
* In the xcmp-handler, there are two processes for sending XCM instructions.
* PayThroughRemoteDerivativeAccount requires 4 XCM instructions,
* PayThroughSovereignAccount requires 6 instructions.
* @param transactType
* @returns The instruction number of XCM instructions
*/
// eslint-disable-next-line class-methods-use-this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can delete this // eslint-disable-next-line class-methods-use-this since there is no this used in the function

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the function doesn't use this.
However, we can't remove it. If we delete it, we would have to convert the function into a static method. I prefer not to do that.
https://eslint.org/docs/latest/rules/class-methods-use-this

getTransactXcmInstructionCount() {
return TRANSACT_XCM_INSTRUCTION_COUNT;
getTransactXcmInstructionCount(transactType: OakAdapterTransactType) {
return transactType ===
OakAdapterTransactType.PayThroughRemoteDerivativeAccount
? 4
: 6;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
OakAdapter,
TaskSchedulerChainAdapter,
SendExtrinsicResult,
OakAdapterTransactType,
} from "@oak-network/adapter";
import { Weight } from "@oak-network/config";

Expand Down Expand Up @@ -124,7 +125,10 @@ const scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow = async (
const destination = { V3: destinationChainAdapter.getLocation() };
const encodedCall = taskPayloadExtrinsic.method.toHex();
const oakTransactXcmInstructionCount =
xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount();
xcmOptions?.instructionCount ||
oakAdapter.getTransactXcmInstructionCount(
OakAdapterTransactType.PayThroughRemoteDerivativeAccount,
);
const taskPayloadEncodedCallWeight =
await destinationChainAdapter.getExtrinsicWeight(
taskPayloadExtrinsic,
Expand Down Expand Up @@ -339,7 +343,9 @@ export function Sdk() {
const encodedCall = taskPayloadExtrinsic.method.toHex();
const oakTransactXcmInstructionCount =
xcmOptions?.instructionCount ||
oakAdapter.getTransactXcmInstructionCount();
oakAdapter.getTransactXcmInstructionCount(
OakAdapterTransactType.PayThroughSoverignAccount,
);
const taskPayloadEncodedCallWeight =
await destinationChainAdapter.getExtrinsicWeight(
taskPayloadExtrinsic,
Expand Down