From 75ca1a753ab01c8ebc9d1cd5008b2496be7e8762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20L=C3=B3pez?= Date: Thu, 24 Oct 2024 14:30:30 +0200 Subject: [PATCH] Refactor Job Launcher to remove allocation --- .../src/components/CardTextRow/index.tsx | 17 +++- .../client/src/constants/index.tsx | 2 + .../client/src/pages/Job/JobDetail/index.tsx | 89 ++++++++++--------- .../job-launcher/client/src/utils/index.ts | 7 ++ .../server/src/modules/job/job.dto.ts | 20 ----- .../src/modules/job/job.service.spec.ts | 24 ----- .../server/src/modules/job/job.service.ts | 16 +--- .../qualification/qualification.module.ts | 3 +- packages/core/test/Staking.ts | 2 +- .../staking/staking_client.py | 2 +- .../human-protocol-sdk/src/staking.ts | 2 +- 11 files changed, 78 insertions(+), 106 deletions(-) create mode 100644 packages/apps/job-launcher/client/src/utils/index.ts diff --git a/packages/apps/job-launcher/client/src/components/CardTextRow/index.tsx b/packages/apps/job-launcher/client/src/components/CardTextRow/index.tsx index ee22221e19..c7075f5d07 100644 --- a/packages/apps/job-launcher/client/src/components/CardTextRow/index.tsx +++ b/packages/apps/job-launcher/client/src/components/CardTextRow/index.tsx @@ -1,16 +1,19 @@ import { Stack, Typography } from '@mui/material'; import { FC } from 'react'; +import { Link } from 'react-router-dom'; type CardTextRowProps = { label?: string; value?: string | number; minWidth?: number; + url?: string; }; export const CardTextRow: FC = ({ label, value, minWidth = 130, + url, }) => { return ( @@ -22,7 +25,19 @@ export const CardTextRow: FC = ({ color="primary" sx={{ overflow: 'hidden', textOverflow: 'ellipsis' }} > - {value} + {url ? ( + + {value} + + ) : ( + value + )} ); diff --git a/packages/apps/job-launcher/client/src/constants/index.tsx b/packages/apps/job-launcher/client/src/constants/index.tsx index e35f316641..48930fffb1 100644 --- a/packages/apps/job-launcher/client/src/constants/index.tsx +++ b/packages/apps/job-launcher/client/src/constants/index.tsx @@ -32,3 +32,5 @@ export const LOCAL_STORAGE_KEYS = { accessToken: 'HUMAN_JOB_LAUNCHER_ACCESS_TOKEN', refreshToken: 'HUMAN_JOB_LAUNCHER_REFRESH_TOKEN', }; + +export const DASHBOARD_URL = 'https://dashboard.humanprotocol.org/'; diff --git a/packages/apps/job-launcher/client/src/pages/Job/JobDetail/index.tsx b/packages/apps/job-launcher/client/src/pages/Job/JobDetail/index.tsx index 5c7936c2b8..8399bb2bc2 100644 --- a/packages/apps/job-launcher/client/src/pages/Job/JobDetail/index.tsx +++ b/packages/apps/job-launcher/client/src/pages/Job/JobDetail/index.tsx @@ -11,6 +11,7 @@ import { useJobDetails } from '../../../hooks/useJobDetails'; import { useSnackbar } from '../../../providers/SnackProvider'; import * as jobService from '../../../services/job'; import { JobStatus } from '../../../types'; +import { generateDashboardURL } from '../../../utils'; const CardContainer = styled(Card)(({ theme }) => ({ borderRadius: '16px', @@ -91,7 +92,7 @@ export default function JobDetail() { )} - + - - - - - - - - - - - - - Stake details - - - - - + + + + + + + + + + + + @@ -175,6 +160,10 @@ export default function JobDetail() { @@ -191,14 +184,26 @@ export default function JobDetail() { diff --git a/packages/apps/job-launcher/client/src/utils/index.ts b/packages/apps/job-launcher/client/src/utils/index.ts new file mode 100644 index 0000000000..11e48d7cbd --- /dev/null +++ b/packages/apps/job-launcher/client/src/utils/index.ts @@ -0,0 +1,7 @@ +import { DASHBOARD_URL } from '../constants'; +import { IS_MAINNET } from '../constants/chains'; + +export const generateDashboardURL = (chainId: number, address: string) => { + if (!IS_MAINNET) return; + return `${DASHBOARD_URL}/search/${chainId}/${address}`; +}; diff --git a/packages/apps/job-launcher/server/src/modules/job/job.dto.ts b/packages/apps/job-launcher/server/src/modules/job/job.dto.ts index 8f5c9d9d7f..d38f35474e 100644 --- a/packages/apps/job-launcher/server/src/modules/job/job.dto.ts +++ b/packages/apps/job-launcher/server/src/modules/job/job.dto.ts @@ -227,22 +227,6 @@ export class JobIdDto { public id: number; } -export class StakingDetails { - @ApiProperty({ description: 'Ethereum address of the staker' }) - @IsEthereumAddress() - public staker: string; - - @ApiProperty({ description: 'Amount allocated' }) - @IsNumber() - @Min(0) - public allocated: number; - - @ApiProperty({ description: 'Amount slashed' }) - @IsNumber() - @Min(0) - public slashed: number; -} - export class ManifestDetails { @ApiProperty({ description: 'Chain ID', name: 'chain_id' }) @IsNumber() @@ -378,10 +362,6 @@ export class JobDetailsDto { @ApiProperty({ description: 'Manifest details' }) @IsNotEmpty() public manifest: ManifestDetails; - - @ApiProperty({ description: 'Staking details' }) - @IsNotEmpty() - public staking: StakingDetails; } export class FortuneManifestDto { diff --git a/packages/apps/job-launcher/server/src/modules/job/job.service.spec.ts b/packages/apps/job-launcher/server/src/modules/job/job.service.spec.ts index 89316e5077..e09d82ef6f 100644 --- a/packages/apps/job-launcher/server/src/modules/job/job.service.spec.ts +++ b/packages/apps/job-launcher/server/src/modules/job/job.service.spec.ts @@ -4,8 +4,6 @@ import { ChainId, EscrowClient, EscrowStatus, - StakingClient, - IAllocation, EscrowUtils, Encryption, KVStoreUtils, @@ -318,7 +316,6 @@ describe('JobService', () => { it('should use all oracles provided by the user and skip oracle selection', async () => { const fundAmount = 10; - const fee = (MOCK_JOB_LAUNCHER_FEE / 100) * fundAmount; const userBalance = 25; const userId = 1; @@ -365,7 +362,6 @@ describe('JobService', () => { it('should select missing oracles when only partial oracles are provided by the user', async () => { const fundAmount = 10; - const fee = (MOCK_JOB_LAUNCHER_FEE / 100) * fundAmount; const userBalance = 25; const providedReputationOracle = '0xProvidedReputationOracle'; @@ -3380,13 +3376,6 @@ describe('JobService', () => { describe('getDetails', () => { it('should return job details with escrow address successfully', async () => { const balance = '1'; - const allocationMock: IAllocation = { - escrowAddress: ethers.ZeroAddress, - staker: ethers.ZeroAddress, - tokens: 1n, - createdAt: 1n, - closedAt: 1n, - }; const manifestMock: FortuneManifestDto = { submissionsRequired: 10, @@ -3432,11 +3421,6 @@ describe('JobService', () => { recordingOracleAddress: expect.any(String), reputationOracleAddress: expect.any(String), }, - staking: { - staker: expect.any(String), - allocated: expect.any(Number), - slashed: 0, - }, }; const getEscrowData = { @@ -3453,9 +3437,6 @@ describe('JobService', () => { .fn() .mockResolvedValue(jobEntityMock as any); EscrowUtils.getEscrow = jest.fn().mockResolvedValue(getEscrowData); - (StakingClient.build as any).mockImplementation(() => ({ - getAllocation: jest.fn().mockResolvedValue(allocationMock), - })); storageService.download = jest.fn().mockResolvedValue(manifestMock); jobService.getPaidOutAmount = jest.fn().mockResolvedValue(10); @@ -3508,11 +3489,6 @@ describe('JobService', () => { recordingOracleAddress: ethers.ZeroAddress, reputationOracleAddress: ethers.ZeroAddress, }, - staking: { - staker: expect.any(String), - allocated: 0, - slashed: 0, - }, }; jobRepository.findOneByIdAndUserId = jest diff --git a/packages/apps/job-launcher/server/src/modules/job/job.service.ts b/packages/apps/job-launcher/server/src/modules/job/job.service.ts index a0b5d9a446..8638cf3de0 100644 --- a/packages/apps/job-launcher/server/src/modules/job/job.service.ts +++ b/packages/apps/job-launcher/server/src/modules/job/job.service.ts @@ -5,7 +5,6 @@ import { EscrowStatus, EscrowUtils, NETWORKS, - StakingClient, StorageParams, Encryption, KVStoreKeys, @@ -1476,13 +1475,10 @@ export class JobService { const { chainId, escrowAddress, manifestUrl, manifestHash } = jobEntity; const signer = this.web3Service.getSigner(chainId); - let escrow, allocation; + let escrow; if (escrowAddress) { - const stakingClient = await StakingClient.build(signer); - escrow = await EscrowUtils.getEscrow(chainId, escrowAddress); - allocation = await stakingClient.getAllocation(escrowAddress); } let manifestData = await this.storageService.download(manifestUrl); @@ -1575,11 +1571,6 @@ export class JobService { failedReason: jobEntity.failedReason, }, manifest: manifestDetails, - staking: { - staker: ethers.ZeroAddress, - allocated: 0, - slashed: 0, - }, }; } @@ -1594,11 +1585,6 @@ export class JobService { failedReason: jobEntity.failedReason, }, manifest: manifestDetails, - staking: { - staker: allocation?.staker as string, - allocated: Number(ethers.formatEther(allocation?.tokens || 0)), - slashed: 0, // TODO: Retrieve slash tokens - }, }; } diff --git a/packages/apps/job-launcher/server/src/modules/qualification/qualification.module.ts b/packages/apps/job-launcher/server/src/modules/qualification/qualification.module.ts index d5c8df96a7..934c00ee6b 100644 --- a/packages/apps/job-launcher/server/src/modules/qualification/qualification.module.ts +++ b/packages/apps/job-launcher/server/src/modules/qualification/qualification.module.ts @@ -3,9 +3,10 @@ import { ConfigModule } from '@nestjs/config'; import { QualificationService } from './qualification.service'; import { QualificationController } from './qualification.controller'; import { HttpModule } from '@nestjs/axios'; +import { Web3Module } from '../web3/web3.module'; @Module({ - imports: [ConfigModule, HttpModule], + imports: [ConfigModule, HttpModule, Web3Module], providers: [Logger, QualificationService], controllers: [QualificationController], exports: [QualificationService], diff --git a/packages/core/test/Staking.ts b/packages/core/test/Staking.ts index e893a85ad9..c386a32fc4 100644 --- a/packages/core/test/Staking.ts +++ b/packages/core/test/Staking.ts @@ -259,7 +259,7 @@ describe('Staking', function () { expect(event?.escrow).to.not.be.null; }); - describe('Withdrawal without allocation', function () { + describe('Withdrawal without tokens available', function () { describe('Validations', function () { it('Should revert with the right error if has no available tokens for withdrawal', async function () { await expect(staking.connect(operator).withdraw()).to.be.revertedWith( diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/staking/staking_client.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/staking/staking_client.py index c84e16c564..f6619cc6e9 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/staking/staking_client.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/staking/staking_client.py @@ -82,7 +82,7 @@ class StakingClientError(Exception): class StakingClient: """ - A class used to manage staking, and allocation on the HUMAN network. + A class used to manage staking on the HUMAN network. """ def __init__(self, w3: Web3): diff --git a/packages/sdk/typescript/human-protocol-sdk/src/staking.ts b/packages/sdk/typescript/human-protocol-sdk/src/staking.ts index 48aa381d43..de9a1cebd5 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/staking.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/staking.ts @@ -350,7 +350,7 @@ export class StakingClient extends BaseEthersClient { * * @param {string} slasher Wallet address from who requested the slash * @param {string} staker Wallet address from who is going to be slashed - * @param {string} escrowAddress Address of the escrow which allocation will be slashed + * @param {string} escrowAddress Address of the escrow that the slash is made * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object). * @param {bigint} amount Amount in WEI of tokens to unstake. * @returns Returns void if successful. Throws error if any.