11import { Redis } from "ioredis" ;
2+ import { CHAIN_IDs } from "@across-protocol/constants" ;
23import { DataSource , entities } from "@repo/indexer-database" ;
34import type {
45 DepositParams ,
@@ -7,9 +8,11 @@ import type {
78 DepositReturnType ,
89 ParsedDepositReturnType ,
910 DepositStatusResponse ,
11+ DepositStatusParams ,
1012} from "../dtos/deposits.dto" ;
1113import {
1214 DepositNotFoundException ,
15+ HyperliquidWithdrawalNotFoundException ,
1316 IncorrectQueryParamsException ,
1417 IndexParamOutOfRangeException ,
1518} from "./exceptions" ;
@@ -222,7 +225,7 @@ export class DepositsService {
222225 }
223226
224227 public async getDepositStatus (
225- params : DepositParams ,
228+ params : DepositStatusParams ,
226229 ) : Promise < DepositStatusResponse > {
227230 // in the validation rules each of these params are marked as optional
228231 // but we need to check that at least one of them is present
@@ -231,7 +234,8 @@ export class DepositsService {
231234 ( params . depositId && params . originChainId ) ||
232235 params . depositTxHash ||
233236 params . depositTxnRef ||
234- params . relayDataHash
237+ params . relayDataHash ||
238+ ( params . from && params . hypercoreWithdrawalNonce )
235239 )
236240 ) {
237241 throw new IncorrectQueryParamsException ( ) ;
@@ -245,6 +249,11 @@ export class DepositsService {
245249 return JSON . parse ( cachedData ) ;
246250 }
247251
252+ if ( params . from && params . hypercoreWithdrawalNonce ) {
253+ // Hyperliquid Withdrawal status check
254+ return this . getHyperliquidWithdrawalStatus ( params ) ;
255+ }
256+
248257 // no cached data, so we need to query the database
249258 const repo = this . db . getRepository ( entities . RelayHashInfo ) ;
250259 const queryBuilder = repo . createQueryBuilder ( "rhi" ) ;
@@ -323,6 +332,46 @@ export class DepositsService {
323332 return result ;
324333 }
325334
335+ private async getHyperliquidWithdrawalStatus ( params : DepositStatusParams ) {
336+ const cacheKey = this . getDepositStatusCacheKey ( params ) ;
337+ const repo = this . db . getRepository ( entities . HypercoreCctpWithdraw ) ;
338+ const withdrawal = await repo . findOne ( {
339+ where : {
340+ fromAddress : params . from ,
341+ hypercoreNonce : params . hypercoreWithdrawalNonce ,
342+ } ,
343+ } ) ;
344+
345+ if ( ! withdrawal ) {
346+ throw new HyperliquidWithdrawalNotFoundException ( ) ;
347+ }
348+
349+ const result = {
350+ status : "filled" ,
351+ originChainId : CHAIN_IDs . HYPERCORE ,
352+ depositId : params . hypercoreWithdrawalNonce as string , // it cannot be undefined because of the query validation rules
353+ depositTxnRef : null ,
354+ fillTxnRef : withdrawal . mintTxnHash ,
355+ destinationChainId : parseInt ( withdrawal . destinationChainId ) ,
356+ depositRefundTxnRef : null ,
357+ actionsSucceeded : null ,
358+ pagination : {
359+ currentIndex : 0 ,
360+ maxIndex : 0 ,
361+ } ,
362+ } ;
363+
364+ const cacheTtlSeconds = 60 * 5 ; // 5 minutes
365+ await this . redis . set (
366+ cacheKey ,
367+ JSON . stringify ( result ) ,
368+ "EX" ,
369+ cacheTtlSeconds ,
370+ ) ;
371+
372+ return result ;
373+ }
374+
326375 public async getDeposit ( params : DepositParams ) {
327376 // in the validation rules each of these params are marked as optional
328377 // but we need to check that at least one of them is present
@@ -703,7 +752,7 @@ export class DepositsService {
703752 return false ;
704753 }
705754
706- private getDepositStatusCacheKey ( params : DepositParams ) {
755+ private getDepositStatusCacheKey ( params : DepositStatusParams ) {
707756 if ( params . depositId && params . originChainId ) {
708757 return `depositStatus-${ params . depositId } -${ params . originChainId } -${ params . index } ` ;
709758 }
@@ -716,6 +765,10 @@ export class DepositsService {
716765 return `depositStatus-${ params . relayDataHash } -${ params . index } ` ;
717766 }
718767
768+ if ( params . from && params . hypercoreWithdrawalNonce ) {
769+ return `depositStatus-${ params . from } -${ params . hypercoreWithdrawalNonce } ` ;
770+ }
771+
719772 // in theory this should never happen because we have already checked
720773 // that at least one of the params is present
721774 throw new Error (
0 commit comments