@xyo-network/chain-reward-redemption 1.16.9 → 1.16.11
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 +224 -234
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/manifest/getLocator.d.ts +1 -1
- package/dist/node/manifest/getLocator.d.ts.map +1 -1
- package/dist/node/manifest/getNode.d.ts +1 -1
- package/dist/node/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.d.ts +2 -2
- package/dist/node/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.d.ts.map +1 -1
- package/dist/node/modules/ChainStepRewardsClaimSentinel/index.d.ts +0 -1
- package/dist/node/modules/ChainStepRewardsClaimSentinel/index.d.ts.map +1 -1
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.d.ts +5 -9
- package/dist/node/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.d.ts.map +1 -1
- package/dist/node/server/routes/address/get/get.d.ts.map +1 -1
- package/dist/node/server/routes/dataLake/archivistMiddleware.d.ts.map +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/pathParams/AddressPathParam.d.ts +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/pathParams/AddressPathParam.d.ts.map +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.d.ts.map +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/routes/redeem.d.ts.map +1 -1
- package/dist/node/server/routes/rewardRedemption/routeDefinitions/util/getAccountFromConfig.d.ts.map +1 -1
- package/dist/node/server/server.d.ts +1 -1
- package/dist/node/server/server.d.ts.map +1 -1
- package/package.json +46 -54
- package/src/manifest/getLocator.ts +8 -6
- package/src/manifest/getNode.ts +1 -1
- package/src/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts +11 -14
- package/src/modules/ChainStepRewardsClaimSentinel/index.ts +0 -1
- package/src/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.ts +6 -7
- package/src/modules/DerivedAddressWalletTransferSentinel/spec/DerivedAddressWalletTransferSentinel.spec.ts +9 -6
- package/src/modules/helper/retry.ts +1 -1
- package/src/server/routes/address/get/get.ts +1 -2
- package/src/server/routes/address/post/post.ts +4 -4
- package/src/server/routes/dataLake/archivistMiddleware.ts +1 -2
- package/src/server/routes/rewardRedemption/routeDefinitions/pathParams/AddressPathParam.ts +1 -1
- package/src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts +3 -5
- package/src/server/routes/rewardRedemption/routeDefinitions/routes/redeem.ts +1 -1
- package/src/server/routes/rewardRedemption/routeDefinitions/util/getAccountFromConfig.ts +1 -2
- package/src/server/routes/rewardRedemption/routeDefinitions/util/getViewerFromConfig.ts +1 -1
- package/src/server/server.ts +4 -3
- package/dist/node/modules/ChainStepRewardsClaimSentinel/StepIdentityPayload.d.ts +0 -6
- package/dist/node/modules/ChainStepRewardsClaimSentinel/StepIdentityPayload.d.ts.map +0 -1
- package/src/modules/ChainStepRewardsClaimSentinel/StepIdentityPayload.ts +0 -11
package/dist/node/index.mjs
CHANGED
|
@@ -23,8 +23,7 @@ var addInstrumentation = /* @__PURE__ */ __name(() => {
|
|
|
23
23
|
|
|
24
24
|
// src/server/routes/dataLake/archivistMiddleware.ts
|
|
25
25
|
import { setRawResponseFormat } from "@xylabs/express";
|
|
26
|
-
import { asHash } from "@xylabs/
|
|
27
|
-
import { isDefined } from "@xylabs/typeof";
|
|
26
|
+
import { asHash, isDefined } from "@xylabs/sdk-js";
|
|
28
27
|
import { asArchivistInstance } from "@xyo-network/archivist-model";
|
|
29
28
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
30
29
|
import { isAnyPayload, isSequence } from "@xyo-network/payload-model";
|
|
@@ -115,40 +114,203 @@ var addDataLakeRoutes = /* @__PURE__ */ __name((app) => {
|
|
|
115
114
|
import { addRouteDefinitions } from "@xylabs/express";
|
|
116
115
|
|
|
117
116
|
// src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
|
|
118
|
-
import { assertEx as assertEx3 } from "@xylabs/assert";
|
|
119
117
|
import { requestHandlerValidator } from "@xylabs/express";
|
|
120
|
-
import { isDefined as
|
|
121
|
-
import { blockRangeSteps
|
|
118
|
+
import { assertEx, isDefined as isDefined3 } from "@xylabs/sdk-js";
|
|
119
|
+
import { blockRangeSteps } from "@xyo-network/chain-protocol";
|
|
122
120
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/payload-builder";
|
|
123
121
|
import { PayloadZodLoose } from "@xyo-network/payload-model";
|
|
124
122
|
import { asSentinelInstance } from "@xyo-network/sentinel-model";
|
|
125
|
-
import { asXL1BlockRange
|
|
123
|
+
import { asXL1BlockRange, StepIdentitySchema } from "@xyo-network/xl1-protocol";
|
|
124
|
+
import { z } from "zod";
|
|
125
|
+
|
|
126
|
+
// src/server/routes/rewardRedemption/routeDefinitions/util/getViewerFromConfig.ts
|
|
127
|
+
import { isDefined as isDefined2 } from "@xylabs/sdk-js";
|
|
128
|
+
import { HttpRpcTransport, JsonRpcNetworkStakeViewer, JsonRpcXyoViewer, NetworkStakeViewerRpcSchemas, XyoViewerRpcSchemas } from "@xyo-network/xl1-rpc";
|
|
129
|
+
var viewer;
|
|
130
|
+
var getViewerFromConfig = /* @__PURE__ */ __name((config) => {
|
|
131
|
+
if (isDefined2(viewer)) return viewer;
|
|
132
|
+
const transport = new HttpRpcTransport(config.rewardRedemptionApi.chainRpcApiUrl, {
|
|
133
|
+
...XyoViewerRpcSchemas,
|
|
134
|
+
...NetworkStakeViewerRpcSchemas
|
|
135
|
+
});
|
|
136
|
+
const networkStakeViewer = new JsonRpcNetworkStakeViewer(transport);
|
|
137
|
+
viewer = new JsonRpcXyoViewer(transport, {
|
|
138
|
+
networkStakeViewer
|
|
139
|
+
});
|
|
140
|
+
return viewer;
|
|
141
|
+
}, "getViewerFromConfig");
|
|
142
|
+
|
|
143
|
+
// src/server/routes/rewardRedemption/routeDefinitions/util/rewardableSteps.ts
|
|
144
|
+
var RewardableSteps = [
|
|
145
|
+
3,
|
|
146
|
+
4,
|
|
147
|
+
5,
|
|
148
|
+
6,
|
|
149
|
+
7,
|
|
150
|
+
8
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
// src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
|
|
154
|
+
var query = z.object({
|
|
155
|
+
fromBlock: z.coerce.number().int().nonnegative().optional(),
|
|
156
|
+
toBlock: z.coerce.number().int().nonnegative().optional(),
|
|
157
|
+
step: z.coerce.number().int().nonnegative().min(Math.min(...RewardableSteps)).max(Math.max(...RewardableSteps)).optional().default(3)
|
|
158
|
+
});
|
|
159
|
+
var response = z.array(PayloadZodLoose);
|
|
160
|
+
var validateRequest = requestHandlerValidator({
|
|
161
|
+
query,
|
|
162
|
+
response
|
|
163
|
+
});
|
|
164
|
+
var getChainStepRewardsClaimSentinel = /* @__PURE__ */ __name(async (node) => {
|
|
165
|
+
const mod = await node.resolve("XYORewardRedemptionNode:ChainStepRewardsClaimSentinel");
|
|
166
|
+
const sentinel = asSentinelInstance(mod);
|
|
167
|
+
return assertEx(sentinel, () => "ChainStepRewardsClaimSentinel not found on node");
|
|
168
|
+
}, "getChainStepRewardsClaimSentinel");
|
|
169
|
+
var postClaimRange = {
|
|
170
|
+
method: "post",
|
|
171
|
+
path: "/rewards/claimRange",
|
|
172
|
+
handlers: validateRequest(async (req, res) => {
|
|
173
|
+
const { config, node } = req.app;
|
|
174
|
+
const { fromBlock, toBlock, step } = z.parse(query, req.query);
|
|
175
|
+
const viewer2 = getViewerFromConfig(config);
|
|
176
|
+
const from = isDefined3(fromBlock) ? fromBlock : 0;
|
|
177
|
+
const currentBlock = await viewer2.currentBlockNumber();
|
|
178
|
+
const to = isDefined3(toBlock) ? Math.min(toBlock, currentBlock) : currentBlock;
|
|
179
|
+
if (to <= from) {
|
|
180
|
+
res.status(400);
|
|
181
|
+
res.json([]);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const range = asXL1BlockRange([
|
|
185
|
+
from,
|
|
186
|
+
to
|
|
187
|
+
], {
|
|
188
|
+
name: "claimRange"
|
|
189
|
+
});
|
|
190
|
+
const stepIdentities = blockRangeSteps(range, [
|
|
191
|
+
step
|
|
192
|
+
]);
|
|
193
|
+
const results = [];
|
|
194
|
+
for (const stepIdentity of stepIdentities) {
|
|
195
|
+
const mod = await getChainStepRewardsClaimSentinel(node);
|
|
196
|
+
const stepIdentityPayload = new PayloadBuilder2({
|
|
197
|
+
schema: StepIdentitySchema
|
|
198
|
+
}).fields(stepIdentity).build();
|
|
199
|
+
const result = await mod.report([
|
|
200
|
+
stepIdentityPayload
|
|
201
|
+
]);
|
|
202
|
+
results.push(...result);
|
|
203
|
+
}
|
|
204
|
+
res.status(200);
|
|
205
|
+
res.json(results);
|
|
206
|
+
})
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/server/routes/rewardRedemption/routeDefinitions/routes/redeem.ts
|
|
210
|
+
import { requestHandlerValidator as requestHandlerValidator2 } from "@xylabs/express";
|
|
211
|
+
import { assertEx as assertEx2 } from "@xylabs/sdk-js";
|
|
212
|
+
import { PayloadZodLoose as PayloadZodLoose2, PayloadZodStrictOfSchema } from "@xyo-network/payload-model";
|
|
213
|
+
import { asSentinelInstance as asSentinelInstance2 } from "@xyo-network/sentinel-model";
|
|
214
|
+
import { EIP712DataPayloadFieldsZod, EIP712DataPayloadSchema, EIP712SignaturePayloadFieldsZod, EIP712SignaturePayloadSchema } from "@xyo-network/xl1-protocol-sdk";
|
|
126
215
|
import { z as z2 } from "zod";
|
|
216
|
+
var body = z2.tuple([
|
|
217
|
+
PayloadZodStrictOfSchema(EIP712DataPayloadSchema).extend(EIP712DataPayloadFieldsZod.shape),
|
|
218
|
+
PayloadZodStrictOfSchema(EIP712SignaturePayloadSchema).extend(EIP712SignaturePayloadFieldsZod.shape)
|
|
219
|
+
]);
|
|
220
|
+
var response2 = z2.array(PayloadZodLoose2);
|
|
221
|
+
var validateRequest2 = requestHandlerValidator2({
|
|
222
|
+
body,
|
|
223
|
+
response: response2
|
|
224
|
+
});
|
|
225
|
+
var getDerivedAddressWalletTransferSentinel = /* @__PURE__ */ __name(async (node) => {
|
|
226
|
+
const mod = await node.resolve("XYORewardRedemptionNode:DerivedAddressWalletTransferSentinel");
|
|
227
|
+
const sentinel = asSentinelInstance2(mod);
|
|
228
|
+
return assertEx2(sentinel, () => "DerivedAddressWalletTransferSentinel not found on node");
|
|
229
|
+
}, "getDerivedAddressWalletTransferSentinel");
|
|
230
|
+
var postRedeem = {
|
|
231
|
+
method: "post",
|
|
232
|
+
path: "/rewards/redeem",
|
|
233
|
+
handlers: validateRequest2(async (req, res) => {
|
|
234
|
+
const { node } = req.app;
|
|
235
|
+
const { body: body2 } = req;
|
|
236
|
+
const sentinel = await getDerivedAddressWalletTransferSentinel(node);
|
|
237
|
+
const result = await sentinel.report(body2);
|
|
238
|
+
res.status(200);
|
|
239
|
+
res.json(result);
|
|
240
|
+
})
|
|
241
|
+
};
|
|
127
242
|
|
|
128
|
-
// src/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
import { asXL1BlockNumber, asXL1BlockRange, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
136
|
-
import { completedStepRewardAddress, derivedReceiveAddress, flattenHydratedTransaction, flattenHydratedTransactions, SimpleXyoGatewayRunner } from "@xyo-network/xl1-protocol-sdk";
|
|
137
|
-
import { Mutex } from "async-mutex";
|
|
243
|
+
// src/server/routes/rewardRedemption/routeDefinitions/getRouteDefinitions.ts
|
|
244
|
+
var getRouteDefinitions = /* @__PURE__ */ __name(() => {
|
|
245
|
+
return [
|
|
246
|
+
postClaimRange,
|
|
247
|
+
postRedeem
|
|
248
|
+
];
|
|
249
|
+
}, "getRouteDefinitions");
|
|
138
250
|
|
|
139
|
-
// src/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
251
|
+
// src/server/routes/rewardRedemption/addRewardRoutes.ts
|
|
252
|
+
var addRewardRedemptionRoutes = /* @__PURE__ */ __name((app) => {
|
|
253
|
+
const routeDefinitions = getRouteDefinitions();
|
|
254
|
+
addRouteDefinitions(app, routeDefinitions);
|
|
255
|
+
}, "addRewardRedemptionRoutes");
|
|
256
|
+
|
|
257
|
+
// src/server/routes/addRoutes.ts
|
|
258
|
+
var addRoutes = /* @__PURE__ */ __name((app) => {
|
|
259
|
+
addDataLakeRoutes(app);
|
|
260
|
+
addRewardRedemptionRoutes(app);
|
|
261
|
+
}, "addRoutes");
|
|
262
|
+
|
|
263
|
+
// src/server/app.ts
|
|
264
|
+
var getApp = /* @__PURE__ */ __name((node, config) => {
|
|
265
|
+
addInstrumentation();
|
|
266
|
+
const app = express2();
|
|
267
|
+
app.set("etag", false);
|
|
268
|
+
app.use(cors());
|
|
269
|
+
app.use(compression());
|
|
270
|
+
app.use(responseProfiler);
|
|
271
|
+
app.use(getJsonBodyParser(getJsonBodyParserOptions({
|
|
272
|
+
limit: "1mb"
|
|
273
|
+
})));
|
|
274
|
+
app.use(standardResponses);
|
|
275
|
+
disableExpressDefaultPoweredByHeader(app);
|
|
276
|
+
app.use(customPoweredByHeader);
|
|
277
|
+
disableCaseSensitiveRouting(app);
|
|
278
|
+
app.config = config;
|
|
279
|
+
app.node = node;
|
|
280
|
+
addRoutes(app);
|
|
281
|
+
app.use(standardErrors);
|
|
282
|
+
return app;
|
|
283
|
+
}, "getApp");
|
|
284
|
+
|
|
285
|
+
// src/server/server.ts
|
|
286
|
+
import { assertEx as assertEx5, isDefined as isDefined7, isString } from "@xylabs/sdk-js";
|
|
287
|
+
import { boot } from "@xyo-network/bios";
|
|
288
|
+
import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
|
|
289
|
+
|
|
290
|
+
// src/manifest/getLocator.ts
|
|
291
|
+
import { isDefined as isDefined6 } from "@xylabs/sdk-js";
|
|
292
|
+
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
293
|
+
import { MongoDBArchivistV2 } from "@xyo-network/archivist-mongodb";
|
|
294
|
+
import { ViewArchivist } from "@xyo-network/archivist-view";
|
|
295
|
+
import { initTelemetry } from "@xyo-network/chain-telemetry";
|
|
296
|
+
import { AbstractModule, LoggerModuleStatusReporter } from "@xyo-network/module-abstract";
|
|
297
|
+
import { ModuleFactoryLocator } from "@xyo-network/module-factory-locator";
|
|
298
|
+
import { MemorySentinel } from "@xyo-network/sentinel-memory";
|
|
299
|
+
import { HDWallet } from "@xyo-network/wallet";
|
|
300
|
+
import { hasMongoConfig, SimpleXyoGatewayRunner, SimpleXyoSigner } from "@xyo-network/xl1-protocol-sdk";
|
|
301
|
+
import { HttpRpcXyoConnection } from "@xyo-network/xl1-rpc";
|
|
146
302
|
|
|
147
303
|
// src/modules/ChainStepRewardsClaimSentinel/ChainStepRewardsClaimSentinel.ts
|
|
304
|
+
import { assertEx as assertEx3, delay, isDefined as isDefined4, isUndefined, toAddress } from "@xylabs/sdk-js";
|
|
305
|
+
import { blockRangeSteps as blockRangeSteps2, createTransferPayload } from "@xyo-network/chain-protocol";
|
|
306
|
+
import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
|
|
307
|
+
import { asXL1BlockNumber, asXL1BlockRange as asXL1BlockRange2, isStepIdentityPayload, XYO_STEP_REWARD_ADDRESS } from "@xyo-network/xl1-protocol";
|
|
308
|
+
import { completedStepRewardAddress, derivedReceiveAddress, flattenHydratedTransaction, flattenHydratedTransactions } from "@xyo-network/xl1-protocol-sdk";
|
|
309
|
+
import { Mutex } from "async-mutex";
|
|
148
310
|
var ChainStepRewardsClaimSentinelConfigSchema = "network.xyo.sentinel.chain.step.rewards.claim.config";
|
|
149
311
|
var defaultStepClaimIntervalMs = 15e3;
|
|
150
312
|
var scope = "reward-escrow";
|
|
151
|
-
var
|
|
313
|
+
var RewardableSteps2 = [
|
|
152
314
|
3,
|
|
153
315
|
4,
|
|
154
316
|
5,
|
|
@@ -173,16 +335,16 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
173
335
|
_reportMutex = new Mutex();
|
|
174
336
|
_viewer;
|
|
175
337
|
get connection() {
|
|
176
|
-
return
|
|
338
|
+
return assertEx3(this._connection, () => "Connection is not defined");
|
|
177
339
|
}
|
|
178
340
|
get gateway() {
|
|
179
|
-
return
|
|
341
|
+
return assertEx3(this._gateway, () => "Gateway is not defined");
|
|
180
342
|
}
|
|
181
343
|
get stepClaimIntervalMs() {
|
|
182
|
-
return
|
|
344
|
+
return isDefined4(this.config.stepClaimIntervalMs) ? this.config.stepClaimIntervalMs : defaultStepClaimIntervalMs;
|
|
183
345
|
}
|
|
184
346
|
get viewer() {
|
|
185
|
-
return
|
|
347
|
+
return assertEx3(this._viewer, () => "Viewer is not defined");
|
|
186
348
|
}
|
|
187
349
|
async createHandler() {
|
|
188
350
|
await super.createHandler();
|
|
@@ -198,9 +360,9 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
198
360
|
this._claimErrorCounter = this.meter?.createCounter("chain_step_rewards_claim_sentinel_errors_total", {
|
|
199
361
|
description: "Number of claim errors"
|
|
200
362
|
});
|
|
201
|
-
const gateway =
|
|
202
|
-
const connection =
|
|
203
|
-
const viewer2 =
|
|
363
|
+
const gateway = assertEx3(this.params.gateway, () => "Gateway parameter is required");
|
|
364
|
+
const connection = assertEx3(await gateway.connection(), () => "Gateway connection is required");
|
|
365
|
+
const viewer2 = assertEx3(connection.viewer, () => "Viewer is not defined in gateway connection");
|
|
204
366
|
this._gateway = gateway;
|
|
205
367
|
this._connection = connection;
|
|
206
368
|
this._viewer = viewer2;
|
|
@@ -217,15 +379,17 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
217
379
|
} else {
|
|
218
380
|
const stepIdentities = payloads.filter(isStepIdentityPayload).map((p) => {
|
|
219
381
|
const { step, block: blockNumber } = p;
|
|
220
|
-
const block = asXL1BlockNumber(blockNumber,
|
|
382
|
+
const block = asXL1BlockNumber(blockNumber, {
|
|
383
|
+
name: "reportHandler"
|
|
384
|
+
});
|
|
221
385
|
return {
|
|
222
386
|
step,
|
|
223
387
|
block
|
|
224
388
|
};
|
|
225
|
-
}).filter((stepIdentity) =>
|
|
389
|
+
}).filter((stepIdentity) => RewardableSteps2.includes(stepIdentity.step));
|
|
226
390
|
for (const stepIdentity of stepIdentities) {
|
|
227
391
|
const result = await this.claimStepIdentity(stepIdentity);
|
|
228
|
-
if (
|
|
392
|
+
if (isDefined4(result)) response3.push(...flattenHydratedTransaction(result));
|
|
229
393
|
}
|
|
230
394
|
}
|
|
231
395
|
return response3;
|
|
@@ -242,7 +406,7 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
242
406
|
addressClaims[receiveAddress] = reward;
|
|
243
407
|
}
|
|
244
408
|
const totalClaimed = Object.values(addressClaims).reduce((acc, val) => acc + val, 0n);
|
|
245
|
-
|
|
409
|
+
assertEx3(totalClaimed <= balance, () => "Total claimed exceeds claimable balance");
|
|
246
410
|
const unclaimed = balance - totalClaimed;
|
|
247
411
|
if (unclaimed > 0n) {
|
|
248
412
|
addressClaims[XYO_STEP_REWARD_ADDRESS] = unclaimed;
|
|
@@ -251,19 +415,21 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
251
415
|
}
|
|
252
416
|
async claimAllSteps() {
|
|
253
417
|
const results = [];
|
|
254
|
-
for (const step of
|
|
418
|
+
for (const step of RewardableSteps2) {
|
|
255
419
|
const from = 0;
|
|
256
420
|
const to = await this.viewer.currentBlockNumber();
|
|
257
|
-
const range =
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
],
|
|
261
|
-
|
|
421
|
+
const range = asXL1BlockRange2([
|
|
422
|
+
from,
|
|
423
|
+
to
|
|
424
|
+
], {
|
|
425
|
+
name: "claimAllSteps"
|
|
426
|
+
});
|
|
427
|
+
const stepIdentities = blockRangeSteps2(range, [
|
|
262
428
|
step
|
|
263
429
|
]);
|
|
264
430
|
for (const stepIdentity of stepIdentities) {
|
|
265
431
|
const result = await this.claimStepIdentity(stepIdentity);
|
|
266
|
-
if (
|
|
432
|
+
if (isDefined4(result)) {
|
|
267
433
|
results.push(result);
|
|
268
434
|
}
|
|
269
435
|
await delay(this.stepClaimIntervalMs);
|
|
@@ -309,27 +475,25 @@ var ChainStepRewardsClaimSentinel = class extends AbstractSentinel {
|
|
|
309
475
|
nbf: currentBlockNumber,
|
|
310
476
|
exp: currentBlockNumber + 10
|
|
311
477
|
});
|
|
312
|
-
if (
|
|
478
|
+
if (isDefined4(result)) return result[1];
|
|
313
479
|
}
|
|
314
480
|
};
|
|
315
481
|
|
|
316
482
|
// src/modules/DerivedAddressWalletTransferSentinel/DerivedAddressWalletTransferSentinel.ts
|
|
317
|
-
import { assertEx as
|
|
318
|
-
import { AddressZod, EthAddressZod, hexToBigInt, HexZod, toAddress as toAddress2, toHex } from "@xylabs/hex";
|
|
319
|
-
import { isDefined as isDefined3, isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
483
|
+
import { AddressZod, assertEx as assertEx4, EthAddressZod, hexToBigInt, HexZod, isDefined as isDefined5, isUndefined as isUndefined2, toAddress as toAddress2, toHex } from "@xylabs/sdk-js";
|
|
320
484
|
import { createTransferPayload as createTransferPayload2 } from "@xyo-network/chain-protocol";
|
|
321
485
|
import { AbstractSentinel as AbstractSentinel2 } from "@xyo-network/sentinel-abstract";
|
|
322
|
-
import { derivedReceiveAddress as derivedReceiveAddress2, flattenHydratedTransaction as flattenHydratedTransaction2, isEIP712DataPayload, isEIP712SignaturePayload,
|
|
323
|
-
import
|
|
486
|
+
import { derivedReceiveAddress as derivedReceiveAddress2, flattenHydratedTransaction as flattenHydratedTransaction2, isEIP712DataPayload, isEIP712SignaturePayload, verifyEIP712Message } from "@xyo-network/xl1-protocol-sdk";
|
|
487
|
+
import z3 from "zod";
|
|
324
488
|
var DerivedAddressWalletTransferSentinelConfigSchema = "network.xyo.sentinel.chain.derived.address.wallet.transfer.config";
|
|
325
489
|
var scope2 = "reward-escrow";
|
|
326
|
-
var ConfirmedClaimValuesZod =
|
|
490
|
+
var ConfirmedClaimValuesZod = z3.object({
|
|
327
491
|
"From": EthAddressZod,
|
|
328
492
|
"To XL1 Address": AddressZod,
|
|
329
|
-
"XL1 Amount":
|
|
493
|
+
"XL1 Amount": z3.string(),
|
|
330
494
|
"XL1 Amount (Hex)": HexZod,
|
|
331
|
-
"XL1 Not after block":
|
|
332
|
-
"XL1 Not before block":
|
|
495
|
+
"XL1 Not after block": z3.number().int().nonnegative(),
|
|
496
|
+
"XL1 Not before block": z3.number().int().nonnegative()
|
|
333
497
|
});
|
|
334
498
|
var parseConfirmedClaimValues = /* @__PURE__ */ __name((values) => {
|
|
335
499
|
return {
|
|
@@ -352,7 +516,7 @@ var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
|
|
|
352
516
|
_transferErrorCounter;
|
|
353
517
|
_transferSuccessCounter;
|
|
354
518
|
get gateway() {
|
|
355
|
-
return
|
|
519
|
+
return this.params.gateway;
|
|
356
520
|
}
|
|
357
521
|
async createHandler() {
|
|
358
522
|
await super.createHandler();
|
|
@@ -382,7 +546,7 @@ var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
|
|
|
382
546
|
const parsedAddress = toAddress2(parsed.from);
|
|
383
547
|
if (signatureAddress === parsedAddress) {
|
|
384
548
|
const tx = await this.submitRewardDistributionTransaction(parsed);
|
|
385
|
-
if (
|
|
549
|
+
if (isDefined5(tx)) {
|
|
386
550
|
this._transferSuccessCounter?.add(1);
|
|
387
551
|
return flattenHydratedTransaction2(tx);
|
|
388
552
|
}
|
|
@@ -392,18 +556,18 @@ var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
|
|
|
392
556
|
}
|
|
393
557
|
submitRewardDistributionTransaction = /* @__PURE__ */ __name(async (claimValues) => {
|
|
394
558
|
const { amount, from: address, to, nbf, exp } = claimValues;
|
|
395
|
-
const signer =
|
|
559
|
+
const signer = assertEx4(await this.gateway.signer(), () => "Signer is not defined in gateway");
|
|
396
560
|
const signerAddress = await signer.address();
|
|
397
561
|
const connection = await this.gateway.connection();
|
|
398
|
-
const viewer2 =
|
|
562
|
+
const viewer2 = assertEx4(connection.viewer, () => "Viewer is not defined in gateway connection");
|
|
399
563
|
const currentBlock = await viewer2.currentBlockNumber();
|
|
400
564
|
if (currentBlock < nbf || currentBlock > exp) throw new Error("Transaction is not within a valid block range");
|
|
401
565
|
const escrowAccount = derivedReceiveAddress2(address, scope2);
|
|
402
566
|
const balance = await viewer2.accountBalance(escrowAccount);
|
|
403
567
|
const redemptionAmount = hexToBigInt(toHex(amount));
|
|
404
|
-
|
|
568
|
+
assertEx4(balance === redemptionAmount, () => "Insufficient balance in escrow account");
|
|
405
569
|
const allowance = await viewer2.accountBalance(signerAddress);
|
|
406
|
-
|
|
570
|
+
assertEx4(allowance > 1000n, () => "Insufficient allowance to transfer from escrow account");
|
|
407
571
|
const transferPayload = createTransferPayload2(escrowAccount, {
|
|
408
572
|
[to]: hexToBigInt(toHex(amount))
|
|
409
573
|
});
|
|
@@ -419,185 +583,11 @@ var DerivedAddressWalletTransferSentinel = class extends AbstractSentinel2 {
|
|
|
419
583
|
nbf,
|
|
420
584
|
exp
|
|
421
585
|
});
|
|
422
|
-
if (
|
|
586
|
+
if (isDefined5(result)) return result[1];
|
|
423
587
|
}, "submitRewardDistributionTransaction");
|
|
424
588
|
};
|
|
425
589
|
|
|
426
|
-
// src/server/routes/rewardRedemption/routeDefinitions/util/getViewerFromConfig.ts
|
|
427
|
-
import { isDefined as isDefined4 } from "@xylabs/typeof";
|
|
428
|
-
import { HttpRpcTransport, JsonRpcNetworkStakeViewer, JsonRpcXyoViewer, NetworkStakeViewerRpcSchemas, XyoViewerRpcSchemas } from "@xyo-network/xl1-rpc";
|
|
429
|
-
var viewer;
|
|
430
|
-
var getViewerFromConfig = /* @__PURE__ */ __name((config) => {
|
|
431
|
-
if (isDefined4(viewer)) return viewer;
|
|
432
|
-
const transport = new HttpRpcTransport(config.rewardRedemptionApi.chainRpcApiUrl, {
|
|
433
|
-
...XyoViewerRpcSchemas,
|
|
434
|
-
...NetworkStakeViewerRpcSchemas
|
|
435
|
-
});
|
|
436
|
-
const networkStakeViewer = new JsonRpcNetworkStakeViewer(transport);
|
|
437
|
-
viewer = new JsonRpcXyoViewer(transport, {
|
|
438
|
-
networkStakeViewer
|
|
439
|
-
});
|
|
440
|
-
return viewer;
|
|
441
|
-
}, "getViewerFromConfig");
|
|
442
|
-
|
|
443
|
-
// src/server/routes/rewardRedemption/routeDefinitions/util/rewardableSteps.ts
|
|
444
|
-
var RewardableSteps2 = [
|
|
445
|
-
3,
|
|
446
|
-
4,
|
|
447
|
-
5,
|
|
448
|
-
6,
|
|
449
|
-
7,
|
|
450
|
-
8
|
|
451
|
-
];
|
|
452
|
-
|
|
453
|
-
// src/server/routes/rewardRedemption/routeDefinitions/routes/claimRange.ts
|
|
454
|
-
var query = z2.object({
|
|
455
|
-
fromBlock: z2.coerce.number().int().nonnegative().optional(),
|
|
456
|
-
toBlock: z2.coerce.number().int().nonnegative().optional(),
|
|
457
|
-
step: z2.coerce.number().int().nonnegative().min(Math.min(...RewardableSteps2)).max(Math.max(...RewardableSteps2)).optional().default(3)
|
|
458
|
-
});
|
|
459
|
-
var response = z2.array(PayloadZodLoose);
|
|
460
|
-
var validateRequest = requestHandlerValidator({
|
|
461
|
-
query,
|
|
462
|
-
response
|
|
463
|
-
});
|
|
464
|
-
var getChainStepRewardsClaimSentinel = /* @__PURE__ */ __name(async (node) => {
|
|
465
|
-
const mod = await node.resolve("XYORewardRedemptionNode:ChainStepRewardsClaimSentinel");
|
|
466
|
-
const sentinel = asSentinelInstance(mod);
|
|
467
|
-
return assertEx3(sentinel, () => "ChainStepRewardsClaimSentinel not found on node");
|
|
468
|
-
}, "getChainStepRewardsClaimSentinel");
|
|
469
|
-
var postClaimRange = {
|
|
470
|
-
method: "post",
|
|
471
|
-
path: "/rewards/claimRange",
|
|
472
|
-
handlers: validateRequest(async (req, res) => {
|
|
473
|
-
const { config, node } = req.app;
|
|
474
|
-
const { fromBlock, toBlock, step } = z2.parse(query, req.query);
|
|
475
|
-
const viewer2 = getViewerFromConfig(config);
|
|
476
|
-
const from = isDefined5(fromBlock) ? fromBlock : 0;
|
|
477
|
-
const currentBlock = await viewer2.currentBlockNumber();
|
|
478
|
-
const to = isDefined5(toBlock) ? Math.min(toBlock, currentBlock) : currentBlock;
|
|
479
|
-
if (to <= from) {
|
|
480
|
-
res.status(400);
|
|
481
|
-
res.json([]);
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const range = asXL1BlockRange2([
|
|
485
|
-
from,
|
|
486
|
-
to
|
|
487
|
-
], true);
|
|
488
|
-
const stepIdentities = blockRangeSteps2(range, [
|
|
489
|
-
step
|
|
490
|
-
]);
|
|
491
|
-
const results = [];
|
|
492
|
-
for (const stepIdentity of stepIdentities) {
|
|
493
|
-
const mod = await getChainStepRewardsClaimSentinel(node);
|
|
494
|
-
const stepIdentityPayload = new PayloadBuilder2({
|
|
495
|
-
schema: StepIdentitySchema
|
|
496
|
-
}).fields(stepIdentity).build();
|
|
497
|
-
const result = await mod.report([
|
|
498
|
-
stepIdentityPayload
|
|
499
|
-
]);
|
|
500
|
-
results.push(...result);
|
|
501
|
-
}
|
|
502
|
-
res.status(200);
|
|
503
|
-
res.json(results);
|
|
504
|
-
})
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
// src/server/routes/rewardRedemption/routeDefinitions/routes/redeem.ts
|
|
508
|
-
import { assertEx as assertEx4 } from "@xylabs/assert";
|
|
509
|
-
import { requestHandlerValidator as requestHandlerValidator2 } from "@xylabs/express";
|
|
510
|
-
import { PayloadZodLoose as PayloadZodLoose2, PayloadZodStrictOfSchema } from "@xyo-network/payload-model";
|
|
511
|
-
import { asSentinelInstance as asSentinelInstance2 } from "@xyo-network/sentinel-model";
|
|
512
|
-
import { EIP712DataPayloadFieldsZod, EIP712DataPayloadSchema, EIP712SignaturePayloadFieldsZod, EIP712SignaturePayloadSchema } from "@xyo-network/xl1-protocol-sdk";
|
|
513
|
-
import { z as z3 } from "zod";
|
|
514
|
-
var body = z3.tuple([
|
|
515
|
-
PayloadZodStrictOfSchema(EIP712DataPayloadSchema).extend(EIP712DataPayloadFieldsZod.shape),
|
|
516
|
-
PayloadZodStrictOfSchema(EIP712SignaturePayloadSchema).extend(EIP712SignaturePayloadFieldsZod.shape)
|
|
517
|
-
]);
|
|
518
|
-
var response2 = z3.array(PayloadZodLoose2);
|
|
519
|
-
var validateRequest2 = requestHandlerValidator2({
|
|
520
|
-
body,
|
|
521
|
-
response: response2
|
|
522
|
-
});
|
|
523
|
-
var getDerivedAddressWalletTransferSentinel = /* @__PURE__ */ __name(async (node) => {
|
|
524
|
-
const mod = await node.resolve("XYORewardRedemptionNode:DerivedAddressWalletTransferSentinel");
|
|
525
|
-
const sentinel = asSentinelInstance2(mod);
|
|
526
|
-
return assertEx4(sentinel, () => "DerivedAddressWalletTransferSentinel not found on node");
|
|
527
|
-
}, "getDerivedAddressWalletTransferSentinel");
|
|
528
|
-
var postRedeem = {
|
|
529
|
-
method: "post",
|
|
530
|
-
path: "/rewards/redeem",
|
|
531
|
-
handlers: validateRequest2(async (req, res) => {
|
|
532
|
-
const { node } = req.app;
|
|
533
|
-
const { body: body2 } = req;
|
|
534
|
-
const sentinel = await getDerivedAddressWalletTransferSentinel(node);
|
|
535
|
-
const result = await sentinel.report(body2);
|
|
536
|
-
res.status(200);
|
|
537
|
-
res.json(result);
|
|
538
|
-
})
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
// src/server/routes/rewardRedemption/routeDefinitions/getRouteDefinitions.ts
|
|
542
|
-
var getRouteDefinitions = /* @__PURE__ */ __name(() => {
|
|
543
|
-
return [
|
|
544
|
-
postClaimRange,
|
|
545
|
-
postRedeem
|
|
546
|
-
];
|
|
547
|
-
}, "getRouteDefinitions");
|
|
548
|
-
|
|
549
|
-
// src/server/routes/rewardRedemption/addRewardRoutes.ts
|
|
550
|
-
var addRewardRedemptionRoutes = /* @__PURE__ */ __name((app) => {
|
|
551
|
-
const routeDefinitions = getRouteDefinitions();
|
|
552
|
-
addRouteDefinitions(app, routeDefinitions);
|
|
553
|
-
}, "addRewardRedemptionRoutes");
|
|
554
|
-
|
|
555
|
-
// src/server/routes/addRoutes.ts
|
|
556
|
-
var addRoutes = /* @__PURE__ */ __name((app) => {
|
|
557
|
-
addDataLakeRoutes(app);
|
|
558
|
-
addRewardRedemptionRoutes(app);
|
|
559
|
-
}, "addRoutes");
|
|
560
|
-
|
|
561
|
-
// src/server/app.ts
|
|
562
|
-
var getApp = /* @__PURE__ */ __name((node, config) => {
|
|
563
|
-
addInstrumentation();
|
|
564
|
-
const app = express2();
|
|
565
|
-
app.set("etag", false);
|
|
566
|
-
app.use(cors());
|
|
567
|
-
app.use(compression());
|
|
568
|
-
app.use(responseProfiler);
|
|
569
|
-
app.use(getJsonBodyParser(getJsonBodyParserOptions({
|
|
570
|
-
limit: "1mb"
|
|
571
|
-
})));
|
|
572
|
-
app.use(standardResponses);
|
|
573
|
-
disableExpressDefaultPoweredByHeader(app);
|
|
574
|
-
app.use(customPoweredByHeader);
|
|
575
|
-
disableCaseSensitiveRouting(app);
|
|
576
|
-
app.config = config;
|
|
577
|
-
app.node = node;
|
|
578
|
-
addRoutes(app);
|
|
579
|
-
app.use(standardErrors);
|
|
580
|
-
return app;
|
|
581
|
-
}, "getApp");
|
|
582
|
-
|
|
583
|
-
// src/server/server.ts
|
|
584
|
-
import { assertEx as assertEx5 } from "@xylabs/assert";
|
|
585
|
-
import { isDefined as isDefined7, isString } from "@xylabs/typeof";
|
|
586
|
-
import { boot } from "@xyo-network/bios";
|
|
587
|
-
import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
|
|
588
|
-
|
|
589
590
|
// src/manifest/getLocator.ts
|
|
590
|
-
import { isDefined as isDefined6 } from "@xylabs/typeof";
|
|
591
|
-
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
592
|
-
import { MongoDBArchivistV2 } from "@xyo-network/archivist-mongodb";
|
|
593
|
-
import { ViewArchivist } from "@xyo-network/archivist-view";
|
|
594
|
-
import { initTelemetry } from "@xyo-network/chain-telemetry";
|
|
595
|
-
import { AbstractModule, LoggerModuleStatusReporter } from "@xyo-network/module-abstract";
|
|
596
|
-
import { ModuleFactoryLocator } from "@xyo-network/module-factory-locator";
|
|
597
|
-
import { MemorySentinel } from "@xyo-network/sentinel-memory";
|
|
598
|
-
import { HDWallet } from "@xyo-network/wallet";
|
|
599
|
-
import { hasMongoConfig, SimpleXyoGateway, SimpleXyoSigner } from "@xyo-network/xl1-protocol-sdk";
|
|
600
|
-
import { HttpRpcXyoConnection } from "@xyo-network/xl1-rpc";
|
|
601
591
|
var getLocator = /* @__PURE__ */ __name(async (context) => {
|
|
602
592
|
const { config, logger } = context;
|
|
603
593
|
const { otlpEndpoint } = config.telemetry?.otel ?? {};
|
|
@@ -673,7 +663,7 @@ var getGateway = /* @__PURE__ */ __name(async (config) => {
|
|
|
673
663
|
const connection = new HttpRpcXyoConnection({
|
|
674
664
|
endpoint
|
|
675
665
|
});
|
|
676
|
-
const gateway = new
|
|
666
|
+
const gateway = new SimpleXyoGatewayRunner(connection, signer);
|
|
677
667
|
return gateway;
|
|
678
668
|
}, "getGateway");
|
|
679
669
|
|