mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Update importers of eth, review eth/README.md
This commit is contained in:
@@ -23,6 +23,7 @@ SyncLoopInterval = "1s"
|
|||||||
Rollup = "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
|
Rollup = "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
|
||||||
Auction = "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
|
Auction = "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
|
||||||
TokenHEZ = "0xf784709d2317D872237C4bC22f867d1BAe2913AB"
|
TokenHEZ = "0xf784709d2317D872237C4bC22f867d1BAe2913AB"
|
||||||
|
TokenHEZName = "Hermez Network Token"
|
||||||
|
|
||||||
[EthClient]
|
[EthClient]
|
||||||
CallGasLimit = 300000
|
CallGasLimit = 300000
|
||||||
|
|||||||
@@ -68,9 +68,10 @@ type Node struct {
|
|||||||
SyncLoopInterval Duration `validate:"required"`
|
SyncLoopInterval Duration `validate:"required"`
|
||||||
} `validate:"required"`
|
} `validate:"required"`
|
||||||
SmartContracts struct {
|
SmartContracts struct {
|
||||||
Rollup ethCommon.Address `validate:"required"`
|
Rollup ethCommon.Address `validate:"required"`
|
||||||
Auction ethCommon.Address `validate:"required"`
|
Auction ethCommon.Address `validate:"required"`
|
||||||
TokenHEZ ethCommon.Address `validate:"required"`
|
TokenHEZ ethCommon.Address `validate:"required"`
|
||||||
|
TokenHEZName string `validate:"required"`
|
||||||
} `validate:"required"`
|
} `validate:"required"`
|
||||||
EthClient struct {
|
EthClient struct {
|
||||||
CallGasLimit uint64 `validate:"required"`
|
CallGasLimit uint64 `validate:"required"`
|
||||||
|
|||||||
@@ -178,9 +178,9 @@ func TestCoordinator(t *testing.T) {
|
|||||||
// Bid for slot 2 and 4
|
// Bid for slot 2 and 4
|
||||||
_, err := ethClient.AuctionSetCoordinator(forger, "https://foo.bar")
|
_, err := ethClient.AuctionSetCoordinator(forger, "https://foo.bar")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
_, err = ethClient.AuctionBid(2, big.NewInt(9999))
|
_, err = ethClient.AuctionBidSimple(2, big.NewInt(9999))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
_, err = ethClient.AuctionBid(4, big.NewInt(9999))
|
_, err = ethClient.AuctionBidSimple(4, big.NewInt(9999))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
c := NewCoordinator(conf, hdb, txsel, bb, serverProofs, ethClient)
|
c := NewCoordinator(conf, hdb, txsel, bb, serverProofs, ethClient)
|
||||||
|
|||||||
@@ -12,23 +12,28 @@ While the prepared deployment is not found to master, branch in repository must
|
|||||||
|
|
||||||
Now, install the dependencies:
|
Now, install the dependencies:
|
||||||
|
|
||||||
`npm i`
|
```
|
||||||
|
cd contracts/
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
Go to where the deployment scripts for the test are found:
|
Go to where the deployment scripts for the test are found:
|
||||||
|
|
||||||
`cd scripts/ethclient-test-deployment`
|
`cd scripts/ethclient-deployment/`
|
||||||
|
|
||||||
Now, a bash script has to be run to do the deployment:
|
Now, a bash script (which uses gnome-terminal) has to be run to do the deployment:
|
||||||
`./test-deployment`
|
`./test-deploy.sh`
|
||||||
|
|
||||||
This bash file follows these steps:
|
This bash file follows these steps:
|
||||||
- `npx builder node`: a local blockchain to do our tests
|
- `npx builder node`: a local blockchain to do our tests
|
||||||
- `npx buidler run --network localhost test-deployment.js`: run the deployment on the local blockchain
|
- `npx buidler run --network localhost test-deployment.js`: run the deployment on the local blockchain
|
||||||
|
|
||||||
|
Alternatively you can run the two previous commands manually in different terminals.
|
||||||
|
|
||||||
An output file necessary for the next step is obtained: `deploy-output`.
|
An output file necessary for the next step is obtained: `deploy-output`.
|
||||||
|
|
||||||
> The files that find in `/eth/contracts` must be obtained from the same contract that we deploy in this step
|
> The files that appear in `hermez-node/eth/contracts` must be generated from the same contract that we deploy in this step
|
||||||
|
|
||||||
## Ethclient Test
|
## Ethclient Test
|
||||||
|
|
||||||
Different environment variables are necessary to run this test.
|
Different environment variables are necessary to run this test.
|
||||||
@@ -46,9 +51,9 @@ WDELAYER="0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
|
|||||||
WDELAYER_TEST="0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160"
|
WDELAYER_TEST="0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160"
|
||||||
```
|
```
|
||||||
|
|
||||||
> An example is found in `/etc/.env.example`
|
> An example is found in `hermez-node/eth/.env.example`
|
||||||
|
|
||||||
And then run test:
|
And then run test from `hermez-node/eth/`:
|
||||||
|
|
||||||
`INTEGRATION=1 go test`
|
`INTEGRATION=1 go test`
|
||||||
|
|
||||||
|
|||||||
@@ -263,13 +263,14 @@ type AuctionInterface interface {
|
|||||||
type AuctionClient struct {
|
type AuctionClient struct {
|
||||||
client *EthereumClient
|
client *EthereumClient
|
||||||
address ethCommon.Address
|
address ethCommon.Address
|
||||||
tokenHEZ TokenConfig
|
tokenHEZCfg TokenConfig
|
||||||
auction *HermezAuctionProtocol.HermezAuctionProtocol
|
auction *HermezAuctionProtocol.HermezAuctionProtocol
|
||||||
|
tokenHEZ *HEZ.HEZ
|
||||||
contractAbi abi.ABI
|
contractAbi abi.ABI
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAuctionClient creates a new AuctionClient. `tokenAddress` is the address of the HEZ tokens.
|
// NewAuctionClient creates a new AuctionClient. `tokenAddress` is the address of the HEZ tokens.
|
||||||
func NewAuctionClient(client *EthereumClient, address ethCommon.Address, tokenHEZ TokenConfig) (*AuctionClient, error) {
|
func NewAuctionClient(client *EthereumClient, address ethCommon.Address, tokenHEZCfg TokenConfig) (*AuctionClient, error) {
|
||||||
contractAbi, err := abi.JSON(strings.NewReader(string(HermezAuctionProtocol.HermezAuctionProtocolABI)))
|
contractAbi, err := abi.JSON(strings.NewReader(string(HermezAuctionProtocol.HermezAuctionProtocolABI)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -278,11 +279,16 @@ func NewAuctionClient(client *EthereumClient, address ethCommon.Address, tokenHE
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
tokenHEZ, err := HEZ.NewHEZ(tokenHEZCfg.Address, client.Client())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &AuctionClient{
|
return &AuctionClient{
|
||||||
client: client,
|
client: client,
|
||||||
address: address,
|
address: address,
|
||||||
tokenHEZ: tokenHEZ,
|
tokenHEZCfg: tokenHEZCfg,
|
||||||
auction: auction,
|
auction: auction,
|
||||||
|
tokenHEZ: tokenHEZ,
|
||||||
contractAbi: contractAbi,
|
contractAbi: contractAbi,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -561,17 +567,16 @@ func (c *AuctionClient) AuctionBid(amount *big.Int, slot int64, bidAmount *big.I
|
|||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
0,
|
0,
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
tokenHEZcontract, err := HEZ.NewHEZ(c.tokenHEZ.Address, ec)
|
owner := c.client.account.Address
|
||||||
|
spender := c.address
|
||||||
|
nonce, err := c.tokenHEZ.Nonces(nil, owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
owner := c.client.account.Address
|
tokenName := c.tokenHEZCfg.Name
|
||||||
spender := c.address
|
tokenAddr := c.tokenHEZCfg.Address
|
||||||
nonce, err := tokenHEZcontract.Nonces(nil, owner)
|
chainid, _ := c.client.Client().ChainID(context.Background())
|
||||||
tokenname := c.tokenHEZ.Name
|
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenName)
|
||||||
tokenAddr := c.tokenHEZ.Address
|
|
||||||
chainid, _ := c.client.client.ChainID(context.Background())
|
|
||||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenname)
|
|
||||||
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
||||||
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
||||||
_slot := big.NewInt(slot)
|
_slot := big.NewInt(slot)
|
||||||
@@ -581,7 +586,6 @@ func (c *AuctionClient) AuctionBid(amount *big.Int, slot int64, bidAmount *big.I
|
|||||||
return nil, fmt.Errorf("Failed bid: %w", err)
|
return nil, fmt.Errorf("Failed bid: %w", err)
|
||||||
}
|
}
|
||||||
return tx, nil
|
return tx, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuctionMultiBid is the interface to call the smart contract function
|
// AuctionMultiBid is the interface to call the smart contract function
|
||||||
@@ -590,18 +594,17 @@ func (c *AuctionClient) AuctionMultiBid(amount *big.Int, startingSlot, endingSlo
|
|||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
1000000, //nolint:gomnd
|
1000000, //nolint:gomnd
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
tokenHEZcontract, err := HEZ.NewHEZ(c.tokenHEZ.Address, ec)
|
owner := c.client.account.Address
|
||||||
|
spender := c.address
|
||||||
|
nonce, err := c.tokenHEZ.Nonces(nil, owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
owner := c.client.account.Address
|
tokenName := c.tokenHEZCfg.Name
|
||||||
spender := c.address
|
tokenAddr := c.tokenHEZCfg.Address
|
||||||
nonce, err := tokenHEZcontract.Nonces(nil, owner)
|
chainid, _ := c.client.Client().ChainID(context.Background())
|
||||||
tokenname := c.tokenHEZ.Name
|
|
||||||
tokenAddr := c.tokenHEZ.Address
|
|
||||||
chainid, _ := c.client.client.ChainID(context.Background())
|
|
||||||
|
|
||||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenname)
|
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenName)
|
||||||
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
||||||
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
||||||
_startingSlot := big.NewInt(startingSlot)
|
_startingSlot := big.NewInt(startingSlot)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const openAuctionSlotsConst = uint16(4320)
|
|||||||
const closedAuctionSlotsConst = uint16(2)
|
const closedAuctionSlotsConst = uint16(2)
|
||||||
const outbiddingConst = uint16(1000)
|
const outbiddingConst = uint16(1000)
|
||||||
const currentSlotConst = 0
|
const currentSlotConst = 0
|
||||||
const BLOCKSPERSLOT = uint8(40)
|
const blocksPerSlot = uint8(40)
|
||||||
const minBidStr = "10000000000000000000"
|
const minBidStr = "10000000000000000000"
|
||||||
const URL = "http://localhost:3000"
|
const URL = "http://localhost:3000"
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ func TestAuctionConstants(t *testing.T) {
|
|||||||
|
|
||||||
auctionConstants, err := auctionClientTest.AuctionConstants()
|
auctionConstants, err := auctionClientTest.AuctionConstants()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, auctionConstants.BlocksPerSlot, BLOCKSPERSLOT)
|
assert.Equal(t, auctionConstants.BlocksPerSlot, blocksPerSlot)
|
||||||
assert.Equal(t, auctionConstants.GenesisBlockNum, genesisBlock)
|
assert.Equal(t, auctionConstants.GenesisBlockNum, genesisBlock)
|
||||||
assert.Equal(t, auctionConstants.HermezRollup, hermezRollupAddressTestConst)
|
assert.Equal(t, auctionConstants.HermezRollup, hermezRollupAddressTestConst)
|
||||||
assert.Equal(t, auctionConstants.InitialMinimalBidding, INITMINBID)
|
assert.Equal(t, auctionConstants.InitialMinimalBidding, INITMINBID)
|
||||||
@@ -277,7 +277,7 @@ func TestAuctionBid(t *testing.T) {
|
|||||||
|
|
||||||
func TestAuctionGetSlotNumber(t *testing.T) {
|
func TestAuctionGetSlotNumber(t *testing.T) {
|
||||||
slotConst := 4
|
slotConst := 4
|
||||||
blockNum := int(BLOCKSPERSLOT)*slotConst + int(genesisBlock)
|
blockNum := int(blocksPerSlot)*slotConst + int(genesisBlock)
|
||||||
|
|
||||||
slot, err := auctionClientTest.AuctionGetSlotNumber(int64(blockNum))
|
slot, err := auctionClientTest.AuctionGetSlotNumber(int64(blockNum))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -286,7 +286,7 @@ func TestAuctionGetSlotNumber(t *testing.T) {
|
|||||||
|
|
||||||
func TestAuctionCanForge(t *testing.T) {
|
func TestAuctionCanForge(t *testing.T) {
|
||||||
slotConst := 4
|
slotConst := 4
|
||||||
blockNum := int(BLOCKSPERSLOT)*slotConst + int(genesisBlock)
|
blockNum := int(blocksPerSlot)*slotConst + int(genesisBlock)
|
||||||
|
|
||||||
canForge, err := auctionClientTest.AuctionCanForge(governanceAddressConst, int64(blockNum))
|
canForge, err := auctionClientTest.AuctionCanForge(governanceAddressConst, int64(blockNum))
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -344,7 +344,7 @@ func TestAuctionForge(t *testing.T) {
|
|||||||
auctionClientTestHermez, err := NewAuctionClient(ethereumClientHermez, auctionTestAddressConst, tokenHEZ)
|
auctionClientTestHermez, err := NewAuctionClient(ethereumClientHermez, auctionTestAddressConst, tokenHEZ)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
slotConst := 4
|
slotConst := 4
|
||||||
blockNum := int64(int(BLOCKSPERSLOT)*slotConst + int(genesisBlock))
|
blockNum := int64(int(blocksPerSlot)*slotConst + int(genesisBlock))
|
||||||
currentBlockNum, _ := auctionClientTestHermez.client.EthCurrentBlock()
|
currentBlockNum, _ := auctionClientTestHermez.client.EthCurrentBlock()
|
||||||
blocksToAdd := blockNum - currentBlockNum
|
blocksToAdd := blockNum - currentBlockNum
|
||||||
addBlocks(blocksToAdd, ethClientDialURL)
|
addBlocks(blocksToAdd, ethClientDialURL)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ abigen --abi=HEZ.abi --bin=HEZ.bin --pkg=HEZ --out=HEZ.go
|
|||||||
You must compile the contracts to get the `.bin` and `.abi` files. The contracts used are in the repo: https://github.com/hermeznetwork/contracts
|
You must compile the contracts to get the `.bin` and `.abi` files. The contracts used are in the repo: https://github.com/hermeznetwork/contracts
|
||||||
|
|
||||||
Branch: `RemoveERC777`
|
Branch: `RemoveERC777`
|
||||||
Specifically they have been processed in the commit with hash: `7574ba47fd3d7dab2653a22f57b15c69280350dc`
|
Specifically they have been processed in the commit with hash: `2a1cfccfba6770c1077ecea983d2c743dc4a1e93`
|
||||||
|
|
||||||
Versions:
|
Versions:
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -277,6 +277,8 @@ func (c *EthereumClient) EthBlockByNumber(ctx context.Context, number int64) (*c
|
|||||||
|
|
||||||
// EthERC20Consts returns the constants defined for a particular ERC20 Token instance.
|
// EthERC20Consts returns the constants defined for a particular ERC20 Token instance.
|
||||||
func (c *EthereumClient) EthERC20Consts(tokenAddress ethCommon.Address) (*ERC20Consts, error) {
|
func (c *EthereumClient) EthERC20Consts(tokenAddress ethCommon.Address) (*ERC20Consts, error) {
|
||||||
|
// We use the HEZ token smart contract interfacehere because it's an
|
||||||
|
// ERC20, which allows us to access the standard ERC20 constants.
|
||||||
instance, err := HEZ.NewHEZ(tokenAddress, c.client)
|
instance, err := HEZ.NewHEZ(tokenAddress, c.client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -68,19 +67,21 @@ func addTime(seconds float64, url string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createPermitDigest(tokenAddr, owner, spender ethCommon.Address, chainID, value, nonce, deadline *big.Int, tokenName string) ([]byte, error) {
|
func createPermitDigest(tokenAddr, owner, spender ethCommon.Address, chainID, value, nonce, deadline *big.Int, tokenName string) ([]byte, error) {
|
||||||
|
// NOTE: We ignore hash.Write errors because we are writing to a memory
|
||||||
|
// buffer and don't expect any errors to occur.
|
||||||
abiPermit := []byte("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")
|
abiPermit := []byte("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")
|
||||||
hashPermit := sha3.NewLegacyKeccak256()
|
hashPermit := sha3.NewLegacyKeccak256()
|
||||||
hashPermit.Write(abiPermit)
|
hashPermit.Write(abiPermit) //nolint:errcheck,gosec
|
||||||
abiEIP712Domain := []byte("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
|
abiEIP712Domain := []byte("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
|
||||||
hashEIP712Domain := sha3.NewLegacyKeccak256()
|
hashEIP712Domain := sha3.NewLegacyKeccak256()
|
||||||
hashEIP712Domain.Write(abiEIP712Domain)
|
hashEIP712Domain.Write(abiEIP712Domain) //nolint:errcheck,gosec
|
||||||
var encodeBytes []byte
|
var encodeBytes []byte
|
||||||
paddedHash := ethCommon.LeftPadBytes(hashEIP712Domain.Sum(nil), 32)
|
paddedHash := ethCommon.LeftPadBytes(hashEIP712Domain.Sum(nil), 32)
|
||||||
hashName := sha3.NewLegacyKeccak256()
|
hashName := sha3.NewLegacyKeccak256()
|
||||||
hashName.Write([]byte(tokenName))
|
hashName.Write([]byte(tokenName)) //nolint:errcheck,gosec
|
||||||
paddedName := ethCommon.LeftPadBytes(hashName.Sum(nil), 32)
|
paddedName := ethCommon.LeftPadBytes(hashName.Sum(nil), 32)
|
||||||
hashVersion := sha3.NewLegacyKeccak256()
|
hashVersion := sha3.NewLegacyKeccak256()
|
||||||
hashVersion.Write([]byte("1"))
|
hashVersion.Write([]byte("1")) //nolint:errcheck,gosec
|
||||||
paddedX := ethCommon.LeftPadBytes(hashVersion.Sum(nil), 32)
|
paddedX := ethCommon.LeftPadBytes(hashVersion.Sum(nil), 32)
|
||||||
paddedChainID := ethCommon.LeftPadBytes(chainID.Bytes(), 32)
|
paddedChainID := ethCommon.LeftPadBytes(chainID.Bytes(), 32)
|
||||||
paddedAddr := ethCommon.LeftPadBytes(tokenAddr.Bytes(), 32)
|
paddedAddr := ethCommon.LeftPadBytes(tokenAddr.Bytes(), 32)
|
||||||
@@ -90,7 +91,7 @@ func createPermitDigest(tokenAddr, owner, spender ethCommon.Address, chainID, va
|
|||||||
encodeBytes = append(encodeBytes, paddedChainID...)
|
encodeBytes = append(encodeBytes, paddedChainID...)
|
||||||
encodeBytes = append(encodeBytes, paddedAddr...)
|
encodeBytes = append(encodeBytes, paddedAddr...)
|
||||||
_domainSeparator := sha3.NewLegacyKeccak256()
|
_domainSeparator := sha3.NewLegacyKeccak256()
|
||||||
_domainSeparator.Write(encodeBytes)
|
_domainSeparator.Write(encodeBytes) //nolint:errcheck,gosec
|
||||||
|
|
||||||
var bytes1 []byte
|
var bytes1 []byte
|
||||||
paddedHashPermit := ethCommon.LeftPadBytes(hashPermit.Sum(nil), 32)
|
paddedHashPermit := ethCommon.LeftPadBytes(hashPermit.Sum(nil), 32)
|
||||||
@@ -106,19 +107,11 @@ func createPermitDigest(tokenAddr, owner, spender ethCommon.Address, chainID, va
|
|||||||
bytes1 = append(bytes1, paddedNonce...)
|
bytes1 = append(bytes1, paddedNonce...)
|
||||||
bytes1 = append(bytes1, paddedDeadline...)
|
bytes1 = append(bytes1, paddedDeadline...)
|
||||||
hashBytes1 := sha3.NewLegacyKeccak256()
|
hashBytes1 := sha3.NewLegacyKeccak256()
|
||||||
hashBytes1.Write(bytes1)
|
hashBytes1.Write(bytes1) //nolint:errcheck,gosec
|
||||||
|
|
||||||
var bytes2 []byte
|
var bytes2 []byte
|
||||||
byte19, err := hex.DecodeString("19")
|
paddedY := ethCommon.LeftPadBytes([]byte{0x19}, 1)
|
||||||
if err != nil {
|
paddedZ := ethCommon.LeftPadBytes([]byte{0x01}, 1)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
byte01, err := hex.DecodeString("01")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
paddedY := ethCommon.LeftPadBytes(byte19, 1)
|
|
||||||
paddedZ := ethCommon.LeftPadBytes(byte01, 1)
|
|
||||||
paddedDomainSeparator := ethCommon.LeftPadBytes(_domainSeparator.Sum(nil), 32)
|
paddedDomainSeparator := ethCommon.LeftPadBytes(_domainSeparator.Sum(nil), 32)
|
||||||
paddedHashBytes1 := ethCommon.LeftPadBytes(hashBytes1.Sum(nil), 32)
|
paddedHashBytes1 := ethCommon.LeftPadBytes(hashBytes1.Sum(nil), 32)
|
||||||
bytes2 = append(bytes2, paddedY...)
|
bytes2 = append(bytes2, paddedY...)
|
||||||
@@ -126,7 +119,7 @@ func createPermitDigest(tokenAddr, owner, spender ethCommon.Address, chainID, va
|
|||||||
bytes2 = append(bytes2, paddedDomainSeparator...)
|
bytes2 = append(bytes2, paddedDomainSeparator...)
|
||||||
bytes2 = append(bytes2, paddedHashBytes1...)
|
bytes2 = append(bytes2, paddedHashBytes1...)
|
||||||
hashBytes2 := sha3.NewLegacyKeccak256()
|
hashBytes2 := sha3.NewLegacyKeccak256()
|
||||||
hashBytes2.Write(bytes2)
|
hashBytes2.Write(bytes2) //nolint:errcheck,gosec
|
||||||
|
|
||||||
return hashBytes2.Sum(nil), nil
|
return hashBytes2.Sum(nil), nil
|
||||||
}
|
}
|
||||||
@@ -134,11 +127,11 @@ func createPermitDigest(tokenAddr, owner, spender ethCommon.Address, chainID, va
|
|||||||
func createPermit(owner, spender ethCommon.Address, amount, deadline *big.Int, digest, signature []byte) []byte {
|
func createPermit(owner, spender ethCommon.Address, amount, deadline *big.Int, digest, signature []byte) []byte {
|
||||||
r := signature[0:32]
|
r := signature[0:32]
|
||||||
s := signature[32:64]
|
s := signature[32:64]
|
||||||
v := signature[64] + byte(27)
|
v := signature[64] + byte(27) //nolint:gomnd
|
||||||
|
|
||||||
ABIpermit := []byte("permit(address,address,uint256,uint256,uint8,bytes32,bytes32)")
|
ABIpermit := []byte("permit(address,address,uint256,uint256,uint8,bytes32,bytes32)")
|
||||||
hash := sha3.NewLegacyKeccak256()
|
hash := sha3.NewLegacyKeccak256()
|
||||||
hash.Write(ABIpermit)
|
hash.Write(ABIpermit) //nolint:errcheck,gosec
|
||||||
methodID := hash.Sum(nil)[:4]
|
methodID := hash.Sum(nil)[:4]
|
||||||
|
|
||||||
var permit []byte
|
var permit []byte
|
||||||
|
|||||||
@@ -16,25 +16,25 @@ import (
|
|||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ethClientDialURLConst = "http://localhost:8545"
|
|
||||||
var passwordConst = "pass"
|
|
||||||
var deadlineConst, _ = new(big.Int).SetString("ffffffffffffffffffffffffffffffff", 16)
|
|
||||||
|
|
||||||
var errEnvVar = fmt.Errorf("Some environment variable is missing")
|
var errEnvVar = fmt.Errorf("Some environment variable is missing")
|
||||||
|
|
||||||
|
var (
|
||||||
|
ethClientDialURL = "http://localhost:8545"
|
||||||
|
password = "pass"
|
||||||
|
deadline, _ = new(big.Int).SetString("ffffffffffffffffffffffffffffffff", 16)
|
||||||
|
)
|
||||||
|
|
||||||
// Smart Contract Addresses
|
// Smart Contract Addresses
|
||||||
var (
|
var (
|
||||||
password string
|
genesisBlock int64
|
||||||
ethClientDialURL string
|
auctionAddressConst ethCommon.Address
|
||||||
deadline *big.Int
|
auctionTestAddressConst ethCommon.Address
|
||||||
genesisBlock int64
|
tokenHEZAddressConst ethCommon.Address
|
||||||
auctionAddressConst ethCommon.Address
|
hermezRollupAddressConst ethCommon.Address
|
||||||
auctionTestAddressConst ethCommon.Address
|
wdelayerAddressConst ethCommon.Address
|
||||||
tokenHEZAddressConst ethCommon.Address
|
wdelayerTestAddressConst ethCommon.Address
|
||||||
hermezRollupAddressConst ethCommon.Address
|
tokenHEZ TokenConfig
|
||||||
wdelayerAddressConst ethCommon.Address
|
|
||||||
wdelayerTestAddressConst ethCommon.Address
|
|
||||||
tokenHEZ TokenConfig
|
|
||||||
donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
|
donationAddressStr = "0x6c365935CA8710200C7595F0a72EB6023A7706Cd"
|
||||||
donationAddressConst = ethCommon.HexToAddress(donationAddressStr)
|
donationAddressConst = ethCommon.HexToAddress(donationAddressStr)
|
||||||
bootCoordinatorAddressStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
|
bootCoordinatorAddressStr = "0xc783df8a850f42e7f7e57013759c285caa701eb6"
|
||||||
@@ -65,9 +65,9 @@ var (
|
|||||||
auxAddressStr = "0x3d91185a02774C70287F6c74Dd26d13DFB58ff16"
|
auxAddressStr = "0x3d91185a02774C70287F6c74Dd26d13DFB58ff16"
|
||||||
auxAddressConst = ethCommon.HexToAddress(auxAddressStr)
|
auxAddressConst = ethCommon.HexToAddress(auxAddressStr)
|
||||||
|
|
||||||
aux2AddressSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29087"
|
aux2AddressSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29087"
|
||||||
aux2AddressStr = "0x532792b73c0c6e7565912e7039c59986f7e1dd1f"
|
// aux2AddressStr = "0x532792b73c0c6e7565912e7039c59986f7e1dd1f"
|
||||||
aux2AddressConst = ethCommon.HexToAddress(aux2AddressStr)
|
// aux2AddressConst = ethCommon.HexToAddress(aux2AddressStr)
|
||||||
|
|
||||||
hermezRollupTestSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088"
|
hermezRollupTestSK = "28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088"
|
||||||
hermezRollupTestAddressStr = "0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0"
|
hermezRollupTestAddressStr = "0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0"
|
||||||
@@ -111,7 +111,7 @@ func addKey(ks *keystore.KeyStore, skHex string) *accounts.Account {
|
|||||||
func getEnvVariables() {
|
func getEnvVariables() {
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Variables loaded from command")
|
fmt.Println("Variables loaded from environment")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Variables loaded from .env file")
|
fmt.Println("Variables loaded from .env file")
|
||||||
}
|
}
|
||||||
@@ -130,9 +130,6 @@ func getEnvVariables() {
|
|||||||
panic(errEnvVar)
|
panic(errEnvVar)
|
||||||
}
|
}
|
||||||
|
|
||||||
ethClientDialURL = ethClientDialURLConst
|
|
||||||
password = passwordConst
|
|
||||||
deadline = deadlineConst
|
|
||||||
auctionAddressConst = ethCommon.HexToAddress(auctionAddressStr)
|
auctionAddressConst = ethCommon.HexToAddress(auctionAddressStr)
|
||||||
auctionTestAddressConst = ethCommon.HexToAddress(auctionTestAddressStr)
|
auctionTestAddressConst = ethCommon.HexToAddress(auctionTestAddressStr)
|
||||||
tokenHEZAddressConst = ethCommon.HexToAddress(tokenHEZAddressStr)
|
tokenHEZAddressConst = ethCommon.HexToAddress(tokenHEZAddressStr)
|
||||||
|
|||||||
@@ -290,13 +290,14 @@ type RollupInterface interface {
|
|||||||
type RollupClient struct {
|
type RollupClient struct {
|
||||||
client *EthereumClient
|
client *EthereumClient
|
||||||
address ethCommon.Address
|
address ethCommon.Address
|
||||||
tokenHEZ TokenConfig
|
tokenHEZCfg TokenConfig
|
||||||
hermez *Hermez.Hermez
|
hermez *Hermez.Hermez
|
||||||
|
tokenHEZ *HEZ.HEZ
|
||||||
contractAbi abi.ABI
|
contractAbi abi.ABI
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRollupClient creates a new RollupClient
|
// NewRollupClient creates a new RollupClient
|
||||||
func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZ TokenConfig) (*RollupClient, error) {
|
func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZCfg TokenConfig) (*RollupClient, error) {
|
||||||
contractAbi, err := abi.JSON(strings.NewReader(string(Hermez.HermezABI)))
|
contractAbi, err := abi.JSON(strings.NewReader(string(Hermez.HermezABI)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -305,11 +306,16 @@ func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZ
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
tokenHEZ, err := HEZ.NewHEZ(tokenHEZCfg.Address, client.Client())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &RollupClient{
|
return &RollupClient{
|
||||||
client: client,
|
client: client,
|
||||||
address: address,
|
address: address,
|
||||||
tokenHEZ: tokenHEZ,
|
tokenHEZCfg: tokenHEZCfg,
|
||||||
hermez: hermez,
|
hermez: hermez,
|
||||||
|
tokenHEZ: tokenHEZ,
|
||||||
contractAbi: contractAbi,
|
contractAbi: contractAbi,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -375,17 +381,16 @@ func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToke
|
|||||||
if tx, err = c.client.CallAuth(
|
if tx, err = c.client.CallAuth(
|
||||||
0,
|
0,
|
||||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||||
tokenHEZcontract, err := HEZ.NewHEZ(c.tokenHEZ.Address, ec)
|
owner := c.client.account.Address
|
||||||
|
spender := c.address
|
||||||
|
nonce, err := c.tokenHEZ.Nonces(nil, owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
owner := c.client.account.Address
|
tokenName := c.tokenHEZCfg.Name
|
||||||
spender := c.address
|
tokenAddr := c.tokenHEZCfg.Address
|
||||||
nonce, err := tokenHEZcontract.Nonces(nil, owner)
|
chainid, _ := c.client.Client().ChainID(context.Background())
|
||||||
tokenname := c.tokenHEZ.Name
|
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, feeAddToken, nonce, deadline, tokenName)
|
||||||
tokenAddr := c.tokenHEZ.Address
|
|
||||||
chainid, _ := c.client.client.ChainID(context.Background())
|
|
||||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, feeAddToken, nonce, deadline, tokenname)
|
|
||||||
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
||||||
permit := createPermit(owner, spender, feeAddToken, deadline, digest, signature)
|
permit := createPermit(owner, spender, feeAddToken, deadline, digest, signature)
|
||||||
|
|
||||||
@@ -431,7 +436,6 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
|
|||||||
babyPubKey := new(big.Int).SetBytes(pkCompB)
|
babyPubKey := new(big.Int).SetBytes(pkCompB)
|
||||||
fromIdxBig := big.NewInt(fromIdx)
|
fromIdxBig := big.NewInt(fromIdx)
|
||||||
toIdxBig := big.NewInt(toIdx)
|
toIdxBig := big.NewInt(toIdx)
|
||||||
tokenIDBig := uint32(tokenID)
|
|
||||||
loadAmountF, err := common.NewFloat16(loadAmount)
|
loadAmountF, err := common.NewFloat16(loadAmount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -444,7 +448,8 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
|
|||||||
auth.Value = loadAmount
|
auth.Value = loadAmount
|
||||||
}
|
}
|
||||||
var permit []byte
|
var permit []byte
|
||||||
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF), uint16(amountF), tokenIDBig, toIdxBig, permit)
|
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF),
|
||||||
|
uint16(amountF), tokenID, toIdxBig, permit)
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err)
|
return nil, fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err)
|
||||||
@@ -462,7 +467,6 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
|
|||||||
babyPubKey := new(big.Int).SetBytes(pkCompB)
|
babyPubKey := new(big.Int).SetBytes(pkCompB)
|
||||||
fromIdxBig := big.NewInt(fromIdx)
|
fromIdxBig := big.NewInt(fromIdx)
|
||||||
toIdxBig := big.NewInt(toIdx)
|
toIdxBig := big.NewInt(toIdx)
|
||||||
tokenIDBig := uint32(tokenID)
|
|
||||||
loadAmountF, err := common.NewFloat16(loadAmount)
|
loadAmountF, err := common.NewFloat16(loadAmount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -474,20 +478,20 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fro
|
|||||||
if tokenID == 0 {
|
if tokenID == 0 {
|
||||||
auth.Value = loadAmount
|
auth.Value = loadAmount
|
||||||
}
|
}
|
||||||
tokenHEZcontract, err := HEZ.NewHEZ(c.tokenHEZ.Address, ec)
|
owner := c.client.account.Address
|
||||||
|
spender := c.address
|
||||||
|
nonce, err := c.tokenHEZ.Nonces(nil, owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
owner := c.client.account.Address
|
tokenName := c.tokenHEZCfg.Name
|
||||||
spender := c.address
|
tokenAddr := c.tokenHEZCfg.Address
|
||||||
nonce, err := tokenHEZcontract.Nonces(nil, owner)
|
chainid, _ := c.client.Client().ChainID(context.Background())
|
||||||
tokenname := c.tokenHEZ.Name
|
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenName)
|
||||||
tokenAddr := c.tokenHEZ.Address
|
|
||||||
chainid, _ := c.client.client.ChainID(context.Background())
|
|
||||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenname)
|
|
||||||
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
||||||
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
||||||
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF), uint16(amountF), tokenIDBig, toIdxBig, permit)
|
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, uint16(loadAmountF),
|
||||||
|
uint16(amountF), tokenID, toIdxBig, permit)
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, fmt.Errorf("Failed add L1 Tx ERC20Permit: %w", err)
|
return nil, fmt.Errorf("Failed add L1 Tx ERC20Permit: %w", err)
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ func TestRollupForgeBatch(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
// Add Blocks
|
// Add Blocks
|
||||||
blockNum := int64(int(BLOCKSPERSLOT)*int(currentSlot+4) + int(genesisBlock))
|
blockNum := int64(int(blocksPerSlot)*int(currentSlot+4) + int(genesisBlock))
|
||||||
currentBlockNum, _ := auctionClient.client.EthCurrentBlock()
|
currentBlockNum, _ := auctionClient.client.EthCurrentBlock()
|
||||||
blocksToAdd := blockNum - currentBlockNum
|
blocksToAdd := blockNum - currentBlockNum
|
||||||
addBlocks(blocksToAdd, ethClientDialURL)
|
addBlocks(blocksToAdd, ethClientDialURL)
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ func TestWDelayerWithdrawal(t *testing.T) {
|
|||||||
amount := new(big.Int)
|
amount := new(big.Int)
|
||||||
amount.SetString("1100000000000000000", 10)
|
amount.SetString("1100000000000000000", 10)
|
||||||
_, err := wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenHEZAddressConst)
|
_, err := wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenHEZAddressConst)
|
||||||
require.Contains(t, err.Error(), "Withdrawal not allowed yet")
|
require.Contains(t, err.Error(), "WITHDRAWAL_NOT_ALLOWED")
|
||||||
addBlocks(newWithdrawalDelay.Int64(), ethClientDialURL)
|
addBlocks(newWithdrawalDelay.Int64(), ethClientDialURL)
|
||||||
_, err = wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenHEZAddressConst)
|
_, err = wdelayerClientTest.WDelayerWithdrawal(auxAddressConst, tokenHEZAddressConst)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -193,7 +193,7 @@ func TestWDelayerEscapeHatchWithdrawal(t *testing.T) {
|
|||||||
wdelayerClientWhite, err := NewWDelayerClient(ethereumClientWhite, wdelayerTestAddressConst)
|
wdelayerClientWhite, err := NewWDelayerClient(ethereumClientWhite, wdelayerTestAddressConst)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
|
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
|
||||||
require.Contains(t, err.Error(), "NO MAX_EMERGENCY_MODE_TIME")
|
require.Contains(t, err.Error(), "NO_MAX_EMERGENCY_MODE_TIME")
|
||||||
seconds := maxEmergencyModeTime.Seconds()
|
seconds := maxEmergencyModeTime.Seconds()
|
||||||
addTime(seconds, ethClientDialURL)
|
addTime(seconds, ethClientDialURL)
|
||||||
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
|
_, err = wdelayerClientWhite.WDelayerEscapeHatchWithdrawal(governanceAddressConst, tokenHEZAddressConst, amount)
|
||||||
|
|||||||
@@ -96,8 +96,11 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node,
|
|||||||
Address: cfg.SmartContracts.Rollup,
|
Address: cfg.SmartContracts.Rollup,
|
||||||
},
|
},
|
||||||
Auction: eth.AuctionConfig{
|
Auction: eth.AuctionConfig{
|
||||||
Address: cfg.SmartContracts.Auction,
|
Address: cfg.SmartContracts.Auction,
|
||||||
TokenHEZAddress: cfg.SmartContracts.TokenHEZ,
|
TokenHEZ: eth.TokenConfig{
|
||||||
|
Address: cfg.SmartContracts.TokenHEZ,
|
||||||
|
Name: cfg.SmartContracts.TokenHEZName,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func TestSync(t *testing.T) {
|
|||||||
// Add tokens to ethereum, and to rollup
|
// Add tokens to ethereum, and to rollup
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
client.CtlAddERC20(token.Addr, token.Consts)
|
client.CtlAddERC20(token.Addr, token.Consts)
|
||||||
_, err := client.RollupAddToken(token.Addr, clientSetup.RollupVariables.FeeAddToken)
|
_, err := client.RollupAddTokenSimple(token.Addr, clientSetup.RollupVariables.FeeAddToken)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -621,6 +621,12 @@ var errTODO = fmt.Errorf("TODO: Not implemented yet")
|
|||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// RollupL1UserTxERC20Permit is the interface to call the smart contract function
|
||||||
|
func (c *Client) RollupL1UserTxERC20Permit(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64, deadline *big.Int) (tx *types.Transaction, err error) {
|
||||||
|
log.Error("TODO")
|
||||||
|
return nil, errTODO
|
||||||
|
}
|
||||||
|
|
||||||
// RollupL1UserTxERC20ETH sends an L1UserTx to the Rollup.
|
// RollupL1UserTxERC20ETH sends an L1UserTx to the Rollup.
|
||||||
func (c *Client) RollupL1UserTxERC20ETH(
|
func (c *Client) RollupL1UserTxERC20ETH(
|
||||||
fromBJJ *babyjub.PublicKey,
|
fromBJJ *babyjub.PublicKey,
|
||||||
@@ -683,10 +689,10 @@ func (c *Client) RollupL1UserTxERC20ETH(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RollupL1UserTxERC777 is the interface to call the smart contract function
|
// RollupL1UserTxERC777 is the interface to call the smart contract function
|
||||||
func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
// func (c *Client) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||||
log.Error("TODO")
|
// log.Error("TODO")
|
||||||
return nil, errTODO
|
// return nil, errTODO
|
||||||
}
|
// }
|
||||||
|
|
||||||
// RollupRegisterTokensCount is the interface to call the smart contract function
|
// RollupRegisterTokensCount is the interface to call the smart contract function
|
||||||
func (c *Client) RollupRegisterTokensCount() (*big.Int, error) {
|
func (c *Client) RollupRegisterTokensCount() (*big.Int, error) {
|
||||||
@@ -790,8 +796,15 @@ func (c *Client) addBatch(args *eth.RollupForgeBatchArgs) (*types.Transaction, e
|
|||||||
return ethTx, nil
|
return ethTx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RollupAddTokenSimple is a wrapper around RollupAddToken that automatically
|
||||||
|
// sets `deadlie`.
|
||||||
|
func (c *Client) RollupAddTokenSimple(tokenAddress ethCommon.Address, feeAddToken *big.Int) (tx *types.Transaction, err error) {
|
||||||
|
return c.RollupAddToken(tokenAddress, feeAddToken, big.NewInt(9999)) //nolint:gomnd
|
||||||
|
}
|
||||||
|
|
||||||
// RollupAddToken is the interface to call the smart contract function
|
// RollupAddToken is the interface to call the smart contract function
|
||||||
func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (tx *types.Transaction, err error) {
|
func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int,
|
||||||
|
deadline *big.Int) (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()
|
||||||
@@ -1190,8 +1203,15 @@ func (c *Client) AuctionGetSlotSet(slot int64) (*big.Int, error) {
|
|||||||
// return errTODO
|
// return errTODO
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// AuctionBid is the interface to call the smart contract function
|
// AuctionBidSimple is a wrapper around AuctionBid that automatically sets `amount` and `deadline`.
|
||||||
func (c *Client) AuctionBid(slot int64, bidAmount *big.Int) (tx *types.Transaction, err error) {
|
func (c *Client) AuctionBidSimple(slot int64, bidAmount *big.Int) (tx *types.Transaction, err error) {
|
||||||
|
return c.AuctionBid(bidAmount, slot, bidAmount, big.NewInt(99999)) //nolint:gomnd
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuctionBid is the interface to call the smart contract function. This
|
||||||
|
// implementation behaves as if any address has infinite tokens.
|
||||||
|
func (c *Client) AuctionBid(amount *big.Int, slot int64, bidAmount *big.Int,
|
||||||
|
deadline *big.Int) (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()
|
||||||
@@ -1242,8 +1262,10 @@ func (c *Client) AuctionBid(slot int64, bidAmount *big.Int) (tx *types.Transacti
|
|||||||
return a.addTransaction(newTransaction("bid", data{slot, bidAmount, *c.addr})), nil
|
return a.addTransaction(newTransaction("bid", data{slot, bidAmount, *c.addr})), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuctionMultiBid is the interface to call the smart contract function
|
// AuctionMultiBid is the interface to call the smart contract function. This
|
||||||
func (c *Client) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int) (tx *types.Transaction, err error) {
|
// implementation behaves as if any address has infinite tokens.
|
||||||
|
func (c *Client) AuctionMultiBid(amount *big.Int, startingSlot int64, endingSlot int64, slotSet [6]bool,
|
||||||
|
maxBid, closedMinBid, deadline *big.Int) (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()
|
||||||
|
|||||||
@@ -94,34 +94,34 @@ 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))
|
_, err := c.AuctionBidSimple(0, big.NewInt(1))
|
||||||
assert.Equal(t, errBidClosed, err)
|
assert.Equal(t, errBidClosed, err)
|
||||||
|
|
||||||
_, err = c.AuctionBid(4322, big.NewInt(1))
|
_, err = c.AuctionBidSimple(4322, big.NewInt(1))
|
||||||
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))
|
_, err = c.AuctionBidSimple(101, big.NewInt(1650))
|
||||||
assert.Equal(t, errCoordNotReg, err)
|
assert.Equal(t, errCoordNotReg, err)
|
||||||
|
|
||||||
_, err = c.AuctionSetCoordinator(addrForge, "https://foo.bar")
|
_, err = c.AuctionSetCoordinator(addrForge, "https://foo.bar")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
_, err = c.AuctionBid(3, big.NewInt(1))
|
_, err = c.AuctionBidSimple(3, big.NewInt(1))
|
||||||
assert.Equal(t, errBidBelowMin, err)
|
assert.Equal(t, errBidBelowMin, err)
|
||||||
|
|
||||||
_, err = c.AuctionBid(3, big.NewInt(1650))
|
_, err = c.AuctionBidSimple(3, big.NewInt(1650))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
c.CtlSetAddr(addrBidder2)
|
c.CtlSetAddr(addrBidder2)
|
||||||
_, err = c.AuctionSetCoordinator(addrForge2, "https://foo2.bar")
|
_, err = c.AuctionSetCoordinator(addrForge2, "https://foo2.bar")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
_, err = c.AuctionBid(3, big.NewInt(16))
|
_, err = c.AuctionBidSimple(3, big.NewInt(16))
|
||||||
assert.Equal(t, errBidBelowMin, err)
|
assert.Equal(t, errBidBelowMin, err)
|
||||||
|
|
||||||
// 1650 + 10% = 1815
|
// 1650 + 10% = 1815
|
||||||
_, err = c.AuctionBid(3, big.NewInt(1815))
|
_, err = c.AuctionBidSimple(3, big.NewInt(1815))
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
c.CtlMineBlock()
|
c.CtlMineBlock()
|
||||||
@@ -143,7 +143,7 @@ func TestClientRollup(t *testing.T) {
|
|||||||
|
|
||||||
// Add a token
|
// Add a token
|
||||||
|
|
||||||
tx, err := c.RollupAddToken(token1Addr, clientSetup.RollupVariables.FeeAddToken)
|
tx, err := c.RollupAddTokenSimple(token1Addr, clientSetup.RollupVariables.FeeAddToken)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.NotNil(t, tx)
|
assert.NotNil(t, tx)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user