Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

feat: add swap strategy#56

Merged
Wizdave97 merged 20 commits into
mainfrom
feat/filler-swap-strategy
May 25, 2025
Merged

feat: add swap strategy#56
Wizdave97 merged 20 commits into
mainfrom
feat/filler-swap-strategy

Conversation

@royvardhan

Copy link
Copy Markdown
Contributor

A swap strategy will the following rules:

  1. canFill: Only checks whether the filler has enough balance to fill the order outputs. This comparison happens in USD value only, as we later swap tokens to derive the output tokens. If the filler wallet's USD value exceeds the order outputs, we can probably fill the order.
  2. calculateProfitability: Checks what the filler will receive versus what the filler will spend with the following formula
const toReceive = outputUsdValue + order.fees // USD value
const toPay = inputUsdValue + totalGasCostUsd // USD value
const profit = toReceive - toPay
  1. executeOrder: Fills the order by deriving the missing output tokens by swapping

Comment thread packages/filler/src/services/ContractInteractionService.ts Outdated
@royvardhan royvardhan force-pushed the feat/filler-swap-strategy branch from 6dd15e9 to 5f339db Compare May 14, 2025 09:09
@royvardhan royvardhan force-pushed the feat/filler-swap-strategy branch from cd42364 to 41ccabe Compare May 19, 2025 05:26
@royvardhan royvardhan marked this pull request as ready for review May 19, 2025 05:28
Comment thread packages/filler/src/services/ContractInteractionService.ts
Comment thread packages/filler/src/strategies/swap.ts
Comment thread packages/filler/src/tests/filler.test.ts Outdated
Comment thread packages/filler/src/tests/filler.test.ts Outdated
@royvardhan royvardhan force-pushed the feat/filler-swap-strategy branch from adcebcd to 82e8a46 Compare May 20, 2025 11:32
@royvardhan royvardhan force-pushed the feat/filler-swap-strategy branch from 82e8a46 to 2687b93 Compare May 20, 2025 11:35
Comment thread packages/filler/src/services/CacheService.ts Outdated
Comment thread packages/filler/src/services/CacheService.ts Outdated
@royvardhan royvardhan force-pushed the feat/filler-swap-strategy branch from 96a9772 to 4f212d5 Compare May 20, 2025 18:25
Comment thread packages/filler/src/services/CacheService.ts
Comment thread packages/filler/src/services/ContractInteractionService.ts Outdated
@royvardhan royvardhan force-pushed the feat/filler-swap-strategy branch from da36194 to 5db23d9 Compare May 22, 2025 06:27
@royvardhan royvardhan marked this pull request as draft May 22, 2025 10:46
return { calls, totalGasEstimate }
}

// Find whether uniswap v2 or v3 is the best protocol to use based on the amountIn the filler has to pay

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not including V4 because it requires unlock patterns with IUnlockCallback that regular wallets can't handle directly. EIP-7702 workaround can be used, as the BatchExecutor contract code we are inheriting right now as an EOA can be updated. But it will add complexity to the contract.

V2/V3 already provide good liquidity coverage with simpler integration, and V3 uses the same fee structure the V4 does.

@Wizdave97 Wizdave97 May 23, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the callback affect swapping in the pool? Don't EOAs currently interact with UniV4?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes correct. If we knew the amountIn already, we could easily send v4 swap to universal router as it handles everything.

To get the amountIn through the v4 quoter, we need to call quoteExactInputSingle which is a write function. This works through callback to the caller, always ending up reverting with revert reason being the amountIn, and gasEstimate data

@royvardhan royvardhan marked this pull request as ready for review May 23, 2025 05:43
@Wizdave97 Wizdave97 merged commit f843080 into main May 25, 2025
1 check passed
@Wizdave97 Wizdave97 deleted the feat/filler-swap-strategy branch May 25, 2025 14:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants