Skip to content

Commit 9905355

Browse files
feat: add owner parameter to AppCreated event (#4425)
Co-authored-by: Miguel Nascimento <[email protected]>
1 parent 93d7fc0 commit 9905355

File tree

9 files changed

+51
-45
lines changed

9 files changed

+51
-45
lines changed

packages/bot/src/bot.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('Bot', { sequential: true }, () => {
158158
31536000n,
159159
)
160160
const receipt = await tx.wait()
161-
const { app: address } = await appRegistryDapp.getCreateAppEvent(receipt, bob.userId)
161+
const { app: address } = appRegistryDapp.getCreateAppEvent(receipt, bob.userId)
162162
const fundingAppTx = await bob.signer.sendTransaction({
163163
to: address,
164164
value: ethers.utils.parseEther('0.5').toBigInt(),

packages/contracts/src/apps/facets/factory/AppFactoryFacet.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ contract AppFactoryFacet is
4646

4747
app = _createApp(beaconId, params);
4848
appId = _registerApp(ITownsApp(app), params.client);
49-
emit AppCreated(app, appId);
49+
emit AppCreated(app, appId, msg.sender);
5050
}
5151

5252
/// @notice Create an upgradeable simple app contract
@@ -59,7 +59,7 @@ contract AppFactoryFacet is
5959
bytes32 beaconId = _getDefaultBeaconId();
6060
app = _createApp(beaconId, params);
6161
appId = _registerApp(ITownsApp(app), params.client);
62-
emit AppCreated(app, appId);
62+
emit AppCreated(app, appId, msg.sender);
6363
}
6464

6565
function addBeacons(Beacon[] calldata beacons) external onlyOwner {

packages/contracts/src/apps/facets/factory/IAppFactory.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface IAppFactoryBase {
3636
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
3737
/* EVENTS */
3838
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
39-
event AppCreated(address indexed app, bytes32 indexed uid);
39+
event AppCreated(address indexed app, bytes32 indexed uid, address indexed owner);
4040
event BeaconAdded(bytes32 indexed beaconId, address indexed beacon);
4141
event BeaconRemoved(bytes32 indexed beaconId, address indexed beacon);
4242
event EntryPointSet(address indexed oldEntryPoint, address indexed newEntryPoint);

packages/playground/src/components/dialog/create-bot/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export const CreateBotDialog = ({ open, onOpenChange }: CreateBotDialogProps) =>
215215
if (!receipt) {
216216
throw new Error('Transaction failed')
217217
}
218-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
218+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
219219
receipt,
220220
signerAddress,
221221
)
@@ -231,9 +231,9 @@ export const CreateBotDialog = ({ open, onOpenChange }: CreateBotDialogProps) =>
231231
throw new Error('Transaction failed')
232232
}
233233

234-
const { app: foundAppAddress } = await appRegistryDapp.getRegisterAppEvent(
234+
const { app: foundAppAddress } = appRegistryDapp.getRegisterAppEvent(
235235
receipt,
236-
signerAddress,
236+
contractAddress,
237237
)
238238
appAddress = foundAppAddress as Address
239239
} else {

packages/sdk/src/tests/multi/botEntitlements.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('bot entitlements tests', () => {
4141
31536000n,
4242
)
4343
const receipt = await tx.wait()
44-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
44+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
4545
receipt,
4646
botWallet.address as Address,
4747
)
@@ -172,7 +172,7 @@ describe('bot entitlements tests', () => {
172172
31536000n,
173173
)
174174
const receipt1 = await tx1.wait()
175-
const { app: readOnlyBotAddress } = await appRegistryDapp.getCreateAppEvent(
175+
const { app: readOnlyBotAddress } = appRegistryDapp.getCreateAppEvent(
176176
receipt1,
177177
botWithoutWriteWallet.address as Address,
178178
)
@@ -188,7 +188,7 @@ describe('bot entitlements tests', () => {
188188
31536000n,
189189
)
190190
const receipt2 = await tx2.wait()
191-
const { app: readWriteBotAddress } = await appRegistryDapp.getCreateAppEvent(
191+
const { app: readWriteBotAddress } = appRegistryDapp.getCreateAppEvent(
192192
receipt2,
193193
botWithWriteWallet.address as Address,
194194
)
@@ -318,7 +318,7 @@ describe('bot entitlements tests', () => {
318318
31536000n,
319319
)
320320
const receipt = await tx.wait()
321-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
321+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
322322
receipt,
323323
botWallet.address as Address,
324324
)

packages/sdk/src/tests/multi/botMembership.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('bot membership tests', () => {
4949
31536000n,
5050
)
5151
const receipt = await tx.wait()
52-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
52+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
5353
receipt,
5454
botWallet.address as Address,
5555
)
@@ -149,7 +149,7 @@ describe('bot membership tests', () => {
149149
31536000n,
150150
)
151151
const receipt = await tx.wait()
152-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
152+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
153153
receipt,
154154
botWallet.address as Address,
155155
)
@@ -263,7 +263,7 @@ describe('bot membership tests', () => {
263263
31536000n,
264264
)
265265
const receipt = await tx.wait()
266-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
266+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
267267
receipt,
268268
botWallet.address as Address,
269269
)
@@ -332,7 +332,7 @@ describe('bot membership tests', () => {
332332
31536000n,
333333
)
334334
const receipt = await tx.wait()
335-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
335+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
336336
receipt,
337337
botWallet.address as Address,
338338
)
@@ -468,7 +468,7 @@ describe('bot membership tests', () => {
468468
31536000n,
469469
)
470470
const receipt = await tx.wait()
471-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
471+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
472472
receipt,
473473
botWallet.address as Address,
474474
)
@@ -579,7 +579,7 @@ describe('bot membership tests', () => {
579579
31536000n,
580580
)
581581
const receipt = await tx.wait()
582-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
582+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
583583
receipt,
584584
botWallet.address as Address,
585585
)

packages/sdk/src/tests/multi/botStreamCreation.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('bot stream creation tests', () => {
4040
31536000n,
4141
)
4242
const receipt1 = await tx1.wait()
43-
const { app: bot1AppAddress } = await appRegistryDapp.getCreateAppEvent(
43+
const { app: bot1AppAddress } = appRegistryDapp.getCreateAppEvent(
4444
receipt1,
4545
bot1Wallet.address as Address,
4646
)
@@ -56,7 +56,7 @@ describe('bot stream creation tests', () => {
5656
31536000n,
5757
)
5858
const receipt2 = await tx2.wait()
59-
const { app: bot2AppAddress } = await appRegistryDapp.getCreateAppEvent(
59+
const { app: bot2AppAddress } = appRegistryDapp.getCreateAppEvent(
6060
receipt2,
6161
bot2Wallet.address as Address,
6262
)
@@ -113,7 +113,7 @@ describe('bot stream creation tests', () => {
113113
31536000n,
114114
)
115115
const receipt = await tx.wait()
116-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
116+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
117117
receipt,
118118
botWallet.address as Address,
119119
)

packages/sdk/src/tests/multi/channelScrubbing.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('channelScrubbing', () => {
103103
31536000n,
104104
)
105105
const receipt = await tx.wait()
106-
const { app: foundAppAddress } = await appRegistryDapp.getCreateAppEvent(
106+
const { app: foundAppAddress } = appRegistryDapp.getCreateAppEvent(
107107
receipt,
108108
botWallet.address as Address,
109109
)

packages/web3/src/app-registry/AppRegistryDapp.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,48 +61,54 @@ export class AppRegistryDapp {
6161
})
6262
}
6363

64-
public async getCreateAppEvent(
64+
public getCreateAppEvent(
6565
receipt: ContractReceipt,
6666
senderAddress: Address,
67-
): Promise<AppCreatedEventObject> {
67+
): AppCreatedEventObject {
6868
for (const log of receipt.logs) {
6969
try {
70-
const parsedLog = this.factory.interface.parseLog(log)
70+
const parsedLog = this.factory.parseLog(log)
7171
if (parsedLog.name === 'AppCreated') {
72-
const app = await this.getAppById(parsedLog.args.uid as string)
73-
const isOwner = app.owner.toLowerCase() === senderAddress.toLowerCase()
74-
if (!isOwner) {
75-
continue
72+
if ('owner' in parsedLog.args && typeof parsedLog.args.owner === 'string') {
73+
// newer contracts - filter by owner from event
74+
if (parsedLog.args.owner.toLowerCase() === senderAddress.toLowerCase()) {
75+
return {
76+
app: parsedLog.args.app,
77+
uid: parsedLog.args.uid,
78+
owner: parsedLog.args.owner,
79+
} satisfies AppCreatedEventObject
80+
}
81+
} else {
82+
// older contracts - return first match
83+
return {
84+
app: parsedLog.args.app,
85+
uid: parsedLog.args.uid,
86+
owner: '',
87+
} satisfies AppCreatedEventObject
7688
}
77-
return {
78-
app: parsedLog.args.app,
79-
uid: parsedLog.args.uid,
80-
} satisfies AppCreatedEventObject
8189
}
8290
} catch {
8391
// no need for error, this log is not from the contract we're interested in
8492
}
8593
}
86-
return { app: '', uid: '' }
94+
return { app: '', uid: '', owner: '' }
8795
}
8896

89-
public async getRegisterAppEvent(
97+
public getRegisterAppEvent(
9098
receipt: ContractReceipt,
91-
senderAddress: Address,
92-
): Promise<AppRegisteredEventObject> {
99+
appAddress: Address,
100+
): AppRegisteredEventObject {
93101
for (const log of receipt.logs) {
94102
try {
95-
const parsedLog = this.registry.interface.parseLog(log)
103+
const parsedLog = this.registry.parseLog(log)
96104
if (parsedLog.name === 'AppRegistered') {
97-
const app = await this.getAppById(parsedLog.args.uid as string)
98-
const isOwner = app.owner.toLowerCase() === senderAddress.toLowerCase()
99-
if (!isOwner) {
100-
continue
105+
const eventAppAddress = parsedLog.args.app as Address
106+
if (eventAppAddress.toLowerCase() === appAddress.toLowerCase()) {
107+
return {
108+
app: parsedLog.args.app,
109+
uid: parsedLog.args.uid,
110+
} satisfies AppRegisteredEventObject
101111
}
102-
return {
103-
app: parsedLog.args.app,
104-
uid: parsedLog.args.uid,
105-
} satisfies AppRegisteredEventObject
106112
}
107113
} catch {
108114
// no need for error, this log is not from the contract we're interested in

0 commit comments

Comments
 (0)