You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1092 lines
39 KiB

  1. package eth
  2. import (
  3. "context"
  4. "encoding/binary"
  5. "fmt"
  6. "math/big"
  7. "strings"
  8. "github.com/ethereum/go-ethereum"
  9. "github.com/ethereum/go-ethereum/accounts/abi"
  10. "github.com/ethereum/go-ethereum/accounts/abi/bind"
  11. ethCommon "github.com/ethereum/go-ethereum/common"
  12. "github.com/ethereum/go-ethereum/core/types"
  13. "github.com/ethereum/go-ethereum/crypto"
  14. "github.com/ethereum/go-ethereum/ethclient"
  15. HermezAuctionProtocol "github.com/hermeznetwork/hermez-node/eth/contracts/auction"
  16. ERC777 "github.com/hermeznetwork/hermez-node/eth/contracts/erc777"
  17. "golang.org/x/crypto/sha3"
  18. )
  19. // AuctionConstants are the constants of the Rollup Smart Contract
  20. type AuctionConstants struct {
  21. // Blocks per slot
  22. BlocksPerSlot uint8
  23. // Minimum bid when no one has bid yet
  24. InitialMinimalBidding *big.Int
  25. // First block where the first slot begins
  26. GenesisBlockNum int64
  27. // Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee
  28. // Only for test
  29. GovernanceAddress ethCommon.Address
  30. // ERC777 token with which the bids will be made
  31. TokenHEZ ethCommon.Address
  32. // HermezRollup smartcontract address
  33. HermezRollup ethCommon.Address
  34. }
  35. // SlotState is the state of a slot
  36. type SlotState struct {
  37. Forger ethCommon.Address
  38. BidAmount *big.Int
  39. ClosedMinBid *big.Int
  40. Fulfilled bool
  41. }
  42. // NewSlotState returns an empty SlotState
  43. func NewSlotState() *SlotState {
  44. return &SlotState{
  45. Forger: ethCommon.Address{},
  46. BidAmount: big.NewInt(0),
  47. ClosedMinBid: big.NewInt(0),
  48. Fulfilled: false,
  49. }
  50. }
  51. // Coordinator is the details of the Coordinator identified by the forger address
  52. type Coordinator struct {
  53. WithdrawalAddress ethCommon.Address
  54. URL string
  55. }
  56. // AuctionVariables are the variables of the Auction Smart Contract
  57. type AuctionVariables struct {
  58. // Boot Coordinator Address
  59. DonationAddress ethCommon.Address
  60. // Boot Coordinator Address
  61. BootCoordinator ethCommon.Address
  62. // The minimum bid value in a series of 6 slots
  63. DefaultSlotSetBid [6]*big.Int
  64. // Distance (#slots) to the closest slot to which you can bid ( 2 Slots = 2 * 40 Blocks = 20 min )
  65. ClosedAuctionSlots uint16
  66. // Distance (#slots) to the farthest slot to which you can bid (30 days = 4320 slots )
  67. OpenAuctionSlots uint16
  68. // How the HEZ tokens deposited by the slot winner are distributed (Burn: 40% - Donation: 40% - HGT: 20%)
  69. AllocationRatio [3]uint16
  70. // Minimum outbid (percentage) over the previous one to consider it valid
  71. Outbidding uint16
  72. // Number of blocks at the end of a slot in which any coordinator can forge if the winner has not forged one before
  73. SlotDeadline uint8
  74. }
  75. // AuctionState represents the state of the Rollup in the Smart Contract
  76. type AuctionState struct {
  77. // Mapping to control slot state
  78. Slots map[int64]*SlotState
  79. // Mapping to control balances pending to claim
  80. PendingBalances map[ethCommon.Address]*big.Int
  81. // Mapping to register all the coordinators. The address used for the mapping is the forger address
  82. Coordinators map[ethCommon.Address]*Coordinator
  83. }
  84. // AuctionEventNewBid is an event of the Auction Smart Contract
  85. type AuctionEventNewBid struct {
  86. Slot int64
  87. BidAmount *big.Int
  88. CoordinatorForger ethCommon.Address
  89. }
  90. // AuctionEventNewSlotDeadline is an event of the Auction Smart Contract
  91. type AuctionEventNewSlotDeadline struct {
  92. NewSlotDeadline uint8
  93. }
  94. // AuctionEventNewClosedAuctionSlots is an event of the Auction Smart Contract
  95. type AuctionEventNewClosedAuctionSlots struct {
  96. NewClosedAuctionSlots uint16
  97. }
  98. // AuctionEventNewOutbidding is an event of the Auction Smart Contract
  99. type AuctionEventNewOutbidding struct {
  100. NewOutbidding uint16
  101. }
  102. // AuctionEventNewDonationAddress is an event of the Auction Smart Contract
  103. type AuctionEventNewDonationAddress struct {
  104. NewDonationAddress ethCommon.Address
  105. }
  106. // AuctionEventNewBootCoordinator is an event of the Auction Smart Contract
  107. type AuctionEventNewBootCoordinator struct {
  108. NewBootCoordinator ethCommon.Address
  109. }
  110. // AuctionEventNewOpenAuctionSlots is an event of the Auction Smart Contract
  111. type AuctionEventNewOpenAuctionSlots struct {
  112. NewOpenAuctionSlots uint16
  113. }
  114. // AuctionEventNewAllocationRatio is an event of the Auction Smart Contract
  115. type AuctionEventNewAllocationRatio struct {
  116. NewAllocationRatio [3]uint16
  117. }
  118. // AuctionEventNewCoordinator is an event of the Auction Smart Contract
  119. type AuctionEventNewCoordinator struct {
  120. ForgerAddress ethCommon.Address
  121. WithdrawalAddress ethCommon.Address
  122. CoordinatorURL string
  123. }
  124. // AuctionEventCoordinatorUpdated is an event of the Auction Smart Contract
  125. type AuctionEventCoordinatorUpdated struct {
  126. ForgerAddress ethCommon.Address
  127. WithdrawalAddress ethCommon.Address
  128. CoordinatorURL string
  129. }
  130. // AuctionEventNewForgeAllocated is an event of the Auction Smart Contract
  131. type AuctionEventNewForgeAllocated struct {
  132. Forger ethCommon.Address
  133. CurrentSlot int64
  134. BurnAmount *big.Int
  135. DonationAmount *big.Int
  136. GovernanceAmount *big.Int
  137. }
  138. // AuctionEventNewDefaultSlotSetBid is an event of the Auction Smart Contract
  139. type AuctionEventNewDefaultSlotSetBid struct {
  140. SlotSet int64
  141. NewInitialMinBid *big.Int
  142. }
  143. // AuctionEventNewForge is an event of the Auction Smart Contract
  144. type AuctionEventNewForge struct {
  145. Forger ethCommon.Address
  146. CurrentSlot int64
  147. }
  148. // AuctionEventHEZClaimed is an event of the Auction Smart Contract
  149. type AuctionEventHEZClaimed struct {
  150. Owner ethCommon.Address
  151. Amount *big.Int
  152. }
  153. // AuctionEvents is the list of events in a block of the Auction Smart Contract
  154. type AuctionEvents struct { //nolint:structcheck
  155. NewBid []AuctionEventNewBid
  156. NewSlotDeadline []AuctionEventNewSlotDeadline
  157. NewClosedAuctionSlots []AuctionEventNewClosedAuctionSlots
  158. NewOutbidding []AuctionEventNewOutbidding
  159. NewDonationAddress []AuctionEventNewDonationAddress
  160. NewBootCoordinator []AuctionEventNewBootCoordinator
  161. NewOpenAuctionSlots []AuctionEventNewOpenAuctionSlots
  162. NewAllocationRatio []AuctionEventNewAllocationRatio
  163. NewCoordinator []AuctionEventNewCoordinator
  164. CoordinatorUpdated []AuctionEventCoordinatorUpdated
  165. NewForgeAllocated []AuctionEventNewForgeAllocated
  166. NewDefaultSlotSetBid []AuctionEventNewDefaultSlotSetBid
  167. NewForge []AuctionEventNewForge
  168. HEZClaimed []AuctionEventHEZClaimed
  169. }
  170. // NewAuctionEvents creates an empty AuctionEvents with the slices initialized.
  171. func NewAuctionEvents() AuctionEvents {
  172. return AuctionEvents{
  173. NewBid: make([]AuctionEventNewBid, 0),
  174. NewSlotDeadline: make([]AuctionEventNewSlotDeadline, 0),
  175. NewClosedAuctionSlots: make([]AuctionEventNewClosedAuctionSlots, 0),
  176. NewOutbidding: make([]AuctionEventNewOutbidding, 0),
  177. NewDonationAddress: make([]AuctionEventNewDonationAddress, 0),
  178. NewBootCoordinator: make([]AuctionEventNewBootCoordinator, 0),
  179. NewOpenAuctionSlots: make([]AuctionEventNewOpenAuctionSlots, 0),
  180. NewAllocationRatio: make([]AuctionEventNewAllocationRatio, 0),
  181. NewCoordinator: make([]AuctionEventNewCoordinator, 0),
  182. CoordinatorUpdated: make([]AuctionEventCoordinatorUpdated, 0),
  183. NewForgeAllocated: make([]AuctionEventNewForgeAllocated, 0),
  184. NewDefaultSlotSetBid: make([]AuctionEventNewDefaultSlotSetBid, 0),
  185. NewForge: make([]AuctionEventNewForge, 0),
  186. HEZClaimed: make([]AuctionEventHEZClaimed, 0),
  187. }
  188. }
  189. // AuctionInterface is the inteface to to Auction Smart Contract
  190. type AuctionInterface interface {
  191. //
  192. // Smart Contract Methods
  193. //
  194. // Getter/Setter, where Setter is onlyOwner
  195. AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error)
  196. AuctionGetSlotDeadline() (uint8, error)
  197. AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error)
  198. AuctionGetOpenAuctionSlots() (uint16, error)
  199. AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error)
  200. AuctionGetClosedAuctionSlots() (uint16, error)
  201. AuctionSetOutbidding(newOutbidding uint16) (*types.Transaction, error)
  202. AuctionGetOutbidding() (uint16, error)
  203. AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (*types.Transaction, error)
  204. AuctionGetAllocationRatio() ([3]uint16, error)
  205. AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error)
  206. AuctionGetDonationAddress() (*ethCommon.Address, error)
  207. AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error)
  208. AuctionGetBootCoordinator() (*ethCommon.Address, error)
  209. AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error)
  210. // Coordinator Management
  211. AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error)
  212. AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error)
  213. AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error)
  214. // Slot Info
  215. AuctionGetCurrentSlotNumber() (int64, error)
  216. AuctionGetMinBidBySlot(slot int64) (*big.Int, error)
  217. AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error)
  218. AuctionGetSlotSet(slot int64) (*big.Int, error)
  219. AuctionGetSlotNumber(blockNum int64) (*big.Int, error)
  220. // Bidding
  221. // AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int,
  222. // userData, operatorData []byte) error // Only called from another smart contract
  223. AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error)
  224. AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
  225. // Forge
  226. AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error)
  227. // AuctionForge(forger ethCommon.Address) (bool, error) // Only called from another smart contract
  228. // Fees
  229. AuctionClaimHEZ(claimAddress ethCommon.Address) (*types.Transaction, error)
  230. //
  231. // Smart Contract Status
  232. //
  233. AuctionConstants() (*AuctionConstants, error)
  234. AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error)
  235. }
  236. //
  237. // Implementation
  238. //
  239. // AuctionClient is the implementation of the interface to the Auction Smart Contract in ethereum.
  240. type AuctionClient struct {
  241. client *EthereumClient
  242. address ethCommon.Address
  243. tokenAddress ethCommon.Address
  244. gasLimit uint64
  245. contractAbi abi.ABI
  246. }
  247. // NewAuctionClient creates a new AuctionClient. `tokenAddress` is the address of the HEZ tokens.
  248. func NewAuctionClient(client *EthereumClient, address, tokenAddress ethCommon.Address) (*AuctionClient, error) {
  249. contractAbi, err := abi.JSON(strings.NewReader(string(HermezAuctionProtocol.HermezAuctionProtocolABI)))
  250. if err != nil {
  251. return nil, err
  252. }
  253. return &AuctionClient{
  254. client: client,
  255. address: address,
  256. tokenAddress: tokenAddress,
  257. gasLimit: 1000000, //nolint:gomnd
  258. contractAbi: contractAbi,
  259. }, nil
  260. }
  261. // AuctionSetSlotDeadline is the interface to call the smart contract function
  262. func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error) {
  263. var tx *types.Transaction
  264. var err error
  265. if tx, err = c.client.CallAuth(
  266. c.gasLimit,
  267. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  268. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  269. if err != nil {
  270. return nil, err
  271. }
  272. return auction.SetSlotDeadline(auth, newDeadline)
  273. },
  274. ); err != nil {
  275. return nil, fmt.Errorf("Failed setting slotDeadline: %w", err)
  276. }
  277. return tx, nil
  278. }
  279. // AuctionGetSlotDeadline is the interface to call the smart contract function
  280. func (c *AuctionClient) AuctionGetSlotDeadline() (uint8, error) {
  281. var slotDeadline uint8
  282. if err := c.client.Call(func(ec *ethclient.Client) error {
  283. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  284. if err != nil {
  285. return err
  286. }
  287. slotDeadline, err = auction.GetSlotDeadline(nil)
  288. return err
  289. }); err != nil {
  290. return 0, err
  291. }
  292. return slotDeadline, nil
  293. }
  294. // AuctionSetOpenAuctionSlots is the interface to call the smart contract function
  295. func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error) {
  296. var tx *types.Transaction
  297. var err error
  298. if tx, err = c.client.CallAuth(
  299. c.gasLimit,
  300. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  301. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  302. if err != nil {
  303. return nil, err
  304. }
  305. return auction.SetOpenAuctionSlots(auth, newOpenAuctionSlots)
  306. },
  307. ); err != nil {
  308. return nil, fmt.Errorf("Failed setting openAuctionSlots: %w", err)
  309. }
  310. return tx, nil
  311. }
  312. // AuctionGetOpenAuctionSlots is the interface to call the smart contract function
  313. func (c *AuctionClient) AuctionGetOpenAuctionSlots() (uint16, error) {
  314. var openAuctionSlots uint16
  315. if err := c.client.Call(func(ec *ethclient.Client) error {
  316. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  317. if err != nil {
  318. return err
  319. }
  320. openAuctionSlots, err = auction.GetOpenAuctionSlots(nil)
  321. return err
  322. }); err != nil {
  323. return 0, err
  324. }
  325. return openAuctionSlots, nil
  326. }
  327. // AuctionSetClosedAuctionSlots is the interface to call the smart contract function
  328. func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error) {
  329. var tx *types.Transaction
  330. var err error
  331. if tx, err = c.client.CallAuth(
  332. c.gasLimit,
  333. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  334. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  335. if err != nil {
  336. return nil, err
  337. }
  338. return auction.SetClosedAuctionSlots(auth, newClosedAuctionSlots)
  339. },
  340. ); err != nil {
  341. return nil, fmt.Errorf("Failed setting closedAuctionSlots: %w", err)
  342. }
  343. return tx, nil
  344. }
  345. // AuctionGetClosedAuctionSlots is the interface to call the smart contract function
  346. func (c *AuctionClient) AuctionGetClosedAuctionSlots() (uint16, error) {
  347. var closedAuctionSlots uint16
  348. if err := c.client.Call(func(ec *ethclient.Client) error {
  349. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  350. if err != nil {
  351. return err
  352. }
  353. closedAuctionSlots, err = auction.GetClosedAuctionSlots(nil)
  354. return err
  355. }); err != nil {
  356. return 0, err
  357. }
  358. return closedAuctionSlots, nil
  359. }
  360. // AuctionSetOutbidding is the interface to call the smart contract function
  361. func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (*types.Transaction, error) {
  362. var tx *types.Transaction
  363. var err error
  364. if tx, err = c.client.CallAuth(
  365. 12500000, //nolint:gomnd
  366. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  367. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  368. if err != nil {
  369. return nil, err
  370. }
  371. return auction.SetOutbidding(auth, newOutbidding)
  372. },
  373. ); err != nil {
  374. return nil, fmt.Errorf("Failed setting setOutbidding: %w", err)
  375. }
  376. return tx, nil
  377. }
  378. // AuctionGetOutbidding is the interface to call the smart contract function
  379. func (c *AuctionClient) AuctionGetOutbidding() (uint16, error) {
  380. var outbidding uint16
  381. if err := c.client.Call(func(ec *ethclient.Client) error {
  382. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  383. if err != nil {
  384. return err
  385. }
  386. outbidding, err = auction.GetOutbidding(nil)
  387. return err
  388. }); err != nil {
  389. return 0, err
  390. }
  391. return outbidding, nil
  392. }
  393. // AuctionSetAllocationRatio is the interface to call the smart contract function
  394. func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (*types.Transaction, error) {
  395. var tx *types.Transaction
  396. var err error
  397. if tx, err = c.client.CallAuth(
  398. c.gasLimit,
  399. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  400. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  401. if err != nil {
  402. return nil, err
  403. }
  404. return auction.SetAllocationRatio(auth, newAllocationRatio)
  405. },
  406. ); err != nil {
  407. return nil, fmt.Errorf("Failed setting allocationRatio: %w", err)
  408. }
  409. return tx, nil
  410. }
  411. // AuctionGetAllocationRatio is the interface to call the smart contract function
  412. func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint16, error) {
  413. var allocationRation [3]uint16
  414. if err := c.client.Call(func(ec *ethclient.Client) error {
  415. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  416. if err != nil {
  417. return err
  418. }
  419. allocationRation, err = auction.GetAllocationRatio(nil)
  420. return err
  421. }); err != nil {
  422. return [3]uint16{}, err
  423. }
  424. return allocationRation, nil
  425. }
  426. // AuctionSetDonationAddress is the interface to call the smart contract function
  427. func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error) {
  428. var tx *types.Transaction
  429. var err error
  430. if tx, err = c.client.CallAuth(
  431. c.gasLimit,
  432. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  433. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  434. if err != nil {
  435. return nil, err
  436. }
  437. return auction.SetDonationAddress(auth, newDonationAddress)
  438. },
  439. ); err != nil {
  440. return nil, fmt.Errorf("Failed setting donationAddress: %w", err)
  441. }
  442. return tx, nil
  443. }
  444. // AuctionGetDonationAddress is the interface to call the smart contract function
  445. func (c *AuctionClient) AuctionGetDonationAddress() (*ethCommon.Address, error) {
  446. var donationAddress ethCommon.Address
  447. if err := c.client.Call(func(ec *ethclient.Client) error {
  448. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  449. if err != nil {
  450. return err
  451. }
  452. donationAddress, err = auction.GetDonationAddress(nil)
  453. return err
  454. }); err != nil {
  455. return nil, err
  456. }
  457. return &donationAddress, nil
  458. }
  459. // AuctionSetBootCoordinator is the interface to call the smart contract function
  460. func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error) {
  461. var tx *types.Transaction
  462. var err error
  463. if tx, err = c.client.CallAuth(
  464. c.gasLimit,
  465. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  466. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  467. if err != nil {
  468. return nil, err
  469. }
  470. return auction.SetBootCoordinator(auth, newBootCoordinator)
  471. },
  472. ); err != nil {
  473. return nil, fmt.Errorf("Failed setting bootCoordinator: %w", err)
  474. }
  475. return tx, nil
  476. }
  477. // AuctionGetBootCoordinator is the interface to call the smart contract function
  478. func (c *AuctionClient) AuctionGetBootCoordinator() (*ethCommon.Address, error) {
  479. var bootCoordinator ethCommon.Address
  480. if err := c.client.Call(func(ec *ethclient.Client) error {
  481. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  482. if err != nil {
  483. return err
  484. }
  485. bootCoordinator, err = auction.GetBootCoordinator(nil)
  486. return err
  487. }); err != nil {
  488. return nil, err
  489. }
  490. return &bootCoordinator, nil
  491. }
  492. // AuctionChangeDefaultSlotSetBid is the interface to call the smart contract function
  493. func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
  494. var tx *types.Transaction
  495. var err error
  496. if tx, err = c.client.CallAuth(
  497. c.gasLimit,
  498. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  499. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  500. if err != nil {
  501. return nil, err
  502. }
  503. slotSetToSend := big.NewInt(slotSet)
  504. return auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid)
  505. },
  506. ); err != nil {
  507. return nil, fmt.Errorf("Failed changing slotSet Bid: %w", err)
  508. }
  509. return tx, nil
  510. }
  511. // AuctionGetClaimableHEZ is the interface to call the smart contract function
  512. func (c *AuctionClient) AuctionGetClaimableHEZ(claimAddress ethCommon.Address) (*big.Int, error) {
  513. var claimableHEZ *big.Int
  514. if err := c.client.Call(func(ec *ethclient.Client) error {
  515. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  516. if err != nil {
  517. return err
  518. }
  519. claimableHEZ, err = auction.GetClaimableHEZ(nil, claimAddress)
  520. return err
  521. }); err != nil {
  522. return nil, err
  523. }
  524. return claimableHEZ, nil
  525. }
  526. // AuctionRegisterCoordinator is the interface to call the smart contract function
  527. func (c *AuctionClient) AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error) {
  528. var tx *types.Transaction
  529. var err error
  530. if tx, err = c.client.CallAuth(
  531. c.gasLimit,
  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. return auction.RegisterCoordinator(auth, forgerAddress, URL)
  538. },
  539. ); err != nil {
  540. return nil, fmt.Errorf("Failed register coordinator: %w", err)
  541. }
  542. return tx, nil
  543. }
  544. // AuctionIsRegisteredCoordinator is the interface to call the smart contract function
  545. func (c *AuctionClient) AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error) {
  546. var registered bool
  547. if err := c.client.Call(func(ec *ethclient.Client) error {
  548. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  549. if err != nil {
  550. return err
  551. }
  552. registered, err = auction.IsRegisteredCoordinator(nil, forgerAddress)
  553. return err
  554. }); err != nil {
  555. return false, err
  556. }
  557. return registered, nil
  558. }
  559. // AuctionUpdateCoordinatorInfo is the interface to call the smart contract function
  560. func (c *AuctionClient) AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error) {
  561. var tx *types.Transaction
  562. var err error
  563. if tx, err = c.client.CallAuth(
  564. c.gasLimit,
  565. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  566. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  567. if err != nil {
  568. return nil, err
  569. }
  570. return auction.UpdateCoordinatorInfo(auth, forgerAddress, newWithdrawAddress, newURL)
  571. },
  572. ); err != nil {
  573. return nil, fmt.Errorf("Failed update coordinator info: %w", err)
  574. }
  575. return tx, nil
  576. }
  577. // AuctionGetCurrentSlotNumber is the interface to call the smart contract function
  578. func (c *AuctionClient) AuctionGetCurrentSlotNumber() (int64, error) {
  579. var _currentSlotNumber *big.Int
  580. if err := c.client.Call(func(ec *ethclient.Client) error {
  581. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  582. if err != nil {
  583. return err
  584. }
  585. _currentSlotNumber, err = auction.GetCurrentSlotNumber(nil)
  586. return err
  587. }); err != nil {
  588. return 0, err
  589. }
  590. currentSlotNumber := _currentSlotNumber.Int64()
  591. return currentSlotNumber, nil
  592. }
  593. // AuctionGetMinBidBySlot is the interface to call the smart contract function
  594. func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) {
  595. var minBid *big.Int
  596. if err := c.client.Call(func(ec *ethclient.Client) error {
  597. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  598. if err != nil {
  599. return err
  600. }
  601. slotToSend := big.NewInt(slot)
  602. minBid, err = auction.GetMinBidBySlot(nil, slotToSend)
  603. return err
  604. }); err != nil {
  605. return big.NewInt(0), err
  606. }
  607. return minBid, nil
  608. }
  609. // AuctionGetSlotSet is the interface to call the smart contract function
  610. func (c *AuctionClient) AuctionGetSlotSet(slot int64) (*big.Int, error) {
  611. var slotSet *big.Int
  612. if err := c.client.Call(func(ec *ethclient.Client) error {
  613. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  614. if err != nil {
  615. return err
  616. }
  617. slotToSend := big.NewInt(slot)
  618. slotSet, err = auction.GetSlotSet(nil, slotToSend)
  619. return err
  620. }); err != nil {
  621. return big.NewInt(0), err
  622. }
  623. return slotSet, nil
  624. }
  625. // AuctionGetDefaultSlotSetBid is the interface to call the smart contract function
  626. func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) {
  627. var minBidSlotSet *big.Int
  628. if err := c.client.Call(func(ec *ethclient.Client) error {
  629. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  630. if err != nil {
  631. return err
  632. }
  633. minBidSlotSet, err = auction.GetDefaultSlotSetBid(nil, slotSet)
  634. return err
  635. }); err != nil {
  636. return big.NewInt(0), err
  637. }
  638. return minBidSlotSet, nil
  639. }
  640. // AuctionGetSlotNumber is the interface to call the smart contract function
  641. func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (*big.Int, error) {
  642. var slot *big.Int
  643. if err := c.client.Call(func(ec *ethclient.Client) error {
  644. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  645. if err != nil {
  646. return err
  647. }
  648. blockNumBig := big.NewInt(blockNum)
  649. slot, err = auction.GetSlotNumber(nil, blockNumBig)
  650. return err
  651. }); err != nil {
  652. return big.NewInt(0), err
  653. }
  654. return slot, nil
  655. }
  656. // AuctionBid is the interface to call the smart contract function
  657. func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
  658. var tx *types.Transaction
  659. var err error
  660. if tx, err = c.client.CallAuth(
  661. c.gasLimit,
  662. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  663. tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
  664. if err != nil {
  665. return nil, err
  666. }
  667. bidFnSignature := []byte("bid(uint128,uint128,address)")
  668. hash := sha3.NewLegacyKeccak256()
  669. _, err = hash.Write(bidFnSignature)
  670. if err != nil {
  671. return nil, err
  672. }
  673. methodID := hash.Sum(nil)[:4]
  674. slotBytes := make([]byte, 8)
  675. binary.BigEndian.PutUint64(slotBytes, uint64(slot))
  676. paddedSlot := ethCommon.LeftPadBytes(slotBytes, 32)
  677. paddedAmount := ethCommon.LeftPadBytes(bidAmount.Bytes(), 32)
  678. paddedAddress := ethCommon.LeftPadBytes(forger.Bytes(), 32)
  679. var userData []byte
  680. userData = append(userData, methodID...)
  681. userData = append(userData, paddedSlot...)
  682. userData = append(userData, paddedAmount...)
  683. userData = append(userData, paddedAddress...)
  684. return tokens.Send(auth, c.address, bidAmount, userData)
  685. },
  686. ); err != nil {
  687. return nil, fmt.Errorf("Failed bid: %w", err)
  688. }
  689. return tx, nil
  690. }
  691. // AuctionMultiBid is the interface to call the smart contract function
  692. func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
  693. var tx *types.Transaction
  694. var err error
  695. if tx, err = c.client.CallAuth(
  696. c.gasLimit,
  697. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  698. tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
  699. if err != nil {
  700. return nil, err
  701. }
  702. multiBidFnSignature := []byte("multiBid(uint128,uint128,bool[6],uint128,uint128,address)")
  703. hash := sha3.NewLegacyKeccak256()
  704. _, err = hash.Write(multiBidFnSignature)
  705. if err != nil {
  706. return nil, err
  707. }
  708. methodID := hash.Sum(nil)[:4]
  709. startingSlotBytes := make([]byte, 8)
  710. binary.BigEndian.PutUint64(startingSlotBytes, uint64(startingSlot))
  711. paddedStartingSlot := ethCommon.LeftPadBytes(startingSlotBytes, 32)
  712. endingSlotBytes := make([]byte, 8)
  713. binary.BigEndian.PutUint64(endingSlotBytes, uint64(endingSlot))
  714. paddedEndingSlot := ethCommon.LeftPadBytes(endingSlotBytes, 32)
  715. paddedMinBid := ethCommon.LeftPadBytes(closedMinBid.Bytes(), 32)
  716. paddedMaxBid := ethCommon.LeftPadBytes(maxBid.Bytes(), 32)
  717. paddedAddress := ethCommon.LeftPadBytes(forger.Bytes(), 32)
  718. var userData []byte
  719. userData = append(userData, methodID...)
  720. userData = append(userData, paddedStartingSlot...)
  721. userData = append(userData, paddedEndingSlot...)
  722. for i := 0; i < len(slotSet); i++ {
  723. if slotSet[i] {
  724. paddedSlotSet := ethCommon.LeftPadBytes([]byte{1}, 32)
  725. userData = append(userData, paddedSlotSet...)
  726. } else {
  727. paddedSlotSet := ethCommon.LeftPadBytes([]byte{0}, 32)
  728. userData = append(userData, paddedSlotSet...)
  729. }
  730. }
  731. userData = append(userData, paddedMaxBid...)
  732. userData = append(userData, paddedMinBid...)
  733. userData = append(userData, paddedAddress...)
  734. return tokens.Send(auth, c.address, budget, userData)
  735. },
  736. ); err != nil {
  737. return nil, fmt.Errorf("Failed multibid: %w", err)
  738. }
  739. return tx, nil
  740. }
  741. // AuctionCanForge is the interface to call the smart contract function
  742. func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error) {
  743. var canForge bool
  744. if err := c.client.Call(func(ec *ethclient.Client) error {
  745. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  746. if err != nil {
  747. return err
  748. }
  749. canForge, err = auction.CanForge(nil, forger, big.NewInt(blockNum))
  750. return err
  751. }); err != nil {
  752. return false, err
  753. }
  754. return canForge, nil
  755. }
  756. // AuctionForge is the interface to call the smart contract function
  757. // func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (bool, error) {
  758. // return false, errTODO
  759. // }
  760. // AuctionClaimHEZ is the interface to call the smart contract function
  761. func (c *AuctionClient) AuctionClaimHEZ(claimAddress ethCommon.Address) (*types.Transaction, error) {
  762. var tx *types.Transaction
  763. var err error
  764. if tx, err = c.client.CallAuth(
  765. c.gasLimit,
  766. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  767. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  768. if err != nil {
  769. return nil, err
  770. }
  771. return auction.ClaimHEZ(auth, claimAddress)
  772. },
  773. ); err != nil {
  774. return nil, fmt.Errorf("Failed claim HEZ: %w", err)
  775. }
  776. return tx, nil
  777. }
  778. // AuctionForge is the interface to call the smart contract function
  779. func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (*types.Transaction, error) {
  780. var tx *types.Transaction
  781. var err error
  782. if tx, err = c.client.CallAuth(
  783. c.gasLimit,
  784. func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
  785. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  786. if err != nil {
  787. return nil, err
  788. }
  789. return auction.Forge(auth, forger)
  790. },
  791. ); err != nil {
  792. return nil, fmt.Errorf("Failed forge: %w", err)
  793. }
  794. return tx, nil
  795. }
  796. // AuctionConstants returns the Constants of the Auction Smart Contract
  797. func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
  798. auctionConstants := new(AuctionConstants)
  799. if err := c.client.Call(func(ec *ethclient.Client) error {
  800. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  801. if err != nil {
  802. return err
  803. }
  804. auctionConstants.BlocksPerSlot, err = auction.BLOCKSPERSLOT(nil)
  805. if err != nil {
  806. return err
  807. }
  808. genesisBlock, err := auction.GenesisBlock(nil)
  809. if err != nil {
  810. return err
  811. }
  812. auctionConstants.GenesisBlockNum = genesisBlock.Int64()
  813. auctionConstants.HermezRollup, err = auction.HermezRollup(nil)
  814. if err != nil {
  815. return err
  816. }
  817. auctionConstants.InitialMinimalBidding, err = auction.INITIALMINIMALBIDDING(nil)
  818. if err != nil {
  819. return err
  820. }
  821. auctionConstants.TokenHEZ, err = auction.TokenHEZ(nil)
  822. return err
  823. }); err != nil {
  824. return nil, err
  825. }
  826. return auctionConstants, nil
  827. }
  828. // AuctionVariables returns the variables of the Auction Smart Contract
  829. func (c *AuctionClient) AuctionVariables() (*AuctionVariables, error) {
  830. auctionVariables := new(AuctionVariables)
  831. if err := c.client.Call(func(ec *ethclient.Client) error {
  832. var err error
  833. auctionVariables.AllocationRatio, err = c.AuctionGetAllocationRatio()
  834. if err != nil {
  835. return err
  836. }
  837. bootCoordinator, err := c.AuctionGetBootCoordinator()
  838. if err != nil {
  839. return err
  840. }
  841. auctionVariables.BootCoordinator = *bootCoordinator
  842. auctionVariables.ClosedAuctionSlots, err = c.AuctionGetClosedAuctionSlots()
  843. if err != nil {
  844. return err
  845. }
  846. var defaultSlotSetBid [6]*big.Int
  847. for i := uint8(0); i < 6; i++ {
  848. bid, err := c.AuctionGetDefaultSlotSetBid(i)
  849. if err != nil {
  850. return err
  851. }
  852. defaultSlotSetBid[i] = bid
  853. }
  854. auctionVariables.DefaultSlotSetBid = defaultSlotSetBid
  855. donationAddress, err := c.AuctionGetDonationAddress()
  856. if err != nil {
  857. return err
  858. }
  859. auctionVariables.DonationAddress = *donationAddress
  860. auctionVariables.OpenAuctionSlots, err = c.AuctionGetOpenAuctionSlots()
  861. if err != nil {
  862. return err
  863. }
  864. auctionVariables.Outbidding, err = c.AuctionGetOutbidding()
  865. if err != nil {
  866. return err
  867. }
  868. auctionVariables.SlotDeadline, err = c.AuctionGetSlotDeadline()
  869. return err
  870. }); err != nil {
  871. return nil, err
  872. }
  873. return auctionVariables, nil
  874. }
  875. var (
  876. logNewBid = crypto.Keccak256Hash([]byte("NewBid(uint128,uint128,address)"))
  877. logNewSlotDeadline = crypto.Keccak256Hash([]byte("NewSlotDeadline(uint8)"))
  878. logNewClosedAuctionSlots = crypto.Keccak256Hash([]byte("NewClosedAuctionSlots(uint16)"))
  879. logNewOutbidding = crypto.Keccak256Hash([]byte("NewOutbidding(uint16)"))
  880. logNewDonationAddress = crypto.Keccak256Hash([]byte("NewDonationAddress(address)"))
  881. logNewBootCoordinator = crypto.Keccak256Hash([]byte("NewBootCoordinator(address)"))
  882. logNewOpenAuctionSlots = crypto.Keccak256Hash([]byte("NewOpenAuctionSlots(uint16)"))
  883. logNewAllocationRatio = crypto.Keccak256Hash([]byte("NewAllocationRatio(uint16[3])"))
  884. logNewCoordinator = crypto.Keccak256Hash([]byte("NewCoordinator(address,address,string)"))
  885. logCoordinatorUpdated = crypto.Keccak256Hash([]byte("CoordinatorUpdated(address,address,string)"))
  886. logNewForgeAllocated = crypto.Keccak256Hash([]byte("NewForgeAllocated(address,uint128,uint128,uint128,uint128)"))
  887. logNewDefaultSlotSetBid = crypto.Keccak256Hash([]byte("NewDefaultSlotSetBid(uint128,uint128)"))
  888. logNewForge = crypto.Keccak256Hash([]byte("NewForge(address,uint128)"))
  889. logHEZClaimed = crypto.Keccak256Hash([]byte("HEZClaimed(address,uint128)"))
  890. )
  891. // AuctionEventsByBlock returns the events in a block that happened in the
  892. // Auction Smart Contract and the blockHash where the eents happened. If there
  893. // are no events in that block, blockHash is nil.
  894. func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error) {
  895. var auctionEvents AuctionEvents
  896. var blockHash ethCommon.Hash
  897. query := ethereum.FilterQuery{
  898. FromBlock: big.NewInt(blockNum),
  899. ToBlock: big.NewInt(blockNum),
  900. Addresses: []ethCommon.Address{
  901. c.address,
  902. },
  903. Topics: [][]ethCommon.Hash{},
  904. }
  905. logs, err := c.client.client.FilterLogs(context.TODO(), query)
  906. if err != nil {
  907. return nil, nil, err
  908. }
  909. if len(logs) > 0 {
  910. blockHash = logs[0].BlockHash
  911. }
  912. for _, vLog := range logs {
  913. if vLog.BlockHash != blockHash {
  914. return nil, nil, ErrBlockHashMismatchEvent
  915. }
  916. switch vLog.Topics[0] {
  917. case logNewBid:
  918. var auxNewBid struct {
  919. Slot *big.Int
  920. BidAmount *big.Int
  921. Address ethCommon.Address
  922. }
  923. var newBid AuctionEventNewBid
  924. if err := c.contractAbi.Unpack(&auxNewBid, "NewBid", vLog.Data); err != nil {
  925. return nil, nil, err
  926. }
  927. newBid.BidAmount = auxNewBid.BidAmount
  928. newBid.Slot = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
  929. newBid.CoordinatorForger = ethCommon.BytesToAddress(vLog.Topics[2].Bytes())
  930. auctionEvents.NewBid = append(auctionEvents.NewBid, newBid)
  931. case logNewSlotDeadline:
  932. var newSlotDeadline AuctionEventNewSlotDeadline
  933. if err := c.contractAbi.Unpack(&newSlotDeadline, "NewSlotDeadline", vLog.Data); err != nil {
  934. return nil, nil, err
  935. }
  936. auctionEvents.NewSlotDeadline = append(auctionEvents.NewSlotDeadline, newSlotDeadline)
  937. case logNewClosedAuctionSlots:
  938. var newClosedAuctionSlots AuctionEventNewClosedAuctionSlots
  939. if err := c.contractAbi.Unpack(&newClosedAuctionSlots, "NewClosedAuctionSlots", vLog.Data); err != nil {
  940. return nil, nil, err
  941. }
  942. auctionEvents.NewClosedAuctionSlots = append(auctionEvents.NewClosedAuctionSlots, newClosedAuctionSlots)
  943. case logNewOutbidding:
  944. var newOutbidding AuctionEventNewOutbidding
  945. if err := c.contractAbi.Unpack(&newOutbidding, "NewOutbidding", vLog.Data); err != nil {
  946. return nil, nil, err
  947. }
  948. auctionEvents.NewOutbidding = append(auctionEvents.NewOutbidding, newOutbidding)
  949. case logNewDonationAddress:
  950. var newDonationAddress AuctionEventNewDonationAddress
  951. if err := c.contractAbi.Unpack(&newDonationAddress, "NewDonationAddress", vLog.Data); err != nil {
  952. return nil, nil, err
  953. }
  954. auctionEvents.NewDonationAddress = append(auctionEvents.NewDonationAddress, newDonationAddress)
  955. case logNewBootCoordinator:
  956. var newBootCoordinator AuctionEventNewBootCoordinator
  957. if err := c.contractAbi.Unpack(&newBootCoordinator, "NewBootCoordinator", vLog.Data); err != nil {
  958. return nil, nil, err
  959. }
  960. auctionEvents.NewBootCoordinator = append(auctionEvents.NewBootCoordinator, newBootCoordinator)
  961. case logNewOpenAuctionSlots:
  962. var newOpenAuctionSlots AuctionEventNewOpenAuctionSlots
  963. if err := c.contractAbi.Unpack(&newOpenAuctionSlots, "NewOpenAuctionSlots", vLog.Data); err != nil {
  964. return nil, nil, err
  965. }
  966. auctionEvents.NewOpenAuctionSlots = append(auctionEvents.NewOpenAuctionSlots, newOpenAuctionSlots)
  967. case logNewAllocationRatio:
  968. var newAllocationRatio AuctionEventNewAllocationRatio
  969. if err := c.contractAbi.Unpack(&newAllocationRatio, "NewAllocationRatio", vLog.Data); err != nil {
  970. return nil, nil, err
  971. }
  972. auctionEvents.NewAllocationRatio = append(auctionEvents.NewAllocationRatio, newAllocationRatio)
  973. case logNewCoordinator:
  974. var newCoordinator AuctionEventNewCoordinator
  975. if err := c.contractAbi.Unpack(&newCoordinator, "NewCoordinator", vLog.Data); err != nil {
  976. return nil, nil, err
  977. }
  978. auctionEvents.NewCoordinator = append(auctionEvents.NewCoordinator, newCoordinator)
  979. case logCoordinatorUpdated:
  980. var coordinatorUpdated AuctionEventCoordinatorUpdated
  981. if err := c.contractAbi.Unpack(&coordinatorUpdated, "CoordinatorUpdated", vLog.Data); err != nil {
  982. return nil, nil, err
  983. }
  984. auctionEvents.CoordinatorUpdated = append(auctionEvents.CoordinatorUpdated, coordinatorUpdated)
  985. case logNewForgeAllocated:
  986. var newForgeAllocated AuctionEventNewForgeAllocated
  987. if err := c.contractAbi.Unpack(&newForgeAllocated, "NewForgeAllocated", vLog.Data); err != nil {
  988. return nil, nil, err
  989. }
  990. newForgeAllocated.Forger = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
  991. newForgeAllocated.CurrentSlot = new(big.Int).SetBytes(vLog.Topics[2][:]).Int64()
  992. auctionEvents.NewForgeAllocated = append(auctionEvents.NewForgeAllocated, newForgeAllocated)
  993. case logNewDefaultSlotSetBid:
  994. var auxNewDefaultSlotSetBid struct {
  995. SlotSet *big.Int
  996. NewInitialMinBid *big.Int
  997. }
  998. var newDefaultSlotSetBid AuctionEventNewDefaultSlotSetBid
  999. if err := c.contractAbi.Unpack(&auxNewDefaultSlotSetBid, "NewDefaultSlotSetBid", vLog.Data); err != nil {
  1000. return nil, nil, err
  1001. }
  1002. newDefaultSlotSetBid.NewInitialMinBid = auxNewDefaultSlotSetBid.NewInitialMinBid
  1003. newDefaultSlotSetBid.SlotSet = auxNewDefaultSlotSetBid.SlotSet.Int64()
  1004. auctionEvents.NewDefaultSlotSetBid = append(auctionEvents.NewDefaultSlotSetBid, newDefaultSlotSetBid)
  1005. case logNewForge:
  1006. var newForge AuctionEventNewForge
  1007. newForge.Forger = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
  1008. newForge.CurrentSlot = new(big.Int).SetBytes(vLog.Topics[2][:]).Int64()
  1009. auctionEvents.NewForge = append(auctionEvents.NewForge, newForge)
  1010. case logHEZClaimed:
  1011. var HEZClaimed AuctionEventHEZClaimed
  1012. if err := c.contractAbi.Unpack(&HEZClaimed, "HEZClaimed", vLog.Data); err != nil {
  1013. return nil, nil, err
  1014. }
  1015. HEZClaimed.Owner = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
  1016. auctionEvents.HEZClaimed = append(auctionEvents.HEZClaimed, HEZClaimed)
  1017. }
  1018. }
  1019. return &auctionEvents, &blockHash, nil
  1020. }