From ae00e7335b713f96d5f9eab89985c2e29d7f5202 Mon Sep 17 00:00:00 2001 From: Jakub Swierczek Date: Mon, 18 Mar 2024 10:38:09 +0100 Subject: [PATCH] Add 'Unknown' case to LendingProtocol and modify failure behavior In the event of an unrecognised lending protocol, the code will not throw an error but instead log a warning message. A new case 'Unknown' has been added to LendingProtocol to give a default value for this scenario. --- features/aave/services/read-position-created-events.ts | 3 ++- lendingProtocols/LendingProtocol.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/features/aave/services/read-position-created-events.ts b/features/aave/services/read-position-created-events.ts index 920da7866e..93dd7ae8d0 100644 --- a/features/aave/services/read-position-created-events.ts +++ b/features/aave/services/read-position-created-events.ts @@ -105,11 +105,12 @@ export function extractLendingProtocolFromPositionCreatedEvent( case 'MorphoBlue': return LendingProtocol.MorphoBlue default: - throw new Error( + console.warn( `Unrecognised protocol received from positionCreatedChainEvent ${JSON.stringify( positionCreatedChainEvent, )}`, ) + return LendingProtocol.Unknown } } diff --git a/lendingProtocols/LendingProtocol.ts b/lendingProtocols/LendingProtocol.ts index 14b3ded22e..312287263f 100644 --- a/lendingProtocols/LendingProtocol.ts +++ b/lendingProtocols/LendingProtocol.ts @@ -5,6 +5,7 @@ export enum LendingProtocol { Maker = 'maker', MorphoBlue = 'morphoblue', SparkV3 = 'sparkv3', + Unknown = 'unknown', } export enum LendingProtocolLabel {