@render-foundation/utils 0.0.197 → 0.0.199

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 (41) hide show
  1. package/CHANGELOG.md +310 -0
  2. package/lib/cjs/assertSecrets.js +43 -0
  3. package/lib/cjs/assertSecrets.js.map +1 -0
  4. package/lib/cjs/client/dispersed.js +123 -0
  5. package/lib/cjs/client/dispersed.js.map +1 -0
  6. package/lib/cjs/client/pg/v2Client.js +47 -1
  7. package/lib/cjs/client/pg/v2Client.js.map +1 -1
  8. package/lib/cjs/index.js +6 -2
  9. package/lib/cjs/index.js.map +1 -1
  10. package/lib/esm/src/assertSecrets.js +39 -0
  11. package/lib/esm/src/assertSecrets.js.map +1 -0
  12. package/lib/esm/src/client/dispersed.js +108 -0
  13. package/lib/esm/src/client/dispersed.js.map +1 -0
  14. package/lib/esm/src/client/pg/v2Client.js +40 -0
  15. package/lib/esm/src/client/pg/v2Client.js.map +1 -1
  16. package/lib/esm/src/index.js +6 -2
  17. package/lib/esm/src/index.js.map +1 -1
  18. package/lib/esm/tsconfig.esm.tsbuildinfo +1 -1
  19. package/lib/types/src/assertSecrets.d.ts +27 -0
  20. package/lib/types/src/assertSecrets.d.ts.map +1 -0
  21. package/lib/types/src/client/dispersed.d.ts +91 -0
  22. package/lib/types/src/client/dispersed.d.ts.map +1 -0
  23. package/lib/types/src/client/pg/v2Client.d.ts +21 -0
  24. package/lib/types/src/client/pg/v2Client.d.ts.map +1 -1
  25. package/lib/types/src/dbTypesV2.d.ts +13 -1
  26. package/lib/types/src/dbTypesV2.d.ts.map +1 -1
  27. package/lib/types/src/index.d.ts +3 -2
  28. package/lib/types/src/index.d.ts.map +1 -1
  29. package/package.json +2 -2
  30. package/lib/cjs/burn/burnAnalysis.js +0 -101
  31. package/lib/cjs/burn/burnAnalysis.js.map +0 -1
  32. package/lib/cjs/burn/burnCalculations.js +0 -140
  33. package/lib/cjs/burn/burnCalculations.js.map +0 -1
  34. package/lib/esm/src/burn/burnAnalysis.js +0 -90
  35. package/lib/esm/src/burn/burnAnalysis.js.map +0 -1
  36. package/lib/esm/src/burn/burnCalculations.js +0 -124
  37. package/lib/esm/src/burn/burnCalculations.js.map +0 -1
  38. package/lib/types/src/burn/burnAnalysis.d.ts +0 -51
  39. package/lib/types/src/burn/burnAnalysis.d.ts.map +0 -1
  40. package/lib/types/src/burn/burnCalculations.d.ts +0 -52
  41. package/lib/types/src/burn/burnCalculations.d.ts.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,310 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [3.10.2](https://github.com/StrataFoundation/strata/compare/v3.10.1...v3.10.2) (2022-08-10)
7
+
8
+ **Note:** Version bump only for package @strata-foundation/spl-utils
9
+
10
+
11
+
12
+
13
+
14
+ # [3.10.0](https://github.com/StrataFoundation/strata/compare/v3.9.12...v3.10.0) (2022-08-04)
15
+
16
+ **Note:** Version bump only for package @strata-foundation/spl-utils
17
+
18
+
19
+
20
+
21
+
22
+ ## [3.9.5](https://github.com/StrataFoundation/strata/compare/v3.9.4...v3.9.5) (2022-07-26)
23
+
24
+ **Note:** Version bump only for package @strata-foundation/spl-utils
25
+
26
+
27
+
28
+
29
+
30
+ ## [3.9.3](https://github.com/StrataFoundation/strata/compare/v3.9.2...v3.9.3) (2022-07-25)
31
+
32
+ **Note:** Version bump only for package @strata-foundation/spl-utils
33
+
34
+
35
+
36
+
37
+
38
+ # [3.9.0](https://github.com/StrataFoundation/strata/compare/v3.8.2...v3.9.0) (2022-07-11)
39
+
40
+ **Note:** Version bump only for package @strata-foundation/spl-utils
41
+
42
+
43
+
44
+
45
+
46
+ ## [3.8.2](https://github.com/StrataFoundation/strata/compare/v3.8.1...v3.8.2) (2022-06-19)
47
+
48
+ **Note:** Version bump only for package @strata-foundation/spl-utils
49
+
50
+
51
+
52
+
53
+
54
+ ## [3.8.1](https://github.com/StrataFoundation/strata/compare/v3.8.0...v3.8.1) (2022-06-18)
55
+
56
+ **Note:** Version bump only for package @strata-foundation/spl-utils
57
+
58
+
59
+
60
+
61
+
62
+ # [3.7.0](https://github.com/StrataFoundation/strata/compare/v3.5.5...v3.7.0) (2022-06-02)
63
+
64
+
65
+ ### Bug Fixes
66
+
67
+ * **transactions:** remove subscription if available ([#230](https://github.com/StrataFoundation/strata/issues/230)) ([e99f05c](https://github.com/StrataFoundation/strata/commit/e99f05c02dd1f0176c8303608ea4859c68774cf4))
68
+
69
+
70
+
71
+
72
+
73
+ ## [3.6.1](https://github.com/StrataFoundation/strata/compare/v3.6.0...v3.6.1) (2022-05-21)
74
+
75
+ **Note:** Version bump only for package @strata-foundation/spl-utils
76
+
77
+
78
+
79
+
80
+
81
+ ## [3.5.7](https://github.com/StrataFoundation/strata/compare/v3.5.5...v3.5.7) (2022-05-07)
82
+
83
+
84
+ ### Bug Fixes
85
+
86
+ * **transactions:** remove subscription if available ([#230](https://github.com/StrataFoundation/strata/issues/230)) ([e99f05c](https://github.com/StrataFoundation/strata/commit/e99f05c02dd1f0176c8303608ea4859c68774cf4))
87
+
88
+
89
+
90
+
91
+
92
+ ## [3.5.5](https://github.com/StrataFoundation/strata/compare/v3.5.4...v3.5.5) (2022-04-19)
93
+
94
+ **Note:** Version bump only for package @strata-foundation/spl-utils
95
+
96
+
97
+
98
+
99
+
100
+ ## [3.5.4](https://github.com/StrataFoundation/strata/compare/v3.5.2...v3.5.4) (2022-04-18)
101
+
102
+ **Note:** Version bump only for package @strata-foundation/spl-utils
103
+
104
+
105
+
106
+
107
+
108
+ ## [3.5.3](https://github.com/StrataFoundation/strata/compare/v3.5.2...v3.5.3) (2022-04-18)
109
+
110
+ **Note:** Version bump only for package @strata-foundation/spl-utils
111
+
112
+
113
+
114
+
115
+
116
+ ## [3.4.5](https://github.com/StrataFoundation/strata/compare/v3.4.1...v3.4.5) (2022-03-29)
117
+
118
+ **Note:** Version bump only for package @strata-foundation/spl-utils
119
+
120
+
121
+
122
+
123
+
124
+ ## [3.4.3](https://github.com/StrataFoundation/strata/compare/v3.4.1...v3.4.3) (2022-03-26)
125
+
126
+ **Note:** Version bump only for package @strata-foundation/spl-utils
127
+
128
+
129
+
130
+
131
+
132
+ ## [3.4.2](https://github.com/StrataFoundation/strata/compare/v3.4.1...v3.4.2) (2022-03-26)
133
+
134
+ **Note:** Version bump only for package @strata-foundation/spl-utils
135
+
136
+
137
+
138
+
139
+
140
+ ## [3.4.1](https://github.com/StrataFoundation/strata/compare/v3.4.0...v3.4.1) (2022-03-25)
141
+
142
+ **Note:** Version bump only for package @strata-foundation/spl-utils
143
+
144
+
145
+
146
+
147
+
148
+ # [3.4.0](https://github.com/StrataFoundation/strata/compare/v3.3.6...v3.4.0) (2022-03-25)
149
+
150
+ **Note:** Version bump only for package @strata-foundation/spl-utils
151
+
152
+
153
+
154
+
155
+
156
+ ## [3.3.6](https://github.com/StrataFoundation/strata/compare/v3.3.4...v3.3.6) (2022-03-16)
157
+
158
+ **Note:** Version bump only for package @strata-foundation/spl-utils
159
+
160
+
161
+
162
+
163
+
164
+ ## [3.3.5](https://github.com/StrataFoundation/strata/compare/v3.3.4...v3.3.5) (2022-03-16)
165
+
166
+ **Note:** Version bump only for package @strata-foundation/spl-utils
167
+
168
+
169
+
170
+
171
+
172
+ ## [3.3.4](https://github.com/StrataFoundation/strata/compare/v3.3.2...v3.3.4) (2022-03-16)
173
+
174
+ **Note:** Version bump only for package @strata-foundation/spl-utils
175
+
176
+
177
+
178
+
179
+
180
+ ## [3.3.3](https://github.com/StrataFoundation/strata/compare/v3.3.2...v3.3.3) (2022-03-16)
181
+
182
+ **Note:** Version bump only for package @strata-foundation/spl-utils
183
+
184
+
185
+
186
+
187
+
188
+ # [3.3.0](https://github.com/StrataFoundation/strata/compare/v3.2.6...v3.3.0) (2022-03-04)
189
+
190
+ **Note:** Version bump only for package @strata-foundation/spl-utils
191
+
192
+
193
+
194
+
195
+
196
+ ## [3.2.6](https://github.com/StrataFoundation/strata/compare/v3.0.0...v3.2.6) (2022-03-03)
197
+
198
+ **Note:** Version bump only for package @strata-foundation/spl-utils
199
+
200
+
201
+
202
+
203
+
204
+ ## [3.2.4](https://github.com/StrataFoundation/strata/compare/v3.2.4-alpha.5...v3.2.4) (2022-02-12)
205
+
206
+ **Note:** Version bump only for package @strata-foundation/spl-utils
207
+
208
+
209
+
210
+
211
+
212
+ ## [3.2.3](https://github.com/StrataFoundation/strata/compare/v3.2.2...v3.2.3) (2022-02-09)
213
+
214
+ **Note:** Version bump only for package @strata-foundation/spl-utils
215
+
216
+
217
+
218
+
219
+
220
+ ## [3.2.2](https://github.com/StrataFoundation/strata/compare/v3.2.1...v3.2.2) (2022-02-08)
221
+
222
+ **Note:** Version bump only for package @strata-foundation/spl-utils
223
+
224
+
225
+
226
+
227
+
228
+ ## [3.2.1](https://github.com/StrataFoundation/strata/compare/v3.2.0...v3.2.1) (2022-02-08)
229
+
230
+ **Note:** Version bump only for package @strata-foundation/spl-utils
231
+
232
+
233
+
234
+
235
+
236
+ # [3.2.0](https://github.com/StrataFoundation/strata/compare/v3.1.0...v3.2.0) (2022-02-03)
237
+
238
+ **Note:** Version bump only for package @strata-foundation/spl-utils
239
+
240
+
241
+
242
+
243
+
244
+ # [3.1.0](https://github.com/StrataFoundation/strata/compare/v3.0.0...v3.1.0) (2022-01-29)
245
+
246
+ **Note:** Version bump only for package @strata-foundation/spl-utils
247
+
248
+
249
+
250
+
251
+
252
+ # [3.0.0](https://github.com/StrataFoundation/strata/compare/v2.2.0...v3.0.0) (2022-01-26)
253
+
254
+ **Note:** Version bump only for package @strata-foundation/spl-utils
255
+
256
+
257
+
258
+
259
+
260
+ # [2.2.0](https://github.com/StrataFoundation/strata/compare/v2.1.11...v2.2.0) (2022-01-25)
261
+
262
+ **Note:** Version bump only for package @strata-foundation/spl-utils
263
+
264
+
265
+
266
+
267
+
268
+ ## [2.1.7](https://github.com/StrataFoundation/strata/compare/v2.1.6...v2.1.7) (2022-01-20)
269
+
270
+ **Note:** Version bump only for package @strata-foundation/spl-utils
271
+
272
+
273
+
274
+
275
+
276
+ ## [2.1.2](https://github.com/StrataFoundation/strata/compare/v2.1.1...v2.1.2) (2022-01-17)
277
+
278
+ **Note:** Version bump only for package @strata-foundation/spl-utils
279
+
280
+
281
+
282
+
283
+
284
+ ## [2.1.1](https://github.com/StrataFoundation/strata/compare/v2.1.0...v2.1.1) (2022-01-12)
285
+
286
+ **Note:** Version bump only for package @strata-foundation/spl-utils
287
+
288
+
289
+
290
+
291
+
292
+ # [2.1.0](https://github.com/StrataFoundation/strata/compare/v2.0.6...v2.1.0) (2022-01-11)
293
+
294
+ **Note:** Version bump only for package @strata-foundation/spl-utils
295
+
296
+
297
+
298
+
299
+
300
+ # [2.0.0](https://github.com/StrataFoundation/strata/compare/v1.3.2...v2.0.0) (2021-12-24)
301
+
302
+ **Note:** Version bump only for package @strata-foundation/spl-utils
303
+
304
+
305
+
306
+
307
+
308
+ ## [1.3.2](https://github.com/StrataFoundation/strata/compare/v0.7.0...v1.3.2) (2021-12-15)
309
+
310
+ **Note:** Version bump only for package @strata-foundation/spl-utils
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertNoUnresolvedSecrets = void 0;
4
+ const UNRESOLVED_PREFIX = 'op://';
5
+ /**
6
+ * Fail-fast guard against 1Password Secrets Injector misses.
7
+ *
8
+ * The injector is a mutating webhook with failurePolicy: Ignore, so a pod that
9
+ * reschedules while the webhook is briefly unavailable starts WITHOUT the
10
+ * `op run` wrapper. Its op:// secret refs are then never resolved and reach the
11
+ * app as the literal string "op://vault/item/field" — Postgres rejects auth,
12
+ * keys fail to parse, etc., while the pod itself looks Running. The only signal
13
+ * has historically been downstream errors/pages (hit cron-server, relayer, and
14
+ * admin in prod multiple times). Diagnose an individual pod with:
15
+ * kubectl exec <pod> -- sh -c 'tr "\0" " " </proc/1/cmdline'
16
+ * (injected iff PID1 is `/op/bin/op run -- <cmd>`; printenv is NOT reliable
17
+ * because `op run` resolves refs per-process).
18
+ *
19
+ * Call this right after config/env load with the required secrets. If any is
20
+ * still an unresolved op:// ref we log the offending keys and exit(1) so the
21
+ * pod CrashLoops visibly (and alertably) instead of serving broken. Fix is a
22
+ * `kubectl rollout restart` once the injector is back — NOT flipping the
23
+ * webhook to failurePolicy: Fail, which would block all scheduling while the
24
+ * injector is down (worse availability tradeoff).
25
+ *
26
+ * Pass a name -> value map so the log names exactly which keys were missed.
27
+ * Non-string values are ignored (convict's keypair/pubkey formats already throw
28
+ * on an op:// ref at coercion time, so they self-guard).
29
+ */
30
+ function assertNoUnresolvedSecrets(secrets) {
31
+ const unresolved = Object.entries(secrets)
32
+ .filter(([, v]) => typeof v === 'string' && v.startsWith(UNRESOLVED_PREFIX))
33
+ .map(([k]) => k);
34
+ if (unresolved.length > 0) {
35
+ console.error(`FATAL: 1Password secret injection failed — these secrets are still ` +
36
+ `unresolved op:// refs: ${unresolved.join(', ')}. This pod almost ` +
37
+ `certainly (re)scheduled while the op injector webhook was down ` +
38
+ `(failurePolicy: Ignore). Fix: kubectl rollout restart the deployment.`);
39
+ process.exit(1);
40
+ }
41
+ }
42
+ exports.assertNoUnresolvedSecrets = assertNoUnresolvedSecrets;
43
+ //# sourceMappingURL=assertSecrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertSecrets.js","sourceRoot":"","sources":["../../src/assertSecrets.ts"],"names":[],"mappings":";;;AAAA,MAAM,iBAAiB,GAAG,OAAO,CAAA;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,yBAAyB,CAAC,OAAgC;IACxE,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;SACvC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;SAC3E,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IAElB,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACzB,OAAO,CAAC,KAAK,CACX,qEAAqE;YACnE,0BAA0B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB;YACnE,iEAAiE;YACjE,uEAAuE,CAC1E,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAChB;AACH,CAAC;AAdD,8DAcC"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.dispersedClient = exports.DispersedConflictError = void 0;
16
+ const logger_1 = require("../logger");
17
+ const node_fetch_1 = __importDefault(require("node-fetch"));
18
+ /**
19
+ * Dispersed Token Burn API client (M2M OAuth2 client_credentials).
20
+ *
21
+ * Thin transport only: it mints/caches the bearer token and posts the two burn
22
+ * endpoints (claim, settle). It does NOT price RENDER, sum obligations, or do
23
+ * any burn math — the consumer owns that (incl. the `settled_amount == Σ
24
+ * obligation amounts` invariant). Amounts are passed through as decimal strings.
25
+ *
26
+ * Contract: see docs/dispersed-burn.md. Authoritative spec at
27
+ * `{apiBaseUrl}/openapi.json` (tag "Burn Ledger").
28
+ */
29
+ // Both scopes, space-delimited, requested on every token mint.
30
+ const SCOPES = 'burn_ledger_claims.create.all burn_ledger_settlements.create.all';
31
+ // Re-mint a little before the token actually expires.
32
+ const TOKEN_REFRESH_MARGIN_MS = 60000;
33
+ /**
34
+ * Thrown on a 409 from settle: the claim is missing/expired/released/already
35
+ * settled, an obligation mismatch, an amount mismatch, or a tx_signature reused
36
+ * with a different payload. Nothing was written. Do NOT re-burn — reconcile.
37
+ */
38
+ class DispersedConflictError extends Error {
39
+ constructor(body) {
40
+ super(`dispersed 409 conflict: ${body}`);
41
+ this.body = body;
42
+ this.status = 409;
43
+ this.name = 'DispersedConflictError';
44
+ }
45
+ }
46
+ exports.DispersedConflictError = DispersedConflictError;
47
+ const dispersedClient = (cfg, fetchImpl = node_fetch_1.default) => {
48
+ let cached;
49
+ const mintToken = () => __awaiter(void 0, void 0, void 0, function* () {
50
+ const res = yield fetchImpl(`${cfg.authBaseUrl}/token`, {
51
+ method: 'POST',
52
+ headers: { 'Content-Type': 'application/json' },
53
+ body: JSON.stringify({
54
+ grant_type: 'client_credentials',
55
+ client_id: cfg.clientId,
56
+ client_secret: cfg.clientSecret,
57
+ scope: SCOPES,
58
+ }),
59
+ });
60
+ if (res.status !== 200) {
61
+ throw new Error(`dispersed token mint failed. code: ${res.status} body: ${JSON.stringify(yield res.text())}`);
62
+ }
63
+ const json = (yield res.json());
64
+ cached = {
65
+ token: json.access_token,
66
+ expiresAt: Date.now() + json.expires_in * 1000,
67
+ };
68
+ return cached.token;
69
+ });
70
+ const getToken = () => __awaiter(void 0, void 0, void 0, function* () {
71
+ if (cached && Date.now() < cached.expiresAt - TOKEN_REFRESH_MARGIN_MS) {
72
+ return cached.token;
73
+ }
74
+ return mintToken();
75
+ });
76
+ // POST with bearer; one transparent re-mint+retry on 401 (a dropped daily run
77
+ // is expensive, so it's worth recovering from a token that died mid-flight).
78
+ const authedPost = (path, body) => __awaiter(void 0, void 0, void 0, function* () {
79
+ const doPost = (token) => fetchImpl(`${cfg.apiBaseUrl}${path}`, {
80
+ method: 'POST',
81
+ headers: {
82
+ 'Content-Type': 'application/json',
83
+ Authorization: `Bearer ${token}`,
84
+ },
85
+ body: JSON.stringify(body),
86
+ });
87
+ let res = yield doPost(yield getToken());
88
+ if (res.status === 401) {
89
+ cached = undefined;
90
+ res = yield doPost(yield mintToken());
91
+ }
92
+ return res;
93
+ });
94
+ return {
95
+ claim({ from, to, limit }, log = logger_1.consoleLogger) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const res = yield authedPost('/v1/burn-ledger-claims', Object.assign({ executor_id: cfg.executorId, from: from.toISOString(), to: to.toISOString() }, (limit !== undefined ? { limit } : {})));
98
+ if (res.status !== 201) {
99
+ throw new Error(`dispersed claim failed. code: ${res.status} body: ${JSON.stringify(yield res.text())}`);
100
+ }
101
+ const result = (yield res.json());
102
+ log.info(`dispersed claim ${result.claim.uuid}: ${result.claimed_count} obligations, expires ${result.claim.claim_expires_at}`);
103
+ return result;
104
+ });
105
+ },
106
+ settle(req, log = logger_1.consoleLogger) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const res = yield authedPost('/v1/burn-ledger-settlements', req);
109
+ if (res.status === 409) {
110
+ throw new DispersedConflictError(yield res.text());
111
+ }
112
+ if (res.status !== 201 && res.status !== 200) {
113
+ throw new Error(`dispersed settle failed. code: ${res.status} body: ${JSON.stringify(yield res.text())}`);
114
+ }
115
+ const result = (yield res.json());
116
+ log.info(`dispersed settle ${result.settlement.uuid} for tx ${req.tx_signature} (replay=${result.idempotent_replay})`);
117
+ return result;
118
+ });
119
+ },
120
+ };
121
+ };
122
+ exports.dispersedClient = dispersedClient;
123
+ //# sourceMappingURL=dispersed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispersed.js","sourceRoot":"","sources":["../../../src/client/dispersed.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAAuD;AACvD,4DAA8B;AAE9B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I,WAAW,GAAG,CAAC,YAAY,YAAY,MAAM,CAAC,iBAAiB,GAAG,CAC7G,CAAA;gBACD,OAAO,MAAM,CAAA;YACf,CAAC;SAAA;KACF,CAAA;AACH,CAAC,CAAA;AAxGY,QAAA,eAAe,mBAwG3B"}
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.pgClient = exports.batchFinishedAtMedian = exports.GRANT_BURN_TABLE = exports.GRANT_BURN_ID_TABLE = exports.USER_GRANT_SPEND_TABLE = exports.CURRENT_USER_GRANT_SPEND_TABLE = exports.POLYGON_UPGRADE_TABLE = exports.ENTITY_EPOCH_INFO_TABLE = exports.BURN_ADJUSTMENT_TABLE = exports.NETWORK_REVENUE_TABLE = exports.BRIDGE_TRANSFER_TABLE = exports.BURN_TABLE = exports.JOB_TABLE = exports.JOB_ID_TABLE = exports.LIABILITY_TABLE = exports.SOL_TRANSFER_TABLE = exports.ENTITY_TABLE = exports.MANUAL_BURN_TABLE = exports.EPOCH_TABLE = exports.SOL_TX_TABLE = void 0;
38
+ exports.pgClient = exports.batchFinishedAtMedian = exports.DISPERSED_SETTLEMENT_TABLE = exports.GRANT_BURN_TABLE = exports.GRANT_BURN_ID_TABLE = exports.USER_GRANT_SPEND_TABLE = exports.CURRENT_USER_GRANT_SPEND_TABLE = exports.POLYGON_UPGRADE_TABLE = exports.ENTITY_EPOCH_INFO_TABLE = exports.BURN_ADJUSTMENT_TABLE = exports.NETWORK_REVENUE_TABLE = exports.BRIDGE_TRANSFER_TABLE = exports.BURN_TABLE = exports.JOB_TABLE = exports.JOB_ID_TABLE = exports.LIABILITY_TABLE = exports.SOL_TRANSFER_TABLE = exports.ENTITY_TABLE = exports.MANUAL_BURN_TABLE = exports.EPOCH_TABLE = exports.SOL_TX_TABLE = void 0;
39
39
  const kysely_1 = require("kysely");
