Skip to content

Commit ce94c9c

Browse files
committed
Update all SDK dependencies to use new types
1 parent 8547da7 commit ce94c9c

File tree

11 files changed

+159
-94
lines changed

11 files changed

+159
-94
lines changed

packages/apps/dashboard/server/src/modules/stats/stats.service.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { NETWORKS, StatisticsClient } from '@human-protocol/sdk';
2-
import { DailyHMTData } from '@human-protocol/sdk/dist/graphql';
1+
import { IDailyHMT, NETWORKS, StatisticsClient } from '@human-protocol/sdk';
32
import { HttpService } from '@nestjs/axios';
43
import { Cache, CACHE_MANAGER } from '@nestjs/cache-manager';
54
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
@@ -265,7 +264,7 @@ export class StatsService implements OnModuleInit {
265264
}
266265

267266
private async isHmtDailyStatsFetched(): Promise<boolean> {
268-
const data = await this.cacheManager.get<DailyHMTData>(
267+
const data = await this.cacheManager.get<IDailyHMT>(
269268
`${HMT_PREFIX}${HMT_STATS_START_DATE}`,
270269
);
271270
return !!data;
@@ -298,7 +297,7 @@ export class StatsService implements OnModuleInit {
298297
operatingNetworks.map(async (network) => {
299298
const statisticsClient = new StatisticsClient(NETWORKS[network]);
300299
let skip = 0;
301-
let fetchedRecords: DailyHMTData[] = [];
300+
let fetchedRecords: IDailyHMT[] = [];
302301

303302
do {
304303
fetchedRecords = await statisticsClient.getHMTDailyData({
@@ -310,7 +309,7 @@ export class StatsService implements OnModuleInit {
310309

311310
for (const record of fetchedRecords) {
312311
const dailyCacheKey = `${HMT_PREFIX}${
313-
record.timestamp.toISOString().split('T')[0]
312+
new Date(record.timestamp).toISOString().split('T')[0]
314313
}`;
315314

316315
// Sum daily values

packages/apps/fortune/exchange-oracle/server/src/modules/webhook/webhook.service.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,24 @@ describe('WebhookService', () => {
323323
),
324324
).rejects.toThrow(new NotFoundError('Oracle not found'));
325325
});
326+
327+
it('should throw NotFoundError if webhook url is not found', async () => {
328+
(EscrowClient.build as any).mockImplementation(() => ({
329+
getJobLauncherAddress: jest.fn().mockResolvedValue(MOCK_ADDRESS),
330+
}));
331+
332+
(OperatorUtils.getOperator as any).mockResolvedValue({
333+
webhookUrl: null,
334+
});
335+
336+
await expect(
337+
(webhookService as any).getOracleWebhookUrl(
338+
JOB_LAUNCHER_WEBHOOK_URL,
339+
ChainId.LOCALHOST,
340+
EventType.ESCROW_FAILED,
341+
),
342+
).rejects.toThrow(new NotFoundError('Oracle webhook URL not found'));
343+
});
326344
});
327345

328346
describe('handleWebhookError', () => {

packages/apps/fortune/exchange-oracle/server/src/modules/webhook/webhook.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ export class WebhookService {
184184
if (!oracle) {
185185
throw new NotFoundError('Oracle not found');
186186
}
187-
const oracleWebhookUrl = oracle.webhookUrl;
187+
if (!oracle.webhookUrl) {
188+
throw new NotFoundError('Oracle webhook URL not found');
189+
}
188190

189-
return oracleWebhookUrl;
191+
return oracle.webhookUrl;
190192
}
191193
}

packages/apps/human-app/server/src/modules/oracle-discovery/model/oracle-discovery.model.ts

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ type DiscoveredOracleCreateProps = {
88
id: string;
99
address: string;
1010
chainId: ChainId;
11-
stakedAmount: bigint;
12-
lockedAmount: bigint;
13-
lockedUntilTimestamp: bigint;
14-
withdrawnAmount: bigint;
15-
slashedAmount: bigint;
16-
amountJobsProcessed: bigint;
17-
role?: string;
18-
fee?: bigint;
19-
publicKey?: string;
20-
webhookUrl?: string;
21-
website?: string;
22-
url: string;
23-
jobTypes: string[];
24-
registrationNeeded?: boolean;
25-
registrationInstructions?: string;
26-
reputationNetworks?: string[];
27-
name?: string;
28-
category?: string;
11+
stakedAmount: bigint | null;
12+
lockedAmount: bigint | null;
13+
lockedUntilTimestamp: number | null;
14+
withdrawnAmount: bigint | null;
15+
slashedAmount: bigint | null;
16+
amountJobsProcessed: bigint | null;
17+
role: string | null;
18+
fee: bigint | null;
19+
publicKey: string | null;
20+
webhookUrl: string | null;
21+
website: string | null;
22+
url: string | null;
23+
jobTypes: string[] | null;
24+
registrationNeeded: boolean | null;
25+
registrationInstructions: string | null;
26+
reputationNetworks: string[];
27+
name: string | null;
28+
category: string | null;
2929
};
3030

3131
export class DiscoveredOracle {
@@ -38,23 +38,31 @@ export class DiscoveredOracle {
3838
@ApiProperty({ description: 'Chain ID where the oracle is registered' })
3939
chainId: ChainId;
4040

41-
@ApiProperty({ description: 'Amount staked by the operator' })
42-
stakedAmount: string;
41+
@ApiPropertyOptional({ description: 'Amount staked by the operator' })
42+
stakedAmount?: string;
4343

44-
@ApiProperty({ description: 'Amount currently locked by the operator' })
45-
lockedAmount: string;
44+
@ApiPropertyOptional({
45+
description: 'Amount currently locked by the operator',
46+
})
47+
lockedAmount?: string;
4648

47-
@ApiProperty({ description: 'Timestamp until funds are locked' })
48-
lockedUntilTimestamp: string;
49+
@ApiPropertyOptional({ description: 'Timestamp until funds are locked' })
50+
lockedUntilTimestamp?: string;
4951

50-
@ApiProperty({ description: 'Total amount withdrawn by the operator' })
51-
withdrawnAmount: string;
52+
@ApiPropertyOptional({
53+
description: 'Total amount withdrawn by the operator',
54+
})
55+
withdrawnAmount?: string;
5256

53-
@ApiProperty({ description: 'Total amount slashed from the operator' })
54-
slashedAmount: string;
57+
@ApiPropertyOptional({
58+
description: 'Total amount slashed from the operator',
59+
})
60+
slashedAmount?: string;
5561

56-
@ApiProperty({ description: 'Number of jobs processed by the operator' })
57-
amountJobsProcessed: string;
62+
@ApiPropertyOptional({
63+
description: 'Number of jobs processed by the operator',
64+
})
65+
amountJobsProcessed?: string;
5866

5967
@ApiPropertyOptional({ description: 'Fee charged by the operator' })
6068
fee?: bigint;
@@ -68,11 +76,11 @@ export class DiscoveredOracle {
6876
@ApiPropertyOptional({ description: 'Website of the operator' })
6977
website?: string;
7078

71-
@ApiProperty({ description: 'URL of the oracle operator' })
72-
url: string;
79+
@ApiPropertyOptional({ description: 'URL of the oracle operator' })
80+
url?: string;
7381

74-
@ApiProperty({ description: 'Role of the oracle operator' })
75-
role: string;
82+
@ApiPropertyOptional({ description: 'Role of the oracle operator' })
83+
role?: string;
7684

7785
@ApiPropertyOptional({
7886
type: [String],
@@ -81,7 +89,7 @@ export class DiscoveredOracle {
8189
jobTypes: string[];
8290

8391
@ApiPropertyOptional({ description: 'Indicates if registration is needed' })
84-
registrationNeeded: boolean;
92+
registrationNeeded?: boolean;
8593

8694
@ApiPropertyOptional({
8795
description: 'Instructions for registration, if needed',
@@ -94,8 +102,8 @@ export class DiscoveredOracle {
94102
})
95103
reputationNetworks?: string[];
96104

97-
@ApiProperty({ description: 'Name of the operator' })
98-
name: string;
105+
@ApiPropertyOptional({ description: 'Name of the operator' })
106+
name?: string;
99107

100108
@ApiPropertyOptional({ description: 'Category of the operator' })
101109
category?: string;
@@ -107,14 +115,27 @@ export class DiscoveredOracle {
107115
executionsToSkip = 0;
108116

109117
constructor(props: DiscoveredOracleCreateProps) {
110-
Object.assign(this, props);
111-
this.registrationNeeded = props.registrationNeeded || false;
112-
this.stakedAmount = this.stakedAmount.toString();
113-
this.lockedAmount = this.lockedAmount.toString();
114-
this.withdrawnAmount = this.withdrawnAmount.toString();
115-
this.slashedAmount = this.slashedAmount.toString();
116-
this.amountJobsProcessed = this.amountJobsProcessed.toString();
117-
this.lockedUntilTimestamp = this.lockedUntilTimestamp.toString();
118+
this.id = props.id;
119+
this.address = props.address;
120+
this.chainId = props.chainId;
121+
this.registrationNeeded = props.registrationNeeded ?? undefined;
122+
this.role = props.role ?? undefined;
123+
this.url = props.url ?? undefined;
124+
this.name = props.name ?? undefined;
125+
this.fee = props.fee ?? undefined;
126+
this.publicKey = props.publicKey ?? undefined;
127+
this.webhookUrl = props.webhookUrl ?? undefined;
128+
this.website = props.website ?? undefined;
129+
this.category = props.category ?? undefined;
130+
this.registrationInstructions = props.registrationInstructions ?? undefined;
131+
this.jobTypes = props.jobTypes ?? [];
132+
this.reputationNetworks = props.reputationNetworks ?? undefined;
133+
this.stakedAmount = props.stakedAmount?.toString();
134+
this.lockedAmount = props.lockedAmount?.toString();
135+
this.withdrawnAmount = props.withdrawnAmount?.toString();
136+
this.slashedAmount = props.slashedAmount?.toString();
137+
this.amountJobsProcessed = props.amountJobsProcessed?.toString();
138+
this.lockedUntilTimestamp = props.lockedUntilTimestamp?.toString();
118139
}
119140
}
120141

packages/apps/human-app/server/src/modules/oracle-discovery/oracle-discovery.controller.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,24 @@ export class OracleDiscoveryController {
5555
id: 'thisrty-oracle',
5656
address: process.env.THIRSTYFI_ORACLE_ADDRESS ?? '',
5757
chainId: ChainId.POLYGON,
58-
stakedAmount: '0' as any,
59-
lockedAmount: '0' as any,
60-
lockedUntilTimestamp: '0' as any,
61-
withdrawnAmount: '0' as any,
62-
slashedAmount: '0' as any,
63-
amountJobsProcessed: '0' as any,
58+
stakedAmount: 0n,
59+
lockedAmount: 0n,
60+
lockedUntilTimestamp: 0,
61+
withdrawnAmount: 0n,
62+
slashedAmount: 0n,
63+
amountJobsProcessed: 0n,
6464
role: 'exchange_oracle',
6565
url: ' ',
6666
jobTypes: ['thirstyfi'],
6767
name: 'ThirstyFi',
6868
registrationNeeded: false,
69-
// registrationInstructions: 'https://www.thisrty.com/',
69+
registrationInstructions: null,
70+
publicKey: null,
71+
webhookUrl: null,
72+
website: null,
73+
fee: null,
74+
reputationNetworks: [],
75+
category: null,
7076
});
7177
oracles.push(thisrtyOracle);
7278

packages/apps/human-app/server/src/modules/oracle-discovery/oracle-discovery.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ export class OracleDiscoveryService {
106106
slashedAmount: exchangeOracle.slashedAmount,
107107
amountJobsProcessed: exchangeOracle.amountJobsProcessed,
108108
lockedUntilTimestamp: exchangeOracle.lockedUntilTimestamp,
109+
fee: exchangeOracle.fee,
110+
publicKey: exchangeOracle.publicKey,
111+
webhookUrl: exchangeOracle.webhookUrl,
112+
website: exchangeOracle.website,
113+
reputationNetworks: exchangeOracle.reputationNetworks,
114+
category: exchangeOracle.category,
109115
}),
110116
);
111117
}

packages/apps/job-launcher/server/src/modules/cron-job/cron-job.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
EscrowClient,
99
EscrowStatus,
1010
EscrowUtils,
11+
IStatusEvent,
1112
KVStoreUtils,
1213
NETWORKS,
1314
} from '@human-protocol/sdk';
14-
import { StatusEvent } from '@human-protocol/sdk/dist/graphql';
1515
import { HttpService } from '@nestjs/axios';
1616
import { ConfigService } from '@nestjs/config';
1717
import { Test, TestingModule } from '@nestjs/testing';
@@ -1107,7 +1107,7 @@ describe('CronJobService', () => {
11071107
describe('syncJobStatuses Cron Job', () => {
11081108
let cronJobEntityMock: Partial<CronJobEntity>;
11091109
let jobEntityMock: Partial<JobEntity>;
1110-
let escrowEventMock: Partial<StatusEvent>;
1110+
let escrowEventMock: Partial<IStatusEvent>;
11111111

11121112
beforeEach(() => {
11131113
cronJobEntityMock = {
@@ -1125,7 +1125,7 @@ describe('CronJobService', () => {
11251125
escrowEventMock = {
11261126
chainId: ChainId.LOCALHOST,
11271127
escrowAddress: MOCK_ADDRESS,
1128-
status: EscrowStatus[EscrowStatus.Partial],
1128+
status: EscrowStatus.Partial,
11291129
};
11301130

11311131
jest.spyOn(repository, 'findOneByType').mockResolvedValue(null);

packages/apps/job-launcher/server/src/modules/cron-job/cron-job.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,19 @@ export class CronJobService {
515515
}
516516
if (!job || job.status === JobStatus.CANCELED) continue;
517517

518-
if (event.status === EscrowStatus[EscrowStatus.Cancelled]) {
518+
if (event.status === EscrowStatus.Cancelled) {
519519
await this.jobService.cancelJob(job);
520520
continue;
521521
}
522522

523523
let newStatus: JobStatus | null = null;
524524
if (
525-
event.status === EscrowStatus[EscrowStatus.Partial] &&
525+
event.status === EscrowStatus.Partial &&
526526
job.status !== JobStatus.PARTIAL
527527
) {
528528
newStatus = JobStatus.PARTIAL;
529529
} else if (
530-
event.status === EscrowStatus[EscrowStatus.Complete] &&
530+
event.status === EscrowStatus.Complete &&
531531
job.status !== JobStatus.COMPLETED
532532
) {
533533
newStatus = JobStatus.COMPLETED;

packages/apps/job-launcher/server/src/modules/job/job.service.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,16 +1745,17 @@ describe('JobService', () => {
17451745
describe('cancelJob', () => {
17461746
it('should create a refund payment and set status to CANCELED', async () => {
17471747
const jobEntity = createJobEntity();
1748-
const refundAmount = faker.number.float({ min: 1, max: 10 });
1748+
const tokenDecimals = (TOKEN_ADDRESSES[jobEntity.chainId as ChainId] ??
1749+
{})[jobEntity.token as EscrowFundToken]?.decimals;
1750+
const refundAmount = faker.number.float({
1751+
min: 1,
1752+
max: 10,
1753+
fractionDigits: tokenDecimals,
1754+
});
17491755

17501756
mockPaymentService.getJobPayments.mockResolvedValueOnce([]);
17511757
mockedEscrowUtils.getCancellationRefund.mockResolvedValueOnce({
1752-
amount: ethers.parseUnits(
1753-
refundAmount.toString(),
1754-
(TOKEN_ADDRESSES[jobEntity.chainId as ChainId] ?? {})[
1755-
jobEntity.token as EscrowFundToken
1756-
]?.decimals,
1757-
),
1758+
amount: ethers.parseUnits(refundAmount.toString(), tokenDecimals),
17581759
escrowAddress: jobEntity.escrowAddress!,
17591760
} as any);
17601761
mockPaymentService.createRefundPayment.mockResolvedValueOnce(undefined);

0 commit comments

Comments
 (0)