diff --git a/packages/payment-processor/src/payment/swap-erc20-fee-proxy.ts b/packages/payment-processor/src/payment/swap-erc20-fee-proxy.ts index d03697fdc3..dcf7d8ba21 100644 --- a/packages/payment-processor/src/payment/swap-erc20-fee-proxy.ts +++ b/packages/payment-processor/src/payment/swap-erc20-fee-proxy.ts @@ -8,11 +8,13 @@ import { ITransactionOverrides } from './transaction-overrides'; import { getAmountToPay, getProvider, + getProxyAddress, getRequestPaymentValues, getSigner, validateErc20FeeProxyRequest, } from './utils'; import { IPreparedTransaction } from './prepared-transaction'; +import { Erc20PaymentNetwork } from '@requestnetwork/payment-detection'; /** * Details required for a token swap: @@ -131,10 +133,16 @@ export function encodeSwapToPayErc20FeeRequest( throw new Error('Request currency network is missing'); } + const feeProxyAddress = getProxyAddress( + request, + Erc20PaymentNetwork.ERC20FeeProxyPaymentDetector.getDeploymentInformation, + ); + const swapToPayAddress = erc20FeeProxyArtifact.getAddress(request.currencyInfo.network); const swapToPayContract = ERC20SwapToPay__factory.connect(swapToPayAddress, signer); return swapToPayContract.interface.encodeFunctionData('swapTransferWithReference', [ + feeProxyAddress, paymentAddress, amountToPay, swapSettings.maxInputAmount, diff --git a/packages/payment-processor/test/payment/encoder-payment.test.ts b/packages/payment-processor/test/payment/encoder-payment.test.ts index 8601cb3909..f3338b0ac7 100644 --- a/packages/payment-processor/test/payment/encoder-payment.test.ts +++ b/packages/payment-processor/test/payment/encoder-payment.test.ts @@ -318,7 +318,7 @@ describe('Payment encoder handles ERC20 Swap Proxy', () => { ); expect(paymentTransaction).toEqual({ - data: '0x8d09fe2b000000000000000000000000f17f52151ebef6c7334fad080c5704d77216b732000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000cc000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c5fdf4076b8f3a5357c5e395ab970b5b54098fef000000000000000000000000000000000000000000000000000000009af4c3db000000000000000000000000000000000000000000000000000000000000000200000000000000000000000038cf23c52bb4b13f051aec09580a2de845a7fa350000000000000000000000009fbda871d559710256a2502a2517b794b482db40000000000000000000000000000000000000000000000000000000000000000886dfbccad783599a000000000000000000000000000000000000000000000000', + data: '0x5f2993bf00000000000000000000000075c35c980c0d37ef46df04d31a140b65503c0eed000000000000000000000000f17f52151ebef6c7334fad080c5704d77216b732000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000cc000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c5fdf4076b8f3a5357c5e395ab970b5b54098fef000000000000000000000000000000000000000000000000000000009af4c3db000000000000000000000000000000000000000000000000000000000000000200000000000000000000000038cf23c52bb4b13f051aec09580a2de845a7fa350000000000000000000000009fbda871d559710256a2502a2517b794b482db40000000000000000000000000000000000000000000000000000000000000000886dfbccad783599a000000000000000000000000000000000000000000000000', to: proxyAddress, value: 0, }); diff --git a/packages/payment-processor/test/payment/swap-erc20-fee-proxy.test.ts b/packages/payment-processor/test/payment/swap-erc20-fee-proxy.test.ts index d395917041..a0d2a15342 100644 --- a/packages/payment-processor/test/payment/swap-erc20-fee-proxy.test.ts +++ b/packages/payment-processor/test/payment/swap-erc20-fee-proxy.test.ts @@ -57,7 +57,7 @@ const validRequest: ClientTypes.IRequestData = { paymentAddress, salt: 'salt', }, - version: '1.0', + version: '0.1.0', }, }, extensionsData: [], @@ -146,7 +146,7 @@ describe('swap-erc20-fee-proxy', () => { wallet, { deadline: 2599732187000, // This test will fail in 2052 - maxInputAmount: 204, + maxInputAmount: 206, path: [alphaErc20Address, erc20ContractAddress], }, { @@ -154,7 +154,7 @@ describe('swap-erc20-fee-proxy', () => { }, ); expect(spy).toHaveBeenCalledWith({ - data: '0x8d09fe2b000000000000000000000000f17f52151ebef6c7334fad080c5704d77216b732000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000cc000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c5fdf4076b8f3a5357c5e395ab970b5b54098fef000000000000000000000000000000000000000000000000000000009af4c3db000000000000000000000000000000000000000000000000000000000000000200000000000000000000000038cf23c52bb4b13f051aec09580a2de845a7fa350000000000000000000000009fbda871d559710256a2502a2517b794b482db40000000000000000000000000000000000000000000000000000000000000000886dfbccad783599a000000000000000000000000000000000000000000000000', + data: '0x5f2993bf00000000000000000000000075c35c980c0d37ef46df04d31a140b65503c0eed000000000000000000000000f17f52151ebef6c7334fad080c5704d77216b732000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000ce000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c5fdf4076b8f3a5357c5e395ab970b5b54098fef000000000000000000000000000000000000000000000000000000009af4c3db000000000000000000000000000000000000000000000000000000000000000200000000000000000000000038cf23c52bb4b13f051aec09580a2de845a7fa350000000000000000000000009fbda871d559710256a2502a2517b794b482db40000000000000000000000000000000000000000000000000000000000000000886dfbccad783599a000000000000000000000000000000000000000000000000', gasPrice: '20000000000', to: '0xA4392264a2d8c998901D10C154C91725b1BF0158', value: 0, @@ -191,8 +191,8 @@ describe('swap-erc20-fee-proxy', () => { // Swap and pay const tx = await swapErc20FeeProxyRequest(validRequest, wallet, { - deadline: Date.now() + 1000, - maxInputAmount: 204, + deadline: Date.now() + 10000, + maxInputAmount: 206, path: [alphaErc20Address, erc20ContractAddress], }); const confirmedTx = await tx.wait(1);