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

Change oakAdapter account derivation #125

Merged
merged 2 commits into from
Dec 12, 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
6 changes: 6 additions & 0 deletions .changeset/cyan-needles-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@oak-network/adapter": patch
"@oak-network/sdk": patch
---

Change oakAdapter account derivation
22 changes: 5 additions & 17 deletions packages/adapter/src/chains/oak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +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, Chain, XToken } from "@oak-network/config";
import { ISubmittableResult } from "@polkadot/types/types";
import { ChainAdapter } from "./chainAdapter";
import { getDerivativeAccountV2, isValidAddress, sendExtrinsic, getDecimalBN } from "../utils";
import { isValidAddress, sendExtrinsic, getDecimalBN, getDerivativeAccountV3 } from "../utils";
import { AccountType, SendExtrinsicResult } from "../types";
import { WEIGHT_REF_TIME_PER_SECOND } from "../constants";
import { InvalidAddress } from "../errors";
Expand Down Expand Up @@ -296,23 +296,11 @@ export class OakAdapter extends ChainAdapter {
* Calculate the derivative account ID of a certain account ID
* @param accountId
* @param paraId The paraId of the XCM message sender
* @param options Optional operation options: { locationType, network }
* @returns Derivative account
*/
getDerivativeAccount(
accountId: HexString,
paraId: number,
xcmInstructionNetworkType: XcmInstructionNetworkType = XcmInstructionNetworkType.Null,
): HexString {
const api = this.getApi();
const accountOptions =
xcmInstructionNetworkType === XcmInstructionNetworkType.Concrete
? {
locationType: "XcmV3MultiLocation",
network: this.getChainConfig().xcm.network,
}
: undefined;
return getDerivativeAccountV2(api, accountId, paraId, accountOptions);
// eslint-disable-next-line class-methods-use-this
getDerivativeAccount(accountId: HexString, paraId: number): HexString {
return getDerivativeAccountV3(accountId, paraId);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow = async (
};

// Calculate derive account on Turing/OAK
const deriveAccountId = oakAdapter.getDerivativeAccount(u8aToHex(keyringPair.addressRaw), paraId, xcm.instructionNetworkType);
const deriveAccountId = oakAdapter.getDerivativeAccount(u8aToHex(keyringPair.addressRaw), paraId);

// Create task extrinsic
const taskExtrinsic = createTaskFunc({
Expand Down