@aegis-engine/core 0.7.0 → 0.8.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.
Files changed (74) hide show
  1. package/README.md +215 -7
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/dist/account.d.ts +11 -0
  4. package/dist/account.js +129 -0
  5. package/dist/actions/allowance.d.ts +94 -0
  6. package/dist/actions/directPoolSwap.d.ts +8 -1
  7. package/dist/actions/kyberSwap.d.ts +1 -0
  8. package/dist/actions/types.d.ts +2 -0
  9. package/dist/actions/wallet.d.ts +1 -0
  10. package/dist/aegis-core.js +9654 -205
  11. package/dist/backendAdapters.d.ts +3 -1
  12. package/dist/config/chains.d.ts +1 -0
  13. package/dist/config/constants.d.ts +4 -0
  14. package/dist/config/tokens.d.ts +2 -1
  15. package/dist/config/types.d.ts +8 -0
  16. package/dist/contract/backendClient.d.ts +3 -1
  17. package/dist/contract/generated/aegis-swap.d.ts +6337 -1377
  18. package/dist/contract/generated/market-data.d.ts +8286 -0
  19. package/dist/contract/index.d.ts +1 -0
  20. package/dist/contract/responseBudget.d.ts +9 -0
  21. package/dist/contract/schemas.d.ts +13 -3
  22. package/dist/engine/account/accounting.d.ts +24 -0
  23. package/dist/engine/account/accountingSchemas.d.ts +2056 -0
  24. package/dist/engine/account/activity.d.ts +42 -0
  25. package/dist/engine/account/activitySchemas.d.ts +327 -0
  26. package/dist/engine/account/amountSchemas.d.ts +9 -0
  27. package/dist/engine/account/catalogSchemas.d.ts +108 -0
  28. package/dist/engine/account/client.d.ts +14 -0
  29. package/dist/engine/account/history.d.ts +40 -0
  30. package/dist/engine/account/historySchemas.d.ts +251 -0
  31. package/dist/engine/account/management.d.ts +13 -0
  32. package/dist/engine/account/portfolioSchemas.d.ts +712 -0
  33. package/dist/engine/account/positionPerformance.d.ts +18 -0
  34. package/dist/engine/account/positionPerformanceSchemas.d.ts +101 -0
  35. package/dist/engine/account/positionPnl.d.ts +18 -0
  36. package/dist/engine/account/positionPnlSchemas.d.ts +149 -0
  37. package/dist/engine/account/transactionHistory.d.ts +50 -0
  38. package/dist/engine/account/transactionSchemas.d.ts +101 -0
  39. package/dist/engine/account/transactions.d.ts +26 -0
  40. package/dist/engine/account/transport.d.ts +31 -0
  41. package/dist/engine/account/types.d.ts +39 -0
  42. package/dist/engine/actions.d.ts +8 -3
  43. package/dist/engine/adaptiveFee.d.ts +14 -0
  44. package/dist/engine/balancedLending.d.ts +82 -0
  45. package/dist/engine/dataSource.d.ts +2 -0
  46. package/dist/engine/index.d.ts +19 -0
  47. package/dist/engine/marketAdapter.d.ts +3 -0
  48. package/dist/engine/marketSeries.d.ts +61 -0
  49. package/dist/engine/marketSeriesSchemas.d.ts +312 -0
  50. package/dist/engine/marketTrust.d.ts +26 -0
  51. package/dist/engine/openingEntry.d.ts +41 -0
  52. package/dist/engine/rateHistorySchemas.d.ts +88 -0
  53. package/dist/engine/reads.d.ts +1 -1
  54. package/dist/engine/registry.d.ts +1 -1
  55. package/dist/engine/restSchemas.d.ts +59 -1
  56. package/dist/engine/tradeExecutionSession.d.ts +155 -0
  57. package/dist/engine/types.d.ts +128 -14
  58. package/dist/engine/v4Quote.d.ts +5 -0
  59. package/dist/index.d.ts +11 -7
  60. package/dist/internal/guardedWalletTransaction.d.ts +31 -0
  61. package/dist/permit.d.ts +80 -7
  62. package/dist/quote/aggregatedSwapQuote.d.ts +5 -1
  63. package/dist/quote/kyberCalldata.d.ts +5 -1
  64. package/dist/{sdkRuntime-BE3ZMb5o.js → sdkRuntime-3aRt_g55.js} +3385 -2958
  65. package/dist/services/kyberSwap.d.ts +12 -0
  66. package/dist/swap/authorizePermit.d.ts +11 -9
  67. package/dist/swap/executeSwapTransaction.d.ts +5 -1
  68. package/dist/swap/receiptWait.d.ts +9 -0
  69. package/dist/swap/sendSwapTransaction.d.ts +7 -0
  70. package/dist/swap/trustedMarket.d.ts +25 -0
  71. package/dist/transactionHistory-1Zl2KCcV.js +5915 -0
  72. package/dist/wallet.d.ts +4 -0
  73. package/package.json +12 -5
  74. package/dist/index-DofKgro2.js +0 -11201
