Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add UserOperationEvent #10

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ contracts:
- event: DepositInflationary(address indexed account, uint256 amount, uint256 demurragedAmount)
- event: WithdrawInflationary(address indexed account, uint256 amount, uint256 demurragedAmount)
- name: SafeAccount
handler: src/event_handlers/hubV2.ts
handler: src/event_handlers/safeAccount.ts
events:
- event: ExecutionSuccess(bytes32 txHash, uint256 payment)
# - event: UserOperationEvent(bytes32 indexed userOpHash, address indexed sender, address indexed paymaster, uint256 nonce, bool success, uint256 actualGasCost, uint256 actualGasUsed)

networks:
# - id: 10200
Expand Down
2 changes: 1 addition & 1 deletion src/common/updateAvatarBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const updateAvatarBalance = async (
avatar_id: avatarId,
token_id: tokenId,
balance: amount,
computedValue: 0n,
computedValue: amount,
lastCalculated: blockTimestamp,
});
}
Expand Down
31 changes: 0 additions & 31 deletions src/event_handlers/hubV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
HubV2,
TrustRelation,
NameRegistry,
SafeAccount,
Avatar,
} from "generated";
import { toBytes, bytesToBigInt, parseEther, zeroAddress } from "viem";
Expand Down Expand Up @@ -86,36 +85,6 @@ HubV2.RegisterHuman.contractRegister(
{ preRegisterDynamicContracts: true }
);

SafeAccount.ExecutionSuccess.handlerWithLoader({
loader: async ({ event, context }) => {
let transfers = await context.Transfer.getWhere.transactionHash.eq(
event.transaction.hash
);

return { transfers };
},
handler: async ({ event, context, loaderReturn }) => {
const { transfers } = loaderReturn;

const transfer = transfers.find(
(t) =>
t.transferType === "StreamCompleted" ||
t.transferType === "PersonalMint"
);
if (transfer) {
context.Transfer.set({
...transfer,
safeTxHash: event.params.txHash,
});
} else if (transfers.length > 0) {
context.Transfer.set({
...transfers[0],
safeTxHash: event.params.txHash,
});
}
},
});

HubV2.RegisterOrganization.handler(async ({ event, context }) => {
context.Avatar.set({
...defaultAvatarProps(event),
Expand Down
64 changes: 64 additions & 0 deletions src/event_handlers/safeAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
HandlerTypes_handler,
HandlerTypes_loader,
SafeAccount,
SafeAccount_ExecutionSuccess_eventArgs,
SafeAccount_UserOperationEvent_eventArgs,
} from "generated";
import { Transfer_t } from "generated/src/db/Entities.gen";

const loader: HandlerTypes_loader<
| SafeAccount_UserOperationEvent_eventArgs
| SafeAccount_ExecutionSuccess_eventArgs,
{
transfers: Transfer_t[];
}
> = async ({ event, context }) => {
let transfers = await context.Transfer.getWhere.transactionHash.eq(
event.transaction.hash
);

return { transfers };
};

const handler: HandlerTypes_handler<
| SafeAccount_ExecutionSuccess_eventArgs
| SafeAccount_UserOperationEvent_eventArgs,
{
transfers: Transfer_t[];
}
> = async ({ event, context, loaderReturn }) => {
const { transfers } = loaderReturn;

const transfer = transfers.find(
(t) =>
t.transferType === "StreamCompleted" || t.transferType === "PersonalMint"
);
if (transfer) {
context.Transfer.set({
...transfer,
safeTxHash:
"txHash" in event.params
? event.params.txHash
: event.params.userOpHash,
});
} else if (transfers.length > 0) {
context.Transfer.set({
...transfers[0],
safeTxHash:
"txHash" in event.params
? event.params.txHash
: event.params.userOpHash,
});
}
};

SafeAccount.ExecutionSuccess.handlerWithLoader({
loader,
handler,
});

// SafeAccount.UserOperationEvent.handlerWithLoader({
// loader,
// handler,
// });