Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@oasisdex/automation

Package Overview
Dependencies
47
Maintainers
9
Versions
108
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.0 to 1.6.1

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

2

lib/src/index.d.ts
export { decodeTriggerData, decodeTriggerDataByType, decodeTriggerDataByTriggerType, encodeTriggerData, encodeTriggerDataByType, decodeTriggerDataAsJson, encodeTriggerDataByTriggerType, decodeTriggerDataByTypeAsJson, decodeTriggerDataByTriggerTypeAsJson, } from './abi-coding';
export { getCommandAddresses } from './mapping';
export { getCommandAddresses, commandTypeJsonMapping } from './mapping';
export { CommandContractType, TriggerType, TriggerGroupType, triggerTypeToCommandContractTypeMap, } from './types';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.triggerTypeToCommandContractTypeMap = exports.TriggerGroupType = exports.TriggerType = exports.CommandContractType = exports.getCommandAddresses = exports.decodeTriggerDataByTriggerTypeAsJson = exports.decodeTriggerDataByTypeAsJson = exports.encodeTriggerDataByTriggerType = exports.decodeTriggerDataAsJson = exports.encodeTriggerDataByType = exports.encodeTriggerData = exports.decodeTriggerDataByTriggerType = exports.decodeTriggerDataByType = exports.decodeTriggerData = void 0;
exports.triggerTypeToCommandContractTypeMap = exports.TriggerGroupType = exports.TriggerType = exports.CommandContractType = exports.commandTypeJsonMapping = exports.getCommandAddresses = exports.decodeTriggerDataByTriggerTypeAsJson = exports.decodeTriggerDataByTypeAsJson = exports.encodeTriggerDataByTriggerType = exports.decodeTriggerDataAsJson = exports.encodeTriggerDataByType = exports.encodeTriggerData = exports.decodeTriggerDataByTriggerType = exports.decodeTriggerDataByType = exports.decodeTriggerData = void 0;
var abi_coding_1 = require("./abi-coding");

@@ -16,2 +16,3 @@ Object.defineProperty(exports, "decodeTriggerData", { enumerable: true, get: function () { return abi_coding_1.decodeTriggerData; } });

Object.defineProperty(exports, "getCommandAddresses", { enumerable: true, get: function () { return mapping_1.getCommandAddresses; } });
Object.defineProperty(exports, "commandTypeJsonMapping", { enumerable: true, get: function () { return mapping_1.commandTypeJsonMapping; } });
var types_1 = require("./types");

@@ -18,0 +19,0 @@ Object.defineProperty(exports, "CommandContractType", { enumerable: true, get: function () { return types_1.CommandContractType; } });

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 AaveBasicBuyCommandV2: readonly ["address", "uint16", "uint256", "address", "address", "bytes32", "uint256", "uint256", "uint256", "uint64", "uint32"];
readonly AaveBasicSellCommandV2: readonly ["address", "uint16", "uint256", "address", "address", "bytes32", "uint256", "uint256", "uint256", "uint64", "uint32"];
};
export declare const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinition>;
export declare const defaultCommandOffchainDataTypeMapping: Partial<Record<CommandContractType, ParamDefinition>>;
export declare function getCommandAddresses(network: number): Record<CommandContractType, string[]>;

@@ -29,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.

@@ -31,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");

