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

fix(protocol): revert impl deployment V2 #14621

Merged
merged 10 commits into from
Sep 3, 2023
24 changes: 19 additions & 5 deletions packages/protocol/contracts/tokenvault/ERC1155Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable {
|| super.supportsInterface(interfaceId);
}

/// @dev Encodes sending bridged or canonical ERC1155 tokens to the user.
/// @param user The user's address.
/// @param opt BridgeTransferOp data.
/// @return msgData Encoded message data.
function _encodeDestinationCall(
address user,
BridgeTransferOp memory opt
Expand Down Expand Up @@ -314,7 +318,9 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable {
);
}

/// @dev Returns the contract address per given canonical token.
/// @dev Retrieve or deploy a bridged ERC1155 token contract.
/// @param ctoken CanonicalNFT data.
/// @return btoken Address of the bridged token contract.
function _getOrDeployBridgedToken(CanonicalNFT memory ctoken)
private
returns (address btoken)
Expand All @@ -325,18 +331,26 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable {
}
}

/// @dev Deploys a new BridgedNFT contract and initializes it. This must be
/// called before the first time a btoken is sent to this chain.
/// @dev Deploy a new BridgedNFT contract and initialize it.
/// This must be called before the first time a bridged token is sent to
/// this chain.
/// @param ctoken CanonicalNFT data.
/// @return btoken Address of the deployed bridged token contract.
function _deployBridgedToken(CanonicalNFT memory ctoken)
private
returns (address btoken)
{
ProxiedBridgedERC1155 bridgedToken = new ProxiedBridgedERC1155();
address bridgedToken = Create2Upgradeable.deploy({
amount: 0, // amount of Ether to send
salt: keccak256(abi.encode(ctoken)),
bytecode: type(ProxiedBridgedERC1155).creationCode
});

btoken = LibVaultUtils.deployProxy(
address(bridgedToken),
owner(),
bytes.concat(
bridgedToken.init.selector,
ProxiedBridgedERC1155(bridgedToken).init.selector,
abi.encode(
address(_addressManager),
ctoken.addr,
Expand Down
26 changes: 24 additions & 2 deletions packages/protocol/contracts/tokenvault/ERC20Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ contract ERC20Vault is
return interfaceId == type(IRecallableMessageSender).interfaceId;
}

/// @dev Encodes sending bridged or canonical ERC20 tokens to the user.
/// @param user The user's address.
/// @param token The token address.
/// @param to To address.
/// @param amount Amount to be sent.
/// @return msgData Encoded message data.
/// @return _amount Token amount left in the contract. (Todo Daniel: why we
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
/// calcualte the left amount ? Why is it necessary ? It seems ambigous that
/// in one case we just return the amount while in other case we calculate
/// the left tokens.)
function _encodeDestinationCall(
address user,
address token,
Expand Down Expand Up @@ -315,6 +325,9 @@ contract ERC20Vault is
);
}

/// @dev Retrieve or deploy a bridged ERC20 token contract.
/// @param ctoken CanonicalERC20 data.
/// @return btoken Address of the bridged token contract.
function _getOrDeployBridgedToken(CanonicalERC20 calldata ctoken)
private
returns (address btoken)
Expand All @@ -326,17 +339,26 @@ contract ERC20Vault is
}
}

/// @dev Deploy a new BridgedERC20 contract and initialize it.
/// This must be called before the first time a bridged token is sent to
/// this chain.
/// @param ctoken CanonicalERC20 data.
/// @return btoken Address of the deployed bridged token contract.
function _deployBridgedToken(CanonicalERC20 calldata ctoken)
private
returns (address btoken)
{
ProxiedBridgedERC20 bridgedToken = new ProxiedBridgedERC20();
address bridgedToken = Create2Upgradeable.deploy({
amount: 0, // amount of Ether to send
salt: keccak256(abi.encode(ctoken)),
bytecode: type(ProxiedBridgedERC20).creationCode
});

btoken = LibVaultUtils.deployProxy(
address(bridgedToken),
owner(),
bytes.concat(
bridgedToken.init.selector,
ProxiedBridgedERC20(bridgedToken).init.selector,
abi.encode(
address(_addressManager),
ctoken.addr,
Expand Down
8 changes: 6 additions & 2 deletions packages/protocol/contracts/tokenvault/ERC721Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,17 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver, IERC165Upgradeable {
private
returns (address btoken)
{
ProxiedBridgedERC721 bridgedToken = new ProxiedBridgedERC721();
address bridgedToken = Create2Upgradeable.deploy({
amount: 0, // amount of Ether to send
salt: keccak256(abi.encode(ctoken)),
bytecode: type(ProxiedBridgedERC721).creationCode
});

btoken = LibVaultUtils.deployProxy(
address(bridgedToken),
owner(),
bytes.concat(
bridgedToken.init.selector,
ProxiedBridgedERC721(bridgedToken).init.selector,
abi.encode(
address(_addressManager),
ctoken.addr,
Expand Down