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

bug: getRoutes fails when passing amount as integer #225

Open
daniel0ar opened this issue Dec 10, 2024 · 1 comment
Open

bug: getRoutes fails when passing amount as integer #225

daniel0ar opened this issue Dec 10, 2024 · 1 comment

Comments

@daniel0ar
Copy link

daniel0ar commented Dec 10, 2024

When using the getRoutes function from the asdk and passing in an integer as the "fromAmount" parameter the function call fails and returns no clear error message:

code: 1001,
name: 'SDKError',
cause: ValidationError: Invalid routes request.

In contrast, this does not happen in the getQuote function call.

Examples

This is a success in getQuote (see amount as integer):

const result = await getQuote({
  fromChain: 42161,
  toChain: 10,
  fromToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
  toToken: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
  fromAmount: 10000000
  // The address from which the tokens are being transferred.
  fromAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0', 
})

This is an error in getRoutes:

const result = await getRoutes({
  fromChainId: 42161,
  toChainId: 10,
  fromTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
  toTokenAddress: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
  fromAmount: 10000000,
  fromAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0', 
})

However, this is a success (notice using string insead of integer):

const result = await getRoutes({
  fromChainId: 42161,
  toChainId: 10,
  fromTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
  toTokenAddress: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
  fromAmount: '10000000' ,
  fromAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0', 
})

Solution

Add support for integers alongside strings for the parameter "fromAmount".

Sidenote

Parameters having different names in RoutesRequest and QuoteRequest is a potential error vector. Just standarize all param names (a.ka instead of having fromChain in getQuote and fromChainId in getRoutes, just use fromChain)

@chybisov
Copy link
Member

@daniel0ar Hey, thanks for pointing this out! Yeah, the inconsistency is due to how the SDK types are set up to match our API:

https://apidocs.li.fi/reference/get_v1-quote
https://apidocs.li.fi/reference/post_v1-advanced-routes

Definitely not ideal, and we’re planning to clean this up in the next major version of the SDK soon. Thanks again for helping us improve 🙂

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

No branches or pull requests

2 participants