@pax2pay/model-banking 0.1.261 → 0.1.263

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/Counterbalance2.ts +5 -14
  2. package/Settlement/Amount.ts +21 -0
  3. package/Settlement/Creatable.ts +3 -3
  4. package/Settlement/Entry/Capture.ts +1 -1
  5. package/Settlement/Entry/index.ts +0 -7
  6. package/Settlement/Total.ts +72 -24
  7. package/Settlement/Totals.ts +54 -0
  8. package/Settlement/index.ts +49 -39
  9. package/Treasury/Account/Storable.ts +2 -0
  10. package/Treasury/Snapshot/Fragment.ts +24 -7
  11. package/Treasury/Snapshot/index.ts +1 -2
  12. package/Treasury/index.ts +1 -7
  13. package/dist/Counterbalance2.d.ts +5 -7
  14. package/dist/Counterbalance2.js +3 -12
  15. package/dist/Counterbalance2.js.map +1 -1
  16. package/dist/Operation/Changes.d.ts +1 -1
  17. package/dist/Settlement/Amount.d.ts +12 -0
  18. package/dist/Settlement/Amount.js +17 -0
  19. package/dist/Settlement/Amount.js.map +1 -0
  20. package/dist/Settlement/Creatable.d.ts +2 -2
  21. package/dist/Settlement/Creatable.js +2 -2
  22. package/dist/Settlement/Creatable.js.map +1 -1
  23. package/dist/Settlement/Entry/index.d.ts +0 -2
  24. package/dist/Settlement/Entry/index.js +0 -8
  25. package/dist/Settlement/Entry/index.js.map +1 -1
  26. package/dist/Settlement/Total.d.ts +25 -13
  27. package/dist/Settlement/Total.js +62 -23
  28. package/dist/Settlement/Total.js.map +1 -1
  29. package/dist/Settlement/Totals.d.ts +13 -0
  30. package/dist/Settlement/Totals.js +48 -0
  31. package/dist/Settlement/Totals.js.map +1 -0
  32. package/dist/Settlement/index.d.ts +39 -25
  33. package/dist/Settlement/index.js +39 -37
  34. package/dist/Settlement/index.js.map +1 -1
  35. package/dist/Treasury/Account/Storable.d.ts +1 -0
  36. package/dist/Treasury/Account/Storable.js +1 -0
  37. package/dist/Treasury/Account/Storable.js.map +1 -1
  38. package/dist/Treasury/Snapshot/Fragment.d.ts +22 -2
  39. package/dist/Treasury/Snapshot/Fragment.js +18 -2
  40. package/dist/Treasury/Snapshot/Fragment.js.map +1 -1
  41. package/dist/Treasury/Snapshot/index.d.ts +1 -2
  42. package/dist/Treasury/Snapshot/index.js.map +1 -1
  43. package/dist/Treasury/index.d.ts +1 -7
  44. package/dist/Treasury/index.js.map +1 -1
  45. package/package.json +1 -1
  46. package/Settlement/Settled.ts +0 -16
  47. package/dist/Settlement/Settled.d.ts +0 -11
  48. package/dist/Settlement/Settled.js +0 -12
  49. package/dist/Settlement/Settled.js.map +0 -1
@@ -1,30 +1,21 @@
1
1
  import { isoly } from "isoly"
2
2
  import { isly } from "isly"
3
- import { Supplier } from "./Supplier"
4
3
 
5
4
  export type Counterbalance2 = {
6
5
  minted: Partial<Record<Counterbalance2.Source, number>>
7
6
  burned: Partial<Record<Counterbalance2.Sink, number>>
8
7
  }
