make reserve dependant on calculator in tests and add testing script

Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
Uncle Fatso 2025-10-07 14:19:55 +03:00
parent 9dfd10aff7
commit d4c6583e12
Signed by: f4ts0
GPG Key ID: 565F4F2860226EBB
5 changed files with 51 additions and 17 deletions

View File

@ -11,6 +11,7 @@ import "../../src/Treasury.sol";
import "../../src/Staking.sol";
import "../../src/BondDepository.sol";
import "../../src/mocks/ERC20Mock.sol";
import "../../src/StandardBondingCalculator.sol";
contract GhostBondDepositoryTest is Test {
uint256 public constant TOTAL_INITIAL_SUPPLY = 5000000000000000;
@ -20,8 +21,8 @@ contract GhostBondDepositoryTest is Test {
uint48 public constant EPOCH_NUMBER = 1;
uint48 public constant EPOCH_END_TIME = 1337;
uint256 public constant initialMint = 10000000000000000000000000;
uint256 public constant initialDeposit = 1000000000000000000000000;
uint256 public constant initialMint = 1000000000000000000000000;
uint256 public constant initialDeposit = 100000000000000000000000;
uint256 public constant capacity = 10000e9;
uint256 public constant initialPrice = 400e9;
uint256 public constant buffer = 2e5;
@ -49,6 +50,7 @@ contract GhostBondDepositoryTest is Test {
GhostTreasury treasury;
GhostAuthority authority;
GhostBondDepository depository;
GhostBondingCalculator calculator;
function setUp() public {
vm.startPrank(initializer);
@ -72,6 +74,7 @@ contract GhostBondDepositoryTest is Test {
address(authority)
);
treasury = new GhostTreasury(address(ftso), 69, address(authority));
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
stnk.initialize(address(staking), address(treasury), address(ghst));
ghst.initialize(address(staking));
depository = new GhostBondDepository(
@ -90,7 +93,7 @@ contract GhostBondDepositoryTest is Test {
authority.pushVault(address(treasury));
treasury.enable(ITreasury.STATUS.REWARDMANAGER, address(depository), address(0));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, alice, address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.stopPrank();
vm.startPrank(alice);

View File

@ -11,6 +11,7 @@ import "../../src/Treasury.sol";
import "../../src/Staking.sol";
import "../../src/mocks/ERC20Mock.sol";
import "../../src/Gatekeeper.sol";
import "../../src/StandardBondingCalculator.sol";
contract StakingTest is Test {
address constant initializer = 0x0000000000000000000000000000000000000001;
@ -35,6 +36,7 @@ contract StakingTest is Test {
GhostTreasury treasury;
GhostAuthority authority;
Gatekeeper gatekeeper;
GhostBondingCalculator calculator;
uint256 public constant amount = 69;
uint256 public constant bigAmount = amount * 1e9;
@ -67,6 +69,7 @@ contract StakingTest is Test {
stnk.initialize(address(staking), address(treasury), address(ghst));
ghst.initialize(address(staking));
gatekeeper = new Gatekeeper(address(staking), 0);
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
vm.stopPrank();
}
@ -423,7 +426,7 @@ contract StakingTest is Test {
treasury.enable(ITreasury.STATUS.REWARDMANAGER, address(distributor), address(0));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, alice, address(0));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, bob, address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.stopPrank();
vm.startPrank(bob);
@ -479,7 +482,7 @@ contract StakingTest is Test {
distributor.setBounty(bounty);
treasury.enable(ITreasury.STATUS.REWARDMANAGER, address(distributor), address(0));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, alice, address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.stopPrank();
vm.startPrank(alice);

View File

@ -10,6 +10,7 @@ import "../../src/StakingDistributor.sol";
import "../../src/Treasury.sol";
import "../../src/Staking.sol";
import "../../src/mocks/ERC20Mock.sol";
import "../../src/StandardBondingCalculator.sol";
contract StakingDistributorTest is Test {
address public constant owner = 0x0000000000000000000000000000000000000001;
@ -35,6 +36,7 @@ contract StakingDistributorTest is Test {
GhostStaking staking;
GhostDistributor distributor;
GhostAuthority authority;
GhostBondingCalculator calculator;
uint256 public constant TEN_PERCENT = 1e5;
@ -60,6 +62,7 @@ contract StakingDistributorTest is Test {
address(authority)
);
treasury = new GhostTreasury(address(ftso), 69, address(authority));
calculator = new GhostBondingCalculator(address(ftso), 1, 1);
distributor = new GhostDistributor(
address(treasury),
address(ftso),
@ -250,7 +253,7 @@ contract StakingDistributorTest is Test {
treasury.enable(ITreasury.STATUS.REWARDMANAGER, address(distributor), address(0));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, alice, address(0));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, bob, address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.stopPrank();
vm.startPrank(alice);

View File

@ -1,6 +1,7 @@
pragma solidity 0.8.20;
import {Test} from "forge-std/Test.sol";
import {StdChains} from "forge-std/StdChains.sol";
import "../../src/FatsoERC20.sol";
import "../../src/GhostAuthority.sol";
@ -63,7 +64,7 @@ contract GhostTreasuryTest is Test {
treasury.deposit(address(reserve), amount, 0);
vm.prank(governor);
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.prank(alice);
uint256 send = treasury.deposit(address(reserve), amount, 0);
@ -74,7 +75,7 @@ contract GhostTreasuryTest is Test {
function test_withdraw_onlyIfApprovedTokenAndApprovedAddress() public {
vm.startPrank(governor);
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, alice, address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.stopPrank();
vm.prank(alice);
@ -98,7 +99,7 @@ contract GhostTreasuryTest is Test {
function test_manage_onlyIfApprovedTokenAndApprovedAddress() public {
vm.startPrank(governor);
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, alice, address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.stopPrank();
uint256 tokenValue = treasury.tokenValue(address(reserve), amount);
@ -123,7 +124,7 @@ contract GhostTreasuryTest is Test {
function test_mint_onlyIfApprovedTokenAndApprovedAddress() public {
vm.startPrank(governor);
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, alice, address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.stopPrank();
uint256 tokenValue = treasury.tokenValue(address(reserve), amount);
@ -147,7 +148,7 @@ contract GhostTreasuryTest is Test {
function test_auditTreasuryReserves() public {
vm.startPrank(governor);
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, alice, address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
vm.stopPrank();
uint256 tokenValue = treasury.tokenValue(address(reserve), amount);
@ -182,7 +183,7 @@ contract GhostTreasuryTest is Test {
function test_enableStatusAndCalculator() public {
vm.startPrank(governor);
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
treasury.enable(ITreasury.STATUS.LIQUIDITYTOKEN, address(liquidity), address(calculator));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, msg.sender, address(0));
vm.stopPrank();
@ -202,7 +203,7 @@ contract GhostTreasuryTest is Test {
vm.assume(who != governor && who != guardian);
vm.startPrank(governor);
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
treasury.enable(ITreasury.STATUS.LIQUIDITYTOKEN, address(liquidity), address(calculator));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, msg.sender, address(0));
vm.stopPrank();
@ -222,7 +223,7 @@ contract GhostTreasuryTest is Test {
function test_disableStatusByAddress() public {
vm.startPrank(governor);
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
treasury.enable(ITreasury.STATUS.LIQUIDITYTOKEN, address(liquidity), address(calculator));
treasury.enable(ITreasury.STATUS.RESERVEDEPOSITOR, msg.sender, address(0));
vm.stopPrank();
@ -239,13 +240,23 @@ contract GhostTreasuryTest is Test {
}
function test_tokenValueIsCorret() public {
address realDexPair = 0xB20bd5D04BE54f870D5C0d3cA85d82b34B836405;
vm.startPrank(governor);
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(0));
treasury.enable(ITreasury.STATUS.LIQUIDITYTOKEN, 0xB20bd5D04BE54f870D5C0d3cA85d82b34B836405, address(calculator));
treasury.enable(ITreasury.STATUS.RESERVETOKEN, address(reserve), address(calculator));
treasury.enable(ITreasury.STATUS.LIQUIDITYTOKEN, realDexPair, address(calculator));
vm.stopPrank();
uint256 totalSupply = IUniswapV2Pair(realDexPair).totalSupply();
assertEq(treasury.tokenValue(address(reserve), 1e18), 1e9);
assertEq(treasury.tokenValue(address(liquidity), 1e18), 1e9);
(uint256 reserve0, uint256 reserve1,) = IUniswapV2Pair(realDexPair).getReserves();
uint256 reserves = reserve0 * reserve1 / 1e6;
uint256 reserveEps = reserves * 1e5 / 1e7; // 1%
uint256 liquidityValue = (treasury.tokenValue(realDexPair, totalSupply) / 2)**2;
assertEq(liquidityValue + reserveEps >= reserves, true);
assertEq(liquidityValue - reserveEps <= reserves, true);
}
function test_randomAddressCouldNotTriggerTimelock(address who) public {

14
tester.sh Normal file
View File

@ -0,0 +1,14 @@
# exclude all tests dependant on rpc
forge test --no-match-test test_tokenValueIsCorret
echo ""
echo "#####################################"
echo "## Running mainnet dependant tests ##"
echo "#####################################"
echo ""
# url from the foundry, forge-std/StdChains.sol
FORK_URL="${1:-https://eth-mainnet.alchemyapi.io/v2/pwc5rmJhrdoaSEfimoKEmsvOjKSmPDrP}"
# run tests where rpc to the mainnet is needed
forge test --match-test test_tokenValueIsCorret --fork-url $FORK_URL