Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00| Transaction Hash |
Method
|
Block
|
From
|
|
To
|
||||
|---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
|
To
|
||
|---|---|---|---|---|---|---|---|
| - | 13010020 | 1661 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Minimal Proxy Contract for 0x44e999d5c2f66ef0861317f9a4805ac2e90aeb4f
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xCF015c7a...695944b34 in Arbitrum Sepolia Testnet The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
ProxyWallet
Compiler Version
v0.5.10+commit.5a6ea5b1
Optimization Enabled:
Yes with 200 runs
Other Settings:
Default EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;
import { GSNRecipient } from "@openzeppelin/contracts/GSN/GSNRecipient.sol";
import { Ownable } from "@openzeppelin/contracts/ownership/Ownable.sol";
import { ERC1155TokenReceiver } from "@gnosis.pm/conditional-tokens-contracts/contracts/ERC1155/ERC1155TokenReceiver.sol";
import { Create2 } from "openzeppelin-solidity/contracts/utils/Create2.sol";
import { RevertCaptureLib } from "../libraries/RevertCaptureLib.sol";
import { ProxyWalletLib } from "./ProxyWalletLib.sol";
import { ProxyWallet } from "./ProxyWallet.sol";
import { FactoryLib } from "../libraries/FactoryLib.sol";
import { GSNLib } from "../GSNModules/GSNLib.sol";
import { GSNModule01 } from "../GSNModules/GSNModule01.sol";
import { IGSNModule } from "../interfaces/IGSNModule.sol";
contract ProxyWalletFactory is Ownable, GSNRecipient {
using GSNLib for *;
constructor() Ownable() public {
ProxyWalletLib.setImplementation(deployImplementation());
ProxyWalletLib.setGSNModule(address(new GSNModule01()));
}
/**
* @notice Updates the GSN module to be used
*
* @param gsnModule - address of the new GSN module
*/
function setGSNModule(address gsnModule) public onlyOwner {
return ProxyWalletLib.setGSNModule(gsnModule);
}
/**
* @notice Returns the address of the currently used GSN module
*/
function getGSNModule() public view returns (address) {
return ProxyWalletLib.getGSNModule();
}
/**
* @notice Returns the address of the implementation of the proxy wallet
*/
function getImplementation() public view returns (address) {
return ProxyWalletLib.getImplementation();
}
/**
* @notice Deploys the initial implementation of the proxy wallet which is to be cloned
*/
function deployImplementation() internal returns (address) {
return Create2.deploy(ProxyWalletLib.WALLET_FACTORY_SALT(), type(ProxyWallet).creationCode);
}
function _preRelayedCall(bytes memory context) internal returns (bytes32 returnData) {
(bool success, bytes memory retval) = ProxyWalletLib.getGSNModule().delegatecall(abi.encodeWithSelector(IGSNModule(0).preRelayedCall.selector, context));
if (!success) revert(RevertCaptureLib.decodeError(retval));
(returnData) = abi.decode(retval, (bytes32));
}
function _postRelayedCall(bytes memory context, bool success, uint256 actualCharge, bytes32 preRetVal) internal {
(bool success, bytes memory retval) = ProxyWalletLib.getGSNModule().delegatecall(abi.encodeWithSelector(IGSNModule(0).postRelayedCall.selector, context, success, actualCharge, preRetVal));
if (!success) revert(RevertCaptureLib.decodeError(retval));
return;
}
function acceptRelayedCall(
address /* relay */,
address /* from */,
bytes memory /* encodedFunction */,
uint256 /* transactionFee */,
uint256 /* gasPrice */,
uint256 /* gasLimit */,
uint256 /* nonce */,
bytes memory /* approvalData */,
uint256 /* maxPossibleCharge */
) public view returns (uint256 doCall, bytes memory context) {
(bool success, bytes memory retval) = ProxyWalletLib.getGSNModule().staticcall(msg.data);
if (!success) revert(RevertCaptureLib.decodeError(retval));
(doCall, context) = abi.decode(retval, (uint256, bytes));
}
/**
* @notice Creates a proxy wallet for msgSender by cloning the one at _implementation
*
* @param _implementation - address of proxy wallet implementation to clone
* @param msgSender - The address of the owner of the proxy wallet at instanceAddress
*/
function makeWallet(address _implementation, address msgSender) internal returns (address user) {
address payable clone = address(uint160(FactoryLib.create2Clone(_implementation, uint256(keccak256(abi.encodePacked(address(msgSender)))))));
ProxyWallet(clone).initialize();
return clone;
}
/**
* @notice Checks if there already exists a proxy wallet for the provided msgSender. If so then do nothing, if not then create one.
*
* @param _implementation - address of proxy wallet implementation to clone
* @param instanceAddress - The address at which the proxy wallet was (or will be) created
* @param msgSender - The address of the owner of the proxy wallet at instanceAddress
*/
function maybeMakeWallet(address _implementation, address instanceAddress, address msgSender) internal returns (address clone) {
uint256 sz;
assembly {
sz := extcodesize(instanceAddress)
}
if (sz == 0) return makeWallet(_implementation, msgSender);
}
function cloneConstructor(bytes calldata /* consData */) external {}
/**
* @notice Fallback function.
*/
function () external payable {
// do nothing
}
/**
* @notice Passes an array of contract calls from GSN relayer through to a proxy wallet. If the _msgSender does not own a wallet then one is created for them.
*
* @param calls - array of ProxyCalls which to pass along to the proxy wallet to be executed.
*/
function proxy(ProxyWalletLib.ProxyCall[] memory calls) public payable returns (bytes[] memory returnValues) {
address msgSender = _msgSender();
address _implementation = ProxyWalletLib.getImplementation();
address instanceAddress = FactoryLib.deriveInstanceAddress(_implementation, keccak256(abi.encodePacked(msgSender)));
maybeMakeWallet(_implementation, instanceAddress, msgSender);
returnValues = ProxyWallet(instanceAddress).proxy.value(msg.value)(calls);
}
}pragma solidity ^0.5.0;
import "./IRelayRecipient.sol";
import "./IRelayHub.sol";
import "./Context.sol";
/**
* @dev Base GSN recipient contract: includes the {IRelayRecipient} interface
* and enables GSN support on all contracts in the inheritance tree.
*
* TIP: This contract is abstract. The functions {IRelayRecipient-acceptRelayedCall},
* {_preRelayedCall}, and {_postRelayedCall} are not implemented and must be
* provided by derived contracts. See the
* xref:ROOT:gsn-strategies.adoc#gsn-strategies[GSN strategies] for more
* information on how to use the pre-built {GSNRecipientSignature} and
* {GSNRecipientERC20Fee}, or how to write your own.
*/
contract GSNRecipient is IRelayRecipient, Context {
// Default RelayHub address, deployed on mainnet and all testnets at the same address
address private _relayHub = 0xD216153c06E857cD7f72665E0aF1d7D82172F494;
uint256 constant private RELAYED_CALL_ACCEPTED = 0;
uint256 constant private RELAYED_CALL_REJECTED = 11;
// How much gas is forwarded to postRelayedCall
uint256 constant internal POST_RELAYED_CALL_MAX_GAS = 100000;
/**
* @dev Emitted when a contract changes its {IRelayHub} contract to a new one.
*/
event RelayHubChanged(address indexed oldRelayHub, address indexed newRelayHub);
/**
* @dev Returns the address of the {IRelayHub} contract for this recipient.
*/
function getHubAddr() public view returns (address) {
return _relayHub;
}
/**
* @dev Switches to a new {IRelayHub} instance. This method is added for future-proofing: there's no reason to not
* use the default instance.
*
* IMPORTANT: After upgrading, the {GSNRecipient} will no longer be able to receive relayed calls from the old
* {IRelayHub} instance. Additionally, all funds should be previously withdrawn via {_withdrawDeposits}.
*/
function _upgradeRelayHub(address newRelayHub) internal {
address currentRelayHub = _relayHub;
require(newRelayHub != address(0), "GSNRecipient: new RelayHub is the zero address");
require(newRelayHub != currentRelayHub, "GSNRecipient: new RelayHub is the current one");
emit RelayHubChanged(currentRelayHub, newRelayHub);
_relayHub = newRelayHub;
}
/**
* @dev Returns the version string of the {IRelayHub} for which this recipient implementation was built. If
* {_upgradeRelayHub} is used, the new {IRelayHub} instance should be compatible with this version.
*/
// This function is view for future-proofing, it may require reading from
// storage in the future.
function relayHubVersion() public view returns (string memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return "1.0.0";
}
/**
* @dev Withdraws the recipient's deposits in `RelayHub`.
*
* Derived contracts should expose this in an external interface with proper access control.
*/
function _withdrawDeposits(uint256 amount, address payable payee) internal {
IRelayHub(_relayHub).withdraw(amount, payee);
}
// Overrides for Context's functions: when called from RelayHub, sender and
// data require some pre-processing: the actual sender is stored at the end
// of the call data, which in turns means it needs to be removed from it
// when handling said data.
/**
* @dev Replacement for msg.sender. Returns the actual sender of a transaction: msg.sender for regular transactions,
* and the end-user for GSN relayed calls (where msg.sender is actually `RelayHub`).
*
* IMPORTANT: Contracts derived from {GSNRecipient} should never use `msg.sender`, and use {_msgSender} instead.
*/
function _msgSender() internal view returns (address payable) {
if (msg.sender != _relayHub) {
return msg.sender;
} else {
return _getRelayedCallSender();
}
}
/**
* @dev Replacement for msg.data. Returns the actual calldata of a transaction: msg.data for regular transactions,
* and a reduced version for GSN relayed calls (where msg.data contains additional information).
*
* IMPORTANT: Contracts derived from {GSNRecipient} should never use `msg.data`, and use {_msgData} instead.
*/
function _msgData() internal view returns (bytes memory) {
if (msg.sender != _relayHub) {
return msg.data;
} else {
return _getRelayedCallData();
}
}
// Base implementations for pre and post relayedCall: only RelayHub can invoke them, and data is forwarded to the
// internal hook.
/**
* @dev See `IRelayRecipient.preRelayedCall`.
*
* This function should not be overriden directly, use `_preRelayedCall` instead.
*
* * Requirements:
*
* - the caller must be the `RelayHub` contract.
*/
function preRelayedCall(bytes calldata context) external returns (bytes32) {
require(msg.sender == getHubAddr(), "GSNRecipient: caller is not RelayHub");
return _preRelayedCall(context);
}
/**
* @dev See `IRelayRecipient.preRelayedCall`.
*
* Called by `GSNRecipient.preRelayedCall`, which asserts the caller is the `RelayHub` contract. Derived contracts
* must implement this function with any relayed-call preprocessing they may wish to do.
*
*/
function _preRelayedCall(bytes memory context) internal returns (bytes32);
/**
* @dev See `IRelayRecipient.postRelayedCall`.
*
* This function should not be overriden directly, use `_postRelayedCall` instead.
*
* * Requirements:
*
* - the caller must be the `RelayHub` contract.
*/
function postRelayedCall(bytes calldata context, bool success, uint256 actualCharge, bytes32 preRetVal) external {
require(msg.sender == getHubAddr(), "GSNRecipient: caller is not RelayHub");
_postRelayedCall(context, success, actualCharge, preRetVal);
}
/**
* @dev See `IRelayRecipient.postRelayedCall`.
*
* Called by `GSNRecipient.postRelayedCall`, which asserts the caller is the `RelayHub` contract. Derived contracts
* must implement this function with any relayed-call postprocessing they may wish to do.
*
*/
function _postRelayedCall(bytes memory context, bool success, uint256 actualCharge, bytes32 preRetVal) internal;
/**
* @dev Return this in acceptRelayedCall to proceed with the execution of a relayed call. Note that this contract
* will be charged a fee by RelayHub
*/
function _approveRelayedCall() internal pure returns (uint256, bytes memory) {
return _approveRelayedCall("");
}
/**
* @dev See `GSNRecipient._approveRelayedCall`.
*
* This overload forwards `context` to _preRelayedCall and _postRelayedCall.
*/
function _approveRelayedCall(bytes memory context) internal pure returns (uint256, bytes memory) {
return (RELAYED_CALL_ACCEPTED, context);
}
/**
* @dev Return this in acceptRelayedCall to impede execution of a relayed call. No fees will be charged.
*/
function _rejectRelayedCall(uint256 errorCode) internal pure returns (uint256, bytes memory) {
return (RELAYED_CALL_REJECTED + errorCode, "");
}
/*
* @dev Calculates how much RelayHub will charge a recipient for using `gas` at a `gasPrice`, given a relayer's
* `serviceFee`.
*/
function _computeCharge(uint256 gas, uint256 gasPrice, uint256 serviceFee) internal pure returns (uint256) {
// The fee is expressed as a percentage. E.g. a value of 40 stands for a 40% fee, so the recipient will be
// charged for 1.4 times the spent amount.
return (gas * gasPrice * (100 + serviceFee)) / 100;
}
function _getRelayedCallSender() private pure returns (address payable result) {
// We need to read 20 bytes (an address) located at array index msg.data.length - 20. In memory, the array
// is prefixed with a 32-byte length value, so we first add 32 to get the memory read index. However, doing
// so would leave the address in the upper 20 bytes of the 32-byte word, which is inconvenient and would
// require bit shifting. We therefore subtract 12 from the read index so the address lands on the lower 20
// bytes. This can always be done due to the 32-byte prefix.
// The final memory read index is msg.data.length - 20 + 32 - 12 = msg.data.length. Using inline assembly is the
// easiest/most-efficient way to perform this operation.
// These fields are not accessible from assembly
bytes memory array = msg.data;
uint256 index = msg.data.length;
// solhint-disable-next-line no-inline-assembly
assembly {
// Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those.
result := and(mload(add(array, index)), 0xffffffffffffffffffffffffffffffffffffffff)
}
return result;
}
function _getRelayedCallData() private pure returns (bytes memory) {
// RelayHub appends the sender address at the end of the calldata, so in order to retrieve the actual msg.data,
// we must strip the last 20 bytes (length of an address type) from it.
uint256 actualDataLength = msg.data.length - 20;
bytes memory actualData = new bytes(actualDataLength);
for (uint256 i = 0; i < actualDataLength; ++i) {
actualData[i] = msg.data[i];
}
return actualData;
}
}pragma solidity ^0.5.0;
import "../GSN/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}pragma solidity ^0.5.0;
import "./IERC1155TokenReceiver.sol";
import "openzeppelin-solidity/contracts/introspection/ERC165.sol";
contract ERC1155TokenReceiver is ERC165, IERC1155TokenReceiver {
constructor() public {
_registerInterface(
ERC1155TokenReceiver(0).onERC1155Received.selector ^
ERC1155TokenReceiver(0).onERC1155BatchReceived.selector
);
}
}pragma solidity ^0.5.0;
/**
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
* `CREATE2` can be used to compute in advance the address where a smart
* contract will be deployed, which allows for interesting new mechanisms known
* as 'counterfactual interactions'.
*
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
* information.
*
* _Available since v2.5.0._
*/
library Create2 {
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}. Note that
* a contract cannot be deployed twice using the same salt.
*/
function deploy(bytes32 salt, bytes memory bytecode) internal returns (address) {
address addr;
// solhint-disable-next-line no-inline-assembly
assembly {
addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
}
require(addr != address(0), "Create2: Failed on deploy");
return addr;
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the `bytecode`
* or `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt, bytes memory bytecode) internal view returns (address) {
return computeAddress(salt, bytecode, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes memory bytecodeHash, address deployer) internal pure returns (address) {
bytes32 bytecodeHashHash = keccak256(bytecodeHash);
bytes32 _data = keccak256(
abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHashHash)
);
return address(bytes20(_data << 96));
}
}pragma solidity ^0.5.0;
import { SliceLib } from "./SliceLib.sol";
library RevertCaptureLib {
using SliceLib for *;
uint32 constant REVERT_WITH_REASON_MAGIC = 0x08c379a0; // keccak256("Error(string)")
function decodeError(bytes memory buffer) internal pure returns (string memory) {
if (buffer.length == 0) return "captured empty revert buffer";
if (uint32(uint256(bytes32(buffer.toSlice(0, 4).asWord()))) != REVERT_WITH_REASON_MAGIC) return "captured a revert error, but it doesn't conform to the standard";
bytes memory revertMessageEncoded = buffer.toSlice(4).copy();
if (revertMessageEncoded.length == 0) return "captured empty revert message";
(string memory revertMessage) = abi.decode(revertMessageEncoded, (string));
return revertMessage;
}
}pragma solidity ^0.5.0;
import { Create2 } from "@openzeppelin/contracts/utils/Create2.sol";
import { MemcpyLib } from "../libraries/MemcpyLib.sol";
library ProxyWalletLib {
bytes32 constant _OWNER_SLOT = 0x734a2a5caf82146a5ddd5263d9af379f9f72724959f0567ddc9df2c40cf2cc20; // keccak256("owner")
bytes32 constant _WALLET_FACTORY_SALT = 0x154d67e25bcc1ea1986fa661b5b80b8facf3a90be6159e155e199e54a74fcb4d; // keccak256("wallet-factory")
bytes32 constant _IMPLEMENTATION_SLOT = 0x8ba0ed1f62da1d3048614c2c1feb566f041c8467eb00fb8294776a9179dc1643; // keccak256("implementation")
bytes32 constant _GSN_MODULE_SLOT = 0x73c1ac149a67e4e6e228d78c3a8df342639f43de1a2480627ae6fad35761d9af; // keccak256("gsn-module")
function WALLET_FACTORY_SALT() internal pure returns (bytes32 salt) {
salt = _WALLET_FACTORY_SALT;
}
function getImplementation() internal view returns (address implementation) {
bytes32 local = _IMPLEMENTATION_SLOT;
assembly {
implementation := sload(local)
}
}
function setImplementation(address implementation) internal {
bytes32 local = _IMPLEMENTATION_SLOT;
assembly {
sstore(local, implementation)
}
}
function setGSNModule(address gsnModule) internal {
bytes32 local = _GSN_MODULE_SLOT;
assembly {
sstore(local, gsnModule)
}
}
function getGSNModule() internal view returns (address gsnModule) {
bytes32 local = _GSN_MODULE_SLOT;
assembly {
gsnModule := sload(local)
}
}
function getOwner() internal view returns (address owner) {
bytes32 OWNER_SLOT = _OWNER_SLOT;
assembly {
owner := sload(OWNER_SLOT)
}
}
enum CallType {
INVALID,
CALL,
DELEGATECALL
}
struct ProxyCall {
CallType typeCode;
address payable to;
uint256 value;
bytes data;
}
function setOwner(address owner) internal {
bytes32 local = _OWNER_SLOT;
assembly {
sstore(local, owner)
}
}
function proxyCall(ProxyCall memory callDetails) internal returns (bool success, bytes memory returnData) {
if (callDetails.typeCode == CallType.DELEGATECALL) {
(success, returnData) = callDetails.to.delegatecall(callDetails.data);
} else if (callDetails.typeCode == CallType.CALL) {
(success, returnData) = callDetails.to.call.value(callDetails.value)(callDetails.data);
}
}
function computeCreationCode(address target) internal view returns (bytes memory clone) {
clone = computeCreationCode(address(this), target);
}
function computeCreationCode(address deployer, address target) internal pure returns (bytes memory clone) {
bytes memory consData = abi.encodeWithSignature("cloneConstructor(bytes)", new bytes(0));
clone = new bytes(99 + consData.length);
assembly {
mstore(add(clone, 0x20),
0x3d3d606380380380913d393d73bebebebebebebebebebebebebebebebebebebe)
mstore(add(clone, 0x2d),
mul(deployer, 0x01000000000000000000000000))
mstore(add(clone, 0x41),
0x5af4602a57600080fd5b602d8060366000396000f3363d3d373d3d3d363d73be)
mstore(add(clone, 0x60),
mul(target, 0x01000000000000000000000000))
mstore(add(clone, 116),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
}
for (uint256 i = 0; i < consData.length; i++) {
clone[i + 99] = consData[i];
}
}
function deriveInstanceAddress(address target, bytes32 salt) internal view returns (address) {
return Create2.computeAddress(salt, computeCreationCode(target));
}
function deriveInstanceAddress(address from, address target, bytes32 salt) internal pure returns (address) {
return Create2.computeAddress(salt, computeCreationCode(from, target), from);
}
}pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;
import { ProxyWalletLib } from "./ProxyWalletLib.sol";
import { GSNRecipient } from "@openzeppelin/contracts/GSN/GSNRecipient.sol";
import { MemcpyLib } from "../libraries/MemcpyLib.sol";
import { RevertCaptureLib } from "../libraries/RevertCaptureLib.sol";
import { IRelayHub } from "@openzeppelin/contracts/GSN/IRelayHub.sol";
contract ProxyWallet {
using ProxyWalletLib for *;
function initialize() public {
require(ProxyWalletLib.getOwner() == address(0x0), "already initialized");
ProxyWalletLib.setOwner(msg.sender);
}
modifier onlyOwner {
require(ProxyWalletLib.getOwner() == msg.sender, "must be called be owner");
_;
}
function onERC1155BatchReceived(
address /* operator */,
address /* from */,
uint256[] memory /* ids */,
uint256[] memory /* values */,
bytes memory /* data */
) public pure returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
function onERC1155Received(
address /* operator */,
address /* from */,
uint256 /* id */,
uint256 /* value */,
bytes memory /* data */
) public pure returns (bytes4) {
return this.onERC1155Received.selector;
}
/**
* @notice Receives an array of contract calls from ProxyWalletFactory to be executed.
* @dev Access control for this function is handled on ProxyWalletFactory
*
* @param calls - array of ProxyCalls to be executed.
*/
function proxy(ProxyWalletLib.ProxyCall[] memory calls) public payable onlyOwner returns (bytes[] memory returnValues) {
returnValues = new bytes[](calls.length);
for (uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory returnData) = calls[i].proxyCall();
if (!success) revert(RevertCaptureLib.decodeError(returnData));
returnValues[i] = returnData;
}
}
}pragma solidity ^0.5.0;
import { Create2 } from "@openzeppelin/contracts/utils/Create2.sol";
library FactoryLib {
function computeCreationCode(address target) internal view returns (bytes memory clone) {
clone = computeCreationCode(address(this), target);
}
function computeCreationCode(address deployer, address target) internal pure returns (bytes memory clone) {
bytes memory consData = abi.encodeWithSignature("cloneConstructor(bytes)", new bytes(0));
clone = new bytes(99 + consData.length);
assembly {
mstore(add(clone, 0x20),
0x3d3d606380380380913d393d73bebebebebebebebebebebebebebebebebebebe)
mstore(add(clone, 0x2d),
mul(deployer, 0x01000000000000000000000000))
mstore(add(clone, 0x41),
0x5af4602a57600080fd5b602d8060366000396000f3363d3d373d3d3d363d73be)
mstore(add(clone, 0x60),
mul(target, 0x01000000000000000000000000))
mstore(add(clone, 116),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
}
for (uint256 i = 0; i < consData.length; i++) {
clone[i + 99] = consData[i];
}
}
function deriveInstanceAddress(address target, bytes32 salt) internal view returns (address) {
return Create2.computeAddress(salt, computeCreationCode(target));
}
function deriveInstanceAddress(address from, address target, bytes32 salt) internal pure returns (address) {
return Create2.computeAddress(salt, computeCreationCode(from, target), from);
}
function create2Clone(address target, uint saltNonce) internal returns (address result) {
bytes memory clone = computeCreationCode(target);
bytes32 salt = bytes32(saltNonce);
assembly {
let len := mload(clone)
let data := add(clone, 0x20)
result := create2(0, data, len, salt)
}
require(result != address(0), "create2 failed");
}
}pragma solidity ^0.5.0;
import { SliceLib } from "../libraries/SliceLib.sol";
library GSNLib {
bytes32 constant SIGNATURE_MASK = 0xffffffff00000000000000000000000000000000000000000000000000000000;
function toSignature(bytes memory input) internal pure returns (bytes4 signature) {
bytes32 local = SIGNATURE_MASK;
assembly {
signature := and(mload(add(0x20, input)), local)
}
}
function splitPayload(bytes memory payload) internal pure returns (bytes4 signature, bytes memory args) {
signature = toSignature(payload);
args = SliceLib.copy(SliceLib.toSlice(payload, 4));
}
}pragma solidity ^0.5.0;
import { IProxyWalletFactory } from "../interfaces/IProxyWalletFactory.sol";
import { GSNLib } from "./GSNLib.sol";
import { RevertCaptureLib } from "../libraries/RevertCaptureLib.sol";
import { ProxyWalletLib } from "../ProxyWallet/ProxyWalletLib.sol";
contract GSNModule01 {
using GSNLib for *;
function acceptRelayedCall(
address /* relay */,
address /* from */,
bytes memory encodedFunction,
uint256 /* transactionFee */,
uint256 /* gasPrice */,
uint256 /* gasLimit */,
uint256 /* nonce */,
bytes memory /* approvalData */,
uint256 /* maxPossibleCharge */
) public pure returns (uint256 doCall, bytes memory) {
bytes4 signature = encodedFunction.toSignature();
if (signature == IProxyWalletFactory(0).proxy.selector) doCall = 0;
else doCall = 1;
}
function preRelayedCall(bytes memory /* context */) public returns (bytes32) { }
function postRelayedCall(bytes memory /* context */, bool /* success */, uint256 /* actualCharge */, bytes32 /* preRetVal */) public {}
}pragma experimental ABIEncoderV2;
pragma solidity ^0.5.0;
contract IGSNModule {
function acceptRelayedCall(
address /* relay */,
address /* from */,
bytes calldata /* encodedFunction */,
uint256 /* transactionFee */,
uint256 /* gasPrice */,
uint256 /* gasLimit */,
uint256 /* nonce */,
bytes calldata /* approvalData */,
uint256 /* maxPossibleCharge */
) external returns (uint256 doCall, bytes memory);
function preRelayedCall(bytes calldata /* context */) external returns (bytes32) { }
function postRelayedCall(bytes calldata /* context */, bool /* success */, uint256 /* actualCharge */, bytes32 /* preRetVal */) external;
}pragma solidity ^0.5.0;
/**
* @dev Base interface for a contract that will be called via the GSN from {IRelayHub}.
*
* TIP: You don't need to write an implementation yourself! Inherit from {GSNRecipient} instead.
*/
interface IRelayRecipient {
/**
* @dev Returns the address of the {IRelayHub} instance this recipient interacts with.
*/
function getHubAddr() external view returns (address);
/**
* @dev Called by {IRelayHub} to validate if this recipient accepts being charged for a relayed call. Note that the
* recipient will be charged regardless of the execution result of the relayed call (i.e. if it reverts or not).
*
* The relay request was originated by `from` and will be served by `relay`. `encodedFunction` is the relayed call
* calldata, so its first four bytes are the function selector. The relayed call will be forwarded `gasLimit` gas,
* and the transaction executed with a gas price of at least `gasPrice`. `relay`'s fee is `transactionFee`, and the
* recipient will be charged at most `maxPossibleCharge` (in wei). `nonce` is the sender's (`from`) nonce for
* replay attack protection in {IRelayHub}, and `approvalData` is a optional parameter that can be used to hold a signature
* over all or some of the previous values.
*
* Returns a tuple, where the first value is used to indicate approval (0) or rejection (custom non-zero error code,
* values 1 to 10 are reserved) and the second one is data to be passed to the other {IRelayRecipient} functions.
*
* {acceptRelayedCall} is called with 50k gas: if it runs out during execution, the request will be considered
* rejected. A regular revert will also trigger a rejection.
*/
function acceptRelayedCall(
address relay,
address from,
bytes calldata encodedFunction,
uint256 transactionFee,
uint256 gasPrice,
uint256 gasLimit,
uint256 nonce,
bytes calldata approvalData,
uint256 maxPossibleCharge
)
external
view
returns (uint256, bytes memory);
/**
* @dev Called by {IRelayHub} on approved relay call requests, before the relayed call is executed. This allows to e.g.
* pre-charge the sender of the transaction.
*
* `context` is the second value returned in the tuple by {acceptRelayedCall}.
*
* Returns a value to be passed to {postRelayedCall}.
*
* {preRelayedCall} is called with 100k gas: if it runs out during exection or otherwise reverts, the relayed call
* will not be executed, but the recipient will still be charged for the transaction's cost.
*/
function preRelayedCall(bytes calldata context) external returns (bytes32);
/**
* @dev Called by {IRelayHub} on approved relay call requests, after the relayed call is executed. This allows to e.g.
* charge the user for the relayed call costs, return any overcharges from {preRelayedCall}, or perform
* contract-specific bookkeeping.
*
* `context` is the second value returned in the tuple by {acceptRelayedCall}. `success` is the execution status of
* the relayed call. `actualCharge` is an estimate of how much the recipient will be charged for the transaction,
* not including any gas used by {postRelayedCall} itself. `preRetVal` is {preRelayedCall}'s return value.
*
*
* {postRelayedCall} is called with 100k gas: if it runs out during execution or otherwise reverts, the relayed call
* and the call to {preRelayedCall} will be reverted retroactively, but the recipient will still be charged for the
* transaction's cost.
*/
function postRelayedCall(bytes calldata context, bool success, uint256 actualCharge, bytes32 preRetVal) external;
}pragma solidity ^0.5.0;
/**
* @dev Interface for `RelayHub`, the core contract of the GSN. Users should not need to interact with this contract
* directly.
*
* See the https://github.com/OpenZeppelin/openzeppelin-gsn-helpers[OpenZeppelin GSN helpers] for more information on
* how to deploy an instance of `RelayHub` on your local test network.
*/
interface IRelayHub {
// Relay management
/**
* @dev Adds stake to a relay and sets its `unstakeDelay`. If the relay does not exist, it is created, and the caller
* of this function becomes its owner. If the relay already exists, only the owner can call this function. A relay
* cannot be its own owner.
*
* All Ether in this function call will be added to the relay's stake.
* Its unstake delay will be assigned to `unstakeDelay`, but the new value must be greater or equal to the current one.
*
* Emits a {Staked} event.
*/
function stake(address relayaddr, uint256 unstakeDelay) external payable;
/**
* @dev Emitted when a relay's stake or unstakeDelay are increased
*/
event Staked(address indexed relay, uint256 stake, uint256 unstakeDelay);
/**
* @dev Registers the caller as a relay.
* The relay must be staked for, and not be a contract (i.e. this function must be called directly from an EOA).
*
* This function can be called multiple times, emitting new {RelayAdded} events. Note that the received
* `transactionFee` is not enforced by {relayCall}.
*
* Emits a {RelayAdded} event.
*/
function registerRelay(uint256 transactionFee, string calldata url) external;
/**
* @dev Emitted when a relay is registered or re-registerd. Looking at these events (and filtering out
* {RelayRemoved} events) lets a client discover the list of available relays.
*/
event RelayAdded(address indexed relay, address indexed owner, uint256 transactionFee, uint256 stake, uint256 unstakeDelay, string url);
/**
* @dev Removes (deregisters) a relay. Unregistered (but staked for) relays can also be removed.
*
* Can only be called by the owner of the relay. After the relay's `unstakeDelay` has elapsed, {unstake} will be
* callable.
*
* Emits a {RelayRemoved} event.
*/
function removeRelayByOwner(address relay) external;
/**
* @dev Emitted when a relay is removed (deregistered). `unstakeTime` is the time when unstake will be callable.
*/
event RelayRemoved(address indexed relay, uint256 unstakeTime);
/** Deletes the relay from the system, and gives back its stake to the owner.
*
* Can only be called by the relay owner, after `unstakeDelay` has elapsed since {removeRelayByOwner} was called.
*
* Emits an {Unstaked} event.
*/
function unstake(address relay) external;
/**
* @dev Emitted when a relay is unstaked for, including the returned stake.
*/
event Unstaked(address indexed relay, uint256 stake);
// States a relay can be in
enum RelayState {
Unknown, // The relay is unknown to the system: it has never been staked for
Staked, // The relay has been staked for, but it is not yet active
Registered, // The relay has registered itself, and is active (can relay calls)
Removed // The relay has been removed by its owner and can no longer relay calls. It must wait for its unstakeDelay to elapse before it can unstake
}
/**
* @dev Returns a relay's status. Note that relays can be deleted when unstaked or penalized, causing this function
* to return an empty entry.
*/
function getRelay(address relay) external view returns (uint256 totalStake, uint256 unstakeDelay, uint256 unstakeTime, address payable owner, RelayState state);
// Balance management
/**
* @dev Deposits Ether for a contract, so that it can receive (and pay for) relayed transactions.
*
* Unused balance can only be withdrawn by the contract itself, by calling {withdraw}.
*
* Emits a {Deposited} event.
*/
function depositFor(address target) external payable;
/**
* @dev Emitted when {depositFor} is called, including the amount and account that was funded.
*/
event Deposited(address indexed recipient, address indexed from, uint256 amount);
/**
* @dev Returns an account's deposits. These can be either a contracts's funds, or a relay owner's revenue.
*/
function balanceOf(address target) external view returns (uint256);
/**
* Withdraws from an account's balance, sending it back to it. Relay owners call this to retrieve their revenue, and
* contracts can use it to reduce their funding.
*
* Emits a {Withdrawn} event.
*/
function withdraw(uint256 amount, address payable dest) external;
/**
* @dev Emitted when an account withdraws funds from `RelayHub`.
*/
event Withdrawn(address indexed account, address indexed dest, uint256 amount);
// Relaying
/**
* @dev Checks if the `RelayHub` will accept a relayed operation.
* Multiple things must be true for this to happen:
* - all arguments must be signed for by the sender (`from`)
* - the sender's nonce must be the current one
* - the recipient must accept this transaction (via {acceptRelayedCall})
*
* Returns a `PreconditionCheck` value (`OK` when the transaction can be relayed), or a recipient-specific error
* code if it returns one in {acceptRelayedCall}.
*/
function canRelay(
address relay,
address from,
address to,
bytes calldata encodedFunction,
uint256 transactionFee,
uint256 gasPrice,
uint256 gasLimit,
uint256 nonce,
bytes calldata signature,
bytes calldata approvalData
) external view returns (uint256 status, bytes memory recipientContext);
// Preconditions for relaying, checked by canRelay and returned as the corresponding numeric values.
enum PreconditionCheck {
OK, // All checks passed, the call can be relayed
WrongSignature, // The transaction to relay is not signed by requested sender
WrongNonce, // The provided nonce has already been used by the sender
AcceptRelayedCallReverted, // The recipient rejected this call via acceptRelayedCall
InvalidRecipientStatusCode // The recipient returned an invalid (reserved) status code
}
/**
* @dev Relays a transaction.
*
* For this to succeed, multiple conditions must be met:
* - {canRelay} must `return PreconditionCheck.OK`
* - the sender must be a registered relay
* - the transaction's gas price must be larger or equal to the one that was requested by the sender
* - the transaction must have enough gas to not run out of gas if all internal transactions (calls to the
* recipient) use all gas available to them
* - the recipient must have enough balance to pay the relay for the worst-case scenario (i.e. when all gas is
* spent)
*
* If all conditions are met, the call will be relayed and the recipient charged. {preRelayedCall}, the encoded
* function and {postRelayedCall} will be called in that order.
*
* Parameters:
* - `from`: the client originating the request
* - `to`: the target {IRelayRecipient} contract
* - `encodedFunction`: the function call to relay, including data
* - `transactionFee`: fee (%) the relay takes over actual gas cost
* - `gasPrice`: gas price the client is willing to pay
* - `gasLimit`: gas to forward when calling the encoded function
* - `nonce`: client's nonce
* - `signature`: client's signature over all previous params, plus the relay and RelayHub addresses
* - `approvalData`: dapp-specific data forwared to {acceptRelayedCall}. This value is *not* verified by the
* `RelayHub`, but it still can be used for e.g. a signature.
*
* Emits a {TransactionRelayed} event.
*/
function relayCall(
address from,
address to,
bytes calldata encodedFunction,
uint256 transactionFee,
uint256 gasPrice,
uint256 gasLimit,
uint256 nonce,
bytes calldata signature,
bytes calldata approvalData
) external;
/**
* @dev Emitted when an attempt to relay a call failed.
*
* This can happen due to incorrect {relayCall} arguments, or the recipient not accepting the relayed call. The
* actual relayed call was not executed, and the recipient not charged.
*
* The `reason` parameter contains an error code: values 1-10 correspond to `PreconditionCheck` entries, and values
* over 10 are custom recipient error codes returned from {acceptRelayedCall}.
*/
event CanRelayFailed(address indexed relay, address indexed from, address indexed to, bytes4 selector, uint256 reason);
/**
* @dev Emitted when a transaction is relayed.
* Useful when monitoring a relay's operation and relayed calls to a contract
*
* Note that the actual encoded function might be reverted: this is indicated in the `status` parameter.
*
* `charge` is the Ether value deducted from the recipient's balance, paid to the relay's owner.
*/
event TransactionRelayed(address indexed relay, address indexed from, address indexed to, bytes4 selector, RelayCallStatus status, uint256 charge);
// Reason error codes for the TransactionRelayed event
enum RelayCallStatus {
OK, // The transaction was successfully relayed and execution successful - never included in the event
RelayedCallFailed, // The transaction was relayed, but the relayed call failed
PreRelayedFailed, // The transaction was not relayed due to preRelatedCall reverting
PostRelayedFailed, // The transaction was relayed and reverted due to postRelatedCall reverting
RecipientBalanceChanged // The transaction was relayed and reverted due to the recipient's balance changing
}
/**
* @dev Returns how much gas should be forwarded to a call to {relayCall}, in order to relay a transaction that will
* spend up to `relayedCallStipend` gas.
*/
function requiredGas(uint256 relayedCallStipend) external view returns (uint256);
/**
* @dev Returns the maximum recipient charge, given the amount of gas forwarded, gas price and relay fee.
*/
function maxPossibleCharge(uint256 relayedCallStipend, uint256 gasPrice, uint256 transactionFee) external view returns (uint256);
// Relay penalization.
// Any account can penalize relays, removing them from the system immediately, and rewarding the
// reporter with half of the relay's stake. The other half is burned so that, even if the relay penalizes itself, it
// still loses half of its stake.
/**
* @dev Penalize a relay that signed two transactions using the same nonce (making only the first one valid) and
* different data (gas price, gas limit, etc. may be different).
*
* The (unsigned) transaction data and signature for both transactions must be provided.
*/
function penalizeRepeatedNonce(bytes calldata unsignedTx1, bytes calldata signature1, bytes calldata unsignedTx2, bytes calldata signature2) external;
/**
* @dev Penalize a relay that sent a transaction that didn't target `RelayHub`'s {registerRelay} or {relayCall}.
*/
function penalizeIllegalTransaction(bytes calldata unsignedTx, bytes calldata signature) external;
/**
* @dev Emitted when a relay is penalized.
*/
event Penalized(address indexed relay, address sender, uint256 amount);
/**
* @dev Returns an account's nonce in `RelayHub`.
*/
function getNonce(address from) external view returns (uint256);
}pragma solidity ^0.5.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor () internal { }
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/introspection/IERC165.sol";
/**
@title ERC-1155 Multi Token Receiver Interface
@dev See https://eips.ethereum.org/EIPS/eip-1155
*/
contract IERC1155TokenReceiver is IERC165 {
/**
@dev Handles the receipt of a single ERC1155 token type. This function is
called at the end of a `safeTransferFrom` after the balance has been updated.
To accept the transfer, this must return
`bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
(i.e. 0xf23a6e61, or its own function selector).
@param operator The address which initiated the transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param id The ID of the token being transferred
@param value The amount of tokens being transferred
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
)
external
returns(bytes4);
/**
@dev Handles the receipt of a multiple ERC1155 token types. This function
is called at the end of a `safeBatchTransferFrom` after the balances have
been updated. To accept the transfer(s), this must return
`bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
(i.e. 0xbc197c81, or its own function selector).
@param operator The address which initiated the batch transfer (i.e. msg.sender)
@param from The address which previously owned the token
@param ids An array containing ids of each token being transferred (order and length must match values array)
@param values An array containing amounts of each token being transferred (order and length must match ids array)
@param data Additional data with no specified format
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
)
external
returns(bytes4);
}pragma solidity ^0.5.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts may inherit from this and call {_registerInterface} to declare
* their support of an interface.
*/
contract ERC165 is IERC165 {
/*
* bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
*/
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
* @dev Mapping of interface ids to whether or not it's supported.
*/
mapping(bytes4 => bool) private _supportedInterfaces;
constructor () internal {
// Derived contracts need only register support for their own interfaces,
// we register support for ERC165 itself here
_registerInterface(_INTERFACE_ID_ERC165);
}
/**
* @dev See {IERC165-supportsInterface}.
*
* Time complexity O(1), guaranteed to always use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool) {
return _supportedInterfaces[interfaceId];
}
/**
* @dev Registers the contract as an implementer of the interface defined by
* `interfaceId`. Support of the actual ERC165 interface is automatic and
* registering its interface id is not required.
*
* See {IERC165-supportsInterface}.
*
* Requirements:
*
* - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
*/
function _registerInterface(bytes4 interfaceId) internal {
require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
_supportedInterfaces[interfaceId] = true;
}
}pragma solidity ^0.5.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}pragma solidity ^0.5.0;
import { MemcpyLib } from "./MemcpyLib.sol";
library SliceLib {
struct Slice {
uint256 data;
uint256 length;
uint256 offset;
}
function toPtr(bytes memory input, uint256 offset) internal pure returns (uint256 data) {
assembly {
data := add(input, add(offset, 0x20))
}
}
function toSlice(bytes memory input, uint256 offset, uint256 length) internal pure returns (Slice memory retval) {
retval.data = toPtr(input, offset);
retval.length = length;
retval.offset = offset;
}
function toSlice(bytes memory input) internal pure returns (Slice memory) {
return toSlice(input, 0);
}
function toSlice(bytes memory input, uint256 offset) internal pure returns (Slice memory) {
if (input.length < offset) offset = input.length;
return toSlice(input, offset, input.length - offset);
}
function toSlice(Slice memory input, uint256 offset, uint256 length) internal pure returns (Slice memory) {
return Slice({
data: input.data + offset,
offset: input.offset + offset,
length: length
});
}
function toSlice(Slice memory input, uint256 offset) internal pure returns (Slice memory) {
return toSlice(input, offset, input.length - offset);
}
function toSlice(Slice memory input) internal pure returns (Slice memory) {
return toSlice(input, 0);
}
function maskLastByteOfWordAt(uint256 data) internal pure returns (uint8 lastByte) {
assembly {
lastByte := and(mload(data), 0xff)
}
}
function get(Slice memory slice, uint256 index) internal pure returns (bytes1 result) {
return bytes1(maskLastByteOfWordAt(slice.data - 0x1f + index));
}
function setByteAt(uint256 ptr, uint8 value) internal pure {
assembly {
mstore8(ptr, value)
}
}
function set(Slice memory slice, uint256 index, uint8 value) internal pure {
setByteAt(slice.data + index, value);
}
function wordAt(uint256 ptr, uint256 length) internal pure returns (bytes32 word) {
assembly {
let mask := sub(shl(mul(length, 0x8), 0x1), 0x1)
word := and(mload(sub(ptr, sub(0x20, length))), mask)
}
}
function asWord(Slice memory slice) internal pure returns (bytes32 word) {
uint256 data = slice.data;
uint256 length = slice.length;
return wordAt(data, length);
}
function toDataStart(bytes memory input) internal pure returns (bytes32 start) {
assembly {
start := add(input, 0x20)
}
}
function copy(Slice memory slice) internal pure returns (bytes memory retval) {
uint256 length = slice.length;
retval = new bytes(length);
bytes32 src = bytes32(slice.data);
bytes32 dest = toDataStart(retval);
MemcpyLib.memcpy(dest, src, length);
}
function keccakAt(uint256 data, uint256 length) internal pure returns (bytes32 result) {
assembly {
result := keccak256(data, length)
}
}
function toKeccak(Slice memory slice) internal pure returns (bytes32 result) {
return keccakAt(slice.data, slice.length);
}
}pragma solidity ^0.5.0;
library MemcpyLib {
function memcpy(bytes32 dest, bytes32 src, uint256 len) internal pure {
assembly {
for {} iszero(lt(len, 0x20)) { len := sub(len, 0x20) } {
mstore(dest, mload(src))
dest := add(dest, 0x20)
src := add(src, 0x20)
}
let mask := sub(shl(mul(sub(32, len), 8), 1), 1)
mstore(dest, or(and(mload(src), not(mask)), and(mload(dest), mask)))
}
}
}pragma solidity ^0.5.0;
/**
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
* `CREATE2` can be used to compute in advance the address where a smart
* contract will be deployed, which allows for interesting new mechanisms known
* as 'counterfactual interactions'.
*
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
* information.
*
* _Available since v2.5.0._
*/
library Create2 {
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}. Note that
* a contract cannot be deployed twice using the same salt.
*/
function deploy(bytes32 salt, bytes memory bytecode) internal returns (address) {
address addr;
// solhint-disable-next-line no-inline-assembly
assembly {
addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
}
require(addr != address(0), "Create2: Failed on deploy");
return addr;
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the `bytecode`
* or `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt, bytes memory bytecode) internal view returns (address) {
return computeAddress(salt, bytecode, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes memory bytecodeHash, address deployer) internal pure returns (address) {
bytes32 bytecodeHashHash = keccak256(bytecodeHash);
bytes32 _data = keccak256(
abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHashHash)
);
return address(bytes20(_data << 96));
}
}pragma experimental ABIEncoderV2;
pragma solidity ^0.5.0;
import { ProxyWalletLib } from "../ProxyWallet/ProxyWalletLib.sol";
interface IProxyWalletFactory {
function proxy(ProxyWalletLib.ProxyCall[] calldata /* calls */) external payable returns (bytes[] memory /* returnValues */);
function getImplementation() external view returns (address);
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract ABI
API[{"constant":false,"inputs":[{"components":[{"name":"typeCode","type":"uint8"},{"name":"to","type":"address"},{"name":"value","type":"uint256"},{"name":"data","type":"bytes"}],"name":"calls","type":"tuple[]"}],"name":"proxy","outputs":[{"name":"returnValues","type":"bytes[]"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"},{"name":"","type":"uint256[]"},{"name":"","type":"uint256[]"},{"name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"pure","type":"function"}]Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.