@render-foundation/utils 0.0.197 → 0.0.199
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/CHANGELOG.md +310 -0
- package/lib/cjs/assertSecrets.js +43 -0
- package/lib/cjs/assertSecrets.js.map +1 -0
- package/lib/cjs/client/dispersed.js +123 -0
- package/lib/cjs/client/dispersed.js.map +1 -0
- package/lib/cjs/client/pg/v2Client.js +47 -1
- package/lib/cjs/client/pg/v2Client.js.map +1 -1
- package/lib/cjs/index.js +6 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/src/assertSecrets.js +39 -0
- package/lib/esm/src/assertSecrets.js.map +1 -0
- package/lib/esm/src/client/dispersed.js +108 -0
- package/lib/esm/src/client/dispersed.js.map +1 -0
- package/lib/esm/src/client/pg/v2Client.js +40 -0
- package/lib/esm/src/client/pg/v2Client.js.map +1 -1
- package/lib/esm/src/index.js +6 -2
- package/lib/esm/src/index.js.map +1 -1
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/src/assertSecrets.d.ts +27 -0
- package/lib/types/src/assertSecrets.d.ts.map +1 -0
- package/lib/types/src/client/dispersed.d.ts +91 -0
- package/lib/types/src/client/dispersed.d.ts.map +1 -0
- package/lib/types/src/client/pg/v2Client.d.ts +21 -0
- package/lib/types/src/client/pg/v2Client.d.ts.map +1 -1
- package/lib/types/src/dbTypesV2.d.ts +13 -1
- package/lib/types/src/dbTypesV2.d.ts.map +1 -1
- package/lib/types/src/index.d.ts +3 -2
- package/lib/types/src/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/lib/cjs/burn/burnAnalysis.js +0 -101
- package/lib/cjs/burn/burnAnalysis.js.map +0 -1
- package/lib/cjs/burn/burnCalculations.js +0 -140
- package/lib/cjs/burn/burnCalculations.js.map +0 -1
- package/lib/esm/src/burn/burnAnalysis.js +0 -90
- package/lib/esm/src/burn/burnAnalysis.js.map +0 -1
- package/lib/esm/src/burn/burnCalculations.js +0 -124
- package/lib/esm/src/burn/burnCalculations.js.map +0 -1
- package/lib/types/src/burn/burnAnalysis.d.ts +0 -51
- package/lib/types/src/burn/burnAnalysis.d.ts.map +0 -1
- package/lib/types/src/burn/burnCalculations.d.ts +0 -52
- package/lib/types/src/burn/burnCalculations.d.ts.map +0 -1
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { calculateBurnAmounts, } from './burnCalculations';
|
|
2
|
-
import { consoleLogger } from '../logger';
|
|
3
|
-
/**
|
|
4
|
-
* Analyzes a set of jobs and calculates what should have been burned
|
|
5
|
-
* This function can be used for both live processing and backfill analysis
|
|
6
|
-
*/
|
|
7
|
-
export const analyzeBurnJobs = async (ctx, input, opts = {
|
|
8
|
-
perpetual: true,
|
|
9
|
-
}, log = consoleLogger) => {
|
|
10
|
-
const { jobs, params, decimals, pricedAt } = input;
|
|
11
|
-
// Get user grant spends
|
|
12
|
-
const userIds = jobs.reduce((acc, job) => {
|
|
13
|
-
if (job.userId) {
|
|
14
|
-
acc.add(job.userId);
|
|
15
|
-
}
|
|
16
|
-
return acc;
|
|
17
|
-
}, new Set());
|
|
18
|
-
// For analysis, we use the underlying db object directly
|
|
19
|
-
const userGrantSpends = (await Promise.all(Array.from(userIds).map(async (userId) => {
|
|
20
|
-
// Note: For backfill, we might need historical grant spend data
|
|
21
|
-
// This is a limitation we'll need to address
|
|
22
|
-
const currSpend = await ctx.pgV2.getCurrentUserGrantSpend(ctx.pgV2.db, // Use the underlying db object
|
|
23
|
-
{ userId }, log);
|
|
24
|
-
return { userId, currSpend };
|
|
25
|
-
}))).reduce((acc, us) => {
|
|
26
|
-
if (us.currSpend) {
|
|
27
|
-
acc[us.userId] = {
|
|
28
|
-
userGrantSpend: us.currSpend,
|
|
29
|
-
currAllot: us.currSpend.renderSpent,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return acc;
|
|
33
|
-
}, {});
|
|
34
|
-
// Get burn adjustments (for backfill, we might need historical data)
|
|
35
|
-
const burnAdjustments = await ctx.pgV2.getBurnAdjustments(ctx.pgV2.db, // Use the underlying db object
|
|
36
|
-
{ toFill: true }, log);
|
|
37
|
-
// Determine pricing date
|
|
38
|
-
const effectivePricedAt = pricedAt ||
|
|
39
|
-
calculateBurnAmounts({
|
|
40
|
-
jobs,
|
|
41
|
-
userGrantSpends,
|
|
42
|
-
burnAdjustments,
|
|
43
|
-
params,
|
|
44
|
-
decimals,
|
|
45
|
-
priceAtDate: 1,
|
|
46
|
-
eurToUSDC: 1, // Dummy value for date calculation
|
|
47
|
-
}, opts, log).pricedAt;
|
|
48
|
-
// Get historical prices
|
|
49
|
-
const price = await ctx.priceClient.getRenderPriceAtDate({
|
|
50
|
-
ts: effectivePricedAt,
|
|
51
|
-
});
|
|
52
|
-
const eurToUSDC = await ctx.priceClient.eurToUSDC(effectivePricedAt);
|
|
53
|
-
// Calculate burn amounts
|
|
54
|
-
const result = calculateBurnAmounts({
|
|
55
|
-
jobs,
|
|
56
|
-
userGrantSpends,
|
|
57
|
-
burnAdjustments,
|
|
58
|
-
params,
|
|
59
|
-
decimals,
|
|
60
|
-
priceAtDate: price,
|
|
61
|
-
eurToUSDC,
|
|
62
|
-
}, opts, log);
|
|
63
|
-
return {
|
|
64
|
-
...result,
|
|
65
|
-
price,
|
|
66
|
-
eurToUSDC,
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
export const compareBurnAmounts = (expected, actual) => {
|
|
70
|
-
const discrepancyTotalToBurn = actual.totalToBurn - expected.totalToBurn;
|
|
71
|
-
/* // Only return discrepancy if absolute total discrepancy is significant (> 10^8)
|
|
72
|
-
if (Math.abs(discrepancyTotalToBurn) <= Math.pow(10, 8)) {
|
|
73
|
-
return null
|
|
74
|
-
} */
|
|
75
|
-
return {
|
|
76
|
-
expectedRenderToBuyAndBurn: expected.renderToBuyAndBurn,
|
|
77
|
-
actualRenderToBuyAndBurn: actual.renderToBuyAndBurn,
|
|
78
|
-
expectedRenderToBurnFromEmissions: expected.renderToBurnFromEmissions,
|
|
79
|
-
actualRenderToBurnFromEmissions: actual.renderToBurnFromEmissions,
|
|
80
|
-
expectedTotalToBurn: expected.totalToBurn,
|
|
81
|
-
actualTotalToBurn: actual.totalToBurn,
|
|
82
|
-
discrepancyRenderToBuyAndBurn: actual.renderToBuyAndBurn - expected.renderToBuyAndBurn,
|
|
83
|
-
discrepancyRenderToBurnFromEmissions: actual.renderToBurnFromEmissions - expected.renderToBurnFromEmissions,
|
|
84
|
-
discrepancyTotalToBurn,
|
|
85
|
-
jobs: actual.jobs,
|
|
86
|
-
burnDate: actual.burnDate,
|
|
87
|
-
txSig: actual.txSig,
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
//# sourceMappingURL=burnAnalysis.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"burnAnalysis.js","sourceRoot":"","sources":["../../../../src/burn/burnAnalysis.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,GAGrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAgB,aAAa,EAAE,MAAM,WAAW,CAAA;AAqBvD;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,GAAkB,EAClB,KAAwB,EACxB,OAEI;IACF,SAAS,EAAE,IAAI;CAChB,EACD,MAAoB,aAAa,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;SACpB;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,IAAI,GAAG,EAAU,CAAC,CAAA;IAErB,yDAAyD;IACzD,MAAM,eAAe,G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ACtB,CAAC,CAAA;IACF,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAA;IAEpE,yBAAyB;IACzB,MAAM,MAAM,GAAG,oBAAoB,CACjC;QACE,IAAI;QACJ,eAAe;QACf,eAAe;QACf,MAAM;QACN,QAAQ;QACR,WAAW,EAAE,KAAK;QAClB,SAAS;KACV,EACD,IAAI,EACJ,GAAG,CACJ,CAAA;IAED,OAAO;QACL,GAAG,MAAM;QACT,KAAK;QACL,SAAS;KACV,CAAA;AACH,CAAC,CAAA;AAoBD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,QAA4B,EAC5B,MAOC,EACuB,EAAE;IAC1B,MAAM,sBAAsB,GAAG,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAA;IAExE;;;QAGI;IAEJ,OAAO;QACL,0BAA0B,EAAE,QAAQ,CAAC,kBAAkB;QACvD,wBAAwB,EAAE,MAAM,CAAC,kBAAkB;QACnD,iCAAiC,EAAE,QAAQ,CAAC,yBAAyB;QACrE,+BAA+B,EAAE,MAAM,CAAC,yBAAyB;QACjE,mBAAmB,EAAE,QAAQ,CAAC,WAAW;QACzC,iBAAiB,EAAE,MAAM,CAAC,WAAW;QACrC,6BAA6B,EAC3B,MAAM,CAAC,kBAAkB,GAAG,QAAQ,CAAC,kBAAkB;QACzD,oCAAoC,EAClC,MAAM,CAAC,yBAAyB,GAAG,QAAQ,CAAC,yBAAyB;QACvE,sBAAsB;QACtB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { toBN } from '@render-foundation/spl-utils';
|
|
2
|
-
import { consoleLogger } from '../logger';
|
|
3
|
-
// Utility function copied from cron-server
|
|
4
|
-
export const batchFinishedAtMedian = (jobs) => {
|
|
5
|
-
const pricedAt = jobs.length % 2 == 0
|
|
6
|
-
? new Date(Math.trunc((Date.parse(jobs[jobs.length / 2].finishedAt) +
|
|
7
|
-
Date.parse(jobs[jobs.length / 2 - 1].finishedAt)) /
|
|
8
|
-
2))
|
|
9
|
-
: new Date(Date.parse(jobs[Math.floor(jobs.length / 2)].finishedAt));
|
|
10
|
-
return pricedAt;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Pure function that calculates burn amounts without side effects
|
|
14
|
-
* This is the core logic extracted from consumeIncrBuyAndBurnRenderPG
|
|
15
|
-
*/
|
|
16
|
-
export const calculateBurnAmounts = (input, opts = {
|
|
17
|
-
perpetual: true,
|
|
18
|
-
}, log = consoleLogger) => {
|
|
19
|
-
const { jobs, userGrantSpends, burnAdjustments, params, decimals, priceAtDate, eurToUSDC, } = input;
|
|
20
|
-
// Apply grant/buy split logic to jobs
|
|
21
|
-
const processedJobs = jobs.map((j) => {
|
|
22
|
-
const { buyRenderAmt, grantRenderAmt, ...rest } = j;
|
|
23
|
-
return rest;
|
|
24
|
-
}); // Deep copy to avoid mutations
|
|
25
|
-
for (const j of processedJobs) {
|
|
26
|
-
const userGrantSpend = userGrantSpends[j.userId];
|
|
27
|
-
if (userGrantSpend) {
|
|
28
|
-
if (opts.perpetual ||
|
|
29
|
-
userGrantSpend.userGrantSpend.perpetual ||
|
|
30
|
-
j.rndrUsed <= userGrantSpend.currAllot) {
|
|
31
|
-
j.grantRenderAmt = Number(j.rndrUsed);
|
|
32
|
-
log.debug(`job ${j.id} grant split: ${j.rndrUsed}`);
|
|
33
|
-
userGrantSpend.currAllot -= BigInt(j.rndrUsed);
|
|
34
|
-
}
|
|
35
|
-
else if (userGrantSpend.currAllot <= BigInt(0)) {
|
|
36
|
-
log.debug(`job ${j.id} buy split: ${j.rndrUsed}`);
|
|
37
|
-
j.buyRenderAmt = Number(j.rndrUsed);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
log.debug(`job ${j.id} buy + grant split: ${j.rndrUsed} grant: ${Number(userGrantSpend.currAllot)} buy: ${Number(j.rndrUsed) - Number(userGrantSpend.currAllot)}`);
|
|
41
|
-
j.grantRenderAmt = Number(userGrantSpend.currAllot);
|
|
42
|
-
j.buyRenderAmt = Number(j.rndrUsed) - Number(userGrantSpend.currAllot);
|
|
43
|
-
userGrantSpend.currAllot = BigInt(0);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
log.debug(`job ${j.id} no grant split: ${j.rndrUsed}`);
|
|
48
|
-
j.buyRenderAmt = Number(j.rndrUsed);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const totalRenderUsed = processedJobs.reduce((tot, job) => tot + Number(job.rndrUsed.toString()), 0);
|
|
52
|
-
log.debug(`jobs buy + grant split: ${JSON.stringify(processedJobs)}`);
|
|
53
|
-
// Check minimum threshold
|
|
54
|
-
if (totalRenderUsed < toBN(params.minTotalRndrThreshold, decimals).toNumber()) {
|
|
55
|
-
throw new Error(`totalRenderUsed ${totalRenderUsed / Math.pow(10, decimals)} < total threshold ${params.minTotalRndrThreshold}`);
|
|
56
|
-
}
|
|
57
|
-
const totalRenderBuyAndBurn = processedJobs.reduce((tot, job) => tot + Number(job.buyRenderAmt ?? 0), 0);
|
|
58
|
-
const totalRender = processedJobs.reduce((tot, job) => tot + Number(job.rndrUsed.toString()), 0);
|
|
59
|
-
log.debug(`Burn calculation inputs:`);
|
|
60
|
-
log.debug(` totalRenderUsed: ${totalRenderUsed}`);
|
|
61
|
-
log.debug(` totalRenderBuyAndBurn: ${totalRenderBuyAndBurn}`);
|
|
62
|
-
log.debug(` totalRender: ${totalRender}`);
|
|
63
|
-
log.debug(` priceAtDate: ${priceAtDate}`);
|
|
64
|
-
log.debug(` eurToUSDC: ${eurToUSDC}`);
|
|
65
|
-
const pricedAt = batchFinishedAtMedian(processedJobs.map((job) => ({
|
|
66
|
-
finishedAt: job.completedAt.toISOString(),
|
|
67
|
-
jobId: job.id,
|
|
68
|
-
rndrUsed: Number(job.rndrUsed.toString()),
|
|
69
|
-
})));
|
|
70
|
-
// Core burn calculation logic
|
|
71
|
-
const toBurn = Math.trunc((totalRender / priceAtDate / 4) * 0.95 * eurToUSDC);
|
|
72
|
-
let renderToBuyAndBurn = Math.trunc((totalRenderBuyAndBurn / totalRender) * toBurn);
|
|
73
|
-
const origRenderToBuyAndBurn = renderToBuyAndBurn;
|
|
74
|
-
log.debug(`Core burn calculation:`);
|
|
75
|
-
log.debug(` toBurn: ${toBurn}`);
|
|
76
|
-
log.debug(` renderToBuyAndBurn: ${renderToBuyAndBurn}`);
|
|
77
|
-
log.debug(` origRenderToBuyAndBurn: ${origRenderToBuyAndBurn}`);
|
|
78
|
-
let burnAdjustmentId = undefined;
|
|
79
|
-
// Apply burn adjustments
|
|
80
|
-
if (burnAdjustments.length > 0) {
|
|
81
|
-
const adjustment = burnAdjustments[0];
|
|
82
|
-
burnAdjustmentId = adjustment.id;
|
|
83
|
-
const adjLeft = adjustment.downAdjToBurn - adjustment.adjusted;
|
|
84
|
-
const minBurnRndrThreshold = toBN(params.minBurnRndrThreshold, decimals).toNumber();
|
|
85
|
-
const available = renderToBuyAndBurn - minBurnRndrThreshold;
|
|
86
|
-
if (adjLeft > available) {
|
|
87
|
-
renderToBuyAndBurn = minBurnRndrThreshold;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
renderToBuyAndBurn -= adjLeft;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// Validate burn thresholds
|
|
94
|
-
const toBuyAndBurnUI = renderToBuyAndBurn / Math.pow(10, decimals);
|
|
95
|
-
if (renderToBuyAndBurn != 0) {
|
|
96
|
-
if (toBuyAndBurnUI > params.maxBurnRndrThreshold) {
|
|
97
|
-
throw new Error(`buy and burn RENDER ${toBuyAndBurnUI} too high`);
|
|
98
|
-
}
|
|
99
|
-
if (toBuyAndBurnUI < params.minBurnRndrThreshold) {
|
|
100
|
-
throw new Error(`buy and burn RENDER ${toBuyAndBurnUI} too low < ${params.minBurnRndrThreshold}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const renderToBurnFromEmissions = toBurn - origRenderToBuyAndBurn;
|
|
104
|
-
const totalToBurn = renderToBuyAndBurn + renderToBurnFromEmissions;
|
|
105
|
-
log.debug(`Final burn calculation results:`);
|
|
106
|
-
log.debug(` renderToBuyAndBurn: ${renderToBuyAndBurn}`);
|
|
107
|
-
log.debug(` renderToBurnFromEmissions: ${renderToBurnFromEmissions}`);
|
|
108
|
-
log.debug(` totalToBurn: ${totalToBurn}`);
|
|
109
|
-
log.debug(` toBurn: ${toBurn}`);
|
|
110
|
-
return {
|
|
111
|
-
totalRenderUsed,
|
|
112
|
-
totalRenderBuyAndBurn,
|
|
113
|
-
totalRender,
|
|
114
|
-
renderToBuyAndBurn,
|
|
115
|
-
renderToBurnFromEmissions,
|
|
116
|
-
totalToBurn,
|
|
117
|
-
toBurn,
|
|
118
|
-
origRenderToBuyAndBurn,
|
|
119
|
-
burnAdjustmentId,
|
|
120
|
-
pricedAt,
|
|
121
|
-
processedJobs,
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
//# sourceMappingURL=burnCalculations.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"burnCalculations.js","sourceRoot":"","sources":["../../../../src/burn/burnCalculations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAA;AACnD,OAAO,EAAgB,aAAa,EAAE,MAAM,WAAW,CAAA;AAWvD,2CAA2C;AAC3C,MAAM,CAAC,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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AC1C;aAAM;YACL,kBAAkB,IAAI,OAAO,CAAA;SAC9B;KACF;IAED,2BAA2B;IAC3B,MAAM,cAAc,GAAG,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;IAElE,IAAI,kBAAkB,IAAI,CAAC,EAAE;QAC3B,IAAI,cAAc,GAAG,MAAM,CAAC,oBAAoB,EAAE;YAChD,MAAM,IAAI,KAAK,CAAC,uBAAuB,cAAc,WAAW,CAAC,CAAA;SAClE;QACD,IAAI,cAAc,GAAG,MAAM,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"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Job, PriceClient, DB } from '../index';
|
|
2
|
-
import { BurnCalculationResult, IncrBuyAndBurnParams } from './burnCalculations';
|
|
3
|
-
import { RenderLogger } from '../logger';
|
|
4
|
-
import { PgClient } from '../client/pg/v2Client';
|
|
5
|
-
export interface CronServerCtx {
|
|
6
|
-
pgV2: PgClient<DB>;
|
|
7
|
-
priceClient: PriceClient;
|
|
8
|
-
}
|
|
9
|
-
export interface BurnAnalysisInput {
|
|
10
|
-
jobs: Job[];
|
|
11
|
-
params: IncrBuyAndBurnParams;
|
|
12
|
-
decimals: number;
|
|
13
|
-
pricedAt?: Date;
|
|
14
|
-
}
|
|
15
|
-
export interface BurnAnalysisResult extends BurnCalculationResult {
|
|
16
|
-
price: number;
|
|
17
|
-
eurToUSDC: number;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Analyzes a set of jobs and calculates what should have been burned
|
|
21
|
-
* This function can be used for both live processing and backfill analysis
|
|
22
|
-
*/
|
|
23
|
-
export declare const analyzeBurnJobs: (ctx: CronServerCtx, input: BurnAnalysisInput, opts?: {
|
|
24
|
-
perpetual: boolean;
|
|
25
|
-
}, log?: RenderLogger) => Promise<BurnAnalysisResult>;
|
|
26
|
-
/**
|
|
27
|
-
* Compares actual burn data with expected burn calculations
|
|
28
|
-
*/
|
|
29
|
-
export interface BurnDiscrepancy {
|
|
30
|
-
expectedRenderToBuyAndBurn: number;
|
|
31
|
-
actualRenderToBuyAndBurn: number;
|
|
32
|
-
expectedRenderToBurnFromEmissions: number;
|
|
33
|
-
actualRenderToBurnFromEmissions: number;
|
|
34
|
-
expectedTotalToBurn: number;
|
|
35
|
-
actualTotalToBurn: number;
|
|
36
|
-
discrepancyRenderToBuyAndBurn: number;
|
|
37
|
-
discrepancyRenderToBurnFromEmissions: number;
|
|
38
|
-
discrepancyTotalToBurn: number;
|
|
39
|
-
jobs: Job[];
|
|
40
|
-
burnDate: Date;
|
|
41
|
-
txSig?: string;
|
|
42
|
-
}
|
|
43
|
-
export declare const compareBurnAmounts: (expected: BurnAnalysisResult, actual: {
|
|
44
|
-
renderToBuyAndBurn: number;
|
|
45
|
-
renderToBurnFromEmissions: number;
|
|
46
|
-
totalToBurn: number;
|
|
47
|
-
jobs: Job[];
|
|
48
|
-
burnDate: Date;
|
|
49
|
-
txSig?: string;
|
|
50
|
-
}) => BurnDiscrepancy | null;
|
|
51
|
-
//# sourceMappingURL=burnAnalysis.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"burnAnalysis.d.ts","sourceRoot":"","sources":["../../../../src/burn/burnAnalysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAyB,WAAW,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AACtE,OAAO,EAEL,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,YAAY,EAAiB,MAAM,WAAW,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAGhD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;IAClB,WAAW,EAAE,WAAW,CAAA;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,MAAM,EAAE,oBAAoB,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB;IAC/D,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,QACrB,aAAa,SACX,iBAAiB,SAClB;IACJ,SAAS,EAAE,OAAO,CAAA;CACnB,QAGI,YAAY,KAChB,QAAQ,kBAAkB,CAqF5B,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,0BAA0B,EAAE,MAAM,CAAA;IAClC,wBAAwB,EAAE,MAAM,CAAA;IAChC,iCAAiC,EAAE,MAAM,CAAA;IACzC,+BAA+B,EAAE,MAAM,CAAA;IACvC,mBAAmB,EAAE,MAAM,CAAA;IAC3B,iBAAiB,EAAE,MAAM,CAAA;IACzB,6BAA6B,EAAE,MAAM,CAAA;IACrC,oCAAoC,EAAE,MAAM,CAAA;IAC5C,sBAAsB,EAAE,MAAM,CAAA;IAC9B,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,QAAQ,EAAE,IAAI,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,kBAAkB,aACnB,kBAAkB,UACpB;IACN,kBAAkB,EAAE,MAAM,CAAA;IAC1B,yBAAyB,EAAE,MAAM,CAAA;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,QAAQ,EAAE,IAAI,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,KACA,eAAe,GAAG,IAwBpB,CAAA"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Job, CurrentUserGrantSpend } from '../index';
|
|
2
|
-
import { RenderLogger } from '../logger';
|
|
3
|
-
export interface IncrBuyAndBurnParams {
|
|
4
|
-
minTotalRndrThreshold: number;
|
|
5
|
-
maxTotalRndrThreshold: number;
|
|
6
|
-
minBurnRndrThreshold: number;
|
|
7
|
-
consumeJobsLimit: number;
|
|
8
|
-
maxBurnRndrThreshold: number;
|
|
9
|
-
slippageTolThresholds: Record<string, number>;
|
|
10
|
-
}
|
|
11
|
-
export declare const batchFinishedAtMedian: (jobs: {
|
|
12
|
-
finishedAt: string;
|
|
13
|
-
jobId: number;
|
|
14
|
-
rndrUsed: number;
|
|
15
|
-
}[]) => Date;
|
|
16
|
-
export interface BurnCalculationInput {
|
|
17
|
-
jobs: Job[];
|
|
18
|
-
userGrantSpends: Record<string, {
|
|
19
|
-
userGrantSpend: CurrentUserGrantSpend;
|
|
20
|
-
currAllot: bigint;
|
|
21
|
-
}>;
|
|
22
|
-
burnAdjustments: Array<{
|
|
23
|
-
id: number;
|
|
24
|
-
downAdjToBurn: number;
|
|
25
|
-
adjusted: number;
|
|
26
|
-
}>;
|
|
27
|
-
params: IncrBuyAndBurnParams;
|
|
28
|
-
decimals: number;
|
|
29
|
-
priceAtDate: number;
|
|
30
|
-
eurToUSDC: number;
|
|
31
|
-
}
|
|
32
|
-
export interface BurnCalculationResult {
|
|
33
|
-
totalRenderUsed: number;
|
|
34
|
-
totalRenderBuyAndBurn: number;
|
|
35
|
-
totalRender: number;
|
|
36
|
-
renderToBuyAndBurn: number;
|
|
37
|
-
renderToBurnFromEmissions: number;
|
|
38
|
-
totalToBurn: number;
|
|
39
|
-
toBurn: number;
|
|
40
|
-
origRenderToBuyAndBurn: number;
|
|
41
|
-
burnAdjustmentId?: number;
|
|
42
|
-
pricedAt: Date;
|
|
43
|
-
processedJobs: Job[];
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Pure function that calculates burn amounts without side effects
|
|
47
|
-
* This is the core logic extracted from consumeIncrBuyAndBurnRenderPG
|
|
48
|
-
*/
|
|
49
|
-
export declare const calculateBurnAmounts: (input: BurnCalculationInput, opts?: {
|
|
50
|
-
perpetual: boolean;
|
|
51
|
-
}, log?: RenderLogger) => BurnCalculationResult;
|
|
52
|
-
//# sourceMappingURL=burnCalculations.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"burnCalculations.d.ts","sourceRoot":"","sources":["../../../../src/burn/burnCalculations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAErD,OAAO,EAAE,YAAY,EAAiB,MAAM,WAAW,CAAA;AAEvD,MAAM,WAAW,oBAAoB;IACnC,qBAAqB,EAAE,MAAM,CAAA;IAC7B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;IACxB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,C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