import { PoolKey } from '../types'; import { IDexHelper } from '../../../dex-helper'; import { Network } from '../../../constants'; import { Logger } from '../../../types'; export type HookConfig = { [network: number]: HookParams; }; export interface BalanceDelta { amount0: bigint; amount1: bigint; } export interface BeforeSwapDelta { amount0: bigint; amount1: bigint; } export interface SwapParams { zeroForOne: boolean; amountSpecified: string; sqrtPriceLimitX96: string; } export interface ModifyLiquidityParams { tickLower: number; tickUpper: number; liquidityDelta: string; salt: string; } export interface HooksPermissions { beforeInitialize: boolean; afterInitialize: boolean; beforeAddLiquidity: boolean; afterAddLiquidity: boolean; beforeRemoveLiquidity: boolean; afterRemoveLiquidity: boolean; beforeSwap: boolean; afterSwap: boolean; beforeDonate: boolean; afterDonate: boolean; beforeSwapReturnDelta: boolean; afterSwapReturnDelta: boolean; afterAddLiquidityReturnDelta: boolean; afterRemoveLiquidityReturnDelta: boolean; } export interface IBaseHook { readonly name: string; readonly address: string; getHookPermissions(): HooksPermissions; registerPool(poolId: string, poolKey: PoolKey): void; initialize(blockNumber: number): Promise; beforeInitialize?(sender: string, key: PoolKey, sqrtPriceX96: string): string; afterInitialize?(sender: string, key: PoolKey, sqrtPriceX96: string, tick: number): string; beforeAddLiquidity?(sender: string, key: PoolKey, params: ModifyLiquidityParams, hookData: string): string; beforeRemoveLiquidity?(sender: string, key: PoolKey, params: ModifyLiquidityParams, hookData: string): string; afterAddLiquidity?(sender: string, key: PoolKey, params: ModifyLiquidityParams, delta0: BalanceDelta, delta1: BalanceDelta, hookData: string): [string, BalanceDelta]; afterRemoveLiquidity?(sender: string, key: PoolKey, params: ModifyLiquidityParams, delta0: BalanceDelta, delta1: BalanceDelta, hookData: string): [string, BalanceDelta]; beforeSwap?(sender: string, key: PoolKey, params: SwapParams, hookData: string): [string, BeforeSwapDelta, number]; /** * The hook implementing this method should return the final * modified amount exactly as swapExactAmountIn/Out would return */ afterSwap?(sender: string, key: PoolKey, params: SwapParams, delta: BalanceDelta, hookData: string): bigint; beforeDonate?(sender: string, key: PoolKey, amount0: string, amount1: string, hookData: string): string; afterDonate?(sender: string, key: PoolKey, amount0: string, amount1: string, hookData: string): string; } export type HookConstructor = new (dexHelper: IDexHelper, network: Network, logger: Logger) => IBaseHook;