Socket
Socket
Sign inDemoInstall

@oak-network/sdk

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oak-network/sdk - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

62

index.d.ts

@@ -1,28 +0,11 @@

import BN from 'bn.js';
import type { SubmittableExtrinsic } from '@polkadot/api/types';
import type { HexString } from '@polkadot/util/types';
import type { KeyringPair } from '@polkadot/keyring/types';
import { ChainAdapter, OakAdapter, TaskSchedulerChainAdapter, SendExtrinsicResult } from '@oak-network/adapter';
import { Weight } from '@oak-network/sdk-types';
interface ScheduleXcmpTaskWithPayThroughSoverignAccountFlowParams {
import BN from "bn.js";
import type { SubmittableExtrinsic } from "@polkadot/api/types";
import type { KeyringPair } from "@polkadot/keyring/types";
import { ChainAdapter, OakAdapter, TaskSchedulerChainAdapter, SendExtrinsicResult, AutomationPriceTriggerParams } from "@oak-network/adapter";
import { Weight } from "@oak-network/config";
interface ScheduleXcmpTaskParams {
oakAdapter: OakAdapter;
destinationChainAdapter: ChainAdapter;
taskPayloadExtrinsic: SubmittableExtrinsic<'promise'>;
schedule: any;
keyringPair: KeyringPair;
xcmOptions?: {
instructionCount?: number;
overallWeight?: Weight;
executionFeeAmount?: BN;
};
}
interface ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams {
oakAdapter: OakAdapter;
destinationChainAdapter: TaskSchedulerChainAdapter;
taskPayloadExtrinsic: SubmittableExtrinsic<'promise'>;
taskPayloadExtrinsic: SubmittableExtrinsic<"promise">;
scheduleFeeLocation: any;
executionFeeLocation: any;
schedule: any;
scheduleAs: HexString;
keyringPair: KeyringPair;
xcmOptions?: {

@@ -33,29 +16,18 @@ instructionCount?: number;

};
keyringPair: KeyringPair;
}
interface AutomationPriceTriggerParams {
chain: string;
exchange: string;
asset1: string;
asset2: string;
submittedAt: number;
triggerFunction: 'lt' | 'gt';
triggerParam: number[];
interface ScheduleXcmpTaskWithPayThroughSoverignAccountFlowParams extends ScheduleXcmpTaskParams {
destinationChainAdapter: ChainAdapter;
}
interface ScheduleXcmpPriceTaskWithPayThroughRemoteDerivativeAccountFlowParams {
oakAdapter: OakAdapter;
interface ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams extends ScheduleXcmpTaskParams {
destinationChainAdapter: TaskSchedulerChainAdapter;
taskPayloadExtrinsic: SubmittableExtrinsic<'promise'>;
scheduleFeeLocation: any;
executionFeeLocation: any;
automationPriceTriggerParams: AutomationPriceTriggerParams;
scheduleAs: HexString;
keyringPair: KeyringPair;
}
export declare function Sdk(): {
/**
* Schedule XCMP task with PayThroughSoverignAccount instruction sequances
* Schedule XCMP price task with PayThroughRemoteDerivativeAccount instruction sequances
* @param params Operation params
* @returns
*/
scheduleXcmpTaskWithPayThroughSoverignAccountFlow: (params: ScheduleXcmpTaskWithPayThroughSoverignAccountFlowParams) => Promise<SendExtrinsicResult>;
scheduleXcmpPriceTaskWithPayThroughRemoteDerivativeAccountFlow: (params: ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams, automationPriceTriggerParams: AutomationPriceTriggerParams) => Promise<SendExtrinsicResult>;
scheduleXcmpPriceTaskWithPayThroughSoverignAccountFlow: (params: ScheduleXcmpTaskWithPayThroughSoverignAccountFlowParams, automationPriceTriggerParams: AutomationPriceTriggerParams) => Promise<SendExtrinsicResult>;
/**

@@ -66,10 +38,10 @@ * Schedule XCMP time task with PayThroughRemoteDerivativeAccount instruction sequances

*/
scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow: (params: ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams) => Promise<SendExtrinsicResult>;
scheduleXcmpTimeTaskWithPayThroughRemoteDerivativeAccountFlow: (scheduleXcmpTaskParams: ScheduleXcmpTaskParams, destinationChainAdapter: TaskSchedulerChainAdapter, schedule: any) => Promise<SendExtrinsicResult>;
/**
* Schedule XCMP price task with PayThroughRemoteDerivativeAccount instruction sequances
* Schedule XCMP task with PayThroughSoverignAccount instruction sequances
* @param params Operation params
* @returns
*/
scheduleXcmpPriceTaskWithPayThroughRemoteDerivativeAccountFlow: (params: ScheduleXcmpPriceTaskWithPayThroughRemoteDerivativeAccountFlowParams) => Promise<SendExtrinsicResult>;
scheduleXcmpTimeTaskWithPayThroughSoverignAccountFlow: (scheduleXcmpTaskParams: ScheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlowParams, schedule: any) => Promise<SendExtrinsicResult>;
};
export {};

@@ -15,17 +15,14 @@ "use strict";

*/
const scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow = async (params) => {
const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, createTaskFunc, executionFeeLocation, keyringPair, xcmOptions, } = params;
const { defaultAsset } = oakAdapter.getChainData();
const scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow = async (params, destinationChainAdapter, createTaskFunc) => {
const { oakAdapter, taskPayloadExtrinsic, executionFeeLocation, keyringPair, xcmOptions } = params;
const [defaultAsset] = oakAdapter.getChainConfig().assets;
if (lodash_1.default.isUndefined(defaultAsset)) {
throw new Error("chainData.defaultAsset not set");
throw new Error("chainConfig.defaultAsset not set");
}
const { paraId, xcmInstructionNetworkType, xcm } = destinationChainAdapter.getChainData();
const { paraId, xcm } = destinationChainAdapter.getChainConfig();
if (lodash_1.default.isUndefined(paraId)) {
throw new Error("chainData.paraId not set");
throw new Error("chainConfig.paraId not set");
}
if (lodash_1.default.isUndefined(xcmInstructionNetworkType)) {
throw new Error("chainData.xcmInstructionNetworkType not set");
}
if (lodash_1.default.isUndefined(xcm)) {
throw new Error("chainData.xcm not set");
throw new Error("chainConfig.xcm not set");
}

@@ -35,17 +32,20 @@ // Caluculate weight and fee for task

const encodedCall = taskPayloadExtrinsic.method.toHex();
const oakTransactXcmInstructionCount = xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount();
const oakTransactXcmInstructionCount = xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount(adapter_1.OakAdapterTransactType.PayThroughRemoteDerivativeAccount);
const taskPayloadEncodedCallWeight = await destinationChainAdapter.getExtrinsicWeight(taskPayloadExtrinsic, keyringPair);
const taskPayloadOverallWeight = xcmOptions?.overallWeight || await destinationChainAdapter.calculateXcmOverallWeight(taskPayloadEncodedCallWeight, oakTransactXcmInstructionCount);
const executionFeeAmout = xcmOptions?.executionFeeAmount || await destinationChainAdapter.weightToFee(taskPayloadOverallWeight, executionFeeLocation);
const executionFee = { assetLocation: { V3: executionFeeLocation }, amount: executionFeeAmout };
const taskPayloadOverallWeight = xcmOptions?.overallWeight ||
(await destinationChainAdapter.calculateXcmOverallWeight(taskPayloadEncodedCallWeight, oakTransactXcmInstructionCount));
const executionFeeAmout = xcmOptions?.executionFeeAmount || (await destinationChainAdapter.weightToFee(taskPayloadOverallWeight, executionFeeLocation));
const executionFee = {
amount: executionFeeAmout,
assetLocation: { V3: executionFeeLocation },
};
// Calculate derive account on Turing/OAK
const accountOptions = xcmInstructionNetworkType === adapter_1.XcmInstructionNetworkType.Concrete ? { locationType: 'XcmV3MultiLocation', network: xcm.network } : undefined;
const deriveAccountId = oakAdapter.getDerivativeAccount((0, util_1.u8aToHex)(keyringPair.addressRaw), paraId, accountOptions);
const deriveAccountId = oakAdapter.getDerivativeAccount((0, util_1.u8aToHex)(keyringPair.addressRaw), paraId, xcm.instructionNetworkType);
// Create task extrinsic
const taskExtrinsic = createTaskFunc({
oakApi: oakAdapter.getApi(),
destination,
executionFee,
encodedCall,
encodedCallWeight: taskPayloadEncodedCallWeight,
executionFee,
oakApi: oakAdapter.getApi(),
overallWeight: taskPayloadOverallWeight,

@@ -66,11 +66,28 @@ });

/**
* Schedule XCMP task with PayThroughSoverignAccount instruction sequances
* Schedule XCMP price task with PayThroughRemoteDerivativeAccount instruction sequances
* @param params Operation params
* @returns
*/
scheduleXcmpTaskWithPayThroughSoverignAccountFlow: async (params) => {
const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, schedule, keyringPair, xcmOptions } = params;
const { defaultAsset } = oakAdapter.getChainData();
scheduleXcmpPriceTaskWithPayThroughRemoteDerivativeAccountFlow: async (params, automationPriceTriggerParams) => {
const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, keyringPair, xcmOptions } = params;
const createTaskFunc = (funcParams) => {
const { oakApi, destination, executionFee, encodedCall, encodedCallWeight, overallWeight } = funcParams;
const taskExtrinsic = oakApi.tx.automationPrice.scheduleXcmpTaskThroughProxy(automationPriceTriggerParams.chain, automationPriceTriggerParams.exchange, automationPriceTriggerParams.asset1, automationPriceTriggerParams.asset2, automationPriceTriggerParams.submittedAt, automationPriceTriggerParams.triggerFunction, automationPriceTriggerParams.triggerParam, destination, { V3: scheduleFeeLocation }, executionFee, encodedCall, encodedCallWeight, overallWeight, (0, util_1.u8aToHex)(keyringPair.addressRaw));
return taskExtrinsic;
};
const sendExtrinsicResult = scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow({
executionFeeLocation,
keyringPair,
oakAdapter,
scheduleFeeLocation,
taskPayloadExtrinsic,
xcmOptions,
}, destinationChainAdapter, createTaskFunc);
return sendExtrinsicResult;
},
scheduleXcmpPriceTaskWithPayThroughSoverignAccountFlow: async (params, automationPriceTriggerParams) => {
const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, keyringPair, xcmOptions } = params;
const [defaultAsset] = oakAdapter.getChainConfig().assets;
if (lodash_1.default.isUndefined(defaultAsset)) {
throw new Error("chainData.defaultAsset not set");
throw new Error("chainConfig.defaultAsset not set");
}

@@ -80,10 +97,13 @@ // Caluculate weight and fee for task

const encodedCall = taskPayloadExtrinsic.method.toHex();
const oakTransactXcmInstructionCount = xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount();
const oakTransactXcmInstructionCount = xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount(adapter_1.OakAdapterTransactType.PayThroughSoverignAccount);
const taskPayloadEncodedCallWeight = await destinationChainAdapter.getExtrinsicWeight(taskPayloadExtrinsic, keyringPair);
const taskPayloadOverallWeight = xcmOptions?.overallWeight || await destinationChainAdapter.calculateXcmOverallWeight(taskPayloadEncodedCallWeight, oakTransactXcmInstructionCount);
const scheduleFee = { V3: defaultAsset.location };
const executionFeeAmout = xcmOptions?.executionFeeAmount || await destinationChainAdapter.weightToFee(taskPayloadOverallWeight, defaultAsset.location);
const executionFee = { assetLocation: { V3: defaultAsset.location }, amount: executionFeeAmout };
const taskPayloadOverallWeight = xcmOptions?.overallWeight ||
(await destinationChainAdapter.calculateXcmOverallWeight(taskPayloadEncodedCallWeight, oakTransactXcmInstructionCount));
const executionFeeAmout = xcmOptions?.executionFeeAmount || (await destinationChainAdapter.weightToFee(taskPayloadOverallWeight, executionFeeLocation));
const executionFee = {
amount: executionFeeAmout,
assetLocation: { V3: executionFeeLocation },
};
// Schedule XCMP task
const sendExtrinsicResult = oakAdapter.scheduleXcmpTask(destination, schedule, scheduleFee, executionFee, encodedCall, taskPayloadEncodedCallWeight, taskPayloadOverallWeight, keyringPair);
const sendExtrinsicResult = oakAdapter.scheduleXcmpPriceTask(automationPriceTriggerParams, destination, { V3: scheduleFeeLocation }, executionFee, encodedCall, taskPayloadEncodedCallWeight, taskPayloadOverallWeight, keyringPair);
return sendExtrinsicResult;

@@ -96,30 +116,45 @@ },

*/
scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow: async (params) => {
const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, schedule, scheduleAs, keyringPair, } = params;
const createTaskFunc = (params) => {
const { oakApi, destination, executionFee, encodedCall, encodedCallWeight, overallWeight } = params;
console.log('scheduleFeeLocation: ', scheduleFeeLocation);
const taskExtrinsic = oakApi.tx.automationTime.scheduleXcmpTaskThroughProxy(schedule, destination, { V3: scheduleFeeLocation }, executionFee, encodedCall, encodedCallWeight, overallWeight, scheduleAs);
scheduleXcmpTimeTaskWithPayThroughRemoteDerivativeAccountFlow: async (scheduleXcmpTaskParams, destinationChainAdapter, schedule) => {
const { oakAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, keyringPair, xcmOptions } = scheduleXcmpTaskParams;
const createTaskFunc = (funcParams) => {
const { oakApi, destination, executionFee, encodedCall, encodedCallWeight, overallWeight } = funcParams;
console.log("scheduleFeeLocation: ", scheduleFeeLocation);
const taskExtrinsic = oakApi.tx.automationTime.scheduleXcmpTaskThroughProxy(schedule, destination, { V3: scheduleFeeLocation }, executionFee, encodedCall, encodedCallWeight, overallWeight, (0, util_1.u8aToHex)(keyringPair.addressRaw));
return taskExtrinsic;
};
const sendExtrinsicResult = scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow({
oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, createTaskFunc, scheduleFeeLocation, executionFeeLocation, keyringPair,
});
executionFeeLocation,
keyringPair,
oakAdapter,
scheduleFeeLocation,
taskPayloadExtrinsic,
xcmOptions,
}, destinationChainAdapter, createTaskFunc);
return sendExtrinsicResult;
},
/**
* Schedule XCMP price task with PayThroughRemoteDerivativeAccount instruction sequances
* Schedule XCMP task with PayThroughSoverignAccount instruction sequances
* @param params Operation params
* @returns
*/
scheduleXcmpPriceTaskWithPayThroughRemoteDerivativeAccountFlow: async (params) => {
const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, automationPriceTriggerParams, scheduleAs, keyringPair, } = params;
const createTaskFunc = (params) => {
const { oakApi, destination, executionFee, encodedCall, encodedCallWeight, overallWeight } = params;
const taskExtrinsic = oakApi.tx.automationPrice.scheduleXcmpTaskThroughProxy(automationPriceTriggerParams.chain, automationPriceTriggerParams.exchange, automationPriceTriggerParams.asset1, automationPriceTriggerParams.asset2, automationPriceTriggerParams.submittedAt, automationPriceTriggerParams.triggerFunction, automationPriceTriggerParams.triggerParam, destination, { V3: scheduleFeeLocation }, executionFee, encodedCall, encodedCallWeight, overallWeight, scheduleAs);
return taskExtrinsic;
scheduleXcmpTimeTaskWithPayThroughSoverignAccountFlow: async (scheduleXcmpTaskParams, schedule) => {
const { oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, scheduleFeeLocation, executionFeeLocation, keyringPair, xcmOptions } = scheduleXcmpTaskParams;
const [defaultAsset] = oakAdapter.getChainConfig().assets;
if (lodash_1.default.isUndefined(defaultAsset)) {
throw new Error("chainData.defaultAsset not set");
}
// Caluculate weight and fee for task
const destination = { V3: destinationChainAdapter.getLocation() };
const encodedCall = taskPayloadExtrinsic.method.toHex();
const oakTransactXcmInstructionCount = xcmOptions?.instructionCount || oakAdapter.getTransactXcmInstructionCount(adapter_1.OakAdapterTransactType.PayThroughSoverignAccount);
const taskPayloadEncodedCallWeight = await destinationChainAdapter.getExtrinsicWeight(taskPayloadExtrinsic, keyringPair);
const taskPayloadOverallWeight = xcmOptions?.overallWeight ||
(await destinationChainAdapter.calculateXcmOverallWeight(taskPayloadEncodedCallWeight, oakTransactXcmInstructionCount));
const executionFeeAmout = xcmOptions?.executionFeeAmount || (await destinationChainAdapter.weightToFee(taskPayloadOverallWeight, executionFeeLocation));
const executionFee = {
amount: executionFeeAmout,
assetLocation: { V3: executionFeeLocation },
};
const sendExtrinsicResult = scheduleXcmpTaskWithPayThroughRemoteDerivativeAccountFlow({
oakAdapter, destinationChainAdapter, taskPayloadExtrinsic, createTaskFunc, scheduleFeeLocation, executionFeeLocation, keyringPair,
});
// Schedule XCMP task
const sendExtrinsicResult = oakAdapter.scheduleXcmpTask(destination, schedule, { V3: scheduleFeeLocation }, executionFee, encodedCall, taskPayloadEncodedCallWeight, taskPayloadOverallWeight, keyringPair);
return sendExtrinsicResult;

@@ -126,0 +161,0 @@ },

{
"name": "@oak-network/sdk",
"version": "0.1.4",
"version": "0.2.0",
"license": "Apache-2.0",
"main": "./index.js",
"scripts": {},
"dependencies": {
"@oak-network/adapter": "^0.2.0",
"@oak-network/config": "^1.0.1",
"@polkadot/util": "^12.6.1",
"bn.js": "^5.2.1",
"lodash": "^4.17.21"
},
"devDependencies": {
"typescript": "^5.3.2"
},
"types": "./index.d.ts"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc