@xoxno/sdk-js 1.0.229 → 1.0.230

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.
@@ -62,7 +62,7 @@ export declare const STELLAR_NETWORKS: {
62
62
  readonly lendingPool: "CBSGF6QOQAMPFBEVSYPEQHSZRIHJ6RCGUPCRDMUX36DEKRWFAO2PZB5A";
63
63
  readonly aggregatorRouter: "CDNTWMWW2WGYTKIZTJYNGNVQQZI4KTC5BQRZ3275KESRX5T4O3AYECL5";
64
64
  readonly governance: "CDS33JDOYH3F3FL4QUQ6DV4WKHML2AKHF4LADTZ57FRUAEBTE7NMY5FQ";
65
- readonly priceAggregator: "CAALOOTIDXCX7D7FMQIBSSAJLPKOM3GMXS4UUSTDIG42JCRRJHOPUHOP";
65
+ readonly priceAggregator: "CBMARXSYE56NPDLX42TTICM5GS5XQCYRD5VMCJME624TS6C2S53VETYU";
66
66
  readonly positionNftContract: "CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY";
67
67
  };
68
68
  };
@@ -97,7 +97,7 @@ export declare const stellarNetworks: {
97
97
  readonly lendingPool: "CBSGF6QOQAMPFBEVSYPEQHSZRIHJ6RCGUPCRDMUX36DEKRWFAO2PZB5A";
98
98
  readonly aggregatorRouter: "CDNTWMWW2WGYTKIZTJYNGNVQQZI4KTC5BQRZ3275KESRX5T4O3AYECL5";
99
99
  readonly governance: "CDS33JDOYH3F3FL4QUQ6DV4WKHML2AKHF4LADTZ57FRUAEBTE7NMY5FQ";
100
- readonly priceAggregator: "CAALOOTIDXCX7D7FMQIBSSAJLPKOM3GMXS4UUSTDIG42JCRRJHOPUHOP";
100
+ readonly priceAggregator: "CBMARXSYE56NPDLX42TTICM5GS5XQCYRD5VMCJME624TS6C2S53VETYU";
101
101
  readonly positionNftContract: "CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY";
102
102
  };
103
103
  };
@@ -25,3 +25,4 @@ export * from './cctp.js';
25
25
  export * from './math/index.js';
26
26
  export type { StellarStrategySwapInput, StellarStrategySwapPathInput, StellarStrategySwapHopInput, } from './scval-encode.js';
27
27
  export { mapSorobanError } from '../../utils/soroban-errors.js';
