@@ -5,15 +5,12 @@ import {
55 generateOTokenHistoryId ,
66 generateOTokenId ,
77 generateOTokenRebaseId ,
8+ generateOTokenWithdrawalRequestId ,
89} from '../../utils/compositeIds' ;
910import { getTokenByAddress } from '../../utils/getToken' ;
10- import { OToken } from './generated' ;
11+ import { OToken , OTokenVault } from './generated' ;
1112import { calculateRebase } from './oTokenRebase' ;
1213
13- /**
14- * Handle Transfer events
15- * Updates OTokenAddress balances and creates history/activity records
16- */
1714OToken . Transfer . handler ( async ( { event, context } ) => {
1815 const chainId = event . chainId ;
1916 const tokenAddress = event . srcAddress . toLowerCase ( ) ;
@@ -129,7 +126,7 @@ OToken.Transfer.handler(async ({ event, context }) => {
129126 generateOTokenAddressId ( chainId , tokenAddress , from ) ,
130127 ) ;
131128
132- context . OTokenHistory . set ( {
129+ context . History . set ( {
133130 id : fromHistoryId ,
134131 chainId,
135132 otoken : tokenAddress ,
@@ -156,7 +153,7 @@ OToken.Transfer.handler(async ({ event, context }) => {
156153 generateOTokenAddressId ( chainId , tokenAddress , to ) ,
157154 ) ;
158155
159- context . OTokenHistory . set ( {
156+ context . History . set ( {
160157 id : toHistoryId ,
161158 chainId,
162159 otoken : tokenAddress ,
@@ -179,7 +176,7 @@ OToken.Transfer.handler(async ({ event, context }) => {
179176 event . logIndex ,
180177 ) ;
181178
182- context . OTokenActivity . set ( {
179+ context . Activity . set ( {
183180 id : activityId ,
184181 chainId,
185182 otoken : tokenAddress ,
@@ -194,10 +191,6 @@ OToken.Transfer.handler(async ({ event, context }) => {
194191 } ) ;
195192} ) ;
196193
197- /**
198- * Handle Rebase events
199- * Updates OToken supply and creates rebase records
200- */
201194OToken . Rebase . handler ( async ( { event, context } ) => {
202195 const chainId = event . chainId ;
203196 const tokenAddress = event . srcAddress . toLowerCase ( ) ;
@@ -254,7 +247,7 @@ OToken.Rebase.handler(async ({ event, context }) => {
254247 event . logIndex ,
255248 ) ;
256249
257- context . OTokenRebase . set ( {
250+ context . Rebase . set ( {
258251 id : rebaseId ,
259252 chainId,
260253 otoken : tokenAddress ,
@@ -271,3 +264,54 @@ OToken.Rebase.handler(async ({ event, context }) => {
271264 logIndex : event . logIndex ,
272265 } ) ;
273266} ) ;
267+
268+ OTokenVault . WithdrawalRequested . handler ( async ( { event, context } ) => {
269+ const chainId = event . chainId ;
270+ const otoken = event . srcAddress . toLowerCase ( ) ;
271+ const withdrawer = event . params . withdrawer . toLowerCase ( ) ;
272+ const requestId = BigInt ( event . params . requestId ) ;
273+ const amount = BigInt ( event . params . amount ) ;
274+ const queued = BigInt ( event . params . queued ) ;
275+ const timestamp = BigInt ( event . block . timestamp ) ;
276+ const hash = event . transaction . hash ;
277+
278+ const extraBytes = event . transaction . input . slice ( 74 ) ;
279+ let queueWait : bigint | undefined ;
280+ if ( extraBytes . length > 0 ) {
281+ queueWait = BigInt ( '0x' + extraBytes ) ;
282+ }
283+
284+ context . WithdrawalRequest . set ( {
285+ id : generateOTokenWithdrawalRequestId ( chainId , otoken , requestId ) ,
286+ chainId,
287+ otoken,
288+ withdrawer,
289+ requestId,
290+ amount,
291+ queued,
292+ claimed : false ,
293+ queueWait,
294+ createdAt : timestamp ,
295+ updatedAt : timestamp ,
296+ hash,
297+ } ) ;
298+ } ) ;
299+
300+ OTokenVault . WithdrawalClaimed . handler ( async ( { event, context } ) => {
301+ const chainId = event . chainId ;
302+ const otoken = event . srcAddress . toLowerCase ( ) ;
303+ const requestId = BigInt ( event . params . requestId ) ;
304+
305+ const request = await context . WithdrawalRequest . get (
306+ generateOTokenWithdrawalRequestId ( chainId , otoken , requestId ) ,
307+ ) ;
308+ if ( ! request ) {
309+ return ;
310+ }
311+
312+ context . WithdrawalRequest . set ( {
313+ ...request ,
314+ claimed : true ,
315+ updatedAt : BigInt ( event . block . timestamp ) ,
316+ } ) ;
317+ } ) ;
0 commit comments