@xoxno/sdk-js 1.0.218 → 1.0.220

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.
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Decoder and pre-signing verifier for the aggregator router's packed route
3
+ * (`routeXdr` / `swap_xdr`).
4
+ *
5
+ * The quote server is unauthenticated and returns the route as an opaque blob
6
+ * next to separate JSON display fields. The router enforces only the minimum
7
+ * that is ENCODED in the blob, so a caller must decode it and compare it with
8
+ * its own request before a wallet signs. The decoder mirrors
9
+ * `contracts/swap-aggregator/src/program.rs` (`Program::decode` + `validate`)
10
+ * and `execute::run` check for check; the encoder is `./scval-encode.ts`.
11
+ */
12
+ import { type StellarNetwork } from './contracts.js';
13
+ import { type StellarStrategySwapInput, type StellarSwapVenue } from './scval-encode.js';
14
+ /**
15
+ * Cap on the serialized payload, checked before XDR parsing so a hostile
16
+ * response cannot force a proportional allocation. The largest legal payload
17
+ * (256 addresses, 126 amounts, 346 program bytes) is below 16 KiB.
18
+ */
19
+ export declare const STELLAR_ROUTE_MAX_BYTES: number;
20
+ export type StellarRouteErrorCode = 'MALFORMED' | 'OVERSIZED' | 'UNSUPPORTED_VERSION' | 'UNKNOWN_OPCODE' | 'INVALID_STRUCTURE' | 'TOKEN_IN_MISMATCH' | 'TOKEN_OUT_MISMATCH' | 'MIN_OUT_TOO_LOW' | 'AMOUNT_IN_EXCEEDED' | 'EXPECTATION_MISSING';
21
+ /** Thrown when a route cannot be decoded or disagrees with the caller's request. */
22
+ export declare class StellarRouteVerificationError extends Error {
23
+ readonly code: StellarRouteErrorCode;
24
+ constructor(code: StellarRouteErrorCode, message: string);
25
+ }
26
+ export type DecodedStellarRouteMode = {
27
+ kind: 'all';
28
+ } | {
29
+ kind: 'prev';
30
+ } | {
31
+ kind: 'fixed';
32
+ amount: bigint;
33
+ } | {
34
+ kind: 'ppm';
35
+ ppm: number;
36
+ };
37
+ export type DecodedStellarRouteOp = {
38
+ kind: 'swap';
39
+ venue: StellarSwapVenue;
40
+ mode: DecodedStellarRouteMode;
41
+ pool: string;
42
+ tokenIn: string;
43
+ tokenOut: string;
44
+ } | {
45
+ kind: 'burn' | 'mint';
46
+ pool: string;
47
+ shareToken: string;
48
+ /** Burn: first index of the per-constituent floor run. Mint: index of the minimum shares. */
49
+ amountIndex: number;
50
+ };
51
+ export interface DecodedStellarRoute {
52
+ version: number;
53
+ tokenIn: string;
54
+ tokenOut: string;
55
+ /** The minimum output the router enforces on chain (`amounts[min_out]`). */
56
+ totalMinOut: bigint;
57
+ referralId: number;
58
+ assets: string[];
59
+ amounts: bigint[];
60
+ ops: DecodedStellarRouteOp[];
61
+ /** Split weights in parts per million. */
62
+ weights: number[];
63
+ }
64
+ /**
65
+ * Any form the builders accept: base64 `routeXdr`, `0x` hex, raw bytes,
66
+ * `{ routeXdr }` / `{ swapXdr }` / `{ bytes }`, or a decoded payload object
67
+ * (encoded locally first, so the check covers exactly what would be signed).
68
+ */
69
+ export type StellarRouteBytesInput = StellarStrategySwapInput;
70
+ /**
71
+ * Decode and structurally validate route bytes. Applies every check of the
72
+ * on-chain decoder, so a route that `Program::decode` rejects does not decode
73
+ * here. Venue behaviour (pools, liquidity, budget) is not checked.
74
+ * @throws StellarRouteVerificationError
75
+ */
76
+ export declare function decodeStellarRouteBytes(route: StellarRouteBytesInput): DecodedStellarRoute;
77
+ /**
78
+ * Contract id of a quote-server token id: `C…` as is, `XLM` / `native` and
79
+ * `CODE:GISSUER` through the Stellar Asset Contract id of `network`.
80
+ * @throws StellarRouteVerificationError when the id needs a network and none is given.
81
+ */
82
+ export declare function stellarTokenContractId(tokenId: string, network?: StellarNetwork): string;
83
+ /** What the CALLER asked for. Take these from request state, not from the response. */
84
+ export interface StellarRouteExpectation {
85
+ /** Input token contract id (`C…`). */
86
+ tokenIn: string;
87
+ /** Output token contract id (`C…`). */
88
+ tokenOut: string;
89
+ /** Lowest acceptable encoded `total_min_out`, base units. This is the value shown to the user. */
90
+ minOut: string | bigint;
91
+ /** Input amount, base units. When given, no fixed-size leg may spend more of `tokenIn`. */
92
+ amountIn?: string | bigint;
93
+ }
94
+ /**
95
+ * Decode `route` and require it to match `expected`. Call before signing any
96
+ * transaction that carries route bytes; never sign when this throws.
97
+ * @returns The decoded route, for display or further checks.
98
+ * @throws StellarRouteVerificationError
99
+ */
100
+ export declare function verifyStellarRouteBytes(route: StellarRouteBytesInput, expected: StellarRouteExpectation): DecodedStellarRoute;
@@ -21,6 +21,16 @@ export declare const STELLAR_SWAP_VENUE_OPCODE: Record<StellarSwapVenue, number>
21
21
  export declare const STELLAR_PROGRAM_VERSION = 1;
