Skip to content

Commit

Permalink
Change oakAdapter account derivation (#125)
Browse files Browse the repository at this point in the history
* Change oakAdapter account derivation

* docs(changeset): Change oakAdapter account derivation
  • Loading branch information
imstar15 authored Dec 12, 2023
1 parent 776a764 commit 9cfa4a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
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

0 comments on commit 9cfa4a9

Please sign in to comment.