@human-protocol/sdk 3.0.0 → 3.0.1
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/README.md +23 -80
- package/dist/enums.d.ts +4 -0
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +6 -1
- package/dist/error.d.ts +7 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +8 -1
- package/dist/escrow.d.ts +90 -5
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +153 -37
- package/dist/graphql/queries/escrow.d.ts +1 -0
- package/dist/graphql/queries/escrow.d.ts.map +1 -1
- package/dist/graphql/queries/escrow.js +50 -9
- package/dist/graphql/queries/hmtoken.d.ts +1 -1
- package/dist/graphql/queries/hmtoken.d.ts.map +1 -1
- package/dist/graphql/queries/hmtoken.js +23 -7
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +2 -0
- package/dist/graphql/queries/transaction.d.ts.map +1 -1
- package/dist/graphql/queries/transaction.js +12 -7
- package/dist/graphql/types.d.ts +11 -0
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/interfaces.d.ts +15 -6
- 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 +64 -81
- package/dist/statistics.d.ts +28 -2
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +46 -1
- package/dist/transaction.d.ts +10 -4
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +36 -27
- package/package.json +5 -4
- package/src/enums.ts +5 -0
- package/src/error.ts +8 -0
- package/src/escrow.ts +197 -48
- package/src/graphql/queries/escrow.ts +53 -8
- package/src/graphql/queries/hmtoken.ts +23 -7
- package/src/graphql/queries/statistics.ts +2 -0
- package/src/graphql/queries/transaction.ts +12 -7
- package/src/graphql/types.ts +13 -0
- package/src/index.ts +2 -0
- package/src/interfaces.ts +17 -6
- package/src/kvstore.ts +1 -1
- package/src/operator.ts +79 -91
- package/src/statistics.ts +54 -2
- package/src/transaction.ts +40 -30
|
@@ -7,11 +7,27 @@ const HOLDER_FRAGMENT = gql`
|
|
|
7
7
|
}
|
|
8
8
|
`;
|
|
9
9
|
|
|
10
|
-
export const GET_HOLDERS_QUERY =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export const GET_HOLDERS_QUERY = (address?: string) => {
|
|
11
|
+
const WHERE_CLAUSE = `
|
|
12
|
+
where: {
|
|
13
|
+
${address ? `address: $address,` : ''}
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
return gql`
|
|
18
|
+
query GetHolders(
|
|
19
|
+
$address: String
|
|
20
|
+
$orderBy: String
|
|
21
|
+
$orderDirection: String
|
|
22
|
+
) {
|
|
23
|
+
holders(
|
|
24
|
+
${WHERE_CLAUSE}
|
|
25
|
+
orderBy: $orderBy,
|
|
26
|
+
orderDirection: $orderDirection
|
|
27
|
+
) {
|
|
28
|
+
...HolderFields
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
${HOLDER_FRAGMENT}
|
|
32
|
+
`;
|
|
33
|
+
};
|
|
@@ -19,12 +19,12 @@ export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
|
|
|
19
19
|
|
|
20
20
|
const WHERE_CLAUSE = `
|
|
21
21
|
where: {
|
|
22
|
-
${fromAddress ? `from: $fromAddress
|
|
23
|
-
${toAddress ? `to: $toAddress
|
|
24
|
-
${startDate ? `timestamp_gte: $startDate
|
|
25
|
-
${endDate ? `timestamp_lte: $endDate
|
|
26
|
-
${startBlock ? `block_gte: $startBlock
|
|
27
|
-
${endBlock ? `block_lte: $endBlock
|
|
22
|
+
${fromAddress ? `from: $fromAddress,` : ''}
|
|
23
|
+
${toAddress ? `to: $toAddress,` : ''}
|
|
24
|
+
${startDate ? `timestamp_gte: $startDate,` : ''}
|
|
25
|
+
${endDate ? `timestamp_lte: $endDate,` : ''}
|
|
26
|
+
${startBlock ? `block_gte: $startBlock,` : ''}
|
|
27
|
+
${endBlock ? `block_lte: $endBlock,` : ''}
|
|
28
28
|
}
|
|
29
29
|
`;
|
|
30
30
|
|
|
@@ -36,11 +36,16 @@ export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
|
|
|
36
36
|
$endDate: Int
|
|
37
37
|
$startBlock: Int
|
|
38
38
|
$endBlock: Int
|
|
39
|
+
$orderDirection: String
|
|
40
|
+
$first: Int
|
|
41
|
+
$skip: Int
|
|
39
42
|
) {
|
|
40
43
|
transactions(
|
|
41
44
|
${WHERE_CLAUSE}
|
|
42
45
|
orderBy: timestamp,
|
|
43
|
-
orderDirection:
|
|
46
|
+
orderDirection: $orderDirection,
|
|
47
|
+
first: $first,
|
|
48
|
+
skip: $skip
|
|
44
49
|
) {
|
|
45
50
|
...TransactionFields
|
|
46
51
|
}
|
package/src/graphql/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ChainId } from '../enums';
|
|
2
|
+
|
|
1
3
|
export type EscrowData = {
|
|
2
4
|
id: string;
|
|
3
5
|
address: string;
|
|
@@ -72,6 +74,8 @@ export type EventDayData = {
|
|
|
72
74
|
dailyPayoutAmount: string;
|
|
73
75
|
dailyHMTTransferCount: string;
|
|
74
76
|
dailyHMTTransferAmount: string;
|
|
77
|
+
dailyUniqueSenders: string;
|
|
78
|
+
dailyUniqueReceivers: string;
|
|
75
79
|
};
|
|
76
80
|
|
|
77
81
|
export type RewardAddedEventData = {
|
|
@@ -129,6 +133,8 @@ export type DailyHMTData = {
|
|
|
129
133
|
timestamp: Date;
|
|
130
134
|
totalTransactionAmount: bigint;
|
|
131
135
|
totalTransactionCount: number;
|
|
136
|
+
dailyUniqueSenders: number;
|
|
137
|
+
dailyUniqueReceivers: number;
|
|
132
138
|
};
|
|
133
139
|
|
|
134
140
|
export type HMTStatistics = {
|
|
@@ -156,6 +162,13 @@ export type TaskStatistics = {
|
|
|
156
162
|
dailyTasksData: DailyTaskData[];
|
|
157
163
|
};
|
|
158
164
|
|
|
165
|
+
export type StatusEvent = {
|
|
166
|
+
timestamp: number;
|
|
167
|
+
escrowAddress: string;
|
|
168
|
+
status: string;
|
|
169
|
+
chainId: ChainId;
|
|
170
|
+
};
|
|
171
|
+
|
|
159
172
|
export type KVStoreData = {
|
|
160
173
|
id: string;
|
|
161
174
|
address: string;
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { EscrowClient, EscrowUtils } from './escrow';
|
|
|
5
5
|
import { StatisticsClient } from './statistics';
|
|
6
6
|
import { Encryption, EncryptionUtils } from './encryption';
|
|
7
7
|
import { OperatorUtils } from './operator';
|
|
8
|
+
import { TransactionUtils } from './transaction';
|
|
8
9
|
|
|
9
10
|
export * from './constants';
|
|
10
11
|
export * from './types';
|
|
@@ -21,4 +22,5 @@ export {
|
|
|
21
22
|
Encryption,
|
|
22
23
|
EncryptionUtils,
|
|
23
24
|
OperatorUtils,
|
|
25
|
+
TransactionUtils,
|
|
24
26
|
};
|
package/src/interfaces.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EscrowStatus } from './types';
|
|
2
|
-
import { ChainId } from './enums';
|
|
2
|
+
import { ChainId, OrderDirection } from './enums';
|
|
3
3
|
|
|
4
4
|
export interface IAllocation {
|
|
5
5
|
escrowAddress: string;
|
|
@@ -66,7 +66,7 @@ export interface IOperatorSubgraph extends Omit<IOperator, 'jobTypes'> {
|
|
|
66
66
|
jobTypes?: string;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export interface IEscrowsFilter {
|
|
69
|
+
export interface IEscrowsFilter extends IPagination {
|
|
70
70
|
launcher?: string;
|
|
71
71
|
reputationOracle?: string;
|
|
72
72
|
recordingOracle?: string;
|
|
@@ -75,7 +75,7 @@ export interface IEscrowsFilter {
|
|
|
75
75
|
status?: EscrowStatus;
|
|
76
76
|
from?: Date;
|
|
77
77
|
to?: Date;
|
|
78
|
-
|
|
78
|
+
chainId: ChainId;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export interface IEscrowConfig {
|
|
@@ -102,6 +102,11 @@ export interface IStatisticsParams {
|
|
|
102
102
|
limit?: number;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
export interface IHMTHoldersParams {
|
|
106
|
+
address?: string;
|
|
107
|
+
orderDirection?: 'asc' | 'desc';
|
|
108
|
+
}
|
|
109
|
+
|
|
105
110
|
export interface IPayoutFilter {
|
|
106
111
|
escrowAddress?: string;
|
|
107
112
|
recipient?: string;
|
|
@@ -116,7 +121,7 @@ export interface IKVStore {
|
|
|
116
121
|
|
|
117
122
|
export interface ITransaction {
|
|
118
123
|
block: bigint;
|
|
119
|
-
|
|
124
|
+
txHash: string;
|
|
120
125
|
from: string;
|
|
121
126
|
to: string;
|
|
122
127
|
timestamp: bigint;
|
|
@@ -124,8 +129,8 @@ export interface ITransaction {
|
|
|
124
129
|
method: string;
|
|
125
130
|
}
|
|
126
131
|
|
|
127
|
-
export interface ITransactionsFilter {
|
|
128
|
-
|
|
132
|
+
export interface ITransactionsFilter extends IPagination {
|
|
133
|
+
chainId: ChainId;
|
|
129
134
|
startBlock?: number;
|
|
130
135
|
endBlock?: number;
|
|
131
136
|
startDate?: Date;
|
|
@@ -133,3 +138,9 @@ export interface ITransactionsFilter {
|
|
|
133
138
|
fromAddress?: string;
|
|
134
139
|
toAddress?: string;
|
|
135
140
|
}
|
|
141
|
+
|
|
142
|
+
export interface IPagination {
|
|
143
|
+
first?: number;
|
|
144
|
+
skip?: number;
|
|
145
|
+
orderDirection?: OrderDirection;
|
|
146
|
+
}
|
package/src/kvstore.ts
CHANGED
|
@@ -442,7 +442,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
442
442
|
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
443
443
|
*
|
|
444
444
|
* const KVStoreAddresses = new KVStoreUtils.getData({
|
|
445
|
-
*
|
|
445
|
+
* network: ChainId.POLYGON_AMOY
|
|
446
446
|
* });
|
|
447
447
|
* ```
|
|
448
448
|
*/
|
package/src/operator.ts
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
ErrorInvalidStakerAddressProvided,
|
|
22
22
|
ErrorUnsupportedChainID,
|
|
23
23
|
} from './error';
|
|
24
|
-
import { getSubgraphUrl
|
|
24
|
+
import { getSubgraphUrl } from './utils';
|
|
25
25
|
import { ChainId } from './enums';
|
|
26
26
|
import { NETWORKS } from './constants';
|
|
27
27
|
|
|
@@ -54,28 +54,28 @@ export class OperatorUtils {
|
|
|
54
54
|
throw ErrorUnsupportedChainID;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
57
|
+
const { leader } = await gqlFetch<{
|
|
58
|
+
leader: ILeaderSubgraph;
|
|
59
|
+
}>(getSubgraphUrl(networkData), GET_LEADER_QUERY, {
|
|
60
|
+
address: address.toLowerCase(),
|
|
61
|
+
});
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
if (!leader) {
|
|
64
|
+
return (leader as ILeader) || null;
|
|
65
|
+
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
jobTypes = leader.jobTypes.split(',');
|
|
68
|
-
} else if (Array.isArray(leader.jobTypes)) {
|
|
69
|
-
jobTypes = leader.jobTypes;
|
|
70
|
-
}
|
|
67
|
+
let jobTypes: string[] = [];
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} catch (e) {
|
|
77
|
-
return throwError(e);
|
|
69
|
+
if (typeof leader.jobTypes === 'string') {
|
|
70
|
+
jobTypes = leader.jobTypes.split(',');
|
|
71
|
+
} else if (Array.isArray(leader.jobTypes)) {
|
|
72
|
+
jobTypes = leader.jobTypes;
|
|
78
73
|
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
...leader,
|
|
77
|
+
jobTypes,
|
|
78
|
+
};
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|
|
@@ -97,45 +97,41 @@ export class OperatorUtils {
|
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
99
|
public static async getLeaders(filter: ILeadersFilter): Promise<ILeader[]> {
|
|
100
|
-
|
|
101
|
-
let leaders_data: ILeader[] = [];
|
|
100
|
+
let leaders_data: ILeader[] = [];
|
|
102
101
|
|
|
103
|
-
|
|
102
|
+
const networkData = NETWORKS[filter.chainId];
|
|
104
103
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const { leaders } = await gqlFetch<{
|
|
110
|
-
leaders: ILeaderSubgraph[];
|
|
111
|
-
}>(getSubgraphUrl(networkData), GET_LEADERS_QUERY(filter), {
|
|
112
|
-
role: filter?.role,
|
|
113
|
-
});
|
|
104
|
+
if (!networkData) {
|
|
105
|
+
throw ErrorUnsupportedChainID;
|
|
106
|
+
}
|
|
114
107
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
const { leaders } = await gqlFetch<{
|
|
109
|
+
leaders: ILeaderSubgraph[];
|
|
110
|
+
}>(getSubgraphUrl(networkData), GET_LEADERS_QUERY(filter), {
|
|
111
|
+
role: filter?.role,
|
|
112
|
+
});
|
|
118
113
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
let jobTypes: string[] = [];
|
|
122
|
-
|
|
123
|
-
if (typeof leader.jobTypes === 'string') {
|
|
124
|
-
jobTypes = leader.jobTypes.split(',');
|
|
125
|
-
} else if (Array.isArray(leader.jobTypes)) {
|
|
126
|
-
jobTypes = leader.jobTypes;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
...leader,
|
|
131
|
-
jobTypes,
|
|
132
|
-
};
|
|
133
|
-
})
|
|
134
|
-
);
|
|
135
|
-
return leaders_data;
|
|
136
|
-
} catch (e) {
|
|
137
|
-
return throwError(e);
|
|
114
|
+
if (!leaders) {
|
|
115
|
+
return [];
|
|
138
116
|
}
|
|
117
|
+
|
|
118
|
+
leaders_data = leaders_data.concat(
|
|
119
|
+
leaders.map((leader) => {
|
|
120
|
+
let jobTypes: string[] = [];
|
|
121
|
+
|
|
122
|
+
if (typeof leader.jobTypes === 'string') {
|
|
123
|
+
jobTypes = leader.jobTypes.split(',');
|
|
124
|
+
} else if (Array.isArray(leader.jobTypes)) {
|
|
125
|
+
jobTypes = leader.jobTypes;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
...leader,
|
|
130
|
+
jobTypes,
|
|
131
|
+
};
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
return leaders_data;
|
|
139
135
|
}
|
|
140
136
|
|
|
141
137
|
/**
|
|
@@ -162,31 +158,27 @@ export class OperatorUtils {
|
|
|
162
158
|
if (!networkData) {
|
|
163
159
|
throw ErrorUnsupportedChainID;
|
|
164
160
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
let jobTypes: string[] = [];
|
|
161
|
+
const { reputationNetwork } = await gqlFetch<{
|
|
162
|
+
reputationNetwork: IReputationNetworkSubgraph;
|
|
163
|
+
}>(getSubgraphUrl(networkData), GET_REPUTATION_NETWORK_QUERY(role), {
|
|
164
|
+
address: address.toLowerCase(),
|
|
165
|
+
role: role,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return reputationNetwork.operators.map((operator) => {
|
|
169
|
+
let jobTypes: string[] = [];
|
|
175
170
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
171
|
+
if (typeof operator.jobTypes === 'string') {
|
|
172
|
+
jobTypes = operator.jobTypes.split(',');
|
|
173
|
+
} else if (Array.isArray(operator.jobTypes)) {
|
|
174
|
+
jobTypes = operator.jobTypes;
|
|
175
|
+
}
|
|
181
176
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
} catch (e) {
|
|
188
|
-
return throwError(e);
|
|
189
|
-
}
|
|
177
|
+
return {
|
|
178
|
+
...operator,
|
|
179
|
+
jobTypes,
|
|
180
|
+
};
|
|
181
|
+
});
|
|
190
182
|
}
|
|
191
183
|
|
|
192
184
|
/**
|
|
@@ -217,21 +209,17 @@ export class OperatorUtils {
|
|
|
217
209
|
throw ErrorUnsupportedChainID;
|
|
218
210
|
}
|
|
219
211
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
});
|
|
212
|
+
const { rewardAddedEvents } = await gqlFetch<{
|
|
213
|
+
rewardAddedEvents: RewardAddedEventData[];
|
|
214
|
+
}>(getSubgraphUrl(networkData), GET_REWARD_ADDED_EVENTS_QUERY, {
|
|
215
|
+
slasherAddress: slasherAddress.toLowerCase(),
|
|
216
|
+
});
|
|
226
217
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
} catch (e) {
|
|
234
|
-
return throwError(e);
|
|
235
|
-
}
|
|
218
|
+
return rewardAddedEvents.map((reward: any) => {
|
|
219
|
+
return {
|
|
220
|
+
escrowAddress: reward.escrow,
|
|
221
|
+
amount: reward.amount,
|
|
222
|
+
};
|
|
223
|
+
});
|
|
236
224
|
}
|
|
237
225
|
}
|
package/src/statistics.ts
CHANGED
|
@@ -15,8 +15,9 @@ import {
|
|
|
15
15
|
PaymentStatistics,
|
|
16
16
|
WorkerStatistics,
|
|
17
17
|
HMTHolderData,
|
|
18
|
+
HMTHolder,
|
|
18
19
|
} from './graphql';
|
|
19
|
-
import { IStatisticsParams } from './interfaces';
|
|
20
|
+
import { IHMTHoldersParams, IStatisticsParams } from './interfaces';
|
|
20
21
|
import { NetworkData } from './types';
|
|
21
22
|
import { getSubgraphUrl, throwError } from './utils';
|
|
22
23
|
|
|
@@ -403,7 +404,7 @@ export class StatisticsClient {
|
|
|
403
404
|
|
|
404
405
|
const { holders } = await gqlFetch<{
|
|
405
406
|
holders: HMTHolderData[];
|
|
406
|
-
}>(this.subgraphUrl, GET_HOLDERS_QUERY);
|
|
407
|
+
}>(this.subgraphUrl, GET_HOLDERS_QUERY());
|
|
407
408
|
|
|
408
409
|
const { eventDayDatas } = await gqlFetch<{
|
|
409
410
|
eventDayDatas: EventDayData[];
|
|
@@ -428,10 +429,61 @@ export class StatisticsClient {
|
|
|
428
429
|
eventDayData.dailyHMTTransferAmount
|
|
429
430
|
),
|
|
430
431
|
totalTransactionCount: +eventDayData.dailyHMTTransferCount,
|
|
432
|
+
dailyUniqueSenders: +eventDayData.dailyUniqueSenders,
|
|
433
|
+
dailyUniqueReceivers: +eventDayData.dailyUniqueReceivers,
|
|
431
434
|
})),
|
|
432
435
|
};
|
|
433
436
|
} catch (e: any) {
|
|
434
437
|
return throwError(e);
|
|
435
438
|
}
|
|
436
439
|
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* This function returns the holders of the HMToken with optional filters and ordering.
|
|
443
|
+
*
|
|
444
|
+
* **Input parameters**
|
|
445
|
+
*
|
|
446
|
+
* @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
|
|
447
|
+
* @returns {HMTHolder[]} List of HMToken holders.
|
|
448
|
+
*
|
|
449
|
+
* **Code example**
|
|
450
|
+
*
|
|
451
|
+
* ```ts
|
|
452
|
+
* import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
|
|
453
|
+
*
|
|
454
|
+
* const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
|
|
455
|
+
*
|
|
456
|
+
* const hmtHolders = await statisticsClient.getHMTHolders({
|
|
457
|
+
* orderDirection: 'asc',
|
|
458
|
+
* });
|
|
459
|
+
*
|
|
460
|
+
* console.log('HMT holders:', hmtHolders.map((h) => ({
|
|
461
|
+
* ...h,
|
|
462
|
+
* balance: h.balance.toString(),
|
|
463
|
+
* })));
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
async getHMTHolders(params: IHMTHoldersParams = {}): Promise<HMTHolder[]> {
|
|
467
|
+
try {
|
|
468
|
+
const { address, orderDirection } = params;
|
|
469
|
+
const query = GET_HOLDERS_QUERY(address);
|
|
470
|
+
|
|
471
|
+
const { holders } = await gqlFetch<{ holders: HMTHolderData[] }>(
|
|
472
|
+
this.subgraphUrl,
|
|
473
|
+
query,
|
|
474
|
+
{
|
|
475
|
+
address,
|
|
476
|
+
orderBy: 'balance',
|
|
477
|
+
orderDirection,
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
return holders.map((holder) => ({
|
|
482
|
+
address: holder.address,
|
|
483
|
+
balance: ethers.toBigInt(holder.balance),
|
|
484
|
+
}));
|
|
485
|
+
} catch (e: any) {
|
|
486
|
+
return throwError(e);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
437
489
|
}
|
package/src/transaction.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
3
|
import gqlFetch from 'graphql-request';
|
|
4
4
|
import { NETWORKS } from './constants';
|
|
5
|
-
import { ChainId } from './enums';
|
|
5
|
+
import { ChainId, OrderDirection } from './enums';
|
|
6
6
|
import {
|
|
7
7
|
ErrorCannotUseDateAndBlockSimultaneously,
|
|
8
8
|
ErrorInvalidHahsProvided,
|
|
@@ -62,13 +62,16 @@ export class TransactionUtils {
|
|
|
62
62
|
*
|
|
63
63
|
* ```ts
|
|
64
64
|
* interface ITransactionsFilter {
|
|
65
|
-
*
|
|
65
|
+
* chainId: ChainId; // List of chain IDs to query.
|
|
66
66
|
* fromAddress?: string; // (Optional) The address from which transactions are sent.
|
|
67
67
|
* toAddress?: string; // (Optional) The address to which transactions are sent.
|
|
68
68
|
* startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
|
|
69
69
|
* endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
|
|
70
70
|
* startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
|
|
71
71
|
* endBlock?: number; // (Optional) The end block number to filter transactions (inclusive).
|
|
72
|
+
* first?: number; // (Optional) Number of transactions per page. Default is 10.
|
|
73
|
+
* skip?: number; // (Optional) Number of transactions to skip. Default is 0.
|
|
74
|
+
* orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
|
|
72
75
|
* }
|
|
73
76
|
* ```
|
|
74
77
|
*
|
|
@@ -90,12 +93,15 @@ export class TransactionUtils {
|
|
|
90
93
|
* **Code example**
|
|
91
94
|
*
|
|
92
95
|
* ```ts
|
|
93
|
-
* import { TransactionUtils, ChainId } from '@human-protocol/sdk';
|
|
96
|
+
* import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
|
|
94
97
|
*
|
|
95
98
|
* const filter: ITransactionsFilter = {
|
|
96
|
-
*
|
|
99
|
+
* chainId: ChainId.POLYGON,
|
|
97
100
|
* startDate: new Date('2022-01-01'),
|
|
98
|
-
* endDate: new Date('2022-12-31')
|
|
101
|
+
* endDate: new Date('2022-12-31'),
|
|
102
|
+
* first: 10,
|
|
103
|
+
* skip: 0,
|
|
104
|
+
* orderDirection: OrderDirection.DESC,
|
|
99
105
|
* };
|
|
100
106
|
* const transactions = await TransactionUtils.getTransactions(filter);
|
|
101
107
|
* ```
|
|
@@ -110,33 +116,37 @@ export class TransactionUtils {
|
|
|
110
116
|
throw ErrorCannotUseDateAndBlockSimultaneously;
|
|
111
117
|
}
|
|
112
118
|
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
throw ErrorUnsupportedChainID;
|
|
118
|
-
}
|
|
119
|
-
const { transactions } = await gqlFetch<{
|
|
120
|
-
transactions: ITransaction[];
|
|
121
|
-
}>(getSubgraphUrl(networkData), GET_TRANSACTIONS_QUERY(filter), {
|
|
122
|
-
fromAddress: filter?.fromAddress,
|
|
123
|
-
toAddress: filter?.toAddress,
|
|
124
|
-
startDate: filter?.startDate
|
|
125
|
-
? Math.floor(filter?.startDate.getTime() / 1000)
|
|
126
|
-
: undefined,
|
|
127
|
-
endDate: filter.endDate
|
|
128
|
-
? Math.floor(filter.endDate.getTime() / 1000)
|
|
129
|
-
: undefined,
|
|
130
|
-
startBlock: filter.startBlock ? filter.startBlock : undefined,
|
|
131
|
-
endBlock: filter.endBlock ? filter.endBlock : undefined,
|
|
132
|
-
});
|
|
119
|
+
const first =
|
|
120
|
+
filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
121
|
+
const skip = filter.skip || 0;
|
|
122
|
+
const orderDirection = filter.orderDirection || OrderDirection.DESC;
|
|
133
123
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
const networkData = NETWORKS[filter.chainId];
|
|
125
|
+
if (!networkData) {
|
|
126
|
+
throw ErrorUnsupportedChainID;
|
|
127
|
+
}
|
|
128
|
+
const { transactions } = await gqlFetch<{
|
|
129
|
+
transactions: ITransaction[];
|
|
130
|
+
}>(getSubgraphUrl(networkData), GET_TRANSACTIONS_QUERY(filter), {
|
|
131
|
+
fromAddress: filter?.fromAddress,
|
|
132
|
+
toAddress: filter?.toAddress,
|
|
133
|
+
startDate: filter?.startDate
|
|
134
|
+
? Math.floor(filter?.startDate.getTime() / 1000)
|
|
135
|
+
: undefined,
|
|
136
|
+
endDate: filter.endDate
|
|
137
|
+
? Math.floor(filter.endDate.getTime() / 1000)
|
|
138
|
+
: undefined,
|
|
139
|
+
startBlock: filter.startBlock ? filter.startBlock : undefined,
|
|
140
|
+
endBlock: filter.endBlock ? filter.endBlock : undefined,
|
|
141
|
+
orderDirection: orderDirection,
|
|
142
|
+
first: first,
|
|
143
|
+
skip: skip,
|
|
144
|
+
});
|
|
137
145
|
|
|
138
|
-
|
|
146
|
+
if (!transactions) {
|
|
147
|
+
return [];
|
|
139
148
|
}
|
|
140
|
-
|
|
149
|
+
|
|
150
|
+
return transactions;
|
|
141
151
|
}
|
|
142
152
|
}
|