@xoxno/sdk-js 1.0.119 → 1.0.120

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 @@
1
+ export {};
@@ -17,7 +17,8 @@ export type StellarNetwork = 'mainnet' | 'testnet';
17
17
  export declare const STELLAR_LENDING_CONTROLLER: Record<StellarNetwork, string>;
18
18
  /**
19
19
  * Stellar aggregator router contract addresses per network.
20
- * Targets `batch_execute(BatchSwap)` for direct (non-lending) swaps.
20
+ * Targets `execute_strategy(sender, total_in, swap_xdr)` for direct
21
+ * (non-lending) swaps.
21
22
  * Env vars:
22
23
  * - STELLAR_AGGREGATOR_ROUTER_MAINNET
23
24
  * - STELLAR_AGGREGATOR_ROUTER_TESTNET
@@ -50,6 +51,6 @@ export declare const STELLAR_NETWORK_PASSPHRASE: Record<StellarNetwork, string>;
50
51
  export declare function getStellarLendingController(network: StellarNetwork): string;
51
52
  /**
52
53
  * Assert an aggregator router address is configured for the target network.
53
- * Used by `buildStellarBatchSwapTx` for direct userrouter swaps.
54
+ * Used by `buildStellarExecuteStrategyTx` for direct user -> router swaps.
54
55
  */
55
56
  export declare function getStellarAggregatorRouter(network: StellarNetwork): string;
@@ -15,9 +15,10 @@
15
15
  * `rpc.Server.prepareTransaction` (simulation + Soroban footprint/auth/resource
16
16
  * fee) before handing the XDR to the wallet to sign.
17
17
  */
18
- import type { AggregatorSwapDto, BorrowArgs, FlashLoanArgs, LiquidateArgs, MultiplyArgs, RepayArgs, RepayDebtWithCollateralArgs, SupplyArgs, SwapCollateralArgs, SwapDebtArgs, SwapHopDto, SwapPathDto, SwapVenue, WithdrawArgs } from '@xoxno/types';
18
+ import type { BorrowArgs, FlashLoanArgs, LiquidateArgs, MultiplyArgs, RepayArgs, RepayDebtWithCollateralArgs, SupplyArgs, SwapCollateralArgs, SwapDebtArgs, WithdrawArgs } from '@xoxno/types';
19
19
  import { xdr } from '@stellar/stellar-sdk';
20
20
  import { type StellarNetwork } from './contracts';
21
+ import { type StellarStrategySwapHopInput, type StellarStrategySwapInput, type StellarStrategySwapPathInput } from './scval-encode';
21
22
  /**
22
23
  * Stellar `G...` public key of the caller (tx source account).
23
24
  */
