-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54eab20
commit a813688
Showing
9 changed files
with
2,022 additions
and
1,140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// SPDX-License-Identifier:MIT | ||
// solhint-disable no-inline-assembly | ||
pragma solidity ^0.6.12; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import "@rsksmart/rif-relay-contracts/contracts/factory/SmartWalletFactory.sol"; | ||
import "@rsksmart/rif-relay-contracts/contracts/interfaces/IDeployVerifier.sol"; | ||
import "@rsksmart/rif-relay-contracts/contracts/interfaces/EnvelopingTypes.sol"; | ||
import "@rsksmart/rif-relay-contracts/contracts/TokenHandler.sol"; | ||
|
||
struct ClaimInfo { | ||
bytes32 preimage; | ||
uint amount; | ||
address refundAddress; | ||
uint timelock; | ||
} | ||
|
||
/** | ||
* A Verifier to be used on deploys. | ||
*/ | ||
contract BoltzDeployVerifier is IDeployVerifier, TokenHandler { | ||
address private _factory; | ||
|
||
constructor(address walletFactory) public { | ||
_factory = walletFactory; | ||
} | ||
|
||
function versionVerifier() | ||
external | ||
view | ||
virtual | ||
override | ||
returns (string memory) | ||
{ | ||
return "[email protected]"; | ||
} | ||
|
||
/* solhint-disable no-unused-vars */ | ||
function verifyRelayedCall( | ||
EnvelopingTypes.DeployRequest calldata relayRequest, | ||
bytes calldata signature | ||
) external virtual override returns (bytes memory context) { | ||
require( | ||
relayRequest.relayData.callForwarder == _factory, | ||
"Invalid factory" | ||
); | ||
|
||
address contractAddr = SmartWalletFactory( | ||
relayRequest.relayData.callForwarder | ||
).getSmartWalletAddress( | ||
relayRequest.request.from, | ||
relayRequest.request.recoverer, | ||
relayRequest.request.index | ||
); | ||
|
||
require(!_isContract(contractAddr), "Address already created!"); | ||
|
||
if (relayRequest.request.tokenContract != address(0)) { | ||
require( | ||
tokens[relayRequest.request.tokenContract], | ||
"Token contract not allowed" | ||
); | ||
|
||
require( | ||
relayRequest.request.tokenAmount <= | ||
IERC20(relayRequest.request.tokenContract).balanceOf( | ||
contractAddr | ||
), | ||
"Token balance too low" | ||
); | ||
} else { | ||
if(relayRequest.request.to != address(0)){ | ||
ClaimInfo memory claim = abi.decode( | ||
relayRequest.request.data[4:], | ||
(ClaimInfo) | ||
); | ||
|
||
require( | ||
relayRequest.request.tokenAmount <= claim.amount, | ||
"Native balance too low" | ||
); | ||
}else{ | ||
require( | ||
relayRequest.request.tokenAmount <= address(contractAddr).balance, | ||
"Native balance too low" | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
abi.encode( | ||
contractAddr, | ||
relayRequest.request.tokenAmount, | ||
relayRequest.request.tokenContract | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Check if a contract has code in it | ||
* Should NOT be used in a contructor, it fails | ||
* See: https://stackoverflow.com/a/54056854 | ||
*/ | ||
function _isContract(address _addr) internal view returns (bool) { | ||
uint32 size; | ||
assembly { | ||
size := extcodesize(_addr) | ||
} | ||
return (size > 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.12; | ||
|
||
contract TestSwap { | ||
|
||
function claim( | ||
bytes32 preimage, | ||
uint amount, | ||
address refundAddress, | ||
uint timelock | ||
) external { | ||
(bool success, ) = payable(msg.sender).call{value: amount}(""); | ||
require(success, "Could not transfer Ether"); | ||
} | ||
|
||
// solhint-disable-next-line no-empty-blocks | ||
receive() external payable {} | ||
|
||
} |
Oops, something went wrong.