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: accept skippable actions in order planner #298

Merged
merged 61 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
137e04a
fix: move vault ID to Maker position ID (#186)
robercano Apr 24, 2024
1c0ed24
Merge branch 'dev' into feature/refinance-non-ajna
robercano Apr 25, 2024
7b3348c
feat: refactor lending pool data type into single pair (#204)
robercano May 2, 2024
99d38c9
feat: add getLendingPoolInfo to retrieve extra info (#217)
robercano May 2, 2024
8bac286
feat: add tokens service (#218)
robercano May 2, 2024
37a827d
Merge branch 'dev' into feature/refinance-non-ajna
robercano May 3, 2024
ccd7098
feat: add oracle service (#219)
robercano May 3, 2024
97896e5
Merge branch 'dev' into feature/refinance-non-ajna
robercano May 6, 2024
8943f06
feat: add spark and aave action builders
paszkowskiDamian May 7, 2024
6781ebb
feat: add emode category
paszkowskiDamian May 7, 2024
14c3ae6
feat: add open position step
paszkowskiDamian May 8, 2024
4c43c46
feat: add action builders for open position
paszkowskiDamian May 8, 2024
f64c9b1
feat: open step
paszkowskiDamian May 8, 2024
ea8baa7
refactor: improve simulator types (1st iteration)
paszkowskiDamian May 8, 2024
ed40bd0
refactor: resolve types
paszkowskiDamian May 13, 2024
11655cf
refactor: fix all reducers to follow new state interface
paszkowskiDamian May 13, 2024
e325eff
refactor: add name to steps
paszkowskiDamian May 13, 2024
35a765e
chore: create new test
paszkowskiDamian May 13, 2024
94b8eb8
fix: types
paszkowskiDamian May 13, 2024
a8f2adb
Merge branch 'dev' into damianpaszkowski/aavelike-plugins
robercano May 13, 2024
7ccf90c
fix: e2e tests
robercano May 13, 2024
9c19a5b
Merge branch 'dev' into damianpaszkowski/aavelike-plugins
robercano May 15, 2024
015a6cb
fix: build
robercano May 16, 2024
d725f4d
Merge branch 'dev' into damianpaszkowski/aavelike-plugins
robercano May 16, 2024
1b82946
fix: cicheck
robercano May 16, 2024
23353d8
feat: add unit tests
robercano May 16, 2024
ea5306f
feat: add more unit tests
robercano May 16, 2024
bde8d6a
Merge branch 'dev' into damianpaszkowski/aavelike-plugins
robercano May 16, 2024
be36dc3
fix: format
robercano May 16, 2024
1e37a27
feat: add e2e Refinance AaveV3 Spark
robercano May 16, 2024
bef7459
Merge branch 'dev' into damianpaszkowski/aavelike-plugins
robercano May 16, 2024
261509e
feat: fix tests
robercano May 16, 2024
3515e42
feat: refactor action builder into classes
robercano May 16, 2024
f44772f
fix: disable e2e test
robercano May 16, 2024
72db237
Merge branch 'damianpaszkowski/aavelike-plugins' into rc/sc-15195/ope…
robercano May 16, 2024
e8bd5a3
feat: convert action builders to classes
robercano May 17, 2024
40e8b29
wip: initial version for operation definitions gen
robercano May 23, 2024
8fdc8a2
feat: operation definition tool
robercano May 24, 2024
572802b
Merge branch 'dev' into rc/sc-15195/operation-definitions-tool
robercano May 24, 2024
af2daa2
Merge branch 'dev' into rc/sc-15195/operation-definitions-tool
robercano May 24, 2024
8b405f0
fix: cicheck
robercano May 24, 2024
d30d0c2
fix: change how strategy name is generated
robercano May 24, 2024
b8b4b12
fix: build
robercano May 24, 2024
44b1e0d
fix: aws-cdk version issue
robercano May 24, 2024
fa22fe7
feat: add format option
robercano May 24, 2024
8721330
feat: accept skippable actions in order planner
robercano May 24, 2024
87ba13b
chore: cleanup
robercano May 24, 2024
e40a1f7
chore: cleanup
robercano May 24, 2024
5565920
chore: cleanup
robercano May 24, 2024
1a57f56
fix: disable e2e test
robercano May 24, 2024
293dd0b
chore: cleanup
robercano May 24, 2024
8d9fd3b
fix: refinance maker spark test
robercano May 24, 2024
5f2c1ed
Merge branch 'dev' into rc/sc-15195/operation-definitions-tool
robercano May 24, 2024
b645154
Merge branch 'rc/sc-15195/operation-definitions-tool' into rc/enable-…
robercano May 24, 2024
e2e9b4b
Merge branch 'dev' into rc/sc-15195/operation-definitions-tool
robercano May 27, 2024
9548f0b
Merge branch 'rc/sc-15195/operation-definitions-tool' into rc/enable-…
robercano May 27, 2024
e374960
fix: address PR comments
robercano May 27, 2024
82259fa
fix: Address PR comments
robercano May 27, 2024
2888a5a
Merge branch 'rc/sc-15195/operation-definitions-tool' into rc/enable-…
robercano May 27, 2024
2ec1f83
Merge branch 'dev' into rc/enable-optional-actions
robercano May 27, 2024
f49985b
fix: remove unused simulation types
robercano May 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class OrderPlanner implements IOrderPlanner {
addressBookManager,
step,
protocolsRegistry,
actionBuildersMap,
})
}

Expand Down
12 changes: 1 addition & 11 deletions sdk/order-planner-common/src/utils/EncodeStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { Address, HexData, Maybe } from '@summerfi/sdk-common/common'
import { IPositionsManager, TransactionInfo } from '@summerfi/sdk-common/orders'
import { encodeFunctionData, parseAbi } from 'viem'

type SkippableActionCall = ActionCall & {
skipped: boolean
}

function encodeForExecutor(params: { strategyName: string; actions: ActionCall[] }): HexData {
const { strategyName, actions } = params

Expand All @@ -15,16 +11,10 @@ function encodeForExecutor(params: { strategyName: string; actions: ActionCall[]
'struct Call { bytes32 targetHash; bytes callData; bool skipped; }',
])

// TODO: Hiding this here for now as we don't support skippable actions anymore in the new version
const skippableActions: SkippableActionCall[] = actions.map((action) => ({
...action,
skipped: false,
}))

return encodeFunctionData({
abi,
functionName: 'executeOp',
args: [skippableActions, strategyName],
args: [actions, strategyName],
})
}

Expand Down
12 changes: 0 additions & 12 deletions sdk/order-planner-common/src/utils/GenerateStrategyName.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { ISimulation, SimulationType } from '@summerfi/sdk-common/simulation'

export function generateStrategyName(simulation: ISimulation<SimulationType>): string {
// TODO: temporary workaround to use the right simulation name
if (
simulation.simulationType === SimulationType.Refinance ||
simulation.simulationType === SimulationType.RefinanceDifferentPair ||
simulation.simulationType === SimulationType.RefinanceDifferentCollateral ||
simulation.simulationType === SimulationType.RefinanceDifferentDebt ||
simulation.simulationType === SimulationType.RefinanceNoDebt ||
simulation.simulationType === SimulationType.RefinanceNoDebtDifferentCollateral
) {
return `Refinance${simulation.sourcePosition?.pool.id.protocol.name}${simulation.targetPosition.pool.id.protocol.name}`
}

return `${simulation.simulationType}${simulation.sourcePosition?.pool.id.protocol.name}${simulation.targetPosition?.pool.id.protocol.name}`
}
2 changes: 2 additions & 0 deletions sdk/order-planner-service/src/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ReturnFundsActionBuilder,
SwapActionBuilder,
OpenPositionActionBuilder,
SkippedStepActionBuilder,
} from '@summerfi/protocol-plugins/plugins/common'

export const ActionBuildersConfig: ActionBuildersMap = {
Expand All @@ -24,4 +25,5 @@ export const ActionBuildersConfig: ActionBuildersMap = {
[SimulationSteps.NewPositionEvent]: PositionCreatedActionBuilder,
[SimulationSteps.Import]: ImportPositionActionBuilder,
[SimulationSteps.OpenPosition]: OpenPositionActionBuilder,
[SimulationSteps.Skipped]: SkippedStepActionBuilder,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import { getRefinanceSimulation } from '../utils/RefinanceSimulation/RefinanceSi
import { OrderPlannerService } from '../../src/implementation/OrderPlannerService'
import {
decodeActionCalldata,
SkippableActionCall,
decodePositionsManagerCalldata,
decodeStrategyExecutorCalldata,
getErrorMessage,
} from '@summerfi/testing-utils'
import assert from 'assert'
import { IUser } from '@summerfi/sdk-common/user'
import { IProtocolPluginsRegistry } from '@summerfi/protocol-plugins-common'
import { ActionCall, IProtocolPluginsRegistry } from '@summerfi/protocol-plugins-common'
import { http, createPublicClient } from 'viem'
import {
MakerPaybackAction,
Expand Down Expand Up @@ -153,7 +152,7 @@ describe('Order Planner Service', () => {
expect(flashloanCall.mapping).toEqual([0, 0, 0, 0])

/* Decode flashloan sub-calls */
const flashloanSubcalls = flashloanCall.args[0].calls as SkippableActionCall[]
const flashloanSubcalls = flashloanCall.args[0].calls as ActionCall[]

// PaybackWithdraw in Maker and DepositBorrow in Spark take 2 actions each
expect(flashloanSubcalls.length).toBe(6)
Expand Down
1 change: 1 addition & 0 deletions sdk/protocol-plugins-common/src/actions/BaseAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export abstract class BaseAction<
name: this.config.name,
targetHash,
callData: calldata,
skipped: false,
} as ActionCall
}

Expand Down
40 changes: 40 additions & 0 deletions sdk/protocol-plugins-common/src/actions/SkippedAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { BaseAction } from './BaseAction'
import { InputSlotsMapping } from '../types/InputSlotsMapping'
import { ActionCall } from './Types'
import { IAction } from '../interfaces/IAction'

export class SkippedAction extends BaseAction<typeof SkippedAction.Config> {
static Config = {
name: 'SkippedAction',
version: 0,
parametersAbi: ['()'],
storageInputs: [],
storageOutputs: [],
} as const

private _skippedAction: IAction

public constructor(skippedAction: IAction) {
super()

this._skippedAction = skippedAction
}

/* eslint-disable @typescript-eslint/no-unused-vars */
public encodeCall(paramsMapping?: InputSlotsMapping): ActionCall {
return {
name: this._skippedAction.config.name,
callData: '0x',
targetHash: this._skippedAction.getActionHash(),
skipped: true,
}
}

public get config() {
return SkippedAction.Config
}

public getVersionedName(): string {
return this._skippedAction.getVersionedName()
}
}
6 changes: 4 additions & 2 deletions sdk/protocol-plugins-common/src/actions/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ActionVersion = number
*/
export type ActionConfig = {
/** The name of the action */
readonly name: ActionNames
readonly name: ActionNames | 'SkippedAction'
/** The version of the action */
readonly version: ActionVersion
/** Human-readable ABI parameters (check `viem` documentation) */
Expand All @@ -32,11 +32,13 @@ export type ActionConfig = {
*/
export type ActionCall = {
/** Name of the action for logging */
readonly name: ActionNames
readonly name: ActionNames | 'SkippedAction'
/** The hash of the action name plus its version */
readonly targetHash: HexData
/** The call data to be sent to the smart contract */
readonly callData: HexData
/** If the action was skipped */
readonly skipped: boolean
}

/**
Expand Down
13 changes: 3 additions & 10 deletions sdk/protocol-plugins-common/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
export type {
ActionConfig,
ActionCall,
ActionCallBatch,
ActionStorageName,
ActionInputStorageNames,
ActionOutputStorageNames,
ActionVersion,
} from './Types'
export { BaseAction } from './BaseAction'
export type * from './Types'
export * from './BaseAction'
export * from './SkippedAction'
13 changes: 13 additions & 0 deletions sdk/protocol-plugins-common/src/context/StepBuilderContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ActionCallBatch, ActionConfig } from '../actions/Types'
import { ActionCallsStack } from './ActionCallsStack'
import { ExecutionStorageMapper } from './ExecutionStorageMapper'
import { TransactionInfo } from '@summerfi/sdk-common/orders'
import { SkippedAction } from '../actions/SkippedAction'

/**
* @name StepBuilderContext
Expand All @@ -33,7 +34,19 @@ export class StepBuilderContext implements IStepBuilderContext {
arguments: Parameters<Action['encodeCall']>[0]
connectedInputs: Partial<StorageInputsMapType<Step, Config>>
connectedOutputs: Partial<StorageOutputsMapType<Step, Config>>
skip?: boolean
}) {
// TODO: temporary solution until we remove the Operations Registry
if (params.skip) {
const skipAction = new SkippedAction(params.action)

this._calls.addCall({
call: skipAction.encodeCall(),
})

return
}

const paramsMapping = this._storage.addStorageMap({
step: params.step,
action: params.action,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type ActionBuilderParams<Step extends steps.Steps> = {
addressBookManager: IAddressBookManager
protocolsRegistry: IProtocolPluginsRegistry
step: Step
actionBuildersMap: ActionBuildersMap
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface IStepBuilderContext {
* will read from storage
* @param connectedOutputs The connected outputs to the action, this is the values that the action
* will write to storage
* @param skip If true, the action will be skipped and empty calldata will be added to the TX
*/
addActionCall<
Step extends steps.Steps,
Expand All @@ -38,6 +39,7 @@ export interface IStepBuilderContext {
arguments: Parameters<Action['encodeCall']>[0]
connectedInputs: Partial<StorageInputsMapType<Step, Config>>
connectedOutputs: Partial<StorageOutputsMapType<Step, Config>>
skip?: boolean
}): void

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,19 @@ export class AaveV3DepositBorrowActionBuilder extends BaseActionBuilder<steps.De
})

const borrowAmount = getValueFromReference(step.inputs.borrowAmount)

if (!borrowAmount.toBN().isZero()) {
context.addActionCall({
step: step,
action: new AaveV3BorrowAction(),
arguments: {
borrowAmount: borrowAmount,
borrowTo: await this._getBorrowTargetAddress(params),
},
connectedInputs: {},
connectedOutputs: {
borrowAmount: 'borrowedAmount',
},
})
}
context.addActionCall({
step: step,
action: new AaveV3BorrowAction(),
arguments: {
borrowAmount: borrowAmount,
borrowTo: await this._getBorrowTargetAddress(params),
},
connectedInputs: {},
connectedOutputs: {
borrowAmount: 'borrowedAmount',
},
skip: borrowAmount.toBN().isZero(),
})
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,53 @@ export class AaveV3PaybackWithdrawActionBuilder extends BaseActionBuilder<steps.

const paybackAmount = getValueFromReference(step.inputs.paybackAmount)

if (!paybackAmount.toBN().isZero()) {
context.addActionCall({
step: step,
action: new SetApprovalAction(),
arguments: {
approvalAmount: getValueFromReference(step.inputs.paybackAmount),
delegate: sparkLendingPoolAddress,
sumAmounts: false,
},
connectedInputs: {
paybackAmount: 'approvalAmount',
},
connectedOutputs: {},
})
context.addActionCall({
step: step,
action: new SetApprovalAction(),
arguments: {
approvalAmount: getValueFromReference(step.inputs.paybackAmount),
delegate: sparkLendingPoolAddress,
sumAmounts: false,
},
connectedInputs: {
paybackAmount: 'approvalAmount',
},
connectedOutputs: {},
skip: paybackAmount.toBN().isZero(),
})

context.addActionCall({
step: params.step,
action: new AaveV3PaybackAction(),
arguments: {
paybackAmount: getValueFromReference(step.inputs.paybackAmount),
paybackAll: getValueFromReference(step.inputs.paybackAmount)
.toBN()
.gt(step.inputs.position.debtAmount.toBN()),
onBehalf: Address.ZeroAddressEthereum,
},
connectedInputs: {},
connectedOutputs: {
paybackAmount: 'paybackedAmount',
},
})
}
context.addActionCall({
step: params.step,
action: new AaveV3PaybackAction(),
arguments: {
paybackAmount: getValueFromReference(step.inputs.paybackAmount),
paybackAll: getValueFromReference(step.inputs.paybackAmount)
.toBN()
.gt(step.inputs.position.debtAmount.toBN()),
onBehalf: Address.ZeroAddressEthereum,
},
connectedInputs: {},
connectedOutputs: {
paybackAmount: 'paybackedAmount',
},
skip: paybackAmount.toBN().isZero(),
})

const withdrawAmount = getValueFromReference(step.inputs.withdrawAmount)

if (!withdrawAmount.toBN().isZero()) {
context.addActionCall({
step: step,
action: new AaveV3WithdrawAction(),
arguments: {
withdrawAmount: withdrawAmount,
withdrawTo: await this._getWithdrawTargetAddress(params),
},
connectedInputs: {},
connectedOutputs: {
withdrawAmount: 'withdrawnAmount',
},
})
}
context.addActionCall({
step: step,
action: new AaveV3WithdrawAction(),
arguments: {
withdrawAmount: withdrawAmount,
withdrawTo: await this._getWithdrawTargetAddress(params),
},
connectedInputs: {},
connectedOutputs: {
withdrawAmount: 'withdrawnAmount',
},
skip: withdrawAmount.toBN().isZero(),
})
}

/**
Expand Down
Loading
Loading