Skip to content

Commit

Permalink
stop exporting BaseTransferReceipt
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek committed Jan 3, 2024
1 parent 7b29bb4 commit b7b4006
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
29 changes: 17 additions & 12 deletions connect/src/protocols/tokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { signSendWait } from "../common";
import { DEFAULT_TASK_TIMEOUT } from "../config";
import { Wormhole } from "../wormhole";
import {
CompletedTransferReceipt,
TransferQuote,
TransferReceipt,
TransferState,
Expand Down Expand Up @@ -560,7 +561,7 @@ export class TokenTransfer<N extends Network = Network>
...receipt,
state: TransferState.DestinationInitiated,
destinationTxs: destinationTxs,
};
} as CompletedTransferReceipt<TokenTransferProtocol>;
}

return receipt as TransferReceipt<TokenTransferProtocol>;
Expand Down Expand Up @@ -622,7 +623,7 @@ export class TokenTransfer<N extends Network = Network>
...receipt,
destinationTxs: [{ chain: toChain(chainId) as DC, txid: txHash }],
state: TransferState.DestinationFinalized,
};
} as CompletedTransferReceipt<TokenTransferProtocol, SC, DC>;
}
yield receipt;
}
Expand All @@ -631,16 +632,20 @@ export class TokenTransfer<N extends Network = Network>
// 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<TokenTransferProtocol, SC, DC>;
} else {
yield receipt;
}
}

yield receipt;
Expand Down
30 changes: 19 additions & 11 deletions connect/src/wormholeTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,57 @@ export enum TransferState {
}

// Base type for common properties
export interface BaseTransferReceipt<PN extends ProtocolName, SC extends Chain, DC extends Chain> {
interface BaseTransferReceipt<PN extends ProtocolName, SC extends Chain, DC extends Chain> {
protocol: PN;
from: SC;
to: DC;
request: TransferRequest<PN>;
state: TransferState;
}

export interface CreatedTransferReceipt<
PN extends ProtocolName,
SC extends Chain = Chain,
DC extends Chain = Chain,
> extends BaseTransferReceipt<PN, SC, DC> {
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<PN, SC, DC> {
state: TransferState.SourceInitiated;
originTxs: TransactionId<SC>[];
}
export interface SourceFinalizedTransferReceipt<
PN extends ProtocolName,
SC extends Chain,
DC extends Chain,
SC extends Chain = Chain,
DC extends Chain = Chain,
> extends BaseTransferReceipt<PN, SC, DC> {
state: TransferState.SourceFinalized;
originTxs: TransactionId<SC>[];
attestation: AttestationReceipt<PN>;
}
export interface AttestedTransferReceipt<
PN extends ProtocolName,
SC extends Chain,
DC extends Chain,
SC extends Chain = Chain,
DC extends Chain = Chain,
> extends BaseTransferReceipt<PN, SC, DC> {
state: TransferState.Attested;
originTxs: TransactionId<SC>[];
attestation: Required<AttestationReceipt<PN>>;
}
export interface CompletedTransferReceipt<
PN extends ProtocolName,
SC extends Chain,
DC extends Chain,
SC extends Chain = Chain,
DC extends Chain = Chain,
> extends BaseTransferReceipt<PN, SC, DC> {
state: TransferState.DestinationInitiated | TransferState.DestinationFinalized;
originTxs: TransactionId<SC>[];
attestation: Required<AttestationReceipt<PN>>;
destinationTxs: TransactionId<DC>[];
destinationTxs?: TransactionId<DC>[];
}

export function isAttested<PN extends ProtocolName>(
Expand All @@ -109,7 +117,7 @@ export type TransferReceipt<
SC extends Chain = Chain,
DC extends Chain = Chain,
> =
| BaseTransferReceipt<PN, SC, DC>
| CreatedTransferReceipt<PN, SC, DC>
| SourceInitiatedTransferReceipt<PN, SC, DC>
| SourceFinalizedTransferReceipt<PN, SC, DC>
| AttestedTransferReceipt<PN, SC, DC>
Expand Down

0 comments on commit b7b4006

Please sign in to comment.