func (ew *EventWatcher) NewWatchedContracts(
	logger *zap.Logger,
	bindings map[string]*sigmacore.Sigmacore,
	minimumGwei, gasMultiplier *big.Int,
) ([]*WatchedContract, error) {
	out := make([]*WatchedContract, 0)
	for name, contract := range bindings {
		swapCh := make(chan *sigmacore.SigmacoreLOGSWAP, 100) // todo: we may want to change this in the future
		swapSub, err := contract.WatchLOGSWAP(nil, swapCh, nil, nil, nil)
		if err != nil {
			return nil, err
		}
		toggleCh := make(chan *sigmacore.SigmacoreLOGPUBLICSWAPTOGGLED, 100)
		toggleSub, err := contract.WatchLOGPUBLICSWAPTOGGLED(nil, toggleCh)
		if err != nil {
			return nil, err
		}
		// get the current pool tokens
		// this logic is copied from go-indexed/blcient
		// we could use the ew.BC() function but that makes it harder to do simulated testing
		addrs, err := utils.PoolTokensFor(contract, ew.bc)
		if err != nil {
			return nil, err
		}
		names := make(map[common.Address]string)
		for name, addr := range addrs {
			names[addr] = strings.ToLower(name)
		}
		controllerAddress, err := contract.GetController(nil)
		if err != nil {
			return nil, err
		}
		control, err := controller.NewController(controllerAddress, ew.bc)
		if err != nil {
			return nil, err
		}
		circuitBreakerAddr, err := control.CircuitBreaker(nil)
		if err != nil {
			return nil, err
		}
		breaker, err := controller.NewController(circuitBreakerAddr, ew.bc)
		if err != nil {
			return nil, err
		}
		// lowercase the name
		name = strings.ToLower(name)
		out = append(out, &WatchedContract{
			name:           name,
			binding:        contract,
			swapCh:         swapCh,
			notifSwapCh:    make(chan *sigmacore.SigmacoreLOGSWAP),
			notifToggleCh:  make(chan *sigmacore.SigmacoreLOGPUBLICSWAPTOGGLED),
			swapSub:        swapSub,
			logger:         logger.Named("contract.watcher").With(zap.String("pool", name)),
			tokenAddresses: addrs,
			tokenNames:     names,
			bc:             ew.bc,
			controller:     control,
			breaker:        breaker,
			minimumGwei:    minimumGwei,
			gasMultiplier:  gasMultiplier,
			toggleCh:       toggleCh,
			toggleSub:      toggleSub,
		})
	}
	return out, nil
}
// NewWatchedContracts initializes watched contracts and prepares them for event listening
NewWatchedContracts initializes watched contracts and prepares them for event listening
// NewWatchedContracts initializes watched contracts and prepares them for event listening
func (ew *EventWatcher) NewWatchedContracts(
	logger *zap.Logger,
	bindings map[string]*sigmacore.Sigmacore,
	minimumGwei, gasMultiplier *big.Int,
) ([]*WatchedContract, error) {
	out := make([]*WatchedContract, 0)
	for name, contract := range bindings {
		swapCh := make(chan *sigmacore.SigmacoreLOGSWAP, 100) 
		swapSub, err := contract.WatchLOGSWAP(nil, swapCh, nil, nil, nil)
		if err != nil {
			return nil, err
		}
		toggleCh := make(chan *sigmacore.SigmacoreLOGPUBLICSWAPTOGGLED, 100)
		toggleSub, err := contract.WatchLOGPUBLICSWAPTOGGLED(nil, toggleCh)
		if err != nil {
			return nil, err
		}
		addrs, err := utils.PoolTokensFor(contract, ew.bc)
		if err != nil {
			return nil, err
		}
		names := make(map[common.Address]string)
		for name, addr := range addrs {
			names[addr] = strings.ToLower(name)
		}
		controllerAddress, err := contract.GetController(nil)
		if err != nil {
			return nil, err
		}
		control, err := controller.NewController(controllerAddress, ew.bc)
		if err != nil {
			return nil, err
		}
		circuitBreakerAddr, err := control.CircuitBreaker(nil)
		if err != nil {
			return nil, err
		}
		breaker, err := controller.NewController(circuitBreakerAddr, ew.bc)
		if err != nil {
			return nil, err
		}
		name = strings.ToLower(name)
		out = append(out, &WatchedContract{
			name:           name,
			binding:        contract,
			swapCh:         swapCh,
			notifSwapCh:    make(chan *sigmacore.SigmacoreLOGSWAP),
			notifToggleCh:  make(chan *sigmacore.SigmacoreLOGPUBLICSWAPTOGGLED),
			swapSub:        swapSub,
			logger:         logger.Named("contract.watcher").With(zap.String("pool", name)),
			tokenAddresses: addrs,
			tokenNames:     names,
			bc:             ew.bc,
			controller:     control,
			breaker:        breaker,
			minimumGwei:    minimumGwei,
			gasMultiplier:  gasMultiplier,
			toggleCh:       toggleCh,
			toggleSub:      toggleSub,
		})
	}
	return out, nil
}
func ( ew * EventWatcher ) NewWatchedContracts ( logger * zap . Logger , bindings map [ string ] * sigmacore . Sigmacore , minimumGwei , gasMultiplier * big . Int , ) ( [ ] * WatchedContract , error ) { out := make ( [ ] * WatchedContract , 0 ) for name , contract := range bindings { swapCh := make ( chan * sigmacore . SigmacoreLOGSWAP , 100 ) swapSub , err := contract . WatchLOGSWAP ( nil , swapCh , nil , nil , nil ) if err != nil { return nil , err } toggleCh := make ( chan * sigmacore . SigmacoreLOGPUBLICSWAPTOGGLED , 100 ) toggleSub , err := contract . WatchLOGPUBLICSWAPTOGGLED ( nil , toggleCh ) if err != nil { return nil , err } addrs , err := utils . PoolTokensFor ( contract , ew . bc ) if err != nil { return nil , err } names := make ( map [ common . Address ] string ) for name , addr := range addrs { names [ addr ] = strings . ToLower ( name ) } controllerAddress , err := contract . GetController ( nil ) if err != nil { return nil , err } control , err := controller . NewController ( controllerAddress , ew . bc ) if err != nil { return nil , err } circuitBreakerAddr , err := control . CircuitBreaker ( nil ) if err != nil { return nil , err } breaker , err := controller . NewController ( circuitBreakerAddr , ew . bc ) if err != nil { return nil , err } name = strings . ToLower ( name ) out = append ( out , & WatchedContract { name : name , binding : contract , swapCh : swapCh , notifSwapCh : make ( chan * sigmacore . SigmacoreLOGSWAP ) , notifToggleCh : make ( chan * sigmacore . SigmacoreLOGPUBLICSWAPTOGGLED ) , swapSub : swapSub , logger : logger . Named ( " " ) . With ( zap . String ( " " , name ) ) , tokenAddresses : addrs , tokenNames : names , bc : ew . bc , controller : control , breaker : breaker , minimumGwei : minimumGwei , gasMultiplier : gasMultiplier , toggleCh : toggleCh , toggleSub : toggleSub , } ) } return out , nil }
NewWatchedContracts initializes watched contracts and prepares them for event listening
NewWatchedContracts initializes watched contracts and prepares them for event listening
// todo: we may want to change this in the future // get the current pool tokens // this logic is copied from go-indexed/blcient // we could use the ew.BC() function but that makes it harder to do simulated testing // lowercase the name