Skip to content

FEAT: Complete backend — Issues #5, #6, #7, #8 - #13

Merged
Verifieddanny merged 1 commit into
mainfrom
dev
Jun 10, 2026
Merged

Verifieddanny merged 1 commit into
mainfrom
dev

Conversation

@Verifieddanny

Copy link
Copy Markdown
Contributor

closes Issue #5 — Redis Pub/Sub Integration

  • internal/ws/pubsub.go: Redis client, Subscribe/Publish/PublishLeaderboardUpdate
  • internal/ws/hub.go: leaderboard channel key, RegisterLeaderboard, BroadcastLeaderboard
  • All state changes (proposal, winner, settlement) now publish to Redis pub/sub alongside local WebSocket broadcast — enables horizontal scaling

closes Issue #6 — Scoring Engine

  • internal/scoring/engine.go: deterministic 4-criterion weighted scorer Weights: execution efficiency (35%), win rate (25%), slippage (25%), reputation (15%)
  • New agents seeded with neutral 0.5 on slippage + reputation — can compete from day one
  • Tie-break: earlier proposal wins — fully deterministic, no randomness
  • handlers/executions.go SelectWinner(): replaced stub with real engine Fetches agent_reputations, runs engine, persists individual scores back to proposals table

closes Issue #7 — Execution Validation Service

  • internal/validation/service.go: 6-constraint validation — token pair, slippage, deadline, approved venue, intent ownership, agent ID presence
  • All checks run on every call — caller always gets the full failure list
  • handlers/executions.go ValidateExecution(): replaced stub with real service Failed proposals get score zeroed (penalises agent in future scoring) HTTP 422 Unprocessable Entity on failure (semantically correct)
  • handlers/executions.go SettleExecution(): validation added as hard gate Cannot settle without passing — runs independently of /validate endpoint

closes Issue #8 — Circle Integration

  • internal/circle/client.go: isolated Circle API client CreateWallet (deterministic idempotency via SHA1 UUID from wallet address) GetWallet / GetBalance (USDC balance reads) SendUSDC (micropayment settlement — agent execution fee) SimulateCCTPTransfer (cross-chain routing demo) Sandbox/production toggled from ENV — never hits prod from dev
  • internal/handlers/circle.go: 4 new endpoints POST /api/v1/wallets, GET /api/v1/wallets/{id}/balance POST /api/v1/wallets/transfer, POST /api/v1/wallets/cctp
  • handlers/executions.go SettleExecution(): Circle.SendUSDC() called after settlement Idempotency key tied to execution ID — retries never double-pay Agent total_intents_won + consecutive_successes incremented atomically (gorm.Expr)

CI/CD fixes

  • golangci-lint-action upgraded v3 → v6
  • Linter now installed via go install (compiled with Go 1.26, no version mismatch)
  • actions/upload-artifact, actions/cache, codecov/codecov-action all bumped to v4
  • errcheck fix: json.Encode return value checked in respondJSON

README

  • Full rewrite reflecting complete backend scope
  • Added Circle badge, scoring weights table, validation constraints table
  • Full API reference table (13 endpoints)
  • WebSocket events table with message shape example
  • Updated project structure with all new packages
  • All 7 issues marked ✅ Done

Verified end-to-end:
Intent → proposal → scoring engine (0.841) → validation passed → settlement confirmed → leaderboard updated ✅

Issue #5 — Redis Pub/Sub Integration
- internal/ws/pubsub.go: Redis client, Subscribe/Publish/PublishLeaderboardUpdate
- internal/ws/hub.go: leaderboard channel key, RegisterLeaderboard, BroadcastLeaderboard
- All state changes (proposal, winner, settlement) now publish to Redis pub/sub
  alongside local WebSocket broadcast — enables horizontal scaling

Issue #6 — Scoring Engine
- internal/scoring/engine.go: deterministic 4-criterion weighted scorer
  Weights: execution efficiency (35%), win rate (25%), slippage (25%), reputation (15%)
- New agents seeded with neutral 0.5 on slippage + reputation — can compete from day one
- Tie-break: earlier proposal wins — fully deterministic, no randomness
- handlers/executions.go SelectWinner(): replaced stub with real engine
  Fetches agent_reputations, runs engine, persists individual scores back to proposals table

Issue #7 — Execution Validation Service
- internal/validation/service.go: 6-constraint validation — token pair, slippage,
  deadline, approved venue, intent ownership, agent ID presence
- All checks run on every call — caller always gets the full failure list
- handlers/executions.go ValidateExecution(): replaced stub with real service
  Failed proposals get score zeroed (penalises agent in future scoring)
  HTTP 422 Unprocessable Entity on failure (semantically correct)
- handlers/executions.go SettleExecution(): validation added as hard gate
  Cannot settle without passing — runs independently of /validate endpoint

Issue #8 — Circle Integration
- internal/circle/client.go: isolated Circle API client
  CreateWallet (deterministic idempotency via SHA1 UUID from wallet address)
  GetWallet / GetBalance (USDC balance reads)
  SendUSDC (micropayment settlement — agent execution fee)
  SimulateCCTPTransfer (cross-chain routing demo)
  Sandbox/production toggled from ENV — never hits prod from dev
- internal/handlers/circle.go: 4 new endpoints
  POST /api/v1/wallets, GET /api/v1/wallets/{id}/balance
  POST /api/v1/wallets/transfer, POST /api/v1/wallets/cctp
- handlers/executions.go SettleExecution(): Circle.SendUSDC() called after settlement
  Idempotency key tied to execution ID — retries never double-pay
  Agent total_intents_won + consecutive_successes incremented atomically (gorm.Expr)

CI/CD fixes
- golangci-lint-action upgraded v3 → v6
- Linter now installed via go install (compiled with Go 1.26, no version mismatch)
- actions/upload-artifact, actions/cache, codecov/codecov-action all bumped to v4
- errcheck fix: json.Encode return value checked in respondJSON

README
- Full rewrite reflecting complete backend scope
- Added Circle badge, scoring weights table, validation constraints table
- Full API reference table (13 endpoints)
- WebSocket events table with message shape example
- Updated project structure with all new packages
- All 7 issues marked ✅ Done

Verified end-to-end:
  Intent → proposal → scoring engine (0.841) → validation passed
  → settlement confirmed → leaderboard updated ✅
@Verifieddanny Verifieddanny added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 10, 2026
@Verifieddanny
Verifieddanny merged commit c93d68b into main Jun 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant