Socket
Socket
Sign inDemoInstall

@oasisdex/automation

Package Overview
Dependencies
Maintainers
11
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.2.7-alpha.3 to 1.2.8-alpha.0

2

lib/src/abi-coding.d.ts
import { utils } from 'ethers';
import { CommandContractType } from './types';
export declare function decodeTriggerData(commandAddress: string, network: number, data: string): utils.Result;
export declare function decodeTriggerDataAsJson(commandAddress: string, network: number, data: string): utils.Result;
export declare function decodeTriggerDataByType(type: CommandContractType, data: string): utils.Result;
export declare function decodeTriggerDataByTypeAsJson(type: CommandContractType, 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;
//# sourceMappingURL=abi-coding.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeTriggerDataByType = exports.encodeTriggerData = exports.decodeTriggerDataByType = exports.decodeTriggerData = void 0;
exports.encodeTriggerDataByType = exports.encodeTriggerData = exports.decodeTriggerDataByTypeAsJson = exports.decodeTriggerDataByType = exports.decodeTriggerDataAsJson = exports.decodeTriggerData = void 0;
const ethers_1 = require("ethers");

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

exports.decodeTriggerData = decodeTriggerData;
function decodeTriggerDataAsJson(commandAddress, network, data) {
const arr = decodeTriggerData(commandAddress, network, data);
const type = mapping_1.commandAddressMapping[network][commandAddress].type;
return arr.reduce((acc, curr, idx) => {
acc[mapping_1.commandTypeJsonMapping[type][idx]] = curr.toString();
return acc;
}, {});
}
exports.decodeTriggerDataAsJson = decodeTriggerDataAsJson;
function decodeTriggerDataByType(type, data) {

@@ -17,2 +26,10 @@ const paramTypes = (0, mapping_1.getDefinitionForCommandType)(type);

exports.decodeTriggerDataByType = decodeTriggerDataByType;
function decodeTriggerDataByTypeAsJson(type, data) {
const arr = decodeTriggerDataByType(type, data);
return arr.reduce((acc, curr, idx) => {
acc[mapping_1.commandTypeJsonMapping[type][idx]] = curr.toString();
return acc;
}, {});
}
exports.decodeTriggerDataByTypeAsJson = decodeTriggerDataByTypeAsJson;
function encodeTriggerData(commandAddress, network, values) {

@@ -19,0 +36,0 @@ const paramTypes = (0, mapping_1.getDefinitionForCommandAddress)(commandAddress, network);

import { CommandContractInfo, CommandContractType, ParamDefinition } from './types';
export declare const commandTypeJsonMapping: Record<CommandContractType, string[]>;
export declare const commandAddressMapping: Record<number, Record<string, CommandContractInfo>>;

@@ -9,2 +10,3 @@ export declare const defaultCommandTypeMapping: {

readonly BasicSellCommand: readonly ["uint256", "uint16", "uint256", "uint256", "uint256", "bool", "uint64", "uint32"];
readonly AaveStopLossCommand: readonly ["address", "uint16", "address", "address", "uint256", "uint32"];
};

@@ -11,0 +13,0 @@ export declare function getCommandAddresses(network: number): Record<CommandContractType, string[]>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCommandContractInfo = exports.getDefinitionForCommandAddress = exports.getDefinitionForCommandType = exports.getCommandAddresses = exports.defaultCommandTypeMapping = exports.commandAddressMapping = void 0;
exports.getCommandContractInfo = exports.getDefinitionForCommandAddress = exports.getDefinitionForCommandType = exports.getCommandAddresses = exports.defaultCommandTypeMapping = exports.commandAddressMapping = exports.commandTypeJsonMapping = void 0;
const types_1 = require("./types");
exports.commandTypeJsonMapping = {
[types_1.CommandContractType.CloseCommand]: ['cdpId', 'triggerType', 'collRatio'],
[types_1.CommandContractType.BasicBuyCommand]: [
'cdpId',
'triggerType',
'execCollRatio',
'targetCollRatio',
'maxBuyPrice',
'continous',
'deviation',
'maxBaseFeeInGwei',
],
[types_1.CommandContractType.BasicSellCommand]: [
'cdpId',
'triggerType',
'execCollRatio',
'targetCollRatio',
'minSellPrice',
'continous',
'deviation',
'maxBaseFeeInGwei',
],
[types_1.CommandContractType.AutoTakeProfitCommand]: [
'cdpId',
'triggerType',
'executionPrice',
'maxBaseFeeInGwei',
],
[types_1.CommandContractType.SimpleAAVESellCommand]: [
'positionAddress',
'triggerType',
'amount',
'interval',
'recipient',
],
[types_1.CommandContractType.AaveStopLossCommand]: [
'positionAddress',
'triggerType',
'collateralToken',
'debtToken',
'slLevel',
'maxBaseFeeInGwei',
],
};
exports.commandAddressMapping = Object.fromEntries(Object.entries({

@@ -29,7 +73,7 @@ [types_1.EthereumNetwork.GOERLI]: {

},
'0x9c0AD6E7f9dAF14fA5445dc92B9327fe4B313163': {
'0x7b548daF6c7057449a57c08b9d34e352dB220E3B': {
type: types_1.CommandContractType.SimpleAAVESellCommand,
},
'0x025bc7F363051ae01e328d6B6ac4F2a0CafcF753': {
type: types_1.CommandContractType.SimpleAAVESellCommand,
'0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676': {
type: types_1.CommandContractType.AaveStopLossCommand,
},

@@ -52,2 +96,5 @@ },

},
'0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676': {
type: types_1.CommandContractType.AaveStopLossCommand,
},
},

@@ -88,2 +135,10 @@ }).map(([network, mapping]) => [

],
[types_1.CommandContractType.AaveStopLossCommand]: [
'address',
'uint16',
'address',
'address',
'uint256',
'uint32',
],
};

@@ -90,0 +145,0 @@ function getCommandAddresses(network) {

7

lib/src/types.d.ts

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

BasicSellCommand = "BasicSellCommand",
SimpleAAVESellCommand = "SimpleAAVESell"
SimpleAAVESellCommand = "SimpleAAVESell",
AaveStopLossCommand = "AaveStopLossCommand"
}

@@ -21,3 +22,5 @@ export declare enum TriggerType {

AutoTakeProfitToDai = 8,
SimpleAAVESell = 9
SimpleAAVESell = 9,
AaveStopLossToCollateral = 10,
AaveStopLossToDebt = 11
}

@@ -24,0 +27,0 @@ export declare enum TriggerGroupType {

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

CommandContractType["SimpleAAVESellCommand"] = "SimpleAAVESell";
CommandContractType["AaveStopLossCommand"] = "AaveStopLossCommand";
})(CommandContractType = exports.CommandContractType || (exports.CommandContractType = {}));

@@ -27,2 +28,4 @@ var TriggerType;

TriggerType[TriggerType["SimpleAAVESell"] = 9] = "SimpleAAVESell";
TriggerType[TriggerType["AaveStopLossToCollateral"] = 10] = "AaveStopLossToCollateral";
TriggerType[TriggerType["AaveStopLossToDebt"] = 11] = "AaveStopLossToDebt";
})(TriggerType = exports.TriggerType || (exports.TriggerType = {}));

