diff --git a/.gitignore b/.gitignore index b48c67a8..801765e3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,6 @@ logs.json states.json -scripts/gas-refund-program/*.csv \ No newline at end of file +scripts/gas-refund-program/*.csv + +.ignored \ No newline at end of file diff --git a/scripts/gas-refund-program/persistance/db-persistance.ts b/scripts/gas-refund-program/persistance/db-persistance.ts index a6933fb3..36eecda6 100644 --- a/scripts/gas-refund-program/persistance/db-persistance.ts +++ b/scripts/gas-refund-program/persistance/db-persistance.ts @@ -219,6 +219,7 @@ export function composeGasRefundTransactionStakeSnapshots( bptTotalSupply: score?.bptTotalSupply || '0', bptPSPBalance: score?.bptPSPBalance || '0', claimableSePSP1Balance: score?.claimableSePSP1Balance || '0', + staker: transaction.address, })); } return []; diff --git a/scripts/gas-refund-program/transactions-indexing/fetchRefundableTransactions.ts b/scripts/gas-refund-program/transactions-indexing/fetchRefundableTransactions.ts index e61b0d7f..465a1278 100644 --- a/scripts/gas-refund-program/transactions-indexing/fetchRefundableTransactions.ts +++ b/scripts/gas-refund-program/transactions-indexing/fetchRefundableTransactions.ts @@ -77,9 +77,11 @@ function constructTransactionsProcessor({ transaction.txGasPrice.toString(), ); // in wei - const currGasUsedUSD = currGasUsedChainCur - .multipliedBy(currencyRate.chainPrice) - .dividedBy(10 ** 18); // chaincurrency always encoded in 18decimals + const currGasUsedUSD = transaction.txGasUsedUSD + ? new BigNumber(transaction.txGasUsedUSD) + : currGasUsedChainCur + .multipliedBy(currencyRate.chainPrice) + .dividedBy(10 ** 18); // chaincurrency always encoded in 18decimals const currGasFeePSP = currGasUsedChainCur.dividedBy( currencyRate.pspToChainCurRate, diff --git a/sequelize/migrations/20241014000000-tx-snapshot-add-staker-column.js b/sequelize/migrations/20241014000000-tx-snapshot-add-staker-column.js new file mode 100644 index 00000000..b46d79bc --- /dev/null +++ b/sequelize/migrations/20241014000000-tx-snapshot-add-staker-column.js @@ -0,0 +1,29 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ + +module.exports = { + async up(queryInterface, Sequelize) { + // queryInterface. + await queryInterface.addColumn( + 'GasRefundTransactionStakeSnapshots', + 'staker', + Sequelize.STRING(42), + ); + + // Drop the 'txChain_txHash_stakeChain' key if it exists -- the old constraint, without staker column. + // the new one will be auto-created by modle + await queryInterface.removeIndex( + 'GasRefundTransactionStakeSnapshots', + 'txChain_txHash_stakeChain', + ); + }, + + async down(queryInterface) { + queryInterface.removeColumn('GasRefundTransactionStakeSnapshots', 'staker'); + await queryInterface.removeIndex( + 'GasRefundTransactionStakeSnapshots', + 'txChain_txHash_staker_stakeChain', + ); + }, +}; diff --git a/src/lib/gas-refund/multi-staking-utils.ts b/src/lib/gas-refund/multi-staking-utils.ts index 0cd5e6fb..cc017a86 100644 --- a/src/lib/gas-refund/multi-staking-utils.ts +++ b/src/lib/gas-refund/multi-staking-utils.ts @@ -12,6 +12,8 @@ from left join "GasRefundTransactionStakeSnapshots" grtss on grt.hash = grtss."transactionHash" and grt."chainId" = grtss."transactionChainId" + -- before Delta, staker field was missing in the GasRefundTransactionStakeSnapshots as txs were 1:1 with stakers + and ((grtss.staker = grt.address) OR (grtss.staker is NULL)) where grt.address = :address and grt.epoch between :epochFrom and :epochTo @@ -144,7 +146,14 @@ export function computeAggregatedStakeChainDetails( const transactionsWithClaimableByChain: TransactionWithCaimableByStakeChain[] = transactions.map(tx => { const sumStakeScore = Object.values(tx.stakeByChain).reduce( - (acc, stake) => acc + BigInt(stake.stakeScore), + (acc, stake) => { + const stakeScore = stake.stakeScore || '0'; + if (!stake.stakeScore) + console.log( + `stakeScore is null for tx ${tx.hash} on chain ${tx.chainId} of user ${tx.address}`, + ); + return acc + BigInt(stakeScore); + }, BigInt(0), ); @@ -213,8 +222,12 @@ export function computeAggregatedStakeChainDetails( return byEpoch; } - -function toFixed(dictionary: Record): Record { - const entries = Object.entries(dictionary).map(([k, v]) => [k, v.toFixed()]); - return Object.fromEntries(entries) -} \ No newline at end of file +function toFixed( + dictionary: Record, +): Record { + const entries = Object.entries(dictionary).map(([k, v]) => [ + k, + v.toFixed(), + ]); + return Object.fromEntries(entries); +} diff --git a/src/lib/paraswap-v6-stakers-transactions.ts b/src/lib/paraswap-v6-stakers-transactions.ts index b4e9c51a..eb7e5cd9 100644 --- a/src/lib/paraswap-v6-stakers-transactions.ts +++ b/src/lib/paraswap-v6-stakers-transactions.ts @@ -20,6 +20,7 @@ type ParaswapTransactionData = { blocknumber: number; // 58545814, blockhash: string; // '0xb1fdf818d10b1b2d97d82ff421972b03e1e04ceafaa5237c8373e705531e4617', txhash: string; //'0xca4c03b4e1fc17553706f9b91a3dd7eaa20202927e3ef77aa31dfdfc04ca4b16' + delta_fees_usd: null | number; }; function generateObjectsFromData(data: any): ParaswapTransactionData[] { // Dynamically extract column names from the 'cols' array @@ -101,6 +102,7 @@ export async function fetchParaswapV6StakersTransactions(arg0: { txGasUsed: item.txgasused.toString(), gasSpentInChainCurrencyWei, contract: item.augustusaddress, + txGasUsedUSD: item.delta_fees_usd || undefined, }; }, ), diff --git a/src/models/GasRefundTransactionStakeSnapshot.ts b/src/models/GasRefundTransactionStakeSnapshot.ts index 0ee14ace..4ee4aca4 100644 --- a/src/models/GasRefundTransactionStakeSnapshot.ts +++ b/src/models/GasRefundTransactionStakeSnapshot.ts @@ -5,11 +5,15 @@ import { createIndexDecorator, Table, } from 'sequelize-typescript'; -import { DataType_KECCAK256_HASHED_VALUE } from '../lib/sql-data-types'; +import { + DataType_ADDRESS, + DataType_KECCAK256_HASHED_VALUE, +} from '../lib/sql-data-types'; export interface GasRefundTransactionStakeSnapshotData { transactionChainId: number; transactionHash: string; + staker: string; stakeChainId: number; stakeScore: string; // should be computed by JS, not by SQL sePSP1Balance: string; @@ -20,7 +24,7 @@ export interface GasRefundTransactionStakeSnapshotData { } const compositeIndex = createIndexDecorator({ - name: 'txChain_txHash_stakeChain', + name: 'txChain_txHash_staker_stakeChain', type: 'UNIQUE', unique: true, }); @@ -35,6 +39,10 @@ export class GasRefundTransactionStakeSnapshot extends Model