Skip to content

Commit

Permalink
fix(staking): withdrawalDelay
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Jul 16, 2021
1 parent b77be1e commit f97fedf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/api/enums/error_messages.md
Expand Up @@ -31,6 +31,7 @@
* [ROLE\_NOT\_EXISTS](error_messages.md#role_not_exists)
* [ROLE\_PRECONDITION\_NOT\_MET](error_messages.md#role_precondition_not_met)
* [SIGNER\_NOT\_INITIALIZED](error_messages.md#signer_not_initialized)
* [STAKE\_WAS\_NOT\_PUT](error_messages.md#stake_was_not_put)
* [UNABLE\_TO\_OBTAIN\_PUBLIC\_KEY](error_messages.md#unable_to_obtain_public_key)
* [USER\_NOT\_LOGGED\_IN](error_messages.md#user_not_logged_in)
* [WALLET\_PROVIDER\_NOT\_SUPPORTED](error_messages.md#wallet_provider_not_supported)
Expand Down Expand Up @@ -189,6 +190,12 @@ ___

___

### STAKE\_WAS\_NOT\_PUT

**STAKE\_WAS\_NOT\_PUT**: = "Stake was not put"

___

### UNABLE\_TO\_OBTAIN\_PUBLIC\_KEY

**UNABLE\_TO\_OBTAIN\_PUBLIC\_KEY**: = "Enable to obtain public key"
Expand Down
3 changes: 2 additions & 1 deletion src/errors/ErrorMessages.ts
Expand Up @@ -28,5 +28,6 @@ export enum ERROR_MESSAGES {
CLAIM_PUBLISHER_NOT_REQUESTER = "Claim subject is not controlled by publisher",
ONCHAIN_ROLE_VERSION_NOT_SPECIFIED = "On-chain role version not specified",
CACHE_SERVER_NOT_REGISTERED = "Cache server for this chain is not registered",
WITHDRAWAL_WAS_NOT_REQUESTED = "Stake withdrawal was not requested"
WITHDRAWAL_WAS_NOT_REQUESTED = "Stake withdrawal was not requested",
STAKE_WAS_NOT_PUT = "Stake was not put"
}
10 changes: 8 additions & 2 deletions src/staking/index.ts
@@ -1,4 +1,4 @@
import { DomainReader, ResolverContractType, StakingPoolFactory__factory, StakingPool__factory, } from "@energyweb/iam-contracts";
import { DomainReader, ResolverContractType, StakingPoolFactory__factory, StakingPool__factory, WITHDRAW_DELAY, } from "@energyweb/iam-contracts";
import { StakingPool as StakingPoolContract } from "@energyweb/iam-contracts/dist/ethers-v4/StakingPool";
import { StakingPoolFactory } from "@energyweb/iam-contracts/dist/ethers-v4/StakingPoolFactory";
import { Signer, utils } from "ethers";
Expand Down Expand Up @@ -168,7 +168,13 @@ export class StakingPool {
if (status !== StakeStatus.WITHDRAWING) {
throw new Error(ERROR_MESSAGES.WITHDRAWAL_WAS_NOT_REQUESTED);
}
return new BigNumber(new Date().getTime()).sub(depositEnd);
const withdrawAvailableFrom = depositEnd.add(WITHDRAW_DELAY);
const now = new BigNumber(new Date().getTime());
if (withdrawAvailableFrom.lte(now)) {
return new BigNumber(0);
} else {
return withdrawAvailableFrom.sub(now);
}
}

/**
Expand Down

0 comments on commit f97fedf

Please sign in to comment.