diff --git a/packages/constants/src/addresses.ts b/packages/constants/src/addresses.ts
index c65e609..4bf1e29 100644
--- a/packages/constants/src/addresses.ts
+++ b/packages/constants/src/addresses.ts
@@ -117,3 +117,10 @@ export const NFTX_FEE_DISTRIBUTOR = {
[Network.Sepolia]: a('0x66EF5B4b6ee05639194844CE4867515665F14fED'),
[Network.Arbitrum]: a('0x0d50970C7848ebbE52661e70057D7D063B7de886'),
};
+
+/** A list of old fee distributors that are no longer active (but useful for historical data) */
+export const NFTX_FEE_DISTRIBUTOR_LEGACY = {
+ [Network.Mainnet]: [a('0x6845fF5f102bEF9D785468F0bEb535b4687406E7')],
+ [Network.Sepolia]:
[],
+ [Network.Arbitrum]: [],
+};
diff --git a/packages/constants/src/subgraph.ts b/packages/constants/src/subgraph.ts
index f927060..d9b6a09 100644
--- a/packages/constants/src/subgraph.ts
+++ b/packages/constants/src/subgraph.ts
@@ -1,18 +1,7 @@
import { Network } from './networks';
-const SHARED_PATH = 'subgraphs/name';
-
-const SHARED_HOST = 'https://api.thegraph.com';
-const PROXY_HOST = 'https://graph-proxy.nftx.xyz';
-
-const SHARED_PROXY_NAME = 'shared';
-
-const SHARED_ROOT = `${SHARED_HOST}/${SHARED_PATH}`;
-
-const SHARED_PROXY_ROOT = `${PROXY_HOST}/${SHARED_PROXY_NAME}/${SHARED_PATH}`;
-
export const NON_STANDARD_SUBGRAPH = {
- [Network.Mainnet]: `${SHARED_PROXY_ROOT}/0xorg/non-standard-nfts`,
+ [Network.Mainnet]: `https://graph-proxy.nftx.xyz/shared/subgraphs/name/0xorg/non-standard-nfts`,
};
export const ERC721_SUBGRAPH = {
@@ -44,9 +33,9 @@ export const NFTX_SUBGRAPH = {
export const NFTX_UNISWAP_SUBGRAPH = {
[Network.Mainnet]:
- 'https://graph-proxy.nftx.xyz/nftx-indexer/subgraphs/id/QmTqJsUzqsmSzkvDeSGDmGYCcVu8v3Tr3j3MqNsTZvVCMm',
+ 'https://query.graph.nftx.xyz/subgraphs/id/QmXavb61qVUrfYe7daW47n77LhinFgSoMhWVkMfgEdUspS',
[Network.Sepolia]:
- 'https://api.thegraph.com/subgraphs/name/nftx-project/nftx-v3-amm-sepolia',
+ 'https://api.thegraph.com/subgraphs/name/gundamdweeb/nftx-univ3-sepolia',
[Network.Arbitrum]:
- 'https://api.thegraph.com/subgraphs/name/nftx-project/nftx-v3-amm-arbitrum',
+ 'https://query.graph.nftx.xyz/subgraphs/id/QmaTrSbtkkCeJW5fhbsm1BoEZm31zEE9HtCP5BEjfeGLMT',
};
diff --git a/packages/core/src/pools/fetchLiquidityPools/__tests__/calculateAprs.test.ts b/packages/core/src/pools/fetchLiquidityPools/__tests__/calculateAprs.test.ts
index 73320b3..ada5f67 100644
--- a/packages/core/src/pools/fetchLiquidityPools/__tests__/calculateAprs.test.ts
+++ b/packages/core/src/pools/fetchLiquidityPools/__tests__/calculateAprs.test.ts
@@ -25,20 +25,16 @@ beforeEach(() => {
createdAt = oneMonthAgo;
dailySnapshots = [
{
- dailyTotalRevenueETH: '0.01',
- inputTokenBalances: [
- parseEther('10').toString(),
- parseEther('5').toString(),
- ],
- timestamp: `${now - ONE_DAY * 2}`,
+ feesETH: '0.01',
+ totalValueLockedToken0: '10',
+ totalValueLockedToken1: '5',
+ date: now - ONE_DAY * 2,
},
{
- dailyTotalRevenueETH: '0.02',
- inputTokenBalances: [
- parseEther('10').toString(),
- parseEther('5').toString(),
- ],
- timestamp: `${now - ONE_DAY * 3}`,
+ feesETH: '0.02',
+ totalValueLockedToken0: '10',
+ totalValueLockedToken1: '5',
+ date: now - ONE_DAY * 3,
},
];
vaultFeeReceipts = [
diff --git a/packages/core/src/pools/fetchLiquidityPools/__tests__/fetchPoolSet.test.ts b/packages/core/src/pools/fetchLiquidityPools/__tests__/fetchPoolSet.test.ts
index 2a6ddf0..cf5e3f4 100644
--- a/packages/core/src/pools/fetchLiquidityPools/__tests__/fetchPoolSet.test.ts
+++ b/packages/core/src/pools/fetchLiquidityPools/__tests__/fetchPoolSet.test.ts
@@ -1,75 +1,90 @@
import { WETH_TOKEN, WeiPerEther } from '@nftx/constants';
import { makeFetchPoolsSet } from '../fetchPoolsSet';
import { getChainConstant } from '@nftx/utils';
+import { NftxV3Uniswap } from '@nftx/types';
import { formatEther } from 'viem';
-let poolData: any;
+let poolData: { pools: NftxV3Uniswap.Pool[] };
let queryPoolData: jest.Mock;
let fetchPoolsSet: ReturnType;
let args: Parameters[0];
let run: () => ReturnType;
beforeEach(() => {
+ const _pool = {} as NftxV3Uniswap.Pool;
+ const _token = {} as NftxV3Uniswap.Token;
+ const _poolHourData = {} as NftxV3Uniswap.PoolHourData;
+ const _poolDayData = {} as NftxV3Uniswap.PoolDayData;
+
poolData = {
- liquidityPools: [
+ pools: [
{
+ ..._pool,
id: '0x',
name: '0x',
- tick: 0,
+ tick: '0',
totalLiquidity: `${WeiPerEther * 3n}`,
- activeLiquidity: `${WeiPerEther * 2n}`,
- inputTokenBalances: [
- WeiPerEther.toString(),
- (WeiPerEther * 2n).toString(),
- ],
+ liquidity: `${WeiPerEther * 2n}`,
+ totalValueLockedToken0: '1',
+ totalValueLockedToken1: '2',
totalValueLockedETH: '0',
openPositionCount: 0,
- createdTimestamp: 0,
+ createdAtTimestamp: '0',
fees: [
{
id: '0x',
- feePercentage: 0,
- feeType: 'FIXED_LP_FEE',
+ feePercentage: '0',
+ feeType: 'FIXED_LP_FEE' as NftxV3Uniswap.PoolFeeType,
},
{
id: '0x',
- feePercentage: 0,
- feeType: 'FIXED_PROTOCOL_FEE',
+ feePercentage: '0',
+ feeType: 'FIXED_PROTOCOL_FEE' as NftxV3Uniswap.PoolFeeType,
},
{
id: '0x',
- feePercentage: 0.3,
- feeType: 'FIXED_TRADING_FEE',
+ feePercentage: '0.3',
+ feeType: 'FIXED_TRADING_FEE' as NftxV3Uniswap.PoolFeeType,
},
],
+ token0: { ..._token, id: '0x', symbol: '0x', name: '0x' },
+ token1: {
+ ..._token,
+ id: getChainConstant(WETH_TOKEN, 1),
+ symbol: 'WETH',
+ name: 'Wrapped Ether',
+ },
inputTokens: [
+ { ..._token, id: '0x', symbol: '0x', name: '0x' },
{
- id: '0x',
- symbol: '0x',
- name: '0x',
- },
- {
+ ..._token,
id: getChainConstant(WETH_TOKEN, 1),
symbol: 'WETH',
name: 'Wrapped Ether',
},
],
- hourlySnapshots: [
+ poolHourData: [
{
- hourlyVolumeByTokenAmount: ['0', '0'],
- hourlyTotalRevenueETH: '0',
+ ..._poolHourData,
+ volumeToken0: '0',
+ volumeToken1: '0',
+ totalValueLockedToken0: '0',
+ totalValueLockedToken1: '0',
+ feesETH: '0',
id: '0x',
- inputTokenBalances: ['0', '0'],
- timestamp: 0,
+ periodStartUnix: 0,
},
],
- dailySnapshots: [
+ poolDayData: [
{
- dailyVolumeByTokenAmount: ['0', '0'],
- dailyTotalRevenueETH: '0.001',
+ ..._poolDayData,
+ volumeToken0: '0',
+ volumeToken1: '1',
+ feesETH: '0.001',
id: '0x',
- inputTokenBalances: ['0', '0'],
- timestamp: 0,
+ totalValueLockedToken0: '0',
+ totalValueLockedToken1: '0',
+ date: 0,
},
],
},
@@ -172,20 +187,20 @@ it('calculates the APRs', async () => {
describe('when pool is a 0.3% tier', () => {
beforeEach(() => {
- poolData.liquidityPools[0].fees[2].feePercentage = 0.3;
+ poolData.pools[0].fees[2].feePercentage = '0.3';
});
it('calculates the daily and weekly revenue from the vault fee receipts', async () => {
const [[pool]] = await run();
expect(formatEther(pool.dailyRevenue)).toEqual('0');
- expect(formatEther(pool.weeklyRevenue)).toEqual('1.4');
+ expect(formatEther(pool.weeklyRevenue)).toEqual('1.401');
});
});
describe('when pool is a 1% tier', () => {
beforeEach(() => {
- poolData.liquidityPools[0].fees[2].feePercentage = 1;
+ poolData.pools[0].fees[2].feePercentage = '1';
});
it('calculates the daily and weekly revenue from the AMM fees', async () => {
@@ -198,8 +213,8 @@ describe('when pool is a 1% tier', () => {
describe('when there are more than 1000 pools', () => {
beforeEach(() => {
- poolData.liquidityPools = Array.from({ length: 1000 }).fill(
- poolData.liquidityPools[0]
+ poolData.pools = Array.from({ length: 1000 }).fill(
+ poolData.pools[0]
);
});
diff --git a/packages/core/src/pools/fetchLiquidityPools/calculateAprs.ts b/packages/core/src/pools/fetchLiquidityPools/calculateAprs.ts
index 8f9da26..3d4aa4f 100644
--- a/packages/core/src/pools/fetchLiquidityPools/calculateAprs.ts
+++ b/packages/core/src/pools/fetchLiquidityPools/calculateAprs.ts
@@ -20,13 +20,27 @@ const calculatePoolValue = ({
isWeth0: boolean;
vTokenToEth: bigint;
}) => {
- const eth = BigInt(balances?.[isWeth0 ? 0 : 1] ?? '0');
- const vToken = BigInt(balances?.[isWeth0 ? 1 : 0] ?? '0');
+ const eth = parseEther(balances?.[isWeth0 ? 0 : 1] ?? '0');
+ const vToken = parseEther(balances?.[isWeth0 ? 1 : 0] ?? '0');
const vTokenValue = (vToken * vTokenToEth) / WeiPerEther;
const poolValue = eth + vTokenValue;
return poolValue;
};
+const snapshotToBalances = (
+ snapshot:
+ | Pick<
+ NftxV3Uniswap.PoolDayData,
+ 'totalValueLockedToken0' | 'totalValueLockedToken1'
+ >
+ | undefined
+) => {
+ if (!snapshot) {
+ return undefined;
+ }
+ return [snapshot.totalValueLockedToken0, snapshot.totalValueLockedToken1];
+};
+
const calculateAMMApr = ({
createdAt,
dailySnapshots,
@@ -36,8 +50,8 @@ const calculateAMMApr = ({
vTokenToEth,
}: {
dailySnapshots: Pick<
- NftxV3Uniswap.LiquidityPoolDailySnapshot,
- 'timestamp' | 'inputTokenBalances' | 'dailyTotalRevenueETH'
+ NftxV3Uniswap.PoolDayData,
+ 'date' | 'totalValueLockedToken0' | 'totalValueLockedToken1' | 'feesETH'
>[];
isWeth0: boolean;
periodStart: number;
@@ -50,17 +64,17 @@ const calculateAMMApr = ({
let start = periodStart > createdAt ? periodStart : createdAt;
let end = start + 86400;
const initialSnapshot = dailySnapshots.findLast(
- (s) => Number(s.timestamp) >= start && Number(s.timestamp) <= end
+ (s) => Number(s.date) >= start && Number(s.date) <= end
);
let lastPoolValue = calculatePoolValue({
isWeth0,
- balances: initialSnapshot?.inputTokenBalances,
+ balances: snapshotToBalances(initialSnapshot),
vTokenToEth,
});
while (end <= periodEnd) {
const dailySnapshot = dailySnapshots.find(
- (s) => Number(s.timestamp) >= start && Number(s.timestamp) <= end
+ (s) => Number(s.date) >= start && Number(s.date) <= end
);
let apr = 0n;
@@ -68,11 +82,11 @@ const calculateAMMApr = ({
lastPoolValue = calculatePoolValue({
isWeth0,
vTokenToEth,
- balances: dailySnapshot.inputTokenBalances,
+ balances: snapshotToBalances(dailySnapshot),
});
const poolValue = lastPoolValue;
- const periodFees = parseEther(dailySnapshot.dailyTotalRevenueETH);
+ const periodFees = parseEther(dailySnapshot.feesETH);
if (periodFees && poolValue) {
apr = (periodFees * WeiPerEther * 365n) / poolValue;
if (apr < 0n) {
@@ -108,8 +122,8 @@ const calculateVaultFeeApr = ({
periodStart: number;
periodEnd: number;
dailySnapshots: Pick<
- NftxV3Uniswap.LiquidityPoolDailySnapshot,
- 'timestamp' | 'inputTokenBalances'
+ NftxV3Uniswap.PoolDayData,
+ 'date' | 'totalValueLockedToken0' | 'totalValueLockedToken1'
>[];
vaultFeeReceipts: Pick[];
vTokenToEth: bigint;
@@ -121,17 +135,17 @@ const calculateVaultFeeApr = ({
let start = periodStart > createdAt ? periodStart : createdAt;
let end = start + 86400;
const initialSnapshot = dailySnapshots.findLast(
- (s) => Number(s.timestamp) >= start && Number(s.timestamp) <= end
+ (s) => Number(s.date) >= start && Number(s.date) <= end
);
let lastPoolValue = calculatePoolValue({
isWeth0,
- balances: initialSnapshot?.inputTokenBalances,
+ balances: snapshotToBalances(initialSnapshot),
vTokenToEth,
});
while (end <= periodEnd) {
const dailySnapshot = dailySnapshots.find(
- (s) => Number(s.timestamp) >= start && Number(s.timestamp) <= end
+ (s) => Number(s.date) >= start && Number(s.date) <= end
);
const vaultFeeReceipt = vaultFeeReceipts.find(
(r) => r.date >= start && r.date <= end
@@ -142,7 +156,7 @@ const calculateVaultFeeApr = ({
lastPoolValue = calculatePoolValue({
isWeth0,
vTokenToEth,
- balances: dailySnapshot.inputTokenBalances,
+ balances: snapshotToBalances(dailySnapshot),
});
}
const poolValue = lastPoolValue;
@@ -179,8 +193,8 @@ export default ({
}: {
createdAt: number;
dailySnapshots: Pick<
- NftxV3Uniswap.LiquidityPoolDailySnapshot,
- 'timestamp' | 'dailyTotalRevenueETH' | 'inputTokenBalances'
+ NftxV3Uniswap.PoolDayData,
+ 'date' | 'totalValueLockedToken0' | 'totalValueLockedToken1' | 'feesETH'
>[];
vaultFeeReceipts: VaultFeeReceipt[];
vTokenToEth: bigint;
diff --git a/packages/core/src/pools/fetchLiquidityPools/fetchPoolsSet.ts b/packages/core/src/pools/fetchLiquidityPools/fetchPoolsSet.ts
index f7a1408..9f774e7 100644
--- a/packages/core/src/pools/fetchLiquidityPools/fetchPoolsSet.ts
+++ b/packages/core/src/pools/fetchLiquidityPools/fetchPoolsSet.ts
@@ -51,7 +51,7 @@ export const makeFetchPoolsSet =
vaultIds,
});
- const pools = data.liquidityPools.reduce((acc, pool) => {
+ const pools = data.pools.reduce((acc, pool) => {
const vault = getVaultByTokens({
inputTokens: pool.inputTokens,
vaults,
@@ -77,8 +77,8 @@ export const makeFetchPoolsSet =
}, [] as LiquidityPool[]);
let nextId: Address | undefined;
- if (data.liquidityPools.length === 1000) {
- nextId = data.liquidityPools.pop()?.id as Address;
+ if (data.pools.length === 1000) {
+ nextId = data.pools.pop()?.id as Address;
}
return [pools, nextId] as const;
diff --git a/packages/core/src/pools/fetchLiquidityPools/queryPoolData.ts b/packages/core/src/pools/fetchLiquidityPools/queryPoolData.ts
index 740e680..803d695 100644
--- a/packages/core/src/pools/fetchLiquidityPools/queryPoolData.ts
+++ b/packages/core/src/pools/fetchLiquidityPools/queryPoolData.ts
@@ -5,9 +5,6 @@ import type { NftxV3Uniswap, Address, Vault } from '@nftx/types';
type QuerySubgraph = typeof querySubgraph;
-const ONE_DAY = 60 * 60 * 24;
-const ONE_WEEK = ONE_DAY * 7;
-
const getAddressesForVaultIds = (
vaultIds: string[],
vaults: Pick[]
@@ -39,12 +36,8 @@ export const makeQueryPoolData =
vaultAddresses = getAddressesForVaultIds(vaultIds, vaults);
}
- const now = Math.floor(Date.now() / 1000);
- const oneDayAgo = now - ONE_DAY;
- const oneWeekAgo = now - ONE_WEEK;
-
const q = createQuery();
- const query = q.liquidityPools
+ const query = q.pools
.first(1000)
.orderBy('id')
.where((w) => [
@@ -55,39 +48,45 @@ export const makeQueryPoolData =
s.id,
s.name,
s.tick,
+ s.liquidity,
s.totalLiquidity,
- s.activeLiquidity,
- s.inputTokenBalances,
+ s.totalValueLockedToken0,
+ s.totalValueLockedToken1,
s.totalValueLockedETH,
s.openPositionCount,
- s.createdTimestamp,
+ s.createdAtTimestamp,
+ s.token0((token0) => [token0.id, token0.symbol, token0.name]),
+ s.token1((token1) => [token1.id, token1.symbol, token1.name]),
s.fees((fee) => [fee.id, fee.feePercentage, fee.feeType]),
s.inputTokens((token) => [token.id, token.symbol, token.name]),
- s.hourlySnapshots(
- q.liquidityPoolHourlySnapshots
+ s.poolHourData(
+ q.poolHourDatas
.first(1000)
- .orderBy('hour')
+ .orderBy('periodStartUnix')
.orderDirection('desc')
.select((s) => [
- s.hourlyVolumeByTokenAmount,
- s.hourlyTotalRevenueETH,
+ s.volumeToken0,
+ s.volumeToken1,
+ s.feesETH,
s.id,
- s.inputTokenBalances,
- s.timestamp,
+ s.totalValueLockedToken0,
+ s.totalValueLockedToken1,
+ s.periodStartUnix,
])
),
- s.dailySnapshots(
- q.liquidityPoolDailySnapshots
+ s.poolDayData(
+ q.poolDayDatas
.first(1000)
- .orderBy('day')
+ .orderBy('date')
.orderDirection('desc')
.select((s) => [
s.id,
- s.day,
- s.dailyVolumeByTokenAmount,
- s.dailyTotalRevenueETH,
- s.inputTokenBalances,
- s.timestamp,
+ s.date,
+ s.volumeToken0,
+ s.volumeToken1,
+ s.feesETH,
+ s.totalValueLockedToken0,
+ s.totalValueLockedToken1,
])
),
]);
diff --git a/packages/core/src/pools/fetchLiquidityPools/transformPool.ts b/packages/core/src/pools/fetchLiquidityPools/transformPool.ts
index 5de9ec4..2f384d6 100644
--- a/packages/core/src/pools/fetchLiquidityPools/transformPool.ts
+++ b/packages/core/src/pools/fetchLiquidityPools/transformPool.ts
@@ -22,7 +22,7 @@ import { parseEther } from 'viem';
import calculateAprs from './calculateAprs';
import { calculatePriceFromTick } from '../../univ3-helpers';
-type Pool = LiquidityPoolsResponse['liquidityPools'][0];
+type Pool = LiquidityPoolsResponse['pools'][0];
const transformFees = (fees: Pool['fees']): LiquidityPool['fees'] => {
return fees.map((fee): LiquidityPool['fees'][0] => {
@@ -47,15 +47,23 @@ const transformPool = (
premiumPaids: { amount: bigint; date: number }[]
): LiquidityPool => {
const fees = transformFees(pool.fees);
- const tokens = pool.inputTokens.map(({ id, symbol, name }, i) => ({
- id: id as Address,
- symbol,
- name,
- balance: BigInt(pool.inputTokenBalances[i] ?? '0'),
- }));
+ const tokens = [
+ {
+ id: pool.token0.id as Address,
+ symbol: pool.token0.symbol,
+ name: pool.token0.name,
+ balance: parseEther(pool.totalValueLockedToken0),
+ },
+ {
+ id: pool.token1.id as Address,
+ symbol: pool.token1.symbol,
+ name: pool.token1.name,
+ balance: parseEther(pool.totalValueLockedToken1),
+ },
+ ];
const wethToken = getChainConstant(WETH_TOKEN, network);
const isWeth0 = addressEqual(tokens[0].id, wethToken);
- const activeLiquidity = BigInt(pool.activeLiquidity ?? '0');
+ const activeLiquidity = BigInt(pool.liquidity ?? '0');
const totalLiquidity = BigInt(pool.totalLiquidity ?? '0');
const tick = BigInt(pool.tick ?? '0');
const tickValue = calculatePriceFromTick(tick);
@@ -81,20 +89,20 @@ const transformPool = (
const oneDayAgo = now - 60 * 60 * 24;
const oneWeekAgo = now - 60 * 60 * 24 * 7;
- const dailyVolume = pool.hourlySnapshots.reduce((total, snapshot) => {
- if (Number(snapshot.timestamp) >= oneDayAgo) {
- const value = BigInt(
- snapshot.hourlyVolumeByTokenAmount[isWeth0 ? 0 : 1] ?? '0'
+ const dailyVolume = pool.poolHourData.reduce((total, snapshot) => {
+ if (Number(snapshot.periodStartUnix) >= oneDayAgo) {
+ const value = parseEther(
+ (isWeth0 ? snapshot.volumeToken0 : snapshot.volumeToken1) || '0'
);
return total + value;
}
return total;
}, Zero);
- const weeklyVolume = pool.dailySnapshots.reduce((total, snapshot) => {
- if (Number(snapshot.timestamp) >= oneWeekAgo) {
- const value = BigInt(
- snapshot.dailyVolumeByTokenAmount[isWeth0 ? 0 : 1] ?? '0'
+ const weeklyVolume = pool.poolDayData.reduce((total, snapshot) => {
+ if (Number(snapshot.date) >= oneWeekAgo) {
+ const value = parseEther(
+ (isWeth0 ? snapshot.volumeToken0 : snapshot.volumeToken1) || '0'
);
return total + value;
}
@@ -118,25 +126,25 @@ const transformPool = (
}
return total;
}, Zero);
- } else {
- // All other pools only get the AMM fees
- dailyRevenue = pool.hourlySnapshots.reduce((total, snapshot) => {
- if (Number(snapshot.timestamp) >= oneDayAgo) {
- return total + parseEther(snapshot.hourlyTotalRevenueETH ?? '0');
- }
- return total;
- }, Zero);
- weeklyRevenue = pool.dailySnapshots.reduce((total, snapshot) => {
- if (Number(snapshot.timestamp) >= oneWeekAgo) {
- return total + parseEther(snapshot.dailyTotalRevenueETH ?? '0');
- }
- return total + parseEther(snapshot.dailyTotalRevenueETH ?? '0');
- }, Zero);
}
+ // All other pools only get the AMM fees
+ dailyRevenue += pool.poolHourData.reduce((total, snapshot) => {
+ if (Number(snapshot.periodStartUnix) >= oneDayAgo) {
+ return total + parseEther(snapshot.feesETH ?? '0');
+ }
+ return total;
+ }, Zero);
+ weeklyRevenue += pool.poolDayData.reduce((total, snapshot) => {
+ if (Number(snapshot.date) >= oneWeekAgo) {
+ return total + parseEther(snapshot.feesETH ?? '0');
+ }
+ return total + parseEther(snapshot.feesETH ?? '0');
+ }, Zero);
+
const apr = calculateAprs({
- createdAt: Number(pool.createdTimestamp),
- dailySnapshots: pool.dailySnapshots,
+ createdAt: Number(pool.createdAtTimestamp),
+ dailySnapshots: pool.poolDayData,
isWeth0,
vaultFeeReceipts: receipts,
vTokenToEth: vault.vTokenToEth,
diff --git a/packages/core/src/pools/fetchLiquidityPools/types.ts b/packages/core/src/pools/fetchLiquidityPools/types.ts
index 0e882e4..5ed89d2 100644
--- a/packages/core/src/pools/fetchLiquidityPools/types.ts
+++ b/packages/core/src/pools/fetchLiquidityPools/types.ts
@@ -1,6 +1,3 @@
import type { NftxV3Uniswap } from '@nftx/types';
-export type LiquidityPoolsResponse = Pick<
- NftxV3Uniswap.Query,
- 'liquidityPools'
->;
+export type LiquidityPoolsResponse = Pick;
diff --git a/packages/core/src/positions/fetchLiquidityPositions/__tests__/fetchLiquidityPositions.test.ts b/packages/core/src/positions/fetchLiquidityPositions/__tests__/fetchLiquidityPositions.test.ts
index 0d359d2..3bb0dfd 100644
--- a/packages/core/src/positions/fetchLiquidityPositions/__tests__/fetchLiquidityPositions.test.ts
+++ b/packages/core/src/positions/fetchLiquidityPositions/__tests__/fetchLiquidityPositions.test.ts
@@ -6,8 +6,9 @@ import { getChainConstant } from '@nftx/utils';
import { MAX_TICK, MIN_TICK, WETH_TOKEN } from '@nftx/constants';
import { MAX_PRICE } from '@nftx/constants';
import { MIN_PRICE } from '@nftx/constants';
+import { NftxV3Uniswap } from '@nftx/types';
-let subggraphResponse: any;
+let subggraphResponse: { positions: NftxV3Uniswap.Position[] };
let querySubgraph: jest.Mock;
let queryPositionData: ReturnType;
let fetchClaimableAmount: jest.Mock;
@@ -18,26 +19,35 @@ let args: Parameters[0];
let run: () => ReturnType;
beforeEach(() => {
+ const _token = {} as NftxV3Uniswap.Token;
+ const _pool = {} as NftxV3Uniswap.Pool;
+ const _owner = {} as NftxV3Uniswap.Account;
+ const _position = {} as NftxV3Uniswap.Position;
+
subggraphResponse = {
positions: [
{
+ ..._position,
id: '0x1',
tokenId: '1',
liquidity: '5431575616225859850',
- cumulativeDepositTokenAmounts: ['100', '100'],
- cumulativeWithdrawTokenAmounts: ['100', '100'],
+ depositedToken0: '100',
+ depositedToken1: '100',
+ withdrawnToken0: '100',
+ withdrawnToken1: '100',
lockedUntil: '0',
- tickUpper: { index: '-23160' },
- tickLower: { index: '-36960' },
+ tickUpper: -23160,
+ tickLower: -36960,
pool: {
+ ..._pool,
id: '0x2',
tick: '-24000',
inputTokens: [
- { id: '0xe770493b2663004b356d3374ec23ea52f6c82ca6' },
- { id: getChainConstant(WETH_TOKEN, 1) },
+ { ..._token, id: '0xe770493b2663004b356d3374ec23ea52f6c82ca6' },
+ { ..._token, id: getChainConstant(WETH_TOKEN, 1) },
],
},
- account: { id: '0x4' },
+ owner: { ..._owner, id: '0x4' },
},
],
};
@@ -141,7 +151,7 @@ describe('when userAddresses are provided', () => {
const query = querySubgraph.mock.calls[0][0].query.toString();
- expect(query).toContain('account_in: ["0x4"]');
+ expect(query).toContain('owner_in: ["0x4"]');
});
});
@@ -203,8 +213,8 @@ it('calculate the tick values', async () => {
describe('when position has an infinite range', () => {
beforeEach(() => {
- subggraphResponse.positions[0].tickLower.index = `${MIN_TICK}`;
- subggraphResponse.positions[0].tickUpper.index = `${MAX_TICK}`;
+ subggraphResponse.positions[0].tickLower = MIN_TICK;
+ subggraphResponse.positions[0].tickUpper = MAX_TICK;
});
it('sets infiniteRange to true', async () => {
diff --git a/packages/core/src/positions/fetchLiquidityPositions/__tests__/fetchPoolIdsForVaultIds.test.ts b/packages/core/src/positions/fetchLiquidityPositions/__tests__/fetchPoolIdsForVaultIds.test.ts
index a351754..071f333 100644
--- a/packages/core/src/positions/fetchLiquidityPositions/__tests__/fetchPoolIdsForVaultIds.test.ts
+++ b/packages/core/src/positions/fetchLiquidityPositions/__tests__/fetchPoolIdsForVaultIds.test.ts
@@ -1,25 +1,31 @@
+import { NftxV3Uniswap } from '@nftx/types';
import { makeFetchPoolIdsForVaultIds } from '../fetchPoolIdsForVaultIds';
const trim = (s: string) => {
return s.replace(/[\s\n]/g, '');
};
-let subgraphResponse: any;
+let subgraphResponse: Pick;
let querySubgraph: jest.Mock;
let fetchPoolIdsForVaultIds: ReturnType;
let run: () => ReturnType;
let args: Parameters[0];
beforeEach(() => {
+ const _pool = {} as NftxV3Uniswap.Pool;
+
subgraphResponse = {
- liquidityPools: [
+ pools: [
{
+ ..._pool,
id: '0x3',
},
{
+ ..._pool,
id: '0x4',
},
{
+ ..._pool,
id: '0x5',
},
],
@@ -75,7 +81,7 @@ it('uses the the vault addresses to match up with pool input tokens', async () =
describe('when there are more than 1000 pools', () => {
beforeEach(() => {
querySubgraph.mockResolvedValueOnce({
- liquidityPools: Array(1000).fill({ id: '0x3' }),
+ pools: Array(1000).fill({ id: '0x3' }),
});
});
diff --git a/packages/core/src/positions/fetchLiquidityPositions/fetchPoolIdsForVaultIds.ts b/packages/core/src/positions/fetchLiquidityPositions/fetchPoolIdsForVaultIds.ts
index bd76a5e..1d2b994 100644
--- a/packages/core/src/positions/fetchLiquidityPositions/fetchPoolIdsForVaultIds.ts
+++ b/packages/core/src/positions/fetchLiquidityPositions/fetchPoolIdsForVaultIds.ts
@@ -17,7 +17,7 @@ const fetchPoolIdsNextSet = async ({
querySubgraph: QuerySubgraph;
}) => {
const query = createQuery()
- .liquidityPools.first(1000)
+ .pools.first(1000)
.orderBy('id')
.where((w) => [
w.inputTokens((token) => [token.id.in(addresses), token.id.gt(lastId)]),
@@ -29,11 +29,11 @@ const fetchPoolIdsNextSet = async ({
query,
});
- const poolIds = data.liquidityPools.map((pool) => pool.id as Address);
+ const poolIds = data.pools.map((pool) => pool.id as Address);
let nextId: Address | undefined;
- if (data.liquidityPools.length === 1000) {
- nextId = data.liquidityPools.pop()?.id as Address;
+ if (data.pools.length === 1000) {
+ nextId = data.pools.pop()?.id as Address;
}
return [poolIds, nextId] as const;
diff --git a/packages/core/src/positions/fetchLiquidityPositions/queryPositionData.ts b/packages/core/src/positions/fetchLiquidityPositions/queryPositionData.ts
index 7cec210..9b53991 100644
--- a/packages/core/src/positions/fetchLiquidityPositions/queryPositionData.ts
+++ b/packages/core/src/positions/fetchLiquidityPositions/queryPositionData.ts
@@ -26,7 +26,7 @@ export const makeQueryPositionData =
.positions.first(1000)
.orderBy('id')
.where((w) => [
- w.account.in(userAddresses),
+ w.owner.in(userAddresses),
w.pool.in(poolIds),
w.id.in(positionIds),
w.id.gt(lastId),
@@ -36,20 +36,21 @@ export const makeQueryPositionData =
s.id,
s.tokenId,
s.liquidity,
- s.cumulativeDepositTokenAmounts,
- s.cumulativeWithdrawTokenAmounts,
+ s.depositedToken0,
+ s.depositedToken1,
+ s.withdrawnToken0,
+ s.withdrawnToken1,
s.lockedUntil,
- s.timestampOpened,
s.nfpmAddress,
- s.tickUpper((tick) => [tick.index]),
- s.tickLower((tick) => [tick.index]),
+ s.tickUpper,
+ s.tickLower,
s.pool((pool) => [
pool.id,
pool.tick,
pool.name,
pool.inputTokens((token) => [token.id]),
]),
- s.account((account) => [account.id]),
+ s.owner((account) => [account.id]),
]);
return querySubgraph({
diff --git a/packages/core/src/positions/fetchLiquidityPositions/transformPosition.ts b/packages/core/src/positions/fetchLiquidityPositions/transformPosition.ts
index 69426e1..3c2d258 100644
--- a/packages/core/src/positions/fetchLiquidityPositions/transformPosition.ts
+++ b/packages/core/src/positions/fetchLiquidityPositions/transformPosition.ts
@@ -36,8 +36,8 @@ const transformPosition = ({
}): LiquidityPosition => {
const tokenId = position.tokenId as TokenId;
const tick = BigInt(position.pool.tick ?? '0');
- const tickLower = BigInt(position.tickLower?.index ?? '0');
- const tickUpper = BigInt(position.tickUpper?.index ?? '0');
+ const tickLower = BigInt(position.tickLower ?? '0');
+ const tickUpper = BigInt(position.tickUpper ?? '0');
const inRange = tick >= tickLower && tick <= tickUpper;
const liquidity = BigInt(position.liquidity);
@@ -92,7 +92,7 @@ const transformPosition = ({
tick,
isFullRange,
tickUpper,
- userAddress: position.account.id as Address,
+ userAddress: position.owner.id as Address,
inRange,
eth,
tickLowerValue,
diff --git a/packages/core/src/vaults/__tests__/fetchVaultActivity.test.ts b/packages/core/src/vaults/__tests__/fetchVaultActivity.test.ts
index 9458c89..3aaf550 100644
--- a/packages/core/src/vaults/__tests__/fetchVaultActivity.test.ts
+++ b/packages/core/src/vaults/__tests__/fetchVaultActivity.test.ts
@@ -1,6 +1,7 @@
import { formatJson, getChainConstant } from '@nftx/utils';
import { makeFetchVaultActivity } from '../fetchVaultActivity';
import { NFTX_FEE_DISTRIBUTOR } from '@nftx/constants';
+import { NFTX_FEE_DISTRIBUTOR_LEGACY } from '@nftx/constants';
let subgraphResponse: any;
let querySubgraph: jest.Mock;
@@ -221,10 +222,13 @@ it('filters transfers by fee distrubtor', async () => {
await run();
const str = querySubgraph.mock.calls[0][0].query;
- const address = getChainConstant(NFTX_FEE_DISTRIBUTOR, 1).toLowerCase();
+ const addresses = [
+ getChainConstant(NFTX_FEE_DISTRIBUTOR, 1),
+ ...getChainConstant(NFTX_FEE_DISTRIBUTOR_LEGACY, 1),
+ ].map((x) => x.toLowerCase());
expect(`${str}`.replace(/[ \n]/g, '')).toContain(
- `transfers(where:{to:"${address}"})`
+ `transfers(where:{to_in:${JSON.stringify(addresses)}})`
);
});
diff --git a/packages/core/src/vaults/fetchVaultActivity.ts b/packages/core/src/vaults/fetchVaultActivity.ts
index 4fc22ba..59ed807 100644
--- a/packages/core/src/vaults/fetchVaultActivity.ts
+++ b/packages/core/src/vaults/fetchVaultActivity.ts
@@ -1,5 +1,8 @@
import config from '@nftx/config';
-import { NFTX_FEE_DISTRIBUTOR } from '@nftx/constants';
+import {
+ NFTX_FEE_DISTRIBUTOR,
+ NFTX_FEE_DISTRIBUTOR_LEGACY,
+} from '@nftx/constants';
import { Zero } from '@nftx/constants';
import { querySubgraph, createQuery } from '@nftx/subgraph';
import type {
@@ -268,10 +271,10 @@ export const makeFetchVaultActivity = ({
}): Promise {
let lastId: string | undefined;
const activity: VaultActivity[] = [];
- const feeDistributorAddress = getChainConstant(
- NFTX_FEE_DISTRIBUTOR,
- network
- );
+ const feeDistributorAddresses = [
+ getChainConstant(NFTX_FEE_DISTRIBUTOR, network),
+ ...getChainConstant(NFTX_FEE_DISTRIBUTOR_LEGACY, network),
+ ];
do {
const q = createQuery();
@@ -297,7 +300,7 @@ export const makeFetchVaultActivity = ({
s.feeReceipt((r) => [
r.transfers(
q.feeTransfers
- .where((w) => [w.to.is(feeDistributorAddress)])
+ .where((w) => [w.to.in(feeDistributorAddresses)])
.select((receipt) => [receipt.amount])
),
]),
@@ -308,7 +311,7 @@ export const makeFetchVaultActivity = ({
s.feeReceipt((r) => [
r.transfers(
q.feeTransfers
- .where((w) => [w.to.is(feeDistributorAddress)])
+ .where((w) => [w.to.in(feeDistributorAddresses)])
.select((receipt) => [receipt.amount])
),
]),
@@ -319,7 +322,7 @@ export const makeFetchVaultActivity = ({
s.feeReceipt((r) => [
r.transfers(
q.feeTransfers
- .where((w) => [w.to.is(feeDistributorAddress)])
+ .where((w) => [w.to.in(feeDistributorAddresses)])
.select((receipt) => [receipt.amount])
),
]),
diff --git a/packages/subgraph/src/__tests__/createQuery.test.ts b/packages/subgraph/src/__tests__/createQuery.test.ts
index b2d48ba..da56b9a 100644
--- a/packages/subgraph/src/__tests__/createQuery.test.ts
+++ b/packages/subgraph/src/__tests__/createQuery.test.ts
@@ -9,13 +9,13 @@ const ignoreWs = (str: string) => str.replace(/ /g, '').replace(/\n/g, '');
it('handles a single entity', () => {
const g = createQuery();
- const query = g.liquidityPool
+ const query = g.pool
.id('0x1768ccc3fc3a40522fcd3296633ae8c00434b3b6')
.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPool(id: "0x1768ccc3fc3a40522fcd3296633ae8c00434b3b6") {
+ pool(id: "0x1768ccc3fc3a40522fcd3296633ae8c00434b3b6") {
id
}
}`;
@@ -25,11 +25,11 @@ it('handles a single entity', () => {
it('handles a list entity', () => {
const g = createQuery();
- const query = g.liquidityPools.select((s) => [s.id]);
+ const query = g.pools.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPools {
+ pools {
id
}
}`;
@@ -39,11 +39,11 @@ it('handles a list entity', () => {
it('aliases the collection name', () => {
const g = createQuery();
- const query = g.liquidityPools.as('foo').select((s) => [s.id]);
+ const query = g.pools.as('foo').select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- foo: liquidityPools {
+ foo: pools {
id
}
}`;
@@ -53,17 +53,17 @@ it('aliases the collection name', () => {
it('adds filters', () => {
const g = createQuery();
- const query = g.liquidityPools
+ const query = g.pools
.first(10)
- .orderBy('activeLiquidity')
+ .orderBy('liquidity')
.orderDirection('desc')
.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPools(
+ pools(
first: 10
- orderBy: activeLiquidity
+ orderBy: liquidity
orderDirection: desc
) {
id
@@ -76,15 +76,15 @@ it('adds filters', () => {
it('searches by primitive values', () => {
const g = createQuery();
- const query = g.liquidityPools
- .where((w) => [w.createdTimestamp('0')])
+ const query = g.pools
+ .where((w) => [w.createdAtTimestamp('0')])
.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPools(
+ pools(
where: {
- createdTimestamp: "0"
+ createdAtTimestamp: "0"
}
) {
id
@@ -97,18 +97,21 @@ it('searches by primitive values', () => {
it('strips out nullish values', () => {
const g = createQuery();
- const query = g.liquidityPools
+ const query = g.pools
.where((w) => [
- w.createdTimestamp(undefined),
- w.totalLiquidity(null),
- w.activeLiquidity.in(undefined),
- w.protocol((w) => [w.id.in(null), w.pools((w) => [w.id.is(undefined)])]),
+ w.createdAtTimestamp(undefined),
+ w.liquidity(null),
+ w.balanceOfBlock.in(undefined),
+ w.collects((collect) => [
+ collect.id.in(null),
+ collect.owner((owner) => [owner.id.is(undefined)]),
+ ]),
])
.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPools {
+ pools {
id
}
}`;
@@ -118,15 +121,15 @@ it('strips out nullish values', () => {
it('filters with a contains query', () => {
const q = createQuery();
- const query = q.withdraws
- .where((w) => [w.inputTokens.contains(['0x1234'])])
+ const query = q.pools
+ .where((w) => [w.burns.contains(['0x1234'])])
.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- withdraws(
+ pools(
where: {
- inputTokens_contains: ["0x1234"]
+ burns_contains: ["0x1234"]
}
) {
id
@@ -136,36 +139,37 @@ it('filters with a contains query', () => {
expect(ignoreWs(actual)).toBe(ignoreWs(expected));
});
-it('filters by an exact array match', () => {
- const q = createQuery();
- const query = q.withdraws
- .where((w) => [w.inputTokenAmounts.isNot(['0', '0'])])
- .select((s) => [s.id]);
+// Pretty sure we no longer have a use case for this in our schemas
+// it('filters by an exact array match', () => {
+// const q = createQuery();
+// const query = q.pools
+// .where((w) => [w.feesUSD.isNot(['0', '0'])])
+// .select((s) => [s.id]);
- const actual = query.toString();
- const expected = `{
- withdraws(
- where: {
- inputTokenAmounts_not: ["0", "0"]
- }
- ) {
- id
- }
- }`;
+// const actual = query.toString();
+// const expected = `{
+// withdraws(
+// where: {
+// inputTokenAmounts_not: ["0", "0"]
+// }
+// ) {
+// id
+// }
+// }`;
- expect(ignoreWs(actual)).toBe(ignoreWs(expected));
-});
+// expect(ignoreWs(actual)).toBe(ignoreWs(expected));
+// });
// For now we're just saying bigint fields should be stringified
// it('handles a bigint value', () => {
// const g = createQuery();
-// const query = g.liquidityPools
+// const query = g.pools
// .where((w) => w.activeLiquidity.is(0n))
// .select((s) => [s.id]);
// const actual = query.toString();
// const expected = `{
-// liquidityPools(
+// pools(
// where: {
// activeLiquidity: 0
// }
@@ -179,25 +183,25 @@ it('filters by an exact array match', () => {
it('searches by lt/lte/gt/gte/ne', () => {
const g = createQuery();
- const query = g.liquidityPools
+ const query = g.pools
.where((w) => [
- w.activeLiquidity.gt('0'),
- w.activeLiquidity.gte('1'),
- w.activeLiquidity.isNot('2'),
- w.activeLiquidity.lt('100000000000'),
- w.activeLiquidity.lte('9999999999'),
+ w.liquidity.gt('0'),
+ w.liquidity.gte('1'),
+ w.liquidity.isNot('2'),
+ w.liquidity.lt('100000000000'),
+ w.liquidity.lte('9999999999'),
])
.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPools(
+ pools(
where: {
- activeLiquidity_gt: "0",
- activeLiquidity_gte: "1",
- activeLiquidity_ne: "2",
- activeLiquidity_lt: "100000000000",
- activeLiquidity_lte: "9999999999"
+ liquidity_gt: "0",
+ liquidity_gte: "1",
+ liquidity_ne: "2",
+ liquidity_lt: "100000000000",
+ liquidity_lte: "9999999999"
}
) {
id
@@ -210,16 +214,19 @@ it('searches by lt/lte/gt/gte/ne', () => {
it('searches on nested fields', () => {
const g = createQuery();
- const query = g.liquidityPools
- .where((w) => [w.inputTokens((w) => [w.id('0x00000'), w.decimals(18)])])
+ const query = g.pools
+ // .where((w) => [w.inputTokens((w) => [w.id('0x00000'), w.decimals(18)])])
+ .where((w) => [
+ w.fees((fee) => [fee.id('0x00000'), fee.feePercentage('0.01')]),
+ ])
.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPools(
+ pools(
where: {
- inputTokens_: {
+ fees_: {
id: "0x00000",
- decimals: 18
+ feePercentage: "0.01"
}
}
) {
@@ -230,18 +237,20 @@ it('searches on nested fields', () => {
expect(ignoreWs(actual)).toBe(ignoreWs(expected));
});
+it.todo('allows for OR queries');
+
it("searches by a child entity's ID", () => {
const g = createQuery();
- const query = g.liquidityPools
- .where((w) => w.protocol.is('0x000'))
+ const query = g.pools
+ .where((w) => w.token1.is('0x000'))
.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPools(
+ pools(
where: {
- protocol: "0x000"
+ token1: "0x000"
}
) {
id
@@ -253,18 +262,18 @@ it("searches by a child entity's ID", () => {
it('selects primitive fields', () => {
const g = createQuery();
- const query = g.liquidityPools.select((s) => [
+ const query = g.pools.select((s) => [
s.id,
- s.activeLiquidity,
- s.createdTimestamp,
+ s.liquidity,
+ s.createdAtTimestamp,
]);
const actual = query.toString();
const expected = `{
- liquidityPools {
+ pools {
id
- activeLiquidity
- createdTimestamp
+ liquidity
+ createdAtTimestamp
}
}`;
@@ -273,12 +282,13 @@ it('selects primitive fields', () => {
it('selects nested primitive fields', () => {
const g = createQuery();
- const query = g.liquidityPools.select((s) => [s.positions((s) => [s.id])]);
+ // const query = g.pools.select((s) => [s.positions((s) => [s.id])]);
+ const query = g.positions.select((s) => [s.pool((pool) => [pool.id])]);
const actual = query.toString();
const expected = `{
- liquidityPools {
- positions {
+ positions {
+ pool {
id
}
}
@@ -289,15 +299,15 @@ it('selects nested primitive fields', () => {
it('selects deeply-nested primitive fields', () => {
const g = createQuery();
- const query = g.liquidityPools.select((s) => [
- s.positions((s) => [s.pool((s) => [s.id])]),
+ const query = g.positions.select((s) => [
+ s.pool((pool) => [pool.mints((mint) => [mint.id])]),
]);
const actual = query.toString();
const expected = `{
- liquidityPools {
- positions {
- pool {
+ positions {
+ pool {
+ mints {
id
}
}
@@ -309,11 +319,11 @@ it('selects deeply-nested primitive fields', () => {
it('selects primitives with object-syntax', () => {
const g = createQuery();
- const query = g.liquidityPools.select((s) => [s.id]);
+ const query = g.pools.select((s) => [s.id]);
const actual = query.toString();
const expected = `{
- liquidityPools {
+ pools {
id
}
}`;
@@ -323,21 +333,19 @@ it('selects primitives with object-syntax', () => {
it('selects and filters child entities with a nested query', () => {
const g = createQuery();
- const query = g.liquidityPools.select(() => [
- g.positions
- .where((w) => w.account.is('0x0'))
- .select((s) => [s.depositCount]),
+ const query = g.pools.select(() => [
+ g.positions.where((w) => w.owner.is('0x0')).select((s) => [s.nfpmAddress]),
]);
const actual = query.toString();
const expected = `{
- liquidityPools {
+ pools {
positions(
where: {
- account: "0x0"
+ owner: "0x0"
}
) {
- depositCount
+ nfpmAddress
}
}
}`;
@@ -348,24 +356,25 @@ it('selects and filters child entities with a nested query', () => {
it('selects and filters child entities with a nested query assigned to another field', () => {
const q = createQuery();
- const query = q.liquidityPools.select((s) => [
- s.hourlySnapshots(
- q.liquidityPoolHourlySnapshots
+ const query = q.pools.select((s) => [
+ s.poolHourData(
+ q.poolHourDatas
.first(24)
- .orderBy('hour')
+ .orderBy('periodStartUnix')
.orderDirection('desc')
- .select((s) => [s.hourlyVolumeUSD, s.id])
+ .select((s) => [s.volumeUSD, s.id])
),
]);
+
const actual = query.toString();
const expected = `{
- liquidityPools {
- hourlySnapshots(
+ pools {
+ poolHourData(
first: 24
- orderBy: hour
+ orderBy: periodStartUnix
orderDirection: desc
) {
- hourlyVolumeUSD
+ volumeUSD
id
}
}
@@ -377,28 +386,28 @@ it('selects and filters child entities with a nested query assigned to another f
it('selects and filters child entities with a nested query assigned to an on... field', () => {
const q = createQuery();
- const query = q.liquidityPools.select((s) => [
+ const query = q.pools.select((s) => [
s.on('Foo', (s) => [
- s.hourlySnapshots(
- q.liquidityPoolHourlySnapshots
+ s.poolHourData(
+ q.poolHourDatas
.first(24)
- .orderBy('hour')
+ .orderBy('periodStartUnix')
.orderDirection('desc')
- .select((s) => [s.hourlyVolumeUSD, s.id])
+ .select((s) => [s.volumeUSD, s.id])
),
]),
]);
const actual = query.toString();
const expected = `{
- liquidityPools {
+ pools {
... on Foo {
- hourlySnapshots(
+ poolHourData(
first: 24
- orderBy: hour
+ orderBy: periodStartUnix
orderDirection: desc
) {
- hourlyVolumeUSD
+ volumeUSD
id
}
}
@@ -426,30 +435,27 @@ it('works with optional fields', () => {
it('works with implicit stringify', () => {
const g = createQuery();
- const query = g.liquidityPools
- .where((w) => [
- w.activeLiquidity.gt('0'),
- w.inputTokens((w) => [w.id('0xAB')]),
- ])
+ const query = g.pools
+ .where((w) => [w.liquidity.gt('0'), w.token0((w) => [w.id('0xAB')])])
.select((s) => [
- s.activeLiquidity,
+ s.liquidity,
s.fees((s) => [s.id, s.feeType, s.feePercentage]),
g.positions
- .where((w) => [w.account.is('0x0')])
- .select((s) => [s.id, s.account((s) => [s.id])]),
+ .where((w) => [w.owner.is('0x0')])
+ .select((s) => [s.id, s.owner((s) => [s.id])]),
]);
const actual = `${query}`;
const expected = `{
- liquidityPools(
+ pools(
where: {
- activeLiquidity_gt: "0",
- inputTokens_: {
+ liquidity_gt: "0",
+ token0_: {
id: "0xab"
}
}
) {
- activeLiquidity
+ liquidity
fees {
id
feeType
@@ -457,11 +463,11 @@ it('works with implicit stringify', () => {
}
positions(
where: {
- account: "0x0"
+ owner: "0x0"
}
) {
id
- account {
+ owner {
id
}
}
@@ -472,21 +478,21 @@ it('works with implicit stringify', () => {
});
it('aliases fields', () => {
- const query = createQuery().liquidityPools.select((s) => [
- s.activeLiquidity.as('liquidityActive'),
- s.deposits((s) => [s.blockNumber]).as('x'),
- s.positions((s) => [s.withdrawCount.as('totalWithdrawals')]).as('y'),
+ const query = createQuery().pools.select((s) => [
+ s.liquidity.as('w'),
+ s.mints((s) => [s.timestamp]).as('x'),
+ s.burns((s) => [s.timestamp.as('z')]).as('y'),
]);
const actual = query.toString();
const expected = `{
- liquidityPools {
- liquidityActive: activeLiquidity
- x: deposits {
- blockNumber
+ pools {
+ w: liquidity
+ x: mints {
+ timestamp
}
- y: positions {
- totalWithdrawals: withdrawCount
+ y: burns {
+ z: timestamp
}
}
}`;
@@ -536,14 +542,14 @@ it('creates "... on" selectors', () => {
describe('when select has not been set', () => {
it('throws an error', () => {
const g = createQuery();
- const query = g.liquidityPools;
+ const query = g.pools;
expect(() => query.toString()).toThrow();
});
});
it('sends a query to the subgraph', async () => {
- const response = { data: { liquidityPools: [] } };
+ const response = { data: { pools: [] } };
const fetch = jest.fn().mockResolvedValue({
ok: true,
status: 200,
@@ -551,7 +557,7 @@ it('sends a query to the subgraph', async () => {
text: async () => JSON.stringify(response),
});
const g = createQuery();
- const query = g.liquidityPools.select((s) => [s.id]).first(1);
+ const query = g.pools.select((s) => [s.id]).first(1);
const result = await querySubgraph({
url: 'https://example.com',
@@ -560,14 +566,14 @@ it('sends a query to the subgraph', async () => {
});
expect(fetch).toBeCalled();
- expect(fetch.mock.calls[0][1].body).toContain('liquidityPools');
+ expect(fetch.mock.calls[0][1].body).toContain('pools');
expect(fetch.mock.calls[0][1].body).toContain('first: 1');
expect(fetch.mock.calls[0][1].body).toContain('id');
expect(result).toEqual(response.data);
});
it('combines multiple queries into a single query request', async () => {
- const response = { data: { liquidityPools: [] } };
+ const response = { data: { pools: [] } };
const fetch = jest.fn().mockResolvedValue({
ok: true,
status: 200,
@@ -575,14 +581,14 @@ it('combines multiple queries into a single query request', async () => {
text: async () => JSON.stringify(response),
});
const g = createQuery();
- const q1 = g.liquidityPools.select((s) => [s.id]);
+ const q1 = g.pools.select((s) => [s.id]);
const q2 = g.positions.select((s) => [s.id]);
const q3 = g.accounts.select((s) => [s.id]);
const query = q1.combine(q2).combine(q3);
const actual = query.toString();
const expected = `{
- liquidityPools {
+ pools {
id
}
positions {
@@ -600,6 +606,6 @@ it('combines multiple queries into a single query request', async () => {
});
expect(ignoreWs(actual)).toBe(ignoreWs(expected));
- expect(fetch.mock.calls[0][1].body).toContain('liquidityPools');
+ expect(fetch.mock.calls[0][1].body).toContain('pools');
expect(fetch.mock.calls[0][1].body).toContain('positions');
});
diff --git a/packages/types/1155.codegen.yml b/packages/types/1155.codegen.yml
index 97516a0..24f2423 100644
--- a/packages/types/1155.codegen.yml
+++ b/packages/types/1155.codegen.yml
@@ -16,5 +16,6 @@ generates:
input: string
output: string
Int8: string|number
+ Timestamp: string
plugins:
- typescript
diff --git a/packages/types/721.codegen.yml b/packages/types/721.codegen.yml
index 81196eb..2abfc63 100644
--- a/packages/types/721.codegen.yml
+++ b/packages/types/721.codegen.yml
@@ -16,5 +16,6 @@ generates:
input: string
output: string
Int8: string|number
+ Timestamp: string
plugins:
- typescript
diff --git a/packages/types/nftx-v3-uniswap.codegen.yml b/packages/types/nftx-v3-uniswap.codegen.yml
index 88bd952..79c8278 100644
--- a/packages/types/nftx-v3-uniswap.codegen.yml
+++ b/packages/types/nftx-v3-uniswap.codegen.yml
@@ -1,4 +1,4 @@
-schema: https://api.thegraph.com/subgraphs/name/nftx-project/nftx-v3-amm-sepolia
+schema: https://query.graph.nftx.xyz/subgraphs/id/QmXavb61qVUrfYe7daW47n77LhinFgSoMhWVkMfgEdUspS
generates:
./src/subgraph/nftx-v3-uniswap.ts:
config:
@@ -15,5 +15,6 @@ generates:
input: string
output: string
Int8: string|number
+ Timestamp: string
plugins:
- typescript
diff --git a/packages/types/nftx-v3.codegen.yml b/packages/types/nftx-v3.codegen.yml
index eadf09c..44b4c27 100644
--- a/packages/types/nftx-v3.codegen.yml
+++ b/packages/types/nftx-v3.codegen.yml
@@ -15,5 +15,6 @@ generates:
input: string
output: string
Int8: string|number
+ Timestamp: string
plugins:
- typescript
diff --git a/packages/types/src/subgraph/1155.ts b/packages/types/src/subgraph/1155.ts
index 72bf65e..f1b4c69 100644
--- a/packages/types/src/subgraph/1155.ts
+++ b/packages/types/src/subgraph/1155.ts
@@ -16,6 +16,7 @@ export type Scalars = {
BigInt: { input: string; output: string; }
Bytes: { input: string; output: string; }
Int8: { input: string|number; output: string|number; }
+ Timestamp: { input: string; output: string; }
};
export type Account = {
diff --git a/packages/types/src/subgraph/721.ts b/packages/types/src/subgraph/721.ts
index 18b8f2d..a33135a 100644
--- a/packages/types/src/subgraph/721.ts
+++ b/packages/types/src/subgraph/721.ts
@@ -16,6 +16,7 @@ export type Scalars = {
BigInt: { input: string; output: string; }
Bytes: { input: string; output: string; }
Int8: { input: string|number; output: string|number; }
+ Timestamp: { input: string; output: string; }
};
export enum Aggregation_Interval {
diff --git a/packages/types/src/subgraph/nftx-v3-uniswap.ts b/packages/types/src/subgraph/nftx-v3-uniswap.ts
index 2bb193c..c231d48 100644
--- a/packages/types/src/subgraph/nftx-v3-uniswap.ts
+++ b/packages/types/src/subgraph/nftx-v3-uniswap.ts
@@ -20,157 +20,111 @@ export type Scalars = {
export type Account = {
__typename?: 'Account';
- /** Number of closed positions this account has */
- closedPositionCount: Scalars['Int']['output'];
- /** Number of deposits this account made */
- depositCount: Scalars['Int']['output'];
- /** All deposit events of this account */
- deposits: Array;
+ /** All withdraw events of this account */
+ burns: Array;
/** { Account address } */
- id: Scalars['ID']['output'];
- /** Number of open positions this account has */
- openPositionCount: Scalars['Int']['output'];
- /** Number of positions this account has */
- positionCount: Scalars['Int']['output'];
+ id: Scalars['Bytes']['output'];
+ /** All deposit events of this account */
+ mints: Array;
/** All positions that belong to this account */
positions: Array;
- /** Number of times this account has traded/swapped */
- swapCount: Scalars['Int']['output'];
/** All swap events of this account */
swaps: Array;
- /** Number of withdrawals this account made */
- withdrawCount: Scalars['Int']['output'];
- /** All withdraw events of this account */
- withdraws: Array;
};
-export type AccountDepositsArgs = {
+export type AccountBurnsArgs = {
first?: InputMaybe;
- orderBy?: InputMaybe;
+ orderBy?: InputMaybe;
orderDirection?: InputMaybe;
skip?: InputMaybe;
- where?: InputMaybe;
+ where?: InputMaybe;
};
-export type AccountPositionsArgs = {
+export type AccountMintsArgs = {
first?: InputMaybe;
- orderBy?: InputMaybe;
+ orderBy?: InputMaybe;
orderDirection?: InputMaybe;
skip?: InputMaybe;
- where?: InputMaybe;
+ where?: InputMaybe;
};
-export type AccountSwapsArgs = {
+export type AccountPositionsArgs = {
first?: InputMaybe;
- orderBy?: InputMaybe;
+ orderBy?: InputMaybe;
orderDirection?: InputMaybe;
skip?: InputMaybe;
- where?: InputMaybe;
+ where?: InputMaybe;
};
-export type AccountWithdrawsArgs = {
+export type AccountSwapsArgs = {
first?: InputMaybe;
- orderBy?: InputMaybe;
+ orderBy?: InputMaybe;
orderDirection?: InputMaybe;
skip?: InputMaybe;
- where?: InputMaybe;
+ where?: InputMaybe;
};
export type Account_Filter = {
/** Filter for the block changed event. */
_change_block?: InputMaybe;
and?: InputMaybe>>;
- closedPositionCount?: InputMaybe;
- closedPositionCount_gt?: InputMaybe;
- closedPositionCount_gte?: InputMaybe;
- closedPositionCount_in?: InputMaybe>;
- closedPositionCount_lt?: InputMaybe;
- closedPositionCount_lte?: InputMaybe;
- closedPositionCount_not?: InputMaybe;
- closedPositionCount_not_in?: InputMaybe>;
- depositCount?: InputMaybe;
- depositCount_gt?: InputMaybe;
- depositCount_gte?: InputMaybe;
- depositCount_in?: InputMaybe>;
- depositCount_lt?: InputMaybe;
- depositCount_lte?: InputMaybe;
- depositCount_not?: InputMaybe;
- depositCount_not_in?: InputMaybe>;
- deposits_?: InputMaybe;
- id?: InputMaybe;
- id_gt?: InputMaybe;
- id_gte?: InputMaybe;
- id_in?: InputMaybe>;
- id_lt?: InputMaybe;
- id_lte?: InputMaybe;
- id_not?: InputMaybe;
- id_not_in?: InputMaybe>;
- openPositionCount?: InputMaybe;
- openPositionCount_gt?: InputMaybe;
- openPositionCount_gte?: InputMaybe;
- openPositionCount_in?: InputMaybe>;
- openPositionCount_lt?: InputMaybe;
- openPositionCount_lte?: InputMaybe;
- openPositionCount_not?: InputMaybe;
- openPositionCount_not_in?: InputMaybe>;
+ burns_?: InputMaybe;
+ id?: InputMaybe;
+ id_contains?: InputMaybe;
+ id_gt?: InputMaybe;
+ id_gte?: InputMaybe;
+ id_in?: InputMaybe>;
+ id_lt?: InputMaybe;
+ id_lte?: InputMaybe;
+ id_not?: InputMaybe;
+ id_not_contains?: InputMaybe;
+ id_not_in?: InputMaybe>;
+ mints_?: InputMaybe;
or?: InputMaybe>>;
- positionCount?: InputMaybe;
- positionCount_gt?: InputMaybe;
- positionCount_gte?: InputMaybe;
- positionCount_in?: InputMaybe>;
- positionCount_lt?: InputMaybe;
- positionCount_lte?: InputMaybe;
- positionCount_not?: InputMaybe;
- positionCount_not_in?: InputMaybe>;
positions_?: InputMaybe;
- swapCount?: InputMaybe;
- swapCount_gt?: InputMaybe;
- swapCount_gte?: InputMaybe;
- swapCount_in?: InputMaybe>;
- swapCount_lt?: InputMaybe;
- swapCount_lte?: InputMaybe;
- swapCount_not?: InputMaybe;
- swapCount_not_in?: InputMaybe>;
swaps_?: InputMaybe;
- withdrawCount?: InputMaybe;
- withdrawCount_gt?: InputMaybe;
- withdrawCount_gte?: InputMaybe;
- withdrawCount_in?: InputMaybe>;
- withdrawCount_lt?: InputMaybe;
- withdrawCount_lte?: InputMaybe;
- withdrawCount_not?: InputMaybe;
- withdrawCount_not_in?: InputMaybe>;
- withdraws_?: InputMaybe;
};
export enum Account_OrderBy {
- ClosedPositionCount = 'closedPositionCount',
- DepositCount = 'depositCount',
- Deposits = 'deposits',
+ Burns = 'burns',
Id = 'id',
- OpenPositionCount = 'openPositionCount',
- PositionCount = 'positionCount',
+ Mints = 'mints',
Positions = 'positions',
- SwapCount = 'swapCount',
- Swaps = 'swaps',
- WithdrawCount = 'withdrawCount',
- Withdraws = 'withdraws'
+ Swaps = 'swaps'
}
-export type ActiveAccount = {
- __typename?: 'ActiveAccount';
- /** { daily/hourly }-{ Address of the account }-{ Days/hours since Unix epoch } */
+export type BlockChangedFilter = {
+ number_gte: Scalars['Int']['input'];
+};
+
+export type Block_Height = {
+ hash?: InputMaybe;
+ number?: InputMaybe;
+ number_gte?: InputMaybe;
+};
+
+export type Bundle = {
+ __typename?: 'Bundle';
+ ethPriceUSD: Scalars['BigDecimal']['output'];
id: Scalars['ID']['output'];
};
-export type ActiveAccount_Filter = {
+export type Bundle_Filter = {
/** Filter for the block changed event. */
_change_block?: InputMaybe;
- and?: InputMaybe>>;
+ and?: InputMaybe>>;
+ ethPriceUSD?: InputMaybe;
+ ethPriceUSD_gt?: InputMaybe;
+ ethPriceUSD_gte?: InputMaybe;
+ ethPriceUSD_in?: InputMaybe>;
+ ethPriceUSD_lt?: InputMaybe;
+ ethPriceUSD_lte?: InputMaybe;
+ ethPriceUSD_not?: InputMaybe;
+ ethPriceUSD_not_in?: InputMaybe>;
id?: InputMaybe;
id_gt?: InputMaybe;
id_gte?: InputMaybe;
@@ -179,123 +133,53 @@ export type ActiveAccount_Filter = {
id_lte?: InputMaybe;
id_not?: InputMaybe;
id_not_in?: InputMaybe>;
- or?: InputMaybe>>;
+ or?: InputMaybe>>;
};
-export enum ActiveAccount_OrderBy {
+export enum Bundle_OrderBy {
+ EthPriceUsd = 'ethPriceUSD',
Id = 'id'
}
-export enum Aggregation_Interval {
- Day = 'day',
- Hour = 'hour'
-}
-
-export type BlockChangedFilter = {
- number_gte: Scalars['Int']['input'];
-};
-
-export type Block_Height = {
- hash?: InputMaybe;
- number?: InputMaybe;
- number_gte?: InputMaybe;
-};
-
-/**
- * An event is any user action that occurs in a protocol. Generally, they are Ethereum events
- * emitted by a function in the smart contracts, stored in transaction receipts as event logs.
- * However, some user actions of interest are function calls that don't emit events. For example,
- * the deposit and withdraw functions in Yearn do not emit any events. In our subgraphs, we still
- * store them as events, although they are not technically Ethereum events emitted by smart
- * contracts.
- *
- */
-export type Deposit = {
- __typename?: 'Deposit';
- /** Account that emitted this event */
- account: Account;
- /** USD-normalized value of the transaction of the underlying (e.g. sum of tokens deposited into a pool) */
+export type Burn = Event & {
+ __typename?: 'Burn';
+ amount: Scalars['BigInt']['output'];
+ amount0: Scalars['BigDecimal']['output'];
+ amount1: Scalars['BigDecimal']['output'];
amountUSD: Scalars['BigDecimal']['output'];
- /** Block number of this event */
- blockNumber: Scalars['BigInt']['output'];
- /** Gas limit of the transaction that emitted this event */
- gasLimit?: Maybe;
- /** Gas price of the transaction that emitted this event */
- gasPrice?: Maybe;
- /** Gas used in this transaction. (Optional because not every chain will support this) */
- gasUsed?: Maybe;
- /** Transaction hash of the transaction that emitted this event */
- hash: Scalars['Bytes']['output'];
- /** { Transaction hash }-{ Log index } */
id: Scalars['ID']['output'];
- /** Amount of input tokens in the token's native unit */
- inputTokenAmounts: Array;
- /** Input tokens of the pool. E.g. WETH and USDC to a WETH-USDC pool */
- inputTokens: Array;
- /** Amount of liquidity minted */
- liquidity: Scalars['BigInt']['output'];
- /** Event log index. For transactions that don't emit event, create arbitrary index starting from 0 */
- logIndex: Scalars['Int']['output'];
- /** Nonce of the transaction that emitted this event */
- nonce: Scalars['BigInt']['output'];
- /** The pool involving this event */
- pool: LiquidityPool;
- /** The user position changed by this event */
- position?: Maybe;
- /** The protocol this transaction belongs to */
- protocol: DexAmmProtocol;
- /** Amount of input tokens in the liquidity pool */
- reserveAmounts?: Maybe>;
- /** lower tick of position */
- tickLower?: Maybe;
- /** upper tick of position */
- tickUpper?: Maybe;
- /** Timestamp of this event */
+ logIndex?: Maybe;
+ origin: Account;
+ owner?: Maybe;
+ pool: Pool;
+ tickLower: Scalars['BigInt']['output'];
+ tickUpper: Scalars['BigInt']['output'];
timestamp: Scalars['BigInt']['output'];
+ token0: Token;
+ token1: Token;
+ transaction: Transaction;
};
-
-/**
- * An event is any user action that occurs in a protocol. Generally, they are Ethereum events
- * emitted by a function in the smart contracts, stored in transaction receipts as event logs.
- * However, some user actions of interest are function calls that don't emit events. For example,
- * the deposit and withdraw functions in Yearn do not emit any events. In our subgraphs, we still
- * store them as events, although they are not technically Ethereum events emitted by smart
- * contracts.
- *
- */
-export type DepositInputTokensArgs = {
- first?: InputMaybe;
- orderBy?: InputMaybe;
- orderDirection?: InputMaybe;
- skip?: InputMaybe;
- where?: InputMaybe;
-};
-
-export type Deposit_Filter = {
+export type Burn_Filter = {
/** Filter for the block changed event. */
_change_block?: InputMaybe;
- account?: InputMaybe;
- account_?: InputMaybe;
- account_contains?: InputMaybe;
- account_contains_nocase?: InputMaybe;
- account_ends_with?: InputMaybe;
- account_ends_with_nocase?: InputMaybe;
- account_gt?: InputMaybe;
- account_gte?: InputMaybe;
- account_in?: InputMaybe>;
- account_lt?: InputMaybe;
- account_lte?: InputMaybe;
- account_not?: InputMaybe;
- account_not_contains?: InputMaybe;
- account_not_contains_nocase?: InputMaybe;
- account_not_ends_with?: InputMaybe;
- account_not_ends_with_nocase?: InputMaybe;
- account_not_in?: InputMaybe>;
- account_not_starts_with?: InputMaybe;
- account_not_starts_with_nocase?: InputMaybe;
- account_starts_with?: InputMaybe;
- account_starts_with_nocase?: InputMaybe;
+ amount?: InputMaybe;
+ amount0?: InputMaybe;
+ amount0_gt?: InputMaybe;
+ amount0_gte?: InputMaybe;
+ amount0_in?: InputMaybe>;
+ amount0_lt?: InputMaybe;
+ amount0_lte?: InputMaybe;
+ amount0_not?: InputMaybe;
+ amount0_not_in?: InputMaybe>;
+ amount1?: InputMaybe;
+ amount1_gt?: InputMaybe;
+ amount1_gte?: InputMaybe;
+ amount1_in?: InputMaybe>;
+ amount1_lt?: InputMaybe;
+ amount1_lte?: InputMaybe;
+ amount1_not?: InputMaybe;
+ amount1_not_in?: InputMaybe>;
amountUSD?: InputMaybe;
amountUSD_gt?: InputMaybe;
amountUSD_gte?: InputMaybe;
@@ -304,49 +188,14 @@ export type Deposit_Filter = {
amountUSD_lte?: InputMaybe;
amountUSD_not?: InputMaybe;
amountUSD_not_in?: InputMaybe>;
- and?: InputMaybe>>;
- blockNumber?: InputMaybe;
- blockNumber_gt?: InputMaybe;
- blockNumber_gte?: InputMaybe;
- blockNumber_in?: InputMaybe>;
- blockNumber_lt?: InputMaybe;
- blockNumber_lte?: InputMaybe;
- blockNumber_not?: InputMaybe;
- blockNumber_not_in?: InputMaybe>;
- gasLimit?: InputMaybe;
- gasLimit_gt?: InputMaybe;
- gasLimit_gte?: InputMaybe;
- gasLimit_in?: InputMaybe