@somnia-chain/markets-sdk / index / densifyFundingBuckets
Function: densifyFundingBuckets()
densifyFundingBuckets<
T>(candles,intervalSeconds,from,to): (T| {bucketStart:string;intervalSeconds:number;avgFundingRate8h:"0";coverage:"0";filled:true; })[]
Defined in: packages/sdk/src/funding.ts:188
Fill the bucket-grid slots a candle query did not return, over [from, to).
Rollup candles are sparse by construction: a window touched by no settlement's covered span produces no row, because nothing triggered a write. A chart that plots the rows as-is silently closes those gaps and draws funding that never accrued.
This is the ONLY densification the presentation tier should do, and the constraint is as much about what it must not do:
- Missing slots are emitted as zero rate with zero coverage — never as a carry-forward of the previous rate. Carrying forward is the specific error the protocol docs call out: gaps are genuinely zero-funding intervals, and carrying the last rate through the 22h outage these pools actually had would fabricate ~2.6% of funding out of nothing.
- It is not interpolation. Nothing is smoothed, and no real value is altered.
coverage: "0"is what lets a chart hatch or grey the slot rather than draw a zero that looks like a measurement. A filled slot and a genuinely-zero measured slot are different facts, and onlycoveragedistinguishes them.- It never fills slots older than the oldest row it was given. This is the
truncation guard, and it matters because
listFundingRateCandlespages newest-first: 30 days of hourly buckets is 720 rows against a defaultlimitof 500, so a caller who asks for a month gets the newest 500 and no indication that anything was dropped. Filling the 220 missing older slots would render nine days as a funding pause that never happened — reintroducing exactly the ambiguitycoverageexists to remove, one layer up. Refusing to invent them means the window can come back SHORTER than[from, to): read the first element'sbucketStartrather than assuming it equalsfrom, and page withoffsetif you need the rest.
Returned oldest-first, which is chart order — note that listFundingRateCandles
serves newest-first.
Type Parameters
T
T extends FundingBucketLike
Parameters
candles
readonly T[]
rows from client.listFundingRateCandles, any order
intervalSeconds
number
the grid resolution the rows were queried at
from
number | bigint
window start, unix seconds (snapped down to the grid)
to
number | bigint
window end, unix seconds (exclusive)
Returns
(T | { bucketStart: string; intervalSeconds: number; avgFundingRate8h: "0"; coverage: "0"; filled: true; })[]