-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCrossChainBridge.sol
More file actions
74 lines (60 loc) · 2.22 KB
/
CrossChainBridge.sol
File metadata and controls
74 lines (60 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/access/Ownable.sol";
/**
* @title CrossChainBridge
* @dev Handles cross-chain NFT transfers and liquidity bridging
*/
contract CrossChainBridge is Ownable {
struct BridgeRequest {
uint256 tokenId;
address owner;
uint256 sourceChain;
uint256 targetChain;
uint256 timestamp;
bool completed;
}
mapping(bytes32 => BridgeRequest) public bridgeRequests;
mapping(uint256 => bool) public supportedChains;
event BridgeInitiated(bytes32 indexed requestId, uint256 tokenId, uint256 sourceChain, uint256 targetChain);
event BridgeCompleted(bytes32 indexed requestId, uint256 tokenId);
constructor() Ownable(msg.sender) {
// Initialize supported chains
supportedChains[1] = true; // Ethereum
supportedChains[137] = true; // Polygon
supportedChains[56] = true; // BSC
supportedChains[43114] = true; // Avalanche
supportedChains[42161] = true; // Arbitrum
}
function initiateBridge(
uint256 tokenId,
uint256 targetChain
) public returns (bytes32) {
require(supportedChains[targetChain], "Chain not supported");
bytes32 requestId = keccak256(abi.encodePacked(
tokenId,
msg.sender,
block.chainid,
targetChain,
block.timestamp
));
bridgeRequests[requestId] = BridgeRequest({
tokenId: tokenId,
owner: msg.sender,
sourceChain: block.chainid,
targetChain: targetChain,
timestamp: block.timestamp,
completed: false
});
emit BridgeInitiated(requestId, tokenId, block.chainid, targetChain);
return requestId;
}
function completeBridge(bytes32 requestId) public onlyOwner {
require(!bridgeRequests[requestId].completed, "Already completed");
bridgeRequests[requestId].completed = true;
emit BridgeCompleted(requestId, bridgeRequests[requestId].tokenId);
}
function addSupportedChain(uint256 chainId) public onlyOwner {
supportedChains[chainId] = true;
}
}