Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gasLimitMultiplier to fireblocks and privatekey wallets #165

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"math"
"math/big"

Expand Down Expand Up @@ -212,7 +213,8 @@ func (r *AvsRegistryChainReader) GetOperatorAddrsInQuorumsAtCurrentBlock(
uint32(curBlock),
)
if err != nil {
return nil, types.WrapError(errors.New("Failed to get operators state"), err)
return nil, types.WrapError(fmt.Errorf("Failed to get operators state at block %d, quorums %v and registryCoordinatorAddr %v",
curBlock, quorumNumbers, r.registryCoordinatorAddr), err)
Comment on lines +216 to +217
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throwing this into this PR if you don't mind

}
var quorumOperatorAddrs [][]common.Address
for _, quorum := range operatorStakes {
Expand Down
29 changes: 18 additions & 11 deletions chainio/clients/wallet/fireblocks_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ type fireblocksWallet struct {
// accessed concurrently by SendTransaction and GetTransactionReceipt
mu sync.Mutex

fireblocksClient fireblocks.Client
ethClient eth.Client
vaultAccountName string
logger logging.Logger
chainID *big.Int
fireblocksClient fireblocks.Client
ethClient eth.Client
vaultAccountName string
logger logging.Logger
chainID *big.Int
gasLimitMultiplier float64

// nonceToTx keeps track of the transaction ID for each nonce
// this is used to retrieve the transaction hash for a given nonce
Expand All @@ -53,11 +54,12 @@ func NewFireblocksWallet(fireblocksClient fireblocks.Client, ethClient eth.Clien
}
logger.Debug("Creating new Fireblocks wallet for chain", "chainID", chainID)
return &fireblocksWallet{
fireblocksClient: fireblocksClient,
ethClient: ethClient,
vaultAccountName: vaultAccountName,
logger: logger,
chainID: chainID,
fireblocksClient: fireblocksClient,
ethClient: ethClient,
vaultAccountName: vaultAccountName,
logger: logger,
chainID: chainID,
gasLimitMultiplier: FallbackGasLimitMultiplier,

nonceToTxID: make(map[uint64]TxID),
txIDToNonce: make(map[TxID]uint64),
Expand All @@ -68,6 +70,11 @@ func NewFireblocksWallet(fireblocksClient fireblocks.Client, ethClient eth.Clien
}, nil
}

func (t *fireblocksWallet) WithGasLimitMultiplier(multiplier float64) *fireblocksWallet {
t.gasLimitMultiplier = multiplier
return t
}

func (t *fireblocksWallet) getAccount(ctx context.Context) (*fireblocks.VaultAccount, error) {
if t.account == nil {
accounts, err := t.fireblocksClient.ListVaultAccounts(ctx)
Expand Down Expand Up @@ -158,7 +165,7 @@ func (t *fireblocksWallet) SendTransaction(ctx context.Context, tx *types.Transa

gasLimit := ""
if tx.Gas() > 0 {
gasLimit = strconv.FormatUint(tx.Gas(), 10)
gasLimit = strconv.FormatUint(uint64(float64(tx.Gas())*t.gasLimitMultiplier), 10)
}

// if the gas fees are specified in the transaction, use them.
Expand Down
30 changes: 19 additions & 11 deletions chainio/clients/wallet/privatekey_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,39 @@ import (
)

var (
FallbackGasTipCap = big.NewInt(15_000_000_000)
FallbackGasTipCap = big.NewInt(15_000_000_000)
FallbackGasLimitMultiplier = 1.1
)

var _ Wallet = (*privateKeyWallet)(nil)

type privateKeyWallet struct {
ethClient eth.Client
address common.Address
signerFn signerv2.SignerFn
logger logging.Logger
ethClient eth.Client
address common.Address
signerFn signerv2.SignerFn
logger logging.Logger
gasLimitMultiplier float64

// cache
contracts map[common.Address]*bind.BoundContract
}

func NewPrivateKeyWallet(ethClient eth.Client, signer signerv2.SignerFn, signerAddress common.Address, logger logging.Logger) (Wallet, error) {
return &privateKeyWallet{
ethClient: ethClient,
address: signerAddress,
signerFn: signer,
logger: logger,
contracts: make(map[common.Address]*bind.BoundContract, 0),
ethClient: ethClient,
address: signerAddress,
signerFn: signer,
logger: logger,
gasLimitMultiplier: FallbackGasLimitMultiplier,
contracts: make(map[common.Address]*bind.BoundContract, 0),
}, nil
}

func (t *privateKeyWallet) WithGasLimitMultiplier(multiplier float64) *privateKeyWallet {
t.gasLimitMultiplier = multiplier
return t
}

func (t *privateKeyWallet) SendTransaction(ctx context.Context, tx *types.Transaction) (TxID, error) {
// Estimate gas and nonce
// can't print tx hash in logs because the tx changes below when we complete and sign it
Expand Down Expand Up @@ -134,7 +142,7 @@ func (t *privateKeyWallet) estimateGasAndNonce(ctx context.Context, tx *types.Tr
GasFeeCap: gasFeeCap,
Data: tx.Data(),
Value: tx.Value(),
Gas: gasLimit, // TODO(add buffer)
Gas: uint64(float64(gasLimit) * t.gasLimitMultiplier),
Nonce: tx.Nonce(), // We are not doing any nonce management for now but we probably should later for more robustness
}

Expand Down
Loading