Skip to content

Smart contract integration + UI polish#45

Merged
SumanthPal merged 33 commits intomainfrom
smartContractFeature
Feb 19, 2026
Merged

Smart contract integration + UI polish#45
SumanthPal merged 33 commits intomainfrom
smartContractFeature

Conversation

@janhqnguyen2020
Copy link
Copy Markdown
Collaborator

Summary

  • smart contract integration
  • 3 new columns added to Tournament table for smart contract linking
  • Frontend UX fixes (admin page, landing page, bet modal)
  • Error handling improvements across admin panel and betting flows

Root Page Scroll Lag

what was happening:

  • constant re-rendering
  • this caused disconnect and dynamic parts were causing lag

Admin Page Issues

what was wrong:

  • "Connect Wallet" button was off-centered on the auth gate screen
  • tournament cards had slide-in animation that replayed on filter changes (calendar icon "moving")
  • error messages showed raw contract hex data (unreadable)

Database Changes

3 new columns on Tournament model:

contract_tournament_idOptional[int], default None

  • links DB tournament (UUID) to on-chain tournament (integer ID)
  • smart contract uses sequential ints, not UUIDs
  • when admin clicks "Create On-Chain", contract emits event with this ID

agent_contract_mappingJSON dict, default {}

  • maps agent UUIDs to contract-side integer IDs
  • example: {"agent-uuid-1": 1, "agent-uuid-2": 2}
  • sorted deterministically to prevent settlement mismatches
  • without this, no way to link on-chain bets back to DB agents

betting_closedbool, default False

  • tracks whether betting closed on-chain
  • contract requires closeBetting() before settleTournament()
  • keeps DB in sync with contract state

these columns have safe defaults — existing data is unaffected


Backend

tournament lifecycle endpoints (all admin-gated):

  • POST /{id}/onchain/create — creates on-chain, stores contract_tournament_id + agent mapping
  • POST /{id}/onchain/close — closes betting on-chain, sets betting_closed=True
  • POST /{id}/onchain/settle — settles with winner, updates agent win stats
  • POST /{id}/onchain/cancel — cancels on-chain, refunds bets
  • POST /{id}/start — initializes agent states, sets status=live

auth:

  • POST /auth/wallet — verifies wallet signature, returns JWT with role
  • admin addresses from ADMIN_ADDRESSES env var
  • require_admin dependency gates mutation endpoints

Data Shape Reference

tournament (backend → frontend):

{
  "id": "6b1a0a2c-...",
  "name": "February Trading Cup",
  "status": "live",
  "start_date": "2026-02-01T00:00:00Z",
  "end_date": "2026-02-07T00:00:00Z",
  "prize_pool": "10000.00",
  "contract_tournament_id": 3,
  "agent_contract_mapping": {
    "agent-uuid-1": 1,
    "agent-uuid-2": 2
  },
  "betting_closed": false
}

problems should be fixed. I have been referring to the wallet you gave me and I have been able to successfully chain agents, start tournament, cancel tournament, and end betting. I have checked that betting interface works; despite this I noticed that smart contract integration has led me to struggle with actual betting since I do not have amount in my own wallet. everything else works.

This PR  is also in relation to the frontend-expansion pull request

janhqnguyen2020 and others added 23 commits November 27, 2025 23:58
- New home dashboard UI (agents, trades, bets, chart)
- Updated mock data
- Added agent API router
- Updated market data and trading endpoints
- Added pyproject + tools for backend
- Added runtime_agents router
- Moved market_data into app/tools
- Added tools/__init__.py
- Updated executor + main imports
- Removed old tools folder
Backend:
- Add 3 Tournament columns (contract_tournament_id, agent_contract_mapping, betting_closed)
- Add on-chain endpoints: create, close betting, settle, cancel tournaments
- JWT wallet auth with admin role gating
- Update seed/reset scripts to match current schema

Frontend:
- Fix admin page: center wallet button, static tournament cards, clean error messages
- Fix landing page: scroll perf (ParallaxLayer extraction), animation warnings
- Fix BetModal: clean viem/contract error display
- Improve mutation hooks: surface actual backend error messages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@janhqnguyen2020
Copy link
Copy Markdown
Collaborator Author

HI HI!

The last commit a few hours ago was me merging my changes with the main branch as of 02/08/26.

Front-end issues:

  • Addressed a few bugs (animation lag, distracting animations, etc)
  • noticed that navbar for the informational pages (About, FAQ, Terms) was rooted in landing page. so new navbar is set up for those sections

Back-end:
Our backend uses UUIDs as primary keys, while the smart contracts reference entities using incremental uint256 IDs (e.g. tournamentId = 0, 1, 2, ...). Since contracts can’t work with UUIDs, we need a translation layer on the backend.

This commit keeps that mapping explicit in the database:

  • contract_tournament_id → links a DB tournament (UUID) to its on-chain tournament ID

  • agent_contract_id → maps DB agent UUIDs to their on-chain integer IDs

  • betting_closed → mirrors whether closeBetting() has been called on-chain for lifecycle correctness

These fields are only used by the scheduler / settlement flow and do not replace UUID usage elsewhere. Other services and the frontend continue to reference tournaments and agents by UUID, so this shouldn’t ripple into unrelated code.

@janhqnguyen2020
Copy link
Copy Markdown
Collaborator Author

Error check

After last commit, there were some tests that github ran and it failed. One error was that there was unsupported token: WETH and the other was the PERPEXLITY_API_KEY not being found. I think the unsupported token is an issue coming from either:

  • backend/app/agents/tools/make_trade_tool.py
  • backend/tests/test_make_trade_tool.py

@SumanthPal SumanthPal merged commit de5deec into main Feb 19, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants