@voltro/plugin-economy 0.0.0-stage → 0.88.0
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.
- package/CHANGELOG.md +24492 -0
- package/LICENSE +61 -0
- package/README.md +2719 -2
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +9841 -0
- package/dist/amount.js +20 -0
- package/dist/appleIap.server.js +262 -0
- package/dist/appleIapNotifications.server.js +162 -0
- package/dist/appleIapTrust.server.js +30 -0
- package/dist/bundleValue.server.js +112 -0
- package/dist/canonicalDataJson.js +10 -0
- package/dist/capture.js +53 -0
- package/dist/codePort.fixture.js +123 -0
- package/dist/codeStore.server.js +439 -0
- package/dist/codeTables.entity.js +43 -0
- package/dist/codes.d.ts +150 -0
- package/dist/codes.js +82 -0
- package/dist/components.d.ts +397 -0
- package/dist/components.js +283 -0
- package/dist/consistency.server.js +115 -0
- package/dist/containerStore.server.js +687 -0
- package/dist/containerStore.testFixtures.js +75 -0
- package/dist/containerTables.entity.js +45 -0
- package/dist/containers.d.ts +311 -0
- package/dist/containers.fixture.js +128 -0
- package/dist/containers.js +214 -0
- package/dist/containers.server.js +39 -0
- package/dist/containersPort.fixture.js +74 -0
- package/dist/currency.js +32 -0
- package/dist/declarationFixtures.js +61 -0
- package/dist/economy-app/events/economy.refundReversed.event.ts +1 -0
- package/dist/economy-app/events/economy.refunded.event.ts +1 -0
- package/dist/economyPort.fixture.js +124 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +21 -0
- package/dist/events.d.ts +46 -0
- package/dist/events.js +1 -0
- package/dist/googleIap.server.js +391 -0
- package/dist/googleIapNotifications.server.js +130 -0
- package/dist/googleIapSubscription.server.js +183 -0
- package/dist/iap.d.ts +309 -0
- package/dist/iap.js +303 -0
- package/dist/iap.testFixtures.js +144 -0
- package/dist/iapAccountTables.entity.js +39 -0
- package/dist/iapAccounts.server.js +200 -0
- package/dist/iapBinding.server.js +523 -0
- package/dist/iapCheckout.server.js +97 -0
- package/dist/iapCompletion.server.js +55 -0
- package/dist/iapCurrentState.server.js +107 -0
- package/dist/iapCurrentState.testFixtures.js +22 -0
- package/dist/iapCurrentStatePort.fixture.js +63 -0
- package/dist/iapEntitlements.d.ts +79 -0
- package/dist/iapEntitlements.js +57 -0
- package/dist/iapEntitlements.server.js +48 -0
- package/dist/iapEntitlementsBinding.server.js +105 -0
- package/dist/iapEntitlementsPort.fixture.js +80 -0
- package/dist/iapInstalledEntitlements.testFixtures.js +75 -0
- package/dist/iapInstalledNotifications.testFixtures.js +93 -0
- package/dist/iapInventoryRefunds.server.js +261 -0
- package/dist/iapNotificationCustodyPort.fixture.js +67 -0
- package/dist/iapNotificationPort.fixture.js +73 -0
- package/dist/iapNotificationProcessor.server.js +134 -0
- package/dist/iapNotificationProcessor.testFixtures.js +63 -0
- package/dist/iapNotificationProcessorPort.fixture.js +55 -0
- package/dist/iapNotificationSchedule.server.js +69 -0
- package/dist/iapNotificationStore.server.js +352 -0
- package/dist/iapNotificationStore.testFixtures.js +31 -0
- package/dist/iapNotificationTables.entity.js +48 -0
- package/dist/iapNotificationTarget.server.js +36 -0
- package/dist/iapNotificationTarget.testFixtures.js +29 -0
- package/dist/iapNotifications.d.ts +644 -0
- package/dist/iapNotifications.js +6 -0
- package/dist/iapNotifications.server.js +95 -0
- package/dist/iapNotificationsBinding.server.js +232 -0
- package/dist/iapNotificationsSystemPort.fixture.js +50 -0
- package/dist/iapPlugin.testFixtures.js +59 -0
- package/dist/iapPort.fixture.js +74 -0
- package/dist/iapProviderCapture.server.js +17 -0
- package/dist/iapRecovery.d.ts +146 -0
- package/dist/iapRecovery.js +89 -0
- package/dist/iapRefundEventDelivery.server.js +82 -0
- package/dist/iapRefundEvents.js +44 -0
- package/dist/iapRefundEventsPort.fixture.js +59 -0
- package/dist/iapRefundPort.fixture.js +54 -0
- package/dist/iapRefundTables.entity.js +55 -0
- package/dist/iapRefunds.d.ts +755 -0
- package/dist/iapRefunds.js +6 -0
- package/dist/iapRefunds.server.js +553 -0
- package/dist/iapRefunds.testFixtures.js +64 -0
- package/dist/iapSpendAdmission.server.js +98 -0
- package/dist/iapStore.server.js +740 -0
- package/dist/iapStore.testFixtures.js +127 -0
- package/dist/iapTables.entity.js +80 -0
- package/dist/iapVerification.server.js +120 -0
- package/dist/index.d.ts +2984 -0
- package/dist/index.js +15 -0
- package/dist/intentionRecovery.js +133 -0
- package/dist/ledger.js +77 -0
- package/dist/loyalty.d.ts +274 -0
- package/dist/loyalty.fixture.js +92 -0
- package/dist/loyalty.js +311 -0
- package/dist/loyaltyBinding.server.js +203 -0
- package/dist/loyaltyPort.fixture.js +86 -0
- package/dist/loyaltyShopSource.server.js +90 -0
- package/dist/loyaltyStore.server.js +552 -0
- package/dist/loyaltyStore.testFixtures.js +82 -0
- package/dist/loyaltyTables.entity.js +49 -0
- package/dist/offerMerchandising.fixture.js +114 -0
- package/dist/offerMerchandising.js +282 -0
- package/dist/offerPolicies.d.ts +441 -0
- package/dist/offerPolicies.fixture.js +53 -0
- package/dist/offerPolicies.js +267 -0
- package/dist/piggyBanks.d.ts +272 -0
- package/dist/piggyBanks.fixture.js +70 -0
- package/dist/piggyBanks.js +200 -0
- package/dist/piggyBinding.server.js +204 -0
- package/dist/piggyPort.fixture.js +72 -0
- package/dist/piggyStore.server.js +610 -0
- package/dist/piggyStore.testFixtures.js +97 -0
- package/dist/piggyTables.entity.js +40 -0
- package/dist/plugin.js +1047 -0
- package/dist/port.js +12 -0
- package/dist/price.d.ts +99 -0
- package/dist/price.js +143 -0
- package/dist/purchaseRecovery.js +55 -0
- package/dist/reports.server.js +114 -0
- package/dist/rpc.d.ts +3201 -0
- package/dist/rpc.js +1200 -0
- package/dist/sanctionsTradeAuthority.server.js +79 -0
- package/dist/server.d.ts +3856 -0
- package/dist/server.js +43 -0
- package/dist/shop.d.ts +279 -0
- package/dist/shop.js +195 -0
- package/dist/shop.testFixtures.js +113 -0
- package/dist/shopPort.fixture.js +71 -0
- package/dist/shopPresentation.js +67 -0
- package/dist/shopStore.server.js +623 -0
- package/dist/shopTables.entity.js +62 -0
- package/dist/shopUiCopy.js +56 -0
- package/dist/spendLimits.d.ts +140 -0
- package/dist/spendLimits.fixture.js +52 -0
- package/dist/spendLimits.js +154 -0
- package/dist/spendLimitsPort.fixture.js +119 -0
- package/dist/subscriptionBinding.server.js +210 -0
- package/dist/subscriptionStore.server.js +642 -0
- package/dist/subscriptionStore.testFixtures.js +71 -0
- package/dist/subscriptionTables.entity.js +36 -0
- package/dist/subscriptions.d.ts +394 -0
- package/dist/subscriptions.fixture.js +96 -0
- package/dist/subscriptions.js +212 -0
- package/dist/subscriptionsPort.fixture.js +75 -0
- package/dist/systemFixtures.js +88 -0
- package/dist/tables.entity.js +82 -0
- package/dist/testing.d.ts +4615 -0
- package/dist/testing.js +29 -0
- package/dist/tradeAuthority.server.js +171 -0
- package/dist/tradeBinding.server.js +200 -0
- package/dist/tradeComponents.js +341 -0
- package/dist/tradeEscrow.server.js +231 -0
- package/dist/tradeEscrow.testFixtures.js +132 -0
- package/dist/tradeExpiry.server.js +42 -0
- package/dist/tradeRecovery.js +47 -0
- package/dist/tradeStore.server.js +749 -0
- package/dist/tradeStore.testFixtures.js +72 -0
- package/dist/tradeTables.entity.js +65 -0
- package/dist/tradeUiCopy.js +78 -0
- package/dist/trades.d.ts +246 -0
- package/dist/trades.fixture.js +102 -0
- package/dist/trades.js +288 -0
- package/dist/tradesPort.fixture.js +93 -0
- package/dist/walletEscrow.js +105 -0
- package/dist/walletEscrow.server.js +375 -0
- package/dist/walletKeys.server.js +4 -0
- package/dist/walletStore.js +570 -0
- package/dist/web.d.ts +2257 -0
- package/dist/web.js +8 -0
- package/package.json +161 -4
package/dist/trades.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
import { captureBoundMethods as t, dataList as n, dataObject as r, identifier as i } from "./capture.js";
|
|
3
|
+
import { nonNegativeAmount as a, positiveAmount as o } from "./amount.js";
|
|
4
|
+
import { captureCurrencies as s } from "./currency.js";
|
|
5
|
+
import { shopInteger as c } from "./shop.js";
|
|
6
|
+
import { Context as l } from "effect";
|
|
7
|
+
// src/trades.ts
|
|
8
|
+
var u = (t) => {
|
|
9
|
+
let n = r(t, [
|
|
10
|
+
"version",
|
|
11
|
+
"taxBps",
|
|
12
|
+
"maxDurationMs",
|
|
13
|
+
"minTrustScore"
|
|
14
|
+
]), a = i(n.version);
|
|
15
|
+
if (a === "default.v1") throw e("invalid_input");
|
|
16
|
+
return Object.freeze({
|
|
17
|
+
version: a,
|
|
18
|
+
taxBps: c(n.taxBps ?? 0, 0, 1e4),
|
|
19
|
+
maxDurationMs: c(n.maxDurationMs ?? 864e5, 1, 316224e5),
|
|
20
|
+
minTrustScore: c(n.minTrustScore ?? 0, 0, 1e6)
|
|
21
|
+
});
|
|
22
|
+
}, d = (t) => {
|
|
23
|
+
let a = r(t, ["items", "currencies"]), s = Object.freeze(n(a.items, 32).map((e) => {
|
|
24
|
+
let t = r(e, ["instanceId", "qty"]);
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
instanceId: i(t.instanceId),
|
|
27
|
+
qty: c(t.qty, 1, 1e6)
|
|
28
|
+
});
|
|
29
|
+
}).sort((e, t) => e.instanceId < t.instanceId ? -1 : +(e.instanceId > t.instanceId))), l = Object.freeze(n(a.currencies, 32).map((e) => {
|
|
30
|
+
let t = r(e, ["currency", "amount"]);
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
currency: i(t.currency),
|
|
33
|
+
amount: o(t.amount).toString()
|
|
34
|
+
});
|
|
35
|
+
}).sort((e, t) => e.currency < t.currency ? -1 : +(e.currency > t.currency)));
|
|
36
|
+
if (new Set(s.map((e) => e.instanceId)).size !== s.length || new Set(l.map((e) => e.currency)).size !== l.length) throw e("invalid_input");
|
|
37
|
+
return Object.freeze({
|
|
38
|
+
items: s,
|
|
39
|
+
currencies: l
|
|
40
|
+
});
|
|
41
|
+
}, f = (t, n) => {
|
|
42
|
+
let r = d(t), i = s(n);
|
|
43
|
+
for (let t of r.currencies) {
|
|
44
|
+
let n = i.find((e) => e.id === t.currency);
|
|
45
|
+
if (!n || BigInt(t.amount) > BigInt(n.cap)) throw e("invalid_currency");
|
|
46
|
+
}
|
|
47
|
+
return r;
|
|
48
|
+
}, p = (t) => {
|
|
49
|
+
let n = r(t, [
|
|
50
|
+
"toId",
|
|
51
|
+
"offered",
|
|
52
|
+
"requested",
|
|
53
|
+
"durationMs",
|
|
54
|
+
"requestId"
|
|
55
|
+
]), a = d(n.offered), o = d(n.requested);
|
|
56
|
+
if (!a.items.length && !a.currencies.length && !o.items.length && !o.currencies.length || a.items.some((e) => o.items.some((t) => t.instanceId === e.instanceId))) throw e("invalid_input");
|
|
57
|
+
return Object.freeze({
|
|
58
|
+
toId: n.toId === null ? null : i(n.toId),
|
|
59
|
+
offered: a,
|
|
60
|
+
requested: o,
|
|
61
|
+
durationMs: c(n.durationMs, 1, 316224e5),
|
|
62
|
+
requestId: i(n.requestId)
|
|
63
|
+
});
|
|
64
|
+
}, m = (e, t, n) => {
|
|
65
|
+
let r = u(n), i = p(e);
|
|
66
|
+
return Object.freeze({
|
|
67
|
+
...i,
|
|
68
|
+
offered: f(i.offered, t),
|
|
69
|
+
requested: f(i.requested, t),
|
|
70
|
+
durationMs: c(i.durationMs, 1, r.maxDurationMs)
|
|
71
|
+
});
|
|
72
|
+
}, h = (t) => {
|
|
73
|
+
if (typeof t != "string" || !/^[a-f0-9]{64}$/.test(t)) throw e("invalid_input");
|
|
74
|
+
return t;
|
|
75
|
+
}, g = (e) => {
|
|
76
|
+
let t = r(e, [
|
|
77
|
+
"tradeId",
|
|
78
|
+
"tradeDigest",
|
|
79
|
+
"requestId"
|
|
80
|
+
]);
|
|
81
|
+
return Object.freeze({
|
|
82
|
+
tradeId: i(t.tradeId),
|
|
83
|
+
tradeDigest: h(t.tradeDigest),
|
|
84
|
+
requestId: i(t.requestId)
|
|
85
|
+
});
|
|
86
|
+
}, _ = (e) => {
|
|
87
|
+
let t = r(e, ["tradeId", "requestId"]);
|
|
88
|
+
return Object.freeze({
|
|
89
|
+
tradeId: i(t.tradeId),
|
|
90
|
+
requestId: i(t.requestId)
|
|
91
|
+
});
|
|
92
|
+
}, v = ({ amount: e, rules: t }) => (o(e) * BigInt(t.taxBps) + 9999n) / 10000n, y = (t, n = v) => {
|
|
93
|
+
let s = r(t, [
|
|
94
|
+
"currency",
|
|
95
|
+
"amount",
|
|
96
|
+
"rules"
|
|
97
|
+
]), c = u(s.rules), l = i(s.currency), d = o(s.amount);
|
|
98
|
+
if (typeof n != "function") throw e("invalid_input");
|
|
99
|
+
let f = Object.freeze({
|
|
100
|
+
currency: l,
|
|
101
|
+
amount: d.toString(),
|
|
102
|
+
rules: c
|
|
103
|
+
}), p = a(n(f)), m = a(v(f));
|
|
104
|
+
if (p > d || p > m) throw e("invalid_input");
|
|
105
|
+
return Object.freeze({
|
|
106
|
+
currency: l,
|
|
107
|
+
gross: d.toString(),
|
|
108
|
+
net: (d - p).toString(),
|
|
109
|
+
tax: p.toString()
|
|
110
|
+
});
|
|
111
|
+
}, b = (e, t, n, r) => e.items.every((e) => {
|
|
112
|
+
let i = t.items.find((t) => t.instanceId === e.instanceId);
|
|
113
|
+
return i !== void 0 && i.qty >= e.qty && i.tradable && (!i.locked || i.reservationId === r) && (i.expiresAt === null || i.expiresAt > n);
|
|
114
|
+
}), x = (e) => e.at >= e.createdAt && e.at < e.expiresAt && e.expiresAt - e.createdAt <= e.rules.maxDurationMs && e.proposerId !== e.accepterId && (e.proposedToId === null || e.proposedToId === e.accepterId) && e.proposer.allowed && e.accepter.allowed && e.proposer.trustScore >= e.rules.minTrustScore && e.accepter.trustScore >= e.rules.minTrustScore && b(e.offered, e.proposer, e.at, e.tradeId) && b(e.requested, e.accepter, e.at, e.tradeId), S = (t, a, o) => {
|
|
115
|
+
let s = r(t, [
|
|
116
|
+
"tenantId",
|
|
117
|
+
"ownerId",
|
|
118
|
+
"allowed",
|
|
119
|
+
"trustScore",
|
|
120
|
+
"items"
|
|
121
|
+
]);
|
|
122
|
+
if (s.tenantId !== a || s.ownerId !== o || typeof s.allowed != "boolean") throw e("invalid_record");
|
|
123
|
+
let l = Object.freeze(n(s.items, 1e4).map((t) => {
|
|
124
|
+
let n = r(t, [
|
|
125
|
+
"instanceId",
|
|
126
|
+
"itemId",
|
|
127
|
+
"qty",
|
|
128
|
+
"tradable",
|
|
129
|
+
"locked",
|
|
130
|
+
"reservationId",
|
|
131
|
+
"expiresAt"
|
|
132
|
+
]);
|
|
133
|
+
if (typeof n.tradable != "boolean" || typeof n.locked != "boolean" || n.locked === !1 && n.reservationId !== null) throw e("invalid_record");
|
|
134
|
+
return Object.freeze({
|
|
135
|
+
instanceId: i(n.instanceId),
|
|
136
|
+
itemId: i(n.itemId),
|
|
137
|
+
qty: c(n.qty, 1, 1e6),
|
|
138
|
+
tradable: n.tradable,
|
|
139
|
+
locked: n.locked,
|
|
140
|
+
reservationId: n.reservationId === null ? null : i(n.reservationId),
|
|
141
|
+
expiresAt: n.expiresAt === null ? null : c(n.expiresAt, 0, 864e13)
|
|
142
|
+
});
|
|
143
|
+
}));
|
|
144
|
+
if (new Set(l.map((e) => e.instanceId)).size !== l.length) throw e("invalid_record");
|
|
145
|
+
return Object.freeze({
|
|
146
|
+
tenantId: a,
|
|
147
|
+
ownerId: o,
|
|
148
|
+
allowed: s.allowed,
|
|
149
|
+
trustScore: c(s.trustScore, 0, 1e6),
|
|
150
|
+
items: l
|
|
151
|
+
});
|
|
152
|
+
}, C = (t, n = x) => {
|
|
153
|
+
let a = r(t, [
|
|
154
|
+
"tenantId",
|
|
155
|
+
"proposerId",
|
|
156
|
+
"accepterId",
|
|
157
|
+
"tradeId",
|
|
158
|
+
"proposedToId",
|
|
159
|
+
"createdAt",
|
|
160
|
+
"at",
|
|
161
|
+
"expiresAt",
|
|
162
|
+
"rules",
|
|
163
|
+
"currencies",
|
|
164
|
+
"offered",
|
|
165
|
+
"requested",
|
|
166
|
+
"proposer",
|
|
167
|
+
"accepter"
|
|
168
|
+
]), o = i(a.tenantId), l = i(a.proposerId), d = i(a.accepterId), p = u(a.rules), m = s(a.currencies), h = i(a.tradeId), g = c(a.createdAt, 0, 864e13), _ = c(a.at, 0, 864e13), v = c(a.expiresAt, 0, 864e13), y = Object.freeze({
|
|
169
|
+
tenantId: o,
|
|
170
|
+
proposerId: l,
|
|
171
|
+
accepterId: d,
|
|
172
|
+
tradeId: h,
|
|
173
|
+
createdAt: g,
|
|
174
|
+
proposedToId: a.proposedToId === null ? null : i(a.proposedToId),
|
|
175
|
+
at: _,
|
|
176
|
+
expiresAt: v,
|
|
177
|
+
rules: p,
|
|
178
|
+
currencies: m,
|
|
179
|
+
offered: f(a.offered, m),
|
|
180
|
+
requested: f(a.requested, m),
|
|
181
|
+
proposer: S(a.proposer, o, l),
|
|
182
|
+
accepter: S(a.accepter, o, d)
|
|
183
|
+
});
|
|
184
|
+
if (typeof n != "function") throw e("invalid_input");
|
|
185
|
+
let b = n(y);
|
|
186
|
+
if (typeof b != "boolean" || b && !x(y)) throw e("invalid_input");
|
|
187
|
+
return b;
|
|
188
|
+
}, w = class extends l.Service()("@voltro/TradesPort") {}, T = (e) => t(e, [
|
|
189
|
+
"propose",
|
|
190
|
+
"accept",
|
|
191
|
+
"cancel",
|
|
192
|
+
"mine",
|
|
193
|
+
"receipt",
|
|
194
|
+
"rebuild",
|
|
195
|
+
"exportSubject",
|
|
196
|
+
"eraseSubject"
|
|
197
|
+
]), E = (t) => {
|
|
198
|
+
let s = r(t, [
|
|
199
|
+
"tradeId",
|
|
200
|
+
"tradeDigest",
|
|
201
|
+
"proposerId",
|
|
202
|
+
"toId",
|
|
203
|
+
"offered",
|
|
204
|
+
"requested",
|
|
205
|
+
"createdAt",
|
|
206
|
+
"expiresAt",
|
|
207
|
+
"state",
|
|
208
|
+
"accepterId",
|
|
209
|
+
"rulesVersion",
|
|
210
|
+
"taxes"
|
|
211
|
+
], "invalid_record"), l = d(s.offered), u = d(s.requested), f = i(s.proposerId), p = s.toId === null ? null : i(s.toId), m = s.accepterId === null ? null : i(s.accepterId), g = c(s.createdAt, 0, 864e13), _ = c(s.expiresAt, 0, 864e13), v = i(s.rulesVersion), y = h(s.tradeDigest);
|
|
212
|
+
if (![
|
|
213
|
+
"proposed",
|
|
214
|
+
"accepted",
|
|
215
|
+
"cancelled",
|
|
216
|
+
"expired"
|
|
217
|
+
].includes(String(s.state)) || v === "default.v1" || _ <= g || _ - g > 316224e5 || p === f || !l.items.length && !l.currencies.length && !u.items.length && !u.currencies.length || l.items.some((e) => u.items.some((t) => t.instanceId === e.instanceId)) || (s.state === "accepted" ? m === null || m === f || p !== null && p !== m : m !== null)) throw e("invalid_record");
|
|
218
|
+
let b = Object.freeze(n(s.taxes, 64).map((t) => {
|
|
219
|
+
let n = r(t, [
|
|
220
|
+
"leg",
|
|
221
|
+
"currency",
|
|
222
|
+
"gross",
|
|
223
|
+
"net",
|
|
224
|
+
"tax"
|
|
225
|
+
], "invalid_record");
|
|
226
|
+
if (n.leg !== "offered" && n.leg !== "requested") throw e("invalid_record");
|
|
227
|
+
let s = o(n.gross), c = a(n.net), l = a(n.tax);
|
|
228
|
+
if (s !== c + l) throw e("invalid_record");
|
|
229
|
+
return Object.freeze({
|
|
230
|
+
leg: n.leg,
|
|
231
|
+
currency: i(n.currency),
|
|
232
|
+
gross: s.toString(),
|
|
233
|
+
net: c.toString(),
|
|
234
|
+
tax: l.toString()
|
|
235
|
+
});
|
|
236
|
+
})), x = [...l.currencies.map((e) => ({
|
|
237
|
+
leg: "offered",
|
|
238
|
+
...e
|
|
239
|
+
})), ...u.currencies.map((e) => ({
|
|
240
|
+
leg: "requested",
|
|
241
|
+
...e
|
|
242
|
+
}))];
|
|
243
|
+
if (b.length !== x.length || b.some((e, t) => e.leg !== x[t].leg || e.currency !== x[t].currency || e.gross !== x[t].amount)) throw e("invalid_record");
|
|
244
|
+
return Object.freeze({
|
|
245
|
+
tradeId: i(s.tradeId),
|
|
246
|
+
tradeDigest: y,
|
|
247
|
+
proposerId: f,
|
|
248
|
+
toId: p,
|
|
249
|
+
offered: l,
|
|
250
|
+
requested: u,
|
|
251
|
+
createdAt: g,
|
|
252
|
+
expiresAt: _,
|
|
253
|
+
state: s.state,
|
|
254
|
+
accepterId: m,
|
|
255
|
+
rulesVersion: v,
|
|
256
|
+
taxes: b
|
|
257
|
+
});
|
|
258
|
+
}, D = (e) => {
|
|
259
|
+
let t = r(e, [
|
|
260
|
+
"operationId",
|
|
261
|
+
"requestId",
|
|
262
|
+
"trade"
|
|
263
|
+
], "invalid_record");
|
|
264
|
+
return Object.freeze({
|
|
265
|
+
operationId: i(t.operationId),
|
|
266
|
+
requestId: i(t.requestId),
|
|
267
|
+
trade: E(t.trade)
|
|
268
|
+
});
|
|
269
|
+
}, O = (t) => {
|
|
270
|
+
let n = r(t, [
|
|
271
|
+
"requestId",
|
|
272
|
+
"state",
|
|
273
|
+
"receipt"
|
|
274
|
+
], "invalid_record"), a = i(n.requestId);
|
|
275
|
+
if (n.state === "not-observed" && !Object.hasOwn(n, "receipt")) return Object.freeze({
|
|
276
|
+
requestId: a,
|
|
277
|
+
state: "not-observed"
|
|
278
|
+
});
|
|
279
|
+
if (n.state !== "fulfilled") throw e("invalid_record");
|
|
280
|
+
let o = D(n.receipt);
|
|
281
|
+
if (o.requestId !== a) throw e("invalid_record");
|
|
282
|
+
return Object.freeze({
|
|
283
|
+
requestId: a,
|
|
284
|
+
state: "fulfilled",
|
|
285
|
+
receipt: o
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
export { w as TradesPort, f as captureTradeLeg, O as captureTradeObservation, S as captureTradeParticipantAuthority, p as captureTradeProposeIntention, D as captureTradeReceipt, E as captureTradeView, T as captureTradesService, x as defaultTradeEligibilityPolicy, v as defaultTradeTaxPolicy, u as defineTradeRules, C as resolveTradeEligibility, y as resolveTradeTax, g as tradeAcceptIntent, _ as tradeCancelIntent, m as tradeProposeIntent };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { TradesPort as e } from "./trades.js";
|
|
2
|
+
import { EconomyPort as t } from "./port.js";
|
|
3
|
+
import { economyPlugin as n } from "./plugin.js";
|
|
4
|
+
import { tradeEscrowAt as r } from "./tradeEscrow.testFixtures.js";
|
|
5
|
+
import { tradeStoreFixture as i } from "./tradeStore.testFixtures.js";
|
|
6
|
+
import { Effect as a, Layer as o } from "effect";
|
|
7
|
+
import { InMemoryDataStore as s } from "@voltro/runtime";
|
|
8
|
+
// src/tradesPort.fixture.ts
|
|
9
|
+
var c = {
|
|
10
|
+
app: {
|
|
11
|
+
name: "trades-fixture",
|
|
12
|
+
type: "api",
|
|
13
|
+
voltroVersion: "0.83.1"
|
|
14
|
+
},
|
|
15
|
+
config: {},
|
|
16
|
+
env: {},
|
|
17
|
+
logger: {
|
|
18
|
+
info() {},
|
|
19
|
+
warn() {},
|
|
20
|
+
error() {},
|
|
21
|
+
debug() {}
|
|
22
|
+
}
|
|
23
|
+
}, l = a.gen(function* () {
|
|
24
|
+
let e = new s(), t = yield* a.promise(() => i(e, "fixture")), { currencies: o, economy: l, now: u, ...d } = t.options, f = r, p = n({
|
|
25
|
+
currencies: o,
|
|
26
|
+
now: () => f,
|
|
27
|
+
trades: d
|
|
28
|
+
});
|
|
29
|
+
return yield* a.promise(async () => {
|
|
30
|
+
await p.bindDataStore?.(e);
|
|
31
|
+
}), Object.freeze({
|
|
32
|
+
store: e,
|
|
33
|
+
base: t,
|
|
34
|
+
plugin: p,
|
|
35
|
+
advance: (e) => {
|
|
36
|
+
f = r + e;
|
|
37
|
+
},
|
|
38
|
+
close: a.suspend(() => p.onDeactivate?.(c))
|
|
39
|
+
});
|
|
40
|
+
}), u = o.effectContext(a.acquireRelease(l, (e) => e.close).pipe(a.flatMap((e) => o.build(e.plugin.services)))), d = Object.freeze({
|
|
41
|
+
kind: "port",
|
|
42
|
+
tag: e,
|
|
43
|
+
fakeLayer: u,
|
|
44
|
+
probe: {
|
|
45
|
+
run: () => a.scoped(a.gen(function* () {
|
|
46
|
+
let n = yield* e, r = yield* t, i = {
|
|
47
|
+
type: "user",
|
|
48
|
+
id: "a",
|
|
49
|
+
tenantId: "fixture"
|
|
50
|
+
}, a = yield* n.propose(i, {
|
|
51
|
+
toId: "b",
|
|
52
|
+
offered: {
|
|
53
|
+
items: [],
|
|
54
|
+
currencies: [{
|
|
55
|
+
currency: "gold",
|
|
56
|
+
amount: "30"
|
|
57
|
+
}]
|
|
58
|
+
},
|
|
59
|
+
requested: {
|
|
60
|
+
items: [],
|
|
61
|
+
currencies: [{
|
|
62
|
+
currency: "gold",
|
|
63
|
+
amount: "10"
|
|
64
|
+
}]
|
|
65
|
+
},
|
|
66
|
+
durationMs: 500,
|
|
67
|
+
requestId: "scoped.proposal"
|
|
68
|
+
}), o = {
|
|
69
|
+
tradeId: a.trade.tradeId,
|
|
70
|
+
tradeDigest: a.trade.tradeDigest,
|
|
71
|
+
requestId: "scoped.accept"
|
|
72
|
+
}, s = {
|
|
73
|
+
...i,
|
|
74
|
+
id: "b"
|
|
75
|
+
}, c = yield* n.accept(s, o), l = yield* n.accept(s, o), u = yield* n.receipt(s, { requestId: o.requestId }), d = yield* r.mine(i);
|
|
76
|
+
return {
|
|
77
|
+
same: c.operationId === l.operationId,
|
|
78
|
+
observed: u.state,
|
|
79
|
+
state: c.trade.state,
|
|
80
|
+
balance: d[0].balance,
|
|
81
|
+
tax: c.trade.taxes.map((e) => e.tax)
|
|
82
|
+
};
|
|
83
|
+
}).pipe(a.provide(u))),
|
|
84
|
+
expected: {
|
|
85
|
+
same: !0,
|
|
86
|
+
observed: "fulfilled",
|
|
87
|
+
state: "accepted",
|
|
88
|
+
balance: "79",
|
|
89
|
+
tax: ["1", "1"]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
export { u as tradesFakeLayer, l as tradesPortFixture, d as tradesPortSystemFixture };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { economyError as e } from "./errors.js";
|
|
2
|
+
import { dataObject as t, identifier as n } from "./capture.js";
|
|
3
|
+
import { nonNegativeAmount as r, positiveAmount as i } from "./amount.js";
|
|
4
|
+
import { captureAccount as a } from "./ledger.js";
|
|
5
|
+
// src/walletEscrow.ts
|
|
6
|
+
var o = (t) => {
|
|
7
|
+
let n = a(t);
|
|
8
|
+
if (n.kind !== "wallet") throw e("invalid_input");
|
|
9
|
+
return n;
|
|
10
|
+
}, s = (e) => {
|
|
11
|
+
let r = t(e, [
|
|
12
|
+
"tenantId",
|
|
13
|
+
"owner",
|
|
14
|
+
"reservationId",
|
|
15
|
+
"currency"
|
|
16
|
+
]);
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
tenantId: n(r.tenantId),
|
|
19
|
+
owner: o(r.owner),
|
|
20
|
+
reservationId: n(r.reservationId),
|
|
21
|
+
currency: n(r.currency)
|
|
22
|
+
});
|
|
23
|
+
}, c = (e) => {
|
|
24
|
+
let n = t(e, [
|
|
25
|
+
"tenantId",
|
|
26
|
+
"owner",
|
|
27
|
+
"reservationId",
|
|
28
|
+
"currency",
|
|
29
|
+
"amount"
|
|
30
|
+
]);
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
...s({
|
|
33
|
+
tenantId: n.tenantId,
|
|
34
|
+
owner: n.owner,
|
|
35
|
+
reservationId: n.reservationId,
|
|
36
|
+
currency: n.currency
|
|
37
|
+
}),
|
|
38
|
+
amount: i(n.amount).toString()
|
|
39
|
+
});
|
|
40
|
+
}, l = (n) => {
|
|
41
|
+
let r = t(n, [
|
|
42
|
+
"tenantId",
|
|
43
|
+
"owner",
|
|
44
|
+
"reservationId",
|
|
45
|
+
"currency",
|
|
46
|
+
"to"
|
|
47
|
+
]), i = s({
|
|
48
|
+
tenantId: r.tenantId,
|
|
49
|
+
owner: r.owner,
|
|
50
|
+
reservationId: r.reservationId,
|
|
51
|
+
currency: r.currency
|
|
52
|
+
}), a = o(r.to);
|
|
53
|
+
if (i.owner.ownerKind === a.ownerKind && i.owner.ownerId === a.ownerId) throw e("invalid_input");
|
|
54
|
+
return Object.freeze({
|
|
55
|
+
...i,
|
|
56
|
+
to: a
|
|
57
|
+
});
|
|
58
|
+
}, u = (i) => {
|
|
59
|
+
let a = t(i, [
|
|
60
|
+
"tenantId",
|
|
61
|
+
"owner",
|
|
62
|
+
"reservationId",
|
|
63
|
+
"currency",
|
|
64
|
+
"to",
|
|
65
|
+
"taxAmount",
|
|
66
|
+
"taxAccountId"
|
|
67
|
+
]), o = l({
|
|
68
|
+
tenantId: a.tenantId,
|
|
69
|
+
owner: a.owner,
|
|
70
|
+
reservationId: a.reservationId,
|
|
71
|
+
currency: a.currency,
|
|
72
|
+
to: a.to
|
|
73
|
+
}), s = n(a.taxAccountId ?? "escrow.tax.default");
|
|
74
|
+
if (!s.startsWith("escrow.tax.")) throw e("invalid_input");
|
|
75
|
+
return Object.freeze({
|
|
76
|
+
...o,
|
|
77
|
+
taxAmount: r(a.taxAmount).toString(),
|
|
78
|
+
taxAccountId: s
|
|
79
|
+
});
|
|
80
|
+
}, d = (n) => {
|
|
81
|
+
let r = t(n, [
|
|
82
|
+
"tenantId",
|
|
83
|
+
"owner",
|
|
84
|
+
"reservationId",
|
|
85
|
+
"currency",
|
|
86
|
+
"amount",
|
|
87
|
+
"to",
|
|
88
|
+
"taxAmount",
|
|
89
|
+
"taxAccountId"
|
|
90
|
+
]), a = u({
|
|
91
|
+
tenantId: r.tenantId,
|
|
92
|
+
owner: r.owner,
|
|
93
|
+
reservationId: r.reservationId,
|
|
94
|
+
currency: r.currency,
|
|
95
|
+
to: r.to,
|
|
96
|
+
taxAmount: r.taxAmount,
|
|
97
|
+
taxAccountId: r.taxAccountId
|
|
98
|
+
}), o = i(r.amount).toString();
|
|
99
|
+
if (BigInt(a.taxAmount) > BigInt(o)) throw e("invalid_amount");
|
|
100
|
+
return Object.freeze({
|
|
101
|
+
...a,
|
|
102
|
+
amount: o
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
export { o as captureEscrowWallet, s as captureWalletEscrowInput, c as captureWalletEscrowReserveInput, d as captureWalletEscrowReserveTaxSettleInput, l as captureWalletEscrowSettleInput, u as captureWalletEscrowTaxSettleInput };
|