@cfxdevkit/defi-react 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.
@@ -0,0 +1,377 @@
1
+ import { Address } from 'viem';
2
+
3
+ /**
4
+ * AutomationManager contract ABI (subset) and helpers.
5
+ *
6
+ * The full artifact lives at:
7
+ * contracts/artifacts/contracts/AutomationManager.sol/AutomationManager.json
8
+ *
9
+ * We only include the fragments needed by the frontend:
10
+ * - createLimitOrder
11
+ * - createDCAJob
12
+ * - JobCreated event
13
+ */
14
+
15
+ declare const AUTOMATION_MANAGER_ADDRESS: Address;
16
+ declare const ERC20_ABI: readonly [{
17
+ readonly type: "function";
18
+ readonly name: "allowance";
19
+ readonly stateMutability: "view";
20
+ readonly inputs: readonly [{
21
+ readonly name: "owner";
22
+ readonly type: "address";
23
+ }, {
24
+ readonly name: "spender";
25
+ readonly type: "address";
26
+ }];
27
+ readonly outputs: readonly [{
28
+ readonly name: "";
29
+ readonly type: "uint256";
30
+ }];
31
+ }, {
32
+ readonly type: "function";
33
+ readonly name: "approve";
34
+ readonly stateMutability: "nonpayable";
35
+ readonly inputs: readonly [{
36
+ readonly name: "spender";
37
+ readonly type: "address";
38
+ }, {
39
+ readonly name: "amount";
40
+ readonly type: "uint256";
41
+ }];
42
+ readonly outputs: readonly [{
43
+ readonly name: "";
44
+ readonly type: "bool";
45
+ }];
46
+ }];
47
+ declare const WCFX_ABI: readonly [{
48
+ readonly type: "function";
49
+ readonly name: "balanceOf";
50
+ readonly stateMutability: "view";
51
+ readonly inputs: readonly [{
52
+ readonly name: "account";
53
+ readonly type: "address";
54
+ }];
55
+ readonly outputs: readonly [{
56
+ readonly name: "";
57
+ readonly type: "uint256";
58
+ }];
59
+ }, {
60
+ readonly type: "function";
61
+ readonly name: "allowance";
62
+ readonly stateMutability: "view";
63
+ readonly inputs: readonly [{
64
+ readonly name: "owner";
65
+ readonly type: "address";
66
+ }, {
67
+ readonly name: "spender";
68
+ readonly type: "address";
69
+ }];
70
+ readonly outputs: readonly [{
71
+ readonly name: "";
72
+ readonly type: "uint256";
73
+ }];
74
+ }, {
75
+ readonly type: "function";
76
+ readonly name: "approve";
77
+ readonly stateMutability: "nonpayable";
78
+ readonly inputs: readonly [{
79
+ readonly name: "spender";
80
+ readonly type: "address";
81
+ }, {
82
+ readonly name: "amount";
83
+ readonly type: "uint256";
84
+ }];
85
+ readonly outputs: readonly [{
86
+ readonly name: "";
87
+ readonly type: "bool";
88
+ }];
89
+ }, {
90
+ readonly type: "function";
91
+ readonly name: "deposit";
92
+ readonly stateMutability: "payable";
93
+ readonly inputs: readonly [];
94
+ readonly outputs: readonly [];
95
+ }, {
96
+ readonly type: "function";
97
+ readonly name: "withdraw";
98
+ readonly stateMutability: "nonpayable";
99
+ readonly inputs: readonly [{
100
+ readonly name: "wad";
101
+ readonly type: "uint256";
102
+ }];
103
+ readonly outputs: readonly [];
104
+ }];
105
+ /** Max uint256 — used as an unlimited approval amount for DCA jobs. */
106
+ declare const MAX_UINT256: bigint;
107
+ declare const AUTOMATION_MANAGER_ABI: readonly [{
108
+ readonly type: "error";
109
+ readonly name: "DCACompleted";
110
+ readonly inputs: readonly [{
111
+ readonly name: "jobId";
112
+ readonly type: "bytes32";
113
+ }];
114
+ }, {
115
+ readonly type: "error";
116
+ readonly name: "DCAIntervalNotReached";
117
+ readonly inputs: readonly [{
118
+ readonly name: "nextExecution";
119
+ readonly type: "uint256";
120
+ }];
121
+ }, {
122
+ readonly type: "error";
123
+ readonly name: "EnforcedPause";
124
+ readonly inputs: readonly [];
125
+ }, {
126
+ readonly type: "error";
127
+ readonly name: "ExpectedPause";
128
+ readonly inputs: readonly [];
129
+ }, {
130
+ readonly type: "error";
131
+ readonly name: "InvalidParams";
132
+ readonly inputs: readonly [{
133
+ readonly name: "reason";
134
+ readonly type: "string";
135
+ }];
136
+ }, {
137
+ readonly type: "error";
138
+ readonly name: "JobExpiredError";
139
+ readonly inputs: readonly [{
140
+ readonly name: "jobId";
141
+ readonly type: "bytes32";
142
+ }];
143
+ }, {
144
+ readonly type: "error";
145
+ readonly name: "JobNotActive";
146
+ readonly inputs: readonly [{
147
+ readonly name: "jobId";
148
+ readonly type: "bytes32";
149
+ }];
150
+ }, {
151
+ readonly type: "error";
152
+ readonly name: "JobNotFound";
153
+ readonly inputs: readonly [{
154
+ readonly name: "jobId";
155
+ readonly type: "bytes32";
156
+ }];
157
+ }, {
158
+ readonly type: "error";
159
+ readonly name: "OwnableInvalidOwner";
160
+ readonly inputs: readonly [{
161
+ readonly name: "owner";
162
+ readonly type: "address";
163
+ }];
164
+ }, {
165
+ readonly type: "error";
166
+ readonly name: "OwnableUnauthorizedAccount";
167
+ readonly inputs: readonly [{
168
+ readonly name: "account";
169
+ readonly type: "address";
170
+ }];
171
+ }, {
172
+ readonly type: "error";
173
+ readonly name: "PriceConditionNotMet";
174
+ readonly inputs: readonly [{
175
+ readonly name: "jobId";
176
+ readonly type: "bytes32";
177
+ }];
178
+ }, {
179
+ readonly type: "error";
180
+ readonly name: "ReentrancyGuardReentrantCall";
181
+ readonly inputs: readonly [];
182
+ }, {
183
+ readonly type: "error";
184
+ readonly name: "SafeERC20FailedOperation";
185
+ readonly inputs: readonly [{
186
+ readonly name: "token";
187
+ readonly type: "address";
188
+ }];
189
+ }, {
190
+ readonly type: "error";
191
+ readonly name: "SlippageTooHigh";
192
+ readonly inputs: readonly [{
193
+ readonly name: "requested";
194
+ readonly type: "uint256";
195
+ }, {
196
+ readonly name: "maxAllowed";
197
+ readonly type: "uint256";
198
+ }];
199
+ }, {
200
+ readonly type: "error";
201
+ readonly name: "TooManyJobs";
202
+ readonly inputs: readonly [{
203
+ readonly name: "user";
204
+ readonly type: "address";
205
+ }];
206
+ }, {
207
+ readonly type: "error";
208
+ readonly name: "Unauthorized";
209
+ readonly inputs: readonly [];
210
+ }, {
211
+ readonly type: "error";
212
+ readonly name: "ZeroAddress";
213
+ readonly inputs: readonly [];
214
+ }, {
215
+ readonly type: "event";
216
+ readonly name: "JobCreated";
217
+ readonly anonymous: false;
218
+ readonly inputs: readonly [{
219
+ readonly indexed: true;
220
+ readonly name: "jobId";
221
+ readonly type: "bytes32";
222
+ }, {
223
+ readonly indexed: true;
224
+ readonly name: "owner";
225
+ readonly type: "address";
226
+ }, {
227
+ readonly indexed: false;
228
+ readonly name: "jobType";
229
+ readonly type: "uint8";
230
+ }];
231
+ }, {
232
+ readonly type: "function";
233
+ readonly name: "createLimitOrder";
234
+ readonly stateMutability: "nonpayable";
235
+ readonly inputs: readonly [{
236
+ readonly name: "params";
237
+ readonly type: "tuple";
238
+ readonly components: readonly [{
239
+ readonly name: "tokenIn";
240
+ readonly type: "address";
241
+ }, {
242
+ readonly name: "tokenOut";
243
+ readonly type: "address";
244
+ }, {
245
+ readonly name: "amountIn";
246
+ readonly type: "uint256";
247
+ }, {
248
+ readonly name: "minAmountOut";
249
+ readonly type: "uint256";
250
+ }, {
251
+ readonly name: "targetPrice";
252
+ readonly type: "uint256";
253
+ }, {
254
+ readonly name: "triggerAbove";
255
+ readonly type: "bool";
256
+ }];
257
+ }, {
258
+ readonly name: "slippageBps";
259
+ readonly type: "uint256";
260
+ }, {
261
+ readonly name: "expiresAt";
262
+ readonly type: "uint256";
263
+ }];
264
+ readonly outputs: readonly [{
265
+ readonly name: "jobId";
266
+ readonly type: "bytes32";
267
+ }];
268
+ }, {
269
+ readonly type: "function";
270
+ readonly name: "createDCAJob";
271
+ readonly stateMutability: "nonpayable";
272
+ readonly inputs: readonly [{
273
+ readonly name: "params";
274
+ readonly type: "tuple";
275
+ readonly components: readonly [{
276
+ readonly name: "tokenIn";
277
+ readonly type: "address";
278
+ }, {
279
+ readonly name: "tokenOut";
280
+ readonly type: "address";
281
+ }, {
282
+ readonly name: "amountPerSwap";
283
+ readonly type: "uint256";
284
+ }, {
285
+ readonly name: "intervalSeconds";
286
+ readonly type: "uint256";
287
+ }, {
288
+ readonly name: "totalSwaps";
289
+ readonly type: "uint256";
290
+ }, {
291
+ readonly name: "swapsCompleted";
292
+ readonly type: "uint256";
293
+ }, {
294
+ readonly name: "nextExecution";
295
+ readonly type: "uint256";
296
+ }];
297
+ }, {
298
+ readonly name: "slippageBps";
299
+ readonly type: "uint256";
300
+ }, {
301
+ readonly name: "expiresAt";
302
+ readonly type: "uint256";
303
+ }];
304
+ readonly outputs: readonly [{
305
+ readonly name: "jobId";
306
+ readonly type: "bytes32";
307
+ }];
308
+ }, {
309
+ readonly type: "function";
310
+ readonly name: "cancelJob";
311
+ readonly stateMutability: "nonpayable";
312
+ readonly inputs: readonly [{
313
+ readonly name: "jobId";
314
+ readonly type: "bytes32";
315
+ }];
316
+ readonly outputs: readonly [];
317
+ }, {
318
+ readonly type: "event";
319
+ readonly name: "JobCancelled";
320
+ readonly anonymous: false;
321
+ readonly inputs: readonly [{
322
+ readonly indexed: true;
323
+ readonly name: "jobId";
324
+ readonly type: "bytes32";
325
+ }, {
326
+ readonly indexed: true;
327
+ readonly name: "canceller";
328
+ readonly type: "address";
329
+ }];
330
+ }];
331
+
332
+ interface TokenWithBalance {
333
+ address: string;
334
+ symbol: string;
335
+ name: string;
336
+ /**
337
+ * Token decimals — `null` when GeckoTerminal did not publish them.
338
+ * Consumers that need an accurate value for `parseUnits` / `formatUnits`
339
+ * should fall back to an on-chain `decimals()` read when this is null.
340
+ * Display-only callers can safely fall back to 18.
341
+ */
342
+ decimals: number | null;
343
+ /** Token logo image URL (from GeckoTerminal), if available */
344
+ logoURI?: string;
345
+ /** Raw wei balance as string, '0' if no wallet connected */
346
+ balanceWei: string;
347
+ /** Human-readable balance, e.g. '123.45' */
348
+ balanceFormatted: string;
349
+ }
350
+ interface PairInfo {
351
+ address: string;
352
+ token0: string;
353
+ token1: string;
354
+ }
355
+ interface UsePoolTokensResult {
356
+ tokens: TokenWithBalance[];
357
+ pairs: PairInfo[];
358
+ /** True only on first-ever load when there is no cached metadata yet. */
359
+ loading: boolean;
360
+ /** True while on-chain balances are being fetched (background enrichment). */
361
+ balancesLoading: boolean;
362
+ error: string | null;
363
+ /** Non-null when balance RPC calls partially or fully failed (quota/node issue). */
364
+ rpcWarning: string | null;
365
+ refresh: () => void;
366
+ }
367
+ declare const CFX_NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
368
+ declare function wcfxAddress(network?: string): string;
369
+ declare function resolveTokenInAddress(address: string): string;
370
+ /**
371
+ * Returns tokens that are paired with tokenInAddress.
372
+ * All address comparisons are case-insensitive.
373
+ */
374
+ declare function getPairedTokens(pairs: PairInfo[], allTokens: TokenWithBalance[], tokenInAddress: string): TokenWithBalance[];
375
+ declare function usePoolTokens(userAddress: string | undefined): UsePoolTokensResult;
376
+
377
+ export { AUTOMATION_MANAGER_ABI, AUTOMATION_MANAGER_ADDRESS, CFX_NATIVE_ADDRESS, ERC20_ABI, MAX_UINT256, type PairInfo, type TokenWithBalance, type UsePoolTokensResult, WCFX_ABI, getPairedTokens, resolveTokenInAddress, usePoolTokens, wcfxAddress };