@wireio/stake 2.0.0 → 2.1.0

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.
@@ -1,8 +1,9 @@
1
1
  import { SolChainID, PublicKey as PublicKey$1, KeyType, EvmChainID } from '@wireio/core';
2
- import { SystemProgram, StakeProgram, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_CLOCK_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, SYSVAR_RENT_PUBKEY, TransactionMessage, Transaction, PublicKey, Keypair, Connection, ComputeBudgetProgram } from '@solana/web3.js';
2
+ import { SystemProgram, StakeProgram, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_CLOCK_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, SYSVAR_RENT_PUBKEY, Transaction, PublicKey, Keypair, Connection, TransactionMessage, ComputeBudgetProgram, SendTransactionError } from '@solana/web3.js';
3
3
  import { BN, Program, AnchorProvider } from '@coral-xyz/anchor';
4
4
  import { getAssociatedTokenAddressSync, TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddress, createAssociatedTokenAccountInstruction } from '@solana/spl-token';
5
5
  import * as multisig from '@sqds/multisig';
6
+ import bs58 from 'bs58';
6
7
  import { ethers, Contract, BigNumber } from 'ethers';
7
8
 
8
9
  class DepositClient {
@@ -82,57 +83,6 @@ class DepositClient {
82
83
  globalConfig
83
84
  }).instruction();
84
85
  }
