CrossChainBridgeERC721
Manages deposits and releases for ERC721 bridge transactions

Functions

deposit

Accepts ERC721 deposits that should be bridged into another network (effectively starting a bridge transaction). The collection must be whitelisted in order to be accepted for a deposit.
1
function deposit(
2
address collectionAddress,
3
uint256 tokenId,
4
address receiverAddress,
5
uint256 targetChainId
6
) external payable whenNotPaused {
7
// check if token was minted from an original collection or minted by this bridge
8
if (mintedDeposits[collectionAddress][tokenId]) {
9
// no whitelist check necessary since token was minted by this bridge
10
MintableERC721(collectionAddress).burn(tokenId);
11
} else {
12
if (!officialCollectionWhitelist[collectionAddress]) revert Unauthorized();
13
// transfer the token into the bridge
14
IERC721Upgradeable(collectionAddress).safeTransferFrom(_msgSender(), address(this), tokenId);
15
}
16
17
// For every deposit we increase the counter to create a unique ID that can be used on the target side bridge to avoid double releases
18
depositCount = depositCount + 1;
19
20
// We always dispatch the deposit event with the "true" token address in the source network
21
emit TokenDeposited(collectionAddress, tokenId, receiverAddress, _getChainID(), targetChainId, depositCount);
22
}
Copied!

Parameters:

Name
Type
Description
collectionAddress
address
the address of the ERC721 contract the collection was issued with
tokenId
uint256
the (native) ID of the ERC721 token that should be bridged
receiverAddress
address
the address which should receive the bridged token in the target network
targetChainId
uint256
chain ID of the target network

release

Releases an ERC721 token in this network after a deposit was made in the source network (effectively completing a bridge transaction)
1
function release(
2
uint8[] memory sigV,
3
bytes32[] memory sigR,
4
bytes32[] memory sigS,
5
address receiverAddress,
6
address sourceNetworkCollectionAddress,
7
uint256 tokenId,
8
uint256 depositChainId,
9
uint256 depositNumber
10
) external payable whenNotPaused {
11
// check input parameters
12
if (releasedDeposits[depositChainId][depositNumber]) revert AlreadyUsed();
13
if (
14
!multiSignatureOracle.signaturesCheckERC721(
15
sigV,
16
sigR,
17
sigS,
18
receiverAddress,
19
sourceNetworkCollectionAddress,
20
tokenId,
21
depositChainId,
22
depositNumber
23
)
24
) revert Unauthorized();
25
26
// get collection address in release network
27
address collectionAddress = sourceNetworkCollectionAddress;
28
if (outsidePeggedCollections[collectionAddress] != address(0)) {
29
collectionAddress = outsidePeggedCollections[collectionAddress];
30
}
31
32
// calculate bridging fee
33
uint256 nftBridgingFee = defaultBridgeFee;
34
if (bridgeFees[collectionAddress] > 0) {
35
nftBridgingFee = bridgeFees[collectionAddress];
36
}
37
38
// check if transaction contains enough native tokens to pay the bridging fee
39
if (msg.value < nftBridgingFee) revert InvalidMessageValue(msg.value, nftBridgingFee);
40
41
// check if to-be-released token is part of the official collection (whitelisted)
42
if (officialCollectionWhitelist[collectionAddress] == true) {
43
ERC721Upgradeable(collectionAddress).safeTransferFrom(address(this), receiverAddress, tokenId);
44
} else {
45
MintableERC721(collectionAddress).mint(receiverAddress, tokenId);
46
mintedDeposits[collectionAddress][tokenId] = true;
47
}
48
49
// update records to track released deposits
50
releasedDeposits[depositChainId][depositNumber] = true;
51
52
// release successful, deposit event
53
emit TokenReleased(collectionAddress, tokenId, receiverAddress, depositChainId, depositNumber);
54
}
55
Copied!

Parameters:

Name
Type
Description
sigV
uint8
Array of recovery Ids for the signature
sigR
bytes32
Array of R values of the signatures
sigS
bytes32
Array of S values of the signatures
receiverAddress
address
the address to which the bridged token should be released to
sourceNetworkCollectionAddress
address
the address of the ERC721 collection in the network in which the deposit was made
tokenId
uint256
The tokenId to be released
depositChainId
uint256
chain ID of the network in which the deposit was made
depositNumber
uint256
The deposit ID of the corresponding deposit
Copy link