Skip to content

Commit 93279f2

Browse files
committed
chore: update event handling for deployment
1 parent 35e327c commit 93279f2

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed

packages/payment-processor/src/payment/single-request-proxy.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ export async function deploySingleRequestProxy(
9191

9292
const receipt = await tx.wait();
9393

94-
const event = receipt.events?.[0];
94+
const event = receipt.events?.find(
95+
(e) =>
96+
e.event ===
97+
(isERC20 ? 'ERC20SingleRequestProxyCreated' : 'EthereumSingleRequestProxyCreated'),
98+
);
9599

96100
if (!event) {
97101
throw new Error('Single request proxy creation event not found');
98102
}
99103

100-
const proxyAddress = ethers.utils.defaultAbiCoder.decode(['address', 'address'], event.data)[0];
104+
const proxyAddress = event.args?.proxyAddress || event.args?.[0];
101105

102106
if (!proxyAddress) {
103107
throw new Error('Proxy address not found in event data');

packages/payment-processor/test/payment/single-request-proxy.test.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,19 @@ describe('deploySingleRequestProxy', () => {
187187

188188
expect(events.length).toBeGreaterThan(0);
189189

190-
const eventData = utils.defaultAbiCoder.decode(
191-
['address', 'address', 'address', 'uint256', 'address'],
192-
events[0].data,
193-
);
194-
195-
expect(eventData[0]).toBe(proxyAddress);
196-
expect(eventData[1]).toBe(ethRequest.payee?.value);
197-
expect(eventData[2]).toBe(
190+
const event = events[0];
191+
expect(event.args?.proxyAddress).toBe(proxyAddress);
192+
expect(event.args?.payee).toBe(ethRequest.payee?.value);
193+
expect(event.args?.feeAddress).toBe(
198194
ethRequest.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ETH_FEE_PROXY_CONTRACT].values
199195
.feeAddress,
200196
);
201-
expect(eventData[3]).toBe(
197+
expect(event.args?.feeAmount.toString()).toBe(
202198
ethRequest.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ETH_FEE_PROXY_CONTRACT].values
203199
.feeAmount,
204200
);
205201
const feeProxyUsed = await singleRequestProxyFactory.ethereumFeeProxy();
206-
expect(eventData[4]).toBe(feeProxyUsed);
202+
expect(event.args?.feeProxyUsed).toBe(feeProxyUsed);
207203
});
208204

209205
it('should deploy ERC20SingleRequestProxy and emit event', async () => {
@@ -226,24 +222,20 @@ describe('deploySingleRequestProxy', () => {
226222

227223
expect(events.length).toBeGreaterThan(0);
228224

229-
const eventData = utils.defaultAbiCoder.decode(
230-
['address', 'address', 'address', 'address', 'uint256', 'address'],
231-
events[0].data,
232-
);
233-
234-
expect(eventData[0]).toBe(proxyAddress);
235-
expect(eventData[1]).toBe(erc20Request.payee?.value);
236-
expect(eventData[2]).toBe(erc20Request.currencyInfo.value);
237-
expect(eventData[3]).toBe(
225+
const event = events[0];
226+
expect(event.args?.proxyAddress).toBe(proxyAddress);
227+
expect(event.args?.payee).toBe(erc20Request.payee?.value);
228+
expect(event.args?.tokenAddress).toBe(erc20Request.currencyInfo.value);
229+
expect(event.args?.feeAddress).toBe(
238230
erc20Request.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_FEE_PROXY_CONTRACT].values
239231
.feeAddress,
240232
);
241-
expect(eventData[4]).toBe(
233+
expect(event.args?.feeAmount.toString()).toBe(
242234
erc20Request.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_FEE_PROXY_CONTRACT].values
243235
.feeAmount,
244236
);
245237
const feeProxyUsed = await singleRequestProxyFactory.erc20FeeProxy();
246-
expect(eventData[5]).toBe(feeProxyUsed);
238+
expect(event.args?.feeProxyUsed).toBe(feeProxyUsed);
247239
});
248240

249241
it('should throw error when trying to pay with invalid single request proxy', async () => {

packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/0.1.0.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@
6060
"internalType": "bytes",
6161
"name": "paymentReference",
6262
"type": "bytes"
63+
},
64+
{
65+
"indexed": false,
66+
"internalType": "address",
67+
"name": "feeAddress",
68+
"type": "address"
69+
},
70+
{
71+
"indexed": false,
72+
"internalType": "uint256",
73+
"name": "feeAmount",
74+
"type": "uint256"
75+
},
76+
{
77+
"indexed": false,
78+
"internalType": "address",
79+
"name": "feeProxyUsed",
80+
"type": "address"
6381
}
6482
],
6583
"name": "ERC20SingleRequestProxyCreated",
@@ -98,6 +116,24 @@
98116
"internalType": "bytes",
99117
"name": "paymentReference",
100118
"type": "bytes"
119+
},
120+
{
121+
"indexed": false,
122+
"internalType": "address",
123+
"name": "feeAddress",
124+
"type": "address"
125+
},
126+
{
127+
"indexed": false,
128+
"internalType": "uint256",
129+
"name": "feeAmount",
130+
"type": "uint256"
131+
},
132+
{
133+
"indexed": false,
134+
"internalType": "address",
135+
"name": "feeProxyUsed",
136+
"type": "address"
101137
}
102138
],
103139
"name": "EthereumSingleRequestProxyCreated",

packages/smart-contracts/src/lib/artifacts/SingleRequestProxyFactory/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const singleRequestProxyFactoryArtifact = new ContractArtifact<SingleRequ
1313
address: '0x9d075ae44D859191C121d7522da0Cc3B104b8837',
1414
creationBlockNumber: 0,
1515
},
16+
sepolia: {
17+
address: '0xf8cACE7EE4c03Eb4f225434B0709527938D365b4',
18+
creationBlockNumber: 7038199,
19+
},
1620
},
1721
},
1822
},

0 commit comments

Comments
 (0)