aegis-swap-widget 0.5.1 → 0.6.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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d401c4d: Add optional partner context UI, host-owned action requirements, and one-shot launch intents that open a matching Engine Buy or Borrow market and prefill a concrete resource amount without submitting a transaction.
8
+
9
+ Adds the `partnerContext`, `partnerLaunchIntent`, `onPartnerLaunchIntentApplied`, `onPartnerAction`, and `onPartnerRequirementAction` props to `AegisEngineWidget`. The partner-neutral `PartnerActionRequirement` keeps host action semantics separate from the explicit Buy/Borrow launch event. The change also forwards `pools`/`poolIds` to the Buy surface and publishes the normalized contract from a new `aegis-swap-widget/partner-context` export. Omitting `partnerContext` keeps current behavior and performs no extra requests.
10
+
11
+ The `embedded` presentation is silent for aggregate partner facts and renders only a compact host-owned action requirement inside Buy or Borrow transaction content. The `showroom` presentation retains partner identity, environment, balances, activities, details, and navigation for integration evaluation.
12
+
13
+ API-backed partner amounts can additionally retain a validated raw base-unit integer and decimal scale. Partner blocks and action targets can carry observation and validity provenance; incomplete raw-amount or action-provenance pairs fail closed while the original display-only host shape remains compatible. Expired host requirements cannot produce a launch intent.
14
+
15
+ ### Patch Changes
16
+
17
+ - d401c4d: Make collapsed Engine disclosures findable with the browser's page search. TX details, the Borrow/Lend details panel, the lifecycle card body and both position-row details now hide with `hidden="until-found"` instead of `visibility`, so Cmd/Ctrl+F, `#fragment` navigation and `#:~:text=` links reach their text and expand the panel that holds it.
18
+
19
+ Closed panels still leave the tab order — `content-visibility` skips its subtree the same way the previous `visibility` flip did — and the collapse animation is unchanged: searchability is re-armed only after the transition finishes. The attribute is applied only where the browser supports it (feature-detected via `beforematch`); elsewhere the previous `visibility` behavior is untouched. Panels also assert their own `display`, so a host stylesheet with an unguarded `[hidden] { display: none }` reset cannot flatten the accordion track.
20
+
3
21
  ## 0.5.1
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -58,6 +58,123 @@ export function Engine({ account, provider }) {
58
58
  }
59
59
  ```
60
60
 
61
+ ## Partner context and host action requirements
62
+
63
+ `partnerContext` adds optional, display-only facts from a game or partner. The
64
+ host must normalize this data on its server. Do not pass API keys, private
65
+ vendor responses, or wallet-specific context through shared URLs.
66
+
67
+ An `actionRequirement` is the host's authoritative statement of what a selected
68
+ partner action needs. The widget can display the shortfall and let the user
69
+ explicitly open Buy or Borrow. The choice creates an editable prefill; it never
70
+ submits a transaction or changes Aegis market data:
71
+
72
+ ```tsx
73
+ import { AegisEngineWidget } from 'aegis-swap-widget'
74
+ import type { PartnerContext } from 'aegis-swap-widget/partner-context'
75
+
76
+ const partnerContext = {
77
+ partner: { id: 'wolf-game', name: 'Wolf Game' },
78
+ actionRequirement: {
79
+ id: 'upgrade-barn-water',
80
+ label: 'Upgrade Barn',
81
+ resource: {
82
+ chainId: 1,
83
+ address: '0x828B22c9ea1c20B551EeFC6198174C4bb7a8CBF6',
84
+ symbol: 'WATER',
85
+ },
86
+ requiredAmount: '1000',
87
+ availableAmount: '660',
88
+ shortfallAmount: '340',
89
+ resourceUse: 'consumed',
90
+ },
91
+ } satisfies PartnerContext
92
+
93
+ export function GameMarket() {
94
+ return (
95
+ <AegisEngineWidget
96
+ partnerContext={partnerContext}
97
+ partnerContextVariant="embedded"
98
+ onPartnerRequirementAction={(requirement, surface) => {
99
+ console.log(surface, requirement.id)
100
+ }}
101
+ onPartnerLaunchIntentApplied={(intent) => {
102
+ console.log('Editable amount applied', intent.amount)
103
+ }}
104
+ />
105
+ )
106
+ }
107
+ ```
108
+
109
+ `requiredAmount`, `availableAmount`, and `shortfallAmount` are canonical token-unit
110
+ decimal strings, not grouped text or raw base units. When `availableAmount` is
111
+ present, the shortfall must equal `max(required - available, 0)`. `resourceUse`
112
+ is host-owned disclosure: `'consumed'`, `'returned'`, or `'unknown'`. It does not
113
+ make Borrow a recommendation.
114
+
115
+ API-backed display amounts may also include `rawAmount` and `decimals`. Supply
116
+ both or neither. `rawAmount` is a canonical nonnegative base-unit integer; it
117
+ remains display-only and never becomes a transaction amount. Environment,
118
+ production, inventory, and activity blocks can carry a `PartnerObservation`
119
+ with `observedAt` and optional `validUntil`. An action target can carry the same
120
+ validity provenance plus a host-owned `reason`. Partial or malformed amount and
121
+ action-provenance blocks fail closed at the widget boundary. The launch helper
122
+ also rejects a requirement once its optional `expiresAt` deadline is reached.
123
+
124
+ If the host owns the action button outside the widget, keep using a separate
125
+ one-shot `partnerLaunchIntent`. The exported helper maps a validated requirement
126
+ to that event without duplicating its resource or amount:
127
+
128
+ ```tsx
129
+ import { partnerLaunchIntentForRequirement } from 'aegis-swap-widget/partner-context'
130
+
131
+ const launchIntent = partnerLaunchIntentForRequirement(
132
+ partnerContext.actionRequirement,
133
+ 'borrow',
134
+ crypto.randomUUID()
135
+ )
136
+ ```
137
+
138
+ The equivalent launch intent is:
139
+
140
+ ```ts
141
+ {
142
+ requestId: 'new-id-for-this-click',
143
+ source: 'action-requirement',
144
+ requirementId: 'upgrade-barn-water',
145
+ surface: 'borrow',
146
+ resource: {
147
+ chainId: 1,
148
+ address: '0x828B22c9ea1c20B551EeFC6198174C4bb7a8CBF6',
149
+ symbol: 'WATER',
150
+ },
151
+ amount: '340',
152
+ }
153
+ ```
154
+
155
+ Pass that value through `partnerLaunchIntent` and clear it after
156
+ `onPartnerLaunchIntentApplied`. Use a new `requestId` for each external click.
157
+ Borrow fills the debt token's “I need” field. Buy uses the matching direct pool
158
+ and fills an exact-output Receive amount. The widget never submits automatically
159
+ and fails closed when the chain, market, token identity, or precision does not
160
+ match.
161
+
162
+ Use `partnerContextVariant="embedded"` inside an existing product shell. It is
163
+ silent unless the host supplies an `actionRequirement`; then the widget places
164
+ one compact purpose row beside the active Buy or Borrow transaction content.
165
+ Partner identity, weather, aggregate balances, activities, secondary details,
166
+ and navigation remain available only in the default `showroom` variant. If the
167
+ host already owns resource selection, pass its exact Engine `marketId`. This
168
+ controlled form hides the widget market picker and prevents partner actions from
169
+ selecting another market. Use `defaultMarketId` when the widget should own
170
+ selection.
171
+
172
+ Wolf Game's current aggregate API provides Community 12 balances, weather, and
173
+ harvesting data. It does not provide wallet-specific inventory, claimable
174
+ resources, energy timing, or a concrete action requirement. A Wolf host must
175
+ therefore create `actionRequirement` only from real game state. Do not derive it
176
+ from aggregate weather or inventory alone.
177
+
61
178
  The Engine discovery surface defaults to Amplifi's public production REST API.
62
179
  The production source implements
63
180
  `GET /v1/engine/markets?chainId=`,
@@ -122,9 +239,11 @@ Product semantics are deliberately conservative:
122
239
  impermanent-loss exposure.
123
240
  - The widget does not claim borrowing is cheaper than buying without a
124
241
  partner-provided returnability/consumption model and duration.
125
- - Positions are indexed snapshots (open + display). Last-locked LTV is not
126
- presented as current health. Repay, redeem, close, and withdraw flows are
127
- deferred and not exposed in the widget.
242
+ - Positions start from indexed discovery snapshots. Last-locked LTV is not
243
+ presented as current health. The management dialog rehydrates live RPC state
244
+ before it quotes and submits add-collateral, repay, idle-withdraw, loan-close,
245
+ and lend-redeem actions. A close that needs an idle-token rebalance asks the
246
+ user to repay first, then re-quote the close.
128
247
  - Lender balances are indexed Engine share units, not token amounts; the widget
129
248
  does not invent a token/USD value without a current share price.
130
249
 
@@ -766,6 +885,7 @@ No other props changed. See the [CHANGELOG](./CHANGELOG.md) for the full entry.
766
885
  - `networkSelectorColorMode`: `'accent'` (default) keeps host-brand selector chrome; `'chain'` uses the built-in DFF chain palette for supported chains.
767
886
  - `pools`: direct pool configs to render and swap against. This is the canonical config path.
768
887
  - `defaultPoolId`: initial pool id when `pools` is provided.
888
+ - `poolId`: controlled active pool id. Pair with `onPoolChange` when the host owns pool selection; updates change the form in place.
769
889
  - `poolIds`: optional pool id order/subset. Use this when the host wants to hide pools or control ordering.
770
890
  - `defaultDirection`: `buy` (counter token into the pool token) or `sell` (pool token into the counter token). Defaults to `buy`.
771
891
  - `defaultSlippagePercent`: number (canonical) or numeric string, in percent. Defaults to `1`.
@@ -779,7 +899,10 @@ No other props changed. See the [CHANGELOG](./CHANGELOG.md) for the full entry.
779
899
  - `style`: optional root style object, useful for host layout constraints or CSS variables.
780
900
  - `title`: optional widget heading. Swap and Engine default to empty for compact embedded chrome.
781
901
  - `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.
902
+ - `onSurfaceChange`: Engine callback fired when the active unified tab changes (`'buy'`, `'borrow'`, `'lend'`, or `'positions'`).
903
+ - `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.
782
904
  - `showBuySettings`: show the Engine Buy surface's slippage-settings control. Defaults to `false`.
905
+ - `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.
783
906
  - `subtitle`: optional header eyebrow. Defaults to empty. Pass a string to show it.
784
907
  - `ariaLabel`: optional accessible label for the widget region. Defaults to `Swap` for Swap and `Lend, borrow, and buy` for Engine.
785
908
  - `theme`: `dark`, `light`, or `auto` (follows `prefers-color-scheme`). Defaults to `dark`.