@@ -0,0 +1,31 @@
1
+ import type { Chain, Hex, PublicClient, TransactionReceipt } from 'viem';
2
+ import { type Eip1193Provider } from '../wallet.js';
3
+ import { type AegisTransactionObservation } from '../swap/receiptWait.js';
4
+ /**
5
+ * Sends one already-prepared wallet transaction through the safety boundary
6
+ * shared by swaps and authorization writes.
7
+ *
8
+ * Preparation and simulation stay with the caller. This helper owns the
9
+ * invariants that begin immediately before the wallet prompt: verify the
10
+ * active chain, honor cancellation until a hash exists, publish submitted and
11
+ * replacement hashes without trusting host callbacks, and reconcile the
12
+ * receipt. Once submitted, caller cancellation cannot hide the mined result.
13
+ */
14
+ export declare function runGuardedWalletTransaction(args: {
15
+ provider: Eip1193Provider;
16
+ publicClient: PublicClient;
17
+ chain: Chain;
18
+ signal?: AbortSignal;
19
+ timeoutMs: number;
20
+ submit: () => Promise<Hex>;
21
+ unreadableChainMessage: string;
22
+ cancelledMessage: string;
23
+ revertedMessage: string;
24
+ onWalletRequest?: () => void;
25
+ onHash?: (hash: Hex, replacement?: {
26
+ replacesHash: Hex;
27
+ executionChanged: boolean;
28
+ }) => void;
29
+ onTransactionObservation?: (event: AegisTransactionObservation) => void;
30
+ onSubmitted?: (hash: Hex) => void;
31
+ }): Promise<TransactionReceipt>;
package/dist/permit.d.ts CHANGED
@@ -1,8 +1,20 @@
1
1
  import { type Address, type Chain, type Hex, type PublicClient } from 'viem';
2
- import type { Eip1193Provider } from './wallet.js';
2
+ import { type Eip1193Provider } from './wallet.js';
3
3
  import type { SignedPermitBatch } from './encoding.js';
4
4
  export declare const MAX_UINT160: bigint;
5
5
  export declare const MAX_UINT256: bigint;
6
+ /** "No limit" only counts once the standing grant still reads as effectively
7
+ * unlimited. Half the type maximum tolerates tokens and Permit2 flows that
8
+ * decrement a max grant on spend — an equality test against the maximum would
9
+ * re-approve before every swap — while an exact-sized allowance, however large
10
+ * against today's amount, never qualifies. */
11
+ export declare const UNLIMITED_ERC20_FLOOR: bigint;
12
+ export declare const UNLIMITED_PERMIT2_FLOOR: bigint;
13
+ /** Whether an ERC-20 grant reads as "no limit" rather than a number worth
14
+ * showing — formatting the integer yields a quantity nobody can read. */
15
+ export declare function isUnlimitedErc20Approval(amount: bigint): boolean;
16
+ /** The Permit2 counterpart, against the uint160 wire type's own floor. */
17
+ export declare function isUnlimitedPermit2Approval(amount: bigint): boolean;
6
18
  export declare const SWAP_TX_DEADLINE_SECONDS = 600;
7
19
  export declare const DEFAULT_PERMIT_EXPIRATION_SECONDS: number;
8
20
  export declare const PERMIT2_FAR_FUTURE_EXPIRATION: number;