@@ -29,0 +32,0 @@ var TriggerGroupType;

@@ -87,3 +87,81 @@ "use strict";

});
describe('toJSON', () => {
const closeData = [12, 1, 101];
const buyData = [12, 1, 101, 100, 2000, true, 10, 100];
const aaveSLData = ["0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676", 1, "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676", "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676", 2000, 100];
describe('CloseCommand', () => {
const data = (0, abi_coding_1.encodeTriggerDataByType)(types_1.CommandContractType.CloseCommand, closeData);
it('decodeTriggerDataAsJson converts to correct json', () => {
const actual = (0, abi_coding_1.decodeTriggerDataAsJson)((0, mapping_1.getCommandAddresses)(network)[types_1.CommandContractType.CloseCommand][0], network, data);
(0, chai_1.expect)(actual).to.deep.eq({
cdpId: "12",
triggerType: "1",
collRatio: "101"
});
});
it('decodeTriggerDataByTypeAsJson converts to correct json', () => {
const actual = (0, abi_coding_1.decodeTriggerDataByTypeAsJson)(types_1.CommandContractType.CloseCommand, data);
(0, chai_1.expect)(actual).to.deep.eq({
cdpId: "12",
triggerType: "1",
collRatio: "101"
});
});
});
describe('BasicBuyCommand', () => {
const data = (0, abi_coding_1.encodeTriggerDataByType)(types_1.CommandContractType.BasicBuyCommand, buyData);
it('decodeTriggerDataAsJson converts to correct json', () => {
const actual = (0, abi_coding_1.decodeTriggerDataAsJson)((0, mapping_1.getCommandAddresses)(network)[types_1.CommandContractType.BasicBuyCommand][2], network, data);
(0, chai_1.expect)(actual).to.deep.eq({
cdpId: "12",
triggerType: "1",
execCollRatio: "101",
maxBaseFeeInGwei: "100",
maxBuyPrice: "2000",
continous: "true",
deviation: "10",
targetCollRatio: "100",
});
});
it('decodeTriggerDataByTypeAsJson converts to correct json', () => {
const actual = (0, abi_coding_1.decodeTriggerDataByTypeAsJson)(types_1.CommandContractType.BasicBuyCommand, data);
(0, chai_1.expect)(actual).to.deep.eq({
cdpId: "12",
triggerType: "1",
execCollRatio: "101",
maxBaseFeeInGwei: "100",
maxBuyPrice: "2000",
continous: "true",
deviation: "10",
targetCollRatio: "100",
});
});
});
describe('AaveStopLossCommand', () => {
const data = (0, abi_coding_1.encodeTriggerDataByType)(types_1.CommandContractType.AaveStopLossCommand, aaveSLData);
it('decodeTriggerDataAsJson converts to correct json', () => {
const actual = (0, abi_coding_1.decodeTriggerDataAsJson)((0, mapping_1.getCommandAddresses)(network)[types_1.CommandContractType.AaveStopLossCommand][0], network, data);
(0, chai_1.expect)(actual).to.deep.eq({
positionAddress: "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
triggerType: "1",
collateralToken: "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
debtToken: "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
maxBaseFeeInGwei: "100",
slLevel: "2000",
});
});
it('decodeTriggerDataByTypeAsJson converts to correct json', () => {
const actual = (0, abi_coding_1.decodeTriggerDataByTypeAsJson)(types_1.CommandContractType.AaveStopLossCommand, data);
(0, chai_1.expect)(actual).to.deep.eq({
positionAddress: "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
triggerType: "1",
collateralToken: "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
debtToken: "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
maxBaseFeeInGwei: "100",
slLevel: "2000",
});
});
});
});
});
//# sourceMappingURL=abi-coding.test.js.map
{
"name": "@oasisdex/automation",
"version": "1.2.7-alpha.3",
"version": "1.2.8-alpha.0",
"description": "The set of utilities for Oasis automation",

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

},
"gitHead": "f2beabbd0735e18bb8db62f39ac4e82560ff5b1f"
"gitHead": "14ced8496e50bb1d964bebb92eb03c8d26f7673b"
}
import { utils } from 'ethers';
import { getDefinitionForCommandAddress, getDefinitionForCommandType } from './mapping';
import {
commandAddressMapping,
commandTypeJsonMapping,
getDefinitionForCommandAddress,
getDefinitionForCommandType,
} from './mapping';
import { CommandContractType } from './types';

