@wireio/stake 0.0.6 → 0.1.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/README.md +260 -13
- package/lib/stake.browser.js +4861 -4218
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +434 -6484
- package/lib/stake.js +5059 -4371
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +4861 -4218
- package/lib/stake.m.js.map +1 -1
- package/package.json +2 -2
- package/src/assets/solana/idl/liqsol_core.json +4239 -0
- package/src/assets/solana/idl/liqsol_token.json +183 -0
- package/src/assets/solana/idl/validator_leaderboard.json +296 -250
- package/src/assets/solana/types/liqsol_core.ts +4245 -0
- package/src/assets/solana/types/liqsol_token.ts +189 -0
- package/src/assets/solana/types/validator_leaderboard.ts +296 -250
- package/src/index.ts +2 -5
- package/src/networks/ethereum/contract.ts +138 -36
- package/src/networks/ethereum/ethereum.ts +167 -38
- package/src/networks/ethereum/types.ts +32 -1
- package/src/networks/solana/clients/deposit.client.ts +92 -139
- package/src/networks/solana/clients/distribution.client.ts +302 -178
- package/src/networks/solana/clients/leaderboard.client.ts +40 -160
- package/src/networks/solana/constants.ts +238 -69
- package/src/networks/solana/program.ts +27 -93
- package/src/networks/solana/solana.ts +181 -36
- package/src/networks/solana/types.ts +47 -0
- package/src/networks/solana/utils.ts +522 -93
- package/src/scripts/fetch-artifacts.sh +24 -0
- package/src/scripts/tsconfig.json +17 -0
- package/src/staker/staker.ts +35 -30
- package/src/staker/types.ts +25 -22
- package/src/assets/solana/idl/deposit.json +0 -260
- package/src/assets/solana/idl/distribution.json +0 -736
- package/src/assets/solana/idl/liq_sol_token.json +0 -275
- package/src/assets/solana/idl/stake_controller.json +0 -1788
- package/src/assets/solana/idl/stake_registry.json +0 -435
- package/src/assets/solana/idl/treasury.json +0 -336
- package/src/assets/solana/idl/validator_registry.json +0 -418
- package/src/assets/solana/idl/yield_oracle.json +0 -32
- package/src/assets/solana/types/deposit.ts +0 -266
- package/src/assets/solana/types/distribution.ts +0 -742
- package/src/assets/solana/types/liq_sol_token.ts +0 -281
- package/src/assets/solana/types/stake_controller.ts +0 -1794
- package/src/assets/solana/types/stake_registry.ts +0 -441
- package/src/assets/solana/types/treasury.ts +0 -342
- package/src/assets/solana/types/validator_registry.ts +0 -424
- package/src/assets/solana/types/yield_oracle.ts +0 -38
- package/src/utils.ts +0 -9
|
@@ -1,178 +1,131 @@
|
|
|
1
|
-
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
2
|
-
import { BN } from '@coral-xyz/anchor';
|
|
1
|
+
import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
|
|
3
2
|
import {
|
|
4
3
|
PublicKey,
|
|
5
|
-
Transaction,
|
|
6
4
|
SystemProgram,
|
|
5
|
+
Transaction,
|
|
6
|
+
TransactionInstruction,
|
|
7
|
+
StakeProgram,
|
|
7
8
|
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
8
9
|
SYSVAR_CLOCK_PUBKEY,
|
|
9
10
|
SYSVAR_RENT_PUBKEY,
|
|
10
11
|
SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
11
|
-
StakeProgram,
|
|
12
|
-
ComputeBudgetProgram,
|
|
13
|
-
VersionedTransaction,
|
|
14
|
-
Signer,
|
|
15
|
-
TransactionSignature,
|
|
16
12
|
} from '@solana/web3.js';
|
|
17
13
|
import {
|
|
18
14
|
TOKEN_2022_PROGRAM_ID,
|
|
19
15
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
16
|
+
getAssociatedTokenAddressSync,
|
|
20
17
|
} from '@solana/spl-token';
|
|
21
18
|
|
|
19
|
+
import { SolanaProgramService } from '../program';
|
|
20
|
+
import type { LiqsolCore } from '../../../assets/solana/types/liqsol_core';
|
|
21
|
+
|
|
22
22
|
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
LIQSOL_TOKEN_PROGRAM_ID,
|
|
37
|
-
YIELD_ORACLE_PROGRAM_ID,
|
|
38
|
-
DISTRIBUTION_PROGRAM_ID,
|
|
39
|
-
MIN_SOL_TO_PARTICIPATE,
|
|
23
|
+
PROGRAM_IDS,
|
|
24
|
+
deriveDepositAuthorityPda,
|
|
25
|
+
deriveLiqsolMintPda,
|
|
26
|
+
deriveLiqsolMintAuthorityPda,
|
|
27
|
+
deriveReservePoolPda,
|
|
28
|
+
deriveVaultPda,
|
|
29
|
+
deriveStakeControllerStatePda,
|
|
30
|
+
deriveBucketAuthorityPda,
|
|
31
|
+
derivePayRateHistoryPda,
|
|
32
|
+
deriveDistributionStatePda,
|
|
33
|
+
deriveUserRecordPda,
|
|
34
|
+
derivePayoutStatePda,
|
|
35
|
+
deriveEphemeralStakeAddress,
|
|
40
36
|
} from '../constants';
|
|
41
|
-
import { SolanaProgramService } from '../program';
|
|
42
37
|
|
|
43
|
-
/**
|
|
44
|
-
* DepositClient provides methods for building, simulating, and sending deposit transactions
|
|
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.
|
|
49
|
-
*
|
|
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
|
-
*/
|
|
56
38
|
export class DepositClient {
|
|
57
|
-
private program
|
|
58
|
-
|
|
59
|
-
constructor(private provider: AnchorProvider) { }
|
|
39
|
+
private program: Program<LiqsolCore>;
|
|
60
40
|
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
constructor(private provider: AnchorProvider) {
|
|
42
|
+
const svc = new SolanaProgramService(provider);
|
|
43
|
+
this.program = svc.getProgram('liqsolCore');
|
|
44
|
+
}
|
|
63
45
|
|
|
64
|
-
/**
|
|
65
|
-
* Build the deposit transaction (compute-budget bump + deposit Ix).
|
|
66
|
-
* Returns both the Transaction and the ephemeral stake account Pubkey.
|
|
67
|
-
*/
|
|
68
46
|
async buildDepositTx(
|
|
69
47
|
user: PublicKey,
|
|
70
|
-
|
|
71
|
-
): Promise<{ transaction: Transaction;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
48
|
+
lamports: number
|
|
49
|
+
): Promise<{ transaction: Transaction; ephemeralStake: PublicKey }> {
|
|
50
|
+
|
|
51
|
+
const program = this.program;
|
|
52
|
+
|
|
53
|
+
// -------------------------------------------------------------
|
|
54
|
+
// PDAs
|
|
55
|
+
// -------------------------------------------------------------
|
|
56
|
+
const depositAuthority = deriveDepositAuthorityPda();
|
|
57
|
+
const liqsolMint = deriveLiqsolMintPda();
|
|
58
|
+
const liqsolMintAuthority = deriveLiqsolMintAuthorityPda();
|
|
59
|
+
const reservePool = deriveReservePoolPda();
|
|
60
|
+
const vault = deriveVaultPda();
|
|
61
|
+
const controllerState = deriveStakeControllerStatePda();
|
|
62
|
+
const payoutState = derivePayoutStatePda();
|
|
63
|
+
const bucketAuthority = deriveBucketAuthorityPda();
|
|
64
|
+
const payRateHistory = derivePayRateHistoryPda();
|
|
65
|
+
const distributionState = deriveDistributionStatePda();
|
|
66
|
+
const userRecord = deriveUserRecordPda(user);
|
|
67
|
+
|
|
68
|
+
// -------------------------------------------------------------
|
|
69
|
+
// Token-2022 ATAs
|
|
70
|
+
// -------------------------------------------------------------
|
|
71
|
+
const userAta = getAssociatedTokenAddressSync(
|
|
72
|
+
liqsolMint,
|
|
95
73
|
user,
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
false,
|
|
75
|
+
TOKEN_2022_PROGRAM_ID
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const bucketTokenAccount = getAssociatedTokenAddressSync(
|
|
79
|
+
liqsolMint,
|
|
80
|
+
bucketAuthority,
|
|
81
|
+
true,
|
|
82
|
+
TOKEN_2022_PROGRAM_ID
|
|
98
83
|
);
|
|
99
84
|
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
// -------------------------------------------------------------
|
|
86
|
+
// Ephemeral stake
|
|
87
|
+
// -------------------------------------------------------------
|
|
88
|
+
const seed = Math.floor(Math.random() * 2 ** 32);
|
|
89
|
+
const ephemeralStake = await deriveEphemeralStakeAddress(user, seed);
|
|
90
|
+
|
|
91
|
+
// -------------------------------------------------------------
|
|
92
|
+
// BUILD IX (MUST MATCH IDL)
|
|
93
|
+
// -------------------------------------------------------------
|
|
94
|
+
const ix: TransactionInstruction = await program.methods
|
|
95
|
+
.deposit(new BN(lamports), seed)
|
|
103
96
|
.accounts({
|
|
104
97
|
user,
|
|
105
|
-
|
|
106
|
-
treasuryWallet: TREASURY_WALLET_PDA,
|
|
98
|
+
depositAuthority,
|
|
107
99
|
systemProgram: SystemProgram.programId,
|
|
108
100
|
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
109
101
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
110
|
-
|
|
111
|
-
liqsolProgram: LIQSOL_TOKEN_PROGRAM_ID,
|
|
112
|
-
yieldOracleProgram: YIELD_ORACLE_PROGRAM_ID,
|
|
102
|
+
liqsolProgram: PROGRAM_IDS.LIQSOL_TOKEN,
|
|
113
103
|
stakeProgram: StakeProgram.programId,
|
|
114
|
-
|
|
115
|
-
liqsolMint
|
|
104
|
+
|
|
105
|
+
liqsolMint,
|
|
116
106
|
userAta,
|
|
117
|
-
liqsolMintAuthority
|
|
118
|
-
reservePool
|
|
119
|
-
vault
|
|
120
|
-
ephemeralStake
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
liqsolMintAuthority,
|
|
108
|
+
reservePool,
|
|
109
|
+
vault,
|
|
110
|
+
ephemeralStake,
|
|
111
|
+
|
|
112
|
+
controllerState,
|
|
113
|
+
payoutState,
|
|
114
|
+
bucketAuthority,
|
|
115
|
+
bucketTokenAccount,
|
|
116
|
+
|
|
117
|
+
userRecord,
|
|
118
|
+
distributionState,
|
|
119
|
+
payRateHistory,
|
|
120
|
+
|
|
124
121
|
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
125
122
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
126
123
|
stakeHistory: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
127
124
|
rent: SYSVAR_RENT_PUBKEY,
|
|
128
|
-
}
|
|
125
|
+
})
|
|
129
126
|
.instruction();
|
|
130
127
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
units: 400_000,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const tx = new Transaction().add(computeIx, depositIx);
|
|
137
|
-
return { transaction: tx, ephemeralStakePubkey };
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Simulate (dry-run) a built transaction.
|
|
142
|
-
* Returns any error plus the total compute-units consumed.
|
|
143
|
-
*/
|
|
144
|
-
async simulate(
|
|
145
|
-
tx: Transaction
|
|
146
|
-
): Promise<{ err: any; unitsConsumed: number }> {
|
|
147
|
-
tx.feePayer = this.provider.wallet.publicKey;
|
|
148
|
-
const { blockhash } = await this.provider.connection.getLatestBlockhash();
|
|
149
|
-
tx.recentBlockhash = blockhash;
|
|
150
|
-
|
|
151
|
-
const versioned = new VersionedTransaction(tx.compileMessage());
|
|
152
|
-
const sim = await this.provider.connection.simulateTransaction(
|
|
153
|
-
versioned,
|
|
154
|
-
{ sigVerify: false }
|
|
155
|
-
);
|
|
156
|
-
return { err: sim.value.err, unitsConsumed: sim.value.unitsConsumed! };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* High-level “build & send” helper.
|
|
161
|
-
* Returns the confirmed signature.
|
|
162
|
-
*/
|
|
163
|
-
async deposit(
|
|
164
|
-
user: PublicKey,
|
|
165
|
-
amount: number,
|
|
166
|
-
signers: Signer[] = []
|
|
167
|
-
): Promise<TransactionSignature> {
|
|
168
|
-
const { transaction } = await this.buildDepositTx(user, amount);
|
|
169
|
-
|
|
170
|
-
// set feePayer & recent blockhash
|
|
171
|
-
transaction.feePayer = this.provider.wallet.publicKey;
|
|
172
|
-
const { blockhash } = await this.provider.connection.getLatestBlockhash();
|
|
173
|
-
transaction.recentBlockhash = blockhash;
|
|
174
|
-
|
|
175
|
-
// send + confirm
|
|
176
|
-
return this.provider.sendAndConfirm(transaction, signers);
|
|
128
|
+
const tx = new Transaction().add(ix);
|
|
129
|
+
return { transaction: tx, ephemeralStake };
|
|
177
130
|
}
|
|
178
131
|
}
|