From 230c848d4a3898d280fd83346404ba654b2f0d75 Mon Sep 17 00:00:00 2001 From: Ulysse Ramage Date: Thu, 12 Sep 2024 19:17:06 +0200 Subject: [PATCH] fix: update pool fee upon first liquidity add (#159) * fix: update pool fee upon first liquidity add * fix: type * fix: comment added --------- Co-authored-by: matstyler --- src/mappings/amm.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mappings/amm.ts b/src/mappings/amm.ts index d7feb5b..6f8f35c 100644 --- a/src/mappings/amm.ts +++ b/src/mappings/amm.ts @@ -15,7 +15,11 @@ import { getAccount } from "../entities/Account" import { updateAccountAssetBalance } from "../entities/AccountAsset" import { getAsset } from "../entities/Asset" import { getAssetAmount } from "../entities/AssetAmount" -import { getPoolLastPrices, getPoolLPToken } from "../entities/CurvePool" +import { + getPoolFee, + getPoolLastPrices, + getPoolLPToken, +} from "../entities/CurvePool" import { getERC20Decimals, getERC20TotalSupply } from "../entities/ERC20" import { updateFutureDailyStats } from "../entities/FutureDailyStats" import { createTransaction } from "../entities/Transaction" @@ -138,6 +142,14 @@ export function handleAddLiquidity(event: AddLiquidity): void { pool.totalFees = pool.totalFees.plus(fee) pool.totalAdminFees = pool.totalAdminFees.plus(adminFee) + // In case of no liquidity, the fee() will revert on the "CurvePoolDeployed" event so we have to set the fee rate here + if ( + poolIBTAssetAmount.amount.equals(ZERO_BI) && + poolPTAssetAmount.amount.equals(ZERO_BI) + ) { + pool.feeRate = getPoolFee(Address.fromBytes(pool.address)) + } + pool.save() poolIBTAssetAmount.amount = poolIBTAssetAmount.amount.plus(