@@ -6,8 +6,11 @@ import {
66 LiquidityAddedToBuffer ,
77 LiquidityRemoved ,
88 LiquidityRemovedFromBuffer ,
9+ PoolPausedStateChanged ,
10+ PoolRecoveryModeStateChanged ,
911 PoolRegistered ,
1012 Swap as SwapEvent ,
13+ SwapFeePercentageChanged ,
1114 Unwrap ,
1215 Wrap ,
1316} from "../types/Vault/Vault" ;
@@ -37,7 +40,7 @@ import { BPT } from "../types/templates";
3740import { ERC20 } from "../types/Vault/ERC20" ;
3841import { VaultExtension } from "../types/Vault/VaultExtension" ;
3942import { ERC4626 } from "../types/Vault/ERC4626" ;
40- import { computeAggregateSwapFee } from "../helpers/math" ;
43+ import { mulDownSwapFee } from "../helpers/math" ;
4144
4245/************************************
4346 ******* POOLS REGISTRATIONS ********
@@ -54,6 +57,8 @@ export function handlePoolRegistered(event: PoolRegistered): void {
5457 pool . pauseWindowEndTime = event . params . pauseWindowEndTime ;
5558 pool . totalShares = ZERO_BD ;
5659 pool . isInitialized = false ;
60+ pool . isInRecoveryMode = false ;
61+ pool . isPaused = false ;
5762 pool . swapsCount = ZERO_BI ;
5863 pool . holdersCount = ZERO_BI ;
5964 pool . protocolSwapFee = vault . protocolSwapFee ;
@@ -189,10 +194,7 @@ export function handleLiquidityAdded(event: LiquidityAdded): void {
189194 ) ;
190195
191196 let aggregateSwapFeeAmount = scaleDown (
192- computeAggregateSwapFee (
193- event . params . swapFeeAmountsRaw [ i ] ,
194- pool . protocolSwapFee
195- ) ,
197+ mulDownSwapFee ( event . params . swapFeeAmountsRaw [ i ] , pool . protocolSwapFee ) ,
196198 poolToken . decimals
197199 ) ;
198200
@@ -259,10 +261,7 @@ export function handleLiquidityRemoved(event: LiquidityRemoved): void {
259261 ) ;
260262
261263 let aggregateSwapFeeAmount = scaleDown (
262- computeAggregateSwapFee (
263- event . params . swapFeeAmountsRaw [ i ] ,
264- pool . protocolSwapFee
265- ) ,
264+ mulDownSwapFee ( event . params . swapFeeAmountsRaw [ i ] , pool . protocolSwapFee ) ,
266265 poolToken . decimals
267266 ) ;
268267
@@ -331,8 +330,14 @@ export function handleSwap(event: SwapEvent): void {
331330 let swapFeeDeltaAmount = ZERO_BD ;
332331 if ( hasDynamicSwapFee ) {
333332 let swapFeeDelta = swapFeePercentage . minus ( pool . swapFee ) ;
334- swapFeeBaseAmount = tokenAmountIn . times ( pool . swapFee ) ;
335- swapFeeDeltaAmount = tokenAmountIn . times ( swapFeeDelta ) ;
333+ swapFeeBaseAmount = scaleDown (
334+ mulDownSwapFee ( event . params . amountIn , pool . swapFee ) ,
335+ tokenIn . decimals
336+ ) ;
337+ swapFeeDeltaAmount = scaleDown (
338+ mulDownSwapFee ( event . params . amountIn , swapFeeDelta ) ,
339+ tokenIn . decimals
340+ ) ;
336341 }
337342
338343 swap . pool = event . params . pool ;
@@ -369,7 +374,7 @@ export function handleSwap(event: SwapEvent): void {
369374 }
370375
371376 let aggregateSwapFeeAmount = scaleDown (
372- computeAggregateSwapFee ( event . params . swapFeeAmount , pool . protocolSwapFee ) ,
377+ mulDownSwapFee ( event . params . swapFeeAmount , pool . protocolSwapFee ) ,
373378 poolTokenIn . decimals
374379 ) ;
375380
@@ -594,3 +599,31 @@ export function handleWrap(event: Wrap): void {
594599 ) ;
595600 buffer . save ( ) ;
596601}
602+
603+ /************************************
604+ ********** POOLS STATE *************
605+ ************************************/
606+
607+ export function handleSwapFeePercentageChanged (
608+ event : SwapFeePercentageChanged
609+ ) : void {
610+ let pool = Pool . load ( event . params . pool ) as Pool ;
611+ pool . swapFee = scaleDown ( event . params . swapFeePercentage , 18 ) ;
612+ pool . save ( ) ;
613+ }
614+
615+ export function handlePoolRecoveryModeStateChanged (
616+ event : PoolRecoveryModeStateChanged
617+ ) : void {
618+ let pool = Pool . load ( event . params . pool ) as Pool ;
619+ pool . isInRecoveryMode = event . params . recoveryMode ;
620+ pool . save ( ) ;
621+ }
622+
623+ export function handlePoolPausedStateChanged (
624+ event : PoolPausedStateChanged
625+ ) : void {
626+ let pool = Pool . load ( event . params . pool ) as Pool ;
627+ pool . isPaused = event . params . paused ;
628+ pool . save ( ) ;
629+ }
0 commit comments