@0x/contracts-zero-ex: Use array of structs in AffiliateFeeTransformer data.

This commit is contained in:
Lawrence Forman 2020-06-06 10:59:27 -04:00 committed by Lawrence Forman
parent 5707993995
commit 7c5035aa39

View File

@ -37,14 +37,16 @@ contract AffiliateFeeTransformer is
using LibSafeMathV06 for uint256; using LibSafeMathV06 for uint256;
using LibERC20Transformer for IERC20TokenV06; using LibERC20Transformer for IERC20TokenV06;
/// @dev Transform data to ABI-encode and pass into `transform()`. /// @dev Information for a single fee.
struct TransformData { struct TokenFee {
// The tokens to transfer to each respective address in `recipients`. // The token to transfer to `recipient`.
IERC20TokenV06[] tokens; IERC20TokenV06 token;
// Amount of each token in `tokens` to transfer to the affiliate. // Amount of each `token` to transfer to `recipient`.
uint256[] amounts; // If `amount == uint256(-1)`, the entire balance of `token` will be
// Recipient of each token in `tokens`. // transferred.
address payable[] recipients; uint256 amount;
// Recipient of `token`.
address payable recipient;
} }
/// @dev Create this contract. /// @dev Create this contract.
@ -55,34 +57,24 @@ contract AffiliateFeeTransformer is
{} {}
/// @dev Transfers tokens to recipients. /// @dev Transfers tokens to recipients.
/// @param data_ ABI-encoded `TransformData`, indicating which tokens to transfer. /// @param data ABI-encoded `TokenFee[]`, indicating which tokens to transfer.
/// @return rlpDeploymentNonce RLP-encoded deployment nonce of the deployer /// @return rlpDeploymentNonce RLP-encoded deployment nonce of the deployer
/// when this transformer was deployed. This is used to verify that /// when this transformer was deployed. This is used to verify that
/// this transformer was deployed by a trusted contract. /// this transformer was deployed by a trusted contract.
function transform( function transform(
bytes32, // callDataHash, bytes32, // callDataHash,
address payable, // taker, address payable, // taker,
bytes calldata data_ bytes calldata data
) )
external external
override override
returns (bytes memory rlpDeploymentNonce) returns (bytes memory rlpDeploymentNonce)
{ {
TransformData memory data = abi.decode(data_, (TransformData)); TokenFee[] memory fees = abi.decode(data, (TokenFee[]));
// All arrays must be the same length.
if (data.tokens.length != data.amounts.length ||
data.tokens.length != data.recipients.length)
{
LibTransformERC20RichErrors.InvalidTransformDataError(
LibTransformERC20RichErrors.InvalidTransformDataErrorCode.INVALID_ARRAY_LENGTH,
data_
).rrevert();
}
// Transfer tokens to recipients. // Transfer tokens to recipients.
for (uint256 i = 0; i < data.tokens.length; ++i) { for (uint256 i = 0; i < fees.length; ++i) {
data.tokens[i].transformerTransfer(data.recipients[i], data.amounts[i]); fees[i].token.transformerTransfer(fees[i].recipient, fees[i].amount);
} }
return _getRLPEncodedDeploymentNonce(); return _getRLPEncodedDeploymentNonce();