Skip to content

Commit

Permalink
set commission (#2)
Browse files Browse the repository at this point in the history
update the change commission event params;
update test for set commission;
  • Loading branch information
Vitomir2 authored Apr 25, 2024
1 parent e5b98fe commit c1afcce
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion contracts/ValidatorSet/modules/Staking/IStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.17;

interface IStaking {
event NewValidator(address indexed validator, uint256[4] blsKey);
event CommissionUpdated(address indexed validator, uint256 oldCommission, uint256 newCommission);
event CommissionUpdated(address indexed validator, uint256 newCommission);
event Staked(address indexed validator, uint256 amount);
event Unstaked(address indexed validator, uint256 amount);

Expand Down
2 changes: 1 addition & 1 deletion contracts/ValidatorSet/modules/Staking/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ abstract contract Staking is

validators[validator].commission = newCommission;

emit CommissionUpdated(msg.sender, validators[msg.sender].commission, newCommission);
emit CommissionUpdated(validator, newCommission);
}

// slither-disable-next-line unused-state,naming-convention
Expand Down
3 changes: 1 addition & 2 deletions docs/ValidatorSet/ValidatorSet.md
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ event AddedToWhitelist(address indexed validator)
### CommissionUpdated

```solidity
event CommissionUpdated(address indexed validator, uint256 oldCommission, uint256 newCommission)
event CommissionUpdated(address indexed validator, uint256 newCommission)
```


Expand All @@ -1079,7 +1079,6 @@ event CommissionUpdated(address indexed validator, uint256 oldCommission, uint25
| Name | Type | Description |
|---|---|---|
| validator `indexed` | address | undefined |
| oldCommission | uint256 | undefined |
| newCommission | uint256 | undefined |

### Delegated
Expand Down
3 changes: 1 addition & 2 deletions docs/ValidatorSet/modules/Staking/IStaking.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Unstakes amount for sender. Claims rewards beforehand.
### CommissionUpdated

```solidity
event CommissionUpdated(address indexed validator, uint256 oldCommission, uint256 newCommission)
event CommissionUpdated(address indexed validator, uint256 newCommission)
```


Expand All @@ -106,7 +106,6 @@ event CommissionUpdated(address indexed validator, uint256 oldCommission, uint25
| Name | Type | Description |
|---|---|---|
| validator `indexed` | address | undefined |
| oldCommission | uint256 | undefined |
| newCommission | uint256 | undefined |

### NewValidator
Expand Down
3 changes: 1 addition & 2 deletions docs/ValidatorSet/modules/Staking/Staking.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ event AddedToWhitelist(address indexed validator)
### CommissionUpdated

```solidity
event CommissionUpdated(address indexed validator, uint256 oldCommission, uint256 newCommission)
event CommissionUpdated(address indexed validator, uint256 newCommission)
```


Expand All @@ -634,7 +634,6 @@ event CommissionUpdated(address indexed validator, uint256 oldCommission, uint25
| Name | Type | Description |
|---|---|---|
| validator `indexed` | address | undefined |
| oldCommission | uint256 | undefined |
| newCommission | uint256 | undefined |

### Initialized
Expand Down
9 changes: 7 additions & 2 deletions test/ValidatorSet/ValidatorSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,15 @@ describe("ValidatorSet", function () {
it("should set commission", async function () {
const { validatorSet } = await loadFixture(this.fixtures.withdrawableFixture);

await validatorSet.connect(this.signers.validators[0]).setCommission(MAX_COMMISSION.div(2));
// set commission and verify event
const newCommission = MAX_COMMISSION.div(2);
await expect(validatorSet.connect(this.signers.validators[0]).setCommission(newCommission))
.to.emit(validatorSet, "CommissionUpdated")
.withArgs(this.signers.validators[0].address, newCommission);

// get the update validator and ensure that the new commission is set
const validator = await validatorSet.getValidator(this.signers.validators[0].address);
expect(validator.commission).to.equal(MAX_COMMISSION.div(2));
expect(validator.commission).to.equal(newCommission);
});
});
});
Expand Down

0 comments on commit c1afcce

Please sign in to comment.