@human-protocol/sdk 4.0.3 → 4.1.2
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.js +6 -6
- package/dist/escrow.d.ts +47 -27
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +73 -31
- package/dist/graphql/queries/escrow.d.ts.map +1 -1
- package/dist/graphql/queries/hmtoken.d.ts.map +1 -1
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/payout.d.ts +1 -1
- package/dist/graphql/queries/payout.d.ts.map +1 -1
- package/dist/graphql/queries/payout.js +6 -5
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +1 -1
- package/dist/graphql/queries/transaction.d.ts.map +1 -1
- package/dist/graphql/queries/transaction.js +7 -1
- package/dist/graphql/queries/worker.d.ts +4 -0
- package/dist/graphql/queries/worker.d.ts.map +1 -0
- package/dist/graphql/queries/worker.js +44 -0
- package/dist/graphql/types.d.ts +1 -8
- 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 +44 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/statistics.js +2 -2
- package/dist/transaction.d.ts +25 -2
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +28 -2
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/worker.d.ts +63 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +109 -0
- package/package.json +13 -9
- package/src/constants.ts +6 -6
- package/src/escrow.ts +103 -45
- package/src/graphql/queries/payout.ts +7 -6
- package/src/graphql/queries/statistics.ts +1 -1
- package/src/graphql/queries/transaction.ts +17 -2
- package/src/graphql/queries/worker.ts +41 -0
- package/src/graphql/types.ts +1 -9
- package/src/index.ts +2 -0
- package/src/interfaces.ts +48 -1
- package/src/statistics.ts +2 -2
- package/src/transaction.ts +28 -2
- package/src/types.ts +26 -0
- package/src/utils.ts +2 -1
- package/src/worker.ts +120 -0
package/src/escrow.ts
CHANGED
|
@@ -44,16 +44,24 @@ import {
|
|
|
44
44
|
EscrowData,
|
|
45
45
|
GET_ESCROWS_QUERY,
|
|
46
46
|
GET_ESCROW_BY_ADDRESS_QUERY,
|
|
47
|
+
GET_PAYOUTS_QUERY,
|
|
47
48
|
GET_STATUS_UPDATES_QUERY,
|
|
48
49
|
StatusEvent,
|
|
49
50
|
} from './graphql';
|
|
50
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
IEscrow,
|
|
53
|
+
IEscrowConfig,
|
|
54
|
+
IEscrowsFilter,
|
|
55
|
+
IPayoutFilter,
|
|
56
|
+
IStatusEventFilter,
|
|
57
|
+
} from './interfaces';
|
|
51
58
|
import {
|
|
52
59
|
EscrowCancel,
|
|
53
60
|
EscrowStatus,
|
|
54
61
|
EscrowWithdraw,
|
|
55
62
|
NetworkData,
|
|
56
63
|
TransactionLikeWithNonce,
|
|
64
|
+
Payout,
|
|
57
65
|
} from './types';
|
|
58
66
|
import {
|
|
59
67
|
getSubgraphUrl,
|
|
@@ -1611,7 +1619,7 @@ export class EscrowUtils {
|
|
|
1611
1619
|
* ```
|
|
1612
1620
|
*
|
|
1613
1621
|
* ```ts
|
|
1614
|
-
*
|
|
1622
|
+
* interface IEscrow {
|
|
1615
1623
|
* id: string;
|
|
1616
1624
|
* address: string;
|
|
1617
1625
|
* amountPaid: string;
|
|
@@ -1636,7 +1644,7 @@ export class EscrowUtils {
|
|
|
1636
1644
|
*
|
|
1637
1645
|
*
|
|
1638
1646
|
* @param {IEscrowsFilter} filter Filter parameters.
|
|
1639
|
-
* @returns {
|
|
1647
|
+
* @returns {IEscrow[]} List of escrows that match the filter.
|
|
1640
1648
|
*
|
|
1641
1649
|
* **Code example**
|
|
1642
1650
|
*
|
|
@@ -1649,12 +1657,10 @@ export class EscrowUtils {
|
|
|
1649
1657
|
* to: new Date(2023, 5, 8),
|
|
1650
1658
|
* chainId: ChainId.POLYGON_AMOY
|
|
1651
1659
|
* };
|
|
1652
|
-
* const
|
|
1660
|
+
* const escrows = await EscrowUtils.getEscrows(filters);
|
|
1653
1661
|
* ```
|
|
1654
1662
|
*/
|
|
1655
|
-
public static async getEscrows(
|
|
1656
|
-
filter: IEscrowsFilter
|
|
1657
|
-
): Promise<EscrowData[]> {
|
|
1663
|
+
public static async getEscrows(filter: IEscrowsFilter): Promise<IEscrow[]> {
|
|
1658
1664
|
if (filter.launcher && !ethers.isAddress(filter.launcher)) {
|
|
1659
1665
|
throw ErrorInvalidAddress;
|
|
1660
1666
|
}
|
|
@@ -1734,7 +1740,7 @@ export class EscrowUtils {
|
|
|
1734
1740
|
* ```
|
|
1735
1741
|
*
|
|
1736
1742
|
* ```ts
|
|
1737
|
-
*
|
|
1743
|
+
* interface IEscrow {
|
|
1738
1744
|
* id: string;
|
|
1739
1745
|
* address: string;
|
|
1740
1746
|
* amountPaid: string;
|
|
@@ -1760,20 +1766,20 @@ export class EscrowUtils {
|
|
|
1760
1766
|
*
|
|
1761
1767
|
* @param {ChainId} chainId Network in which the escrow has been deployed
|
|
1762
1768
|
* @param {string} escrowAddress Address of the escrow
|
|
1763
|
-
* @returns {
|
|
1769
|
+
* @returns {IEscrow} Escrow data
|
|
1764
1770
|
*
|
|
1765
1771
|
* **Code example**
|
|
1766
1772
|
*
|
|
1767
1773
|
* ```ts
|
|
1768
1774
|
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1769
1775
|
*
|
|
1770
|
-
* const
|
|
1776
|
+
* const escrow = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
|
|
1771
1777
|
* ```
|
|
1772
1778
|
*/
|
|
1773
1779
|
public static async getEscrow(
|
|
1774
1780
|
chainId: ChainId,
|
|
1775
1781
|
escrowAddress: string
|
|
1776
|
-
): Promise<
|
|
1782
|
+
): Promise<IEscrow> {
|
|
1777
1783
|
const networkData = NETWORKS[chainId];
|
|
1778
1784
|
|
|
1779
1785
|
if (!networkData) {
|
|
@@ -1828,14 +1834,7 @@ export class EscrowUtils {
|
|
|
1828
1834
|
* };
|
|
1829
1835
|
* ```
|
|
1830
1836
|
*
|
|
1831
|
-
* @param {
|
|
1832
|
-
* @param {EscrowStatus[]} [statuses] - Optional array of statuses to query for. If not provided, queries for all statuses.
|
|
1833
|
-
* @param {Date} [from] - Optional start date to filter events.
|
|
1834
|
-
* @param {Date} [to] - Optional end date to filter events.
|
|
1835
|
-
* @param {string} [launcher] - Optional launcher address to filter events. Must be a valid Ethereum address.
|
|
1836
|
-
* @param {number} [first] - Optional number of transactions per page. Default is 10.
|
|
1837
|
-
* @param {number} [skip] - Optional number of transactions to skip. Default is 0.
|
|
1838
|
-
* @param {OrderDirection} [orderDirection] - Optional order of the results. Default is DESC.
|
|
1837
|
+
* @param {IStatusEventFilter} filter Filter parameters.
|
|
1839
1838
|
* @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
|
|
1840
1839
|
*
|
|
1841
1840
|
* **Code example**
|
|
@@ -1846,34 +1845,38 @@ export class EscrowUtils {
|
|
|
1846
1845
|
* (async () => {
|
|
1847
1846
|
* const fromDate = new Date('2023-01-01');
|
|
1848
1847
|
* const toDate = new Date('2023-12-31');
|
|
1849
|
-
* const statusEvents = await EscrowUtils.getStatusEvents(
|
|
1850
|
-
*
|
|
1851
|
-
* [EscrowStatus.Pending, EscrowStatus.Complete],
|
|
1852
|
-
* fromDate,
|
|
1853
|
-
* toDate
|
|
1854
|
-
* );
|
|
1848
|
+
* const statusEvents = await EscrowUtils.getStatusEvents({
|
|
1849
|
+
* chainId: ChainId.POLYGON,
|
|
1850
|
+
* statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
|
|
1851
|
+
* from: fromDate,
|
|
1852
|
+
* to: toDate
|
|
1853
|
+
* });
|
|
1855
1854
|
* console.log(statusEvents);
|
|
1856
1855
|
* })();
|
|
1857
1856
|
* ```
|
|
1858
1857
|
*/
|
|
1859
|
-
|
|
1860
1858
|
public static async getStatusEvents(
|
|
1861
|
-
|
|
1862
|
-
statuses?: EscrowStatus[],
|
|
1863
|
-
from?: Date,
|
|
1864
|
-
to?: Date,
|
|
1865
|
-
launcher?: string,
|
|
1866
|
-
first?: number,
|
|
1867
|
-
skip?: number,
|
|
1868
|
-
orderDirection?: OrderDirection
|
|
1859
|
+
filter: IStatusEventFilter
|
|
1869
1860
|
): Promise<StatusEvent[]> {
|
|
1861
|
+
const {
|
|
1862
|
+
chainId,
|
|
1863
|
+
statuses,
|
|
1864
|
+
from,
|
|
1865
|
+
to,
|
|
1866
|
+
launcher,
|
|
1867
|
+
first = 10,
|
|
1868
|
+
skip = 0,
|
|
1869
|
+
orderDirection = OrderDirection.DESC,
|
|
1870
|
+
} = filter;
|
|
1871
|
+
|
|
1870
1872
|
if (launcher && !ethers.isAddress(launcher)) {
|
|
1871
1873
|
throw ErrorInvalidAddress;
|
|
1872
1874
|
}
|
|
1873
1875
|
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1876
|
+
const networkData = NETWORKS[chainId];
|
|
1877
|
+
if (!networkData) {
|
|
1878
|
+
throw ErrorUnsupportedChainID;
|
|
1879
|
+
}
|
|
1877
1880
|
|
|
1878
1881
|
// If statuses are not provided, use all statuses except Launched
|
|
1879
1882
|
const effectiveStatuses = statuses ?? [
|
|
@@ -1885,11 +1888,6 @@ export class EscrowUtils {
|
|
|
1885
1888
|
EscrowStatus.Cancelled,
|
|
1886
1889
|
];
|
|
1887
1890
|
|
|
1888
|
-
const networkData = NETWORKS[chainId];
|
|
1889
|
-
if (!networkData) {
|
|
1890
|
-
throw ErrorUnsupportedChainID;
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
1891
|
const statusNames = effectiveStatuses.map((status) => EscrowStatus[status]);
|
|
1894
1892
|
|
|
1895
1893
|
const data = await gqlFetch<{
|
|
@@ -1902,9 +1900,9 @@ export class EscrowUtils {
|
|
|
1902
1900
|
from: from ? getUnixTimestamp(from) : undefined,
|
|
1903
1901
|
to: to ? getUnixTimestamp(to) : undefined,
|
|
1904
1902
|
launcher: launcher || undefined,
|
|
1905
|
-
orderDirection
|
|
1906
|
-
first: first,
|
|
1907
|
-
skip
|
|
1903
|
+
orderDirection,
|
|
1904
|
+
first: Math.min(first, 1000),
|
|
1905
|
+
skip,
|
|
1908
1906
|
}
|
|
1909
1907
|
);
|
|
1910
1908
|
|
|
@@ -1921,4 +1919,64 @@ export class EscrowUtils {
|
|
|
1921
1919
|
|
|
1922
1920
|
return eventsWithChainId;
|
|
1923
1921
|
}
|
|
1922
|
+
|
|
1923
|
+
/**
|
|
1924
|
+
* This function returns the payouts for a given set of networks.
|
|
1925
|
+
*
|
|
1926
|
+
* > This uses Subgraph
|
|
1927
|
+
*
|
|
1928
|
+
* **Input parameters**
|
|
1929
|
+
* Fetch payouts from the subgraph.
|
|
1930
|
+
*
|
|
1931
|
+
* @param {IPayoutFilter} filter Filter parameters.
|
|
1932
|
+
* @returns {Promise<Payout[]>} List of payouts matching the filters.
|
|
1933
|
+
*
|
|
1934
|
+
* **Code example**
|
|
1935
|
+
*
|
|
1936
|
+
* ```ts
|
|
1937
|
+
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1938
|
+
*
|
|
1939
|
+
* const payouts = await EscrowUtils.getPayouts({
|
|
1940
|
+
* chainId: ChainId.POLYGON,
|
|
1941
|
+
* escrowAddress: '0x1234567890123456789012345678901234567890',
|
|
1942
|
+
* recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
|
|
1943
|
+
* from: new Date('2023-01-01'),
|
|
1944
|
+
* to: new Date('2023-12-31')
|
|
1945
|
+
* });
|
|
1946
|
+
* console.log(payouts);
|
|
1947
|
+
* ```
|
|
1948
|
+
*/
|
|
1949
|
+
public static async getPayouts(filter: IPayoutFilter): Promise<Payout[]> {
|
|
1950
|
+
const networkData = NETWORKS[filter.chainId];
|
|
1951
|
+
if (!networkData) {
|
|
1952
|
+
throw ErrorUnsupportedChainID;
|
|
1953
|
+
}
|
|
1954
|
+
if (filter.escrowAddress && !ethers.isAddress(filter.escrowAddress)) {
|
|
1955
|
+
throw ErrorInvalidAddress;
|
|
1956
|
+
}
|
|
1957
|
+
if (filter.recipient && !ethers.isAddress(filter.recipient)) {
|
|
1958
|
+
throw ErrorInvalidAddress;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
const first =
|
|
1962
|
+
filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
1963
|
+
const skip = filter.skip || 0;
|
|
1964
|
+
const orderDirection = filter.orderDirection || OrderDirection.DESC;
|
|
1965
|
+
|
|
1966
|
+
const { payouts } = await gqlFetch<{ payouts: Payout[] }>(
|
|
1967
|
+
getSubgraphUrl(networkData),
|
|
1968
|
+
GET_PAYOUTS_QUERY(filter),
|
|
1969
|
+
{
|
|
1970
|
+
escrowAddress: filter.escrowAddress?.toLowerCase(),
|
|
1971
|
+
recipient: filter.recipient?.toLowerCase(),
|
|
1972
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
1973
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
1974
|
+
first: Math.min(first, 1000),
|
|
1975
|
+
skip,
|
|
1976
|
+
orderDirection,
|
|
1977
|
+
}
|
|
1978
|
+
);
|
|
1979
|
+
|
|
1980
|
+
return payouts || [];
|
|
1981
|
+
}
|
|
1924
1982
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import gql from 'graphql-tag';
|
|
2
|
-
import { IPayoutFilter } from '
|
|
2
|
+
import { IPayoutFilter } from 'src/interfaces';
|
|
3
3
|
|
|
4
4
|
const PAYOUT_FRAGMENT = gql`
|
|
5
5
|
fragment PayoutFields on Payout {
|
|
@@ -22,9 +22,6 @@ export const GET_PAYOUTS_QUERY = (filter: IPayoutFilter) => {
|
|
|
22
22
|
${to ? `createdAt_lt: $to` : ''}
|
|
23
23
|
}
|
|
24
24
|
`;
|
|
25
|
-
const LIMIT_CLAUSE = `
|
|
26
|
-
first: 1000
|
|
27
|
-
`;
|
|
28
25
|
|
|
29
26
|
return gql`
|
|
30
27
|
query getPayouts(
|
|
@@ -32,12 +29,16 @@ export const GET_PAYOUTS_QUERY = (filter: IPayoutFilter) => {
|
|
|
32
29
|
$recipient: String
|
|
33
30
|
$from: Int
|
|
34
31
|
$to: Int
|
|
32
|
+
$first: Int
|
|
33
|
+
$skip: Int
|
|
34
|
+
$orderDirection: String
|
|
35
35
|
) {
|
|
36
36
|
payouts(
|
|
37
37
|
${WHERE_CLAUSE}
|
|
38
38
|
orderBy: createdAt,
|
|
39
|
-
orderDirection:
|
|
40
|
-
$
|
|
39
|
+
orderDirection: $orderDirection,
|
|
40
|
+
first: $first,
|
|
41
|
+
skip: $skip
|
|
41
42
|
) {
|
|
42
43
|
...PayoutFields
|
|
43
44
|
}
|
|
@@ -27,8 +27,17 @@ const TRANSACTION_FRAGMENT = gql`
|
|
|
27
27
|
`;
|
|
28
28
|
|
|
29
29
|
export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
|
|
30
|
-
const {
|
|
31
|
-
|
|
30
|
+
const {
|
|
31
|
+
startDate,
|
|
32
|
+
endDate,
|
|
33
|
+
startBlock,
|
|
34
|
+
endBlock,
|
|
35
|
+
fromAddress,
|
|
36
|
+
toAddress,
|
|
37
|
+
method,
|
|
38
|
+
escrow,
|
|
39
|
+
token,
|
|
40
|
+
} = filter;
|
|
32
41
|
const addressCondition =
|
|
33
42
|
fromAddress === toAddress
|
|
34
43
|
? `
|
|
@@ -48,6 +57,9 @@ export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
|
|
|
48
57
|
${endDate ? `{timestamp_lte: $endDate},` : ''}
|
|
49
58
|
${startBlock ? `{block_gte: $startBlock},` : ''}
|
|
50
59
|
${endBlock ? `{block_lte: $endBlock},` : ''}
|
|
60
|
+
${method ? `{ method: $method },` : ''}
|
|
61
|
+
${escrow ? `{ escrow: $escrow },` : ''}
|
|
62
|
+
${token ? `{ token: $token },` : ''}
|
|
51
63
|
]
|
|
52
64
|
}
|
|
53
65
|
`;
|
|
@@ -60,6 +72,9 @@ export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
|
|
|
60
72
|
$endDate: Int
|
|
61
73
|
$startBlock: Int
|
|
62
74
|
$endBlock: Int
|
|
75
|
+
$method: String
|
|
76
|
+
$escrow: String
|
|
77
|
+
$token: String
|
|
63
78
|
$orderDirection: String
|
|
64
79
|
$first: Int
|
|
65
80
|
$skip: Int
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import gql from 'graphql-tag';
|
|
2
|
+
import { IWorkersFilter } from '../../interfaces';
|
|
3
|
+
|
|
4
|
+
export const GET_WORKER_QUERY = gql`
|
|
5
|
+
query GetWorker($address: String!) {
|
|
6
|
+
worker(id: $address) {
|
|
7
|
+
id
|
|
8
|
+
address
|
|
9
|
+
totalHMTAmountReceived
|
|
10
|
+
payoutCount
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export const GET_WORKERS_QUERY = (filter: IWorkersFilter) => {
|
|
16
|
+
const { address } = filter;
|
|
17
|
+
|
|
18
|
+
return gql`
|
|
19
|
+
query GetWorkers(
|
|
20
|
+
$address: String
|
|
21
|
+
$first: Int
|
|
22
|
+
$skip: Int
|
|
23
|
+
$orderBy: String
|
|
24
|
+
$orderDirection: String
|
|
25
|
+
) {
|
|
26
|
+
workers(
|
|
27
|
+
where: {
|
|
28
|
+
${address ? 'address: $address,' : ''}
|
|
29
|
+
}
|
|
30
|
+
first: $first
|
|
31
|
+
skip: $skip
|
|
32
|
+
orderBy: $orderBy
|
|
33
|
+
orderDirection: $orderDirection
|
|
34
|
+
) {
|
|
35
|
+
id
|
|
36
|
+
address
|
|
37
|
+
totalHMTAmountReceived
|
|
38
|
+
payoutCount
|
|
39
|
+
}
|
|
40
|
+
}`;
|
|
41
|
+
};
|
package/src/graphql/types.ts
CHANGED
|
@@ -22,14 +22,6 @@ export type EscrowData = {
|
|
|
22
22
|
chainId: number;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export type PayoutData = {
|
|
26
|
-
id: string;
|
|
27
|
-
escrowAddress: string;
|
|
28
|
-
recipient: string;
|
|
29
|
-
amount: string;
|
|
30
|
-
createdAt: string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
25
|
export type HMTStatisticsData = {
|
|
34
26
|
totalTransferEventCount: string;
|
|
35
27
|
totalBulkTransferEventCount: string;
|
|
@@ -66,7 +58,7 @@ export type EventDayData = {
|
|
|
66
58
|
dailyEscrowCount: string;
|
|
67
59
|
dailyWorkerCount: string;
|
|
68
60
|
dailyPayoutCount: string;
|
|
69
|
-
|
|
61
|
+
dailyHMTPayoutAmount: string;
|
|
70
62
|
dailyHMTTransferCount: string;
|
|
71
63
|
dailyHMTTransferAmount: string;
|
|
72
64
|
dailyUniqueSenders: string;
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { StatisticsClient } from './statistics';
|
|
|
6
6
|
import { Encryption, EncryptionUtils } from './encryption';
|
|
7
7
|
import { OperatorUtils } from './operator';
|
|
8
8
|
import { TransactionUtils } from './transaction';
|
|
9
|
+
import { WorkerUtils } from './worker';
|
|
9
10
|
|
|
10
11
|
export * from './constants';
|
|
11
12
|
export * from './types';
|
|
@@ -24,4 +25,5 @@ export {
|
|
|
24
25
|
EncryptionUtils,
|
|
25
26
|
OperatorUtils,
|
|
26
27
|
TransactionUtils,
|
|
28
|
+
WorkerUtils,
|
|
27
29
|
};
|
package/src/interfaces.ts
CHANGED
|
@@ -64,6 +64,28 @@ export interface IOperator {
|
|
|
64
64
|
registrationInstructions?: string;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
export interface IEscrow {
|
|
68
|
+
id: string;
|
|
69
|
+
address: string;
|
|
70
|
+
amountPaid: string;
|
|
71
|
+
balance: string;
|
|
72
|
+
count: string;
|
|
73
|
+
factoryAddress: string;
|
|
74
|
+
finalResultsUrl?: string;
|
|
75
|
+
intermediateResultsUrl?: string;
|
|
76
|
+
launcher: string;
|
|
77
|
+
manifestHash?: string;
|
|
78
|
+
manifestUrl?: string;
|
|
79
|
+
recordingOracle?: string;
|
|
80
|
+
reputationOracle?: string;
|
|
81
|
+
exchangeOracle?: string;
|
|
82
|
+
status: string;
|
|
83
|
+
token: string;
|
|
84
|
+
totalFundedAmount: string;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
chainId: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
67
89
|
export interface IEscrowsFilter extends IPagination {
|
|
68
90
|
launcher?: string;
|
|
69
91
|
reputationOracle?: string;
|
|
@@ -103,7 +125,8 @@ export interface IHMTHoldersParams extends IPagination {
|
|
|
103
125
|
address?: string;
|
|
104
126
|
}
|
|
105
127
|
|
|
106
|
-
export interface IPayoutFilter {
|
|
128
|
+
export interface IPayoutFilter extends IPagination {
|
|
129
|
+
chainId: ChainId;
|
|
107
130
|
escrowAddress?: string;
|
|
108
131
|
recipient?: string;
|
|
109
132
|
from?: Date;
|
|
@@ -147,6 +170,9 @@ export interface ITransactionsFilter extends IPagination {
|
|
|
147
170
|
endDate?: Date;
|
|
148
171
|
fromAddress?: string;
|
|
149
172
|
toAddress?: string;
|
|
173
|
+
method?: string;
|
|
174
|
+
escrow?: string;
|
|
175
|
+
token?: string;
|
|
150
176
|
}
|
|
151
177
|
|
|
152
178
|
export interface IPagination {
|
|
@@ -161,3 +187,24 @@ export interface StakerInfo {
|
|
|
161
187
|
lockedUntil: bigint;
|
|
162
188
|
withdrawableAmount: bigint;
|
|
163
189
|
}
|
|
190
|
+
|
|
191
|
+
export interface IStatusEventFilter extends IPagination {
|
|
192
|
+
chainId: ChainId;
|
|
193
|
+
statuses?: EscrowStatus[];
|
|
194
|
+
from?: Date;
|
|
195
|
+
to?: Date;
|
|
196
|
+
launcher?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface IWorker {
|
|
200
|
+
id: string;
|
|
201
|
+
address: string;
|
|
202
|
+
totalHMTAmountReceived: number;
|
|
203
|
+
payoutCount: number;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface IWorkersFilter extends IPagination {
|
|
207
|
+
chainId: ChainId;
|
|
208
|
+
address?: string;
|
|
209
|
+
orderBy?: string;
|
|
210
|
+
}
|
package/src/statistics.ts
CHANGED
|
@@ -319,12 +319,12 @@ export class StatisticsClient {
|
|
|
319
319
|
return {
|
|
320
320
|
dailyPaymentsData: eventDayDatas.map((eventDayData) => ({
|
|
321
321
|
timestamp: new Date(+eventDayData.timestamp * 1000),
|
|
322
|
-
totalAmountPaid: ethers.toBigInt(eventDayData.
|
|
322
|
+
totalAmountPaid: ethers.toBigInt(eventDayData.dailyHMTPayoutAmount),
|
|
323
323
|
totalCount: +eventDayData.dailyPayoutCount,
|
|
324
324
|
averageAmountPerWorker:
|
|
325
325
|
eventDayData.dailyWorkerCount === '0'
|
|
326
326
|
? ethers.toBigInt(0)
|
|
327
|
-
: ethers.toBigInt(eventDayData.
|
|
327
|
+
: ethers.toBigInt(eventDayData.dailyHMTPayoutAmount) /
|
|
328
328
|
ethers.toBigInt(eventDayData.dailyWorkerCount),
|
|
329
329
|
})),
|
|
330
330
|
};
|
package/src/transaction.ts
CHANGED
|
@@ -19,6 +19,22 @@ export class TransactionUtils {
|
|
|
19
19
|
/**
|
|
20
20
|
* This function returns the transaction data for the given hash.
|
|
21
21
|
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* type ITransaction = {
|
|
24
|
+
* block: bigint;
|
|
25
|
+
* txHash: string;
|
|
26
|
+
* from: string;
|
|
27
|
+
* to: string;
|
|
28
|
+
* timestamp: bigint;
|
|
29
|
+
* value: string;
|
|
30
|
+
* method: string;
|
|
31
|
+
* receiver?: string;
|
|
32
|
+
* escrow?: string;
|
|
33
|
+
* token?: string;
|
|
34
|
+
* internalTransactions: InternalTransaction[];
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
22
38
|
* @param {ChainId} chainId The chain ID.
|
|
23
39
|
* @param {string} hash The transaction hash.
|
|
24
40
|
* @returns {Promise<ITransaction>} Returns the transaction details.
|
|
@@ -65,6 +81,9 @@ export class TransactionUtils {
|
|
|
65
81
|
* chainId: ChainId; // List of chain IDs to query.
|
|
66
82
|
* fromAddress?: string; // (Optional) The address from which transactions are sent.
|
|
67
83
|
* toAddress?: string; // (Optional) The address to which transactions are sent.
|
|
84
|
+
* method?: string; // (Optional) The method of the transaction to filter by.
|
|
85
|
+
* escrow?: string; // (Optional) The escrow address to filter transactions.
|
|
86
|
+
* token?: string; // (Optional) The token address to filter transactions.
|
|
68
87
|
* startDate?: Date; // (Optional) The start date to filter transactions (inclusive).
|
|
69
88
|
* endDate?: Date; // (Optional) The end date to filter transactions (inclusive).
|
|
70
89
|
* startBlock?: number; // (Optional) The start block number to filter transactions (inclusive).
|
|
@@ -77,13 +96,17 @@ export class TransactionUtils {
|
|
|
77
96
|
*
|
|
78
97
|
* ```ts
|
|
79
98
|
* type ITransaction = {
|
|
80
|
-
* block:
|
|
99
|
+
* block: bigint;
|
|
81
100
|
* txHash: string;
|
|
82
101
|
* from: string;
|
|
83
102
|
* to: string;
|
|
84
|
-
* timestamp:
|
|
103
|
+
* timestamp: bigint;
|
|
85
104
|
* value: string;
|
|
86
105
|
* method: string;
|
|
106
|
+
* receiver?: string;
|
|
107
|
+
* escrow?: string;
|
|
108
|
+
* token?: string;
|
|
109
|
+
* internalTransactions: InternalTransaction[];
|
|
87
110
|
* };
|
|
88
111
|
* ```
|
|
89
112
|
*
|
|
@@ -137,6 +160,9 @@ export class TransactionUtils {
|
|
|
137
160
|
endDate: filter.endDate ? getUnixTimestamp(filter.endDate) : undefined,
|
|
138
161
|
startBlock: filter.startBlock ? filter.startBlock : undefined,
|
|
139
162
|
endBlock: filter.endBlock ? filter.endBlock : undefined,
|
|
163
|
+
method: filter.method ? filter.method : undefined,
|
|
164
|
+
escrow: filter.escrow ? filter.escrow : undefined,
|
|
165
|
+
token: filter.token ? filter.token : undefined,
|
|
140
166
|
orderDirection: orderDirection,
|
|
141
167
|
first: first,
|
|
142
168
|
skip: skip,
|
package/src/types.ts
CHANGED
|
@@ -171,4 +171,30 @@ export type EscrowWithdraw = {
|
|
|
171
171
|
amountWithdrawn: bigint;
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Represents a payout from an escrow.
|
|
176
|
+
*/
|
|
177
|
+
export type Payout = {
|
|
178
|
+
/**
|
|
179
|
+
* Unique identifier of the payout.
|
|
180
|
+
*/
|
|
181
|
+
id: string;
|
|
182
|
+
/**
|
|
183
|
+
* The address of the escrow associated with the payout.
|
|
184
|
+
*/
|
|
185
|
+
escrowAddress: string;
|
|
186
|
+
/**
|
|
187
|
+
* The address of the recipient who received the payout.
|
|
188
|
+
*/
|
|
189
|
+
recipient: string;
|
|
190
|
+
/**
|
|
191
|
+
* The amount paid to the recipient.
|
|
192
|
+
*/
|
|
193
|
+
amount: bigint;
|
|
194
|
+
/**
|
|
195
|
+
* The timestamp when the payout was created (in UNIX format).
|
|
196
|
+
*/
|
|
197
|
+
createdAt: number;
|
|
198
|
+
};
|
|
199
|
+
|
|
174
200
|
export type TransactionLikeWithNonce = TransactionLike & { nonce: number };
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
3
|
|
|
4
|
+
import { ChainId } from './enums';
|
|
4
5
|
import {
|
|
5
6
|
ContractExecutionError,
|
|
6
7
|
EthereumError,
|
|
@@ -66,7 +67,7 @@ export const getSubgraphUrl = (networkData: NetworkData) => {
|
|
|
66
67
|
SUBGRAPH_API_KEY_PLACEHOLDER,
|
|
67
68
|
process.env.SUBGRAPH_API_KEY
|
|
68
69
|
);
|
|
69
|
-
} else {
|
|
70
|
+
} else if (networkData.chainId !== ChainId.LOCALHOST) {
|
|
70
71
|
// eslint-disable-next-line no-console
|
|
71
72
|
console.warn(WarnSubgraphApiKeyNotProvided);
|
|
72
73
|
}
|