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

Allow to choose local or GH SPM release yttrium package #21

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2354,11 +2354,9 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = DApp/DApp.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 184;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = W5R8AG9K22;
DEVELOPMENT_TEAM = W5R8AG9K22;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = DApp/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = dApp;
Expand All @@ -2378,7 +2376,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.walletconnect.dapp;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "match AppStore com.walletconnect.dapp";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/ProxymanApp/atlantis",
"state": {
"branch": null,
"revision": "5145a7041ec71421d09653db87dcc80c81792004",
"version": "1.24.0"
"revision": "523dd773538e1e20036cb2d28f8b9947448c2d20",
"version": "1.25.1"
}
},
{
Expand Down Expand Up @@ -127,15 +127,6 @@
"version": "1.0.3"
}
},
{
"package": "swift-snapshot-testing",
"repositoryURL": "https://github.com/pointfreeco/swift-snapshot-testing",
"state": {
"branch": null,
"revision": "f29e2014f6230cf7d5138fc899da51c7f513d467",
"version": "1.10.0"
}
},
{
"package": "SwiftImageReadWrite",
"repositoryURL": "https://github.com/dagronf/SwiftImageReadWrite",
Expand Down Expand Up @@ -198,6 +189,15 @@
"revision": "569255adcfff0b37e4cb8004aea29d0e2d6266df",
"version": "1.0.2"
}
},
{
"package": "yttrium",
"repositoryURL": "https://github.com/reown-com/yttrium",
"state": {
"branch": null,
"revision": "f090637fc2b68417b20a9f8249d2a531f9d405a5",
"version": "0.0.24"
}
}
]
},
Expand Down
30 changes: 14 additions & 16 deletions Example/Shared/Signer/Signer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ final class Signer {
return nil
}

let simpleSmartAccountAddress = try await SmartAccount.instance.getClient().getAddress()
let safeSmartAccountAddress = try await SmartAccountSafe.instance.getClient().getAddress()

