Skip to content

Commit

Permalink
feat: missing action
Browse files Browse the repository at this point in the history
  • Loading branch information
halaprix committed Nov 22, 2023
1 parent 09e934f commit fa96386
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/automation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oasisdex/automation",
"version": "1.5.9-alpha3",
"version": "1.5.9-alpha4",
"description": "The set of utilities for Oasis automation",
"homepage": "https://github.com/OasisDEX/common#readme",
"main": "lib/src/index.js",
Expand Down
19 changes: 14 additions & 5 deletions packages/automation/src/abi-coding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ export function decodeTriggerData(
return utils.defaultAbiCoder.decode(paramTypes, data);
}

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

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

export function decodeTriggerDataAsJson(
commandAddress: string,
network: number,
Expand All @@ -30,11 +44,6 @@ export function decodeTriggerDataAsJson(
}, {});
}

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

export function decodeTriggerDataByTypeAsJson(
type: CommandContractType,
data: string,
Expand Down
10 changes: 9 additions & 1 deletion packages/automation/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
export {
decodeTriggerData,
decodeTriggerDataByType,
decodeTriggerDataByTriggerType,
encodeTriggerData,
encodeTriggerDataByType,
decodeTriggerDataAsJson,
encodeTriggerDataByTriggerType,
decodeTriggerDataByTypeAsJson,
decodeTriggerDataByTriggerTypeAsJson,
} from './abi-coding';
export { getCommandAddresses } from './mapping';

export { CommandContractType, TriggerType, TriggerGroupType } from './types';
export {
CommandContractType,
TriggerType,
TriggerGroupType,
triggerTypeToCommandContractTypeMap,
} from './types';
10 changes: 8 additions & 2 deletions packages/automation/test/abi-coding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BigNumber as EthersBN, constants, utils } from 'ethers';
import {
decodeTriggerData,
decodeTriggerDataAsJson,
decodeTriggerDataByTriggerType,
decodeTriggerDataByTriggerTypeAsJson,
decodeTriggerDataByType,
decodeTriggerDataByTypeAsJson,
Expand Down Expand Up @@ -79,8 +80,13 @@ describe('abi-coding', () => {
expect(EthersBN.from(value).toNumber()).to.eq(validValues[idx]);
});
});

it('can decode trigger data by command address', () => {
it('can decode trigger data by trigger type', () => {
const result = decodeTriggerDataByTriggerType(TriggerType.StopLossToCollateral, data);
result.forEach((value, idx) => {
expect(EthersBN.from(value).toNumber()).to.eq(validValues[idx]);
});
});
it('can decode trigger data by command type', () => {
const result = decodeTriggerDataByType(type, data);
result.forEach((value, idx) => {
expect(EthersBN.from(value).toNumber()).to.eq(validValues[idx]);
Expand Down

0 comments on commit fa96386

Please sign in to comment.