@@ -14,9 +14,9 @@ import { jsonifyError, Logger } from '@mark/logger';
1414import { BridgeAdapter , MemoizedTransactionRequest , RebalanceTransactionMemo } from '../../types' ;
1515import { STARGATE_OFT_ABI } from './abi' ;
1616import {
17- STARGATE_USDT_POOL_ETH ,
1817 USDT_ETH ,
19- LZ_ENDPOINT_ID_TON ,
18+ STARGATE_POOL_ADDRESSES ,
19+ CHAIN_ID_TO_LZ_ENDPOINT ,
2020 StargateSendParam ,
2121 StargateMessagingFee ,
2222 LzMessageStatus ,
@@ -27,6 +27,7 @@ import {
2727 tonAddressToBytes32 ,
2828 USDT_TON_STARGATE ,
2929} from './types' ;
30+ import { getDestinationAssetAddress } from '../../shared/asset' ;
3031
3132// LayerZero Scan API base URL
3233const LZ_SCAN_API_URL = 'https://scan.layerzero-api.com' ;
@@ -56,6 +57,26 @@ export class StargateBridgeAdapter implements BridgeAdapter {
5657 return SupportedBridge . Stargate ;
5758 }
5859
60+ /**
61+ * Resolve the destination token address for a route
62+ * For TON, uses the Stargate-specific hex address; for EVM chains, looks up via chain config
63+ */
64+ private resolveDstToken ( route : RebalanceRoute ) : string | null {
65+ if ( route . destination === 30826 ) return USDT_TON_STARGATE ;
66+ return (
67+ getDestinationAssetAddress ( route . asset , route . origin , route . destination , this . chains , this . logger ) ?? null
68+ ) ;
69+ }
70+
71+ /**
72+ * Get the LayerZero endpoint ID for a chain
73+ */
74+ protected getLzEndpointId ( chainId : number ) : number {
75+ const eid = CHAIN_ID_TO_LZ_ENDPOINT [ chainId ] ;
76+ if ( eid === undefined ) throw new Error ( `No LayerZero endpoint ID configured for chain ${ chainId } ` ) ;
77+ return eid ;
78+ }
79+
5980 /**
6081 * Get the expected amount received after bridging via Stargate
6182 *
@@ -99,8 +120,11 @@ export class StargateBridgeAdapter implements BridgeAdapter {
99120 return null ;
100121 }
101122
102- // For TON destination, use the Stargate-specific token address format
103- const dstToken = route . destination === 30826 ? USDT_TON_STARGATE : route . asset ;
123+ const dstToken = this . resolveDstToken ( route ) ;
124+ if ( ! dstToken ) {
125+ this . logger . warn ( 'Could not resolve destination token' , { route } ) ;
126+ return null ;
127+ }
104128
105129 // Use a placeholder address for quote - actual address will be used in send()
106130 const placeholderAddress = '0x1234567890abcdef1234567890abcdef12345678' ;
@@ -162,7 +186,7 @@ export class StargateBridgeAdapter implements BridgeAdapter {
162186
163187 // Prepare send parameters for quote
164188 const sendParam : StargateSendParam = {
165- dstEid : LZ_ENDPOINT_ID_TON ,
189+ dstEid : this . getLzEndpointId ( route . destination ) ,
166190 to : pad ( '0x0000000000000000000000000000000000000000' as `0x${string } `, { size : 32 } ) ,
167191 amountLD : BigInt ( amount ) ,
168192 minAmountLD : BigInt ( 0 ) , // Will be calculated after quote
@@ -304,8 +328,11 @@ export class StargateBridgeAdapter implements BridgeAdapter {
304328 return null ;
305329 }
306330
307- // For TON destination, use the Stargate-specific token address format
308- const dstToken = route . destination === 30826 ? USDT_TON_STARGATE : route . asset ;
331+ const dstToken = this . resolveDstToken ( route ) ;
332+ if ( ! dstToken ) {
333+ this . logger . warn ( 'Could not resolve destination token' , { route } ) ;
334+ return null ;
335+ }
309336
310337 // Calculate minimum amount with slippage (0.5%)
311338 const slippageBps = 50n ;
@@ -471,7 +498,7 @@ export class StargateBridgeAdapter implements BridgeAdapter {
471498
472499 // Prepare send parameters
473500 const sendParam : StargateSendParam = {
474- dstEid : LZ_ENDPOINT_ID_TON ,
501+ dstEid : this . getLzEndpointId ( route . destination ) ,
475502 to : recipientBytes32 ,
476503 amountLD : BigInt ( amount ) ,
477504 minAmountLD : minAmount ,
@@ -745,13 +772,11 @@ export class StargateBridgeAdapter implements BridgeAdapter {
745772 * Get the Stargate pool address for an asset
746773 */
747774 protected getPoolAddress ( asset : string , chainId : number ) : `0x${string } ` {
748- // For USDT on Ethereum mainnet
749- if ( asset . toLowerCase ( ) === USDT_ETH . toLowerCase ( ) && chainId === 1 ) {
750- return STARGATE_USDT_POOL_ETH ;
751- }
752-
753- // Add more pool addresses as needed
754- throw new Error ( `No Stargate pool found for asset ${ asset } on chain ${ chainId } ` ) ;
775+ const chainPools = STARGATE_POOL_ADDRESSES [ chainId ] ;
776+ if ( ! chainPools ) throw new Error ( `No Stargate pools configured for chain ${ chainId } ` ) ;
777+ const pool = chainPools [ asset . toLowerCase ( ) ] ;
778+ if ( ! pool ) throw new Error ( `No Stargate pool found for asset ${ asset } on chain ${ chainId } ` ) ;
779+ return pool ;
755780 }
756781
757782 /**
0 commit comments