Skip to content

Commit

Permalink
refactor: cleanup squid queries
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Jun 11, 2024
2 parents 171ec10 + d5026ce commit 2fc262b
Show file tree
Hide file tree
Showing 18 changed files with 902 additions and 724 deletions.
4 changes: 2 additions & 2 deletions src/api/contracts/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

import { useApproveSqd } from '@api/contracts/sqd';
import { VESTING_CONTRACT_ABI } from '@api/contracts/vesting.abi';
import { AccountType, BlockchainApiWorker, SourceWallet } from '@api/subsquid-network-squid';
import { AccountType, Worker, SourceWallet } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';
Expand All @@ -25,7 +25,7 @@ import { STAKING_CONTRACT_ABI } from './staking.abi';
import { errorMessage, TxResult, isApproveRequiredError, WriteContractRes } from './utils';

type WorkerDepositRequest = {
worker: BlockchainApiWorker;
worker: Pick<Worker, 'id'>;
amount: string;
wallet: Pick<SourceWallet, 'id' | 'type'>;
};
Expand Down
137 changes: 80 additions & 57 deletions src/api/subsquid-network-squid/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,40 @@ query account($address: String!) {

### WORKERS ###

fragment WorkerFragment on Worker {
fragment WorkerBaseFragment on Worker {
id
name
peerId
}

fragment WorkerStatusFragment on Worker {
status
createdAt
bond
claimableReward
claimedReward
uptime24Hours
uptime90Days
totalDelegation
capedDelegation
delegationCount
apr
stakerApr
online
jailed
dialOk
locked
version
jailReason
owner {
id
type
}
realOwner {
id
}
}

fragment WorkerFragment on Worker {
...WorkerBaseFragment
...WorkerStatusFragment
version
createdAt
uptime90Days
apr
stakerApr
totalDelegation
capedDelegation
}

fragment WorkerFullFragment on Worker {
...WorkerFragment
bond
claimableReward
claimedReward
uptime24Hours
delegationCount
locked
totalDelegationRewards
website
email
Expand All @@ -90,6 +92,9 @@ fragment WorkerFullFragment on Worker {
id
type
}
realOwner {
id
}
}

query allWorkers {
Expand All @@ -98,17 +103,17 @@ query allWorkers {
}
}

query workerByPeerId($peerId: String!, $address: String!) {
query workerByPeerId($peerId: String!, $address: String) {
workers(where: { peerId_eq: $peerId }, limit: 1) {
...WorkerFragment
...WorkerFullFragment
myDelegations: delegations(where: { realOwner: { id_eq: $address } }) {
delegations(where: { realOwner: { id_eq: $address } }) {
claimableReward
claimedReward
deposit
locked
owner {
id
type
balance
}
}
}
Expand All @@ -124,15 +129,9 @@ query workerDaysUptimeById($id: String!, $from: DateTime!) {
query myWorkers($address: String!) {
workers(orderBy: id_ASC, where: { realOwner: { id_eq: $address }, status_not_eq: WITHDRAWN }) {
...WorkerFragment
myDelegations: delegations(where: { realOwner: { id_eq: $address } }) {
deposit
locked
owner {
id
type
balance
}
}
uptime24Hours
claimableReward
claimedReward
}
}

Expand All @@ -142,22 +141,49 @@ query myWorkersCount($address: String!) {
}
}

query workerRewardStats($workerId: String!) {
query workerDelegationInfo($workerId: String!) {
workerById(id: $workerId) {
bond
totalDelegation
capedDelegation
liveness
dTenure
trafficWeight
bond
capedDelegation
totalDelegation
}

statistics(limit: 1) {
utilizedStake
baseApr
}
}

query workerOwner($workerId: String!) {
workerById(id: $workerId) {
owner {
id
type
}
realOwner {
id
}
}
}

query myWorkerDelegations($address: String!, $workerId: String!) {
workerById(id: $workerId) {
delegations(where: { realOwner: { id_eq: $address } }) {
claimableReward
claimedReward
deposit
locked
owner {
id
type
}
}
}
}

query myAssets($address: String!) {
accounts(where: { id_eq: $address }) {
balance
Expand All @@ -167,6 +193,7 @@ query myAssets($address: String!) {
}
}
workers(where: { realOwner: { id_eq: $address } }) {
...WorkerBaseFragment
bond
claimableReward
}
Expand All @@ -182,39 +209,35 @@ query myAssets($address: String!) {
}

query myDelegations($address: String!) {
delegations(where: { realOwner: { id_eq: $address }, deposit_gt: 0 }) {
claimableReward
claimedReward
deposit
locked
worker {
...WorkerFragment
}
owner {
id
type
workers(where: { delegations_some: { realOwner: { id_eq: $address } } }) {
...WorkerFragment
delegations(where: { realOwner: { id_eq: $address } }) {
claimableReward
claimedReward
deposit
locked
owner {
id
type
}
}
}
}

query myClaimsAvailable($address: String!) {
query myClaims($address: String!) {
delegations(where: { realOwner: { id_eq: $address }, claimableReward_gt: 0 }) {
claimableReward
deposit
worker {
id
name
peerId
...WorkerBaseFragment
}
owner {
id
type
}
}
workers(where: { realOwner: { id_eq: $address }, claimableReward_gt: 0 }) {
id
name
peerId
...WorkerBaseFragment
claimableReward
owner {
id
Expand Down
Loading

0 comments on commit 2fc262b

Please sign in to comment.