fibx 0.1.0 → 0.1.2
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 +39 -47
- package/dist/commands/auth/login.d.ts +3 -0
- package/dist/commands/auth/login.d.ts.map +1 -0
- package/dist/commands/auth/login.js +34 -0
- package/dist/commands/auth/login.js.map +1 -0
- package/dist/commands/auth/verify.d.ts +3 -0
- package/dist/commands/auth/verify.d.ts.map +1 -0
- package/dist/commands/auth/verify.js +61 -0
- package/dist/commands/auth/verify.js.map +1 -0
- package/dist/commands/balance.d.ts.map +1 -1
- package/dist/commands/balance.js +27 -8
- package/dist/commands/balance.js.map +1 -1
- package/dist/commands/trade/status.d.ts +3 -0
- package/dist/commands/trade/status.d.ts.map +1 -0
- package/dist/commands/trade/status.js +31 -0
- package/dist/commands/trade/status.js.map +1 -0
- package/dist/commands/trade/swap.d.ts +7 -0
- package/dist/commands/trade/swap.d.ts.map +1 -0
- package/dist/commands/trade/swap.js +69 -0
- package/dist/commands/trade/swap.js.map +1 -0
- package/dist/commands/wallet/address.d.ts +3 -0
- package/dist/commands/wallet/address.d.ts.map +1 -0
- package/dist/commands/wallet/address.js +15 -0
- package/dist/commands/wallet/address.js.map +1 -0
- package/dist/commands/wallet/balance.d.ts +3 -0
- package/dist/commands/wallet/balance.d.ts.map +1 -0
- package/dist/commands/wallet/balance.js +48 -0
- package/dist/commands/wallet/balance.js.map +1 -0
- package/dist/commands/wallet/list.d.ts +3 -0
- package/dist/commands/wallet/list.d.ts.map +1 -0
- package/dist/commands/wallet/list.js +39 -0
- package/dist/commands/wallet/list.js.map +1 -0
- package/dist/commands/wallet/send.d.ts +3 -0
- package/dist/commands/wallet/send.d.ts.map +1 -0
- package/dist/commands/wallet/send.js +58 -0
- package/dist/commands/wallet/send.js.map +1 -0
- package/dist/fibrous/balances.d.ts +14 -0
- package/dist/fibrous/balances.d.ts.map +1 -0
- package/dist/fibrous/balances.js +26 -0
- package/dist/fibrous/balances.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cache.d.ts +3 -0
- package/dist/lib/cache.d.ts.map +1 -0
- package/dist/lib/cache.js +23 -0
- package/dist/lib/cache.js.map +1 -0
- package/dist/lib/config.d.ts +7 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +8 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/errors.d.ts +22 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +29 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/format.d.ts +8 -0
- package/dist/lib/format.d.ts.map +1 -0
- package/dist/lib/format.js +69 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/parseAmount.d.ts +3 -0
- package/dist/lib/parseAmount.d.ts.map +1 -0
- package/dist/lib/parseAmount.js +10 -0
- package/dist/lib/parseAmount.js.map +1 -0
- package/dist/lib/validation.d.ts +6 -0
- package/dist/lib/validation.d.ts.map +1 -0
- package/dist/lib/validation.js +24 -0
- package/dist/lib/validation.js.map +1 -0
- package/dist/services/auth/policy.d.ts +2 -0
- package/dist/services/auth/policy.d.ts.map +1 -0
- package/dist/services/auth/policy.js +3 -0
- package/dist/services/auth/policy.js.map +1 -0
- package/dist/services/auth/session.d.ts +15 -0
- package/dist/services/auth/session.d.ts.map +1 -0
- package/dist/services/auth/session.js +47 -0
- package/dist/services/auth/session.js.map +1 -0
- package/dist/services/chain/client.d.ts +24029 -0
- package/dist/services/chain/client.d.ts.map +1 -0
- package/dist/services/chain/client.js +74 -0
- package/dist/services/chain/client.js.map +1 -0
- package/dist/services/chain/constants.d.ts +14 -0
- package/dist/services/chain/constants.d.ts.map +1 -0
- package/dist/services/chain/constants.js +21 -0
- package/dist/services/chain/constants.js.map +1 -0
- package/dist/services/chain/erc20.d.ts +6 -0
- package/dist/services/chain/erc20.d.ts.map +1 -0
- package/dist/services/chain/erc20.js +72 -0
- package/dist/services/chain/erc20.js.map +1 -0
- package/dist/services/fibrous/abi/base.d.ts +768 -0
- package/dist/services/fibrous/abi/base.d.ts.map +1 -0
- package/dist/services/fibrous/abi/base.js +984 -0
- package/dist/services/fibrous/abi/base.js.map +1 -0
- package/dist/services/fibrous/balances.d.ts +14 -0
- package/dist/services/fibrous/balances.d.ts.map +1 -0
- package/dist/services/fibrous/balances.js +26 -0
- package/dist/services/fibrous/balances.js.map +1 -0
- package/dist/services/fibrous/health.d.ts +11 -0
- package/dist/services/fibrous/health.d.ts.map +1 -0
- package/dist/services/fibrous/health.js +18 -0
- package/dist/services/fibrous/health.js.map +1 -0
- package/dist/services/fibrous/route.d.ts +47 -0
- package/dist/services/fibrous/route.d.ts.map +1 -0
- package/dist/services/fibrous/route.js +60 -0
- package/dist/services/fibrous/route.js.map +1 -0
- package/dist/services/fibrous/tokens.d.ts +10 -0
- package/dist/services/fibrous/tokens.d.ts.map +1 -0
- package/dist/services/fibrous/tokens.js +37 -0
- package/dist/services/fibrous/tokens.js.map +1 -0
- package/dist/services/privy/client.d.ts +15 -0
- package/dist/services/privy/client.d.ts.map +1 -0
- package/dist/services/privy/client.js +63 -0
- package/dist/services/privy/client.js.map +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
A command-line tool for specialized DeFi operations on **Base**, powered by [Fibrous Finance](https://fibrous.finance) aggregation and [Privy](https://privy.io) Server Wallets.
|
|
4
4
|
|
|
5
|
+
[](https://badge.fury.io/js/fibx)
|
|
6
|
+
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
9
|
- **Privy Server Wallets**: Uses "Agentic" server-side wallets (ownerless) for seamless, automated signing without user interaction.
|
|
@@ -18,25 +20,28 @@ A command-line tool for specialized DeFi operations on **Base**, powered by [Fib
|
|
|
18
20
|
|
|
19
21
|
## Quick Start
|
|
20
22
|
|
|
21
|
-
### 1.
|
|
23
|
+
### 1. Installation
|
|
24
|
+
|
|
25
|
+
You can use `fibx` without installation via `npx`, or install it globally.
|
|
26
|
+
|
|
27
|
+
**Option A: No Installation (Recommended for Agents)**
|
|
22
28
|
|
|
23
29
|
```bash
|
|
24
|
-
|
|
30
|
+
npx fibx <command>
|
|
25
31
|
```
|
|
26
32
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Copy the example environment file and add your Privy credentials:
|
|
33
|
+
**Option B: Global Install**
|
|
30
34
|
|
|
31
35
|
```bash
|
|
32
|
-
|
|
36
|
+
npm install -g fibx
|
|
37
|
+
fibx <command>
|
|
33
38
|
```
|
|
34
39
|
|
|
35
|
-
|
|
40
|
+
Set your Privy credentials as environment variables:
|
|
36
41
|
|
|
37
|
-
```
|
|
38
|
-
PRIVY_APP_ID=your_app_id
|
|
39
|
-
PRIVY_APP_SECRET=your_app_secret
|
|
42
|
+
```bash
|
|
43
|
+
export PRIVY_APP_ID="your_app_id"
|
|
44
|
+
export PRIVY_APP_SECRET="your_app_secret"
|
|
40
45
|
```
|
|
41
46
|
|
|
42
47
|
### 3. Authenticate & Provision Wallet
|
|
@@ -46,17 +51,17 @@ This two-step process links your email to a server-side wallet.
|
|
|
46
51
|
**Step 1: Request OTP**
|
|
47
52
|
|
|
48
53
|
```bash
|
|
49
|
-
|
|
54
|
+
npx fibx auth login <email>
|
|
50
55
|
# Example:
|
|
51
|
-
|
|
56
|
+
npx fibx auth login user@example.com
|
|
52
57
|
```
|
|
53
58
|
|
|
54
59
|
**Step 2: Verify & Create Session**
|
|
55
60
|
|
|
56
61
|
```bash
|
|
57
|
-
|
|
62
|
+
npx fibx auth verify <email> <code>
|
|
58
63
|
# Example:
|
|
59
|
-
|
|
64
|
+
npx fibx auth verify user@example.com 123456
|
|
60
65
|
```
|
|
61
66
|
|
|
62
67
|
_Successfully verifying will create a local session file and provision a Server Wallet if one doesn't exist._
|
|
@@ -66,7 +71,7 @@ _Successfully verifying will create a local session file and provision a Server
|
|
|
66
71
|
Verify that you are authenticated and the API is healthy:
|
|
67
72
|
|
|
68
73
|
```bash
|
|
69
|
-
|
|
74
|
+
npx fibx status
|
|
70
75
|
```
|
|
71
76
|
|
|
72
77
|
## Usage
|
|
@@ -76,7 +81,7 @@ pnpm dev status
|
|
|
76
81
|
View your ETH and USDC balances on Base:
|
|
77
82
|
|
|
78
83
|
```bash
|
|
79
|
-
|
|
84
|
+
npx fibx balance
|
|
80
85
|
```
|
|
81
86
|
|
|
82
87
|
### Send Tokens
|
|
@@ -86,13 +91,13 @@ Transfer ETH or ERC-20 tokens to another address.
|
|
|
86
91
|
**Send ETH (Default):**
|
|
87
92
|
|
|
88
93
|
```bash
|
|
89
|
-
|
|
94
|
+
npx fibx send 0.001 0xRecipientAddress
|
|
90
95
|
```
|
|
91
96
|
|
|
92
97
|
**Send ERC-20 (e.g., USDC):**
|
|
93
98
|
|
|
94
99
|
```bash
|
|
95
|
-
|
|
100
|
+
npx fibx send 10 0xRecipientAddress USDC
|
|
96
101
|
```
|
|
97
102
|
|
|
98
103
|
### Swap Tokens
|
|
@@ -100,17 +105,17 @@ pnpm dev send 10 0xRecipientAddress USDC
|
|
|
100
105
|
Swap tokens using Fibrous Finance's aggregator.
|
|
101
106
|
|
|
102
107
|
```bash
|
|
103
|
-
|
|
108
|
+
npx fibx trade <amount> <from_token> <to_token>
|
|
104
109
|
```
|
|
105
110
|
|
|
106
111
|
**Examples:**
|
|
107
112
|
|
|
108
113
|
```bash
|
|
109
114
|
# Swap 0.0001 ETH to USDC
|
|
110
|
-
|
|
115
|
+
npx fibx trade 0.0001 ETH USDC
|
|
111
116
|
|
|
112
117
|
# Swap 20 USDC to DAI
|
|
113
|
-
|
|
118
|
+
npx fibx trade 20 USDC DAI
|
|
114
119
|
```
|
|
115
120
|
|
|
116
121
|
**Options:**
|
|
@@ -123,37 +128,24 @@ pnpm dev trade 20 USDC DAI
|
|
|
123
128
|
Print your connected server wallet address:
|
|
124
129
|
|
|
125
130
|
```bash
|
|
126
|
-
|
|
131
|
+
npx fibx address
|
|
127
132
|
```
|
|
128
133
|
|
|
129
|
-
|
|
134
|
+
## Agent Skills
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
Looking to use `fibx` with an AI Agent? Check out the [fibx-agentic-wallet-skills](./fibx-agentic-wallet-skills/README.md) package.
|
|
132
137
|
|
|
133
|
-
|
|
134
|
-
2. **Viem**: Handles all blockchain interactions (RPC calls, transaction signing) using a custom Privy-backed account.
|
|
135
|
-
3. **Fibrous**: Provides the routing and calldata for optimal token swaps on Base.
|
|
138
|
+
## Development
|
|
136
139
|
|
|
137
|
-
|
|
140
|
+
1. Clone the repo
|
|
141
|
+
2. `pnpm install`
|
|
142
|
+
3. `cp .env.example .env` (add secrets)
|
|
143
|
+
4. Run commands with `pnpm dev <command>`
|
|
138
144
|
|
|
139
|
-
|
|
140
|
-
src/
|
|
141
|
-
├── cli.ts # Entry point & Command definitions
|
|
142
|
-
├── commands/ # Command implementation logic
|
|
143
|
-
│ ├── auth-login.ts # Step 1: Request OTP
|
|
144
|
-
│ ├── auth-verify.ts # Step 2: Verify & Provision Wallet
|
|
145
|
-
│ ├── trade.ts # Swap logic via Fibrous
|
|
146
|
-
│ ├── send.ts # ETH/ERC20 transfer logic
|
|
147
|
-
│ └── ...
|
|
148
|
-
├── chain/ # Blockchain layer
|
|
149
|
-
│ └── viem.ts # Viem client & Custom Privy Account
|
|
150
|
-
├── wallet/ # Wallet management
|
|
151
|
-
│ ├── privy.ts # Privy SDK integration (Server Wallets)
|
|
152
|
-
│ └── session.ts # Local session management
|
|
153
|
-
├── fibrous/ # Fibrous API integration
|
|
154
|
-
└── utils/ # Config, validation, and helpers
|
|
155
|
-
```
|
|
145
|
+
# Architecture
|
|
156
146
|
|
|
157
|
-
|
|
147
|
+
This CLI uses a **Server Wallet** architecture:
|
|
158
148
|
|
|
159
|
-
|
|
149
|
+
1. **Privy**: Manages the embedded wallets. We use "Ownerless" wallets (Agents) that are controlled via the Privy App Secret, allowing the CLI to sign transactions programmatically without requiring a user-side browser or JWT.
|
|
150
|
+
2. **Viem**: Handles all blockchain interactions (RPC calls, transaction signing) using a custom Privy-backed account, abstracted in the `services/chain` module.
|
|
151
|
+
3. **Fibrous**: Provides the routing and calldata for optimal token swaps on Base, encapsulated in the `services/fibrous` module.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/commands/auth/login.ts"],"names":[],"mappings":"AACA,OAAO,EAA0C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEjG,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAyCxF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getPrivyClient } from "../../services/privy/client.js";
|
|
2
|
+
import { outputResult, outputError, withSpinner } from "../../lib/format.js";
|
|
3
|
+
export async function authLoginCommand(email, opts) {
|
|
4
|
+
try {
|
|
5
|
+
getPrivyClient();
|
|
6
|
+
await withSpinner("Sending OTP...", async () => {
|
|
7
|
+
const appId = process.env.PRIVY_APP_ID;
|
|
8
|
+
const appSecret = process.env.PRIVY_APP_SECRET;
|
|
9
|
+
const credentials = Buffer.from(`${appId}:${appSecret}`).toString("base64");
|
|
10
|
+
const res = await fetch("https://auth.privy.io/api/v1/passwordless/init", {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
Authorization: `Basic ${credentials}`,
|
|
15
|
+
"privy-app-id": appId,
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify({ email }),
|
|
18
|
+
});
|
|
19
|
+
if (!res.ok) {
|
|
20
|
+
const body = await res.text().catch(() => "");
|
|
21
|
+
throw new Error(`OTP init failed (${res.status}): ${body}`);
|
|
22
|
+
}
|
|
23
|
+
return res.json();
|
|
24
|
+
}, opts);
|
|
25
|
+
outputResult({
|
|
26
|
+
email,
|
|
27
|
+
message: `OTP sent to ${email}. Run: fibx auth verify ${email} <code>`,
|
|
28
|
+
}, opts);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
outputError(error, opts);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../../src/commands/auth/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,qBAAqB,CAAC;AAEjG,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAa,EAAE,IAAmB;IACxE,IAAI,CAAC;QACJ,cAAc,EAAE,CAAC;QAEjB,MAAM,WAAW,CAChB,gBAAgB,EAChB,KAAK,IAAI,EAAE;YACV,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAa,CAAC;YACxC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAiB,CAAC;YAChD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAE5E,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,gDAAgD,EAAE;gBACzE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACR,cAAc,EAAE,kBAAkB;oBAClC,aAAa,EAAE,SAAS,WAAW,EAAE;oBACrC,cAAc,EAAE,KAAK;iBACrB;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC;aAC/B,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gBACb,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;gBAC9C,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;YAC7D,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;QACnB,CAAC,EACD,IAAI,CACJ,CAAC;QAEF,YAAY,CACX;YACC,KAAK;YACL,OAAO,EAAE,eAAe,KAAK,2BAA2B,KAAK,SAAS;SACtE,EACD,IAAI,CACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../src/commands/auth/verify.ts"],"names":[],"mappings":"AAOA,OAAO,EAA0C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAOjG,wBAAsB,iBAAiB,CACtC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,aAAa,GACjB,OAAO,CAAC,IAAI,CAAC,CAoFf"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getPrivyClient, createAgentWallet, findExistingWallet, saveWalletIdToUser, } from "../../services/privy/client.js";
|
|
2
|
+
import { saveSession } from "../../services/auth/session.js";
|
|
3
|
+
import { outputResult, outputError, withSpinner } from "../../lib/format.js";
|
|
4
|
+
export async function authVerifyCommand(email, code, opts) {
|
|
5
|
+
try {
|
|
6
|
+
const privy = getPrivyClient();
|
|
7
|
+
const { userId, userToken } = await withSpinner("Verifying OTP...", async () => {
|
|
8
|
+
const appId = process.env.PRIVY_APP_ID;
|
|
9
|
+
const appSecret = process.env.PRIVY_APP_SECRET;
|
|
10
|
+
const credentials = Buffer.from(`${appId}:${appSecret}`).toString("base64");
|
|
11
|
+
const res = await fetch("https://auth.privy.io/api/v1/passwordless/authenticate", {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
Authorization: `Basic ${credentials}`,
|
|
16
|
+
"privy-app-id": appId,
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({ email, code }),
|
|
19
|
+
});
|
|
20
|
+
if (!res.ok) {
|
|
21
|
+
const body = await res.text().catch(() => "");
|
|
22
|
+
throw new Error(`OTP verify failed (${res.status}): ${body}`);
|
|
23
|
+
}
|
|
24
|
+
const data = (await res.json());
|
|
25
|
+
return { userId: data.user.id, userToken: data.privy_access_token };
|
|
26
|
+
}, opts);
|
|
27
|
+
// Check for existing wallet
|
|
28
|
+
const existingWallet = await withSpinner("Checking for existing wallet...", async () => findExistingWallet(privy, email), opts);
|
|
29
|
+
let wallet;
|
|
30
|
+
let isExisting;
|
|
31
|
+
if (existingWallet) {
|
|
32
|
+
wallet = existingWallet;
|
|
33
|
+
isExisting = true;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Create new server wallet
|
|
37
|
+
wallet = await withSpinner("Creating server wallet...", async () => createAgentWallet(privy), opts);
|
|
38
|
+
// Link wallet to user
|
|
39
|
+
await withSpinner("Linking wallet to user...", async () => saveWalletIdToUser(privy, userId, wallet.id), opts);
|
|
40
|
+
isExisting = false;
|
|
41
|
+
}
|
|
42
|
+
await saveSession({
|
|
43
|
+
userId,
|
|
44
|
+
walletId: wallet.id,
|
|
45
|
+
walletAddress: wallet.address,
|
|
46
|
+
userJwt: userToken,
|
|
47
|
+
createdAt: new Date().toISOString(),
|
|
48
|
+
});
|
|
49
|
+
outputResult({
|
|
50
|
+
walletAddress: wallet.address,
|
|
51
|
+
walletId: wallet.id,
|
|
52
|
+
message: isExisting
|
|
53
|
+
? "Existing wallet found and connected. You're ready to go!"
|
|
54
|
+
: "New wallet created and session saved. You're ready to go!",
|
|
55
|
+
}, opts);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
outputError(error, opts);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../src/commands/auth/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,qBAAqB,CAAC;AAOjG,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,KAAa,EACb,IAAY,EACZ,IAAmB;IAEnB,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,cAAc,EAAE,CAAC;QAE/B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,WAAW,CAC9C,kBAAkB,EAClB,KAAK,IAAI,EAAE;YACV,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAa,CAAC;YACxC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAiB,CAAC;YAChD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAE5E,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,wDAAwD,EAAE;gBACjF,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACR,cAAc,EAAE,kBAAkB;oBAClC,aAAa,EAAE,SAAS,WAAW,EAAE;oBACrC,cAAc,EAAE,KAAK;iBACrB;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;aACrC,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;gB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;YAClB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACnC,CAAC,CAAC;QAEH,YAAY,CACX;YACC,aAAa,EAAE,MAAM,CAAC,OAAO;YAC7B,QAAQ,EAAE,MAAM,CAAC,EAAE;YACnB,OAAO,EAAE,UAAU;gBAClB,CAAC,CAAC,0DAA0D;gBAC5D,CAAC,CAAC,2DAA2D;SAC9D,EACD,IAAI,CACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/commands/balance.ts"],"names":[],"mappings":"AAQA,OAAO,EAA0C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEjG,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/commands/balance.ts"],"names":[],"mappings":"AAQA,OAAO,EAA0C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEjG,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA2DvE"}
|
package/dist/commands/balance.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { requireSession } from "../wallet/session.js";
|
|
2
2
|
import { publicClient } from "../chain/viem.js";
|
|
3
3
|
import { getChainConfig } from "../chain/chains.js";
|
|
4
|
-
import { getERC20Balance } from "../chain/erc20.js";
|
|
5
4
|
import { ACTIVE_NETWORK } from "../utils/config.js";
|
|
6
|
-
import {
|
|
5
|
+
import { getTokens } from "../fibrous/tokens.js";
|
|
6
|
+
import { getBalances } from "../fibrous/balances.js";
|
|
7
7
|
import { formatAmount } from "../utils/parseAmount.js";
|
|
8
8
|
import { outputResult, outputError, withSpinner } from "../format/output.js";
|
|
9
9
|
export async function balanceCommand(opts) {
|
|
@@ -11,22 +11,41 @@ export async function balanceCommand(opts) {
|
|
|
11
11
|
const chain = getChainConfig(ACTIVE_NETWORK);
|
|
12
12
|
const session = requireSession();
|
|
13
13
|
const wallet = session.walletAddress;
|
|
14
|
-
|
|
14
|
+
// 1. Fetch all supported tokens
|
|
15
|
+
const tokensMap = await getTokens();
|
|
16
|
+
const tokenList = Object.values(tokensMap);
|
|
15
17
|
const balances = await withSpinner("Fetching balances...", async () => {
|
|
16
|
-
|
|
18
|
+
// 2. Parallel fetch: Native ETH + All Token Balances
|
|
19
|
+
const [ethBalance, tokenBalances] = await Promise.all([
|
|
17
20
|
publicClient.getBalance({ address: wallet }),
|
|
18
|
-
|
|
21
|
+
getBalances(tokenList, wallet),
|
|
19
22
|
]);
|
|
20
23
|
return {
|
|
21
24
|
eth: formatAmount(ethBalance, 18),
|
|
22
|
-
|
|
25
|
+
tokens: tokenBalances,
|
|
23
26
|
};
|
|
24
27
|
}, opts);
|
|
28
|
+
// 3. Prepare Output
|
|
29
|
+
const result = {};
|
|
30
|
+
// Always show ETH first
|
|
31
|
+
result["ETH"] = balances.eth;
|
|
32
|
+
// 4. Filter and Map Tokens
|
|
33
|
+
for (const item of balances.tokens) {
|
|
34
|
+
// Filter out zero balances
|
|
35
|
+
// item.balance is a string string from the API, e.g., "0.0" or "10.5"
|
|
36
|
+
const balanceVal = parseFloat(item.balance);
|
|
37
|
+
if (balanceVal > 0) {
|
|
38
|
+
// Try to find the symbol for the token
|
|
39
|
+
const tokenAddr = item.token.address.toLowerCase();
|
|
40
|
+
const token = tokenList.find((t) => t.address.toLowerCase() === tokenAddr);
|
|
41
|
+
const symbol = token ? token.symbol : tokenAddr; // Fallback to address if symbol not found
|
|
42
|
+
result[symbol] = item.balance;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
25
45
|
outputResult({
|
|
26
46
|
wallet: session.walletAddress,
|
|
27
47
|
chain: chain.name,
|
|
28
|
-
|
|
29
|
-
usdc: balances.usdc,
|
|
48
|
+
...result,
|
|
30
49
|
}, opts);
|
|
31
50
|
}
|
|
32
51
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/commands/balance.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/commands/balance.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,qBAAqB,CAAC;AAEjG,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAmB;IACvD,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;QAC7C,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAwB,CAAC;QAEhD,gCAAgC;QAChC,MAAM,SAAS,GAAG,MAAM,SAAS,EAAE,CAAC;QACpC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC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AY,CACX;YACC,MAAM,EAAE,OAAO,CAAC,aAAa;YAC7B,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,GAAG,MAAM;SACT,EACD,IAAI,CACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/commands/trade/status.ts"],"names":[],"mappings":"AAIA,OAAO,EAA0C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEjG,wBAAsB,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BtE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { loadSession } from "../../services/auth/session.js";
|
|
2
|
+
import { checkHealth } from "../../services/fibrous/health.js";
|
|
3
|
+
import { getChainConfig } from "../../services/chain/constants.js";
|
|
4
|
+
import { ACTIVE_NETWORK } from "../../lib/config.js";
|
|
5
|
+
import { outputResult, outputError, withSpinner } from "../../lib/format.js";
|
|
6
|
+
export async function statusCommand(opts) {
|
|
7
|
+
try {
|
|
8
|
+
const chain = getChainConfig(ACTIVE_NETWORK);
|
|
9
|
+
const session = loadSession();
|
|
10
|
+
const fibrousHealth = await withSpinner("Checking Fibrous API...", async () => {
|
|
11
|
+
try {
|
|
12
|
+
const health = await checkHealth();
|
|
13
|
+
return { ok: true, message: health.message };
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return { ok: false, message: "unreachable" };
|
|
17
|
+
}
|
|
18
|
+
}, opts);
|
|
19
|
+
outputResult({
|
|
20
|
+
chain: chain.name,
|
|
21
|
+
chainId: chain.id,
|
|
22
|
+
authenticated: !!session,
|
|
23
|
+
wallet: session?.walletAddress ?? null,
|
|
24
|
+
fibrous: fibrousHealth,
|
|
25
|
+
}, opts);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
outputError(error, opts);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/commands/trade/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,qBAAqB,CAAC;AAEjG,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAmB;IACtD,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;QAC7C,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;QAE9B,MAAM,aAAa,GAAG,MAAM,WAAW,CACtC,yBAAyB,EACzB,KAAK,IAAI,EAAE;YACV,IAAI,CAAC;gBACJ,MAAM,MAAM,GAAG,MAAM,WAAW,EAAE,CAAC;gBACnC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;YAC9C,CAAC;YAAC,MAAM,CAAC;gBACR,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;YAC9C,CAAC;QACF,CAAC,EACD,IAAI,CACJ,CAAC;QAEF,YAAY,CACX;YACC,KAAK,EAAE,KAAK,CAAC,IAAI;YACjB,OAAO,EAAE,KAAK,CAAC,EAAE;YACjB,aAAa,EAAE,CAAC,CAAC,OAAO;YACxB,MAAM,EAAE,OAAO,EAAE,aAAa,IAAI,IAAI;YACtC,OAAO,EAAE,aAAa;SACtB,EACD,IAAI,CACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type OutputOptions } from "../../lib/format.js";
|
|
2
|
+
interface TradeOptions extends OutputOptions {
|
|
3
|
+
slippage: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function tradeCommand(amount: string, from: string, to: string, opts: TradeOptions): Promise<void>;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=swap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../../src/commands/trade/swap.ts"],"names":[],"mappings":"AAWA,OAAO,EAA0C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEjG,UAAU,YAAa,SAAQ,aAAa;IAC3C,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,YAAY,CACjC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,YAAY,GAChB,OAAO,CAAC,IAAI,CAAC,CAyFf"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { requireSession } from "../../services/auth/session.js";
|
|
2
|
+
import { getPrivyClient } from "../../services/privy/client.js";
|
|
3
|
+
import { getWalletClient } from "../../services/chain/client.js";
|
|
4
|
+
import { getChainConfig } from "../../services/chain/constants.js";
|
|
5
|
+
import { getAllowance, encodeApprove } from "../../services/chain/erc20.js";
|
|
6
|
+
import { resolveToken } from "../../services/fibrous/tokens.js";
|
|
7
|
+
import { getRouteAndCallData, encodeSwapCalldata } from "../../services/fibrous/route.js";
|
|
8
|
+
import { ACTIVE_NETWORK, DEFAULT_SLIPPAGE } from "../../lib/config.js";
|
|
9
|
+
import { validateAmount } from "../../lib/validation.js";
|
|
10
|
+
import { parseAmount, formatAmount } from "../../lib/parseAmount.js";
|
|
11
|
+
import { outputResult, outputError, withSpinner } from "../../lib/format.js";
|
|
12
|
+
export async function tradeCommand(amount, from, to, opts) {
|
|
13
|
+
try {
|
|
14
|
+
validateAmount(amount);
|
|
15
|
+
const chain = getChainConfig(ACTIVE_NETWORK);
|
|
16
|
+
const session = requireSession();
|
|
17
|
+
const privy = getPrivyClient();
|
|
18
|
+
const wallet = session.walletAddress;
|
|
19
|
+
const [tokenIn, tokenOut] = await withSpinner("Resolving tokens...", async () => Promise.all([resolveToken(from), resolveToken(to)]), opts);
|
|
20
|
+
const amountBaseUnits = parseAmount(amount, tokenIn.decimals);
|
|
21
|
+
const isNativeInput = tokenIn.address.toLowerCase() === chain.nativeTokenAddress.toLowerCase();
|
|
22
|
+
const routeData = await withSpinner("Finding best route...", async () => {
|
|
23
|
+
return getRouteAndCallData({
|
|
24
|
+
amount: amountBaseUnits.toString(),
|
|
25
|
+
tokenInAddress: tokenIn.address,
|
|
26
|
+
tokenOutAddress: tokenOut.address,
|
|
27
|
+
slippage: opts.slippage ?? DEFAULT_SLIPPAGE,
|
|
28
|
+
destination: wallet,
|
|
29
|
+
});
|
|
30
|
+
}, opts);
|
|
31
|
+
const routerAddress = routeData.router_address;
|
|
32
|
+
const walletClient = getWalletClient(privy, session);
|
|
33
|
+
if (!isNativeInput) {
|
|
34
|
+
const currentAllowance = await getAllowance(tokenIn.address, wallet, routerAddress);
|
|
35
|
+
if (currentAllowance < amountBaseUnits) {
|
|
36
|
+
await withSpinner("Approving token spend...", async () => {
|
|
37
|
+
const approveData = encodeApprove(routerAddress, amountBaseUnits);
|
|
38
|
+
return walletClient.sendTransaction({
|
|
39
|
+
to: tokenIn.address,
|
|
40
|
+
data: approveData,
|
|
41
|
+
value: 0n,
|
|
42
|
+
});
|
|
43
|
+
}, opts);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const hash = await withSpinner(`Swapping ${amount} ${tokenIn.symbol} → ${tokenOut.symbol}...`, async () => {
|
|
47
|
+
const swapData = encodeSwapCalldata(routeData.calldata);
|
|
48
|
+
return walletClient.sendTransaction({
|
|
49
|
+
to: routerAddress,
|
|
50
|
+
data: swapData,
|
|
51
|
+
value: isNativeInput ? amountBaseUnits : 0n,
|
|
52
|
+
});
|
|
53
|
+
}, opts);
|
|
54
|
+
const outputAmount = formatAmount(BigInt(routeData.route.outputAmount), tokenOut.decimals);
|
|
55
|
+
outputResult({
|
|
56
|
+
txHash: hash,
|
|
57
|
+
amountIn: amount,
|
|
58
|
+
amountOut: outputAmount,
|
|
59
|
+
tokenIn: tokenIn.symbol,
|
|
60
|
+
tokenOut: tokenOut.symbol,
|
|
61
|
+
router: routerAddress,
|
|
62
|
+
chain: chain.name,
|
|
63
|
+
}, opts);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
outputError(error, opts);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=swap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.js","sourceRoot":"","sources":["../../../src/commands/trade/swap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,O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E,MAAM;YAChB,SAAS,EAAE,YAAY;YACvB,OAAO,EAAE,OAAO,CAAC,MAAM;YACvB,QAAQ,EAAE,QAAQ,CAAC,MAAM;YACzB,MAAM,EAAE,aAAa;YACrB,KAAK,EAAE,KAAK,CAAC,IAAI;SACjB,EACD,IAAI,CACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/commands/wallet/address.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpF,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAcvE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { requireSession } from "../../services/auth/session.js";
|
|
2
|
+
import { outputResult, outputError } from "../../lib/format.js";
|
|
3
|
+
export async function addressCommand(opts) {
|
|
4
|
+
try {
|
|
5
|
+
const session = requireSession();
|
|
6
|
+
outputResult({
|
|
7
|
+
address: session.walletAddress,
|
|
8
|
+
walletId: session.walletId,
|
|
9
|
+
}, opts);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
outputError(error, opts);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/commands/wallet/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAsB,MAAM,qBAAqB,CAAC;AAEpF,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAmB;IACvD,IAAI,CAAC;QACJ,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;QAEjC,YAAY,CACX;YACC,OAAO,EAAE,OAAO,CAAC,aAAa;YAC9B,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC1B,EACD,IAAI,CACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../../src/commands/wallet/balance.ts"],"names":[],"mappings":"AAQA,OAAO,EAA0C,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEjG,wBAAsB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAoDvE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { requireSession } from "../../services/auth/session.js";
|
|
2
|
+
import { publicClient } from "../../services/chain/client.js";
|
|
3
|
+
import { getChainConfig } from "../../services/chain/constants.js";
|
|
4
|
+
import { ACTIVE_NETWORK } from "../../lib/config.js";
|
|
5
|
+
import { getTokens } from "../../services/fibrous/tokens.js";
|
|
6
|
+
import { getBalances } from "../../services/fibrous/balances.js";
|
|
7
|
+
import { formatAmount } from "../../lib/parseAmount.js";
|
|
8
|
+
import { outputResult, outputError, withSpinner } from "../../lib/format.js";
|
|
9
|
+
export async function balanceCommand(opts) {
|
|
10
|
+
try {
|
|
11
|
+
const chain = getChainConfig(ACTIVE_NETWORK);
|
|
12
|
+
const session = requireSession();
|
|
13
|
+
const wallet = session.walletAddress;
|
|
14
|
+
const tokensMap = await getTokens();
|
|
15
|
+
const tokenList = Object.values(tokensMap);
|
|
16
|
+
const balances = await withSpinner("Fetching balances...", async () => {
|
|
17
|
+
const [ethBalance, tokenBalances] = await Promise.all([
|
|
18
|
+
publicClient.getBalance({ address: wallet }),
|
|
19
|
+
getBalances(tokenList, wallet),
|
|
20
|
+
]);
|
|
21
|
+
return {
|
|
22
|
+
eth: formatAmount(ethBalance, 18),
|
|
23
|
+
tokens: tokenBalances,
|
|
24
|
+
};
|
|
25
|
+
}, opts);
|
|
26
|
+
const result = {};
|
|
27
|
+
// Always show ETH first
|
|
28
|
+
result["ETH"] = balances.eth;
|
|
29
|
+
for (const item of balances.tokens) {
|
|
30
|
+
const balanceVal = parseFloat(item.balance);
|
|
31
|
+
if (balanceVal > 0) {
|
|
32
|
+
const tokenAddr = item.token.address.toLowerCase();
|
|
33
|
+
const token = tokenList.find((t) => t.address.toLowerCase() === tokenAddr);
|
|
34
|
+
const symbol = token ? token.symbol : tokenAddr;
|
|
35
|
+
result[symbol] = item.balance;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
outputResult({
|
|
39
|
+
wallet: session.walletAddress,
|
|
40
|
+
chain: chain.name,
|
|
41
|
+
...result,
|
|
42
|
+
}, opts);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
outputError(error, opts);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=balance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.js","sourceRoot":"","sources":["../../../src/commands/wallet/balance.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,qBA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