@@ -52,14 +53,16 @@ export interface BuiltStellarTx {
52
53
  * `MultiplyArgs.steps`, `SwapDebtArgs.steps`, `SwapCollateralArgs.steps`, and
53
54
  * `RepayDebtWithCollateralArgs.steps`.
54
55
  *
55
- * `@xoxno/types` declares `steps: unknown` on these DTOs so every chain owns its
56
- * own encoding. On Stellar, callers must pass an `AggregatorSwapDto`, which is
57
- * serialised into the Soroban `AggregatorSwap` struct.
56
+ * `@xoxno/types` declares `steps: unknown` on these DTOs so every chain owns
57
+ * its own encoding. On Stellar, callers pass opaque aggregator strategy bytes,
58
+ * normally the quote response `routeXdr` (base64 ScVal XDR) or `{ routeXdr }`.
59
+ * The lending controller forwards those bytes to the aggregator and does not
60
+ * decode the aggregator route.
58
61
  */
59
- export type StellarSwapStepsInput = AggregatorSwapDto;
60
- export type StellarSwapHopInput = SwapHopDto;
61
- export type StellarSwapPathInput = SwapPathDto;
62
- export type StellarSwapVenue = SwapVenue;
62
+ export type StellarSwapStepsInput = StellarStrategySwapInput;
63
+ export type StellarSwapHopInput = StellarStrategySwapHopInput;
64
+ export type StellarSwapPathInput = StellarStrategySwapPathInput;
65
+ export type { StellarSwapVenue } from './scval-encode';
63
66
  /**
64
67
  * Assemble an unsigned XDR that invokes a single Soroban contract method.
65
68
  *
@@ -98,8 +101,8 @@ export declare function buildStellarFlashLoanTx(opts: StellarBuilderOptions, arg
98
101
  /**
99
102
  * multiply(caller, account_id, e_mode_category, collateral_token,
100
103
  * debt_to_flash_loan: i128, debt_token, mode: PositionMode,
101
- * swap: AggregatorSwap, initial_payment: Option<(Address, i128)>,
102
- * convert_swap: Option<AggregatorSwap>) -> u64
104
+ * swap: Bytes, initial_payment: Option<(Address, i128)>,
105
+ * convert_swap: Option<Bytes>) -> u64
103
106
  *
104
107
  * `mode` is a repr(u32) `PositionMode` → encoded as `scvU32`. The two trailing
105
108
  * `Option`s seed an optional initial collateral payment and a secondary swap
@@ -108,17 +111,17 @@ export declare function buildStellarFlashLoanTx(opts: StellarBuilderOptions, arg
108
111
  export declare function buildStellarMultiplyTx(opts: StellarBuilderOptions, args: MultiplyArgs): BuiltStellarTx;
109
112
  /**
110
113
  * swap_debt(caller, account_id, existing_debt_token, new_debt_amount: i128,
111
- * new_debt_token, steps: SwapSteps)
114
+ * new_debt_token, steps: Bytes)
112
115
  */
113
116
  export declare function buildStellarSwapDebtTx(opts: StellarBuilderOptions, args: SwapDebtArgs): BuiltStellarTx;
114
117
  /**
115
118
  * swap_collateral(caller, account_id, current_collateral, from_amount: i128,
116
- * new_collateral, steps: SwapSteps)
119
+ * new_collateral, steps: Bytes)
117
120
  */
118
121
  export declare function buildStellarSwapCollateralTx(opts: StellarBuilderOptions, args: SwapCollateralArgs): BuiltStellarTx;
119
122
  /**
120
123
  * repay_debt_with_collateral(caller, account_id, collateral_token,
121
124
  * collateral_amount: i128, debt_token,
122
- * steps: SwapSteps, close_position: bool)
125
+ * steps: Bytes, close_position: bool)
123
126
  */
124
127
  export declare function buildStellarRepayDebtWithCollateralTx(opts: StellarBuilderOptions, args: RepayDebtWithCollateralArgs): BuiltStellarTx;
@@ -5,14 +5,39 @@
5
5
  * Addresses (Stellar `G...` accounts and Soroban `C...` contracts) encode via
6
6
  * `new Address(str).toScVal()`.
7
7
  */
8
- import type { AggregatorSwapDto, SwapVenue } from '@xoxno/types';
9
8
  import { xdr } from '@stellar/stellar-sdk';
10
9
  /**
11
10
  * On-chain swap venues, validated at runtime for a caller-supplied venue.
12
- * Mirrors `SWAP_VENUES` from `@xoxno/types` and the contract's `SwapVenue` enum.
11
+ * Mirrors the Soroban-only aggregator router's `SwapVenue` enum.
13
12
  */
14
- export declare const STELLAR_SWAP_VENUES: readonly ["Soroswap", "Aquarius", "Phoenix", "NativeAmm", "StaticBridge"];
15
- export type StellarSwapStepsInput = AggregatorSwapDto;
13
+ export declare const STELLAR_SWAP_VENUES: readonly ["Soroswap", "Aquarius", "Phoenix", "Sushi", "CometDex"];
14
+ export type StellarSwapVenue = (typeof STELLAR_SWAP_VENUES)[number];
15
+ export interface StellarStrategySwapHopInput {
16
+ amountOut: string;
17
+ pool: string;
18
+ tokenIn: string;
19
+ tokenOut: string;
20
+ venue: StellarSwapVenue;
21
+ }
22
+ export interface StellarStrategySwapPathInput {
23
+ hops: StellarStrategySwapHopInput[];
24
+ splitPpm: number;
25
+ }
26
+ export interface StellarStrategyPayloadInput {
27
+ paths: StellarStrategySwapPathInput[];
28
+ referralId?: number | string;
29
+ tokenIn: string;
30
+ tokenOut: string;
31
+ totalMinOut: string;
32
+ }
33
+ export type StellarStrategySwapInput = string | Uint8Array | {
34
+ routeXdr: string;
35
+ } | {
36
+ swapXdr: string;
37
+ } | {
38
+ bytes: string | Uint8Array;
39
+ } | StellarStrategyPayloadInput;
40
+ export type StellarSwapStepsInput = StellarStrategySwapInput;
16
41
  export declare const addr: (a: string) => xdr.ScVal;
17
42
  export declare const i128: (s: string) => xdr.ScVal;
18
43
  export declare const u32: (n: number) => xdr.ScVal;
@@ -57,21 +82,32 @@ export declare const scStruct: (fields: Record<string, xdr.ScVal>) => xdr.ScVal;
57
82
  * Encode a Soroban `enum SwapVenue` (tag-only / unit variant). At the XDR level
58
83
  * a unit variant is `scvVec([symbol_name])`.
59
84
  */
60
- export declare const encodeSwapVenue: (venue: SwapVenue) => xdr.ScVal;
85
+ export declare const encodeSwapVenue: (venue: StellarSwapVenue) => xdr.ScVal;
61
86
  /**
62
- * Encode the controller-facing `AggregatorSwap` struct
63
- * (`{ paths: Vec<SwapPath>, total_min_out: i128 }`).
64
- *
65
- * `SwapPath` is the PPM-split shape: each path declares `split_ppm`
66
- * (parts-per-million share of the batch's total input) and a `hops` chain.
87
+ * Encode the aggregator router's decoded `StrategyPayload` struct. The caller
88
+ * usually receives this as quote `routeXdr`; this helper is for tests and for
89
+ * callers that construct routes locally.
67
90
  */
68
- export declare const encodeAggregatorSwap: (swap: StellarSwapStepsInput) => xdr.ScVal;
91
+ export declare const encodeStrategyPayload: (payload: StellarStrategyPayloadInput) => xdr.ScVal;
92
+ /** @deprecated Use `encodeStrategyPayload`. */
93
+ export declare const encodeAggregatorSwap: (payload: StellarStrategyPayloadInput) => xdr.ScVal;
94
+ export declare const encodeStrategyPayloadToBytes: (payload: StellarStrategyPayloadInput) => xdr.ScVal;
69
95
  /**
70
- * Validate the untyped `steps` field and narrow it to `AggregatorSwapDto`.
96
+ * Validate the untyped `steps` field and narrow it to `StrategyPayload`.
71
97
  * Throws if the caller passed the wrong shape so the failure surfaces at the
72
98
  * SDK boundary, not inside the Soroban host on-chain.
73
99
  */
74
- export declare const asStellarSwapSteps: (steps: unknown) => StellarSwapStepsInput;
100
+ export declare const asStellarStrategyPayload: (steps: unknown) => StellarStrategyPayloadInput;
101
+ /**
102
+ * Encode opaque strategy bytes for the lending controller. Accepted inputs:
103
+ * - quote `routeXdr` base64 string
104
+ * - `{ routeXdr }` / `{ swapXdr }`
105
+ * - raw `Uint8Array` / `{ bytes }`
106
+ * - decoded `StrategyPayload` object
107
+ */
108
+ export declare const asStellarStrategySwapBytes: (steps: unknown) => xdr.ScVal;
109
+ /** @deprecated Use `asStellarStrategyPayload` or `asStellarStrategySwapBytes`. */
110
+ export declare const asStellarSwapSteps: (steps: unknown) => StellarStrategyPayloadInput;
75
111
  /**
76
112
  * Validate the untyped `data` field on FlashLoanArgs and narrow it to
77
113
  * Buffer / hex string for Soroban `Bytes` encoding.
@@ -1,55 +1,70 @@
1
1
  /**
2
2
  * Stellar aggregator router direct-call transaction builder.
3
3
  *
4
- * Builds an unsigned XDR for `router.batch_execute(BatchSwap)` so a
5
- * user can swap A B without involving the lending controller. The
6
- * `BatchSwap.sender` is filled with the caller's G-strkey (the user's
7
- * own SAC balances fund the swap and receive the output).
4
+ * Builds an unsigned XDR for
5
+ * `router.execute_strategy(sender, total_in, swap_xdr)` so a user can swap
6
+ * A -> B without involving the lending controller. The strategy route is
7
+ * opaque bytes: normally the quote response `routeXdr`, decoded into Soroban
8
+ * `Bytes` for the contract call.
8
9
  *
9
- * For lending strategies (multiply / swap_debt / swap_collateral /
10
- * repay_debt_with_collateral) the controller wraps the same payload
11
- * itself and sets `sender = current_contract_address` — those flows
12
- * use the strategy builders in `./lending.ts`, NOT this builder.
10
+ * Lending strategies use the builders in `./lending.ts`; they pass the same
11
+ * opaque route bytes to the controller, which forwards them to the aggregator.
13
12
  */
14
- import type { AggregatorSwapDto, StellarAggregatorQuoteResponseDto } from '@xoxno/types';
13
+ import type { StellarAggregatorQuoteResponseDto } from '@xoxno/types';
15
14
  import type { BuiltStellarTx, StellarBuilderOptions } from './lending';
16
- export interface StellarBatchSwapBuilderOptions extends StellarBuilderOptions {
15
+ import { type StellarStrategyPayloadInput, type StellarStrategySwapHopInput, type StellarStrategySwapInput, type StellarStrategySwapPathInput } from './scval-encode';
16
+ export type StellarStrategyPayload = StellarStrategyPayloadInput;
17
+ export type StellarStrategySwap = StellarStrategySwapInput;
18
+ export type StellarStrategySwapHop = StellarStrategySwapHopInput;
19
+ export type StellarStrategySwapPath = StellarStrategySwapPathInput;
20
+ export interface StellarExecuteStrategyBuilderOptions extends StellarBuilderOptions {
17
21
  /**
18
22
  * Override the resolved aggregator router contract address. Normally
19
23
  * resolved from `STELLAR_AGGREGATOR_ROUTER[network]`.
20
24
  */
21
25
  routerAddress?: string;
22
26
  /**
23
- * Total input amount the router will pull from `caller` once at the
24
- * start of `batch_execute` (i128 decimal string). Per-path
25
- * allocations are derived inside the router from each path's
26
- * `splitPpm`. For a quote-derived swap, pass `quote.amountIn`.
27
+ * Total input amount passed to `execute_strategy` (i128 decimal string).
28
+ * For a quote-derived swap, pass `quote.amountIn`.
27
29
  */
28
30
  totalIn: string;
29
31
  /**
30
- * Referral identifier embedded into the BatchSwap. Defaults to `0`
31
- * (no referral / no fee matches rs-aggregator MVX semantics).
32
- * Non-zero IDs MUST be registered on-chain via `add_referral` or the
33
- * router reverts at execution.
32
+ * Referral identifier used only when the `swap` input is a decoded
33
+ * `StrategyPayload` object and does not already include `referralId`.
34
+ * Quote `routeXdr` already contains the referral chosen by the quote server.
34
35
  */
35
36
  referralId?: number | string;
36
37
  }
38
+ /** @deprecated Use `StellarExecuteStrategyBuilderOptions`. */
39
+ export interface StellarBatchSwapBuilderOptions extends StellarExecuteStrategyBuilderOptions {
40
+ }
41
+ export declare const encodeStrategyPayloadToRouteXdr: (payload: StellarStrategyPayloadInput) => string;
37
42
  /**
38
- * Build an unsigned XDR for a direct user aggregator router swap.
43
+ * Build an unsigned XDR for a direct user -> aggregator router swap.
39
44
  *
40
- * The `swap` payload (paths + total-min-out) comes straight from the
41
- * quote server; map a `StellarAggregatorQuoteResponseDto` to
42
- * `AggregatorSwapDto` via `mapQuoteResponseToAggregatorSwap` before
43
- * calling this. `opts.totalIn` is the authoritative input amount.
45
+ * Pass the quote response `routeXdr` string or `{ routeXdr }` directly when
46
+ * available. Decoded `StrategyPayload` objects are accepted for local tests and
47
+ * custom route builders.
44
48
  */
45
- export declare function buildStellarBatchSwapTx(opts: StellarBatchSwapBuilderOptions, swap: AggregatorSwapDto): BuiltStellarTx;
49
+ export declare function buildStellarExecuteStrategyTx(opts: StellarExecuteStrategyBuilderOptions, swap: StellarStrategySwapInput): BuiltStellarTx;
46
50
  /**
47
- * Translate a quote-server response into the controller-facing
48
- * `AggregatorSwapDto`. Each path's `splitPpm` comes straight from the
49
- * server; the single-path fallback (when `paths` is omitted) gets the
50
- * full 1_000_000 weight.
51
- *
52
- * Throws if `amountOutMin` is missing the controller refuses
53
- * unbounded swaps so the SDK rejects them at the boundary.
51
+ * @deprecated The router no longer exposes `batch_execute`; this wrapper now
52
+ * builds `execute_strategy(sender, total_in, swap_xdr)`.
53
+ */
54
+ export declare function buildStellarBatchSwapTx(opts: StellarBatchSwapBuilderOptions, swap: StellarStrategySwapInput): BuiltStellarTx;
55
+ /**
56
+ * Translate a quote-server response into the decoded `StrategyPayload` shape.
57
+ * Prefer `mapQuoteResponseToStrategySwap` when the quote includes `routeXdr`.
54
58
  */
55
- export declare function mapQuoteResponseToAggregatorSwap(quote: StellarAggregatorQuoteResponseDto): AggregatorSwapDto;
59
+ export declare function mapQuoteResponseToStrategyPayload(quote: StellarAggregatorQuoteResponseDto, opts?: {
60
+ referralId?: number | string;
61
+ }): StellarStrategyPayloadInput;
62
+ /**
63
+ * Return the executable quote route when the API provided it; otherwise build
64
+ * the decoded fallback payload from hop/path fields.
65
+ */
66
+ export declare function mapQuoteResponseToStrategySwap(quote: StellarAggregatorQuoteResponseDto, opts?: {
67
+ referralId?: number | string;
68
+ }): StellarStrategySwapInput;
69
+ /** @deprecated Use `mapQuoteResponseToStrategyPayload`. */
70
+ 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.119",
3
+ "version": "1.0.120",
4
4
  "description": "The SDK to interact with the XOXNO Protocol!",
5
5
  "type": "module",
6
6
  "exports": {