@aegis-engine/core 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/LICENSE +21 -0
- package/README.md +42 -0
- package/dist/abis.d.ts +205 -0
- package/dist/actions/directPoolSwap.d.ts +39 -0
- package/dist/actions/kyberSwap.d.ts +38 -0
- package/dist/actions/types.d.ts +17 -0
- package/dist/actions/wallet.d.ts +17 -0
- package/dist/address.d.ts +5 -0
- package/dist/aegis-core.js +2043 -0
- package/dist/config.d.ts +119 -0
- package/dist/encoding.d.ts +57 -0
- package/dist/errors.d.ts +3 -0
- package/dist/index.d.ts +28 -0
- package/dist/metadata.d.ts +25 -0
- package/dist/permit.d.ts +70 -0
- package/dist/polling.d.ts +3 -0
- package/dist/quote/aggregatedSwapQuote.d.ts +5 -0
- package/dist/quote.d.ts +59 -0
- package/dist/services/kyberSwap.d.ts +84 -0
- package/dist/swap/authorizePermit.d.ts +29 -0
- package/dist/swap/executeSwapTransaction.d.ts +38 -0
- package/dist/swap/gas.d.ts +8 -0
- package/dist/swap/types.d.ts +28 -0
- package/dist/transactionProgress.d.ts +55 -0
- package/dist/types/aggregatedSwap.d.ts +29 -0
- package/dist/wallet.d.ts +34 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aegis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Aegis Core
|
|
2
|
+
|
|
3
|
+
React-free swap operations for Aegis integrations.
|
|
4
|
+
|
|
5
|
+
This package exposes the operational pieces that the widget uses internally:
|
|
6
|
+
direct pool quotes and execution, KyberSwap quotes and execution, Permit2
|
|
7
|
+
authorization helpers, chain/wallet helpers, token and market config, and
|
|
8
|
+
transaction progress types.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import {
|
|
12
|
+
AEGIS_SWAP_MAINNET_CHAIN,
|
|
13
|
+
AEGIS_SWAP_MARKETS,
|
|
14
|
+
AEGIS_SWAP_TOKENS,
|
|
15
|
+
createSwapPublicClient,
|
|
16
|
+
executeDirectPoolSwap,
|
|
17
|
+
resolveWalletSession
|
|
18
|
+
} from '@aegis-engine/core'
|
|
19
|
+
|
|
20
|
+
const publicClient = createSwapPublicClient(
|
|
21
|
+
AEGIS_SWAP_MAINNET_CHAIN.chain,
|
|
22
|
+
AEGIS_SWAP_MAINNET_CHAIN.rpcUrls
|
|
23
|
+
)
|
|
24
|
+
const wallet = await resolveWalletSession()
|
|
25
|
+
|
|
26
|
+
const result = await executeDirectPoolSwap({
|
|
27
|
+
wallet,
|
|
28
|
+
publicClient,
|
|
29
|
+
activeChain: AEGIS_SWAP_MAINNET_CHAIN,
|
|
30
|
+
market: AEGIS_SWAP_MARKETS.WATER_USDC,
|
|
31
|
+
inputToken: AEGIS_SWAP_TOKENS.USDC,
|
|
32
|
+
outputToken: AEGIS_SWAP_TOKENS.WATER,
|
|
33
|
+
mode: 'exactIn',
|
|
34
|
+
amount: 1_000_000n,
|
|
35
|
+
slippageBps: 100
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
For Kyber routes, call `executeKyberSwap` with an input token, output token,
|
|
40
|
+
amount, and slippage. Both execution actions accept callbacks for status,
|
|
41
|
+
transaction hash, and submitted swap details so a host UI can render its own
|
|
42
|
+
progress surfaces.
|
package/dist/abis.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
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: "approve";
|
|
77
|
+
readonly stateMutability: "nonpayable";
|
|
78
|
+
readonly inputs: readonly [{
|
|
79
|
+
readonly name: "token";
|
|
80
|
+
readonly type: "address";
|
|
81
|
+
}, {
|
|
82
|
+
readonly name: "spender";
|
|
83
|
+
readonly type: "address";
|
|
84
|
+
}, {
|
|
85
|
+
readonly name: "amount";
|
|
86
|
+
readonly type: "uint160";
|
|
87
|
+
}, {
|
|
88
|
+
readonly name: "expiration";
|
|
89
|
+
readonly type: "uint48";
|
|
90
|
+
}];
|
|
91
|
+
readonly outputs: readonly [];
|
|
92
|
+
}, {
|
|
93
|
+
readonly type: "function";
|
|
94
|
+
readonly name: "allowance";
|
|
95
|
+
readonly stateMutability: "view";
|
|
96
|
+
readonly inputs: readonly [{
|
|
97
|
+
readonly name: "owner";
|
|
98
|
+
readonly type: "address";
|
|
99
|
+
}, {
|
|
100
|
+
readonly name: "token";
|
|
101
|
+
readonly type: "address";
|
|
102
|
+
}, {
|
|
103
|
+
readonly name: "spender";
|
|
104
|
+
readonly type: "address";
|
|
105
|
+
}];
|
|
106
|
+
readonly outputs: readonly [{
|
|
107
|
+
readonly name: "amount";
|
|
108
|
+
readonly type: "uint160";
|
|
109
|
+
}, {
|
|
110
|
+
readonly name: "expiration";
|
|
111
|
+
readonly type: "uint48";
|
|
112
|
+
}, {
|
|
113
|
+
readonly name: "nonce";
|
|
114
|
+
readonly type: "uint48";
|
|
115
|
+
}];
|
|
116
|
+
}];
|
|
117
|
+
export declare const UNISWAP_V4_QUOTER_ABI: readonly [{
|
|
118
|
+
readonly type: "function";
|
|
119
|
+
readonly name: "quoteExactInputSingle";
|
|
120
|
+
readonly stateMutability: "nonpayable";
|
|
121
|
+
readonly inputs: readonly [{
|
|
122
|
+
readonly name: "params";
|
|
123
|
+
readonly type: "tuple";
|
|
124
|
+
readonly components: readonly [{
|
|
125
|
+
readonly name: "poolKey";
|
|
126
|
+
readonly type: "tuple";
|
|
127
|
+
readonly components: readonly [{
|
|
128
|
+
readonly name: "currency0";
|
|
129
|
+
readonly type: "address";
|
|
130
|
+
}, {
|
|
131
|
+
readonly name: "currency1";
|
|
132
|
+
readonly type: "address";
|
|
133
|
+
}, {
|
|
134
|
+
readonly name: "fee";
|
|
135
|
+
readonly type: "uint24";
|
|
136
|
+
}, {
|
|
137
|
+
readonly name: "tickSpacing";
|
|
138
|
+
readonly type: "int24";
|
|
139
|
+
}, {
|
|
140
|
+
readonly name: "hooks";
|
|
141
|
+
readonly type: "address";
|
|
142
|
+
}];
|
|
143
|
+
}, {
|
|
144
|
+
readonly name: "zeroForOne";
|
|
145
|
+
readonly type: "bool";
|
|
146
|
+
}, {
|
|
147
|
+
readonly name: "exactAmount";
|
|
148
|
+
readonly type: "uint128";
|
|
149
|
+
}, {
|
|
150
|
+
readonly name: "hookData";
|
|
151
|
+
readonly type: "bytes";
|
|
152
|
+
}];
|
|
153
|
+
}];
|
|
154
|
+
readonly outputs: readonly [{
|
|
155
|
+
readonly name: "amountOut";
|
|
156
|
+
readonly type: "uint256";
|
|
157
|
+
}, {
|
|
158
|
+
readonly name: "gasEstimate";
|
|
159
|
+
readonly type: "uint256";
|
|
160
|
+
}];
|
|
161
|
+
}, {
|
|
162
|
+
readonly type: "function";
|
|
163
|
+
readonly name: "quoteExactOutputSingle";
|
|
164
|
+
readonly stateMutability: "nonpayable";
|
|
165
|
+
readonly inputs: readonly [{
|
|
166
|
+
readonly name: "params";
|
|
167
|
+
readonly type: "tuple";
|
|
168
|
+
readonly components: readonly [{
|
|
169
|
+
readonly name: "poolKey";
|
|
170
|
+
readonly type: "tuple";
|
|
171
|
+
readonly components: readonly [{
|
|
172
|
+
readonly name: "currency0";
|
|
173
|
+
readonly type: "address";
|
|
174
|
+
}, {
|
|
175
|
+
readonly name: "currency1";
|
|
176
|
+
readonly type: "address";
|
|
177
|
+
}, {
|
|
178
|
+
readonly name: "fee";
|
|
179
|
+
readonly type: "uint24";
|
|
180
|
+
}, {
|
|
181
|
+
readonly name: "tickSpacing";
|
|
182
|
+
readonly type: "int24";
|
|
183
|
+
}, {
|
|
184
|
+
readonly name: "hooks";
|
|
185
|
+
readonly type: "address";
|
|
186
|
+
}];
|
|
187
|
+
}, {
|
|
188
|
+
readonly name: "zeroForOne";
|
|
189
|
+
readonly type: "bool";
|
|
190
|
+
}, {
|
|
191
|
+
readonly name: "exactAmount";
|
|
192
|
+
readonly type: "uint128";
|
|
193
|
+
}, {
|
|
194
|
+
readonly name: "hookData";
|
|
195
|
+
readonly type: "bytes";
|
|
196
|
+
}];
|
|
197
|
+
}];
|
|
198
|
+
readonly outputs: readonly [{
|
|
199
|
+
readonly name: "amountIn";
|
|
200
|
+
readonly type: "uint256";
|
|
201
|
+
}, {
|
|
202
|
+
readonly name: "gasEstimate";
|
|
203
|
+
readonly type: "uint256";
|
|
204
|
+
}];
|
|
205
|
+
}];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import type { AegisSwapChainConfig, AegisSwapFeeConfig, AegisSwapMarket, AegisSwapToken } from '../config';
|
|
3
|
+
import { type DirectSwapQuote, type SwapQuoteMode } from '../quote';
|
|
4
|
+
import type { AegisSwapApprovalMode, WalletSession } from '../swap/types';
|
|
5
|
+
import type { AegisSwapActionCallbacks, AegisSwapActionResult } from './types';
|
|
6
|
+
export declare class DirectPoolSwapPriceMovedError extends Error {
|
|
7
|
+
readonly quote: DirectSwapQuote;
|
|
8
|
+
constructor(quote: DirectSwapQuote);
|
|
9
|
+
}
|
|
10
|
+
export type DirectPoolSwapApprovalResult = {
|
|
11
|
+
approvalHash: Hex | null;
|
|
12
|
+
allowance: bigint;
|
|
13
|
+
};
|
|
14
|
+
export declare function approveDirectPoolSwapInput(args: {
|
|
15
|
+
wallet: WalletSession;
|
|
16
|
+
publicClient: PublicClient;
|
|
17
|
+
activeChain: AegisSwapChainConfig;
|
|
18
|
+
token: AegisSwapToken;
|
|
19
|
+
permit2: AegisSwapMarket['permit2'];
|
|
20
|
+
amount: bigint;
|
|
21
|
+
approvalMode?: AegisSwapApprovalMode;
|
|
22
|
+
onStatus?: AegisSwapActionCallbacks['onStatus'];
|
|
23
|
+
}): Promise<DirectPoolSwapApprovalResult>;
|
|
24
|
+
export declare function executeDirectPoolSwap(args: {
|
|
25
|
+
wallet: WalletSession;
|
|
26
|
+
publicClient: PublicClient;
|
|
27
|
+
activeChain: AegisSwapChainConfig;
|
|
28
|
+
market: AegisSwapMarket;
|
|
29
|
+
inputToken: AegisSwapToken;
|
|
30
|
+
outputToken: AegisSwapToken;
|
|
31
|
+
mode: SwapQuoteMode;
|
|
32
|
+
amount: bigint;
|
|
33
|
+
slippageBps: number;
|
|
34
|
+
fee?: AegisSwapFeeConfig | null;
|
|
35
|
+
displayedQuote?: DirectSwapQuote | null;
|
|
36
|
+
approvalMode?: AegisSwapApprovalMode;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
onWalletChainId?: (chainId: number | null) => void;
|
|
39
|
+
} & AegisSwapActionCallbacks): Promise<AegisSwapActionResult<DirectSwapQuote>>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Address, type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import type { AegisSwapChainConfig, AegisSwapToken } from '../config';
|
|
3
|
+
import type { AegisSwapApprovalMode, WalletSession } from '../swap/types';
|
|
4
|
+
import type { AggregatedSwapQuote } from '../types/aggregatedSwap';
|
|
5
|
+
import type { AegisSwapActionCallbacks, AegisSwapActionResult } from './types';
|
|
6
|
+
export declare const NATIVE_TOKEN_ADDRESS: Address;
|
|
7
|
+
export declare function isNativeToken(token: AegisSwapToken): boolean;
|
|
8
|
+
export declare class KyberSwapPriceMovedError extends Error {
|
|
9
|
+
readonly quote: AggregatedSwapQuote;
|
|
10
|
+
constructor(quote: AggregatedSwapQuote);
|
|
11
|
+
}
|
|
12
|
+
export type KyberSwapApprovalResult = {
|
|
13
|
+
approvalHashes: Hex[];
|
|
14
|
+
allowance: bigint;
|
|
15
|
+
};
|
|
16
|
+
export declare function approveKyberSwapInput(args: {
|
|
17
|
+
wallet: WalletSession;
|
|
18
|
+
publicClient: PublicClient;
|
|
19
|
+
activeChain: AegisSwapChainConfig;
|
|
20
|
+
inputToken: AegisSwapToken;
|
|
21
|
+
spender: Address;
|
|
22
|
+
amount: bigint;
|
|
23
|
+
approvalMode?: AegisSwapApprovalMode;
|
|
24
|
+
onStatus?: AegisSwapActionCallbacks['onStatus'];
|
|
25
|
+
}): Promise<KyberSwapApprovalResult>;
|
|
26
|
+
export declare function executeKyberSwap(args: {
|
|
27
|
+
wallet: WalletSession;
|
|
28
|
+
publicClient: PublicClient;
|
|
29
|
+
activeChain: AegisSwapChainConfig;
|
|
30
|
+
inputToken: AegisSwapToken;
|
|
31
|
+
outputToken: AegisSwapToken;
|
|
32
|
+
amount: bigint;
|
|
33
|
+
slippageBps: number;
|
|
34
|
+
displayedQuote?: AggregatedSwapQuote | null;
|
|
35
|
+
approvalMode?: AegisSwapApprovalMode;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
onWalletChainId?: (chainId: number | null) => void;
|
|
38
|
+
} & AegisSwapActionCallbacks): Promise<AegisSwapActionResult<AggregatedSwapQuote>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
import type { DirectSwapQuote } from '../quote';
|
|
3
|
+
import type { AegisSwapReceiptSummary, SubmitStatus } from '../transactionProgress';
|
|
4
|
+
import type { AggregatedSwapQuote } from '../types/aggregatedSwap';
|
|
5
|
+
import type { AegisSwapSubmitDetails } from '../swap/types';
|
|
6
|
+
export type AegisSwapActionCallbacks<TSwapDetails = AegisSwapSubmitDetails> = {
|
|
7
|
+
onStatus?: (status: SubmitStatus) => void;
|
|
8
|
+
onTxHash?: (hash: Hex | null) => void;
|
|
9
|
+
onSubmitted?: (hash: Hex, swap?: TSwapDetails) => void;
|
|
10
|
+
};
|
|
11
|
+
export type AegisSwapActionResult<TQuote = DirectSwapQuote | AggregatedSwapQuote> = {
|
|
12
|
+
hash: Hex;
|
|
13
|
+
explorerUrl: string;
|
|
14
|
+
quote: TQuote;
|
|
15
|
+
receiptSummary: AegisSwapReceiptSummary;
|
|
16
|
+
swap: AegisSwapSubmitDetails;
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
import type { AegisSwapChainConfig } from '../config';
|
|
3
|
+
import type { WalletSession } from '../swap/types';
|
|
4
|
+
import { type AegisSwapProviderResolver, type AegisSwapWalletConnection, type Eip1193Provider } from '../wallet';
|
|
5
|
+
export declare function waitForProviderChain(provider: Eip1193Provider, targetChainId: number, attempts?: number, delayMs?: number): Promise<boolean>;
|
|
6
|
+
export declare function ensureWalletChain(args: {
|
|
7
|
+
provider: Eip1193Provider;
|
|
8
|
+
chain: AegisSwapChainConfig;
|
|
9
|
+
onChainId?: (chainId: number | null) => void;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
export declare function resolveWalletSession(args?: {
|
|
12
|
+
provider?: Eip1193Provider | null;
|
|
13
|
+
account?: Address | string | null;
|
|
14
|
+
getProvider?: AegisSwapProviderResolver;
|
|
15
|
+
connectWallet?: () => Promise<AegisSwapWalletConnection | void>;
|
|
16
|
+
requestAccount?: boolean;
|
|
17
|
+
}): Promise<WalletSession>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
export declare function addressKey(address: Address | null | undefined): string;
|
|
3
|
+
export declare function sameAddress(a: Address, b: Address): boolean;
|
|
4
|
+
export declare function sameOptionalAddress(a: Address | null, b: Address | null): boolean;
|
|
5
|
+
export declare function samePoolId(a: Hex, b: Hex): boolean;
|