9
8
  export namespace Counterbalance2 {
10
- export const sources = [...Supplier.names, "internal"] as const
11
- export type Source = `${typeof sources[number]}-${string}` // string: fiat account identifier
12
- export const Source = isly.fromIs<Source>("Source", (value: any | Source) => {
13
- const result = !value ? false : typeof value == "string" && value.split("-")
14
- return result && result.length == 2 && sources.includes(result[0] as any) && typeof result[1] == "string"
15
- })
16
- export const sinks = [...Supplier.names, "internal"] as const
17
- export type Sink = `${typeof sinks[number]}-${string}` // string: fiat account identifier
18
- export const Sink = isly.fromIs<Sink>("Sink", (value: any | Sink) => {
19
- const result = !value ? false : typeof value == "string" && value.split("-")
20
- return result && result.length == 2 && sinks.includes(result[0] as any) && typeof result[1] == "string"
21
- })
9
+ export type Source = string
10
+ export const Source = isly.string()
11
+ export type Sink = string
12
+ export const Sink = isly.string()
22
13
  export const type = isly.object<Counterbalance2>({
23
14
  minted: isly.record<Counterbalance2["minted"]>(Source, isly.number()),
24
15
  burned: isly.record<Counterbalance2["burned"]>(Sink, isly.number()),
25
16
  })
26
17
  export type Link = Source | Sink
27
- export const Link = isly.union<Link, Source, Sink>(Source, Sink)
18
+ export const Link = isly.string()
28
19
  export function add(currency: isoly.Currency, addendee: Counterbalance2, addend: Counterbalance2): Counterbalance2 {
29
20
  const result: Counterbalance2 = { minted: { ...addend.minted }, burned: { ...addend.burned } }
30
21
  for (const [source, value] of Object.entries(addendee["minted"]) as [Source, number][]) {
@@ -0,0 +1,21 @@
1
+ import { isoly } from "isoly"
2
+ import { isly } from "isly"
3
+
4
+ export type Amount = {
5
+ net: number
6
+ fee: {
7
+ other: number
8
+ }
9
+ }
10
+ export namespace Amount {
11
+ export const type = isly.object<Amount>({
12
+ net: isly.number(),
13
+ fee: isly.object<Amount["fee"]>({ other: isly.number() }),
14
+ })
15
+ export function add(currency: isoly.Currency, addendee: Amount, addend: Partial<Amount>): Amount {
16
+ const result = { ...addendee }
17
+ result.net = isoly.Currency.add(currency, result.net, addend.net ?? 0)
18
+ result.fee.other = isoly.Currency.add(currency, result.fee.other, addend.fee?.other ?? 0)
19
+ return result
20
+ }
21
+ }
@@ -1,10 +1,10 @@
1
1
  import { isly } from "isly"
2
2
  import { Card } from "../Card"
3
3
  import { Batch } from "./Batch"
4
- import { Total } from "./Total"
4
+ import { Totals } from "./Totals"
5
5
 
6
6
  export interface Creatable {
7
- expected?: Total
7
+ totals: Totals
8
8
  processor: Card.Stack
9
9
  references?: string[] //File name
10
10
  batch: Batch
@@ -12,7 +12,7 @@ export interface Creatable {
12
12
 
13
13
  export namespace Creatable {
14
14
  export const type = isly.object<Creatable>({
15
- expected: Total.type.optional(),
15
+ totals: Totals.type,
16
16
  processor: Card.Stack.type,
17
17
  references: isly.string().array().optional(),
18
18
  batch: Batch.type,
@@ -19,7 +19,7 @@ export namespace Capture {
19
19
  export interface Creatable {
20
20
  type: "capture"
21
21
  authorization: Authorization
22
- reference: string
22
+ reference: string // card transaction
23
23
  batch: Batch
24
24
  fee: Fee
25
25
  amount: Amount
@@ -1,8 +1,6 @@
1
1
  import { gracely } from "gracely"
2
2
  import { isly } from "isly"
3
- import { Amount } from "../../Amount"
4
3
  import { Transaction } from "../../Transaction"
5
- import { Total } from "../Total"
6
4
  import { Cancel as EntryCancel } from "./Cancel"
7
5
  import { Capture as EntryCapture } from "./Capture"
8
6
  import { Creatable as EntryCreatable } from "./Creatable"
@@ -38,11 +36,6 @@ export namespace Entry {
38
36
  export const Summary = EntrySummary
39
37
  export type Creatable = EntryCreatable
40
38
  export const Creatable = EntryCreatable
41
- export function compile(entry: Entry): Total {
42
- return entry.type == "unknown"
43
- ? Total.initiate()
44
- : Total.initiate({ amount: Amount.toAmounts(entry.amount), fee: entry.fee })
45
- }
46
39
  export function from(creatable: Entry.Creatable, transaction: Transaction | gracely.Error | string): Entry {
47
40
  let result: Entry
48
41
  if (!Transaction.is(transaction) || transaction.status != "finalized")
@@ -1,34 +1,82 @@
1
+ import { isoly } from "isoly"
1
2
  import { isly } from "isly"
2
- import { Amounts } from "../Amounts"
3
- import { Transaction } from "../Transaction"
4
- import { Fee } from "./Fee"
3
+ import { Amount } from "./Amount"
5
4
 
6
- export type Total = {
7
- amount: Amounts
8
- fee: Fee
5
+ export interface Total {
6
+ expected: Amount
7
+ outcome?: Amount
8
+ collected?: Amount & { transactions: { net: string; fee: string } }
9
+ settled?: Total.Settled
9
10
  }
10
11
  export namespace Total {
11
- export function initiate(partial?: Partial<Total>): Total {
12
- return { amount: partial?.amount ?? {}, fee: partial?.fee ?? { other: {} } }
12
+ export type Settled = {
13
+ net: number
14
+ transactions: string[]
13
15
  }
14
- export function add(addendee: Total, addend: Total): Total {
15
- return { amount: Amounts.add(addendee.amount, addend.amount), fee: Fee.add(addendee.fee, addend.fee) }
16
+ export const Settled = isly.object<Settled>({ net: isly.number(), transactions: isly.string().array() })
17
+ export const type = isly.object<Total>({
18
+ expected: Amount.type,
19
+ outcome: Amount.type.optional(),
20
+ collected: Amount.type
21
+ .extend<Required<Total>["collected"]>({
22
+ transactions: isly.object<Required<Total>["collected"]["transactions"]>({
23
+ net: isly.string(),
24
+ fee: isly.string(),
25
+ }),
26
+ })
27
+ .optional(),
28
+ settled: Settled.optional(),
29
+ })
30
+ export function create(): Total {
31
+ return { expected: { net: 0, fee: { other: 0 } } }
16
32
  }
17
- export function compare(expected: Total, outcome: Total): boolean {
18
- return Amounts.compare(expected.amount, outcome.amount) && Amounts.compare(expected.fee.other, outcome.fee.other)
19
- }
20
- export function from(collect: Transaction.Collect, collected: Total = initiate()): Total {
21
- let result: Total = collected
22
- for (const [currency, counterbalance] of Object.entries(collect.counterbalances)) {
23
- for (const [entry, amount] of Object.entries(counterbalance))
24
- if (entry.startsWith("fee"))
25
- result = add(result, initiate({ fee: { other: { [currency]: amount } } }))
26
- else if (entry.startsWith("settle"))
27
- result = add(result, initiate({ amount: { [currency]: amount } }))
33
+ export function verify(total: Total, type: "outcome" | "collected" | "settled"): boolean {
34
+ let result: boolean
35
+ switch (type) {
36
+ case "outcome":
37
+ result = total.outcome?.net == total.expected.net && total.outcome.fee.other == total.expected.fee.other
38
+ break
39
+ case "collected":
40
+ result = total.collected?.net == total.outcome?.net && total.collected?.fee.other == total.outcome?.fee.other
41
+ break
42
+ case "settled":
43
+ result = total.settled?.net == total.collected?.net
44
+ break
28
45
  }
29
46
  return result
30
47
  }
31
- export const type = isly.object<Total>({ amount: Amounts.type, fee: Fee.type })
32
- export const is = type.is
33
- export const flaw = type.flaw
48
+ export function add(currency: isoly.Currency, addendee: Total, addend: Partial<Total>): Total {
49
+ const result: Total = { ...addendee }
50
+ addend.expected && (result.expected = Amount.add(currency, result.expected, addend.expected))
51
+ if (result.outcome || addend.outcome)
52
+ result.outcome = Amount.add(currency, result.outcome ?? { net: 0, fee: { other: 0 } }, addend.outcome ?? {})
53
+ if (result.collected || addend.collected)
54
+ result.collected = {
55
+ ...Amount.add(currency, result.collected ?? { net: 0, fee: { other: 0 } }, addend.collected ?? {}),
56
+ transactions: {
57
+ net: addend.collected?.transactions.net ?? result.collected?.transactions.net ?? "",
58
+ fee: addend.collected?.transactions.fee ?? result.collected?.transactions.fee ?? "",
59
+ },
60
+ }
61
+ if (result.settled || addend.settled)
62
+ result.settled = {
63
+ net: isoly.Currency.add(currency, result.settled?.net ?? 0, addend.settled?.net ?? 0),
64
+ transactions: (result.settled?.transactions ?? []).concat(addend.settled?.transactions ?? []),
65
+ }
66
+ return result
67
+ }
68
+ export function collect(
69
+ currency: isoly.Currency,
70
+ total: Total,
71
+ collected: Amount,
72
+ transactions: { net: string; fee: string }
73
+ ): Total {
74
+ const result = { ...total }
75
+ if (result.collected) {
76
+ result.collected.net = isoly.Currency.add(currency, result.collected.net, collected.net)
77
+ result.collected.fee.other = isoly.Currency.add(currency, result.collected.fee.other, collected.fee.other)
78
+ } else
79
+ result.collected = { ...collected, transactions }
80
+ return result
81
+ }
34
82
  }
@@ -0,0 +1,54 @@
1
+ import { isoly } from "isoly"
2
+ import { isly } from "isly"
3
+ import type { Collect } from "../Transaction/Collect"
4
+ import { Amount } from "./Amount"
5
+ import { Entry } from "./Entry"
6
+ import { Total } from "./Total"
7
+
8
+ export type Totals = Partial<Record<isoly.Currency, Total>>
9
+ export namespace Totals {
10
+ export const type = isly.record<isoly.Currency, Total>(isly.string(isoly.Currency.types), Total.type)
11
+ export function addEntry(totals: Totals, entry: Entry): Totals {
12
+ const result = { ...totals }
13
+ if (entry.status == "succeeded" && (entry.type == "capture" || entry.type == "refund")) {
14
+ result[entry.amount[0]] = Total.add(entry.amount[0], result[entry.amount[0]] ?? Total.create(), {
15
+ outcome: {
16
+ net: entry.amount[1],
17
+ // TODO: other currencies in fees
18
+ fee: { other: entry.fee.other[entry.amount[0]] ?? 0 },
19
+ },
20
+ })
21
+ }
22
+ return result
23
+ }
24
+ export function verify(totals: Totals, type: "outcome" | "collected" | "settled"): boolean {
25
+ return Object.values(totals).every(t => Total.verify(t, type))
26
+ }
27
+ export function add(addendee: Totals, addends: Partial<Record<isoly.Currency, Partial<Total>>>): Totals {
28
+ const result = { ...addendee }
29
+ for (const [currency, addend] of Object.entries(addends) as [isoly.Currency, Partial<Total>][]) {
30
+ result[currency] = Total.add(currency, result[currency] ?? Total.create(), addend)
31
+ }
32
+ return result
33
+ }
34
+ // TODO: update this for new collection method
35
+ export function collect(totals: Totals, collect: Collect): Totals {
36
+ const result: Totals = { ...totals }
37
+ for (const [currency, counterbalance] of Object.entries(collect.counterbalances)) {
38
+ const collected: Amount = { net: 0, fee: { other: 0 } }
39
+ for (const [entry, amount] of Object.entries(counterbalance)) {
40
+ if (entry.startsWith("fee"))
41
+ collected.fee.other = isoly.Currency.add(currency as isoly.Currency, collected.fee.other, amount ?? 0)
42
+ else if (entry.startsWith("settle"))
43
+ collected.net = isoly.Currency.add(currency as isoly.Currency, collected.net, amount ?? 0)
44
+ }
45
+ result[currency as isoly.Currency] = Total.collect(
46
+ currency as isoly.Currency,
47
+ result[currency as isoly.Currency] ?? Total.create(),
48
+ collected,
49
+ { net: "", fee: "" }
50
+ )
51
+ }
52
+ return result
53
+ }
54
+ }
@@ -1,30 +1,30 @@
1
1
  import { isoly } from "isoly"
2
2
  import { isly } from "isly"
3
- import { Card } from "../Card"
3
+ import { Amounts } from "../Amounts"
4
4
  import { Identifier } from "../Identifier"
5
+ import { Amount as SettlementAmount } from "./Amount"
5
6
  import { Batch as SettlementBatch } from "./Batch"
6
7
  import { Creatable as SettlementCreatable } from "./Creatable"
7
8
  import { Entry as SettlementEntry } from "./Entry"
8
9
  import { Fee as SettlementFee } from "./Fee"
9
- import { Settled as SettlementSettled } from "./Settled"
10
10
  import { Status } from "./Status"
11
11
  import { Total as SettlementTotal } from "./Total"
12
+ import { Totals as SettlementTotals } from "./Totals"
12
13
 
13
14
  export interface Settlement extends Settlement.Creatable {
14
15
  id: string
15
16
  by?: string
16
17
  created: isoly.DateTime
17
18
  status: Status
18
- collected?: Settlement.Total
19
- outcome: Settlement.Total
20
- settled?: Settlement.Settled
21
19
  entries: Settlement.Entry.Summary
22
20
  }
23
21
  export namespace Settlement {
24
- export type Settled = SettlementSettled
25
- export const Settled = SettlementSettled
26
22
  export const Total = SettlementTotal
27
23
  export type Total = SettlementTotal
24
+ export const Totals = SettlementTotals
25
+ export type Totals = SettlementTotals
26
+ export const Amount = SettlementAmount
27
+ export type Amount = SettlementAmount
28
28
  export const Fee = SettlementFee
29
29
  export type Fee = SettlementFee
30
30
  export type Creatable = SettlementCreatable
@@ -53,25 +53,11 @@ export namespace Settlement {
53
53
  export type Creatable = SettlementEntry.Unknown.Creatable
54
54
  }
55
55
  }
56
- export function initiate(id: string, by: string, batch: Batch, processor: Card.Stack): Settlement {
56
+ export function from(creatable: Settlement.Creatable, by: string): Settlement {
57
57
  return {
58
- id: id ?? Identifier.generate(),
59
- by,
60
- created: isoly.DateTime.now(),
61
- batch,
62
- processor,
63
- status: { collected: "pending", settled: "pending" },
64
- expected: Total.initiate(),
65
- outcome: Total.initiate(),
66
- entries: { count: 0 },
67
- }
68
- }
69
- export function from(id: string, creatable: Settlement.Creatable, by: string): Settlement {
70
- return {
71
- id,
58
+ id: Identifier.generate(),
72
59
  status: { collected: "pending", settled: "pending" },
73
60
  by,
74
- outcome: Total.initiate(),
75
61
  ...creatable,
76
62
  created: isoly.DateTime.now(),
77
63
  entries: { count: 0 },
@@ -82,7 +68,7 @@ export namespace Settlement {
82
68
  for (const entry of entries) {
83
69
  switch (entry.status) {
84
70
  case "succeeded":
85
- result.outcome = Total.add(result.outcome, Entry.compile(entry))
71
+ result.totals = Totals.addEntry(result.totals, entry)
86
72
  result.entries.count++
87
73
  break
88
74
  case "failed":
@@ -92,28 +78,52 @@ export namespace Settlement {
92
78
  }
93
79
  return result
94
80
  }
95
- export function toFailed(id: string, creatable: Settlement.Creatable, by: string, reason: string): Settlement {
96
- return {
97
- id,
98
- created: isoly.DateTime.now(),
99
- status: { collected: "failed", settled: "failed" }, // ["failed", reason],
100
- by,
101
- processor: creatable.processor,
102
- references: creatable.references,
103
- batch: creatable.batch,
104
- expected: Total.initiate(),
105
- outcome: Total.initiate(),
106
- entries: { count: 0 },
81
+ type OldTotal = { amount: Amounts; fee: Fee }
82
+ export type OldSettlement = Omit<Settlement, "totals"> & {
83
+ expected?: OldTotal
84
+ collected?: OldTotal
85
+ outcome: OldTotal
86
+ settled?: { paid: Amounts; transactions: string[] }
87
+ }
88
+ export type MaybeOld = Settlement | OldSettlement
89
+ export function fromLegacy(settlement: MaybeOld): Settlement {
90
+ let result: Settlement
91
+ if (!is(settlement)) {
92
+ const totalToAmount: (currency: isoly.Currency, total?: OldTotal) => Amount = (currency, oldTotal) => ({
93
+ net: oldTotal?.amount[currency] ?? 0,
94
+ fee: { other: oldTotal?.fee.other[currency] ?? 0 },
95
+ })
96
+ const { expected, collected, outcome, settled, ...partialSettlement } = settlement
97
+ const currencies = Array.from(
98
+ new Set<isoly.Currency>([
99
+ ...Object.keys(expected?.amount ?? {}),
100
+ ...Object.keys(collected?.amount ?? {}),
101
+ ...Object.keys(settled?.paid ?? {}),
102
+ ...Object.keys(outcome.amount),
103
+ ] as isoly.Currency[])
104
+ )
105
+ const totals = currencies.reduce((total, currency) => {
106
+ total[currency] = {
107
+ expected: totalToAmount(currency, expected),
108
+ ...(outcome ? { outcome: totalToAmount(currency, outcome) } : {}),
109
+ ...(collected
110
+ ? { collected: { ...totalToAmount(currency, collected), transactions: { net: "", fee: "" } } } //TODO: Find transactions?
111
+ : {}),
112
+ ...(settled ? { settled: { net: settled.paid[currency] ?? 0, transactions: settled.transactions } } : {}), //Find transactions?
113
+ }
114
+ return total
115
+ }, {} as Totals)
116
+ result = { ...partialSettlement, totals }
117
+ } else {
118
+ result = settlement
107
119
  }
120
+ return result
108
121
  }
109
122
  export const type = SettlementCreatable.type.extend<Settlement>({
110
123
  id: isly.string(),
111
124
  by: isly.string().optional(),
112
125
  created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
113
126
  status: Status.type,
114
- collected: Settlement.Total.type.optional(),
115
- outcome: Settlement.Total.type,
116
- settled: Settled.type.optional(),
117
127
  entries: Settlement.Entry.Summary.type,
118
128
  })
119
129
  export const is = type.is
@@ -11,6 +11,7 @@ export interface Storable {
11
11
  created: isoly.DateTime
12
12
  realm: Realm
13
13
  supplier: Supplier
14
+ link: string
14
15
  type: Category
15
16
  reference: string
16
17
  conditions?: Conditions
@@ -22,6 +23,7 @@ export namespace Storable {
22
23
  created: isly.fromIs("Treasury.Account.Storable", isoly.DateTime.is),
23
24
  realm: isly.fromIs("realm", Realm.is),
24
25
  supplier: isly.fromIs("supplier", Supplier.is),
26
+ link: isly.string(),
25
27
  type: Category.type,
26
28
  reference: isly.string(),
27
29
  conditions: Conditions.type.optional(),
@@ -1,12 +1,13 @@
1
1
  import { isly } from "isly"
2
2
  import { Balances } from "../../Balances"
3
- import { Counterbalance2 } from "../../Counterbalance2"
4
3
  import { Account } from "../Account"
5
4
  import { Warning } from "./Warning"
6
5
 
7
6
  export interface Fragment {
8
7
  warnings: Warning[]
9
- emoney: Balances.Balance & Counterbalance2
8
+ emoney: Balances.Balance
9
+ minted: Fragment.Coinage.Minted
10
+ burned: Fragment.Coinage.Burned
10
11
  fiat: {
11
12
  safe: number
12
13
  unsafe: number
@@ -17,13 +18,29 @@ export interface Fragment {
17
18
  }
18
19
  }
19
20
  export namespace Fragment {
21
+ export namespace Coinage {
22
+ export type LedgerAccount = string
23
+ export type Change = { account: Record<LedgerAccount, number>; amount: number }
24
+ export const change = isly.object<Change>({
25
+ account: isly.record(isly.string(), isly.number()),
26
+ amount: isly.number(),
27
+ })
28
+ type Source = string
29
+ export type Minted = Record<Source, Change>
30
+ export namespace Minted {
31
+ export const type = isly.record<Minted>(isly.string(), Fragment.Coinage.change)
32
+ }
33
+ type Sink = string
34
+ export type Burned = Record<Sink, Change>
35
+ export namespace Burned {
36
+ export const type = isly.record<Burned>(isly.string(), Fragment.Coinage.change)
37
+ }
38
+ }
20
39
  export const type = isly.object<Fragment>({
21
40
  warnings: Warning.type.array(),
22
- // there is a problem with isly.intersection, but isly.union works for this case
23
- emoney: isly.union<Fragment["emoney"], Balances.Balance, Counterbalance2>(
24
- Balances.Balance.type,
25
- Counterbalance2.type
26
- ),
41
+ emoney: Balances.Balance.type,
42
+ minted: Fragment.Coinage.Minted.type,
43
+ burned: Fragment.Coinage.Burned.type,
27
44
  fiat: isly.object({
28
45
  safe: isly.number(),
29
46
  unsafe: isly.number(),
@@ -7,8 +7,7 @@ import { Warning as SnapshotWarning } from "./Warning"
7
7
  export type Snapshot = Partial<Record<isoly.Currency, Snapshot.Fragment>>
8
8
 
9
9
  export namespace Snapshot {
10
- export type Fragment = SnapshotFragment
11
- export const Fragment = SnapshotFragment
10
+ export import Fragment = SnapshotFragment
12
11
  export type Warning = SnapshotWarning
13
12
  export const Warning = SnapshotWarning
14
13
  export type Emoney = SnapshotEmoney
package/Treasury/index.ts CHANGED
@@ -17,13 +17,7 @@ export namespace Treasury {
17
17
  export type Transaction = TreasuryTransaction
18
18
  export type Balance = TreasuryBalance
19
19
  export const Balance = TreasuryBalance
20
- export type Snapshot = TreasurySnapshot
21
- export const Snapshot = TreasurySnapshot
22
- export namespace Snapshot {
23
- export type Fragment = TreasurySnapshot.Fragment
24
- export type Warning = TreasurySnapshot.Warning
25
- export type Emoney = TreasurySnapshot.Emoney
26
- }
20
+ export import Snapshot = TreasurySnapshot
27
21
  export namespace Account {
28
22
  export type Creatable = TreasuryAccount.Creatable
29
23
  export const Creatable = TreasuryAccount.Creatable
@@ -5,14 +5,12 @@ export type Counterbalance2 = {
5
5
  burned: Partial<Record<Counterbalance2.Sink, number>>;
6
6
  };
7
7
  export declare namespace Counterbalance2 {
8
- const sources: readonly ["paxgiro", "clearbank", "internal"];
9
- type Source = `${typeof sources[number]}-${string}`;
10
- const Source: isly.Type<`paxgiro-${string}` | `clearbank-${string}` | `internal-${string}`>;
11
- const sinks: readonly ["paxgiro", "clearbank", "internal"];
12
- type Sink = `${typeof sinks[number]}-${string}`;
13
- const Sink: isly.Type<`paxgiro-${string}` | `clearbank-${string}` | `internal-${string}`>;
8
+ type Source = string;
9
+ const Source: isly.Type<string>;
10
+ type Sink = string;
11
+ const Sink: isly.Type<string>;
14
12
  const type: isly.object.ExtendableType<Counterbalance2>;
15
13
  type Link = Source | Sink;
16
- const Link: isly.Type<Link>;
14
+ const Link: isly.Type<string>;
17
15
  function add(currency: isoly.Currency, addendee: Counterbalance2, addend: Counterbalance2): Counterbalance2;
18
16
  }
@@ -1,23 +1,14 @@
1
1
  import { isoly } from "isoly";
2
2
  import { isly } from "isly";
3
- import { Supplier } from "./Supplier";
4
3
  export var Counterbalance2;
5
4
  (function (Counterbalance2) {
6
- Counterbalance2.sources = [...Supplier.names, "internal"];
7
- Counterbalance2.Source = isly.fromIs("Source", (value) => {
8
- const result = !value ? false : typeof value == "string" && value.split("-");
9
- return result && result.length == 2 && Counterbalance2.sources.includes(result[0]) && typeof result[1] == "string";
10
- });
11
- Counterbalance2.sinks = [...Supplier.names, "internal"];
12
- Counterbalance2.Sink = isly.fromIs("Sink", (value) => {
13
- const result = !value ? false : typeof value == "string" && value.split("-");
14
- return result && result.length == 2 && Counterbalance2.sinks.includes(result[0]) && typeof result[1] == "string";
15
- });
5
+ Counterbalance2.Source = isly.string();
6
+ Counterbalance2.Sink = isly.string();
16
7
  Counterbalance2.type = isly.object({
17
8
  minted: isly.record(Counterbalance2.Source, isly.number()),
18
9
  burned: isly.record(Counterbalance2.Sink, isly.number()),
19
10
  });
20
- Counterbalance2.Link = isly.union(Counterbalance2.Source, Counterbalance2.Sink);
11
+ Counterbalance2.Link = isly.string();
21
12
  function add(currency, addendee, addend) {
22
13
  const result = { minted: { ...addend.minted }, burned: { ...addend.burned } };
23
14
  for (const [source, value] of Object.entries(addendee["minted"])) {
@@ -1 +1 @@
1
- {"version":3,"file":"Counterbalance2.js","sourceRoot":"../","sources":["Counterbalance2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,QAAQ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E,CAAC;YACpF,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAC/F,CAAC;QACD,OAAO,MAAM,CAAA;IACd,CAAC;IATe,mBAAG,MASlB,CAAA;AACF,CAAC,EArBgB,eAAe,KAAf,eAAe,QAqB/B"}
@@ -8,7 +8,7 @@ export type Changes = Partial<Record<Balances.Balance.Entry, Change>> & Record<C
8
8
  export declare namespace Changes {
9
9
  namespace Entry {
10
10
  type Counterbalance = `${Counterbalance2.Link}-${isoly.DateTime}`;
11
- const Counterbalance: isly.Type<`paxgiro-${string}-${string}` | `clearbank-${string}-${string}` | `internal-${string}-${string}`>;
11
+ const Counterbalance: isly.Type<`${string}-${string}`>;
12
12
  function split(counterbalance: Counterbalance): [Counterbalance2.Link, isoly.DateTime];
13
13
  }
14
14
  type Entry = Balances.Balance.Entry | Entry.Counterbalance | Counterbalances.Counterbalance.Entry.Settlement;
@@ -0,0 +1,12 @@
1
+ import { isoly } from "isoly";
2
+ import { isly } from "isly";
3
+ export type Amount = {
4
+ net: number;
5
+ fee: {
6
+ other: number;
7
+ };
8
+ };
9
+ export declare namespace Amount {
10
+ const type: isly.object.ExtendableType<Amount>;
11
+ function add(currency: isoly.Currency, addendee: Amount, addend: Partial<Amount>): Amount;
12
+ }
@@ -0,0 +1,17 @@
1
+ import { isoly } from "isoly";
2
+ import { isly } from "isly";
3
+ export var Amount;
4
+ (function (Amount) {
5
+ Amount.type = isly.object({
6
+ net: isly.number(),
7
+ fee: isly.object({ other: isly.number() }),
8
+ });
9
+ function add(currency, addendee, addend) {
10
+ const result = { ...addendee };
11
+ result.net = isoly.Currency.add(currency, result.net, addend.net ?? 0);
12
+ result.fee.other = isoly.Currency.add(currency, result.fee.other, addend.fee?.other ?? 0);
13
+ return result;
14
+ }
15
+ Amount.add = add;
16
+ })(Amount || (Amount = {}));
17
+ //# sourceMappingURL=Amount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Amount.js","sourceRoot":"../","sources":["Settlement/Amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAQ3B,MAAM,KAAW,MAAM,CAWtB;AAXD,WAAiB,MAAM;IACT,WAAI,GAAG,IAAI,CAAC,MAAM,CAAS;QACvC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;QAClB,GAAG,EAAE,IAAI,CAAC,MAAM,CAAgB,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;KACzD,CAAC,CAAA;IACF,SAAgB,GAAG,CAAC,QAAwB,EAAE,QAAgB,EAAE,MAAuB;QACtF,MAAM,MAAM,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAA;QAC9B,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QACtE,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC,CAAA;QACzF,OAAO,MAAM,CAAA;IACd,CAAC;IALe,UAAG,MAKlB,CAAA;AACF,CAAC,EAXgB,MAAM,KAAN,MAAM,QAWtB"}
@@ -1,9 +1,9 @@
1
1
  import { isly } from "isly";
2
2
  import { Card } from "../Card";
3
3
  import { Batch } from "./Batch";
4
- import { Total } from "./Total";
4
+ import { Totals } from "./Totals";
5
5
  export interface Creatable {
6
- expected?: Total;
6
+ totals: Totals;
7
7
  processor: Card.Stack;
8
8
  references?: string[];
9
9
  batch: Batch;
@@ -1,11 +1,11 @@
1
1
  import { isly } from "isly";
2
2
  import { Card } from "../Card";
3
3
  import { Batch } from "./Batch";
4
- import { Total } from "./Total";
4
+ import { Totals } from "./Totals";
5
5
  export var Creatable;
6
6
  (function (Creatable) {
7
7
  Creatable.type = isly.object({
8
- expected: Total.type.optional(),
8
+ totals: Totals.type,
9
9
  processor: Card.Stack.type,
10
10
  references: isly.string().array().optional(),
11
11
  batch: Batch.type,