@human-protocol/sdk 1.1.11 → 1.1.13

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.
Files changed (56) hide show
  1. package/README.md +2 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.js +14 -14
  4. package/dist/error.d.ts +8 -0
  5. package/dist/error.d.ts.map +1 -1
  6. package/dist/error.js +10 -2
  7. package/dist/escrow.d.ts +31 -11
  8. package/dist/escrow.d.ts.map +1 -1
  9. package/dist/escrow.js +133 -37
  10. package/dist/graphql/queries/escrow.d.ts +1 -0
  11. package/dist/graphql/queries/escrow.d.ts.map +1 -1
  12. package/dist/graphql/queries/escrow.js +18 -2
  13. package/dist/graphql/queries/index.d.ts +1 -0
  14. package/dist/graphql/queries/index.d.ts.map +1 -1
  15. package/dist/graphql/queries/index.js +1 -0
  16. package/dist/graphql/queries/payout.d.ts +3 -0
  17. package/dist/graphql/queries/payout.d.ts.map +1 -0
  18. package/dist/graphql/queries/payout.js +49 -0
  19. package/dist/graphql/queries/staking.d.ts +4 -0
  20. package/dist/graphql/queries/staking.d.ts.map +1 -0
  21. package/dist/graphql/queries/staking.js +58 -0
  22. package/dist/graphql/queries/statistics.d.ts.map +1 -1
  23. package/dist/graphql/queries/statistics.js +10 -2
  24. package/dist/graphql/types.d.ts +24 -2
  25. package/dist/graphql/types.d.ts.map +1 -1
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +2 -1
  29. package/dist/interfaces.d.ts +34 -9
  30. package/dist/interfaces.d.ts.map +1 -1
  31. package/dist/staking.d.ts +8 -8
  32. package/dist/staking.d.ts.map +1 -1
  33. package/dist/staking.js +16 -38
  34. package/dist/statistics.d.ts.map +1 -1
  35. package/dist/statistics.js +2 -8
  36. package/dist/storage.d.ts +3 -0
  37. package/dist/storage.d.ts.map +1 -1
  38. package/dist/storage.js +3 -0
  39. package/dist/types.d.ts +18 -0
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/constants.ts +16 -14
  43. package/src/error.ts +14 -0
  44. package/src/escrow.ts +189 -46
  45. package/src/graphql/queries/escrow.ts +26 -2
  46. package/src/graphql/queries/index.ts +1 -0
  47. package/src/graphql/queries/payout.ts +47 -0
  48. package/src/graphql/queries/staking.ts +57 -0
  49. package/src/graphql/queries/statistics.ts +10 -2
  50. package/src/graphql/types.ts +29 -2
  51. package/src/index.ts +2 -1
  52. package/src/interfaces.ts +35 -14
  53. package/src/staking.ts +23 -53
  54. package/src/statistics.ts +2 -12
  55. package/src/storage.ts +3 -0
  56. package/src/types.ts +20 -0
package/src/constants.ts CHANGED
@@ -184,29 +184,31 @@ export const NETWORKS: {
184
184
  chainId: ChainId.AVALANCHE_TESTNET,
185
185
  title: 'Fuji C-Chain',
186
186
  scanUrl: 'https://testnet.snowtrace.io',
187
- factoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
187
+ factoryAddress: '0x56C2ba540726ED4f46E7a134b6b9Ee9C867FcF92',
188
188
  hmtAddress: '0x9406d5c635AD22b0d76c75E52De57A2177919ca3',
189
- stakingAddress: '',
190
- rewardPoolAddress: '',
191
- kvstoreAddress: '0xd232c1426CF0653cE8a71DC98bCfDf10c471c114',
192
-
193
- subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
194
- oldSubgraphUrl: '',
195
- oldFactoryAddress: '',
189
+ stakingAddress: '0x9890473B0b93E24d6D1a8Dfb739D577C6f25FFd3',
190
+ rewardPoolAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
191
+ kvstoreAddress: '0x707fb5A5d36BC15275Af3f73262bf9a1D8C470EB',
192
+ subgraphUrl:
193
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji-v2',
194
+ oldSubgraphUrl:
195
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
196
+ oldFactoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
196
197
  },
