mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
update contracts
This commit is contained in:
193
eth/auction.go
193
eth/auction.go
@@ -5,6 +5,7 @@ import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
@@ -14,8 +15,6 @@ import (
|
||||
|
||||
// AuctionConstants are the constants of the Rollup Smart Contract
|
||||
type AuctionConstants struct {
|
||||
// Blocks to wait before starting with the first slot
|
||||
DelayGenesis uint16
|
||||
// Blocks per slot
|
||||
BlocksPerSlot uint8
|
||||
// Minimum bid when no one has bid yet
|
||||
@@ -23,6 +22,7 @@ type AuctionConstants struct {
|
||||
// First block where the first slot begins
|
||||
GenesisBlockNum int64
|
||||
// Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee
|
||||
// Only for test
|
||||
GovernanceAddress ethCommon.Address
|
||||
// ERC777 token with which the bids will be made
|
||||
TokenHEZ ethCommon.Address
|
||||
@@ -57,9 +57,9 @@ type Coordinator struct {
|
||||
// AuctionVariables are the variables of the Auction Smart Contract
|
||||
type AuctionVariables struct {
|
||||
// Boot Coordinator Address
|
||||
DonationAddress ethCommon.Address
|
||||
DonationAddress *ethCommon.Address
|
||||
// Boot Coordinator Address
|
||||
BootCoordinator ethCommon.Address
|
||||
BootCoordinator *ethCommon.Address
|
||||
// The minimum bid value in a series of 6 slots
|
||||
DefaultSlotSetBid [6]*big.Int
|
||||
// Distance (#slots) to the closest slot to which you can bid ( 2 Slots = 2 * 40 Blocks = 20 min )
|
||||
@@ -246,11 +246,11 @@ type AuctionInterface interface {
|
||||
maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
|
||||
|
||||
// Forge
|
||||
AuctionCanForge(forger ethCommon.Address) (bool, error)
|
||||
AuctionCanForge(forger ethCommon.Address, blockNumber *big.Int) (bool, error)
|
||||
// AuctionForge(forger ethCommon.Address) (bool, error) // Only called from another smart contract
|
||||
|
||||
// Fees
|
||||
AuctionClaimHEZ() (*types.Transaction, error)
|
||||
AuctionClaimHEZ(claimAddress common.Address) (*types.Transaction, error)
|
||||
|
||||
//
|
||||
// Smart Contract Status
|
||||
@@ -384,11 +384,11 @@ func (c *AuctionClient) AuctionGetClosedAuctionSlots() (uint16, error) {
|
||||
}
|
||||
|
||||
// AuctionSetOutbidding is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint8) (*types.Transaction, error) {
|
||||
func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
12500000,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -404,25 +404,22 @@ func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint8) (*types.Transa
|
||||
|
||||
// AuctionGetOutbidding is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetOutbidding() (uint16, error) {
|
||||
// TODO: Update
|
||||
// var outbidding uint8
|
||||
// if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
// auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// outbidding, err = auction.GetOutbidding(nil)
|
||||
// return err
|
||||
// }); err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// return outbidding, nil
|
||||
log.Error("TODO")
|
||||
return 0, errTODO
|
||||
var outbidding uint16
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outbidding, err = auction.GetOutbidding(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return outbidding, nil
|
||||
}
|
||||
|
||||
// AuctionSetAllocationRatio is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint8) (*types.Transaction, error) {
|
||||
func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
@@ -442,21 +439,18 @@ func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint8) (
|
||||
|
||||
// AuctionGetAllocationRatio is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint16, error) {
|
||||
// TODO: Update
|
||||
// var allocationRation [3]uint8
|
||||
// if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
// auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// allocationRation, err = auction.GetAllocationRatio(nil)
|
||||
// return err
|
||||
// }); err != nil {
|
||||
// return [3]uint8{}, err
|
||||
// }
|
||||
// return allocationRation, nil
|
||||
log.Error("TODO")
|
||||
return [3]uint16{}, errTODO
|
||||
var allocationRation [3]uint16
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
allocationRation, err = auction.GetAllocationRatio(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return [3]uint16{}, err
|
||||
}
|
||||
return allocationRation, nil
|
||||
}
|
||||
|
||||
// AuctionSetDonationAddress is the interface to call the smart contract function
|
||||
@@ -529,8 +523,8 @@ func (c *AuctionClient) AuctionGetBootCoordinator() (*ethCommon.Address, error)
|
||||
return &bootCoordinator, nil
|
||||
}
|
||||
|
||||
// AuctionChangeEpochMinBid is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionChangeEpochMinBid(slotEpoch int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
|
||||
// AuctionChangeDefaultSlotSetBid is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
@@ -540,15 +534,12 @@ func (c *AuctionClient) AuctionChangeEpochMinBid(slotEpoch int64, newInitialMinB
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
slotEpochToSend := big.NewInt(slotEpoch)
|
||||
fmt.Println(slotEpochToSend)
|
||||
fmt.Println(newInitialMinBid)
|
||||
return auction.ChangeEpochMinBid(auth, slotEpochToSend, newInitialMinBid)
|
||||
slotSetToSend := big.NewInt(slotSet)
|
||||
return auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed changing epoch minBid: %w", err)
|
||||
}
|
||||
fmt.Println(tx)
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
@@ -642,22 +633,18 @@ func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) {
|
||||
|
||||
// AuctionGetDefaultSlotSetBid is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) {
|
||||
// TODO: Update
|
||||
// var DefaultSlotSetBid *big.Int
|
||||
// if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
// auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defaultSlotSetBid, err = auction.GetDefaultSlotSetBid(nil, slotSet)
|
||||
// return err
|
||||
// }); err != nil {
|
||||
// return big.NewInt(0), err
|
||||
// }
|
||||
// return defaultSlotSetBid, nil
|
||||
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
var minBidSlotSet *big.Int
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
minBidSlotSet, err = auction.GetDefaultSlotSetBid(nil, slotSet)
|
||||
return err
|
||||
}); err != nil {
|
||||
return big.NewInt(0), err
|
||||
}
|
||||
return minBidSlotSet, nil
|
||||
}
|
||||
|
||||
// AuctionTokensReceived is the interface to call the smart contract function
|
||||
@@ -678,9 +665,19 @@ func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, sl
|
||||
}
|
||||
|
||||
// AuctionCanForge is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address) (bool, error) {
|
||||
log.Error("TODO")
|
||||
return false, errTODO
|
||||
func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNumber *big.Int) (bool, error) {
|
||||
var canForge bool
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
canForge, err = auction.CanForge(nil, forger, blockNumber)
|
||||
return err
|
||||
}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return canForge, nil
|
||||
}
|
||||
|
||||
// AuctionForge is the interface to call the smart contract function
|
||||
@@ -689,15 +686,71 @@ func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address) (bool, error)
|
||||
// }
|
||||
|
||||
// AuctionClaimHEZ is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionClaimHEZ() (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
func (c *AuctionClient) AuctionClaimHEZ(claimAddress common.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.ClaimHEZ(auth, claimAddress)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed claim HEZ: %w", err)
|
||||
}
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// AuctionConstants returns the Constants of the Auction Smart Contract
|
||||
func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
auctionConstants := new(AuctionConstants)
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionConstants.BlocksPerSlot, err = auction.BLOCKSPERSLOT(nil)
|
||||
genesisBlock, err := auction.GenesisBlock(nil)
|
||||
auctionConstants.GenesisBlockNum = genesisBlock.Int64()
|
||||
auctionConstants.HermezRollup, err = auction.HermezRollup(nil)
|
||||
auctionConstants.InitialMinimalBidding, err = auction.INITIALMINIMALBIDDING(nil)
|
||||
auctionConstants.TokenHEZ, err = auction.TokenHEZ(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auctionConstants, nil
|
||||
}
|
||||
|
||||
// AuctionVariables returns the variables of the Auction Smart Contract
|
||||
func (c *AuctionClient) AuctionVariables() (*AuctionVariables, error) {
|
||||
auctionVariables := new(AuctionVariables)
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
var err error
|
||||
auctionVariables.AllocationRatio, err = c.AuctionGetAllocationRatio()
|
||||
auctionVariables.BootCoordinator, err = c.AuctionGetBootCoordinator()
|
||||
auctionVariables.ClosedAuctionSlots, err = c.AuctionGetClosedAuctionSlots()
|
||||
var defaultSlotSetBid [6]*big.Int
|
||||
for i := uint8(0); i < 6; i++ {
|
||||
bid, err := c.AuctionGetDefaultSlotSetBid(i)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defaultSlotSetBid[i] = bid
|
||||
}
|
||||
auctionVariables.DefaultSlotSetBid = defaultSlotSetBid
|
||||
auctionVariables.DonationAddress, err = c.AuctionGetDonationAddress()
|
||||
auctionVariables.OpenAuctionSlots, err = c.AuctionGetOpenAuctionSlots()
|
||||
auctionVariables.Outbidding, err = c.AuctionGetOutbidding()
|
||||
auctionVariables.SlotDeadline, err = c.AuctionGetSlotDeadline()
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auctionVariables, nil
|
||||
}
|
||||
|
||||
// AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -15,22 +16,24 @@ import (
|
||||
const slotDeadlineConst = uint8(20)
|
||||
const openAuctionSlotsConst = uint16(4320)
|
||||
const closedAuctionSlotsConst = uint16(2)
|
||||
const outbiddingConst = uint8(10)
|
||||
const outbiddingConst = uint16(1000)
|
||||
const currentSlotConst = 0
|
||||
|
||||
var allocationRatioConst [3]uint8 = [3]uint8{40, 40, 20}
|
||||
var allocationRatioConst [3]uint16 = [3]uint16{4000, 4000, 2000}
|
||||
|
||||
var auctionClient *AuctionClient
|
||||
|
||||
/*var donationAddressStr = os.Getenv("DONATION_ADDRESS")
|
||||
var bootCoordinatorStr = os.Getenv("BOOT_COORDINATOR_ADDRESS")
|
||||
var integration = os.Getenv("INTEGRATION")
|
||||
var ehtClientDialURL = os.Getenv("ETHCLIENT_DIAL_URL")
|
||||
var auctionAddressStr = os.Getenv("AUCTION_ADDRESS")*/
|
||||
var integration = os.Getenv("INTEGRATION")
|
||||
|
||||
var donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
|
||||
var bootCoordinatorStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
|
||||
var integration = os.Getenv("INTEGRATION")
|
||||
var DONATION = common.HexToAddress(donationAddressStr)
|
||||
var BOOTCOORDINATOR = common.HexToAddress(bootCoordinatorStr)
|
||||
|
||||
var ehtClientDialURL = "http://localhost:8545"
|
||||
var auctionAddressStr = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5"
|
||||
var ownerAddressStr = "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
@@ -39,6 +42,9 @@ var governancePrivateKey = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f
|
||||
var minBidStr = "10000000000000000000"
|
||||
var URL = "http://localhost:3000"
|
||||
var newURL = "http://localhost:3002"
|
||||
var BLOCKSPERSLOT = uint8(40)
|
||||
var TOKENHEZ = common.HexToAddress("0xf4e77E5Da47AC3125140c470c71cBca77B5c638c")
|
||||
var HERMEZROLLUP = common.HexToAddress("0xc4905364b78a742ccce7B890A89514061E47068D")
|
||||
|
||||
var pathKs = "test/ks"
|
||||
var password = "pass"
|
||||
@@ -54,7 +60,9 @@ func TestNewAction(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
ethereumClient := NewEthereumClient(ethClient, &account, ks, nil)
|
||||
auctionAddress := common.HexToAddress(auctionAddressStr)
|
||||
if integration != "" {
|
||||
auctionClient = NewAuctionClient(ethereumClient, auctionAddress)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuctionGetCurrentSlotNumber(t *testing.T) {
|
||||
@@ -66,6 +74,38 @@ func TestAuctionGetCurrentSlotNumber(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuctionConstants(t *testing.T) {
|
||||
INITMINBID := new(big.Int)
|
||||
INITMINBID.SetString(minBidStr, 10)
|
||||
if auctionClient != nil {
|
||||
auctionConstants, err := auctionClient.AuctionConstants()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, auctionConstants.BlocksPerSlot, BLOCKSPERSLOT)
|
||||
// assert.Equal(t, auctionConstants.GenesisBlockNum, GENESISBLOCKNUM)
|
||||
assert.Equal(t, auctionConstants.HermezRollup, HERMEZROLLUP)
|
||||
assert.Equal(t, auctionConstants.InitialMinimalBidding, INITMINBID)
|
||||
assert.Equal(t, auctionConstants.TokenHEZ, TOKENHEZ)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuctionVariables(t *testing.T) {
|
||||
INITMINBID := new(big.Int)
|
||||
INITMINBID.SetString(minBidStr, 10)
|
||||
defaultSlotSetBid := [6]*big.Int{INITMINBID, INITMINBID, INITMINBID, INITMINBID, INITMINBID, INITMINBID}
|
||||
if auctionClient != nil {
|
||||
auctionVariables, err := auctionClient.AuctionVariables()
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, auctionVariables.AllocationRatio, allocationRatioConst)
|
||||
assert.Equal(t, auctionVariables.BootCoordinator, &BOOTCOORDINATOR)
|
||||
assert.Equal(t, auctionVariables.ClosedAuctionSlots, closedAuctionSlotsConst)
|
||||
assert.Equal(t, auctionVariables.DefaultSlotSetBid, defaultSlotSetBid)
|
||||
assert.Equal(t, auctionVariables.DonationAddress, &DONATION)
|
||||
assert.Equal(t, auctionVariables.OpenAuctionSlots, openAuctionSlotsConst)
|
||||
assert.Equal(t, auctionVariables.Outbidding, outbiddingConst)
|
||||
assert.Equal(t, auctionVariables.SlotDeadline, slotDeadlineConst)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuctionGetSlotDeadline(t *testing.T) {
|
||||
if auctionClient != nil {
|
||||
slotDeadline, err := auctionClient.AuctionGetSlotDeadline()
|
||||
@@ -135,7 +175,7 @@ func TestAuctionGetOutbidding(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuctionSetOutbidding(t *testing.T) {
|
||||
newOutbidding := uint8(15)
|
||||
newOutbidding := uint16(0xb)
|
||||
if auctionClient != nil {
|
||||
_, err := auctionClient.AuctionSetOutbidding(newOutbidding)
|
||||
require.Nil(t, err)
|
||||
@@ -155,7 +195,7 @@ func TestAuctionGetAllocationRatio(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuctionSetAllocationRatio(t *testing.T) {
|
||||
newAllocationRatio := [3]uint8{30, 30, 40}
|
||||
newAllocationRatio := [3]uint16{3000, 3000, 4000}
|
||||
if auctionClient != nil {
|
||||
_, err := auctionClient.AuctionSetAllocationRatio(newAllocationRatio)
|
||||
require.Nil(t, err)
|
||||
@@ -210,32 +250,33 @@ func TestAuctionSetBootCoordinator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuctionGetMinBidEpoch(t *testing.T) {
|
||||
epoch := uint8(3)
|
||||
func TestAuctionGetDefaultSlotSetBid(t *testing.T) {
|
||||
slotSet := uint8(3)
|
||||
if auctionClient != nil {
|
||||
minBid, err := auctionClient.AuctionGetMinBidEpoch(epoch)
|
||||
minBid, err := auctionClient.AuctionGetDefaultSlotSetBid(slotSet)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, minBid.String(), minBidStr)
|
||||
}
|
||||
}
|
||||
|
||||
/* func TestAuctionChangeEpochMinBid(t *testing.T) {
|
||||
slotEpoch := int64(3)
|
||||
epoch := uint8(3)
|
||||
func TestAuctionChangeEpochMinBid(t *testing.T) {
|
||||
slotSet := int64(3)
|
||||
set := uint8(3)
|
||||
newInitialMinBid := new(big.Int)
|
||||
newInitialMinBid.SetString("20000000000000000000", 10)
|
||||
if auctionClient != nil {
|
||||
_, err := auctionClient.AuctionChangeEpochMinBid(slotEpoch, newInitialMinBid)
|
||||
_, err := auctionClient.AuctionChangeDefaultSlotSetBid(slotSet, newInitialMinBid)
|
||||
require.Nil(t, err)
|
||||
minBid, err := auctionClient.AuctionGetMinBidEpoch(epoch)
|
||||
minBid, err := auctionClient.AuctionGetDefaultSlotSetBid(set)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, minBid, newInitialMinBid)
|
||||
newMinBid := new(big.Int)
|
||||
newMinBid.SetString("10000000000000000000", 10)
|
||||
_, err = auctionClient.AuctionChangeEpochMinBid(slotEpoch, newMinBid)
|
||||
_, err = auctionClient.AuctionChangeDefaultSlotSetBid(slotSet, newMinBid)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
func TestAuctionIsRegisteredCoordinator(t *testing.T) {
|
||||
forgerAddress := common.HexToAddress(governanceAddressStr)
|
||||
if auctionClient != nil {
|
||||
@@ -262,7 +303,7 @@ func TestAuctionIsRegisteredCoordinatorTrue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func AuctionUpdateCoordinatorInfo(t *testing.T) {
|
||||
func TestAuctionUpdateCoordinatorInfo(t *testing.T) {
|
||||
forgerAddress := common.HexToAddress(governanceAddressStr)
|
||||
if auctionClient != nil {
|
||||
_, err := auctionClient.AuctionUpdateCoordinatorInfo(forgerAddress, forgerAddress, newURL)
|
||||
|
||||
@@ -9,6 +9,6 @@ abigen --abi=HermezAuctionProtocol.abi --bin=HermezAuctionProtocol.bin --pkg=Her
|
||||
```
|
||||
You must compile the contracts to get the `.bin` and `.abi` files. The contracts used are in the repo: https://github.com/hermeznetwork/contracts-circuits
|
||||
|
||||
Specifically they have been processed in the commit with hash: `0ba124d60e192afda99ef4703aa13b8fef4a392a`
|
||||
Specifically they have been processed in the commit with hash: `745e8d588496d7762d4084a54bafd4435061ae35`
|
||||
|
||||
> abigen version 1.9.21
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
174
eth/rollup.go
174
eth/rollup.go
@@ -5,7 +5,9 @@ import (
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
Hermez "github.com/hermeznetwork/hermez-node/eth/contracts/hermez"
|
||||
"github.com/hermeznetwork/hermez-node/log"
|
||||
"github.com/hermeznetwork/hermez-node/utils"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
@@ -24,28 +26,37 @@ type RollupConstants struct {
|
||||
// Maxim Deposit allowed
|
||||
MaxAmountDeposit *big.Int
|
||||
MaxAmountL2 *big.Int
|
||||
MaxTokens uint32
|
||||
MaxTokens *big.Int
|
||||
// maximum L1 transactions allowed to be queued for a batch
|
||||
MaxL1Tx int
|
||||
MaxL1Tx *big.Int
|
||||
// maximum L1 user transactions allowed to be queued for a batch
|
||||
MaxL1UserTx int
|
||||
MaxL1UserTx *big.Int
|
||||
Rfield *big.Int
|
||||
L1CoordinatorBytes int
|
||||
L1UserBytes int
|
||||
L2Bytes int
|
||||
L1CoordinatorBytes *big.Int
|
||||
L1UserBytes *big.Int
|
||||
L2Bytes *big.Int
|
||||
MaxTxVerifiers []int
|
||||
TokenHEZ ethCommon.Address
|
||||
// Only test
|
||||
GovernanceAddress ethCommon.Address
|
||||
// Only test
|
||||
SafetyBot ethCommon.Address
|
||||
// Only test
|
||||
ConsensusContract ethCommon.Address
|
||||
// Only test
|
||||
WithdrawalContract ethCommon.Address
|
||||
ReservedIDx uint32
|
||||
LastIDx uint32
|
||||
ExitIDx uint32
|
||||
NoLimitToken *big.Int
|
||||
NumBuckets *big.Int
|
||||
MaxWDelay *big.Int
|
||||
}
|
||||
|
||||
// RollupVariables are the variables of the Rollup Smart Contract
|
||||
type RollupVariables struct {
|
||||
MaxTxVerifiers []int
|
||||
TokenHEZ ethCommon.Address
|
||||
GovernanceAddress ethCommon.Address
|
||||
SafetyBot ethCommon.Address
|
||||
ConsensusContract ethCommon.Address
|
||||
WithdrawalContract ethCommon.Address
|
||||
FeeAddToken *big.Int
|
||||
ForgeL1Timeout int64
|
||||
FeeL1UserTx *big.Int
|
||||
}
|
||||
|
||||
// QueueStruct is the queue of L1Txs for a batch
|
||||
@@ -78,9 +89,11 @@ type RollupState struct {
|
||||
CurrentIdx int64
|
||||
}
|
||||
|
||||
// RollupEventL1UserTx is an event of the Rollup Smart Contract
|
||||
type RollupEventL1UserTx struct {
|
||||
// RollupEventL1UserTxEvent is an event of the Rollup Smart Contract
|
||||
type RollupEventL1UserTxEvent struct {
|
||||
L1Tx common.L1Tx
|
||||
QueueIndex *big.Int
|
||||
TransactionIndex *big.Int
|
||||
}
|
||||
|
||||
// RollupEventAddToken is an event of the Rollup Smart Contract
|
||||
@@ -91,18 +104,13 @@ type RollupEventAddToken struct {
|
||||
|
||||
// RollupEventForgeBatch is an event of the Rollup Smart Contract
|
||||
type RollupEventForgeBatch struct {
|
||||
BatchNum int64
|
||||
BatchNum *big.Int
|
||||
EthTxHash ethCommon.Hash
|
||||
}
|
||||
|
||||
// RollupEventUpdateForgeL1Timeout is an event of the Rollup Smart Contract
|
||||
type RollupEventUpdateForgeL1Timeout struct {
|
||||
ForgeL1Timeout int64
|
||||
}
|
||||
|
||||
// RollupEventUpdateFeeL1UserTx is an event of the Rollup Smart Contract
|
||||
type RollupEventUpdateFeeL1UserTx struct {
|
||||
FeeL1UserTx *big.Int
|
||||
// RollupEventUpdateForgeL1L2BatchTimeout is an event of the Rollup Smart Contract
|
||||
type RollupEventUpdateForgeL1L2BatchTimeout struct {
|
||||
ForgeL1Timeout *big.Int
|
||||
}
|
||||
|
||||
// RollupEventUpdateFeeAddToken is an event of the Rollup Smart Contract
|
||||
@@ -110,40 +118,32 @@ type RollupEventUpdateFeeAddToken struct {
|
||||
FeeAddToken *big.Int
|
||||
}
|
||||
|
||||
// RollupEventUpdateTokenHez is an event of the Rollup Smart Contract
|
||||
type RollupEventUpdateTokenHez struct {
|
||||
TokenHEZ ethCommon.Address
|
||||
}
|
||||
|
||||
// RollupEventWithdraw is an event of the Rollup Smart Contract
|
||||
type RollupEventWithdraw struct {
|
||||
Idx int64
|
||||
NumExitRoot int
|
||||
// RollupEventWithdrawEvent is an event of the Rollup Smart Contract
|
||||
type RollupEventWithdrawEvent struct {
|
||||
Idx *big.Int
|
||||
NumExitRoot *big.Int
|
||||
InstantWithdraw bool
|
||||
}
|
||||
|
||||
// RollupEvents is the list of events in a block of the Rollup Smart Contract
|
||||
type RollupEvents struct { //nolint:structcheck
|
||||
L1UserTx []RollupEventL1UserTx
|
||||
L1UserTxEvent []RollupEventL1UserTxEvent
|
||||
AddToken []RollupEventAddToken
|
||||
ForgeBatch []RollupEventForgeBatch
|
||||
UpdateForgeL1Timeout []RollupEventUpdateForgeL1Timeout
|
||||
UpdateFeeL1UserTx []RollupEventUpdateFeeL1UserTx
|
||||
UpdateForgeL1L2BatchTimeout []RollupEventUpdateForgeL1L2BatchTimeout
|
||||
UpdateFeeAddToken []RollupEventUpdateFeeAddToken
|
||||
UpdateTokenHez []RollupEventUpdateTokenHez
|
||||
Withdraw []RollupEventWithdraw
|
||||
WithdrawEvent []RollupEventWithdrawEvent
|
||||
}
|
||||
|
||||
// NewRollupEvents creates an empty RollupEvents with the slices initialized.
|
||||
func NewRollupEvents() RollupEvents {
|
||||
return RollupEvents{
|
||||
L1UserTx: make([]RollupEventL1UserTx, 0),
|
||||
L1UserTxEvent: make([]RollupEventL1UserTxEvent, 0),
|
||||
AddToken: make([]RollupEventAddToken, 0),
|
||||
ForgeBatch: make([]RollupEventForgeBatch, 0),
|
||||
UpdateForgeL1Timeout: make([]RollupEventUpdateForgeL1Timeout, 0),
|
||||
UpdateFeeL1UserTx: make([]RollupEventUpdateFeeL1UserTx, 0),
|
||||
UpdateForgeL1L2BatchTimeout: make([]RollupEventUpdateForgeL1L2BatchTimeout, 0),
|
||||
UpdateFeeAddToken: make([]RollupEventUpdateFeeAddToken, 0),
|
||||
UpdateTokenHez: make([]RollupEventUpdateTokenHez, 0),
|
||||
Withdraw: make([]RollupEventWithdraw, 0),
|
||||
WithdrawEvent: make([]RollupEventWithdrawEvent, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,8 +175,7 @@ type RollupInterface interface {
|
||||
|
||||
RollupForgeBatch(*RollupForgeBatchArgs) (*types.Transaction, error)
|
||||
RollupAddToken(tokenAddress ethCommon.Address) (*types.Transaction, error)
|
||||
// RollupWithdrawSNARK() (*types.Transaction, error) // TODO (Not defined in Hermez.sol)
|
||||
RollupWithdrawMerkleProof(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey,
|
||||
RollupWithdraw(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey,
|
||||
numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (*types.Transaction, error)
|
||||
RollupForceExit(fromIdx int64, amountF utils.Float16, tokenID int64) (*types.Transaction, error)
|
||||
RollupForceTransfer(fromIdx int64, amountF utils.Float16, tokenID, toIdx int64) (*types.Transaction, error)
|
||||
@@ -190,16 +189,14 @@ type RollupInterface interface {
|
||||
RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey, loadAmountF utils.Float16,
|
||||
tokenID int64) (*types.Transaction, error)
|
||||
|
||||
RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error)
|
||||
RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error)
|
||||
RollupGetQueue(queue int64) ([]byte, error)
|
||||
RollupGetCurrentTokens() (*big.Int, error)
|
||||
// RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error)
|
||||
// RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error)
|
||||
// RollupGetQueue(queue int64) ([]byte, error)
|
||||
|
||||
// Governance Public Functions
|
||||
RollupUpdateForgeL1Timeout(newForgeL1Timeout int64) (*types.Transaction, error)
|
||||
RollupUpdateFeeL1UserTx(newFeeL1UserTx *big.Int) (*types.Transaction, error)
|
||||
RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (*types.Transaction, error)
|
||||
RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.Transaction, error)
|
||||
RollupUpdateTokensHEZ(newTokenHEZ ethCommon.Address) (*types.Transaction, error)
|
||||
// RollupUpdateGovernance() (*types.Transaction, error) // TODO (Not defined in Hermez.sol)
|
||||
|
||||
//
|
||||
// Smart Contract Status
|
||||
@@ -245,8 +242,8 @@ func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address) (*types.Tr
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupWithdrawMerkleProof is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupWithdrawMerkleProof(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey, numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (*types.Transaction, error) {
|
||||
// RollupWithdraw is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupWithdraw(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey, numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
@@ -294,31 +291,28 @@ func (c *RollupClient) RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey,
|
||||
}
|
||||
|
||||
// RollupGetTokenAddress is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error) {
|
||||
/* func (c *RollupClient) RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error) {
|
||||
return nil, errTODO
|
||||
} */
|
||||
|
||||
// RollupGetCurrentTokens is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupGetCurrentTokens() (*big.Int, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupGetL1TxFromQueue is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
||||
log.Error("TODO")
|
||||
/* func (c *RollupClient) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
||||
return nil, errTODO
|
||||
}
|
||||
} */
|
||||
|
||||
// RollupGetQueue is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupGetQueue(queue int64) ([]byte, error) {
|
||||
log.Error("TODO")
|
||||
/* func (c *RollupClient) RollupGetQueue(queue int64) ([]byte, error) {
|
||||
return nil, errTODO
|
||||
}
|
||||
}*/
|
||||
|
||||
// RollupUpdateForgeL1Timeout is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupUpdateForgeL1Timeout(newForgeL1Timeout int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupUpdateFeeL1UserTx is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupUpdateFeeL1UserTx(newFeeL1UserTx *big.Int) (*types.Transaction, error) {
|
||||
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
@@ -329,21 +323,37 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupUpdateTokensHEZ is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupUpdateTokensHEZ(newTokenHEZ ethCommon.Address) (*types.Transaction, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
}
|
||||
|
||||
// RollupUpdateGovernance is the interface to call the smart contract function
|
||||
// func (c *RollupClient) RollupUpdateGovernance() (*types.Transaction, error) { // TODO (Not defined in Hermez.sol)
|
||||
// return nil, errTODO
|
||||
// }
|
||||
|
||||
// RollupConstants returns the Constants of the Rollup Smart Contract
|
||||
func (c *RollupClient) RollupConstants() (*RollupConstants, error) {
|
||||
log.Error("TODO")
|
||||
return nil, errTODO
|
||||
rollupConstants := new(RollupConstants)
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
rollup, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// rollupConstants.GovernanceAddress :=
|
||||
rollupConstants.L1CoordinatorBytes, err = rollup.L1COORDINATORBYTES(nil)
|
||||
rollupConstants.L1UserBytes, err = rollup.L1USERBYTES(nil)
|
||||
rollupConstants.L2Bytes, err = rollup.L2BYTES(nil)
|
||||
rollupConstants.LastIDx, err = rollup.LASTIDX(nil)
|
||||
rollupConstants.MaxAmountDeposit, err = rollup.MAXLOADAMOUNT(nil)
|
||||
rollupConstants.MaxAmountL2, err = rollup.MAXAMOUNT(nil)
|
||||
rollupConstants.MaxL1Tx, err = rollup.MAXL1TX(nil)
|
||||
rollupConstants.MaxL1UserTx, err = rollup.MAXL1USERTX(nil)
|
||||
rollupConstants.MaxTokens, err = rollup.MAXTOKENS(nil)
|
||||
rollupConstants.MaxWDelay, err = rollup.MAXWITHDRAWALDELAY(nil)
|
||||
rollupConstants.NoLimitToken, err = rollup.NOLIMIT(nil)
|
||||
rollupConstants.NumBuckets, err = rollup.NUMBUCKETS(nil)
|
||||
// rollupConstants.ReservedIDx =
|
||||
rollupConstants.Rfield, err = rollup.RFIELD(nil)
|
||||
// rollupConstants.SafetyBot =
|
||||
// rollupConstants.TokenHEZ =
|
||||
// rollupConstants.WithdrawalContract =
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rollupConstants, nil
|
||||
}
|
||||
|
||||
// RollupEventsByBlock returns the events in a block that happened in the Rollup Smart Contract
|
||||
|
||||
34
eth/rollup_test.go
Normal file
34
eth/rollup_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var rollupClient *RollupClient
|
||||
|
||||
func TestNewRollupClient(t *testing.T) {
|
||||
key, err := crypto.HexToECDSA(governancePrivateKey)
|
||||
require.Nil(t, err)
|
||||
ks := keystore.NewKeyStore(pathKs, keystore.StandardScryptN, keystore.StandardScryptP)
|
||||
account, err := ks.ImportECDSA(key, password)
|
||||
ks.Unlock(account, password)
|
||||
// Init eth client
|
||||
ethClient, err := ethclient.Dial(ehtClientDialURL)
|
||||
require.Nil(t, err)
|
||||
ethereumClient := NewEthereumClient(ethClient, &account, ks, nil)
|
||||
if integration != "" {
|
||||
rollupClient = NewRollupClient(ethereumClient, HERMEZROLLUP)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRollupConstants(t *testing.T) {
|
||||
if rollupClient != nil {
|
||||
_, err := rollupClient.RollupConstants()
|
||||
require.Nil(t, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user