Skip to content

Commit a372599

Browse files
authored
Feat/adjustments (#107)
* return rewards while claim all * made is whitelisted methods internal * bumped version
1 parent 7dc446e commit a372599

File tree

9 files changed

+54
-24
lines changed

9 files changed

+54
-24
lines changed

contracts/access/MerkleWhitelisted.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,35 @@ abstract contract MerkleWhitelisted {
2424

2525
modifier onlyWhitelisted(bytes memory data_, bytes32[] memory merkleProof_) {
2626
require(
27-
isWhitelisted(keccak256(data_), merkleProof_),
27+
_isWhitelisted(keccak256(data_), merkleProof_),
2828
"MerkleWhitelisted: not whitelisted"
2929
);
3030
_;
3131
}
3232

3333
modifier onlyWhitelistedUser(address user_, bytes32[] memory merkleProof_) {
34-
require(isWhitelistedUser(user_, merkleProof_), "MerkleWhitelisted: not whitelisted");
34+
require(_isWhitelistedUser(user_, merkleProof_), "MerkleWhitelisted: not whitelisted");
3535
_;
3636
}
3737

38+
/**
39+
* @notice The function to get the current Merkle root
40+
* @return the current Merkle root or zero bytes if it has not been set
41+
*/
42+
function getMerkleRoot() public view returns (bytes32) {
43+
return _merkleRoot;
44+
}
45+
3846
/**
3947
* @notice The function to check if the leaf belongs to the Merkle tree
4048
* @param leaf_ the leaf to be checked
4149
* @param merkleProof_ the path from the leaf to the Merkle tree root
4250
* @return true if the leaf belongs to the Merkle tree, false otherwise
4351
*/
44-
function isWhitelisted(
52+
function _isWhitelisted(
4553
bytes32 leaf_,
4654
bytes32[] memory merkleProof_
47-
) public view returns (bool) {
55+
) internal view returns (bool) {
4856
return merkleProof_.verify(_merkleRoot, leaf_);
4957
}
5058

@@ -54,19 +62,11 @@ abstract contract MerkleWhitelisted {
5462
* @param merkleProof_ the path from the user to the Merkle tree root
5563
* @return true if the user belongs to the Merkle tree, false otherwise
5664
*/
57-
function isWhitelistedUser(
65+
function _isWhitelistedUser(
5866
address user_,
5967
bytes32[] memory merkleProof_
60-
) public view returns (bool) {
61-
return isWhitelisted(keccak256(abi.encodePacked(user_)), merkleProof_);
62-
}
63-
64-
/**
65-
* @notice The function to get the current Merkle root
66-
* @return the current Merkle root or zero bytes if it has not been set
67-
*/
68-
function getMerkleRoot() public view returns (bytes32) {
69-
return _merkleRoot;
68+
) internal view returns (bool) {
69+
return _isWhitelisted(keccak256(abi.encodePacked(user_)), merkleProof_);
7070
}
7171

7272
/**

contracts/finance/staking/AbstractStaking.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ abstract contract AbstractStaking is AbstractValueDistributor, Initializable {
9191

9292
/**
9393
* @notice Claims all the available rewards.
94+
* @return The total value of the rewards claimed.
9495
*/
95-
function claimAll() public stakingStarted {
96-
_distributeAllValue(msg.sender);
96+
function claimAll() public stakingStarted returns (uint256) {
97+
return _distributeAllValue(msg.sender);
9798
}
9899

99100
/**

contracts/finance/staking/AbstractValueDistributor.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ abstract contract AbstractValueDistributor {
145145
/**
146146
* @notice Distributes all the available value to a specific user.
147147
* @param user_ The address of the user.
148+
* @return The amount of value distributed.
148149
*/
149-
function _distributeAllValue(address user_) internal virtual {
150+
function _distributeAllValue(address user_) internal virtual returns (uint256) {
150151
_update(user_);
151152

152153
UserDistribution storage _userDist = _userDistributions[user_];
@@ -155,11 +156,13 @@ abstract contract AbstractValueDistributor {
155156

156157
require(amount_ > 0, "ValueDistributor: amount has to be more than 0");
157158

158-
_userDist.owedValue -= amount_;
159+
delete _userDist.owedValue;
159160

160161
emit ValueDistributed(user_, amount_);
161162

162163
_afterDistributeValue(user_, amount_);
164+
165+
return amount_;
163166
}
164167

165168
/**

contracts/mock/access/MerkleWhitelistedMock.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ contract MerkleWhitelistedMock is MerkleWhitelisted {
2020
emit WhitelistedUser();
2121
}
2222

23+
function isWhitelisted(
24+
bytes32 leaf_,
25+
bytes32[] memory merkleProof_
26+
) internal view returns (bool) {
27+
return _isWhitelisted(leaf_, merkleProof_);
28+
}
29+
30+
function isWhitelistedUser(
31+
address user_,
32+
bytes32[] memory merkleProof_
33+
) internal view returns (bool) {
34+
return _isWhitelistedUser(user_, merkleProof_);
35+
}
36+
2337
function setMerkleRoot(bytes32 merkleRoot_) external {
2438
_setMerkleRoot(merkleRoot_);
2539
}

contracts/mock/finance/staking/AbstractValueDistributorMock.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ contract AbstractValueDistributorMock is AbstractValueDistributor, Multicall {
1919
_distributeValue(user_, amount_);
2020
}
2121

22-
function distributeAllValue(address user_) external {
23-
_distributeAllValue(user_);
22+
function distributeAllValue(address user_) external returns (uint256) {
23+
return _distributeAllValue(user_);
2424
}
2525

2626
function userShares(address user_) external view returns (uint256) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solarity/solidity-lib",
3-
"version": "2.7.9",
3+
"version": "2.7.10",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"readme": "README.md",

test/finance/staking/AbstractStaking.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ describe("AbstractStaking", () => {
624624
const secondOwed = await abstractStaking.getOwedValue(SECOND);
625625
const thirdOwed = await abstractStaking.getOwedValue(THIRD);
626626

627+
expect(await abstractStaking.connect(FIRST).claimAll.staticCall()).to.eq(firstOwed);
628+
expect(await abstractStaking.connect(SECOND).claimAll.staticCall()).to.eq(secondOwed);
629+
expect(await abstractStaking.connect(THIRD).claimAll.staticCall()).to.eq(thirdOwed);
630+
627631
await abstractStaking.connect(FIRST).claimAll();
628632
await abstractStaking.connect(SECOND).claimAll();
629633

test/finance/staking/AbstractValueDistributor.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ describe("AbstractValueDistributor", () => {
231231
it("should distribute all the owed values optimally", async () => {
232232
await performSharesManipulations();
233233

234+
const firstOwed = await abstractValueDistributor.getOwedValue(FIRST);
235+
const secondOwed = await abstractValueDistributor.getOwedValue(SECOND);
236+
const thirdOwed = await abstractValueDistributor.getOwedValue(THIRD);
237+
238+
expect(await abstractValueDistributor.distributeAllValue.staticCall(FIRST)).to.eq(firstOwed);
239+
expect(await abstractValueDistributor.distributeAllValue.staticCall(SECOND)).to.eq(secondOwed);
240+
expect(await abstractValueDistributor.distributeAllValue.staticCall(THIRD)).to.eq(thirdOwed);
241+
234242
await abstractValueDistributor.distributeAllValue(FIRST);
235243
await abstractValueDistributor.distributeAllValue(SECOND);
236244
await abstractValueDistributor.distributeAllValue(THIRD);

0 commit comments

Comments
 (0)