Skip to content

3: DCA Tool (Dollar Cost Averaging) #155

@premiumjibles

Description

@premiumjibles

Summary

Implement DCA using Mean Finance protocol. No smart wallet required - works with regular EOAs.

Background

DCA automates recurring purchases (e.g., "$100 of ETH every week"). Mean Finance is a non-custodial DCA protocol that works with standard EOA wallets via EIP-712 signatures.

Third-Party API

User Flow

User: "I want to DCA into ETH, $200 per week for 3 months"

Agent: "I'll set up a DCA position for you:

📅 DCA Plan

  • Buy: ETH
  • Amount: $200 per week
  • Duration: 12 weeks (3 months)
  • Total: $2,400 USDC

You'll need to approve $2,400 USDC upfront.

Mean Finance executes purchases automatically -

you don't pay gas on each swap.

Ready to set this up?"

User: "Yes"

Agent: [Creates position]

"✅ DCA position created!

Your $200/week ETH purchases will execute automatically.

First purchase: Within 24 hours

Track progress: [Mean Finance Link]

Tip: You can cancel anytime and withdraw remaining funds."

Tool Schema

const createDcaSchema = z.object({

sellAsset: z.string().describe('Asset to spend (usually stablecoin)'),
buyAsset: z.string().describe('Asset to accumulate'),
amountPerInterval: z.string().describe('Amount to spend each interval'),
intervalUnit: z.enum(['hour', 'day', 'week', 'month']),
totalIntervals: z.number().describe('Number of purchases to make'),
network: z.string().describe('Network for DCA (ethereum, optimism, arbitrum, polygon)'),

})

const getDcaPositionsSchema = z.object({

status: z.enum(['active', 'completed', 'terminated', 'all']).optional(),

})

const terminateDcaSchema = z.object({

positionId: z.string(),
withdrawRemaining: z.boolean().default(true),

})

Tool Output

interface CreateDcaOutput {

success: boolean
positionId: string
positionUrl: string // Mean Finance dashboard
summary: {
  sellAsset: { symbol: string; totalAmount: string }
  buyAsset: { symbol: string }
  amountPerInterval: string
  interval: string // "weekly", "daily", etc.
  totalIntervals: number
  startDate: string
  endDate: string
  totalCost: string
}
approvalTx?: TransactionData // If approval needed
createPositionTx: TransactionData

}

interface GetDcaPositionsOutput {

positions: Array<{
  positionId: string
  status: 'active' | 'completed' | 'terminated'
  sellAsset: { symbol: string; remaining: string; spent: string }
  buyAsset: { symbol: string; accumulated: string }
  progress: { completed: number; total: number }
  nextExecution: string | null
  positionUrl: string
}>

}

UI Card

┌─────────────────────────────────────────────┐

│ 📈 DCA Position [Active] │

├─────────────────────────────────────────────┤

│ Buying ETH with USDC │

│ │

│ Progress: 4 of 12 weeks complete │

│ ████████░░░░░░░░░░░░░░░░ 33% │

│ │

│ Spent: $800 USDC │

│ Accumulated: 0.31 ETH │

│ Avg Price: $2,580 │

│ │

│ Next purchase: Dec 16, 2025 │

│ │

│ [Terminate Early] [View on Mean Finance →] │

└─────────────────────────────────────────────┘

Implementation Notes

  • User approves total amount upfront (e.g., $2,400 for 12 weeks)
  • Mean Finance keepers execute each interval's swap
  • User pays gas only on position creation/termination
  • 0.6% fee per swap (taken by Mean)
  • Supports Ethereum, Optimism, Arbitrum, Polygon

Acceptance Criteria

  • Create DCA positions on supported networks
  • Query user's active/completed positions
  • Terminate positions early (withdraw remaining)
  • UI card shows progress, accumulated amount, avg price
  • Agent can explain position status
  • Activity panel integration

Files to Create/Modify

  • packages/server/src/tools/dca/createDca.ts
  • packages/server/src/tools/dca/getDcaPositions.ts
  • packages/server/src/tools/dca/terminateDca.ts
  • packages/server/src/lib/meanFinance/ - Mean Finance SDK
  • apps/agentic-chat/src/components/tools/DcaUI.tsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions