@jpool/bond-sdk 0.7.0 → 0.8.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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _solana_web3_js from '@solana/web3.js';
2
- import { PublicKey, Connection, Keypair, PublicKeyInitData, Transaction, VersionedTransaction } from '@solana/web3.js';
3
- import { BN, AnchorProvider, Program, Wallet as Wallet$1 } from '@coral-xyz/anchor';
2
+ import { PublicKey, Transaction, VersionedTransaction, Keypair, Connection, PublicKeyInitData } from '@solana/web3.js';
3
+ import { BN, AnchorProvider, Program } from '@coral-xyz/anchor';
4
4
 
5
5
  /**
6
6
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -286,12 +286,6 @@ type Jbond = {
286
286
  {
287
287
  "name": "initialCollateral";
288
288
  "type": "u64";
289
- },
290
- {
291
- "name": "withdrawalAuthority";
292
- "type": {
293
- "option": "pubkey";
294
- };
295
289
  }
296
290
  ];
297
291
  },
@@ -356,6 +350,72 @@ type Jbond = {
356
350
  ];
357
351
  "args": [];
358
352
  },
353
+ {
354
+ "name": "setWithdrawAuthority";
355
+ "docs": [
356
+ "Sets a new withdrawal authority for a validator's bond account.",
357
+ "Allows changing who can withdraw collateral in the future.",
358
+ "",
359
+ "# Arguments",
360
+ "* `new_withdraw_authority` - Optional new withdrawal authority key (None to restrict to identity).",
361
+ "",
362
+ "# Errors",
363
+ "Fails if the signer is not authorized to change the withdrawal authority."
364
+ ];
365
+ "discriminator": [
366
+ 199,
367
+ 146,
368
+ 140,
369
+ 67,
370
+ 1,
371
+ 90,
372
+ 8,
373
+ 222
374
+ ];
375
+ "accounts": [
376
+ {
377
+ "name": "validatorBond";
378
+ "writable": true;
379
+ "pda": {
380
+ "seeds": [
381
+ {
382
+ "kind": "const";
383
+ "value": [
384
+ 118,
385
+ 97,
386
+ 108,
387
+ 105,
388
+ 100,
389
+ 97,
390
+ 116,
391
+ 111,
392
+ 114,
393
+ 95,
394
+ 98,
395
+ 111,
396
+ 110,
397
+ 100
398
+ ];
399
+ },
400
+ {
401
+ "kind": "account";
402
+ "path": "validator_bond.vote_account";
403
+ "account": "validatorBond";
404
+ }
405
+ ];
406
+ };
407
+ },
408
+ {
409
+ "name": "identity";
410
+ "signer": true;
411
+ },
412
+ {
413
+ "name": "newWithdrawAuthority";
414
+ "optional": true;
415
+ }
416
+ ];
417
+ "args": [];
418
+ },
359
419
  {
360
420
  "name": "topUp";
361
421
  "docs": [
@@ -628,7 +688,7 @@ type Jbond = {
628
688
  {
629
689
  "code": 6006;
630
690
  "name": "validatorNotActive";
631
- "msg": "Validator boost account is not active";
691
+ "msg": "Validator bond account is not active";
632
692
  },
633
693
  {
634
694
  "code": 6007;
@@ -891,7 +951,6 @@ type RegisterValidatorProps = {
891
951
  identity: PublicKey;
892
952
  voteAccount: PublicKey;
893
953
  initialCollateral: number;
894
- withdrawalAuthority?: PublicKey;
895
954
  creator?: PublicKey;
896
955
  };
897
956
  type TopUpCollateralProps = {
@@ -927,6 +986,11 @@ type SetAuthorityProps = {
927
986
  newAuthority: PublicKey;
928
987
  authority?: PublicKey;
929
988
  };
989
+ type SetWithdrawAuthorityProps = {
990
+ voteAccount: PublicKey;
991
+ newWithdrawAuthority?: PublicKey | null;
992
+ identity?: PublicKey;
993
+ };
930
994
  type GlobalState = {
931
995
  authority: PublicKey;
932
996
  totalValidators: number;
@@ -956,6 +1020,20 @@ declare enum BondTransactionType {
956
1020
  Compensation = "compensation"
957
1021
  }
958
1022
 
1023
+ type Wallet = {
1024
+ publicKey: PublicKey;
1025
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
1026
+ signTransaction: <T extends Transaction | VersionedTransaction>(tx: T) => Promise<T>;
1027
+ signAllTransactions: <T extends Transaction | VersionedTransaction>(txs: T[]) => Promise<T[]>;
1028
+ };
1029
+ declare class NodeWallet implements Wallet {
1030
+ readonly payer: Keypair;
1031
+ constructor(payer: Keypair);
1032
+ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
1033
+ signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
1034
+ get publicKey(): PublicKey;
1035
+ }
1036
+
959
1037
  /**
960
1038
  * Enum for different client environments.
961
1039
  */
