Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(protocol): add batch transfer and burn for BridgedERC721 #17058

Merged
merged 32 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f59a182
Change to transfer and burn pattern
May 8, 2024
b36902d
remove for loop
May 8, 2024
6e73966
address pr comments
May 8, 2024
384632d
Merge branch 'main' into vault_burn_design_fix
adaki2004 May 8, 2024
75389f4
forge fmt & update contract layout table
adaki2004 May 8, 2024
028ce30
Update packages/protocol/contracts/tokenvault/BridgedERC721.sol
dantaik May 8, 2024
a69c7d9
forge fmt & update contract layout table
dantaik May 8, 2024
251e1af
remove pnpm-lock
May 8, 2024
0ee4bde
add batch mint/burn function for bridged ERC721 tokens
dantaik May 9, 2024
9decea2
Revert "add batch mint/burn function for bridged ERC721 tokens"
dantaik May 9, 2024
ddabdd8
Reapply "add batch mint/burn function for bridged ERC721 tokens"
dantaik May 9, 2024
915f8b1
forge fmt & update contract layout table
dantaik May 9, 2024
67b9451
Merge branch 'main' into vault_burn_design_fix
dantaik May 9, 2024
4704776
Merge branch 'vault_burn_design_fix' into batch_erc721
dantaik May 9, 2024
f4b1b78
Update ERC721Vault.sol
dantaik May 9, 2024
362cc15
Merge branch 'batch_erc721' of ssh://github.com/taikoxyz/taiko-mono i…
dantaik May 9, 2024
c547326
more
dantaik May 9, 2024
9e9e429
more
dantaik May 9, 2024
0fc2024
Update packages/protocol/contracts/tokenvault/BridgedERC20.sol
dantaik May 9, 2024
abd90dd
fix
dantaik May 9, 2024
0d7a806
Merge branch 'batch_erc721' of ssh://github.com/taikoxyz/taiko-mono i…
dantaik May 9, 2024
5ed6fb7
forge fmt & update contract layout table
dantaik May 9, 2024
a0d4b61
more
dantaik May 9, 2024
df8aaf7
Revert "more"
dantaik May 9, 2024
10d5691
Revert "Merge branch 'batch_erc721' of ssh://github.com/taikoxyz/taik…
dantaik May 9, 2024
ad7c372
Revert "fix"
dantaik May 9, 2024
5e6cf39
Revert "more"
dantaik May 9, 2024
0dbcc0e
Revert "more"
dantaik May 9, 2024
2a04726
Merge branch 'batch_erc721' of ssh://github.com/taikoxyz/taiko-mono i…
dantaik May 9, 2024
1293c46
Merge branch 'main' into batch_erc721
dantaik May 9, 2024
5f85450
more
dantaik May 9, 2024
0690818
Revert "more"
dantaik May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/protocol/contracts/tokenvault/BridgedERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,41 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable {

/// @dev Mints tokens.
/// @param _account Address to receive the minted token.
/// @param _tokenId ID of the token to mint.
function mint(
/// @param _tokenIds IDs of the tokens to mint.
function batchMint(
address _account,
uint256 _tokenId
uint256[] memory _tokenIds
)
external
whenNotPaused
onlyFromNamed(LibStrings.B_ERC721_VAULT)
nonReentrant
{
_safeMint(_account, _tokenId);
for (uint256 i; i < _tokenIds.length; ++i) {
_safeMint(_account, _tokenIds[i]);
}
}

/// @dev Burns tokens.
/// @param _tokenId ID of the token to burn.
function burn(uint256 _tokenId)
/// @param _tokenIds IDs of the tokens to burn.
function batchBurn(uint256[] memory _tokenIds)
external
whenNotPaused
onlyFromNamed(LibStrings.B_ERC721_VAULT)
nonReentrant
{
// Check if the caller is the owner of the token. Somehow this is not done inside the
// _burn() function below.
if (ownerOf(_tokenId) != msg.sender) {
revert BTOKEN_INVALID_BURN();
for (uint256 i; i < _tokenIds.length; ++i) {
// Check if the caller is the owner of the token. Somehow this is not done inside the
// _burn() function below.
if (ownerOf(_tokenIds[i]) != msg.sender) revert BTOKEN_INVALID_BURN();
_burn(_tokenIds[i]);
}
}

function safeBatchTransferFrom(address _from, address _to, uint256[] memory _tokenIds) public {
for (uint256 i; i < _tokenIds.length; ++i) {
safeTransferFrom(_from, _to, _tokenIds[i], "");
}
_burn(_tokenId);
}

/// @notice Gets the source token and source chain ID being bridged.
Expand Down
18 changes: 6 additions & 12 deletions packages/protocol/contracts/tokenvault/ERC721Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver {
}
} else {
token_ = _getOrDeployBridgedToken(_ctoken);
for (uint256 i; i < _tokenIds.length; ++i) {
BridgedERC721(token_).mint(_to, _tokenIds[i]);
}
BridgedERC721(token_).batchMint(_to, _tokenIds);
}
}

Expand All @@ -196,12 +194,10 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver {
CanonicalNFT storage _ctoken = bridgedToCanonical[_op.token];
if (_ctoken.addr != address(0)) {
ctoken_ = _ctoken;
for (uint256 i; i < _op.tokenIds.length; ++i) {
BridgedERC721(_op.token).safeTransferFrom(
msg.sender, address(this), _op.tokenIds[i]
);
BridgedERC721(_op.token).burn(_op.tokenIds[i]);
}
BridgedERC721(_op.token).safeBatchTransferFrom(
msg.sender, address(this), _op.tokenIds
);
BridgedERC721(_op.token).batchBurn(_op.tokenIds);
} else {
ctoken_ = CanonicalNFT({
chainId: uint64(block.chainid),
Expand All @@ -211,9 +207,7 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver {
});

for (uint256 i; i < _op.tokenIds.length; ++i) {
ERC721Upgradeable(_op.token).safeTransferFrom(
msg.sender, address(this), _op.tokenIds[i]
);
IERC721(_op.token).safeTransferFrom(msg.sender, address(this), _op.tokenIds[i]);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/protocol/test/tokenvault/ERC721Vault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,10 @@ contract ERC721VaultTest is TaikoTest {
// Also Vault cannot burn tokens it does not own (even if the priv key compromised)
vm.prank(address(destChainErc721Vault), address(destChainErc721Vault));
vm.expectRevert(BridgedERC721.BTOKEN_INVALID_BURN.selector);
BridgedERC721(deployedContract).burn(1);

tokenIds = new uint256[](1);
tokenIds[0] = 1;
BridgedERC721(deployedContract).batchBurn(tokenIds);

// After approve() ERC721Vault can transfer and burn
vm.prank(Alice, Alice);
Expand Down