-
Notifications
You must be signed in to change notification settings - Fork 27
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
Native Token Bridges uses Teleporter Registry #197
Changes from 10 commits
cc6f94b
7f76f5c
bcd564c
57c3a17
e34de0f
fe9079a
b9ae8a2
e2e6b33
c8754d2
1d62d0f
9cf5eae
46d9ed6
d498530
edf47be
3efd7dc
fefa001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,13 @@ import { | |
TeleporterMessageInput, | ||
TeleporterFeeInfo | ||
} from "../../Teleporter/ITeleporterMessenger.sol"; | ||
import {ITeleporterReceiver} from "../../Teleporter/ITeleporterReceiver.sol"; | ||
import {TeleporterOwnerUpgradeable} from "../../Teleporter/upgrades/TeleporterOwnerUpgradeable.sol"; | ||
import {SafeERC20TransferFrom} from "../../Teleporter/SafeERC20TransferFrom.sol"; | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
contract ERC20TokenSource is | ||
ITeleporterReceiver, | ||
TeleporterOwnerUpgradeable, | ||
IERC20TokenSource, | ||
ITokenSource, | ||
ReentrancyGuard | ||
|
@@ -37,21 +37,12 @@ contract ERC20TokenSource is | |
address public immutable nativeTokenDestinationAddress; | ||
address public immutable erc20ContractAddress; | ||
|
||
// Used for sending and receiving Teleporter messages. | ||
ITeleporterMessenger public immutable teleporterMessenger; | ||
|
||
constructor( | ||
address teleporterMessengerAddress, | ||
address teleporterRegistryAddress, | ||
bytes32 destinationBlockchainID_, | ||
address nativeTokenDestinationAddress_, | ||
address erc20ContractAddress_ | ||
) { | ||
require( | ||
teleporterMessengerAddress != address(0), | ||
"ERC20TokenSource: zero TeleporterMessenger address" | ||
); | ||
teleporterMessenger = ITeleporterMessenger(teleporterMessengerAddress); | ||
|
||
) TeleporterOwnerUpgradeable(teleporterRegistryAddress) { | ||
require( | ||
destinationBlockchainID_ != bytes32(0), | ||
"ERC20TokenSource: zero destination blockchain ID" | ||
|
@@ -75,48 +66,6 @@ contract ERC20TokenSource is | |
erc20ContractAddress = erc20ContractAddress_; | ||
} | ||
|
||
/** | ||
* @dev See {ITeleporterReceiver-receiveTeleporterMessage}. | ||
* | ||
* Receives a Teleporter message and routes to the appropriate internal function call. | ||
*/ | ||
function receiveTeleporterMessage( | ||
bytes32 senderBlockchainID, | ||
address senderAddress, | ||
bytes calldata message | ||
) external nonReentrant { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we mgiht want to add reentrancy guard to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think we should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. created issue #213 |
||
// Only allow the Teleporter messenger to deliver messages. | ||
require( | ||
msg.sender == address(teleporterMessenger), | ||
"ERC20TokenSource: unauthorized TeleporterMessenger contract" | ||
); | ||
|
||
// Only allow messages from the destination chain. | ||
require( | ||
senderBlockchainID == destinationBlockchainID, | ||
"ERC20TokenSource: invalid destination chain" | ||
); | ||
|
||
// Only allow the partner contract to send messages. | ||
require( | ||
senderAddress == nativeTokenDestinationAddress, "ERC20TokenSource: unauthorized sender" | ||
); | ||
|
||
// Decode the payload to recover the action and corresponding function parameters | ||
(SourceAction action, bytes memory actionData) = abi.decode(message, (SourceAction, bytes)); | ||
|
||
// Route to the appropriate function. | ||
if (action == SourceAction.Unlock) { | ||
(address recipient, uint256 amount) = abi.decode(actionData, (address, uint256)); | ||
_unlockTokens(recipient, amount); | ||
} else if (action == SourceAction.Burn) { | ||
uint256 newBurnTotal = abi.decode(actionData, (uint256)); | ||
_handleBurnTokens(newBurnTotal); | ||
} else { | ||
revert("ERC20TokenSource: invalid action"); | ||
} | ||
} | ||
|
||
/** | ||
* @dev See {IERC20TokenSource-transferToDestination}. | ||
*/ | ||
|
@@ -126,6 +75,8 @@ contract ERC20TokenSource is | |
uint256 feeAmount, | ||
address[] calldata allowedRelayerAddresses | ||
) external nonReentrant { | ||
ITeleporterMessenger teleporterMessenger = teleporterRegistry.getLatestTeleporter(); | ||
geoff-vball marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// The recipient cannot be the zero address. | ||
require(recipient != address(0), "ERC20TokenSource: zero recipient address"); | ||
|
||
|
@@ -166,6 +117,42 @@ contract ERC20TokenSource is | |
}); | ||
} | ||
|
||
/** | ||
* @dev See {ITeleporterReceiver-receiveTeleporterMessage}. | ||
geoff-vball marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Receives a Teleporter message and routes to the appropriate internal function call. | ||
*/ | ||
function _receiveTeleporterMessage( | ||
bytes32 senderBlockchainID, | ||
address senderAddress, | ||
bytes memory message | ||
) internal override { | ||
// Only allow messages from the destination chain. | ||
require( | ||
senderBlockchainID == destinationBlockchainID, | ||
"ERC20TokenSource: invalid destination chain" | ||
); | ||
|
||
// Only allow the partner contract to send messages. | ||
require( | ||
senderAddress == nativeTokenDestinationAddress, "ERC20TokenSource: unauthorized sender" | ||
); | ||
|
||
// Decode the payload to recover the action and corresponding function parameters | ||
(SourceAction action, bytes memory actionData) = abi.decode(message, (SourceAction, bytes)); | ||
|
||
// Route to the appropriate function. | ||
if (action == SourceAction.Unlock) { | ||
(address recipient, uint256 amount) = abi.decode(actionData, (address, uint256)); | ||
_unlockTokens(recipient, amount); | ||
} else if (action == SourceAction.Burn) { | ||
uint256 newBurnTotal = abi.decode(actionData, (uint256)); | ||
_handleBurnTokens(newBurnTotal); | ||
} else { | ||
revert("ERC20TokenSource: invalid action"); | ||
} | ||
} | ||
|
||
/** | ||
* @dev Unlocks tokens to recipient. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling out with #194 to update to use remapping
@teleporter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you update this witht he merge