Skip to content

Commit 57979a3

Browse files
committed
some notes in GDA during review
1 parent b9f0344 commit 57979a3

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

packages/ethereum-contracts/contracts/agreements/gdav1/GeneralDistributionAgreementV1.sol

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,34 +279,44 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
279279
}
280280

281281
/// @inheritdoc IGeneralDistributionAgreementV1
282-
function updateMemberUnits(ISuperfluidPool pool, address memberAddress, uint128 newUnits, bytes calldata ctx)
282+
function updateMemberUnits(ISuperfluidPool untrustedPool, address memberAddress, uint128 newUnits, bytes calldata ctx)
283283
external
284284
override
285285
returns (bytes memory newCtx)
286286
{
287+
ISuperfluidToken token = untrustedPool.superToken();
288+
address msgSender = AgreementLibrary.authorizeTokenAccess(token, ctx).msgSender;
289+
287290
// Only the admin can update member units here
288-
if (AgreementLibrary.authorizeTokenAccess(pool.superToken(), ctx).msgSender != pool.admin()) {
291+
if (msgSender != untrustedPool.admin()) {
289292
revert GDA_NOT_POOL_ADMIN();
290293
}
291294
newCtx = ctx;
292295

293-
pool.updateMemberUnits(memberAddress, newUnits);
296+
// NOTE: In GDA.appendIndexUpdateByPool, it checks whether pool is created by the token.
297+
untrustedPool.updateMemberUnits(memberAddress, newUnits);
294298
}
295299

296300
/// @inheritdoc IGeneralDistributionAgreementV1
297-
function claimAll(ISuperfluidPool pool, address memberAddress, bytes calldata ctx)
301+
function claimAll(ISuperfluidPool untrustedPool, address memberAddress, bytes calldata ctx)
298302
external
299303
override
300304
returns (bytes memory newCtx)
301305
{
302-
AgreementLibrary.authorizeTokenAccess(pool.superToken(), ctx);
306+
ISuperfluidToken token = untrustedPool.superToken();
307+
AgreementLibrary.authorizeTokenAccess(token, ctx);
303308
newCtx = ctx;
304309

310+
// NOTE: In GDA.poolSettleClaim, it checks whether pool is created by the token.
305311
pool.claimAll(memberAddress);
306312
}
307313

308314
/// @inheritdoc IGeneralDistributionAgreementV1
309-
function connectPool(ISuperfluidPool pool, bytes calldata ctx) external override returns (bytes memory newCtx) {
315+
function connectPool(ISuperfluidPool pool, bytes calldata ctx)
316+
external
317+
override
318+
returns (bytes memory newCtx)
319+
{
310320
newCtx = ctx;
311321
_setPoolConnectionFor(pool, address(0), true /* doConnect */, ctx);
312322
}
@@ -319,6 +329,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
319329
{
320330
newCtx = ctx;
321331

332+
// NOTE: We do not allow a pool to connect to another pool.
322333
if (memberAddr == address(0) || pool.superToken().isPool(this, memberAddr)) {
323334
revert GDA_CANNOT_CONNECT_POOL();
324335
}
@@ -354,6 +365,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
354365
bool doConnect,
355366
bytes memory ctx
356367
)
368+
// _poolIsTrustedByItsSuperToken(pool) // TODO
357369
internal
358370
returns (bool success)
359371
{
@@ -404,14 +416,22 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
404416
)
405417
);
406418

419+
// NOTE: similar to Transfer, we cannot tell if it is done through tryConnect or regular connect.
407420
emit PoolConnectionUpdated(token, pool, memberAddr, doConnect, currentContext.userData);
408421
}
409422

410423
return true;
411424
}
412425

