Skip to content

Conversation

@hanzel98
Copy link
Contributor

@hanzel98 hanzel98 commented Jun 10, 2025

What?

  • This ERC1155TransferEnforcer is needed to validate the transfer amounts and ids for erc1155.

Why?

  • We need this enforcer to create delegations for specific amounts and ids on erc1155

How?

  • Creating amount limits for each token, it validates and stores the used amount in a spent map

@hanzel98 hanzel98 self-assigned this Jun 10, 2025
@hanzel98 hanzel98 requested a review from a team as a code owner June 10, 2025 03:12
@hanzel98 hanzel98 marked this pull request as draft June 10, 2025 03:12
@hanzel98 hanzel98 changed the title feat: adds ERC1155TransferEnforcer Adds ERC1155TransferEnforcer Jun 13, 2025
@hanzel98 hanzel98 requested a review from MoMannn June 13, 2025 20:28
@hanzel98 hanzel98 marked this pull request as ready for review June 13, 2025 20:32
MoMannn
MoMannn previously approved these changes Jun 17, 2025
@hanzel98 hanzel98 requested a review from McOso June 19, 2025 20:29
@hanzel98 hanzel98 added the new release This PR goes to the next release label Jun 25, 2025
event IncreasedSpentMap(address indexed sender, bytes32 indexed delegationHash, uint256 tokenId, uint256 limit, uint256 spent);

/**
* @notice Enforces that the contract and tokenIds are permitted for transfer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract, tokenIds and amounts

/**
* @notice Enforces that the contract and tokenIds are permitted for transfer
* @dev Validates that the transfer execution matches the permitted terms and updates spent amounts
* @param _terms encoded terms containing transfer type, contract address, token IDs and amounts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terms don't include transfer type anymore since its extracted via bytes length

/**
* @notice Decodes the terms to get the transfer type, permitted contract and token IDs
* @dev Validates the terms length and structure
* @param _terms The encoded terms containing transfer type, contract address and token IDs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no transfer type here as well

if (callData_.length != 196 && callData_.length < 324) revert("ERC1155TransferEnforcer:invalid-calldata-length");
if (target_ != permittedContract_) revert("ERC1155TransferEnforcer:unauthorized-contract-target");

bytes4 selector_ = bytes4(callData_[0:4]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think writting this this way:

if (isBatch_) {
    if (selector_ != IERC1155.safeBatchTransferFrom.selector) {
        revert("ERC1155TransferEnforcer:unauthorized-selector-batch");
    }
    _validateBatchTransfer(_delegationHash, callData_, permittedTokenIds_, permittedAmounts_);
} else {    
    if (selector_ != IERC1155.safeTransferFrom.selector) {
        revert("ERC1155TransferEnforcer:unauthorized-selector-single");
    }
    _validateSingleTransfer(_delegationHash, callData_, permittedTokenIds_[0], permittedAmounts_[0]);
}

Should be slightly better gas wise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new release This PR goes to the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants