jup-ag / jupiter-quote-api-node

91 stars 32 forks source link

`dexes` and `excludeDexes` are not stringified correctly in query params #21

Open yamen opened 7 months ago

yamen commented 7 months ago

Issue

Array-based query strings such as dexes and excludeDexes are serialised using repeating parameters (eg dexes=Openbook&dexes=Saber) instead of as comma separated strings as expected by the server.

Reproduce

Call with for eg:

{
  inputMint: 'So11111111111111111111111111111111111111112',
  outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
  amount: 100000000000,
  excludeDexes: [ 'Openbook', 'Whirlpool' ]
}

The following will be used as the query parameter:

inputMint=So11111111111111111111111111111111111111112&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amount=100000000000&excludeDexes=Openbook&excludeDexes=Whirlpool

Which will result in the dexes not actually being exlcuded in the resulting quote.

Fix

Overriding the client can fix this as a hack:

const jupiterClient = createJupiterApiClient({
  basePath: JUPITER_API_URL,
  queryParamsStringify: (params) => {
    if (params['excludeDexes']) {
      params['excludeDexes'] = (params['excludeDexes'] as string[]).join(',');
    }
    if (params['dexes']) {
      params['dexes'] = (params['dexes'] as string[]).join(',');
    }
    return querystring(params);
  }
});

But this should ideally be fixed in the runtime where the query string generator can prefer concatenating arrays with commas.