@@ -96,3 +96,3 @@ exports.commandTypeJsonMapping = {

],
[types_1.CommandContractType.AaveBasicSellCommandV2]: [
[types_1.CommandContractType.DmaAaveBasicSellCommandV2]: [
'positionAddress',

@@ -103,4 +103,4 @@ 'triggerType',

'collateralToken',
'opHash',
'execLtv',
'operationName',
'executionLtv',
'targetLtv',

@@ -111,3 +111,3 @@ 'minSellPrice',

],
[types_1.CommandContractType.AaveBasicBuyCommandV2]: [
[types_1.CommandContractType.DmaAaveBasicBuyCommandV2]: [
'positionAddress',

@@ -118,4 +118,4 @@ 'triggerType',

'collateralToken',
'opHash',
'execLtv',
'operationName',
'executionLtv',
'targetLtv',

@@ -126,3 +126,87 @@ 'maxBuyPrice',

],
[types_1.CommandContractType.DmaAaveStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
],
[types_1.CommandContractType.DmaSparkStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
],
[types_1.CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'collateralOracle',
'collateralAddedRoundId',
'debtOracle',
'debtAddedRoundId',
'trailingDistance',
'closeToCollateral',
],
[types_1.CommandContractType.DmaSparkTrailingStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'collateralOracle',
'collateralAddedRoundId',
'debtOracle',
'debtAddedRoundId',
'trailingDistance',
'closeToCollateral',
],
[types_1.CommandContractType.DmaSparkBasicSellCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
'targetLtv',
'minSellPrice',
'deviation',
'maxBaseFeeInGwei',
],
[types_1.CommandContractType.DmaSparkBasicBuyCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
'targetLtv',
'maxBuyPrice',
'deviation',
'maxBaseFeeInGwei',
],
};
exports.commandOffchainDataTypeJsonMapping = {
[types_1.CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'collateralMaxPriceRoundId',
'debtClosestPriceRoundId',
'debtNextPriceRoundId',
],
[types_1.CommandContractType.DmaSparkTrailingStopLossCommandV2]: [
'collateralMaxPriceRoundId',
'debtClosestPriceRoundId',
'debtNextPriceRoundId',
],
};
exports.commandAddressMapping = Object.fromEntries(Object.entries({

@@ -196,16 +280,47 @@ [types_1.EthereumNetwork.GOERLI]: {

'0x72241841022bc824B0b66e3D27D8937D36dA4FDF': {
type: types_1.CommandContractType.AaveBasicBuyCommandV2,
type: types_1.CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0x31d767f6556CE3fC55d6245C9aEF3575aa64BABf': {
type: types_1.CommandContractType.AaveBasicSellCommandV2,
type: types_1.CommandContractType.DmaAaveBasicSellCommandV2,
},
'0xf7c7168b965215420E15cDE6F7e54570Ec171D67': {
type: types_1.CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0x4A13b02ef24B2906a33e48e8F0AaF343C5316327': {
type: types_1.CommandContractType.DmaAaveBasicSellCommandV2,
},
'0xea0c35bd1c2fae4d540ce30d9738bc55147f2a9c': {
type: types_1.CommandContractType.DmaAaveStopLossCommandV2,
},
},
[types_1.EthereumNetwork.BASE]: {
'0xb7CB13e4cD2D64e739b5746563978Ab7ee36B064': {
type: types_1.CommandContractType.AaveBasicBuyCommandV2,
type: types_1.CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0xEd7ac8827A0DCAAc039F122c67664ad9EC0B55Fd': {
type: types_1.CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0xbf566C1b260F0464f75470C146288283f11219a9': {
type: types_1.CommandContractType.AaveBasicSellCommandV2,
type: types_1.CommandContractType.DmaAaveBasicSellCommandV2,
},
'0xB3105b9b5B80107Fa6Dae970fd59d5a67A8ef984': {
type: types_1.CommandContractType.DmaAaveBasicSellCommandV2,
},
},
[types_1.EthereumNetwork.OPTIMISM]: {
'0xbA06eb5D30Ec7D6B47e5FC30457D7b2Be5AB784a': {
type: types_1.CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0x61C45e7bF23eF18d546449186DEFd9A591937D62': {
type: types_1.CommandContractType.DmaAaveBasicSellCommandV2,
},
},
[types_1.EthereumNetwork.ARBITRUM]: {
'0xda06cc7e416c97324bbce79896f807aaff6cf5d3': {
type: types_1.CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0x00d01ae61e554fc17530fbafcd282e9695e34693': {
type: types_1.CommandContractType.DmaAaveBasicSellCommandV2,
},
},
}).map(([network, mapping]) => [

@@ -284,3 +399,3 @@ network,

],
[types_1.CommandContractType.AaveBasicBuyCommandV2]: [
[types_1.CommandContractType.DmaAaveBasicBuyCommandV2]: [
'address',

@@ -298,3 +413,3 @@ 'uint16',

],
[types_1.CommandContractType.AaveBasicSellCommandV2]: [
[types_1.CommandContractType.DmaAaveBasicSellCommandV2]: [
'address',

@@ -312,3 +427,87 @@ 'uint16',

],
[types_1.CommandContractType.DmaAaveStopLossCommandV2]: [
'address',
'uint16',
'uint256',
'address',
'address',
'bytes32',
'uint256', // executionLTV
],
[types_1.CommandContractType.DmaSparkStopLossCommandV2]: [
'address',
'uint16',
'uint256',
'address',
'address',
'bytes32',
'uint256', // executionLTV
],
[types_1.CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'address',
'uint16',
'uint256',
'address',
'address',
'bytes32',
'address',
'uint80',
'address',
'uint80',
'uint256',
'bool', // closeToCollateral
],
[types_1.CommandContractType.DmaSparkTrailingStopLossCommandV2]: [
'address',
'uint16',
'uint256',
'address',
'address',
'bytes32',
'address',
'uint80',
'address',
'uint80',
'uint256',
'bool', // closeToCollateral
],
[types_1.CommandContractType.DmaSparkBasicBuyCommandV2]: [
'address',
'uint16',
'uint256',
'address',
'address',
'bytes32',
'uint256',
'uint256',
'uint256',
'uint64',
'uint32', // maxBaseFeeInGwei
],
[types_1.CommandContractType.DmaSparkBasicSellCommandV2]: [
'address',
'uint16',
'uint256',
'address',
'address',
'bytes32',
'uint256',
'uint256',
'uint256',
'uint64',
'uint32', // maxBaseFeeInGwei
],
};
exports.defaultCommandOffchainDataTypeMapping = {
[types_1.CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'uint80',
'uint80',
'uint80', // debtNextPriceRoundId
],
[types_1.CommandContractType.DmaSparkTrailingStopLossCommandV2]: [
'uint80',
'uint80',
'uint80', // debtNextPriceRoundId
],
};
function getCommandAddresses(network) {

@@ -336,2 +535,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.

@@ -338,0 +566,0 @@ * @param triggerType The type of trigger.

@@ -22,4 +22,10 @@ import { ethers } from 'ethers';

SparkStopLossCommandV2 = "SparkStopLossCommandV2",
AaveBasicBuyCommandV2 = "AaveBasicBuyCommandV2",
AaveBasicSellCommandV2 = "AaveBasicSellCommandV2"
DmaAaveBasicBuyCommandV2 = "DmaAaveV3BasicBuyCommandV2",
DmaAaveBasicSellCommandV2 = "DmaAaveV3BasicSellCommandV2",
DmaSparkStopLossCommandV2 = "DmaSparkStopLossCommandV2",
DmaAaveStopLossCommandV2 = "DmaAaveV3StopLossCommandV2",
DmaAaveTrailingStopLossCommandV2 = "DmaAaveV3TrailingStopLossCommandV2",
DmaSparkTrailingStopLossCommandV2 = "DmaSparkTrailingStopLossCommandV2",
DmaSparkBasicBuyCommandV2 = "DmaSparkBasicBuyCommandV2",
DmaSparkBasicSellCommandV2 = "DmaSparkBasicSellCommandV2"
}

@@ -46,4 +52,12 @@ export declare enum TriggerType {

SparkStopLossToDebtV2 = 118,
AaveBasicBuyV2 = 119,
AaveBasicSellV2 = 120
DmaAaveBasicBuyV2 = 121,
DmaAaveBasicSellV2 = 122,
DmaAaveStopLossToCollateralV2 = 127,
DmaAaveStopLossToDebtV2 = 128,
DmaSparkStopLossToCollateralV2 = 129,
DmaSparkStopLossToDebtV2 = 130,
DmaSparkBasicBuyV2 = 131,
DmaSparkBasicSellV2 = 132,
DmaAaveTrailingStopLossV2 = 10006,
DmaSparkTrailingStopLossV2 = 10007
}

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

@@ -26,4 +26,10 @@ "use strict";

CommandContractType["SparkStopLossCommandV2"] = "SparkStopLossCommandV2";
CommandContractType["AaveBasicBuyCommandV2"] = "AaveBasicBuyCommandV2";
CommandContractType["AaveBasicSellCommandV2"] = "AaveBasicSellCommandV2";
CommandContractType["DmaAaveBasicBuyCommandV2"] = "DmaAaveV3BasicBuyCommandV2";
CommandContractType["DmaAaveBasicSellCommandV2"] = "DmaAaveV3BasicSellCommandV2";
CommandContractType["DmaSparkStopLossCommandV2"] = "DmaSparkStopLossCommandV2";
CommandContractType["DmaAaveStopLossCommandV2"] = "DmaAaveV3StopLossCommandV2";
CommandContractType["DmaAaveTrailingStopLossCommandV2"] = "DmaAaveV3TrailingStopLossCommandV2";
CommandContractType["DmaSparkTrailingStopLossCommandV2"] = "DmaSparkTrailingStopLossCommandV2";
CommandContractType["DmaSparkBasicBuyCommandV2"] = "DmaSparkBasicBuyCommandV2";
CommandContractType["DmaSparkBasicSellCommandV2"] = "DmaSparkBasicSellCommandV2";
})(CommandContractType = exports.CommandContractType || (exports.CommandContractType = {}));

@@ -51,4 +57,12 @@ var TriggerType;

TriggerType[TriggerType["SparkStopLossToDebtV2"] = 118] = "SparkStopLossToDebtV2";
TriggerType[TriggerType["AaveBasicBuyV2"] = 119] = "AaveBasicBuyV2";
TriggerType[TriggerType["AaveBasicSellV2"] = 120] = "AaveBasicSellV2";
TriggerType[TriggerType["DmaAaveBasicBuyV2"] = 121] = "DmaAaveBasicBuyV2";
TriggerType[TriggerType["DmaAaveBasicSellV2"] = 122] = "DmaAaveBasicSellV2";
TriggerType[TriggerType["DmaAaveStopLossToCollateralV2"] = 127] = "DmaAaveStopLossToCollateralV2";
TriggerType[TriggerType["DmaAaveStopLossToDebtV2"] = 128] = "DmaAaveStopLossToDebtV2";
TriggerType[TriggerType["DmaSparkStopLossToCollateralV2"] = 129] = "DmaSparkStopLossToCollateralV2";
TriggerType[TriggerType["DmaSparkStopLossToDebtV2"] = 130] = "DmaSparkStopLossToDebtV2";
TriggerType[TriggerType["DmaSparkBasicBuyV2"] = 131] = "DmaSparkBasicBuyV2";
TriggerType[TriggerType["DmaSparkBasicSellV2"] = 132] = "DmaSparkBasicSellV2";
TriggerType[TriggerType["DmaAaveTrailingStopLossV2"] = 10006] = "DmaAaveTrailingStopLossV2";
TriggerType[TriggerType["DmaSparkTrailingStopLossV2"] = 10007] = "DmaSparkTrailingStopLossV2";
})(TriggerType = exports.TriggerType || (exports.TriggerType = {}));

