From 72d5bfe9e7d5427a610372d9ab4d0568233b6061 Mon Sep 17 00:00:00 2001 From: Roberto Cano <3525807+robercano@users.noreply.github.com> Date: Tue, 4 Jun 2024 08:21:30 +0200 Subject: [PATCH] feat: improve debug definitions (#307) --- .../genStrategyDefinitions/src/Helpers.ts | 29 +++++++++++++++++++ sdk/tools/genStrategyDefinitions/src/Types.ts | 13 ++++++++- sdk/tools/genStrategyDefinitions/src/index.ts | 5 +++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/sdk/tools/genStrategyDefinitions/src/Helpers.ts b/sdk/tools/genStrategyDefinitions/src/Helpers.ts index 3dea8fa865..c8a6691e73 100644 --- a/sdk/tools/genStrategyDefinitions/src/Helpers.ts +++ b/sdk/tools/genStrategyDefinitions/src/Helpers.ts @@ -3,6 +3,7 @@ import { ProtocolPluginsRecord } from '@summerfi/protocol-plugins' import { ActionBuilderUsedAction } from '@summerfi/protocol-plugins-common' import { SimulationStrategy, StrategyStep } from '@summerfi/sdk-common/simulation' import { + DebugDefinitions, OperationDefinition, OperationDefinitions, StrategyDefinitions, @@ -76,6 +77,33 @@ export function generateOperationDefinitions( }) } +export function generateDebugDefinitions( + strategyName: string, + strategyDefinitions: StrategyDefinitions, +): DebugDefinitions { + return strategyDefinitions.map((strategy) => { + const paybackAction = strategy.find((action) => { + return action.name.includes('Payback') + }) + + const depositAction = strategy.find((action) => { + return action.name.includes('Deposit') + }) + + if (!paybackAction || !depositAction) { + throw new Error('Cannot find payback or deposit action') + } + + const fromProtocol = paybackAction.name.split('Payback')[0] + const toProtocol = depositAction.name.split('Deposit')[0] + + return { + operationName: `${strategyName}${fromProtocol}${toProtocol}`, + operation: strategy, + } + }) +} + export function processStrategies(strategyConfigs: SimulationStrategy[]): StrategyDefinitions { const strategyDefinitions = strategyConfigs.reduce((acc, strategy) => { acc.push(...processStrategy(strategy)) @@ -136,6 +164,7 @@ export function processAction( [ { name: action.config.name, + versionedName: action.getVersionedName(), hash: action.getActionHash(), optional: DISABLE_OPTIONALS || stepConfig.optional || actionConfig.isOptionalTags !== undefined, diff --git a/sdk/tools/genStrategyDefinitions/src/Types.ts b/sdk/tools/genStrategyDefinitions/src/Types.ts index 223124ec68..57a828524a 100644 --- a/sdk/tools/genStrategyDefinitions/src/Types.ts +++ b/sdk/tools/genStrategyDefinitions/src/Types.ts @@ -1,12 +1,23 @@ import { AddressValue, HexData } from '@summerfi/sdk-common' -export type ActionDefinition = { name: string; hash: HexData; optional: boolean } +export type ActionDefinition = { + name: string + versionedName: string + hash: HexData + optional: boolean +} export type StrategyDefinition = ActionDefinition[] export type StrategyDefinitions = StrategyDefinition[] export type OperationDefinition = { actions: HexData[]; optional: boolean[]; name: string } export type OperationDefinitions = OperationDefinition[] +export type DebugDefinition = { + operation: StrategyDefinition + operationName: string +} +export type DebugDefinitions = DebugDefinition[] + export type Transaction = { to: AddressValue value: string diff --git a/sdk/tools/genStrategyDefinitions/src/index.ts b/sdk/tools/genStrategyDefinitions/src/index.ts index 7526a5bf37..37fb3c69b9 100644 --- a/sdk/tools/genStrategyDefinitions/src/index.ts +++ b/sdk/tools/genStrategyDefinitions/src/index.ts @@ -1,4 +1,5 @@ import { + generateDebugDefinitions, generateOperationDefinitions, generateSafeMultisendJSON, processStrategies, @@ -54,7 +55,9 @@ async function main() { } else if (args.format === 'tenderly') { fs.writeFileSync(args.output, JSON.stringify(operationDefinitions, null, 2)) } else { - fs.writeFileSync(args.output, JSON.stringify(strategyDefinitions, null, 2)) + const debugDefinitions = generateDebugDefinitions('Refinance', strategyDefinitions) + + fs.writeFileSync(args.output, JSON.stringify(debugDefinitions, null, 2)) } } else { console.log('--------------------')