@xoxno/sdk-js 1.0.228 → 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.
- package/dist/cjs/sdk/stellar/contracts.d.ts +2 -2
- package/dist/cjs/sdk/stellar/index.d.ts +1 -0
- package/dist/cjs/sdk/stellar/lending.d.ts +34 -0
- package/dist/cjs/sdk/stellar/scval-encode.d.ts +1 -1
- 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 +7 -2
- package/dist/esm/sdk/stellar/lending.js +45 -0
- package/dist/esm/sdk/stellar/route-verify.js +6 -3
- package/dist/esm/sdk/stellar/scval-encode.js +4 -2
- 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/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.d.ts +34 -0
- package/dist/sdk/stellar/scval-encode.d.ts +1 -1
- package/dist/sdk/stellar/swap-index.cjs +1 -1
- package/dist/sdk/stellar/swap-index.esm.js +1 -1
- 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
|
};
|
|
@@ -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.
|
|
@@ -10,7 +10,7 @@ import { xdr } from '@stellar/stellar-sdk';
|
|
|
10
10
|
* On-chain swap venues, validated at runtime for a caller-supplied venue.
|
|
11
11
|
* Mirrors the Soroban-only aggregator router's opcode table.
|
|
12
12
|
*/
|
|
13
|
-
export declare const STELLAR_SWAP_VENUES: readonly ["Soroswap", "Aquarius", "Phoenix", "Sushi", "CometDex"];
|
|
13
|
+
export declare const STELLAR_SWAP_VENUES: readonly ["Soroswap", "Aquarius", "Phoenix", "Sushi", "CometDex", "Curve"];
|
|
14
14
|
export type StellarSwapVenue = (typeof STELLAR_SWAP_VENUES)[number];
|
|
15
15
|
/**
|
|
16
16
|
* Instruction opcode per venue. Part of the on-chain ABI — see
|
|
@@ -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
|
};
|
|
@@ -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.
|
|
@@ -24,7 +24,7 @@ function _define_property(obj, key, value) {
|
|
|
24
24
|
*/ import { Address, Asset, scValToBigInt, StrKey, xdr } from "@stellar/stellar-sdk";
|
|
25
25
|
import { STELLAR_NETWORK_PASSPHRASE } from "./contracts.js";
|
|
26
26
|
import { xdrBytes, xdrField, xdrType } from "./xdr-compat.js";
|
|
27
|
-
import { asStellarStrategySwapBytes, MAX_AMOUNTS, MAX_ASSETS, MAX_OPS, MAX_WEIGHTS, MODE_ALL, MODE_FIXED_BASE, MODE_PPM_BASE, MODE_PREV, OP_BURN, OP_MINT, PPM_DENOMINATOR, STELLAR_PROGRAM_VERSION, STELLAR_SWAP_VENUES } from "./scval-encode.js";
|
|
27
|
+
import { asStellarStrategySwapBytes, MAX_AMOUNTS, MAX_ASSETS, MAX_OPS, MAX_WEIGHTS, MODE_ALL, MODE_FIXED_BASE, MODE_PPM_BASE, MODE_PREV, OP_BURN, OP_MINT, PPM_DENOMINATOR, STELLAR_PROGRAM_VERSION, STELLAR_SWAP_VENUES, STELLAR_SWAP_VENUE_OPCODE } from "./scval-encode.js";
|
|
28
28
|
const HEADER_LEN = 10;
|
|
29
29
|
const OP_LEN = 5;
|
|
30
30
|
const WEIGHT_LEN = 3;
|
|
@@ -164,7 +164,10 @@ const readPayloadFields = (buf)=>{
|
|
|
164
164
|
const idxA = byte(at + 2);
|
|
165
165
|
const idxB = byte(at + 3);
|
|
166
166
|
const idxC = byte(at + 4);
|
|
167
|
-
|
|
167
|
+
const venue = STELLAR_SWAP_VENUES.find((value)=>STELLAR_SWAP_VENUE_OPCODE[value] === opcode);
|
|
168
|
+
if (!venue && opcode !== OP_BURN && opcode !== OP_MINT) {
|
|
169
|
+
fail('UNKNOWN_OPCODE', `instruction ${i} has opcode ${opcode}`);
|
|
170
|
+
}
|
|
168
171
|
let mode;
|
|
169
172
|
if (modeByte === MODE_ALL) {
|
|
170
173
|
mode = {
|
|
@@ -208,7 +211,7 @@ const readPayloadFields = (buf)=>{
|
|
|
208
211
|
if (idxB === idxC) fail('INVALID_STRUCTURE', `instruction ${i} swaps a token for itself`);
|
|
209
212
|
decoded.push({
|
|
210
213
|
kind: 'swap',
|
|
211
|
-
venue:
|
|
214
|
+
venue: venue,
|
|
212
215
|
mode,
|
|
213
216
|
pool,
|
|
214
217
|
tokenIn: asset(idxB),
|
|
@@ -27,7 +27,8 @@ import { Buffer } from "buffer";
|
|
|
27
27
|
'Aquarius',
|
|
28
28
|
'Phoenix',
|
|
29
29
|
'Sushi',
|
|
30
|
-
'CometDex'
|
|
30
|
+
'CometDex',
|
|
31
|
+
'Curve'
|
|
31
32
|
];
|
|
32
33
|
/**
|
|
33
34
|
* Instruction opcode per venue. Part of the on-chain ABI — see
|
|
@@ -37,7 +38,8 @@ import { Buffer } from "buffer";
|
|
|
37
38
|
Aquarius: 1,
|
|
38
39
|
Phoenix: 2,
|
|
39
40
|
Sushi: 3,
|
|
40
|
-
CometDex: 4
|
|
41
|
+
CometDex: 4,
|
|
42
|
+
Curve: 7
|
|
41
43
|
};
|
|
42
44
|
/** Wire version of the packed program. Must match the contract's `VERSION`. */ export const STELLAR_PROGRAM_VERSION = 1;
|
|
43
45
|
/** Split weights are parts per million. */ export const PPM_DENOMINATOR = 1000000;
|