@jpool/bond-sdk 0.1.0-next.2 → 0.1.0-next.4

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 CHANGED
@@ -1,126 +1,6 @@
1
- # JBond CLI
1
+ # @jpool/bond-sdk
2
2
 
3
- Command-line interface for interacting with the JBond Solana contract.
3
+ ![https://img.shields.io/npm/v/@jpool/bond-sdk.svg](https://img.shields.io/npm/v/@jpool/bond-sdk.svg?style=flat-square)
4
+ [![npm downloads](https://img.shields.io/npm/dt/@jpool/bond-sdk.svg?maxAge=2592000&style=flat-square)](https://npm-stat.com/charts.html?package=@jpool/bond-sdk)
4
5
 
5
- ## Installation
6
-
7
- ```bash
8
- cd app
9
- npm install
10
- npm run build
11
- ```
12
-
13
- ## Configuration
14
-
15
- 1. Copy `.env.example` to `.env`:
16
-
17
- ```bash
18
- cp .env.example .env
19
- ```
20
-
21
- 2. Edit `.env` with your configuration:
22
-
23
- - `SOLANA_RPC_URL`: Solana RPC endpoint
24
- - `PROGRAM_ID`: JBond program ID
25
- - `RESERVE_ADDRESS`: Reserve vault address
26
- - `KEYPAIR_PATH`: Path to your Solana keypair (optional)
27
-
28
- ## Usage
29
-
30
- ### Initialize Compensation Pool (First time setup)
31
-
32
- ```bash
33
- npm run dev initialize
34
- # or with custom keypair
35
- npm run dev initialize --keypair /path/to/authority.json
36
- ```
37
-
38
- ### Register Validator
39
-
40
- ```bash
41
- # Register with vote account and 10 SOL initial collateral
42
- npm run dev register-validator <vote-account-pubkey> 10
43
- ```
44
-
45
- ### Top Up Collateral
46
-
47
- ```bash
48
- # Add 5 SOL to existing collateral
49
- npm run dev topup-collateral <vote-account-pubkey> 5
50
- ```
51
-
52
- ### Withdraw Compensation (Oracle only)
53
-
54
- ```bash
55
- # Withdraw 2 SOL from validator
56
- npm run dev withdraw-compensation <validator-pubkey> <vote-account-pubkey> 2
57
- ```
58
-
59
- ### Check Validator Info
60
-
61
- ```bash
62
- # Check validator boost account
63
- npm run dev validator-info <vote-account-pubkey>
64
-
65
- # Check specific validator
66
- npm run dev validator-info <vote-account-pubkey> --validator <validator-pubkey>
67
- ```
68
-
69
- ### Check Pool Info
70
-
71
- ```bash
72
- npm run dev pool-info
73
- ```
74
-
75
- ## Building for Production
76
-
77
- ```bash
78
- npm run build
79
- npm link # Make 'jbond' command available globally
80
- ```
81
-
82
- Then you can use:
83
-
84
- ```bash
85
- jbond validator-info <vote-account-pubkey>
86
- jbond register-validator <vote-account-pubkey> 10
87
- # etc...
88
- ```
89
-
90
- ## Project Structure
91
-
92
- ```
93
- app/
94
- ├── src/
95
- │ ├── cli.ts # Main CLI entry point
96
- │ ├── client.ts # JBond client implementation
97
- │ ├── config.ts # Configuration loader
98
- │ ├── types/ # TypeScript types
99
- │ └── idl/ # Contract IDL
100
- ├── package.json
101
- ├── tsconfig.json
102
- ├── .env.example
103
- └── README.md
104
- ```
105
-
106
- ## Development
107
-
108
- ```bash
109
- # Run in development mode
110
- npm run dev <command>
111
-
112
- # Build
113
- npm run build
114
-
115
- # Lint
116
- npm run lint
117
-
118
- # Format
119
- npm run format
120
- ```
121
-
122
- ## Important Notes
123
-
124
- 1. Before registering a validator, make sure you have your vote account public key
125
- 2. The authority keypair is required for initialize and withdraw-compensation commands
126
- 3. Make sure to copy your program's IDL file to `src/idl/jbond.json` after building the Anchor program
6
+ > The bond module of [jpool](https://jpool.one/).
package/dist/index.d.mts CHANGED
@@ -3,8 +3,6 @@ import { PublicKey, Connection, Keypair, TransactionInstruction } from '@solana/
3
3
 
4
4
  type Config = {
5
5
  rpcUrl: string;
6
- programId: PublicKey;
7
- reserveAddress: PublicKey;
8
6
  };
9
7
  type ValidatorBondAccount = {
10
8
  identity: PublicKey;
@@ -18,6 +16,7 @@ type ValidatorBondAccount = {
18
16
  };
19
17
  type InitializeProps = {
20
18
  authority: PublicKey;
19
+ reserveAddress: PublicKey;
21
20
  };
22
21
  type RegisterValidatorProps = {
23
22
  creator: PublicKey;
@@ -90,7 +89,7 @@ declare enum BondTransactionType {
90
89
  * IDL can be found at `target/idl/jbond.json`.
91
90
  */
92
91
  type Jbond = {
93
- address: '4a3YovKEfm4jWhczCzJciHXL1xVkXWfGQjRCaMft7M4G';
92
+ address: '8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr';
94
93
  metadata: {
95
94
  name: 'jbond';
96
95
  version: '0.1.0';
@@ -321,6 +320,10 @@ type Jbond = {
321
320
  name: 'destination';
322
321
  writable: true;
323
322
  },
323
+ {
324
+ name: 'epochSchedule';
325
+ address: 'SysvarEpochSchedu1e111111111111111111111111';
326
+ },
324
327
  {
325
328
  name: 'systemProgram';
326
329
  address: '11111111111111111111111111111111';
@@ -389,6 +392,60 @@ type Jbond = {
389
392
  ];
390
393
  args: [];
391
394
  },
395
+ {
396
+ name: 'setAuthority';
397
+ docs: [
398
+ 'Change the bond authority'
399
+ ];
400
+ discriminator: [
401
+ 133,
402
+ 250,
403
+ 37,
404
+ 21,
405
+ 110,
406
+ 163,
407
+ 26,
408
+ 121
409
+ ];
410
+ accounts: [
411
+ {
412
+ name: 'globalState';
413
+ writable: true;
414
+ pda: {
415
+ seeds: [
416
+ {
417
+ kind: 'const';
418
+ value: [
419
+ 103,
420
+ 108,
421
+ 111,
422
+ 98,
423
+ 97,
424
+ 108,
425
+ 95,
426
+ 115,
427
+ 116,
428
+ 97,
429
+ 116,
430
+ 101
431
+ ];
432
+ }
433
+ ];
434
+ };
435
+ },
436
+ {
437
+ name: 'authority';
438
+ signer: true;
439
+ relations: [
440
+ 'globalState'
441
+ ];
442
+ },
443
+ {
444
+ name: 'newAuthority';
445
+ }
446
+ ];
447
+ args: [];
448
+ },
392
449
  {
393
450
  name: 'withdrawCompensation';
394
451
  docs: [
@@ -613,6 +670,11 @@ type Jbond = {
613
670
  code: 6008;
614
671
  name: 'unauthorized';
615
672
  msg: 'unauthorized';
673
+ },
674
+ {
675
+ code: 6009;
676
+ name: 'withdrawalLockedNearEpochEnd';
677
+ msg: 'Withdrawals are locked near the end of the epoch.';
616
678
  }
617
679
  ];
618
680
  types: [
@@ -797,20 +859,37 @@ type Jbond = {
797
859
  ];
798
860
  };
799
861
 
862
+ declare enum BondClientEnv {
863
+ DEV = "dev",
864
+ PROD = "prod"
865
+ }
800
866
  declare class JBondClient {
801
867
  connection: Connection;
802
868
  program: Program<Jbond>;
803
869
  provider: AnchorProvider;
804
870
  config: Config;
805
- constructor(config: Config, wallet?: Wallet);
871
+ readonly options: ClientOptions;
872
+ constructor(config: Config, wallet?: Wallet, options?: ClientOptions);
806
873
  /**
807
874
  * Creates an instance of `JBondClient` using a provided connection and wallet.
808
875
  */
809
- static fromWallet(config: Config, wallet?: Wallet): JBondClient;
876
+ static fromWallet(config: Config, wallet?: Wallet, options?: ClientOptions): JBondClient;
810
877
  /**
811
878
  * Creates an instance of `JBondClient` using the provided connection and keypair.
812
879
  */
813
- static fromKeypair(config: Config, keypair: Keypair): JBondClient;
880
+ static fromKeypair(config: Config, keypair: Keypair, options?: ClientOptions): JBondClient;
881
+ /**
882
+ * Get the current program ID.
883
+ */
884
+ get programId(): PublicKey;
885
+ /**
886
+ * Set the environment.
887
+ */
888
+ env(env: BondClientEnv): this;
889
+ /**
890
+ * Configure a specific option.
891
+ */
892
+ configure<K extends keyof ClientOptions>(key: K, val: ClientOptions[K]): this;
814
893
  getGlobalStatePDA(): [PublicKey, number];
815
894
  getValidatorBondPDA(voteAccount: PublicKey): [PublicKey, number];
816
895
  buildInitializeInstruction(props: InitializeProps): Promise<TransactionInstruction>;
@@ -823,6 +902,10 @@ declare class JBondClient {
823
902
  amount: number;
824
903
  }>): Promise<TransactionInstruction[]>;
825
904
  getValidatorBondAccount(voteAccount: PublicKey): Promise<ValidatorBondAccount | null>;
905
+ buildSetAuthorityInstruction(props: {
906
+ authority: PublicKey;
907
+ newAuthority: PublicKey;
908
+ }): Promise<TransactionInstruction>;
826
909
  /**
827
910
  * Get the collateral balance of a validator bond account
828
911
  * @param voteAccount - The vote account public key
@@ -833,9 +916,10 @@ declare class JBondClient {
833
916
  authority: string;
834
917
  totalValidators: number;
835
918
  totalWithdrawn: number;
919
+ reserveAddress: string;
836
920
  } | null>;
837
921
  getCurrentEpoch(): Promise<number>;
838
- initialize(authority?: PublicKey): Promise<string>;
922
+ initialize(reserveAddress: PublicKey, authority?: PublicKey): Promise<string>;
839
923
  registerValidator(voteAccount: PublicKey, initialCollateral: number, withdrawalAuthority?: PublicKey, identity?: PublicKey): Promise<string>;
840
924
  topUpCollateral(voteAccount: PublicKey, amount: number, validator?: PublicKey): Promise<string>;
841
925
  withdrawCollateral(voteAccount: PublicKey, destination: PublicKey, amount: number, withdrawalAuthority?: PublicKey): Promise<string>;
@@ -856,11 +940,12 @@ declare class JBondClient {
856
940
  getFullHistory(voteAccount: PublicKey, pageSize?: number): Promise<TransactionHistoryItem[]>;
857
941
  private getInstructionDiscriminator;
858
942
  }
943
+ type ClientOptions = {
944
+ programId?: PublicKey;
945
+ debug?: boolean;
946
+ } & Record<string, any>;
859
947
 
860
- declare const PROGRAM_ID = "4a3YovKEfm4jWhczCzJciHXL1xVkXWfGQjRCaMft7M4G";
861
- declare const RESERVE_ADDRESS = "61mS9nEir6jx6cvte6NzQpyrFk3Fj4krMNLuHhi4tjJz";
862
-
863
- declare function loadConfig(): Config;
864
- declare function loadKeypair(keypairPath: string): Keypair;
948
+ declare const PROGRAM_ID: PublicKey;
949
+ declare const DEV_PROGRAM_ID: PublicKey;
865
950
 
866
- export { BondTransactionType, type Config, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, PROGRAM_ID, RESERVE_ADDRESS, type RegisterValidatorProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBondAccount, type WithdrawCollateralProps, type WithdrawCompensationProps, loadConfig, loadKeypair };
951
+ export { BondClientEnv, BondTransactionType, type ClientOptions, type Config, DEV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, PROGRAM_ID, type RegisterValidatorProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBondAccount, type WithdrawCollateralProps, type WithdrawCompensationProps };
package/dist/index.d.ts CHANGED
@@ -3,8 +3,6 @@ import { PublicKey, Connection, Keypair, TransactionInstruction } from '@solana/
3
3
 
4
4
  type Config = {
5
5
  rpcUrl: string;
6
- programId: PublicKey;
7
- reserveAddress: PublicKey;
8
6
  };
9
7
  type ValidatorBondAccount = {
10
8
  identity: PublicKey;
@@ -18,6 +16,7 @@ type ValidatorBondAccount = {
18
16
  };
19
17
  type InitializeProps = {
20
18
  authority: PublicKey;
19
+ reserveAddress: PublicKey;
21
20
  };
22
21
  type RegisterValidatorProps = {
23
22
  creator: PublicKey;
@@ -90,7 +89,7 @@ declare enum BondTransactionType {
90
89
  * IDL can be found at `target/idl/jbond.json`.
91
90
  */
92
91
  type Jbond = {
93
- address: '4a3YovKEfm4jWhczCzJciHXL1xVkXWfGQjRCaMft7M4G';
92
+ address: '8vrqsFHnDdjMYMwahytRzmmYgRqCMmka8X6DJUXGQzWr';
94
93
  metadata: {
95
94
  name: 'jbond';
96
95
  version: '0.1.0';
@@ -321,6 +320,10 @@ type Jbond = {
321
320
  name: 'destination';
322
321
  writable: true;
323
322
  },
323
+ {
324
+ name: 'epochSchedule';
325
+ address: 'SysvarEpochSchedu1e111111111111111111111111';
326
+ },
324
327
  {
325
328
  name: 'systemProgram';
326
329
  address: '11111111111111111111111111111111';
@@ -389,6 +392,60 @@ type Jbond = {
389
392
  ];
390
393
  args: [];
391
394
  },
395
+ {
396
+ name: 'setAuthority';
397
+ docs: [
398
+ 'Change the bond authority'
399
+ ];
400
+ discriminator: [
401
+ 133,
402
+ 250,
403
+ 37,
404
+ 21,
405
+ 110,
406
+ 163,
407
+ 26,
408
+ 121
409
+ ];
410
+ accounts: [
411
+ {
412
+ name: 'globalState';
413
+ writable: true;
414
+ pda: {
415
+ seeds: [
416
+ {
417
+ kind: 'const';
418
+ value: [
419
+ 103,
420
+ 108,
421
+ 111,
422
+ 98,
423
+ 97,
424
+ 108,
425
+ 95,
426
+ 115,
427
+ 116,
428
+ 97,
429
+ 116,
430
+ 101
431
+ ];
432
+ }
433
+ ];
434
+ };
435
+ },
436
+ {
437
+ name: 'authority';
438
+ signer: true;
439
+ relations: [
440
+ 'globalState'
441
+ ];
442
+ },
443
+ {
444
+ name: 'newAuthority';
445
+ }
446
+ ];
447
+ args: [];
448
+ },
392
449
  {
393
450
  name: 'withdrawCompensation';
394
451
  docs: [
@@ -613,6 +670,11 @@ type Jbond = {
613
670
  code: 6008;
614
671
  name: 'unauthorized';
615
672
  msg: 'unauthorized';
673
+ },
674
+ {
675
+ code: 6009;
676
+ name: 'withdrawalLockedNearEpochEnd';
677
+ msg: 'Withdrawals are locked near the end of the epoch.';
616
678
  }
617
679
  ];
618
680
  types: [
@@ -797,20 +859,37 @@ type Jbond = {
797
859
  ];
798
860
  };
799
861
 
862
+ declare enum BondClientEnv {
863
+ DEV = "dev",
864
+ PROD = "prod"
865
+ }
800
866
  declare class JBondClient {
801
867
  connection: Connection;
802
868
  program: Program<Jbond>;
803
869
  provider: AnchorProvider;
804
870
  config: Config;
805
- constructor(config: Config, wallet?: Wallet);
871
+ readonly options: ClientOptions;
872
+ constructor(config: Config, wallet?: Wallet, options?: ClientOptions);
806
873
  /**
807
874
  * Creates an instance of `JBondClient` using a provided connection and wallet.
808
875
  */
809
- static fromWallet(config: Config, wallet?: Wallet): JBondClient;
876
+ static fromWallet(config: Config, wallet?: Wallet, options?: ClientOptions): JBondClient;
810
877
  /**
811
878
  * Creates an instance of `JBondClient` using the provided connection and keypair.
812
879
  */
813
- static fromKeypair(config: Config, keypair: Keypair): JBondClient;
880
+ static fromKeypair(config: Config, keypair: Keypair, options?: ClientOptions): JBondClient;
881
+ /**
882
+ * Get the current program ID.
883
+ */
884
+ get programId(): PublicKey;
885
+ /**
886
+ * Set the environment.
887
+ */
888
+ env(env: BondClientEnv): this;
889
+ /**
890
+ * Configure a specific option.
891
+ */
892
+ configure<K extends keyof ClientOptions>(key: K, val: ClientOptions[K]): this;
814
893
  getGlobalStatePDA(): [PublicKey, number];
815
894
  getValidatorBondPDA(voteAccount: PublicKey): [PublicKey, number];
816
895
  buildInitializeInstruction(props: InitializeProps): Promise<TransactionInstruction>;
@@ -823,6 +902,10 @@ declare class JBondClient {
823
902
  amount: number;
824
903
  }>): Promise<TransactionInstruction[]>;
825
904
  getValidatorBondAccount(voteAccount: PublicKey): Promise<ValidatorBondAccount | null>;
905
+ buildSetAuthorityInstruction(props: {
906
+ authority: PublicKey;
907
+ newAuthority: PublicKey;
908
+ }): Promise<TransactionInstruction>;
826
909
  /**
827
910
  * Get the collateral balance of a validator bond account
828
911
  * @param voteAccount - The vote account public key
@@ -833,9 +916,10 @@ declare class JBondClient {
833
916
  authority: string;
834
917
  totalValidators: number;
835
918
  totalWithdrawn: number;
919
+ reserveAddress: string;
836
920
  } | null>;
837
921
  getCurrentEpoch(): Promise<number>;
838
- initialize(authority?: PublicKey): Promise<string>;
922
+ initialize(reserveAddress: PublicKey, authority?: PublicKey): Promise<string>;
839
923
  registerValidator(voteAccount: PublicKey, initialCollateral: number, withdrawalAuthority?: PublicKey, identity?: PublicKey): Promise<string>;
840
924
  topUpCollateral(voteAccount: PublicKey, amount: number, validator?: PublicKey): Promise<string>;
841
925
  withdrawCollateral(voteAccount: PublicKey, destination: PublicKey, amount: number, withdrawalAuthority?: PublicKey): Promise<string>;
@@ -856,11 +940,12 @@ declare class JBondClient {
856
940
  getFullHistory(voteAccount: PublicKey, pageSize?: number): Promise<TransactionHistoryItem[]>;
857
941
  private getInstructionDiscriminator;
858
942
  }
943
+ type ClientOptions = {
944
+ programId?: PublicKey;
945
+ debug?: boolean;
946
+ } & Record<string, any>;
859
947
 
860
- declare const PROGRAM_ID = "4a3YovKEfm4jWhczCzJciHXL1xVkXWfGQjRCaMft7M4G";
861
- declare const RESERVE_ADDRESS = "61mS9nEir6jx6cvte6NzQpyrFk3Fj4krMNLuHhi4tjJz";
862
-
863
- declare function loadConfig(): Config;
864
- declare function loadKeypair(keypairPath: string): Keypair;
948
+ declare const PROGRAM_ID: PublicKey;
949
+ declare const DEV_PROGRAM_ID: PublicKey;
865
950
 
866
- export { BondTransactionType, type Config, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, PROGRAM_ID, RESERVE_ADDRESS, type RegisterValidatorProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBondAccount, type WithdrawCollateralProps, type WithdrawCompensationProps, loadConfig, loadKeypair };
951
+ export { BondClientEnv, BondTransactionType, type ClientOptions, type Config, DEV_PROGRAM_ID, type EpochHistoryItem, type GetHistoryGroupedProps, type GetHistoryProps, type GlobalState, type InitializeProps, JBondClient, type Jbond, PROGRAM_ID, type RegisterValidatorProps, type TopUpCollateralProps, type TransactionHistoryItem, type ValidatorBondAccount, type WithdrawCollateralProps, type WithdrawCompensationProps };