Skip to content

Commit

Permalink
Make the routes return a receipt (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin authored Apr 17, 2024
1 parent a931e9c commit 1f9169d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
12 changes: 8 additions & 4 deletions connect/src/routes/cctp/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
CircleTransferDetails,
Signer,
TokenId,
TransactionId,
} from "@wormhole-foundation/sdk-definitions";
import { CircleBridge } from "@wormhole-foundation/sdk-definitions";
import { signSendWait } from "../../common.js";
Expand Down Expand Up @@ -149,7 +148,7 @@ export class CCTPRoute<N extends Network>
};
}

async complete(signer: Signer, receipt: R): Promise<TransactionId[]> {
async complete(signer: Signer, receipt: R): Promise<R> {
if (!isAttested(receipt))
throw new Error("The source must be finalized in order to complete the transfer");

Expand All @@ -160,10 +159,15 @@ export class CCTPRoute<N extends Network>

const cb = await this.request.toChain.getCircleBridge();
const xfer = cb.redeem(this.request.to.address, message, attestation);
return await signSendWait<N, Chain>(this.request.toChain, xfer, signer);
const dstTxids = await signSendWait<N, Chain>(this.request.toChain, xfer, signer);
return {
...receipt,
state: TransferState.DestinationInitiated,
destinationTxs: dstTxids,
};
} else {
//
return [];
return receipt;
}
}

Expand Down
11 changes: 3 additions & 8 deletions connect/src/routes/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import type { Chain, Network } from "@wormhole-foundation/sdk-base";
import type {
ChainContext,
Signer,
TokenId,
TransactionId,
} from "@wormhole-foundation/sdk-definitions";
import type { ChainContext, Signer, TokenId } from "@wormhole-foundation/sdk-definitions";
import type { Wormhole } from "../wormhole.js";
import type { RouteTransferRequest } from "./request.js";
import type {
Expand Down Expand Up @@ -123,7 +118,7 @@ export abstract class ManualRoute<
> extends Route<N, OP, VP, R> {
NATIVE_GAS_DROPOFF_SUPPORTED = false;
IS_AUTOMATIC = false;
public abstract complete(sender: Signer, receipt: R): Promise<TransactionId[]>;
public abstract complete(sender: Signer, receipt: R): Promise<R>;
}

export function isManual<N extends Network>(route: Route<N>): route is ManualRoute<N> {
Expand All @@ -140,7 +135,7 @@ export abstract class FinalizableRoute<
VP extends ValidatedTransferParams<OP> = ValidatedTransferParams<OP>,
R extends Receipt = Receipt,
> extends Route<N, OP, VP, R> {
public abstract finalize(sender: Signer, receipt: R): Promise<TransactionId[]>;
public abstract finalize(sender: Signer, receipt: R): Promise<R>;
}

export function isFinalizable<N extends Network>(route: Route<N>): route is FinalizableRoute<N> {
Expand Down
12 changes: 8 additions & 4 deletions connect/src/routes/tokenBridge/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
Signer,
TokenId,
TokenTransferDetails,
TransactionId,
} from "@wormhole-foundation/sdk-definitions";
import type { TokenTransferVAA } from "../../protocols/tokenTransfer.js";
import { TokenTransfer } from "../../protocols/tokenTransfer.js";
Expand Down Expand Up @@ -138,15 +137,20 @@ export class TokenBridgeRoute<N extends Network>
} satisfies SourceInitiatedTransferReceipt;
}

async complete(signer: Signer, receipt: R): Promise<TransactionId[]> {
async complete(signer: Signer, receipt: R): Promise<R> {
if (!isAttested(receipt))
throw new Error("The source must be finalized in order to complete the transfer");
return await TokenTransfer.redeem<N>(
const dstTxIds = await TokenTransfer.redeem<N>(
this.request.toChain,
// todo: ew?
receipt.attestation.attestation as TokenTransferVAA,
signer,
);

return {
...receipt,
state: TransferState.DestinationInitiated,
destinationTxs: dstTxIds,
};
}

public override async *track(receipt: R, timeout?: number) {
Expand Down

0 comments on commit 1f9169d

Please sign in to comment.