Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upload the files #29

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6063546
feat: upload the files
siftal Jun 27, 2023
e93be66
fix: fix an issue
siftal Jun 28, 2023
12810e6
fix: remove an extra check
siftal Jun 28, 2023
4887e77
feat: refactor lockToBondedToken to restrict usage to NFT stakers
siftal Jun 28, 2023
26d3e41
feat: refactor mergeBondedTokens to restrict usage to NFT stakers
siftal Jun 28, 2023
4d3403a
feat: remove tier mapping and add tier field to the Node struct
siftal Jun 30, 2023
350da1c
feat: change tier type from uint64 to uint8
siftal Jul 4, 2023
0a0db3f
feat: remove unnecessary getTier function
siftal Jul 4, 2023
7c4920a
fix: fix an issue
siftal Jul 4, 2023
d14feb9
feat: remove unnecessary check
siftal Jul 4, 2023
518dd50
fix: fix an issue
siftal Jul 4, 2023
eacd683
feat: change minStakeAmountPerNode to minStakeAmount
siftal Jul 5, 2023
ad192c9
feat: add setMuonNodeTire function
siftal Jul 5, 2023
01ddb15
feat: remove unnecessary check
siftal Jul 5, 2023
7e64a40
feat: set balance to zero on node exit
siftal Jul 8, 2023
2abbcee
feat: calculate not paid rewards and redistribute them in the next di…
siftal Jul 8, 2023
585f9af
style: format the code
siftal Jul 8, 2023
c62cd70
feat: add getInfo function
siftal Jul 8, 2023
5c60340
test: update tests
siftal Jul 12, 2023
ee75a25
feat: add a new getEditedNodes function
siftal Jul 17, 2023
c5c1506
feat: let DAO_ROLE to deactivate a node
siftal Jul 17, 2023
edcfd0b
feat: check the balance of the node before withdrawing the stake
siftal Jul 17, 2023
46e3368
fix: add nodes' roles
siftal Jul 18, 2023
4e7b630
feat: get response length as a parameter
siftal Jul 18, 2023
c46dd01
fix: fix an issue
siftal Jul 18, 2023
e04c7da
feat: to improve performance break the loop instead of checking the c…
siftal Jul 18, 2023
27e6e6b
feat: make the nodesList size dynamic
siftal Jul 18, 2023
012bd68
test: update tests
siftal Jul 18, 2023
2cf81c3
feat: ables DAO to pause/unpause specific functions
siftal Jul 22, 2023
3420da0
test: update tests
siftal Jul 22, 2023
c1267aa
feat: use IERC20Upgradeable instead of IERC20
siftal Jul 22, 2023
245d8a0
fix: remove an extra import
siftal Jul 22, 2023
c1bbf8c
feat: add constant for reward period
siftal Jul 22, 2023
6797572
feat: check the NFT is received
siftal Jul 22, 2023
3b3dbdd
feat: write state variables before the call
siftal Jul 22, 2023
ac0b9db
feat: add onERC721Received function
siftal Jul 23, 2023
7e3bcc7
feat: check the node exists before setting the tier
siftal Jul 23, 2023
11531bf
feat: check the node exists before setting the tier
siftal Jul 23, 2023
b1361a8
feat: update messages
siftal Jul 23, 2023
ea5925a
style: clean the code
siftal Jul 23, 2023
74de8f4
test: update tests
siftal Jul 23, 2023
5e59c8a
feat: combine lockStake and unlockStake
siftal Jul 23, 2023
12c7c18
feat: use safeTransferFrom instead of transferFrom
siftal Jul 23, 2023
544b829
feat: combine pauseFunction and unpauseFunction
siftal Jul 25, 2023
fce9c5e
fix: fix a typo
siftal Aug 14, 2023
64e6044
fix: fix a typo
siftal Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions contracts/MuonNodeStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ contract MuonNodeStaking is
// tier => maxStakeAmount
mapping(uint8 => uint256) public tiersMaxStakeAmount;

