Skip to content

JIT-funded TWAP from EOA via ComposableCowPoller#14

Open
anxolin wants to merge 3 commits into
post-twap-from-eoafrom
twap-from-eoa-jit-funding
Open

JIT-funded TWAP from EOA via ComposableCowPoller#14
anxolin wants to merge 3 commits into
post-twap-from-eoafrom
twap-from-eoa-jit-funding

Conversation

@anxolin

@anxolin anxolin commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Follow-up to #12 (TWAP from EOA), adding just-in-time funding of funds.

In #12 the full TWAP sell amount had to flow into cow-shed up front, which is capital-inefficient for TWAPs/DCA that span long periods. Here the capital stays in the user's EOA and each part is pulled just before it settles via the ComposableCowPoller contract (see cowprotocol/composable-cow#116).

How it works

  1. A minimal sell=buy order (BUY 1 wei of sDAI with sDAI) carries a gasless post-hook that, via cow-shed: approves the Vault Relayer and creates the TWAP (createWithContext, so t0 is anchored to the settlement block). The TWAP is owned by cow-shed; proceeds go back to the EOA. Now that sell==buy is supported, no extra intermediate token is needed.
  2. The EOA approves the ComposableCowPoller for the full TWAP sell amount and registers the funding schedule (register(ctx, {handler, funder: EOA, owner: cow-shed, staticInput})).
  3. Before each part settles, the watch-tower calls poller.topUp(ctx), which pulls exactly that part's sell amount from the EOA into cow-shed.

This removes both drawbacks noted in #12: it is capital-efficient, and it no longer depends on a distinct sell/buy token for the setup order.

Notes

  • topUp is left to the watch-tower (it cannot live in the TWAP's own appData: the hook embeds ctx, but ctx derives from the appData hash — a cycle).
  • Requires the cow-sdk patch from the base branch (End-end script to post TWAP from EOA #12) to be present for yarn install to patch the SDK.

Test

Requirements: set PRIVATE_KEY and RPC_URL_100 in .env; the EOA needs ≥ ~0.21 sDAI on Gnosis (0.2 TWAP + dust for the sell=buy order fee).

yarn dev   # runs postTwapForEOAWithJitFunds

Then watch the cow-shed orders in the explorer (printed by the script) as each part is funded and settled.

anxolin added 3 commits June 30, 2026 20:40
Follow-up to the TWAP-from-EOA PoC. Instead of moving the full TWAP sell
amount into cow-shed up front, each part is pulled just-in-time from the EOA
via the ComposableCowPoller contract, so capital stays in the user's wallet
between parts.

- New postTwapForEOAWithJitFunds script: a 1-wei sell=buy order carries a
  gasless post-hook that approves the Vault Relayer and creates the TWAP on
  cow-shed; the EOA approves the poller for the full sell amount and registers
  the JIT funding schedule. The watch-tower then pulls each part on demand.
- Add a minimal ComposableCowPoller contract helper and its Gnosis address.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant