diff --git a/packages/ethereum-contracts/contracts/agreements/InstantDistributionAgreementV1.sol b/packages/ethereum-contracts/contracts/agreements/InstantDistributionAgreementV1.sol index 6bd8a6740b..4ae5b4a9d6 100644 --- a/packages/ethereum-contracts/contracts/agreements/InstantDistributionAgreementV1.sol +++ b/packages/ethereum-contracts/contracts/agreements/InstantDistributionAgreementV1.sol @@ -14,10 +14,11 @@ import { AgreementLibrary } from "./AgreementLibrary.sol"; /** - * @title InstantDistributionAgreementV1 contract + * @title [DEPRECATED] InstantDistributionAgreementV1 contract * @author Superfluid * @dev Please read IInstantDistributionAgreementV1 for implementation notes. * @dev For more technical notes, please visit protocol-monorepo wiki area. + * @custom:deprecated Use GeneralDistributionAgreementV1 instead * * Storage Layout Notes * Agreement State diff --git a/packages/ethereum-contracts/contracts/apps/CFAv1Library.sol b/packages/ethereum-contracts/contracts/apps/CFAv1Library.sol index c3b2efb283..ac68e07f64 100644 --- a/packages/ethereum-contracts/contracts/apps/CFAv1Library.sol +++ b/packages/ethereum-contracts/contracts/apps/CFAv1Library.sol @@ -8,7 +8,8 @@ import { } from "../interfaces/superfluid/ISuperfluid.sol"; /** - * @title Constant flow agreement v1 library + * @title [DEPRECATED] Constant flow agreement v1 library + * @custom:deprecated Use SuperTokenV1Library instead * @author Superfluid * @dev for working with the constant flow agreement within solidity * @dev the first set of functions are each for callAgreement() diff --git a/packages/ethereum-contracts/contracts/apps/IDAv1Library.sol b/packages/ethereum-contracts/contracts/apps/IDAv1Library.sol deleted file mode 100644 index 1b00ccdcd6..0000000000 --- a/packages/ethereum-contracts/contracts/apps/IDAv1Library.sol +++ /dev/null @@ -1,988 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >= 0.8.11; -pragma experimental ABIEncoderV2; - -import {ISuperfluid, ISuperfluidToken} from "../interfaces/superfluid/ISuperfluid.sol"; - -import { - IInstantDistributionAgreementV1 -} from "../interfaces/agreements/IInstantDistributionAgreementV1.sol"; - -/// @title Instant Distribution Agreement V1 helper library for solidity development. -/// @author Superfluid -/// @dev Set a variable of type `InitData` in the contract, then call this library's functions -/// directly `initData.functionName()`. -library IDAv1Library { - - /// @dev Initialization data. - /// @param host Superfluid host contract for calling agreements. - /// @param ida Instant Distribution Agreement contract. - struct InitData { - ISuperfluid host; - IInstantDistributionAgreementV1 ida; - } - - /************************************************************************** - * View Functions - *************************************************************************/ - - /// @dev Gets an index by its ID and publisher. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @return exist True if the index exists. - /// @return indexValue Total value of the index. - /// @return totalUnitsApproved Units of the index approved by subscribers. - /// @return totalUnitsPending Units of teh index not yet approved by subscribers. - function getIndex( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId - ) - internal - view - returns ( - bool exist, - uint128 indexValue, - uint128 totalUnitsApproved, - uint128 totalUnitsPending - ) - { - return idaLibrary.ida.getIndex(token, publisher, indexId); - } - - /// @dev Calculates the distribution amount based on the amount of tokens desired to distribute. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param amount Amount of tokens desired to distribute. - /// @return actualAmount Amount to be distributed with correct rounding. - /// @return newIndexValue The index value after the distribution would be called. - function calculateDistribution( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId, - uint256 amount - ) - internal - view - returns ( - uint256 actualAmount, - uint128 newIndexValue - ) - { - return idaLibrary.ida.calculateDistribution(token, publisher, indexId, amount); - } - - /// @dev List all subscriptions of an address - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super token used in the indexes listed. - /// @param subscriber Subscriber address. - /// @return publishers Publishers of the indices. - /// @return indexIds IDs of the indices. - /// @return unitsList Units owned of the indices. - function listSubscriptions( - InitData storage idaLibrary, - ISuperfluidToken token, - address subscriber - ) - internal - view - returns ( - address[] memory publishers, - uint32[] memory indexIds, - uint128[] memory unitsList - ) - { - return idaLibrary.ida.listSubscriptions(token, subscriber); - } - - /// @dev Gets subscription by publisher, index id, and subscriber. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber to the index. - /// @return exist True if the subscription exists. - /// @return approved True if the subscription has been approved by the subscriber. - /// @return units Units held by the subscriber - /// @return pendingDistribution If not approved, the amount to be claimed on approval. - function getSubscription( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber - ) - internal - view - returns ( - bool exist, - bool approved, - uint128 units, - uint256 pendingDistribution - ) - { - return idaLibrary.ida.getSubscription(token, publisher, indexId, subscriber); - } - - /// @dev Gets subscription by the agreement ID. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param agreementId Agreement ID, unique to the subscriber and index ID. - /// @return publisher Publisher of the index. - /// @return indexId ID of the index. - /// @return approved True if the subscription has been approved by the subscriber. - /// @return units Units held by the subscriber - /// @return pendingDistribution If not approved, the amount to be claimed on approval. - function getSubscriptionByID( - InitData storage idaLibrary, - ISuperfluidToken token, - bytes32 agreementId - ) - internal - view - returns ( - address publisher, - uint32 indexId, - bool approved, - uint128 units, - uint256 pendingDistribution - ) - { - return idaLibrary.ida.getSubscriptionByID(token, agreementId); - } - - /************************************************************************** - * Index Operations - *************************************************************************/ - - /// @dev Creates a new index. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - function createIndex( - InitData storage idaLibrary, - ISuperfluidToken token, - uint32 indexId - ) internal { - createIndex(idaLibrary, token, indexId, new bytes(0)); - } - - /// @dev Creates a new index. This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param userData Arbitrary user data field. - function createIndex( - InitData storage idaLibrary, - ISuperfluidToken token, - uint32 indexId, - bytes memory userData - ) internal { - idaLibrary.host.callAgreement( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.createIndex, - ( - token, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - } - - /// @dev Creates a new index in a super app callback. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - function createIndexWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - uint32 indexId - ) internal returns (bytes memory newCtx) { - return createIndexWithCtx(idaLibrary, ctx, token, indexId, new bytes(0)); - } - - /// @dev Creates a new index in a super app callback. This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param userData Arbitrary user data field. - function createIndexWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - uint32 indexId, - bytes memory userData - ) internal returns (bytes memory newCtx) { - (newCtx, ) = idaLibrary.host.callAgreementWithContext( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.createIndex, - ( - token, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData, - ctx - ); - } - - /// @dev Updates an index value. This distributes an amount of tokens equal to - /// `indexValue - lastIndexValue`. See `distribute` for another way to distribute. This takes - /// arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param indexValue New TOTAL index value, this will equal the total amount distributed. - function updateIndexValue( - InitData storage idaLibrary, - ISuperfluidToken token, - uint32 indexId, - uint128 indexValue - ) internal { - updateIndexValue(idaLibrary, token, indexId, indexValue, new bytes(0)); - } - - /// @dev Updates an index value. This distributes an amount of tokens equal to - /// `indexValue - lastIndexValue`. See `distribute` for another way to distribute. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param indexValue New TOTAL index value, this will equal the total amount distributed. - /// @param userData Arbitrary user data field. - function updateIndexValue( - InitData storage idaLibrary, - ISuperfluidToken token, - uint32 indexId, - uint128 indexValue, - bytes memory userData - ) internal { - idaLibrary.host.callAgreement( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.updateIndex, - ( - token, - indexId, - indexValue, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - } - - /// @dev Updates an index value in a super app callback. This distributes an amount of tokens - /// equal to `indexValue - lastIndexValue`. See `distribute` for another way to distribute. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param indexValue New TOTAL index value, this will equal the total amount distributed. - function updateIndexValueWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - uint32 indexId, - uint128 indexValue - ) internal returns (bytes memory newCtx) { - return updateIndexValueWithCtx( - idaLibrary, - ctx, - token, - indexId, - indexValue, - new bytes(0) - ); - } - - /// @dev Updates an index value in a super app callback. This distributes an amount of tokens - /// equal to `indexValue - lastIndexValue`. See `distribute` for another way to distribute. - /// This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param indexValue New TOTAL index value, this will equal the total amount distributed. - function updateIndexValueWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - uint32 indexId, - uint128 indexValue, - bytes memory userData - ) internal returns (bytes memory newCtx) { - (newCtx, ) = idaLibrary.host.callAgreementWithContext( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.updateIndex, - ( - token, - indexId, - indexValue, - new bytes(0) // ctx placeholder - ) - ), - userData, - ctx - ); - } - - /** - * @dev Distributes tokens in a more developer friendly way than `updateIndex`. Instead of - * passing the new total index value, you pass the amount of tokens desired to be distributed. - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param amount - total number of tokens desired to be distributed - * NOTE in many cases, there can be some precision loss - This may cause a slight difference in the amount param specified and the actual amount distributed. - See below for math: - //indexDelta = amount the index will be updated by during internal call to _updateIndex(). - It is calculated like so: - indexDelta = amount / totalUnits - (see distribute() implementatation in ./agreements/InstantDistributionAgreement.sol) - * NOTE Solidity does not support floating point numbers - // So the indexDelta will be rounded down to the nearest integer. - This will create a 'remainder' amount of tokens that will not be distributed - (we'll call this the 'distribution modulo') - distributionModulo = amount - indexDelta * totalUnits - * NOTE due to rounding, there may be a small amount of tokens left in the publisher's account - This amount is equal to the 'distributionModulo' value - // - */ - function distribute( - InitData storage idaLibrary, - ISuperfluidToken token, - uint32 indexId, - uint256 amount - ) internal { - distribute(idaLibrary, token, indexId, amount, new bytes(0)); - } - - /// @dev Distributes tokens in a more developer friendly way than `updateIndex`. Instead of - /// passing the new total index value, this function will increase the index value by `amount`. - /// This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param amount Amount by which the index value should increase. - /// @param userData Arbitrary user data field. - function distribute( - InitData storage idaLibrary, - ISuperfluidToken token, - uint32 indexId, - uint256 amount, - bytes memory userData - ) internal { - idaLibrary.host.callAgreement( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.distribute, - ( - token, - indexId, - amount, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - } - - /// @dev Distributes tokens in a super app callback. Instead of passing the new total index - /// value, this function will increase the index value by `amount`. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param amount Amount by which the index value should increase. - function distributeWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - uint32 indexId, - uint256 amount - ) internal returns (bytes memory newCtx) { - return distributeWithCtx(idaLibrary, ctx, token, indexId, amount, new bytes(0)); - } - - /// @dev Distributes tokens in a super app callback. Instead of passing the new total index - /// value, this function will increase the index value by `amount`. This takes arbitrary user - /// data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param amount Amount by which the index value should increase. - /// @param userData Arbitrary user data field. - function distributeWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - uint32 indexId, - uint256 amount, - bytes memory userData - ) internal returns (bytes memory newCtx) { - (newCtx, ) = idaLibrary.host.callAgreementWithContext( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.distribute, - ( - token, - indexId, - amount, - new bytes(0) // ctx placeholder - ) - ), - userData, - ctx - ); - } - - /************************************************************************** - * Subscription Operations - *************************************************************************/ - - /// @dev Approves a subscription to an index. The subscriber's real time balance will not update - /// until the subscription is approved, but once approved, the balance will be updated with - /// prior distributions. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - function approveSubscription( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId - ) internal { - approveSubscription(idaLibrary, token, publisher, indexId, new bytes(0)); - } - - /// @dev Approves a subscription to an index. The subscriber's real time balance will not update - /// until the subscription is approved, but once approved, the balance will be updated with - /// prior distributions. - /// This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param userData Arbitrary user data field. - function approveSubscription( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) internal { - idaLibrary.host.callAgreement( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.approveSubscription, - ( - token, - publisher, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - } - - /// @dev Approves a subscription to an index in a super app callback. The subscriber's real time - /// balance will not update until the subscription is approved, but once approved, the balance - /// will be updated with prior distributions. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - function approveSubscriptionWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - address publisher, - uint32 indexId - ) internal returns (bytes memory newCtx) { - return approveSubscriptionWithCtx( - idaLibrary, - ctx, - token, - publisher, - indexId, - new bytes(0) - ); - } - - /// @dev Approves a subscription to an index in a super app callback. The subscriber's real time - /// balance will not update until the subscription is approved, but once approved, the balance - /// will be updated with prior distributions. This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param userData Arbitrary user data field. - function approveSubscriptionWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) internal returns (bytes memory newCtx) { - (newCtx, ) = idaLibrary.host.callAgreementWithContext( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.approveSubscription, - ( - token, - publisher, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData, - ctx - ); - } - - /// @dev Revokes a previously approved subscription. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - function revokeSubscription( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId - ) internal { - revokeSubscription(idaLibrary, token, publisher, indexId, new bytes(0)); - } - - /// @dev Revokes a previously approved subscription. This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param userData Arbitrary user data field. - function revokeSubscription( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) internal { - idaLibrary.host.callAgreement( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.revokeSubscription, - ( - token, - publisher, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - } - - /// @dev Revokes a previously approved subscription in a super app callback. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - function revokeSubscriptionWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - address publisher, - uint32 indexId - ) internal returns (bytes memory newCtx) { - return revokeSubscriptionWithCtx( - idaLibrary, - ctx, - token, - publisher, - indexId, - new bytes(0) - ); - } - - /// @dev Revokes a previously approved subscription in a super app callback. This takes - /// arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param userData Arbitrary user data field. - function revokeSubscriptionWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) internal returns (bytes memory newCtx) { - (newCtx, ) = idaLibrary.host.callAgreementWithContext( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.revokeSubscription, - ( - token, - publisher, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData, - ctx - ); - } - - /// @dev Updates the units of a subscription. This changes the number of shares the subscriber - /// holds. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address whose units are to be updated. - /// @param units New number of units the subscriber holds. - function updateSubscriptionUnits( - InitData storage idaLibrary, - ISuperfluidToken token, - uint32 indexId, - address subscriber, - uint128 units - ) internal { - updateSubscriptionUnits(idaLibrary, token, indexId, subscriber, units, new bytes(0)); - } - - /// @dev Updates the units of a subscription. This changes the number of shares the subscriber - /// holds. This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address whose units are to be updated. - /// @param units New number of units the subscriber holds. - /// @param userData Arbitrary user data field. - function updateSubscriptionUnits( - InitData storage idaLibrary, - ISuperfluidToken token, - uint32 indexId, - address subscriber, - uint128 units, - bytes memory userData - ) internal { - idaLibrary.host.callAgreement( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.updateSubscription, - ( - token, - indexId, - subscriber, - units, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - } - - /// @dev Updates the units of a subscription in a super app callback. This changes the number of - /// shares the subscriber holds. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address whose units are to be updated. - /// @param units New number of units the subscriber holds. - function updateSubscriptionUnitsWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - uint32 indexId, - address subscriber, - uint128 units - ) internal returns (bytes memory newCtx) { - return updateSubscriptionUnitsWithCtx( - idaLibrary, - ctx, - token, - indexId, - subscriber, - units, - new bytes(0) - ); - } - - /// @dev Updates the units of a subscription in a super app callback. This changes the number of - /// shares the subscriber holds. This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address whose units are to be updated. - /// @param units New number of units the subscriber holds. - /// @param userData Arbitrary user data field. - function updateSubscriptionUnitsWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - uint32 indexId, - address subscriber, - uint128 units, - bytes memory userData - ) internal returns (bytes memory newCtx) { - (newCtx, ) = idaLibrary.host.callAgreementWithContext( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.updateSubscription, - ( - token, - indexId, - subscriber, - units, - new bytes(0) // ctx placeholder - ) - ), - userData, - ctx - ); - } - - /// @dev Deletes a subscription, setting a subcriber's units to zero. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address whose units are to be deleted. - function deleteSubscription( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber - ) internal { - deleteSubscription(idaLibrary, token, publisher, indexId, subscriber, new bytes(0)); - } - - /// @dev Deletes a subscription, setting a subcriber's units to zero. This takes arbitrary user - /// data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address whose units are to be deleted. - /// @param userData Arbitrary user data field. - function deleteSubscription( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) internal { - idaLibrary.host.callAgreement( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.deleteSubscription, - ( - token, - publisher, - indexId, - subscriber, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - } - - /// @dev Deletes a subscription in a super app callback, setting a subcriber's units to zero. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address whose units are to be deleted. - function deleteSubscriptionWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber - ) internal returns (bytes memory newCtx) { - return deleteSubscriptionWithCtx( - idaLibrary, - ctx, - token, - publisher, - indexId, - subscriber, - new bytes(0) - ); - } - - /// @dev Deletes a subscription in a super app callback, setting a subcriber's units to zero. - /// This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param ctx Context byte string used by the Superfluid host. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address whose units are to be deleted. - /// @param userData Arbitrary user data field. - function deleteSubscriptionWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) internal returns (bytes memory newCtx) { - (newCtx, ) = idaLibrary.host.callAgreementWithContext( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.deleteSubscription, - ( - token, - publisher, - indexId, - subscriber, - new bytes(0) // ctx placeholder - ) - ), - userData, - ctx - ); - } - - /// @dev Claims pending distribution. Subscription should not be approved. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address that receives the claim. - function claim( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber - ) internal { - claim(idaLibrary, token, publisher, indexId, subscriber, new bytes(0)); - } - - /// @dev Claims pending distribution. Subscription should not be approved. This takes arbitrary - /// user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address that receives the claim. - /// @param userData Arbitrary user data field. - function claim( - InitData storage idaLibrary, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) internal { - idaLibrary.host.callAgreement( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.claim, - ( - token, - publisher, - indexId, - subscriber, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - } - - /// @dev Claims pending distribution in a super app callback. Subscription should not be - /// approved. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address that receives the claim. - function claimWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber - ) internal returns (bytes memory newCtx) { - return claimWithCtx( - idaLibrary, - ctx, - token, - publisher, - indexId, - subscriber, - new bytes(0) - ); - } - - /// @dev Claims pending distribution in a super app callback. Subscription should not be - /// approved. This takes arbitrary user data. - /// @param idaLibrary Storage pointer to host and ida interfaces. - /// @param token Super Token used with the index. - /// @param publisher Publisher of the index. - /// @param indexId ID of the index. - /// @param subscriber Subscriber address that receives the claim. - /// @param userData Arbitrary user data field. - function claimWithCtx( - InitData storage idaLibrary, - bytes memory ctx, - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) internal returns (bytes memory newCtx) { - (newCtx, ) = idaLibrary.host.callAgreementWithContext( - idaLibrary.ida, - abi.encodeCall( - idaLibrary.ida.claim, - ( - token, - publisher, - indexId, - subscriber, - new bytes(0) // ctx placeholder - ) - ), - userData, - ctx - ); - } -} diff --git a/packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol b/packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol index b389f658f6..d2ee068001 100644 --- a/packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol +++ b/packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol @@ -5,21 +5,17 @@ import { ISuperfluid, ISuperToken, IConstantFlowAgreementV1, - IInstantDistributionAgreementV1 -} from "../interfaces/superfluid/ISuperfluid.sol"; - -import { IGeneralDistributionAgreementV1, ISuperfluidPool, PoolConfig -} from "../interfaces/agreements/gdav1/IGeneralDistributionAgreementV1.sol"; +} from "../interfaces/superfluid/ISuperfluid.sol"; /** * @title Library for Token Centric Interface * @author Superfluid * @dev Set `using for ISuperToken` in including file, and call any of these functions on an instance * of ISuperToken. - * Note that it is important to "warm up" the cache and cache the host, cfa, ida before calling, + * Note that it is important to "warm up" the cache and cache the host, cfa, gda before calling, * this is only applicable to Foundry tests where the vm.expectRevert() will not work as expected. * You must use vm.startPrank(account) instead of vm.prank when executing functions if the cache * isn't "warmed up" yet. vm.prank impersonates the account only for the first call, which will be @@ -1037,111 +1033,6 @@ library SuperTokenV1Library { allowDelete = permissionsBitmask >> 2 & 1 == 1; } - - /** IDA VIEW FUNCTIONS ************************************* */ - - - /** - * @dev Gets an index by its ID and publisher. - * @param token Super token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @return exist True if the index exists. - * @return indexValue Total value of the index. - * @return totalUnitsApproved Units of the index approved by subscribers. - * @return totalUnitsPending Units of teh index not yet approved by subscribers. - */ - function getIndex(ISuperToken token, address publisher, uint32 indexId) - internal view - returns (bool exist, uint128 indexValue, uint128 totalUnitsApproved, uint128 totalUnitsPending) - { - (, IInstantDistributionAgreementV1 ida) = _getHostAndIDA(token); - return ida.getIndex(token, publisher, indexId); - } - - /** - * @dev Calculates the distribution amount based on the amount of tokens desired to distribute. - * @param token Super token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param amount Amount of tokens desired to distribute. - * @return actualAmount Amount to be distributed with correct rounding. - * @return newIndexValue The index value after the distribution would be called. - */ - function calculateDistribution(ISuperToken token, address publisher, uint32 indexId, uint256 amount) - internal view - returns (uint256 actualAmount, uint128 newIndexValue) - { - (, IInstantDistributionAgreementV1 ida) = _getHostAndIDA(token); - return ida.calculateDistribution(token, publisher, indexId, amount); - } - - /** - * @dev List all subscriptions of an address - * @param token Super token used in the indexes listed. - * @param subscriber Subscriber address. - * @return publishers Publishers of the indices. - * @return indexIds IDs of the indices. - * @return unitsList Units owned of the indices. - */ - function listSubscriptions( - ISuperToken token, - address subscriber - ) - internal view - returns ( - address[] memory publishers, - uint32[] memory indexIds, - uint128[] memory unitsList - ) - { - (, IInstantDistributionAgreementV1 ida) = _getHostAndIDA(token); - return ida.listSubscriptions(token, subscriber); - } - - /** - * @dev Gets subscription by publisher, index id, and subscriber. - * @param token Super token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param subscriber Subscriber to the index. - * @return exist True if the subscription exists. - * @return approved True if the subscription has been approved by the subscriber. - * @return units Units held by the subscriber - * @return pendingDistribution If not approved, the amount to be claimed on approval. - */ - function getSubscription(ISuperToken token, address publisher, uint32 indexId, address subscriber) - internal view - returns (bool exist, bool approved, uint128 units, uint256 pendingDistribution) - { - (, IInstantDistributionAgreementV1 ida) = _getHostAndIDA(token); - return ida.getSubscription(token, publisher, indexId, subscriber); - } - - /* - * @dev Gets subscription by the agreement ID. - * @param token Super Token used with the index. - * @param agreementId Agreement ID, unique to the subscriber and index ID. - * @return publisher Publisher of the index. - * @return indexId ID of the index. - * @return approved True if the subscription has been approved by the subscriber. - * @return units Units held by the subscriber - * @return pendingDistribution If not approved, the amount to be claimed on approval. - */ - function getSubscriptionByID(ISuperToken token, bytes32 agreementId) - internal view - returns ( - address publisher, - uint32 indexId, - bool approved, - uint128 units, - uint256 pendingDistribution - ) - { - (, IInstantDistributionAgreementV1 ida) = _getHostAndIDA(token); - return ida.getSubscriptionByID(token, agreementId); - } - /** GDA VIEW FUNCTIONS ************************************* */ function getFlowDistributionFlowRate(ISuperToken token, address from, ISuperfluidPool to) internal @@ -1178,661 +1069,6 @@ library SuperTokenV1Library { } - /** IDA BASE FUNCTIONS ************************************* */ - - - /** - * @dev Creates a new index. - * @param token Super Token used with the index. - * @param indexId ID of the index. - */ - function createIndex( - ISuperToken token, - uint32 indexId - ) internal returns (bool) { - return createIndex(token, indexId, new bytes(0)); - } - - /** - * @dev Creates a new index with userData. - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param userData Arbitrary user data field. - */ - function createIndex( - ISuperToken token, - uint32 indexId, - bytes memory userData - ) internal returns (bool) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - host.callAgreement( - ida, - abi.encodeCall( - ida.createIndex, - ( - token, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - return true; - } - - /** - * @dev Updates an index value. This distributes an amount of tokens equal to - * `indexValue - lastIndexValue`. See `distribute` for another way to distribute. - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param indexValue New TOTAL index value, this will equal the total amount distributed. - */ - function updateIndexValue( - ISuperToken token, - uint32 indexId, - uint128 indexValue - ) internal returns (bool) { - return updateIndexValue(token, indexId, indexValue, new bytes(0)); - } - - /** - * @dev Updates an index value with userData. This distributes an amount of tokens equal to - * `indexValue - lastIndexValue`. See `distribute` for another way to distribute. - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param indexValue New TOTAL index value, this will equal the total amount distributed. - * @param userData Arbitrary user data field. - */ - function updateIndexValue( - ISuperToken token, - uint32 indexId, - uint128 indexValue, - bytes memory userData - ) internal returns (bool) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - host.callAgreement( - ida, - abi.encodeCall( - ida.updateIndex, - ( - token, - indexId, - indexValue, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - return true; - } - - /** - * @dev Distributes tokens in a more developer friendly way than `updateIndex`. Instead of - * passing the new total index value, you pass the amount of tokens desired to be distributed. - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param amount - total number of tokens desired to be distributed - * NOTE in many cases, there can be some precision loss - This may cause a slight difference in the amount param specified and the actual amount distributed. - See below for math: - //indexDelta = amount the index will be updated by during an internal call to _updateIndex(). - It is calculated like so: - indexDelta = amount / totalUnits - (see the distribute() implementatation in ./agreements/InstantDistributionAgreement.sol) - * NOTE Solidity does not support floating point numbers - So the indexDelta will be rounded down to the nearest integer. - This will create a 'remainder' amount of tokens that will not be distributed - (we'll call this the 'distribution modulo') - distributionModulo = amount - indexDelta * totalUnits - * NOTE due to rounding, there may be a small amount of tokens left in the publisher's account - This amount is equal to the 'distributionModulo' value - // - */ - function distribute( - ISuperToken token, - uint32 indexId, - uint256 amount - ) internal returns (bool) { - return distribute(token, indexId, amount, new bytes(0)); - } - - /** - * @dev Distributes tokens in a more developer friendly way than `updateIndex` (w user data). Instead of - * passing the new total index value, this function will increase the index value by `amount`. - * This takes arbitrary user data. - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param amount Amount by which the index value should increase. - * @param userData Arbitrary user data field. - */ - function distribute( - ISuperToken token, - uint32 indexId, - uint256 amount, - bytes memory userData - ) internal returns (bool) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - host.callAgreement( - ida, - abi.encodeCall( - ida.distribute, - ( - token, - indexId, - amount, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - return true; - } - - /** - * @dev Approves a subscription to an index. The subscriber's real time balance will not update - * until the subscription is approved, but once approved, the balance will be updated with - * prior distributions. - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - */ - function approveSubscription( - ISuperToken token, - address publisher, - uint32 indexId - ) internal returns (bool) { - return approveSubscription(token, publisher, indexId, new bytes(0)); - } - - /** - * @dev Approves a subscription to an index with user data. The subscriber's real time balance will not update - * until the subscription is approved, but once approved, the balance will be updated with - * prior distributions. - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param userData Arbitrary user data field. - */ - function approveSubscription( - ISuperToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) internal returns (bool) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - host.callAgreement( - ida, - abi.encodeCall( - ida.approveSubscription, - ( - token, - publisher, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - return true; - } - - /** - * @dev Revokes a previously approved subscription. - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - */ - function revokeSubscription( - ISuperToken token, - address publisher, - uint32 indexId - ) internal returns (bool) { - return revokeSubscription(token, publisher, indexId, new bytes(0)); - } - - /** - * @dev Revokes a previously approved subscription. This takes arbitrary user data. - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param userData Arbitrary user data field. - */ - function revokeSubscription( - ISuperToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) internal returns (bool) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - host.callAgreement( - ida, - abi.encodeCall( - ida.revokeSubscription, - ( - token, - publisher, - indexId, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - return true; - } - - /** - * @dev Updates the units of a subscription. This changes the number of shares the subscriber holds - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address whose units are to be updated. - * @param units New number of units the subscriber holds. - */ - function updateSubscriptionUnits( - ISuperToken token, - uint32 indexId, - address subscriber, - uint128 units - ) internal returns (bool) { - return updateSubscriptionUnits(token, indexId, subscriber, units, new bytes(0)); - } - - /** - * @dev Updates the units of a subscription. This changes the number of shares the subscriber - * holds. This takes arbitrary user data. - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address whose units are to be updated. - * @param units New number of units the subscriber holds. - * @param userData Arbitrary user data field. - */ - function updateSubscriptionUnits( - ISuperToken token, - uint32 indexId, - address subscriber, - uint128 units, - bytes memory userData - ) internal returns (bool) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - host.callAgreement( - ida, - abi.encodeCall( - ida.updateSubscription, - ( - token, - indexId, - subscriber, - units, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - return true; - } - - /** - * @dev Deletes a subscription, setting a subcriber's units to zero - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address whose units are to be deleted. - */ - function deleteSubscription( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber - ) internal returns (bool) { - return deleteSubscription(token, publisher, indexId, subscriber, new bytes(0)); - } - - /** - * @dev Deletes a subscription, setting a subcriber's units to zero. This takes arbitrary userdata. - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address whose units are to be deleted. - * @param userData Arbitrary user data field. - */ - function deleteSubscription( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) internal returns (bool) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - host.callAgreement( - ida, - abi.encodeCall( - ida.deleteSubscription, - ( - token, - publisher, - indexId, - subscriber, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - return true; - } - - /** - * @dev Claims pending distribution. Subscription should not be approved - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address that receives the claim. - */ - function claim( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber - ) internal returns (bool) { - return claim(token, publisher, indexId, subscriber, new bytes(0)); - } - - /** - * @dev Claims pending distribution. Subscription should not be approved. This takes arbitrary user data. - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address that receives the claim. - * @param userData Arbitrary user data field. - */ - function claim( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) internal returns (bool) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - host.callAgreement( - ida, - abi.encodeCall( - ida.claim, - ( - token, - publisher, - indexId, - subscriber, - new bytes(0) // ctx placeholder - ) - ), - userData - ); - return true; - } - - /** IDA WITH CTX FUNCTIONS ************************************* */ - - /** - * @dev Creates a new index with ctx. - * Meant for usage in super app callbacks - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param ctx Context bytes (see ISuperfluid.sol for Context struct) - * @return newCtx The updated context after the execution of the agreement function - */ - function createIndexWithCtx( - ISuperToken token, - uint32 indexId, - bytes memory ctx - ) internal returns (bytes memory newCtx) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - (newCtx, ) = host.callAgreementWithContext( - ida, - abi.encodeCall( - ida.createIndex, - ( - token, - indexId, - new bytes(0) // ctx placeholder - ) - ), - "0x", - ctx - ); - } - - /** - * @dev Updates an index value with ctx. This distributes an amount of tokens equal to - * `indexValue - lastIndexValue`. See `distribute` for another way to distribute. - * Meant for usage in super app callbakcs - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param indexValue New TOTAL index value, this will equal the total amount distributed. - * @param ctx Context bytes (see ISuperfluid.sol for Context struct) - * @return newCtx The updated context after the execution of the agreement function - */ - function updateIndexValueWithCtx( - ISuperToken token, - uint32 indexId, - uint128 indexValue, - bytes memory ctx - ) internal returns (bytes memory newCtx) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - (newCtx, ) = host.callAgreementWithContext( - ida, - abi.encodeCall( - ida.updateIndex, - ( - token, - indexId, - indexValue, - new bytes(0) // ctx placeholder - ) - ), - "0x", - ctx - ); - } - - /** - * @dev Distributes tokens in a more developer friendly way than `updateIndex`.Instead of - * passing the new total index value, this function will increase the index value by `amount`. - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param amount Amount by which the index value should increase. - * @param ctx Context bytes (see ISuperfluid.sol for Context struct) - * @return newCtx The updated context after the execution of the agreement function - */ - function distributeWithCtx( - ISuperToken token, - uint32 indexId, - uint256 amount, - bytes memory ctx - ) internal returns (bytes memory newCtx) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - (newCtx, ) = host.callAgreementWithContext( - ida, - abi.encodeCall( - ida.distribute, - ( - token, - indexId, - amount, - new bytes(0) // ctx placeholder - ) - ), - "0x", - ctx - ); - } - - /** - * @dev Approves a subscription to an index. The subscriber's real time balance will not update - * until the subscription is approved, but once approved, the balance will be updated with - * prior distributions. - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param ctx Context bytes (see ISuperfluid.sol for Context struct) - * @return newCtx The updated context after the execution of the agreement function - */ - function approveSubscriptionWithCtx( - ISuperToken token, - address publisher, - uint32 indexId, - bytes memory ctx - ) internal returns (bytes memory newCtx) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - (newCtx, ) = host.callAgreementWithContext( - ida, - abi.encodeCall( - ida.approveSubscription, - ( - token, - publisher, - indexId, - new bytes(0) // ctx placeholder - ) - ), - "0x", - ctx - ); - } - - /** - * @dev Revokes a previously approved subscription. Meant for usage in super apps - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param ctx Context bytes (see ISuperfluid.sol for Context struct) - * @return newCtx The updated context after the execution of the agreement function - */ - function revokeSubscriptionWithCtx( - ISuperToken token, - address publisher, - uint32 indexId, - bytes memory ctx - ) internal returns (bytes memory newCtx) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - (newCtx, ) = host.callAgreementWithContext( - ida, - abi.encodeCall( - ida.revokeSubscription, - ( - token, - publisher, - indexId, - new bytes(0) // ctx placeholder - ) - ), - "0x", - ctx - ); - } - - /** - * @dev Updates the units of a subscription. This changes the number of shares the subscriber - * holds. Meant for usage in super apps - * @param token Super Token used with the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address whose units are to be updated. - * @param units New number of units the subscriber holds. - * @param ctx Context bytes (see ISuperfluid.sol for Context struct) - * @return newCtx The updated context after the execution of the agreement function - */ - function updateSubscriptionUnitsWithCtx( - ISuperToken token, - uint32 indexId, - address subscriber, - uint128 units, - bytes memory ctx - ) internal returns (bytes memory newCtx) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - (newCtx, ) = host.callAgreementWithContext( - ida, - abi.encodeCall( - ida.updateSubscription, - ( - token, - indexId, - subscriber, - units, - new bytes(0) // ctx placeholder - ) - ), - "0x", - ctx - ); - } - - /** - * @dev Deletes a subscription, setting a subcriber's units to zero. - * Meant for usage in super apps - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address whose units are to be deleted. - * @param ctx Context bytes (see ISuperfluid.sol for Context struct) - * @return newCtx The updated context after the execution of the agreement function - */ - function deleteSubscriptionWithCtx( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory ctx - ) internal returns (bytes memory newCtx) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - (newCtx, ) = host.callAgreementWithContext( - ida, - abi.encodeCall( - ida.deleteSubscription, - ( - token, - publisher, - indexId, - subscriber, - new bytes(0) // ctx placeholder - ) - ), - "0x", - ctx - ); - } - - /** - * @dev Claims pending distribution. Subscription should not be approved. - * Meant for usage in super app callbacks - * @param token Super Token used with the index. - * @param publisher Publisher of the index. - * @param indexId ID of the index. - * @param subscriber Subscriber address that receives the claim. - * @param ctx Context bytes (see ISuperfluid.sol for Context struct) - * @return newCtx The updated context after the execution of the agreement function - */ - function claimWithCtx( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory ctx - ) internal returns (bytes memory newCtx) { - (ISuperfluid host, IInstantDistributionAgreementV1 ida) = _getAndCacheHostAndIDA(token); - (newCtx, ) = host.callAgreementWithContext( - ida, - abi.encodeCall( - ida.claim, - ( - token, - publisher, - indexId, - subscriber, - new bytes(0) // ctx placeholder - ) - ), - "0x", - ctx - ); - } - /** GDA BASE FUNCTIONS ************************************* */ @@ -2234,8 +1470,6 @@ library SuperTokenV1Library { bytes32 private constant _HOST_SLOT = 0x65599bf746e17a00ea62e3610586992d88101b78eec3cf380706621fb97ea837; // keccak256("org.superfluid-finance.apps.SuperTokenLibrary.v1.cfa") bytes32 private constant _CFA_SLOT = 0xb969d79d88acd02d04ed7ee7d43b949e7daf093d363abcfbbc43dfdfd1ce969a; - // keccak256("org.superfluid-finance.apps.SuperTokenLibrary.v1.ida"); - bytes32 private constant _IDA_SLOT = 0xa832ee1924ea960211af2df07d65d166232018f613ac6708043cd8f8773eddeb; // keccak256("org.superfluid-finance.apps.SuperTokenLibrary.v1.gda"); bytes32 private constant _GDA_SLOT = 0xc36f6c05164a669ecb6da53e218d77ae44d51cfc99f91e5a125a18de0949bee4; @@ -2270,36 +1504,6 @@ library SuperTokenV1Library { assert(address(cfa) != address(0)); } - // gets the host and ida addrs for the token and caches it in storage for gas efficiency - // to be used in state changing methods - function _getAndCacheHostAndIDA(ISuperToken token) - private - returns (ISuperfluid host, IInstantDistributionAgreementV1 ida) - { - // check if already in contract storage... - assembly { - // solium-disable-line - host := sload(_HOST_SLOT) - ida := sload(_IDA_SLOT) - } - if (address(ida) == address(0)) { - // framework contract addrs not yet cached, retrieving now... - if (address(host) == address(0)) { - host = ISuperfluid(token.getHost()); - } - ida = IInstantDistributionAgreementV1(address(ISuperfluid(host).getAgreementClass( - keccak256("org.superfluid-finance.agreements.InstantDistributionAgreement.v1")))); - // now that we got them and are in a transaction context, persist in storage - assembly { - // solium-disable-line - sstore(_HOST_SLOT, host) - sstore(_IDA_SLOT, ida) - } - } - assert(address(host) != address(0)); - assert(address(ida) != address(0)); - } - // gets the host and gda addrs for the token and caches it in storage for gas efficiency // to be used in state changing methods function _getAndCacheHostAndGDA(ISuperToken token) @@ -2356,31 +1560,6 @@ library SuperTokenV1Library { assert(address(cfa) != address(0)); } - // gets the host and ida addrs for the token - // to be used in non-state changing methods (view functions) - function _getHostAndIDA(ISuperToken token) - private - view - returns (ISuperfluid host, IInstantDistributionAgreementV1 ida) - { - // check if already in contract storage... - assembly { - // solium-disable-line - host := sload(_HOST_SLOT) - ida := sload(_IDA_SLOT) - } - if (address(ida) == address(0)) { - // framework contract addrs not yet cached in storage, retrieving now... - if (address(host) == address(0)) { - host = ISuperfluid(token.getHost()); - } - ida = IInstantDistributionAgreementV1(address(ISuperfluid(host).getAgreementClass( - keccak256("org.superfluid-finance.agreements.InstantDistributionAgreement.v1")))); - } - assert(address(host) != address(0)); - assert(address(ida) != address(0)); - } - // gets the host and gda addrs for the token // to be used in non-state changing methods (view functions) function _getHostAndGDA(ISuperToken token) diff --git a/packages/ethereum-contracts/contracts/interfaces/agreements/IInstantDistributionAgreementV1.sol b/packages/ethereum-contracts/contracts/interfaces/agreements/IInstantDistributionAgreementV1.sol index 775859c9f8..e9beba7d0a 100644 --- a/packages/ethereum-contracts/contracts/interfaces/agreements/IInstantDistributionAgreementV1.sol +++ b/packages/ethereum-contracts/contracts/interfaces/agreements/IInstantDistributionAgreementV1.sol @@ -5,10 +5,11 @@ import { ISuperAgreement } from "../superfluid/ISuperAgreement.sol"; import { ISuperfluidToken } from "../superfluid/ISuperfluidToken.sol"; /** - * @title Instant Distribution Agreement interface + * @title [DEPRECATED] Instant Distribution Agreement interface * @author Superfluid + * @custom:deprecated Use IGeneralDistributionAgreementV1 instead * - * @notice + * @notice * - A publisher can create as many as indices as possibly identifiable with `indexId`. * - `indexId` is deliberately limited to 32 bits, to avoid the chance for sha-3 collision. * Despite knowing sha-3 collision is only theoretical. @@ -62,7 +63,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { * @param indexId Id of the index * @param ctx Context bytes (see ISuperfluid.sol for Context struct) * - * @custom:callbacks + * @custom:callbacks * None */ function createIndex( @@ -135,7 +136,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { * @param indexValue Value of the index * @param ctx Context bytes (see ISuperfluid.sol for Context struct) * - * @custom:callbacks + * @custom:callbacks * None */ function updateIndex( @@ -174,14 +175,14 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { * @param amount The amount of tokens desired to be distributed * @param ctx Context bytes (see ISuperfluid.sol for Context struct) * - * @custom:note + * @custom:note * - This is a convenient version of updateIndex. It adds to the index * a delta that equals to `amount / totalUnits` * - The actual amount distributed could be obtained via * `calculateDistribution`. This is due to precision error with index * value and units data range * - * @custom:callbacks + * @custom:callbacks * None */ function distribute( @@ -205,7 +206,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { * @param indexId Id of the index * @param ctx Context bytes (see ISuperfluid.sol for Context struct) * - * @custom:callbacks + * @custom:callbacks * - if subscription exist * - AgreementCreated callback to the publisher: * - agreementId is for the subscription @@ -259,7 +260,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { * @param indexId Id of the index * @param ctx Context bytes (see ISuperfluid.sol for Context struct) * - * @custom:callbacks + * @custom:callbacks * - AgreementUpdated callback to the publisher: * - agreementId is for the subscription */ @@ -285,7 +286,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { uint32 indexed indexId, address subscriber, bytes userData); - + /** * @dev Subscription approved event * @param token Super token address @@ -309,7 +310,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { * @param units Number of units of the subscription * @param ctx Context bytes (see ISuperfluid.sol for Context struct) * - * @custom:callbacks + * @custom:callbacks * - if subscription exist * - AgreementCreated callback to the subscriber: * - agreementId is for the subscription @@ -343,7 +344,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { address subscriber, uint128 units, bytes userData); - + /** * @dev Subscription units updated event * @param token Super token address @@ -439,7 +440,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { * @param subscriber The subscriber's address * @param ctx Context bytes (see ISuperfluid.sol for Context struct) * - * @custom:callbacks + * @custom:callbacks * - if the subscriber called it * - AgreementTerminated callback to the publsiher: * - agreementId is for the subscription @@ -467,7 +468,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { * * @custom:note The subscription should not be approved yet * - * @custom:callbacks + * @custom:callbacks * - AgreementUpdated callback to the publisher: * - agreementId is for the subscription */ @@ -480,7 +481,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { external virtual returns(bytes memory newCtx); - + /** * @dev Index distribution claimed event * @param token Super token address @@ -495,7 +496,7 @@ abstract contract IInstantDistributionAgreementV1 is ISuperAgreement { uint32 indexed indexId, address subscriber, uint256 amount); - + /** * @dev Subscription distribution claimed event * @param token Super token address diff --git a/packages/ethereum-contracts/contracts/mocks/IDAv1LibraryMock.t.sol b/packages/ethereum-contracts/contracts/mocks/IDAv1LibraryMock.t.sol deleted file mode 100644 index 938d2fb327..0000000000 --- a/packages/ethereum-contracts/contracts/mocks/IDAv1LibraryMock.t.sol +++ /dev/null @@ -1,400 +0,0 @@ -// SPDX-License-Identifier: AGPLv3 -pragma solidity ^0.8.23; -pragma experimental ABIEncoderV2; - -import {ISuperfluid, ISuperfluidToken, ISuperToken} from "../interfaces/superfluid/ISuperfluid.sol"; - -import {SuperAppBase, SuperAppDefinitions} from "../apps/SuperAppBase.sol"; - -import { - IInstantDistributionAgreementV1 -} from "../interfaces/agreements/IInstantDistributionAgreementV1.sol"; - -import {IDAv1Library} from "../apps/IDAv1Library.sol"; - -contract IDAv1LibraryMock { - using IDAv1Library for IDAv1Library.InitData; - - IDAv1Library.InitData internal _idaLib; - - bytes32 internal constant _IDAV1_HASH = keccak256( - "org.superfluid-finance.agreements.InstantDistributionAgreement.v1" - ); - - constructor(ISuperfluid host) { - _idaLib = IDAv1Library.InitData( - host, - IInstantDistributionAgreementV1( - address(host.getAgreementClass(_IDAV1_HASH)) - ) - ); - } - - /************************************************************************** - * View Functions - *************************************************************************/ - - function getIndexTest(ISuperfluidToken token, address publisher, uint32 indexId) - external - view - returns ( - bool exist, - uint128 indexValue, - uint128 totalUnitsApproved, - uint128 totalUnitsPending - ) - { - return _idaLib.getIndex(token, publisher, indexId); - } - - function calculateDistributionTest( - ISuperfluidToken token, - address publisher, - uint32 indexId, - uint256 amount - ) - external - view - returns ( - uint256 actualAmount, - uint128 newIndexValue - ) - { - return _idaLib.calculateDistribution(token, publisher, indexId, amount); - } - - function listSubscriptionsTest(ISuperfluidToken token, address subscriber) - external - view - returns ( - address[] memory publishers, - uint32[] memory indexIds, - uint128[] memory unitsList - ) - { - return _idaLib.listSubscriptions(token, subscriber); - } - - function getSubscriptionTest( - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber - ) - external - view - returns ( - bool exist, - bool approved, - uint128 units, - uint256 pendingDistribution - ) - { - return _idaLib.getSubscription(token, publisher, indexId, subscriber); - } - - /// @dev agreementId == keccak256(abi.encodePacked("subscription", subscriber, indexId)); - function getSubscriptionByIDTest(ISuperfluidToken token, bytes32 agreementId) - external - view - returns ( - address publisher, - uint32 indexId, - bool approved, - uint128 units, - uint256 pendingDistribution - ) - { - return _idaLib.getSubscriptionByID(token, agreementId); - } - - /************************************************************************** - * Index Operations - *************************************************************************/ - - function createIndexTest(ISuperfluidToken token, uint32 indexId) external { - _idaLib.createIndex(token, indexId); - } - - function createIndexWithUserDataTest( - ISuperfluidToken token, - uint32 indexId, - bytes memory userData - ) external { - _idaLib.createIndex(token, indexId, userData); - } - - function updateIndexValueTest( - ISuperfluidToken token, - uint32 indexId, - uint128 indexValue - ) external { - _idaLib.updateIndexValue(token, indexId, indexValue); - } - - function updateIndexValueWithUserDataTest( - ISuperfluidToken token, - uint32 indexId, - uint128 indexValue, - bytes memory userData - ) external { - _idaLib.updateIndexValue(token, indexId, indexValue, userData); - } - - function distributeTest(ISuperfluidToken token, uint32 indexId, uint256 amount) external { - _idaLib.distribute(token, indexId, amount); - } - - function distributeWithUserDataTest( - ISuperfluidToken token, - uint32 indexId, - uint256 amount, - bytes memory userData - ) external { - _idaLib.distribute(token, indexId, amount, userData); - } - - /************************************************************************** - * Subscription Operations - *************************************************************************/ - - function approveSubscriptionTest( - ISuperfluidToken token, - address publisher, - uint32 indexId - ) external { - _idaLib.approveSubscription(token, publisher, indexId); - } - - function approveSubscriptionWithUserDataTest( - ISuperfluidToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) external { - _idaLib.approveSubscription(token, publisher, indexId, userData); - } - - function revokeSubscriptionTest( - ISuperfluidToken token, - address publisher, - uint32 indexId - ) external { - _idaLib.revokeSubscription(token, publisher, indexId); - } - - function revokeSubscriptionWithUserDataTest( - ISuperfluidToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) external { - _idaLib.revokeSubscription(token, publisher, indexId, userData); - } - - function updateSubscriptionUnitsTest( - ISuperfluidToken token, - uint32 indexId, - address subscriber, - uint128 units - ) external { - _idaLib.updateSubscriptionUnits(token, indexId, subscriber, units); - } - - function updateSubscriptionUnitsWithUserDataTest( - ISuperfluidToken token, - uint32 indexId, - address subscriber, - uint128 units, - bytes memory userData - ) external { - _idaLib.updateSubscriptionUnits(token, indexId, subscriber, units, userData); - } - - function deleteSubscriptionTest( - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber - ) external { - _idaLib.deleteSubscription(token, publisher, indexId, subscriber); - } - - function deleteSubscriptionWithUserDataTest( - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) external { - _idaLib.deleteSubscription(token, publisher, indexId, subscriber, userData); - } - - function claimTest( - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber - ) external { - _idaLib.claim(token, publisher, indexId, subscriber); - } - - function claimWithUserDataTest( - ISuperfluidToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) external { - _idaLib.claim(token, publisher, indexId, subscriber, userData); - } -} - -// IDA LIBRARY SUPER APP CALLBACK MOCK -contract IDAv1LibrarySuperAppMock is IDAv1LibraryMock, SuperAppBase { - using IDAv1Library for IDAv1Library.InitData; - - bytes internal constant _MOCK_USER_DATA = abi.encode("oh hello"); - - constructor(ISuperfluid host) IDAv1LibraryMock(host) { - uint256 configWord = SuperAppDefinitions.APP_LEVEL_FINAL | - SuperAppDefinitions.BEFORE_AGREEMENT_CREATED_NOOP | - // SuperAppDefinitions.AFTER_AGREEMENT_CREATED_NOOP | - SuperAppDefinitions.BEFORE_AGREEMENT_UPDATED_NOOP | - // SuperAppDefinitions.AFTER_AGREEMENT_UPDATED_NOOP | - SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP | - SuperAppDefinitions.AFTER_AGREEMENT_TERMINATED_NOOP; - - host.registerAppWithKey(configWord, ""); - } - - function afterAgreementCreated( - ISuperToken token, - address, - bytes32, - bytes calldata, - bytes calldata, - bytes calldata ctx - ) external override returns (bytes memory newCtx) { - return _callbackTest(token, ctx); - } - - function afterAgreementUpdated( - ISuperToken token, - address, - bytes32, - bytes calldata, - bytes calldata, - bytes calldata ctx - ) external override returns (bytes memory newCtx) { - return _callbackTest(token, ctx); - } - - enum FunctionIndex { - CREATE_INDEX, - CREATE_INDEX_USER_DATA, - UPDATE_INDEX, - UPDATE_INDEX_USER_DATA, - DISTRIBUTE, - DISTRIBUTE_USER_DATA, - APROVE_SUBSCRIPTION, - APROVE_SUBSCRIPTION_USER_DATA, - REVOKE_SUBSCRIPTION, - REVOKE_SUBSCRIPTION_USER_DATA, - UPDATE_SUBSCRIPTION, - UPDATE_SUBSCRIPTION_USER_DATA, - DELETE_SUBSCRIPTION, - DELETE_SUBSCRIPTION_USER_DATA, - CLAIM, - CLAIM_USER_DATA - } - - /// @dev extracts some user data to test out all callback library functions - /// @param token super token - /// @param ctx Context string - /// @return New Context - function _callbackTest( - ISuperToken token, - bytes memory ctx - ) internal returns (bytes memory) { - - // extract userData, then decode everything else - bytes memory userData = _idaLib.host.decodeCtx(ctx).userData; - ( - uint8 functionIndex, - uint32 indexId, - address publisher, - address subscriber, - uint128 units - ) = abi.decode(userData, (uint8, uint32, address, address, uint128)); - - if (functionIndex == uint8(FunctionIndex.CREATE_INDEX)) { - return _idaLib.createIndexWithCtx(ctx, token, indexId); - } else if (functionIndex == uint8(FunctionIndex.CREATE_INDEX_USER_DATA)) { - return _idaLib.createIndexWithCtx(ctx, token, indexId, _MOCK_USER_DATA); - } else if (functionIndex == uint8(FunctionIndex.UPDATE_INDEX)) { - return _idaLib.updateIndexValueWithCtx(ctx, token, indexId, units); - } else if (functionIndex == uint8(FunctionIndex.UPDATE_INDEX_USER_DATA)) { - return _idaLib.updateIndexValueWithCtx(ctx, token, indexId, units, _MOCK_USER_DATA); - } else if (functionIndex == uint8(FunctionIndex.DISTRIBUTE)) { - return _idaLib.distributeWithCtx(ctx, token, indexId, units); - } else if (functionIndex == uint8(FunctionIndex.DISTRIBUTE_USER_DATA)) { - return _idaLib.distributeWithCtx(ctx, token, indexId, units, _MOCK_USER_DATA); - } else if (functionIndex == uint8(FunctionIndex.APROVE_SUBSCRIPTION)) { - return _idaLib.approveSubscriptionWithCtx(ctx, token, publisher, indexId); - } else if (functionIndex == uint8(FunctionIndex.APROVE_SUBSCRIPTION_USER_DATA)) { - return _idaLib.approveSubscriptionWithCtx( - ctx, - token, - publisher, - indexId, - _MOCK_USER_DATA - ); - } else if (functionIndex == uint8(FunctionIndex.REVOKE_SUBSCRIPTION)) { - return _idaLib.revokeSubscriptionWithCtx(ctx, token, publisher, indexId); - } else if (functionIndex == uint8(FunctionIndex.REVOKE_SUBSCRIPTION_USER_DATA)) { - return _idaLib.revokeSubscriptionWithCtx( - ctx, - token, - publisher, - indexId, - _MOCK_USER_DATA - ); - } else if (functionIndex == uint8(FunctionIndex.UPDATE_SUBSCRIPTION)) { - return _idaLib.updateSubscriptionUnitsWithCtx(ctx, token, indexId, subscriber, units); - } else if (functionIndex == uint8(FunctionIndex.UPDATE_SUBSCRIPTION_USER_DATA)) { - return _idaLib.updateSubscriptionUnitsWithCtx( - ctx, - token, - indexId, - subscriber, - units, - _MOCK_USER_DATA - ); - } else if (functionIndex == uint8(FunctionIndex.DELETE_SUBSCRIPTION)) { - return _idaLib.deleteSubscriptionWithCtx(ctx, token, publisher, indexId, subscriber); - } else if (functionIndex == uint8(FunctionIndex.DELETE_SUBSCRIPTION_USER_DATA)) { - return _idaLib.deleteSubscriptionWithCtx( - ctx, - token, - publisher, - indexId, - subscriber, - _MOCK_USER_DATA - ); - } else if (functionIndex == uint8(FunctionIndex.CLAIM)) { - return _idaLib.claimWithCtx(ctx, token, publisher, indexId, subscriber); - } else if (functionIndex == uint8(FunctionIndex.CLAIM_USER_DATA)) { - return _idaLib.claimWithCtx( - ctx, - token, - publisher, - indexId, - subscriber, - _MOCK_USER_DATA - ); - } else { - revert("invalid function index"); - } - } -} diff --git a/packages/ethereum-contracts/contracts/mocks/SuperTokenLibraryV1Mock.t.sol b/packages/ethereum-contracts/contracts/mocks/SuperTokenLibraryV1Mock.t.sol index 663034e984..b56bfd3838 100644 --- a/packages/ethereum-contracts/contracts/mocks/SuperTokenLibraryV1Mock.t.sol +++ b/packages/ethereum-contracts/contracts/mocks/SuperTokenLibraryV1Mock.t.sol @@ -274,225 +274,6 @@ contract SuperTokenLibraryCFAMock { } } -contract SuperTokenLibraryIDAMock { - - using SuperTokenV1Library for ISuperToken; - - /************************************************************************** - * View Functions - *************************************************************************/ - - function getIndexTest(ISuperToken token, address publisher, uint32 indexId) - external view - returns ( - bool exist, - uint128 indexValue, - uint128 totalUnitsApproved, - uint128 totalUnitsPending - ) - { - return token.getIndex(publisher, indexId); - } - - function calculateDistributionTest( - ISuperToken token, - address publisher, - uint32 indexId, - uint256 amount - ) - external view - returns ( - uint256 actualAmount, - uint128 newIndexValue - ) - { - return token.calculateDistribution(publisher, indexId, amount); - } - - function listSubscriptionsTest(ISuperToken token, address subscriber) - external view - returns ( - address[] memory publishers, - uint32[] memory indexIds, - uint128[] memory unitsList - ) - { - return token.listSubscriptions(subscriber); - } - - function getSubscriptionTest( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber - ) - external view - returns ( - bool exist, - bool approved, - uint128 units, - uint256 pendingDistribution - ) - { - return token.getSubscription(publisher, indexId, subscriber); - } - - /// @dev agreementId == keccak256(abi.encodePacked("subscription", subscriber, indexId)); - function getSubscriptionByIDTest(ISuperToken token, bytes32 agreementId) - external view - returns ( - address publisher, - uint32 indexId, - bool approved, - uint128 units, - uint256 pendingDistribution - ) - { - return token.getSubscriptionByID(agreementId); - } - - /************************************************************************** - * Index Operations - *************************************************************************/ - - function createIndexTest(ISuperToken token, uint32 indexId) external { - token.createIndex(indexId); - } - - function createIndexWithUserDataTest( - ISuperToken token, - uint32 indexId, - bytes memory userData - ) external { - token.createIndex(indexId, userData); - } - - function updateIndexValueTest( - ISuperToken token, - uint32 indexId, - uint128 indexValue - ) external { - token.updateIndexValue(indexId, indexValue); - } - - function updateIndexValueWithUserDataTest( - ISuperToken token, - uint32 indexId, - uint128 indexValue, - bytes memory userData - ) external { - token.updateIndexValue(indexId, indexValue, userData); - } - - function distributeTest(ISuperToken token, uint32 indexId, uint256 amount) external { - token.distribute(indexId, amount); - } - - function distributeWithUserDataTest( - ISuperToken token, - uint32 indexId, - uint256 amount, - bytes memory userData - ) external { - token.distribute(indexId, amount, userData); - } - - /************************************************************************** - * Subscription Operations - *************************************************************************/ - - function approveSubscriptionTest( - ISuperToken token, - address publisher, - uint32 indexId - ) external { - token.approveSubscription(publisher, indexId); - } - - function approveSubscriptionWithUserDataTest( - ISuperToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) external { - token.approveSubscription(publisher, indexId, userData); - } - - function revokeSubscriptionTest( - ISuperToken token, - address publisher, - uint32 indexId - ) external { - token.revokeSubscription(publisher, indexId); - } - - function revokeSubscriptionWithUserDataTest( - ISuperToken token, - address publisher, - uint32 indexId, - bytes memory userData - ) external { - token.revokeSubscription(publisher, indexId, userData); - } - - function updateSubscriptionUnitsTest( - ISuperToken token, - uint32 indexId, - address subscriber, - uint128 units - ) external { - token.updateSubscriptionUnits(indexId, subscriber, units); - } - - function updateSubscriptionUnitsWithUserDataTest( - ISuperToken token, - uint32 indexId, - address subscriber, - uint128 units, - bytes memory userData - ) external { - token.updateSubscriptionUnits(indexId, subscriber, units, userData); - } - - function deleteSubscriptionTest( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber - ) external { - token.deleteSubscription(publisher, indexId, subscriber); - } - - function deleteSubscriptionWithUserDataTest( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) external { - token.deleteSubscription(publisher, indexId, subscriber, userData); - } - - function claimTest( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber - ) external { - token.claim(publisher, indexId, subscriber); - } - - function claimWithUserDataTest( - ISuperToken token, - address publisher, - uint32 indexId, - address subscriber, - bytes memory userData - ) external { - token.claim(publisher, indexId, subscriber, userData); - } -} - contract SuperTokenLibraryGDAMock { using SuperTokenV1Library for ISuperToken; //// View Functions //// @@ -658,145 +439,6 @@ contract SuperTokenLibraryCFASuperAppMock is SuperAppBase { } } -// IDA LIBRARY SUPER APP CALLBACK MOCK -contract SuperTokenLibraryIDASuperAppMock is SuperTokenLibraryIDAMock, SuperAppBase { - - using SuperTokenV1Library for ISuperToken; - - ISuperfluid internal immutable host; - - constructor(ISuperfluid _host) SuperTokenLibraryIDAMock() { - host = _host; - uint256 configWord = SuperAppDefinitions.APP_LEVEL_FINAL | - SuperAppDefinitions.BEFORE_AGREEMENT_CREATED_NOOP | - SuperAppDefinitions.BEFORE_AGREEMENT_UPDATED_NOOP | - SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP | - SuperAppDefinitions.AFTER_AGREEMENT_TERMINATED_NOOP; - - host.registerAppWithKey(configWord, ""); - } - - function afterAgreementCreated( - ISuperToken token, - address, - bytes32, - bytes calldata, - bytes calldata, - bytes calldata ctx - ) external override returns (bytes memory newCtx) { - return _callbackTest(token, ctx); - } - - function afterAgreementUpdated( - ISuperToken token, - address, - bytes32, - bytes calldata, - bytes calldata, - bytes calldata ctx - ) external override returns (bytes memory newCtx) { - return _callbackTest(token, ctx); - } - - enum FunctionIndex { - CREATE_INDEX, - CREATE_INDEX_USER_DATA, - UPDATE_INDEX, - UPDATE_INDEX_USER_DATA, - DISTRIBUTE, - DISTRIBUTE_USER_DATA, - APROVE_SUBSCRIPTION, - APROVE_SUBSCRIPTION_USER_DATA, - REVOKE_SUBSCRIPTION, - REVOKE_SUBSCRIPTION_USER_DATA, - UPDATE_SUBSCRIPTION, - UPDATE_SUBSCRIPTION_USER_DATA, - DELETE_SUBSCRIPTION, - DELETE_SUBSCRIPTION_USER_DATA, - CLAIM, - CLAIM_USER_DATA - } - - /// @dev extracts some user data to test out all callback library functions - /// @param token super token - /// @param ctx Context string - /// @return New Context - function _callbackTest( - ISuperToken token, - bytes memory ctx - ) internal returns (bytes memory) { - - // extract userData, then decode everything else - bytes memory userData = host.decodeCtx(ctx).userData; - ( - uint8 functionIndex, - uint32 indexId, - address publisher, - address subscriber, - uint128 units - ) = abi.decode(userData, (uint8, uint32, address, address, uint128)); - - if (functionIndex == uint8(FunctionIndex.CREATE_INDEX)) { - return token.createIndexWithCtx(indexId, ctx); - } else if (functionIndex == uint8(FunctionIndex.CREATE_INDEX_USER_DATA)) { - return token.createIndexWithCtx(indexId, ctx); - } else if (functionIndex == uint8(FunctionIndex.UPDATE_INDEX)) { - return token.updateIndexValueWithCtx(indexId, units, ctx); - } else if (functionIndex == uint8(FunctionIndex.UPDATE_INDEX_USER_DATA)) { - return token.updateIndexValueWithCtx(indexId, units, ctx); - } else if (functionIndex == uint8(FunctionIndex.DISTRIBUTE)) { - return token.distributeWithCtx(indexId, units, ctx); - } else if (functionIndex == uint8(FunctionIndex.DISTRIBUTE_USER_DATA)) { - return token.distributeWithCtx(indexId, units, ctx); - } else if (functionIndex == uint8(FunctionIndex.APROVE_SUBSCRIPTION)) { - return token.approveSubscriptionWithCtx(publisher, indexId, ctx); - } else if (functionIndex == uint8(FunctionIndex.APROVE_SUBSCRIPTION_USER_DATA)) { - return token.approveSubscriptionWithCtx( - publisher, - indexId, - ctx - ); - } else if (functionIndex == uint8(FunctionIndex.REVOKE_SUBSCRIPTION)) { - return token.revokeSubscriptionWithCtx(publisher, indexId, ctx); - } else if (functionIndex == uint8(FunctionIndex.REVOKE_SUBSCRIPTION_USER_DATA)) { - return token.revokeSubscriptionWithCtx( - publisher, - indexId, - ctx - ); - } else if (functionIndex == uint8(FunctionIndex.UPDATE_SUBSCRIPTION)) { - return token.updateSubscriptionUnitsWithCtx(indexId, subscriber, units, ctx); - } else if (functionIndex == uint8(FunctionIndex.UPDATE_SUBSCRIPTION_USER_DATA)) { - return token.updateSubscriptionUnitsWithCtx( - indexId, - subscriber, - units, - ctx - ); - } else if (functionIndex == uint8(FunctionIndex.DELETE_SUBSCRIPTION)) { - return token.deleteSubscriptionWithCtx(publisher, indexId, subscriber, ctx); - } else if (functionIndex == uint8(FunctionIndex.DELETE_SUBSCRIPTION_USER_DATA)) { - return token.deleteSubscriptionWithCtx( - publisher, - indexId, - subscriber, - ctx - ); - } else if (functionIndex == uint8(FunctionIndex.CLAIM)) { - return token.claimWithCtx(publisher, indexId, subscriber, ctx); - } else if (functionIndex == uint8(FunctionIndex.CLAIM_USER_DATA)) { - return token.claimWithCtx( - publisher, - indexId, - subscriber, - ctx - ); - } else { - revert("invalid function index"); - } - } -} - // GDA LIBRARY SUPER APP CALLBACK MOCK contract SuperTokenLibraryGDASuperAppMock is SuperTokenLibraryGDAMock, SuperAppBase { using SuperTokenV1Library for ISuperToken; diff --git a/packages/ethereum-contracts/contracts/utils/SuperfluidFrameworkDeploymentSteps.sol b/packages/ethereum-contracts/contracts/utils/SuperfluidFrameworkDeploymentSteps.sol index a8c769b773..f5188b1db1 100644 --- a/packages/ethereum-contracts/contracts/utils/SuperfluidFrameworkDeploymentSteps.sol +++ b/packages/ethereum-contracts/contracts/utils/SuperfluidFrameworkDeploymentSteps.sol @@ -30,7 +30,6 @@ import { UUPSProxy } from "../upgradability/UUPSProxy.sol"; import { BatchLiquidator } from "./BatchLiquidator.sol"; import { TOGA } from "./TOGA.sol"; import { CFAv1Library } from "../apps/CFAv1Library.sol"; -import { IDAv1Library } from "../apps/IDAv1Library.sol"; import { IResolver } from "../interfaces/utils/IResolver.sol"; import { DMZForwarder } from "../utils/DMZForwarder.sol"; import { MacroForwarder } from "../utils/MacroForwarder.sol"; @@ -59,7 +58,6 @@ contract SuperfluidFrameworkDeploymentSteps { CFAv1Library.InitData cfaLib; InstantDistributionAgreementV1 ida; GeneralDistributionAgreementV1 gda; - IDAv1Library.InitData idaLib; SuperTokenFactory superTokenFactory; ISuperToken superTokenLogic; TestResolver resolver; @@ -115,7 +113,6 @@ contract SuperfluidFrameworkDeploymentSteps { cfa: cfaV1, cfaLib: CFAv1Library.InitData(host, cfaV1), ida: idaV1, - idaLib: IDAv1Library.InitData(host, idaV1), gda: gdaV1, superTokenFactory: superTokenFactory, superTokenLogic: superTokenLogic, diff --git a/packages/ethereum-contracts/test/contracts/apps/IDAv1Library.test.ts b/packages/ethereum-contracts/test/contracts/apps/IDAv1Library.test.ts deleted file mode 100644 index c03ee17d46..0000000000 --- a/packages/ethereum-contracts/test/contracts/apps/IDAv1Library.test.ts +++ /dev/null @@ -1,1384 +0,0 @@ -import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; -import {assert, ethers, expect, web3} from "hardhat"; - -import { - IDAv1LibraryMock, - IDAv1LibrarySuperAppMock, - InstantDistributionAgreementV1, - SuperfluidMock, - SuperTokenMock, -} from "../../../typechain-types"; -import TestEnvironment from "../../TestEnvironment"; - -const ZERO_ADDRESS = ethers.constants.AddressZero; - -describe("IDAv1Library testing", function () { - this.timeout(300e3); - - // HELPERS - - // enum simulator. - // This is used in the IDAv1LibrarySuperAppMock for checking all functions. - const FunctionIndex = { - CREATE_INDEX: 0, - CREATE_INDEX_USER_DATA: 1, - UPDATE_INDEX: 2, - UPDATE_INDEX_USER_DATA: 3, - DISTRIBUTE: 4, - DISTRIBUTE_USER_DATA: 5, - APPROVE_SUBSCRIPTION: 6, - APPROVE_SUBSCRIPTION_USER_DATA: 7, - REVOKE_SUBSCRIPTION: 8, - REVOKE_SUBSCRIPTION_USER_DATA: 9, - UPDATE_SUBSCRIPTION: 10, - UPDATE_SUBSCRIPTION_USER_DATA: 11, - DELETE_SUBSCRIPTION: 12, - DELETE_SUBSCRIPTION_USER_DATA: 13, - CLAIM: 14, - CLAIM_USER_DATA: 15, - }; - - const toBytes = (text: string) => - web3.eth.abi.encodeParameter("string", text); - - const userData = ( - functionIndex: number, - indexId: number, - publisher = ZERO_ADDRESS, - subscriber = ZERO_ADDRESS, - units = 0 - ) => - web3.eth.abi.encodeParameters( - ["uint8", "uint32", "address", "address", "uint128"], - [functionIndex, indexId, publisher, subscriber, units] - ); - - // TEST SET UP - const t = TestEnvironment.getSingleton(); - - const INDEX_ID = 0; - - let superToken: SuperTokenMock, - host: SuperfluidMock, - ida: InstantDistributionAgreementV1, - alice: string, - bob: string, - idaV1LibMock: IDAv1LibraryMock, - idaV1LibSuperAppMock: IDAv1LibrarySuperAppMock, - aliceSigner: SignerWithAddress; - - before(async () => { - await t.beforeTestSuite({isTruffle: true, nAccounts: 4}); - - ida = t.contracts.ida; - host = t.contracts.superfluid; - ({alice, bob} = t.aliases); - superToken = await ethers.getContractAt( - "SuperTokenMock", - t.tokens.SuperToken.address - ); - - await superToken.mintInternal( - alice, - ethers.utils.parseUnits("100000", "ether"), - "0x", - "0x" - ); - aliceSigner = await ethers.getSigner(alice); - }); - - beforeEach(async function () { - const idaV1LibMockFactory = - await ethers.getContractFactory("IDAv1LibraryMock"); - idaV1LibMock = (await idaV1LibMockFactory.deploy(host.address)).connect( - aliceSigner - ); - const idaV1LibSuperAppMockFactory = await ethers.getContractFactory( - "IDAv1LibrarySuperAppMock" - ); - idaV1LibSuperAppMock = ( - await idaV1LibSuperAppMockFactory.deploy(host.address) - ).connect(aliceSigner); - await superToken - .connect(aliceSigner) - .transfer( - idaV1LibMock.address, - ethers.utils.parseUnits("10", "ether") - ); - await superToken - .connect(aliceSigner) - .transfer( - idaV1LibSuperAppMock.address, - ethers.utils.parseUnits("10", "ether") - ); - t.beforeEachTestCaseBenchmark(this); - }); - - afterEach(() => { - t.afterEachTestCaseBenchmark(); - }); - - describe("#1 - Non-Callback Index Operations", async function () { - it("#1.1 - create index", async () => { - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ) - ).exist, - true - ); - }); - - it("#1.2 - create index with user data", async () => { - console.log("Alice create index with user data"); - await idaV1LibMock.createIndexWithUserDataTest( - superToken.address, - INDEX_ID, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ) - ).exist, - true - ); - }); - - it("#1.3 - update index value", async () => { - const indexValue = 1; - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("Alice updates index value"); - await idaV1LibMock.updateIndexValueTest( - superToken.address, - INDEX_ID, - indexValue - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - indexValue - ); - }); - - it("#1.4 - update index value with user data", async () => { - const indexValue = 1; - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("Alice updates index value with user data"); - await idaV1LibMock.updateIndexValueWithUserDataTest( - superToken.address, - INDEX_ID, - indexValue, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - indexValue - ); - }); - - it("#1.5 - distribute", async () => { - const distribution = 1; - const units = 1; - - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("Alice issues units to Bob"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("Alice distributes"); - await idaV1LibMock.distributeTest( - superToken.address, - INDEX_ID, - distribution - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - distribution - ); - }); - - it("#1.6 - distribute with user data", async () => { - const distribution = 1; - const units = 1; - - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("Alice issues units to Bob"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("Alice distributes with user data"); - await idaV1LibMock.distributeWithUserDataTest( - superToken.address, - INDEX_ID, - distribution, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - distribution - ); - }); - }); - - describe("#2 - Non-Callback Subscription Operations", async function () { - it("#2.1 - approve subscription", async () => { - // must create externally to test against mock contract - console.log("Alice creates index"); - await host - .connect(aliceSigner) - .callAgreement( - ida.address, - t.agreementHelper.idaInterface.encodeFunctionData( - "createIndex", - [superToken.address, INDEX_ID, "0x"] - ), - "0x" - ); - - console.log("Bob approves subscription"); - await idaV1LibMock - .connect(await ethers.getSigner(bob)) - .approveSubscriptionTest(superToken.address, alice, INDEX_ID); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - idaV1LibMock.address - ) - ).approved, - true - ); - }); - - it("#2.2 - approve subscription with user data", async () => { - console.log("Bob approves subscription with user data"); - await idaV1LibMock - .connect(await ethers.getSigner(bob)) - .approveSubscriptionWithUserDataTest( - superToken.address, - alice, - INDEX_ID, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - idaV1LibMock.address - ) - ).approved, - true - ); - }); - - it("#2.3 - revoke subscription", async () => { - console.log("Bob approves subscription"); - await idaV1LibMock.approveSubscriptionTest( - superToken.address, - alice, - INDEX_ID - ); - - console.log("Bob revokes subscription"); - await idaV1LibMock.revokeSubscriptionTest( - superToken.address, - alice, - INDEX_ID - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - idaV1LibMock.address - ) - ).approved, - false - ); - }); - - it("#2.4 - revoke subscription with user data", async () => { - console.log("Bob approves subscription"); - await idaV1LibMock.approveSubscriptionTest( - superToken.address, - alice, - INDEX_ID - ); - - console.log("Bob revokes subscription with user data"); - await idaV1LibMock.revokeSubscriptionWithUserDataTest( - superToken.address, - alice, - INDEX_ID, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - idaV1LibMock.address - ) - ).approved, - false - ); - }); - - it("#2.5 - update subscription units", async () => { - const units = 1; - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("Alice updates Bob's subscription"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - units - ); - }); - - it("#2.6 - update subscription with user data", async () => { - const units = 1; - - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("Alice updates Bob's subscription with user data"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - bob, - units, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - units - ); - }); - - it("#2.7 - delete subscription", async () => { - const units = 1; - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("Alice updates Bob's subscription"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("Alice deletes Bob's subscription"); - await idaV1LibMock - .connect(await ethers.getSigner(bob)) - .deleteSubscriptionTest( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - bob - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - 0 - ); - }); - - it("#2.8 - delete subscription with user data", async () => { - const units = 1; - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("Alice updates Bob's subscription"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("Alice deletes Bob's subscription"); - await idaV1LibMock - .connect(await ethers.getSigner(bob)) - .deleteSubscriptionWithUserDataTest( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - bob, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - 0 - ); - }); - - it("#2.9 - claim", async () => { - const units = 1; - - console.log("Alice updates subscription units"); - await host - .connect(aliceSigner) - .callAgreement( - ida.address, - t.agreementHelper.idaInterface.encodeFunctionData( - "updateSubscription", - [ - superToken.address, - INDEX_ID, - idaV1LibMock.address, - units, - "0x", - ] - ), - "0x" - ); - - console.log("Bob claims pending units"); - await idaV1LibMock - .connect(await ethers.getSigner(bob)) - .claimTest( - superToken.address, - alice, - INDEX_ID, - idaV1LibMock.address - ); - - const subscription = await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - idaV1LibMock.address - ); - - assert.equal(subscription.units.toNumber(), units); - assert.equal(subscription.pendingDistribution.toNumber(), 0); - }); - - it("#2.10 - claim with user data", async () => { - const units = 1; - console.log("Alice updates subscription units"); - await host - .connect(aliceSigner) - .callAgreement( - ida.address, - t.agreementHelper.idaInterface.encodeFunctionData( - "updateSubscription", - [ - superToken.address, - INDEX_ID, - idaV1LibMock.address, - units, - "0x", - ] - ), - "0x" - ); - - console.log("Bob claims pending units"); - await idaV1LibMock - .connect(await ethers.getSigner(bob)) - .claimWithUserDataTest( - superToken.address, - alice, - INDEX_ID, - idaV1LibMock.address, - toBytes("oh hello") - ); - - const subscription = await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - idaV1LibMock.address - ); - - assert.equal(subscription.units.toNumber(), units); - assert.equal(subscription.pendingDistribution.toNumber(), 0); - }); - }); - - describe("#3 - View Operations", async function () { - it("#3.1 - get index", async () => { - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - const index = await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ); - - const libIndex = await idaV1LibMock.getIndexTest( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ); - - assert.equal(index.exist, libIndex.exist); - assert.equal( - index.indexValue.toString(), - libIndex.indexValue.toString() - ); - assert.equal( - index.totalUnitsApproved.toString(), - libIndex.totalUnitsApproved.toString() - ); - assert.equal( - index.totalUnitsPending.toString(), - libIndex.totalUnitsPending.toString() - ); - }); - - it("#3.2 - calculate distribution", async () => { - const amount = 1; - const units = 1; - - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("Alice updates subscription units"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - const distribution = await ida.calculateDistribution( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - amount - ); - const distributionLib = - await idaV1LibMock.calculateDistributionTest( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - amount - ); - - assert.equal( - distribution.actualAmount.toString(), - distributionLib.actualAmount.toString() - ); - assert.equal( - distribution.newIndexValue.toString(), - distributionLib.newIndexValue.toString() - ); - }); - - it("#3.3 - list subscriptions", async () => { - const units = 1; - - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("Alice updates subscription units"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - const subscriptions = await ida.listSubscriptions( - superToken.address, - bob - ); - const subscriptionsLib = await idaV1LibMock.listSubscriptionsTest( - superToken.address, - bob - ); - - expect(subscriptions.publishers).to.eql( - subscriptionsLib.publishers - ); - expect(subscriptions.indexIds).to.eql(subscriptionsLib.indexIds); - expect(subscriptions.unitsList).to.eql(subscriptionsLib.unitsList); - }); - - it("#3.4 - get subscription", async () => { - const units = 1; - - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("Alice updates subscription units"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - const subscription = await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - bob - ); - const subscriptionLib = await idaV1LibMock.getSubscriptionTest( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - bob - ); - - assert.equal(subscription.exist, subscriptionLib.exist); - assert.equal(subscription.approved, subscriptionLib.approved); - assert.equal( - subscription.units.toString(), - subscriptionLib.units.toString() - ); - assert.equal( - subscription.pendingDistribution.toString(), - subscriptionLib.pendingDistribution.toString() - ); - }); - - it("#3.5 - get subscription by id", async () => { - const units = 1; - - const publisherId = ethers.utils.solidityKeccak256( - ["string", "address", "uint32"], - ["publisher", idaV1LibMock.address, INDEX_ID] - ); - const subscriptionId = ethers.utils.solidityKeccak256( - ["string", "address", "bytes32"], - ["subscription", bob, publisherId] - ); - - console.log("Alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("Alice updates subscription units"); - await idaV1LibMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - const subscription = await ida.getSubscriptionByID( - superToken.address, - subscriptionId - ); - const subscriptionLib = await idaV1LibMock.getSubscriptionByIDTest( - superToken.address, - subscriptionId - ); - - assert.equal(subscription.approved, subscriptionLib.approved); - assert.equal( - subscription.units.toString(), - subscriptionLib.units.toString() - ); - assert.equal( - subscription.pendingDistribution.toString(), - subscriptionLib.pendingDistribution.toString() - ); - }); - }); - - // CALLBACK TESTS - // These tests pass `userData` to be extracted and used inside a super app callback. - describe("#4 - Callback Index Operations", async function () { - it("#4.1 - create index in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData(FunctionIndex.CREATE_INDEX, INDEX_ID) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID - ) - ).exist, - true - ); - }); - - it("#4.2 - create index in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData(FunctionIndex.CREATE_INDEX_USER_DATA, INDEX_ID) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID - ) - ).exist, - true - ); - }); - - it("#4.3 - update index in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("super app creates index"); - await idaV1LibSuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app adds subscription to bob"); - await idaV1LibSuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.UPDATE_INDEX, - INDEX_ID, - undefined, - undefined, - units - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - units - ); - }); - - it("#4.4 - update index in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("super app creates index"); - await idaV1LibSuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app adds subscription to bob"); - await idaV1LibSuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.UPDATE_INDEX_USER_DATA, - INDEX_ID, - undefined, - undefined, - units - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - units - ); - }); - - it("#4.5 - distribute in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("super app creates index"); - await idaV1LibSuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app adds subscription to bob"); - await idaV1LibSuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.DISTRIBUTE, - INDEX_ID, - undefined, - undefined, - units - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - units - ); - }); - - it("#4.6 - distribute in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("super app creates index"); - await idaV1LibSuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app adds subscription to bob"); - await idaV1LibSuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.DISTRIBUTE_USER_DATA, - INDEX_ID, - undefined, - undefined, - units - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - units - ); - }); - - it("#4.7 - approve subscription in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.APPROVE_SUBSCRIPTION, - INDEX_ID, - idaV1LibMock.address - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ) - ).totalUnitsApproved.toNumber(), - units - ); - }); - - it("#4.8 - approve subscription in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.APPROVE_SUBSCRIPTION_USER_DATA, - INDEX_ID, - idaV1LibMock.address - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ) - ).totalUnitsApproved.toNumber(), - units - ); - }); - - it("#4.9 - revoke subscription in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("super app approves subscription"); - await idaV1LibSuperAppMock.approveSubscriptionTest( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.REVOKE_SUBSCRIPTION, - INDEX_ID, - idaV1LibMock.address - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - idaV1LibSuperAppMock.address - ) - ).approved, - false - ); - }); - - it("#4.10 - revoke subscription in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("super app approves subscription"); - await idaV1LibSuperAppMock.approveSubscriptionTest( - superToken.address, - idaV1LibMock.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.REVOKE_SUBSCRIPTION_USER_DATA, - INDEX_ID, - idaV1LibMock.address - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - idaV1LibSuperAppMock.address - ) - ).approved, - false - ); - }); - - it("#4.11 - update subscription units in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("super app creates index"); - await idaV1LibSuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.UPDATE_SUBSCRIPTION, - INDEX_ID, - undefined, - idaV1LibMock.address, - units - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID, - idaV1LibMock.address - ) - ).units.toNumber(), - units - ); - }); - - it("#4.12 - update subscription units in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("super app creates index"); - await idaV1LibSuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.UPDATE_SUBSCRIPTION_USER_DATA, - INDEX_ID, - undefined, - idaV1LibMock.address, - units - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID, - idaV1LibMock.address - ) - ).units.toNumber(), - units - ); - }); - - it("#4.13 - delete subscription in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("super app creates index"); - await idaV1LibSuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app issues units to bob"); - await idaV1LibSuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.DELETE_SUBSCRIPTION, - INDEX_ID, - idaV1LibSuperAppMock.address, - bob - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - 0 - ); - }); - - it("#4.14 - delete subscription in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - - console.log("super app creates index"); - await idaV1LibSuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("super app issues units to bob"); - await idaV1LibSuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.DELETE_SUBSCRIPTION, - INDEX_ID, - idaV1LibSuperAppMock.address, - bob - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibSuperAppMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - 0 - ); - }); - - it("#4.15 - claim in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.CLAIM, - INDEX_ID, - idaV1LibMock.address, - idaV1LibSuperAppMock.address - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - idaV1LibSuperAppMock.address - ) - ).pendingDistribution.toNumber(), - 0 - ); - }); - - it("#4.15 - claim in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await idaV1LibMock.createIndexTest(superToken.address, INDEX_ID); - console.log("alice triggers callback on super app"); - await idaV1LibMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - idaV1LibSuperAppMock.address, - units, - userData( - FunctionIndex.CLAIM_USER_DATA, - INDEX_ID, - idaV1LibMock.address, - idaV1LibSuperAppMock.address - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - idaV1LibMock.address, - INDEX_ID, - idaV1LibSuperAppMock.address - ) - ).pendingDistribution.toNumber(), - 0 - ); - }); - }); -}); diff --git a/packages/ethereum-contracts/test/contracts/apps/SuperTokenV1Library.IDA.test.ts b/packages/ethereum-contracts/test/contracts/apps/SuperTokenV1Library.IDA.test.ts deleted file mode 100644 index eac33fee16..0000000000 --- a/packages/ethereum-contracts/test/contracts/apps/SuperTokenV1Library.IDA.test.ts +++ /dev/null @@ -1,1485 +0,0 @@ -import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; -import {assert, ethers, expect, web3} from "hardhat"; - -import { - InstantDistributionAgreementV1, - SuperfluidMock, - SuperTokenLibraryIDAMock, - SuperTokenLibraryIDASuperAppMock, - SuperTokenMock, -} from "../../../typechain-types"; -import TestEnvironment from "../../TestEnvironment"; - -const ZERO_ADDRESS = ethers.constants.AddressZero; - -describe("IDAv1Library testing", function () { - this.timeout(300e3); - - // HELPERS - - // enum simulator. - // This is used in the IDAv1LibrarySuperAppMock for checking all functions. - const FunctionIndex = { - CREATE_INDEX: 0, - CREATE_INDEX_USER_DATA: 1, - UPDATE_INDEX: 2, - UPDATE_INDEX_USER_DATA: 3, - DISTRIBUTE: 4, - DISTRIBUTE_USER_DATA: 5, - APPROVE_SUBSCRIPTION: 6, - APPROVE_SUBSCRIPTION_USER_DATA: 7, - REVOKE_SUBSCRIPTION: 8, - REVOKE_SUBSCRIPTION_USER_DATA: 9, - UPDATE_SUBSCRIPTION: 10, - UPDATE_SUBSCRIPTION_USER_DATA: 11, - DELETE_SUBSCRIPTION: 12, - DELETE_SUBSCRIPTION_USER_DATA: 13, - CLAIM: 14, - CLAIM_USER_DATA: 15, - }; - - const toBytes = (text: string) => - web3.eth.abi.encodeParameter("string", text); - - const userData = ( - functionIndex: number, - indexId: number, - publisher = ZERO_ADDRESS, - subscriber = ZERO_ADDRESS, - units = 0 - ) => - web3.eth.abi.encodeParameters( - ["uint8", "uint32", "address", "address", "uint128"], - [functionIndex, indexId, publisher, subscriber, units] - ); - - // TEST SET UP - const t = TestEnvironment.getSingleton(); - - const INDEX_ID = 0; - - let superToken: SuperTokenMock, - host: SuperfluidMock, - ida: InstantDistributionAgreementV1, - alice: string, - bob: string, - superTokenLibIDAMock: SuperTokenLibraryIDAMock, - superTokenLibIDASuperAppMock: SuperTokenLibraryIDASuperAppMock, - aliceSigner: SignerWithAddress; - - before(async () => { - await t.beforeTestSuite({isTruffle: true, nAccounts: 4}); - - ida = t.contracts.ida; - host = t.contracts.superfluid; - ({alice, bob} = t.aliases); - superToken = await ethers.getContractAt( - "SuperTokenMock", - t.tokens.SuperToken.address - ); - - await superToken.mintInternal( - alice, - ethers.utils.parseUnits("100000", "ether"), - "0x", - "0x" - ); - aliceSigner = await ethers.getSigner(alice); - }); - - beforeEach(async function () { - const superTokenLibIDAMockFactory = await ethers.getContractFactory( - "SuperTokenLibraryIDAMock" - ); - superTokenLibIDAMock = ( - await superTokenLibIDAMockFactory.deploy() - ).connect(aliceSigner); - const superTokenLibIDASuperAppMockFactory = - await ethers.getContractFactory("SuperTokenLibraryIDASuperAppMock"); - superTokenLibIDASuperAppMock = ( - await superTokenLibIDASuperAppMockFactory.deploy(host.address) - ).connect(aliceSigner); - await superToken - .connect(aliceSigner) - .transfer( - superTokenLibIDAMock.address, - ethers.utils.parseUnits("10", "ether") - ); - await superToken - .connect(aliceSigner) - .transfer( - superTokenLibIDASuperAppMock.address, - ethers.utils.parseUnits("10", "ether") - ); - - t.beforeEachTestCaseBenchmark(this); - }); - - afterEach(() => { - t.afterEachTestCaseBenchmark(); - }); - - describe("#1 - Non-Callback Index Operations", async function () { - it("#1.1 - create index", async () => { - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ) - ).exist, - true - ); - }); - - it("#1.2 - create index with user data", async () => { - console.log("Alice create index with user data"); - await superTokenLibIDAMock.createIndexWithUserDataTest( - superToken.address, - INDEX_ID, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ) - ).exist, - true - ); - }); - - it("#1.3 - update index value", async () => { - const indexValue = 1; - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("Alice updates index value"); - await superTokenLibIDAMock.updateIndexValueTest( - superToken.address, - INDEX_ID, - indexValue - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - indexValue - ); - }); - - it("#1.4 - update index value with user data", async () => { - const indexValue = 1; - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("Alice updates index value with user data"); - await superTokenLibIDAMock.updateIndexValueWithUserDataTest( - superToken.address, - INDEX_ID, - indexValue, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - indexValue - ); - }); - - it("#1.5 - distribute", async () => { - const distribution = 1; - const units = 1; - - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("Alice issues units to Bob"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("Alice distributes"); - await superTokenLibIDAMock.distributeTest( - superToken.address, - INDEX_ID, - distribution - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - distribution - ); - }); - - it("#1.6 - distribute with user data", async () => { - const distribution = 1; - const units = 1; - - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("Alice issues units to Bob"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("Alice distributes with user data"); - await superTokenLibIDAMock.distributeWithUserDataTest( - superToken.address, - INDEX_ID, - distribution, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - distribution - ); - }); - - it("#1.7 - _getHostAndIDA empty cache test", async () => { - await superTokenLibIDAMock.listSubscriptionsTest( - superToken.address, - bob - ); - }); - }); - - describe("#2 - Non-Callback Subscription Operations", async function () { - it("#2.1 - approve subscription", async () => { - // must create externally to test against mock contract - console.log("Alice creates index"); - await host - .connect(aliceSigner) - .callAgreement( - ida.address, - t.agreementHelper.idaInterface.encodeFunctionData( - "createIndex", - [superToken.address, INDEX_ID, "0x"] - ), - "0x" - ); - - console.log("Bob approves subscription"); - await superTokenLibIDAMock - .connect(await ethers.getSigner(bob)) - .approveSubscriptionTest(superToken.address, alice, INDEX_ID); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - superTokenLibIDAMock.address - ) - ).approved, - true - ); - }); - - it("#2.2 - approve subscription with user data", async () => { - console.log("Bob approves subscription with user data"); - await superTokenLibIDAMock - .connect(await ethers.getSigner(bob)) - .approveSubscriptionWithUserDataTest( - superToken.address, - alice, - INDEX_ID, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - superTokenLibIDAMock.address - ) - ).approved, - true - ); - }); - - it("#2.3 - revoke subscription", async () => { - console.log("Bob approves subscription"); - await superTokenLibIDAMock.approveSubscriptionTest( - superToken.address, - alice, - INDEX_ID - ); - - console.log("Bob revokes subscription"); - await superTokenLibIDAMock.revokeSubscriptionTest( - superToken.address, - alice, - INDEX_ID - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - superTokenLibIDAMock.address - ) - ).approved, - false - ); - }); - - it("#2.4 - revoke subscription with user data", async () => { - console.log("Bob approves subscription"); - await superTokenLibIDAMock.approveSubscriptionTest( - superToken.address, - alice, - INDEX_ID - ); - - console.log("Bob revokes subscription with user data"); - await superTokenLibIDAMock.revokeSubscriptionWithUserDataTest( - superToken.address, - alice, - INDEX_ID, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - superTokenLibIDAMock.address - ) - ).approved, - false - ); - }); - - it("#2.5 - update subscription units", async () => { - const units = 1; - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("Alice updates Bob's subscription"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - units - ); - }); - - it("#2.6 - update subscription with user data", async () => { - const units = 1; - - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("Alice updates Bob's subscription with user data"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - bob, - units, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - units - ); - }); - - it("#2.7 - delete subscription", async () => { - const units = 1; - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("Alice updates Bob's subscription"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("Alice deletes Bob's subscription"); - await superTokenLibIDAMock - .connect(await ethers.getSigner(bob)) - .deleteSubscriptionTest( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - bob - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - 0 - ); - }); - - it("#2.8 - delete subscription with user data", async () => { - const units = 1; - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("Alice updates Bob's subscription"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("Alice deletes Bob's subscription"); - await superTokenLibIDAMock - .connect(await ethers.getSigner(bob)) - .deleteSubscriptionWithUserDataTest( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - bob, - toBytes("oh hello") - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - 0 - ); - }); - - it("#2.9 - claim", async () => { - const units = 1; - - console.log("Alice updates subscription units"); - await host - .connect(aliceSigner) - .callAgreement( - ida.address, - t.agreementHelper.idaInterface.encodeFunctionData( - "updateSubscription", - [ - superToken.address, - INDEX_ID, - superTokenLibIDAMock.address, - units, - "0x", - ] - ), - "0x" - ); - - console.log("Bob claims pending units"); - await superTokenLibIDAMock - .connect(await ethers.getSigner(bob)) - .claimTest( - superToken.address, - alice, - INDEX_ID, - superTokenLibIDAMock.address - ); - - const subscription = await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - superTokenLibIDAMock.address - ); - - assert.equal(subscription.units.toNumber(), units); - assert.equal(subscription.pendingDistribution.toNumber(), 0); - }); - - it("#2.10 - claim with user data", async () => { - const units = 1; - console.log("Alice updates subscription units"); - await host - .connect(aliceSigner) - .callAgreement( - ida.address, - t.agreementHelper.idaInterface.encodeFunctionData( - "updateSubscription", - [ - superToken.address, - INDEX_ID, - superTokenLibIDAMock.address, - units, - "0x", - ] - ), - "0x" - ); - - console.log("Bob claims pending units"); - await superTokenLibIDAMock - .connect(await ethers.getSigner(bob)) - .claimWithUserDataTest( - superToken.address, - alice, - INDEX_ID, - superTokenLibIDAMock.address, - toBytes("oh hello") - ); - - const subscription = await ida.getSubscription( - superToken.address, - alice, - INDEX_ID, - superTokenLibIDAMock.address - ); - - assert.equal(subscription.units.toNumber(), units); - assert.equal(subscription.pendingDistribution.toNumber(), 0); - }); - }); - - describe("#3 - View Operations", async function () { - it("#3.1 - get index", async () => { - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - const index = await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ); - - const libIndex = await superTokenLibIDAMock.getIndexTest( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ); - - assert.equal(index.exist, libIndex.exist); - assert.equal( - index.indexValue.toString(), - libIndex.indexValue.toString() - ); - assert.equal( - index.totalUnitsApproved.toString(), - libIndex.totalUnitsApproved.toString() - ); - assert.equal( - index.totalUnitsPending.toString(), - libIndex.totalUnitsPending.toString() - ); - }); - - it("#3.2 - calculate distribution", async () => { - const amount = 1; - const units = 1; - - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("Alice updates subscription units"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - const distribution = await ida.calculateDistribution( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - amount - ); - const distributionLib = - await superTokenLibIDAMock.calculateDistributionTest( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - amount - ); - - assert.equal( - distribution.actualAmount.toString(), - distributionLib.actualAmount.toString() - ); - assert.equal( - distribution.newIndexValue.toString(), - distributionLib.newIndexValue.toString() - ); - }); - - it("#3.3 - list subscriptions", async () => { - const units = 1; - - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("Alice updates subscription units"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - const subscriptions = await ida.listSubscriptions( - superToken.address, - bob - ); - const subscriptionsLib = - await superTokenLibIDAMock.listSubscriptionsTest( - superToken.address, - bob - ); - - expect(subscriptions.publishers).to.eql( - subscriptionsLib.publishers - ); - expect(subscriptions.indexIds).to.eql(subscriptionsLib.indexIds); - expect(subscriptions.unitsList).to.eql(subscriptionsLib.unitsList); - }); - - it("#3.4 - get subscription", async () => { - const units = 1; - - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("Alice updates subscription units"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - const subscription = await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - bob - ); - const subscriptionLib = - await superTokenLibIDAMock.getSubscriptionTest( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - bob - ); - - assert.equal(subscription.exist, subscriptionLib.exist); - assert.equal(subscription.approved, subscriptionLib.approved); - assert.equal( - subscription.units.toString(), - subscriptionLib.units.toString() - ); - assert.equal( - subscription.pendingDistribution.toString(), - subscriptionLib.pendingDistribution.toString() - ); - }); - - it("#3.5 - get subscription by id", async () => { - const units = 1; - - const publisherId = ethers.utils.solidityKeccak256( - ["string", "address", "uint32"], - ["publisher", superTokenLibIDAMock.address, INDEX_ID] - ); - const subscriptionId = ethers.utils.solidityKeccak256( - ["string", "address", "bytes32"], - ["subscription", bob, publisherId] - ); - - console.log("Alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("Alice updates subscription units"); - await superTokenLibIDAMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - const subscription = await ida.getSubscriptionByID( - superToken.address, - subscriptionId - ); - const subscriptionLib = - await superTokenLibIDAMock.getSubscriptionByIDTest( - superToken.address, - subscriptionId - ); - - assert.equal(subscription.approved, subscriptionLib.approved); - assert.equal( - subscription.units.toString(), - subscriptionLib.units.toString() - ); - assert.equal( - subscription.pendingDistribution.toString(), - subscriptionLib.pendingDistribution.toString() - ); - }); - }); - - // CALLBACK TESTS - // These tests pass `userData` to be extracted and used inside a super app callback. - describe("#4 - Callback Index Operations", async function () { - it("#4.1 - create index in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData(FunctionIndex.CREATE_INDEX, INDEX_ID) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID - ) - ).exist, - true - ); - }); - - it("#4.2 - create index in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData(FunctionIndex.CREATE_INDEX_USER_DATA, INDEX_ID) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID - ) - ).exist, - true - ); - }); - - it("#4.3 - update index in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("super app creates index"); - await superTokenLibIDASuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app adds subscription to bob"); - await superTokenLibIDASuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.UPDATE_INDEX, - INDEX_ID, - undefined, - undefined, - units - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - units - ); - }); - - it("#4.4 - update index in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("super app creates index"); - await superTokenLibIDASuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app adds subscription to bob"); - await superTokenLibIDASuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.UPDATE_INDEX_USER_DATA, - INDEX_ID, - undefined, - undefined, - units - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - units - ); - }); - - it("#4.5 - distribute in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("super app creates index"); - await superTokenLibIDASuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app adds subscription to bob"); - await superTokenLibIDASuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.DISTRIBUTE, - INDEX_ID, - undefined, - undefined, - units - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - units - ); - }); - - it("#4.6 - distribute in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("super app creates index"); - await superTokenLibIDASuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app adds subscription to bob"); - await superTokenLibIDASuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.DISTRIBUTE_USER_DATA, - INDEX_ID, - undefined, - undefined, - units - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID - ) - ).indexValue.toNumber(), - units - ); - }); - - it("#4.7 - approve subscription in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.APPROVE_SUBSCRIPTION, - INDEX_ID, - superTokenLibIDAMock.address - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ) - ).totalUnitsApproved.toNumber(), - units - ); - }); - - it("#4.8 - approve subscription in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.APPROVE_SUBSCRIPTION_USER_DATA, - INDEX_ID, - superTokenLibIDAMock.address - ) - ); - - assert.equal( - ( - await ida.getIndex( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ) - ).totalUnitsApproved.toNumber(), - units - ); - }); - - it("#4.9 - revoke subscription in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app approves subscription"); - await superTokenLibIDASuperAppMock.approveSubscriptionTest( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.REVOKE_SUBSCRIPTION, - INDEX_ID, - superTokenLibIDAMock.address - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address - ) - ).approved, - false - ); - }); - - it("#4.10 - revoke subscription in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app approves subscription"); - await superTokenLibIDASuperAppMock.approveSubscriptionTest( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.REVOKE_SUBSCRIPTION_USER_DATA, - INDEX_ID, - superTokenLibIDAMock.address - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address - ) - ).approved, - false - ); - }); - - it("#4.11 - update subscription units in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app creates index"); - await superTokenLibIDASuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.UPDATE_SUBSCRIPTION, - INDEX_ID, - undefined, - superTokenLibIDAMock.address, - units - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID, - superTokenLibIDAMock.address - ) - ).units.toNumber(), - units - ); - }); - - it("#4.12 - update subscription units in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app creates index"); - await superTokenLibIDASuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.UPDATE_SUBSCRIPTION_USER_DATA, - INDEX_ID, - undefined, - superTokenLibIDAMock.address, - units - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID, - superTokenLibIDAMock.address - ) - ).units.toNumber(), - units - ); - }); - - it("#4.13 - delete subscription in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app creates index"); - await superTokenLibIDASuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("super app issues units to bob"); - await superTokenLibIDASuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.DELETE_SUBSCRIPTION, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - bob - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - 0 - ); - }); - - it("#4.14 - delete subscription in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("super app creates index"); - await superTokenLibIDASuperAppMock.createIndexTest( - superToken.address, - INDEX_ID - ); - - console.log("super app issues units to bob"); - await superTokenLibIDASuperAppMock.updateSubscriptionUnitsTest( - superToken.address, - INDEX_ID, - bob, - units - ); - - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.DELETE_SUBSCRIPTION, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - bob - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDASuperAppMock.address, - INDEX_ID, - bob - ) - ).units.toNumber(), - 0 - ); - }); - - it("#4.15 - claim in callback", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.CLAIM, - INDEX_ID, - superTokenLibIDAMock.address, - superTokenLibIDASuperAppMock.address - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address - ) - ).pendingDistribution.toNumber(), - 0 - ); - }); - - it("#4.15 - claim in callback with user data", async () => { - const units = 1; - - console.log("alice creates index"); - await superTokenLibIDAMock.createIndexTest( - superToken.address, - INDEX_ID - ); - console.log("alice triggers callback on super app"); - await superTokenLibIDAMock.updateSubscriptionUnitsWithUserDataTest( - superToken.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address, - units, - userData( - FunctionIndex.CLAIM_USER_DATA, - INDEX_ID, - superTokenLibIDAMock.address, - superTokenLibIDASuperAppMock.address - ) - ); - - assert.equal( - ( - await ida.getSubscription( - superToken.address, - superTokenLibIDAMock.address, - INDEX_ID, - superTokenLibIDASuperAppMock.address - ) - ).pendingDistribution.toNumber(), - 0 - ); - }); - }); -}); diff --git a/packages/ethereum-contracts/testsuites/apps-contracts.ts b/packages/ethereum-contracts/testsuites/apps-contracts.ts index 20edbb21fc..a630d12ea8 100644 --- a/packages/ethereum-contracts/testsuites/apps-contracts.ts +++ b/packages/ethereum-contracts/testsuites/apps-contracts.ts @@ -1,5 +1,4 @@ import "../test/contracts/apps/SuperTokenV1Library.CFA.test"; -import "../test/contracts/apps/SuperTokenV1Library.IDA.test"; import "../test/contracts/apps/SuperTokenV1Library.GDA.test"; import "../test/contracts/apps/CFAv1Library.test"; -import "../test/contracts/apps/IDAv1Library.test"; \ No newline at end of file + diff --git a/packages/hot-fuzz/contracts/HotFuzzBase.sol b/packages/hot-fuzz/contracts/HotFuzzBase.sol index 5e0fb92659..07b20c1a37 100644 --- a/packages/hot-fuzz/contracts/HotFuzzBase.sol +++ b/packages/hot-fuzz/contracts/HotFuzzBase.sol @@ -16,7 +16,6 @@ import { SuperfluidFrameworkDeployer } from "@superfluid-finance/ethereum-contracts/contracts/utils/SuperfluidFrameworkDeployer.sol"; import "@superfluid-finance/ethereum-contracts/contracts/apps/CFAv1Library.sol"; -import "@superfluid-finance/ethereum-contracts/contracts/apps/IDAv1Library.sol"; import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol";