From 5ee5ac2fe69e739dff83315c49048cfd03bf3f65 Mon Sep 17 00:00:00 2001 From: Yongfeng LI Date: Tue, 26 Mar 2024 16:49:53 +0800 Subject: [PATCH] Fix centrifuge block rewards --- .../src/business/event/centrifuge/minted.js | 43 +++++++++++++++++++ .../input-scan/src/business/event/index.js | 3 ++ packages/input-scan/src/play.js | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 packages/input-scan/src/business/event/centrifuge/minted.js diff --git a/packages/input-scan/src/business/event/centrifuge/minted.js b/packages/input-scan/src/business/event/centrifuge/minted.js new file mode 100644 index 000000000..ee818cb0d --- /dev/null +++ b/packages/input-scan/src/business/event/centrifuge/minted.js @@ -0,0 +1,43 @@ +const { + env: { currentChain }, + consts: { + Modules, + } +} = require("@osn/scan-common"); + +function isNextEventValid(indexer, blockEvents) { + const nextEvent = blockEvents[indexer.eventIndex + 1]; + const { section, method } = nextEvent.event; + return "blockRewards" === section && "NewSession" === method; +} + +function handleBalancesMinted(event, indexer, blockEvents) { + if ("centrifuge" !== currentChain()) { + return; + } + const { section, method, data } = event; + if (section !== Modules.Balances || "Minted" !== method) { + return; + } + + if (!isNextEventValid(indexer, blockEvents)) { + return; + } + + if ("4dpEcgqJRyJK3J8Es6v8ZfVntV7c64Ysgcjd4hYwyGoFPWbg" !== data[0].toString()) { + return; + } + + const obj = { + indexer, + section: "blockRewards", + method: "NewSession", + balance: data[1].toString(), + } + + return data[1].toString(); +} + +module.exports = { + handleBalancesMinted, +} diff --git a/packages/input-scan/src/business/event/index.js b/packages/input-scan/src/business/event/index.js index d000fbffa..f0b1fb875 100644 --- a/packages/input-scan/src/business/event/index.js +++ b/packages/input-scan/src/business/event/index.js @@ -22,6 +22,7 @@ const { handleRollover } = require("./treasury/rollover"); const { handleCentrifugeBlockRewards } = require("./centrifuge/blockRewards"); const BigNumber = require("bignumber.js"); const { handleCentrifugeTxFee } = require("./centrifuge/txFee"); +const { handleBalancesMinted } = require("./centrifuge/minted"); async function handleDeposit( indexer, @@ -94,6 +95,7 @@ async function handleCommon( return { transfer, + cfgMinted: handleBalancesMinted(event, indexer, blockEvents), } } @@ -127,6 +129,7 @@ async function handleEvents(events, extrinsics, blockIndexer) { const commonObj = await handleCommon(indexer, event, events); transfer = bigAdd(transfer, commonObj.transfer); + centrifugeBlockReward = bigAdd(centrifugeBlockReward, commonObj.cfgMinted || 0); if (Modules.Treasury !== section || TreasuryCommonEvent.Deposit !== method) { continue; diff --git a/packages/input-scan/src/play.js b/packages/input-scan/src/play.js index cc91acd7d..ab423a01d 100644 --- a/packages/input-scan/src/play.js +++ b/packages/input-scan/src/play.js @@ -9,7 +9,7 @@ const { async function test() { const blockHeights = [ - 4330800, + 5108400, ]; for (const height of blockHeights) {