diff --git a/src/app-toolkit/app-toolkit.helpers.ts b/src/app-toolkit/app-toolkit.helpers.ts deleted file mode 100644 index b1d907702..000000000 --- a/src/app-toolkit/app-toolkit.helpers.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { Inject, Injectable } from '@nestjs/common'; - -import { ContractPositionBalanceHelper } from './helpers/balance/contract-position-balance.helper'; -import { SingleStakingContractPositionBalanceHelper } from './helpers/balance/single-staking-farm.contract-position-balance-helper'; -import { StakedTokenHelper } from './helpers/balance/staked.token-helper'; -import { TokenBalanceHelper } from './helpers/balance/token-balance.helper'; -import { MasterChefContractPositionBalanceHelper } from './helpers/master-chef/master-chef.contract-position-balance-helper'; -import { MasterChefContractPositionHelper } from './helpers/master-chef/master-chef.contract-position-helper'; -import { MasterChefDefaultClaimableBalanceStrategy } from './helpers/master-chef/master-chef.default.claimable-token-balances-strategy'; -import { MasterChefDefaultRewardRateStrategy } from './helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy'; -import { MasterChefDefaultStakedBalanceStrategy } from './helpers/master-chef/master-chef.default.staked-token-balance-strategy'; -import { MasterChefV2ClaimableBalanceStrategy } from './helpers/master-chef/master-chef.v2.claimable-token-balance-strategy'; -import { MasterChefV2ClaimableTokenStrategy } from './helpers/master-chef/master-chef.v2.claimable-token-strategy'; -import { MasterChefV2RewardRateStrategy } from './helpers/master-chef/master-chef.v2.reward-rate-strategy'; -import { MerkleContractPositionHelper } from './helpers/merkle/merkle.contract-position-helper'; -import { SingleStakingFarmContractPositionHelper } from './helpers/position/single-staking-farm.contract-position-helper'; -import { VaultTokenHelper } from './helpers/position/vault.token-helper'; -import { TheGraphHelper } from './helpers/the-graph/the-graph.helper'; - -export const AppToolkitHelpers = [ - // General - TokenBalanceHelper, - StakedTokenHelper, - ContractPositionBalanceHelper, - TheGraphHelper, - // Single Staking - SingleStakingContractPositionBalanceHelper, - SingleStakingFarmContractPositionHelper, - // Vaults - VaultTokenHelper, - // Master Chef - MasterChefContractPositionBalanceHelper, - MasterChefContractPositionHelper, - MasterChefDefaultClaimableBalanceStrategy, - MasterChefDefaultRewardRateStrategy, - MasterChefDefaultStakedBalanceStrategy, - MasterChefV2ClaimableBalanceStrategy, - MasterChefV2ClaimableTokenStrategy, - MasterChefV2RewardRateStrategy, - // Merkle - MerkleContractPositionHelper, -]; - -@Injectable() -export class AppToolkitHelperRegistry { - constructor( - @Inject(TokenBalanceHelper) public readonly tokenBalanceHelper: TokenBalanceHelper, - @Inject(StakedTokenHelper) public readonly stakedTokenHelper: StakedTokenHelper, - @Inject(ContractPositionBalanceHelper) public readonly contractPositionBalanceHelper: ContractPositionBalanceHelper, - @Inject(TheGraphHelper) public readonly theGraphHelper: TheGraphHelper, - @Inject(SingleStakingContractPositionBalanceHelper) - public readonly singleStakingContractPositionBalanceHelper: SingleStakingContractPositionBalanceHelper, - @Inject(SingleStakingFarmContractPositionHelper) - public readonly singleStakingFarmContractPositionHelper: SingleStakingFarmContractPositionHelper, - @Inject(VaultTokenHelper) - public readonly vaultTokenHelper: VaultTokenHelper, - @Inject(MasterChefContractPositionBalanceHelper) - public readonly masterChefContractPositionBalanceHelper: MasterChefContractPositionBalanceHelper, - @Inject(MasterChefContractPositionHelper) - public readonly masterChefContractPositionHelper: MasterChefContractPositionHelper, - @Inject(MasterChefDefaultClaimableBalanceStrategy) - public readonly masterChefDefaultClaimableBalanceStrategy: MasterChefDefaultClaimableBalanceStrategy, - @Inject(MasterChefDefaultRewardRateStrategy) - public readonly masterChefDefaultRewardsPerBlockStrategy: MasterChefDefaultRewardRateStrategy, - @Inject(MasterChefDefaultStakedBalanceStrategy) - public readonly masterChefDefaultStakedBalanceStrategy: MasterChefDefaultStakedBalanceStrategy, - @Inject(MasterChefV2ClaimableBalanceStrategy) - public readonly masterChefV2ClaimableBalanceStrategy: MasterChefV2ClaimableBalanceStrategy, - @Inject(MasterChefV2ClaimableTokenStrategy) - public readonly masterChefV2ClaimableTokenStrategy: MasterChefV2ClaimableTokenStrategy, - @Inject(MasterChefV2RewardRateStrategy) - public readonly masterChefV2RewardRateStrategy: MasterChefV2RewardRateStrategy, - @Inject(MerkleContractPositionHelper) - public readonly merkleContractPositionHelper: MerkleContractPositionHelper, - ) {} -} diff --git a/src/app-toolkit/app-toolkit.interface.ts b/src/app-toolkit/app-toolkit.interface.ts index 7d247b815..b34d62354 100644 --- a/src/app-toolkit/app-toolkit.interface.ts +++ b/src/app-toolkit/app-toolkit.interface.ts @@ -15,8 +15,6 @@ import { import { BaseToken } from '~position/token.interface'; import { Network } from '~types/network.interface'; -import { AppToolkitHelperRegistry } from './app-toolkit.helpers'; - export const APP_TOOLKIT = Symbol('APP_TOOLKIT'); export interface IAppToolkit { @@ -65,7 +63,5 @@ export interface IAppToolkit { // Global Helpers - get helpers(): AppToolkitHelperRegistry; - getBigNumber(source: BigNumberJS.Value | ethers.BigNumber): BigNumberJS; } diff --git a/src/app-toolkit/app-toolkit.module.ts b/src/app-toolkit/app-toolkit.module.ts index 3868036f8..d5a523813 100644 --- a/src/app-toolkit/app-toolkit.module.ts +++ b/src/app-toolkit/app-toolkit.module.ts @@ -6,13 +6,12 @@ import { NetworkProviderModule } from '~network-provider/network-provider.module import { PositionModule } from '~position/position.module'; import { TokenModule } from '~token/token.module'; -import { AppToolkitHelperRegistry, AppToolkitHelpers } from './app-toolkit.helpers'; import { APP_TOOLKIT } from './app-toolkit.interface'; import { AppToolkit } from './app-toolkit.service'; @Module({ imports: [NetworkProviderModule, TokenModule, PositionModule, MulticallModule, AppModule], - providers: [{ provide: APP_TOOLKIT, useClass: AppToolkit }, AppToolkitHelperRegistry, ...AppToolkitHelpers], - exports: [APP_TOOLKIT, ...AppToolkitHelpers], + providers: [{ provide: APP_TOOLKIT, useClass: AppToolkit }], + exports: [APP_TOOLKIT], }) export class AppToolkitModule {} diff --git a/src/app-toolkit/app-toolkit.service.ts b/src/app-toolkit/app-toolkit.service.ts index 4975f4a09..920ded3cb 100644 --- a/src/app-toolkit/app-toolkit.service.ts +++ b/src/app-toolkit/app-toolkit.service.ts @@ -1,4 +1,4 @@ -import { CACHE_MANAGER, forwardRef, Inject, Injectable } from '@nestjs/common'; +import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common'; import { BigNumber as BigNumberJS } from 'bignumber.js'; import { Cache } from 'cache-manager'; import { ethers } from 'ethers'; @@ -17,15 +17,12 @@ import { BaseToken } from '~position/token.interface'; import { PriceSelectorService } from '~token/selectors/token-price-selector.service'; import { Network } from '~types/network.interface'; -import { AppToolkitHelperRegistry } from './app-toolkit.helpers'; import { IAppToolkit } from './app-toolkit.interface'; @Injectable() export class AppToolkit implements IAppToolkit { private readonly contractFactory: ContractFactory; constructor( - // We need the forward ref here, since there is a circular dependency on the AppToolkit, since each helper needs the toolkit - @Inject(forwardRef(() => AppToolkitHelperRegistry)) private readonly helperRegistry: AppToolkitHelperRegistry, @Inject(AppService) private readonly appService: AppService, @Inject(NetworkProviderService) private readonly networkProviderService: NetworkProviderService, @Inject(PositionService) private readonly positionService: PositionService, @@ -112,12 +109,6 @@ export class AppToolkit implements IAppToolkit { await Promise.all(entries.map(([key, value]) => this.cacheManager.set(key, value, { ttl }))); } - // Global Helpers - - get helpers() { - return this.helperRegistry; - } - getBigNumber(source: BigNumberJS.Value | ethers.BigNumber): BigNumberJS { if (source instanceof ethers.BigNumber) return new BigNumberJS(source.toString()); return new BigNumberJS(source); diff --git a/src/app-toolkit/helpers/balance/contract-position-balance.helper.ts b/src/app-toolkit/helpers/balance/contract-position-balance.helper.ts deleted file mode 100644 index e34578a95..000000000 --- a/src/app-toolkit/helpers/balance/contract-position-balance.helper.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { Inject, Injectable } from '@nestjs/common'; -import { identity, sumBy } from 'lodash'; - -import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { DefaultDataProps, WithMetaType } from '~position/display.interface'; -import { ContractPositionBalance, TokenBalance } from '~position/position-balance.interface'; -import { ContractPosition } from '~position/position.interface'; -import { Network } from '~types/network.interface'; - -type GetTokenBalancesParams = { - network: Network; - appId: string; - groupId: string; - address: string; - filter?: (contractPosition: ContractPosition) => boolean; - resolveBalances: (opts: { - address: string; - network: Network; - multicall: IMulticallWrapper; - contractPosition: ContractPosition; - }) => Promise[]>; -}; - -@Injectable() -export class ContractPositionBalanceHelper { - constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} - - async getContractPositionBalances({ - network, - appId, - groupId, - address, - filter = identity, - resolveBalances, - }: GetTokenBalancesParams) { - const multicall = this.appToolkit.getMulticall(network); - const contractPositions = await this.appToolkit.getAppContractPositions({ - appId, - network, - groupIds: [groupId], - }); - - const filteredPositions = contractPositions.filter(filter); - const balances = await Promise.all( - filteredPositions.map(async contractPosition => { - const tokens = await resolveBalances({ multicall, network, address, contractPosition }); - const balanceUSD = sumBy(tokens, t => t.balanceUSD); - const balance: ContractPositionBalance = { ...contractPosition, tokens, balanceUSD }; - return balance; - }), - ); - - return balances; - } -} diff --git a/src/app-toolkit/helpers/balance/single-staking-farm.contract-position-balance-helper.ts b/src/app-toolkit/helpers/balance/single-staking-farm.contract-position-balance-helper.ts deleted file mode 100644 index a437a13ef..000000000 --- a/src/app-toolkit/helpers/balance/single-staking-farm.contract-position-balance-helper.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { Inject, Injectable } from '@nestjs/common'; -import { BigNumberish } from 'ethers'; -import { compact, isArray, sumBy } from 'lodash'; - -import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { BALANCE_LOCALSTORAGE_FLAGS } from '~balance/balance.utils'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { ContractPositionBalance } from '~position/position-balance.interface'; -import { ContractPosition, MetaType } from '~position/position.interface'; -import { Network } from '~types/network.interface'; - -import { SingleStakingFarmDataProps } from '../position/single-staking-farm.contract-position-helper'; -import { getImagesFromToken } from '../presentation/image.present'; - -import { drillBalance } from './token-balance.helper'; - -export type SingleStakingContractStrategy = (opts: { address: string; network: Network }) => T; - -export type SingleStakingStakedTokenBalanceStrategy = (opts: { - address: string; - network: Network; - multicall: IMulticallWrapper; - contract: T; - contractPosition: ContractPosition; -}) => BigNumberish | Promise; - -export type SingleStakingRewardTokenBalanceStrategy = (opts: { - address: string; - network: Network; - multicall: IMulticallWrapper; - contract: T; - contractPosition: ContractPosition; -}) => BigNumberish | BigNumberish[] | Promise; - -export type SingleStakingContractPositionBalanceHelperParams = { - address: string; - network: Network; - appId: string; - groupId: string; - farmFilter?: (farm: ContractPosition) => boolean; - resolveContract: SingleStakingContractStrategy; - resolveStakedTokenBalance: SingleStakingStakedTokenBalanceStrategy; - resolveRewardTokenBalances: SingleStakingRewardTokenBalanceStrategy; -}; - -@Injectable() -export class SingleStakingContractPositionBalanceHelper { - constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} - - async getBalances({ - address, - network, - appId, - groupId, - farmFilter, - resolveContract, - resolveStakedTokenBalance, - resolveRewardTokenBalances, - }: SingleStakingContractPositionBalanceHelperParams): Promise { - const multicall = this.appToolkit.getMulticall(network); - const contractPositions = await this.appToolkit.getAppContractPositions({ - network, - appId, - groupIds: [groupId], - }); - - const filteredContractPositions = contractPositions.filter(farmFilter ? farmFilter : () => true); - - const balances = await Promise.all( - filteredContractPositions.map(async contractPosition => { - const contract = resolveContract({ address: contractPosition.address, network }); - const [stakedTokenBalanceRaw, rewardTokenBalancesRawAny] = await Promise.all([ - resolveStakedTokenBalance({ - address, - network, - contract, - contractPosition, - multicall, - }), - resolveRewardTokenBalances({ - address, - network, - contract, - contractPosition, - multicall, - }), - ]); - - const rewardTokenBalancesRaw = isArray(rewardTokenBalancesRawAny) - ? rewardTokenBalancesRawAny - : [rewardTokenBalancesRawAny]; - const stakedToken = contractPosition.tokens.find(v => v.metaType === MetaType.SUPPLIED); - if (!stakedToken) return null; - - const stakedTokenBalance = drillBalance(stakedToken, stakedTokenBalanceRaw.toString()); - const rewardTokens = contractPosition.tokens.filter(v => v.metaType === MetaType.CLAIMABLE); - const rewardTokenBalances = rewardTokens.map((v, i) => - drillBalance(v, rewardTokenBalancesRaw[i]?.toString() ?? '0'), - ); - - const storage = BALANCE_LOCALSTORAGE_FLAGS.getStore(); - const { includeZeroBalances } = storage ?? { includeZeroBalances: false }; - - const tokens = [stakedTokenBalance, ...rewardTokenBalances].filter( - v => includeZeroBalances || v.balanceUSD > 0, - ); - const balanceUSD = sumBy(tokens, t => t.balanceUSD); - - return { - ...contractPosition, - displayProps: { - ...contractPosition.displayProps, - images: getImagesFromToken(stakedToken), - }, - balanceUSD, - tokens, - }; - }), - ); - - return compact(balances); - } -} diff --git a/src/app-toolkit/helpers/balance/staked.token-helper.ts b/src/app-toolkit/helpers/balance/staked.token-helper.ts deleted file mode 100644 index d84403a9f..000000000 --- a/src/app-toolkit/helpers/balance/staked.token-helper.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { Inject, Injectable } from '@nestjs/common'; - -import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { ContractType } from '~position/contract.interface'; -import { AppTokenPosition, ExchangeableAppTokenDataProps } from '~position/position.interface'; -import { Network } from '~types/network.interface'; - -import { buildDollarDisplayItem } from '../presentation/display-item.present'; -import { getTokenImg } from '../presentation/image.present'; - -type StakedTokenHelperParams = { - address: string; - network: Network; - appId: string; - groupId: string; - underlyingTokenAddress: string; - exchangeable?: boolean; - reserveAddress?: string; - resolvePricePerShare?: (opts: { - reserve: number; - supply: number; - address: string; - network: Network; - }) => number | Promise; - resolveLiquidity?: (opts: { reserve: number; supply: number; price: number }) => number; - resolveImages?: (opts: { address: string }) => string[]; -}; - -export type StakedTokenDataProps = ExchangeableAppTokenDataProps & { - liquidity: number; -}; - -@Injectable() -export class StakedTokenHelper { - constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} - - async getTokens({ - address, - network, - appId, - groupId, - underlyingTokenAddress, - reserveAddress, - exchangeable = false, - resolvePricePerShare = ({ reserve, supply }) => reserve / supply, - resolveLiquidity = ({ supply, price }) => supply * price, - resolveImages = ({ address }) => [getTokenImg(address, network)], - }: StakedTokenHelperParams) { - // Supports implementations forked (or similar) to xSUSHI - const type = ContractType.APP_TOKEN; - const contractFactory = this.appToolkit.globalContracts; - const multicall = this.appToolkit.getMulticall(network); - const tokenSelector = this.appToolkit.getTokenDependencySelector({ tags: { network, context: appId } }); - - const underlyingToken = await tokenSelector.getOne({ network, address: underlyingTokenAddress }); - if (!underlyingToken) return []; - - const underlyingTokenContract = contractFactory.erc20({ network, address: underlyingToken.address }); - const tokenContract = contractFactory.erc20({ network, address }); - const reserveLocation = reserveAddress ?? address; - - const [decimals, symbol, supplyRaw, reserveRaw] = await Promise.all([ - multicall.wrap(tokenContract).decimals(), - multicall.wrap(tokenContract).symbol(), - multicall.wrap(tokenContract).totalSupply(), - multicall.wrap(underlyingTokenContract).balanceOf(reserveLocation), - ]); - - const supply = Number(supplyRaw) / 10 ** decimals; - const reserve = Number(reserveRaw) / 10 ** underlyingToken.decimals; - const pricePerShare = await resolvePricePerShare({ reserve, supply, address, network }); - const price = Number(pricePerShare) * underlyingToken.price; - const liquidity = resolveLiquidity({ reserve, supply, price }); - - const tokens = [underlyingToken]; - - // Display properties - const label = symbol; - const secondaryLabel = buildDollarDisplayItem(price); - const images = resolveImages({ address: underlyingTokenAddress }); - const statsItems = [{ label: 'Liquidity', value: buildDollarDisplayItem(liquidity) }]; - - const stakedToken: AppTokenPosition = { - type, - address, - network, - appId, - groupId, - symbol, - decimals, - supply, - price, - pricePerShare, - tokens, - - dataProps: { - liquidity, - exchangeable, - }, - - displayProps: { - label, - secondaryLabel, - images, - statsItems, - }, - }; - - return [stakedToken]; - } -} diff --git a/src/app-toolkit/helpers/balance/token-balance.helper.ts b/src/app-toolkit/helpers/balance/token-balance.helper.ts deleted file mode 100644 index fab52ec62..000000000 --- a/src/app-toolkit/helpers/balance/token-balance.helper.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { Inject, Injectable } from '@nestjs/common'; -import BigNumberJS from 'bignumber.js'; -import { identity, isArray, pick } from 'lodash'; - -import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { ContractType } from '~position/contract.interface'; -import { DefaultDataProps, StatsItem, WithMetaType } from '~position/display.interface'; -import { AppTokenPositionBalance, BaseTokenBalance } from '~position/position-balance.interface'; -import { AppTokenPosition, ContractPosition, MetaType, Token } from '~position/position.interface'; -import { BaseToken } from '~position/token.interface'; -import { Network } from '~types/network.interface'; - -import { buildPercentageDisplayItem } from '../presentation/display-item.present'; - -type GetTokenBalancesParams = { - network: Network; - appId: string; - groupId: string; - address: string; - filter?: (contractPosition: AppTokenPosition) => boolean; - resolveBalance?: (opts: { - multicall: IMulticallWrapper; - address: string; - token: AppTokenPosition; - }) => Promise; -}; - -type Options = { - isDebt?: boolean; -}; - -type InferHasMetaType = T extends WithMetaType ? WithMetaType : B; - -type InferTokenBalanceType = T extends AppTokenPosition - ? InferHasMetaType> - : T extends BaseToken - ? InferHasMetaType - : never; - -export const getContractPositionFromToken = ( - token: AppTokenPosition, - overrides?: Partial>, -): ContractPosition => { - const type = ContractType.POSITION; - const partial = pick(token, 'address', 'network', 'appId', 'groupId'); - const dataProps = { ...token.dataProps, ...overrides?.dataProps }; - const displayProps = { ...token.displayProps, ...overrides?.displayProps }; - const tokens = overrides?.tokens ?? token.tokens.map(v => ({ metaType: MetaType.SUPPLIED, ...v })); - const contractPosition: ContractPosition = { type, ...partial, ...overrides, tokens, dataProps, displayProps }; - return contractPosition; -}; - -export const drillBalance = ( - token: T, - balanceRaw: string, - options: Options = {}, -): InferTokenBalanceType => { - const balance = Number(balanceRaw) / 10 ** token.decimals; - const balanceUSD = balance * token.price * (options.isDebt ? -1 : 1); - - if (token.type === ContractType.BASE_TOKEN || token.type === ContractType.NON_FUNGIBLE_TOKEN) { - const tokenWithBalance = { ...(token as BaseToken), balance, balanceRaw, balanceUSD }; - return tokenWithBalance as unknown as InferTokenBalanceType; - } - - // Token share stats item - const userStatsItems: StatsItem[] = []; - if (token.supply > 0) { - const share = (balance / token.supply) * 100; - userStatsItems.push({ label: 'Share', value: buildPercentageDisplayItem(share) }); - } - - const tokenStatsItems = token.displayProps?.statsItems || []; - const tokens = token.tokens || []; - - const tokenWithBalance = { - ...token, - balance, - balanceRaw, - balanceUSD, - tokens: tokens.map((underlyingToken, i) => { - const pricePerShare = isArray(token.pricePerShare) ? token.pricePerShare[i] : token.pricePerShare; - const underlyingBalanceRawBN = new BigNumberJS(balanceRaw) - .div(10 ** token.decimals) - .times(10 ** underlyingToken.decimals) - .times(pricePerShare); - const underlyingBalanceRaw = - underlyingToken.decimals === 0 ? underlyingBalanceRawBN.toFixed(18) : underlyingBalanceRawBN.toFixed(0); - - return drillBalance(underlyingToken, underlyingBalanceRaw); - }), - dataProps: token.dataProps, - displayProps: { - ...token.displayProps, - statsItems: [...tokenStatsItems, ...userStatsItems], - }, - }; - - return tokenWithBalance as unknown as InferTokenBalanceType; -}; - -@Injectable() -export class TokenBalanceHelper { - constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} - - async getTokenBalances({ - network, - appId, - groupId, - address, - filter = identity, - resolveBalance = async ({ multicall, address, token }) => { - return await multicall - .wrap(this.appToolkit.globalContracts.erc20({ network, address: token.address })) - .balanceOf(address) - .then(v => v.toString()); - }, - }: GetTokenBalancesParams) { - const multicall = this.appToolkit.getMulticall(network); - const appTokens = await this.appToolkit.getAppTokenPositions({ appId, network, groupIds: [groupId] }); - - const filteredTokens = appTokens.filter(filter); - const balances = await Promise.all( - filteredTokens.map(async token => { - const balanceRaw = await resolveBalance({ multicall, address, token }); - const tokenBalance = drillBalance(token as AppTokenPosition, balanceRaw); - return tokenBalance; - }), - ); - - return balances.filter(v => v.balance > 0); - } -} diff --git a/src/app-toolkit/helpers/drill-balance.helper.ts b/src/app-toolkit/helpers/drill-balance.helper.ts new file mode 100644 index 000000000..0a0c5de34 --- /dev/null +++ b/src/app-toolkit/helpers/drill-balance.helper.ts @@ -0,0 +1,71 @@ +import BigNumberJS from 'bignumber.js'; +import { isArray } from 'lodash'; + +import { ContractType } from '~position/contract.interface'; +import { DefaultDataProps, StatsItem, WithMetaType } from '~position/display.interface'; +import { AppTokenPositionBalance, BaseTokenBalance } from '~position/position-balance.interface'; +import { AppTokenPosition, Token } from '~position/position.interface'; +import { BaseToken } from '~position/token.interface'; + +import { buildPercentageDisplayItem } from './presentation/display-item.present'; + +type Options = { + isDebt?: boolean; +}; + +type InferHasMetaType = T extends WithMetaType ? WithMetaType : B; + +type InferTokenBalanceType = T extends AppTokenPosition + ? InferHasMetaType> + : T extends BaseToken + ? InferHasMetaType + : never; + +export const drillBalance = ( + token: T, + balanceRaw: string, + options: Options = {}, +): InferTokenBalanceType => { + const balance = Number(balanceRaw) / 10 ** token.decimals; + const balanceUSD = balance * token.price * (options.isDebt ? -1 : 1); + + if (token.type === ContractType.BASE_TOKEN || token.type === ContractType.NON_FUNGIBLE_TOKEN) { + const tokenWithBalance = { ...(token as BaseToken), balance, balanceRaw, balanceUSD }; + return tokenWithBalance as unknown as InferTokenBalanceType; + } + + // Token share stats item + const userStatsItems: StatsItem[] = []; + if (token.supply > 0) { + const share = (balance / token.supply) * 100; + userStatsItems.push({ label: 'Share', value: buildPercentageDisplayItem(share) }); + } + + const tokenStatsItems = token.displayProps?.statsItems || []; + const tokens = token.tokens || []; + + const tokenWithBalance = { + ...token, + balance, + balanceRaw, + balanceUSD, + tokens: tokens.map((underlyingToken, i) => { + const pricePerShare = isArray(token.pricePerShare) ? token.pricePerShare[i] : token.pricePerShare; + const underlyingBalanceRawBN = new BigNumberJS(balanceRaw) + .div(10 ** token.decimals) + .times(10 ** underlyingToken.decimals) + .times(pricePerShare); + const underlyingBalanceRaw = + underlyingToken.decimals === 0 ? underlyingBalanceRawBN.toFixed(18) : underlyingBalanceRawBN.toFixed(0); + + return drillBalance(underlyingToken, underlyingBalanceRaw); + }), + dataProps: token.dataProps, + displayProps: { + ...token.displayProps, + statsItems: [...tokenStatsItems, ...userStatsItems], + }, + }; + + return tokenWithBalance as unknown as InferTokenBalanceType; +}; diff --git a/src/app-toolkit/helpers/master-chef/master-chef.contract-position-balance-helper.ts b/src/app-toolkit/helpers/master-chef/master-chef.contract-position-balance-helper.ts deleted file mode 100644 index eaa27bdb5..000000000 --- a/src/app-toolkit/helpers/master-chef/master-chef.contract-position-balance-helper.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { Inject, Injectable } from '@nestjs/common'; -import { sumBy } from 'lodash'; - -import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { BALANCE_LOCALSTORAGE_FLAGS } from '~balance/balance.utils'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { WithMetaType } from '~position/display.interface'; -import { ContractPositionBalance, TokenBalance } from '~position/position-balance.interface'; -import { ContractPosition } from '~position/position.interface'; -import { Network } from '~types/network.interface'; - -import { MasterChefContractPositionDataProps } from './master-chef.contract-position-helper'; -import { MasterChefDefaultClaimableBalanceStrategy } from './master-chef.default.claimable-token-balances-strategy'; -import { MasterChefDefaultStakedBalanceStrategy } from './master-chef.default.staked-token-balance-strategy'; - -export type MasterChefChefContractStrategy = (opts: { network: Network; contractAddress: string }) => T; - -export type MasterChefClaimableTokenBalanceStrategy = (opts: { - address: string; - network: Network; - multicall: IMulticallWrapper; - contract: T; - contractPosition: ContractPosition; -}) => Promise[]>; - -export type MasterChefStakedTokenBalanceStrategy = (opts: { - address: string; - network: Network; - multicall: IMulticallWrapper; - contract: T; - contractPosition: ContractPosition; -}) => Promise | null>; - -export type MasterChefContractPositionBalanceHelperParams = { - address: string; - network: Network; - appId: string; - groupId: string; - resolveChefContract: MasterChefChefContractStrategy; - resolveStakedTokenBalance: MasterChefStakedTokenBalanceStrategy; - resolveClaimableTokenBalances: MasterChefClaimableTokenBalanceStrategy; -}; - -@Injectable() -export class MasterChefContractPositionBalanceHelper { - constructor( - @Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, - @Inject(MasterChefDefaultClaimableBalanceStrategy) - private readonly defaultClaimableTokenStrategy: MasterChefDefaultClaimableBalanceStrategy, - @Inject(MasterChefDefaultStakedBalanceStrategy) - private readonly defaultStakedBalanceStrategy: MasterChefDefaultStakedBalanceStrategy, - ) {} - - async getBalances({ - address, - network, - appId, - groupId, - resolveChefContract, - resolveStakedTokenBalance, - resolveClaimableTokenBalances, - }: MasterChefContractPositionBalanceHelperParams): Promise { - const multicall = this.appToolkit.getMulticall(network); - - const contractPositions = await this.appToolkit.getAppContractPositions({ - network, - appId, - groupIds: [groupId], - }); - - const balances = await Promise.all( - contractPositions.map(async contractPosition => { - const contract = resolveChefContract({ network, contractAddress: contractPosition.address }); - const [stakedTokenBalance, claimableTokenBalances] = await Promise.all([ - resolveStakedTokenBalance({ - address, - network, - contract, - contractPosition, - multicall, - }), - resolveClaimableTokenBalances({ - address, - network, - contract, - contractPosition, - multicall, - }), - ]); - - const storage = BALANCE_LOCALSTORAGE_FLAGS.getStore(); - const { includeZeroBalances } = storage ?? { includeZeroBalances: false }; - - const tokens = [stakedTokenBalance!, ...claimableTokenBalances].filter( - v => includeZeroBalances || v.balanceUSD > 0, - ); - const balanceUSD = sumBy(tokens, t => t.balanceUSD); - - return { - ...contractPosition, - balanceUSD, - tokens, - }; - }), - ); - - return balances; - } -} diff --git a/src/app-toolkit/helpers/master-chef/master-chef.contract-position-helper.ts b/src/app-toolkit/helpers/master-chef/master-chef.contract-position-helper.ts deleted file mode 100644 index cb2ff1b5d..000000000 --- a/src/app-toolkit/helpers/master-chef/master-chef.contract-position-helper.ts +++ /dev/null @@ -1,318 +0,0 @@ -import { Contract } from '@ethersproject/contracts'; -import { Inject, Injectable } from '@nestjs/common'; -import { BigNumber, BigNumberish } from 'ethers'; -import _, { compact, isArray, toLower } from 'lodash'; - -import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; -import { BLOCKS_PER_DAY } from '~app-toolkit/constants/blocks'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { ContractType } from '~position/contract.interface'; -import { AppTokenPosition, ContractPosition, Token } from '~position/position.interface'; -import { AppGroupsDefinition } from '~position/position.service'; -import { claimable, supplied } from '~position/position.utils'; -import { BaseToken } from '~position/token.interface'; -import { Network } from '~types/network.interface'; - -import { buildDollarDisplayItem, buildPercentageDisplayItem } from '../presentation/display-item.present'; -import { getImagesFromToken, getLabelFromToken } from '../presentation/image.present'; - -import { - MasterChefDefaultRewardRateStrategy, - MasterChefDefaultRewardRateStrategyParams, -} from './master-chef.default.reward-token-reward-rate-strategy'; - -export type MasterChefContractStrategy = (opts: { address: string; network: Network }) => T; - -export type MasterChefRewardAddressStrategy = (opts: { contract: T; poolIndex: number }) => string | Promise; - -export type MasterChefPoolLengthStrategy = (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; -}) => BigNumberish | Promise; - -export type MasterChefPoolIndexIsValidStrategy = (opts: { - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; -}) => Promise; - -export type MasterChefEndBlockStrategy = (opts: { - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; -}) => Promise; - -export type MasterChefDespositTokenAddressStrategy = (opts: { - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - network: Network; -}) => Promise; - -export type MasterChefRewardTokenAddressesStrategy = (opts: { - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - network: Network; -}) => Promise; - -export type MasterChefRewardRateStrategy = (opts: { - network: Network; - contract: T; - address: string; - multicall: IMulticallWrapper; - depositTokenAddress: string; - poolIndex: number; - baseTokens: BaseToken[]; - appTokens: AppTokenPosition[]; -}) => Promise; - -export type MasterChefLiquidityStrategy = (opts: { - contract: T; - address: string; - network: Network; - multicall: IMulticallWrapper; - depositTokenAddress: string; - poolIndex: number; - baseTokens: BaseToken[]; - appTokens: AppTokenPosition[]; -}) => Promise; - -export enum RewardRateUnit { - BLOCK = 'block', - SECOND = 'second', -} - -export type MasterChefLabelStrategy = (opts: { stakedToken: Token; rewardTokens: Token[] }) => string; - -type MasterChefContractPositionHelperParams = { - address: string; - network: Network; - appId: string; - groupId: string; - minimumTvl?: number; - dependencies?: AppGroupsDefinition[]; - rewardRateUnit?: RewardRateUnit; - resolveContract: MasterChefContractStrategy; - resolveAddress?: MasterChefRewardAddressStrategy; - resolvePoolLength: MasterChefPoolLengthStrategy; - resolvePoolIndexIsValid?: MasterChefPoolIndexIsValidStrategy; - resolveEndBlock?: MasterChefEndBlockStrategy; - resolveDepositTokenAddress: MasterChefDespositTokenAddressStrategy; - resolveRewardTokenAddresses: MasterChefRewardTokenAddressesStrategy; - resolveRewardRate?: MasterChefRewardRateStrategy; - resolveLiquidity?: MasterChefLiquidityStrategy; - resolveLabel?: MasterChefLabelStrategy; -}; - -export type MasterChefContractPositionDataProps = { - poolIndex: number; - liquidity: number; - isActive: boolean; - dailyROI: number; - weeklyROI: number; - yearlyROI: number; -}; - -@Injectable() -export class MasterChefContractPositionHelper { - constructor( - @Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, - @Inject(MasterChefDefaultRewardRateStrategy) - private readonly defaultRewardsPerBlockStrategy: MasterChefDefaultRewardRateStrategy, - ) {} - - async getContractPositions({ - address, - network, - appId, - groupId, - minimumTvl = 0, - dependencies = [], - rewardRateUnit = RewardRateUnit.BLOCK, - resolveContract, - resolvePoolLength, - resolveDepositTokenAddress, - resolveRewardTokenAddresses, - resolveRewardRate = async () => 0, - resolvePoolIndexIsValid = async () => true, - resolveEndBlock = async () => 0, - resolveLiquidity = async ({ depositTokenAddress, address, multicall }) => - multicall - .wrap(this.appToolkit.globalContracts.erc20({ network, address: depositTokenAddress })) - .balanceOf(address), - resolveAddress = async ({ contract }) => (contract as unknown as Contract).address, - resolveLabel = ({ stakedToken }) => `${getLabelFromToken(stakedToken)}`, - }: MasterChefContractPositionHelperParams): Promise[]> { - const provider = this.appToolkit.getNetworkProvider(network); - const multicall = this.appToolkit.getMulticall(network); - - // Resolve the current block, base tokens, and dependency app tokens - const [currentBlock, baseTokens, appTokens] = await Promise.all([ - provider.getBlockNumber(), - this.appToolkit.getBaseTokenPrices(network), - this.appToolkit.getAppTokenPositions(...dependencies), - ]); - - // Resolve the number of pools in this Master Chef implementation - const contract = resolveContract({ address, network }); - const numPools = await resolvePoolLength({ contract, multicall, network }); - - const contractPositions = await Promise.all( - _.range(0, Number(numPools)).flatMap(async poolIndex => { - const type = ContractType.POSITION; - const addressRaw = await resolveAddress({ poolIndex, contract }); - const address = addressRaw.toLowerCase(); - const isValid = await resolvePoolIndexIsValid({ contract, poolIndex, multicall }); - if (!isValid) return null; - - // Resolve end block of rewards - const endBlock = await resolveEndBlock({ contract, multicall, poolIndex }); - - // Resolve deposit token address - const depositTokenAddress = await resolveDepositTokenAddress({ - network, - contract, - poolIndex, - multicall, - }).then(v => v.toLowerCase()); - - // Resolve reward token addresses - const rewardTokenAddresses = await resolveRewardTokenAddresses({ - network, - multicall, - poolIndex, - contract, - }).then(v => (isArray(v) ? v.map(toLower) : [v.toLowerCase()])); - - // Resolve deposit and reward tokens - const allTokens = [...appTokens, ...baseTokens]; - const depositToken = allTokens.find(t => t.address === depositTokenAddress); - const maybeRewardTokens = rewardTokenAddresses.map(v => allTokens.find(t => t.address === v)); - if (!depositToken || depositTokenAddress === ZERO_ADDRESS) return null; - - // Resolve as much as we can about this token from on-chain data - const rewardTokens = await Promise.all( - maybeRewardTokens.map(async (maybeRewardToken, i) => { - if (maybeRewardToken) return maybeRewardToken; - - const address = rewardTokenAddresses[i]; - const contract = this.appToolkit.globalContracts.erc20({ address, network }); - const [symbol, decimals] = await Promise.all([ - multicall.wrap(contract).symbol(), - multicall.wrap(contract).decimals(), - ]); - - const token: BaseToken = { type: ContractType.BASE_TOKEN, address, network, symbol, decimals, price: 0 }; - return token; - }), - ); - - // Resolve liquidity (aka TVL) - const liquidityRaw = await resolveLiquidity({ - multicall, - poolIndex, - contract, - address, - network, - depositTokenAddress, - baseTokens, - appTokens, - }).then(v => Number(v)); - - // Resolve reward token amounts per block - const rewardsPerBlock = await resolveRewardRate({ - network, - multicall, - poolIndex, - contract, - address, - depositTokenAddress, - baseTokens, - appTokens, - }).then(v => (isArray(v) ? v.map(Number) : [Number(v)])); - - // Build tokens - const stakedToken = supplied(depositToken); - const claimableTokens = rewardTokens.map(t => claimable(t)); - const tokens = [stakedToken, ...claimableTokens]; - - // Resolve daily, weekly, and yearly ROIs - let dailyROI = 0; - let weeklyROI = 0; - let yearlyROI = 0; - const isRewardsOver = endBlock > 0 && currentBlock >= endBlock; - const isActive = !isRewardsOver && rewardsPerBlock.some(t => t > 0); - const liquidity = stakedToken.price * (Number(liquidityRaw) / 10 ** stakedToken.decimals); - - if (liquidity !== 0 && isActive) { - const roisPerToken = rewardTokens.map((rewardToken, index) => { - const rewardPerBlock = (rewardsPerBlock[index] ?? 0) / 10 ** rewardToken.decimals; - const dailyRewardRate = - rewardRateUnit === RewardRateUnit.BLOCK - ? rewardPerBlock * BLOCKS_PER_DAY[network] - : rewardPerBlock * 86_400; - const dailyRewardRateUSD = dailyRewardRate * rewardToken.price; - - const dailyROI = (dailyRewardRateUSD + liquidity) / liquidity - 1; - const weeklyROI = Number(dailyROI * 7); - const yearlyROI = dailyROI * 365; - return { dailyROI, weeklyROI, yearlyROI }; - }); - - dailyROI = _.sumBy(roisPerToken, t => t.dailyROI); - weeklyROI = _.sumBy(roisPerToken, t => t.weeklyROI); - yearlyROI = _.sumBy(roisPerToken, t => t.yearlyROI); - } - - // Resolve data properties - const dataProps = { - poolIndex, - liquidity, - isActive, - dailyROI, - weeklyROI, - yearlyROI, - positionKey: `${poolIndex}`, - }; - - // Resolve display properties - const label = resolveLabel({ stakedToken, rewardTokens }); - const secondaryLabel = buildDollarDisplayItem(stakedToken.price); - const images = getImagesFromToken(stakedToken); - const statsItems = [ - { label: 'APR', value: buildPercentageDisplayItem(yearlyROI * 100) }, - { label: 'Liquidity', value: buildDollarDisplayItem(liquidity) }, - ]; - const displayProps = { - label, - secondaryLabel, - images, - statsItems, - }; - - const position: ContractPosition = { - type, - address, - network, - appId, - groupId, - tokens, - dataProps, - displayProps, - }; - - position.key = this.appToolkit.getPositionKey(position); - return position; - }), - ); - - return compact(contractPositions).filter(f => f.dataProps.liquidity >= minimumTvl); - } - - buildDefaultRewardsPerBlockStrategy(opts: MasterChefDefaultRewardRateStrategyParams) { - return this.defaultRewardsPerBlockStrategy.build(opts); - } -} diff --git a/src/app-toolkit/helpers/master-chef/master-chef.default.claimable-token-balances-strategy.ts b/src/app-toolkit/helpers/master-chef/master-chef.default.claimable-token-balances-strategy.ts deleted file mode 100644 index 18b230450..000000000 --- a/src/app-toolkit/helpers/master-chef/master-chef.default.claimable-token-balances-strategy.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { BigNumberish } from 'ethers'; - -import { drillBalance } from '~app-toolkit'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { ContractPosition } from '~position/position.interface'; -import { isClaimable } from '~position/position.utils'; - -import { MasterChefClaimableTokenBalanceStrategy } from './master-chef.contract-position-balance-helper'; -import { MasterChefContractPositionDataProps } from './master-chef.contract-position-helper'; - -export type MasterChefDefaultClaimableBalanceStrategyParams = { - resolveClaimableBalance: (opts: { - address: string; - multicall: IMulticallWrapper; - contract: T; - contractPosition: ContractPosition; - }) => Promise; -}; - -@Injectable() -export class MasterChefDefaultClaimableBalanceStrategy { - build({ - resolveClaimableBalance, - }: MasterChefDefaultClaimableBalanceStrategyParams): MasterChefClaimableTokenBalanceStrategy { - return async opts => { - const { address, contract, multicall, contractPosition } = opts; - const claimableToken = contractPosition.tokens.find(isClaimable); - if (!claimableToken) return []; - - const balanceRaw = await resolveClaimableBalance({ address, contract, multicall, contractPosition }); - const balance = drillBalance(claimableToken, balanceRaw.toString()); - return [balance]; - }; - } -} diff --git a/src/app-toolkit/helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy.ts b/src/app-toolkit/helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy.ts deleted file mode 100644 index 13d1eb519..000000000 --- a/src/app-toolkit/helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { BigNumberish } from 'ethers'; -import { isArray } from 'lodash'; - -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { Network } from '~types/network.interface'; - -import { MasterChefRewardRateStrategy } from './master-chef.contract-position-helper'; - -export type MasterChefDefaultRewardRateStrategyParams = { - resolveTotalAllocPoints: (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - }) => BigNumberish | Promise; - resolvePoolAllocPoints: (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - }) => BigNumberish | Promise; - resolveTotalRewardRate: (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - }) => Promise; - resolveRewardMultiplier?: (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - }) => Promise; -}; - -@Injectable() -export class MasterChefDefaultRewardRateStrategy { - build({ - resolvePoolAllocPoints, - resolveTotalAllocPoints, - resolveTotalRewardRate, - resolveRewardMultiplier = async () => [1], - }: MasterChefDefaultRewardRateStrategyParams): MasterChefRewardRateStrategy { - return async ({ multicall, poolIndex, contract, network }) => { - const [totalAllocPoints, totalRewardPerBlock, poolAllocPoints, rewardMultiplier] = await Promise.all([ - resolveTotalAllocPoints({ contract, multicall, poolIndex, network }), - resolveTotalRewardRate({ contract, multicall, poolIndex, network }), - resolvePoolAllocPoints({ contract, multicall, poolIndex, network }), - resolveRewardMultiplier({ contract, multicall, poolIndex, network }), - ]); - - const poolShare = Number(poolAllocPoints) / Number(totalAllocPoints); - const totalRewardPerBlockArr = isArray(totalRewardPerBlock) ? totalRewardPerBlock : [totalRewardPerBlock]; - const rewardPerBlock = totalRewardPerBlockArr.map( - (v, i) => poolShare * Number(v) * Number(rewardMultiplier[i] ?? 1), - ); - - return rewardPerBlock; - }; - } -} diff --git a/src/app-toolkit/helpers/master-chef/master-chef.default.staked-token-balance-strategy.ts b/src/app-toolkit/helpers/master-chef/master-chef.default.staked-token-balance-strategy.ts deleted file mode 100644 index ee49a1268..000000000 --- a/src/app-toolkit/helpers/master-chef/master-chef.default.staked-token-balance-strategy.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { BigNumberish } from 'ethers'; - -import { drillBalance } from '~app-toolkit'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { ContractPosition } from '~position/position.interface'; -import { isSupplied } from '~position/position.utils'; - -import { MasterChefStakedTokenBalanceStrategy } from './master-chef.contract-position-balance-helper'; -import { MasterChefContractPositionDataProps } from './master-chef.contract-position-helper'; - -export type MasterChefDefaultStakedBalanceStrategyParams = { - resolveStakedBalance: (opts: { - address: string; - multicall: IMulticallWrapper; - contract: T; - contractPosition: ContractPosition; - }) => Promise; -}; - -@Injectable() -export class MasterChefDefaultStakedBalanceStrategy { - build({ - resolveStakedBalance, - }: MasterChefDefaultStakedBalanceStrategyParams): MasterChefStakedTokenBalanceStrategy { - return async opts => { - const { address, contract, multicall, contractPosition } = opts; - const stakedToken = contractPosition.tokens.find(isSupplied); - if (!stakedToken) return null; - - const balanceRaw = await resolveStakedBalance({ address, contract, multicall, contractPosition }); - const balance = drillBalance(stakedToken, balanceRaw.toString()); - return balance; - }; - } -} diff --git a/src/app-toolkit/helpers/master-chef/master-chef.v2.claimable-token-balance-strategy.ts b/src/app-toolkit/helpers/master-chef/master-chef.v2.claimable-token-balance-strategy.ts deleted file mode 100644 index 3af53fcbf..000000000 --- a/src/app-toolkit/helpers/master-chef/master-chef.v2.claimable-token-balance-strategy.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { forwardRef, Inject, Injectable } from '@nestjs/common'; -import { BigNumberish } from 'ethers'; - -import { drillBalance } from '~app-toolkit'; -import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { ContractPosition } from '~position/position.interface'; -import { isClaimable } from '~position/position.utils'; -import { Network } from '~types/network.interface'; - -import { MasterChefClaimableTokenBalanceStrategy } from './master-chef.contract-position-balance-helper'; -import { MasterChefContractPositionDataProps } from './master-chef.contract-position-helper'; -import { MasterChefDefaultClaimableBalanceStrategy } from './master-chef.default.claimable-token-balances-strategy'; - -export type MasterChefV2ClaimableBalanceStrategyParams = { - resolvePrimaryClaimableBalance: (opts: { - address: string; - multicall: IMulticallWrapper; - contract: T; - contractPosition: ContractPosition; - }) => Promise; - resolveRewarderAddress: (opts: { - multicall: IMulticallWrapper; - contract: T; - contractPosition: ContractPosition; - }) => Promise; - resolveRewarderContract: (opts: { rewarderAddress: string; network: Network }) => V; - resolveSecondaryClaimableBalance: (opts: { - address: string; - multicall: IMulticallWrapper; - rewarderContract: V; - contractPosition: ContractPosition; - }) => Promise; -}; - -@Injectable() -export class MasterChefV2ClaimableBalanceStrategy { - constructor( - @Inject(forwardRef(() => MasterChefDefaultClaimableBalanceStrategy)) - private readonly masterChefDefaultClaimableBalanceStrategy: MasterChefDefaultClaimableBalanceStrategy, - ) {} - - build({ - resolvePrimaryClaimableBalance, - resolveRewarderAddress, - resolveRewarderContract, - resolveSecondaryClaimableBalance, - }: MasterChefV2ClaimableBalanceStrategyParams): MasterChefClaimableTokenBalanceStrategy { - const primaryStrategy = this.masterChefDefaultClaimableBalanceStrategy.build({ - resolveClaimableBalance: resolvePrimaryClaimableBalance, - }); - - return async opts => { - // Resolve the reward balance claimable from the primary chef contract - const primaryClaimableBalances = await primaryStrategy(opts); - - // If there are no additional rewards on this index, return early - const rewardTokens = opts.contractPosition.tokens.filter(isClaimable); - if (rewardTokens.length < 2) return primaryClaimableBalances; - - // Resolve additional rewarder address - const rewarderAddressRaw = await resolveRewarderAddress(opts); - const rewarderAddress = rewarderAddressRaw.toLowerCase(); - if (rewarderAddress === ZERO_ADDRESS) return primaryClaimableBalances; - - // Resolve additional claimable amount from the rewarder contract - const rewarderContract = resolveRewarderContract({ rewarderAddress, network: opts.network }); - const claimableBalanceRaw = await resolveSecondaryClaimableBalance({ rewarderContract, ...opts }); - const claimableToken = rewardTokens[1]; - return [...primaryClaimableBalances, drillBalance(claimableToken, claimableBalanceRaw.toString())]; - }; - } -} diff --git a/src/app-toolkit/helpers/master-chef/master-chef.v2.claimable-token-strategy.ts b/src/app-toolkit/helpers/master-chef/master-chef.v2.claimable-token-strategy.ts deleted file mode 100644 index f571333a8..000000000 --- a/src/app-toolkit/helpers/master-chef/master-chef.v2.claimable-token-strategy.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import _ from 'lodash'; - -import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { Network } from '~types/network.interface'; - -import { MasterChefRewardTokenAddressesStrategy } from './master-chef.contract-position-helper'; - -export type MasterChefV2ClaimableTokenStrategyParams = { - resolvePrimaryClaimableToken: (opts: { multicall: IMulticallWrapper; contract: T }) => Promise; - resolveRewarderAddress: (opts: { multicall: IMulticallWrapper; poolIndex: number; contract: T }) => Promise; - resolveRewarderContract: (opts: { rewarderAddress: string; network: Network }) => V; - resolveSecondaryClaimableToken: (opts: { - multicall: IMulticallWrapper; - poolIndex: number; - rewarderContract: V; - }) => Promise; -}; - -@Injectable() -export class MasterChefV2ClaimableTokenStrategy { - build({ - resolvePrimaryClaimableToken, - resolveRewarderAddress, - resolveRewarderContract, - resolveSecondaryClaimableToken, - }: MasterChefV2ClaimableTokenStrategyParams): MasterChefRewardTokenAddressesStrategy { - return async opts => { - // Resolve the reward token address from the primary chef contract - const primaryRewardTokenAddress = await resolvePrimaryClaimableToken(opts); - - // Resolve additional rewarder address - const rewarderAddressRaw = await resolveRewarderAddress(opts); - const rewarderAddress = rewarderAddressRaw.toLowerCase(); - if (rewarderAddress === ZERO_ADDRESS) return [primaryRewardTokenAddress]; - - // Resolve extra reward tokena address from the rewarder contract - const rewarderContract = resolveRewarderContract({ rewarderAddress, network: opts.network }); - const secondaryRewardTokenAddress = await resolveSecondaryClaimableToken({ rewarderContract, ...opts }); - const secondaryRewardTokenAddresses = _.isArray(secondaryRewardTokenAddress) - ? secondaryRewardTokenAddress - : [secondaryRewardTokenAddress]; - return [primaryRewardTokenAddress.toLowerCase(), ...secondaryRewardTokenAddresses.map(v => v.toLowerCase())]; - }; - } -} diff --git a/src/app-toolkit/helpers/master-chef/master-chef.v2.reward-rate-strategy.ts b/src/app-toolkit/helpers/master-chef/master-chef.v2.reward-rate-strategy.ts deleted file mode 100644 index e54353d52..000000000 --- a/src/app-toolkit/helpers/master-chef/master-chef.v2.reward-rate-strategy.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { BigNumberish } from 'ethers'; -import { isArray } from 'lodash'; - -import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { Network } from '~types/network.interface'; - -import { MasterChefRewardRateStrategy } from './master-chef.contract-position-helper'; - -export type MasterChefV2RewardRateStrategyParams = { - resolveTotalAllocPoints: (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - }) => BigNumberish | Promise; - resolvePoolAllocPoints: (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - }) => BigNumberish | Promise; - resolvePrimaryTotalRewardRate: (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - }) => Promise; - resolveRewarderAddress: (opts: { multicall: IMulticallWrapper; poolIndex: number; contract: T }) => Promise; - resolveRewarderContract: (opts: { rewarderAddress: string; network: Network }) => V; - resolveSecondaryTotalRewardRate: (opts: { - multicall: IMulticallWrapper; - poolIndex: number; - rewarderContract: V; - }) => Promise; - resolveRewardMultiplier?: (opts: { - network: Network; - contract: T; - multicall: IMulticallWrapper; - poolIndex: number; - }) => Promise; -}; - -@Injectable() -export class MasterChefV2RewardRateStrategy { - build({ - resolvePoolAllocPoints, - resolveTotalAllocPoints, - resolvePrimaryTotalRewardRate, - resolveRewarderAddress, - resolveRewarderContract, - resolveSecondaryTotalRewardRate, - resolveRewardMultiplier = async () => [1], - }: MasterChefV2RewardRateStrategyParams): MasterChefRewardRateStrategy { - return async opts => { - // Resolve the reward allocations and reward per block from the primary chef contract - const [totalAllocPoints, primaryTotalRewardRate, poolAllocPoints, rewardMultiplier] = await Promise.all([ - resolveTotalAllocPoints(opts), - resolvePrimaryTotalRewardRate(opts), - resolvePoolAllocPoints(opts), - resolveRewardMultiplier(opts), - ]); - - // Resolve additional rewarder address - const rewarderAddressRaw = await resolveRewarderAddress(opts); - const rewarderAddress = rewarderAddressRaw.toLowerCase(); - - // Retrieve bonus token total reward per block if there's a valid rewarder - const totalRewardRate = [primaryTotalRewardRate]; - if (rewarderAddress !== ZERO_ADDRESS) { - const rewarderContract = resolveRewarderContract({ rewarderAddress, ...opts }); - const secondaryTotalRewardRate = await resolveSecondaryTotalRewardRate({ rewarderContract, ...opts }); - const secondaryTotalRewardRates = isArray(secondaryTotalRewardRate) - ? secondaryTotalRewardRate - : [secondaryTotalRewardRate]; - totalRewardRate.push(...secondaryTotalRewardRates); - } - - // Calculate reward per block for the given pool's share - const share = Number(poolAllocPoints) / Number(totalAllocPoints); - const rewardRate = totalRewardRate.map((v, i) => share * Number(v) * Number(rewardMultiplier[i] ?? 1)); - return rewardRate; - }; - } -} diff --git a/src/app-toolkit/helpers/merkle/merkle.contract-position-helper.ts b/src/app-toolkit/helpers/merkle/merkle.contract-position-helper.ts deleted file mode 100644 index 6f0ef1e54..000000000 --- a/src/app-toolkit/helpers/merkle/merkle.contract-position-helper.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { Inject, Injectable } from '@nestjs/common'; -import { compact } from 'lodash'; - -import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { ContractType } from '~position/contract.interface'; -import { ContractPosition } from '~position/position.interface'; -import { AppGroupsDefinition } from '~position/position.service'; -import { claimable } from '~position/position.utils'; -import { Network } from '~types/network.interface'; - -import { buildDollarDisplayItem } from '../presentation/display-item.present'; -import { getImagesFromToken, getLabelFromToken } from '../presentation/image.present'; - -type MerkleContractPositionHelperParams = { - address: string; - network: Network; - appId: string; - groupId: string; - rewardTokenAddresses: string[]; - dependencies?: AppGroupsDefinition[]; -}; - -@Injectable() -export class MerkleContractPositionHelper { - constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} - - async getContractPositions({ - address, - network, - appId, - groupId, - rewardTokenAddresses = [], - dependencies = [], - }: MerkleContractPositionHelperParams): Promise { - // Resolve the base tokens and dependency app tokens - const [baseTokens, appTokens] = await Promise.all([ - this.appToolkit.getBaseTokenPrices(network), - this.appToolkit.getAppTokenPositions(...dependencies), - ]); - - const positions = rewardTokenAddresses.map(rewardTokenAddress => { - const allTokens = [...appTokens, ...baseTokens]; - const rewardToken = allTokens.find(t => t.address === rewardTokenAddress); - if (!rewardToken) return null; - - const tokens = [claimable(rewardToken)]; - const dataProps = {}; - const displayProps = { - label: `Claimable ${getLabelFromToken(rewardToken)}`, - secondaryLabel: buildDollarDisplayItem(rewardToken.price), - images: getImagesFromToken(rewardToken), - }; - - const position: ContractPosition = { - type: ContractType.POSITION, - address, - network, - appId, - groupId, - tokens, - dataProps, - displayProps, - }; - - return position; - }); - - return compact(positions); - } -} diff --git a/src/app-toolkit/helpers/position/single-staking-farm.contract-position-helper.ts b/src/app-toolkit/helpers/position/single-staking-farm.contract-position-helper.ts deleted file mode 100644 index a7a85e4f5..000000000 --- a/src/app-toolkit/helpers/position/single-staking-farm.contract-position-helper.ts +++ /dev/null @@ -1,246 +0,0 @@ -import { Inject, Injectable } from '@nestjs/common'; -import { BigNumberish } from 'ethers'; -import { compact, isArray } from 'lodash'; - -import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { ContractType } from '~position/contract.interface'; -import { WithMetaType } from '~position/display.interface'; -import { ContractPosition, Token } from '~position/position.interface'; -import { AppGroupsDefinition } from '~position/position.service'; -import { claimable, supplied } from '~position/position.utils'; -import { BaseToken } from '~position/token.interface'; -import { Network } from '~types/network.interface'; - -import { buildDollarDisplayItem, buildPercentageDisplayItem } from '../presentation/display-item.present'; -import { getTokenImg } from '../presentation/image.present'; - -export type SingleStakingFarmDefinition = { - address: string; - reserveAddress?: string; - stakedTokenAddress: string; - rewardTokenAddresses: string[]; -}; - -export type SingleStakingFarmRois = { - dailyROI: number; - weeklyROI: number; - yearlyROI: number; -}; - -export type SingleStakingFarmDataProps = { - liquidity: number; - isActive: boolean; - dailyROI: number; - weeklyROI: number; - yearlyROI: number; - implementation?: string; -}; - -export type SingleStakingFarmResolveLiquidityParams = (opts: { - contract: T; - address: string; - network: Network; - stakedToken: WithMetaType; - multicall: IMulticallWrapper; -}) => Promise; - -export type SingleStakingFarmResolveIsActiveParams = (opts: { - address: string; - network: Network; - contract: T; - multicall: IMulticallWrapper; - stakedToken: WithMetaType; - rewardTokens: WithMetaType[]; -}) => boolean | Promise; - -export type SingleStakingFarmResolveRoisParams = (opts: { - address: string; - network: Network; - contract: T; - multicall: IMulticallWrapper; - stakedToken: WithMetaType; - rewardTokens: WithMetaType[]; - liquidity: number; -}) => SingleStakingFarmRois | Promise; - -export type SingleStakingFarmContractPositionHelperParams = { - network: Network; - appId: string; - groupId: string; - dependencies?: AppGroupsDefinition[]; - minimumTvl?: number; - resolveFarmContract: (opts: { address: string; network: Network }) => T; - resolveFarmDefinitions?: (opts: { - network: Network; - }) => SingleStakingFarmDefinition[] | Promise; - resolveImplementation?: () => string; - resolveLabel?: (definition: string | SingleStakingFarmDefinition) => string; - resolveFarmAddresses?: (opts: { network: Network }) => (string | null)[] | Promise<(string | null)[]>; - resolveStakedTokenAddress?: (opts: { contract: T; multicall: IMulticallWrapper; index: number }) => Promise; - resolveRewardTokenAddresses?: (opts: { contract: T; multicall: IMulticallWrapper }) => Promise; - resolveLiquidity?: SingleStakingFarmResolveLiquidityParams; - resolveIsActive?: SingleStakingFarmResolveIsActiveParams; - resolveRois: SingleStakingFarmResolveRoisParams; -}; - -@Injectable() -export class SingleStakingFarmContractPositionHelper { - constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} - - async getContractPositions({ - network, - appId, - groupId, - dependencies = [], - minimumTvl = 0, - resolveFarmContract, - resolveFarmAddresses, - resolveFarmDefinitions, - resolveImplementation, - resolveLabel, - resolveStakedTokenAddress = async () => '', - resolveRewardTokenAddresses = async () => [], - resolveIsActive = async () => true, - resolveRois, - resolveLiquidity = this.defaultLiquidity(), - }: SingleStakingFarmContractPositionHelperParams) { - const multicall = this.appToolkit.getMulticall(network); - - const appTokens = await this.appToolkit.getAppTokenPositions(...dependencies); - const baseTokens = await this.appToolkit.getBaseTokenPrices(network); - const allTokens = [...appTokens, ...baseTokens]; - const farmDefinitionsOrAddresses = resolveFarmDefinitions - ? await resolveFarmDefinitions({ network }) - : resolveFarmAddresses - ? await resolveFarmAddresses({ network }) - : []; - - const contractPositions = await Promise.all( - farmDefinitionsOrAddresses.map( - async (definitionOrAddress: string | SingleStakingFarmDefinition | null, index: number) => { - if (!definitionOrAddress) return null; - - const type = ContractType.POSITION; - const address = typeof definitionOrAddress === 'string' ? definitionOrAddress : definitionOrAddress.address; - const contract = resolveFarmContract({ address, network }); - - // Resolve staked token address - const stakedTokenAddressRaw = - typeof definitionOrAddress === 'string' - ? await resolveStakedTokenAddress({ contract, multicall, index }) - : definitionOrAddress.stakedTokenAddress; - const stakedTokenAddress = stakedTokenAddressRaw.toLowerCase(); - - // Resolve reward token addresses - const rewardTokenAddresses = - typeof definitionOrAddress === 'string' - ? await resolveRewardTokenAddresses({ contract, multicall }).then(v => (isArray(v) ? v : [v])) - : definitionOrAddress.rewardTokenAddresses; - - // Resolve reserve address (where funds are locked) - const reserveAddress = - typeof definitionOrAddress === 'string' - ? definitionOrAddress - : definitionOrAddress.reserveAddress ?? definitionOrAddress.address; - - // Resolve tokens - const depositTokenMatch = allTokens.find(v => v.address === stakedTokenAddress.toLowerCase()); - const maybeRewardTokens = rewardTokenAddresses.map(v => allTokens.find(t => t.address === v.toLowerCase())); - if (!depositTokenMatch) return null; - - // Resolve as much as we can about this token from on-chain data - const rewardTokenMatches = await Promise.all( - maybeRewardTokens.map(async (maybeRewardToken, i) => { - if (maybeRewardToken) return maybeRewardToken; - - const address = rewardTokenAddresses[i]; - const contract = this.appToolkit.globalContracts.erc20({ address, network }); - const [symbol, decimals] = await Promise.all([ - multicall.wrap(contract).symbol(), - multicall.wrap(contract).decimals(), - ]); - - const token: BaseToken = { type: ContractType.BASE_TOKEN, address, network, symbol, decimals, price: 0 }; - return token; - }), - ); - - const stakedToken = supplied(depositTokenMatch); - const rewardTokens = rewardTokenMatches.map(rewardToken => claimable(rewardToken)); - const tokens = [stakedToken, ...rewardTokens]; - - // Resolve data props - const liquidityRaw = await resolveLiquidity({ - address: reserveAddress, - network, - contract, - multicall, - stakedToken, - }); - - const liquidity = stakedToken.price * (Number(liquidityRaw) / 10 ** stakedToken.decimals); - const isActive = await resolveIsActive({ address, network, contract, multicall, stakedToken, rewardTokens }); - - const rois = - isActive === true - ? await resolveRois({ - address, - network, - contract, - multicall, - stakedToken, - rewardTokens: rewardTokenMatches, - liquidity, - }) - : { - dailyROI: 0, - weeklyROI: 0, - yearlyROI: 0, - }; - - const otherProps = resolveImplementation ? { implementation: resolveImplementation() } : {}; - const dataProps = { liquidity, isActive, ...rois, ...otherProps }; - - // Display Properties - const underlyingLabel = - stakedToken.type === ContractType.APP_TOKEN ? stakedToken.displayProps.label : stakedToken.symbol; - const label = resolveLabel ? resolveLabel(definitionOrAddress) : `${underlyingLabel}`; - const secondaryLabel = buildDollarDisplayItem(stakedToken.price); - const images = [getTokenImg(stakedToken.address, network)]; - const statsItems = [ - { label: 'APR', value: buildPercentageDisplayItem(rois.yearlyROI * 100) }, - { label: 'Liquidity', value: buildDollarDisplayItem(liquidity) }, - ]; - const displayProps = { label, secondaryLabel, images, statsItems }; - - const contractPosition: ContractPosition = { - type, - address, - network, - appId, - groupId, - tokens, - dataProps, - displayProps, - }; - - return contractPosition; - }, - ), - ); - - return compact(contractPositions).filter(v => v.dataProps.liquidity >= minimumTvl); - } - - defaultLiquidity(): SingleStakingFarmResolveLiquidityParams { - return ({ stakedToken, network, address, multicall }) => { - return stakedToken.address === ZERO_ADDRESS - ? multicall.wrap(multicall.contract).getEthBalance(address) - : multicall - .wrap(this.appToolkit.globalContracts.erc20({ address: stakedToken.address, network })) - .balanceOf(address); - }; - } -} diff --git a/src/app-toolkit/helpers/position/vault.token-helper.ts b/src/app-toolkit/helpers/position/vault.token-helper.ts deleted file mode 100644 index b5a02a0c4..000000000 --- a/src/app-toolkit/helpers/position/vault.token-helper.ts +++ /dev/null @@ -1,212 +0,0 @@ -import { isPromise } from 'util/types'; - -import { Inject, Injectable } from '@nestjs/common'; -import { compact } from 'lodash'; - -import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { - buildDollarDisplayItem, - buildNumberDisplayItem, - buildPercentageDisplayItem, -} from '~app-toolkit/helpers/presentation/display-item.present'; -import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present'; -import { IMulticallWrapper } from '~multicall/multicall.interface'; -import { ContractType } from '~position/contract.interface'; -import { StatsItem } from '~position/display.interface'; -import { AppTokenPosition, ExchangeableAppTokenDataProps, Token } from '~position/position.interface'; -import { AppGroupsDefinition } from '~position/position.service'; -import { Network } from '~types/network.interface'; - -export type VaultTokenDataProps = ExchangeableAppTokenDataProps & { - liquidity: number; - reserve: number; -}; - -export type VaultTokenHelperParams = { - /** - * Network enum for a given vault - */ - network: Network; - /** - * The application id value should match up to the folder name of a given app - */ - appId: string; - /** - * The group id that is defined for a given app. The value should be obtainable within - * an app's definition file under the groups key. - */ - groupId: string; - /** - * If the vault is dependant on other apps for proper function, then a valid - * application definition must be passed in. - */ - dependencies?: AppGroupsDefinition[]; - /** - * Is this token exchangeable? - */ - exchangeable?: boolean; - /** - * The contract factory which will be leveraged during the entire token retrieval process. - * Usually, you can use the application specific generated contract factory. The factory - * is normally stored within an app folder under the `contracts/` sub-folder - */ - resolveContract: (opts: { address: string; network: Network }) => T; - /** - * The address of a vault we wish to retrieve our tokens from. - * You can either use static string addresses, leverage the multicall function (which should map to the - * the contract passed in via resolveContract) or other methods (such as an external API call). - */ - resolveVaultAddresses: (opts: { multicall: IMulticallWrapper; network: Network }) => string[] | Promise; - /** - * The address of an underlying token which correponds to a vault deposit. - * You can either use static string addresses, leverage the multicall function (which should map to the - * the contract passed in via resolveContract) or other methods (such as an external API call). - */ - resolveUnderlyingTokenAddress: (opts: { - multicall: IMulticallWrapper; - contract: T; - }) => string | Promise; - /** - * How do we resolve the reserve (aka: the liquidity or total supply) of a given underlying token. - */ - resolveReserve: (opts: { - address: string; - contract: T; - multicall: IMulticallWrapper; - underlyingToken: Token; - network: Network; - }) => number | Promise; - /** - * How do we resolve the price of a given share of an underlying token. - */ - resolvePricePerShare: (opts: { - contract: T; - multicall: IMulticallWrapper; - underlyingToken: Token; - reserve: number; - supply: number; - }) => number | Promise; - /** - * How to retrieve the APY of a given vault. - * The APY MUST be a value between 1 - 100 and NOT a fractional value. - * e.g: A value of 6 corresponds to 6%, 42.56 would correspond to 42.56%. - * If empty, we default to 0 - */ - resolveApy?: (opts: { vaultAddress: string; multicall: IMulticallWrapper; contract: T }) => Promise; - /** - * How do we resolve the label that will be displayed on the frontend. - * By default, we will use the symbol. - */ - resolvePrimaryLabel?: (opts: { symbol: string; vaultAddress: string; underlyingToken: Token }) => string; - /** - * How do we resolve the images that will be displayed on the frontend. - * By default, we will attempt to use the underlying token's image. - */ - resolveImages?: (opts: { underlyingToken: Token; symbol: string }) => string[]; -}; - -@Injectable() -export class VaultTokenHelper { - constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} - - /** - * Retrieve all tokens within a given vault. - */ - async getTokens({ - network, - appId, - groupId, - dependencies = [], - exchangeable = false, - resolveVaultAddresses, - resolveContract, - resolveUnderlyingTokenAddress, - resolveReserve, - resolvePricePerShare, - resolveApy, - resolvePrimaryLabel = ({ symbol }) => symbol, - resolveImages = ({ underlyingToken }) => getImagesFromToken(underlyingToken), - }: VaultTokenHelperParams) { - const multicall = this.appToolkit.getMulticall(network); - - const baseTokens = await this.appToolkit.getBaseTokenPrices(network); - const appTokens = await this.appToolkit.getAppTokenPositions(...dependencies); - const allTokens = [...appTokens, ...baseTokens]; - const vaultAddresses = await resolveVaultAddresses({ multicall, network }); - - const tokens = await Promise.all( - vaultAddresses.map(async vaultAddress => { - const type = ContractType.APP_TOKEN; - const erc20Contract = this.appToolkit.globalContracts.erc20({ address: vaultAddress, network }); - const contract = resolveContract({ address: vaultAddress, network }); - - const [symbol, decimals, supplyRaw] = await Promise.all([ - multicall.wrap(erc20Contract).symbol(), - multicall.wrap(erc20Contract).decimals(), - multicall.wrap(erc20Contract).totalSupply(), - ]); - - // Find underlying token in dependencies - const underlyingTokenAddressRawMaybePromise = resolveUnderlyingTokenAddress({ multicall, contract }); - const underlyingTokenAddressRaw = isPromise(underlyingTokenAddressRawMaybePromise) - ? await underlyingTokenAddressRawMaybePromise.catch(() => null) - : underlyingTokenAddressRawMaybePromise; - if (!underlyingTokenAddressRaw) return null; - - const underlyingTokenAddress = underlyingTokenAddressRaw.toLowerCase(); - const underlyingToken = allTokens.find(p => p.address === underlyingTokenAddress); - if (!underlyingToken) return null; - - // Data props - const supply = Number(supplyRaw) / 10 ** decimals; - const reserve = await resolveReserve({ address: vaultAddress, contract, multicall, underlyingToken, network }); - const pricePerShare = await resolvePricePerShare({ multicall, contract, reserve, supply, underlyingToken }); - const apy = resolveApy ? await resolveApy({ multicall, contract, vaultAddress }) : 0; - const price = underlyingToken.price * pricePerShare; - const tokens = [underlyingToken]; - const liquidity = price * supply; - - // Display props - const label = resolvePrimaryLabel({ vaultAddress, symbol, underlyingToken }); - const secondaryLabel = buildDollarDisplayItem(price); - const tertiaryLabel = resolveApy ? `${(apy * 100).toFixed(3)}% APY` : ''; - const images = resolveImages({ underlyingToken, symbol }); - const statsItems: StatsItem[] = [{ label: 'Liquidity', value: buildDollarDisplayItem(liquidity) }]; - if (reserve > 0) statsItems.push({ label: 'Reserve', value: buildNumberDisplayItem(reserve) }); - if (resolveApy) statsItems.push({ label: 'APY', value: buildPercentageDisplayItem(apy) }); - - const vaultToken: AppTokenPosition = { - type, - address: vaultAddress, - network, - appId, - groupId, - symbol, - decimals, - supply, - price, - pricePerShare, - tokens, - - dataProps: { - liquidity, - reserve, - exchangeable, - }, - - displayProps: { - label, - secondaryLabel, - tertiaryLabel, - images, - statsItems, - }, - }; - - return vaultToken; - }), - ); - - return compact(tokens).filter(v => v.price > 0 && v.supply > 0); - } -} diff --git a/src/app-toolkit/helpers/the-graph.helper.ts b/src/app-toolkit/helpers/the-graph.helper.ts new file mode 100644 index 000000000..75713e69a --- /dev/null +++ b/src/app-toolkit/helpers/the-graph.helper.ts @@ -0,0 +1,76 @@ +import { GraphQLClient } from 'graphql-request'; +import { Variables } from 'graphql-request/dist/types'; + +export const gqlFetch = async ({ + endpoint, + query, + variables = {}, + headers = {}, +}: { + endpoint: string; + query: string; + variables?: Variables; + headers?: Record; +}): Promise => { + const client = new GraphQLClient(endpoint, { headers }); + return client.request(query, variables); +}; + +export const gqlFetchAll = async ({ + query, + endpoint, + variables = {}, + dataToSearch, + first = 1000, + lastId = '', + prevResults, +}: { + query: string; + endpoint: string; + variables?: Variables; + dataToSearch: string; + lastId?: string; + first?: number; + prevResults?: T; +}): Promise => { + const results = await gqlFetch({ + endpoint, + query, + variables: { + ...variables, + first: first, + lastId, + }, + }); + + if (results[dataToSearch].length === first) { + let newPrevResults = results; + if (prevResults) { + newPrevResults = { + ...prevResults, + ...results, + [dataToSearch]: [...prevResults[dataToSearch], ...results[dataToSearch]], + }; + } + + return gqlFetchAll({ + query, + endpoint, + variables, + dataToSearch, + first: first, + lastId: results[dataToSearch][results[dataToSearch].length - 1].id, + prevResults: newPrevResults, + }); + } + + if (prevResults) { + return { + ...prevResults, + ...results, + [dataToSearch]: [...prevResults[dataToSearch], ...results[dataToSearch]], + }; + } else { + return results; + } +}; diff --git a/src/app-toolkit/helpers/the-graph/the-graph.helper.ts b/src/app-toolkit/helpers/the-graph/the-graph.helper.ts deleted file mode 100644 index a02f6b7e1..000000000 --- a/src/app-toolkit/helpers/the-graph/the-graph.helper.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { GraphQLClient } from 'graphql-request'; -import { Variables } from 'graphql-request/dist/types'; - -type RequestParams = { - endpoint: string; - query: string; - variables?: Variables; - headers?: Record; -}; - -type RequestGraphParams = { - endpoint: string; - query: string | { present: string; past: string }; - variables?: Variables; - headers?: Record; -}; - -interface gqlFetchAllParams { - query: string; - endpoint: string; - variables?: Variables; - dataToSearch: string; - lastId?: string; - first?: number; - prevResults?: T; -} - -@Injectable() -export class TheGraphHelper { - async request({ endpoint, query, variables, headers }: RequestParams) { - const client = new GraphQLClient(endpoint, { headers }); - return client.request(query, variables); - } - - async requestGraph({ endpoint, query, variables = {} }: RequestGraphParams) { - const presentQuery = typeof query === 'string' ? query : query.present; - const pastQuery = typeof query === 'string' ? null : query.past; - const finalQuery = typeof variables.blockTag === 'number' && pastQuery ? pastQuery : presentQuery; - - return this.request({ endpoint, query: finalQuery, variables }); - } - - async gqlFetchAll({ - query, - endpoint, - variables = {}, - dataToSearch, - first = 1000, - lastId = '', - prevResults, - }: gqlFetchAllParams): Promise { - const results = await this.requestGraph({ - endpoint, - query, - variables: { - ...variables, - first: first, - lastId, - }, - }); - - if (results[dataToSearch].length === first) { - let newPrevResults = results; - if (prevResults) { - newPrevResults = { - ...prevResults, - ...results, - [dataToSearch]: [...prevResults[dataToSearch], ...results[dataToSearch]], - }; - } - - return this.gqlFetchAll({ - query, - endpoint, - variables, - dataToSearch, - first: first, - lastId: results[dataToSearch][results[dataToSearch].length - 1].id, - prevResults: newPrevResults, - }); - } - - if (prevResults) { - return { - ...prevResults, - ...results, - [dataToSearch]: [...prevResults[dataToSearch], ...results[dataToSearch]], - }; - } else { - return results; - } - } -} diff --git a/src/app-toolkit/index.ts b/src/app-toolkit/index.ts deleted file mode 100644 index afa97cb8c..000000000 --- a/src/app-toolkit/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -export { SingleStakingContractPositionBalanceHelper } from './helpers/balance/single-staking-farm.contract-position-balance-helper'; -export { TokenBalanceHelper, getContractPositionFromToken, drillBalance } from './helpers/balance/token-balance.helper'; -export { StakedTokenHelper } from './helpers/balance/staked.token-helper'; -export { ContractPositionBalanceHelper } from './helpers/balance/contract-position-balance.helper'; -export { MasterChefContractPositionBalanceHelper } from './helpers/master-chef/master-chef.contract-position-balance-helper'; -export { MasterChefContractPositionHelper } from './helpers/master-chef/master-chef.contract-position-helper'; -export { MasterChefDefaultClaimableBalanceStrategy } from './helpers/master-chef/master-chef.default.claimable-token-balances-strategy'; -export { MasterChefDefaultRewardRateStrategy as MasterChefDefaultRewardsPerBlockStrategy } from './helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy'; -export { MasterChefDefaultStakedBalanceStrategy } from './helpers/master-chef/master-chef.default.staked-token-balance-strategy'; -export { MasterChefV2ClaimableBalanceStrategy } from './helpers/master-chef/master-chef.v2.claimable-token-balance-strategy'; -export { MasterChefV2ClaimableTokenStrategy } from './helpers/master-chef/master-chef.v2.claimable-token-strategy'; -export { SingleStakingFarmContractPositionHelper } from './helpers/position/single-staking-farm.contract-position-helper'; -export { VaultTokenHelper } from './helpers/position/vault.token-helper'; - -export type { - MasterChefChefContractStrategy, - MasterChefClaimableTokenBalanceStrategy, - MasterChefStakedTokenBalanceStrategy, - MasterChefContractPositionBalanceHelperParams, -} from './helpers/master-chef/master-chef.contract-position-balance-helper'; -export type { - MasterChefContractStrategy, - MasterChefRewardAddressStrategy, - MasterChefPoolLengthStrategy, - MasterChefPoolIndexIsValidStrategy, - MasterChefEndBlockStrategy, - MasterChefDespositTokenAddressStrategy, - MasterChefRewardTokenAddressesStrategy, - MasterChefRewardRateStrategy, - MasterChefLiquidityStrategy, - MasterChefLabelStrategy, - MasterChefContractPositionDataProps, -} from './helpers/master-chef/master-chef.contract-position-helper'; -export type { MasterChefDefaultClaimableBalanceStrategyParams } from './helpers/master-chef/master-chef.default.claimable-token-balances-strategy'; -export type { MasterChefDefaultRewardRateStrategyParams as MasterChefDefaultRewardsPerBlockStrategyParams } from './helpers/master-chef/master-chef.default.reward-token-reward-rate-strategy'; -export type { MasterChefDefaultStakedBalanceStrategyParams } from './helpers/master-chef/master-chef.default.staked-token-balance-strategy'; -export type { MasterChefV2ClaimableBalanceStrategyParams } from './helpers/master-chef/master-chef.v2.claimable-token-balance-strategy'; -export type { MasterChefV2ClaimableTokenStrategyParams } from './helpers/master-chef/master-chef.v2.claimable-token-strategy'; -export type { - SingleStakingContractStrategy, - SingleStakingStakedTokenBalanceStrategy, - SingleStakingRewardTokenBalanceStrategy, - SingleStakingContractPositionBalanceHelperParams, -} from './helpers/balance/single-staking-farm.contract-position-balance-helper'; -export type { - SingleStakingFarmDefinition, - SingleStakingFarmRois, - SingleStakingFarmDataProps, - SingleStakingFarmResolveLiquidityParams, - SingleStakingFarmResolveIsActiveParams, - SingleStakingFarmResolveRoisParams, - SingleStakingFarmContractPositionHelperParams, -} from './helpers/position/single-staking-farm.contract-position-helper'; -export type { VaultTokenDataProps, VaultTokenHelperParams } from './helpers/position/vault.token-helper'; diff --git a/src/apps/abracadabra/common/abracadabra.farm.contract-position-fetcher.ts b/src/apps/abracadabra/common/abracadabra.farm.contract-position-fetcher.ts index 3698d0b33..f7bc385c8 100644 --- a/src/apps/abracadabra/common/abracadabra.farm.contract-position-fetcher.ts +++ b/src/apps/abracadabra/common/abracadabra.farm.contract-position-fetcher.ts @@ -2,11 +2,11 @@ import { Inject } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { AbracadabraContractFactory, PopsicleChef } from '../contracts'; diff --git a/src/apps/aelin/common/aelin.pool.token-fetcher.ts b/src/apps/aelin/common/aelin.pool.token-fetcher.ts index d86ed3533..100ec583f 100644 --- a/src/apps/aelin/common/aelin.pool.token-fetcher.ts +++ b/src/apps/aelin/common/aelin.pool.token-fetcher.ts @@ -3,6 +3,7 @@ import { ethers } from 'ethers'; import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { GetUnderlyingTokensParams, GetDisplayPropsParams } from '~position/template/app-token.template.types'; @@ -38,10 +39,7 @@ export abstract class AelinPoolTokenFetcher extends AppTokenTemplatePositionFetc } async getAddresses() { - const data = await this.appToolkit.helpers.theGraphHelper.request({ - endpoint: this.subgraphUrl, - query, - }); + const data = await gqlFetch({ endpoint: this.subgraphUrl, query }); return data.poolCreateds.map(v => v.id); } diff --git a/src/apps/angle/ethereum/angle.perpetual.contract-position-fetcher.ts b/src/apps/angle/ethereum/angle.perpetual.contract-position-fetcher.ts index b4269788b..5d1a1365e 100644 --- a/src/apps/angle/ethereum/angle.perpetual.contract-position-fetcher.ts +++ b/src/apps/angle/ethereum/angle.perpetual.contract-position-fetcher.ts @@ -2,9 +2,9 @@ import { Inject } from '@nestjs/common'; import { BigNumber, BigNumberish, utils } from 'ethers'; import { compact } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; diff --git a/src/apps/angle/ethereum/angle.vault.contract-position-fetcher.ts b/src/apps/angle/ethereum/angle.vault.contract-position-fetcher.ts index 2da12496c..21a68ef58 100644 --- a/src/apps/angle/ethereum/angle.vault.contract-position-fetcher.ts +++ b/src/apps/angle/ethereum/angle.vault.contract-position-fetcher.ts @@ -2,9 +2,9 @@ import { Inject } from '@nestjs/common'; import { BigNumberish, utils } from 'ethers'; import { compact, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; diff --git a/src/apps/apecoin/ethereum/apecoin.staking.contract-position-fetcher.ts b/src/apps/apecoin/ethereum/apecoin.staking.contract-position-fetcher.ts index f98171df1..bccefa50c 100644 --- a/src/apps/apecoin/ethereum/apecoin.staking.contract-position-fetcher.ts +++ b/src/apps/apecoin/ethereum/apecoin.staking.contract-position-fetcher.ts @@ -2,9 +2,9 @@ import { Inject } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { merge, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance, RawContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; diff --git a/src/apps/arbor-finance/ethereum/arbor-finance.bond.token-fetcher.ts b/src/apps/arbor-finance/ethereum/arbor-finance.bond.token-fetcher.ts index 505918b75..ecd293c11 100644 --- a/src/apps/arbor-finance/ethereum/arbor-finance.bond.token-fetcher.ts +++ b/src/apps/arbor-finance/ethereum/arbor-finance.bond.token-fetcher.ts @@ -3,6 +3,7 @@ import dayjs from 'dayjs'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { DefaultAppTokenDataProps, @@ -40,8 +41,7 @@ export class EthereumArborFinanceBondTokenFetcher extends AppTokenTemplatePositi } async getDefinitions(): Promise { - const graphHelper = this.appToolkit.helpers.theGraphHelper; - const data = await graphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/alwaysbegrowing/arbor-v1', query: BONDS_QUERY, }); diff --git a/src/apps/arrakis/common/arrakis.pool-definition-resolver.ts b/src/apps/arrakis/common/arrakis.pool-definition-resolver.ts index 19481cc71..833e858f4 100644 --- a/src/apps/arrakis/common/arrakis.pool-definition-resolver.ts +++ b/src/apps/arrakis/common/arrakis.pool-definition-resolver.ts @@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Cache } from '~cache/cache.decorator'; import { Network } from '~types/network.interface'; @@ -46,7 +47,7 @@ export class ArrakisPoolDefinitionsResolver { ttl: 5 * 60, // 5 minutes }) private async getPoolDefinitionsData(network: Network) { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: `https://api.thegraph.com/subgraphs/name/gelatodigital/g-uni${NETWORK_NAME[network]}`, query: POOL_ADDRESSES_QUERY, }); diff --git a/src/apps/atlendis-v1/common/atlendis-v1.pool.contract-position-fetcher.ts b/src/apps/atlendis-v1/common/atlendis-v1.pool.contract-position-fetcher.ts index bd83dc931..c97737670 100644 --- a/src/apps/atlendis-v1/common/atlendis-v1.pool.contract-position-fetcher.ts +++ b/src/apps/atlendis-v1/common/atlendis-v1.pool.contract-position-fetcher.ts @@ -4,8 +4,9 @@ import { BigNumberish } from 'ethers'; import { gql } from 'graphql-request'; import { compact, merge } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType, Standard } from '~position/position.interface'; import { @@ -100,7 +101,7 @@ export abstract class AtlendisV1PoolContractPositionFetcher extends CustomContra } async getDefinitions(): Promise { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: this.subgraphUrl, query: GET_POOLS_QUERY, }); @@ -138,7 +139,7 @@ export abstract class AtlendisV1PoolContractPositionFetcher extends CustomContra async getBalances(address: string): Promise[]> { const multicall = this.appToolkit.getMulticall(this.network); - const userPositionsData = await this.appToolkit.helpers.theGraphHelper.request({ + const userPositionsData = await gqlFetch({ endpoint: this.subgraphUrl, query: GET_USER_POSITIONS, variables: { address }, diff --git a/src/apps/aura/common/aura.balancer-pool.resolver.ts b/src/apps/aura/common/aura.balancer-pool.resolver.ts index 1e486f96b..23d323b95 100644 --- a/src/apps/aura/common/aura.balancer-pool.resolver.ts +++ b/src/apps/aura/common/aura.balancer-pool.resolver.ts @@ -3,6 +3,7 @@ import { BigNumber, ethers } from 'ethers'; import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Cache } from '~cache/cache.decorator'; import { Network } from '~types/network.interface'; @@ -96,7 +97,7 @@ export class AuraBalancerPoolResolver { }) private async getBalancerPoolData(poolId: string) { const endpoint = `https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2`; - const { pool } = await this.appToolkit.helpers.theGraphHelper.request({ + const { pool } = await gqlFetch({ endpoint, query: GET_POOL_QUERY, variables: { id: poolId }, diff --git a/src/apps/aura/ethereum/aura.chef.contract-position-fetcher.ts b/src/apps/aura/ethereum/aura.chef.contract-position-fetcher.ts index a1dae93cc..dfe58d941 100644 --- a/src/apps/aura/ethereum/aura.chef.contract-position-fetcher.ts +++ b/src/apps/aura/ethereum/aura.chef.contract-position-fetcher.ts @@ -3,11 +3,11 @@ import { BigNumber, BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { AuraContractFactory, AuraMasterchef } from '../contracts'; diff --git a/src/apps/balancer-v1/common/balancer-v1.volume.data-loader.ts b/src/apps/balancer-v1/common/balancer-v1.volume.data-loader.ts index 620a77560..6d458de4d 100644 --- a/src/apps/balancer-v1/common/balancer-v1.volume.data-loader.ts +++ b/src/apps/balancer-v1/common/balancer-v1.volume.data-loader.ts @@ -3,6 +3,7 @@ import DataLoader from 'dataloader'; import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Network } from '~types/network.interface'; const GET_POOL_VOLUMES_QUERY = gql` @@ -42,7 +43,7 @@ export abstract class BalancerV1PoolSubgraphVolumeDataLoader { const ts = Math.round(new Date().getTime() / 1000); const tsYesterday = ts - 24 * 3600; - const volumeResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const volumeResponse = await gqlFetch({ endpoint: this.subgraphUrl, query: GET_POOL_VOLUMES_QUERY, variables: { tsYesterday, addresses }, diff --git a/src/apps/balancer-v1/ethereum/balancer-v1.pool.token-fetcher.ts b/src/apps/balancer-v1/ethereum/balancer-v1.pool.token-fetcher.ts index 95bb9329e..3a1b1bf0b 100644 --- a/src/apps/balancer-v1/ethereum/balancer-v1.pool.token-fetcher.ts +++ b/src/apps/balancer-v1/ethereum/balancer-v1.pool.token-fetcher.ts @@ -11,6 +11,7 @@ import { buildPercentageDisplayItem, } from '~app-toolkit/helpers/presentation/display-item.present'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { GetUnderlyingTokensParams, @@ -70,7 +71,7 @@ export class EthereumBalancerV1PoolTokenFetcher extends AppTokenTemplatePosition async getAddresses() { this.volumeDataLoader = this.volumeDataLoaderBuilder.getLoader(); - const poolsFromSubgraph = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const poolsFromSubgraph = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer', query: getPoolsQuery, }); diff --git a/src/apps/balancer-v2/common/balancer-v2.claimable.contract-position-fetcher.ts b/src/apps/balancer-v2/common/balancer-v2.claimable.contract-position-fetcher.ts index bf089e316..b35376e01 100644 --- a/src/apps/balancer-v2/common/balancer-v2.claimable.contract-position-fetcher.ts +++ b/src/apps/balancer-v2/common/balancer-v2.claimable.contract-position-fetcher.ts @@ -2,8 +2,8 @@ import { Inject, NotImplementedException } from '@nestjs/common'; import BigNumber from 'bignumber.js'; import { compact, range, sum, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getLabelFromToken, getTokenImg } from '~app-toolkit/helpers/presentation/image.present'; import { ContractType } from '~position/contract.interface'; diff --git a/src/apps/balancer-v2/common/balancer-v2.farm.contract-position-fetcher.ts b/src/apps/balancer-v2/common/balancer-v2.farm.contract-position-fetcher.ts index 78ab69a06..6dbc14008 100644 --- a/src/apps/balancer-v2/common/balancer-v2.farm.contract-position-fetcher.ts +++ b/src/apps/balancer-v2/common/balancer-v2.farm.contract-position-fetcher.ts @@ -5,6 +5,7 @@ import { range } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { isClaimable } from '~position/position.utils'; import { GetDataPropsParams, @@ -47,7 +48,7 @@ export abstract class BalancerV2FarmContractPositionFetcher extends SingleStakin } async getFarmAddresses() { - const gaugesResponse = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const gaugesResponse = await gqlFetch({ endpoint: this.subgraphUrl, query: GAUGES_QUERY, }); diff --git a/src/apps/balancer-v2/common/balancer-v2.pool.token-fetcher.ts b/src/apps/balancer-v2/common/balancer-v2.pool.token-fetcher.ts index 69c34d566..b6830c847 100644 --- a/src/apps/balancer-v2/common/balancer-v2.pool.token-fetcher.ts +++ b/src/apps/balancer-v2/common/balancer-v2.pool.token-fetcher.ts @@ -4,6 +4,7 @@ import { isEmpty } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { isMulticallUnderlyingError } from '~multicall/multicall.ethers'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { @@ -74,7 +75,7 @@ export abstract class BalancerV2PoolTokenFetcher extends AppTokenTemplatePositio } async getDefinitions(): Promise { - const poolsResponse = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const poolsResponse = await gqlFetch({ endpoint: this.subgraphUrl, query: GET_POOLS_QUERY, }); diff --git a/src/apps/banano/common/banano.farm.contract-position-fetcher.ts b/src/apps/banano/common/banano.farm.contract-position-fetcher.ts index 27ae01e4f..448139b66 100644 --- a/src/apps/banano/common/banano.farm.contract-position-fetcher.ts +++ b/src/apps/banano/common/banano.farm.contract-position-fetcher.ts @@ -2,11 +2,11 @@ import { Inject } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { BananoContractFactory, Benis } from '../contracts'; diff --git a/src/apps/beethoven-x/common/beethoven-x.farm.contract-position-fetcher.ts b/src/apps/beethoven-x/common/beethoven-x.farm.contract-position-fetcher.ts index d7a654995..773d1f5a3 100644 --- a/src/apps/beethoven-x/common/beethoven-x.farm.contract-position-fetcher.ts +++ b/src/apps/beethoven-x/common/beethoven-x.farm.contract-position-fetcher.ts @@ -5,6 +5,7 @@ import { range } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { isClaimable } from '~position/position.utils'; import { GetDataPropsParams, @@ -48,7 +49,7 @@ export abstract class BeethovenXFarmContractPositionFetcher extends SingleStakin } async getFarmAddresses() { - const gaugesResponse = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const gaugesResponse = await gqlFetch({ endpoint: this.subgraphUrl, query: GAUGES_QUERY, }); diff --git a/src/apps/beethoven-x/common/beethoven-x.pool.token-fetcher.ts b/src/apps/beethoven-x/common/beethoven-x.pool.token-fetcher.ts index 2ed8ccf2c..41eca0de6 100644 --- a/src/apps/beethoven-x/common/beethoven-x.pool.token-fetcher.ts +++ b/src/apps/beethoven-x/common/beethoven-x.pool.token-fetcher.ts @@ -1,5 +1,6 @@ import { gql } from 'graphql-request'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { BalancerV2PoolTokenDataProps, BalancerV2PoolTokenDefinition, @@ -41,7 +42,7 @@ export abstract class BeethovenXPoolTokenFetcher extends BalancerV2PoolTokenFetc abstract weightedPoolV2Factory: string; async getDefinitions() { - const poolsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const poolsResponse = await gqlFetch({ endpoint: this.subgraphUrl, query: GET_POOLS_QUERY, headers: { 'Content-Type': 'application/json' }, diff --git a/src/apps/bluebit/aurora/bluebit.farm.contract-position-fetcher.ts b/src/apps/bluebit/aurora/bluebit.farm.contract-position-fetcher.ts index efd559d3f..982c60edd 100644 --- a/src/apps/bluebit/aurora/bluebit.farm.contract-position-fetcher.ts +++ b/src/apps/bluebit/aurora/bluebit.farm.contract-position-fetcher.ts @@ -3,11 +3,11 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { BluebitChef, BluebitContractFactory } from '../contracts'; diff --git a/src/apps/chicken-bond/ethereum/chicken-bond.bond.contract-position-fetcher.ts b/src/apps/chicken-bond/ethereum/chicken-bond.bond.contract-position-fetcher.ts index acd3968c4..452d8a551 100644 --- a/src/apps/chicken-bond/ethereum/chicken-bond.bond.contract-position-fetcher.ts +++ b/src/apps/chicken-bond/ethereum/chicken-bond.bond.contract-position-fetcher.ts @@ -1,10 +1,9 @@ import { Inject, NotImplementedException } from '@nestjs/common'; -import _ from 'lodash'; -import { range } from 'lodash'; +import _, { range } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; diff --git a/src/apps/concave/ethereum/concave.liquid-staking.contract-position-fetcher.ts b/src/apps/concave/ethereum/concave.liquid-staking.contract-position-fetcher.ts index bb67a63da..504cc9578 100644 --- a/src/apps/concave/ethereum/concave.liquid-staking.contract-position-fetcher.ts +++ b/src/apps/concave/ethereum/concave.liquid-staking.contract-position-fetcher.ts @@ -5,9 +5,10 @@ import { gql } from 'graphql-request'; import { sumBy } from 'lodash'; import moment from 'moment'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { ContractType } from '~position/contract.interface'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; @@ -108,7 +109,7 @@ export class EthereumConcaveLiquidStakingContractPositionFetcher extends CustomC const balanceRaw = await contract.balanceOf(address); if (Number(balanceRaw) === 0) return []; - const lockData = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const lockData = await gqlFetch({ endpoint: 'https://concave.hasura.app/v1/graphql', query: GET_STAKING_V1_LOCK_EVENTS, variables: { address: getAddress(address) }, diff --git a/src/apps/dystopia/polygon/dystopia.farm.contract-position-fetcher.ts b/src/apps/dystopia/polygon/dystopia.farm.contract-position-fetcher.ts index e5c1d9352..0cc94a71f 100644 --- a/src/apps/dystopia/polygon/dystopia.farm.contract-position-fetcher.ts +++ b/src/apps/dystopia/polygon/dystopia.farm.contract-position-fetcher.ts @@ -3,6 +3,7 @@ import { filter, range } from 'lodash'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { isClaimable } from '~position/position.utils'; import { GetTokenDefinitionsParams, @@ -34,7 +35,7 @@ export class PolygonDystopiaStakingContractPositionFetcher extends SingleStaking } async getFarmAddresses() { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/dystopia-exchange/dystopia', query: DYSTOPIA_QUERY, }); diff --git a/src/apps/dystopia/polygon/dystopia.pool.token-fetcher.ts b/src/apps/dystopia/polygon/dystopia.pool.token-fetcher.ts index 2c91b7b55..9d5916d3c 100644 --- a/src/apps/dystopia/polygon/dystopia.pool.token-fetcher.ts +++ b/src/apps/dystopia/polygon/dystopia.pool.token-fetcher.ts @@ -5,6 +5,7 @@ import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DefaultDataProps } from '~position/display.interface'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { @@ -52,7 +53,7 @@ export class PolygonDystopiaPairsTokenFetcher extends AppTokenTemplatePositionFe } async getAddresses() { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/dystopia-exchange/dystopia', query: DYSTOPIA_QUERY, }); diff --git a/src/apps/enzyme-finance/ethereum/enzyme-finance.vault.token-fetcher.ts b/src/apps/enzyme-finance/ethereum/enzyme-finance.vault.token-fetcher.ts index b44b96477..e878ff64a 100644 --- a/src/apps/enzyme-finance/ethereum/enzyme-finance.vault.token-fetcher.ts +++ b/src/apps/enzyme-finance/ethereum/enzyme-finance.vault.token-fetcher.ts @@ -3,6 +3,7 @@ import { gql } from 'graphql-request'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { DefaultAppTokenDataProps, @@ -41,7 +42,7 @@ export class EthereumEnzymeFinanceVaultTokenFetcher extends AppTokenTemplatePosi async getAddresses(): Promise { const endpoint = `https://api.thegraph.com/subgraphs/name/enzymefinance/enzyme`; - const data = await this.appToolkit.helpers.theGraphHelper.request({ endpoint, query }); + const data = await gqlFetch({ endpoint, query }); return data.funds.map(v => v.id.toLowerCase()); } diff --git a/src/apps/ethereum-staking/ethereum/ethereum-staking.deposit.contract-position-fetcher.ts b/src/apps/ethereum-staking/ethereum/ethereum-staking.deposit.contract-position-fetcher.ts index 4d00d58ee..a865fe630 100644 --- a/src/apps/ethereum-staking/ethereum/ethereum-staking.deposit.contract-position-fetcher.ts +++ b/src/apps/ethereum-staking/ethereum/ethereum-staking.deposit.contract-position-fetcher.ts @@ -6,6 +6,7 @@ import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetchAll } from '~app-toolkit/helpers/the-graph.helper'; import { MetaType } from '~position/position.interface'; import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; import { @@ -68,7 +69,7 @@ export class EthereumEthereumStakingDepositContractPositionFetcher extends Contr } async getTokenBalancesPerPosition({ address }: GetTokenBalancesParams) { - const data = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const data = await gqlFetchAll({ endpoint: GQL_ENDPOINT, query: ETH2_DEPOSITS_QUERY, dataToSearch: 'deposits', diff --git a/src/apps/euler/common/euler.e-token.token-fetcher.ts b/src/apps/euler/common/euler.e-token.token-fetcher.ts index e707107c0..d9d1e1953 100644 --- a/src/apps/euler/common/euler.e-token.token-fetcher.ts +++ b/src/apps/euler/common/euler.e-token.token-fetcher.ts @@ -2,8 +2,8 @@ import { Inject } from '@nestjs/common'; import { ethers } from 'ethers'; import _ from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { AppTokenPositionBalance, RawTokenBalance } from '~position/position-balance.interface'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { diff --git a/src/apps/euler/common/euler.token-definition-resolver.ts b/src/apps/euler/common/euler.token-definition-resolver.ts index a248377e6..9c8836189 100644 --- a/src/apps/euler/common/euler.token-definition-resolver.ts +++ b/src/apps/euler/common/euler.token-definition-resolver.ts @@ -4,6 +4,7 @@ import _ from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; export type EulerTokenDefinition = { address: string; @@ -63,7 +64,7 @@ export class EulerTokenDefinitionsResolver { constructor(@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit) {} private async getTokenDefinitionsData() { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: `https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet`, query: MARKET_QUERY, }); diff --git a/src/apps/goldfinch/ethereum/goldfinch.senior-bond.contract-position-fetcher.ts b/src/apps/goldfinch/ethereum/goldfinch.senior-bond.contract-position-fetcher.ts index ce37c4e91..20ab70c68 100644 --- a/src/apps/goldfinch/ethereum/goldfinch.senior-bond.contract-position-fetcher.ts +++ b/src/apps/goldfinch/ethereum/goldfinch.senior-bond.contract-position-fetcher.ts @@ -2,9 +2,9 @@ import { Inject } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { compact, range, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType, Standard } from '~position/position.interface'; diff --git a/src/apps/goldfinch/ethereum/goldfinch.vault.contract-position-fetcher.ts b/src/apps/goldfinch/ethereum/goldfinch.vault.contract-position-fetcher.ts index 0342e723f..8b932c5da 100644 --- a/src/apps/goldfinch/ethereum/goldfinch.vault.contract-position-fetcher.ts +++ b/src/apps/goldfinch/ethereum/goldfinch.vault.contract-position-fetcher.ts @@ -2,9 +2,9 @@ import { Inject } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType, Standard } from '~position/position.interface'; diff --git a/src/apps/good-ghosting/common/good-ghosting.game.contract-position-fetcher.ts b/src/apps/good-ghosting/common/good-ghosting.game.contract-position-fetcher.ts index 6046afb3f..0fd3b4a92 100644 --- a/src/apps/good-ghosting/common/good-ghosting.game.contract-position-fetcher.ts +++ b/src/apps/good-ghosting/common/good-ghosting.game.contract-position-fetcher.ts @@ -2,8 +2,8 @@ import { Inject, Injectable } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { compact, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; diff --git a/src/apps/hakuswap/avalanche/hakuswap.farm.contract-position-fetcher.ts b/src/apps/hakuswap/avalanche/hakuswap.farm.contract-position-fetcher.ts index 94afa9466..a5928231d 100644 --- a/src/apps/hakuswap/avalanche/hakuswap.farm.contract-position-fetcher.ts +++ b/src/apps/hakuswap/avalanche/hakuswap.farm.contract-position-fetcher.ts @@ -3,11 +3,11 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { HakuswapContractFactory, HakuswapMasterchef } from '../contracts'; diff --git a/src/apps/homora-v2/common/homora-v2.farm.contract-position-fetcher.ts b/src/apps/homora-v2/common/homora-v2.farm.contract-position-fetcher.ts index e4ad064e4..7e51ab314 100644 --- a/src/apps/homora-v2/common/homora-v2.farm.contract-position-fetcher.ts +++ b/src/apps/homora-v2/common/homora-v2.farm.contract-position-fetcher.ts @@ -1,9 +1,9 @@ import { Inject, NotImplementedException } from '@nestjs/common'; import { compact, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { Cache } from '~cache/cache.decorator'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; diff --git a/src/apps/keeper/common/keeper.job.contract-position-fetcher.ts b/src/apps/keeper/common/keeper.job.contract-position-fetcher.ts index fe8f9910d..0a0b32cfe 100644 --- a/src/apps/keeper/common/keeper.job.contract-position-fetcher.ts +++ b/src/apps/keeper/common/keeper.job.contract-position-fetcher.ts @@ -5,11 +5,16 @@ import { compact, find, merge, sumBy } from 'lodash'; import moment from 'moment'; import 'moment-duration-format'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; +import { gqlFetchAll } from '~app-toolkit/helpers/the-graph.helper'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; -import { GetTokenDefinitionsParams, GetDataPropsParams, GetDisplayPropsParams } from '~position/template/contract-position.template.types'; +import { + GetTokenDefinitionsParams, + GetDataPropsParams, + GetDisplayPropsParams, +} from '~position/template/contract-position.template.types'; import { CustomContractPositionTemplatePositionFetcher } from '~position/template/custom-contract-position.template.position-fetcher'; import { NETWORK_IDS } from '~types'; @@ -23,7 +28,7 @@ type KeeperJobRegistryApiResponse = { chainID: number; address: string; name: string; -}[] +}[]; type KeeperJobDefinition = { address: string; @@ -81,7 +86,7 @@ export abstract class KeeperJobContractPositionFetcher extends CustomContractPos } async getDefinitions() { - const jobData = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const jobData = await gqlFetchAll({ endpoint: SUBGRAPH_URL, query: GET_JOBS, variables: {}, @@ -112,19 +117,15 @@ export abstract class KeeperJobContractPositionFetcher extends CustomContractPos async getLabel({ definition, - }: GetDisplayPropsParams< - KeeperJobManager, - KeeperJobDataProps, - KeeperJobDefinition - >): Promise { - const data = await Axios.get(KEEP3R_JOB_NAME_API).then( - (v) => Object.values(v.data).map(job => ({ ...job, address: job.address.toLowerCase() })) + }: GetDisplayPropsParams): Promise { + const data = await Axios.get(KEEP3R_JOB_NAME_API).then(v => + Object.values(v.data).map(job => ({ ...job, address: job.address.toLowerCase() })), ); const filteredData = data.filter(job => job.chainID === NETWORK_IDS[this.network]); const foundJob = find(filteredData, { address: definition.address.toLowerCase() }); - return foundJob && `${foundJob.name} Keep3r Job` || 'Keep3r Job'; + return (foundJob && `${foundJob.name} Keep3r Job`) || 'Keep3r Job'; } async getDataProps({ @@ -153,13 +154,13 @@ export abstract class KeeperJobContractPositionFetcher extends CustomContractPos groupIds: [this.groupId], }); - const data = await Axios.get(KEEP3R_JOB_NAME_API).then( - (v) => Object.values(v.data).map(job => ({ ...job, address: job.address.toLowerCase() })) + const data = await Axios.get(KEEP3R_JOB_NAME_API).then(v => + Object.values(v.data).map(job => ({ ...job, address: job.address.toLowerCase() })), ); const filteredData = data.filter(job => job.chainID === NETWORK_IDS[this.network]); - const userJobsData = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const userJobsData = await gqlFetchAll({ endpoint: SUBGRAPH_URL, query: GET_USER_JOBS, variables: { address }, @@ -183,7 +184,7 @@ export abstract class KeeperJobContractPositionFetcher extends CustomContractPos // Display Properties const foundJob = find(filteredData, { address: userJob.id.toLowerCase() }); - const label = foundJob && `${foundJob.name} Keep3r Job` || 'Keep3r Job'; + const label = (foundJob && `${foundJob.name} Keep3r Job`) || 'Keep3r Job'; const secondaryLabel = ''; const displayProps = { label, secondaryLabel }; diff --git a/src/apps/keeper/common/keeper.keeper-bond.contract-position-fetcher.ts b/src/apps/keeper/common/keeper.keeper-bond.contract-position-fetcher.ts index f0394a590..8d0632dae 100644 --- a/src/apps/keeper/common/keeper.keeper-bond.contract-position-fetcher.ts +++ b/src/apps/keeper/common/keeper.keeper-bond.contract-position-fetcher.ts @@ -2,9 +2,10 @@ import { Inject } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { compact, find, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetchAll } from '~app-toolkit/helpers/the-graph.helper'; import { ContractType } from '~position/contract.interface'; import { DefaultDataProps, WithMetaType } from '~position/display.interface'; import { @@ -53,7 +54,7 @@ export abstract class KeeperBondContractPositionFetcher extends CustomContractPo } async getDefinitions() { - const bondData = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const bondData = await gqlFetchAll({ endpoint: SUBGRAPH_URL, query: GET_BONDS, variables: {}, @@ -84,7 +85,7 @@ export abstract class KeeperBondContractPositionFetcher extends CustomContractPo groupIds: [this.groupId], }); - const userBondsData = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const userBondsData = await gqlFetchAll({ endpoint: SUBGRAPH_URL, query: GET_USER_BONDS, variables: { address }, diff --git a/src/apps/keeper/common/keeper.keeper-unbond.contract-position-fetcher.ts b/src/apps/keeper/common/keeper.keeper-unbond.contract-position-fetcher.ts index da9728e59..244503e67 100644 --- a/src/apps/keeper/common/keeper.keeper-unbond.contract-position-fetcher.ts +++ b/src/apps/keeper/common/keeper.keeper-unbond.contract-position-fetcher.ts @@ -3,9 +3,10 @@ import { BigNumberish } from 'ethers'; import { compact, find, sumBy } from 'lodash'; import moment from 'moment'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetchAll } from '~app-toolkit/helpers/the-graph.helper'; import { ContractType } from '~position/contract.interface'; import { DefaultDataProps, WithMetaType } from '~position/display.interface'; import { @@ -55,7 +56,7 @@ export abstract class KeeperUnbondContractPositionFetcher extends CustomContract } async getDefinitions() { - const unbondData = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const unbondData = await gqlFetchAll({ endpoint: SUBGRAPH_URL, query: GET_UNBONDS, variables: {}, @@ -90,7 +91,7 @@ export abstract class KeeperUnbondContractPositionFetcher extends CustomContract groupIds: [this.groupId], }); - const userUnbondsData = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const userUnbondsData = await gqlFetchAll({ endpoint: SUBGRAPH_URL, query: GET_USER_UNBONDS, variables: { address }, diff --git a/src/apps/kwenta/common/kwenta.perp.contract-position-fetcher.ts b/src/apps/kwenta/common/kwenta.perp.contract-position-fetcher.ts index d3d4dbc03..76abec71c 100644 --- a/src/apps/kwenta/common/kwenta.perp.contract-position-fetcher.ts +++ b/src/apps/kwenta/common/kwenta.perp.contract-position-fetcher.ts @@ -4,6 +4,7 @@ import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { getAppAssetImage } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { SYNTHETIX_DEFINITION } from '~apps/synthetix/synthetix.definition'; import { MetaType } from '~position/position.interface'; import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; @@ -42,7 +43,7 @@ export abstract class OptimismKwentaPerpContractPositionFetcher extends Contract } async getDefinitions(): Promise { - const contractsFromSubgraph = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const contractsFromSubgraph = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/kwenta/optimism-main', query: getContractsQuery, }); diff --git a/src/apps/kwenta/optimism/kwenta.cross.contract-position-fetcher.ts b/src/apps/kwenta/optimism/kwenta.cross.contract-position-fetcher.ts index aff238c55..04599df63 100644 --- a/src/apps/kwenta/optimism/kwenta.cross.contract-position-fetcher.ts +++ b/src/apps/kwenta/optimism/kwenta.cross.contract-position-fetcher.ts @@ -2,6 +2,7 @@ import { gql } from 'graphql-request'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { OptimismKwentaPerpContractPositionFetcher } from '../common/kwenta.perp.contract-position-fetcher'; @@ -24,12 +25,11 @@ export class OptimismKwentaCrossContractPositionFetcher extends OptimismKwentaPe groupLabel = 'Cross Margin'; async getAccountAddress(address: string): Promise { - const crossMarginAccountsFromSubgraph = - await this.appToolkit.helpers.theGraphHelper.requestGraph({ - endpoint: 'https://api.thegraph.com/subgraphs/name/kwenta/optimism-main', - query: getCrossMarginAccountsQuery, - variables: { address: address }, - }); + const crossMarginAccountsFromSubgraph = await gqlFetch({ + endpoint: 'https://api.thegraph.com/subgraphs/name/kwenta/optimism-main', + query: getCrossMarginAccountsQuery, + variables: { address: address }, + }); if (crossMarginAccountsFromSubgraph.crossMarginAccounts.length === 0) { return ZERO_ADDRESS; diff --git a/src/apps/kyberswap-elastic/common/kyberswap-elastic.apy.data-loader.ts b/src/apps/kyberswap-elastic/common/kyberswap-elastic.apy.data-loader.ts index 29f848258..5293bb829 100644 --- a/src/apps/kyberswap-elastic/common/kyberswap-elastic.apy.data-loader.ts +++ b/src/apps/kyberswap-elastic/common/kyberswap-elastic.apy.data-loader.ts @@ -4,6 +4,7 @@ import { gql } from 'graphql-request'; import _ from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { getTimeDayAgo } from './kyberswap-elastic.liquidity.utils'; import { GET_BLOCKS, POOLS_FEE_HISTORY } from './kyberswap-elastic.pool.subgraph.types'; @@ -46,7 +47,7 @@ export class KyberswapElasticApyDataLoader { const dataLoaderOptions = { cache: true, maxBatchSize: 1000 }; return new DataLoader(async (addresses: string[]) => { // Get block from 24h ago - const response = await this.appToolkit.helpers.theGraphHelper.request({ + const response = await gqlFetch({ query: GET_BLOCKS([getTimeDayAgo()]), endpoint: blockSubgraphUrl, }); @@ -54,7 +55,7 @@ export class KyberswapElasticApyDataLoader { const blockNumberOneDayAgo = Number(response.blocks[0].number); // Get pool stats - const poolStatsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const poolStatsResponse = await gqlFetch({ endpoint: subgraphUrl, query: GET_POOL_INFOS, variables: { @@ -68,7 +69,7 @@ export class KyberswapElasticApyDataLoader { .value(); // Get fees - const poolsFeeResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const poolsFeeResponse = await gqlFetch({ endpoint: subgraphUrl, query: POOLS_FEE_HISTORY, variables: { block: blockNumberOneDayAgo }, diff --git a/src/apps/kyberswap-elastic/common/kyberswap-elastic.farm.contract-position-builder.ts b/src/apps/kyberswap-elastic/common/kyberswap-elastic.farm.contract-position-builder.ts index 9f70481ab..a2b5c4355 100644 --- a/src/apps/kyberswap-elastic/common/kyberswap-elastic.farm.contract-position-builder.ts +++ b/src/apps/kyberswap-elastic/common/kyberswap-elastic.farm.contract-position-builder.ts @@ -3,8 +3,8 @@ import BigNumber from 'bignumber.js'; import { BigNumberish } from 'ethers'; import { sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { IMulticallWrapper } from '~multicall'; diff --git a/src/apps/kyberswap-elastic/common/kyberswap-elastic.liquidity.contract-position-builder.ts b/src/apps/kyberswap-elastic/common/kyberswap-elastic.liquidity.contract-position-builder.ts index de4e0bbb8..4c0916a93 100644 --- a/src/apps/kyberswap-elastic/common/kyberswap-elastic.liquidity.contract-position-builder.ts +++ b/src/apps/kyberswap-elastic/common/kyberswap-elastic.liquidity.contract-position-builder.ts @@ -3,8 +3,8 @@ import BigNumber from 'bignumber.js'; import { BigNumberish } from 'ethers'; import { sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { IMulticallWrapper } from '~multicall'; diff --git a/src/apps/kyberswap-elastic/common/kyberswap-elastic.liquidity.contract-position-fetcher.ts b/src/apps/kyberswap-elastic/common/kyberswap-elastic.liquidity.contract-position-fetcher.ts index a6f7ea18d..d96ebbde6 100644 --- a/src/apps/kyberswap-elastic/common/kyberswap-elastic.liquidity.contract-position-fetcher.ts +++ b/src/apps/kyberswap-elastic/common/kyberswap-elastic.liquidity.contract-position-fetcher.ts @@ -4,6 +4,7 @@ import { compact, range } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType, Standard } from '~position/position.interface'; import { @@ -86,7 +87,7 @@ export abstract class KyberswapElasticLiquidityContractPositionFetcher extends C blockSubgraphUrl: this.blockSubgraphUrl, }); - const data = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: this.subgraphUrl, query: GET_TOP_POOLS_QUERY, }); diff --git a/src/apps/llama-airforce/ethereum/llama-airforce.merkle-cache.ts b/src/apps/llama-airforce/ethereum/llama-airforce.merkle-cache.ts index 1277190b7..3542adb3d 100644 --- a/src/apps/llama-airforce/ethereum/llama-airforce.merkle-cache.ts +++ b/src/apps/llama-airforce/ethereum/llama-airforce.merkle-cache.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import Axios from 'axios'; -import { MerkleCache } from '~app-toolkit/helpers/merkle/merkle.cache'; +import { MerkleCache } from '~position/template/merkle.cache'; import { Network } from '~types/network.interface'; import { LLAMA_AIRFORCE_DEFINITION } from '../llama-airforce.definition'; diff --git a/src/apps/llamapay/common/llamapay.stream.api-client.ts b/src/apps/llamapay/common/llamapay.stream.api-client.ts index 85b020217..37993b03c 100644 --- a/src/apps/llamapay/common/llamapay.stream.api-client.ts +++ b/src/apps/llamapay/common/llamapay.stream.api-client.ts @@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Network } from '~types/network.interface'; export const getTokensQuery = gql` @@ -112,7 +113,7 @@ export class LlamapayStreamApiClient { constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} async getTokens() { - const tokensResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const tokensResponse = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/nemusonaneko/llamapay-mainnet', query: getTokensQuery, }); @@ -124,7 +125,7 @@ export class LlamapayStreamApiClient { } async getStreams(address: string, _network: Network) { - const streamsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const streamsResponse = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/nemusonaneko/llamapay-mainnet', query: getStreamsQuery, variables: { id: address, network: _network }, @@ -134,13 +135,11 @@ export class LlamapayStreamApiClient { } async getVestingEscrows(address: string, _network: Network) { - const vestingEscrowsResponse = await this.appToolkit.helpers.theGraphHelper.request( - { - endpoint: 'https://api.thegraph.com/subgraphs/name/nemusonaneko/llamapay-vesting-mainnet', - query: getVestingEscrowsQuery, - variables: { id: address, network: _network }, - }, - ); + const vestingEscrowsResponse = await gqlFetch({ + endpoint: 'https://api.thegraph.com/subgraphs/name/nemusonaneko/llamapay-vesting-mainnet', + query: getVestingEscrowsQuery, + variables: { id: address, network: _network }, + }); return vestingEscrowsResponse.vestingEscrows ?? []; } diff --git a/src/apps/llamapay/ethereum/llamapay.stream.contract-position-fetcher.ts b/src/apps/llamapay/ethereum/llamapay.stream.contract-position-fetcher.ts index ba7a592bf..99a5a1a86 100644 --- a/src/apps/llamapay/ethereum/llamapay.stream.contract-position-fetcher.ts +++ b/src/apps/llamapay/ethereum/llamapay.stream.contract-position-fetcher.ts @@ -1,9 +1,9 @@ import { Inject, NotImplementedException } from '@nestjs/common'; import { compact } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getImagesFromToken, getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { isMulticallUnderlyingError } from '~multicall/multicall.ethers'; diff --git a/src/apps/llamapay/ethereum/llamapay.vesting-escrow.contract-position-fetcher.ts b/src/apps/llamapay/ethereum/llamapay.vesting-escrow.contract-position-fetcher.ts index 935c8e6ec..bf7f47a6e 100644 --- a/src/apps/llamapay/ethereum/llamapay.vesting-escrow.contract-position-fetcher.ts +++ b/src/apps/llamapay/ethereum/llamapay.vesting-escrow.contract-position-fetcher.ts @@ -1,9 +1,9 @@ import { Inject, NotImplementedException } from '@nestjs/common'; import { compact, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getImagesFromToken, getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { ContractType } from '~position/contract.interface'; diff --git a/src/apps/lyra-avalon/optimism/lyra-avalon.options.contract-position-fetcher.ts b/src/apps/lyra-avalon/optimism/lyra-avalon.options.contract-position-fetcher.ts index 6c6585984..a313e5fb6 100644 --- a/src/apps/lyra-avalon/optimism/lyra-avalon.options.contract-position-fetcher.ts +++ b/src/apps/lyra-avalon/optimism/lyra-avalon.options.contract-position-fetcher.ts @@ -5,6 +5,7 @@ import _, { flattenDeep, omit } from 'lodash'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DefaultDataProps } from '~position/display.interface'; import { MetaType } from '~position/position.interface'; import { ContractPositionTemplatePositionFetcher } from '~position/template/contract-position.template.position-fetcher'; @@ -127,7 +128,7 @@ export class OptimismLyraAvalonOptionsContractPositionFetcher extends ContractPo } async getDefinitions(): Promise { - const response = await this.appToolkit.helpers.theGraphHelper.request({ + const response = await gqlFetch({ endpoint: 'https://api.lyra.finance/subgraph/optimism/v1/api', query: OPTIONS_QUERY, }); diff --git a/src/apps/lyra-avalon/optimism/lyra-avalon.pool.token-fetcher.ts b/src/apps/lyra-avalon/optimism/lyra-avalon.pool.token-fetcher.ts index 6456cd8c5..378585233 100644 --- a/src/apps/lyra-avalon/optimism/lyra-avalon.pool.token-fetcher.ts +++ b/src/apps/lyra-avalon/optimism/lyra-avalon.pool.token-fetcher.ts @@ -4,6 +4,7 @@ import { gql } from 'graphql-request'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { DefaultAppTokenDefinition, @@ -73,7 +74,7 @@ export class OptimismLyraAvalonPoolTokenFetcher extends AppTokenTemplatePosition network: this.network, }); - const marketsResponse = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const marketsResponse = await gqlFetch({ endpoint: 'https://api.lyra.finance/subgraph/optimism/v1/api', query: QUERY, }); diff --git a/src/apps/maker/ethereum/maker.vault.contract-position-fetcher.ts b/src/apps/maker/ethereum/maker.vault.contract-position-fetcher.ts index f4c2c193f..81455f9c2 100644 --- a/src/apps/maker/ethereum/maker.vault.contract-position-fetcher.ts +++ b/src/apps/maker/ethereum/maker.vault.contract-position-fetcher.ts @@ -3,10 +3,10 @@ import BigNumber from 'bignumber.js'; import { ethers } from 'ethers'; import { compact, range, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { ContractType } from '~position/contract.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; diff --git a/src/apps/mean-finance/common/mean-finance.dca-position.contract-position-fetcher.ts b/src/apps/mean-finance/common/mean-finance.dca-position.contract-position-fetcher.ts index cdd085fde..14563133a 100644 --- a/src/apps/mean-finance/common/mean-finance.dca-position.contract-position-fetcher.ts +++ b/src/apps/mean-finance/common/mean-finance.dca-position.contract-position-fetcher.ts @@ -4,10 +4,11 @@ import { compact, merge, reduce, sumBy, uniqBy } from 'lodash'; import moment from 'moment'; import 'moment-duration-format'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { ETH_ADDR_ALIAS, ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetchAll } from '~app-toolkit/helpers/the-graph.helper'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType, Standard } from '~position/position.interface'; import { @@ -64,7 +65,7 @@ export abstract class MeanFinanceDcaPositionContractPositionFetcher extends Cust async getDefinitions() { const allPositions = await Promise.all( this.hubs.map(async ({ tokenAddress, hubAddress, subgraphUrl }) => { - const positionData = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const positionData = await gqlFetchAll({ endpoint: subgraphUrl, query: GET_POSITIONS, variables: {}, @@ -145,7 +146,7 @@ export abstract class MeanFinanceDcaPositionContractPositionFetcher extends Cust const allUserPositions = await Promise.all( this.hubs.map(async ({ transformerAddress, subgraphUrl }) => { - const userPositionsData = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const userPositionsData = await gqlFetchAll({ endpoint: subgraphUrl, query: GET_USER_POSITIONS, variables: { address }, diff --git a/src/apps/mux/common/mux.mlp.token-fetcher.ts b/src/apps/mux/common/mux.mlp.token-fetcher.ts index 1695564cf..3f3de2979 100644 --- a/src/apps/mux/common/mux.mlp.token-fetcher.ts +++ b/src/apps/mux/common/mux.mlp.token-fetcher.ts @@ -6,6 +6,7 @@ import { compact } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Erc20 } from '~contract/contracts'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { @@ -76,7 +77,7 @@ export abstract class MuxMlpTokenFetcher extends AppTokenTemplatePositionFetcher async getUnderlyingTokenDefinitions({ tokenLoader, }: GetUnderlyingTokensParams): Promise { - const response = await this.appToolkit.helpers.theGraphHelper.request({ + const response = await gqlFetch({ endpoint: this.subgraphUrl, query: ASSETS_TOKENS_QUERY, }); diff --git a/src/apps/naos/common/naos.farm.contract-position-fetcher.ts b/src/apps/naos/common/naos.farm.contract-position-fetcher.ts index 827599cba..2bb18fec3 100644 --- a/src/apps/naos/common/naos.farm.contract-position-fetcher.ts +++ b/src/apps/naos/common/naos.farm.contract-position-fetcher.ts @@ -2,11 +2,11 @@ import { Inject } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { NaosContractFactory, NaosStakingPools } from '../contracts'; diff --git a/src/apps/openleverage/common/openleverage.pool.token-fetcher.ts b/src/apps/openleverage/common/openleverage.pool.token-fetcher.ts index 9a7e2c14f..41ac994b5 100644 --- a/src/apps/openleverage/common/openleverage.pool.token-fetcher.ts +++ b/src/apps/openleverage/common/openleverage.pool.token-fetcher.ts @@ -3,6 +3,7 @@ import { gql } from 'graphql-request'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { GetUnderlyingTokensParams, @@ -42,7 +43,7 @@ export abstract class OpenleveragePoolTokenFetcher extends AppTokenTemplatePosit } async getAddresses() { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: this.subgraphUrl, query, }); diff --git a/src/apps/pendle-v2/ethereum/pendle-v2.pool.token-fetcher.ts b/src/apps/pendle-v2/ethereum/pendle-v2.pool.token-fetcher.ts index 257dadf56..bb5b64071 100644 --- a/src/apps/pendle-v2/ethereum/pendle-v2.pool.token-fetcher.ts +++ b/src/apps/pendle-v2/ethereum/pendle-v2.pool.token-fetcher.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DollarDisplayItem, PercentageDisplayItem } from '~position/display.interface'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { @@ -72,7 +73,7 @@ export class EthereumPendleV2PoolTokenFetcher extends AppTokenTemplatePositionFe } async getDefinitions(): Promise { - const marketsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const marketsResponse = await gqlFetch({ endpoint: PENDLE_V2_GRAPHQL_ENDPOINT, query: BACKEND_QUERIES.getMarkets, variables: { chainId: NETWORK_IDS[this.network] }, diff --git a/src/apps/pendle-v2/ethereum/pendle-v2.principal.token-fetcher.ts b/src/apps/pendle-v2/ethereum/pendle-v2.principal.token-fetcher.ts index ac1c47c59..a94226b51 100644 --- a/src/apps/pendle-v2/ethereum/pendle-v2.principal.token-fetcher.ts +++ b/src/apps/pendle-v2/ethereum/pendle-v2.principal.token-fetcher.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DollarDisplayItem, PercentageDisplayItem } from '~position/display.interface'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { @@ -47,7 +48,7 @@ export class EthereumPendleV2PrincipalTokenFetcher extends AppTokenTemplatePosit } async getDefinitions(_params: GetDefinitionsParams): Promise { - const marketsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const marketsResponse = await gqlFetch({ endpoint: PENDLE_V2_GRAPHQL_ENDPOINT, query: BACKEND_QUERIES.getMarkets, variables: { chainId: NETWORK_IDS[this.network] }, diff --git a/src/apps/pendle-v2/ethereum/pendle-v2.standardized-yield.token-fetcher.ts b/src/apps/pendle-v2/ethereum/pendle-v2.standardized-yield.token-fetcher.ts index 923ae39fb..96e629a1a 100644 --- a/src/apps/pendle-v2/ethereum/pendle-v2.standardized-yield.token-fetcher.ts +++ b/src/apps/pendle-v2/ethereum/pendle-v2.standardized-yield.token-fetcher.ts @@ -2,6 +2,7 @@ import { Inject } from '@nestjs/common'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { DefaultAppTokenDataProps, @@ -48,7 +49,7 @@ export class EthereumPendleV2StandardizedYieldTokenFetcher extends AppTokenTempl } async getDefinitions(_params: GetDefinitionsParams): Promise { - const marketsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const marketsResponse = await gqlFetch({ endpoint: PENDLE_V2_GRAPHQL_ENDPOINT, query: BACKEND_QUERIES.getMarkets, variables: { chainId: NETWORK_IDS[this.network] }, diff --git a/src/apps/pendle-v2/ethereum/pendle-v2.yield.token-fetcher.ts b/src/apps/pendle-v2/ethereum/pendle-v2.yield.token-fetcher.ts index 648f447df..e0ceaf4d0 100644 --- a/src/apps/pendle-v2/ethereum/pendle-v2.yield.token-fetcher.ts +++ b/src/apps/pendle-v2/ethereum/pendle-v2.yield.token-fetcher.ts @@ -3,6 +3,7 @@ import moment from 'moment'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DollarDisplayItem, PercentageDisplayItem } from '~position/display.interface'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { @@ -50,7 +51,7 @@ export class EthereumPendleV2YieldTokenFetcher extends AppTokenTemplatePositionF } async getDefinitions(_params: GetDefinitionsParams): Promise { - const marketsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const marketsResponse = await gqlFetch({ endpoint: PENDLE_V2_GRAPHQL_ENDPOINT, query: BACKEND_QUERIES.getMarkets, variables: { chainId: NETWORK_IDS[this.network] }, diff --git a/src/apps/penguin/avalanche/penguin.chef-v1-farm.contract-position-fetcher.ts b/src/apps/penguin/avalanche/penguin.chef-v1-farm.contract-position-fetcher.ts index 2044d1ca0..bb248ba56 100644 --- a/src/apps/penguin/avalanche/penguin.chef-v1-farm.contract-position-fetcher.ts +++ b/src/apps/penguin/avalanche/penguin.chef-v1-farm.contract-position-fetcher.ts @@ -3,11 +3,11 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { PenguinChef, PenguinContractFactory } from '../contracts'; diff --git a/src/apps/penguin/avalanche/penguin.chef-v2-farm.contract-position-fetcher.ts b/src/apps/penguin/avalanche/penguin.chef-v2-farm.contract-position-fetcher.ts index db8b88fb9..44cffec02 100644 --- a/src/apps/penguin/avalanche/penguin.chef-v2-farm.contract-position-fetcher.ts +++ b/src/apps/penguin/avalanche/penguin.chef-v2-farm.contract-position-fetcher.ts @@ -4,7 +4,6 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefV2ExtraRewardTokenBalancesParams, GetMasterChefV2ExtraRewardTokenRewardRates, @@ -13,6 +12,7 @@ import { import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { PenguinChefV2, PenguinContractFactory, PenguinExtraRewarder } from '../contracts'; diff --git a/src/apps/pickle/arbitrum/pickle.masterchef-v2-farm.contract-position-fetcher.ts b/src/apps/pickle/arbitrum/pickle.masterchef-v2-farm.contract-position-fetcher.ts index 4565eae9c..b9483c6cb 100644 --- a/src/apps/pickle/arbitrum/pickle.masterchef-v2-farm.contract-position-fetcher.ts +++ b/src/apps/pickle/arbitrum/pickle.masterchef-v2-farm.contract-position-fetcher.ts @@ -4,7 +4,6 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefV2ExtraRewardTokenBalancesParams, GetMasterChefV2ExtraRewardTokenRewardRates, @@ -13,6 +12,7 @@ import { import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { PickleContractFactory, PickleMiniChefV2, PickleRewarder } from '../contracts'; diff --git a/src/apps/pickle/ethereum/pickle.masterchef-farm.contract-position-fetcher.ts b/src/apps/pickle/ethereum/pickle.masterchef-farm.contract-position-fetcher.ts index 7ca6aecf9..4a24e6f27 100644 --- a/src/apps/pickle/ethereum/pickle.masterchef-farm.contract-position-fetcher.ts +++ b/src/apps/pickle/ethereum/pickle.masterchef-farm.contract-position-fetcher.ts @@ -3,11 +3,11 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { PickleContractFactory, PickleJarMasterchef } from '../contracts'; diff --git a/src/apps/pickle/optimism/pickle.masterchef-v2-farm.contract-position-fetcher.ts b/src/apps/pickle/optimism/pickle.masterchef-v2-farm.contract-position-fetcher.ts index acba9b045..ca2085649 100644 --- a/src/apps/pickle/optimism/pickle.masterchef-v2-farm.contract-position-fetcher.ts +++ b/src/apps/pickle/optimism/pickle.masterchef-v2-farm.contract-position-fetcher.ts @@ -4,7 +4,6 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefV2ExtraRewardTokenBalancesParams, GetMasterChefV2ExtraRewardTokenRewardRates, @@ -13,6 +12,7 @@ import { import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { PickleContractFactory, PickleMiniChefV2, PickleRewarder } from '../contracts'; diff --git a/src/apps/pickle/polygon/pickle.masterchef-v2-farm.contract-position-fetcher.ts b/src/apps/pickle/polygon/pickle.masterchef-v2-farm.contract-position-fetcher.ts index e8500dea5..c81b13b9d 100644 --- a/src/apps/pickle/polygon/pickle.masterchef-v2-farm.contract-position-fetcher.ts +++ b/src/apps/pickle/polygon/pickle.masterchef-v2-farm.contract-position-fetcher.ts @@ -4,7 +4,6 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefV2ExtraRewardTokenBalancesParams, GetMasterChefV2ExtraRewardTokenRewardRates, @@ -13,6 +12,7 @@ import { import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { PickleContractFactory, PickleMiniChefV2, PickleRewarder } from '../contracts'; diff --git a/src/apps/polygon-staking/ethereum/polygon-staking.deposit.contract-position-fetcher.ts b/src/apps/polygon-staking/ethereum/polygon-staking.deposit.contract-position-fetcher.ts index f3050ee5e..41b93d48a 100644 --- a/src/apps/polygon-staking/ethereum/polygon-staking.deposit.contract-position-fetcher.ts +++ b/src/apps/polygon-staking/ethereum/polygon-staking.deposit.contract-position-fetcher.ts @@ -3,10 +3,11 @@ import axios from 'axios'; import { gql } from 'graphql-request'; import { compact, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getImagesFromToken, getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetchAll } from '~app-toolkit/helpers/the-graph.helper'; import { CacheOnInterval } from '~cache/cache-on-interval.decorator'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; @@ -166,7 +167,7 @@ export class EthereumPolygonStakingContractPositionFetcher extends CustomContrac async getBalances(address: string): Promise[]> { const multicall = this.appToolkit.getMulticall(this.network); - const data = await this.appToolkit.helpers.theGraphHelper.gqlFetchAll({ + const data = await gqlFetchAll({ endpoint: GQL_ENDPOINT, query: DELEGATED_MATIC_QUERY, dataToSearch: 'delegators', diff --git a/src/apps/qi-dao/common/qi-dao.vault.contract-position-fetcher.ts b/src/apps/qi-dao/common/qi-dao.vault.contract-position-fetcher.ts index 3c791a24c..6e9a6c8fc 100644 --- a/src/apps/qi-dao/common/qi-dao.vault.contract-position-fetcher.ts +++ b/src/apps/qi-dao/common/qi-dao.vault.contract-position-fetcher.ts @@ -1,9 +1,9 @@ import { Inject, Injectable, NotImplementedException } from '@nestjs/common'; import { range, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { isMulticallUnderlyingError } from '~multicall/multicall.ethers'; import { ContractPositionBalance } from '~position/position-balance.interface'; diff --git a/src/apps/rari-fuse/common/rari-fuse.borrow.contract-position-fetcher.ts b/src/apps/rari-fuse/common/rari-fuse.borrow.contract-position-fetcher.ts index d11220daa..8b8c8ada1 100644 --- a/src/apps/rari-fuse/common/rari-fuse.borrow.contract-position-fetcher.ts +++ b/src/apps/rari-fuse/common/rari-fuse.borrow.contract-position-fetcher.ts @@ -1,8 +1,8 @@ import { BigNumber, BigNumberish, Contract } from 'ethers'; import { sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { BLOCKS_PER_DAY } from '~app-toolkit/constants/blocks'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { isMulticallUnderlyingError } from '~multicall/multicall.ethers'; import { ContractPositionBalance } from '~position/position-balance.interface'; diff --git a/src/apps/ren/common/ren.api.client.ts b/src/apps/ren/common/ren.api.client.ts index 00192c3fd..04f67d229 100644 --- a/src/apps/ren/common/ren.api.client.ts +++ b/src/apps/ren/common/ren.api.client.ts @@ -1,6 +1,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Cache } from '~cache/cache.decorator'; import { REN_DEFINITION } from '../ren.definition'; @@ -17,7 +18,7 @@ export class RenApiClient { ttl: 5 * 60, // 5 minutes }) async getDarknodeAssets() { - const data = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/renproject/renvm', query: GET_ASSETS_QUERY, }); @@ -31,7 +32,7 @@ export class RenApiClient { ttl: 5 * 60, // 5 minutes }) async getDarknodeBalance(address: string) { - const data = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/renproject/renvm', query: GET_DARKNODES_QUERY, variables: { diff --git a/src/apps/ren/ethereum/ren.darknode.contract-position-fetcher.ts b/src/apps/ren/ethereum/ren.darknode.contract-position-fetcher.ts index 55db15681..de77fb6ab 100644 --- a/src/apps/ren/ethereum/ren.darknode.contract-position-fetcher.ts +++ b/src/apps/ren/ethereum/ren.darknode.contract-position-fetcher.ts @@ -2,10 +2,10 @@ import { Inject } from '@nestjs/common'; import BigNumber from 'bignumber.js'; import { compact, groupBy, sumBy, values } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; import { isClaimable, isSupplied } from '~position/position.utils'; diff --git a/src/apps/revert-finance/common/revert-finance.compoundor-rewards.contract-position-fetcher.ts b/src/apps/revert-finance/common/revert-finance.compoundor-rewards.contract-position-fetcher.ts index c34a3bd9a..7326a3e5f 100644 --- a/src/apps/revert-finance/common/revert-finance.compoundor-rewards.contract-position-fetcher.ts +++ b/src/apps/revert-finance/common/revert-finance.compoundor-rewards.contract-position-fetcher.ts @@ -2,8 +2,8 @@ import { Inject } from '@nestjs/common'; import { BigNumberish } from 'ethers'; import { compact, merge, range, sumBy, uniqBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { UniswapV3LiquidityContractPositionBuilder } from '~apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-builder'; import { DefaultDataProps } from '~position/display.interface'; diff --git a/src/apps/rhino-fi/ethereum/rhino-fi.deposit.contract-position-fetcher.ts b/src/apps/rhino-fi/ethereum/rhino-fi.deposit.contract-position-fetcher.ts index b19c87eb3..59a5d4417 100644 --- a/src/apps/rhino-fi/ethereum/rhino-fi.deposit.contract-position-fetcher.ts +++ b/src/apps/rhino-fi/ethereum/rhino-fi.deposit.contract-position-fetcher.ts @@ -5,7 +5,7 @@ import { compact, sumBy } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { drillBalance } from '~app-toolkit/helpers/balance/token-balance.helper'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; diff --git a/src/apps/rubicon/common/rubicon.bath.token-definition-resolver.ts b/src/apps/rubicon/common/rubicon.bath.token-definition-resolver.ts index 4a0cf4d95..e1e24d05a 100644 --- a/src/apps/rubicon/common/rubicon.bath.token-definition-resolver.ts +++ b/src/apps/rubicon/common/rubicon.bath.token-definition-resolver.ts @@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Cache } from '~cache/cache.decorator'; export type RubiconPoolFetcherResponse = { @@ -29,7 +30,7 @@ export class RubiconBathTokenDefinitionResolver { ttl: 5 * 60, // 5 minutes }) private async getPoolDefinitionsData() { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: `https://api.thegraph.com/subgraphs/name/denverbaumgartner/bathtokenoptimism`, query: POOL_QUERY, }); diff --git a/src/apps/sablier/common/sablier.stream.api-client.ts b/src/apps/sablier/common/sablier.stream.api-client.ts index 312b4362d..c36d708ea 100644 --- a/src/apps/sablier/common/sablier.stream.api-client.ts +++ b/src/apps/sablier/common/sablier.stream.api-client.ts @@ -3,6 +3,7 @@ import { gql } from 'graphql-request'; import _ from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Network } from '~types/network.interface'; export const getTokensQuery = gql` @@ -60,7 +61,7 @@ export class SablierStreamApiClient { constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {} async getTokens() { - const tokensResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const tokensResponse = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/sablierhq/sablier', query: getTokensQuery, }); @@ -69,7 +70,7 @@ export class SablierStreamApiClient { } async getStreams(address: string, _network: Network) { - const streamsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const streamsResponse = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/sablierhq/sablier', query: getStreamsQuery, variables: { address: address }, @@ -82,7 +83,7 @@ export class SablierStreamApiClient { } async getLegacyStreams(address: string, _network: Network) { - const streamsResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const streamsResponse = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/sablierhq/sablier', query: getStreamsQuery, variables: { address: address }, @@ -91,7 +92,7 @@ export class SablierStreamApiClient { const allStreams = [...streamsResponse.senderStreams, ...streamsResponse.recipientStreams]; const legacyStreamIds = _.uniq(allStreams.map(v => v.id).filter(v => Number(v) < 100_000)); - const salariesResponse = await this.appToolkit.helpers.theGraphHelper.request({ + const salariesResponse = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/sablierhq/sablier', query: getStreamsToSalariesQuery, variables: { streamIds: legacyStreamIds }, diff --git a/src/apps/sablier/ethereum/sablier.stream-legacy.contract-position-fetcher.ts b/src/apps/sablier/ethereum/sablier.stream-legacy.contract-position-fetcher.ts index 65ac9ba13..55c485f49 100644 --- a/src/apps/sablier/ethereum/sablier.stream-legacy.contract-position-fetcher.ts +++ b/src/apps/sablier/ethereum/sablier.stream-legacy.contract-position-fetcher.ts @@ -1,9 +1,9 @@ import { Inject, NotImplementedException } from '@nestjs/common'; import { compact } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getImagesFromToken, getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { isMulticallUnderlyingError } from '~multicall/multicall.ethers'; diff --git a/src/apps/sablier/ethereum/sablier.stream.contract-position-fetcher.ts b/src/apps/sablier/ethereum/sablier.stream.contract-position-fetcher.ts index 41d113595..41f22e110 100644 --- a/src/apps/sablier/ethereum/sablier.stream.contract-position-fetcher.ts +++ b/src/apps/sablier/ethereum/sablier.stream.contract-position-fetcher.ts @@ -1,9 +1,9 @@ import { Inject, NotImplementedException } from '@nestjs/common'; import { compact } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getImagesFromToken, getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { isMulticallUnderlyingError } from '~multicall/multicall.ethers'; diff --git a/src/apps/spool/ethereum/spool.staking.contract-position-fetcher.ts b/src/apps/spool/ethereum/spool.staking.contract-position-fetcher.ts index 57aca4335..650e54136 100644 --- a/src/apps/spool/ethereum/spool.staking.contract-position-fetcher.ts +++ b/src/apps/spool/ethereum/spool.staking.contract-position-fetcher.ts @@ -7,6 +7,7 @@ import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; import { buildDollarDisplayItem, buildNumberDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { SpoolContractFactory } from '~apps/spool'; import { REWARDS_QUERY, @@ -58,7 +59,7 @@ export class EthereumSpoolStakingContractPositionFetcher extends ContractPositio async getTokenDefinitions() { const now = parseInt(String(new Date().getTime() / 1000)); - const stakingRewards = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const stakingRewards = await gqlFetch({ endpoint: SUBGRAPH_API_BASE_URL, query: REWARDS_QUERY, }); @@ -115,7 +116,6 @@ export class EthereumSpoolStakingContractPositionFetcher extends ContractPositio contractPosition, multicall, }: GetTokenBalancesParams) { - const graphHelper = this.appToolkit.helpers.theGraphHelper; const suppliedToken = contractPosition.tokens.find(isSupplied)!; const rewardTokens = contractPosition.tokens.filter(isClaimable); @@ -128,7 +128,7 @@ export class EthereumSpoolStakingContractPositionFetcher extends ContractPositio ...rewardTokens.map(reward => multicall.wrap(staking).earned(reward.address, address)), ]); - const stakedSpool = await graphHelper.requestGraph({ + const stakedSpool = await gqlFetch({ endpoint: SUBGRAPH_API_BASE_URL, query: SPOOL_STAKED_QUERY, variables: { address }, diff --git a/src/apps/spool/ethereum/spool.vault.contract-position-fetcher.ts b/src/apps/spool/ethereum/spool.vault.contract-position-fetcher.ts index 7e66828d8..6e0b16720 100644 --- a/src/apps/spool/ethereum/spool.vault.contract-position-fetcher.ts +++ b/src/apps/spool/ethereum/spool.vault.contract-position-fetcher.ts @@ -12,6 +12,7 @@ import { buildStringDisplayItem, } from '~app-toolkit/helpers/presentation/display-item.present'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { SpoolContractFactory } from '~apps/spool'; import { ANALYTICS_API_BASE_URL, SUBGRAPH_API_BASE_URL } from '~apps/spool/ethereum/spool.constants'; import { WithMetaType } from '~position/display.interface'; @@ -141,13 +142,13 @@ export class EthereumSpoolVaultContractPositionFetcher extends ContractPositionT async getDefinitions() { // Request all vaults - const vaultsData = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const vaultsData = await gqlFetch({ endpoint: SUBGRAPH_API_BASE_URL, query: vaultsQuery, }); // Request platform fees - const platformFees = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const platformFees = await gqlFetch({ endpoint: SUBGRAPH_API_BASE_URL, query: platformQuery, }); diff --git a/src/apps/stake-dao/ethereum/stake-dao.farm.contract-position-fetcher.ts b/src/apps/stake-dao/ethereum/stake-dao.farm.contract-position-fetcher.ts index 65d7a2315..52f9f8f46 100644 --- a/src/apps/stake-dao/ethereum/stake-dao.farm.contract-position-fetcher.ts +++ b/src/apps/stake-dao/ethereum/stake-dao.farm.contract-position-fetcher.ts @@ -3,11 +3,11 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { StakeDaoContractFactory, StakeDaoFarm } from '../contracts'; diff --git a/src/apps/superfluid/polygon/superfluid.vault.token-fetcher.ts b/src/apps/superfluid/polygon/superfluid.vault.token-fetcher.ts index f268221c4..09ae8be85 100644 --- a/src/apps/superfluid/polygon/superfluid.vault.token-fetcher.ts +++ b/src/apps/superfluid/polygon/superfluid.vault.token-fetcher.ts @@ -3,6 +3,7 @@ import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { GetUnderlyingTokensParams } from '~position/template/app-token.template.types'; @@ -50,7 +51,7 @@ export class PolygonSuperfluidVaultTokenFetcher extends AppTokenTemplatePosition async getAddresses(): Promise { const subgraphUrl = 'https://api.thegraph.com/subgraphs/name/superfluid-finance/superfluid-matic'; - const tokenData = await this.appToolkit.helpers.theGraphHelper.request({ + const tokenData = await gqlFetch({ endpoint: subgraphUrl, query: ALL_TOKENS_QUERY, }); diff --git a/src/apps/sushiswap-bentobox/common/sushiswap-bentobox.vault-tokens-resolver.ts b/src/apps/sushiswap-bentobox/common/sushiswap-bentobox.vault-tokens-resolver.ts index 1dd764e44..b08029ba1 100644 --- a/src/apps/sushiswap-bentobox/common/sushiswap-bentobox.vault-tokens-resolver.ts +++ b/src/apps/sushiswap-bentobox/common/sushiswap-bentobox.vault-tokens-resolver.ts @@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Cache } from '~cache/cache.decorator'; import { Network } from '~types/network.interface'; @@ -42,7 +43,7 @@ export class SushiswapBentoboxVaultTokensResolver { ttl: 5 * 60, // 5 minutes }) private async getVaultTokensData(subgraphUrl: string, _network: Network) { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: subgraphUrl, query: ALL_TOKENS_QUERY, }); diff --git a/src/apps/sushiswap-kashi/common/sushiswap-kashi.lending.token-fetcher.ts b/src/apps/sushiswap-kashi/common/sushiswap-kashi.lending.token-fetcher.ts index 120741ef6..855067493 100644 --- a/src/apps/sushiswap-kashi/common/sushiswap-kashi.lending.token-fetcher.ts +++ b/src/apps/sushiswap-kashi/common/sushiswap-kashi.lending.token-fetcher.ts @@ -4,6 +4,7 @@ import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { buildPercentageDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { StatsItem } from '~position/display.interface'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { @@ -81,7 +82,7 @@ export abstract class SushiswapKashiLendingTokenFetcher extends AppTokenTemplate } async getDefinitions(): Promise { - const pairsData = await this.appToolkit.helpers.theGraphHelper.request({ + const pairsData = await gqlFetch({ endpoint: this.subgraphUrl, query: kashiSubgraphPairsQuery, variables: { first: 500 }, diff --git a/src/apps/symphony/common/symphony.yolo.contract-position-fetcher.ts b/src/apps/symphony/common/symphony.yolo.contract-position-fetcher.ts index 31d1a65d3..8b3897d4f 100644 --- a/src/apps/symphony/common/symphony.yolo.contract-position-fetcher.ts +++ b/src/apps/symphony/common/symphony.yolo.contract-position-fetcher.ts @@ -5,9 +5,10 @@ import { BigNumberish } from 'ethers'; import { gql } from 'graphql-request'; import { sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; @@ -86,7 +87,7 @@ export abstract class SymphonyYoloContractPositionFetcher extends CustomContract network: this.network, }); - const openOrdersData = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const openOrdersData = await gqlFetch({ endpoint: this.subgraphUrl, query: USER_OPEN_ORDERS_QUERY, variables: { creator: address }, diff --git a/src/apps/synthetix/common/synthetix.loan.contract-position-fetcher.ts b/src/apps/synthetix/common/synthetix.loan.contract-position-fetcher.ts index c6da9c52f..4d31b78de 100644 --- a/src/apps/synthetix/common/synthetix.loan.contract-position-fetcher.ts +++ b/src/apps/synthetix/common/synthetix.loan.contract-position-fetcher.ts @@ -6,6 +6,7 @@ import { gql } from 'graphql-request'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DefaultDataProps } from '~position/display.interface'; import { MetaType } from '~position/position.interface'; import { isSupplied } from '~position/position.utils'; @@ -87,7 +88,7 @@ export abstract class SynthetixLoanContractPositionFetcher extends ContractPosit address, contractPosition, }: GetTokenBalancesParams): Promise { - const loansFromSubgraph = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const loansFromSubgraph = await gqlFetch({ endpoint: this.subgraphUrl, query: getLoanQuery, variables: { address: address }, diff --git a/src/apps/synthetix/common/synthetix.mintr.snx-holders.cache.ts b/src/apps/synthetix/common/synthetix.mintr.snx-holders.cache.ts index ac119ef14..5d678aea3 100644 --- a/src/apps/synthetix/common/synthetix.mintr.snx-holders.cache.ts +++ b/src/apps/synthetix/common/synthetix.mintr.snx-holders.cache.ts @@ -3,6 +3,7 @@ import { gql } from 'graphql-request'; import moment from 'moment'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Cache } from '~cache/cache.decorator'; import { Network } from '~types/network.interface'; @@ -58,11 +59,7 @@ export class SynthetixMintrSnxHoldersCache { let lastId = ''; do { - lastResult = await this.appToolkit.helpers.theGraphHelper.request({ - endpoint, - query: HOLDERS_QUERY, - variables: { lastId }, - }); + lastResult = await gqlFetch({ endpoint, query: HOLDERS_QUERY, variables: { lastId } }); lastId = lastResult.snxholders[lastResult.snxholders.length - 1].id; lastResult.snxholders.forEach(v => holders.set(v.id, v)); } while (lastResult.snxholders.length === 1000); diff --git a/src/apps/tenderize/common/tenderize.token-definition-resolver.ts b/src/apps/tenderize/common/tenderize.token-definition-resolver.ts index 581200788..97c6b79f5 100644 --- a/src/apps/tenderize/common/tenderize.token-definition-resolver.ts +++ b/src/apps/tenderize/common/tenderize.token-definition-resolver.ts @@ -3,6 +3,7 @@ import Axios from 'axios'; import { gql } from 'graphql-request'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Cache } from '~cache/cache.decorator'; import { Network } from '~types/network.interface'; @@ -47,7 +48,7 @@ export class TenderizeTokenDefinitionsResolver { ttl: 5 * 60, // 5 minutes }) private async getVaultDefinitionsData(network: Network) { - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: `https://api.thegraph.com/subgraphs/name/tenderize/tenderize-${network}`, query: TOKEN_QUERY, }); diff --git a/src/apps/trisolaris/aurora/trisolaris.farm.contract-position-fetcher.ts b/src/apps/trisolaris/aurora/trisolaris.farm.contract-position-fetcher.ts index 4a8da84b2..31949aa8c 100644 --- a/src/apps/trisolaris/aurora/trisolaris.farm.contract-position-fetcher.ts +++ b/src/apps/trisolaris/aurora/trisolaris.farm.contract-position-fetcher.ts @@ -3,7 +3,6 @@ import { Inject } from '@nestjs/common'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefV2ExtraRewardTokenBalancesParams, GetMasterChefV2ExtraRewardTokenRewardRates, @@ -12,6 +11,7 @@ import { import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { TrisolarisMasterChef, TrisolarisRewarder, TrisolarisContractFactory } from '../contracts'; diff --git a/src/apps/unipilot/common/unipilot-vault.apy.helper.ts b/src/apps/unipilot/common/unipilot-vault.apy.helper.ts index d0d8110f3..a88da9739 100644 --- a/src/apps/unipilot/common/unipilot-vault.apy.helper.ts +++ b/src/apps/unipilot/common/unipilot-vault.apy.helper.ts @@ -3,6 +3,7 @@ import { Inject, Injectable } from '@nestjs/common'; import Axios from 'axios'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { CacheOnInterval } from '~cache/cache-on-interval.decorator'; import { Network } from '~types'; @@ -23,12 +24,12 @@ export class UnipilotVaultAPYHelper { failOnMissingData: false, }) async getApy() { - const ethData = await this.appToolkit.helpers.theGraphHelper.request({ + const ethData = await gqlFetch({ endpoint: SUBGRAPH_ENDPOINTS[Network.ETHEREUM_MAINNET].stats, query: VAULT_ADDRESSES, }); - const polygonData = await this.appToolkit.helpers.theGraphHelper.request({ + const polygonData = await gqlFetch({ endpoint: SUBGRAPH_ENDPOINTS[Network.POLYGON_MAINNET].stats, query: VAULT_ADDRESSES, }); diff --git a/src/apps/unipilot/common/unipilot.vault-definition-resolver.ts b/src/apps/unipilot/common/unipilot.vault-definition-resolver.ts index e9ed11cf6..934ccd1e3 100644 --- a/src/apps/unipilot/common/unipilot.vault-definition-resolver.ts +++ b/src/apps/unipilot/common/unipilot.vault-definition-resolver.ts @@ -1,6 +1,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { Cache } from '~cache/cache.decorator'; import { Network } from '~types/network.interface'; @@ -19,7 +20,7 @@ export class UnipilotVaultDefinitionsResolver { private async getVaultDefinitionsData(network: Network) { const Query = network === Network.ETHEREUM_MAINNET ? UNIPILOT_VAULTS : UNIPILOT_VAULTS_POLYGON; - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: SUBGRAPH_ENDPOINTS[network].stats, query: Query, variables: { diff --git a/src/apps/uniswap-v2/common/uniswap-v2.pool.subgraph.template.token-fetcher.ts b/src/apps/uniswap-v2/common/uniswap-v2.pool.subgraph.template.token-fetcher.ts index efd5d9fef..ccc6d0c2d 100644 --- a/src/apps/uniswap-v2/common/uniswap-v2.pool.subgraph.template.token-fetcher.ts +++ b/src/apps/uniswap-v2/common/uniswap-v2.pool.subgraph.template.token-fetcher.ts @@ -3,6 +3,7 @@ import { BigNumberish, Contract } from 'ethers'; import { difference, range, uniq } from 'lodash'; import { BLOCKS_PER_DAY } from '~app-toolkit/constants/blocks'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { GetDataPropsParams } from '~position/template/app-token.template.types'; import { @@ -51,7 +52,7 @@ export abstract class UniswapV2PoolSubgraphTemplateTokenFetcher< const chunks = await Promise.all( range(0, this.first, 1000).map(skip => { const count = Math.min(1000, this.first - skip); - return this.appToolkit.helpers.theGraphHelper.request({ + return gqlFetch({ endpoint: this.subgraphUrl, query: this.poolsQuery, variables: { first: count, skip, orderBy: this.orderBy }, @@ -60,7 +61,7 @@ export abstract class UniswapV2PoolSubgraphTemplateTokenFetcher< ); const poolsData = chunks.flat(); - const poolsByIdData = await this.appToolkit.helpers.theGraphHelper.request({ + const poolsByIdData = await gqlFetch({ endpoint: this.subgraphUrl, query: this.poolsByIdQuery, variables: { ids: this.requiredPools }, @@ -112,7 +113,7 @@ export abstract class UniswapV2PoolSubgraphTemplateTokenFetcher< // Get last block synced on graph; if the graph is not caught up to yesterday, exit early if (this.subgraphUrl.includes('api.fura.org')) { const subgraphName = this.subgraphUrl.substring(this.subgraphUrl.lastIndexOf('/') + 1); - const graphMetaData = await this.appToolkit.helpers.theGraphHelper.request({ + const graphMetaData = await gqlFetch({ endpoint: this.subgraphUrl, query: FURA_LAST_BLOCK_SYNCED_ON_GRAPH_QUERY, variables: { subgraphName }, @@ -120,7 +121,7 @@ export abstract class UniswapV2PoolSubgraphTemplateTokenFetcher< blockNumberLastSynced = graphMetaData.indexingStatusForCurrentVersion.chains[0].latestBlock.number; } else { - const graphMetaData = await this.appToolkit.helpers.theGraphHelper.request({ + const graphMetaData = await gqlFetch({ endpoint: this.subgraphUrl, query: this.lastBlockSyncedOnGraphQuery, }); @@ -132,12 +133,12 @@ export abstract class UniswapV2PoolSubgraphTemplateTokenFetcher< // Retrieve volume data from TheGraph (@TODO Cache this) const [volumeByIDData, volumeByIDData1DayAgo] = await Promise.all([ - this.appToolkit.helpers.theGraphHelper.request({ + gqlFetch({ endpoint: this.subgraphUrl, query: this.poolVolumesByIdQuery, variables: { ids: addresses }, }), - this.appToolkit.helpers.theGraphHelper.request({ + gqlFetch({ endpoint: this.subgraphUrl, query: this.poolVolumesByIdAtBlockQuery, variables: { ids: addresses, block: block1DayAgo }, diff --git a/src/apps/uniswap-v2/ethereum/uniswap-v2.pool.token-fetcher.ts b/src/apps/uniswap-v2/ethereum/uniswap-v2.pool.token-fetcher.ts index aa1b24009..2f5c8bbf7 100644 --- a/src/apps/uniswap-v2/ethereum/uniswap-v2.pool.token-fetcher.ts +++ b/src/apps/uniswap-v2/ethereum/uniswap-v2.pool.token-fetcher.ts @@ -1,9 +1,10 @@ import { gql } from 'graphql-request'; import { chunk, compact } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenPositionBalance, RawAppTokenBalance } from '~position/position-balance.interface'; import { isAppToken } from '~position/position.interface'; @@ -56,7 +57,7 @@ export class EthereumUniswapV2PoolTokenFetcher extends UniswapV2DefaultPoolSubgr if (address === ZERO_ADDRESS) return []; // Use the subgraph to determine holdings. Later, we'll optimize this to use our own holdings by default. - const data = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: this.subgraphUrl, query: UNISWAP_V2_BALANCES_QUERY, variables: { address: address.toLowerCase() }, @@ -84,7 +85,7 @@ export class EthereumUniswapV2PoolTokenFetcher extends UniswapV2DefaultPoolSubgr if (address === ZERO_ADDRESS) return []; // Use the subgraph to determine holdings. Later, we'll optimize this to use our own holdings by default. - const data = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: this.subgraphUrl, query: UNISWAP_V2_BALANCES_QUERY, variables: { address: address.toLowerCase() }, diff --git a/src/apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-builder.ts b/src/apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-builder.ts index 95a199332..5595ccf89 100644 --- a/src/apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-builder.ts +++ b/src/apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-builder.ts @@ -3,8 +3,8 @@ import BigNumber from 'bignumber.js'; import { BigNumberish } from 'ethers'; import { sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; import { getImagesFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { IMulticallWrapper } from '~multicall'; diff --git a/src/apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-fetcher.ts b/src/apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-fetcher.ts index 0dc70d390..45fdcf161 100644 --- a/src/apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-fetcher.ts +++ b/src/apps/uniswap-v3/common/uniswap-v3.liquidity.contract-position-fetcher.ts @@ -4,6 +4,7 @@ import { compact, range } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType, Standard } from '~position/position.interface'; import { @@ -87,7 +88,7 @@ export abstract class UniswapV3LiquidityContractPositionFetcher extends CustomCo } async getDefinitions(): Promise { - const data = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: this.subgraphUrl, query: GET_TOP_POOLS_QUERY, }); diff --git a/src/apps/vector-finance/avalanche/vector-finance.farm.contract-position-fetcher.ts b/src/apps/vector-finance/avalanche/vector-finance.farm.contract-position-fetcher.ts index 9acf4d7e7..beb645e2d 100644 --- a/src/apps/vector-finance/avalanche/vector-finance.farm.contract-position-fetcher.ts +++ b/src/apps/vector-finance/avalanche/vector-finance.farm.contract-position-fetcher.ts @@ -4,7 +4,6 @@ import { compact, range } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { IMulticallWrapper } from '~multicall'; import { isMulticallUnderlyingError } from '~multicall/multicall.ethers'; import { isClaimable, isSupplied } from '~position/position.utils'; @@ -19,6 +18,7 @@ import { GetMasterChefDataPropsParams, MasterChefContractPositionDataProps, MasterChefContractPositionDefinition, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { VectorFinanceContractFactory, VectorFinanceMasterChef, VectorFinanceMasterChefRewarder } from '../contracts'; diff --git a/src/apps/vendor-finance/arbitrum/vendor-finance.pool.contract-position-fetcher.ts b/src/apps/vendor-finance/arbitrum/vendor-finance.pool.contract-position-fetcher.ts index ee519d0fc..e2296d0fb 100644 --- a/src/apps/vendor-finance/arbitrum/vendor-finance.pool.contract-position-fetcher.ts +++ b/src/apps/vendor-finance/arbitrum/vendor-finance.pool.contract-position-fetcher.ts @@ -7,6 +7,7 @@ import { buildPercentageDisplayItem, } from '~app-toolkit/helpers/presentation/display-item.present'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DefaultDataProps } from '~position/display.interface'; import { MetaType } from '~position/position.interface'; import { isBorrowed } from '~position/position.utils'; @@ -57,7 +58,7 @@ export class ArbitrumVendorFinancePoolContractPositionFetcher extends ContractPo } async getDefinitions() { - const data = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: VENDOR_GRAPH_URL, query: lendingPoolsQuery, }); @@ -159,7 +160,7 @@ export class ArbitrumVendorFinancePoolContractPositionFetcher extends ContractPo // --! Lender logic !--- // --- Borrower logic ---- - const data = await this.appToolkit.helpers.theGraphHelper.requestGraph({ + const data = await gqlFetch({ endpoint: VENDOR_GRAPH_URL, query: borrowerInfosQuery(address), }); diff --git a/src/apps/votium/ethereum/votium.merkle-cache.ts b/src/apps/votium/ethereum/votium.merkle-cache.ts index b9323b3b8..821fcbe01 100644 --- a/src/apps/votium/ethereum/votium.merkle-cache.ts +++ b/src/apps/votium/ethereum/votium.merkle-cache.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import Axios from 'axios'; import { fromPairs } from 'lodash'; -import { MerkleCache } from '~app-toolkit/helpers/merkle/merkle.cache'; +import { MerkleCache } from '~position/template/merkle.cache'; import { Network } from '~types/network.interface'; import { VOTIUM_DEFINITION } from '../votium.definition'; diff --git a/src/apps/wolf-game/ethereum/wolf-game.wool-pouch.contract-position-fetcher.ts b/src/apps/wolf-game/ethereum/wolf-game.wool-pouch.contract-position-fetcher.ts index ea96780b6..50d3b3057 100644 --- a/src/apps/wolf-game/ethereum/wolf-game.wool-pouch.contract-position-fetcher.ts +++ b/src/apps/wolf-game/ethereum/wolf-game.wool-pouch.contract-position-fetcher.ts @@ -1,10 +1,11 @@ import { Inject } from '@nestjs/common'; import { gql } from 'graphql-request'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { AppToolkit } from '~app-toolkit/app-toolkit.service'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { DefaultDataProps } from '~position/display.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; @@ -70,7 +71,7 @@ export class EthereumWolfGameWoolPouchContractPositionFetcher extends CustomCont network: this.network, groupIds: [this.groupId], }); - const result = await this.appToolKit.helpers.theGraphHelper.request({ + const result = await gqlFetch({ endpoint: 'https://api.thegraph.com/subgraphs/name/wolfgamedev/wolf-game', query: pouchesQuery, variables: { owner: address }, diff --git a/src/apps/yield-protocol/common/yield-protocol.borrow.contract-position-fetcher.ts b/src/apps/yield-protocol/common/yield-protocol.borrow.contract-position-fetcher.ts index 4fe402961..e0658bde6 100644 --- a/src/apps/yield-protocol/common/yield-protocol.borrow.contract-position-fetcher.ts +++ b/src/apps/yield-protocol/common/yield-protocol.borrow.contract-position-fetcher.ts @@ -4,9 +4,10 @@ import { parseUnits } from 'ethers/lib/utils'; import { gql } from 'graphql-request'; import { compact, isEqual, sumBy, uniqWith } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { getImagesFromToken, getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { ContractType } from '~position/contract.interface'; import { ContractPositionBalance } from '~position/position-balance.interface'; import { MetaType } from '~position/position.interface'; @@ -161,12 +162,12 @@ export abstract class YieldProtocolBorrowContractPositionFetcher extends CustomC network: this.network, }); - const { assets: ilks } = await this.appToolkit.helpers.theGraphHelper.request({ + const { assets: ilks } = await gqlFetch({ endpoint: this.subgraphUrl, query: ilksQuery, }); - const { seriesEntities: artsRes } = await this.appToolkit.helpers.theGraphHelper.request({ + const { seriesEntities: artsRes } = await gqlFetch({ endpoint: this.subgraphUrl, query: artsQuery, }); @@ -240,7 +241,7 @@ export abstract class YieldProtocolBorrowContractPositionFetcher extends CustomC network: this.network, }); - const data = await this.appToolkit.helpers.theGraphHelper.request({ + const data = await gqlFetch({ endpoint: this.subgraphUrl, query: vaultsQuery, variables: { address }, diff --git a/src/apps/yield-protocol/common/yield-protocol.lend.token-fetcher.ts b/src/apps/yield-protocol/common/yield-protocol.lend.token-fetcher.ts index c2b53a73b..cf3b39a24 100644 --- a/src/apps/yield-protocol/common/yield-protocol.lend.token-fetcher.ts +++ b/src/apps/yield-protocol/common/yield-protocol.lend.token-fetcher.ts @@ -5,6 +5,7 @@ import moment from 'moment'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { gqlFetch } from '~app-toolkit/helpers/the-graph.helper'; import { AppTokenTemplatePositionFetcher } from '~position/template/app-token.template.position-fetcher'; import { GetDataPropsParams, @@ -103,7 +104,7 @@ export abstract class YieldProtocolLendTokenFetcher extends AppTokenTemplatePosi } async getDefinitions(): Promise { - const { pools, seriesEntities } = await this.appToolkit.helpers.theGraphHelper.request({ + const { pools, seriesEntities } = await gqlFetch({ endpoint: this.subgraphUrl, query, }); diff --git a/src/apps/yield-yak/avalanche/yield-yak.farm.contract-position-fetcher.ts b/src/apps/yield-yak/avalanche/yield-yak.farm.contract-position-fetcher.ts index 4d3a98636..37b52e278 100644 --- a/src/apps/yield-yak/avalanche/yield-yak.farm.contract-position-fetcher.ts +++ b/src/apps/yield-yak/avalanche/yield-yak.farm.contract-position-fetcher.ts @@ -4,11 +4,11 @@ import { BigNumberish } from 'ethers'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { GetMasterChefDataPropsParams, GetMasterChefTokenBalancesParams, MasterChefTemplateContractPositionFetcher, + RewardRateUnit, } from '~position/template/master-chef.template.contract-position-fetcher'; import { YieldYakChef, YieldYakContractFactory } from '../contracts'; diff --git a/src/balance/default.token-balance-fetcher.factory.ts b/src/balance/default.token-balance-fetcher.factory.ts index f8c9116e9..19b8c8afe 100644 --- a/src/balance/default.token-balance-fetcher.factory.ts +++ b/src/balance/default.token-balance-fetcher.factory.ts @@ -1,7 +1,7 @@ import { Inject, Injectable } from '@nestjs/common'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { ContractFactory } from '~contract'; import { NetworkProviderService } from '~network-provider/network-provider.service'; import { PositionBalanceFetcher } from '~position/position-balance-fetcher.interface'; diff --git a/src/index.ts b/src/index.ts index 1e3bf12e7..27ac2594f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,4 +2,3 @@ // really strange transpilation issue + nest dynamic imports. export { AppsModule } from './apps/apps.module'; export { IAppToolkit, APP_TOOLKIT } from './app-toolkit/app-toolkit.interface'; -export { AppToolkitHelperRegistry, AppToolkitHelpers } from './app-toolkit/app-toolkit.helpers'; diff --git a/src/position/template/app-token.template.position-fetcher.ts b/src/position/template/app-token.template.position-fetcher.ts index 972c0ee94..f29b9538c 100644 --- a/src/position/template/app-token.template.position-fetcher.ts +++ b/src/position/template/app-token.template.position-fetcher.ts @@ -2,9 +2,9 @@ import { Inject } from '@nestjs/common'; import { BigNumberish, Contract } from 'ethers/lib/ethers'; import _, { isEqual, isUndefined, uniqWith, compact, intersection, isArray, partition, sortBy, sum } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem, buildPercentageDisplayItem, diff --git a/src/position/template/contract-position.template.position-fetcher.ts b/src/position/template/contract-position.template.position-fetcher.ts index 79350aa26..855cf6fa2 100644 --- a/src/position/template/contract-position.template.position-fetcher.ts +++ b/src/position/template/contract-position.template.position-fetcher.ts @@ -2,9 +2,9 @@ import { Inject } from '@nestjs/common'; import { BigNumberish, Contract } from 'ethers/lib/ethers'; import _, { compact, sumBy } from 'lodash'; -import { drillBalance } from '~app-toolkit'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; import { buildDollarDisplayItem, buildPercentageDisplayItem, diff --git a/src/position/template/master-chef.template.contract-position-fetcher.ts b/src/position/template/master-chef.template.contract-position-fetcher.ts index d88b6b0f8..81823f0d9 100644 --- a/src/position/template/master-chef.template.contract-position-fetcher.ts +++ b/src/position/template/master-chef.template.contract-position-fetcher.ts @@ -5,7 +5,6 @@ import { isArray, range, sum } from 'lodash'; import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; import { ZERO_ADDRESS } from '~app-toolkit/constants/address'; import { BLOCKS_PER_DAY } from '~app-toolkit/constants/blocks'; -import { RewardRateUnit } from '~app-toolkit/helpers/master-chef/master-chef.contract-position-helper'; import { getImagesFromToken, getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; import { IMulticallWrapper } from '~multicall'; import { isMulticallUnderlyingError } from '~multicall/multicall.ethers'; @@ -21,6 +20,11 @@ import { GetDefinitionsParams, } from '~position/template/contract-position.template.types'; +export enum RewardRateUnit { + BLOCK = 'block', + SECOND = 'second', +} + export type MasterChefContractPositionDataProps = { poolIndex: number; liquidity: number; diff --git a/src/app-toolkit/helpers/merkle/merkle.cache.ts b/src/position/template/merkle.cache.ts similarity index 100% rename from src/app-toolkit/helpers/merkle/merkle.cache.ts rename to src/position/template/merkle.cache.ts