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: Introduce the TransformERC20 feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
dorothy-zbornak authored and merklejerk committed May 5, 2020
1 parent f9cf097 commit 1fc7d3f
Show file tree
Hide file tree
Showing 43 changed files with 3,520 additions and 18 deletions.
4 changes: 0 additions & 4 deletions contracts/utils/contracts/src/v06/interfaces/IOwnableV06.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ pragma solidity ^0.6.5;

interface IOwnableV06 {

/// @dev The owner of this contract.
/// @return ownerAddress The owner address.
function owner() external view returns (address ownerAddress);

/// @dev Emitted by Ownable when ownership is transferred.
/// @param previousOwner The previous owner of the contract.
/// @param newOwner The new owner of the contract.
Expand Down
4 changes: 4 additions & 0 deletions contracts/zero-ex/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
{
"note": "Create this package",
"pr": 2540
},
{
"note": "Introduce fill `TransformERC20` feature.",
"pr": 2545
}
]
}
Expand Down
10 changes: 10 additions & 0 deletions contracts/zero-ex/contracts/src/errors/LibCommonRichErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ library LibCommonRichErrors {
sender
);
}

function IllegalReentrancyError()
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("IllegalReentrancyError()"))
);
}
}
68 changes: 68 additions & 0 deletions contracts/zero-ex/contracts/src/errors/LibPuppetRichErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
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;


library LibPuppetRichErrors {

// solhint-disable func-name-mixedcase

function PuppetExecuteFailedError(
address puppet,
address callTarget,
bytes memory callData,
uint256 callValue,
bytes memory errorData
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("PuppetExecuteFailedError(address,address,bytes,uint256,bytes)")),
puppet,
callTarget,
callData,
callValue,
errorData
);
}

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

function PuppetNotAcquiredError(address puppet)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("PuppetNotAcquiredError(address)")),
puppet
);
}
}
46 changes: 46 additions & 0 deletions contracts/zero-ex/contracts/src/errors/LibSpenderRichErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
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;


library LibSpenderRichErrors {

// solhint-disable func-name-mixedcase

function SpenderERC20TransferFromFailedError(
address token,
address owner,
address to,
uint256 amount,
bytes memory errorData
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("SpenderERC20TransferFromFailedError(address,address,address,uint256,bytes)")),
token,
owner,
to,
amount,
errorData
);
}
}
219 changes: 219 additions & 0 deletions contracts/zero-ex/contracts/src/errors/LibTransformERC20RichErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
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;


library LibTransformERC20RichErrors {

// solhint-disable func-name-mixedcase,separate-by-one-line-in-contract

function InsufficientEthAttachedError(
uint256 ethAttached,
uint256 ethNeeded
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InsufficientEthAttachedError(uint256,uint256)")),
ethAttached,
ethNeeded
);
}

function IncompleteERC20TransformError(
address outputToken,
uint256 outputTokenAmount,
uint256 minOutputTokenAmount
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("IncompleteERC20TransformError(address,uint256,uint256)")),
outputToken,
outputTokenAmount,
minOutputTokenAmount
);
}

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

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

function InvalidTransformationError(
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)")),
transformer,
tokens,
amounts,
data
);
}

// FillQuoteTransformer errors /////////////////////////////////////////////

function IncompleteFillSellQuoteError(
address sellToken,
uint256 soldAmount,
uint256 sellAmount
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("IncompleteFillSellQuoteError(address,uint256,uint256)")),
sellToken,
soldAmount,
sellAmount
);
}

function IncompleteFillBuyQuoteError(
address buyToken,
uint256 boughtAmount,
uint256 buyAmount
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("IncompleteFillBuyQuoteError(address,uint256,uint256)")),
buyToken,
boughtAmount,
buyAmount
);
}

function InsufficientTakerTokenError(
uint256 tokenBalance,
uint256 tokensNeeded
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InsufficientTakerTokenError(uint256,uint256)")),
tokenBalance,
tokensNeeded
);
}

function InsufficientProtocolFeeError(
uint256 ethBalance,
uint256 ethNeeded
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InsufficientProtocolFeeError(uint256,uint256)")),
ethBalance,
ethNeeded
);
}

function InvalidERC20AssetDataError(
bytes memory assetData
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InvalidERC20AssetDataError(bytes)")),
assetData
);
}

// WethTransformer rors ////////////////////////////////////////////////////

function WrongNumberOfTokensReceivedError(
uint256 actual,
uint256 expected
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("WrongNumberOfTokensReceivedError(uint256,uint256)")),
actual,
expected
);
}

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

0 comments on commit 1fc7d3f

Please sign in to comment.