@xyo-network/chain-reward-redemption 1.23.0 → 2.0.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.
@@ -1,5 +1,15 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __decorateClass = (decorators, target, key, kind) => {
5
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
6
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7
+ if (decorator = decorators[i])
8
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9
+ if (kind && result) __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
3
13
 
4
14
  // src/command.ts
5
15
  import { RewardRedemptionConfigZod } from "@xyo-network/chain-orchestration";
@@ -11,7 +21,11 @@ import { initActorWallet } from "@xyo-network/chain-orchestration";
11
21
  // src/RewardRedemptionActor.ts
12
22
  import { creatable } from "@xylabs/sdk-js";
13
23
  import { ActorV3 } from "@xyo-network/chain-orchestration";
14
- import { asHostActorConfigContext, XyoGatewayRunnerMoniker, XyoViewerMoniker as XyoViewerMoniker2 } from "@xyo-network/xl1-sdk";
24
+ import {
25
+ asHostActorConfigContext,
26
+ XyoGatewayRunnerMoniker,
27
+ XyoViewerMoniker as XyoViewerMoniker2
28
+ } from "@xyo-network/xl1-sdk";
15
29
 
16
30
  // src/server/app.ts
17
31
  import { standardErrors } from "@xylabs/express";
@@ -22,278 +36,287 @@ import express2 from "express";
22
36
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
23
37
  import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
24
38
  import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
25
- var addInstrumentation = /* @__PURE__ */ __name(() => {
26
- const instrumentations = [
27
- new HttpInstrumentation(),
28
- new ExpressInstrumentation()
29
- ];
30
- registerInstrumentations({
31
- instrumentations
32
- });
33
- }, "addInstrumentation");
39
+ var addInstrumentation = () => {
40
+ const instrumentations = [new HttpInstrumentation(), new ExpressInstrumentation()];
41
+ registerInstrumentations({ instrumentations });
42
+ };
34
43
 
35
44
  // src/server/routes/livez/get.ts
36
45
  import { setRawResponseFormat } from "@xylabs/express";
37
46
  import { ReasonPhrases } from "http-status-codes";
38
47
  var message = ReasonPhrases.OK;
39
- var handler = /* @__PURE__ */ __name((_req, res) => {
48
+ var handler = (_req, res) => {
40
49
  setRawResponseFormat(res);
41
- res.status(200).send({
42
- message
43
- });
44
- }, "handler");
50
+ res.status(200).send({ message });
51
+ };
45
52
  var getLivez = handler;
46
53
 
47
54
  // src/server/routes/readyz/get.ts
48
55
  import { setRawResponseFormat as setRawResponseFormat2 } from "@xylabs/express";
49
56
  import { ReasonPhrases as ReasonPhrases2 } from "http-status-codes";
50
57
  var message2 = ReasonPhrases2.OK;
51
- var handler2 = /* @__PURE__ */ __name((_req, res) => {
58
+ var handler2 = (_req, res) => {
52
59
  setRawResponseFormat2(res);
53
- res.status(200).send({
54
- message: message2
55
- });
56
- }, "handler");
60
+ res.status(200).send({ message: message2 });
61
+ };
57
62
  var getReadyz = handler2;
58
63
 
59
64
  // src/server/routes/startupz/get.ts
60
65
  import { setRawResponseFormat as setRawResponseFormat3 } from "@xylabs/express";
61
66
  import { ReasonPhrases as ReasonPhrases3 } from "http-status-codes";
62
67
  var message3 = ReasonPhrases3.OK;
63
- var handler3 = /* @__PURE__ */ __name((_req, res) => {
68
+ var handler3 = (_req, res) => {
64
69
  setRawResponseFormat3(res);
65
- res.status(200).send({
66
- message: message3
67
- });
68
- }, "handler");
70
+ res.status(200).send({ message: message3 });
71
+ };
69
72
  var getStartupz = handler3;
70
73
 
71
74
  // src/server/routes/addProbeRoutes.ts
72
- var addProbeRoutes = /* @__PURE__ */ __name((app) => {
75
+ var addProbeRoutes = (app) => {
73
76
  app.get("/livez", getLivez);
74
77
  app.get("/readyz", getReadyz);
75
78
  app.get("/startupz", getStartupz);
76
- }, "addProbeRoutes");
79
+ };
77
80
 
78
81
  // src/server/routes/dataLake/archivistMiddleware.ts
79
82
  import { setRawResponseFormat as setRawResponseFormat4 } from "@xylabs/express";
80
- import { asHash, isDefined } from "@xylabs/sdk-js";
81
- import { asArchivistInstance, isAnyPayload, isSequence, PayloadBuilder } from "@xyo-network/sdk-js";
83
+ import {
84
+ asHash,
85
+ isDefined,
86
+ spanAsync
87
+ } from "@xylabs/sdk-js";
88
+ import {
89
+ asArchivistInstance,
90
+ isAnyPayload,
91
+ isSequence,
92
+ PayloadBuilder
93
+ } from "@xyo-network/sdk-js";
82
94
  import express from "express";
83
- var resolveArchivist = /* @__PURE__ */ __name(async (node, archivistModuleIdentifier) => {
95
+ var resolveArchivist = async (node, archivistModuleIdentifier) => {
84
96
  const mod = await node.resolve(archivistModuleIdentifier);
85
- return asArchivistInstance(mod, {
86
- required: true
87
- });
88
- }, "resolveArchivist");
97
+ return asArchivistInstance(mod, { required: true });
98
+ };
89
99
  var archivistInstance;
90
- var getArchivist = /* @__PURE__ */ __name(async (node, archivistModuleIdentifier) => {
100
+ var getArchivist = async (node, archivistModuleIdentifier) => {
91
101
  if (isDefined(archivistInstance)) return archivistInstance;
92
102
  archivistInstance = await resolveArchivist(node, archivistModuleIdentifier);
93
103
  return archivistInstance;
94
- }, "getArchivist");
95
- var archivistMiddleware = /* @__PURE__ */ __name((options) => {
104
+ };
105
+ var archivistMiddleware = (options) => {
96
106
  const { node, archivistModuleIdentifier } = options;
97
- const router = express.Router({
98
- mergeParams: true
99
- });
107
+ const router = express.Router({ mergeParams: true });
100
108
  router.post("/insert", async (req, res) => {
101
- setRawResponseFormat4(res);
102
- const body2 = Array.isArray(req.body) ? req.body : [
103
- req.body
104
- ];
105
- const payloads = (await PayloadBuilder.hashPairs(body2)).map((p) => p[0]);
106
- const archivist = await getArchivist(node, archivistModuleIdentifier);
107
- const result = await archivist.insert(payloads);
108
- res.status(200).json(result);
109
+ await spanAsync("reward-redemption:data-lake:insert", async () => {
110
+ setRawResponseFormat4(res);
111
+ const body2 = Array.isArray(req.body) ? req.body : [req.body];
112
+ const payloads = (await PayloadBuilder.hashPairs(body2)).map((p) => p[0]);
113
+ const archivist = await getArchivist(node, archivistModuleIdentifier);
114
+ const result = await archivist.insert(payloads);
115
+ res.status(200).json(result);
116
+ }, { timeBudgetLimit: 2e3 });
109
117
  });
110
118
  router.get("/next", async (req, res) => {
111
- setRawResponseFormat4(res);
112
- const cursor = isSequence(req.query.cursor) ? req.query.cursor : void 0;
113
- const limit = isDefined(req.query.limit) ? Number(req.query.limit) : void 0;
114
- const open = isDefined(req.query.open) ? Boolean(req.query.open) : void 0;
115
- const order = req.query.order === "asc" ? "asc" : "desc";
116
- const options2 = {
117
- limit,
118
- open,
119
- order,
120
- cursor
121
- };
122
- const archivist = await getArchivist(node, archivistModuleIdentifier);
123
- const result = await archivist.next(options2);
124
- res.status(200).json(result);
119
+ await spanAsync("reward-redemption:data-lake:next-get", async () => {
120
+ setRawResponseFormat4(res);
121
+ const cursor = isSequence(req.query.cursor) ? req.query.cursor : void 0;
122
+ const limit = isDefined(req.query.limit) ? Number(req.query.limit) : void 0;
123
+ const open = isDefined(req.query.open) ? Boolean(req.query.open) : void 0;
124
+ const order = req.query.order === "asc" ? "asc" : "desc";
125
+ const options2 = {
126
+ limit,
127
+ open,
128
+ order,
129
+ cursor
130
+ };
131
+ const archivist = await getArchivist(node, archivistModuleIdentifier);
132
+ const result = await archivist.next(options2);
133
+ res.status(200).json(result);
134
+ }, { timeBudgetLimit: 2e3 });
125
135
  });
126
136
  router.post("/next", async (req, res) => {
127
- setRawResponseFormat4(res);
128
- const options2 = req.body;
129
- const archivist = await getArchivist(node, archivistModuleIdentifier);
130
- const result = await (isDefined(options2) ? archivist.next(options2) : archivist.next());
131
- res.status(200).json(result);
137
+ await spanAsync("reward-redemption:data-lake:next-post", async () => {
138
+ setRawResponseFormat4(res);
139
+ const options2 = req.body;
140
+ const archivist = await getArchivist(node, archivistModuleIdentifier);
141
+ const result = await (isDefined(options2) ? archivist.next(options2) : archivist.next());
142
+ res.status(200).json(result);
143
+ }, { timeBudgetLimit: 2e3 });
132
144
  });
133
145
  router.get("/get/:hash", async (req, res) => {
134
- setRawResponseFormat4(res);
135
- const { hash: rawHash } = req.params;
136
- const hash = asHash(rawHash);
137
- if (isDefined(hash)) {
138
- const archivist = await getArchivist(node, archivistModuleIdentifier);
139
- const [payload] = await archivist.get([
140
- hash
141
- ]);
142
- if (isAnyPayload(payload)) {
143
- res.json(payload);
144
- return;
145
- } else {
146
- res.status(404).send();
147
- return;
146
+ await spanAsync("reward-redemption:data-lake:get", async () => {
147
+ setRawResponseFormat4(res);
148
+ const { hash: rawHash } = req.params;
149
+ const hash = asHash(rawHash);
150
+ if (isDefined(hash)) {
151
+ const archivist = await getArchivist(node, archivistModuleIdentifier);
152
+ const [payload] = await archivist.get([hash]);
153
+ if (isAnyPayload(payload)) {
154
+ res.json(payload);
155
+ return;
156
+ } else {
157
+ res.status(404).send();
158
+ return;
159
+ }
148
160
  }
149
- }
150
- res.status(400).send();
161
+ res.status(400).send();
162
+ }, { timeBudgetLimit: 2e3 });
151
163
  });
152
164
  return router;
153
- }, "archivistMiddleware");
165
+ };
154
166
 
155
167
  // src/server/routes/dataLake/addDataLakeRoutes.ts
156
- var addDataLakeRoutes = /* @__PURE__ */ __name((app) => {
168
+ var addDataLakeRoutes = (app) => {
157
169
  const { node } = app;
158
170
  const archivistModuleIdentifier = "Data";
159
- app.use("/data", archivistMiddleware({
160
- node,
161
- archivistModuleIdentifier
162
- }));
163
- }, "addDataLakeRoutes");
171
+ app.use("/data", archivistMiddleware({ node, archivistModuleIdentifier }));
172
+ };
164
173
 
165
174
  // src/server/routes/rewardRedemption/addRewardRoutes.ts
166
175
  import { addRouteDefinitions } from "@xylabs/express";
167
176
 
168
177
  // src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
169
178
  import { requestHandlerValidator } from "@xylabs/express";
170
- import { assertEx, isDefined as isDefined2 } from "@xylabs/sdk-js";
171
- import { asSentinelInstance, PayloadBuilder as PayloadBuilder2, PayloadZodLoose } from "@xyo-network/sdk-js";
172
- import { asXL1BlockRange, blockRangeSteps, StepIdentitySchema, XyoViewerMoniker } from "@xyo-network/xl1-sdk";
173
- import { z } from "zod";
179
+ import {
180
+ assertEx,
181
+ isDefined as isDefined2,
182
+ spanAsync as spanAsync2
183
+ } from "@xylabs/sdk-js";
184
+ import {
185
+ asSentinelInstance,
186
+ PayloadBuilder as PayloadBuilder2,
187
+ PayloadZodLoose
188
+ } from "@xyo-network/sdk-js";
189
+ import {
190
+ asXL1BlockRange,
191
+ blockRangeSteps,
192
+ StepIdentitySchema,
193
+ XyoViewerMoniker
194
+ } from "@xyo-network/xl1-sdk";
195
+ import { z } from "zod/mini";
174
196
 
175
197
  // src/server/routes/rewardRedemption/routeDefinitions/util/rewardableSteps.ts
176
- var RewardableSteps = [
177
- 3,
178
- 4,
179
- 5,
180
- 6,
181
- 7,
182
- 8
183
- ];
198
+ var RewardableSteps = [3, 4, 5, 6, 7, 8];
184
199
 
185
200
  // src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
186
- var query = z.object({
187
- fromBlock: z.coerce.number().int().nonnegative().optional(),
188
- toBlock: z.coerce.number().int().nonnegative().optional(),
189
- step: z.coerce.number().int().nonnegative().min(Math.min(...RewardableSteps)).max(Math.max(...RewardableSteps)).optional().default(3)
201
+ var MIN_STEP = Math.min(...RewardableSteps);
202
+ var MAX_STEP = Math.max(...RewardableSteps);
203
+ var queryFields = z.object({
204
+ fromBlock: z.optional(z.coerce.number().check(z.multipleOf(1), z.nonnegative())),
205
+ toBlock: z.optional(z.coerce.number().check(z.multipleOf(1), z.nonnegative())),
206
+ step: z._default(
207
+ z.coerce.number().check(z.multipleOf(1), z.nonnegative(), z.gte(MIN_STEP), z.lte(MAX_STEP)),
208
+ 3
209
+ )
190
210
  });
191
211
  var response = z.array(PayloadZodLoose);
192
- var validateRequest = requestHandlerValidator({
193
- query,
194
- response
195
- });
196
- var getChainStepRewardsClaimSentinel = /* @__PURE__ */ __name(async (node) => {
212
+ var validateRequest = requestHandlerValidator({ response });
213
+ var getChainStepRewardsClaimSentinel = async (node) => {
197
214
  const mod = await node.resolve("XYORewardRedemptionNode:ChainStepRewardsClaimSentinel");
198
215
  const sentinel = asSentinelInstance(mod);
199
216
  return assertEx(sentinel, () => "ChainStepRewardsClaimSentinel not found on node");
200
- }, "getChainStepRewardsClaimSentinel");
217
+ };
201
218
  var postClaimRange = {
202
219
  method: "post",
203
220
  path: "/rewards/claimRange",
204
221
  handlers: validateRequest(async (req, res) => {
205
- const { locator, node } = req.app;
206
- const { fromBlock, toBlock, step } = z.parse(query, req.query);
207
- const viewer = await locator.getInstance(XyoViewerMoniker);
208
- const from = isDefined2(fromBlock) ? fromBlock : 0;
209
- const currentBlock = await viewer.currentBlockNumber();
210
- const to = isDefined2(toBlock) ? Math.min(toBlock, currentBlock) : currentBlock;
211
- if (to <= from) {
212
- res.status(400);
213
- res.json([]);
214
- return;
215
- }
216
- const range = asXL1BlockRange([
217
- from,
218
- to
219
- ], {
220
- name: "claimRange"
221
- });
222
- const stepIdentities = blockRangeSteps(range, [
223
- step
224
- ]);
225
- const results = [];
226
- for (const stepIdentity of stepIdentities) {
227
- const mod = await getChainStepRewardsClaimSentinel(node);
228
- const stepIdentityPayload = new PayloadBuilder2({
229
- schema: StepIdentitySchema
230
- }).fields(stepIdentity).build();
231
- const result = await mod.report([
232
- stepIdentityPayload
233
- ]);
234
- results.push(...result);
235
- }
236
- res.status(200);
237
- res.json(results);
222
+ await spanAsync2("reward-redemption:claim-range", async () => {
223
+ const { locator, node } = req.app;
224
+ const {
225
+ fromBlock,
226
+ toBlock,
227
+ step
228
+ } = z.parse(queryFields, req.query);
229
+ const viewer = await locator.getInstance(XyoViewerMoniker);
230
+ const from = isDefined2(fromBlock) ? fromBlock : 0;
231
+ const currentBlock = await viewer.currentBlockNumber();
232
+ const to = isDefined2(toBlock) ? Math.min(toBlock, currentBlock) : currentBlock;
233
+ if (to <= from) {
234
+ res.status(400);
235
+ res.json([]);
236
+ return;
237
+ }
238
+ const range = asXL1BlockRange([from, to], { name: "claimRange" });
239
+ const stepIdentities = blockRangeSteps(range, [step]);
240
+ const results = [];
241
+ for (const stepIdentity of stepIdentities) {
242
+ const mod = await getChainStepRewardsClaimSentinel(node);
243
+ const stepIdentityPayload = new PayloadBuilder2({ schema: StepIdentitySchema }).fields(stepIdentity).build();
244
+ const result = await mod.report([stepIdentityPayload]);
245
+ results.push(...result);
246
+ }
247
+ res.status(200);
248
+ res.json(results);
249
+ }, { timeBudgetLimit: 5e3 });
238
250
  })
239
251
  };
240
252
 
241
253
  // src/server/routes/rewardRedemption/routeDefinitions/routes/redeem.ts
242
254
  import { requestHandlerValidator as requestHandlerValidator2 } from "@xylabs/express";
243
- import { assertEx as assertEx2 } from "@xylabs/sdk-js";
244
- import { asSentinelInstance as asSentinelInstance2, PayloadZodLoose as PayloadZodLoose2, PayloadZodStrictOfSchema } from "@xyo-network/sdk-js";
245
- import { EIP712DataPayloadFieldsZod, EIP712DataPayloadSchema, EIP712SignaturePayloadFieldsZod, EIP712SignaturePayloadSchema } from "@xyo-network/xl1-sdk";
246
- import { z as z2 } from "zod";
255
+ import { assertEx as assertEx2, spanAsync as spanAsync3 } from "@xylabs/sdk-js";
256
+ import {
257
+ asSentinelInstance as asSentinelInstance2,
258
+ PayloadZodLoose as PayloadZodLoose2,
259
+ PayloadZodStrictOfSchema
260
+ } from "@xyo-network/sdk-js";
261
+ import {
262
+ EIP712DataPayloadFieldsZod,
263
+ EIP712DataPayloadSchema,
264
+ EIP712SignaturePayloadFieldsZod,
265
+ EIP712SignaturePayloadSchema
266
+ } from "@xyo-network/xl1-sdk";
267
+ import { z as z2 } from "zod/mini";
247
268
  var body = z2.tuple([
248
- PayloadZodStrictOfSchema(EIP712DataPayloadSchema).extend(EIP712DataPayloadFieldsZod.shape),
249
- PayloadZodStrictOfSchema(EIP712SignaturePayloadSchema).extend(EIP712SignaturePayloadFieldsZod.shape)
269
+ z2.extend(PayloadZodStrictOfSchema(EIP712DataPayloadSchema), EIP712DataPayloadFieldsZod.shape),
270
+ z2.extend(PayloadZodStrictOfSchema(EIP712SignaturePayloadSchema), EIP712SignaturePayloadFieldsZod.shape)
250
271
  ]);
251
272
  var response2 = z2.array(PayloadZodLoose2);
252
273
  var validateRequest2 = requestHandlerValidator2({
253
274
  body,
254
275
  response: response2
255
276
  });
256
- var getDerivedAddressWalletTransferSentinel = /* @__PURE__ */ __name(async (node) => {
277
+ var getDerivedAddressWalletTransferSentinel = async (node) => {
257
278
  const mod = await node.resolve("XYORewardRedemptionNode:DerivedAddressWalletTransferSentinel");
258
279
  const sentinel = asSentinelInstance2(mod);
259
280
  return assertEx2(sentinel, () => "DerivedAddressWalletTransferSentinel not found on node");
260
- }, "getDerivedAddressWalletTransferSentinel");
281
+ };
261
282
  var postRedeem = {
262
283
  method: "post",
263
284
  path: "/rewards/redeem",
264
285
  handlers: validateRequest2(async (req, res) => {
265
- const { node } = req.app;
266
- const { body: body2 } = req;
267
- const sentinel = await getDerivedAddressWalletTransferSentinel(node);
268
- const result = await sentinel.report(body2);
269
- res.status(200);
270
- res.json(result);
286
+ await spanAsync3("reward-redemption:redeem", async () => {
287
+ const { node } = req.app;
288
+ const { body: body2 } = req;
289
+ const sentinel = await getDerivedAddressWalletTransferSentinel(node);
290
+ const result = await sentinel.report(body2);
291
+ res.status(200);
292
+ res.json(result);
293
+ }, { timeBudgetLimit: 2e3 });
271
294
  })
272
295
  };
273
296
 
274
297
  // src/server/routes/rewardRedemption/routeDefinitions/getRouteDefinitions.ts
275
- var getRouteDefinitions = /* @__PURE__ */ __name(() => {
298
+ var getRouteDefinitions = () => {
276
299
  return [
277
300
  postClaimRange,
278
301
  postRedeem
279
302
  ];
280
- }, "getRouteDefinitions");
303
+ };
281
304
 
282
305
  // src/server/routes/rewardRedemption/addRewardRoutes.ts
283
- var addRewardRedemptionRoutes = /* @__PURE__ */ __name((app) => {
306
+ var addRewardRedemptionRoutes = (app) => {
284
307
  const routeDefinitions = getRouteDefinitions();
285
308
  addRouteDefinitions(app, routeDefinitions);
286
- }, "addRewardRedemptionRoutes");
309
+ };
287
310
 
288
311
  // src/server/routes/addRoutes.ts
289
- var addRoutes = /* @__PURE__ */ __name((app) => {
312
+ var addRoutes = (app) => {
290
313
  addProbeRoutes(app);
291
314
  addDataLakeRoutes(app);
292
315
  addRewardRedemptionRoutes(app);
293
- }, "addRoutes");
316
+ };
294
317
 
295
318
  // src/server/app.ts
296
- var getApp = /* @__PURE__ */ __name((node, config, locator) => {
319
+ var getApp = (node, config, locator) => {
297
320
  addInstrumentation();
298
321
  const app = express2();
299
322
  sharedMiddleware(app);
@@ -303,7 +326,7 @@ var getApp = /* @__PURE__ */ __name((node, config, locator) => {
303
326
  addRoutes(app);
304
327
  app.use(standardErrors);
305
328
  return app;
306
- }, "getApp");
329
+ };
307
330
 
308
331
  // src/server/server.ts
309
332
  import { boot } from "@xyo-network/bios";
@@ -315,32 +338,43 @@ import { isDefined as isDefined5 } from "@xylabs/sdk-js";
315
338
  import { MongoDBArchivistV2 } from "@xyo-network/archivist-mongodb";
316
339
  import { ViewArchivist } from "@xyo-network/archivist-view";
317
340
  import { initTelemetry } from "@xyo-network/chain-telemetry";
318
- import { AbstractModule, LoggerModuleStatusReporter, MemoryArchivist, MemorySentinel, ModuleFactoryLocator } from "@xyo-network/sdk-js";
341
+ import {
342
+ AbstractModule,
343
+ LoggerModuleStatusReporter,
344
+ MemoryArchivist,
345
+ MemorySentinel,
346
+ ModuleFactoryLocator
347
+ } from "@xyo-network/sdk-js";
319
348
  import { hasMongoConfig } from "@xyo-network/xl1-sdk";
320
349
 
321
350
  // src/services/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts
322
- import { assertEx as assertEx3, delay, isDefined as isDefined3, isUndefined, toAddress } from "@xylabs/sdk-js";
351
+ import {
352
+ assertEx as assertEx3,
353
+ delay,
354
+ isDefined as isDefined3,
355
+ isUndefined,
356
+ toAddress
357
+ } from "@xylabs/sdk-js";
323
358
  import { AbstractSentinel, asSchema } from "@xyo-network/sdk-js";
324
- import { asXL1BlockNumber, asXL1BlockRange as asXL1BlockRange2, blockRangeSteps as blockRangeSteps2, completedStepRewardAddress, createTransferPayload, derivedReceiveAddress, flattenHydratedTransaction, flattenHydratedTransactions, isStepIdentityPayload, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-sdk";
359
+ import {
360
+ asXL1BlockNumber,
361
+ asXL1BlockRange as asXL1BlockRange2,
362
+ blockRangeSteps as blockRangeSteps2,
363
+ completedStepRewardAddress,
364
+ createTransferPayload,
365
+ derivedReceiveAddress,
366
+ flattenHydratedTransaction,
367
+ flattenHydratedTransactions,
368
+ isStepIdentityPayload,
369
+ XYO_STEP_REWARD_ADDRESS
370
+ } from "@xyo-network/xl1-sdk";
325
371
  import { Mutex } from "async-mutex";
326
372
  var ChainStepRewardsClaimSentinelConfigSchema = asSchema("network.xyo.sentinel.chain.step.rewards.claim.config", true);
327
373
  var defaultStepClaimIntervalMs = 15e3;
328
374
  var scope = "reward-escrow";
329
- var DefaultRewardableSteps = [
330
- 3,
331
- 4,
332
- 5,
333
- 6,
334
- 7,
335
- 8
336
- ];
375
+ var DefaultRewardableSteps = [3, 4, 5, 6, 7, 8];
337
376
  var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
338
- static {
339
- __name(this, "ChainStepRewardsClaimSentinel");
340
- }
341
- static configSchemas = [
342
- ChainStepRewardsClaimSentinelConfigSchema
343
- ];
377
+ static configSchemas = [ChainStepRewardsClaimSentinelConfigSchema];
344
378
  static defaultConfigSchema = ChainStepRewardsClaimSentinelConfigSchema;
345
379
  _claimAttemptsCounter;
346
380
  _claimCheckCounter;
@@ -367,18 +401,10 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
367
401
  }
368
402
  async createHandler() {
369
403
  await super.createHandler();
370
- this._claimAttemptsCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_attempts_total", {
371
- description: "Number of claim attempts"
372
- });
373
- this._claimCheckCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_check_total", {
374
- description: "Number of claim checks"
375
- });
376
- this._claimSuccessCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_success_total", {
377
- description: "Number of claim successes"
378
- });
379
- this._claimErrorCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_errors_total", {
380
- description: "Number of claim errors"
381
- });
404
+ this._claimAttemptsCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_attempts_total", { description: "Number of claim attempts" });
405
+ this._claimCheckCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_check_total", { description: "Number of claim checks" });
406
+ this._claimSuccessCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_success_total", { description: "Number of claim successes" });
407
+ this._claimErrorCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_errors_total", { description: "Number of claim errors" });
382
408
  const gateway = assertEx3(this.params.gateway, () => "Gateway parameter is required");
