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

(Deposit/Withdraw) Support External Url Providers #3310

Merged
merged 19 commits into from
Jun 12, 2024

Conversation

JoseRFelix
Copy link
Collaborator

@JoseRFelix JoseRFelix commented Jun 8, 2024

What is the purpose of the change:

Providers often have their own user interfaces (UIs) that support their unique IDs, such as Satellite for Axelar. We could query each provider using the counterparty chain and token to obtain a URL that preselects those assets, along with Osmosis as the source or destination.

Linear Task

Linear Task URL

Testing and Verifying

  • Tests are passing

Copy link

vercel bot commented Jun 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
osmosis-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2024 6:31pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
osmosis-frontend-datadog ⬜️ Ignored (Inspect) Visit Preview Jun 12, 2024 6:31pm
osmosis-frontend-dev ⬜️ Ignored (Inspect) Visit Preview Jun 12, 2024 6:31pm
osmosis-frontend-edgenet ⬜️ Ignored (Inspect) Jun 12, 2024 6:31pm
osmosis-testnet ⬜️ Ignored (Inspect) Visit Preview Jun 12, 2024 6:31pm

Copy link
Member

@jonator jonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add support for tfm URLs in IBC provider? I recall they have deep IBC support, for CW20s as well since we're removing support for that.

@JoseRFelix JoseRFelix changed the title feat: Support External Url Providers (Deposit/Withdraw) Support External Url Providers Jun 11, 2024
@JoseRFelix
Copy link
Collaborator Author

Should we add support for tfm URLs in IBC provider? I recall they have deep IBC support, for CW20s as well since we're removing support for that.

@jonator Added an IBC external url function for TFM on my latest commit

Copy link
Member

@jonator jonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. But what are your thoughts on adding this as a method on the bridge provider interface?

@JoseRFelix
Copy link
Collaborator Author

Approved. But what are your thoughts on adding this as a method on the bridge provider interface?

I considered it, but I'm hesitant to include it to avoid having to manage the bundle size

Base automatically changed from jose/fe-449-bridge-providers-migrate-from-ethers-to-viem to stage June 12, 2024 16:13
Copy link
Contributor

coderabbitai bot commented Jun 12, 2024

Walkthrough

The updates to the bridge package involve significant enhancements to the Axelar and IBC modules, including the introduction of new functions for generating external URLs, improved mock data handling, and schema updates for chain types. The changes also standardize chain ID representations and improve error messages for unsupported chains. Additionally, new tests have been added to ensure the robustness of these functionalities.

Changes

Files Change Summary
packages/bridge/src/axelar/__tests__/axelar-bridge-provider.spec.ts Updated chain IDs to numeric values, added networkName for unsupported chains, and modified various method calls including getDepositAddress, estimateGasCost, createEvmTransaction, and getQuote.
packages/bridge/src/axelar/__tests__/axelar-transfer-status.spec.ts Enhanced mocking behavior for @osmosis-labs/utils module and added afterEach block to clear mocks after each test.
packages/bridge/src/axelar/__tests__/external-url.spec.ts Introduced tests for getAxelarExternalUrl function and added mock data classes MockAxelarAssets and MockAxelarChains.
packages/bridge/src/axelar/__tests__/mock-axelar-assets-and-chains.ts Added mock data for Axelar assets and chains, including asset denominations, addresses, and chain information.
packages/bridge/src/axelar/external-url.ts Introduced getAxelarExternalUrl function for generating external URLs for bridging assets between chains.
packages/bridge/src/axelar/index.ts Updated error message for unsupported chains to include the specific chain ID.
packages/bridge/src/ibc/__tests__/external-url.spec.ts Added tests for getIBCExternalUrl function to validate URL generation based on input parameters.
packages/bridge/src/ibc/external-url.ts Introduced getIBCExternalUrl function for generating external URLs based on chain types and environments.
packages/bridge/src/interface.ts Renamed bridgeChainSchema to cosmosChainSchema, introduced evmChainSchema, and created a new bridgeChainSchema as a union of both. Updated various interfaces to use BridgeChain directly.
packages/bridge/src/skip/__tests__/external-url.spec.ts Added tests for getSkipExternalUrl function to validate URL generation based on input parameters.
packages/bridge/src/skip/external-url.ts Introduced getSkipExternalUrl function for generating external URLs for bridge operations, with conditional logic for testnet environments.
packages/bridge/src/squid/__tests__/squid-bridge-provider.spec.ts Updated numeric values from strings to numbers in getQuote function calls and modified chainType values from "evm" to "cosmos" in certain scenarios.
packages/bridge/src/squid/external-url.ts Introduced getSquidExternalUrl function for generating external URLs based on input parameters.
packages/bridge/src/squid/index.ts Modified SquidBridgeProvider class to ensure type consistency by converting chainId to a string before comparison.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AxelarBridgeProvider
    participant MockAxelarAssets
    participant MockAxelarChains

    User->>AxelarBridgeProvider: Call getAxelarExternalUrl()
    AxelarBridgeProvider->>MockAxelarAssets: Fetch asset info
    AxelarBridgeProvider->>MockAxelarChains: Fetch chain info
    MockAxelarAssets-->>AxelarBridgeProvider: Return asset info
    MockAxelarChains-->>AxelarBridgeProvider: Return chain info
    AxelarBridgeProvider-->>User: Return generated URL
