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

activeQuote depositAmount [SLT-464] #3372

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
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
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 @@
}
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
parodime marked this conversation as resolved.
Show resolved Hide resolved

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 @@
OriginBalance: originBalance,
DestBalance: balance,
DestRFQAddr: destRFQAddr.Hex(),
DepositAmount: nil,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor nit: let's add a small comment explaining why this is nil.

}

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

Expand Down Expand Up @@ -764,6 +773,20 @@
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add some cases for this in TestGetOriginAmount

}

return quoteAmount, nil
}

Expand Down
Loading