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

enable contract deposit box usage via destination address #945

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
86 changes: 84 additions & 2 deletions proxy/contracts/mainnet/DepositBoxes/DepositBoxERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,44 @@ contract DepositBoxERC1155 is DepositBox, ERC1155ReceiverUpgradeable, IDepositBo
override
rightTransaction(schainName, msg.sender)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositTransferERC1155(schainName, erc1155OnMainnet, msg.sender, id, amount);
}

/**
* @dev Allows `msg.sender` to send ERC1155 token from mainnet to a specific schain destination address.
* This is potentially dangerous if the destination address is invalid.
* Consider depositERC1155() instead.
*
* Requirements:
*
* - Receiver contract should be defined.
* - `msg.sender` should approve their tokens for DepositBoxERC1155 address.
* - destination `to` cannot be 0 address.
*/
function transferERC1155(
string calldata schainName,
address erc1155OnMainnet,
address to,
uint256 id,
uint256 amount
)
external
override
rightTransaction(schainName, to)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositTransferERC1155(schainName, erc1155OnMainnet, to, id, amount);
}

function _depositTransferERC1155(
string calldata schainName,
address erc1155OnMainnet,
address to,
uint256 id,
uint256 amount
)
private
{
bytes32 schainHash = keccak256(abi.encodePacked(schainName));
address contractReceiver = schainLinks[schainHash];
Expand All @@ -116,7 +154,7 @@ contract DepositBoxERC1155 is DepositBox, ERC1155ReceiverUpgradeable, IDepositBo
bytes memory data = _receiveERC1155(
schainName,
erc1155OnMainnet,
msg.sender,
to,
id,
amount
);
Expand Down Expand Up @@ -148,6 +186,50 @@ contract DepositBoxERC1155 is DepositBox, ERC1155ReceiverUpgradeable, IDepositBo
override
rightTransaction(schainName, msg.sender)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositERC1155Batch(schainName, erc1155OnMainnet, msg.sender, ids, amounts);
}

/**
* @dev Allows `msg.sender` to send batch of ERC1155 tokens from mainnet to a specific schain destination address.
*
* Requirements:
*
* - Receiver contract should be defined.
* - `msg.sender` should approve their tokens for DepositBoxERC1155 address.
* - destination `to` cannot be 0 address.
*/
function transferERC1155Batch(
string calldata schainName,
address erc1155OnMainnet,
address to,
uint256[] calldata ids,
uint256[] calldata amounts
)
external
override
rightTransaction(schainName, to)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositERC1155Batch(schainName, erc1155OnMainnet, to, ids, amounts);
}

/**
* @dev Allows `msg.sender` to send batch of ERC1155 tokens from mainnet to schain.
*
* Requirements:
*
* - Receiver contract should be defined.
* - `msg.sender` should approve their tokens for DepositBoxERC1155 address.
*/
function _depositTransferERC1155Batch(
string calldata schainName,
address erc1155OnMainnet,
address to,
uint256[] calldata ids,
uint256[] calldata amounts
)
private
{
bytes32 schainHash = keccak256(abi.encodePacked(schainName));
address contractReceiver = schainLinks[schainHash];
Expand All @@ -159,7 +241,7 @@ contract DepositBoxERC1155 is DepositBox, ERC1155ReceiverUpgradeable, IDepositBo
bytes memory data = _receiveERC1155Batch(
schainName,
erc1155OnMainnet,
msg.sender,
to,
ids,
amounts
);
Expand Down
41 changes: 40 additions & 1 deletion proxy/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,45 @@ contract DepositBoxERC20 is DepositBox, IDepositBoxERC20 {
override
rightTransaction(schainName, msg.sender)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositTransferERC20(schainName, erc20OnMainnet, msg.sender, amount);
}

/**
* @dev Allows `msg.sender` to send ERC20 token from mainnet to a specific schain destination address.
* This is potentially dangerous if the destination address is invalid.
* Consider depositERC20() instead.
*
* Requirements:
*
* - Schain name must not be `Mainnet`.
* - Receiver account on schain cannot be null.
* - Schain that receives tokens should not be killed.
* - Receiver contract should be defined.
* - destination {to} cannot be 0 address.
* - `msg.sender` should approve their tokens for DepositBoxERC20 address.
*/
function transferERC20(
string calldata schainName,
address erc20OnMainnet,
address to,
uint256 amount
)
external
override
rightTransaction(schainName, to)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositTransferERC20(schainName, erc20OnMainnet, to, amount);
}

