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

chore: abi types #34

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 3 additions & 0 deletions scripts/rewards-distribution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. `yarn install` to install dependencies
1. `yarn wagmi generate` to generate typings from the compiled Foundry contracts
1. `npx ts-node scripts/rewards-distribution/index.ts` to run
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
2 changes: 2 additions & 0 deletions scripts/rewards-distribution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"version": "1.0.0",
"main": "index.ts",
"license": "MIT",
"type": "module",
"devDependencies": {
"@types/node": "^20.12.4",
"ts-node": "^10.9.2",
"typescript": "^5.4.4"
},
"dependencies": {
"@wagmi/cli": "^2.1.4",
"viem": "^2.9.9"
}
}
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 MockFOXToken from "../../foundry/out/MockFOXToken.sol/MockFOXToken.json" with { type: "json" };
import { foxStakingV1Abi } from "./src/generated.ts";
import FoxStaking from "../../foundry/out/FoxStakingV1.sol/FOXStakingV1.json";
import MockFOXToken from "../../foundry/out/MockFOXToken.sol/MockFOXToken.json";
import { localPublicClient, localWalletClient } from "./constants";
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
14 changes: 8 additions & 6 deletions scripts/rewards-distribution/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 18",

"_version": "18.2.0",

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

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node16",
"resolveJsonModule": true
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"noEmit": true,
"allowImportingTsExtensions": true
},
"ts-node": {
"esm": true
}
}
16 changes: 16 additions & 0 deletions scripts/rewards-distribution/wagmi.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from "@wagmi/cli";
import { foundry } from "@wagmi/cli/plugins";
import { type FoundryConfig } from "@wagmi/cli/plugins";

const foundryConfig: FoundryConfig = {
project: "../../foundry",
artifacts: "out/",
// We need to explicitly whitelist the contracts we want, else we get duplicate contract names from the Foundry contracts
include: ["FoxStakingV1.sol/**", "StakingInfo.sol/**"],
};

export default defineConfig({
out: "src/generated.ts",
contracts: [],
plugins: [foundry(foundryConfig)],
});
Loading