@xoxno/sdk-js 1.0.224 → 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.
Files changed (46) hide show
  1. package/dist/esm/index.js +3 -0
  2. package/dist/esm/sdk/index.js +198 -0
  3. package/dist/esm/sdk/stellar/admin.js +385 -0
  4. package/dist/esm/sdk/stellar/auth-policy.js +310 -0
  5. package/dist/esm/sdk/stellar/cctp.js +23 -0
  6. package/dist/esm/sdk/stellar/contracts.js +49 -0
  7. package/dist/esm/sdk/stellar/events/decode.js +415 -0
  8. package/dist/esm/sdk/stellar/events/id.js +62 -0
  9. package/dist/esm/sdk/stellar/events/index.js +2 -0
  10. package/dist/esm/sdk/stellar/governance.js +403 -0
  11. package/dist/esm/sdk/stellar/index.js +25 -0
  12. package/dist/esm/sdk/stellar/lending-api-types.js +3 -0
  13. package/dist/esm/sdk/stellar/lending-read-types.js +1 -0
  14. package/dist/esm/sdk/stellar/lending-read.js +341 -0
  15. package/dist/esm/sdk/stellar/lending.js +358 -0
  16. package/dist/esm/sdk/stellar/math/account.js +256 -0
  17. package/dist/esm/sdk/stellar/math/index.js +11 -0
  18. package/dist/esm/sdk/stellar/math/limits.js +273 -0
  19. package/dist/esm/sdk/stellar/math/projection.js +130 -0
  20. package/dist/esm/sdk/stellar/math/rates.js +62 -0
  21. package/dist/esm/sdk/stellar/math/scaled.js +156 -0
  22. package/dist/esm/sdk/stellar/position-mode.js +11 -0
  23. package/dist/esm/sdk/stellar/prepare.js +47 -0
  24. package/dist/esm/sdk/stellar/quote.js +87 -0
  25. package/dist/esm/sdk/stellar/repay-swap.js +12 -0
  26. package/dist/esm/sdk/stellar/route-verify.js +285 -0
  27. package/dist/esm/sdk/stellar/scval-encode.js +464 -0
  28. package/dist/esm/sdk/stellar/swap-history.js +46 -0
  29. package/dist/esm/sdk/stellar/swap-index.js +1 -0
  30. package/dist/esm/sdk/stellar/swap.js +117 -0
  31. package/dist/esm/sdk/stellar/xdr-compat.js +17 -0
  32. package/dist/esm/sdk/stellar-schema.js +129 -0
  33. package/dist/esm/sdk/swagger.js +1957 -0
  34. package/dist/esm/sdk/types.js +1 -0
  35. package/dist/esm/sdk/utils.js +21 -0
  36. package/dist/esm/utils/api.js +169 -0
  37. package/dist/esm/utils/const.js +11 -0
  38. package/dist/esm/utils/errors.js +20 -0
  39. package/dist/esm/utils/guards.js +29 -0
  40. package/dist/esm/utils/helpers.js +20 -0
  41. package/dist/esm/utils/regex.js +14 -0
  42. package/dist/esm/utils/soroban-errors.js +149 -0
  43. package/dist/index.esm.js +1 -2
  44. package/dist/sdk/stellar/index.esm.js +1 -1
  45. package/package.json +2 -2
  46. package/dist/index.esm.js.LICENSE.txt +0 -8
