Skip to content

[ETHEREUM-CONTRACTS] improve CFASuperAppBase #2069

Description

@hajnalben

Add currentFlowRate param to onFlowCreated and onFlowUpdated hooks as it is used in almost every cases in the implementation side. Unnecessary for onFlowDeleted as it should be a constant 0.

function onFlowCreated(
      ISuperToken /*superToken*/,
      address /*sender*/,
      int96 /*currentFlowRate*/, //  <==================== here
      bytes calldata ctx
  ) internal virtual returns (bytes memory /*newCtx*/) {
      return ctx;
  }

  function onFlowUpdated(
      ISuperToken /*superToken*/,
      address /*sender*/,
      int96 /*currentFlowRate*/, // <==================== here
      int96 /*previousFlowRate*/,
      uint256 /*lastUpdated*/,
      bytes calldata ctx
  ) internal virtual returns (bytes memory /*newCtx*/) {
      return ctx;
  }
function afterAgreementCreated(
      ISuperToken superToken,
      address agreementClass,
      bytes32 /*agreementId*/,
      bytes calldata agreementData,
      bytes calldata /*cbdata*/,
      bytes calldata ctx
  ) external override returns (bytes memory newCtx) {
      if (msg.sender != address(HOST)) revert UnauthorizedHost();
      if (!isAcceptedAgreement(agreementClass)) return ctx;
      if (!isAcceptedSuperToken(superToken)) revert NotAcceptedSuperToken();

      (address sender, ) = abi.decode(agreementData, (address, address));
      int96 currentFlowRate = superToken.getFlowRate(sender, address(this)); // <==================== here

      return
          onFlowCreated(
              superToken,
              sender,
              currentFlowRate, // <==================== here
              ctx // userData can be acquired with `host.decodeCtx(ctx).userData`
          );
  }

function afterAgreementUpdated(
      ISuperToken superToken,
      address agreementClass,
      bytes32 /*agreementId*/,
      bytes calldata agreementData,
      bytes calldata cbdata,
      bytes calldata ctx
  ) external override returns (bytes memory newCtx) {
      if (msg.sender != address(HOST)) revert UnauthorizedHost();
      if (!isAcceptedAgreement(agreementClass)) return ctx;
      if (!isAcceptedSuperToken(superToken)) revert NotAcceptedSuperToken();

      (address sender, ) = abi.decode(agreementData, (address, address));
      (int96 previousFlowRate, uint256 lastUpdated) = abi.decode(cbdata, (int96, uint256));
      int96 currentFlowRate = superToken.getFlowRate(sender, address(this)); // <==================== here

      return
          onFlowUpdated(
              superToken,
              sender,
              currentFlowRate, // <==================== here
              previousFlowRate,
              lastUpdated,
              ctx // userData can be acquired with `host.decodeCtx(ctx).userData`
          );
  }

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions