Skip to content

Commit

Permalink
feat(app): no quote available case in quote token calc
Browse files Browse the repository at this point in the history
  • Loading branch information
cor committed Jan 24, 2025
1 parent 85e8cdb commit e4632a2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions typescript-sdk/playground/holesky-to-stargaze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ if (quoteToken.isErr()) {
process.exit(1)
}

if (quoteToken.value.type === "NO_QUOTE_AVAILABLE") {
consola.info("no quote token available")
process.exit(1)
}

consola.info("quote token", quoteToken.value)

const transferArgs = {
Expand Down
17 changes: 16 additions & 1 deletion typescript-sdk/src/query/offchain/ucs03-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@ export type Channel = {
destination_connection_id: number
}

function isPositiveInteger(str: string): boolean {
return /^[1-9]\d*$/.test(str)
}

export const getQuoteToken = async (
source_chain_id: string,
base_token: string,
channel: Channel
): Promise<Result<{ quote_token: string; type: "UNWRAPPED" | "NEW_WRAPPED" }, Error>> => {
): Promise<
Result<
{ quote_token: string; type: "UNWRAPPED" | "NEW_WRAPPED" } | { type: "NO_QUOTE_AVAILABLE" },
Error
>
> => {
// check if the denom is wrapped
let wrapping = await ResultAsync.fromPromise(
request(GRAQPHQL_URL, tokenWrappingQuery, {
Expand Down Expand Up @@ -83,6 +92,12 @@ export const getQuoteToken = async (
}
}

// HACK: to check evm vs cosmos we check if te destination chain id is a number
if (!isPositiveInteger(channel.destination_chain_id)) {
// we donn't support sending new assets to cosmos chains yet.
return ok({ type: "NO_QUOTE_AVAILABLE" })
}

// if it is unknown, calculate the quotetoken
const destinationChainClient = createPublicClient({
chain: evmChainFromChainId(channel.destination_chain_id),
Expand Down

0 comments on commit e4632a2

Please sign in to comment.