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

Refactor/swift concurency #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 7 additions & 15 deletions Sources/OrcaSwapSwift/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public protocol OrcaSwapAPIClient {
var configsProvider: OrcaSwapConfigsProvider {get}
func reload() async throws
func getTokens() async throws -> [String: TokenValue]
func getAquafarms() async throws -> [String: Aquafarm]
func getPools() async throws -> [String: Pool]
func getProgramID() async throws -> ProgramIDS
}

extension OrcaSwapAPIClient {
Expand All @@ -24,26 +22,20 @@ extension OrcaSwapAPIClient {

public func getTokens() async throws -> [String: TokenValue] {
let data = try await configsProvider.getConfigs()
let configs = try JSONDecoder().decode(OrcaConfigs.self, from: data)
return configs.tokens
}

public func getAquafarms() async throws -> [String: Aquafarm] {
let data = try await configsProvider.getConfigs()
let configs = try JSONDecoder().decode(OrcaConfigs.self, from: data)
return configs.aquafarms
let response = try JSONDecoder().decode(OrcaInfoResponse.self, from: data)
return response.value.tokens
}

public func getPools() async throws -> [String: Pool] {
let data = try await configsProvider.getConfigs()
let configs = try JSONDecoder().decode(OrcaConfigs.self, from: data)
return configs.pools
let response = try JSONDecoder().decode(OrcaInfoResponse.self, from: data)
return response.value.pools
}

public func getProgramID() async throws -> ProgramIDS {
let data = try await configsProvider.getConfigs()
let configs = try JSONDecoder().decode(OrcaConfigs.self, from: data)
return configs.programIDS
let response = try JSONDecoder().decode(OrcaInfoResponse.self, from: data)
return response.value.programIds
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/OrcaSwapSwift/APIClient/ConfigsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension OrcaSwapConfigsProvider {
public class NetworkConfigsProvider: OrcaSwapConfigsProvider {
public let network: String
public var cache: Data?
private let urlString = "https://api.orca.so/configs"
private let urlString = "https://orca.wallet.p2p.org/info"
private let locker = NSLock()

public init(network: String) {
Expand Down
252 changes: 0 additions & 252 deletions Sources/OrcaSwapSwift/Models/OrcaConfigs.swift

This file was deleted.

56 changes: 56 additions & 0 deletions Sources/OrcaSwapSwift/Models/OrcaInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse the JSON, add this file to your project and do:
//
// let orcaConfigs = try? newJSONDecoder().decode(OrcaConfigs.self, from: jsonData)

import Foundation
import SolanaSwift

// MARK: - OrcaConfigs
public struct OrcaInfo: Codable {
public let pools: [String: Pool]
public let programIds: ProgramIDS
public let tokens: [String: TokenValue]

public init(pools: [String: Pool], programIds: ProgramIDS, tokens: [String: TokenValue]) {
self.pools = pools
self.programIds = programIds
self.tokens = tokens
}
}

public enum TokenEnum: String, Codable {
case tokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}

// MARK: - ProgramIDS
public struct ProgramIDS: Codable {
public let serumTokenSwap, tokenSwapV2, tokenSwap: String
public let token: TokenEnum
public let aquafarm: String

public init(serumTokenSwap: String, tokenSwapV2: String, tokenSwap: String, token: TokenEnum, aquafarm: String) {
self.serumTokenSwap = serumTokenSwap
self.tokenSwapV2 = tokenSwapV2
self.tokenSwap = tokenSwap
self.token = token
self.aquafarm = aquafarm
}
}

// MARK: - TokenValue
public struct TokenValue: Codable {
public let mint, name: String
public let decimals: Int
public let fetchPrice, poolToken: Bool?
public let wrapper: String?

public init(mint: String, name: String, decimals: Int, fetchPrice: Bool?, poolToken: Bool?, wrapper: String?) {
self.mint = mint
self.name = name
self.decimals = decimals
self.fetchPrice = fetchPrice
self.poolToken = poolToken
self.wrapper = wrapper
}
}
3 changes: 3 additions & 0 deletions Sources/OrcaSwapSwift/Models/OrcaInfoResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct OrcaInfoResponse: Decodable {
let value: OrcaInfo
}