@human-protocol/sdk 1.1.8 → 1.1.10
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/escrow.d.ts +4 -3
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +16 -9
- package/dist/graphql/index.d.ts +3 -0
- package/dist/graphql/index.d.ts.map +1 -0
- package/dist/graphql/index.js +18 -0
- package/dist/graphql/queries/escrow.d.ts +3 -0
- package/dist/graphql/queries/escrow.d.ts.map +1 -0
- package/dist/graphql/queries/escrow.js +57 -0
- package/dist/graphql/queries/index.d.ts +3 -0
- package/dist/graphql/queries/index.d.ts.map +1 -0
- package/dist/graphql/queries/index.js +18 -0
- package/dist/graphql/queries/reward.d.ts +2 -0
- package/dist/graphql/queries/reward.d.ts.map +1 -0
- package/dist/graphql/queries/reward.js +23 -0
- package/dist/graphql/types.d.ts +27 -0
- package/dist/graphql/types.d.ts.map +1 -0
- package/dist/graphql/types.js +2 -0
- package/dist/interfaces.d.ts +1 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +9 -3
- package/dist/utils.d.ts +0 -10
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -28
- package/package.json +4 -1
- package/src/escrow.ts +25 -21
- package/src/graphql/index.ts +2 -0
- package/src/graphql/queries/escrow.ts +54 -0
- package/src/graphql/queries/index.ts +2 -0
- package/src/graphql/queries/reward.ts +19 -0
- package/src/graphql/types.ts +27 -0
- package/src/interfaces.ts +1 -1
- package/src/staking.ts +10 -7
- package/src/utils.ts +0 -29
- package/dist/queries.d.ts +0 -5
- package/dist/queries.d.ts.map +0 -1
- package/dist/queries.js +0 -19
- package/src/queries.ts +0 -26
package/dist/escrow.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Provider } from '@ethersproject/abstract-provider';
|
|
|
2
2
|
import { BigNumber, Signer } from 'ethers';
|
|
3
3
|
import { IEscrowConfig, IEscrowsFilter } from './interfaces';
|
|
4
4
|
import { EscrowStatus, NetworkData } from './types';
|
|
5
|
+
import { EscrowData } from './graphql';
|
|
5
6
|
export declare class EscrowClient {
|
|
6
7
|
private escrowFactoryContract;
|
|
7
8
|
private escrowContract?;
|
|
@@ -172,15 +173,15 @@ export declare class EscrowClient {
|
|
|
172
173
|
* @returns {Promise<string[]>}
|
|
173
174
|
* @throws {Error} - An error object if an error occurred.
|
|
174
175
|
*/
|
|
175
|
-
getLaunchedEscrows(
|
|
176
|
+
getLaunchedEscrows(launcherAddress: string): Promise<EscrowData[]>;
|
|
176
177
|
/**
|
|
177
178
|
* Returns the escrow addresses based on a specified filter.
|
|
178
179
|
*
|
|
179
180
|
* @param {IEscrowsFilter} filter - Filter parameters.
|
|
180
|
-
* @returns {Promise<
|
|
181
|
+
* @returns {Promise<EscrowData[]>}
|
|
181
182
|
* @throws {Error} - An error object if an error occurred.
|
|
182
183
|
*/
|
|
183
|
-
getEscrowsFiltered(filter: IEscrowsFilter): Promise<
|
|
184
|
+
getEscrowsFiltered(filter: IEscrowsFilter): Promise<EscrowData[]>;
|
|
184
185
|
/**
|
|
185
186
|
* Returns the recording oracle address of given escrow
|
|
186
187
|
*
|
package/dist/escrow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../src/escrow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAU5D,OAAO,EAAE,SAAS,EAAmB,MAAM,EAAU,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../src/escrow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAU5D,OAAO,EAAE,SAAS,EAAmB,MAAM,EAAU,MAAM,QAAQ,CAAC;AA2BpE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAA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AAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBnE;;;;;;OAMG;IACG,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBxE;;;;;;OAMG;IACG,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAmBhE"}
|
package/dist/escrow.js
CHANGED
|
@@ -8,15 +8,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.EscrowClient = void 0;
|
|
13
16
|
const typechain_types_1 = require("@human-protocol/core/typechain-types");
|
|
14
17
|
const ethers_1 = require("ethers");
|
|
18
|
+
const graphql_request_1 = __importDefault(require("graphql-request"));
|
|
15
19
|
const constants_1 = require("./constants");
|
|
16
20
|
const decorators_1 = require("./decorators");
|
|
17
21
|
const error_1 = require("./error");
|
|
18
|
-
const queries_1 = require("./queries");
|
|
19
22
|
const utils_1 = require("./utils");
|
|
23
|
+
const graphql_1 = require("./graphql");
|
|
20
24
|
class EscrowClient {
|
|
21
25
|
/**
|
|
22
26
|
* **EscrowClient constructor**
|
|
@@ -512,13 +516,13 @@ class EscrowClient {
|
|
|
512
516
|
* @returns {Promise<string[]>}
|
|
513
517
|
* @throws {Error} - An error object if an error occurred.
|
|
514
518
|
*/
|
|
515
|
-
async getLaunchedEscrows(
|
|
516
|
-
if (!ethers_1.ethers.utils.isAddress(
|
|
519
|
+
async getLaunchedEscrows(launcherAddress) {
|
|
520
|
+
if (!ethers_1.ethers.utils.isAddress(launcherAddress)) {
|
|
517
521
|
throw error_1.ErrorInvalidAddress;
|
|
518
522
|
}
|
|
519
523
|
try {
|
|
520
|
-
const {
|
|
521
|
-
return
|
|
524
|
+
const { escrows } = await (0, graphql_request_1.default)(this.network.subgraphUrl, graphql_1.GET_ESCROWS_BY_LAUNCHER_QUERY, { launcherAddress });
|
|
525
|
+
return escrows;
|
|
522
526
|
}
|
|
523
527
|
catch (e) {
|
|
524
528
|
return (0, utils_1.throwError)(e);
|
|
@@ -528,16 +532,19 @@ class EscrowClient {
|
|
|
528
532
|
* Returns the escrow addresses based on a specified filter.
|
|
529
533
|
*
|
|
530
534
|
* @param {IEscrowsFilter} filter - Filter parameters.
|
|
531
|
-
* @returns {Promise<
|
|
535
|
+
* @returns {Promise<EscrowData[]>}
|
|
532
536
|
* @throws {Error} - An error object if an error occurred.
|
|
533
537
|
*/
|
|
534
538
|
async getEscrowsFiltered(filter) {
|
|
535
|
-
if (filter?.
|
|
539
|
+
if (filter?.launcherAddress &&
|
|
540
|
+
!ethers_1.ethers.utils.isAddress(filter?.launcherAddress)) {
|
|
536
541
|
throw error_1.ErrorInvalidAddress;
|
|
537
542
|
}
|
|
538
543
|
try {
|
|
539
|
-
const {
|
|
540
|
-
|
|
544
|
+
const { escrows } = await (0, graphql_request_1.default)(this.network.subgraphUrl, graphql_1.GET_FILTERED_ESCROWS_QUERY, {
|
|
545
|
+
...filter,
|
|
546
|
+
});
|
|
547
|
+
return escrows;
|
|
541
548
|
}
|
|
542
549
|
catch (e) {
|
|
543
550
|
return (0, utils_1.throwError)(e);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graphql/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./queries"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/escrow.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,6BAA6B,gCAOzC,CAAC;AAEF,eAAO,MAAM,0BAA0B,gCAmBtC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GET_FILTERED_ESCROWS_QUERY = exports.GET_ESCROWS_BY_LAUNCHER_QUERY = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const ESCROW_FRAGMENT = (0, graphql_tag_1.default) `
|
|
9
|
+
fragment EscrowFields on Escrow {
|
|
10
|
+
address
|
|
11
|
+
amountPaid
|
|
12
|
+
balance
|
|
13
|
+
count
|
|
14
|
+
factoryAddress
|
|
15
|
+
finalResultsUrl
|
|
16
|
+
id
|
|
17
|
+
intermediateResultsUrl
|
|
18
|
+
launcher
|
|
19
|
+
manifestHash
|
|
20
|
+
manifestUrl
|
|
21
|
+
recordingOracle
|
|
22
|
+
recordingOracleFee
|
|
23
|
+
reputationOracle
|
|
24
|
+
reputationOracleFee
|
|
25
|
+
status
|
|
26
|
+
token
|
|
27
|
+
totalFundedAmount
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
exports.GET_ESCROWS_BY_LAUNCHER_QUERY = (0, graphql_tag_1.default) `
|
|
31
|
+
query GetEscrowByLauncher($launcherAddress: String!) {
|
|
32
|
+
escrows(where: { launcher: $launcherAddress }) {
|
|
33
|
+
...EscrowFields
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
${ESCROW_FRAGMENT}
|
|
37
|
+
`;
|
|
38
|
+
exports.GET_FILTERED_ESCROWS_QUERY = (0, graphql_tag_1.default) `
|
|
39
|
+
query GetFilteredEscrows(
|
|
40
|
+
$launcherAddress: String
|
|
41
|
+
$status: EscrowStatus
|
|
42
|
+
$from: Int
|
|
43
|
+
$to: Int
|
|
44
|
+
) {
|
|
45
|
+
escrows(
|
|
46
|
+
where: {
|
|
47
|
+
launcher: $launcherAddress
|
|
48
|
+
status: $status
|
|
49
|
+
createdAt_gte: $from
|
|
50
|
+
createdAt_lte: $to
|
|
51
|
+
}
|
|
52
|
+
) {
|
|
53
|
+
...EscrowFields
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
${ESCROW_FRAGMENT}
|
|
57
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./escrow"), exports);
|
|
18
|
+
__exportStar(require("./reward"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reward.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/reward.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,6BAA6B,gCAOzC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GET_REWARD_ADDED_EVENTS_QUERY = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
const REWARD_ADDED_EVENT_FRAGMENT = (0, graphql_tag_1.default) `
|
|
9
|
+
fragment RewardAddedEventFields on RewardAddedEvent {
|
|
10
|
+
escrowAddress
|
|
11
|
+
staker
|
|
12
|
+
slasher
|
|
13
|
+
amount
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
exports.GET_REWARD_ADDED_EVENTS_QUERY = (0, graphql_tag_1.default) `
|
|
17
|
+
query GetRewardAddedEvents($slasherAddress: String!) {
|
|
18
|
+
rewardAddedEvents(where: { slasher: $slasherAddress }) {
|
|
19
|
+
...RewardAddedEventFields
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
${REWARD_ADDED_EVENT_FRAGMENT}
|
|
23
|
+
`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type EscrowData = {
|
|
2
|
+
id: string;
|
|
3
|
+
address: string;
|
|
4
|
+
amountPaid: string;
|
|
5
|
+
balance: string;
|
|
6
|
+
count: string;
|
|
7
|
+
factoryAddress: string;
|
|
8
|
+
finalResultsUrl?: string;
|
|
9
|
+
intermediateResultsUrl?: string;
|
|
10
|
+
launcher: string;
|
|
11
|
+
manifestHash?: string;
|
|
12
|
+
manifestUrl?: string;
|
|
13
|
+
recordingOracle?: string;
|
|
14
|
+
recordingOracleFee?: string;
|
|
15
|
+
reputationOracle?: string;
|
|
16
|
+
reputationOracleFee?: string;
|
|
17
|
+
status: string;
|
|
18
|
+
token: string;
|
|
19
|
+
totalFundedAmount: string;
|
|
20
|
+
};
|
|
21
|
+
export type RewardAddedEventData = {
|
|
22
|
+
escrowAddress: string;
|
|
23
|
+
staker: string;
|
|
24
|
+
slasher: string;
|
|
25
|
+
amount: string;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/graphql/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
package/dist/interfaces.d.ts
CHANGED
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,SAAS,CAAC;IACxB,eAAe,EAAE,SAAS,CAA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MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
package/dist/staking.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACL,aAAa,EAEb,OAAO,EAIP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACL,aAAa,EAEb,OAAO,EAIP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAgBnD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAKtC,qBAAa,aAAa;IACjB,gBAAgB,EAAE,MAAM,GAAG,QAAQ,CAAC;IACpC,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,aAAa,CAAC;IAE5C;;;;;OAKG;gBACS,gBAAgB,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,WAAW;IAoBrE;;;;;;;OAOG;WACiB,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ;IAsB7D;;;;;;;OAOG;IAEU,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB3D;;;;;;OAMG;IAEU,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBpD;;;;;;;OAOG;IAEU,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBtD;;;;;OAKG;IAEU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAStC;;;;;;;;;;OAUG;IAEU,KAAK,CAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,IAAI,CAAC;IAkChB;;;;;;;OAOG;IAEU,QAAQ,CACnB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,IAAI,CAAC;IAyBhB;;;;;;OAMG;IAEU,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlE;;;;;;OAMG;IAEU,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBpE;;;;;;OAMG;IACU,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA8BxD;;;;;OAKG;IACU,aAAa,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAgChD;;;;;;OAMG;IACU,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAiBvE;;;;;;OAMG;IACU,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAsBpE"}
|
package/dist/staking.js
CHANGED
|
@@ -8,15 +8,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.StakingClient = void 0;
|
|
13
16
|
const typechain_types_1 = require("@human-protocol/core/typechain-types");
|
|
14
17
|
const ethers_1 = require("ethers");
|
|
18
|
+
const graphql_request_1 = __importDefault(require("graphql-request"));
|
|
15
19
|
const constants_1 = require("./constants");
|
|
16
20
|
const decorators_1 = require("./decorators");
|
|
17
21
|
const error_1 = require("./error");
|
|
18
|
-
const queries_1 = require("./queries");
|
|
19
22
|
const utils_1 = require("./utils");
|
|
23
|
+
const reward_1 = require("./graphql/queries/reward");
|
|
20
24
|
class StakingClient {
|
|
21
25
|
/**
|
|
22
26
|
* **StakingClient constructor**
|
|
@@ -347,8 +351,10 @@ class StakingClient {
|
|
|
347
351
|
throw error_1.ErrorInvalidSlasherAddressProvided;
|
|
348
352
|
}
|
|
349
353
|
try {
|
|
350
|
-
const {
|
|
351
|
-
|
|
354
|
+
const { rewardAddedEvents } = await (0, graphql_request_1.default)(this.network.subgraphUrl, reward_1.GET_REWARD_ADDED_EVENTS_QUERY, {
|
|
355
|
+
slasherAddress,
|
|
356
|
+
});
|
|
357
|
+
return rewardAddedEvents.map((reward) => {
|
|
352
358
|
return {
|
|
353
359
|
escrowAddress: reward.escrow,
|
|
354
360
|
amount: reward.amount,
|
package/dist/utils.d.ts
CHANGED
|
@@ -19,14 +19,4 @@ export declare const throwError: (e: any) => never;
|
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
21
|
export declare const isValidUrl: (url: string) => boolean;
|
|
22
|
-
/**
|
|
23
|
-
* **Fetching data with queries.*
|
|
24
|
-
*
|
|
25
|
-
* @param {string} url
|
|
26
|
-
* @param {string} query
|
|
27
|
-
* @param {any} variables
|
|
28
|
-
* @param {any} headers
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
export declare const gqlFetch: (url: string, query: string, variables?: any, headers?: any) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
32
22
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,GAAG,KAAG,MAO5C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,MAAO,GAAG,UAqBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,YAOrC,CAAC"}
|
package/dist/utils.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.isValidUrl = exports.throwError = exports.getRevertReason = void 0;
|
|
7
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
5
|
const ethers_1 = require("ethers");
|
|
10
6
|
const error_1 = require("./error");
|
|
11
7
|
/**
|
|
@@ -74,26 +70,3 @@ const isValidUrl = (url) => {
|
|
|
74
70
|
}
|
|
75
71
|
};
|
|
76
72
|
exports.isValidUrl = isValidUrl;
|
|
77
|
-
/**
|
|
78
|
-
* **Fetching data with queries.*
|
|
79
|
-
*
|
|
80
|
-
* @param {string} url
|
|
81
|
-
* @param {string} query
|
|
82
|
-
* @param {any} variables
|
|
83
|
-
* @param {any} headers
|
|
84
|
-
* @returns
|
|
85
|
-
*/
|
|
86
|
-
const gqlFetch = (url, query, variables, headers) => {
|
|
87
|
-
if (url && url.length) {
|
|
88
|
-
return axios_1.default.post(url, JSON.stringify({ query, variables }), {
|
|
89
|
-
headers: {
|
|
90
|
-
'Content-Type': 'application/json',
|
|
91
|
-
...headers,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
return Promise.reject(error_1.ErrorNoURLprovided);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
exports.gqlFetch = gqlFetch;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@human-protocol/sdk",
|
|
3
3
|
"description": "Human Protocol SDK",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.10",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
7
7
|
"dist"
|
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"axios": "^1.4.0",
|
|
43
43
|
"crypto": "^1.0.1",
|
|
44
44
|
"ethers": "^5.7.2",
|
|
45
|
+
"graphql": "^16.7.1",
|
|
46
|
+
"graphql-request": "^6.1.0",
|
|
47
|
+
"graphql-tag": "^2.12.6",
|
|
45
48
|
"minio": "^7.0.32",
|
|
46
49
|
"secp256k1": "^4.0.3",
|
|
47
50
|
"vitest": "^0.30.1",
|
package/src/escrow.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
HMToken__factory,
|
|
11
11
|
} from '@human-protocol/core/typechain-types';
|
|
12
12
|
import { BigNumber, ContractReceipt, Signer, ethers } from 'ethers';
|
|
13
|
+
import gqlFetch from 'graphql-request';
|
|
13
14
|
import { DEFAULT_TX_ID, NETWORKS } from './constants';
|
|
14
15
|
import { requiresSigner } from './decorators';
|
|
15
16
|
import { ChainId } from './enums';
|
|
@@ -36,12 +37,13 @@ import {
|
|
|
36
37
|
InvalidEthereumAddressError,
|
|
37
38
|
} from './error';
|
|
38
39
|
import { IEscrowConfig, IEscrowsFilter } from './interfaces';
|
|
39
|
-
import {
|
|
40
|
-
RAW_LAUNCHED_ESCROWS_FILTERED_QUERY,
|
|
41
|
-
RAW_LAUNCHED_ESCROWS_QUERY,
|
|
42
|
-
} from './queries';
|
|
43
40
|
import { EscrowStatus, NetworkData } from './types';
|
|
44
|
-
import {
|
|
41
|
+
import { isValidUrl, throwError } from './utils';
|
|
42
|
+
import {
|
|
43
|
+
EscrowData,
|
|
44
|
+
GET_ESCROWS_BY_LAUNCHER_QUERY,
|
|
45
|
+
GET_FILTERED_ESCROWS_QUERY,
|
|
46
|
+
} from './graphql';
|
|
45
47
|
|
|
46
48
|
export class EscrowClient {
|
|
47
49
|
private escrowFactoryContract: EscrowFactory;
|
|
@@ -725,18 +727,19 @@ export class EscrowClient {
|
|
|
725
727
|
* @returns {Promise<string[]>}
|
|
726
728
|
* @throws {Error} - An error object if an error occurred.
|
|
727
729
|
*/
|
|
728
|
-
async getLaunchedEscrows(
|
|
729
|
-
if (!ethers.utils.isAddress(
|
|
730
|
+
async getLaunchedEscrows(launcherAddress: string): Promise<EscrowData[]> {
|
|
731
|
+
if (!ethers.utils.isAddress(launcherAddress)) {
|
|
730
732
|
throw ErrorInvalidAddress;
|
|
731
733
|
}
|
|
732
734
|
|
|
733
735
|
try {
|
|
734
|
-
const {
|
|
736
|
+
const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
|
|
735
737
|
this.network.subgraphUrl,
|
|
736
|
-
|
|
738
|
+
GET_ESCROWS_BY_LAUNCHER_QUERY,
|
|
739
|
+
{ launcherAddress }
|
|
737
740
|
);
|
|
738
741
|
|
|
739
|
-
return
|
|
742
|
+
return escrows;
|
|
740
743
|
} catch (e: any) {
|
|
741
744
|
return throwError(e);
|
|
742
745
|
}
|
|
@@ -746,26 +749,27 @@ export class EscrowClient {
|
|
|
746
749
|
* Returns the escrow addresses based on a specified filter.
|
|
747
750
|
*
|
|
748
751
|
* @param {IEscrowsFilter} filter - Filter parameters.
|
|
749
|
-
* @returns {Promise<
|
|
752
|
+
* @returns {Promise<EscrowData[]>}
|
|
750
753
|
* @throws {Error} - An error object if an error occurred.
|
|
751
754
|
*/
|
|
752
|
-
async getEscrowsFiltered(filter: IEscrowsFilter): Promise<
|
|
753
|
-
if (
|
|
755
|
+
async getEscrowsFiltered(filter: IEscrowsFilter): Promise<EscrowData[]> {
|
|
756
|
+
if (
|
|
757
|
+
filter?.launcherAddress &&
|
|
758
|
+
!ethers.utils.isAddress(filter?.launcherAddress)
|
|
759
|
+
) {
|
|
754
760
|
throw ErrorInvalidAddress;
|
|
755
761
|
}
|
|
756
762
|
|
|
757
763
|
try {
|
|
758
|
-
const {
|
|
764
|
+
const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
|
|
759
765
|
this.network.subgraphUrl,
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
filter
|
|
763
|
-
|
|
764
|
-
filter.to
|
|
765
|
-
)
|
|
766
|
+
GET_FILTERED_ESCROWS_QUERY,
|
|
767
|
+
{
|
|
768
|
+
...filter,
|
|
769
|
+
}
|
|
766
770
|
);
|
|
767
771
|
|
|
768
|
-
return
|
|
772
|
+
return escrows;
|
|
769
773
|
} catch (e: any) {
|
|
770
774
|
return throwError(e);
|
|
771
775
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import gql from 'graphql-tag';
|
|
2
|
+
|
|
3
|
+
const ESCROW_FRAGMENT = gql`
|
|
4
|
+
fragment EscrowFields on Escrow {
|
|
5
|
+
address
|
|
6
|
+
amountPaid
|
|
7
|
+
balance
|
|
8
|
+
count
|
|
9
|
+
factoryAddress
|
|
10
|
+
finalResultsUrl
|
|
11
|
+
id
|
|
12
|
+
intermediateResultsUrl
|
|
13
|
+
launcher
|
|
14
|
+
manifestHash
|
|
15
|
+
manifestUrl
|
|
16
|
+
recordingOracle
|
|
17
|
+
recordingOracleFee
|
|
18
|
+
reputationOracle
|
|
19
|
+
reputationOracleFee
|
|
20
|
+
status
|
|
21
|
+
token
|
|
22
|
+
totalFundedAmount
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const GET_ESCROWS_BY_LAUNCHER_QUERY = gql`
|
|
27
|
+
query GetEscrowByLauncher($launcherAddress: String!) {
|
|
28
|
+
escrows(where: { launcher: $launcherAddress }) {
|
|
29
|
+
...EscrowFields
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
${ESCROW_FRAGMENT}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
export const GET_FILTERED_ESCROWS_QUERY = gql`
|
|
36
|
+
query GetFilteredEscrows(
|
|
37
|
+
$launcherAddress: String
|
|
38
|
+
$status: EscrowStatus
|
|
39
|
+
$from: Int
|
|
40
|
+
$to: Int
|
|
41
|
+
) {
|
|
42
|
+
escrows(
|
|
43
|
+
where: {
|
|
44
|
+
launcher: $launcherAddress
|
|
45
|
+
status: $status
|
|
46
|
+
createdAt_gte: $from
|
|
47
|
+
createdAt_lte: $to
|
|
48
|
+
}
|
|
49
|
+
) {
|
|
50
|
+
...EscrowFields
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
${ESCROW_FRAGMENT}
|
|
54
|
+
`;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import gql from 'graphql-tag';
|
|
2
|
+
|
|
3
|
+
const REWARD_ADDED_EVENT_FRAGMENT = gql`
|
|
4
|
+
fragment RewardAddedEventFields on RewardAddedEvent {
|
|
5
|
+
escrowAddress
|
|
6
|
+
staker
|
|
7
|
+
slasher
|
|
8
|
+
amount
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const GET_REWARD_ADDED_EVENTS_QUERY = gql`
|
|
13
|
+
query GetRewardAddedEvents($slasherAddress: String!) {
|
|
14
|
+
rewardAddedEvents(where: { slasher: $slasherAddress }) {
|
|
15
|
+
...RewardAddedEventFields
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
${REWARD_ADDED_EVENT_FRAGMENT}
|
|
19
|
+
`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type EscrowData = {
|
|
2
|
+
id: string;
|
|
3
|
+
address: string;
|
|
4
|
+
amountPaid: string;
|
|
5
|
+
balance: string;
|
|
6
|
+
count: string;
|
|
7
|
+
factoryAddress: string;
|
|
8
|
+
finalResultsUrl?: string;
|
|
9
|
+
intermediateResultsUrl?: string;
|
|
10
|
+
launcher: string;
|
|
11
|
+
manifestHash?: string;
|
|
12
|
+
manifestUrl?: string;
|
|
13
|
+
recordingOracle?: string;
|
|
14
|
+
recordingOracleFee?: string;
|
|
15
|
+
reputationOracle?: string;
|
|
16
|
+
reputationOracleFee?: string;
|
|
17
|
+
status: string;
|
|
18
|
+
token: string;
|
|
19
|
+
totalFundedAmount: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type RewardAddedEventData = {
|
|
23
|
+
escrowAddress: string;
|
|
24
|
+
staker: string;
|
|
25
|
+
slasher: string;
|
|
26
|
+
amount: string;
|
|
27
|
+
};
|
package/src/interfaces.ts
CHANGED
package/src/staking.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
Staking__factory,
|
|
13
13
|
} from '@human-protocol/core/typechain-types';
|
|
14
14
|
import { BigNumber, Signer, ethers } from 'ethers';
|
|
15
|
+
import gqlFetch from 'graphql-request';
|
|
15
16
|
import { NETWORKS } from './constants';
|
|
16
17
|
import { requiresSigner } from './decorators';
|
|
17
18
|
import { ChainId } from './enums';
|
|
@@ -27,9 +28,10 @@ import {
|
|
|
27
28
|
ErrorUnsupportedChainID,
|
|
28
29
|
} from './error';
|
|
29
30
|
import { IAllocation, IReward, IStaker } from './interfaces';
|
|
30
|
-
import { RAW_REWARDS_QUERY } from './queries';
|
|
31
31
|
import { NetworkData } from './types';
|
|
32
|
-
import {
|
|
32
|
+
import { throwError } from './utils';
|
|
33
|
+
import { GET_REWARD_ADDED_EVENTS_QUERY } from './graphql/queries/reward';
|
|
34
|
+
import { RewardAddedEventData } from './graphql';
|
|
33
35
|
|
|
34
36
|
export class StakingClient {
|
|
35
37
|
public signerOrProvider: Signer | Provider;
|
|
@@ -442,12 +444,13 @@ export class StakingClient {
|
|
|
442
444
|
}
|
|
443
445
|
|
|
444
446
|
try {
|
|
445
|
-
const {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
447
|
+
const { rewardAddedEvents } = await gqlFetch<{
|
|
448
|
+
rewardAddedEvents: RewardAddedEventData[];
|
|
449
|
+
}>(this.network.subgraphUrl, GET_REWARD_ADDED_EVENTS_QUERY, {
|
|
450
|
+
slasherAddress,
|
|
451
|
+
});
|
|
449
452
|
|
|
450
|
-
return
|
|
453
|
+
return rewardAddedEvents.map((reward: any) => {
|
|
451
454
|
return {
|
|
452
455
|
escrowAddress: reward.escrow,
|
|
453
456
|
amount: reward.amount,
|
package/src/utils.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import axios from 'axios';
|
|
3
2
|
import { ethers } from 'ethers';
|
|
4
3
|
|
|
5
4
|
import {
|
|
6
5
|
ContractExecutionError,
|
|
7
|
-
ErrorNoURLprovided,
|
|
8
6
|
EthereumError,
|
|
9
7
|
InvalidArgumentError,
|
|
10
8
|
NonceExpired,
|
|
@@ -73,30 +71,3 @@ export const isValidUrl = (url: string) => {
|
|
|
73
71
|
return false;
|
|
74
72
|
}
|
|
75
73
|
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* **Fetching data with queries.*
|
|
79
|
-
*
|
|
80
|
-
* @param {string} url
|
|
81
|
-
* @param {string} query
|
|
82
|
-
* @param {any} variables
|
|
83
|
-
* @param {any} headers
|
|
84
|
-
* @returns
|
|
85
|
-
*/
|
|
86
|
-
export const gqlFetch = (
|
|
87
|
-
url: string,
|
|
88
|
-
query: string,
|
|
89
|
-
variables?: any,
|
|
90
|
-
headers?: any
|
|
91
|
-
) => {
|
|
92
|
-
if (url && url.length) {
|
|
93
|
-
return axios.post(url, JSON.stringify({ query, variables }), {
|
|
94
|
-
headers: {
|
|
95
|
-
'Content-Type': 'application/json',
|
|
96
|
-
...headers,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
} else {
|
|
100
|
-
return Promise.reject(ErrorNoURLprovided);
|
|
101
|
-
}
|
|
102
|
-
};
|
package/dist/queries.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { EscrowStatus } from './types';
|
|
2
|
-
export declare const RAW_REWARDS_QUERY: (slasherAddress: string) => string;
|
|
3
|
-
export declare const RAW_LAUNCHED_ESCROWS_QUERY: (requesterAddress: string) => string;
|
|
4
|
-
export declare const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY: (address?: string, status?: EscrowStatus, from?: Date, to?: Date) => string;
|
|
5
|
-
//# sourceMappingURL=queries.d.ts.map
|
package/dist/queries.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,eAAO,MAAM,iBAAiB,mBAAoB,MAAM,WAKpD,CAAC;AAEL,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,WAI/D,CAAC;AAEL,eAAO,MAAM,mCAAmC,aACpC,MAAM,WACP,YAAY,SACd,IAAI,OACN,IAAI,WAMG,CAAC"}
|
package/dist/queries.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = exports.RAW_LAUNCHED_ESCROWS_QUERY = exports.RAW_REWARDS_QUERY = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
const RAW_REWARDS_QUERY = (slasherAddress) => `{
|
|
6
|
-
rewardAddedEvents(id: "${slasherAddress}") {
|
|
7
|
-
escrow,
|
|
8
|
-
amount
|
|
9
|
-
}
|
|
10
|
-
}`;
|
|
11
|
-
exports.RAW_REWARDS_QUERY = RAW_REWARDS_QUERY;
|
|
12
|
-
const RAW_LAUNCHED_ESCROWS_QUERY = (requesterAddress) => `{
|
|
13
|
-
launchedEscrows(where: { from: ${requesterAddress} }) {
|
|
14
|
-
id
|
|
15
|
-
}
|
|
16
|
-
}`;
|
|
17
|
-
exports.RAW_LAUNCHED_ESCROWS_QUERY = RAW_LAUNCHED_ESCROWS_QUERY;
|
|
18
|
-
const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = (address, status, from, to) => `{ launchedEscrows(where: { ${address ? 'from: "' + address + '", ' : ''}${status ? 'status: "' + types_1.EscrowStatus[status] + '", ' : ''}${from ? 'timestamp_gte: "' + from?.valueOf() + '", ' : ''}${to ? 'timestamp_lte: "' + to?.valueOf() + '"' : ''}}) { id }}`;
|
|
19
|
-
exports.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = RAW_LAUNCHED_ESCROWS_FILTERED_QUERY;
|
package/src/queries.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { EscrowStatus } from './types';
|
|
2
|
-
|
|
3
|
-
export const RAW_REWARDS_QUERY = (slasherAddress: string) => `{
|
|
4
|
-
rewardAddedEvents(id: "${slasherAddress}") {
|
|
5
|
-
escrow,
|
|
6
|
-
amount
|
|
7
|
-
}
|
|
8
|
-
}`;
|
|
9
|
-
|
|
10
|
-
export const RAW_LAUNCHED_ESCROWS_QUERY = (requesterAddress: string) => `{
|
|
11
|
-
launchedEscrows(where: { from: ${requesterAddress} }) {
|
|
12
|
-
id
|
|
13
|
-
}
|
|
14
|
-
}`;
|
|
15
|
-
|
|
16
|
-
export const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = (
|
|
17
|
-
address?: string,
|
|
18
|
-
status?: EscrowStatus,
|
|
19
|
-
from?: Date,
|
|
20
|
-
to?: Date
|
|
21
|
-
) =>
|
|
22
|
-
`{ launchedEscrows(where: { ${address ? 'from: "' + address + '", ' : ''}${
|
|
23
|
-
status ? 'status: "' + EscrowStatus[status] + '", ' : ''
|
|
24
|
-
}${from ? 'timestamp_gte: "' + from?.valueOf() + '", ' : ''}${
|
|
25
|
-
to ? 'timestamp_lte: "' + to?.valueOf() + '"' : ''
|
|
26
|
-
}}) { id }}`;
|