Skip to content

Commit

Permalink
apply satisfies for typechecking
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Jan 4, 2024
1 parent 25d4f1b commit b0a2392
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
39 changes: 20 additions & 19 deletions connect/src/protocols/cctpTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ import { Wormhole } from "../wormhole";
import {
AttestedTransferReceipt,
CompletedTransferReceipt,
SourceInitiatedTransferReceipt,
SourceFinalizedTransferReceipt,
SourceInitiatedTransferReceipt,
TransferQuote,
TransferReceipt,
TransferState,
WormholeTransfer,
isSourceInitiated,
isSourceFinalized,
isAttested,
isSourceFinalized,
isSourceInitiated,
} from "../wormholeTransfer";

type CircleTransferProtocol = "CircleBridge" | "AutomaticCircleBridge";
Expand Down Expand Up @@ -479,7 +479,7 @@ export class CircleTransfer<N extends Network = Network>
// This attestation may be either the auto relay vaa or the circle attestation
// depending on the request

let receipt: Partial<TransferReceipt<CircleTransferProtocol>> = {
let receipt: TransferReceipt<CircleTransferProtocol> = {
protocol: xfer.transfer.automatic ? "AutomaticCircleBridge" : "CircleBridge",
request: xfer.transfer,
from: from.chain,
Expand All @@ -493,7 +493,7 @@ export class CircleTransfer<N extends Network = Network>
...receipt,
state: TransferState.SourceInitiated,
originTxs,
} as SourceInitiatedTransferReceipt<CircleTransferProtocol>;
} satisfies SourceInitiatedTransferReceipt<CircleTransferProtocol>;
}

const att = xfer.attestations?.filter((a) => isWormholeMessageId(a.id)) ?? [];
Expand All @@ -502,27 +502,28 @@ export class CircleTransfer<N extends Network = Network>
if (attestation) {
if (attestation.id) {
receipt = {
...receipt,
...(receipt as SourceInitiatedTransferReceipt<CircleTransferProtocol>),
state: TransferState.SourceFinalized,
attestation: attestation,
} as SourceFinalizedTransferReceipt<CircleTransferProtocol>;
}
} satisfies SourceFinalizedTransferReceipt<CircleTransferProtocol>;

if (attestation.attestation)
receipt = {
...receipt,
state: TransferState.Attested,
attestation: { id: attestation.id, attestation: attestation.attestation },
} as AttestedTransferReceipt<CircleTransferProtocol>;
if (attestation.attestation) {
receipt = {
...receipt,
state: TransferState.Attested,
attestation: { id: attestation.id, attestation: attestation.attestation },
} satisfies AttestedTransferReceipt<CircleTransferProtocol>;
}
}
}

const destinationTxs = xfer.txids.filter((txid) => txid.chain === xfer.transfer.to.chain);
if (destinationTxs.length > 0) {
receipt = {
...receipt,
...(receipt as AttestedTransferReceipt<CircleTransferProtocol>),
state: TransferState.DestinationInitiated,
destinationTxs,
} as CompletedTransferReceipt<CircleTransferProtocol>;
} satisfies CompletedTransferReceipt<CircleTransferProtocol>;
}

return receipt as TransferReceipt<CircleTransferProtocol>;
Expand Down Expand Up @@ -558,7 +559,7 @@ export class CircleTransfer<N extends Network = Network>
...receipt,
attestation: { id: xfermsg },
state: TransferState.SourceFinalized,
} as SourceFinalizedTransferReceipt<CircleTransferProtocol, SC, DC>;
} satisfies SourceFinalizedTransferReceipt<CircleTransferProtocol, SC, DC>;
yield receipt;
}

Expand All @@ -580,7 +581,7 @@ export class CircleTransfer<N extends Network = Network>
...receipt,
attestation: { id: receipt.attestation.id, attestation: vaa },
state: TransferState.Attested,
} as AttestedTransferReceipt<CircleTransferProtocol, SC, DC>;
} satisfies AttestedTransferReceipt<CircleTransferProtocol, SC, DC>;
yield receipt;
}
}
Expand All @@ -602,7 +603,7 @@ export class CircleTransfer<N extends Network = Network>
...receipt,
destinationTxs: [{ chain: toChain(chainId) as DC, txid: txHash }],
state: TransferState.DestinationFinalized,
} as CompletedTransferReceipt<CircleTransferProtocol, SC, DC>;
} satisfies CompletedTransferReceipt<CircleTransferProtocol, SC, DC>;
yield receipt;
}
}
Expand Down
36 changes: 18 additions & 18 deletions connect/src/protocols/tokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export class TokenTransfer<N extends Network = Network>
const from = transfer.from.chain;
const to = transfer.to.chain;

let receipt: Partial<TransferReceipt<TokenTransferProtocol>> = {
let receipt: TransferReceipt<TokenTransferProtocol> = {
protocol,
request: transfer,
from: from,
Expand All @@ -547,7 +547,7 @@ export class TokenTransfer<N extends Network = Network>
...receipt,
state: TransferState.SourceInitiated,
originTxs: originTxs,
} as SourceInitiatedTransferReceipt<TokenTransferProtocol>;
} satisfies SourceInitiatedTransferReceipt<TokenTransferProtocol>;
}

const att =
Expand All @@ -556,28 +556,28 @@ export class TokenTransfer<N extends Network = Network>
if (attestation) {
if (attestation.id) {
receipt = {
...receipt,
...(receipt as SourceInitiatedTransferReceipt<TokenTransferProtocol>),
state: TransferState.SourceFinalized,
attestation: { id: attestation.id },
} as SourceFinalizedTransferReceipt<TokenTransferProtocol>;
}

if (attestation.attestation) {
receipt = {
...receipt,
state: TransferState.Attested,
attestation: { id: attestation.id, attestation: attestation.attestation },
} as AttestedTransferReceipt<TokenTransferProtocol>;
} satisfies SourceFinalizedTransferReceipt<TokenTransferProtocol>;

if (attestation.attestation) {
receipt = {
...receipt,
state: TransferState.Attested,
attestation: { id: attestation.id, attestation: attestation.attestation },
} satisfies AttestedTransferReceipt<TokenTransferProtocol>;
}
}
}

const destinationTxs = xfer.txids.filter((txid) => txid.chain === transfer.to.chain);
if (destinationTxs.length > 0) {
receipt = {
...receipt,
...(receipt as AttestedTransferReceipt<TokenTransferProtocol>),
state: TransferState.DestinationInitiated,
destinationTxs: destinationTxs,
} as CompletedTransferReceipt<TokenTransferProtocol>;
} satisfies CompletedTransferReceipt<TokenTransferProtocol>;
}

return receipt as TransferReceipt<TokenTransferProtocol>;
Expand Down Expand Up @@ -615,7 +615,7 @@ export class TokenTransfer<N extends Network = Network>
...receipt,
state: TransferState.SourceFinalized,
attestation: { id: msg },
} as SourceFinalizedTransferReceipt<TokenTransferProtocol, SC, DC>;
} satisfies SourceFinalizedTransferReceipt<TokenTransferProtocol>;
yield receipt;
}

Expand All @@ -630,7 +630,7 @@ export class TokenTransfer<N extends Network = Network>
...receipt,
attestation: { id, attestation },
state: TransferState.Attested,
} as AttestedTransferReceipt<TokenTransferProtocol, SC, DC>;
} satisfies AttestedTransferReceipt<TokenTransferProtocol>;
yield receipt;
}

Expand All @@ -647,7 +647,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>;
} satisfies CompletedTransferReceipt<TokenTransferProtocol>;
}
yield receipt;
}
Expand All @@ -666,7 +666,7 @@ export class TokenTransfer<N extends Network = Network>
receipt = {
...receipt,
state: TransferState.DestinationFinalized,
} as CompletedTransferReceipt<TokenTransferProtocol, SC, DC>;
} satisfies CompletedTransferReceipt<TokenTransferProtocol>;
}

yield receipt;
Expand Down

0 comments on commit b0a2392

Please sign in to comment.