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.

214 lines
7.9 KiB

  1. package eth
  2. import (
  3. "math/big"
  4. ethCommon "github.com/ethereum/go-ethereum/common"
  5. "github.com/ethereum/go-ethereum/core/types"
  6. )
  7. // WDelayerConstants are the constants of the Rollup Smart Contract
  8. type WDelayerConstants struct {
  9. // Max Withdrawal Delay
  10. MaxWithdrawalDelay uint64
  11. // Max Emergency mode time
  12. MaxEmergencyModeTime uint64
  13. // HermezRollup smartcontract address
  14. HermezRollup ethCommon.Address
  15. }
  16. // DepositState is the state of Deposit
  17. type DepositState struct {
  18. Amount *big.Int
  19. DepositTimestamp uint64
  20. }
  21. // WDelayerEventDeposit is an event of the WithdrawalDelayer Smart Contract
  22. type WDelayerEventDeposit struct {
  23. Owner ethCommon.Address
  24. Token ethCommon.Address
  25. Amount *big.Int
  26. DepositTimestamp uint64
  27. }
  28. // WDelayerEventWithdraw is an event of the WithdrawalDelayer Smart Contract
  29. type WDelayerEventWithdraw struct {
  30. Owner ethCommon.Address
  31. Token ethCommon.Address
  32. Amount *big.Int
  33. }
  34. // WDelayerEventEmergencyModeEnabled an event of the WithdrawalDelayer Smart Contract
  35. type WDelayerEventEmergencyModeEnabled struct {
  36. }
  37. // WDelayerEventNewWithdrawalDelay an event of the WithdrawalDelayer Smart Contract
  38. type WDelayerEventNewWithdrawalDelay struct {
  39. WithdrawalDelay uint64
  40. }
  41. // WDelayerEventEscapeHatchWithdrawal an event of the WithdrawalDelayer Smart Contract
  42. type WDelayerEventEscapeHatchWithdrawal struct {
  43. Who ethCommon.Address
  44. To ethCommon.Address
  45. Token ethCommon.Address
  46. }
  47. // WDelayerEventNewHermezKeeperAddress an event of the WithdrawalDelayer Smart Contract
  48. type WDelayerEventNewHermezKeeperAddress struct {
  49. NewHermezKeeperAddress ethCommon.Address
  50. }
  51. // WDelayerEventNewWhiteHackGroupAddress an event of the WithdrawalDelayer Smart Contract
  52. type WDelayerEventNewWhiteHackGroupAddress struct {
  53. NewWhiteHackGroupAddress ethCommon.Address
  54. }
  55. // WDelayerEventNewHermezGovernanceDAOAddress an event of the WithdrawalDelayer Smart Contract
  56. type WDelayerEventNewHermezGovernanceDAOAddress struct {
  57. NewHermezGovernanceDAOAddress ethCommon.Address
  58. }
  59. // WDelayerEvents is the lis of events in a block of the WithdrawalDelayer Smart Contract
  60. type WDelayerEvents struct { //nolint:structcheck
  61. Deposit []WDelayerEventDeposit
  62. Withdraw []WDelayerEventWithdraw
  63. EmergencyModeEnabled []WDelayerEventEmergencyModeEnabled
  64. NewWithdrawalDelay []WDelayerEventNewWithdrawalDelay
  65. EscapeHatchWithdrawal []WDelayerEventEscapeHatchWithdrawal
  66. NewHermezKeeperAddress []WDelayerEventNewHermezKeeperAddress
  67. NewWhiteHackGroupAddress []WDelayerEventNewWhiteHackGroupAddress
  68. NewHermezGovernanceDAOAddress []WDelayerEventNewHermezGovernanceDAOAddress
  69. }
  70. // NewWDelayerEvents creates an empty WDelayerEvents with the slices initialized.
  71. func NewWDelayerEvents() WDelayerEvents {
  72. return WDelayerEvents{
  73. Deposit: make([]WDelayerEventDeposit, 0),
  74. Withdraw: make([]WDelayerEventWithdraw, 0),
  75. EmergencyModeEnabled: make([]WDelayerEventEmergencyModeEnabled, 0),
  76. NewWithdrawalDelay: make([]WDelayerEventNewWithdrawalDelay, 0),
  77. EscapeHatchWithdrawal: make([]WDelayerEventEscapeHatchWithdrawal, 0),
  78. NewHermezKeeperAddress: make([]WDelayerEventNewHermezKeeperAddress, 0),
  79. NewWhiteHackGroupAddress: make([]WDelayerEventNewWhiteHackGroupAddress, 0),
  80. NewHermezGovernanceDAOAddress: make([]WDelayerEventNewHermezGovernanceDAOAddress, 0),
  81. }
  82. }
  83. // WDelayerInterface is the inteface to WithdrawalDelayer Smart Contract
  84. type WDelayerInterface interface {
  85. //
  86. // Smart Contract Methods
  87. //
  88. WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, error)
  89. WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (*types.Transaction, error)
  90. WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error)
  91. WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (*types.Transaction, error)
  92. WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error)
  93. WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (*types.Transaction, error)
  94. WDelayerIsEmergencyMode() (bool, error)
  95. WDelayerGetWithdrawalDelay() (*big.Int, error)
  96. WDelayerGetEmergencyModeStartingTime() (*big.Int, error)
  97. WDelayerEnableEmergencyMode() (*types.Transaction, error)
  98. WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (*types.Transaction, error)
  99. WDelayerDepositInfo(owner, token ethCommon.Address) (*big.Int, uint64)
  100. WDelayerDeposit(onwer, token ethCommon.Address, amount *big.Int) (*types.Transaction, error)
  101. WDelayerWithdrawal(owner, token ethCommon.Address) (*types.Transaction, error)
  102. WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address) (*types.Transaction, error)
  103. }
  104. //
  105. // Implementation
  106. //
  107. // WDelayerClient is the implementation of the interface to the WithdrawDelayer Smart Contract in ethereum.
  108. type WDelayerClient struct {
  109. client *EthereumClient
  110. address ethCommon.Address
  111. gasLimit uint64
  112. }
  113. // NewWDelayerClient creates a new WDelayerClient
  114. func NewWDelayerClient(client *EthereumClient, address ethCommon.Address) *WDelayerClient {
  115. return &WDelayerClient{
  116. client: client,
  117. address: address,
  118. gasLimit: 1000000, //nolint:gomnd
  119. }
  120. }
  121. // WDelayerGetHermezGovernanceDAOAddress is the interface to call the smart contract function
  122. func (c *WDelayerClient) WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, error) {
  123. return nil, errTODO
  124. }
  125. // WDelayerSetHermezGovernanceDAOAddress is the interface to call the smart contract function
  126. func WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
  127. return nil, errTODO
  128. }
  129. // WDelayerGetHermezKeeperAddress is the interface to call the smart contract function
  130. func WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error) {
  131. return nil, errTODO
  132. }
  133. // WDelayerSetHermezKeeperAddress is the interface to call the smart contract function
  134. func WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
  135. return nil, errTODO
  136. }
  137. // WDelayerGetWhiteHackGroupAddress is the interface to call the smart contract function
  138. func WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error) {
  139. return nil, errTODO
  140. }
  141. // WDelayerSetWhiteHackGroupAddress is the interface to call the smart contract function
  142. func WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
  143. return nil, errTODO
  144. }
  145. // WDelayerIsEmergencyMode is the interface to call the smart contract function
  146. func WDelayerIsEmergencyMode() (bool, error) {
  147. return false, errTODO
  148. }
  149. // WDelayerGetWithdrawalDelay is the interface to call the smart contract function
  150. func WDelayerGetWithdrawalDelay() (*big.Int, error) {
  151. return nil, errTODO
  152. }
  153. // WDelayerGetEmergencyModeStartingTime is the interface to call the smart contract function
  154. func WDelayerGetEmergencyModeStartingTime() (*big.Int, error) {
  155. return nil, errTODO
  156. }
  157. // WDelayerEnableEmergencyMode is the interface to call the smart contract function
  158. func WDelayerEnableEmergencyMode() (*types.Transaction, error) {
  159. return nil, errTODO
  160. }
  161. // WDelayerChangeWithdrawalDelay is the interface to call the smart contract function
  162. func WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (*types.Transaction, error) {
  163. return nil, errTODO
  164. }
  165. // WDelayerDepositInfo is the interface to call the smart contract function
  166. func WDelayerDepositInfo(owner, token ethCommon.Address) (*big.Int, uint64, error) {
  167. return big.NewInt(0), 0, errTODO
  168. }
  169. // WDelayerDeposit is the interface to call the smart contract function
  170. func WDelayerDeposit(onwer, token ethCommon.Address, amount *big.Int) (*types.Transaction, error) {
  171. return nil, errTODO
  172. }
  173. // WDelayerWithdrawal is the interface to call the smart contract function
  174. func WDelayerWithdrawal(owner, token ethCommon.Address) (*types.Transaction, error) {
  175. return nil, errTODO
  176. }
  177. // WDelayerEscapeHatchWithdrawal is the interface to call the smart contract function
  178. func WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address) (*types.Transaction, error) {
  179. return nil, errTODO
  180. }