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

chore: make estimatedExchangeRate nullable (for now) #2039

Merged
merged 1 commit into from
Oct 17, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
exports.up = function (knex) {
return knex.schema.alterTable('quotes', (table) => {
table.json('additionalFields').nullable()
table.decimal('estimatedExchangeRate', 20, 10).notNullable()
table.decimal('estimatedExchangeRate', 20, 10).nullable()
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/open_payments/quote/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Quote extends PaymentPointerSubresource {
public asset!: Asset
public additionalFields!: Record<string, unknown>

public estimatedExchangeRate!: number
public estimatedExchangeRate?: number
public feeId?: string
public fee?: Fee

Expand Down
7 changes: 4 additions & 3 deletions packages/backend/src/open_payments/quote/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ function calculateQuoteAmountsAfterFees(
} else {
// FixedSend
const fees = quote.fee?.calculate(receiveAmountValue) ?? 0n
const exchangeAdjustedFees = BigInt(
Number(fees) * quote.estimatedExchangeRate.valueOf()
)
const estimatedExchangeRate =
quote.estimatedExchangeRate || quote.lowEstimatedExchangeRate.valueOf()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fallback to lowEstimatedExchangeRate (until #2000)


const exchangeAdjustedFees = BigInt(Number(fees) * estimatedExchangeRate)
receiveAmountValue = BigInt(receiveAmountValue) - exchangeAdjustedFees

if (receiveAmountValue <= exchangeAdjustedFees) {
Expand Down