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

Delegation Chain Enforcer - Referral System

Open hanzel98 opened this issue 8 months ago • 0 comments

What?

  • Enables a referral system where people can get prizes for referring new users.
  • This system depends on an off-chain system for certain validations like KYC, repeated addresses, and correct usage of enforcers in the delegations.

How?

  • The system creates a delegation that allows a redeemer to call an enforcer function post(address[] referrals), this method stores an array of addresses that will be paid in the afterHook of the enforcer. The delegators (referrers) validate their position in the array when calling the function post in the beforeHook of the enforcer. The afterHook validates that the post function has stored the addresses in the state and it pays these addresses using an allowance delegation passed in the args by the redeemer.

Intermediary Chain Account Responsibilities - Offchain Part

  • Get a delegation from the Root Delegator, DelegationChainEnforcer's Owner.
  • Redelegate to the users to extend the chain.
  • Validate that a referral address is only once in the chain.
  • Validate that the delegation from the User=>ICA includes the DelegationChainEnforcer, once and only once, and the correct position in the terms.
  • Validate the KYC and off-chain steps.
  • Prepare for redemption when requested. Create the post(address[]) execution, and make sure it doesn't have duplicate addresses.
    • Make sure someone can't add himself twice in the same delegation chain.
    • Make sure the intermediary chain is involved on every level otherwise fails.
  • Get the erc20 allowance delegations for paying the prizes. According to the position of each address.
  • Submit as a redeemer the execution to the post(address[]) using the referral delegation chain, attaching in the args the erc20 allowance delegations for paying the prizes.

Intermediary Chain Account Responsibilities - Onchain Part

  • Make sure that the same array of referrals doesn't get paid twice. The array of addresses is hashed and marked as paid.
  • Pay the referrals the prize amount according to their position, no matter the array length it always pays the last 5 for example.
  • Allow each delegator to enforce their position in the array of referrals, so no one can submit an incorrect array.
  • Redeem the allowance delegations passed in the args in the afterHook to pay the prizes. Protects the allowance delegation with the delegation hash+redeemer.
  • Make sure the referrals get their correct amount of ERC20 tokens, in the afterHook as a prize, otherwise revert.

hanzel98 avatar May 02 '25 02:05 hanzel98