22
22
  /** Split weights are parts per million. */
23
23
  export declare const PPM_DENOMINATOR = 1000000;
24
+ export declare const OP_BURN = 5;
25
+ export declare const OP_MINT = 6;
26
+ export declare const MODE_ALL = 0;
27
+ export declare const MODE_PREV = 1;
28
+ export declare const MODE_FIXED_BASE = 2;
29
+ export declare const MODE_PPM_BASE = 128;
30
+ export declare const MAX_OPS = 48;
31
+ export declare const MAX_WEIGHTS = 32;
32
+ export declare const MAX_ASSETS = 256;
33
+ export declare const MAX_AMOUNTS: number;
24
34
  export interface StellarStrategySwapHopInput {
25
35
  /** Quote-side estimate; not carried on the wire. */
26
36
  amountOut?: string;
@@ -11,8 +11,27 @@
11
11
  * opaque route bytes to the controller, which forwards them to the aggregator.
12
12
  */
13
13
  import type { StellarAggregatorQuoteResponseDto } from '@xoxno/types';
14
+ import { type StellarNetwork } from './contracts.js';
14
15
  import type { BuiltStellarTx, StellarBuilderOptions } from './lending.js';
15
16
  import { type StellarStrategyPayloadInput, type StellarStrategySwapHopInput, type StellarStrategySwapInput, type StellarStrategySwapPathInput } from './scval-encode.js';
17
+ /**
18
+ * The caller's own request, used to check a quote before it is signed. Every
19
+ * field that is absent falls back to the quote's JSON, which proves only that
20
+ * the response agrees with itself — pass request state whenever it is known.
21
+ */
22
+ export interface StellarQuoteExpectation {
23
+ tokenIn?: string;
24
+ tokenOut?: string;
25
+ /** Lowest acceptable minimum output, base units. */
26
+ minOut?: string | bigint;
27
+ amountIn?: string | bigint;
28
+ }
29
+ export interface StellarQuoteMapOptions {
30
+ referralId?: number | string;
31
+ /** Needed only when a token id is `XLM` or `CODE:GISSUER` instead of `C…`. */
32
+ network?: StellarNetwork;
33
+ expected?: StellarQuoteExpectation;
34
+ }
16
35
  export type StellarStrategyPayload = StellarStrategyPayloadInput;
17
36
  export type StellarStrategySwap = StellarStrategySwapInput;
18
37
  export type StellarStrategySwapHop = StellarStrategySwapHopInput;
@@ -55,15 +74,16 @@ export declare function buildStellarBatchSwapTx(opts: StellarBatchSwapBuilderOpt
55
74
  * Translate a quote-server response into the decoded `StrategyPayload` shape.
56
75
  * Prefer `mapQuoteResponseToStrategySwap` when the quote includes `routeXdr`.
57
76
  */
58
- export declare function mapQuoteResponseToStrategyPayload(quote: StellarAggregatorQuoteResponseDto, opts?: {
59
- referralId?: number | string;
60
- }): StellarStrategyPayloadInput;
77
+ export declare function mapQuoteResponseToStrategyPayload(quote: StellarAggregatorQuoteResponseDto, opts?: Pick<StellarQuoteMapOptions, 'referralId'>): StellarStrategyPayloadInput;
61
78
  /**
62
79
  * Return the executable quote route when the API provided it; otherwise build
63
80
  * the decoded fallback payload from hop/path fields.
81
+ *
82
+ * Either form is decoded and checked before it is returned: it must spend and
83
+ * deliver the expected pair and enforce a minimum that is not below the
84
+ * quote's `amountOutMin` (what a UI displays) nor below `expected.minOut`.
85
+ * @throws StellarRouteVerificationError — never sign a quote that throws here.
64
86
  */
65
- export declare function mapQuoteResponseToStrategySwap(quote: StellarAggregatorQuoteResponseDto, opts?: {
66
- referralId?: number | string;
67
- }): StellarStrategySwapInput;
87
+ export declare function mapQuoteResponseToStrategySwap(quote: StellarAggregatorQuoteResponseDto, opts?: StellarQuoteMapOptions): StellarStrategySwapInput;
68
88
  /** @deprecated Use `mapQuoteResponseToStrategyPayload`. */
69
89
  export declare const mapQuoteResponseToAggregatorSwap: typeof mapQuoteResponseToStrategyPayload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xoxno/sdk-js",
3
- "version": "1.0.218",
3
+ "version": "1.0.220",
4
4
  "description": "The SDK to interact with the XOXNO Protocol!",
5
5
  "type": "module",
6
6
  "exports": {