Updated on 2026-08-14
This commit is contained in:
parent
10171a3b3e
commit
ecf8e5fc96
19 changed files with 125 additions and 55 deletions
|
|
@ -1,5 +1,6 @@
|
|||
plugins {
|
||||
alias(deps.plugins.kotlin.jvm)
|
||||
alias(deps.plugins.kotlin.serialization)
|
||||
id("configuration")
|
||||
}
|
||||
|
||||
|
|
@ -7,4 +8,6 @@ dependencies {
|
|||
api(deps.kotlin.coroutines)
|
||||
api(deps.arrow.core)
|
||||
api(deps.arrow.fx)
|
||||
|
||||
implementation(deps.kotlin.serialization)
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.tangem.domain.core.serialization
|
||||
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import java.math.BigDecimal
|
||||
|
||||
internal object BigDecimalSerializer : KSerializer<BigDecimal> {
|
||||
|
||||
override val descriptor = PrimitiveSerialDescriptor(serialName = "BigDecimal", PrimitiveKind.STRING)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: BigDecimal) {
|
||||
encoder.encodeString(value.toString())
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): BigDecimal {
|
||||
return BigDecimal(decoder.decodeString())
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package com.tangem.domain.core.serialization
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.math.BigDecimal
|
||||
|
||||
typealias SerializedBigDecimal = @Serializable(with = BigDecimalSerializer::class) BigDecimal
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
plugins {
|
||||
alias(deps.plugins.android.library)
|
||||
alias(deps.plugins.kotlin.android)
|
||||
alias(deps.plugins.kotlin.serialization)
|
||||
id("configuration")
|
||||
}
|
||||
|
||||
|
|
@ -10,10 +11,10 @@ android {
|
|||
|
||||
|
||||
dependencies {
|
||||
implementation(deps.kotlin.coroutines)
|
||||
implementation(deps.arrow.core)
|
||||
implementation(deps.kotlin.serialization)
|
||||
api(projects.domain.staking.models)
|
||||
|
||||
api(projects.domain.core)
|
||||
implementation(deps.kotlin.serialization)
|
||||
|
||||
implementation(projects.domain.tokens.models)
|
||||
}
|
||||
1
domain/staking/models/.gitignore
vendored
Normal file
1
domain/staking/models/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
11
domain/staking/models/build.gradle.kts
Normal file
11
domain/staking/models/build.gradle.kts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
plugins {
|
||||
alias(deps.plugins.kotlin.jvm)
|
||||
alias(deps.plugins.kotlin.serialization)
|
||||
id("configuration")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.domain.core)
|
||||
|
||||
implementation(deps.kotlin.serialization)
|
||||
}
|
||||
|
|
@ -1,54 +1,64 @@
|
|||
package com.tangem.domain.staking.model
|
||||
|
||||
import java.io.Serializable
|
||||
import java.math.BigDecimal
|
||||
import com.tangem.domain.core.serialization.SerializedBigDecimal
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Yield(
|
||||
val id: String,
|
||||
val token: Token,
|
||||
val tokens: List<Token>,
|
||||
val args: Args,
|
||||
val status: Status,
|
||||
val apy: BigDecimal,
|
||||
val apy: SerializedBigDecimal,
|
||||
val rewardRate: Double,
|
||||
val rewardType: RewardType,
|
||||
val metadata: Metadata,
|
||||
val validators: List<Validator>,
|
||||
val isAvailable: Boolean,
|
||||
) : Serializable {
|
||||
) {
|
||||
|
||||
@Serializable
|
||||
data class Status(
|
||||
val enter: Boolean,
|
||||
val exit: Boolean?,
|
||||
) : Serializable
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Args(
|
||||
val enter: Enter,
|
||||
val exit: Enter?,
|
||||
) : Serializable {
|
||||
) {
|
||||
|
||||
@Serializable
|
||||
data class Enter(
|
||||
val addresses: Addresses,
|
||||
val args: Map<String, AddressArgument>,
|
||||
) : Serializable {
|
||||
) {
|
||||
|
||||
@Serializable
|
||||
data class Addresses(
|
||||
val address: AddressArgument,
|
||||
val additionalAddresses: Map<String, AddressArgument>? = null,
|
||||
) : Serializable
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Validator(
|
||||
val address: String,
|
||||
val status: String,
|
||||
val name: String,
|
||||
val image: String?,
|
||||
val website: String?,
|
||||
val apr: BigDecimal?,
|
||||
val apr: SerializedBigDecimal?,
|
||||
val commission: Double?,
|
||||
val stakedBalance: String?,
|
||||
val votingPower: Double?,
|
||||
val preferred: Boolean,
|
||||
) : Serializable
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Metadata(
|
||||
val name: String,
|
||||
val logoUri: String,
|
||||
|
|
@ -67,14 +77,17 @@ data class Yield(
|
|||
val supportsMultipleValidators: Boolean,
|
||||
val revshare: Enabled,
|
||||
val fee: Enabled,
|
||||
) : Serializable {
|
||||
) {
|
||||
|
||||
@Serializable
|
||||
data class Period(
|
||||
val days: Int,
|
||||
) : Serializable
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Enabled(
|
||||
val enabled: Boolean,
|
||||
) : Serializable
|
||||
)
|
||||
}
|
||||
|
||||
enum class RewardType {
|
||||
|
|
@ -84,6 +97,7 @@ data class Yield(
|
|||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Token(
|
||||
val name: String,
|
||||
val network: NetworkType,
|
||||
|
|
@ -93,7 +107,7 @@ data class Token(
|
|||
val coinGeckoId: String?,
|
||||
val logoURI: String?,
|
||||
val isPoints: Boolean?,
|
||||
) : Serializable {
|
||||
) {
|
||||
enum class NetworkType {
|
||||
AVALANCHE_C,
|
||||
AVALANCHE_ATOMIC,
|
||||
|
|
@ -165,9 +179,10 @@ data class Token(
|
|||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class AddressArgument(
|
||||
val required: Boolean,
|
||||
val network: String? = null,
|
||||
val minimum: Double? = null,
|
||||
val maximum: Double? = null,
|
||||
) : Serializable
|
||||
)
|
||||
|
|
@ -188,11 +188,11 @@ sealed class CryptoCurrency {
|
|||
return "ID(value='$value')"
|
||||
}
|
||||
|
||||
private companion object {
|
||||
companion object {
|
||||
// should use delimiters that could be used in URL not like path or query delimiters
|
||||
const val PREFIX_DELIMITER = '_'
|
||||
const val SUFFIX_DELIMITER = ';'
|
||||
const val DERIVATION_PATH_DELIMITER = 'd'
|
||||
private const val PREFIX_DELIMITER = '_'
|
||||
private const val SUFFIX_DELIMITER = ';'
|
||||
private const val DERIVATION_PATH_DELIMITER = 'd'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue