@cfxdevkit/defi-react 0.1.0 → 1.0.5
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/README.md +87 -0
- package/package.json +21 -20
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @cfxdevkit/defi-react
|
|
2
|
+
|
|
3
|
+
DeFi React hooks for Conflux DevKit — Swappi pool token resolution with on-chain balance enrichment.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **`usePoolTokens`** — Fetches the full Swappi token list from your backend, enriches each entry with the connected wallet's live on-chain balance (batched via Multicall3), and caches aggressively in `localStorage` so the UI is instant on re-mount.
|
|
8
|
+
- **`getPairedTokens`** — Filter helper to get all tokens paired with a given `tokenIn` address.
|
|
9
|
+
- **CFX native support** — A synthetic "CFX (native)" entry at the EIP-7528 sentinel address is included alongside the WCFX ERC-20.
|
|
10
|
+
- **Resilience** — Token/pair lists only grow, never shrink. A flaky RPC response that temporarily drops entries cannot remove them from the UI.
|
|
11
|
+
- **Contract constants** — Re-exports `AUTOMATION_MANAGER_ABI`, `ERC20_ABI`, `WCFX_ABI`, and `MAX_UINT256` for convenience.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @cfxdevkit/defi-react
|
|
17
|
+
# or
|
|
18
|
+
npm install @cfxdevkit/defi-react
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Peer dependencies
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"react": ">=18",
|
|
26
|
+
"viem": ">=2.0.0"
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### `usePoolTokens`
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { usePoolTokens } from '@cfxdevkit/defi-react';
|
|
36
|
+
|
|
37
|
+
function TokenSelector() {
|
|
38
|
+
const { tokens, pairs, isLoading, error } = usePoolTokens({
|
|
39
|
+
/** URL of your backend /api/pools endpoint */
|
|
40
|
+
poolsApiUrl: '/api/pools',
|
|
41
|
+
/** viem chain — confluxESpace or confluxESpaceTestnet */
|
|
42
|
+
chain: confluxESpace,
|
|
43
|
+
/** Connected wallet address (or undefined if not connected) */
|
|
44
|
+
address: walletAddress,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (isLoading) return <p>Loading tokens…</p>;
|
|
48
|
+
if (error) return <p>Error: {error.message}</p>;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<ul>
|
|
52
|
+
{tokens.map((t) => (
|
|
53
|
+
<li key={t.address}>
|
|
54
|
+
{t.symbol} — {t.balanceFormatted}
|
|
55
|
+
</li>
|
|
56
|
+
))}
|
|
57
|
+
</ul>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### `getPairedTokens`
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { getPairedTokens } from '@cfxdevkit/defi-react';
|
|
66
|
+
|
|
67
|
+
// Get all tokens that can be swapped with WCFX
|
|
68
|
+
const options = getPairedTokens(pairs, wcfxAddress);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Contract constants
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import {
|
|
75
|
+
AUTOMATION_MANAGER_ABI,
|
|
76
|
+
ERC20_ABI,
|
|
77
|
+
WCFX_ABI,
|
|
78
|
+
MAX_UINT256,
|
|
79
|
+
} from '@cfxdevkit/defi-react';
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Conflux Compatibility
|
|
83
|
+
|
|
84
|
+
| Network | Chain | Support |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| Conflux eSpace Mainnet | `confluxESpace` (1030) | ✅ |
|
|
87
|
+
| Conflux eSpace Testnet | `confluxESpaceTestnet` (71) | ✅ |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cfxdevkit/defi-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Conflux DevKit – DeFi React hooks for Swappi pool tokens and on-chain balances",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,6 +22,22 @@
|
|
|
22
22
|
},
|
|
23
23
|
"./package.json": "./package.json"
|
|
24
24
|
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"build:watch": "tsup --watch",
|
|
28
|
+
"type-check": "tsc --noEmit",
|
|
29
|
+
"dev": "tsup --watch",
|
|
30
|
+
"test": "vitest run --pass-with-no-tests",
|
|
31
|
+
"test:run": "vitest --run",
|
|
32
|
+
"test:coverage": "vitest --run --coverage --pass-with-no-tests",
|
|
33
|
+
"clean": "rm -rf dist",
|
|
34
|
+
"lint": "biome lint src/",
|
|
35
|
+
"lint:fix": "biome lint --write src/",
|
|
36
|
+
"format": "biome format src/",
|
|
37
|
+
"format:fix": "biome format --write src/",
|
|
38
|
+
"check": "biome check src/",
|
|
39
|
+
"check:fix": "biome check --write src/"
|
|
40
|
+
},
|
|
25
41
|
"dependencies": {},
|
|
26
42
|
"peerDependencies": {
|
|
27
43
|
"react": "^18.0.0",
|
|
@@ -53,29 +69,14 @@
|
|
|
53
69
|
],
|
|
54
70
|
"author": "Conflux DevKit Team",
|
|
55
71
|
"license": "Apache-2.0",
|
|
72
|
+
"packageManager": "pnpm@10.11.0",
|
|
56
73
|
"repository": {
|
|
57
74
|
"type": "git",
|
|
58
|
-
"url": "git+https://github.com/cfxdevkit/
|
|
75
|
+
"url": "git+https://github.com/cfxdevkit/devkit.git",
|
|
59
76
|
"directory": "packages/defi-react"
|
|
60
77
|
},
|
|
61
78
|
"homepage": "https://github.com/cfxdevkit/conflux-devkit#readme",
|
|
62
79
|
"bugs": {
|
|
63
|
-
"url": "https://github.com/cfxdevkit/
|
|
64
|
-
},
|
|
65
|
-
"scripts": {
|
|
66
|
-
"build": "tsup",
|
|
67
|
-
"build:watch": "tsup --watch",
|
|
68
|
-
"type-check": "tsc --noEmit",
|
|
69
|
-
"dev": "tsup --watch",
|
|
70
|
-
"test": "vitest run --pass-with-no-tests",
|
|
71
|
-
"test:run": "vitest --run",
|
|
72
|
-
"test:coverage": "vitest --run --coverage",
|
|
73
|
-
"clean": "rm -rf dist",
|
|
74
|
-
"lint": "biome lint src/",
|
|
75
|
-
"lint:fix": "biome lint --write src/",
|
|
76
|
-
"format": "biome format src/",
|
|
77
|
-
"format:fix": "biome format --write src/",
|
|
78
|
-
"check": "biome check src/",
|
|
79
|
-
"check:fix": "biome check --write src/"
|
|
80
|
+
"url": "https://github.com/cfxdevkit/devkit/issues"
|
|
80
81
|
}
|
|
81
|
-
}
|
|
82
|
+
}
|