// Code generated by abigen. DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.

package contracts

import (
	"fmt"
	"math/big"
	"reflect"
	"strings"

	ethereum "github.com/erigontech/erigon"
	"github.com/erigontech/erigon/common"
	"github.com/erigontech/erigon/execution/abi"
	"github.com/erigontech/erigon/execution/abi/bind"
	"github.com/erigontech/erigon/execution/types"
	"github.com/erigontech/erigon/p2p/event"
)

// Reference imports to suppress errors if they are not otherwise used.
var (
	_ = big.NewInt
	_ = strings.NewReader
	_ = ethereum.NotFound
	_ = bind.Bind
	_ = common.Big1
	_ = types.BloomLookup
	_ = event.NewSubscription
	_ = fmt.Errorf
	_ = reflect.ValueOf
)

// PolyABI is the input ABI used to generate the binding from.
const PolyABI = "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"d\",\"type\":\"address\"}],\"name\":\"DeployEvent\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"salt\",\"type\":\"uint256\"}],\"name\":\"deploy\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"

// PolyBin is the compiled bytecode used for deploying new contracts.
var PolyBin = "0x6080604052348015600f57600080fd5b5060f88061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063a5e3875114602d575b600080fd5b604760048036036020811015604157600080fd5b50356049565b005b6040805180820190915260138082527260606000534360015360ff60025360036000f360681b60208301908152600091849183f5604080516001600160a01b038316815290519192507f68f6a0f063c25c6678c443b9a484086f15ba8f91f60218695d32a5251f2050eb919081900360200190a150505056fea264697066735822122032d356806c978fb0bf45bc0b927ecf2af1ebbc7036396fe43793a0d0a312cac164736f6c63430007020033"

// DeployPoly deploys a new Ethereum contract, binding an instance of Poly to it.
func DeployPoly(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, types.Transaction, *Poly, error) {
	parsed, err := abi.JSON(strings.NewReader(PolyABI))
	if err != nil {
		return common.Address{}, nil, nil, err
	}

	address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(PolyBin), backend)
	if err != nil {
		return common.Address{}, nil, nil, err
	}
	return address, tx, &Poly{PolyCaller: PolyCaller{contract: contract}, PolyTransactor: PolyTransactor{contract: contract}, PolyFilterer: PolyFilterer{contract: contract}}, nil
}

// Poly is an auto generated Go binding around an Ethereum contract.
type Poly struct {
	PolyCaller     // Read-only binding to the contract
	PolyTransactor // Write-only binding to the contract
	PolyFilterer   // Log filterer for contract events
}

// PolyCaller is an auto generated read-only Go binding around an Ethereum contract.
type PolyCaller struct {
	contract *bind.BoundContract // Generic contract wrapper for the low level calls
}

// PolyTransactor is an auto generated write-only Go binding around an Ethereum contract.
type PolyTransactor struct {
	contract *bind.BoundContract // Generic contract wrapper for the low level calls
}

// PolyFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
type PolyFilterer struct {
	contract *bind.BoundContract // Generic contract wrapper for the low level calls
}