@@ -75,4 +89,12 @@ exports.triggerTypeToCommandContractTypeMap = {

[TriggerType.SparkStopLossToDebtV2]: CommandContractType.SparkStopLossCommandV2,
[TriggerType.AaveBasicBuyV2]: CommandContractType.AaveBasicBuyCommandV2,
[TriggerType.AaveBasicSellV2]: CommandContractType.AaveBasicSellCommandV2,
[TriggerType.DmaAaveBasicBuyV2]: CommandContractType.DmaAaveBasicBuyCommandV2,
[TriggerType.DmaAaveBasicSellV2]: CommandContractType.DmaAaveBasicSellCommandV2,
[TriggerType.DmaAaveStopLossToCollateralV2]: CommandContractType.DmaAaveStopLossCommandV2,
[TriggerType.DmaAaveStopLossToDebtV2]: CommandContractType.DmaAaveStopLossCommandV2,
[TriggerType.DmaSparkStopLossToCollateralV2]: CommandContractType.DmaSparkStopLossCommandV2,
[TriggerType.DmaSparkStopLossToDebtV2]: CommandContractType.DmaSparkStopLossCommandV2,
[TriggerType.DmaAaveTrailingStopLossV2]: CommandContractType.DmaAaveTrailingStopLossCommandV2,
[TriggerType.DmaSparkTrailingStopLossV2]: CommandContractType.DmaSparkTrailingStopLossCommandV2,
[TriggerType.DmaSparkBasicBuyV2]: CommandContractType.DmaSparkBasicBuyCommandV2,
[TriggerType.DmaSparkBasicSellV2]: CommandContractType.DmaSparkBasicSellCommandV2,
};

