@jpool/bond-cli 1.1.0 → 1.2.0-next.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/README.md +36 -7
- package/dist/cli.js +48 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ Example:
|
|
|
52
52
|
Add additional collateral to an existing validator bond.
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
|
-
pnpm jbond topup
|
|
55
|
+
pnpm jbond topup <vote-account> <amount> -k <path>
|
|
56
56
|
|
|
57
57
|
Arguments:
|
|
58
58
|
vote-account Vote account public key
|
|
@@ -63,15 +63,15 @@ Options:
|
|
|
63
63
|
-c, --cluster <CLUSTER_NAME> Solana cluster(devnet or mainnet-beta)
|
|
64
64
|
|
|
65
65
|
Example:
|
|
66
|
-
pnpm jbond topup
|
|
66
|
+
pnpm jbond topup 686JcEJ98r8fMtUiVuKiz4WRoBpJ2Sm9zMhdc2b6H4bu 50 -c mainnet-beta
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
### Withdraw Collateral
|
|
70
70
|
|
|
71
|
-
Withdraw collateral from validator bond account.
|
|
71
|
+
Withdraw collateral from a validator bond account to a specified destination address.
|
|
72
72
|
|
|
73
73
|
```bash
|
|
74
|
-
pnpm jbond withdraw
|
|
74
|
+
pnpm jbond withdraw <vote-account> <destination> <amount> [options]
|
|
75
75
|
|
|
76
76
|
Arguments:
|
|
77
77
|
vote-account Vote account public key
|
|
@@ -83,13 +83,42 @@ Options:
|
|
|
83
83
|
-c, --cluster <CLUSTER_NAME> Solana cluster(devnet or mainnet-beta)
|
|
84
84
|
|
|
85
85
|
Example:
|
|
86
|
-
pnpm jbond withdraw
|
|
86
|
+
pnpm jbond withdraw 686JcEJ98r8fMtUiVuKiz4WRoBpJ2Sm9zMhdc2b6H4bu 3K2coMGaZhrSkyF52wUBUXBeRBRpGLnmB3znzLRKjgiP 25 -c mainnet-beta
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
**Requirements**:
|
|
90
90
|
|
|
91
91
|
Only the validator identity or withdrawal authority can execute withdrawals. The validator bond account must have sufficient collateral
|
|
92
92
|
|
|
93
|
+
### Set Withdrawal Authority
|
|
94
|
+
|
|
95
|
+
Set or update the withdrawal authority for a validator bond account. This allows delegating withdrawal permissions to another address.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pnpm jbond set-withdraw-authority <vote-account> [options]
|
|
99
|
+
|
|
100
|
+
Arguments:
|
|
101
|
+
vote-account Vote account public key
|
|
102
|
+
|
|
103
|
+
Options:
|
|
104
|
+
-k, --keypair <path> Path to keypair file (default: ~/.config/solana/id.json)
|
|
105
|
+
-w, --new-authority <pubkey> New withdrawal authority (omit to remove authority)
|
|
106
|
+
-c, --cluster <CLUSTER_NAME> Solana cluster(devnet or mainnet-beta)
|
|
107
|
+
|
|
108
|
+
Examples:
|
|
109
|
+
# Set a withdrawal authority
|
|
110
|
+
pnpm jbond set-withdraw-authority 686JcEJ98r8fMtUiVuKiz4WRoBpJ2Sm9zMhdc2b6H4bu -w 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin -c mainnet-beta
|
|
111
|
+
|
|
112
|
+
# Remove withdrawal authority (revert to identity-only)
|
|
113
|
+
pnpm jbond set-withdraw-authority 686JcEJ98r8fMtUiVuKiz4WRoBpJ2Sm9zMhdc2b6H4bu -c mainnet-beta
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Requirements**:
|
|
117
|
+
|
|
118
|
+
- Only the validator identity can set or update the withdrawal authority
|
|
119
|
+
- When a withdrawal authority is set, only that authority (or validator identity) can withdraw collateral
|
|
120
|
+
- Omitting the `--new-authority` option removes the withdrawal authority, reverting to identity-only withdrawals
|
|
121
|
+
|
|
93
122
|
### Claim Compensation
|
|
94
123
|
|
|
95
124
|
Claim compensation from a validator's collateral to the reserve (authority only).
|
|
@@ -195,7 +224,7 @@ pnpm jbond register-validator GHRvDXj9BfACkJ9CoLWbpi2UkMVti9DwXJGsaFT9XDcD 100
|
|
|
195
224
|
pnpm jbond validator-info GHRvDXj9BfACkJ9CoLWbpi2UkMVti9DwXJGsaFT9XDcD -c mainnet-beta
|
|
196
225
|
|
|
197
226
|
# 4. Top up with additional 50 SOL
|
|
198
|
-
pnpm jbond topup
|
|
227
|
+
pnpm jbond topup GHRvDXj9BfACkJ9CoLWbpi2UkMVti9DwXJGsaFT9XDcD 50 -c mainnet-beta
|
|
199
228
|
```
|
|
200
229
|
|
|
201
230
|
### Authority Operations
|
|
@@ -231,4 +260,4 @@ Common errors and solutions:
|
|
|
231
260
|
### `Account already in use`
|
|
232
261
|
|
|
233
262
|
- The validator is already registered
|
|
234
|
-
- Use `topup
|
|
263
|
+
- Use `topup` to add more funds instead
|
package/dist/cli.js
CHANGED
|
@@ -81,7 +81,7 @@ function resolveKeypair(path) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// package.json
|
|
84
|
-
var version = "1.0.
|
|
84
|
+
var version = "1.2.0-next.0";
|
|
85
85
|
|
|
86
86
|
// src/cli.ts
|
|
87
87
|
import_commander.program.name("jbond").description("CLI to interact with the JPool Bond program").version(process.env.VERSION ?? version).allowExcessArguments(false).option("-c, --cluster <CLUSTER>", "Solana cluster or RPC URL").option("-k, --keypair <KEYPAIR>", "Filepath to Solana keypair").hook("preAction", async (command) => {
|
|
@@ -103,13 +103,28 @@ import_commander.program.command("info").description("Get global state informati
|
|
|
103
103
|
console.log(import_chalk.default.yellow("Global state not initialized"));
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
console.log(import_chalk.default.cyan("Global State
|
|
106
|
+
console.log(import_chalk.default.cyan("====== Global State: ======\n"));
|
|
107
107
|
console.log(import_chalk.default.white(` Authority: ${state.authority}`));
|
|
108
108
|
console.log(import_chalk.default.white(` Reserve: ${state.reserve}`));
|
|
109
109
|
console.log(import_chalk.default.white(` Total Validators: ${state.totalValidators}`));
|
|
110
110
|
console.log(import_chalk.default.white(` Total Compensation Amount: ${state.totalCompensationAmount.toString()}`));
|
|
111
111
|
const epochInfo = await provider.connection.getEpochInfo();
|
|
112
112
|
console.log(import_chalk.default.white(` Current Epoch: ${epochInfo.epoch}`));
|
|
113
|
+
console.log(import_chalk.default.cyan("\n====== Validators: ======\n"));
|
|
114
|
+
const bonds = await client.program.account.validatorBond.all();
|
|
115
|
+
const publicKeys = bonds.map((b) => b.publicKey);
|
|
116
|
+
const bondAccounts = await provider.connection.getMultipleAccountsInfo(publicKeys);
|
|
117
|
+
const bondBalances = bondAccounts.map((acc) => acc?.lamports ?? 0);
|
|
118
|
+
if (bonds.length === 0) {
|
|
119
|
+
console.log(import_chalk.default.dim("No validators found"));
|
|
120
|
+
} else {
|
|
121
|
+
bonds.forEach((b, i) => {
|
|
122
|
+
console.log(import_chalk.default.magenta(prettyJson({
|
|
123
|
+
balance: `${bondBalances[i] / import_web32.LAMPORTS_PER_SOL} SOL`,
|
|
124
|
+
...b
|
|
125
|
+
})));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
113
128
|
} catch (error) {
|
|
114
129
|
console.error(import_chalk.default.red(`Failed to get global state info: ${error}`));
|
|
115
130
|
process.exit(1);
|
|
@@ -152,7 +167,7 @@ import_commander.program.command("register-validator").description("Register val
|
|
|
152
167
|
spinner.fail(import_chalk.default.red(`Failed to register validator: ${error}`));
|
|
153
168
|
}
|
|
154
169
|
});
|
|
155
|
-
import_commander.program.command("topup
|
|
170
|
+
import_commander.program.command("topup").description("Top up collateral for validator bond account").argument("<vote-account>", "Vote account public key").argument("<amount>", "Amount to top up in SOL").action(async (voteAccountStr, amount) => {
|
|
156
171
|
const spinner = (0, import_ora.default)("Topping up collateral...").start();
|
|
157
172
|
const { client } = useContext();
|
|
158
173
|
try {
|
|
@@ -170,7 +185,7 @@ import_commander.program.command("topup-collateral").description("Top up collate
|
|
|
170
185
|
process.exit(1);
|
|
171
186
|
}
|
|
172
187
|
});
|
|
173
|
-
import_commander.program.command("withdraw
|
|
188
|
+
import_commander.program.command("withdraw").description("Withdraw collateral from validator bond account").argument("<vote-account>", "Vote account public key").argument("<destination>", "Destination address for withdrawn funds").argument("<amount>", "Amount to withdraw in SOL").action(async (voteAccountStr, destinationStr, amount) => {
|
|
174
189
|
const spinner = (0, import_ora.default)("Withdrawing collateral...").start();
|
|
175
190
|
const { client } = useContext();
|
|
176
191
|
try {
|
|
@@ -314,3 +329,32 @@ import_commander.program.parseAsync().catch((e) => {
|
|
|
314
329
|
}
|
|
315
330
|
process.exit();
|
|
316
331
|
});
|
|
332
|
+
function prettyJson(obj, omitKeys = ["bump"]) {
|
|
333
|
+
const convertValue = (value) => {
|
|
334
|
+
if (value === null || value === void 0) {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
if (typeof value === "boolean" || typeof value === "number" || typeof value === "string") {
|
|
338
|
+
return value;
|
|
339
|
+
}
|
|
340
|
+
if (value && typeof value === "object") {
|
|
341
|
+
if (typeof value.toString === "function" && value.constructor.name !== "Object") {
|
|
342
|
+
return value.toString();
|
|
343
|
+
}
|
|
344
|
+
if (Array.isArray(value)) {
|
|
345
|
+
return value.map((item) => convertValue(item));
|
|
346
|
+
}
|
|
347
|
+
const converted2 = {};
|
|
348
|
+
for (const [k, v] of Object.entries(value)) {
|
|
349
|
+
if (omitKeys.includes(k)) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
converted2[k] = convertValue(v);
|
|
353
|
+
}
|
|
354
|
+
return converted2;
|
|
355
|
+
}
|
|
356
|
+
return String(value);
|
|
357
|
+
};
|
|
358
|
+
const converted = convertValue(obj);
|
|
359
|
+
return JSON.stringify(converted, null, 2);
|
|
360
|
+
}
|