Skip to content

Commit

Permalink
Coverage to 99%
Browse files Browse the repository at this point in the history
  • Loading branch information
pouya-eghbali committed Mar 16, 2024
1 parent 3cc2679 commit a0a9754
Show file tree
Hide file tree
Showing 3 changed files with 358 additions and 36 deletions.
30 changes: 16 additions & 14 deletions contracts/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
eip712Transfer.from,
eip712Transfer.to,
eip712Transfer.amount,
keccak256(abi.encode(eip712Transfer.nonces))
keccak256(abi.encodePacked(eip712Transfer.nonces))
)
);
}
Expand Down Expand Up @@ -865,7 +865,7 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
* @return The address of the signer set by the staker.
*/
function stakerToSigner(address staker) external view returns (address) {
return _signerToStaker[staker];
return _stakerToSigner[staker];
}

/**
Expand All @@ -891,10 +891,6 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
for (uint i = 0; i < eip712Slashes.length; i++) {
EIP712Slash memory eip712Slash = eip712Slashes[i];

if (_incidentTracker[eip712Slash.incident]) {
continue;
}

EIP712SlashKey memory slashKey = EIP712SlashKey(
eip712Slash.accused,
eip712Slash.amount,
Expand Down Expand Up @@ -936,9 +932,11 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
revert InvalidSignature(i);
}

slashData.info.amount = eip712Slash.amount;
slashData.info.accused = eip712Slash.accused;
slashData.info.incident = eip712Slash.incident;
slashData.info.voted += userStake.amount;
slashData.accusers[eip712Slash.accuser] = true;
slashData.info.incident = eip712Slash.incident;

emit Accused(
eip712Slash.accused,
Expand All @@ -948,6 +946,10 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
eip712Slash.incident
);

if (_incidentTracker[eip712Slash.incident]) {
continue;
}

if (slashData.info.voted >= threshold) {
_incidentTracker[eip712Slash.incident] = true;
slashData.info.slashed = true;
Expand Down Expand Up @@ -1047,10 +1049,6 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
for (uint i = 0; i < eip712SetParams.length; i++) {
EIP712SetParams memory eip712SetParam = eip712SetParams[i];

if (_setParamsTracker[eip712SetParam.nonce]) {
continue;
}

EIP712SetParamsKey memory key = EIP712SetParamsKey(
eip712SetParam.token,
eip712SetParam.nft,
Expand Down Expand Up @@ -1107,6 +1105,10 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {

emit VotedForParams(eip712SetParam.requester, eip712SetParam.nonce);

if (_setParamsTracker[eip712SetParam.nonce]) {
continue;
}

if (setParamsData.info.voted >= threshold) {
_setParamsTracker[eip712SetParam.nonce] = true;

Expand Down Expand Up @@ -1137,7 +1139,7 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
* @return ParamsInfo The detailed information of the requested set parameters operation.
*/
function getSetParamsData(
EIP712SetParams memory key
EIP712SetParamsKey memory key
) external view returns (ParamsInfo memory) {
bytes32 eipHash = hash(key);
Params storage setParamsData = _setParams[eipHash];
Expand Down Expand Up @@ -1173,7 +1175,7 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
* @return A boolean indicating whether the address has already requested the set of parameters.
*/
function getHasRequestedSetParams(
EIP712SetParams memory key,
EIP712SetParamsKey memory key,
address requester
) external view returns (bool) {
bytes32 eipHash = hash(key);
Expand All @@ -1188,7 +1190,7 @@ contract UnchainedStaking is Ownable, IERC721Receiver, ReentrancyGuard {
* the aggregate voting power at the current state.
* @return The total voting power from all staked tokens.
*/
function totalVotingPower() external view returns (uint256) {
function getTotalVotingPower() external view returns (uint256) {
return _totalVotingPower;
}

Expand Down
42 changes: 21 additions & 21 deletions docs/UnchainedStaking.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function getConsensusThreshold() external view returns (uint256)
### getHasRequestedSetParams

```solidity
function getHasRequestedSetParams(UnchainedStaking.EIP712SetParams key, address requester) external view returns (bool)
function getHasRequestedSetParams(UnchainedStaking.EIP712SetParamsKey key, address requester) external view returns (bool)
```


Expand All @@ -118,7 +118,7 @@ function getHasRequestedSetParams(UnchainedStaking.EIP712SetParams key, address

| Name | Type | Description |
|---|---|---|
| key | UnchainedStaking.EIP712SetParams | undefined |
| key | UnchainedStaking.EIP712SetParamsKey | undefined |
| requester | address | undefined |

#### Returns
Expand Down Expand Up @@ -170,7 +170,7 @@ function getParams() external view returns (struct UnchainedStaking.ParamsInfo)
### getSetParamsData

```solidity
function getSetParamsData(UnchainedStaking.EIP712SetParams key) external view returns (struct UnchainedStaking.ParamsInfo)
function getSetParamsData(UnchainedStaking.EIP712SetParamsKey key) external view returns (struct UnchainedStaking.ParamsInfo)
```


Expand All @@ -181,7 +181,7 @@ function getSetParamsData(UnchainedStaking.EIP712SetParams key) external view re

| Name | Type | Description |
|---|---|---|
| key | UnchainedStaking.EIP712SetParams | undefined |
| key | UnchainedStaking.EIP712SetParamsKey | undefined |

#### Returns

Expand Down Expand Up @@ -211,6 +211,23 @@ function getSlashData(UnchainedStaking.EIP712SlashKey key) external view returns
|---|---|---|
| _0 | UnchainedStaking.SlashInfo | undefined |

### getTotalVotingPower

```solidity
function getTotalVotingPower() external view returns (uint256)
```



*Returns the total voting power represented by the sum of all staked tokens. Voting power is used in governance decisions, including the slashing process, where it determines the weight of a participant&#39;s vote. This function provides the aggregate voting power at the current state.*


#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | The total voting power from all staked tokens. |

### increaseStake

```solidity
Expand Down Expand Up @@ -496,23 +513,6 @@ function stakerToSigner(address staker) external view returns (address)
|---|---|---|
| _0 | address | The address of the signer set by the staker. |

### totalVotingPower

```solidity
function totalVotingPower() external view returns (uint256)
```



*Returns the total voting power represented by the sum of all staked tokens. Voting power is used in governance decisions, including the slashing process, where it determines the weight of a participant&#39;s vote. This function provides the aggregate voting power at the current state.*


#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | The total voting power from all staked tokens. |

### transfer

```solidity
Expand Down
Loading

0 comments on commit a0a9754

Please sign in to comment.