Skip to content

Commit

Permalink
Refactor Job Launcher to remove allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
flopez7 committed Oct 24, 2024
1 parent 1273036 commit 75ca1a7
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -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<CardTextRowProps> = ({
label,
value,
minWidth = 130,
url,
}) => {
return (
<Stack direction="row" spacing={3}>
Expand All @@ -22,7 +25,19 @@ export const CardTextRow: FC<CardTextRowProps> = ({
color="primary"
sx={{ overflow: 'hidden', textOverflow: 'ellipsis' }}
>
{value}
{url ? (
<Link
style={{
textDecoration: 'underline',
alignItems: 'left',
}}
to={url}
>
{value}
</Link>
) : (
value
)}
</Typography>
</Stack>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/apps/job-launcher/client/src/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
89 changes: 47 additions & 42 deletions packages/apps/job-launcher/client/src/pages/Job/JobDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -91,7 +92,7 @@ export default function JobDetail() {
</LoadingButton>
)}
<Grid container spacing={4}>
<Grid item xs={12} md={6}>
<Grid item xs={12}>
<CardContainer>
<Typography
variant="body2"
Expand All @@ -102,47 +103,31 @@ export default function JobDetail() {
Job details
</Typography>
<Stack spacing={2}>
<CardTextRow
label="Manifest URL"
value={data.details.manifestUrl}
/>
<CardTextRow
label="Manifest Hash"
value={data.details.manifestHash}
/>
<CardTextRow
label="Balance of"
value={`${data.details.balance} HMT`}
/>
<CardTextRow
label="Paid Out HMT"
value={`${data.details.paidOut.toString()} HMT`}
/>
<CardTextRow label="Amount of Jobs" value="" />
<CardTextRow label="Workers assigned" value="" />
</Stack>
</CardContainer>
</Grid>
<Grid item xs={12} md={6}>
<CardContainer>
<Typography
variant="body2"
color="primary"
fontWeight={600}
sx={{ mb: 2 }}
>
Stake details
</Typography>
<Stack spacing={2}>
<CardTextRow label="Staker" value={data.staking.staker} />
<CardTextRow
label="Staked HMT"
value={`${data.staking.allocated.toString()} HMT`}
/>
<CardTextRow
label="Slashed HMT"
value={`${data.staking.slashed.toString()} HMT`}
/>
<Grid container spacing={4}>
<Grid item xs={12} md={6}>
<CardTextRow
label="Manifest URL"
value={data.details.manifestUrl}
url={data.details.manifestUrl}
/>
<CardTextRow
label="Manifest Hash"
value={data.details.manifestHash}
/>
<CardTextRow
label="Balance of"
value={`${data.details.balance} HMT`}
/>
</Grid>
<Grid item xs={12} md={6}>
<CardTextRow
label="Paid Out HMT"
value={`${data.details.paidOut.toString()} HMT`}
/>
<CardTextRow label="Amount of Jobs" value="" />
<CardTextRow label="Workers assigned" value="" />
</Grid>
</Grid>
</Stack>
</CardContainer>
</Grid>
Expand Down Expand Up @@ -175,6 +160,10 @@ export default function JobDetail() {
<CardTextRow
label="Token"
value={data.manifest.tokenAddress}
url={generateDashboardURL(
data.manifest.chainId,
data.manifest.tokenAddress,
)}
/>
<CardTextRow
label="Fund Amount"
Expand All @@ -183,6 +172,10 @@ export default function JobDetail() {
<CardTextRow
label="Job Requester"
value={data.manifest.requesterAddress}
url={generateDashboardURL(
data.manifest.chainId,
data.manifest.requesterAddress,
)}
/>
</Stack>
</Grid>
Expand All @@ -191,14 +184,26 @@ export default function JobDetail() {
<CardTextRow
label="Recording Oracle"
value={data.manifest.recordingOracleAddress}
url={generateDashboardURL(
data.manifest.chainId,
data.manifest.recordingOracleAddress,
)}
/>
<CardTextRow
label="Reputation Oracle"
value={data.manifest.reputationOracleAddress}
url={generateDashboardURL(
data.manifest.chainId,
data.manifest.recordingOracleAddress,
)}
/>
<CardTextRow
label="Exchange Oracle"
value={data.manifest.exchangeOracleAddress}
url={generateDashboardURL(
data.manifest.chainId,
data.manifest.exchangeOracleAddress,
)}
/>
<CardTextRow label="Recording URL" value="" />
<CardTextRow label="Reputation URL" value="" />
Expand Down
7 changes: 7 additions & 0 deletions packages/apps/job-launcher/client/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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}`;
};
20 changes: 0 additions & 20 deletions packages/apps/job-launcher/server/src/modules/job/job.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
ChainId,
EscrowClient,
EscrowStatus,
StakingClient,
IAllocation,
EscrowUtils,
Encryption,
KVStoreUtils,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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);

Expand Down Expand Up @@ -3508,11 +3489,6 @@ describe('JobService', () => {
recordingOracleAddress: ethers.ZeroAddress,
reputationOracleAddress: ethers.ZeroAddress,
},
staking: {
staker: expect.any(String),
allocated: 0,
slashed: 0,
},
};

jobRepository.findOneByIdAndUserId = jest
Expand Down
16 changes: 1 addition & 15 deletions packages/apps/job-launcher/server/src/modules/job/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
EscrowStatus,
EscrowUtils,
NETWORKS,
StakingClient,
StorageParams,
Encryption,
KVStoreKeys,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1575,11 +1571,6 @@ export class JobService {
failedReason: jobEntity.failedReason,
},
manifest: manifestDetails,
staking: {
staker: ethers.ZeroAddress,
allocated: 0,
slashed: 0,
},
};
}

Expand All @@ -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
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/Staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/typescript/human-protocol-sdk/src/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 75ca1a7

Please sign in to comment.