@render-foundation/utils 0.0.195 → 0.0.197
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/lib/cjs/burn/burnAnalysis.js +101 -0
- package/lib/cjs/burn/burnAnalysis.js.map +1 -0
- package/lib/cjs/burn/burnCalculations.js +140 -0
- package/lib/cjs/burn/burnCalculations.js.map +1 -0
- package/lib/cjs/client/pg/v2Client.js +145 -13
- package/lib/cjs/client/pg/v2Client.js.map +1 -1
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/src/burn/burnAnalysis.js +90 -0
- package/lib/esm/src/burn/burnAnalysis.js.map +1 -0
- package/lib/esm/src/burn/burnCalculations.js +124 -0
- package/lib/esm/src/burn/burnCalculations.js.map +1 -0
- package/lib/esm/src/client/pg/v2Client.js +139 -13
- package/lib/esm/src/client/pg/v2Client.js.map +1 -1
- package/lib/esm/src/index.js +2 -0
- package/lib/esm/src/index.js.map +1 -1
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/src/burn/burnAnalysis.d.ts +51 -0
- package/lib/types/src/burn/burnAnalysis.d.ts.map +1 -0
- package/lib/types/src/burn/burnCalculations.d.ts +52 -0
- package/lib/types/src/burn/burnCalculations.d.ts.map +1 -0
- package/lib/types/src/client/pg/v2Client.d.ts +10 -0
- package/lib/types/src/client/pg/v2Client.d.ts.map +1 -1
- package/lib/types/src/index.d.ts +2 -0
- package/lib/types/src/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.compareBurnAmounts = exports.analyzeBurnJobs = void 0;
|
|
13
|
+
const burnCalculations_1 = require("./burnCalculations");
|
|
14
|
+
const logger_1 = require("../logger");
|
|
15
|
+
/**
|
|
16
|
+
* Analyzes a set of jobs and calculates what should have been burned
|
|
17
|
+
* This function can be used for both live processing and backfill analysis
|
|
18
|
+
*/
|
|
19
|
+
const analyzeBurnJobs = (ctx, input, opts = {
|
|
20
|
+
perpetual: true,
|
|
21
|
+
}, log = logger_1.consoleLogger) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
const { jobs, params, decimals, pricedAt } = input;
|
|
23
|
+
// Get user grant spends
|
|
24
|
+
const userIds = jobs.reduce((acc, job) => {
|
|
25
|
+
if (job.userId) {
|
|
26
|
+
acc.add(job.userId);
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}, new Set());
|
|
30
|
+
// For analysis, we use the underlying db object directly
|
|
31
|
+
const userGrantSpends = (yield Promise.all(Array.from(userIds).map((userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
// Note: For backfill, we might need historical grant spend data
|
|
33
|
+
// This is a limitation we'll need to address
|
|
34
|
+
const currSpend = yield ctx.pgV2.getCurrentUserGrantSpend(ctx.pgV2.db, // Use the underlying db object
|
|
35
|
+
{ userId }, log);
|
|
36
|
+
return { userId, currSpend };
|
|
37
|
+
})))).reduce((acc, us) => {
|
|
38
|
+
if (us.currSpend) {
|
|
39
|
+
acc[us.userId] = {
|
|
40
|
+
userGrantSpend: us.currSpend,
|
|
41
|
+
currAllot: us.currSpend.renderSpent,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return acc;
|
|
45
|
+
}, {});
|
|
46
|
+
// Get burn adjustments (for backfill, we might need historical data)
|
|
47
|
+
const burnAdjustments = yield ctx.pgV2.getBurnAdjustments(ctx.pgV2.db, // Use the underlying db object
|
|
48
|
+
{ toFill: true }, log);
|
|
49
|
+
// Determine pricing date
|
|
50
|
+
const effectivePricedAt = pricedAt ||
|
|
51
|
+
(0, burnCalculations_1.calculateBurnAmounts)({
|
|
52
|
+
jobs,
|
|
53
|
+
userGrantSpends,
|
|
54
|
+
burnAdjustments,
|
|
55
|
+
params,
|
|
56
|
+
decimals,
|
|
57
|
+
priceAtDate: 1,
|
|
58
|
+
eurToUSDC: 1, // Dummy value for date calculation
|
|
59
|
+
}, opts, log).pricedAt;
|
|
60
|
+
// Get historical prices
|
|
61
|
+
const price = yield ctx.priceClient.getRenderPriceAtDate({
|
|
62
|
+
ts: effectivePricedAt,
|
|
63
|
+
});
|
|
64
|
+
const eurToUSDC = yield ctx.priceClient.eurToUSDC(effectivePricedAt);
|
|
65
|
+
// Calculate burn amounts
|
|
66
|
+
const result = (0, burnCalculations_1.calculateBurnAmounts)({
|
|
67
|
+
jobs,
|
|
68
|
+
userGrantSpends,
|
|
69
|
+
burnAdjustments,
|
|
70
|
+
params,
|
|
71
|
+
decimals,
|
|
72
|
+
priceAtDate: price,
|
|
73
|
+
eurToUSDC,
|
|
74
|
+
}, opts, log);
|
|
75
|
+
return Object.assign(Object.assign({}, result), { price,
|
|
76
|
+
eurToUSDC });
|
|
77
|
+
});
|
|
78
|
+
exports.analyzeBurnJobs = analyzeBurnJobs;
|
|
79
|
+
const compareBurnAmounts = (expected, actual) => {
|
|
80
|
+
const discrepancyTotalToBurn = actual.totalToBurn - expected.totalToBurn;
|
|
81
|
+
/* // Only return discrepancy if absolute total discrepancy is significant (> 10^8)
|
|
82
|
+
if (Math.abs(discrepancyTotalToBurn) <= Math.pow(10, 8)) {
|
|
83
|
+
return null
|
|
84
|
+
} */
|
|
85
|
+
return {
|
|
86
|
+
expectedRenderToBuyAndBurn: expected.renderToBuyAndBurn,
|
|
87
|
+
actualRenderToBuyAndBurn: actual.renderToBuyAndBurn,
|
|
88
|
+
expectedRenderToBurnFromEmissions: expected.renderToBurnFromEmissions,
|
|
89
|
+
actualRenderToBurnFromEmissions: actual.renderToBurnFromEmissions,
|
|
90
|
+
expectedTotalToBurn: expected.totalToBurn,
|
|
91
|
+
actualTotalToBurn: actual.totalToBurn,
|
|
92
|
+
discrepancyRenderToBuyAndBurn: actual.renderToBuyAndBurn - expected.renderToBuyAndBurn,
|
|
93
|
+
discrepancyRenderToBurnFromEmissions: actual.renderToBurnFromEmissions - expected.renderToBurnFromEmissions,
|
|
94
|
+
discrepancyTotalToBurn,
|
|
95
|
+
jobs: actual.jobs,
|
|
96
|
+
burnDate: actual.burnDate,
|
|
97
|
+
txSig: actual.txSig,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
exports.compareBurnAmounts = compareBurnAmounts;
|
|
101
|
+
//# sourceMappingURL=burnAnalysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"burnAnalysis.js","sourceRoot":"","sources":["../../../src/burn/burnAnalysis.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yDAI2B;AAC3B,sCAAuD;AAqBvD;;;GAGG;AACI,MAAM,eAAe,GAAG,CAC7B,GAAkB,EAClB,KAAwB,EACxB,OAEI;IACF,SAAS,EAAE,IAAI;CAChB,EACD,MAAoB,sBAAa,EACJ,EAAE;IAC/B,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAElD,wBAAwB;IACxB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACvC,IAAI,GAAG,CAAC,MAAM,EAAE;YACd,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;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,sBAkC9B"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.calculateBurnAmounts = exports.batchFinishedAtMedian = void 0;
|
|
15
|
+
const spl_utils_1 = require("@render-foundation/spl-utils");
|
|
16
|
+
const logger_1 = require("../logger");
|
|
17
|
+
// Utility function copied from cron-server
|
|
18
|
+
const batchFinishedAtMedian = (jobs) => {
|
|
19
|
+
const pricedAt = jobs.length % 2 == 0
|
|
20
|
+
? new Date(Math.trunc((Date.parse(jobs[jobs.length / 2].finishedAt) +
|
|
21
|
+
Date.parse(jobs[jobs.length / 2 - 1].finishedAt)) /
|
|
22
|
+
2))
|
|
23
|
+
: new Date(Date.parse(jobs[Math.floor(jobs.length / 2)].finishedAt));
|
|
24
|
+
return pricedAt;
|
|
25
|
+
};
|
|
26
|
+
exports.batchFinishedAtMedian = batchFinishedAtMedian;
|
|
27
|
+
/**
|
|
28
|
+
* Pure function that calculates burn amounts without side effects
|
|
29
|
+
* This is the core logic extracted from consumeIncrBuyAndBurnRenderPG
|
|
30
|
+
*/
|
|
31
|
+
const calculateBurnAmounts = (input, opts = {
|
|
32
|
+
perpetual: true,
|
|
33
|
+
}, log = logger_1.consoleLogger) => {
|
|
34
|
+
const { jobs, userGrantSpends, burnAdjustments, params, decimals, priceAtDate, eurToUSDC, } = input;
|
|
35
|
+
// Apply grant/buy split logic to jobs
|
|
36
|
+
const processedJobs = jobs.map((j) => {
|
|
37
|
+
const { buyRenderAmt, grantRenderAmt } = j, rest = __rest(j, ["buyRenderAmt", "grantRenderAmt"]);
|
|
38
|
+
return rest;
|
|
39
|
+
}); // Deep copy to avoid mutations
|
|
40
|
+
for (const j of processedJobs) {
|
|
41
|
+
const userGrantSpend = userGrantSpends[j.userId];
|
|
42
|
+
if (userGrantSpend) {
|
|
43
|
+
if (opts.perpetual ||
|
|
44
|
+
userGrantSpend.userGrantSpend.perpetual ||
|
|
45
|
+
j.rndrUsed <= userGrantSpend.currAllot) {
|
|
46
|
+
j.grantRenderAmt = Number(j.rndrUsed);
|
|
47
|
+
log.debug(`job ${j.id} grant split: ${j.rndrUsed}`);
|
|
48
|
+
userGrantSpend.currAllot -= BigInt(j.rndrUsed);
|
|
49
|
+
}
|
|
50
|
+
else if (userGrantSpend.currAllot <= BigInt(0)) {
|
|
51
|
+
log.debug(`job ${j.id} buy split: ${j.rndrUsed}`);
|
|
52
|
+
j.buyRenderAmt = Number(j.rndrUsed);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
log.debug(`job ${j.id} buy + grant split: ${j.rndrUsed} grant: ${Number(userGrantSpend.currAllot)} buy: ${Number(j.rndrUsed) - Number(userGrantSpend.currAllot)}`);
|
|
56
|
+
j.grantRenderAmt = Number(userGrantSpend.currAllot);
|
|
57
|
+
j.buyRenderAmt = Number(j.rndrUsed) - Number(userGrantSpend.currAllot);
|
|
58
|
+
userGrantSpend.currAllot = BigInt(0);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
log.debug(`job ${j.id} no grant split: ${j.rndrUsed}`);
|
|
63
|
+
j.buyRenderAmt = Number(j.rndrUsed);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const totalRenderUsed = processedJobs.reduce((tot, job) => tot + Number(job.rndrUsed.toString()), 0);
|
|
67
|
+
log.debug(`jobs buy + grant split: ${JSON.stringify(processedJobs)}`);
|
|
68
|
+
// Check minimum threshold
|
|
69
|
+
if (totalRenderUsed < (0, spl_utils_1.toBN)(params.minTotalRndrThreshold, decimals).toNumber()) {
|
|
70
|
+
throw new Error(`totalRenderUsed ${totalRenderUsed / Math.pow(10, decimals)} < total threshold ${params.minTotalRndrThreshold}`);
|
|
71
|
+
}
|
|
72
|
+
const totalRenderBuyAndBurn = processedJobs.reduce((tot, job) => { var _a; return tot + Number((_a = job.buyRenderAmt) !== null && _a !== void 0 ? _a : 0); }, 0);
|
|
73
|
+
const totalRender = processedJobs.reduce((tot, job) => tot + Number(job.rndrUsed.toString()), 0);
|
|
74
|
+
log.debug(`Burn calculation inputs:`);
|
|
75
|
+
log.debug(` totalRenderUsed: ${totalRenderUsed}`);
|
|
76
|
+
log.debug(` totalRenderBuyAndBurn: ${totalRenderBuyAndBurn}`);
|
|
77
|
+
log.debug(` totalRender: ${totalRender}`);
|
|
78
|
+
log.debug(` priceAtDate: ${priceAtDate}`);
|
|
79
|
+
log.debug(` eurToUSDC: ${eurToUSDC}`);
|
|
80
|
+
const pricedAt = (0, exports.batchFinishedAtMedian)(processedJobs.map((job) => ({
|
|
81
|
+
finishedAt: job.completedAt.toISOString(),
|
|
82
|
+
jobId: job.id,
|
|
83
|
+
rndrUsed: Number(job.rndrUsed.toString()),
|
|
84
|
+
})));
|
|
85
|
+
// Core burn calculation logic
|
|
86
|
+
const toBurn = Math.trunc((totalRender / priceAtDate / 4) * 0.95 * eurToUSDC);
|
|
87
|
+
let renderToBuyAndBurn = Math.trunc((totalRenderBuyAndBurn / totalRender) * toBurn);
|
|
88
|
+
const origRenderToBuyAndBurn = renderToBuyAndBurn;
|
|
89
|
+
log.debug(`Core burn calculation:`);
|
|
90
|
+
log.debug(` toBurn: ${toBurn}`);
|
|
91
|
+
log.debug(` renderToBuyAndBurn: ${renderToBuyAndBurn}`);
|
|
92
|
+
log.debug(` origRenderToBuyAndBurn: ${origRenderToBuyAndBurn}`);
|
|
93
|
+
let burnAdjustmentId = undefined;
|
|
94
|
+
// Apply burn adjustments
|
|
95
|
+
if (burnAdjustments.length > 0) {
|
|
96
|
+
const adjustment = burnAdjustments[0];
|
|
97
|
+
burnAdjustmentId = adjustment.id;
|
|
98
|
+
const adjLeft = adjustment.downAdjToBurn - adjustment.adjusted;
|
|
99
|
+
const minBurnRndrThreshold = (0, spl_utils_1.toBN)(params.minBurnRndrThreshold, decimals).toNumber();
|
|
100
|
+
const available = renderToBuyAndBurn - minBurnRndrThreshold;
|
|
101
|
+
if (adjLeft > available) {
|
|
102
|
+
renderToBuyAndBurn = minBurnRndrThreshold;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
renderToBuyAndBurn -= adjLeft;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Validate burn thresholds
|
|
109
|
+
const toBuyAndBurnUI = renderToBuyAndBurn / Math.pow(10, decimals);
|
|
110
|
+
if (renderToBuyAndBurn != 0) {
|
|
111
|
+
if (toBuyAndBurnUI > params.maxBurnRndrThreshold) {
|
|
112
|
+
throw new Error(`buy and burn RENDER ${toBuyAndBurnUI} too high`);
|
|
113
|
+
}
|
|
114
|
+
if (toBuyAndBurnUI < params.minBurnRndrThreshold) {
|
|
115
|
+
throw new Error(`buy and burn RENDER ${toBuyAndBurnUI} too low < ${params.minBurnRndrThreshold}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const renderToBurnFromEmissions = toBurn - origRenderToBuyAndBurn;
|
|
119
|
+
const totalToBurn = renderToBuyAndBurn + renderToBurnFromEmissions;
|
|
120
|
+
log.debug(`Final burn calculation results:`);
|
|
121
|
+
log.debug(` renderToBuyAndBurn: ${renderToBuyAndBurn}`);
|
|
122
|
+
log.debug(` renderToBurnFromEmissions: ${renderToBurnFromEmissions}`);
|
|
123
|
+
log.debug(` totalToBurn: ${totalToBurn}`);
|
|
124
|
+
log.debug(` toBurn: ${toBurn}`);
|
|
125
|
+
return {
|
|
126
|
+
totalRenderUsed,
|
|
127
|
+
totalRenderBuyAndBurn,
|
|
128
|
+
totalRender,
|
|
129
|
+
renderToBuyAndBurn,
|
|
130
|
+
renderToBurnFromEmissions,
|
|
131
|
+
totalToBurn,
|
|
132
|
+
toBurn,
|
|
133
|
+
origRenderToBuyAndBurn,
|
|
134
|
+
burnAdjustmentId,
|
|
135
|
+
pricedAt,
|
|
136
|
+
processedJobs,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
exports.calculateBurnAmounts = calculateBurnAmounts;
|
|
140
|
+
//# sourceMappingURL=burnCalculations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"burnCalculations.js","sourceRoot":"","sources":["../../../src/burn/burnCalculations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,4DAAmD;AACnD,sCAAuD;AAWvD,2CAA2C;AACpC,MAAM,qBAAqB,GAAG,CACnC,IAA+D,EACzD,EAAE;IACR,MAAM,QAAQ,GACZ,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC;QAClB,CAAC,CAAC,IAAI,IAAI,CACN,IAAI,CAAC,KAAK,CACR,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC;YAC3C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;YACjD,CAAC,CACJ,CACF;QACH,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;IACxE,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAdY,QAAA,qBAAqB,yB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AM,CAAC,oBAAoB,EAAE;YAChD,MAAM,IAAI,KAAK,CACb,uBAAuB,cAAc,cAAc,MAAM,CAAC,oBAAoB,EAAE,CACjF,CAAA;SACF;KACF;IAED,MAAM,yBAAyB,GAAG,MAAM,GAAG,sBAAsB,CAAA;IACjE,MAAM,WAAW,GAAG,kBAAkB,GAAG,yBAAyB,CAAA;IAElE,GAAG,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAA;IAC5C,GAAG,CAAC,KAAK,CAAC,yBAAyB,kBAAkB,EAAE,CAAC,CAAA;IACxD,GAAG,CAAC,KAAK,CAAC,gCAAgC,yBAAyB,EAAE,CAAC,CAAA;IACtE,GAAG,CAAC,KAAK,CAAC,kBAAkB,WAAW,EAAE,CAAC,CAAA;IAC1C,GAAG,CAAC,KAAK,CAAC,aAAa,MAAM,EAAE,CAAC,CAAA;IAEhC,OAAO;QACL,eAAe;QACf,qBAAqB;QACrB,WAAW;QACX,kBAAkB;QAClB,yBAAyB;QACzB,WAAW;QACX,MAAM;QACN,sBAAsB;QACtB,gBAAgB;QAChB,QAAQ;QACR,aAAa;KACd,CAAA;AACH,CAAC,CAAA;AAxKY,QAAA,oBAAoB,wBAwKhC"}
|
|
@@ -1033,9 +1033,7 @@ const pgClient = (config) => {
|
|
|
1033
1033
|
rndrUsed: Number(j.rndrUsed.toString()),
|
|
1034
1034
|
})));
|
|
1035
1035
|
}
|
|
1036
|
-
const
|
|
1037
|
-
.insertInto(exports.BURN_TABLE)
|
|
1038
|
-
.values({
|
|
1036
|
+
const v = {
|
|
1039
1037
|
sol_tx_id: solTxId,
|
|
1040
1038
|
priced_at: pricedAt,
|
|
1041
1039
|
eur_to_usdc: eurToUsdc,
|
|
@@ -1046,7 +1044,11 @@ const pgClient = (config) => {
|
|
|
1046
1044
|
tags: tags.join(','),
|
|
1047
1045
|
burn_adjustment_id: burnAdjustmentId,
|
|
1048
1046
|
to_burn: toBurn,
|
|
1049
|
-
}
|
|
1047
|
+
};
|
|
1048
|
+
log.debug(`inserting burn ${JSON.stringify(v)}`);
|
|
1049
|
+
const { id } = yield trx.trx
|
|
1050
|
+
.insertInto(exports.BURN_TABLE)
|
|
1051
|
+
.values(v)
|
|
1050
1052
|
//.onConflict((oc) => oc.column('sol_tx').doNothing())
|
|
1051
1053
|
.returning((eb) => ['id as id'])
|
|
1052
1054
|
.executeTakeFirstOrThrow();
|
|
@@ -1054,27 +1056,37 @@ const pgClient = (config) => {
|
|
|
1054
1056
|
}
|
|
1055
1057
|
if (p.grantBurn) {
|
|
1056
1058
|
const { burned, tags } = p.grantBurn;
|
|
1057
|
-
const
|
|
1058
|
-
.insertInto(exports.GRANT_BURN_TABLE)
|
|
1059
|
-
.values({
|
|
1059
|
+
const v = {
|
|
1060
1060
|
sol_tx_id: solTxId,
|
|
1061
1061
|
burned: burned,
|
|
1062
1062
|
tags: tags === null || tags === void 0 ? void 0 : tags.join(','),
|
|
1063
|
-
}
|
|
1063
|
+
};
|
|
1064
|
+
log.debug(`inserting grant burn ${JSON.stringify(v)}`);
|
|
1065
|
+
const { id } = yield trx.trx
|
|
1066
|
+
.insertInto(exports.GRANT_BURN_TABLE)
|
|
1067
|
+
.values(v)
|
|
1064
1068
|
.returning((eb) => ['id as id'])
|
|
1065
1069
|
.executeTakeFirstOrThrow();
|
|
1066
1070
|
grantBurnId = Number(id);
|
|
1067
1071
|
}
|
|
1068
|
-
const burnId = buyBurnId
|
|
1072
|
+
const burnId = buyBurnId;
|
|
1069
1073
|
const grantId = grantBurnId !== null && grantBurnId !== void 0 ? grantBurnId : buyBurnId;
|
|
1070
1074
|
for (const job of p.jobs) {
|
|
1075
|
+
const v = {
|
|
1076
|
+
burnId,
|
|
1077
|
+
grantId,
|
|
1078
|
+
jobId: String(job.id),
|
|
1079
|
+
buyRenderAmt: (_a = job.buyRenderAmt) !== null && _a !== void 0 ? _a : 0,
|
|
1080
|
+
grantRenderAmt: (_b = job.grantRenderAmt) !== null && _b !== void 0 ? _b : 0
|
|
1081
|
+
};
|
|
1082
|
+
log.debug(`updating job ${job.id} -> ${JSON.stringify(v)}`);
|
|
1071
1083
|
const res = yield trx.trx
|
|
1072
1084
|
.updateTable(exports.JOB_TABLE)
|
|
1073
1085
|
.where('id', '=', String(job.id))
|
|
1074
|
-
.set('burn_id', burnId)
|
|
1075
|
-
.set('grant_burn_id', grantId)
|
|
1076
|
-
.set('buy_render_amt',
|
|
1077
|
-
.set('grant_render_amt',
|
|
1086
|
+
.set('burn_id', v.burnId)
|
|
1087
|
+
.set('grant_burn_id', v.grantId)
|
|
1088
|
+
.set('buy_render_amt', v.buyRenderAmt)
|
|
1089
|
+
.set('grant_render_amt', v.grantRenderAmt)
|
|
1078
1090
|
.executeTakeFirstOrThrow();
|
|
1079
1091
|
log.debug(`set burn_id ${burnId} grant_burn_id ${grantId} buy_render_amt ${job.buyRenderAmt} grant_render_amt ${job.grantRenderAmt} on ${res.numUpdatedRows} jobs id ${job.id}`);
|
|
1080
1092
|
}
|
|
@@ -1783,6 +1795,126 @@ const pgClient = (config) => {
|
|
|
1783
1795
|
}
|
|
1784
1796
|
});
|
|
1785
1797
|
},
|
|
1798
|
+
checkPaymentsForDate(targetDate, channel = 'both', log = logger_1.consoleLogger) {
|
|
1799
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1800
|
+
const startOfDay = new Date(targetDate);
|
|
1801
|
+
startOfDay.setHours(0, 0, 0, 0);
|
|
1802
|
+
const endOfDay = new Date(targetDate);
|
|
1803
|
+
endOfDay.setHours(23, 59, 59, 999);
|
|
1804
|
+
try {
|
|
1805
|
+
let query = db
|
|
1806
|
+
.selectFrom('sol_transfer1')
|
|
1807
|
+
.innerJoin('sol_tx', 'sol_transfer1.sol_tx_id', 'sol_tx.id')
|
|
1808
|
+
.select([
|
|
1809
|
+
(0, kysely_1.sql) `COUNT(*)`.as('count'),
|
|
1810
|
+
(0, kysely_1.sql) `SUM(sol_transfer1.amount_payed)`.as('totalPaid'),
|
|
1811
|
+
(0, kysely_1.sql) `MAX(sol_tx.executed_at)`.as('lastPayment'),
|
|
1812
|
+
])
|
|
1813
|
+
.where('sol_tx.executed_at', '>=', startOfDay)
|
|
1814
|
+
.where('sol_tx.executed_at', '<=', endOfDay)
|
|
1815
|
+
.where('sol_transfer1.amount_payed', '>', '0');
|
|
1816
|
+
if (channel !== 'both') {
|
|
1817
|
+
query = query.where('sol_transfer1.channel', '=', channel);
|
|
1818
|
+
}
|
|
1819
|
+
else {
|
|
1820
|
+
query = query.where('sol_transfer1.channel', 'in', [
|
|
1821
|
+
'node_operator',
|
|
1822
|
+
'availability',
|
|
1823
|
+
]);
|
|
1824
|
+
}
|
|
1825
|
+
const result = yield query.executeTakeFirst();
|
|
1826
|
+
const paymentCount = Number((result === null || result === void 0 ? void 0 : result.count) || 0);
|
|
1827
|
+
const hasPayments = paymentCount > 0;
|
|
1828
|
+
const totalAmountPaid = (result === null || result === void 0 ? void 0 : result.totalPaid) || BigInt(0);
|
|
1829
|
+
const lastPaymentDate = (result === null || result === void 0 ? void 0 : result.lastPayment) || undefined;
|
|
1830
|
+
if (hasPayments) {
|
|
1831
|
+
log.warn(`Found ${paymentCount} ${channel} payments on ${targetDate.toISOString().split('T')[0]} ` +
|
|
1832
|
+
`(total: ${totalAmountPaid} tokens, last payment: ${lastPaymentDate})`);
|
|
1833
|
+
}
|
|
1834
|
+
else {
|
|
1835
|
+
log.info(`No existing ${channel} payments found on ${targetDate.toISOString().split('T')[0]}`);
|
|
1836
|
+
}
|
|
1837
|
+
return {
|
|
1838
|
+
hasPayments,
|
|
1839
|
+
paymentCount,
|
|
1840
|
+
lastPaymentDate,
|
|
1841
|
+
totalAmountPaid,
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
catch (error) {
|
|
1845
|
+
log.error(`Error checking payments for date ${targetDate.toISOString()}: ${error}`);
|
|
1846
|
+
throw error;
|
|
1847
|
+
}
|
|
1848
|
+
});
|
|
1849
|
+
},
|
|
1850
|
+
checkEpochProcessed(epochId, channel, log = logger_1.consoleLogger) {
|
|
1851
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1852
|
+
try {
|
|
1853
|
+
const result = yield db
|
|
1854
|
+
.selectFrom('epoch')
|
|
1855
|
+
.select(['saved_at'])
|
|
1856
|
+
.where('ui', '=', epochId.toString())
|
|
1857
|
+
.where('channel', '=', channel)
|
|
1858
|
+
.executeTakeFirst();
|
|
1859
|
+
const isProcessed = (result === null || result === void 0 ? void 0 : result.saved_at) !== null && (result === null || result === void 0 ? void 0 : result.saved_at) !== undefined;
|
|
1860
|
+
if (isProcessed) {
|
|
1861
|
+
log.info(`Epoch ${epochId} for ${channel} was already processed at ${result === null || result === void 0 ? void 0 : result.saved_at}`);
|
|
1862
|
+
}
|
|
1863
|
+
return isProcessed;
|
|
1864
|
+
}
|
|
1865
|
+
catch (error) {
|
|
1866
|
+
log.error(`Error checking if epoch ${epochId} is processed: ${error}`);
|
|
1867
|
+
throw error;
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
},
|
|
1871
|
+
checkRecentPaymentActivity(lookbackHours = 2, channel = 'both', log = logger_1.consoleLogger) {
|
|
1872
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1873
|
+
const lookbackTime = new Date(Date.now() - lookbackHours * 60 * 60 * 1000);
|
|
1874
|
+
const now = new Date();
|
|
1875
|
+
try {
|
|
1876
|
+
let query = db
|
|
1877
|
+
.selectFrom('sol_transfer1')
|
|
1878
|
+
.innerJoin('sol_tx', 'sol_transfer1.sol_tx_id', 'sol_tx.id')
|
|
1879
|
+
.select([
|
|
1880
|
+
(0, kysely_1.sql) `COUNT(*)`.as('count'),
|
|
1881
|
+
(0, kysely_1.sql) `SUM(sol_transfer1.amount_payed)`.as('totalPaid'),
|
|
1882
|
+
(0, kysely_1.sql) `MAX(sol_tx.executed_at)`.as('lastPayment'),
|
|
1883
|
+
])
|
|
1884
|
+
.where('sol_tx.executed_at', '>=', lookbackTime)
|
|
1885
|
+
.where('sol_tx.executed_at', '<=', now)
|
|
1886
|
+
.where('sol_transfer1.amount_payed', '>', '0');
|
|
1887
|
+
if (channel !== 'both') {
|
|
1888
|
+
query = query.where('sol_transfer1.channel', '=', channel);
|
|
1889
|
+
}
|
|
1890
|
+
else {
|
|
1891
|
+
query = query.where('sol_transfer1.channel', 'in', [
|
|
1892
|
+
'node_operator',
|
|
1893
|
+
'availability',
|
|
1894
|
+
]);
|
|
1895
|
+
}
|
|
1896
|
+
const result = yield query.executeTakeFirst();
|
|
1897
|
+
const paymentCount = Number((result === null || result === void 0 ? void 0 : result.count) || 0);
|
|
1898
|
+
const hasPayments = paymentCount > 0;
|
|
1899
|
+
const totalAmountPaid = (result === null || result === void 0 ? void 0 : result.totalPaid) || BigInt(0);
|
|
1900
|
+
const lastPaymentDate = (result === null || result === void 0 ? void 0 : result.lastPayment) || undefined;
|
|
1901
|
+
if (hasPayments) {
|
|
1902
|
+
log.info(`Found ${paymentCount} ${channel} payments in last ${lookbackHours} hours ` +
|
|
1903
|
+
`(total: ${totalAmountPaid} tokens)`);
|
|
1904
|
+
}
|
|
1905
|
+
return {
|
|
1906
|
+
hasPayments,
|
|
1907
|
+
paymentCount,
|
|
1908
|
+
lastPaymentDate,
|
|
1909
|
+
totalAmountPaid,
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1912
|
+
catch (error) {
|
|
1913
|
+
log.error(`Error checking recent payment activity: ${error}`);
|
|
1914
|
+
throw error;
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
},
|
|
1786
1918
|
};
|
|
1787
1919
|
};
|
|
1788
1920
|
exports.pgClient = pgClient;
|