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