Socket
Socket
Sign inDemoInstall

@oasisdex/automation

Package Overview
Dependencies
Maintainers
9
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oasisdex/automation - npm Package Compare versions

Comparing version 1.6.0-alpha.9 to 1.6.0-alpha.10

5

lib/src/abi-coding.d.ts

@@ -5,9 +5,14 @@ import { utils } from 'ethers';

export declare function decodeTriggerDataByType(type: CommandContractType, data: string): utils.Result;
export declare function decodeOffchainTriggerDataByType(type: CommandContractType, data: string): utils.Result;
export declare function decodeTriggerDataByTriggerType(triggerType: TriggerType, data: string): utils.Result;
export declare function decodeOffchainTriggerDataByTriggerType(triggerType: TriggerType, data: string): utils.Result;
export declare function decodeTriggerDataAsJson(commandAddress: string, network: number, data: string): utils.Result;
export declare function decodeTriggerDataByTypeAsJson(type: CommandContractType, data: string): utils.Result;
export declare function decodeTriggerDataByTriggerTypeAsJson(triggerType: TriggerType, data: string): utils.Result;
export declare function decodeOffchainTriggerDataByTriggerTypeAsJson(triggerType: TriggerType, data: string): utils.Result;
export declare function encodeTriggerData(commandAddress: string, network: number, values: readonly any[]): string;
export declare function encodeTriggerDataByType(type: CommandContractType, values: readonly any[]): string;
export declare function encodeTriggerDataByTriggerType(triggerType: TriggerType, values: readonly any[]): string;
export declare function encodeOffchainTriggerDataByType(type: CommandContractType, values: readonly any[]): string;
export declare function encodeTriggerOffchainDataByTriggerType(triggerType: TriggerType, values: readonly any[]): string;
//# sourceMappingURL=abi-coding.d.ts.map

37

lib/src/abi-coding.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeTriggerDataByTriggerType = exports.encodeTriggerDataByType = exports.encodeTriggerData = exports.decodeTriggerDataByTriggerTypeAsJson = exports.decodeTriggerDataByTypeAsJson = exports.decodeTriggerDataAsJson = exports.decodeTriggerDataByTriggerType = exports.decodeTriggerDataByType = exports.decodeTriggerData = void 0;
exports.encodeTriggerOffchainDataByTriggerType = exports.encodeOffchainTriggerDataByType = exports.encodeTriggerDataByTriggerType = exports.encodeTriggerDataByType = exports.encodeTriggerData = exports.decodeOffchainTriggerDataByTriggerTypeAsJson = exports.decodeTriggerDataByTriggerTypeAsJson = exports.decodeTriggerDataByTypeAsJson = exports.decodeTriggerDataAsJson = exports.decodeOffchainTriggerDataByTriggerType = exports.decodeTriggerDataByTriggerType = exports.decodeOffchainTriggerDataByType = exports.decodeTriggerDataByType = exports.decodeTriggerData = void 0;
const ethers_1 = require("ethers");

@@ -17,2 +17,7 @@ const mapping_1 = require("./mapping");

