Skip to content

Commit

Permalink
Fix centrifuge block rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
wliyongfeng committed Mar 26, 2024
1 parent 209b474 commit 5ee5ac2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
43 changes: 43 additions & 0 deletions packages/input-scan/src/business/event/centrifuge/minted.js
Original file line number Diff line number Diff line change
@@ -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,
}
3 changes: 3 additions & 0 deletions packages/input-scan/src/business/event/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -94,6 +95,7 @@ async function handleCommon(

return {
transfer,
cfgMinted: handleBalancesMinted(event, indexer, blockEvents),
}
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/input-scan/src/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {

async function test() {
const blockHeights = [
4330800,
5108400,
];

for (const height of blockHeights) {
Expand Down

0 comments on commit 5ee5ac2

Please sign in to comment.