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
69 // Mapping to register all the coordinators. The address used for the mapping is the forger address
70 Coordinators map[ethCommon.Address]Coordinator
71}
72
73// AuctionEventNewBid is an event of the Auction Smart Contract
74type AuctionEventNewBid struct {
75 Slot int64
76 BidAmount *big.Int
77 CoordinatorForger ethCommon.Address
78}
79
80// AuctionEventNewSlotDeadline is an event of the Auction Smart Contract
81type AuctionEventNewSlotDeadline struct {
82 NewSlotDeadline uint8
83}
84
85// AuctionEventNewClosedAuctionSlots is an event of the Auction Smart Contract
86type AuctionEventNewClosedAuctionSlots struct {
87 NewClosedAuctionSlots uint16
88}
89
90// AuctionEventNewOutbidding is an event of the Auction Smart Contract
91type AuctionEventNewOutbidding struct {
92 NewOutbidding uint8
93}
94
95// AuctionEventNewDonationAddress is an event of the Auction Smart Contract
96type AuctionEventNewDonationAddress struct {
97 NewDonationAddress ethCommon.Address
98}
99
100// AuctionEventNewBootCoordinator is an event of the Auction Smart Contract
101type AuctionEventNewBootCoordinator struct {
102 NewBootCoordinator ethCommon.Address
103}
104
105// AuctionEventNewOpenAuctionSlots is an event of the Auction Smart Contract
106type AuctionEventNewOpenAuctionSlots struct {
107 NewOpenAuctionSlots uint16
108}
109
110// AuctionEventNewAllocationRatio is an event of the Auction Smart Contract
111type AuctionEventNewAllocationRatio struct {
112 NewAllocationRatio [3]uint8
113}
114
115// AuctionEventNewCoordinator is an event of the Auction Smart Contract
116type AuctionEventNewCoordinator struct {
117 ForgerAddress ethCommon.Address
118 WithdrawalAddress ethCommon.Address
119 URL string
120}
121
122// AuctionEventCoordinatorUpdated is an event of the Auction Smart Contract
123type AuctionEventCoordinatorUpdated struct {
124 ForgerAddress ethCommon.Address
125 WithdrawalAddress ethCommon.Address
126 URL string
127}
128
129// AuctionEventNewForgeAllocated is an event of the Auction Smart Contract
130type AuctionEventNewForgeAllocated struct {
131 Forger ethCommon.Address
132 CurrentSlot int64
133 BurnAmount *big.Int
134 DonationAmount *big.Int
135 GovernanceAmount *big.Int
136}
137
138// AuctionEventNewMinBidEpoch is an event of the Auction Smart Contract
139type AuctionEventNewMinBidEpoch struct {
140 SlotEpoch int64
141 NewInitialMinBid *big.Int
142}
143
144// AuctionEventNewForge is an event of the Auction Smart Contract
145type AuctionEventNewForge struct {
146 Forger ethCommon.Address
147 CurrentSlot int64
148}
149
150// AuctionEventHEZClaimed is an event of the Auction Smart Contract
151type AuctionEventHEZClaimed struct {
152 Owner ethCommon.Address
153 Amount *big.Int
154}
155
156// AuctionEvents is the list of events in a block of the Auction Smart Contract
157type AuctionEvents struct { //nolint:structcheck
158 NewBid []AuctionEventNewBid
159 NewSlotDeadline []AuctionEventNewSlotDeadline
160 NewClosedAuctionSlots []AuctionEventNewClosedAuctionSlots
161 NewOutbidding []AuctionEventNewOutbidding
162 NewDonationAddress []AuctionEventNewDonationAddress
163 NewBootCoordinator []AuctionEventNewBootCoordinator
164 NewOpenAuctionSlots []AuctionEventNewOpenAuctionSlots
165 NewAllocationRatio []AuctionEventNewAllocationRatio
166 NewCoordinator []AuctionEventNewCoordinator
167 CoordinatorUpdated []AuctionEventCoordinatorUpdated
168 NewForgeAllocated []AuctionEventNewForgeAllocated
169 NewMinBidEpoch []AuctionEventNewMinBidEpoch
170 NewForge []AuctionEventNewForge
171 HEZClaimed []AuctionEventHEZClaimed
172}
173
174// AuctionInterface is the inteface to to Auction Smart Contract
175type AuctionInterface interface {
176 //
177 // Smart Contract Methods
178 //
179
180 // Getter/Setter, where Setter is onlyOwner
181 AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error)
182 AuctionGetSlotDeadline() (uint8, error)
183 AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error)
184 AuctionGetOpenAuctionSlots() (uint16, error)
185 AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error)
186 AuctionGetClosedAuctionSlots() (uint16, error)
187 AuctionSetOutbidding(newOutbidding uint8) (*types.Transaction, error)
188 AuctionGetOutbidding() (uint8, error)
189 AuctionSetAllocationRatio(newAllocationRatio [3]uint8) (*types.Transaction, error)
190 AuctionGetAllocationRatio() ([3]uint8, error)
191 AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error)
192 AuctionGetDonationAddress() (*ethCommon.Address, error)
193 AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error)
194 AuctionGetBootCoordinator() (*ethCommon.Address, error)
195 AuctionChangeEpochMinBid(slotEpoch int64, newInitialMinBid *big.Int) (*types.Transaction, error)
196
197 // Coordinator Management
198 AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error)
199 AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error)
200 AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error)
201
202 // Slot Info
203 AuctionGetCurrentSlotNumber() (int64, error)
204 AuctionGetMinBidBySlot(slot int64) (*big.Int, error)
205 AuctionGetMinBidEpoch(epoch uint8) (*big.Int, error)
206
207 // Bidding
208 // AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int,
209 // userData, operatorData []byte) error // Only called from another smart contract
210 AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error)
211 AuctionMultiBid(startingSlot int64, endingSlot int64, slotEpoch [6]bool,
212 maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
213
214 // Forge
215 AuctionCanForge(forger ethCommon.Address) (bool, error)
216 // AuctionForge(forger ethCommon.Address) (bool, error) // Only called from another smart contract
217
218 // Fees
219 AuctionClaimHEZ() (*types.Transaction, error)
220
221 //
222 // Smart Contract Status
223 //
224
225 AuctionConstants() (*AuctionConstants, error)
226 AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error)
227}
228
229//
230// Implementation
231//
232
233// AuctionClient is the implementation of the interface to the Auction Smart Contract in ethereum.
234type AuctionClient struct {
235}
236
237// AuctionSetSlotDeadline is the interface to call the smart contract function
238func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error) {
239 return nil, errTODO
240}
241
242// AuctionGetSlotDeadline is the interface to call the smart contract function
243func (c *AuctionClient) AuctionGetSlotDeadline() (uint8, error) {
244 return 0, errTODO
245}
246
247// AuctionSetOpenAuctionSlots is the interface to call the smart contract function
248func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error) {
249 return nil, errTODO
250}
251
252// AuctionGetOpenAuctionSlots is the interface to call the smart contract function
253func (c *AuctionClient) AuctionGetOpenAuctionSlots() (uint16, error) {
254 return 0, errTODO
255}
256
257// AuctionSetClosedAuctionSlots is the interface to call the smart contract function
258func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error) {
259 return nil, errTODO
260}
261
262// AuctionGetClosedAuctionSlots is the interface to call the smart contract function
263func (c *AuctionClient) AuctionGetClosedAuctionSlots() (uint16, error) {
264 return 0, errTODO
265}
266
267// AuctionSetOutbidding is the interface to call the smart contract function
268func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint8) (*types.Transaction, error) {
269 return nil, errTODO
270}
271
272// AuctionGetOutbidding is the interface to call the smart contract function
273func (c *AuctionClient) AuctionGetOutbidding() (uint8, error) {
274 return 0, errTODO
275}
276
277// AuctionSetAllocationRatio is the interface to call the smart contract function
278func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint8) (*types.Transaction, error) {
279 return nil, errTODO
280}
281
282// AuctionGetAllocationRatio is the interface to call the smart contract function
283func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint8, error) {
284 return [3]uint8{}, errTODO
285}
286
287// AuctionSetDonationAddress is the interface to call the smart contract function
288func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error) {
289 return nil, errTODO
290}
291
292// AuctionGetDonationAddress is the interface to call the smart contract function
293func (c *AuctionClient) AuctionGetDonationAddress() (*ethCommon.Address, error) {
294 return nil, errTODO
295}
296
297// AuctionSetBootCoordinator is the interface to call the smart contract function
298func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error) {
299 return nil, errTODO
300}
301
302// AuctionGetBootCoordinator is the interface to call the smart contract function
303func (c *AuctionClient) AuctionGetBootCoordinator() (*ethCommon.Address, error) {
304 return nil, errTODO
305}
306
307// AuctionChangeEpochMinBid is the interface to call the smart contract function
308func (c *AuctionClient) AuctionChangeEpochMinBid(slotEpoch int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
309 return nil, errTODO
310}
311
312// AuctionRegisterCoordinator is the interface to call the smart contract function
313func (c *AuctionClient) AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error) {
314 return nil, errTODO
315}
316
317// AuctionIsRegisteredCoordinator is the interface to call the smart contract function
318func (c *AuctionClient) AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error) {
319 return false, errTODO
320}
321
322// AuctionUpdateCoordinatorInfo is the interface to call the smart contract function
323func (c *AuctionClient) AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error) {
324 return nil, errTODO
325}
326
327// AuctionGetCurrentSlotNumber is the interface to call the smart contract function
328func (c *AuctionClient) AuctionGetCurrentSlotNumber() (int64, error) {
329 return 0, errTODO
330}
331
332// AuctionGetMinBidBySlot is the interface to call the smart contract function
333func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) {
334 return nil, errTODO
335}
336
337// AuctionGetMinBidEpoch is the interface to call the smart contract function
338func (c *AuctionClient) AuctionGetMinBidEpoch(epoch uint8) (*big.Int, error) {
339 return nil, errTODO
340}
341
342// AuctionTokensReceived is the interface to call the smart contract function
343// func (c *AuctionClient) AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int, userData, operatorData []byte) error {
344// return errTODO
345// }
346
347// AuctionBid is the interface to call the smart contract function
348func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
349 return nil, errTODO
350}
351
352// AuctionMultiBid is the interface to call the smart contract function
353func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotEpoch [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
354 return nil, errTODO
355}
356
357// AuctionCanForge is the interface to call the smart contract function
358func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address) (bool, error) {
359 return false, errTODO
360}
361
362// AuctionForge is the interface to call the smart contract function
363// func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (bool, error) {
364// return false, errTODO
365// }
366
367// AuctionClaimHEZ is the interface to call the smart contract function
368func (c *AuctionClient) AuctionClaimHEZ() (*types.Transaction, error) {
369 return nil, errTODO
370}
371
372// AuctionConstants returns the Constants of the Auction Smart Contract
373func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
374 return nil, errTODO
375}
376
377// AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract
378func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error) {
379 return nil, nil, errTODO
380}