85
- async buildSquadsDepositProposalTx(params) {
86
- const { connection, multisigPda, amountLamports, wallet } = params;
87
- const vaultIndex = params.vaultIndex ?? 0;
88
- if (!wallet?.publicKey) throw new Error("wallet.publicKey missing");
89
- if (!amountLamports || amountLamports <= BigInt(0)) throw new Error("amountLamports must be > 0");
90
- const [vaultPda] = multisig.getVaultPda({ multisigPda, index: vaultIndex });
91
- const depositBuilt = await this.buildDepositIxForUser(amountLamports, vaultPda);
92
- const ms = await multisig.accounts.Multisig.fromAccountAddress(connection, multisigPda);
93
- const current = BigInt(ms.transactionIndex?.toString?.() ?? 0);
94
- const transactionIndex = current + BigInt(1);
95
- const { blockhash } = await connection.getLatestBlockhash("confirmed");
96
- const message = new TransactionMessage({
97
- payerKey: vaultPda,
98
- recentBlockhash: blockhash,
99
- instructions: [depositBuilt.ix]
100
- });
101
- const createVaultTxIx = await multisig.instructions.vaultTransactionCreate({
102
- multisigPda,
103
- transactionIndex,
104
- creator: wallet.publicKey,
105
- vaultIndex,
106
- ephemeralSigners: 0,
107
- transactionMessage: message
108
- });
109
- const tx = new Transaction().add(createVaultTxIx);
110
- return { tx, transactionIndex, vaultPda };
111
- }
112
- async buildSquadsDepositProposalTx2(params) {
113
- const { connection, multisigPda, amountLamports, wallet } = params;
114
- const vaultIndex = params.vaultIndex ?? 0;
115
- if (!wallet?.publicKey) throw new Error("wallet.publicKey missing");
116
- if (!amountLamports || amountLamports <= BigInt(0)) throw new Error("amountLamports must be > 0");
117
- const [vaultPda] = multisig.getVaultPda({ multisigPda, index: vaultIndex });
118
- const depositBuilt = await this.buildDepositIxForUser(amountLamports, vaultPda);
119
- const ms = await multisig.accounts.Multisig.fromAccountAddress(connection, multisigPda);
120
- const current = BigInt(ms.transactionIndex?.toString?.() ?? 0);
121
- const transactionIndex = current + BigInt(1);
122
- const { blockhash } = await connection.getLatestBlockhash("confirmed");
123
- new TransactionMessage({
124
- payerKey: vaultPda,
125
- recentBlockhash: blockhash,
126
- instructions: [depositBuilt.ix]
127
- });
128
- const createProposalIx = await multisig.instructions.proposalCreate({
129
- multisigPda,
130
- transactionIndex,
131
- creator: wallet.publicKey
132
- });
133
- const tx = new Transaction().add(createProposalIx);
134
- return { tx, transactionIndex, vaultPda };
135
- }
136
86
  async buildWithdrawTx(amount, user = this.wallet.publicKey) {
137
87
  if (!user) {
138
88
  throw new Error(
@@ -809,7 +759,8 @@ var instructions$7 = [
809
759
  writable: true
810
760
  },
811
761
  {
812
- name: "user"
762
+ name: "user",
763
+ writable: true
813
764
  },
814
765
  {
815
766
  name: "outpost_account",
@@ -1196,6 +1147,9 @@ var instructions$7 = [
1196
1147
  {
1197
1148
  name: "token_program"
1198
1149
  },
1150
+ {
1151
+ name: "associated_token_program"
1152
+ },
1199
1153
  {
1200
1154
  name: "system_program"
1201
1155
  }
@@ -1851,7 +1805,7 @@ var instructions$7 = [
1851
1805
  ],
1852
1806
  accounts: [
1853
1807
  {
1854
- name: "payer",
1808
+ name: "admin",
1855
1809
  writable: true,
1856
1810
  signer: true
1857
1811
  },
@@ -1859,6 +1813,9 @@ var instructions$7 = [
1859
1813
  name: "metadata",
1860
1814
  writable: true
1861
1815
  },
1816
+ {
1817
+ name: "global_config"
1818
+ },
1862
1819
  {
1863
1820
  name: "system_program"
1864
1821
  }
@@ -2308,6 +2265,7 @@ var instructions$7 = [
2308
2265
  accounts: [
2309
2266
  {
2310
2267
  name: "admin",
2268
+ writable: true,
2311
2269
  signer: true
2312
2270
  },
2313
2271
  {
@@ -2546,7 +2504,7 @@ var instructions$7 = [
2546
2504
  writable: true
2547
2505
  },
2548
2506
  {
2549
- name: "user_pretoken_record",
2507
+ name: "pool_pretoken_record",
2550
2508
  writable: true
2551
2509
  },
2552
2510
  {
@@ -5145,6 +5103,10 @@ var types$9 = [
5145
5103
  type: {
5146
5104
  kind: "struct",
5147
5105
  fields: [
5106
+ {
5107
+ name: "receipt_id",
5108
+ type: "u64"
5109
+ },
5148
5110
  {
5149
5111
  name: "liqports",
5150
5112
  type: "u64"
@@ -8008,7 +7970,8 @@ var instructions$3 = [
8008
7970
  writable: true
8009
7971
  },
8010
7972
  {
8011
- name: "user"
7973
+ name: "user",
7974
+ writable: true
8012
7975
  },
8013
7976
  {
8014
7977
  name: "outpost_account",
@@ -8395,6 +8358,9 @@ var instructions$3 = [
8395
8358
  {
8396
8359
  name: "token_program"
8397
8360
  },
8361
+ {
8362
+ name: "associated_token_program"
8363
+ },
8398
8364
  {
8399
8365
  name: "system_program"
8400
8366
  }
@@ -9050,7 +9016,7 @@ var instructions$3 = [
9050
9016
  ],
9051
9017
  accounts: [
9052
9018
  {
9053
- name: "payer",
9019
+ name: "admin",
9054
9020
  writable: true,
9055
9021
  signer: true
9056
9022
  },
@@ -9058,6 +9024,9 @@ var instructions$3 = [
9058
9024
  name: "metadata",
9059
9025
  writable: true
9060
9026
  },
9027
+ {
9028
+ name: "global_config"
9029
+ },
9061
9030
  {
9062
9031
  name: "system_program"
9063
9032
  }
@@ -9507,6 +9476,7 @@ var instructions$3 = [
9507
9476
  accounts: [
9508
9477
  {
9509
9478
  name: "admin",
9479
+ writable: true,
9510
9480
  signer: true
9511
9481
  },
9512
9482
  {
@@ -9745,7 +9715,7 @@ var instructions$3 = [
9745
9715
  writable: true
9746
9716
  },
9747
9717
  {
9748
- name: "user_pretoken_record",
9718
+ name: "pool_pretoken_record",
9749
9719
  writable: true
9750
9720
  },
9751
9721
  {
@@ -12344,6 +12314,10 @@ var types$5 = [
12344
12314
  type: {
12345
12315
  kind: "struct",
12346
12316
  fields: [
12317
+ {
12318
+ name: "receipt_id",
12319
+ type: "u64"
12320
+ },
12347
12321
  {
12348
12322
  name: "liqports",
12349
12323
  type: "u64"
@@ -15242,9 +15216,6 @@ class OutpostClient {
15242
15216
  get wallet() {
15243
15217
  return this.provider.wallet;
15244
15218
  }
15245
- get liqsolCoreProgram() {
15246
- return this.program;
15247
- }
15248
15219
  async buildAccounts(user) {
15249
15220
  const userPk = user ?? this.wallet.publicKey;
15250
15221
  if (!userPk) {
@@ -15350,7 +15321,8 @@ class OutpostClient {
15350
15321
  liqsolPoolAta: a.liqsolPoolAta,
15351
15322
  outpostAccount: a.outpostAccount,
15352
15323
  tokenProgram: TOKEN_2022_PROGRAM_ID,
15353
- systemProgram: SystemProgram.programId
15324
+ systemProgram: SystemProgram.programId,
15325
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID
15354
15326
  }).instruction();
15355
15327
  }
15356
15328
  previewPretokens(params) {
@@ -15906,7 +15878,8 @@ const _SolanaStakingClient = class _SolanaStakingClient {
15906
15878
  const signed = await this.signTransaction(prepared.tx);
15907
15879
  return this.sendAndConfirmHttp(signed, prepared);
15908
15880
  } catch (err) {
15909
- throw new Error(`Failed to deposit Solana: ${err}`);
15881
+ console.log(`Failed to deposit Solana: ${err}`);
15882
+ throw err;
15910
15883
  }
15911
15884
  }
15912
15885
  async withdraw(amountLamports) {
@@ -15922,7 +15895,8 @@ const _SolanaStakingClient = class _SolanaStakingClient {
15922
15895
  const signed = await this.signTransaction(prepared.tx);
15923
15896
  return this.sendAndConfirmHttp(signed, prepared);
15924
15897
  } catch (err) {
15925
- throw new Error(`Failed to withdraw Solana: ${err}`);
15898
+ console.log(`Failed to withdraw Solana: ${err}`);
15899
+ throw err;
15926
15900
  }
15927
15901
  }
15928
15902
  async stake(amountLamports) {
@@ -15939,7 +15913,8 @@ const _SolanaStakingClient = class _SolanaStakingClient {
15939
15913
  const signed = await this.signTransaction(prepared.tx);
15940
15914
  return this.sendAndConfirmHttp(signed, prepared);
15941
15915
  } catch (err) {
15942
- throw new Error(`Failed to stake Solana: ${err}`);
15916
+ console.log(`Failed to stake Solana: ${err}`);
15917
+ throw err;
15943
15918
  }
15944
15919
  }
15945
15920
  async unstake(amountLamports) {
@@ -15956,7 +15931,8 @@ const _SolanaStakingClient = class _SolanaStakingClient {
15956
15931
  const signed = await this.signTransaction(prepared.tx);
15957
15932
  return this.sendAndConfirmHttp(signed, prepared);
15958
15933
  } catch (err) {
15959
- throw new Error(`Failed to unstake Solana: ${err}`);
15934
+ console.log(`Failed to unstake Solana: ${err}`);
15935
+ throw err;
15960
15936
  }
15961
15937
  }
15962
15938
  async buy(amountLamports) {
@@ -15973,7 +15949,8 @@ const _SolanaStakingClient = class _SolanaStakingClient {
15973
15949
  const signed = await this.signTransaction(prepared.tx);
15974
15950
  return this.sendAndConfirmHttp(signed, prepared);
15975
15951
  } catch (err) {
15976
- throw new Error(`Failed to buy liqSOL pretokens: ${err}`);
15952
+ console.log(`Failed to buy liqSOL pretokens: ${err}`);
15953
+ throw err;
15977
15954
  }
15978
15955
  }
15979
15956
  async getPortfolio() {
@@ -16060,7 +16037,8 @@ const _SolanaStakingClient = class _SolanaStakingClient {
16060
16037
  chainID: this.network.chainId
16061
16038
  };
16062
16039
  } catch (err) {
16063
- throw new Error(`Failed to get Solana portfolio: ${err}`);
16040
+ console.log(`Failed to get Solana portfolio: ${err}`);
16041
+ throw err;
16064
16042
  }
16065
16043
  }
16066
16044
  async getUserRecord() {
@@ -16093,7 +16071,8 @@ const _SolanaStakingClient = class _SolanaStakingClient {
16093
16071
  nativePriceTimestamp: timestamp
16094
16072
  });
16095
16073
  } catch (err) {
16096
- throw new Error(`Failed to build Solana tranche snapshot: ${err}`);
16074
+ console.log(`Failed to build Solana tranche snapshot: ${err}`);
16075
+ throw err;
16097
16076
  }
16098
16077
  }
16099
16078
  async getSystemAPY() {
@@ -16104,7 +16083,8 @@ const _SolanaStakingClient = class _SolanaStakingClient {
16104
16083
  const apyPercent = apyDecimal * 100;
16105
16084
  return apyPercent;
16106
16085
  } catch (err) {
16107
- throw new Error(`Failed to compute Solana system APY: ${err}`);
16086
+ console.log(`Failed to compute Solana system APY: ${err}`);
16087
+ throw err;
16108
16088
  }
16109
16089
  }
16110
16090
  async getEpochRateDecimalFromProgram() {
@@ -16255,30 +16235,63 @@ const _SolanaStakingClient = class _SolanaStakingClient {
16255
16235
  };
16256
16236
  return singleTxFeeLamports;
16257
16237
  }
16258
- async sendAndConfirmHttp(signed, ctx) {
16238
+ async sendAndConfirmHttp(signed, _ctx) {
16259
16239
  this.ensureUser();
16260
- const signature = await this.connection.sendRawTransaction(
16261
- signed.serialize(),
16262
- {
16240
+ const rawTx = signed.serialize();
16241
+ let signature;
16242
+ try {
16243
+ signature = await this.connection.sendRawTransaction(rawTx, {
16263
16244
  skipPreflight: false,
16264
16245
  preflightCommitment: commitment,
16265
16246
  maxRetries: 3
16247
+ });
16248
+ } catch (e) {
16249
+ const msg = e?.message ?? "";
16250
+ const isSendTxError = e instanceof SendTransactionError || e?.name === "SendTransactionError";
16251
+ if (isSendTxError && msg.includes("already been processed")) {
16252
+ console.warn(
16253
+ 'sendRawTransaction preflight says "already been processed"; treating as success and deriving signature from signed tx.'
16254
+ );
16255
+ const legacy = signed;
16256
+ const first = legacy.signatures?.[0]?.signature;
16257
+ if (!first) {
16258
+ throw e;
16259
+ }
16260
+ signature = bs58.encode(first);
16261
+ } else {
16262
+ throw e;
16266
16263
  }
16267
- );
16268
- const conf = await this.connection.confirmTransaction(
16269
- {
16270
- signature,
16271
- blockhash: ctx.blockhash,
16272
- lastValidBlockHeight: ctx.lastValidBlockHeight
16273
- },
16274
- commitment
16275
- );
16276
- if (conf.value.err) {
16277
- throw new Error(
16278
- `Transaction failed: ${JSON.stringify(conf.value.err)}`
16264
+ }
16265
+ const start = Date.now();
16266
+ const timeoutMs = 3e4;
16267
+ const pollIntervalMs = 500;
16268
+ while (true) {
16269
+ const { value } = await this.connection.getSignatureStatuses(
16270
+ [signature],
16271
+ { searchTransactionHistory: true }
16279
16272
  );
16273
+ const status = value[0];
16274
+ if (status) {
16275
+ if (status.err) {
16276
+ throw new Error(
16277
+ `Transaction failed: ${JSON.stringify(status.err)}`
16278
+ );
16279
+ }
16280
+ const confirmations = status.confirmations;
16281
+ const confirmationStatus = status.confirmationStatus;
16282
+ const satisfied = confirmationStatus === "confirmed" || confirmationStatus === "finalized" || confirmations === null ||
16283
+ (confirmations ?? 0) > 0;
16284
+ if (satisfied) {
16285
+ return signature;
16286
+ }
16287
+ }
16288
+ if (Date.now() - start > timeoutMs) {
16289
+ throw new Error(
16290
+ `Transaction confirmation timed out for ${signature}`
16291
+ );
16292
+ }
16293
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
16280
16294
  }
16281
- return signature;
16282
16295
  }
16283
16296
  async signTransaction(tx) {
16284
16297
  this.ensureUser();
@@ -41662,7 +41675,6 @@ class EthereumStakingClient {
41662
41675
  };
41663
41676
  }
41664
41677
  async getTrancheSnapshot(chainID) {
41665
- console.log("getTrancheSnapshot", chainID);
41666
41678
  try {
41667
41679
  const blockNumber = await this.provider.getBlockNumber();
41668
41680
  const blockTag = { blockTag: blockNumber };