A cross-chain bridge system that enables token transfers between BSC (Binance Smart Chain) and Studio blockchain.
The Studio Blockchain Bridge is a secure and efficient solution for transferring tokens between BSC and Studio blockchain networks. It consists of smart contracts deployed on both chains and a relayer service that monitors for deposit events and executes proposals.
The bridge system consists of the following components:
- Bridge Contracts: Main entry points for users, handling deposit events and proposal execution.
- Handler Contracts:
- ERC20HandlerFixed: Handles ERC20 token deposits and withdrawals
- NativeHandler: Handles native token (BNB/STO) deposits and withdrawals
- Relayer Service: A TypeScript application that monitors both chains for deposit events and executes proposals on the destination chain.
The bridge currently supports the following tokens:
-
USDT
- BSC: BEP20 USDT
- Studio: Studio USDT
-
USDC
- BSC: BEP20 USDC
- Studio: Studio USDC
-
3DC (3D City)
- BSC: BEP20 3DC
- Studio: Studio 3DC
-
Native Tokens (BNB/STO)
-
Deposit Phase (Source Chain):
- User approves the handler contract to spend their tokens (for ERC20 tokens)
- User calls
deposit()on the source chain's Bridge contract - The Bridge contract locks or burns tokens
- A
Depositevent is emitted
-
Relay Phase:
- The relayer service monitors both chains for
Depositevents - When a
Depositevent is detected, the relayer callsvoteProposal()on the destination chain's Bridge contract
- The relayer service monitors both chains for
-
Execution Phase (Destination Chain):
- Once enough relayers have voted, the proposal is executed
- The Handler contract releases or mints tokens to the recipient
- Fee System: Configurable fee percentage with chain-specific and token-specific multipliers
- Decimal Handling: Automatic handling of tokens with different decimal places across chains
- Rate Limiting: Optional rate limiter to prevent excessive transfers
- STO Gas Distribution: Automatic distribution of STO for gas when bridging from BSC to Studio
- Fallback RPC URLs: Support for multiple RPC endpoints for resilience
- Security Features: Blacklisting, pausing, and reentrancy protection
- Node.js (v16+)
- npm or yarn
- Access to BSC and Studio blockchain RPC endpoints
- Private key for the relayer account (must be registered as a relayer on both bridge contracts)
-
Clone the repository:
git clone https://github.com/studio-blockchain/bridge.git cd bridge -
Install dependencies:
npm install
-
Create a
.envfile based on.env.example:cp .env.example .env
-
Edit the
.envfile with your configuration:PRIVATE_KEY=your_private_key_here STUDIO_RPC_URL=https://mainnet2.studio-blockchain.com BSC_RPC_URL=https://bsc-dataseed.binance.org/ STO_GAS_PROVIDER_KEY=your_sto_gas_provider_key_here [email protected] [email protected]
-
Deploy the Bridge contract:
npx hardhat run scripts/deploy-studio-bridge.js --network studio npx hardhat run scripts/deploy-studio-bridge.js --network bsc
-
Register the relayer on both bridge contracts:
npx hardhat run scripts/register-relayer-bsc.js --network bsc npx hardhat run scripts/register-relayer-studio.js --network studio
-
Verify the contracts on the respective block explorers:
npx hardhat run scripts/verify-studio-bridge.js --network studio npx hardhat run scripts/verify-bridge-contracts.js --network bsc
-
Compile the TypeScript code:
npx tsc multichain-relayer-fixed-nonce.ts --outDir dist --target ES2020 --module commonjs --esModuleInterop --skipLibCheck --resolveJsonModule
-
Start the relayer service:
node dist/multichain-relayer-fixed-nonce.js
-
For production, use a process manager like PM2:
npm install -g pm2 pm2 start ecosystem.config.js pm2 save pm2 startup
To add a new token to the bridge:
- Generate a unique resource ID for the token
- Set the resource ID in the Bridge and Handler contracts on both chains
- Configure the token decimals on both chains
Example for adding a new token:
npx hardhat run scripts/add-new-token-to-bridge.js --network studio
npx hardhat run scripts/add-new-token-to-bridge.js --network bscMonitor the bridge status using the provided scripts:
# Check bridge status
npx hardhat run scripts/check-bridge-status.js --network studio
# Check relayer balance
npx hardhat run scripts/check-relayer-balance.js --network bsc
# Check deposit events
npx hardhat run scripts/check-bsc-deposit-events.js --network bscCommon issues and solutions:
-
Transaction Reverted on Destination Chain:
- Check token decimals configuration
- Ensure relayer has enough gas
- Verify resource ID mappings
-
Relayer Not Processing Deposits:
- Check relayer service status
- Verify relayer registration on both chains
- Check RPC connectivity
-
Incorrect Token Amounts:
- Verify token decimals configuration
- Check fee percentage settings
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- The Studio Blockchain team
- The Ethereum and Binance Smart Chain communities