Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ERC20RoyaltyEnforcer #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

gitaalekhyapaul
Copy link

What?

  • Added ERC20RoyaltyEnforcer contract to enforce royalty payments when redeeming ERC20 token delegations
  • Added comprehensive test suite for the enforcer

Why?

  • Enable token delegations with royalty distribution requirements
  • Ensure secure and reliable royalty payments to specified recipients
  • Prevent unauthorized transfers and protect delegator/recipient funds

How?

The flow works as follows:

sequenceDiagram
participant Delegator
participant DelegationManager
participant ERC20RoyaltyEnforcer
participant ERC20Token
participant RoyaltyRecipients
participant Redeemer
Delegator->>DelegationManager: Delegate tokens with royalty terms
DelegationManager->>ERC20RoyaltyEnforcer: beforeHook()
Note over ERC20RoyaltyEnforcer: Validate transfer details<br/>Lock execution<br/>Cache balances
alt Invalid conditions
ERC20RoyaltyEnforcer-->>DelegationManager: Revert with error
end
Delegator->>ERC20Token: Transfer tokens to enforcer
DelegationManager->>ERC20RoyaltyEnforcer: afterHook()
alt Insufficient balance
ERC20RoyaltyEnforcer-->>DelegationManager: Revert with ERC20InsufficientBalance
end
ERC20RoyaltyEnforcer->>RoyaltyRecipients: Distribute royalties
Note over ERC20RoyaltyEnforcer: Calculate remaining balance
alt Remaining balance > 0
ERC20RoyaltyEnforcer->>Redeemer: Transfer remaining tokens
end
Note over ERC20RoyaltyEnforcer: Unlock execution
Loading
  • Implemented core royalty enforcement logic in src/enforcers/ERC20RoyaltyEnforcer.sol

  • Added state management for:

    • Execution locking to prevent reentrancy
    • Balance caching for validation
    • Royalty distribution tracking
  • Added validation checks for:

    • Transfer recipient must be enforcer
    • Transfer amount >= total royalties
    • Valid redeemer address
    • Single execution mode only
    • Zero ETH value
    • Valid calldata format
  • Added comprehensive test coverage in test/enforcers/ERC20RoyaltyEnforcerTest.t.sol

  • Key test scenarios:

    • Valid royalty execution
    • Balance caching
    • Enforcer locking
    • Error cases (invalid recipient, insufficient amount, etc)

Signed-off-by: Gita Alekhya Paul <[email protected]>
@gitaalekhyapaul gitaalekhyapaul requested a review from a team as a code owner November 13, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant