Browse Source

Update ethclient auction & add wdelayer

feature/sql-semaphore1
laisolizq 4 years ago
parent
commit
729f37c912
6 changed files with 2104 additions and 33 deletions
  1. +120
    -10
      eth/auction.go
  2. +64
    -14
      eth/auction_test.go
  3. +1696
    -0
      eth/contracts/erc777/ERC777.go
  4. +214
    -0
      eth/wdelayer.go
  5. +2
    -2
      test/ethclient.go
  6. +8
    -7
      test/ethclient_test.go

+ 120
- 10
eth/auction.go

@ -1,6 +1,7 @@
package eth package eth
import ( import (
"encoding/binary"
"fmt" "fmt"
"math/big" "math/big"
@ -9,7 +10,9 @@ import (
"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"
HermezAuctionProtocol "github.com/hermeznetwork/hermez-node/eth/contracts/auction" HermezAuctionProtocol "github.com/hermeznetwork/hermez-node/eth/contracts/auction"
ERC777 "github.com/hermeznetwork/hermez-node/eth/contracts/erc777"
"github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/log"
"golang.org/x/crypto/sha3"
) )
// AuctionConstants are the constants of the Rollup Smart Contract // AuctionConstants are the constants of the Rollup Smart Contract
@ -240,9 +243,8 @@ type AuctionInterface interface {
// Bidding // Bidding
// AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int, // AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int,
// userData, operatorData []byte) error // Only called from another smart contract // userData, operatorData []byte) error // Only called from another smart contract
AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error)
AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool,
maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error)
AuctionBid(slot int64, bidAmount *big.Int, forger, tokenAddress ethCommon.Address) (*types.Transaction, error)
AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger, tokenAddress ethCommon.Address) (*types.Transaction, error)
// Forge // Forge
AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error) AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error)
@ -539,11 +541,27 @@ func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitial
return auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid) return auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid)
}, },
); err != nil { ); err != nil {
return nil, fmt.Errorf("Failed changing epoch minBid: %w", err)
return nil, fmt.Errorf("Failed changing slotSet Bid: %w", err)
} }
return tx, nil return tx, nil
} }
// AuctionGetClaimableHEZ is the interface to call the smart contract function
func (c *AuctionClient) AuctionGetClaimableHEZ(claimAddress ethCommon.Address) (*big.Int, error) {
var claimableHEZ *big.Int
if err := c.client.Call(func(ec *ethclient.Client) error {
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
if err != nil {
return err
}
claimableHEZ, err = auction.GetClaimableHEZ(nil, claimAddress)
return err
}); err != nil {
return nil, err
}
return claimableHEZ, nil
}
// AuctionRegisterCoordinator is the interface to call the smart contract function // AuctionRegisterCoordinator is the interface to call the smart contract function
func (c *AuctionClient) AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error) { func (c *AuctionClient) AuctionRegisterCoordinator(forgerAddress ethCommon.Address, URL string) (*types.Transaction, error) {
var tx *types.Transaction var tx *types.Transaction
@ -632,6 +650,23 @@ func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) {
return minBid, nil return minBid, nil
} }
// AuctionGetSlotSet is the interface to call the smart contract function
func (c *AuctionClient) AuctionGetSlotSet(slot int64) (*big.Int, error) {
var slotSet *big.Int
if err := c.client.Call(func(ec *ethclient.Client) error {
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
if err != nil {
return err
}
slotToSend := big.NewInt(slot)
slotSet, err = auction.GetSlotSet(nil, slotToSend)
return err
}); err != nil {
return big.NewInt(0), err
}
return slotSet, nil
}
// 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) {
var minBidSlotSet *big.Int var minBidSlotSet *big.Int
@ -654,15 +689,90 @@ func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, er
// } // }
// AuctionBid is the interface to call the smart contract function // AuctionBid is the interface to call the smart contract function
func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
log.Error("TODO")
return nil, errTODO
func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int, forger, tokenAddress ethCommon.Address) (*types.Transaction, error) {
var tx *types.Transaction
var err error
if tx, err = c.client.CallAuth(
c.gasLimit,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
tokens, err := ERC777.NewERC777(tokenAddress, ec)
if err != nil {
return nil, err
}
bidFnSignature := []byte("bid(uint128,uint128,address)")
hash := sha3.NewLegacyKeccak256()
_, err = hash.Write(bidFnSignature)
if err != nil {
return nil, err
}
methodID := hash.Sum(nil)[:4]
slotBytes := make([]byte, 8)
binary.BigEndian.PutUint64(slotBytes, uint64(slot))
paddedSlot := ethCommon.LeftPadBytes(slotBytes, 32)
paddedAmount := ethCommon.LeftPadBytes(bidAmount.Bytes(), 32)
paddedAddress := ethCommon.LeftPadBytes(forger.Bytes(), 32)
var userData []byte
userData = append(userData, methodID...)
userData = append(userData, paddedSlot...)
userData = append(userData, paddedAmount...)
userData = append(userData, paddedAddress...)
return tokens.Send(auth, c.address, bidAmount, userData)
},
); err != nil {
return nil, fmt.Errorf("Failed bid: %w", err)
}
return tx, nil
} }
// AuctionMultiBid is the interface to call the smart contract function // AuctionMultiBid is the interface to call the smart contract function
func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (*types.Transaction, error) {
log.Error("TODO")
return nil, errTODO
func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger, tokenAddress ethCommon.Address) (*types.Transaction, error) {
var tx *types.Transaction
var err error
if tx, err = c.client.CallAuth(
c.gasLimit,
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
tokens, err := ERC777.NewERC777(tokenAddress, ec)
if err != nil {
return nil, err
}
multiBidFnSignature := []byte("multiBid(uint128,uint128,bool[6],uint128,uint128,address)")
hash := sha3.NewLegacyKeccak256()
_, err = hash.Write(multiBidFnSignature)
if err != nil {
return nil, err
}
methodID := hash.Sum(nil)[:4]
startingSlotBytes := make([]byte, 8)
binary.BigEndian.PutUint64(startingSlotBytes, uint64(startingSlot))
paddedStartingSlot := ethCommon.LeftPadBytes(startingSlotBytes, 32)
endingSlotBytes := make([]byte, 8)
binary.BigEndian.PutUint64(endingSlotBytes, uint64(endingSlot))
paddedEndingSlot := ethCommon.LeftPadBytes(endingSlotBytes, 32)
paddedMinBid := ethCommon.LeftPadBytes(closedMinBid.Bytes(), 32)
paddedMaxBid := ethCommon.LeftPadBytes(maxBid.Bytes(), 32)
paddedAddress := ethCommon.LeftPadBytes(forger.Bytes(), 32)
var userData []byte
userData = append(userData, methodID...)
userData = append(userData, paddedStartingSlot...)
userData = append(userData, paddedEndingSlot...)
for i := 0; i < len(slotSet); i++ {
if slotSet[i] {
paddedSlotSet := ethCommon.LeftPadBytes([]byte{1}, 32)
userData = append(userData, paddedSlotSet...)
} else {
paddedSlotSet := ethCommon.LeftPadBytes([]byte{0}, 32)
userData = append(userData, paddedSlotSet...)
}
}
userData = append(userData, paddedMaxBid...)
userData = append(userData, paddedMinBid...)
userData = append(userData, paddedAddress...)
return tokens.Send(auth, c.address, budget, userData)
},
); err != nil {
return nil, fmt.Errorf("Failed multibid: %w", err)
}
return tx, nil
} }
// AuctionCanForge is the interface to call the smart contract function // AuctionCanForge is the interface to call the smart contract function