Loading

Poem

In the code where bridges span,
Chains of cosmos, evm, and,
URLs now, they brightly gleam,
Guiding assets like a dream.
Tests and mocks, they play their part,
Bringing joy to every heart.
🐇✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bd60533 and 734630b.

Files selected for processing (1)
  • packages/bridge/src/axelar/index.ts (1 hunks)
Additional context used
Biome
packages/bridge/src/axelar/index.ts

[error] 311-313: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 365-375: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

Outside diff range and nitpick comments (3)
packages/bridge/src/skip/external-url.ts (1)

10-10: Clarify the return of undefined for "testnet".

Consider adding a comment explaining why undefined is returned when the environment is "testnet". This could help future maintainers understand the decision-making process behind this condition.

packages/bridge/src/ibc/external-url.ts (1)

10-16: Clarify conditions for returning undefined.

Consider adding comments to explain why undefined is returned for "testnet" or EVM chain types. This could help future maintainers understand the decision-making process behind these conditions.

packages/bridge/src/squid/index.ts (1)

Line range hint 284-284: Ensure proper error handling for JSON parsing in createCosmosTransaction.

- const parsedData = JSON.parse(data) as {
+ try {
+   const parsedData = JSON.parse(data) as {
    msgTypeUrl: typeof IbcTransferType | typeof WasmTransferType;
    msg: {
      sourcePort: string;
      sourceChannel: string;
      token: {
        denom: string;
        amount: string;
      };
      sender: string;
      receiver: string;
      timeoutTimestamp: {
        low: number;
        high: number;
        unsigned: boolean;
      };
      memo: string;
    };
+ } catch (e) {
+   throw new BridgeQuoteError([
+     {
+       errorType: BridgeError.CreateCosmosTxError,
+       message: "Failed to parse transaction data",
+     },
+   ]);
+ }

Adding a try-catch block around JSON parsing can prevent runtime errors from unhandled exceptions and provide clearer error messages.

Comment on lines +10 to +24
const url = new URL(
env === "mainnet"
? "https://app.squidrouter.com/"
: "https://testnet.app.squidrouter.com/"
);
url.searchParams.set(
"chains",
[fromChain.chainId, toChain.chainId].join(",")
);
url.searchParams.set(
"tokens",
[fromAsset.address, toAsset.address].join(",")
);

return url.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure robust error handling in URL construction.

The URL construction logic is clear, but consider adding error handling to manage potential exceptions that might arise from malformed inputs. This could improve the robustness of the function.

Comment on lines +7 to +71
export async function getAxelarExternalUrl({
fromChain,
toChain,
toAsset,
env,
toAddress,
fromAsset,
}: GetBridgeExternalUrlParams): Promise<string> {
const [axelarChains, axelarAssets] = await Promise.all([
getAxelarChains({ env }),
getAxelarAssets({ env }),
]);

const fromAxelarChain = axelarChains.find(
(chain) => String(chain.chain_id) === String(fromChain.chainId)
);

if (!fromAxelarChain) {
throw new Error(`Chain not found: ${fromChain.chainId}`);
}

const toAxelarChain = axelarChains.find(
(chain) => String(chain.chain_id) === String(toChain.chainId)
);

if (!toAxelarChain) {
throw new Error(`Chain not found: ${toChain.chainId}`);
}

const fromAxelarAsset = axelarAssets.find((axelarAsset) => {
return (
!isNil(axelarAsset.addresses[toAxelarChain.chain_name]) &&
(axelarAsset.addresses[toAxelarChain.chain_name].ibc_denom ===
toAsset.address ||
axelarAsset.addresses[toAxelarChain.chain_name].address ===
toAsset.address)
);
});

if (!fromAxelarAsset) {
throw new Error(`Asset not found: ${toAsset.address}`);
}

const url = new URL(
env === "mainnet"
? "https://satellite.money/"
: "https://testnet.satellite.money/"
);
url.searchParams.set("source", fromAxelarChain.chain_name);
url.searchParams.set("destination", toAxelarChain.chain_name);
url.searchParams.set(
"asset_denom",
// Check if the asset has multiple denoms (indicating wrapped tokens)
!isNil(fromAxelarAsset.denoms) && fromAxelarAsset.denoms.length > 1
? // If the fromAsset address is the native EVM token constant address, use the second denom which is the unwrapped token
fromAsset.address === NativeEVMTokenConstantAddress
? fromAxelarAsset.denoms[1]
: fromAxelarAsset.denoms[0]
: // If there are no multiple denoms, use the default denom
fromAxelarAsset.denom
);
url.searchParams.set("destination_address", toAddress);

return url.toString();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function getAxelarExternalUrl is comprehensive and handles various scenarios including environment checks and asset denomination handling. Consider adding more detailed error messages to improve debugging and user feedback.

- throw new Error(`Chain not found: ${fromChain.chainId}`);
+ throw new Error(`Chain not found for ID: ${fromChain.chainId}. Please verify the chain ID and try again.`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function getAxelarExternalUrl({
fromChain,
toChain,
toAsset,
env,
toAddress,
fromAsset,
}: GetBridgeExternalUrlParams): Promise<string> {
const [axelarChains, axelarAssets] = await Promise.all([
getAxelarChains({ env }),
getAxelarAssets({ env }),
]);
const fromAxelarChain = axelarChains.find(
(chain) => String(chain.chain_id) === String(fromChain.chainId)
);
if (!fromAxelarChain) {
throw new Error(`Chain not found: ${fromChain.chainId}`);
}
const toAxelarChain = axelarChains.find(
(chain) => String(chain.chain_id) === String(toChain.chainId)
);
if (!toAxelarChain) {
throw new Error(`Chain not found: ${toChain.chainId}`);
}
const fromAxelarAsset = axelarAssets.find((axelarAsset) => {
return (
!isNil(axelarAsset.addresses[toAxelarChain.chain_name]) &&
(axelarAsset.addresses[toAxelarChain.chain_name].ibc_denom ===
toAsset.address ||
axelarAsset.addresses[toAxelarChain.chain_name].address ===
toAsset.address)
);
});
if (!fromAxelarAsset) {
throw new Error(`Asset not found: ${toAsset.address}`);
}
const url = new URL(
env === "mainnet"
? "https://satellite.money/"
: "https://testnet.satellite.money/"
);
url.searchParams.set("source", fromAxelarChain.chain_name);
url.searchParams.set("destination", toAxelarChain.chain_name);
url.searchParams.set(
"asset_denom",
// Check if the asset has multiple denoms (indicating wrapped tokens)
!isNil(fromAxelarAsset.denoms) && fromAxelarAsset.denoms.length > 1
? // If the fromAsset address is the native EVM token constant address, use the second denom which is the unwrapped token
fromAsset.address === NativeEVMTokenConstantAddress
? fromAxelarAsset.denoms[1]
: fromAxelarAsset.denoms[0]
: // If there are no multiple denoms, use the default denom
fromAxelarAsset.denom
);
url.searchParams.set("destination_address", toAddress);
return url.toString();
}
export async function getAxelarExternalUrl({
fromChain,
toChain,
toAsset,
env,
toAddress,
fromAsset,
}: GetBridgeExternalUrlParams): Promise<string> {
const [axelarChains, axelarAssets] = await Promise.all([
getAxelarChains({ env }),
getAxelarAssets({ env }),
]);
const fromAxelarChain = axelarChains.find(
(chain) => String(chain.chain_id) === String(fromChain.chainId)
);
if (!fromAxelarChain) {
throw new Error(`Chain not found for ID: ${fromChain.chainId}. Please verify the chain ID and try again.`);
}
const toAxelarChain = axelarChains.find(
(chain) => String(chain.chain_id) === String(toChain.chainId)
);
if (!toAxelarChain) {
throw new Error(`Chain not found: ${toChain.chainId}`);
}
const fromAxelarAsset = axelarAssets.find((axelarAsset) => {
return (
!isNil(axelarAsset.addresses[toAxelarChain.chain_name]) &&
(axelarAsset.addresses[toAxelarChain.chain_name].ibc_denom ===
toAsset.address ||
axelarAsset.addresses[toAxelarChain.chain_name].address ===
toAsset.address)
);
});
if (!fromAxelarAsset) {
throw new Error(`Asset not found: ${toAsset.address}`);
}
const url = new URL(
env === "mainnet"
? "https://satellite.money/"
: "https://testnet.satellite.money/"
);
url.searchParams.set("source", fromAxelarChain.chain_name);
url.searchParams.set("destination", toAxelarChain.chain_name);
url.searchParams.set(
"asset_denom",
// Check if the asset has multiple denoms (indicating wrapped tokens)
!isNil(fromAxelarAsset.denoms) && fromAxelarAsset.denoms.length > 1
? // If the fromAsset address is the native EVM token constant address, use the second denom which is the unwrapped token
fromAsset.address === NativeEVMTokenConstantAddress
? fromAxelarAsset.denoms[1]
: fromAxelarAsset.denoms[0]
: // If there are no multiple denoms, use the default denom
fromAxelarAsset.denom
);
url.searchParams.set("destination_address", toAddress);
return url.toString();
}

packages/bridge/src/axelar/queries.ts Show resolved Hide resolved
@@ -270,7 +270,7 @@ export class SquidBridgeProvider implements BridgeProvider {
const isFromAssetNative =
fromAsset.address === NativeEVMTokenConstantAddress;
const squidFromChain = (await this.getChains()).find(({ chainId }) => {
return chainId === fromChain.chainId;
return String(chainId) === String(fromChain.chainId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistent string comparison for chain IDs.

- return String(chainId) === String(fromChain.chainId);
+ return chainId.toString() === fromChain.chainId.toString();

This change ensures that the comparison is explicitly done between string representations, enhancing readability and maintainability.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return String(chainId) === String(fromChain.chainId);
return chainId.toString() === fromChain.chainId.toString();

Consider adding more specific error handling in getChains.

- throw error.data;
+ if (error instanceof ApiClientError) {
+   throw new BridgeError({
+     errorType: BridgeError.NetworkError,
+     message: error.message || "Failed to fetch chain data",
+   });
+ } else {
+   throw error;
+ }

This change provides more specific error handling, distinguishing between API client errors and other types of errors, which can aid in debugging and provide more informative error messages to the user.

Committable suggestion was skipped due to low confidence.

Comment on lines +12 to +21
beforeEach(() => {
server.use(
rest.get("https://api.axelarscan.io/api/getAssets", (_req, res, ctx) => {
return res(ctx.json(MockAxelarAssets));
}),
rest.get("https://api.axelarscan.io/api/getChains", (_req, res, ctx) => {
return res(ctx.json(MockAxelarChains));
})
);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize the setup of mock server handlers.

The repeated use of rest.get can be simplified by combining them into a single server.use call to streamline the setup.

- server.use(
-   rest.get("https://api.axelarscan.io/api/getAssets", (_req, res, ctx) => {
-     return res(ctx.json(MockAxelarAssets));
-   }),
-   rest.get("https://api.axelarscan.io/api/getChains", (_req, res, ctx) => {
-     return res(ctx.json(MockAxelarChains));
-   })
- );
+ server.use(
+   rest.get("https://api.axelarscan.io/api/getAssets", (_req, res, ctx) => res(ctx.json(MockAxelarAssets))),
+   rest.get("https://api.axelarscan.io/api/getChains", (_req, res, ctx) => res(ctx.json(MockAxelarChains)))
+ );
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
beforeEach(() => {
server.use(
rest.get("https://api.axelarscan.io/api/getAssets", (_req, res, ctx) => {
return res(ctx.json(MockAxelarAssets));
}),
rest.get("https://api.axelarscan.io/api/getChains", (_req, res, ctx) => {
return res(ctx.json(MockAxelarChains));
})
);
});
beforeEach(() => {
server.use(
rest.get("https://api.axelarscan.io/api/getAssets", (_req, res, ctx) => res(ctx.json(MockAxelarAssets))),
rest.get("https://api.axelarscan.io/api/getChains", (_req, res, ctx) => res(ctx.json(MockAxelarChains)))
);
});

Comment on lines +166 to +167
fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper handling of transaction data in the test for creating an EVM transaction.

- fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
- toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
+ fromChain: { chainId: '1', chainName: "Ethereum", chainType: "evm" },
+ toChain: { chainId: '43114', chainName: "Avalanche", chainType: "evm" },

This change ensures that chain IDs are consistently used as strings across all test cases, aligning with the updated schema definitions.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
fromChain: { chainId: '1', chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: '43114', chainName: "Avalanche", chainType: "evm" },

Comment on lines +102 to +111
chainId: 989898989898,
chainName: "Unsupported",
chainType: "evm",
networkName: "unsupported",
},
toChain: {
chainId: "unsupported",
chainId: 989898989898,
chainName: "Unsupported",
chainType: "evm",
networkName: "unsupported",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refine the error message for better clarity in the test for unsupported chains.

- }).rejects.toThrow("Unsupported chain");
+ }).rejects.toThrow("Unsupported chain: Chain ID 989898989898 is not supported.");

This change provides a more descriptive error message, which can help in debugging and understanding the specific cause of the error.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
chainId: 989898989898,
chainName: "Unsupported",
chainType: "evm",
networkName: "unsupported",
},
toChain: {
chainId: "unsupported",
chainId: 989898989898,
chainName: "Unsupported",
chainType: "evm",
networkName: "unsupported",
chainId: 989898989898,
chainName: "Unsupported",
chainType: "evm",
networkName: "unsupported",
},
toChain: {
chainId: 989898989898,
chainName: "Unsupported",
chainType: "evm",
networkName: "unsupported",
```
}).rejects.toThrow("Unsupported chain: Chain ID 989898989898 is not supported.");

Comment on lines +448 to +449
fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve error handling in the test for getQuote.

- }).rejects.toThrow("Query client error");
+ }).rejects.toThrow(new Error("Query client error"));

This change ensures that errors are properly instantiated and thrown, which can help in debugging and understanding the specific cause of the error.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
// Assuming the context of the test case is provided here
await expect(getQuote()).rejects.toThrow(new Error("Query client error"));

Comment on lines +84 to +85
fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistent use of numeric chain IDs in test cases.

- fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
- toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
+ fromChain: { chainId: '1', chainName: "Ethereum", chainType: "evm" },
+ toChain: { chainId: '43114', chainName: "Avalanche", chainType: "evm" },

This change ensures that chain IDs are consistently used as strings across all test cases, aligning with the updated schema definitions.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fromChain: { chainId: 1, chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: 43114, chainName: "Avalanche", chainType: "evm" },
fromChain: { chainId: '1', chainName: "Ethereum", chainType: "evm" },
toChain: { chainId: '43114', chainName: "Avalanche", chainType: "evm" },

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (3)
packages/bridge/src/axelar/__tests__/axelar-bridge-provider.spec.ts (1)

Line range hint 17-26: Consider using arrow functions for better readability and consistency.

- jest.mock("viem", function () {
+ jest.mock("viem", () => {
  return {
    ...jest.requireActual("viem"),
    createPublicClient: jest.fn().mockImplementation(() => ({
      estimateGas: jest.fn().mockResolvedValue(BigInt("21000")),
      getGasPrice: jest.fn().mockResolvedValue(BigInt("0x4a817c800")),
    })),
    http: jest.fn(),
  };
- });
+ });
packages/bridge/src/axelar/index.ts (2)

Line range hint 311-313: Consider omitting the else clause as previous branches break early, improving code readability.

- } else {
+ }

Line range hint 365-375: Consider omitting the else clause as previous branches break early, improving code readability.

- } else {
+ }

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
packages/bridge/src/axelar/index.ts (1)

Line range hint 311-313: Consider removing unnecessary else clauses.

The static analysis tool has identified unnecessary else clauses that can be removed to simplify the code. If these clauses are indeed redundant, removing them could enhance code readability and maintainability.

Also applies to: 365-375

Comment on lines +504 to +508
throw new Error(
`Unsupported chain: Chain ID ${
!fromChainAxelarId ? fromChain.chainId : toChain.chainId
} is not supported.`
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refine the error handling for unsupported chains.

The error message construction can be optimized by directly using template literals for the entire message, which enhances readability and maintainability:

- throw new Error(
-   `Unsupported chain: Chain ID ${
-     !fromChainAxelarId ? fromChain.chainId : toChain.chainId
-   } is not supported.`
- );
+ throw new Error(`Unsupported chain: Chain ID ${fromChainAxelarId ? toChain.chainId : fromChain.chainId} is not supported.`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
throw new Error(
`Unsupported chain: Chain ID ${
!fromChainAxelarId ? fromChain.chainId : toChain.chainId
} is not supported.`
);
throw new Error(`Unsupported chain: Chain ID ${fromChainAxelarId ? toChain.chainId : fromChain.chainId} is not supported.`);

@vercel vercel bot temporarily deployed to prod_swap_test June 12, 2024 18:31 Inactive
@JoseRFelix JoseRFelix merged commit c67f6eb into stage Jun 12, 2024
28 checks passed
@JoseRFelix JoseRFelix deleted the jose/fe-471-support-external-url-providers branch June 12, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants