Skip to content

Duplicate results in /extended/v2/pox/cycles/{cycle_number}/signers/{signer_key}/stackers #2022

@aryzing

Description

@aryzing

Describe the bug
The results from /extended/v2/pox/cycles/{cycle_number}/signers/{signer_key}/stackers contain some stackers more than once.

To Reproduce

The following script gets dupes. You can try it with cycle 86 and signer public key 02877ce29ba35458b827a6ea18510b9058ae4c30e2c33d288f2982c13497caec6e

async function getDupes(cycleNumber: number, signerPublicKey: string) {
  function makeEndpoint(
    cycleNumber: number,
    signerPublicKey: string,
    offset: number,
    limit: number,
  ) {
    const baseUrl = "https://api.mainnet.hiro.so";
    const path = `/extended/v2/pox/cycles/${cycleNumber}/signers/0x${signerPublicKey}/stackers?offset=${offset}&limit=${limit}`;
    const endpoint = `${baseUrl}${path}`;
    return endpoint;
  }

  type GetStackersForSignerInPoxCycleResponse = {
    limit: number;
    offset: number;
    total: number;
    results: Array<{
      stacker_address: string;
      stacked_amount: string;
      pox_address: string;
      stacker_type: "pooled" | "solo";
    }>;
  };

  const stackersMap = new Map<string, bigint>();

  let hasMore = true;
  let offset = 0;
  const limit = 200;
  while (hasMore) {
    const res = await fetch(
      makeEndpoint(cycleNumber, signerPublicKey, offset, limit),
      {
        headers: {
          "x-hiro-api-key": hiroApiKey,
        },
      },
    );

    const data = (await res.json()) as GetStackersForSignerInPoxCycleResponse;

    const stackers = data.results;
    for (const stacker of stackers) {
      const stacksAddress = stacker.stacker_address;
      const lockAmount = BigInt(stacker.stacked_amount);

      if (stackersMap.get(stacksAddress)) {
        console.log("Found repeat result from API");
        console.log("  Existing entry:", stackersMap.get(stacksAddress));
        console.log("  New entry:", stacksAddress, lockAmount);
      } else {
        stackersMap.set(stacksAddress, lockAmount);
      }
    }

    offset += data.results.length;
    hasMore = offset < data.total;
  }
}

Expected behavior
No dupes

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions