Skip to content

Conversation

@ruhil6789
Copy link

@ruhil6789 ruhil6789 commented Jan 15, 2026

Summary

This PR updates the Koios provider to align with the IFetcher interface and improve error messaging. The changes address issue #618 by:

  1. Fixed fetchCollectionAssets method signature: Added the missing cursor parameter and next return field to match the IFetcher interface. Implemented proper pagination support using Koios API's limit and offset parameters. The cursor parameter is used as the offset, with a default limit of 500 records per request (Koios API maximum). The method now correctly returns the next cursor when more results are available.

  2. Improved fetchGovernanceProposal error message: Updated the error message to clearly document that governance proposal queries are not supported by Koios API, making it consistent with other providers (Maestro, Yaci, U5C) and providing better developer feedback.

These changes ensure the Koios provider fully implements the IFetcher interface and properly supports pagination for collection assets.

Affect components

  • @meshsdk/provider

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation update (adding or updating documentation related to the project)

Related Issues

Checklist

  • My code is appropriately commented and includes relevant documentation, if necessary
  • I have added tests to cover my changes, if necessary
  • I have updated the documentation, if necessary
  • All new and existing tests pass (i.e. npm run test)
  • The build is pass (i.e. npm run build)

Additional Information

Changes Made:

  1. fetchCollectionAssets method (lines 286-311):

    • Added cursor?: number | string parameter to match IFetcher interface
    • Updated return type to include next?: string | number | null
    • Implemented proper pagination using Koios API's limit and offset parameters
    • Uses limit=500 (Koios API maximum) and converts cursor to offset
    • Calculates next cursor: returns offset + limit when more results are available, null otherwise
    • Improved error handling to return empty array with next: null on error
  2. fetchGovernanceProposal method (lines 459-466):

    • Updated error message from generic "Method not implemented" to specific "Governance proposal queries are not supported by Koios API"
    • Added inline comments explaining the limitation and consistency with other providers

Technical Details:

Pagination Implementation:

  • Koios API supports PostgREST-style pagination with limit and offset parameters
  • Default maximum limit is 500 records per request
  • The cursor parameter is converted to offset (supports both number and string formats)
  • When data.length === limit, there may be more results, so next is set to offset + limit
  • When data.length < limit, all results have been fetched, so next is set to null

Example Usage:
// First page (offset 0)
const page1 = await provider.fetchCollectionAssets(policyId);
// page1.next = 500 if more results exist

// Next page (offset 500)
const page2 = await provider.fetchCollectionAssets(policyId, page1.next);
// Continue until next is null

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.

update koios provider

1 participant