delegation-framework icon indicating copy to clipboard operation
delegation-framework copied to clipboard

feat: Return value enforcer

Open patidarmanoj10 opened this issue 1 year ago • 0 comments

What?

  • Introduces ReturnValueComparisonEnforcer, a new enforcer contract for the delegation framework.
  • Allows enforcement of rules based on the return value of a staticcall to any contract.
  • Supports flexible comparison operators: EQ, NEQ, GTE, LTE.
  • Supports multiple value types: uint256, int256, uint128, int128, and bool.
  • Compares values using ABI encoding for equality and decodes for ordered comparisons.

Why?

  • Enables advanced delegation use cases where execution should be conditional on external contract state.
  • Example: Only allow a repay action if the collateral ratio (queried from a protocol) is below a threshold.
  • Increases security and flexibility for protocol integrations and automated account management.

How?

  • _terms encodes the target contract, calldata, comparison operator, value type, and expected value.
  • In beforeHook, the enforcer performs a staticcall to the target with the provided calldata.
  • For EQ/NEQ, compares the keccak256 hash of the ABI-encoded return value and expected value (supports any type, including structs).
  • For GTE/LTE, decodes the return and expected value to the specified type and performs the ordered comparison.
  • Reverts with clear error messages if the comparison fails or if the type/operator is unsupported.

patidarmanoj10 avatar Jun 11 '25 07:06 patidarmanoj10