28
+ export type { MapSorobanErrorOptions } from '../../utils/soroban-errors.js';
@@ -299,6 +299,40 @@ export declare function buildStellarLiquidateTx(opts: StellarLendingBuilderOptio
299
299
  * `decodeStellarLendingEvent`. Hold a parsed ScVal? Pass `toBase64Xdr(scv)`.
300
300
  */
301
301
  export declare function decodeStellarLiquidateReturn(returnValueB64: string): string;
302
+ /**
303
+ * get_liquidation_estimate(account_id: u64, debt_payments: Vec<(HubAssetKey, i128)>,
304
+ * seize_mode: SeizeMode) -> LiquidationEstimate
305
+ *
306
+ * Read-only view: simulate the built transaction (`server.simulateTransaction`)
307
+ * and decode `result.retval` with `decodeStellarLiquidationEstimate`. Takes the
308
+ * same args as `buildStellarLiquidateTx`, so an estimate and the real call stay
309
+ * encoded identically. Never submit this transaction.
310
+ * @param opts - Network, caller (any account; it is only the simulation source), sequence and controller.
311
+ * @param args - The liquidation you intend to send.
312
+ * @returns Unsigned XDR to simulate.
313
+ * @category Lending transactions
314
+ */
315
+ export declare function buildStellarLiquidationEstimateTx(opts: StellarLendingBuilderOptions, args: StellarLiquidateArgs): BuiltStellarTx;
316
+ /** One `PaymentTuple`: a token amount without a hub id. */
317
+ export interface StellarPaymentTuple {
318
+ asset: string;
319
+ /** Token base units for Transfer legs; RAY-scaled supply shares for Credit seizure. */
320
+ amount: string;
321
+ }
322
+ /** Decoded `LiquidationEstimate`; i128 fields as decimal strings. */
323
+ export interface StellarLiquidationEstimate {
324
+ seizedCollaterals: StellarPaymentTuple[];
325
+ protocolFees: StellarPaymentTuple[];
326
+ refunds: StellarPaymentTuple[];
327
+ maxPaymentWad: string;
328
+ bonusRateBps: string;
329
+ }
330
+ /**
331
+ * Decode `get_liquidation_estimate`'s return value from base64 XDR (Soroban
332
+ * RPC `result.retval`). Tuples carry token addresses without hub ids; match
333
+ * them to the target's `(hub_id, asset)` positions yourself.
334
+ */
335
+ export declare function decodeStellarLiquidationEstimate(returnValueB64: string): StellarLiquidationEstimate;
302
336
  /**
303
337
  * flash_loan(caller, asset: HubAssetKey, amount: i128, receiver, data: Bytes)
304
338
  * @param opts - Network, caller, current source sequence and deployment addresses.
@@ -1,10 +1,27 @@
1
+ export interface MapSorobanErrorOptions {
2
+ /**
3
+ * Accept only an error emitted by one of these contract IDs (`C…`), for
4
+ * example the lending controller and pool. The emitter is read from the
5
+ * diagnostic event log, or from the `[xoxno-invoked:<id>]` tag that
6
+ * `prepareStellarTxXdr` adds when the string has no event log.
7
+ *
8
+ * RPC simulation errors usually carry only the top-level code
9
+ * (`HostError: Error(Contract, #N)`). With only the tag, a code raised by a
10
+ * nested contract (for example the swap aggregator) cannot be told apart;
11
+ * read the simulation's diagnostic events when that matters.
12
+ */
13
+ contracts?: readonly string[];
14
+ }
1
15
  /**
2
16
  * Extracts a `Error(Contract, #N)` code from a raw Soroban simulation/RPC error
3
17
  * string and resolves it against the rs-lending-xlm catalog. Matches only the
4
18
  * exact `Error(Contract, #N)` pattern — never loose digits, since raw error
5
19
  * strings can contain unrelated numbers (fees, ledgers, sequence numbers).
20
+ *
21
+ * Without `opts.contracts` it maps the first code in the string, whichever
22
+ * contract emitted it.
6
23
  */
7
- export declare function mapSorobanError(raw: string): {
24
+ export declare function mapSorobanError(raw: string, opts?: MapSorobanErrorOptions): {
8
25
  code: number;
9
26
  name: string;
10
27
  message: string;
@@ -32,7 +32,7 @@
32
32
  lendingPool: 'CBSGF6QOQAMPFBEVSYPEQHSZRIHJ6RCGUPCRDMUX36DEKRWFAO2PZB5A',
33
33
  aggregatorRouter: 'CDNTWMWW2WGYTKIZTJYNGNVQQZI4KTC5BQRZ3275KESRX5T4O3AYECL5',
34
34
  governance: 'CDS33JDOYH3F3FL4QUQ6DV4WKHML2AKHF4LADTZ57FRUAEBTE7NMY5FQ',
35
- priceAggregator: 'CAALOOTIDXCX7D7FMQIBSSAJLPKOM3GMXS4UUSTDIG42JCRRJHOPUHOP',
35
+ priceAggregator: 'CBMARXSYE56NPDLX42TTICM5GS5XQCYRD5VMCJME624TS6C2S53VETYU',
36
36
  positionNftContract: 'CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY'
37
37
  }
38
38
  };
@@ -70,7 +70,8 @@ const POSITION_MODE = [
70
70
  'close_wd',
71
71
  'migrate',
72
72
  'rp_col_net',
73
- 'liq_credit'
73
+ 'liq_credit',
74
+ 'flash_pos'
74
75
  ];
75
76
  const positionMode = (v)=>POSITION_MODE[num(v)] ?? 'None';
76
77
  // Unknown discriminants surface as their decimal string instead of throwing.
@@ -195,9 +196,12 @@ const REGISTRY = {
195
196
  marketAddress: str(d.market_address)
196
197
  }
