arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/eth/auction.go
eth/auction.goRaw
  1package eth
  2
  3import (
  4	"fmt"
  5	"math/big"
  6
  7	"github.com/ethereum/go-ethereum/accounts/abi/bind"
  8	"github.com/ethereum/go-ethereum/common"
  9	ethCommon "github.com/ethereum/go-ethereum/common"
 10	"github.com/ethereum/go-ethereum/core/types"
 11	"github.com/ethereum/go-ethereum/ethclient"
 12	HermezAuctionProtocol "github.com/hermeznetwork/hermez-node/eth/contracts/auction"
 13	"github.com/hermeznetwork/hermez-node/log"
 14)
 15
 16// AuctionConstants are the constants of the Rollup Smart Contract
 17type AuctionConstants struct {
 18	// Blocks per slot
 19	BlocksPerSlot uint8
 20	// Minimum bid when no one has bid yet
 21	InitialMinimalBidding *big.Int
 22	// First block where the first slot begins
 23	GenesisBlockNum int64
 24	// Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee
 25	// Only for test
 26	GovernanceAddress ethCommon.Address
 27	// ERC777 token with which the bids will be made
 28	TokenHEZ ethCommon.Address
 29	// HermezRollup smartcontract address
 30	HermezRollup ethCommon.Address
 31}
 32
 33// SlotState is the state of a slot
 34type SlotState struct {
 35	Forger       ethCommon.Address
 36	BidAmount    *big.Int
 37	ClosedMinBid *big.Int
 38	Fulfilled    bool
 39}
 40
 41// NewSlotState returns an empty SlotState
 42func NewSlotState() *SlotState {
 43	return &SlotState{
 44		Forger:       ethCommon.Address{},
 45		BidAmount:    big.NewInt(0),
 46		ClosedMinBid: big.NewInt(0),
 47		Fulfilled:    false,
 48	}
 49}
 50
 51// Coordinator is the details of the Coordinator identified by the forger address
 52type Coordinator struct {
 53	WithdrawalAddress ethCommon.Address
 54	URL               string
 55}
 56
 57// AuctionVariables are the variables of the Auction Smart Contract
 58type AuctionVariables struct {
 59	// Boot Coordinator Address
 60	DonationAddress *ethCommon.Address
 61	// Boot Coordinator Address
 62	BootCoordinator *ethCommon.Address
 63	// The minimum bid value in a series of 6 slots
 64	DefaultSlotSetBid [6]*big.Int
 65	// Distance (#slots) to the closest slot to which you can bid ( 2 Slots = 2 * 40 Blocks = 20 min )
 66	ClosedAuctionSlots uint16
 67	// Distance (#slots) to the farthest slot to which you can bid (30 days = 4320 slots )
 68	OpenAuctionSlots uint16
 69	// How the HEZ tokens deposited by the slot winner are distributed (Burn: 40% - Donation: 40% - HGT: 20%)
 70	AllocationRatio [3]uint16
 71	// Minimum outbid (percentage) over the previous one to consider it valid
 72	Outbidding uint16
 73	// Number of blocks at the end of a slot in which any coordinator can forge if the winner has not forged one before
 74	SlotDeadline uint8
 75}
 76
 77// AuctionState represents the state of the Rollup in the Smart Contract
 78type AuctionState struct {
 79	// Mapping to control slot state
 80	Slots map[int64]*SlotState
 81	// Mapping to control balances pending to claim
 82	PendingBalances map[ethCommon.Address]*big.Int
 83	// Mapping to register all the coordinators. The address used for the mapping is the forger address
 84	Coordinators map[ethCommon.Address]*Coordinator
 85}
 86
 87// AuctionEventNewBid is an event of the Auction Smart Contract
 88type AuctionEventNewBid struct {
 89	Slot              int64
 90	BidAmount         *big.Int
 91	CoordinatorForger ethCommon.Address
 92}
 93
 94// AuctionEventNewSlotDeadline is an event of the Auction Smart Contract
 95type AuctionEventNewSlotDeadline struct {
 96	NewSlotDeadline uint8
 97}
 98
 99// AuctionEventNewClosedAuctionSlots is an event of the Auction Smart Contract
