Skip to content

Commit

Permalink
add serviceType to baking-bad baker data
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Feb 16, 2024
1 parent f5e18fe commit 94c5085
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions Sources/KukaiCoreSwift/Models/BakingBad/TzKTBaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public enum TzKTBakerTiming: String, Codable {
case no_data
}

/// The reliability of the bakers payouts
public enum TzKTBakerServiceType: String, Codable {
case tezosOnly = "tezos_only"
case multiasset = "multiasset"
case exchange = "exchange"
case unknown
}

/// Data representing a baker from TzKT or Baking-Bad
public struct TzKTBaker: Codable, Hashable {

Expand All @@ -48,6 +56,7 @@ public struct TzKTBaker: Codable, Hashable {
public let openForDelegation: Bool
public let estimatedRoi: Decimal
public let serviceHealth: TzKTBakerHealth
public let serviceType: TzKTBakerServiceType
public let payoutTiming: TzKTBakerTiming
public let payoutAccuracy: TzKTBakerAccuracy
public let config: TzKTBakerConfig?
Expand All @@ -70,12 +79,13 @@ public struct TzKTBaker: Codable, Hashable {
self.openForDelegation = false
self.estimatedRoi = 0
self.serviceHealth = .dead
self.serviceType = .unknown
self.payoutTiming = .no_data
self.payoutAccuracy = .no_data
self.config = nil
}

public init(address: String, name: String?, logo: String?, balance: Decimal, stakingBalance: Decimal, stakingCapacity: Decimal, maxStakingBalance: Decimal, freeSpace: Decimal, fee: Double, minDelegation: Decimal, payoutDelay: Int, payoutPeriod: Int, openForDelegation: Bool, estimatedRoi: Decimal, serviceHealth: TzKTBakerHealth, payoutTiming: TzKTBakerTiming, payoutAccuracy: TzKTBakerAccuracy, config: TzKTBakerConfig?) {
public init(address: String, name: String?, logo: String?, balance: Decimal, stakingBalance: Decimal, stakingCapacity: Decimal, maxStakingBalance: Decimal, freeSpace: Decimal, fee: Double, minDelegation: Decimal, payoutDelay: Int, payoutPeriod: Int, openForDelegation: Bool, estimatedRoi: Decimal, serviceHealth: TzKTBakerHealth, serviceType: TzKTBakerServiceType, payoutTiming: TzKTBakerTiming, payoutAccuracy: TzKTBakerAccuracy, config: TzKTBakerConfig?) {

self.address = address
self.name = name
Expand All @@ -92,6 +102,7 @@ public struct TzKTBaker: Codable, Hashable {
self.openForDelegation = openForDelegation
self.estimatedRoi = estimatedRoi
self.serviceHealth = serviceHealth
self.serviceType = serviceType
self.payoutTiming = payoutTiming
self.payoutAccuracy = payoutAccuracy
self.config = config
Expand All @@ -107,7 +118,7 @@ public struct TzKTBaker: Codable, Hashable {
let name = data[1] as? String
let normalisedBalance = balance/1000000
let normalisedStakingBal = stakingBalance/1000000
return TzKTBaker(address: address, name: name, logo: nil, balance: normalisedBalance, stakingBalance: normalisedStakingBal, stakingCapacity: normalisedStakingBal, maxStakingBalance: normalisedStakingBal, freeSpace: normalisedStakingBal, fee: 0.05, minDelegation: 0, payoutDelay: 6, payoutPeriod: 1, openForDelegation: true, estimatedRoi: 0.05, serviceHealth: .active, payoutTiming: .no_data, payoutAccuracy: .no_data, config: nil)
return TzKTBaker(address: address, name: name, logo: nil, balance: normalisedBalance, stakingBalance: normalisedStakingBal, stakingCapacity: normalisedStakingBal, maxStakingBalance: normalisedStakingBal, freeSpace: normalisedStakingBal, fee: 0.05, minDelegation: 0, payoutDelay: 6, payoutPeriod: 1, openForDelegation: true, estimatedRoi: 0.05, serviceHealth: .active, serviceType: .tezosOnly, payoutTiming: .no_data, payoutAccuracy: .no_data, config: nil)
}

/// Convert con-chain data into a meaningful, readable object
Expand Down
2 changes: 1 addition & 1 deletion Tests/KukaiCoreSwiftTests/Models/TzKTBakerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class TzKTBakerTests: XCTestCase {
rewardStruct: [
TzKTBakerConfigIntValue(cycle: 500, value: 981)
])
let baker2 = TzKTBaker(address: "tz1abc123", name: "Baking Benjamins", logo: nil, balance: 123, stakingBalance: 123, stakingCapacity: 123, maxStakingBalance: 123, freeSpace: 123, fee: 0.5, minDelegation: 123, payoutDelay: 1, payoutPeriod: 1, openForDelegation: true, estimatedRoi: 5.5, serviceHealth: .active, payoutTiming: .stable, payoutAccuracy: .precise, config: config)
let baker2 = TzKTBaker(address: "tz1abc123", name: "Baking Benjamins", logo: nil, balance: 123, stakingBalance: 123, stakingCapacity: 123, maxStakingBalance: 123, freeSpace: 123, fee: 0.5, minDelegation: 123, payoutDelay: 1, payoutPeriod: 1, openForDelegation: true, estimatedRoi: 5.5, serviceHealth: .active, serviceType: .tezosOnly, payoutTiming: .stable, payoutAccuracy: .precise, config: config)
XCTAssert(baker2.name == "Baking Benjamins")
XCTAssert(baker2.config != nil)
XCTAssert(baker2.config?.latesetFee() == 14)
Expand Down

0 comments on commit 94c5085

Please sign in to comment.