Skip to content
Merged
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
13 changes: 7 additions & 6 deletions tools/preconf-rpc/fastswap/fastswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ func (s *Service) callBarter(ctx context.Context, reqBody barterRequest, logDesc
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", s.barterAPIKey))

s.logger.Debug("calling Barter API",
s.logger.Info("calling Barter API",
"type", logDescription,
"url", s.barterBaseURL+"/swap",
"source", reqBody.Source,
"target", reqBody.Target,
"sellAmount", reqBody.SellAmount,
"inputToken", reqBody.Source,
"outputToken", reqBody.Target,
"inputAmount", reqBody.SellAmount,
"outputAmount", reqBody.MinReturn,
)

resp, err := s.httpClient.Do(req)
Expand Down Expand Up @@ -384,7 +384,8 @@ func (s *Service) HandleSwap(ctx context.Context, req SwapRequest) (*SwapResult,
nextBaseFee = big.NewInt(30_000_000_000) // 30 gwei fallback
}
gasTipCap := big.NewInt(0) // No priority fee - mev-commit bid handles inclusion
gasFeeCap := nextBaseFee // GasFeeCap = BaseFee (tip is 0)
// add buffer to fee cap to account for changes
gasFeeCap := new(big.Int).Mul(nextBaseFee, big.NewInt(2))

// 6. Build the transaction
chainID := big.NewInt(int64(s.chainID))
Expand Down
18 changes: 18 additions & 0 deletions tools/preconf-rpc/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type Store interface {
DeductBalance(ctx context.Context, account common.Address, amount *big.Int) error
StoreTransaction(ctx context.Context, txn *Transaction, commitments []*bidderapiv1.Commitment, logs []*types.Log) error
GetTransactionByHash(ctx context.Context, txnHash common.Hash) (*Transaction, error)
StoreReceipt(ctx context.Context, receipt *types.Receipt) error
}

type Bidder interface {
Expand Down Expand Up @@ -579,6 +580,23 @@ func (t *TxSender) processQueuedTransactions(ctx context.Context) {
txn.Status = TxStatusFailed
txn.Details = err.Error()
t.clearBlockAttemptHistory(txn, time.Now())

// Store a failed receipt to unblock the user's wallet
receipt := &types.Receipt{
Type: txn.Transaction.Type(),
Status: types.ReceiptStatusFailed,
TxHash: txn.Hash(),
ContractAddress: common.Address{},
GasUsed: 0, // 0 since no execution happened
CumulativeGasUsed: 0,
BlockHash: common.Hash{}, // Pending/Unknown
BlockNumber: big.NewInt(0), // Pending/Unknown
TransactionIndex: 0,
}
if storeErr := t.store.StoreReceipt(ctx, receipt); storeErr != nil {
t.logger.Error("Failed to store failed receipt", "error", storeErr)
}

defer t.signalReceiptAvailable(txn.Hash())
return t.store.StoreTransaction(ctx, txn, nil, nil)
}
Expand Down
7 changes: 7 additions & 0 deletions tools/preconf-rpc/sender/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ func (m *mockStore) GetTransactionByHash(
return txn, nil
}

func (m *mockStore) StoreReceipt(
ctx context.Context,
receipt *types.Receipt,
) error {
return nil
}

type bidOp struct {
bidAmount *big.Int
slashAmount *big.Int
Expand Down
Loading