@xyo-network/chain-reward-redemption 1.15.20 → 1.15.22
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/dist/node/index.mjs +153 -206
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.d.ts +38 -0
- package/dist/node/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.d.ts.map +1 -0
- package/dist/node/modules/ChainStepRewardsClaimSentinel/StepIdentityPayload.d.ts.map +1 -0
- package/dist/node/modules/ChainStepRewardsClaimSentinel/index.d.ts +3 -0
- package/dist/node/modules/ChainStepRewardsClaimSentinel/index.d.ts.map +1 -0
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.d.ts +41 -0
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.d.ts.map +1 -0
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/index.d.ts +2 -0
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/index.d.ts.map +1 -0
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/spec/DerivedAddressWalletTransferSentinel.spec.d.ts +2 -0
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/spec/DerivedAddressWalletTransferSentinel.spec.d.ts.map +1 -0
- package/dist/node/modules/index.d.ts +1 -2
- package/dist/node/modules/index.d.ts.map +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/getRouteDefinitions.d.ts.map +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/index.d.ts +0 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/index.d.ts.map +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/redeem.d.ts +0 -22
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/redeem.d.ts.map +1 -1
- package/package.json +53 -52
- package/src/manifest/getLocator.ts +4 -4
- package/src/manifest/node.json +3 -3
- package/src/modules/{ChainRewardsClaimSentinel.ts → ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts} +18 -18
- package/src/modules/ChainStepRewardsClaimSentinel/index.ts +2 -0
- package/src/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.ts +144 -0
- package/src/modules/DerivedAddressWalletTransferSentinel/index.ts +1 -0
- package/src/modules/DerivedAddressWalletTransferSentinel/spec/DerivedAddressWalletTransferSentinel.spec.ts +138 -0
- package/src/modules/index.ts +1 -2
- package/src/server/routes/rewardRedemption/routeDefinitions/getRouteDefinitions.ts +0 -1
- package/src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts +4 -4
- package/src/server/routes/rewardRedemption/routeDefinitions/routes/index.ts +0 -1
- package/src/server/routes/rewardRedemption/routeDefinitions/routes/redeem.ts +17 -92
- package/dist/node/modules/ChainRewardsClaimSentinel.d.ts +0 -38
- package/dist/node/modules/ChainRewardsClaimSentinel.d.ts.map +0 -1
- package/dist/node/modules/StepIdentityPayload.d.ts.map +0 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/claimAddress.d.ts +0 -3
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/claimAddress.d.ts.map +0 -1
- package/src/server/routes/rewardRedemption/routeDefinitions/routes/claimAddress.ts +0 -133
- /package/dist/node/modules/{StepIdentityPayload.d.ts → ChainStepRewardsClaimSentinel/StepIdentityPayload.d.ts} +0 -0
- /package/src/modules/{StepIdentityPayload.ts → ChainStepRewardsClaimSentinel/StepIdentityPayload.ts} +0 -0
package/dist/node/index.mjs
CHANGED
|
@@ -111,100 +111,6 @@ var addDataLakeRoutes = /* @__PURE__ */ __name((app) => {
|
|
|
111
111
|
}));
|
|
112
112
|
}, "addDataLakeRoutes");
|
|
113
113
|
|
|
114
|
-
// src/server/routes/rewardRedemption/middleware/requestHandlerValidator.ts
|
|
115
|
-
import { isDefined as isDefined2, isPromise } from "@xylabs/typeof";
|
|
116
|
-
import { ReasonPhrases, StatusCodes } from "http-status-codes";
|
|
117
|
-
import { z } from "zod";
|
|
118
|
-
var EmptyParamsZod = z.object({}).catchall(z.string());
|
|
119
|
-
var EmptyQueryParamsZod = z.object({}).catchall(z.union([
|
|
120
|
-
z.string(),
|
|
121
|
-
z.array(z.string())
|
|
122
|
-
]));
|
|
123
|
-
var ValidateRequestDefaults = {
|
|
124
|
-
params: EmptyParamsZod,
|
|
125
|
-
query: EmptyQueryParamsZod,
|
|
126
|
-
body: z.json().optional(),
|
|
127
|
-
response: z.json().optional()
|
|
128
|
-
};
|
|
129
|
-
function requestHandlerValidator(schemas) {
|
|
130
|
-
const validators = {
|
|
131
|
-
...ValidateRequestDefaults,
|
|
132
|
-
...schemas
|
|
133
|
-
};
|
|
134
|
-
return (handler) => {
|
|
135
|
-
return async (req, res, next) => {
|
|
136
|
-
const originalJson = res.json.bind(res);
|
|
137
|
-
try {
|
|
138
|
-
const errors = [];
|
|
139
|
-
const keys = [
|
|
140
|
-
"params",
|
|
141
|
-
"query",
|
|
142
|
-
"body"
|
|
143
|
-
];
|
|
144
|
-
for (const key of keys) {
|
|
145
|
-
const validator = validators[key];
|
|
146
|
-
const result2 = validator.safeParse(req[key]);
|
|
147
|
-
if (result2.success) {
|
|
148
|
-
if (isDefined2(result2.data)) Object.assign(req[key], result2.data);
|
|
149
|
-
} else {
|
|
150
|
-
errors.push(...result2.error.issues.map((issue) => issue.path.length === 0 ? `${key}: ${issue.message}` : `${key}.${issue.path.join(".")}: ${issue.message}`));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (errors.length > 0) {
|
|
154
|
-
const message = errors.join("; ");
|
|
155
|
-
const err = new Error(message);
|
|
156
|
-
err.name = ReasonPhrases.BAD_REQUEST;
|
|
157
|
-
err.statusCode = StatusCodes.BAD_REQUEST;
|
|
158
|
-
next(err);
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
res.json = (data) => {
|
|
162
|
-
const result2 = validators.response.safeParse(data);
|
|
163
|
-
if (result2.success) {
|
|
164
|
-
return originalJson(result2.data);
|
|
165
|
-
} else {
|
|
166
|
-
const message = result2.error.issues.map((issue) => issue.path.length === 0 ? `response: ${issue.message}` : `response.${issue.path.join(".")}: ${issue.message}`).join("; ");
|
|
167
|
-
const err = new Error(message);
|
|
168
|
-
err.name = ReasonPhrases.INTERNAL_SERVER_ERROR;
|
|
169
|
-
err.statusCode = StatusCodes.INTERNAL_SERVER_ERROR;
|
|
170
|
-
res.json = originalJson;
|
|
171
|
-
throw err;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
const result = handler(req, res, next);
|
|
175
|
-
if (result && isPromise(result)) {
|
|
176
|
-
await result;
|
|
177
|
-
}
|
|
178
|
-
} catch (err) {
|
|
179
|
-
res.json = originalJson;
|
|
180
|
-
next(err);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
__name(requestHandlerValidator, "requestHandlerValidator");
|
|
186
|
-
|
|
187
|
-
// src/server/routes/rewardRedemption/routeDefinitions/util/getViewerFromConfig.ts
|
|
188
|
-
import { isDefined as isDefined3 } from "@xylabs/typeof";
|
|
189
|
-
import { HttpRpcTransport, JsonRpcXyoViewer, XyoViewerRpcSchemas } from "@xyo-network/xl1-rpc";
|
|
190
|
-
var viewer;
|
|
191
|
-
var getViewerFromConfig = /* @__PURE__ */ __name((config) => {
|
|
192
|
-
if (isDefined3(viewer)) return viewer;
|
|
193
|
-
const transport = new HttpRpcTransport(config.rewardRedemptionApi.chainRpcApiUrl, XyoViewerRpcSchemas);
|
|
194
|
-
viewer = new JsonRpcXyoViewer(transport);
|
|
195
|
-
return viewer;
|
|
196
|
-
}, "getViewerFromConfig");
|
|
197
|
-
|
|
198
|
-
// src/server/routes/rewardRedemption/routeDefinitions/util/rewardableSteps.ts
|
|
199
|
-
var RewardableSteps = [
|
|
200
|
-
3,
|
|
201
|
-
4,
|
|
202
|
-
5,
|
|
203
|
-
6,
|
|
204
|
-
7,
|
|
205
|
-
8
|
|
206
|
-
];
|
|
207
|
-
|
|
208
114
|
// src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
|
|
209
115
|
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
210
116
|
import { isDefined as isDefined5 } from "@xylabs/typeof";
|
|
@@ -215,17 +121,17 @@ import { asSentinelInstance } from "@xyo-network/sentinel-model";
|
|
|
215
121
|
import { asXL1BlockNumber as asXL1BlockNumber2 } from "@xyo-network/xl1-protocol";
|
|
216
122
|
import { z as z2 } from "zod";
|
|
217
123
|
|
|
218
|
-
// src/modules/
|
|
124
|
+
// src/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts
|
|
219
125
|
import { assertEx } from "@xylabs/assert";
|
|
220
126
|
import { toAddress } from "@xylabs/hex";
|
|
221
|
-
import { isDefined as
|
|
127
|
+
import { isDefined as isDefined2, isUndefined } from "@xylabs/typeof";
|
|
222
128
|
import { blockRangeSteps, createTransferPayload } from "@xyo-network/chain-protocol";
|
|
223
129
|
import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
|
|
224
130
|
import { asXL1BlockNumber, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
225
131
|
import { completedStepRewardAddress, derivedReceiveAddress, flattenHydratedTransaction, flattenHydratedTransactions } from "@xyo-network/xl1-protocol-sdk";
|
|
226
132
|
import { Mutex } from "async-mutex";
|
|
227
133
|
|
|
228
|
-
// src/modules/StepIdentityPayload.ts
|
|
134
|
+
// src/modules/ChainStepRewardsClaimSentinel/StepIdentityPayload.ts
|
|
229
135
|
import { AsObjectFactory } from "@xylabs/object";
|
|
230
136
|
import { isPayloadOfZodType } from "@xyo-network/payload-model";
|
|
231
137
|
import { StepIdentityZod } from "@xyo-network/xl1-rpc";
|
|
@@ -233,10 +139,10 @@ var StepIdentitySchema = "network.xyo.chain.step.identity";
|
|
|
233
139
|
var isStepIdentityPayload = isPayloadOfZodType(StepIdentityZod, StepIdentitySchema);
|
|
234
140
|
var asStepIdentityPayload = AsObjectFactory.create(isStepIdentityPayload);
|
|
235
141
|
|
|
236
|
-
// src/modules/
|
|
237
|
-
var
|
|
142
|
+
// src/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts
|
|
143
|
+
var ChainStepRewardsClaimSentinelConfigSchema = "network.xyo.sentinel.chain.step.rewards.claim.config";
|
|
238
144
|
var scope = "reward-escrow";
|
|
239
|
-
var
|
|
145
|
+
var RewardableSteps = [
|
|
240
146
|
3,
|
|
241
147
|
4,
|
|
242
148
|
5,
|
|
@@ -244,14 +150,14 @@ var RewardableSteps2 = [
|
|
|
244
150
|
7,
|
|
245
151
|
8
|
|
246
152
|
];
|
|
247
|
-
var
|
|
153
|
+
var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
248
154
|
static {
|
|
249
|
-
__name(this, "
|
|
155
|
+
__name(this, "ChainStepRewardsClaimSentinel");
|
|
250
156
|
}
|
|
251
157
|
static configSchemas = [
|
|
252
|
-
|
|
158
|
+
ChainStepRewardsClaimSentinelConfigSchema
|
|
253
159
|
];
|
|
254
|
-
static defaultConfigSchema =
|
|
160
|
+
static defaultConfigSchema = ChainStepRewardsClaimSentinelConfigSchema;
|
|
255
161
|
_claimAttemptsCounter;
|
|
256
162
|
_claimCheckCounter;
|
|
257
163
|
_claimErrorCounter;
|
|
@@ -262,16 +168,16 @@ var ChainRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
262
168
|
}
|
|
263
169
|
async createHandler() {
|
|
264
170
|
await super.createHandler();
|
|
265
|
-
this._claimAttemptsCounter = this.meter?.createCounter("
|
|
171
|
+
this._claimAttemptsCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_attempts_total", {
|
|
266
172
|
description: "Number of claim attempts"
|
|
267
173
|
});
|
|
268
|
-
this._claimCheckCounter = this.meter?.createCounter("
|
|
174
|
+
this._claimCheckCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_check_total", {
|
|
269
175
|
description: "Number of claim checks"
|
|
270
176
|
});
|
|
271
|
-
this._claimSuccessCounter = this.meter?.createCounter("
|
|
177
|
+
this._claimSuccessCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_success_total", {
|
|
272
178
|
description: "Number of claim successes"
|
|
273
179
|
});
|
|
274
|
-
this._claimErrorCounter = this.meter?.createCounter("
|
|
180
|
+
this._claimErrorCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_errors_total", {
|
|
275
181
|
description: "Number of claim errors"
|
|
276
182
|
});
|
|
277
183
|
}
|
|
@@ -292,10 +198,10 @@ var ChainRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
292
198
|
step,
|
|
293
199
|
block
|
|
294
200
|
};
|
|
295
|
-
}).filter((stepIdentity) =>
|
|
201
|
+
}).filter((stepIdentity) => RewardableSteps.includes(stepIdentity.step));
|
|
296
202
|
for (const stepIdentity of stepIdentities) {
|
|
297
203
|
const result = await this.claimStepIdentity(stepIdentity);
|
|
298
|
-
if (
|
|
204
|
+
if (isDefined2(result)) response3.push(...flattenHydratedTransaction(result));
|
|
299
205
|
}
|
|
300
206
|
}
|
|
301
207
|
return response3;
|
|
@@ -323,8 +229,8 @@ var ChainRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
323
229
|
const results = [];
|
|
324
230
|
const connection = await this.gateway.connection();
|
|
325
231
|
const { viewer: viewer2 } = connection;
|
|
326
|
-
if (
|
|
327
|
-
for (const step of
|
|
232
|
+
if (isDefined2(viewer2)) {
|
|
233
|
+
for (const step of RewardableSteps) {
|
|
328
234
|
const from = 0;
|
|
329
235
|
const to = await viewer2.currentBlockNumber();
|
|
330
236
|
const range = [
|
|
@@ -336,7 +242,7 @@ var ChainRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
336
242
|
]);
|
|
337
243
|
for (const stepIdentity of stepIdentities) {
|
|
338
244
|
const result = await this.claimStepIdentity(stepIdentity);
|
|
339
|
-
if (
|
|
245
|
+
if (isDefined2(result)) results.push(result);
|
|
340
246
|
}
|
|
341
247
|
}
|
|
342
248
|
}
|
|
@@ -385,26 +291,120 @@ var ChainRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
385
291
|
nbf: currentBlock,
|
|
386
292
|
exp: currentBlock + 1e3
|
|
387
293
|
});
|
|
388
|
-
if (
|
|
294
|
+
if (isDefined2(result)) return result[1];
|
|
389
295
|
}
|
|
390
296
|
};
|
|
391
297
|
|
|
298
|
+
// src/server/routes/rewardRedemption/middleware/requestHandlerValidator.ts
|
|
299
|
+
import { isDefined as isDefined3, isPromise } from "@xylabs/typeof";
|
|
300
|
+
import { ReasonPhrases, StatusCodes } from "http-status-codes";
|
|
301
|
+
import { z } from "zod";
|
|
302
|
+
var EmptyParamsZod = z.object({}).catchall(z.string());
|
|
303
|
+
var EmptyQueryParamsZod = z.object({}).catchall(z.union([
|
|
304
|
+
z.string(),
|
|
305
|
+
z.array(z.string())
|
|
306
|
+
]));
|
|
307
|
+
var ValidateRequestDefaults = {
|
|
308
|
+
params: EmptyParamsZod,
|
|
309
|
+
query: EmptyQueryParamsZod,
|
|
310
|
+
body: z.json().optional(),
|
|
311
|
+
response: z.json().optional()
|
|
312
|
+
};
|
|
313
|
+
function requestHandlerValidator(schemas) {
|
|
314
|
+
const validators = {
|
|
315
|
+
...ValidateRequestDefaults,
|
|
316
|
+
...schemas
|
|
317
|
+
};
|
|
318
|
+
return (handler) => {
|
|
319
|
+
return async (req, res, next) => {
|
|
320
|
+
const originalJson = res.json.bind(res);
|
|
321
|
+
try {
|
|
322
|
+
const errors = [];
|
|
323
|
+
const keys = [
|
|
324
|
+
"params",
|
|
325
|
+
"query",
|
|
326
|
+
"body"
|
|
327
|
+
];
|
|
328
|
+
for (const key of keys) {
|
|
329
|
+
const validator = validators[key];
|
|
330
|
+
const result2 = validator.safeParse(req[key]);
|
|
331
|
+
if (result2.success) {
|
|
332
|
+
if (isDefined3(result2.data)) Object.assign(req[key], result2.data);
|
|
333
|
+
} else {
|
|
334
|
+
errors.push(...result2.error.issues.map((issue) => issue.path.length === 0 ? `${key}: ${issue.message}` : `${key}.${issue.path.join(".")}: ${issue.message}`));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (errors.length > 0) {
|
|
338
|
+
const message = errors.join("; ");
|
|
339
|
+
const err = new Error(message);
|
|
340
|
+
err.name = ReasonPhrases.BAD_REQUEST;
|
|
341
|
+
err.statusCode = StatusCodes.BAD_REQUEST;
|
|
342
|
+
next(err);
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
res.json = (data) => {
|
|
346
|
+
const result2 = validators.response.safeParse(data);
|
|
347
|
+
if (result2.success) {
|
|
348
|
+
return originalJson(result2.data);
|
|
349
|
+
} else {
|
|
350
|
+
const message = result2.error.issues.map((issue) => issue.path.length === 0 ? `response: ${issue.message}` : `response.${issue.path.join(".")}: ${issue.message}`).join("; ");
|
|
351
|
+
const err = new Error(message);
|
|
352
|
+
err.name = ReasonPhrases.INTERNAL_SERVER_ERROR;
|
|
353
|
+
err.statusCode = StatusCodes.INTERNAL_SERVER_ERROR;
|
|
354
|
+
res.json = originalJson;
|
|
355
|
+
throw err;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
const result = handler(req, res, next);
|
|
359
|
+
if (result && isPromise(result)) {
|
|
360
|
+
await result;
|
|
361
|
+
}
|
|
362
|
+
} catch (err) {
|
|
363
|
+
res.json = originalJson;
|
|
364
|
+
next(err);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
__name(requestHandlerValidator, "requestHandlerValidator");
|
|
370
|
+
|
|
371
|
+
// src/server/routes/rewardRedemption/routeDefinitions/util/getViewerFromConfig.ts
|
|
372
|
+
import { isDefined as isDefined4 } from "@xylabs/typeof";
|
|
373
|
+
import { HttpRpcTransport, JsonRpcXyoViewer, XyoViewerRpcSchemas } from "@xyo-network/xl1-rpc";
|
|
374
|
+
var viewer;
|
|
375
|
+
var getViewerFromConfig = /* @__PURE__ */ __name((config) => {
|
|
376
|
+
if (isDefined4(viewer)) return viewer;
|
|
377
|
+
const transport = new HttpRpcTransport(config.rewardRedemptionApi.chainRpcApiUrl, XyoViewerRpcSchemas);
|
|
378
|
+
viewer = new JsonRpcXyoViewer(transport);
|
|
379
|
+
return viewer;
|
|
380
|
+
}, "getViewerFromConfig");
|
|
381
|
+
|
|
382
|
+
// src/server/routes/rewardRedemption/routeDefinitions/util/rewardableSteps.ts
|
|
383
|
+
var RewardableSteps2 = [
|
|
384
|
+
3,
|
|
385
|
+
4,
|
|
386
|
+
5,
|
|
387
|
+
6,
|
|
388
|
+
7,
|
|
389
|
+
8
|
|
390
|
+
];
|
|
391
|
+
|
|
392
392
|
// src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
|
|
393
393
|
var query = z2.object({
|
|
394
394
|
fromBlock: z2.coerce.number().int().min(0).optional(),
|
|
395
395
|
toBlock: z2.coerce.number().int().min(0).optional(),
|
|
396
|
-
step: z2.coerce.number().min(Math.min(...
|
|
396
|
+
step: z2.coerce.number().min(Math.min(...RewardableSteps2)).max(Math.max(...RewardableSteps2)).int().optional().default(3)
|
|
397
397
|
});
|
|
398
398
|
var response = z2.array(PayloadZodLoose);
|
|
399
399
|
var validateRequest = requestHandlerValidator({
|
|
400
400
|
query,
|
|
401
401
|
response
|
|
402
402
|
});
|
|
403
|
-
var
|
|
404
|
-
const mod = await node.resolve("XYORewardRedemptionNode:
|
|
403
|
+
var getChainStepRewardsClaimSentinel = /* @__PURE__ */ __name(async (node) => {
|
|
404
|
+
const mod = await node.resolve("XYORewardRedemptionNode:ChainStepRewardsClaimSentinel");
|
|
405
405
|
const sentinel = asSentinelInstance(mod);
|
|
406
|
-
return assertEx2(sentinel, () => "
|
|
407
|
-
}, "
|
|
406
|
+
return assertEx2(sentinel, () => "ChainStepRewardsClaimSentinel not found on node");
|
|
407
|
+
}, "getChainStepRewardsClaimSentinel");
|
|
408
408
|
var postClaimRange = {
|
|
409
409
|
method: "post",
|
|
410
410
|
path: "/rewards/claimRange",
|
|
@@ -429,7 +429,7 @@ var postClaimRange = {
|
|
|
429
429
|
]);
|
|
430
430
|
const results = [];
|
|
431
431
|
for (const stepIdentity of stepIdentities) {
|
|
432
|
-
const mod = await
|
|
432
|
+
const mod = await getChainStepRewardsClaimSentinel(node);
|
|
433
433
|
const stepIdentityPayload = new PayloadBuilder2({
|
|
434
434
|
schema: StepIdentitySchema
|
|
435
435
|
}).fields(stepIdentity).build();
|
|
@@ -445,83 +445,31 @@ var postClaimRange = {
|
|
|
445
445
|
|
|
446
446
|
// src/server/routes/rewardRedemption/routeDefinitions/routes/redeem.ts
|
|
447
447
|
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
448
|
-
import {
|
|
449
|
-
import {
|
|
450
|
-
import { createTransferPayload as createTransferPayload2 } from "@xyo-network/chain-protocol";
|
|
451
|
-
import { HDWallet } from "@xyo-network/wallet";
|
|
452
|
-
import { verifyEIP712Message } from "@xyo-network/xl1-protocol-sdk";
|
|
453
|
-
import { HttpRpcXyoConnection, MemoryXyoGateway, MemoryXyoSigner, SignedHydratedTransactionZod } from "@xyo-network/xl1-rpc";
|
|
448
|
+
import { PayloadZodLoose as PayloadZodLoose2 } from "@xyo-network/payload-model";
|
|
449
|
+
import { asSentinelInstance as asSentinelInstance2 } from "@xyo-network/sentinel-model";
|
|
454
450
|
import { z as z3 } from "zod";
|
|
455
|
-
var body = z3.
|
|
456
|
-
var response2 =
|
|
451
|
+
var body = z3.array(PayloadZodLoose2);
|
|
452
|
+
var response2 = z3.array(PayloadZodLoose2);
|
|
457
453
|
var validateRequest2 = requestHandlerValidator({
|
|
458
454
|
body,
|
|
459
455
|
response: response2
|
|
460
456
|
});
|
|
461
|
-
var
|
|
462
|
-
const
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
endpoint,
|
|
467
|
-
account
|
|
468
|
-
});
|
|
469
|
-
const gateway = new MemoryXyoGateway(signer, connection);
|
|
470
|
-
return gateway;
|
|
471
|
-
}, "getGateway");
|
|
472
|
-
var submitRewardDistributionTransaction = /* @__PURE__ */ __name(async (to, amount, nbf, exp, gateway) => {
|
|
473
|
-
const signer = assertEx3(await gateway.signer(), () => "Signer is not defined in gateway");
|
|
474
|
-
const from = await signer.address();
|
|
475
|
-
const transferPayload = createTransferPayload2(from, {
|
|
476
|
-
[to]: hexToBigInt(toHex(amount))
|
|
477
|
-
});
|
|
478
|
-
const connection = await gateway.connection();
|
|
479
|
-
const viewer2 = assertEx3(connection.viewer, () => "Viewer is not defined in gateway connection");
|
|
480
|
-
const chain = await viewer2.chainId();
|
|
481
|
-
const result = await gateway.addPayloadsToChain?.([
|
|
482
|
-
transferPayload
|
|
483
|
-
], [], {
|
|
484
|
-
chain,
|
|
485
|
-
nbf,
|
|
486
|
-
exp
|
|
487
|
-
});
|
|
488
|
-
if (isDefined6(result)) return result[1];
|
|
489
|
-
}, "submitRewardDistributionTransaction");
|
|
490
|
-
var parseConfirmedClaimValues = /* @__PURE__ */ __name((values) => {
|
|
491
|
-
return {
|
|
492
|
-
from: toAddress2(values.from),
|
|
493
|
-
to: values["To XL1 Address"],
|
|
494
|
-
amount: values["XL1 Amount (Hex)"],
|
|
495
|
-
nbf: values["XL1 Not before block"],
|
|
496
|
-
exp: values["XL1 Not after block"]
|
|
497
|
-
};
|
|
498
|
-
}, "parseConfirmedClaimValues");
|
|
457
|
+
var getDerivedAddressWalletTransferSentinel = /* @__PURE__ */ __name(async (node) => {
|
|
458
|
+
const mod = await node.resolve("XYORewardRedemptionNode:DerivedAddressWalletTransferSentinel");
|
|
459
|
+
const sentinel = asSentinelInstance2(mod);
|
|
460
|
+
return assertEx3(sentinel, () => "DerivedAddressWalletTransferSentinel not found on node");
|
|
461
|
+
}, "getDerivedAddressWalletTransferSentinel");
|
|
499
462
|
var postRedeem = {
|
|
500
463
|
method: "post",
|
|
501
464
|
path: "/rewards/redeem",
|
|
502
465
|
handlers: validateRequest2(async (req, res) => {
|
|
503
|
-
const {
|
|
466
|
+
const { node } = req.app;
|
|
504
467
|
const { body: body2 } = req;
|
|
505
|
-
const
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
assertEx3(toAddress2(signature.address) === toAddress2(from), () => "Signature does not match from address");
|
|
511
|
-
const gateway = await getGateway(config);
|
|
512
|
-
const receiver = toAddress2(to);
|
|
513
|
-
const tx = await submitRewardDistributionTransaction(receiver, amount, nbf, exp, gateway);
|
|
514
|
-
if (isDefined6(tx)) {
|
|
515
|
-
res.status(200);
|
|
516
|
-
res.json(tx);
|
|
517
|
-
} else {
|
|
518
|
-
res.status(500);
|
|
519
|
-
res.json();
|
|
520
|
-
}
|
|
521
|
-
} else {
|
|
522
|
-
res.status(404);
|
|
523
|
-
res.json();
|
|
524
|
-
}
|
|
468
|
+
const input = body2;
|
|
469
|
+
const sentinel = await getDerivedAddressWalletTransferSentinel(node);
|
|
470
|
+
const result = await sentinel.report(input);
|
|
471
|
+
res.status(200);
|
|
472
|
+
res.json(result);
|
|
525
473
|
})
|
|
526
474
|
};
|
|
527
475
|
|
|
@@ -529,7 +477,6 @@ var postRedeem = {
|
|
|
529
477
|
var getRouteDefinitions = /* @__PURE__ */ __name(() => {
|
|
530
478
|
return [
|
|
531
479
|
postClaimRange,
|
|
532
|
-
// postClaim,
|
|
533
480
|
postRedeem
|
|
534
481
|
];
|
|
535
482
|
}, "getRouteDefinitions");
|
|
@@ -572,12 +519,12 @@ var getApp = /* @__PURE__ */ __name((node, config) => {
|
|
|
572
519
|
|
|
573
520
|
// src/server/server.ts
|
|
574
521
|
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
575
|
-
import { isDefined as
|
|
522
|
+
import { isDefined as isDefined7, isString } from "@xylabs/typeof";
|
|
576
523
|
import { boot } from "@xyo-network/bios";
|
|
577
|
-
import { HDWallet as
|
|
524
|
+
import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
|
|
578
525
|
|
|
579
526
|
// src/manifest/getLocator.ts
|
|
580
|
-
import { isDefined as
|
|
527
|
+
import { isDefined as isDefined6 } from "@xylabs/typeof";
|
|
581
528
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
582
529
|
import { MongoDBArchivistV2 } from "@xyo-network/archivist-mongodb";
|
|
583
530
|
import { ViewArchivist } from "@xyo-network/archivist-view";
|
|
@@ -585,9 +532,9 @@ import { initTelemetry } from "@xyo-network/chain-telemetry";
|
|
|
585
532
|
import { AbstractModule, LoggerModuleStatusReporter } from "@xyo-network/module-abstract";
|
|
586
533
|
import { ModuleFactoryLocator } from "@xyo-network/module-factory-locator";
|
|
587
534
|
import { MemorySentinel } from "@xyo-network/sentinel-memory";
|
|
588
|
-
import { HDWallet
|
|
535
|
+
import { HDWallet } from "@xyo-network/wallet";
|
|
589
536
|
import { hasMongoConfig } from "@xyo-network/xl1-protocol-sdk";
|
|
590
|
-
import { HttpRpcXyoConnection
|
|
537
|
+
import { HttpRpcXyoConnection, MemoryXyoGateway, MemoryXyoSigner } from "@xyo-network/xl1-rpc";
|
|
591
538
|
var getLocator = /* @__PURE__ */ __name(async (context) => {
|
|
592
539
|
const { config, logger } = context;
|
|
593
540
|
const { otlpEndpoint } = config.telemetry?.otel ?? {};
|
|
@@ -602,7 +549,7 @@ var getLocator = /* @__PURE__ */ __name(async (context) => {
|
|
|
602
549
|
port: 9465
|
|
603
550
|
}
|
|
604
551
|
});
|
|
605
|
-
if (
|
|
552
|
+
if (isDefined6(logger)) AbstractModule.defaultLogger = logger;
|
|
606
553
|
const statusReporter = logger ? new LoggerModuleStatusReporter(logger) : void 0;
|
|
607
554
|
const locator = new ModuleFactoryLocator();
|
|
608
555
|
const mongoConfig = config.storage?.mongo;
|
|
@@ -643,21 +590,21 @@ var getLocator = /* @__PURE__ */ __name(async (context) => {
|
|
|
643
590
|
}, "getLocator");
|
|
644
591
|
var registerChainRewardsClaimSentinel = /* @__PURE__ */ __name(async (locator, config, traceProvider, meterProvider, statusReporter) => {
|
|
645
592
|
const { mnemonic, chainRpcApiUrl: endpoint } = config.rewardRedemptionApi;
|
|
646
|
-
const walletPromise =
|
|
593
|
+
const walletPromise = isDefined6(mnemonic) ? HDWallet.fromPhrase(mnemonic) : HDWallet.random();
|
|
647
594
|
const account = await walletPromise;
|
|
648
|
-
const signer = new
|
|
649
|
-
const connection = new
|
|
595
|
+
const signer = new MemoryXyoSigner(account);
|
|
596
|
+
const connection = new HttpRpcXyoConnection({
|
|
650
597
|
endpoint,
|
|
651
598
|
account
|
|
652
599
|
});
|
|
653
|
-
const gateway = new
|
|
654
|
-
const
|
|
600
|
+
const gateway = new MemoryXyoGateway(signer, connection);
|
|
601
|
+
const chainStepRewardsClaimSentinelParams = {
|
|
655
602
|
gateway,
|
|
656
603
|
traceProvider,
|
|
657
604
|
meterProvider,
|
|
658
605
|
statusReporter
|
|
659
606
|
};
|
|
660
|
-
locator.register(
|
|
607
|
+
locator.register(ChainStepRewardsClaimSentinel.factory(chainStepRewardsClaimSentinelParams));
|
|
661
608
|
}, "registerChainRewardsClaimSentinel");
|
|
662
609
|
|
|
663
610
|
// src/manifest/getNode.ts
|
|
@@ -692,8 +639,8 @@ var node_default = {
|
|
|
692
639
|
{
|
|
693
640
|
config: {
|
|
694
641
|
accountPath: "1/1'/2'",
|
|
695
|
-
name: "
|
|
696
|
-
schema: "network.xyo.sentinel.chain.rewards.claim.config"
|
|
642
|
+
name: "ChainStepRewardsClaimSentinel",
|
|
643
|
+
schema: "network.xyo.sentinel.chain.step.rewards.claim.config"
|
|
697
644
|
}
|
|
698
645
|
},
|
|
699
646
|
{
|
|
@@ -712,7 +659,7 @@ var node_default = {
|
|
|
712
659
|
synchronous: true,
|
|
713
660
|
tasks: [
|
|
714
661
|
{
|
|
715
|
-
mod: "
|
|
662
|
+
mod: "ChainStepRewardsClaimSentinel",
|
|
716
663
|
endPoint: "report"
|
|
717
664
|
}
|
|
718
665
|
]
|
|
@@ -779,7 +726,7 @@ var getSeedPhrase = /* @__PURE__ */ __name(async (bios, config, logger) => {
|
|
|
779
726
|
if (isString(mnemonic)) {
|
|
780
727
|
seedPhrase = mnemonic;
|
|
781
728
|
} else {
|
|
782
|
-
seedPhrase =
|
|
729
|
+
seedPhrase = HDWallet2.generateMnemonic();
|
|
783
730
|
logger?.log("[Bridge] No mnemonic provided, using random mnemonic. This is not recommended for production use.");
|
|
784
731
|
logger?.log(`[Bridge] Mnemonic: ${seedPhrase}`);
|
|
785
732
|
}
|
|
@@ -791,8 +738,8 @@ var getServer = /* @__PURE__ */ __name(async (context) => {
|
|
|
791
738
|
const { logger, config } = context;
|
|
792
739
|
const { port, mnemonic } = config.rewardRedemptionApi;
|
|
793
740
|
const bios = await boot();
|
|
794
|
-
const seedPhrase =
|
|
795
|
-
const wallet = await
|
|
741
|
+
const seedPhrase = isDefined7(mnemonic) ? mnemonic : await getSeedPhrase(bios, config, logger);
|
|
742
|
+
const wallet = await HDWallet2.fromPhrase(seedPhrase);
|
|
796
743
|
const nodeContext = {
|
|
797
744
|
wallet,
|
|
798
745
|
logger,
|