From 84e3ad6c2bb155a0c991f531139353cff45ac79e Mon Sep 17 00:00:00 2001 From: NikolaiEmelianov Date: Fri, 13 Dec 2024 13:41:05 +0700 Subject: [PATCH] Vanar blockchain semi-support --- .../blockchain/blockchains/ethereum/Chain.kt | 2 ++ .../eip1559/EthereumLikeBlockchainExt.kt | 1 + .../providers/VanarChainProvidersBuilder.kt | 23 +++++++++++++++++++ .../tangem/blockchain/common/Blockchain.kt | 8 +++++++ .../blockchain/common/WalletManagerFactory.kt | 1 + .../address/EstimationFeeAddressFactory.kt | 1 + .../impl/EthereumLikeWalletManagerAssembly.kt | 1 + .../common/derivation/DerivationConfigV1.kt | 2 ++ .../common/derivation/DerivationConfigV2.kt | 2 ++ .../common/derivation/DerivationConfigV3.kt | 2 ++ .../ExternalLinkProviderFactory.kt | 1 + .../VanarChainExternalLinkProvider.kt | 23 +++++++++++++++++++ 12 files changed, 67 insertions(+) create mode 100644 blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/providers/VanarChainProvidersBuilder.kt create mode 100644 blockchain/src/main/java/com/tangem/blockchain/externallinkprovider/providers/VanarChainExternalLinkProvider.kt diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/Chain.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/Chain.kt index ef0744706..90b4e03f0 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/Chain.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/Chain.kt @@ -81,4 +81,6 @@ enum class Chain(val id: Int, val blockchain: Blockchain?) { Canxium(id = 3003, blockchain = Blockchain.Canxium), Chiliz(id = 88888, blockchain = Blockchain.Chiliz), ChilizTestnet(id = 88882, blockchain = Blockchain.ChilizTestnet), + VanarChain(id = 2040, blockchain = Blockchain.VanarChain), + VanarChainTestnet(id = 78600, blockchain = Blockchain.VanarChainTestnet), } diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/eip1559/EthereumLikeBlockchainExt.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/eip1559/EthereumLikeBlockchainExt.kt index ef4e95f1d..9e763d119 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/eip1559/EthereumLikeBlockchainExt.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/eip1559/EthereumLikeBlockchainExt.kt @@ -52,6 +52,7 @@ internal val Blockchain.isSupportEIP1559: Boolean Blockchain.Mantle, Blockchain.Xodex, Blockchain.Chiliz, + Blockchain.VanarChain, -> false else -> error("Don't forget about evm here") } diff --git a/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/providers/VanarChainProvidersBuilder.kt b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/providers/VanarChainProvidersBuilder.kt new file mode 100644 index 000000000..d3c80789c --- /dev/null +++ b/blockchain/src/main/java/com/tangem/blockchain/blockchains/ethereum/providers/VanarChainProvidersBuilder.kt @@ -0,0 +1,23 @@ +package com.tangem.blockchain.blockchains.ethereum.providers + +import com.tangem.blockchain.blockchains.ethereum.network.EthereumJsonRpcProvider +import com.tangem.blockchain.common.Blockchain +import com.tangem.blockchain.common.network.providers.NetworkProvidersBuilder +import com.tangem.blockchain.common.network.providers.ProviderType + +internal class VanarChainProvidersBuilder( + override val providerTypes: List, +) : NetworkProvidersBuilder() { + + override fun createProviders(blockchain: Blockchain): List { + return listOf( + EthereumJsonRpcProvider("https://rpc.vanarchain.com"), // FIXME: use config during full integration + ) + } + + override fun createTestnetProviders(blockchain: Blockchain): List { + return listOf( + EthereumJsonRpcProvider("https://rpc-vanguard.vanarchain.com"), + ) + } +} diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/Blockchain.kt b/blockchain/src/main/java/com/tangem/blockchain/common/Blockchain.kt index 1bbcfb53c..a3cb975eb 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/Blockchain.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/Blockchain.kt @@ -174,6 +174,8 @@ enum class Blockchain( Chiliz("chiliz", "CHZ", "Chiliz"), ChilizTestnet("chiliz/test", "CHZ", "Chiliz Spicy Testnet"), Clore("clore-ai", "CLORE", "Clore"), + VanarChain("vanar-chain", "VANRY", "Vanar Chain"), + VanarChainTestnet("vanar-chain/test", "VG", "Vanar Vanguard Testnet"), ; private val externalLinkProvider: ExternalLinkProvider by lazy { ExternalLinkProviderFactory.makeProvider(this) } @@ -273,6 +275,7 @@ enum class Blockchain( EnergyWebX, EnergyWebXTestnet, Core, CoreTestnet, Chiliz, ChilizTestnet, + VanarChain, VanarChainTestnet, Xodex, Canxium, -> 18 @@ -349,6 +352,7 @@ enum class Blockchain( EnergyWebChain, EnergyWebChainTestnet, Core, CoreTestnet, Chiliz, ChilizTestnet, + VanarChain, VanarChainTestnet, Xodex, Canxium, -> EthereumAddressService() @@ -481,6 +485,7 @@ enum class Blockchain( Casper, CasperTestnet -> CasperTestnet Core, CoreTestnet -> CoreTestnet Chiliz, ChilizTestnet -> ChilizTestnet + VanarChain, VanarChainTestnet -> VanarChainTestnet else -> null } } @@ -555,6 +560,7 @@ enum class Blockchain( Core, CoreTestnet, Casper, CasperTestnet, Chiliz, ChilizTestnet, + VanarChain, VanarChainTestnet, Xodex, Canxium, Clore, @@ -657,6 +663,8 @@ enum class Blockchain( Canxium -> Chain.Canxium.id Chiliz -> Chain.Chiliz.id ChilizTestnet -> Chain.ChilizTestnet.id + VanarChain -> Chain.VanarChain.id + VanarChainTestnet -> Chain.VanarChainTestnet.id else -> null } } diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/WalletManagerFactory.kt b/blockchain/src/main/java/com/tangem/blockchain/common/WalletManagerFactory.kt index 25ba1cfdc..40146a422 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/WalletManagerFactory.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/WalletManagerFactory.kt @@ -151,6 +151,7 @@ class WalletManagerFactory( Blockchain.EnergyWebChain, Blockchain.EnergyWebChainTestnet, Blockchain.Core, Blockchain.CoreTestnet, Blockchain.Chiliz, Blockchain.ChilizTestnet, + Blockchain.VanarChain, Blockchain.VanarChainTestnet, Blockchain.Xodex, Blockchain.Canxium, -> EthereumLikeWalletManagerAssembly diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/address/EstimationFeeAddressFactory.kt b/blockchain/src/main/java/com/tangem/blockchain/common/address/EstimationFeeAddressFactory.kt index 482dd726b..115748d75 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/address/EstimationFeeAddressFactory.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/address/EstimationFeeAddressFactory.kt @@ -90,6 +90,7 @@ class EstimationFeeAddressFactory { Blockchain.EnergyWebChain, Blockchain.EnergyWebChainTestnet, Blockchain.Core, Blockchain.CoreTestnet, Blockchain.Chiliz, Blockchain.ChilizTestnet, + Blockchain.VanarChain, Blockchain.VanarChainTestnet, Blockchain.Xodex, Blockchain.Canxium, -> "0x52bb4012854f808CF9BAbd855e44E506dAf6C077" diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/assembly/impl/EthereumLikeWalletManagerAssembly.kt b/blockchain/src/main/java/com/tangem/blockchain/common/assembly/impl/EthereumLikeWalletManagerAssembly.kt index 947e3fd40..cb6ec595d 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/assembly/impl/EthereumLikeWalletManagerAssembly.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/assembly/impl/EthereumLikeWalletManagerAssembly.kt @@ -69,6 +69,7 @@ internal object EthereumLikeWalletManagerAssembly : WalletManagerAssembly EnergyWebChainProvidersBuilder(providerTypes) Blockchain.Core, Blockchain.CoreTestnet -> CoreProvidersBuilder(providerTypes) Blockchain.Chiliz, Blockchain.ChilizTestnet -> ChilizProvidersBuilder(providerTypes) + Blockchain.VanarChain, Blockchain.VanarChainTestnet -> VanarChainProvidersBuilder(providerTypes) Blockchain.Xodex -> XodexProvidersBuilder(providerTypes) Blockchain.Canxium -> CanxiumProvidersBuilder(providerTypes) else -> error("Unsupported blockchain: $blockchain") diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV1.kt b/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV1.kt index 1b49ebc38..7448ade2e 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV1.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV1.kt @@ -62,6 +62,7 @@ object DerivationConfigV1 : DerivationConfig() { Blockchain.Cyber, Blockchain.Canxium, Blockchain.Chiliz, + Blockchain.VanarChain, Blockchain.Xodex, -> mapOf(AddressType.Default to DerivationPath("m/44'/60'/0'/0/0")) Blockchain.XDC -> mapOf(AddressType.Default to DerivationPath("m/44'/550'/0'/0/0")) @@ -151,6 +152,7 @@ object DerivationConfigV1 : DerivationConfig() { Blockchain.EnergyWebChainTestnet, Blockchain.CoreTestnet, Blockchain.ChilizTestnet, + Blockchain.VanarChainTestnet, -> mapOf(AddressType.Default to DerivationPath("m/44'/1'/0'/0/0")) Blockchain.Aptos, Blockchain.AptosTestnet, diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV2.kt b/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV2.kt index 4c761d7a0..76f49abb4 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV2.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV2.kt @@ -77,6 +77,7 @@ object DerivationConfigV2 : DerivationConfig() { Blockchain.Xodex, Blockchain.Canxium, Blockchain.Chiliz, + Blockchain.VanarChain, -> mapOf(AddressType.Default to DerivationPath("m/44'/60'/0'/0/0")) Blockchain.XDC -> mapOf(AddressType.Default to DerivationPath("m/44'/550'/0'/0/0")) Blockchain.Binance -> mapOf(AddressType.Default to DerivationPath("m/44'/714'/0'/0/0")) @@ -151,6 +152,7 @@ object DerivationConfigV2 : DerivationConfig() { Blockchain.EnergyWebChainTestnet, Blockchain.CoreTestnet, Blockchain.ChilizTestnet, + Blockchain.VanarChainTestnet, -> mapOf(AddressType.Default to DerivationPath("m/44'/1'/0'/0/0")) Blockchain.Aptos, Blockchain.AptosTestnet, diff --git a/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV3.kt b/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV3.kt index f9a9c641e..9f6334ba2 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV3.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/common/derivation/DerivationConfigV3.kt @@ -72,6 +72,7 @@ object DerivationConfigV3 : DerivationConfig() { Blockchain.Xodex, Blockchain.Canxium, Blockchain.Chiliz, + Blockchain.VanarChain, -> mapOf(AddressType.Default to DerivationPath("m/44'/60'/0'/0/0")) Blockchain.XDC -> mapOf(AddressType.Default to DerivationPath("m/44'/550'/0'/0/0")) Blockchain.EthereumClassic -> mapOf(AddressType.Default to DerivationPath("m/44'/61'/0'/0/0")) @@ -147,6 +148,7 @@ object DerivationConfigV3 : DerivationConfig() { Blockchain.EnergyWebChainTestnet, Blockchain.CoreTestnet, Blockchain.ChilizTestnet, + Blockchain.VanarChainTestnet, -> mapOf(AddressType.Default to DerivationPath("m/44'/1'/0'/0/0")) Blockchain.Aptos, Blockchain.AptosTestnet, diff --git a/blockchain/src/main/java/com/tangem/blockchain/externallinkprovider/ExternalLinkProviderFactory.kt b/blockchain/src/main/java/com/tangem/blockchain/externallinkprovider/ExternalLinkProviderFactory.kt index 16513b5c8..13e5d8e97 100644 --- a/blockchain/src/main/java/com/tangem/blockchain/externallinkprovider/ExternalLinkProviderFactory.kt +++ b/blockchain/src/main/java/com/tangem/blockchain/externallinkprovider/ExternalLinkProviderFactory.kt @@ -91,6 +91,7 @@ internal object ExternalLinkProviderFactory { Blockchain.Casper, Blockchain.CasperTestnet -> CasperExternalLinkProvider(isTestnet) Blockchain.Core, Blockchain.CoreTestnet -> CoreExternalLinkProvider(isTestnet) Blockchain.Chiliz, Blockchain.ChilizTestnet -> ChilizExternalLinkProvider(isTestnet) + Blockchain.VanarChain, Blockchain.VanarChainTestnet -> VanarChainExternalLinkProvider(isTestnet) Blockchain.Xodex -> XodexExternalLinkProvider() Blockchain.Canxium -> CanxiumExternalLinkProvider() Blockchain.Clore -> CloreExternalLinkProvider() diff --git a/blockchain/src/main/java/com/tangem/blockchain/externallinkprovider/providers/VanarChainExternalLinkProvider.kt b/blockchain/src/main/java/com/tangem/blockchain/externallinkprovider/providers/VanarChainExternalLinkProvider.kt new file mode 100644 index 000000000..e71fc6dc3 --- /dev/null +++ b/blockchain/src/main/java/com/tangem/blockchain/externallinkprovider/providers/VanarChainExternalLinkProvider.kt @@ -0,0 +1,23 @@ +package com.tangem.blockchain.externallinkprovider.providers + +import com.tangem.blockchain.externallinkprovider.ExternalLinkProvider +import com.tangem.blockchain.externallinkprovider.TxExploreState + +internal class VanarChainExternalLinkProvider(isTestnet: Boolean) : ExternalLinkProvider { + + override val explorerBaseUrl: String = if (isTestnet) { + "https://explorer-vanguard.vanarchain.com/" + } else { + "https://explorer.vanarchain.com/" + } + + override val testNetTopUpUrl: String = "https://faucet.vanarchain.com/" + + override fun explorerUrl(walletAddress: String, contractAddress: String?): String { + return "${explorerBaseUrl}address/$walletAddress" + } + + override fun getExplorerTxUrl(transactionHash: String): TxExploreState { + return TxExploreState.Url("${explorerBaseUrl}tx/$transactionHash") + } +}