@@ -79,0 +101,0 @@ var TriggerGroupType;

{
"name": "@oasisdex/automation",
"packageManager": "yarn@1.22.21",
"version": "1.6.0",
"version": "1.6.1",
"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,10 @@ 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 +44,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 +91,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 +131,18 @@ 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);
}

@@ -12,3 +12,3 @@ export {

} from './abi-coding';
export { getCommandAddresses } from './mapping';
export { getCommandAddresses, commandTypeJsonMapping } from './mapping';

@@ -15,0 +15,0 @@ export {

@@ -101,3 +101,3 @@ import {

],
[CommandContractType.AaveBasicSellCommandV2]: [
[CommandContractType.DmaAaveBasicSellCommandV2]: [
'positionAddress',

@@ -108,4 +108,4 @@ 'triggerType',

'collateralToken',
'opHash',
'execLtv',
'operationName',
'executionLtv',
'targetLtv',

@@ -116,3 +116,3 @@ 'minSellPrice',

],
[CommandContractType.AaveBasicBuyCommandV2]: [
[CommandContractType.DmaAaveBasicBuyCommandV2]: [
'positionAddress',

@@ -123,4 +123,4 @@ 'triggerType',

'collateralToken',
'opHash',
'execLtv',
'operationName',
'executionLtv',
'targetLtv',

@@ -131,4 +131,87 @@ 'maxBuyPrice',

],
[CommandContractType.DmaAaveStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
],
[CommandContractType.DmaSparkStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
],
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'collateralOracle',
'collateralAddedRoundId',
'debtOracle',
'debtAddedRoundId',
'trailingDistance',
'closeToCollateral',
],
[CommandContractType.DmaSparkTrailingStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'collateralOracle',
'collateralAddedRoundId',
'debtOracle',
'debtAddedRoundId',
'trailingDistance',
'closeToCollateral',
],
[CommandContractType.DmaSparkBasicSellCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
'targetLtv',
'minSellPrice',
'deviation',
'maxBaseFeeInGwei',
],
[CommandContractType.DmaSparkBasicBuyCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
'targetLtv',
'maxBuyPrice',
'deviation',
'maxBaseFeeInGwei',
],
};
export const commandOffchainDataTypeJsonMapping: Partial<Record<CommandContractType, string[]>> = {
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'collateralMaxPriceRoundId',
'debtClosestPriceRoundId',
'debtNextPriceRoundId',
],
[CommandContractType.DmaSparkTrailingStopLossCommandV2]: [
'collateralMaxPriceRoundId',
'debtClosestPriceRoundId',
'debtNextPriceRoundId',
],
};
export const commandAddressMapping: Record<

