Skip to content

Commit

Permalink
Merge branch 'main' into mk/1999/ilp-peers
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurapov committed Oct 17, 2023
2 parents 416afe8 + 8405951 commit 393cc11
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
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()

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

if (receiveAmountValue <= exchangeAdjustedFees) {
Expand Down

0 comments on commit 393cc11

Please sign in to comment.