@render-foundation/utils 0.0.231 → 0.0.232-beta.0
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/client/dispersed.js +123 -0
- package/lib/cjs/client/dispersed.js.map +1 -0
- package/lib/cjs/client/pg/v2Client.js +122 -222
- package/lib/cjs/client/pg/v2Client.js.map +1 -1
- package/lib/cjs/index.js +5 -2
- package/lib/cjs/index.js.map +1 -1
- 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 +109 -214
- package/lib/esm/src/client/pg/v2Client.js.map +1 -1
- package/lib/esm/src/index.js +5 -2
- package/lib/esm/src/index.js.map +1 -1
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -1
- 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 +31 -41
- package/lib/types/src/client/pg/v2Client.d.ts.map +1 -1
- package/lib/types/src/dbTypesV2.d.ts +16 -40
- package/lib/types/src/dbTypesV2.d.ts.map +1 -1
- package/lib/types/src/index.d.ts +2 -2
- package/lib/types/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- 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
|
@@ -9,21 +9,19 @@ export const MANUAL_BURN_TABLE = 'manual_burn';
|
|
|
9
9
|
export const ENTITY_TABLE = 'entity';
|
|
10
10
|
export const SOL_TRANSFER_TABLE = 'sol_transfer1';
|
|
11
11
|
export const LIABILITY_TABLE = 'liability';
|
|
12
|
-
export const LIABILITY_ADJUSTMENT_TABLE = 'liability_adjustment';
|
|
13
|
-
export const LIABILITY_ADJUSTMENT_BATCH_TABLE = 'liability_adjustment_batch';
|
|
14
12
|
export const JOB_ID_TABLE = 'job_id';
|
|
15
13
|
export const JOB_TABLE = 'job';
|
|
16
14
|
export const BURN_TABLE = 'burn';
|
|
17
15
|
export const BRIDGE_TRANSFER_TABLE = 'bridge_transfer';
|
|
18
16
|
export const NETWORK_REVENUE_TABLE = 'network_revenue';
|
|
19
|
-
export const
|
|
20
|
-
export const TX_BURN_ADJUSTMENT_TABLE = 'tx_burn_adjustment';
|
|
17
|
+
export const BURN_ADJUSTMENT_TABLE = 'burn_adjustment';
|
|
21
18
|
export const ENTITY_EPOCH_INFO_TABLE = 'entity_epoch_info';
|
|
22
19
|
export const POLYGON_UPGRADE_TABLE = 'polygon_upgrade';
|
|
23
20
|
export const CURRENT_USER_GRANT_SPEND_TABLE = 'current_user_grant_spend';
|
|
24
21
|
export const USER_GRANT_SPEND_TABLE = 'user_grant_spend';
|
|
25
22
|
export const GRANT_BURN_ID_TABLE = 'grant_burn_id';
|
|
26
23
|
export const GRANT_BURN_TABLE = 'grant_burn';
|
|
24
|
+
export const DISPERSED_SETTLEMENT_TABLE = 'dispersed_settlement';
|
|
27
25
|
BigInt.prototype.toJSON = function () {
|
|
28
26
|
return this.toString();
|
|
29
27
|
};
|
|
@@ -315,11 +313,7 @@ export const pgClient = (config) => {
|
|
|
315
313
|
sig: solTx,
|
|
316
314
|
executedAt,
|
|
317
315
|
}, log);
|
|
318
|
-
|
|
319
|
-
// to_entity_id, symbol). Without ON CONFLICT a retry of the record step
|
|
320
|
-
// throws a unique violation and wedges the BullMQ job; make it an
|
|
321
|
-
// idempotent no-op and re-fetch the existing id instead.
|
|
322
|
-
let transferRow = await db
|
|
316
|
+
const { id } = await db
|
|
323
317
|
.insertInto(SOL_TRANSFER_TABLE)
|
|
324
318
|
.values({
|
|
325
319
|
id: dbId,
|
|
@@ -330,23 +324,9 @@ export const pgClient = (config) => {
|
|
|
330
324
|
symbol,
|
|
331
325
|
amount_payed: amountPayed,
|
|
332
326
|
})
|
|
333
|
-
.onConflict((oc) => oc
|
|
334
|
-
.columns(['sol_tx_id', 'from_entity_id', 'to_entity_id', 'symbol'])
|
|
335
|
-
.doNothing())
|
|
336
327
|
.returning((eb) => ['id as id'])
|
|
337
|
-
.
|
|
338
|
-
|
|
339
|
-
log.warn(`sol_transfer for sol_tx_id ${solTxId} ${fromEntityId}->${toEntityId} ${symbol} already exists; reusing existing id (idempotent retry)`);
|
|
340
|
-
transferRow = await db
|
|
341
|
-
.selectFrom(SOL_TRANSFER_TABLE)
|
|
342
|
-
.select((eb) => ['id as id'])
|
|
343
|
-
.where('sol_tx_id', '=', solTxId)
|
|
344
|
-
.where('from_entity_id', '=', fromEntityId)
|
|
345
|
-
.where('to_entity_id', '=', toEntityId)
|
|
346
|
-
.where('symbol', '=', symbol)
|
|
347
|
-
.executeTakeFirstOrThrow();
|
|
348
|
-
}
|
|
349
|
-
transferId = BigInt(transferRow.id);
|
|
328
|
+
.executeTakeFirstOrThrow();
|
|
329
|
+
transferId = BigInt(id);
|
|
350
330
|
}
|
|
351
331
|
ids.push({ transferId, liabilityId });
|
|
352
332
|
}
|
|
@@ -653,36 +633,9 @@ export const pgClient = (config) => {
|
|
|
653
633
|
}
|
|
654
634
|
return b.as('x');
|
|
655
635
|
}, (join) => join.onRef('y.sol_key', '=', 'x.sol_key'))
|
|
656
|
-
// Standing per-wallet/channel corrections (migration 36). NO epoch filter — an adjustment is
|
|
657
|
-
// a permanent delta on outstanding, not tied to a payout window; payments net it via `payed`.
|
|
658
|
-
.fullJoin((eb) => {
|
|
659
|
-
let b = eb
|
|
660
|
-
.selectFrom(LIABILITY_ADJUSTMENT_TABLE)
|
|
661
|
-
.select(({ fn }) => fn.sum(`amount_adjustment`).as('adj'))
|
|
662
|
-
.innerJoin(ENTITY_TABLE, `${LIABILITY_ADJUSTMENT_TABLE}.entity_id`, 'entity.id')
|
|
663
|
-
.select(['entity.sol_key'])
|
|
664
|
-
.groupBy('entity.sol_key');
|
|
665
|
-
if (f.banned) {
|
|
666
|
-
b = b.where('entity.banned', '=', true);
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
b = b.where('entity.banned', '=', false);
|
|
670
|
-
}
|
|
671
|
-
if (f.channels && f.channels.length > 0) {
|
|
672
|
-
b = b.where((eb) => eb.or(f.channels.map((c) => eb('liability_adjustment.channel', '=', c))));
|
|
673
|
-
}
|
|
674
|
-
else {
|
|
675
|
-
b = b.where((eb) => eb.or([
|
|
676
|
-
eb('liability_adjustment.channel', '=', 'node_operator'),
|
|
677
|
-
eb('liability_adjustment.channel', '=', 'availability'),
|
|
678
|
-
]));
|
|
679
|
-
}
|
|
680
|
-
return b.as('a');
|
|
681
|
-
}, (join) => join.on(sql `"a"."sol_key" = coalesce("y"."sol_key", "x"."sol_key")`))
|
|
682
636
|
.select(({ fn }) => [
|
|
683
|
-
fn.coalesce('y.sol_key', 'x.sol_key'
|
|
684
|
-
sql `${fn.coalesce(`x.due`, sql `0`)}
|
|
685
|
-
${fn.coalesce(`a.adj`, sql `0`)} -
|
|
637
|
+
fn.coalesce('y.sol_key', 'x.sol_key').as('sol_key'),
|
|
638
|
+
sql `${fn.coalesce(`x.due`, sql `0`)} -
|
|
686
639
|
${fn.coalesce(`y.payed`, sql `0`)}`.as('out'),
|
|
687
640
|
])
|
|
688
641
|
.as('z'))
|
|
@@ -705,56 +658,6 @@ export const pgClient = (config) => {
|
|
|
705
658
|
}
|
|
706
659
|
return out;
|
|
707
660
|
},
|
|
708
|
-
async addLiabilityAdjustments(batch, rows, log = consoleLogger) {
|
|
709
|
-
return await db.transaction().execute(async (trx) => {
|
|
710
|
-
// Upsert the batch by its label (idempotent re-runs; label is the run identity).
|
|
711
|
-
const b = await trx
|
|
712
|
-
.insertInto(LIABILITY_ADJUSTMENT_BATCH_TABLE)
|
|
713
|
-
.values({
|
|
714
|
-
label: batch.label,
|
|
715
|
-
description: batch.description,
|
|
716
|
-
created_by: batch.createdBy,
|
|
717
|
-
})
|
|
718
|
-
.onConflict((oc) => oc.column('label').doUpdateSet({
|
|
719
|
-
description: batch.description,
|
|
720
|
-
created_by: batch.createdBy,
|
|
721
|
-
}))
|
|
722
|
-
.returning('id')
|
|
723
|
-
.executeTakeFirstOrThrow();
|
|
724
|
-
const batchId = BigInt(b.id);
|
|
725
|
-
let inserted = 0;
|
|
726
|
-
let skipped = 0;
|
|
727
|
-
let net = BigInt(0);
|
|
728
|
-
let positive = BigInt(0);
|
|
729
|
-
let negative = BigInt(0);
|
|
730
|
-
for (const r of rows) {
|
|
731
|
-
const entityId = await getOrInsertEntity(trx, { solKey: r.solKey }, log);
|
|
732
|
-
const res = await trx
|
|
733
|
-
.insertInto(LIABILITY_ADJUSTMENT_TABLE)
|
|
734
|
-
.values({
|
|
735
|
-
entity_id: entityId,
|
|
736
|
-
channel: r.channel,
|
|
737
|
-
amount_adjustment: r.amountAdjustment,
|
|
738
|
-
batch_id: batchId,
|
|
739
|
-
})
|
|
740
|
-
// unique (entity_id, channel, batch_id) → a re-run of the same batch is a no-op
|
|
741
|
-
.onConflict((oc) => oc.columns(['entity_id', 'channel', 'batch_id']).doNothing())
|
|
742
|
-
.executeTakeFirst();
|
|
743
|
-
if ((res.numInsertedOrUpdatedRows ?? BigInt(0)) > BigInt(0))
|
|
744
|
-
inserted++;
|
|
745
|
-
else
|
|
746
|
-
skipped++;
|
|
747
|
-
net += r.amountAdjustment;
|
|
748
|
-
if (r.amountAdjustment > BigInt(0))
|
|
749
|
-
positive += r.amountAdjustment;
|
|
750
|
-
else
|
|
751
|
-
negative += r.amountAdjustment;
|
|
752
|
-
}
|
|
753
|
-
log.info(`liability_adjustment batch '${batch.label}' (id ${batchId}): ` +
|
|
754
|
-
`inserted ${inserted}, skipped ${skipped}, net ${net} (+${positive} / ${negative})`);
|
|
755
|
-
return { batchId, inserted, skipped, net, positive, negative };
|
|
756
|
-
});
|
|
757
|
-
},
|
|
758
661
|
async fetchNodeOperatorEpoch(epochId, log = consoleLogger) {
|
|
759
662
|
const q = db
|
|
760
663
|
.selectFrom(JOB_ID_TABLE)
|
|
@@ -1039,7 +942,7 @@ export const pgClient = (config) => {
|
|
|
1039
942
|
let buyBurnId;
|
|
1040
943
|
let grantBurnId;
|
|
1041
944
|
if (p.buyBurn) {
|
|
1042
|
-
const { burned, usdcSpent, eurToUsdc, renderToUsdc, quoteAmt, tags,
|
|
945
|
+
const { burned, usdcSpent, eurToUsdc, renderToUsdc, quoteAmt, tags, burnAdjustmentId, toBurn, } = p.buyBurn;
|
|
1043
946
|
let pricedAt = p.buyBurn.pricedAt;
|
|
1044
947
|
if (!pricedAt) {
|
|
1045
948
|
const jobs = await fetchJobs1(trx.trx, { ids: p.jobs.map((j) => String(j.id)) }, log);
|
|
@@ -1058,30 +961,17 @@ export const pgClient = (config) => {
|
|
|
1058
961
|
quote_amt: quoteAmt,
|
|
1059
962
|
burned: burned,
|
|
1060
963
|
tags: tags.join(','),
|
|
1061
|
-
|
|
1062
|
-
tx_burn_adjustment_id: txBurnAdjustmentId,
|
|
964
|
+
burn_adjustment_id: burnAdjustmentId,
|
|
1063
965
|
to_burn: toBurn,
|
|
1064
|
-
from_escrow_credit: fromEscrowCredit ?? 0,
|
|
1065
966
|
};
|
|
1066
967
|
log.debug(`inserting burn ${JSON.stringify(v)}`);
|
|
1067
|
-
|
|
1068
|
-
// the record step for the same on-chain burn is a safe no-op. On conflict
|
|
1069
|
-
// executeTakeFirst() returns undefined, so re-fetch the existing id.
|
|
1070
|
-
let burnRow = await trx.trx
|
|
968
|
+
const { id } = await trx.trx
|
|
1071
969
|
.insertInto(BURN_TABLE)
|
|
1072
970
|
.values(v)
|
|
1073
|
-
|
|
971
|
+
//.onConflict((oc) => oc.column('sol_tx').doNothing())
|
|
1074
972
|
.returning((eb) => ['id as id'])
|
|
1075
|
-
.
|
|
1076
|
-
|
|
1077
|
-
log.warn(`burn for sol_tx_id ${solTxId} already exists; reusing existing id (idempotent retry)`);
|
|
1078
|
-
burnRow = await trx.trx
|
|
1079
|
-
.selectFrom(BURN_TABLE)
|
|
1080
|
-
.select((eb) => ['id as id'])
|
|
1081
|
-
.where('sol_tx_id', '=', solTxId)
|
|
1082
|
-
.executeTakeFirstOrThrow();
|
|
1083
|
-
}
|
|
1084
|
-
buyBurnId = Number(burnRow.id);
|
|
973
|
+
.executeTakeFirstOrThrow();
|
|
974
|
+
buyBurnId = Number(id);
|
|
1085
975
|
}
|
|
1086
976
|
if (p.grantBurn) {
|
|
1087
977
|
const { burned, tags } = p.grantBurn;
|
|
@@ -1091,22 +981,12 @@ export const pgClient = (config) => {
|
|
|
1091
981
|
tags: tags?.join(','),
|
|
1092
982
|
};
|
|
1093
983
|
log.debug(`inserting grant burn ${JSON.stringify(v)}`);
|
|
1094
|
-
|
|
1095
|
-
let grantBurnRow = await trx.trx
|
|
984
|
+
const { id } = await trx.trx
|
|
1096
985
|
.insertInto(GRANT_BURN_TABLE)
|
|
1097
986
|
.values(v)
|
|
1098
|
-
.onConflict((oc) => oc.column('sol_tx_id').doNothing())
|
|
1099
987
|
.returning((eb) => ['id as id'])
|
|
1100
|
-
.
|
|
1101
|
-
|
|
1102
|
-
log.warn(`grant_burn for sol_tx_id ${solTxId} already exists; reusing existing id (idempotent retry)`);
|
|
1103
|
-
grantBurnRow = await trx.trx
|
|
1104
|
-
.selectFrom(GRANT_BURN_TABLE)
|
|
1105
|
-
.select((eb) => ['id as id'])
|
|
1106
|
-
.where('sol_tx_id', '=', solTxId)
|
|
1107
|
-
.executeTakeFirstOrThrow();
|
|
1108
|
-
}
|
|
1109
|
-
grantBurnId = Number(grantBurnRow.id);
|
|
988
|
+
.executeTakeFirstOrThrow();
|
|
989
|
+
grantBurnId = Number(id);
|
|
1110
990
|
}
|
|
1111
991
|
const burnId = buyBurnId;
|
|
1112
992
|
const grantId = grantBurnId ?? buyBurnId;
|
|
@@ -1597,6 +1477,61 @@ export const pgClient = (config) => {
|
|
|
1597
1477
|
log.debug(`burn id ${id} inserted ${num} of ${p.jobs.length} burn jobs`);
|
|
1598
1478
|
});
|
|
1599
1479
|
},
|
|
1480
|
+
async insertDispersedOutbox(p, log = consoleLogger) {
|
|
1481
|
+
const res = await db
|
|
1482
|
+
.insertInto(DISPERSED_SETTLEMENT_TABLE)
|
|
1483
|
+
.values({
|
|
1484
|
+
tx_signature: p.txSignature,
|
|
1485
|
+
claim_uuid: p.claimUuid,
|
|
1486
|
+
obligation_uuids: p.obligationUuids,
|
|
1487
|
+
settled_amount: p.settledAmount,
|
|
1488
|
+
burned_amount: p.burnedAmount,
|
|
1489
|
+
executed_at: p.executedAt,
|
|
1490
|
+
eur_render: p.eurRender ?? null,
|
|
1491
|
+
last_valid_block_height: p.lastValidBlockHeight ?? null,
|
|
1492
|
+
})
|
|
1493
|
+
.onConflict((oc) => oc.column('tx_signature').doNothing())
|
|
1494
|
+
.executeTakeFirst();
|
|
1495
|
+
log.debug(`dispersed outbox tx ${p.txSignature}: ${res.numInsertedOrUpdatedRows} row(s)`);
|
|
1496
|
+
},
|
|
1497
|
+
async markDispersedSettled(txSignature, p, log = consoleLogger) {
|
|
1498
|
+
await db
|
|
1499
|
+
.updateTable(DISPERSED_SETTLEMENT_TABLE)
|
|
1500
|
+
.set({ settled_at: new Date(), idempotent_replay: p.idempotentReplay })
|
|
1501
|
+
.where('tx_signature', '=', txSignature)
|
|
1502
|
+
.execute();
|
|
1503
|
+
log.debug(`dispersed settled tx ${txSignature}`);
|
|
1504
|
+
},
|
|
1505
|
+
async getUnsettledDispersed(log = consoleLogger) {
|
|
1506
|
+
const rows = await db
|
|
1507
|
+
.selectFrom(DISPERSED_SETTLEMENT_TABLE)
|
|
1508
|
+
.selectAll()
|
|
1509
|
+
.where('settled_at', 'is', null)
|
|
1510
|
+
.execute();
|
|
1511
|
+
log.debug(`dispersed outbox: ${rows.length} unsettled`);
|
|
1512
|
+
return rows.map((r) => ({
|
|
1513
|
+
txSignature: r.tx_signature,
|
|
1514
|
+
claimUuid: r.claim_uuid,
|
|
1515
|
+
obligationUuids: r.obligation_uuids,
|
|
1516
|
+
settledAmount: r.settled_amount,
|
|
1517
|
+
burnedAmount: r.burned_amount,
|
|
1518
|
+
executedAt: r.executed_at,
|
|
1519
|
+
eurRender: r.eur_render ?? undefined,
|
|
1520
|
+
// int8 comes back as a string from pg; block heights are well within JS safe-integer range.
|
|
1521
|
+
lastValidBlockHeight: r.last_valid_block_height != null
|
|
1522
|
+
? Number(r.last_valid_block_height)
|
|
1523
|
+
: undefined,
|
|
1524
|
+
}));
|
|
1525
|
+
},
|
|
1526
|
+
async voidDispersedOutbox(txSignature, log = consoleLogger) {
|
|
1527
|
+
const res = await db
|
|
1528
|
+
.deleteFrom(DISPERSED_SETTLEMENT_TABLE)
|
|
1529
|
+
.where('tx_signature', '=', txSignature)
|
|
1530
|
+
// Never delete a row we already settled — void only applies to pending (un-landed) rows.
|
|
1531
|
+
.where('settled_at', 'is', null)
|
|
1532
|
+
.executeTakeFirst();
|
|
1533
|
+
log.debug(`dispersed outbox void tx ${txSignature}: ${res.numDeletedRows} row(s)`);
|
|
1534
|
+
},
|
|
1600
1535
|
async fetchJobs(db, f, log = consoleLogger) {
|
|
1601
1536
|
return await fetchJobs1(db.trx, f, log);
|
|
1602
1537
|
},
|
|
@@ -1660,85 +1595,45 @@ export const pgClient = (config) => {
|
|
|
1660
1595
|
: {},
|
|
1661
1596
|
}));
|
|
1662
1597
|
},
|
|
1663
|
-
async
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1598
|
+
async getBurnAdjustments(trx, ps, log = consoleLogger) {
|
|
1599
|
+
if (ps.toFill) {
|
|
1600
|
+
const q = trx.trx
|
|
1601
|
+
.selectFrom(BURN_ADJUSTMENT_TABLE)
|
|
1602
|
+
.selectAll(BURN_ADJUSTMENT_TABLE)
|
|
1603
|
+
.innerJoin(JOB_TABLE, `${JOB_TABLE}.id`, `${BURN_ADJUSTMENT_TABLE}.job_id`)
|
|
1604
|
+
.select([`${JOB_TABLE}.completed_at`, `${JOB_TABLE}.render_amt`])
|
|
1605
|
+
.leftJoin(BURN_TABLE, `${BURN_TABLE}.burn_adjustment_id`, `${BURN_ADJUSTMENT_TABLE}.id`)
|
|
1606
|
+
.select(({ fn, lit }) => [
|
|
1607
|
+
fn
|
|
1608
|
+
.sum(fn.coalesce(`${BURN_TABLE}.to_burn`, lit(0)))
|
|
1609
|
+
.as('tot_to_burn'),
|
|
1610
|
+
fn
|
|
1611
|
+
.sum(fn.coalesce(`${BURN_TABLE}.burned`, lit(0)))
|
|
1612
|
+
.as('tot_burned'),
|
|
1613
|
+
])
|
|
1614
|
+
.groupBy([
|
|
1615
|
+
`${BURN_ADJUSTMENT_TABLE}.id`,
|
|
1616
|
+
`${JOB_TABLE}.completed_at`,
|
|
1617
|
+
`${JOB_TABLE}.render_amt`,
|
|
1618
|
+
])
|
|
1619
|
+
.havingRef(sql `SUM(COALESCE("burn"."to_burn", 0)) - SUM(COALESCE("burn"."burned", 0))`, '<', `${BURN_ADJUSTMENT_TABLE}.down_adj_to_burn`);
|
|
1620
|
+
log.info(`getBurnAdjustments ${q.compile().sql}`);
|
|
1621
|
+
const res = await q.execute();
|
|
1622
|
+
return res.map((r) => ({
|
|
1623
|
+
id: Number(r.id),
|
|
1624
|
+
createdAt: r.created_at,
|
|
1625
|
+
jobId: Number(r.job_id),
|
|
1626
|
+
downAdjRndrUsed: Number(r.down_adj_rndr_used),
|
|
1627
|
+
downAdjToBurn: Number(r.down_adj_to_burn),
|
|
1628
|
+
adjusted: Number(r.tot_to_burn) - Number(r.tot_burned),
|
|
1629
|
+
job: {
|
|
1630
|
+
id: Number(r.job_id),
|
|
1631
|
+
completedAt: r.completed_at,
|
|
1632
|
+
rndrUsed: BigInt(r.render_amt),
|
|
1633
|
+
},
|
|
1634
|
+
}));
|
|
1678
1635
|
}
|
|
1679
|
-
|
|
1680
|
-
return Number(row.id);
|
|
1681
|
-
},
|
|
1682
|
-
async getJobBurnAdjustments(trx, ps, log = consoleLogger) {
|
|
1683
|
-
if (!ps.toFill)
|
|
1684
|
-
return [];
|
|
1685
|
-
const q = trx.trx
|
|
1686
|
-
.selectFrom(JOB_BURN_ADJUSTMENT_TABLE)
|
|
1687
|
-
.selectAll(JOB_BURN_ADJUSTMENT_TABLE)
|
|
1688
|
-
.innerJoin(JOB_TABLE, `${JOB_TABLE}.id`, `${JOB_BURN_ADJUSTMENT_TABLE}.job_id`)
|
|
1689
|
-
.select([`${JOB_TABLE}.completed_at`, `${JOB_TABLE}.render_amt`])
|
|
1690
|
-
.leftJoin(BURN_TABLE, `${BURN_TABLE}.job_burn_adjustment_id`, `${JOB_BURN_ADJUSTMENT_TABLE}.id`)
|
|
1691
|
-
.select(({ fn, lit }) => [
|
|
1692
|
-
fn.sum(fn.coalesce(`${BURN_TABLE}.to_burn`, lit(0))).as('tot_to_burn'),
|
|
1693
|
-
fn.sum(fn.coalesce(`${BURN_TABLE}.burned`, lit(0))).as('tot_burned'),
|
|
1694
|
-
])
|
|
1695
|
-
.groupBy([
|
|
1696
|
-
`${JOB_BURN_ADJUSTMENT_TABLE}.id`,
|
|
1697
|
-
`${JOB_TABLE}.completed_at`,
|
|
1698
|
-
`${JOB_TABLE}.render_amt`,
|
|
1699
|
-
]);
|
|
1700
|
-
log.info(`getJobBurnAdjustments ${q.compile().sql}`);
|
|
1701
|
-
const res = await q.execute();
|
|
1702
|
-
return res
|
|
1703
|
-
.map((r) => ({
|
|
1704
|
-
id: Number(r.id),
|
|
1705
|
-
createdAt: r.created_at,
|
|
1706
|
-
jobId: Number(r.job_id),
|
|
1707
|
-
downAdjRndrUsed: Number(r.down_adj_rndr_used),
|
|
1708
|
-
downAdjToBurn: Number(r.down_adj_to_burn),
|
|
1709
|
-
adjusted: Number(r.tot_to_burn) - Number(r.tot_burned),
|
|
1710
|
-
job: {
|
|
1711
|
-
id: Number(r.job_id),
|
|
1712
|
-
completedAt: r.completed_at,
|
|
1713
|
-
rndrUsed: BigInt(r.render_amt),
|
|
1714
|
-
},
|
|
1715
|
-
}))
|
|
1716
|
-
.filter((a) => a.adjusted < a.downAdjToBurn);
|
|
1717
|
-
},
|
|
1718
|
-
async getTxBurnAdjustments(trx, ps, log = consoleLogger) {
|
|
1719
|
-
if (!ps.toFill)
|
|
1720
|
-
return [];
|
|
1721
|
-
const q = trx.trx
|
|
1722
|
-
.selectFrom(TX_BURN_ADJUSTMENT_TABLE)
|
|
1723
|
-
.selectAll(TX_BURN_ADJUSTMENT_TABLE)
|
|
1724
|
-
.leftJoin(BURN_TABLE, `${BURN_TABLE}.tx_burn_adjustment_id`, `${TX_BURN_ADJUSTMENT_TABLE}.id`)
|
|
1725
|
-
.select(({ fn, lit }) => [
|
|
1726
|
-
fn
|
|
1727
|
-
.sum(fn.coalesce(`${BURN_TABLE}.from_escrow_credit`, lit(0)))
|
|
1728
|
-
.as('tot_from_escrow'),
|
|
1729
|
-
])
|
|
1730
|
-
.groupBy(`${TX_BURN_ADJUSTMENT_TABLE}.id`);
|
|
1731
|
-
log.info(`getTxBurnAdjustments ${q.compile().sql}`);
|
|
1732
|
-
const res = await q.execute();
|
|
1733
|
-
return res
|
|
1734
|
-
.map((r) => ({
|
|
1735
|
-
id: Number(r.id),
|
|
1736
|
-
createdAt: r.created_at,
|
|
1737
|
-
solTxId: Number(r.sol_tx_id),
|
|
1738
|
-
surplusRender: Number(r.surplus_render),
|
|
1739
|
-
consumed: Number(r.tot_from_escrow),
|
|
1740
|
-
}))
|
|
1741
|
-
.filter((a) => a.consumed < a.surplusRender);
|
|
1636
|
+
return [];
|
|
1742
1637
|
},
|
|
1743
1638
|
async insertPolygonUpgrade(db, p, log = consoleLogger) {
|
|
1744
1639
|
const solTxId = await getOrInsertTx(db.trx, {
|