197
198
  }),
199
+ // `hub_id` is required to tell same-token markets apart; the upstream DTO
200
+ // does not declare it yet, hence the cast.
198
201
  'market:params_update': (d)=>({
199
202
  topic: 'market:params_update',
200
203
  data: {
204
+ hubId: num(d.hub_id),
201
205
  asset: str(d.asset),
202
206
  maxBorrowRateRay: dec(d.max_borrow_rate),
203
207
  baseBorrowRateRay: dec(d.base_borrow_rate),
@@ -303,12 +307,13 @@ const REGISTRY = {
303
307
  totalCollateralUsdWad: dec(d.total_collateral_usd_wad)
304
308
  }
305
309
  }),
310
+ // The event carries `{ token, amount, account_id }` only. The upstream DTO
311
+ // still declares `usdValueWad`; it is left absent rather than fabricated.
306
312
  'strategy:initial_payment': (d)=>({
307
313
  topic: 'strategy:initial_payment',
308
314
  data: {
309
315
  token: str(d.token),
310
316
  amount: dec(d.amount),
311
- usdValueWad: dec(d.usd_value_wad),
312
317
  accountId: dec(d.account_id)
313
318
  }
314
319
  }),
@@ -248,6 +248,51 @@ function encodeSpokeId(value) {
248
248
  }
249
249
  throw new Error(`Stellar builder: liquidate return value must be a u64, got ${typeof native}`);
250
250
  }
251
+ /**
252
+ * get_liquidation_estimate(account_id: u64, debt_payments: Vec<(HubAssetKey, i128)>,
253
+ * seize_mode: SeizeMode) -> LiquidationEstimate
254
+ *
255
+ * Read-only view: simulate the built transaction (`server.simulateTransaction`)
256
+ * and decode `result.retval` with `decodeStellarLiquidationEstimate`. Takes the
257
+ * same args as `buildStellarLiquidateTx`, so an estimate and the real call stay
258
+ * encoded identically. Never submit this transaction.
259
+ * @param opts - Network, caller (any account; it is only the simulation source), sequence and controller.
260
+ * @param args - The liquidation you intend to send.
261
+ * @returns Unsigned XDR to simulate.
262
+ * @category Lending transactions
263
+ */ export function buildStellarLiquidationEstimateTx(opts, args) {
264
+ return buildTx(opts, 'get_liquidation_estimate', [
265
+ u64(args.accountNonce),
266
+ tupleHubAssetAmountVec([
267
+ ...args.debtPayments
268
+ ]),
269
+ seizeMode(args.seizeMode ?? 'Transfer')
270
+ ]);
271
+ }
272
+ const paymentTuples = (v)=>(Array.isArray(v) ? v : []).map((p)=>{
273
+ const row = p;
274
+ return {
275
+ asset: String(row.asset),
276
+ amount: String(row.amount)
277
+ };
278
+ });
279
+ /**
280
+ * Decode `get_liquidation_estimate`'s return value from base64 XDR (Soroban
281
+ * RPC `result.retval`). Tuples carry token addresses without hub ids; match
282
+ * them to the target's `(hub_id, asset)` positions yourself.
283
+ */ export function decodeStellarLiquidationEstimate(returnValueB64) {
284
+ const native = scValToNative(xdr.ScVal.fromXDR(returnValueB64, 'base64'));
285
+ if (!native || typeof native !== 'object' || Array.isArray(native)) {
286
+ throw new Error('Stellar builder: liquidation estimate must be a struct');
287
+ }
288
+ return {
289
+ seizedCollaterals: paymentTuples(native.seized_collaterals),
290
+ protocolFees: paymentTuples(native.protocol_fees),
291
+ refunds: paymentTuples(native.refunds),
292
+ maxPaymentWad: String(native.max_payment_wad),
293
+ bonusRateBps: String(native.bonus_rate_bps)
294
+ };
295
+ }
251
296
  /**
252
297
  * flash_loan(caller, asset: HubAssetKey, amount: i128, receiver, data: Bytes)
253
298
  * @param opts - Network, caller, current source sequence and deployment addresses.