@@ -14,2 +19,16 @@

export function decodeTriggerDataAsJson(
commandAddress: string,
network: number,
data: string,
): utils.Result {
const arr: any[] = decodeTriggerData(commandAddress, network, data) as any[];
const type = commandAddressMapping[network][commandAddress].type;
return arr.reduce((acc, curr, idx) => {
acc[commandTypeJsonMapping[type][idx]] = curr.toString();
return acc;
},{});
}
export function decodeTriggerDataByType(type: CommandContractType, data: string): utils.Result {

@@ -20,2 +39,14 @@ const paramTypes = getDefinitionForCommandType(type);

export function decodeTriggerDataByTypeAsJson(
type: CommandContractType,
data: string,
): utils.Result {
const arr: any[] = decodeTriggerDataByType(type, data) as any[];
return arr.reduce((acc, curr, idx) => {
acc[commandTypeJsonMapping[type][idx]] = curr.toString();
return acc;
},{});
}
export function encodeTriggerData(

@@ -22,0 +53,0 @@ commandAddress: string,

@@ -8,2 +8,47 @@ import {

export const commandTypeJsonMapping: Record<CommandContractType, string[]> = {
[CommandContractType.CloseCommand]: ['cdpId', 'triggerType', 'collRatio'],
[CommandContractType.BasicBuyCommand]: [
'cdpId',
'triggerType',
'execCollRatio',
'targetCollRatio',
'maxBuyPrice',
'continous',
'deviation',
'maxBaseFeeInGwei',
],
[CommandContractType.BasicSellCommand]: [
'cdpId',
'triggerType',
'execCollRatio',
'targetCollRatio',
'minSellPrice',
'continous',
'deviation',
'maxBaseFeeInGwei',
],
[CommandContractType.AutoTakeProfitCommand]: [
'cdpId',
'triggerType',
'executionPrice',
'maxBaseFeeInGwei',
],
[CommandContractType.SimpleAAVESellCommand]: [
'positionAddress',
'triggerType',
'amount',
'interval',
'recipient',
],
[CommandContractType.AaveStopLossCommand]: [
'positionAddress',
'triggerType',
'collateralToken',
'debtToken',
'slLevel',
'maxBaseFeeInGwei',
],
};
export const commandAddressMapping: Record<

@@ -37,7 +82,7 @@ number,

},
'0x9c0AD6E7f9dAF14fA5445dc92B9327fe4B313163': {
'0x7b548daF6c7057449a57c08b9d34e352dB220E3B': {
type: CommandContractType.SimpleAAVESellCommand,
},
'0x025bc7F363051ae01e328d6B6ac4F2a0CafcF753': {
type: CommandContractType.SimpleAAVESellCommand,
'0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676': {
type: CommandContractType.AaveStopLossCommand,
},

@@ -60,2 +105,5 @@ },

},
'0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676': {
type: CommandContractType.AaveStopLossCommand,
},
},

@@ -100,2 +148,10 @@ }).map(([network, mapping]) => [

],
[CommandContractType.AaveStopLossCommand]: [
'address',
'uint16',
'address',
'address',
'uint256',
'uint32',
],
} as const;

