@@ -19,7 +19,6 @@ enum Solana {
1919
2020 static let lamportsPerSOL = Decimal ( SOLANA_LAMPORTS_PER_SOL)
2121 static let microLamportsPerLamport : Decimal = 1_000_000
22- static let accountCreationCost : Decimal = 0.002_039_28
2322 static let keyPairCount = 64
2423
2524 static func publicKey( seed: Data ) throws -> String {
@@ -172,8 +171,7 @@ extension Solana {
172171 priorityFee: PriorityFee ? ,
173172 token: Web3Token
174173 ) throws {
175- let isSendingSOL = token. chainID == ChainID . solana
176- && ( token. assetKey == Web3Token . AssetKey. sol || token. assetKey == Web3Token . AssetKey. wrappedSOL)
174+ let isSendingSOL = token. chainID == ChainID . solana && token. assetKey == Web3Token . AssetKey. sol
177175 let solanaPriorityFee : SolanaPriorityFee ? = if let fee = priorityFee {
178176 SolanaPriorityFee ( price: fee. unitPrice, limit: fee. unitLimit)
179177 } else {
@@ -261,3 +259,77 @@ extension Solana {
261259 }
262260
263261}
262+
263+ extension Solana {
264+
265+ enum RentExemptionFailedReason {
266+
267+ case reserveSOLForRent( Decimal )
268+ case sendSOLForRent( Decimal )
269+ case insufficientSOL( requiredAmount: Decimal )
270+
271+ var localizedDescription : String {
272+ switch self {
273+ case . reserveSOLForRent( let amount) :
274+ R . string. localizable. reserve_sol_for_rent (
275+ CurrencyFormatter . localizedString (
276+ from: amount,
277+ format: . precision,
278+ sign: . never
279+ )
280+ )
281+ case . sendSOLForRent( let amount) :
282+ R . string. localizable. send_sol_for_rent (
283+ CurrencyFormatter . localizedString (
284+ from: amount,
285+ format: . precision,
286+ sign: . never
287+ )
288+ )
289+ case . insufficientSOL( let requiredAmount) :
290+ R . string. localizable. insufficient_sol_for_sending_spl_token (
291+ CurrencyFormatter . localizedString (
292+ from: requiredAmount,
293+ format: . precision,
294+ sign: . never
295+ )
296+ )
297+ }
298+ }
299+
300+ }
301+
302+ enum RentExemptionValue {
303+ static let systemAccount : Decimal = 0.00089088
304+ static let tokenAccount : Decimal = 0.00203928
305+ }
306+
307+ static func checkRentExemptionForSOLTransfer(
308+ sendingAmount: Decimal ,
309+ feeAmount: Decimal ,
310+ senderSOLBalance: Decimal ,
311+ receiverAccountExists: Bool
312+ ) -> RentExemptionFailedReason ? {
313+ if senderSOLBalance - sendingAmount - feeAmount < RentExemptionValue . systemAccount {
314+ . reserveSOLForRent( RentExemptionValue . systemAccount)
315+ } else if !receiverAccountExists && sendingAmount < RentExemptionValue . tokenAccount {
316+ . sendSOLForRent( RentExemptionValue . tokenAccount)
317+ } else {
318+ nil
319+ }
320+ }
321+
322+ static func checkRentExemptionForSPLTokenTransfer(
323+ senderSOLBalance: Decimal ,
324+ feeAmount: Decimal ,
325+ receiverAccountExists: Bool
326+ ) -> RentExemptionFailedReason ? {
327+ let minBalance = RentExemptionValue . systemAccount + RentExemptionValue. tokenAccount + feeAmount
328+ if receiverAccountExists || senderSOLBalance >= minBalance {
329+ return nil
330+ } else {
331+ return . insufficientSOL( requiredAmount: minBalance)
332+ }
333+ }
334+
335+ }
0 commit comments