Architecture

How the contracts fit together, and how funds and permissions move through the system.

The short version

Each user gets a private account (a cheap clone) that holds their USDC. A factory creates these accounts and stores protocol settings. A separate executor pools many accounts' buys into one swap, routed through a swap adapter, with an on-chain price oracle guarding the minimum output. A timelock owns the administrative contracts. Funds only flow through permissioned paths: the design keeps user accounts isolated while letting execution be shared and gas-efficient.

Design principles

Three principles shape every structural choice:

Isolated custody, pooled execution
Each user's funds live in their own account contract - never commingled in a shared pool. But execution is batched: many accounts buying the same asset are combined into a single swap. You get isolation for safety and pooling for efficiency.
Least privilege for automation
The executor can trigger a scheduled buy, and pause a due strategy that can no longer fund it, and nothing else. It cannot withdraw, cannot change parameters, and cannot pull more than the per-period amount from any account.
EVM-agnostic, no hardcoded addresses
No external address is baked into contract logic. Everything - tokens, routers, pools, Aave - is injected at deploy time from per-chain config. Replicating the protocol on another EVM chain requires config, not code changes.

Contract topology

There are three families of contracts: the user layer (factory + per-user accounts + yield), the execution layer (executor + router + swap adapters), and the oracle layer (the price floor). The factory and executor are deployed once; user accounts are minted per strategy as minimal proxies (clones), which makes creating a strategy cheap.

How the contracts fit together Governance: a TimelockController owns the factory, batch executor, swap router and oracles, and every change waits two days in public; a guardian Safe can act instantly only to pause, replace the keeper and flush retained fees, and it is also the party that proposes and executes timelock changes, after the delay. Custody: DCAFactory clones one UserStrategyAccount per strategy; each account holds its strategy's USDC, can be pulled from only by the batch executor and withdrawn only by you, and optionally uses its own AaveV3YieldAdapter clone to supply Aave V3. Execution: the keeper calls BatchExecutor, which pulls from accounts and returns output to them, swaps through SwapRouter and UniswapV3Adapter on Uniswap V3, and asks OracleDispatcher for the price floor. OracleDispatcher routes WETH and cbBTC to ChainlinkPriceOracle; ComposedPriceOracle is deployed with no asset routed to it. GOVERNANCE TimelockController Owns the factory, batch executor, swap router and oracles. Every change waits two days, in public. Guardian Safe Instant: pause, replace the keeper, flush retained fees to the treasury. Also drives the timelock, at its delay. CUSTODY EXECUTION DCAFactory Creates accounts, keeps the registry and fee settings Keeper Off-chain automation, replaceable clones, one per strategy executeBatch UserStrategyAccount Holds one strategy's USDC. Only the batch executor can pull; only you can withdraw. BatchExecutor Pull, fee, floor, swap, split its own adapter only swap AaveV3YieldAdapter Optional clone per account. Supplies to Aave V3. SwapRouter Picks the adapter for each asset router only UniswapV3Adapter Trades on Uniswap V3 pools PRICE FLOOR OracleDispatcher Routes each asset to its oracle. No price logic. ChainlinkPriceOracle WETH and cbBTC. Direct USD feeds, sequencer check. quoteMinOut ComposedPriceOracle Deployed. No asset is routed to it.

Three deployed singletons (Factory, BatchExecutor, SwapRouter) plus per-strategy account clones, a swap adapter routed per asset, the oracles and the governance pair. Violet marks the account that holds your funds; cyan marks a contract that talks to an outside protocol. The double arrow is USDC pulled one way and the purchased asset returned the other. The oracle layer is detailed on the Price oracle page.

The deposit-to-buy lifecycle

Following the money end-to-end is the clearest way to understand the system.

User-facing versionThis section explains the architecture behind the flow. If you want the product journey first - including what transactions the app asks you to sign and what happens when something fails - start with User flows.
Where your money is at every step USDC moves from your wallet into your own strategy account, which can park it in Aave V3 if you chose yield. On schedule, the batch executor pulls your scheduled amount plus any yield fee owed; it moves funds within that one transaction and keeps nothing except a share or fee it could not deliver. Fees go to the treasury in USDC. The net USDC is swapped on Uniswap V3 through the swap router, the batch executor splits the output by contribution, and your account forwards your share to your wallet. If the token refuses delivery to your account, the batch executor holds your share for you to claim; if the last hop to your wallet fails, your account keeps it as pending for you to claim. Withdrawing returns all remaining USDC to your wallet, after the yield fee on yield not yet charged. Your wallet USDC deposit Your strategy account Holds your USDC. Only your wallet can withdraw it. Aave V3 optional idle yield scheduled amount, plus the yield fee on any yield it spends Batch executor Moves funds within one transaction. Keeps only what it could not deliver. Treasury fees, in USDC net USDC Swap router One pooled swap, held to the oracle floor Uniswap V3 the market WETH or cbBTC Batch executor Splits the output by contribution Held for you if the token refuses your account. Claim it to any address. your share Your strategy account Forwards it on arrival Pending if this hop fails. Claim with withdrawPending WETH or cbBTC Your wallet Your asset ANYTIME Withdraw Your account pulls back any Aave position, pays the treasury the yield fee on yield not yet charged, sends every remaining USDC to your wallet and closes. No protocol pause blocks it.

Each box is who holds the money at that moment; each arrow is what moves. Violet is yours, cyan is an outside protocol, yellow is the fee recipient, green is a fallback that keeps your output claimable.

1 - Create & deposit

A user calls DCAFactory.createStrategy(...) with their choices: target asset, amount per execution, frequency tier, and whether to enable Aave yield. The strategy owner is not one of those choices: the factory takes it from the caller, so the account always belongs to the wallet that created it. The factory clones a UserStrategyAccount and initializes it. The user then calls deposit(amount) on their account. On the first deposit, the account registers itself in the factory's active registry and (if yield is on) supplies the USDC to Aave.

2 - Off-chain: find who is due

The executor periodically reads DCAFactory.getDueFundedAccounts(tier, windowStart, cursor, limit), a free view call returning a bounded page of accounts that are due and able to fund one execution. It groups them by target asset and computes each account's per-period amount. This selection happens off-chain; the chain only validates.

The view has no authority over execution. Funding can change between selection and the batch landing, so the contracts stay tolerant of an account that turns out to pay nothing. A raw getDueAccounts query remains alongside it as a monitoring surface, precisely because a strategy that is persistently due but unable to pay is deliberately absent from the funded selector and would otherwise be invisible.

3 - On-chain: execute the batch

The executor calls BatchExecutor.executeBatch(accounts, amounts, targetAsset, minAmountOut, nonce). The executor is the only address allowed to call this. Inside, in order:

  1. Structural checks: asset is whitelisted, oracle is configured, nonce unused, minAmountOut > 0.
  2. Pull: for each account, authorisedPull moves exactly that account's per-period USDC, plus the yield fee on any yield it spends, which goes to the treasury and is never swapped. Accounts that cannot pay are skipped, not failed; each account also verifies the batch's targetAsset matches its own target. The batch totals used downstream are accumulated here from what was actually pulled, so the executor submits no total it could overstate.
  3. Fee: the execution fee is computed on the USDC collected and set aside, so only the net amount continues. Everything downstream sizes itself on that net amount: what is not swapped cannot be bought, quoted against, or distributed.
  4. Floor: the price oracle returns an independent minimum output for the net amount; the effective minimum is max(executor's adjusted min, oracle min). The executor can only make slippage stricter.
  5. Swap: one pooled swap through SwapRouter into the target asset, with the returned amount re-checked against the same minimum afterwards, because the router is a trust boundary.
  6. Distribute: the entire output is split pro-rata to each account, with the last account absorbing any rounding dust so nothing is stranded. A share the token refuses to deliver is held for that account's owner to claim, so one frozen recipient cannot revert everyone's buy. The USDC fees are transferred to the treasury after the swap, so a reverting swap cannot leave a fee already banked.
Many accounts, one swap, split by contribution Illustrative numbers. Account A contributes 25 USDC, B 50 and C 25, so the batch pulls 100 USDC. The execution fee, 0.15 USDC, goes to the treasury in USDC, and 99.85 USDC is swapped in one trade that returns 1,001 units of the asset. A receives 25 percent rounded down, 250 units; B receives 50 percent rounded down, 500 units; C, the last account, receives the remainder, 1,001 minus 750, which is 251 units. Nothing is left in the batch executor. Account A 25 USDC Account B 50 USDC Account C 25 USDC One batch: 100 USDC pulled · Execution fee: 0.15 USDC, to the treasury in USDC · Swapped: 99.85 USDC, in one trade · Out: 1,001 units of the asset 250 units 25% of 1,001, rounded down 500 units 50% of 1,001, rounded down 251 units Last account: the rest, 1,001 minus 750 Nothing stays in the batch executor.

Illustrative numbers at the current 0.15% execution fee. Shares are computed on what each account actually contributed, and the last account takes whatever rounding leaves.

Important propertyThe BatchExecutor distributes everything it pulls and swaps, keeping none of the funds it moves; a refused share is held for its owner, not kept. Because the fee is taken in USDC, the distribution step has no fee term at all: every unit of the purchased asset belongs to the accounts that paid for it.

4 - Receive & withdraw

Each account's receiveOutput forwards the purchased asset to the strategy owner. If that transfer fails, the amount is safely held in pendingWithdrawals for the user to claim. The user can call withdraw() at any time to take their full balance and close the strategy; this works even when the protocol is paused.

Permission flow - who may call what

Every privileged edge is locked down. The list below shows the only permitted callers of each sensitive entry point.

Who can do what, and what nobody can do Five roles. You, the strategy owner: create, fund, pause, resume, withdraw even while paused and claim held or pending output; you cannot change a strategy after creation. The keeper: triggers due batches and can pause a due strategy that cannot fund its next buy; it cannot withdraw or redirect funds, pull early or more than the scheduled amount, choose who receives output, or lower the oracle floor. The guardian, a 2-of-3 Safe acting instantly: pauses and unpauses, replaces the keeper address, pays retained fees to the treasury, and proposes, executes or cancels timelock changes, which still wait two days; it cannot touch a balance, block a withdrawal, or change configuration without the delay. The owner, a timelock with a two-day public delay: sets capped fees, treasury, router, oracle, assets and yield venues, replaces the guardian and recovers stray tokens; it cannot withdraw from your account, change your strategy, pause, replace the keeper, skip the delay, or take held output or retained fees. The treasury only receives fees. Only your wallet can withdraw your funds, nobody can change your strategy's settings, and no protocol pause blocks your withdrawal. STRATEGY OWNER You createStrategy deposit pause resume withdraw withdrawPending claimHeldOutput reconcileFunding CAN CANNOT · Create and fund strategies · Pause and resume yours · Withdraw everything, even while paused · Claim held or pending output · Change a strategy after creation. Withdraw and create a new one instead. AUTOMATION Keeper executeBatch reconcileFunding CAN CANNOT · Trigger a due batch · Pause a due strategy that cannot fund its next buy · Withdraw or redirect funds · Pull early, or more than the scheduled amount · Choose who receives the output · Lower the oracle floor 2-OF-3 SAFE, INSTANT Guardian pause unpause setExecutor flushFees CAN CANNOT · Pause or unpause creation and execution · Replace the keeper address · Pay retained fees to the treasury · Propose, execute or cancel timelock changes, which still wait two days · Touch any user balance · Block a withdrawal · Change fees, routing, the oracle, assets or itself without the delay TIMELOCK, 2-DAY DELAY Owner every other setter, setGuardian, rescueTokens CAN CANNOT · Set fees within hard caps: 1% per buy, 30% of yield · Set the treasury, router, oracle, assets and yield venues · Replace the guardian · Recover tokens sent to the batch executor by mistake · Withdraw from your account · Change your strategy's settings · Pause, or replace the keeper · Skip the two-day delay · Take held output or retained fees SAFE, FEES ONLY Treasury receives transfers only CAN CANNOT · Receive the execution fee and yield fee, in USDC · Touch strategy funds or settings Only your wallet can withdraw your funds. Nobody can change your strategy's settings. No protocol pause blocks your withdrawal.

The grey line under each role names the entry points it may call. Contract-to-contract calls are locked the same way: authorisedPull and receiveOutput answer only the BatchExecutor (and a pull never exceeds the account's amount per execution plus the yield fee on yield it spends), SwapRouter.swap answers only the BatchExecutor, an adapter's swap answers only the SwapRouter, and a yield adapter answers only the account that owns it. createStrategy is open to anyone while the factory is not paused. Anything that could redirect funds sits behind the timelock's two-day public delay; the guardian's instant powers cannot change routing or touch a balance. The security page explains the limits.

What this architecture optimizes for

The system intentionally separates custody, execution, routing, and pricing. That separation creates a few practical user outcomes:

  • Your account holds your funds. The factory creates strategies but does not custody deposits.
  • Execution can be pooled without pooling custody. Many users can share one swap while their balances remain isolated.
  • The executor has a narrow job. It can trigger a due batch, but each account and the BatchExecutor validate the requested action.
  • External dependencies are replaceable by configuration. A future chain, keeper, oracle, router, or yield source should require config or adapters rather than rewriting the core custody model.

The trade-off is that operators must configure those dependencies correctly. The trust and failure assumptions are covered in Trust & failures.

Why clones?

Each UserStrategyAccount is an EIP-1167 minimal proxy pointing at one shared implementation. Deploying a full contract per user would be prohibitively expensive; a clone costs a fraction of the gas. The implementation's constructor calls _disableInitializers() so the logic contract itself can never be initialized or hijacked - only clones are initialized, exactly once.

Frequency tiers

Strategies run on one of four fixed schedules, anchored to absolute time windows rather than each user's signup moment. This lets many users share a window and therefore a batch.

TierFrequencyAnchor (UTC)
0Daily00:00 every day
1Weekly00:00 every Monday
2BiWeekly00:00, 14-day epochs anchored to 1970-01-05
3Monthly00:00 on the 1st