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.

1065 lines
38 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 {
  249. contractAbi, err := abi.JSON(strings.NewReader(string(HermezAuctionProtocol.HermezAuctionProtocolABI)))
  250. if err != nil {
  251. fmt.Println(err)
  252. }
  253. return &AuctionClient{
  254. client: client,
  255. address: address,
  256. tokenAddress: tokenAddress,
  257. gasLimit: 1000000, //nolint:gomnd
  258. contractAbi: contractAbi,
  259. }
  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. // AuctionConstants returns the Constants of the Auction Smart Contract
  779. func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
  780. auctionConstants := new(AuctionConstants)
  781. if err := c.client.Call(func(ec *ethclient.Client) error {
  782. auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
  783. if err != nil {
  784. return err
  785. }
  786. auctionConstants.BlocksPerSlot, err = auction.BLOCKSPERSLOT(nil)
  787. if err != nil {
  788. return err
  789. }
  790. genesisBlock, err := auction.GenesisBlock(nil)
  791. if err != nil {
  792. return err
  793. }
  794. auctionConstants.GenesisBlockNum = genesisBlock.Int64()
  795. auctionConstants.HermezRollup, err = auction.HermezRollup(nil)
  796. if err != nil {
  797. return err
  798. }
  799. auctionConstants.InitialMinimalBidding, err = auction.INITIALMINIMALBIDDING(nil)
  800. if err != nil {
  801. return err
  802. }
  803. auctionConstants.TokenHEZ, err = auction.TokenHEZ(nil)
  804. return err
  805. }); err != nil {
  806. return nil, err
  807. }
  808. return auctionConstants, nil
  809. }
  810. // AuctionVariables returns the variables of the Auction Smart Contract
  811. func (c *AuctionClient) AuctionVariables() (*AuctionVariables, error) {
  812. auctionVariables := new(AuctionVariables)
  813. if err := c.client.Call(func(ec *ethclient.Client) error {
  814. var err error
  815. auctionVariables.AllocationRatio, err = c.AuctionGetAllocationRatio()
  816. if err != nil {
  817. return err
  818. }
  819. bootCoordinator, err := c.AuctionGetBootCoordinator()
  820. if err != nil {
  821. return err
  822. }
  823. auctionVariables.BootCoordinator = *bootCoordinator
  824. auctionVariables.ClosedAuctionSlots, err = c.AuctionGetClosedAuctionSlots()
  825. if err != nil {
  826. return err
  827. }
  828. var defaultSlotSetBid [6]*big.Int
  829. for i := uint8(0); i < 6; i++ {
  830. bid, err := c.AuctionGetDefaultSlotSetBid(i)
  831. if err != nil {
  832. return err
  833. }
  834. defaultSlotSetBid[i] = bid
  835. }
  836. auctionVariables.DefaultSlotSetBid = defaultSlotSetBid
  837. donationAddress, err := c.AuctionGetDonationAddress()
  838. if err != nil {
  839. return err
  840. }
  841. auctionVariables.DonationAddress = *donationAddress
  842. auctionVariables.OpenAuctionSlots, err = c.AuctionGetOpenAuctionSlots()
  843. if err != nil {
  844. return err
  845. }
  846. auctionVariables.Outbidding, err = c.AuctionGetOutbidding()
  847. if err != nil {
  848. return err
  849. }
  850. auctionVariables.SlotDeadline, err = c.AuctionGetSlotDeadline()
  851. return err
  852. }); err != nil {
  853. return nil, err
  854. }
  855. return auctionVariables, nil
  856. }
  857. var (
  858. logNewBid = crypto.Keccak256Hash([]byte("NewBid(uint128,uint128,address)"))
  859. logNewSlotDeadline = crypto.Keccak256Hash([]byte("NewSlotDeadline(uint8)"))
  860. logNewClosedAuctionSlots = crypto.Keccak256Hash([]byte("NewClosedAuctionSlots(uint16)"))
  861. logNewOutbidding = crypto.Keccak256Hash([]byte("NewOutbidding(uint16)"))
  862. logNewDonationAddress = crypto.Keccak256Hash([]byte("NewDonationAddress(address)"))
  863. logNewBootCoordinator = crypto.Keccak256Hash([]byte("NewBootCoordinator(address)"))
  864. logNewOpenAuctionSlots = crypto.Keccak256Hash([]byte("NewOpenAuctionSlots(uint16)"))
  865. logNewAllocationRatio = crypto.Keccak256Hash([]byte("NewAllocationRatio(uint16[3])"))
  866. logNewCoordinator = crypto.Keccak256Hash([]byte("NewCoordinator(address,address,string)"))
  867. logCoordinatorUpdated = crypto.Keccak256Hash([]byte("CoordinatorUpdated(address,address,string)"))
  868. logNewForgeAllocated = crypto.Keccak256Hash([]byte("NewForgeAllocated(address,uint128,uint128,uint128,uint128)"))
  869. logNewDefaultSlotSetBid = crypto.Keccak256Hash([]byte("NewDefaultSlotSetBid(uint128,uint128)"))
  870. logNewForge = crypto.Keccak256Hash([]byte("NewForge(address,uint128)"))
  871. logHEZClaimed = crypto.Keccak256Hash([]byte("HEZClaimed(address,uint128)"))
  872. )
  873. // AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract
  874. func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error) {
  875. var auctionEvents AuctionEvents
  876. query := ethereum.FilterQuery{
  877. FromBlock: big.NewInt(blockNum),
  878. ToBlock: big.NewInt(blockNum),
  879. Addresses: []ethCommon.Address{
  880. c.address,
  881. },
  882. BlockHash: nil, // TODO: Maybe we can put the blockHash here to make sure we get the results from the known block.
  883. Topics: [][]ethCommon.Hash{},
  884. }
  885. logs, err := c.client.client.FilterLogs(context.TODO(), query)
  886. if err != nil {
  887. fmt.Println(err)
  888. }
  889. for _, vLog := range logs {
  890. switch vLog.Topics[0] {
  891. case logNewBid:
  892. var auxNewBid struct {
  893. Slot *big.Int
  894. BidAmount *big.Int
  895. Address ethCommon.Address
  896. }
  897. var newBid AuctionEventNewBid
  898. if err := c.contractAbi.Unpack(&auxNewBid, "NewBid", vLog.Data); err != nil {
  899. return nil, nil, err
  900. }
  901. newBid.BidAmount = auxNewBid.BidAmount
  902. newBid.Slot = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
  903. newBid.CoordinatorForger = ethCommon.BytesToAddress(vLog.Topics[2].Bytes())
  904. auctionEvents.NewBid = append(auctionEvents.NewBid, newBid)
  905. case logNewSlotDeadline:
  906. var newSlotDeadline AuctionEventNewSlotDeadline
  907. if err := c.contractAbi.Unpack(&newSlotDeadline, "NewSlotDeadline", vLog.Data); err != nil {
  908. return nil, nil, err
  909. }
  910. auctionEvents.NewSlotDeadline = append(auctionEvents.NewSlotDeadline, newSlotDeadline)
  911. case logNewClosedAuctionSlots:
  912. var newClosedAuctionSlots AuctionEventNewClosedAuctionSlots
  913. if err := c.contractAbi.Unpack(&newClosedAuctionSlots, "NewClosedAuctionSlots", vLog.Data); err != nil {
  914. return nil, nil, err
  915. }
  916. auctionEvents.NewClosedAuctionSlots = append(auctionEvents.NewClosedAuctionSlots, newClosedAuctionSlots)
  917. case logNewOutbidding:
  918. var newOutbidding AuctionEventNewOutbidding
  919. if err := c.contractAbi.Unpack(&newOutbidding, "NewOutbidding", vLog.Data); err != nil {
  920. return nil, nil, err
  921. }
  922. auctionEvents.NewOutbidding = append(auctionEvents.NewOutbidding, newOutbidding)
  923. case logNewDonationAddress:
  924. var newDonationAddress AuctionEventNewDonationAddress
  925. if err := c.contractAbi.Unpack(&newDonationAddress, "NewDonationAddress", vLog.Data); err != nil {
  926. return nil, nil, err
  927. }
  928. auctionEvents.NewDonationAddress = append(auctionEvents.NewDonationAddress, newDonationAddress)
  929. case logNewBootCoordinator:
  930. var newBootCoordinator AuctionEventNewBootCoordinator
  931. if err := c.contractAbi.Unpack(&newBootCoordinator, "NewBootCoordinator", vLog.Data); err != nil {
  932. return nil, nil, err
  933. }
  934. auctionEvents.NewBootCoordinator = append(auctionEvents.NewBootCoordinator, newBootCoordinator)
  935. case logNewOpenAuctionSlots:
  936. var newOpenAuctionSlots AuctionEventNewOpenAuctionSlots
  937. if err := c.contractAbi.Unpack(&newOpenAuctionSlots, "NewOpenAuctionSlots", vLog.Data); err != nil {
  938. return nil, nil, err
  939. }
  940. auctionEvents.NewOpenAuctionSlots = append(auctionEvents.NewOpenAuctionSlots, newOpenAuctionSlots)
  941. case logNewAllocationRatio:
  942. var newAllocationRatio AuctionEventNewAllocationRatio
  943. if err := c.contractAbi.Unpack(&newAllocationRatio, "NewAllocationRatio", vLog.Data); err != nil {
  944. return nil, nil, err
  945. }
  946. auctionEvents.NewAllocationRatio = append(auctionEvents.NewAllocationRatio, newAllocationRatio)
  947. case logNewCoordinator:
  948. var newCoordinator AuctionEventNewCoordinator
  949. if err := c.contractAbi.Unpack(&newCoordinator, "NewCoordinator", vLog.Data); err != nil {
  950. return nil, nil, err
  951. }
  952. auctionEvents.NewCoordinator = append(auctionEvents.NewCoordinator, newCoordinator)
  953. case logCoordinatorUpdated:
  954. var coordinatorUpdated AuctionEventCoordinatorUpdated
  955. if err := c.contractAbi.Unpack(&coordinatorUpdated, "CoordinatorUpdated", vLog.Data); err != nil {
  956. return nil, nil, err
  957. }
  958. auctionEvents.CoordinatorUpdated = append(auctionEvents.CoordinatorUpdated, coordinatorUpdated)
  959. case logNewForgeAllocated:
  960. var newForgeAllocated AuctionEventNewForgeAllocated
  961. if err := c.contractAbi.Unpack(&newForgeAllocated, "NewForgeAllocated", vLog.Data); err != nil {
  962. return nil, nil, err
  963. }
  964. newForgeAllocated.Forger = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
  965. newForgeAllocated.CurrentSlot = new(big.Int).SetBytes(vLog.Topics[2][:]).Int64()
  966. auctionEvents.NewForgeAllocated = append(auctionEvents.NewForgeAllocated, newForgeAllocated)
  967. case logNewDefaultSlotSetBid:
  968. var auxNewDefaultSlotSetBid struct {
  969. SlotSet *big.Int
  970. NewInitialMinBid *big.Int
  971. }
  972. var newDefaultSlotSetBid AuctionEventNewDefaultSlotSetBid
  973. if err := c.contractAbi.Unpack(&auxNewDefaultSlotSetBid, "NewDefaultSlotSetBid", vLog.Data); err != nil {
  974. return nil, nil, err
  975. }
  976. newDefaultSlotSetBid.NewInitialMinBid = auxNewDefaultSlotSetBid.NewInitialMinBid
  977. newDefaultSlotSetBid.SlotSet = auxNewDefaultSlotSetBid.SlotSet.Int64()
  978. auctionEvents.NewDefaultSlotSetBid = append(auctionEvents.NewDefaultSlotSetBid, newDefaultSlotSetBid)
  979. case logNewForge:
  980. var newForge AuctionEventNewForge
  981. newForge.Forger = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
  982. newForge.CurrentSlot = new(big.Int).SetBytes(vLog.Topics[2][:]).Int64()
  983. auctionEvents.NewForge = append(auctionEvents.NewForge, newForge)
  984. case logHEZClaimed:
  985. var HEZClaimed AuctionEventHEZClaimed
  986. if err := c.contractAbi.Unpack(&HEZClaimed, "HEZClaimed", vLog.Data); err != nil {
  987. return nil, nil, err
  988. }
  989. HEZClaimed.Owner = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
  990. auctionEvents.HEZClaimed = append(auctionEvents.HEZClaimed, HEZClaimed)
  991. }
  992. }
  993. return &auctionEvents, nil, nil
  994. }