diff --git a/packages/payment-processor/src/payment/single-request-proxy.ts b/packages/payment-processor/src/payment/single-request-proxy.ts index eb5e4f62b..17c1c2b2f 100644 --- a/packages/payment-processor/src/payment/single-request-proxy.ts +++ b/packages/payment-processor/src/payment/single-request-proxy.ts @@ -91,13 +91,17 @@ export async function deploySingleRequestProxy( const receipt = await tx.wait(); - const event = receipt.events?.[0]; + const event = receipt.events?.find( + (e) => + e.event === + (isERC20 ? 'ERC20SingleRequestProxyCreated' : 'EthereumSingleRequestProxyCreated'), + ); if (!event) { throw new Error('Single request proxy creation event not found'); } - const proxyAddress = ethers.utils.defaultAbiCoder.decode(['address', 'address'], event.data)[0]; + const proxyAddress = event.args?.proxyAddress || event.args?.[0]; if (!proxyAddress) { throw new Error('Proxy address not found in event data'); diff --git a/packages/payment-processor/test/payment/single-request-proxy.test.ts b/packages/payment-processor/test/payment/single-request-proxy.test.ts index 6f5cf0f27..7db5bb8f4 100644 --- a/packages/payment-processor/test/payment/single-request-proxy.test.ts +++ b/packages/payment-processor/test/payment/single-request-proxy.test.ts @@ -170,9 +170,7 @@ describe('deploySingleRequestProxy', () => { it('should deploy EthereumSingleRequestProxy and emit event', async () => { const singleRequestProxyFactory = singleRequestProxyFactoryArtifact.connect('private', wallet); - const initialEventCount = await provider.getBlockNumber(); - - const walletAddress = await wallet.getAddress(); + const initialBlock = await provider.getBlockNumber(); const proxyAddress = await deploySingleRequestProxy(ethRequest, wallet); @@ -183,23 +181,31 @@ describe('deploySingleRequestProxy', () => { const latestBlock = await provider.getBlockNumber(); const events = await singleRequestProxyFactory.queryFilter( singleRequestProxyFactory.filters.EthereumSingleRequestProxyCreated(), - initialEventCount, + initialBlock, latestBlock, ); expect(events.length).toBeGreaterThan(0); - const eventData = utils.defaultAbiCoder.decode(['address', 'address'], events[0].data); - - expect(eventData[0]).toBe(proxyAddress); + const event = events[0]; + expect(event.args?.proxyAddress).toBe(proxyAddress); + expect(event.args?.payee).toBe(ethRequest.payee?.value); + expect(event.args?.feeAddress).toBe( + ethRequest.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ETH_FEE_PROXY_CONTRACT].values + .feeAddress, + ); + expect(event.args?.feeAmount.toString()).toBe( + ethRequest.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ETH_FEE_PROXY_CONTRACT].values + .feeAmount, + ); + const feeProxyUsed = await singleRequestProxyFactory.ethereumFeeProxy(); + expect(event.args?.feeProxyUsed).toBe(feeProxyUsed); }); it('should deploy ERC20SingleRequestProxy and emit event', async () => { const singleRequestProxyFactory = singleRequestProxyFactoryArtifact.connect('private', wallet); - const initialEventCount = await provider.getBlockNumber(); - - const walletAddress = await wallet.getAddress(); + const initialBlock = await provider.getBlockNumber(); const proxyAddress = await deploySingleRequestProxy(erc20Request, wallet); @@ -210,15 +216,26 @@ describe('deploySingleRequestProxy', () => { const latestBlock = await provider.getBlockNumber(); const events = await singleRequestProxyFactory.queryFilter( singleRequestProxyFactory.filters.ERC20SingleRequestProxyCreated(), - initialEventCount, + initialBlock, latestBlock, ); expect(events.length).toBeGreaterThan(0); - const eventData = utils.defaultAbiCoder.decode(['address', 'address'], events[0].data); - - expect(eventData[0]).toBe(proxyAddress); + const event = events[0]; + expect(event.args?.proxyAddress).toBe(proxyAddress); + expect(event.args?.payee).toBe(erc20Request.payee?.value); + expect(event.args?.tokenAddress).toBe(erc20Request.currencyInfo.value); + expect(event.args?.feeAddress).toBe( + erc20Request.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_FEE_PROXY_CONTRACT].values + .feeAddress, + ); + expect(event.args?.feeAmount.toString()).toBe( + erc20Request.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_FEE_PROXY_CONTRACT].values + .feeAmount, + ); + const feeProxyUsed = await singleRequestProxyFactory.erc20FeeProxy(); + expect(event.args?.feeProxyUsed).toBe(feeProxyUsed); }); it('should throw error when trying to pay with invalid single request proxy', async () => { diff --git a/packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol b/packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol index c2cf1b534..69223555b 100644 --- a/packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol +++ b/packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol @@ -13,24 +13,24 @@ import './lib/SafeERC20.sol'; contract ERC20SingleRequestProxy { address public payee; address public tokenAddress; + bytes public paymentReference; address public feeAddress; uint256 public feeAmount; - bytes public paymentReference; IERC20FeeProxy public erc20FeeProxy; constructor( address _payee, address _tokenAddress, + bytes memory _paymentReference, address _feeAddress, uint256 _feeAmount, - bytes memory _paymentReference, address _erc20FeeProxy ) { payee = _payee; tokenAddress = _tokenAddress; + paymentReference = _paymentReference; feeAddress = _feeAddress; feeAmount = _feeAmount; - paymentReference = _paymentReference; erc20FeeProxy = IERC20FeeProxy(_erc20FeeProxy); } diff --git a/packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol b/packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol index 03d8752da..259e62233 100644 --- a/packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol +++ b/packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol @@ -30,9 +30,9 @@ contract EthereumSingleRequestProxy { constructor( address _payee, bytes memory _paymentReference, - address _ethereumFeeProxy, address _feeAddress, - uint256 _feeAmount + uint256 _feeAmount, + address _ethereumFeeProxy ) { payee = _payee; paymentReference = _paymentReference; diff --git a/packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol b/packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol index 6ac89e9d9..55c99c035 100644 --- a/packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol +++ b/packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol @@ -21,14 +21,20 @@ contract SingleRequestProxyFactory is Ownable { event EthereumSingleRequestProxyCreated( address proxyAddress, address payee, - bytes indexed paymentReference + bytes indexed paymentReference, + address feeAddress, + uint256 feeAmount, + address feeProxyUsed ); event ERC20SingleRequestProxyCreated( address proxyAddress, address payee, address tokenAddress, - bytes indexed paymentReference + bytes indexed paymentReference, + address feeAddress, + uint256 feeAmount, + address feeProxyUsed ); event ERC20FeeProxyUpdated(address indexed newERC20FeeProxy); @@ -60,11 +66,18 @@ contract SingleRequestProxyFactory is Ownable { EthereumSingleRequestProxy proxy = new EthereumSingleRequestProxy( _payee, _paymentReference, - ethereumFeeProxy, _feeAddress, - _feeAmount + _feeAmount, + ethereumFeeProxy + ); + emit EthereumSingleRequestProxyCreated( + address(proxy), + _payee, + _paymentReference, + _feeAddress, + _feeAmount, + ethereumFeeProxy ); - emit EthereumSingleRequestProxyCreated(address(proxy), _payee, _paymentReference); return address(proxy); } @@ -87,13 +100,21 @@ contract SingleRequestProxyFactory is Ownable { ERC20SingleRequestProxy proxy = new ERC20SingleRequestProxy( _payee, _tokenAddress, + _paymentReference, _feeAddress, _feeAmount, - _paymentReference, erc20FeeProxy ); - emit ERC20SingleRequestProxyCreated(address(proxy), _payee, _tokenAddress, _paymentReference); + emit ERC20SingleRequestProxyCreated( + address(proxy), + _payee, + _tokenAddress, + _paymentReference, + _feeAddress, + _feeAmount, + erc20FeeProxy + ); return address(proxy); } diff --git a/packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json b/packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json index e5aae47dc..d2b1b9f61 100644 --- a/packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json +++ b/packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json @@ -60,6 +60,24 @@ "internalType": "bytes", "name": "paymentReference", "type": "bytes" + }, + { + "indexed": false, + "internalType": "address", + "name": "feeAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "feeAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "feeProxyUsed", + "type": "address" } ], "name": "ERC20SingleRequestProxyCreated", @@ -98,6 +116,24 @@ "internalType": "bytes", "name": "paymentReference", "type": "bytes" + }, + { + "indexed": false, + "internalType": "address", + "name": "feeAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "feeAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "feeProxyUsed", + "type": "address" } ], "name": "EthereumSingleRequestProxyCreated", diff --git a/packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts b/packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts index 43493b04b..6eed98ac9 100644 --- a/packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts +++ b/packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts @@ -14,8 +14,8 @@ export const singleRequestProxyFactoryArtifact = new ContractArtifact { erc20SingleRequestProxy = await new ERC20SingleRequestProxy__factory(deployer).deploy( user2Addr, testToken.address, + paymentReference, feeRecipientAddr, feeAmount, - paymentReference, erc20FeeProxy.address, ); @@ -156,9 +156,9 @@ describe('contract: ERC20SingleRequestProxy', () => { const usdtProxy = await new ERC20SingleRequestProxy__factory(deployer).deploy( user2Addr, usdtFake.address, + paymentReference, feeRecipientAddr, usdtFeeAmount, - paymentReference, erc20FeeProxy.address, ); @@ -210,9 +210,9 @@ describe('contract: ERC20SingleRequestProxy', () => { const zeroFeeProxy = await new ERC20SingleRequestProxy__factory(deployer).deploy( user2Addr, testToken.address, + paymentReference, feeRecipientAddr, 0, - paymentReference, erc20FeeProxy.address, ); diff --git a/packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts b/packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts index 7cb7982e5..90d370a61 100644 --- a/packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts +++ b/packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts @@ -30,9 +30,9 @@ describe('contract : EthereumSingleRequestProxy', () => { ethereumSingleRequestProxy = await ethereumSingleRequestProxyFactory.deploy( payeeAddress, paymentReference, - ethereumFeeProxy.address, feeRecipientAddress, feeAmount, + ethereumFeeProxy.address, ); await ethereumSingleRequestProxy.deployed(); }); @@ -87,9 +87,9 @@ describe('contract : EthereumSingleRequestProxy', () => { const newEthereumSingleRequestProxy = await newEthereumSingleRequestProxyFactory.deploy( payeeAddress, paymentReference, - mockEthereumFeeProxy.address, feeRecipientAddress, feeAmount, + mockEthereumFeeProxy.address, ); await newEthereumSingleRequestProxy.deployed(); diff --git a/packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts b/packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts index 707e5db21..3d5d3328b 100644 --- a/packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts +++ b/packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts @@ -83,10 +83,16 @@ describe('contract: SingleRequestProxyFactory', () => { expect(proxyAddress).to.not.equal(ethers.constants.AddressZero); expect(proxyAddress).to.be.properAddress; - // Check if the event was emitted with correct parameters await expect(tx) .to.emit(singleRequestProxyFactory, 'EthereumSingleRequestProxyCreated') - .withArgs(proxyAddress, payeeAddress, paymentReference); + .withArgs( + proxyAddress, + payeeAddress, + paymentReference, + feeRecipientAddress, + feeAmount, + ethereumFeeProxy.address, + ); const proxy = (await ethers.getContractAt( 'EthereumSingleRequestProxy', @@ -119,10 +125,17 @@ describe('contract: SingleRequestProxyFactory', () => { expect(proxyAddress).to.not.equal(ethers.constants.AddressZero); expect(proxyAddress).to.be.properAddress; - // Check if the event was emitted with correct parameters await expect(tx) .to.emit(singleRequestProxyFactory, 'ERC20SingleRequestProxyCreated') - .withArgs(proxyAddress, payeeAddress, testToken.address, paymentReference); + .withArgs( + proxyAddress, + payeeAddress, + testToken.address, + paymentReference, + feeRecipientAddress, + feeAmount, + erc20FeeProxy.address, + ); const proxy = (await ethers.getContractAt( 'ERC20SingleRequestProxy',