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"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
ethCommon "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/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
@@ -14,8 +15,6 @@ import (
|
|||||||
|
|
||||||
// AuctionConstants are the constants of the Rollup Smart Contract
|
// AuctionConstants are the constants of the Rollup Smart Contract
|
||||||
type AuctionConstants struct {
|
type AuctionConstants struct {
|
||||||
// Blocks to wait before starting with the first slot
|
|
||||||
DelayGenesis uint16
|
|
||||||
// Blocks per slot
|
// Blocks per slot
|
||||||
BlocksPerSlot uint8
|
BlocksPerSlot uint8
|
||||||
// Minimum bid when no one has bid yet
|
// Minimum bid when no one has bid yet
|
||||||
@@ -23,6 +22,7 @@ type AuctionConstants struct {
|
|||||||
// First block where the first slot begins
|
// First block where the first slot begins
|
||||||
GenesisBlockNum int64
|
GenesisBlockNum int64
|
||||||
// Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee
|
// Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee
|
||||||
|
// Only for test
|
||||||
GovernanceAddress ethCommon.Address
|
GovernanceAddress ethCommon.Address
|
||||||
// ERC777 token with which the bids will be made
|
// ERC777 token with which the bids will be made
|
||||||
TokenHEZ ethCommon.Address
|
TokenHEZ ethCommon.Address
|
||||||
@@ -57,9 +57,9 @@ type Coordinator struct {
|
|||||||
// AuctionVariables are the variables of the Auction Smart Contract
|
// AuctionVariables are the variables of the Auction Smart Contract
|
||||||
type AuctionVariables struct {
|
type AuctionVariables struct {
|
||||||
// Boot Coordinator Address
|
// Boot Coordinator Address
|
||||||
DonationAddress ethCommon.Address
|
DonationAddress *ethCommon.Address
|
||||||
// Boot Coordinator Address
|
// Boot Coordinator Address
|
||||||
BootCoordinator ethCommon.Address
|
BootCoordinator *ethCommon.Address
|
||||||
// The minimum bid value in a series of 6 slots
|
// The minimum bid value in a series of 6 slots
|
||||||
DefaultSlotSetBid [6]*big.Int
|
DefaultSlotSetBid [6]*big.Int
|
||||||
// Distance (#slots) to the closest slot to which you can bid ( 2 Slots = 2 * 40 Blocks = 20 min )
|
// 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)
|
maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
|
||||||
|
|
||||||
// Forge
|
// 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
|
// AuctionForge(forger ethCommon.Address) (bool, error) // Only called from another smart contract
|
||||||
|
|
||||||
// Fees
|
// Fees
|
||||||
AuctionClaimHEZ() (*types.Transaction, error)
|
AuctionClaimHEZ(claimAddress common.Address) (*types.Transaction, error)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Smart Contract Status
|
// Smart Contract Status
|
||||||
@@ -384,11 +384,11 @@ func (c *AuctionClient) AuctionGetClosedAuctionSlots() (uint16, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AuctionSetOutbidding is the interface to call the smart contract function
|
// 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 tx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
1000000,
|
12500000,
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||||
if err != nil {
|
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
|
// AuctionGetOutbidding is the interface to call the smart contract function
|
||||||
func (c *AuctionClient) AuctionGetOutbidding() (uint16, error) {
|
func (c *AuctionClient) AuctionGetOutbidding() (uint16, error) {
|
||||||
// TODO: Update
|
var outbidding uint16
|
||||||
// var outbidding uint8
|
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||||
// if err := c.client.Call(func(ec *ethclient.Client) error {
|
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||||
// auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
if err != nil {
|
||||||
// if err != nil {
|
return err
|
||||||
// return err
|
}
|
||||||
// }
|
outbidding, err = auction.GetOutbidding(nil)
|
||||||
// outbidding, err = auction.GetOutbidding(nil)
|
return err
|
||||||
// return err
|
}); err != nil {
|
||||||
// }); err != nil {
|
return 0, err
|
||||||
// return 0, err
|
}
|
||||||
// }
|
return outbidding, nil
|
||||||
// return outbidding, nil
|
|
||||||
log.Error("TODO")
|
|
||||||
return 0, errTODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuctionSetAllocationRatio is the interface to call the smart contract function
|
// 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 tx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
if tx, err = c.client.CallAuth(
|
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
|
// AuctionGetAllocationRatio is the interface to call the smart contract function
|
||||||
func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint16, error) {
|
func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint16, error) {
|
||||||
// TODO: Update
|
var allocationRation [3]uint16
|
||||||
// var allocationRation [3]uint8
|
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||||
// if err := c.client.Call(func(ec *ethclient.Client) error {
|
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||||
// auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
if err != nil {
|
||||||
// if err != nil {
|
return err
|
||||||
// return err
|
}
|
||||||
// }
|
allocationRation, err = auction.GetAllocationRatio(nil)
|
||||||
// allocationRation, err = auction.GetAllocationRatio(nil)
|
return err
|
||||||
// return err
|
}); err != nil {
|
||||||
// }); err != nil {
|
return [3]uint16{}, err
|
||||||
// return [3]uint8{}, err
|
}
|
||||||
// }
|
return allocationRation, nil
|
||||||
// return allocationRation, nil
|
|
||||||
log.Error("TODO")
|
|
||||||
return [3]uint16{}, errTODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuctionSetDonationAddress is the interface to call the smart contract function
|
// AuctionSetDonationAddress is the interface to call the smart contract function
|
||||||
@@ -529,8 +523,8 @@ func (c *AuctionClient) AuctionGetBootCoordinator() (*ethCommon.Address, error)
|
|||||||
return &bootCoordinator, nil
|
return &bootCoordinator, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuctionChangeEpochMinBid is the interface to call the smart contract function
|
// AuctionChangeDefaultSlotSetBid is the interface to call the smart contract function
|
||||||
func (c *AuctionClient) AuctionChangeEpochMinBid(slotEpoch int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
|
func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
|
||||||
var tx *types.Transaction
|
var tx *types.Transaction
|
||||||
var err error
|
var err error
|
||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
@@ -540,15 +534,12 @@ func (c *AuctionClient) AuctionChangeEpochMinBid(slotEpoch int64, newInitialMinB
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
slotEpochToSend := big.NewInt(slotEpoch)
|
slotSetToSend := big.NewInt(slotSet)
|
||||||
fmt.Println(slotEpochToSend)
|
return auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid)
|
||||||
fmt.Println(newInitialMinBid)
|
|
||||||
return auction.ChangeEpochMinBid(auth, slotEpochToSend, newInitialMinBid)
|
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, fmt.Errorf("Failed changing epoch minBid: %w", err)
|
return nil, fmt.Errorf("Failed changing epoch minBid: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Println(tx)
|
|
||||||
return tx, nil
|
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
|
// AuctionGetDefaultSlotSetBid is the interface to call the smart contract function
|
||||||
func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) {
|
func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) {
|
||||||
// TODO: Update
|
var minBidSlotSet *big.Int
|
||||||
// var DefaultSlotSetBid *big.Int
|
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||||
// if err := c.client.Call(func(ec *ethclient.Client) error {
|
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||||
// auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
if err != nil {
|
||||||
// if err != nil {
|
return err
|
||||||
// return err
|
}
|
||||||
// }
|
minBidSlotSet, err = auction.GetDefaultSlotSetBid(nil, slotSet)
|
||||||
// defaultSlotSetBid, err = auction.GetDefaultSlotSetBid(nil, slotSet)
|
return err
|
||||||
// return err
|
}); err != nil {
|
||||||
// }); err != nil {
|
return big.NewInt(0), err
|
||||||
// return big.NewInt(0), err
|
}
|
||||||
// }
|
return minBidSlotSet, nil
|
||||||
// return defaultSlotSetBid, nil
|
|
||||||
|
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuctionTokensReceived is the interface to call the smart contract function
|
// 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
|
// AuctionCanForge is the interface to call the smart contract function
|
||||||
func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address) (bool, error) {
|
func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNumber *big.Int) (bool, error) {
|
||||||
log.Error("TODO")
|
var canForge bool
|
||||||
return false, errTODO
|
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
|
// 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
|
// AuctionClaimHEZ is the interface to call the smart contract function
|
||||||
func (c *AuctionClient) AuctionClaimHEZ() (*types.Transaction, error) {
|
func (c *AuctionClient) AuctionClaimHEZ(claimAddress common.Address) (*types.Transaction, error) {
|
||||||
log.Error("TODO")
|
var tx *types.Transaction
|
||||||
return nil, errTODO
|
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
|
// AuctionConstants returns the Constants of the Auction Smart Contract
|
||||||
func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
|
func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
|
||||||
log.Error("TODO")
|
auctionConstants := new(AuctionConstants)
|
||||||
return nil, errTODO
|
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
|
// AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -15,22 +16,24 @@ import (
|
|||||||
const slotDeadlineConst = uint8(20)
|
const slotDeadlineConst = uint8(20)
|
||||||
const openAuctionSlotsConst = uint16(4320)
|
const openAuctionSlotsConst = uint16(4320)
|
||||||
const closedAuctionSlotsConst = uint16(2)
|
const closedAuctionSlotsConst = uint16(2)
|
||||||
const outbiddingConst = uint8(10)
|
const outbiddingConst = uint16(1000)
|
||||||
const currentSlotConst = 0
|
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 auctionClient *AuctionClient
|
||||||
|
|
||||||
/*var donationAddressStr = os.Getenv("DONATION_ADDRESS")
|
/*var donationAddressStr = os.Getenv("DONATION_ADDRESS")
|
||||||
var bootCoordinatorStr = os.Getenv("BOOT_COORDINATOR_ADDRESS")
|
var bootCoordinatorStr = os.Getenv("BOOT_COORDINATOR_ADDRESS")
|
||||||
var integration = os.Getenv("INTEGRATION")
|
|
||||||
var ehtClientDialURL = os.Getenv("ETHCLIENT_DIAL_URL")
|
var ehtClientDialURL = os.Getenv("ETHCLIENT_DIAL_URL")
|
||||||
var auctionAddressStr = os.Getenv("AUCTION_ADDRESS")*/
|
var auctionAddressStr = os.Getenv("AUCTION_ADDRESS")*/
|
||||||
|
var integration = os.Getenv("INTEGRATION")
|
||||||
|
|
||||||
var donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
|
var donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
|
||||||
var bootCoordinatorStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
|
var bootCoordinatorStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
|
||||||
var integration = os.Getenv("INTEGRATION")
|
var DONATION = common.HexToAddress(donationAddressStr)
|
||||||
|
var BOOTCOORDINATOR = common.HexToAddress(bootCoordinatorStr)
|
||||||
|
|
||||||
var ehtClientDialURL = "http://localhost:8545"
|
var ehtClientDialURL = "http://localhost:8545"
|
||||||
var auctionAddressStr = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5"
|
var auctionAddressStr = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5"
|
||||||
var ownerAddressStr = "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
var ownerAddressStr = "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
@@ -39,6 +42,9 @@ var governancePrivateKey = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f
|
|||||||
var minBidStr = "10000000000000000000"
|
var minBidStr = "10000000000000000000"
|
||||||
var URL = "http://localhost:3000"
|
var URL = "http://localhost:3000"
|
||||||
var newURL = "http://localhost:3002"
|
var newURL = "http://localhost:3002"
|
||||||
|
var BLOCKSPERSLOT = uint8(40)
|
||||||
|
var TOKENHEZ = common.HexToAddress("0xf4e77E5Da47AC3125140c470c71cBca77B5c638c")
|
||||||
|
var HERMEZROLLUP = common.HexToAddress("0xc4905364b78a742ccce7B890A89514061E47068D")
|
||||||
|
|
||||||
var pathKs = "test/ks"
|
var pathKs = "test/ks"
|
||||||
var password = "pass"
|
var password = "pass"
|
||||||
@@ -54,7 +60,9 @@ func TestNewAction(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
ethereumClient := NewEthereumClient(ethClient, &account, ks, nil)
|
ethereumClient := NewEthereumClient(ethClient, &account, ks, nil)
|
||||||
auctionAddress := common.HexToAddress(auctionAddressStr)
|
auctionAddress := common.HexToAddress(auctionAddressStr)
|
||||||
auctionClient = NewAuctionClient(ethereumClient, auctionAddress)
|
if integration != "" {
|
||||||
|
auctionClient = NewAuctionClient(ethereumClient, auctionAddress)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAuctionGetCurrentSlotNumber(t *testing.T) {
|
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) {
|
func TestAuctionGetSlotDeadline(t *testing.T) {
|
||||||
if auctionClient != nil {
|
if auctionClient != nil {
|
||||||
slotDeadline, err := auctionClient.AuctionGetSlotDeadline()
|
slotDeadline, err := auctionClient.AuctionGetSlotDeadline()
|
||||||
@@ -135,7 +175,7 @@ func TestAuctionGetOutbidding(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAuctionSetOutbidding(t *testing.T) {
|
func TestAuctionSetOutbidding(t *testing.T) {
|
||||||
newOutbidding := uint8(15)
|
newOutbidding := uint16(0xb)
|
||||||
if auctionClient != nil {
|
if auctionClient != nil {
|
||||||
_, err := auctionClient.AuctionSetOutbidding(newOutbidding)
|
_, err := auctionClient.AuctionSetOutbidding(newOutbidding)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -155,7 +195,7 @@ func TestAuctionGetAllocationRatio(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAuctionSetAllocationRatio(t *testing.T) {
|
func TestAuctionSetAllocationRatio(t *testing.T) {
|
||||||
newAllocationRatio := [3]uint8{30, 30, 40}
|
newAllocationRatio := [3]uint16{3000, 3000, 4000}
|
||||||
if auctionClient != nil {
|
if auctionClient != nil {
|
||||||
_, err := auctionClient.AuctionSetAllocationRatio(newAllocationRatio)
|
_, err := auctionClient.AuctionSetAllocationRatio(newAllocationRatio)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -210,32 +250,33 @@ func TestAuctionSetBootCoordinator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAuctionGetMinBidEpoch(t *testing.T) {
|
func TestAuctionGetDefaultSlotSetBid(t *testing.T) {
|
||||||
epoch := uint8(3)
|
slotSet := uint8(3)
|
||||||
if auctionClient != nil {
|
if auctionClient != nil {
|
||||||
minBid, err := auctionClient.AuctionGetMinBidEpoch(epoch)
|
minBid, err := auctionClient.AuctionGetDefaultSlotSetBid(slotSet)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, minBid.String(), minBidStr)
|
assert.Equal(t, minBid.String(), minBidStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* func TestAuctionChangeEpochMinBid(t *testing.T) {
|
func TestAuctionChangeEpochMinBid(t *testing.T) {
|
||||||
slotEpoch := int64(3)
|
slotSet := int64(3)
|
||||||
epoch := uint8(3)
|
set := uint8(3)
|
||||||
newInitialMinBid := new(big.Int)
|
newInitialMinBid := new(big.Int)
|
||||||
newInitialMinBid.SetString("20000000000000000000", 10)
|
newInitialMinBid.SetString("20000000000000000000", 10)
|
||||||
if auctionClient != nil {
|
if auctionClient != nil {
|
||||||
_, err := auctionClient.AuctionChangeEpochMinBid(slotEpoch, newInitialMinBid)
|
_, err := auctionClient.AuctionChangeDefaultSlotSetBid(slotSet, newInitialMinBid)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
minBid, err := auctionClient.AuctionGetMinBidEpoch(epoch)
|
minBid, err := auctionClient.AuctionGetDefaultSlotSetBid(set)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, minBid, newInitialMinBid)
|
assert.Equal(t, minBid, newInitialMinBid)
|
||||||
newMinBid := new(big.Int)
|
newMinBid := new(big.Int)
|
||||||
newMinBid.SetString("10000000000000000000", 10)
|
newMinBid.SetString("10000000000000000000", 10)
|
||||||
_, err = auctionClient.AuctionChangeEpochMinBid(slotEpoch, newMinBid)
|
_, err = auctionClient.AuctionChangeDefaultSlotSetBid(slotSet, newMinBid)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
} */
|
}
|
||||||
|
|
||||||
func TestAuctionIsRegisteredCoordinator(t *testing.T) {
|
func TestAuctionIsRegisteredCoordinator(t *testing.T) {
|
||||||
forgerAddress := common.HexToAddress(governanceAddressStr)
|
forgerAddress := common.HexToAddress(governanceAddressStr)
|
||||||
if auctionClient != nil {
|
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)
|
forgerAddress := common.HexToAddress(governanceAddressStr)
|
||||||
if auctionClient != nil {
|
if auctionClient != nil {
|
||||||
_, err := auctionClient.AuctionUpdateCoordinatorInfo(forgerAddress, forgerAddress, newURL)
|
_, 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
|
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
|
> 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
192
eth/rollup.go
192
eth/rollup.go
@@ -5,7 +5,9 @@ import (
|
|||||||
|
|
||||||
ethCommon "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/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
"github.com/hermeznetwork/hermez-node/common"
|
"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/log"
|
||||||
"github.com/hermeznetwork/hermez-node/utils"
|
"github.com/hermeznetwork/hermez-node/utils"
|
||||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||||
@@ -24,28 +26,37 @@ type RollupConstants struct {
|
|||||||
// Maxim Deposit allowed
|
// Maxim Deposit allowed
|
||||||
MaxAmountDeposit *big.Int
|
MaxAmountDeposit *big.Int
|
||||||
MaxAmountL2 *big.Int
|
MaxAmountL2 *big.Int
|
||||||
MaxTokens uint32
|
MaxTokens *big.Int
|
||||||
// maximum L1 transactions allowed to be queued for a batch
|
// 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
|
// maximum L1 user transactions allowed to be queued for a batch
|
||||||
MaxL1UserTx int
|
MaxL1UserTx *big.Int
|
||||||
Rfield *big.Int
|
Rfield *big.Int
|
||||||
L1CoordinatorBytes int
|
L1CoordinatorBytes *big.Int
|
||||||
L1UserBytes int
|
L1UserBytes *big.Int
|
||||||
L2Bytes 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
|
// RollupVariables are the variables of the Rollup Smart Contract
|
||||||
type RollupVariables struct {
|
type RollupVariables struct {
|
||||||
MaxTxVerifiers []int
|
FeeAddToken *big.Int
|
||||||
TokenHEZ ethCommon.Address
|
ForgeL1Timeout int64
|
||||||
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
|
// QueueStruct is the queue of L1Txs for a batch
|
||||||
@@ -78,9 +89,11 @@ type RollupState struct {
|
|||||||
CurrentIdx int64
|
CurrentIdx int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupEventL1UserTx is an event of the Rollup Smart Contract
|
// RollupEventL1UserTxEvent is an event of the Rollup Smart Contract
|
||||||
type RollupEventL1UserTx struct {
|
type RollupEventL1UserTxEvent struct {
|
||||||
L1Tx common.L1Tx
|
L1Tx common.L1Tx
|
||||||
|
QueueIndex *big.Int
|
||||||
|
TransactionIndex *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupEventAddToken is an event of the Rollup Smart Contract
|
// 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
|
// RollupEventForgeBatch is an event of the Rollup Smart Contract
|
||||||
type RollupEventForgeBatch struct {
|
type RollupEventForgeBatch struct {
|
||||||
BatchNum int64
|
BatchNum *big.Int
|
||||||
EthTxHash ethCommon.Hash
|
EthTxHash ethCommon.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupEventUpdateForgeL1Timeout is an event of the Rollup Smart Contract
|
// RollupEventUpdateForgeL1L2BatchTimeout is an event of the Rollup Smart Contract
|
||||||
type RollupEventUpdateForgeL1Timeout struct {
|
type RollupEventUpdateForgeL1L2BatchTimeout struct {
|
||||||
ForgeL1Timeout int64
|
ForgeL1Timeout *big.Int
|
||||||
}
|
|
||||||
|
|
||||||
// RollupEventUpdateFeeL1UserTx is an event of the Rollup Smart Contract
|
|
||||||
type RollupEventUpdateFeeL1UserTx struct {
|
|
||||||
FeeL1UserTx *big.Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupEventUpdateFeeAddToken is an event of the Rollup Smart Contract
|
// RollupEventUpdateFeeAddToken is an event of the Rollup Smart Contract
|
||||||
@@ -110,40 +118,32 @@ type RollupEventUpdateFeeAddToken struct {
|
|||||||
FeeAddToken *big.Int
|
FeeAddToken *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupEventUpdateTokenHez is an event of the Rollup Smart Contract
|
// RollupEventWithdrawEvent is an event of the Rollup Smart Contract
|
||||||
type RollupEventUpdateTokenHez struct {
|
type RollupEventWithdrawEvent struct {
|
||||||
TokenHEZ ethCommon.Address
|
Idx *big.Int
|
||||||
}
|
NumExitRoot *big.Int
|
||||||
|
InstantWithdraw bool
|
||||||
// RollupEventWithdraw is an event of the Rollup Smart Contract
|
|
||||||
type RollupEventWithdraw struct {
|
|
||||||
Idx int64
|
|
||||||
NumExitRoot int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupEvents is the list of events in a block of the Rollup Smart Contract
|
// RollupEvents is the list of events in a block of the Rollup Smart Contract
|
||||||
type RollupEvents struct { //nolint:structcheck
|
type RollupEvents struct { //nolint:structcheck
|
||||||
L1UserTx []RollupEventL1UserTx
|
L1UserTxEvent []RollupEventL1UserTxEvent
|
||||||
AddToken []RollupEventAddToken
|
AddToken []RollupEventAddToken
|
||||||
ForgeBatch []RollupEventForgeBatch
|
ForgeBatch []RollupEventForgeBatch
|
||||||
UpdateForgeL1Timeout []RollupEventUpdateForgeL1Timeout
|
UpdateForgeL1L2BatchTimeout []RollupEventUpdateForgeL1L2BatchTimeout
|
||||||
UpdateFeeL1UserTx []RollupEventUpdateFeeL1UserTx
|
UpdateFeeAddToken []RollupEventUpdateFeeAddToken
|
||||||
UpdateFeeAddToken []RollupEventUpdateFeeAddToken
|
WithdrawEvent []RollupEventWithdrawEvent
|
||||||
UpdateTokenHez []RollupEventUpdateTokenHez
|
|
||||||
Withdraw []RollupEventWithdraw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRollupEvents creates an empty RollupEvents with the slices initialized.
|
// NewRollupEvents creates an empty RollupEvents with the slices initialized.
|
||||||
func NewRollupEvents() RollupEvents {
|
func NewRollupEvents() RollupEvents {
|
||||||
return RollupEvents{
|
return RollupEvents{
|
||||||
L1UserTx: make([]RollupEventL1UserTx, 0),
|
L1UserTxEvent: make([]RollupEventL1UserTxEvent, 0),
|
||||||
AddToken: make([]RollupEventAddToken, 0),
|
AddToken: make([]RollupEventAddToken, 0),
|
||||||
ForgeBatch: make([]RollupEventForgeBatch, 0),
|
ForgeBatch: make([]RollupEventForgeBatch, 0),
|
||||||
UpdateForgeL1Timeout: make([]RollupEventUpdateForgeL1Timeout, 0),
|
UpdateForgeL1L2BatchTimeout: make([]RollupEventUpdateForgeL1L2BatchTimeout, 0),
|
||||||
UpdateFeeL1UserTx: make([]RollupEventUpdateFeeL1UserTx, 0),
|
UpdateFeeAddToken: make([]RollupEventUpdateFeeAddToken, 0),
|
||||||
UpdateFeeAddToken: make([]RollupEventUpdateFeeAddToken, 0),
|
WithdrawEvent: make([]RollupEventWithdrawEvent, 0),
|
||||||
UpdateTokenHez: make([]RollupEventUpdateTokenHez, 0),
|
|
||||||
Withdraw: make([]RollupEventWithdraw, 0),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,8 +175,7 @@ type RollupInterface interface {
|
|||||||
|
|
||||||
RollupForgeBatch(*RollupForgeBatchArgs) (*types.Transaction, error)
|
RollupForgeBatch(*RollupForgeBatchArgs) (*types.Transaction, error)
|
||||||
RollupAddToken(tokenAddress ethCommon.Address) (*types.Transaction, error)
|
RollupAddToken(tokenAddress ethCommon.Address) (*types.Transaction, error)
|
||||||
// RollupWithdrawSNARK() (*types.Transaction, error) // TODO (Not defined in Hermez.sol)
|
RollupWithdraw(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey,
|
||||||
RollupWithdrawMerkleProof(tokenID int64, balance *big.Int, babyPubKey *babyjub.PublicKey,
|
|
||||||
numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (*types.Transaction, error)
|
numExitRoot int64, siblings []*big.Int, idx int64, instantWithdraw bool) (*types.Transaction, error)
|
||||||
RollupForceExit(fromIdx int64, amountF utils.Float16, tokenID int64) (*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)
|
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,
|
RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey, loadAmountF utils.Float16,
|
||||||
tokenID int64) (*types.Transaction, error)
|
tokenID int64) (*types.Transaction, error)
|
||||||
|
|
||||||
RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error)
|
RollupGetCurrentTokens() (*big.Int, error)
|
||||||
RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error)
|
// RollupGetTokenAddress(tokenID int64) (*ethCommon.Address, error)
|
||||||
RollupGetQueue(queue int64) ([]byte, error)
|
// RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error)
|
||||||
|
// RollupGetQueue(queue int64) ([]byte, error)
|
||||||
|
|
||||||
// Governance Public Functions
|
// Governance Public Functions
|
||||||
RollupUpdateForgeL1Timeout(newForgeL1Timeout int64) (*types.Transaction, error)
|
RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (*types.Transaction, error)
|
||||||
RollupUpdateFeeL1UserTx(newFeeL1UserTx *big.Int) (*types.Transaction, error)
|
|
||||||
RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*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
|
// Smart Contract Status
|
||||||
@@ -245,8 +242,8 @@ func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address) (*types.Tr
|
|||||||
// return nil, errTODO
|
// return nil, errTODO
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// RollupWithdrawMerkleProof is the interface to call the smart contract function
|
// RollupWithdraw 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) {
|
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")
|
log.Error("TODO")
|
||||||
return nil, errTODO
|
return nil, errTODO
|
||||||
}
|
}
|
||||||
@@ -294,31 +291,28 @@ func (c *RollupClient) RollupCreateAccountDeposit(babyPubKey babyjub.PublicKey,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RollupGetTokenAddress is the interface to call the smart contract function
|
// 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")
|
log.Error("TODO")
|
||||||
return nil, errTODO
|
return nil, errTODO
|
||||||
}
|
}
|
||||||
|
|
||||||
// RollupGetL1TxFromQueue is the interface to call the smart contract function
|
// RollupGetL1TxFromQueue is the interface to call the smart contract function
|
||||||
func (c *RollupClient) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
/* func (c *RollupClient) RollupGetL1TxFromQueue(queue int64, position int64) ([]byte, error) {
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
return nil, errTODO
|
||||||
}
|
} */
|
||||||
|
|
||||||
// RollupGetQueue is the interface to call the smart contract function
|
// RollupGetQueue is the interface to call the smart contract function
|
||||||
func (c *RollupClient) RollupGetQueue(queue int64) ([]byte, error) {
|
/* func (c *RollupClient) RollupGetQueue(queue int64) ([]byte, error) {
|
||||||
log.Error("TODO")
|
|
||||||
return nil, errTODO
|
return nil, errTODO
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// RollupUpdateForgeL1Timeout is the interface to call the smart contract function
|
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
||||||
func (c *RollupClient) RollupUpdateForgeL1Timeout(newForgeL1Timeout int64) (*types.Transaction, error) {
|
func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(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) {
|
|
||||||
log.Error("TODO")
|
log.Error("TODO")
|
||||||
return nil, errTODO
|
return nil, errTODO
|
||||||
}
|
}
|
||||||
@@ -329,21 +323,37 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.
|
|||||||
return nil, errTODO
|
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
|
// RollupConstants returns the Constants of the Rollup Smart Contract
|
||||||
func (c *RollupClient) RollupConstants() (*RollupConstants, error) {
|
func (c *RollupClient) RollupConstants() (*RollupConstants, error) {
|
||||||
log.Error("TODO")
|
rollupConstants := new(RollupConstants)
|
||||||
return nil, errTODO
|
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
|
// 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