@xyo-network/chain-reward-redemption 1.15.22 → 1.15.23
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 +194 -68
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/manifest/getLocator.d.ts.map +1 -1
- package/dist/node/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.d.ts.map +1 -1
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.d.ts +23 -1
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.d.ts.map +1 -1
- package/dist/node/modules/helper/index.d.ts +2 -0
- package/dist/node/modules/helper/index.d.ts.map +1 -0
- package/dist/node/modules/helper/retry.d.ts +9 -0
- package/dist/node/modules/helper/retry.d.ts.map +1 -0
- package/dist/node/modules/index.d.ts +1 -0
- package/dist/node/modules/index.d.ts.map +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/redeem.d.ts.map +1 -1
- package/package.json +53 -53
- package/src/manifest/getLocator.ts +15 -13
- package/src/manifest/node.json +4 -19
- package/src/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts +5 -2
- package/src/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.ts +68 -40
- package/src/modules/DerivedAddressWalletTransferSentinel/spec/DerivedAddressWalletTransferSentinel.spec.ts +23 -15
- package/src/modules/helper/index.ts +1 -0
- package/src/modules/helper/retry.ts +30 -0
- package/src/modules/index.ts +1 -0
- package/src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts +3 -3
- package/src/server/routes/rewardRedemption/routeDefinitions/routes/redeem.ts +10 -6
package/dist/node/index.mjs
CHANGED
|
@@ -112,14 +112,14 @@ var addDataLakeRoutes = /* @__PURE__ */ __name((app) => {
|
|
|
112
112
|
}, "addDataLakeRoutes");
|
|
113
113
|
|
|
114
114
|
// src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
|
|
115
|
-
import { assertEx as
|
|
116
|
-
import { isDefined as
|
|
115
|
+
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
116
|
+
import { isDefined as isDefined6 } from "@xylabs/typeof";
|
|
117
117
|
import { blockRangeSteps as blockRangeSteps2 } from "@xyo-network/chain-protocol";
|
|
118
118
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
119
119
|
import { PayloadZodLoose } from "@xyo-network/payload-model";
|
|
120
120
|
import { asSentinelInstance } from "@xyo-network/sentinel-model";
|
|
121
121
|
import { asXL1BlockNumber as asXL1BlockNumber2 } from "@xyo-network/xl1-protocol";
|
|
122
|
-
import { z as
|
|
122
|
+
import { z as z3 } from "zod";
|
|
123
123
|
|
|
124
124
|
// src/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts
|
|
125
125
|
import { assertEx } from "@xylabs/assert";
|
|
@@ -131,6 +131,23 @@ import { asXL1BlockNumber, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-prot
|
|
|
131
131
|
import { completedStepRewardAddress, derivedReceiveAddress, flattenHydratedTransaction, flattenHydratedTransactions } from "@xyo-network/xl1-protocol-sdk";
|
|
132
132
|
import { Mutex } from "async-mutex";
|
|
133
133
|
|
|
134
|
+
// src/modules/helper/retry.ts
|
|
135
|
+
import { delay } from "@xylabs/delay";
|
|
136
|
+
async function retry(fn, delayMs = 1e3, retries = 3) {
|
|
137
|
+
let lastError;
|
|
138
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
139
|
+
try {
|
|
140
|
+
return await fn();
|
|
141
|
+
} catch (error) {
|
|
142
|
+
lastError = error;
|
|
143
|
+
if (attempt >= retries) throw lastError;
|
|
144
|
+
if (delayMs > 0) await delay(delayMs);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
throw new Error("Retry logic failed unexpectedly");
|
|
148
|
+
}
|
|
149
|
+
__name(retry, "retry");
|
|
150
|
+
|
|
134
151
|
// src/modules/ChainStepRewardsClaimSentinel/StepIdentityPayload.ts
|
|
135
152
|
import { AsObjectFactory } from "@xylabs/object";
|
|
136
153
|
import { isPayloadOfZodType } from "@xyo-network/payload-model";
|
|
@@ -141,6 +158,8 @@ var asStepIdentityPayload = AsObjectFactory.create(isStepIdentityPayload);
|
|
|
141
158
|
|
|
142
159
|
// src/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts
|
|
143
160
|
var ChainStepRewardsClaimSentinelConfigSchema = "network.xyo.sentinel.chain.step.rewards.claim.config";
|
|
161
|
+
var retryAttempts = 3;
|
|
162
|
+
var retryDelayMs = 6e4;
|
|
144
163
|
var scope = "reward-escrow";
|
|
145
164
|
var RewardableSteps = [
|
|
146
165
|
3,
|
|
@@ -261,9 +280,9 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
261
280
|
const stepRewardAddress = completedStepRewardAddress(stepIdentity);
|
|
262
281
|
const balance = await viewer2.accountBalance(stepRewardAddress);
|
|
263
282
|
if (balance > 0n) {
|
|
264
|
-
this.logger?.info(`Found
|
|
283
|
+
this.logger?.info(`Found balance of ${balance} to claim for step ${stepIdentity.step} at block ${stepIdentity.block}`);
|
|
265
284
|
this._claimAttemptsCounter?.add(1, claimCounterAttributes);
|
|
266
|
-
const rewardsByStaker = await viewer2.networkStakeStepRewardPoolRewards(stepIdentity);
|
|
285
|
+
const rewardsByStaker = await retry(() => viewer2.networkStakeStepRewardPoolRewards(stepIdentity), retryDelayMs, retryAttempts);
|
|
267
286
|
const addressDistributions = this.calculateAddressDistributions(rewardsByStaker, balance);
|
|
268
287
|
const tx = await this.submitRewardDistributionTransaction(stepRewardAddress, addressDistributions, stepIdentity, this.gateway);
|
|
269
288
|
this.logger?.info(`Claimed rewards for step ${stepIdentity.step} at block ${stepIdentity.block}`);
|
|
@@ -295,20 +314,131 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
295
314
|
}
|
|
296
315
|
};
|
|
297
316
|
|
|
317
|
+
// src/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.ts
|
|
318
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
319
|
+
import { AddressZod, EthAddressZod, hexToBigInt, HexZod, toAddress as toAddress2, toHex } from "@xylabs/hex";
|
|
320
|
+
import { isDefined as isDefined3, isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
321
|
+
import { createTransferPayload as createTransferPayload2 } from "@xyo-network/chain-protocol";
|
|
322
|
+
import { AbstractSentinel as AbstractSentinel2 } from "@xyo-network/sentinel-abstract";
|
|
323
|
+
import { derivedReceiveAddress as derivedReceiveAddress2, flattenHydratedTransaction as flattenHydratedTransaction2, isEIP712DataPayload, isEIP712SignaturePayload, verifyEIP712Message } from "@xyo-network/xl1-protocol-sdk";
|
|
324
|
+
import z from "zod";
|
|
325
|
+
var DerivedAddressWalletTransferSentinelConfigSchema = "network.xyo.sentinel.chain.derived.address.wallet.transfer.config";
|
|
326
|
+
var scope2 = "reward-escrow";
|
|
327
|
+
var ConfirmedClaimValuesZod = z.object({
|
|
328
|
+
"From": EthAddressZod,
|
|
329
|
+
"To XL1 Address": AddressZod,
|
|
330
|
+
"XL1 Amount": z.string(),
|
|
331
|
+
"XL1 Amount (Hex)": HexZod,
|
|
332
|
+
"XL1 Not after block": z.number().int().nonnegative(),
|
|
333
|
+
"XL1 Not before block": z.number().int().nonnegative()
|
|
334
|
+
});
|
|
335
|
+
var parseConfirmedClaimValues = /* @__PURE__ */ __name((values) => {
|
|
336
|
+
return {
|
|
337
|
+
amount: values["XL1 Amount (Hex)"],
|
|
338
|
+
exp: values["XL1 Not after block"],
|
|
339
|
+
from: toAddress2(values.From),
|
|
340
|
+
nbf: values["XL1 Not before block"],
|
|
341
|
+
to: toAddress2(values["To XL1 Address"])
|
|
342
|
+
};
|
|
343
|
+
}, "parseConfirmedClaimValues");
|
|
344
|
+
var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
|
|
345
|
+
static {
|
|
346
|
+
__name(this, "DerivedAddressWalletTransferSentinel");
|
|
347
|
+
}
|
|
348
|
+
static configSchemas = [
|
|
349
|
+
DerivedAddressWalletTransferSentinelConfigSchema
|
|
350
|
+
];
|
|
351
|
+
static defaultConfigSchema = DerivedAddressWalletTransferSentinelConfigSchema;
|
|
352
|
+
_transferAttemptsCounter;
|
|
353
|
+
_transferErrorCounter;
|
|
354
|
+
_transferSuccessCounter;
|
|
355
|
+
get gateway() {
|
|
356
|
+
return this.params.gateway;
|
|
357
|
+
}
|
|
358
|
+
async createHandler() {
|
|
359
|
+
await super.createHandler();
|
|
360
|
+
this._transferAttemptsCounter = this.meter?.createCounter("derived_address_wallet_transfer_sentinel_attempts_total", {
|
|
361
|
+
description: "Number of transfer attempts"
|
|
362
|
+
});
|
|
363
|
+
this._transferSuccessCounter = this.meter?.createCounter("derived_address_wallet_transfer_sentinel_success_total", {
|
|
364
|
+
description: "Number of transfer successes"
|
|
365
|
+
});
|
|
366
|
+
this._transferErrorCounter = this.meter?.createCounter("derived_address_wallet_transfer_sentinel_errors_total", {
|
|
367
|
+
description: "Number of transfer errors"
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
async reportHandler(payloads) {
|
|
371
|
+
const data = payloads?.find(isEIP712DataPayload);
|
|
372
|
+
const signature = payloads?.find(isEIP712SignaturePayload);
|
|
373
|
+
if (isUndefined2(data) || isUndefined2(signature)) return [];
|
|
374
|
+
this._transferAttemptsCounter?.add(1);
|
|
375
|
+
const valid = await verifyEIP712Message(data, signature);
|
|
376
|
+
if (!valid) {
|
|
377
|
+
this._transferErrorCounter?.add(1);
|
|
378
|
+
throw new Error("Invalid EIP712 signature");
|
|
379
|
+
}
|
|
380
|
+
const values = data.values;
|
|
381
|
+
const parsed = parseConfirmedClaimValues(values);
|
|
382
|
+
const signatureAddress = toAddress2(signature.address);
|
|
383
|
+
const parsedAddress = toAddress2(parsed.from);
|
|
384
|
+
if (signatureAddress === parsedAddress) {
|
|
385
|
+
const tx = await this.submitRewardDistributionTransaction(parsed);
|
|
386
|
+
if (isDefined3(tx)) {
|
|
387
|
+
this._transferSuccessCounter?.add(1);
|
|
388
|
+
return flattenHydratedTransaction2(tx);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
this._transferErrorCounter?.add(1);
|
|
392
|
+
return [];
|
|
393
|
+
}
|
|
394
|
+
submitRewardDistributionTransaction = /* @__PURE__ */ __name(async (claimValues) => {
|
|
395
|
+
const { amount, from: address, to, nbf, exp } = claimValues;
|
|
396
|
+
const signer = assertEx2(await this.gateway.signer(), () => "Signer is not defined in gateway");
|
|
397
|
+
const signerAddress = await signer.address();
|
|
398
|
+
const connection = await this.gateway.connection();
|
|
399
|
+
const viewer2 = assertEx2(connection.viewer, () => "Viewer is not defined in gateway connection");
|
|
400
|
+
const chainId = await viewer2.chainId();
|
|
401
|
+
const currentBlock = await viewer2.currentBlockNumber();
|
|
402
|
+
if (currentBlock < nbf || currentBlock > exp) throw new Error("Transaction is not within a valid block range");
|
|
403
|
+
const escrowAccount = derivedReceiveAddress2(address, scope2);
|
|
404
|
+
const balance = await viewer2.accountBalance(escrowAccount);
|
|
405
|
+
const redemptionAmount = hexToBigInt(toHex(amount));
|
|
406
|
+
assertEx2(balance === redemptionAmount, () => "Insufficient balance in escrow account");
|
|
407
|
+
const allowance = await viewer2.accountBalance(signerAddress);
|
|
408
|
+
assertEx2(allowance > 1000n, () => "Insufficient allowance to transfer from escrow account");
|
|
409
|
+
const transferPayload = createTransferPayload2(escrowAccount, {
|
|
410
|
+
[to]: hexToBigInt(toHex(amount))
|
|
411
|
+
});
|
|
412
|
+
transferPayload.context = {
|
|
413
|
+
address,
|
|
414
|
+
scope: scope2
|
|
415
|
+
};
|
|
416
|
+
const chain = await viewer2.chainId();
|
|
417
|
+
const result = await this.gateway.addPayloadsToChain?.([
|
|
418
|
+
transferPayload
|
|
419
|
+
], [], {
|
|
420
|
+
chain,
|
|
421
|
+
nbf,
|
|
422
|
+
exp
|
|
423
|
+
});
|
|
424
|
+
if (isDefined3(result)) return result[1];
|
|
425
|
+
}, "submitRewardDistributionTransaction");
|
|
426
|
+
};
|
|
427
|
+
|
|
298
428
|
// src/server/routes/rewardRedemption/middleware/requestHandlerValidator.ts
|
|
299
|
-
import { isDefined as
|
|
429
|
+
import { isDefined as isDefined4, isPromise } from "@xylabs/typeof";
|
|
300
430
|
import { ReasonPhrases, StatusCodes } from "http-status-codes";
|
|
301
|
-
import { z } from "zod";
|
|
302
|
-
var EmptyParamsZod =
|
|
303
|
-
var EmptyQueryParamsZod =
|
|
304
|
-
|
|
305
|
-
|
|
431
|
+
import { z as z2 } from "zod";
|
|
432
|
+
var EmptyParamsZod = z2.object({}).catchall(z2.string());
|
|
433
|
+
var EmptyQueryParamsZod = z2.object({}).catchall(z2.union([
|
|
434
|
+
z2.string(),
|
|
435
|
+
z2.array(z2.string())
|
|
306
436
|
]));
|
|
307
437
|
var ValidateRequestDefaults = {
|
|
308
438
|
params: EmptyParamsZod,
|
|
309
439
|
query: EmptyQueryParamsZod,
|
|
310
|
-
body:
|
|
311
|
-
response:
|
|
440
|
+
body: z2.json().optional(),
|
|
441
|
+
response: z2.json().optional()
|
|
312
442
|
};
|
|
313
443
|
function requestHandlerValidator(schemas) {
|
|
314
444
|
const validators = {
|
|
@@ -329,7 +459,7 @@ function requestHandlerValidator(schemas) {
|
|
|
329
459
|
const validator = validators[key];
|
|
330
460
|
const result2 = validator.safeParse(req[key]);
|
|
331
461
|
if (result2.success) {
|
|
332
|
-
if (
|
|
462
|
+
if (isDefined4(result2.data)) Object.assign(req[key], result2.data);
|
|
333
463
|
} else {
|
|
334
464
|
errors.push(...result2.error.issues.map((issue) => issue.path.length === 0 ? `${key}: ${issue.message}` : `${key}.${issue.path.join(".")}: ${issue.message}`));
|
|
335
465
|
}
|
|
@@ -369,11 +499,11 @@ function requestHandlerValidator(schemas) {
|
|
|
369
499
|
__name(requestHandlerValidator, "requestHandlerValidator");
|
|
370
500
|
|
|
371
501
|
// src/server/routes/rewardRedemption/routeDefinitions/util/getViewerFromConfig.ts
|
|
372
|
-
import { isDefined as
|
|
502
|
+
import { isDefined as isDefined5 } from "@xylabs/typeof";
|
|
373
503
|
import { HttpRpcTransport, JsonRpcXyoViewer, XyoViewerRpcSchemas } from "@xyo-network/xl1-rpc";
|
|
374
504
|
var viewer;
|
|
375
505
|
var getViewerFromConfig = /* @__PURE__ */ __name((config) => {
|
|
376
|
-
if (
|
|
506
|
+
if (isDefined5(viewer)) return viewer;
|
|
377
507
|
const transport = new HttpRpcTransport(config.rewardRedemptionApi.chainRpcApiUrl, XyoViewerRpcSchemas);
|
|
378
508
|
viewer = new JsonRpcXyoViewer(transport);
|
|
379
509
|
return viewer;
|
|
@@ -390,12 +520,12 @@ var RewardableSteps2 = [
|
|
|
390
520
|
];
|
|
391
521
|
|
|
392
522
|
// src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
|
|
393
|
-
var query =
|
|
394
|
-
fromBlock:
|
|
395
|
-
toBlock:
|
|
396
|
-
step:
|
|
523
|
+
var query = z3.object({
|
|
524
|
+
fromBlock: z3.coerce.number().int().nonnegative().optional(),
|
|
525
|
+
toBlock: z3.coerce.number().int().nonnegative().optional(),
|
|
526
|
+
step: z3.coerce.number().int().nonnegative().min(Math.min(...RewardableSteps2)).max(Math.max(...RewardableSteps2)).optional().default(3)
|
|
397
527
|
});
|
|
398
|
-
var response =
|
|
528
|
+
var response = z3.array(PayloadZodLoose);
|
|
399
529
|
var validateRequest = requestHandlerValidator({
|
|
400
530
|
query,
|
|
401
531
|
response
|
|
@@ -403,18 +533,18 @@ var validateRequest = requestHandlerValidator({
|
|
|
403
533
|
var getChainStepRewardsClaimSentinel = /* @__PURE__ */ __name(async (node) => {
|
|
404
534
|
const mod = await node.resolve("XYORewardRedemptionNode:ChainStepRewardsClaimSentinel");
|
|
405
535
|
const sentinel = asSentinelInstance(mod);
|
|
406
|
-
return
|
|
536
|
+
return assertEx3(sentinel, () => "ChainStepRewardsClaimSentinel not found on node");
|
|
407
537
|
}, "getChainStepRewardsClaimSentinel");
|
|
408
538
|
var postClaimRange = {
|
|
409
539
|
method: "post",
|
|
410
540
|
path: "/rewards/claimRange",
|
|
411
541
|
handlers: validateRequest(async (req, res) => {
|
|
412
542
|
const { config, node } = req.app;
|
|
413
|
-
const { fromBlock, toBlock, step } =
|
|
543
|
+
const { fromBlock, toBlock, step } = z3.parse(query, req.query);
|
|
414
544
|
const viewer2 = getViewerFromConfig(config);
|
|
415
|
-
const from =
|
|
545
|
+
const from = isDefined6(fromBlock) ? fromBlock : 0;
|
|
416
546
|
const currentBlock = await viewer2.currentBlockNumber();
|
|
417
|
-
const to =
|
|
547
|
+
const to = isDefined6(toBlock) ? Math.min(toBlock, currentBlock) : currentBlock;
|
|
418
548
|
if (to <= from) {
|
|
419
549
|
res.status(400);
|
|
420
550
|
res.json([]);
|
|
@@ -444,12 +574,16 @@ var postClaimRange = {
|
|
|
444
574
|
};
|
|
445
575
|
|
|
446
576
|
// src/server/routes/rewardRedemption/routeDefinitions/routes/redeem.ts
|
|
447
|
-
import { assertEx as
|
|
448
|
-
import { PayloadZodLoose as PayloadZodLoose2 } from "@xyo-network/payload-model";
|
|
577
|
+
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
578
|
+
import { PayloadZodLoose as PayloadZodLoose2, PayloadZodStrictOfSchema } from "@xyo-network/payload-model";
|
|
449
579
|
import { asSentinelInstance as asSentinelInstance2 } from "@xyo-network/sentinel-model";
|
|
450
|
-
import {
|
|
451
|
-
|
|
452
|
-
var
|
|
580
|
+
import { EIP712DataPayloadFieldsZod, EIP712DataPayloadSchema, EIP712SignaturePayloadFieldsZod, EIP712SignaturePayloadSchema } from "@xyo-network/xl1-protocol-sdk";
|
|
581
|
+
import { z as z4 } from "zod";
|
|
582
|
+
var body = z4.tuple([
|
|
583
|
+
PayloadZodStrictOfSchema(EIP712DataPayloadSchema).extend(EIP712DataPayloadFieldsZod.shape),
|
|
584
|
+
PayloadZodStrictOfSchema(EIP712SignaturePayloadSchema).extend(EIP712SignaturePayloadFieldsZod.shape)
|
|
585
|
+
]);
|
|
586
|
+
var response2 = z4.array(PayloadZodLoose2);
|
|
453
587
|
var validateRequest2 = requestHandlerValidator({
|
|
454
588
|
body,
|
|
455
589
|
response: response2
|
|
@@ -457,7 +591,7 @@ var validateRequest2 = requestHandlerValidator({
|
|
|
457
591
|
var getDerivedAddressWalletTransferSentinel = /* @__PURE__ */ __name(async (node) => {
|
|
458
592
|
const mod = await node.resolve("XYORewardRedemptionNode:DerivedAddressWalletTransferSentinel");
|
|
459
593
|
const sentinel = asSentinelInstance2(mod);
|
|
460
|
-
return
|
|
594
|
+
return assertEx4(sentinel, () => "DerivedAddressWalletTransferSentinel not found on node");
|
|
461
595
|
}, "getDerivedAddressWalletTransferSentinel");
|
|
462
596
|
var postRedeem = {
|
|
463
597
|
method: "post",
|
|
@@ -465,9 +599,8 @@ var postRedeem = {
|
|
|
465
599
|
handlers: validateRequest2(async (req, res) => {
|
|
466
600
|
const { node } = req.app;
|
|
467
601
|
const { body: body2 } = req;
|
|
468
|
-
const input = body2;
|
|
469
602
|
const sentinel = await getDerivedAddressWalletTransferSentinel(node);
|
|
470
|
-
const result = await sentinel.report(
|
|
603
|
+
const result = await sentinel.report(body2);
|
|
471
604
|
res.status(200);
|
|
472
605
|
res.json(result);
|
|
473
606
|
})
|
|
@@ -518,13 +651,13 @@ var getApp = /* @__PURE__ */ __name((node, config) => {
|
|
|
518
651
|
}, "getApp");
|
|
519
652
|
|
|
520
653
|
// src/server/server.ts
|
|
521
|
-
import { assertEx as
|
|
522
|
-
import { isDefined as
|
|
654
|
+
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
655
|
+
import { isDefined as isDefined8, isString } from "@xylabs/typeof";
|
|
523
656
|
import { boot } from "@xyo-network/bios";
|
|
524
657
|
import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
|
|
525
658
|
|
|
526
659
|
// src/manifest/getLocator.ts
|
|
527
|
-
import { isDefined as
|
|
660
|
+
import { isDefined as isDefined7 } from "@xylabs/typeof";
|
|
528
661
|
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
529
662
|
import { MongoDBArchivistV2 } from "@xyo-network/archivist-mongodb";
|
|
530
663
|
import { ViewArchivist } from "@xyo-network/archivist-view";
|
|
@@ -549,7 +682,7 @@ var getLocator = /* @__PURE__ */ __name(async (context) => {
|
|
|
549
682
|
port: 9465
|
|
550
683
|
}
|
|
551
684
|
});
|
|
552
|
-
if (
|
|
685
|
+
if (isDefined7(logger)) AbstractModule.defaultLogger = logger;
|
|
553
686
|
const statusReporter = logger ? new LoggerModuleStatusReporter(logger) : void 0;
|
|
554
687
|
const locator = new ModuleFactoryLocator();
|
|
555
688
|
const mongoConfig = config.storage?.mongo;
|
|
@@ -585,12 +718,26 @@ var getLocator = /* @__PURE__ */ __name(async (context) => {
|
|
|
585
718
|
meterProvider,
|
|
586
719
|
statusReporter
|
|
587
720
|
}));
|
|
588
|
-
await
|
|
721
|
+
const gateway = await getGateway(config);
|
|
722
|
+
const chainStepRewardsClaimSentinelParams = {
|
|
723
|
+
gateway,
|
|
724
|
+
traceProvider,
|
|
725
|
+
meterProvider,
|
|
726
|
+
statusReporter
|
|
727
|
+
};
|
|
728
|
+
locator.register(ChainStepRewardsClaimSentinel.factory(chainStepRewardsClaimSentinelParams));
|
|
729
|
+
const derivedAddressWalletTransferSentinelParams = {
|
|
730
|
+
gateway,
|
|
731
|
+
traceProvider,
|
|
732
|
+
meterProvider,
|
|
733
|
+
statusReporter
|
|
734
|
+
};
|
|
735
|
+
locator.register(DerivedAddressWalletTransferSentinel.factory(derivedAddressWalletTransferSentinelParams));
|
|
589
736
|
return locator;
|
|
590
737
|
}, "getLocator");
|
|
591
|
-
var
|
|
738
|
+
var getGateway = /* @__PURE__ */ __name(async (config) => {
|
|
592
739
|
const { mnemonic, chainRpcApiUrl: endpoint } = config.rewardRedemptionApi;
|
|
593
|
-
const walletPromise =
|
|
740
|
+
const walletPromise = isDefined7(mnemonic) ? HDWallet.fromPhrase(mnemonic) : HDWallet.random();
|
|
594
741
|
const account = await walletPromise;
|
|
595
742
|
const signer = new MemoryXyoSigner(account);
|
|
596
743
|
const connection = new HttpRpcXyoConnection({
|
|
@@ -598,14 +745,8 @@ var registerChainRewardsClaimSentinel = /* @__PURE__ */ __name(async (locator, c
|
|
|
598
745
|
account
|
|
599
746
|
});
|
|
600
747
|
const gateway = new MemoryXyoGateway(signer, connection);
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
traceProvider,
|
|
604
|
-
meterProvider,
|
|
605
|
-
statusReporter
|
|
606
|
-
};
|
|
607
|
-
locator.register(ChainStepRewardsClaimSentinel.factory(chainStepRewardsClaimSentinelParams));
|
|
608
|
-
}, "registerChainRewardsClaimSentinel");
|
|
748
|
+
return gateway;
|
|
749
|
+
}, "getGateway");
|
|
609
750
|
|
|
610
751
|
// src/manifest/getNode.ts
|
|
611
752
|
import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
|
|
@@ -645,24 +786,9 @@ var node_default = {
|
|
|
645
786
|
},
|
|
646
787
|
{
|
|
647
788
|
config: {
|
|
648
|
-
accountPath: "1/1'/
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
frequency: 6e4,
|
|
652
|
-
frequencyUnits: "millis",
|
|
653
|
-
schema: "network.xyo.automation.interval",
|
|
654
|
-
type: "interval"
|
|
655
|
-
}
|
|
656
|
-
],
|
|
657
|
-
name: "ChainRewardsClaimIntervalSentinel",
|
|
658
|
-
schema: "network.xyo.sentinel.config",
|
|
659
|
-
synchronous: true,
|
|
660
|
-
tasks: [
|
|
661
|
-
{
|
|
662
|
-
mod: "ChainStepRewardsClaimSentinel",
|
|
663
|
-
endPoint: "report"
|
|
664
|
-
}
|
|
665
|
-
]
|
|
789
|
+
accountPath: "1/1'/4'",
|
|
790
|
+
name: "DerivedAddressWalletTransferSentinel",
|
|
791
|
+
schema: "network.xyo.sentinel.chain.derived.address.wallet.transfer.config"
|
|
666
792
|
}
|
|
667
793
|
}
|
|
668
794
|
],
|
|
@@ -732,13 +858,13 @@ var getSeedPhrase = /* @__PURE__ */ __name(async (bios, config, logger) => {
|
|
|
732
858
|
}
|
|
733
859
|
await bios.seedPhraseStore.set("os", seedPhrase);
|
|
734
860
|
}
|
|
735
|
-
return
|
|
861
|
+
return assertEx5(await bios.seedPhraseStore.get("os"), () => "Unable to acquire mnemonic from bios");
|
|
736
862
|
}, "getSeedPhrase");
|
|
737
863
|
var getServer = /* @__PURE__ */ __name(async (context) => {
|
|
738
864
|
const { logger, config } = context;
|
|
739
865
|
const { port, mnemonic } = config.rewardRedemptionApi;
|
|
740
866
|
const bios = await boot();
|
|
741
|
-
const seedPhrase =
|
|
867
|
+
const seedPhrase = isDefined8(mnemonic) ? mnemonic : await getSeedPhrase(bios, config, logger);
|
|
742
868
|
const wallet = await HDWallet2.fromPhrase(seedPhrase);
|
|
743
869
|
const nodeContext = {
|
|
744
870
|
wallet,
|