diff --git a/packages/ethereum-contracts/CHANGELOG.md b/packages/ethereum-contracts/CHANGELOG.md index 12b657a635..8240d39599 100644 --- a/packages/ethereum-contracts/CHANGELOG.md +++ b/packages/ethereum-contracts/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to the ethereum-contracts will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [UNRELEASED] + +### Added + +- `SuperTokenV1Library`: overloaded `claimAll` for the msg.sender to claim for themselves. + ## [v1.12.0] ### Added diff --git a/packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol b/packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol index b3e3788b7f..4c1d4def9b 100644 --- a/packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol +++ b/packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol @@ -1221,6 +1221,16 @@ library SuperTokenV1Library { return createPool(token, address(this)); } + /** + * @dev Claims all tokens from the pool for the msg.sender + * @param token The Super Token address. + * @param pool The Superfluid Pool to claim from. + * @return A boolean value indicating whether the claim was successful. + */ + function claimAll(ISuperToken token, ISuperfluidPool pool) internal returns (bool) { + return claimAll(token, pool, address(this), new bytes(0)); + } + /** * @dev Claims all tokens from the pool. * @param token The Super Token address. diff --git a/packages/ethereum-contracts/test/foundry/apps/SuperTokenV1Library.t.sol b/packages/ethereum-contracts/test/foundry/apps/SuperTokenV1Library.t.sol index c5bb7209df..c550cca651 100644 --- a/packages/ethereum-contracts/test/foundry/apps/SuperTokenV1Library.t.sol +++ b/packages/ethereum-contracts/test/foundry/apps/SuperTokenV1Library.t.sol @@ -119,6 +119,26 @@ contract SuperTokenV1LibraryTest is FoundrySuperfluidTester { assertEq(superToken.balanceOf(bob) - bobBalBefore, DEFAULT_AMOUNT, "distribute unexpected result"); } + function testClaimAllToMsgSender() external { + superToken.transfer(alice, DEFAULT_AMOUNT); + + uint256 balBefore = superToken.balanceOf(address(this)); + ISuperfluidPool pool = superToken.createPool(); + pool.updateMemberUnits(address(this), 1); + + vm.startPrank(alice); + // using callAgreement here because prank won't work as expected with the lib function + sf.host.callAgreement( + sf.gda, + abi.encodeCall(sf.gda.distribute, (superToken, alice, pool, DEFAULT_AMOUNT, new bytes(0))), + new bytes(0) // userData + ); + vm.stopPrank(); + + superToken.claimAll(pool); + assertEq(superToken.balanceOf(address(this)) - balBefore, DEFAULT_AMOUNT, "distribute unexpected result"); + } + function testCreatePool() external { ISuperfluidPool pool = superToken.createPool(); assertEq(pool.admin(), address(this));