diff --git a/cache.ts b/cache.ts index 726fb4b..8807fa8 100644 --- a/cache.ts +++ b/cache.ts @@ -3,7 +3,8 @@ import { getRedisClient } from './redis-utils/get-client' import { RedisStore } from './store/redis-store' -import { currentTimestamp, CacheResponse } from './utils' +import type { CacheResponse } from './utils' +import { currentTimestamp } from './utils' interface Options { cacheSeconds: number diff --git a/scripts/aggregated/market-movement.ts b/scripts/aggregated/market-movement.ts index b35a755..ec6fe18 100644 --- a/scripts/aggregated/market-movement.ts +++ b/scripts/aggregated/market-movement.ts @@ -212,19 +212,20 @@ export async function getMarketMovement( const vaultGlp = fsGlp_balanceOf_juniorVault + fsGlp_balanceOf_batchingManager + // (poolAmount - reserveAmount) + (shortSize / averagePrice) const wethTokenWeight = - (wethPoolAmount - wethReservedAmounts) + (wethShortSizes / wethShortAveragePrice); + wethPoolAmount - wethReservedAmounts + wethShortSizes / wethShortAveragePrice const wbtcTokenWeight = - (wbtcPoolAmount - wbtcReservedAmounts) + (wbtcShortSizes / wbtcShortAveragePrice); + wbtcPoolAmount - wbtcReservedAmounts + wbtcShortSizes / wbtcShortAveragePrice const linkTokenWeight = linkPoolAmount const uniTokenWeight = uniPoolAmount - const wethCurrentToken = (wethTokenWeight * vaultGlp / totalGLPSupply) - const wbtcCurrentToken = (wbtcTokenWeight * vaultGlp / totalGLPSupply) - const linkCurrentToken = (linkTokenWeight * vaultGlp / totalGLPSupply) - const uniCurrentToken = (uniTokenWeight * vaultGlp / totalGLPSupply) + const wethCurrentToken = (wethTokenWeight * vaultGlp) / totalGLPSupply + const wbtcCurrentToken = (wbtcTokenWeight * vaultGlp) / totalGLPSupply + const linkCurrentToken = (linkTokenWeight * vaultGlp) / totalGLPSupply + const uniCurrentToken = (uniTokenWeight * vaultGlp) / totalGLPSupply return { blockNumber: blockNumber, diff --git a/scripts/aggregated/util/events/batching-manager/deposit-token.ts b/scripts/aggregated/util/events/batching-manager/deposit-token.ts index 546c83c..125b881 100644 --- a/scripts/aggregated/util/events/batching-manager/deposit-token.ts +++ b/scripts/aggregated/util/events/batching-manager/deposit-token.ts @@ -1,11 +1,10 @@ import type { NetworkName } from '@ragetrade/sdk' import { deltaNeutralGmxVaults, tokens } from '@ragetrade/sdk' - -import { ErrorWithStatusCode, getLogs } from '../../../../../utils' - import type { DepositTokenEvent } from '@ragetrade/sdk/dist/typechain/delta-neutral-gmx-vaults/contracts/vaults/DnGmxBatchingManager' import type { ethers } from 'ethers' +import { ErrorWithStatusCode, getLogs } from '../../../../../utils' + export async function depositToken( networkName: NetworkName, provider: ethers.providers.Provider, diff --git a/scripts/aggregated/util/events/gmx-vault/decreasePoolAmount.ts b/scripts/aggregated/util/events/gmx-vault/decreasePoolAmount.ts index 3f2e36f..0ff62b4 100644 --- a/scripts/aggregated/util/events/gmx-vault/decreasePoolAmount.ts +++ b/scripts/aggregated/util/events/gmx-vault/decreasePoolAmount.ts @@ -1,7 +1,6 @@ import type { NetworkName } from '@ragetrade/sdk' -import { ethers } from 'ethers' - import { gmxProtocol } from '@ragetrade/sdk' +import { ethers } from 'ethers' import { getLogs } from '../../../../../utils' import { GET_LOGS_INTERVAL, getStartBlock, oneInFiftyBlocks } from './common' diff --git a/scripts/aggregated/util/events/gmx-vault/increasePoolAmount.ts b/scripts/aggregated/util/events/gmx-vault/increasePoolAmount.ts index c81e762..9c82f14 100644 --- a/scripts/aggregated/util/events/gmx-vault/increasePoolAmount.ts +++ b/scripts/aggregated/util/events/gmx-vault/increasePoolAmount.ts @@ -1,7 +1,6 @@ import type { NetworkName } from '@ragetrade/sdk' -import { ethers } from 'ethers' - import { gmxProtocol } from '@ragetrade/sdk' +import { ethers } from 'ethers' import { getLogs } from '../../../../../utils' import { GET_LOGS_INTERVAL, getStartBlock, oneInFiftyBlocks } from './common' diff --git a/scripts/aggregated/util/events/junior-vault/deposit.ts b/scripts/aggregated/util/events/junior-vault/deposit.ts index 0b94339..777994c 100644 --- a/scripts/aggregated/util/events/junior-vault/deposit.ts +++ b/scripts/aggregated/util/events/junior-vault/deposit.ts @@ -1,11 +1,10 @@ import type { NetworkName } from '@ragetrade/sdk' import { deltaNeutralGmxVaults } from '@ragetrade/sdk' - -import { ErrorWithStatusCode, getLogs } from '../../../../../utils' - import type { DepositEvent } from '@ragetrade/sdk/dist/typechain/delta-neutral-gmx-vaults/contracts/vaults/DnGmxJuniorVault' import type { ethers } from 'ethers' +import { ErrorWithStatusCode, getLogs } from '../../../../../utils' + export async function deposit( networkName: NetworkName, provider: ethers.providers.Provider, diff --git a/scripts/aggregated/util/events/junior-vault/glp-swapped.ts b/scripts/aggregated/util/events/junior-vault/glp-swapped.ts index fc588f9..05277f4 100644 --- a/scripts/aggregated/util/events/junior-vault/glp-swapped.ts +++ b/scripts/aggregated/util/events/junior-vault/glp-swapped.ts @@ -1,11 +1,10 @@ import type { NetworkName } from '@ragetrade/sdk' import { deltaNeutralGmxVaults } from '@ragetrade/sdk' - -import { ErrorWithStatusCode, getLogs } from '../../../../../utils' - import type { GlpSwappedEvent } from '@ragetrade/sdk/dist/typechain/delta-neutral-gmx-vaults/contracts/vaults/DnGmxJuniorVault' import type { ethers } from 'ethers' +import { ErrorWithStatusCode, getLogs } from '../../../../../utils' + export async function glpSwapped( networkName: NetworkName, provider: ethers.providers.Provider, diff --git a/scripts/aggregated/util/events/junior-vault/rebalanced.ts b/scripts/aggregated/util/events/junior-vault/rebalanced.ts index 36b9efe..c4ce138 100644 --- a/scripts/aggregated/util/events/junior-vault/rebalanced.ts +++ b/scripts/aggregated/util/events/junior-vault/rebalanced.ts @@ -1,11 +1,10 @@ import type { NetworkName } from '@ragetrade/sdk' import { deltaNeutralGmxVaults } from '@ragetrade/sdk' - -import { ErrorWithStatusCode, getLogs } from '../../../../../utils' - import type { RebalancedEvent } from '@ragetrade/sdk/dist/typechain/delta-neutral-gmx-vaults/contracts/interfaces/IDnGmxJuniorVault' import type { ethers } from 'ethers' +import { ErrorWithStatusCode, getLogs } from '../../../../../utils' + export async function rebalanced( networkName: NetworkName, provider: ethers.providers.Provider, diff --git a/scripts/aggregated/util/events/junior-vault/rewards-harvested.ts b/scripts/aggregated/util/events/junior-vault/rewards-harvested.ts index a290a3e..e012d0f 100644 --- a/scripts/aggregated/util/events/junior-vault/rewards-harvested.ts +++ b/scripts/aggregated/util/events/junior-vault/rewards-harvested.ts @@ -1,11 +1,10 @@ import type { NetworkName } from '@ragetrade/sdk' import { deltaNeutralGmxVaults } from '@ragetrade/sdk' - -import { ErrorWithStatusCode, getLogs } from '../../../../../utils' - import type { RewardsHarvestedEvent } from '@ragetrade/sdk/dist/typechain/delta-neutral-gmx-vaults/contracts/vaults/DnGmxJuniorVault' import type { ethers } from 'ethers' +import { ErrorWithStatusCode, getLogs } from '../../../../../utils' + export async function rewardsHarvested( networkName: NetworkName, provider: ethers.providers.Provider, diff --git a/scripts/aggregated/util/events/junior-vault/withdraw.ts b/scripts/aggregated/util/events/junior-vault/withdraw.ts index fc5e659..d832be2 100644 --- a/scripts/aggregated/util/events/junior-vault/withdraw.ts +++ b/scripts/aggregated/util/events/junior-vault/withdraw.ts @@ -1,11 +1,10 @@ import type { NetworkName } from '@ragetrade/sdk' import { deltaNeutralGmxVaults } from '@ragetrade/sdk' - -import { ErrorWithStatusCode, getLogs } from '../../../../../utils' - import type { WithdrawEvent } from '@ragetrade/sdk/dist/typechain/delta-neutral-gmx-vaults/contracts/vaults/DnGmxJuniorVault' import type { ethers } from 'ethers' +import { ErrorWithStatusCode, getLogs } from '../../../../../utils' + export async function withdraw( networkName: NetworkName, provider: ethers.providers.Provider, diff --git a/scripts/aggregated/util/events/senior-vault/deposit.ts b/scripts/aggregated/util/events/senior-vault/deposit.ts index 3a98451..bf4a6f0 100644 --- a/scripts/aggregated/util/events/senior-vault/deposit.ts +++ b/scripts/aggregated/util/events/senior-vault/deposit.ts @@ -1,11 +1,10 @@ import type { NetworkName } from '@ragetrade/sdk' import { deltaNeutralGmxVaults } from '@ragetrade/sdk' - -import { ErrorWithStatusCode, getLogs } from '../../../../../utils' - import type { DepositEvent } from '@ragetrade/sdk/dist/typechain/delta-neutral-gmx-vaults/contracts/vaults/DnGmxSeniorVault' import type { ethers } from 'ethers' +import { ErrorWithStatusCode, getLogs } from '../../../../../utils' + export async function deposit( networkName: NetworkName, provider: ethers.providers.Provider, diff --git a/scripts/aggregated/util/events/senior-vault/withdraw.ts b/scripts/aggregated/util/events/senior-vault/withdraw.ts index 10ff836..20a8b6f 100644 --- a/scripts/aggregated/util/events/senior-vault/withdraw.ts +++ b/scripts/aggregated/util/events/senior-vault/withdraw.ts @@ -1,11 +1,10 @@ import type { NetworkName } from '@ragetrade/sdk' import { deltaNeutralGmxVaults } from '@ragetrade/sdk' - -import { ErrorWithStatusCode, getLogs } from '../../../../../utils' - import type { WithdrawEvent } from '@ragetrade/sdk/dist/typechain/delta-neutral-gmx-vaults/contracts/vaults/DnGmxSeniorVault' import type { ethers } from 'ethers' +import { ErrorWithStatusCode, getLogs } from '../../../../../utils' + export async function withdraw( networkName: NetworkName, provider: ethers.providers.Provider, diff --git a/scripts/runner/per-interval-3.ts b/scripts/runner/per-interval-3.ts index b49f010..bc4c9da 100644 --- a/scripts/runner/per-interval-3.ts +++ b/scripts/runner/per-interval-3.ts @@ -5,7 +5,6 @@ import { formatEther } from 'ethers/lib/utils' import { getProviderAggregate } from '../../providers' import { getLogs } from '../../utils' - import { parallelize } from '../aggregated/util/parallelize' perInterval('arbmain').then((v) => console.log(JSON.stringify(v))) diff --git a/scripts/runner/per-interval-6.ts b/scripts/runner/per-interval-6.ts index a1c05d0..90503a7 100644 --- a/scripts/runner/per-interval-6.ts +++ b/scripts/runner/per-interval-6.ts @@ -1,5 +1,5 @@ -import { deltaNeutralGmxVaults, NetworkName } from '@ragetrade/sdk' -import { gmxProtocol, tokens } from '@ragetrade/sdk' +import type { NetworkName } from '@ragetrade/sdk' +import { deltaNeutralGmxVaults, gmxProtocol, tokens } from '@ragetrade/sdk' import type { ethers } from 'ethers' import { BigNumber } from 'ethers' import { formatEther, formatUnits } from 'ethers/lib/utils' diff --git a/scripts/runner/per-interval.ts b/scripts/runner/per-interval.ts index ca1dc2e..2757f27 100644 --- a/scripts/runner/per-interval.ts +++ b/scripts/runner/per-interval.ts @@ -13,7 +13,6 @@ import { getProviderAggregate } from '../../providers' import { getLogs } from '../../utils' import { juniorVault } from '../aggregated/util/events' import { price } from '../aggregated/util/helpers' - import { parallelize } from '../aggregated/util/parallelize' // import { juniorVault } from "./aggregated/util/events"; // import { getLogsInLoop, price } from "./util/helpers"; diff --git a/scripts/v2/dn-gmx-vault-apy/borrow-rate.ts b/scripts/v2/dn-gmx-vault-apy/borrow-rate.ts index 19cbfe3..ca61c34 100644 --- a/scripts/v2/dn-gmx-vault-apy/borrow-rate.ts +++ b/scripts/v2/dn-gmx-vault-apy/borrow-rate.ts @@ -1,7 +1,7 @@ import 'isomorphic-unfetch' -import { aave, NetworkName } from '@ragetrade/sdk' -import { deltaNeutralGmxVaults, typechain } from '@ragetrade/sdk' +import type { NetworkName } from '@ragetrade/sdk' +import { aave, deltaNeutralGmxVaults, typechain } from '@ragetrade/sdk' import { formatUnits } from 'ethers/lib/utils' import { getProvider } from '../../../providers' diff --git a/scripts/v2/dn-gmx-vault-apy/trader-pnl.ts b/scripts/v2/dn-gmx-vault-apy/trader-pnl.ts index 31c661d..d7cd255 100644 --- a/scripts/v2/dn-gmx-vault-apy/trader-pnl.ts +++ b/scripts/v2/dn-gmx-vault-apy/trader-pnl.ts @@ -1,5 +1,6 @@ import 'isomorphic-unfetch' +import type { NetworkName } from '@ragetrade/sdk' import { fetchJson } from 'ethers/lib/utils' import type { @@ -8,7 +9,6 @@ import type { VaultInfoResult } from '../../aggregated' import { combineStatsData } from '../../aggregated/util/combineStatsData' -import { NetworkName } from '@ragetrade/sdk' export const getTraderPnl = async (networkName: NetworkName) => { const { result: glpPnl }: { result: GlobalGlpPnlResult } = await fetchJson({ @@ -44,12 +44,11 @@ export const getTraderPnl = async (networkName: NetworkName) => { } ) - const data = vaultInfo.data - .map((entry) => { - const foundDay = combined.find((d) => d.Day === entry.timestamp) + const data = vaultInfo.data.map((entry) => { + const foundDay = combined.find((d) => d.Day === entry.timestamp) - return (foundDay?.totalTraderPnL || 0) / entry.juniorVaultInfo.vaultMarketValue - }) + return (foundDay?.totalTraderPnL || 0) / entry.juniorVaultInfo.vaultMarketValue + }) const dataSum = data .filter((num) => !Number.isNaN(num) && Number.isFinite(num)) diff --git a/store/redis-store.ts b/store/redis-store.ts index e64f4ef..9782bc7 100644 --- a/store/redis-store.ts +++ b/store/redis-store.ts @@ -1,10 +1,9 @@ import Debugger from 'debug' +import type { Redis } from 'ioredis' import { isCacheExpired, isCacheResponse, years } from '../utils' import { BaseStore } from './base-store' -import type { Redis } from 'ioredis' - const debug = Debugger('apis:redis-store') export class RedisStore extends BaseStore { diff --git a/utils.ts b/utils.ts index e53c749..ac7dbbe 100644 --- a/utils.ts +++ b/utils.ts @@ -5,6 +5,10 @@ import { getNetworkName as getNetworkNameSdk, getVaultName as getVaultNameSdk } from '@ragetrade/sdk' +import type { + TypedEvent, + TypedEventFilter +} from '@ragetrade/sdk/dist/typechain/core/common' import type { BigNumber, EventFilter } from 'ethers' import { ethers } from 'ethers' import { fetchJson, getAddress, isAddress } from 'ethers/lib/utils' @@ -13,7 +17,6 @@ import type { Request } from 'express' import createError from 'http-errors' import { ENV } from './env' -import { TypedEvent, TypedEventFilter } from '@ragetrade/sdk/dist/typechain/core/common' export const secs = 1 export const mins = 60 @@ -295,7 +298,7 @@ export async function getLogs( _fetchedBlock = _toBlock // next getLogs query range - let newToBlock = Math.min( + const newToBlock = Math.min( toBlock, _toBlock + 2 * roundNumber(_toBlock - _fromBlock + 1) ) @@ -304,7 +307,7 @@ export async function getLogs( } catch (e: any) { if (typeof e?.message === 'string') { // if error message contains a block range, use that as the new toBlock - let [, fromBlockStr, toBlockStr] = e.message.match( + const [, fromBlockStr, toBlockStr] = e.message.match( /\[(0x[0-9a-fA-F]+), (0x[0-9a-fA-F]+)\]/ ) console.log('match', fromBlockStr, toBlockStr)