aegis-swap-widget 0.7.0 → 0.9.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 +79 -0
- package/DESIGN.md +2 -1
- package/README.md +158 -48
- package/dist/aegis-swap-widget.js +18040 -11260
- package/dist/components/Slider.d.ts +6 -2
- package/dist/components/icons.d.ts +2 -0
- package/dist/errors.d.ts +2 -3
- package/dist/format.d.ts +2 -0
- package/dist/hooks/useLatest.d.ts +2 -0
- package/dist/hooks/useRetryOnRefocus.d.ts +11 -0
- package/dist/hooks/useTokenAllowance.d.ts +2 -0
- package/dist/index.d.ts +4 -1
- package/dist/styles.css +1 -1
- package/dist/toast/useSwipeDismiss.d.ts +6 -1
- package/dist/widget/AegisLeverageWidget.d.ts +8 -0
- package/dist/widget/EngineAmountBox.d.ts +6 -1
- package/dist/widget/SwapWidgetShell.d.ts +3 -1
- package/dist/widget/TokenPriceHistoryStrip.d.ts +8 -2
- package/dist/widget/engine-controller/displayCache.d.ts +7 -1
- package/dist/widget/engine-controller/engineActionExpiry.d.ts +9 -1
- package/dist/widget/engine-controller/engineActionState.d.ts +22 -2
- package/dist/widget/engine-controller/engineCtaLabel.d.ts +12 -7
- package/dist/widget/engine-controller/engineDisplay.d.ts +8 -0
- package/dist/widget/engine-controller/engineOptions.d.ts +13 -1
- package/dist/widget/engine-controller/enginePermissionFamilies.d.ts +94 -0
- package/dist/widget/engine-controller/enginePositionBook.d.ts +66 -0
- package/dist/widget/engine-controller/enginePositionManageCopy.d.ts +51 -0
- package/dist/widget/engine-controller/engineQuoteFetch.d.ts +27 -6
- package/dist/widget/engine-controller/engineTokenPull.d.ts +13 -0
- package/dist/widget/engine-controller/engineTradePositionStorage.d.ts +9 -0
- package/dist/widget/engine-controller/engineTransactionProgress.d.ts +11 -2
- package/dist/widget/engine-controller/engineTransactionView.d.ts +10 -1
- package/dist/widget/engine-controller/useEngineActionDrafts.d.ts +3 -3
- package/dist/widget/engine-controller/useEngineActivity.d.ts +1 -1
- package/dist/widget/engine-controller/useEngineAuthorizationPlan.d.ts +44 -0
- package/dist/widget/engine-controller/useEngineMarketMarks.d.ts +18 -0
- package/dist/widget/engine-controller/useEnginePermissionSetup.d.ts +34 -0
- package/dist/widget/engine-controller/useEnginePositionActions.d.ts +24 -1
- package/dist/widget/engine-controller/useEnginePositionStrategies.d.ts +20 -0
- package/dist/widget/engine-controller/useEnginePositions.d.ts +35 -5
- package/dist/widget/engine-controller/useEngineSubmit.d.ts +6 -3
- package/dist/widget/engine-controller/useEngineTradePermissions.d.ts +81 -0
- package/dist/widget/engine-controller/useEngineTradeSubmit.d.ts +49 -0
- package/dist/widget/engine-ui/EngineBodySkeleton.d.ts +4 -0
- package/dist/widget/engine-ui/EngineCollateralRow.d.ts +8 -0
- package/dist/widget/engine-ui/EngineCollateralRowSkeleton.d.ts +3 -0
- package/dist/widget/engine-ui/EngineDetailsBreakdown.d.ts +7 -0
- package/dist/widget/engine-ui/EngineEstimateReveal.d.ts +4 -0
- package/dist/widget/engine-ui/EngineLeverageControl.d.ts +22 -0
- package/dist/widget/engine-ui/EngineNotice.d.ts +15 -0
- package/dist/widget/engine-ui/EngineOnboardingActivePermissions.d.ts +9 -0
- package/dist/widget/engine-ui/EngineOnboardingAuthorize.d.ts +18 -0
- package/dist/widget/engine-ui/EngineOnboardingFooter.d.ts +20 -0
- package/dist/widget/engine-ui/EngineOnboardingProgress.d.ts +12 -0
- package/dist/widget/engine-ui/EngineOnboardingReview.d.ts +19 -0
- package/dist/widget/engine-ui/EngineOnboardingSuccess.d.ts +15 -0
- package/dist/widget/engine-ui/EngineOverlaySheet.d.ts +18 -0
- package/dist/widget/engine-ui/EnginePartnerContext.d.ts +43 -0
- package/dist/widget/engine-ui/EnginePermissionRail.d.ts +21 -0
- package/dist/widget/engine-ui/EnginePermissionRailRow.d.ts +42 -0
- package/dist/widget/engine-ui/EnginePositionBookFacts.d.ts +5 -0
- package/dist/widget/engine-ui/EnginePositionManageDialog.d.ts +9 -2
- package/dist/widget/engine-ui/EnginePositionsPanel.d.ts +5 -3
- package/dist/widget/engine-ui/EngineQuotePending.d.ts +1 -0
- package/dist/widget/engine-ui/EngineReservedShell.d.ts +16 -0
- package/dist/widget/engine-ui/EngineRiskMeter.d.ts +7 -7
- package/dist/widget/engine-ui/EngineSegmentedControl.d.ts +12 -0
- package/dist/widget/engine-ui/EngineStepStateIcon.d.ts +5 -0
- package/dist/widget/engine-ui/EngineTradeEstimate.d.ts +11 -0
- package/dist/widget/engine-ui/EngineTradeOnboarding.d.ts +49 -0
- package/dist/widget/engine-ui/EngineTradePermissions.d.ts +44 -0
- package/dist/widget/engine-ui/EngineTradePermissionsPanels.d.ts +62 -0
- package/dist/widget/engine-ui/EngineTxDetailsPending.d.ts +1 -0
- package/dist/widget/engine-ui/TokenPairMark.d.ts +3 -3
- package/dist/widget/engine-ui/engineOnboardingPanelTypes.d.ts +6 -0
- package/dist/widget/engine-ui/enginePermissionCopy.d.ts +19 -0
- package/dist/widget/engine-ui/enginePermissionRailGeometry.d.ts +28 -0
- package/dist/widget/engine-ui/useEngineTradeEducation.d.ts +22 -0
- package/dist/widget/engine-ui/useOverlayClose.d.ts +1 -0
- package/dist/widget/engineTradeViewModel.d.ts +21 -0
- package/dist/widget/focusTrap.d.ts +1 -1
- package/dist/widget/types.d.ts +160 -7
- package/dist/widget/useEngineController.d.ts +3213 -2
- package/dist/widget/useSheetEntrance.d.ts +1 -1
- package/dist/widget/useSwapController.d.ts +1 -1
- package/dist/widget/useWidgetStyle.d.ts +2 -1
- package/dist/widget/viewState.d.ts +15 -1
- package/package.json +2 -2
- package/dist/encoding.d.ts +0 -2
- package/dist/quote/aggregatedSwapQuote.d.ts +0 -1
- package/dist/services/kyberSwap.d.ts +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,84 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c76ba41: Add Engine Long/Short trading.
|
|
8
|
+
|
|
9
|
+
Core sizes a directional position against one block-pinned Engine state and v4
|
|
10
|
+
route, then opens it in a single atomic router call. The swap settles inside the
|
|
11
|
+
transaction, so the wallet signs only the authorizations it must.
|
|
12
|
+
|
|
13
|
+
The widget gains an opt-in `'trade'` surface and a dedicated one-view
|
|
14
|
+
`AegisLeverageWidget`. Leverage limits come from the quote, alongside the
|
|
15
|
+
trader-facing risk facts for the position. Authorization reports its request
|
|
16
|
+
count per chain, and a review step is mandatory before submission but stays
|
|
17
|
+
customizable. Permissions are granted in sequence, each with its own checkpoint;
|
|
18
|
+
after a partial failure the revoke guidance for what was already granted stays
|
|
19
|
+
on screen. A successful open links through to Positions.
|
|
20
|
+
|
|
21
|
+
Position identity survives a reload: the strategy is reconstructed from indexed
|
|
22
|
+
opening actions, with optional bounded persistence of the reviewed target
|
|
23
|
+
scenario.
|
|
24
|
+
|
|
25
|
+
- 1e7a963: Keep the Leverage Positions surface trader-first and evidence-backed.
|
|
26
|
+
|
|
27
|
+
Only positions with strict indexed Long/Short evidence appear in the Leverage
|
|
28
|
+
widget. Ordinary borrow vaults remain in the portfolio presentation and are no
|
|
29
|
+
longer relabelled as trades while classification loads or fails. Stored opening
|
|
30
|
+
intents enrich matching indexed strategies but never classify a vault alone.
|
|
31
|
+
|
|
32
|
+
The collapsed trade row removes the borrow-rate runway, LTV bar, and
|
|
33
|
+
credit-product language. It shows direction, pair, opening-plan leverage, and a
|
|
34
|
+
signed underlying price move only while a fresh on-chain pool mark is available.
|
|
35
|
+
It does not call that move PnL or return. The detail keeps the reviewed
|
|
36
|
+
entry→target plan, and live debt/equity use the Engine liquidity-debt valuation
|
|
37
|
+
instead of deriving dollars or leverage from the protocol LTV ratio.
|
|
38
|
+
When NFT/LP collateral is attached and cannot be valued from the live idle
|
|
39
|
+
balances, the widget omits total equity rather than presenting a partial value.
|
|
40
|
+
|
|
41
|
+
"Last activity" now appears only when something actually happened after the
|
|
42
|
+
open. On an untouched lot it restated the opening date the collapsed row already
|
|
43
|
+
carries — one fact wearing two formats.
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 1e7a963: Unify the failure taxonomy and remove dead-end error states.
|
|
48
|
+
|
|
49
|
+
Core now owns one error classifier: `classifyError` returns curated copy plus a
|
|
50
|
+
failure `kind` and `retryable` flag, `UserFacingError` accepts both, and
|
|
51
|
+
`errorMessage` stays as a message-only compat wrapper. Wallet-cancelled sends
|
|
52
|
+
and not-ready Engine markets keep their curated copy instead of collapsing to a
|
|
53
|
+
generic fallback, and a not-ready market is marked non-retryable so retry CTAs
|
|
54
|
+
suppress.
|
|
55
|
+
|
|
56
|
+
The widget re-exports the core classifier (removing its diverged fork), catches
|
|
57
|
+
core's `TransactionReceiptTimeoutError` (hash included, explorer-link
|
|
58
|
+
messaging) instead of viem's unreachable timeout, retries failed Engine market
|
|
59
|
+
discovery via a Try again button and on refocus, turns a failed allowance check
|
|
60
|
+
into an enabled Try again CTA, labels fallback-served Engine data as
|
|
61
|
+
"last known" with a retry, derives inline errors from one precedence object
|
|
62
|
+
(submit failures outrank background quote failures), and keeps raw backend
|
|
63
|
+
error text out of the inline alert (widget log only).
|
|
64
|
+
|
|
65
|
+
- 1e7a963: Hug Engine onboarding sheets to their content and end leverage opens on a trading success screen with See position and Open another.
|
|
66
|
+
- Updated dependencies [1e7a963]
|
|
67
|
+
- Updated dependencies [c76ba41]
|
|
68
|
+
- Updated dependencies [1e7a963]
|
|
69
|
+
- @aegis-engine/core@0.5.0
|
|
70
|
+
|
|
71
|
+
## 0.8.0
|
|
72
|
+
|
|
73
|
+
### Minor Changes
|
|
74
|
+
|
|
75
|
+
- 127be2b: Add trusted Aegis Engine v1.0.3 deployment support for Robinhood Chain, upgrade the Engine SDK to 0.33.0, and bundle Robinhood Chain network artwork in the widget. Redeem quotes now return execution fields only for an SDK-verified frame, and an execution-gated redeem that the Engine assessed above the post-redeem utilization cap reports `utilization-blocked`.
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- Updated dependencies [127be2b]
|
|
80
|
+
- @aegis-engine/core@0.4.0
|
|
81
|
+
|
|
3
82
|
## 0.7.0
|
|
4
83
|
|
|
5
84
|
### Minor Changes
|
package/DESIGN.md
CHANGED
|
@@ -45,7 +45,8 @@ carry across both themes. `theme="auto"` follows `prefers-color-scheme`.
|
|
|
45
45
|
|
|
46
46
|
## Motion
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
Motion uses CSS and the browser Web Animations API. No third-party animation
|
|
49
|
+
runtime ships with the widget, and `prefers-reduced-motion` is respected.
|
|
49
50
|
|
|
50
51
|
| Token | Default | Role |
|
|
51
52
|
| --- | --- | --- |
|
package/README.md
CHANGED
|
@@ -4,7 +4,9 @@ Embed Amplifi Swap or Aegis Engine directly in a React application. Import the
|
|
|
4
4
|
component and CSS, then configure networks, REST data, wallet handoff, and host
|
|
5
5
|
styling through props.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Choose `<AegisSwapWidget />` for a swap-only embed or
|
|
8
|
+
`<AegisEngineWidget />` for Buy, Borrow, Lend, and Positions. Quoting, token
|
|
9
|
+
approval, Permit2 signing, and transaction submission stay inside the widget.
|
|
8
10
|
|
|
9
11
|
In the direct-pool widget, typing in the Sell field creates an exact-input swap
|
|
10
12
|
and typing in the Buy field creates an exact-output swap. Active quotes refresh
|
|
@@ -52,14 +54,105 @@ export function Engine({ account, provider }) {
|
|
|
52
54
|
defaultSurface="buy"
|
|
53
55
|
showTokenPriceHistory
|
|
54
56
|
showEngineMarketHistory
|
|
55
|
-
surfaces={['buy', 'borrow', 'lend', 'positions']}
|
|
57
|
+
surfaces={['buy', 'trade', 'borrow', 'lend', 'positions']}
|
|
56
58
|
/>
|
|
57
59
|
)
|
|
58
60
|
}
|
|
59
61
|
```
|
|
60
62
|
|
|
63
|
+
## Trade surface
|
|
64
|
+
|
|
65
|
+
`'trade'` is opt-in. The default tab set is `['buy', 'borrow', 'lend',
|
|
66
|
+
'positions']`, so the tab appears only when a host lists `'trade'` in
|
|
67
|
+
`surfaces`.
|
|
68
|
+
|
|
69
|
+
The surface opens a directional position in one atomic Engine router call:
|
|
70
|
+
create a fresh vault, deposit the user's token, borrow, swap through the same
|
|
71
|
+
Uniswap v4 pool, redeposit the output, and lock the vault. The quote pins the
|
|
72
|
+
Engine state and v4 route to one block, applies the selected slippage floor, and
|
|
73
|
+
re-quotes after wallet authorization before submission.
|
|
74
|
+
|
|
75
|
+
The user chooses Long or Short, a deposit, and leverage inside the live range
|
|
76
|
+
returned by the quote. The widget shows opening LTV against the borrow limit,
|
|
77
|
+
gross return at the configured target, entry-to-target price, opening price
|
|
78
|
+
impact, and interest over the configured horizon. Engine positions do not have
|
|
79
|
+
a single liquidation price; interest accrual increases LTV over time.
|
|
80
|
+
|
|
81
|
+
For a separate Long/Short experience that starts without
|
|
82
|
+
Buy/Borrow/Lend/Positions tabs, mount `AegisLeverageWidget`:
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { AegisLeverageWidget } from 'aegis-swap-widget'
|
|
86
|
+
import 'aegis-swap-widget/styles.css'
|
|
87
|
+
|
|
88
|
+
export function LongShort({ account, provider }) {
|
|
89
|
+
return (
|
|
90
|
+
<AegisLeverageWidget
|
|
91
|
+
account={account}
|
|
92
|
+
provider={provider}
|
|
93
|
+
chains={engineChains}
|
|
94
|
+
engineDataSource={{ kind: 'rest', baseUrl: '/api/engine' }}
|
|
95
|
+
tradeLeverageOptions={[1.25, 1.5, 2, 3]}
|
|
96
|
+
defaultTradeLeverage={1.5}
|
|
97
|
+
onboarding={{ mode: 'guided' }}
|
|
98
|
+
/>
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
This is the frontend integration interface; the host does not call the Engine
|
|
104
|
+
SDK directly. The host still supplies wallet connectivity, chain/router
|
|
105
|
+
configuration, and an Engine data source or same-origin proxy. Trade offers
|
|
106
|
+
only markets that support borrowing and have the required trusted execution
|
|
107
|
+
addresses.
|
|
108
|
+
|
|
109
|
+
After a deposit is entered, the leverage slider reads the feasible minimum and
|
|
110
|
+
maximum from the live Engine quote. The range recalculates for the amount,
|
|
111
|
+
direction, market, horizon, price scenario, liquidity, and slippage. Presets
|
|
112
|
+
are shortcuts, not protocol limits. If a live bound moves past the selected
|
|
113
|
+
target, the widget shows an explicit error and does not silently clamp it.
|
|
114
|
+
|
|
115
|
+
After confirmation, Positions reconstructs Long/Short direction and executed
|
|
116
|
+
entry price from the indexed opening transaction returned by
|
|
117
|
+
`GET /v1/engine/positions/activity`. A normal Borrow swap has a final
|
|
118
|
+
wallet-side withdrawal and is not labeled as a trade. The Leverage Positions
|
|
119
|
+
tab shows only vaults whose activity proves the Long/Short recipe; ordinary
|
|
120
|
+
borrow vaults remain in the unified portfolio. The reviewed average
|
|
121
|
+
leverage and target are off-chain scenario inputs, so the widget stores only
|
|
122
|
+
those fields after the receipt confirms. Omit `tradePositionStorage` for
|
|
123
|
+
origin-local `localStorage`, pass `null` to keep only indexed facts, or provide
|
|
124
|
+
an authenticated async adapter for cross-device continuity. Stored metadata is
|
|
125
|
+
joined by chain, account, pool, and opening transaction hash; it cannot
|
|
126
|
+
override indexed direction or entry price. A no-swap opening has no indexed
|
|
127
|
+
direction signal and remains a generic position.
|
|
128
|
+
|
|
129
|
+
The success sheet retains the reviewed risk snapshot and transaction link.
|
|
130
|
+
`AegisLeverageWidget` then reveals a Positions entry; indexed data can take a
|
|
131
|
+
moment to appear.
|
|
132
|
+
|
|
133
|
+
`guided` is the default onboarding mode. It keeps optional education available
|
|
134
|
+
through **How it works** without opening it automatically. Set
|
|
135
|
+
`onboarding={{ showBeforeConnect: true }}` to open it once for a browser that
|
|
136
|
+
has not dismissed it. Both `guided` and `contextual` use a required review
|
|
137
|
+
sheet. The sheet freezes the displayed position, reads
|
|
138
|
+
the connected account's current vault and token permissions, and lists only
|
|
139
|
+
the missing wallet actions before the final open transaction. A zero-first
|
|
140
|
+
ERC-20 reset is shown as a separate wallet prompt. The submit path re-reads the
|
|
141
|
+
permissions and obtains a fresh executable quote; the review is not execution
|
|
142
|
+
evidence. If that fresh quote weakens a displayed swap floor or risk fact, the
|
|
143
|
+
widget stops before the router transaction and requires review of the updated
|
|
144
|
+
strategy.
|
|
145
|
+
|
|
146
|
+
Use `onboarding={{ mode: 'contextual' }}` to omit the introductory education
|
|
147
|
+
while retaining the required review. Hosts can override presentation copy and
|
|
148
|
+
persistence through `onboarding`, but contract scope, token amount, expiry,
|
|
149
|
+
spender, target, and revocation copy remain SDK-owned.
|
|
150
|
+
|
|
61
151
|
## Partner context and host action requirements
|
|
62
152
|
|
|
153
|
+
Wolf Game partners can use the canonical
|
|
154
|
+
[live Wolf preview](https://swap.widget.aegis.markets/wolf).
|
|
155
|
+
|
|
63
156
|
`partnerContext` adds optional, display-only facts from a game or partner. The
|
|
64
157
|
host must normalize this data on its server. Do not pass API keys, private
|
|
65
158
|
vendor responses, or wallet-specific context through shared URLs.
|
|
@@ -81,13 +174,13 @@ const partnerContext = {
|
|
|
81
174
|
resource: {
|
|
82
175
|
chainId: 1,
|
|
83
176
|
address: '0x828B22c9ea1c20B551EeFC6198174C4bb7a8CBF6',
|
|
84
|
-
symbol: 'WATER'
|
|
177
|
+
symbol: 'WATER'
|
|
85
178
|
},
|
|
86
179
|
requiredAmount: '1000',
|
|
87
180
|
availableAmount: '660',
|
|
88
181
|
shortfallAmount: '340',
|
|
89
|
-
resourceUse: 'consumed'
|
|
90
|
-
}
|
|
182
|
+
resourceUse: 'consumed'
|
|
183
|
+
}
|
|
91
184
|
} satisfies PartnerContext
|
|
92
185
|
|
|
93
186
|
export function GameMarket() {
|
|
@@ -197,8 +290,8 @@ widget should own selection. The nested Buy surface remains independently
|
|
|
197
290
|
controlled through `buySwapConfig`; one-shot partner Buy intents already
|
|
198
291
|
resolve their matching direct pool.
|
|
199
292
|
|
|
200
|
-
Wolf Game's
|
|
201
|
-
harvesting data. It does not provide wallet-specific inventory, claimable
|
|
293
|
+
Wolf Game's aggregate API provides game-wide balances plus weather and
|
|
294
|
+
harvesting data for a selected community. It does not provide wallet-specific inventory, claimable
|
|
202
295
|
resources, energy timing, or a concrete action requirement. A Wolf host must
|
|
203
296
|
therefore create `actionRequirement` only from real game state. Do not derive it
|
|
204
297
|
from aggregate weather or inventory alone.
|
|
@@ -272,6 +365,12 @@ Product semantics are deliberately conservative:
|
|
|
272
365
|
before it quotes and submits add-collateral, repay, idle-withdraw, loan-close,
|
|
273
366
|
and lend-redeem actions. A close that needs an idle-token rebalance asks the
|
|
274
367
|
user to repay first, then re-quote the close.
|
|
368
|
+
- Positions identify Tap Long/Short openings from the activity ledger's exact
|
|
369
|
+
create/deposit/debt/internal-swap/lock order. Target price and average
|
|
370
|
+
leverage remain clearly labeled opening-plan metadata, not current protocol
|
|
371
|
+
state or an on-chain order. Leverage rows omit borrow-rate runway forecasts
|
|
372
|
+
and show the underlying move from entry only while a fresh same-pool mark is
|
|
373
|
+
available; the move is not presented as PnL or return.
|
|
275
374
|
- Lender balances are indexed Engine share units, not token amounts; the widget
|
|
276
375
|
does not invent a token/USD value without a current share price.
|
|
277
376
|
|
|
@@ -356,10 +455,11 @@ normalizes addresses and validates shape, but it cannot prove that a host's
|
|
|
356
455
|
override points at the intended Aegis or Uniswap deployment. Source those values
|
|
357
456
|
from your own audited config or backend, not from user input.
|
|
358
457
|
|
|
359
|
-
`onSubmitted`, `onSuccess`, `onError`, `onQuote`, `onStatusChange`,
|
|
360
|
-
`onPoolChange`
|
|
361
|
-
|
|
362
|
-
|
|
458
|
+
`onSubmitted`, `onSuccess`, `onError`, `onQuote`, `onStatusChange`,
|
|
459
|
+
`onPoolChange`, `onAuthorizationPlan`, `onAuthorizationStepChange`, and
|
|
460
|
+
`onOnboardingEvent` are the supported host signals. The in-widget "Latest tx"
|
|
461
|
+
drawer is a session-local UI receipt for the most recent confirmed swap; it is
|
|
462
|
+
not a transaction history API. If a host needs durable history, record
|
|
363
463
|
`onSubmitted`/`onSuccess` on the host side.
|
|
364
464
|
|
|
365
465
|
## Appearance
|
|
@@ -367,11 +467,7 @@ transaction history API. If a host needs durable history, record
|
|
|
367
467
|
Hosts can choose the widget surface and brand accent at instantiation time:
|
|
368
468
|
|
|
369
469
|
```tsx
|
|
370
|
-
<AegisSwapWidget
|
|
371
|
-
theme="dark"
|
|
372
|
-
accentColor="#7c5cff"
|
|
373
|
-
baseColor="#16121f"
|
|
374
|
-
/>
|
|
470
|
+
<AegisSwapWidget theme="dark" accentColor="#7c5cff" baseColor="#16121f" />
|
|
375
471
|
```
|
|
376
472
|
|
|
377
473
|
`theme` supports `dark`, `light`, or `auto` (which follows the host's `prefers-color-scheme`). `accentColor` accepts any CSS color value and is used for the CTA, selected pools, focus states, links, and swap controls. The widget auto-derives a readable CTA text color from `accentColor` — for hex, `rgb()`, and `hsl()` values everywhere, and for any CSS color (named, `oklch()`, …) in the browser. `accentTextColor` overrides that and is the deterministic choice when you want an exact CTA text color (or are rendering a named/`oklch()` accent during SSR).
|
|
@@ -443,7 +539,7 @@ The general Ethereum preset is exported for hosts that want the standard list:
|
|
|
443
539
|
import { AegisAggregatedSwapWidget } from 'aegis-swap-widget'
|
|
444
540
|
import {
|
|
445
541
|
AGGREGATED_SWAP_DEFAULT_TOKEN_LIST,
|
|
446
|
-
AGGREGATED_SWAP_WOLFGAME_TOKEN_LIST
|
|
542
|
+
AGGREGATED_SWAP_WOLFGAME_TOKEN_LIST
|
|
447
543
|
} from '@aegis-engine/core'
|
|
448
544
|
|
|
449
545
|
export function WolfGameSwap() {
|
|
@@ -520,7 +616,7 @@ import { AegisSwapWidget } from 'aegis-swap-widget'
|
|
|
520
616
|
import {
|
|
521
617
|
AEGIS_DYNAMIC_FEE_FLAG,
|
|
522
618
|
AEGIS_SWAP_HOOK,
|
|
523
|
-
type AegisSwapPoolConfig
|
|
619
|
+
type AegisSwapPoolConfig
|
|
524
620
|
} from '@aegis-engine/core'
|
|
525
621
|
|
|
526
622
|
const pools: AegisSwapPoolConfig[] = [
|
|
@@ -532,14 +628,14 @@ const pools: AegisSwapPoolConfig[] = [
|
|
|
532
628
|
currency1: '0xYourTokenAddress',
|
|
533
629
|
fee: AEGIS_DYNAMIC_FEE_FLAG,
|
|
534
630
|
tickSpacing: 60,
|
|
535
|
-
hooks: AEGIS_SWAP_HOOK
|
|
631
|
+
hooks: AEGIS_SWAP_HOOK
|
|
536
632
|
},
|
|
537
633
|
counterToken: {
|
|
538
634
|
chainId: 1,
|
|
539
635
|
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
540
636
|
name: 'USD Coin',
|
|
541
637
|
symbol: 'USDC',
|
|
542
|
-
decimals: 6
|
|
638
|
+
decimals: 6
|
|
543
639
|
},
|
|
544
640
|
token: {
|
|
545
641
|
chainId: 1,
|
|
@@ -547,9 +643,9 @@ const pools: AegisSwapPoolConfig[] = [
|
|
|
547
643
|
name: 'Example Token',
|
|
548
644
|
symbol: 'EXAMPLE',
|
|
549
645
|
decimals: 18,
|
|
550
|
-
iconUrl: 'https://example.com/token.svg'
|
|
551
|
-
}
|
|
552
|
-
}
|
|
646
|
+
iconUrl: 'https://example.com/token.svg'
|
|
647
|
+
}
|
|
648
|
+
}
|
|
553
649
|
]
|
|
554
650
|
|
|
555
651
|
export function Swap() {
|
|
@@ -566,13 +662,13 @@ The default chain is Ethereum mainnet. You can override mainnet RPCs or provide
|
|
|
566
662
|
```tsx
|
|
567
663
|
import { mainnet } from 'viem/chains'
|
|
568
664
|
|
|
569
|
-
|
|
665
|
+
;<AegisSwapWidget
|
|
570
666
|
chainId={1}
|
|
571
667
|
chains={{
|
|
572
668
|
1: {
|
|
573
669
|
chain: mainnet,
|
|
574
|
-
rpcUrls: ['https://your-mainnet-rpc.example']
|
|
575
|
-
}
|
|
670
|
+
rpcUrls: ['https://your-mainnet-rpc.example']
|
|
671
|
+
}
|
|
576
672
|
}}
|
|
577
673
|
pools={pools}
|
|
578
674
|
/>
|
|
@@ -588,15 +684,15 @@ import { base } from 'viem/chains'
|
|
|
588
684
|
import { AegisSwapWidget } from 'aegis-swap-widget'
|
|
589
685
|
import { UNISWAP_V4_CONTRACTS_BY_CHAIN } from '@aegis-engine/core'
|
|
590
686
|
|
|
591
|
-
|
|
687
|
+
;<AegisSwapWidget
|
|
592
688
|
chainId={8453}
|
|
593
689
|
chains={{
|
|
594
690
|
8453: {
|
|
595
691
|
chain: base,
|
|
596
692
|
router: '0xYourAegisRouter',
|
|
597
693
|
rpcUrls: ['https://your-base-rpc.example'],
|
|
598
|
-
v4Contracts: UNISWAP_V4_CONTRACTS_BY_CHAIN[8453]
|
|
599
|
-
}
|
|
694
|
+
v4Contracts: UNISWAP_V4_CONTRACTS_BY_CHAIN[8453]
|
|
695
|
+
}
|
|
600
696
|
}}
|
|
601
697
|
pools={pools}
|
|
602
698
|
/>
|
|
@@ -614,10 +710,7 @@ The widget fetches token icons by address using the metadata IDs from the Aegis
|
|
|
614
710
|
`evm_${chainId}_${tokenAddressLowercase}`.
|
|
615
711
|
|
|
616
712
|
```tsx
|
|
617
|
-
<AegisSwapWidget
|
|
618
|
-
metadataEndpoint="/graphql/meta"
|
|
619
|
-
pools={pools}
|
|
620
|
-
/>
|
|
713
|
+
<AegisSwapWidget metadataEndpoint="/graphql/meta" pools={pools} />
|
|
621
714
|
```
|
|
622
715
|
|
|
623
716
|
Use `metadataEndpoint={null}` to disable backend icon hydration. It does not
|
|
@@ -657,7 +750,7 @@ host connect modal creates the provider during the button click:
|
|
|
657
750
|
const connection = await openWallet()
|
|
658
751
|
return {
|
|
659
752
|
provider: connection.provider,
|
|
660
|
-
account: connection.account
|
|
753
|
+
account: connection.account
|
|
661
754
|
}
|
|
662
755
|
}}
|
|
663
756
|
/>
|
|
@@ -837,12 +930,12 @@ same viewport — a plain function, no hooks or context:
|
|
|
837
930
|
```tsx
|
|
838
931
|
import { aegisToast } from 'aegis-swap-widget'
|
|
839
932
|
|
|
840
|
-
aegisToast('Copied')
|
|
933
|
+
aegisToast('Copied') // info
|
|
841
934
|
aegisToast.success('Saved', { description: 'Order #1204' })
|
|
842
935
|
aegisToast.error('Could not save', { duration: 8000 })
|
|
843
936
|
|
|
844
|
-
const id = aegisToast.loading('Uploading…')
|
|
845
|
-
aegisToast.success('Uploaded', { id })
|
|
937
|
+
const id = aegisToast.loading('Uploading…') // sticky until updated
|
|
938
|
+
aegisToast.success('Uploaded', { id }) // reusing an id morphs in place
|
|
846
939
|
|
|
847
940
|
aegisToast.promise(save(), {
|
|
848
941
|
loading: 'Saving…',
|
|
@@ -862,8 +955,9 @@ package keep two independent toast stores (and two viewports).
|
|
|
862
955
|
|
|
863
956
|
Switching pools or the approval mode glides a single active pill between the
|
|
864
957
|
options (iOS-segmented-control style), and the Sell/Buy token pills cross-fade
|
|
865
|
-
when a switch retargets them.
|
|
866
|
-
|
|
958
|
+
when a switch retargets them. Motion uses CSS plus the browser Web Animations
|
|
959
|
+
API for the bottom-sheet entrance; no third-party animation runtime ships with
|
|
960
|
+
the widget. Every animation respects `prefers-reduced-motion` automatically.
|
|
867
961
|
|
|
868
962
|
Hosts tune or disable the switch motion through CSS tokens on the `style` prop:
|
|
869
963
|
|
|
@@ -881,13 +975,13 @@ Hosts tune or disable the switch motion through CSS tokens on the `style` prop:
|
|
|
881
975
|
0.3.0 removes the props that were deprecated in 0.2.x. The replacements are
|
|
882
976
|
drop-in:
|
|
883
977
|
|
|
884
|
-
| Removed
|
|
885
|
-
|
|
|
886
|
-
| `targets={[...]}`
|
|
887
|
-
| `markets={map}`
|
|
888
|
-
| `defaultDirection="intoTarget"`
|
|
889
|
-
| `defaultDirection="outOfTarget"` | `defaultDirection="sell"`
|
|
890
|
-
| `showApprovalModeControl`
|
|
978
|
+
| Removed | Use instead |
|
|
979
|
+
| -------------------------------- | ----------------------------------- |
|
|
980
|
+
| `targets={[...]}` | `poolIds={[...]}` (same `string[]`) |
|
|
981
|
+
| `markets={map}` | `pools={Object.values(map)}` |
|
|
982
|
+
| `defaultDirection="intoTarget"` | `defaultDirection="buy"` |
|
|
983
|
+
| `defaultDirection="outOfTarget"` | `defaultDirection="sell"` |
|
|
984
|
+
| `showApprovalModeControl` | `showApprovalMode` |
|
|
891
985
|
|
|
892
986
|
No other props changed. See the [CHANGELOG](./CHANGELOG.md) for the full entry.
|
|
893
987
|
|
|
@@ -927,8 +1021,22 @@ No other props changed. See the [CHANGELOG](./CHANGELOG.md) for the full entry.
|
|
|
927
1021
|
- `style`: optional root style object, useful for host layout constraints or CSS variables.
|
|
928
1022
|
- `title`: optional widget heading. Swap and Engine default to empty for compact embedded chrome.
|
|
929
1023
|
- `showNetworkSelector`: Engine header-network visibility: `'never'` (default), `'auto'`, or `'always'`. Cross-chain markets and tokens remain available in the full selectors when the header rail is hidden.
|
|
930
|
-
- `onSurfaceChange`: Engine callback fired when the active unified tab changes (`'buy'`, `'borrow'`, `'lend'`, or `'positions'`).
|
|
1024
|
+
- `onSurfaceChange`: Engine callback fired when the active unified tab changes (`'buy'`, `'trade'`, `'borrow'`, `'lend'`, or `'positions'`).
|
|
931
1025
|
- `marketResource`: controlled Lend/Borrow market locator (`chainId`, token `address`, and `symbol`). On the active chain, the widget resolves one eligible Engine market, hides its picker, and fails closed on missing or ambiguous matches. It does not lock token direction. Use `marketId` only as an optional disambiguator for the same resource.
|
|
1026
|
+
- `surfaces`: Engine tabs to expose. Defaults to `['buy', 'borrow', 'lend', 'positions']`. Add `'trade'` to opt into the Long/Short surface (see Trade surface).
|
|
1027
|
+
- `tradeDirections`: directions offered on the Trade surface. Defaults to `['long', 'short']`.
|
|
1028
|
+
- `defaultTradeDirection`: initial Trade direction. Defaults to the first `tradeDirections` entry.
|
|
1029
|
+
- `tradeDirectionSelector`: Long/Short selector visibility — `'auto'` (default) hides it when `tradeDirections` resolves to a single entry, `'always'`, or `'never'`.
|
|
1030
|
+
- `tradeLeverageOptions`: shortcuts shown below the quote-driven leverage slider. Defaults to `[2]`, with a separate live `Max` shortcut; preset values must be above `1` and no greater than `5`. The live Engine quote, not this list, sets the actual minimum and maximum.
|
|
1031
|
+
- `defaultTradeLeverage`: initial Trade leverage. Defaults to `1.5` and does not need to match a shortcut.
|
|
1032
|
+
- `tradeHorizonDays`: horizon used to size the directional position and estimate interest. Defaults to `30`.
|
|
1033
|
+
- `tradePriceMovePercent`: target-price move used to measure average leverage and gross target return. Defaults to `20`.
|
|
1034
|
+
- `tradePositionStorage`: optional async `load`/`save` adapter for confirmed Long/Short opening intent. Omit for origin-local browser persistence, pass `null` to disable off-chain persistence, or provide a host service for cross-device continuity. Host operations receive an optional `{ signal }`, use `timeoutMs` (default `10000`), and must treat `(chainId, account, txHash)` as an idempotent upsert key. Return newest-first records; the widget validates and reads at most 64. Timed-out operations fail softly and are not retried. Indexed actions always own direction and entry price.
|
|
1035
|
+
- `onboarding`: Long/Short education and review options. `mode` is `'guided'` (default) or `'contextual'`; required transaction review cannot be disabled. `motion: 'reduce'` forces the no-travel variant; `storage`, `storageKey`, and safe presentation `copy` overrides support host customization. `howItWorks: false` hides the education link and sheet. `showBeforeConnect: true` opens education once on first view; it stays closed by default. `permissionsWalkthrough: 'auto'` opens setup when a positive deposit still needs wallet access.
|
|
1036
|
+
- `permissionRailColor`: optional Engine permission-step rail color. It defaults to `accentColor` and derives readable rail ink automatically.
|
|
1037
|
+
- `onAuthorizationPlan`: called after the widget reads the connected account's live Long/Short authorization plan.
|
|
1038
|
+
- `onAuthorizationStepChange`: called with `requesting` and `confirmed` progress for each required vault, token, Permit2, and final-open action.
|
|
1039
|
+
- `onOnboardingEvent`: product lifecycle callback for education, review, authorization start, and confirmed-position events.
|
|
932
1040
|
- `buySwapConfig`: optional host overrides for the nested Engine Buy surface only. Use it to constrain Buy to a chain, pool set, or controlled `poolId` without changing Engine market discovery or the Lend/Borrow/Positions surfaces.
|
|
933
1041
|
- `showBuySettings`: show the Engine Buy surface's slippage-settings control. Defaults to `false`.
|
|
934
1042
|
- `showAmountSlider`: amount-slider visibility on the Engine lend/borrow amount boxes: `'auto'` (default) shows sliders on the borrow surface only, sized against the wallet's borrowing limit; `'always'` adds the lend deposit slider; `'never'` hides every amount slider.
|
|
@@ -939,7 +1047,9 @@ No other props changed. See the [CHANGELOG](./CHANGELOG.md) for the full entry.
|
|
|
939
1047
|
- `accentTextColor`: optional CTA text color for contrast with the chosen accent.
|
|
940
1048
|
- `baseColor`: CSS base surface color; derives the full neutral ramp (background, panels, borders, text, card gradient) in OKLCH for the active theme with contrast enforced (see Appearance).
|
|
941
1049
|
- `defaultApprovalMode`: `exact` approves only the current quote spend by default; `max` opts into the old unlimited ERC-20 to Permit2 approval behavior.
|
|
942
|
-
- `showApprovalMode`: whether the details drawer
|
|
1050
|
+
- `showApprovalMode`: whether to show the approval-amount control. On Swap it appears in the details drawer; on Engine Long/Short it appears on the Permit spending-limit row. Defaults to `true`.
|
|
1051
|
+
- `approvalMode`: controlled Engine approval mode (`'exact'` or `'max'`). Omit it to initialize internal state from `defaultApprovalMode`.
|
|
1052
|
+
- `onApprovalModeChange`: fired when the Engine approval mode changes. A controlled host must update `approvalMode` in response.
|
|
943
1053
|
- `showExecutionDetails`: whether to render the collapsible drawer for trade details and, after a confirmed swap, the session-local Latest tx receipt. Defaults to `true`.
|
|
944
1054
|
- `defaultExecutionDetailsOpen`: whether that settings drawer starts expanded. Defaults to `false`.
|
|
945
1055
|
- `executionDetailsOpen`: controlled open state for the Trade details drawer. Omit this for the widget's internal open/closed state.
|