exports.decodeTriggerDataByType = decodeTriggerDataByType;
function decodeOffchainTriggerDataByType(type, data) {
const paramTypes = (0, mapping_1.getOffchainDataDefinitionForCommandType)(type);
return ethers_1.utils.defaultAbiCoder.decode(paramTypes, data);
}
exports.decodeOffchainTriggerDataByType = decodeOffchainTriggerDataByType;
function decodeTriggerDataByTriggerType(triggerType, data) {

@@ -24,2 +29,8 @@ const type = types_1.triggerTypeToCommandContractTypeMap[triggerType];

exports.decodeTriggerDataByTriggerType = decodeTriggerDataByTriggerType;
function decodeOffchainTriggerDataByTriggerType(triggerType, data) {
const type = types_1.triggerTypeToCommandContractTypeMap[triggerType];
const paramTypes = (0, mapping_1.getOffchainDataDefinitionForCommandType)(type);
return ethers_1.utils.defaultAbiCoder.decode(paramTypes, data);
}
exports.decodeOffchainTriggerDataByTriggerType = decodeOffchainTriggerDataByTriggerType;
function decodeTriggerDataAsJson(commandAddress, network, data) {

@@ -51,2 +62,15 @@ const arr = decodeTriggerData(commandAddress, network, data);

exports.decodeTriggerDataByTriggerTypeAsJson = decodeTriggerDataByTriggerTypeAsJson;
function decodeOffchainTriggerDataByTriggerTypeAsJson(triggerType, data) {
const type = types_1.triggerTypeToCommandContractTypeMap[triggerType];
const arr = decodeOffchainTriggerDataByType(type, data);
const offchainDataType = mapping_1.commandOffchainDataTypeJsonMapping[type];
if (!offchainDataType) {
throw new Error(`No offchain data mapping for type ${type}`);
}
return arr.reduce((acc, curr, idx) => {
acc[offchainDataType[idx]] = curr.toString();
return acc;
}, {});
}
exports.decodeOffchainTriggerDataByTriggerTypeAsJson = decodeOffchainTriggerDataByTriggerTypeAsJson;
function encodeTriggerData(commandAddress, network, values) {

@@ -68,2 +92,13 @@ const paramTypes = (0, mapping_1.getDefinitionForCommandAddress)(commandAddress, network);

exports.encodeTriggerDataByTriggerType = encodeTriggerDataByTriggerType;
function encodeOffchainTriggerDataByType(type, values) {
const paramTypes = (0, mapping_1.getOffchainDataDefinitionForCommandType)(type);
return ethers_1.utils.defaultAbiCoder.encode(paramTypes, values);
}
exports.encodeOffchainTriggerDataByType = encodeOffchainTriggerDataByType;
function encodeTriggerOffchainDataByTriggerType(triggerType, values) {
const commandType = types_1.triggerTypeToCommandContractTypeMap[triggerType];
const paramTypes = (0, mapping_1.getOffchainDataDefinitionForCommandType)(commandType);
return ethers_1.utils.defaultAbiCoder.encode(paramTypes, values);
}
exports.encodeTriggerOffchainDataByTriggerType = encodeTriggerOffchainDataByTriggerType;
//# sourceMappingURL=abi-coding.js.map

35

lib/src/mapping.d.ts
import { CommandContractInfo, CommandContractType, ParamDefinition, TriggerType } from './types';
export declare const commandTypeJsonMapping: Record<CommandContractType, string[]>;
export declare const commandOffchainDataTypeJsonMapping: Partial<Record<CommandContractType, string[]>>;
export declare const commandAddressMapping: Record<number, Record<string, CommandContractInfo>>;
export declare const defaultCommandTypeMapping: {
readonly CloseCommand: readonly ["uint256", "uint16", "uint256"];
readonly SimpleAAVESell: readonly ["address", "uint16", "uint256", "uint256", "address"];
readonly AutoTakeProfitCommand: readonly ["uint256", "uint16", "uint256", "uint32"];
readonly BasicBuyCommand: readonly ["uint256", "uint16", "uint256", "uint256", "uint256", "bool", "uint64", "uint32"];
readonly BasicSellCommand: readonly ["uint256", "uint16", "uint256", "uint256", "uint256", "bool", "uint64", "uint32"];
readonly AaveStopLossCommand: readonly ["address", "uint16", "address", "address", "uint256"];
readonly AaveStopLossCommandV2: readonly ["address", "uint16", "uint256", "address", "address", "uint256"];
readonly SparkStopLossCommandV2: readonly ["address", "uint16", "uint256", "address", "address", "uint256"];
readonly MakerStopLossCommandV2: readonly ["uint256", "uint16", "uint256", "uint256"];
readonly MakerAutoTakeProfitCommandV2: readonly ["uint256", "uint16", "uint256", "uint32"];
readonly MakerBasicBuyCommandV2: readonly ["uint256", "uint16", "uint256", "uint256", "uint256", "uint256", "uint64", "uint32"];
readonly MakerBasicSellCommandV2: readonly ["uint256", "uint16", "uint256", "uint256", "uint256", "uint256", "uint64", "uint32"];
readonly DmaAaveV3BasicBuyCommandV2: readonly ["address", "uint16", "uint256", "address", "address", "bytes32", "uint256", "uint256", "uint256", "uint64", "uint32"];
readonly DmaAaveV3BasicSellCommandV2: readonly ["address", "uint16", "uint256", "address", "address", "bytes32", "uint256", "uint256", "uint256", "uint64", "uint32"];
readonly DmaAaveV3StopLossCommandV2: readonly ["address", "uint16", "uint256", "address", "address", "bytes32", "uint256"];
readonly DmaSparkStopLossCommandV2: readonly ["address", "uint16", "uint256", "address", "address", "bytes32", "uint256"];
};
export declare const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinition>;
export declare const defaultCommandOffchainDataTypeMapping: Partial<Record<CommandContractType, ParamDefinition>>;
export declare function getCommandAddresses(network: number): Record<CommandContractType, string[]>;

@@ -31,2 +16,16 @@ /**

/**
* Retrieves the offchain data definition for a given command type.
* @param type - The command type.
* @returns The offchain data definition for the command type.
* @throws Error if the command type is unknown.
*/
export declare function getOffchainDataDefinitionForCommandType(type: Partial<CommandContractType>): ParamDefinition;
/**
* Retrieves the offchain data definition for a given trigger type.
* @param triggerType - The trigger type for which to retrieve the offchain data definition.
* @returns The offchain data definition for the specified trigger type.
* @throws An error if the command type is unknown or not supported.
*/
export declare function getOffchainDataDefinitionForTriggerType(triggerType: Partial<TriggerType>): ParamDefinition;
/**
* Retrieves the parameter definition for a given trigger type.

@@ -33,0 +32,0 @@ * @param triggerType The type of trigger.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCommandContractInfo = exports.getDefinitionForCommandAddress = exports.getDefinitionForTriggerType = exports.getDefinitionForCommandType = exports.getCommandAddresses = exports.defaultCommandTypeMapping = exports.commandAddressMapping = exports.commandTypeJsonMapping = void 0;
exports.getCommandContractInfo = exports.getDefinitionForCommandAddress = exports.getDefinitionForTriggerType = exports.getOffchainDataDefinitionForTriggerType = exports.getOffchainDataDefinitionForCommandType = exports.getDefinitionForCommandType = exports.getCommandAddresses = exports.defaultCommandOffchainDataTypeMapping = exports.defaultCommandTypeMapping = exports.commandAddressMapping = exports.commandOffchainDataTypeJsonMapping = exports.commandTypeJsonMapping = void 0;
const types_1 = require("./types");

@@ -140,3 +140,24 @@ exports.commandTypeJsonMapping = {

],
[types_1.CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'collateralOracle',
'collateralAddedRoundId',
'debtOracle',
'debtAddedRoundId',
'trailingDistance',
'closeToCollateral'
],
};
exports.commandOffchainDataTypeJsonMapping = {
[types_1.CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'collateralMaxPriceRoundId',
'debtClosestPriceRoundId',
'debtNextPriceRoundId',
],
};
exports.commandAddressMapping = Object.fromEntries(Object.entries({

@@ -369,3 +390,24 @@ [types_1.EthereumNetwork.GOERLI]: {

],
[types_1.CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'address',
'uint16',
'uint256',
'address',
'address',
'bytes32',
'address',
'uint80',
'address',
'uint80',
'uint256',
'bool', // closeToCollateral
],
};
exports.defaultCommandOffchainDataTypeMapping = {
[types_1.CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'uint80',
'uint80',
'uint80', // debtNextPriceRoundId
],
};
function getCommandAddresses(network) {

@@ -393,2 +435,31 @@ if (!(network in exports.commandAddressMapping)) {

/**
* Retrieves the offchain data definition for a given command type.
* @param type - The command type.
* @returns The offchain data definition for the command type.
* @throws Error if the command type is unknown.
*/
function getOffchainDataDefinitionForCommandType(type) {
const offchainDataType = exports.defaultCommandOffchainDataTypeMapping[type];
if (!offchainDataType) {
throw new Error(`Unknown command type ${type}. Supported types: ${Object.keys(exports.defaultCommandOffchainDataTypeMapping).join(', ')}.`);
}
return offchainDataType;
}
exports.getOffchainDataDefinitionForCommandType = getOffchainDataDefinitionForCommandType;
/**
* Retrieves the offchain data definition for a given trigger type.
* @param triggerType - The trigger type for which to retrieve the offchain data definition.
* @returns The offchain data definition for the specified trigger type.
* @throws An error if the command type is unknown or not supported.
*/
function getOffchainDataDefinitionForTriggerType(triggerType) {
const type = types_1.triggerTypeToCommandContractTypeMap[triggerType];
const offchainDataType = exports.defaultCommandOffchainDataTypeMapping[type];
if (!offchainDataType) {
throw new Error(`Unknown command type ${type}. Supported types: ${Object.keys(exports.defaultCommandOffchainDataTypeMapping).join(', ')}.`);
}
return offchainDataType;
}
exports.getOffchainDataDefinitionForTriggerType = getOffchainDataDefinitionForTriggerType;
/**
* Retrieves the parameter definition for a given trigger type.

@@ -395,0 +466,0 @@ * @param triggerType The type of trigger.

@@ -25,3 +25,4 @@ import { ethers } from 'ethers';

DmaSparkStopLossCommandV2 = "DmaSparkStopLossCommandV2",
DmaAaveStopLossCommandV2 = "DmaAaveV3StopLossCommandV2"
DmaAaveStopLossCommandV2 = "DmaAaveV3StopLossCommandV2",
DmaAaveTrailingStopLossCommandV2 = "DmaAaveV3TrailingStopLossCommandV2"
}

@@ -53,3 +54,4 @@ export declare enum TriggerType {

DmaSparkStopLossToCollateralV2 = 125,
DmaSparkStopLossToDebtV2 = 126
DmaSparkStopLossToDebtV2 = 126,
DmaAaveTrailingStopLossV2 = 10001
}

@@ -56,0 +58,0 @@ export declare const triggerTypeToCommandContractTypeMap: Record<TriggerType, CommandContractType>;

@@ -30,2 +30,3 @@ "use strict";

CommandContractType["DmaAaveStopLossCommandV2"] = "DmaAaveV3StopLossCommandV2";
CommandContractType["DmaAaveTrailingStopLossCommandV2"] = "DmaAaveV3TrailingStopLossCommandV2";
})(CommandContractType = exports.CommandContractType || (exports.CommandContractType = {}));

@@ -59,2 +60,3 @@ var TriggerType;

TriggerType[TriggerType["DmaSparkStopLossToDebtV2"] = 126] = "DmaSparkStopLossToDebtV2";
TriggerType[TriggerType["DmaAaveTrailingStopLossV2"] = 10001] = "DmaAaveTrailingStopLossV2";
})(TriggerType = exports.TriggerType || (exports.TriggerType = {}));

@@ -87,2 +89,3 @@ exports.triggerTypeToCommandContractTypeMap = {

[TriggerType.DmaSparkStopLossToDebtV2]: CommandContractType.DmaSparkStopLossCommandV2,
[TriggerType.DmaAaveTrailingStopLossV2]: CommandContractType.DmaAaveTrailingStopLossCommandV2,
};

@@ -89,0 +92,0 @@ var TriggerGroupType;

{
"name": "@oasisdex/automation",
"packageManager": "yarn@1.22.21",
"version": "1.6.0-alpha.9",
"version": "1.6.0-alpha.10",
"description": "The set of utilities for Oasis automation",

@@ -6,0 +6,0 @@ "homepage": "https://github.com/OasisDEX/common#readme",

import { utils } from 'ethers';
import {
commandAddressMapping,
commandOffchainDataTypeJsonMapping,
commandTypeJsonMapping,
getDefinitionForCommandAddress,
getDefinitionForCommandType,
getOffchainDataDefinitionForCommandType,
} from './mapping';

@@ -24,2 +26,7 @@ import { CommandContractType, TriggerType, triggerTypeToCommandContractTypeMap } from './types';

export function decodeOffchainTriggerDataByType(type: CommandContractType, data: string): utils.Result {
const paramTypes = getOffchainDataDefinitionForCommandType(type);
return utils.defaultAbiCoder.decode(paramTypes, data);
}
export function decodeTriggerDataByTriggerType(

@@ -34,2 +41,11 @@ triggerType: TriggerType,

export function decodeOffchainTriggerDataByTriggerType(
triggerType: TriggerType,
data: string,
): utils.Result {
const type = triggerTypeToCommandContractTypeMap[triggerType];
const paramTypes = getOffchainDataDefinitionForCommandType(type);
return utils.defaultAbiCoder.decode(paramTypes, data);
}
export function decodeTriggerDataAsJson(

@@ -72,2 +88,19 @@ commandAddress: string,

}
export function decodeOffchainTriggerDataByTriggerTypeAsJson(
triggerType: TriggerType,
data: string,
): utils.Result {
const type = triggerTypeToCommandContractTypeMap[triggerType];
const arr: any[] = decodeOffchainTriggerDataByType(type, data) as any[];
const offchainDataType = commandOffchainDataTypeJsonMapping[type]
if (!offchainDataType) {
throw new Error(`No offchain data mapping for type ${type}`);
}
return arr.reduce((acc, curr, idx) => {
acc[offchainDataType[idx]] = curr.toString();
return acc;
}, {});
}
export function encodeTriggerData(

@@ -95,1 +128,15 @@ commandAddress: string,

}
export function encodeOffchainTriggerDataByType(type: CommandContractType, values: readonly any[]): string {
const paramTypes = getOffchainDataDefinitionForCommandType(type);
return utils.defaultAbiCoder.encode(paramTypes, values);
}
export function encodeTriggerOffchainDataByTriggerType(
triggerType: TriggerType,
values: readonly any[],
): string {
const commandType = triggerTypeToCommandContractTypeMap[triggerType];
const paramTypes = getOffchainDataDefinitionForCommandType(commandType);
return utils.defaultAbiCoder.encode(paramTypes, values);
}

@@ -145,4 +145,24 @@ import {

],
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'collateralOracle',
'collateralAddedRoundId',
'debtOracle',
'debtAddedRoundId',
'trailingDistance',
'closeToCollateral'
],
};
export const commandOffchainDataTypeJsonMapping: Partial<Record<CommandContractType, string[]>> = {
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'collateralMaxPriceRoundId',
'debtClosestPriceRoundId',
'debtNextPriceRoundId',
],
};
export const commandAddressMapping: Record<

@@ -270,3 +290,3 @@ number,

export const defaultCommandTypeMapping = {
export const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinition> = {
[CommandContractType.CloseCommand]: ['uint256', 'uint16', 'uint256'],

@@ -384,4 +404,26 @@ [CommandContractType.SimpleAAVESellCommand]: [

],
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'address', // collateralOracle
'uint80', // collateralAddedRoundId
'address', // debtOracle
'uint80', // debtAddedRoundId
'uint256', // trailingDistance
'bool', // closeToCollateral
],
} as const;
export const defaultCommandOffchainDataTypeMapping: Partial<Record<CommandContractType, ParamDefinition>> = {
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'uint80', // collateralMaxPriceRoundId
'uint80', // debtClosestPriceRoundId
'uint80', // debtNextPriceRoundId
],
} as const;
export function getCommandAddresses(network: number): Record<CommandContractType, string[]> {

@@ -422,2 +464,41 @@ if (!(network in commandAddressMapping)) {

/**
* Retrieves the offchain data definition for a given command type.
* @param type - The command type.
* @returns The offchain data definition for the command type.
* @throws Error if the command type is unknown.
*/
export function getOffchainDataDefinitionForCommandType(type: Partial<CommandContractType>): ParamDefinition {
const offchainDataType = defaultCommandOffchainDataTypeMapping[type]
if (!offchainDataType) {
throw new Error(
`Unknown command type ${type}. Supported types: ${Object.keys(defaultCommandOffchainDataTypeMapping).join(
', ',
)}.`,
);
}
return offchainDataType;
}
/**
* Retrieves the offchain data definition for a given trigger type.
* @param triggerType - The trigger type for which to retrieve the offchain data definition.
* @returns The offchain data definition for the specified trigger type.
* @throws An error if the command type is unknown or not supported.
*/
export function getOffchainDataDefinitionForTriggerType(triggerType: Partial<TriggerType>): ParamDefinition {
const type = triggerTypeToCommandContractTypeMap[triggerType];
const offchainDataType = defaultCommandOffchainDataTypeMapping[type]
if (!offchainDataType) {
throw new Error(
`Unknown command type ${type}. Supported types: ${Object.keys(defaultCommandOffchainDataTypeMapping).join(
', ',
)}.`,
);
}
return offchainDataType;
}
/**
* Retrieves the parameter definition for a given trigger type.

@@ -424,0 +505,0 @@ * @param triggerType The type of trigger.

@@ -28,2 +28,3 @@ import { ethers } from 'ethers';

DmaAaveStopLossCommandV2 = 'DmaAaveV3StopLossCommandV2',
DmaAaveTrailingStopLossCommandV2 = 'DmaAaveV3TrailingStopLossCommandV2',
}

@@ -57,2 +58,3 @@

DmaSparkStopLossToDebtV2 = 126,
DmaAaveTrailingStopLossV2 = 10001,
}

@@ -86,2 +88,3 @@

[TriggerType.DmaSparkStopLossToDebtV2]: CommandContractType.DmaSparkStopLossCommandV2,
[TriggerType.DmaAaveTrailingStopLossV2]: CommandContractType.DmaAaveTrailingStopLossCommandV2,
};

@@ -88,0 +91,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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