Skip to content

Commit

Permalink
Merge pull request #61 from shapeshift/cli-rune-address-fix
Browse files Browse the repository at this point in the history
fix: fetch rune address to avoid keccak hashed rune address issue from logs
  • Loading branch information
0xApotheosis committed Jun 11, 2024
2 parents 2dee2c0 + 8ccfcf6 commit d608a44
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 36 deletions.
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;
};

0 comments on commit d608a44

Please sign in to comment.