{
  "feature": "stablecoin-wallet-api",
  "version": "1.0.0",
  "description": "Stablecoin wallet infrastructure API — multi-chain wallets, addresses, deposits, withdrawals, swaps, gateway, checkout, and fiat offramp",
  "category": "integration",
  "tags": [
    "blockchain",
    "stablecoin",
    "crypto",
    "wallet",
    "api",
    "payments",
    "defi",
    "fintech"
  ],
  "actors": [
    {
      "id": "client_application",
      "name": "Client Application",
      "type": "system",
      "description": "The fintech application integrating with Blockradar via REST API",
      "role": "api-consumer"
    },
    {
      "id": "wallet_platform",
      "name": "Wallet Infrastructure Platform",
      "type": "external",
      "description": "Stablecoin wallet infrastructure that orchestrates multi-chain operations",
      "role": "platform"
    },
    {
      "id": "blockchain_network",
      "name": "Blockchain Network",
      "type": "external",
      "description": "Underlying blockchain networks (Ethereum, BSC, Polygon, Base, Tron, Solana, etc.)",
      "role": "settlement"
    }
  ],
  "fields": [
    {
      "name": "api_key",
      "type": "token",
      "required": true,
      "label": "API Key",
      "sensitive": true
    },
    {
      "name": "wallet_id",
      "type": "token",
      "required": true,
      "label": "Master Wallet ID",
      "immutable": true
    },
    {
      "name": "blockchain",
      "type": "text",
      "required": true,
      "label": "Blockchain Network"
    },
    {
      "name": "network",
      "type": "select",
      "required": true,
      "label": "Environment",
      "options": [
        {
          "value": "testnet",
          "label": "Testnet"
        },
        {
          "value": "mainnet",
          "label": "Mainnet"
        }
      ]
    },
    {
      "name": "webhook_url",
      "type": "url",
      "required": true,
      "label": "Webhook URL"
    },
    {
      "name": "address_id",
      "type": "token",
      "required": false,
      "label": "Address ID"
    },
    {
      "name": "address",
      "type": "text",
      "required": false,
      "label": "Blockchain Address"
    },
    {
      "name": "address_name",
      "type": "text",
      "required": false,
      "label": "Address Name"
    },
    {
      "name": "disable_auto_sweep",
      "type": "boolean",
      "required": false,
      "label": "Disable Auto Sweep",
      "default": false
    },
    {
      "name": "enable_gasless_withdraw",
      "type": "boolean",
      "required": false,
      "label": "Enable Gasless Withdraw",
      "default": false
    },
    {
      "name": "show_private_key",
      "type": "boolean",
      "required": false,
      "label": "Show Private Key",
      "default": false
    },
    {
      "name": "metadata",
      "type": "json",
      "required": false,
      "label": "Custom Metadata"
    },
    {
      "name": "blockchain_id",
      "type": "token",
      "required": false,
      "label": "Blockchain UUID"
    },
    {
      "name": "blockchain_slug",
      "type": "text",
      "required": false,
      "label": "Blockchain Slug"
    },
    {
      "name": "is_evm_compatible",
      "type": "boolean",
      "required": false,
      "label": "EVM Compatible"
    },
    {
      "name": "token_standard",
      "type": "text",
      "required": false,
      "label": "Token Standard"
    },
    {
      "name": "derivation_path",
      "type": "text",
      "required": false,
      "label": "BIP44 Derivation Path"
    },
    {
      "name": "wallet_status",
      "type": "select",
      "required": false,
      "label": "Wallet Status",
      "options": [
        {
          "value": "ACTIVE",
          "label": "Active"
        }
      ]
    },
    {
      "name": "asset_id",
      "type": "token",
      "required": true,
      "label": "Asset ID"
    },
    {
      "name": "amount",
      "type": "text",
      "required": true,
      "label": "Amount",
      "validation": [
        {
          "type": "required",
          "message": "Amount is required"
        }
      ]
    },
    {
      "name": "destination_address",
      "type": "text",
      "required": false,
      "label": "Destination Address"
    },
    {
      "name": "reference",
      "type": "text",
      "required": false,
      "label": "Internal Reference"
    },
    {
      "name": "note",
      "type": "text",
      "required": false,
      "label": "Note"
    },
    {
      "name": "transaction_hash",
      "type": "text",
      "required": false,
      "label": "Transaction Hash"
    },
    {
      "name": "currency",
      "type": "select",
      "required": false,
      "label": "Fiat Currency",
      "options": [
        {
          "value": "NGN",
          "label": "Nigerian Naira"
        },
        {
          "value": "KES",
          "label": "Kenyan Shilling"
        },
        {
          "value": "TZS",
          "label": "Tanzanian Shilling"
        },
        {
          "value": "UGX",
          "label": "Ugandan Shilling"
        },
        {
          "value": "BRL",
          "label": "Brazilian Real"
        },
        {
          "value": "MWK",
          "label": "Malawian Kwacha"
        }
      ]
    },
    {
      "name": "account_identifier",
      "type": "text",
      "required": false,
      "label": "Bank Account Number"
    },
    {
      "name": "institution_identifier",
      "type": "text",
      "required": false,
      "label": "Bank/Institution Identifier"
    },
    {
      "name": "gateway_balance",
      "type": "number",
      "required": false,
      "label": "Unified USDC Gateway Balance"
    },
    {
      "name": "settlement_rule_name",
      "type": "text",
      "required": false,
      "label": "Settlement Rule Name"
    },
    {
      "name": "slippage_tolerance",
      "type": "text",
      "required": false,
      "label": "Slippage Tolerance (%)"
    },
    {
      "name": "settlement_order",
      "type": "select",
      "required": false,
      "label": "Execution Priority",
      "options": [
        {
          "value": "FASTEST",
          "label": "Fastest"
        },
        {
          "value": "CHEAPEST",
          "label": "Cheapest"
        },
        {
          "value": "RECOMMENDED",
          "label": "Recommended"
        },
        {
          "value": "NO_SLIPPAGE",
          "label": "No Slippage"
        }
      ]
    },
    {
      "name": "payment_link_id",
      "type": "token",
      "required": false,
      "label": "Payment Link ID"
    },
    {
      "name": "payment_link_url",
      "type": "url",
      "required": false,
      "label": "Payment Link URL"
    },
    {
      "name": "message",
      "type": "text",
      "required": false,
      "label": "Message to Sign",
      "validation": [
        {
          "type": "maxLength",
          "value": 4096,
          "message": "Message must not exceed 4,096 characters"
        }
      ]
    }
  ],
  "states": {
    "field": "transaction_status",
    "values": [
      {
        "id": "pending",
        "label": "Pending",
        "initial": true
      },
      {
        "id": "processing",
        "label": "Processing"
      },
      {
        "id": "success",
        "label": "Success",
        "terminal": true
      },
      {
        "id": "failed",
        "label": "Failed",
        "terminal": true
      },
      {
        "id": "incomplete",
        "label": "Incomplete"
      },
      {
        "id": "cancelled",
        "label": "Cancelled",
        "terminal": true
      }
    ],
    "transitions": [
      {
        "from": "pending",
        "to": "processing",
        "actor": "blockradar",
        "description": "Transaction accepted and being processed"
      },
      {
        "from": "processing",
        "to": "success",
        "actor": "blockchain_network",
        "description": "Transaction confirmed on the blockchain"
      },
      {
        "from": "processing",
        "to": "failed",
        "actor": "blockchain_network",
        "description": "Transaction failed or was rejected"
      },
      {
        "from": "pending",
        "to": "cancelled",
        "actor": "client_application",
        "description": "Transaction cancelled before processing"
      },
      {
        "from": "processing",
        "to": "incomplete",
        "actor": "blockradar",
        "description": "Transaction requires additional steps"
      }
    ]
  },
  "rules": {
    "authentication": {
      "api_key_header": "x-api-key",
      "api_key_required": "All API operations require the x-api-key header",
      "separate_keys": "Use separate API keys for testnet and mainnet environments"
    },
    "wallets": {
      "one_per_chain": "Only one Master Wallet per blockchain network per account",
      "environment_isolation": "Wallets created in live are isolated from test, and vice versa",
      "fund_native_token": "Master wallet must hold native blockchain tokens (ETH, BNB, MATIC, etc.) for gas fees",
      "evm_address_sharing": "Addresses from one EVM wallet can receive deposits on other EVM-compatible chains (isEvmCompatible: true)"
    },
    "auto_sweep": {
      "default_enabled": true,
      "default_threshold": 0,
      "address_override": "Address-level settings override master wallet configuration"
    },
    "gasless": {
      "default_enabled": false,
      "threshold_operators": [
        "gt",
        "gte",
        "lt",
        "lte",
        "eq"
      ],
      "address_override": "Address-level settings override master wallet configuration"
    },
    "withdrawals": {
      "batch_max": 20,
      "batch_min": 1,
      "amount_positive": "Amount must be greater than 0"
    },
    "gateway": {
      "usdc_only": "Gateway only supports USDC for cross-chain operations",
      "no_direct_transfer": "Do NOT send USDC directly to Gateway Wallet contract — permanent loss of funds",
      "finality_required": "Funds credited only after transaction reaches finality on source chain"
    },
    "virtual_accounts": {
      "mainnet_only": "Virtual accounts are only available on MAINNET",
      "compliance_required": "Must complete Due Diligence Form before using virtual accounts"
    },
    "fiat_withdrawal": {
      "compliance_ngn": "NGN requires Naira-only onboarding form",
      "compliance_african": "KES, TZS, UGX, MWK require African currencies partner onboarding"
    },
    "signing": {
      "message_max_length": 4096,
      "broadcast_retries": 10,
      "broadcast_interval": "5m"
    },
    "auto_settlement": {
      "rule_isolation": "Rules are isolated per blockchain — a rule on Ethereum does NOT affect Base",
      "address_override": "Child address rules completely override master wallet rules (no merging)"
    },
    "webhooks": {
      "retry_attempts": 5,
      "retry_backoff": "5 min → 80 min (total ~2h35m)",
      "signature_header": "x-blockradar-signature",
      "signature_algorithm": "HMAC-SHA512 using API key",
      "must_return_200": "Webhook endpoint must return HTTP 200 OK",
      "https_required": "HTTPS required for production (HTTP allowed for local testing)"
    },
    "security": {
      "https_required": "All API requests must be made over HTTPS",
      "ssl_verification": "Do not set VERIFY_PEER to FALSE — ensure SSL connection is verified",
      "api_key_secret": "API keys must not be committed to git or used in client-side code",
      "api_key_per_wallet": "Each wallet has its own API key",
      "key_rotation": "Compromised API keys can be reset from the dashboard",
      "aml_screening": "New addresses are screened against OFAC sanctions list",
      "private_key_caution": "showPrivateKey exposes sensitive information — use only in secure environments",
      "non_custodial": "Blockradar never stores private keys — only encrypted seed phrases and derivation paths",
      "encryption": "AES-256-GCM with PBKDF2 key derivation, random IV, and authentication tags",
      "real_time_key_computation": "Private keys computed on-demand for signing, then immediately wiped from memory",
      "dual_seed_system": "Separate encrypted seed phrases for mainnet and testnet environments",
      "seed_backup_required": "Users must back up seed phrases immediately — if compromised, Blockradar cannot recover funds",
      "shared_responsibility": "Blockradar secures the platform; customer secures integration, API keys, and seed phrase backups",
      "vulnerability_reporting": "Report vulnerabilities to support@blockradar.co"
    }
  },
  "outcomes": {
    "wallet_created": {
      "priority": 1,
      "given": [
        "Client is authenticated with valid API key",
        "No master wallet exists for the selected blockchain"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.create_wallet",
          "description": "POST /v1/wallets — create master wallet for a blockchain"
        },
        {
          "action": "emit_event",
          "event": "wallet.created",
          "payload": [
            "wallet_id",
            "blockchain",
            "network"
          ]
        }
      ],
      "result": "Master wallet created — ready to generate addresses and receive deposits"
    },
    "deposit_received": {
      "priority": 2,
      "given": [
        "Customer deposits stablecoins to a dedicated address",
        "Transaction is confirmed on the blockchain"
      ],
      "then": [
        {
          "action": "emit_event",
          "event": "deposit.success",
          "payload": [
            "wallet_id",
            "address_id",
            "amount",
            "asset_id",
            "transaction_hash"
          ]
        },
        {
          "action": "call_service",
          "target": "auto_sweep",
          "description": "Funds automatically swept to master wallet (if auto-sweep enabled)"
        }
      ],
      "result": "Deposit notification sent via webhook — client updates customer record"
    },
    "deposit_sweep_success": {
      "priority": 3,
      "given": [
        "Deposit was received at a child address",
        "Auto-sweep is enabled for this address",
        "Master wallet has sufficient native token for gas"
      ],
      "then": [
        {
          "action": "emit_event",
          "event": "deposit.swept.success",
          "payload": [
            "wallet_id",
            "address_id",
            "amount",
            "transaction_hash"
          ]
        }
      ],
      "result": "Deposited funds swept to master wallet"
    },
    "deposit_sweep_failed": {
      "priority": 4,
      "error": "DEPOSIT_SWEEP_FAILED",
      "given": [
        "Auto-sweep is enabled but master wallet has insufficient native token for gas"
      ],
      "then": [
        {
          "action": "emit_event",
          "event": "deposit.swept.failed",
          "payload": [
            "wallet_id",
            "address_id",
            "error_code"
          ]
        }
      ],
      "result": "Auto-sweep failed — fund master wallet with native tokens"
    },
    "address_created": {
      "priority": 5,
      "given": [
        "Client is authenticated",
        "Master wallet exists and is funded"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.create_address",
          "description": "POST /v1/wallets/{walletId}/addresses"
        },
        {
          "action": "emit_event",
          "event": "address.created",
          "payload": [
            "wallet_id",
            "address_id",
            "address",
            "blockchain"
          ]
        }
      ],
      "result": "Dedicated address generated for customer — can receive deposits across EVM chains"
    },
    "address_whitelisted": {
      "priority": 6,
      "given": [
        "Client provides an external address to monitor"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.whitelist_address",
          "description": "POST /v1/wallets/{walletId}/addresses/whitelist"
        },
        {
          "action": "emit_event",
          "event": "address.whitelisted",
          "payload": [
            "wallet_id",
            "address_id",
            "address"
          ]
        }
      ],
      "result": "External address whitelisted for deposit monitoring"
    },
    "withdrawal_success": {
      "priority": 7,
      "given": [
        "Client is authenticated",
        "Master wallet has sufficient stablecoin balance",
        {
          "field": "amount",
          "source": "input",
          "operator": "gt",
          "value": 0,
          "description": "Withdrawal amount is positive"
        }
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.withdraw",
          "description": "POST /v1/wallets/{walletId}/withdraw"
        },
        {
          "action": "emit_event",
          "event": "withdraw.success",
          "payload": [
            "wallet_id",
            "amount",
            "asset_id",
            "destination_address",
            "transaction_hash"
          ]
        }
      ],
      "result": "Stablecoins sent to destination address and confirmed on blockchain"
    },
    "withdrawal_failed": {
      "priority": 8,
      "error": "WITHDRAWAL_FAILED",
      "given": [
        "Withdrawal was initiated but failed on the blockchain"
      ],
      "then": [
        {
          "action": "emit_event",
          "event": "withdraw.failed",
          "payload": [
            "wallet_id",
            "error_code"
          ]
        }
      ],
      "result": "Withdrawal failed — check balance and destination address"
    },
    "batch_withdrawal": {
      "priority": 9,
      "given": [
        "Client provides array of 1-20 withdrawal recipients",
        "Master wallet has sufficient balance for total amount"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.batch_withdraw",
          "description": "POST /v1/wallets/{walletId}/withdraw with assets[] array (max 20)"
        }
      ],
      "result": "Batch withdrawal queued — individual webhook notifications per recipient"
    },
    "fiat_withdrawal_success": {
      "priority": 10,
      "given": [
        "Client is authenticated",
        "Compliance requirements met for target currency",
        "Bank account verified via institution-account-verification",
        "Quote obtained and accepted"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.withdraw_fiat_execute",
          "description": "POST /v1/wallets/{walletId}/withdraw/fiat/execute"
        },
        {
          "action": "emit_event",
          "event": "offramp.success",
          "payload": [
            "wallet_id",
            "amount",
            "currency",
            "institution_identifier"
          ]
        }
      ],
      "result": "Stablecoins converted to fiat and sent to bank account",
      "transaction": true
    },
    "fiat_withdrawal_failed": {
      "priority": 11,
      "error": "OFFRAMP_FAILED",
      "given": [
        "Fiat withdrawal was initiated but failed"
      ],
      "then": [
        {
          "action": "emit_event",
          "event": "offramp.failed",
          "payload": [
            "wallet_id",
            "error_code"
          ]
        }
      ],
      "result": "Fiat withdrawal failed"
    },
    "gateway_deposit_success": {
      "priority": 12,
      "given": [
        "Client is authenticated",
        "Wallet is on a Gateway-supported chain",
        "Wallet has USDC balance"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.gateway_deposit",
          "description": "POST /v1/wallets/{walletId}/gateway/deposit"
        },
        {
          "action": "emit_event",
          "event": "gateway.deposit.success",
          "payload": [
            "wallet_id",
            "amount",
            "source_chain"
          ]
        }
      ],
      "result": "USDC deposited to unified Gateway balance (after chain finality)"
    },
    "gateway_withdraw_success": {
      "priority": 13,
      "given": [
        "Client has sufficient Gateway USDC balance",
        "Destination chain is supported"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.gateway_withdraw",
          "description": "POST /v1/wallets/{walletId}/gateway/withdraw"
        },
        {
          "action": "emit_event",
          "event": "gateway.withdraw.success",
          "payload": [
            "wallet_id",
            "amount",
            "destination_chain"
          ]
        }
      ],
      "result": "USDC minted and withdrawn on destination chain"
    },
    "payment_link_created": {
      "priority": 14,
      "given": [
        "Client is authenticated",
        "Master wallet exists"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.create_payment_link",
          "description": "POST /v1/wallets/{walletId}/payment-links"
        },
        {
          "action": "emit_event",
          "event": "checkout.link_created",
          "payload": [
            "payment_link_id",
            "payment_link_url",
            "wallet_id"
          ]
        }
      ],
      "result": "Shareable payment link generated — customers can pay via stablecoins"
    },
    "auto_settlement_executed": {
      "priority": 15,
      "given": [
        "Deposit matches an active auto-settlement rule",
        "Amount is within rule's min/max thresholds"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.auto_settle",
          "description": "Automatic swap to destination asset on destination chain"
        },
        {
          "action": "emit_event",
          "event": "swap.success",
          "payload": [
            "wallet_id",
            "source_asset",
            "destination_asset",
            "amount"
          ]
        }
      ],
      "result": "Deposit automatically converted and routed to destination chain"
    },
    "swap_success": {
      "priority": 16,
      "given": [
        "Client is authenticated",
        "Source asset balance is sufficient",
        "Swap quote obtained"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.execute_swap",
          "description": "POST /v1/wallets/{walletId}/swap"
        },
        {
          "action": "emit_event",
          "event": "swap.success",
          "payload": [
            "wallet_id",
            "from_asset",
            "to_asset",
            "amount"
          ]
        }
      ],
      "result": "Asset swap executed successfully"
    },
    "message_signed": {
      "priority": 17,
      "given": [
        "Client is authenticated",
        {
          "field": "message",
          "source": "input",
          "operator": "exists",
          "description": "Message to sign is provided"
        }
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.sign_message",
          "description": "POST /v1/wallets/{walletId}/signing/message"
        },
        {
          "action": "emit_event",
          "event": "signed.success",
          "payload": [
            "wallet_id",
            "signature"
          ]
        }
      ],
      "result": "Message signed with wallet's private key"
    },
    "transaction_broadcast": {
      "priority": 18,
      "given": [
        "Client provides raw transaction data"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.sign_and_broadcast",
          "description": "POST /v1/wallets/{walletId}/signing/broadcast"
        },
        {
          "action": "emit_event",
          "event": "signed.success",
          "payload": [
            "wallet_id",
            "transaction_hash"
          ]
        }
      ],
      "result": "Transaction signed and broadcast — retries up to 10x at 5-min intervals"
    },
    "asset_recovered": {
      "priority": 19,
      "given": [
        "Assets were sent to correct address on wrong blockchain",
        "Client provides sender/recipient addresses and blockchain"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.salvage",
          "description": "POST /v1/wallets/{walletId}/salvage"
        },
        {
          "action": "emit_event",
          "event": "salvage.success",
          "payload": [
            "wallet_id",
            "amount",
            "blockchain"
          ]
        }
      ],
      "result": "Stuck assets recovered and transferred to recipient address"
    },
    "deposit_rescanned": {
      "priority": 20,
      "given": [
        "Client has a transaction hash for a missing deposit"
      ],
      "then": [
        {
          "action": "call_service",
          "target": "blockradar_api.rescan_blocks",
          "description": "POST /v1/wallets/{walletId}/rescan/blocks"
        }
      ],
      "result": "Blockchain rescanned — missing deposit webhook will be sent if found"
    },
    "webhook_verified": {
      "priority": 21,
      "given": [
        "Webhook received with x-blockradar-signature header",
        "HMAC-SHA512 of request body using API key matches signature"
      ],
      "then": [
        "Process the webhook event"
      ],
      "result": "Webhook origin verified as Blockradar — safe to process"
    },
    "webhook_signature_invalid": {
      "priority": 22,
      "error": "WEBHOOK_SIGNATURE_INVALID",
      "given": [
        "Webhook received but signature does not match"
      ],
      "then": [
        "Reject the webhook"
      ],
      "result": "Webhook rejected — potential tampering or misconfiguration"
    }
  },
  "errors": [
    {
      "code": "BLOCKRADAR_AUTH_FAILED",
      "status": 401,
      "message": "Invalid or missing API key"
    },
    {
      "code": "BLOCKRADAR_VALIDATION_ERROR",
      "status": 400,
      "message": "A validation or client-side error occurred"
    },
    {
      "code": "BLOCKRADAR_NOT_FOUND",
      "status": 404,
      "message": "Requested resource does not exist"
    },
    {
      "code": "BLOCKRADAR_SERVER_ERROR",
      "status": 500,
      "message": "An internal error occurred on Blockradar's end",
      "retry": true
    },
    {
      "code": "BLOCKRADAR_WALLET_EXISTS",
      "status": 409,
      "message": "A master wallet already exists for this blockchain"
    },
    {
      "code": "BLOCKRADAR_INSUFFICIENT_BALANCE",
      "status": 422,
      "message": "Insufficient balance for this operation"
    },
    {
      "code": "BLOCKRADAR_INSUFFICIENT_GAS",
      "status": 422,
      "message": "Master wallet needs native tokens for gas fees"
    },
    {
      "code": "WITHDRAWAL_FAILED",
      "status": 422,
      "message": "Withdrawal failed to execute on the blockchain",
      "retry": true
    },
    {
      "code": "DEPOSIT_SWEEP_FAILED",
      "status": 422,
      "message": "Auto-sweep failed — fund master wallet with native tokens",
      "retry": true
    },
    {
      "code": "OFFRAMP_FAILED",
      "status": 422,
      "message": "Fiat withdrawal failed",
      "retry": true
    },
    {
      "code": "GATEWAY_DIRECT_TRANSFER",
      "status": 400,
      "message": "Do not send USDC directly to Gateway contract — use the API"
    },
    {
      "code": "BATCH_SIZE_EXCEEDED",
      "status": 400,
      "message": "Batch withdrawal cannot exceed 20 recipients"
    },
    {
      "code": "VIRTUAL_ACCOUNT_TESTNET",
      "status": 400,
      "message": "Virtual accounts are only available on mainnet"
    },
    {
      "code": "WEBHOOK_SIGNATURE_INVALID",
      "status": 403,
      "message": "Webhook signature verification failed"
    },
    {
      "code": "SWAP_FAILED",
      "status": 422,
      "message": "Swap transaction failed",
      "retry": true
    }
  ],
  "events": [
    {
      "name": "deposit.success",
      "payload": [
        "wallet_id",
        "address_id",
        "amount",
        "asset_id",
        "transaction_hash",
        "metadata"
      ],
      "description": "Deposit confirmed on the blockchain"
    },
    {
      "name": "deposit.processing",
      "payload": [
        "wallet_id",
        "address_id",
        "amount",
        "asset_id"
      ],
      "description": "Deposit detected, awaiting confirmation"
    },
    {
      "name": "deposit.failed",
      "payload": [
        "wallet_id",
        "address_id",
        "error_code"
      ],
      "description": "Deposit failed to be processed"
    },
    {
      "name": "deposit.swept.success",
      "payload": [
        "wallet_id",
        "address_id",
        "amount",
        "transaction_hash"
      ],
      "description": "Funds auto-swept from child address to master wallet"
    },
    {
      "name": "deposit.swept.failed",
      "payload": [
        "wallet_id",
        "address_id",
        "error_code"
      ],
      "description": "Auto-sweep failed (likely insufficient gas)"
    },
    {
      "name": "withdraw.success",
      "payload": [
        "wallet_id",
        "amount",
        "asset_id",
        "destination_address",
        "transaction_hash"
      ],
      "description": "Withdrawal confirmed on blockchain"
    },
    {
      "name": "withdraw.failed",
      "payload": [
        "wallet_id",
        "error_code"
      ],
      "description": "Withdrawal failed"
    },
    {
      "name": "offramp.processing",
      "payload": [
        "wallet_id",
        "amount",
        "currency"
      ],
      "description": "Fiat withdrawal being processed"
    },
    {
      "name": "offramp.success",
      "payload": [
        "wallet_id",
        "amount",
        "currency",
        "institution_identifier"
      ],
      "description": "Fiat withdrawal completed"
    },
    {
      "name": "offramp.failed",
      "payload": [
        "wallet_id",
        "error_code"
      ],
      "description": "Fiat withdrawal failed"
    },
    {
      "name": "gateway.deposit.success",
      "payload": [
        "wallet_id",
        "amount",
        "source_chain"
      ],
      "description": "USDC deposited to Gateway unified balance"
    },
    {
      "name": "gateway.withdraw.success",
      "payload": [
        "wallet_id",
        "amount",
        "destination_chain"
      ],
      "description": "USDC withdrawn from Gateway to destination chain"
    },
    {
      "name": "swap.success",
      "payload": [
        "wallet_id",
        "from_asset",
        "to_asset",
        "amount"
      ],
      "description": "Asset swap executed successfully"
    },
    {
      "name": "swap.failed",
      "payload": [
        "wallet_id",
        "error_code"
      ],
      "description": "Swap transaction failed"
    },
    {
      "name": "signed.success",
      "payload": [
        "wallet_id",
        "transaction_hash"
      ],
      "description": "Transaction signed and broadcast successfully"
    },
    {
      "name": "signed.failed",
      "payload": [
        "wallet_id",
        "error_code"
      ],
      "description": "Transaction broadcast failed after all retries"
    },
    {
      "name": "salvage.success",
      "payload": [
        "wallet_id",
        "amount",
        "blockchain"
      ],
      "description": "Asset recovery completed"
    },
    {
      "name": "salvage.failed",
      "payload": [
        "wallet_id",
        "error_code"
      ],
      "description": "Asset recovery failed"
    }
  ],
  "related": [],
  "agi": {
    "goals": [
      {
        "id": "reliable_stablecoin_wallet_api",
        "description": "Stablecoin wallet infrastructure API — multi-chain wallets, addresses, deposits, withdrawals, swaps, gateway, checkout, and fiat offramp",
        "success_metrics": [
          {
            "metric": "success_rate",
            "target": ">= 99.5%",
            "measurement": "Successful operations divided by total attempts"
          },
          {
            "metric": "error_recovery_rate",
            "target": ">= 95%",
            "measurement": "Errors that auto-recover without manual intervention"
          }
        ],
        "constraints": [
          {
            "type": "availability",
            "description": "Must degrade gracefully when dependencies are unavailable",
            "negotiable": false
          },
          {
            "type": "security",
            "description": "Sensitive fields must be encrypted at rest and never logged in plaintext",
            "negotiable": false
          }
        ]
      }
    ],
    "autonomy": {
      "level": "supervised",
      "escalation_triggers": [
        "error_rate > 5"
      ]
    },
    "safety": {
      "action_permissions": [
        {
          "action": "wallet_created",
          "permission": "supervised"
        },
        {
          "action": "deposit_received",
          "permission": "autonomous"
        },
        {
          "action": "deposit_sweep_success",
          "permission": "autonomous"
        },
        {
          "action": "deposit_sweep_failed",
          "permission": "autonomous"
        },
        {
          "action": "address_created",
          "permission": "supervised"
        },
        {
          "action": "address_whitelisted",
          "permission": "autonomous"
        },
        {
          "action": "withdrawal_success",
          "permission": "autonomous"
        },
        {
          "action": "withdrawal_failed",
          "permission": "autonomous"
        },
        {
          "action": "batch_withdrawal",
          "permission": "autonomous"
        },
        {
          "action": "fiat_withdrawal_success",
          "permission": "autonomous"
        },
        {
          "action": "fiat_withdrawal_failed",
          "permission": "autonomous"
        },
        {
          "action": "gateway_deposit_success",
          "permission": "autonomous"
        },
        {
          "action": "gateway_withdraw_success",
          "permission": "autonomous"
        },
        {
          "action": "payment_link_created",
          "permission": "supervised"
        },
        {
          "action": "auto_settlement_executed",
          "permission": "autonomous"
        },
        {
          "action": "swap_success",
          "permission": "autonomous"
        },
        {
          "action": "message_signed",
          "permission": "autonomous"
        },
        {
          "action": "transaction_broadcast",
          "permission": "autonomous"
        },
        {
          "action": "asset_recovered",
          "permission": "autonomous"
        },
        {
          "action": "deposit_rescanned",
          "permission": "autonomous"
        },
        {
          "action": "webhook_verified",
          "permission": "autonomous"
        },
        {
          "action": "webhook_signature_invalid",
          "permission": "autonomous"
        }
      ]
    },
    "tradeoffs": [
      {
        "prefer": "reliability",
        "over": "throughput",
        "reason": "integration failures can cascade across systems"
      }
    ],
    "verification": {
      "invariants": [
        "sensitive fields are never logged in plaintext",
        "all data access is authenticated and authorized",
        "error messages never expose internal system details",
        "state transitions follow the defined state machine — no illegal transitions"
      ]
    }
  },
  "extensions": {
    "api": {
      "base_url": "https://api.blockradar.co/v1",
      "auth": {
        "method": "API Key",
        "header": "x-api-key",
        "scope": "per-wallet"
      },
      "content_type": "application/json",
      "postman_collection": "https://documenter.getpostman.com/view/7709133/2s93eSYaVs",
      "github": "https://github.com/blockradar",
      "response_format": {
        "statusCode": "number — request status code",
        "message": "string — summary of response",
        "data": "object|array — results of the request",
        "meta": "object — pagination info (totalItems, itemCount, itemsPerPage, totalPages, currentPage)"
      },
      "pagination": {
        "default_page_size": 100,
        "default_page": 1
      },
      "environments": {
        "testnet": "Test environment with faucet tokens",
        "mainnet": "Live environment with real assets"
      },
      "supported_blockchains": {
        "evm": [
          "ethereum",
          "bsc",
          "polygon",
          "base",
          "arbitrum",
          "optimism",
          "celo",
          "lisk",
          "avalanche"
        ],
        "non_evm": [
          "tron",
          "solana"
        ],
        "additional": [
          "asset-chain",
          "plasma",
          "arc",
          "tempo"
        ]
      },
      "supported_stablecoins": [
        "USDT",
        "USDC",
        "DAI",
        "BUSD",
        "cUSD",
        "cNGN",
        "EURC",
        "IDRX",
        "ZARP",
        "JPYC",
        "AlphaUSD"
      ],
      "webhook_signature": "HMAC-SHA512 via x-blockradar-signature header",
      "total_endpoints": 127
    },
    "security": {
      "architecture": "Non-custodial — private keys never stored, only encrypted seed phrases",
      "encryption": "Custom AES-256-GCM with PBKDF2 key derivation",
      "key_computation": "Real-time on-demand — computed for signing, immediately wiped",
      "seed_system": "Dual encrypted seeds (mainnet/testnet) per business account",
      "compliance": [
        "SOC2",
        "ISO27001",
        "PCI-DSS",
        "GDPR"
      ],
      "aml_provider": "OFAC sanctions screening on address creation",
      "disaster_recovery": "Geo-distributed encrypted backups + user-exportable seed phrases"
    }
  }
}