From 2022e1337009f85e2486c94e4afe83ab4f727771 Mon Sep 17 00:00:00 2001 From: Leo Sollier Date: Wed, 30 Apr 2025 19:01:54 +0200 Subject: [PATCH 1/2] chore(data-format): rnf invoice allow negative line items --- .../data-format/src/format/rnf_invoice/rnf_invoice-0.0.3.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-format/src/format/rnf_invoice/rnf_invoice-0.0.3.json b/packages/data-format/src/format/rnf_invoice/rnf_invoice-0.0.3.json index 55b4ec412c..0c903382e2 100644 --- a/packages/data-format/src/format/rnf_invoice/rnf_invoice-0.0.3.json +++ b/packages/data-format/src/format/rnf_invoice/rnf_invoice-0.0.3.json @@ -124,7 +124,7 @@ }, "unitPrice": { "type": "string", - "pattern": "^\\d+$" + "pattern": "^-?\\d+$" }, "discount": { "type": "string", From 7581f0bc652edaf278226c328e1699d6f64ea51e Mon Sep 17 00:00:00 2001 From: Leo Sollier Date: Fri, 16 May 2025 13:40:54 +0200 Subject: [PATCH 2/2] fix: safe eth requirements --- .../payment-processor/src/payment/index.ts | 2 +- .../test/payment/index.test.ts | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/payment-processor/src/payment/index.ts b/packages/payment-processor/src/payment/index.ts index 4bd6b57e2a..1db54b2283 100644 --- a/packages/payment-processor/src/payment/index.ts +++ b/packages/payment-processor/src/payment/index.ts @@ -271,7 +271,7 @@ export async function isSolvent({ const ethBalance = await provider.getBalance(fromAddress); if (currency.type === 'ETH') { - return ethBalance.gt(amount); + return needsGas ? ethBalance.gt(amount) : ethBalance.gte(amount); } else { const balance = await getCurrencyBalance(fromAddress, currency, provider); return (ethBalance.gt(0) || !needsGas) && BigNumber.from(balance).gte(amount); diff --git a/packages/payment-processor/test/payment/index.test.ts b/packages/payment-processor/test/payment/index.test.ts index 9dfff0014d..574544f3d6 100644 --- a/packages/payment-processor/test/payment/index.test.ts +++ b/packages/payment-processor/test/payment/index.test.ts @@ -34,6 +34,12 @@ const nearCurrency: RequestLogicTypes.ICurrency = { value: 'near', }; +const ethCurrency: RequestLogicTypes.ICurrency = { + type: RequestLogicTypes.CURRENCY.ETH, + network: 'mainnet', + value: 'ETH', +}; + describe('payRequest', () => { afterEach(() => { jest.resetAllMocks(); @@ -516,7 +522,7 @@ describe('hasSufficientFunds', () => { expect(solvency).toBeFalsy(); }); - it('should skip ETH balance checks when needsGas is false', async () => { + it('should skip ETH balance checks when needsGas is false - ERC20 payment', async () => { const mock = jest .spyOn(erc20Module, 'getAnyErc20Balance') .mockReturnValue(Promise.resolve(BigNumber.from('200'))); @@ -534,6 +540,34 @@ describe('hasSufficientFunds', () => { expect(mock).toHaveBeenCalledTimes(1); }); + it('should require only the given ETH amount when needsGas is false - ETH payment', async () => { + // eslint-disable-next-line no-magic-numbers + const solvency = await isSolvent({ + fromAddress: 'any', + currency: ethCurrency, + amount: 200, + providerOptions: { + provider: fakeProvider as any, + }, + needsGas: false, + }); + expect(solvency).toBeTruthy(); + }); + + it('should require an excess of ETH when needsGas is true - ETH payment', async () => { + // eslint-disable-next-line no-magic-numbers + const solvency = await isSolvent({ + fromAddress: 'any', + currency: ethCurrency, + amount: 200, + providerOptions: { + provider: fakeProvider as any, + }, + needsGas: true, + }); + expect(solvency).toBeFalsy(); + }); + it('should check ETH balance checks by default', async () => { const mock = jest .spyOn(erc20Module, 'getAnyErc20Balance')