Skip to content

Commit

Permalink
add DepositAmount to QuoteInput, incorporate into getOriginAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
parodime committed Nov 6, 2024
1 parent f2f1139 commit 6808eb0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions services/rfq/relayer/quoter/quoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,20 @@ func (m *Manager) generateActiveRFQ(ctx context.Context, msg *model.ActiveRFQMes
}
span.SetAttributes(attribute.String("request_id", rfqRequest.RequestID))

depositAmount := new(big.Int)
depositAmount, ok := depositAmount.SetString(rfqRequest.Data.OriginAmount, 10) // base 10 for decimal
if !ok {
return nil, fmt.Errorf("invalid rfq request deposit amount: %s", rfqRequest.Data.OriginAmount)
}

Check warning on line 371 in services/rfq/relayer/quoter/quoter.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/quoter/quoter.go#L367-L371

Added lines #L367 - L371 were not covered by tests

quoteInput := QuoteInput{
OriginChainID: rfqRequest.Data.OriginChainID,
DestChainID: rfqRequest.Data.DestChainID,
OriginTokenAddr: common.HexToAddress(rfqRequest.Data.OriginTokenAddr),
DestTokenAddr: common.HexToAddress(rfqRequest.Data.DestTokenAddr),
OriginBalance: inv[rfqRequest.Data.OriginChainID][common.HexToAddress(rfqRequest.Data.OriginTokenAddr)],
DestBalance: inv[rfqRequest.Data.DestChainID][common.HexToAddress(rfqRequest.Data.DestTokenAddr)],
DepositAmount: depositAmount,

Check warning on line 380 in services/rfq/relayer/quoter/quoter.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/quoter/quoter.go#L380

Added line #L380 was not covered by tests
}

rawQuote, err := m.generateQuote(ctx, quoteInput)
Expand Down Expand Up @@ -540,6 +547,7 @@ func (m *Manager) generateQuotes(parentCtx context.Context, chainID int, address
OriginBalance: originBalance,
DestBalance: balance,
DestRFQAddr: destRFQAddr.Hex(),
DepositAmount: nil,
}

quote, quoteErr := m.generateQuote(gctx, input)
Expand Down Expand Up @@ -576,6 +584,7 @@ type QuoteInput struct {
DestTokenAddr common.Address
OriginBalance *big.Int
DestBalance *big.Int
DepositAmount *big.Int
DestRFQAddr string
}

Expand Down Expand Up @@ -764,6 +773,20 @@ func (m *Manager) getOriginAmount(parentCtx context.Context, input QuoteInput) (
return nil, fmt.Errorf("error deducting gas cost: %w", err)
}

// If input included a depositAmount, and our calculated quoteAmount is sufficient to cover it,
// then clip to the depositAmount. Otherwise return 0 to indicate inability to cover the requested amount.
if input.DepositAmount != nil {
if quoteAmount.Cmp(input.DepositAmount) >= 0 {
quoteAmount = input.DepositAmount
} else {
span.AddEvent("quote amount insufficient to cover deposit amount", trace.WithAttributes(
attribute.String("quote_amount", quoteAmount.String()),
attribute.String("deposit_amount", input.DepositAmount.String()),
))
quoteAmount = big.NewInt(0)
}

Check warning on line 787 in services/rfq/relayer/quoter/quoter.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/quoter/quoter.go#L779-L787

Added lines #L779 - L787 were not covered by tests
}

return quoteAmount, nil
}

Expand Down

0 comments on commit 6808eb0

Please sign in to comment.