@render-foundation/utils 0.0.258 → 0.0.259
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.map +1 -1
- package/lib/cjs/client/pg/v2Client.js +48 -28
- package/lib/cjs/client/pg/v2Client.js.map +1 -1
- package/lib/esm/src/client/dispersed.js.map +1 -1
- package/lib/esm/src/client/pg/v2Client.js +40 -9
- package/lib/esm/src/client/pg/v2Client.js.map +1 -1
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/src/client/dispersed.d.ts +3 -0
- package/lib/types/src/client/dispersed.d.ts.map +1 -1
- package/lib/types/src/client/pg/v2Client.d.ts +8 -0
- package/lib/types/src/client/pg/v2Client.d.ts.map +1 -1
- package/lib/types/src/dbTypesV2.d.ts +10 -0
- package/lib/types/src/dbTypesV2.d.ts.map +1 -1
- package/lib/types/src/index.d.ts +1 -1
- package/lib/types/src/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispersed.js","sourceRoot":"","sources":["../../../src/client/dispersed.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAAuD;AACvD,4DAA8B;AAE9B;;;;;;;;;;GAUG;AAEH,+DAA+D;AAC/D,MAAM,MAAM,GACV,kEAAkE,CAAA;AAEpE,sDAAsD;AACtD,MAAM,uBAAuB,GAAG,KAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"dispersed.js","sourceRoot":"","sources":["../../../src/client/dispersed.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sCAAuD;AACvD,4DAA8B;AAE9B;;;;;;;;;;GAUG;AAEH,+DAA+D;AAC/D,MAAM,MAAM,GACV,kEAAkE,CAAA;AAEpE,sDAAsD;AACtD,MAAM,uBAAuB,GAAG,KAAM,CAAA;AAgFtC;;;;GAIG;AACH,MAAa,sBAAuB,SAAQ,KAAK;IAE/C,YAA4B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
1645
1645
|
const raw = atob(f.cursor);
|
|
1646
1646
|
try {
|
|
1647
1647
|
const c = JSON.parse(raw);
|
|
1648
|
-
cursorEa = c.ea;
|
|
1648
|
+
cursorEa = new Date(c.ea);
|
|
1649
1649
|
cursorType = c.t;
|
|
1650
1650
|
cursorId = c.id;
|
|
1651
1651
|
}
|
|
@@ -1674,7 +1674,7 @@ const pgClient = (config) => {
|
|
|
1674
1674
|
const buyWhereClause = buyWhere.length ? `WHERE ${buyWhere.join(' AND ')}` : '';
|
|
1675
1675
|
const buySql = `
|
|
1676
1676
|
SELECT 'buy'::text AS type, b.id::bigint AS sortid, b.id AS id,
|
|
1677
|
-
st.executed_at,
|
|
1677
|
+
st.executed_at, b.priced_at, b.burned::text AS burned,
|
|
1678
1678
|
b.usdc_spent::text AS usdc_spent, b.quote_amt::text AS quote_amt,
|
|
1679
1679
|
b.tags, st.sig, b.render_to_usdc, b.eur_to_usdc,
|
|
1680
1680
|
coalesce(b.from_escrow_usdc, 0)::text AS from_escrow_usdc,
|
|
@@ -1693,7 +1693,7 @@ const pgClient = (config) => {
|
|
|
1693
1693
|
const grantWhereClause = grantWhere.length ? `WHERE ${grantWhere.join(' AND ')}` : '';
|
|
1694
1694
|
const grantSql = `
|
|
1695
1695
|
SELECT 'grant'::text AS type, gb.id::bigint AS sortid, gb.id AS id,
|
|
1696
|
-
st.executed_at,
|
|
1696
|
+
st.executed_at, null::timestamp AS priced_at, gb.burned::text AS burned,
|
|
1697
1697
|
'0' AS usdc_spent, '0' AS quote_amt,
|
|
1698
1698
|
gb.tags, st.sig, null::float8 AS render_to_usdc, null::float8 AS eur_to_usdc,
|
|
1699
1699
|
'0' AS from_escrow_usdc,
|
|
@@ -1747,7 +1747,7 @@ const pgClient = (config) => {
|
|
|
1747
1747
|
burns,
|
|
1748
1748
|
cursor: burns.length === limit
|
|
1749
1749
|
? btoa(JSON.stringify({
|
|
1750
|
-
ea: rows[burns.length - 1].
|
|
1750
|
+
ea: rows[burns.length - 1].executed_at,
|
|
1751
1751
|
t: rows[burns.length - 1].type,
|
|
1752
1752
|
id: rows[burns.length - 1].sortid,
|
|
1753
1753
|
}))
|
|
@@ -1786,8 +1786,8 @@ const pgClient = (config) => {
|
|
|
1786
1786
|
.innerJoin('sol_tx', 'sol_tx.id', 'burn.sol_tx_id')
|
|
1787
1787
|
.select(({ fn }) => [
|
|
1788
1788
|
dayExpr.as('day'),
|
|
1789
|
-
(0, kysely_1.sql) `SUM(burn.burned
|
|
1790
|
-
(0, kysely_1.sql) `SUM(burn.usdc_spent
|
|
1789
|
+
(0, kysely_1.sql) `SUM(CASE WHEN burn.burned > 0 THEN burn.burned WHEN COALESCE(burn.from_escrow_usdc, 0) > 0 AND burn.render_to_usdc > 0 THEN (burn.from_escrow_usdc::numeric / burn.render_to_usdc * 100)::bigint ELSE 0 END)`.as('render_burned'),
|
|
1790
|
+
(0, kysely_1.sql) `SUM(CASE WHEN burn.usdc_spent > 0 THEN burn.usdc_spent ELSE COALESCE(burn.from_escrow_usdc, 0) END)`.as('usdc_spent'),
|
|
1791
1791
|
fn.count('burn.id').as('burn_count'),
|
|
1792
1792
|
])
|
|
1793
1793
|
.groupBy((0, kysely_1.sql) `date_trunc('day', sol_tx.executed_at)`)
|
|
@@ -2086,7 +2086,21 @@ const pgClient = (config) => {
|
|
|
2086
2086
|
});
|
|
2087
2087
|
},
|
|
2088
2088
|
insertDispersedOutbox(p, log = logger_1.consoleLogger) {
|
|
2089
|
+
var _a;
|
|
2089
2090
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2091
|
+
// Check if dispersed_obligation table exists BEFORE the transaction so a missing table never
|
|
2092
|
+
// poisons the txn (PG aborts the entire transaction on any error, even a caught one).
|
|
2093
|
+
let hasObligationTable = false;
|
|
2094
|
+
let hasJsonbColumn = false;
|
|
2095
|
+
if ((_a = p.obligations) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2096
|
+
const { rows: tblRows } = yield (0, base_1.timedQuery)(pgPool, `SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'dispersed_obligation' LIMIT 1`, [], 'checkObligationTable', log);
|
|
2097
|
+
hasObligationTable = tblRows.length > 0;
|
|
2098
|
+
const { rows: colRows } = yield (0, base_1.timedQuery)(pgPool, `SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'dispersed_settlement' AND column_name = 'obligation_details' LIMIT 1`, [], 'checkObligationDetailsCol', log);
|
|
2099
|
+
hasJsonbColumn = colRows.length > 0;
|
|
2100
|
+
if (!hasObligationTable) {
|
|
2101
|
+
log.warn(`dispersed obligations: table not found (migration 44 pending); skipping fan-out for tx ${p.txSignature}`);
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2090
2104
|
// The outbox row is the durable, crash-safe anchor persisted BEFORE broadcast. When it carries a
|
|
2091
2105
|
// burn-correction draw, we increment consumed_render in the SAME transaction as the insert, bounded
|
|
2092
2106
|
// so it can never exceed amount_render. Row + counter are therefore atomic and inseparable: no
|
|
@@ -2094,28 +2108,16 @@ const pgClient = (config) => {
|
|
|
2094
2108
|
// (decremented again by voidDispersedOutbox). If the bounded increment can't fit (a concurrent draw
|
|
2095
2109
|
// took the room), the whole txn rolls back and we return {inserted:false} — the caller must NOT
|
|
2096
2110
|
// broadcast (no row, no counter change, no burn).
|
|
2097
|
-
|
|
2098
|
-
var
|
|
2111
|
+
const result = yield db.transaction().execute((trx) => __awaiter(this, void 0, void 0, function* () {
|
|
2112
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
2099
2113
|
const res = yield trx
|
|
2100
2114
|
.insertInto(exports.DISPERSED_SETTLEMENT_TABLE)
|
|
2101
|
-
.values({
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
obligation_uuids: p.obligationUuids,
|
|
2105
|
-
settled_amount: p.settledAmount,
|
|
2106
|
-
burned_amount: p.burnedAmount,
|
|
2107
|
-
executed_at: p.executedAt,
|
|
2108
|
-
eur_render: (_a = p.eurRender) !== null && _a !== void 0 ? _a : null,
|
|
2109
|
-
last_valid_block_height: (_b = p.lastValidBlockHeight) !== null && _b !== void 0 ? _b : null,
|
|
2110
|
-
usdc_spent: (_c = p.usdcSpent) !== null && _c !== void 0 ? _c : null,
|
|
2111
|
-
correction_id: (_d = p.correctionId) !== null && _d !== void 0 ? _d : null,
|
|
2112
|
-
correction_render: (_e = p.correctionRender) !== null && _e !== void 0 ? _e : null,
|
|
2113
|
-
usage_from: (_f = p.usageFrom) !== null && _f !== void 0 ? _f : null,
|
|
2114
|
-
usage_to: (_g = p.usageTo) !== null && _g !== void 0 ? _g : null,
|
|
2115
|
-
})
|
|
2115
|
+
.values(Object.assign({ tx_signature: p.txSignature, claim_uuid: p.claimUuid, obligation_uuids: p.obligationUuids, settled_amount: p.settledAmount, burned_amount: p.burnedAmount, executed_at: p.executedAt, eur_render: (_b = p.eurRender) !== null && _b !== void 0 ? _b : null, last_valid_block_height: (_c = p.lastValidBlockHeight) !== null && _c !== void 0 ? _c : null, usdc_spent: (_d = p.usdcSpent) !== null && _d !== void 0 ? _d : null, correction_id: (_e = p.correctionId) !== null && _e !== void 0 ? _e : null, correction_render: (_f = p.correctionRender) !== null && _f !== void 0 ? _f : null, usage_from: (_g = p.usageFrom) !== null && _g !== void 0 ? _g : null, usage_to: (_h = p.usageTo) !== null && _h !== void 0 ? _h : null }, (hasJsonbColumn && ((_j = p.obligations) === null || _j === void 0 ? void 0 : _j.length)
|
|
2116
|
+
? { obligation_details: JSON.stringify(p.obligations.map((o) => ({ uuid: o.uuid, amount_eur: o.amountEur, opened_at: o.openedAt.toISOString(), authorization_uuid: o.authorizationUuid }))) }
|
|
2117
|
+
: {})))
|
|
2116
2118
|
.onConflict((oc) => oc.column('tx_signature').doNothing())
|
|
2117
2119
|
.executeTakeFirst();
|
|
2118
|
-
const inserted = ((
|
|
2120
|
+
const inserted = ((_k = res.numInsertedOrUpdatedRows) !== null && _k !== void 0 ? _k : BigInt(0)) > BigInt(0);
|
|
2119
2121
|
// Only reserve when the row was actually inserted (a tx_signature conflict is a no-op → no double
|
|
2120
2122
|
// count) and it drew a correction.
|
|
2121
2123
|
if (inserted &&
|
|
@@ -2130,19 +2132,36 @@ const pgClient = (config) => {
|
|
|
2130
2132
|
.where('id', '=', String(p.correctionId))
|
|
2131
2133
|
.where((eb) => eb((0, kysely_1.sql) `consumed_render + ${p.correctionRender}::numeric`, '<=', eb.ref('amount_render')))
|
|
2132
2134
|
.executeTakeFirst();
|
|
2133
|
-
if (((
|
|
2135
|
+
if (((_l = upd.numUpdatedRows) !== null && _l !== void 0 ? _l : BigInt(0)) === BigInt(0)) {
|
|
2134
2136
|
// Would exceed amount_render (concurrent draw won the room) — roll back the whole txn.
|
|
2135
2137
|
log.warn(`dispersed correction ${p.correctionId}: draw ${p.correctionRender} would over-consume; rejecting outbox insert for tx ${p.txSignature}`);
|
|
2136
2138
|
throw new DispersedCorrectionRejected();
|
|
2137
2139
|
}
|
|
2138
2140
|
}
|
|
2139
|
-
|
|
2141
|
+
if (inserted && hasObligationTable && ((_m = p.obligations) === null || _m === void 0 ? void 0 : _m.length)) {
|
|
2142
|
+
yield trx
|
|
2143
|
+
.insertInto('dispersed_obligation')
|
|
2144
|
+
.values(p.obligations.map((o) => {
|
|
2145
|
+
var _a;
|
|
2146
|
+
return ({
|
|
2147
|
+
settlement_tx_sig: p.txSignature,
|
|
2148
|
+
uuid: o.uuid,
|
|
2149
|
+
amount_eur: o.amountEur,
|
|
2150
|
+
opened_at: o.openedAt,
|
|
2151
|
+
authorization_uuid: (_a = o.authorizationUuid) !== null && _a !== void 0 ? _a : null,
|
|
2152
|
+
});
|
|
2153
|
+
}))
|
|
2154
|
+
.onConflict((oc) => oc.column('uuid').doNothing())
|
|
2155
|
+
.execute();
|
|
2156
|
+
}
|
|
2157
|
+
log.debug(`dispersed outbox tx ${p.txSignature}: ${res.numInsertedOrUpdatedRows} row(s), ${hasObligationTable ? ((_p = (_o = p.obligations) === null || _o === void 0 ? void 0 : _o.length) !== null && _p !== void 0 ? _p : 0) : 0} obligations`);
|
|
2140
2158
|
return { inserted };
|
|
2141
2159
|
})).catch((e) => {
|
|
2142
2160
|
if (e instanceof DispersedCorrectionRejected)
|
|
2143
2161
|
return { inserted: false };
|
|
2144
2162
|
throw e;
|
|
2145
2163
|
});
|
|
2164
|
+
return result;
|
|
2146
2165
|
});
|
|
2147
2166
|
},
|
|
2148
2167
|
getOutstandingDispersedCorrection(log = logger_1.consoleLogger) {
|
|
@@ -2184,7 +2203,7 @@ const pgClient = (config) => {
|
|
|
2184
2203
|
.execute();
|
|
2185
2204
|
log.debug(`dispersed outbox: ${rows.length} unsettled`);
|
|
2186
2205
|
return rows.map((r) => {
|
|
2187
|
-
var _a, _b;
|
|
2206
|
+
var _a, _b, _c, _d;
|
|
2188
2207
|
return ({
|
|
2189
2208
|
txSignature: r.tx_signature,
|
|
2190
2209
|
claimUuid: r.claim_uuid,
|
|
@@ -2194,10 +2213,11 @@ const pgClient = (config) => {
|
|
|
2194
2213
|
executedAt: r.executed_at,
|
|
2195
2214
|
eurRender: (_a = r.eur_render) !== null && _a !== void 0 ? _a : undefined,
|
|
2196
2215
|
usdcSpent: (_b = r.usdc_spent) !== null && _b !== void 0 ? _b : undefined,
|
|
2197
|
-
// int8 comes back as a string from pg; block heights are well within JS safe-integer range.
|
|
2198
2216
|
lastValidBlockHeight: r.last_valid_block_height != null
|
|
2199
2217
|
? Number(r.last_valid_block_height)
|
|
2200
2218
|
: undefined,
|
|
2219
|
+
usageFrom: (_c = r.usage_from) !== null && _c !== void 0 ? _c : undefined,
|
|
2220
|
+
usageTo: (_d = r.usage_to) !== null && _d !== void 0 ? _d : undefined,
|
|
2201
2221
|
});
|
|
2202
2222
|
});
|
|
2203
2223
|
});
|