@lumenwipe/verify 0.0.0-stage → 0.2.0
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/CHANGELOG.md +67 -0
- package/LICENSE +201 -0
- package/README.md +137 -2
- package/dist/index.cjs +2372 -0
- package/dist/index.d.cts +654 -0
- package/dist/index.d.ts +654 -0
- package/dist/index.js +2367 -0
- package/package.json +79 -4
- package/vectors/close-v1.json +4898 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@lumenwipe/verify`: the verifier the LumenWipe web app runs before every signature, compiled
|
|
3
|
+
* from the web's own modules rather than copied. There is one implementation; this file only
|
|
4
|
+
* gives it explicit, documented types. `tests/types.test.ts` pins every type below to the web
|
|
5
|
+
* signature in both directions, so a change on either side fails the build.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export declare interface AccountSigner {
|
|
11
|
+
key: string;
|
|
12
|
+
weight: number;
|
|
13
|
+
type: "ed25519_public_key" | "hash_x" | "preauth_tx" | "ed25519_signed_payload";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare interface AccountState {
|
|
17
|
+
address: string;
|
|
18
|
+
network: Network_2;
|
|
19
|
+
sequence: string;
|
|
20
|
+
nativeBalanceLumens: string;
|
|
21
|
+
dataEntries: DataEntry[];
|
|
22
|
+
signers: AccountSigner[];
|
|
23
|
+
thresholds: AccountThresholds;
|
|
24
|
+
numSubEntries: number;
|
|
25
|
+
numSponsoring: number;
|
|
26
|
+
/** Reserves another account pays for this one: its own base reserve when its creation was
|
|
27
|
+
* sponsored, and each sponsored subentry. Lowers the minimum balance. Absent when the read
|
|
28
|
+
* did not report it, which is treated as none. */
|
|
29
|
+
numSponsored?: number;
|
|
30
|
+
/** Ledger entries this account currently sponsors (on other accounts, or itself via a
|
|
31
|
+
* fully-sponsored account creation). Populated by replaying sponsorship-relevant
|
|
32
|
+
* operations and re-verifying each candidate's live sponsor - see sponsorship.ts. */
|
|
33
|
+
sponsoredEntries: SponsoredEntry[];
|
|
34
|
+
/** True when sponsoredEntries could not be enumerated completely (pagination cut off,
|
|
35
|
+
* a live re-verification fetch failed, or the enumerated count doesn't match
|
|
36
|
+
* numSponsoring). Mirrors subEntryMismatch: an incomplete read must never be treated
|
|
37
|
+
* as "sponsors nothing" downstream. */
|
|
38
|
+
sponsorshipEnumerationIncomplete: boolean;
|
|
39
|
+
/** Account whose reserve covers this account's base reserve, or null. Populated by the
|
|
40
|
+
* Horizon-based scan path only; the RPC getLedgerEntries response strips the outer
|
|
41
|
+
* LedgerEntry extension where sponsoringID lives, so it remains null on that path. */
|
|
42
|
+
sponsoredBy: string | null;
|
|
43
|
+
/** AUTH_IMMUTABLE flag is set - ACCOUNT_MERGE is permanently blocked. */
|
|
44
|
+
authImmutable: boolean;
|
|
45
|
+
trustlines: Trustline[];
|
|
46
|
+
openOffers: OpenOffer[];
|
|
47
|
+
poolShares: PoolShareEntry[];
|
|
48
|
+
/** Claimable balances where this account is listed as a claimant. Does not affect
|
|
49
|
+
* numSubEntries on this account; populated via the Horizon adapter. */
|
|
50
|
+
claimableBalances: ClaimableBalance[];
|
|
51
|
+
/** True when the account holds more claimable balances than one read returns, so
|
|
52
|
+
* `claimableBalances` is a bounded part of them. Set only by the account reader. While it is
|
|
53
|
+
* set the merge is never built: the rest would be stranded. */
|
|
54
|
+
claimableBalancesMore?: boolean;
|
|
55
|
+
subEntryMismatch: boolean;
|
|
56
|
+
/** Close time of the latest ledger (epoch seconds) when the claim predicates were judged.
|
|
57
|
+
* Absent means it could not be read, and only unconditional claims count as claimable. */
|
|
58
|
+
ledgerCloseTime?: number;
|
|
59
|
+
/** The latest ledger the enumeration's reads reflect, for debugging. Absent when the provider
|
|
60
|
+
* reports none. */
|
|
61
|
+
snapshotLedger?: number;
|
|
62
|
+
/** Detected DeFi positions (Blend, Aquarius, Soroswap, Phoenix, FxDAO), resolved via OctoPos on
|
|
63
|
+
* mainnet or a direct contract read on testnet / mainnet degraded mode - architecture.md §7.1.
|
|
64
|
+
* Never absent: an unconfigured deployment or provider outage still returns a result, stamped
|
|
65
|
+
* with a null `timestamp` and reflected in `defiPositionsWarnings` rather than being omitted. */
|
|
66
|
+
defiPositions: DefiPositionsResult;
|
|
67
|
+
/** Plain-language notices from `assessDefiPositionsGate` (issue #147) - stale/unconfirmed data
|
|
68
|
+
* or an unrecognized position - reusing the exact same typed-blocker signal close/plan already
|
|
69
|
+
* gates on, so the analysis view and the plan never disagree about what's trustworthy. Empty
|
|
70
|
+
* when nothing needs flagging. */
|
|
71
|
+
defiPositionsWarnings: PlanBlocker[];
|
|
72
|
+
/** Soroban token balances held directly, best effort (see `SorobanTokensResult`). Absent on
|
|
73
|
+
* account reads produced before this field existed; a consumer treats absence as "nothing
|
|
74
|
+
* known", never as "nothing held". */
|
|
75
|
+
sorobanTokens?: SorobanTokensResult;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export declare interface AccountThresholds {
|
|
79
|
+
low: number;
|
|
80
|
+
med: number;
|
|
81
|
+
high: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare interface AquariusLpPosition extends DefiPositionBase {
|
|
85
|
+
protocol: "aquarius";
|
|
86
|
+
positionType: "lp";
|
|
87
|
+
shareAmount: string;
|
|
88
|
+
/** Reported by OctoPos alongside the LP position rather than as its own position. */
|
|
89
|
+
claimableAquaAmount?: string;
|
|
90
|
+
/** The pool's tokens in the pool's own order - the order `withdraw` pays them out and
|
|
91
|
+
* `min_amounts` is given in. Read from the pool when detection can. */
|
|
92
|
+
tokens?: string[];
|
|
93
|
+
/** The pool's LP share token: a separate contract in Aquarius, where the account's shares live. */
|
|
94
|
+
shareToken?: string;
|
|
95
|
+
/** Which pool code the pool runs, from the registry. */
|
|
96
|
+
poolType?: AquariusPoolType;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Aquarius deploys three pool codes; only the share-based ones can be exited by shares. */
|
|
100
|
+
declare type AquariusPoolType = "constant_product" | "stable" | "concentrated";
|
|
101
|
+
|
|
102
|
+
declare interface BlendBorrowPosition extends DefiPositionBase {
|
|
103
|
+
protocol: "blend";
|
|
104
|
+
positionType: "borrow";
|
|
105
|
+
assetAddress: string;
|
|
106
|
+
dTokenAmount: string;
|
|
107
|
+
healthFactor?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare interface BlendSupplyPosition extends DefiPositionBase {
|
|
111
|
+
protocol: "blend";
|
|
112
|
+
positionType: "supply";
|
|
113
|
+
assetAddress: string;
|
|
114
|
+
bTokenAmount: string;
|
|
115
|
+
/** True when this supply is also posted as backstop collateral. */
|
|
116
|
+
isBackstop?: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare interface ClaimableBalance {
|
|
120
|
+
/** Full 72-char hex balance ID as returned by Horizon ("00000000" + 64-char hash). */
|
|
121
|
+
id: string;
|
|
122
|
+
/** "CODE:ISSUER" or "native" */
|
|
123
|
+
asset: string;
|
|
124
|
+
amount: string;
|
|
125
|
+
/** One entry per claimant on the balance, each with its own predicate. */
|
|
126
|
+
claimants: {
|
|
127
|
+
destination: string;
|
|
128
|
+
predicate: ClaimPredicate;
|
|
129
|
+
}[];
|
|
130
|
+
/** Account sponsoring this balance's reserve, or null if unsponsored. */
|
|
131
|
+
sponsor: string | null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
declare type ClaimPredicate = {
|
|
135
|
+
type: "unconditional";
|
|
136
|
+
} | {
|
|
137
|
+
type: "and";
|
|
138
|
+
predicates: ClaimPredicate[];
|
|
139
|
+
} | {
|
|
140
|
+
type: "or";
|
|
141
|
+
predicates: ClaimPredicate[];
|
|
142
|
+
} | {
|
|
143
|
+
type: "not";
|
|
144
|
+
predicate: ClaimPredicate;
|
|
145
|
+
} | {
|
|
146
|
+
type: "before_absolute_time";
|
|
147
|
+
absBeforeEpoch: string;
|
|
148
|
+
} | {
|
|
149
|
+
type: "before_relative_time";
|
|
150
|
+
relBeforeSeconds: string;
|
|
151
|
+
deadlineEpoch: string;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/** A classic conversion the user chose. */
|
|
155
|
+
export declare interface ClassicConversionChoice {
|
|
156
|
+
/** The least XLM, in stroops, the plan showed it delivering, or null for an asset only a DeFi
|
|
157
|
+
* exit pays in (no amount to quote; only the choice and a positive minimum are held). */
|
|
158
|
+
minAmountOut: string | null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* What the integrator independently knows a close transaction should do. Three sources, never
|
|
163
|
+
* the transaction under verification:
|
|
164
|
+
*
|
|
165
|
+
* - the user's own inputs: `destination`, `memo`, `memoType` and every per-asset choice;
|
|
166
|
+
* - the account read the user reviewed (`client.getAccount` or the plan's `sourceAccount`):
|
|
167
|
+
* `source`, `nativeBalance`, `accountSigners`, `accountThresholds`, and the exit half;
|
|
168
|
+
* - this package's bundled registries, through {@link exitExpectations}.
|
|
169
|
+
*
|
|
170
|
+
* The memo policy for a listed exchange (whether a memo is required, its type, whether the merge
|
|
171
|
+
* must go through the shared intermediary) is not an input: the verifier derives it from the
|
|
172
|
+
* exchange registry bundled in this package, tightened by a served snapshot when one is passed
|
|
173
|
+
* ({@link VerifyCloseInput.servedRegistry}).
|
|
174
|
+
*/
|
|
175
|
+
export declare interface CloseExpectationInput extends ExitExpectations {
|
|
176
|
+
/** The account being closed. */
|
|
177
|
+
source: string;
|
|
178
|
+
/** The final destination the user typed. */
|
|
179
|
+
destination: string;
|
|
180
|
+
/** The account's native balance in XLM as last read (`"100.0000000"`). The floor under the
|
|
181
|
+
* intermediary's forward on an exchange close. `"0"` when unknown fails closed. */
|
|
182
|
+
nativeBalance: string;
|
|
183
|
+
/** The memo the user confirmed, or null. */
|
|
184
|
+
memo: string | null;
|
|
185
|
+
/** The type the user confirmed for `memo`, or null with no memo. The bundled registry's type
|
|
186
|
+
* replaces it for an exchange the bundle lists; a served registry's type that differs from it
|
|
187
|
+
* is refused (`registry_memo_type_unconfirmed`), never adopted. */
|
|
188
|
+
memoType: "text" | "id" | "hash" | null;
|
|
189
|
+
/** Canonical `CODE:ISSUER` of each trustline a claimable balance claim may add and remove. */
|
|
190
|
+
claimTrustlineAssets: string[];
|
|
191
|
+
/** The account's signers from the read. A transaction may never add one. Empty fails closed. */
|
|
192
|
+
accountSigners: AccountSigner[];
|
|
193
|
+
/** The account's thresholds from the read. A transaction may never raise one. */
|
|
194
|
+
accountThresholds: AccountThresholds;
|
|
195
|
+
/** The per-asset transfers the user chose, keyed by canonical `CODE:ISSUER`. Required: pass
|
|
196
|
+
* `{}` to allow none. */
|
|
197
|
+
transfers: Record<string, TransferChoice>;
|
|
198
|
+
/** The Soroban token transfers the user chose, keyed by token contract, amounts in base units. */
|
|
199
|
+
tokenTransfers: Record<string, TransferChoice>;
|
|
200
|
+
/** The classic conversions the user chose, keyed by `CODE:ISSUER`. Only these may be sold. */
|
|
201
|
+
classicConversions: Record<string, ClassicConversionChoice>;
|
|
202
|
+
/** The Soroban token conversions the user chose, keyed by token contract. */
|
|
203
|
+
tokenConversions: Record<string, TokenConversionChoice>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
declare interface DataEntry {
|
|
207
|
+
key: string;
|
|
208
|
+
value: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Keyed by asset/contract address. Built from OctoPos's queryKeys.tokenInfos. */
|
|
212
|
+
declare interface DefiEnrichmentEntry {
|
|
213
|
+
symbol: string;
|
|
214
|
+
decimals: number;
|
|
215
|
+
usdPrice: string | null;
|
|
216
|
+
priceSource: string | null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare type DefiPosition = BlendSupplyPosition | BlendBorrowPosition | AquariusLpPosition | SoroswapLpPosition | PhoenixLpPosition | PhoenixStakePosition | FxdaoCdpPosition;
|
|
220
|
+
|
|
221
|
+
declare interface DefiPositionBase {
|
|
222
|
+
protocol: DefiProtocol;
|
|
223
|
+
/** Pool, market, or vault contract this position lives in. */
|
|
224
|
+
contractAddress: string;
|
|
225
|
+
/** Human-readable view of the position, when the analysis could resolve one. */
|
|
226
|
+
display?: DefiPositionDisplay;
|
|
227
|
+
/** Left as an optional hook: the wasmHash -\> protocol-version contract registry
|
|
228
|
+
* architecture.md describes does not exist in code yet (a later contribution). */
|
|
229
|
+
wasmHash?: string;
|
|
230
|
+
usdValue: string | null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* What a person should read about a position, in the protocol's own terms, resolved by the API
|
|
235
|
+
* from a live read at analysis time (issue #197). Presentation only: every field is nullable, a
|
|
236
|
+
* failed read leaves the whole object absent, and nothing here feeds the plan, the gate, or an
|
|
237
|
+
* exit - those re-read the ledger themselves.
|
|
238
|
+
*/
|
|
239
|
+
declare interface DefiPositionDisplay {
|
|
240
|
+
/** The pool, pair, or vault by name (the protocol's own metadata or the registry label). */
|
|
241
|
+
pool: string | null;
|
|
242
|
+
/** Symbol of the position's asset; for an LP position the pair, e.g. "XLM/USDC". */
|
|
243
|
+
asset: string | null;
|
|
244
|
+
/** Underlying amount in the asset's own units as a decimal string - not shares or bTokens. */
|
|
245
|
+
amount: string | null;
|
|
246
|
+
/** The part of `amount` posted as collateral (lending protocols), decimal string; null when
|
|
247
|
+
* the protocol has no such distinction. */
|
|
248
|
+
collateralAmount: string | null;
|
|
249
|
+
/** Current yield as a percentage with two decimals ("3.99"): earned on a supply, paid on debt. */
|
|
250
|
+
yieldPct: string | null;
|
|
251
|
+
yieldKind: "earned" | "paid" | null;
|
|
252
|
+
/** One protocol-specific clause the line ends with, e.g. what an LP share is worth in its two
|
|
253
|
+
* tokens ("9.95 XLM + 19.90 USDC"). Null when there is nothing to add. */
|
|
254
|
+
detail?: string | null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* The normalized DeFi position model every downstream consumer (exit adapters, plan preview)
|
|
259
|
+
* depends on - no OctoPos-specific field names beyond this boundary (architecture.md §7.1).
|
|
260
|
+
*/
|
|
261
|
+
declare interface DefiPositionsResult {
|
|
262
|
+
address: string;
|
|
263
|
+
network: Network_2;
|
|
264
|
+
positions: DefiPosition[];
|
|
265
|
+
unrecognizedPositions: UnrecognizedDefiPosition[];
|
|
266
|
+
enrichment: Record<string, DefiEnrichmentEntry>;
|
|
267
|
+
/** OctoPos's own freshness/provenance signal ("snapshot" | "empty" | "cache" | "not-tracked").
|
|
268
|
+
* Passed through verbatim rather than architecture.md's described (but not actually shipped)
|
|
269
|
+
* partial_result/attribution_confidence fields - see issue #147 for the gating that consumes
|
|
270
|
+
* this. */
|
|
271
|
+
source: string;
|
|
272
|
+
timestamp: string | null;
|
|
273
|
+
queryKeys: DefiQueryKeys;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Protocols LumenWipe knows how to act on: most are DeFi positions it knows how to exit
|
|
278
|
+
* (architecture.md §9's table); `xbull` is the one exception, a swap router with no position to
|
|
279
|
+
* exit, registered here only so it can share the contract registry's protocol-keyed lookups.
|
|
280
|
+
* OctoPos itself indexes more than this (e.g. "untangled-vault", "stellar-wallet") - those are
|
|
281
|
+
* dropped by the adapter rather than represented here, since the type system should not claim
|
|
282
|
+
* LumenWipe can act on a protocol it has no exit path for.
|
|
283
|
+
*/
|
|
284
|
+
declare type DefiProtocol = "blend" | "aquarius" | "soroswap" | "phoenix" | "fxdao" | "xbull";
|
|
285
|
+
|
|
286
|
+
declare interface DefiQueryKeys {
|
|
287
|
+
rpcEndpoints: DefiRpcEndpoint[];
|
|
288
|
+
rpcPolicy: DefiRpcPolicy;
|
|
289
|
+
slices: Partial<Record<DefiProtocol, DefiQueryKeysSlice>>;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Ready-made ledger keys plus pool/vault metadata for one protocol, letting a caller read
|
|
294
|
+
* positions directly over RPC without OctoPos storing anything server-side (architecture.md
|
|
295
|
+
* §7.1). Passed through typed rather than discarded, since issue #148's RPC fallback needs
|
|
296
|
+
* exactly this and would otherwise have to refetch it.
|
|
297
|
+
*/
|
|
298
|
+
declare interface DefiQueryKeysSlice {
|
|
299
|
+
protocol: string;
|
|
300
|
+
ledgerKeys: string[];
|
|
301
|
+
poolAddresses: string[];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** A public Soroban RPC endpoint OctoPos suggests for a direct getLedgerEntries read. */
|
|
305
|
+
declare interface DefiRpcEndpoint {
|
|
306
|
+
url: string;
|
|
307
|
+
health: string;
|
|
308
|
+
avgLatencyMs: number;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
declare interface DefiRpcPolicy {
|
|
312
|
+
maxKeysPerCall: number;
|
|
313
|
+
recommendedConcurrency: number;
|
|
314
|
+
backoffOn429Ms: number[];
|
|
315
|
+
timeoutMs: number;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** One exchange in the registry: whether a close into it needs the mediator, and its memo rule. */
|
|
319
|
+
export declare interface ExchangeRegistryEntry {
|
|
320
|
+
address: string;
|
|
321
|
+
name: string;
|
|
322
|
+
domain: string;
|
|
323
|
+
requiresMediator: boolean;
|
|
324
|
+
requiresMemo: boolean;
|
|
325
|
+
/** The required memo type, if `requiresMemo` is true. */
|
|
326
|
+
memoType: "text" | "id" | "hash";
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* The DeFi half of the expectation. Build it with {@link exitExpectations} from the account read
|
|
331
|
+
* the user reviewed, never by hand from a plan: it combines that read with the registries bundled
|
|
332
|
+
* in this package. Empty lists fail closed (every exit is refused).
|
|
333
|
+
*/
|
|
334
|
+
export declare interface ExitExpectations {
|
|
335
|
+
/** Pools, pairs or vaults the account holds a position in, plus the bundled registry's routers,
|
|
336
|
+
* backstops and stakes for those protocols. An exit may invoke only one of these. */
|
|
337
|
+
exitContracts: string[];
|
|
338
|
+
/** The Stellar Asset Contract of every asset the account holds (XLM and each trustline) and
|
|
339
|
+
* the Soroban tokens the read confirmed with a positive balance. */
|
|
340
|
+
heldTokenContracts: string[];
|
|
341
|
+
/** Each position's tokens, share token and debt token: what a withdrawal pays out or spends. */
|
|
342
|
+
positionTokenContracts: string[];
|
|
343
|
+
/** Per exit contract, the functions that leave that protocol. */
|
|
344
|
+
exitFunctions: Record<string, string[]>;
|
|
345
|
+
/** The bundled registry's Soroswap aggregator and router and xBull's router: the only contracts
|
|
346
|
+
* a token conversion may be entered through. */
|
|
347
|
+
conversionContracts: string[];
|
|
348
|
+
/** XLM's contract on this network: the one asset a token conversion may buy. */
|
|
349
|
+
xlmContract: string;
|
|
350
|
+
/** Every contract the bundled contract registry names on this network. */
|
|
351
|
+
registryContracts: string[];
|
|
352
|
+
/** XLM's contract and the contract of every classic asset the account holds. Only a registry
|
|
353
|
+
* contract may receive or spend these in an exit. */
|
|
354
|
+
protectedTokenContracts: string[];
|
|
355
|
+
/** xBull's router asset table, index to token contract; empty off mainnet. */
|
|
356
|
+
xbullAssets: Record<string, string>;
|
|
357
|
+
/** Per position contract, the tokens the account read names as that position's own. */
|
|
358
|
+
ownTokensByContract: Record<string, string[]>;
|
|
359
|
+
/** Per Blend pool, the tokens of the account's `borrow` positions in that pool. */
|
|
360
|
+
repayTokensByPool: Record<string, string[]>;
|
|
361
|
+
/** Every position's share token (Aquarius, Phoenix). */
|
|
362
|
+
shareTokenContracts: string[];
|
|
363
|
+
/** Every position's debt token (FxDAO). */
|
|
364
|
+
debtTokenContracts: string[];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* The DeFi half of a close expectation, derived from the account read the user reviewed and the
|
|
369
|
+
* contract registry bundled in this package. With no read, every list is empty and every exit is
|
|
370
|
+
* refused.
|
|
371
|
+
*/
|
|
372
|
+
export declare function exitExpectations(accountState: AccountState | null | undefined, network: Network): ExitExpectations;
|
|
373
|
+
|
|
374
|
+
declare interface FxdaoCdpPosition extends DefiPositionBase {
|
|
375
|
+
protocol: "fxdao";
|
|
376
|
+
positionType: "cdp";
|
|
377
|
+
denomination: string;
|
|
378
|
+
collateralAmount: string;
|
|
379
|
+
debtAmount: string;
|
|
380
|
+
/** The denomination's registered stablecoin (`Currency(denomination).contract`), the token a
|
|
381
|
+
* repay burns. Read from the vault. */
|
|
382
|
+
debtToken?: string;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** The Stellar network a transaction is verified for. Selects the network passphrase the XDR is
|
|
386
|
+
* decoded with and the bundled registry entries that apply. */
|
|
387
|
+
export declare type Network = "mainnet" | "testnet";
|
|
388
|
+
|
|
389
|
+
declare type Network_2 = "mainnet" | "testnet";
|
|
390
|
+
|
|
391
|
+
declare interface OpenOffer {
|
|
392
|
+
id: string;
|
|
393
|
+
selling: string;
|
|
394
|
+
buying: string;
|
|
395
|
+
amount: string;
|
|
396
|
+
price: string;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
declare interface PhoenixLpPosition extends DefiPositionBase {
|
|
400
|
+
protocol: "phoenix";
|
|
401
|
+
positionType: "lp";
|
|
402
|
+
shareAmount: string;
|
|
403
|
+
/** The pool's LP share token (`CONFIG.share_token`): a separate contract in Phoenix, where the
|
|
404
|
+
* account's shares live and what a withdrawal transfers back to the pool. Read from the pool. */
|
|
405
|
+
shareToken?: string;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
declare interface PhoenixStakePosition extends DefiPositionBase {
|
|
409
|
+
protocol: "phoenix";
|
|
410
|
+
positionType: "stake";
|
|
411
|
+
stakedAmount: string;
|
|
412
|
+
/** Unix seconds; unbonding requires the original stake's timestamp (architecture.md §9.6). */
|
|
413
|
+
stakedAtEpoch: string;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
declare interface PlanBlocker {
|
|
417
|
+
message: string;
|
|
418
|
+
helpUrl?: string;
|
|
419
|
+
/** Distinguishes an acknowledged, non-trapping warning (e.g. a chosen forfeit) from a hard
|
|
420
|
+
* blocker. Absent means the generic hard-blocking case. */
|
|
421
|
+
code?: string;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
declare interface PoolShareEntry {
|
|
425
|
+
poolId: string;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Whether a close to `address` goes through the shared intermediary: true only for an exchange
|
|
430
|
+
* the registry bundled in this package lists as unable to receive an account merge. The same
|
|
431
|
+
* rule `verifyCloseTransaction` applies, so an integrator decides from it, never from the API's
|
|
432
|
+
* response, whether a transaction needs the intermediary's co-signature. A served snapshot never
|
|
433
|
+
* changes this answer, so it takes none.
|
|
434
|
+
*/
|
|
435
|
+
export declare function requiresMediator(address: string): boolean;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* A served exchange registry: the body of `GET /v1/config/exchange-registry` (the SDK's
|
|
439
|
+
* `client.getExchangeRegistry()`), passed as is. Only these three fields are read.
|
|
440
|
+
*
|
|
441
|
+
* It is not authenticated, and it does not need to be for what it can do: it is merged over the
|
|
442
|
+
* registry bundled in this package and can only make verification stricter.
|
|
443
|
+
*
|
|
444
|
+
* - A bundled exchange is never removed, and its memo requirement and its refusal of a direct
|
|
445
|
+
* merge are never turned off.
|
|
446
|
+
* - An address it adds is checked as an exchange: a direct merge into it is refused when it
|
|
447
|
+
* needs the intermediary, a memo is required when it needs one, and a transfer to it is refused.
|
|
448
|
+
* - It never enables the mediated hand-off. That stays limited to the exchanges the bundled
|
|
449
|
+
* registry lists ({@link requiresMediator}), so an address only the snapshot lists as needing
|
|
450
|
+
* the intermediary refuses both shapes until this package is updated.
|
|
451
|
+
* - Its `validUntil` may move the bundled expiry later, by at most 120 days, never earlier.
|
|
452
|
+
* - It never decides a memo type. A different type for a bundled exchange is refused with
|
|
453
|
+
* `registry_memo_type_conflict`, and a type for an address it adds that differs from the one
|
|
454
|
+
* the user confirmed is refused with `registry_memo_type_unconfirmed`. A memo sent under the
|
|
455
|
+
* wrong type reaches the exchange and is credited to nobody.
|
|
456
|
+
*
|
|
457
|
+
* An entry's `name` is taken from it, and only used in refusal messages.
|
|
458
|
+
*/
|
|
459
|
+
export declare interface ServedRegistry {
|
|
460
|
+
/** The listed exchanges. An entry that is not well formed is dropped. */
|
|
461
|
+
entries: ExchangeRegistryEntry[];
|
|
462
|
+
/** When the entries were last checked (YYYY-MM-DD). Not used to decide anything. */
|
|
463
|
+
lastVerified: string;
|
|
464
|
+
/** The date (YYYY-MM-DD) after which the registry is not relied on. */
|
|
465
|
+
validUntil: string;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** A SEP-41 token balance the account holds in a contract's storage - not a classic trustline. */
|
|
469
|
+
declare interface SorobanTokenBalance {
|
|
470
|
+
/** The token contract, `C...`. */
|
|
471
|
+
contract: string;
|
|
472
|
+
/** Base units, integer string, as `balance(account)` reports it on the ledger. "0" only for a
|
|
473
|
+
* token the account does not hold yet but a detected position's exit will pay out. */
|
|
474
|
+
balance: string;
|
|
475
|
+
/** From the contract's own `symbol()` / `decimals()`, null when it does not answer them. */
|
|
476
|
+
symbol: string | null;
|
|
477
|
+
decimals: number | null;
|
|
478
|
+
/** Every source that proposed this contract; the balance itself always comes from the ledger. */
|
|
479
|
+
sources: SorobanTokenSource[];
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** How one candidate source fared, so the interface can say exactly what was consulted. */
|
|
483
|
+
declare interface SorobanTokenCoverage {
|
|
484
|
+
source: SorobanTokenSource;
|
|
485
|
+
status: "ok" | "failed" | "skipped";
|
|
486
|
+
detail?: string;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Where a Soroban token candidate came from before its balance was confirmed on the ledger. */
|
|
490
|
+
declare type SorobanTokenSource = "explorer" | "positions" | "list" | "events" | "manual";
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Soroban token balances the account holds directly. Soroban has no per-account token index, so
|
|
494
|
+
* this is a best-effort union of candidate sources - an explorer, the tokens named by detected
|
|
495
|
+
* positions, bundled lists, recent on-chain `transfer`/`mint` events, and contracts the user added
|
|
496
|
+
* by hand - each confirmed by reading `balance(account)` on the ledger. What could not be read is
|
|
497
|
+
* listed, never dropped; classic assets' contracts are excluded (their balance is the trustline).
|
|
498
|
+
*/
|
|
499
|
+
declare interface SorobanTokensResult {
|
|
500
|
+
tokens: SorobanTokenBalance[];
|
|
501
|
+
/** Candidate contracts whose balance could not be read (a hostile, broken, or archived token). */
|
|
502
|
+
unreadable: string[];
|
|
503
|
+
coverage: SorobanTokenCoverage[];
|
|
504
|
+
/** The ledger range the event scan covered, or null when it ran out of budget before starting. */
|
|
505
|
+
eventsScanned: {
|
|
506
|
+
fromLedger: number;
|
|
507
|
+
toLedger: number;
|
|
508
|
+
} | null;
|
|
509
|
+
/** Plain-language warnings for the plan: a source that failed, contracts that could not be read. */
|
|
510
|
+
warnings: PlanBlocker[];
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
declare interface SoroswapLpPosition extends DefiPositionBase {
|
|
514
|
+
protocol: "soroswap";
|
|
515
|
+
positionType: "lp";
|
|
516
|
+
shareAmount: string;
|
|
517
|
+
/** The pair's two token contracts (token_0, token_1), read from the pair when detection can;
|
|
518
|
+
* what a withdrawal receives and the exit's arguments name. */
|
|
519
|
+
tokens?: [string, string];
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* A ledger entry this account currently sponsors, on another account (or itself, for
|
|
524
|
+
* "account" - a fully-sponsored account creation). Mirrors the ledger-key kinds
|
|
525
|
+
* RevokeSponsorship supports. Claimable balances have no owning-account concept in
|
|
526
|
+
* their ledger key (unlike the other five kinds), so they carry only balanceId.
|
|
527
|
+
*/
|
|
528
|
+
declare type SponsoredEntry = {
|
|
529
|
+
kind: "account";
|
|
530
|
+
owner: string;
|
|
531
|
+
} | {
|
|
532
|
+
kind: "trustline";
|
|
533
|
+
owner: string;
|
|
534
|
+
asset: string;
|
|
535
|
+
} | {
|
|
536
|
+
kind: "offer";
|
|
537
|
+
owner: string;
|
|
538
|
+
offerId: string;
|
|
539
|
+
} | {
|
|
540
|
+
kind: "data_entry";
|
|
541
|
+
owner: string;
|
|
542
|
+
name: string;
|
|
543
|
+
} | {
|
|
544
|
+
kind: "signer";
|
|
545
|
+
owner: string;
|
|
546
|
+
signerKey: string;
|
|
547
|
+
} | {
|
|
548
|
+
kind: "claimable_balance";
|
|
549
|
+
balanceId: string;
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
/** A Soroban token conversion the user chose, with the quote they accepted. */
|
|
553
|
+
export declare interface TokenConversionChoice {
|
|
554
|
+
/** The least XLM, in stroops, the plan quoted and the user accepted. The built swap's own
|
|
555
|
+
* minimum must be at least this. */
|
|
556
|
+
minAmountOut: string;
|
|
557
|
+
/** The quoted XLM out, in stroops, when the plan reported one. */
|
|
558
|
+
amountOut?: string;
|
|
559
|
+
/** The token balance sold, in base units. */
|
|
560
|
+
amountIn: string;
|
|
561
|
+
/** An xBull route as the API resolved it at plan time. Not relied on: the verifier reads xBull
|
|
562
|
+
* routes through the bundled asset table. */
|
|
563
|
+
resolvedPath?: string[];
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** A per-asset transfer the user chose: the account the balance goes to and the floor it is
|
|
567
|
+
* held to. */
|
|
568
|
+
export declare interface TransferChoice {
|
|
569
|
+
/** The account the user typed for this asset. */
|
|
570
|
+
destination: string;
|
|
571
|
+
/** The balance the account read showed, in the asset's display units for a classic asset
|
|
572
|
+
* (`"12.5000000"`) or base units for a Soroban token. A floor, not an exact figure. */
|
|
573
|
+
amount: string;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
declare interface Trustline {
|
|
577
|
+
asset: string;
|
|
578
|
+
balance: string;
|
|
579
|
+
limit?: string;
|
|
580
|
+
/** True only when `authorization` is `authorized`. */
|
|
581
|
+
authorized: boolean;
|
|
582
|
+
authorization: TrustlineAuthorization;
|
|
583
|
+
/** The issuer can reclaim this balance at any time. */
|
|
584
|
+
clawbackEnabled: boolean;
|
|
585
|
+
issuer: string;
|
|
586
|
+
code: string;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** The issuer's authorization of a trustline. Only `authorized` can send or receive payments;
|
|
590
|
+
* `maintain_liabilities` keeps existing offers alive and nothing else. */
|
|
591
|
+
declare type TrustlineAuthorization = "authorized" | "maintain_liabilities" | "unauthorized";
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* A position tagged with a supported protocol whose shape the adapter could not validate. Kept
|
|
595
|
+
* distinct from "no position" so a caller (issue #147's gating) can surface it rather than treat
|
|
596
|
+
* a parse failure as an account with nothing to unwind - the "no silent skips" invariant applied
|
|
597
|
+
* to a provider field OctoPos does not formally type.
|
|
598
|
+
*/
|
|
599
|
+
declare interface UnrecognizedDefiPosition {
|
|
600
|
+
protocol: DefiProtocol;
|
|
601
|
+
/** OctoPos's raw type tag (e.g. "SUPPLY"), kept for diagnostics even though it didn't parse. */
|
|
602
|
+
rawType: string;
|
|
603
|
+
reason: string;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Every reason the verifier refuses a transaction, one stable code each. The code is the contract
|
|
608
|
+
* an integrator branches on; the message is the current English wording and may change. A check
|
|
609
|
+
* that applies to several operation kinds (the fee cap, the operation source) shares one code,
|
|
610
|
+
* since the kind is visible in the transaction itself.
|
|
611
|
+
*/
|
|
612
|
+
declare const VERIFICATION_ERROR_CODES: readonly ["registry_expired", "registry_snapshot_invalid", "registry_memo_type_conflict", "registry_memo_type_unconfirmed", "transaction_source_mismatch", "expiry_missing", "expiry_too_far", "fee_unreadable", "fee_above_cap", "operation_unknown", "operation_source_mismatch", "merge_multiple", "merge_direct_refused", "merge_destination_mismatch", "mediator_handoff_shape", "mediator_forward_source_mismatch", "mediator_forward_destination_mismatch", "mediator_forward_not_native", "mediator_forward_short", "transfer_not_chosen", "transfer_destination_mismatch", "transfer_to_deposit_address", "transfer_duplicate", "transfer_amount_short", "token_transfer_function_invalid", "token_transfer_from_mismatch", "token_transfer_foreign_contract", "conversion_recipient_mismatch", "conversion_not_to_xlm", "conversion_min_out_missing", "conversion_asset_not_chosen", "conversion_duplicate", "conversion_min_out_below_floor", "conversion_amount_short", "swap_quote_missing", "swap_args_unreadable", "swap_referral_recipient", "swap_route_asset_unknown", "swap_auth_unexpected_call", "swap_auth_exceeds_amount", "trustline_not_removal", "data_entry_not_removal", "offer_not_cancellation", "signer_added", "signer_unknown", "master_weight_changed", "thresholds_raised", "account_settings_changed", "invocation_not_alone", "invocation_auth_beyond_self", "invocation_address_unsupported", "invocation_foreign_account", "exit_contract_not_position", "exit_expectation_inconsistent", "exit_function_not_allowed", "exit_foreign_contract", "exit_argument_party_mismatch", "exit_request_not_allowed", "exit_unverified_spend", "exit_spend_not_repay", "exit_liquidity_auth_invalid", "exit_auth_foreign_contract", "exit_token_function_not_allowed", "exit_token_argument_count", "exit_token_recipient_mismatch", "memo_unexpected", "memo_type_unreadable", "memo_missing", "memo_value_mismatch", "memo_type_mismatch", "memo_required", "memo_invalid_text"];
|
|
613
|
+
|
|
614
|
+
/** Thrown when a server-built close transaction fails verification. Never sign past this. */
|
|
615
|
+
export declare class VerificationError extends Error {
|
|
616
|
+
/** Why the transaction was refused. Stable across releases, unlike the message. */
|
|
617
|
+
readonly code: VerificationErrorCode;
|
|
618
|
+
constructor(code: VerificationErrorCode, message: string);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** The reason a {@link VerificationError} was thrown. */
|
|
622
|
+
export declare type VerificationErrorCode = (typeof VERIFICATION_ERROR_CODES)[number];
|
|
623
|
+
|
|
624
|
+
/** The input to {@link verifyCloseTransaction}. */
|
|
625
|
+
export declare interface VerifyCloseInput {
|
|
626
|
+
/** The unsigned transaction envelope as returned by the API (`CloseTransaction.xdr`), base64. */
|
|
627
|
+
unsignedXdr: string;
|
|
628
|
+
/** The network the close runs on. */
|
|
629
|
+
network: Network;
|
|
630
|
+
/** True only for a pre-authorized transaction the account's own signers set up earlier. */
|
|
631
|
+
preAuthorized?: boolean;
|
|
632
|
+
/** What the transaction must do, from the user's inputs and the reviewed account read. */
|
|
633
|
+
expected: CloseExpectationInput;
|
|
634
|
+
/** A served exchange registry to apply over the bundled one, stricter-only. Omit it to use the
|
|
635
|
+
* bundled registry alone. A value that is not a registry (no `entries` list, no
|
|
636
|
+
* `lastVerified` or `validUntil` string) is refused with `registry_snapshot_invalid` rather
|
|
637
|
+
* than ignored. */
|
|
638
|
+
servedRegistry?: ServedRegistry;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Decodes an API-built, unsigned close transaction and asserts it does exactly what `expected`
|
|
643
|
+
* says, using the exchange and contract registries bundled in this package. Returns only when the
|
|
644
|
+
* transaction may be signed; throws {@link VerificationError} on any mismatch.
|
|
645
|
+
*
|
|
646
|
+
* Synchronous and offline: it reads no network and no page state, and keeps no state between
|
|
647
|
+
* calls. It reads the system clock twice: for the transaction's expiry (at most 900 seconds
|
|
648
|
+
* ahead) and for the exchange registry's `validUntil`, past which an exchange close is refused
|
|
649
|
+
* until this package is updated or a served snapshot extends it.
|
|
650
|
+
* Run it once per transaction, immediately before each signature.
|
|
651
|
+
*/
|
|
652
|
+
export declare function verifyCloseTransaction(input: VerifyCloseInput): void;
|
|
653
|
+
|
|
654
|
+
export { }
|