@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/dist/config.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type Address, type Chain, type Hex } from 'viem';
|
|
2
|
+
export type AegisSwapBuiltInTokenSymbol = 'USDC' | 'WATER' | 'WOOD' | 'GRASS' | 'STONE';
|
|
3
|
+
export type AegisSwapBuiltInAssetSymbol = Exclude<AegisSwapBuiltInTokenSymbol, 'USDC'>;
|
|
4
|
+
export type AegisSwapBuiltInMarketId = 'WATER_USDC' | 'WOOD_USDC' | 'GRASS_USDC' | 'STONE_USDC';
|
|
5
|
+
export type AegisSwapTokenSymbol = string;
|
|
6
|
+
export type AegisSwapFeeConfig = {
|
|
7
|
+
bps: number;
|
|
8
|
+
recipient: Address;
|
|
9
|
+
};
|
|
10
|
+
export type AegisSwapToken = {
|
|
11
|
+
chainId: number;
|
|
12
|
+
address: Address;
|
|
13
|
+
name: string;
|
|
14
|
+
symbol: AegisSwapTokenSymbol;
|
|
15
|
+
decimals: number;
|
|
16
|
+
iconUrl?: string | null;
|
|
17
|
+
};
|
|
18
|
+
export type AegisPoolKey = {
|
|
19
|
+
currency0: Address;
|
|
20
|
+
currency1: Address;
|
|
21
|
+
fee: number;
|
|
22
|
+
tickSpacing: number;
|
|
23
|
+
hooks: Address;
|
|
24
|
+
};
|
|
25
|
+
export type AegisSwapUniswapV4Contracts = {
|
|
26
|
+
permit2: Address;
|
|
27
|
+
quoter: Address;
|
|
28
|
+
poolManager?: Address;
|
|
29
|
+
positionDescriptor?: Address;
|
|
30
|
+
positionManager?: Address;
|
|
31
|
+
stateView?: Address;
|
|
32
|
+
universalRouter?: Address;
|
|
33
|
+
universalRouterV2_1_1?: Address;
|
|
34
|
+
};
|
|
35
|
+
export type AegisSwapUniswapV4ContractsInput = Partial<AegisSwapUniswapV4Contracts>;
|
|
36
|
+
export type AegisSwapMarket = {
|
|
37
|
+
id: string;
|
|
38
|
+
chainId: number;
|
|
39
|
+
symbol: AegisSwapTokenSymbol;
|
|
40
|
+
poolId: Hex;
|
|
41
|
+
poolKey: AegisPoolKey;
|
|
42
|
+
token: AegisSwapToken;
|
|
43
|
+
counterToken: AegisSwapToken;
|
|
44
|
+
router: Address;
|
|
45
|
+
permit2: Address;
|
|
46
|
+
quoter: Address;
|
|
47
|
+
label?: string;
|
|
48
|
+
};
|
|
49
|
+
export type AegisSwapChainConfig = {
|
|
50
|
+
chainId: number;
|
|
51
|
+
chain: Chain;
|
|
52
|
+
name: string;
|
|
53
|
+
router: Address;
|
|
54
|
+
permit2: Address;
|
|
55
|
+
quoter: Address;
|
|
56
|
+
v4Contracts: AegisSwapUniswapV4Contracts;
|
|
57
|
+
rpcUrls: string[];
|
|
58
|
+
explorerTxUrl?: (hash: Hex) => string;
|
|
59
|
+
poolExplorerUrl?: (poolId: Hex, market: AegisSwapMarket) => string;
|
|
60
|
+
metadataEndpoint?: string | null;
|
|
61
|
+
fee?: AegisSwapFeeConfig;
|
|
62
|
+
};
|
|
63
|
+
export type AegisSwapChainConfigInput = Partial<Omit<AegisSwapChainConfig, 'chainId' | 'v4Contracts' | 'fee'>> & {
|
|
64
|
+
chainId?: number;
|
|
65
|
+
v4Contracts?: AegisSwapUniswapV4ContractsInput;
|
|
66
|
+
};
|
|
67
|
+
export declare function getExplorerUrl(hash: Hex, chain: AegisSwapChainConfig): string;
|
|
68
|
+
export type AegisSwapPoolConfig = {
|
|
69
|
+
id: string;
|
|
70
|
+
symbol?: AegisSwapTokenSymbol;
|
|
71
|
+
chainId?: number;
|
|
72
|
+
poolKey: AegisPoolKey;
|
|
73
|
+
poolId?: Hex;
|
|
74
|
+
token: AegisSwapToken;
|
|
75
|
+
counterToken: AegisSwapToken;
|
|
76
|
+
router?: Address;
|
|
77
|
+
permit2?: Address;
|
|
78
|
+
quoter?: Address;
|
|
79
|
+
label?: string;
|
|
80
|
+
};
|
|
81
|
+
export declare const AEGIS_SWAP_CHAIN_ID = 1;
|
|
82
|
+
export declare const AEGIS_SWAP_ROUTER: `0x${string}`;
|
|
83
|
+
export declare const AEGIS_SWAP_HOOK: `0x${string}`;
|
|
84
|
+
export declare const AEGIS_DYNAMIC_FEE_FLAG = 8388608;
|
|
85
|
+
export declare const AEGIS_SWAP_DEFAULT_FEE_BPS = 50;
|
|
86
|
+
export declare const AEGIS_SWAP_DEFAULT_FEE_RECIPIENT: `0x${string}`;
|
|
87
|
+
export declare function createAegisSwapUniswapV4Contracts(input: AegisSwapUniswapV4ContractsInput): AegisSwapUniswapV4Contracts;
|
|
88
|
+
export declare const UNISWAP_V4_CONTRACTS_BY_CHAIN: Record<number, AegisSwapUniswapV4Contracts>;
|
|
89
|
+
export declare const AEGIS_SWAP_MAINNET_UNISWAP_V4_CONTRACTS: AegisSwapUniswapV4Contracts;
|
|
90
|
+
export declare const AEGIS_SWAP_PERMIT2: `0x${string}`;
|
|
91
|
+
export declare const AEGIS_SWAP_V4_QUOTER: `0x${string}`;
|
|
92
|
+
export declare const AEGIS_SWAP_DEFAULT_RPC_URLS: string[];
|
|
93
|
+
export declare const AEGIS_SWAP_DEFAULT_METADATA_ENDPOINT = "https://aegis.markets/graphql/meta";
|
|
94
|
+
export declare const AEGIS_SWAP_MAINNET_CHAIN: AegisSwapChainConfig;
|
|
95
|
+
export declare const AEGIS_SWAP_CHAINS: Record<number, AegisSwapChainConfig>;
|
|
96
|
+
export declare const AEGIS_SWAP_TOKENS: Record<AegisSwapBuiltInTokenSymbol, AegisSwapToken>;
|
|
97
|
+
export declare const AEGIS_SWAP_MARKETS: Record<AegisSwapBuiltInMarketId, AegisSwapMarket>;
|
|
98
|
+
export declare const AEGIS_SWAP_DEFAULT_POOL_IDS: AegisSwapBuiltInMarketId[];
|
|
99
|
+
export declare const AGGREGATED_SWAP_FEE_BPS = 50;
|
|
100
|
+
export declare const AGGREGATED_SWAP_FEE_RECIPIENT: `0x${string}`;
|
|
101
|
+
export type AggregatedSwapToken = AegisSwapToken;
|
|
102
|
+
export type AggregatedSwapDefaultTokenSymbol = 'USDC' | 'USDT' | 'WETH' | 'ETH' | 'WBTC' | 'STETH';
|
|
103
|
+
export type AggregatedSwapWolfGameTokenSymbol = AegisSwapBuiltInTokenSymbol | 'ETH';
|
|
104
|
+
export type AggregatedSwapTokenSymbol = AggregatedSwapDefaultTokenSymbol | AggregatedSwapWolfGameTokenSymbol;
|
|
105
|
+
export declare const AGGREGATED_SWAP_DEFAULT_TOKENS: Record<AggregatedSwapDefaultTokenSymbol, AggregatedSwapToken>;
|
|
106
|
+
export declare const AGGREGATED_SWAP_WOLFGAME_TOKENS: Record<AggregatedSwapWolfGameTokenSymbol, AggregatedSwapToken>;
|
|
107
|
+
export declare const AGGREGATED_SWAP_DEFAULT_TOKEN_LIST: AegisSwapToken[];
|
|
108
|
+
export declare const AGGREGATED_SWAP_WOLFGAME_TOKEN_LIST: AegisSwapToken[];
|
|
109
|
+
export declare const AGGREGATED_SWAP_TOKEN_PRESETS: {
|
|
110
|
+
readonly default: AegisSwapToken[];
|
|
111
|
+
readonly wolfgame: AegisSwapToken[];
|
|
112
|
+
};
|
|
113
|
+
export declare const AGGREGATED_SWAP_CURATED_TOKENS: Record<AggregatedSwapDefaultTokenSymbol, AegisSwapToken>;
|
|
114
|
+
export declare function createAegisSwapChainConfig(input: AegisSwapChainConfigInput & {
|
|
115
|
+
chainId: number;
|
|
116
|
+
}, base?: AegisSwapChainConfig): AegisSwapChainConfig;
|
|
117
|
+
export declare function createAegisSwapChains(chains?: Partial<Record<number, AegisSwapChainConfigInput>>): Record<number, AegisSwapChainConfig>;
|
|
118
|
+
export declare function createAegisSwapPoolMarket(input: AegisSwapPoolConfig, chains?: Record<number, AegisSwapChainConfig>): AegisSwapMarket;
|
|
119
|
+
export declare function createAegisSwapMarketsFromPools(pools: AegisSwapPoolConfig[] | undefined, chains?: Record<number, AegisSwapChainConfig>): Record<string, AegisSwapMarket>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
import type { AegisPoolKey } from './config';
|
|
3
|
+
export type ExecutionBatch = {
|
|
4
|
+
requiresV4Unlock: boolean;
|
|
5
|
+
actions: Hex;
|
|
6
|
+
params: Hex[];
|
|
7
|
+
};
|
|
8
|
+
export type PermitDetails = {
|
|
9
|
+
token: Address;
|
|
10
|
+
amount: bigint;
|
|
11
|
+
expiration: number;
|
|
12
|
+
nonce: number;
|
|
13
|
+
};
|
|
14
|
+
export type PermitBatch = {
|
|
15
|
+
details: PermitDetails[];
|
|
16
|
+
spender: Address;
|
|
17
|
+
sigDeadline: bigint;
|
|
18
|
+
};
|
|
19
|
+
export type SignedPermitBatch = {
|
|
20
|
+
owner: Address;
|
|
21
|
+
permitBatch: PermitBatch;
|
|
22
|
+
signature: Hex;
|
|
23
|
+
};
|
|
24
|
+
export type SwapOutputFee = {
|
|
25
|
+
recipient: Address;
|
|
26
|
+
bips: number;
|
|
27
|
+
} | {
|
|
28
|
+
recipient: Address;
|
|
29
|
+
amount: bigint;
|
|
30
|
+
};
|
|
31
|
+
export type BuiltSwapTransaction = {
|
|
32
|
+
calldata: Hex;
|
|
33
|
+
value: bigint;
|
|
34
|
+
};
|
|
35
|
+
export declare const MAX_UINT128: bigint;
|
|
36
|
+
export declare function assertUint128(value: bigint, label?: string): void;
|
|
37
|
+
export declare function computePoolId(poolKey: AegisPoolKey): Hex;
|
|
38
|
+
export declare function buildExactInSwapTransaction(args: {
|
|
39
|
+
poolKey: AegisPoolKey;
|
|
40
|
+
zeroForOne: boolean;
|
|
41
|
+
amountIn: bigint;
|
|
42
|
+
amountOutMinimum: bigint;
|
|
43
|
+
recipient: Address;
|
|
44
|
+
deadline: bigint;
|
|
45
|
+
permit?: SignedPermitBatch | null;
|
|
46
|
+
fee?: SwapOutputFee | null;
|
|
47
|
+
}): BuiltSwapTransaction;
|
|
48
|
+
export declare function buildExactOutSwapTransaction(args: {
|
|
49
|
+
poolKey: AegisPoolKey;
|
|
50
|
+
zeroForOne: boolean;
|
|
51
|
+
amountOut: bigint;
|
|
52
|
+
amountInMaximum: bigint;
|
|
53
|
+
recipient: Address;
|
|
54
|
+
deadline: bigint;
|
|
55
|
+
permit?: SignedPermitBatch | null;
|
|
56
|
+
fee?: SwapOutputFee | null;
|
|
57
|
+
}): BuiltSwapTransaction;
|
package/dist/errors.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { AEGIS_DYNAMIC_FEE_FLAG, AEGIS_SWAP_CHAINS, AEGIS_SWAP_CHAIN_ID, AEGIS_SWAP_DEFAULT_FEE_BPS, AEGIS_SWAP_DEFAULT_FEE_RECIPIENT, AEGIS_SWAP_DEFAULT_METADATA_ENDPOINT, AEGIS_SWAP_DEFAULT_POOL_IDS, AEGIS_SWAP_DEFAULT_RPC_URLS, AEGIS_SWAP_HOOK, AEGIS_SWAP_MAINNET_CHAIN, AEGIS_SWAP_MAINNET_UNISWAP_V4_CONTRACTS, AEGIS_SWAP_MARKETS, AEGIS_SWAP_PERMIT2, AEGIS_SWAP_ROUTER, AEGIS_SWAP_TOKENS, AEGIS_SWAP_V4_QUOTER, AGGREGATED_SWAP_CURATED_TOKENS, AGGREGATED_SWAP_DEFAULT_TOKEN_LIST, AGGREGATED_SWAP_DEFAULT_TOKENS, AGGREGATED_SWAP_TOKEN_PRESETS, AGGREGATED_SWAP_WOLFGAME_TOKEN_LIST, AGGREGATED_SWAP_WOLFGAME_TOKENS, UNISWAP_V4_CONTRACTS_BY_CHAIN, createAegisSwapChainConfig, createAegisSwapChains, createAegisSwapMarketsFromPools, createAegisSwapPoolMarket, createAegisSwapUniswapV4Contracts, getExplorerUrl } from './config';
|
|
2
|
+
export type { AegisPoolKey, AegisSwapBuiltInAssetSymbol, AegisSwapBuiltInMarketId, AegisSwapBuiltInTokenSymbol, AegisSwapChainConfig, AegisSwapChainConfigInput, AegisSwapFeeConfig, AegisSwapMarket, AegisSwapPoolConfig, AegisSwapToken, AegisSwapTokenSymbol, AegisSwapUniswapV4Contracts, AegisSwapUniswapV4ContractsInput, AggregatedSwapDefaultTokenSymbol, AggregatedSwapToken, AggregatedSwapTokenSymbol, AggregatedSwapWolfGameTokenSymbol } from './config';
|
|
3
|
+
export { assertUint128, buildExactInSwapTransaction, buildExactOutSwapTransaction, computePoolId, MAX_UINT128 } from './encoding';
|
|
4
|
+
export type { BuiltSwapTransaction, ExecutionBatch, PermitBatch, PermitDetails, SignedPermitBatch, SwapOutputFee } from './encoding';
|
|
5
|
+
export { fetchDirectSwapQuote, getZeroForOne, outputFeeForQuote, quoteSpendAmount, reconcileSubmitQuote, sameQuote } from './quote';
|
|
6
|
+
export type { DirectSwapQuote, ReconciledSubmitQuote, SwapQuoteMode } from './quote';
|
|
7
|
+
export { aggregatedSwapErrorMessage, fetchAggregatedSwapQuote } from './quote/aggregatedSwapQuote';
|
|
8
|
+
export type { AggregatedSwapQuote, AggregatedSwapRoute, HopInfo } from './types/aggregatedSwap';
|
|
9
|
+
export { KyberSwapApiError, buildKyberSwapRoute, fetchKyberSwapRoute, isRetryableKyberSwapError } from './services/kyberSwap';
|
|
10
|
+
export type { KyberSwapBuild, KyberSwapError, KyberSwapFeeParams, KyberSwapRoute, KyberSwapRouteLeg, KyberSwapRouteSummary } from './services/kyberSwap';
|
|
11
|
+
export { approveErc20Spender, approveErc20ToPermit2, approvePermit2ToRouter, buildSignedPermitBatch, DEFAULT_PERMIT_EXPIRATION_SECONDS, MAX_UINT160, MAX_UINT256, PERMIT2_FAR_FUTURE_EXPIRATION, readErc20Allowance, readPermit2RouterAllowance, SWAP_TX_DEADLINE_SECONDS } from './permit';
|
|
12
|
+
export { fetchGlobalTokenMetadata, getIchiIconGuess, resolveTokenIconUrl } from './metadata';
|
|
13
|
+
export type { AegisSwapGlobalTokenMetadata, TokenMetadataByAddress } from './metadata';
|
|
14
|
+
export { createSwapPublicClient, getInjectedProvider, getProviderAccount, getProviderChainId, isEip1193Provider, normalizeAccount, normalizeWalletConnection, requestProviderAccount, subscribeProvider, switchProviderChain } from './wallet';
|
|
15
|
+
export type { AegisSwapProviderResolver, AegisSwapWalletConnection, Eip1193Provider, ProviderChainConfig } from './wallet';
|
|
16
|
+
export { approveDirectPoolSwapInput, DirectPoolSwapPriceMovedError, executeDirectPoolSwap } from './actions/directPoolSwap';
|
|
17
|
+
export type { DirectPoolSwapApprovalResult } from './actions/directPoolSwap';
|
|
18
|
+
export { approveKyberSwapInput, executeKyberSwap, isNativeToken, KyberSwapPriceMovedError, NATIVE_TOKEN_ADDRESS } from './actions/kyberSwap';
|
|
19
|
+
export type { KyberSwapApprovalResult } from './actions/kyberSwap';
|
|
20
|
+
export { ensureWalletChain, resolveWalletSession, waitForProviderChain } from './actions/wallet';
|
|
21
|
+
export type { AegisSwapActionCallbacks, AegisSwapActionResult } from './actions/types';
|
|
22
|
+
export { estimateSwapGasWithBuffer } from './swap/gas';
|
|
23
|
+
export type { SwapGasRequest } from './swap/gas';
|
|
24
|
+
export type { AegisSwapApprovalMode, AegisSwapSubmitDetails, WalletSession } from './swap/types';
|
|
25
|
+
export { errorMessage, isUserRejectedError } from './errors';
|
|
26
|
+
export { isBusy, transactionProgressView } from './transactionProgress';
|
|
27
|
+
export type { AegisSwapReceiptSummary, AegisSwapStatusSnapshot, AegisSwapWalletPromptProgress, SubmitStatus, TransactionProgressState, TransactionProgressView } from './transactionProgress';
|
|
28
|
+
export { isDocumentVisible, pollUntil, retryOnError } from './polling';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Address } from 'viem';
|
|
2
|
+
import type { AegisSwapToken } from './config';
|
|
3
|
+
export type AegisSwapGlobalTokenMetadata = {
|
|
4
|
+
chainId: number | null;
|
|
5
|
+
address: string | null;
|
|
6
|
+
symbol: string | null;
|
|
7
|
+
displayName: string | null;
|
|
8
|
+
fullName: string | null;
|
|
9
|
+
decimals: number | null;
|
|
10
|
+
iconURL: string | null;
|
|
11
|
+
};
|
|
12
|
+
export declare function getIchiIconGuess(symbol: string | null | undefined): string | null;
|
|
13
|
+
export type TokenMetadataByAddress = Record<string, AegisSwapGlobalTokenMetadata>;
|
|
14
|
+
/**
|
|
15
|
+
* Canonical icon-source order for a token: explicit config URL, the metadata
|
|
16
|
+
* service, then the ichi naming guess. Public so hosts rendering their own
|
|
17
|
+
* token marks resolve identically to the widget.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveTokenIconUrl(token: AegisSwapToken, metadataByAddress: TokenMetadataByAddress): string | null;
|
|
20
|
+
export declare function fetchGlobalTokenMetadata(args: {
|
|
21
|
+
endpoint: string;
|
|
22
|
+
chainId: number;
|
|
23
|
+
addresses: Address[];
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
}): Promise<Map<string, AegisSwapGlobalTokenMetadata>>;
|
package/dist/permit.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type Address, type Chain, type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import type { Eip1193Provider } from './wallet';
|
|
3
|
+
import type { SignedPermitBatch } from './encoding';
|
|
4
|
+
export declare const MAX_UINT160: bigint;
|
|
5
|
+
export declare const MAX_UINT256: bigint;
|
|
6
|
+
export declare const SWAP_TX_DEADLINE_SECONDS = 600;
|
|
7
|
+
export declare const DEFAULT_PERMIT_EXPIRATION_SECONDS: number;
|
|
8
|
+
export declare const PERMIT2_FAR_FUTURE_EXPIRATION: number;
|
|
9
|
+
export declare function approveErc20ToPermit2(args: {
|
|
10
|
+
provider: Eip1193Provider;
|
|
11
|
+
publicClient: PublicClient;
|
|
12
|
+
account: Address;
|
|
13
|
+
chain: Chain;
|
|
14
|
+
token: Address;
|
|
15
|
+
permit2: Address;
|
|
16
|
+
amount?: bigint;
|
|
17
|
+
}): Promise<Hex>;
|
|
18
|
+
export declare function readErc20Allowance(args: {
|
|
19
|
+
publicClient: PublicClient;
|
|
20
|
+
token: Address;
|
|
21
|
+
owner: Address;
|
|
22
|
+
spender: Address;
|
|
23
|
+
}): Promise<bigint>;
|
|
24
|
+
export declare function approveErc20Spender(args: {
|
|
25
|
+
provider: Eip1193Provider;
|
|
26
|
+
publicClient: PublicClient;
|
|
27
|
+
account: Address;
|
|
28
|
+
chain: Chain;
|
|
29
|
+
token: Address;
|
|
30
|
+
spender: Address;
|
|
31
|
+
amount?: bigint;
|
|
32
|
+
}): Promise<Hex>;
|
|
33
|
+
export declare function approvePermit2ToRouter(args: {
|
|
34
|
+
provider: Eip1193Provider;
|
|
35
|
+
publicClient: PublicClient;
|
|
36
|
+
account: Address;
|
|
37
|
+
chain: Chain;
|
|
38
|
+
token: Address;
|
|
39
|
+
permit2: Address;
|
|
40
|
+
router: Address;
|
|
41
|
+
amount?: bigint;
|
|
42
|
+
expiration?: number;
|
|
43
|
+
}): Promise<Hex>;
|
|
44
|
+
export declare function readPermit2RouterAllowance(args: {
|
|
45
|
+
publicClient: PublicClient;
|
|
46
|
+
permit2: Address;
|
|
47
|
+
account: Address;
|
|
48
|
+
token: Address;
|
|
49
|
+
router: Address;
|
|
50
|
+
}): Promise<readonly [amount: bigint, expiration: number, nonce: number]>;
|
|
51
|
+
export declare function buildSignedPermitBatch(args: {
|
|
52
|
+
provider: Eip1193Provider;
|
|
53
|
+
publicClient: PublicClient;
|
|
54
|
+
account: Address;
|
|
55
|
+
chainId: number;
|
|
56
|
+
chain: Chain;
|
|
57
|
+
permit2: Address;
|
|
58
|
+
router: Address;
|
|
59
|
+
token: Address;
|
|
60
|
+
amount: bigint;
|
|
61
|
+
/**
|
|
62
|
+
* 'max' signs a MAX_UINT160 permit (still expiring in 30 minutes) so quick
|
|
63
|
+
* follow-up swaps reuse it instead of prompting for a new signature each
|
|
64
|
+
* time — Permit2 decrements exact-sized permits to zero on transfer.
|
|
65
|
+
* Defaults to 'exact'.
|
|
66
|
+
*/
|
|
67
|
+
sizing?: 'exact' | 'max';
|
|
68
|
+
/** Pre-started readPermit2RouterAllowance result to overlap with other RPC work. */
|
|
69
|
+
allowanceRead?: ReturnType<typeof readPermit2RouterAllowance>;
|
|
70
|
+
}): Promise<SignedPermitBatch | null>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function isDocumentVisible(): boolean;
|
|
2
|
+
export declare function retryOnError<T>(read: () => Promise<T>, attempts: number, delayMs: number, stopped?: () => boolean): Promise<T>;
|
|
3
|
+
export declare function pollUntil<T>(read: () => Promise<T>, done: (value: T) => boolean, attempts: number, delayMs: number): Promise<T>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Address, type PublicClient } from 'viem';
|
|
2
|
+
import { type AegisSwapToken } from '../config';
|
|
3
|
+
import type { AggregatedSwapQuote } from '../types/aggregatedSwap';
|
|
4
|
+
export declare function aggregatedSwapErrorMessage(error: unknown, fallbackMessage: string): string;
|
|
5
|
+
export declare function fetchAggregatedSwapQuote(inputToken: AegisSwapToken, outputToken: AegisSwapToken, amount: bigint, slippageBps: number, mode?: 'exactIn' | 'exactOut', account?: Address | null, signal?: AbortSignal, _publicClient?: PublicClient): Promise<AggregatedSwapQuote>;
|
package/dist/quote.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type Address, type PublicClient } from 'viem';
|
|
2
|
+
import { type SwapOutputFee } from './encoding';
|
|
3
|
+
import type { AegisPoolKey, AegisSwapFeeConfig, AegisSwapMarket, AegisSwapToken } from './config';
|
|
4
|
+
export type SwapQuoteMode = 'exactIn' | 'exactOut';
|
|
5
|
+
export type DirectSwapQuote = {
|
|
6
|
+
mode: SwapQuoteMode;
|
|
7
|
+
poolKey: AegisPoolKey;
|
|
8
|
+
zeroForOne: boolean;
|
|
9
|
+
amountIn: bigint;
|
|
10
|
+
/** Net output the user is quoted to receive (gross minus the widget fee). */
|
|
11
|
+
amountOut: bigint;
|
|
12
|
+
/** Pool output before the widget fee is taken. */
|
|
13
|
+
grossAmountOut: bigint;
|
|
14
|
+
/**
|
|
15
|
+
* Swap-action output floor, enforced on-chain. Semantics differ by mode:
|
|
16
|
+
* - exactIn: gross floor sized so the user still nets `userAmountOutMinimum`
|
|
17
|
+
* after the fee portion is taken.
|
|
18
|
+
* - exactOut: equals `grossAmountOut` (output is fixed; the on-chain
|
|
19
|
+
* protection is `amountInMaximum`). Informational only.
|
|
20
|
+
*/
|
|
21
|
+
amountOutMinimum: bigint;
|
|
22
|
+
/** exactOut: input ceiling enforced on-chain. exactIn: equals `amountIn`. */
|
|
23
|
+
amountInMaximum: bigint;
|
|
24
|
+
/** Minimum the user nets after slippage and fee. Display/reconciliation value. */
|
|
25
|
+
userAmountOutMinimum: bigint;
|
|
26
|
+
/** Estimated widget fee in output currency (exact for exactOut, quote-time estimate for exactIn). */
|
|
27
|
+
feeAmount: bigint;
|
|
28
|
+
feeBps: number;
|
|
29
|
+
feeRecipient: Address | null;
|
|
30
|
+
gasEstimate: bigint;
|
|
31
|
+
};
|
|
32
|
+
export declare function getZeroForOne(poolKey: AegisPoolKey, tokenIn: AegisSwapToken): boolean;
|
|
33
|
+
export declare function fetchDirectSwapQuote(args: {
|
|
34
|
+
publicClient: PublicClient;
|
|
35
|
+
account: Address;
|
|
36
|
+
market: AegisSwapMarket;
|
|
37
|
+
tokenIn: AegisSwapToken;
|
|
38
|
+
tokenOut: AegisSwapToken;
|
|
39
|
+
mode: SwapQuoteMode;
|
|
40
|
+
amount: bigint;
|
|
41
|
+
slippageBps: number;
|
|
42
|
+
fee?: AegisSwapFeeConfig | null;
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
}): Promise<DirectSwapQuote>;
|
|
45
|
+
export type ReconciledSubmitQuote = {
|
|
46
|
+
quote: DirectSwapQuote;
|
|
47
|
+
/**
|
|
48
|
+
* True when the fresh quote can no longer satisfy the protection the user
|
|
49
|
+
* saw (exactIn: output below the displayed minimum; exactOut: input above
|
|
50
|
+
* the displayed maximum). Callers should surface the fresh quote instead of
|
|
51
|
+
* submitting.
|
|
52
|
+
*/
|
|
53
|
+
priceMovedBeyondTolerance: boolean;
|
|
54
|
+
};
|
|
55
|
+
export declare function sameQuote(a: DirectSwapQuote, b: DirectSwapQuote): boolean;
|
|
56
|
+
export declare function reconcileSubmitQuote(displayed: DirectSwapQuote | null, fresh: DirectSwapQuote): ReconciledSubmitQuote;
|
|
57
|
+
/** The input-side amount a swap may spend: the bound for allowances and permits. */
|
|
58
|
+
export declare function quoteSpendAmount(quote: DirectSwapQuote): bigint;
|
|
59
|
+
export declare function outputFeeForQuote(quote: DirectSwapQuote): SwapOutputFee | null;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
export type KyberSwapFeeParams = {
|
|
3
|
+
feeAmount: string;
|
|
4
|
+
chargeFeeBy: 'currency_in' | 'currency_out';
|
|
5
|
+
isInBps: boolean;
|
|
6
|
+
feeReceiver: Address;
|
|
7
|
+
};
|
|
8
|
+
export type KyberSwapRouteLeg = {
|
|
9
|
+
pool?: string;
|
|
10
|
+
tokenIn?: Address;
|
|
11
|
+
tokenOut?: Address;
|
|
12
|
+
swapAmount?: string;
|
|
13
|
+
amountOut?: string;
|
|
14
|
+
exchange?: string;
|
|
15
|
+
poolType?: string;
|
|
16
|
+
};
|
|
17
|
+
export type KyberSwapRouteSummary = {
|
|
18
|
+
tokenIn: Address;
|
|
19
|
+
tokenOut: Address;
|
|
20
|
+
amountIn: string;
|
|
21
|
+
amountOut: string;
|
|
22
|
+
amountInUsd?: string;
|
|
23
|
+
amountOutUsd?: string;
|
|
24
|
+
gas?: string;
|
|
25
|
+
gasEstimate?: string;
|
|
26
|
+
gasUsd?: string;
|
|
27
|
+
priceImpact?: number;
|
|
28
|
+
route?: KyberSwapRouteLeg[][];
|
|
29
|
+
routeComposition?: Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
part: number;
|
|
32
|
+
}>;
|
|
33
|
+
extraFee?: KyberSwapFeeParams | Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
export type KyberSwapRoute = {
|
|
36
|
+
routeSummary: KyberSwapRouteSummary;
|
|
37
|
+
routerAddress: Address;
|
|
38
|
+
requestId?: string;
|
|
39
|
+
};
|
|
40
|
+
export type KyberSwapBuild = {
|
|
41
|
+
amountIn: string;
|
|
42
|
+
amountOut: string;
|
|
43
|
+
gas?: string;
|
|
44
|
+
gasUsd?: string;
|
|
45
|
+
data: Hex;
|
|
46
|
+
routerAddress: Address;
|
|
47
|
+
transactionValue?: string;
|
|
48
|
+
requestId?: string;
|
|
49
|
+
};
|
|
50
|
+
export type KyberSwapError = {
|
|
51
|
+
code?: number;
|
|
52
|
+
message?: string;
|
|
53
|
+
};
|
|
54
|
+
export declare class KyberSwapApiError extends Error {
|
|
55
|
+
readonly status: number;
|
|
56
|
+
readonly statusText: string;
|
|
57
|
+
readonly code?: number;
|
|
58
|
+
readonly body?: unknown;
|
|
59
|
+
constructor({ status, statusText, code, message, body }: {
|
|
60
|
+
status: number;
|
|
61
|
+
statusText: string;
|
|
62
|
+
code?: number;
|
|
63
|
+
message: string;
|
|
64
|
+
body?: unknown;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export declare function isRetryableKyberSwapError(error: unknown): boolean;
|
|
68
|
+
export declare function fetchKyberSwapRoute({ tokenIn, tokenOut, amountIn, chainId, origin, fee, signal }: {
|
|
69
|
+
tokenIn: Address;
|
|
70
|
+
tokenOut: Address;
|
|
71
|
+
amountIn: string;
|
|
72
|
+
chainId?: number;
|
|
73
|
+
origin?: Address | null;
|
|
74
|
+
fee?: KyberSwapFeeParams | null;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
}): Promise<KyberSwapRoute>;
|
|
77
|
+
export declare function buildKyberSwapRoute({ routeSummary, sender, recipient, slippageBps, chainId, signal }: {
|
|
78
|
+
routeSummary: KyberSwapRouteSummary;
|
|
79
|
+
sender: Address;
|
|
80
|
+
recipient: Address;
|
|
81
|
+
slippageBps: number;
|
|
82
|
+
chainId?: number;
|
|
83
|
+
signal?: AbortSignal;
|
|
84
|
+
}): Promise<KyberSwapBuild>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Address, PublicClient } from 'viem';
|
|
2
|
+
import type { AegisSwapChainConfig } from '../config';
|
|
3
|
+
import type { SignedPermitBatch } from '../encoding';
|
|
4
|
+
import { readPermit2RouterAllowance } from '../permit';
|
|
5
|
+
import type { SubmitStatus } from '../transactionProgress';
|
|
6
|
+
import type { AegisSwapApprovalMode, WalletSession } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Produces the Permit2 authorization the swap calldata needs.
|
|
9
|
+
*
|
|
10
|
+
* Tries an off-chain Permit2 signature first (`null` calldata permit when the
|
|
11
|
+
* on-chain allowance already covers the spend). Wallets that cannot produce an
|
|
12
|
+
* EOA-style typed-data signature Permit2 can verify — undeployed smart accounts
|
|
13
|
+
* sign ERC-6492, some wallets refuse `eth_signTypedData_v4` — fall back to an
|
|
14
|
+
* on-chain Permit2 approval scoped to the same amount and expiration the permit
|
|
15
|
+
* would have carried, and this returns `null` so the swap proceeds without an
|
|
16
|
+
* inline permit. A user rejection is rethrown untouched.
|
|
17
|
+
*/
|
|
18
|
+
export declare function authorizePermit({ wallet, publicClient, activeChain, permit2, router, token, amount, approvalMode, allowanceRead, setStatus }: {
|
|
19
|
+
wallet: WalletSession;
|
|
20
|
+
publicClient: PublicClient;
|
|
21
|
+
activeChain: AegisSwapChainConfig;
|
|
22
|
+
permit2: Address;
|
|
23
|
+
router: Address;
|
|
24
|
+
token: Address;
|
|
25
|
+
amount: bigint;
|
|
26
|
+
approvalMode: AegisSwapApprovalMode;
|
|
27
|
+
allowanceRead: ReturnType<typeof readPermit2RouterAllowance>;
|
|
28
|
+
setStatus: (status: SubmitStatus) => void;
|
|
29
|
+
}): Promise<SignedPermitBatch | null>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import type { AegisSwapChainConfig, AegisSwapMarket, AegisSwapToken } from '../config';
|
|
3
|
+
import { type SignedPermitBatch } from '../encoding';
|
|
4
|
+
import { type DirectSwapQuote } from '../quote';
|
|
5
|
+
import type { AegisSwapReceiptSummary, SubmitStatus } from '../transactionProgress';
|
|
6
|
+
import type { AegisSwapSubmitDetails, WalletSession } from './types';
|
|
7
|
+
export type SwapExecutionResult = {
|
|
8
|
+
receipt: {
|
|
9
|
+
status: 'success' | 'reverted';
|
|
10
|
+
transactionHash: Hex;
|
|
11
|
+
};
|
|
12
|
+
/** Settlement facts (gas, block, fee) lifted off the mined receipt. */
|
|
13
|
+
summary: AegisSwapReceiptSummary;
|
|
14
|
+
swapDetails: AegisSwapSubmitDetails;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Builds the swap calldata, sends it, and waits for the receipt.
|
|
18
|
+
*
|
|
19
|
+
* Estimates gas with a 20% headroom bump, surfaces the optimistic hash through
|
|
20
|
+
* `setTxHash` (and `onSubmitted`) before mining, then tracks replacements: a
|
|
21
|
+
* wallet speed-up swaps in the hash that actually mines, while a wallet cancel
|
|
22
|
+
* mines a no-op whose "successful" receipt must not count as a swap — so a
|
|
23
|
+
* cancelled or reverted receipt throws. Setting the success status and the
|
|
24
|
+
* post-success refreshes stay with the caller.
|
|
25
|
+
*/
|
|
26
|
+
export declare function executeSwapTransaction({ wallet, publicClient, activeChain, market, inputToken, outputToken, swapQuote, permit, setStatus, setTxHash, onSubmitted }: {
|
|
27
|
+
wallet: WalletSession;
|
|
28
|
+
publicClient: PublicClient;
|
|
29
|
+
activeChain: AegisSwapChainConfig;
|
|
30
|
+
market: AegisSwapMarket;
|
|
31
|
+
inputToken: AegisSwapToken;
|
|
32
|
+
outputToken: AegisSwapToken;
|
|
33
|
+
swapQuote: DirectSwapQuote;
|
|
34
|
+
permit: SignedPermitBatch | null;
|
|
35
|
+
setStatus: (status: SubmitStatus) => void;
|
|
36
|
+
setTxHash: (hash: Hex | null) => void;
|
|
37
|
+
onSubmitted?: (hash: Hex, swap?: AegisSwapSubmitDetails) => void;
|
|
38
|
+
}): Promise<SwapExecutionResult>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Address, Hex, PublicClient } from 'viem';
|
|
2
|
+
export type SwapGasRequest = {
|
|
3
|
+
account: Address;
|
|
4
|
+
to: Address;
|
|
5
|
+
data: Hex;
|
|
6
|
+
value: bigint;
|
|
7
|
+
};
|
|
8
|
+
export declare function estimateSwapGasWithBuffer(publicClient: Pick<PublicClient, 'estimateGas'>, request: SwapGasRequest): Promise<bigint | undefined>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Address } from 'viem';
|
|
2
|
+
import type { SwapQuoteMode } from '../quote';
|
|
3
|
+
import type { Eip1193Provider } from '../wallet';
|
|
4
|
+
/** A resolved wallet: a provider landed on the active chain plus its account. */
|
|
5
|
+
export type WalletSession = {
|
|
6
|
+
provider: Eip1193Provider;
|
|
7
|
+
account: Address;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* ERC-20 approval sizing.
|
|
11
|
+
*
|
|
12
|
+
* `exact` approves only the current quote spend. `max` approves the token's
|
|
13
|
+
* maximum spender allowance so later swaps can skip the approval transaction.
|
|
14
|
+
*/
|
|
15
|
+
export type AegisSwapApprovalMode = 'exact' | 'max';
|
|
16
|
+
/**
|
|
17
|
+
* Swap context attached to submit callbacks and action results. Amounts are raw
|
|
18
|
+
* base units.
|
|
19
|
+
*/
|
|
20
|
+
export type AegisSwapSubmitDetails = {
|
|
21
|
+
mode: SwapQuoteMode;
|
|
22
|
+
inputSymbol: string;
|
|
23
|
+
outputSymbol: string;
|
|
24
|
+
amountIn: bigint;
|
|
25
|
+
amountOut: bigint;
|
|
26
|
+
feeAmount: bigint;
|
|
27
|
+
feeBps: number;
|
|
28
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
export type SubmitStatus = 'idle' | 'approving' | 'signing' | 'submitting' | 'success';
|
|
3
|
+
/**
|
|
4
|
+
* On-chain settlement facts pulled from the swap's mined receipt. Raw base
|
|
5
|
+
* units / wei so the widget view layer owns formatting (viem `formatEther` /
|
|
6
|
+
* `formatGwei`) without widening the public success callback.
|
|
7
|
+
*/
|
|
8
|
+
export type AegisSwapReceiptSummary = {
|
|
9
|
+
transactionHash: Hex;
|
|
10
|
+
blockNumber: bigint;
|
|
11
|
+
gasUsed: bigint;
|
|
12
|
+
effectiveGasPrice: bigint;
|
|
13
|
+
/** gasUsed * effectiveGasPrice — the L2-exclusive execution fee in native wei. */
|
|
14
|
+
feeWei: bigint;
|
|
15
|
+
};
|
|
16
|
+
export declare function isBusy(status: SubmitStatus): boolean;
|
|
17
|
+
export type TransactionProgressState = 'pending' | 'mining' | 'success' | 'error';
|
|
18
|
+
export type AegisSwapWalletPromptProgress = {
|
|
19
|
+
/** Total swap-flow wallet-provider prompts expected from current allowances. */
|
|
20
|
+
total: number;
|
|
21
|
+
completed: number;
|
|
22
|
+
/** 1-based prompt currently awaiting the wallet; null while idle/mining/terminal. */
|
|
23
|
+
active: number | null;
|
|
24
|
+
};
|
|
25
|
+
export type TransactionProgressView = {
|
|
26
|
+
state: TransactionProgressState;
|
|
27
|
+
label: string;
|
|
28
|
+
walletPrompts: AegisSwapWalletPromptProgress;
|
|
29
|
+
/** Calm fill showing completed wallet-provider prompts. */
|
|
30
|
+
completePct: number;
|
|
31
|
+
/** Visual activity layer width; pending/mining sweeps full-width by default. */
|
|
32
|
+
activeWidthPct: number;
|
|
33
|
+
};
|
|
34
|
+
export declare function transactionProgressView({ status, inputSymbol, txHash, actionError, approvalRequired, approvalDone, authorizationRequired }: {
|
|
35
|
+
status: SubmitStatus;
|
|
36
|
+
inputSymbol: string;
|
|
37
|
+
txHash: Hex | null;
|
|
38
|
+
actionError: string | null;
|
|
39
|
+
approvalRequired: boolean;
|
|
40
|
+
approvalDone: boolean;
|
|
41
|
+
authorizationRequired: boolean;
|
|
42
|
+
}): TransactionProgressView | null;
|
|
43
|
+
export type AegisSwapStatusSnapshot = {
|
|
44
|
+
status: SubmitStatus;
|
|
45
|
+
progress: TransactionProgressState | null;
|
|
46
|
+
/** The rail's phase copy (e.g. "Approving USDC for Permit2 · wallet prompt 1 of 3"); null while idle. */
|
|
47
|
+
label: string | null;
|
|
48
|
+
/** Swap-flow wallet provider prompt count/progress, derived from current allowances. */
|
|
49
|
+
walletPrompts: AegisSwapWalletPromptProgress;
|
|
50
|
+
/** Rail geometry; null while idle. */
|
|
51
|
+
completePct: number | null;
|
|
52
|
+
activeWidthPct: number | null;
|
|
53
|
+
txHash: Hex | null;
|
|
54
|
+
error: string | null;
|
|
55
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
import type { AegisSwapToken } from '../config';
|
|
3
|
+
export type HopInfo = {
|
|
4
|
+
dex: string;
|
|
5
|
+
inputToken: AegisSwapToken;
|
|
6
|
+
outputToken: AegisSwapToken;
|
|
7
|
+
part: number;
|
|
8
|
+
};
|
|
9
|
+
export type AggregatedSwapQuote = {
|
|
10
|
+
inputToken: AegisSwapToken;
|
|
11
|
+
outputToken: AegisSwapToken;
|
|
12
|
+
amountIn: bigint;
|
|
13
|
+
amountOut: bigint;
|
|
14
|
+
gasEstimate: bigint;
|
|
15
|
+
hops: HopInfo[];
|
|
16
|
+
routerAddress: Address;
|
|
17
|
+
calldata: Hex | null;
|
|
18
|
+
transactionValue: bigint;
|
|
19
|
+
priceImpact: number;
|
|
20
|
+
feeAmount: bigint;
|
|
21
|
+
feeBps: number;
|
|
22
|
+
feeRecipient: Address | null;
|
|
23
|
+
userAmountOutMinimum: bigint;
|
|
24
|
+
amountOutMinimum: bigint;
|
|
25
|
+
};
|
|
26
|
+
export type AggregatedSwapRoute = {
|
|
27
|
+
inputToken: AegisSwapToken;
|
|
28
|
+
outputToken: AegisSwapToken;
|
|
29
|
+
};
|