Merge pull request #325 from hermeznetwork/feature/ethclient-up-ev

Update ethclient
This commit is contained in:
a_bennassar
2020-12-04 11:58:52 +01:00
committed by GitHub
28 changed files with 1706 additions and 1411 deletions

View File

@@ -369,6 +369,7 @@ func TestMain(m *testing.M) {
Outbidding: uint16(1),
SlotDeadline: uint8(20),
BootCoordinator: ethCommon.HexToAddress("0x1111111111111111111111111111111111111111"),
BootCoordinatorURL: "https://boot.coordinator.io",
ClosedAuctionSlots: uint16(2),
OpenAuctionSlots: uint16(5),
}

View File

@@ -15,8 +15,7 @@ func getConfigTest() Config {
var rollupPublicConstants common.RollupConstants
rollupPublicConstants.AbsoluteMaxL1L2BatchTimeout = 240
rollupPublicConstants.HermezAuctionContract = ethCommon.HexToAddress("0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e")
rollupPublicConstants.HermezGovernanceDAOAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4")
rollupPublicConstants.SafetyAddress = ethCommon.HexToAddress("0xE5904695748fe4A84b40b3fc79De2277660BD1D3")
rollupPublicConstants.HermezGovernanceAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4")
rollupPublicConstants.TokenHEZ = ethCommon.HexToAddress("0xf784709d2317D872237C4bC22f867d1BAe2913AB")
rollupPublicConstants.WithdrawDelayerContract = ethCommon.HexToAddress("0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe")
var verifier common.RollupVerifierStruct

View File

@@ -2697,6 +2697,10 @@ components:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the boot coordinator.
- example: "0x997dc4262BCDbf85190C01c996b4C06a461d2430"
bootCoordinatorUrl:
type: string
description: Boot Coordinator URL
example: "https://boot.coordinator.io"
slotDeadline:
type: integer
description: Number of blocks after the beginning of a slot after which any coordinator can forge if the winner has not forged any batch in that slot.
@@ -2733,6 +2737,7 @@ components:
required:
- ethereumBlockNum
- bootCoordinator
- bootCoordinatorUrl
- slotDeadline
- closedAuctionSlots
- openAuctionSlots
@@ -2804,21 +2809,16 @@ components:
properties:
ethereumBlockNum:
$ref: '#/components/schemas/EthBlockNum'
hermezGovernanceDAOAddress:
hermezGovernanceAddress:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the governance DAO.
- description: Ethereum address of the governance.
- example: "0x667dc4262BCDbf85190C01c996b4C06a461d2430"
whiteHackGroupAddress:
emergencyCouncilAddress:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum Address that can claim the funds in an emergency when the maximum emergency mode time is exceeded.
- example: "0x557dc4262BCDbf85190C01c996b4C06a461d2430"
hermezKeeperAddress:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum Address that can enable emergency mode and modify the delay to make a withdrawal.
- example: "0x557dc4262BCDbf85190C01c996b4C06a461d2430"
withdrawalDelay:
allOf:
- $ref: '#/components/schemas/EthBlockNum'
@@ -2835,9 +2835,8 @@ components:
additionalProperties: false
required:
- ethereumBlockNum
- hermezGovernanceDAOAddress
- whiteHackGroupAddress
- hermezKeeperAddress
- hermezGovernanceAddress
- emergencyCouncilAddress
- withdrawalDelay
- emergencyModeStartingTime
- emergencyMode
@@ -2925,16 +2924,11 @@ components:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the auction smart contract.
- example: "0x111dc4262BCDbf85190C01c996b4C06a461d2430"
hermezGovernanceDAOAddress:
hermezGovernanceAddress:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the governanceDAO.
- description: Ethereum address of the governance.
- example: "0x222dc4262BCDbf85190C01c996b4C06a461d2430"
safetyAddress:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the safety.
- example: "0x333dc4262BCDbf85190C01c996b4C06a461d2430"
withdrawDelayerContract:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
@@ -2945,8 +2939,7 @@ components:
- absoluteMaxL1L2BatchTimeout
- verifiers
- hermezAuctionContract
- hermezGovernanceDAOAddress
- safetyAddress
- hermezGovernanceAddress
- withdrawDelayerContract
additionalProperties: false
maxFeeIdxCoordinator:

View File

@@ -25,7 +25,6 @@ type AuctionConstants struct {
// HermezRollup smartcontract address
HermezRollup ethCommon.Address `json:"hermezRollup"`
// Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee
// Only for test
GovernanceAddress ethCommon.Address `json:"governanceAddress"`
}
@@ -54,10 +53,12 @@ func (c *AuctionConstants) RelativeBlock(blockNum int64) int64 {
// AuctionVariables are the variables of the Auction Smart Contract
type AuctionVariables struct {
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
// Boot Coordinator Address
// Donation Address
DonationAddress ethCommon.Address `json:"donationAddress" meddler:"donation_address" validate:"required"`
// Boot Coordinator Address
BootCoordinator ethCommon.Address `json:"bootCoordinator" meddler:"boot_coordinator" validate:"required"`
// Boot Coordinator URL
BootCoordinatorURL string `json:"bootCoordinatorUrl" meddler:"boot_coordinator_url" validate:"required"`
// The minimum bid value in a series of 6 slots
DefaultSlotSetBid [6]*big.Int `json:"defaultSlotSetBid" meddler:"default_slot_set_bid,json" validate:"required"`
// SlotNum at which the new default_slot_set_bid applies

View File

@@ -34,8 +34,8 @@ import (
// WithdrawDelayerVars contains the Withdrawal Delayer smart contract variables
// type WithdrawDelayerVars struct {
// HermezRollupAddress eth.Address
// HermezGovernanceDAOAddress eth.Address
// WhiteHackGroupAddress eth.Address
// HermezGovernanceAddress eth.Address
// EmergencyCouncilAddress eth.Address
// WithdrawalDelay uint
// EmergencyModeStartingTime time.Time
// EmergencyModeEnabled bool
@@ -142,8 +142,7 @@ type RollupConstants struct {
TokenHEZ ethCommon.Address `json:"tokenHEZ"`
Verifiers []RollupVerifierStruct `json:"verifiers"`
HermezAuctionContract ethCommon.Address `json:"hermezAuctionContract"`
HermezGovernanceDAOAddress ethCommon.Address `json:"hermezGovernanceDAOAddress"`
SafetyAddress ethCommon.Address `json:"safetyAddress"`
HermezGovernanceAddress ethCommon.Address `json:"hermezGovernanceAddress"`
WithdrawDelayerContract ethCommon.Address `json:"withdrawDelayerContract"`
}

View File

@@ -16,12 +16,11 @@ type WDelayerConstants struct {
type WDelayerVariables struct {
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
// HermezRollupAddress ethCommon.Address `json:"hermezRollupAddress" meddler:"rollup_address"`
HermezGovernanceDAOAddress ethCommon.Address `json:"hermezGovernanceDAOAddress" meddler:"govdao_address" validate:"required"`
WhiteHackGroupAddress ethCommon.Address `json:"whiteHackGroupAddress" meddler:"whg_address" validate:"required"`
HermezKeeperAddress ethCommon.Address `json:"hermezKeeperAddress" meddler:"keeper_address" validate:"required"`
WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"`
EmergencyModeStartingTime uint64 `json:"emergencyModeStartingTime" meddler:"emergency_start_time"`
EmergencyMode bool `json:"emergencyMode" meddler:"emergency_mode"`
HermezGovernanceAddress ethCommon.Address `json:"hermezGovernanceAddress" meddler:"gov_address" validate:"required"`
EmergencyCouncilAddress ethCommon.Address `json:"emergencyCouncilAddress" meddler:"emg_address" validate:"required"`
WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"`
EmergencyModeStartingTime uint64 `json:"emergencyModeStartingTime" meddler:"emergency_start_time"`
EmergencyMode bool `json:"emergencyMode" meddler:"emergency_mode"`
}
// Copy returns a deep copy of the Variables

View File

@@ -217,6 +217,29 @@ func (tx *L1Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
return b[:], nil
}
// L1TxFromDataAvailability decodes a L1Tx from []byte (Data Availability)
func L1TxFromDataAvailability(b []byte, nLevels uint32) (*L1Tx, error) {
idxLen := nLevels / 8 //nolint:gomnd
fromIdxBytes := b[0:idxLen]
toIdxBytes := b[idxLen : idxLen*2]
amountBytes := b[idxLen*2 : idxLen*2+2]
l1tx := L1Tx{}
fromIdx, err := IdxFromBytes(ethCommon.LeftPadBytes(fromIdxBytes, 6))
if err != nil {
return nil, err
}
l1tx.FromIdx = fromIdx
toIdx, err := IdxFromBytes(ethCommon.LeftPadBytes(toIdxBytes, 6))
if err != nil {
return nil, err
}
l1tx.ToIdx = toIdx
l1tx.EffectiveAmount = Float16FromBytes(amountBytes).BigInt()
return &l1tx, nil
}
// BytesGeneric returns the generic representation of a L1Tx. This method is
// used to compute the []byte representation of a L1UserTx, and also to compute
// the L1TxData for the ZKInputs (at the HashGlobalInputs), using this method

View File

@@ -87,6 +87,33 @@ func TestBytesDataAvailability(t *testing.T) {
assert.Equal(t, "0000000200000003000400", hex.EncodeToString(txCompressedData))
}
func TestL1TxFromDataAvailability(t *testing.T) {
tx := L1Tx{
FromIdx: 2,
ToIdx: 3,
Amount: big.NewInt(4),
}
txCompressedData, err := tx.BytesDataAvailability(32)
assert.Nil(t, err)
l1tx, err := L1TxFromDataAvailability(txCompressedData, 32)
require.NoError(t, err)
assert.Equal(t, tx.FromIdx, l1tx.FromIdx)
assert.Equal(t, tx.ToIdx, l1tx.ToIdx)
tx = L1Tx{
FromIdx: 2,
ToIdx: 3,
EffectiveAmount: big.NewInt(4),
}
txCompressedData, err = tx.BytesDataAvailability(32)
assert.Nil(t, err)
l1tx, err = L1TxFromDataAvailability(txCompressedData, 32)
require.NoError(t, err)
assert.Equal(t, tx.FromIdx, l1tx.FromIdx)
assert.Equal(t, tx.ToIdx, l1tx.ToIdx)
assert.Equal(t, tx.EffectiveAmount, l1tx.EffectiveAmount)
}
func TestL1userTxByteParsers(t *testing.T) {
var pkComp babyjub.PublicKeyComp
pkCompL := []byte("0x56ca90f80d7c374ae7485e9bcc47d4ac399460948da6aeeb899311097925a72c")

View File

@@ -134,8 +134,8 @@ func (tx L2Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
return b[:], nil
}
// L2TxFromBytes decodes a L1Tx from []byte
func L2TxFromBytes(b []byte, nLevels int) (*L2Tx, error) {
// L2TxFromBytesDataAvailability decodes a L2Tx from []byte (Data Availability)
func L2TxFromBytesDataAvailability(b []byte, nLevels int) (*L2Tx, error) {
idxLen := nLevels / 8 //nolint:gomnd
tx := &L2Tx{}
var err error

View File

@@ -36,7 +36,7 @@ func TestL2TxByteParsers(t *testing.T) {
require.Nil(t, err)
assert.Equal(t, expected, hex.EncodeToString(encodedData))
decodedData, err := L2TxFromBytes(encodedData, 32)
decodedData, err := L2TxFromBytesDataAvailability(encodedData, 32)
require.Nil(t, err)
assert.Equal(t, l2Tx, decodedData)
}

View File

@@ -654,6 +654,7 @@ func exampleInitSCVars() (*common.RollupVariables, *common.AuctionVariables, *co
0,
ethCommon.BigToAddress(big.NewInt(2)),
ethCommon.BigToAddress(big.NewInt(3)),
"https://boot.coord.com",
[6]*big.Int{
big.NewInt(1), big.NewInt(2), big.NewInt(3),
big.NewInt(4), big.NewInt(5), big.NewInt(6),
@@ -670,7 +671,6 @@ func exampleInitSCVars() (*common.RollupVariables, *common.AuctionVariables, *co
0,
ethCommon.BigToAddress(big.NewInt(2)),
ethCommon.BigToAddress(big.NewInt(3)),
ethCommon.BigToAddress(big.NewInt(4)),
13,
14,
false,

View File

@@ -12,7 +12,7 @@ CREATE TABLE coordinator (
bidder_addr BYTEA NOT NULL,
forger_addr BYTEA NOT NULL,
eth_block_num BIGINT NOT NULL REFERENCES block (eth_block_num) ON DELETE CASCADE,
url VARCHAR(200) NOT NULL
url BYTEA NOT NULL
);
CREATE TABLE batch (
@@ -537,6 +537,7 @@ CREATE TABLE auction_vars (
eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE,
donation_address BYTEA NOT NULL,
boot_coordinator BYTEA NOT NULL,
boot_coordinator_url BYTEA NOT NULL,
default_slot_set_bid BYTEA NOT NULL,
default_slot_set_bid_slot_num BIGINT NOT NULL, -- slot_num after which the new default_slot_set_bid applies
closed_auction_slots INT NOT NULL,
@@ -548,9 +549,8 @@ CREATE TABLE auction_vars (
CREATE TABLE wdelayer_vars (
eth_block_num BIGINT PRIMARY KEY REFERENCES block (eth_block_num) ON DELETE CASCADE,
govdao_address BYTEA NOT NULL,
whg_address BYTEA NOT NULL,
keeper_address BYTEA NOT NULL,
gov_address BYTEA NOT NULL,
emg_address BYTEA NOT NULL,
withdrawal_delay BIGINT NOT NULL,
emergency_start_time BIGINT NOT NULL,
emergency_mode BOOLEAN NOT NULL

View File

@@ -8,7 +8,7 @@ The first step is to clone the github repository where the contracts are located
While the prepared deployment is not found to master, branch in repository must be changed:
`git checkout feature/newDeploymentScript-ethclient` (tested with commit `af4c93916d6cd93d866c121cc63b6a6794f649b2`)
`git checkout feature/newDeploymentScript-eth` (tested with commit `6335252b073dc59afafc45040dae8630c72ecdf3`)
Now, install the dependencies:
@@ -27,7 +27,7 @@ Now, in a terminal start a local blockchain with ganache:
```
Once ganache is ready, in another terminal run the deployment in the local ganache network:
```
npx buidler run --network ganache test-deployment.js
npx buidler run --network localhostMnemonic test-deployment.js
```
An output file necessary for the next step is obtained: `deploy-output`.
@@ -42,13 +42,13 @@ They must be taken from the output file of the previous step.
They can be provided by file called `.env`:
```
GENESIS_BLOCK=97
AUCTION="0x5E0816F0f8bC560cB2B9e9C87187BeCac8c2021F"
AUCTION_TEST="0x56D4563E85477AC8Aa6a3b980b831DDb18a826ec"
TOKENHEZ="0x2b7dEe2CF60484325716A1c6A193519c8c3b19F3"
HERMEZ="0x6F4e99522F4eB37e0B73D0C0373147893EF12fD5"
WDELAYER="0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77"
WDELAYER_TEST="0xdc05EFc3029024068FCc86f05323411f14D69280"
GENESIS_BLOCK=98
AUCTION="0x317113D2593e3efF1FfAE0ba2fF7A61861Df7ae5"
AUCTION_TEST="0x2b7dEe2CF60484325716A1c6A193519c8c3b19F3"
TOKENHEZ="0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77"
HERMEZ="0x8EEaea23686c319133a7cC110b840d1591d9AeE0"
WDELAYER="0x5E0816F0f8bC560cB2B9e9C87187BeCac8c2021F"
WDELAYER_TEST="0xc8F466fFeF9E9788fb363c2F4fBDdF2cAe477805"
```
> An example is found in `hermez-node/eth/.env.example`
@@ -59,4 +59,4 @@ And then run test from `hermez-node/eth/`:
Or they can be provided as a parameter in the command that runs the test:
`INTEGRATION=1 GENESIS_BLOCK=97 AUCTION="0x5E0816F0f8bC560cB2B9e9C87187BeCac8c2021F" AUCTION_TEST="0x56D4563E85477AC8Aa6a3b980b831DDb18a826ec" TOKENHEZ="0x2b7dEe2CF60484325716A1c6A193519c8c3b19F3" HERMEZ="0x6F4e99522F4eB37e0B73D0C0373147893EF12fD5" WDELAYER="0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77" WDELAYER_TEST="0xdc05EFc3029024068FCc86f05323411f14D69280" go test`
`INTEGRATION=1 GENESIS_BLOCK=98 AUCTION="0x317113D2593e3efF1FfAE0ba2fF7A61861Df7ae5" AUCTION_TEST="0x2b7dEe2CF60484325716A1c6A193519c8c3b19F3" TOKENHEZ="0x5D94e3e7aeC542aB0F9129B9a7BAdeb5B3Ca0f77" HERMEZ="0x8EEaea23686c319133a7cC110b840d1591d9AeE0" WDELAYER="0x5E0816F0f8bC560cB2B9e9C87187BeCac8c2021F" WDELAYER_TEST="0xc8F466fFeF9E9788fb363c2F4fBDdF2cAe477805" go test`

View File

@@ -32,10 +32,11 @@ type SlotState struct {
// NewSlotState returns an empty SlotState
func NewSlotState() *SlotState {
return &SlotState{
Bidder: ethCommon.Address{},
Fulfilled: false,
BidAmount: big.NewInt(0),
ClosedMinBid: big.NewInt(0),
Bidder: ethCommon.Address{},
Fulfilled: false,
ForgerCommitment: false,
BidAmount: big.NewInt(0),
ClosedMinBid: big.NewInt(0),
}
}
@@ -84,7 +85,8 @@ type AuctionEventNewDonationAddress struct {
// AuctionEventNewBootCoordinator is an event of the Auction Smart Contract
type AuctionEventNewBootCoordinator struct {
NewBootCoordinator ethCommon.Address
NewBootCoordinator ethCommon.Address
NewBootCoordinatorURL string
}
// AuctionEventNewOpenAuctionSlots is an event of the Auction Smart Contract
@@ -187,7 +189,7 @@ type AuctionInterface interface {
AuctionGetAllocationRatio() ([3]uint16, error)
AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error)
AuctionGetDonationAddress() (*ethCommon.Address, error)
AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error)
AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address, newBootCoordinatorURL string) (*types.Transaction, error)
AuctionGetBootCoordinator() (*ethCommon.Address, error)
AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error)
@@ -408,11 +410,11 @@ func (c *AuctionClient) AuctionGetDonationAddress() (donationAddress *ethCommon.
}
// AuctionSetBootCoordinator is the interface to call the smart contract function
func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (tx *types.Transaction, err error) {
func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address, newBootCoordinatorURL string) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.auction.SetBootCoordinator(auth, newBootCoordinator)
return c.auction.SetBootCoordinator(auth, newBootCoordinator, newBootCoordinatorURL)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed setting bootCoordinator: %w", err))
@@ -642,6 +644,10 @@ func (c *AuctionClient) AuctionConstants() (auctionConstants *common.AuctionCons
if err != nil {
return tracerr.Wrap(err)
}
auctionConstants.GovernanceAddress, err = c.auction.GovernanceAddress(nil)
if err != nil {
return tracerr.Wrap(err)
}
auctionConstants.TokenHEZ, err = c.auction.TokenHEZ(nil)
return tracerr.Wrap(err)
}); err != nil {
@@ -663,6 +669,10 @@ func (c *AuctionClient) AuctionVariables() (auctionVariables *common.AuctionVari
return tracerr.Wrap(err)
}
auctionVariables.BootCoordinator = *bootCoordinator
auctionVariables.BootCoordinatorURL, err = c.auction.BootCoordinatorURL(nil)
if err != nil {
return tracerr.Wrap(err)
}
auctionVariables.ClosedAuctionSlots, err = c.AuctionGetClosedAuctionSlots()
if err != nil {
return tracerr.Wrap(err)
@@ -703,7 +713,7 @@ var (
logAuctionNewClosedAuctionSlots = crypto.Keccak256Hash([]byte("NewClosedAuctionSlots(uint16)"))
logAuctionNewOutbidding = crypto.Keccak256Hash([]byte("NewOutbidding(uint16)"))
logAuctionNewDonationAddress = crypto.Keccak256Hash([]byte("NewDonationAddress(address)"))
logAuctionNewBootCoordinator = crypto.Keccak256Hash([]byte("NewBootCoordinator(address)"))
logAuctionNewBootCoordinator = crypto.Keccak256Hash([]byte("NewBootCoordinator(address,string)"))
logAuctionNewOpenAuctionSlots = crypto.Keccak256Hash([]byte("NewOpenAuctionSlots(uint16)"))
logAuctionNewAllocationRatio = crypto.Keccak256Hash([]byte("NewAllocationRatio(uint16[3])"))
logAuctionSetCoordinator = crypto.Keccak256Hash([]byte("SetCoordinator(address,address,string)"))
@@ -780,6 +790,9 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e
auctionEvents.NewDonationAddress = append(auctionEvents.NewDonationAddress, newDonationAddress)
case logAuctionNewBootCoordinator:
var newBootCoordinator AuctionEventNewBootCoordinator
if err := c.contractAbi.Unpack(&newBootCoordinator, "NewBootCoordinator", vLog.Data); err != nil {
return nil, nil, tracerr.Wrap(err)
}
newBootCoordinator.NewBootCoordinator = ethCommon.BytesToAddress(vLog.Topics[1].Bytes())
auctionEvents.NewBootCoordinator = append(auctionEvents.NewBootCoordinator, newBootCoordinator)
case logAuctionNewOpenAuctionSlots:

View File

@@ -38,6 +38,7 @@ func TestAuctionConstants(t *testing.T) {
assert.Equal(t, auctionConstants.HermezRollup, hermezRollupTestAddressConst)
assert.Equal(t, auctionConstants.InitialMinimalBidding, INITMINBID)
assert.Equal(t, auctionConstants.TokenHEZ, tokenHEZAddressConst)
assert.Equal(t, auctionConstants.GovernanceAddress, governanceAddressConst)
}
func TestAuctionVariables(t *testing.T) {
@@ -199,8 +200,10 @@ func TestAuctionSetDonationAddress(t *testing.T) {
func TestAuctionSetBootCoordinator(t *testing.T) {
newBootCoordinator := governanceAddressConst
bootCoordinatorURL := "https://boot.coordinator2.io"
newBootCoordinatorURL := "https://boot.coordinator2.io"
_, err := auctionClientTest.AuctionSetBootCoordinator(newBootCoordinator)
_, err := auctionClientTest.AuctionSetBootCoordinator(newBootCoordinator, newBootCoordinatorURL)
require.Nil(t, err)
bootCoordinator, err := auctionClientTest.AuctionGetBootCoordinator()
require.Nil(t, err)
@@ -210,7 +213,8 @@ func TestAuctionSetBootCoordinator(t *testing.T) {
auctionEvents, _, err := auctionClientTest.AuctionEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, newBootCoordinator, auctionEvents.NewBootCoordinator[0].NewBootCoordinator)
_, err = auctionClientTest.AuctionSetBootCoordinator(bootCoordinatorAddressConst)
assert.Equal(t, newBootCoordinatorURL, auctionEvents.NewBootCoordinator[0].NewBootCoordinatorURL)
_, err = auctionClientTest.AuctionSetBootCoordinator(bootCoordinatorAddressConst, bootCoordinatorURL)
require.Nil(t, err)
}

View File

@@ -11,7 +11,7 @@ abigen --abi=HEZ.abi --bin=HEZ.bin --pkg=HEZ --out=HEZ.go
You must compile the contracts to get the `.bin` and `.abi` files. The contracts used are in the repo: https://github.com/hermeznetwork/contracts
Branch: `feature/newDeploymentScript`
Specifically they have been processed in the commit with hash: `4489f8e7fe4dd17cf22f1e96741b09bdf81946d8`
Specifically they have been processed in the commit with hash: `254dc035142c56553d6d4ee9b2ea9d97259357c2`
Versions:
```

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -64,21 +64,12 @@ var (
bootCoordinatorAccount *accounts.Account
bootCoordinatorAddressConst ethCommon.Address
safetyAccount *accounts.Account
safetyAddressConst ethCommon.Address
)
// Ethereum Accounts
var (
hermezGovernanceDAOAccount *accounts.Account
hermezGovernanceDAOAddressConst ethCommon.Address
whiteHackGroupAccount *accounts.Account
whiteHackGroupAddressConst ethCommon.Address
hermezKeeperAccount *accounts.Account
hermezKeeperAddressConst ethCommon.Address
emergencyCouncilAccount *accounts.Account
emergencyCouncilAddressConst ethCommon.Address
governanceAccount *accounts.Account
governanceAddressConst ethCommon.Address
@@ -94,14 +85,12 @@ var (
)
var (
ks *keystore.KeyStore
ethClient *ethclient.Client
ethereumClientWhite *EthereumClient
ethereumClientKep *EthereumClient
ethereumClientGovDAO *EthereumClient
ethereumClientAux *EthereumClient
ethereumClientAux2 *EthereumClient
ethereumClientHermez *EthereumClient
ks *keystore.KeyStore
ethClient *ethclient.Client
ethereumClientEmergencyCouncil *EthereumClient
ethereumClientAux *EthereumClient
ethereumClientAux2 *EthereumClient
ethereumClientHermez *EthereumClient
)
func getEnvVariables() {
@@ -163,14 +152,11 @@ func TestMain(m *testing.M) {
// into the keystore
bootCoordinatorAccount, bootCoordinatorAddressConst = genAcc(w, ks, 0)
governanceAccount, governanceAddressConst = genAcc(w, ks, 1)
safetyAccount, safetyAddressConst = genAcc(w, ks, 2)
hermezKeeperAccount, hermezKeeperAddressConst = genAcc(w, ks, 6)
hermezGovernanceDAOAccount, hermezGovernanceDAOAddressConst = genAcc(w, ks, 7)
whiteHackGroupAccount, whiteHackGroupAddressConst = genAcc(w, ks, 8)
donationAccount, donationAddressConst = genAcc(w, ks, 9)
aux2Account, aux2AddressConst = genAcc(w, ks, 11)
hermezRollupTestAccount, hermezRollupTestAddressConst = genAcc(w, ks, 12)
auxAccount, auxAddressConst = genAcc(w, ks, 13)
emergencyCouncilAccount, emergencyCouncilAddressConst = genAcc(w, ks, 2)
donationAccount, donationAddressConst = genAcc(w, ks, 3)
hermezRollupTestAccount, hermezRollupTestAddressConst = genAcc(w, ks, 4)
auxAccount, auxAddressConst = genAcc(w, ks, 5)
aux2Account, aux2AddressConst = genAcc(w, ks, 6)
ethClient, err = ethclient.Dial(ethClientDialURL)
if err != nil {
@@ -200,9 +186,7 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
ethereumClientKep = NewEthereumClient(ethClient, hermezKeeperAccount, ks, nil)
ethereumClientWhite = NewEthereumClient(ethClient, whiteHackGroupAccount, ks, nil)
ethereumClientGovDAO = NewEthereumClient(ethClient, hermezGovernanceDAOAccount, ks, nil)
ethereumClientEmergencyCouncil = NewEthereumClient(ethClient, emergencyCouncilAccount, ks, nil)
ethereumClientAux = NewEthereumClient(ethClient, auxAccount, ks, nil)
ethereumClientAux2 = NewEthereumClient(ethClient, aux2Account, ks, nil)
ethereumClientHermez = NewEthereumClient(ethClient, hermezRollupTestAccount, ks, nil)

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"strconv"
"strings"
"github.com/ethereum/go-ethereum"
@@ -58,7 +59,7 @@ type RollupEventL1UserTx struct {
}
// RollupEventL1UserTxAux is an event of the Rollup Smart Contract
type RollupEventL1UserTxAux struct {
type rollupEventL1UserTxAux struct {
ToForgeL1TxsNum uint64 // QueueIndex *big.Int
Position uint8 // TransactionIndex *big.Int
L1UserTx []byte
@@ -74,7 +75,8 @@ type RollupEventAddToken struct {
type RollupEventForgeBatch struct {
BatchNum int64
// Sender ethCommon.Address
EthTxHash ethCommon.Hash
EthTxHash ethCommon.Hash
L1UserTxsLen uint16
}
// RollupEventUpdateForgeL1L2BatchTimeout is an event of the Rollup Smart Contract
@@ -95,6 +97,52 @@ type RollupEventWithdraw struct {
TxHash ethCommon.Hash // Hash of the transaction that generated this event
}
type rollupEventUpdateBucketWithdrawAux struct {
NumBucket uint8
BlockStamp *big.Int
Withdrawals *big.Int
}
// RollupEventUpdateBucketWithdraw is an event of the Rollup Smart Contract
type RollupEventUpdateBucketWithdraw struct {
NumBucket int
BlockStamp int64 // blockNum
Withdrawals *big.Int
}
// RollupEventUpdateWithdrawalDelay is an event of the Rollup Smart Contract
type RollupEventUpdateWithdrawalDelay struct {
NewWithdrawalDelay uint64
}
// RollupUpdateBucketsParameters are the bucket parameters used in an update
type RollupUpdateBucketsParameters struct {
CeilUSD *big.Int
Withdrawals *big.Int
BlockWithdrawalRate *big.Int
MaxWithdrawals *big.Int
}
type rollupEventUpdateBucketsParametersAux struct {
ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int
}
// RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract
type RollupEventUpdateBucketsParameters struct {
// ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int
ArrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters
}
// RollupEventUpdateTokenExchange is an event of the Rollup Smart Contract
type RollupEventUpdateTokenExchange struct {
AddressArray []ethCommon.Address
ValueArray []uint64
}
// RollupEventSafeMode is an event of the Rollup Smart Contract
type RollupEventSafeMode struct {
}
// RollupEvents is the list of events in a block of the Rollup Smart Contract
type RollupEvents struct {
L1UserTx []RollupEventL1UserTx
@@ -103,6 +151,11 @@ type RollupEvents struct {
UpdateForgeL1L2BatchTimeout []RollupEventUpdateForgeL1L2BatchTimeout
UpdateFeeAddToken []RollupEventUpdateFeeAddToken
Withdraw []RollupEventWithdraw
UpdateWithdrawalDelay []RollupEventUpdateWithdrawalDelay
UpdateBucketWithdraw []RollupEventUpdateBucketWithdraw
UpdateBucketsParameters []RollupEventUpdateBucketsParameters
UpdateTokenExchange []RollupEventUpdateTokenExchange
SafeMode []RollupEventSafeMode
}
// NewRollupEvents creates an empty RollupEvents with the slices initialized.
@@ -122,6 +175,7 @@ type RollupForgeBatchArgs struct {
NewLastIdx int64
NewStRoot *big.Int
NewExitRoot *big.Int
L1UserTxs []common.L1Tx
L1CoordinatorTxs []common.L1Tx
L1CoordinatorTxsAuths [][]byte // Authorization for accountCreations for each L1CoordinatorTx
L2TxsData []common.L2Tx
@@ -135,12 +189,12 @@ type RollupForgeBatchArgs struct {
}
// RollupForgeBatchArgsAux are the arguments to the ForgeBatch function in the Rollup Smart Contract
type RollupForgeBatchArgsAux struct {
type rollupForgeBatchArgsAux struct {
NewLastIdx *big.Int
NewStRoot *big.Int
NewExitRoot *big.Int
EncodedL1CoordinatorTx []byte
L2TxsData []byte
L1L2TxsData []byte
FeeIdxCoordinator []byte
// Circuit selector
VerifierIdx uint8
@@ -181,7 +235,7 @@ type RollupInterface interface {
RollupConstants() (*common.RollupConstants, error)
RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethCommon.Hash, error)
RollupForgeBatchArgs(ethCommon.Hash) (*RollupForgeBatchArgs, *ethCommon.Address, error)
RollupForgeBatchArgs(ethCommon.Hash, uint16) (*RollupForgeBatchArgs, *ethCommon.Address, error)
}
//
@@ -240,6 +294,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T
nLevels := rollupConst.Verifiers[args.VerifierIdx].NLevels
lenBytes := nLevels / 8 //nolint:gomnd
newLastIdx := big.NewInt(int64(args.NewLastIdx))
// L1CoordinatorBytes
var l1CoordinatorBytes []byte
for i := 0; i < len(args.L1CoordinatorTxs); i++ {
l1 := args.L1CoordinatorTxs[i]
@@ -249,15 +304,33 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T
}
l1CoordinatorBytes = append(l1CoordinatorBytes, bytesl1[:]...)
}
var l2DataBytes []byte
// L1L2TxData
var l1l2TxData []byte
for i := 0; i < len(args.L1UserTxs); i++ {
l1User := args.L1UserTxs[i]
bytesl1User, err := l1User.BytesDataAvailability(uint32(nLevels))
if err != nil {
return nil, tracerr.Wrap(err)
}
l1l2TxData = append(l1l2TxData, bytesl1User[:]...)
}
for i := 0; i < len(args.L1CoordinatorTxs); i++ {
l1Coord := args.L1CoordinatorTxs[i]
bytesl1Coord, err := l1Coord.BytesDataAvailability(uint32(nLevels))
if err != nil {
return nil, tracerr.Wrap(err)
}
l1l2TxData = append(l1l2TxData, bytesl1Coord[:]...)
}
for i := 0; i < len(args.L2TxsData); i++ {
l2 := args.L2TxsData[i]
bytesl2, err := l2.BytesDataAvailability(uint32(nLevels))
if err != nil {
return nil, tracerr.Wrap(err)
}
l2DataBytes = append(l2DataBytes, bytesl2[:]...)
l1l2TxData = append(l1l2TxData, bytesl2[:]...)
}
// FeeIdxCoordinator
var feeIdxCoordinator []byte
if len(args.FeeIdxCoordinator) > common.RollupConstMaxFeeIdxCoordinator {
return nil, tracerr.Wrap(fmt.Errorf("len(args.FeeIdxCoordinator) > %v",
@@ -274,7 +347,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T
}
feeIdxCoordinator = append(feeIdxCoordinator, bytesFeeIdx[len(bytesFeeIdx)-int(lenBytes):]...)
}
return c.hermez.ForgeBatch(auth, newLastIdx, args.NewStRoot, args.NewExitRoot, l1CoordinatorBytes, l2DataBytes, feeIdxCoordinator, args.VerifierIdx, args.L1Batch, args.ProofA, args.ProofB, args.ProofC)
return c.hermez.ForgeBatch(auth, newLastIdx, args.NewStRoot, args.NewExitRoot, l1CoordinatorBytes, l1l2TxData, feeIdxCoordinator, args.VerifierIdx, args.L1Batch, args.ProofA, args.ProofB, args.ProofC)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed forge batch: %w", err))
@@ -317,7 +390,7 @@ func (c *RollupClient) RollupWithdrawMerkleProof(fromBJJ *babyjub.PublicKey, tok
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey := new(big.Int).SetBytes(pkCompB)
numExitRootB := big.NewInt(numExitRoot)
numExitRootB := uint32(numExitRoot)
idxBig := big.NewInt(idx)
return c.hermez.WithdrawMerkleProof(auth, tokenID, amount, babyPubKey, numExitRootB, siblings, idxBig, instantWithdraw)
},
@@ -338,9 +411,14 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey := new(big.Int).SetBytes(pkCompB)
var babyPubKey *big.Int
if fromBJJ != nil {
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey = new(big.Int).SetBytes(pkCompB)
} else {
babyPubKey = big.NewInt(0)
}
fromIdxBig := big.NewInt(fromIdx)
toIdxBig := big.NewInt(toIdx)
loadAmountF, err := common.NewFloat16(loadAmount)
@@ -369,9 +447,14 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey := new(big.Int).SetBytes(pkCompB)
var babyPubKey *big.Int
if fromBJJ != nil {
pkCompL := fromBJJ.Compress()
pkCompB := common.SwapEndianness(pkCompL[:])
babyPubKey = new(big.Int).SetBytes(pkCompB)
} else {
babyPubKey = big.NewInt(0)
}
fromIdxBig := big.NewInt(fromIdx)
toIdxBig := big.NewInt(toIdx)
loadAmountF, err := common.NewFloat16(loadAmount)
@@ -454,6 +537,78 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *typ
return tx, nil
}
// RollupUpdateBucketsParameters is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateBucketsParameters(
arrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters,
) (tx *types.Transaction, err error) {
params := [common.RollupConstNumBuckets][4]*big.Int{}
for i, bucket := range arrayBuckets {
params[i][0] = bucket.CeilUSD
params[i][1] = bucket.Withdrawals
params[i][2] = bucket.BlockWithdrawalRate
params[i][3] = bucket.MaxWithdrawals
}
if tx, err = c.client.CallAuth(
12500000, //nolint:gomnd
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.UpdateBucketsParameters(auth, params)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update Buckets Parameters: %w", err))
}
return tx, nil
}
// RollupUpdateTokenExchange is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateTokenExchange(addressArray []ethCommon.Address, valueArray []uint64) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.UpdateTokenExchange(auth, addressArray, valueArray)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update Token Exchange: %w", err))
}
return tx, nil
}
// RollupUpdateWithdrawalDelay is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateWithdrawalDelay(newWithdrawalDelay int64) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.UpdateWithdrawalDelay(auth, uint64(newWithdrawalDelay))
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update WithdrawalDelay: %w", err))
}
return tx, nil
}
// RollupSafeMode is the interface to call the smart contract function
func (c *RollupClient) RollupSafeMode() (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.hermez.SafeMode(auth)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed update Safe Mode: %w", err))
}
return tx, nil
}
// RollupInstantWithdrawalViewer is the interface to call the smart contract function
func (c *RollupClient) RollupInstantWithdrawalViewer(tokenAddress ethCommon.Address, amount *big.Int) (instantAllowed bool, err error) {
if err := c.client.Call(func(ec *ethclient.Client) error {
instantAllowed, err = c.hermez.InstantWithdrawalViewer(nil, tokenAddress, amount)
return tracerr.Wrap(err)
}); err != nil {
return false, tracerr.Wrap(err)
}
return instantAllowed, nil
}
// RollupConstants returns the Constants of the Rollup Smart Contract
func (c *RollupClient) RollupConstants() (rollupConstants *common.RollupConstants, err error) {
rollupConstants = new(common.RollupConstants)
@@ -481,11 +636,7 @@ func (c *RollupClient) RollupConstants() (rollupConstants *common.RollupConstant
if err != nil {
return tracerr.Wrap(err)
}
rollupConstants.HermezGovernanceDAOAddress, err = c.hermez.HermezGovernanceDAOAddress(nil)
if err != nil {
return tracerr.Wrap(err)
}
rollupConstants.SafetyAddress, err = c.hermez.SafetyAddress(nil)
rollupConstants.HermezGovernanceAddress, err = c.hermez.HermezGovernanceAddress(nil)
if err != nil {
return tracerr.Wrap(err)
}
@@ -498,12 +649,17 @@ func (c *RollupClient) RollupConstants() (rollupConstants *common.RollupConstant
}
var (
logHermezL1UserTxEvent = crypto.Keccak256Hash([]byte("L1UserTxEvent(uint64,uint8,bytes)"))
logHermezL1UserTxEvent = crypto.Keccak256Hash([]byte("L1UserTxEvent(uint32,uint8,bytes)"))
logHermezAddToken = crypto.Keccak256Hash([]byte("AddToken(address,uint32)"))
logHermezForgeBatch = crypto.Keccak256Hash([]byte("ForgeBatch(uint64)"))
logHermezForgeBatch = crypto.Keccak256Hash([]byte("ForgeBatch(uint32,uint16)"))
logHermezUpdateForgeL1L2BatchTimeout = crypto.Keccak256Hash([]byte("UpdateForgeL1L2BatchTimeout(uint8)"))
logHermezUpdateFeeAddToken = crypto.Keccak256Hash([]byte("UpdateFeeAddToken(uint256)"))
logHermezWithdrawEvent = crypto.Keccak256Hash([]byte("WithdrawEvent(uint48,uint48,bool)"))
logHermezWithdrawEvent = crypto.Keccak256Hash([]byte("WithdrawEvent(uint48,uint32,bool)"))
logHermezUpdateBucketWithdraw = crypto.Keccak256Hash([]byte("UpdateBucketWithdraw(uint8,uint256,uint256)"))
logHermezUpdateWithdrawalDelay = crypto.Keccak256Hash([]byte("UpdateWithdrawalDelay(uint64)"))
logHermezUpdateBucketsParameters = crypto.Keccak256Hash([]byte("UpdateBucketsParameters(uint256[4][" + strconv.Itoa(common.RollupConstNumBuckets) + "])"))
logHermezUpdateTokenExchange = crypto.Keccak256Hash([]byte("UpdateTokenExchange(address[],uint64[])"))
logHermezSafeMode = crypto.Keccak256Hash([]byte("SafeMode()"))
)
// RollupEventsByBlock returns the events in a block that happened in the Rollup Smart Contract
@@ -534,7 +690,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
}
switch vLog.Topics[0] {
case logHermezL1UserTxEvent:
var L1UserTxAux RollupEventL1UserTxAux
var L1UserTxAux rollupEventL1UserTxAux
var L1UserTx RollupEventL1UserTx
err := c.contractAbi.Unpack(&L1UserTxAux, "L1UserTxEvent", vLog.Data)
if err != nil {
@@ -560,6 +716,10 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
rollupEvents.AddToken = append(rollupEvents.AddToken, addToken)
case logHermezForgeBatch:
var forgeBatch RollupEventForgeBatch
err := c.contractAbi.Unpack(&forgeBatch, "ForgeBatch", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
forgeBatch.BatchNum = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
forgeBatch.EthTxHash = vLog.TxHash
// forgeBatch.Sender = vLog.Address
@@ -593,6 +753,49 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
}
withdraw.TxHash = vLog.TxHash
rollupEvents.Withdraw = append(rollupEvents.Withdraw, withdraw)
case logHermezUpdateBucketWithdraw:
var updateBucketWithdrawAux rollupEventUpdateBucketWithdrawAux
var updateBucketWithdraw RollupEventUpdateBucketWithdraw
err := c.contractAbi.Unpack(&updateBucketWithdrawAux, "UpdateBucketWithdraw", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
updateBucketWithdraw.Withdrawals = updateBucketWithdrawAux.Withdrawals
updateBucketWithdraw.NumBucket = int(new(big.Int).SetBytes(vLog.Topics[1][:]).Int64())
updateBucketWithdraw.BlockStamp = new(big.Int).SetBytes(vLog.Topics[2][:]).Int64()
rollupEvents.UpdateBucketWithdraw = append(rollupEvents.UpdateBucketWithdraw, updateBucketWithdraw)
case logHermezUpdateWithdrawalDelay:
var withdrawalDelay RollupEventUpdateWithdrawalDelay
err := c.contractAbi.Unpack(&withdrawalDelay, "UpdateWithdrawalDelay", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupEvents.UpdateWithdrawalDelay = append(rollupEvents.UpdateWithdrawalDelay, withdrawalDelay)
case logHermezUpdateBucketsParameters:
var bucketsParametersAux rollupEventUpdateBucketsParametersAux
var bucketsParameters RollupEventUpdateBucketsParameters
err := c.contractAbi.Unpack(&bucketsParametersAux, "UpdateBucketsParameters", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
for i, bucket := range bucketsParametersAux.ArrayBuckets {
bucketsParameters.ArrayBuckets[i].CeilUSD = bucket[0]
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket[1]
bucketsParameters.ArrayBuckets[i].BlockWithdrawalRate = bucket[2]
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket[3]
}
rollupEvents.UpdateBucketsParameters = append(rollupEvents.UpdateBucketsParameters, bucketsParameters)
case logHermezUpdateTokenExchange:
var tokensExchange RollupEventUpdateTokenExchange
err := c.contractAbi.Unpack(&tokensExchange, "UpdateTokenExchange", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupEvents.UpdateTokenExchange = append(rollupEvents.UpdateTokenExchange, tokensExchange)
case logHermezSafeMode:
var safeMode RollupEventSafeMode
rollupEvents.SafeMode = append(rollupEvents.SafeMode, safeMode)
}
}
return &rollupEvents, blockHash, nil
@@ -600,7 +803,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
// RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the
// Rollup Smart Contract in the given transaction, and the sender address.
func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupForgeBatchArgs, *ethCommon.Address, error) {
func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, l1UserTxsLen uint16) (*RollupForgeBatchArgs, *ethCommon.Address, error) {
tx, _, err := c.client.client.TransactionByHash(context.Background(), ethTxHash)
if err != nil {
return nil, nil, tracerr.Wrap(err)
@@ -619,7 +822,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
var aux RollupForgeBatchArgsAux
var aux rollupForgeBatchArgsAux
if err := method.Inputs.Unpack(&aux, txData[4:]); err != nil {
return nil, nil, tracerr.Wrap(err)
}
@@ -637,8 +840,40 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
L2TxsData: []common.L2Tx{},
FeeIdxCoordinator: []common.Idx{},
}
numTxsL1 := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
for i := 0; i < numTxsL1; i++ {
rollupConsts, err := c.RollupConstants()
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels
lenL1L2TxsBytes := int((nLevels/8)*2 + 2 + 1)
numBytesL1TxUser := int(l1UserTxsLen) * lenL1L2TxsBytes
numTxsL1Coord := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
numBytesL1TxCoord := numTxsL1Coord * lenL1L2TxsBytes
numBeginL2Tx := numBytesL1TxCoord + numBytesL1TxUser
l1UserTxsData := []byte{}
if l1UserTxsLen > 0 {
l1UserTxsData = aux.L1L2TxsData[:numBytesL1TxUser]
}
for i := 0; i < int(l1UserTxsLen); i++ {
l1Tx, err := common.L1TxFromDataAvailability(l1UserTxsData[i*lenL1L2TxsBytes:(i+1)*lenL1L2TxsBytes], uint32(nLevels))
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupForgeBatchArgs.L1UserTxs = append(rollupForgeBatchArgs.L1UserTxs, *l1Tx)
}
l2TxsData := []byte{}
if numBeginL2Tx < len(aux.L1L2TxsData) {
l2TxsData = aux.L1L2TxsData[numBeginL2Tx:]
}
numTxsL2 := len(l2TxsData) / lenL1L2TxsBytes
for i := 0; i < numTxsL2; i++ {
l2Tx, err := common.L2TxFromBytesDataAvailability(l2TxsData[i*lenL1L2TxsBytes:(i+1)*lenL1L2TxsBytes], int(nLevels))
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupForgeBatchArgs.L2TxsData = append(rollupForgeBatchArgs.L2TxsData, *l2Tx)
}
for i := 0; i < numTxsL1Coord; i++ {
bytesL1Coordinator := aux.EncodedL1CoordinatorTx[i*common.L1CoordinatorTxBytesLen : (i+1)*common.L1CoordinatorTxBytesLen]
var signature []byte
v := bytesL1Coordinator[0]
@@ -654,20 +889,6 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
rollupForgeBatchArgs.L1CoordinatorTxs = append(rollupForgeBatchArgs.L1CoordinatorTxs, *l1Tx)
rollupForgeBatchArgs.L1CoordinatorTxsAuths = append(rollupForgeBatchArgs.L1CoordinatorTxsAuths, signature)
}
rollupConsts, err := c.RollupConstants()
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels
lenL2TxsBytes := int((nLevels/8)*2 + 2 + 1)
numTxsL2 := len(aux.L2TxsData) / lenL2TxsBytes
for i := 0; i < numTxsL2; i++ {
l2Tx, err := common.L2TxFromBytes(aux.L2TxsData[i*lenL2TxsBytes:(i+1)*lenL2TxsBytes], int(nLevels))
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
rollupForgeBatchArgs.L2TxsData = append(rollupForgeBatchArgs.L2TxsData, *l2Tx)
}
lenFeeIdxCoordinatorBytes := int(nLevels / 8) //nolint:gomnd
numFeeIdxCoordinator := len(aux.FeeIdxCoordinator) / lenFeeIdxCoordinatorBytes
for i := 0; i < numFeeIdxCoordinator; i++ {

File diff suppressed because it is too large Load Diff

View File

@@ -58,44 +58,37 @@ type WDelayerEventEscapeHatchWithdrawal struct {
Amount *big.Int
}
// WDelayerEventNewHermezKeeperAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewHermezKeeperAddress struct {
NewHermezKeeperAddress ethCommon.Address
// WDelayerEventNewEmergencyCouncil an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewEmergencyCouncil struct {
NewEmergencyCouncil ethCommon.Address
}
// WDelayerEventNewWhiteHackGroupAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewWhiteHackGroupAddress struct {
NewWhiteHackGroupAddress ethCommon.Address
}
// WDelayerEventNewHermezGovernanceDAOAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewHermezGovernanceDAOAddress struct {
NewHermezGovernanceDAOAddress ethCommon.Address
// WDelayerEventNewHermezGovernanceAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewHermezGovernanceAddress struct {
NewHermezGovernanceAddress ethCommon.Address
}
// WDelayerEvents is the lis of events in a block of the WithdrawalDelayer Smart Contract
type WDelayerEvents struct {
Deposit []WDelayerEventDeposit
Withdraw []WDelayerEventWithdraw
EmergencyModeEnabled []WDelayerEventEmergencyModeEnabled
NewWithdrawalDelay []WDelayerEventNewWithdrawalDelay
EscapeHatchWithdrawal []WDelayerEventEscapeHatchWithdrawal
NewHermezKeeperAddress []WDelayerEventNewHermezKeeperAddress
NewWhiteHackGroupAddress []WDelayerEventNewWhiteHackGroupAddress
NewHermezGovernanceDAOAddress []WDelayerEventNewHermezGovernanceDAOAddress
Deposit []WDelayerEventDeposit
Withdraw []WDelayerEventWithdraw
EmergencyModeEnabled []WDelayerEventEmergencyModeEnabled
NewWithdrawalDelay []WDelayerEventNewWithdrawalDelay
EscapeHatchWithdrawal []WDelayerEventEscapeHatchWithdrawal
NewEmergencyCouncil []WDelayerEventNewEmergencyCouncil
NewHermezGovernanceAddress []WDelayerEventNewHermezGovernanceAddress
}
// NewWDelayerEvents creates an empty WDelayerEvents with the slices initialized.
func NewWDelayerEvents() WDelayerEvents {
return WDelayerEvents{
Deposit: make([]WDelayerEventDeposit, 0),
Withdraw: make([]WDelayerEventWithdraw, 0),
EmergencyModeEnabled: make([]WDelayerEventEmergencyModeEnabled, 0),
NewWithdrawalDelay: make([]WDelayerEventNewWithdrawalDelay, 0),
EscapeHatchWithdrawal: make([]WDelayerEventEscapeHatchWithdrawal, 0),
NewHermezKeeperAddress: make([]WDelayerEventNewHermezKeeperAddress, 0),
NewWhiteHackGroupAddress: make([]WDelayerEventNewWhiteHackGroupAddress, 0),
NewHermezGovernanceDAOAddress: make([]WDelayerEventNewHermezGovernanceDAOAddress, 0),
Deposit: make([]WDelayerEventDeposit, 0),
Withdraw: make([]WDelayerEventWithdraw, 0),
EmergencyModeEnabled: make([]WDelayerEventEmergencyModeEnabled, 0),
NewWithdrawalDelay: make([]WDelayerEventNewWithdrawalDelay, 0),
EscapeHatchWithdrawal: make([]WDelayerEventEscapeHatchWithdrawal, 0),
NewEmergencyCouncil: make([]WDelayerEventNewEmergencyCouncil, 0),
NewHermezGovernanceAddress: make([]WDelayerEventNewHermezGovernanceAddress, 0),
}
}
@@ -105,12 +98,12 @@ type WDelayerInterface interface {
// Smart Contract Methods
//
WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, error)
WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error)
WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error)
WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerGetHermezGovernanceAddress() (*ethCommon.Address, error)
WDelayerTransferGovernance(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerClaimGovernance() (*types.Transaction, error)
WDelayerGetEmergencyCouncil() (*ethCommon.Address, error)
WDelayerTransferEmergencyCouncil(newAddress ethCommon.Address) (*types.Transaction, error)
WDelayerClaimEmergencyCouncil() (*types.Transaction, error)
WDelayerIsEmergencyMode() (bool, error)
WDelayerGetWithdrawalDelay() (*big.Int, error)
WDelayerGetEmergencyModeStartingTime() (*big.Int, error)
@@ -155,77 +148,78 @@ func NewWDelayerClient(client *EthereumClient, address ethCommon.Address) (*WDel
}, nil
}
// WDelayerGetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetHermezGovernanceDAOAddress() (hermezGovernanceDAOAddress *ethCommon.Address, err error) {
var _hermezGovernanceDAOAddress ethCommon.Address
// WDelayerGetHermezGovernanceAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetHermezGovernanceAddress() (hermezGovernanceAddress *ethCommon.Address, err error) {
var _hermezGovernanceAddress ethCommon.Address
if err := c.client.Call(func(ec *ethclient.Client) error {
_hermezGovernanceDAOAddress, err = c.wdelayer.GetHermezGovernanceDAOAddress(nil)
_hermezGovernanceAddress, err = c.wdelayer.GetHermezGovernanceAddress(nil)
return tracerr.Wrap(err)
}); err != nil {
return nil, tracerr.Wrap(err)
}
return &_hermezGovernanceDAOAddress, nil
return &_hermezGovernanceAddress, nil
}
// WDelayerSetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerTransferGovernance is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerTransferGovernance(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.wdelayer.SetHermezGovernanceDAOAddress(auth, newAddress)
return c.wdelayer.TransferGovernance(auth, newAddress)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed setting hermezGovernanceDAOAddress: %w", err))
return nil, tracerr.Wrap(fmt.Errorf("Failed transfer hermezGovernanceAddress: %w", err))
}
return tx, nil
}
// WDelayerGetHermezKeeperAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetHermezKeeperAddress() (hermezKeeperAddress *ethCommon.Address, err error) {
var _hermezKeeperAddress ethCommon.Address
if err := c.client.Call(func(ec *ethclient.Client) error {
_hermezKeeperAddress, err = c.wdelayer.GetHermezKeeperAddress(nil)
return tracerr.Wrap(err)
}); err != nil {
return nil, tracerr.Wrap(err)
}
return &_hermezKeeperAddress, nil
}
// WDelayerSetHermezKeeperAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerClaimGovernance is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerClaimGovernance() (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.wdelayer.SetHermezKeeperAddress(auth, newAddress)
return c.wdelayer.ClaimGovernance(auth)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed setting hermezKeeperAddress: %w", err))
return nil, tracerr.Wrap(fmt.Errorf("Failed claim hermezGovernanceAddress: %w", err))
}
return tx, nil
}
// WDelayerGetWhiteHackGroupAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetWhiteHackGroupAddress() (whiteHackGroupAddress *ethCommon.Address, err error) {
var _whiteHackGroupAddress ethCommon.Address
// WDelayerGetEmergencyCouncil is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetEmergencyCouncil() (emergencyCouncilAddress *ethCommon.Address, err error) {
var _emergencyCouncilAddress ethCommon.Address
if err := c.client.Call(func(ec *ethclient.Client) error {
_whiteHackGroupAddress, err = c.wdelayer.GetWhiteHackGroupAddress(nil)
_emergencyCouncilAddress, err = c.wdelayer.GetEmergencyCouncil(nil)
return tracerr.Wrap(err)
}); err != nil {
return nil, tracerr.Wrap(err)
}
return &_whiteHackGroupAddress, nil
return &_emergencyCouncilAddress, nil
}
// WDelayerSetWhiteHackGroupAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerTransferEmergencyCouncil is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerTransferEmergencyCouncil(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.wdelayer.SetWhiteHackGroupAddress(auth, newAddress)
return c.wdelayer.TransferEmergencyCouncil(auth, newAddress)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed setting whiteHackGroupAddress: %w", err))
return nil, tracerr.Wrap(fmt.Errorf("Failed transfer EmergencyCouncil: %w", err))
}
return tx, nil
}
// WDelayerClaimEmergencyCouncil is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerClaimEmergencyCouncil() (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth(
0,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
return c.wdelayer.ClaimEmergencyCouncil(auth)
},
); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed claim EmergencyCouncil: %w", err))
}
return tx, nil
}
@@ -365,14 +359,13 @@ func (c *WDelayerClient) WDelayerConstants() (constants *common.WDelayerConstant
}
var (
logWDelayerDeposit = crypto.Keccak256Hash([]byte("Deposit(address,address,uint192,uint64)"))
logWDelayerWithdraw = crypto.Keccak256Hash([]byte("Withdraw(address,address,uint192)"))
logWDelayerEmergencyModeEnabled = crypto.Keccak256Hash([]byte("EmergencyModeEnabled()"))
logWDelayerNewWithdrawalDelay = crypto.Keccak256Hash([]byte("NewWithdrawalDelay(uint64)"))
logWDelayerEscapeHatchWithdrawal = crypto.Keccak256Hash([]byte("EscapeHatchWithdrawal(address,address,address,uint256)"))
logWDelayerNewHermezKeeperAddress = crypto.Keccak256Hash([]byte("NewHermezKeeperAddress(address)"))
logWDelayerNewWhiteHackGroupAddress = crypto.Keccak256Hash([]byte("NewWhiteHackGroupAddress(address)"))
logWDelayerNewHermezGovernanceDAOAddress = crypto.Keccak256Hash([]byte("NewHermezGovernanceDAOAddress(address)"))
logWDelayerDeposit = crypto.Keccak256Hash([]byte("Deposit(address,address,uint192,uint64)"))
logWDelayerWithdraw = crypto.Keccak256Hash([]byte("Withdraw(address,address,uint192)"))
logWDelayerEmergencyModeEnabled = crypto.Keccak256Hash([]byte("EmergencyModeEnabled()"))
logWDelayerNewWithdrawalDelay = crypto.Keccak256Hash([]byte("NewWithdrawalDelay(uint64)"))
logWDelayerEscapeHatchWithdrawal = crypto.Keccak256Hash([]byte("EscapeHatchWithdrawal(address,address,address,uint256)"))
logWDelayerNewEmergencyCouncil = crypto.Keccak256Hash([]byte("NewEmergencyCouncil(address)"))
logWDelayerNewHermezGovernanceAddress = crypto.Keccak256Hash([]byte("NewHermezGovernanceAddress(address)"))
)
// WDelayerEventsByBlock returns the events in a block that happened in the
@@ -449,29 +442,21 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents,
escapeHatchWithdrawal.Token = ethCommon.BytesToAddress(vLog.Topics[3].Bytes())
wdelayerEvents.EscapeHatchWithdrawal = append(wdelayerEvents.EscapeHatchWithdrawal, escapeHatchWithdrawal)
case logWDelayerNewHermezKeeperAddress:
var keeperAddress WDelayerEventNewHermezKeeperAddress
err := c.contractAbi.Unpack(&keeperAddress, "NewHermezKeeperAddress", vLog.Data)
case logWDelayerNewEmergencyCouncil:
var emergencyCouncil WDelayerEventNewEmergencyCouncil
err := c.contractAbi.Unpack(&emergencyCouncil, "NewEmergencyCouncil", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
wdelayerEvents.NewHermezKeeperAddress = append(wdelayerEvents.NewHermezKeeperAddress, keeperAddress)
wdelayerEvents.NewEmergencyCouncil = append(wdelayerEvents.NewEmergencyCouncil, emergencyCouncil)
case logWDelayerNewWhiteHackGroupAddress:
var whiteHackGroupAddress WDelayerEventNewWhiteHackGroupAddress
err := c.contractAbi.Unpack(&whiteHackGroupAddress, "NewWhiteHackGroupAddress", vLog.Data)
case logWDelayerNewHermezGovernanceAddress:
var governanceAddress WDelayerEventNewHermezGovernanceAddress
err := c.contractAbi.Unpack(&governanceAddress, "NewHermezGovernanceAddress", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
wdelayerEvents.NewWhiteHackGroupAddress = append(wdelayerEvents.NewWhiteHackGroupAddress, whiteHackGroupAddress)
case logWDelayerNewHermezGovernanceDAOAddress:
var governanceDAOAddress WDelayerEventNewHermezGovernanceDAOAddress
err := c.contractAbi.Unpack(&governanceDAOAddress, "NewHermezGovernanceDAOAddress", vLog.Data)
if err != nil {
return nil, nil, tracerr.Wrap(err)
}
wdelayerEvents.NewHermezGovernanceDAOAddress = append(wdelayerEvents.NewHermezGovernanceDAOAddress, governanceDAOAddress)
wdelayerEvents.NewHermezGovernanceAddress = append(wdelayerEvents.NewHermezGovernanceAddress, governanceAddress)
}
}
return &wdelayerEvents, blockHash, nil

View File

@@ -12,8 +12,6 @@ import (
var wdelayerClient *WDelayerClient
var wdelayerClientTest *WDelayerClient
// var wdelayerClientKep *WDelayerClient
var initWithdrawalDelay = big.NewInt(60)
var newWithdrawalDelay = big.NewInt(79)
var maxEmergencyModeTime = time.Hour * 24 * 7 * 26
@@ -27,78 +25,59 @@ func TestWDelayerConstants(t *testing.T) {
assert.Equal(t, hermezRollupTestAddressConst, wDelayerConstants.HermezRollup)
}
func TestWDelayerGetHermezGovernanceDAOAddress(t *testing.T) {
governanceAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceDAOAddress()
func TestWDelayerGetHermezGovernanceAddress(t *testing.T) {
governanceAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceAddress()
require.Nil(t, err)
assert.Equal(t, &hermezGovernanceDAOAddressConst, governanceAddress)
assert.Equal(t, &governanceAddressConst, governanceAddress)
}
func TestWDelayerSetHermezGovernanceDAOAddress(t *testing.T) {
wdelayerClientGov, err := NewWDelayerClient(ethereumClientGovDAO, wdelayerTestAddressConst)
func TestWDelayerSetHermezGovernanceAddress(t *testing.T) {
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientGov.WDelayerSetHermezGovernanceDAOAddress(auxAddressConst)
_, err = wdelayerClientTest.WDelayerTransferGovernance(auxAddressConst)
require.Nil(t, err)
auxAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceDAOAddress()
_, err = wdelayerClientAux.WDelayerClaimGovernance()
require.Nil(t, err)
auxAddress, err := wdelayerClientTest.WDelayerGetHermezGovernanceAddress()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, err := wdelayerClientTest.client.EthLastBlock()
require.Nil(t, err)
wdelayerEvents, _, err := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewHermezGovernanceDAOAddress[0].NewHermezGovernanceDAOAddress)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewHermezGovernanceAddress[0].NewHermezGovernanceAddress)
_, err = wdelayerClientAux.WDelayerTransferGovernance(governanceAddressConst)
require.Nil(t, err)
_, err = wdelayerClientTest.WDelayerClaimGovernance()
require.Nil(t, err)
}
func TestWDelayerGetEmergencyCouncil(t *testing.T) {
emergencyCouncil, err := wdelayerClientTest.WDelayerGetEmergencyCouncil()
require.Nil(t, err)
assert.Equal(t, &emergencyCouncilAddressConst, emergencyCouncil)
}
func TestWDelayerSetEmergencyCouncil(t *testing.T) {
wdelayerClientEmergencyCouncil, err := NewWDelayerClient(ethereumClientEmergencyCouncil, wdelayerTestAddressConst)
require.Nil(t, err)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientAux.WDelayerSetHermezGovernanceDAOAddress(hermezGovernanceDAOAddressConst)
_, err = wdelayerClientEmergencyCouncil.WDelayerTransferEmergencyCouncil(auxAddressConst)
require.Nil(t, err)
}
func TestWDelayerGetHermezKeeperAddress(t *testing.T) {
keeperAddress, err := wdelayerClientTest.WDelayerGetHermezKeeperAddress()
_, err = wdelayerClientAux.WDelayerClaimEmergencyCouncil()
require.Nil(t, err)
assert.Equal(t, &hermezKeeperAddressConst, keeperAddress)
}
func TestWDelayerSetHermezKeeperAddress(t *testing.T) {
wdelayerClientKep, err := NewWDelayerClient(ethereumClientKep, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientKep.WDelayerSetHermezKeeperAddress(auxAddressConst)
require.Nil(t, err)
auxAddress, err := wdelayerClientTest.WDelayerGetHermezKeeperAddress()
auxAddress, err := wdelayerClientTest.WDelayerGetEmergencyCouncil()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, err := wdelayerClientTest.client.EthLastBlock()
require.Nil(t, err)
wdelayerEvents, _, err := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewHermezKeeperAddress[0].NewHermezKeeperAddress)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewEmergencyCouncil[0].NewEmergencyCouncil)
_, err = wdelayerClientAux.WDelayerTransferEmergencyCouncil(emergencyCouncilAddressConst)
require.Nil(t, err)
_, err = wdelayerClientAux.WDelayerSetHermezKeeperAddress(hermezKeeperAddressConst)
require.Nil(t, err)
}
func TestWDelayerGetWhiteHackGroupAddress(t *testing.T) {
whiteHackGroupAddress, err := wdelayerClientTest.WDelayerGetWhiteHackGroupAddress()
require.Nil(t, err)
assert.Equal(t, &whiteHackGroupAddressConst, whiteHackGroupAddress)
}
func TestWDelayerSetWhiteHackGroupAddress(t *testing.T) {
wdelayerClientWhite, err := NewWDelayerClient(ethereumClientWhite, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientWhite.WDelayerSetWhiteHackGroupAddress(auxAddressConst)
require.Nil(t, err)
auxAddress, err := wdelayerClientTest.WDelayerGetWhiteHackGroupAddress()
require.Nil(t, err)
assert.Equal(t, &auxAddressConst, auxAddress)
currentBlockNum, err := wdelayerClientTest.client.EthLastBlock()
require.Nil(t, err)
wdelayerEvents, _, err := wdelayerClientTest.WDelayerEventsByBlock(currentBlockNum)
require.Nil(t, err)
assert.Equal(t, auxAddressConst, wdelayerEvents.NewWhiteHackGroupAddress[0].NewWhiteHackGroupAddress)
wdelayerClientAux, err := NewWDelayerClient(ethereumClientAux, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientAux.WDelayerSetWhiteHackGroupAddress(whiteHackGroupAddressConst)
_, err = wdelayerClientEmergencyCouncil.WDelayerClaimEmergencyCouncil()
require.Nil(t, err)
}
@@ -115,9 +94,7 @@ func TestWDelayerGetWithdrawalDelay(t *testing.T) {
}
func TestWDelayerChangeWithdrawalDelay(t *testing.T) {
wdelayerClientKep, err := NewWDelayerClient(ethereumClientKep, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientKep.WDelayerChangeWithdrawalDelay(newWithdrawalDelay.Uint64())
_, err := wdelayerClientTest.WDelayerChangeWithdrawalDelay(newWithdrawalDelay.Uint64())
require.Nil(t, err)
withdrawalDelay, err := wdelayerClientTest.WDelayerGetWithdrawalDelay()
require.Nil(t, err)
@@ -188,9 +165,7 @@ func TestWDelayerSecondDeposit(t *testing.T) {
}
func TestWDelayerEnableEmergencyMode(t *testing.T) {
wdelayerClientKep, err := NewWDelayerClient(ethereumClientKep, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientKep.WDelayerEnableEmergencyMode()
_, err := wdelayerClientTest.WDelayerEnableEmergencyMode()
require.Nil(t, err)
emergencyMode, err := wdelayerClientTest.WDelayerIsEmergencyMode()
require.Nil(t, err)
@@ -216,13 +191,13 @@ func TestWDelayerGetEmergencyModeStartingTime(t *testing.T) {
func TestWDelayerEscapeHatchWithdrawal(t *testing.T) {
amount := new(big.Int)
amount.SetString("10000000000000000", 10)
wdelayerClientWhite, err := NewWDelayerClient(ethereumClientWhite, wdelayerTestAddressConst)
wdelayerClientEmergencyCouncil, err := NewWDelayerClient(ethereumClientEmergencyCouncil, wdelayerTestAddressConst)
require.Nil(t, err)
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
_, err = wdelayerClientEmergencyCouncil.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
require.Contains(t, err.Error(), "NO_MAX_EMERGENCY_MODE_TIME")
seconds := maxEmergencyModeTime.Seconds()
addTime(seconds, ethClientDialURL)
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
_, err = wdelayerClientEmergencyCouncil.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
require.Nil(t, err)
currentBlockNum, err := wdelayerClientTest.client.EthLastBlock()
require.Nil(t, err)
@@ -230,6 +205,6 @@ func TestWDelayerEscapeHatchWithdrawal(t *testing.T) {
require.Nil(t, err)
assert.Equal(t, tokenHEZAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Token)
assert.Equal(t, governanceAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].To)
assert.Equal(t, whiteHackGroupAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Who)
assert.Equal(t, emergencyCouncilAddressConst, wdelayerEvents.EscapeHatchWithdrawal[0].Who)
assert.Equal(t, amount, wdelayerEvents.EscapeHatchWithdrawal[0].Amount)
}

View File

@@ -736,7 +736,8 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
position := 0
// Get the input for each Tx
forgeBatchArgs, sender, err := s.ethClient.RollupForgeBatchArgs(evtForgeBatch.EthTxHash)
forgeBatchArgs, sender, err := s.ethClient.RollupForgeBatchArgs(evtForgeBatch.EthTxHash,
evtForgeBatch.L1UserTxsLen)
if err != nil {
return nil, tracerr.Wrap(err)
}
@@ -1074,16 +1075,12 @@ func (s *Synchronizer) wdelayerSync(ethBlock *common.Block) (*common.WDelayerDat
s.vars.WDelayer.WithdrawalDelay = evt.WithdrawalDelay
varsUpdate = true
}
for _, evt := range wDelayerEvents.NewHermezKeeperAddress {
s.vars.WDelayer.HermezKeeperAddress = evt.NewHermezKeeperAddress
for _, evt := range wDelayerEvents.NewEmergencyCouncil {
s.vars.WDelayer.EmergencyCouncilAddress = evt.NewEmergencyCouncil
varsUpdate = true
}
for _, evt := range wDelayerEvents.NewWhiteHackGroupAddress {
s.vars.WDelayer.WhiteHackGroupAddress = evt.NewWhiteHackGroupAddress
varsUpdate = true
}
for _, evt := range wDelayerEvents.NewHermezGovernanceDAOAddress {
s.vars.WDelayer.HermezGovernanceDAOAddress = evt.NewHermezGovernanceDAOAddress
for _, evt := range wDelayerEvents.NewHermezGovernanceAddress {
s.vars.WDelayer.HermezGovernanceAddress = evt.NewHermezGovernanceAddress
varsUpdate = true
}

View File

@@ -292,11 +292,10 @@ func NewClientSetupExample() *ClientSetup {
NLevels: 32,
},
},
TokenHEZ: tokenHEZ,
HermezGovernanceDAOAddress: governanceAddress,
SafetyAddress: ethCommon.HexToAddress("0x84d8B79E84fe87B14ad61A554e740f6736bF4c20"),
HermezAuctionContract: ethCommon.HexToAddress("0x8E442975805fb1908f43050c9C1A522cB0e28D7b"),
WithdrawDelayerContract: ethCommon.HexToAddress("0x5CB7979cBdbf65719BEE92e4D15b7b7Ed3D79114"),
TokenHEZ: tokenHEZ,
HermezGovernanceAddress: governanceAddress,
HermezAuctionContract: ethCommon.HexToAddress("0x8E442975805fb1908f43050c9C1A522cB0e28D7b"),
WithdrawDelayerContract: ethCommon.HexToAddress("0x5CB7979cBdbf65719BEE92e4D15b7b7Ed3D79114"),
}
rollupVariables := &common.RollupVariables{
FeeAddToken: big.NewInt(11),
@@ -312,8 +311,9 @@ func NewClientSetupExample() *ClientSetup {
HermezRollup: ethCommon.HexToAddress("0x474B6e29852257491cf283EfB1A9C61eBFe48369"),
}
auctionVariables := &common.AuctionVariables{
DonationAddress: ethCommon.HexToAddress("0x61Ed87CF0A1496b49A420DA6D84B58196b98f2e7"),
BootCoordinator: ethCommon.HexToAddress("0xE39fEc6224708f0772D2A74fd3f9055A90E0A9f2"),
DonationAddress: ethCommon.HexToAddress("0x61Ed87CF0A1496b49A420DA6D84B58196b98f2e7"),
BootCoordinator: ethCommon.HexToAddress("0xE39fEc6224708f0772D2A74fd3f9055A90E0A9f2"),
BootCoordinatorURL: "https://boot.coordinator.com",
DefaultSlotSetBid: [6]*big.Int{
big.NewInt(1000), big.NewInt(1100), big.NewInt(1200),
big.NewInt(1300), big.NewInt(1400), big.NewInt(1500)},
@@ -329,12 +329,11 @@ func NewClientSetupExample() *ClientSetup {
HermezRollup: auctionConstants.HermezRollup,
}
wDelayerVariables := &common.WDelayerVariables{
HermezGovernanceDAOAddress: ethCommon.HexToAddress("0xcfD0d163AE6432a72682323E2C3A5a69e6B37D12"),
WhiteHackGroupAddress: ethCommon.HexToAddress("0x2730700932a4FDB97B9268A3Ca29f97Ea5fd7EA0"),
HermezKeeperAddress: ethCommon.HexToAddress("0x92aAD86176dC0f0046FE85Ed5dA008a828bE3868"),
WithdrawalDelay: 60,
EmergencyModeStartingTime: 0,
EmergencyMode: false,
HermezGovernanceAddress: ethCommon.HexToAddress("0xcfD0d163AE6432a72682323E2C3A5a69e6B37D12"),
EmergencyCouncilAddress: ethCommon.HexToAddress("0x2730700932a4FDB97B9268A3Ca29f97Ea5fd7EA0"),
WithdrawalDelay: 60,
EmergencyModeStartingTime: 0,
EmergencyMode: false,
}
return &ClientSetup{
RollupConstants: rollupConstants,
@@ -942,8 +941,9 @@ func (c *Client) addBatch(args *eth.RollupForgeBatchArgs) (*types.Transaction, e
ethTx := r.addTransaction(c.newTransaction("forgebatch", args))
c.forgeBatchArgsPending[ethTx.Hash()] = &batch{*args, *c.addr}
r.Events.ForgeBatch = append(r.Events.ForgeBatch, eth.RollupEventForgeBatch{
BatchNum: int64(len(r.State.ExitRoots)) - 1,
EthTxHash: ethTx.Hash(),
BatchNum: int64(len(r.State.ExitRoots)) - 1,
EthTxHash: ethTx.Hash(),
L1UserTxsLen: uint16(len(args.L1UserTxs)),
})
return ethTx, nil
@@ -1061,7 +1061,7 @@ func (c *Client) RollupEventsByBlock(blockNum int64) (*eth.RollupEvents, *ethCom
}
// RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the Rollup Smart Contract in the given transaction
func (c *Client) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*eth.RollupForgeBatchArgs, *ethCommon.Address, error) {
func (c *Client) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, l1UserTxsLen uint16) (*eth.RollupForgeBatchArgs, *ethCommon.Address, error) {
c.rw.RLock()
defer c.rw.RUnlock()
@@ -1220,7 +1220,7 @@ func (c *Client) AuctionGetDonationAddress() (*ethCommon.Address, error) {
}
// AuctionSetBootCoordinator is the interface to call the smart contract function
func (c *Client) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (tx *types.Transaction, err error) {
func (c *Client) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address, newBootCoordinatorURL string) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()
@@ -1511,8 +1511,8 @@ func (c *Client) AuctionEventsByBlock(blockNum int64) (*eth.AuctionEvents, *ethC
// WDelayer
//
// WDelayerGetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *Client) WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, error) {
// WDelayerGetHermezGovernanceAddress is the interface to call the smart contract function
func (c *Client) WDelayerGetHermezGovernanceAddress() (*ethCommon.Address, error) {
c.rw.RLock()
defer c.rw.RUnlock()
@@ -1520,8 +1520,8 @@ func (c *Client) WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, er
return nil, tracerr.Wrap(errTODO)
}
// WDelayerSetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *Client) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerTransferGovernance is the interface to call the smart contract function
func (c *Client) WDelayerTransferGovernance(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()
@@ -1534,17 +1534,8 @@ func (c *Client) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Addr
return nil, tracerr.Wrap(errTODO)
}
// WDelayerGetHermezKeeperAddress is the interface to call the smart contract function
func (c *Client) WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error) {
c.rw.RLock()
defer c.rw.RUnlock()
log.Error("TODO")
return nil, tracerr.Wrap(errTODO)
}
// WDelayerSetHermezKeeperAddress is the interface to call the smart contract function
func (c *Client) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerClaimGovernance is the interface to call the smart contract function
func (c *Client) WDelayerClaimGovernance() (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()
@@ -1557,8 +1548,8 @@ func (c *Client) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (t
return nil, tracerr.Wrap(errTODO)
}
// WDelayerGetWhiteHackGroupAddress is the interface to call the smart contract function
func (c *Client) WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error) {
// WDelayerGetEmergencyCouncil is the interface to call the smart contract function
func (c *Client) WDelayerGetEmergencyCouncil() (*ethCommon.Address, error) {
c.rw.RLock()
defer c.rw.RUnlock()
@@ -1566,8 +1557,22 @@ func (c *Client) WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error)
return nil, tracerr.Wrap(errTODO)
}
// WDelayerSetWhiteHackGroupAddress is the interface to call the smart contract function
func (c *Client) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
// WDelayerTransferEmergencyCouncil is the interface to call the smart contract function
func (c *Client) WDelayerTransferEmergencyCouncil(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()
defer func() { c.revertIfErr(err, cpy) }()
if c.addr == nil {
return nil, tracerr.Wrap(eth.ErrAccountNil)
}
log.Error("TODO")
return nil, tracerr.Wrap(errTODO)
}
// WDelayerClaimEmergencyCouncil is the interface to call the smart contract function
func (c *Client) WDelayerClaimEmergencyCouncil() (tx *types.Transaction, err error) {
c.rw.Lock()
defer c.rw.Unlock()
cpy := c.nextBlock().copy()

View File

@@ -235,7 +235,8 @@ func TestClientRollup(t *testing.T) {
rollupEvents, _, err = c.RollupEventsByBlock(blockNum)
require.Nil(t, err)
rollupForgeBatchArgs1, sender, err := c.RollupForgeBatchArgs(rollupEvents.ForgeBatch[0].EthTxHash)
rollupForgeBatchArgs1, sender, err := c.RollupForgeBatchArgs(rollupEvents.ForgeBatch[0].EthTxHash,
rollupEvents.ForgeBatch[0].L1UserTxsLen)
require.Nil(t, err)
assert.Equal(t, *c.addr, *sender)
assert.Equal(t, rollupForgeBatchArgs0, rollupForgeBatchArgs1)