Skip to content

Commit

Permalink
fix: format
Browse files Browse the repository at this point in the history
  • Loading branch information
halaprix committed Feb 13, 2024
1 parent 77edd4c commit 29af3c2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
14 changes: 10 additions & 4 deletions packages/automation/src/abi-coding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export function decodeTriggerDataByType(type: CommandContractType, data: string)
return utils.defaultAbiCoder.decode(paramTypes, data);
}

export function decodeOffchainTriggerDataByType(type: CommandContractType, data: string): utils.Result {
export function decodeOffchainTriggerDataByType(
type: CommandContractType,
data: string,
): utils.Result {
const paramTypes = getOffchainDataDefinitionForCommandType(type);
return utils.defaultAbiCoder.decode(paramTypes, data);
}
Expand Down Expand Up @@ -90,7 +93,7 @@ export function decodeOffchainTriggerDataByTriggerTypeAsJson(
): utils.Result {
const type = triggerTypeToCommandContractTypeMap[triggerType];
const arr: any[] = decodeOffchainTriggerDataByType(type, data) as any[];
const offchainDataType = commandOffchainDataTypeJsonMapping[type]
const offchainDataType = commandOffchainDataTypeJsonMapping[type];
if (!offchainDataType) {
throw new Error(`No offchain data mapping for type ${type}`);
}
Expand Down Expand Up @@ -123,7 +126,10 @@ export function encodeTriggerDataByTriggerType(
return utils.defaultAbiCoder.encode(paramTypes, values);
}

export function encodeOffchainTriggerDataByType(type: CommandContractType, values: readonly any[]): string {
export function encodeOffchainTriggerDataByType(
type: CommandContractType,
values: readonly any[],
): string {
const paramTypes = getOffchainDataDefinitionForCommandType(type);
return utils.defaultAbiCoder.encode(paramTypes, values);
}
Expand All @@ -135,4 +141,4 @@ export function encodeTriggerOffchainDataByTriggerType(
const commandType = triggerTypeToCommandContractTypeMap[triggerType];
const paramTypes = getOffchainDataDefinitionForCommandType(commandType);
return utils.defaultAbiCoder.encode(paramTypes, values);
}
}
31 changes: 19 additions & 12 deletions packages/automation/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const commandTypeJsonMapping: Record<CommandContractType, string[]> = {
'debtOracle',
'debtAddedRoundId',
'trailingDistance',
'closeToCollateral'
'closeToCollateral',
],
};
export const commandOffchainDataTypeJsonMapping: Partial<Record<CommandContractType, string[]>> = {
Expand Down Expand Up @@ -415,7 +415,10 @@ export const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinit
],
} as const;

export const defaultCommandOffchainDataTypeMapping: Partial<Record<CommandContractType, ParamDefinition>> = {
export const defaultCommandOffchainDataTypeMapping: Partial<Record<
CommandContractType,
ParamDefinition
>> = {
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
'uint80', // collateralMaxPriceRoundId
'uint80', // debtClosestPriceRoundId
Expand Down Expand Up @@ -463,13 +466,15 @@ export function getDefinitionForCommandType(type: CommandContractType): ParamDef
* @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]
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(
', ',
)}.`,
`Unknown command type ${type}. Supported types: ${Object.keys(
defaultCommandOffchainDataTypeMapping,
).join(', ')}.`,
);
}

Expand All @@ -482,14 +487,16 @@ export function getOffchainDataDefinitionForCommandType(type: Partial<CommandCon
* @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 {
export function getOffchainDataDefinitionForTriggerType(
triggerType: Partial<TriggerType>,
): ParamDefinition {
const type = triggerTypeToCommandContractTypeMap[triggerType];
const offchainDataType = defaultCommandOffchainDataTypeMapping[type]
const offchainDataType = defaultCommandOffchainDataTypeMapping[type];
if (!offchainDataType) {
throw new Error(
`Unknown command type ${type}. Supported types: ${Object.keys(defaultCommandOffchainDataTypeMapping).join(
', ',
)}.`,
`Unknown command type ${type}. Supported types: ${Object.keys(
defaultCommandOffchainDataTypeMapping,
).join(', ')}.`,
);
}

Expand Down

0 comments on commit 29af3c2

Please sign in to comment.