Skip to content

Commit

Permalink
Feat: quoter submits bulk quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Jul 5, 2024
1 parent 7eb7089 commit cc5624c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
53 changes: 39 additions & 14 deletions services/rfq/relayer/quoter/quoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,31 @@ func (m *Manager) prepareAndSubmitQuotes(ctx context.Context, inv map[int]map[co
span.SetAttributes(attribute.Int("num_quotes", len(allQuotes)))

// Now, submit all the generated quotes
for _, quote := range allQuotes {
if err := m.submitQuote(ctx, quote); err != nil {
span.AddEvent("error submitting quote; setting relayPaused to true", trace.WithAttributes(
attribute.String("error", err.Error()),
attribute.Int(metrics.Origin, quote.OriginChainID),
attribute.Int(metrics.Destination, quote.DestChainID),
attribute.String("origin_token_addr", quote.OriginTokenAddr),
attribute.String("dest_token_addr", quote.DestTokenAddr),
attribute.String("max_origin_amount", quote.MaxOriginAmount),
attribute.String("dest_amount", quote.DestAmount),
))
if m.config.SubmitSingleQuotes {
for _, quote := range allQuotes {
if err := m.submitQuote(ctx, quote); err != nil {
span.AddEvent("error submitting quote; setting relayPaused to true", trace.WithAttributes(
attribute.String("error", err.Error()),
attribute.Int(metrics.Origin, quote.OriginChainID),
attribute.Int(metrics.Destination, quote.DestChainID),
attribute.String("origin_token_addr", quote.OriginTokenAddr),
attribute.String("dest_token_addr", quote.DestTokenAddr),
attribute.String("max_origin_amount", quote.MaxOriginAmount),
attribute.String("dest_amount", quote.DestAmount),
))
m.relayPaused.Store(true)

// Suppress error so that we can continue submitting quotes
return nil
}
}
} else {
err = m.submitBulkQuotes(ctx, allQuotes)
if err != nil {
span.AddEvent("error submitting bulk quotes; setting relayPaused to true", trace.WithAttributes(
attribute.String("error", err.Error())))
m.relayPaused.Store(true)

// Suppress error so that we can continue submitting quotes
return nil
return fmt.Errorf("error submitting bulk quotes: %w", err)
}
}

Expand Down Expand Up @@ -600,3 +610,18 @@ func (m *Manager) submitQuote(ctx context.Context, quote model.PutQuoteRequest)
}
return nil
}

// Submits a single quote.
func (m *Manager) submitBulkQuotes(ctx context.Context, quotes []model.PutQuoteRequest) error {
quoteCtx, quoteCancel := context.WithTimeout(ctx, m.config.GetQuoteSubmissionTimeout())
defer quoteCancel()

req := model.PutBulkQuotesRequest{
Quotes: quotes,
}
err := m.rfqClient.PutBulkQuotes(quoteCtx, &req)
if err != nil {
return fmt.Errorf("error submitting bulk quotes: %w", err)
}
return nil
}
2 changes: 2 additions & 0 deletions services/rfq/relayer/relconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type Config struct {
EnableAPIWithdrawals bool `yaml:"enable_api_withdrawals"`
// WithdrawalWhitelist is a list of addresses that are allowed to withdraw.
WithdrawalWhitelist []string `yaml:"withdrawal_whitelist"`
// SubmitSingleQuotes enables submitting single quotes.
SubmitSingleQuotes bool `yaml:"submit_single_quotes"`
}

// ChainConfig represents the configuration for a chain.
Expand Down

0 comments on commit cc5624c

Please sign in to comment.