@wireio/stake 0.0.6 → 0.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.
- package/README.md +203 -13
- package/lib/stake.browser.js +2800 -3329
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +376 -6261
- package/lib/stake.js +2937 -3476
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +2800 -3329
- package/lib/stake.m.js.map +1 -1
- package/package.json +2 -2
- package/src/assets/solana/idl/deposit.json +46 -10
- package/src/assets/solana/idl/distribution.json +40 -8
- package/src/assets/solana/idl/liq_sol_token.json +25 -2
- package/src/assets/solana/idl/mint_helper.json +110 -0
- package/src/assets/solana/idl/read_tracked_balance.json +140 -0
- package/src/assets/solana/idl/stake_controller.json +1141 -780
- package/src/assets/solana/idl/treasury.json +1 -227
- package/src/assets/solana/idl/validator_leaderboard.json +88 -47
- package/src/assets/solana/idl/validator_registry.json +115 -46
- package/src/assets/solana/idl/yield_oracle.json +1 -1
- package/src/assets/solana/types/deposit.ts +46 -10
- package/src/assets/solana/types/distribution.ts +40 -8
- package/src/assets/solana/types/liq_sol_token.ts +25 -2
- package/src/assets/solana/types/mint_helper.ts +116 -0
- package/src/assets/solana/types/read_tracked_balance.ts +146 -0
- package/src/assets/solana/types/stake_controller.ts +1141 -780
- package/src/assets/solana/types/treasury.ts +1 -227
- package/src/assets/solana/types/validator_leaderboard.ts +88 -47
- package/src/assets/solana/types/validator_registry.ts +115 -46
- package/src/assets/solana/types/yield_oracle.ts +1 -1
- package/src/index.ts +3 -4
- package/src/networks/ethereum/ethereum.ts +2 -2
- package/src/networks/solana/clients/deposit.client.ts +71 -80
- package/src/networks/solana/clients/distribution.client.ts +392 -141
- package/src/networks/solana/clients/leaderboard.client.ts +82 -107
- package/src/networks/solana/constants.ts +141 -56
- package/src/networks/solana/program.ts +36 -89
- package/src/networks/solana/solana.ts +168 -34
- package/src/networks/solana/types.ts +57 -0
- package/src/scripts/fetch-artifacts.sh +24 -0
- package/src/staker/staker.ts +32 -28
- package/src/staker/types.ts +24 -21
- package/src/assets/solana/idl/stake_registry.json +0 -435
- package/src/networks/solana/utils.ts +0 -122
- /package/src/{utils.ts → common/utils.ts} +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
2
|
-
import { BN } from '@coral-xyz/anchor';
|
|
1
|
+
import { AnchorProvider, BN } from '@coral-xyz/anchor';
|
|
3
2
|
import {
|
|
4
3
|
PublicKey,
|
|
5
4
|
Transaction,
|
|
@@ -14,81 +13,83 @@ import {
|
|
|
14
13
|
Signer,
|
|
15
14
|
TransactionSignature,
|
|
16
15
|
} from '@solana/web3.js';
|
|
16
|
+
|
|
17
17
|
import {
|
|
18
|
-
|
|
18
|
+
getAssociatedTokenAddress,
|
|
19
19
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
20
|
+
TOKEN_2022_PROGRAM_ID
|
|
20
21
|
} from '@solana/spl-token';
|
|
21
22
|
|
|
22
23
|
import {
|
|
24
|
+
STAKE_CONTROLLER_PROGRAM_ID,
|
|
25
|
+
LIQSOL_TOKEN_PROGRAM_ID,
|
|
26
|
+
DISTRIBUTION_PROGRAM_ID,
|
|
27
|
+
MIN_SOL_TO_PARTICIPATE,
|
|
23
28
|
deriveDepositAuthorityPDA,
|
|
29
|
+
deriveLiqsolMintPDA,
|
|
24
30
|
deriveLiqsolMintAuthorityPDA,
|
|
25
|
-
deriveStakeControllerVaultPDA,
|
|
26
31
|
deriveStakeControllerReservePoolPDA,
|
|
32
|
+
deriveStakeControllerVaultPDA,
|
|
27
33
|
deriveStakeControllerStatePDA,
|
|
34
|
+
deriveGlobalStakeInfoPDA,
|
|
35
|
+
deriveBucketAuthorityPDA,
|
|
28
36
|
deriveDistributionStatePDA,
|
|
29
37
|
deriveUserRecordPDA,
|
|
30
|
-
|
|
31
|
-
} from '../utils';
|
|
32
|
-
import {
|
|
33
|
-
LIQSOL_MINT_ADDRESS,
|
|
34
|
-
TREASURY_WALLET_PDA,
|
|
35
|
-
STAKE_CONTROLLER_PROGRAM_ID,
|
|
36
|
-
LIQSOL_TOKEN_PROGRAM_ID,
|
|
37
|
-
YIELD_ORACLE_PROGRAM_ID,
|
|
38
|
-
DISTRIBUTION_PROGRAM_ID,
|
|
39
|
-
MIN_SOL_TO_PARTICIPATE,
|
|
38
|
+
derivePayRateHistoryPDA,
|
|
40
39
|
} from '../constants';
|
|
41
40
|
import { SolanaProgramService } from '../program';
|
|
42
41
|
|
|
43
42
|
/**
|
|
44
|
-
* DepositClient
|
|
45
|
-
* to the Solana blockchain using the Anchor framework. It handles the creation of ephemeral
|
|
46
|
-
* stake accounts, derives necessary PDAs and ATAs, and manages transaction construction
|
|
47
|
-
* with compute budget adjustments. This client is designed to facilitate deposits into
|
|
48
|
-
* the Liqsol staking protocol, ensuring all required accounts and instructions are included.
|
|
43
|
+
* DepositClient: builds, simulates, and sends deposit txns matching the latest IDL.
|
|
49
44
|
*
|
|
50
|
-
* @remarks
|
|
51
|
-
* - Uses AnchorProvider for network interactions.
|
|
52
|
-
* - Enforces minimum deposit requirements.
|
|
53
|
-
* - Supports dry-run simulation for transaction debugging.
|
|
54
|
-
* - Provides high-level helper for building and sending deposit transactions.
|
|
55
45
|
*/
|
|
56
46
|
export class DepositClient {
|
|
57
|
-
private
|
|
47
|
+
private programs = new SolanaProgramService(this.provider);
|
|
58
48
|
|
|
59
49
|
constructor(private provider: AnchorProvider) { }
|
|
60
50
|
|
|
61
|
-
/** Minimum lamports (1 SOL) */
|
|
62
|
-
static readonly MIN_DEPOSIT = MIN_SOL_TO_PARTICIPATE;
|
|
63
|
-
|
|
64
51
|
/**
|
|
65
52
|
* Build the deposit transaction (compute-budget bump + deposit Ix).
|
|
66
|
-
* Returns
|
|
53
|
+
* Returns the Transaction and the derived ephemeral stake pubkey.
|
|
67
54
|
*/
|
|
68
55
|
async buildDepositTx(
|
|
69
56
|
user: PublicKey,
|
|
70
57
|
amount: number
|
|
71
58
|
): Promise<{ transaction: Transaction; ephemeralStakePubkey: PublicKey }> {
|
|
72
59
|
if (amount < MIN_SOL_TO_PARTICIPATE) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
`Minimum deposit is ${MIN_SOL_TO_PARTICIPATE / 1e9} SOL`
|
|
75
|
-
);
|
|
60
|
+
throw new Error(`Minimum deposit is ${MIN_SOL_TO_PARTICIPATE / 1e9} SOL`);
|
|
76
61
|
}
|
|
77
62
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const [
|
|
84
|
-
const [
|
|
85
|
-
const [
|
|
86
|
-
const [
|
|
87
|
-
const [
|
|
88
|
-
const [
|
|
89
|
-
const [
|
|
63
|
+
const program = this.programs.getProgram('deposit');
|
|
64
|
+
|
|
65
|
+
// PDAs
|
|
66
|
+
const [programAuthority] = deriveDepositAuthorityPDA();
|
|
67
|
+
const [liqsolMint] = deriveLiqsolMintPDA();
|
|
68
|
+
const [liqsolMintAuthority] = deriveLiqsolMintAuthorityPDA();
|
|
69
|
+
const [reservePool] = deriveStakeControllerReservePoolPDA();
|
|
70
|
+
const [vault] = deriveStakeControllerVaultPDA();
|
|
71
|
+
const [controllerState] = deriveStakeControllerStatePDA();
|
|
72
|
+
const [globalStakeInfo] = deriveGlobalStakeInfoPDA();
|
|
73
|
+
const [bucketAuthority] = deriveBucketAuthorityPDA();
|
|
74
|
+
const [distributionState] = deriveDistributionStatePDA();
|
|
75
|
+
const [userRecord] = deriveUserRecordPDA(user);
|
|
76
|
+
const [payRateHistory] = derivePayRateHistoryPDA();
|
|
77
|
+
|
|
78
|
+
// Token-2022 ATAs
|
|
79
|
+
const userAta = await getAssociatedTokenAddress(
|
|
80
|
+
liqsolMint,
|
|
81
|
+
user,
|
|
82
|
+
false,
|
|
83
|
+
TOKEN_2022_PROGRAM_ID
|
|
84
|
+
);
|
|
85
|
+
const bucketTokenAccount = await getAssociatedTokenAddress(
|
|
86
|
+
liqsolMint,
|
|
87
|
+
bucketAuthority,
|
|
88
|
+
/* allowOwnerOffCurve */ true,
|
|
89
|
+
TOKEN_2022_PROGRAM_ID
|
|
90
|
+
);
|
|
90
91
|
|
|
91
|
-
//
|
|
92
|
+
// Ephemeral stake account
|
|
92
93
|
const seed = Math.floor(Math.random() * 0xffffffff);
|
|
93
94
|
const ephemeralSeed = `ephemeral_${seed}`;
|
|
94
95
|
const ephemeralStakePubkey = await PublicKey.createWithSeed(
|
|
@@ -97,30 +98,36 @@ export class DepositClient {
|
|
|
97
98
|
StakeProgram.programId
|
|
98
99
|
);
|
|
99
100
|
|
|
100
|
-
//
|
|
101
|
+
// Build the deposit instruction
|
|
101
102
|
const depositIx = await program.methods
|
|
102
103
|
.deposit(new BN(amount), seed)
|
|
103
104
|
.accounts({
|
|
104
105
|
user,
|
|
105
|
-
programAuthority
|
|
106
|
-
treasuryWallet: TREASURY_WALLET_PDA,
|
|
106
|
+
programAuthority,
|
|
107
107
|
systemProgram: SystemProgram.programId,
|
|
108
108
|
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
109
109
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
110
110
|
stakeControllerProgram: STAKE_CONTROLLER_PROGRAM_ID,
|
|
111
111
|
liqsolProgram: LIQSOL_TOKEN_PROGRAM_ID,
|
|
112
|
-
|
|
112
|
+
payRateHistory,
|
|
113
113
|
stakeProgram: StakeProgram.programId,
|
|
114
114
|
distributionProgram: DISTRIBUTION_PROGRAM_ID,
|
|
115
|
-
|
|
115
|
+
|
|
116
|
+
// mints / ATAs / PDAs
|
|
117
|
+
liqsolMint,
|
|
116
118
|
userAta,
|
|
117
|
-
liqsolMintAuthority
|
|
118
|
-
reservePool
|
|
119
|
-
vault
|
|
119
|
+
liqsolMintAuthority,
|
|
120
|
+
reservePool,
|
|
121
|
+
vault,
|
|
120
122
|
ephemeralStake: ephemeralStakePubkey,
|
|
121
|
-
controllerState
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
controllerState,
|
|
124
|
+
globalStakeInfo,
|
|
125
|
+
bucketAuthority,
|
|
126
|
+
bucketTokenAccount,
|
|
127
|
+
userRecord,
|
|
128
|
+
distributionState,
|
|
129
|
+
|
|
130
|
+
// sysvars
|
|
124
131
|
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
125
132
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
126
133
|
stakeHistory: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
@@ -128,51 +135,35 @@ export class DepositClient {
|
|
|
128
135
|
} as any)
|
|
129
136
|
.instruction();
|
|
130
137
|
|
|
131
|
-
//
|
|
132
|
-
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({
|
|
133
|
-
units: 400_000,
|
|
134
|
-
});
|
|
135
|
-
|
|
138
|
+
// Prepend compute-budget bump
|
|
139
|
+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 400_000 });
|
|
136
140
|
const tx = new Transaction().add(computeIx, depositIx);
|
|
137
141
|
return { transaction: tx, ephemeralStakePubkey };
|
|
138
142
|
}
|
|
139
143
|
|
|
140
|
-
/**
|
|
141
|
-
|
|
142
|
-
* Returns any error plus the total compute-units consumed.
|
|
143
|
-
*/
|
|
144
|
-
async simulate(
|
|
145
|
-
tx: Transaction
|
|
146
|
-
): Promise<{ err: any; unitsConsumed: number }> {
|
|
144
|
+
/** Simulate a transaction (dry-run). */
|
|
145
|
+
async simulate(tx: Transaction): Promise<{ err: any; unitsConsumed: number }> {
|
|
147
146
|
tx.feePayer = this.provider.wallet.publicKey;
|
|
148
147
|
const { blockhash } = await this.provider.connection.getLatestBlockhash();
|
|
149
148
|
tx.recentBlockhash = blockhash;
|
|
150
149
|
|
|
151
150
|
const versioned = new VersionedTransaction(tx.compileMessage());
|
|
152
|
-
const sim = await this.provider.connection.simulateTransaction(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
151
|
+
const sim = await this.provider.connection.simulateTransaction(versioned, {
|
|
152
|
+
sigVerify: false,
|
|
153
|
+
});
|
|
156
154
|
return { err: sim.value.err, unitsConsumed: sim.value.unitsConsumed! };
|
|
157
155
|
}
|
|
158
156
|
|
|
159
|
-
/**
|
|
160
|
-
* High-level “build & send” helper.
|
|
161
|
-
* Returns the confirmed signature.
|
|
162
|
-
*/
|
|
157
|
+
/** Build + send. Returns confirmed signature. */
|
|
163
158
|
async deposit(
|
|
164
159
|
user: PublicKey,
|
|
165
160
|
amount: number,
|
|
166
161
|
signers: Signer[] = []
|
|
167
162
|
): Promise<TransactionSignature> {
|
|
168
163
|
const { transaction } = await this.buildDepositTx(user, amount);
|
|
169
|
-
|
|
170
|
-
// set feePayer & recent blockhash
|
|
171
164
|
transaction.feePayer = this.provider.wallet.publicKey;
|
|
172
165
|
const { blockhash } = await this.provider.connection.getLatestBlockhash();
|
|
173
166
|
transaction.recentBlockhash = blockhash;
|
|
174
|
-
|
|
175
|
-
// send + confirm
|
|
176
167
|
return this.provider.sendAndConfirm(transaction, signers);
|
|
177
168
|
}
|
|
178
169
|
}
|