383
409
  const connection = assertEx3(gateway.connection, () => "Gateway connection is required");
384
410
  const viewer = assertEx3(connection.viewer, () => "Viewer is not defined in gateway connection");
@@ -398,13 +424,8 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
398
424
  } else {
399
425
  const stepIdentities = payloads.filter(isStepIdentityPayload).map((p) => {
400
426
  const { step, block: blockNumber } = p;
401
- const block = asXL1BlockNumber(blockNumber, {
402
- name: "reportHandler"
403
- });
404
- return {
405
- step,
406
- block
407
- };
427
+ const block = asXL1BlockNumber(blockNumber, { name: "reportHandler" });
428
+ return { step, block };
408
429
  }).filter((stepIdentity) => this.rewardableSteps.includes(stepIdentity.step));
409
430
  for (const stepIdentity of stepIdentities) {
410
431
  const result = await this.claimStepIdentity(stepIdentity);
@@ -437,15 +458,8 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
437
458
  for (const step of this.rewardableSteps) {
438
459
  const from = 0;
439
460
  const to = await this.viewer.currentBlockNumber();
440
- const range = asXL1BlockRange2([
441
- from,
442
- to
443
- ], {
444
- name: "claimAllSteps"
445
- });
446
- const stepIdentities = blockRangeSteps2(range, [
447
- step
448
- ]);
461
+ const range = asXL1BlockRange2([from, to], { name: "claimAllSteps" });
462
+ const stepIdentities = blockRangeSteps2(range, [step]);
449
463
  for (const stepIdentity of stepIdentities) {
450
464
  const result = await this.claimStepIdentity(stepIdentity);
451
465
  if (isDefined3(result)) {
@@ -458,25 +472,28 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
458
472
  }
459
473
  async claimStepIdentity(stepIdentity) {
460
474
  this.logger?.info(`Checking rewards to claim for step ${stepIdentity.step} at block ${stepIdentity.block}`);
461
- const claimCounterAttributes = {
462
- step: stepIdentity.step.toString(),
463
- block: stepIdentity.block.toString()
464
- };
475
+ const claimCounterAttributes = { step: stepIdentity.step.toString(), block: stepIdentity.block.toString() };
465
476
  try {
466
477
  this._claimCheckCounter?.add(1, claimCounterAttributes);
467
478
  const stepRewardAddress = completedStepRewardAddress(stepIdentity);
468
479
  const balance = await this.viewer.account.balance.accountBalance(stepRewardAddress);
469
- this.logger?.info(`Found balance of ${balance} to claim for step ${stepIdentity.step} at block ${stepIdentity.block} in step reward address ${stepRewardAddress}`);
480
+ this.logger?.info(
481
+ `Found balance of ${balance} to claim for step ${stepIdentity.step} at block ${stepIdentity.block} in step reward address ${stepRewardAddress}`
482
+ );
470
483
  if (balance > 0n) {
471
484
  this._claimAttemptsCounter?.add(1, claimCounterAttributes);
472
485
  const rewardsByStaker = await this.viewer.networkStakeStepRewardPoolRewards(stepIdentity);
473
486
  const rewardRecipients = Object.keys(rewardsByStaker).length;
474
- this.logger?.info(`Found ${rewardRecipients} reward recipients for step ${stepIdentity.step} at block ${stepIdentity.block}`);
487
+ this.logger?.info(
488
+ `Found ${rewardRecipients} reward recipients for step ${stepIdentity.step} at block ${stepIdentity.block}`
489
+ );
475
490
  if (!this.config.claimEmptySteps) {
476
491
  assertEx3(rewardRecipients > 0, () => "No reward recipients for step");
477
492
  }
478
493
  const addressDistributions = this.calculateAddressDistributions(rewardsByStaker, balance);
479
- this.logger?.info(`Calculated address distributions for step ${stepIdentity.step} at block ${stepIdentity.block} with ${Object.keys(addressDistributions).length} addresses`);
494
+ this.logger?.info(
495
+ `Calculated address distributions for step ${stepIdentity.step} at block ${stepIdentity.block} with ${Object.keys(addressDistributions).length} addresses`
496
+ );
480
497
  const tx = await this.submitRewardDistributionTransaction(stepRewardAddress, addressDistributions, stepIdentity, this.gateway);
481
498
  this.logger?.info(`Claimed rewards for step ${stepIdentity.step} at block ${stepIdentity.block}`);
482
499
  this._claimSuccessCounter?.add(1, claimCounterAttributes);
@@ -489,25 +506,36 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
489
506
  }
490
507
  async submitRewardDistributionTransaction(stepRewardAddress, addressDistributions, step, gateway) {
491
508
  const transferPayload = createTransferPayload(stepRewardAddress, addressDistributions);
492
- transferPayload.context = {
493
- step
494
- };
509
+ transferPayload.context = { step };
495
510
  const currentBlockNumber = await this.viewer.currentBlockNumber();
496
- const result = await gateway.addPayloadsToChain?.([
497
- transferPayload
498
- ], [], {
499
- nbf: currentBlockNumber,
500
- exp: asXL1BlockNumber(currentBlockNumber + 10)
501
- });
511
+ const result = await gateway.addPayloadsToChain?.([transferPayload], [], { nbf: currentBlockNumber, exp: asXL1BlockNumber(currentBlockNumber + 10) });
502
512
  if (isDefined3(result)) return result[1];
503
513
  }
504
514
  };
505
515
 
506
516
  // src/services/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.ts
507
- import { AddressZod, assertEx as assertEx4, EthAddressZod, hexToBigInt, HexZod, isDefined as isDefined4, isUndefined as isUndefined2, toAddress as toAddress2, toHex } from "@xylabs/sdk-js";
517
+ import {
518
+ AddressZod,
519
+ assertEx as assertEx4,
520
+ EthAddressZod,
521
+ hexToBigInt,
522
+ HexZod,
523
+ isDefined as isDefined4,
524
+ isUndefined as isUndefined2,
525
+ toAddress as toAddress2,
526
+ toHex
527
+ } from "@xylabs/sdk-js";
508
528
  import { AbstractSentinel as AbstractSentinel2, asSchema as asSchema2 } from "@xyo-network/sdk-js";
509
- import { createTransferPayload as createTransferPayload2, derivedReceiveAddress as derivedReceiveAddress2, flattenHydratedTransaction as flattenHydratedTransaction2, isEIP712DataPayload, isEIP712SignaturePayload, verifyEIP712Message, XL1BlockNumberZod } from "@xyo-network/xl1-sdk";
510
- import z3 from "zod";
529
+ import {
530
+ createTransferPayload as createTransferPayload2,
531
+ derivedReceiveAddress as derivedReceiveAddress2,
532
+ flattenHydratedTransaction as flattenHydratedTransaction2,
533
+ isEIP712DataPayload,
534
+ isEIP712SignaturePayload,
535
+ verifyEIP712Message,
536
+ XL1BlockNumberZod
537
+ } from "@xyo-network/xl1-sdk";
538
+ import { z as z3 } from "zod/mini";
511
539
  var DerivedAddressWalletTransferSentinelConfigSchema = asSchema2("network.xyo.sentinel.chain.derived.address.wallet.transfer.config", true);
512
540
  var scope2 = "reward-escrow";
513
541
  var ConfirmedClaimValuesZod = z3.object({
@@ -515,10 +543,11 @@ var ConfirmedClaimValuesZod = z3.object({
515
543
  "To XL1 Address": AddressZod,
516
544
  "XL1 Amount": z3.string(),
517
545
  "XL1 Amount (Hex)": HexZod,
546
+ // Hex
518
547
  "XL1 Not after block": XL1BlockNumberZod,
519
548
  "XL1 Not before block": XL1BlockNumberZod
520
549
  });
521
- var parseConfirmedClaimValues = /* @__PURE__ */ __name((values) => {
550
+ var parseConfirmedClaimValues = (values) => {
522
551
  return {
523
552
  amount: values["XL1 Amount (Hex)"],
524
553
  exp: values["XL1 Not after block"],
@@ -526,14 +555,9 @@ var parseConfirmedClaimValues = /* @__PURE__ */ __name((values) => {
526
555
  nbf: values["XL1 Not before block"],
527
556
  to: toAddress2(values["To XL1 Address"])
528
557
  };
529
- }, "parseConfirmedClaimValues");
558
+ };
530
559
  var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
531
- static {
532
- __name(this, "DerivedAddressWalletTransferSentinel");
533
- }
534
- static configSchemas = [
535
- DerivedAddressWalletTransferSentinelConfigSchema
536
- ];
560
+ static configSchemas = [DerivedAddressWalletTransferSentinelConfigSchema];
537
561
  static defaultConfigSchema = DerivedAddressWalletTransferSentinelConfigSchema;
538
562
  _transferAttemptsCounter;
539
563
  _transferErrorCounter;
@@ -543,15 +567,18 @@ var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
543
567
  }
544
568
  async createHandler() {
545
569
  await super.createHandler();
546
- this._transferAttemptsCounter = this.meter?.createCounter("derived_address_wallet_transfer_sentinel_attempts_total", {
547
- description: "Number of transfer attempts"
548
- });
549
- this._transferSuccessCounter = this.meter?.createCounter("derived_address_wallet_transfer_sentinel_success_total", {
550
- description: "Number of transfer successes"
551
- });
552
- this._transferErrorCounter = this.meter?.createCounter("derived_address_wallet_transfer_sentinel_errors_total", {
553
- description: "Number of transfer errors"
554
- });
570
+ this._transferAttemptsCounter = this.meter?.createCounter(
571
+ "derived_address_wallet_transfer_sentinel_attempts_total",
572
+ { description: "Number of transfer attempts" }
573
+ );
574
+ this._transferSuccessCounter = this.meter?.createCounter(
575
+ "derived_address_wallet_transfer_sentinel_success_total",
576
+ { description: "Number of transfer successes" }
577
+ );
578
+ this._transferErrorCounter = this.meter?.createCounter(
579
+ "derived_address_wallet_transfer_sentinel_errors_total",
580
+ { description: "Number of transfer errors" }
581
+ );
555
582
  }
556
583
  async reportHandler(payloads) {
557
584
  const data = payloads?.find((x) => isEIP712DataPayload(x));
@@ -577,8 +604,14 @@ var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
577
604
  this._transferErrorCounter?.add(1);
578
605
  return [];
579
606
  }
580
- submitRewardDistributionTransaction = /* @__PURE__ */ __name(async (claimValues) => {
581
- const { amount, from: address, to, nbf, exp } = claimValues;
607
+ submitRewardDistributionTransaction = async (claimValues) => {
608
+ const {
609
+ amount,
610
+ from: address,
611
+ to,
612
+ nbf,
613
+ exp
614
+ } = claimValues;
582
615
  const signer = assertEx4(this.gateway.signer, () => "Signer is not defined in gateway");
583
616
  const signerAddress = await signer.address();
584
617
  const connection = this.gateway.connection;
@@ -591,27 +624,20 @@ var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
591
624
  assertEx4(balance === redemptionAmount, () => "Insufficient balance in escrow account");
592
625
  const allowance = await viewer.account.balance.accountBalance(signerAddress);
593
626
  assertEx4(allowance > 1000n, () => "Insufficient allowance to transfer from escrow account");
594
- const transferPayload = createTransferPayload2(escrowAccount, {
595
- [to]: hexToBigInt(toHex(amount))
596
- });
597
- transferPayload.context = {
598
- address,
599
- scope: scope2
600
- };
627
+ const transferPayload = createTransferPayload2(escrowAccount, { [to]: hexToBigInt(toHex(amount)) });
628
+ transferPayload.context = { address, scope: scope2 };
601
629
  const chain = await viewer.chainId();
602
- const result = await this.gateway.addPayloadsToChain?.([
603
- transferPayload
604
- ], [], {
630
+ const result = await this.gateway.addPayloadsToChain?.([transferPayload], [], {
605
631
  chain,
606
632
  nbf,
607
633
  exp
608
634
  });
609
635
  if (isDefined4(result)) return result[1];
610
- }, "submitRewardDistributionTransaction");
636
+ };
611
637
  };
612
638
 
613
639
  // src/services/manifest/getLocator.ts
614
- var getLocator = /* @__PURE__ */ __name(async (context, gateway) => {
640
+ var getLocator = async (context, gateway) => {
615
641
  const { config, logger } = context;
616
642
  const { otlpEndpoint } = config.telemetry?.otel ?? {};
617
643
  const { path: endpoint = "/metrics", port = 9467 } = config.telemetry?.metrics?.scrape ?? {};
@@ -621,17 +647,20 @@ var getLocator = /* @__PURE__ */ __name(async (context, gateway) => {
621
647
  serviceVersion: "1.0.0"
622
648
  },
623
649
  otlpEndpoint,
624
- metricsConfig: {
625
- endpoint,
626
- port
627
- }
650
+ metricsConfig: { endpoint, port }
628
651
  });
629
652
  if (isDefined5(logger)) AbstractModule.defaultLogger = logger;
630
653
  const statusReporter = logger ? new LoggerModuleStatusReporter(logger) : void 0;
631
654
  const locator = new ModuleFactoryLocator();
632
655
  const mongoConfig = config.storage?.mongo;
633
656
  if (hasMongoConfig(mongoConfig)) {
634
- const { connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName } = mongoConfig;
657
+ const {
658
+ connectionString: dbConnectionString,
659
+ database: dbName,
660
+ domain: dbDomain,
661
+ password: dbPassword,
662
+ username: dbUserName
663
+ } = mongoConfig;
635
664
  const payloadSdkConfig = {
636
665
  dbConnectionString,
637
666
  dbDomain,
@@ -677,7 +706,7 @@ var getLocator = /* @__PURE__ */ __name(async (context, gateway) => {
677
706
  };
678
707
  locator.register(DerivedAddressWalletTransferSentinel.factory(derivedAddressWalletTransferSentinelParams));
679
708
  return locator;
680
- }, "getLocator");
709
+ };
681
710
 
682
711
  // src/services/manifest/getNode.ts
683
712
  import { ManifestWrapper } from "@xyo-network/sdk-js";
@@ -779,7 +808,7 @@ var PrivateChildManifests = [];
779
808
  var PublicChildManifests = [];
780
809
 
781
810
  // src/services/manifest/getNode.ts
782
- var getNode = /* @__PURE__ */ __name(async (context, gateway, wallet) => {
811
+ var getNode = async (context, gateway, wallet) => {
783
812
  const locator = await getLocator(context, gateway);
784
813
  const wrapper = new ManifestWrapper(NodeManifest, wallet, locator, PublicChildManifests, PrivateChildManifests);
785
814
  const [node, ...childNodes] = await wrapper.loadNodes();
@@ -788,11 +817,11 @@ var getNode = /* @__PURE__ */ __name(async (context, gateway, wallet) => {
788
817
  await Promise.all(childNodes.map((childNode) => node.attach(childNode.address, true)));
789
818
  }
790
819
  return node;
791
- }, "getNode");
820
+ };
792
821
 
793
822
  // src/server/server.ts
794
823
  var hostname = "::";
795
- var getServer = /* @__PURE__ */ __name(async (context, gateway, locator, providedNode) => {
824
+ var getServer = async (context, gateway, locator, providedNode) => {
796
825
  const { logger, config } = context;
797
826
  const { port } = config;
798
827
  const bios = await boot();
@@ -809,26 +838,10 @@ var getServer = /* @__PURE__ */ __name(async (context, gateway, locator, provide
809
838
  });
810
839
  server.setTimeout(12e4);
811
840
  return server;
812
- }, "getServer");
841
+ };
813
842
 
814
843
  // src/RewardRedemptionActor.ts
815
- function _ts_decorate(decorators, target, key, desc) {
816
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
817
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
818
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
819
- return c > 3 && r && Object.defineProperty(target, key, r), r;
820
- }
821
- __name(_ts_decorate, "_ts_decorate");
822
844
  var RewardRedemptionActor = class extends ActorV3 {
823
- static {
824
- __name(this, "RewardRedemptionActor");
825
- }
826
- static needs = {
827
- required: [
828
- XyoGatewayRunnerMoniker,
829
- XyoViewerMoniker2
830
- ]
831
- };
832
845
  _gatewayRunner;
833
846
  server;
834
847
  get gatewayRunner() {
@@ -855,7 +868,13 @@ var RewardRedemptionActor = class extends ActorV3 {
855
868
  this.server = void 0;
856
869
  }
857
870
  };
858
- RewardRedemptionActor = _ts_decorate([
871
+ __publicField(RewardRedemptionActor, "needs", {
872
+ required: [
873
+ XyoGatewayRunnerMoniker,
874
+ XyoViewerMoniker2
875
+ ]
876
+ });
877
+ RewardRedemptionActor = __decorateClass([
859
878
  creatable()
860
879
  ], RewardRedemptionActor);
861
880
 
@@ -873,18 +892,14 @@ async function getRewardRedemptionActor(config, locator) {
873
892
  locator
874
893
  });
875
894
  }
876
- __name(getRewardRedemptionActor, "getRewardRedemptionActor");
877
895
  async function runRewardRedemptionApi(config, orchestrator, locator) {
878
896
  const rewardRedemption = await getRewardRedemptionActor(config, locator);
879
- const actors = [
880
- rewardRedemption
881
- ].filter(exists);
897
+ const actors = [rewardRedemption].filter(exists);
882
898
  for (const actor of actors) {
883
899
  await orchestrator.registerActor(actor);
884
900
  }
885
901
  await orchestrator.start();
886
902
  }
887
- __name(runRewardRedemptionApi, "runRewardRedemptionApi");
888
903
 
889
904
  // src/command.ts
890
905
  function rewardRedemptionCommand(getConfiguration, getLocatorsFromConfig) {
@@ -892,16 +907,13 @@ function rewardRedemptionCommand(getConfiguration, getLocatorsFromConfig) {
892
907
  command: "reward-redemption-api",
893
908
  deprecated: 'Use "start rewardRedemption" instead',
894
909
  describe: "Run a XL1 Rewards Redemption API Node",
895
- handler: /* @__PURE__ */ __name(async () => {
910
+ handler: async () => {
896
911
  const configuration = getConfiguration();
897
- const { locators, orchestrator } = await getLocatorsFromConfig([
898
- "rewardRedemption"
899
- ], configuration);
912
+ const { locators, orchestrator } = await getLocatorsFromConfig(["rewardRedemption"], configuration);
900
913
  await runRewardRedemptionApi(RewardRedemptionConfigZod.parse(locators["rewardRedemption"].context.config), orchestrator, locators["rewardRedemption"]);
901
- }, "handler")
914
+ }
902
915
  };
903
916
  }
904
- __name(rewardRedemptionCommand, "rewardRedemptionCommand");
905
917
  export {
906
918
  ChainStepRewardsClaimSentinel,
907
919
  ChainStepRewardsClaimSentinelConfigSchema,
@@ -918,4 +930,4 @@ export {
918
930
  rewardRedemptionCommand,
919
931
  runRewardRedemptionApi
920
932
  };
921
- //# sourceMappingURL=index.mjs.map
933
+ //# sourceMappingURL=index.mjs.map