@human-protocol/sdk 3.0.6 → 3.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +1 -24
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +23 -64
- package/dist/encryption.d.ts +6 -4
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +52 -16
- package/dist/escrow.d.ts +20 -57
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +74 -88
- package/dist/graphql/queries/operator.js +2 -2
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +0 -2
- package/dist/graphql/queries/transaction.d.ts.map +1 -1
- package/dist/graphql/queries/transaction.js +23 -10
- package/dist/graphql/types.d.ts +0 -2
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/interfaces.d.ts +19 -10
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +1 -1
- package/dist/kvstore.js +1 -1
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +13 -0
- package/dist/staking.d.ts +3 -112
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +2 -170
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +3 -1
- package/dist/storage.js +17 -7
- package/dist/types.d.ts +17 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/constants.ts +23 -64
- package/src/encryption.ts +47 -15
- package/src/escrow.ts +119 -103
- package/src/graphql/queries/operator.ts +2 -2
- package/src/graphql/queries/statistics.ts +0 -2
- package/src/graphql/queries/transaction.ts +23 -13
- package/src/graphql/types.ts +0 -2
- package/src/interfaces.ts +19 -11
- package/src/kvstore.ts +1 -1
- package/src/operator.ts +21 -0
- package/src/staking.ts +2 -185
- package/src/statistics.ts +3 -1
- package/src/types.ts +18 -4
package/src/staking.ts
CHANGED
|
@@ -3,8 +3,6 @@ import {
|
|
|
3
3
|
EscrowFactory__factory,
|
|
4
4
|
HMToken,
|
|
5
5
|
HMToken__factory,
|
|
6
|
-
RewardPool,
|
|
7
|
-
RewardPool__factory,
|
|
8
6
|
Staking,
|
|
9
7
|
Staking__factory,
|
|
10
8
|
} from '@human-protocol/core/typechain-types';
|
|
@@ -23,7 +21,6 @@ import {
|
|
|
23
21
|
ErrorProviderDoesNotExist,
|
|
24
22
|
ErrorUnsupportedChainID,
|
|
25
23
|
} from './error';
|
|
26
|
-
import { IAllocation } from './interfaces';
|
|
27
24
|
import { NetworkData } from './types';
|
|
28
25
|
import { throwError } from './utils';
|
|
29
26
|
|
|
@@ -100,13 +97,12 @@ export class StakingClient extends BaseEthersClient {
|
|
|
100
97
|
public tokenContract: HMToken;
|
|
101
98
|
public stakingContract: Staking;
|
|
102
99
|
public escrowFactoryContract: EscrowFactory;
|
|
103
|
-
public rewardPoolContract: RewardPool;
|
|
104
100
|
|
|
105
101
|
/**
|
|
106
102
|
* **StakingClient constructor**
|
|
107
103
|
*
|
|
108
104
|
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
109
|
-
* @param {NetworkData}
|
|
105
|
+
* @param {NetworkData} networkData - The network information required to connect to the Staking contract
|
|
110
106
|
*/
|
|
111
107
|
constructor(runner: ContractRunner, networkData: NetworkData) {
|
|
112
108
|
super(runner, networkData);
|
|
@@ -125,18 +121,12 @@ export class StakingClient extends BaseEthersClient {
|
|
|
125
121
|
networkData.hmtAddress,
|
|
126
122
|
runner
|
|
127
123
|
);
|
|
128
|
-
|
|
129
|
-
this.rewardPoolContract = RewardPool__factory.connect(
|
|
130
|
-
networkData.rewardPoolAddress,
|
|
131
|
-
this.runner
|
|
132
|
-
);
|
|
133
124
|
}
|
|
134
125
|
|
|
135
126
|
/**
|
|
136
127
|
* Creates an instance of StakingClient from a Runner.
|
|
137
128
|
*
|
|
138
129
|
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
139
|
-
* @param {number | undefined} gasPriceMultiplier - The multiplier to apply to the gas price
|
|
140
130
|
*
|
|
141
131
|
* @returns {Promise<StakingClient>} - An instance of StakingClient
|
|
142
132
|
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
@@ -360,7 +350,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
360
350
|
*
|
|
361
351
|
* @param {string} slasher Wallet address from who requested the slash
|
|
362
352
|
* @param {string} staker Wallet address from who is going to be slashed
|
|
363
|
-
* @param {string} escrowAddress Address of the escrow
|
|
353
|
+
* @param {string} escrowAddress Address of the escrow that the slash is made
|
|
364
354
|
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
365
355
|
* @param {bigint} amount Amount in WEI of tokens to unstake.
|
|
366
356
|
* @returns Returns void if successful. Throws error if any.
|
|
@@ -425,177 +415,4 @@ export class StakingClient extends BaseEthersClient {
|
|
|
425
415
|
return throwError(e);
|
|
426
416
|
}
|
|
427
417
|
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* This function allocates a portion of the staked tokens to a specific escrow.
|
|
431
|
-
*
|
|
432
|
-
* > Must have tokens staked
|
|
433
|
-
*
|
|
434
|
-
* @param {string} escrowAddress Address of the escrow contract to allocate in.
|
|
435
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
436
|
-
* @param {bigint} amount Amount in WEI of tokens to allocate.
|
|
437
|
-
* @returns Returns void if successful. Throws error if any.
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
* **Code example**
|
|
441
|
-
*
|
|
442
|
-
* ```ts
|
|
443
|
-
* import { ethers, Wallet, providers } from 'ethers';
|
|
444
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
445
|
-
*
|
|
446
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
447
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
448
|
-
*
|
|
449
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
450
|
-
* const signer = new Wallet(privateKey, provider);
|
|
451
|
-
* const stakingClient = await StakingClient.build(signer);
|
|
452
|
-
*
|
|
453
|
-
* const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI
|
|
454
|
-
* await stakingClient.allocate('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount);
|
|
455
|
-
* ```
|
|
456
|
-
*/
|
|
457
|
-
@requiresSigner
|
|
458
|
-
public async allocate(
|
|
459
|
-
escrowAddress: string,
|
|
460
|
-
amount: bigint,
|
|
461
|
-
txOptions: Overrides = {}
|
|
462
|
-
): Promise<void> {
|
|
463
|
-
if (typeof amount !== 'bigint') {
|
|
464
|
-
throw ErrorInvalidStakingValueType;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
if (amount < 0n) {
|
|
468
|
-
throw ErrorInvalidStakingValueSign;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
await this.checkValidEscrow(escrowAddress);
|
|
472
|
-
|
|
473
|
-
try {
|
|
474
|
-
await (
|
|
475
|
-
await this.stakingContract.allocate(escrowAddress, amount, txOptions)
|
|
476
|
-
).wait();
|
|
477
|
-
return;
|
|
478
|
-
} catch (e) {
|
|
479
|
-
return throwError(e);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* This function drops the allocation from a specific escrow.
|
|
485
|
-
*
|
|
486
|
-
* > The escrow must have allocation
|
|
487
|
-
* > The escrow must be cancelled or completed.
|
|
488
|
-
*
|
|
489
|
-
* @param {string} escrowAddress Address of the escrow contract to close allocation from.
|
|
490
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
491
|
-
* @returns Returns void if successful. Throws error if any.
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* **Code example**
|
|
495
|
-
*
|
|
496
|
-
* ```ts
|
|
497
|
-
* import { Wallet, providers } from 'ethers';
|
|
498
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
499
|
-
*
|
|
500
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
501
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
502
|
-
*
|
|
503
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
504
|
-
* const signer = new Wallet(privateKey, provider);
|
|
505
|
-
* const stakingClient = await StakingClient.build(signer);
|
|
506
|
-
*
|
|
507
|
-
* await stakingClient.closeAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
508
|
-
* ```
|
|
509
|
-
*/
|
|
510
|
-
@requiresSigner
|
|
511
|
-
public async closeAllocation(
|
|
512
|
-
escrowAddress: string,
|
|
513
|
-
txOptions: Overrides = {}
|
|
514
|
-
): Promise<void> {
|
|
515
|
-
await this.checkValidEscrow(escrowAddress);
|
|
516
|
-
|
|
517
|
-
try {
|
|
518
|
-
await (
|
|
519
|
-
await this.stakingContract.closeAllocation(escrowAddress, txOptions)
|
|
520
|
-
).wait();
|
|
521
|
-
return;
|
|
522
|
-
} catch (e) {
|
|
523
|
-
return throwError(e);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* This function drops the allocation from a specific escrow.
|
|
529
|
-
*
|
|
530
|
-
* > The escrow must have rewards added
|
|
531
|
-
*
|
|
532
|
-
* @param {string} escrowAddress Escrow address from which rewards are distributed.
|
|
533
|
-
* @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
|
|
534
|
-
* @returns Returns void if successful. Throws error if any.
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* **Code example**
|
|
538
|
-
*
|
|
539
|
-
* ```ts
|
|
540
|
-
* import { Wallet, providers } from 'ethers';
|
|
541
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
542
|
-
*
|
|
543
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
544
|
-
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
545
|
-
*
|
|
546
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
547
|
-
* const signer = new Wallet(privateKey, provider);
|
|
548
|
-
* const stakingClient = await StakingClient.build(signer);
|
|
549
|
-
*
|
|
550
|
-
* await stakingClient.distributeReward('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
551
|
-
* ```
|
|
552
|
-
*/
|
|
553
|
-
@requiresSigner
|
|
554
|
-
public async distributeReward(
|
|
555
|
-
escrowAddress: string,
|
|
556
|
-
txOptions: Overrides = {}
|
|
557
|
-
): Promise<void> {
|
|
558
|
-
await this.checkValidEscrow(escrowAddress);
|
|
559
|
-
|
|
560
|
-
try {
|
|
561
|
-
(
|
|
562
|
-
await this.rewardPoolContract.distributeReward(escrowAddress, txOptions)
|
|
563
|
-
).wait();
|
|
564
|
-
return;
|
|
565
|
-
} catch (e) {
|
|
566
|
-
return throwError(e);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* This function returns information about the allocation of the specified escrow.
|
|
572
|
-
*
|
|
573
|
-
* @param {string} escrowAddress Escrow address from which we want to get allocation information.
|
|
574
|
-
* @returns {IAllocation} Returns allocation info if exists.
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
* **Code example**
|
|
578
|
-
*
|
|
579
|
-
* ```ts
|
|
580
|
-
* import { StakingClient } from '@human-protocol/sdk';
|
|
581
|
-
* import { providers } from 'ethers';
|
|
582
|
-
*
|
|
583
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
584
|
-
*
|
|
585
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
586
|
-
* const stakingClient = await StakingClient.build(provider);
|
|
587
|
-
*
|
|
588
|
-
* const allocationInfo = await stakingClient.getAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
589
|
-
* ```
|
|
590
|
-
*/
|
|
591
|
-
public async getAllocation(escrowAddress: string): Promise<IAllocation> {
|
|
592
|
-
await this.checkValidEscrow(escrowAddress);
|
|
593
|
-
|
|
594
|
-
try {
|
|
595
|
-
const result = await this.stakingContract.getAllocation(escrowAddress);
|
|
596
|
-
return result;
|
|
597
|
-
} catch (e) {
|
|
598
|
-
return throwError(e);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
418
|
}
|
package/src/statistics.ts
CHANGED
|
@@ -149,7 +149,9 @@ export class StatisticsClient {
|
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
return {
|
|
152
|
-
totalEscrows:
|
|
152
|
+
totalEscrows: escrowStatistics?.totalEscrowCount
|
|
153
|
+
? +escrowStatistics.totalEscrowCount
|
|
154
|
+
: 0,
|
|
153
155
|
dailyEscrowsData: eventDayDatas.map((eventDayData) => ({
|
|
154
156
|
timestamp: new Date(+eventDayData.timestamp * 1000),
|
|
155
157
|
escrowsTotal: +eventDayData.dailyEscrowCount,
|
package/src/types.ts
CHANGED
|
@@ -115,10 +115,6 @@ export type NetworkData = {
|
|
|
115
115
|
* Staking contract address
|
|
116
116
|
*/
|
|
117
117
|
stakingAddress: string;
|
|
118
|
-
/**
|
|
119
|
-
* RewardPool contract address
|
|
120
|
-
*/
|
|
121
|
-
rewardPoolAddress: string;
|
|
122
118
|
/**
|
|
123
119
|
* KVStore contract address
|
|
124
120
|
*/
|
|
@@ -154,3 +150,21 @@ export type EscrowCancel = {
|
|
|
154
150
|
*/
|
|
155
151
|
amountRefunded: bigint;
|
|
156
152
|
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Represents the response data for an escrow withdrawal.
|
|
156
|
+
*/
|
|
157
|
+
export type EscrowWithdraw = {
|
|
158
|
+
/**
|
|
159
|
+
* The hash of the transaction associated with the escrow withdrawal.
|
|
160
|
+
*/
|
|
161
|
+
txHash: string;
|
|
162
|
+
/**
|
|
163
|
+
* The address of the token used for the withdrawal.
|
|
164
|
+
*/
|
|
165
|
+
tokenAddress: string;
|
|
166
|
+
/**
|
|
167
|
+
* The amount withdrawn from the escrow.
|
|
168
|
+
*/
|
|
169
|
+
amountWithdrawn: bigint;
|
|
170
|
+
};
|