Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
FIX: Cannot unstake 0 (#260)
Browse files Browse the repository at this point in the history
* FIX: Cannot unstake 0

* FIX: Use CannotReleaseZero

* commit rust binding

---------

Co-authored-by: auto-commit <auto-commit@users.noreply.github.com>
  • Loading branch information
aakoshh and auto-commit authored Oct 25, 2023
1 parent b1e3705 commit 7ecad9a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
38 changes: 38 additions & 0 deletions binding/src/subnet_actor_manager_facet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,15 @@ pub mod subnet_actor_manager_facet {
},
],
),
(
::std::borrow::ToOwned::to_owned("CannotReleaseZero"),
::std::vec![
::ethers::core::abi::ethabi::AbiError {
name: ::std::borrow::ToOwned::to_owned("CannotReleaseZero"),
inputs: ::std::vec![],
},
],
),
(
::std::borrow::ToOwned::to_owned("CollateralIsZero"),
::std::vec![
Expand Down Expand Up @@ -904,6 +913,19 @@ pub mod subnet_actor_manager_facet {
abi = "CannotConfirmFutureChanges()"
)]
pub struct CannotConfirmFutureChanges;
///Custom Error type `CannotReleaseZero` with signature `CannotReleaseZero()` and selector `0xc79cad7b`
#[derive(
Clone,
::ethers::contract::EthError,
::ethers::contract::EthDisplay,
Default,
Debug,
PartialEq,
Eq,
Hash,
)]
#[etherror(name = "CannotReleaseZero", abi = "CannotReleaseZero()")]
pub struct CannotReleaseZero;
///Custom Error type `CollateralIsZero` with signature `CollateralIsZero()` and selector `0xb4f18b02`
#[derive(
Clone,
Expand Down Expand Up @@ -1149,6 +1171,7 @@ pub mod subnet_actor_manager_facet {
pub enum SubnetActorManagerFacetErrors {
AddressShouldBeValidator(AddressShouldBeValidator),
CannotConfirmFutureChanges(CannotConfirmFutureChanges),
CannotReleaseZero(CannotReleaseZero),
CollateralIsZero(CollateralIsZero),
EmptyAddress(EmptyAddress),
InvalidCheckpointEpoch(InvalidCheckpointEpoch),
Expand Down Expand Up @@ -1191,6 +1214,10 @@ pub mod subnet_actor_manager_facet {
{
return Ok(Self::CannotConfirmFutureChanges(decoded));
}
if let Ok(decoded) = <CannotReleaseZero as ::ethers::core::abi::AbiDecode>::decode(data)
{
return Ok(Self::CannotReleaseZero(decoded));
}
if let Ok(decoded) = <CollateralIsZero as ::ethers::core::abi::AbiDecode>::decode(data)
{
return Ok(Self::CollateralIsZero(decoded));
Expand Down Expand Up @@ -1280,6 +1307,7 @@ pub mod subnet_actor_manager_facet {
Self::CannotConfirmFutureChanges(element) => {
::ethers::core::abi::AbiEncode::encode(element)
}
Self::CannotReleaseZero(element) => ::ethers::core::abi::AbiEncode::encode(element),
Self::CollateralIsZero(element) => ::ethers::core::abi::AbiEncode::encode(element),
Self::EmptyAddress(element) => ::ethers::core::abi::AbiEncode::encode(element),
Self::InvalidCheckpointEpoch(element) => {
Expand Down Expand Up @@ -1336,6 +1364,10 @@ pub mod subnet_actor_manager_facet {
== <CannotConfirmFutureChanges as ::ethers::contract::EthError>::selector() => {
true
}
_ if selector
== <CannotReleaseZero as ::ethers::contract::EthError>::selector() => {
true
}
_ if selector
== <CollateralIsZero as ::ethers::contract::EthError>::selector() => {
true
Expand Down Expand Up @@ -1409,6 +1441,7 @@ pub mod subnet_actor_manager_facet {
match self {
Self::AddressShouldBeValidator(element) => ::core::fmt::Display::fmt(element, f),
Self::CannotConfirmFutureChanges(element) => ::core::fmt::Display::fmt(element, f),
Self::CannotReleaseZero(element) => ::core::fmt::Display::fmt(element, f),
Self::CollateralIsZero(element) => ::core::fmt::Display::fmt(element, f),
Self::EmptyAddress(element) => ::core::fmt::Display::fmt(element, f),
Self::InvalidCheckpointEpoch(element) => ::core::fmt::Display::fmt(element, f),
Expand Down Expand Up @@ -1448,6 +1481,11 @@ pub mod subnet_actor_manager_facet {
Self::CannotConfirmFutureChanges(value)
}
}
impl ::core::convert::From<CannotReleaseZero> for SubnetActorManagerFacetErrors {
fn from(value: CannotReleaseZero) -> Self {
Self::CannotReleaseZero(value)
}
}
impl ::core::convert::From<CollateralIsZero> for SubnetActorManagerFacetErrors {
fn from(value: CollateralIsZero) -> Self {
Self::CollateralIsZero(value)
Expand Down
12 changes: 9 additions & 3 deletions src/subnet/SubnetActorManagerFacet.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.19;

import {CollateralIsZero, NotOwnerOfPublicKey, EmptyAddress, NotEnoughBalanceForRewards, NotEnoughCollateral, NotValidator, NotAllValidatorsHaveLeft, NotStakedBefore, InvalidSignatureErr, InvalidCheckpointEpoch, InvalidCheckpointMessagesHash, InvalidPublicKeyLength} from "../errors/IPCErrors.sol";
import {CollateralIsZero, CannotReleaseZero, NotOwnerOfPublicKey, EmptyAddress, NotEnoughBalanceForRewards, NotEnoughCollateral, NotValidator, NotAllValidatorsHaveLeft, NotStakedBefore, InvalidSignatureErr, InvalidCheckpointEpoch, InvalidCheckpointMessagesHash, InvalidPublicKeyLength} from "../errors/IPCErrors.sol";
import {IGateway} from "../interfaces/IGateway.sol";
import {ISubnetActor} from "../interfaces/ISubnetActor.sol";
import {BottomUpCheckpoint, CrossMsg} from "../structs/Checkpoint.sol";
Expand Down Expand Up @@ -152,10 +152,16 @@ contract SubnetActorManagerFacet is ISubnetActor, SubnetActorModifiers, Reentran
/// @notice method that allows a validator to unstake a part of its collateral from a subnet
/// @dev `leave` must be used to unstake the entire stake.
function unstake(uint256 amount) external notKilled {
if (LibStaking.totalValidatorCollateral(msg.sender) == 0) {
if (amount == 0) {
revert CannotReleaseZero();
}

uint256 collateral = LibStaking.totalValidatorCollateral(msg.sender);

if (collateral == 0) {
revert NotValidator(msg.sender);
}
if (LibStaking.totalValidatorCollateral(msg.sender) <= amount) {
if (collateral <= amount) {
revert NotEnoughCollateral();
}
if (!s.bootstrapped) {
Expand Down

0 comments on commit 7ecad9a

Please sign in to comment.