-
Notifications
You must be signed in to change notification settings - Fork 0
SpritzBridgeReceiver #20
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
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,67 @@ | |||
// SPDX-License-Identifier: UNLICENSED | |||
|
|||
pragma solidity ^0.8.7; |
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.
use 0.8.21 now
|
||
pragma solidity ^0.8.7; | ||
|
||
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; |
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.
try openzeppelin-5, its aliased to the latest openzeppelin contracts which are better
bytes32 public constant BRIDGE_ROLE = keccak256("BRIDGE_ROLE"); | ||
|
||
// @dev Address of paraswap | ||
address internal _target = 0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57; |
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.
make these all contstants
) external payable onlyRole(BRIDGE_ROLE) { | ||
require(amount <= IERC20(fromToken).balanceOf(address(this)), "Amount exceeds balance"); | ||
IERC20(fromToken).safeApprove(_allowanceTarget, amount); | ||
_target.call{ value: msg.value }(swapData); |
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.
(bool success, ) = _target.call{ value: msg.value }(swapData);
if (!success) {
assembly {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
* @param to Target address | ||
*/ | ||
function sweep(IERC20 token, address to) external onlyRole(BRIDGE_ROLE) { | ||
token.transfer(to, token.balanceOf(address(this))); |
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.
safeTransfer, just because it can cause issues in some cases where the token doesn't conform properly
require(amount <= IERC20(fromToken).balanceOf(address(this)), "Amount exceeds balance"); | ||
IERC20(fromToken).safeApprove(_allowanceTarget, amount); | ||
_target.call{ value: msg.value }(swapData); | ||
IERC20(toToken).transfer(_circleReceiving, IERC20(toToken).balanceOf(address(this))); |
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.
safeTransfer
* @param swapData Data for paraswap call | ||
*/ | ||
function swapToken( | ||
address fromToken, |
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.
you can cast this to IERC20 then you wont need to do it everywhere else
// @dev Circle receiving address | ||
address internal _circleReceiving = 0xb0E2D41a14494717f42Ffc6327F9D250b0ad32a8; | ||
|
||
constructor(address bridgeRole) { |
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.
you can make the constructor payable to save some gas
No description provided.