Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ type DiscoveredOracleCreateProps = {
address: string;
chainId: ChainId;
stakedAmount: bigint | null;
lockedAmount: bigint | null;
lockedUntilTimestamp: number | null;
withdrawnAmount: bigint | null;
slashedAmount: bigint | null;
amountJobsProcessed: bigint | null;
role: string;
fee: bigint | null;
Expand Down Expand Up @@ -41,24 +37,6 @@ export class DiscoveredOracle {
@ApiPropertyOptional({ description: 'Amount staked by the operator' })
stakedAmount?: string;

@ApiPropertyOptional({
description: 'Amount currently locked by the operator',
})
lockedAmount?: string;

@ApiPropertyOptional({ description: 'Timestamp until funds are locked' })
lockedUntilTimestamp?: string;

@ApiPropertyOptional({
description: 'Total amount withdrawn by the operator',
})
withdrawnAmount?: string;

@ApiPropertyOptional({
description: 'Total amount slashed from the operator',
})
slashedAmount?: string;

@ApiPropertyOptional({
description: 'Number of jobs processed by the operator',
})
Expand Down Expand Up @@ -131,11 +109,7 @@ export class DiscoveredOracle {
this.jobTypes = props.jobTypes ?? [];
this.reputationNetworks = props.reputationNetworks ?? undefined;
this.stakedAmount = props.stakedAmount?.toString();
this.lockedAmount = props.lockedAmount?.toString();
this.withdrawnAmount = props.withdrawnAmount?.toString();
this.slashedAmount = props.slashedAmount?.toString();
this.amountJobsProcessed = props.amountJobsProcessed?.toString();
this.lockedUntilTimestamp = props.lockedUntilTimestamp?.toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ export class OracleDiscoveryService {
registrationInstructions: exchangeOracle.registrationInstructions,
chainId,
stakedAmount: exchangeOracle.stakedAmount,
lockedAmount: exchangeOracle.lockedAmount,
withdrawnAmount: exchangeOracle.withdrawnAmount,
slashedAmount: exchangeOracle.slashedAmount,
amountJobsProcessed: exchangeOracle.amountJobsProcessed,
lockedUntilTimestamp: exchangeOracle.lockedUntilTimestamp,
fee: exchangeOracle.fee,
publicKey: exchangeOracle.publicKey,
webhookUrl: exchangeOracle.webhookUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export const response1: DiscoveredOracle = {
registrationNeeded: true,
registrationInstructions: 'https://instructions.com',
stakedAmount: '0',
lockedAmount: '0',
lockedUntilTimestamp: '0',
withdrawnAmount: '0',
slashedAmount: '0',
amountJobsProcessed: '0',
};

Expand All @@ -37,10 +33,6 @@ export const response2: DiscoveredOracle = {
registrationNeeded: false,
registrationInstructions: undefined,
stakedAmount: '0',
lockedAmount: '0',
lockedUntilTimestamp: '0',
withdrawnAmount: '0',
slashedAmount: '0',
amountJobsProcessed: '0',
};

Expand All @@ -57,10 +49,6 @@ export const response3: DiscoveredOracle = {
registrationNeeded: false,
registrationInstructions: undefined,
stakedAmount: '0',
lockedAmount: '0',
lockedUntilTimestamp: '0',
withdrawnAmount: '0',
slashedAmount: '0',
amountJobsProcessed: '0',
};

Expand All @@ -77,10 +65,6 @@ export const response4: DiscoveredOracle = {
registrationNeeded: false,
registrationInstructions: undefined,
stakedAmount: '0',
lockedAmount: '0',
lockedUntilTimestamp: '0',
withdrawnAmount: '0',
slashedAmount: '0',
amountJobsProcessed: '0',
};

Expand Down
29 changes: 28 additions & 1 deletion packages/sdk/typescript/human-protocol-sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export const NETWORKS: {
'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
subgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmNhLQEfBJQ46fngBh4YCttk8kNkveFy5uvAeUmyAdX1kD',
stakingSubgraphUrl:
'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
stakingSubgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmNhLQEfBJQ46fngBh4YCttk8kNkveFy5uvAeUmyAdX1kD',
oldSubgraphUrl: '',
oldFactoryAddress: '',
},
Expand All @@ -52,6 +56,10 @@ export const NETWORKS: {
'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
subgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmQghdr7hxqrjFde8DN15TzfrJLCfwvzmUH9RzWwH1mKzk',
stakingSubgraphUrl:
'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
stakingSubgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmQghdr7hxqrjFde8DN15TzfrJLCfwvzmUH9RzWwH1mKzk',
oldSubgraphUrl: '',
oldFactoryAddress: '',
},
Expand All @@ -67,6 +75,10 @@ export const NETWORKS: {
'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
subgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmTioC9Z1HzKSCnEKL3BP9iHqbgZt1ceLU2VE4Mv6sxNkd',
stakingSubgraphUrl:
'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
stakingSubgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmTioC9Z1HzKSCnEKL3BP9iHqbgZt1ceLU2VE4Mv6sxNkd',
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
},
Expand All @@ -82,6 +94,10 @@ export const NETWORKS: {
'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
subgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmPyUYRjAvzDdeenXMGHcCRD2v4qwZbKMEkVkY3Jq6VLwn',
stakingSubgraphUrl:
'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
stakingSubgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmPyUYRjAvzDdeenXMGHcCRD2v4qwZbKMEkVkY3Jq6VLwn',
oldSubgraphUrl:
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
Expand All @@ -95,9 +111,13 @@ export const NETWORKS: {
stakingAddress: '0x01D115E9E8bF0C58318793624CC662a030D07F1D',
kvstoreAddress: '0xbcB28672F826a50B03EE91B28145EAbddA73B2eD',
subgraphUrl:
'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
'https://api.studio.thegraph.com/query/74256/human-polygon/version/latest',
subgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmQNkWNE5FPtqbtSkdtR6AEBJz9N7WDz1X7pfvQqYAcUZJ',
stakingSubgraphUrl:
'https://api.studio.thegraph.com/query/118155/staking/version/latest',
stakingSubgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmQNkWNE5FPtqbtSkdtR6AEBJz9N7WDz1X7pfvQqYAcUZJ',
oldSubgraphUrl:
'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
Expand All @@ -114,6 +134,10 @@ export const NETWORKS: {
'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
subgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmcLwLMw3UzCSbNbjegrpNu6PB3kAd67xquuyaVWvc5Q7Q',
stakingSubgraphUrl:
'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
stakingSubgraphUrlApiKey:
'https://gateway.thegraph.com/api/deployments/id/QmcLwLMw3UzCSbNbjegrpNu6PB3kAd67xquuyaVWvc5Q7Q',
oldSubgraphUrl: '',
oldFactoryAddress: '',
},
Expand All @@ -127,6 +151,9 @@ export const NETWORKS: {
kvstoreAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost',
subgraphUrlApiKey: '',
stakingSubgraphUrl:
'http://localhost:8000/subgraphs/name/humanprotocol/staking-localhost',
stakingSubgraphUrlApiKey: '',
oldSubgraphUrl: '',
oldFactoryAddress: '',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const LEADER_FRAGMENT = gql`
fragment OperatorFields on Operator {
id
address
stakedAmount
amountJobsProcessed
role
fee
Expand All @@ -20,14 +21,6 @@ const LEADER_FRAGMENT = gql`
}
name
category
staker {
stakedAmount
lockedAmount
withdrawnAmount
slashedAmount
lockedUntilTimestamp
lastDepositTimestamp
}
}
`;

Expand All @@ -36,7 +29,7 @@ export const GET_LEADERS_QUERY = (filter: IOperatorsFilter) => {

const WHERE_CLAUSE = `
where: {
${minStakedAmount ? `staker_: { stakedAmount_gte: $minStakedAmount }` : ''}
${minStakedAmount ? `stakedAmount_gte: $minStakedAmount` : ''}
${roles ? `role_in: $roles` : ''}
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export type StakerData = {
export interface IOperatorSubgraph {
id: string;
address: string;
stakedAmount: string | null;
amountJobsProcessed: string;
role: string | null;
fee: string | null;
Expand All @@ -156,14 +157,6 @@ export interface IOperatorSubgraph {
category: string | null;
jobTypes: string | string[] | null;
reputationNetworks: { address: string }[];
staker: {
stakedAmount: string;
lockedAmount: string;
lockedUntilTimestamp: string;
withdrawnAmount: string;
slashedAmount: string;
lastDepositTimestamp: string;
} | null;
}

export interface IReputationNetworkSubgraph extends Omit<
Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export interface IOperator {
chainId: ChainId;
address: string;
stakedAmount: bigint | null;
lockedAmount: bigint | null;
lockedUntilTimestamp: number | null;
withdrawnAmount: bigint | null;
slashedAmount: bigint | null;
amountJobsProcessed: bigint | null;
role: string | null;
fee: bigint | null;
Expand Down
22 changes: 2 additions & 20 deletions packages/sdk/typescript/human-protocol-sdk/src/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ export class OperatorUtils {
filter.skip !== undefined && filter.skip >= 0 ? filter.skip : 0;
const orderDirection = filter.orderDirection || OrderDirection.DESC;

let orderBy = filter.orderBy;
if (filter.orderBy === 'stakedAmount') orderBy = 'staker__stakedAmount';
else if (filter.orderBy === 'lockedAmount')
orderBy = 'staker__lockedAmount';
else if (filter.orderBy === 'withdrawnAmount')
orderBy = 'staker__withdrawnAmount';
else if (filter.orderBy === 'slashedAmount')
orderBy = 'staker__slashedAmount';

const networkData = NETWORKS[filter.chainId];

if (!networkData) {
Expand All @@ -144,7 +135,7 @@ export class OperatorUtils {
{
minStakedAmount: filter?.minStakedAmount,
roles: filter?.roles,
orderBy: orderBy,
orderBy: filter?.orderBy,
orderDirection: orderDirection,
first: first,
skip: skip,
Expand Down Expand Up @@ -268,7 +259,6 @@ export class OperatorUtils {
}

function mapOperator(operator: IOperatorSubgraph, chainId: ChainId): IOperator {
const staker = operator?.staker;
let jobTypes: string[] = [];
let reputationNetworks: string[] = [];

Expand All @@ -291,15 +281,7 @@ function mapOperator(operator: IOperatorSubgraph, chainId: ChainId): IOperator {
id: operator.id,
chainId,
address: operator.address,
stakedAmount: staker?.stakedAmount ? BigInt(staker?.stakedAmount) : null,
lockedAmount: staker?.lockedAmount ? BigInt(staker?.lockedAmount) : null,
lockedUntilTimestamp: staker?.lockedUntilTimestamp
? Number(staker.lockedUntilTimestamp) * 1000
: null,
withdrawnAmount: staker?.withdrawnAmount
? BigInt(staker?.withdrawnAmount)
: null,
slashedAmount: staker?.slashedAmount ? BigInt(staker?.slashedAmount) : null,
stakedAmount: operator.stakedAmount ? BigInt(operator.stakedAmount) : null,
amountJobsProcessed: operator.amountJobsProcessed
? BigInt(operator.amountJobsProcessed)
: null,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/typescript/human-protocol-sdk/src/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from './interfaces';
import { StakerData } from './graphql';
import { NetworkData, TransactionOverrides } from './types';
import { getSubgraphUrl, customGqlFetch, throwError } from './utils';
import { getStakingSubgraphUrl, customGqlFetch, throwError } from './utils';
import {
GET_STAKER_BY_ADDRESS_QUERY,
GET_STAKERS_QUERY,
Expand Down Expand Up @@ -509,7 +509,7 @@ export class StakingUtils {
}

const { staker } = await customGqlFetch<{ staker: StakerData }>(
getSubgraphUrl(networkData),
getStakingSubgraphUrl(networkData),
GET_STAKER_BY_ADDRESS_QUERY,
{ id: stakerAddress.toLowerCase() },
options
Expand Down Expand Up @@ -558,7 +558,7 @@ export class StakingUtils {
}

const { stakers } = await customGqlFetch<{ stakers: StakerData[] }>(
getSubgraphUrl(networkData),
getStakingSubgraphUrl(networkData),
GET_STAKERS_QUERY(filter),
{
minStakedAmount: filter.minStakedAmount
Expand Down
8 changes: 8 additions & 0 deletions packages/sdk/typescript/human-protocol-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export type NetworkData = {
* Subgraph URL API key
*/
subgraphUrlApiKey: string;
/**
* Staking subgraph URL
*/
stakingSubgraphUrl?: string;
/**
* Staking subgraph URL API key
*/
stakingSubgraphUrlApiKey?: string;
/**
* Old subgraph URL
*/
Expand Down
27 changes: 27 additions & 0 deletions packages/sdk/typescript/human-protocol-sdk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ export const getSubgraphUrl = (networkData: NetworkData) => {
return subgraphUrl;
};

/**
* Gets the staking subgraph URL for the given network, using API key if available.
* Falls back to the default subgraph URL when staking-specific URLs are not configured.
*
* @param networkData - The network data containing subgraph URLs
* @returns The staking subgraph URL with API key if available
*/
export const getStakingSubgraphUrl = (networkData: NetworkData) => {
const stakingSubgraphUrl = networkData.stakingSubgraphUrl
? networkData.stakingSubgraphUrl
: networkData.subgraphUrl;
const stakingSubgraphUrlApiKey = networkData.stakingSubgraphUrlApiKey
? networkData.stakingSubgraphUrlApiKey
: networkData.subgraphUrlApiKey;

if (process.env.SUBGRAPH_API_KEY) {
return stakingSubgraphUrlApiKey;
}

if (networkData.chainId !== ChainId.LOCALHOST) {
// eslint-disable-next-line no-console
console.warn(WarnSubgraphApiKeyNotProvided);
}

return stakingSubgraphUrl;
};

/**
* Converts a Date object to Unix timestamp (seconds since epoch).
*
Expand Down
Loading
Loading