@human-protocol/sdk 3.0.0 → 3.0.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/README.md +23 -80
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- 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 -11
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +153 -43
- 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 -12
- 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/kvstore.d.ts +1 -0
- package/dist/graphql/queries/kvstore.d.ts.map +1 -1
- package/dist/graphql/queries/kvstore.js +12 -1
- package/dist/graphql/queries/operator.js +1 -1
- package/dist/graphql/queries/statistics.d.ts +2 -2
- package/dist/graphql/queries/statistics.d.ts.map +1 -1
- package/dist/graphql/queries/statistics.js +13 -7
- 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 -5
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/interfaces.d.ts +16 -9
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +69 -106
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +123 -159
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +64 -81
- package/dist/statistics.d.ts +91 -59
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +162 -85
- 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/constants.ts +1 -0
- package/src/enums.ts +5 -0
- package/src/error.ts +8 -0
- package/src/escrow.ts +197 -54
- package/src/graphql/queries/escrow.ts +53 -11
- package/src/graphql/queries/hmtoken.ts +23 -7
- package/src/graphql/queries/kvstore.ts +11 -0
- package/src/graphql/queries/operator.ts +1 -1
- package/src/graphql/queries/statistics.ts +15 -9
- package/src/graphql/queries/transaction.ts +12 -7
- package/src/graphql/types.ts +13 -5
- package/src/index.ts +4 -1
- package/src/interfaces.ts +18 -9
- package/src/kvstore.ts +145 -158
- package/src/operator.ts +79 -91
- package/src/statistics.ts +186 -96
- package/src/transaction.ts +40 -30
package/src/escrow.ts
CHANGED
|
@@ -12,7 +12,7 @@ import gqlFetch from 'graphql-request';
|
|
|
12
12
|
import { BaseEthersClient } from './base';
|
|
13
13
|
import { DEFAULT_TX_ID, NETWORKS } from './constants';
|
|
14
14
|
import { requiresSigner } from './decorators';
|
|
15
|
-
import { ChainId } from './enums';
|
|
15
|
+
import { ChainId, OrderDirection } from './enums';
|
|
16
16
|
import {
|
|
17
17
|
ErrorAmountMustBeGreaterThanZero,
|
|
18
18
|
ErrorAmountsCannotBeEmptyArray,
|
|
@@ -41,6 +41,8 @@ import {
|
|
|
41
41
|
EscrowData,
|
|
42
42
|
GET_ESCROWS_QUERY,
|
|
43
43
|
GET_ESCROW_BY_ADDRESS_QUERY,
|
|
44
|
+
GET_STATUS_UPDATES_QUERY,
|
|
45
|
+
StatusEvent,
|
|
44
46
|
} from './graphql';
|
|
45
47
|
import { IEscrowConfig, IEscrowsFilter } from './interfaces';
|
|
46
48
|
import { EscrowCancel, EscrowStatus, NetworkData } from './types';
|
|
@@ -1399,7 +1401,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1399
1401
|
* import { ChainId, EscrowUtils } from '@human-protocol/sdk';
|
|
1400
1402
|
*
|
|
1401
1403
|
* const escrowAddresses = new EscrowUtils.getEscrows({
|
|
1402
|
-
*
|
|
1404
|
+
* network: ChainId.POLYGON_AMOY
|
|
1403
1405
|
* });
|
|
1404
1406
|
* ```
|
|
1405
1407
|
*/
|
|
@@ -1412,7 +1414,7 @@ export class EscrowUtils {
|
|
|
1412
1414
|
*
|
|
1413
1415
|
* ```ts
|
|
1414
1416
|
* interface IEscrowsFilter {
|
|
1415
|
-
*
|
|
1417
|
+
* chainId: ChainId;
|
|
1416
1418
|
* launcher?: string;
|
|
1417
1419
|
* reputationOracle?: string;
|
|
1418
1420
|
* recordingOracle?: string;
|
|
@@ -1421,6 +1423,9 @@ export class EscrowUtils {
|
|
|
1421
1423
|
* status?: EscrowStatus;
|
|
1422
1424
|
* from?: Date;
|
|
1423
1425
|
* to?: Date;
|
|
1426
|
+
* first?: number;
|
|
1427
|
+
* skip?: number;
|
|
1428
|
+
* orderDirection?: OrderDirection;
|
|
1424
1429
|
* }
|
|
1425
1430
|
* ```
|
|
1426
1431
|
*
|
|
@@ -1447,6 +1452,13 @@ export class EscrowUtils {
|
|
|
1447
1452
|
* ```
|
|
1448
1453
|
*
|
|
1449
1454
|
* ```ts
|
|
1455
|
+
* enum OrderDirection {
|
|
1456
|
+
* ASC = 'asc',
|
|
1457
|
+
* DESC = 'desc',
|
|
1458
|
+
* }
|
|
1459
|
+
* ```
|
|
1460
|
+
*
|
|
1461
|
+
* ```ts
|
|
1450
1462
|
* enum EscrowStatus {
|
|
1451
1463
|
* Launched,
|
|
1452
1464
|
* Pending,
|
|
@@ -1472,11 +1484,8 @@ export class EscrowUtils {
|
|
|
1472
1484
|
* manifestHash?: string;
|
|
1473
1485
|
* manifestUrl?: string;
|
|
1474
1486
|
* recordingOracle?: string;
|
|
1475
|
-
* recordingOracleFee?: string;
|
|
1476
1487
|
* reputationOracle?: string;
|
|
1477
|
-
* reputationOracleFee?: string;
|
|
1478
1488
|
* exchangeOracle?: string;
|
|
1479
|
-
* exchangeOracleFee?: string;
|
|
1480
1489
|
* status: EscrowStatus;
|
|
1481
1490
|
* token: string;
|
|
1482
1491
|
* totalFundedAmount: string;
|
|
@@ -1497,7 +1506,7 @@ export class EscrowUtils {
|
|
|
1497
1506
|
* status: EscrowStatus.Pending,
|
|
1498
1507
|
* from: new Date(2023, 4, 8),
|
|
1499
1508
|
* to: new Date(2023, 5, 8),
|
|
1500
|
-
*
|
|
1509
|
+
* chainId: ChainId.POLYGON_AMOY
|
|
1501
1510
|
* };
|
|
1502
1511
|
* const escrowDatas = await EscrowUtils.getEscrows(filters);
|
|
1503
1512
|
* ```
|
|
@@ -1505,9 +1514,6 @@ export class EscrowUtils {
|
|
|
1505
1514
|
public static async getEscrows(
|
|
1506
1515
|
filter: IEscrowsFilter
|
|
1507
1516
|
): Promise<EscrowData[]> {
|
|
1508
|
-
if (!filter?.networks?.length) {
|
|
1509
|
-
throw ErrorUnsupportedChainID;
|
|
1510
|
-
}
|
|
1511
1517
|
if (filter.launcher && !ethers.isAddress(filter.launcher)) {
|
|
1512
1518
|
throw ErrorInvalidAddress;
|
|
1513
1519
|
}
|
|
@@ -1524,42 +1530,46 @@ export class EscrowUtils {
|
|
|
1524
1530
|
throw ErrorInvalidAddress;
|
|
1525
1531
|
}
|
|
1526
1532
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1533
|
+
const first =
|
|
1534
|
+
filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
1535
|
+
const skip = filter.skip || 0;
|
|
1536
|
+
const orderDirection = filter.orderDirection || OrderDirection.DESC;
|
|
1531
1537
|
|
|
1532
|
-
|
|
1533
|
-
throw ErrorUnsupportedChainID;
|
|
1534
|
-
}
|
|
1538
|
+
const networkData = NETWORKS[filter.chainId];
|
|
1535
1539
|
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1540
|
+
if (!networkData) {
|
|
1541
|
+
throw ErrorUnsupportedChainID;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
|
|
1545
|
+
getSubgraphUrl(networkData),
|
|
1546
|
+
GET_ESCROWS_QUERY(filter),
|
|
1547
|
+
{
|
|
1548
|
+
...filter,
|
|
1549
|
+
launcher: filter.launcher?.toLowerCase(),
|
|
1550
|
+
reputationOracle: filter.reputationOracle?.toLowerCase(),
|
|
1551
|
+
recordingOracle: filter.recordingOracle?.toLowerCase(),
|
|
1552
|
+
exchangeOracle: filter.exchangeOracle?.toLowerCase(),
|
|
1553
|
+
status:
|
|
1554
|
+
filter.status !== undefined
|
|
1555
|
+
? Object.entries(EscrowStatus).find(
|
|
1556
|
+
([, value]) => value === filter.status
|
|
1557
|
+
)?.[0]
|
|
1558
|
+
: undefined,
|
|
1559
|
+
from: filter.from ? +filter.from.getTime() / 1000 : undefined,
|
|
1560
|
+
to: filter.to ? +filter.to.getTime() / 1000 : undefined,
|
|
1561
|
+
orderDirection: orderDirection,
|
|
1562
|
+
first: first,
|
|
1563
|
+
skip: skip,
|
|
1557
1564
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1565
|
+
);
|
|
1566
|
+
escrows.map((escrow) => (escrow.chainId = networkData.chainId));
|
|
1567
|
+
|
|
1568
|
+
if (!escrows) {
|
|
1569
|
+
return [];
|
|
1562
1570
|
}
|
|
1571
|
+
|
|
1572
|
+
return escrows;
|
|
1563
1573
|
}
|
|
1564
1574
|
|
|
1565
1575
|
/**
|
|
@@ -1605,11 +1615,8 @@ export class EscrowUtils {
|
|
|
1605
1615
|
* manifestHash?: string;
|
|
1606
1616
|
* manifestUrl?: string;
|
|
1607
1617
|
* recordingOracle?: string;
|
|
1608
|
-
* recordingOracleFee?: string;
|
|
1609
1618
|
* reputationOracle?: string;
|
|
1610
|
-
* reputationOracleFee?: string;
|
|
1611
1619
|
* exchangeOracle?: string;
|
|
1612
|
-
* exchangeOracleFee?: string;
|
|
1613
1620
|
* status: EscrowStatus;
|
|
1614
1621
|
* token: string;
|
|
1615
1622
|
* totalFundedAmount: string;
|
|
@@ -1644,16 +1651,152 @@ export class EscrowUtils {
|
|
|
1644
1651
|
throw ErrorInvalidAddress;
|
|
1645
1652
|
}
|
|
1646
1653
|
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
);
|
|
1654
|
+
const { escrow } = await gqlFetch<{ escrow: EscrowData }>(
|
|
1655
|
+
getSubgraphUrl(networkData),
|
|
1656
|
+
GET_ESCROW_BY_ADDRESS_QUERY(),
|
|
1657
|
+
{ escrowAddress: escrowAddress.toLowerCase() }
|
|
1658
|
+
);
|
|
1653
1659
|
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1660
|
+
return escrow || null;
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
/**
|
|
1664
|
+
* This function returns the status events for a given set of networks within an optional date range.
|
|
1665
|
+
*
|
|
1666
|
+
* > This uses Subgraph
|
|
1667
|
+
*
|
|
1668
|
+
* **Input parameters**
|
|
1669
|
+
*
|
|
1670
|
+
* ```ts
|
|
1671
|
+
* enum ChainId {
|
|
1672
|
+
* ALL = -1,
|
|
1673
|
+
* MAINNET = 1,
|
|
1674
|
+
* RINKEBY = 4,
|
|
1675
|
+
* GOERLI = 5,
|
|
1676
|
+
* SEPOLIA = 11155111,
|
|
1677
|
+
* BSC_MAINNET = 56,
|
|
1678
|
+
* BSC_TESTNET = 97,
|
|
1679
|
+
* POLYGON = 137,
|
|
1680
|
+
* POLYGON_MUMBAI = 80001,
|
|
1681
|
+
* POLYGON_AMOY = 80002,
|
|
1682
|
+
* MOONBEAM = 1284,
|
|
1683
|
+
* MOONBASE_ALPHA = 1287,
|
|
1684
|
+
* AVALANCHE = 43114,
|
|
1685
|
+
* AVALANCHE_TESTNET = 43113,
|
|
1686
|
+
* CELO = 42220,
|
|
1687
|
+
* CELO_ALFAJORES = 44787,
|
|
1688
|
+
* LOCALHOST = 1338,
|
|
1689
|
+
* XLAYER_TESTNET = 195,
|
|
1690
|
+
* XLAYER = 196,
|
|
1691
|
+
* }
|
|
1692
|
+
* ```
|
|
1693
|
+
*
|
|
1694
|
+
* ```ts
|
|
1695
|
+
* enum OrderDirection {
|
|
1696
|
+
* ASC = 'asc',
|
|
1697
|
+
* DESC = 'desc',
|
|
1698
|
+
* }
|
|
1699
|
+
* ```
|
|
1700
|
+
*
|
|
1701
|
+
* ```ts
|
|
1702
|
+
* type Status = {
|
|
1703
|
+
* escrowAddress: string;
|
|
1704
|
+
* timestamp: string;
|
|
1705
|
+
* status: string;
|
|
1706
|
+
* };
|
|
1707
|
+
* ```
|
|
1708
|
+
*
|
|
1709
|
+
* @param {ChainId} chainId - List of network IDs to query for status events.
|
|
1710
|
+
* @param {EscrowStatus[]} [statuses] - Optional array of statuses to query for. If not provided, queries for all statuses.
|
|
1711
|
+
* @param {Date} [from] - Optional start date to filter events.
|
|
1712
|
+
* @param {Date} [to] - Optional end date to filter events.
|
|
1713
|
+
* @param {string} [launcher] - Optional launcher address to filter events. Must be a valid Ethereum address.
|
|
1714
|
+
* @param {number} [first] - Optional number of transactions per page. Default is 10.
|
|
1715
|
+
* @param {number} [skip] - Optional number of transactions to skip. Default is 0.
|
|
1716
|
+
* @param {OrderDirection} [orderDirection] - Optional order of the results. Default is DESC.
|
|
1717
|
+
* @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
|
|
1718
|
+
*
|
|
1719
|
+
* **Code example**
|
|
1720
|
+
*
|
|
1721
|
+
* ```ts
|
|
1722
|
+
* import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
|
|
1723
|
+
*
|
|
1724
|
+
* (async () => {
|
|
1725
|
+
* const fromDate = new Date('2023-01-01');
|
|
1726
|
+
* const toDate = new Date('2023-12-31');
|
|
1727
|
+
* const statusEvents = await EscrowUtils.getStatusEvents(
|
|
1728
|
+
* [ChainId.POLYGON, ChainId.MAINNET],
|
|
1729
|
+
* [EscrowStatus.Pending, EscrowStatus.Complete],
|
|
1730
|
+
* fromDate,
|
|
1731
|
+
* toDate
|
|
1732
|
+
* );
|
|
1733
|
+
* console.log(statusEvents);
|
|
1734
|
+
* })();
|
|
1735
|
+
* ```
|
|
1736
|
+
*/
|
|
1737
|
+
|
|
1738
|
+
public static async getStatusEvents(
|
|
1739
|
+
chainId: ChainId,
|
|
1740
|
+
statuses?: EscrowStatus[],
|
|
1741
|
+
from?: Date,
|
|
1742
|
+
to?: Date,
|
|
1743
|
+
launcher?: string,
|
|
1744
|
+
first?: number,
|
|
1745
|
+
skip?: number,
|
|
1746
|
+
orderDirection?: OrderDirection
|
|
1747
|
+
): Promise<StatusEvent[]> {
|
|
1748
|
+
if (launcher && !ethers.isAddress(launcher)) {
|
|
1749
|
+
throw ErrorInvalidAddress;
|
|
1657
1750
|
}
|
|
1751
|
+
|
|
1752
|
+
first = first !== undefined ? Math.min(first, 1000) : 10;
|
|
1753
|
+
skip = skip || 0;
|
|
1754
|
+
orderDirection = orderDirection || OrderDirection.DESC;
|
|
1755
|
+
|
|
1756
|
+
// If statuses are not provided, use all statuses except Launched
|
|
1757
|
+
const effectiveStatuses = statuses ?? [
|
|
1758
|
+
EscrowStatus.Launched,
|
|
1759
|
+
EscrowStatus.Pending,
|
|
1760
|
+
EscrowStatus.Partial,
|
|
1761
|
+
EscrowStatus.Paid,
|
|
1762
|
+
EscrowStatus.Complete,
|
|
1763
|
+
EscrowStatus.Cancelled,
|
|
1764
|
+
];
|
|
1765
|
+
|
|
1766
|
+
const networkData = NETWORKS[chainId];
|
|
1767
|
+
if (!networkData) {
|
|
1768
|
+
throw ErrorUnsupportedChainID;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
const statusNames = effectiveStatuses.map((status) => EscrowStatus[status]);
|
|
1772
|
+
|
|
1773
|
+
const data = await gqlFetch<{
|
|
1774
|
+
escrowStatusEvents: StatusEvent[];
|
|
1775
|
+
}>(
|
|
1776
|
+
getSubgraphUrl(networkData),
|
|
1777
|
+
GET_STATUS_UPDATES_QUERY(from, to, launcher),
|
|
1778
|
+
{
|
|
1779
|
+
status: statusNames,
|
|
1780
|
+
from: from ? Math.floor(from.getTime() / 1000) : undefined,
|
|
1781
|
+
to: to ? Math.floor(to.getTime() / 1000) : undefined,
|
|
1782
|
+
launcher: launcher || undefined,
|
|
1783
|
+
orderDirection: orderDirection,
|
|
1784
|
+
first: first,
|
|
1785
|
+
skip: skip,
|
|
1786
|
+
}
|
|
1787
|
+
);
|
|
1788
|
+
|
|
1789
|
+
if (!data || !data['escrowStatusEvents']) {
|
|
1790
|
+
return [];
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
const statusEvents = data['escrowStatusEvents'] as StatusEvent[];
|
|
1794
|
+
|
|
1795
|
+
const eventsWithChainId = statusEvents.map((event) => ({
|
|
1796
|
+
...event,
|
|
1797
|
+
chainId,
|
|
1798
|
+
}));
|
|
1799
|
+
|
|
1800
|
+
return eventsWithChainId;
|
|
1658
1801
|
}
|
|
1659
1802
|
}
|
|
@@ -16,11 +16,8 @@ const ESCROW_FRAGMENT = gql`
|
|
|
16
16
|
manifestHash
|
|
17
17
|
manifestUrl
|
|
18
18
|
recordingOracle
|
|
19
|
-
recordingOracleFee
|
|
20
19
|
reputationOracle
|
|
21
|
-
reputationOracleFee
|
|
22
20
|
exchangeOracle
|
|
23
|
-
exchangeOracleFee
|
|
24
21
|
status
|
|
25
22
|
token
|
|
26
23
|
totalFundedAmount
|
|
@@ -51,14 +48,14 @@ export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
|
|
|
51
48
|
|
|
52
49
|
const WHERE_CLAUSE = `
|
|
53
50
|
where: {
|
|
54
|
-
${launcher ? `launcher: $launcher
|
|
55
|
-
${jobRequesterId ? `jobRequesterId: $jobRequesterId
|
|
56
|
-
${reputationOracle ? `reputationOracle: $reputationOracle
|
|
57
|
-
${recordingOracle ? `recordingOracle: $recordingOracle
|
|
58
|
-
${exchangeOracle ? `exchangeOracle: $exchangeOracle
|
|
59
|
-
${status !== undefined ? `status: $status
|
|
60
|
-
${from ? `createdAt_gte: $from
|
|
61
|
-
${to ? `createdAt_lte: $to
|
|
51
|
+
${launcher ? `launcher: $launcher,` : ''}
|
|
52
|
+
${jobRequesterId ? `jobRequesterId: $jobRequesterId,` : ''}
|
|
53
|
+
${reputationOracle ? `reputationOracle: $reputationOracle,` : ''}
|
|
54
|
+
${recordingOracle ? `recordingOracle: $recordingOracle,` : ''}
|
|
55
|
+
${exchangeOracle ? `exchangeOracle: $exchangeOracle,` : ''}
|
|
56
|
+
${status !== undefined ? `status: $status,` : ''}
|
|
57
|
+
${from ? `createdAt_gte: $from,` : ''}
|
|
58
|
+
${to ? `createdAt_lte: $to,` : ''}
|
|
62
59
|
}
|
|
63
60
|
`;
|
|
64
61
|
|
|
@@ -72,9 +69,16 @@ export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
|
|
|
72
69
|
$status: String
|
|
73
70
|
$from: Int
|
|
74
71
|
$to: Int
|
|
72
|
+
$orderDirection: String
|
|
73
|
+
$first: Int
|
|
74
|
+
$skip: Int
|
|
75
75
|
) {
|
|
76
76
|
escrows(
|
|
77
77
|
${WHERE_CLAUSE}
|
|
78
|
+
orderBy: createdAt,
|
|
79
|
+
orderDirection: $orderDirection,
|
|
80
|
+
first: $first,
|
|
81
|
+
skip: $skip
|
|
78
82
|
) {
|
|
79
83
|
...EscrowFields
|
|
80
84
|
}
|
|
@@ -82,3 +86,41 @@ export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
|
|
|
82
86
|
${ESCROW_FRAGMENT}
|
|
83
87
|
`;
|
|
84
88
|
};
|
|
89
|
+
|
|
90
|
+
export const GET_STATUS_UPDATES_QUERY = (
|
|
91
|
+
from?: Date,
|
|
92
|
+
to?: Date,
|
|
93
|
+
launcher?: string
|
|
94
|
+
) => {
|
|
95
|
+
const WHERE_CLAUSE = `
|
|
96
|
+
where: {
|
|
97
|
+
status_in: $status
|
|
98
|
+
${from ? `timestamp_gte: $from` : ''}
|
|
99
|
+
${to ? `timestamp_lte: $to` : ''}
|
|
100
|
+
${launcher ? `launcher: $launcher` : ''}
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
return gql`
|
|
104
|
+
query getStatus(
|
|
105
|
+
$status: [String!]!
|
|
106
|
+
$from: Int
|
|
107
|
+
$to: Int
|
|
108
|
+
$launcher: String
|
|
109
|
+
$orderDirection: String
|
|
110
|
+
$first: Int
|
|
111
|
+
$skip: Int
|
|
112
|
+
) {
|
|
113
|
+
escrowStatusEvents(
|
|
114
|
+
${WHERE_CLAUSE}
|
|
115
|
+
orderBy: timestamp,
|
|
116
|
+
orderDirection: $orderDirection,
|
|
117
|
+
first: $first,
|
|
118
|
+
skip: $skip
|
|
119
|
+
) {
|
|
120
|
+
escrowAddress,
|
|
121
|
+
timestamp,
|
|
122
|
+
status,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -21,3 +21,14 @@ export const GET_KVSTORE_BY_ADDRESS_QUERY = () => {
|
|
|
21
21
|
${KVSTORE_FRAGMENT}
|
|
22
22
|
`;
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
export const GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY = () => {
|
|
26
|
+
return gql`
|
|
27
|
+
query getKVStoreDataByKey($address: String!, $key: String!) {
|
|
28
|
+
kvstores(where: { address: $address, key: $key }) {
|
|
29
|
+
...KVStoreFields
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
${KVSTORE_FRAGMENT}
|
|
33
|
+
`;
|
|
34
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import gql from 'graphql-tag';
|
|
2
|
-
import {
|
|
2
|
+
import { IStatisticsFilter } from '../../interfaces';
|
|
3
3
|
|
|
4
4
|
const HMTOKEN_STATISTICS_FRAGMENT = gql`
|
|
5
5
|
fragment HMTokenStatisticsFields on HMTokenStatistics {
|
|
@@ -47,6 +47,8 @@ const EVENT_DAY_DATA_FRAGMENT = gql`
|
|
|
47
47
|
dailyPayoutAmount
|
|
48
48
|
dailyHMTTransferCount
|
|
49
49
|
dailyHMTTransferAmount
|
|
50
|
+
dailyUniqueSenders
|
|
51
|
+
dailyUniqueReceivers
|
|
50
52
|
}
|
|
51
53
|
`;
|
|
52
54
|
|
|
@@ -68,25 +70,29 @@ export const GET_ESCROW_STATISTICS_QUERY = gql`
|
|
|
68
70
|
${ESCROW_STATISTICS_FRAGMENT}
|
|
69
71
|
`;
|
|
70
72
|
|
|
71
|
-
export const GET_EVENT_DAY_DATA_QUERY = (params:
|
|
72
|
-
const { from, to
|
|
73
|
+
export const GET_EVENT_DAY_DATA_QUERY = (params: IStatisticsFilter) => {
|
|
74
|
+
const { from, to } = params;
|
|
73
75
|
const WHERE_CLAUSE = `
|
|
74
76
|
where: {
|
|
75
77
|
${from !== undefined ? `timestamp_gte: $from` : ''}
|
|
76
78
|
${to !== undefined ? `timestamp_lte: $to` : ''}
|
|
77
79
|
}
|
|
78
80
|
`;
|
|
79
|
-
const LIMIT_CLAUSE = `
|
|
80
|
-
first: ${limit ? `$limit` : `1000`}
|
|
81
|
-
`;
|
|
82
81
|
|
|
83
82
|
return gql`
|
|
84
|
-
query GetEscrowDayData(
|
|
83
|
+
query GetEscrowDayData(
|
|
84
|
+
$from: Int,
|
|
85
|
+
$to: Int,
|
|
86
|
+
$orderDirection: String
|
|
87
|
+
$first: Int
|
|
88
|
+
$skip: Int
|
|
89
|
+
) {
|
|
85
90
|
eventDayDatas(
|
|
86
91
|
${WHERE_CLAUSE},
|
|
87
92
|
orderBy: timestamp,
|
|
88
|
-
orderDirection:
|
|
89
|
-
$
|
|
93
|
+
orderDirection: $orderDirection,
|
|
94
|
+
first: $first,
|
|
95
|
+
skip: $skip
|
|
90
96
|
) {
|
|
91
97
|
...EventDayDataFields
|
|
92
98
|
}
|
|
@@ -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;
|
|
@@ -11,11 +13,8 @@ export type EscrowData = {
|
|
|
11
13
|
manifestHash?: string;
|
|
12
14
|
manifestUrl?: string;
|
|
13
15
|
recordingOracle?: string;
|
|
14
|
-
recordingOracleFee?: string;
|
|
15
16
|
reputationOracle?: string;
|
|
16
|
-
reputationOracleFee?: string;
|
|
17
17
|
exchangeOracle?: string;
|
|
18
|
-
exchangeOracleFee?: string;
|
|
19
18
|
status: string;
|
|
20
19
|
token: string;
|
|
21
20
|
totalFundedAmount: string;
|
|
@@ -72,6 +71,8 @@ export type EventDayData = {
|
|
|
72
71
|
dailyPayoutAmount: string;
|
|
73
72
|
dailyHMTTransferCount: string;
|
|
74
73
|
dailyHMTTransferAmount: string;
|
|
74
|
+
dailyUniqueSenders: string;
|
|
75
|
+
dailyUniqueReceivers: string;
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
export type RewardAddedEventData = {
|
|
@@ -129,14 +130,14 @@ export type DailyHMTData = {
|
|
|
129
130
|
timestamp: Date;
|
|
130
131
|
totalTransactionAmount: bigint;
|
|
131
132
|
totalTransactionCount: number;
|
|
133
|
+
dailyUniqueSenders: number;
|
|
134
|
+
dailyUniqueReceivers: number;
|
|
132
135
|
};
|
|
133
136
|
|
|
134
137
|
export type HMTStatistics = {
|
|
135
138
|
totalTransferAmount: bigint;
|
|
136
139
|
totalTransferCount: number;
|
|
137
140
|
totalHolders: number;
|
|
138
|
-
holders: HMTHolder[];
|
|
139
|
-
dailyHMTData: DailyHMTData[];
|
|
140
141
|
};
|
|
141
142
|
|
|
142
143
|
export type IMDataEntity = {
|
|
@@ -156,6 +157,13 @@ export type TaskStatistics = {
|
|
|
156
157
|
dailyTasksData: DailyTaskData[];
|
|
157
158
|
};
|
|
158
159
|
|
|
160
|
+
export type StatusEvent = {
|
|
161
|
+
timestamp: number;
|
|
162
|
+
escrowAddress: string;
|
|
163
|
+
status: string;
|
|
164
|
+
chainId: ChainId;
|
|
165
|
+
};
|
|
166
|
+
|
|
159
167
|
export type KVStoreData = {
|
|
160
168
|
id: string;
|
|
161
169
|
address: string;
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { StakingClient } from './staking';
|
|
2
2
|
import { StorageClient } from './storage';
|
|
3
|
-
import { KVStoreClient } from './kvstore';
|
|
3
|
+
import { KVStoreClient, KVStoreUtils } from './kvstore';
|
|
4
4
|
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';
|
|
@@ -15,10 +16,12 @@ export {
|
|
|
15
16
|
StakingClient,
|
|
16
17
|
StorageClient,
|
|
17
18
|
KVStoreClient,
|
|
19
|
+
KVStoreUtils,
|
|
18
20
|
EscrowClient,
|
|
19
21
|
EscrowUtils,
|
|
20
22
|
StatisticsClient,
|
|
21
23
|
Encryption,
|
|
22
24
|
EncryptionUtils,
|
|
23
25
|
OperatorUtils,
|
|
26
|
+
TransactionUtils,
|
|
24
27
|
};
|