@xoxno/sdk-js 1.0.223 → 1.0.225
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/sdk/stellar/__tests__/admin.test.d.ts +0 -12
- package/dist/cjs/sdk/stellar/__tests__/builders-hubasset.test.d.ts +0 -11
- package/dist/cjs/sdk/stellar/__tests__/governance.test.d.ts +0 -4
- package/dist/cjs/sdk/stellar/__tests__/lending.test.d.ts +0 -20
- package/dist/cjs/sdk/stellar/__tests__/strategy-program.test.d.ts +0 -8
- package/dist/cjs/sdk/stellar/__tests__/swap-history.test.d.ts +1 -0
- package/dist/cjs/sdk/stellar/index.d.ts +1 -0
- package/dist/cjs/sdk/stellar/swap-history.d.ts +25 -0
- package/dist/cjs/sdk/stellar/swap-index.d.ts +2 -0
- package/dist/cjs/sdk/stellar/xdr-compat.d.ts +11 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/sdk/index.js +198 -0
- package/dist/esm/sdk/stellar/admin.js +385 -0
- package/dist/esm/sdk/stellar/auth-policy.js +310 -0
- package/dist/esm/sdk/stellar/cctp.js +23 -0
- package/dist/esm/sdk/stellar/contracts.js +49 -0
- package/dist/esm/sdk/stellar/events/decode.js +415 -0
- package/dist/esm/sdk/stellar/events/id.js +62 -0
- package/dist/esm/sdk/stellar/events/index.js +2 -0
- package/dist/esm/sdk/stellar/governance.js +403 -0
- package/dist/esm/sdk/stellar/index.js +25 -0
- package/dist/esm/sdk/stellar/lending-api-types.js +3 -0
- package/dist/esm/sdk/stellar/lending-read-types.js +1 -0
- package/dist/esm/sdk/stellar/lending-read.js +341 -0
- package/dist/esm/sdk/stellar/lending.js +358 -0
- package/dist/esm/sdk/stellar/math/account.js +256 -0
- package/dist/esm/sdk/stellar/math/index.js +11 -0
- package/dist/esm/sdk/stellar/math/limits.js +273 -0
- package/dist/esm/sdk/stellar/math/projection.js +130 -0
- package/dist/esm/sdk/stellar/math/rates.js +62 -0
- package/dist/esm/sdk/stellar/math/scaled.js +156 -0
- package/dist/esm/sdk/stellar/position-mode.js +11 -0
- package/dist/esm/sdk/stellar/prepare.js +47 -0
- package/dist/esm/sdk/stellar/quote.js +87 -0
- package/dist/esm/sdk/stellar/repay-swap.js +12 -0
- package/dist/esm/sdk/stellar/route-verify.js +285 -0
- package/dist/esm/sdk/stellar/scval-encode.js +464 -0
- package/dist/esm/sdk/stellar/swap-history.js +46 -0
- package/dist/esm/sdk/stellar/swap-index.js +1 -0
- package/dist/esm/sdk/stellar/swap.js +117 -0
- package/dist/esm/sdk/stellar/xdr-compat.js +17 -0
- package/dist/esm/sdk/stellar-schema.js +129 -0
- package/dist/esm/sdk/swagger.js +1957 -0
- package/dist/esm/sdk/types.js +1 -0
- package/dist/esm/sdk/utils.js +21 -0
- package/dist/esm/utils/api.js +169 -0
- package/dist/esm/utils/const.js +11 -0
- package/dist/esm/utils/errors.js +20 -0
- package/dist/esm/utils/guards.js +29 -0
- package/dist/esm/utils/helpers.js +20 -0
- package/dist/esm/utils/regex.js +14 -0
- package/dist/esm/utils/soroban-errors.js +149 -0
- package/dist/index.cjs +1 -1
- package/dist/index.esm.js +1 -2
- package/dist/sdk/stellar/__tests__/admin.test.d.ts +0 -12
- package/dist/sdk/stellar/__tests__/builders-hubasset.test.d.ts +0 -11
- package/dist/sdk/stellar/__tests__/governance.test.d.ts +0 -4
- package/dist/sdk/stellar/__tests__/lending.test.d.ts +0 -20
- package/dist/sdk/stellar/__tests__/strategy-program.test.d.ts +0 -8
- package/dist/sdk/stellar/__tests__/swap-history.test.d.ts +1 -0
- package/dist/sdk/stellar/index.cjs +1 -1
- package/dist/sdk/stellar/index.d.ts +1 -0
- package/dist/sdk/stellar/index.esm.js +1 -1
- package/dist/sdk/stellar/swap-history.d.ts +25 -0
- package/dist/sdk/stellar/swap-index.cjs +2 -0
- package/dist/sdk/stellar/swap-index.d.ts +2 -0
- package/dist/sdk/stellar/swap-index.esm.js +2 -0
- package/dist/sdk/stellar/swap-index.esm.js.LICENSE.txt +8 -0
- package/dist/sdk/stellar/xdr-compat.d.ts +11 -0
- package/package.json +16 -5
- /package/dist/{index.esm.js.LICENSE.txt → sdk/stellar/swap-index.cjs.LICENSE.txt} +0 -0
|
@@ -1,13 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Snapshot + structural tests for the Stellar lending admin / config / keeper /
|
|
3
|
-
* access transaction builders.
|
|
4
|
-
*
|
|
5
|
-
* Beyond the function-name / arg-count / determinism / snapshot guards, this
|
|
6
|
-
* suite decodes the complex `#[contracttype]` struct args
|
|
7
|
-
* (`MarketOracleConfigInput`, `AssetConfigRaw`) back out of the XDR and asserts
|
|
8
|
-
* the ScMap keys are ascending-sorted (the Soroban host requires sorted symbol
|
|
9
|
-
* keys) and that the oracle union / custom-option tags are well-formed. For the
|
|
10
|
-
* all-lowercase snake_case field sets used here, JS lexicographic order matches
|
|
11
|
-
* Soroban's symbol collation.
|
|
12
|
-
*/
|
|
13
1
|
export {};
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Multi-hub ABI encoding tests for the Stellar lending builders.
|
|
3
|
-
*
|
|
4
|
-
* Asserts the on-the-wire ScVal shape after the migration from the old
|
|
5
|
-
* `(Address, i128)` + `e_mode_category` ABI to the multi-hub
|
|
6
|
-
* `(HubAssetKey, i128)` + `spoke_id` ABI:
|
|
7
|
-
* - `supply` carries `spoke_id` as a `u32` and a `Vec<(HubAssetKey, i128)>`.
|
|
8
|
-
* - each `HubAssetKey` is a struct/map whose symbol keys are sorted
|
|
9
|
-
* (`asset`, `hub_id`) — the canonical Soroban `#[contracttype]` layout.
|
|
10
|
-
* - `borrow` carries the same `Vec<(HubAssetKey, i128)>` payload.
|
|
11
|
-
*/
|
|
12
1
|
export {};
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Snapshot + sanity tests for the Stellar Soroban lending transaction builders.
|
|
3
|
-
*
|
|
4
|
-
* These tests assert:
|
|
5
|
-
* 1. Every builder returns a non-empty base64 XDR.
|
|
6
|
-
* 2. XDR parses back into a valid Transaction with exactly one InvokeHostFunction
|
|
7
|
-
* operation targeting the configured controller contract.
|
|
8
|
-
* 3. The function name encoded in the XDR matches the Stellar controller
|
|
9
|
-
* entry point exactly (`supply`, `borrow`, `withdraw`, `repay`,
|
|
10
|
-
* `liquidate`, `flash_loan`, `multiply`, `swap_debt`, `swap_collateral`,
|
|
11
|
-
* `repay_debt_with_collateral`).
|
|
12
|
-
* 4. The XDR is deterministic — identical fixture inputs yield identical XDR.
|
|
13
|
-
* 5. Stable snapshots for the full XDR of every builder (regression guard
|
|
14
|
-
* for any unintended encoding change).
|
|
15
|
-
*
|
|
16
|
-
* Builders are RPC-free — they accept a `sourceSequence` so output is
|
|
17
|
-
* fully deterministic and snapshot-testable. The UI layer is responsible
|
|
18
|
-
* for fetching the sequence and running `rpc.Server.prepareTransaction`
|
|
19
|
-
* before signing.
|
|
20
|
-
*/
|
|
21
1
|
export {};
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cross-language wire-format check for the aggregator's packed strategy program.
|
|
3
|
-
*
|
|
4
|
-
* The same fixtures are asserted byte-for-byte in
|
|
5
|
-
* `contracts/swap-aggregator/tests/unit/payload_wire_format.rs` and
|
|
6
|
-
* `arb-algo/stellar-indexer/src/transaction/abi.rs`. If this file and those
|
|
7
|
-
* diverge, routes built by this SDK will be rejected on-chain.
|
|
8
|
-
*/
|
|
9
1
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -14,6 +14,7 @@ export * from './governance.js';
|
|
|
14
14
|
export * from './events/index.js';
|
|
15
15
|
export * from './quote.js';
|
|
16
16
|
export * from './swap.js';
|
|
17
|
+
export * from './swap-history.js';
|
|
17
18
|
export * from './route-verify.js';
|
|
18
19
|
export * from './auth-policy.js';
|
|
19
20
|
export * from './prepare.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface StellarSwapEnvelopeOptions {
|
|
2
|
+
envelopeXdr: string;
|
|
3
|
+
networkPassphrase: string;
|
|
4
|
+
/** Router pinned by the application for this network. */
|
|
5
|
+
routerAddress: string;
|
|
6
|
+
/** Only swaps whose encoded sender equals this address are returned. */
|
|
7
|
+
viewer: string;
|
|
8
|
+
/** Zero-based operation index in the inner transaction. */
|
|
9
|
+
operationIndex?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface DecodedStellarSwapEnvelope {
|
|
12
|
+
tokenIn: string;
|
|
13
|
+
tokenOut: string;
|
|
14
|
+
/** Exact positive input in base units; never converted to a JS number. */
|
|
15
|
+
amountInAtoms: string;
|
|
16
|
+
operationIndex: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Synchronously decode direct XOXNO router swaps, including fee-bump envelopes.
|
|
20
|
+
* Returns null for malformed, unrelated or ambiguous envelopes. Without an
|
|
21
|
+
* operation index exactly one matching swap is required. No RPC or output
|
|
22
|
+
* amount inference: the route minimum is not the amount actually received.
|
|
23
|
+
* The network passphrase parses the envelope; it cannot prove its network.
|
|
24
|
+
*/
|
|
25
|
+
export declare function decodeStellarSwapEnvelope(options: StellarSwapEnvelopeOptions): DecodedStellarSwapEnvelope | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
type FieldValue<T> = T extends (...args: never[]) => infer R ? R : T;
|
|
3
|
+
/** SDK 16 exposes XDR getters; SDK 17 exposes the same fields as properties. */
|
|
4
|
+
export declare function xdrField<T, K extends keyof T>(value: T, key: K): FieldValue<T[K]>;
|
|
5
|
+
export declare function xdrType(value: unknown): string | undefined;
|
|
6
|
+
/** SDK 17 opaque byte fields wrap their Uint8Array in `value`. */
|
|
7
|
+
export declare function xdrBytes(value: {
|
|
8
|
+
bytes: unknown;
|
|
9
|
+
}): Buffer;
|
|
10
|
+
export declare function xdrOpaque(value: unknown): Buffer;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { AddressNotFoundError, CollectionNotFoundError } from "../utils/errors.js";
|
|
2
|
+
import { isAddressValid } from "../utils/helpers.js";
|
|
3
|
+
import { isValidCollectionTicker } from "../utils/regex.js";
|
|
4
|
+
import { endpoints as routes } from "./swagger.js";
|
|
5
|
+
import { coveredMethods } from "./utils.js";
|
|
6
|
+
// Stellar Soroban lending transaction builders (Wave 1B).
|
|
7
|
+
// Additive re-export — no overlap with the auto-generated read SDK.
|
|
8
|
+
export * from "./stellar/index.js";
|
|
9
|
+
const kebabToCamel = (s)=>s.replace(/-([a-z])/g, (_, c)=>c.toUpperCase());
|
|
10
|
+
const makeNode = ()=>({
|
|
11
|
+
static: {},
|
|
12
|
+
params: {},
|
|
13
|
+
leaves: []
|
|
14
|
+
});
|
|
15
|
+
function buildTemplate() {
|
|
16
|
+
const root = makeNode();
|
|
17
|
+
for (const [rawPath, def] of Object.entries(routes)){
|
|
18
|
+
const segs = rawPath.split('/').filter(Boolean);
|
|
19
|
+
let node = root;
|
|
20
|
+
for (const seg of segs){
|
|
21
|
+
if (seg.startsWith(':')) {
|
|
22
|
+
var _node_params, _p;
|
|
23
|
+
const p = kebabToCamel(seg.slice(1));
|
|
24
|
+
node = (_node_params = node.params)[_p = p] || (_node_params[_p] = makeNode());
|
|
25
|
+
} else {
|
|
26
|
+
var _node_static, _k;
|
|
27
|
+
const k = kebabToCamel(seg);
|
|
28
|
+
node = (_node_static = node.static)[_k = k] || (_node_static[_k] = makeNode());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
node.leaves.push({
|
|
32
|
+
rawPath,
|
|
33
|
+
def
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return root;
|
|
37
|
+
}
|
|
38
|
+
function makeLeafHandler(rawPath, def, bound, client) {
|
|
39
|
+
const { input: _input, output: _output, ...rest } = def;
|
|
40
|
+
const core = async (args = {})=>{
|
|
41
|
+
const fullArgs = {
|
|
42
|
+
...bound,
|
|
43
|
+
...args
|
|
44
|
+
};
|
|
45
|
+
const url = rawPath.replace(/:([a-zA-Z_]+)/g, (_, p)=>`${fullArgs[p]}`);
|
|
46
|
+
const paramNames = [
|
|
47
|
+
...rawPath.matchAll(/:([a-zA-Z_]+)/g)
|
|
48
|
+
].map((m)=>m[1]);
|
|
49
|
+
const extraArgs = Object.fromEntries(Object.entries(fullArgs).filter(([k])=>!paramNames.includes(k)));
|
|
50
|
+
const hasAddress = /:address[^A-Z]/.test(rawPath) || 'address' in extraArgs;
|
|
51
|
+
const hasCollection = /:collection[^A-Z]/.test(rawPath) || 'collection' in extraArgs;
|
|
52
|
+
if (hasAddress) {
|
|
53
|
+
const addr = fullArgs.address;
|
|
54
|
+
if (!isAddressValid(addr)) throw new AddressNotFoundError(addr);
|
|
55
|
+
}
|
|
56
|
+
if (hasCollection) {
|
|
57
|
+
const col = fullArgs.collection;
|
|
58
|
+
const bad = Array.isArray(col) ? col.some((x)=>!isValidCollectionTicker(x)) : !isValidCollectionTicker(col);
|
|
59
|
+
if (bad) throw new CollectionNotFoundError(col);
|
|
60
|
+
}
|
|
61
|
+
const extraArgsConv = Object.fromEntries(Object.entries(extraArgs).map(([k, v])=>{
|
|
62
|
+
return [
|
|
63
|
+
k,
|
|
64
|
+
v instanceof FormData ? v : k === 'filter' || k === 'body' ? JSON.stringify(v) : Array.isArray(v) ? v.join(',') : v
|
|
65
|
+
];
|
|
66
|
+
}));
|
|
67
|
+
const { body, auth, method, headers, cache, next, debug, signal, credentials, mode, redirect, referrer, referrerPolicy, integrity, keepalive, priority, window, continuationToken, ...params } = extraArgsConv;
|
|
68
|
+
const Authorization = auth ? `Bearer ${auth}` : undefined;
|
|
69
|
+
// Stellar cursor endpoints declare a query parameter. Other API families
|
|
70
|
+
// retain the legacy header convention.
|
|
71
|
+
if (rawPath.startsWith('/stellar-lending/') && continuationToken !== undefined) {
|
|
72
|
+
params.continuationToken = continuationToken;
|
|
73
|
+
}
|
|
74
|
+
const headersData = {
|
|
75
|
+
...headers,
|
|
76
|
+
...Authorization ? {
|
|
77
|
+
Authorization
|
|
78
|
+
} : {},
|
|
79
|
+
...continuationToken && !rawPath.startsWith('/stellar-lending/') ? {
|
|
80
|
+
'X-Continuation-Token': String(continuationToken)
|
|
81
|
+
} : {}
|
|
82
|
+
};
|
|
83
|
+
const hydratedNext = {
|
|
84
|
+
...next,
|
|
85
|
+
tags: [
|
|
86
|
+
...next?.tags ?? [],
|
|
87
|
+
url
|
|
88
|
+
]
|
|
89
|
+
};
|
|
90
|
+
return client.fetchWithTimeout(url, {
|
|
91
|
+
method,
|
|
92
|
+
params,
|
|
93
|
+
body,
|
|
94
|
+
headers: headersData,
|
|
95
|
+
cache,
|
|
96
|
+
debug,
|
|
97
|
+
...Object.fromEntries(Object.entries({
|
|
98
|
+
signal,
|
|
99
|
+
credentials,
|
|
100
|
+
mode,
|
|
101
|
+
redirect,
|
|
102
|
+
referrer,
|
|
103
|
+
referrerPolicy,
|
|
104
|
+
integrity,
|
|
105
|
+
keepalive,
|
|
106
|
+
priority,
|
|
107
|
+
window
|
|
108
|
+
}).filter(([, value])=>value !== undefined)),
|
|
109
|
+
...hydratedNext ? {
|
|
110
|
+
next: hydratedNext
|
|
111
|
+
} : {}
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const leaf = (args = {})=>core(args);
|
|
115
|
+
for (const verb of Object.keys(rest)){
|
|
116
|
+
if (!coveredMethods.includes(verb)) continue;
|
|
117
|
+
leaf[verb] = (va)=>core({
|
|
118
|
+
...va,
|
|
119
|
+
method: va.method ?? verb.toUpperCase()
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return leaf;
|
|
123
|
+
}
|
|
124
|
+
export function buildSdk(client) {
|
|
125
|
+
const tplRoot = buildTemplate();
|
|
126
|
+
const instantiate = (tpl, bound)=>{
|
|
127
|
+
// 1) detect “one leaf + other children” case
|
|
128
|
+
const leafCount = tpl.leaves.length;
|
|
129
|
+
const staticCount = Object.keys(tpl.static).length;
|
|
130
|
+
const paramCount = Object.keys(tpl.params).length;
|
|
131
|
+
const isLeafWithChildren = leafCount === 1 && staticCount + paramCount > 0;
|
|
132
|
+
let obj;
|
|
133
|
+
// 2) if exactly one leaf and it has static/param siblings → use its handler as the root object
|
|
134
|
+
if (isLeafWithChildren) {
|
|
135
|
+
const { rawPath, def } = tpl.leaves[0];
|
|
136
|
+
obj = makeLeafHandler(rawPath, def, bound, client);
|
|
137
|
+
} else {
|
|
138
|
+
// otherwise, build a plain object and attach all leaves under their keys
|
|
139
|
+
obj = {};
|
|
140
|
+
for (const { rawPath, def } of tpl.leaves){
|
|
141
|
+
const leafKey = kebabToCamel(rawPath.split('/').pop().replace(/^:/, ''));
|
|
142
|
+
obj[leafKey] = makeLeafHandler(rawPath, def, bound, client);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// 3) now merge in all the static‐children
|
|
146
|
+
for (const [key, childTpl] of Object.entries(tpl.static)){
|
|
147
|
+
const produced = instantiate(childTpl, bound);
|
|
148
|
+
// exactly your existing “flatten‐or‐assign” logic will work here
|
|
149
|
+
let flat = produced;
|
|
150
|
+
if (produced && typeof produced === 'object' && key in produced && typeof produced[key] === 'function') {
|
|
151
|
+
const fn = produced[key];
|
|
152
|
+
const rest = Object.fromEntries(Object.entries(produced).filter(([k])=>k !== key));
|
|
153
|
+
const isParamHandler = fn.length === 1;
|
|
154
|
+
if (!isParamHandler) {
|
|
155
|
+
Object.assign(fn, rest);
|
|
156
|
+
flat = fn;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (obj[key] === undefined) {
|
|
160
|
+
obj[key] = flat;
|
|
161
|
+
} else if (typeof obj[key] === 'function') {
|
|
162
|
+
Object.assign(obj[key], flat);
|
|
163
|
+
} else if (typeof flat === 'function') {
|
|
164
|
+
Object.assign(flat, obj[key]);
|
|
165
|
+
obj[key] = flat;
|
|
166
|
+
} else {
|
|
167
|
+
Object.assign(obj[key], flat);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// 4) and then all the param‐children exactly as before
|
|
171
|
+
for (const [paramKey, childTpl] of Object.entries(tpl.params)){
|
|
172
|
+
const paramFn = (value)=>{
|
|
173
|
+
const produced = instantiate(childTpl, {
|
|
174
|
+
...bound,
|
|
175
|
+
[paramKey]: value
|
|
176
|
+
});
|
|
177
|
+
// your existing “unwrap single‐key proxy” hack
|
|
178
|
+
if (produced && typeof produced === 'object' && Object.keys(produced).length === 1 && paramKey in produced && typeof produced[paramKey] === 'function') {
|
|
179
|
+
const leaf = produced[paramKey];
|
|
180
|
+
const proxy = (...a)=>leaf(...a);
|
|
181
|
+
return Object.assign(proxy, leaf);
|
|
182
|
+
}
|
|
183
|
+
return produced;
|
|
184
|
+
};
|
|
185
|
+
if (obj[paramKey]) {
|
|
186
|
+
const prev = obj[paramKey];
|
|
187
|
+
obj[paramKey] = (v)=>({
|
|
188
|
+
...prev(v),
|
|
189
|
+
...paramFn(v)
|
|
190
|
+
});
|
|
191
|
+
} else {
|
|
192
|
+
obj[paramKey] = paramFn;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return obj;
|
|
196
|
+
};
|
|
197
|
+
return instantiate(tplRoot, {});
|
|
198
|
+
}
|