{"id":49430449,"url":"https://github.com/pablomg-dev/xlayer-agentic-vault","last_synced_at":"2026-04-29T12:02:47.818Z","repository":{"id":346710829,"uuid":"1191208282","full_name":"pablomg-dev/xlayer-agentic-vault","owner":"pablomg-dev","description":"Autonomous agent for asset management on X Layer","archived":false,"fork":false,"pushed_at":"2026-03-25T19:04:54.000Z","size":171,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-26T09:50:53.371Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pablomg-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-25T02:44:38.000Z","updated_at":"2026-03-25T19:04:58.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pablomg-dev/xlayer-agentic-vault","commit_stats":null,"previous_names":["pablomg-dev/xlayer-agentic-vault"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/pablomg-dev/xlayer-agentic-vault","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablomg-dev%2Fxlayer-agentic-vault","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablomg-dev%2Fxlayer-agentic-vault/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablomg-dev%2Fxlayer-agentic-vault/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablomg-dev%2Fxlayer-agentic-vault/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pablomg-dev","download_url":"https://codeload.github.com/pablomg-dev/xlayer-agentic-vault/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablomg-dev%2Fxlayer-agentic-vault/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32424499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T11:26:24.167Z","status":"ssl_error","status_checked_at":"2026-04-29T11:26:13.719Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-29T12:02:46.026Z","updated_at":"2026-04-29T12:02:47.810Z","avatar_url":"https://github.com/pablomg-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xlayer-agentic-vault\n\n\u003e Autonomous agent for asset management and x402 payments on X Layer (OKX L2, chainId: 196)\n\nBuilt for the **X Layer Onchain OS AI Hackathon** — an agentic vault system that autonomously monitors balances, manages deposits/withdrawals, and executes x402 micropayments on X Layer mainnet.\n\n## 🤖 AI-Assisted Development\n\nThis project was built with the assistance of:\n- **[Claude](https://claude.ai)** (Anthropic) — architecture design, prompt engineering, code review\n- **[MiniMax M2.5](https://www.minimaxi.com)** (free tier via OpenCode) — code generation and implementation\n\n## Overview\n\n- **Smart Contract Vault** deployed on X Layer mainnet\n- Autonomous decision cycles (healthy / low / critical balance)\n- x402 payment protocol for autonomous micropayments\n- Full TypeScript with strong typing — `any` is forbidden\n- SOLID principles throughout\n- 20/20 unit tests passing\n\n## Tech Stack\n\n- **Runtime**: Node.js 20 + TypeScript 6\n- **Blockchain**: viem for X Layer RPC\n- **Smart Contracts**: Solidity 0.8.0 + Hardhat\n- **Testing**: Vitest\n- **Environment**: dotenv\n\n## Project Structure\n\n```\nsrc/\n├── agents/\n│   └── OKXAgenticWallet.ts       # OKX Agentic Wallet with viem\n├── config/\n│   └── network.ts                # X Layer network config (chainId 196)\n├── contracts/\n│   └── Vault.sol                 # Smart contract\n├── core/\n│   ├── errors/                   # Typed custom errors\n│   │   ├── PaymentErrors.ts\n│   │   ├── VaultErrors.ts\n│   │   └── WalletErrors.ts\n│   └── interfaces/               # Core interfaces (SOLID ISP)\n│       ├── IPaymentHandler.ts\n│       ├── IOrchestrator.ts\n│       ├── IVault.ts\n│       └── IWalletAgent.ts\n├── orchestrator/\n│   └── AgentOrchestrator.ts      # Autonomous decision cycles\n├── payments/\n│   └── X402PaymentHandler.ts     # x402 payment protocol\n├── scripts/\n│   ├── runAgent.ts               # Main demo entry point\n│   ├── testConnection.ts         # Verify X Layer RPC\n│   ├── testPayment.ts            # Test payment flow\n│   ├── testVault.ts              # Read-only vault test\n│   ├── testDeposit.cjs           # Deposit to vault contract\n│   ├── testWithdraw.cjs          # Withdraw from vault contract\n│   └── deploy.cjs                # Deploy vault contract\n├── utils/\n│   └── logger.ts                 # Typed singleton logger\n└── vault/\n    └── VaultService.ts           # Vault contract interaction\ntests/\n├── agent.test.ts\n├── orchestrator.test.ts\n├── payment.test.ts\n└── vault.test.ts\n```\n\n## Smart Contract — X Layer Mainnet\n\n**Vault Contract**: `0x7FE71a4817Fe49658BCFFBCcD7FBc00B5f74F150`\n\n| Function | Description |\n|----------|-------------|\n| `deposit()` | Payable — receive native OKB |\n| `withdraw(uint256 amount)` | Owner only |\n| `getBalance()` | Returns contract balance |\n\n**Events**: `Deposited(address, amount)` · `Withdrawn(address, amount)`\n\n## Live Transactions on X Layer Mainnet\n\n| Operation | Tx Hash | Gas Used |\n|-----------|---------|----------|\n| Deposit 0.001 OKB | `0x0c0d5569...` | 45,165 |\n| Withdraw 0.001 OKB | `0x5486973f...` | 33,146 |\n\n## Installation\n\n```bash\nnpm install\n```\n\n## Configuration\n\n```bash\ncp .env.example .env\n```\n\n```dotenv\nRPC_URL=https://rpc.xlayer.tech\nPRIVATE_KEY=0x...\n\nVAULT_ADDRESS=0x7FE71a4817Fe49658BCFFBCcD7FBc00B5f74F150\n\nMAX_DEPOSIT_AMOUNT=1000000000000000000    # 1 OKB\nMIN_DEPOSIT_AMOUNT=1000000000000000       # 0.001 OKB\n\nVAULT_THRESHOLD_LOW=50000000000000000     # 0.05 OKB\nVAULT_THRESHOLD_CRITICAL=10000000000000000 # 0.01 OKB\n```\n\n## Scripts\n\n| Command | Description |\n|---------|-------------|\n| `npm test` | Run all 20 unit tests |\n| `npm run test:watch` | Watch mode |\n| `npm run test:connection` | Verify X Layer RPC + chainId |\n| `npm run test:vault` | Read-only vault test |\n| `npm run test:payment` | x402 payment flow test |\n| `npm run run:agent` | Run autonomous agent demo |\n| `npm run run:agent:ts-node` | Run with ts-node/esm |\n\n## Running the Agent\n\n```bash\nnpm run run:agent:ts-node\n```\n\nExample output:\n```\n==================================================\n  X Layer Agentic Vault - Demo\n==================================================\n[INFO] Connecting to wallet...\n[INFO] Wallet connected successfully\n[INFO] VaultService initialized\n\n--- Cycle 1 ---\n  Action:    vault_healthy\n  Success:   true\n  Details:   Balance above threshold\n\n--- Cycle 2 ---\n  Action:    vault_healthy\n  Success:   true\n\n--- Cycle 3 ---\n  Action:    vault_healthy\n  Success:   true\n==================================================\n  Demo Complete\n==================================================\n```\n\n## Deploy New Vault Contract\n\n```bash\nnpx hardhat compile\nnpx hardhat run scripts/deploy.cjs --network xlayer\n```\n\n## Core Interfaces\n\n### IWalletAgent\n- `connect()` — initialize wallet connection\n- `getBalance(tokenAddress)` — balance in wei\n- `simulateTransaction(tx)` — dry-run before execution\n- `executeTransaction(tx)` — submit to X Layer\n\n### IVault\n- `deposit(tokenAddress, amount)` — deposit into vault contract\n- `withdraw(tokenAddress, amount, recipient)` — withdraw from vault\n- `getVaultBalance(tokenAddress)` — current contract balance\n- `getDepositHistory(tokenAddress)` — operation history\n\n### IPaymentHandler\n- `handlePayment(response)` — handle HTTP 402 payment request\n- `verifyPayment(txHash)` — confirm payment on-chain\n- `getPaymentHistory()` — payment history\n\n### IOrchestrator\n- `start()` — initialize all modules\n- `stop()` — graceful shutdown\n- `getStatus()` — `idle` | `running` | `stopped` | `error`\n- `runCycle()` — one autonomous decision cycle\n\n## Agent Decision Logic\n\nEach cycle evaluates vault health and acts accordingly:\n\n| Status | Condition | Action |\n|--------|-----------|--------|\n| `healthy` | balance \u003e `VAULT_THRESHOLD_LOW` | Log, no action |\n| `low` | balance between thresholds | Simulate deposit |\n| `critical` | balance \u003c `VAULT_THRESHOLD_CRITICAL` | Alert + simulate deposit |\n\n## X Layer Network\n\n| Property | Value |\n|----------|-------|\n| Chain ID | 196 |\n| RPC | https://rpc.xlayer.tech |\n| Explorer | https://www.oklink.com/xlayer |\n| Currency | OKB (18 decimals) |\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablomg-dev%2Fxlayer-agentic-vault","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpablomg-dev%2Fxlayer-agentic-vault","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablomg-dev%2Fxlayer-agentic-vault/lists"}