Skip to content

Commit

Permalink
Add basic pools fetcher, refactor some util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
timjrobinson committed Aug 14, 2023
1 parent 7e9fd2a commit ac7a326
Show file tree
Hide file tree
Showing 6 changed files with 492 additions and 93 deletions.
66 changes: 2 additions & 64 deletions src/composables/queries/useVotingPoolsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import {
} from '@/services/balancer/gauges/gauge-controller.decorator';
import useWeb3 from '@/services/web3/useWeb3';
import { isTestnet } from '@/composables/useNetwork';
import {
GqlChain,
GqlPoolMinimalType,
VeBalGetVotingListQuery,
} from '@/services/api/graphql/generated/api-types';
import { VeBalGetVotingListQuery } from '@/services/api/graphql/generated/api-types';
import { Network } from '@/lib/config';
import { PoolType } from '@/services/pool/types';
import { testnetVotingPools } from '@/components/contextual/pages/vebal/LMVoting/testnet-voting-pools';
import { mapApiChain, mapApiPoolType } from '@/lib/utils/api';

/**
* TYPES
Expand Down Expand Up @@ -94,62 +91,3 @@ export default function useVotingPoolsQuery(
queryOptions as QueryOptions
);
}

export function mapApiChain(
apiChain: GqlChain | 'SEPOLIA' | 'GOERLI'
): Network {
switch (apiChain) {
case GqlChain.Arbitrum:
return Network.ARBITRUM;
case GqlChain.Avalanche:
return Network.AVALANCHE;
case GqlChain.Gnosis:
return Network.GNOSIS;
case GqlChain.Fantom:
return Network.FANTOM;
case GqlChain.Optimism:
return Network.OPTIMISM;
case GqlChain.Polygon:
return Network.POLYGON;
case GqlChain.Mainnet:
return Network.MAINNET;
case GqlChain.Zkevm:
return Network.ZKEVM;
case 'SEPOLIA':
return Network.SEPOLIA;
case 'GOERLI':
return Network.GOERLI;

default:
throw new Error(`Unexpected API chain: ${apiChain}`);
}
}

export function mapApiPoolType(
apiPoolType: GqlPoolMinimalType
): PoolType | null {
switch (apiPoolType) {
case GqlPoolMinimalType.Element:
return PoolType.Element;
case GqlPoolMinimalType.Gyro3:
return PoolType.Gyro3;
case GqlPoolMinimalType.Gyroe:
return PoolType.GyroE;
case GqlPoolMinimalType.Investment:
return PoolType.Investment;
case GqlPoolMinimalType.Linear:
return PoolType.Linear;
case GqlPoolMinimalType.LiquidityBootstrapping:
return PoolType.LiquidityBootstrapping;
case GqlPoolMinimalType.MetaStable:
return PoolType.MetaStable;
case GqlPoolMinimalType.PhantomStable:
return PoolType.StablePhantom;
case GqlPoolMinimalType.Stable:
return PoolType.Stable;
case GqlPoolMinimalType.Weighted:
return PoolType.Weighted;
default:
return null;
}
}
65 changes: 65 additions & 0 deletions src/lib/utils/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
GqlChain,
GqlPoolMinimalType,
} from '@/services/api/graphql/generated/api-types';
import { Network } from '@/lib/config';
import { PoolType } from '@/services/pool/types';

export function mapApiChain(
apiChain: GqlChain | 'SEPOLIA' | 'GOERLI'
): Network {
switch (apiChain) {
case GqlChain.Arbitrum:
return Network.ARBITRUM;
case GqlChain.Avalanche:
return Network.AVALANCHE;
case GqlChain.Gnosis:
return Network.GNOSIS;
case GqlChain.Fantom:
return Network.FANTOM;
case GqlChain.Optimism:
return Network.OPTIMISM;
case GqlChain.Polygon:
return Network.POLYGON;
case GqlChain.Mainnet:
return Network.MAINNET;
case GqlChain.Zkevm:
return Network.ZKEVM;
case 'SEPOLIA':
return Network.SEPOLIA;
case 'GOERLI':
return Network.GOERLI;

default:
throw new Error(`Unexpected API chain: ${apiChain}`);
}
}

export function mapApiPoolType(
apiPoolType: GqlPoolMinimalType
): PoolType | null {
switch (apiPoolType) {
case GqlPoolMinimalType.Element:
return PoolType.Element;
case GqlPoolMinimalType.Gyro3:
return PoolType.Gyro3;
case GqlPoolMinimalType.Gyroe:
return PoolType.GyroE;
case GqlPoolMinimalType.Investment:
return PoolType.Investment;
case GqlPoolMinimalType.Linear:
return PoolType.Linear;
case GqlPoolMinimalType.LiquidityBootstrapping:
return PoolType.LiquidityBootstrapping;
case GqlPoolMinimalType.MetaStable:
return PoolType.MetaStable;
case GqlPoolMinimalType.PhantomStable:
return PoolType.StablePhantom;
case GqlPoolMinimalType.Stable:
return PoolType.Stable;
case GqlPoolMinimalType.Weighted:
return PoolType.Weighted;
default:
return null;
}
}
1 change: 1 addition & 0 deletions src/services/api/graphql/generated/api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ type Mutation {
poolBlackListAddPool(poolId: String!): String!
poolBlackListRemovePool(poolId: String!): String!
poolDeletePool(poolId: String!): String!
poolInitOnChainDataForAllPools: String!
poolInitializeSnapshotsForPool(poolId: String!): String!
poolLoadOnChainDataForAllPools: String!
poolLoadOnChainDataForPoolsWithActiveUpdates: String!
Expand Down
217 changes: 217 additions & 0 deletions src/services/api/graphql/generated/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ export type Mutation = {
poolBlackListAddPool: Scalars['String'];
poolBlackListRemovePool: Scalars['String'];
poolDeletePool: Scalars['String'];
poolInitOnChainDataForAllPools: Scalars['String'];
poolInitializeSnapshotsForPool: Scalars['String'];
poolLoadOnChainDataForAllPools: Scalars['String'];
poolLoadOnChainDataForPoolsWithActiveUpdates: Scalars['String'];
Expand Down Expand Up @@ -1355,6 +1356,97 @@ export type QueryUserGetSwapsArgs = {
skip?: InputMaybe<Scalars['Int']>;
};

export type GetPoolsQueryVariables = Exact<{ [key: string]: never }>;

export type GetPoolsQuery = {
__typename?: 'Query';
pools: Array<{
__typename?: 'GqlPoolMinimal';
id: string;
chain: GqlChain;
address: string;
name: string;
symbol: string;
type: GqlPoolMinimalType;
version: number;
owner?: string | null;
factory?: string | null;
createTime: number;
dynamicData: {
__typename?: 'GqlPoolDynamicData';
totalLiquidity: string;
totalShares: string;
fees24h: string;
swapFee: string;
lifetimeSwapFees: string;
swapEnabled: boolean;
volume24h: string;
lifetimeVolume: string;
apr: {
__typename?: 'GqlPoolApr';
hasRewardApr: boolean;
swapApr: string;
thirdPartyApr:
| { __typename?: 'GqlPoolAprRange'; min: string; max: string }
| { __typename?: 'GqlPoolAprTotal'; total: string };
nativeRewardApr:
| { __typename?: 'GqlPoolAprRange'; min: string; max: string }
| { __typename?: 'GqlPoolAprTotal'; total: string };
apr:
| { __typename?: 'GqlPoolAprRange'; min: string; max: string }
| { __typename?: 'GqlPoolAprTotal'; total: string };
items: Array<{
__typename?: 'GqlBalancePoolAprItem';
id: string;
title: string;
apr:
| { __typename?: 'GqlPoolAprRange'; min: string; max: string }
| { __typename?: 'GqlPoolAprTotal'; total: string };
subItems?: Array<{
__typename?: 'GqlBalancePoolAprSubItem';
id: string;
title: string;
apr:
| { __typename?: 'GqlPoolAprRange'; min: string; max: string }
| { __typename?: 'GqlPoolAprTotal'; total: string };
}> | null;
}>;
};
};
allTokens: Array<{
__typename?: 'GqlPoolTokenExpanded';
id: string;
address: string;
isNested: boolean;
isPhantomBpt: boolean;
weight?: string | null;
symbol: string;
}>;
displayTokens: Array<{
__typename?: 'GqlPoolTokenDisplay';
id: string;
address: string;
name: string;
weight?: string | null;
symbol: string;
nestedTokens?: Array<{
__typename?: 'GqlPoolTokenDisplay';
id: string;
address: string;
name: string;
weight?: string | null;
symbol: string;
}> | null;
}>;
staking?: {
__typename?: 'GqlPoolStaking';
id: string;
type: GqlPoolStakingType;
address: string;
} | null;
}>;
};

export type GetCurrentTokenPricesQueryVariables = Exact<{
[key: string]: never;
}>;
Expand Down Expand Up @@ -1396,6 +1488,117 @@ export type VeBalGetVotingListQuery = {
}>;
};

export const GetPoolsDocument = gql`
query GetPools {
pools: poolGetPools {
id
chain
address
name
symbol
type
version
owner
factory
symbol
createTime
dynamicData {
totalLiquidity
totalShares
fees24h
swapFee
lifetimeSwapFees
swapEnabled
volume24h
lifetimeVolume
apr {
hasRewardApr
thirdPartyApr {
... on GqlPoolAprTotal {
total
}
... on GqlPoolAprRange {
min
max
}
}
nativeRewardApr {
... on GqlPoolAprTotal {
total
}
... on GqlPoolAprRange {
min
max
}
}
swapApr
apr {
... on GqlPoolAprTotal {
total
}
... on GqlPoolAprRange {
min
max
}
}
items {
id
title
apr {
... on GqlPoolAprTotal {
total
}
... on GqlPoolAprRange {
min
max
}
}
subItems {
id
title
apr {
... on GqlPoolAprTotal {
total
}
... on GqlPoolAprRange {
min
max
}
}
}
}
}
}
allTokens {
id
address
isNested
isPhantomBpt
weight
symbol
}
displayTokens {
id
address
name
weight
symbol
nestedTokens {
id
address
name
weight
symbol
}
}
staking {
id
type
address
}
}
}
`;
export const GetCurrentTokenPricesDocument = gql`
query GetCurrentTokenPrices {
prices: tokenGetCurrentPrices {
Expand Down Expand Up @@ -1445,6 +1648,20 @@ export function getSdk(
withWrapper: SdkFunctionWrapper = defaultWrapper
) {
return {
GetPools(
variables?: GetPoolsQueryVariables,
requestHeaders?: Dom.RequestInit['headers']
): Promise<GetPoolsQuery> {
return withWrapper(
wrappedRequestHeaders =>
client.request<GetPoolsQuery>(GetPoolsDocument, variables, {
...requestHeaders,
...wrappedRequestHeaders,
}),
'GetPools',
'query'
);
},
GetCurrentTokenPrices(
variables?: GetCurrentTokenPricesQueryVariables,
requestHeaders?: Dom.RequestInit['headers']
Expand Down
Loading

0 comments on commit ac7a326

Please sign in to comment.