74 lines
2.9 KiB
Solidity
74 lines
2.9 KiB
Solidity
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
pragma solidity ^0.8.13;
|
|
|
|
import "forge-std/Test.sol";
|
|
import "forge-std/console.sol";
|
|
import { TwabController } from "pt-v5-twab-controller/TwabController.sol";
|
|
import "../src/Harb.sol";
|
|
import "../src/Stake.sol";
|
|
|
|
contract HarbTest is Test {
|
|
Harb public harb;
|
|
Stake public stake;
|
|
|
|
function setUp() public {
|
|
|
|
TwabController tc = new TwabController(60*60*24, uint32(block.timestamp));
|
|
|
|
harb = new Harb("HARB", "HARB", tc);
|
|
stake = new Stake(address(harb));
|
|
harb.setStakingPool(address(stake));
|
|
}
|
|
|
|
function test_MintStakeUnstake(address account, uint256 amount) public {
|
|
vm.assume(amount > 10000);
|
|
vm.assume(amount < 2**93); // TWAB limit = 2**96
|
|
vm.assume(account != address(0));
|
|
vm.assume(account != address(1)); // TWAB sponsorship address
|
|
vm.assume(account != address(2)); // tax pool address
|
|
vm.assume(account != address(harb));
|
|
vm.assume(account != address(stake));
|
|
|
|
// test mint
|
|
uint256 totalSupplyBefore = harb.totalSupply();
|
|
uint256 balanceBefore = harb.balanceOf(account);
|
|
harb.setLiquidityManager(account);
|
|
vm.prank(account);
|
|
harb.mint(amount);
|
|
uint256 totalAfter = harb.totalSupply();
|
|
assertEq(totalAfter, totalSupplyBefore + amount, "total supply should match");
|
|
assertEq(harb.balanceOf(account), balanceBefore + amount, "balance should match");
|
|
|
|
// test stake
|
|
{
|
|
vm.prank(account);
|
|
harb.mint(amount * 4);
|
|
assertEq(stake.outstandingStake(), 0, "init failure");
|
|
vm.prank(account);
|
|
harb.approve(address(stake), amount);
|
|
uint256[] memory empty;
|
|
vm.prank(account);
|
|
stake.snatch(amount, account, 1, empty);
|
|
assertEq(harb.totalSupply(), totalAfter * 5, "total supply should match after stake");
|
|
assertEq(harb.balanceOf(account), amount * 4, "balance should match after stake");
|
|
assertEq(harb.balanceOf(address(stake)), amount, "balance should match after stake");
|
|
(uint256 share, address owner, uint32 creationTime, uint32 lastTaxTime, uint32 taxRate) = stake.positions(0);
|
|
assertEq(share, stake.totalSupply() / 5, "share should match");
|
|
assertEq(owner, account, "owners should match");
|
|
assertEq(taxRate, 1, "tax rate should match");
|
|
}
|
|
|
|
// test unstake
|
|
{
|
|
uint256 timeBefore = block.timestamp;
|
|
vm.warp(timeBefore + 60 * 60 * 24 * 4);
|
|
uint256 taxDue = stake.taxDue(0, 60 * 60 * 24 * 3);
|
|
console.logUint(taxDue);
|
|
console.log("tax due :%i", taxDue);
|
|
vm.prank(account);
|
|
stake.exitPosition(0);
|
|
assertApproxEqRel(harb.balanceOf(account), amount * 5 - taxDue, 1e15, "balance should match");
|
|
}
|
|
}
|
|
|
|
}
|