Skip to content

Commit

Permalink
Merge branch 'bc/1639/add-fees-to-quote' into mk/1802/accept-peering-…
Browse files Browse the repository at this point in the history
…request
  • Loading branch information
mkurapov committed Sep 14, 2023
2 parents 9619132 + db49061 commit 8fb0154
Show file tree
Hide file tree
Showing 62 changed files with 938 additions and 1,006 deletions.
1 change: 0 additions & 1 deletion infrastructure/helm/rafiki/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ rafiki-backend:
PAYMENT_POINTER_URL: http://rafiki-rafiki-backend/.well-known/pay
WEBHOOK_URL: http://cloud-nine-wallet/webhooks
EXCHANGE_RATES_URL: http://cloud-nine-wallet/prices
QUOTE_URL: http://cloud-nine-wallet/quotes
AUTH_SERVER_GRANT_URL: http://rafiki-rafiki-auth:3006
AUTH_SERVER_INTROSPECTION_URL: http://rafiki-rafiki-auth:3007
redis:
Expand Down
1 change: 0 additions & 1 deletion localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ services:
WEBHOOK_URL: http://cloud-nine-wallet/webhooks
EXCHANGE_RATES_URL: http://cloud-nine-wallet/rates
REDIS_URL: redis://shared-redis:6379/0
QUOTE_URL: http://cloud-nine-wallet/quotes
PAYMENT_POINTER_URL: https://cloud-nine-wallet-backend/.well-known/pay
depends_on:
- shared-database
Expand Down
1 change: 0 additions & 1 deletion localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ services:
OPEN_PAYMENTS_URL: http://happy-life-bank-backend
EXCHANGE_RATES_URL: http://happy-life-bank/rates
REDIS_URL: redis://shared-redis:6379/1
QUOTE_URL: http://happy-life-bank/quotes
PAYMENT_POINTER_URL: https://happy-life-bank-backend/.well-known/pay
depends_on:
- cloud-nine-backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export async function getPaymentPointerPayments(
id
state
error
sendAmount {
debitAmount {
value
assetCode
assetScale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export async function getAccountTransactions(
id: node.id,
receiver: node.receiver,
metadata: node.metadata,
sendAmountValue: node.sendAmount.value,
debitAmountValue: node.debitAmount.value,
amountValue: node.sentAmount.value,
receiveAmount: node.receiveAmount,
assetCode: node.sendAmount.assetCode,
assetScale: node.sendAmount.assetScale,
assetCode: node.debitAmount.assetCode,
assetScale: node.debitAmount.assetScale,
state: node.state,
createdAt: node.createdAt,
type: TransactionType.OutgoingPayment
Expand Down
2 changes: 1 addition & 1 deletion localenv/mock-account-servicing-entity/app/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface PaymentAmount {

export interface AccessLimit {
receiver: string
sendAmount?: PaymentAmount
debitAmount?: PaymentAmount
receiveAmount?: PaymentAmount
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export async function handleOutgoingPaymentCompletedFailed(wh: WebHook) {
throw new Error('No account found for payment pointer')
}

const amtSend = parseAmount(payment['sendAmount'])
const amtDebit = parseAmount(payment['debitAmount'])
const amtSent = parseAmount(payment['sentAmount'])

const toVoid = amtSend.value - amtSent.value
const toVoid = amtDebit.value - amtSent.value

await mockAccounts.debit(acc.id, amtSent.value, true)
if (toVoid > 0) {
Expand All @@ -86,7 +86,7 @@ export async function handleOutgoingPaymentCreated(wh: WebHook) {
throw new Error('No account found for payment pointer')
}

const amt = parseAmount(payment['sendAmount'])
const amt = parseAmount(payment['debitAmount'])

await mockAccounts.pendingDebit(acc.id, amt.value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,19 @@ export default function ConsentScreen() {
returnUrlObject.searchParams.append(
'currencyDisplayCode',
outgoingPaymentAccess && outgoingPaymentAccess.limits
? outgoingPaymentAccess.limits.sendAmount.assetCode
? outgoingPaymentAccess.limits.debitAmount.assetCode
: null
)
returnUrlObject.searchParams.append(
'sendAmountValue',
outgoingPaymentAccess && outgoingPaymentAccess.limits
? outgoingPaymentAccess.limits.sendAmount.value
? outgoingPaymentAccess.limits.debitAmount.value
: null
)
returnUrlObject.searchParams.append(
'sendAmountScale',
outgoingPaymentAccess && outgoingPaymentAccess.limits
? outgoingPaymentAccess.limits.sendAmount.assetScale
? outgoingPaymentAccess.limits.debitAmount.assetScale
: null
)
setCtx({
Expand Down Expand Up @@ -339,10 +339,10 @@ export default function ConsentScreen() {
) {
if (
ctx.outgoingPaymentAccess.limits &&
ctx.outgoingPaymentAccess.limits.sendAmount &&
ctx.outgoingPaymentAccess.limits.debitAmount &&
ctx.outgoingPaymentAccess.limits.receiveAmount
) {
const { receiveAmount, sendAmount } = ctx.outgoingPaymentAccess.limits
const { receiveAmount, debitAmount } = ctx.outgoingPaymentAccess.limits
setCtx({
...ctx,
price: {
Expand All @@ -353,8 +353,8 @@ export default function ConsentScreen() {
},
costToUser: {
amount:
Number(sendAmount.value) / Math.pow(10, sendAmount.assetScale),
currencyDisplayCode: sendAmount.assetCode
Number(debitAmount.value) / Math.pow(10, debitAmount.assetScale),
currencyDisplayCode: debitAmount.assetCode
}
})
} else {
Expand Down
10 changes: 5 additions & 5 deletions localenv/mock-account-servicing-entity/app/routes/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type Quote = {
paymentType: PaymentType
paymentPointerId: string
receiver: string
sendAmount: Amount
debitAmount: Amount
receiveAmount: Amount
maxPacketAmount: number // bigint
minExchangeRate: number
Expand All @@ -37,16 +37,16 @@ export async function action({ request }: ActionArgs) {

if (receivedQuote.paymentType == PaymentType.FixedDelivery) {
// TODO: handle quote fee calculation for different assets
if (!supportedAssets.includes(receivedQuote.sendAmount.assetCode)) {
if (!supportedAssets.includes(receivedQuote.debitAmount.assetCode)) {
throw json('Invalid quote sendAmount asset', { status: 400 })
}
const sendAmountValue = BigInt(receivedQuote.sendAmount.value)
const sendAmountValue = BigInt(receivedQuote.debitAmount.value)
const fees =
// TODO: bigint/float multiplication
BigInt(Math.floor(Number(sendAmountValue) * fee.percentage)) +
BigInt(fee.fixed * Math.pow(10, receivedQuote.sendAmount.assetScale))
BigInt(fee.fixed * Math.pow(10, receivedQuote.debitAmount.assetScale))

receivedQuote.sendAmount.value = (sendAmountValue + fees).toString()
receivedQuote.debitAmount.value = (sendAmountValue + fees).toString()
} else if (receivedQuote.paymentType === PaymentType.FixedSend) {
if (!supportedAssets.includes(receivedQuote.receiveAmount.assetCode)) {
throw json('Invalid quote receiveAmount asset', { status: 400 })
Expand Down
16 changes: 8 additions & 8 deletions localenv/mock-account-servicing-entity/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion openapi/auth-server.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.1.0
info:
title: Open Payments Authorization Server
version: '1.0'
version: '1.1'
license:
name: Apache 2.0
identifier: Apache-2.0
Expand Down Expand Up @@ -516,8 +516,10 @@ components:
receiver:
$ref: './schemas.yaml#/components/schemas/receiver'
debitAmount:
description: 'All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant.'
$ref: './schemas.yaml#/components/schemas/amount'
receiveAmount:
description: 'All amounts are maxima, i.e. multiple payments can be created under a grant as long as the total amounts of these payments do not exceed the maximum amount per interval as specified in the grant.'
$ref: './schemas.yaml#/components/schemas/amount'
interval:
$ref: '#/components/schemas/interval'
Expand Down
Loading

0 comments on commit 8fb0154

Please sign in to comment.