@aegis-engine/core 0.4.0 → 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.
@@ -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
  *
@@ -30,6 +43,8 @@ export declare function sendGuardedTransactionAndAwait(args: {
30
43
  data: Hex;
31
44
  value: bigint;
32
45
  gas?: bigint;
46
+ /** Cancels only before a transaction hash exists. */
47
+ signal?: AbortSignal;
33
48
  cancelledMessage: string;
34
49
  revertedMessage: string;
35
50
  onHash?: (hash: Hex | null) => void;
@@ -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
@@ -29,6 +29,24 @@ export type AegisSwapWalletPromptProgress = {
29
29
  /** 1-based prompt currently awaiting the wallet; null while idle/mining/terminal. */
30
30
  active: number | null;
31
31
  };
32
+ /** Immutable token identity recorded when the swap transaction is broadcast. */
33
+ export type AegisSwapStatusTransactionToken = {
34
+ address: Address;
35
+ symbol: string;
36
+ };
37
+ /**
38
+ * Immutable execution identity attached to status snapshots once a transaction
39
+ * hash exists. Hosts can keep rendering and indexing the submitted swap even
40
+ * if controlled chain, account, or market props change while it confirms.
41
+ */
42
+ export type AegisSwapStatusTransactionContext = {
43
+ hash: Hex;
44
+ chainId: number;
45
+ account: Address;
46
+ inputToken: AegisSwapStatusTransactionToken;
47
+ outputToken: AegisSwapStatusTransactionToken;
48
+ explorerUrl: string | null;
49
+ };
32
50
  export type TransactionProgressView = {
33
51
  state: TransactionProgressState;
34
52
  label: string;
@@ -38,14 +56,28 @@ export type TransactionProgressView = {
38
56
  /** Visual activity layer width; pending/mining sweeps full-width by default. */
39
57
  activeWidthPct: number;
40
58
  };
41
- export declare function transactionProgressView({ status, inputSymbol, txHash, actionError, approvalRequired, approvalDone, authorizationRequired }: {
59
+ export declare function transactionProgressView({ status, inputSymbol, txHash, transactionStage, actionError, approvalRequired, approvalDone, resetRequired, approvalsCompleted, authorizationRequired, authorizationPrompts, authorizationsCompleted }: {
42
60
  status: SubmitStatus;
43
61
  inputSymbol: string;
44
62
  txHash: Hex | null;
63
+ /** Which submitted transaction owns txHash during receipt recovery. */
64
+ transactionStage?: 'permission' | 'swap' | null;
45
65
  actionError: string | null;
46
66
  approvalRequired: boolean;
47
67
  approvalDone: boolean;
68
+ /** Whether the approval spends an extra approve(0) prompt first. */
69
+ resetRequired?: boolean;
70
+ /**
71
+ * Approval prompts already confirmed on-chain, from the executor's
72
+ * onApprovalProgress. Only read while approving — the later phases place the
73
+ * approval step behind them regardless.
74
+ */
75
+ approvalsCompleted?: number;
48
76
  authorizationRequired: boolean;
77
+ /** Executor-reported Permit2 prompts; overrides the boolean prediction. */
78
+ authorizationPrompts?: number;
79
+ /** Permit2 authorization prompts already completed by the wallet. */
80
+ authorizationsCompleted?: number;
49
81
  }): TransactionProgressView | null;
50
82
  export type AegisSwapStatusSnapshot = {
51
83
  status: SubmitStatus;
@@ -58,5 +90,11 @@ export type AegisSwapStatusSnapshot = {
58
90
  completePct: number | null;
59
91
  activeWidthPct: number | null;
60
92
  txHash: Hex | null;
93
+ /**
94
+ * Submission-time chain, account, and asset identity for `txHash`. Null
95
+ * before broadcast. Optional so existing host-authored snapshot fixtures
96
+ * remain source-compatible.
97
+ */
98
+ transaction?: AegisSwapStatusTransactionContext | null;
61
99
  error: string | null;
62
100
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aegis-engine/core",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "React-free Aegis Swap and Engine quoting, risk, approval, and execution operations.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -57,6 +57,7 @@
57
57
  "typecheck": "tsc -p tsconfig.build.json --noEmit",
58
58
  "typecheck:test": "tsc -p tsconfig.test.json --noEmit",
59
59
  "test": "vitest run",
60
+ "test:fork": "vitest run --config vitest.fork.config.ts",
60
61
  "build": "vite build && tsc -p tsconfig.build.json && node ../../scripts/fix-dts-imports.mjs ."
61
62
  }
62
63
  }