Skip to content

Commit

Permalink
Merge pull request #78 from hats-finance/fix-48
Browse files Browse the repository at this point in the history
Fix #48
  • Loading branch information
jellegerbrandy authored Dec 4, 2023
2 parents f2a4d00 + 0c9ab41 commit aebfd25
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contracts/HATPaymentSplitterFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ contract HATPaymentSplitterFactory {
address public immutable implementation;
event HATPaymentSplitterCreated(address indexed _hatPaymentSplitter);

error ArrayLengthMismatch();
error NoPayees();
error ZeroAddress();
error ZeroShares();
error DuplicatedPayee();

constructor (address _implementation) {
implementation = _implementation;
}
Expand All @@ -21,6 +27,17 @@ contract HATPaymentSplitterFactory {
}

function predictSplitterAddress(address[] memory _payees, uint256[] memory _shares) public view returns (address) {
if (_payees.length != _shares.length) revert ArrayLengthMismatch();
if (_payees.length == 0) revert NoPayees();

for (uint256 i = 0; i < _payees.length; i++) {
if (_payees[i] == address(0)) revert ZeroAddress();
if (_shares[i] == 0) revert ZeroShares();
for (uint256 j = i + 1; j < _payees.length; j++) {
if (_payees[i] == _payees[j]) revert DuplicatedPayee();
}
}

return Clones.predictDeterministicAddress(implementation, keccak256(abi.encodePacked(_payees, _shares)));
}
}
58 changes: 58 additions & 0 deletions docs/dodoc/HATPaymentSplitterFactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,61 @@ event HATPaymentSplitterCreated(address indexed _hatPaymentSplitter)



## Errors

### ArrayLengthMismatch

```solidity
error ArrayLengthMismatch()
```






### DuplicatedPayee

```solidity
error DuplicatedPayee()
```






### NoPayees

```solidity
error NoPayees()
```






### ZeroAddress

```solidity
error ZeroAddress()
```






### ZeroShares

```solidity
error ZeroShares()
```







55 changes: 55 additions & 0 deletions test/hatvaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5477,6 +5477,61 @@ it("getVaultReward - no vault updates will return 0 ", async () => {
);
});

it("hatpaymentsplitter predict bad splitter", async () => {
let hatPaymentSplitterImplementation = await HATPaymentSplitter.new();
let hatPaymentSplitterFactory = await HATPaymentSplitterFactory.new(hatPaymentSplitterImplementation.address);

try {
await hatPaymentSplitterFactory.predictSplitterAddress(
[accounts[2], accounts[3]],
[5000]
);
assert(false, "array length mismatch");
} catch (ex) {
assertVMException(ex, "ArrayLengthMismatch");
}

try {
await hatPaymentSplitterFactory.predictSplitterAddress(
[],
[]
);
assert(false, "no payees");
} catch (ex) {
assertVMException(ex, "NoPayees");
}

try {
await hatPaymentSplitterFactory.predictSplitterAddress(
[ZERO_ADDRESS],
[5000]
);
assert(false, "zero address");
} catch (ex) {
assertVMException(ex, "ZeroAddress");
}

try {
await hatPaymentSplitterFactory.predictSplitterAddress(
[accounts[2]],
[0]
);
assert(false, "zero shares");
} catch (ex) {
assertVMException(ex, "ZeroShares");
}

try {
await hatPaymentSplitterFactory.predictSplitterAddress(
[accounts[2], accounts[2]],
[5000, 2000]
);
assert(false, "dulpicated payee");
} catch (ex) {
assertVMException(ex, "DuplicatedPayee");
}
});

it("hatpaymentsplitter withdraw from tokenlock", async () => {
await setUpGlobalVars(accounts, 0, 8000, [8000, 2000, 0], [550, 450]);
var staker = accounts[4];
Expand Down

0 comments on commit aebfd25

Please sign in to comment.