Skip to content

feat: wire backend to deployed BNB Testnet contracts - #3

Open
OmLanke with Copilot wants to merge 2 commits into
mainfrom
copilot/connect-backend-to-contracts
Open

feat: wire backend to deployed BNB Testnet contracts#3
OmLanke with Copilot wants to merge 2 commits into
mainfrom
copilot/connect-backend-to-contracts

Conversation

Copilot AI commented Feb 27, 2026

Copy link
Copy Markdown

The backend had no live connection to the deployed GhostPool/GhostPaymaster contracts — contract addresses were placeholders, deposits required manual API calls, and nullifier/commitment checks were DB-only.

Contract ABI + Address Layer

  • src/contracts/abis.ts — typed minimal ABIs for GhostPool and GhostPaymaster (view functions + events the backend actually calls)
  • src/contracts/addresses.ts — chainId-keyed address registry hardcoded from deployments/97/addresses.json; env vars always override

Extended Contract Reads (paymasterClient.ts)

Added GhostPaymaster reads:

  • isNullifierSpentOnChain(hash) — authoritative on-chain nullifier check
  • getBnbToUsdcRate() — current fee conversion rate
  • isZkVerificationEnabled() — paymaster verification flag

Refactored to use shared ABIs; exported publicClient for reuse.

On-Chain Deposit Indexer (src/indexer/depositIndexer.ts)

Polls GhostPool.Deposit events every 15s (configurable via INDEXER_POLL_INTERVAL_MS). Auto-inserts new deposits into the off-chain Merkle tree and DB — removes the requirement for the frontend to manually call POST /pool/deposit.

// First run looks back ~24h of blocks, then tracks from last processed block
const fromBlock = latestBlock > INITIAL_LOOKBACK_BLOCKS
  ? latestBlock - INITIAL_LOOKBACK_BLOCKS : 0n;

Route Hardening

  • POST /pool/deposit — now calls isCommitmentInserted on-chain before accepting; rejects if commitment not yet in GhostPool
  • GET /pool/status — response now includes onChain.merkleRoot and onChain.nextLeafIndex read live from the contract
  • POST /relay — dual nullifier check: local DB (fast path) then isNullifierSpentOnChain (authoritative)

Config

  • .env.example updated with BNB Testnet (chainId 97) deployed addresses pre-filled
  • INDEXER_POLL_INTERVAL_MS env var added

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: OmLanke <92863779+OmLanke@users.noreply.github.com>
Copilot AI changed the title [WIP] Connect backend to smart contracts feat: wire backend to deployed BNB Testnet contracts Feb 27, 2026
@OmLanke
OmLanke marked this pull request as ready for review February 27, 2026 16:44
@OmLanke
OmLanke requested a review from Arnab-Afk February 27, 2026 16:49
@OmLanke

OmLanke commented Feb 27, 2026

Copy link
Copy Markdown
Collaborator

@Arnab-Afk Looks good to me. Please check

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.

2 participants