@@ -14,8 +26,14 @@ export declare function approveErc20ToPermit2(args: {
14
26
  token: Address;
15
27
  permit2: Address;
16
28
  amount?: bigint;
29
+ /** Stops preparation before the approval is handed to the wallet. */
30
+ signal?: AbortSignal;
17
31
  onWalletRequest?: () => void;
18
- onHash?: (hash: Hex) => void;
32
+ onHash?: (hash: Hex, replacement?: {
33
+ replacesHash: Hex;
34
+ executionChanged: boolean;
35
+ }) => void;
36
+ onSubmitted?: (hash: Hex) => void;
19
37
  }): Promise<Hex>;
20
38
  export declare function readErc20Allowance(args: {
21
39
  publicClient: PublicClient;
@@ -30,9 +48,25 @@ export declare function approveErc20Spender(args: {
30
48
  chain: Chain;
31
49
  token: Address;
32
50
  spender: Address;
33
- onHash?: (hash: Hex) => void;
34
51
  amount?: bigint;
52
+ /** Stops preparation before the approval is handed to the wallet. */
53
+ signal?: AbortSignal;
54
+ onWalletRequest?: () => void;
55
+ onHash?: (hash: Hex, replacement?: {
56
+ replacesHash: Hex;
57
+ executionChanged: boolean;
58
+ }) => void;
59
+ onSubmitted?: (hash: Hex) => void;
35
60
  }): Promise<Hex>;
61
+ /**
62
+ * Installs a Permit2 -> router spending cap on-chain: the fallback for wallets
63
+ * whose typed-data signature Permit2 will not accept.
64
+ *
65
+ * `amount` follows the same convention as the ERC-20 writers above — omitted
66
+ * means maximum authority (MAX_UINT160), and an explicit `0n` revokes. Anything
67
+ * wider than the uint160 wire type is clamped. `expiration` defaults to
68
+ * Permit2's far-future sentinel.
69
+ */
36
70
  export declare function approvePermit2ToRouter(args: {
37
71
  provider: Eip1193Provider;
38
72
  publicClient: PublicClient;
@@ -43,8 +77,14 @@ export declare function approvePermit2ToRouter(args: {
43
77
  router: Address;
44
78
  amount?: bigint;
45
79
  expiration?: number;
80
+ /** Stops preparation before the approval is handed to the wallet. */
81
+ signal?: AbortSignal;
46
82
  onWalletRequest?: () => void;
47
- onHash?: (hash: Hex) => void;
83
+ onHash?: (hash: Hex, replacement?: {
84
+ replacesHash: Hex;
85
+ executionChanged: boolean;
86
+ }) => void;
87
+ onSubmitted?: (hash: Hex) => void;
48
88
  }): Promise<Hex>;
49
89
  export declare function readPermit2RouterAllowance(args: {
50
90
  publicClient: PublicClient;
@@ -53,7 +93,36 @@ export declare function readPermit2RouterAllowance(args: {
53
93
  token: Address;
54
94
  router: Address;
55
95
  }): Promise<readonly [amount: bigint, expiration: number, nonce: number]>;
56
- export declare function hasUsablePermit2Allowance(allowance: Awaited<ReturnType<typeof readPermit2RouterAllowance>>, amount: bigint): boolean;
96
+ export declare function hasUsablePermit2Allowance(allowance: Awaited<ReturnType<typeof readPermit2RouterAllowance>>, amount: bigint, sizing?: 'exact' | 'max'): boolean;
97
+ /**
98
+ * True only when Permit2's own `SignatureVerification` would accept this
99
+ * signature. It branches on the owner's code, not on the signature's shape: an
100
+ * address with code is checked through ERC-1271 alone, with no ecrecover
101
+ * fallback, so an EIP-7702-delegated EOA whose delegate does not implement
102
+ * `isValidSignature` rejects the ordinary 65-byte signature its own key just
103
+ * produced. A codeless owner takes the other branch and reverts on any length
104
+ * other than 64 or 65, which is where an ERC-6492 wrapper from an undeployed
105
+ * smart account dies.
106
+ *
107
+ * viem's `verifyTypedData` is used only for the codeless branch it models
108
+ * exactly, in `eoa` mode: its default `auto` mode opens with an `eth_call` that
109
+ * deploys viem's ERC-6492 validator, a blocking round trip sitting between the
110
+ * wallet signature and the submit on every ordinary swap.
111
+ *
112
+ * `false` means the owner refused, never "the check could not run": an RPC
113
+ * failure throws so the caller cannot mistake it for an unsignable wallet.
114
+ */
115
+ export declare function isPermit2AcceptableSignature(args: {
116
+ publicClient: PublicClient;
117
+ chainId: number;
118
+ permit2: Address;
119
+ signed: SignedPermitBatch;
120
+ /**
121
+ * The owner's deployed code, read by the caller so a failed read propagates
122
+ * instead of arriving here as a `false`.
123
+ */
124
+ ownerCode: Hex | undefined;
125
+ }): Promise<boolean>;
57
126
  export declare function buildSignedPermitBatch(args: {
58
127
  provider: Eip1193Provider;
59
128
  publicClient: PublicClient;
@@ -67,11 +136,15 @@ export declare function buildSignedPermitBatch(args: {
67
136
  /**
68
137
  * 'max' signs a MAX_UINT160 permit (still expiring in 30 minutes) so quick
69
138
  * follow-up swaps reuse it instead of prompting for a new signature each
70
- * time — Permit2 decrements exact-sized permits to zero on transfer.
71
- * Defaults to 'exact'.
139
+ * time — Permit2 decrements exact-sized permits to zero on transfer. It also
140
+ * re-signs over a merely amount-covering standing cap, because that cap is
141
+ * not the unlimited authority 'max' asked for. Defaults to 'exact'.
72
142
  */
73
143
  sizing?: 'exact' | 'max';
74
144
  /** Pre-started readPermit2RouterAllowance result to overlap with other RPC work. */
75
145
  allowanceRead?: ReturnType<typeof readPermit2RouterAllowance>;
146
+ /** Stops preparation before typed data is handed to the wallet. */
147
+ signal?: AbortSignal;
148
+ /** Fires only when a new typed-data signature is actually requested. */
76
149
  onWalletRequest?: () => void;
77
150
  }): Promise<SignedPermitBatch | null>;
@@ -13,5 +13,9 @@ export declare class AggregatedSwapBuildMismatchError extends UserFacingError {
13
13
  actual: bigint;
14
14
  });
15
15
  }
16
+ /** Absolute settlement floor established by the quote the user approved. */
17
+ export type AggregatedSwapExecutionIntent = Readonly<{
18
+ reviewedAmountOutMinimum: bigint;
19
+ }>;
16
20
  export declare function assertAggregatedRouterTrusted(router: Address, chainId: number): void;
17
- export declare function fetchAggregatedSwapQuote(inputToken: AegisSwapToken, outputToken: AegisSwapToken, amount: bigint, slippageBps: number, mode?: 'exactIn' | 'exactOut', account?: Address | null, signal?: AbortSignal, _publicClient?: PublicClient): Promise<AggregatedSwapQuote>;
21
+ export declare function fetchAggregatedSwapQuote(inputToken: AegisSwapToken, outputToken: AegisSwapToken, amount: bigint, slippageBps: number, mode?: 'exactIn' | 'exactOut', account?: Address | null, signal?: AbortSignal, _publicClient?: PublicClient, executionIntent?: AggregatedSwapExecutionIntent): Promise<AggregatedSwapQuote>;
@@ -189,6 +189,10 @@ export declare const KYBER_META_AGGREGATION_ROUTER_V2_ABI: readonly [{
189
189
  readonly type: "uint256";
190
190
  }];
191
191
  }];
192
+ export type KyberSettlementFeePolicy = Readonly<{
193
+ receiver: Address;
194
+ feeBps: number;
195
+ }>;
192
196
  export declare class AggregatedSwapCalldataError extends UserFacingError {
193
197
  readonly reason: string;
194
198
  constructor(reason: string);
@@ -207,5 +211,5 @@ export declare function assertKyberCalldataMatchesQuote(args: {
207
211
  recipient: Address;
208
212
  /** Lowest acceptable value for the calldata's embedded minReturnAmount. */
209
213
  minReturnFloor: bigint;
210
- feeRecipient: Address | null;
214
+ feePolicy: KyberSettlementFeePolicy | null;
211
215
  }): void;