40
40
  const logger_1 = require("../../logger");
41
41
  const pg_1 = require("pg");
@@ -59,6 +59,7 @@ exports.CURRENT_USER_GRANT_SPEND_TABLE = 'current_user_grant_spend';
59
59
  exports.USER_GRANT_SPEND_TABLE = 'user_grant_spend';
60
60
  exports.GRANT_BURN_ID_TABLE = 'grant_burn_id';
61
61
  exports.GRANT_BURN_TABLE = 'grant_burn';
62
+ exports.DISPERSED_SETTLEMENT_TABLE = 'dispersed_settlement';
62
63
  BigInt.prototype.toJSON = function () {
63
64
  return this.toString();
64
65
  };
@@ -1586,6 +1587,51 @@ const pgClient = (config) => {
1586
1587
  }));
1587
1588
  });
1588
1589
  },
1590
+ insertDispersedOutbox(p, log = logger_1.consoleLogger) {
1591
+ return __awaiter(this, void 0, void 0, function* () {
1592
+ const res = yield db
1593
+ .insertInto(exports.DISPERSED_SETTLEMENT_TABLE)
1594
+ .values({
1595
+ tx_signature: p.txSignature,
1596
+ claim_uuid: p.claimUuid,
1597
+ obligation_uuids: p.obligationUuids,
1598
+ settled_amount: p.settledAmount,
1599
+ burned_amount: p.burnedAmount,
1600
+ executed_at: p.executedAt,
1601
+ })
1602
+ .onConflict((oc) => oc.column('tx_signature').doNothing())
1603
+ .executeTakeFirst();
1604
+ log.debug(`dispersed outbox tx ${p.txSignature}: ${res.numInsertedOrUpdatedRows} row(s)`);
1605
+ });
1606
+ },
1607
+ markDispersedSettled(txSignature, p, log = logger_1.consoleLogger) {
1608
+ return __awaiter(this, void 0, void 0, function* () {
1609
+ yield db
1610
+ .updateTable(exports.DISPERSED_SETTLEMENT_TABLE)
1611
+ .set({ settled_at: new Date(), idempotent_replay: p.idempotentReplay })
1612
+ .where('tx_signature', '=', txSignature)
1613
+ .execute();
1614
+ log.debug(`dispersed settled tx ${txSignature}`);
1615
+ });
1616
+ },
1617
+ getUnsettledDispersed(log = logger_1.consoleLogger) {
1618
+ return __awaiter(this, void 0, void 0, function* () {
1619
+ const rows = yield db
1620
+ .selectFrom(exports.DISPERSED_SETTLEMENT_TABLE)
1621
+ .selectAll()
1622
+ .where('settled_at', 'is', null)
1623
+ .execute();
1624
+ log.debug(`dispersed outbox: ${rows.length} unsettled`);
1625
+ return rows.map((r) => ({
1626
+ txSignature: r.tx_signature,
1627
+ claimUuid: r.claim_uuid,
1628
+ obligationUuids: r.obligation_uuids,
1629
+ settledAmount: r.settled_amount,
1630
+ burnedAmount: r.burned_amount,
1631
+ executedAt: r.executed_at,
1632
+ }));
1633
+ });
1634
+ },
1589
1635
  fetchJobs(db, f, log = logger_1.consoleLogger) {
1590
1636
  return __awaiter(this, void 0, void 0, function* () {
1591
1637
  return yield fetchJobs1(db.trx, f, log);