@@ -206,17 +289,47 @@ number,

'0x72241841022bc824B0b66e3D27D8937D36dA4FDF': {
type: CommandContractType.AaveBasicBuyCommandV2,
type: CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0x31d767f6556CE3fC55d6245C9aEF3575aa64BABf': {
type: CommandContractType.AaveBasicSellCommandV2,
type: CommandContractType.DmaAaveBasicSellCommandV2,
},
'0xf7c7168b965215420E15cDE6F7e54570Ec171D67': {
type: CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0x4A13b02ef24B2906a33e48e8F0AaF343C5316327': {
type: CommandContractType.DmaAaveBasicSellCommandV2,
},
'0xea0c35bd1c2fae4d540ce30d9738bc55147f2a9c': {
type: CommandContractType.DmaAaveStopLossCommandV2,
},
},
[EthereumNetwork.BASE]: {
'0xb7CB13e4cD2D64e739b5746563978Ab7ee36B064': {
type: CommandContractType.AaveBasicBuyCommandV2,
type: CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0xEd7ac8827A0DCAAc039F122c67664ad9EC0B55Fd': {
type: CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0xbf566C1b260F0464f75470C146288283f11219a9': {
type: CommandContractType.AaveBasicSellCommandV2,
type: CommandContractType.DmaAaveBasicSellCommandV2,
},
'0xB3105b9b5B80107Fa6Dae970fd59d5a67A8ef984': {
type: CommandContractType.DmaAaveBasicSellCommandV2,
},
},
[EthereumNetwork.OPTIMISM]: {
'0xbA06eb5D30Ec7D6B47e5FC30457D7b2Be5AB784a': {
type: CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0x61C45e7bF23eF18d546449186DEFd9A591937D62': {
type: CommandContractType.DmaAaveBasicSellCommandV2,
},
},
[EthereumNetwork.ARBITRUM]: {
'0xda06cc7e416c97324bbce79896f807aaff6cf5d3': {
type: CommandContractType.DmaAaveBasicBuyCommandV2,
},
'0x00d01ae61e554fc17530fbafcd282e9695e34693': {
type: CommandContractType.DmaAaveBasicSellCommandV2,
},
},
}).map(([network, mapping]) => [

@@ -230,3 +343,3 @@ network,

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

@@ -300,3 +413,3 @@ [CommandContractType.SimpleAAVESellCommand]: [

],
[CommandContractType.AaveBasicBuyCommandV2]: [
[CommandContractType.DmaAaveBasicBuyCommandV2]: [
'address', //positionAddress

@@ -307,3 +420,3 @@ 'uint16', // triggerType

'address', // collateralToken
'bytes32', // opHash
'bytes32', // operationName
'uint256', // execCollRatio

@@ -315,3 +428,3 @@ 'uint256', // targetCollRatio

],
[CommandContractType.AaveBasicSellCommandV2]: [
[CommandContractType.DmaAaveBasicSellCommandV2]: [
'address', //positionAddress

@@ -322,3 +435,3 @@ 'uint16', // triggerType

'address', // collateralToken
'bytes32', // opHash
'bytes32', // operationName
'uint256', // execCollRatio

@@ -330,4 +443,92 @@ 'uint256', // targetCollRatio

],
[CommandContractType.DmaAaveStopLossCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // executionLTV
],
[CommandContractType.DmaSparkStopLossCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // executionLTV
],
[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
],
[CommandContractType.DmaSparkTrailingStopLossCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'address', // collateralOracle
'uint80', // collateralAddedRoundId
'address', // debtOracle
'uint80', // debtAddedRoundId
'uint256', // trailingDistance
'bool', // closeToCollateral
],
[CommandContractType.DmaSparkBasicBuyCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // execCollRatio
'uint256', // targetCollRatio
'uint256', // maxBuyPrice
'uint64', // deviation
'uint32', // maxBaseFeeInGwei
],
[CommandContractType.DmaSparkBasicSellCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // execCollRatio
'uint256', // targetCollRatio
'uint256', // minSellPrice
'uint64', // deviation
'uint32', // maxBaseFeeInGwei
],
} as const;
export const defaultCommandOffchainDataTypeMapping: Partial<Record<
CommandContractType,
ParamDefinition
>> = {
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'uint80', // collateralMaxPriceRoundId
'uint80', // debtClosestPriceRoundId
'uint80', // debtNextPriceRoundId
],
[CommandContractType.DmaSparkTrailingStopLossCommandV2]: [
'uint80', // collateralMaxPriceRoundId
'uint80', // debtClosestPriceRoundId
'uint80', // debtNextPriceRoundId
],
} as const;
export function getCommandAddresses(network: number): Record<CommandContractType, string[]> {

@@ -368,2 +569,45 @@ 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.

@@ -370,0 +614,0 @@ * @param triggerType The type of trigger.

@@ -24,4 +24,10 @@ import { ethers } from 'ethers';

SparkStopLossCommandV2 = 'SparkStopLossCommandV2',
AaveBasicBuyCommandV2 = 'AaveBasicBuyCommandV2',
AaveBasicSellCommandV2 = 'AaveBasicSellCommandV2',
DmaAaveBasicBuyCommandV2 = 'DmaAaveV3BasicBuyCommandV2',
DmaAaveBasicSellCommandV2 = 'DmaAaveV3BasicSellCommandV2',
DmaSparkStopLossCommandV2 = 'DmaSparkStopLossCommandV2',
DmaAaveStopLossCommandV2 = 'DmaAaveV3StopLossCommandV2',
DmaAaveTrailingStopLossCommandV2 = 'DmaAaveV3TrailingStopLossCommandV2',
DmaSparkTrailingStopLossCommandV2 = 'DmaSparkTrailingStopLossCommandV2',
DmaSparkBasicBuyCommandV2 = 'DmaSparkBasicBuyCommandV2',
DmaSparkBasicSellCommandV2 = 'DmaSparkBasicSellCommandV2',
}

@@ -49,4 +55,12 @@

SparkStopLossToDebtV2 = 118,
AaveBasicBuyV2 = 119,
AaveBasicSellV2 = 120,
DmaAaveBasicBuyV2 = 121,
DmaAaveBasicSellV2 = 122,
DmaAaveStopLossToCollateralV2 = 127,
DmaAaveStopLossToDebtV2 = 128,
DmaSparkStopLossToCollateralV2 = 129,
DmaSparkStopLossToDebtV2 = 130,
DmaSparkBasicBuyV2 = 131,
DmaSparkBasicSellV2 = 132,
DmaAaveTrailingStopLossV2 = 10006,
DmaSparkTrailingStopLossV2 = 10007,
}

@@ -74,4 +88,12 @@

[TriggerType.SparkStopLossToDebtV2]: CommandContractType.SparkStopLossCommandV2,
[TriggerType.AaveBasicBuyV2]: CommandContractType.AaveBasicBuyCommandV2,
[TriggerType.AaveBasicSellV2]: CommandContractType.AaveBasicSellCommandV2,
[TriggerType.DmaAaveBasicBuyV2]: CommandContractType.DmaAaveBasicBuyCommandV2,
[TriggerType.DmaAaveBasicSellV2]: CommandContractType.DmaAaveBasicSellCommandV2,
[TriggerType.DmaAaveStopLossToCollateralV2]: CommandContractType.DmaAaveStopLossCommandV2,
[TriggerType.DmaAaveStopLossToDebtV2]: CommandContractType.DmaAaveStopLossCommandV2,
[TriggerType.DmaSparkStopLossToCollateralV2]: CommandContractType.DmaSparkStopLossCommandV2,
[TriggerType.DmaSparkStopLossToDebtV2]: CommandContractType.DmaSparkStopLossCommandV2,
[TriggerType.DmaAaveTrailingStopLossV2]: CommandContractType.DmaAaveTrailingStopLossCommandV2,
[TriggerType.DmaSparkTrailingStopLossV2]: CommandContractType.DmaSparkTrailingStopLossCommandV2,
[TriggerType.DmaSparkBasicBuyV2]: CommandContractType.DmaSparkBasicBuyCommandV2,
[TriggerType.DmaSparkBasicSellV2]: CommandContractType.DmaSparkBasicSellCommandV2,
};

@@ -78,0 +100,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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc