@wireio/stake 2.1.1 → 2.2.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/lib/stake.browser.js +147 -227
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +39 -51
- package/lib/stake.js +161 -243
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +147 -227
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/solana/clients/deposit.client.ts +2 -229
- package/src/networks/solana/clients/outpost.client.ts +4 -5
- package/src/networks/solana/clients/token.client.ts +2 -0
- package/src/networks/solana/constants.ts +3 -0
- package/src/networks/solana/solana.ts +265 -317
- package/src/networks/solana/utils.ts +1 -1
package/lib/stake.d.ts
CHANGED
|
@@ -1323,6 +1323,7 @@ type SolanaProgramIds = {
|
|
|
1323
1323
|
LIQSOL_TOKEN: PublicKey$1;
|
|
1324
1324
|
VALIDATOR_LEADERBOARD: PublicKey$1;
|
|
1325
1325
|
TRANSFER_HOOK: PublicKey$1;
|
|
1326
|
+
ALT_LOOKUP_TABLE: PublicKey$1;
|
|
1326
1327
|
};
|
|
1327
1328
|
declare const PROGRAM_IDS_BY_CHAIN: Record<SupportedSolChainID, SolanaProgramIds>;
|
|
1328
1329
|
declare const getProgramIds: (chainId: SolChainID) => SolanaProgramIds;
|
|
@@ -15395,13 +15396,7 @@ declare class DepositClient {
|
|
|
15395
15396
|
* - increments totalEncumberedFunds in global state
|
|
15396
15397
|
* - mints an NFT receipt (liqReceiptData + NFT ATA for owner)
|
|
15397
15398
|
*/
|
|
15398
|
-
buildWithdrawTx(amount: bigint, user?: PublicKey$1): Promise<
|
|
15399
|
-
/**
|
|
15400
|
-
* Internal helper: build the liqsol_core::deposit instruction for a specific `user`.
|
|
15401
|
-
* This is the exact same account wiring as buildDepositTx(), but returns the IX
|
|
15402
|
-
* plus useful this.pgs.derived addresses/seed for Squads flows.
|
|
15403
|
-
*/
|
|
15404
|
-
private buildDepositIxForUser;
|
|
15399
|
+
buildWithdrawTx(amount: bigint, user?: PublicKey$1): Promise<TransactionInstruction>;
|
|
15405
15400
|
}
|
|
15406
15401
|
|
|
15407
15402
|
/**
|
|
@@ -15765,15 +15760,6 @@ declare class SolanaStakingClient implements IStakingClient {
|
|
|
15765
15760
|
get feePayer(): PublicKey$1;
|
|
15766
15761
|
get squadsX(): SquadsXConfig | null;
|
|
15767
15762
|
constructor(config: StakerConfig);
|
|
15768
|
-
createVaultLiqsolAtaOneShot(params: {
|
|
15769
|
-
connection: Connection;
|
|
15770
|
-
payer: PublicKey$1;
|
|
15771
|
-
vaultPda: PublicKey$1;
|
|
15772
|
-
}): Promise<{
|
|
15773
|
-
tx: Transaction;
|
|
15774
|
-
vaultAta: PublicKey$1;
|
|
15775
|
-
} | null>;
|
|
15776
|
-
private prepSquadsIxs;
|
|
15777
15763
|
/**
|
|
15778
15764
|
* Deposit native SOL into liqSOL (liqsol_core::deposit).
|
|
15779
15765
|
* Handles tx build, sign, send, and confirmation.
|
|
@@ -15820,8 +15806,43 @@ declare class SolanaStakingClient implements IStakingClient {
|
|
|
15820
15806
|
* Used by balance-correction flows and debugging.
|
|
15821
15807
|
*/
|
|
15822
15808
|
getUserRecord(): Promise<DistributionUserRecord | null>;
|
|
15823
|
-
get squadsMultisigPDA(): PublicKey$1 |
|
|
15824
|
-
get squadsVaultPDA(): PublicKey$1 |
|
|
15809
|
+
get squadsMultisigPDA(): PublicKey$1 | undefined;
|
|
15810
|
+
get squadsVaultPDA(): PublicKey$1 | undefined;
|
|
15811
|
+
private sendSquadsIxs;
|
|
15812
|
+
buildAndSendIx(ix: TransactionInstruction | TransactionInstruction[]): Promise<string>;
|
|
15813
|
+
/**
|
|
15814
|
+
* Send a signed transaction over HTTP RPC.
|
|
15815
|
+
*
|
|
15816
|
+
* - Returns immediately on successful sendRawTransaction.
|
|
15817
|
+
* - If sendRawTransaction throws a SendTransactionError with
|
|
15818
|
+
* "already been processed", we treat it as success and
|
|
15819
|
+
* just return a derived signature.
|
|
15820
|
+
* - No confirmTransaction / polling / blockheight handling.
|
|
15821
|
+
*/
|
|
15822
|
+
private sendAndConfirmHttp;
|
|
15823
|
+
/**
|
|
15824
|
+
* Sign a single Solana transaction using the connected wallet adapter.
|
|
15825
|
+
*/
|
|
15826
|
+
signTransaction(tx: SolanaTransaction): Promise<SolanaTransaction>;
|
|
15827
|
+
/**
|
|
15828
|
+
* Generic "fire and forget" send helper if the caller already
|
|
15829
|
+
* prepared and signed the transaction.
|
|
15830
|
+
*/
|
|
15831
|
+
sendTransaction(signed: SolanaTransaction): Promise<TransactionSignature>;
|
|
15832
|
+
/**
|
|
15833
|
+
* Attach recent blockhash + fee payer to a transaction.
|
|
15834
|
+
* Required before signing and sending.
|
|
15835
|
+
*/
|
|
15836
|
+
prepareTx(tx: Transaction): Promise<{
|
|
15837
|
+
tx: Transaction;
|
|
15838
|
+
blockhash: string;
|
|
15839
|
+
lastValidBlockHeight: number;
|
|
15840
|
+
}>;
|
|
15841
|
+
/**
|
|
15842
|
+
* Guard for all write operations (deposit/withdraw/stake/unstake/buy).
|
|
15843
|
+
* Ensures we have a Wire pubKey and an Anchor wallet pubKey, and that they match.
|
|
15844
|
+
*/
|
|
15845
|
+
ensureUser(): void;
|
|
15825
15846
|
/**
|
|
15826
15847
|
* Unified, chain-agnostic tranche snapshot for Solana.
|
|
15827
15848
|
*
|
|
@@ -15888,39 +15909,6 @@ declare class SolanaStakingClient implements IStakingClient {
|
|
|
15888
15909
|
private cachedTxFee?;
|
|
15889
15910
|
private static readonly FEE_CACHE_TTL_MS;
|
|
15890
15911
|
private getSingleTxFeeLamports;
|
|
15891
|
-
/**
|
|
15892
|
-
* Send a signed transaction over HTTP RPC.
|
|
15893
|
-
*
|
|
15894
|
-
* - Returns immediately on successful sendRawTransaction.
|
|
15895
|
-
* - If sendRawTransaction throws a SendTransactionError with
|
|
15896
|
-
* "already been processed", we treat it as success and
|
|
15897
|
-
* just return a derived signature.
|
|
15898
|
-
* - No confirmTransaction / polling / blockheight handling.
|
|
15899
|
-
*/
|
|
15900
|
-
private sendAndConfirmHttp;
|
|
15901
|
-
/**
|
|
15902
|
-
* Sign a single Solana transaction using the connected wallet adapter.
|
|
15903
|
-
*/
|
|
15904
|
-
signTransaction(tx: SolanaTransaction): Promise<SolanaTransaction>;
|
|
15905
|
-
/**
|
|
15906
|
-
* Generic "fire and forget" send helper if the caller already
|
|
15907
|
-
* prepared and signed the transaction.
|
|
15908
|
-
*/
|
|
15909
|
-
sendTransaction(signed: SolanaTransaction): Promise<TransactionSignature>;
|
|
15910
|
-
/**
|
|
15911
|
-
* Attach recent blockhash + fee payer to a transaction.
|
|
15912
|
-
* Required before signing and sending.
|
|
15913
|
-
*/
|
|
15914
|
-
prepareTx(tx: Transaction): Promise<{
|
|
15915
|
-
tx: Transaction;
|
|
15916
|
-
blockhash: string;
|
|
15917
|
-
lastValidBlockHeight: number;
|
|
15918
|
-
}>;
|
|
15919
|
-
/**
|
|
15920
|
-
* Guard for all write operations (deposit/withdraw/stake/unstake/buy).
|
|
15921
|
-
* Ensures we have a Wire pubKey and an Anchor wallet pubKey, and that they match.
|
|
15922
|
-
*/
|
|
15923
|
-
ensureUser(): void;
|
|
15924
15912
|
}
|
|
15925
15913
|
|
|
15926
15914
|
export { ADDRESSES, ADDRESS_BOOK_BY_CHAIN, CHAINLINK_FEED, CHAINLINK_PROGRAM, CONTRACTS_BY_CHAIN, DEFAULT_AVERAGE_PAY_RATE, DEFAULT_PAY_RATE_LOOKBACK, DepositClient, DistributionClient, EPHEMERAL_RENT_EXEMPTION, ERC1155Abi, ERC20Abi, ERC721Abi, types$1 as ETH, EthereumContractService, EthereumStakingClient, HOODI_ADDRESSES, INDEX_SCALE, INITIAL_TRANCHE_SUPPLY, LAMPORTS_PER_SOL, LeaderboardClient, MAINNET_ADDRESSES, OutpostClient, PAY_RATE_SCALE_FACTOR, PDA_SEEDS, PROGRAM_IDS_BY_CHAIN, PurchaseAsset, ReceiptNFTKind, SCALE, types as SOL, SolanaStakingClient, Staker, SupportedEvmChainID, SupportedSolChainID, TokenClient, airdropSol, buildOutpostAccounts, buildSolanaTrancheLadder, buildSolanaTrancheSnapshot, ceilDiv, deriveEphemeralStakeAddress, generateRandomDepositAmount, generateTestKeypair, getEpochSnapshot, getErrorMessage, getProgramIds, lamportsToSol, msToEpochEnd, scheduledInstruction, sleep, solToLamports, toBigint, tokensToShares, waitForConfirmation, waitUntilSafeToExecuteFunction };
|
package/lib/stake.js
CHANGED
|
@@ -186,7 +186,7 @@ class DepositClient {
|
|
|
186
186
|
true,
|
|
187
187
|
splToken.TOKEN_2022_PROGRAM_ID
|
|
188
188
|
);
|
|
189
|
-
|
|
189
|
+
return yield this.program.methods.requestWithdraw(new anchor.BN(amount.toString())).accounts({
|
|
190
190
|
user,
|
|
191
191
|
owner,
|
|
192
192
|
global,
|
|
@@ -212,71 +212,6 @@ class DepositClient {
|
|
|
212
212
|
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
213
213
|
globalConfig
|
|
214
214
|
}).instruction();
|
|
215
|
-
return new web3_js.Transaction().add(ix);
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
buildDepositIxForUser(amount, user) {
|
|
219
|
-
return __async$g(this, null, function* () {
|
|
220
|
-
if (!user) {
|
|
221
|
-
throw new Error("buildDepositIxForUser: user is required");
|
|
222
|
-
}
|
|
223
|
-
if (!amount || amount <= BigInt(0)) {
|
|
224
|
-
throw new Error("buildDepositIxForUser: amount must be > 0");
|
|
225
|
-
}
|
|
226
|
-
const depositAuthority = this.pgs.deriveDepositAuthorityPda();
|
|
227
|
-
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
228
|
-
const liqsolMintAuthority = this.pgs.deriveLiqsolMintAuthorityPda();
|
|
229
|
-
const reservePool = this.pgs.deriveReservePoolPda();
|
|
230
|
-
const vault = this.pgs.deriveVaultPda();
|
|
231
|
-
const controllerState = this.pgs.deriveStakeControllerStatePda();
|
|
232
|
-
const payoutState = this.pgs.derivePayoutStatePda();
|
|
233
|
-
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
234
|
-
const payRateHistory = this.pgs.derivePayRateHistoryPda();
|
|
235
|
-
const globalConfig = this.pgs.deriveGlobalConfigPda();
|
|
236
|
-
const userAta = splToken.getAssociatedTokenAddressSync(
|
|
237
|
-
liqsolMint,
|
|
238
|
-
user,
|
|
239
|
-
true,
|
|
240
|
-
splToken.TOKEN_2022_PROGRAM_ID
|
|
241
|
-
);
|
|
242
|
-
const distributionState = this.pgs.deriveDistributionStatePda();
|
|
243
|
-
const userRecord = this.pgs.deriveUserRecordPda(userAta);
|
|
244
|
-
const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
245
|
-
liqsolMint,
|
|
246
|
-
bucketAuthority,
|
|
247
|
-
true,
|
|
248
|
-
splToken.TOKEN_2022_PROGRAM_ID
|
|
249
|
-
);
|
|
250
|
-
const seed = Math.floor(Math.random() * __pow(2, 32));
|
|
251
|
-
const ephemeralStake = yield this.pgs.deriveEphemeralStakeAddress(user, seed);
|
|
252
|
-
const ix = yield this.program.methods.deposit(new anchor.BN(amount.toString()), seed).accounts({
|
|
253
|
-
user,
|
|
254
|
-
depositAuthority,
|
|
255
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
256
|
-
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
|
|
257
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
258
|
-
liqsolProgram: this.pgs.PROGRAM_IDS.LIQSOL_TOKEN,
|
|
259
|
-
stakeProgram: web3_js.StakeProgram.programId,
|
|
260
|
-
liqsolMint,
|
|
261
|
-
userAta,
|
|
262
|
-
liqsolMintAuthority,
|
|
263
|
-
reservePool,
|
|
264
|
-
vault,
|
|
265
|
-
ephemeralStake,
|
|
266
|
-
controllerState,
|
|
267
|
-
payoutState,
|
|
268
|
-
bucketAuthority,
|
|
269
|
-
bucketTokenAccount,
|
|
270
|
-
userRecord,
|
|
271
|
-
distributionState,
|
|
272
|
-
payRateHistory,
|
|
273
|
-
instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
274
|
-
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
275
|
-
stakeHistory: web3_js.SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
276
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
277
|
-
globalConfig
|
|
278
|
-
}).instruction();
|
|
279
|
-
return { ix, seed, userAta, ephemeralStake };
|
|
280
215
|
});
|
|
281
216
|
}
|
|
282
217
|
}
|
|
@@ -14727,13 +14662,15 @@ const MAINNET_PROGRAM_IDS = {
|
|
|
14727
14662
|
LIQSOL_CORE: new web3_js.PublicKey(liqsolCoreMainnetJson.address),
|
|
14728
14663
|
LIQSOL_TOKEN: new web3_js.PublicKey(liqsolTokenMainnetJson.address),
|
|
14729
14664
|
VALIDATOR_LEADERBOARD: new web3_js.PublicKey(validatorLeaderboardMainnetJson.address),
|
|
14730
|
-
TRANSFER_HOOK: new web3_js.PublicKey(mainnetTransferHookIDL.address)
|
|
14665
|
+
TRANSFER_HOOK: new web3_js.PublicKey(mainnetTransferHookIDL.address),
|
|
14666
|
+
ALT_LOOKUP_TABLE: new web3_js.PublicKey("AQXTHwkdNBEiXeQuVA5uCoxvzgYUmudRxthQY4vWKCPS")
|
|
14731
14667
|
};
|
|
14732
14668
|
const DEVNET_PROGRAM_IDS = {
|
|
14733
14669
|
LIQSOL_CORE: new web3_js.PublicKey(liqsolCoreDevnetJson.address),
|
|
14734
14670
|
LIQSOL_TOKEN: new web3_js.PublicKey(liqsolTokenDevnetJson.address),
|
|
14735
14671
|
VALIDATOR_LEADERBOARD: new web3_js.PublicKey(validatorLeaderboardDevnetJson.address),
|
|
14736
|
-
TRANSFER_HOOK: new web3_js.PublicKey(devnetTransferHookIDL.address)
|
|
14672
|
+
TRANSFER_HOOK: new web3_js.PublicKey(devnetTransferHookIDL.address),
|
|
14673
|
+
ALT_LOOKUP_TABLE: new web3_js.PublicKey("3MbupRDxUqPtJzoLLmjEYV3dXJdh1jojQrpDEQUqv7xb")
|
|
14737
14674
|
};
|
|
14738
14675
|
const PROGRAM_IDS_BY_CHAIN = {
|
|
14739
14676
|
[core.SolChainID.Mainnet]: MAINNET_PROGRAM_IDS,
|
|
@@ -14976,7 +14913,7 @@ function buildOutpostAccounts(connection, user, pgs) {
|
|
|
14976
14913
|
const userAta = yield splToken.getAssociatedTokenAddress(
|
|
14977
14914
|
liqsolMint,
|
|
14978
14915
|
user,
|
|
14979
|
-
|
|
14916
|
+
true,
|
|
14980
14917
|
splToken.TOKEN_2022_PROGRAM_ID
|
|
14981
14918
|
);
|
|
14982
14919
|
const bucketUserRecord = pgs.deriveUserRecordPda(bucketTokenAccount);
|
|
@@ -15459,15 +15396,14 @@ class OutpostClient {
|
|
|
15459
15396
|
}
|
|
15460
15397
|
});
|
|
15461
15398
|
}
|
|
15462
|
-
buildStakeIx(
|
|
15463
|
-
return __async$b(this,
|
|
15464
|
-
|
|
15465
|
-
if (!userPk) {
|
|
15399
|
+
buildStakeIx(_0) {
|
|
15400
|
+
return __async$b(this, arguments, function* (amountLamports, user = this.wallet.publicKey) {
|
|
15401
|
+
if (!user) {
|
|
15466
15402
|
throw new Error("OutpostClient.buildStakeIx: wallet not connected");
|
|
15467
15403
|
}
|
|
15468
|
-
const a = yield this.buildAccounts(
|
|
15404
|
+
const a = yield this.buildAccounts(user);
|
|
15469
15405
|
return this.program.methods.synd(new anchor.BN(amountLamports.toString())).accounts({
|
|
15470
|
-
user
|
|
15406
|
+
user,
|
|
15471
15407
|
liqsolMint: a.liqsolMint,
|
|
15472
15408
|
globalState: a.globalState,
|
|
15473
15409
|
distributionState: a.distributionState,
|
|
@@ -15619,6 +15555,7 @@ class TokenClient {
|
|
|
15619
15555
|
buildPurchaseIx(_0) {
|
|
15620
15556
|
return __async$a(this, arguments, function* (amountLamports, user = this.wallet.publicKey) {
|
|
15621
15557
|
var _a, _b;
|
|
15558
|
+
console.log("build purchase for", user.toBase58());
|
|
15622
15559
|
const a = yield this.getAccounts(user);
|
|
15623
15560
|
const extraAccountMetaList = this.pgs.deriveExtraAccountMetaListPda(a.liqsolMint);
|
|
15624
15561
|
const liqsolCoreProgram = this.pgs.PROGRAM_IDS.LIQSOL_CORE;
|
|
@@ -16113,77 +16050,14 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16113
16050
|
const config = (_a = this.config.extras) == null ? void 0 : _a.squadsX;
|
|
16114
16051
|
return config != null ? config : null;
|
|
16115
16052
|
}
|
|
16116
|
-
createVaultLiqsolAtaOneShot(params) {
|
|
16117
|
-
return __async$8(this, null, function* () {
|
|
16118
|
-
const { connection, payer, vaultPda } = params;
|
|
16119
|
-
const liqsolMint = this.program.deriveLiqsolMintPda();
|
|
16120
|
-
const vaultAta = splToken.getAssociatedTokenAddressSync(
|
|
16121
|
-
liqsolMint,
|
|
16122
|
-
vaultPda,
|
|
16123
|
-
true,
|
|
16124
|
-
splToken.TOKEN_2022_PROGRAM_ID,
|
|
16125
|
-
splToken.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
16126
|
-
);
|
|
16127
|
-
const info = yield connection.getAccountInfo(vaultAta, "confirmed");
|
|
16128
|
-
if (info) return null;
|
|
16129
|
-
const ix = splToken.createAssociatedTokenAccountInstruction(
|
|
16130
|
-
payer,
|
|
16131
|
-
vaultAta,
|
|
16132
|
-
vaultPda,
|
|
16133
|
-
liqsolMint,
|
|
16134
|
-
splToken.TOKEN_2022_PROGRAM_ID,
|
|
16135
|
-
splToken.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
16136
|
-
);
|
|
16137
|
-
const tx = new web3_js.Transaction().add(ix);
|
|
16138
|
-
return { tx, vaultAta };
|
|
16139
|
-
});
|
|
16140
|
-
}
|
|
16141
|
-
prepSquadsIxs(ix) {
|
|
16142
|
-
return __async$8(this, null, function* () {
|
|
16143
|
-
var _a, _b, _c, _d;
|
|
16144
|
-
if (!this.squadsX) throw new Error("Attempting to wrap Squads instruction without SquadsX config");
|
|
16145
|
-
const multisigPda = this.squadsMultisigPDA;
|
|
16146
|
-
const vaultPda = this.squadsVaultPDA;
|
|
16147
|
-
const vaultIndex = (_b = (_a = this.squadsX) == null ? void 0 : _a.vaultIndex) != null ? _b : 0;
|
|
16148
|
-
const creator = this.solPubKey;
|
|
16149
|
-
const ms = yield multisig__namespace.accounts.Multisig.fromAccountAddress(this.connection, multisigPda);
|
|
16150
|
-
const current = BigInt((_d = (_c = ms.transactionIndex) == null ? void 0 : _c.toString()) != null ? _d : 0);
|
|
16151
|
-
const transactionIndex = current + BigInt(1);
|
|
16152
|
-
const { blockhash } = yield this.connection.getLatestBlockhash("confirmed");
|
|
16153
|
-
const transactionMessage = new web3_js.TransactionMessage({
|
|
16154
|
-
payerKey: vaultPda,
|
|
16155
|
-
recentBlockhash: blockhash,
|
|
16156
|
-
instructions: [ix]
|
|
16157
|
-
});
|
|
16158
|
-
const createVaultTxIx = yield multisig__namespace.instructions.vaultTransactionCreate({
|
|
16159
|
-
multisigPda,
|
|
16160
|
-
transactionIndex,
|
|
16161
|
-
creator,
|
|
16162
|
-
vaultIndex,
|
|
16163
|
-
transactionMessage,
|
|
16164
|
-
ephemeralSigners: 0
|
|
16165
|
-
});
|
|
16166
|
-
const createProposalIx = yield multisig__namespace.instructions.proposalCreate({
|
|
16167
|
-
multisigPda,
|
|
16168
|
-
transactionIndex,
|
|
16169
|
-
creator
|
|
16170
|
-
});
|
|
16171
|
-
return [createVaultTxIx, createProposalIx];
|
|
16172
|
-
});
|
|
16173
|
-
}
|
|
16174
16053
|
deposit(amountLamports) {
|
|
16175
16054
|
return __async$8(this, null, function* () {
|
|
16176
16055
|
this.ensureUser();
|
|
16177
|
-
if (amountLamports <= BigInt(0))
|
|
16056
|
+
if (amountLamports <= BigInt(0))
|
|
16178
16057
|
throw new Error("Deposit amount must be greater than zero.");
|
|
16179
|
-
}
|
|
16180
16058
|
try {
|
|
16181
|
-
const
|
|
16182
|
-
|
|
16183
|
-
const tx = new web3_js.Transaction().add(ix);
|
|
16184
|
-
const prepared = yield this.prepareTx(tx);
|
|
16185
|
-
const signed = yield this.signTransaction(prepared.tx);
|
|
16186
|
-
return this.sendAndConfirmHttp(signed, prepared);
|
|
16059
|
+
const ix = yield this.depositClient.buildDepositTx(amountLamports, this.squadsVaultPDA);
|
|
16060
|
+
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16187
16061
|
} catch (err) {
|
|
16188
16062
|
console.log(`Failed to deposit Solana: ${err}`);
|
|
16189
16063
|
throw err;
|
|
@@ -16193,16 +16067,11 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16193
16067
|
withdraw(amountLamports) {
|
|
16194
16068
|
return __async$8(this, null, function* () {
|
|
16195
16069
|
this.ensureUser();
|
|
16196
|
-
if (amountLamports <= BigInt(0))
|
|
16070
|
+
if (amountLamports <= BigInt(0))
|
|
16197
16071
|
throw new Error("Withdraw amount must be greater than zero.");
|
|
16198
|
-
}
|
|
16199
16072
|
try {
|
|
16200
|
-
const
|
|
16201
|
-
|
|
16202
|
-
const tx = new web3_js.Transaction().add(cuIx, ix);
|
|
16203
|
-
const prepared = yield this.prepareTx(tx);
|
|
16204
|
-
const signed = yield this.signTransaction(prepared.tx);
|
|
16205
|
-
return this.sendAndConfirmHttp(signed, prepared);
|
|
16073
|
+
const ix = yield this.depositClient.buildWithdrawTx(amountLamports, this.squadsVaultPDA);
|
|
16074
|
+
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16206
16075
|
} catch (err) {
|
|
16207
16076
|
console.log(`Failed to withdraw Solana: ${err}`);
|
|
16208
16077
|
throw err;
|
|
@@ -16212,17 +16081,11 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16212
16081
|
stake(amountLamports) {
|
|
16213
16082
|
return __async$8(this, null, function* () {
|
|
16214
16083
|
this.ensureUser();
|
|
16215
|
-
if (!amountLamports || amountLamports <= BigInt(0))
|
|
16084
|
+
if (!amountLamports || amountLamports <= BigInt(0))
|
|
16216
16085
|
throw new Error("Stake amount must be greater than zero.");
|
|
16217
|
-
}
|
|
16218
16086
|
try {
|
|
16219
|
-
const
|
|
16220
|
-
|
|
16221
|
-
const ix = yield this.outpostClient.buildStakeIx(amountLamports, user);
|
|
16222
|
-
const tx = new web3_js.Transaction().add(cuIx, ix);
|
|
16223
|
-
const prepared = yield this.prepareTx(tx);
|
|
16224
|
-
const signed = yield this.signTransaction(prepared.tx);
|
|
16225
|
-
return this.sendAndConfirmHttp(signed, prepared);
|
|
16087
|
+
const ix = yield this.outpostClient.buildStakeIx(amountLamports, this.squadsVaultPDA);
|
|
16088
|
+
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16226
16089
|
} catch (err) {
|
|
16227
16090
|
console.log(`Failed to stake Solana: ${err}`);
|
|
16228
16091
|
throw err;
|
|
@@ -16232,17 +16095,11 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16232
16095
|
unstake(amountLamports) {
|
|
16233
16096
|
return __async$8(this, null, function* () {
|
|
16234
16097
|
this.ensureUser();
|
|
16235
|
-
if (!amountLamports || amountLamports <= BigInt(0))
|
|
16098
|
+
if (!amountLamports || amountLamports <= BigInt(0))
|
|
16236
16099
|
throw new Error("Unstake amount must be greater than zero.");
|
|
16237
|
-
}
|
|
16238
16100
|
try {
|
|
16239
|
-
const
|
|
16240
|
-
|
|
16241
|
-
const ix = yield this.outpostClient.buildUnstakeIx(amountLamports, user);
|
|
16242
|
-
const tx = new web3_js.Transaction().add(cuIx, ix);
|
|
16243
|
-
const prepared = yield this.prepareTx(tx);
|
|
16244
|
-
const signed = yield this.signTransaction(prepared.tx);
|
|
16245
|
-
return this.sendAndConfirmHttp(signed, prepared);
|
|
16101
|
+
const ix = yield this.outpostClient.buildUnstakeIx(amountLamports, this.squadsVaultPDA);
|
|
16102
|
+
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16246
16103
|
} catch (err) {
|
|
16247
16104
|
console.log(`Failed to unstake Solana: ${err}`);
|
|
16248
16105
|
throw err;
|
|
@@ -16252,17 +16109,11 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16252
16109
|
buy(amountLamports) {
|
|
16253
16110
|
return __async$8(this, null, function* () {
|
|
16254
16111
|
this.ensureUser();
|
|
16255
|
-
if (!amountLamports || amountLamports <= BigInt(0))
|
|
16112
|
+
if (!amountLamports || amountLamports <= BigInt(0))
|
|
16256
16113
|
throw new Error("liqSOL pretoken purchase requires a positive amount.");
|
|
16257
|
-
}
|
|
16258
16114
|
try {
|
|
16259
|
-
const
|
|
16260
|
-
|
|
16261
|
-
const ix = yield this.tokenClient.buildPurchaseIx(amountLamports, user);
|
|
16262
|
-
const tx = new web3_js.Transaction().add(cuIx, ix);
|
|
16263
|
-
const prepared = yield this.prepareTx(tx);
|
|
16264
|
-
const signed = yield this.signTransaction(prepared.tx);
|
|
16265
|
-
return this.sendAndConfirmHttp(signed, prepared);
|
|
16115
|
+
const ix = yield this.tokenClient.buildPurchaseIx(amountLamports, this.squadsVaultPDA);
|
|
16116
|
+
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16266
16117
|
} catch (err) {
|
|
16267
16118
|
console.log(`Failed to buy liqSOL pretokens: ${err}`);
|
|
16268
16119
|
throw err;
|
|
@@ -16272,7 +16123,6 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16272
16123
|
getPortfolio() {
|
|
16273
16124
|
return __async$8(this, null, function* () {
|
|
16274
16125
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
16275
|
-
if (!this.pubKey) throw new Error("User pubKey is undefined");
|
|
16276
16126
|
try {
|
|
16277
16127
|
const user = !!this.squadsX ? this.squadsVaultPDA : this.solPubKey;
|
|
16278
16128
|
const reservePoolPDA = this.program.deriveReservePoolPda();
|
|
@@ -16367,17 +16217,131 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16367
16217
|
});
|
|
16368
16218
|
}
|
|
16369
16219
|
get squadsMultisigPDA() {
|
|
16370
|
-
if (!this.squadsX) return
|
|
16220
|
+
if (!this.squadsX) return void 0;
|
|
16371
16221
|
return new web3_js.PublicKey(this.squadsX.multisigPDA);
|
|
16372
16222
|
}
|
|
16373
16223
|
get squadsVaultPDA() {
|
|
16374
16224
|
var _a;
|
|
16375
|
-
if (!this.squadsX || !this.squadsMultisigPDA) return
|
|
16225
|
+
if (!this.squadsX || !this.squadsMultisigPDA) return void 0;
|
|
16376
16226
|
const multisigPda = this.squadsMultisigPDA;
|
|
16377
16227
|
const index = (_a = this.squadsX.vaultIndex) != null ? _a : 0;
|
|
16378
16228
|
const pda = multisig__namespace.getVaultPda({ multisigPda, index });
|
|
16379
16229
|
return pda[0];
|
|
16380
16230
|
}
|
|
16231
|
+
sendSquadsIxs(ix) {
|
|
16232
|
+
return __async$8(this, null, function* () {
|
|
16233
|
+
var _a, _b, _c, _d;
|
|
16234
|
+
if (!this.squadsX) throw new Error("Attempting to wrap Squads instruction without SquadsX config");
|
|
16235
|
+
const multisigPda = this.squadsMultisigPDA;
|
|
16236
|
+
const vaultPda = this.squadsVaultPDA;
|
|
16237
|
+
const vaultIndex = (_b = (_a = this.squadsX) == null ? void 0 : _a.vaultIndex) != null ? _b : 0;
|
|
16238
|
+
const creator = this.solPubKey;
|
|
16239
|
+
const ms = yield multisig__namespace.accounts.Multisig.fromAccountAddress(this.connection, multisigPda);
|
|
16240
|
+
const current = BigInt((_d = (_c = ms.transactionIndex) == null ? void 0 : _c.toString()) != null ? _d : 0);
|
|
16241
|
+
const transactionIndex = current + BigInt(1);
|
|
16242
|
+
const altAddress = this.program.PROGRAM_IDS.ALT_LOOKUP_TABLE;
|
|
16243
|
+
const altAccount = yield this.connection.getAddressLookupTable(altAddress);
|
|
16244
|
+
if (!altAccount.value) throw new Error("ALT not found on-chain or not yet active.");
|
|
16245
|
+
const lookupTable = altAccount.value;
|
|
16246
|
+
const computeLimitIx = web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
|
|
16247
|
+
const computePriceIx = web3_js.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 2e3 });
|
|
16248
|
+
const { blockhash } = yield this.connection.getLatestBlockhash("confirmed");
|
|
16249
|
+
const transactionMessage = new web3_js.TransactionMessage({
|
|
16250
|
+
payerKey: vaultPda,
|
|
16251
|
+
recentBlockhash: blockhash,
|
|
16252
|
+
instructions: [computeLimitIx, computePriceIx, ix]
|
|
16253
|
+
});
|
|
16254
|
+
const createVaultTxIx = yield multisig__namespace.instructions.vaultTransactionCreate({
|
|
16255
|
+
multisigPda,
|
|
16256
|
+
transactionIndex,
|
|
16257
|
+
creator,
|
|
16258
|
+
vaultIndex,
|
|
16259
|
+
transactionMessage,
|
|
16260
|
+
ephemeralSigners: 0,
|
|
16261
|
+
addressLookupTableAccounts: [lookupTable]
|
|
16262
|
+
});
|
|
16263
|
+
const vaultTransactionCreate = yield this.buildAndSendIx(createVaultTxIx);
|
|
16264
|
+
console.log("SQUADSX: vaultTransactionCreate", vaultTransactionCreate);
|
|
16265
|
+
const createProposalIx = yield multisig__namespace.instructions.proposalCreate({
|
|
16266
|
+
multisigPda,
|
|
16267
|
+
transactionIndex,
|
|
16268
|
+
creator
|
|
16269
|
+
});
|
|
16270
|
+
const proposalCreate = yield this.buildAndSendIx(createProposalIx);
|
|
16271
|
+
console.log("SQUADSX: proposalCreate", proposalCreate);
|
|
16272
|
+
return proposalCreate;
|
|
16273
|
+
});
|
|
16274
|
+
}
|
|
16275
|
+
buildAndSendIx(ix) {
|
|
16276
|
+
return __async$8(this, null, function* () {
|
|
16277
|
+
const cuIx = web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 4e5 });
|
|
16278
|
+
const ixs = Array.isArray(ix) ? ix : [ix];
|
|
16279
|
+
const tx = new web3_js.Transaction().add(cuIx, ...ixs);
|
|
16280
|
+
const prepared = yield this.prepareTx(tx);
|
|
16281
|
+
const signed = yield this.signTransaction(prepared.tx);
|
|
16282
|
+
return this.sendAndConfirmHttp(signed, prepared);
|
|
16283
|
+
});
|
|
16284
|
+
}
|
|
16285
|
+
sendAndConfirmHttp(signed, _ctx) {
|
|
16286
|
+
return __async$8(this, null, function* () {
|
|
16287
|
+
var _a, _b, _c;
|
|
16288
|
+
this.ensureUser();
|
|
16289
|
+
const rawTx = signed.serialize();
|
|
16290
|
+
try {
|
|
16291
|
+
const signature = yield this.connection.sendRawTransaction(rawTx, {
|
|
16292
|
+
skipPreflight: false,
|
|
16293
|
+
preflightCommitment: commitment,
|
|
16294
|
+
maxRetries: 3
|
|
16295
|
+
});
|
|
16296
|
+
return signature;
|
|
16297
|
+
} catch (e) {
|
|
16298
|
+
const msg = (_a = e == null ? void 0 : e.message) != null ? _a : "";
|
|
16299
|
+
const isSendTxError = e instanceof web3_js.SendTransactionError || (e == null ? void 0 : e.name) === "SendTransactionError";
|
|
16300
|
+
if (isSendTxError && msg.includes("already been processed")) {
|
|
16301
|
+
console.warn(
|
|
16302
|
+
'sendRawTransaction reports "already been processed"; treating as success without further confirmation.'
|
|
16303
|
+
);
|
|
16304
|
+
const legacy = signed;
|
|
16305
|
+
const first = (_c = (_b = legacy.signatures) == null ? void 0 : _b[0]) == null ? void 0 : _c.signature;
|
|
16306
|
+
if (first) {
|
|
16307
|
+
return bs58.encode(first);
|
|
16308
|
+
}
|
|
16309
|
+
return "already-processed";
|
|
16310
|
+
}
|
|
16311
|
+
throw e;
|
|
16312
|
+
}
|
|
16313
|
+
});
|
|
16314
|
+
}
|
|
16315
|
+
signTransaction(tx) {
|
|
16316
|
+
return __async$8(this, null, function* () {
|
|
16317
|
+
this.ensureUser();
|
|
16318
|
+
return this.anchor.wallet.signTransaction(tx);
|
|
16319
|
+
});
|
|
16320
|
+
}
|
|
16321
|
+
sendTransaction(signed) {
|
|
16322
|
+
return __async$8(this, null, function* () {
|
|
16323
|
+
this.ensureUser();
|
|
16324
|
+
return this.anchor.sendAndConfirm(signed);
|
|
16325
|
+
});
|
|
16326
|
+
}
|
|
16327
|
+
prepareTx(tx) {
|
|
16328
|
+
return __async$8(this, null, function* () {
|
|
16329
|
+
const { blockhash, lastValidBlockHeight } = yield this.connection.getLatestBlockhash("confirmed");
|
|
16330
|
+
tx.recentBlockhash = blockhash;
|
|
16331
|
+
tx.feePayer = this.feePayer;
|
|
16332
|
+
return { tx, blockhash, lastValidBlockHeight };
|
|
16333
|
+
});
|
|
16334
|
+
}
|
|
16335
|
+
ensureUser() {
|
|
16336
|
+
var _a;
|
|
16337
|
+
if (!this.pubKey) throw new Error("User pubKey is undefined");
|
|
16338
|
+
const wallet = (_a = this.anchor) == null ? void 0 : _a.wallet;
|
|
16339
|
+
const pk = wallet == null ? void 0 : wallet.publicKey;
|
|
16340
|
+
if (!pk) throw new Error("Wallet not connected");
|
|
16341
|
+
if (typeof wallet.signTransaction !== "function") {
|
|
16342
|
+
throw new Error("Wallet does not support signTransaction");
|
|
16343
|
+
}
|
|
16344
|
+
}
|
|
16381
16345
|
getTrancheSnapshot(chainID) {
|
|
16382
16346
|
return __async$8(this, null, function* () {
|
|
16383
16347
|
try {
|
|
@@ -16424,10 +16388,24 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16424
16388
|
return Number(DEFAULT_AVERAGE_PAY_RATE) / Number(PAY_RATE_SCALE_FACTOR);
|
|
16425
16389
|
}
|
|
16426
16390
|
const currentIndex = Number(payRateHistory.currentIndex);
|
|
16427
|
-
const
|
|
16428
|
-
|
|
16429
|
-
|
|
16430
|
-
|
|
16391
|
+
const processedCount = Math.min(totalEntriesAdded, maxEntries);
|
|
16392
|
+
let sum = BigInt(0);
|
|
16393
|
+
let validCount = 0;
|
|
16394
|
+
let idx = (currentIndex - 1 + maxEntries) % maxEntries;
|
|
16395
|
+
for (let i = 0; i < processedCount; i++) {
|
|
16396
|
+
const entry = payRateHistory.entries[idx];
|
|
16397
|
+
const scaledRate = BigInt(entry.scaledRate.toString());
|
|
16398
|
+
if (scaledRate > BigInt(0)) {
|
|
16399
|
+
sum += scaledRate;
|
|
16400
|
+
validCount++;
|
|
16401
|
+
}
|
|
16402
|
+
idx = (idx - 1 + maxEntries) % maxEntries;
|
|
16403
|
+
}
|
|
16404
|
+
if (validCount === 0) {
|
|
16405
|
+
return Number(DEFAULT_AVERAGE_PAY_RATE) / Number(PAY_RATE_SCALE_FACTOR);
|
|
16406
|
+
}
|
|
16407
|
+
const average = Number(sum / BigInt(validCount));
|
|
16408
|
+
return average / Number(PAY_RATE_SCALE_FACTOR);
|
|
16431
16409
|
});
|
|
16432
16410
|
}
|
|
16433
16411
|
getEpochsPerYearFromCluster() {
|
|
@@ -16574,66 +16552,6 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16574
16552
|
return singleTxFeeLamports;
|
|
16575
16553
|
});
|
|
16576
16554
|
}
|
|
16577
|
-
sendAndConfirmHttp(signed, _ctx) {
|
|
16578
|
-
return __async$8(this, null, function* () {
|
|
16579
|
-
var _a, _b, _c;
|
|
16580
|
-
this.ensureUser();
|
|
16581
|
-
const rawTx = signed.serialize();
|
|
16582
|
-
try {
|
|
16583
|
-
const signature = yield this.connection.sendRawTransaction(rawTx, {
|
|
16584
|
-
skipPreflight: false,
|
|
16585
|
-
preflightCommitment: commitment,
|
|
16586
|
-
maxRetries: 3
|
|
16587
|
-
});
|
|
16588
|
-
return signature;
|
|
16589
|
-
} catch (e) {
|
|
16590
|
-
const msg = (_a = e == null ? void 0 : e.message) != null ? _a : "";
|
|
16591
|
-
const isSendTxError = e instanceof web3_js.SendTransactionError || (e == null ? void 0 : e.name) === "SendTransactionError";
|
|
16592
|
-
if (isSendTxError && msg.includes("already been processed")) {
|
|
16593
|
-
console.warn(
|
|
16594
|
-
'sendRawTransaction reports "already been processed"; treating as success without further confirmation.'
|
|
16595
|
-
);
|
|
16596
|
-
const legacy = signed;
|
|
16597
|
-
const first = (_c = (_b = legacy.signatures) == null ? void 0 : _b[0]) == null ? void 0 : _c.signature;
|
|
16598
|
-
if (first) {
|
|
16599
|
-
return bs58.encode(first);
|
|
16600
|
-
}
|
|
16601
|
-
return "already-processed";
|
|
16602
|
-
}
|
|
16603
|
-
throw e;
|
|
16604
|
-
}
|
|
16605
|
-
});
|
|
16606
|
-
}
|
|
16607
|
-
signTransaction(tx) {
|
|
16608
|
-
return __async$8(this, null, function* () {
|
|
16609
|
-
this.ensureUser();
|
|
16610
|
-
return this.anchor.wallet.signTransaction(tx);
|
|
16611
|
-
});
|
|
16612
|
-
}
|
|
16613
|
-
sendTransaction(signed) {
|
|
16614
|
-
return __async$8(this, null, function* () {
|
|
16615
|
-
this.ensureUser();
|
|
16616
|
-
return this.anchor.sendAndConfirm(signed);
|
|
16617
|
-
});
|
|
16618
|
-
}
|
|
16619
|
-
prepareTx(tx) {
|
|
16620
|
-
return __async$8(this, null, function* () {
|
|
16621
|
-
const { blockhash, lastValidBlockHeight } = yield this.connection.getLatestBlockhash("confirmed");
|
|
16622
|
-
tx.recentBlockhash = blockhash;
|
|
16623
|
-
tx.feePayer = this.feePayer;
|
|
16624
|
-
return { tx, blockhash, lastValidBlockHeight };
|
|
16625
|
-
});
|
|
16626
|
-
}
|
|
16627
|
-
ensureUser() {
|
|
16628
|
-
var _a;
|
|
16629
|
-
if (!this.pubKey) throw new Error("User pubKey is undefined");
|
|
16630
|
-
const wallet = (_a = this.anchor) == null ? void 0 : _a.wallet;
|
|
16631
|
-
const pk = wallet == null ? void 0 : wallet.publicKey;
|
|
16632
|
-
if (!pk) throw new Error("Wallet not connected");
|
|
16633
|
-
if (typeof wallet.signTransaction !== "function") {
|
|
16634
|
-
throw new Error("Wallet does not support signTransaction");
|
|
16635
|
-
}
|
|
16636
|
-
}
|
|
16637
16555
|
};
|
|
16638
16556
|
_SolanaStakingClient.EPOCHS_PER_YEAR_TTL_MS = 10 * 60 * 1e3;
|
|
16639
16557
|
_SolanaStakingClient.FEE_CACHE_TTL_MS = 6e4;
|