// PolySession is an auto generated Go binding around an Ethereum contract,
// with pre-set call and transact options.
type PolySession struct {
	Contract     *Poly             // Generic contract binding to set the session for
	CallOpts     bind.CallOpts     // Call options to use throughout this session
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

// PolyCallerSession is an auto generated read-only Go binding around an Ethereum contract,
// with pre-set call options.
type PolyCallerSession struct {
	Contract *PolyCaller   // Generic contract caller binding to set the session for
	CallOpts bind.CallOpts // Call options to use throughout this session
}

// PolyTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
// with pre-set transact options.
type PolyTransactorSession struct {
	Contract     *PolyTransactor   // Generic contract transactor binding to set the session for
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

// PolyRaw is an auto generated low-level Go binding around an Ethereum contract.
type PolyRaw struct {
	Contract *Poly // Generic contract binding to access the raw methods on
}

// PolyCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
type PolyCallerRaw struct {
	Contract *PolyCaller // Generic read-only contract binding to access the raw methods on
}

// PolyTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
type PolyTransactorRaw struct {
	Contract *PolyTransactor // Generic write-only contract binding to access the raw methods on
}

// NewPoly creates a new instance of Poly, bound to a specific deployed contract.
func NewPoly(address common.Address, backend bind.ContractBackend) (*Poly, error) {
	contract, err := bindPoly(address, backend, backend, backend)
	if err != nil {
		return nil, err
	}
	return &Poly{PolyCaller: PolyCaller{contract: contract}, PolyTransactor: PolyTransactor{contract: contract}, PolyFilterer: PolyFilterer{contract: contract}}, nil
}

// NewPolyCaller creates a new read-only instance of Poly, bound to a specific deployed contract.
func NewPolyCaller(address common.Address, caller bind.ContractCaller) (*PolyCaller, error) {
	contract, err := bindPoly(address, caller, nil, nil)
	if err != nil {
		return nil, err
	}
	return &PolyCaller{contract: contract}, nil
}

// NewPolyTransactor creates a new write-only instance of Poly, bound to a specific deployed contract.
func NewPolyTransactor(address common.Address, transactor bind.ContractTransactor) (*PolyTransactor, error) {
	contract, err := bindPoly(address, nil, transactor, nil)
	if err != nil {
		return nil, err
	}
	return &PolyTransactor{contract: contract}, nil
}

// NewPolyFilterer creates a new log filterer instance of Poly, bound to a specific deployed contract.
func NewPolyFilterer(address common.Address, filterer bind.ContractFilterer) (*PolyFilterer, error) {
	contract, err := bindPoly(address, nil, nil, filterer)
	if err != nil {
		return nil, err
	}
	return &PolyFilterer{contract: contract}, nil
}

// bindPoly binds a generic wrapper to an already deployed contract.
func bindPoly(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
	parsed, err := abi.JSON(strings.NewReader(PolyABI))
	if err != nil {
		return nil, err
	}
	return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
}

// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_Poly *PolyRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
	return _Poly.Contract.PolyCaller.contract.Call(opts, result, method, params...)
}

// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_Poly *PolyRaw) Transfer(opts *bind.TransactOpts) (types.Transaction, error) {
	return _Poly.Contract.PolyTransactor.contract.Transfer(opts)
}

// Transact invokes the (paid) contract method with params as input values.
func (_Poly *PolyRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (types.Transaction, error) {
	return _Poly.Contract.PolyTransactor.contract.Transact(opts, method, params...)
}

// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_Poly *PolyCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
	return _Poly.Contract.contract.Call(opts, result, method, params...)
}

// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_Poly *PolyTransactorRaw) Transfer(opts *bind.TransactOpts) (types.Transaction, error) {
	return _Poly.Contract.contract.Transfer(opts)
}

// Transact invokes the (paid) contract method with params as input values.
func (_Poly *PolyTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (types.Transaction, error) {
	return _Poly.Contract.contract.Transact(opts, method, params...)
}

// Deploy is a paid mutator transaction binding the contract method 0xa5e38751.
//
// Solidity: function deploy(uint256 salt) returns()
func (_Poly *PolyTransactor) Deploy(opts *bind.TransactOpts, salt *big.Int) (types.Transaction, error) {
	return _Poly.contract.Transact(opts, "deploy", salt)
}

// Deploy is a paid mutator transaction binding the contract method 0xa5e38751.
//
// Solidity: function deploy(uint256 salt) returns()
func (_Poly *PolySession) Deploy(salt *big.Int) (types.Transaction, error) {
	return _Poly.Contract.Deploy(&_Poly.TransactOpts, salt)
}

// Deploy is a paid mutator transaction binding the contract method 0xa5e38751.
//
// Solidity: function deploy(uint256 salt) returns()
func (_Poly *PolyTransactorSession) Deploy(salt *big.Int) (types.Transaction, error) {
	return _Poly.Contract.Deploy(&_Poly.TransactOpts, salt)
}

// PolyDeployParams is an auto generated read-only Go binding of transcaction calldata params
type PolyDeployParams struct {
	Param_salt *big.Int
}

// Parse Deploy method from calldata of a transaction
//
// Solidity: function deploy(uint256 salt) returns()
func ParsePolyDeployParams(calldata []byte) (*PolyDeployParams, error) {
	if len(calldata) <= 4 {
		return nil, fmt.Errorf("invalid calldata input")
	}

	_abi, err := abi.JSON(strings.NewReader(PolyABI))
	if err != nil {
		return nil, fmt.Errorf("failed to get abi of registry metadata: %w", err)
	}

	out, err := _abi.Methods["deploy"].Inputs.Unpack(calldata[4:])
	if err != nil {
		return nil, fmt.Errorf("failed to unpack deploy params data: %w", err)
	}

	var paramsResult = new(PolyDeployParams)
	value := reflect.ValueOf(paramsResult).Elem()

	if value.NumField() != len(out) {
		return nil, fmt.Errorf("failed to match calldata with param field number")
	}

	out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)

	return &PolyDeployParams{
		Param_salt: out0,
	}, nil
}