if account?.lowercased() == simpleSmartAccountAddress.lowercased() {
return .simple
} else if account?.lowercased() == safeSmartAccountAddress.lowercased() {
if account?.lowercased() == safeSmartAccountAddress.lowercased() {
return .safe
}

Expand Down Expand Up @@ -108,10 +105,10 @@ final class Signer {
private static func signWithSmartAccount(request: Request, accountType: SmartAccountType) async throws -> AnyCodable {
let client: AccountClientProtocol
switch accountType {
case .simple:
client = await SmartAccount.instance.getClient()
case .safe:
client = await SmartAccountSafe.instance.getClient()
default:
fatalError("Only safe is currently supported")
}

switch request.method {
Expand All @@ -129,26 +126,27 @@ final class Signer {

case "eth_sendTransaction":
let params = try request.params.get([YttriumWrapper.Transaction].self)
let transaction = params[0]
let result = try await client.sendTransaction(transaction)
let result = try await client.sendTransactions(params)
return AnyCodable(result)

case "wallet_sendCalls":
let params = try request.params.get([SendCallsParams].self)
guard let firstCall = params.first?.calls.first else {
guard let calls = params.first?.calls else {
fatalError()
}

let transaction = YttriumWrapper.Transaction(
to: firstCall.to!,
value: firstCall.value!,
data: firstCall.data!
)
let transactions = calls.map {
YttriumWrapper.Transaction(
to: $0.to!,
value: $0.value!,
data: $0.data!
)
}

let userOpHash = try await client.sendTransaction(transaction)
let userOpHash = try await client.sendTransactions(transactions)

Task {
let userOpReceipt = try await SmartAccount.instance.getClient().waitForUserOperationReceipt(userOperationHash: userOpHash)
let userOpReceipt = try await SmartAccountSafe.instance.getClient().waitForUserOperationReceipt(userOperationHash: userOpHash)
guard let userOpReceiptSting = userOpReceipt.jsonString else { return }
AlertPresenter.present(message: userOpReceiptSting, type: .info)
}
Expand Down
1 change: 0 additions & 1 deletion Example/WalletApp/ApplicationLayer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
// Override point for customization after application launch.
let entryPointAddress = "0x0000000071727De22E5E9d8BAf0edAc6f37da032" // v0.7 on Sepolia
let chainId = 11155111 // Sepolia
SmartAccount.instance.configure(entryPoint: entryPointAddress, chainId: chainId)
SmartAccountSafe.instance.configure(entryPoint: entryPointAddress, chainId: chainId)
return true
}
Expand Down
137 changes: 0 additions & 137 deletions Example/WalletApp/BusinessLayer/SmartAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,88 +11,6 @@ extension YttriumWrapper.AccountClient {
}
}

class SmartAccount {

static var instance = SmartAccount()

private var client: AccountClient? {
didSet {
if let _ = client {
clientSetContinuation?.resume()
}
}
}

private var clientSetContinuation: CheckedContinuation<Void, Never>?

private var config: Config?

private init() {

}

public func configure(entryPoint: String, chainId: Int) {
self.config = Config(
entryPoint: entryPoint,
chainId: chainId
)
}

public func register(owner: String, privateKey: String) {
guard let config = self.config else {
fatalError("Error - you must call SmartAccount.configure(entryPoint:chainId:onSign:) before accessing the shared instance.")
}
assert(owner.count == 40)

let localConfig = YttriumWrapper.Config.local()

let pimlicoBundlerUrl = "https://\(InputConfig.pimlicoBundlerUrl!)"
let rpcUrl = "https://\(InputConfig.rpcUrl!)"
let pimlicoSepolia = YttriumWrapper.Config(
endpoints: .init(
rpc: .init(baseURL: rpcUrl),
bundler: .init(baseURL: pimlicoBundlerUrl),
paymaster: .init(baseURL: pimlicoBundlerUrl)
)
)

let pickedConfig = if !(InputConfig.pimlicoBundlerUrl?.isEmpty ?? true) && !(InputConfig.rpcUrl?.isEmpty ?? true) {
pimlicoSepolia
} else {
localConfig
}

let client = AccountClient(
ownerAddress: owner,
entryPoint: config.entryPoint,
chainId: config.chainId,
config: pickedConfig,
safe: false
)
client.register(privateKey: privateKey)

self.client = client
}


public func getClient() async -> AccountClient {
if let client = client {
return client
}

await withCheckedContinuation { continuation in
self.clientSetContinuation = continuation
}

return client!
}

struct Config {
let entryPoint: String
let chainId: Int
}
}

class SmartAccountSafe {

static var instance = SmartAccountSafe()
Expand Down Expand Up @@ -174,58 +92,3 @@ class SmartAccountSafe {
let chainId: Int
}
}


class AccountClientMock: YttriumWrapper.AccountClientProtocol {

var onSign: OnSign?

var chainId: Int

var ownerAddress: String

var entryPoint: String

private var config: Yttrium.Config

required init(ownerAddress: String, entryPoint: String, chainId: Int, config: Yttrium.Config, safe: Bool) {
self.ownerAddress = ownerAddress
self.entryPoint = entryPoint
self.chainId = chainId
self.config = config
}

func register(privateKey: String) {

}

// prepares UserOp
func sendTransaction(_ transaction: YttriumWrapper.Transaction) async throws -> String {
guard let onSign = onSign else {
fatalError("Error - onSign closure must be set before calling signMessage")
}
let _ = onSign("UserOp")
return "txHash"
}

func sendBatchTransaction(_ batch: [YttriumWrapper.Transaction]) async throws -> String {
return "userOpReceipt"
}

func getAddress() async throws -> String {
return "0xF4D7560648F1252FD7501863355AEaBfb9d3b7c3"
}

func getAccount() async throws -> Account {
let chain = try Blockchain(namespace: "eip155", reference: chainId)
let address = try await getAddress()
return try Account(blockchain: chain, accountAddress: address)
}

func signMessage(_ message: String) throws -> String {
guard let onSign = onSign else {
fatalError("Error - onSign closure must be set before calling signMessage")
}
return try! onSign(message).get()
}
}
3 changes: 1 addition & 2 deletions Example/WalletApp/BusinessLayer/SmartAccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class SmartAccountManager {
guard isSmartAccountEnabled else {
throw Errors.smartAccountNotEnabled
}
let simpleAccountAddress = try await SmartAccount.instance.getClient().getAddress()
let safeAccountAddress = try await SmartAccountSafe.instance.getClient().getAddress()
return [simpleAccountAddress, safeAccountAddress]
return [safeAccountAddress]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ final class MainModule {
static func configureSmartAccountOnSign(importAccount: ImportAccount) {
let privateKey = importAccount.privateKey
let ownerAddress = String(importAccount.account.address.dropFirst(2))
SmartAccount.instance.register(
owner: ownerAddress,
privateKey: privateKey
)
SmartAccountSafe.instance.register(
owner: ownerAddress,
privateKey: privateKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ReownWalletKit
import ReownRouter

final class SessionProposalInteractor {
func approve(proposal: Session.Proposal, EOAAccount: Account, smartAccount: Account) async throws -> Bool {
func approve(proposal: Session.Proposal, EOAAccount: Account) async throws -> Bool {
// Following properties are used to support all the required and optional namespaces for the testing purposes
let supportedMethods = Set(proposal.requiredNamespaces.flatMap { $0.value.methods } + (proposal.optionalNamespaces?.flatMap { $0.value.methods } ?? []))
let supportedEvents = Set(proposal.requiredNamespaces.flatMap { $0.value.events } + (proposal.optionalNamespaces?.flatMap { $0.value.events } ?? []))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ final class SessionProposalPresenter: ObservableObject {
func onApprove() async throws {
do {
ActivityIndicatorManager.shared.start()
let smartAccount = try await SmartAccount.instance.getClient().getAccount()
let showConnected = try await interactor.approve(proposal: sessionProposal, EOAAccount: importAccount.account, smartAccount: smartAccount)
let showConnected = try await interactor.approve(proposal: sessionProposal, EOAAccount: importAccount.account)
showConnected ? showConnectedSheet.toggle() : router.dismiss()
ActivityIndicatorManager.shared.stop()
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,9 @@ final class SettingsPresenter: ObservableObject {
self.interactor = interactor
self.router = router
self.accountStorage = accountStorage
fetchSmartAccount()
fetchSmartAccountSafe()
}

func fetchSmartAccount() {
Task {
do {
let smartAccount = try await getSmartAccount()
DispatchQueue.main.async {
self.smartAccount = smartAccount
}
} catch {
DispatchQueue.main.async {
self.smartAccount = "Failed to load"
}
print("Failed to get smart account: \(error)")
}
}
}

private func getSmartAccount() async throws -> String {
try await SmartAccount.instance.getClient().getAccount().absoluteString
}

func fetchSmartAccountSafe() {
Task {
do {
Expand Down
Loading