@elizaos/plugin-wallet 2.0.0-beta.1
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 +64 -0
- package/auto-enable.ts +76 -0
- package/dist/LpManagementService-BWrQ5-cO.mjs +353 -0
- package/dist/MockLpService-D_Apn4Fd.mjs +99 -0
- package/dist/aerodrome-CfnESC32.mjs +890 -0
- package/dist/chunk-hT5z_Zn9.mjs +35 -0
- package/dist/index.d.mts +34727 -0
- package/dist/index.mjs +21590 -0
- package/dist/lib/server-wallet-trade.d.mts +34 -0
- package/dist/lib/server-wallet-trade.mjs +306 -0
- package/dist/meteora-BPX39hZo.mjs +22640 -0
- package/dist/orca-Bybp1HXO.mjs +249 -0
- package/dist/pancakeswp-CkEXlXti.mjs +604 -0
- package/dist/plugin-ZO_MTyd0.mjs +529 -0
- package/dist/raydium-rfaM9yEf.mjs +539 -0
- package/dist/sdk/index.d.mts +32492 -0
- package/dist/sdk/index.mjs +6415 -0
- package/dist/types-D5252NZk.mjs +487 -0
- package/dist/uniswap-CReXgXVN.mjs +573 -0
- package/dist/wallet-action.d.mts +6 -0
- package/dist/wallet-action.mjs +820 -0
- package/package.json +152 -0
- package/src/actions/failure-codes.ts +79 -0
- package/src/actions/index.ts +1 -0
- package/src/analytics/birdeye/actions/wallet-search-address.ts +9 -0
- package/src/analytics/birdeye/birdeye-task.ts +175 -0
- package/src/analytics/birdeye/birdeye.ts +813 -0
- package/src/analytics/birdeye/constants.ts +74 -0
- package/src/analytics/birdeye/providers/agent-portfolio-provider.ts +18 -0
- package/src/analytics/birdeye/providers/market.ts +227 -0
- package/src/analytics/birdeye/providers/portfolio-factory.test.ts +138 -0
- package/src/analytics/birdeye/providers/portfolio-factory.ts +252 -0
- package/src/analytics/birdeye/providers/trending.ts +365 -0
- package/src/analytics/birdeye/providers/wallet.ts +14 -0
- package/src/analytics/birdeye/search-category.test.ts +207 -0
- package/src/analytics/birdeye/search-category.ts +506 -0
- package/src/analytics/birdeye/service.ts +992 -0
- package/src/analytics/birdeye/tasks/birdeye.ts +232 -0
- package/src/analytics/birdeye/types/api/common.ts +305 -0
- package/src/analytics/birdeye/types/api/defi.ts +220 -0
- package/src/analytics/birdeye/types/api/pair.ts +200 -0
- package/src/analytics/birdeye/types/api/search.ts +86 -0
- package/src/analytics/birdeye/types/api/token.ts +635 -0
- package/src/analytics/birdeye/types/api/trader.ts +76 -0
- package/src/analytics/birdeye/types/api/wallet.ts +181 -0
- package/src/analytics/birdeye/types/shared.ts +106 -0
- package/src/analytics/birdeye/utils.ts +700 -0
- package/src/analytics/dexscreener/errors.ts +28 -0
- package/src/analytics/dexscreener/index.ts +3 -0
- package/src/analytics/dexscreener/search-category.test.ts +49 -0
- package/src/analytics/dexscreener/search-category.ts +42 -0
- package/src/analytics/dexscreener/service.ts +595 -0
- package/src/analytics/dexscreener/types.ts +128 -0
- package/src/analytics/lpinfo/index.d.ts +7 -0
- package/src/analytics/lpinfo/index.ts +52 -0
- package/src/analytics/lpinfo/kamino/README.md +102 -0
- package/src/analytics/lpinfo/kamino/index.ts +24 -0
- package/src/analytics/lpinfo/kamino/providers/kaminoLiquidityProvider.ts +422 -0
- package/src/analytics/lpinfo/kamino/providers/kaminoPoolProvider.ts +365 -0
- package/src/analytics/lpinfo/kamino/providers/kaminoProvider.ts +496 -0
- package/src/analytics/lpinfo/kamino/services/kaminoLiquidityService.ts +1123 -0
- package/src/analytics/lpinfo/kamino/services/kaminoService.ts +758 -0
- package/src/analytics/lpinfo/steer/README.md +169 -0
- package/src/analytics/lpinfo/steer/index.ts +23 -0
- package/src/analytics/lpinfo/steer/providers/steerLiquidityProvider.ts +544 -0
- package/src/analytics/lpinfo/steer/services/steerLiquidityService.ts +1690 -0
- package/src/analytics/lpinfo/steer/steer-display-types.ts +99 -0
- package/src/analytics/news/index.ts +52 -0
- package/src/analytics/news/interfaces/types.ts +222 -0
- package/src/analytics/news/providers/defiNewsProvider.ts +734 -0
- package/src/analytics/news/services/newsDataService.ts +332 -0
- package/src/analytics/news/utils/formatters.ts +151 -0
- package/src/analytics/token-info/action.ts +240 -0
- package/src/analytics/token-info/index.ts +3 -0
- package/src/analytics/token-info/params.ts +215 -0
- package/src/analytics/token-info/providers.ts +681 -0
- package/src/analytics/token-info/service.ts +168 -0
- package/src/analytics/token-info/types.ts +74 -0
- package/src/audit/audit-log.ts +45 -0
- package/src/browser-shim/build-shim.ts +123 -0
- package/src/browser-shim/index.ts +5 -0
- package/src/browser-shim/shim.template.js +563 -0
- package/src/chains/evm/.github/workflows/npm-deploy.yml +112 -0
- package/src/chains/evm/LICENSE +21 -0
- package/src/chains/evm/README.md +106 -0
- package/src/chains/evm/actions/helpers.ts +147 -0
- package/src/chains/evm/actions/swap.ts +839 -0
- package/src/chains/evm/actions/transfer.ts +254 -0
- package/src/chains/evm/biome.json +61 -0
- package/src/chains/evm/bridge-router.ts +660 -0
- package/src/chains/evm/build.ts +89 -0
- package/src/chains/evm/chain-handler.ts +416 -0
- package/src/chains/evm/constants.ts +23 -0
- package/src/chains/evm/contracts/artifacts/OZGovernor.json +1707 -0
- package/src/chains/evm/contracts/artifacts/TimelockController.json +1007 -0
- package/src/chains/evm/contracts/artifacts/VoteToken.json +895 -0
- package/src/chains/evm/dex/aerodrome/index.ts +34 -0
- package/src/chains/evm/dex/aerodrome/services/AerodromeLpService.ts +558 -0
- package/src/chains/evm/dex/aerodrome/types.ts +318 -0
- package/src/chains/evm/dex/pancakeswp/index.ts +35 -0
- package/src/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.ts +743 -0
- package/src/chains/evm/dex/pancakeswp/types.ts +65 -0
- package/src/chains/evm/dex/uniswap/index.ts +35 -0
- package/src/chains/evm/dex/uniswap/services/UniswapV3LpService.ts +759 -0
- package/src/chains/evm/dex/uniswap/types.ts +390 -0
- package/src/chains/evm/generated/specs/spec-helpers.ts +73 -0
- package/src/chains/evm/generated/specs/specs.ts +151 -0
- package/src/chains/evm/gov-router.ts +250 -0
- package/src/chains/evm/index.browser.ts +16 -0
- package/src/chains/evm/index.ts +31 -0
- package/src/chains/evm/prompts.ts +193 -0
- package/src/chains/evm/providers/get-balance.ts +123 -0
- package/src/chains/evm/providers/wallet.ts +715 -0
- package/src/chains/evm/routes/sign.ts +333 -0
- package/src/chains/evm/rpc-providers.ts +410 -0
- package/src/chains/evm/service.ts +140 -0
- package/src/chains/evm/templates/index.ts +10 -0
- package/src/chains/evm/types/index.ts +432 -0
- package/src/chains/evm/vitest.config.ts +18 -0
- package/src/chains/registry.ts +668 -0
- package/src/chains/solana/README.md +367 -0
- package/src/chains/wallet-action.ts +533 -0
- package/src/chains/wallet-router.test.ts +296 -0
- package/src/contracts.ts +65 -0
- package/src/core-augmentation.ts +10 -0
- package/src/index.ts +71 -0
- package/src/lib/server-wallet-trade.ts +192 -0
- package/src/lib/wallet-export-guard.ts +330 -0
- package/src/lp/actions/liquidity.ts +827 -0
- package/src/lp/e2e/real-token-tests.ts +428 -0
- package/src/lp/e2e/scenarios.ts +470 -0
- package/src/lp/e2e/test-utils.ts +145 -0
- package/src/lp/lp-manager-entry.ts +303 -0
- package/src/lp/services/ConcentratedLiquidityService.ts +120 -0
- package/src/lp/services/DexInteractionService.ts +226 -0
- package/src/lp/services/LpManagementService.test.ts +148 -0
- package/src/lp/services/LpManagementService.ts +632 -0
- package/src/lp/services/UserLpProfileService.ts +163 -0
- package/src/lp/services/VaultService.ts +153 -0
- package/src/lp/services/YieldOptimizationService.ts +344 -0
- package/src/lp/services/__tests__/MockLpService.ts +146 -0
- package/src/lp/tasks/LpAutoRebalanceTask.ts +117 -0
- package/src/lp/tasks/__tests__/LpAutoRebalanceTask.test.ts +370 -0
- package/src/lp/types.ts +582 -0
- package/src/lp/utils/solanaClient.ts +143 -0
- package/src/plugin.ts +125 -0
- package/src/policy/policy.ts +19 -0
- package/src/providers/canonical-provider.ts +27 -0
- package/src/providers/unified-wallet-provider.ts +79 -0
- package/src/register-routes.ts +11 -0
- package/src/routes/plugin.ts +47 -0
- package/src/routes/wallet-market-overview-route.ts +869 -0
- package/src/sdk/abi.ts +258 -0
- package/src/sdk/bridge/abis.ts +126 -0
- package/src/sdk/bridge/client.ts +518 -0
- package/src/sdk/bridge/index.ts +56 -0
- package/src/sdk/bridge/solana.ts +604 -0
- package/src/sdk/bridge/types.ts +202 -0
- package/src/sdk/convenience.ts +347 -0
- package/src/sdk/escrow/MutualStakeEscrow.ts +480 -0
- package/src/sdk/escrow/types.ts +64 -0
- package/src/sdk/escrow/verifiers.ts +73 -0
- package/src/sdk/identity/erc8004.ts +692 -0
- package/src/sdk/identity/reputation.ts +449 -0
- package/src/sdk/identity/uaid.ts +497 -0
- package/src/sdk/identity/validation.ts +372 -0
- package/src/sdk/index.ts +763 -0
- package/src/sdk/policy/SpendingPolicy.ts +260 -0
- package/src/sdk/policy/UptoBillingPolicy.ts +320 -0
- package/src/sdk/router/PaymentRouter.ts +215 -0
- package/src/sdk/router/index.ts +8 -0
- package/src/sdk/swap/SwapModule.ts +310 -0
- package/src/sdk/swap/abi.ts +117 -0
- package/src/sdk/swap/index.ts +34 -0
- package/src/sdk/swap/types.ts +135 -0
- package/src/sdk/tokens/decimals.ts +140 -0
- package/src/sdk/tokens/registry.ts +911 -0
- package/src/sdk/tokens/solana.ts +419 -0
- package/src/sdk/tokens/transfers.ts +327 -0
- package/src/sdk/types.ts +158 -0
- package/src/sdk/wallet-core.ts +115 -0
- package/src/sdk/x402/budget.ts +168 -0
- package/src/sdk/x402/chains/abstract/index.ts +280 -0
- package/src/sdk/x402/client.ts +320 -0
- package/src/sdk/x402/index.ts +46 -0
- package/src/sdk/x402/middleware.ts +92 -0
- package/src/sdk/x402/multi-asset.ts +144 -0
- package/src/sdk/x402/types.ts +156 -0
- package/src/services/wallet-backend-service.ts +328 -0
- package/src/types/wallet-router.ts +227 -0
- package/src/utils/intent-trajectory.ts +106 -0
- package/src/wallet/backend.ts +62 -0
- package/src/wallet/errors.ts +49 -0
- package/src/wallet/index.ts +27 -0
- package/src/wallet/local-eoa-backend.ts +201 -0
- package/src/wallet/pending.ts +60 -0
- package/src/wallet/select-backend.ts +47 -0
- package/src/wallet/steward-backend.ts +161 -0
- package/src/wallet-action.ts +1 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import type { Route, Token } from "@lifi/sdk";
|
|
2
|
+
import type {
|
|
3
|
+
Account,
|
|
4
|
+
Address,
|
|
5
|
+
Chain,
|
|
6
|
+
Hash,
|
|
7
|
+
Hex,
|
|
8
|
+
HttpTransport,
|
|
9
|
+
Log,
|
|
10
|
+
PublicClient,
|
|
11
|
+
WalletClient,
|
|
12
|
+
} from "viem";
|
|
13
|
+
import * as viemChains from "viem/chains";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
|
|
16
|
+
const SUPPORTED_CHAIN_NAMES = Object.keys(viemChains) as ReadonlyArray<keyof typeof viemChains>;
|
|
17
|
+
|
|
18
|
+
export type SupportedChain = keyof typeof viemChains;
|
|
19
|
+
|
|
20
|
+
export const SupportedChainSchema = z.enum(
|
|
21
|
+
SUPPORTED_CHAIN_NAMES as [string, ...string[]]
|
|
22
|
+
) as z.ZodType<SupportedChain>;
|
|
23
|
+
|
|
24
|
+
export function getChainByName(chainName: string): Chain {
|
|
25
|
+
const chain = (viemChains as Record<string, Chain>)[chainName];
|
|
26
|
+
if (!chain) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Invalid chain name: ${chainName}. Valid chains: ${SUPPORTED_CHAIN_NAMES.slice(0, 10).join(", ")}...`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return chain;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const AddressSchema = z
|
|
35
|
+
.string()
|
|
36
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
37
|
+
.transform((addr) => addr as Address);
|
|
38
|
+
|
|
39
|
+
export const HashSchema = z
|
|
40
|
+
.string()
|
|
41
|
+
.regex(/^0x[a-fA-F0-9]{64}$/, "Invalid transaction hash format")
|
|
42
|
+
.transform((hash) => hash as Hash);
|
|
43
|
+
|
|
44
|
+
export const HexSchema = z
|
|
45
|
+
.string()
|
|
46
|
+
.regex(/^0x[a-fA-F0-9]*$/, "Invalid hex data format")
|
|
47
|
+
.transform((hex) => hex as Hex);
|
|
48
|
+
|
|
49
|
+
export const PrivateKeySchema = z
|
|
50
|
+
.string()
|
|
51
|
+
.regex(/^0x[a-fA-F0-9]{64}$/, "Invalid private key format")
|
|
52
|
+
.transform((key) => key as `0x${string}`);
|
|
53
|
+
|
|
54
|
+
export const AmountSchema = z.string().refine(
|
|
55
|
+
(val) => {
|
|
56
|
+
const num = parseFloat(val);
|
|
57
|
+
return !Number.isNaN(num) && num > 0;
|
|
58
|
+
},
|
|
59
|
+
{ message: "Amount must be a positive number" }
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
export const OptionalAmountSchema = z
|
|
63
|
+
.string()
|
|
64
|
+
.optional()
|
|
65
|
+
.refine(
|
|
66
|
+
(val) => {
|
|
67
|
+
if (val === undefined) return true;
|
|
68
|
+
const num = parseFloat(val);
|
|
69
|
+
return !Number.isNaN(num) && num > 0;
|
|
70
|
+
},
|
|
71
|
+
{ message: "If provided, amount must be a positive number" }
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
export interface Transaction {
|
|
75
|
+
readonly hash: Hash;
|
|
76
|
+
readonly from: Address;
|
|
77
|
+
readonly to: Address;
|
|
78
|
+
readonly value: bigint;
|
|
79
|
+
readonly data?: Hex;
|
|
80
|
+
readonly chainId?: number;
|
|
81
|
+
readonly logs?: readonly Log[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const TransactionSchema = z.object({
|
|
85
|
+
hash: HashSchema,
|
|
86
|
+
from: AddressSchema,
|
|
87
|
+
to: AddressSchema,
|
|
88
|
+
value: z.bigint(),
|
|
89
|
+
data: HexSchema.optional(),
|
|
90
|
+
chainId: z.number().int().positive().optional(),
|
|
91
|
+
logs: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export interface TokenWithBalance {
|
|
95
|
+
readonly token: Token;
|
|
96
|
+
readonly balance: bigint;
|
|
97
|
+
readonly formattedBalance: string;
|
|
98
|
+
readonly priceUSD: string;
|
|
99
|
+
readonly valueUSD: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface WalletBalance {
|
|
103
|
+
readonly chain: SupportedChain;
|
|
104
|
+
readonly address: Address;
|
|
105
|
+
readonly totalValueUSD: string;
|
|
106
|
+
readonly tokens: readonly TokenWithBalance[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface TokenData extends Token {
|
|
110
|
+
readonly symbol: string;
|
|
111
|
+
readonly decimals: number;
|
|
112
|
+
readonly address: Address;
|
|
113
|
+
readonly name: string;
|
|
114
|
+
readonly logoURI?: string;
|
|
115
|
+
readonly chainId: number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface TransferParams {
|
|
119
|
+
readonly fromChain: SupportedChain;
|
|
120
|
+
readonly toAddress: Address;
|
|
121
|
+
readonly amount: string;
|
|
122
|
+
readonly data?: Hex;
|
|
123
|
+
readonly token?: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const TransferParamsSchema = z.object({
|
|
127
|
+
fromChain: SupportedChainSchema,
|
|
128
|
+
toAddress: AddressSchema,
|
|
129
|
+
amount: AmountSchema,
|
|
130
|
+
data: HexSchema.optional().default("0x"),
|
|
131
|
+
token: z.string().optional(),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export function parseTransferParams(input: unknown): TransferParams {
|
|
135
|
+
return TransferParamsSchema.parse(input) as TransferParams;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface SwapParams {
|
|
139
|
+
readonly chain: SupportedChain;
|
|
140
|
+
readonly fromToken: Address;
|
|
141
|
+
readonly toToken: Address;
|
|
142
|
+
readonly amount: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const SwapParamsSchema = z.object({
|
|
146
|
+
chain: SupportedChainSchema,
|
|
147
|
+
fromToken: z.union([AddressSchema, z.string().min(1)]),
|
|
148
|
+
toToken: z.union([AddressSchema, z.string().min(1)]),
|
|
149
|
+
amount: AmountSchema,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export function parseSwapParams(input: unknown): SwapParams {
|
|
153
|
+
return SwapParamsSchema.parse(input) as SwapParams;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface BebopRoute {
|
|
157
|
+
readonly data: string;
|
|
158
|
+
readonly approvalTarget: Address;
|
|
159
|
+
readonly sellAmount: string;
|
|
160
|
+
readonly from: Address;
|
|
161
|
+
readonly to: Address;
|
|
162
|
+
readonly value: string;
|
|
163
|
+
readonly gas: string;
|
|
164
|
+
readonly gasPrice: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const BebopRouteSchema = z.object({
|
|
168
|
+
data: z.string(),
|
|
169
|
+
approvalTarget: AddressSchema,
|
|
170
|
+
sellAmount: z.string(),
|
|
171
|
+
from: AddressSchema,
|
|
172
|
+
to: AddressSchema,
|
|
173
|
+
value: z.string(),
|
|
174
|
+
gas: z.string(),
|
|
175
|
+
gasPrice: z.string(),
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
export interface SwapQuote {
|
|
179
|
+
readonly aggregator: "lifi" | "bebop";
|
|
180
|
+
readonly minOutputAmount: string;
|
|
181
|
+
readonly swapData: Route | BebopRoute;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface BridgeParams {
|
|
185
|
+
readonly fromChain: SupportedChain;
|
|
186
|
+
readonly toChain: SupportedChain;
|
|
187
|
+
readonly fromToken: Address;
|
|
188
|
+
readonly toToken: Address;
|
|
189
|
+
readonly amount: string;
|
|
190
|
+
readonly toAddress?: Address;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export const BridgeParamsSchema = z.object({
|
|
194
|
+
fromChain: SupportedChainSchema,
|
|
195
|
+
toChain: SupportedChainSchema,
|
|
196
|
+
fromToken: z.union([AddressSchema, z.string().min(1)]),
|
|
197
|
+
toToken: z.union([AddressSchema, z.string().min(1)]),
|
|
198
|
+
amount: AmountSchema,
|
|
199
|
+
toAddress: AddressSchema.optional(),
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
export function parseBridgeParams(input: unknown): BridgeParams {
|
|
203
|
+
return BridgeParamsSchema.parse(input) as BridgeParams;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface ChainMetadata {
|
|
207
|
+
readonly chainId: number;
|
|
208
|
+
readonly name: string;
|
|
209
|
+
readonly chain: Chain;
|
|
210
|
+
readonly rpcUrl: string;
|
|
211
|
+
readonly nativeCurrency: {
|
|
212
|
+
readonly name: string;
|
|
213
|
+
readonly symbol: string;
|
|
214
|
+
readonly decimals: number;
|
|
215
|
+
};
|
|
216
|
+
readonly blockExplorerUrl: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface ChainConfig {
|
|
220
|
+
readonly chain: Chain;
|
|
221
|
+
readonly publicClient: PublicClient<HttpTransport, Chain, Account | undefined>;
|
|
222
|
+
readonly walletClient?: WalletClient;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface RpcUrlConfig {
|
|
226
|
+
readonly ethereum?: string;
|
|
227
|
+
readonly base?: string;
|
|
228
|
+
readonly arbitrum?: string;
|
|
229
|
+
readonly optimism?: string;
|
|
230
|
+
readonly polygon?: string;
|
|
231
|
+
readonly avalanche?: string;
|
|
232
|
+
readonly bsc?: string;
|
|
233
|
+
readonly sepolia?: string;
|
|
234
|
+
readonly [key: string]: string | undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface EvmPluginConfig {
|
|
238
|
+
readonly rpcUrl?: RpcUrlConfig;
|
|
239
|
+
readonly secrets?: {
|
|
240
|
+
readonly EVM_PRIVATE_KEY: string;
|
|
241
|
+
};
|
|
242
|
+
readonly testMode?: boolean;
|
|
243
|
+
readonly multicall?: {
|
|
244
|
+
readonly batchSize?: number;
|
|
245
|
+
readonly wait?: number;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export const EvmPluginConfigSchema = z.object({
|
|
250
|
+
rpcUrl: z.record(z.string(), z.string().url().optional()).optional(),
|
|
251
|
+
secrets: z
|
|
252
|
+
.object({
|
|
253
|
+
EVM_PRIVATE_KEY: PrivateKeySchema,
|
|
254
|
+
})
|
|
255
|
+
.optional(),
|
|
256
|
+
testMode: z.boolean().optional(),
|
|
257
|
+
multicall: z
|
|
258
|
+
.object({
|
|
259
|
+
batchSize: z.number().int().positive().optional(),
|
|
260
|
+
wait: z.number().int().nonnegative().optional(),
|
|
261
|
+
})
|
|
262
|
+
.optional(),
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
export enum VoteType {
|
|
266
|
+
AGAINST = 0,
|
|
267
|
+
FOR = 1,
|
|
268
|
+
ABSTAIN = 2,
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export const VoteTypeSchema = z.enum(VoteType);
|
|
272
|
+
|
|
273
|
+
export interface Proposal {
|
|
274
|
+
readonly targets: readonly Address[];
|
|
275
|
+
readonly values: readonly bigint[];
|
|
276
|
+
readonly calldatas: readonly Hex[];
|
|
277
|
+
readonly description: string;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export const ProposalSchema = z.object({
|
|
281
|
+
targets: z.array(AddressSchema).min(1),
|
|
282
|
+
values: z.array(z.bigint()),
|
|
283
|
+
calldatas: z.array(HexSchema),
|
|
284
|
+
description: z.string().min(1),
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
export interface VoteParams {
|
|
288
|
+
readonly chain: SupportedChain;
|
|
289
|
+
readonly governor: Address;
|
|
290
|
+
readonly proposalId: string;
|
|
291
|
+
readonly support: VoteType;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export const VoteParamsSchema = z.object({
|
|
295
|
+
chain: SupportedChainSchema,
|
|
296
|
+
governor: AddressSchema,
|
|
297
|
+
proposalId: z.string().min(1),
|
|
298
|
+
support: VoteTypeSchema,
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
export function parseVoteParams(input: unknown): VoteParams {
|
|
302
|
+
return VoteParamsSchema.parse(input) as VoteParams;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export interface QueueProposalParams extends Proposal {
|
|
306
|
+
readonly chain: SupportedChain;
|
|
307
|
+
readonly governor: Address;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export const QueueProposalParamsSchema = ProposalSchema.extend({
|
|
311
|
+
chain: SupportedChainSchema,
|
|
312
|
+
governor: AddressSchema,
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
export interface ExecuteProposalParams extends Proposal {
|
|
316
|
+
readonly chain: SupportedChain;
|
|
317
|
+
readonly governor: Address;
|
|
318
|
+
readonly proposalId: string;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface ProposeProposalParams extends Proposal {
|
|
322
|
+
readonly chain: SupportedChain;
|
|
323
|
+
readonly governor: Address;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface LiFiStatus {
|
|
327
|
+
readonly status: "PENDING" | "DONE" | "FAILED";
|
|
328
|
+
readonly substatus?: string;
|
|
329
|
+
readonly error?: Error;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export const LiFiStatusSchema = z.object({
|
|
333
|
+
status: z.enum(["PENDING", "DONE", "FAILED"]),
|
|
334
|
+
substatus: z.string().optional(),
|
|
335
|
+
error: z.instanceof(Error).optional(),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
export interface LiFiRoute {
|
|
339
|
+
readonly transactionHash: Hash;
|
|
340
|
+
readonly transactionData: Hex;
|
|
341
|
+
readonly toAddress: Address;
|
|
342
|
+
readonly status: LiFiStatus;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export interface TokenPriceResponse {
|
|
346
|
+
readonly priceUSD: string;
|
|
347
|
+
readonly token: TokenData;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface TokenListResponse {
|
|
351
|
+
readonly tokens: readonly TokenData[];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export interface ProviderError extends Error {
|
|
355
|
+
readonly code?: number;
|
|
356
|
+
readonly data?: Record<string, unknown>;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export const EVMErrorCode = {
|
|
360
|
+
INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS",
|
|
361
|
+
USER_REJECTED: "USER_REJECTED",
|
|
362
|
+
NETWORK_ERROR: "NETWORK_ERROR",
|
|
363
|
+
CONTRACT_REVERT: "CONTRACT_REVERT",
|
|
364
|
+
GAS_ESTIMATION_FAILED: "GAS_ESTIMATION_FAILED",
|
|
365
|
+
INVALID_PARAMS: "INVALID_PARAMS",
|
|
366
|
+
CHAIN_NOT_CONFIGURED: "CHAIN_NOT_CONFIGURED",
|
|
367
|
+
WALLET_NOT_INITIALIZED: "WALLET_NOT_INITIALIZED",
|
|
368
|
+
} as const;
|
|
369
|
+
|
|
370
|
+
export type EVMErrorCode = (typeof EVMErrorCode)[keyof typeof EVMErrorCode];
|
|
371
|
+
|
|
372
|
+
export class EVMError extends Error {
|
|
373
|
+
constructor(
|
|
374
|
+
public readonly code: EVMErrorCode,
|
|
375
|
+
message: string,
|
|
376
|
+
public readonly cause?: Error
|
|
377
|
+
) {
|
|
378
|
+
super(message);
|
|
379
|
+
this.name = "EVMError";
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function assertDefined<T>(value: T | null | undefined, message: string): asserts value is T {
|
|
384
|
+
if (value === null || value === undefined) {
|
|
385
|
+
throw new EVMError(EVMErrorCode.INVALID_PARAMS, message);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export function assertChainConfigured(
|
|
390
|
+
chains: Record<string, Chain>,
|
|
391
|
+
chainName: string
|
|
392
|
+
): asserts chains is Record<string, Chain> & {
|
|
393
|
+
[K in typeof chainName]: Chain;
|
|
394
|
+
} {
|
|
395
|
+
if (!(chainName in chains)) {
|
|
396
|
+
throw new EVMError(
|
|
397
|
+
EVMErrorCode.CHAIN_NOT_CONFIGURED,
|
|
398
|
+
`Chain "${chainName}" is not configured. Available chains: ${Object.keys(chains).join(", ")}`
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function formatZodError(error: z.ZodError<unknown>): string {
|
|
404
|
+
if (error.issues.length > 0) {
|
|
405
|
+
return error.issues[0].message;
|
|
406
|
+
}
|
|
407
|
+
return "Validation failed";
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function validateAddress(address: string): Address {
|
|
411
|
+
const result = AddressSchema.safeParse(address);
|
|
412
|
+
if (!result.success) {
|
|
413
|
+
throw new EVMError(
|
|
414
|
+
EVMErrorCode.INVALID_PARAMS,
|
|
415
|
+
`Invalid address: ${address}. ${formatZodError(result.error)}`
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
return result.data;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function validateHash(hash: string): Hash {
|
|
422
|
+
const result = HashSchema.safeParse(hash);
|
|
423
|
+
if (!result.success) {
|
|
424
|
+
throw new EVMError(
|
|
425
|
+
EVMErrorCode.INVALID_PARAMS,
|
|
426
|
+
`Invalid transaction hash: ${hash}. ${formatZodError(result.error)}`
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
return result.data;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export type { Address, Chain, Hash, Hex, Log } from "viem";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
environment: "node",
|
|
6
|
+
include: ["__tests__/**/*.test.ts", "src/**/*.test.ts"],
|
|
7
|
+
exclude: [
|
|
8
|
+
"**/node_modules/**",
|
|
9
|
+
"**/dist/**",
|
|
10
|
+
"**/*.live.test.ts",
|
|
11
|
+
"**/*.real.test.ts",
|
|
12
|
+
"**/*.e2e.test.ts",
|
|
13
|
+
"**/*.live.e2e.test.ts",
|
|
14
|
+
"**/*.real.e2e.test.ts",
|
|
15
|
+
],
|
|
16
|
+
passWithNoTests: true,
|
|
17
|
+
},
|
|
18
|
+
});
|