100type AuctionEventNewClosedAuctionSlots struct {
101	NewClosedAuctionSlots uint16
102}
103
104// AuctionEventNewOutbidding is an event of the Auction Smart Contract
105type AuctionEventNewOutbidding struct {
106	NewOutbidding uint16
107}
108
109// AuctionEventNewDonationAddress is an event of the Auction Smart Contract
110type AuctionEventNewDonationAddress struct {
111	NewDonationAddress ethCommon.Address
112}
113
114// AuctionEventNewBootCoordinator is an event of the Auction Smart Contract
115type AuctionEventNewBootCoordinator struct {
116	NewBootCoordinator ethCommon.Address
117}
118
119// AuctionEventNewOpenAuctionSlots is an event of the Auction Smart Contract
120type AuctionEventNewOpenAuctionSlots struct {
121	NewOpenAuctionSlots uint16
122}
123
124// AuctionEventNewAllocationRatio is an event of the Auction Smart Contract
125type AuctionEventNewAllocationRatio struct {
126	NewAllocationRatio [3]uint16
127}
128
129// AuctionEventNewCoordinator is an event of the Auction Smart Contract
130type AuctionEventNewCoordinator struct {
131	ForgerAddress     ethCommon.Address
132	WithdrawalAddress ethCommon.Address
133	URL               string
134}
135
136// AuctionEventCoordinatorUpdated is an event of the Auction Smart Contract
137type AuctionEventCoordinatorUpdated struct {
138	ForgerAddress     ethCommon.Address
139	WithdrawalAddress ethCommon.Address
140	URL               string
141}
142
143// AuctionEventNewForgeAllocated is an event of the Auction Smart Contract
144type AuctionEventNewForgeAllocated struct {
145	Forger           ethCommon.Address
146	CurrentSlot      int64
147	BurnAmount       *big.Int
148	DonationAmount   *big.Int
149	GovernanceAmount *big.Int
150}
151
152// AuctionEventNewDefaultSlotSetBid is an event of the Auction Smart Contract
153type AuctionEventNewDefaultSlotSetBid struct {
154	SlotSet          int64
155	NewInitialMinBid *big.Int
156}
157
158// AuctionEventNewForge is an event of the Auction Smart Contract
159type AuctionEventNewForge struct {
160	Forger      ethCommon.Address
161	CurrentSlot int64
162}
163
164// AuctionEventHEZClaimed is an event of the Auction Smart Contract
165type AuctionEventHEZClaimed struct {
166	Owner  ethCommon.Address
167	Amount *big.Int
168}
169
170// AuctionEvents is the list of events in a block of the Auction Smart Contract
171type AuctionEvents struct { //nolint:structcheck
172	NewBid                []AuctionEventNewBid
173	NewSlotDeadline       []AuctionEventNewSlotDeadline
174	NewClosedAuctionSlots []AuctionEventNewClosedAuctionSlots
175	NewOutbidding         []AuctionEventNewOutbidding
176	NewDonationAddress    []AuctionEventNewDonationAddress
177	NewBootCoordinator    []AuctionEventNewBootCoordinator
178	NewOpenAuctionSlots   []AuctionEventNewOpenAuctionSlots
179	NewAllocationRatio    []AuctionEventNewAllocationRatio
180	NewCoordinator        []AuctionEventNewCoordinator
181	CoordinatorUpdated    []AuctionEventCoordinatorUpdated
182	NewForgeAllocated     []AuctionEventNewForgeAllocated
183	NewDefaultSlotSetBid  []AuctionEventNewDefaultSlotSetBid
184	NewForge              []AuctionEventNewForge
185	HEZClaimed            []AuctionEventHEZClaimed
186}
187
188// NewAuctionEvents creates an empty AuctionEvents with the slices initialized.
189func NewAuctionEvents() AuctionEvents {
190	return AuctionEvents{
191		NewBid:                make([]AuctionEventNewBid, 0),
192		NewSlotDeadline:       make([]AuctionEventNewSlotDeadline, 0),
193		NewClosedAuctionSlots: make([]AuctionEventNewClosedAuctionSlots, 0),
194		NewOutbidding:         make([]AuctionEventNewOutbidding, 0),
195		NewDonationAddress:    make([]AuctionEventNewDonationAddress, 0),
196		NewBootCoordinator:    make([]AuctionEventNewBootCoordinator, 0),
197		NewOpenAuctionSlots:   make([]AuctionEventNewOpenAuctionSlots, 0),
198		NewAllocationRatio:    make([]AuctionEventNewAllocationRatio, 0),
199		NewCoordinator:        make([]AuctionEventNewCoordinator, 0),
200		CoordinatorUpdated:    make([]AuctionEventCoordinatorUpdated, 0),
201		NewForgeAllocated:     make([]AuctionEventNewForgeAllocated, 0),
202		NewDefaultSlotSetBid:  make([]AuctionEventNewDefaultSlotSetBid, 0),
203		NewForge:              make([]AuctionEventNewForge, 0),
204		HEZClaimed:            make([]AuctionEventHEZClaimed, 0),
205	}
206}
207
208// AuctionInterface is the inteface to to Auction Smart Contract
209type AuctionInterface interface {
210	//
211	// Smart Contract Methods
212	//
213
214	// Getter/Setter, where Setter is onlyOwner
215	AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error)
216	AuctionGetSlotDeadline() (uint8, error)
217	AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error)
218	AuctionGetOpenAuctionSlots() (uint16, error)
219	AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error)
220	AuctionGetClosedAuctionSlots() (uint16, error)
221	AuctionSetOutbidding(newOutbidding uint16) (*types.Transaction, error)
222	AuctionGetOutbidding() (uint16, error)
223	AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (*types.Transaction, error)
224	AuctionGetAllocationRatio() ([3]uint16, error)
225	AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error)
226	AuctionGetDonationAddress() (*ethCommon.Address, error)
227	AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error)
228	AuctionGetBootCoordinator() (*ethCommon.Address, error)
229	AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error)
230
231	// Coordinator Management
232	AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error)
233	AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error)
234	AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error)
235
236	// Slot Info
237	AuctionGetCurrentSlotNumber() (int64, error)
238	AuctionGetMinBidBySlot(slot int64) (*big.Int, error)
239	AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error)
240
241	// Bidding
242	// AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int,
243	// 	userData, operatorData []byte) error // Only called from another smart contract
244	AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error)
245	AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool,
246		maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
247
248	// Forge
249	AuctionCanForge(forger ethCommon.Address, blockNumber *big.Int) (bool, error)
250	// AuctionForge(forger ethCommon.Address) (bool, error) // Only called from another smart contract
251
252	// Fees
253	AuctionClaimHEZ(claimAddress common.Address) (*types.Transaction, error)
254
255	//
256	// Smart Contract Status
257	//
258
259	AuctionConstants() (*AuctionConstants, error)
260	AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error)
261}
262
263//
264// Implementation
265//
266
267// AuctionClient is the implementation of the interface to the Auction Smart Contract in ethereum.
268type AuctionClient struct {
269	client  *EthereumClient
270	address ethCommon.Address
271}
272
273// NewAuctionClient creates a new AuctionClient
274func NewAuctionClient(client *EthereumClient, address ethCommon.Address) *AuctionClient {
275	return &AuctionClient{
276		client:  client,
277		address: address,
278	}
279}
280
281// AuctionSetSlotDeadline is the interface to call the smart contract function
282func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error) {
283	var tx *types.Transaction
284	var err error
285	if tx, err = c.client.CallAuth(
286		1000000,
287		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
288			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
289			if err != nil {
290				return nil, err
291			}
292			return auction.SetSlotDeadline(auth, newDeadline)
293		},
294	); err != nil {
295		return nil, fmt.Errorf("Failed setting slotDeadline: %w", err)
296	}
297	return tx, nil
298}
299
300// AuctionGetSlotDeadline is the interface to call the smart contract function
301func (c *AuctionClient) AuctionGetSlotDeadline() (uint8, error) {
302	var slotDeadline uint8
303	if err := c.client.Call(func(ec *ethclient.Client) error {
304		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
305		if err != nil {
306			return err
307		}
308		slotDeadline, err = auction.GetSlotDeadline(nil)
309		return err
310	}); err != nil {
311		return 0, err
312	}
313	return slotDeadline, nil
314}
315
316// AuctionSetOpenAuctionSlots is the interface to call the smart contract function
317func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error) {
318	var tx *types.Transaction
319	var err error
320	if tx, err = c.client.CallAuth(
321		1000000,
322		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
323			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
324			if err != nil {
325				return nil, err
326			}
327			return auction.SetOpenAuctionSlots(auth, newOpenAuctionSlots)
328		},
329	); err != nil {
330		return nil, fmt.Errorf("Failed setting openAuctionSlots: %w", err)
331	}
332	return tx, nil
333}
334
335// AuctionGetOpenAuctionSlots is the interface to call the smart contract function
336func (c *AuctionClient) AuctionGetOpenAuctionSlots() (uint16, error) {
337	var openAuctionSlots uint16
338	if err := c.client.Call(func(ec *ethclient.Client) error {
339		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
340		if err != nil {
341			return err
342		}
343		openAuctionSlots, err = auction.GetOpenAuctionSlots(nil)
344		return err
345	}); err != nil {
346		return 0, err
347	}
348	return openAuctionSlots, nil
349}
350
351// AuctionSetClosedAuctionSlots is the interface to call the smart contract function
352func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error) {
353	var tx *types.Transaction
354	var err error
355	if tx, err = c.client.CallAuth(
356		1000000,
357		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
358			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
359			if err != nil {
360				return nil, err
361			}
362			return auction.SetClosedAuctionSlots(auth, newClosedAuctionSlots)
363		},
364	); err != nil {
365		return nil, fmt.Errorf("Failed setting closedAuctionSlots: %w", err)
366	}
367	return tx, nil
368}
369
370// AuctionGetClosedAuctionSlots is the interface to call the smart contract function
371func (c *AuctionClient) AuctionGetClosedAuctionSlots() (uint16, error) {
372	var closedAuctionSlots uint16
373	if err := c.client.Call(func(ec *ethclient.Client) error {
374		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
375		if err != nil {
376			return err
377		}
378		closedAuctionSlots, err = auction.GetClosedAuctionSlots(nil)
379		return err
380	}); err != nil {
381		return 0, err
382	}
383	return closedAuctionSlots, nil
384}
385
386// AuctionSetOutbidding is the interface to call the smart contract function
387func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (*types.Transaction, error) {
388	var tx *types.Transaction
389	var err error
390	if tx, err = c.client.CallAuth(
391		12500000,
392		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
393			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
394			if err != nil {
395				return nil, err
396			}
397			return auction.SetOutbidding(auth, newOutbidding)
398		},
399	); err != nil {
400		return nil, fmt.Errorf("Failed setting setOutbidding: %w", err)
401	}
402	return tx, nil
403}
404
405// AuctionGetOutbidding is the interface to call the smart contract function
406func (c *AuctionClient) AuctionGetOutbidding() (uint16, error) {
407	var outbidding uint16
408	if err := c.client.Call(func(ec *ethclient.Client) error {
409		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
410		if err != nil {
411			return err
412		}
413		outbidding, err = auction.GetOutbidding(nil)
414		return err
415	}); err != nil {
416		return 0, err
417	}
418	return outbidding, nil
419}
420
421// AuctionSetAllocationRatio is the interface to call the smart contract function
422func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (*types.Transaction, error) {
423	var tx *types.Transaction
424	var err error
425	if tx, err = c.client.CallAuth(
426		1000000,
427		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
428			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
429			if err != nil {
430				return nil, err
431			}
432			return auction.SetAllocationRatio(auth, newAllocationRatio)
433		},
434	); err != nil {
435		return nil, fmt.Errorf("Failed setting allocationRatio: %w", err)
436	}
437	return tx, nil
438}
439
440// AuctionGetAllocationRatio is the interface to call the smart contract function
441func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint16, error) {
442	var allocationRation [3]uint16
443	if err := c.client.Call(func(ec *ethclient.Client) error {
444		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
445		if err != nil {
446			return err
447		}
448		allocationRation, err = auction.GetAllocationRatio(nil)
449		return err
450	}); err != nil {
451		return [3]uint16{}, err
452	}
453	return allocationRation, nil
454}
455
456// AuctionSetDonationAddress is the interface to call the smart contract function
457func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error) {
458	var tx *types.Transaction
459	var err error
460	if tx, err = c.client.CallAuth(
461		1000000,
462		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
463			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
464			if err != nil {
465				return nil, err
466			}
467			return auction.SetDonationAddress(auth, newDonationAddress)
468		},
469	); err != nil {
470		return nil, fmt.Errorf("Failed setting donationAddress: %w", err)
471	}
472	return tx, nil
473}
474
475// AuctionGetDonationAddress is the interface to call the smart contract function
476func (c *AuctionClient) AuctionGetDonationAddress() (*ethCommon.Address, error) {
477	var donationAddress ethCommon.Address
478	if err := c.client.Call(func(ec *ethclient.Client) error {
479		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
480		if err != nil {
481			return err
482		}
483		donationAddress, err = auction.GetDonationAddress(nil)
484		return err
485	}); err != nil {
486		return nil, err
487	}
488	return &donationAddress, nil
489}
490
491// AuctionSetBootCoordinator is the interface to call the smart contract function
492func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error) {
493	var tx *types.Transaction
494	var err error
495	if tx, err = c.client.CallAuth(
496		1000000,
497		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
498			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
499			if err != nil {
500				return nil, err
501			}
502			return auction.SetBootCoordinator(auth, newBootCoordinator)
503		},
504	); err != nil {
505		return nil, fmt.Errorf("Failed setting bootCoordinator: %w", err)
506	}
507	return tx, nil
508}
509
510// AuctionGetBootCoordinator is the interface to call the smart contract function
511func (c *AuctionClient) AuctionGetBootCoordinator() (*ethCommon.Address, error) {
512	var bootCoordinator ethCommon.Address
513	if err := c.client.Call(func(ec *ethclient.Client) error {
514		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
515		if err != nil {
516			return err
517		}
518		bootCoordinator, err = auction.GetBootCoordinator(nil)
519		return err
520	}); err != nil {
521		return nil, err
522	}
523	return &bootCoordinator, nil
524}
525
526// AuctionChangeDefaultSlotSetBid is the interface to call the smart contract function
527func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
528	var tx *types.Transaction
529	var err error
530	if tx, err = c.client.CallAuth(
531		1000000,
532		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
533			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
534			if err != nil {
535				return nil, err
536			}
537			slotSetToSend := big.NewInt(slotSet)
538			return auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid)
539		},
540	); err != nil {
541		return nil, fmt.Errorf("Failed changing epoch minBid: %w", err)
542	}
543	return tx, nil
544}
545
546// AuctionRegisterCoordinator is the interface to call the smart contract function
547func (c *AuctionClient) AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error) {
548	var tx *types.Transaction
549	var err error
550	if tx, err = c.client.CallAuth(
551		1000000,
552		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
553			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
554			if err != nil {
555				return nil, err
556			}
557			return auction.RegisterCoordinator(auth, forgerAddress, URL)
558		},
559	); err != nil {
560		return nil, fmt.Errorf("Failed register coordinator: %w", err)
561	}
562	return tx, nil
563}
564
565// AuctionIsRegisteredCoordinator is the interface to call the smart contract function
566func (c *AuctionClient) AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error) {
567	var registered bool
568	if err := c.client.Call(func(ec *ethclient.Client) error {
569		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
570		if err != nil {
571			return err
572		}
573		registered, err = auction.IsRegisteredCoordinator(nil, forgerAddress)
574		return err
575	}); err != nil {
576		return false, err
577	}
578	return registered, nil
579}
580
581// AuctionUpdateCoordinatorInfo is the interface to call the smart contract function
582func (c *AuctionClient) AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error) {
583	var tx *types.Transaction
584	var err error
585	if tx, err = c.client.CallAuth(
586		1000000,
587		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
588			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
589			if err != nil {
590				return nil, err
591			}
592			return auction.UpdateCoordinatorInfo(auth, forgerAddress, newWithdrawAddress, newURL)
593		},
594	); err != nil {
595		return nil, fmt.Errorf("Failed update coordinator info: %w", err)
596	}
597	return tx, nil
598}
599
600// AuctionGetCurrentSlotNumber is the interface to call the smart contract function
601func (c *AuctionClient) AuctionGetCurrentSlotNumber() (int64, error) {
602	var _currentSlotNumber *big.Int
603	if err := c.client.Call(func(ec *ethclient.Client) error {
604		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
605		if err != nil {
606			return err
607		}
608		_currentSlotNumber, err = auction.GetCurrentSlotNumber(nil)
609		return err
610	}); err != nil {
611		return 0, err
612	}
613	currentSlotNumber := _currentSlotNumber.Int64()
614	return currentSlotNumber, nil
615}
616
617// AuctionGetMinBidBySlot is the interface to call the smart contract function
618func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) {
619	var minBid *big.Int
620	if err := c.client.Call(func(ec *ethclient.Client) error {
621		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
622		if err != nil {
623			return err
624		}
625		slotToSend := big.NewInt(slot)
626		minBid, err = auction.GetMinBidBySlot(nil, slotToSend)
627		return err
628	}); err != nil {
629		return big.NewInt(0), err
630	}
631	return minBid, nil
632}
633
634// AuctionGetDefaultSlotSetBid is the interface to call the smart contract function
635func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) {
636	var minBidSlotSet *big.Int
637	if err := c.client.Call(func(ec *ethclient.Client) error {
638		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
639		if err != nil {
640			return err
641		}
642		minBidSlotSet, err = auction.GetDefaultSlotSetBid(nil, slotSet)
643		return err
644	}); err != nil {
645		return big.NewInt(0), err
646	}
647	return minBidSlotSet, nil
648}
649
650// AuctionTokensReceived is the interface to call the smart contract function
651// func (c *AuctionClient) AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int, userData, operatorData []byte) error {
652// 	return errTODO
653// }
654
655// AuctionBid is the interface to call the smart contract function
656func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
657	log.Error("TODO")
658	return nil, errTODO
659}
660
661// AuctionMultiBid is the interface to call the smart contract function
662func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
663	log.Error("TODO")
664	return nil, errTODO
665}
666
667// AuctionCanForge is the interface to call the smart contract function
668func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNumber *big.Int) (bool, error) {
669	var canForge bool
670	if err := c.client.Call(func(ec *ethclient.Client) error {
671		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
672		if err != nil {
673			return err
674		}
675		canForge, err = auction.CanForge(nil, forger, blockNumber)
676		return err
677	}); err != nil {
678		return false, err
679	}
680	return canForge, nil
681}
682
683// AuctionForge is the interface to call the smart contract function
684// func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (bool, error) {
685// 	return false, errTODO
686// }
687
688// AuctionClaimHEZ is the interface to call the smart contract function
689func (c *AuctionClient) AuctionClaimHEZ(claimAddress common.Address) (*types.Transaction, error) {
690	var tx *types.Transaction
691	var err error
692	if tx, err = c.client.CallAuth(
693		1000000,
694		func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
695			auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
696			if err != nil {
697				return nil, err
698			}
699			return auction.ClaimHEZ(auth, claimAddress)
700		},
701	); err != nil {
702		return nil, fmt.Errorf("Failed claim HEZ: %w", err)
703	}
704	return tx, nil
705}
706
707// AuctionConstants returns the Constants of the Auction Smart Contract
708func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
709	auctionConstants := new(AuctionConstants)
710	if err := c.client.Call(func(ec *ethclient.Client) error {
711		auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
712		if err != nil {
713			return err
714		}
715		auctionConstants.BlocksPerSlot, err = auction.BLOCKSPERSLOT(nil)
716		genesisBlock, err := auction.GenesisBlock(nil)
717		auctionConstants.GenesisBlockNum = genesisBlock.Int64()
718		auctionConstants.HermezRollup, err = auction.HermezRollup(nil)
719		auctionConstants.InitialMinimalBidding, err = auction.INITIALMINIMALBIDDING(nil)
720		auctionConstants.TokenHEZ, err = auction.TokenHEZ(nil)
721		return err
722	}); err != nil {
723		return nil, err
724	}
725	return auctionConstants, nil
726}
727
728// AuctionVariables returns the variables of the Auction Smart Contract
729func (c *AuctionClient) AuctionVariables() (*AuctionVariables, error) {
730	auctionVariables := new(AuctionVariables)
731	if err := c.client.Call(func(ec *ethclient.Client) error {
732		var err error
733		auctionVariables.AllocationRatio, err = c.AuctionGetAllocationRatio()
734		auctionVariables.BootCoordinator, err = c.AuctionGetBootCoordinator()
735		auctionVariables.ClosedAuctionSlots, err = c.AuctionGetClosedAuctionSlots()
736		var defaultSlotSetBid [6]*big.Int
737		for i := uint8(0); i < 6; i++ {
738			bid, err := c.AuctionGetDefaultSlotSetBid(i)
739			if err != nil {
740				return err
741			}
742			defaultSlotSetBid[i] = bid
743		}
744		auctionVariables.DefaultSlotSetBid = defaultSlotSetBid
745		auctionVariables.DonationAddress, err = c.AuctionGetDonationAddress()
746		auctionVariables.OpenAuctionSlots, err = c.AuctionGetOpenAuctionSlots()
747		auctionVariables.Outbidding, err = c.AuctionGetOutbidding()
748		auctionVariables.SlotDeadline, err = c.AuctionGetSlotDeadline()
749		return err
750	}); err != nil {
751		return nil, err
752	}
753	return auctionVariables, nil
754}
755
756// AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract
757func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error) {
758	log.Error("TODO")
759	return nil, nil, errTODO
760}