Skip to content

Commit e004515

Browse files
feat: add all data to deployment events (#1487)
Co-authored-by: MantisClone <david.huntmateo@request.network>
1 parent 3df13d5 commit e004515

File tree

10 files changed

+130
-39
lines changed

10 files changed

+130
-39
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: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ describe('deploySingleRequestProxy', () => {
170170
it('should deploy EthereumSingleRequestProxy and emit event', async () => {
171171
const singleRequestProxyFactory = singleRequestProxyFactoryArtifact.connect('private', wallet);
172172

173-
const initialEventCount = await provider.getBlockNumber();
174-
175-
const walletAddress = await wallet.getAddress();
173+
const initialBlock = await provider.getBlockNumber();
176174

177175
const proxyAddress = await deploySingleRequestProxy(ethRequest, wallet);
178176

@@ -183,23 +181,31 @@ describe('deploySingleRequestProxy', () => {
183181
const latestBlock = await provider.getBlockNumber();
184182
const events = await singleRequestProxyFactory.queryFilter(
185183
singleRequestProxyFactory.filters.EthereumSingleRequestProxyCreated(),
186-
initialEventCount,
184+
initialBlock,
187185
latestBlock,
188186
);
189187

190188
expect(events.length).toBeGreaterThan(0);
191189

192-
const eventData = utils.defaultAbiCoder.decode(['address', 'address'], events[0].data);
193-
194-
expect(eventData[0]).toBe(proxyAddress);
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(
194+
ethRequest.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ETH_FEE_PROXY_CONTRACT].values
195+
.feeAddress,
196+
);
197+
expect(event.args?.feeAmount.toString()).toBe(
198+
ethRequest.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ETH_FEE_PROXY_CONTRACT].values
199+
.feeAmount,
200+
);
201+
const feeProxyUsed = await singleRequestProxyFactory.ethereumFeeProxy();
202+
expect(event.args?.feeProxyUsed).toBe(feeProxyUsed);
195203
});
196204

197205
it('should deploy ERC20SingleRequestProxy and emit event', async () => {
198206
const singleRequestProxyFactory = singleRequestProxyFactoryArtifact.connect('private', wallet);
199207

200-
const initialEventCount = await provider.getBlockNumber();
201-
202-
const walletAddress = await wallet.getAddress();
208+
const initialBlock = await provider.getBlockNumber();
203209

204210
const proxyAddress = await deploySingleRequestProxy(erc20Request, wallet);
205211

@@ -210,15 +216,26 @@ describe('deploySingleRequestProxy', () => {
210216
const latestBlock = await provider.getBlockNumber();
211217
const events = await singleRequestProxyFactory.queryFilter(
212218
singleRequestProxyFactory.filters.ERC20SingleRequestProxyCreated(),
213-
initialEventCount,
219+
initialBlock,
214220
latestBlock,
215221
);
216222

217223
expect(events.length).toBeGreaterThan(0);
218224

219-
const eventData = utils.defaultAbiCoder.decode(['address', 'address'], events[0].data);
220-
221-
expect(eventData[0]).toBe(proxyAddress);
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(
230+
erc20Request.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_FEE_PROXY_CONTRACT].values
231+
.feeAddress,
232+
);
233+
expect(event.args?.feeAmount.toString()).toBe(
234+
erc20Request.extensions[ExtensionTypes.PAYMENT_NETWORK_ID.ERC20_FEE_PROXY_CONTRACT].values
235+
.feeAmount,
236+
);
237+
const feeProxyUsed = await singleRequestProxyFactory.erc20FeeProxy();
238+
expect(event.args?.feeProxyUsed).toBe(feeProxyUsed);
222239
});
223240

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

packages/smart-contracts/src/contracts/ERC20SingleRequestProxy.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ import './lib/SafeERC20.sol';
1313
contract ERC20SingleRequestProxy {
1414
address public payee;
1515
address public tokenAddress;
16+
bytes public paymentReference;
1617
address public feeAddress;
1718
uint256 public feeAmount;
18-
bytes public paymentReference;
1919
IERC20FeeProxy public erc20FeeProxy;
2020

2121
constructor(
2222
address _payee,
2323
address _tokenAddress,
24+
bytes memory _paymentReference,
2425
address _feeAddress,
2526
uint256 _feeAmount,
26-
bytes memory _paymentReference,
2727
address _erc20FeeProxy
2828
) {
2929
payee = _payee;
3030
tokenAddress = _tokenAddress;
31+
paymentReference = _paymentReference;
3132
feeAddress = _feeAddress;
3233
feeAmount = _feeAmount;
33-
paymentReference = _paymentReference;
3434
erc20FeeProxy = IERC20FeeProxy(_erc20FeeProxy);
3535
}
3636

packages/smart-contracts/src/contracts/EthereumSingleRequestProxy.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ contract EthereumSingleRequestProxy {
3030
constructor(
3131
address _payee,
3232
bytes memory _paymentReference,
33-
address _ethereumFeeProxy,
3433
address _feeAddress,
35-
uint256 _feeAmount
34+
uint256 _feeAmount,
35+
address _ethereumFeeProxy
3636
) {
3737
payee = _payee;
3838
paymentReference = _paymentReference;

packages/smart-contracts/src/contracts/SingleRequestProxyFactory.sol

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ contract SingleRequestProxyFactory is Ownable {
2121
event EthereumSingleRequestProxyCreated(
2222
address proxyAddress,
2323
address payee,
24-
bytes indexed paymentReference
24+
bytes indexed paymentReference,
25+
address feeAddress,
26+
uint256 feeAmount,
27+
address feeProxyUsed
2528
);
2629

2730
event ERC20SingleRequestProxyCreated(
2831
address proxyAddress,
2932
address payee,
3033
address tokenAddress,
31-
bytes indexed paymentReference
34+
bytes indexed paymentReference,
35+
address feeAddress,
36+
uint256 feeAmount,
37+
address feeProxyUsed
3238
);
3339

3440
event ERC20FeeProxyUpdated(address indexed newERC20FeeProxy);
@@ -60,11 +66,18 @@ contract SingleRequestProxyFactory is Ownable {
6066
EthereumSingleRequestProxy proxy = new EthereumSingleRequestProxy(
6167
_payee,
6268
_paymentReference,
63-
ethereumFeeProxy,
6469
_feeAddress,
65-
_feeAmount
70+
_feeAmount,
71+
ethereumFeeProxy
72+
);
73+
emit EthereumSingleRequestProxyCreated(
74+
address(proxy),
75+
_payee,
76+
_paymentReference,
77+
_feeAddress,
78+
_feeAmount,
79+
ethereumFeeProxy
6680
);
67-
emit EthereumSingleRequestProxyCreated(address(proxy), _payee, _paymentReference);
6881
return address(proxy);
6982
}
7083

@@ -87,13 +100,21 @@ contract SingleRequestProxyFactory is Ownable {
87100
ERC20SingleRequestProxy proxy = new ERC20SingleRequestProxy(
88101
_payee,
89102
_tokenAddress,
103+
_paymentReference,
90104
_feeAddress,
91105
_feeAmount,
92-
_paymentReference,
93106
erc20FeeProxy
94107
);
95108

96-
emit ERC20SingleRequestProxyCreated(address(proxy), _payee, _tokenAddress, _paymentReference);
109+
emit ERC20SingleRequestProxyCreated(
110+
address(proxy),
111+
_payee,
112+
_tokenAddress,
113+
_paymentReference,
114+
_feeAddress,
115+
_feeAmount,
116+
erc20FeeProxy
117+
);
97118
return address(proxy);
98119
}
99120

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const singleRequestProxyFactoryArtifact = new ContractArtifact<SingleRequ
1414
creationBlockNumber: 0,
1515
},
1616
sepolia: {
17-
address: '0x435E81E12136414e2c09cAFe05E902E23bD46030',
18-
creationBlockNumber: 6965557,
17+
address: '0xf8cACE7EE4c03Eb4f225434B0709527938D365b4',
18+
creationBlockNumber: 7038199,
1919
},
2020
},
2121
},

packages/smart-contracts/test/contracts/ERC20SingleRequestProxy.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ describe('contract: ERC20SingleRequestProxy', () => {
4747
erc20SingleRequestProxy = await new ERC20SingleRequestProxy__factory(deployer).deploy(
4848
user2Addr,
4949
testToken.address,
50+
paymentReference,
5051
feeRecipientAddr,
5152
feeAmount,
52-
paymentReference,
5353
erc20FeeProxy.address,
5454
);
5555

@@ -156,9 +156,9 @@ describe('contract: ERC20SingleRequestProxy', () => {
156156
const usdtProxy = await new ERC20SingleRequestProxy__factory(deployer).deploy(
157157
user2Addr,
158158
usdtFake.address,
159+
paymentReference,
159160
feeRecipientAddr,
160161
usdtFeeAmount,
161-
paymentReference,
162162
erc20FeeProxy.address,
163163
);
164164

@@ -210,9 +210,9 @@ describe('contract: ERC20SingleRequestProxy', () => {
210210
const zeroFeeProxy = await new ERC20SingleRequestProxy__factory(deployer).deploy(
211211
user2Addr,
212212
testToken.address,
213+
paymentReference,
213214
feeRecipientAddr,
214215
0,
215-
paymentReference,
216216
erc20FeeProxy.address,
217217
);
218218

packages/smart-contracts/test/contracts/EthereumSingleRequestProxy.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ describe('contract : EthereumSingleRequestProxy', () => {
3030
ethereumSingleRequestProxy = await ethereumSingleRequestProxyFactory.deploy(
3131
payeeAddress,
3232
paymentReference,
33-
ethereumFeeProxy.address,
3433
feeRecipientAddress,
3534
feeAmount,
35+
ethereumFeeProxy.address,
3636
);
3737
await ethereumSingleRequestProxy.deployed();
3838
});
@@ -87,9 +87,9 @@ describe('contract : EthereumSingleRequestProxy', () => {
8787
const newEthereumSingleRequestProxy = await newEthereumSingleRequestProxyFactory.deploy(
8888
payeeAddress,
8989
paymentReference,
90-
mockEthereumFeeProxy.address,
9190
feeRecipientAddress,
9291
feeAmount,
92+
mockEthereumFeeProxy.address,
9393
);
9494
await newEthereumSingleRequestProxy.deployed();
9595

packages/smart-contracts/test/contracts/SingleRequestProxyFactory.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,16 @@ describe('contract: SingleRequestProxyFactory', () => {
8383
expect(proxyAddress).to.not.equal(ethers.constants.AddressZero);
8484
expect(proxyAddress).to.be.properAddress;
8585

86-
// Check if the event was emitted with correct parameters
8786
await expect(tx)
8887
.to.emit(singleRequestProxyFactory, 'EthereumSingleRequestProxyCreated')
89-
.withArgs(proxyAddress, payeeAddress, paymentReference);
88+
.withArgs(
89+
proxyAddress,
90+
payeeAddress,
91+
paymentReference,
92+
feeRecipientAddress,
93+
feeAmount,
94+
ethereumFeeProxy.address,
95+
);
9096

9197
const proxy = (await ethers.getContractAt(
9298
'EthereumSingleRequestProxy',
@@ -119,10 +125,17 @@ describe('contract: SingleRequestProxyFactory', () => {
119125
expect(proxyAddress).to.not.equal(ethers.constants.AddressZero);
120126
expect(proxyAddress).to.be.properAddress;
121127

122-
// Check if the event was emitted with correct parameters
123128
await expect(tx)
124129
.to.emit(singleRequestProxyFactory, 'ERC20SingleRequestProxyCreated')
125-
.withArgs(proxyAddress, payeeAddress, testToken.address, paymentReference);
130+
.withArgs(
131+
proxyAddress,
132+
payeeAddress,
133+
testToken.address,
134+
paymentReference,
135+
feeRecipientAddress,
136+
feeAmount,
137+
erc20FeeProxy.address,
138+
);
126139

127140
const proxy = (await ethers.getContractAt(
128141
'ERC20SingleRequestProxy',

0 commit comments

Comments
 (0)