+ 64
- 14
eth/auction_test.go

@ -26,28 +26,31 @@ 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 ehtClientDialURL = os.Getenv("ETHCLIENT_DIAL_URL")
var auctionAddressStr = os.Getenv("AUCTION_ADDRESS")*/
var auctionAddressStr = os.Getenv("AUCTION_ADDRESS")
var tokenHezStr = os.Getenv("TOKEN_ADDRESS")
var hermezStr = os.Getenv("HERMEZ_ADDRESS")
var governanceAddressStr = os.Getenv("GOV_ADDRESS")
var governancePrivateKey = os.Getenv("GOV_PK")
var ehtClientDialURL = os.Getenv("ETHCLIENT_DIAL_URL")*/
var integration = os.Getenv("INTEGRATION") var integration = os.Getenv("INTEGRATION")
var donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd" var donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
var bootCoordinatorStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6" var bootCoordinatorStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
var DONATION = common.HexToAddress(donationAddressStr)
var BOOTCOORDINATOR = common.HexToAddress(bootCoordinatorStr)
var ehtClientDialURL = "http://localhost:8545"
var auctionAddressStr = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5" var auctionAddressStr = "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5"
// var ownerAddressStr = "0xc783df8a850f42e7F7e57013759C285caa701eB6"
var tokenHezStr = "0xf4e77E5Da47AC3125140c470c71cBca77B5c638c" //nolint:gosec
var hermezStr = "0xc4905364b78a742ccce7B890A89514061E47068D"
var governanceAddressStr = "0xead9c93b79ae7c1591b1fb5323bd777e86e150d4" var governanceAddressStr = "0xead9c93b79ae7c1591b1fb5323bd777e86e150d4"
var governancePrivateKey = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb" var governancePrivateKey = "d49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb"
var ehtClientDialURL = "http://localhost:8545"
var DONATION = common.HexToAddress(donationAddressStr)
var BOOTCOORDINATOR = common.HexToAddress(bootCoordinatorStr)
var TOKENHEZ = common.HexToAddress(tokenHezStr)
var HERMEZROLLUP = common.HexToAddress(hermezStr)
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 BLOCKSPERSLOT = uint8(40)
var TOKENHEZ = common.HexToAddress("0xf4e77E5Da47AC3125140c470c71cBca77B5c638c")
var HERMEZROLLUP = common.HexToAddress("0xc4905364b78a742ccce7B890A89514061E47068D")
var password = "pass" var password = "pass"
func TestNewAction(t *testing.T) { func TestNewAction(t *testing.T) {
@ -101,10 +104,10 @@ func TestAuctionVariables(t *testing.T) {
auctionVariables, err := auctionClient.AuctionVariables() auctionVariables, err := auctionClient.AuctionVariables()
require.Nil(t, err) require.Nil(t, err)
assert.Equal(t, auctionVariables.AllocationRatio, allocationRatioConst) assert.Equal(t, auctionVariables.AllocationRatio, allocationRatioConst)
assert.Equal(t, auctionVariables.BootCoordinator, &BOOTCOORDINATOR)
assert.Equal(t, auctionVariables.BootCoordinator, BOOTCOORDINATOR)
assert.Equal(t, auctionVariables.ClosedAuctionSlots, closedAuctionSlotsConst) assert.Equal(t, auctionVariables.ClosedAuctionSlots, closedAuctionSlotsConst)
assert.Equal(t, auctionVariables.DefaultSlotSetBid, defaultSlotSetBid) assert.Equal(t, auctionVariables.DefaultSlotSetBid, defaultSlotSetBid)
assert.Equal(t, auctionVariables.DonationAddress, &DONATION)
assert.Equal(t, auctionVariables.DonationAddress, DONATION)
assert.Equal(t, auctionVariables.OpenAuctionSlots, openAuctionSlotsConst) assert.Equal(t, auctionVariables.OpenAuctionSlots, openAuctionSlotsConst)
assert.Equal(t, auctionVariables.Outbidding, outbiddingConst) assert.Equal(t, auctionVariables.Outbidding, outbiddingConst)
assert.Equal(t, auctionVariables.SlotDeadline, slotDeadlineConst) assert.Equal(t, auctionVariables.SlotDeadline, slotDeadlineConst)
@ -262,6 +265,15 @@ func TestAuctionSetBootCoordinator(t *testing.T) {
} }
} }
func TestAuctionGetSlotSet(t *testing.T) {
slot := int64(10)
if auctionClient != nil {
slotSet, err := auctionClient.AuctionGetSlotSet(slot)
require.Nil(t, err)
assert.Equal(t, slotSet, big.NewInt(4))
}
}
func TestAuctionGetDefaultSlotSetBid(t *testing.T) { func TestAuctionGetDefaultSlotSetBid(t *testing.T) {
slotSet := uint8(3) slotSet := uint8(3)
if auctionClient != nil { if auctionClient != nil {
@ -271,7 +283,7 @@ func TestAuctionGetDefaultSlotSetBid(t *testing.T) {
} }
} }
func TestAuctionChangeEpochMinBid(t *testing.T) {
func TestAuctionChangeDefaultSlotSetBid(t *testing.T) {
slotSet := int64(3) slotSet := int64(3)
set := uint8(3) set := uint8(3)
newInitialMinBid := new(big.Int) newInitialMinBid := new(big.Int)
@ -289,6 +301,15 @@ func TestAuctionChangeEpochMinBid(t *testing.T) {
} }
} }
func TestAuctionGetClaimableHEZ(t *testing.T) {
forgerAddress := common.HexToAddress(governanceAddressStr)
if auctionClient != nil {
claimableHEZ, err := auctionClient.AuctionGetClaimableHEZ(forgerAddress)
require.Nil(t, err)
assert.Equal(t, claimableHEZ.Int64(), int64(0))
}
}
func TestAuctionIsRegisteredCoordinator(t *testing.T) { func TestAuctionIsRegisteredCoordinator(t *testing.T) {
forgerAddress := common.HexToAddress(governanceAddressStr) forgerAddress := common.HexToAddress(governanceAddressStr)
if auctionClient != nil { if auctionClient != nil {
@ -322,3 +343,32 @@ func TestAuctionUpdateCoordinatorInfo(t *testing.T) {
require.Nil(t, err) require.Nil(t, err)
} }
} }
func TestAuctionBid(t *testing.T) {
if auctionClient != nil {
currentSlot, err := auctionClient.AuctionGetCurrentSlotNumber()
require.Nil(t, err)
bidAmount := new(big.Int)
bidAmount.SetString("11000000000000000000", 10)
forgerAddress := common.HexToAddress(governanceAddressStr)
_, err = auctionClient.AuctionBid(currentSlot+4, bidAmount, forgerAddress, TOKENHEZ)
require.Nil(t, err)
}
}
func TestAuctionMultiBid(t *testing.T) {
if auctionClient != nil {
currentSlot, err := auctionClient.AuctionGetCurrentSlotNumber()
require.Nil(t, err)
slotSet := [6]bool{false, true, false, true, false, true}
maxBid := new(big.Int)
maxBid.SetString("11000000000000000000", 10)
minBid := new(big.Int)
minBid.SetString("11000000000000000000", 10)
budget := new(big.Int)
budget.SetString("110000000000000000000", 10)
forgerAddress := common.HexToAddress(governanceAddressStr)
_, err = auctionClient.AuctionMultiBid(currentSlot+5, currentSlot+10, slotSet, maxBid, minBid, budget, forgerAddress, TOKENHEZ)
require.Nil(t, err)
}
}

+ 1696
- 0
eth/contracts/erc777/ERC777.go
File diff suppressed because it is too large
View File


+ 214
- 0
eth/wdelayer.go

@ -0,0 +1,214 @@
package eth
import (
"math/big"
ethCommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// WDelayerConstants are the constants of the Rollup Smart Contract
type WDelayerConstants struct {
// Max Withdrawal Delay
MaxWithdrawalDelay uint64
// Max Emergency mode time
MaxEmergencyModeTime uint64
// HermezRollup smartcontract address
HermezRollup ethCommon.Address
}
// DepositState is the state of Deposit
type DepositState struct {
Amount *big.Int
DepositTimestamp uint64
}
// WDelayerEventDeposit is an event of the WithdrawalDelayer Smart Contract
type WDelayerEventDeposit struct {
Owner ethCommon.Address
Token ethCommon.Address
Amount *big.Int
DepositTimestamp uint64
}
// WDelayerEventWithdraw is an event of the WithdrawalDelayer Smart Contract
type WDelayerEventWithdraw struct {
Owner ethCommon.Address
Token ethCommon.Address
Amount *big.Int
}
// WDelayerEventEmergencyModeEnabled an event of the WithdrawalDelayer Smart Contract
type WDelayerEventEmergencyModeEnabled struct {
}
// WDelayerEventNewWithdrawalDelay an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewWithdrawalDelay struct {
WithdrawalDelay uint64
}
// WDelayerEventEscapeHatchWithdrawal an event of the WithdrawalDelayer Smart Contract
type WDelayerEventEscapeHatchWithdrawal struct {
Who ethCommon.Address
To ethCommon.Address
Token ethCommon.Address
}
// WDelayerEventNewHermezKeeperAddress an event of the WithdrawalDelayer Smart Contract
type WDelayerEventNewHermezKeeperAddress struct {
NewHermezKeeperAddress 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
}
// WDelayerEvents is the lis of events in a block of the WithdrawalDelayer Smart Contract
type WDelayerEvents struct { //nolint:structcheck
Deposit []WDelayerEventDeposit
Withdraw []WDelayerEventWithdraw
EmergencyModeEnabled []WDelayerEventEmergencyModeEnabled
NewWithdrawalDelay []WDelayerEventNewWithdrawalDelay
EscapeHatchWithdrawal []WDelayerEventEscapeHatchWithdrawal
NewHermezKeeperAddress []WDelayerEventNewHermezKeeperAddress
NewWhiteHackGroupAddress []WDelayerEventNewWhiteHackGroupAddress
NewHermezGovernanceDAOAddress []WDelayerEventNewHermezGovernanceDAOAddress
}
// 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),
}
}
// WDelayerInterface is the inteface to WithdrawalDelayer Smart Contract
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)
WDelayerIsEmergencyMode() (bool, error)
WDelayerGetWithdrawalDelay() (*big.Int, error)
WDelayerGetEmergencyModeStartingTime() (*big.Int, error)
WDelayerEnableEmergencyMode() (*types.Transaction, error)
WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (*types.Transaction, error)
WDelayerDepositInfo(owner, token ethCommon.Address) (*big.Int, uint64)
WDelayerDeposit(onwer, token ethCommon.Address, amount *big.Int) (*types.Transaction, error)
WDelayerWithdrawal(owner, token ethCommon.Address) (*types.Transaction, error)
WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address) (*types.Transaction, error)
}
//
// Implementation
//
// WDelayerClient is the implementation of the interface to the WithdrawDelayer Smart Contract in ethereum.
type WDelayerClient struct {
client *EthereumClient
address ethCommon.Address
gasLimit uint64
}
// NewWDelayerClient creates a new WDelayerClient
func NewWDelayerClient(client *EthereumClient, address ethCommon.Address) *WDelayerClient {
return &WDelayerClient{
client: client,
address: address,
gasLimit: 1000000, //nolint:gomnd
}
}
// WDelayerGetHermezGovernanceDAOAddress is the interface to call the smart contract function
func (c *WDelayerClient) WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, error) {
return nil, errTODO
}
// WDelayerSetHermezGovernanceDAOAddress is the interface to call the smart contract function
func WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
return nil, errTODO
}
// WDelayerGetHermezKeeperAddress is the interface to call the smart contract function
func WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error) {
return nil, errTODO
}
// WDelayerSetHermezKeeperAddress is the interface to call the smart contract function
func WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
return nil, errTODO
}
// WDelayerGetWhiteHackGroupAddress is the interface to call the smart contract function
func WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error) {
return nil, errTODO
}
// WDelayerSetWhiteHackGroupAddress is the interface to call the smart contract function
func WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
return nil, errTODO
}
// WDelayerIsEmergencyMode is the interface to call the smart contract function
func WDelayerIsEmergencyMode() (bool, error) {
return false, errTODO
}
// WDelayerGetWithdrawalDelay is the interface to call the smart contract function
func WDelayerGetWithdrawalDelay() (*big.Int, error) {
return nil, errTODO
}
// WDelayerGetEmergencyModeStartingTime is the interface to call the smart contract function
func WDelayerGetEmergencyModeStartingTime() (*big.Int, error) {
return nil, errTODO
}
// WDelayerEnableEmergencyMode is the interface to call the smart contract function
func WDelayerEnableEmergencyMode() (*types.Transaction, error) {
return nil, errTODO
}
// WDelayerChangeWithdrawalDelay is the interface to call the smart contract function
func WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (*types.Transaction, error) {
return nil, errTODO
}
// WDelayerDepositInfo is the interface to call the smart contract function
func WDelayerDepositInfo(owner, token ethCommon.Address) (*big.Int, uint64, error) {
return big.NewInt(0), 0, errTODO
}
// WDelayerDeposit is the interface to call the smart contract function
func WDelayerDeposit(onwer, token ethCommon.Address, amount *big.Int) (*types.Transaction, error) {
return nil, errTODO
}
// WDelayerWithdrawal is the interface to call the smart contract function
func WDelayerWithdrawal(owner, token ethCommon.Address) (*types.Transaction, error) {
return nil, errTODO
}
// WDelayerEscapeHatchWithdrawal is the interface to call the smart contract function
func WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address) (*types.Transaction, error) {
return nil, errTODO
}

