@jpool/bond-sdk 0.11.0-next.18 → 0.11.0-next.20

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
@@ -1821,6 +1821,14 @@ type Jbond = {
1821
1821
  ];
1822
1822
  };
1823
1823
 
1824
+ /**
1825
+ * Enum for different client environments.
1826
+ */
1827
+ declare enum JBondClientEnv {
1828
+ DEV = "dev",
1829
+ STAGE = "stage",
1830
+ PROD = "prod"
1831
+ }
1824
1832
  type GlobalState = IdlAccounts<Jbond>['globalState'];
1825
1833
  type BondState = IdlAccounts<Jbond>['bondState'];
1826
1834
  type ValidatorBond = IdlAccounts<Jbond>['validatorBond'];
@@ -1981,7 +1989,7 @@ declare class HistoryManager {
1981
1989
  private discCache;
1982
1990
  constructor(client: JBondClient);
1983
1991
  get program(): _coral_xyz_anchor.Program<Jbond>;
1984
- get programId(): any;
1992
+ get programId(): PublicKey;
1985
1993
  get connection(): _solana_web3_js.Connection;
1986
1994
  debug(...args: any[]): void;
1987
1995
  getHistory(bondType: BondType, bondName: string, vote: PublicKeyInitData, opts?: GetHistoryOpts): Promise<TransactionHistoryItem[]>;
@@ -2005,14 +2013,6 @@ declare class NodeWallet implements Wallet {
2005
2013
  get publicKey(): PublicKey;
2006
2014
  }
2007
2015
 
2008
- /**
2009
- * Enum for different client environments.
2010
- */
2011
- declare enum JBondClientEnv {
2012
- DEV = "dev",
2013
- STAGE = "stage",
2014
- PROD = "prod"
2015
- }
2016
2016
  /**
2017
2017
  * Options for configuring the JBondClient.
2018
2018
  */
@@ -2022,7 +2022,7 @@ type JBondClientOptions = {
2022
2022
  declare class JBondClient {
2023
2023
  readonly provider: Provider;
2024
2024
  readonly options: JBondClientOptions;
2025
- readonly program: Program<Jbond>;
2025
+ private _program;
2026
2026
  constructor(provider: Provider, options?: JBondClientOptions);
2027
2027
  get history(): HistoryManager;
2028
2028
  /**
@@ -2037,10 +2037,14 @@ declare class JBondClient {
2037
2037
  * Creates an instance of `JBondClient` using the provided connection and keypair.
2038
2038
  */
2039
2039
  static fromKeypair(connection: Connection, keypair: Keypair, options?: JBondClientOptions): JBondClient;
2040
+ /**
2041
+ * Get or create the program instance
2042
+ */
2043
+ get program(): Program<Jbond>;
2040
2044
  /**
2041
2045
  * Get the current program ID.
2042
2046
  */
2043
- get programId(): any;
2047
+ get programId(): PublicKey;
2044
2048
  /**
2045
2049
  * Get the current connection.
2046
2050
  */
package/dist/index.d.ts CHANGED
@@ -1821,6 +1821,14 @@ type Jbond = {
1821
1821
  ];
1822
1822
  };
1823
1823
 
1824
+ /**
1825
+ * Enum for different client environments.
1826
+ */
1827
+ declare enum JBondClientEnv {
1828
+ DEV = "dev",
1829
+ STAGE = "stage",
1830
+ PROD = "prod"
1831
+ }
1824
1832
  type GlobalState = IdlAccounts<Jbond>['globalState'];
1825
1833
  type BondState = IdlAccounts<Jbond>['bondState'];
1826
1834
  type ValidatorBond = IdlAccounts<Jbond>['validatorBond'];
@@ -1981,7 +1989,7 @@ declare class HistoryManager {
1981
1989
  private discCache;
1982
1990
  constructor(client: JBondClient);
1983
1991
  get program(): _coral_xyz_anchor.Program<Jbond>;
1984
- get programId(): any;
1992
+ get programId(): PublicKey;
1985
1993
  get connection(): _solana_web3_js.Connection;
1986
1994
  debug(...args: any[]): void;
1987
1995
  getHistory(bondType: BondType, bondName: string, vote: PublicKeyInitData, opts?: GetHistoryOpts): Promise<TransactionHistoryItem[]>;
@@ -2005,14 +2013,6 @@ declare class NodeWallet implements Wallet {
2005
2013
  get publicKey(): PublicKey;
2006
2014
  }
2007
2015
 
2008
- /**
2009
- * Enum for different client environments.
2010
- */
2011
- declare enum JBondClientEnv {
2012
- DEV = "dev",
2013
- STAGE = "stage",
2014
- PROD = "prod"
2015
- }
2016
2016
  /**
2017
2017
  * Options for configuring the JBondClient.
2018
2018
  */
@@ -2022,7 +2022,7 @@ type JBondClientOptions = {
2022
2022
  declare class JBondClient {
2023
2023
  readonly provider: Provider;
2024
2024
  readonly options: JBondClientOptions;
2025
- readonly program: Program<Jbond>;
2025
+ private _program;
2026
2026
  constructor(provider: Provider, options?: JBondClientOptions);
2027
2027
  get history(): HistoryManager;
2028
2028
  /**
@@ -2037,10 +2037,14 @@ declare class JBondClient {
2037
2037
  * Creates an instance of `JBondClient` using the provided connection and keypair.
2038
2038
  */
2039
2039
  static fromKeypair(connection: Connection, keypair: Keypair, options?: JBondClientOptions): JBondClient;
2040
+ /**
2041
+ * Get or create the program instance
2042
+ */
2043
+ get program(): Program<Jbond>;
2040
2044
  /**
2041
2045
  * Get the current program ID.
2042
2046
  */
2043
- get programId(): any;
2047
+ get programId(): PublicKey;
2044
2048
  /**
2045
2049
  * Get the current connection.
2046
2050
  */
package/dist/index.js CHANGED
@@ -4568,20 +4568,15 @@ var import_bn = __toESM(require_bn());
4568
4568
 
4569
4569
  // src/constants.ts
4570
4570
  init_cjs_shims();
4571
- var GLOBAL_STATE_SEED = "global_state";
4572
- var BOND_STATE_SEED = "bond_state";
4573
- var VALIDATOR_BOND_SEED = "validator_bond";
4574
- var STANDARD_BOND_SEED = "standard";
4575
- var CROWDFUNDING_BOND_SEED = "crowdfunding";
4576
- var ENV_PROGRAM_ID = {
4577
- // [JBondClientEnv.DEV]: new PublicKey('...'),
4578
- };
4579
-
4580
- // src/history.ts
4581
- init_cjs_shims();
4582
4571
 
4583
4572
  // src/types/index.ts
4584
4573
  init_cjs_shims();
4574
+ var JBondClientEnv = /* @__PURE__ */ ((JBondClientEnv2) => {
4575
+ JBondClientEnv2["DEV"] = "dev";
4576
+ JBondClientEnv2["STAGE"] = "stage";
4577
+ JBondClientEnv2["PROD"] = "prod";
4578
+ return JBondClientEnv2;
4579
+ })(JBondClientEnv || {});
4585
4580
  var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
4586
4581
  SessionStatus2[SessionStatus2["Live"] = 0] = "Live";
4587
4582
  SessionStatus2[SessionStatus2["Finished"] = 1] = "Finished";
@@ -4599,7 +4594,19 @@ var BondTransactionType = /* @__PURE__ */ ((BondTransactionType2) => {
4599
4594
  return BondTransactionType2;
4600
4595
  })(BondTransactionType || {});
4601
4596
 
4597
+ // src/constants.ts
4598
+ var GLOBAL_STATE_SEED = "global_state";
4599
+ var BOND_STATE_SEED = "bond_state";
4600
+ var VALIDATOR_BOND_SEED = "validator_bond";
4601
+ var STANDARD_BOND_SEED = "standard";
4602
+ var CROWDFUNDING_BOND_SEED = "crowdfunding";
4603
+ var ENV_PROGRAM_ID = {
4604
+ ["dev" /* DEV */]: new web3_js.PublicKey("Fo17edWRJewZNTRibgx9iTfjywCW6dzS81VwBLmPFVq1"),
4605
+ ["prod" /* PROD */]: new web3_js.PublicKey("BondQ7KqZreTcW2UbeTNDcLCJQ3aXAtLn2Fm6ftaJDU")
4606
+ };
4607
+
4602
4608
  // src/history.ts
4609
+ init_cjs_shims();
4603
4610
  var { bs58 } = anchor.utils.bytes;
4604
4611
  var HistoryManager = class {
4605
4612
  constructor(client) {
@@ -6687,20 +6694,13 @@ function getBondTypeSeed(type) {
6687
6694
  }
6688
6695
 
6689
6696
  // src/client.ts
6690
- var JBondClientEnv = /* @__PURE__ */ ((JBondClientEnv2) => {
6691
- JBondClientEnv2["DEV"] = "dev";
6692
- JBondClientEnv2["STAGE"] = "stage";
6693
- JBondClientEnv2["PROD"] = "prod";
6694
- return JBondClientEnv2;
6695
- })(JBondClientEnv || {});
6696
6697
  var JBondClient = class _JBondClient {
6697
6698
  constructor(provider, options) {
6698
6699
  this.provider = provider;
6699
6700
  this.options = options ?? {};
6700
- this.program = new anchor.Program(jbond_default, this.provider);
6701
6701
  }
6702
6702
  options;
6703
- program;
6703
+ _program = null;
6704
6704
  get history() {
6705
6705
  return new HistoryManager(this);
6706
6706
  }
@@ -6729,11 +6729,24 @@ var JBondClient = class _JBondClient {
6729
6729
  static fromKeypair(connection, keypair, options) {
6730
6730
  return _JBondClient.fromWallet(connection, new NodeWallet(keypair), options);
6731
6731
  }
6732
+ /**
6733
+ * Get or create the program instance
6734
+ */
6735
+ get program() {
6736
+ if (!this._program) {
6737
+ jbond_default.address = this.programId.toBase58();
6738
+ this._program = new anchor.Program(jbond_default, this.provider);
6739
+ }
6740
+ return this._program;
6741
+ }
6732
6742
  /**
6733
6743
  * Get the current program ID.
6734
6744
  */
6735
6745
  get programId() {
6736
- return this.options.programId ?? this.program.programId;
6746
+ if (this.options.programId) {
6747
+ return this.options.programId;
6748
+ }
6749
+ return ENV_PROGRAM_ID["prod" /* PROD */];
6737
6750
  }
6738
6751
  /**
6739
6752
  * Get the current connection.
@@ -6745,7 +6758,13 @@ var JBondClient = class _JBondClient {
6745
6758
  * Set the environment.
6746
6759
  */
6747
6760
  env(env) {
6748
- return this.configure("programId", ENV_PROGRAM_ID[env]);
6761
+ const envProgramId = ENV_PROGRAM_ID[env];
6762
+ if (!envProgramId) {
6763
+ throw new Error(`Invalid environment: ${env}`);
6764
+ }
6765
+ this._program = null;
6766
+ this.debug(`Set environment to ${env} with program ID: ${envProgramId.toString()}`);
6767
+ return this.configure("programId", envProgramId);
6749
6768
  }
6750
6769
  /**
6751
6770
  * Configure a specific option.