Skip to content

Move scheduled swap price calculation from registration to execution time #11

@johnson86tw

Description

@johnson86tw

Currently, swap parameters (sqrtPriceLimitX96, amountOutMinimum, fee) are calculated at job registration time and encoded into the UserOp. When the backend executes scheduled swaps later, these parameters are often stale due to price fluctuations, causing swap failures.

const { sqrtPriceLimitX96, amountOutMinimum, fee } = await getSwapParameters(client, swapParams)
execution = {
to: ADDRESS.ScheduledOrders,
value: 0n,
data: INTERFACES.ScheduledOrders.encodeFunctionData('executeOrder', [
jobId,
sqrtPriceLimitX96,
amountOutMinimum,
fee,
]),
}

Current Flow

  1. User schedules swap → calculates price parameters with current market data
  2. Backend stores UserOp with encoded parameters
  3. Backend executes UserOp later → parameters may be outdated → swap fails

Proposed Solution

Move price-sensitive parameter calculation to execution time:

  1. Registration: Store swap intent (tokens, amount, user preferences) instead of exact parameters
  2. Execution: Backend calculates fresh price parameters using current market data
  3. Safety: Preserve user-defined minimum output amount as absolute floor

Files to modify

  • src/lib/scheduling/registerJob.ts - Remove price calculation from registration
  • SAManaber-backend - Add logic to calculate fresh parameters at execution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions