Skip to content

Commit

Permalink
chore: fix compile things
Browse files Browse the repository at this point in the history
  • Loading branch information
0xApotheosis committed Apr 17, 2024
1 parent 2bc0d08 commit 505426d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
10 changes: 5 additions & 5 deletions scripts/rewards-distribution/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Address, parseAbiItem } from "viem";
import { StakingLog } from "./events";
import { assertUnreachable } from "./helpers";
import { simulateStaking } from "./simulateStaking";
import { localPublicClient } from "./constants";
import { StakingLog } from "./events.ts";
import { assertUnreachable } from "./helpers.ts";
import { simulateStaking } from "./simulateStaking.ts";
import { localPublicClient } from "./constants.ts";

const getLogs = async ({
fromBlock,
Expand Down Expand Up @@ -30,7 +30,7 @@ const getStakingAmount = (log: StakingLog): bigint => {
case "Stake":
return log.args.amount;
case "Unstake":
return -log.args.amount;
return -BigInt(log.args.amount);
default:
assertUnreachable(log.eventName);
}
Expand Down
30 changes: 20 additions & 10 deletions scripts/rewards-distribution/simulateStaking.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Address, formatUnits, parseUnits } from "viem";
import { Hex } from "viem";

import FoxStaking from "../../foundry/out/FoxStakingV1.sol/FOXStakingV1.json";
import MockFOXToken from "../../foundry/out/MockFOXToken.sol/MockFOXToken.json";
import { localPublicClient, localWalletClient } from "./constants";
import { foxStakingV1Abi } from "./src/generated.ts";
import FoxStaking from "../../foundry/out/FoxStakingV1.sol/FOXStakingV1.json";
import { localPublicClient, localWalletClient } from "./constants.ts";

export const simulateStaking = async () => {
const walletClient = localWalletClient;
Expand All @@ -22,10 +23,14 @@ export const simulateStaking = async () => {
});
console.log(`MockFOXToken deployed to: ${mockFoxtokenContractAddress}`);

if (!mockFoxtokenContractAddress) {
throw new Error("FOXStaking contract address not found");
}

// Deploy the FOXStaking contract with the address of the deployed MockFOXToken as FOX

const mockFoxStakingDeployHash = await walletClient.deployContract({
abi: FoxStaking.abi,
abi: FoxStaking.abi, // foxStakingV1Abi has no args, work out why
account: alice,
bytecode: FoxStaking.bytecode.object as Hex,
args: [mockFoxtokenContractAddress],
Expand All @@ -35,6 +40,11 @@ export const simulateStaking = async () => {
await publicClient.waitForTransactionReceipt({
hash: mockFoxStakingDeployHash,
});

if (!mockFoxStakingContractAddress) {
throw new Error("FOXStaking contract address not found");
}

console.log(`FOXStaking deployed to: ${mockFoxStakingContractAddress}`);

const foxDecimals = (await publicClient.readContract({
Expand Down Expand Up @@ -80,11 +90,11 @@ export const simulateStaking = async () => {
);

const stakeTxHash = await walletClient.writeContract({
address: mockFoxStakingContractAddress as Address,
abi: FoxStaking.abi,
address: mockFoxStakingContractAddress,
abi: foxStakingV1Abi,
account: bob,
functionName: "stake",
args: [amountToStakeCryptoBaseUnit],
args: [amountToStakeCryptoBaseUnit, ""], // FIXME: add the runeAddress
});

const { transactionHash: stakeTransactionHash } =
Expand All @@ -93,12 +103,12 @@ export const simulateStaking = async () => {
`Staked ${amountToStakeCryptoPrecision} FOX from Bob to FOXStaking contract: ${stakeTransactionHash}`,
);

const bobStakedBalance = (await publicClient.readContract({
address: mockFoxStakingContractAddress as Address,
abi: FoxStaking.abi,
const bobStakedBalance = await publicClient.readContract({
address: mockFoxStakingContractAddress,
abi: foxStakingV1Abi,
functionName: "balanceOf",
args: [bob],
})) as number;
});

console.log(
`Bob's staked balance: ${formatUnits(BigInt(bobStakedBalance), foxDecimals)} FOX`,
Expand Down
7 changes: 3 additions & 4 deletions scripts/rewards-distribution/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 18",

"_version": "18.2.0",

"compilerOptions": {
"lib": ["es2023"],
"module": "node16",
"target": "es2022",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node16",
"resolveJsonModule": true
"resolveJsonModule": true,
"noEmit": true,
"allowImportingTsExtensions": true
}
}

0 comments on commit 505426d

Please sign in to comment.