Skip to content

Portfolio Protection Tool (Orchestration) #173

@premiumjibles

Description

@premiumjibles

Summary

Implement a "portfolio protection" flow that allows users to sign multiple stop-loss/limit orders in a single session, creating layered protection without repeated interactions.

Background

For effective portfolio protection, users often want multiple orders at different price levels:

  • Stop-loss at -10%
  • Stop-loss at -20%
  • Stop-loss at -30%
  • Limit buy if price drops 50% (catch the dip)

Currently, each order requires a separate conversation and signature. This ticket creates a streamlined flow for signing multiple protective orders at once.

User Flow

User: "Protect my ETH position"

Agent: "I can set up layered protection for your 10 ETH position.

📊 Suggested Protection Plan:

1. 🛡️ Stop-loss at $3,100 (-10%) - Sell 3 ETH
2. 🛡️ Stop-loss at $2,750 (-20%) - Sell 3 ETH  
3. 🛡️ Stop-loss at $2,400 (-30%) - Sell 4 ETH
4. 🎯 Limit buy at $1,700 (-50%) - Buy 2 ETH back

This protects against gradual decline while leaving upside open.

Want me to adjust any levels, or shall I prepare these orders?"

User: "Looks good, set it up"

Agent: [Prepares all 4 orders]

"I've prepared 4 orders for your protection plan.
You'll sign each one (4 signatures total, no gas fees).

[Sign All Orders]"

User: [Signs 4 times via sequential modals or batched UI]

Agent: "✅ Protection plan active!

• 3 stop-losses watching for downside
• 1 limit buy ready to catch a dip
• All expire in 30 days

Track all orders: [CoW Explorer Link]"

Implementation

1. Portfolio Protection Tool

const createProtectionPlanSchema = z.object({
  asset: assetInputSchema.describe('Asset to protect'),
  protectionLevels: z.array(z.object({
    type: z.enum(['stop-loss', 'limit-buy']),
    triggerPercent: z.number().describe('Percentage from current price'),
    amountPercent: z.number().describe('Percentage of holding to trade'),
  })).optional().describe('Custom levels, or use defaults'),
  expirationDays: z.number().optional().default(30),
})

2. Multi-Order Signing UI

interface ProtectionPlanOutput {
  orders: Array<{
    type: 'stop-loss' | 'limit-buy'
    signingData: CowOrderSigningData
    summary: OrderSummary
  }>
  totalOrders: number
  asset: string
  expiresAt: string
}

// UI Component
function ProtectionPlanCard({ plan }: { plan: ProtectionPlanOutput }) {
  const [signedCount, setSignedCount] = useState(0)
  
  return (
    <Card>
      <h3>Protection Plan for {plan.asset}</h3>
      <OrderList orders={plan.orders} signedCount={signedCount} />
      <Button onClick={signAllSequentially}>
        Sign All ({plan.totalOrders} signatures)
      </Button>
      <Progress value={signedCount} max={plan.totalOrders} />
    </Card>
  )
}

3. Default Protection Templates

const DEFAULT_PROTECTION_LEVELS = [
  { type: 'stop-loss', triggerPercent: -10, amountPercent: 30 },
  { type: 'stop-loss', triggerPercent: -20, amountPercent: 30 },
  { type: 'stop-loss', triggerPercent: -30, amountPercent: 40 },
]

const AGGRESSIVE_PROTECTION = [
  { type: 'stop-loss', triggerPercent: -5, amountPercent: 50 },
  { type: 'stop-loss', triggerPercent: -10, amountPercent: 50 },
]

const DIP_BUYER_PROTECTION = [
  { type: 'stop-loss', triggerPercent: -15, amountPercent: 100 },
  { type: 'limit-buy', triggerPercent: -40, amountPercent: 50 },
]

Acceptance Criteria

  • Agent can suggest protection plan based on user's holdings
  • User can customize protection levels or use defaults
  • Multiple orders prepared in single tool call
  • UI supports sequential signing of multiple orders
  • Progress indicator shows signing status
  • All orders tracked together as a "plan"
  • User can cancel entire plan or individual orders

Dependencies

  • SS-5290: Limit Order Tool
  • Stop-Loss Orders ticket (create first)
  • SS-5295: Long-Running Order Infrastructure

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