Skip to content

Commit

Permalink
approve command with wei (0xPolygonHermez#1703)
Browse files Browse the repository at this point in the history
* approve with wei

* fix

* comment consolidations
  • Loading branch information
ARR552 authored Feb 27, 2023
1 parent 4f9154c commit 39aaf4e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 21 deletions.
15 changes: 6 additions & 9 deletions cmd/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"strings"

"github.com/0xPolygonHermez/zkevm-node/config"
"github.com/0xPolygonHermez/zkevm-node/encoding"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/urfave/cli/v2"
)

func approveTokens(ctx *cli.Context) error {
amountArg := ctx.String(config.FlagAmount)
amount, _ := new(big.Float).SetString(amountArg)
amount, _ := new(big.Int).SetString(amountArg, encoding.Base10)
if amount == nil {
fmt.Println("Please, introduce a valid amount. Use '.' instead of ',' if it is a decimal number")
fmt.Println("Please, introduce a valid amount in wei")
return nil
}

Expand All @@ -27,8 +28,8 @@ func approveTokens(ctx *cli.Context) error {
}

if !ctx.Bool(config.FlagYes) {
fmt.Print("*WARNING* Are you sure you want to approve ", amount,
" tokens to be spent by the smc <Name: PoE. Address: "+c.Etherman.PoEAddr.String()+">? [y/N]: ")
fmt.Print("*WARNING* Are you sure you want to approve ", amount.String(),
" tokens (in wei) for the smc <Name: PoE. Address: "+c.Etherman.PoEAddr.String()+">? [y/N]: ")
var input string
if _, err := fmt.Scanln(&input); err != nil {
return err
Expand All @@ -55,11 +56,7 @@ func approveTokens(ctx *cli.Context) error {
return err
}

const decimals = 1000000000000000000
amountInWei := new(big.Float).Mul(amount, big.NewFloat(decimals))
amountB := new(big.Int)
amountInWei.Int(amountB)
tx, err := etherman.ApproveMatic(ctx.Context, auth.From, amountB, c.Etherman.PoEAddr)
tx, err := etherman.ApproveMatic(ctx.Context, auth.From, amount, c.Etherman.PoEAddr)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ func Test_Defaults(t *testing.T) {
},
{
path: "Etherman.PoEAddr",
expectedValue: common.HexToAddress("0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"),
expectedValue: common.HexToAddress("0x610178dA211FEF7D417bC0e6FeD39F05609AD788"),
},
{
path: "Etherman.MaticAddr",
expectedValue: common.HexToAddress("0x5FbDB2315678afecb367f032d93F642f64180aa3"),
},
{
path: "Etherman.GlobalExitRootManagerAddr",
expectedValue: common.HexToAddress("0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"),
expectedValue: common.HexToAddress("0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"),
},
{
path: "Etherman.MultiGasProvider",
Expand Down
4 changes: 2 additions & 2 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ FreeClaimGasLimit = 150000
[Etherman]
URL = "http://localhost:8545"
L1ChainID = 1337
PoEAddr = "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"
PoEAddr = "0x610178dA211FEF7D417bC0e6FeD39F05609AD788"
MaticAddr = "0x5FbDB2315678afecb367f032d93F642f64180aa3"
GlobalExitRootManagerAddr = "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
GlobalExitRootManagerAddr = "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"
MultiGasProvider = true
[Etherman.Etherscan]
ApiKey = ""
Expand Down
2 changes: 1 addition & 1 deletion etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (etherMan *Client) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVe
var newStateRoot [32]byte
copy(newStateRoot[:], inputs.NewStateRoot)

log.Info("Proof before trim: %v", inputs.FinalProof.Proof)
log.Info("Proof before trim: ", inputs.FinalProof.Proof)
proof, err := encoding.DecodeBytes(&inputs.FinalProof.Proof)
if err != nil {
return nil, nil, fmt.Errorf("failed to decode proof, err: %w", err)
Expand Down
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ run: ## Runs a full node
$(RUNL1NETWORK)
sleep 1
$(RUNZKPROVER)
$(RUNAPPROVE)
sleep 3
$(RUNSYNC)
sleep 2
Expand Down
2 changes: 1 addition & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ services:
command:
- "/bin/sh"
- "-c"
- "/app/zkevm-node approve --key-store-path /pk/keystore --pw testonly --am 10000000000000000 -y --cfg /app/config.toml"
- "/app/zkevm-node approve --key-store-path /pk/keystore --pw testonly --am 115792089237316195423570985008687907853269984665640564039457584007913129639935 -y --cfg /app/config.toml"

zkevm-permissionless-db:
container_name: zkevm-permissionless-db
Expand Down
11 changes: 6 additions & 5 deletions test/operations/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,12 @@ func ApplyL2Txs(ctx context.Context, txs []*types.Transaction, auth *bind.Transa
}

// wait for l2 block number to be consolidated
log.Infof("waiting for the block number %v to be consolidated", l2BlockNumber.String())
err = WaitL2BlockToBeConsolidated(l2BlockNumber, 4*time.Minute) //nolint:gomnd
if err != nil {
return err
}
// TODO UNCOMMENT
// log.Infof("waiting for the block number %v to be consolidated", l2BlockNumber.String())
// err = WaitL2BlockToBeConsolidated(l2BlockNumber, 4*time.Minute) //nolint:gomnd
// if err != nil {
// return err
// }

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/sendForcedBatch/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Command:
```
go run main.go send --url http://localhost:8545 --smc 0x8A791620dd6260079BF849Dc5567aDC3F2FdC318
go run main.go send --url http://localhost:8545 --smc 0x610178dA211FEF7D417bC0e6FeD39F05609AD788
```

0 comments on commit 39aaf4e

Please sign in to comment.