Skip to content

Commit

Permalink
IOS-8962 Added Sonic EVM (#4523)
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseilobankov95 authored Jan 28, 2025
1 parent 228ce49 commit 44a70eb
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// SonicExternalLinkProvider.swift
// TangemApp
//
// Created by Aleksei Lobankov on 20.01.2025.
// Copyright © 2025 Tangem AG. All rights reserved.
//

struct SonicExternalLinkProvider: ExternalLinkProvider {
private let baseExplorerUrl: String

let testnetFaucetURL = URL(string: "https://testnet.soniclabs.com/account")

init(isTestnet: Bool) {
baseExplorerUrl = isTestnet
? "https://testnet.sonicscan.org"
: "https://sonicscan.org"
}

func url(address: String, contractAddress: String?) -> URL? {
URL(string: "\(baseExplorerUrl)/address/\(address)")
}

func url(transaction hash: String) -> URL? {
URL(string: "\(baseExplorerUrl)/tx/\(hash)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct NowNodesAPIKeysInfoProvider {
let apiKey: String
func apiKeys(for blockchain: Blockchain) -> APIHeaderKeyInfo? {
switch blockchain {
case .xrp, .tron, .algorand, .aptos, .solana, .odysseyChain:
case .xrp, .tron, .algorand, .aptos, .solana, .odysseyChain, .sonic:
return .init(
headerName: Constants.nowNodesApiKeyHeaderName,
headerValue: apiKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ struct NowNodesAPIResolver {
link = "https://xtz.nownodes.io/\(apiKey)"
case .odysseyChain:
link = "https://odyssey.nownodes.io/ext/bc/D/rpc"
case .sonic:
link = "https://ftm-sonic.nownodes.io"
default:
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions BlockchainSdk/Common/API/TestnetAPINodeInfoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ struct TestnetAPINodeInfoProvider {
return [
.init(url: URL(string: "https://curtis.rpc.caldera.xyz/http")!),
]
case .sonic:
return [
.init(url: URL(string: "https://sonic-blaze-rpc.publicnode.com")!),
]
// TODO: Refactor in IOS-6639
case .bitcoin, .litecoin, .disChain, .rsk, .bitcoinCash, .binance, .cardano,
.xrp, .ducatus, .tezos, .dogecoin, .solana, .kusama, .dash, .gnosis,
Expand Down
3 changes: 2 additions & 1 deletion BlockchainSdk/Common/Address/AddressTypesConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ struct AddressTypesConfig {
.fact0rn,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
return [.default]
}
}
Expand Down
23 changes: 20 additions & 3 deletions BlockchainSdk/Common/Blockchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public indirect enum Blockchain: Equatable, Hashable {
case odysseyChain(testnet: Bool)
case bitrock(testnet: Bool)
case apeChain(testnet: Bool)
case sonic(testnet: Bool)

public var isTestnet: Bool {
switch self {
Expand Down Expand Up @@ -147,7 +148,8 @@ public indirect enum Blockchain: Equatable, Hashable {
.chiliz(let testnet),
.odysseyChain(let testnet),
.bitrock(let testnet),
.apeChain(let testnet):
.apeChain(let testnet),
.sonic(let testnet):
return testnet
case .litecoin,
.ducatus,
Expand Down Expand Up @@ -324,7 +326,8 @@ public indirect enum Blockchain: Equatable, Hashable {
.xodex,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
return 18
case .cardano,
.xrp,
Expand Down Expand Up @@ -511,6 +514,8 @@ public indirect enum Blockchain: Equatable, Hashable {
return "BROCK"
case .apeChain:
return "APE"
case .sonic:
return "S"
}
}

Expand Down Expand Up @@ -597,6 +602,8 @@ public indirect enum Blockchain: Equatable, Hashable {
return "Bitrock" + testnetSuffix
case .apeChain:
return isTestnet ? "Curtis Testnet" : "ApeChain"
case .sonic:
return "Sonic" + (isTestnet ? " Blaze Testnet" : "")
default:
var name = "\(self)".capitalizingFirstLetter()
if let index = name.firstIndex(of: "(") {
Expand Down Expand Up @@ -857,6 +864,7 @@ public extension Blockchain {
case .odysseyChain: return isTestnet ? 131313 : 153153
case .bitrock: return isTestnet ? 7771 : 7171
case .apeChain: return isTestnet ? 33111 : 33139
case .sonic: return isTestnet ? 57054 : 146
default:
return nil
}
Expand Down Expand Up @@ -932,6 +940,7 @@ public extension Blockchain {
case .odysseyChain: return true
case .bitrock: return false // eth_feeHistory all zeroes
case .apeChain: return true
case .sonic: return true
default:
assertionFailure("Don't forget about evm here")
return false
Expand Down Expand Up @@ -1078,6 +1087,7 @@ extension Blockchain: Codable {
case .odysseyChain: return "dione"
case .bitrock: return "bitrock"
case .apeChain: return "apechain"
case .sonic: return "sonic"
}
}

Expand Down Expand Up @@ -1183,6 +1193,7 @@ extension Blockchain: Codable {
case "dione": self = .odysseyChain(testnet: isTestnet)
case "bitrock": self = .bitrock(testnet: isTestnet)
case "apechain": self = .apeChain(testnet: isTestnet)
case "sonic": self = .sonic(testnet: isTestnet)
default:
throw BlockchainSdkError.decodingFailed
}
Expand Down Expand Up @@ -1445,6 +1456,11 @@ private extension Blockchain {
case .network: return "apechain"
case .coin: return "apecoin"
}
case .sonic:
switch type {
case .network: return "sonic"
case .coin: return "sonic-3"
}
}
}

Expand Down Expand Up @@ -1505,7 +1521,8 @@ extension Blockchain {
.xodex,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
return EthereumWalletAssembly()
case .optimism,
.manta,
Expand Down
2 changes: 2 additions & 0 deletions BlockchainSdk/Common/Blockchain/Blockchain+AllCases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public extension Blockchain {
case .odysseyChain: break
case .bitrock: break
case .apeChain: break
case .sonic: break
// READ BELOW:
//
// Did you get a compilation error here? If so, add your new blockchain to the array below
Expand Down Expand Up @@ -183,6 +184,7 @@ public extension Blockchain {
.odysseyChain(testnet: false),
.bitrock(testnet: false),
.apeChain(testnet: false),
.sonic(testnet: false),
]
}
}
2 changes: 2 additions & 0 deletions BlockchainSdk/Common/Derivations/DerivationConfigV1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ struct DerivationConfigV1: DerivationConfig {
return "m/44'/695'/0'/0/0"
case .bitrock:
return "m/44'/7171666'/0'/0/0"
case .sonic:
return "m/44'/10007'/0'/0/0"
}
}
}
3 changes: 2 additions & 1 deletion BlockchainSdk/Common/Derivations/DerivationConfigV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ struct DerivationConfigV2: DerivationConfig {
.xodex,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
return "m/44'/60'/0'/0/0"
case .binance:
return "m/44'/714'/0'/0/0"
Expand Down
3 changes: 2 additions & 1 deletion BlockchainSdk/Common/Derivations/DerivationConfigV3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ struct DerivationConfigV3: DerivationConfig {
.xodex,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
return "m/44'/60'/0'/0/0"
case .ethereumClassic:
return "m/44'/61'/0'/0/0"
Expand Down
3 changes: 2 additions & 1 deletion BlockchainSdk/Common/Factories/AddressServiceFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public struct AddressServiceFactory {
.xodex,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
return EthereumAddressService()
case .rsk:
return RskAddressService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct EstimationFeeAddressFactory {
.zkSync, .moonbeam, .polygonZkEVM, .moonriver, .mantle,
.flare, .taraxa, .base, .blast, .cyber, .energyWebEVM,
.core, .canxium, .chiliz, .xodex, .odysseyChain, .bitrock,
.apeChain:
.apeChain, .sonic:
return "0x52bb4012854f808CF9BAbd855e44E506dAf6C077"
case .ethereumClassic:
return "0xc49722a6f4Fe5A1347710dEAAa1fafF4c275689b"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public struct ExternalLinkProviderFactory {
return BitrockExternalLinkProvider(isTestnet: isTestnet)
case .apeChain:
return ApeChainExternalLinkProvider(isTestnet: isTestnet)
case .sonic:
return SonicExternalLinkProvider(isTestnet: isTestnet)
}
}
}
3 changes: 2 additions & 1 deletion BlockchainSdk/Extensions/TWCoin+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ extension CoinType {
.fact0rn,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
// Blockchains that are not in WalletCore yet
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion BlockchainSdkTests/Extensions/TWPublicKeyType+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ extension PublicKeyType {
.chiliz,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
self = PublicKeyType.secp256k1Extended
case .stellar,
.ton,
Expand Down
2 changes: 2 additions & 0 deletions Tangem/App/Models/Config/SupportedBlockchains.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ struct SupportedBlockchains {
.bitrock(testnet: false),
.fact0rn,
.apeChain(testnet: false),
.sonic(testnet: false),
]
}

Expand Down Expand Up @@ -209,6 +210,7 @@ struct SupportedBlockchains {
.odysseyChain(testnet: true),
.bitrock(testnet: true),
.apeChain(testnet: true),
.sonic(testnet: true),
]
}

Expand Down
3 changes: 2 additions & 1 deletion Tangem/App/Services/ExchangeService/MercuryoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ private extension Blockchain {
.fact0rn,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
// Did you get a compilation error here? If so, check whether the network is supported at https://api.mercuryo.io/v1.6/lib/currencies
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions Tangem/App/Services/ExchangeService/MoonPayService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ private extension Blockchain {
case .odysseyChain: return nil
case .bitrock: return nil
case .apeChain: return nil
case .sonic: return nil
// Did you get a compilation error here? If so, check whether the network is supported at https://api.moonpay.com/v3/currencies
}
}
Expand Down Expand Up @@ -528,6 +529,7 @@ private extension Blockchain {
case .odysseyChain: return nil
case .bitrock: return nil
case .apeChain: return nil
case .sonic: return nil
// Did you get a compilation error here? If so, check whether the network is supported at https://api.moonpay.com/v3/currencies
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ struct CustomTokenContractAddressConverter {
.fact0rn,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
// Did you get a compilation error here? If so, check if the network supports multiple token contract address
// formats (as Hedera does, for example) and add the appropriate conversion logic here if needed
return originalAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ struct TokenInteractionAvailabilityProvider {
.fact0rn,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
// Checking that we have at least one valid (non-empty) address
//
// If necessary, add more specific conditions for newly added blockchains
Expand Down
3 changes: 2 additions & 1 deletion Tangem/Modules/Send/Services/TransactionParamsBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ struct TransactionParamsBuilder {
.fact0rn,
.odysseyChain,
.bitrock,
.apeChain:
.apeChain,
.sonic:
throw TransactionParamsBuilderError.extraIdNotSupported
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "sonic.fill.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "sonic.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
4 changes: 4 additions & 0 deletions TangemApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@
C21707172D395292000AC361 /* BitrockExternalLinkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C21707162D395290000AC361 /* BitrockExternalLinkProvider.swift */; };
C27A0EEE2D3648D400AC2336 /* OdysseyChainExternalLinkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C27A0EED2D3648D100AC2336 /* OdysseyChainExternalLinkProvider.swift */; };
C287C61D2D410D640068B899 /* ApeChainExternalLinkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C287C61C2D410D620068B899 /* ApeChainExternalLinkProvider.swift */; };
C2DD0E042D3EBA3200B45935 /* SonicExternalLinkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2DD0E032D3EBA3000B45935 /* SonicExternalLinkProvider.swift */; };
DA070DE22ADD4F0F00F7C0E4 /* SprinklrSupportChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA070DE02ADD4F0F00F7C0E4 /* SprinklrSupportChatView.swift */; };
DA070DE32ADD4F0F00F7C0E4 /* SprinklrSupportChatViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA070DE12ADD4F0F00F7C0E4 /* SprinklrSupportChatViewModel.swift */; };
DA070DE52ADD4F6600F7C0E4 /* SprinklrConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA070DE42ADD4F6500F7C0E4 /* SprinklrConfig.swift */; };
Expand Down Expand Up @@ -5158,6 +5159,7 @@
C21707162D395290000AC361 /* BitrockExternalLinkProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitrockExternalLinkProvider.swift; sourceTree = "<group>"; };
C27A0EED2D3648D100AC2336 /* OdysseyChainExternalLinkProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OdysseyChainExternalLinkProvider.swift; sourceTree = "<group>"; };
C287C61C2D410D620068B899 /* ApeChainExternalLinkProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApeChainExternalLinkProvider.swift; sourceTree = "<group>"; };
C2DD0E032D3EBA3000B45935 /* SonicExternalLinkProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SonicExternalLinkProvider.swift; sourceTree = "<group>"; };
DA070DE02ADD4F0F00F7C0E4 /* SprinklrSupportChatView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SprinklrSupportChatView.swift; sourceTree = "<group>"; };
DA070DE12ADD4F0F00F7C0E4 /* SprinklrSupportChatViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SprinklrSupportChatViewModel.swift; sourceTree = "<group>"; };
DA070DE42ADD4F6500F7C0E4 /* SprinklrConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SprinklrConfig.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -10118,6 +10120,7 @@
isa = PBXGroup;
children = (
C287C61C2D410D620068B899 /* ApeChainExternalLinkProvider.swift */,
C2DD0E032D3EBA3000B45935 /* SonicExternalLinkProvider.swift */,
C27A0EED2D3648D100AC2336 /* OdysseyChainExternalLinkProvider.swift */,
C21707162D395290000AC361 /* BitrockExternalLinkProvider.swift */,
DC77F2562CD63813001B2929 /* CanxiumExternalLinkProvider.swift */,
Expand Down Expand Up @@ -19391,6 +19394,7 @@
B62D400C2CBC79DA00C2460E /* OP_SIZE.swift in Sources */,
B62D41C72CBC79DB00C2460E /* asset_issue_contract.pb.swift in Sources */,
B62D40AE2CBC79DA00C2460E /* FantomExternalLinkProvider.swift in Sources */,
C2DD0E042D3EBA3200B45935 /* SonicExternalLinkProvider.swift in Sources */,
B62D41B72CBC79DB00C2460E /* TONProvider.swift in Sources */,
B62D42382CBC79DB00C2460E /* ElectrumNetworkProvider.swift in Sources */,
B62D41D62CBC79DB00C2460E /* TronAPIResolver.swift in Sources */,
Expand Down

0 comments on commit 44a70eb

Please sign in to comment.