+ 2
- 2
test/ethclient.go

@ -1068,7 +1068,7 @@ func (c *Client) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) {
// } // }
// AuctionBid is the interface to call the smart contract function // AuctionBid is the interface to call the smart contract function
func (c *Client) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Address) (tx *types.Transaction, err error) {
func (c *Client) AuctionBid(slot int64, bidAmount *big.Int, forger, tokenAddress ethCommon.Address) (tx *types.Transaction, err error) {
c.rw.Lock() c.rw.Lock()
defer c.rw.Unlock() defer c.rw.Unlock()
cpy := c.nextBlock().copy() cpy := c.nextBlock().copy()
@ -1117,7 +1117,7 @@ func (c *Client) AuctionBid(slot int64, bidAmount *big.Int, forger ethCommon.Add
} }
// AuctionMultiBid is the interface to call the smart contract function // AuctionMultiBid is the interface to call the smart contract function
func (c *Client) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger ethCommon.Address) (tx *types.Transaction, err error) {
func (c *Client) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int, forger, tokenAddress ethCommon.Address) (tx *types.Transaction, err error) {
c.rw.Lock() c.rw.Lock()
defer c.rw.Unlock() defer c.rw.Unlock()
cpy := c.nextBlock().copy() cpy := c.nextBlock().copy()

+ 8
- 7
test/ethclient_test.go

@ -68,6 +68,7 @@ func TestClientAuction(t *testing.T) {
addrWithdraw := ethCommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f") addrWithdraw := ethCommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f")
addrForge := ethCommon.HexToAddress("0xCfAA413eEb796f328620a3630Ae39124cabcEa92") addrForge := ethCommon.HexToAddress("0xCfAA413eEb796f328620a3630Ae39124cabcEa92")
addrForge2 := ethCommon.HexToAddress("0x1fCb4ac309428feCc61B1C8cA5823C15A5e1a800") addrForge2 := ethCommon.HexToAddress("0x1fCb4ac309428feCc61B1C8cA5823C15A5e1a800")
token1Addr := ethCommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f")
var timer timer var timer timer
clientSetup := NewClientSetupExample() clientSetup := NewClientSetupExample()
@ -80,33 +81,33 @@ func TestClientAuction(t *testing.T) {
// Check several cases in which bid doesn't succed, and also do 2 successful bids. // Check several cases in which bid doesn't succed, and also do 2 successful bids.
_, err := c.AuctionBid(0, big.NewInt(1), addrForge)
_, err := c.AuctionBid(0, big.NewInt(1), addrForge, token1Addr)
assert.Equal(t, errBidClosed, err) assert.Equal(t, errBidClosed, err)
_, err = c.AuctionBid(4322, big.NewInt(1), addrForge)
_, err = c.AuctionBid(4322, big.NewInt(1), addrForge, token1Addr)
assert.Equal(t, errBidNotOpen, err) assert.Equal(t, errBidNotOpen, err)
// 101 % 6 = 5; defaultSlotSetBid[5] = 1500; 1500 + 10% = 1650 // 101 % 6 = 5; defaultSlotSetBid[5] = 1500; 1500 + 10% = 1650
_, err = c.AuctionBid(101, big.NewInt(1650), addrForge)
_, err = c.AuctionBid(101, big.NewInt(1650), addrForge, token1Addr)
assert.Equal(t, errCoordNotReg, err) assert.Equal(t, errCoordNotReg, err)
_, err = c.AuctionRegisterCoordinator(addrForge, "https://foo.bar") _, err = c.AuctionRegisterCoordinator(addrForge, "https://foo.bar")
assert.Nil(t, err) assert.Nil(t, err)
_, err = c.AuctionBid(3, big.NewInt(1), addrForge)
_, err = c.AuctionBid(3, big.NewInt(1), addrForge, token1Addr)
assert.Equal(t, errBidBelowMin, err) assert.Equal(t, errBidBelowMin, err)
_, err = c.AuctionBid(3, big.NewInt(1650), addrForge)
_, err = c.AuctionBid(3, big.NewInt(1650), addrForge, token1Addr)
assert.Nil(t, err) assert.Nil(t, err)
_, err = c.AuctionRegisterCoordinator(addrForge2, "https://foo2.bar") _, err = c.AuctionRegisterCoordinator(addrForge2, "https://foo2.bar")
assert.Nil(t, err) assert.Nil(t, err)
_, err = c.AuctionBid(3, big.NewInt(16), addrForge2)
_, err = c.AuctionBid(3, big.NewInt(16), addrForge2, token1Addr)
assert.Equal(t, errBidBelowMin, err) assert.Equal(t, errBidBelowMin, err)
// 1650 + 10% = 1815 // 1650 + 10% = 1815
_, err = c.AuctionBid(3, big.NewInt(1815), addrForge2)
_, err = c.AuctionBid(3, big.NewInt(1815), addrForge2, token1Addr)
assert.Nil(t, err) assert.Nil(t, err)
c.CtlMineBlock() c.CtlMineBlock()

Loading…
Cancel
Save