Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetch rune address to avoid keccak hashed rune address issue from logs #61

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { RFoxLog, StakeLog, UnstakeLog } from "../events";
import { isLogType } from "../helpers";
import { REWARD_RATE, WAD } from "../constants";
import assert from "assert";

export type StakingInfo = {
stakingBalance: bigint;
earnedRewards: bigint;
rewardPerTokenStored: bigint;
runeAddress: string;
};
import { StakingInfo } from "../types";

const getEmptyStakingInfo = () => {
return {
Expand Down
24 changes: 0 additions & 24 deletions scripts/rewards-distribution/getLatestRuneAddressByAccount.ts

This file was deleted.

41 changes: 41 additions & 0 deletions scripts/rewards-distribution/getStakingInfoByAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Address, PublicClient } from "viem";
import { stakingV1Abi } from "./generated/abi-types";
import { ARBITRUM_RFOX_PROXY_CONTRACT_ADDRESS } from "./constants";
import { StakingInfo } from "./types";

export const getStakingInfoByAccount = async (
publicClient: PublicClient,
accounts: Address[],
blockNumber: bigint,
) => {
const runeAddressByAccount: Record<Address, StakingInfo> = {};

// Note we need to query these sequentially until we have higher rate limits
// TODO: Promise.all when we have higher rate limits
for (const account of accounts) {
const [
stakingBalance,
unstakingBalance,
earnedRewards,
rewardPerTokenStored,
runeAddress,
] = await publicClient.readContract({
// TODO: dotenv or similar for contract addresses
address: ARBITRUM_RFOX_PROXY_CONTRACT_ADDRESS,
abi: stakingV1Abi,
functionName: "stakingInfo",
args: [account],
blockNumber,
});

runeAddressByAccount[account] = {
stakingBalance,
unstakingBalance,
earnedRewards,
rewardPerTokenStored,
runeAddress,
};
}

return runeAddressByAccount;
};
14 changes: 9 additions & 5 deletions scripts/rewards-distribution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { distributeAmount } from "./distributeAmount/distributeAmount";
import { Address } from "viem";
import { orderBy } from "lodash";
import { getLatestRuneAddressByAccount } from "./getLatestRuneAddressByAccount";
import { getStakingInfoByAccount } from "./getStakingInfoByAccount";

const main = async () => {
const [currentBlock, [initLog]] = await Promise.all([
Expand Down Expand Up @@ -82,8 +82,12 @@ const main = async () => {
orderedLogs,
);

// Get the latest rune address for each account
const runeAddressByAccount = getLatestRuneAddressByAccount(orderedLogs);
const accounts = Object.keys(earnedRewardsByAccount) as Address[];
const epochEndStakingInfoByAccount = await getStakingInfoByAccount(
publicClient,
accounts,
toBlock,
);

await validateRewardsDistribution(
publicClient,
Expand All @@ -102,8 +106,8 @@ const main = async () => {

console.log("Rewards distribution calculated successfully!");

const tableRows = Object.entries(runeAddressByAccount).map(
([account, runeAddress]) => {
const tableRows = Object.entries(epochEndStakingInfoByAccount).map(
([account, { runeAddress }]) => {
return {
account,
runeAddress,
Expand Down
7 changes: 7 additions & 0 deletions scripts/rewards-distribution/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type StakingInfo = {
stakingBalance: bigint;
unstakingBalance: bigint;
earnedRewards: bigint;
rewardPerTokenStored: bigint;
runeAddress: string;
};