Skip to content

Commit

Permalink
fix router example, remove console errors (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin authored May 16, 2024
1 parent 09d8b8e commit 9a2ef36
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 36 deletions.
2 changes: 0 additions & 2 deletions connect/src/routes/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class RouteResolver<N extends Network> {
try {
return await rc.supportedDestinationTokens(inputTokenId, fromChain, toChain);
} catch (e) {
console.error(`Failed to get supported destination tokens for ${rc.meta.name}: `, e);
return [];
}
}),
Expand Down Expand Up @@ -96,7 +95,6 @@ export class RouteResolver<N extends Network> {

return protocolSupported && sourceTokenSupported && destinationTokenSupported;
} catch (e) {
console.error(`failed to find routes for ${rc.meta.name}: `, e);
return false;
}
}),
Expand Down
38 changes: 4 additions & 34 deletions examples/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
Chain,
Network,
Signer,
TransactionId,
TransferState,
Wormhole,
canonicalAddress,
routes,
wormhole,
} from "@wormhole-foundation/sdk";
import { Wormhole, canonicalAddress, routes, wormhole } from "@wormhole-foundation/sdk";

import evm from "@wormhole-foundation/sdk/evm";
import solana from "@wormhole-foundation/sdk/solana";
Expand Down Expand Up @@ -63,8 +53,6 @@ import { getSigner } from "./helpers/index.js";
// creating a transfer request fetches token details
// since all routes will need to know about the tokens
const tr = await routes.RouteTransferRequest.create(wh, {
from: sender.address,
to: receiver.address,
source: sendToken,
destination: destinationToken,
});
Expand Down Expand Up @@ -106,32 +94,14 @@ import { getSigner } from "./helpers/index.js";
// EXAMPLE_REQUEST_INITIATE
// Now the transfer may be initiated
// A receipt will be returned, guess what you gotta do with that?
const receipt = await bestRoute.initiate(sender.signer, quote);
const receipt = await bestRoute.initiate(sender.signer, quote, receiver.address);
console.log("Initiated transfer with receipt: ", receipt);
// EXAMPLE_REQUEST_INITIATE

// Kick off a wait log, if there is an opportunity to complete, this function will do it
// see the implementation for how this works
await routes.checkAndCompleteTransfer(bestRoute, receipt, receiver.signer);
} else {
console.log("Not initiating transfer (set `imSure` to true to do so)");
}
})();

// An incomplete transfer can be completed by calling this function
async function completeTransfer<N extends Network>(
route: routes.Route<N>,
fromChain: Chain,
toChain: Chain,
tx: TransactionId,
signer: Signer,
) {
const receipt: routes.Receipt = {
from: fromChain,
to: toChain,
state: TransferState.SourceInitiated,
originTxs: [tx],
};

// Kick off a wait log, if there is an opportunity to complete, this function will do it
// see the implementation for how this works
await routes.checkAndCompleteTransfer(route, receipt, signer);
}

0 comments on commit 9a2ef36

Please sign in to comment.