-
Notifications
You must be signed in to change notification settings - Fork 33
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
fix(rfq-relayer): gas estimation for zaps #3413
Changes from 4 commits
603e42f
cd70e74
d1796a1
f557248
fdeff59
1589b83
6ae2731
3858f68
cc1cd2e
5c5c557
e0f3e55
78a3293
bde24d6
20a2e82
c59425c
e8db2fe
3783b2c
a65d861
89e8bb7
1e05972
8d8491a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -381,16 +381,11 @@ | |||||||||||||||||||||
OriginAmountExact: originAmountExact, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if rfqRequest.Data.ZapNative != "" || rfqRequest.Data.ZapData != "" { | ||||||||||||||||||||||
zapNative, ok := new(big.Int).SetString(rfqRequest.Data.ZapNative, 10) | ||||||||||||||||||||||
if !ok { | ||||||||||||||||||||||
return nil, fmt.Errorf("invalid zap native amount: %s", rfqRequest.Data.ZapNative) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
quoteInput.QuoteRequest = &reldb.QuoteRequest{ | ||||||||||||||||||||||
Transaction: fastbridgev2.IFastBridgeV2BridgeTransactionV2{ | ||||||||||||||||||||||
ZapNative: zapNative, | ||||||||||||||||||||||
ZapData: []byte(rfqRequest.Data.ZapData), | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
quoteRequest, err := quoteDataToQuoteRequestV2(&rfqRequest.Data) | ||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||
return nil, fmt.Errorf("error converting quote data to quote request: %w", err) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
quoteInput.QuoteRequest = quoteRequest | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
rawQuote, err := m.generateQuote(ctx, quoteInput) | ||||||||||||||||||||||
|
@@ -432,6 +427,49 @@ | |||||||||||||||||||||
return resp, nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func quoteDataToQuoteRequestV2(quoteData *model.QuoteData) (*reldb.QuoteRequest, error) { | ||||||||||||||||||||||
if quoteData == nil { | ||||||||||||||||||||||
return nil, errors.New("quote data is nil") | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
originAmount, ok := new(big.Int).SetString(quoteData.OriginAmountExact, 10) | ||||||||||||||||||||||
if !ok { | ||||||||||||||||||||||
return nil, errors.New("invalid origin amount") | ||||||||||||||||||||||
} | ||||||||||||||||||||||
destAmount := originAmount // assume dest amount same as origin amount for estimation purposes | ||||||||||||||||||||||
originFeeAmount := big.NewInt(0) | ||||||||||||||||||||||
nonce := big.NewInt(0) | ||||||||||||||||||||||
exclusivityEndTime := big.NewInt(0) | ||||||||||||||||||||||
zapNative, ok := new(big.Int).SetString(quoteData.ZapNative, 10) | ||||||||||||||||||||||
if !ok { | ||||||||||||||||||||||
return nil, errors.New("invalid zap native") | ||||||||||||||||||||||
} | ||||||||||||||||||||||
deadline := new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil), big.NewInt(1)) | ||||||||||||||||||||||
exclusivityRelayer := common.HexToAddress("") | ||||||||||||||||||||||
|
||||||||||||||||||||||
quoteRequest := &reldb.QuoteRequest{ | ||||||||||||||||||||||
Transaction: fastbridgev2.IFastBridgeV2BridgeTransactionV2{ | ||||||||||||||||||||||
OriginChainId: uint32(quoteData.OriginChainID), | ||||||||||||||||||||||
DestChainId: uint32(quoteData.DestChainID), | ||||||||||||||||||||||
Comment on lines
+453
to
+454
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential integer overflow when converting Casting Apply this diff to add validation: + if quoteData.OriginChainID < 0 || quoteData.OriginChainID > math.MaxUint32 {
+ return nil, fmt.Errorf("OriginChainID out of range: %d", quoteData.OriginChainID)
+ }
+ if quoteData.DestChainID < 0 || quoteData.DestChainID > math.MaxUint32 {
+ return nil, fmt.Errorf("DestChainID out of range: %d", quoteData.DestChainID)
+ }
quoteRequest := &reldb.QuoteRequest{
Transaction: fastbridgev2.IFastBridgeV2BridgeTransactionV2{
OriginChainId: uint32(quoteData.OriginChainID),
DestChainId: uint32(quoteData.DestChainID), Alternatively, if
🧰 Tools🪛 GitHub Check: Lint (services/rfq)[failure] 452-452: [failure] 453-453: |
||||||||||||||||||||||
OriginSender: common.HexToAddress(quoteData.OriginSender), | ||||||||||||||||||||||
DestRecipient: common.HexToAddress(quoteData.DestRecipient), | ||||||||||||||||||||||
Comment on lines
+455
to
+456
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate sender and recipient addresses. The function should validate that the sender and recipient addresses are not zero addresses to prevent potential issues with transactions. + if quoteData.OriginSender == "" || common.HexToAddress(quoteData.OriginSender) == (common.Address{}) {
+ return nil, errors.New("invalid origin sender address")
+ }
+ if quoteData.DestRecipient == "" || common.HexToAddress(quoteData.DestRecipient) == (common.Address{}) {
+ return nil, errors.New("invalid destination recipient address")
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
OriginToken: common.HexToAddress(quoteData.OriginTokenAddr), | ||||||||||||||||||||||
DestToken: common.HexToAddress(quoteData.DestTokenAddr), | ||||||||||||||||||||||
OriginAmount: originAmount, | ||||||||||||||||||||||
DestAmount: destAmount, | ||||||||||||||||||||||
OriginFeeAmount: originFeeAmount, | ||||||||||||||||||||||
Deadline: deadline, | ||||||||||||||||||||||
Nonce: nonce, | ||||||||||||||||||||||
ExclusivityRelayer: exclusivityRelayer, | ||||||||||||||||||||||
ExclusivityEndTime: exclusivityEndTime, | ||||||||||||||||||||||
ZapNative: zapNative, | ||||||||||||||||||||||
ZapData: []byte(quoteData.ZapData), | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return quoteRequest, nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// GetPrice gets the price of a token. | ||||||||||||||||||||||
func (m *Manager) GetPrice(parentCtx context.Context, tokenName string) (_ float64, err error) { | ||||||||||||||||||||||
ctx, span := m.metricsHandler.Tracer().Start(parentCtx, "GetPrice") | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap error returned from external package
The error returned from
args.Pack()
should be wrapped with additional context.Apply this change:
📝 Committable suggestion
🧰 Tools
🪛 golangci-lint (1.62.2)
315-315: error returned from external package is unwrapped: sig: func (github.com/ethereum/go-ethereum/accounts/abi.Arguments).Pack(args ...interface{}) ([]byte, error)
(wrapcheck)
🪛 GitHub Check: Lint (services/rfq)
[failure] 315-315:
error returned from external package is unwrapped: sig: func (github.com/ethereum/go-ethereum/accounts/abi.Arguments).Pack(args ...interface{}) ([]byte, error) (wrapcheck)