interledger-pay icon indicating copy to clipboard operation
interledger-pay copied to clipboard

Request money sends `incomingAmount` in whole units, not minor units

Open linear[bot] opened this issue 1 month ago • 1 comments

Problem

On the Request page, the user types the amount in whole units, for example 10.50 for 10.50 EUR. The frontend sends this number unchanged (transfers.ts:43, amount: z.coerce.number()).

IncomingPaymentService.create also sends the number unchanged (incomingPayment/service.ts:86):

const response = await this.rhyzaAdminClient.createPaymentIntent({
  walletAddress: existingWalletAddress.url,
  incomingAmount: amount,
  ...
})

Rhyza reads incomingAmount in minor units of the wallet address's asset. For EUR at scale 2, 1000 is 10.00 EUR. Rhyza converts the value with BigInt() (aggregate.ts:462) and stores it as a uint64.

The Rafiki code before interledger/interledger-pay#101 (testnet#2257) scaled the amount:

amount: BigInt(amount * 10 ** asset.scale)

The read path in the same file divides by the scale. getPaymentDetailsByUrl calls transformAmount(value, scale) (incomingPayment/service.ts:104).

Impact

  • A request for 10 EUR creates a payment intent for 0.10 EUR. The payment intent completes after it receives 10 cents. The payer sees 0.10 EUR on the payment page.
  • A request for 10.50 EUR sends 10.5. This value is not a whole number of minor units. BigInt(10.5) throws an error in Rhyza. The request then probably fails with 500. This comes from the code; I did not run it.

The unit tests do not find this error. For an input of 100, they expect incomingAmount: 100 (service.test.ts:123, test "should create a payment intent and return its url").

Fix

  1. Multiply the amount by 10 ** scale, with the scale of the account's asset.
  2. Round the result to an integer, for example Math.round(amount * 10 ** scale). Rhyza's spec types incomingAmount as a number.
  3. Change the tests to expect the scaled value.
  4. Add a test with a fraction, for example 10.29.

Note: Do not use transformBalance (helpers.ts:24) for step 2. It rounds down a floating-point result. For example, 10.29 * 100 is 1028.9999…, and transformBalance gives 1028.

Found at

testnet v1 @ 71e6f304, Rhyza main @ 5e206fcf.

linear[bot] avatar Oct 30 '26 09:10 linear[bot]

Hey can I take this up?

addu2612 avatar Oct 30 '26 12:10 addu2612