CetusProtocol / cetus-clmm-sui-sdk

The clmm sdk on Sui.
Apache License 2.0
35 stars 25 forks source link

error: Failed tp [arse response from https://api-sui.devcetus.com/v2/sui/swap/count]. #10

Closed on1force closed 1 week ago

on1force commented 1 month ago

came from this function.

async getPoolByCoins(coins, feeRate) {
    if (coins.length === 0) {
      return [];
    }
    const url = this._sdk.sdkOptions.swapCountUrl;
    const response = await fetch(url);
    let json;
    try {
      json = await response.json();
    } catch (e) {
      throw new ClmmpoolsError(`Failed tp [arse response from ${url}].`, "InvalidSwapCountUrl" /* InvalidSwapCountUrl */);
    }
    const pools = json.data.lp_list;
    if (!pools || pools.length === 0) {
      throw new ClmmpoolsError(`Failed tp [arse response from ${url}].`, "PoolsNotFound" /* PoolsNotFound */);
    }
    const poolAddresses = [];
    for (const pool of pools) {
      if (coins.includes(pool.coin_a_address) && coins.includes(pool.coin_b_address)) {
        if (feeRate != null) {
          if (pool.object.feeRate === feeRate) {
            poolAddresses.push(pool.address);
          }
        } else {
          poolAddresses.push(pool.address);
        }
      }
    }
    if (poolAddresses.length > 0) {
      const poolObjects = await this.getPools(poolAddresses);
      return poolObjects;
    }
    return [];
  }

the culprit is const pools = json.data.lp_list;. the specified lp_list doesn't exist on the response object. it should be json.data.pools.

image