|
| 1 | +using System; |
| 2 | + |
| 3 | +namespace Solnet.Programs.StakePool.Models |
| 4 | +{ |
| 5 | + /// <summary> |
| 6 | + /// The type of fees that can be set on the stake pool. |
| 7 | + /// </summary> |
| 8 | + public abstract class FeeType |
| 9 | + { |
| 10 | + /// <summary> |
| 11 | + /// Represents a referral fee type with a specified percentage. |
| 12 | + /// </summary> |
| 13 | + /// <remarks>This class is used to define a referral fee as a percentage value. The percentage is |
| 14 | + /// immutable and must be specified at the time of instantiation.</remarks> |
| 15 | + public class SolReferral : FeeType |
| 16 | + { |
| 17 | + /// <summary> |
| 18 | + /// Gets the percentage value represented as a byte. |
| 19 | + /// </summary> |
| 20 | + public byte Percentage { get; } |
| 21 | + /// <summary> |
| 22 | + /// Initializes a new instance of the <see cref="SolReferral"/> class with the specified referral |
| 23 | + /// percentage. |
| 24 | + /// </summary> |
| 25 | + /// <param name="percentage">The referral percentage to be applied. Must be a value between 0 and 100, inclusive.</param> |
| 26 | + public SolReferral(byte percentage) => Percentage = percentage; |
| 27 | + } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Represents a referral fee type with a specified percentage for staking rewards. |
| 31 | + /// </summary> |
| 32 | + /// <remarks>This class is used to define a referral fee as a percentage of staking rewards. The |
| 33 | + /// percentage value is immutable and must be specified at the time of instantiation.</remarks> |
| 34 | + public class StakeReferral : FeeType |
| 35 | + { |
| 36 | + /// <summary> |
| 37 | + /// Gets the percentage value represented as a byte. |
| 38 | + /// </summary> |
| 39 | + public byte Percentage { get; } |
| 40 | + /// <summary> |
| 41 | + /// Represents a referral with a specified stake percentage. |
| 42 | + /// </summary> |
| 43 | + /// <remarks>The <paramref name="percentage"/> parameter defines the proportion of the |
| 44 | + /// stake allocated to the referral.</remarks> |
| 45 | + /// <param name="percentage">The percentage of the stake associated with the referral. Must be a value between 0 and 100.</param> |
| 46 | + public StakeReferral(byte percentage) => Percentage = percentage; |
| 47 | + } |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Represents an epoch in the fee structure, associated with a specific fee. |
| 51 | + /// </summary> |
| 52 | + /// <remarks>This class is used to define a specific epoch and its corresponding fee. It inherits |
| 53 | + /// from the <see cref="FeeType"/> base class.</remarks> |
| 54 | + public class Epoch : FeeType |
| 55 | + { |
| 56 | + /// <summary> |
| 57 | + /// Gets the fee associated with the transaction. |
| 58 | + /// </summary> |
| 59 | + public Fee Fee { get; } |
| 60 | + /// <summary> |
| 61 | + /// Represents a specific epoch with an associated fee. |
| 62 | + /// </summary> |
| 63 | + /// <param name="fee">The fee associated with the epoch. Cannot be null.</param> |
| 64 | + public Epoch(Fee fee) => Fee = fee; |
| 65 | + } |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// Represents a withdrawal of staked funds, including an associated fee. |
| 69 | + /// </summary> |
| 70 | + /// <remarks>This class encapsulates the details of a stake withdrawal operation, including the |
| 71 | + /// fee applied to the withdrawal. It inherits from <see cref="FeeType"/>.</remarks> |
| 72 | + public class StakeWithdrawal : FeeType |
| 73 | + { |
| 74 | + /// <summary> |
| 75 | + /// Gets the fee associated with the transaction. |
| 76 | + /// </summary> |
| 77 | + public Fee Fee { get; } |
| 78 | + /// <summary> |
| 79 | + /// Initializes a new instance of the <see cref="StakeWithdrawal"/> class with the specified fee. |
| 80 | + /// </summary> |
| 81 | + /// <param name="fee">The fee associated with the stake withdrawal. This value cannot be null.</param> |
| 82 | + public StakeWithdrawal(Fee fee) => Fee = fee; |
| 83 | + } |
| 84 | + |
| 85 | + /// <summary> |
| 86 | + /// Represents a deposit fee type specific to Solana transactions. |
| 87 | + /// </summary> |
| 88 | + /// <remarks>This class encapsulates the fee information for a Solana deposit transaction. It |
| 89 | + /// inherits from the <see cref="FeeType"/> base class.</remarks> |
| 90 | + public class SolDeposit : FeeType |
| 91 | + { |
| 92 | + /// <summary> |
| 93 | + /// Gets the fee associated with the transaction. |
| 94 | + /// </summary> |
| 95 | + public Fee Fee { get; } |
| 96 | + /// <summary> |
| 97 | + /// Initializes a new instance of the <see cref="SolDeposit"/> class with the specified fee. |
| 98 | + /// </summary> |
| 99 | + /// <param name="fee">The fee associated with the deposit. This value cannot be null.</param> |
| 100 | + public SolDeposit(Fee fee) => Fee = fee; |
| 101 | + } |
| 102 | + |
| 103 | + /// <summary> |
| 104 | + /// Represents a deposit required for staking, associated with a specific fee. |
| 105 | + /// </summary> |
| 106 | + /// <remarks>This class encapsulates the concept of a staking deposit, which includes a fee that |
| 107 | + /// must be paid. It inherits from <see cref="FeeType"/>, providing additional context for fee-related |
| 108 | + /// operations.</remarks> |
| 109 | + public class StakeDeposit : FeeType |
| 110 | + { |
| 111 | + /// <summary> |
| 112 | + /// Gets the fee associated with the transaction. |
| 113 | + /// </summary> |
| 114 | + public Fee Fee { get; } |
| 115 | + /// <summary> |
| 116 | + /// Initializes a new instance of the <see cref="StakeDeposit"/> class with the specified fee. |
| 117 | + /// </summary> |
| 118 | + /// <param name="fee">The fee associated with the stake deposit. Cannot be null.</param> |
| 119 | + public StakeDeposit(Fee fee) => Fee = fee; |
| 120 | + } |
| 121 | + |
| 122 | + /// <summary> |
| 123 | + /// Represents a withdrawal operation for Solana (SOL) that includes an associated fee. |
| 124 | + /// </summary> |
| 125 | + /// <remarks>This class encapsulates the details of a Solana withdrawal, including the fee |
| 126 | + /// required for the transaction.</remarks> |
| 127 | + public class SolWithdrawal : FeeType |
| 128 | + { |
| 129 | + /// <summary> |
| 130 | + /// Gets the fee associated with the transaction. |
| 131 | + /// </summary> |
| 132 | + public Fee Fee { get; } |
| 133 | + /// <summary> |
| 134 | + /// Initializes a new instance of the <see cref="SolWithdrawal"/> class with the specified fee. |
| 135 | + /// </summary> |
| 136 | + /// <param name="fee">The fee associated with the withdrawal. This value cannot be null.</param> |
| 137 | + public SolWithdrawal(Fee fee) => Fee = fee; |
| 138 | + } |
| 139 | + |
| 140 | + /// <summary> |
| 141 | + /// Checks if the provided fee is too high. |
| 142 | + /// </summary> |
| 143 | + public bool IsTooHigh() |
| 144 | + { |
| 145 | + return this switch |
| 146 | + { |
| 147 | + SolReferral s => s.Percentage > 100, |
| 148 | + StakeReferral s => s.Percentage > 100, |
| 149 | + Epoch e => e.Fee.Numerator > e.Fee.Denominator, |
| 150 | + StakeWithdrawal s => s.Fee.Numerator > s.Fee.Denominator, |
| 151 | + SolWithdrawal s => s.Fee.Numerator > s.Fee.Denominator, |
| 152 | + SolDeposit s => s.Fee.Numerator > s.Fee.Denominator, |
| 153 | + StakeDeposit s => s.Fee.Numerator > s.Fee.Denominator, |
| 154 | + _ => false |
| 155 | + }; |
| 156 | + } |
| 157 | + |
| 158 | + /// <summary> |
| 159 | + /// Returns true if the contained fee can only be updated earliest on the next epoch. |
| 160 | + /// </summary> |
| 161 | + public bool CanOnlyChangeNextEpoch() |
| 162 | + { |
| 163 | + return this is StakeWithdrawal or SolWithdrawal or Epoch; |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments