aegis-swap-widget 0.1.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 ADDED
@@ -0,0 +1,193 @@
1
+ # Aegis Swap Widget
2
+
3
+ Embeddable React swap widget for WATER, WOOD, GRASS, and STONE. It does not import the private Aegis Engine SDK and does not use Uniswap widget packages.
4
+
5
+ The widget quotes the configured Uniswap v4 pool, handles ERC20 approval to Permit2, signs a Permit2 batch for the Aegis router, and submits the direct pool swap.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install aegis-swap-widget
11
+ ```
12
+
13
+ ## Basic Usage
14
+
15
+ ```tsx
16
+ import { AegisSwapWidget } from 'aegis-swap-widget'
17
+ import 'aegis-swap-widget/styles.css'
18
+
19
+ export function Swap() {
20
+ return (
21
+ <AegisSwapWidget
22
+ defaultTarget="GRASS"
23
+ theme="dark"
24
+ accentColor="#31d48a"
25
+ />
26
+ )
27
+ }
28
+ ```
29
+
30
+ By default the component uses `window.ethereum` when available, so injected wallets
31
+ like MetaMask and Rabby work without any wallet props.
32
+
33
+ Token icons are hydrated from the same metadata table used by the Aegis website:
34
+ `GlobalToken.iconURL` from the Aegis metadata GraphQL API. The default endpoint is
35
+ `https://aegis.markets/graphql/meta`.
36
+
37
+ ## Appearance
38
+
39
+ Hosts can choose the widget surface and brand accent at instantiation time:
40
+
41
+ ```tsx
42
+ <AegisSwapWidget
43
+ theme="light"
44
+ accentColor="#006adc"
45
+ accentTextColor="#ffffff"
46
+ />
47
+ ```
48
+
49
+ `theme` supports `dark` and `light`. `accentColor` accepts any CSS color value and is used for the CTA, selected pools, focus states, links, and swap controls. `accentTextColor` is optional and only needed when the accent color needs a different CTA text color for contrast.
50
+
51
+ ## Instantiate From Pool Keys
52
+
53
+ Pass the direct pools you want to expose. When `poolKeys` is provided, the widget only renders those token buttons unless you also pass `targets`.
54
+
55
+ ```tsx
56
+ import {
57
+ AegisSwapWidget,
58
+ AEGIS_SWAP_MARKETS,
59
+ type AegisSwapPoolKeys,
60
+ } from 'aegis-swap-widget'
61
+
62
+ const poolKeys: AegisSwapPoolKeys = {
63
+ GRASS: {
64
+ poolKey: AEGIS_SWAP_MARKETS.GRASS.poolKey,
65
+ label: 'USDC / GRASS',
66
+ },
67
+ WATER: {
68
+ poolKey: AEGIS_SWAP_MARKETS.WATER.poolKey,
69
+ label: 'USDC / WATER',
70
+ },
71
+ }
72
+
73
+ export function Swap() {
74
+ return <AegisSwapWidget poolKeys={poolKeys} defaultTarget="GRASS" />
75
+ }
76
+ ```
77
+
78
+ For the built-in WATER, WOOD, GRASS, and STONE symbols, the widget fills in token metadata, router, Permit2, Quoter, and pool id automatically. You can override any of those fields inside each pool-key config.
79
+
80
+ ## Chains
81
+
82
+ The default chain is Ethereum mainnet. You can override mainnet RPCs or provide another chain config:
83
+
84
+ ```tsx
85
+ import { mainnet } from 'viem/chains'
86
+
87
+ <AegisSwapWidget
88
+ chainId={1}
89
+ chains={{
90
+ 1: {
91
+ chain: mainnet,
92
+ rpcUrls: ['https://your-mainnet-rpc.example'],
93
+ },
94
+ }}
95
+ poolKeys={poolKeys}
96
+ />
97
+ ```
98
+
99
+ For a new chain, provide a viem `chain`, router, Permit2, Quoter, and RPC URLs. Pool-key entries can set `chainId`, `token`, and `counterToken` when the token addresses differ by chain.
100
+
101
+ ## Token Icons
102
+
103
+ The widget fetches token icons by address using the metadata IDs from the Aegis metadata API:
104
+ `evm_${chainId}_${tokenAddressLowercase}`.
105
+
106
+ ```tsx
107
+ <AegisSwapWidget
108
+ metadataEndpoint="/graphql/meta"
109
+ poolKeys={poolKeys}
110
+ />
111
+ ```
112
+
113
+ Use `metadataEndpoint={null}` to disable backend icon hydration. Tokens can also provide `iconUrl` directly when passed through a custom `market` or pool-key token override.
114
+
115
+ ## With Existing Wallet UI
116
+
117
+ If a site already has wallet state, pass its EIP-1193 provider and account:
118
+
119
+ ```tsx
120
+ <AegisSwapWidget
121
+ provider={provider}
122
+ account={account}
123
+ onConnectWallet={openWallet}
124
+ defaultTarget="STONE"
125
+ onSubmitted={(hash) => console.log(hash)}
126
+ />
127
+ ```
128
+
129
+ For wallet libraries where the provider is resolved lazily, pass `getProvider`:
130
+
131
+ ```tsx
132
+ <AegisSwapWidget
133
+ account={account}
134
+ getProvider={async () => walletConnector.getProvider()}
135
+ onConnectWallet={openWallet}
136
+ />
137
+ ```
138
+
139
+ `onConnectWallet` can also return the connection directly, which is useful when a
140
+ host connect modal creates the provider during the button click:
141
+
142
+ ```tsx
143
+ <AegisSwapWidget
144
+ onConnectWallet={async () => {
145
+ const connection = await openWallet()
146
+ return {
147
+ provider: connection.provider,
148
+ account: connection.account,
149
+ }
150
+ }}
151
+ />
152
+ ```
153
+
154
+ If none of these props are supplied, the widget still checks `window.ethereum`
155
+ automatically when it renders and again when the user clicks connect/swap.
156
+
157
+ ## Props
158
+
159
+ - `provider`: optional EIP-1193 provider. Defaults to auto-detected `window.ethereum`.
160
+ - `account`: optional connected account from the host wallet UI.
161
+ - `getProvider`: optional provider resolver for wallet libraries with async providers.
162
+ - `onConnectWallet`: optional callback for opening the host wallet modal. It may return `{ provider, account }`.
163
+ - `chainId`: active chain id. Defaults to Ethereum mainnet.
164
+ - `chains`: optional chain config overrides or additional chain configs.
165
+ - `poolKeys`: optional direct pool keys to render and swap against.
166
+ - `targets`: optional token button order/subset.
167
+ - `defaultTarget`: `WATER`, `WOOD`, `GRASS`, or `STONE`.
168
+ - `defaultDirection`: `intoTarget` for USDC to target, or `outOfTarget` for target to USDC.
169
+ - `markets`: optional override for pool/router/quoter config.
170
+ - `rpcUrls`: optional RPC fallback list for the active chain.
171
+ - `metadataEndpoint`: optional metadata GraphQL endpoint for `GlobalToken.iconURL` token icons. Set to `null` to disable.
172
+ - `theme`: `dark` or `light`. Defaults to `dark`.
173
+ - `themeMode`: legacy alias for `theme`.
174
+ - `accentColor`: CSS accent color for the CTA, selected pools, focus states, links, and swap controls.
175
+ - `accentTextColor`: optional CTA text color for contrast with the chosen accent.
176
+
177
+ ## Default Markets
178
+
179
+ The package ships mainnet direct-pool configs for:
180
+
181
+ - `USDC / WATER`
182
+ - `USDC / WOOD`
183
+ - `USDC / GRASS`
184
+ - `USDC / STONE`
185
+
186
+ These use the Aegis mainnet router `0x00581261a1200956ea05d1810fF28ffd66D8E254`, Permit2, and the public Uniswap v4 Quoter.
187
+
188
+ ## Local Demo
189
+
190
+ ```bash
191
+ npm install
192
+ npm run dev
193
+ ```
package/dist/abis.d.ts ADDED
@@ -0,0 +1,188 @@
1
+ export declare const AEGIS_ROUTER_ABI: readonly [{
2
+ readonly type: "function";
3
+ readonly name: "execute";
4
+ readonly stateMutability: "payable";
5
+ readonly inputs: readonly [{
6
+ readonly name: "batches";
7
+ readonly type: "tuple[]";
8
+ readonly components: readonly [{
9
+ readonly name: "requiresV4Unlock";
10
+ readonly type: "bool";
11
+ }, {
12
+ readonly name: "actions";
13
+ readonly type: "bytes";
14
+ }, {
15
+ readonly name: "params";
16
+ readonly type: "bytes[]";
17
+ }];
18
+ }, {
19
+ readonly name: "deadline";
20
+ readonly type: "uint256";
21
+ }];
22
+ readonly outputs: readonly [];
23
+ }, {
24
+ readonly type: "function";
25
+ readonly name: "multicall";
26
+ readonly stateMutability: "payable";
27
+ readonly inputs: readonly [{
28
+ readonly name: "data";
29
+ readonly type: "bytes[]";
30
+ }];
31
+ readonly outputs: readonly [{
32
+ readonly name: "results";
33
+ readonly type: "bytes[]";
34
+ }];
35
+ }, {
36
+ readonly type: "function";
37
+ readonly name: "permitBatch";
38
+ readonly stateMutability: "payable";
39
+ readonly inputs: readonly [{
40
+ readonly name: "owner";
41
+ readonly type: "address";
42
+ }, {
43
+ readonly name: "permitBatch";
44
+ readonly type: "tuple";
45
+ readonly components: readonly [{
46
+ readonly name: "details";
47
+ readonly type: "tuple[]";
48
+ readonly components: readonly [{
49
+ readonly name: "token";
50
+ readonly type: "address";
51
+ }, {
52
+ readonly name: "amount";
53
+ readonly type: "uint160";
54
+ }, {
55
+ readonly name: "expiration";
56
+ readonly type: "uint48";
57
+ }, {
58
+ readonly name: "nonce";
59
+ readonly type: "uint48";
60
+ }];
61
+ }, {
62
+ readonly name: "spender";
63
+ readonly type: "address";
64
+ }, {
65
+ readonly name: "sigDeadline";
66
+ readonly type: "uint256";
67
+ }];
68
+ }, {
69
+ readonly name: "signature";
70
+ readonly type: "bytes";
71
+ }];
72
+ readonly outputs: readonly [];
73
+ }];
74
+ export declare const PERMIT2_ABI: readonly [{
75
+ readonly type: "function";
76
+ readonly name: "allowance";
77
+ readonly stateMutability: "view";
78
+ readonly inputs: readonly [{
79
+ readonly name: "owner";
80
+ readonly type: "address";
81
+ }, {
82
+ readonly name: "token";
83
+ readonly type: "address";
84
+ }, {
85
+ readonly name: "spender";
86
+ readonly type: "address";
87
+ }];
88
+ readonly outputs: readonly [{
89
+ readonly name: "amount";
90
+ readonly type: "uint160";
91
+ }, {
92
+ readonly name: "expiration";
93
+ readonly type: "uint48";
94
+ }, {
95
+ readonly name: "nonce";
96
+ readonly type: "uint48";
97
+ }];
98
+ }];
99
+ export declare const UNISWAP_V4_QUOTER_ABI: readonly [{
100
+ readonly type: "function";
101
+ readonly name: "quoteExactInputSingle";
102
+ readonly stateMutability: "nonpayable";
103
+ readonly inputs: readonly [{
104
+ readonly name: "params";
105
+ readonly type: "tuple";
106
+ readonly components: readonly [{
107
+ readonly name: "poolKey";
108
+ readonly type: "tuple";
109
+ readonly components: readonly [{
110
+ readonly name: "currency0";
111
+ readonly type: "address";
112
+ }, {
113
+ readonly name: "currency1";
114
+ readonly type: "address";
115
+ }, {
116
+ readonly name: "fee";
117
+ readonly type: "uint24";
118
+ }, {
119
+ readonly name: "tickSpacing";
120
+ readonly type: "int24";
121
+ }, {
122
+ readonly name: "hooks";
123
+ readonly type: "address";
124
+ }];
125
+ }, {
126
+ readonly name: "zeroForOne";
127
+ readonly type: "bool";
128
+ }, {
129
+ readonly name: "exactAmount";
130
+ readonly type: "uint128";
131
+ }, {
132
+ readonly name: "hookData";
133
+ readonly type: "bytes";
134
+ }];
135
+ }];
136
+ readonly outputs: readonly [{
137
+ readonly name: "amountOut";
138
+ readonly type: "uint256";
139
+ }, {
140
+ readonly name: "gasEstimate";
141
+ readonly type: "uint256";
142
+ }];
143
+ }, {
144
+ readonly type: "function";
145
+ readonly name: "quoteExactOutputSingle";
146
+ readonly stateMutability: "nonpayable";
147
+ readonly inputs: readonly [{
148
+ readonly name: "params";
149
+ readonly type: "tuple";
150
+ readonly components: readonly [{
151
+ readonly name: "poolKey";
152
+ readonly type: "tuple";
153
+ readonly components: readonly [{
154
+ readonly name: "currency0";
155
+ readonly type: "address";
156
+ }, {
157
+ readonly name: "currency1";
158
+ readonly type: "address";
159
+ }, {
160
+ readonly name: "fee";
161
+ readonly type: "uint24";
162
+ }, {
163
+ readonly name: "tickSpacing";
164
+ readonly type: "int24";
165
+ }, {
166
+ readonly name: "hooks";
167
+ readonly type: "address";
168
+ }];
169
+ }, {
170
+ readonly name: "zeroForOne";
171
+ readonly type: "bool";
172
+ }, {
173
+ readonly name: "exactAmount";
174
+ readonly type: "uint128";
175
+ }, {
176
+ readonly name: "hookData";
177
+ readonly type: "bytes";
178
+ }];
179
+ }];
180
+ readonly outputs: readonly [{
181
+ readonly name: "amountIn";
182
+ readonly type: "uint256";
183
+ }, {
184
+ readonly name: "gasEstimate";
185
+ readonly type: "uint256";
186
+ }];
187
+ }];
188
+ //# sourceMappingURL=abis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abis.d.ts","sourceRoot":"","sources":["../src/abis.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsDnB,CAAA;AAEV,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;EAgBd,CAAA;AAEV,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+DxB,CAAA"}