hermez-node/eth/auction.go
eth/auction.goRaw
1package eth
2
3import (
4 "math/big"
5
6 ethCommon "github.com/ethereum/go-ethereum/common"
7 "github.com/ethereum/go-ethereum/core/types"
8)
9
10// AuctionConstants are the constants of the Rollup Smart Contract
11type AuctionConstants struct {
12 // Blocks to wait before starting with the first slot
13 DelayGenesis uint16
14 // Blocks per slot
15 BlocksPerSlot uint8
16 // Minimum bid when no one has bid yet
17 InitialMinimalBidding *big.Int
18 // First block where the first slot begins
19 GenesisBlockNum int64
20 // Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee
21 GovernanceAddress ethCommon.Address
22 // ERC777 token with which the bids will be made
23 TokenHEZ ethCommon.Address
24 // HermezRollup smartcontract address
25 HermezRollup ethCommon.Address
26}
27
28// SlotState is the state of a slot
29type SlotState struct {
30 Forger ethCommon.Address
31 BidAmount *big.Int
32 ClosedMinBid *big.Int
33 Fulfilled bool
34}
35
36// Coordinator is the details of the Coordinator identified by the forger address
37type Coordinator struct {
38 WithdrawalAddress ethCommon.Address
39 URL string
40}
41
42// AuctionVariables are the variables of the Auction Smart Contract
43type AuctionVariables struct {
44 // Boot Coordinator Address
45 DonationAddress ethCommon.Address
46 // Boot Coordinator Address
47 BootCoordinator ethCommon.Address
48 // The minimum bid value in a series of 6 slots
49 MinBidEpoch [6]*big.Int
50 // Distance (#slots) to the closest slot to which you can bid ( 2 Slots = 2 * 40 Blocks = 20 min )
51 ClosedAuctionSlots uint16
52 // Distance (#slots) to the farthest slot to which you can bid (30 days = 4320 slots )
53 OpenAuctionSlots uint16
54 // How the HEZ tokens deposited by the slot winner are distributed (Burn: 40% - Donation: 40% - HGT: 20%)
55 AllocationRatio [3]uint8
56 // Minimum outbid (percentage) over the previous one to consider it valid
57 Outbidding uint8
58 // Number of blocks at the end of a slot in which any coordinator can forge if the winner has not forged one before
59 SlotDeadline uint8
60}
61
62// AuctionState represents the state of the Rollup in the Smart Contract
63type AuctionState struct {
64 // Mapping to control slot state
65 Slots map[int64]*SlotState
66 // Mapping to control balances pending to claim
67 PendingBalances map[ethCommon.Address]*big.Int
68 // Mapping to register all the coordinators. The address used for the mapping is the forger address
69 Coordinators map[ethCommon.Address]*Coordinator
70}
71
72// AuctionEventNewBid is an event of the Auction Smart Contract
73type AuctionEventNewBid struct {
74 Slot int64
75 BidAmount *big.Int
76 CoordinatorForger ethCommon.Address
77}
78
79// AuctionEventNewSlotDeadline is an event of the Auction Smart Contract
80type AuctionEventNewSlotDeadline struct {
81 NewSlotDeadline uint8
82}
83
84// AuctionEventNewClosedAuctionSlots is an event of the Auction Smart Contract
85type AuctionEventNewClosedAuctionSlots struct {
86 NewClosedAuctionSlots uint16
87}
88
89// AuctionEventNewOutbidding is an event of the Auction Smart Contract
90type AuctionEventNewOutbidding struct {
91 NewOutbidding uint8
92}
93
94// AuctionEventNewDonationAddress is an event of the Auction Smart Contract
95type AuctionEventNewDonationAddress struct {
96 NewDonationAddress ethCommon.Address
97}
98
99// AuctionEventNewBootCoordinator is an event of the Auction Smart Contract
100type AuctionEventNewBootCoordinator struct {
101 NewBootCoordinator ethCommon.Address
102}
103
104// AuctionEventNewOpenAuctionSlots is an event of the Auction Smart Contract
105type AuctionEventNewOpenAuctionSlots struct {
106 NewOpenAuctionSlots uint16
107}
108
109// AuctionEventNewAllocationRatio is an event of the Auction Smart Contract
110type AuctionEventNewAllocationRatio struct {
111 NewAllocationRatio [3]uint8
112}
113
114// AuctionEventNewCoordinator is an event of the Auction Smart Contract
115type AuctionEventNewCoordinator struct {
116 ForgerAddress ethCommon.Address
117 WithdrawalAddress ethCommon.Address
118 URL string
119}
120
121// AuctionEventCoordinatorUpdated is an event of the Auction Smart Contract
122type AuctionEventCoordinatorUpdated struct {
123 ForgerAddress ethCommon.Address
124 WithdrawalAddress ethCommon.Address
125 URL string
126}
127
128// AuctionEventNewForgeAllocated is an event of the Auction Smart Contract
129type AuctionEventNewForgeAllocated struct {
130 Forger ethCommon.Address
131 CurrentSlot int64
132 BurnAmount *big.Int
133 DonationAmount *big.Int
134 GovernanceAmount *big.Int
135}
136
137// AuctionEventNewMinBidEpoch is an event of the Auction Smart Contract
138type AuctionEventNewMinBidEpoch struct {
139 SlotEpoch int64
140 NewInitialMinBid *big.Int
141}
142
143// AuctionEventNewForge is an event of the Auction Smart Contract
144type AuctionEventNewForge struct {
145 Forger ethCommon.Address
146 CurrentSlot int64
147}
148
149// AuctionEventHEZClaimed is an event of the Auction Smart Contract
150type AuctionEventHEZClaimed struct {
151 Owner ethCommon.Address
152 Amount *big.Int
153}
154
155// AuctionEvents is the list of events in a block of the Auction Smart Contract
156type AuctionEvents struct { //nolint:structcheck
157 NewBid []AuctionEventNewBid
158 NewSlotDeadline []AuctionEventNewSlotDeadline
159 NewClosedAuctionSlots []AuctionEventNewClosedAuctionSlots
160 NewOutbidding []AuctionEventNewOutbidding
161 NewDonationAddress []AuctionEventNewDonationAddress
162 NewBootCoordinator []AuctionEventNewBootCoordinator
163 NewOpenAuctionSlots []AuctionEventNewOpenAuctionSlots
164 NewAllocationRatio []AuctionEventNewAllocationRatio
165 NewCoordinator []AuctionEventNewCoordinator
166 CoordinatorUpdated []AuctionEventCoordinatorUpdated
167 NewForgeAllocated []AuctionEventNewForgeAllocated
168 NewMinBidEpoch []AuctionEventNewMinBidEpoch
169 NewForge []AuctionEventNewForge
170 HEZClaimed []AuctionEventHEZClaimed
171}
172
173// NewAuctionEvents creates an empty AuctionEvents with the slices initialized.
174func NewAuctionEvents() AuctionEvents {
175 return AuctionEvents{
176 NewBid: make([]AuctionEventNewBid, 0),
177 NewSlotDeadline: make([]AuctionEventNewSlotDeadline, 0),
178 NewClosedAuctionSlots: make([]AuctionEventNewClosedAuctionSlots, 0),
179 NewOutbidding: make([]AuctionEventNewOutbidding, 0),
180 NewDonationAddress: make([]AuctionEventNewDonationAddress, 0),
181 NewBootCoordinator: make([]AuctionEventNewBootCoordinator, 0),
182 NewOpenAuctionSlots: make([]AuctionEventNewOpenAuctionSlots, 0),
183 NewAllocationRatio: make([]AuctionEventNewAllocationRatio, 0),
184 NewCoordinator: make([]AuctionEventNewCoordinator, 0),
185 CoordinatorUpdated: make([]AuctionEventCoordinatorUpdated, 0),
186 NewForgeAllocated: make([]AuctionEventNewForgeAllocated, 0),
187 NewMinBidEpoch: make([]AuctionEventNewMinBidEpoch, 0),
188 NewForge: make([]AuctionEventNewForge, 0),
189 HEZClaimed: make([]AuctionEventHEZClaimed, 0),
190 }
191}
192
193// AuctionInterface is the inteface to to Auction Smart Contract
194type AuctionInterface interface {
195 //
196 // Smart Contract Methods
197 //
198
199 // Getter/Setter, where Setter is onlyOwner
200 AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error)
201 AuctionGetSlotDeadline() (uint8, error)
202 AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error)
203 AuctionGetOpenAuctionSlots() (uint16, error)
204 AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error)
205 AuctionGetClosedAuctionSlots() (uint16, error)
206 AuctionSetOutbidding(newOutbidding uint8) (*types.Transaction, error)
207 AuctionGetOutbidding() (uint8, error)
208 AuctionSetAllocationRatio(newAllocationRatio [3]uint8) (*types.Transaction, error)
209 AuctionGetAllocationRatio() ([3]uint8, error)
210 AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error)
211 AuctionGetDonationAddress() (*ethCommon.Address, error)
212 AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error)
213 AuctionGetBootCoordinator() (*ethCommon.Address, error)
214 AuctionChangeEpochMinBid(slotEpoch int64, newInitialMinBid *big.Int) (*types.Transaction, error)
215
216 // Coordinator Management
217 AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error)
218 AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error)
219 AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error)
220
221 // Slot Info
222 AuctionGetCurrentSlotNumber() (int64, error)
223 AuctionGetMinBidBySlot(slot int64) (*big.Int, error)
224 AuctionGetMinBidEpoch(epoch uint8) (*big.Int, error)
225
226 // Bidding
227 // AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int,
228 // userData, operatorData []byte) error // Only called from another smart contract
229 AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error)
230 AuctionMultiBid(startingSlot int64, endingSlot int64, slotEpoch [6]bool,
231 maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
232
233 // Forge
234 AuctionCanForge(forger ethCommon.Address) (bool, error)
235 // AuctionForge(forger ethCommon.Address) (bool, error) // Only called from another smart contract
236
237 // Fees
238 AuctionClaimHEZ() (*types.Transaction, error)
239
240 //
241 // Smart Contract Status
242 //
243
244 AuctionConstants() (*AuctionConstants, error)
245 AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error)
246}
247
248//
249// Implementation
250//
251
252// AuctionClient is the implementation of the interface to the Auction Smart Contract in ethereum.
253type AuctionClient struct {
254}
255
256// AuctionSetSlotDeadline is the interface to call the smart contract function
257func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error) {
258 return nil, errTODO
259}
260
261// AuctionGetSlotDeadline is the interface to call the smart contract function
262func (c *AuctionClient) AuctionGetSlotDeadline() (uint8, error) {
263 return 0, errTODO
264}
265
266// AuctionSetOpenAuctionSlots is the interface to call the smart contract function
267func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error) {
268 return nil, errTODO
269}
270
271// AuctionGetOpenAuctionSlots is the interface to call the smart contract function
272func (c *AuctionClient) AuctionGetOpenAuctionSlots() (uint16, error) {
273 return 0, errTODO
274}
275
276// AuctionSetClosedAuctionSlots is the interface to call the smart contract function
277func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error) {
278 return nil, errTODO
279}
280
281// AuctionGetClosedAuctionSlots is the interface to call the smart contract function
282func (c *AuctionClient) AuctionGetClosedAuctionSlots() (uint16, error) {
283 return 0, errTODO
284}
285
286// AuctionSetOutbidding is the interface to call the smart contract function
287func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint8) (*types.Transaction, error) {
288 return nil, errTODO
289}
290
291// AuctionGetOutbidding is the interface to call the smart contract function
292func (c *AuctionClient) AuctionGetOutbidding() (uint8, error) {
293 return 0, errTODO
294}
295
296// AuctionSetAllocationRatio is the interface to call the smart contract function
297func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint8) (*types.Transaction, error) {
298 return nil, errTODO
299}
300
301// AuctionGetAllocationRatio is the interface to call the smart contract function
302func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint8, error) {
303 return [3]uint8{}, errTODO
304}
305
306// AuctionSetDonationAddress is the interface to call the smart contract function
307func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error) {
308 return nil, errTODO
309}
310
311// AuctionGetDonationAddress is the interface to call the smart contract function
312func (c *AuctionClient) AuctionGetDonationAddress() (*ethCommon.Address, error) {
313 return nil, errTODO
314}
315
316// AuctionSetBootCoordinator is the interface to call the smart contract function
317func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error) {
318 return nil, errTODO
319}
320
321// AuctionGetBootCoordinator is the interface to call the smart contract function
322func (c *AuctionClient) AuctionGetBootCoordinator() (*ethCommon.Address, error) {
323 return nil, errTODO
324}
325
326// AuctionChangeEpochMinBid is the interface to call the smart contract function
327func (c *AuctionClient) AuctionChangeEpochMinBid(slotEpoch int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
328 return nil, errTODO
329}
330
331// AuctionRegisterCoordinator is the interface to call the smart contract function
332func (c *AuctionClient) AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error) {
333 return nil, errTODO
334}
335
336// AuctionIsRegisteredCoordinator is the interface to call the smart contract function
337func (c *AuctionClient) AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error) {
338 return false, errTODO
339}
340
341// AuctionUpdateCoordinatorInfo is the interface to call the smart contract function
342func (c *AuctionClient) AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error) {
343 return nil, errTODO
344}
345
346// AuctionGetCurrentSlotNumber is the interface to call the smart contract function
347func (c *AuctionClient) AuctionGetCurrentSlotNumber() (int64, error) {
348 return 0, errTODO
349}
350
351// AuctionGetMinBidBySlot is the interface to call the smart contract function
352func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) {
353 return nil, errTODO
354}
355
356// AuctionGetMinBidEpoch is the interface to call the smart contract function
357func (c *AuctionClient) AuctionGetMinBidEpoch(epoch uint8) (*big.Int, error) {
358 return nil, errTODO
359}
360
361// AuctionTokensReceived is the interface to call the smart contract function
362// func (c *AuctionClient) AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int, userData, operatorData []byte) error {
363// return errTODO
364// }
365
366// AuctionBid is the interface to call the smart contract function
367func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
368 return nil, errTODO
369}
370
371// AuctionMultiBid is the interface to call the smart contract function
372func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotEpoch [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
373 return nil, errTODO
374}
375
376// AuctionCanForge is the interface to call the smart contract function
377func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address) (bool, error) {
378 return false, errTODO
379}
380
381// AuctionForge is the interface to call the smart contract function
382// func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (bool, error) {
383// return false, errTODO
384// }
385
386// AuctionClaimHEZ is the interface to call the smart contract function
387func (c *AuctionClient) AuctionClaimHEZ() (*types.Transaction, error) {
388 return nil, errTODO
389}
390
391// AuctionConstants returns the Constants of the Auction Smart Contract
392func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
393 return nil, errTODO
394}
395
396// AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract
397func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error) {
398 return nil, nil, errTODO
399}