Query editor
WITH stake_by_address AS (SELECT"from" AS "address",MIN("evt_block_time") AS "time",SUM("value" / 1e18) AS "stake_amount"FROMpolygon_ethereum.MaticToken_evt_TransferWHERE"to" = 0x5e3ef299fddf15eaa0432e6e66473ace8c13d908GROUP BY"from"),stake_reward AS (SELECTSUM("_amount") / 1e18 * 10 AS "reward"FROMmaticx_ethereum.MaticX_evt_DistributeFees),total_stake AS (SELECTSUM("stake_amount") AS "total_stake"FROMstake_by_address),stake_with_reward_by_address AS (SELECT"address","time","stake_amount" + ("stake_amount" / "total_stake") * "reward" AS "stake_with_reward"FROMstake_by_address,stake_reward,total_stake),unstake_by_address AS (SELECT"to" AS "address",SUM("value" / 1e18) AS "unstake_amount"FROMpolygon_ethereum.MaticToken_evt_TransferWHERE"from" = 0x5e3ef299fddf15eaa0432e6e66473ace8c13d908GROUP BY"to"),total_unstake AS (SELECTSUM("unstake_amount") AS "total_unstake"FROMunstake_by_address),total_net_stake AS (SELECT"total_stake" + "reward" - "total_unstake" AS "total_net_stake"