Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve debug definitions #307

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading