@@ -32,6 +32,27 @@ import { AgreementBase } from "../AgreementBase.sol";
3232import { AgreementLibrary } from "../AgreementLibrary.sol " ;
3333
3434
35+ /// @dev Universal Index state slot id for storing universal index data
36+ function _universalIndexStateSlotId () pure returns (uint256 ) {
37+ return 0 ;
38+ }
39+
40+ /// @dev returns true if the account is a pool
41+ function _isPool (
42+ IGeneralDistributionAgreementV1 gda ,
43+ ISuperfluidToken token ,
44+ address account
45+ ) view returns (bool exists ) {
46+ // solhint-disable var-name-mixedcase
47+ // @note see createPool, we retrieve the isPool bit from
48+ // UniversalIndex for this pool to determine whether the account
49+ // is a pool
50+ exists = (
51+ (uint256 (token.getAgreementStateSlot (address (gda), account, _universalIndexStateSlotId (), 1 )[0 ]) << 224 )
52+ >> 224
53+ ) & 1 == 1 ;
54+ }
55+
3556/**
3657 * @title General Distribution Agreement
3758 * @author Superfluid
@@ -41,7 +62,7 @@ import { AgreementLibrary } from "../AgreementLibrary.sol";
4162 * Agreement State
4263 *
4364 * Universal Index Data
44- * slotId = _UNIVERSAL_INDEX_STATE_SLOT_ID or 0
65+ * slotId = __universalIndexStateSlotId() or 0
4566 * msg.sender = address of GDAv1
4667 * account = context.msgSender
4768 * Universal Index Data stores a Basic Particle for an account as well as the total buffer and
@@ -103,8 +124,6 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
103124
104125 address public constant SUPERFLUID_POOL_DEPLOYER_ADDRESS = address (SuperfluidPoolDeployerLibrary);
105126
106- /// @dev Universal Index state slot id for storing universal index data
107- uint256 private constant _UNIVERSAL_INDEX_STATE_SLOT_ID = 0 ;
108127 /// @dev Pool member state slot id for storing subs bitmap
109128 uint256 private constant _POOL_SUBS_BITMAP_STATE_SLOT_ID = 1 ;
110129 /// @dev Pool member state slot id starting point for pool connections
@@ -127,7 +146,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
127146 {
128147 UniversalIndexData memory universalIndexData = _getUIndexData (abi.encode (token), account);
129148
130- if (_isPool (token, account)) {
149+ if (_isPool (this , token, account)) {
131150 rtb = ISuperfluidPool (account).getDisconnectedBalance (uint32 (time));
132151 } else {
133152 rtb = Value.unwrap (_getBasicParticleFromUIndex (universalIndexData).rtb (Time.wrap (uint32 (time))));
@@ -165,7 +184,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
165184 function getNetFlow (ISuperfluidToken token , address account ) external view override returns (int96 netFlowRate ) {
166185 netFlowRate = int256 (FlowRate.unwrap (_getUIndex (abi.encode (token), account).flow_rate ())).toInt96 ();
167186
168- if (_isPool (token, account)) {
187+ if (_isPool (this , token, account)) {
169188 netFlowRate += ISuperfluidPool (account).getTotalDisconnectedFlowRate ();
170189 }
171190
@@ -274,7 +293,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
274293 ) internal returns (ISuperfluidPool pool ) {
275294 // @note ensure if token and admin are the same that nothing funky happens with echidna
276295 if (admin == address (0 )) revert GDA_NO_ZERO_ADDRESS_ADMIN ();
277- if (_isPool (token, admin)) revert GDA_ADMIN_CANNOT_BE_POOL ();
296+ if (_isPool (this , token, admin)) revert GDA_ADMIN_CANNOT_BE_POOL ();
278297
279298 pool = ISuperfluidPool (
280299 address (
@@ -288,7 +307,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
288307 // to store whether an account is a pool or not
289308 bytes32 [] memory data = new bytes32 [](1 );
290309 data[0 ] = bytes32 (uint256 (1 ));
291- token.updateAgreementStateSlot (address (pool), _UNIVERSAL_INDEX_STATE_SLOT_ID , data);
310+ token.updateAgreementStateSlot (address (pool), _universalIndexStateSlotId () , data);
292311
293312 IPoolAdminNFT poolAdminNFT = IPoolAdminNFT (_getPoolAdminNFTAddress (token));
294313
@@ -409,7 +428,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
409428 }
410429
411430 function appendIndexUpdateByPool (ISuperfluidToken token , BasicParticle memory p , Time t ) external returns (bool ) {
412- if (_isPool (token, msg .sender ) == false ) {
431+ if (_isPool (this , token, msg .sender ) == false ) {
413432 revert GDA_ONLY_SUPER_TOKEN_POOL ();
414433 }
415434 bytes memory eff = abi.encode (token);
@@ -422,7 +441,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
422441 external
423442 returns (bool )
424443 {
425- if (_isPool (superToken, msg .sender ) == false ) {
444+ if (_isPool (this , superToken, msg .sender ) == false ) {
426445 revert GDA_ONLY_SUPER_TOKEN_POOL ();
427446 }
428447
@@ -443,7 +462,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
443462
444463 newCtx = ctx;
445464
446- if (_isPool (token, address (pool)) == false ||
465+ if (_isPool (this , token, address (pool)) == false ||
447466 // Note: we do not support multi-tokens pools
448467 pool.superToken () != token) {
449468 revert GDA_ONLY_SUPER_TOKEN_POOL ();
@@ -509,7 +528,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
509528 int96 requestedFlowRate ,
510529 bytes calldata ctx
511530 ) external override returns (bytes memory newCtx ) {
512- if (_isPool (token, address (pool)) == false ||
531+ if (_isPool (this , token, address (pool)) == false ||
513532 // Note: we do not support multi-tokens pools
514533 pool.superToken () != token) {
515534 revert GDA_ONLY_SUPER_TOKEN_POOL ();
@@ -708,7 +727,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
708727 // new buffer
709728 (universalIndexData.totalBuffer.toInt256 () + Value.unwrap (bufferDelta)).toUint256 ();
710729 ISuperfluidToken (token).updateAgreementStateSlot (
711- from, _UNIVERSAL_INDEX_STATE_SLOT_ID , _encodeUniversalIndexData (universalIndexData)
730+ from, _universalIndexStateSlotId () , _encodeUniversalIndexData (universalIndexData)
712731 );
713732
714733 {
@@ -837,7 +856,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
837856 {
838857 (, universalIndexData) = _decodeUniversalIndexData (
839858 ISuperfluidToken (abi.decode (eff, (address ))).getAgreementStateSlot (
840- address (this ), owner, _UNIVERSAL_INDEX_STATE_SLOT_ID , 2
859+ address (this ), owner, _universalIndexStateSlotId () , 2
841860 )
842861 );
843862 }
@@ -856,7 +875,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
856875 function _getUIndex (bytes memory eff , address owner ) internal view override returns (BasicParticle memory uIndex ) {
857876 (, UniversalIndexData memory universalIndexData ) = _decodeUniversalIndexData (
858877 ISuperfluidToken (abi.decode (eff, (address ))).getAgreementStateSlot (
859- address (this ), owner, _UNIVERSAL_INDEX_STATE_SLOT_ID , 2
878+ address (this ), owner, _universalIndexStateSlotId () , 2
860879 )
861880 );
862881 uIndex = _getBasicParticleFromUIndex (universalIndexData);
@@ -871,7 +890,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
871890
872891 ISuperfluidToken (abi.decode (eff, (address ))).updateAgreementStateSlot (
873892 owner,
874- _UNIVERSAL_INDEX_STATE_SLOT_ID ,
893+ _universalIndexStateSlotId () ,
875894 _encodeUniversalIndexData (p, universalIndexData.totalBuffer, universalIndexData.isPool)
876895 );
877896
@@ -989,17 +1008,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
9891008
9901009 /// @inheritdoc IGeneralDistributionAgreementV1
9911010 function isPool (ISuperfluidToken token , address account ) external view override returns (bool ) {
992- return _isPool (token, account);
993- }
994-
995- function _isPool (ISuperfluidToken token , address account ) internal view returns (bool exists ) {
996- // @note see createPool, we retrieve the isPool bit from
997- // UniversalIndex for this pool to determine whether the account
998- // is a pool
999- exists = (
1000- (uint256 (token.getAgreementStateSlot (address (this ), account, _UNIVERSAL_INDEX_STATE_SLOT_ID, 1 )[0 ]) << 224 )
1001- >> 224
1002- ) & 1 == 1 ;
1011+ return _isPool (this , token, account);
10031012 }
10041013
10051014 // FlowDistributionData data packing:
0 commit comments