@glamsystems/glam-cli 1.0.3-alpha.3 → 1.0.3-alpha.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.
Files changed (2) hide show
  1. package/main.js +43 -19
  2. package/package.json +2 -2
package/main.js CHANGED
@@ -3773,15 +3773,14 @@ class BaseClient {
3773
3773
  }).compileToV0Message(lookupTableAccounts));
3774
3774
  }
3775
3775
  async sendAndConfirm(tx, additionalSigners = []) {
3776
- const connection = this.provider.connection;
3777
3776
  // Mainnet only: use dedicated connection for sending transactions if available
3778
3777
  const txConnection = this.cluster === clientConfig_1.ClusterNetwork.Mainnet
3779
3778
  ? new web3_js_1.Connection(process.env?.NEXT_PUBLIC_TX_RPC ||
3780
- process.env.TX_RPC ||
3781
- connection.rpcEndpoint, {
3782
- commitment: "confirmed",
3779
+ process.env?.TX_RPC ||
3780
+ this.connection.rpcEndpoint, {
3781
+ commitment: this.connection.commitment,
3783
3782
  })
3784
- : connection;
3783
+ : this.connection;
3785
3784
  // This is just a convenient method so that in tests we can send legacy
3786
3785
  // txs, for example transfer SOL, create ATA, etc.
3787
3786
  if (tx instanceof web3_js_1.Transaction) {
@@ -3789,38 +3788,59 @@ class BaseClient {
3789
3788
  skipPreflight: true,
3790
3789
  });
3791
3790
  }
3792
- let serializedTx;
3793
3791
  // Anchor provider.sendAndConfirm forces a signature with the wallet, which we don't want
3794
3792
  // https://github.com/coral-xyz/anchor/blob/v0.30.0/ts/packages/anchor/src/provider.ts#L159
3795
- const wallet = this.wallet;
3796
- const signedTx = await wallet.signTransaction(tx);
3793
+ const signedTx = await this.wallet.signTransaction(tx);
3797
3794
  if (additionalSigners && additionalSigners.length > 0) {
3798
3795
  signedTx.sign(additionalSigners);
3799
3796
  }
3800
- serializedTx = signedTx.serialize();
3797
+ const serializedTx = signedTx.serialize();
3798
+ // skip simulation since we just did it to compute CUs
3799
+ // however this means that we need to reconstruct the error, if
3800
+ // the tx fails onchain execution.
3801
3801
  const txSig = await txConnection.sendRawTransaction(serializedTx, {
3802
- // skip simulation since we just did it to compute CUs
3803
- // however this means that we need to reconstruct the error, if
3804
- // the tx fails on chain execution.
3805
3802
  skipPreflight: true,
3806
3803
  });
3807
3804
  if (process.env.NODE_ENV === "development") {
3808
3805
  console.log("Confirming tx:", txSig);
3809
3806
  }
3810
- const latestBlockhash = await this.blockhashWithCache.get();
3811
- const res = await connection.confirmTransaction({
3812
- ...latestBlockhash,
3813
- signature: txSig,
3814
- });
3807
+ const res = await this.confirmTransaction(txSig);
3815
3808
  // if the tx fails, throw an error including logs
3816
3809
  if (res.value.err) {
3817
- const errTx = await connection.getTransaction(txSig, {
3810
+ const errTx = await this.connection.getTransaction(txSig, {
3818
3811
  maxSupportedTransactionVersion: 0,
3819
3812
  });
3820
3813
  throw new error_1.GlamError((0, transaction_1.parseProgramLogs)(errTx?.meta?.logMessages), errTx?.meta?.err || undefined, errTx?.meta?.logMessages || []);
3821
3814
  }
3822
3815
  return txSig;
3823
3816
  }
3817
+ async confirmTransaction(txSig) {
3818
+ const useWebSocket = !(process.env?.NEXT_PUBLIC_WEBSOCKET_DISABLED ||
3819
+ process.env?.WEBSOCKET_DISABLED);
3820
+ if (useWebSocket) {
3821
+ const latestBlockhash = await this.blockhashWithCache.get();
3822
+ return await this.connection.confirmTransaction({
3823
+ ...latestBlockhash,
3824
+ signature: txSig,
3825
+ });
3826
+ }
3827
+ if (process.env.NODE_ENV === "development") {
3828
+ console.warn("WebSocket disabled, falling back to polling signature status");
3829
+ }
3830
+ const maxRetries = 60;
3831
+ const retryDelayMs = 1000;
3832
+ for (let i = 0; i < maxRetries; i++) {
3833
+ const status = await this.connection.getSignatureStatus(txSig);
3834
+ if (status?.value?.confirmationStatus === "confirmed" ||
3835
+ status?.value?.confirmationStatus === "finalized" ||
3836
+ status?.value?.err) {
3837
+ return { value: { err: status.value.err } };
3838
+ }
3839
+ await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
3840
+ }
3841
+ const expiry = (maxRetries * retryDelayMs) / 1000;
3842
+ throw new Error(`Transaction confirmation timeout after ${expiry} seconds.`);
3843
+ }
3824
3844
  get connection() {
3825
3845
  return this.provider.connection;
3826
3846
  }
@@ -10826,6 +10846,7 @@ class CliConfig {
10826
10846
  this.cluster = config.cluster || "";
10827
10847
  this.json_rpc_url = config.json_rpc_url || "";
10828
10848
  this.tx_rpc_url = config.tx_rpc_url || "";
10849
+ this.websocket_disabled = config.websocket_disabled || false;
10829
10850
  this.keypair_path = config.keypair_path || "";
10830
10851
  this.glam_api = config.glam_api;
10831
10852
  this.priority_fee = config.priority_fee;
@@ -10873,6 +10894,9 @@ class CliConfig {
10873
10894
  if (cliConfig.tx_rpc_url) {
10874
10895
  process.env.TX_RPC = cliConfig.tx_rpc_url;
10875
10896
  }
10897
+ if (cliConfig.websocket_disabled) {
10898
+ process.env.WEBSOCKET_DISABLED = "1";
10899
+ }
10876
10900
  if (cliConfig.glam_api) {
10877
10901
  process.env.GLAM_API = cliConfig.glam_api || "https://api.glam.systems";
10878
10902
  }
@@ -14082,7 +14106,7 @@ program
14082
14106
  initialize(config, skipSimulation);
14083
14107
  await (0, idl_1.idlCheck)(context.glamClient);
14084
14108
  })
14085
- .version("1.0.3-alpha.3");
14109
+ .version("1.0.3-alpha.4");
14086
14110
  program
14087
14111
  .command("env")
14088
14112
  .description("Display current environment setup")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glamsystems/glam-cli",
3
- "version": "1.0.3-alpha.3",
3
+ "version": "1.0.3-alpha.4",
4
4
  "description": "CLI for interacting with the GLAM Protocol",
5
5
  "main": "./main.js",
6
6
  "bin": {
@@ -21,7 +21,7 @@
21
21
  "node": ">=20.18.0"
22
22
  },
23
23
  "dependencies": {
24
- "@glamsystems/glam-sdk": "1.0.3-alpha.3",
24
+ "@glamsystems/glam-sdk": "1.0.3-alpha.4",
25
25
  "@switchboard-xyz/common": "^3.0.0",
26
26
  "commander": "^11.1.0",
27
27
  "decimal.js": "^10.6.0",