@xoxno/sdk-js 1.0.229 → 1.0.231
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/contracts.d.ts +2 -2
- package/dist/cjs/sdk/stellar/events/decode.d.ts +4 -6
- package/dist/cjs/sdk/stellar/index.d.ts +1 -0
- package/dist/cjs/sdk/stellar/lending-read.d.ts +16 -2
- package/dist/cjs/sdk/stellar/lending.d.ts +34 -0
- package/dist/cjs/utils/soroban-errors.d.ts +18 -1
- package/dist/esm/sdk/stellar/contracts.js +1 -1
- package/dist/esm/sdk/stellar/events/decode.js +115 -9
- package/dist/esm/sdk/stellar/lending-read.js +40 -4
- package/dist/esm/sdk/stellar/lending.js +45 -0
- package/dist/esm/utils/soroban-errors.js +412 -19
- package/dist/index.cjs +1 -1
- package/dist/sdk/stellar/contracts.d.ts +2 -2
- package/dist/sdk/stellar/events/decode.d.ts +4 -6
- 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/lending-read.d.ts +16 -2
- package/dist/sdk/stellar/lending.d.ts +34 -0
- package/dist/utils/soroban-errors.d.ts +18 -1
- package/package.json +2 -2
|
@@ -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: "
|
|
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: "
|
|
100
|
+
readonly priceAggregator: "CBMARXSYE56NPDLX42TTICM5GS5XQCYRD5VMCJME624TS6C2S53VETYU";
|
|
101
101
|
readonly positionNftContract: "CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY";
|
|
102
102
|
};
|
|
103
103
|
};
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Decoders for the Stellar lending `#[contractevent]`s (controller, pool, and
|
|
3
3
|
* the price-aggregator's `config:asset_oracle`).
|
|
4
4
|
*
|
|
5
|
-
* Decodes
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `strategy:blend_migration` (handled by az-functions own decoders).
|
|
5
|
+
* Decodes every topic the controller, pool, price aggregator, governance and
|
|
6
|
+
* DeFindex strategy contracts emit, plus legacy keys for historical ledgers.
|
|
7
|
+
* Unknown topics (for example access-control events) return `null`.
|
|
9
8
|
*
|
|
10
9
|
* The public API takes base64-XDR strings (`decodeStellarLendingEvent(topicsB64,
|
|
11
10
|
* dataB64)`) and parses them with this SDK's bundled `@stellar/stellar-sdk`, so
|
|
@@ -37,8 +36,7 @@ export declare const toBase64Xdr: (scv: {
|
|
|
37
36
|
}) => string;
|
|
38
37
|
/** Build the `"<domain>:<action>"` dispatch key from the event topic ScVals. */
|
|
39
38
|
export declare const stellarLendingDispatchKey: (topicsB64: readonly string[]) => string;
|
|
40
|
-
/** Topic keys this SDK can decode.
|
|
41
|
-
* omissions. */
|
|
39
|
+
/** Topic keys this SDK can decode. */
|
|
42
40
|
export declare const STELLAR_LENDING_TOPICS: readonly string[];
|
|
43
41
|
/**
|
|
44
42
|
* Decode a Stellar lending controller event from its base64-XDR topics and
|
|
@@ -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';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/** Typed Stellar lending reads. Configure the API deployment with XOXNOClient.apiUrl.
|
|
2
2
|
* These cached HTTP reads do not simulate transactions or authorize spending.
|
|
3
3
|
*/
|
|
4
|
-
import type
|
|
4
|
+
import { type OurRequestInit, type XOXNOClient } from '../../utils/api.js';
|
|
5
5
|
import type * as Api from './lending-api-types.js';
|
|
6
|
+
import type { UserTokenInventoryResponseDto } from '@xoxno/types';
|
|
6
7
|
import type { StellarLendingMarketSide, StellarLendingHoldersSide, StellarMarketGraphQuery, StellarReservesParams, StellarActivityQuery, StellarActivityPageQuery, StellarGovernanceQuery, StellarPositionsQuery, StellarRevenueQuery, StellarFeeRevenueQuery, StellarParticipantsQuery, StellarLiquidationsQuery, StellarLiquidationsLeaderboardQuery, StellarVolumeQuery, StellarDistributionQuery, StellarRateSpreadQuery } from './lending-read-types.js';
|
|
7
8
|
/** Load assets, hubs, spokes, reserves and keyed reserve details in one response.
|
|
8
9
|
* @category Stellar lending reads
|
|
@@ -56,7 +57,18 @@ export declare const getStellarUserPositions: (client: XOXNOClient, owner: strin
|
|
|
56
57
|
* @category Stellar lending reads
|
|
57
58
|
*/
|
|
58
59
|
export declare const getStellarAccountPositions: (client: XOXNOClient, accountId: string, init?: OurRequestInit) => Promise<Api.AccountPositionsDto>;
|
|
59
|
-
/** Read
|
|
60
|
+
/** Read a G or C wallet's token holdings from `/user/{owner}/token-inventory`:
|
|
61
|
+
* Horizon balances (native XLM and classic assets, keyed by their SAC id) plus
|
|
62
|
+
* indexed Soroban tokens, cached for about 10 seconds. Each token's
|
|
63
|
+
* `identifier` is its contract id and `balance` is base units as a decimal
|
|
64
|
+
* string. Tokens without a balance or trustline are absent.
|
|
65
|
+
* @category Stellar lending reads
|
|
66
|
+
*/
|
|
67
|
+
export declare const getStellarWalletTokens: (client: XOXNOClient, owner: string, init?: OurRequestInit) => Promise<UserTokenInventoryResponseDto>;
|
|
68
|
+
/** Read exact token base-unit holdings of one asset for a G or C wallet, from
|
|
69
|
+
* {@link getStellarWalletTokens}. An asset the wallet does not hold returns
|
|
70
|
+
* `amount: '0'`, with decimals read from the lending asset. Holdings may exceed
|
|
71
|
+
* spendable funds (reserves, liabilities).
|
|
60
72
|
* @category Stellar lending reads
|
|
61
73
|
*/
|
|
62
74
|
export declare const getStellarWalletBalance: (client: XOXNOClient, owner: string, asset: string, init?: OurRequestInit) => Promise<Api.StellarWalletBalanceDto>;
|
|
@@ -218,6 +230,8 @@ export declare const stellarLendingRead: (client: XOXNOClient) => {
|
|
|
218
230
|
userPositions: (owner: string, init?: OurRequestInit) => Promise<Api.AccountPositionsDto>;
|
|
219
231
|
/** {@inheritDoc getStellarAccountPositions} */
|
|
220
232
|
accountPositions: (accountId: string, init?: OurRequestInit) => Promise<Api.AccountPositionsDto>;
|
|
233
|
+
/** {@inheritDoc getStellarWalletTokens} */
|
|
234
|
+
walletTokens: (owner: string, init?: OurRequestInit) => Promise<UserTokenInventoryResponseDto>;
|
|
221
235
|
/** {@inheritDoc getStellarWalletBalance} */
|
|
222
236
|
walletBalance: (owner: string, asset: string, init?: OurRequestInit) => Promise<Api.StellarWalletBalanceDto>;
|
|
223
237
|
/** {@inheritDoc getStellarAssetPage} */
|
|
@@ -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: '
|
|
35
|
+
priceAggregator: 'CBMARXSYE56NPDLX42TTICM5GS5XQCYRD5VMCJME624TS6C2S53VETYU',
|
|
36
36
|
positionNftContract: 'CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY'
|
|
37
37
|
}
|
|
38
38
|
};
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Decoders for the Stellar lending `#[contractevent]`s (controller, pool, and
|
|
3
3
|
* the price-aggregator's `config:asset_oracle`).
|
|
4
4
|
*
|
|
5
|
-
* Decodes
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `strategy:blend_migration` (handled by az-functions own decoders).
|
|
5
|
+
* Decodes every topic the controller, pool, price aggregator, governance and
|
|
6
|
+
* DeFindex strategy contracts emit, plus legacy keys for historical ledgers.
|
|
7
|
+
* Unknown topics (for example access-control events) return `null`.
|
|
9
8
|
*
|
|
10
9
|
* The public API takes base64-XDR strings (`decodeStellarLendingEvent(topicsB64,
|
|
11
10
|
* dataB64)`) and parses them with this SDK's bundled `@stellar/stellar-sdk`, so
|
|
@@ -70,7 +69,8 @@ const POSITION_MODE = [
|
|
|
70
69
|
'close_wd',
|
|
71
70
|
'migrate',
|
|
72
71
|
'rp_col_net',
|
|
73
|
-
'liq_credit'
|
|
72
|
+
'liq_credit',
|
|
73
|
+
'flash_pos'
|
|
74
74
|
];
|
|
75
75
|
const positionMode = (v)=>POSITION_MODE[num(v)] ?? 'None';
|
|
76
76
|
// Unknown discriminants surface as their decimal string instead of throwing.
|
|
@@ -195,9 +195,11 @@ const REGISTRY = {
|
|
|
195
195
|
marketAddress: str(d.market_address)
|
|
196
196
|
}
|
|
197
197
|
}),
|
|
198
|
+
// `hub_id` tells same-token markets apart; absent on pre-hub ledgers.
|
|
198
199
|
'market:params_update': (d)=>({
|
|
199
200
|
topic: 'market:params_update',
|
|
200
201
|
data: {
|
|
202
|
+
hubId: d.hub_id === undefined ? undefined : num(d.hub_id),
|
|
201
203
|
asset: str(d.asset),
|
|
202
204
|
maxBorrowRateRay: dec(d.max_borrow_rate),
|
|
203
205
|
baseBorrowRateRay: dec(d.base_borrow_rate),
|
|
@@ -303,12 +305,14 @@ const REGISTRY = {
|
|
|
303
305
|
totalCollateralUsdWad: dec(d.total_collateral_usd_wad)
|
|
304
306
|
}
|
|
305
307
|
}),
|
|
308
|
+
// Current contracts emit `{ token, amount, account_id }`; `usd_value_wad`
|
|
309
|
+
// exists only on older ledgers and is never fabricated.
|
|
306
310
|
'strategy:initial_payment': (d)=>({
|
|
307
311
|
topic: 'strategy:initial_payment',
|
|
308
312
|
data: {
|
|
309
313
|
token: str(d.token),
|
|
310
314
|
amount: dec(d.amount),
|
|
311
|
-
usdValueWad: dec(d.usd_value_wad),
|
|
315
|
+
usdValueWad: d.usd_value_wad === undefined ? undefined : dec(d.usd_value_wad),
|
|
312
316
|
accountId: dec(d.account_id)
|
|
313
317
|
}
|
|
314
318
|
}),
|
|
@@ -397,10 +401,112 @@ const REGISTRY = {
|
|
|
397
401
|
liquidationBonusFactorBps: num(s.liquidation_bonus_factor_bps)
|
|
398
402
|
}
|
|
399
403
|
};
|
|
400
|
-
}
|
|
404
|
+
},
|
|
405
|
+
'position:flash_position': (d)=>({
|
|
406
|
+
topic: 'position:flash_position',
|
|
407
|
+
data: {
|
|
408
|
+
accountId: dec(d.account_id),
|
|
409
|
+
hubId: num(d.hub_id),
|
|
410
|
+
asset: str(d.asset),
|
|
411
|
+
receiver: str(d.receiver),
|
|
412
|
+
caller: str(d.caller),
|
|
413
|
+
amount: dec(d.amount),
|
|
414
|
+
amountReceived: dec(d.amount_received),
|
|
415
|
+
fee: dec(d.fee)
|
|
416
|
+
}
|
|
417
|
+
}),
|
|
418
|
+
'revenue:claim': (d)=>({
|
|
419
|
+
topic: 'revenue:claim',
|
|
420
|
+
data: {
|
|
421
|
+
hubId: num(d.hub_id),
|
|
422
|
+
asset: str(d.asset),
|
|
423
|
+
caller: str(d.caller),
|
|
424
|
+
accumulator: str(d.accumulator),
|
|
425
|
+
amount: dec(d.amount)
|
|
426
|
+
}
|
|
427
|
+
}),
|
|
428
|
+
'account:delegate': (d)=>({
|
|
429
|
+
topic: 'account:delegate',
|
|
430
|
+
data: {
|
|
431
|
+
accountId: dec(d.account_id),
|
|
432
|
+
owner: str(d.owner),
|
|
433
|
+
delegate: str(d.delegate),
|
|
434
|
+
granted: Boolean(d.granted)
|
|
435
|
+
}
|
|
436
|
+
}),
|
|
437
|
+
'config:hub': (d)=>({
|
|
438
|
+
topic: 'config:hub',
|
|
439
|
+
data: {
|
|
440
|
+
hubId: num(d.hub_id)
|
|
441
|
+
}
|
|
442
|
+
}),
|
|
443
|
+
'config:spoke_asset': (d)=>{
|
|
444
|
+
const c = d.config;
|
|
445
|
+
return {
|
|
446
|
+
topic: 'config:spoke_asset',
|
|
447
|
+
data: {
|
|
448
|
+
spokeId: num(d.spoke_id),
|
|
449
|
+
hubId: num(d.hub_id),
|
|
450
|
+
asset: str(d.asset),
|
|
451
|
+
config: {
|
|
452
|
+
isCollateralizable: Boolean(c.is_collateralizable),
|
|
453
|
+
isBorrowable: Boolean(c.is_borrowable),
|
|
454
|
+
paused: Boolean(c.paused),
|
|
455
|
+
frozen: Boolean(c.frozen),
|
|
456
|
+
noSeize: Boolean(c.no_seize),
|
|
457
|
+
loanToValueBps: num(c.loan_to_value),
|
|
458
|
+
liquidationThresholdBps: num(c.liquidation_threshold),
|
|
459
|
+
liquidationBonusBps: num(c.liquidation_bonus),
|
|
460
|
+
liquidationFeesBps: num(c.liquidation_fees),
|
|
461
|
+
supplyCap: dec(c.supply_cap),
|
|
462
|
+
borrowCap: dec(c.borrow_cap)
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
},
|
|
467
|
+
'config:remove_spoke_asset': (d)=>({
|
|
468
|
+
topic: 'config:remove_spoke_asset',
|
|
469
|
+
data: {
|
|
470
|
+
spokeId: num(d.spoke_id),
|
|
471
|
+
hubId: num(d.hub_id),
|
|
472
|
+
asset: str(d.asset)
|
|
473
|
+
}
|
|
474
|
+
}),
|
|
475
|
+
'strategy:blend_migration': (d)=>({
|
|
476
|
+
topic: 'strategy:blend_migration',
|
|
477
|
+
data: {
|
|
478
|
+
accountId: dec(d.account_id),
|
|
479
|
+
blendPool: str(d.blend_pool),
|
|
480
|
+
collateralCount: num(d.collateral_count),
|
|
481
|
+
supplyCount: num(d.supply_count),
|
|
482
|
+
debtCount: num(d.debt_count)
|
|
483
|
+
}
|
|
484
|
+
}),
|
|
485
|
+
// Emitted by the DeFindex strategy adapter, not the controller.
|
|
486
|
+
'strategy:harvest': (d)=>({
|
|
487
|
+
topic: 'strategy:harvest',
|
|
488
|
+
data: {
|
|
489
|
+
from: str(d.from),
|
|
490
|
+
amount: dec(d.amount),
|
|
491
|
+
pricePerShare: dec(d.price_per_share)
|
|
492
|
+
}
|
|
493
|
+
}),
|
|
494
|
+
'governance:deploy_controller': (d)=>({
|
|
495
|
+
topic: 'governance:deploy_controller',
|
|
496
|
+
data: {
|
|
497
|
+
controller: str(d.controller),
|
|
498
|
+
wasmHash: hex(d.wasm_hash)
|
|
499
|
+
}
|
|
500
|
+
}),
|
|
501
|
+
'governance:deploy_price_aggregator': (d)=>({
|
|
502
|
+
topic: 'governance:deploy_price_aggregator',
|
|
503
|
+
data: {
|
|
504
|
+
priceAggregator: str(d.price_aggregator),
|
|
505
|
+
wasmHash: hex(d.wasm_hash)
|
|
506
|
+
}
|
|
507
|
+
})
|
|
401
508
|
};
|
|
402
|
-
/** Topic keys this SDK can decode.
|
|
403
|
-
* omissions. */ export const STELLAR_LENDING_TOPICS = Object.freeze(Object.keys(REGISTRY));
|
|
509
|
+
/** Topic keys this SDK can decode. */ export const STELLAR_LENDING_TOPICS = Object.freeze(Object.keys(REGISTRY));
|
|
404
510
|
/**
|
|
405
511
|
* Decode a Stellar lending controller event from its base64-XDR topics and
|
|
406
512
|
* data (exactly as Soroban RPC `getEvents` delivers them). Returns `null` for a
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Typed Stellar lending reads. Configure the API deployment with XOXNOClient.apiUrl.
|
|
2
2
|
* These cached HTTP reads do not simulate transactions or authorize spending.
|
|
3
|
-
*/
|
|
3
|
+
*/ import { Chain } from "../../utils/api.js";
|
|
4
|
+
const BASE = '/stellar-lending';
|
|
4
5
|
const enc = encodeURIComponent;
|
|
5
6
|
/** Load assets, hubs, spokes, reserves and keyed reserve details in one response.
|
|
6
7
|
* @category Stellar lending reads
|
|
@@ -46,9 +47,43 @@ const enc = encodeURIComponent;
|
|
|
46
47
|
/** Read a single lending account, identified by its decimal ID; balances use RAY token quantities.
|
|
47
48
|
* @category Stellar lending reads
|
|
48
49
|
*/ export const getStellarAccountPositions = (client, accountId, init)=>client.fetchWithTimeout(`${BASE}/accounts/${enc(accountId)}/positions`, init);
|
|
49
|
-
/** Read
|
|
50
|
-
*
|
|
51
|
-
|
|
50
|
+
/** Read a G or C wallet's token holdings from `/user/{owner}/token-inventory`:
|
|
51
|
+
* Horizon balances (native XLM and classic assets, keyed by their SAC id) plus
|
|
52
|
+
* indexed Soroban tokens, cached for about 10 seconds. Each token's
|
|
53
|
+
* `identifier` is its contract id and `balance` is base units as a decimal
|
|
54
|
+
* string. Tokens without a balance or trustline are absent.
|
|
55
|
+
* @category Stellar lending reads
|
|
56
|
+
*/ export const getStellarWalletTokens = (client, owner, init)=>client.fetchWithTimeout(`/user/${enc(owner)}/token-inventory`, init);
|
|
57
|
+
/** Read exact token base-unit holdings of one asset for a G or C wallet, from
|
|
58
|
+
* {@link getStellarWalletTokens}. An asset the wallet does not hold returns
|
|
59
|
+
* `amount: '0'`, with decimals read from the lending asset. Holdings may exceed
|
|
60
|
+
* spendable funds (reserves, liabilities).
|
|
61
|
+
* @category Stellar lending reads
|
|
62
|
+
*/ export const getStellarWalletBalance = async (client, owner, asset, init)=>{
|
|
63
|
+
const inventory = await getStellarWalletTokens(client, owner, init);
|
|
64
|
+
const network = client.chain === Chain.MAINNET ? 'mainnet' : 'testnet';
|
|
65
|
+
const token = (inventory?.tokens ?? []).find((t)=>t.identifier === asset);
|
|
66
|
+
if (token) {
|
|
67
|
+
return {
|
|
68
|
+
owner,
|
|
69
|
+
network: token.stellarNetwork ?? network,
|
|
70
|
+
asset,
|
|
71
|
+
amount: String(token.balance),
|
|
72
|
+
decimals: token.decimals
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const { decimals } = await getStellarAsset(client, asset, init);
|
|
76
|
+
if (typeof decimals !== 'number') {
|
|
77
|
+
throw new Error(`Stellar lending: no decimals for ${asset}; it is not a lending asset`);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
owner,
|
|
81
|
+
network,
|
|
82
|
+
asset,
|
|
83
|
+
amount: '0',
|
|
84
|
+
decimals
|
|
85
|
+
};
|
|
86
|
+
};
|
|
52
87
|
/** Load overview, deposit/borrow markets and chart series for an asset page.
|
|
53
88
|
* @category Stellar lending reads
|
|
54
89
|
*/ export const getStellarAssetPage = (client, asset, query, init)=>client.fetchWithTimeout(`${BASE}/assets/${enc(asset)}/page`, {
|
|
@@ -307,6 +342,7 @@ const enc = encodeURIComponent;
|
|
|
307
342
|
/** {@inheritDoc getStellarSpoke} */ spoke: (spokeId, init)=>getStellarSpoke(client, spokeId, init),
|
|
308
343
|
/** {@inheritDoc getStellarUserPositions} */ userPositions: (owner, init)=>getStellarUserPositions(client, owner, init),
|
|
309
344
|
/** {@inheritDoc getStellarAccountPositions} */ accountPositions: (accountId, init)=>getStellarAccountPositions(client, accountId, init),
|
|
345
|
+
/** {@inheritDoc getStellarWalletTokens} */ walletTokens: (owner, init)=>getStellarWalletTokens(client, owner, init),
|
|
310
346
|
/** {@inheritDoc getStellarWalletBalance} */ walletBalance: (owner, asset, init)=>getStellarWalletBalance(client, owner, asset, init),
|
|
311
347
|
/** {@inheritDoc getStellarAssetPage} */ assetPage: (asset, query, init)=>getStellarAssetPage(client, asset, query, init),
|
|
312
348
|
/** {@inheritDoc getStellarAssetMarkets} */ assetMarkets: (asset, side, init)=>getStellarAssetMarkets(client, asset, side, init),
|
|
@@ -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.
|