From b7b40064f8ad97a5dc39f274646f5175579fae52 Mon Sep 17 00:00:00 2001 From: Artur Sapek Date: Wed, 3 Jan 2024 17:49:49 -0500 Subject: [PATCH] stop exporting BaseTransferReceipt --- connect/src/protocols/tokenTransfer.ts | 29 ++++++++++++++----------- connect/src/wormholeTransfer.ts | 30 ++++++++++++++++---------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/connect/src/protocols/tokenTransfer.ts b/connect/src/protocols/tokenTransfer.ts index faa5e2faf6..b83ce24c7f 100644 --- a/connect/src/protocols/tokenTransfer.ts +++ b/connect/src/protocols/tokenTransfer.ts @@ -33,6 +33,7 @@ import { signSendWait } from "../common"; import { DEFAULT_TASK_TIMEOUT } from "../config"; import { Wormhole } from "../wormhole"; import { + CompletedTransferReceipt, TransferQuote, TransferReceipt, TransferState, @@ -560,7 +561,7 @@ export class TokenTransfer ...receipt, state: TransferState.DestinationInitiated, destinationTxs: destinationTxs, - }; + } as CompletedTransferReceipt; } return receipt as TransferReceipt; @@ -622,7 +623,7 @@ export class TokenTransfer ...receipt, destinationTxs: [{ chain: toChain(chainId) as DC, txid: txHash }], state: TransferState.DestinationFinalized, - }; + } as CompletedTransferReceipt; } yield receipt; } @@ -631,16 +632,20 @@ export class TokenTransfer // Note: We do not get any destinationTxs with this method if (isAttested(receipt)) { if (!receipt.attestation.attestation) throw "Signed Attestation required to check for redeem"; - receipt = { - ...receipt, - state: (await TokenTransfer.isTransferComplete( - _toChain, - receipt.attestation.attestation as TokenTransferVAA, - )) - ? TransferState.DestinationFinalized - : TransferState.Attested, - }; - yield receipt; + + let isComplete = await TokenTransfer.isTransferComplete( + _toChain, + receipt.attestation.attestation as TokenTransferVAA, + ); + + if (isComplete) { + yield { + ...receipt, + state: TransferState.DestinationFinalized, + } as CompletedTransferReceipt; + } else { + yield receipt; + } } yield receipt; diff --git a/connect/src/wormholeTransfer.ts b/connect/src/wormholeTransfer.ts index 0ff0e5faad..24e495cf62 100644 --- a/connect/src/wormholeTransfer.ts +++ b/connect/src/wormholeTransfer.ts @@ -41,7 +41,7 @@ export enum TransferState { } // Base type for common properties -export interface BaseTransferReceipt { +interface BaseTransferReceipt { protocol: PN; from: SC; to: DC; @@ -49,18 +49,26 @@ export interface BaseTransferReceipt extends BaseTransferReceipt { + state: TransferState.Created; +} + export interface SourceInitiatedTransferReceipt< PN extends ProtocolName, - SC extends Chain, - DC extends Chain, + SC extends Chain = Chain, + DC extends Chain = Chain, > extends BaseTransferReceipt { state: TransferState.SourceInitiated; originTxs: TransactionId[]; } export interface SourceFinalizedTransferReceipt< PN extends ProtocolName, - SC extends Chain, - DC extends Chain, + SC extends Chain = Chain, + DC extends Chain = Chain, > extends BaseTransferReceipt { state: TransferState.SourceFinalized; originTxs: TransactionId[]; @@ -68,8 +76,8 @@ export interface SourceFinalizedTransferReceipt< } export interface AttestedTransferReceipt< PN extends ProtocolName, - SC extends Chain, - DC extends Chain, + SC extends Chain = Chain, + DC extends Chain = Chain, > extends BaseTransferReceipt { state: TransferState.Attested; originTxs: TransactionId[]; @@ -77,13 +85,13 @@ export interface AttestedTransferReceipt< } export interface CompletedTransferReceipt< PN extends ProtocolName, - SC extends Chain, - DC extends Chain, + SC extends Chain = Chain, + DC extends Chain = Chain, > extends BaseTransferReceipt { state: TransferState.DestinationInitiated | TransferState.DestinationFinalized; originTxs: TransactionId[]; attestation: Required>; - destinationTxs: TransactionId[]; + destinationTxs?: TransactionId[]; } export function isAttested( @@ -109,7 +117,7 @@ export type TransferReceipt< SC extends Chain = Chain, DC extends Chain = Chain, > = - | BaseTransferReceipt + | CreatedTransferReceipt | SourceInitiatedTransferReceipt | SourceFinalizedTransferReceipt | AttestedTransferReceipt