Skip to content

Commit

Permalink
feat: improve debug definitions (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
robercano authored Jun 4, 2024
1 parent d8f846f commit 72d5bfe
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
29 changes: 29 additions & 0 deletions sdk/tools/genStrategyDefinitions/src/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion sdk/tools/genStrategyDefinitions/src/Types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion sdk/tools/genStrategyDefinitions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
generateDebugDefinitions,
generateOperationDefinitions,
generateSafeMultisendJSON,
processStrategies,
Expand Down Expand Up @@ -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('--------------------')
Expand Down

0 comments on commit 72d5bfe

Please sign in to comment.