@wireio/stake 2.1.0 → 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 -258
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +39 -50
- package/lib/stake.js +161 -274
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +147 -258
- 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 -368
- package/src/networks/solana/utils.ts +1 -1
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,97 +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
|
-
let signature;
|
|
16583
|
-
try {
|
|
16584
|
-
signature = yield this.connection.sendRawTransaction(rawTx, {
|
|
16585
|
-
skipPreflight: false,
|
|
16586
|
-
preflightCommitment: commitment,
|
|
16587
|
-
maxRetries: 3
|
|
16588
|
-
});
|
|
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 preflight says "already been processed"; treating as success and deriving signature from signed tx.'
|
|
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
|
-
throw e;
|
|
16600
|
-
}
|
|
16601
|
-
signature = bs58.encode(first);
|
|
16602
|
-
} else {
|
|
16603
|
-
throw e;
|
|
16604
|
-
}
|
|
16605
|
-
}
|
|
16606
|
-
const start = Date.now();
|
|
16607
|
-
const timeoutMs = 3e4;
|
|
16608
|
-
const pollIntervalMs = 500;
|
|
16609
|
-
while (true) {
|
|
16610
|
-
const { value } = yield this.connection.getSignatureStatuses(
|
|
16611
|
-
[signature],
|
|
16612
|
-
{ searchTransactionHistory: true }
|
|
16613
|
-
);
|
|
16614
|
-
const status = value[0];
|
|
16615
|
-
if (status) {
|
|
16616
|
-
if (status.err) {
|
|
16617
|
-
throw new Error(
|
|
16618
|
-
`Transaction failed: ${JSON.stringify(status.err)}`
|
|
16619
|
-
);
|
|
16620
|
-
}
|
|
16621
|
-
const confirmations = status.confirmations;
|
|
16622
|
-
const confirmationStatus = status.confirmationStatus;
|
|
16623
|
-
const satisfied = confirmationStatus === "confirmed" || confirmationStatus === "finalized" || confirmations === null ||
|
|
16624
|
-
(confirmations != null ? confirmations : 0) > 0;
|
|
16625
|
-
if (satisfied) {
|
|
16626
|
-
return signature;
|
|
16627
|
-
}
|
|
16628
|
-
}
|
|
16629
|
-
if (Date.now() - start > timeoutMs) {
|
|
16630
|
-
throw new Error(
|
|
16631
|
-
`Transaction confirmation timed out for ${signature}`
|
|
16632
|
-
);
|
|
16633
|
-
}
|
|
16634
|
-
yield new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
16635
|
-
}
|
|
16636
|
-
});
|
|
16637
|
-
}
|
|
16638
|
-
signTransaction(tx) {
|
|
16639
|
-
return __async$8(this, null, function* () {
|
|
16640
|
-
this.ensureUser();
|
|
16641
|
-
return this.anchor.wallet.signTransaction(tx);
|
|
16642
|
-
});
|
|
16643
|
-
}
|
|
16644
|
-
sendTransaction(signed) {
|
|
16645
|
-
return __async$8(this, null, function* () {
|
|
16646
|
-
this.ensureUser();
|
|
16647
|
-
return this.anchor.sendAndConfirm(signed);
|
|
16648
|
-
});
|
|
16649
|
-
}
|
|
16650
|
-
prepareTx(tx) {
|
|
16651
|
-
return __async$8(this, null, function* () {
|
|
16652
|
-
const { blockhash, lastValidBlockHeight } = yield this.connection.getLatestBlockhash("confirmed");
|
|
16653
|
-
tx.recentBlockhash = blockhash;
|
|
16654
|
-
tx.feePayer = this.feePayer;
|
|
16655
|
-
return { tx, blockhash, lastValidBlockHeight };
|
|
16656
|
-
});
|
|
16657
|
-
}
|
|
16658
|
-
ensureUser() {
|
|
16659
|
-
var _a;
|
|
16660
|
-
if (!this.pubKey) throw new Error("User pubKey is undefined");
|
|
16661
|
-
const wallet = (_a = this.anchor) == null ? void 0 : _a.wallet;
|
|
16662
|
-
const pk = wallet == null ? void 0 : wallet.publicKey;
|
|
16663
|
-
if (!pk) throw new Error("Wallet not connected");
|
|
16664
|
-
if (typeof wallet.signTransaction !== "function") {
|
|
16665
|
-
throw new Error("Wallet does not support signTransaction");
|
|
16666
|
-
}
|
|
16667
|
-
}
|
|
16668
16555
|
};
|
|
16669
16556
|
_SolanaStakingClient.EPOCHS_PER_YEAR_TTL_MS = 10 * 60 * 1e3;
|
|
16670
16557
|
_SolanaStakingClient.FEE_CACHE_TTL_MS = 6e4;
|