413426
/// @inheritdoc IGeneralDistributionAgreementV1
414-
function isMemberConnected(ISuperfluidPool pool, address member) external view override returns (bool) {
427+
function isMemberConnected(ISuperfluidPool pool, address member)
428+
external view override
429+
returns (bool)
430+
{
431+
// NOTE: this function is complete, in that even for invalid pools, it will always return false.
432+
//
433+
// Retrospectively, it may be more helpful to the developers if this function is non-complete, and always revert
434+
// on invalid pool.
415435
return pool.superToken().isPoolMemberConnected(this, pool, member);
416436
}
417437

@@ -427,7 +447,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
427447

428448
newCtx = ctx;
429449

430-
if (token.isPool(this, address(pool)) == false ||
450+
if (token.isPool(this, address(pool)) == false || // TODO: with _poolIsTrustedByItsSuperToken
431451
// Note: we do not support multi-tokens pools
432452
pool.superToken() != token) {
433453
revert GDA_ONLY_SUPER_TOKEN_POOL();
@@ -493,7 +513,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
493513
int96 requestedFlowRate,
494514
bytes calldata ctx
495515
) external override returns (bytes memory newCtx) {
496-
if (token.isPool(this, address(pool)) == false ||
516+
if (token.isPool(this, address(pool)) == false || // TODO _poolIsTrustedByItsSuperTokne
497517
// Note: we do not support multi-tokens pools
498518
pool.superToken() != token) {
499519
revert GDA_ONLY_SUPER_TOKEN_POOL();
@@ -602,6 +622,8 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
602622
)
603623
internal
604624
{
625+
// NOTE: the caller to guarantee that the token and pool are mutually trusted.
626+
605627
// not using oldFlowRate in this model
606628
// surprising effect: reducing flow rate may require more buffer when liquidation_period adjusted upward
607629
ISuperfluidGovernance gov = ISuperfluidGovernance(ISuperfluid(_host).getGovernance());
@@ -781,31 +803,38 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
781803

782804
function appendIndexUpdateByPool(ISuperfluidToken token, BasicParticle memory p, Time t)
783805
external
806+
// TODO _poolIsTrustedByItsSuperToken(msg.sender)
784807
returns (bool)
785808
{
786-
if (token.isPool(this, msg.sender) == false) {
809+
ISuperfluidPool untrustedPool = msg.sender;
810+
811+
if (token.isPool(this, untrustedPool) == false) {
787812
revert GDA_ONLY_SUPER_TOKEN_POOL();
788813
}
789814
bytes memory eff = abi.encode(token);
790-
_setUIndex(eff, msg.sender, _getUIndex(eff, msg.sender).mappend(p));
791-
_setPoolAdjustmentFlowRate(eff, msg.sender, true, /* doShift? */ p.flow_rate(), t);
815+
_setUIndex(eff, msg.sender, _getUIndex(eff, untrustedPool).mappend(p));
816+
_setPoolAdjustmentFlowRate(eff, untrustedPool, true, /* doShift? */ p.flow_rate(), t);
792817
return true;
793818
}
794819

795820
function poolSettleClaim(ISuperfluidToken superToken, address claimRecipient, int256 amount)
796821
external
797822
returns (bool)
798823
{
799-
if (superToken.isPool(this, msg.sender) == false) {
824+
ISuperfluidPool untrustedPool = msg.sender;
825+
826+
if (superToken.isPool(this, untrustedPool) == false) {
800827
revert GDA_ONLY_SUPER_TOKEN_POOL();
801828
}
802829

803-
_doShift(abi.encode(superToken), msg.sender, claimRecipient, Value.wrap(amount));
830+
_doShift(abi.encode(superToken), untrustedPool, claimRecipient, Value.wrap(amount));
804831
return true;
805832
}
806833

807834
function tokenEmitPseudoTransfer(ISuperfluidToken superToken, address from, address to) external {
808-
if (superToken.isPool(this, msg.sender) == false) {
835+
ISuperfluidPool untrustedPool = msg.sender;
836+
837+
if (superToken.isPool(this, untrustedPool) == false) {
809838
revert GDA_ONLY_SUPER_TOKEN_POOL();
810839
}
811840

0 commit comments

Comments
 (0)