Skip to content

Commit

Permalink
Merge pull request #68 from tonkeeper/staking_fix
Browse files Browse the repository at this point in the history
Staking fix
  • Loading branch information
polstianka committed Sep 2, 2024
2 parents 8282498 + 34a000d commit 65db73d
Show file tree
Hide file tree
Showing 312 changed files with 1,306 additions and 547 deletions.
7 changes: 1 addition & 6 deletions apps/wallet/api/src/main/java/com/tonapps/wallet/api/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,7 @@ class API(
.addInterceptor(AcceptLanguageInterceptor(context.locale))
.addInterceptor(AuthorizationInterceptor.bearer(
token = tonApiV2Key,
allowDomains = allowDomains,
ignorePaths = listOf(
"/v1/internal/pushes/tonconnect",
"/v1/internal/pushes/plain/unsubscribe",
"/v1/internal/pushes/plain/subscribe"
)
allowDomains = allowDomains
)).build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ data class BalanceEntity(

companion object {

fun empty(accountId: String) = BalanceEntity(
fun empty(accountId: String) = create(accountId, Coins.ZERO)

fun create(accountId: String, value: Coins) = BalanceEntity(
token = TokenEntity.TON,
value = Coins.ZERO,
value = value,
walletAddress = accountId,
initializedAccount = false,
)
Expand Down

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.tonapps.wallet.data.core.entity

import android.os.Parcelable
import android.util.Log
import com.tonapps.blockchain.ton.TONOpCode
import com.tonapps.blockchain.ton.extensions.loadOpCode
import com.tonapps.blockchain.ton.extensions.safeParseCell
import com.tonapps.blockchain.ton.extensions.storeOpCode
import com.tonapps.blockchain.ton.extensions.toTlb
import kotlinx.parcelize.Parcelize
import org.json.JSONObject
Expand Down Expand Up @@ -49,13 +52,12 @@ data class RawMessageEntity(

private fun rebuildBodyWithCustomExcessesAccount(body: Cell, excessesAddress: AddrStd): Cell {
val slice = body.beginParse()
val opCode = slice.loadUInt32()
var builder = CellBuilder.beginCell()
return when (opCode.toInt()) {
val builder = CellBuilder.beginCell()
return when (slice.loadOpCode()) {
// stonfi swap
0x25938561 -> {
TONOpCode.STONFI_SWAP -> {
builder
.storeUInt(0x25938561, 32)
.storeOpCode(TONOpCode.STONFI_SWAP)
.storeTlb(MsgAddressInt, slice.loadTlb(AddrStd.tlbCodec()))
.storeTlb(Coins, slice.loadTlb(Coins.tlbCodec()))
.storeTlb(MsgAddressInt, slice.loadTlb(AddrStd.tlbCodec()))
Expand All @@ -72,9 +74,9 @@ data class RawMessageEntity(
builder.endCell()
}
// nft transfer
0x5fcc3d14 -> body
TONOpCode.NFT_TRANSFER -> body
// jetton transfer
0xf8a7ea5 -> body
TONOpCode.JETTON_TRANSFER -> body
else -> body
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tonapps.wallet.data.rates

import android.content.Context
import android.util.Log
import com.tonapps.icu.Coins
import com.tonapps.wallet.api.API
import com.tonapps.wallet.api.entity.TokenEntity
Expand All @@ -10,6 +11,8 @@ import com.tonapps.wallet.data.rates.entity.RateEntity
import com.tonapps.wallet.data.rates.entity.RatesEntity
import com.tonapps.wallet.data.rates.source.BlobDataSource
import io.tonapi.models.TokenRates
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.math.BigDecimal

class RatesRepository(
Expand All @@ -23,11 +26,11 @@ class RatesRepository(
return localDataSource.get(currency).filter(tokens)
}

suspend fun load(currency: WalletCurrency, token: String) {
fun load(currency: WalletCurrency, token: String) {
load(currency, mutableListOf(token))
}

private suspend fun load(currency: WalletCurrency, tokens: MutableList<String>) {
private fun load(currency: WalletCurrency, tokens: MutableList<String>) {
if (!tokens.contains(TokenEntity.TON.address)) {
tokens.add(TokenEntity.TON.address)
}
Expand Down Expand Up @@ -57,11 +60,28 @@ class RatesRepository(
localDataSource.add(currency, entities)
}

fun getRates(currency: WalletCurrency, token: String): RatesEntity {
private fun getCachedRates(currency: WalletCurrency, tokens: List<String>): RatesEntity {
return localDataSource.get(currency).filter(tokens)
}

suspend fun getRates(currency: WalletCurrency, token: String): RatesEntity {
return getRates(currency, listOf(token))
}

fun getRates(currency: WalletCurrency, tokens: List<String>): RatesEntity {
return localDataSource.get(currency).filter(tokens)
suspend fun getTONRates(currency: WalletCurrency): RatesEntity {
return getRates(currency, TokenEntity.TON.address)
}

suspend fun getRates(
currency: WalletCurrency,
tokens: List<String>
): RatesEntity = withContext(Dispatchers.IO) {
val rates = getCachedRates(currency, tokens)
if (rates.hasTokens(tokens)) {
rates
} else {
load(currency, tokens.toMutableList())
getCachedRates(currency, tokens)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class RatesEntity(
): Parcelable {

companion object {

fun empty(currency: WalletCurrency): RatesEntity {
return RatesEntity(currency, hashMapOf())
}
Expand All @@ -25,6 +26,19 @@ data class RatesEntity(
private val isUSD: Boolean
get() = currency.code == "USD"

fun hasToken(token: String): Boolean {
return map.containsKey(token)
}

fun hasTokens(tokens: List<String>): Boolean {
for (token in tokens) {
if (!hasToken(token)) {
return false
}
}
return true
}

fun merge(rates: List<RateEntity>): RatesEntity {
val newMap = map.toMutableMap()
for (rate in rates) {
Expand Down Expand Up @@ -54,6 +68,10 @@ data class RatesEntity(
return rate(token)?.diff
}

fun convertTON(value: Coins): Coins {
return convert(TokenEntity.TON.address, value)
}

fun convert(token: String, value: Coins): Coins {
if (currency.code == token) {
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package com.tonapps.wallet.data.settings.folder

import android.content.Context
import android.content.SharedPreferences
import android.util.Log
import com.tonapps.extensions.MutableEffectFlow
import com.tonapps.extensions.getByteArray
import com.tonapps.extensions.getIntArray
import com.tonapps.extensions.putIntArray
import com.tonapps.extensions.state
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.shareIn

internal abstract class BaseSettingsFolder(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tonapps.wallet.data.staking

import kotlinx.coroutines.flow.Flow
import com.tonapps.blockchain.ton.TONOpCode
import com.tonapps.blockchain.ton.extensions.storeOpCode
import org.ton.block.AddrStd
import org.ton.block.Coins
import org.ton.cell.Cell
Expand Down Expand Up @@ -40,7 +41,7 @@ object StakingUtils {
queryId: BigInteger
): Cell {
return buildCell {
storeUInt(3665837821, 32)
storeOpCode(TONOpCode.WHALES_DEPOSIT)
storeUInt(queryId, 64)
storeTlb(Coins, Coins.ofNano(100000))
}
Expand All @@ -51,7 +52,7 @@ object StakingUtils {
amount: Coins
): Cell {
return buildCell {
storeUInt(3665837821, 32)
storeOpCode(TONOpCode.WHALES_WITHDRAW)
storeUInt(queryId, 64)
storeTlb(Coins, Coins.ofNano(100000))
storeTlb(Coins, amount)
Expand All @@ -60,7 +61,7 @@ object StakingUtils {

fun createLiquidTfAddStakeCommand(queryId: BigInteger): Cell {
return buildCell {
storeUInt(0x47d54391, 32)
storeOpCode(TONOpCode.LIQUID_TF_DEPOSIT)
storeUInt(queryId, 64)
storeUInt(0x000000000005b7ce, 64)
}
Expand All @@ -77,7 +78,7 @@ object StakingUtils {
}

return buildCell {
storeUInt(0x595f07bc, 32)
storeOpCode(TONOpCode.LIQUID_TF_BURN)
storeUInt(queryId, 64)
storeTlb(Coins, amount)
storeTlb(AddrStd, address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ data class PoolEntity(
val liquidJettonMaster: String?
): Parcelable {

val isTonstakers: Boolean
get() = implementation == StakingPool.Implementation.LiquidTF

constructor(
info: PoolInfo
): this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tonapps.wallet.data.staking.entities
import android.os.Parcelable
import com.tonapps.icu.Coins
import com.tonapps.wallet.data.staking.StakingPool
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import java.math.BigDecimal
import java.math.RoundingMode
Expand All @@ -14,10 +15,11 @@ data class PoolInfoEntity(
val details: PoolDetailsEntity,
): Parcelable {

@IgnoredOnParcel
val apy = pools.maxOfOrNull { it.apy } ?: BigDecimal.ZERO

@IgnoredOnParcel
val minStake = pools.minOfOrNull { it.minStake } ?: Coins.ZERO
val apyPercent = apy.setScale(2, RoundingMode.DOWN).stripTrailingZeros()
val apyFormat = "APY ≈ ${apyPercent}%"

val name: String
get() = implementation.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class RemoteDataSource(
)
}

private suspend fun loadInfo(
private fun loadInfo(
accountId: String,
testnet: Boolean
): List<StakingInfoEntity> {
Expand All @@ -45,7 +45,7 @@ internal class RemoteDataSource(
return list.map { StakingInfoEntity(it) }
}

private suspend fun loadPools(
private fun loadPools(
accountId: String,
testnet: Boolean
): List<PoolInfoEntity> {
Expand Down
Loading

0 comments on commit 65db73d

Please sign in to comment.