Skip to content

Commit

Permalink
feat(staking): speed up tx
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Jul 27, 2021
1 parent a8be815 commit 572d9dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docs/api/globals.md
Expand Up @@ -13,6 +13,7 @@
* [Order](enums/order.md)
* [RegistrationTypes](enums/registrationtypes.md)
* [StakeStatus](enums/stakestatus.md)
* [TransactionSpeed](enums/transactionspeed.md)
* [WalletProvider](enums/walletprovider.md)

### Classes
Expand Down Expand Up @@ -69,6 +70,7 @@

### Variables

* [BASE\_TRANSACTION\_SPEED](globals.md#base_transaction_speed)
* [BigNumber](globals.md#bignumber)
* [JsonRpcProvider](globals.md#jsonrpcprovider)
* [NATS\_EXCHANGE\_TOPIC](globals.md#nats_exchange_topic)
Expand Down Expand Up @@ -215,6 +217,12 @@ Name | Type |

## Variables

### BASE\_TRANSACTION\_SPEED

`Const` **BASE\_TRANSACTION\_SPEED**: 10 = 10

___

### BigNumber

**BigNumber**: BigNumber
Expand Down
18 changes: 13 additions & 5 deletions src/staking/index.ts
Expand Up @@ -8,7 +8,9 @@ import { emptyAddress } from "../utils/constants";

const { namehash, BigNumber } = utils;

const BASE_TRANSACTION_SPEED = 10;
export enum StakeStatus { NONSTAKING = 0, STAKING = 1, WITHDRAWING = 2 }
export enum TransactionSpeed { AVERAGE = BASE_TRANSACTION_SPEED, FAST = BASE_TRANSACTION_SPEED + 3 }

export type Service = {
/** organization ENS name */
Expand Down Expand Up @@ -127,6 +129,7 @@ export class StakingPool {
async putStake(
/** stake amount */
stake: utils.BigNumber | number,
transactionSpeed = TransactionSpeed.AVERAGE
): Promise<void> {
if (typeof stake === "number") {
stake = new BigNumber(stake);
Expand All @@ -135,7 +138,8 @@ export class StakingPool {
throw new Error(ERROR_MESSAGES.INSUFFICIENT_BALANCE);
}
await (await this.pool.putStake({
value: stake
value: stake,
gasPrice: (await this.pool.provider.getGasPrice()).mul(transactionSpeed).div(BASE_TRANSACTION_SPEED)
})).wait();
}

Expand Down Expand Up @@ -178,8 +182,10 @@ export class StakingPool {
* @description Stops accumulating of the reward and prepars stake to withdraw after withdraw delay.
* Withdraw request unavailable until minimum staking period ends
*/
async requestWithdraw(): Promise<void> {
await (await this.pool.requestWithdraw()).wait();
async requestWithdraw(transactionSpeed = TransactionSpeed.AVERAGE): Promise<void> {
await (await this.pool.requestWithdraw({
gasPrice: (await this.pool.provider.getGasPrice()).mul(transactionSpeed).div(BASE_TRANSACTION_SPEED)
})).wait();
}

/**
Expand All @@ -203,8 +209,10 @@ export class StakingPool {
* @description pays back stake with accumulated reward. Withdrawn unavailable until withdrawn delay ends
* @emits StakingPool.StakeWithdrawn
*/
async withdraw(): Promise<void> {
await (await this.pool.withdraw()).wait();
async withdraw(transactionSpeed = TransactionSpeed.AVERAGE): Promise<void> {
await (await this.pool.withdraw({
gasPrice: (await this.pool.provider.getGasPrice()).mul(transactionSpeed).div(BASE_TRANSACTION_SPEED)
})).wait();
}

/**
Expand Down

0 comments on commit 572d9dd

Please sign in to comment.