A Solana program that enables cross-chain NFT transfers and interactions between ZetaChain and Solana, implementing the Universal NFT standard for seamless interoperability across multiple blockchain networks.
- Cross-Chain NFT Transfers: Send NFTs from Solana to other chains (Ethereum, BSC, Polygon, etc.) via ZetaChain
- Incoming NFT Processing: Mint NFTs on Solana that originated from other chains
- Universal Metadata: Support for cross-chain metadata and ownership verification
- ZetaChain Gateway Integration: Seamless integration with ZetaChain's cross-chain messaging protocol
- TSS (Threshold Signature Scheme) Support: Enhanced security for cross-chain operations
- Replay Protection: Prevents duplicate transaction execution
- Ownership Verification: Cryptographic proof verification for cross-chain ownership
- Access Control: Role-based permissions for administrative functions
- Compute Budget Management: Efficient instruction execution
- Rent Exemption Handling: Proper account sizing and rent management
- Token Account Creation: Automatic associated token account management
- Signer Validation: Robust signer verification and management
src/
βββ lib.rs # Main program entry point
βββ state.rs # Account state definitions
βββ errors.rs # Custom error types
βββ constants.rs # Program constants
βββ instructions/ # Instruction handlers
βββ mod.rs
βββ initialize.rs # Program initialization
βββ mint_nft.rs # NFT minting
βββ transfer_nft.rs # Local NFT transfers
βββ cross_chain_transfer.rs # Cross-chain transfers
βββ process_incoming_nft.rs # Incoming NFT processing
βββ verify_cross_chain_ownership.rs # Ownership verification
βββ update_metadata.rs # Metadata updates
βββ burn_nft.rs # NFT burning
βββ setup_gateway.rs # Gateway configuration
- ProgramState: Global program configuration and statistics
- ZetaChainGatewayState: ZetaChain gateway configuration and supported chains
- NFTMetadata: Individual NFT metadata and cross-chain information
- CrossChainTransferState: Cross-chain transfer status and tracking
- OwnershipVerificationState: Cross-chain ownership verification records
- Solana (Chain ID: 1)
- Ethereum (Chain ID: 2)
- BSC (Chain ID: 3)
- Polygon (Chain ID: 4)
- Avalanche (Chain ID: 5)
- Arbitrum (Chain ID: 6)
- Optimism (Chain ID: 7)
- Base (Chain ID: 8)
- Linea (Chain ID: 9)
- Mantle (Chain ID: 10)
- Scroll (Chain ID: 11)
- Berachain (Chain ID: 12)
- Bitcoin (Chain ID: 13)
- Rust 1.70+
- Solana CLI 1.17+
- Anchor Framework 0.29+
- Node.js 18+
- Yarn or npm
-
Clone the repository
git clone <repository-url> cd zetachain_superteam
-
Install dependencies
yarn install # or npm install -
Build the program
anchor build
-
Generate TypeScript types
anchor build
-
Update Anchor.toml
[programs.devnet] zetachain_universal_nft = "YOUR_PROGRAM_ID" [provider] cluster = "devnet" wallet = "~/.config/solana/id.json"
-
Set your Solana keypair
solana config set --keypair ~/.config/solana/id.json
-
Switch to devnet
solana config set --url devnet
# Run all tests
anchor test
# Run specific test file
anchor test tests/universal-nft.ts
# Run with verbose output
anchor test -- --nocaptureThe test suite covers:
- Program initialization
- NFT minting and burning
- Local NFT transfers
- Cross-chain transfer initiation
- Incoming NFT processing
- Cross-chain ownership verification
- Gateway configuration updates
- Metadata management
import { Program } from "@coral-xyz/anchor";
import { ZetachainUniversalNft } from "../target/types/zetachain_universal_nft";
const program = anchor.workspace.ZetachainUniversalNft as Program<ZetachainUniversalNft>;
// Initialize program
const tx = await program.methods
.initialize("https://example.com/metadata.json", new anchor.BN(1000))
.accounts({
programState: programStatePda,
gatewayState: gatewayStatePda,
authority: authority.publicKey,
systemProgram: SystemProgram.programId,
rent: SYSVAR_RENT_PUBKEY,
})
.signers([authority])
.rpc();// Mint NFT with cross-chain metadata
const tx = await program.methods
.mintNft(
"https://example.com/metadata.json",
new anchor.BN(2), // Ethereum chain ID
new Uint8Array([1, 2, 3, 4, 5]) // Cross-chain data
)
.accounts({
programState: programStatePda,
gatewayState: gatewayStatePda,
mint: mint.publicKey,
mintAta: userTokenAccount,
nftMetadata: nftMetadataPda,
payer: user.publicKey,
mintAuthority: user.publicKey,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
})
.signers([user, mint])
.rpc();// Transfer NFT to Ethereum
const tx = await program.methods
.crossChainTransfer(
new anchor.BN(2), // Ethereum chain ID
recipientAddress, // Ethereum recipient address
crossChainData
)
.accounts({
programState: programStatePda,
gatewayState: gatewayStatePda,
nftMetadata: nftMetadataPda,
nftMint: nftMint.publicKey,
ownerTokenAccount: ownerTokenAccount,
transferState: transferStatePda,
owner: owner.publicKey,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
})
.signers([owner])
.rpc();// Process NFT coming from Ethereum
const tx = await program.methods
.processIncomingNft(
"https://example.com/incoming-metadata.json",
new anchor.BN(2), // Ethereum chain ID
incomingCrossChainData,
zetaTxHash
)
.accounts({
programState: programStatePda,
gatewayState: gatewayStatePda,
transferState: transferStatePda,
incomingNftMint: incomingMint.publicKey,
recipientTokenAccount: recipientTokenAccount,
nftMetadata: nftMetadataPda,
payer: recipient.publicKey,
recipient: recipient.publicKey,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
})
.signers([recipient, incomingMint])
.rpc();The program integrates with ZetaChain's protocol contracts to enable cross-chain operations:
- Gateway Contract: Handles cross-chain message passing
- TSS Verification: Ensures message authenticity
- Replay Protection: Prevents duplicate message processing
- Chain ID Validation: Supports all ZetaChain-connected networks
- Outgoing Transfer: NFT burned on Solana β Message sent to ZetaChain β NFT minted on target chain
- Incoming Transfer: NFT burned on source chain β Message received from ZetaChain β NFT minted on Solana
- Program Authority: Only authorized accounts can update gateway configuration
- NFT Ownership: Only NFT owners can transfer or burn their NFTs
- Metadata Updates: Only NFT owners can update metadata
- TSS Verification: All cross-chain messages verified through ZetaChain's TSS
- Replay Protection: Timestamp-based replay protection for cross-chain operations
- Data Validation: Comprehensive validation of cross-chain data and addresses
- Account Validation: Proper account ownership and derivation verification
- Signer Verification: Multi-signer support for complex operations
- Rent Management: Proper account sizing and rent exemption handling
# Deploy to devnet
anchor deploy --provider.cluster devnet
# Verify deployment
solana program show <PROGRAM_ID> --url devnet# Deploy to mainnet
anchor deploy --provider.cluster mainnet
# Verify deployment
solana program show <PROGRAM_ID> --url mainnet- Total NFTs minted
- Cross-chain transfer success rate
- Gateway configuration updates
- Error rates and types
- Cross-chain transfer status
- ZetaChain transaction hashes
- Ownership verification records
- Metadata update history
- Follow Rust and Solana best practices
- Add comprehensive tests for new features
- Update documentation for API changes
- Ensure security best practices are followed
- All new features must have corresponding tests
- Cross-chain functionality must be tested thoroughly
- Security features must be validated
- Performance benchmarks for critical operations
Note: This program is designed for educational and development purposes. Always test thoroughly on devnet before deploying to mainnet. Cross-chain operations involve multiple networks and should be tested extensively to ensure reliability and security.