// PolyDeployEventIterator is returned from FilterDeployEvent and is used to iterate over the raw logs and unpacked data for DeployEvent events raised by the Poly contract.
type PolyDeployEventIterator struct {
	Event *PolyDeployEvent // Event containing the contract specifics and raw log

	contract *bind.BoundContract // Generic contract to use for unpacking event data
	event    string              // Event name to use for unpacking event data

	logs chan types.Log        // Log channel receiving the found contract events
	sub  ethereum.Subscription // Subscription for errors, completion and termination
	done bool                  // Whether the subscription completed delivering logs
	fail error                 // Occurred error to stop iteration
}

// Next advances the iterator to the subsequent event, returning whether there
// are any more events found. In case of a retrieval or parsing error, false is
// returned and Error() can be queried for the exact failure.
func (it *PolyDeployEventIterator) Next() bool {
	// If the iterator failed, stop iterating
	if it.fail != nil {
		return false
	}
	// If the iterator completed, deliver directly whatever's available
	if it.done {
		select {
		case log := <-it.logs:
			it.Event = new(PolyDeployEvent)
			if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
				it.fail = err
				return false
			}
			it.Event.Raw = log
			return true

		default:
			return false
		}
	}
	// Iterator still in progress, wait for either a data or an error event
	select {
	case log := <-it.logs:
		it.Event = new(PolyDeployEvent)
		if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil {
			it.fail = err
			return false
		}
		it.Event.Raw = log
		return true

	case err := <-it.sub.Err():
		it.done = true
		it.fail = err
		return it.Next()
	}
}

// Error returns any retrieval or parsing error occurred during filtering.
func (it *PolyDeployEventIterator) Error() error {
	return it.fail
}

// Close terminates the iteration process, releasing any pending underlying
// resources.
func (it *PolyDeployEventIterator) Close() error {
	it.sub.Unsubscribe()
	return nil
}

// PolyDeployEvent represents a DeployEvent event raised by the Poly contract.
type PolyDeployEvent struct {
	D   common.Address
	Raw types.Log // Blockchain specific contextual infos
}

func (_Poly *PolyFilterer) DeployEventEventID() common.Hash {
	return common.HexToHash("0x68f6a0f063c25c6678c443b9a484086f15ba8f91f60218695d32a5251f2050eb")
}

// FilterDeployEvent is a free log retrieval operation binding the contract event 0x68f6a0f063c25c6678c443b9a484086f15ba8f91f60218695d32a5251f2050eb.
//
// Solidity: event DeployEvent(address d)
func (_Poly *PolyFilterer) FilterDeployEvent(opts *bind.FilterOpts) (*PolyDeployEventIterator, error) {

	logs, sub, err := _Poly.contract.FilterLogs(opts, "DeployEvent")
	if err != nil {
		return nil, err
	}
	return &PolyDeployEventIterator{contract: _Poly.contract, event: "DeployEvent", logs: logs, sub: sub}, nil
}

// WatchDeployEvent is a free log subscription operation binding the contract event 0x68f6a0f063c25c6678c443b9a484086f15ba8f91f60218695d32a5251f2050eb.
//
// Solidity: event DeployEvent(address d)
func (_Poly *PolyFilterer) WatchDeployEvent(opts *bind.WatchOpts, sink chan<- *PolyDeployEvent) (event.Subscription, error) {

	logs, sub, err := _Poly.contract.WatchLogs(opts, "DeployEvent")
	if err != nil {
		return nil, err
	}
	return event.NewSubscription(func(quit <-chan struct{}) error {
		defer sub.Unsubscribe()
		for {
			select {
			case log := <-logs:
				// New log arrived, parse the event and forward to the user
				event := new(PolyDeployEvent)
				if err := _Poly.contract.UnpackLog(event, "DeployEvent", log); err != nil {
					return err
				}
				event.Raw = log

				select {
				case sink <- event:
				case err := <-sub.Err():
					return err
				case <-quit:
					return nil
				}
			case err := <-sub.Err():
				return err
			case <-quit:
				return nil
			}
		}
	}), nil
}

// ParseDeployEvent is a log parse operation binding the contract event 0x68f6a0f063c25c6678c443b9a484086f15ba8f91f60218695d32a5251f2050eb.
//
// Solidity: event DeployEvent(address d)
func (_Poly *PolyFilterer) ParseDeployEvent(log types.Log) (*PolyDeployEvent, error) {
	event := new(PolyDeployEvent)
	if err := _Poly.contract.UnpackLog(event, "DeployEvent", log); err != nil {
		return nil, err
	}
	event.Raw = log
	return event, nil
}
