• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bmresearch / Solnet / 15456731198

05 Jun 2025 02:04AM UTC coverage: 66.052% (-4.7%) from 70.792%
15456731198

Pull #497

github

web-flow
Merge e0afe0e16 into 632c6bef2
Pull Request #497: Stakepool program

1161 of 2022 branches covered (57.42%)

Branch coverage included in aggregate %.

704 of 1521 new or added lines in 12 files covered. (46.29%)

5822 of 8550 relevant lines covered (68.09%)

987890.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.97
/src/Solnet.Programs/StakePool/Models/StakePool.cs
1
using Solnet.Programs.TokenSwap.Models;
2
using Solnet.Wallet;
3
using System;
4
using System.Collections.Generic;
5
using System.Linq;
6
using System.Numerics;
7
using System.Text;
8
using System.Threading.Tasks;
9
using static Solnet.Programs.Models.Stake.State;
10

11
namespace Solnet.Programs.StakePool.Models
12
{
13
    /// <summary>
14
    /// Represents a Stake Pool in the Solana blockchain.
15
    /// </summary>
16
    public class StakePool
17
    {
18
        /// <summary>
19
        /// Gets or sets the type of the account.
20
        /// </summary>
NEW
21
        public AccountType AccountType { get; set; }
×
22

23
        /// <summary>
24
        /// The public key of the stake pool.
25
        /// </summary>
NEW
26
        public PublicKey Manager { get; set; }
×
27

28
        /// <summary>
29
        /// The public key of the staker.
30
        /// </summary>
31
        public PublicKey Staker { get; set; }
1✔
32

33
        /// <summary>
34
        /// The public key of the Deposit Authority.
35
        /// </summary>
NEW
36
        public PublicKey StakeDepositAuthority { get; set; }
×
37

38
        /// <summary>
39
        /// Gets or sets the bump seed associated with the stake withdrawal operation.
40
        /// </summary>
NEW
41
        public PublicKey StakeWithdrawBumpSeed { get; set; }
×
42

43
        /// <summary>
44
        /// The public key of the validator list.
45
        /// </summary>
46
        public PublicKey ValidatorList { get; set; }
4✔
47

48
        /// <summary>
49
        /// The public key of the reserve stake account.
50
        /// </summary>
51
        public PublicKey ReserveStake { get; set; }
3✔
52

53
        /// <summary>
54
        /// The public key of the pool mint.
55
        /// </summary>
56
        public PublicKey PoolMint { get; set; }
2✔
57

58
        /// <summary>
59
        /// The public key of the manager fee account.
60
        /// </summary>
61
        public PublicKey ManagerFeeAccount { get; set; }
2✔
62

63
        /// <summary>
64
        /// The public key of the token program ID.
65
        /// </summary>
66
        public PublicKey TokenProgramId { get; set; }
2✔
67

68
        /// <summary>
69
        /// The total lamports in the stake pool.
70
        /// </summary>
NEW
71
        public ulong TotalLamports { get; set; }
×
72

73
        /// <summary>
74
        /// The total supply of pool tokens.
75
        /// </summary>
NEW
76
        public ulong PoolTokenSupply { get; set; }
×
77

78
        /// <summary>
79
        /// The epoch of the last update.
80
        /// </summary>
NEW
81
        public ulong LastUpdateEpoch { get; set; }
×
82

83
        /// <summary>
84
        /// The lockup configuration for the stake pool.
85
        /// </summary>
NEW
86
        public Lockup Lockup { get; set; }
×
87

88
        /// <summary>
89
        /// The fee for the current epoch.
90
        /// </summary>
NEW
91
        public Fee EpochFee { get; set; }
×
92

93
        /// <summary>
94
        /// The fee for the next epoch.
95
        /// </summary>
NEW
96
        public Fee NextEpochFee { get; set; }
×
97

98
        /// <summary>
99
        /// The preferred validator vote address for deposits.
100
        /// </summary>
NEW
101
        public PublicKey PreferredDepositValidatorVoteAddress { get; set; }
×
102

103
        /// <summary>
104
        /// The preferred validator vote address for withdrawals.
105
        /// </summary>
NEW
106
        public PublicKey PreferredWithdrawValidatorVoteAddress { get; set; }
×
107

108
        /// <summary>
109
        /// The fee for stake deposits.
110
        /// </summary>
NEW
111
        public Fee StakeDepositFee { get; set; }
×
112

113
        /// <summary>
114
        /// The fee for stake withdrawals.
115
        /// </summary>
NEW
116
        public Fee StakeWithdrawalFee { get; set; }
×
117

118
        /// <summary>
119
        /// The fee for the next stake withdrawals.
120
        /// </summary>
NEW
121
        public Fee NextStakeWithdrawalFees { get; set; }
×
122

123
        /// <summary>
124
        /// The referral fee for stake operations.
125
        /// </summary>
NEW
126
        public byte StakeReferralFee { get; set; }
×
127

128
        /// <summary>
129
        /// The public key of the SOL deposit authority.
130
        /// </summary>
NEW
131
        public PublicKey SolDepositAuthority { get; set; }
×
132

133
        /// <summary>
134
        /// The fee for SOL deposits.
135
        /// </summary>
NEW
136
        public Fee SolDepositFee { get; set; }
×
137

138
        /// <summary>
139
        /// The referral fee for SOL operations.
140
        /// </summary>
NEW
141
        public byte SolReferralFee { get; set; }
×
142

143
        /// <summary>
144
        /// The public key of the SOL withdrawal authority.
145
        /// </summary>
NEW
146
        public PublicKey SolWithdrawAuthority { get; set; }
×
147

148
        /// <summary>
149
        /// The fee for SOL withdrawals.
150
        /// </summary>
NEW
151
        public Fee SolWithdrawalFee { get; set; }
×
152

153
        /// <summary>
154
        /// The fee for the next SOL withdrawals.
155
        /// </summary>
NEW
156
        public Fee NextSolWithdrawalFee { get; set; }
×
157

158
        /// <summary>
159
        /// The pool token supply at the last epoch.
160
        /// </summary>
NEW
161
        public ulong LastEpochPoolTokenSupply { get; set; }
×
162

163
        /// <summary>
164
        /// The total lamports at the last epoch.
165
        /// </summary>
NEW
166
        public ulong LastEpochTotalLamports { get; set; }
×
167

168
        /// <summary>
169
        /// Initializes a new instance of the <see cref="StakePool"/> class.
170
        /// </summary>
171
        public StakePool()
1✔
172
        {
173
            // Initialize properties
174
        }
1✔
175

176
        /// <summary>
177
        /// Calculates the pool tokens that should be minted for a deposit of stake lamports.
178
        /// </summary>
179
        public ulong? CalcPoolTokensForDeposit(ulong stakeLamports)
180
        {
NEW
181
            if (TotalLamports == 0 || PoolTokenSupply == 0)
×
NEW
182
                return stakeLamports;
×
183

184
            try
185
            {
NEW
186
                BigInteger tokens = (BigInteger)stakeLamports * PoolTokenSupply;
×
NEW
187
                BigInteger result = tokens / TotalLamports;
×
NEW
188
                if (result < 0 || result > ulong.MaxValue) return null;
×
NEW
189
                return (ulong)result;
×
190
            }
NEW
191
            catch
×
192
            {
NEW
193
                return null;
×
194
            }
NEW
195
        }
×
196

197
        /// <summary>
198
        /// Calculates the lamports amount on withdrawal.
199
        /// </summary>
200
        public ulong? CalcLamportsWithdrawAmount(ulong poolTokens)
201
        {
NEW
202
            BigInteger numerator = (BigInteger)poolTokens * TotalLamports;
×
NEW
203
            BigInteger denominator = PoolTokenSupply;
×
NEW
204
            if (denominator == 0 || numerator < denominator)
×
NEW
205
                return 0;
×
206
            try
207
            {
NEW
208
                BigInteger result = numerator / denominator;
×
NEW
209
                if (result < 0 || result > ulong.MaxValue) return null;
×
NEW
210
                return (ulong)result;
×
211
            }
NEW
212
            catch
×
213
            {
NEW
214
                return null;
×
215
            }
NEW
216
        }
×
217

218
        /// <summary>
219
        /// Calculates pool tokens to be deducted as stake withdrawal fees.
220
        /// </summary>
221
        public ulong? CalcPoolTokensStakeWithdrawalFee(ulong poolTokens)
222
        {
NEW
223
            return StakeWithdrawalFee?.Apply(poolTokens);
×
224
        }
225

226
        /// <summary>
227
        /// Calculates pool tokens to be deducted as SOL withdrawal fees.
228
        /// </summary>
229
        public ulong? CalcPoolTokensSolWithdrawalFee(ulong poolTokens)
230
        {
NEW
231
            return SolWithdrawalFee?.Apply(poolTokens);
×
232
        }
233

234
        /// <summary>
235
        /// Calculates pool tokens to be deducted as stake deposit fees.
236
        /// </summary>
237
        public ulong? CalcPoolTokensStakeDepositFee(ulong poolTokensMinted)
238
        {
NEW
239
            return StakeDepositFee?.Apply(poolTokensMinted);
×
240
        }
241

242
        /// <summary>
243
        /// Calculates pool tokens to be deducted from deposit fees as referral fees.
244
        /// </summary>
245
        public ulong? CalcPoolTokensStakeReferralFee(ulong stakeDepositFee)
246
        {
247
            try
248
            {
NEW
249
                BigInteger result = (BigInteger)stakeDepositFee * StakeReferralFee / 100;
×
NEW
250
                if (result < 0 || result > ulong.MaxValue) return null;
×
NEW
251
                return (ulong)result;
×
252
            }
NEW
253
            catch
×
254
            {
NEW
255
                return null;
×
256
            }
NEW
257
        }
×
258

259
        /// <summary>
260
        /// Calculates pool tokens to be deducted as SOL deposit fees.
261
        /// </summary>
262
        public ulong? CalcPoolTokensSolDepositFee(ulong poolTokensMinted)
263
        {
NEW
264
            return SolDepositFee?.Apply(poolTokensMinted);
×
265
        }
266

267
        /// <summary>
268
        /// Calculates pool tokens to be deducted from SOL deposit fees as referral fees.
269
        /// </summary>
270
        public ulong? CalcPoolTokensSolReferralFee(ulong solDepositFee)
271
        {
272
            try
273
            {
NEW
274
                BigInteger result = (BigInteger)solDepositFee * SolReferralFee / 100;
×
NEW
275
                if (result < 0 || result > ulong.MaxValue) return null;
×
NEW
276
                return (ulong)result;
×
277
            }
NEW
278
            catch
×
279
            {
NEW
280
                return null;
×
281
            }
NEW
282
        }
×
283

284
        /// <summary>
285
        /// Calculates the fee in pool tokens that goes to the manager for a given reward lamports.
286
        /// </summary>
287
        public ulong? CalcEpochFeeAmount(ulong rewardLamports)
288
        {
NEW
289
            if (rewardLamports == 0)
×
NEW
290
                return 0;
×
291

NEW
292
            BigInteger totalLamports = (BigInteger)TotalLamports + rewardLamports;
×
NEW
293
            var feeLamports = EpochFee?.Apply(rewardLamports) ?? 0;
×
294

NEW
295
            if (totalLamports == feeLamports || PoolTokenSupply == 0)
×
NEW
296
                return rewardLamports;
×
297

298
            try
299
            {
NEW
300
                BigInteger result = (BigInteger)PoolTokenSupply * feeLamports /
×
NEW
301
                                    (totalLamports - feeLamports);
×
NEW
302
                if (result < 0 || result > ulong.MaxValue) return null;
×
NEW
303
                return (ulong)result;
×
304
            }
NEW
305
            catch
×
306
            {
NEW
307
                return null;
×
308
            }
NEW
309
        }
×
310

311
        /// <summary>
312
        /// Gets the current value of pool tokens, rounded up.
313
        /// </summary>
314
        public ulong? GetLamportsPerPoolToken()
315
        {
316
            try
317
            {
NEW
318
                BigInteger result = ((BigInteger)TotalLamports + PoolTokenSupply - 1) / PoolTokenSupply;
×
NEW
319
                if (result < 0 || result > ulong.MaxValue) return null;
×
NEW
320
                return (ulong)result;
×
321
            }
NEW
322
            catch
×
323
            {
NEW
324
                return null;
×
325
            }
NEW
326
        }
×
327
    }
328
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc