Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-7967 Enenrgy WEB EVM/X #854

Merged
merged 14 commits into from
Oct 9, 2024
Merged
16 changes: 16 additions & 0 deletions BlockchainSdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@
DA71441E2795C2EA0052AFB4 /* SolanaNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA71441D2795C2EA0052AFB4 /* SolanaNetworkService.swift */; };
DA7C9A182C07B1C600C8C423 /* KoinosNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA7C9A172C07B1C600C8C423 /* KoinosNetworkService.swift */; };
DA7C9A1A2C07B30500C8C423 /* KoinosAccountInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA7C9A192C07B30500C8C423 /* KoinosAccountInfo.swift */; };
DA81B1BD2CA836AD00A78B6C /* EnergyWebChainExternalLinkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA81B1BC2CA836AD00A78B6C /* EnergyWebChainExternalLinkProvider.swift */; };
DA81B1C02CA84D8600A78B6C /* EnergyWebXExternalLinkProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA81B1BF2CA84D8600A78B6C /* EnergyWebXExternalLinkProvider.swift */; };
DA82433D27A2B06500CFC2C0 /* PolkadotJsonRpcProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA82433C27A2B06500CFC2C0 /* PolkadotJsonRpcProvider.swift */; };
DA82433F27A2B07800CFC2C0 /* PolkadotNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA82433E27A2B07800CFC2C0 /* PolkadotNetwork.swift */; };
DA82434127A2B0AD00CFC2C0 /* PolkadotTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA82434027A2B0AD00CFC2C0 /* PolkadotTarget.swift */; };
Expand Down Expand Up @@ -1494,6 +1496,8 @@
DA7C9A172C07B1C600C8C423 /* KoinosNetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KoinosNetworkService.swift; sourceTree = "<group>"; };
DA7C9A192C07B30500C8C423 /* KoinosAccountInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KoinosAccountInfo.swift; sourceTree = "<group>"; };
DA7CA47527AD4BD90041B1A1 /* PolkadotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolkadotTests.swift; sourceTree = "<group>"; };
DA81B1BC2CA836AD00A78B6C /* EnergyWebChainExternalLinkProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnergyWebChainExternalLinkProvider.swift; sourceTree = "<group>"; };
DA81B1BF2CA84D8600A78B6C /* EnergyWebXExternalLinkProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnergyWebXExternalLinkProvider.swift; sourceTree = "<group>"; };
DA82433C27A2B06500CFC2C0 /* PolkadotJsonRpcProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolkadotJsonRpcProvider.swift; sourceTree = "<group>"; };
DA82433E27A2B07800CFC2C0 /* PolkadotNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolkadotNetwork.swift; sourceTree = "<group>"; };
DA82434027A2B0AD00CFC2C0 /* PolkadotTarget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolkadotTarget.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2351,6 +2355,7 @@
DACAAB4F2BE8BA8A0039ED3D /* Koinos */,
DA1BA9A52C454AEE006F6839 /* Mantle */,
DA15D1E82C7782F300FD733B /* Filecoin */,
DA81B1BE2CA84D7800A78B6C /* EnergyWebX */,
);
path = Blockchains;
sourceTree = "<group>";
Expand Down Expand Up @@ -3638,6 +3643,14 @@
path = Model;
sourceTree = "<group>";
};
DA81B1BE2CA84D7800A78B6C /* EnergyWebX */ = {
isa = PBXGroup;
children = (
DA81B1BF2CA84D8600A78B6C /* EnergyWebXExternalLinkProvider.swift */,
);
path = EnergyWebX;
sourceTree = "<group>";
};
DA9F76E727EC8AD900F0665C /* Tron */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3848,6 +3861,7 @@
B63E63072BC5CD470086F04F /* BaseExternalLinkProvider.swift */,
DA02C7AB2C61016A0086718D /* BlastExternalLinkProvider.swift */,
1CF315322C39B5B0004EF522 /* CyberExternalLinkProvider.swift */,
DA81B1BC2CA836AD00A78B6C /* EnergyWebChainExternalLinkProvider.swift */,
);
path = OtherChains;
sourceTree = "<group>";
Expand Down Expand Up @@ -4896,6 +4910,7 @@
5D54FE1A23E41E5A009FAC2F /* LitecoinNetworkParams.swift in Sources */,
B6B2EB6B2B56A830005FBE8E /* VeChainNetworkParams.ContractCall.swift in Sources */,
5D31EA2F27DA1C910031DBEB /* DetailedError.swift in Sources */,
DA81B1C02CA84D8600A78B6C /* EnergyWebXExternalLinkProvider.swift in Sources */,
DA9F76EC27EC9A2900F0665C /* TronWalletManager.swift in Sources */,
DC5E652D2B1650F400E81AA5 /* OP_VERIFY.swift in Sources */,
2DDE5BA029C4F8D200A5B708 /* BlockBookProviderType.swift in Sources */,
Expand Down Expand Up @@ -5402,6 +5417,7 @@
DACAAB512BE8BAC20039ED3D /* KoinosWalletAssembly.swift in Sources */,
DC3C73912C2EF46E00B33990 /* EthereumModels.swift in Sources */,
2DDEFBC52B59B36A00885675 /* AlgorandTransactionParams.swift in Sources */,
DA81B1BD2CA836AD00A78B6C /* EnergyWebChainExternalLinkProvider.swift in Sources */,
2D24F5B22B6D2C6500D502A0 /* AptosTransactionInfo.swift in Sources */,
DC5E65102B1650F400E81AA5 /* OP_2SWAP.swift in Sources */,
B04E8D5025F8F67F00821CBE /* RosettaNetworkProvider.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// EnergyWebXExternalLinkProvider.swift
// BlockchainSdk
//
// Created by Aleksei Muraveinik on 28.9.24..
// Copyright © 2024 Tangem AG. All rights reserved.
//

import Foundation

struct EnergyWebXExternalLinkProvider {
private let baseExplorerUrl: String

init(isTestnet: Bool) {
baseExplorerUrl = isTestnet
? "https://energywebx-testnet.subscan.io"
: "https://energywebx.subscan.io"
}
}

extension EnergyWebXExternalLinkProvider: ExternalLinkProvider {
var testnetFaucetURL: URL? {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в целом у нас в приле это сейчас не поддерживается, запланируем выпил

nil
}

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

func url(transaction hash: String) -> URL? {
URL(string: "\(baseExplorerUrl)/extrinsic/\(hash)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private extension EthereumTarget {
return AnyEncodable([AnyEncodable(params), AnyEncodable("latest")])
case .feeHistory:
// Get fee history for 5 blocks (around a minute) with 25,50,75 percentiles (selected empirically)
return AnyEncodable([AnyEncodable(5), AnyEncodable("latest"), AnyEncodable([25,50,75])])
return AnyEncodable([AnyEncodable("0x5"), AnyEncodable("latest"), AnyEncodable([25,50,75])])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пришлось тут добавить так, потому что у меня запрос фи хистори для EWC падал

🟠 12:17:45:563: Response: https://energy-web-chain.rpc.thirdweb.com/
🟠 12:17:45:563: body:

{
  "jsonrpc": "2.0",
  "error": {
    "message": "Invalid params: invalid type: integer 5, expected a 0x-prefixed hex string with length between (0; 64].",
    "code": -32602
  },
  "id": 25
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Откатил. По видимому разные сети по разному обрабатывают.

@tureck1y Вроде нам же этот запрос не нужен здесь, т.к. можно пренебречь что он будет падать для EWC?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да, допиши плиз этот коммент напротив тоггла eip1559 у этой сети. Что в целом присылает нули и вот этот момент с энкодингом

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// EnergyWebChainExternalLinkProvider.swift
// BlockchainSdk
//
// Created by Aleksei Muraveinik on 28.9.24..
// Copyright © 2024 Tangem AG. All rights reserved.
//

import Foundation

struct EnergyWebChainExternalLinkProvider {
private let baseExplorerUrl: String

init(isTestnet: Bool) {
baseExplorerUrl = isTestnet
? "https://volta-explorer.energyweb.org"
: "https://explorer.energyweb.org"
}
}

extension EnergyWebChainExternalLinkProvider: ExternalLinkProvider {
var testnetFaucetURL: URL? {
URL(string: "https://voltafaucet.energyweb.org")
}

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

func url(transaction hash: String) -> URL? {
URL(string: "\(baseExplorerUrl)/tx/\(hash)")
}
}
9 changes: 8 additions & 1 deletion BlockchainSdk/Blockchains/Polkadot/PolkadotNetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ enum PolkadotNetwork {
case joystream(curve: EllipticCurve)
/// Bittensor blockchain
case bittensor(curve: EllipticCurve)
/// Energy Web X blockchain
case energyWebX(curve: EllipticCurve)

init?(blockchain: Blockchain) {
switch blockchain {
Expand All @@ -35,6 +37,8 @@ enum PolkadotNetwork {
self = .joystream(curve: curve)
case .bittensor(let curve):
self = .bittensor(curve: curve)
case .energyWebX(let curve):
self = .energyWebX(curve: curve)
default:
return nil
}
Expand All @@ -47,7 +51,7 @@ enum PolkadotNetwork {
return 0
case .kusama:
return 2
case .westend, .azero, .bittensor:
case .westend, .azero, .bittensor, .energyWebX:
return 42
case .joystream:
return 126
Expand Down Expand Up @@ -78,6 +82,9 @@ extension PolkadotNetwork {
return Amount(with: .joystream(curve: curve), value: Decimal(stringValue: "0.026666656")!)
case .bittensor(let curve):
return Amount(with: .bittensor(curve: curve), value: Decimal(stringValue: "0.0000005")!)
case .energyWebX(let curve):
let blockchain = Blockchain.energyWebX(curve: curve)
return Amount(with: blockchain, value: blockchain.minimumValue)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PolkadotTransactionBuilder {
*/
private var balanceTransferCallIndex: Data {
switch network {
case .polkadot, .azero, .joystream, .bittensor:
case .polkadot, .azero, .joystream, .bittensor, .energyWebX: // TODO: [Energy Web X] Questionable
return Data(hexString: "0x0500")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для joystream и bittensor просто брал польковскую, экспериментальным путем проверялось, если транзакции ходят - все ок

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По идее у всех парачейнов польки будет это значение

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно попробовать отправить транзакцию обязательно

case .kusama:
return Data(hexString: "0x0400")
Expand Down Expand Up @@ -126,7 +126,7 @@ class PolkadotTransactionBuilder {
return specVersion < 28
case .kusama:
return specVersion < 2028
case .westend, .azero, .bittensor:
case .westend, .azero, .bittensor, .energyWebX: // TODO: [Energy Web X] Questionable
return false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут тоже экспериментальным путем подбиралось значение

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

допиши плиз в код комменты про экспериментальный подбор тут и в других аналогичных местах

case .joystream:
// specVersion at the moment of initial implementation is '2003'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ struct SubstrateRuntimeVersionProvider {
// 198 is from the first user report
return meta.specVersion >= 198 ? .v15 : .v14
case .azero,
.joystream:
.joystream,
.energyWebX: // TODO: [Energy Web X] Questionable
return .v14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут мы обновляли через баг, потому что непонятно, опять же отправить транзакцию нужно, с неправильным спеком не пройдет

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ставим тут v15?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оставил 14, транзакция ушла

}
}
Expand Down
6 changes: 5 additions & 1 deletion BlockchainSdk/Common/API/TestnetAPINodeInfoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,15 @@ struct TestnetAPINodeInfoProvider {
return [
.init(url: URL(string: "https://api-tn10.kaspa.org")!)
]
case .energyWebEVM:
return [
.init(url: URL(string: "https://73799.rpc.thirdweb.com")!)
]
// TODO: Refactor in IOS-6639
case .bitcoin, .litecoin, .disChain, .rsk, .bitcoinCash, .binance, .cardano,
.xrp, .ducatus, .tezos, .dogecoin, .solana, .kusama, .dash, .gnosis,
.terraV1, .terraV2, .cronos, .octa, .playa3ullGames, .radiant, .joystream,
.bittensor, .internetComputer, .filecoin:
.bittensor, .internetComputer, .filecoin, .energyWebX:
return nil
}
}
Expand Down
4 changes: 3 additions & 1 deletion BlockchainSdk/Common/Address/AddressTypesConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ struct AddressTypesConfig {
.blast,
.sui,
.filecoin,
.sei:
.sei,
.energyWebEVM,
.energyWebX:
return [.default]
}
}
Expand Down
Loading