-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from AugustoL/feat/dynamic-proxy
Dynamic Proxy
- Loading branch information
Showing
16 changed files
with
272 additions
and
217 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
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
This file was deleted.
Oops, something went wrong.
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
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
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,14 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
|
||
import "../ERC827/ERC827.sol"; | ||
|
||
|
||
// mock class using ERC827 Token | ||
contract ERC827Mock is ERC827 { | ||
|
||
constructor(address initialAccount, uint256 initialBalance, bytes memory proxyBytecode) public ERC827(proxyBytecode) { | ||
_mint(initialAccount, initialBalance); | ||
} | ||
|
||
} |
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,47 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
import "../ERC827/ERC827.sol"; | ||
import "../utils/Create2.sol"; | ||
|
||
contract ERC827Receiver { | ||
|
||
event Show(bytes32 b32, uint256 number, string text, uint256 value); | ||
event TokensTransfered(address from, uint256 amount); | ||
|
||
function showMessage(bytes32 message, uint256 number, string memory text) | ||
public payable returns (bool) | ||
{ | ||
emit Show(message, number, text, msg.value); | ||
return true; | ||
} | ||
|
||
function fail() public { | ||
revert("ERC827Receiver function failed"); | ||
} | ||
|
||
function callContarct(address to, bytes memory data) public returns (bool) { | ||
// solium-disable-next-line security/no-low-level-calls, no-unused-vars | ||
(bool success, bytes memory _data) = to.call(data); | ||
require(success, "ERC827Receiver callContarct function failed"); | ||
return true; | ||
} | ||
|
||
function receiveTokens(address sender, address token) public { | ||
uint256 allowance = ERC827(token).allowance(sender, address(this)); | ||
ERC827(token).transferFrom(sender, address(this), allowance); | ||
emit TokensTransfered(sender, allowance); | ||
} | ||
|
||
function receiveVerifiedTokens(address sender, ERC827 token) public { | ||
address proxy = Create2.computeAddress( | ||
address(token), | ||
keccak256(abi.encodePacked(sender, address(this), token.nonces(sender))), | ||
token.proxyBytecode() | ||
); | ||
require(msg.sender == proxy, "ERC827Receiver: Sender invalid"); | ||
uint256 allowance = ERC827(token).allowance(sender, address(this)); | ||
ERC827(token).transferFrom(sender, address(this), allowance); | ||
emit TokensTransfered(sender, allowance); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
/** | ||
* @title Create2 | ||
* | ||
* @dev Utility library that focus on the use of CREATE2 EVM opcode for | ||
* contracts deployment. It also provides a function to precompute the address | ||
* where the smart contracts with the specified salt and bytecode would be | ||
* deployed. | ||
*/ | ||
library Create2 { | ||
|
||
// Event triggered when a contract is deployed | ||
event Create2Deployed(address addr, bytes32 salt); | ||
|
||
/** | ||
* @dev Deploy contract with CREATE2 | ||
* @param salt The salt used to the contract address computation | ||
* @param code The bytecode of of the contract to be deployed | ||
*/ | ||
function deploy(bytes32 salt, bytes memory code) internal returns (address) { | ||
address addr = _deploy(salt, code); | ||
emit Create2Deployed(addr, salt); | ||
return addr; | ||
} | ||
|
||
/** | ||
* @dev Function to compute the address of a contract created with CREATE2. | ||
* @param deployer the address of the contract that will deploy the contract | ||
* @param salt The salt used to the contract address computation | ||
* @param code The bytecode of the contract to be deployed | ||
* @return the computed address of the smart contract. | ||
*/ | ||
function computeAddress( | ||
address deployer, bytes32 salt, bytes memory code | ||
) internal view returns (address) { | ||
bytes32 codeHash = keccak256(code); | ||
bytes32 _data = keccak256( | ||
abi.encodePacked(bytes1(0xff), deployer, salt, codeHash) | ||
); | ||
return address(bytes20(_data << 96)); | ||
} | ||
|
||
/** | ||
* @dev Internal function to deploy contract with CREATE2 | ||
* @param _salt The salt used to the contract address computation | ||
* @param _code The bytecode of the contract to be deployed | ||
*/ | ||
function _deploy( | ||
bytes32 _salt, bytes memory _code | ||
) private returns(address) { | ||
address _addr; | ||
// solhint-disable-next-line no-inline-assembly | ||
assembly { | ||
_addr := create2(0, add(_code, 0x20), mload(_code), _salt) | ||
if iszero(extcodesize(_addr)) { | ||
revert(0, 0) | ||
} | ||
} | ||
return _addr; | ||
} | ||
|
||
} |
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
Oops, something went wrong.