From c8d12d2f52f97d0514c58cc964e234d805871983 Mon Sep 17 00:00:00 2001 From: 0xean <0xean.eth@gmail.com> Date: Fri, 17 May 2024 17:23:06 -0400 Subject: [PATCH] feat: refactor for staking token to be generic (#43) * feat: refactor for staking token to be generic * adds all miissing files * clean up * more cleanup * feat: wagmi config, regen, and renamg imports in rewards-distribution --------- Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com> --- foundry/.env.arbitrum-one.example | 2 +- foundry/.env.arbitrum-sepolia.example | 2 +- foundry/.env.local.example | 2 +- foundry/.env.mainnet.example | 2 +- foundry/.env.sepolia.example | 2 +- foundry/README.md | 16 +- foundry/deploy.sh | 4 +- foundry/script/DeployFoxStaking.s.sol | 25 -- foundry/script/DeployStaking.s.sol | 25 ++ .../src/{FoxStakingV1.sol => StakingV1.sol} | 35 +- ...ting.t.sol => StakingTestAcocunting.t.sol} | 12 +- ...rship.t.sol => StakingTestOwnership.t.sol} | 14 +- ...ess.t.sol => StakingTestRuneAddress.t.sol} | 12 +- ...Staking.t.sol => StakingTestStaking.t.sol} | 14 +- ...Unstake.t.sol => StakingTestUnstake.t.sol} | 12 +- ...grades.t.sol => StakingTestUpgrades.t.sol} | 20 +- ...Version.t.sol => StakingTestVersion.t.sol} | 14 +- ...thdraw.t.sol => StakingTestWithdraw.t.sol} | 12 +- ...MockFoxStakingV2.sol => MockStakingV2.sol} | 6 +- ...stDeployer.sol => StakingTestDeployer.sol} | 10 +- foundry/test/utils/UpgradeHelper.sol | 8 +- .../generated/abi-types.ts | 425 ++++++++++-------- .../rewards-distribution/simulateStaking.ts | 40 +- scripts/rewards-distribution/wagmi.config.ts | 2 +- 24 files changed, 392 insertions(+), 324 deletions(-) delete mode 100644 foundry/script/DeployFoxStaking.s.sol create mode 100644 foundry/script/DeployStaking.s.sol rename foundry/src/{FoxStakingV1.sol => StakingV1.sol} (91%) rename foundry/test/{FOXStakingTestAcocunting.t.sol => StakingTestAcocunting.t.sol} (98%) rename foundry/test/{FOXStakingTestOwnership.t.sol => StakingTestOwnership.t.sol} (78%) rename foundry/test/{FOXStakingTestRuneAddress.t.sol => StakingTestRuneAddress.t.sol} (86%) rename foundry/test/{FOXStakingTestStaking.t.sol => StakingTestStaking.t.sol} (95%) rename foundry/test/{FOXStakingTestUnstake.t.sol => StakingTestUnstake.t.sol} (98%) rename foundry/test/{FoxStakingTestUpgrades.t.sol => StakingTestUpgrades.t.sol} (78%) rename foundry/test/{FoxStakingTestVersion.t.sol => StakingTestVersion.t.sol} (59%) rename foundry/test/{FOXStakingTestWithdraw.t.sol => StakingTestWithdraw.t.sol} (94%) rename foundry/test/utils/{MockFoxStakingV2.sol => MockStakingV2.sol} (95%) rename foundry/test/utils/{FoxStakingTestDeployer.sol => StakingTestDeployer.sol} (74%) diff --git a/foundry/.env.arbitrum-one.example b/foundry/.env.arbitrum-one.example index 10b3c58..e85a17b 100644 --- a/foundry/.env.arbitrum-one.example +++ b/foundry/.env.arbitrum-one.example @@ -1,5 +1,5 @@ ETHERSCAN_API_KEY="" # this must be an arbiscan api key -FOX_TOKEN_ADDRESS="" +STAKING_TOKEN_ADDRESS="" PRIVATE_KEY="" RPC_URL="https://arbitrum-mainnet.infura.io/v3/" VERIFIER_URL="https://api.arbiscan.io/api" diff --git a/foundry/.env.arbitrum-sepolia.example b/foundry/.env.arbitrum-sepolia.example index 56ce63a..ca5b0d8 100644 --- a/foundry/.env.arbitrum-sepolia.example +++ b/foundry/.env.arbitrum-sepolia.example @@ -1,5 +1,5 @@ ETHERSCAN_API_KEY="" # this must be an arbiscan api key -FOX_TOKEN_ADDRESS="" +STAKING_TOKEN_ADDRESS="" PRIVATE_KEY="" RPC_URL="https://arbitrum-sepolia.infura.io/v3/" VERIFIER_URL="https://api-sepolia.arbiscan.io/api" diff --git a/foundry/.env.local.example b/foundry/.env.local.example index 1b38de9..77dc980 100644 --- a/foundry/.env.local.example +++ b/foundry/.env.local.example @@ -1,5 +1,5 @@ ETHERSCAN_API_KEY="not-required" -FOX_TOKEN_ADDRESS="0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d" +STAKING_TOKEN_ADDRESS="0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d" PRIVATE_KEY="" RPC_URL="http://localhost:8545" VERIFIER_URL="not-required" diff --git a/foundry/.env.mainnet.example b/foundry/.env.mainnet.example index 88e5af4..81f32ee 100644 --- a/foundry/.env.mainnet.example +++ b/foundry/.env.mainnet.example @@ -1,5 +1,5 @@ ETHERSCAN_API_KEY="" -FOX_TOKEN_ADDRESS="0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d" +STAKING_TOKEN_ADDRESS="0xc770EEfAd204B5180dF6a14Ee197D99d808ee52d" PRIVATE_KEY="" RPC_URL="https://mainnet.infura.io/v3/" VERIFIER_URL="https://api.etherscan.io/api" diff --git a/foundry/.env.sepolia.example b/foundry/.env.sepolia.example index d139d8a..9f192c6 100644 --- a/foundry/.env.sepolia.example +++ b/foundry/.env.sepolia.example @@ -1,5 +1,5 @@ ETHERSCAN_API_KEY="" -FOX_TOKEN_ADDRESS="" +STAKING_TOKEN_ADDRESS="" PRIVATE_KEY="" RPC_URL="https://sepolia.infura.io/v3/" VERIFIER_URL="https://api-sepolia.etherscan.io/api" diff --git a/foundry/README.md b/foundry/README.md index e8d33d0..7766224 100644 --- a/foundry/README.md +++ b/foundry/README.md @@ -5,11 +5,11 @@ 1. Install foundry https://book.getfoundry.sh/getting-started/installation 2. Install slither `brew install slither-analyzer` 3. Set up .env files: - 1. Copy an example .env file for your chosen environment: - ```shell - cp .env..example .env. - ``` - 2. Fill in the needed env vars there + 1. Copy an example .env file for your chosen environment: + ```shell + cp .env..example .env. + ``` + 2. Fill in the needed env vars there ### Private key @@ -32,7 +32,9 @@ https://faucet.circle.com/ ## Deploying ### Local deployment + Deploying locally is different to deploying directly to a network for 2 reasons: + 1. Its being deployed to a fork of another network (typically ethereum mainnet) rather than a real network. 2. There's no local instance of etherscan, so etherscan verification is skipped. @@ -46,7 +48,7 @@ anvil --rpc-url $RPC_URL ### Deployment steps ```shell -cd foundry +cd foundry # Install forge install @@ -70,5 +72,5 @@ forge verify-contract \ --compiler-version "v0.8.25" \ --etherscan-api-key $ARBISCAN_API_KEY \ $CONTRACT_IMPLEMENTATION_ADDRESS \ - src/FoxStakingV1.sol:FoxStakingV1 + src/StakingV1.sol:StakingV1 ``` diff --git a/foundry/deploy.sh b/foundry/deploy.sh index c8cdeac..d4dfb5a 100755 --- a/foundry/deploy.sh +++ b/foundry/deploy.sh @@ -35,14 +35,14 @@ forge clean if [ "$ENVIRONMENT" = "local" ]; then # Local environment-specific commands (no etherscan verification) - FOX_TOKEN_ADDRESS="$FOX_TOKEN_ADDRESS" forge script script/DeployFoxStaking.s.sol:DeployFoxStaking \ + STAKING_TOKEN_ADDRESS="$STAKING_TOKEN_ADDRESS" forge script script/DeployStaking.s.sol:DeployStaking \ --fork-url $RPC_URL \ --private-key $PRIVATE_KEY \ --broadcast \ -vvvvv else # All other environments use etherscan verification (which automatically reroutes to arbiscan as needed) - FOX_TOKEN_ADDRESS="$FOX_TOKEN_ADDRESS" forge script script/DeployFoxStaking.s.sol:DeployFoxStaking \ + STAKING_TOKEN_ADDRESS="$STAKING_TOKEN_ADDRESS" forge script script/DeployStaking.s.sol:DeployStaking \ --rpc-url $RPC_URL \ --private-key $PRIVATE_KEY \ --broadcast \ diff --git a/foundry/script/DeployFoxStaking.s.sol b/foundry/script/DeployFoxStaking.s.sol deleted file mode 100644 index 592d774..0000000 --- a/foundry/script/DeployFoxStaking.s.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.25; - -import "forge-std/Script.sol"; -import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; -import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; - -contract DeployFoxStaking is Script { - address foxTokenAddress; - - function setUp() public { - foxTokenAddress = vm.envAddress("FOX_TOKEN_ADDRESS"); - } - - function run() public { - vm.startBroadcast(); - address foxStakingProxy = Upgrades.deployUUPSProxy( - "FoxStakingV1.sol", - abi.encodeCall(FoxStakingV1.initialize, (foxTokenAddress)) - ); - vm.stopBroadcast(); - console.log("Contract deployed at:", foxStakingProxy); - } -} diff --git a/foundry/script/DeployStaking.s.sol b/foundry/script/DeployStaking.s.sol new file mode 100644 index 0000000..79e9864 --- /dev/null +++ b/foundry/script/DeployStaking.s.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.25; + +import "forge-std/Script.sol"; +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; +import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol"; +import {StakingV1} from "../src/StakingV1.sol"; + +contract DeployStaking is Script { + address stakingTokenAddress; + + function setUp() public { + stakingTokenAddress = vm.envAddress("STAKING_TOKEN_ADDRESS"); + } + + function run() public { + vm.startBroadcast(); + address stakingProxy = Upgrades.deployUUPSProxy( + "StakingV1.sol", + abi.encodeCall(StakingV1.initialize, (stakingTokenAddress)) + ); + vm.stopBroadcast(); + console.log("Contract deployed at:", stakingProxy); + } +} diff --git a/foundry/src/FoxStakingV1.sol b/foundry/src/StakingV1.sol similarity index 91% rename from foundry/src/FoxStakingV1.sol rename to foundry/src/StakingV1.sol index bc55207..42e0dc2 100644 --- a/foundry/src/FoxStakingV1.sol +++ b/foundry/src/StakingV1.sol @@ -11,7 +11,7 @@ import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/ut import {StakingInfo} from "./StakingInfo.sol"; import {UnstakingRequest} from "./UnstakingRequest.sol"; -contract FoxStakingV1 is +contract StakingV1 is Initializable, PausableUpgradeable, UUPSUpgradeable, @@ -19,7 +19,7 @@ contract FoxStakingV1 is ReentrancyGuardUpgradeable { using SafeERC20 for IERC20; - IERC20 public foxToken; + IERC20 public stakingToken; mapping(address => StakingInfo) public stakingInfo; bool public stakingPaused; bool public withdrawalsPaused; @@ -57,11 +57,11 @@ contract FoxStakingV1 is _disableInitializers(); } - function initialize(address foxTokenAddress) external initializer { + function initialize(address stakingTokenAddress) external initializer { __Ownable_init(msg.sender); __UUPSUpgradeable_init(); __Pausable_init(); - foxToken = IERC20(foxTokenAddress); + stakingToken = IERC20(stakingTokenAddress); cooldownPeriod = 28 days; lastUpdateTimestamp = block.timestamp; } @@ -158,10 +158,10 @@ contract FoxStakingV1 is info.earnedRewards; } - /// @notice Allows a user to stake a specified amount of FOX tokens and assign a RUNE address for rewards - which can be changed later on. + /// @notice Allows a user to stake a specified amount of staking tokens and assign a RUNE address for rewards - which can be changed later on. /// This has to be initiated by the user itself i.e msg.sender only, cannot be called by an address for another - /// @param amount The amount of FOX tokens to be staked. - /// @param runeAddress The RUNE address to be associated with the user's staked FOX position. + /// @param amount The amount of staking tokens to be staked. + /// @param runeAddress The RUNE address to be associated with the user's staked staking position. function stake( uint256 amount, string memory runeAddress @@ -170,9 +170,9 @@ contract FoxStakingV1 is bytes(runeAddress).length == 43, "Rune address must be 43 characters" ); - require(amount > 0, "FOX amount to stake must be greater than 0"); + require(amount > 0, "amount to stake must be greater than 0"); updateReward(msg.sender); - foxToken.safeTransferFrom(msg.sender, address(this), amount); + stakingToken.safeTransferFrom(msg.sender, address(this), amount); StakingInfo storage info = stakingInfo[msg.sender]; info.stakingBalance += amount; @@ -182,9 +182,9 @@ contract FoxStakingV1 is emit Stake(msg.sender, amount, runeAddress); } - /// @notice Initiates the unstake process for a specified amount of FOX, starting the cooldown period (28 days). + /// @notice Initiates the unstake process for a specified amount of staking token, starting the cooldown period (28 days). /// This has to be initiated by the user itself i.e msg.sender only, cannot be called by an address for another - /// @param amount The amount of FOX tokens to be unstaked. + /// @param amount The amount of staking tokens to be unstaked. function unstake( uint256 amount ) external whenNotPaused whenUnstakingNotPaused nonReentrant { @@ -249,7 +249,10 @@ contract FoxStakingV1 is } info.unstakingBalance -= unstakingRequest.unstakingBalance; totalCoolingDown -= unstakingRequest.unstakingBalance; - foxToken.safeTransfer(msg.sender, unstakingRequest.unstakingBalance); + stakingToken.safeTransfer( + msg.sender, + unstakingRequest.unstakingBalance + ); emit Withdraw(msg.sender, unstakingRequest.unstakingBalance); } @@ -284,7 +287,7 @@ contract FoxStakingV1 is /// @notice Allows a user to initially set (or update) their THORChain (RUNE) address for receiving staking rewards. /// This has to be initiated by the user itself i.e msg.sender only, cannot be called by an address for another - /// @param runeAddress The new RUNE address to be associated with the user's staked FOX position. + /// @param runeAddress The new RUNE address to be associated with the user's staked position. function setRuneAddress(string memory runeAddress) external { require( bytes(runeAddress).length == 43, @@ -296,10 +299,10 @@ contract FoxStakingV1 is emit SetRuneAddress(msg.sender, oldRuneAddress, runeAddress); } - /// @notice View the staked balance of FOX tokens for a given address. + /// @notice View the staked balance of tokens for a given address. /// This can be initiated by any address with any address as param, as this has view modifier i.e everything is public on-chain - /// @param account The address we're getting the staked FOX balance for. - /// @return total The total amount of FOX tokens held. + /// @param account The address we're getting the staked staking balance for. + /// @return total The total amount of staking tokens held. function balanceOf(address account) external view returns (uint256 total) { StakingInfo memory info = stakingInfo[account]; return info.stakingBalance + info.unstakingBalance; diff --git a/foundry/test/FOXStakingTestAcocunting.t.sol b/foundry/test/StakingTestAcocunting.t.sol similarity index 98% rename from foundry/test/FOXStakingTestAcocunting.t.sol rename to foundry/test/StakingTestAcocunting.t.sol index bcd97f4..a537bfe 100644 --- a/foundry/test/FOXStakingTestAcocunting.t.sol +++ b/foundry/test/StakingTestAcocunting.t.sol @@ -4,14 +4,14 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; import "forge-std/console.sol"; import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; +import {StakingV1} from "../src/StakingV1.sol"; import {StakingInfo} from "../src/StakingInfo.sol"; import {MockFOXToken} from "./utils/MockFOXToken.sol"; -import {FoxStakingTestDeployer} from "./utils/FoxStakingTestDeployer.sol"; +import {StakingTestDeployer} from "./utils/StakingTestDeployer.sol"; contract FOXStakingTestStaking is Test { - FoxStakingTestDeployer public deployer; - FoxStakingV1 public foxStaking; + StakingTestDeployer public deployer; + StakingV1 public foxStaking; MockFOXToken public foxToken; address userOne = address(0xBEEF); address userTwo = address(0xDEAD); @@ -27,12 +27,12 @@ contract FOXStakingTestStaking is Test { function setUp() public { foxToken = new MockFOXToken(); - deployer = new FoxStakingTestDeployer(); + deployer = new StakingTestDeployer(); address proxyAddress = deployer.deployV1( address(this), address(foxToken) ); - foxStaking = FoxStakingV1(proxyAddress); + foxStaking = StakingV1(proxyAddress); // Free FOX tokens for users foxToken.makeItRain(userOne, amount); diff --git a/foundry/test/FOXStakingTestOwnership.t.sol b/foundry/test/StakingTestOwnership.t.sol similarity index 78% rename from foundry/test/FOXStakingTestOwnership.t.sol rename to foundry/test/StakingTestOwnership.t.sol index dae90da..a38c13e 100644 --- a/foundry/test/FOXStakingTestOwnership.t.sol +++ b/foundry/test/StakingTestOwnership.t.sol @@ -3,24 +3,24 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; +import {StakingV1} from "../src/StakingV1.sol"; import {MockFOXToken} from "./utils/MockFOXToken.sol"; -import {FoxStakingTestDeployer} from "./utils/FoxStakingTestDeployer.sol"; +import {StakingTestDeployer} from "./utils/StakingTestDeployer.sol"; -contract FOXStakingTestOwnership is Test { - FoxStakingTestDeployer public deployer; - FoxStakingV1 public foxStaking; +contract StakingTestOwnership is Test { + StakingTestDeployer public deployer; + StakingV1 public foxStaking; MockFOXToken public foxToken; address nonOwner = 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045; function setUp() public { foxToken = new MockFOXToken(); - deployer = new FoxStakingTestDeployer(); + deployer = new StakingTestDeployer(); address proxyAddress = deployer.deployV1( address(this), address(foxToken) ); - foxStaking = FoxStakingV1(proxyAddress); + foxStaking = StakingV1(proxyAddress); } function testOwnerCanUpdateCooldownPeriod() public { diff --git a/foundry/test/FOXStakingTestRuneAddress.t.sol b/foundry/test/StakingTestRuneAddress.t.sol similarity index 86% rename from foundry/test/FOXStakingTestRuneAddress.t.sol rename to foundry/test/StakingTestRuneAddress.t.sol index 91390cc..0c3775f 100644 --- a/foundry/test/FOXStakingTestRuneAddress.t.sol +++ b/foundry/test/StakingTestRuneAddress.t.sol @@ -2,24 +2,24 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; +import {StakingV1} from "../src/StakingV1.sol"; import {MockFOXToken} from "./utils/MockFOXToken.sol"; -import {FoxStakingTestDeployer} from "./utils/FoxStakingTestDeployer.sol"; +import {StakingTestDeployer} from "./utils/StakingTestDeployer.sol"; contract FOXStakingTestRuneAddress is Test { - FoxStakingTestDeployer public deployer; - FoxStakingV1 public foxStaking; + StakingTestDeployer public deployer; + StakingV1 public foxStaking; MockFOXToken public foxToken; address user = address(0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045); function setUp() public { foxToken = new MockFOXToken(); - deployer = new FoxStakingTestDeployer(); + deployer = new StakingTestDeployer(); address proxyAddress = deployer.deployV1( address(this), address(foxToken) ); - foxStaking = FoxStakingV1(proxyAddress); + foxStaking = StakingV1(proxyAddress); } function testCanSetRuneAddress() public { diff --git a/foundry/test/FOXStakingTestStaking.t.sol b/foundry/test/StakingTestStaking.t.sol similarity index 95% rename from foundry/test/FOXStakingTestStaking.t.sol rename to foundry/test/StakingTestStaking.t.sol index 2fb385e..f8f0dfa 100644 --- a/foundry/test/FOXStakingTestStaking.t.sol +++ b/foundry/test/StakingTestStaking.t.sol @@ -3,24 +3,24 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; +import {StakingV1} from "../src/StakingV1.sol"; import {StakingInfo} from "../src/StakingInfo.sol"; import {MockFOXToken} from "./utils/MockFOXToken.sol"; -import {FoxStakingTestDeployer} from "./utils/FoxStakingTestDeployer.sol"; +import {StakingTestDeployer} from "./utils/StakingTestDeployer.sol"; contract FOXStakingTestStaking is Test { - FoxStakingTestDeployer public deployer; - FoxStakingV1 public foxStaking; + StakingTestDeployer public deployer; + StakingV1 public foxStaking; MockFOXToken public foxToken; function setUp() public { foxToken = new MockFOXToken(); - deployer = new FoxStakingTestDeployer(); + deployer = new StakingTestDeployer(); address proxyAddress = deployer.deployV1( address(this), address(foxToken) ); - foxStaking = FoxStakingV1(proxyAddress); + foxStaking = StakingV1(proxyAddress); } function testCannotStakeWhenStakingPaused() public { @@ -154,7 +154,7 @@ contract FOXStakingTestStaking is Test { vm.assertEq(unstakingBalance, 0); // Try to stake 0 - vm.expectRevert("FOX amount to stake must be greater than 0"); + vm.expectRevert("amount to stake must be greater than 0"); foxStaking.stake(0, runeAddress); // Check user staking balances are unchanged diff --git a/foundry/test/FOXStakingTestUnstake.t.sol b/foundry/test/StakingTestUnstake.t.sol similarity index 98% rename from foundry/test/FOXStakingTestUnstake.t.sol rename to foundry/test/StakingTestUnstake.t.sol index 8842835..d7f1c84 100644 --- a/foundry/test/FOXStakingTestUnstake.t.sol +++ b/foundry/test/StakingTestUnstake.t.sol @@ -3,13 +3,13 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; +import {StakingV1} from "../src/StakingV1.sol"; import {MockFOXToken} from "./utils/MockFOXToken.sol"; -import {FoxStakingTestDeployer} from "./utils/FoxStakingTestDeployer.sol"; +import {StakingTestDeployer} from "./utils/StakingTestDeployer.sol"; contract FOXStakingTestUnstake is Test { - FoxStakingTestDeployer public deployer; - FoxStakingV1 public foxStaking; + StakingTestDeployer public deployer; + StakingV1 public foxStaking; MockFOXToken public foxToken; address user = address(0xBEEF); address user2 = address(0xDEAD); @@ -19,12 +19,12 @@ contract FOXStakingTestUnstake is Test { function setUp() public { foxToken = new MockFOXToken(); - deployer = new FoxStakingTestDeployer(); + deployer = new StakingTestDeployer(); address proxyAddress = deployer.deployV1( address(this), address(foxToken) ); - foxStaking = FoxStakingV1(proxyAddress); + foxStaking = StakingV1(proxyAddress); // Free FOX tokens for user foxToken.makeItRain(user, amount); diff --git a/foundry/test/FoxStakingTestUpgrades.t.sol b/foundry/test/StakingTestUpgrades.t.sol similarity index 78% rename from foundry/test/FoxStakingTestUpgrades.t.sol rename to foundry/test/StakingTestUpgrades.t.sol index 38c1077..46bf137 100644 --- a/foundry/test/FoxStakingTestUpgrades.t.sol +++ b/foundry/test/StakingTestUpgrades.t.sol @@ -4,18 +4,18 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; +import {StakingV1} from "../src/StakingV1.sol"; import {MockFOXToken} from "./utils/MockFOXToken.sol"; -import {MockFoxStakingV2} from "./utils/MockFoxStakingV2.sol"; +import {MockStakingV2} from "./utils/MockStakingV2.sol"; import {UpgradeHelper} from "./utils/UpgradeHelper.sol"; contract FoxStakingTestUpgrades is Test { address public owner = address(0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045); address public foxStakingProxy; - FoxStakingV1 public foxStakingV1; + StakingV1 public foxStakingV1; MockFOXToken public foxToken; - // NOTE: Do NOT use the FoxStakingTestDeployer, we're testing actual upgrades without the code + // NOTE: Do NOT use the StakingTestDeployer, we're testing actual upgrades without the code // coverage workaround here. UpgradeHelper public upgradeHelper; @@ -25,12 +25,12 @@ contract FoxStakingTestUpgrades is Test { vm.startPrank(owner); foxStakingProxy = Upgrades.deployUUPSProxy( - "FoxStakingV1.sol", - abi.encodeCall(FoxStakingV1.initialize, (address(foxToken))) + "StakingV1.sol", + abi.encodeCall(StakingV1.initialize, (address(foxToken))) ); vm.stopPrank(); - foxStakingV1 = FoxStakingV1(foxStakingProxy); + foxStakingV1 = StakingV1(foxStakingProxy); } function testDeployerIsOwner() public view { @@ -44,15 +44,15 @@ contract FoxStakingTestUpgrades is Test { // Check we cannot call the new function vm.expectRevert(); - MockFoxStakingV2 fakeUpgradedFoxStakingV1 = MockFoxStakingV2( + MockStakingV2 fakeUpgradedStakingV1 = MockStakingV2( address(foxStakingV1) ); - fakeUpgradedFoxStakingV1.newV2Function(); + fakeUpgradedStakingV1.newV2Function(); // Perform the upgrade upgradeHelper.doUpgrade(owner, foxStakingProxy); - MockFoxStakingV2 foxStakingV2 = MockFoxStakingV2(foxStakingProxy); + MockStakingV2 foxStakingV2 = MockStakingV2(foxStakingProxy); // Check the new version uint256 expectedUpgradedVersion = 2; diff --git a/foundry/test/FoxStakingTestVersion.t.sol b/foundry/test/StakingTestVersion.t.sol similarity index 59% rename from foundry/test/FoxStakingTestVersion.t.sol rename to foundry/test/StakingTestVersion.t.sol index 4a5c9a6..6c510e3 100644 --- a/foundry/test/FoxStakingTestVersion.t.sol +++ b/foundry/test/StakingTestVersion.t.sol @@ -2,23 +2,23 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; +import {StakingV1} from "../src/StakingV1.sol"; import {MockFOXToken} from "./utils/MockFOXToken.sol"; -import {FoxStakingTestDeployer} from "./utils/FoxStakingTestDeployer.sol"; +import {StakingTestDeployer} from "./utils/StakingTestDeployer.sol"; -contract FOXStakingTestOwnership is Test { - FoxStakingTestDeployer public deployer; - FoxStakingV1 public foxStaking; +contract StakingTestOwnership is Test { + StakingTestDeployer public deployer; + StakingV1 public foxStaking; MockFOXToken public foxToken; function setUp() public { foxToken = new MockFOXToken(); - deployer = new FoxStakingTestDeployer(); + deployer = new StakingTestDeployer(); address proxyAddress = deployer.deployV1( address(this), address(foxToken) ); - foxStaking = FoxStakingV1(proxyAddress); + foxStaking = StakingV1(proxyAddress); } function testCanGetVersion() public view { diff --git a/foundry/test/FOXStakingTestWithdraw.t.sol b/foundry/test/StakingTestWithdraw.t.sol similarity index 94% rename from foundry/test/FOXStakingTestWithdraw.t.sol rename to foundry/test/StakingTestWithdraw.t.sol index 254ddf8..6b81e30 100644 --- a/foundry/test/FOXStakingTestWithdraw.t.sol +++ b/foundry/test/StakingTestWithdraw.t.sol @@ -3,13 +3,13 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol"; -import {FoxStakingV1} from "../src/FoxStakingV1.sol"; +import {StakingV1} from "../src/StakingV1.sol"; import {MockFOXToken} from "./utils/MockFOXToken.sol"; -import {FoxStakingTestDeployer} from "./utils/FoxStakingTestDeployer.sol"; +import {StakingTestDeployer} from "./utils/StakingTestDeployer.sol"; contract FOXStakingTestWithdraw is Test { - FoxStakingTestDeployer public deployer; - FoxStakingV1 public foxStaking; + StakingTestDeployer public deployer; + StakingV1 public foxStaking; MockFOXToken public foxToken; address user = address(0xBEEF); uint256 amount = 1000; @@ -18,12 +18,12 @@ contract FOXStakingTestWithdraw is Test { function setUp() public { foxToken = new MockFOXToken(); - deployer = new FoxStakingTestDeployer(); + deployer = new StakingTestDeployer(); address proxyAddress = deployer.deployV1( address(this), address(foxToken) ); - foxStaking = FoxStakingV1(proxyAddress); + foxStaking = StakingV1(proxyAddress); // Free FOX tokens for user foxToken.makeItRain(user, amount); diff --git a/foundry/test/utils/MockFoxStakingV2.sol b/foundry/test/utils/MockStakingV2.sol similarity index 95% rename from foundry/test/utils/MockFoxStakingV2.sol rename to foundry/test/utils/MockStakingV2.sol index e3fc2e9..8190f13 100644 --- a/foundry/test/utils/MockFoxStakingV2.sol +++ b/foundry/test/utils/MockStakingV2.sol @@ -12,8 +12,8 @@ import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/ut import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {StakingInfo} from "../../src/StakingInfo.sol"; -/// @custom:oz-upgrades-from FoxStakingV1 -contract MockFoxStakingV2 is +/// @custom:oz-upgrades-from StakingV1 +contract MockStakingV2 is Initializable, PausableUpgradeable, UUPSUpgradeable, @@ -21,7 +21,7 @@ contract MockFoxStakingV2 is ReentrancyGuardUpgradeable { using SafeERC20 for IERC20; - IERC20 public foxToken; + IERC20 public stakingToken; mapping(address => StakingInfo) public stakingInfo; bool public stakingPaused; bool public withdrawalsPaused; diff --git a/foundry/test/utils/FoxStakingTestDeployer.sol b/foundry/test/utils/StakingTestDeployer.sol similarity index 74% rename from foundry/test/utils/FoxStakingTestDeployer.sol rename to foundry/test/utils/StakingTestDeployer.sol index 6a60a0c..5972201 100644 --- a/foundry/test/utils/FoxStakingTestDeployer.sol +++ b/foundry/test/utils/StakingTestDeployer.sol @@ -3,23 +3,23 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; -import {FoxStakingV1} from "../../src/FoxStakingV1.sol"; -import {MockFoxStakingV2} from "./MockFoxStakingV2.sol"; +import {StakingV1} from "../../src/StakingV1.sol"; +import {MockStakingV2} from "./MockStakingV2.sol"; import {console2} from "forge-std/Test.sol"; /// @notice This contract is used to deploy the FoxStaking contract for testing purposes only. /// This is a workaround for an issue with the OpenZeppelin Upgrades Plugins breaking code coverage /// reporting with proxies: /// https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/issues/2 -contract FoxStakingTestDeployer is Test { +contract StakingTestDeployer is Test { function deployV1( address owner, address foxTokenAddress ) public returns (address) { vm.startPrank(owner); - FoxStakingV1 implementation = new FoxStakingV1(); + StakingV1 implementation = new StakingV1(); ERC1967Proxy proxy = new ERC1967Proxy(address(implementation), ""); - FoxStakingV1(address(proxy)).initialize(foxTokenAddress); + StakingV1(address(proxy)).initialize(foxTokenAddress); vm.stopPrank(); return address(proxy); diff --git a/foundry/test/utils/UpgradeHelper.sol b/foundry/test/utils/UpgradeHelper.sol index e7994ee..37575f1 100644 --- a/foundry/test/utils/UpgradeHelper.sol +++ b/foundry/test/utils/UpgradeHelper.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.25; import "forge-std/Test.sol"; import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol"; -import {FoxStakingV1} from "../../src/FoxStakingV1.sol"; -import {MockFoxStakingV2} from "./MockFoxStakingV2.sol"; +import {StakingV1} from "../../src/StakingV1.sol"; +import {MockStakingV2} from "./MockStakingV2.sol"; contract UpgradeHelper is Test { /// @dev Wrapper to perform upgrades pranking the owner. Required to make revert reasons @@ -15,8 +15,8 @@ contract UpgradeHelper is Test { vm.startPrank(prankOwner); Upgrades.upgradeProxy( proxy, - "MockFoxStakingV2.sol:MockFoxStakingV2", - abi.encodeCall(MockFoxStakingV2.initialize, ()) + "MockStakingV2.sol:MockStakingV2", + abi.encodeCall(MockStakingV2.initialize, ()) ); vm.stopPrank; } diff --git a/scripts/rewards-distribution/generated/abi-types.ts b/scripts/rewards-distribution/generated/abi-types.ts index 6ee8d51..e2ab373 100644 --- a/scripts/rewards-distribution/generated/abi-types.ts +++ b/scripts/rewards-distribution/generated/abi-types.ts @@ -1,9 +1,188 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// FoxStakingV1 +// MockFOXToken +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +export const mockFoxTokenAbi = [ + { type: "constructor", inputs: [], stateMutability: "nonpayable" }, + { + type: "function", + inputs: [ + { name: "owner", internalType: "address", type: "address" }, + { name: "spender", internalType: "address", type: "address" }, + ], + name: "allowance", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "spender", internalType: "address", type: "address" }, + { name: "value", internalType: "uint256", type: "uint256" }, + ], + name: "approve", + outputs: [{ name: "", internalType: "bool", type: "bool" }], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "account", internalType: "address", type: "address" }], + name: "balanceOf", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "decimals", + outputs: [{ name: "", internalType: "uint8", type: "uint8" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "to", internalType: "address", type: "address" }, + { name: "amount", internalType: "uint256", type: "uint256" }, + ], + name: "makeItRain", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [], + name: "name", + outputs: [{ name: "", internalType: "string", type: "string" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "symbol", + outputs: [{ name: "", internalType: "string", type: "string" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "totalSupply", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "to", internalType: "address", type: "address" }, + { name: "value", internalType: "uint256", type: "uint256" }, + ], + name: "transfer", + outputs: [{ name: "", internalType: "bool", type: "bool" }], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "from", internalType: "address", type: "address" }, + { name: "to", internalType: "address", type: "address" }, + { name: "value", internalType: "uint256", type: "uint256" }, + ], + name: "transferFrom", + outputs: [{ name: "", internalType: "bool", type: "bool" }], + stateMutability: "nonpayable", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "owner", + internalType: "address", + type: "address", + indexed: true, + }, + { + name: "spender", + internalType: "address", + type: "address", + indexed: true, + }, + { + name: "value", + internalType: "uint256", + type: "uint256", + indexed: false, + }, + ], + name: "Approval", + }, + { + type: "event", + anonymous: false, + inputs: [ + { name: "from", internalType: "address", type: "address", indexed: true }, + { name: "to", internalType: "address", type: "address", indexed: true }, + { + name: "value", + internalType: "uint256", + type: "uint256", + indexed: false, + }, + ], + name: "Transfer", + }, + { + type: "error", + inputs: [ + { name: "spender", internalType: "address", type: "address" }, + { name: "allowance", internalType: "uint256", type: "uint256" }, + { name: "needed", internalType: "uint256", type: "uint256" }, + ], + name: "ERC20InsufficientAllowance", + }, + { + type: "error", + inputs: [ + { name: "sender", internalType: "address", type: "address" }, + { name: "balance", internalType: "uint256", type: "uint256" }, + { name: "needed", internalType: "uint256", type: "uint256" }, + ], + name: "ERC20InsufficientBalance", + }, + { + type: "error", + inputs: [{ name: "approver", internalType: "address", type: "address" }], + name: "ERC20InvalidApprover", + }, + { + type: "error", + inputs: [{ name: "receiver", internalType: "address", type: "address" }], + name: "ERC20InvalidReceiver", + }, + { + type: "error", + inputs: [{ name: "sender", internalType: "address", type: "address" }], + name: "ERC20InvalidSender", + }, + { + type: "error", + inputs: [{ name: "spender", internalType: "address", type: "address" }], + name: "ERC20InvalidSpender", + }, +] as const; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// StakingV1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -export const foxStakingV1Abi = [ +export const stakingV1Abi = [ { type: "constructor", inputs: [], stateMutability: "nonpayable" }, + { + type: "function", + inputs: [], + name: "REWARD_RATE", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, { type: "function", inputs: [], @@ -11,6 +190,13 @@ export const foxStakingV1Abi = [ outputs: [{ name: "", internalType: "string", type: "string" }], stateMutability: "view", }, + { + type: "function", + inputs: [], + name: "WAD", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, { type: "function", inputs: [{ name: "account", internalType: "address", type: "address" }], @@ -27,9 +213,9 @@ export const foxStakingV1Abi = [ }, { type: "function", - inputs: [], - name: "foxToken", - outputs: [{ name: "", internalType: "contract IERC20", type: "address" }], + inputs: [{ name: "account", internalType: "address", type: "address" }], + name: "earned", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], stateMutability: "view", }, { @@ -38,11 +224,11 @@ export const foxStakingV1Abi = [ { name: "account", internalType: "address", type: "address" }, { name: "index", internalType: "uint256", type: "uint256" }, ], - name: "getUnstakingInfo", + name: "getUnstakingRequest", outputs: [ { name: "", - internalType: "struct UnstakingInfo", + internalType: "struct UnstakingRequest", type: "tuple", components: [ { @@ -59,19 +245,26 @@ export const foxStakingV1Abi = [ { type: "function", inputs: [{ name: "account", internalType: "address", type: "address" }], - name: "getUnstakingInfoCount", + name: "getUnstakingRequestCount", outputs: [{ name: "", internalType: "uint256", type: "uint256" }], stateMutability: "view", }, { type: "function", inputs: [ - { name: "foxTokenAddress", internalType: "address", type: "address" }, + { name: "stakingTokenAddress", internalType: "address", type: "address" }, ], name: "initialize", outputs: [], stateMutability: "nonpayable", }, + { + type: "function", + inputs: [], + name: "lastUpdateTimestamp", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, { type: "function", inputs: [], @@ -128,6 +321,20 @@ export const foxStakingV1Abi = [ outputs: [], stateMutability: "nonpayable", }, + { + type: "function", + inputs: [], + name: "rewardPerToken", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "rewardPerTokenStored", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, { type: "function", inputs: [ @@ -161,6 +368,12 @@ export const foxStakingV1Abi = [ outputs: [ { name: "stakingBalance", internalType: "uint256", type: "uint256" }, { name: "unstakingBalance", internalType: "uint256", type: "uint256" }, + { name: "earnedRewards", internalType: "uint256", type: "uint256" }, + { + name: "rewardPerTokenStored", + internalType: "uint256", + type: "uint256", + }, { name: "runeAddress", internalType: "string", type: "string" }, ], stateMutability: "view", @@ -172,6 +385,27 @@ export const foxStakingV1Abi = [ outputs: [{ name: "", internalType: "bool", type: "bool" }], stateMutability: "view", }, + { + type: "function", + inputs: [], + name: "stakingToken", + outputs: [{ name: "", internalType: "contract IERC20", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "totalCoolingDown", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "totalStaked", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, { type: "function", inputs: [{ name: "newOwner", internalType: "address", type: "address" }], @@ -470,6 +704,7 @@ export const foxStakingV1Abi = [ inputs: [{ name: "account", internalType: "address", type: "address" }], name: "OwnableUnauthorizedAccount", }, + { type: "error", inputs: [], name: "ReentrancyGuardReentrantCall" }, { type: "error", inputs: [{ name: "token", internalType: "address", type: "address" }], @@ -482,175 +717,3 @@ export const foxStakingV1Abi = [ name: "UUPSUnsupportedProxiableUUID", }, ] as const; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// MockFOXToken -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -export const mockFoxTokenAbi = [ - { type: "constructor", inputs: [], stateMutability: "nonpayable" }, - { - type: "function", - inputs: [ - { name: "owner", internalType: "address", type: "address" }, - { name: "spender", internalType: "address", type: "address" }, - ], - name: "allowance", - outputs: [{ name: "", internalType: "uint256", type: "uint256" }], - stateMutability: "view", - }, - { - type: "function", - inputs: [ - { name: "spender", internalType: "address", type: "address" }, - { name: "value", internalType: "uint256", type: "uint256" }, - ], - name: "approve", - outputs: [{ name: "", internalType: "bool", type: "bool" }], - stateMutability: "nonpayable", - }, - { - type: "function", - inputs: [{ name: "account", internalType: "address", type: "address" }], - name: "balanceOf", - outputs: [{ name: "", internalType: "uint256", type: "uint256" }], - stateMutability: "view", - }, - { - type: "function", - inputs: [], - name: "decimals", - outputs: [{ name: "", internalType: "uint8", type: "uint8" }], - stateMutability: "view", - }, - { - type: "function", - inputs: [ - { name: "to", internalType: "address", type: "address" }, - { name: "amount", internalType: "uint256", type: "uint256" }, - ], - name: "makeItRain", - outputs: [], - stateMutability: "nonpayable", - }, - { - type: "function", - inputs: [], - name: "name", - outputs: [{ name: "", internalType: "string", type: "string" }], - stateMutability: "view", - }, - { - type: "function", - inputs: [], - name: "symbol", - outputs: [{ name: "", internalType: "string", type: "string" }], - stateMutability: "view", - }, - { - type: "function", - inputs: [], - name: "totalSupply", - outputs: [{ name: "", internalType: "uint256", type: "uint256" }], - stateMutability: "view", - }, - { - type: "function", - inputs: [ - { name: "to", internalType: "address", type: "address" }, - { name: "value", internalType: "uint256", type: "uint256" }, - ], - name: "transfer", - outputs: [{ name: "", internalType: "bool", type: "bool" }], - stateMutability: "nonpayable", - }, - { - type: "function", - inputs: [ - { name: "from", internalType: "address", type: "address" }, - { name: "to", internalType: "address", type: "address" }, - { name: "value", internalType: "uint256", type: "uint256" }, - ], - name: "transferFrom", - outputs: [{ name: "", internalType: "bool", type: "bool" }], - stateMutability: "nonpayable", - }, - { - type: "event", - anonymous: false, - inputs: [ - { - name: "owner", - internalType: "address", - type: "address", - indexed: true, - }, - { - name: "spender", - internalType: "address", - type: "address", - indexed: true, - }, - { - name: "value", - internalType: "uint256", - type: "uint256", - indexed: false, - }, - ], - name: "Approval", - }, - { - type: "event", - anonymous: false, - inputs: [ - { name: "from", internalType: "address", type: "address", indexed: true }, - { name: "to", internalType: "address", type: "address", indexed: true }, - { - name: "value", - internalType: "uint256", - type: "uint256", - indexed: false, - }, - ], - name: "Transfer", - }, - { - type: "error", - inputs: [ - { name: "spender", internalType: "address", type: "address" }, - { name: "allowance", internalType: "uint256", type: "uint256" }, - { name: "needed", internalType: "uint256", type: "uint256" }, - ], - name: "ERC20InsufficientAllowance", - }, - { - type: "error", - inputs: [ - { name: "sender", internalType: "address", type: "address" }, - { name: "balance", internalType: "uint256", type: "uint256" }, - { name: "needed", internalType: "uint256", type: "uint256" }, - ], - name: "ERC20InsufficientBalance", - }, - { - type: "error", - inputs: [{ name: "approver", internalType: "address", type: "address" }], - name: "ERC20InvalidApprover", - }, - { - type: "error", - inputs: [{ name: "receiver", internalType: "address", type: "address" }], - name: "ERC20InvalidReceiver", - }, - { - type: "error", - inputs: [{ name: "sender", internalType: "address", type: "address" }], - name: "ERC20InvalidSender", - }, - { - type: "error", - inputs: [{ name: "spender", internalType: "address", type: "address" }], - name: "ERC20InvalidSpender", - }, -] as const; diff --git a/scripts/rewards-distribution/simulateStaking.ts b/scripts/rewards-distribution/simulateStaking.ts index a4c95f4..c4e0281 100644 --- a/scripts/rewards-distribution/simulateStaking.ts +++ b/scripts/rewards-distribution/simulateStaking.ts @@ -1,10 +1,10 @@ import { Address, formatUnits, parseUnits } from "viem"; import { Hex } from "viem"; -import FoxStaking from "../../foundry/out/FoxStakingV1.sol/FOXStakingV1.json"; +import StakingV1 from "../../foundry/out/StakingV1.sol/StakingV1.json"; import MockFOXToken from "../../foundry/out/MockFOXToken.sol/MockFOXToken.json"; import { localPublicClient, localWalletClient } from "./constants"; -import { foxStakingV1Abi, mockFoxTokenAbi } from "./generated/abi-types"; +import { stakingV1Abi, mockFoxTokenAbi } from "./generated/abi-types"; export const simulateStaking = async () => { const walletClient = localWalletClient; @@ -23,24 +23,24 @@ export const simulateStaking = async () => { }); console.log(`MockFOXToken deployed to: ${mockFoxtokenContractAddress}`); - // Deploy the FOXStaking contract with the address of the deployed MockFOXToken as FOX + // Deploy the Staking contract with the address of the deployed MockFOXToken as FOX - const mockFoxStakingDeployHash = await walletClient.deployContract({ - abi: foxStakingV1Abi, + const mockStakingDeployHash = await walletClient.deployContract({ + abi: stakingV1Abi, account: alice, - bytecode: FoxStaking.bytecode.object as Hex, - args: [], // The contructor of the FOXStaking contract does not take any arguments + bytecode: StakingV1.bytecode.object as Hex, + args: [], // The contructor of the Staking contract does not take any arguments }); - const { contractAddress: mockFoxStakingContractAddress } = + const { contractAddress: mockStakingContractAddress } = await publicClient.waitForTransactionReceipt({ - hash: mockFoxStakingDeployHash, + hash: mockStakingDeployHash, }); - if (!mockFoxStakingContractAddress) { - throw new Error("FOXStaking contract address not found"); + if (!mockStakingContractAddress) { + throw new Error("Staking contract address not found"); } - console.log(`FOXStaking deployed to: ${mockFoxStakingContractAddress}`); + console.log(`Staking deployed to: ${mockStakingContractAddress}`); const foxDecimals = await publicClient.readContract({ address: mockFoxtokenContractAddress as Address, @@ -67,26 +67,26 @@ export const simulateStaking = async () => { foxDecimals, ); - // Approve FOX to be spent by the FOXStaking contract + // Approve FOX to be spent by the Staking contract const approveTxHash = await walletClient.writeContract({ address: mockFoxtokenContractAddress as Address, abi: mockFoxTokenAbi, account: bob, functionName: "approve", - args: [mockFoxStakingContractAddress, amountToStakeCryptoBaseUnit], + args: [mockStakingContractAddress, amountToStakeCryptoBaseUnit], }); const { transactionHash } = await publicClient.waitForTransactionReceipt({ hash: approveTxHash, }); console.log( - `Granted allowance for ${amountToStakeCryptoPrecision} FOX tokens to be spent by FOXStaking contract: ${transactionHash}`, + `Granted allowance for ${amountToStakeCryptoPrecision} FOX tokens to be spent by Staking contract: ${transactionHash}`, ); const stakeTxHash = await walletClient.writeContract({ - address: mockFoxStakingContractAddress as Address, - abi: foxStakingV1Abi, + address: mockStakingContractAddress as Address, + abi: stakingV1Abi, account: bob, functionName: "stake", args: [amountToStakeCryptoBaseUnit, ""], // FIXME: add the runeAddress], @@ -95,12 +95,12 @@ export const simulateStaking = async () => { const { transactionHash: stakeTransactionHash } = await publicClient.waitForTransactionReceipt({ hash: stakeTxHash }); console.log( - `Staked ${amountToStakeCryptoPrecision} FOX from Bob to FOXStaking contract: ${stakeTransactionHash}`, + `Staked ${amountToStakeCryptoPrecision} FOX from Bob to Staking contract: ${stakeTransactionHash}`, ); const bobStakedBalance = await publicClient.readContract({ - address: mockFoxStakingContractAddress as Address, - abi: foxStakingV1Abi, + address: mockStakingContractAddress as Address, + abi: stakingV1Abi, functionName: "balanceOf", args: [bob], }); diff --git a/scripts/rewards-distribution/wagmi.config.ts b/scripts/rewards-distribution/wagmi.config.ts index b19d1c5..bbf0466 100644 --- a/scripts/rewards-distribution/wagmi.config.ts +++ b/scripts/rewards-distribution/wagmi.config.ts @@ -6,7 +6,7 @@ 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/**", "MockFOXToken.sol/**"], + include: ["StakingV1.sol/**", "MockFOXToken.sol/**"], }; export default defineConfig({