diff --git a/Examples/CocoaPods/Podfile b/Examples/CocoaPods/Podfile new file mode 100644 index 0000000..78e09d6 --- /dev/null +++ b/Examples/CocoaPods/Podfile @@ -0,0 +1,8 @@ +platform :ios, '13.0' +use_frameworks! + +install! 'cocoapods', :warn_for_unused_master_specs_repo => false + +target 'ZkSync2Example' do + pod 'web3swift-zksync', '2.6.5-zksync' +end \ No newline at end of file diff --git a/Examples/CocoaPods/ZkSync2Example/ContentView.swift b/Examples/CocoaPods/ZkSync2Example/ContentView.swift index a602c28..8e8ed70 100644 --- a/Examples/CocoaPods/ZkSync2Example/ContentView.swift +++ b/Examples/CocoaPods/ZkSync2Example/ContentView.swift @@ -6,6 +6,7 @@ // import SwiftUI +import web3swift_zksync struct ContentView: View { var body: some View { diff --git a/Examples/SPM/ZKSync2Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Examples/SPM/ZKSync2Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 2e587b8..860ee85 100644 --- a/Examples/SPM/ZKSync2Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Examples/SPM/ZKSync2Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -48,10 +48,10 @@ { "identity" : "web3swift", "kind" : "remoteSourceControl", - "location" : "https://github.com/MaximAlien/web3swift.git", + "location" : "https://github.com/zksync-sdk/web3swift.git", "state" : { - "branch" : "2.6.5-patch", - "revision" : "c69d93c7f85f9c0b7252271e2883af6e9f390388" + "revision" : "57f8ff9ecba69be2d21d4ebadc1197b5f0614064", + "version" : "2.6.5-zksync" } } ], diff --git a/Package.swift b/Package.swift index aafaff6..c6e9a6d 100644 --- a/Package.swift +++ b/Package.swift @@ -15,8 +15,8 @@ let package = Package( ], dependencies: [ .package( - url: "https://github.com/MaximAlien/web3swift.git", - branch: "2.6.5-patch" + url: "https://github.com/zksync-sdk/web3swift.git", + exact: "2.6.5-zksync" ), .package( url: "https://github.com/Alamofire/Alamofire.git", diff --git a/Sources/ZkSync2/Crypto/EIP712/EIP712Domain.swift b/Sources/ZkSync2/Crypto/EIP712/EIP712Domain.swift index 183cbde..a302b14 100644 --- a/Sources/ZkSync2/Crypto/EIP712/EIP712Domain.swift +++ b/Sources/ZkSync2/Crypto/EIP712/EIP712Domain.swift @@ -7,7 +7,11 @@ import Foundation import BigInt +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif public class EIP712Domain: Structurable { diff --git a/Sources/ZkSync2/Crypto/EIP712/EIP712Encoder.swift b/Sources/ZkSync2/Crypto/EIP712/EIP712Encoder.swift index d8fde6c..eaf2bc9 100644 --- a/Sources/ZkSync2/Crypto/EIP712/EIP712Encoder.swift +++ b/Sources/ZkSync2/Crypto/EIP712/EIP712Encoder.swift @@ -7,8 +7,12 @@ import Foundation import BigInt -import web3swift import CryptoSwift +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif class EIP712Encoder { diff --git a/Sources/ZkSync2/Crypto/EIP712/Structurable.swift b/Sources/ZkSync2/Crypto/EIP712/Structurable.swift index 0c219aa..7e4df2f 100644 --- a/Sources/ZkSync2/Crypto/EIP712/Structurable.swift +++ b/Sources/ZkSync2/Crypto/EIP712/Structurable.swift @@ -6,9 +6,13 @@ // import Foundation -import web3swift import BigInt import CryptoSwift +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif public protocol Structurable: EIP712Hashable { diff --git a/Sources/ZkSync2/Crypto/Signer/EthSigner.swift b/Sources/ZkSync2/Crypto/Signer/EthSigner.swift index 29f056f..423346b 100644 --- a/Sources/ZkSync2/Crypto/Signer/EthSigner.swift +++ b/Sources/ZkSync2/Crypto/Signer/EthSigner.swift @@ -6,7 +6,11 @@ // import Foundation +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif public protocol EthSigner { diff --git a/Sources/ZkSync2/Crypto/Signer/PrivateKeyEthSigner.swift b/Sources/ZkSync2/Crypto/Signer/PrivateKeyEthSigner.swift index 57282df..143491e 100644 --- a/Sources/ZkSync2/Crypto/Signer/PrivateKeyEthSigner.swift +++ b/Sources/ZkSync2/Crypto/Signer/PrivateKeyEthSigner.swift @@ -7,7 +7,11 @@ import Foundation import BigInt +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif public class PrivateKeyEthSigner: EthSigner { diff --git a/Sources/ZkSync2/Extensions/EthereumAddress.swift b/Sources/ZkSync2/Extensions/EthereumAddress.swift index d307d68..5f41a0f 100644 --- a/Sources/ZkSync2/Extensions/EthereumAddress.swift +++ b/Sources/ZkSync2/Extensions/EthereumAddress.swift @@ -5,7 +5,11 @@ // Created by Maxim Makhun on 9/27/22. // +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif extension EthereumAddress { diff --git a/Sources/ZkSync2/Extensions/EthereumKeystoreV3.swift b/Sources/ZkSync2/Extensions/EthereumKeystoreV3.swift index aa30da1..88b255a 100644 --- a/Sources/ZkSync2/Extensions/EthereumKeystoreV3.swift +++ b/Sources/ZkSync2/Extensions/EthereumKeystoreV3.swift @@ -6,8 +6,12 @@ // import Foundation -import web3swift import BigInt +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif public typealias Credentials = EthereumKeystoreV3 diff --git a/Sources/ZkSync2/Extensions/EthereumTransaction.swift b/Sources/ZkSync2/Extensions/EthereumTransaction.swift index 2407218..e1a722e 100644 --- a/Sources/ZkSync2/Extensions/EthereumTransaction.swift +++ b/Sources/ZkSync2/Extensions/EthereumTransaction.swift @@ -7,7 +7,11 @@ import Foundation import BigInt +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif extension EthereumTransaction { diff --git a/Sources/ZkSync2/Extensions/JsonRpc2_0ZkSync+Promise.swift b/Sources/ZkSync2/Extensions/JsonRpc2_0ZkSync+Promise.swift index 4a013f7..e69a77d 100644 --- a/Sources/ZkSync2/Extensions/JsonRpc2_0ZkSync+Promise.swift +++ b/Sources/ZkSync2/Extensions/JsonRpc2_0ZkSync+Promise.swift @@ -8,7 +8,11 @@ import Foundation import BigInt import PromiseKit +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif extension JsonRpc2_0ZkSync { diff --git a/Sources/ZkSync2/Extensions/Web3Eth.swift b/Sources/ZkSync2/Extensions/Web3Eth.swift index 2e886f1..074d3f8 100644 --- a/Sources/ZkSync2/Extensions/Web3Eth.swift +++ b/Sources/ZkSync2/Extensions/Web3Eth.swift @@ -5,9 +5,13 @@ // Created by Maxim Makhun on 9/29/22. // -import web3swift import BigInt import PromiseKit +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif extension web3.Eth { diff --git a/Sources/ZkSync2/Protocol/JsonRpc2_0ZkSync.swift b/Sources/ZkSync2/Protocol/JsonRpc2_0ZkSync.swift index ceb7ad9..3c1b9bc 100644 --- a/Sources/ZkSync2/Protocol/JsonRpc2_0ZkSync.swift +++ b/Sources/ZkSync2/Protocol/JsonRpc2_0ZkSync.swift @@ -6,8 +6,12 @@ // import Foundation -import web3swift import BigInt +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif class JsonRpc2_0ZkSync: ZkSync { diff --git a/Sources/ZkSync2/Protocol/Provider/DefaultEthereumProvider.swift b/Sources/ZkSync2/Protocol/Provider/DefaultEthereumProvider.swift index bd58dfd..f94b0ad 100644 --- a/Sources/ZkSync2/Protocol/Provider/DefaultEthereumProvider.swift +++ b/Sources/ZkSync2/Protocol/Provider/DefaultEthereumProvider.swift @@ -7,8 +7,12 @@ import Foundation import BigInt -import web3swift import PromiseKit +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif extension DefaultEthereumProvider { @@ -62,9 +66,9 @@ class DefaultEthereumProvider: EthereumProvider { throw EthereumProviderError.invalidToken } - let tokenContract = web3swift.ERC20(web3: web3, - provider: web3.provider, - address: tokenAddress) + let tokenContract = ERC20(web3: web3, + provider: web3.provider, + address: tokenAddress) let maxApproveAmount = BigUInt.two.power(256) - 1 let amount = limit?.description ?? maxApproveAmount.description @@ -252,9 +256,9 @@ class DefaultEthereumProvider: EthereumProvider { throw EthereumProviderError.invalidToken } - let tokenContract = web3swift.ERC20(web3: web3, - provider: web3.provider, - address: tokenAddress) + let tokenContract = ERC20(web3: web3, + provider: web3.provider, + address: tokenAddress) let allowance = try tokenContract.getAllowance(originalOwner: ownerAddress, delegate: spenderAddress) diff --git a/Sources/ZkSync2/Protocol/Provider/EthereumProvider.swift b/Sources/ZkSync2/Protocol/Provider/EthereumProvider.swift index 6349b60..db2bebc 100644 --- a/Sources/ZkSync2/Protocol/Provider/EthereumProvider.swift +++ b/Sources/ZkSync2/Protocol/Provider/EthereumProvider.swift @@ -7,8 +7,12 @@ import Foundation import BigInt -import web3swift import PromiseKit +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif protocol EthereumProvider { diff --git a/Sources/ZkSync2/Protocol/ZkSync.swift b/Sources/ZkSync2/Protocol/ZkSync.swift index 4138071..3524362 100644 --- a/Sources/ZkSync2/Protocol/ZkSync.swift +++ b/Sources/ZkSync2/Protocol/ZkSync.swift @@ -7,7 +7,11 @@ import Foundation import BigInt +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif public typealias Result = Swift.Result diff --git a/Sources/ZkSync2/Transaction/Fee/DefaultTransactionFeeProvider.swift b/Sources/ZkSync2/Transaction/Fee/DefaultTransactionFeeProvider.swift index 044e7b6..af1e380 100644 --- a/Sources/ZkSync2/Transaction/Fee/DefaultTransactionFeeProvider.swift +++ b/Sources/ZkSync2/Transaction/Fee/DefaultTransactionFeeProvider.swift @@ -6,9 +6,13 @@ // import Foundation -import web3swift import BigInt import PromiseKit +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif class DefaultTransactionFeeProvider: ZkTransactionFeeProvider { diff --git a/Sources/ZkSync2/Transaction/Fee/ZkTransactionFeeProvider.swift b/Sources/ZkSync2/Transaction/Fee/ZkTransactionFeeProvider.swift index 760eeee..74ec4b2 100644 --- a/Sources/ZkSync2/Transaction/Fee/ZkTransactionFeeProvider.swift +++ b/Sources/ZkSync2/Transaction/Fee/ZkTransactionFeeProvider.swift @@ -6,9 +6,13 @@ // import Foundation -import web3swift import BigInt import PromiseKit +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif protocol ZkTransactionFeeProvider: ContractGasProvider { diff --git a/Sources/ZkSync2/Transaction/Type/EthereumTransaction+EIP712.swift b/Sources/ZkSync2/Transaction/Type/EthereumTransaction+EIP712.swift index 25b3d9e..d3fe0a6 100644 --- a/Sources/ZkSync2/Transaction/Type/EthereumTransaction+EIP712.swift +++ b/Sources/ZkSync2/Transaction/Type/EthereumTransaction+EIP712.swift @@ -6,8 +6,12 @@ // import Foundation -import web3swift import BigInt +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif extension EthereumTransaction: Structurable { diff --git a/Sources/ZkSync2/Utils/ContractDeployer.swift b/Sources/ZkSync2/Utils/ContractDeployer.swift index 18fb465..8a4da99 100644 --- a/Sources/ZkSync2/Utils/ContractDeployer.swift +++ b/Sources/ZkSync2/Utils/ContractDeployer.swift @@ -6,8 +6,12 @@ // import Foundation -import web3swift import BigInt +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif public class ContractDeployer { diff --git a/Sources/ZkSync2/Utils/ContractUtils.swift b/Sources/ZkSync2/Utils/ContractUtils.swift index 50a4204..01346d5 100644 --- a/Sources/ZkSync2/Utils/ContractUtils.swift +++ b/Sources/ZkSync2/Utils/ContractUtils.swift @@ -7,7 +7,11 @@ import Foundation import BigInt +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif class ContractUtils { diff --git a/Sources/ZkSync2/Utils/Paymaster.swift b/Sources/ZkSync2/Utils/Paymaster.swift index fb8c58b..ce8c2af 100644 --- a/Sources/ZkSync2/Utils/Paymaster.swift +++ b/Sources/ZkSync2/Utils/Paymaster.swift @@ -6,8 +6,12 @@ // import Foundation -import web3swift import BigInt +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif class Paymaster { diff --git a/Sources/ZkSync2/Utils/ZkSyncABI.swift b/Sources/ZkSync2/Utils/ZkSyncABI.swift index 44eec4e..3bed128 100644 --- a/Sources/ZkSync2/Utils/ZkSyncABI.swift +++ b/Sources/ZkSync2/Utils/ZkSyncABI.swift @@ -6,7 +6,11 @@ // import Foundation +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif extension Web3.Utils { diff --git a/Sources/ZkSync2/Wrappers/ERC20.swift b/Sources/ZkSync2/Wrappers/ERC20.swift index ca13c20..d555193 100644 --- a/Sources/ZkSync2/Wrappers/ERC20.swift +++ b/Sources/ZkSync2/Wrappers/ERC20.swift @@ -6,10 +6,14 @@ // import Foundation -import web3swift import BigInt +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif -class ERC20 { +class ZkERC20 { static func encodeTransfer(_ to: EthereumAddress, value: BigUInt) -> Data { diff --git a/Sources/ZkSync2/Wrappers/IL1Bridge.swift b/Sources/ZkSync2/Wrappers/IL1Bridge.swift index d3a831b..7e14f7d 100644 --- a/Sources/ZkSync2/Wrappers/IL1Bridge.swift +++ b/Sources/ZkSync2/Wrappers/IL1Bridge.swift @@ -6,7 +6,11 @@ // import Foundation +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif extension Web3.Utils { diff --git a/Sources/ZkSync2/Wrappers/IL2Bridge.swift b/Sources/ZkSync2/Wrappers/IL2Bridge.swift index 846e4b7..d62dfe4 100644 --- a/Sources/ZkSync2/Wrappers/IL2Bridge.swift +++ b/Sources/ZkSync2/Wrappers/IL2Bridge.swift @@ -6,7 +6,11 @@ // import Foundation +#if canImport(web3swift) import web3swift +#else +import web3swift_zksync +#endif extension Web3.Utils { diff --git a/Sources/ZkSync2/Wrappers/NonceHolder.swift b/Sources/ZkSync2/Wrappers/NonceHolder.swift index baebec9..6ec4371 100644 --- a/Sources/ZkSync2/Wrappers/NonceHolder.swift +++ b/Sources/ZkSync2/Wrappers/NonceHolder.swift @@ -6,9 +6,13 @@ // import Foundation -import web3swift import BigInt import PromiseKit +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif class NonceHolder { diff --git a/Sources/ZkSync2/ZkSyncWallet.swift b/Sources/ZkSync2/ZkSyncWallet.swift index 40df315..db1d21c 100644 --- a/Sources/ZkSync2/ZkSyncWallet.swift +++ b/Sources/ZkSync2/ZkSyncWallet.swift @@ -7,8 +7,12 @@ import Foundation import BigInt -import web3swift import PromiseKit +#if canImport(web3swift) +import web3swift +#else +import web3swift_zksync +#endif public class ZkSyncWallet { @@ -422,9 +426,9 @@ public class ZkSyncWallet { return zkSync.web3.eth.getBalancePromise(address: ethereumAddress, onBlock: at.rawValue) } else { - let erc20 = web3swift.ERC20(web3: zkSync.web3, - provider: zkSync.web3.provider, - address: l2EthereumAddress) + let erc20 = ERC20(web3: zkSync.web3, + provider: zkSync.web3.provider, + address: l2EthereumAddress) let balance = try! erc20.getBalance(account: ethereumAddress) diff --git a/Tests/ZkSync2Tests/ZkSyncWeb3RpcIntegrationTests.swift b/Tests/ZkSync2Tests/ZkSyncWeb3RpcIntegrationTests.swift index f4496d8..fbe037f 100644 --- a/Tests/ZkSync2Tests/ZkSyncWeb3RpcIntegrationTests.swift +++ b/Tests/ZkSync2Tests/ZkSyncWeb3RpcIntegrationTests.swift @@ -329,7 +329,7 @@ class ZKSyncWeb3RpcIntegrationTests: XCTestCase { let value = BigUInt(10000000) - let calldata = ZkSync2.ERC20.encodeTransfer(self.credentials.ethereumAddress, value: value) + let calldata = ZkERC20.encodeTransfer(self.credentials.ethereumAddress, value: value) print("calldata: \(calldata.toHexString().addHexPrefix())") var estimate = EthereumTransaction.createFunctionCallTransaction(from: self.credentials.ethereumAddress, @@ -698,8 +698,8 @@ class ZKSyncWeb3RpcIntegrationTests: XCTestCase { DispatchQueue.global().async { [weak self] in guard let self = self else { return } - let calldata = ZkSync2.ERC20.encodeTransfer(EthereumAddress("0xe1fab3efd74a77c23b426c302d96372140ff7d0c")!, - value: BigUInt(1)) + let calldata = ZkERC20.encodeTransfer(EthereumAddress("0xe1fab3efd74a77c23b426c302d96372140ff7d0c")!, + value: BigUInt(1)) print("calldata: \(calldata.toHexString().addHexPrefix())")