@@ -979,7 +1057,7 @@ declare class JBondClient {
979
1057
  /**
980
1058
  * Creates an instance of `JBondClient` using a provided connection and wallet.
981
1059
  */
982
- static fromWallet(connection: Connection, wallet?: Wallet$1, options?: ClientOptions): JBondClient;
1060
+ static fromWallet(connection: Connection, wallet?: Wallet, options?: ClientOptions): JBondClient;
983
1061
  /**
984
1062
  * Creates an instance of `JBondClient` using the provided connection and keypair.
985
1063
  */
@@ -1041,6 +1119,13 @@ declare class JBondClient {
1041
1119
  * @return Transaction signature
1042
1120
  */
1043
1121
  setAuthority(props: SetAuthorityProps): Promise<string>;
1122
+ /**
1123
+ * Set withdrawal authority for validator bond
1124
+ * Only the validator identity can call this
1125
+ * Default identity is the provider's wallet
1126
+ * @return Transaction signature
1127
+ */
1128
+ setWithdrawAuthority(props: SetWithdrawAuthorityProps): Promise<string>;
1044
1129
  /**
1045
1130
  * Build initialize instruction
1046
1131
  */
@@ -1065,6 +1150,10 @@ declare class JBondClient {
1065
1150
  * Build set authority instruction
1066
1151
  */
1067
1152
  buildSetAuthorityInstruction(props: SetAuthorityProps): Promise<_solana_web3_js.TransactionInstruction>;
1153
+ /**
1154
+ * Build set withdraw authority instruction
1155
+ */
1156
+ buildSetWithdrawAuthorityInstruction(props: SetWithdrawAuthorityProps): Promise<_solana_web3_js.TransactionInstruction>;
1068
1157
  /**
1069
1158
  * Fetch global state or throw if not found
1070
1159
  */
@@ -1132,18 +1221,4 @@ declare class JBondClient {
1132
1221
  */
1133
1222
  declare const ENV_PROGRAM_ID: Record<string, PublicKey>;
1134
1223
 
1135
- type Wallet = {
1136
- publicKey: PublicKey;
1137
- signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
1138
- signTransaction: <T extends Transaction | VersionedTransaction>(tx: T) => Promise<T>;
1139
- signAllTransactions: <T extends Transaction | VersionedTransaction>(txs: T[]) => Promise<T[]>;
1140
- };
1141
- declare class NodeWallet implements Wallet {
1142
- readonly payer: Keypair;
1143
- constructor(payer: Keypair);
1144
- signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
1145
- signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
1146
- get publicKey(): PublicKey;
1147
- }
1148
-
1149
- export { BondClientEnv, BondTransactionType, type ClaimProps, type ClientOptions, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, NodeWallet, type RegisterValidatorProps, type SetAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps };
1224
+ export { BondClientEnv, BondTransactionType, type ClaimProps, type ClientOptions, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, NodeWallet, type RegisterValidatorProps, type SetAuthorityProps, type SetWithdrawAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _solana_web3_js from '@solana/web3.js';
2
- import { PublicKey, Connection, Keypair, PublicKeyInitData, Transaction, VersionedTransaction } from '@solana/web3.js';
3
- import { BN, AnchorProvider, Program, Wallet as Wallet$1 } from '@coral-xyz/anchor';
2
+ import { PublicKey, Transaction, VersionedTransaction, Keypair, Connection, PublicKeyInitData } from '@solana/web3.js';
3
+ import { BN, AnchorProvider, Program } from '@coral-xyz/anchor';
4
4
 
5
5
  /**
6
6
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -286,12 +286,6 @@ type Jbond = {
286
286
  {
287
287
  "name": "initialCollateral";
288
288
  "type": "u64";
289
- },
290
- {
291
- "name": "withdrawalAuthority";
292
- "type": {
293
- "option": "pubkey";
294
- };
295
289
  }
296
290
  ];
297
291
  },
@@ -356,6 +350,72 @@ type Jbond = {
356
350
  ];
357
351
  "args": [];
358
352
  },
353
+ {
354
+ "name": "setWithdrawAuthority";
355
+ "docs": [
356
+ "Sets a new withdrawal authority for a validator's bond account.",
357
+ "Allows changing who can withdraw collateral in the future.",
358
+ "",
359
+ "# Arguments",
360
+ "* `new_withdraw_authority` - Optional new withdrawal authority key (None to restrict to identity).",
361
+ "",
362
+ "# Errors",
363
+ "Fails if the signer is not authorized to change the withdrawal authority."
364
+ ];
365
+ "discriminator": [
366
+ 199,
367
+ 146,
368
+ 140,
369
+ 67,
370
+ 1,
371
+ 90,
372
+ 8,
373
+ 222
374
+ ];
375
+ "accounts": [
376
+ {
377
+ "name": "validatorBond";
378
+ "writable": true;
379
+ "pda": {
380
+ "seeds": [
381
+ {
382
+ "kind": "const";
383
+ "value": [
384
+ 118,
385
+ 97,
386
+ 108,
387
+ 105,
388
+ 100,
389
+ 97,
390
+ 116,
391
+ 111,
392
+ 114,
393
+ 95,
394
+ 98,
395
+ 111,
396
+ 110,
397
+ 100
398
+ ];
399
+ },
400
+ {
401
+ "kind": "account";
402
+ "path": "validator_bond.vote_account";
403
+ "account": "validatorBond";
404
+ }
405
+ ];
406
+ };
407
+ },
408
+ {
409
+ "name": "identity";
410
+ "signer": true;
411
+ },
412
+ {
413
+ "name": "newWithdrawAuthority";
414
+ "optional": true;
415
+ }
416
+ ];
417
+ "args": [];
418
+ },
359
419
  {
360
420
  "name": "topUp";
361
421
  "docs": [
@@ -628,7 +688,7 @@ type Jbond = {
628
688
  {
629
689
  "code": 6006;
630
690
  "name": "validatorNotActive";
631
- "msg": "Validator boost account is not active";
691
+ "msg": "Validator bond account is not active";
632
692
  },
633
693
  {
634
694
  "code": 6007;
@@ -891,7 +951,6 @@ type RegisterValidatorProps = {
891
951
  identity: PublicKey;
892
952
  voteAccount: PublicKey;
893
953
  initialCollateral: number;
894
- withdrawalAuthority?: PublicKey;
895
954
  creator?: PublicKey;
896
955
  };
897
956
  type TopUpCollateralProps = {
@@ -927,6 +986,11 @@ type SetAuthorityProps = {
927
986
  newAuthority: PublicKey;
928
987
  authority?: PublicKey;
929
988
  };
989
+ type SetWithdrawAuthorityProps = {
990
+ voteAccount: PublicKey;
991
+ newWithdrawAuthority?: PublicKey | null;
992
+ identity?: PublicKey;
993
+ };
930
994
  type GlobalState = {
931
995
  authority: PublicKey;
932
996
  totalValidators: number;
@@ -956,6 +1020,20 @@ declare enum BondTransactionType {
956
1020
  Compensation = "compensation"
957
1021
  }
958
1022
 
1023
+ type Wallet = {
1024
+ publicKey: PublicKey;
1025
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
1026
+ signTransaction: <T extends Transaction | VersionedTransaction>(tx: T) => Promise<T>;
1027
+ signAllTransactions: <T extends Transaction | VersionedTransaction>(txs: T[]) => Promise<T[]>;
1028
+ };
1029
+ declare class NodeWallet implements Wallet {
1030
+ readonly payer: Keypair;
1031
+ constructor(payer: Keypair);
1032
+ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
1033
+ signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
1034
+ get publicKey(): PublicKey;
1035
+ }
1036
+
959
1037
  /**
960
1038
  * Enum for different client environments.
961
1039
  */
@@ -979,7 +1057,7 @@ declare class JBondClient {
979
1057
  /**
980
1058
  * Creates an instance of `JBondClient` using a provided connection and wallet.
981
1059
  */
982
- static fromWallet(connection: Connection, wallet?: Wallet$1, options?: ClientOptions): JBondClient;
1060
+ static fromWallet(connection: Connection, wallet?: Wallet, options?: ClientOptions): JBondClient;
983
1061
  /**
984
1062
  * Creates an instance of `JBondClient` using the provided connection and keypair.
985
1063
  */
@@ -1041,6 +1119,13 @@ declare class JBondClient {
1041
1119
  * @return Transaction signature
1042
1120
  */
1043
1121
  setAuthority(props: SetAuthorityProps): Promise<string>;
1122
+ /**
1123
+ * Set withdrawal authority for validator bond
1124
+ * Only the validator identity can call this
1125
+ * Default identity is the provider's wallet
1126
+ * @return Transaction signature
1127
+ */
1128
+ setWithdrawAuthority(props: SetWithdrawAuthorityProps): Promise<string>;
1044
1129
  /**
1045
1130
  * Build initialize instruction
1046
1131
  */
@@ -1065,6 +1150,10 @@ declare class JBondClient {
1065
1150
  * Build set authority instruction
1066
1151
  */
1067
1152
  buildSetAuthorityInstruction(props: SetAuthorityProps): Promise<_solana_web3_js.TransactionInstruction>;
1153
+ /**
1154
+ * Build set withdraw authority instruction
1155
+ */
1156
+ buildSetWithdrawAuthorityInstruction(props: SetWithdrawAuthorityProps): Promise<_solana_web3_js.TransactionInstruction>;
1068
1157
  /**
1069
1158
  * Fetch global state or throw if not found
1070
1159
  */
@@ -1132,18 +1221,4 @@ declare class JBondClient {
1132
1221
  */
1133
1222
  declare const ENV_PROGRAM_ID: Record<string, PublicKey>;
1134
1223
 
1135
- type Wallet = {
1136
- publicKey: PublicKey;
1137
- signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
1138
- signTransaction: <T extends Transaction | VersionedTransaction>(tx: T) => Promise<T>;
1139
- signAllTransactions: <T extends Transaction | VersionedTransaction>(txs: T[]) => Promise<T[]>;
1140
- };
1141
- declare class NodeWallet implements Wallet {
1142
- readonly payer: Keypair;
1143
- constructor(payer: Keypair);
1144
- signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
1145
- signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
1146
- get publicKey(): PublicKey;
1147
- }
1148
-
1149
- export { BondClientEnv, BondTransactionType, type ClaimProps, type ClientOptions, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, NodeWallet, type RegisterValidatorProps, type SetAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps };
1224
+ export { BondClientEnv, BondTransactionType, type ClaimProps, type ClientOptions, ENV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, NodeWallet, type RegisterValidatorProps, type SetAuthorityProps, type SetWithdrawAuthorityProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBond, type WithdrawCollateralProps };
package/dist/index.js CHANGED
@@ -294,12 +294,6 @@ var jbond_default = {
294
294
  {
295
295
  name: "initial_collateral",
296
296
  type: "u64"
297
- },
298
- {
299
- name: "withdrawal_authority",
300
- type: {
301
- option: "pubkey"
302
- }
303
297
  }
304
298
  ]
305
299
  },
@@ -364,6 +358,72 @@ var jbond_default = {
364
358
  ],
365
359
  args: []
366
360
  },
361
+ {
362
+ name: "set_withdraw_authority",
363
+ docs: [
364
+ "Sets a new withdrawal authority for a validator's bond account.",
365
+ "Allows changing who can withdraw collateral in the future.",
366
+ "",
367
+ "# Arguments",
368
+ "* `new_withdraw_authority` - Optional new withdrawal authority key (None to restrict to identity).",
369
+ "",
370
+ "# Errors",
371
+ "Fails if the signer is not authorized to change the withdrawal authority."
372
+ ],
373
+ discriminator: [
374
+ 199,
375
+ 146,
376
+ 140,
377
+ 67,
378
+ 1,
379
+ 90,
380
+ 8,
381
+ 222
382
+ ],
383
+ accounts: [
384
+ {
385
+ name: "validator_bond",
386
+ writable: true,
387
+ pda: {
388
+ seeds: [
389
+ {
390
+ kind: "const",
391
+ value: [
392
+ 118,
393
+ 97,
394
+ 108,
395
+ 105,
396
+ 100,
397
+ 97,
398
+ 116,
399
+ 111,
400
+ 114,
401
+ 95,
402
+ 98,
403
+ 111,
404
+ 110,
405
+ 100
406
+ ]
407
+ },
408
+ {
409
+ kind: "account",
410
+ path: "validator_bond.vote_account",
411
+ account: "ValidatorBond"
412
+ }
413
+ ]
414
+ }
415
+ },
416
+ {
417
+ name: "identity",
418
+ signer: true
419
+ },
420
+ {
421
+ name: "new_withdraw_authority",
422
+ optional: true
423
+ }
424
+ ],
425
+ args: []
426
+ },
367
427
  {
368
428
  name: "top_up",
369
429
  docs: [
@@ -636,7 +696,7 @@ var jbond_default = {
636
696
  {
637
697
  code: 6006,
638
698
  name: "ValidatorNotActive",
639
- msg: "Validator boost account is not active"
699
+ msg: "Validator bond account is not active"
640
700
  },
641
701
  {
642
702
  code: 6007,
@@ -1059,6 +1119,16 @@ var JBondClient = class _JBondClient {
1059
1119
  const ix = await this.buildSetAuthorityInstruction(props);
1060
1120
  return await this.provider.sendAndConfirm(new web3_js.Transaction().add(ix));
1061
1121
  }
1122
+ /**
1123
+ * Set withdrawal authority for validator bond
1124
+ * Only the validator identity can call this
1125
+ * Default identity is the provider's wallet
1126
+ * @return Transaction signature
1127
+ */
1128
+ async setWithdrawAuthority(props) {
1129
+ const ix = await this.buildSetWithdrawAuthorityInstruction(props);
1130
+ return await this.provider.sendAndConfirm(new web3_js.Transaction().add(ix));
1131
+ }
1062
1132
  /**
1063
1133
  * Build initialize instruction
1064
1134
  */
@@ -1076,12 +1146,12 @@ var JBondClient = class _JBondClient {
1076
1146
  * Build register validator instruction
1077
1147
  */
1078
1148
  async buildRegisterValidatorInstruction(props) {
1079
- const { identity, voteAccount, initialCollateral, withdrawalAuthority } = props;
1149
+ const { identity, voteAccount, initialCollateral } = props;
1080
1150
  const [globalState] = this.pda.globalState();
1081
1151
  const [validatorBond] = this.pda.validatorBond(voteAccount);
1082
1152
  const lamports = new anchor.BN(initialCollateral * web3_js.LAMPORTS_PER_SOL);
1083
1153
  const creator = props.creator ?? this.provider.wallet.publicKey;
1084
- return this.program.methods.register(lamports, withdrawalAuthority ?? null).accountsPartial({
1154
+ return this.program.methods.register(lamports).accountsPartial({
1085
1155
  creator,
1086
1156
  globalState,
1087
1157
  validatorBond,
@@ -1153,6 +1223,19 @@ var JBondClient = class _JBondClient {
1153
1223
  newAuthority: props.newAuthority
1154
1224
  }).instruction();
1155
1225
  }
1226
+ /**
1227
+ * Build set withdraw authority instruction
1228
+ */
1229
+ async buildSetWithdrawAuthorityInstruction(props) {
1230
+ const { voteAccount, newWithdrawAuthority } = props;
1231
+ const [validatorBond] = this.pda.validatorBond(voteAccount);
1232
+ const identity = props.identity ?? this.provider.wallet.publicKey;
1233
+ return this.program.methods.setWithdrawAuthority().accountsPartial({
1234
+ validatorBond,
1235
+ identity,
1236
+ newWithdrawAuthority: newWithdrawAuthority ?? null
1237
+ }).instruction();
1238
+ }
1156
1239
  /**
1157
1240
  * Fetch global state or throw if not found
1158
1241
  */
@@ -1227,14 +1310,14 @@ var JBondClient = class _JBondClient {
1227
1310
  */
1228
1311
  async getHistory(vote, options) {
1229
1312
  const [ValidatorBondAccount] = this.pda.validatorBond(new web3_js.PublicKey(vote));
1230
- const signatures = await this.connection.getSignaturesForAddress(
1313
+ const signatures = (await this.connection.getSignaturesForAddress(
1231
1314
  ValidatorBondAccount,
1232
1315
  {
1233
1316
  limit: options?.limit || 1e3,
1234
1317
  before: options?.before,
1235
1318
  until: options?.until
1236
1319
  }
1237
- );
1320
+ )).filter((sig) => !sig.err);
1238
1321
  const signatureStrings = signatures.map((sig) => sig.signature);
1239
1322
  const BATCH_SIZE = 100;
1240
1323
  const allTransactions = [];
@@ -1252,7 +1335,7 @@ var JBondClient = class _JBondClient {
1252
1335
  const history = [];
1253
1336
  for (const [idx, tx] of allTransactions.entries()) {
1254
1337
  const sigInfo = signatures[idx];
1255
- if (!tx || !tx.meta) {
1338
+ if (!tx || !tx.meta || tx.meta.err !== null) {
1256
1339
  continue;
1257
1340
  }
1258
1341
  try {