import { Protocol } from '@steerprotocol/sdk'; import { ProtocolDetector } from './ProtocolDetector'; // Import all ABIs from organized structure import * as Pools from '../abis/pools'; import * as Factories from '../abis/factories'; import * as Quoters from '../abis/quoters'; import * as Vaults from '../abis/vaults'; import * as Steer from '../abis/steer'; /** * AbiManager - Resolves protocol-specific ABIs * * This class provides methods to get the correct ABI for different contract types * based on the beacon name (protocol identifier). */ export class AbiManager { private protocolDetector: ProtocolDetector; constructor() { this.protocolDetector = new ProtocolDetector(); } private _getAbiArray(abiModule: any): any[] { if (Array.isArray(abiModule)) { return abiModule; } if (abiModule && abiModule.abi && Array.isArray(abiModule.abi)) { return abiModule.abi; } throw new Error('Invalid ABI module format'); } /** * Get the factory ABI for a given protocol */ getFactoryAbi(beaconName: string): any[] { if (this.protocolDetector.isAlgebraIntegralVault(beaconName)) { return this._getAbiArray(Factories.AlgebraIntegralFactory); } else if (this.protocolDetector.isAlgebraVault(beaconName)) { return this._getAbiArray(Factories.QuickSwapFactory); } else if (this.protocolDetector.isPoolSharkVault(beaconName)) { return this._getAbiArray(Factories.LimitPoolFactory); } else { return this._getAbiArray(Factories.UniswapV3Factory); } } /** * Get the pool ABI for a given protocol */ getPoolAbi(beaconName: string): any[] { if (this.protocolDetector.isAlgebraIntegralVault(beaconName)) { return this._getAbiArray(Pools.AlgebraIntegralPool); } else if (this.protocolDetector.isAlgebraVault(beaconName)) { return this._getAbiArray(Pools.IQuickSwapV3Pool); } else if (this.protocolDetector.isAlgebraUniDirectionalVault(beaconName)) { return this._getAbiArray(Pools.AlgebraV3UniDirectionalPool); } else if (this.protocolDetector.isPoolSharkVault(beaconName)) { return this._getAbiArray(Pools.LimitPool); } else if (this.protocolDetector.isMachineXV3Vault(beaconName)) { return this._getAbiArray(Pools.MachineXV3Pool); } else if (this.protocolDetector.isAerodromeVault(beaconName)) { return this._getAbiArray(Pools.AerodromV3Pool); } else { return this._getAbiArray(Pools.IUniswapV3Pool); } } /** * Get the vault ABI based on position type and upgrade status */ getVaultAbi(beaconName: string, isUpgraded = true): any[] { const isMultiPosition = beaconName.toLowerCase().indexOf('multi') > -1 || beaconName.toLowerCase().indexOf('aerodrome') > -1; if (isUpgraded) { return isMultiPosition ? this._getAbiArray(Vaults.MultiPositionLiquidityManager) : this._getAbiArray(Vaults.SinglePositionLiquidityManager); } else { return isMultiPosition ? this._getAbiArray(Vaults.MultiPositionLiquidityManagerOld) : this._getAbiArray(Vaults.SinglePostionVaultOld); } } /** * Get the QuoterV2 ABI for a given protocol */ getQuoterV2Abi(beaconName: string): any[] { const protocol = this.protocolDetector.getProtocol(beaconName); if (this.protocolDetector.isAlgebraIntegral19Vault(beaconName)) { return this._getAbiArray(Quoters.QuoterV2AlgebraIntegral19); } if (this.protocolDetector.isShadowVault(beaconName)) { return this._getAbiArray(Quoters.QuoterV2Shadow); } if (this.protocolDetector.isAlgebraIntegralVault(beaconName)) { return this._getAbiArray(Quoters.AlgebraIntegralCustomRouter); } if (protocol === Protocol.Lynex) { return this._getAbiArray(Quoters.QuoterV2Lynex); } else if (this.protocolDetector.isAlgebraVault(beaconName)) { return this._getAbiArray(Quoters.QuickSwapQuoterV2); } else if (this.protocolDetector.isThickV2Vault(beaconName)) { return this._getAbiArray(Quoters.QuoterV2Thick); } else if (this.protocolDetector.isAerodromeVault(beaconName)) { return this._getAbiArray(Quoters.QuoterV2Aerodrom); } else { return this._getAbiArray(Quoters.QuoterV2); } } /** * Get the SteerPeriphery ABI */ getSteerPeripheryAbi(): any[] { return this._getAbiArray(Steer.SteerPeriphery); } }