diff --git a/api/api_test.go b/api/api_test.go index 0e12d32..b087c46 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -499,7 +499,7 @@ func TestMain(m *testing.M) { // Slot 7 nextForgers[6].Coordinator = nonBootForger - var buckets [common.RollupConstNumBuckets]common.BucketParams + buckets := make([]common.BucketParams, 5) for i := range buckets { buckets[i].CeilUSD = big.NewInt(int64(i) * 10) buckets[i].BlockStamp = big.NewInt(int64(i) * 100) diff --git a/api/config.go b/api/config.go index 93292c9..43ce0a1 100644 --- a/api/config.go +++ b/api/config.go @@ -41,7 +41,6 @@ func newRollupConstants(publicConstants common.RollupConstants) *rollupConstants MaxL1UserTx: common.RollupConstMaxL1UserTx, MaxL1Tx: common.RollupConstMaxL1Tx, InputSHAConstantBytes: common.RollupConstInputSHAConstantBytes, - NumBuckets: common.RollupConstNumBuckets, MaxWithdrawalDelay: common.RollupConstMaxWithdrawalDelay, ExchangeMultiplier: common.RollupConstExchangeMultiplier, } diff --git a/api/swagger.yml b/api/swagger.yml index 486395f..6c0f5cf 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -2729,11 +2729,11 @@ components: properties: ceilUSD: type: string - description: Max USD value + description: Max USD value that bucket holds example: "1000" blockStamp: type: string - description: Block stamp + description: Block number of the last bucket update example: "1" withdrawals: type: string @@ -2741,11 +2741,11 @@ components: example: "4" rateBlocks: type: string - description: Rate of blocks + description: rateBlocks every `rateBlocks` blocks add `rateWithdrawals` withdrawal example: "2" rateWithdrawals: type: string - description: Rate of withdrawals + description: add `rateWithdrawals` every `rateBlocks` example: "3" maxWithdrawals: type: string diff --git a/common/ethrollup.go b/common/ethrollup.go index 42a08ea..40c55d1 100644 --- a/common/ethrollup.go +++ b/common/ethrollup.go @@ -37,8 +37,6 @@ const ( // _L1_USER_TOTALBYTES bytes] l1TxsData + totalL2TxsDataLength + feeIdxCoordinatorLength + // [2 bytes] chainID = 18542 bytes + totalL2TxsDataLength + feeIdxCoordinatorLength RollupConstInputSHAConstantBytes = 18546 - // RollupConstNumBuckets Number of buckets - RollupConstNumBuckets = 5 // RollupConstMaxWithdrawalDelay max withdrawal delay in seconds RollupConstMaxWithdrawalDelay = 2 * 7 * 24 * 60 * 60 // RollupConstExchangeMultiplier exchange multiplier @@ -160,12 +158,12 @@ type TokenExchange struct { // RollupVariables are the variables of the Rollup Smart Contract //nolint:lll type RollupVariables struct { - EthBlockNum int64 `meddler:"eth_block_num"` - FeeAddToken *big.Int `meddler:"fee_add_token,bigint" validate:"required"` - ForgeL1L2BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"` - WithdrawalDelay uint64 `meddler:"withdrawal_delay" validate:"required"` - Buckets [RollupConstNumBuckets]BucketParams `meddler:"buckets,json"` - SafeMode bool `meddler:"safe_mode"` + EthBlockNum int64 `meddler:"eth_block_num"` + FeeAddToken *big.Int `meddler:"fee_add_token,bigint" validate:"required"` + ForgeL1L2BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"` + WithdrawalDelay uint64 `meddler:"withdrawal_delay" validate:"required"` + Buckets []BucketParams `meddler:"buckets,json"` + SafeMode bool `meddler:"safe_mode"` } // Copy returns a deep copy of the Variables diff --git a/db/historydb/views.go b/db/historydb/views.go index f869db9..0649e4d 100644 --- a/db/historydb/views.go +++ b/db/historydb/views.go @@ -364,12 +364,12 @@ type BucketParamsAPI struct { // RollupVariablesAPI are the variables of the Rollup Smart Contract type RollupVariablesAPI struct { - EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"` - FeeAddToken *apitypes.BigIntStr `json:"feeAddToken" meddler:"fee_add_token" validate:"required"` - ForgeL1L2BatchTimeout int64 `json:"forgeL1L2BatchTimeout" meddler:"forge_l1_timeout" validate:"required"` - WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"` - Buckets [common.RollupConstNumBuckets]BucketParamsAPI `json:"buckets" meddler:"buckets,json"` - SafeMode bool `json:"safeMode" meddler:"safe_mode"` + EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"` + FeeAddToken *apitypes.BigIntStr `json:"feeAddToken" meddler:"fee_add_token" validate:"required"` + ForgeL1L2BatchTimeout int64 `json:"forgeL1L2BatchTimeout" meddler:"forge_l1_timeout" validate:"required"` + WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"` + Buckets []BucketParamsAPI `json:"buckets" meddler:"buckets,json"` + SafeMode bool `json:"safeMode" meddler:"safe_mode"` } // NewRollupVariablesAPI creates a RollupVariablesAPI from common.RollupVariables diff --git a/eth/rollup.go b/eth/rollup.go index c243532..5e2825b 100644 --- a/eth/rollup.go +++ b/eth/rollup.go @@ -60,7 +60,7 @@ type RollupEventInitialize struct { // RollupVariables returns the RollupVariables from the initialize event func (ei *RollupEventInitialize) RollupVariables() *common.RollupVariables { - var buckets [common.RollupConstNumBuckets]common.BucketParams + buckets := make([]common.BucketParams, 1) for i := range buckets { buckets[i] = common.BucketParams{ CeilUSD: big.NewInt(0), @@ -161,8 +161,7 @@ type rollupEventUpdateBucketsParametersAux struct { // RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract type RollupEventUpdateBucketsParameters struct { - // ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int - ArrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters + ArrayBuckets []RollupUpdateBucketsParameters SafeMode bool } @@ -496,8 +495,8 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ babyjub.PublicKeyComp, fro auth.Value = depositAmount } var permit []byte - return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, big.NewInt(0).SetUint64(uint64(depositAmountF)), - big.NewInt(0).SetUint64(uint64(amountF)), tokenID, toIdxBig, permit) + return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, big.NewInt(int64(depositAmountF)), + big.NewInt(int64(amountF)), tokenID, toIdxBig, permit) }, ); err != nil { return nil, tracerr.Wrap(fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err)) @@ -545,7 +544,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ babyjub.PublicKeyComp, signature, _ := c.client.ks.SignHash(*c.client.account, digest) permit := createPermit(owner, spender, amount, deadline, digest, signature) return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, - big.NewInt(0).SetUint64(uint64(depositAmountF)), big.NewInt(0).SetUint64(uint64(amountF)), tokenID, toIdxBig, permit) + big.NewInt(int64(depositAmountF)), big.NewInt(int64(amountF)), tokenID, toIdxBig, permit) }, ); err != nil { return nil, tracerr.Wrap(fmt.Errorf("Failed add L1 Tx ERC20Permit: %w", err)) @@ -607,14 +606,16 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *typ // RollupUpdateBucketsParameters is the interface to call the smart contract function func (c *RollupClient) RollupUpdateBucketsParameters( - arrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters, + arrayBuckets []RollupUpdateBucketsParameters, ) (tx *types.Transaction, err error) { if tx, err = c.client.CallAuth( 12500000, //nolint:gomnd func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { params := make([]*big.Int, len(arrayBuckets)) for i, bucket := range arrayBuckets { - params[i], err = c.hermez.PackBucket(c.opts, bucket.CeilUSD, bucket.BlockStamp, bucket.Withdrawals, bucket.RateBlocks, bucket.RateWithdrawals, bucket.MaxWithdrawals) + params[i], err = c.hermez.PackBucket(c.opts, + bucket.CeilUSD, bucket.BlockStamp, bucket.Withdrawals, + bucket.RateBlocks, bucket.RateWithdrawals, bucket.MaxWithdrawals) if err != nil { return nil, tracerr.Wrap(fmt.Errorf("failed to pack bucket: %w", err)) } @@ -909,6 +910,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64, if err != nil { return nil, tracerr.Wrap(err) } + bucketsParameters.ArrayBuckets = make([]RollupUpdateBucketsParameters, len(bucketsParametersAux.ArrayBuckets)) for i, bucket := range bucketsParametersAux.ArrayBuckets { bucket, err := c.hermez.UnpackBucket(c.opts, bucket) if err != nil { diff --git a/eth/rollup_test.go b/eth/rollup_test.go index aecf459..feb299d 100644 --- a/eth/rollup_test.go +++ b/eth/rollup_test.go @@ -234,7 +234,7 @@ func TestRollupUpdateFeeAddToken(t *testing.T) { } func TestRollupUpdateBucketsParameters(t *testing.T) { - var bucketsParameters [common.RollupConstNumBuckets]RollupUpdateBucketsParameters + bucketsParameters := make([]RollupUpdateBucketsParameters, 5) for i := range bucketsParameters { bucketsParameters[i].CeilUSD = big.NewInt(int64((i + 1) * 100)) bucketsParameters[i].BlockStamp = big.NewInt(int64(0)) diff --git a/test/ethclient.go b/test/ethclient.go index 74fa7f4..9453f42 100644 --- a/test/ethclient.go +++ b/test/ethclient.go @@ -301,7 +301,7 @@ func NewClientSetupExample() *ClientSetup { HermezAuctionContract: ethCommon.HexToAddress("0x8E442975805fb1908f43050c9C1A522cB0e28D7b"), WithdrawDelayerContract: ethCommon.HexToAddress("0x5CB7979cBdbf65719BEE92e4D15b7b7Ed3D79114"), } - var buckets [common.RollupConstNumBuckets]common.BucketParams + buckets := make([]common.BucketParams, 1) for i := range buckets { buckets[i] = common.BucketParams{ CeilUSD: big.NewInt(0),