Skip to content

Commit

Permalink
added overloaded version of
Browse files Browse the repository at this point in the history
  • Loading branch information
d10r committed Nov 28, 2024
1 parent 3699c23 commit f1d3270
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/ethereum-contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit f1d3270

Please sign in to comment.