Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(cmd): default unit for all related flags / logs
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed Apr 19, 2024
1 parent d3a28b9 commit 6680dbf
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
3 changes: 2 additions & 1 deletion driver/anchor_tx_constructor/anchor_tx_constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/taikoxyz/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-client/driver/signer"
"github.com/taikoxyz/taiko-client/internal/utils"
"github.com/taikoxyz/taiko-client/pkg/rpc"
)

Expand Down Expand Up @@ -69,7 +70,7 @@ func (c *AnchorTxConstructor) AssembleAnchorTx(
"l1Height", l1Height,
"l1Hash", l1Hash,
"stateRoot", l1Header.Root,
"baseFee", baseFee,
"baseFee", utils.WeiToGWei(baseFee),
"gasUsed", parentGasUsed,
)

Expand Down
8 changes: 4 additions & 4 deletions driver/chain_syncer/calldata/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (s *Syncer) onBlockProposed(
"height", payloadData.Number,
"hash", payloadData.BlockHash,
"transactions", len(payloadData.Transactions),
"baseFee", payloadData.BaseFeePerGas,
"baseFee", utils.WeiToGWei(payloadData.BaseFeePerGas),
"withdrawals", len(payloadData.Withdrawals),
)

Expand Down Expand Up @@ -350,7 +350,7 @@ func (s *Syncer) insertNewHead(
log.Info(
"L2 baseFee",
"blockID", event.BlockId,
"baseFee", baseFeeInfo.Basefee,
"baseFee", utils.WeiToGWei(baseFeeInfo.Basefee),
"syncedL1Height", event.Meta.L1Height,
"parentGasUsed", parent.GasUsed,
)
Expand Down Expand Up @@ -483,7 +483,7 @@ func (s *Syncer) createExecutionPayloads(
"gasLimit", attributes.BlockMetadata.GasLimit,
"timestamp", attributes.BlockMetadata.Timestamp,
"mixHash", attributes.BlockMetadata.MixHash,
"baseFee", attributes.BaseFeePerGas,
"baseFee", utils.WeiToGWei(attributes.BaseFeePerGas),
"extraData", string(attributes.BlockMetadata.ExtraData),
"l1OriginHeight", attributes.L1Origin.L1BlockHeight,
"l1OriginHash", attributes.L1Origin.L1BlockHash,
Expand All @@ -510,7 +510,7 @@ func (s *Syncer) createExecutionPayloads(
log.Debug(
"Payload",
"blockID", event.BlockId,
"baseFee", payload.BaseFeePerGas,
"baseFee", utils.WeiToGWei(payload.BaseFeePerGas),
"number", payload.Number,
"hash", payload.BlockHash,
"gasLimit", payload.GasLimit,
Expand Down
26 changes: 26 additions & 0 deletions internal/utils/util_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package utils_test

import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
"github.com/taikoxyz/taiko-client/internal/testutils"
"github.com/taikoxyz/taiko-client/internal/utils"
Expand All @@ -20,3 +22,27 @@ func TestEncodeDecodeBytes(t *testing.T) {

require.Equal(t, b, decompressed)
}

func TestGWeiToWei(t *testing.T) {
wei, err := utils.GWeiToWei(1.0)
require.Nil(t, err)

require.Equal(t, big.NewInt(params.GWei), wei)
}

func TestEtherToWei(t *testing.T) {
wei, err := utils.EtherToWei(1.0)
require.Nil(t, err)

require.Equal(t, big.NewInt(params.Ether), wei)
}

func TestWeiToEther(t *testing.T) {
eth := utils.WeiToEther(big.NewInt(params.Ether))
require.Equal(t, new(big.Float).SetUint64(1), eth)
}

func TestWeiToGWei(t *testing.T) {
gwei := utils.WeiToGWei(big.NewInt(params.GWei))
require.Equal(t, new(big.Float).SetUint64(1), gwei)
}
9 changes: 7 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func EtherToWei(ether float64) (*big.Int, error) {
// convert float GWei value into integer Wei value
wei, _ := new(big.Float).Mul(
big.NewFloat(ether),
big.NewFloat(params.GWei)).
big.NewFloat(params.Ether)).
Int(nil)

if wei.Cmp(abi.MaxUint256) == 1 {
return nil, errors.New("gwei value larger than max uint256")
return nil, errors.New("ether value larger than max uint256")
}

return wei, nil
Expand All @@ -155,3 +155,8 @@ func EtherToWei(ether float64) (*big.Int, error) {
func WeiToEther(wei *big.Int) *big.Float {
return new(big.Float).Quo(new(big.Float).SetInt(wei), new(big.Float).SetInt(big.NewInt(params.Ether)))
}

// WeiToGWei converts wei value to gwei value.
func WeiToGWei(wei *big.Int) *big.Float {
return new(big.Float).Quo(new(big.Float).SetInt(wei), new(big.Float).SetInt(big.NewInt(params.GWei)))
}
3 changes: 2 additions & 1 deletion pkg/rpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-client/internal/utils"
)

var (
Expand Down Expand Up @@ -277,7 +278,7 @@ func (c *Client) GetPoolContent(
return nil, err
}

log.Info("Current base fee", "fee", baseFeeInfo.Basefee)
log.Info("Current base fee", "fee", utils.WeiToGWei(baseFeeInfo.Basefee))

var localsArg []string
for _, local := range locals {
Expand Down
14 changes: 7 additions & 7 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func CheckProverBalance(

log.Info(
"Prover allowance for TaikoL1 contract",
"allowance", allowance.String(),
"allowance", utils.WeiToEther(allowance),
"address", prover.Hex(),
"bond", bond.String(),
"bond", utils.WeiToEther(bond),
)

// Check prover's taiko token balance
Expand All @@ -76,18 +76,18 @@ func CheckProverBalance(

log.Info(
"Prover's wallet taiko token balance",
"balance", balance.String(),
"balance", utils.WeiToEther(balance),
"address", prover.Hex(),
"bond", bond.String(),
"bond", utils.WeiToEther(bond),
)

if bond.Cmp(allowance) > 0 || bond.Cmp(balance) > 0 {
log.Info(
"Assigned prover does not have required on-chain token balance or allowance",
"providedProver", prover.Hex(),
"taikoTokenBalance", balance,
"allowance", allowance.String(),
"bond", bond,
"taikoTokenBalance", utils.WeiToEther(balance),
"allowance", utils.WeiToEther(allowance),
"bond", utils.WeiToEther(bond),
)
return false, nil
}
Expand Down
4 changes: 2 additions & 2 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ func (p *Proposer) initTierFees() error {
"Protocol tier",
"id", tier.ID,
"name", string(bytes.TrimRight(tier.VerifierName[:], "\x00")),
"validityBond", tier.ValidityBond,
"contestBond", tier.ContestBond,
"validityBond", utils.WeiToEther(tier.ValidityBond),
"contestBond", utils.WeiToEther(tier.ContestBond),
"provingWindow", tier.ProvingWindow,
"cooldownWindow", tier.CooldownWindow,
)
Expand Down

0 comments on commit 6680dbf

Please sign in to comment.