@aegis-engine/core 0.5.0 → 0.7.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.
@@ -3,6 +3,7 @@ import type { AegisSwapChainConfig } from '../config/index.js';
3
3
  import type { SignedPermitBatch } from '../encoding.js';
4
4
  import { readPermit2RouterAllowance } from '../permit.js';
5
5
  import type { SubmitStatus } from '../transactionProgress.js';
6
+ import type { AegisSwapAuthorizationProgress } from '../actions/types.js';
6
7
  import type { AegisSwapApprovalMode, WalletSession } from './types.js';
7
8
  /**
8
9
  * Produces the Permit2 authorization the swap calldata needs.
@@ -15,7 +16,7 @@ import type { AegisSwapApprovalMode, WalletSession } from './types.js';
15
16
  * would have carried, and this returns `null` so the swap proceeds without an
16
17
  * inline permit. A user rejection is rethrown untouched.
17
18
  */
18
- export declare function authorizePermit({ wallet, publicClient, activeChain, permit2, router, token, amount, approvalMode, allowanceRead, setStatus }: {
19
+ export declare function authorizePermit({ wallet, publicClient, activeChain, permit2, router, token, amount, approvalMode, allowanceRead, setStatus, onAuthorizationProgress, onWalletRequest, onHash }: {
19
20
  wallet: WalletSession;
20
21
  publicClient: PublicClient;
21
22
  activeChain: AegisSwapChainConfig;
@@ -26,4 +27,7 @@ export declare function authorizePermit({ wallet, publicClient, activeChain, per
26
27
  approvalMode: AegisSwapApprovalMode;
27
28
  allowanceRead: ReturnType<typeof readPermit2RouterAllowance>;
28
29
  setStatus: (status: SubmitStatus) => void;
30
+ onAuthorizationProgress?: (progress: AegisSwapAuthorizationProgress) => void;
31
+ onWalletRequest?: () => void;
32
+ onHash?: (hash: import('viem').Hex) => void;
29
33
  }): Promise<SignedPermitBatch | null>;
@@ -4,9 +4,9 @@ export declare const SWAP_RECEIPT_TIMEOUT_MS: number;
4
4
  type OnReplacedParameter = NonNullable<Parameters<PublicClient['waitForTransactionReceipt']>[0]['onReplaced']>;
5
5
  /**
6
6
  * waitForTransactionReceipt with a hard timeout, mapping viem's timeout error
7
- * to the SDK's TransactionReceiptTimeoutError (which carries the tx hash so
8
- * the UI can degrade to an explorer link). Every other failure passes through
9
- * untouched.
7
+ * to a submitted-receipt error carrying the latest hash. Terminal replacement
8
+ * and revert errors remain terminal; every unresolved RPC failure stays
9
+ * receipt-recoverable instead of making the original call safe to resend.
10
10
  */
11
11
  export declare function waitForReceiptWithTimeout(args: {
12
12
  publicClient: PublicClient;
@@ -14,4 +14,27 @@ export declare function waitForReceiptWithTimeout(args: {
14
14
  timeoutMs: number;
15
15
  onReplaced?: OnReplacedParameter;
16
16
  }): Promise<TransactionReceipt>;
17
+ export type SubmittedReceiptOutcome = Readonly<{
18
+ status: 'confirmed' | 'reverted' | 'cancelled';
19
+ hash: Hex;
20
+ replacesHash?: Hex;
21
+ receipt: TransactionReceipt;
22
+ }> | Readonly<{
23
+ status: 'unresolved';
24
+ hash: Hex;
25
+ replacesHash?: Hex;
26
+ }>;
27
+ /**
28
+ * Reconciles one already-submitted transaction without any broadcast path.
29
+ *
30
+ * A speed-up (`repriced`) preserves the submitted call. A generic same-nonce
31
+ * replacement or wallet cancellation does not, so even a successful receipt
32
+ * for either is reported as cancelled. RPC and timeout failures stay
33
+ * unresolved because the original transaction may still mine.
34
+ */
35
+ export declare function reconcileSubmittedReceipt(args: {
36
+ publicClient: Pick<PublicClient, 'waitForTransactionReceipt'>;
37
+ hash: Hex;
38
+ timeoutMs: number;
39
+ }): Promise<SubmittedReceiptOutcome>;
17
40
  export {};
@@ -2,6 +2,19 @@ import { type Address, type Chain, type Hex, type PublicClient, type Transaction
2
2
  import type { AegisSwapReceiptSummary } from '../transactionProgress.js';
3
3
  import { type SwapSettlementContext } from './settlement.js';
4
4
  import type { AegisSwapSubmitDetails, WalletSession } from './types.js';
5
+ /**
6
+ * Settlement facts (gas, block, fee) lifted off a mined receipt.
7
+ *
8
+ * viem types gasUsed/effectiveGasPrice as required bigints, but a non-EIP-1559
9
+ * chain or a lean RPC can omit them; fall back to 0n so the summary degrades
10
+ * gracefully (the view hides zero rows) instead of throwing.
11
+ */
12
+ export declare function summarizeTransactionReceipt(receipt: {
13
+ transactionHash: Hex;
14
+ blockNumber?: bigint;
15
+ gasUsed?: bigint;
16
+ effectiveGasPrice?: bigint;
17
+ }): AegisSwapReceiptSummary;
5
18
  /**
6
19
  * Guarded send pipeline shared by the swap and engine planes.
7
20
  *
@@ -4,6 +4,7 @@ export type SwapSettlementContext = {
4
4
  recipient: Address;
5
5
  /** Output token address; zero address or the 0xEeee… sentinel means native. */
6
6
  outputToken: Address;
7
+ inputToken?: Address;
7
8
  };
8
9
  /**
9
10
  * Best-effort decode of what the swap actually settled to the recipient:
@@ -13,3 +14,6 @@ export type SwapSettlementContext = {
13
14
  * never failed retroactively over display data.
14
15
  */
15
16
  export declare function resolveSettledAmountOut(publicClient: PublicClient, receipt: TransactionReceipt, settlement: SwapSettlementContext): Promise<bigint | undefined>;
17
+ /** Receipt-local input transfers, net of token refunds. Native spends have no
18
+ * Transfer logs and remain unknown here rather than using a block balance guess. */
19
+ export declare function resolveSettledAmountIn(receipt: TransactionReceipt, settlement: SwapSettlementContext): bigint | undefined;
@@ -1,4 +1,4 @@
1
- import type { Hex } from 'viem';
1
+ import type { Address, Hex } from 'viem';
2
2
  export type SubmitStatus = 'idle' | 'approving' | 'signing' | 'submitting' | 'success';
3
3
  /**
4
4
  * On-chain settlement facts pulled from the swap's mined receipt. Raw base
@@ -19,6 +19,8 @@ export type AegisSwapReceiptSummary = {
19
19
  * case UIs should keep showing the quote estimate with a "~" affordance.
20
20
  */
21
21
  settledAmountOut?: bigint;
22
+ /** Net input-token transfers from the payer in this receipt, after refunds. */
23
+ settledAmountIn?: bigint;
22
24
  };
23
25
  export declare function isBusy(status: SubmitStatus): boolean;
24
26
  export type TransactionProgressState = 'pending' | 'mining' | 'success' | 'error';
@@ -29,23 +31,87 @@ export type AegisSwapWalletPromptProgress = {
29
31
  /** 1-based prompt currently awaiting the wallet; null while idle/mining/terminal. */
30
32
  active: number | null;
31
33
  };
34
+ /** Immutable token identity recorded when the swap transaction is broadcast. */
35
+ export type AegisSwapStatusTransactionToken = {
36
+ address: Address;
37
+ symbol: string;
38
+ };
39
+ /**
40
+ * Immutable execution identity attached to status snapshots once a transaction
41
+ * hash exists. Hosts can keep rendering and indexing the submitted swap even
42
+ * if controlled chain, account, or market props change while it confirms.
43
+ */
44
+ export type AegisSwapStatusTransactionContext = {
45
+ hash: Hex;
46
+ chainId: number;
47
+ account: Address;
48
+ inputToken: AegisSwapStatusTransactionToken;
49
+ outputToken: AegisSwapStatusTransactionToken;
50
+ explorerUrl: string | null;
51
+ };
32
52
  export type TransactionProgressView = {
33
53
  state: TransactionProgressState;
34
54
  label: string;
35
55
  walletPrompts: AegisSwapWalletPromptProgress;
36
- /** Calm fill showing completed wallet-provider prompts. */
56
+ /** Calm fill showing settled rail steps; the final action settles on receipt. */
37
57
  completePct: number;
38
58
  /** Visual activity layer width; pending/mining sweeps full-width by default. */
39
59
  activeWidthPct: number;
60
+ /**
61
+ * Steps the rail divides itself into, so a three-step flow reads
62
+ * 33/66/100 instead of one indivisible half. Presentation only, and separate
63
+ * from `walletPrompts`: the Engine counts settlement steps it can name, not
64
+ * provider prompts it cannot predict. Absent when the total is not known
65
+ * before the first prompt — the rail then stays one continuous bar rather
66
+ * than inventing a denominator that could grow mid-flight.
67
+ */
68
+ steps?: number;
69
+ };
70
+ /**
71
+ * Chips the top rail divides itself into. Explicit settlement steps when a
72
+ * producer counts them, else the wallet-prompt plan — which is the swap path's
73
+ * step count already. Fewer than two is not a division worth drawing, so the
74
+ * rail stays one continuous bar. Where along those chips the bar sits comes
75
+ * from `completePct`, so only the count is needed here.
76
+ */
77
+ export declare function progressRailSteps(view: TransactionProgressView | null | undefined): number | undefined;
78
+ export declare function normalizeProgressCount(value: number): number;
79
+ /** Shared geometry for every widget and host rail. The final action is only
80
+ * complete after confirmation, even if every wallet prompt has finished. */
81
+ export declare function transactionSequenceProgress({ total, completed, confirmed }: {
82
+ total: number;
83
+ completed: number;
84
+ confirmed?: boolean;
85
+ }): {
86
+ total: number;
87
+ completed: number;
88
+ completePct: number;
89
+ steps?: number;
40
90
  };
41
- export declare function transactionProgressView({ status, inputSymbol, txHash, actionError, approvalRequired, approvalDone, authorizationRequired }: {
91
+ export declare function transactionProgressView({ status, inputSymbol, txHash, transactionStage, actionError, approvalRequired, approvalPrompts, approvalDone, resetRequired, approvalsCompleted, authorizationRequired, authorizationPrompts, authorizationsCompleted }: {
42
92
  status: SubmitStatus;
43
93
  inputSymbol: string;
44
94
  txHash: Hex | null;
95
+ /** Which submitted transaction owns txHash during receipt recovery. */
96
+ transactionStage?: 'permission' | 'swap' | null;
45
97
  actionError: string | null;
46
98
  approvalRequired: boolean;
99
+ /** Explicit executor plan, including every prerequisite approval. */
100
+ approvalPrompts?: number;
47
101
  approvalDone: boolean;
102
+ /** Whether the approval spends an extra approve(0) prompt first. */
103
+ resetRequired?: boolean;
104
+ /**
105
+ * Approval prompts already confirmed on-chain, from the executor's
106
+ * onApprovalProgress. Only read while approving — the later phases place the
107
+ * approval step behind them regardless.
108
+ */
109
+ approvalsCompleted?: number;
48
110
  authorizationRequired: boolean;
111
+ /** Executor-reported Permit2 prompts; overrides the boolean prediction. */
112
+ authorizationPrompts?: number;
113
+ /** Permit2 authorization prompts already completed by the wallet. */
114
+ authorizationsCompleted?: number;
49
115
  }): TransactionProgressView | null;
50
116
  export type AegisSwapStatusSnapshot = {
51
117
  status: SubmitStatus;
@@ -57,6 +123,17 @@ export type AegisSwapStatusSnapshot = {
57
123
  /** Rail geometry; null while idle. */
58
124
  completePct: number | null;
59
125
  activeWidthPct: number | null;
126
+ /**
127
+ * Segmented rail chip count; null for a continuous or hidden rail.
128
+ * Optional so existing host-authored snapshot fixtures may omit it.
129
+ */
130
+ steps?: number | null;
60
131
  txHash: Hex | null;
132
+ /**
133
+ * Submission-time chain, account, and asset identity for `txHash`. Null
134
+ * before broadcast. Optional so existing host-authored snapshot fixtures
135
+ * remain source-compatible.
136
+ */
137
+ transaction?: AegisSwapStatusTransactionContext | null;
61
138
  error: string | null;
62
139
  };
package/dist/wallet.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare function getProviderAccount(provider: Eip1193Provider): Promise<A
27
27
  export declare function requestProviderAccount(provider: Eip1193Provider): Promise<Address | null>;
28
28
  export declare function getProviderChainId(provider: Eip1193Provider): Promise<number | null>;
29
29
  export declare function switchProviderChain(provider: Eip1193Provider, chain: number | ProviderChainConfig): Promise<void>;
30
- export declare function createSwapPublicClient(chain: Chain, rpcUrls: readonly string[]): PublicClient;
30
+ export declare function createSwapPublicClient(chain: Chain, rpcUrls: readonly string[], readProvider?: Eip1193Provider): PublicClient;
31
31
  export declare function subscribeProvider(provider: Eip1193Provider, handlers: {
32
32
  onAccountsChanged?: () => void;
33
33
  onChainChanged?: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aegis-engine/core",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "React-free Aegis Swap and Engine quoting, risk, approval, and execution operations.",
5
5
  "license": "MIT",
6
6
  "type": "module",