struct FunctionPauseState {
bakhshandeh marked this conversation as resolved.
Show resolved Hide resolved
bool isPaused;
}
mapping(string => FunctionPauseState) public functionPauseStates;

/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenFunctionNotPaused(string memory functionName) {
require(
!functionPauseStates[functionName].isPaused,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is calling by all of the user functions. If we define constants and use uint8 as the mapping key, it wil be more gas efficient.

uint8 public constant FUNCTION_GET_REWARD = 1;
// ... other functions

... getReward() functionNotPaused(FUNCTION_GET_REWARD)

"Function is paused."
);
_;
}

/**
* @dev Modifier that updates the reward parameters
* before all of the functions that can change the rewards.
Expand Down Expand Up @@ -191,7 +207,7 @@ contract MuonNodeStaking is
function lockToBondedToken(
address[] memory tokens,
uint256[] memory amounts
) external {
) external whenFunctionNotPaused("lockToBondedToken") {
require(
tokens.length == amounts.length,
"Mismatch in the length of arrays."
Expand Down Expand Up @@ -240,7 +256,10 @@ contract MuonNodeStaking is
* The staker must first approve the contract to transfer the tokenIdA on their behalf.
* @param tokenIdA The id of the first token to be merged.
*/
function mergeBondedTokens(uint256 tokenIdA) external {
function mergeBondedTokens(uint256 tokenIdA)
external
whenFunctionNotPaused("mergeBondedTokens")
{
require(
bondedToken.ownerOf(tokenIdA) == msg.sender,
"The sender is not the owner of the NFT."
Expand Down Expand Up @@ -337,7 +356,7 @@ contract MuonNodeStaking is
uint256 paidRewardPerToken,
bytes calldata reqId,
SchnorrSign calldata signature
) public {
) public whenFunctionNotPaused("getReward") {
require(amount > 0, "Invalid withdrawal amount.");

IMuonNodeManager.Node memory node = nodeManager.stakerAddressInfo(
Expand Down Expand Up @@ -425,7 +444,7 @@ contract MuonNodeStaking is
/**
* @dev Allows stakers to withdraw their staked amount after exiting the network and exit pending period has passed.
*/
function withdraw() public {
function withdraw() public whenFunctionNotPaused("withdraw") {
IMuonNodeManager.Node memory node = nodeManager.stakerAddressInfo(
msg.sender
);
Expand Down Expand Up @@ -466,7 +485,7 @@ contract MuonNodeStaking is
address nodeAddress,
string calldata peerId,
uint256 tokenId
) public {
) public whenFunctionNotPaused("addMuonNode") {
require(
users[msg.sender].tokenId == 0,
"You have already staked an NFT. Multiple staking is not allowed."
Expand Down Expand Up @@ -626,6 +645,24 @@ contract MuonNodeStaking is
_updateStaking(stakerAddress);
}

function pauseFunction(string memory functionName)
external
bakhshandeh marked this conversation as resolved.
Show resolved Hide resolved
onlyRole(DAO_ROLE)
{
functionPauseStates[functionName].isPaused = true;

emit Paused(functionName);
}

function unpauseFunction(string memory functionName)
external
onlyRole(DAO_ROLE)
{
functionPauseStates[functionName].isPaused = false;

emit Unpaused(functionName);
}

// ======== Events ========
event Staked(address indexed stakerAddress, uint256 amount);
event Withdrawn(address indexed stakerAddress, uint256 tokenId);
Expand All @@ -649,4 +686,6 @@ contract MuonNodeStaking is
event StakeUnlocked(address indexed stakerAddress);
event StakingTokenUpdated(address indexed token, uint256 multiplier);
event TierMaxStakeUpdated(uint8 tier, uint256 maxStakeAmount);
event Paused(string functionName);
event Unpaused(string functionName);
}