@xoxno/sdk-js 1.0.98 → 1.0.100
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/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/stellar/__tests__/lending.test.d.ts +21 -0
- package/dist/sdk/stellar/contracts.d.ts +31 -0
- package/dist/sdk/stellar/index.d.ts +2 -0
- package/dist/sdk/stellar/lending.d.ts +143 -0
- package/package.json +3 -2
package/dist/sdk/index.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stellar lending controller contract addresses + Soroban RPC config per network.
|
|
3
|
+
*
|
|
4
|
+
* Addresses are env-sourced so ops can rotate mainnet/testnet deployments without
|
|
5
|
+
* a code change. Defaults fall back to empty string so a missing env surfaces as a
|
|
6
|
+
* clear "controller address not configured" error at builder call time rather than
|
|
7
|
+
* silently pointing at the wrong contract.
|
|
8
|
+
*/
|
|
9
|
+
export type StellarNetwork = 'mainnet' | 'testnet';
|
|
10
|
+
/**
|
|
11
|
+
* Stellar controller contract addresses per network.
|
|
12
|
+
* Env vars:
|
|
13
|
+
* - STELLAR_LENDING_CONTROLLER_MAINNET
|
|
14
|
+
* - STELLAR_LENDING_CONTROLLER_TESTNET
|
|
15
|
+
*/
|
|
16
|
+
export declare const STELLAR_LENDING_CONTROLLER: Record<StellarNetwork, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Default Soroban RPC URLs per network.
|
|
19
|
+
* Overridable at runtime via the `sorobanRpcUrl` option on each builder.
|
|
20
|
+
*/
|
|
21
|
+
export declare const STELLAR_SOROBAN_RPC_URL: Record<StellarNetwork, string>;
|
|
22
|
+
/**
|
|
23
|
+
* Stellar network passphrases (Soroban tx signing domain separator).
|
|
24
|
+
* These are fixed by the Stellar network itself and must not be overridden.
|
|
25
|
+
*/
|
|
26
|
+
export declare const STELLAR_NETWORK_PASSPHRASE: Record<StellarNetwork, string>;
|
|
27
|
+
/**
|
|
28
|
+
* Assert a controller address is configured for the target network.
|
|
29
|
+
* Throws early with a clear message rather than building an XDR that points at `""`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getStellarLendingController(network: StellarNetwork): string;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stellar Soroban lending transaction builders (Wave 1B).
|
|
3
|
+
*
|
|
4
|
+
* Each builder takes a Wave 0 `*Args` DTO from @xoxno/types plus a shared
|
|
5
|
+
* `StellarBuilderOptions` ({ network, caller, sourceSequence, ... }) and
|
|
6
|
+
* returns an unsigned transaction XDR string ready for wallet signing
|
|
7
|
+
* (Freighter / LOBSTR / xBull / WalletConnect via StellarWalletsKit).
|
|
8
|
+
*
|
|
9
|
+
* Mirrors the Stellar controller entry points in
|
|
10
|
+
* rs-lending/stellar/controller/src/lib.rs:
|
|
11
|
+
*
|
|
12
|
+
* supply(caller, account_id: u64, e_mode_category: u32, assets: Vec<(Address, i128)>) -> u64
|
|
13
|
+
* borrow(caller, account_id: u64, borrows: Vec<(Address, i128)>)
|
|
14
|
+
* withdraw(caller, account_id: u64, withdrawals: Vec<(Address, i128)>)
|
|
15
|
+
* repay(caller, account_id: u64, payments: Vec<(Address, i128)>)
|
|
16
|
+
* liquidate(liquidator, account_id: u64, debt_payments: Vec<(Address, i128)>)
|
|
17
|
+
* flash_loan(caller, asset, amount: i128, receiver, data: Bytes)
|
|
18
|
+
* multiply(caller, account_id, e_mode_category, collateral_token,
|
|
19
|
+
* debt_to_flash_loan: i128, debt_token, mode: u32, steps: SwapSteps) -> u64
|
|
20
|
+
* swap_debt(caller, account_id, existing_debt_token, new_debt_amount: i128,
|
|
21
|
+
* new_debt_token, steps: SwapSteps)
|
|
22
|
+
* swap_collateral(caller, account_id, current_collateral, from_amount: i128,
|
|
23
|
+
* new_collateral, steps: SwapSteps)
|
|
24
|
+
* repay_debt_with_collateral(caller, account_id, collateral_token,
|
|
25
|
+
* collateral_amount: i128, debt_token,
|
|
26
|
+
* steps: SwapSteps, close_position: bool)
|
|
27
|
+
*
|
|
28
|
+
* i128 values cross the boundary as decimal strings and are encoded via
|
|
29
|
+
* `new ScInt(str).toI128()`. addresses (Stellar `G...` accounts and Soroban
|
|
30
|
+
* `C...` contracts) are encoded via `new Address(str).toScVal()`.
|
|
31
|
+
*
|
|
32
|
+
* These builders are RPC-free on purpose: they accept a caller-supplied
|
|
33
|
+
* `sourceSequence` so the returned XDR is deterministic and snapshot-testable.
|
|
34
|
+
* The UI hook layer (Wave 1C) is responsible for fetching the current sequence
|
|
35
|
+
* via `rpc.Server.getAccount(caller)` and calling `rpc.Server.prepareTransaction`
|
|
36
|
+
* (which handles simulation + Soroban footprint/auth/resource fee) before
|
|
37
|
+
* handing the XDR to the wallet to sign.
|
|
38
|
+
*/
|
|
39
|
+
import type { BorrowArgs, FlashLoanArgs, LiquidateArgs, MultiplyArgs, RepayArgs, RepayDebtWithCollateralArgs, SupplyArgs, SwapCollateralArgs, SwapDebtArgs, WithdrawArgs } from '@xoxno/types';
|
|
40
|
+
import { type StellarNetwork } from './contracts';
|
|
41
|
+
/**
|
|
42
|
+
* Stellar `G...` public key of the caller (tx source account).
|
|
43
|
+
*/
|
|
44
|
+
export type StellarAccountAddress = string;
|
|
45
|
+
export interface StellarBuilderOptions {
|
|
46
|
+
network: StellarNetwork;
|
|
47
|
+
caller: StellarAccountAddress;
|
|
48
|
+
/**
|
|
49
|
+
* Current sequence number of the caller account, as a decimal string.
|
|
50
|
+
* Callers fetch this from Soroban RPC (`server.getAccount(caller)`) before
|
|
51
|
+
* building. Keeping it as an input (rather than fetching inside the builder)
|
|
52
|
+
* makes builders sync-friendly, RPC-free, and deterministic for snapshot tests.
|
|
53
|
+
*/
|
|
54
|
+
sourceSequence: string;
|
|
55
|
+
/**
|
|
56
|
+
* Override the controller contract address. Normally resolved from env via
|
|
57
|
+
* `getStellarLendingController(network)` — override is for tests and
|
|
58
|
+
* preview/staging deployments.
|
|
59
|
+
*/
|
|
60
|
+
controllerAddress?: string;
|
|
61
|
+
/** Base fee in stroops (default BASE_FEE = "100"). */
|
|
62
|
+
fee?: string;
|
|
63
|
+
/** Tx timeout in seconds (default 300). */
|
|
64
|
+
timeoutSeconds?: number;
|
|
65
|
+
}
|
|
66
|
+
export interface BuiltStellarTx {
|
|
67
|
+
/** Unsigned transaction XDR (base64) ready for wallet signing. */
|
|
68
|
+
xdr: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Input shape for the Stellar-specific `SwapSteps` payload carried on
|
|
72
|
+
* `MultiplyArgs.steps`, `SwapDebtArgs.steps`, `SwapCollateralArgs.steps`,
|
|
73
|
+
* `RepayDebtWithCollateralArgs.steps`.
|
|
74
|
+
*
|
|
75
|
+
* @xoxno/types declares `steps: unknown` on the Wave 0 DTOs so every chain
|
|
76
|
+
* owns its own encoding. On Stellar, this is what callers MUST pass,
|
|
77
|
+
* which is serialised to a Soroban `Vec<SwapHop>` struct matching
|
|
78
|
+
* rs-lending/stellar/common/src/types.rs:
|
|
79
|
+
*
|
|
80
|
+
* pub struct SwapHop {
|
|
81
|
+
* pub pool_address: Address,
|
|
82
|
+
* pub token_in: Address,
|
|
83
|
+
* pub token_out: Address,
|
|
84
|
+
* pub min_amount_out: i128,
|
|
85
|
+
* }
|
|
86
|
+
*/
|
|
87
|
+
export interface StellarSwapStepsInput {
|
|
88
|
+
hops: StellarSwapHopInput[];
|
|
89
|
+
}
|
|
90
|
+
export interface StellarSwapHopInput {
|
|
91
|
+
poolAddress: string;
|
|
92
|
+
tokenIn: string;
|
|
93
|
+
tokenOut: string;
|
|
94
|
+
/** Decimal string i128. */
|
|
95
|
+
minAmountOut: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* supply(caller, account_id: u64, e_mode_category: u32, assets: Vec<(Address, i128)>)
|
|
99
|
+
* @xoxno/types `SupplyArgs` is a single-asset shape; the Stellar contract
|
|
100
|
+
* expects a batch — we wrap the single asset in a 1-element Vec.
|
|
101
|
+
*/
|
|
102
|
+
export declare function buildStellarSupplyTx(opts: StellarBuilderOptions, args: SupplyArgs): BuiltStellarTx;
|
|
103
|
+
/**
|
|
104
|
+
* borrow(caller, account_id: u64, borrows: Vec<(Address, i128)>)
|
|
105
|
+
*/
|
|
106
|
+
export declare function buildStellarBorrowTx(opts: StellarBuilderOptions, args: BorrowArgs): BuiltStellarTx;
|
|
107
|
+
/**
|
|
108
|
+
* withdraw(caller, account_id: u64, withdrawals: Vec<(Address, i128)>)
|
|
109
|
+
*/
|
|
110
|
+
export declare function buildStellarWithdrawTx(opts: StellarBuilderOptions, args: WithdrawArgs): BuiltStellarTx;
|
|
111
|
+
/**
|
|
112
|
+
* repay(caller, account_id: u64, payments: Vec<(Address, i128)>)
|
|
113
|
+
*/
|
|
114
|
+
export declare function buildStellarRepayTx(opts: StellarBuilderOptions, args: RepayArgs): BuiltStellarTx;
|
|
115
|
+
/**
|
|
116
|
+
* liquidate(liquidator, account_id: u64, debt_payments: Vec<(Address, i128)>)
|
|
117
|
+
*/
|
|
118
|
+
export declare function buildStellarLiquidateTx(opts: StellarBuilderOptions, args: LiquidateArgs): BuiltStellarTx;
|
|
119
|
+
/**
|
|
120
|
+
* flash_loan(caller, asset, amount: i128, receiver, data: Bytes)
|
|
121
|
+
*/
|
|
122
|
+
export declare function buildStellarFlashLoanTx(opts: StellarBuilderOptions, args: FlashLoanArgs): BuiltStellarTx;
|
|
123
|
+
/**
|
|
124
|
+
* multiply(caller, account_id, e_mode_category, collateral_token,
|
|
125
|
+
* debt_to_flash_loan: i128, debt_token, mode: u32, steps: SwapSteps) -> u64
|
|
126
|
+
*/
|
|
127
|
+
export declare function buildStellarMultiplyTx(opts: StellarBuilderOptions, args: MultiplyArgs): BuiltStellarTx;
|
|
128
|
+
/**
|
|
129
|
+
* swap_debt(caller, account_id, existing_debt_token, new_debt_amount: i128,
|
|
130
|
+
* new_debt_token, steps: SwapSteps)
|
|
131
|
+
*/
|
|
132
|
+
export declare function buildStellarSwapDebtTx(opts: StellarBuilderOptions, args: SwapDebtArgs): BuiltStellarTx;
|
|
133
|
+
/**
|
|
134
|
+
* swap_collateral(caller, account_id, current_collateral, from_amount: i128,
|
|
135
|
+
* new_collateral, steps: SwapSteps)
|
|
136
|
+
*/
|
|
137
|
+
export declare function buildStellarSwapCollateralTx(opts: StellarBuilderOptions, args: SwapCollateralArgs): BuiltStellarTx;
|
|
138
|
+
/**
|
|
139
|
+
* repay_debt_with_collateral(caller, account_id, collateral_token,
|
|
140
|
+
* collateral_amount: i128, debt_token,
|
|
141
|
+
* steps: SwapSteps, close_position: bool)
|
|
142
|
+
*/
|
|
143
|
+
export declare function buildStellarRepayDebtWithCollateralTx(opts: StellarBuilderOptions, args: RepayDebtWithCollateralArgs): BuiltStellarTx;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xoxno/sdk-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.100",
|
|
4
4
|
"description": "The SDK to interact with the XOXNO Protocol!",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
"dependencies": {
|
|
94
94
|
"@multiversx/sdk-core": "^15.3.2",
|
|
95
95
|
"@multiversx/sdk-network-providers": "^2.9.3",
|
|
96
|
-
"@
|
|
96
|
+
"@stellar/stellar-sdk": "^15.0.1",
|
|
97
|
+
"@xoxno/types": "^1.0.384"
|
|
97
98
|
}
|
|
98
99
|
}
|