@@ -102,0 +158,0 @@

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

SimpleAAVESellCommand = 'SimpleAAVESell',
AaveStopLossCommand = 'AaveStopLossCommand',
}

@@ -25,2 +26,4 @@

SimpleAAVESell = 9,
AaveStopLossToCollateral = 10,
AaveStopLossToDebt = 11,
}

@@ -27,0 +30,0 @@

@@ -5,7 +5,9 @@ import { expect } from 'chai';

decodeTriggerData,
decodeTriggerDataAsJson,
decodeTriggerDataByType,
decodeTriggerDataByTypeAsJson,
encodeTriggerData,
encodeTriggerDataByType,
} from '../src/abi-coding';
import { commandAddressMapping, getDefinitionForCommandType } from '../src/mapping';
import { commandAddressMapping, getCommandAddresses, getDefinitionForCommandType } from '../src/mapping';
import { CommandContractType, EthereumNetwork } from '../src/types';

@@ -119,2 +121,82 @@

});
describe('toJSON', () => {
const closeData = [12, 1, 101];
const buyData = [12, 1, 101, 100, 2000, true, 10, 100];
const aaveSLData = ["0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676", 1, "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676", "0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676", 2000, 100];
describe('CloseCommand',()=>{
const data = encodeTriggerDataByType(CommandContractType.CloseCommand, closeData);
it('decodeTriggerDataAsJson converts to correct json', ()=>{
const actual = decodeTriggerDataAsJson(getCommandAddresses(network)[CommandContractType.CloseCommand][0] ,network, data);
expect(actual).to.deep.eq({
cdpId:"12",
triggerType:"1",
collRatio:"101"
});
})
it('decodeTriggerDataByTypeAsJson converts to correct json', ()=>{
const actual = decodeTriggerDataByTypeAsJson(CommandContractType.CloseCommand, data);
expect(actual).to.deep.eq({
cdpId:"12",
triggerType:"1",
collRatio:"101"
});
})
})
describe('BasicBuyCommand',()=>{
const data = encodeTriggerDataByType(CommandContractType.BasicBuyCommand, buyData);
it('decodeTriggerDataAsJson converts to correct json', ()=>{
const actual = decodeTriggerDataAsJson(getCommandAddresses(network)[CommandContractType.BasicBuyCommand][2] ,network, data);
expect(actual).to.deep.eq({
cdpId:"12",
triggerType:"1",
execCollRatio:"101",
maxBaseFeeInGwei:"100",
maxBuyPrice:"2000",
continous:"true",
deviation:"10",
targetCollRatio:"100",
});
})
it('decodeTriggerDataByTypeAsJson converts to correct json', ()=>{
const actual = decodeTriggerDataByTypeAsJson(CommandContractType.BasicBuyCommand, data);
expect(actual).to.deep.eq({
cdpId:"12",
triggerType:"1",
execCollRatio:"101",
maxBaseFeeInGwei:"100",
maxBuyPrice:"2000",
continous:"true",
deviation:"10",
targetCollRatio:"100",
});
})
})
describe('AaveStopLossCommand',()=>{
const data = encodeTriggerDataByType(CommandContractType.AaveStopLossCommand, aaveSLData);
it('decodeTriggerDataAsJson converts to correct json', ()=>{
const actual = decodeTriggerDataAsJson(getCommandAddresses(network)[CommandContractType.AaveStopLossCommand][0] ,network, data);
expect(actual).to.deep.eq({
positionAddress:"0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
triggerType:"1",
collateralToken:"0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
debtToken:"0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
maxBaseFeeInGwei:"100",
slLevel:"2000",
});
})
it('decodeTriggerDataByTypeAsJson converts to correct json', ()=>{
const actual = decodeTriggerDataByTypeAsJson(CommandContractType.AaveStopLossCommand, data);
expect(actual).to.deep.eq({
positionAddress:"0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
triggerType:"1",
collateralToken:"0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
debtToken:"0xE78ACEa26B79564C4D29D8c1f5bAd3D4E0414676",
maxBaseFeeInGwei:"100",
slLevel:"2000",
});
})
})
});
});

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc