Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the routes return a receipt #471

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading