Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
@0x/contracts-zero-ex: Revamp TransformERC20.
Browse files Browse the repository at this point in the history
  • Loading branch information
merklejerk authored and dorothy-zbornak committed May 14, 2020
1 parent 4bdc220 commit b4c5081
Show file tree
Hide file tree
Showing 41 changed files with 1,148 additions and 1,183 deletions.
25 changes: 11 additions & 14 deletions contracts/zero-ex/contracts/src/errors/LibPuppetRichErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,22 @@ library LibPuppetRichErrors {
);
}

function InvalidPuppetInstanceError(address puppet)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InvalidPuppetInstanceError(address)")),
puppet
);
}

function PuppetNotAcquiredError(address puppet)
function PuppetExecuteWithFailedError(
address puppet,
address callTarget,
bytes memory callData,
bytes memory errorData
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("PuppetNotAcquiredError(address)")),
puppet
bytes4(keccak256("PuppetExecuteWithFailedError(address,address,bytes,bytes)")),
puppet,
callTarget,
callData,
errorData
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,45 @@ library LibTransformERC20RichErrors {
);
}

function TransferERC20FailedError(
address token,
address to,
uint256 amount
function UnauthorizedTransformerError(
address transformer,
bytes memory rlpNonce
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("TransferERC20FailedError(address,address,uint256)")),
token,
to,
amount
bytes4(keccak256("UnauthorizedTransformerError(address,bytes)")),
transformer,
rlpNonce
);
}

function ERC20TransformerFailedError(
address transformer,
address[] memory tokens,
uint256[] memory amounts
function InvalidRLPNonceError(
bytes memory rlpNonce
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("ERC20TransformerFailedError(address,address[],uint256[])")),
transformer,
tokens,
amounts
bytes4(keccak256("InvalidRLPNonceError(bytes)")),
rlpNonce
);
}

function InvalidTransformationError(
function ERC20TransformerFailedError(
address transformer,
address[] memory tokens,
uint256[] memory amounts,
bytes memory data
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InvalidTransformationError(address,address[],uint256[],bytes)")),
bytes4(keccak256("ERC20TransformerFailedError(address,bytes)")),
transformer,
tokens,
amounts,
data
);
}
Expand Down
56 changes: 56 additions & 0 deletions contracts/zero-ex/contracts/src/external/AllowanceTarget.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2020 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol";
import "../errors/LibSpenderRichErrors.sol";
import "./IAllowanceTarget.sol";


/// @dev The allowance target for the TokenSpender feature.
contract AllowanceTarget is
IAllowanceTarget,
AuthorizableV06
{
// solhint-disable no-unused-vars,indent,no-empty-blocks
using LibRichErrorsV06 for bytes;

/// @dev Execute an arbitrary call. Only an authority can call this.
/// @param target The call target.
/// @param callData The call data.
/// @return resultData The data returned by the call.
function execute(
address payable target,
bytes calldata callData
)
external
payable
override
onlyAuthorized
returns (bytes memory resultData)
{
bool success;
(success, resultData) = target.call(callData);
if (!success) {
resultData.rrevert();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,19 @@ pragma experimental ABIEncoderV2;
import "@0x/contracts-utils/contracts/src/v06/interfaces/IAuthorizableV06.sol";


/// @dev A contract that can execute arbitrary calls from an authority.
interface IPuppet is
/// @dev The allowance target for the TokenSpender feature.
interface IAllowanceTarget is
IAuthorizableV06
{
/// @dev Execute an arbitrary call.
/// @dev Execute an arbitrary call. Only an authority can call this.
/// @param target The call target.
/// @param callData The call data.
/// @param value Ether to attach to the call.
/// @return resultData The data returned by the call.
function execute(
address payable target,
bytes calldata callData,
uint256 value
bytes calldata callData
)
external
payable
returns (bytes memory resultData);

/// @dev Allows the puppet to receive ETH.
receive() external payable;
}
58 changes: 58 additions & 0 deletions contracts/zero-ex/contracts/src/external/IPuppet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2020 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/v06/interfaces/IOwnableV06.sol";


/// @dev A contract that can execute arbitrary calls from its owner.
interface IPuppet is
IOwnableV06
{
/// @dev Execute an arbitrary call. Only an authority can call this.
/// @param target The call target.
/// @param callData The call data.
/// @param value Ether to attach to the call.
/// @return resultData The data returned by the call.
function execute(
address payable target,
bytes calldata callData,
uint256 value
)
external
payable
returns (bytes memory resultData);

/// @dev Execute an arbitrary delegatecall, in the context of this puppet.
/// Only an authority can call this.
/// @param target The call target.
/// @param callData The call data.
/// @return resultData The data returned by the call.
function executeWith(
address payable target,
bytes calldata callData
)
external
payable
returns (bytes memory resultData);

/// @dev Allows the puppet to receive ETH.
receive() external payable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;

import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol";
import "@0x/contracts-utils/contracts/src/v06/OwnableV06.sol";
import "../errors/LibPuppetRichErrors.sol";
import "./IPuppet.sol";


/// @dev A contract that can execute arbitrary calls from an authority.
/// @dev A contract that can execute arbitrary calls from its owner.
contract Puppet is
IPuppet,
AuthorizableV06
OwnableV06
{
// solhint-disable no-unused-vars,indent,no-empty-blocks
using LibRichErrorsV06 for bytes;

/// @dev Execute an arbitrary call, forwarding any ether attached and
/// refunding any remaining ether. Only an authority can call this.
/// @dev Execute an arbitrary call. Only an authority can call this.
/// @param target The call target.
/// @param callData The call data.
/// @param value Ether to attach to the call.
Expand All @@ -47,7 +46,7 @@ contract Puppet is
external
payable
override
onlyAuthorized
onlyOwner
returns (bytes memory resultData)
{
bool success;
Expand All @@ -65,16 +64,39 @@ contract Puppet is
}
}

// solhint-disable state-visibility
/// @dev Execute an arbitrary delegatecall, in the context of this puppet.
/// Only an authority can call this.
/// @param target The call target.
/// @param callData The call data.
/// @return resultData The data returned by the call.
function executeWith(
address payable target,
bytes calldata callData
)
external
payable
override
onlyOwner
returns (bytes memory resultData)
{
bool success;
(success, resultData) = target.delegatecall(callData);
if (!success) {
LibPuppetRichErrors
.PuppetExecuteWithFailedError(
address(this),
target,
callData,
resultData
)
.rrevert();
}
}

// solhint-disable
/// @dev Allows this contract to receive ether.
receive() external override payable {}
// solhint-enable state-visibility

/// @dev Destroy this contract. Only callable by the owner.
/// @param ethReceiver A payable recipient of any ETH in this contract.
function die(address payable ethReceiver) external onlyOwner {
selfdestruct(ethReceiver);
}
// solhint-enable

/// @dev Signal support for receiving ERC1155 tokens.
/// @param interfaceID The interface ID, as per ERC-165 rules.
Expand All @@ -88,6 +110,7 @@ contract Puppet is
interfaceID == this.onERC1155Received.selector ^ this.onERC1155BatchReceived.selector ||
interfaceID == this.tokenFallback.selector;
}

/// @dev Allow this contract to receive ERC1155 tokens.
/// @return success `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
function onERC1155Received(
Expand Down
55 changes: 0 additions & 55 deletions contracts/zero-ex/contracts/src/features/IPuppetPool.sol

This file was deleted.

Loading

0 comments on commit b4c5081

Please sign in to comment.