Skip to content

Commit

Permalink
GDA Pool Permission (#2010)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellwolf authored Sep 6, 2024
1 parent fb6cd05 commit 6e19531
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/ethereum-contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

* `IUserDefinedMacro`: added a method `postCheck()` which allows to verify state changes after running the macro.

### Fixed

* GDA Pools are not multi-tokens ready, added a permission check (#2010).

## [v1.11.0]

### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi

newCtx = ctx;

if (_isPool(token, address(pool)) == false) {
if (_isPool(token, address(pool)) == false ||
// Note: we do not support multi-tokens pools
pool.superToken() != token) {
revert GDA_ONLY_SUPER_TOKEN_POOL();
}

Expand Down Expand Up @@ -485,7 +487,9 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
int96 requestedFlowRate,
bytes calldata ctx
) external override returns (bytes memory newCtx) {
if (_isPool(token, address(pool)) == false) {
if (_isPool(token, address(pool)) == false ||
// Note: we do not support multi-tokens pools
pool.superToken() != token) {
revert GDA_ONLY_SUPER_TOKEN_POOL();
}
if (requestedFlowRate < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ contract GeneralDistributionAgreementV1IntegrationTest is FoundrySuperfluidTeste
vm.stopPrank();
}

function testRevertDistributeFlowToPoolOfWrongToken(int96 requestedFlowRate) public {
vm.assume(requestedFlowRate >= 0);
vm.assume(requestedFlowRate < int96(type(int64).max));
ISuperToken badToken = sfDeployer.deployNativeAssetSuperToken("Super Bad", "BADx");
vm.startPrank(alice);
vm.expectRevert(IGeneralDistributionAgreementV1.GDA_ONLY_SUPER_TOKEN_POOL.selector);
badToken.distributeFlow(alice, ISuperfluidPool(bob), requestedFlowRate);
vm.stopPrank();
}

function testRevertDistributeFromAnyAddressWhenNotAllowed(bool useForwarder) public {
PoolConfig memory config = PoolConfig({ transferabilityForUnitsOwner: true, distributionFromAnyAddress: false });
ISuperfluidPool pool = _helperCreatePool(superToken, alice, alice, useForwarder, config);
Expand Down Expand Up @@ -258,6 +268,15 @@ contract GeneralDistributionAgreementV1IntegrationTest is FoundrySuperfluidTeste
vm.stopPrank();
}

function testRevertDistributeToPoolOfWrongToken(uint256 requestedAmount) public {
vm.assume(requestedAmount < uint256(type(uint128).max));
ISuperToken badToken = sfDeployer.deployNativeAssetSuperToken("Super Bad", "BADx");
vm.startPrank(alice);
vm.expectRevert(IGeneralDistributionAgreementV1.GDA_ONLY_SUPER_TOKEN_POOL.selector);
badToken.distributeToPool(alice, ISuperfluidPool(bob), requestedAmount);
vm.stopPrank();
}

function testRevertDistributeForOthers(address signer, uint256 requestedAmount) public {
ISuperfluidPool pool = _helperCreatePool(superToken, alice, alice, false, poolConfig);
vm.assume(requestedAmount < uint256(type(uint128).max));
Expand Down

0 comments on commit 6e19531

Please sign in to comment.