Skip to content

Commit

Permalink
Added new events and unit tests for CommitManagerV2U1/StakingV2
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbraindevd committed Feb 2, 2024
1 parent feceafd commit afbe3c0
Show file tree
Hide file tree
Showing 8 changed files with 1,508 additions and 9 deletions.
6 changes: 6 additions & 0 deletions abi/Profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
"internalType": "bytes",
"name": "nodeId",
"type": "bytes"
},
{
"indexed": false,
"internalType": "address",
"name": "sharesContractAddress",
"type": "address"
}
],
"name": "ProfileCreated",
Expand Down
72 changes: 72 additions & 0 deletions abi/StakingV2.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
},
{
"inputs": [
{
"internalType": "uint256",
"name": "nowTimestamp",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "endTimestamp",
Expand Down Expand Up @@ -93,6 +98,11 @@
},
{
"inputs": [
{
"internalType": "uint256",
"name": "nowTimestamp",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "endTimestamp",
Expand Down Expand Up @@ -236,6 +246,68 @@
"name": "RewardCollected",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sharesContractAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "delegator",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "sharesBurnedAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "newTotalSupply",
"type": "uint256"
}
],
"name": "SharesBurned",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sharesContractAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "delegator",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "sharesMintedAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "newTotalSupply",
"type": "uint256"
}
],
"name": "SharesMinted",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down
4 changes: 2 additions & 2 deletions contracts/v1/Profile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {UnorderedIndexableContractDynamicSetLib} from "./utils/UnorderedIndexabl
import {ADMIN_KEY, OPERATIONAL_KEY} from "./constants/IdentityConstants.sol";

contract Profile is Named, Versioned, ContractStatus, Initializable {
event ProfileCreated(uint72 indexed identityId, bytes nodeId);
event ProfileCreated(uint72 indexed identityId, bytes nodeId, address sharesContractAddress);
event ProfileDeleted(uint72 indexed identityId);
event AskUpdated(uint72 indexed identityId, bytes nodeId, uint96 ask);

Expand Down Expand Up @@ -104,7 +104,7 @@ contract Profile is Named, Versioned, ContractStatus, Initializable {
ps.createProfile(identityId, nodeId, address(sharesContract));
_setAvailableNodeAddresses(identityId);

emit ProfileCreated(identityId, nodeId);
emit ProfileCreated(identityId, nodeId, address(sharesContract));
}

function setAsk(uint72 identityId, uint96 ask) external onlyIdentityOwner(identityId) {
Expand Down
20 changes: 18 additions & 2 deletions contracts/v2/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
uint96 oldStake,
uint96 newStake
);
event SharesMinted(
address indexed sharesContractAddress,
address indexed delegator,
uint256 sharesMintedAmount,
uint256 newTotalSupply
);
event RewardCollected(
uint72 indexed identityId,
bytes nodeId,
Expand All @@ -46,6 +52,12 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
uint256 withdrawalPeriodEnd
);
event StakeWithdrawn(uint72 indexed identityId, bytes nodeId, address indexed staker, uint96 withdrawnStakeAmount);
event SharesBurned(
address indexed sharesContractAddress,
address indexed delegator,
uint256 sharesBurnedAmount,
uint256 newTotalSupply
);
event AccumulatedOperatorFeeIncreased(
uint72 indexed identityId,
bytes nodeId,
Expand Down Expand Up @@ -144,6 +156,7 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
newStake,
withdrawalPeriodEnd
);
emit SharesBurned(address(sharesContract), msg.sender, sharesToBurn, sharesContract.totalSupply());
}

function withdrawStake(uint72 identityId) external {
Expand All @@ -158,7 +171,8 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
(stakeWithdrawalAmount, withdrawalTimestamp) = ss.withdrawalRequests(identityId, msg.sender);

if (stakeWithdrawalAmount == 0) revert StakingErrors.WithdrawalWasntInitiated();
if (withdrawalTimestamp >= block.timestamp) revert StakingErrors.WithdrawalPeriodPending(withdrawalTimestamp);
if (block.timestamp < withdrawalTimestamp)
revert StakingErrors.WithdrawalPeriodPending(block.timestamp, withdrawalTimestamp);

ss.deleteWithdrawalRequest(identityId, msg.sender);
ss.transferStake(msg.sender, stakeWithdrawalAmount);
Expand Down Expand Up @@ -232,7 +246,8 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
uint256 feeChangeDelayEnd;
(newFee, feeChangeDelayEnd) = nofcs.operatorFeeChangeRequests(identityId);

if (block.timestamp < feeChangeDelayEnd) revert StakingErrors.OperatorFeeChangeDelayPending(feeChangeDelayEnd);
if (block.timestamp < feeChangeDelayEnd)
revert StakingErrors.OperatorFeeChangeDelayPending(block.timestamp, feeChangeDelayEnd);

stakingStorage.setOperatorFee(identityId, newFee);
nofcs.deleteOperatorFeeChangeRequest(identityId);
Expand Down Expand Up @@ -269,6 +284,7 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable {
shardingTableContract.insertNode(identityId);

emit StakeIncreased(identityId, ps.getNodeId(identityId), sender, oldStake, newStake);
emit SharesMinted(address(sharesContract), sender, sharesMinted, sharesContract.totalSupply());
}

function _checkAdmin(uint72 identityId) internal view virtual {
Expand Down
4 changes: 2 additions & 2 deletions contracts/v2/errors/StakingErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pragma solidity ^0.8.16;
library StakingErrors {
error ZeroSharesAmount();
error WithdrawalWasntInitiated();
error WithdrawalPeriodPending(uint256 endTimestamp);
error WithdrawalPeriodPending(uint256 nowTimestamp, uint256 endTimestamp);
error InvalidOperatorFee();
error OperatorFeeChangeDelayPending(uint256 endTimestamp);
error OperatorFeeChangeDelayPending(uint256 nowTimestamp, uint256 endTimestamp);
error MaximumStakeExceeded(uint256 amount);
}
7 changes: 4 additions & 3 deletions test/v1/unit/Profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ describe('@v1 @unit Profile contract', function () {
const identityId1 = 1;

async function createProfile() {
await expect(Profile.createProfile(accounts[1].address, nodeId1, 'Token', 'TKN'))
.to.emit(Profile, 'ProfileCreated')
.withArgs(identityId1, nodeId1);
await expect(Profile.createProfile(accounts[1].address, nodeId1, 'Token', 'TKN')).to.emit(
Profile,
'ProfileCreated',
);
}

async function deployProfileFixture(): Promise<ProfileFixture> {
Expand Down
Loading

0 comments on commit afbe3c0

Please sign in to comment.