@xoxno/sdk-js 1.0.231 → 1.0.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -535,11 +535,11 @@ export type StellarMarketIndexByHub = {
535
535
  export type ReserveIrmCurveDto = {
536
536
  /** Base borrow rate (ray, 1e27). */
537
537
  "baseRateRay": string;
538
- /** Slope below the optimal utilization (ray). */
538
+ /** Rate added from zero to the mid utilization kink (ray). */
539
539
  "slope1Ray": string;
540
- /** Slope between optimal and mid utilization (ray). */
540
+ /** Rate added between the mid and optimal utilization kinks (ray). */
541
541
  "slope2Ray": string;
542
- /** Slope above the mid utilization (ray). */
542
+ /** Rate added from the optimal kink to full utilization (ray). */
543
543
  "slope3Ray": string;
544
544
  /** Optimal utilization kink (ray). */
545
545
  "optimalUtilizationRay": string;
@@ -37,11 +37,11 @@ export type StellarUserActivityItem = Api.StellarUserActivityItemDto;
37
37
  export type StellarLendingMarketSide = 'deposit' | 'borrow';
38
38
  /** Holder-list balance selector. Also used by holder distribution. */
39
39
  export type StellarLendingHoldersSide = 'deposits' | 'borrows';
40
- /** Time window for API charts. Dates are ISO-8601; bin examples: 1h, 1d. */
40
+ /** Time window for API charts. Dates are calendar days (yyyy-MM-dd, e.g. 2026-09-01); the API rejects ISO-8601 datetimes with HTTP 400. Bin examples: 1h, 1d. */
41
41
  export interface StellarMarketGraphQuery {
42
- /** Window start. */
42
+ /** Window start day, yyyy-MM-dd. */
43
43
  from: string;
44
- /** Window end. */
44
+ /** Window end day, yyyy-MM-dd. */
45
45
  to: string;
46
46
  /** Kusto timespan, for example 1h or 1d. */
47
47
  bin: string;
@@ -51,11 +51,16 @@ export type StellarActivityQuery = (typeof endpoints)['/stellar-lending/users/:o
51
51
  export type StellarActivityPageQuery = (typeof endpoints)['/stellar-lending/users/:owner/activity/page']['input'];
52
52
  export type StellarGovernanceQuery = (typeof endpoints)['/stellar-lending/governance/proposals']['input'];
53
53
  export type StellarPositionsQuery = (typeof endpoints)['/stellar-lending/positions']['input'];
54
+ /** from/to are calendar days (yyyy-MM-dd); the API rejects ISO-8601 datetimes with HTTP 400. */
54
55
  export type StellarRevenueQuery = (typeof endpoints)['/stellar-lending/revenue']['input'];
56
+ /** from/to are calendar days (yyyy-MM-dd); the API rejects ISO-8601 datetimes with HTTP 400. */
55
57
  export type StellarFeeRevenueQuery = (typeof endpoints)['/stellar-lending/revenue/fees']['input'];
56
58
  export type StellarParticipantsQuery = (typeof endpoints)['/stellar-lending/participants']['input'];
59
+ /** from/to are calendar days (yyyy-MM-dd); the API rejects ISO-8601 datetimes with HTTP 400. */
57
60
  export type StellarLiquidationsQuery = (typeof endpoints)['/stellar-lending/liquidations']['input'];
58
61
  export type StellarLiquidationsLeaderboardQuery = (typeof endpoints)['/stellar-lending/liquidations/leaderboard']['input'];
62
+ /** from/to are calendar days (yyyy-MM-dd); the API rejects ISO-8601 datetimes with HTTP 400. */
59
63
  export type StellarVolumeQuery = (typeof endpoints)['/stellar-lending/volume']['input'];
60
64
  export type StellarDistributionQuery = (typeof endpoints)['/stellar-lending/distribution']['input'];
65
+ /** from/to are calendar days (yyyy-MM-dd); the API rejects ISO-8601 datetimes with HTTP 400. */
61
66
  export type StellarRateSpreadQuery = (typeof endpoints)['/stellar-lending/rate-spread']['input'];
@@ -2,7 +2,7 @@ import type { LendingAsset, LendingAssetUsage, LendingPosition } from './types.j
2
2
  export interface StellarLendingReadClientOptions {
3
3
  /** API root, for example https://api.xoxno.com. May include a deployment prefix. */
4
4
  baseUrl: string;
5
- /** Inject the host's fetch implementation when unavailable globally; it must honor redirect: 'error'. */
5
+ /** Inject the host's fetch implementation when unavailable globally; it must honor redirect: 'manual'. */
6
6
  fetch?: typeof globalThis.fetch;
7
7
  }
8
8
  export interface StellarLendingReadOptions {
@@ -7,8 +7,9 @@ export interface MapSorobanErrorOptions {
7
7
  *
8
8
  * RPC simulation errors usually carry only the top-level code
9
9
  * (`HostError: Error(Contract, #N)`). With only the tag, a code raised by a
10
- * nested contract (for example the swap aggregator) cannot be told apart;
11
- * read the simulation's diagnostic events when that matters.
10
+ * nested contract (for example the swap aggregator or a token) cannot be told
11
+ * apart; read the simulation's diagnostic events when that matters.
12
+ * Tag-only matches on codes 1, 3, 6, 10, 11 and 12 return `null`.
12
13
  */
13
14
  contracts?: readonly string[];
14
15
  }
@@ -19,7 +20,11 @@ export interface MapSorobanErrorOptions {
19
20
  * strings can contain unrelated numbers (fees, ledgers, sequence numbers).
20
21
  *
21
22
  * Without `opts.contracts` it maps the first code in the string, whichever
22
- * contract emitted it.
23
+ * contract emitted it. A failed nested call (token, swap aggregator, oracle)
24
+ * reports its own code at the top level, so an unscoped or tag-only result can
25
+ * name the wrong lending error: a token's `#10` BalanceError reads as
26
+ * InvalidWasmHash. Pass `contracts` and, where available, the simulation's
27
+ * diagnostic event log to attribute the code to its emitter.
23
28
  */
24
29
  export declare function mapSorobanError(raw: string, opts?: MapSorobanErrorOptions): {
25
30
  code: number;
@@ -45,12 +45,13 @@ export function createStellarLendingReadClient(options) {
45
45
  while(true){
46
46
  if (visited.has(url.href)) throw new Error('Pagination Link cycle');
47
47
  visited.add(url.href);
48
- // Reject redirects before a custom fetch could forward credentials to another host.
48
+ // Never follow redirects: a custom fetch could forward credentials to another host.
49
+ // 'manual' instead of 'error' because Cloudflare Workers reject redirect: 'error'.
49
50
  const response = await fetcher(url.href, {
50
51
  signal,
51
- redirect: 'error'
52
+ redirect: 'manual'
52
53
  });
53
- if (response.redirected || response.url && new URL(response.url).href !== url.href) {
54
+ if (response.type === 'opaqueredirect' || response.status >= 300 && response.status < 400 || response.redirected || response.url && new URL(response.url).href !== url.href) {
54
55
  throw new Error('Stellar lending redirects are not allowed');
55
56
  }
56
57
  if (!response.ok) throw new Error(`Stellar lending request failed: HTTP ${response.status}`);
@@ -504,6 +504,22 @@
504
504
  message: 'Flash_position ended without supply or positive debt in its debt market.'
505
505
  }
506
506
  };
507
+ /**
508
+ * Stellar Asset Contract (token) errors 1–13 share numbers with GenericError,
509
+ * and a failed nested token call surfaces as the caller's top-level code. The
510
+ * lending contracts never raise these codes on user paths: 1, 3, 11 and 12 are
511
+ * reserved, 6 and 10 are governance-only. A tag-only match on them is a nested
512
+ * token error (for example #10 BalanceError), not InvalidWasmHash.
513
+ * Other overlaps (such as #13 TrustlineMissingError vs AccountNotInMarket)
514
+ * stay ambiguous without diagnostic events.
515
+ */ const NESTED_ONLY_CODES = new Set([
516
+ 1,
517
+ 3,
518
+ 6,
519
+ 10,
520
+ 11,
521
+ 12
522
+ ]);
507
523
  const ERROR_CODE = /Error\(Contract,\s*#(\d+)\)/;
508
524
  const EMITTED_ERROR = /contract:(C[A-Z2-7]{55})[^\n]*?Error\(Contract,\s*#(\d+)\)/g;
509
525
  const INVOKED_TAG = /\[xoxno-invoked:(C[A-Z2-7]{55})\]/;
@@ -515,7 +531,9 @@ const scopedCode = (raw, allowed)=>{
515
531
  if (HAS_EVENT_LOG.test(raw)) return null;
516
532
  const tag = raw.match(INVOKED_TAG);
517
533
  const first = raw.match(ERROR_CODE);
518
- return tag && allowed.has(tag[1]) && first ? Number(first[1]) : null;
534
+ if (!tag || !allowed.has(tag[1]) || !first) return null;
535
+ const code = Number(first[1]);
536
+ return NESTED_ONLY_CODES.has(code) ? null : code;
519
537
  };
520
538
  /**
521
539
  * Extracts a `Error(Contract, #N)` code from a raw Soroban simulation/RPC error
@@ -524,7 +542,11 @@ const scopedCode = (raw, allowed)=>{
524
542
  * strings can contain unrelated numbers (fees, ledgers, sequence numbers).
525
543
  *
526
544
  * Without `opts.contracts` it maps the first code in the string, whichever
527
- * contract emitted it.
545
+ * contract emitted it. A failed nested call (token, swap aggregator, oracle)
546
+ * reports its own code at the top level, so an unscoped or tag-only result can
547
+ * name the wrong lending error: a token's `#10` BalanceError reads as
548
+ * InvalidWasmHash. Pass `contracts` and, where available, the simulation's
549
+ * diagnostic event log to attribute the code to its emitter.
528
550
  */ export function mapSorobanError(raw, opts) {
529
551
  let code;
530
552
  if (opts?.contracts?.length) {