{"version":3,"file":"upgrade-command.mjs","names":[],"sources":["../../../src/commands/upgrade-command.ts"],"sourcesContent":["/**\n * /upgrade — Detect wallet account type and guide EOA→smart account migration.\n *\n * Usage:\n *   /upgrade         — detect account type and show status\n *   /upgrade detect  — force re-detection (bypass cache)\n *   /upgrade guide   — show migration guide for EOAs\n *\n * Account types:\n * - EOA: standard externally owned account (no code). Delegation enforcement\n *   is app-layer only. On-chain delegation requires a smart account.\n * - Smart Account: already has code (Safe, ERC-4337, etc.). Full delegation\n *   enforcement is available.\n * - EIP-7702: EOA with delegation designation. The account delegates to an\n *   implementation contract, getting smart account capabilities while keeping\n *   the same address. This is the recommended upgrade path.\n *\n * Non-breaking: EOA users continue using ClawnchConnect approval flow.\n * The command educates and guides but never auto-upgrades.\n */\n\nimport { getWalletState, detectAccountType, getWalletClient, type AccountTypeResult } from '../services/walletconnect-service.js';\nimport { isDelegationMode } from '../services/policy-types.js';\nimport { DELEGATION_CONTRACTS, CHAIN_NAMES } from '../services/delegation-types.js';\nimport type { Address } from 'viem';\n\n// MetaMask's EIP7702StatelessDeleGatorImpl — audited, deployed via CREATE2 on all chains.\n// Implements executeFromExecutor + isValidSignature for delegation framework compatibility.\n// Source: https://github.com/MetaMask/delegation-framework/blob/main/documents/Deployments.md\nconst EIP7702_DELEGATOR_IMPL = '0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B' as Address;\n\n// Per-chain override map (falls back to the universal MetaMask impl above).\nconst DELEGATOR_IMPL_OVERRIDES: Record<number, Address> = {};\n\n/** Override via env var, then per-chain map, then universal MetaMask impl. */\nfunction getDelegatorImpl(chainId: number): Address {\n  const envImpl = process.env.DELEGATOR_IMPL_ADDRESS;\n  if (envImpl?.startsWith('0x') && envImpl.length === 42) return envImpl as Address;\n  return DELEGATOR_IMPL_OVERRIDES[chainId] ?? EIP7702_DELEGATOR_IMPL;\n}\n\nexport const upgradeCommand = {\n  name: 'upgrade',\n  description: 'Account type detection & smart account upgrade: /upgrade [detect|guide|7702]',\n  acceptsArgs: true,\n  requireAuth: true,\n\n  handler: async (ctx?: any) => {\n    const args = (ctx?.args ?? '').trim().toLowerCase();\n\n    if (args === 'guide') {\n      return showMigrationGuide();\n    }\n    if (args === '7702') {\n      return handle7702Upgrade();\n    }\n\n    // Default and 'detect' both run detection\n    const force = args === 'detect';\n    return showAccountStatus(force);\n  },\n};\n\nasync function showAccountStatus(force: boolean) {\n  const wallet = getWalletState();\n\n  if (!wallet.connected || !wallet.address) {\n    return {\n      text: [\n        'No wallet connected.',\n        '',\n        'Connect a wallet first with `/connect` or set `CLAWNCHER_PRIVATE_KEY`.',\n      ].join('\\n'),\n    };\n  }\n\n  const lines: string[] = [];\n  lines.push('**Account Type Detection**');\n  lines.push('');\n\n  const result = await detectAccountType({ force });\n\n  if (!result) {\n    lines.push('Could not detect account type. Public client may not be available.');\n    lines.push('');\n    lines.push(`Address: \\`${wallet.address}\\``);\n    lines.push(`Mode: ${wallet.mode}`);\n    return { text: lines.join('\\n') };\n  }\n\n  lines.push(`Address: \\`${wallet.address}\\``);\n  lines.push(`Chain: ${CHAIN_NAMES[wallet.chainId ?? 0] ?? wallet.chainId ?? 'unknown'}`);\n  lines.push(`Mode: ${wallet.mode}`);\n  lines.push('');\n\n  switch (result.accountType) {\n    case 'eoa':\n      lines.push('Type: **EOA** (Externally Owned Account)');\n      lines.push('');\n      lines.push('Your wallet is a standard EOA with no on-chain code.');\n      if (isDelegationMode()) {\n        lines.push('');\n        lines.push('You are in delegation mode, but full on-chain enforcement requires');\n        lines.push('a smart account. Your delegations are currently signed and the agent');\n        lines.push('will attempt to redeem them, but caveat enforcers only work when the');\n        lines.push('delegator account can execute calls through the DelegationManager.');\n        lines.push('');\n        lines.push('Options:');\n        lines.push('1. **Upgrade to EIP-7702** — keep your address, gain smart account features');\n        lines.push('   Run `/upgrade guide` for step-by-step instructions');\n        lines.push('2. **Continue with app-layer enforcement** — policies are still enforced');\n        lines.push('   by the agent before execution. Use `/policymode simple` to make this explicit.');\n        lines.push('3. **Use a Smart Wallet** — connect a Safe, Coinbase Smart Wallet, or other');\n        lines.push('   ERC-4337 account that already supports delegation.');\n      } else {\n        lines.push('');\n        lines.push('In simple mode, app-layer policy enforcement works fine with an EOA.');\n        lines.push('For on-chain enforcement, switch to delegation mode with `/policymode delegation`');\n        lines.push('and consider upgrading: `/upgrade guide`');\n      }\n      break;\n\n    case 'smart_account':\n      lines.push('Type: **Smart Account** (on-chain code detected)');\n      lines.push(`Has code: yes`);\n      lines.push('');\n      lines.push('Your wallet is already a smart account. Full on-chain delegation');\n      lines.push('enforcement via EIP-7710 caveat enforcers is supported.');\n      lines.push('');\n      lines.push('The DelegationManager can execute calls through your account and');\n      lines.push('all caveats (spending limits, allowed targets, time bounds) are');\n      lines.push('enforced on-chain by the respective enforcer contracts.');\n      if (!isDelegationMode()) {\n        lines.push('');\n        lines.push('You are in simple mode. Switch to delegation mode to take advantage');\n        lines.push('of on-chain enforcement: `/policymode delegation`');\n      } else {\n        lines.push('');\n        lines.push('Use `/delegate create <policy-name>` to compile and sign delegations.');\n      }\n      break;\n\n    case 'eip7702':\n      lines.push('Type: **EIP-7702** (delegation designation detected)');\n      lines.push(`Has code: yes`);\n      if (result.delegationDesignation) {\n        lines.push(`Delegates to: \\`${result.delegationDesignation}\\``);\n      }\n      lines.push('');\n      lines.push('Your EOA has an EIP-7702 delegation designation. It retains its');\n      lines.push('original address but gains smart account capabilities through the');\n      lines.push('designated implementation contract.');\n      lines.push('');\n      lines.push('Full on-chain delegation enforcement via EIP-7710 is supported.');\n      lines.push('Caveat enforcers (spending limits, allowed targets, time bounds)');\n      lines.push('are enforced on-chain by the DelegationManager.');\n      if (!isDelegationMode()) {\n        lines.push('');\n        lines.push('Switch to delegation mode: `/policymode delegation`');\n      } else {\n        lines.push('');\n        lines.push('Use `/delegate create <policy-name>` to compile and sign delegations.');\n      }\n      break;\n  }\n\n  if (force) {\n    lines.push('');\n    lines.push('(Cache refreshed — detection was re-run against the chain.)');\n  }\n\n  return { text: lines.join('\\n') };\n}\n\nfunction showMigrationGuide() {\n  const lines: string[] = [];\n\n  lines.push('**EOA to Smart Account — Migration Guide**');\n  lines.push('');\n  lines.push('To use on-chain delegation enforcement (EIP-7710), your wallet needs');\n  lines.push('smart account capabilities. Here are your options:');\n  lines.push('');\n  lines.push('---');\n  lines.push('');\n  lines.push('**Option 1: EIP-7702 Upgrade (Recommended)**');\n  lines.push('');\n  lines.push('EIP-7702 lets your existing EOA delegate to a smart account implementation');\n  lines.push('without changing your address. Your EOA gains smart account features');\n  lines.push('(batched calls, delegation, session keys) while keeping all existing');\n  lines.push('balances, approvals, and history.');\n  lines.push('');\n  lines.push('How it works:');\n  lines.push('1. Sign an EIP-7702 authorization designating an implementation contract');\n  lines.push('2. Submit a type-4 transaction that sets your account\\'s code to `0xef0100` + implementation address');\n  lines.push('3. Your EOA now executes calls through the implementation\\'s logic');\n  lines.push('4. Reversible: you can clear the designation to revert to a plain EOA');\n  lines.push('');\n  lines.push('Supported implementations:');\n  lines.push('- **MetaMask Delegation Framework** — the implementation used by openclawnch');\n  lines.push('  DelegationManager: `' + DELEGATION_CONTRACTS.DelegationManager + '`');\n  lines.push('- **Coinbase Smart Wallet** — ERC-4337 + EIP-7702 compatible');\n  lines.push('- **Safe{Core}** — modular smart account with EIP-7702 support (v1.5+)');\n  lines.push('');\n  lines.push('Requirements:');\n  lines.push('- Wallet must support EIP-7702 signing (MetaMask 12.8+, Rabby, etc.)');\n  lines.push('- Chain must support EIP-7702 (Ethereum mainnet post-Pectra, Base, etc.)');\n  lines.push('');\n  lines.push('---');\n  lines.push('');\n  lines.push('**Option 2: Deploy a Smart Wallet**');\n  lines.push('');\n  lines.push('Create a new smart account and transfer assets to it:');\n  lines.push('- **Safe** — multisig with delegation module (safe.global)');\n  lines.push('- **Coinbase Smart Wallet** — ERC-4337 account (keys.coinbase.com)');\n  lines.push('- **Kernel** — lightweight ERC-4337 account (zerodev.app)');\n  lines.push('');\n  lines.push('This gives you a new address. You\\'ll need to transfer assets and');\n  lines.push('re-approve contracts on the new address.');\n  lines.push('');\n  lines.push('---');\n  lines.push('');\n  lines.push('**Option 3: Stay on EOA (App-Layer Only)**');\n  lines.push('');\n  lines.push('Continue using your EOA with app-layer policy enforcement:');\n  lines.push('- Policies are evaluated by the agent before each action');\n  lines.push('- ClawnchConnect prompts for wallet approval on each transaction');\n  lines.push('- No on-chain enforcement, but still functional and safe');\n  lines.push('- Use `/policymode simple` to make this explicit');\n  lines.push('');\n  lines.push('---');\n  lines.push('');\n  lines.push('Run `/upgrade` to check your current account type.');\n\n  return { text: lines.join('\\n') };\n}\n\n// ─── EIP-7702 Upgrade ───────────────────────────────────────────────────\n\nasync function handle7702Upgrade() {\n  const wallet = getWalletState();\n  const lines: string[] = [];\n\n  if (!wallet.connected || !wallet.address) {\n    return { text: 'No wallet connected. Connect with `/connect` or set `CLAWNCHER_PRIVATE_KEY` first.' };\n  }\n\n  if (wallet.mode !== 'private_key') {\n    lines.push('**EIP-7702 Upgrade — Requires Private Key Mode**');\n    lines.push('');\n    lines.push('`signAuthorization` requires direct private key access.');\n    lines.push('WalletConnect wallets must use their own 7702 UI (MetaMask 12.8+, Rabby).');\n    lines.push('');\n    lines.push('1. Switch to private key mode and run `/upgrade 7702` again');\n    lines.push('2. Use your wallet\\'s native EIP-7702 support');\n    lines.push('3. Deploy a Smart Wallet — see `/upgrade guide`');\n    return { text: lines.join('\\n') };\n  }\n\n  const acctType = await detectAccountType({ force: true });\n  if (acctType?.accountType === 'smart_account' || acctType?.accountType === 'eip7702') {\n    lines.push('**Already a Smart Account**');\n    lines.push(`Type: ${acctType.accountType}`);\n    if (acctType.delegationDesignation) {\n      lines.push(`Delegates to: \\`${acctType.delegationDesignation}\\``);\n    }\n    lines.push('No upgrade needed. Use `/delegate create <policy>` to start.');\n    return { text: lines.join('\\n') };\n  }\n\n  const chainId = wallet.chainId ?? 0;\n  const impl = getDelegatorImpl(chainId);\n\n  lines.push('**EIP-7702 Upgrade**');\n  lines.push('');\n  lines.push(`Address: \\`${wallet.address}\\``);\n  lines.push(`Chain: ${CHAIN_NAMES[chainId] ?? chainId}`);\n  lines.push(`Implementation: \\`${impl}\\``);\n  lines.push('');\n\n  try {\n    const wc = getWalletClient();\n    if (!wc) return { text: 'Wallet client not available.' };\n\n    lines.push('Signing EIP-7702 authorization...');\n    const authorization = await (wc as any).signAuthorization({ contractAddress: impl });\n\n    lines.push('Submitting type-4 transaction...');\n    const txHash = await (wc as any).sendTransaction({\n      to: wallet.address, value: 0n, authorizationList: [authorization],\n    });\n    lines.push(`Transaction: \\`${txHash}\\``);\n\n    const updated = await detectAccountType({ force: true });\n    lines.push('');\n    if (updated?.accountType === 'eip7702') {\n      lines.push('**Upgrade successful.**');\n      lines.push(`Implementation: \\`${updated.delegationDesignation ?? impl}\\``);\n      lines.push('Next: `/policymode delegation` then `/delegate create <policy>`');\n    } else if (updated?.accountType === 'smart_account') {\n      lines.push('**Upgrade successful.** Detected as smart account.');\n    } else {\n      lines.push('Transaction confirmed. Run `/upgrade detect` to verify.');\n    }\n  } catch (err) {\n    const msg = err instanceof Error ? err.message : String(err);\n    if (msg.includes('not supported') || msg.includes('invalid type') || msg.includes('unknown type')) {\n      lines.push(`**${CHAIN_NAMES[chainId] ?? 'This chain'} does not support EIP-7702.**`);\n      lines.push('Requires the Pectra hard fork. See `/upgrade guide` for alternatives.');\n    } else {\n      lines.push(`**Upgrade failed:** ${msg.slice(0, 200)}`);\n    }\n  }\n\n  return { text: lines.join('\\n') };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,yBAAyB;AAG/B,MAAM,2BAAoD,EAAE;;AAG5D,SAAS,iBAAiB,SAA0B;CAClD,MAAM,UAAU,QAAQ,IAAI;AAC5B,KAAI,SAAS,WAAW,KAAK,IAAI,QAAQ,WAAW,GAAI,QAAO;AAC/D,QAAO,yBAAyB,YAAY;;AAG9C,MAAa,iBAAiB;CAC5B,MAAM;CACN,aAAa;CACb,aAAa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