@xoxno/sdk-js 1.0.224 → 1.0.226
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/README.md +39 -0
- package/dist/cjs/sdk/stellar/index.d.ts +1 -0
- package/dist/cjs/sdk/stellar/read/__tests__/client.test.d.ts +1 -0
- package/dist/cjs/sdk/stellar/read/client.d.ts +19 -0
- package/dist/cjs/sdk/stellar/read/index.d.ts +4 -0
- package/dist/cjs/sdk/stellar/read/schemas.d.ts +370 -0
- package/dist/cjs/sdk/stellar/read/types.d.ts +83 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/sdk/index.js +198 -0
- package/dist/esm/sdk/stellar/admin.js +385 -0
- package/dist/esm/sdk/stellar/auth-policy.js +310 -0
- package/dist/esm/sdk/stellar/cctp.js +23 -0
- package/dist/esm/sdk/stellar/contracts.js +49 -0
- package/dist/esm/sdk/stellar/events/decode.js +415 -0
- package/dist/esm/sdk/stellar/events/id.js +62 -0
- package/dist/esm/sdk/stellar/events/index.js +2 -0
- package/dist/esm/sdk/stellar/governance.js +403 -0
- package/dist/esm/sdk/stellar/index.js +26 -0
- package/dist/esm/sdk/stellar/lending-api-types.js +3 -0
- package/dist/esm/sdk/stellar/lending-read-types.js +1 -0
- package/dist/esm/sdk/stellar/lending-read.js +341 -0
- package/dist/esm/sdk/stellar/lending.js +358 -0
- package/dist/esm/sdk/stellar/math/account.js +256 -0
- package/dist/esm/sdk/stellar/math/index.js +11 -0
- package/dist/esm/sdk/stellar/math/limits.js +273 -0
- package/dist/esm/sdk/stellar/math/projection.js +130 -0
- package/dist/esm/sdk/stellar/math/rates.js +62 -0
- package/dist/esm/sdk/stellar/math/scaled.js +156 -0
- package/dist/esm/sdk/stellar/position-mode.js +11 -0
- package/dist/esm/sdk/stellar/prepare.js +47 -0
- package/dist/esm/sdk/stellar/quote.js +87 -0
- package/dist/esm/sdk/stellar/read/client.js +82 -0
- package/dist/esm/sdk/stellar/read/index.js +3 -0
- package/dist/esm/sdk/stellar/read/schemas.js +158 -0
- package/dist/esm/sdk/stellar/read/types.js +1 -0
- package/dist/esm/sdk/stellar/repay-swap.js +12 -0
- package/dist/esm/sdk/stellar/route-verify.js +285 -0
- package/dist/esm/sdk/stellar/scval-encode.js +464 -0
- package/dist/esm/sdk/stellar/swap-history.js +46 -0
- package/dist/esm/sdk/stellar/swap-index.js +1 -0
- package/dist/esm/sdk/stellar/swap.js +117 -0
- package/dist/esm/sdk/stellar/xdr-compat.js +17 -0
- package/dist/esm/sdk/stellar-schema.js +129 -0
- package/dist/esm/sdk/swagger.js +1957 -0
- package/dist/esm/sdk/types.js +1 -0
- package/dist/esm/sdk/utils.js +21 -0
- package/dist/esm/utils/api.js +169 -0
- package/dist/esm/utils/const.js +11 -0
- package/dist/esm/utils/errors.js +20 -0
- package/dist/esm/utils/guards.js +29 -0
- package/dist/esm/utils/helpers.js +20 -0
- package/dist/esm/utils/regex.js +14 -0
- package/dist/esm/utils/soroban-errors.js +149 -0
- package/dist/index.cjs +1 -1
- package/dist/index.esm.js +1 -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/read/__tests__/client.test.d.ts +1 -0
- package/dist/sdk/stellar/read/client.d.ts +19 -0
- package/dist/sdk/stellar/read/index.cjs +1 -0
- package/dist/sdk/stellar/read/index.d.ts +4 -0
- package/dist/sdk/stellar/read/index.esm.js +1 -0
- package/dist/sdk/stellar/read/schemas.d.ts +370 -0
- package/dist/sdk/stellar/read/types.d.ts +83 -0
- package/package.json +20 -4
- package/dist/index.esm.js.LICENSE.txt +0 -8
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stellar lending governance (timelock) transaction builders. Each builder
|
|
3
|
+
* returns an unsigned `BuiltStellarTx` XDR targeting the governance contract
|
|
4
|
+
* selected explicitly by `opts.governanceAddress`.
|
|
5
|
+
*
|
|
6
|
+
* Flow:
|
|
7
|
+
* - An admin holding the PROPOSER role calls the single `propose(proposer,
|
|
8
|
+
* op: AdminOperation, salt)` entrypoint. `proposer = opts.caller`; `op` is
|
|
9
|
+
* the serialized `AdminOperation` enum identifying the target setter and its
|
|
10
|
+
* args; `salt: BytesN<32>` is trailing. Validation runs at propose time and
|
|
11
|
+
* the call returns the operation id (`BytesN<32>`).
|
|
12
|
+
* - After the timelock delay, ANYONE executes. Controller-targeted ops go
|
|
13
|
+
* through the generic `execute(executor, target, function, args,
|
|
14
|
+
* predecessor, salt)`; governance-self ops go through `execute_self(executor,
|
|
15
|
+
* op: AdminOperation, salt)`. Open execution passes `executor = None`
|
|
16
|
+
* (Soroban `Option::None`, encoded as `scvVoid`).
|
|
17
|
+
* - `predecessor` is ALWAYS the 32-zero-byte `BytesN<32>` in this system.
|
|
18
|
+
*
|
|
19
|
+
* The on-chain scheduled `Operation` (target, function, args) is byte-identical
|
|
20
|
+
* to the pre-enum typed proposers, so the operation id, the generic `execute`
|
|
21
|
+
* path, and event indexing are unchanged. The `AdminOperation` enum only changes
|
|
22
|
+
* the `propose` / `execute_self` call encoding, which these builders own.
|
|
23
|
+
*
|
|
24
|
+
* Builders are RPC-free and deterministic (synthetic `Account(caller,
|
|
25
|
+
* sourceSequence)`), exactly like the lending / admin builders. The returned
|
|
26
|
+
* XDR still needs `rpc.Server.prepareTransaction` before signing.
|
|
27
|
+
*/ import { Buffer } from "buffer";
|
|
28
|
+
import { Account, BASE_FEE, Contract, TransactionBuilder, xdr } from "@stellar/stellar-sdk";
|
|
29
|
+
import { encodeAssetOracle, encodeInterestRateModel, encodeMarketParamsRaw, encodePositionLimits, encodePriceKey } from "./admin.js";
|
|
30
|
+
import { STELLAR_NETWORK_PASSPHRASE } from "./contracts.js";
|
|
31
|
+
import { addr, bool, bytesN, hubAsset, i128, option, scStruct, sym, u32, vec, voidVal } from "./scval-encode.js";
|
|
32
|
+
/** The 32-zero-byte `BytesN<32>` predecessor used for every op in this system. */ export const STELLAR_GOVERNANCE_ZERO_PREDECESSOR = '00'.repeat(32);
|
|
33
|
+
/**
|
|
34
|
+
* Coerce a 32-byte hex string / Buffer / Uint8Array salt into a Soroban
|
|
35
|
+
* `BytesN<32>` ScVal. Validates the length at the SDK boundary.
|
|
36
|
+
*/ const saltScVal = (salt)=>{
|
|
37
|
+
if (typeof salt === 'string') return bytesN(salt);
|
|
38
|
+
const buf = Buffer.from(salt);
|
|
39
|
+
if (buf.length !== 32) {
|
|
40
|
+
throw new Error(`Stellar governance builder: expected a 32-byte salt (got ${buf.length} bytes)`);
|
|
41
|
+
}
|
|
42
|
+
return xdr.ScVal.scvBytes(buf);
|
|
43
|
+
};
|
|
44
|
+
// -----------------------------------------------------------------------------
|
|
45
|
+
// AdminOperation enum encoding
|
|
46
|
+
// -----------------------------------------------------------------------------
|
|
47
|
+
/**
|
|
48
|
+
* Encode an `AdminOperation` enum value. At the XDR level a Soroban enum value
|
|
49
|
+
* is `scvVec([scvSymbol(VariantName), ...payload])`: a unit variant carries only
|
|
50
|
+
* the symbol, a single/tuple variant appends its fields in declaration order,
|
|
51
|
+
* and a struct-carrying variant appends the single `scStruct(..)` payload. The
|
|
52
|
+
* `VariantName` MUST match the Rust `AdminOperation` variant identifier exactly.
|
|
53
|
+
*/ const adminOp = (variant, ...payload)=>vec([
|
|
54
|
+
sym(variant),
|
|
55
|
+
...payload
|
|
56
|
+
]);
|
|
57
|
+
// Argument-struct encoders. The `scStruct` keys MUST be the Rust struct field
|
|
58
|
+
// names (snake_case); `scStruct` sorts them lexicographically into the `scvMap`
|
|
59
|
+
// layout the contract decodes. Builder arg interfaces stay camelCase.
|
|
60
|
+
const encodeCreatePoolArgs = (a)=>scStruct({
|
|
61
|
+
asset: addr(a.asset),
|
|
62
|
+
hub_id: u32(a.hubId),
|
|
63
|
+
params: encodeMarketParamsRaw(a.params)
|
|
64
|
+
});
|
|
65
|
+
const encodeUpgradePoolParamsArgs = (a)=>scStruct({
|
|
66
|
+
hub_asset: hubAsset(a.hubId, a.asset),
|
|
67
|
+
params: encodeInterestRateModel(a.params)
|
|
68
|
+
});
|
|
69
|
+
const encodeTransferOwnershipArgs = (a)=>scStruct({
|
|
70
|
+
new_owner: addr(a.newOwner),
|
|
71
|
+
live_until_ledger: u32(a.liveUntilLedger)
|
|
72
|
+
});
|
|
73
|
+
const encodeConfigureAssetOracleArgs = (a)=>scStruct({
|
|
74
|
+
key: encodePriceKey(a.key),
|
|
75
|
+
oracle: encodeAssetOracle(a.oracle)
|
|
76
|
+
});
|
|
77
|
+
// Keys MUST be exactly the Rust `SpokeAssetArgs` fields — a Soroban struct
|
|
78
|
+
// decodes from an ScMap whose key set matches the declaration exactly, so a
|
|
79
|
+
// stale extra key fails the whole proposal at decode time.
|
|
80
|
+
const encodeSpokeAssetArgs = (a)=>scStruct({
|
|
81
|
+
asset: addr(a.asset),
|
|
82
|
+
bonus: u32(a.bonus),
|
|
83
|
+
borrow_cap: i128(a.borrowCap),
|
|
84
|
+
can_borrow: bool(a.canBorrow),
|
|
85
|
+
can_collateral: bool(a.canCollateral),
|
|
86
|
+
frozen: bool(a.frozen),
|
|
87
|
+
hub_id: u32(a.hubId),
|
|
88
|
+
paused: bool(a.paused),
|
|
89
|
+
liquidation_fees: u32(a.liquidationFees),
|
|
90
|
+
ltv: u32(a.ltv),
|
|
91
|
+
no_seize: bool(a.noSeize),
|
|
92
|
+
spoke_id: u32(a.spokeId),
|
|
93
|
+
supply_cap: i128(a.supplyCap),
|
|
94
|
+
threshold: u32(a.threshold)
|
|
95
|
+
});
|
|
96
|
+
const encodeRemoveAssetFromSpokeArgs = (a)=>scStruct({
|
|
97
|
+
hub_asset: hubAsset(a.hubId, a.asset),
|
|
98
|
+
spoke_id: u32(a.spokeId)
|
|
99
|
+
});
|
|
100
|
+
const encodeSpokeLiquidationCurveArgs = (a)=>scStruct({
|
|
101
|
+
hf_for_max_bonus_wad: i128(a.hfForMaxBonusWad),
|
|
102
|
+
liquidation_bonus_factor_bps: u32(a.liquidationBonusFactorBps),
|
|
103
|
+
spoke_id: u32(a.spokeId),
|
|
104
|
+
target_hf_wad: i128(a.targetHfWad)
|
|
105
|
+
});
|
|
106
|
+
const encodeEditToleranceArgs = (a)=>scStruct({
|
|
107
|
+
key: encodePriceKey(a.key),
|
|
108
|
+
tolerance: u32(a.tolerance)
|
|
109
|
+
});
|
|
110
|
+
const encodeRoleArgs = (a)=>scStruct({
|
|
111
|
+
account: addr(a.account),
|
|
112
|
+
role: sym(a.role)
|
|
113
|
+
});
|
|
114
|
+
// -----------------------------------------------------------------------------
|
|
115
|
+
// Governance transaction assembly
|
|
116
|
+
// -----------------------------------------------------------------------------
|
|
117
|
+
/**
|
|
118
|
+
* Assemble an unsigned XDR invoking a single method on the GOVERNANCE contract.
|
|
119
|
+
* Mirrors `buildTx` (lending.ts) but resolves `opts.governanceAddress` instead
|
|
120
|
+
* of the controller address. RPC-free + deterministic.
|
|
121
|
+
*/ function buildGovernanceTx(opts, method, params) {
|
|
122
|
+
if (!opts.governanceAddress) {
|
|
123
|
+
throw new Error('Stellar governanceAddress is required');
|
|
124
|
+
}
|
|
125
|
+
const contract = new Contract(opts.governanceAddress);
|
|
126
|
+
const source = new Account(opts.caller, opts.sourceSequence);
|
|
127
|
+
const tx = new TransactionBuilder(source, {
|
|
128
|
+
fee: opts.fee ?? BASE_FEE,
|
|
129
|
+
networkPassphrase: STELLAR_NETWORK_PASSPHRASE[opts.network]
|
|
130
|
+
}).addOperation(contract.call(method, ...params)).setTimeout(opts.timeoutSeconds ?? 300).build();
|
|
131
|
+
return {
|
|
132
|
+
xdr: tx.toXDR()
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Build a `propose(proposer, op, salt)` tx: `proposer = opts.caller`, then the
|
|
137
|
+
* `AdminOperation`, then `salt`. The caller must hold PROPOSER and sign the tx.
|
|
138
|
+
*/ const buildPropose = (opts, op, salt)=>buildGovernanceTx(opts, 'propose', [
|
|
139
|
+
addr(opts.caller),
|
|
140
|
+
op,
|
|
141
|
+
saltScVal(salt)
|
|
142
|
+
]);
|
|
143
|
+
/**
|
|
144
|
+
* Build an `execute_self(executor, op, salt)` (governance-self) tx: `executor =
|
|
145
|
+
* None`, then the `AdminOperation`, then `salt`. Open execution — any account
|
|
146
|
+
* may sign. Self-target ops cannot use the generic `execute` (the timelock
|
|
147
|
+
* rejects `target == governance` to avoid self-reentry).
|
|
148
|
+
*/ const buildExecuteSelf = (opts, op, salt)=>buildGovernanceTx(opts, 'execute_self', [
|
|
149
|
+
voidVal(),
|
|
150
|
+
op,
|
|
151
|
+
saltScVal(salt)
|
|
152
|
+
]);
|
|
153
|
+
// -----------------------------------------------------------------------------
|
|
154
|
+
// CONTROLLER-targeted proposers — proposer + AdminOperation + salt
|
|
155
|
+
// -----------------------------------------------------------------------------
|
|
156
|
+
/** propose(SetSwapAggregator(addr)) */ export function buildStellarProposeSetSwapAggregatorTx(opts, args, salt) {
|
|
157
|
+
return buildPropose(opts, adminOp('SetSwapAggregator', addr(args.aggregator)), salt);
|
|
158
|
+
}
|
|
159
|
+
/** propose(SetPriceAggregator(addr)) — Sensitive-tier self-op. */ export function buildStellarProposeSetPriceAggregatorTx(opts, args, salt) {
|
|
160
|
+
return buildPropose(opts, adminOp('SetPriceAggregator', addr(args.aggregator)), salt);
|
|
161
|
+
}
|
|
162
|
+
/** propose(SetAccumulator(addr)) */ export function buildStellarProposeSetAccumulatorTx(opts, args, salt) {
|
|
163
|
+
return buildPropose(opts, adminOp('SetAccumulator', addr(args.accumulator)), salt);
|
|
164
|
+
}
|
|
165
|
+
/** propose(SetPositionLimits(limits)) */ export function buildStellarProposeSetPositionLimitsTx(opts, args, salt) {
|
|
166
|
+
return buildPropose(opts, adminOp('SetPositionLimits', encodePositionLimits(args)), salt);
|
|
167
|
+
}
|
|
168
|
+
/** propose(CreateHub) */ export function buildStellarProposeCreateHubTx(opts, salt) {
|
|
169
|
+
return buildPropose(opts, adminOp('CreateHub'), salt);
|
|
170
|
+
}
|
|
171
|
+
/** propose(AddSpoke) */ export function buildStellarProposeAddSpokeTx(opts, salt) {
|
|
172
|
+
return buildPropose(opts, adminOp('AddSpoke'), salt);
|
|
173
|
+
}
|
|
174
|
+
/** propose(RemoveSpoke(spoke_id)) */ export function buildStellarProposeRemoveSpokeTx(opts, args, salt) {
|
|
175
|
+
return buildPropose(opts, adminOp('RemoveSpoke', u32(args.spokeId)), salt);
|
|
176
|
+
}
|
|
177
|
+
/** propose(AddAssetToSpoke(SpokeAssetArgs)) */ export function buildStellarProposeAddAssetToSpokeTx(opts, args, salt) {
|
|
178
|
+
return buildPropose(opts, adminOp('AddAssetToSpoke', encodeSpokeAssetArgs(args)), salt);
|
|
179
|
+
}
|
|
180
|
+
/** propose(EditAssetInSpoke(SpokeAssetArgs)) */ export function buildStellarProposeEditAssetInSpokeTx(opts, args, salt) {
|
|
181
|
+
return buildPropose(opts, adminOp('EditAssetInSpoke', encodeSpokeAssetArgs(args)), salt);
|
|
182
|
+
}
|
|
183
|
+
/** propose(RemoveAssetFromSpoke(RemoveAssetFromSpokeArgs)) */ export function buildStellarProposeRemoveAssetFromSpokeTx(opts, args, salt) {
|
|
184
|
+
return buildPropose(opts, adminOp('RemoveAssetFromSpoke', encodeRemoveAssetFromSpokeArgs(args)), salt);
|
|
185
|
+
}
|
|
186
|
+
/** propose(SetSpokeLiquidationCurve(SpokeLiquidationCurveArgs)) */ export function buildStellarProposeSetSpokeLiquidationCurveTx(opts, args, salt) {
|
|
187
|
+
return buildPropose(opts, adminOp('SetSpokeLiquidationCurve', encodeSpokeLiquidationCurveArgs(args)), salt);
|
|
188
|
+
}
|
|
189
|
+
/** propose(SetPositionManager(manager, is_active)) — tuple variant. */ export function buildStellarProposeSetPositionManagerTx(opts, args, salt) {
|
|
190
|
+
return buildPropose(opts, adminOp('SetPositionManager', addr(args.manager), bool(args.isActive)), salt);
|
|
191
|
+
}
|
|
192
|
+
/** propose(SetMinBorrowCollateralUsd(floor_wad)) */ export function buildStellarProposeSetMinBorrowCollatTx(opts, args, salt) {
|
|
193
|
+
return buildPropose(opts, adminOp('SetMinBorrowCollateralUsd', i128(args.floorWad)), salt);
|
|
194
|
+
}
|
|
195
|
+
/** propose(ApproveToken(token)) */ export function buildStellarProposeApproveTokenTx(opts, args, salt) {
|
|
196
|
+
return buildPropose(opts, adminOp('ApproveToken', addr(args.token)), salt);
|
|
197
|
+
}
|
|
198
|
+
/** propose(RevokeToken(token)) */ export function buildStellarProposeRevokeTokenTx(opts, args, salt) {
|
|
199
|
+
return buildPropose(opts, adminOp('RevokeToken', addr(args.token)), salt);
|
|
200
|
+
}
|
|
201
|
+
/** propose(ApproveBlendPool(pool)) */ export function buildStellarProposeApproveBlendPoolTx(opts, args, salt) {
|
|
202
|
+
return buildPropose(opts, adminOp('ApproveBlendPool', addr(args.pool)), salt);
|
|
203
|
+
}
|
|
204
|
+
/** propose(RevokeBlendPool(pool)) */ export function buildStellarProposeRevokeBlendPoolTx(opts, args, salt) {
|
|
205
|
+
return buildPropose(opts, adminOp('RevokeBlendPool', addr(args.pool)), salt);
|
|
206
|
+
}
|
|
207
|
+
/** propose(CreateLiquidityPool(CreatePoolArgs)) */ export function buildStellarProposeCreateLiquidityPoolTx(opts, args, salt) {
|
|
208
|
+
return buildPropose(opts, adminOp('CreateLiquidityPool', encodeCreatePoolArgs(args)), salt);
|
|
209
|
+
}
|
|
210
|
+
/** propose(UpgradeLiquidityPoolParams(UpgradePoolParamsArgs)) */ export function buildStellarProposeUpgradePoolParamsTx(opts, args, salt) {
|
|
211
|
+
return buildPropose(opts, adminOp('UpgradeLiquidityPoolParams', encodeUpgradePoolParamsArgs(args)), salt);
|
|
212
|
+
}
|
|
213
|
+
/** propose(DeployPool(hash)) */ export function buildStellarProposeDeployPoolTx(opts, args, salt) {
|
|
214
|
+
return buildPropose(opts, adminOp('DeployPool', bytesN(args.wasmHash)), salt);
|
|
215
|
+
}
|
|
216
|
+
/** propose(UpgradePool(hash)) */ export function buildStellarProposeUpgradePoolTx(opts, args, salt) {
|
|
217
|
+
return buildPropose(opts, adminOp('UpgradePool', bytesN(args.wasmHash)), salt);
|
|
218
|
+
}
|
|
219
|
+
/** propose(UpgradeController(hash)) */ export function buildStellarProposeUpgradeControllerTx(opts, args, salt) {
|
|
220
|
+
return buildPropose(opts, adminOp('UpgradeController', bytesN(args.wasmHash)), salt);
|
|
221
|
+
}
|
|
222
|
+
/** propose(MigrateController(new_version)) */ export function buildStellarProposeMigrateControllerTx(opts, args, salt) {
|
|
223
|
+
return buildPropose(opts, adminOp('MigrateController', u32(args.newVersion)), salt);
|
|
224
|
+
}
|
|
225
|
+
/** propose(TransferCtrlOwnership(TransferOwnershipArgs)) */ export function buildStellarProposeTransferCtrlOwnershipTx(opts, args, salt) {
|
|
226
|
+
return buildPropose(opts, adminOp('TransferCtrlOwnership', encodeTransferOwnershipArgs(args)), salt);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* propose(ConfigureAssetOracle(ConfigureAssetOracleArgs))
|
|
230
|
+
*
|
|
231
|
+
* Pass PriceKey + AssetOracle input; governance resolves asset_decimals for
|
|
232
|
+
* Token keys at propose time.
|
|
233
|
+
*/ export function buildStellarProposeConfigureAssetOracleTx(opts, args, salt) {
|
|
234
|
+
return buildPropose(opts, adminOp('ConfigureAssetOracle', encodeConfigureAssetOracleArgs(args)), salt);
|
|
235
|
+
}
|
|
236
|
+
/** propose(EditOracleTolerance(EditToleranceArgs)) */ export function buildStellarProposeEditOracleToleranceTx(opts, args, salt) {
|
|
237
|
+
return buildPropose(opts, adminOp('EditOracleTolerance', encodeEditToleranceArgs(args)), salt);
|
|
238
|
+
}
|
|
239
|
+
// -----------------------------------------------------------------------------
|
|
240
|
+
// GOVERNANCE-self proposers — proposer + AdminOperation + salt
|
|
241
|
+
// -----------------------------------------------------------------------------
|
|
242
|
+
/** propose(UpgradeGov(hash)) */ export function buildStellarProposeGovernanceUpgradeTx(opts, args, salt) {
|
|
243
|
+
return buildPropose(opts, adminOp('UpgradeGov', bytesN(args.wasmHash)), salt);
|
|
244
|
+
}
|
|
245
|
+
/** propose(UpdateGovDelay(new_delay)) */ export function buildStellarProposeUpdateDelayTx(opts, args, salt) {
|
|
246
|
+
return buildPropose(opts, adminOp('UpdateGovDelay', u32(args.newDelay)), salt);
|
|
247
|
+
}
|
|
248
|
+
/** propose(GrantGovRole(RoleArgs)) */ export function buildStellarProposeGrantGovernanceRoleTx(opts, args, salt) {
|
|
249
|
+
return buildPropose(opts, adminOp('GrantGovRole', encodeRoleArgs(args)), salt);
|
|
250
|
+
}
|
|
251
|
+
/** propose(RevokeGovRole(RoleArgs)) */ export function buildStellarProposeRevokeGovernanceRoleTx(opts, args, salt) {
|
|
252
|
+
return buildPropose(opts, adminOp('RevokeGovRole', encodeRoleArgs(args)), salt);
|
|
253
|
+
}
|
|
254
|
+
/** propose(TransferGovOwnership(TransferOwnershipArgs)) */ export function buildStellarProposeTransferGovOwnTx(opts, args, salt) {
|
|
255
|
+
return buildPropose(opts, adminOp('TransferGovOwnership', encodeTransferOwnershipArgs(args)), salt);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Generic `execute(executor, target, function, args, predecessor, salt)` for a
|
|
259
|
+
* controller-targeted op. `executor = None` (open execution), `target` is the
|
|
260
|
+
* controller `Address`, `function` is a `Symbol`, `args` is the `Vec<Val>`
|
|
261
|
+
* reconstructed from `argsXdr`, `predecessor` defaults to 32 zero bytes.
|
|
262
|
+
*
|
|
263
|
+
* Unchanged by the AdminOperation refactor: the scheduled `Operation` is
|
|
264
|
+
* byte-identical, so callers reconstruct `(target, function, argsXdr)` from the
|
|
265
|
+
* indexed proposal exactly as before.
|
|
266
|
+
*/ export function buildStellarGovernanceExecuteTx(opts, args) {
|
|
267
|
+
const callArgs = vec(args.argsXdr.map((s)=>xdr.ScVal.fromXDR(s, 'base64')));
|
|
268
|
+
const predecessor = saltScVal(args.predecessor ?? STELLAR_GOVERNANCE_ZERO_PREDECESSOR);
|
|
269
|
+
return buildGovernanceTx(opts, 'execute', [
|
|
270
|
+
voidVal(),
|
|
271
|
+
addr(args.target),
|
|
272
|
+
sym(args.functionName),
|
|
273
|
+
callArgs,
|
|
274
|
+
predecessor,
|
|
275
|
+
saltScVal(args.salt)
|
|
276
|
+
]);
|
|
277
|
+
}
|
|
278
|
+
/** execute_self(executor=None, UpgradeGov(hash), salt) */ export function buildStellarGovernanceExecuteGovernanceUpgradeTx(opts, args, salt) {
|
|
279
|
+
return buildExecuteSelf(opts, adminOp('UpgradeGov', bytesN(args.wasmHash)), salt);
|
|
280
|
+
}
|
|
281
|
+
/** execute_self(executor=None, UpdateGovDelay(new_delay), salt) */ export function buildStellarGovernanceExecuteUpdateDelayTx(opts, args, salt) {
|
|
282
|
+
return buildExecuteSelf(opts, adminOp('UpdateGovDelay', u32(args.newDelay)), salt);
|
|
283
|
+
}
|
|
284
|
+
/** execute_self(executor=None, GrantGovRole(RoleArgs), salt) */ export function buildStellarGovernanceExecuteGrantGovernanceRoleTx(opts, args, salt) {
|
|
285
|
+
return buildExecuteSelf(opts, adminOp('GrantGovRole', encodeRoleArgs(args)), salt);
|
|
286
|
+
}
|
|
287
|
+
/** execute_self(executor=None, RevokeGovRole(RoleArgs), salt) */ export function buildStellarGovernanceExecuteRevokeGovernanceRoleTx(opts, args, salt) {
|
|
288
|
+
return buildExecuteSelf(opts, adminOp('RevokeGovRole', encodeRoleArgs(args)), salt);
|
|
289
|
+
}
|
|
290
|
+
/** execute_self(executor=None, TransferGovOwnership(TransferOwnershipArgs), salt) */ export function buildStellarGovernanceExecuteTransferGovOwnTx(opts, args, salt) {
|
|
291
|
+
return buildExecuteSelf(opts, adminOp('TransferGovOwnership', encodeTransferOwnershipArgs(args)), salt);
|
|
292
|
+
}
|
|
293
|
+
const addressVec = (addresses)=>vec(addresses.map(addr));
|
|
294
|
+
/**
|
|
295
|
+
* propose_canceller_reset(new_cancellers, salt) — owner-only, non-vetoable
|
|
296
|
+
* council reset scheduled at the Recovery delay; direct entrypoint, not
|
|
297
|
+
* `AdminOperation`. `#[only_owner]` takes no `caller` param — the tx source
|
|
298
|
+
* (`opts.caller`) must be the governance owner and sign. Returns the
|
|
299
|
+
* operation id.
|
|
300
|
+
*/ export function buildStellarProposeCancellerResetTx(opts, args, salt) {
|
|
301
|
+
return buildGovernanceTx(opts, 'propose_canceller_reset', [
|
|
302
|
+
addressVec(args.newCancellers),
|
|
303
|
+
saltScVal(salt)
|
|
304
|
+
]);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* execute_canceller_reset(executor, new_cancellers, salt) — executes a
|
|
308
|
+
* matured council reset; direct entrypoint, not `execute_self` /
|
|
309
|
+
* `AdminOperation`. `executor` omitted leaves execution open to any account;
|
|
310
|
+
* `newCancellers` and `salt` MUST match the values passed to
|
|
311
|
+
* `buildStellarProposeCancellerResetTx`.
|
|
312
|
+
*/ export function buildStellarExecuteCancellerResetTx(opts, args, salt) {
|
|
313
|
+
return buildGovernanceTx(opts, 'execute_canceller_reset', [
|
|
314
|
+
option(args.executor, addr),
|
|
315
|
+
addressVec(args.newCancellers),
|
|
316
|
+
saltScVal(salt)
|
|
317
|
+
]);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* set_spoke_asset_flags(caller, spoke_id, hub_asset, paused, frozen, no_seize)
|
|
321
|
+
* — GUARDIAN-gated, immediate. Flags-only per-listing incident brake: no risk
|
|
322
|
+
* params or caps travel with it. `caller = opts.caller` must hold GUARDIAN and
|
|
323
|
+
* sign.
|
|
324
|
+
*
|
|
325
|
+
* All three flags are one-way ratchets on this path — the guardian may only
|
|
326
|
+
* set them true. Clearing any of them requires the timelocked
|
|
327
|
+
* `EditAssetInSpoke` proposal.
|
|
328
|
+
*/ export function buildStellarGovernanceSetSpokeAssetFlagsImmediateTx(opts, args) {
|
|
329
|
+
return buildGovernanceTx(opts, 'set_spoke_asset_flags', [
|
|
330
|
+
addr(opts.caller),
|
|
331
|
+
u32(args.spokeId),
|
|
332
|
+
hubAsset(args.hubId, args.asset),
|
|
333
|
+
bool(args.paused),
|
|
334
|
+
bool(args.frozen),
|
|
335
|
+
bool(args.noSeize)
|
|
336
|
+
]);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* set_oracle_sanity_bounds(caller, asset, min_wad, max_wad) — ORACLE-gated,
|
|
340
|
+
* immediate. Moves only the sanity band; the controller requires the new band
|
|
341
|
+
* to contain the current live price AND overlap the previous band (bands walk,
|
|
342
|
+
* never teleport). Reverts: InvalidSanityBounds (malformed or disjoint from
|
|
343
|
+
* the old band), SanityBoundViolated (live price outside the new band),
|
|
344
|
+
* PriceFeedStale (feed cannot prove containment). `caller = opts.caller` must
|
|
345
|
+
* hold ORACLE and sign.
|
|
346
|
+
*/ export function buildStellarGovernanceSetOracleSanityBoundsImmediateTx(opts, args) {
|
|
347
|
+
return buildGovernanceTx(opts, 'set_oracle_sanity_bounds', [
|
|
348
|
+
addr(opts.caller),
|
|
349
|
+
addr(args.asset),
|
|
350
|
+
i128(args.minPriceWad),
|
|
351
|
+
i128(args.maxPriceWad)
|
|
352
|
+
]);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* create_hub(caller) — GUARDIAN-gated, immediate; returns the new hub id.
|
|
356
|
+
* The registry entry is inert until assets are listed through the timelocked
|
|
357
|
+
* path. Distinct from `buildStellarProposeCreateHubTx` (timelock).
|
|
358
|
+
*/ export function buildStellarGovernanceCreateHubImmediateTx(opts) {
|
|
359
|
+
return buildGovernanceTx(opts, 'create_hub', [
|
|
360
|
+
addr(opts.caller)
|
|
361
|
+
]);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* add_spoke(caller) — GUARDIAN-gated, immediate; returns the new spoke id.
|
|
365
|
+
* Listings on it still ride the timelock. Distinct from
|
|
366
|
+
* `buildStellarProposeAddSpokeTx` (timelock).
|
|
367
|
+
*/ export function buildStellarGovernanceAddSpokeImmediateTx(opts) {
|
|
368
|
+
return buildGovernanceTx(opts, 'add_spoke', [
|
|
369
|
+
addr(opts.caller)
|
|
370
|
+
]);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* revoke_role_immediate(account, role) — owner-gated emergency
|
|
374
|
+
* de-authorization; accepts only the immediate incident roles GUARDIAN and
|
|
375
|
+
* ORACLE (`InvalidRole` otherwise). Grants and PROPOSER/EXECUTOR/CANCELLER
|
|
376
|
+
* revocations stay timelocked. The tx source (`opts.caller`) must be the
|
|
377
|
+
* governance owner.
|
|
378
|
+
*/ export function buildStellarGovernanceRevokeRoleImmediateTx(opts, args) {
|
|
379
|
+
return buildGovernanceTx(opts, 'revoke_role_immediate', [
|
|
380
|
+
addr(args.account),
|
|
381
|
+
sym(args.role)
|
|
382
|
+
]);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* pause(caller) — GUARDIAN-gated, immediate protocol-wide brake. Forwards to
|
|
386
|
+
* the controller's `pause`, halting supply/borrow/strategy entrypoints across
|
|
387
|
+
* every market (exits and liquidation stay open). Halting is fail-safe, so the
|
|
388
|
+
* fast incident key acts without the owner online. `caller = opts.caller` must
|
|
389
|
+
* hold GUARDIAN and sign. Distinct from the controller-targeted
|
|
390
|
+
* `buildStellarPauseTx`, which an EOA cannot call because the controller's
|
|
391
|
+
* owner is the governance contract.
|
|
392
|
+
*/ export function buildStellarGovernancePauseTx(opts) {
|
|
393
|
+
return buildGovernanceTx(opts, 'pause', [
|
|
394
|
+
addr(opts.caller)
|
|
395
|
+
]);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* propose(Unpause) — resuming the controller is risk-loosening, so unlike the
|
|
399
|
+
* GUARDIAN-immediate `pause` it rides the timelock as a Standard-delay
|
|
400
|
+
* governance proposal. `proposer = opts.caller` must hold PROPOSER and sign.
|
|
401
|
+
*/ export function buildStellarProposeUnpauseTx(opts, salt) {
|
|
402
|
+
return buildPropose(opts, adminOp('Unpause'), salt);
|
|
403
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed Stellar lending reads and unsigned Soroban transaction builders.
|
|
3
|
+
* Start with {@link stellarLendingRead}, then {@link buildStellarSupplyTx}
|
|
4
|
+
* and {@link prepareStellarBuiltTx}. The host wallet signs prepared XDR.
|
|
5
|
+
* @module Stellar lending
|
|
6
|
+
*/ export { XOXNOClient } from "../../utils/api.js";
|
|
7
|
+
export * from "./contracts.js";
|
|
8
|
+
export * from "./lending.js";
|
|
9
|
+
export * from "./lending-read.js";
|
|
10
|
+
export * from "./read/index.js";
|
|
11
|
+
export * from "./admin.js";
|
|
12
|
+
export * from "./governance.js";
|
|
13
|
+
export * from "./events/index.js";
|
|
14
|
+
export * from "./quote.js";
|
|
15
|
+
export * from "./swap.js";
|
|
16
|
+
export * from "./swap-history.js";
|
|
17
|
+
export * from "./route-verify.js";
|
|
18
|
+
export * from "./auth-policy.js";
|
|
19
|
+
export * from "./prepare.js";
|
|
20
|
+
export * from "./position-mode.js";
|
|
21
|
+
export * from "./repay-swap.js";
|
|
22
|
+
export * from "./cctp.js";
|
|
23
|
+
export * from "./math/index.js";
|
|
24
|
+
// Soroban error mapper; re-export at the stellar subpath so consumers can
|
|
25
|
+
// import from '@xoxno/sdk-js/stellar-lending' when decoding contract errors.
|
|
26
|
+
export { mapSorobanError } from "../../utils/soroban-errors.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/** Public reader aliases. All response fields come from the generated API contract. */ export * from "./lending-api-types.js";
|