197
198
  [ChainId.AVALANCHE]: {
198
199
  chainId: ChainId.AVALANCHE,
199
200
  title: 'Avalanche C-Chain Mainnet',
200
201
  scanUrl: 'https://snowtrace.io',
201
- factoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
202
+ factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
202
203
  hmtAddress: '0x12365293cb6477d4fc2686e46BB97E3Fb64f1550',
203
- stakingAddress: '',
204
- rewardPoolAddress: '',
205
- kvstoreAddress: '0x4B79eaD28F52eD5686bf0e379717e85fc7aD10Df',
204
+ stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
205
+ rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
206
+ kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
206
207
  subgraphUrl:
208
+ 'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche-v2',
209
+ oldSubgraphUrl:
207
210
  'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche',
208
- oldSubgraphUrl: '',
209
- oldFactoryAddress: '',
211
+ oldFactoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
210
212
  },
211
213
  [ChainId.SKALE]: {
212
214
  chainId: ChainId.SKALE,
package/src/error.ts CHANGED
@@ -75,6 +75,13 @@ export const ErrorInvalidReputationOracleAddressProvided = new Error(
75
75
  'Invalid reputation oracle address provided'
76
76
  );
77
77
 
78
+ /**
79
+ * @constant {Error} - Invalid reputation oracle address provided.
80
+ */
81
+ export const ErrorInvalidExchangeOracleAddressProvided = new Error(
82
+ 'Invalid exchange oracle address provided'
83
+ );
84
+
78
85
  /**
79
86
  * @constant {Error} - The Staking value must be positive.
80
87
  */
@@ -160,6 +167,13 @@ export const ErrorEscrowAddressIsNotProvidedByFactory = new Error(
160
167
  'Escrow address is not provided by the factory'
161
168
  );
162
169
 
170
+ /**
171
+ * @constant {Error} - Transfer event not found in transaction logs.
172
+ */
173
+ export const ErrorTransferEventNotFoundInTransactionLogs = new Error(
174
+ 'Transfer event not found in transaction logs'
175
+ );
176
+
163
177
  /**
164
178
  * @constant {Error} - Manifest file does not exist.
165
179
  */
package/src/escrow.ts CHANGED
@@ -35,11 +35,17 @@ import {
35
35
  ErrorTotalFeeMustBeLessThanHundred,
36
36
  ErrorUrlIsEmptyString,
37
37
  InvalidEthereumAddressError,
38
+ ErrorInvalidExchangeOracleAddressProvided,
39
+ ErrorTransferEventNotFoundInTransactionLogs,
38
40
  } from './error';
39
41
  import { IEscrowConfig, IEscrowsFilter } from './interfaces';
40
- import { EscrowStatus, NetworkData } from './types';
42
+ import { EscrowCancel, EscrowStatus, NetworkData } from './types';
41
43
  import { isValidUrl, throwError } from './utils';
42
- import { EscrowData, GET_ESCROWS_QUERY } from './graphql';
44
+ import {
45
+ EscrowData,
46
+ GET_ESCROWS_QUERY,
47
+ GET_ESCROW_BY_ADDRESS_QUERY,
48
+ } from './graphql';
43
49
 
44
50
  export class EscrowClient {
45
51
  private escrowFactoryContract: EscrowFactory;
@@ -155,8 +161,10 @@ export class EscrowClient {
155
161
  const {
156
162
  recordingOracle,
157
163
  reputationOracle,
164
+ exchangeOracle,
158
165
  recordingOracleFee,
159
166
  reputationOracleFee,
167
+ exchangeOracleFee,
160
168
  manifestUrl,
161
169
  manifestHash,
162
170
  } = escrowConfig;
@@ -169,15 +177,25 @@ export class EscrowClient {
169
177
  throw ErrorInvalidReputationOracleAddressProvided;
170
178
  }
171
179
 
180
+ if (!ethers.utils.isAddress(exchangeOracle)) {
181
+ throw ErrorInvalidExchangeOracleAddressProvided;
182
+ }
183
+
172
184
  if (!ethers.utils.isAddress(escrowAddress)) {
173
185
  throw ErrorInvalidEscrowAddressProvided;
174
186
  }
175
187
 
176
- if (recordingOracleFee.lte(0) || reputationOracleFee.lte(0)) {
188
+ if (
189
+ recordingOracleFee.lte(0) ||
190
+ reputationOracleFee.lte(0) ||
191
+ exchangeOracleFee.lte(0)
192
+ ) {
177
193
  throw ErrorAmountMustBeGreaterThanZero;
178
194
  }
179
195
 
180
- if (recordingOracleFee.add(reputationOracleFee).gt(100)) {
196
+ if (
197
+ recordingOracleFee.add(reputationOracleFee).add(exchangeOracleFee).gt(100)
198
+ ) {
181
199
  throw ErrorTotalFeeMustBeLessThanHundred;
182
200
  }
183
201
 
@@ -205,8 +223,10 @@ export class EscrowClient {
205
223
  await this.escrowContract.setup(
206
224
  reputationOracle,
207
225
  recordingOracle,
226
+ exchangeOracle,
208
227
  reputationOracleFee,
209
228
  recordingOracleFee,
229
+ exchangeOracleFee,
210
230
  manifestUrl,
211
231
  manifestHash
212
232
  );
@@ -461,11 +481,11 @@ export class EscrowClient {
461
481
  * Cancels the specified escrow and sends the balance to the canceler.
462
482
  *
463
483
  * @param {string} escrowAddress - Address of the escrow.
464
- * @returns {Promise<void>}
484
+ * @returns {Promise<EscrowCancel>}
465
485
  * @throws {Error} - An error object if an error occurred.
466
486
  */
467
487
  @requiresSigner
468
- async cancel(escrowAddress: string): Promise<void> {
488
+ async cancel(escrowAddress: string): Promise<EscrowCancel> {
469
489
  if (!ethers.utils.isAddress(escrowAddress)) {
470
490
  throw ErrorInvalidEscrowAddressProvided;
471
491
  }
@@ -479,8 +499,39 @@ export class EscrowClient {
479
499
  escrowAddress,
480
500
  this.signerOrProvider
481
501
  );
482
- await this.escrowContract.cancel();
483
- return;
502
+ const tx = await this.escrowContract.cancel();
503
+ const transactionReceipt = await tx.wait();
504
+
505
+ let amountTransferred: BigNumber | undefined = undefined;
506
+ const tokenAddress = await this.escrowContract.token();
507
+
508
+ const tokenContract: HMToken = HMToken__factory.connect(
509
+ tokenAddress,
510
+ this.signerOrProvider
511
+ );
512
+
513
+ for (const log of transactionReceipt.logs) {
514
+ if (log.address === tokenAddress) {
515
+ const parsedLog = tokenContract.interface.parseLog(log);
516
+
517
+ const from = parsedLog.args[0];
518
+ if (parsedLog.name === 'Transfer' && from === escrowAddress) {
519
+ amountTransferred = parsedLog.args[2];
520
+ break;
521
+ }
522
+ }
523
+ }
524
+
525
+ if (amountTransferred === undefined) {
526
+ throw ErrorTransferEventNotFoundInTransactionLogs;
527
+ }
528
+
529
+ const escrowCancelData: EscrowCancel = {
530
+ txHash: transactionReceipt.transactionHash,
531
+ amountRefunded: amountTransferred,
532
+ };
533
+
534
+ return escrowCancelData;
484
535
  } catch (e) {
485
536
  return throwError(e);
486
537
  }
@@ -748,56 +799,40 @@ export class EscrowClient {
748
799
  }
749
800
 
750
801
  /**
751
- * Returns the list of escrows for given filter
802
+ * Returns the recording oracle address of given escrow
752
803
  *
753
- * @param {IEscrowsFilter} filter - Filter parameters.
754
- * @returns {Promise<EscrowData[]>}
804
+ * @param {string} escrowAddress - Address of the escrow.
805
+ * @returns {Promise<string>} - Address of the recording oracle.
755
806
  * @throws {Error} - An error object if an error occurred.
756
807
  */
757
- async getEscrows(filter: IEscrowsFilter = {}): Promise<EscrowData[]> {
758
- if (filter.launcher && !ethers.utils.isAddress(filter.launcher)) {
759
- throw ErrorInvalidAddress;
760
- }
761
-
762
- if (
763
- filter.recordingOracle &&
764
- !ethers.utils.isAddress(filter.recordingOracle)
765
- ) {
766
- throw ErrorInvalidAddress;
808
+ async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
809
+ if (!ethers.utils.isAddress(escrowAddress)) {
810
+ throw ErrorInvalidEscrowAddressProvided;
767
811
  }
768
812
 
769
- if (
770
- filter.reputationOracle &&
771
- !ethers.utils.isAddress(filter.reputationOracle)
772
- ) {
773
- throw ErrorInvalidAddress;
813
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
814
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
774
815
  }
775
816
 
776
817
  try {
777
- const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
778
- this.network.subgraphUrl,
779
- GET_ESCROWS_QUERY(filter),
780
- {
781
- ...filter,
782
- from: filter.from ? +filter.from.getTime() / 1000 : undefined,
783
- to: filter.to ? +filter.to.getTime() / 1000 : undefined,
784
- }
818
+ this.escrowContract = Escrow__factory.connect(
819
+ escrowAddress,
820
+ this.signerOrProvider
785
821
  );
786
-
787
- return escrows;
822
+ return this.escrowContract.recordingOracle();
788
823
  } catch (e: any) {
789
824
  return throwError(e);
790
825
  }
791
826
  }
792
827
 
793
828
  /**
794
- * Returns the recording oracle address of given escrow
829
+ * Returns the job launcher address of given escrow
795
830
  *
796
831
  * @param {string} escrowAddress - Address of the escrow.
797
- * @returns {Promise<string>} - Address of the recording oracle.
832
+ * @returns {Promise<string>} - Address of the job launcher.
798
833
  * @throws {Error} - An error object if an error occurred.
799
834
  */
800
- async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
835
+ async getJobLauncherAddress(escrowAddress: string): Promise<string> {
801
836
  if (!ethers.utils.isAddress(escrowAddress)) {
802
837
  throw ErrorInvalidEscrowAddressProvided;
803
838
  }
@@ -811,20 +846,20 @@ export class EscrowClient {
811
846
  escrowAddress,
812
847
  this.signerOrProvider
813
848
  );
814
- return this.escrowContract.recordingOracle();
849
+ return this.escrowContract.launcher();
815
850
  } catch (e: any) {
816
851
  return throwError(e);
817
852
  }
818
853
  }
819
854
 
820
855
  /**
821
- * Returns the job launcher address of given escrow
856
+ * Returns the reputation oracle address of given escrow
822
857
  *
823
858
  * @param {string} escrowAddress - Address of the escrow.
824
- * @returns {Promise<string>} - Address of the job launcher.
859
+ * @returns {Promise<string>} - Address of the reputation oracle.
825
860
  * @throws {Error} - An error object if an error occurred.
826
861
  */
827
- async getJobLauncherAddress(escrowAddress: string): Promise<string> {
862
+ async getReputationOracleAddress(escrowAddress: string): Promise<string> {
828
863
  if (!ethers.utils.isAddress(escrowAddress)) {
829
864
  throw ErrorInvalidEscrowAddressProvided;
830
865
  }
@@ -838,7 +873,7 @@ export class EscrowClient {
838
873
  escrowAddress,
839
874
  this.signerOrProvider
840
875
  );
841
- return this.escrowContract.launcher();
876
+ return this.escrowContract.reputationOracle();
842
877
  } catch (e: any) {
843
878
  return throwError(e);
844
879
  }
@@ -851,7 +886,7 @@ export class EscrowClient {
851
886
  * @returns {Promise<string>} - Address of the reputation oracle.
852
887
  * @throws {Error} - An error object if an error occurred.
853
888
  */
854
- async getReputationOracleAddress(escrowAddress: string): Promise<string> {
889
+ async getExchangeOracleAddress(escrowAddress: string): Promise<string> {
855
890
  if (!ethers.utils.isAddress(escrowAddress)) {
856
891
  throw ErrorInvalidEscrowAddressProvided;
857
892
  }
@@ -865,7 +900,7 @@ export class EscrowClient {
865
900
  escrowAddress,
866
901
  this.signerOrProvider
867
902
  );
868
- return this.escrowContract.reputationOracle();
903
+ return this.escrowContract.exchangeOracle();
869
904
  } catch (e: any) {
870
905
  return throwError(e);
871
906
  }
@@ -898,3 +933,111 @@ export class EscrowClient {
898
933
  }
899
934
  }
900
935
  }
936
+
937
+ export class EscrowUtils {
938
+ /**
939
+ * Returns the list of escrows for given filter
940
+ *
941
+ * @param {IEscrowsFilter} filter - Filter parameters.
942
+ * @returns {Promise<EscrowData[]>}
943
+ * @throws {Error} - An error object if an error occurred.
944
+ */
945
+ public static async getEscrows(
946
+ filter: IEscrowsFilter
947
+ ): Promise<EscrowData[]> {
948
+ if (!filter?.networks?.length) {
949
+ throw ErrorUnsupportedChainID;
950
+ }
951
+ if (filter.launcher && !ethers.utils.isAddress(filter.launcher)) {
952
+ throw ErrorInvalidAddress;
953
+ }
954
+
955
+ if (
956
+ filter.recordingOracle &&
957
+ !ethers.utils.isAddress(filter.recordingOracle)
958
+ ) {
959
+ throw ErrorInvalidAddress;
960
+ }
961
+
962
+ if (
963
+ filter.reputationOracle &&
964
+ !ethers.utils.isAddress(filter.reputationOracle)
965
+ ) {
966
+ throw ErrorInvalidAddress;
967
+ }
968
+
969
+ if (
970
+ filter.exchangeOracle &&
971
+ !ethers.utils.isAddress(filter.exchangeOracle)
972
+ ) {
973
+ throw ErrorInvalidAddress;
974
+ }
975
+
976
+ try {
977
+ const escrowAddresses: EscrowData[] = [];
978
+ for (const chainId of filter.networks) {
979
+ const networkData = NETWORKS[chainId];
980
+
981
+ if (!networkData) {
982
+ throw ErrorUnsupportedChainID;
983
+ }
984
+
985
+ const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
986
+ networkData.subgraphUrl,
987
+ GET_ESCROWS_QUERY(filter),
988
+ {
989
+ ...filter,
990
+ status: filter.status
991
+ ? Object.entries(EscrowStatus).find(
992
+ ([, value]) => value === filter.status
993
+ )?.[0]
994
+ : undefined,
995
+ from: filter.from ? +filter.from.getTime() / 1000 : undefined,
996
+ to: filter.to ? +filter.to.getTime() / 1000 : undefined,
997
+ }
998
+ );
999
+ escrows.map((escrow) => (escrow.chainId = networkData.chainId));
1000
+ escrowAddresses.push(...escrows);
1001
+ }
1002
+ escrowAddresses.sort((a, b) => Number(b.createdAt) - Number(a.createdAt));
1003
+ return escrowAddresses;
1004
+ } catch (e: any) {
1005
+ return throwError(e);
1006
+ }
1007
+ }
1008
+
1009
+ /**
1010
+ * Returns the escrow for a given address
1011
+ *
1012
+ * @param {string} escrowAddress - Escrow address.
1013
+ * @param {ChainId} chainId - Chain id.
1014
+ * @returns {Promise<EscrowData>}
1015
+ * @throws {Error} - An error object if an error occurred.
1016
+ */
1017
+ public static async getEscrow(
1018
+ chainId: ChainId,
1019
+ escrowAddress: string
1020
+ ): Promise<EscrowData> {
1021
+ const networkData = NETWORKS[chainId];
1022
+
1023
+ if (!networkData) {
1024
+ throw ErrorUnsupportedChainID;
1025
+ }
1026
+
1027
+ if (escrowAddress && !ethers.utils.isAddress(escrowAddress)) {
1028
+ throw ErrorInvalidAddress;
1029
+ }
1030
+
1031
+ try {
1032
+ const { escrow } = await gqlFetch<{ escrow: EscrowData }>(
1033
+ networkData.subgraphUrl,
1034
+ GET_ESCROW_BY_ADDRESS_QUERY(),
1035
+ { escrowAddress }
1036
+ );
1037
+
1038
+ return escrow || null;
1039
+ } catch (e: any) {
1040
+ return throwError(e);
1041
+ }
1042
+ }
1043
+ }
@@ -11,6 +11,7 @@ const ESCROW_FRAGMENT = gql`
11
11
  finalResultsUrl
12
12
  id
13
13
  intermediateResultsUrl
14
+ jobRequesterId
14
15
  launcher
15
16
  manifestHash
16
17
  manifestUrl
@@ -18,6 +19,8 @@ const ESCROW_FRAGMENT = gql`
18
19
  recordingOracleFee
19
20
  reputationOracle
20
21
  reputationOracleFee
22
+ exchangeOracle
23
+ exchangeOracleFee
21
24
  status
22
25
  token
23
26
  totalFundedAmount
@@ -25,15 +28,34 @@ const ESCROW_FRAGMENT = gql`
25
28
  }
26
29
  `;
27
30
 
31
+ export const GET_ESCROW_BY_ADDRESS_QUERY = () => gql`
32
+ query getEscrowByAddress($escrowAddress: String!) {
33
+ escrow(id: $escrowAddress) {
34
+ ...EscrowFields
35
+ }
36
+ }
37
+ ${ESCROW_FRAGMENT}
38
+ `;
39
+
28
40
  export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
29
- const { launcher, reputationOracle, recordingOracle, status, from, to } =
30
- filter;
41
+ const {
42
+ launcher,
43
+ jobRequesterId,
44
+ reputationOracle,
45
+ recordingOracle,
46
+ exchangeOracle,
47
+ status,
48
+ from,
49
+ to,
50
+ } = filter;
31
51
 
32
52
  const WHERE_CLAUSE = `
33
53
  where: {
34
54
  ${launcher ? `launcher: $launcher` : ''}
55
+ ${jobRequesterId ? `jobRequesterId: $jobRequesterId` : ''}
35
56
  ${reputationOracle ? `reputationOracle: $reputationOracle` : ''}
36
57
  ${recordingOracle ? `recordingOracle: $recordingOracle` : ''}
58
+ ${exchangeOracle ? `exchangeOracle: $exchangeOracle` : ''}
37
59
  ${status ? `status: $status` : ''}
38
60
  ${from ? `createdAt_gte: $from` : ''}
39
61
  ${to ? `createdAt_lte: $to` : ''}
@@ -43,8 +65,10 @@ export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
43
65
  return gql`
44
66
  query getEscrows(
45
67
  $launcher: String
68
+ $jobRequesterId: String
46
69
  $reputationOracle: String
47
70
  $recordingOracle: String
71
+ $exchangeOracle: String
48
72
  $status: String
49
73
  $from: Int
50
74
  $to: Int
@@ -2,3 +2,4 @@ export * from './escrow';
2
2
  export * from './hmtoken';
3
3
  export * from './reward';
4
4
  export * from './statistics';
5
+ export * from './payout';
@@ -0,0 +1,47 @@
1
+ import gql from 'graphql-tag';
2
+ import { IPayoutFilter } from '../../interfaces';
3
+
4
+ const PAYOUT_FRAGMENT = gql`
5
+ fragment PayoutFields on Payout {
6
+ id
7
+ escrowAddress
8
+ recipient
9
+ amount
10
+ createdAt
11
+ }
12
+ `;
13
+
14
+ export const GET_PAYOUTS_QUERY = (filter: IPayoutFilter) => {
15
+ const { escrowAddress, recipient, from, to } = filter;
16
+
17
+ const WHERE_CLAUSE = `
18
+ where: {
19
+ ${escrowAddress ? `escrowAddress: $escrowAddress` : ''}
20
+ ${recipient ? `recipient: $recipient` : ''}
21
+ ${from ? `createdAt_gte: $from` : ''}
22
+ ${to ? `createdAt_lt: $to` : ''}
23
+ }
24
+ `;
25
+ const LIMIT_CLAUSE = `
26
+ first: 1000
27
+ `;
28
+
29
+ return gql`
30
+ query getPayouts(
31
+ $escrowAddress: String
32
+ $recipient: String
33
+ $from: Int
34
+ $to: Int
35
+ ) {
36
+ payouts(
37
+ ${WHERE_CLAUSE}
38
+ orderBy: createdAt,
39
+ orderDirection: desc,
40
+ ${LIMIT_CLAUSE}
41
+ ) {
42
+ ...PayoutFields
43
+ }
44
+ }
45
+ ${PAYOUT_FRAGMENT}
46
+ `;
47
+ };
@@ -0,0 +1,57 @@
1
+ import gql from 'graphql-tag';
2
+ import { ILeadersFilter } from 'src/interfaces';
3
+
4
+ const LEADER_FRAGMENT = gql`
5
+ fragment LeaderFields on Leader {
6
+ id
7
+ address
8
+ amountStaked
9
+ amountAllocated
10
+ amountLocked
11
+ lockedUntilTimestamp
12
+ amountWithdrawn
13
+ amountSlashed
14
+ reputation
15
+ reward
16
+ amountJobsLaunched
17
+ role
18
+ fee
19
+ publicKey
20
+ webhookUrl
21
+ url
22
+ }
23
+ `;
24
+
25
+ export const GET_LEADERS_QUERY = (filter: ILeadersFilter) => {
26
+ const { role } = filter;
27
+
28
+ const WHERE_CLAUSE = `
29
+ where: {
30
+ ${role ? `role: $role` : ''}
31
+ }
32
+ `;
33
+
34
+ return gql`
35
+ query getLeaders(
36
+ $role: String
37
+ ) {
38
+ leaders(
39
+ ${WHERE_CLAUSE}
40
+ orderBy: amountStaked,
41
+ orderDirection: desc,
42
+ ) {
43
+ ...LeaderFields
44
+ }
45
+ }
46
+ ${LEADER_FRAGMENT}
47
+ `;
48
+ };
49
+
50
+ export const GET_LEADER_QUERY = gql`
51
+ query getLeader($address: String!) {
52
+ leader(id: $address) {
53
+ ...LeaderFields
54
+ }
55
+ }
56
+ ${LEADER_FRAGMENT}
57
+ `;
@@ -69,17 +69,25 @@ export const GET_ESCROW_STATISTICS_QUERY = gql`
69
69
  `;
70
70
 
71
71
  export const GET_EVENT_DAY_DATA_QUERY = (params: IStatisticsParams) => {
72
- const { from, to } = params;
72
+ const { from, to, limit } = params;
73
73
  const WHERE_CLAUSE = `
74
74
  where: {
75
75
  ${from !== undefined ? `timestamp_gte: $from` : ''}
76
76
  ${to !== undefined ? `timestamp_lte: $to` : ''}
77
77
  }
78
78
  `;
79
+ const LIMIT_CLAUSE = `
80
+ first: ${limit ? `$limit` : `1000`}
81
+ `;
79
82
 
80
83
  return gql`
81
84
  query GetEscrowDayData($from: Int, $to: Int) {
82
- eventDayDatas(${WHERE_CLAUSE}) {
85
+ eventDayDatas(
86
+ ${WHERE_CLAUSE},
87
+ orderBy: timestamp,
88
+ orderDirection: desc,
89
+ ${LIMIT_CLAUSE}
90
+ ) {
83
91
  ...EventDayDataFields
84
92
  }
85
93
  }
@@ -16,10 +16,21 @@ export type EscrowData = {
16
16
  recordingOracleFee?: string;
17
17
  reputationOracle?: string;
18
18
  reputationOracleFee?: string;
19
+ exchangeOracle?: string;
20
+ exchangeOracleFee?: string;
19
21
  status: string;
20
22
  token: string;
21
23
  totalFundedAmount: string;
22
24
  createdAt: string;
25
+ chainId: number;
26
+ };
27
+
28
+ export type PayoutData = {
29
+ id: string;
30
+ escrowAddress: string;
31
+ recipient: string;
32
+ amount: string;
33
+ createdAt: string;
23
34
  };
24
35
 
25
36
  export type HMTStatisticsData = {
@@ -89,7 +100,6 @@ export type EscrowStatistics = {
89
100
  export type DailyWorkerData = {
90
101
  timestamp: Date;
91
102
  activeWorkers: number;
92
- averageJobsSolved: number;
93
103
  };
94
104
 
95
105
  export type WorkerStatistics = {
@@ -100,7 +110,6 @@ export type DailyPaymentData = {
100
110
  timestamp: Date;
101
111
  totalAmountPaid: BigNumber;
102
112
  totalCount: number;
103
- averageAmountPerJob: BigNumber;
104
113
  averageAmountPerWorker: BigNumber;
105
114
  };
106
115
 
@@ -126,7 +135,25 @@ export type DailyHMTData = {
126
135
 
127
136
  export type HMTStatistics = {
128
137
  totalTransferAmount: BigNumber;
138
+ totalTransferCount: number;
129
139
  totalHolders: number;
130
140
  holders: HMTHolder[];
131
141
  dailyHMTData: DailyHMTData[];
132
142
  };
143
+
144
+ export type IMDataEntity = {
145
+ served: number;
146
+ solved: number;
147
+ };
148
+
149
+ export type IMData = Record<string, IMDataEntity>;
150
+
151
+ export type DailyTaskData = {
152
+ timestamp: Date;
153
+ tasksTotal: number;
154
+ tasksSolved: number;
155
+ };
156
+
157
+ export type TaskStatistics = {
158
+ dailyTasksData: DailyTaskData[];
159
+ };