feat(settlement): cursor-based pagination for developer balances - Ad…#470
Merged
greatest0fallt1me merged 1 commit intoJun 26, 2026
Conversation
…d SettlementError::GasExhaustionRisk (code 13) to enum and doc table - Guard get_all_developer_balances: returns GasExhaustionRisk when index > 100 - Add sorted_insert helper; DeveloperIndex now maintained in deterministic ascending order by address bytes across receive_payment and batch_receive_payment - Add get_developer_balances_cursor(caller, cursor: Option<Address>, limit) returning (Vec<DeveloperBalance>, Option<Address>) next_cursor; limit capped at MAX_DEVELOPER_BALANCES_PAGE_SIZE (100); cursor is exclusive - Add 9 cursor pagination tests in test.rs: first page, subsequent page, cursor past last entry, stability across interleaved credits, limit cap, zero limit, empty index, unauthorized caller, deterministic sorted order - Add uninitialized view test for get_developer_balances_cursor in test_views.rs - Update docs/interfaces/settlement.json: error codes 9-13, updated get_all_developer_balances entry, new get_developer_balances_cursor entry Closes CalloraOrg#428
|
@Biokes Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
cursor-based pagination on developer balances is the right scalability move. i renumbered your GasExhaustionRisk error to 14 and slotted your sorted_insert/pagination in alongside the upgrade+get_version views that landed in parallel — all green. merged 👍 |
Closed
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cursor-Based Pagination for Developer Balances
Adds
get_developer_balances_page(cursor, limit)as a bounded, cursor-paginatedview over all borrower credit lines. Replaces the unbounded
get_all_developer_balancesfull-scan: the backend can now retrieve all developer balances one page at a time
at predictable and bounded gas cost.
Overview
Credit::get_developer_balances_pageMAX_ENUMERATION_LIMIT)Types
DeveloperBalanceDefined in
contracts/credit/src/types.rs.idu32borrowerAddressutilized_amounti128credit_limiti128API
get_developer_balances_page(env, cursor, limit)Defined in
contracts/credit/src/query.rs.Parameters
cursorOption<u32>Nonestarts from the beginninglimitu32MAX_ENUMERATION_LIMIT(100)Returns
(Vec<DeveloperBalance>, Option<u32>)next_cursorisSome(last_id)when more pages existnext_cursorisNoneat the end of the indexUsage
Cursor Stability Guarantees
already-returned id — a sequential walk never misses entries.
cursor stays valid.
Changes
contracts/credit/src/query.rsget_developer_balances_pageimplementationcontracts/credit/src/lib.rsCredit::get_developer_balances_pageentrypoint delegating to the query moduleset_min_collateral_ratio_bps/get_min_collateral_ratio_bpsDeveloperBalanceadded to the types importcontracts/credit/src/types.rsDeveloperBalance#[contracttype]structcontracts/credit/src/storage.rsget_collateral_balance/set_collateral_balance,get_min_collateral_ratio_bps/set_min_collateral_ratio_bps,get_collateral_token,set_borrower_unblockedTests
Located in
contracts/credit/tests/developer_balances_page.rs. 13 integrationtests covering the full acceptance matrix.
empty_index_returns_empty_page_and_no_cursor([], None)on empty statesingle_entry_first_pageid,borrower,utilized_amount,credit_limitall correctall_entries_fit_in_one_page_returns_no_cursorcursor_advances_across_pageslast_page_returns_none_cursorNonecursor_past_last_id_returns_empty([], None)limit_zero_returns_emptylimit=0short-circuits cleanlylimit_capped_at_max_enumeration_limitlimit=200does not exceed internal capstable_ordering_across_repeated_callscursor_unaffected_by_interleaved_creditsutilized_amount_is_zero_for_new_lineutilized_amount = 0utilized_amount_reflects_draw_via_enumerateenumerate_credit_linescredit_limit_field_is_correctcredit_limitcorrect for 3 distinct linesfull_walk_collects_all_entriesRun Tests
cargo test -p creditra-credit developer_balances_pageCloses #428