-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBridgedERC721.sol
128 lines (114 loc) · 3.94 KB
/
BridgedERC721.sol
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "../common/EssentialContract.sol";
import "./LibBridgedToken.sol";
/// @title BridgedERC721
/// @notice Contract for bridging ERC721 tokens across different chains.
/// @custom:security-contact security@taiko.xyz
contract BridgedERC721 is EssentialContract, ERC721Upgradeable {
/// @notice Address of the source token contract.
address public srcToken;
/// @notice Source chain ID where the token originates.
uint256 public srcChainId;
uint256[48] private __gap;
error BTOKEN_CANNOT_RECEIVE();
error BTOKEN_INVALID_BURN();
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _addressManager The address of the {AddressManager} contract.
/// @param _srcToken Address of the source token.
/// @param _srcChainId Source chain ID.
/// @param _symbol Symbol of the bridged token.
/// @param _name Name of the bridged token.
function init(
address _owner,
address _addressManager,
address _srcToken,
uint256 _srcChainId,
string memory _symbol,
string memory _name
)
external
initializer
{
// Check if provided parameters are valid
LibBridgedToken.validateInputs(_srcToken, _srcChainId, _symbol, _name);
__Essential_init(_owner, _addressManager);
__ERC721_init(_name, _symbol);
srcToken = _srcToken;
srcChainId = _srcChainId;
}
/// @dev Mints tokens.
/// @param _account Address to receive the minted token.
/// @param _tokenId ID of the token to mint.
function mint(
address _account,
uint256 _tokenId
)
public
nonReentrant
whenNotPaused
onlyFromNamed("erc721_vault")
{
_safeMint(_account, _tokenId);
}
/// @dev Burns tokens.
/// @param _account Address from which the token is burned.
/// @param _tokenId ID of the token to burn.
function burn(
address _account,
uint256 _tokenId
)
public
nonReentrant
whenNotPaused
onlyFromNamed("erc721_vault")
{
// Check if the caller is the owner of the token.
if (ownerOf(_tokenId) != _account) {
revert BTOKEN_INVALID_BURN();
}
_burn(_tokenId);
}
/// @notice Gets the name of the token.
/// @return The name.
function name() public view override(ERC721Upgradeable) returns (string memory) {
return LibBridgedToken.buildName(super.name(), srcChainId);
}
/// @notice Gets the symbol of the bridged token.
/// @return The symbol.
function symbol() public view override(ERC721Upgradeable) returns (string memory) {
return LibBridgedToken.buildSymbol(super.symbol());
}
/// @notice Gets the source token and source chain ID being bridged.
/// @return The source token's address.
/// @return The source token's chain ID.
function source() public view returns (address, uint256) {
return (srcToken, srcChainId);
}
/// @notice Returns the token URI.
/// @param _tokenId The token id.
/// @return The token URI following EIP-681.
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
return string(
abi.encodePacked(
LibBridgedToken.buildURI(srcToken, srcChainId), Strings.toString(_tokenId)
)
);
}
function _beforeTokenTransfer(
address, /*_from*/
address _to,
uint256, /*_firstTokenId*/
uint256 /*_batchSize*/
)
internal
virtual
override
{
if (_to == address(this)) revert BTOKEN_CANNOT_RECEIVE();
if (paused()) revert INVALID_PAUSE_STATUS();
}
}