import { Interface } from '@ethersproject/abi'; import { DeepReadonly } from 'ts-essentials'; import { Log, Logger } from '../../types'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { IDexHelper } from '../../dex-helper/idex-helper'; import { PoolState, PoolStateMap, Step, TokenInfo } from './types'; import { SwapKind, Vault } from '@balancer-labs/balancer-maths'; import { HookStateMap, HooksConfigMap } from './hooks/balancer-hook-event-subscriber'; export declare const WAD: bigint; export declare class BalancerV3EventPool extends StatefulEventSubscriber { readonly parentName: string; protected network: number; protected dexHelper: IDexHelper; handlers: { [event: string]: (event: any, state: DeepReadonly, log: Readonly) => DeepReadonly | null; }; logDecoder: (log: Log) => any; addressesSubscribed: string[]; interfaces: { [name: string]: Interface; }; vault: Vault; hooksConfigMap: HooksConfigMap; constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger); setHooksConfigMap(hooksConfigMap: HooksConfigMap): void; /** * The function is called every time any of the subscribed * addresses release log. The function accepts the current * state, updates the state according to the log, and returns * the updated state. * @param state - Current state of event subscriber * @param log - Log released by one of the subscribed addresses * @returns Updates state of the event subscriber after the log */ protected processLog(state: DeepReadonly, log: Readonly): DeepReadonly | null; /** * The function generates state using on-chain calls. This * function is called to regenerate state if the event based * system fails to fetch events and the local state is no * more correct. * @param blockNumber - Blocknumber for which the state should * should be generated * @returns state of the event subscriber at blocknumber */ generateState(blockNumber: number): Promise>; getUpdatedPoolState(blockNumber: number): Promise | null>; liquidityAddedEvent(event: any, state: DeepReadonly, log: Readonly): DeepReadonly | null; liquidityRemovedEvent(event: any, state: DeepReadonly, log: Readonly): DeepReadonly | null; swapEvent(event: any, state: DeepReadonly, log: Readonly): DeepReadonly | null; vaultAuxiliaryEvent(event: any, state: DeepReadonly, log: Readonly): DeepReadonly | null; poolAggregateSwapFeePercentageEvent(event: any, state: DeepReadonly, log: Readonly): DeepReadonly | null; poolSwapFeePercentageChangedEvent(event: any, state: DeepReadonly, log: Readonly): DeepReadonly | null; poolPausedStateChanged(event: any, state: DeepReadonly, log: Readonly): DeepReadonly | null; quantWeightsUpdatedEvent(event: any, state: DeepReadonly, log: Readonly): DeepReadonly | null; getMaxSwapAmount(pool: PoolState, tokenIn: TokenInfo, tokenOut: TokenInfo, swapKind: SwapKind, timestamp: number): bigint; getSwapResult(steps: Step[], amountRaw: bigint, swapKind: SwapKind, timestamp: number, hookStateMap: HookStateMap): bigint; /** * Retrieves any new pools via API/multicall and adds to state */ updateStatePools(): Promise; /** * Uses multicall to get onchain token rate for each pool then updates pool state */ updateStatePoolRates(): Promise; private getPoolRates; getTokenInfo(poolState: PoolState, tokenAddress: string): TokenInfo | null; /** * Prepares all the step data required to simulate maths and construct swap transaction. * Balancer V3 has the concepts of Boosted Pools and ERC4626 Liquidity Buffers. * These enable highly capital efficient pools and gas efficient swaps. * To swap via a buffer we must provide the correct ""steps" to the router transaction. * Wrap: e.g. USDC>aUSDC * Unwrap: e.g. aUSDC>USDC * A full swap between USDC>DAI for an example bbausd pool consisting of aDAI/aUSDC/aUSDT would look like: * USDC[wrap-buffer]aUSDC[swap-pool]aDAI[unwrap-buffer]USDC * See docs for further info: * https://docs-v3.balancer.fi/concepts/explore-available-balancer-pools/boosted-pool.html * https://docs-v3.balancer.fi/concepts/vault/buffer.html */ getSteps(pool: PoolState, tokenIn: TokenInfo, tokenOut: TokenInfo): Step[]; getWrapStep(token: TokenInfo): Step; getUnwrapStep(token: TokenInfo): Step; getSwapStep(pool: PoolState, tokenIn: TokenInfo, tokenOut: TokenInfo): Step; toScaled18(amount: bigint, scalingFactor: bigint): bigint; toScaled18ApplyRateRoundDown(amount: bigint, scalingFactor: bigint, tokenRate: bigint): bigint; mulDown(a: bigint, b: bigint): bigint; }