Skip to content

Refactor ERC20-NEAR Bridge Checker to TypeScript + Zorsh#290

Merged
karim-en merged 4 commits intomigrationfrom
finalization-script
Apr 7, 2025
Merged

Refactor ERC20-NEAR Bridge Checker to TypeScript + Zorsh#290
karim-en merged 4 commits intomigrationfrom
finalization-script

Conversation

@r-near
Copy link
Copy Markdown
Contributor

@r-near r-near commented Mar 7, 2025

This PR refactors the ERC20 Ethereum to NEAR Bridge transaction finalization verifier with these technical improvements:

Changes

  • TypeScript Migration: Full rewrite from JavaScript to TypeScript
  • Zorsh Integration: I wrote a library for type-safe Borsh serialization - switched to that.
  • Type Safety: Added proper typings for EVM proofs and all data structures
  • Environment Validation: Added Envalid for type-safe environment variable validation
  • Error Handling: Implemented robust error catching for each transaction
  • UX Improvements: Added console coloring and better progress reporting
  • Dev Setup: Updated to modern pnpm/tsx execution environment

Technical Notes

  • Zorsh provides a strongly-typed schema-based approach to Borsh, which simplifies the serialization of EVM proofs
  • Type-safe serialization eliminates several potential bugs in the original implementation
  • Proper error isolation prevents individual transaction failures from crashing the entire process
  • The EVMProofSchema now has correct BigInt handling for log_index and receipt_index

Notes

  • Run with pnpm tsx index.ts instead of the previous node index.js
  • Environment variables schema is now validated at runtime
  • Added TypeScript types for improved IDE support

@r-near r-near requested review from karim-en and olga24912 and removed request for karim-en March 7, 2025 18:41
Comment thread migration/checkERC20EthToNearTransfersFinalization/README.md Outdated
Comment thread migration/checkERC20EthToNearTransfersFinalization/index.ts Outdated
Comment thread migration/checkERC20EthToNearTransfersFinalization/index.ts Outdated
@r-near r-near force-pushed the finalization-script branch from 5fbc113 to 12be02d Compare March 27, 2025 18:17
@r-near r-near requested a review from olga24912 March 27, 2025 18:38
NETWORK_ETH: str({ choices: ["mainnet", "goerli", "sepolia"] }),
NETWORK_NEAR: str({ choices: ["mainnet", "testnet"] }),
BRIDGE_TOKEN_FACTORY_ACCOUNT_ID: str(),
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add INFURA_API_KEY here.

/home/olga/Aurora/MainnetMigration/AuroraEthConnectorMainnetMigration/omni-bridge-migration/migration/checkERC20EthToNearTransfersFinalization/node_modules/.pnpm/envalid@8.0.0/node_modules/envalid/src/middleware.ts:49
          throw new ReferenceError(
                ^


ReferenceError: [envalid] Env var INFURA_API_KEY was accessed but not validated. This var is set in the environment; please add an envalid validator for it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed: 4461366

@karim-en karim-en merged commit 67d2f33 into migration Apr 7, 2025
4 of 11 checks passed
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