@aegis-engine/core 0.4.0 → 0.5.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/README.md CHANGED
@@ -31,8 +31,9 @@ the published Core package; consumers do not need GitHub Packages credentials.
31
31
  bounded session caches, and explicit indexed freshness.
32
32
  - Engine 12-hour market-metric history for optional rate, utilization, and
33
33
  liquidity charts.
34
- - Engine lend and borrow quotes, exact rounded LP-shaped debt/carry
35
- projections, collateral sizing, Permit2 preparation, and guarded execution.
34
+ - Engine lend, borrow, and directional Long/Short quotes; exact rounded
35
+ LP-shaped debt/carry projections; collateral sizing; Permit2 preparation;
36
+ and guarded execution.
36
37
 
37
38
  Direct pool swaps support `exactIn` and `exactOut`. KyberSwap routes currently
38
39
  support `exactIn` only because Kyber's route/build flow is exact-input.
@@ -46,8 +47,10 @@ Engine discovery and wallet positions default to partner-safe REST:
46
47
 
47
48
  ```ts
48
49
  import {
50
+ deriveEngineTradePositionStrategy,
49
51
  fetchEngineMarketHistory,
50
52
  fetchEngineMarkets,
53
+ fetchEnginePositionActivitySnapshot,
51
54
  fetchEnginePositionsSnapshot
52
55
  } from '@aegis-engine/core'
53
56
 
@@ -63,6 +66,16 @@ const positions = await fetchEnginePositionsSnapshot({
63
66
  chainId: 1,
64
67
  account
65
68
  })
69
+ const activity = await fetchEnginePositionActivitySnapshot({
70
+ source,
71
+ chainId: 1,
72
+ account
73
+ })
74
+ const position = positions.positions[0]
75
+ const vault = activity?.vaults.find((entry) => entry.vaultId === position?.vaultId)
76
+ const strategy = position && vault
77
+ ? deriveEngineTradePositionStrategy(position, vault)
78
+ : null
66
79
  const marketHistory = await fetchEngineMarketHistory({
67
80
  source,
68
81
  marketId: markets[0].id,
@@ -71,7 +84,10 @@ const marketHistory = await fetchEngineMarketHistory({
71
84
  ```
72
85
 
73
86
  Hosts that already own deterministic market/position metadata can instead use
74
- the typed `static` source. Engine market history remains a REST capability.
87
+ the typed `static` source. Supply `vaultActivity` when an offline fixture must
88
+ reconstruct Long/Short identity; position rows alone are ordinary borrow-vault
89
+ facts and are not enough to classify a trade. Engine market history remains a
90
+ REST capability.
75
91
 
76
92
  The REST service supplies facts and provenance. Core owns live RPC reads,
77
93
  collateral/debt math, quote freshness, recipe construction, simulation,
@@ -106,6 +122,76 @@ remaining collateral stays in the vault until a separate withdrawal. A
106
122
  one-token lend is a zap into a two-sided full-range LP, not single-token
107
123
  lending.
108
124
 
125
+ ### Directional Engine positions
126
+
127
+ `quoteEngineTradeOpen` sizes a fresh-vault Long or Short against one
128
+ block-pinned Engine and Uniswap v4 frame. It returns the selected average and
129
+ live leverage, exact opening LTV after the swap minimum, interest carry, risk
130
+ thresholds, gross return at the configured target, actionable solver limits,
131
+ and atomic router calldata when all execution gates pass.
132
+
133
+ Successful and leverage-bound quotes expose `limits.minLeverage` and
134
+ `limits.maxLeverage`. Treat these as live, request-specific bounds rather than
135
+ a protocol-wide constant.
136
+
137
+ `deriveEngineTradePositionStrategy` recognizes the indexed Tap opening action
138
+ shape and recovers its Long/Short direction and executed entry price after a
139
+ reload. The selected target and average-to-target leverage are not transaction
140
+ fields. A host can pass persisted intent records to augment those fields only
141
+ when chain, account, market, pool, transaction, and direction all match.
142
+ A no-swap opening has no indexed direction signal, so this helper deliberately
143
+ leaves it unclassified instead of trusting off-chain intent alone.
144
+
145
+ ```ts
146
+ import { quoteEngineTradeOpen } from '@aegis-engine/core'
147
+
148
+ const quote = await quoteEngineTradeOpen({
149
+ publicClient,
150
+ market,
151
+ owner: account,
152
+ direction: 'long',
153
+ collateralIn: 1_000_000n,
154
+ inputIsToken0: false,
155
+ leverage: 1.5,
156
+ horizonSeconds: 30 * 24 * 60 * 60,
157
+ priceMove: 0.2,
158
+ slippageBps: 100
159
+ })
160
+ ```
161
+
162
+ Treat `feasible` and `executable` separately. A feasible quote can still need
163
+ the trusted router's vault-operator grant or Permit2 authorization. After an
164
+ authorization transaction, request the submit quote with
165
+ `forceExecutionEvidenceRefresh: true`; then pass its fresh `tx` and `expiresAt`
166
+ to `sendEngineTransaction`. The prebuilt `AegisLeverageWidget` performs this
167
+ sequence for frontend integrations.
168
+
169
+ Use `readEngineAuthorizationPlan` to present the connected account's current
170
+ wallet sequence before submission:
171
+
172
+ ```ts
173
+ import { readEngineAuthorizationPlan } from '@aegis-engine/core'
174
+
175
+ const plan = await readEngineAuthorizationPlan({
176
+ publicClient,
177
+ market,
178
+ owner: account,
179
+ walletChainId,
180
+ token: market.token0,
181
+ amount: 1_000_000n,
182
+ approvalMode: 'exact'
183
+ })
184
+ ```
185
+
186
+ `missingPermissionCount` excludes the final open and any zero-first reset.
187
+ `walletPromptCount` includes every required sequential transaction.
188
+ `walletChainSwitchRequired` reports the network switch separately and is null
189
+ until the wallet chain is known. The plan is a read-only presentation snapshot, not authorization
190
+ evidence. Submission must still re-read permissions and obtain a fresh
191
+ executable quote. Exact ERC-20 and Permit2 limits are consumed by the successful
192
+ opening transfer; maximum limits and the VaultRegistry operator grant remain
193
+ active until revoked.
194
+
109
195
  ## Historical token prices
