{"_id":"@aigentic/economy-wasm","_rev":"2-1cac24fb26aaa52f337d8c4ea5b626c1","name":"@aigentic/economy-wasm","dist-tags":{"alpha":"0.1.29","latest":"0.1.29"},"versions":{"0.1.29":{"name":"@aigentic/economy-wasm","version":"0.1.29","keywords":["wasm","crdt","distributed-economy","p2p-credits","reputation","ruvector","webassembly","distributed-systems","autonomous-economy","consensus"],"author":{"name":"RuVector Team","email":"ruvnet@users.noreply.github.com"},"license":"MIT","_id":"@aigentic/economy-wasm@0.1.29","maintainers":[{"name":"aigentic","email":"engineering@aigentic.net"}],"homepage":"https://ruv.io","bugs":{"url":"https://github.com/ruvnet/ruvector/issues"},"dist":{"shasum":"66f9083143a33b45fe07ab3ebee1b15269284bbd","tarball":"https://registry.npmjs.org/@aigentic/economy-wasm/-/economy-wasm-0.1.29.tgz","fileCount":6,"integrity":"sha512-BgO3rd7eXO9+oELSsGyUgfhlBrZcvqQ9CDwc3CwdK+eddqYqnov1FCeehiXsz4Ei5e3MJEUwAd+JEr6KpySTwg==","signatures":[{"sig":"MEUCIQCVNVhchHYvK0a7D0UvDvR+hfDvfLrryZAik71J0ldTsgIgF+zFkCsHdTVENK23xD0cmt9ZiDo5/cC3qXgD7BWX0GM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":260673},"main":"ruvector_economy_wasm.js","type":"module","types":"ruvector_economy_wasm.d.ts","gitHead":"e2cb6210ce8d478b39cad81872a4aef78a05ceb4","_npmUser":{"name":"aigentic","email":"engineering@aigentic.net"},"repository":{"url":"git+https://github.com/ruvnet/ruvector.git","type":"git"},"_npmVersion":"11.12.0","description":"CRDT-based autonomous credit economy for distributed compute networks - WASM optimized","directories":{},"sideEffects":["./snippets/*"],"_nodeVersion":"22.22.1","collaborators":["RuVector Team"],"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/economy-wasm_0.1.29_1779324098378_0.8686196734862901","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-05-21T00:41:38.171Z","modified":"2026-09-13T15:30:29.046Z","0.1.29":"2026-05-21T00:41:38.546Z"},"bugs":{"url":"https://github.com/ruvnet/ruvector/issues"},"author":{"name":"RuVector Team","email":"ruvnet@users.noreply.github.com"},"license":"MIT","homepage":"https://ruv.io","keywords":["wasm","crdt","distributed-economy","p2p-credits","reputation","ruvector","webassembly","distributed-systems","autonomous-economy","consensus"],"repository":{"url":"git+https://github.com/ruvnet/ruvector.git","type":"git"},"description":"CRDT-based autonomous credit economy for distributed compute networks - WASM optimized","maintainers":[{"email":"engineering@aigentic.net","name":"aiggy"}],"readme":"# @aigentic/economy-wasm - CRDT Credit Economy for Distributed Compute\n\n[![npm version](https://img.shields.io/npm/v/ruvector-economy-wasm.svg)](https://www.npmjs.com/package/ruvector-economy-wasm)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ruvnet/ruvector)\n[![Bundle Size](https://img.shields.io/badge/bundle%20size-177KB%20gzip-green.svg)](https://www.npmjs.com/package/ruvector-economy-wasm)\n[![WebAssembly](https://img.shields.io/badge/WebAssembly-654FF0?logo=webassembly&logoColor=white)](https://webassembly.org/)\n\nA **CRDT-based autonomous credit economy** for distributed compute networks. Provides conflict-free P2P credit tracking, stake/slash mechanics, and reputation scoring - a blockchain alternative for edge computing and AI agent coordination.\n\n## Key Features\n\n- **CRDT Ledger**: G-Counter and PN-Counter for P2P-safe credit tracking with guaranteed eventual consistency\n- **10x Early Adopter Curve**: Contribution multiplier decaying from 10x to 1x baseline as network grows\n- **Stake/Slash Mechanics**: Participation requirements with slashing for sybil attacks, double-spending, and bad behavior\n- **Reputation Scoring**: Multi-factor composite score based on accuracy, uptime, and stake weight\n- **Merkle State Root**: Fast ledger verification with cryptographic proofs\n- **WASM-Optimized**: Runs in browsers, Node.js, and edge runtimes\n\n## Installation\n\n```bash\nnpm install ruvector-economy-wasm\n# or\nyarn add ruvector-economy-wasm\n# or\npnpm add ruvector-economy-wasm\n```\n\n## Quick Start\n\n### TypeScript/JavaScript\n\n```typescript\nimport init, {\n  CreditLedger,\n  ReputationScore,\n  StakeManager,\n  contribution_multiplier,\n  SlashReason\n} from 'ruvector-economy-wasm';\n\n// Initialize WASM module\nawait init();\n\n// Create a credit ledger for a node\nconst ledger = new CreditLedger(\"node-123\");\n\n// Earn credits for completed tasks\nledger.credit(100n, \"task:compute-job-456\");\nconsole.log(`Balance: ${ledger.balance()}`);\n\n// Check early adopter multiplier\nconst mult = contribution_multiplier(50000.0);  // 50K network compute hours\nconsole.log(`Multiplier: ${mult.toFixed(2)}x`);  // ~8.5x for early adopters\n\n// Credit with multiplier applied\nledger.creditWithMultiplier(50n, \"task:bonus-789\");\n\n// Track reputation\nconst rep = new ReputationScore(0.95, 0.98, 1000n);\nconsole.log(`Composite score: ${rep.compositeScore()}`);\nconsole.log(`Tier: ${rep.tierName()}`);\n```\n\n## Understanding CRDTs\n\n**Conflict-free Replicated Data Types (CRDTs)** enable distributed systems to:\n- Merge updates in any order with identical results\n- Operate offline and sync later without conflicts\n- Scale horizontally without coordination bottlenecks\n\nThis package uses:\n- **G-Counter**: Grow-only counter for earned credits (monotonically increasing)\n- **PN-Counter**: Positive-negative counter for spending (allows refunds/disputes)\n\n```typescript\n// P2P merge example - works regardless of message order\nconst nodeA = new CreditLedger(\"node-A\");\nconst nodeB = new CreditLedger(\"node-B\");\n\n// Both nodes earn credits independently\nnodeA.credit(100n, \"job-1\");\nnodeB.credit(50n, \"job-2\");\n\n// Export for P2P sync\nconst earnedA = nodeA.exportEarned();\nconst spentA = nodeA.exportSpent();\n\n// Merge on node B - associative, commutative, idempotent\nconst merged = nodeB.merge(earnedA, spentA);\nconsole.log(`Merged ${merged} updates`);\n```\n\n## Contribution Curve\n\nEarly network contributors receive higher rewards that decay as the network matures:\n\n```\nMultiplier = 1 + 9 * exp(-compute_hours / 100,000)\n\nNetwork Hours  | Multiplier\n---------------|------------\n0              | 10.0x (Genesis)\n10,000         | ~9.0x\n50,000         | ~6.0x\n100,000        | ~4.3x\n200,000        | ~2.2x\n500,000        | ~1.0x (Baseline)\n```\n\n```typescript\nimport { contribution_multiplier, get_tier_name, get_tiers_json } from 'ruvector-economy-wasm';\n\n// Check current multiplier\nconst hours = 25000;\nconst mult = contribution_multiplier(hours);\nconsole.log(`At ${hours} hours: ${mult.toFixed(2)}x multiplier`);\n\n// Get tier name\nconst tier = get_tier_name(hours);  // \"Pioneer\"\n\n// Get all tier definitions\nconst tiers = JSON.parse(get_tiers_json());\n```\n\n## Stake/Slash Mechanics\n\n```typescript\nimport { StakeManager, SlashReason } from 'ruvector-economy-wasm';\n\nconst stakeManager = new StakeManager();\n\n// Stake credits for network participation\nstakeManager.stake(\"node-123\", 1000n);\nconsole.log(`Staked: ${stakeManager.getStake(\"node-123\")}`);\n\n// Check if node meets minimum stake\nif (stakeManager.meetsMinimum(\"node-123\")) {\n  console.log(\"Node can participate\");\n}\n\n// Delegate stake to another node\nstakeManager.delegate(\"node-123\", \"validator-1\", 500n);\nconsole.log(`Effective stake: ${stakeManager.getEffectiveStake(\"validator-1\")}`);\n\n// Slash for bad behavior\nconst slashedAmount = stakeManager.slash(\n  \"bad-actor\",\n  SlashReason.DoubleSpend,\n  \"Evidence: duplicate transaction IDs\"\n);\nconsole.log(`Slashed ${slashedAmount} credits`);\n```\n\n### Slash Reasons\n\n| Reason | Severity | Description |\n|--------|----------|-------------|\n| `InvalidResult` | Medium | Submitted incorrect computation results |\n| `DoubleSpend` | High | Attempted to spend same credits twice |\n| `SybilAttack` | Critical | Multiple fake identities detected |\n| `Downtime` | Low | Excessive offline periods |\n| `Spam` | Medium | Flooding the network |\n| `Malicious` | Critical | Intentional harmful behavior |\n\n## Reputation System\n\n```typescript\nimport { ReputationScore, composite_reputation } from 'ruvector-economy-wasm';\n\n// Create reputation with tracking\nconst rep = ReputationScore.newWithTracking(\n  950n,  // tasks completed\n  50n,   // tasks failed\n  BigInt(30 * 24 * 3600),  // uptime seconds\n  BigInt(31 * 24 * 3600),  // total seconds\n  5000n  // stake amount\n);\n\n// Record task outcomes\nrep.recordSuccess();\nrep.recordFailure();\n\n// Calculate composite score\n// Formula: accuracy^2 * uptime * stake_weight\nconst score = rep.compositeScore();\nconsole.log(`Composite: ${(score * 100).toFixed(1)}%`);\n\n// Get tier\nconsole.log(`Tier: ${rep.tierName()}`);  // \"Elite\", \"Trusted\", \"Standard\", etc.\n\n// Check participation eligibility\nif (rep.meetsMinimum(0.9, 0.95, 100n)) {\n  console.log(\"Eligible for premium tasks\");\n}\n\n// Compare reputations\nconst rep2 = new ReputationScore(0.92, 0.96, 3000n);\nconsole.log(`Better reputation: ${rep.isBetterThan(rep2) ? 'rep1' : 'rep2'}`);\n```\n\n### Reputation Tiers\n\n| Tier | Score Range | Benefits |\n|------|-------------|----------|\n| Elite | >= 0.95 | Priority task assignment, lowest fees |\n| Trusted | >= 0.85 | High-value tasks, reduced collateral |\n| Standard | >= 0.70 | Normal participation |\n| Probation | >= 0.50 | Limited task types |\n| Restricted | < 0.50 | Basic tasks only, increased monitoring |\n\n## Merkle State Verification\n\n```typescript\nconst ledger = new CreditLedger(\"node-123\");\nledger.credit(100n, \"job-1\");\nledger.credit(200n, \"job-2\");\n\n// Get state root for verification\nconst stateRoot = ledger.stateRoot();\nconst stateRootHex = ledger.stateRootHex();\nconsole.log(`State root: ${stateRootHex}`);\n\n// Verify state integrity\nconst isValid = ledger.verifyStateRoot(expectedRoot);\n```\n\n## API Reference\n\n### CreditLedger\n\n| Method | Description |\n|--------|-------------|\n| `new(node_id)` | Create ledger for node |\n| `credit(amount, reason)` | Earn credits |\n| `creditWithMultiplier(base_amount, reason)` | Earn with network multiplier |\n| `deduct(amount)` | Spend credits |\n| `refund(event_id, amount)` | Refund a deduction |\n| `balance()` | Get available balance |\n| `stake(amount)` | Lock credits for participation |\n| `slash(amount)` | Penalty for bad behavior |\n| `merge(other_earned, other_spent)` | CRDT merge operation |\n| `exportEarned()` / `exportSpent()` | Export for P2P sync |\n| `stateRoot()` / `stateRootHex()` | Merkle verification |\n\n### ReputationScore\n\n| Method | Description |\n|--------|-------------|\n| `new(accuracy, uptime, stake)` | Create with scores |\n| `newWithTracking(...)` | Create with detailed tracking |\n| `compositeScore()` | Calculate composite (0.0-1.0) |\n| `tierName()` | Get reputation tier |\n| `recordSuccess()` / `recordFailure()` | Track task outcomes |\n| `stakeWeight()` | Logarithmic stake weight |\n| `meetsMinimum(accuracy, uptime, stake)` | Check eligibility |\n\n### StakeManager\n\n| Method | Description |\n|--------|-------------|\n| `new()` | Create manager |\n| `stake(node_id, amount)` | Stake credits |\n| `unstake(node_id, amount)` | Unstake (if unlocked) |\n| `delegate(from, to, amount)` | Delegate to another node |\n| `slash(node_id, reason, evidence)` | Slash for violation |\n| `getEffectiveStake(node_id)` | Own + delegated stake |\n| `meetsMinimum(node_id)` | Check stake requirement |\n\n## Use Cases\n\n- **Distributed AI Training**: Reward compute contributors fairly\n- **Edge Computing Networks**: Track and reward edge node participation\n- **Federated Learning**: Incentivize model training contributions\n- **P2P Storage**: Credit-based storage allocation\n- **Agent Coordination**: Economic layer for multi-agent systems\n- **Decentralized Inference**: Pay-per-inference without blockchain overhead\n\n## Bundle Size\n\n- **WASM binary**: ~177KB (uncompressed)\n- **Gzip compressed**: ~65KB\n- **JavaScript glue**: ~8KB\n\n## Related Packages\n\n- [ruvector-learning-wasm](https://www.npmjs.com/package/ruvector-learning-wasm) - MicroLoRA adaptation\n- [ruvector-exotic-wasm](https://www.npmjs.com/package/ruvector-exotic-wasm) - NAO governance, morphogenetic networks\n- [ruvector-nervous-system-wasm](https://www.npmjs.com/package/ruvector-nervous-system-wasm) - Bio-inspired neural components\n\n## License\n\nMIT\n\n## Links\n\n- [GitHub Repository](https://github.com/ruvnet/ruvector)\n- [Full Documentation](https://ruv.io)\n- [Bug Reports](https://github.com/ruvnet/ruvector/issues)\n\n---\n\n**Keywords**: CRDT, distributed systems, credits, P2P, peer-to-peer, blockchain alternative, reputation, stake, slash, economy, WebAssembly, WASM, edge computing, decentralized, conflict-free, eventual consistency, G-Counter, PN-Counter\n","readmeFilename":"README.md"}