@human-protocol/sdk 3.0.7 → 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 +1 -1
- package/dist/encryption.js +18 -8
- 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 +1 -1
- 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
|
@@ -10,35 +10,45 @@ const TRANSACTION_FRAGMENT = gql`
|
|
|
10
10
|
timestamp
|
|
11
11
|
value
|
|
12
12
|
method
|
|
13
|
+
receiver
|
|
14
|
+
escrow
|
|
15
|
+
token
|
|
16
|
+
internalTransactions {
|
|
17
|
+
from
|
|
18
|
+
id
|
|
19
|
+
to
|
|
20
|
+
value
|
|
21
|
+
receiver
|
|
22
|
+
escrow
|
|
23
|
+
token
|
|
24
|
+
method
|
|
25
|
+
}
|
|
13
26
|
}
|
|
14
27
|
`;
|
|
15
28
|
|
|
16
29
|
export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
|
|
17
30
|
const { startDate, endDate, startBlock, endBlock, fromAddress, toAddress } =
|
|
18
31
|
filter;
|
|
19
|
-
|
|
20
32
|
const addressCondition =
|
|
21
33
|
fromAddress === toAddress
|
|
22
34
|
? `
|
|
23
35
|
${fromAddress ? `{ from: $fromAddress }` : ''}
|
|
24
|
-
${toAddress ? `{ to: $toAddress }` : ''}
|
|
36
|
+
${toAddress ? `{ or: [{ or: [{ to: $toAddress }, { receiver: $toAddress }] }, {internalTransactions_: { or: [{ to: $toAddress }, { receiver: $toAddress }] } }] }` : ''}
|
|
25
37
|
`
|
|
26
38
|
: `
|
|
27
|
-
${fromAddress ? `from: $fromAddress` : ''}
|
|
28
|
-
${toAddress ? `to: $toAddress` : ''}
|
|
39
|
+
${fromAddress ? `{ from: $fromAddress }` : ''}
|
|
40
|
+
${toAddress ? `{ or: [{ or: [{ to: $toAddress }, { receiver: $toAddress }] }, { internalTransactions_: { or: [{ to: $toAddress }, { receiver: $toAddress }] } }] }` : ''}
|
|
29
41
|
`;
|
|
30
42
|
|
|
31
43
|
const WHERE_CLAUSE = `
|
|
32
44
|
where: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
${
|
|
39
|
-
|
|
40
|
-
${startBlock ? `block_gte: $startBlock,` : ''}
|
|
41
|
-
${endBlock ? `block_lte: $endBlock,` : ''}
|
|
45
|
+
and: [
|
|
46
|
+
${fromAddress && fromAddress === toAddress ? `{or: [ ${addressCondition} ]},` : `${addressCondition}`}
|
|
47
|
+
${startDate ? `{timestamp_gte: $startDate},` : ''}
|
|
48
|
+
${endDate ? `{timestamp_lte: $endDate},` : ''}
|
|
49
|
+
${startBlock ? `{block_gte: $startBlock},` : ''}
|
|
50
|
+
${endBlock ? `{block_lte: $endBlock},` : ''}
|
|
51
|
+
]
|
|
42
52
|
}
|
|
43
53
|
`;
|
|
44
54
|
|
package/src/graphql/types.ts
CHANGED
|
@@ -41,7 +41,6 @@ export type HMTStatisticsData = {
|
|
|
41
41
|
|
|
42
42
|
export type EscrowStatisticsData = {
|
|
43
43
|
fundEventCount: string;
|
|
44
|
-
setupEventCount: string;
|
|
45
44
|
storeResultsEventCount: string;
|
|
46
45
|
bulkPayoutEventCount: string;
|
|
47
46
|
pendingStatusEventCount: string;
|
|
@@ -56,7 +55,6 @@ export type EscrowStatisticsData = {
|
|
|
56
55
|
export type EventDayData = {
|
|
57
56
|
timestamp: string;
|
|
58
57
|
dailyFundEventCount: string;
|
|
59
|
-
dailySetupEventCount: string;
|
|
60
58
|
dailyStoreResultsEventCount: string;
|
|
61
59
|
dailyBulkPayoutEventCount: string;
|
|
62
60
|
dailyPendingStatusEventCount: string;
|
package/src/interfaces.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { EscrowStatus } from './types';
|
|
2
2
|
import { ChainId, OrderDirection } from './enums';
|
|
3
3
|
|
|
4
|
-
export interface IAllocation {
|
|
5
|
-
escrowAddress: string;
|
|
6
|
-
staker: string;
|
|
7
|
-
tokens: bigint;
|
|
8
|
-
createdAt: bigint;
|
|
9
|
-
closedAt: bigint;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
4
|
export interface IReward {
|
|
13
5
|
escrowAddress: string;
|
|
14
6
|
amount: bigint;
|
|
@@ -19,26 +11,28 @@ export interface ILeader {
|
|
|
19
11
|
chainId: ChainId;
|
|
20
12
|
address: string;
|
|
21
13
|
amountStaked: bigint;
|
|
22
|
-
amountAllocated: bigint;
|
|
23
14
|
amountLocked: bigint;
|
|
24
15
|
lockedUntilTimestamp: bigint;
|
|
25
16
|
amountWithdrawn: bigint;
|
|
26
17
|
amountSlashed: bigint;
|
|
27
|
-
reputation: bigint;
|
|
28
18
|
reward: bigint;
|
|
29
19
|
amountJobsProcessed: bigint;
|
|
30
20
|
role?: string;
|
|
31
21
|
fee?: bigint;
|
|
32
22
|
publicKey?: string;
|
|
33
23
|
webhookUrl?: string;
|
|
24
|
+
website?: string;
|
|
34
25
|
url?: string;
|
|
35
26
|
jobTypes?: string[];
|
|
36
27
|
registrationNeeded?: boolean;
|
|
37
28
|
registrationInstructions?: string;
|
|
29
|
+
reputationNetworks?: string[];
|
|
38
30
|
}
|
|
39
31
|
|
|
40
|
-
export interface ILeaderSubgraph
|
|
32
|
+
export interface ILeaderSubgraph
|
|
33
|
+
extends Omit<ILeader, 'jobTypes' | 'reputationNetworks' | 'chainId'> {
|
|
41
34
|
jobTypes?: string;
|
|
35
|
+
reputationNetworks?: { address: string }[];
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
export interface ILeadersFilter {
|
|
@@ -121,6 +115,16 @@ export interface IKVStore {
|
|
|
121
115
|
value: string;
|
|
122
116
|
}
|
|
123
117
|
|
|
118
|
+
export interface InternalTransaction {
|
|
119
|
+
from: string;
|
|
120
|
+
to: string;
|
|
121
|
+
value: string;
|
|
122
|
+
method: string;
|
|
123
|
+
receiver?: string;
|
|
124
|
+
escrow?: string;
|
|
125
|
+
token?: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
124
128
|
export interface ITransaction {
|
|
125
129
|
block: bigint;
|
|
126
130
|
txHash: string;
|
|
@@ -129,6 +133,10 @@ export interface ITransaction {
|
|
|
129
133
|
timestamp: bigint;
|
|
130
134
|
value: string;
|
|
131
135
|
method: string;
|
|
136
|
+
receiver?: string;
|
|
137
|
+
escrow?: string;
|
|
138
|
+
token?: string;
|
|
139
|
+
internalTransactions: InternalTransaction[];
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
export interface ITransactionsFilter extends IPagination {
|
package/src/kvstore.ts
CHANGED
|
@@ -103,7 +103,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
103
103
|
* **KVStoreClient constructor**
|
|
104
104
|
*
|
|
105
105
|
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
106
|
-
* @param {NetworkData}
|
|
106
|
+
* @param {NetworkData} networkData - The network information required to connect to the KVStore contract
|
|
107
107
|
*/
|
|
108
108
|
constructor(runner: ContractRunner, networkData: NetworkData) {
|
|
109
109
|
super(runner, networkData);
|
package/src/operator.ts
CHANGED
|
@@ -65,6 +65,7 @@ export class OperatorUtils {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
let jobTypes: string[] = [];
|
|
68
|
+
let reputationNetworks: string[] = [];
|
|
68
69
|
|
|
69
70
|
if (typeof leader.jobTypes === 'string') {
|
|
70
71
|
jobTypes = leader.jobTypes.split(',');
|
|
@@ -72,9 +73,17 @@ export class OperatorUtils {
|
|
|
72
73
|
jobTypes = leader.jobTypes;
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
if (leader.reputationNetworks && Array.isArray(leader.reputationNetworks)) {
|
|
77
|
+
reputationNetworks = leader.reputationNetworks.map(
|
|
78
|
+
(network) => network.address
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
75
82
|
return {
|
|
76
83
|
...leader,
|
|
77
84
|
jobTypes,
|
|
85
|
+
reputationNetworks,
|
|
86
|
+
chainId,
|
|
78
87
|
};
|
|
79
88
|
}
|
|
80
89
|
|
|
@@ -118,6 +127,7 @@ export class OperatorUtils {
|
|
|
118
127
|
leaders_data = leaders_data.concat(
|
|
119
128
|
leaders.map((leader) => {
|
|
120
129
|
let jobTypes: string[] = [];
|
|
130
|
+
let reputationNetworks: string[] = [];
|
|
121
131
|
|
|
122
132
|
if (typeof leader.jobTypes === 'string') {
|
|
123
133
|
jobTypes = leader.jobTypes.split(',');
|
|
@@ -125,9 +135,20 @@ export class OperatorUtils {
|
|
|
125
135
|
jobTypes = leader.jobTypes;
|
|
126
136
|
}
|
|
127
137
|
|
|
138
|
+
if (
|
|
139
|
+
leader.reputationNetworks &&
|
|
140
|
+
Array.isArray(leader.reputationNetworks)
|
|
141
|
+
) {
|
|
142
|
+
reputationNetworks = leader.reputationNetworks.map(
|
|
143
|
+
(network) => network.address
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
128
147
|
return {
|
|
129
148
|
...leader,
|
|
130
149
|
jobTypes,
|
|
150
|
+
reputationNetworks,
|
|
151
|
+
chainId: filter.chainId,
|
|
131
152
|
};
|
|
132
153
|
})
|
|
133
154
|
);
|
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
|
+
};
|