110
196
 
111
197
  Historical prices are intentionally separate from Engine market and
@@ -113,10 +199,7 @@ transaction truth. A host reads one exact token through the public REST
113
199
  backend without placing private data-service credentials in the client:
114
200
 
115
201
  ```ts
116
- import {
117
- AEGIS_BACKEND_PROD_BASE_URL,
118
- fetchTokenPriceHistory
119
- } from '@aegis-engine/core'
202
+ import { AEGIS_BACKEND_PROD_BASE_URL, fetchTokenPriceHistory } from '@aegis-engine/core'
120
203
 
121
204
  const history = await fetchTokenPriceHistory({
122
205
  baseUrl: AEGIS_BACKEND_PROD_BASE_URL,
@@ -189,10 +272,7 @@ const wallet = await resolveWalletSession({
189
272
  Create a read-side viem client from an Aegis chain config:
190
273
 
191
274
  ```ts
192
- import {
193
- AEGIS_SWAP_MAINNET_CHAIN,
194
- createSwapPublicClient
195
- } from '@aegis-engine/core'
275
+ import { AEGIS_SWAP_MAINNET_CHAIN, createSwapPublicClient } from '@aegis-engine/core'
196
276
 
197
277
  const publicClient = createSwapPublicClient(
198
278
  AEGIS_SWAP_MAINNET_CHAIN.chain,
@@ -212,10 +292,7 @@ metadata, market discovery, allowlists, and fee policy come from REST. Swap
212
292
  execution remains client-side.
213
293
 
214
294
  ```ts
215
- import {
216
- AEGIS_BACKEND_PROD_BASE_URL,
217
- createAegisBackendApiClient
218
- } from '@aegis-engine/core'
295
+ import { AEGIS_BACKEND_PROD_BASE_URL, createAegisBackendApiClient } from '@aegis-engine/core'
219
296
 
220
297
  const aegisApi = createAegisBackendApiClient({
221
298
  baseUrl: AEGIS_BACKEND_PROD_BASE_URL
@@ -281,10 +358,7 @@ provided, core verifies it matches the key.
281
358
  ## Direct Pool Quote
282
359
 
283
360
  ```ts
284
- import {
285
- AEGIS_SWAP_MAINNET_CHAIN,
286
- fetchDirectPoolSwapQuote
287
- } from '@aegis-engine/core'
361
+ import { AEGIS_SWAP_MAINNET_CHAIN, fetchDirectPoolSwapQuote } from '@aegis-engine/core'
288
362
 
289
363
  const quote = await fetchDirectPoolSwapQuote({
290
364
  publicClient,
@@ -339,10 +413,7 @@ protection the user saw.
339
413
  ## KyberSwap Quote
340
414
 
341
415
  ```ts
342
- import {
343
- AGGREGATED_SWAP_DEFAULT_TOKENS,
344
- fetchAggregatedSwapQuote
345
- } from '@aegis-engine/core'
416
+ import { AGGREGATED_SWAP_DEFAULT_TOKENS, fetchAggregatedSwapQuote } from '@aegis-engine/core'
346
417
 
347
418
  const quote = await fetchAggregatedSwapQuote(
348
419
  AGGREGATED_SWAP_DEFAULT_TOKENS.USDC,
@@ -2,7 +2,7 @@
2
2
 
3
3
  The lazy Engine implementation includes code from these MIT-licensed works:
4
4
 
5
- - `@labs-solo/aegis-engine-sdk` 0.30.0 — Copyright (c) 2026 Solo Labs
5
+ - `@labs-solo/aegis-engine-sdk` 0.33.0 — Copyright (c) 2026 Solo Labs
6
6
  - `@uniswap/sdk-core` 6.1.1 and 7.18.0 — Copyright (c) 2021 Uniswap Labs
7
7
  - `@uniswap/v3-sdk` 3.27.0 — Copyright (c) 2021 Uniswap Labs
8
8
  - `tiny-invariant` 1.3.3 — Copyright (c) 2019 Alexander Reardon