Skip to content

Commit

Permalink
ETH-975 - fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardmaximovich committed Feb 19, 2024
1 parent 53549ea commit 2260f87
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.CancellationException
import org.p2p.core.token.Token
import org.p2p.core.utils.formatTokenWithSymbol
import org.p2p.core.utils.fromLamports
import org.p2p.core.utils.orZero
import org.p2p.core.utils.toLamports
import org.p2p.core.utils.toUsd
import org.p2p.solanaj.kits.AccountInfoTokenExtensionConfig.Companion.interestBearingConfig
Expand Down Expand Up @@ -73,7 +74,7 @@ class SendFeeRelayerManager(
return this.transferFeeConfig
?.getActualTransferFee(currentSolanaEpoch)
?.transferFeePercent
?: BigDecimal.ZERO
.orZero()
}

suspend fun initialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CalculateSendFeesUseCase(
}

/**
* this is special case, because if we have fee payer token the same as source token
* this is a special case, because if we have fee payer token the same as source token
* we have to be very precise with amounts we use
* since the math is calculated manually when "max" button is pressed
* transaction will fail if account creation fee in token has incorrect value (rates in usd I guess)
Expand All @@ -100,17 +100,17 @@ class CalculateSendFeesUseCase(
sourceToken: Token.Active,
feePayerToken: Token.Active
): BigInteger {
return if (!sourceToken.isSOL && sourceToken.mintAddress == feePayerToken.mintAddress) {
sendServiceRepository
.getTokenRentExemption(
userWallet = sourceToken.publicKey.toBase58Instance(),
token = sourceToken,
// return in TOKEN
returnInToken = true
)
} else {
BigInteger.ZERO
if (sourceToken.isSOL || sourceToken.mintAddress != feePayerToken.mintAddress) {
return BigInteger.ZERO
}

return sendServiceRepository
.getTokenRentExemption(
userWallet = sourceToken.publicKey.toBase58Instance(),
token = sourceToken,
// return in TOKEN
returnInToken = true
)
}

/**
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/org/p2p/wallet/send/model/SendSolanaFee.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ data class SendSolanaFee constructor(
sourceTokenTotal: BigInteger,
inputAmount: BigInteger
): FeePayerState {
// don't do anything if amount is not entered or it is zero
if (inputAmount.isZero()) {
return KeepSame
}

val feePayerTokenCanCoverExpenses = feePayerToken.totalInLamports >= feeRelayerFee.totalInFeePayerToken
val feePayerIsSourceToken = feePayerSymbol == sourceTokenSymbol
val isNotSourceSol = sourceTokenSymbol != SOL_SYMBOL
Expand Down Expand Up @@ -204,6 +199,11 @@ data class SendSolanaFee constructor(
}
)
return when {
// don't do anything if amount is not entered or it is zero
inputAmount.isZero() -> {
Timber.i("FeePayer: input amount is zero")
KeepSame
}
feePayerTokenCanCoverExpenses && !feePayerIsSourceToken && !shouldTryReduceAmount -> {
Timber.i("FeePayer: keep the same fee payer token")
KeepSame
Expand All @@ -213,7 +213,7 @@ data class SendSolanaFee constructor(
SwitchToSpl(sourceToken)
}
hasAlternativeFeePayerTokens && !shouldTryReduceAmount -> {
Timber.i("FeePayer: switch to max by balance alternative token")
Timber.i("FeePayer: switch to a token with highest USD balance")
SwitchToSpl(alternativeFeePayerTokens.maxBy { it.totalInUsd.orZero() })
}
// if there is not enough SPL token balance to cover amount and fee, then try to reduce input amount
Expand Down

0 comments on commit 2260f87

Please sign in to comment.