function _depositTransferERC20(
string calldata schainName,
address erc20OnMainnet,
address to,
uint256 amount
)
private
{
bytes32 schainHash = keccak256(abi.encodePacked(schainName));
address contractReceiver = schainLinks[schainHash];
Expand All @@ -112,7 +151,7 @@ contract DepositBoxERC20 is DepositBox, IDepositBoxERC20 {
bytes memory data = _receiveERC20(
schainName,
erc20OnMainnet,
msg.sender,
to,
amount
);
if (!linker.interchainConnections(schainHash))
Expand Down
38 changes: 37 additions & 1 deletion proxy/contracts/mainnet/DepositBoxes/DepositBoxERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,42 @@ contract DepositBoxERC721 is DepositBox, IDepositBoxERC721 {
override
rightTransaction(schainName, msg.sender)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositTransferERC721(schainName, erc721OnMainnet, msg.sender, tokenId);
}

/**
* @dev Allows `msg.sender` to send ERC721 token from mainnet to a specific schain destination address.
* This is potentially dangerous if the destination address is invalid.
* Consider depositERC721() instead.
*
* Requirements:
*
* - Receiver contract should be defined.
* - `msg.sender` should approve their token for DepositBoxERC721 address.
* - destination `to` cannot be 0 address.
*/
function transferERC721(
string calldata schainName,
address erc721OnMainnet,
address to,
uint256 tokenId
)
external
override
rightTransaction(schainName, to)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositTransferERC721(schainName, erc721OnMainnet, to, tokenId);
}

function _depositTransferERC721(
string calldata schainName,
address erc721OnMainnet,
address to,
uint256 tokenId
)
private
{
bytes32 schainHash = keccak256(abi.encodePacked(schainName));
address contractReceiver = schainLinks[schainHash];
Expand All @@ -109,7 +145,7 @@ contract DepositBoxERC721 is DepositBox, IDepositBoxERC721 {
bytes memory data = _receiveERC721(
schainName,
erc721OnMainnet,
msg.sender,
to,
tokenId
);
if (!linker.interchainConnections(schainHash))
Expand Down
30 changes: 29 additions & 1 deletion proxy/contracts/mainnet/DepositBoxes/DepositBoxEth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ contract DepositBoxEth is DepositBox, IDepositBoxEth {
override
rightTransaction(schainName, msg.sender)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositTransfer(schainName, msg.sender);
}

/**
* @dev Allows `msg.sender` to send ETH from mainnet to a specific schain destination address.
* This is potentially dangerous if the destination address is invalid.
* Consider deposit() instead.
*
* Requirements:
*
* - Schain name must not be `Mainnet`.
* - Receiver contract should be added as twin contract on schain.
* - Schain that receives tokens should not be killed.
* - destination `to` cannot be 0 address.
*/
function transfer(string memory schainName, address to)
external
payable
override
rightTransaction(schainName, to)
whenNotKilled(keccak256(abi.encodePacked(schainName)))
{
_depositTransfer(schainName, to);
}

function _depositTransfer(string memory schainName, address to)
private
{
bytes32 schainHash = keccak256(abi.encodePacked(schainName));
address contractReceiver = schainLinks[schainHash];
Expand All @@ -72,7 +100,7 @@ contract DepositBoxEth is DepositBox, IDepositBoxEth {
messageProxy.postOutgoingMessage(
schainHash,
contractReceiver,
Messages.encodeTransferEthMessage(msg.sender, msg.value)
Messages.encodeTransferEthMessage(to, msg.value)
);
}

Expand Down
84 changes: 82 additions & 2 deletions proxy/contracts/schain/TokenManagers/TokenManagerERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract TokenManagerERC1155 is TokenManager, ITokenManagerERC1155 {
/**
* @dev Move tokens from schain to mainnet.
*
* {contractOnMainnet} tokens are burned on schain and unlocked on mainnet for {to} address.
* {contractOnMainnet} tokens are burned on schain and unlocked on mainnet for same sender address.
*/
function exitToMainERC1155(
address contractOnMainnet,
Expand All @@ -84,10 +84,29 @@ contract TokenManagerERC1155 is TokenManager, ITokenManagerERC1155 {
}

/**
* @dev Move batch of tokens from schain to mainnet.
* @dev Move tokens from schain to mainnet.
*
* {contractOnMainnet} tokens are burned on schain and unlocked on mainnet for {to} address.
*/
function exitToMainERC1155(
address contractOnMainnet,
address to,
uint256 id,
uint256 amount
)
external
override
{
require(to != address(0), "Destination cannot be 0 address");
communityLocker.checkAllowedToSendMessage(msg.sender);
_exit(MAINNET_HASH, depositBox, contractOnMainnet, to, id, amount);
}

/**
* @dev Move batch of tokens from schain to mainnet.
*
* {contractOnMainnet} tokens are burned on schain and unlocked on mainnet for same address as sender.
*/
function exitToMainERC1155Batch(
address contractOnMainnet,
uint256[] memory ids,
Expand All @@ -100,6 +119,25 @@ contract TokenManagerERC1155 is TokenManager, ITokenManagerERC1155 {
_exitBatch(MAINNET_HASH, depositBox, contractOnMainnet, msg.sender, ids, amounts);
}

/**
* @dev Move batch of tokens from schain to mainnet.
*
* {contractOnMainnet} tokens are burned on schain and unlocked on mainnet for {to} address.
*/
function exitToMainERC1155Batch(
address contractOnMainnet,
address to,
uint256[] memory ids,
uint256[] memory amounts
)
external
override
{
require(to != address(0), "Destination cannot be 0 address");
communityLocker.checkAllowedToSendMessage(msg.sender);
_exitBatch(MAINNET_HASH, depositBox, contractOnMainnet, to, ids, amounts);
}

/**
* @dev Move tokens from schain to schain.
*
Expand All @@ -120,6 +158,27 @@ contract TokenManagerERC1155 is TokenManager, ITokenManagerERC1155 {
_exit(targetSchainHash, tokenManagers[targetSchainHash], contractOnMainnet, msg.sender, id, amount);
}

/**
* @dev Move tokens from schain to schain.
*
* {contractOnMainnet} tokens are burned on origin schain
* and are minted on {targetSchainName} schain for {to} address.
*/
function transferToSchainERC1155(
string calldata targetSchainName,
address contractOnMainnet,
address to,
uint256 id,
uint256 amount
)
external
override
rightTransaction(targetSchainName, to)
{
bytes32 targetSchainHash = keccak256(abi.encodePacked(targetSchainName));
_exit(targetSchainHash, tokenManagers[targetSchainHash], contractOnMainnet, to, id, amount);
}

/**
* @dev Move batch of tokens from schain to schain.
*
Expand All @@ -140,6 +199,27 @@ contract TokenManagerERC1155 is TokenManager, ITokenManagerERC1155 {
_exitBatch(targetSchainHash, tokenManagers[targetSchainHash], contractOnMainnet, msg.sender, ids, amounts);
}

/**
* @dev Move batch of tokens from schain to schain.
*
* {contractOnMainnet} tokens are burned on origin schain
* and are minted on {targetSchainName} schain for {to} address.
*/
function transferToSchainERC1155Batch(
string calldata targetSchainName,
address contractOnMainnet,
address to,
uint256[] memory ids,
uint256[] memory amounts
)
external
override
rightTransaction(targetSchainName, to)
{
bytes32 targetSchainHash = keccak256(abi.encodePacked(targetSchainName));
_exitBatch(targetSchainHash, tokenManagers[targetSchainHash], contractOnMainnet, to, ids, amounts);
}

/**
* @dev Allows MessageProxy to post operational message from mainnet
* or SKALE chains.
Expand Down
Loading