Skip to content

Commit

Permalink
Merge pull request #26 from ambrosus/force-unstake
Browse files Browse the repository at this point in the history
Force unstake
  • Loading branch information
SvineruS authored Dec 20, 2023
2 parents b962e5d + cbd8468 commit 55243e3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
15 changes: 15 additions & 0 deletions contracts/staking/ServerNodes_Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ contract ServerNodes_Manager is UUPSUpgradeable, IStakeManager, IOnBlockListener

// MULTISIG METHODS

function forceUnstake(address nodeAddress) public onlyRole(DEFAULT_ADMIN_ROLE) {
uint amount = stakes[nodeAddress].stake;
require(amount > 0, "nodeAddress not in stakes");

_deleteStake(nodeAddress);
stakes[nodeAddress].stake = 0;

if (validatorSet.getNodeStake(nodeAddress) > 0) // only if node already validator
validatorSet.unstake(nodeAddress, amount);

payable(stakes[nodeAddress].ownerAddress).transfer(amount);

emit StakeChanged(nodeAddress, stakes[nodeAddress].ownerAddress, - int(amount));
}

function changeMinStakeAmount(uint newMinStakeAmount) public onlyRole(DEFAULT_ADMIN_ROLE) {
minStakeAmount = newMinStakeAmount;
}
Expand Down
3 changes: 2 additions & 1 deletion deployments/16718.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@
"function changeNodeOwner(address nodeAddress, address newOwnerAddress)",
"function changeOnboardingDelay(uint256 newOnboardingDelay)",
"function changeUnstakeLockTime(uint256 newUnstakeLockTime)",
"function forceUnstake(address nodeAddress)",
"function getOnboardingWaitingList() view returns (address[])",
"function getRoleAdmin(bytes32 role) view returns (bytes32)",
"function getStakesList() view returns (address[])",
Expand Down Expand Up @@ -805,7 +806,7 @@
"deployTx": "0xa89d74036f95e5bb606cc87540319311e2a7712fb34b5cb75e9d2aa4eca97750",
"fullyQualifiedName": "contracts/staking/ServerNodes_Manager.sol:ServerNodes_Manager",
"proxy": {
"implementation": "0x44079c827dBc6cD731CA22d12Db29310E249F9bC",
"implementation": "0x14d5dA863E1d4E3eb75B460D42251a14cB8dc046",
"fullyQualifiedName": "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol:ERC1967Proxy"
}
},
Expand Down
3 changes: 2 additions & 1 deletion deployments/22040.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@
"function changeNodeOwner(address nodeAddress, address newOwnerAddress)",
"function changeOnboardingDelay(uint256 newOnboardingDelay)",
"function changeUnstakeLockTime(uint256 newUnstakeLockTime)",
"function forceUnstake(address nodeAddress)",
"function getOnboardingWaitingList() view returns (address[])",
"function getRoleAdmin(bytes32 role) view returns (bytes32)",
"function getStakesList() view returns (address[])",
Expand Down Expand Up @@ -805,7 +806,7 @@
"deployTx": "0xa7f9c2f0b9846005bd014faf75a0e312f13f901d0d2e81a81c9d3f10f50e6a52",
"fullyQualifiedName": "contracts/staking/ServerNodes_Manager.sol:ServerNodes_Manager",
"proxy": {
"implementation": "0x8F80eB85E2288acf67407f317c9237c8bD1c1687",
"implementation": "0xCeb337d76bC50E39864Ec019ee8972001F488C5A",
"fullyQualifiedName": "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol:ERC1967Proxy"
}
},
Expand Down
3 changes: 2 additions & 1 deletion deployments/30746.json
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@
"function changeNodeOwner(address nodeAddress, address newOwnerAddress)",
"function changeOnboardingDelay(uint256 newOnboardingDelay)",
"function changeUnstakeLockTime(uint256 newUnstakeLockTime)",
"function forceUnstake(address nodeAddress)",
"function getOnboardingWaitingList() view returns (address[])",
"function getRoleAdmin(bytes32 role) view returns (bytes32)",
"function getStakesList() view returns (address[])",
Expand Down Expand Up @@ -850,7 +851,7 @@
"deployTx": "0x9afda1b30db816a8f76295add9526ea7cd5ad86ed60bdf1fcaee72b2ce5db246",
"fullyQualifiedName": "contracts/staking/ServerNodes_Manager.sol:ServerNodes_Manager",
"proxy": {
"implementation": "0xb4de4aA27C9B0aa3f6A91639a572A430AD59700D",
"implementation": "0x876cd3cf5cE4023737F952586cB3399e4A704380",
"fullyQualifiedName": "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol:ERC1967Proxy"
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airdao/airdao-node-contracts",
"version": "1.2.8",
"version": "1.2.13",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"files": [
Expand Down
14 changes: 10 additions & 4 deletions src/methods/staking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Contracts } from "../contracts/contracts";
import { BigNumberish, ethers } from "ethers";
import { ContractNames } from "../contracts/names";
import {Contracts} from "../contracts/contracts";
import {BigNumberish, ethers} from "ethers";
import {ContractNames} from "../contracts/names";
import {
AirBond,
BaseNodes_Manager,
Expand All @@ -10,7 +10,7 @@ import {
Treasury,
ValidatorSet,
} from "../../typechain-types";
import { submitTransaction2 } from "./internal";
import {submitTransaction2} from "./internal";

// validator set

Expand Down Expand Up @@ -126,6 +126,12 @@ export async function serverNodesManagerGetNodesList(contracts: Contracts) {
return await serverNodes.getStakesList();
}

export async function serverNodesManagerForceUnstake(contracts: Contracts, nodeAddress: string) {
return await submitTransaction2<ServerNodes_Manager>(contracts, ContractNames.ServerNodesManager, 0,
(serverNodesManager) => serverNodesManager.forceUnstake(nodeAddress)
);
}

// rewards bank

type rewardsBankContactNames =
Expand Down

0 comments on commit 55243e3

Please sign in to comment.