@@ -173,7 +173,9 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
173173 }
174174 }
175175
176- async getSendTransceivers ( destinationChain : Chain ) {
176+ async getSendTransceivers (
177+ destinationChain : Chain
178+ ) : Promise < Ntt . TransceiverMeta [ ] > {
177179 const sendTransceivers =
178180 await this . gmpManager . getSendTransceiversWithIndicesForChain (
179181 toChainId ( destinationChain )
@@ -191,7 +193,9 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
191193 ) ;
192194 }
193195
194- async getReceiveTransceivers ( sourceChain : Chain ) {
196+ async getReceiveTransceivers (
197+ sourceChain : Chain
198+ ) : Promise < Ntt . TransceiverMeta [ ] > {
195199 const receiveTransceivers =
196200 await this . gmpManager . getReceiveTransceiversWithIndicesForChain (
197201 toChainId ( sourceChain )
@@ -235,36 +239,44 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
235239
236240 const instructions : Ntt . TransceiverInstruction [ ] = await Promise . all (
237241 sendTransceivers . map ( async ( transceiver ) => {
238- if ( transceiver . type . toLowerCase ( ) === "wormhole" ) {
239- return {
240- index : transceiver . index ,
241- payload : new Uint8Array ( [ 1 ] ) , // skipRelay = true
242- } ;
243- } else if ( transceiver . type . toLowerCase ( ) === "axelar" ) {
244- // If we fail to fetch the axelar gas fee, then use 0 as a fallback
245- // The user will need to manually top up the axelar gas fee later
246- let gasFee = 0n ;
247- try {
248- gasFee = await getAxelarGasFee (
249- this . network ,
250- this . chain ,
251- dstChain ,
252- gasLimit
242+ switch ( transceiver . type . toLowerCase ( ) ) {
243+ case "wormhole" :
244+ return {
245+ index : transceiver . index ,
246+ payload : new Uint8Array ( [ 1 ] ) , // skipRelay = true
247+ } ;
248+ case "axelar" : {
249+ let gasFee = 0n ;
250+ try {
251+ gasFee = await getAxelarGasFee (
252+ this . network ,
253+ this . chain ,
254+ dstChain ,
255+ gasLimit
256+ ) ;
257+ } catch ( e ) {
258+ // If we fail to fetch the gas fee, then use 0 as a fallback.
259+ // The Axelar relay should fail and the track() method will
260+ // surface a RelayFailedError that a UI can use to inform the user.
261+ // We don't want to block the transfer entirely just because
262+ // of a failure to fetch the gas fee.
263+ gasFee = 100000000000000n ; // 0.0001 ETH
264+ console . error ( `Failed to fetch axelar gas fee: ${ e } ` ) ;
265+ }
266+ return {
267+ index : transceiver . index ,
268+ payload : encoding . bignum . toBytes ( gasFee , 32 ) ,
269+ } ;
270+ }
271+ default :
272+ throw new Error (
273+ `Unsupported transceiver type: ${ transceiver . type } at index ${ transceiver . index } `
253274 ) ;
254- } catch { }
255- return {
256- index : transceiver . index ,
257- payload : encoding . bignum . toBytes ( gasFee , 32 ) ,
258- } ;
259- } else {
260- throw new Error (
261- `Unsupported transceiver type: ${ transceiver . type } at index ${ transceiver . index } `
262- ) ;
263275 }
264276 } )
265277 ) ;
266278
267- // the contract expects the instructions to be sorted by transceiver index
279+ // The contract expects the instructions to be sorted by transceiver index.
268280 instructions . sort ( ( a , b ) => a . index - b . index ) ;
269281
270282 return instructions ;
@@ -378,12 +390,12 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
378390 ) ;
379391 }
380392
381- // TODO: this only supports redeeming with a Wormhole transceiver for now
382393 async * redeem ( attestation : MultiTokenNtt . Attestation ) {
383394 const transceivers = await this . getReceiveTransceivers (
384395 attestation . emitterChain
385396 ) ;
386397
398+ // TODO: support other transceiver types
387399 const wormholeTransceiver = transceivers . find ( ( t ) => t . type === "wormhole" ) ;
388400 if ( ! wormholeTransceiver ) {
389401 throw new Error ( "No Wormhole transceiver registered for this chain" ) ;
@@ -514,8 +526,7 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
514526
515527 async * completeInboundQueuedTransfer (
516528 fromChain : Chain ,
517- transceiverMessage : MultiTokenNtt . Message ,
518- payer ?: AccountAddress < C >
529+ transceiverMessage : MultiTokenNtt . Message
519530 ) {
520531 const tx =
521532 await this . manager . completeInboundQueuedTransfer . populateTransaction (
@@ -540,7 +551,7 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
540551 } ;
541552 }
542553
543- // This will return null if the token is not yet created
554+ // This will return null if the token doesn't exist
544555 async getLocalToken (
545556 originalToken : MultiTokenNtt . OriginalTokenId
546557 ) : Promise < TokenId | null > {
@@ -559,6 +570,7 @@ export class EvmMultiTokenNtt<N extends Network, C extends EvmChains>
559570 return { chain : this . chain , address : toNative ( this . chain , wethAddress ) } ;
560571 }
561572
573+ // If the local token doesn't exist yet, this will return the address where it will be deployed
562574 async calculateLocalTokenAddress (
563575 originalToken : MultiTokenNtt . OriginalTokenId ,
564576 tokenMeta : MultiTokenNtt . TokenMeta
0 commit comments