@@ -10,7 +10,8 @@ import { dlnSourceAbi } from "./abis/dlnSource";
1010import { DLN , evmDLNContracts } from "./constants" ;
1111import { getChain } from "dexai" ;
1212import { Chain , ChainById } from "../../../networks/constant" ;
13- import { PrepareTxResponse , ValidateChainResponse } from "./type" ;
13+ import { DeBridgeTokens , PrepareTxResponse , ValidateChainResponse } from "./type" ;
14+ import { toResult } from "@heyanon/sdk" ;
1415
1516// Define bridge step types for better type safety
1617type BridgeStep = "initial" | "confirmation" | "execution" ;
@@ -20,7 +21,7 @@ type BridgeStep = "initial" | "confirmation" | "execution";
2021 * This provider provides the ability for user to bridge token from one chain to another.
2122 */
2223export class DeBridgeLiquidityAdapterProvider extends AdapterProvider < BaseAccount > {
23- private tokensCache : LRUCache < string , Token [ ] > ;
24+ private tokensCache : LRUCache < string , DeBridgeTokens [ ] > ;
2425 private bridgeStep : BridgeStep ;
2526 private transactionTimeout : NodeJS . Timeout | null = null ;
2627 private lastPreparedTransaction : any = null ;
@@ -42,6 +43,9 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
4243 name : "bridge_token" ,
4344 description : `
4445 Bridge a token from one network chain to another network chain or token
46+
47+ Inputs:
48+ -
4549
4650 Strict Rules:
4751 - Do not respond without querying bridge_token function
@@ -55,10 +59,7 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
5559 // Handle transaction cancellation
5660 if ( this . bridgeStep === "execution" && ! args . isConfirmed ) {
5761 this . resetBridgeState ( args ) ;
58- return {
59- success : true ,
60- data : "Transaction has been cancled successfully" ,
61- } ;
62+ return toResult ( "Transaction has been cancled successfully" , false ) ;
6263 }
6364
6465 // Reset confirmation if not in execution step
@@ -73,10 +74,7 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
7374
7475 const validatedChains = validateDLNInputs ( args ) ;
7576 if ( ! validatedChains . success || ! validatedChains . data )
76- return {
77- success : validatedChains . success ,
78- data : validatedChains . errorMessage ,
79- } ;
77+ return toResult ( validatedChains . errorMessage , true ) ;
8078
8179 const { fromChain, toChain } = validatedChains . data ;
8280
@@ -99,10 +97,10 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
9997
10098 if ( ! prepareTx . success ) {
10199 this . resetBridgeState ( ) ;
102- return {
103- success : false ,
104- data : "errorMessage" in prepareTx ? prepareTx . errorMessage : "Unknown error occurred" ,
105- } ;
100+ return toResult (
101+ "errorMessage" in prepareTx ? prepareTx . errorMessage : "Unknown error occurred" ,
102+ true ,
103+ ) ;
106104 }
107105
108106 // Handle confirmation step
@@ -286,14 +284,15 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
286284
287285 // Format token lists for display
288286 const sourceTokens = srcTokens
289- ?. map ( ( t : Token , i ) => `${ i + 1 } . ${ t . symbol . toUpperCase ( ) } - ${ t . address } ` )
287+ ?. map ( ( t : DeBridgeTokens , i ) => `${ i + 1 } . ${ t . symbol . toUpperCase ( ) } - ${ t . address } ` )
290288 . join ( "\n" ) ;
291289
292290 const destinationTokens = destTokens
293- ?. map ( ( t : Token , i ) => `${ i + 1 } . ${ t . symbol . toUpperCase ( ) } - ${ t . address } ` )
291+ ?. map ( ( t : DeBridgeTokens , i ) => `${ i + 1 } . ${ t . symbol . toUpperCase ( ) } - ${ t . address } ` )
294292 . join ( "\n" ) ;
295293
296- return `
294+ return toResult (
295+ `
297296 Stricly display below token data for user to select source and destination tokens
298297 from the list below which they want to bridge.
299298
@@ -304,7 +303,9 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
304303 ${ destinationTokens }
305304
306305 If the token you want to bridge to isn't on the list, kindly paste the token address.
307- ` ;
306+ ` ,
307+ false ,
308+ ) ;
308309 }
309310
310311 /**
@@ -319,8 +320,8 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
319320 ? "⚠️ Your previous transaction has expired. Please review and confirm the updated transaction details."
320321 : "Note: This transaction will expire in 30 seconds if not confirmed." ;
321322
322- return {
323- message : `
323+ return toResult (
324+ `
324325 Strictly display this entire confirmation message to user:
325326
326327 ${ wasExpired ? expiryMessage : "" }
@@ -344,7 +345,8 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
344345
345346 ${ ! wasExpired ? expiryMessage : "" }
346347 ` ,
347- } ;
348+ false ,
349+ ) ;
348350 }
349351
350352 /**
@@ -419,7 +421,7 @@ export class DeBridgeLiquidityAdapterProvider extends AdapterProvider<BaseAccoun
419421
420422 // Reset bridge state after successful transaction
421423 this . resetBridgeState ( args ) ;
422- return { success : true , data : "Bridge transaction submitted successfully" } ;
424+ return toResult ( "Bridge transaction submitted successfully" , false ) ;
423425 }
424426
425427 /**
0 commit comments