@@ -0,0 +1,3 @@
1
+ export * from "./utils/api.js";
2
+ export * from "./utils/regex.js";
3
+ export * from "./sdk/index.js";
@@ -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
+ }
@@ -0,0 +1,385 @@
1
+ /**
2
+ * Stellar lending admin / config / keeper / access transaction builders. Each
3
+ * builder returns an unsigned `BuiltStellarTx` XDR.
4
+ *
5
+ * Auth model:
6
+ * - `#[only_owner]` methods take no `caller` param — the tx source
7
+ * (`opts.caller`) must be the contract owner.
8
+ * - `#[only_role(caller, "ROLE")]` and caller-taking methods encode
9
+ * `opts.caller` as the leading `Address` arg; that account must hold the
10
+ * role and sign the tx.
11
+ */ import { addr, bool, bytesN, hubAsset, i128, scStruct, str, sym, tupleHubAssetAmountVec, u32, u64, vec } from "./scval-encode.js";
12
+ import { buildTx } from "./lending.js";
13
+ // -----------------------------------------------------------------------------
14
+ // Complex struct / union encoders
15
+ // -----------------------------------------------------------------------------
16
+ /** `InterestRateModel` — 8 RAY rates + reserve factor bps. */ export const encodeInterestRateModel = (m)=>scStruct({
17
+ base_borrow_rate: i128(m.baseBorrowRateRay),
18
+ max_borrow_rate: i128(m.maxBorrowRateRay),
19
+ max_utilization: i128(m.maxUtilizationRay),
20
+ mid_utilization: i128(m.midUtilizationRay),
21
+ optimal_utilization: i128(m.optimalUtilizationRay),
22
+ reserve_factor: u32(m.reserveFactorBps),
23
+ slope1: i128(m.slope1Ray),
24
+ slope2: i128(m.slope2Ray),
25
+ slope3: i128(m.slope3Ray)
26
+ });
27
+ /** `MarketParamsRaw` — `InterestRateModel` plus the pool asset identity. */ export const encodeMarketParamsRaw = (p)=>scStruct({
28
+ asset_decimals: u32(p.assetDecimals),
29
+ asset_id: addr(p.assetId),
30
+ base_borrow_rate: i128(p.baseBorrowRateRay),
31
+ flashloan_fee: u32(p.flashloanFeeBps),
32
+ is_flashloanable: bool(p.isFlashloanable),
33
+ max_borrow_rate: i128(p.maxBorrowRateRay),
34
+ max_utilization: i128(p.maxUtilizationRay),
35
+ mid_utilization: i128(p.midUtilizationRay),
36
+ optimal_utilization: i128(p.optimalUtilizationRay),
37
+ reserve_factor: u32(p.reserveFactorBps),
38
+ slope1: i128(p.slope1Ray),
39
+ slope2: i128(p.slope2Ray),
40
+ slope3: i128(p.slope3Ray)
41
+ });
42
+ /** `PositionLimits` — per-account supply/borrow position caps. */ export const encodePositionLimits = (l)=>scStruct({
43
+ max_borrow_positions: u32(l.maxBorrowPositions),
44
+ max_supply_positions: u32(l.maxSupplyPositions)
45
+ });
46
+ /** On-chain `PriceKey` — `{ Token: "C…" }` or `{ Ref: "BTC" }`. */ export const encodePriceKey = (key)=>{
47
+ if ('Token' in key && key.Token) return vec([
48
+ sym('Token'),
49
+ addr(key.Token)
50
+ ]);
51
+ if ('Ref' in key && key.Ref) return vec([
52
+ sym('Ref'),
53
+ sym(key.Ref)
54
+ ]);
55
+ throw new Error(`Stellar builder: PriceKey must be { Token } or { Ref }, got ${JSON.stringify(key)}`);
56
+ };
57
+ const encodeOracleAssetRef = (asset)=>{
58
+ if ('Stellar' in asset) return vec([
59
+ sym('Stellar'),
60
+ addr(asset.Stellar)
61
+ ]);
62
+ if ('Symbol' in asset) return vec([
63
+ sym('Symbol'),
64
+ sym(asset.Symbol)
65
+ ]);
66
+ if ('String' in asset) return vec([
67
+ sym('String'),
68
+ str(asset.String)
69
+ ]);
70
+ throw new Error(`Stellar builder: unknown OracleAssetRef ${JSON.stringify(asset)}`);
71
+ };
72
+ const encodeOracleReadMode = (mode)=>{
73
+ if (mode === 'Spot') return vec([
74
+ sym('Spot')
75
+ ]);
76
+ if (mode && typeof mode === 'object' && 'Twap' in mode) {
77
+ return vec([
78
+ sym('Twap'),
79
+ u32(Number(mode.Twap))
80
+ ]);
81
+ }
82
+ throw new Error(`Stellar builder: unknown OracleReadMode ${JSON.stringify(mode)}`);
83
+ };
84
+ const encodeProviderKind = (kind)=>{
85
+ if (kind === 'Reflector' || kind === 'RedStone' || kind === 'Xoxno') {
86
+ return vec([
87
+ sym(kind)
88
+ ]);
89
+ }
90
+ throw new Error(`Stellar builder: unknown ProviderKind "${kind}"`);
91
+ };
92
+ const encodeFeedNature = (nature)=>{
93
+ if (nature === 'Market' || nature === 'Fundamental') return vec([
94
+ sym(nature)
95
+ ]);
96
+ throw new Error(`Stellar builder: unknown FeedNature "${nature}"`);
97
+ };
98
+ const encodeProviderRef = (provider)=>{
99
+ if ('Reflector' in provider) {
100
+ const r = provider.Reflector;
101
+ return vec([
102
+ sym('Reflector'),
103
+ scStruct({
104
+ asset: encodeOracleAssetRef(r.asset),
105
+ contract: addr(r.contract),
106
+ read_mode: encodeOracleReadMode(r.readMode)
107
+ })
108
+ ]);
109
+ }
110
+ if ('MultiFeed' in provider) {
111
+ const m = provider.MultiFeed;
112
+ return vec([
113
+ sym('MultiFeed'),
114
+ scStruct({
115
+ contract: addr(m.contract),
116
+ feed_id: str(m.feedId),
117
+ kind: encodeProviderKind(m.kind),
118
+ nature: encodeFeedNature(m.nature)
119
+ })
120
+ ]);
121
+ }
122
+ throw new Error(`Stellar builder: unknown ProviderRef ${JSON.stringify(provider)}`);
123
+ };
124
+ const encodeFeedSource = (feed)=>{
125
+ const f = feed;
126
+ return scStruct({
127
+ decimals: u32(f.decimals),
128
+ max_stale_seconds: u64(f.maxStaleSeconds),
129
+ provider: encodeProviderRef(f.provider)
130
+ });
131
+ };
132
+ const encodePriceSource = (source)=>{
133
+ if ('Feed' in source) {
134
+ return vec([
135
+ sym('Feed'),
136
+ encodeFeedSource(source.Feed)
137
+ ]);
138
+ }
139
+ if ('Scaled' in source) {
140
+ const s = source.Scaled;
141
+ return vec([
142
+ sym('Scaled'),
143
+ scStruct({
144
+ factor: encodeFeedSource(s.factor),
145
+ max_factor_wad: i128(s.maxFactorWad),
146
+ min_factor_wad: i128(s.minFactorWad),
147
+ quote: encodePriceKey(s.quote)
148
+ })
149
+ ]);
150
+ }
151
+ if ('LpShare' in source) {
152
+ const s = source.LpShare;
153
+ return vec([
154
+ sym('LpShare'),
155
+ scStruct({
156
+ key_a: encodePriceKey(s.keyA),
157
+ key_b: encodePriceKey(s.keyB),
158
+ kind: vec([
159
+ sym(s.kind || 'ConstantProduct')
160
+ ]),
161
+ pool: addr(s.pool),
162
+ reserve_a_decimals: u32(s.reserveADecimals),
163
+ reserve_b_decimals: u32(s.reserveBDecimals),
164
+ share_decimals: u32(s.shareDecimals)
165
+ })
166
+ ]);
167
+ }
168
+ throw new Error(`Stellar builder: unknown PriceSource ${JSON.stringify(source)}`);
169
+ };
170
+ const encodeIndependence = (policy)=>{
171
+ if (policy === 'RequireDisjoint') return vec([
172
+ sym('RequireDisjoint')
173
+ ]);
174
+ if (policy && typeof policy === 'object' && 'AllowShared' in policy) {
175
+ const domains = policy.AllowShared;
176
+ return vec([
177
+ sym('AllowShared'),
178
+ vec(domains.map((d)=>scStruct({
179
+ contract: addr(d.contract),
180
+ kind: encodeProviderKind(d.kind)
181
+ })))
182
+ ]);
183
+ }
184
+ throw new Error(`Stellar builder: unknown IndependencePolicy ${JSON.stringify(policy)}`);
185
+ };
186
+ /**
187
+ * Encode on-chain `AssetOracle`. Accepts either the swagger DTO
188
+ * (`toleranceBps` + sources) or a full `StellarAssetOracle` with tolerance
189
+ * upper/lower bps (lower is derived as reciprocal when only bps is given).
190
+ */ export const encodeAssetOracle = (cfg)=>{
191
+ const c = cfg;
192
+ const sources = c.sources ?? [];
193
+ let upper;
194
+ let lower;
195
+ if (typeof c.toleranceBps === 'number') {
196
+ upper = 10000 + c.toleranceBps;
197
+ // reciprocal lower ≈ floor(1e8 / upper) style half-up is on-chain; SDK uses
198
+ // symmetric inverse for proposal input (governance may re-derive via view).
199
+ lower = Math.max(1, Math.floor(10000 * 10000 / upper));
200
+ } else {
201
+ const tol = c.tolerance ?? {};
202
+ upper = Number(tol.upperRatioBps);
203
+ lower = Number(tol.lowerRatioBps);
204
+ }
205
+ return scStruct({
206
+ asset_decimals: u32(Number(c.assetDecimals)),
207
+ independence: encodeIndependence(c.independence),
208
+ max_price_stale_seconds: u64(Number(c.maxPriceStaleSeconds)),
209
+ max_sanity_price_wad: i128(String(c.maxSanityPriceWad)),
210
+ min_sanity_price_wad: i128(String(c.minSanityPriceWad)),
211
+ sources: vec(sources.map((s)=>encodePriceSource(s))),
212
+ tolerance: scStruct({
213
+ lower_ratio_bps: u32(lower),
214
+ upper_ratio_bps: u32(upper)
215
+ })
216
+ });
217
+ };
218
+ // -----------------------------------------------------------------------------
219
+ // Access control (access.rs) — #[only_owner] unless noted
220
+ // -----------------------------------------------------------------------------
221
+ /** upgrade(new_wasm_hash: BytesN<32>) */ export function buildStellarUpgradeControllerTx(opts, args) {
222
+ return buildTx(opts, 'upgrade', [
223
+ bytesN(args.wasmHash)
224
+ ]);
225
+ }
226
+ /** migrate(new_version: u32) */ export function buildStellarMigrateTx(opts, args) {
227
+ return buildTx(opts, 'migrate', [
228
+ u32(args.newVersion)
229
+ ]);
230
+ }
231
+ /** pause() */ export function buildStellarPauseTx(opts) {
232
+ return buildTx(opts, 'pause', []);
233
+ }
234
+ /** unpause() */ export function buildStellarUnpauseTx(opts) {
235
+ return buildTx(opts, 'unpause', []);
236
+ }
237
+ /** grant_role(account: Address, role: Symbol) */ export function buildStellarGrantRoleTx(opts, args) {
238
+ return buildTx(opts, 'grant_role', [
239
+ addr(args.account),
240
+ sym(args.role)
241
+ ]);
242
+ }
243
+ /** revoke_role(account: Address, role: Symbol) */ export function buildStellarRevokeRoleTx(opts, args) {
244
+ return buildTx(opts, 'revoke_role', [
245
+ addr(args.account),
246
+ sym(args.role)
247
+ ]);
248
+ }
249
+ /** transfer_ownership(new_owner: Address, live_until_ledger: u32) */ export function buildStellarTransferOwnershipTx(opts, args) {
250
+ return buildTx(opts, 'transfer_ownership', [
251
+ addr(args.newOwner),
252
+ u32(args.liveUntilLedger)
253
+ ]);
254
+ }
255
+ /** accept_ownership() */ export function buildStellarAcceptOwnershipTx(opts) {
256
+ return buildTx(opts, 'accept_ownership', []);
257
+ }
258
+ // -----------------------------------------------------------------------------
259
+ // Config (config.rs)
260
+ // -----------------------------------------------------------------------------
261
+ /** set_swap_aggregator(addr: Address) — #[only_owner] */ export function buildStellarSetSwapAggregatorTx(opts, args) {
262
+ return buildTx(opts, 'set_swap_aggregator', [
263
+ addr(args.aggregator)
264
+ ]);
265
+ }
266
+ /** set_price_aggregator(addr: Address) — #[only_owner] */ export function buildStellarSetPriceAggregatorTx(opts, args) {
267
+ return buildTx(opts, 'set_price_aggregator', [
268
+ addr(args.aggregator)
269
+ ]);
270
+ }
271
+ /** set_accumulator(addr: Address) — #[only_owner] */ export function buildStellarSetAccumulatorTx(opts, args) {
272
+ return buildTx(opts, 'set_accumulator', [
273
+ addr(args.accumulator)
274
+ ]);
275
+ }
276
+ /** set_position_limits(limits: PositionLimits) — #[only_owner] */ export function buildStellarSetPositionLimitsTx(opts, args) {
277
+ return buildTx(opts, 'set_position_limits', [
278
+ encodePositionLimits(args)
279
+ ]);
280
+ }
281
+ /** approve_blend_pool(pool: Address) — #[only_owner] */ export function buildStellarApproveBlendPoolTx(opts, args) {
282
+ return buildTx(opts, 'approve_blend_pool', [
283
+ addr(args.pool)
284
+ ]);
285
+ }
286
+ /** revoke_blend_pool(pool: Address) — #[only_owner] */ export function buildStellarRevokeBlendPoolTx(opts, args) {
287
+ return buildTx(opts, 'revoke_blend_pool', [
288
+ addr(args.pool)
289
+ ]);
290
+ }
291
+ /**
292
+ * Direct price-aggregator `set_oracle(key, oracle)` — owner only (governance
293
+ * contract address as tx source after deploy). Prefer governance propose path
294
+ * in production.
295
+ */ export function buildStellarSetOracleTx(opts, args) {
296
+ return buildTx(opts, 'set_oracle', [
297
+ encodePriceKey(args.key),
298
+ encodeAssetOracle(args.oracle)
299
+ ]);
300
+ }
301
+ /** price-aggregator `set_tolerance(key, OracleTolerance)` — owner only. */ export function buildStellarSetOracleToleranceTx(opts, args) {
302
+ const bps = args.toleranceBps;
303
+ const upper = args.upperRatioBps ?? 10000 + bps;
304
+ const lower = args.lowerRatioBps ?? Math.max(1, Math.floor(10000 * 10000 / upper));
305
+ return buildTx(opts, 'set_tolerance', [
306
+ encodePriceKey(args.key),
307
+ scStruct({
308
+ lower_ratio_bps: u32(lower),
309
+ upper_ratio_bps: u32(upper)
310
+ })
311
+ ]);
312
+ }
313
+ /**
314
+ * set_spoke_asset_flags(spoke_id, hub_asset, paused, frozen, no_seize) —
315
+ * #[only_owner]. Flags-only listing edit; production callers route through the
316
+ * GUARDIAN-gated governance forwarder
317
+ * (`buildStellarGovernanceSetSpokeAssetFlagsImmediateTx`). Every flag is a
318
+ * one-way ratchet here: clearing one requires the timelocked spoke-asset edit.
319
+ */ export function buildStellarSetSpokeAssetFlagsTx(opts, args) {
320
+ return buildTx(opts, 'set_spoke_asset_flags', [
321
+ u32(args.spokeId),
322
+ hubAsset(args.hubId, args.asset),
323
+ bool(args.paused),
324
+ bool(args.frozen),
325
+ bool(args.noSeize)
326
+ ]);
327
+ }
328
+ /**
329
+ * set_oracle_sanity_bounds(asset, min_wad, max_wad) — #[only_owner].
330
+ * Band-only oracle edit; production callers route through the ORACLE-gated
331
+ * governance forwarder (`buildStellarGovernanceSetOracleSanityBoundsImmediateTx`).
332
+ */ export function buildStellarSetOracleSanityBoundsTx(opts, args) {
333
+ return buildTx(opts, 'set_oracle_sanity_bounds', [
334
+ addr(args.asset),
335
+ i128(args.minPriceWad),
336
+ i128(args.maxPriceWad)
337
+ ]);
338
+ }
339
+ // -----------------------------------------------------------------------------
340
+ // Router (router.rs)
341
+ // -----------------------------------------------------------------------------
342
+ /** update_indexes(caller, assets: Vec<HubAssetKey>) */ export function buildStellarUpdateIndexesTx(opts, args) {
343
+ return buildTx(opts, 'update_indexes', [
344
+ addr(opts.caller),
345
+ vec(args.assets.map((a)=>hubAsset(a.hubId, a.asset)))
346
+ ]);
347
+ }
348
+ /** renew_account(caller, account_id: u64) */ export function buildStellarRenewAccountTx(opts, args) {
349
+ return buildTx(opts, 'renew_account', [
350
+ addr(opts.caller),
351
+ u64(args.accountNonce)
352
+ ]);
353
+ }
354
+ /** create_liquidity_pool(hub_id, asset, params: MarketParamsRaw) -> Address — #[only_owner] */ export function buildStellarCreateLiquidityPoolTx(opts, args) {
355
+ return buildTx(opts, 'create_liquidity_pool', [
356
+ u32(args.hubId),
357
+ addr(args.asset),
358
+ encodeMarketParamsRaw(args.params)
359
+ ]);
360
+ }
361
+ /** upgrade_liquidity_pool_params(hub_asset: HubAssetKey, params) — #[only_owner] */ export function buildStellarUpgradeLiquidityPoolParamsTx(opts, args) {
362
+ return buildTx(opts, 'upgrade_liquidity_pool_params', [
363
+ hubAsset(args.hubId, args.asset),
364
+ encodeInterestRateModel(args.params)
365
+ ]);
366
+ }
367
+ /** claim_revenue(caller, assets: Vec<HubAssetKey>) -> Vec<i128> */ export function buildStellarClaimRevenueTx(opts, args) {
368
+ return buildTx(opts, 'claim_revenue', [
369
+ addr(opts.caller),
370
+ vec(args.assets.map((a)=>hubAsset(a.hubId, a.asset)))
371
+ ]);
372
+ }
373
+ /** add_rewards(caller, rewards: Vec<(HubAssetKey, i128)>) */ export function buildStellarAddRewardsTx(opts, args) {
374
+ return buildTx(opts, 'add_rewards', [
375
+ addr(opts.caller),
376
+ tupleHubAssetAmountVec(args.rewards)
377
+ ]);
378
+ }
379
+ /** update_account_threshold(caller, asset, has_risks, account_ids: Vec<u64>) — #[only_role(caller, "KEEPER")] */ export function buildStellarUpdateAccountThresholdTx(opts, args) {
380
+ return buildTx(opts, 'update_account_threshold', [
381
+ addr(opts.caller),
382
+ bool(args.hasRisks),
383
+ vec(args.accountNonces.map((n)=>u64(n)))
384
+ ]);
385
+ }