Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/indexer/indexer-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ ponder.on("Airlock:Migrate", async ({ event, context }) => {
migratorAddress,
assetAddress: assetId,
numeraireAddress: assetEntity.numeraire,
migrationPoolAddress,
parentPoolAddress: parentPool.address,
timestamp,
context,
Expand Down
3 changes: 3 additions & 0 deletions src/indexer/shared/entities/v4pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,15 @@ export const insertV4MigrationPoolIfNotExists = async ({
migratorAddress,
assetAddress,
numeraireAddress,
migrationPoolAddress,
parentPoolAddress,
timestamp,
context,
}: {
migratorAddress: Address;
assetAddress: Address;
numeraireAddress: Address;
migrationPoolAddress: Address;
parentPoolAddress: Address;
timestamp: bigint;
context: Context;
Expand All @@ -256,6 +258,7 @@ export const insertV4MigrationPoolIfNotExists = async ({
migratorAddress,
assetAddress,
numeraireAddress,
migrationPoolAddress,
timestamp,
context,
});
Expand Down
4 changes: 2 additions & 2 deletions src/indexer/shared/swap-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export function processSwapCalculations(
dollarLiquidity,
marketCapUsd: 0n, // Will be calculated after token fetch
swapValueUsd,
nextReserves0: reserves0 - amount0,
nextReserves1: reserves1 - amount1,
nextReserves0: reserves0 + amount0,
nextReserves1: reserves1 + amount1,
fee0,
fee1,
swapType,
Expand Down
45 changes: 22 additions & 23 deletions src/utils/v4-utils/getV4MigrationPoolData.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Address } from "viem";
import { Context } from "ponder:registry";
import { V4MigratorABI, V4MigratorABILegacy, StateViewABI } from "@app/abis";
import { V4MigratorABI, V4MigratorABILegacy, StateViewABI, DERC20ABI } from "@app/abis";
import { PoolKey, Slot0Data } from "@app/types/v4-types";
import { getPoolId } from "./getPoolId";
import { computeV4Price } from "./computeV4Price";
import { chainConfigs } from "@app/config";
import { getQuoteInfo, QuoteInfo } from "@app/utils/getQuoteInfo";
import { getAssetData } from "@app/utils/getAssetData";
import { zeroAddress } from "viem";
import { getAmount0Delta, getAmount1Delta } from "@app/utils/v3-utils/computeGraduationThreshold";

export interface BeneficiaryData {
beneficiary: Address;
Expand Down Expand Up @@ -93,12 +92,14 @@ export const getV4MigrationPoolData = async ({
migratorAddress,
assetAddress,
numeraireAddress,
migrationPoolAddress,
timestamp,
context,
}: {
migratorAddress: Address;
assetAddress: Address;
numeraireAddress: Address;
migrationPoolAddress: Address;
timestamp: bigint;
context: Context;
}): Promise<V4MigrationPoolData> => {
Expand Down Expand Up @@ -160,28 +161,26 @@ export const getV4MigrationPoolData = async ({
quoteTokenDecimals: quoteInfo.quoteDecimals,
});

const MIN_TICK = -887270;
const MAX_TICK = 887270;
const currentTick = slot0Data.tick;

let reserves0 = 0n;
let reserves1 = 0n;

if (liquidity > 0n) {
reserves0 = getAmount0Delta({
tickLower: currentTick,
tickUpper: MAX_TICK,
liquidity,
roundUp: false,
});
// Fetch actual reserves from the migration pool (V3 pool where liquidity resides)
const [r0, r1] = await client.multicall({
contracts: [
{
abi: DERC20ABI,
address: poolKey.currency0,
functionName: "balanceOf",
args: [migrationPoolAddress],
},
{
abi: DERC20ABI,
address: poolKey.currency1,
functionName: "balanceOf",
args: [migrationPoolAddress],
},
],
});

reserves1 = getAmount1Delta({
tickLower: MIN_TICK,
tickUpper: currentTick,
liquidity,
roundUp: false,
});
}
const reserves0 = r0?.result ?? 0n;
const reserves1 = r1?.result ?? 0n;

return {
poolKey,
Expand Down
Loading