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

feat: use payment manager handler in quote service #1994

Merged
merged 18 commits into from
Oct 9, 2023

Conversation

mkurapov
Copy link
Contributor

@mkurapov mkurapov commented Oct 6, 2023

Changes proposed in this pull request

  • Abstracts away ILP-specific details during quoteService.create by using paymentMethodHandlerService.getQuote
  • Minor refactoring of quote service
    -Adding additionalFields to the quote model for storing method-specific information that may need to be stored in between quoting and transfers (like the ILP maxPacketAmount and exchangeRate info)

Context

Progress towards #1967

In the previous PR, #1974, the PaymentMethodHandlerService was introduced, but not used by anything. In this PR, quoteService will now use this service to get a quote, without needing to know exactly how an "ILP" quote happens.

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass
  • Postman collection updated

@github-actions github-actions bot added type: tests Testing related pkg: backend Changes in the backend package. type: source Changes business logic labels Oct 6, 2023
@mkurapov mkurapov marked this pull request as ready for review October 6, 2023 16:54
assetScale: receiver.assetScale
},
debitAmount: quote.debitAmount,
receiveAmount: quote.receiveAmount,
// Cap at MAX_INT64 because of postgres type limits.
maxPacketAmount:
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on refactoring Quote so that ILP-related fields are more delineated from "base" quote stuff? I was thinking it might help keep the amount of columns in quote reasonable when other payment methods become supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Base automatically changed from mk/1967/payment-manager-service to main October 6, 2023 23:27
# Conflicts:
#	packages/backend/src/index.ts
@netlify
Copy link

netlify bot commented Oct 6, 2023

Deploy Preview for brilliant-pasca-3e80ec ready!

Name Link
🔨 Latest commit e1d5215
🔍 Latest deploy log https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/652427e18948c2000747c89b
😎 Deploy Preview https://deploy-preview-1994--brilliant-pasca-3e80ec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mkurapov mkurapov requested a review from njlie October 9, 2023 08:18
*/
exports.up = function (knex) {
return knex.schema.alterTable('quotes', (table) => {
table.json('additionalFields').nullable()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be temporary until ilp related stuff is migrated in #2000?

otherwise I'm concerned about the schemaless-ness of jsonb

Copy link
Contributor Author

@mkurapov mkurapov Oct 9, 2023

Choose a reason for hiding this comment

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

Long term, temporary. I need to determine what non generic items are needed for the mojaloop quote, and decide how to store those as well. I imagine we end up having a separate tables for method-specific quoting/transfer properties

Comment on lines +476 to +487
${1000} | ${0} | ${0} | ${1000n} | ${'no fees'}
${1000n} | ${150} | ${0} | ${1150n} | ${'fixed fee'}
${1000n} | ${0} | ${200} | ${1020n} | ${'basis point fee'}
${1000n} | ${150} | ${200} | ${1170n} | ${'fixed and basis point fee'}
`(
'$description',
withConfigOverride(
() => config,
{ slippage: 0 },
async ({
incomingAmountValue,
fixedFee,
basisPointFee,
expectedQuoteDebitAmountValue
}): Promise<void> => {
const incomingPayment = await createIncomingPayment(deps, {
paymentPointerId: receivingPaymentPointer.id,
incomingAmount: {
assetCode: asset.code,
assetScale: asset.scale,
value: incomingAmountValue
}
})
await Fee.query().insertAndFetch({
assetId: asset.id,
type: FeeType.Sending,
fixedFee,
basisPointFee
})

const quote = await quoteService.create({
paymentPointerId: sendingPaymentPointer.id,
receiver: incomingPayment.getUrl(receivingPaymentPointer)
})
assert.ok(!isQuoteError(quote))

expect(quote.debitAmount).toEqual({
async ({
incomingAmountValue,
fixedFee,
basisPointFee,
expectedQuoteDebitAmountValue
}): Promise<void> => {
Copy link
Contributor

@BlairCurrey BlairCurrey Oct 9, 2023

Choose a reason for hiding this comment

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

Can you elaborate on how there isnt an off by one issue here? Did we gain any insight into that issue?

As I recall the default slippage introduced some variance in this test and manual tests (via postman), which is why I tried to test without slippage originally. Although it appears that using the default slippage doesnt modify the values at all here and there is no off by one issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is because the actual quote itself is mocked, there's no actual ILP quoting happening here. The off-by-one issue was demonstrated in the other PR: #1974 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

aha, makes sense. Good, glad there is something preserving that issue.

BlairCurrey
BlairCurrey previously approved these changes Oct 9, 2023
@mkurapov mkurapov merged commit 064c22f into main Oct 9, 2023
23 checks passed
@mkurapov mkurapov deleted the mk/1967/use-payment-method-handler-quoting branch October 9, 2023 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants