@human-protocol/sdk 1.1.11 → 1.1.12
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 +2 -0
- package/dist/error.d.ts +4 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +6 -2
- package/dist/escrow.d.ts +28 -8
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +109 -34
- 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 +18 -2
- package/dist/graphql/queries/index.d.ts +1 -0
- package/dist/graphql/queries/index.d.ts.map +1 -1
- package/dist/graphql/queries/index.js +1 -0
- package/dist/graphql/queries/payout.d.ts +3 -0
- package/dist/graphql/queries/payout.d.ts.map +1 -0
- package/dist/graphql/queries/payout.js +43 -0
- package/dist/graphql/queries/staking.d.ts +4 -0
- package/dist/graphql/queries/staking.d.ts.map +1 -0
- package/dist/graphql/queries/staking.js +58 -0
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +10 -2
- package/dist/graphql/types.d.ts +23 -0
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/interfaces.d.ts +34 -9
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/staking.d.ts +8 -8
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +16 -38
- package/dist/statistics.d.ts +19 -2
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +93 -13
- package/dist/storage.d.ts +3 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +3 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/error.ts +7 -0
- package/src/escrow.ts +152 -41
- package/src/graphql/queries/escrow.ts +26 -2
- package/src/graphql/queries/index.ts +1 -0
- package/src/graphql/queries/payout.ts +41 -0
- package/src/graphql/queries/staking.ts +57 -0
- package/src/graphql/queries/statistics.ts +10 -2
- package/src/graphql/types.ts +28 -0
- package/src/index.ts +2 -1
- package/src/interfaces.ts +35 -14
- package/src/staking.ts +23 -53
- package/src/statistics.ts +133 -17
- package/src/storage.ts +3 -0
- package/src/types.ts +4 -0
package/src/escrow.ts
CHANGED
|
@@ -35,11 +35,16 @@ import {
|
|
|
35
35
|
ErrorTotalFeeMustBeLessThanHundred,
|
|
36
36
|
ErrorUrlIsEmptyString,
|
|
37
37
|
InvalidEthereumAddressError,
|
|
38
|
+
ErrorInvalidExchangeOracleAddressProvided,
|
|
38
39
|
} from './error';
|
|
39
40
|
import { IEscrowConfig, IEscrowsFilter } from './interfaces';
|
|
40
41
|
import { EscrowStatus, NetworkData } from './types';
|
|
41
42
|
import { isValidUrl, throwError } from './utils';
|
|
42
|
-
import {
|
|
43
|
+
import {
|
|
44
|
+
EscrowData,
|
|
45
|
+
GET_ESCROWS_QUERY,
|
|
46
|
+
GET_ESCROW_BY_ADDRESS_QUERY,
|
|
47
|
+
} from './graphql';
|
|
43
48
|
|
|
44
49
|
export class EscrowClient {
|
|
45
50
|
private escrowFactoryContract: EscrowFactory;
|
|
@@ -155,8 +160,10 @@ export class EscrowClient {
|
|
|
155
160
|
const {
|
|
156
161
|
recordingOracle,
|
|
157
162
|
reputationOracle,
|
|
163
|
+
exchangeOracle,
|
|
158
164
|
recordingOracleFee,
|
|
159
165
|
reputationOracleFee,
|
|
166
|
+
exchangeOracleFee,
|
|
160
167
|
manifestUrl,
|
|
161
168
|
manifestHash,
|
|
162
169
|
} = escrowConfig;
|
|
@@ -169,15 +176,25 @@ export class EscrowClient {
|
|
|
169
176
|
throw ErrorInvalidReputationOracleAddressProvided;
|
|
170
177
|
}
|
|
171
178
|
|
|
179
|
+
if (!ethers.utils.isAddress(exchangeOracle)) {
|
|
180
|
+
throw ErrorInvalidExchangeOracleAddressProvided;
|
|
181
|
+
}
|
|
182
|
+
|
|
172
183
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
173
184
|
throw ErrorInvalidEscrowAddressProvided;
|
|
174
185
|
}
|
|
175
186
|
|
|
176
|
-
if (
|
|
187
|
+
if (
|
|
188
|
+
recordingOracleFee.lte(0) ||
|
|
189
|
+
reputationOracleFee.lte(0) ||
|
|
190
|
+
exchangeOracleFee.lte(0)
|
|
191
|
+
) {
|
|
177
192
|
throw ErrorAmountMustBeGreaterThanZero;
|
|
178
193
|
}
|
|
179
194
|
|
|
180
|
-
if (
|
|
195
|
+
if (
|
|
196
|
+
recordingOracleFee.add(reputationOracleFee).add(exchangeOracleFee).gt(100)
|
|
197
|
+
) {
|
|
181
198
|
throw ErrorTotalFeeMustBeLessThanHundred;
|
|
182
199
|
}
|
|
183
200
|
|
|
@@ -205,8 +222,10 @@ export class EscrowClient {
|
|
|
205
222
|
await this.escrowContract.setup(
|
|
206
223
|
reputationOracle,
|
|
207
224
|
recordingOracle,
|
|
225
|
+
exchangeOracle,
|
|
208
226
|
reputationOracleFee,
|
|
209
227
|
recordingOracleFee,
|
|
228
|
+
exchangeOracleFee,
|
|
210
229
|
manifestUrl,
|
|
211
230
|
manifestHash
|
|
212
231
|
);
|
|
@@ -748,56 +767,40 @@ export class EscrowClient {
|
|
|
748
767
|
}
|
|
749
768
|
|
|
750
769
|
/**
|
|
751
|
-
* Returns the
|
|
770
|
+
* Returns the recording oracle address of given escrow
|
|
752
771
|
*
|
|
753
|
-
* @param {
|
|
754
|
-
* @returns {Promise<
|
|
772
|
+
* @param {string} escrowAddress - Address of the escrow.
|
|
773
|
+
* @returns {Promise<string>} - Address of the recording oracle.
|
|
755
774
|
* @throws {Error} - An error object if an error occurred.
|
|
756
775
|
*/
|
|
757
|
-
async
|
|
758
|
-
if (
|
|
759
|
-
throw
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
if (
|
|
763
|
-
filter.recordingOracle &&
|
|
764
|
-
!ethers.utils.isAddress(filter.recordingOracle)
|
|
765
|
-
) {
|
|
766
|
-
throw ErrorInvalidAddress;
|
|
776
|
+
async getRecordingOracleAddress(escrowAddress: string): Promise<string> {
|
|
777
|
+
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
778
|
+
throw ErrorInvalidEscrowAddressProvided;
|
|
767
779
|
}
|
|
768
780
|
|
|
769
|
-
if (
|
|
770
|
-
|
|
771
|
-
!ethers.utils.isAddress(filter.reputationOracle)
|
|
772
|
-
) {
|
|
773
|
-
throw ErrorInvalidAddress;
|
|
781
|
+
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
782
|
+
throw ErrorEscrowAddressIsNotProvidedByFactory;
|
|
774
783
|
}
|
|
775
784
|
|
|
776
785
|
try {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
{
|
|
781
|
-
...filter,
|
|
782
|
-
from: filter.from ? +filter.from.getTime() / 1000 : undefined,
|
|
783
|
-
to: filter.to ? +filter.to.getTime() / 1000 : undefined,
|
|
784
|
-
}
|
|
786
|
+
this.escrowContract = Escrow__factory.connect(
|
|
787
|
+
escrowAddress,
|
|
788
|
+
this.signerOrProvider
|
|
785
789
|
);
|
|
786
|
-
|
|
787
|
-
return escrows;
|
|
790
|
+
return this.escrowContract.recordingOracle();
|
|
788
791
|
} catch (e: any) {
|
|
789
792
|
return throwError(e);
|
|
790
793
|
}
|
|
791
794
|
}
|
|
792
795
|
|
|
793
796
|
/**
|
|
794
|
-
* Returns the
|
|
797
|
+
* Returns the job launcher address of given escrow
|
|
795
798
|
*
|
|
796
799
|
* @param {string} escrowAddress - Address of the escrow.
|
|
797
|
-
* @returns {Promise<string>} - Address of the
|
|
800
|
+
* @returns {Promise<string>} - Address of the job launcher.
|
|
798
801
|
* @throws {Error} - An error object if an error occurred.
|
|
799
802
|
*/
|
|
800
|
-
async
|
|
803
|
+
async getJobLauncherAddress(escrowAddress: string): Promise<string> {
|
|
801
804
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
802
805
|
throw ErrorInvalidEscrowAddressProvided;
|
|
803
806
|
}
|
|
@@ -811,20 +814,20 @@ export class EscrowClient {
|
|
|
811
814
|
escrowAddress,
|
|
812
815
|
this.signerOrProvider
|
|
813
816
|
);
|
|
814
|
-
return this.escrowContract.
|
|
817
|
+
return this.escrowContract.launcher();
|
|
815
818
|
} catch (e: any) {
|
|
816
819
|
return throwError(e);
|
|
817
820
|
}
|
|
818
821
|
}
|
|
819
822
|
|
|
820
823
|
/**
|
|
821
|
-
* Returns the
|
|
824
|
+
* Returns the reputation oracle address of given escrow
|
|
822
825
|
*
|
|
823
826
|
* @param {string} escrowAddress - Address of the escrow.
|
|
824
|
-
* @returns {Promise<string>} - Address of the
|
|
827
|
+
* @returns {Promise<string>} - Address of the reputation oracle.
|
|
825
828
|
* @throws {Error} - An error object if an error occurred.
|
|
826
829
|
*/
|
|
827
|
-
async
|
|
830
|
+
async getReputationOracleAddress(escrowAddress: string): Promise<string> {
|
|
828
831
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
829
832
|
throw ErrorInvalidEscrowAddressProvided;
|
|
830
833
|
}
|
|
@@ -838,7 +841,7 @@ export class EscrowClient {
|
|
|
838
841
|
escrowAddress,
|
|
839
842
|
this.signerOrProvider
|
|
840
843
|
);
|
|
841
|
-
return this.escrowContract.
|
|
844
|
+
return this.escrowContract.reputationOracle();
|
|
842
845
|
} catch (e: any) {
|
|
843
846
|
return throwError(e);
|
|
844
847
|
}
|
|
@@ -851,7 +854,7 @@ export class EscrowClient {
|
|
|
851
854
|
* @returns {Promise<string>} - Address of the reputation oracle.
|
|
852
855
|
* @throws {Error} - An error object if an error occurred.
|
|
853
856
|
*/
|
|
854
|
-
async
|
|
857
|
+
async getExchangeOracleAddress(escrowAddress: string): Promise<string> {
|
|
855
858
|
if (!ethers.utils.isAddress(escrowAddress)) {
|
|
856
859
|
throw ErrorInvalidEscrowAddressProvided;
|
|
857
860
|
}
|
|
@@ -865,7 +868,7 @@ export class EscrowClient {
|
|
|
865
868
|
escrowAddress,
|
|
866
869
|
this.signerOrProvider
|
|
867
870
|
);
|
|
868
|
-
return this.escrowContract.
|
|
871
|
+
return this.escrowContract.exchangeOracle();
|
|
869
872
|
} catch (e: any) {
|
|
870
873
|
return throwError(e);
|
|
871
874
|
}
|
|
@@ -898,3 +901,111 @@ export class EscrowClient {
|
|
|
898
901
|
}
|
|
899
902
|
}
|
|
900
903
|
}
|
|
904
|
+
|
|
905
|
+
export class EscrowUtils {
|
|
906
|
+
/**
|
|
907
|
+
* Returns the list of escrows for given filter
|
|
908
|
+
*
|
|
909
|
+
* @param {IEscrowsFilter} filter - Filter parameters.
|
|
910
|
+
* @returns {Promise<EscrowData[]>}
|
|
911
|
+
* @throws {Error} - An error object if an error occurred.
|
|
912
|
+
*/
|
|
913
|
+
public static async getEscrows(
|
|
914
|
+
filter: IEscrowsFilter
|
|
915
|
+
): Promise<EscrowData[]> {
|
|
916
|
+
if (!filter?.networks?.length) {
|
|
917
|
+
throw ErrorUnsupportedChainID;
|
|
918
|
+
}
|
|
919
|
+
if (filter.launcher && !ethers.utils.isAddress(filter.launcher)) {
|
|
920
|
+
throw ErrorInvalidAddress;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (
|
|
924
|
+
filter.recordingOracle &&
|
|
925
|
+
!ethers.utils.isAddress(filter.recordingOracle)
|
|
926
|
+
) {
|
|
927
|
+
throw ErrorInvalidAddress;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
if (
|
|
931
|
+
filter.reputationOracle &&
|
|
932
|
+
!ethers.utils.isAddress(filter.reputationOracle)
|
|
933
|
+
) {
|
|
934
|
+
throw ErrorInvalidAddress;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
if (
|
|
938
|
+
filter.exchangeOracle &&
|
|
939
|
+
!ethers.utils.isAddress(filter.exchangeOracle)
|
|
940
|
+
) {
|
|
941
|
+
throw ErrorInvalidAddress;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
try {
|
|
945
|
+
const escrowAddresses: EscrowData[] = [];
|
|
946
|
+
for (const chainId of filter.networks) {
|
|
947
|
+
const networkData = NETWORKS[chainId];
|
|
948
|
+
|
|
949
|
+
if (!networkData) {
|
|
950
|
+
throw ErrorUnsupportedChainID;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
|
|
954
|
+
networkData.subgraphUrl,
|
|
955
|
+
GET_ESCROWS_QUERY(filter),
|
|
956
|
+
{
|
|
957
|
+
...filter,
|
|
958
|
+
status: filter.status
|
|
959
|
+
? Object.entries(EscrowStatus).find(
|
|
960
|
+
([, value]) => value === filter.status
|
|
961
|
+
)?.[0]
|
|
962
|
+
: undefined,
|
|
963
|
+
from: filter.from ? +filter.from.getTime() / 1000 : undefined,
|
|
964
|
+
to: filter.to ? +filter.to.getTime() / 1000 : undefined,
|
|
965
|
+
}
|
|
966
|
+
);
|
|
967
|
+
escrows.map((escrow) => (escrow.chainId = networkData.chainId));
|
|
968
|
+
escrowAddresses.push(...escrows);
|
|
969
|
+
}
|
|
970
|
+
escrowAddresses.sort((a, b) => Number(b.createdAt) - Number(a.createdAt));
|
|
971
|
+
return escrowAddresses;
|
|
972
|
+
} catch (e: any) {
|
|
973
|
+
return throwError(e);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Returns the escrow for a given address
|
|
979
|
+
*
|
|
980
|
+
* @param {string} escrowAddress - Escrow address.
|
|
981
|
+
* @param {ChainId} chainId - Chain id.
|
|
982
|
+
* @returns {Promise<EscrowData>}
|
|
983
|
+
* @throws {Error} - An error object if an error occurred.
|
|
984
|
+
*/
|
|
985
|
+
public static async getEscrow(
|
|
986
|
+
chainId: ChainId,
|
|
987
|
+
escrowAddress: string
|
|
988
|
+
): Promise<EscrowData> {
|
|
989
|
+
const networkData = NETWORKS[chainId];
|
|
990
|
+
|
|
991
|
+
if (!networkData) {
|
|
992
|
+
throw ErrorUnsupportedChainID;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
if (escrowAddress && !ethers.utils.isAddress(escrowAddress)) {
|
|
996
|
+
throw ErrorInvalidAddress;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
try {
|
|
1000
|
+
const { escrow } = await gqlFetch<{ escrow: EscrowData }>(
|
|
1001
|
+
networkData.subgraphUrl,
|
|
1002
|
+
GET_ESCROW_BY_ADDRESS_QUERY(),
|
|
1003
|
+
{ escrowAddress }
|
|
1004
|
+
);
|
|
1005
|
+
|
|
1006
|
+
return escrow || null;
|
|
1007
|
+
} catch (e: any) {
|
|
1008
|
+
return throwError(e);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
@@ -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 {
|
|
30
|
-
|
|
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
|
|
@@ -0,0 +1,41 @@
|
|
|
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_lte: $to` : ''}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
return gql`
|
|
27
|
+
query getPayouts(
|
|
28
|
+
$escrowAddress: String
|
|
29
|
+
$recipient: String
|
|
30
|
+
$from: Int
|
|
31
|
+
$to: Int
|
|
32
|
+
) {
|
|
33
|
+
payouts(
|
|
34
|
+
${WHERE_CLAUSE}
|
|
35
|
+
) {
|
|
36
|
+
...PayoutFields
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
${PAYOUT_FRAGMENT}
|
|
40
|
+
`;
|
|
41
|
+
};
|
|
@@ -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(
|
|
85
|
+
eventDayDatas(
|
|
86
|
+
${WHERE_CLAUSE},
|
|
87
|
+
orderBy: timestamp,
|
|
88
|
+
orderDirection: desc,
|
|
89
|
+
${LIMIT_CLAUSE}
|
|
90
|
+
) {
|
|
83
91
|
...EventDayDataFields
|
|
84
92
|
}
|
|
85
93
|
}
|
package/src/graphql/types.ts
CHANGED
|
@@ -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 = {
|
|
@@ -130,3 +141,20 @@ export type HMTStatistics = {
|
|
|
130
141
|
holders: HMTHolder[];
|
|
131
142
|
dailyHMTData: DailyHMTData[];
|
|
132
143
|
};
|
|
144
|
+
|
|
145
|
+
export type IMDataEntity = {
|
|
146
|
+
served: number;
|
|
147
|
+
solved: number;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type IMData = Record<string, IMDataEntity>;
|
|
151
|
+
|
|
152
|
+
export type DailyTaskData = {
|
|
153
|
+
timestamp: Date;
|
|
154
|
+
tasksTotal: number;
|
|
155
|
+
tasksSolved: number;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export type TaskStatistics = {
|
|
159
|
+
dailyTasksData: DailyTaskData[];
|
|
160
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StakingClient } from './staking';
|
|
2
2
|
import { StorageClient } from './storage';
|
|
3
3
|
import { KVStoreClient } from './kvstore';
|
|
4
|
-
import { EscrowClient } from './escrow';
|
|
4
|
+
import { EscrowClient, EscrowUtils } from './escrow';
|
|
5
5
|
import { StatisticsClient } from './statistics';
|
|
6
6
|
|
|
7
7
|
export * from './constants';
|
|
@@ -14,5 +14,6 @@ export {
|
|
|
14
14
|
StorageClient,
|
|
15
15
|
KVStoreClient,
|
|
16
16
|
EscrowClient,
|
|
17
|
+
EscrowUtils,
|
|
17
18
|
StatisticsClient,
|
|
18
19
|
};
|
package/src/interfaces.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { BigNumber } from 'ethers';
|
|
2
|
+
import { EscrowStatus } from './types';
|
|
3
|
+
import { ChainId } from './enums';
|
|
2
4
|
|
|
3
5
|
export interface IAllocation {
|
|
4
6
|
escrowAddress: string;
|
|
@@ -13,37 +15,48 @@ export interface IReward {
|
|
|
13
15
|
amount: BigNumber;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
export interface
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
export interface ILeader {
|
|
19
|
+
id: string;
|
|
20
|
+
address: string;
|
|
21
|
+
amountStaked: BigNumber;
|
|
22
|
+
amountAllocated: BigNumber;
|
|
23
|
+
amountLocked: BigNumber;
|
|
24
|
+
lockedUntilTimestamp: BigNumber;
|
|
25
|
+
amountWithdrawn: BigNumber;
|
|
26
|
+
amountSlashed: BigNumber;
|
|
27
|
+
reputation: BigNumber;
|
|
28
|
+
reward: BigNumber;
|
|
29
|
+
amountJobsLaunched: BigNumber;
|
|
30
|
+
role?: string;
|
|
31
|
+
fee?: BigNumber;
|
|
32
|
+
publicKey?: string;
|
|
33
|
+
webhookUrl?: string;
|
|
34
|
+
url?: string;
|
|
23
35
|
}
|
|
24
36
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
| 'Partial'
|
|
29
|
-
| 'Paid'
|
|
30
|
-
| 'Complete'
|
|
31
|
-
| 'Cancelled';
|
|
37
|
+
export interface ILeadersFilter {
|
|
38
|
+
role?: string;
|
|
39
|
+
}
|
|
32
40
|
|
|
33
41
|
export interface IEscrowsFilter {
|
|
34
42
|
launcher?: string;
|
|
35
43
|
reputationOracle?: string;
|
|
36
44
|
recordingOracle?: string;
|
|
45
|
+
exchangeOracle?: string;
|
|
46
|
+
jobRequesterId?: string;
|
|
37
47
|
status?: EscrowStatus;
|
|
38
48
|
from?: Date;
|
|
39
49
|
to?: Date;
|
|
50
|
+
networks: ChainId[];
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
export interface IEscrowConfig {
|
|
43
54
|
recordingOracle: string;
|
|
44
55
|
reputationOracle: string;
|
|
56
|
+
exchangeOracle: string;
|
|
45
57
|
recordingOracleFee: BigNumber;
|
|
46
58
|
reputationOracleFee: BigNumber;
|
|
59
|
+
exchangeOracleFee: BigNumber;
|
|
47
60
|
manifestUrl: string;
|
|
48
61
|
manifestHash: string;
|
|
49
62
|
}
|
|
@@ -58,4 +71,12 @@ export interface IKeyPair {
|
|
|
58
71
|
export interface IStatisticsParams {
|
|
59
72
|
from?: Date;
|
|
60
73
|
to?: Date;
|
|
74
|
+
limit?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface IPayoutFilter {
|
|
78
|
+
escrowAddress?: string;
|
|
79
|
+
recipient?: string;
|
|
80
|
+
from?: Date;
|
|
81
|
+
to?: Date;
|
|
61
82
|
}
|