diff --git a/config.yaml b/config.yaml index f628cd5..fbd4a1d 100644 --- a/config.yaml +++ b/config.yaml @@ -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 diff --git a/src/common/updateAvatarBalance.ts b/src/common/updateAvatarBalance.ts index f612c8a..bf974ae 100644 --- a/src/common/updateAvatarBalance.ts +++ b/src/common/updateAvatarBalance.ts @@ -27,7 +27,7 @@ export const updateAvatarBalance = async ( avatar_id: avatarId, token_id: tokenId, balance: amount, - computedValue: 0n, + computedValue: amount, lastCalculated: blockTimestamp, }); } diff --git a/src/event_handlers/hubV2.ts b/src/event_handlers/hubV2.ts index dcce2dd..a0af322 100644 --- a/src/event_handlers/hubV2.ts +++ b/src/event_handlers/hubV2.ts @@ -3,7 +3,6 @@ import { HubV2, TrustRelation, NameRegistry, - SafeAccount, Avatar, } from "generated"; import { toBytes, bytesToBigInt, parseEther, zeroAddress } from "viem"; @@ -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), diff --git a/src/event_handlers/safeAccount.ts b/src/event_handlers/safeAccount.ts new file mode 100644 index 0000000..78e17ac --- /dev/null +++ b/src/event_handlers/safeAccount.ts @@ -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, +// });