@veil-cash/sdk 0.6.1 → 0.6.3
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 +12 -7
- package/SDK.md +38 -7
- package/dist/cli/index.cjs +523 -220
- package/dist/index.cjs +213 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +121 -2
- package/dist/index.d.ts +121 -2
- package/dist/index.js +211 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/skills/veil/SKILL.md +32 -12
- package/skills/veil/reference.md +28 -8
- package/src/abi.ts +8 -0
- package/src/balance.ts +48 -0
- package/src/cli/commands/deposit.ts +61 -15
- package/src/cli/commands/subaccount.ts +82 -2
- package/src/cli/index.ts +1 -1
- package/src/index.ts +7 -0
- package/src/subaccount.ts +244 -5
- package/src/types.ts +56 -0
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ SDK and CLI for interacting with [Veil Cash](https://veil.cash) privacy pools on
|
|
|
8
8
|
|
|
9
9
|
Generate keypairs, register, deposit, withdraw, transfer, and merge ETH and USDC privately.
|
|
10
10
|
|
|
11
|
+
`0.6.2` adds `mergeSubaccount` — transfer a subaccount's private pool balance back to the main wallet via a ZK proof. Also adds `veil subaccount merge` CLI command.
|
|
12
|
+
|
|
11
13
|
`0.6.0` adds SDK-first subaccount support for deterministic slot derivation, forwarder status, relay-backed deploy/sweep, and direct recovery.
|
|
12
14
|
|
|
13
15
|
## Installation
|
|
@@ -86,11 +88,12 @@ veil subaccount derive --slot 0
|
|
|
86
88
|
veil subaccount status --slot 0
|
|
87
89
|
veil subaccount deploy --slot 0
|
|
88
90
|
veil subaccount sweep --slot 0 --asset eth
|
|
91
|
+
veil subaccount merge --slot 0 --pool eth
|
|
89
92
|
veil subaccount recover --slot 0 --asset usdc --to 0xRecipientAddress --amount 25
|
|
90
93
|
|
|
91
94
|
# 9. Use JSON or unsigned modes when you need automation
|
|
92
95
|
veil status --json
|
|
93
|
-
veil deposit ETH 0.1 --unsigned
|
|
96
|
+
veil deposit ETH 0.1 --unsigned --address 0x...
|
|
94
97
|
veil subaccount status --slot 0 --json
|
|
95
98
|
```
|
|
96
99
|
|
|
@@ -139,13 +142,14 @@ SIGNER_ADDRESS=0x... veil register --unsigned
|
|
|
139
142
|
|
|
140
143
|
In `--unsigned` mode, `--address` is optional when `SIGNER_ADDRESS` is set. `veil register --force` checks on-chain state first and emits a `changeDepositKey` payload only if the address is already registered; otherwise it emits a normal `register` payload.
|
|
141
144
|
|
|
142
|
-
Deposit ETH or USDC into Veil. The amount you specify is the **net** amount that arrives in your Veil balance.
|
|
145
|
+
Deposit ETH or USDC into Veil. The amount you specify is the **net** amount that arrives in your Veil balance. A 0.3% protocol fee is normally added on top, but each address gets free daily deposits (fee waived). The CLI checks automatically:
|
|
143
146
|
|
|
144
147
|
```bash
|
|
145
|
-
veil deposit ETH 0.1 # 0.1 ETH lands in pool
|
|
146
|
-
veil deposit USDC 100 # 100 USDC lands in pool
|
|
148
|
+
veil deposit ETH 0.1 # 0.1 ETH lands in pool (free or ~0.1003 ETH sent)
|
|
149
|
+
veil deposit USDC 100 # 100 USDC lands in pool (free or ~100.30 USDC sent)
|
|
147
150
|
veil deposit ETH 0.1 --json
|
|
148
|
-
veil deposit ETH 0.1 --unsigned
|
|
151
|
+
veil deposit ETH 0.1 --unsigned --address 0x...
|
|
152
|
+
SIGNER_ADDRESS=0x... veil deposit ETH 0.1 --unsigned
|
|
149
153
|
```
|
|
150
154
|
|
|
151
155
|
### Balances
|
|
@@ -207,7 +211,7 @@ Subaccounts are deterministic child slots derived from your main `VEIL_KEY`:
|
|
|
207
211
|
|
|
208
212
|
`root key -> slot -> child key -> child deposit key -> forwarder`
|
|
209
213
|
|
|
210
|
-
Base mainnet only. Deploy and sweep are relay-backed.
|
|
214
|
+
Base mainnet only. Deploy and sweep are relay-backed. Merge transfers the subaccount's private pool balance back to the main wallet via a ZK proof. Status reports forwarder wallet balances, private pool balances, and queue state for the child slot. Recovery is for assets still sitting on the forwarder after refund or rejection, and is submitted directly on-chain by your CLI gas payer.
|
|
211
215
|
|
|
212
216
|
```bash
|
|
213
217
|
veil subaccount derive --slot 0
|
|
@@ -215,6 +219,7 @@ veil subaccount status --slot 0
|
|
|
215
219
|
veil subaccount address --slot 0
|
|
216
220
|
veil subaccount deploy --slot 0
|
|
217
221
|
veil subaccount sweep --slot 0 --asset eth
|
|
222
|
+
veil subaccount merge --slot 0 --pool eth
|
|
218
223
|
veil subaccount recover --slot 0 --asset usdc --to 0xRecipientAddress --amount 25
|
|
219
224
|
veil subaccount status --slot 0 --json
|
|
220
225
|
```
|
|
@@ -291,7 +296,7 @@ The CLI is the main entrypoint for most users. If you are integrating Veil progr
|
|
|
291
296
|
2. **Derive Keypair**: Run `veil init` to derive and save your Veil keypair
|
|
292
297
|
3. **Register**: Run `veil register` to link your deposit key on-chain (one-time)
|
|
293
298
|
4. **Check Status**: Run `veil status` to verify your setup
|
|
294
|
-
5. **Deposit**: Run `veil deposit <asset> <amount>` — the amount is what lands in your balance (e.g., `veil deposit ETH 0.1` deposits 0.1 ETH; the 0.3%
|
|
299
|
+
5. **Deposit**: Run `veil deposit <asset> <amount>` — the amount is what lands in your balance (e.g., `veil deposit ETH 0.1` deposits 0.1 ETH; the fee is waived if you have daily free deposits remaining, otherwise 0.3% is added automatically)
|
|
295
300
|
6. **Wait**: The Veil deposit engine processes your deposit
|
|
296
301
|
7. **Done**: Your deposit is accepted into the privacy pool
|
|
297
302
|
|
package/SDK.md
CHANGED
|
@@ -10,7 +10,7 @@ If you are looking for the CLI first-run flow, go back to the main [README](./RE
|
|
|
10
10
|
import {
|
|
11
11
|
Keypair, buildRegisterTx, buildDepositETHTx,
|
|
12
12
|
buildDepositUSDCTx, buildApproveUSDCTx,
|
|
13
|
-
withdraw, transfer, getSubaccountStatus,
|
|
13
|
+
withdraw, transfer, getSubaccountStatus, mergeSubaccount,
|
|
14
14
|
} from '@veil-cash/sdk';
|
|
15
15
|
import { createWalletClient, http } from 'viem';
|
|
16
16
|
import { base } from 'viem/chains';
|
|
@@ -109,6 +109,11 @@ keypair.privkey; // '0x...'
|
|
|
109
109
|
|
|
110
110
|
### Transaction Builders
|
|
111
111
|
|
|
112
|
+
> **Daily free deposits**: Each address gets a configurable number of fee-free
|
|
113
|
+
> deposits per UTC day. The CLI handles this automatically. If you use the
|
|
114
|
+
> builders programmatically, call `getDailyFreeRemaining()` first — when the
|
|
115
|
+
> user has free slots, pass the net amount directly (no fee markup needed).
|
|
116
|
+
|
|
112
117
|
```typescript
|
|
113
118
|
import {
|
|
114
119
|
buildRegisterTx, buildChangeDepositKeyTx, buildDepositETHTx, buildDepositTx,
|
|
@@ -182,7 +187,7 @@ const mergeResult = await mergeUtxos({
|
|
|
182
187
|
Balance functions accept an optional `pool` parameter (`'eth'` | `'usdc'`), defaulting to `'eth'`.
|
|
183
188
|
|
|
184
189
|
```typescript
|
|
185
|
-
import { getQueueBalance, getPrivateBalance } from '@veil-cash/sdk';
|
|
190
|
+
import { getQueueBalance, getPrivateBalance, getDailyFreeRemaining } from '@veil-cash/sdk';
|
|
186
191
|
|
|
187
192
|
// Check ETH queue balance (pending deposits)
|
|
188
193
|
const queueBalance = await getQueueBalance({
|
|
@@ -195,6 +200,13 @@ const privateBalance = await getPrivateBalance({
|
|
|
195
200
|
keypair,
|
|
196
201
|
pool: 'usdc',
|
|
197
202
|
});
|
|
203
|
+
|
|
204
|
+
// Check how many fee-free deposits the user has left today
|
|
205
|
+
const freeRemaining = await getDailyFreeRemaining({
|
|
206
|
+
address: '0x...',
|
|
207
|
+
pool: 'eth', // default
|
|
208
|
+
});
|
|
209
|
+
// freeRemaining: number — 0 when all free slots are used or the feature is disabled
|
|
198
210
|
```
|
|
199
211
|
|
|
200
212
|
### Subaccounts
|
|
@@ -203,14 +215,16 @@ Subaccounts are deterministic child slots derived from your main Veil key:
|
|
|
203
215
|
|
|
204
216
|
`root key -> slot -> child key -> child deposit key -> forwarder`
|
|
205
217
|
|
|
206
|
-
Base mainnet only. Status shows the forwarder wallet and queue state
|
|
218
|
+
Base mainnet only. Status shows the child slot's forwarder wallet balances, private pool balances, and queue state. Deploy and sweep are relay-backed. Merge transfers the subaccount's private pool balance back to the main wallet via a ZK proof. Recovery signs a forwarder withdraw request with the child key and returns a direct transaction for your gas payer to submit.
|
|
207
219
|
|
|
208
220
|
```typescript
|
|
209
221
|
import {
|
|
210
222
|
deriveSubaccountSlot,
|
|
223
|
+
getSubaccountPrivateBalance,
|
|
211
224
|
getSubaccountStatus,
|
|
212
225
|
deploySubaccountForwarder,
|
|
213
226
|
sweepSubaccountForwarder,
|
|
227
|
+
mergeSubaccount,
|
|
214
228
|
buildSubaccountRecoveryTx,
|
|
215
229
|
} from '@veil-cash/sdk';
|
|
216
230
|
|
|
@@ -223,6 +237,14 @@ const status = await getSubaccountStatus({
|
|
|
223
237
|
rootPrivateKey: veilKey,
|
|
224
238
|
slot: 0,
|
|
225
239
|
});
|
|
240
|
+
// status.privateBalances.eth.privateBalance, status.privateBalances.usdc.privateBalance
|
|
241
|
+
|
|
242
|
+
const privateBalance = await getSubaccountPrivateBalance({
|
|
243
|
+
rootPrivateKey: veilKey,
|
|
244
|
+
slot: 0,
|
|
245
|
+
pool: 'eth',
|
|
246
|
+
});
|
|
247
|
+
// privateBalance.privateBalance, privateBalance.unspentCount
|
|
226
248
|
|
|
227
249
|
await deploySubaccountForwarder({
|
|
228
250
|
rootPrivateKey: veilKey,
|
|
@@ -234,6 +256,14 @@ await sweepSubaccountForwarder({
|
|
|
234
256
|
asset: 'eth',
|
|
235
257
|
});
|
|
236
258
|
|
|
259
|
+
// Merge subaccount's private pool balance back to the main wallet
|
|
260
|
+
const mergeResult = await mergeSubaccount({
|
|
261
|
+
rootPrivateKey: veilKey,
|
|
262
|
+
slot: 0,
|
|
263
|
+
pool: 'eth', // 'eth' | 'usdc' (default: 'eth')
|
|
264
|
+
});
|
|
265
|
+
// mergeResult.amount, mergeResult.transactionHash
|
|
266
|
+
|
|
237
267
|
const recovery = await buildSubaccountRecoveryTx({
|
|
238
268
|
rootPrivateKey: veilKey,
|
|
239
269
|
slot: 0,
|
|
@@ -273,8 +303,8 @@ veil init --json
|
|
|
273
303
|
|
|
274
304
|
# Get unsigned transaction payloads for agent signing
|
|
275
305
|
SIGNER_ADDRESS=0x... veil register --unsigned
|
|
276
|
-
veil deposit ETH 0.1 --unsigned
|
|
277
|
-
veil deposit USDC 100 --unsigned # Outputs approve + deposit payloads
|
|
306
|
+
SIGNER_ADDRESS=0x... veil deposit ETH 0.1 --unsigned
|
|
307
|
+
veil deposit USDC 100 --unsigned --address 0x... # Outputs approve + deposit payloads
|
|
278
308
|
|
|
279
309
|
# Request machine-readable status or balances
|
|
280
310
|
veil balance --json
|
|
@@ -326,12 +356,13 @@ Use `--unsigned` to get signer-compatible transaction payloads:
|
|
|
326
356
|
```bash
|
|
327
357
|
SIGNER_ADDRESS=0x... veil register --unsigned
|
|
328
358
|
SIGNER_ADDRESS=0x... veil register --unsigned --force
|
|
329
|
-
veil deposit ETH 0.1 --unsigned
|
|
359
|
+
SIGNER_ADDRESS=0x... veil deposit ETH 0.1 --unsigned
|
|
360
|
+
veil deposit ETH 0.1 --unsigned --address 0x...
|
|
330
361
|
# {"to":"0x...","data":"0x...","value":"100000000000000000","chainId":8453}
|
|
331
362
|
```
|
|
332
363
|
|
|
333
364
|
The `--unsigned` flag outputs a standard `{to, data, value, chainId}` payload compatible with any signer that accepts arbitrary transactions.
|
|
334
|
-
When `SIGNER_ADDRESS` is set, `veil register --unsigned` no longer
|
|
365
|
+
When `SIGNER_ADDRESS` is set, `veil register --unsigned` and `veil deposit --unsigned` no longer require the `--address` flag.
|
|
335
366
|
For `veil register --unsigned --force`, the CLI checks on-chain registration state first and emits `changeDepositKey` only when the address is already registered; otherwise it falls back to `register`.
|
|
336
367
|
|
|
337
368
|
### Programmatic SDK Usage
|