@xoxno/sdk-js 1.0.137 → 1.0.142
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.
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/sdk/index.d.ts +4 -0
- package/dist/cjs/sdk/parseSwagger.d.ts +1 -0
- package/dist/cjs/sdk/stellar/__tests__/admin.test.d.ts +13 -0
- package/dist/cjs/sdk/stellar/__tests__/decode.test.d.ts +10 -0
- package/dist/cjs/sdk/stellar/__tests__/id.test.d.ts +4 -0
- package/dist/cjs/sdk/stellar/__tests__/lending.test.d.ts +21 -0
- package/dist/cjs/sdk/stellar/__tests__/swap.test.d.ts +1 -0
- package/dist/cjs/sdk/stellar/admin.d.ts +170 -0
- package/dist/cjs/sdk/stellar/cctp.d.ts +16 -0
- package/dist/cjs/sdk/stellar/contracts.d.ts +70 -0
- package/dist/cjs/sdk/stellar/events/decode.d.ts +45 -0
- package/dist/cjs/sdk/stellar/events/id.d.ts +40 -0
- package/dist/cjs/sdk/stellar/events/index.d.ts +2 -0
- package/dist/cjs/sdk/stellar/governance.d.ts +158 -0
- package/dist/cjs/sdk/stellar/index.d.ts +11 -0
- package/dist/cjs/sdk/stellar/lending.d.ts +171 -0
- package/dist/cjs/sdk/stellar/position-mode.d.ts +7 -0
- package/dist/cjs/sdk/stellar/prepare.d.ts +25 -0
- package/dist/cjs/sdk/stellar/quote.d.ts +58 -0
- package/dist/cjs/sdk/stellar/repay-swap.d.ts +7 -0
- package/dist/cjs/sdk/stellar/scval-encode.d.ts +115 -0
- package/dist/cjs/sdk/stellar/swap.d.ts +70 -0
- package/dist/cjs/sdk/swagger.d.ts +1967 -0
- package/dist/cjs/sdk/types.d.ts +83 -0
- package/dist/cjs/sdk/utils.d.ts +9 -0
- package/dist/cjs/utils/api.d.ts +36 -0
- package/dist/cjs/utils/const.d.ts +13 -0
- package/dist/cjs/utils/errors.d.ts +12 -0
- package/dist/cjs/utils/guards.d.ts +7 -0
- package/dist/cjs/utils/helpers.d.ts +3 -0
- package/dist/cjs/utils/regex.d.ts +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/sdk/stellar/admin.d.ts +7 -16
- package/dist/sdk/stellar/governance.d.ts +5 -12
- package/package.json +4 -4
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stellar lending user-operation transaction builders.
|
|
3
|
+
*
|
|
4
|
+
* Each builder takes an `*Args` DTO from `@xoxno/types` plus a shared
|
|
5
|
+
* `StellarBuilderOptions` ({ network, caller, sourceSequence, ... }) and returns
|
|
6
|
+
* an unsigned transaction XDR string ready for wallet signing.
|
|
7
|
+
*
|
|
8
|
+
* i128 values cross the boundary as decimal strings, encoded via
|
|
9
|
+
* `new ScInt(str).toI128()`. Addresses (Stellar `G...` accounts and Soroban
|
|
10
|
+
* `C...` contracts) are encoded via `new Address(str).toScVal()`.
|
|
11
|
+
*
|
|
12
|
+
* Builders are RPC-free: they accept a caller-supplied `sourceSequence` so the
|
|
13
|
+
* returned XDR is deterministic and snapshot-testable. The caller fetches the
|
|
14
|
+
* current sequence via `rpc.Server.getAccount(caller)` and runs
|
|
15
|
+
* `rpc.Server.prepareTransaction` (simulation + Soroban footprint/auth/resource
|
|
16
|
+
* fee) before handing the XDR to the wallet to sign.
|
|
17
|
+
*/
|
|
18
|
+
import type { BorrowArgs, FlashLoanArgs, LiquidateArgs, MultiplyArgs, RepayArgs, RepayDebtWithCollateralArgs, SupplyArgs, SwapCollateralArgs, SwapDebtArgs, WithdrawArgs } from '@xoxno/types';
|
|
19
|
+
import { xdr } from '@stellar/stellar-sdk';
|
|
20
|
+
import { type StellarNetwork } from './contracts';
|
|
21
|
+
import { type StellarStrategySwapHopInput, type StellarStrategySwapInput, type StellarStrategySwapPathInput } from './scval-encode';
|
|
22
|
+
/**
|
|
23
|
+
* Stellar `G...` public key of the caller (tx source account).
|
|
24
|
+
*/
|
|
25
|
+
export type StellarAccountAddress = string;
|
|
26
|
+
export interface StellarBuilderOptions {
|
|
27
|
+
network: StellarNetwork;
|
|
28
|
+
caller: StellarAccountAddress;
|
|
29
|
+
/**
|
|
30
|
+
* Current sequence number of the caller account, as a decimal string.
|
|
31
|
+
* Callers fetch this from Soroban RPC (`server.getAccount(caller)`) before
|
|
32
|
+
* building. Keeping it as an input (rather than fetching inside the builder)
|
|
33
|
+
* makes builders sync-friendly, RPC-free, and deterministic for snapshot tests.
|
|
34
|
+
*/
|
|
35
|
+
sourceSequence: string;
|
|
36
|
+
/**
|
|
37
|
+
* Override the controller contract address. Normally resolved from env via
|
|
38
|
+
* `getStellarLendingController(network)` — override is for tests and
|
|
39
|
+
* preview/staging deployments.
|
|
40
|
+
*/
|
|
41
|
+
controllerAddress?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Override the governance (timelock) contract address. Normally resolved from
|
|
44
|
+
* env via `getStellarGovernance(network)` — override is for tests and
|
|
45
|
+
* preview/staging deployments. Required (env or override) for the governance
|
|
46
|
+
* `propose_*` / `execute` / `execute_*` builders.
|
|
47
|
+
*/
|
|
48
|
+
governanceAddress?: string;
|
|
49
|
+
/** Base fee in stroops (default BASE_FEE = "100"). */
|
|
50
|
+
fee?: string;
|
|
51
|
+
/** Tx timeout in seconds (default 300). */
|
|
52
|
+
timeoutSeconds?: number;
|
|
53
|
+
}
|
|
54
|
+
export interface BuiltStellarTx {
|
|
55
|
+
/** Unsigned transaction XDR (base64) ready for wallet signing. */
|
|
56
|
+
xdr: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Input shape for the Stellar-specific `swap` payload carried on
|
|
60
|
+
* `MultiplyArgs.steps`, `SwapDebtArgs.steps`, `SwapCollateralArgs.steps`, and
|
|
61
|
+
* `RepayDebtWithCollateralArgs.steps`.
|
|
62
|
+
*
|
|
63
|
+
* `@xoxno/types` declares `steps: unknown` on these DTOs so every chain owns
|
|
64
|
+
* its own encoding. On Stellar, callers pass opaque aggregator strategy bytes,
|
|
65
|
+
* normally the quote response `routeXdr` (base64 ScVal XDR) or `{ routeXdr }`.
|
|
66
|
+
* The lending controller forwards those bytes to the aggregator and does not
|
|
67
|
+
* decode the aggregator route.
|
|
68
|
+
*/
|
|
69
|
+
export type StellarSwapStepsInput = StellarStrategySwapInput;
|
|
70
|
+
export type StellarSwapHopInput = StellarStrategySwapHopInput;
|
|
71
|
+
export type StellarSwapPathInput = StellarStrategySwapPathInput;
|
|
72
|
+
export type { StellarSwapVenue } from './scval-encode';
|
|
73
|
+
/**
|
|
74
|
+
* Assemble an unsigned XDR that invokes a single Soroban contract method.
|
|
75
|
+
*
|
|
76
|
+
* Uses a synthetic `Account(caller, sourceSequence)` — no RPC call. The
|
|
77
|
+
* returned XDR still needs preparation (simulation to populate Soroban
|
|
78
|
+
* footprint + auth entries + resource fees) before signing. The UI layer
|
|
79
|
+
* does this via `rpc.Server.prepareTransaction`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function buildTx(opts: StellarBuilderOptions, method: string, params: xdr.ScVal[]): BuiltStellarTx;
|
|
82
|
+
export interface StellarTokenAmount {
|
|
83
|
+
token: string;
|
|
84
|
+
amount: string;
|
|
85
|
+
}
|
|
86
|
+
export interface StellarSupplyBatchArgs {
|
|
87
|
+
accountNonce?: number;
|
|
88
|
+
eModeCategory?: number;
|
|
89
|
+
assets: ReadonlyArray<StellarTokenAmount>;
|
|
90
|
+
}
|
|
91
|
+
export interface StellarBorrowBatchArgs {
|
|
92
|
+
accountNonce: number;
|
|
93
|
+
borrows: ReadonlyArray<StellarTokenAmount>;
|
|
94
|
+
}
|
|
95
|
+
export interface StellarWithdrawBatchArgs {
|
|
96
|
+
accountNonce: number;
|
|
97
|
+
withdrawals: ReadonlyArray<StellarTokenAmount>;
|
|
98
|
+
/**
|
|
99
|
+
* Optional recipient override (`C...` or `G...`). The pool pays the
|
|
100
|
+
* withdrawn tokens to this address instead of the caller. Omit for the
|
|
101
|
+
* standard flow — the contract arg is still sent, encoded as
|
|
102
|
+
* `Option::None` (ScVal void), which the controller resolves to the
|
|
103
|
+
* caller.
|
|
104
|
+
*/
|
|
105
|
+
to?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface StellarRepayBatchArgs {
|
|
108
|
+
accountNonce: number;
|
|
109
|
+
payments: ReadonlyArray<StellarTokenAmount>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* supply(caller, account_id: u64, e_mode_category: u32, assets: Vec<(Address, i128)>)
|
|
113
|
+
*/
|
|
114
|
+
export declare function buildStellarSupplyBatchTx(opts: StellarBuilderOptions, args: StellarSupplyBatchArgs): BuiltStellarTx;
|
|
115
|
+
/**
|
|
116
|
+
* @xoxno/types `SupplyArgs` is a single-asset shape; the Stellar contract
|
|
117
|
+
* expects a batch — we wrap the single asset in a 1-element Vec.
|
|
118
|
+
*/
|
|
119
|
+
export declare function buildStellarSupplyTx(opts: StellarBuilderOptions, args: SupplyArgs): BuiltStellarTx;
|
|
120
|
+
export declare function buildStellarBorrowBatchTx(opts: StellarBuilderOptions, args: StellarBorrowBatchArgs): BuiltStellarTx;
|
|
121
|
+
/**
|
|
122
|
+
* borrow(caller, account_id: u64, borrows: Vec<(Address, i128)>)
|
|
123
|
+
*/
|
|
124
|
+
export declare function buildStellarBorrowTx(opts: StellarBuilderOptions, args: BorrowArgs): BuiltStellarTx;
|
|
125
|
+
export declare function buildStellarWithdrawBatchTx(opts: StellarBuilderOptions, args: StellarWithdrawBatchArgs): BuiltStellarTx;
|
|
126
|
+
/**
|
|
127
|
+
* withdraw(caller, account_id: u64, withdrawals: Vec<(Address, i128)>,
|
|
128
|
+
* to: Option<Address>) — `to` is always sent; absent means the caller
|
|
129
|
+
* receives the funds.
|
|
130
|
+
*/
|
|
131
|
+
export declare function buildStellarWithdrawTx(opts: StellarBuilderOptions, args: WithdrawArgs): BuiltStellarTx;
|
|
132
|
+
export declare function buildStellarRepayBatchTx(opts: StellarBuilderOptions, args: StellarRepayBatchArgs): BuiltStellarTx;
|
|
133
|
+
/**
|
|
134
|
+
* repay(caller, account_id: u64, payments: Vec<(Address, i128)>)
|
|
135
|
+
*/
|
|
136
|
+
export declare function buildStellarRepayTx(opts: StellarBuilderOptions, args: RepayArgs): BuiltStellarTx;
|
|
137
|
+
/**
|
|
138
|
+
* liquidate(liquidator, account_id: u64, debt_payments: Vec<(Address, i128)>)
|
|
139
|
+
*/
|
|
140
|
+
export declare function buildStellarLiquidateTx(opts: StellarBuilderOptions, args: LiquidateArgs): BuiltStellarTx;
|
|
141
|
+
/**
|
|
142
|
+
* flash_loan(caller, asset, amount: i128, receiver, data: Bytes)
|
|
143
|
+
*/
|
|
144
|
+
export declare function buildStellarFlashLoanTx(opts: StellarBuilderOptions, args: FlashLoanArgs): BuiltStellarTx;
|
|
145
|
+
/**
|
|
146
|
+
* multiply(caller, account_id, e_mode_category, collateral_token,
|
|
147
|
+
* debt_to_flash_loan: i128, debt_token, mode: PositionMode,
|
|
148
|
+
* swap: Bytes, initial_payment: Option<(Address, i128)>,
|
|
149
|
+
* convert_swap: Option<Bytes>) -> u64
|
|
150
|
+
*
|
|
151
|
+
* `mode` is a repr(u32) `PositionMode` → encoded as `scvU32`. The two trailing
|
|
152
|
+
* `Option`s seed an optional initial collateral payment and a secondary swap
|
|
153
|
+
* converting it into the collateral token; both omit to Soroban `Void`.
|
|
154
|
+
*/
|
|
155
|
+
export declare function buildStellarMultiplyTx(opts: StellarBuilderOptions, args: MultiplyArgs): BuiltStellarTx;
|
|
156
|
+
/**
|
|
157
|
+
* swap_debt(caller, account_id, existing_debt_token, new_debt_amount: i128,
|
|
158
|
+
* new_debt_token, steps: Bytes)
|
|
159
|
+
*/
|
|
160
|
+
export declare function buildStellarSwapDebtTx(opts: StellarBuilderOptions, args: SwapDebtArgs): BuiltStellarTx;
|
|
161
|
+
/**
|
|
162
|
+
* swap_collateral(caller, account_id, current_collateral, from_amount: i128,
|
|
163
|
+
* new_collateral, steps: Bytes)
|
|
164
|
+
*/
|
|
165
|
+
export declare function buildStellarSwapCollateralTx(opts: StellarBuilderOptions, args: SwapCollateralArgs): BuiltStellarTx;
|
|
166
|
+
/**
|
|
167
|
+
* repay_debt_with_collateral(caller, account_id, collateral_token,
|
|
168
|
+
* collateral_amount: i128, debt_token,
|
|
169
|
+
* steps: Bytes, close_position: bool)
|
|
170
|
+
*/
|
|
171
|
+
export declare function buildStellarRepayDebtWithCollateralTx(opts: StellarBuilderOptions, args: RepayDebtWithCollateralArgs): BuiltStellarTx;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map MVX `PositionMode` numbering to the Stellar lending controller enum.
|
|
3
|
+
*
|
|
4
|
+
* MVX: None=0, Normal=1, Multiply=2, Long=3, Short=4
|
|
5
|
+
* Stellar: Normal=0, Multiply=1, Long=2, Short=3
|
|
6
|
+
*/
|
|
7
|
+
export declare function toStellarPositionMode(mvxMode: number): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FeeBumpTransaction, Transaction } from '@stellar/stellar-sdk';
|
|
2
|
+
import type { BuiltStellarTx } from './lending';
|
|
3
|
+
/**
|
|
4
|
+
* The single `rpc.Server` capability the prepare helpers need. Declared
|
|
5
|
+
* structurally instead of `Pick<rpc.Server, 'prepareTransaction'>` so the
|
|
6
|
+
* published `.d.ts` references stellar-sdk's concrete `Transaction` exports
|
|
7
|
+
* rather than its `rpc` namespace — the namespaced form trips
|
|
8
|
+
* `dts-bundle-generator`'s external-type resolution under stellar-sdk v16. A
|
|
9
|
+
* real `rpc.Server` satisfies this structurally, so call sites are unchanged.
|
|
10
|
+
*/
|
|
11
|
+
export interface StellarTxPreparer {
|
|
12
|
+
prepareTransaction(tx: Transaction | FeeBumpTransaction): Promise<Transaction>;
|
|
13
|
+
}
|
|
14
|
+
export declare function tagStellarInvokedContractError(contractId: string, error: unknown): Error;
|
|
15
|
+
/**
|
|
16
|
+
* Simulate a built Soroban envelope (footprint, auth, resource fee) and return
|
|
17
|
+
* prepared base64 XDR. Optionally tag failures with the invoked contract id so
|
|
18
|
+
* UIs can map `Error(Contract, #N)` codes to the right ABI.
|
|
19
|
+
*/
|
|
20
|
+
export declare function prepareStellarTxXdr(server: StellarTxPreparer, xdr: string, opts?: {
|
|
21
|
+
invokedContractId?: string;
|
|
22
|
+
}): Promise<string>;
|
|
23
|
+
export declare function prepareStellarBuiltTx(server: StellarTxPreparer, built: BuiltStellarTx, opts?: {
|
|
24
|
+
invokedContractId?: string;
|
|
25
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed client for the Stellar aggregator quote server
|
|
3
|
+
* (`GET /api/v1/quote`, `GET /api/v1/tokens`).
|
|
4
|
+
*
|
|
5
|
+
* The quote server is a standalone Rust service (deployed independently
|
|
6
|
+
* of the main XOXNO API), so this module hits its base URL directly
|
|
7
|
+
* rather than routing through the swagger-driven endpoints map.
|
|
8
|
+
*
|
|
9
|
+
* All response shapes are mirrored 1:1 by `@xoxno/types` DTOs
|
|
10
|
+
* (`StellarAggregatorQuoteResponseDto`, `StellarQuotePathDto`, etc.) —
|
|
11
|
+
* the wire shape is camelCase, the Soroban contract receives snake_case
|
|
12
|
+
* after the SDK encoder rewrites field names.
|
|
13
|
+
*/
|
|
14
|
+
import type { StellarAggregatorQuoteRequestDto, StellarAggregatorQuoteResponseDto, StellarTokenKind } from '@xoxno/types';
|
|
15
|
+
import { type StellarNetwork } from './contracts';
|
|
16
|
+
/**
|
|
17
|
+
* Resolved token entry returned by the quote server's tokens endpoint.
|
|
18
|
+
* Mirrors the indexer's `TokenEntry` JSON exactly.
|
|
19
|
+
*/
|
|
20
|
+
export interface StellarQuoteToken {
|
|
21
|
+
/** Canonical token id. `C…` for Soroban contracts; `CODE:GISSUER…`
|
|
22
|
+
* for Classic; `XLM` for native. */
|
|
23
|
+
id: string;
|
|
24
|
+
kind: StellarTokenKind;
|
|
25
|
+
decimals: number;
|
|
26
|
+
/** Soroban Asset Contract peer for Classic assets (null otherwise). */
|
|
27
|
+
sacPeer: string | null;
|
|
28
|
+
/** Classic asset code (for Classic / SAC entries; null for Soroban). */
|
|
29
|
+
code: string | null;
|
|
30
|
+
/** Number of pools touching this token in the current snapshot. */
|
|
31
|
+
degree: number;
|
|
32
|
+
}
|
|
33
|
+
export interface StellarQuoteFetchOptions {
|
|
34
|
+
/** Network selects which base URL to hit. */
|
|
35
|
+
network: StellarNetwork;
|
|
36
|
+
/** Override the resolved base URL (useful for tests / preview). */
|
|
37
|
+
baseUrl?: string;
|
|
38
|
+
/** Per-call fetch options (signal, headers, etc.). */
|
|
39
|
+
fetchOptions?: RequestInit;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Fetch a route quote from the Stellar aggregator quote server.
|
|
43
|
+
*
|
|
44
|
+
* Forward mode: pass `amountIn` to compute the maximum reachable
|
|
45
|
+
* `amountOut`. Reverse mode: pass `amountOut` to compute the minimum
|
|
46
|
+
* `amountIn` that delivers at least that output.
|
|
47
|
+
*
|
|
48
|
+
* Pass both `sender` (G-strkey) and `router` (C-strkey) to receive a
|
|
49
|
+
* ready-to-sign envelope under `transaction.envelopeXdr`. The caller
|
|
50
|
+
* must still run `simulateTransaction` to attach Soroban resource fees
|
|
51
|
+
* before signing.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getStellarAggregatorQuote(request: StellarAggregatorQuoteRequestDto, opts: StellarQuoteFetchOptions): Promise<StellarAggregatorQuoteResponseDto>;
|
|
54
|
+
/**
|
|
55
|
+
* List tokens currently indexed by the quote server. Useful to populate
|
|
56
|
+
* pickers or validate that a user-supplied token has on-chain liquidity.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getStellarQuoteTokens(opts: StellarQuoteFetchOptions): Promise<StellarQuoteToken[]>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StellarStrategyPayloadInput } from './scval-encode';
|
|
2
|
+
/**
|
|
3
|
+
* Placeholder aggregator route when `repay_debt_with_collateral` has
|
|
4
|
+
* `collateral_token === debt_token`. The controller short-circuits and never
|
|
5
|
+
* decodes the route, but the Soroban arg must still be valid `Bytes`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildSameTokenRepaySwapSteps(token: string, collateralAmount: string): StellarStrategyPayloadInput;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soroban `ScVal` encoding primitives for the Stellar lending builders.
|
|
3
|
+
*
|
|
4
|
+
* i128/u128 values cross the boundary as decimal strings (`new ScInt(str)`).
|
|
5
|
+
* Addresses (Stellar `G...` accounts and Soroban `C...` contracts) encode via
|
|
6
|
+
* `new Address(str).toScVal()`.
|
|
7
|
+
*/
|
|
8
|
+
import { xdr } from '@stellar/stellar-sdk';
|
|
9
|
+
/**
|
|
10
|
+
* On-chain swap venues, validated at runtime for a caller-supplied venue.
|
|
11
|
+
* Mirrors the Soroban-only aggregator router's `SwapVenue` enum.
|
|
12
|
+
*/
|
|
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;
|
|
41
|
+
export declare const addr: (a: string) => xdr.ScVal;
|
|
42
|
+
export declare const i128: (s: string) => xdr.ScVal;
|
|
43
|
+
export declare const u32: (n: number) => xdr.ScVal;
|
|
44
|
+
export declare const u64: (n: number | string) => xdr.ScVal;
|
|
45
|
+
export declare const bool: (b: boolean) => xdr.ScVal;
|
|
46
|
+
export declare const str: (s: string) => xdr.ScVal;
|
|
47
|
+
export declare const sym: (s: string) => xdr.ScVal;
|
|
48
|
+
export declare const voidVal: () => xdr.ScVal;
|
|
49
|
+
export declare const vec: (items: xdr.ScVal[]) => xdr.ScVal;
|
|
50
|
+
export declare const bytes: (hex: string) => xdr.ScVal;
|
|
51
|
+
/**
|
|
52
|
+
* Encode a Soroban `BytesN<N>` (default 32) — a fixed-length byte array such as
|
|
53
|
+
* a WASM hash. Validates the decoded length so a malformed hash fails at the
|
|
54
|
+
* SDK boundary, not deep inside the host.
|
|
55
|
+
*/
|
|
56
|
+
export declare const bytesN: (hex: string, length?: number) => xdr.ScVal;
|
|
57
|
+
/**
|
|
58
|
+
* Encode a Soroban `Option<T>`: `None` is `scvVoid`, `Some(x)` is the bare
|
|
59
|
+
* encoded `x` (Soroban does not wrap `Some`). NOT for the contract's custom
|
|
60
|
+
* `OracleSourceConfigInputOption` enum, which is a tagged union — see
|
|
61
|
+
* `encodeOracleSourceConfigInputOption` in `admin.ts`.
|
|
62
|
+
*/
|
|
63
|
+
export declare const option: <T>(value: T | undefined | null, encode: (v: T) => xdr.ScVal) => xdr.ScVal;
|
|
64
|
+
/**
|
|
65
|
+
* Encode a single Soroban tuple `(Address, i128)` as a 2-element `scvVec`.
|
|
66
|
+
*/
|
|
67
|
+
export declare const tupleAddrAmount: (token: string, amount: string) => xdr.ScVal;
|
|
68
|
+
/**
|
|
69
|
+
* Encode `Vec<(Address, i128)>` — a Soroban tuple-vec of (asset, amount).
|
|
70
|
+
* Each tuple is a 2-element `scvVec`.
|
|
71
|
+
*/
|
|
72
|
+
export declare const tupleAddrAmountVec: (entries: Array<{
|
|
73
|
+
token: string;
|
|
74
|
+
amount: string;
|
|
75
|
+
}>) => xdr.ScVal;
|
|
76
|
+
/**
|
|
77
|
+
* Encode a Soroban `struct` — at the XDR level, structs are maps with
|
|
78
|
+
* `Symbol` keys in **lexicographic order** of field names.
|
|
79
|
+
*/
|
|
80
|
+
export declare const scStruct: (fields: Record<string, xdr.ScVal>) => xdr.ScVal;
|
|
81
|
+
/**
|
|
82
|
+
* Encode a Soroban `enum SwapVenue` (tag-only / unit variant). At the XDR level
|
|
83
|
+
* a unit variant is `scvVec([symbol_name])`.
|
|
84
|
+
*/
|
|
85
|
+
export declare const encodeSwapVenue: (venue: StellarSwapVenue) => xdr.ScVal;
|
|
86
|
+
/**
|
|
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.
|
|
90
|
+
*/
|
|
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;
|
|
95
|
+
/**
|
|
96
|
+
* Validate the untyped `steps` field and narrow it to `StrategyPayload`.
|
|
97
|
+
* Throws if the caller passed the wrong shape so the failure surfaces at the
|
|
98
|
+
* SDK boundary, not inside the Soroban host on-chain.
|
|
99
|
+
*/
|
|
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;
|
|
111
|
+
/**
|
|
112
|
+
* Validate the untyped `data` field on FlashLoanArgs and narrow it to
|
|
113
|
+
* Buffer / hex string for Soroban `Bytes` encoding.
|
|
114
|
+
*/
|
|
115
|
+
export declare const asStellarBytes: (data: unknown) => xdr.ScVal;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stellar aggregator router direct-call transaction builder.
|
|
3
|
+
*
|
|
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.
|
|
9
|
+
*
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
import type { StellarAggregatorQuoteResponseDto } from '@xoxno/types';
|
|
14
|
+
import type { BuiltStellarTx, StellarBuilderOptions } from './lending';
|
|
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 {
|
|
21
|
+
/**
|
|
22
|
+
* Override the resolved aggregator router contract address. Normally
|
|
23
|
+
* resolved from `STELLAR_AGGREGATOR_ROUTER[network]`.
|
|
24
|
+
*/
|
|
25
|
+
routerAddress?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Total input amount passed to `execute_strategy` (i128 decimal string).
|
|
28
|
+
* For a quote-derived swap, pass `quote.amountIn`.
|
|
29
|
+
*/
|
|
30
|
+
totalIn: string;
|
|
31
|
+
/**
|
|
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.
|
|
35
|
+
*/
|
|
36
|
+
referralId?: number | string;
|
|
37
|
+
}
|
|
38
|
+
/** @deprecated Use `StellarExecuteStrategyBuilderOptions`. */
|
|
39
|
+
export interface StellarBatchSwapBuilderOptions extends StellarExecuteStrategyBuilderOptions {
|
|
40
|
+
}
|
|
41
|
+
export declare const encodeStrategyPayloadToRouteXdr: (payload: StellarStrategyPayloadInput) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Build an unsigned XDR for a direct user -> aggregator router swap.
|
|
44
|
+
*
|
|
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.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildStellarExecuteStrategyTx(opts: StellarExecuteStrategyBuilderOptions, swap: StellarStrategySwapInput): BuiltStellarTx;
|
|
50
|
+
/**
|
|
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`.
|
|
58
|
+
*/
|
|
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;
|