@render-foundation/utils 0.0.234-beta.0 → 0.0.235
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/assertSecrets.js +1 -2
- package/lib/cjs/assertSecrets.js.map +1 -1
- package/lib/cjs/backfiller.js +16 -16
- package/lib/cjs/backfiller.js.map +1 -1
- package/lib/cjs/client/dispersed.js +4 -4
- package/lib/cjs/client/dispersed.js.map +1 -1
- package/lib/cjs/client/onchain.js +3 -3
- package/lib/cjs/client/onchain.js.map +1 -1
- package/lib/cjs/client/pg/base.js +7 -7
- package/lib/cjs/client/pg/base.js.map +1 -1
- package/lib/cjs/client/pg/v1.js +31 -31
- package/lib/cjs/client/pg/v1.js.map +1 -1
- package/lib/cjs/client/pg/v2Client.js +241 -168
- package/lib/cjs/client/pg/v2Client.js.map +1 -1
- package/lib/cjs/client/pg/viewClient.js +6 -6
- package/lib/cjs/client/pg/viewClient.js.map +1 -1
- package/lib/cjs/client/price.js +2 -2
- package/lib/cjs/client/price.js.map +1 -1
- package/lib/cjs/client/render.js +10 -10
- package/lib/cjs/client/render.js.map +1 -1
- package/lib/cjs/client/squads.js +20 -10
- package/lib/cjs/client/squads.js.map +1 -1
- package/lib/cjs/client/trade.js +15 -12
- package/lib/cjs/client/trade.js.map +1 -1
- package/lib/cjs/client/wormhole.js +19 -9
- package/lib/cjs/client/wormhole.js.map +1 -1
- package/lib/cjs/errorReporter.js +1 -1
- package/lib/cjs/errorReporter.js.map +1 -1
- package/lib/cjs/index.js +17 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/lib/esm/src/assertSecrets.js.map +1 -1
- package/lib/esm/src/backfiller.js.map +1 -1
- package/lib/esm/src/client/dispersed.js.map +1 -1
- package/lib/esm/src/client/onchain.js.map +1 -1
- package/lib/esm/src/client/pg/base.js.map +1 -1
- package/lib/esm/src/client/pg/v1.js.map +1 -1
- package/lib/esm/src/client/pg/v2Client.js +110 -56
- package/lib/esm/src/client/pg/v2Client.js.map +1 -1
- package/lib/esm/src/client/pg/viewClient.js.map +1 -1
- package/lib/esm/src/client/price.js.map +1 -1
- package/lib/esm/src/client/render.js.map +1 -1
- package/lib/esm/src/client/squads.js.map +1 -1
- package/lib/esm/src/client/trade.js +2 -2
- package/lib/esm/src/client/trade.js.map +1 -1
- package/lib/esm/src/client/wormhole.js.map +1 -1
- package/lib/esm/src/errorReporter.js.map +1 -1
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/src/backfiller.d.ts.map +1 -1
- package/lib/types/src/client/dispersed.d.ts.map +1 -1
- package/lib/types/src/client/onchain.d.ts +2 -1
- package/lib/types/src/client/onchain.d.ts.map +1 -1
- package/lib/types/src/client/pg/base.d.ts.map +1 -1
- package/lib/types/src/client/pg/v1.d.ts.map +1 -1
- package/lib/types/src/client/pg/v2Client.d.ts +48 -24
- package/lib/types/src/client/pg/v2Client.d.ts.map +1 -1
- package/lib/types/src/client/pg/viewClient.d.ts.map +1 -1
- package/lib/types/src/client/render.d.ts.map +1 -1
- package/lib/types/src/client/squads.d.ts.map +1 -1
- package/lib/types/src/client/trade.d.ts.map +1 -1
- package/lib/types/src/client/wormhole.d.ts +1 -1
- package/lib/types/src/client/wormhole.d.ts.map +1 -1
- package/lib/types/src/dbTypesV2.d.ts +11 -16
- package/lib/types/src/dbTypesV2.d.ts.map +1 -1
- package/lib/types/src/errorReporter.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,7 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
46
|
};
|
|
37
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.pgClient = exports.batchFinishedAtMedian = exports.DISPERSED_SETTLEMENT_TABLE = exports.GRANT_BURN_TABLE = exports.GRANT_BURN_ID_TABLE = exports.USER_GRANT_SPEND_TABLE = exports.CURRENT_USER_GRANT_SPEND_TABLE = exports.POLYGON_UPGRADE_TABLE = exports.ENTITY_EPOCH_INFO_TABLE = exports.
|
|
48
|
+
exports.pgClient = exports.batchFinishedAtMedian = exports.DISPERSED_SETTLEMENT_TABLE = exports.GRANT_BURN_TABLE = exports.GRANT_BURN_ID_TABLE = exports.USER_GRANT_SPEND_TABLE = exports.CURRENT_USER_GRANT_SPEND_TABLE = exports.POLYGON_UPGRADE_TABLE = exports.ENTITY_EPOCH_INFO_TABLE = exports.BURN_CORRECTION_TABLE = exports.NETWORK_REVENUE_TABLE = exports.BRIDGE_TRANSFER_TABLE = exports.BURN_TABLE = exports.JOB_TABLE = exports.JOB_ID_TABLE = exports.LIABILITY_ADJUSTMENT_BATCH_TABLE = exports.LIABILITY_ADJUSTMENT_TABLE = exports.LIABILITY_TABLE = exports.SOL_TRANSFER_TABLE = exports.ENTITY_TABLE = exports.MANUAL_BURN_TABLE = exports.EPOCH_TABLE = exports.SOL_TX_TABLE = void 0;
|
|
39
49
|
const kysely_1 = require("kysely");
|
|
40
50
|
const logger_1 = require("../../logger");
|
|
41
51
|
const pg_1 = require("pg");
|
|
@@ -54,8 +64,7 @@ exports.JOB_TABLE = 'job';
|
|
|
54
64
|
exports.BURN_TABLE = 'burn';
|
|
55
65
|
exports.BRIDGE_TRANSFER_TABLE = 'bridge_transfer';
|
|
56
66
|
exports.NETWORK_REVENUE_TABLE = 'network_revenue';
|
|
57
|
-
exports.
|
|
58
|
-
exports.TX_BURN_ADJUSTMENT_TABLE = 'tx_burn_adjustment';
|
|
67
|
+
exports.BURN_CORRECTION_TABLE = 'burn_correction';
|
|
59
68
|
exports.ENTITY_EPOCH_INFO_TABLE = 'entity_epoch_info';
|
|
60
69
|
exports.POLYGON_UPGRADE_TABLE = 'polygon_upgrade';
|
|
61
70
|
exports.CURRENT_USER_GRANT_SPEND_TABLE = 'current_user_grant_spend';
|
|
@@ -96,7 +105,7 @@ const pgClient = (config) => {
|
|
|
96
105
|
const db = new kysely_1.Kysely({
|
|
97
106
|
dialect,
|
|
98
107
|
});
|
|
99
|
-
const getOrInsertEntity = (
|
|
108
|
+
const getOrInsertEntity = (db_1, p_1, ...args_1) => __awaiter(void 0, [db_1, p_1, ...args_1], void 0, function* (db, p, log = logger_1.consoleLogger) {
|
|
100
109
|
const res = (yield db
|
|
101
110
|
.selectFrom(exports.ENTITY_TABLE)
|
|
102
111
|
.select('id')
|
|
@@ -117,7 +126,7 @@ const pgClient = (config) => {
|
|
|
117
126
|
log.debug(`inserted entity ${id}`);
|
|
118
127
|
return id;
|
|
119
128
|
});
|
|
120
|
-
const getOrInsertTx = (
|
|
129
|
+
const getOrInsertTx = (db_1, p_1, ...args_1) => __awaiter(void 0, [db_1, p_1, ...args_1], void 0, function* (db, p, log = logger_1.consoleLogger) {
|
|
121
130
|
const res = yield db
|
|
122
131
|
.selectFrom(exports.SOL_TX_TABLE)
|
|
123
132
|
.select('id')
|
|
@@ -139,7 +148,7 @@ const pgClient = (config) => {
|
|
|
139
148
|
log.debug(`inserted tx ${id}`);
|
|
140
149
|
return id;
|
|
141
150
|
});
|
|
142
|
-
const getOrInsertEpoch = (
|
|
151
|
+
const getOrInsertEpoch = (db_1, p_1, ...args_1) => __awaiter(void 0, [db_1, p_1, ...args_1], void 0, function* (db, p, log = logger_1.consoleLogger) {
|
|
143
152
|
const res = yield db
|
|
144
153
|
.selectFrom(exports.EPOCH_TABLE)
|
|
145
154
|
.select('id')
|
|
@@ -167,7 +176,7 @@ const pgClient = (config) => {
|
|
|
167
176
|
log.debug(`inserted epoch ${id}`);
|
|
168
177
|
return id;
|
|
169
178
|
});
|
|
170
|
-
const getCurrentUserGrantSpend = (
|
|
179
|
+
const getCurrentUserGrantSpend = (db_1, p_1, ...args_1) => __awaiter(void 0, [db_1, p_1, ...args_1], void 0, function* (db, p, log = logger_1.consoleLogger) {
|
|
171
180
|
var _a;
|
|
172
181
|
const res = yield db
|
|
173
182
|
.selectFrom(exports.CURRENT_USER_GRANT_SPEND_TABLE)
|
|
@@ -197,7 +206,7 @@ const pgClient = (config) => {
|
|
|
197
206
|
.executeTakeFirst());
|
|
198
207
|
log.info(`set ${res.numUpdatedRows} rows. channel: ${p.channel}, ui: ${p.uiEpochId} -> totalRndr ${totalRndr} `);
|
|
199
208
|
});
|
|
200
|
-
const fetchJobs1 = (
|
|
209
|
+
const fetchJobs1 = (db_1, f_1, ...args_1) => __awaiter(void 0, [db_1, f_1, ...args_1], void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
201
210
|
let q = db.selectFrom('job').selectAll();
|
|
202
211
|
//.where('job.burn_id', 'is not', null)
|
|
203
212
|
if (f.completedAtAfter) {
|
|
@@ -227,7 +236,7 @@ const pgClient = (config) => {
|
|
|
227
236
|
insertedAt: r.inserted_at,
|
|
228
237
|
}));
|
|
229
238
|
});
|
|
230
|
-
const fetchJobs2 = (
|
|
239
|
+
const fetchJobs2 = (db_1, f_1, ...args_1) => __awaiter(void 0, [db_1, f_1, ...args_1], void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
231
240
|
let q = db.selectFrom('job').selectAll();
|
|
232
241
|
//.where('job.burn_id', 'is not', null)
|
|
233
242
|
if (f.completedAtAfter) {
|
|
@@ -261,7 +270,7 @@ const pgClient = (config) => {
|
|
|
261
270
|
});
|
|
262
271
|
});
|
|
263
272
|
});
|
|
264
|
-
const createBridgeTransfers = (
|
|
273
|
+
const createBridgeTransfers = (db_1, bts_1, ...args_1) => __awaiter(void 0, [db_1, bts_1, ...args_1], void 0, function* (db, bts, log = logger_1.consoleLogger) {
|
|
265
274
|
const sequenceNumbers = [];
|
|
266
275
|
const dbEpochIds = [];
|
|
267
276
|
for (const bt of bts) {
|
|
@@ -305,7 +314,7 @@ const pgClient = (config) => {
|
|
|
305
314
|
}
|
|
306
315
|
return { sequenceNumbers: sequenceNumbers };
|
|
307
316
|
});
|
|
308
|
-
const createPayments = (
|
|
317
|
+
const createPayments = (db_1, ps_1, ...args_1) => __awaiter(void 0, [db_1, ps_1, ...args_1], void 0, function* (db, ps, log = logger_1.consoleLogger) {
|
|
309
318
|
const ids = [];
|
|
310
319
|
const epochDbIds = [];
|
|
311
320
|
for (const p of ps) {
|
|
@@ -402,18 +411,18 @@ const pgClient = (config) => {
|
|
|
402
411
|
rollback: () => { },
|
|
403
412
|
trx: db,
|
|
404
413
|
},
|
|
405
|
-
startTransaction(
|
|
406
|
-
return __awaiter(this,
|
|
414
|
+
startTransaction() {
|
|
415
|
+
return __awaiter(this, arguments, void 0, function* (log = logger_1.consoleLogger) {
|
|
407
416
|
return (0, base_2.begin)(db, log);
|
|
408
417
|
});
|
|
409
418
|
},
|
|
410
|
-
createPayments(
|
|
411
|
-
return __awaiter(this,
|
|
419
|
+
createPayments(db_1, ps_1) {
|
|
420
|
+
return __awaiter(this, arguments, void 0, function* (db, ps, log = logger_1.consoleLogger) {
|
|
412
421
|
return createPayments(db.trx, ps, log);
|
|
413
422
|
});
|
|
414
423
|
},
|
|
415
|
-
fetchTransfers(
|
|
416
|
-
return __awaiter(this,
|
|
424
|
+
fetchTransfers(db_1, f_1) {
|
|
425
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
417
426
|
let lastId = undefined;
|
|
418
427
|
if (f.cursor) {
|
|
419
428
|
lastId = atob(f.cursor);
|
|
@@ -469,8 +478,8 @@ const pgClient = (config) => {
|
|
|
469
478
|
};
|
|
470
479
|
});
|
|
471
480
|
},
|
|
472
|
-
fetchEpochs(
|
|
473
|
-
return __awaiter(this,
|
|
481
|
+
fetchEpochs(db_1, f_1) {
|
|
482
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
474
483
|
let q = db.trx.selectFrom(exports.EPOCH_TABLE).selectAll();
|
|
475
484
|
if (f.channels) {
|
|
476
485
|
q = q.where('channel', 'in', f.channels);
|
|
@@ -493,9 +502,9 @@ const pgClient = (config) => {
|
|
|
493
502
|
}));
|
|
494
503
|
});
|
|
495
504
|
},
|
|
496
|
-
fetchLiabilities(
|
|
497
|
-
|
|
498
|
-
|
|
505
|
+
fetchLiabilities(db_1, f_1) {
|
|
506
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
507
|
+
var _a;
|
|
499
508
|
let offset = 0;
|
|
500
509
|
let orderBy = (_a = f.orderBy) !== null && _a !== void 0 ? _a : 'epoch.ui,liability.id';
|
|
501
510
|
if (f.cursor) {
|
|
@@ -562,8 +571,8 @@ const pgClient = (config) => {
|
|
|
562
571
|
};
|
|
563
572
|
});
|
|
564
573
|
},
|
|
565
|
-
getLiabilitiesAndTransfers(
|
|
566
|
-
return __awaiter(this,
|
|
574
|
+
getLiabilitiesAndTransfers(f_1) {
|
|
575
|
+
return __awaiter(this, arguments, void 0, function* (f, log = logger_1.consoleLogger) {
|
|
567
576
|
let lq = db
|
|
568
577
|
.selectFrom(exports.LIABILITY_TABLE)
|
|
569
578
|
.selectAll()
|
|
@@ -624,9 +633,9 @@ const pgClient = (config) => {
|
|
|
624
633
|
return { transfers, liabilities, epochs: Object.values(epochs) };
|
|
625
634
|
});
|
|
626
635
|
},
|
|
627
|
-
getOutstanding(
|
|
628
|
-
|
|
629
|
-
|
|
636
|
+
getOutstanding(f_1) {
|
|
637
|
+
return __awaiter(this, arguments, void 0, function* (f, log = logger_1.consoleLogger) {
|
|
638
|
+
var _a, _b, _c, _d, _e;
|
|
630
639
|
log.info(`getting outstanding balances for ${(_a = f.channels) !== null && _a !== void 0 ? _a : '(no channels specified)'} epoch: ${(_b = f.startEpochId.id) !== null && _b !== void 0 ? _b : '(no epoch specified)'}`);
|
|
631
640
|
let epochUi;
|
|
632
641
|
let epochEndTime;
|
|
@@ -762,8 +771,8 @@ const pgClient = (config) => {
|
|
|
762
771
|
return out;
|
|
763
772
|
});
|
|
764
773
|
},
|
|
765
|
-
addLiabilityAdjustments(
|
|
766
|
-
return __awaiter(this,
|
|
774
|
+
addLiabilityAdjustments(batch_1, rows_1) {
|
|
775
|
+
return __awaiter(this, arguments, void 0, function* (batch, rows, log = logger_1.consoleLogger) {
|
|
767
776
|
return yield db.transaction().execute((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
768
777
|
var _a;
|
|
769
778
|
// Upsert the batch by its label (idempotent re-runs; label is the run identity).
|
|
@@ -815,9 +824,9 @@ const pgClient = (config) => {
|
|
|
815
824
|
}));
|
|
816
825
|
});
|
|
817
826
|
},
|
|
818
|
-
fetchNodeOperatorEpoch(
|
|
819
|
-
|
|
820
|
-
|
|
827
|
+
fetchNodeOperatorEpoch(epochId_1) {
|
|
828
|
+
return __awaiter(this, arguments, void 0, function* (epochId, log = logger_1.consoleLogger) {
|
|
829
|
+
var _a;
|
|
821
830
|
const q = db
|
|
822
831
|
.selectFrom(exports.JOB_ID_TABLE)
|
|
823
832
|
.innerJoin(exports.EPOCH_TABLE, 'epoch.id', 'job_id.epoch_id')
|
|
@@ -867,14 +876,14 @@ const pgClient = (config) => {
|
|
|
867
876
|
};
|
|
868
877
|
});
|
|
869
878
|
},
|
|
870
|
-
insertEpoch(
|
|
871
|
-
return __awaiter(this,
|
|
879
|
+
insertEpoch(db_1, epoch_1) {
|
|
880
|
+
return __awaiter(this, arguments, void 0, function* (db, epoch, log = logger_1.consoleLogger) {
|
|
872
881
|
yield getOrInsertEpoch(db.trx, Object.assign(Object.assign({}, epoch), { uiEpochId: epoch.ui }), log);
|
|
873
882
|
});
|
|
874
883
|
},
|
|
875
|
-
getEpoch(
|
|
876
|
-
|
|
877
|
-
|
|
884
|
+
getEpoch(f_1) {
|
|
885
|
+
return __awaiter(this, arguments, void 0, function* (f, log = logger_1.consoleLogger) {
|
|
886
|
+
var _a;
|
|
878
887
|
const now = new Date(Date.now());
|
|
879
888
|
try {
|
|
880
889
|
let q = db
|
|
@@ -912,9 +921,9 @@ const pgClient = (config) => {
|
|
|
912
921
|
}
|
|
913
922
|
});
|
|
914
923
|
},
|
|
915
|
-
getLatestNodeOperatorEpoch(
|
|
916
|
-
|
|
917
|
-
|
|
924
|
+
getLatestNodeOperatorEpoch(f_1) {
|
|
925
|
+
return __awaiter(this, arguments, void 0, function* (f, log = logger_1.consoleLogger) {
|
|
926
|
+
var _a;
|
|
918
927
|
const now = new Date(Date.now());
|
|
919
928
|
try {
|
|
920
929
|
let q = db
|
|
@@ -954,8 +963,8 @@ const pgClient = (config) => {
|
|
|
954
963
|
}
|
|
955
964
|
});
|
|
956
965
|
},
|
|
957
|
-
saveNodeOperatorEpoch(
|
|
958
|
-
return __awaiter(this,
|
|
966
|
+
saveNodeOperatorEpoch(epochId_1, liabilities_1, jobIds_1, totalRndr_1) {
|
|
967
|
+
return __awaiter(this, arguments, void 0, function* (epochId, liabilities, jobIds, totalRndr, log = logger_1.consoleLogger) {
|
|
959
968
|
yield db
|
|
960
969
|
.transaction()
|
|
961
970
|
.setIsolationLevel('repeatable read')
|
|
@@ -991,8 +1000,8 @@ const pgClient = (config) => {
|
|
|
991
1000
|
return;
|
|
992
1001
|
});
|
|
993
1002
|
},
|
|
994
|
-
produceBurnedJobs(
|
|
995
|
-
return __awaiter(this,
|
|
1003
|
+
produceBurnedJobs(jobs_1) {
|
|
1004
|
+
return __awaiter(this, arguments, void 0, function* (jobs, log = logger_1.consoleLogger) {
|
|
996
1005
|
yield db.transaction().execute((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
997
1006
|
var _a;
|
|
998
1007
|
let num = BigInt(0);
|
|
@@ -1015,9 +1024,9 @@ const pgClient = (config) => {
|
|
|
1015
1024
|
}));
|
|
1016
1025
|
});
|
|
1017
1026
|
},
|
|
1018
|
-
markJobsBurntWithGrant(
|
|
1019
|
-
|
|
1020
|
-
|
|
1027
|
+
markJobsBurntWithGrant(db_1, p_1) {
|
|
1028
|
+
return __awaiter(this, arguments, void 0, function* (db, p, log = logger_1.consoleLogger) {
|
|
1029
|
+
var _a;
|
|
1021
1030
|
const solTxId = yield getOrInsertTx(db.trx, { sig: p.tx.sig, executedAt: p.tx.executedAt }, log);
|
|
1022
1031
|
const { id } = yield db.trx
|
|
1023
1032
|
.insertInto(exports.GRANT_BURN_TABLE)
|
|
@@ -1048,9 +1057,9 @@ const pgClient = (config) => {
|
|
|
1048
1057
|
return;
|
|
1049
1058
|
});
|
|
1050
1059
|
},
|
|
1051
|
-
insertGrantSpend(
|
|
1052
|
-
|
|
1053
|
-
|
|
1060
|
+
insertGrantSpend(db_1, p_1) {
|
|
1061
|
+
return __awaiter(this, arguments, void 0, function* (db, p, log = logger_1.consoleLogger) {
|
|
1062
|
+
var _a, _b, _c;
|
|
1054
1063
|
const existing = yield getCurrentUserGrantSpend(db.trx, { userId: p.userId }, log);
|
|
1055
1064
|
const diff = {
|
|
1056
1065
|
render_spent: ((_a = existing === null || existing === void 0 ? void 0 : existing.renderSpent) !== null && _a !== void 0 ? _a : BigInt(0)) + p.renderSpentDelta,
|
|
@@ -1115,9 +1124,9 @@ const pgClient = (config) => {
|
|
|
1115
1124
|
}
|
|
1116
1125
|
});
|
|
1117
1126
|
},
|
|
1118
|
-
markJobsBurnt(
|
|
1119
|
-
|
|
1120
|
-
|
|
1127
|
+
markJobsBurnt(trx_1, p_1) {
|
|
1128
|
+
return __awaiter(this, arguments, void 0, function* (trx, p, log = logger_1.consoleLogger) {
|
|
1129
|
+
var _a, _b;
|
|
1121
1130
|
if (!p.buyBurn && !p.grantBurn) {
|
|
1122
1131
|
throw new Error('no buyBurn or grantBurn');
|
|
1123
1132
|
}
|
|
@@ -1125,7 +1134,7 @@ const pgClient = (config) => {
|
|
|
1125
1134
|
let buyBurnId;
|
|
1126
1135
|
let grantBurnId;
|
|
1127
1136
|
if (p.buyBurn) {
|
|
1128
|
-
const { burned, usdcSpent, eurToUsdc, renderToUsdc, quoteAmt, tags,
|
|
1137
|
+
const { burned, usdcSpent, eurToUsdc, renderToUsdc, quoteAmt, tags, downCorrectionId, escrowCorrectionId, toBurn, fromEscrowUsdc, } = p.buyBurn;
|
|
1129
1138
|
let pricedAt = p.buyBurn.pricedAt;
|
|
1130
1139
|
if (!pricedAt) {
|
|
1131
1140
|
const jobs = yield fetchJobs1(trx.trx, { ids: p.jobs.map((j) => String(j.id)) }, log);
|
|
@@ -1144,8 +1153,8 @@ const pgClient = (config) => {
|
|
|
1144
1153
|
quote_amt: quoteAmt,
|
|
1145
1154
|
burned: burned,
|
|
1146
1155
|
tags: tags.join(','),
|
|
1147
|
-
|
|
1148
|
-
|
|
1156
|
+
down_correction_id: downCorrectionId,
|
|
1157
|
+
escrow_correction_id: escrowCorrectionId,
|
|
1149
1158
|
to_burn: toBurn,
|
|
1150
1159
|
from_escrow_usdc: fromEscrowUsdc !== null && fromEscrowUsdc !== void 0 ? fromEscrowUsdc : 0,
|
|
1151
1160
|
};
|
|
@@ -1218,8 +1227,8 @@ const pgClient = (config) => {
|
|
|
1218
1227
|
return { grantBurnId, buyBurnId };
|
|
1219
1228
|
});
|
|
1220
1229
|
},
|
|
1221
|
-
markJobsBurned(
|
|
1222
|
-
return __awaiter(this,
|
|
1230
|
+
markJobsBurned(trx_1, p_1) {
|
|
1231
|
+
return __awaiter(this, arguments, void 0, function* (trx, p, log = logger_1.consoleLogger) {
|
|
1223
1232
|
let { markedAt, solTx } = p;
|
|
1224
1233
|
let res = yield trx.trx
|
|
1225
1234
|
.updateTable(exports.BURN_TABLE)
|
|
@@ -1243,8 +1252,8 @@ const pgClient = (config) => {
|
|
|
1243
1252
|
}
|
|
1244
1253
|
});
|
|
1245
1254
|
},
|
|
1246
|
-
consumeAndLockBurnJobs(
|
|
1247
|
-
return __awaiter(this,
|
|
1255
|
+
consumeAndLockBurnJobs(limit_1, lowerRndrThreshold_1, upperRndrThreshold_1) {
|
|
1256
|
+
return __awaiter(this, arguments, void 0, function* (limit, lowerRndrThreshold, upperRndrThreshold, log = logger_1.consoleLogger) {
|
|
1248
1257
|
const trx = yield (0, base_2.begin)(db, log);
|
|
1249
1258
|
const q = trx.trx
|
|
1250
1259
|
.selectFrom(trx.trx
|
|
@@ -1351,9 +1360,9 @@ const pgClient = (config) => {
|
|
|
1351
1360
|
};
|
|
1352
1361
|
});
|
|
1353
1362
|
},
|
|
1354
|
-
incrBuyBurnMetrics(
|
|
1355
|
-
|
|
1356
|
-
|
|
1363
|
+
incrBuyBurnMetrics() {
|
|
1364
|
+
return __awaiter(this, arguments, void 0, function* (log = logger_1.consoleLogger) {
|
|
1365
|
+
var _a;
|
|
1357
1366
|
const res = yield db
|
|
1358
1367
|
.selectFrom(exports.JOB_TABLE)
|
|
1359
1368
|
.select('inserted_at')
|
|
@@ -1370,9 +1379,9 @@ const pgClient = (config) => {
|
|
|
1370
1379
|
};
|
|
1371
1380
|
});
|
|
1372
1381
|
},
|
|
1373
|
-
fetchBurns(
|
|
1374
|
-
|
|
1375
|
-
|
|
1382
|
+
fetchBurns(db_1, f_1) {
|
|
1383
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
1384
|
+
var _a, _b;
|
|
1376
1385
|
let q = db.trx
|
|
1377
1386
|
.selectFrom('burn')
|
|
1378
1387
|
.selectAll('burn')
|
|
@@ -1441,9 +1450,9 @@ const pgClient = (config) => {
|
|
|
1441
1450
|
return burns;
|
|
1442
1451
|
});
|
|
1443
1452
|
},
|
|
1444
|
-
fetchBurnsAndGrants(
|
|
1445
|
-
|
|
1446
|
-
|
|
1453
|
+
fetchBurnsAndGrants(db_1, f_1) {
|
|
1454
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
1455
|
+
var _a, _b;
|
|
1447
1456
|
// Build a unified query to get all transactions with both buy burns and grant burns
|
|
1448
1457
|
let baseQuery = db.trx
|
|
1449
1458
|
.selectFrom('sol_tx')
|
|
@@ -1581,13 +1590,13 @@ const pgClient = (config) => {
|
|
|
1581
1590
|
return groupedBurns;
|
|
1582
1591
|
});
|
|
1583
1592
|
},
|
|
1584
|
-
createBridgeTransfers(
|
|
1585
|
-
return __awaiter(this,
|
|
1593
|
+
createBridgeTransfers(db_1, bts_1) {
|
|
1594
|
+
return __awaiter(this, arguments, void 0, function* (db, bts, log = logger_1.consoleLogger) {
|
|
1586
1595
|
return createBridgeTransfers(db.trx, bts, log);
|
|
1587
1596
|
});
|
|
1588
1597
|
},
|
|
1589
|
-
getBridgeTransfers(
|
|
1590
|
-
return __awaiter(this,
|
|
1598
|
+
getBridgeTransfers(_a) {
|
|
1599
|
+
return __awaiter(this, arguments, void 0, function* ({ solKey, page, }, log = logger_1.consoleLogger) {
|
|
1591
1600
|
let q = db
|
|
1592
1601
|
.selectFrom(exports.BRIDGE_TRANSFER_TABLE)
|
|
1593
1602
|
.innerJoin(exports.EPOCH_TABLE, 'epoch.id', 'bridge_transfer.epoch_id')
|
|
@@ -1664,8 +1673,8 @@ const pgClient = (config) => {
|
|
|
1664
1673
|
});
|
|
1665
1674
|
},
|
|
1666
1675
|
getTotalBurned(db) {
|
|
1667
|
-
var _a, _b;
|
|
1668
1676
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1677
|
+
var _a, _b;
|
|
1669
1678
|
const total = yield db.trx
|
|
1670
1679
|
.selectFrom('burn')
|
|
1671
1680
|
.select(({ fn }) => fn.sum('burned').as('total_burned'))
|
|
@@ -1673,8 +1682,8 @@ const pgClient = (config) => {
|
|
|
1673
1682
|
return BigInt((_b = (_a = total[0]) === null || _a === void 0 ? void 0 : _a.total_burned) !== null && _b !== void 0 ? _b : 0);
|
|
1674
1683
|
});
|
|
1675
1684
|
},
|
|
1676
|
-
insertBurn(
|
|
1677
|
-
return __awaiter(this,
|
|
1685
|
+
insertBurn(p_1) {
|
|
1686
|
+
return __awaiter(this, arguments, void 0, function* (p, log = logger_1.consoleLogger) {
|
|
1678
1687
|
yield db.transaction().execute((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
1679
1688
|
var _a;
|
|
1680
1689
|
const solTxId = yield getOrInsertTx(trx, { sig: p.solTx, executedAt: p.executedAt }, log);
|
|
@@ -1711,9 +1720,9 @@ const pgClient = (config) => {
|
|
|
1711
1720
|
}));
|
|
1712
1721
|
});
|
|
1713
1722
|
},
|
|
1714
|
-
insertDispersedOutbox(
|
|
1715
|
-
|
|
1716
|
-
|
|
1723
|
+
insertDispersedOutbox(p_1) {
|
|
1724
|
+
return __awaiter(this, arguments, void 0, function* (p, log = logger_1.consoleLogger) {
|
|
1725
|
+
var _a, _b, _c;
|
|
1717
1726
|
const res = yield db
|
|
1718
1727
|
.insertInto(exports.DISPERSED_SETTLEMENT_TABLE)
|
|
1719
1728
|
.values({
|
|
@@ -1725,14 +1734,15 @@ const pgClient = (config) => {
|
|
|
1725
1734
|
executed_at: p.executedAt,
|
|
1726
1735
|
eur_render: (_a = p.eurRender) !== null && _a !== void 0 ? _a : null,
|
|
1727
1736
|
last_valid_block_height: (_b = p.lastValidBlockHeight) !== null && _b !== void 0 ? _b : null,
|
|
1737
|
+
usdc_spent: (_c = p.usdcSpent) !== null && _c !== void 0 ? _c : null,
|
|
1728
1738
|
})
|
|
1729
1739
|
.onConflict((oc) => oc.column('tx_signature').doNothing())
|
|
1730
1740
|
.executeTakeFirst();
|
|
1731
1741
|
log.debug(`dispersed outbox tx ${p.txSignature}: ${res.numInsertedOrUpdatedRows} row(s)`);
|
|
1732
1742
|
});
|
|
1733
1743
|
},
|
|
1734
|
-
markDispersedSettled(
|
|
1735
|
-
return __awaiter(this,
|
|
1744
|
+
markDispersedSettled(txSignature_1, p_1) {
|
|
1745
|
+
return __awaiter(this, arguments, void 0, function* (txSignature, p, log = logger_1.consoleLogger) {
|
|
1736
1746
|
yield db
|
|
1737
1747
|
.updateTable(exports.DISPERSED_SETTLEMENT_TABLE)
|
|
1738
1748
|
.set({ settled_at: new Date(), idempotent_replay: p.idempotentReplay })
|
|
@@ -1741,8 +1751,8 @@ const pgClient = (config) => {
|
|
|
1741
1751
|
log.debug(`dispersed settled tx ${txSignature}`);
|
|
1742
1752
|
});
|
|
1743
1753
|
},
|
|
1744
|
-
getUnsettledDispersed(
|
|
1745
|
-
return __awaiter(this,
|
|
1754
|
+
getUnsettledDispersed() {
|
|
1755
|
+
return __awaiter(this, arguments, void 0, function* (log = logger_1.consoleLogger) {
|
|
1746
1756
|
const rows = yield db
|
|
1747
1757
|
.selectFrom(exports.DISPERSED_SETTLEMENT_TABLE)
|
|
1748
1758
|
.selectAll()
|
|
@@ -1750,7 +1760,7 @@ const pgClient = (config) => {
|
|
|
1750
1760
|
.execute();
|
|
1751
1761
|
log.debug(`dispersed outbox: ${rows.length} unsettled`);
|
|
1752
1762
|
return rows.map((r) => {
|
|
1753
|
-
var _a;
|
|
1763
|
+
var _a, _b;
|
|
1754
1764
|
return ({
|
|
1755
1765
|
txSignature: r.tx_signature,
|
|
1756
1766
|
claimUuid: r.claim_uuid,
|
|
@@ -1759,6 +1769,7 @@ const pgClient = (config) => {
|
|
|
1759
1769
|
burnedAmount: r.burned_amount,
|
|
1760
1770
|
executedAt: r.executed_at,
|
|
1761
1771
|
eurRender: (_a = r.eur_render) !== null && _a !== void 0 ? _a : undefined,
|
|
1772
|
+
usdcSpent: (_b = r.usdc_spent) !== null && _b !== void 0 ? _b : undefined,
|
|
1762
1773
|
// int8 comes back as a string from pg; block heights are well within JS safe-integer range.
|
|
1763
1774
|
lastValidBlockHeight: r.last_valid_block_height != null
|
|
1764
1775
|
? Number(r.last_valid_block_height)
|
|
@@ -1767,8 +1778,8 @@ const pgClient = (config) => {
|
|
|
1767
1778
|
});
|
|
1768
1779
|
});
|
|
1769
1780
|
},
|
|
1770
|
-
voidDispersedOutbox(
|
|
1771
|
-
return __awaiter(this,
|
|
1781
|
+
voidDispersedOutbox(txSignature_1) {
|
|
1782
|
+
return __awaiter(this, arguments, void 0, function* (txSignature, log = logger_1.consoleLogger) {
|
|
1772
1783
|
const res = yield db
|
|
1773
1784
|
.deleteFrom(exports.DISPERSED_SETTLEMENT_TABLE)
|
|
1774
1785
|
.where('tx_signature', '=', txSignature)
|
|
@@ -1778,18 +1789,91 @@ const pgClient = (config) => {
|
|
|
1778
1789
|
log.debug(`dispersed outbox void tx ${txSignature}: ${res.numDeletedRows} row(s)`);
|
|
1779
1790
|
});
|
|
1780
1791
|
},
|
|
1781
|
-
|
|
1782
|
-
return __awaiter(this,
|
|
1792
|
+
fetchDispersedSettlements(f_1) {
|
|
1793
|
+
return __awaiter(this, arguments, void 0, function* (f, _log = logger_1.consoleLogger) {
|
|
1794
|
+
var _a;
|
|
1795
|
+
let q = db
|
|
1796
|
+
.selectFrom(exports.DISPERSED_SETTLEMENT_TABLE)
|
|
1797
|
+
// Settled burns only — pending (un-landed) outbox rows aren't real, completed burns.
|
|
1798
|
+
.where('settled_at', 'is not', null);
|
|
1799
|
+
if (f.settledAfter)
|
|
1800
|
+
q = q.where('settled_at', '>=', f.settledAfter);
|
|
1801
|
+
if (f.settledBefore)
|
|
1802
|
+
q = q.where('settled_at', '<', f.settledBefore);
|
|
1803
|
+
const rows = yield q
|
|
1804
|
+
.select([
|
|
1805
|
+
'tx_signature',
|
|
1806
|
+
'claim_uuid',
|
|
1807
|
+
'obligation_uuids',
|
|
1808
|
+
'settled_amount',
|
|
1809
|
+
'burned_amount',
|
|
1810
|
+
'usdc_spent',
|
|
1811
|
+
'eur_render',
|
|
1812
|
+
'executed_at',
|
|
1813
|
+
'settled_at',
|
|
1814
|
+
])
|
|
1815
|
+
.orderBy('settled_at', 'desc')
|
|
1816
|
+
.limit((_a = f.limit) !== null && _a !== void 0 ? _a : 500)
|
|
1817
|
+
.execute();
|
|
1818
|
+
return rows.map((r) => {
|
|
1819
|
+
var _a, _b;
|
|
1820
|
+
return ({
|
|
1821
|
+
txSignature: r.tx_signature,
|
|
1822
|
+
claimUuid: r.claim_uuid,
|
|
1823
|
+
obligationUuids: r.obligation_uuids,
|
|
1824
|
+
settledAmount: r.settled_amount,
|
|
1825
|
+
burnedAmount: r.burned_amount,
|
|
1826
|
+
usdcSpent: (_a = r.usdc_spent) !== null && _a !== void 0 ? _a : null,
|
|
1827
|
+
eurRender: (_b = r.eur_render) !== null && _b !== void 0 ? _b : null,
|
|
1828
|
+
executedAt: r.executed_at,
|
|
1829
|
+
settledAt: r.settled_at,
|
|
1830
|
+
});
|
|
1831
|
+
});
|
|
1832
|
+
});
|
|
1833
|
+
},
|
|
1834
|
+
fetchDispersedMonthlyStats(f_1) {
|
|
1835
|
+
return __awaiter(this, arguments, void 0, function* (f, _log = logger_1.consoleLogger) {
|
|
1836
|
+
let q = db
|
|
1837
|
+
.selectFrom(exports.DISPERSED_SETTLEMENT_TABLE)
|
|
1838
|
+
.where('settled_at', 'is not', null);
|
|
1839
|
+
if (f.settledAfter)
|
|
1840
|
+
q = q.where('settled_at', '>=', f.settledAfter);
|
|
1841
|
+
if (f.settledBefore)
|
|
1842
|
+
q = q.where('settled_at', '<', f.settledBefore);
|
|
1843
|
+
const rows = yield q
|
|
1844
|
+
.select([
|
|
1845
|
+
// Bucket by UTC calendar month of settlement.
|
|
1846
|
+
(0, kysely_1.sql) `date_trunc('month', settled_at at time zone 'UTC')`.as('month'),
|
|
1847
|
+
(0, kysely_1.sql) `coalesce(sum(settled_amount), 0)::text`.as('settled_eur'),
|
|
1848
|
+
// usdc_spent is NULL for pre-migration-39 burns; sum() skips NULLs so they simply don't count.
|
|
1849
|
+
(0, kysely_1.sql) `coalesce(sum(usdc_spent), 0)::text`.as('usdc_spent'),
|
|
1850
|
+
(0, kysely_1.sql) `coalesce(sum(burned_amount), 0)::text`.as('render_burned'),
|
|
1851
|
+
(0, kysely_1.sql) `count(*)::text`.as('burn_count'),
|
|
1852
|
+
])
|
|
1853
|
+
.groupBy('month')
|
|
1854
|
+
.orderBy('month', 'asc')
|
|
1855
|
+
.execute();
|
|
1856
|
+
return rows.map((r) => ({
|
|
1857
|
+
month: r.month,
|
|
1858
|
+
settledEur: r.settled_eur,
|
|
1859
|
+
usdcSpent: r.usdc_spent,
|
|
1860
|
+
renderBurned: r.render_burned,
|
|
1861
|
+
burnCount: Number(r.burn_count),
|
|
1862
|
+
}));
|
|
1863
|
+
});
|
|
1864
|
+
},
|
|
1865
|
+
fetchJobs(db_1, f_1) {
|
|
1866
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
1783
1867
|
return yield fetchJobs1(db.trx, f, log);
|
|
1784
1868
|
});
|
|
1785
1869
|
},
|
|
1786
|
-
fetchJobsWithGrantValues(
|
|
1787
|
-
return __awaiter(this,
|
|
1870
|
+
fetchJobsWithGrantValues(db_1, f_1) {
|
|
1871
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
1788
1872
|
return yield fetchJobs2(db.trx, f, log);
|
|
1789
1873
|
});
|
|
1790
1874
|
},
|
|
1791
|
-
fetchLiabilityEpochs(
|
|
1792
|
-
return __awaiter(this,
|
|
1875
|
+
fetchLiabilityEpochs(db_1) {
|
|
1876
|
+
return __awaiter(this, arguments, void 0, function* (db, log = logger_1.consoleLogger) {
|
|
1793
1877
|
const q = db.trx
|
|
1794
1878
|
.selectFrom(exports.LIABILITY_TABLE)
|
|
1795
1879
|
.select(({ fn }) => [
|
|
@@ -1847,94 +1931,83 @@ const pgClient = (config) => {
|
|
|
1847
1931
|
}));
|
|
1848
1932
|
});
|
|
1849
1933
|
},
|
|
1850
|
-
|
|
1851
|
-
return __awaiter(this,
|
|
1852
|
-
//
|
|
1934
|
+
createBurnCorrection(trx_1, p_1) {
|
|
1935
|
+
return __awaiter(this, arguments, void 0, function* (trx, p, log = logger_1.consoleLogger) {
|
|
1936
|
+
// Anchor + unit invariants are also DB CHECKs; validate here for a clearer error.
|
|
1937
|
+
if ((p.jobId == null) === (p.solTxId == null))
|
|
1938
|
+
throw new Error('burn_correction needs exactly one anchor (jobId XOR solTxId)');
|
|
1939
|
+
if (p.kind === 'down_adjust' && p.amountRender == null)
|
|
1940
|
+
throw new Error('down_adjust needs amountRender');
|
|
1941
|
+
if (p.kind === 'escrow_credit' && p.amountUsdc == null)
|
|
1942
|
+
throw new Error('escrow_credit needs amountUsdc');
|
|
1943
|
+
// Idempotent per (anchor, kind) — a re-run for the same bad job/tx is a no-op.
|
|
1853
1944
|
const row = yield trx.trx
|
|
1854
|
-
.insertInto(exports.
|
|
1945
|
+
.insertInto(exports.BURN_CORRECTION_TABLE)
|
|
1855
1946
|
.values({
|
|
1947
|
+
kind: p.kind,
|
|
1948
|
+
job_id: p.jobId,
|
|
1856
1949
|
sol_tx_id: p.solTxId,
|
|
1857
|
-
|
|
1950
|
+
amount_render: p.amountRender,
|
|
1951
|
+
amount_usdc: p.amountUsdc,
|
|
1858
1952
|
description: p.description,
|
|
1859
1953
|
})
|
|
1860
|
-
.onConflict((oc) => oc.
|
|
1954
|
+
.onConflict((oc) => oc.doNothing())
|
|
1861
1955
|
.returning('id')
|
|
1862
1956
|
.executeTakeFirst();
|
|
1863
1957
|
if (!row) {
|
|
1864
|
-
log.info(`
|
|
1958
|
+
log.info(`burn_correction ${p.kind} for ${p.jobId != null ? `job ${p.jobId}` : `sol_tx ${p.solTxId}`} already exists — skipped`);
|
|
1865
1959
|
return undefined;
|
|
1866
1960
|
}
|
|
1867
|
-
log.info(`created
|
|
1961
|
+
log.info(`created burn_correction ${row.id} (${p.kind}, ${p.jobId != null ? `job ${p.jobId}` : `sol_tx ${p.solTxId}`}): ${p.kind === 'down_adjust' ? `${p.amountRender} RENDER` : `${p.amountUsdc} USDC`}`);
|
|
1868
1962
|
return Number(row.id);
|
|
1869
1963
|
});
|
|
1870
1964
|
},
|
|
1871
|
-
|
|
1872
|
-
return __awaiter(this,
|
|
1965
|
+
getBurnCorrections(trx_1, ps_1) {
|
|
1966
|
+
return __awaiter(this, arguments, void 0, function* (trx, ps, log = logger_1.consoleLogger) {
|
|
1873
1967
|
if (!ps.toFill)
|
|
1874
1968
|
return [];
|
|
1969
|
+
// fill column depends on kind: down_adjust consumes (to_burn - burned); escrow_credit consumes
|
|
1970
|
+
// from_escrow_usdc. Each links via its own burn FK so one burn can carry one of each.
|
|
1971
|
+
const linkCol = ps.kind === 'down_adjust' ? 'down_correction_id' : 'escrow_correction_id';
|
|
1875
1972
|
const q = trx.trx
|
|
1876
|
-
.selectFrom(exports.
|
|
1877
|
-
.selectAll(exports.
|
|
1878
|
-
.
|
|
1879
|
-
.select([`${exports.JOB_TABLE}.completed_at`, `${exports.JOB_TABLE}.render_amt`])
|
|
1880
|
-
.leftJoin(exports.BURN_TABLE, `${exports.BURN_TABLE}.job_burn_adjustment_id`, `${exports.JOB_BURN_ADJUSTMENT_TABLE}.id`)
|
|
1973
|
+
.selectFrom(exports.BURN_CORRECTION_TABLE)
|
|
1974
|
+
.selectAll(exports.BURN_CORRECTION_TABLE)
|
|
1975
|
+
.leftJoin(exports.BURN_TABLE, `${exports.BURN_TABLE}.${linkCol}`, `${exports.BURN_CORRECTION_TABLE}.id`)
|
|
1881
1976
|
.select(({ fn, lit }) => [
|
|
1882
1977
|
fn.sum(fn.coalesce(`${exports.BURN_TABLE}.to_burn`, lit(0))).as('tot_to_burn'),
|
|
1883
1978
|
fn.sum(fn.coalesce(`${exports.BURN_TABLE}.burned`, lit(0))).as('tot_burned'),
|
|
1884
|
-
])
|
|
1885
|
-
.groupBy([
|
|
1886
|
-
`${exports.JOB_BURN_ADJUSTMENT_TABLE}.id`,
|
|
1887
|
-
`${exports.JOB_TABLE}.completed_at`,
|
|
1888
|
-
`${exports.JOB_TABLE}.render_amt`,
|
|
1889
|
-
]);
|
|
1890
|
-
log.info(`getJobBurnAdjustments ${q.compile().sql}`);
|
|
1891
|
-
const res = yield q.execute();
|
|
1892
|
-
return res
|
|
1893
|
-
.map((r) => ({
|
|
1894
|
-
id: Number(r.id),
|
|
1895
|
-
createdAt: r.created_at,
|
|
1896
|
-
jobId: Number(r.job_id),
|
|
1897
|
-
downAdjRndrUsed: Number(r.down_adj_rndr_used),
|
|
1898
|
-
downAdjToBurn: Number(r.down_adj_to_burn),
|
|
1899
|
-
adjusted: Number(r.tot_to_burn) - Number(r.tot_burned),
|
|
1900
|
-
job: {
|
|
1901
|
-
id: Number(r.job_id),
|
|
1902
|
-
completedAt: r.completed_at,
|
|
1903
|
-
rndrUsed: BigInt(r.render_amt),
|
|
1904
|
-
},
|
|
1905
|
-
}))
|
|
1906
|
-
.filter((a) => a.adjusted < a.downAdjToBurn);
|
|
1907
|
-
});
|
|
1908
|
-
},
|
|
1909
|
-
getTxBurnAdjustments(trx, ps, log = logger_1.consoleLogger) {
|
|
1910
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1911
|
-
if (!ps.toFill)
|
|
1912
|
-
return [];
|
|
1913
|
-
const q = trx.trx
|
|
1914
|
-
.selectFrom(exports.TX_BURN_ADJUSTMENT_TABLE)
|
|
1915
|
-
.selectAll(exports.TX_BURN_ADJUSTMENT_TABLE)
|
|
1916
|
-
.leftJoin(exports.BURN_TABLE, `${exports.BURN_TABLE}.tx_burn_adjustment_id`, `${exports.TX_BURN_ADJUSTMENT_TABLE}.id`)
|
|
1917
|
-
.select(({ fn, lit }) => [
|
|
1918
1979
|
fn
|
|
1919
1980
|
.sum(fn.coalesce(`${exports.BURN_TABLE}.from_escrow_usdc`, lit(0)))
|
|
1920
1981
|
.as('tot_from_escrow'),
|
|
1921
1982
|
])
|
|
1922
|
-
.
|
|
1923
|
-
|
|
1983
|
+
.where(`${exports.BURN_CORRECTION_TABLE}.kind`, '=', ps.kind)
|
|
1984
|
+
.groupBy(`${exports.BURN_CORRECTION_TABLE}.id`)
|
|
1985
|
+
.orderBy(`${exports.BURN_CORRECTION_TABLE}.created_at`, 'asc');
|
|
1986
|
+
log.info(`getBurnCorrections(${ps.kind}) ${q.compile().sql}`);
|
|
1924
1987
|
const res = yield q.execute();
|
|
1925
1988
|
return res
|
|
1926
1989
|
.map((r) => ({
|
|
1927
1990
|
id: Number(r.id),
|
|
1928
1991
|
createdAt: r.created_at,
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1992
|
+
jobId: r.job_id != null ? Number(r.job_id) : undefined,
|
|
1993
|
+
solTxId: r.sol_tx_id != null ? Number(r.sol_tx_id) : undefined,
|
|
1994
|
+
kind: r.kind,
|
|
1995
|
+
amountRender: r.amount_render != null ? Number(r.amount_render) : undefined,
|
|
1996
|
+
amountUsdc: r.amount_usdc != null ? Number(r.amount_usdc) : undefined,
|
|
1997
|
+
consumed: ps.kind === 'down_adjust'
|
|
1998
|
+
? Number(r.tot_to_burn) - Number(r.tot_burned)
|
|
1999
|
+
: Number(r.tot_from_escrow),
|
|
1932
2000
|
}))
|
|
1933
|
-
.filter((
|
|
2001
|
+
.filter((c) => {
|
|
2002
|
+
var _a, _b;
|
|
2003
|
+
return c.kind === 'down_adjust'
|
|
2004
|
+
? c.consumed < ((_a = c.amountRender) !== null && _a !== void 0 ? _a : 0)
|
|
2005
|
+
: c.consumed < ((_b = c.amountUsdc) !== null && _b !== void 0 ? _b : 0);
|
|
2006
|
+
});
|
|
1934
2007
|
});
|
|
1935
2008
|
},
|
|
1936
|
-
insertPolygonUpgrade(
|
|
1937
|
-
return __awaiter(this,
|
|
2009
|
+
insertPolygonUpgrade(db_1, p_1) {
|
|
2010
|
+
return __awaiter(this, arguments, void 0, function* (db, p, log = logger_1.consoleLogger) {
|
|
1938
2011
|
const solTxId = yield getOrInsertTx(db.trx, {
|
|
1939
2012
|
sig: p.solTx.sig,
|
|
1940
2013
|
executedAt: p.solTx.executedAt,
|
|
@@ -1952,8 +2025,8 @@ const pgClient = (config) => {
|
|
|
1952
2025
|
return;
|
|
1953
2026
|
});
|
|
1954
2027
|
},
|
|
1955
|
-
fetchPolygonUpgrades(
|
|
1956
|
-
return __awaiter(this,
|
|
2028
|
+
fetchPolygonUpgrades(db_1, f_1) {
|
|
2029
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
1957
2030
|
let query = db.trx
|
|
1958
2031
|
.selectFrom('polygon_upgrade')
|
|
1959
2032
|
.selectAll('polygon_upgrade')
|
|
@@ -1979,13 +2052,13 @@ const pgClient = (config) => {
|
|
|
1979
2052
|
}));
|
|
1980
2053
|
});
|
|
1981
2054
|
},
|
|
1982
|
-
getCurrentUserGrantSpend(
|
|
1983
|
-
return __awaiter(this,
|
|
2055
|
+
getCurrentUserGrantSpend(db_1, f_1) {
|
|
2056
|
+
return __awaiter(this, arguments, void 0, function* (db, f, log = logger_1.consoleLogger) {
|
|
1984
2057
|
return yield getCurrentUserGrantSpend(db.trx, f, log);
|
|
1985
2058
|
});
|
|
1986
2059
|
},
|
|
1987
|
-
deleteAll(
|
|
1988
|
-
return __awaiter(this,
|
|
2060
|
+
deleteAll() {
|
|
2061
|
+
return __awaiter(this, arguments, void 0, function* (log = logger_1.consoleLogger) {
|
|
1989
2062
|
if (config.database.includes('render')) {
|
|
1990
2063
|
throw new Error('cannot nuke from deployed database. call from tests only');
|
|
1991
2064
|
}
|
|
@@ -2031,8 +2104,8 @@ const pgClient = (config) => {
|
|
|
2031
2104
|
}
|
|
2032
2105
|
});
|
|
2033
2106
|
},
|
|
2034
|
-
checkPaymentsForDate(
|
|
2035
|
-
return __awaiter(this,
|
|
2107
|
+
checkPaymentsForDate(targetDate_1) {
|
|
2108
|
+
return __awaiter(this, arguments, void 0, function* (targetDate, channel = 'both', log = logger_1.consoleLogger) {
|
|
2036
2109
|
const startOfDay = new Date(targetDate);
|
|
2037
2110
|
startOfDay.setHours(0, 0, 0, 0);
|
|
2038
2111
|
const endOfDay = new Date(targetDate);
|
|
@@ -2083,8 +2156,8 @@ const pgClient = (config) => {
|
|
|
2083
2156
|
}
|
|
2084
2157
|
});
|
|
2085
2158
|
},
|
|
2086
|
-
checkEpochProcessed(
|
|
2087
|
-
return __awaiter(this,
|
|
2159
|
+
checkEpochProcessed(epochId_1, channel_1) {
|
|
2160
|
+
return __awaiter(this, arguments, void 0, function* (epochId, channel, log = logger_1.consoleLogger) {
|
|
2088
2161
|
try {
|
|
2089
2162
|
const result = yield db
|
|
2090
2163
|
.selectFrom('epoch')
|
|
@@ -2104,8 +2177,8 @@ const pgClient = (config) => {
|
|
|
2104
2177
|
}
|
|
2105
2178
|
});
|
|
2106
2179
|
},
|
|
2107
|
-
checkRecentPaymentActivity(
|
|
2108
|
-
return __awaiter(this,
|
|
2180
|
+
checkRecentPaymentActivity() {
|
|
2181
|
+
return __awaiter(this, arguments, void 0, function* (lookbackHours = 2, channel = 'both', log = logger_1.consoleLogger) {
|
|
2109
2182
|
const lookbackTime = new Date(Date.now() - lookbackHours * 60 * 60 * 1000);
|
|
2110
2183
|
const now = new Date();
|
|
2111
2184
|
try {
|