-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathexecutor.ts
More file actions
801 lines (703 loc) · 22.9 KB
/
Copy pathexecutor.ts
File metadata and controls
801 lines (703 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
import {
AttestedTransferReceipt,
Chain,
ChainAddress,
ChainContext,
CompletedTransferReceipt,
DestinationQueuedTransferReceipt,
Network,
RedeemedTransferReceipt,
Signer,
TokenId,
TransactionId,
TransferReceipt as _TransferReceipt,
TransferState,
UniversalAddress,
Wormhole,
WormholeMessageId,
amount,
canonicalAddress,
deserializeLayout,
encoding,
finality,
guardians,
isAttested,
isDestinationQueued,
isFailed,
isRedeemed,
isSourceFinalized,
isSourceInitiated,
nativeTokenId,
routes,
serializeLayout,
signSendWait,
toChainId,
Platform,
chainToPlatform,
} from "@wormhole-foundation/sdk-connect";
import "@wormhole-foundation/sdk-definitions-ntt";
import { NttRoute } from "../types.js";
import {
calculateReferrerFee,
fetchCapabilities,
fetchSignedQuote,
fetchStatus,
getNativeRecipientAddress,
isRelayStatusFailed,
} from "./utils.js";
import { Ntt, NttWithExecutor } from "@wormhole-foundation/sdk-definitions-ntt";
import { StacksNttWithExecutor } from "@wormhole-foundation/sdk-stacks-ntt";
import {
isNative,
relayInstructionsLayout,
signedQuoteLayout,
} from "@wormhole-foundation/sdk-definitions";
import { getDefaultReferrerAddress } from "./consts.js";
export namespace NttExecutorRoute {
export type Config = {
ntt: NttRoute.Config;
referrerFee?: ReferrerFeeConfig;
};
export type ReferrerFeeConfig = {
// Referrer Fee in *tenths* of basis points - e.g. 10 = 1 basis point (0.01%)
feeDbps: bigint;
// The address to which the referrer fee will be sent
referrerAddresses?: Partial<Record<Platform, string>>;
perTokenOverrides?: Partial<
Record<
Chain,
Record<
string,
{
referrerFeeDbps?: bigint;
// Some tokens may require more gas to redeem than the default.
gasLimit?: bigint;
// Some tokens may require more msgValue than the default.
msgValue?: bigint;
}
>
>
>;
};
export type Options = {
// 0.0 - 1.0 percentage of the maximum gas drop-off amount
nativeGas?: number;
};
export type NormalizedParams = {
amount: amount.Amount;
sourceContracts: Ntt.Contracts;
destinationContracts: Ntt.Contracts;
referrerFeeDbps: bigint;
};
export interface ValidatedParams
extends routes.ValidatedTransferParams<Options> {
normalizedParams: NormalizedParams;
}
export type TransferReceipt<
SC extends Chain = Chain,
DC extends Chain = Chain,
> = _TransferReceipt<NttRoute.ManualAttestationReceipt, SC, DC> & {
params: ValidatedParams;
};
}
type Op = NttExecutorRoute.Options;
type Tp = routes.TransferParams<Op>;
type Vr = routes.ValidationResult<Op>;
type Vp = NttExecutorRoute.ValidatedParams;
type Q = routes.Quote<Op, Vp, NttWithExecutor.Quote>;
type QR = routes.QuoteResult<Op, Vp>;
type R = NttExecutorRoute.TransferReceipt;
export function nttExecutorRoute(config: NttExecutorRoute.Config) {
class NttExecutorRouteImpl<N extends Network> extends NttExecutorRoute<N> {
static override config = config;
}
return NttExecutorRouteImpl;
}
export class NttExecutorRoute<N extends Network>
extends routes.AutomaticRoute<N, Op, Vp, R>
implements routes.StaticRouteMethods<typeof NttExecutorRoute>
{
// executor supports gas drop-off
static NATIVE_GAS_DROPOFF_SUPPORTED: boolean = true;
// @ts-ignore
// Since we set the config on the static class, access it with this param
// the NttExecutorRoute.config will always be empty
readonly staticConfig: NttExecutorRoute.Config = this.constructor.config;
static config: NttExecutorRoute.Config = { ntt: { tokens: {} } };
static meta = { name: "NttExecutorRoute" };
static supportedNetworks(): Network[] {
return NttRoute.resolveSupportedNetworks(this.config.ntt);
}
static supportedChains(network: Network): Chain[] {
return NttRoute.resolveSupportedChains(this.config.ntt, network);
}
static async supportedSourceTokens(
fromChain: ChainContext<Network>
): Promise<TokenId[]> {
return NttRoute.resolveSourceTokens(this.config.ntt, fromChain);
}
static async supportedDestinationTokens<N extends Network>(
sourceToken: TokenId,
fromChain: ChainContext<N>,
toChain: ChainContext<N>
): Promise<TokenId[]> {
return NttRoute.resolveDestinationTokens(
this.config.ntt,
sourceToken,
fromChain,
toChain
);
}
static isProtocolSupported<N extends Network>(
chain: ChainContext<N>
): boolean {
return chain.supportsProtocol("Ntt");
}
getDefaultOptions(): Op {
return {
nativeGas: 0,
};
}
async validate(
request: routes.RouteTransferRequest<N>,
params: Tp
): Promise<Vr> {
const options = params.options ?? this.getDefaultOptions();
if (
options.nativeGas !== undefined &&
(options.nativeGas < 0 || options.nativeGas > 1)
) {
return {
valid: false,
error: new Error("Invalid native gas percentage"),
params,
};
}
const parsedAmount = amount.parse(params.amount, request.source.decimals);
// IMPORTANT: The EVM NttManager will revert if there is dust. This is not the case for Solana,
// but we want to be consistent across chains.
const trimmedAmount = NttRoute.trimAmount(
parsedAmount,
request.destination.decimals
);
const { srcContracts, dstContracts } = NttRoute.resolveNttContracts(
this.staticConfig.ntt,
request.source.id,
request.destination.id
);
let referrerFeeDbps = 0n;
if (this.staticConfig.referrerFee) {
referrerFeeDbps = this.staticConfig.referrerFee.feeDbps;
if (this.staticConfig.referrerFee.perTokenOverrides) {
const srcTokenAddress = canonicalAddress(request.source.id);
const override =
this.staticConfig.referrerFee.perTokenOverrides[
request.source.id.chain
]?.[srcTokenAddress];
if (override?.referrerFeeDbps !== undefined) {
referrerFeeDbps = override.referrerFeeDbps;
}
}
}
const validatedParams: Vp = {
amount: params.amount,
normalizedParams: {
amount: trimmedAmount,
sourceContracts: srcContracts,
destinationContracts: dstContracts,
referrerFeeDbps,
},
options,
};
return { valid: true, params: validatedParams };
}
async quote(
request: routes.RouteTransferRequest<N>,
params: Vp
): Promise<QR> {
const { fromChain, toChain } = request;
try {
const executorQuote = await this.fetchExecutorQuote(request, params);
const { remainingAmount, estimatedCost, gasDropOff, expires } =
executorQuote;
const receivedAmount = amount.scale(
amount.fromBaseUnits(remainingAmount, request.source.decimals),
request.destination.decimals
);
const result: QR = {
success: true,
params,
sourceToken: {
token: request.source.id,
amount: params.normalizedParams.amount,
},
destinationToken: {
token: request.destination.id,
amount: receivedAmount,
},
relayFee: {
token: nativeTokenId(fromChain.chain),
amount: amount.fromBaseUnits(
estimatedCost,
fromChain.config.nativeTokenDecimals
),
},
destinationNativeGas: amount.fromBaseUnits(
gasDropOff,
toChain.config.nativeTokenDecimals
),
eta:
request.fromChain.chain === "Stacks"
? 10000
: finality.estimateFinalityTime(request.fromChain.chain) +
guardians.guardianAttestationEta * 1000,
expires,
details: executorQuote,
};
const dstNtt = await toChain.getProtocol("Ntt", {
ntt: params.normalizedParams.destinationContracts,
});
const duration = await dstNtt.getRateLimitDuration();
if (duration > 0n) {
const capacity = await dstNtt.getCurrentInboundCapacity(
fromChain.chain
);
if (
NttRoute.isCapacityThresholdExceeded(
amount.units(receivedAmount),
capacity
)
) {
result.warnings = [
{
type: "DestinationCapacityWarning",
delayDurationSec: Number(duration),
},
];
}
}
return result;
} catch (e: unknown) {
return {
success: false,
error: e instanceof Error ? e : new Error(String(e)),
};
}
}
async fetchExecutorQuote(
request: routes.RouteTransferRequest<N>,
params: Vp
): Promise<NttWithExecutor.Quote> {
const { fromChain, toChain } = request;
let referrer = getDefaultReferrerAddress(fromChain.chain);
const referrerFeeConfig = this.staticConfig.referrerFee;
if (referrerFeeConfig) {
const platform = chainToPlatform(fromChain.chain);
const referrerAddress =
referrerFeeConfig.referrerAddresses?.[platform] ?? "";
if (referrerAddress) {
referrer = Wormhole.chainAddress(fromChain.chain, referrerAddress);
}
}
const { referrerFee, remainingAmount, referrerFeeDbps } =
calculateReferrerFee(
params.normalizedParams.amount,
params.normalizedParams.referrerFeeDbps,
request.destination.decimals
);
if (remainingAmount <= 0n) {
throw new Error("Amount after fee <= 0");
}
const capabilities = await fetchCapabilities(fromChain.network);
const srcCapabilities = capabilities[toChainId(fromChain.chain)];
if (!srcCapabilities) {
throw new Error("Unsupported source chain");
}
const dstCapabilities = capabilities[toChainId(toChain.chain)];
if (!dstCapabilities || !dstCapabilities.requestPrefixes.includes("ERN1")) {
throw new Error("Unsupported destination chain");
}
const { recipient } = request;
const dstNttWithExec = await toChain.getProtocol("NttWithExecutor", {
ntt: params.normalizedParams.destinationContracts,
});
// Calculate the gas dropOff value
const gasDropOffLimit = BigInt(dstCapabilities.gasDropOffLimit);
const dropOff =
params.options.nativeGas && gasDropOffLimit > 0n
? (BigInt(Math.round(params.options.nativeGas * 100)) *
gasDropOffLimit) /
100n
: 0n;
let { msgValue, gasLimit } =
await dstNttWithExec.estimateMsgValueAndGasLimit(recipient);
// Check for overrides in the config.
if (this.staticConfig.referrerFee?.perTokenOverrides) {
const dstTokenAddress = canonicalAddress(request.destination.id);
const override =
this.staticConfig.referrerFee.perTokenOverrides[
request.destination.id.chain
]?.[dstTokenAddress];
if (override?.gasLimit !== undefined) {
gasLimit = override.gasLimit;
}
if (override?.msgValue !== undefined) {
msgValue = override.msgValue;
}
}
let relayInstructions: Uint8Array;
const relayRequests = [];
if (toChain.chain === "Stacks") {
// When transferring to Stacks, we use the StacksNttReceiveInstruction, which includes
// the pre-hashed recipient address (Stacks "universal" addresses are keccak256 hashes).
// The pre-hashed recipient address is used by executor to register the recipient
// with the Stacks addr32 contract if it is not already registered.
relayRequests.push({
request: {
type: "StacksNttReceiveInstruction" as const,
nttManager: Buffer.from(
params.normalizedParams.destinationContracts.manager
),
recipient: recipient
? recipient.address.toUint8Array()
: new Uint8Array(new Uint8Array(32)),
gasDropOff: dropOff,
},
});
} else {
// Add the gas instruction
relayRequests.push({
request: {
type: "GasInstruction" as const,
gasLimit,
msgValue,
},
});
// Add the gas drop-off instruction if applicable
if (dropOff > 0n) {
relayRequests.push({
request: {
type: "GasDropOffInstruction" as const,
dropOff,
// If the recipient is undefined (e.g. the user hasn't connected their wallet yet),
// we temporarily use a dummy address to fetch a quote.
// The recipient address is validated later in the `initiate` method, which will throw if it's still missing.
recipient: recipient
? recipient.address.toUniversalAddress()
: new UniversalAddress(new Uint8Array(32)),
},
});
}
}
relayInstructions = serializeLayout(relayInstructionsLayout, {
requests: relayRequests,
});
const quote = await fetchSignedQuote(
fromChain.network,
fromChain.chain,
toChain.chain,
encoding.hex.encode(relayInstructions, true)
);
if (!quote.estimatedCost) {
throw new Error("No estimated cost");
}
const estimatedCost = BigInt(quote.estimatedCost);
const signedQuoteBytes = encoding.hex.decode(quote.signedQuote);
const signedQuote = deserializeLayout(signedQuoteLayout, signedQuoteBytes);
return {
signedQuote: signedQuoteBytes,
relayInstructions: relayInstructions,
estimatedCost,
payeeAddress: signedQuote.quote.payeeAddress,
referrer,
referrerFee,
remainingAmount,
referrerFeeDbps,
expires: signedQuote.quote.expiryTime,
gasDropOff: dropOff,
};
}
async initiate(
request: routes.RouteTransferRequest<N>,
signer: Signer,
quote: Q,
to: ChainAddress
): Promise<R> {
if (!quote.details) {
throw new Error("Missing quote details");
}
const { params, details } = quote;
const relayInstructions = deserializeLayout(
relayInstructionsLayout,
details.relayInstructions
);
// Make sure that the gas drop-off recipient matches the actual recipient
relayInstructions.requests.forEach(({ request }) => {
if (
request.type === "GasDropOffInstruction" &&
!request.recipient.equals(to.address.toUniversalAddress())
) {
throw new Error("Gas drop-off recipient does not match");
}
if (
request.type === "StacksNttReceiveInstruction" &&
!encoding.bytes.equals(request.recipient, to.address.toUint8Array())
) {
throw new Error("Stacks recipient does not match");
}
});
const { fromChain } = request;
const sender = Wormhole.parseAddress(signer.chain(), signer.address());
const nttWithExec = await fromChain.getProtocol("NttWithExecutor", {
ntt: params.normalizedParams.sourceContracts,
});
const ntt = await fromChain.getProtocol("Ntt", {
ntt: params.normalizedParams.sourceContracts,
});
const wrapNative = isNative(request.source.id.address);
const initXfer = nttWithExec.transfer(
sender,
to,
amount.units(params.normalizedParams.amount),
details,
ntt,
wrapNative
);
const txids = await signSendWait(fromChain, initXfer, signer);
// Status the transfer immediately before returning
let statusAttempts = 0;
const statusTransferImmediately = async () => {
while (statusAttempts < 20) {
try {
const [txStatus] = await fetchStatus(
fromChain.network,
txids.at(-1)!.txid,
fromChain.chain
);
if (txStatus) {
break;
}
} catch (_) {
// is ok we just try again!
}
statusAttempts++;
await new Promise((resolve) => setTimeout(resolve, 2000));
}
};
// Spawn a loop in the background that will status this transfer until
// the API gives a successful response. We don't await the result
// here because we don't need it for the return value.
statusTransferImmediately();
return {
from: fromChain.chain,
to: to.chain,
state: TransferState.SourceInitiated,
originTxs: txids,
params,
};
}
async complete(signer: Signer, receipt: R): Promise<R> {
if (!isAttested(receipt) && !isFailed(receipt)) {
if (isRedeemed(receipt)) return receipt;
throw new Error(
"The source must be finalized in order to complete the transfer"
);
}
if (!receipt.attestation) {
throw new Error("No attestation found for the transfer");
}
const toChain = this.wh.getChain(receipt.to);
const recipientAddress = await getNativeRecipientAddress(
this.wh.network,
receipt
);
const ntt = await toChain.getProtocol("Ntt", {
ntt: receipt.params.normalizedParams.destinationContracts,
});
const sender = Wormhole.parseAddress(signer.chain(), signer.address());
const completeXfer = ntt.redeem(
[receipt.attestation.attestation],
sender,
recipientAddress
);
const txids = await signSendWait(toChain, completeXfer, signer);
return {
...receipt,
state: TransferState.DestinationInitiated,
attestation: receipt.attestation,
destinationTxs: txids,
};
}
async resume(tx: TransactionId): Promise<R> {
const vaa = await this.wh.getVaa(tx.txid, "Ntt:WormholeTransfer");
if (!vaa) throw new Error("No VAA found for transaction: " + tx.txid);
const msgId: WormholeMessageId = {
chain: vaa.emitterChain,
emitter: vaa.emitterAddress,
sequence: vaa.sequence,
};
const { recipientChain, trimmedAmount } =
vaa.payload["nttManagerPayload"].payload;
const srcManagerAddress = await (async () => {
if (chainToPlatform(tx.chain) === "Stacks") {
// We can't use the manager address from the VAA payload for Stacks
// since it's the hashed address. Instead, we need to fetch it from the transaction.
const stacks = this.wh.getChain("Stacks");
const rpc = await stacks.getRpc();
return StacksNttWithExecutor.getManagerAddressFromTx(rpc, tx.txid);
}
return {
chain: vaa.emitterChain,
address: vaa.payload["sourceNttManager"],
};
})();
const { srcContracts, dstContracts } =
NttRoute.resolveDestinationNttContracts(
this.staticConfig.ntt,
srcManagerAddress,
recipientChain
);
const amt = amount.fromBaseUnits(
trimmedAmount.amount,
trimmedAmount.decimals
);
return {
from: vaa.emitterChain,
to: recipientChain,
state: TransferState.Attested,
originTxs: [tx],
attestation: {
id: msgId,
attestation: vaa,
},
params: {
amount: amount.display(amt),
options: {},
normalizedParams: {
amount: amt,
sourceContracts: srcContracts,
destinationContracts: dstContracts,
referrerFeeDbps: 0n,
},
},
};
}
// Even though this is an automatic route, the transfer may need to be
// manually finalized if it was queued
async finalize(signer: Signer, receipt: R): Promise<R> {
if (!isDestinationQueued(receipt)) {
throw new Error(
"The transfer must be destination queued in order to finalize"
);
}
const {
attestation: { attestation: vaa },
} = receipt;
const toChain = this.wh.getChain(receipt.to);
const ntt = await toChain.getProtocol("Ntt", {
ntt: receipt.params.normalizedParams.destinationContracts,
});
const sender = Wormhole.chainAddress(signer.chain(), signer.address());
const completeTransfer = ntt.completeInboundQueuedTransfer(
receipt.from,
vaa.payload["nttManagerPayload"],
sender.address
);
const finalizeTxids = await signSendWait(toChain, completeTransfer, signer);
return {
...receipt,
state: TransferState.DestinationFinalized,
destinationTxs: [...(receipt.destinationTxs ?? []), ...finalizeTxids],
};
}
public override async *track(receipt: R, timeout?: number) {
// First we fetch the attestation (VAA) for the transfer
if (isSourceInitiated(receipt) || isSourceFinalized(receipt)) {
const { txid } = receipt.originTxs.at(-1)!;
const vaa = await this.wh.getVaa(txid, "Ntt:WormholeTransfer", timeout);
if (!vaa) throw new Error("No VAA found for transaction: " + txid);
const msgId: WormholeMessageId = {
chain: vaa.emitterChain,
emitter: vaa.emitterAddress,
sequence: vaa.sequence,
};
receipt = {
...receipt,
state: TransferState.Attested,
attestation: {
id: msgId,
attestation: vaa,
},
} satisfies AttestedTransferReceipt<NttRoute.ManualAttestationReceipt> as R;
yield receipt;
}
const toChain = this.wh.getChain(receipt.to);
const ntt = await toChain.getProtocol("Ntt", {
ntt: receipt.params.normalizedParams.destinationContracts,
});
// Check if the relay was successful or failed
if (isAttested(receipt) && !isFailed(receipt)) {
const [txStatus] = await fetchStatus(
this.wh.network,
receipt.originTxs.at(-1)!.txid,
receipt.from
);
if (!txStatus) throw new Error("No transaction status found");
const relayStatus = txStatus.status;
if (isRelayStatusFailed(relayStatus)) {
receipt = {
...receipt,
state: TransferState.Failed,
error: new routes.RelayFailedError(
`Relay failed with status: ${relayStatus}`
),
};
yield receipt;
}
}
// Check if the transfer was redeemed
if (isAttested(receipt) || isFailed(receipt)) {
if (!receipt.attestation) {
throw new Error("No attestation found");
}
const {
attestation: { attestation: vaa },
} = receipt;
if (await ntt.getIsApproved(vaa)) {
receipt = {
...receipt,
state: TransferState.DestinationInitiated,
attestation: receipt.attestation,
// TODO: check for destination event transactions to get dest Txids
} satisfies RedeemedTransferReceipt<NttRoute.ManualAttestationReceipt>;
yield receipt;
}
}
if (isRedeemed(receipt) || isDestinationQueued(receipt)) {
const {
attestation: { attestation: vaa },
} = receipt;
const queuedTransfer = await ntt.getInboundQueuedTransfer(
vaa.emitterChain,
vaa.payload["nttManagerPayload"]
);
if (queuedTransfer !== null) {
receipt = {
...receipt,
state: TransferState.DestinationQueued,
queueReleaseTime: new Date(
queuedTransfer.rateLimitExpiryTimestamp * 1000
),
} satisfies DestinationQueuedTransferReceipt<NttRoute.ManualAttestationReceipt>;
yield receipt;
} else if (await ntt.getIsExecuted(vaa)) {
receipt = {
...receipt,
state: TransferState.DestinationFinalized,
} satisfies CompletedTransferReceipt<NttRoute.ManualAttestationReceipt>;
yield receipt;
}
}
yield receipt;
}
}