Skip to content

Commit

Permalink
tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
princetonbishop committed Apr 30, 2024
1 parent 2eae21f commit 9745d77
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {IStakedTempleVoteToken} from "contracts/interfaces/templegold/IStakedTem

interface ITempleGoldStaking {
event StakingProxySet(address stakingProxy);
event GoldDistributionNotified(uint256 amount, uint256 timestamp);
event Staked(address indexed staker, uint256 amount);
event RewardPaid(address indexed staker, address toAddress, uint256 reward);
event MigratorSet(address migrator);
Expand Down
6 changes: 0 additions & 6 deletions protocol/contracts/templegold/StakedTempleVoteToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ contract StakedTempleVoteToken is IStakedTempleVoteToken, TempleElevatedAccess,
transferFrom(src, dst, amount);
}

/// The functions below are overrides required by Solidity.

function decimals() public view override returns (uint8) {
return super.decimals();
}

/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
Expand Down
19 changes: 11 additions & 8 deletions protocol/contracts/templegold/TempleGoldStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ contract TempleGoldStaking is ITempleGoldStaking, TempleElevatedAccess, Pausable
* @param _migrator Migrator
*/
function setMigrator(address _migrator) external override onlyElevatedAccess {
if (_migrator == address(0)) { revert CommonEventsAndErrors.InvalidAddress(); }
migrator = _migrator;
emit MigratorSet(_migrator);
}
Expand All @@ -116,7 +117,7 @@ contract TempleGoldStaking is ITempleGoldStaking, TempleElevatedAccess, Pausable
* @param _cooldown Cooldown in seconds
*/
function setRewardDistributionCoolDown(uint160 _cooldown) external override onlyElevatedAccess {
if (_cooldown == 0) { revert CommonEventsAndErrors.ExpectedNonZero(); }
/// @dev zero cooldown is allowed
rewardDistributionCoolDown = _cooldown;
emit RewardDistributionCoolDownSet(_cooldown);
}
Expand Down Expand Up @@ -152,11 +153,14 @@ contract TempleGoldStaking is ITempleGoldStaking, TempleElevatedAccess, Pausable
*/
function distributeRewards() external {
if (distributionStarter != address(0) && msg.sender != distributionStarter) { revert CommonEventsAndErrors.InvalidAccess(); }
// Mint and distribute TGLD is no cooldown set
if (rewardDistributionCoolDown == 0) { _distributeGold(); }
// Mint and distribute TGLD if no cooldown set
// if (rewardDistributionCoolDown == 0) { _distributeGold(); }
if (lastRewardNotificationTimestamp > 0 &&
lastRewardNotificationTimestamp + rewardDistributionCoolDown < block.timestamp)
{ revert CannotDistribute(); }
_distributeGold();
uint256 rewardAmount = nextRewardAmount;
if (rewardAmount == 0 ) { revert CommonEventsAndErrors.ExpectedNonZero(); }
if (lastRewardNotificationTimestamp + rewardDistributionCoolDown < block.timestamp) { revert CannotDistribute(); }
nextRewardAmount = 0;
_notifyReward(rewardAmount);
}
Expand Down Expand Up @@ -299,6 +303,7 @@ contract TempleGoldStaking is ITempleGoldStaking, TempleElevatedAccess, Pausable
/// @notice Temple Gold contract mints TGLD amount to contract before calling `notifyDistribution`
nextRewardAmount += amount;
lastRewardNotificationTimestamp = uint96(block.timestamp);
emit GoldDistributionNotified(amount, block.timestamp);
}

function getRewardData() external override view returns (Reward memory) {
Expand Down Expand Up @@ -401,10 +406,8 @@ contract TempleGoldStaking is ITempleGoldStaking, TempleElevatedAccess, Pausable
}

function _distributeGold() internal {
bool canDistribute = ITempleGold(address(rewardToken)).canDistribute();
if (canDistribute) {
ITempleGold(address(rewardToken)).mint();
}
/// @dev no op silent fail if nothing to distribute
ITempleGold(address(rewardToken)).mint();
}

function _voteWeight(address _account) private view returns (uint256) {
Expand Down
19 changes: 3 additions & 16 deletions protocol/test/forge/templegold/DaiGoldAuction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity 0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// (tests/forge/templegold/DaiGoldAuction.t.sol)

import { TempleTest } from "../TempleTest.sol";
import { TempleGoldCommon } from "./TempleGoldCommon.t.sol";
import { ITempleGold } from "contracts/interfaces/templegold/ITempleGold.sol";
import { TempleGold } from "contracts/templegold/TempleGold.sol";
import { IDaiGoldAuction } from "contracts/interfaces/templegold/IDaiGoldAuction.sol";
Expand All @@ -14,7 +14,7 @@ import { ITempleERC20Token } from "contracts/interfaces/core/ITempleERC20Token.s
import { TempleGoldStaking } from "contracts/templegold/TempleGoldStaking.sol";
// import { console } from "forge-std/console.sol";

contract DaiGoldAuctionTestBase is TempleTest {
contract DaiGoldAuctionTestBase is TempleGoldCommon {
event AuctionStarted(uint256 epochId, address indexed starter, uint64 startTime, uint64 endTime, uint256 auctionTokenAmount);
event BidTokenSet(address bidToken);
event GoldDistributionNotified(uint256 amount, uint256 timestamp);
Expand All @@ -28,14 +28,7 @@ contract DaiGoldAuctionTestBase is TempleTest {
uint32 public constant AUCTIONS_TIME_DIFF_ONE = 2 weeks;
uint32 public constant AUCTIONS_START_COOLDOWN_ONE = 1 hours;
uint192 public constant AUCTION_MIN_DISTRIBUTED_GOLD_ONE = 1_000;

address public treasury = makeAddr("treasury");
address public teamGnosis = makeAddr("teamGnosis");
address public layerZeroEndpointArbitrumOne = 0x1a44076050125825900e736c501f859c50fE728c;
uint256 public layerZeroEndpointArbitrumId = 30110;

address public usdcToken = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831; // arb USDC
address public daiToken = 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1; //arb DAI

address public templeToken = 0x470EBf5f030Ed85Fc1ed4C2d36B9DD02e77CF1b7;
// address public arbDaiWhale = 0xEa55D6319B04b4B6Ce8d03F3db84e432219eFCaA;

Expand All @@ -46,12 +39,6 @@ contract DaiGoldAuctionTestBase is TempleTest {
DaiGoldAuction public daiGoldAuction;
TempleGoldStaking public goldStaking;

uint256 public mintChainId = 1;
uint256 public arbitrumOneChainId = 42161;

string public constant TEMPLE_GOLD_NAME = "TEMPLE GOLD";
string public constant TEMPLE_GOLD_SYMBOL = "TGLD";

function setUp() public {
/// @dev forking for layerzero endpoint to execute code
fork("arbitrum_one", 204026954);
Expand Down
12 changes: 10 additions & 2 deletions protocol/test/forge/templegold/StakedTempleVoteToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ contract StakedTempleVoteTokenTestBase is TempleGoldCommon {

templeGold = new TempleGold(initArgs);
templeToken = new FakeERC20("Temple Token", "TEMPLE", executor, 1000 ether);
staking = new TempleGoldStaking(rescuer, executor, address(templeToken), address(templeGold), address(0));
voteToken = new StakedTempleVoteToken(rescuer, executor,address(staking), NAME, SYMBOL);
voteToken = new StakedTempleVoteToken(rescuer, executor,address(0), NAME, SYMBOL);
staking = new TempleGoldStaking(rescuer, executor, address(templeToken), address(templeGold), address(voteToken));
vm.startPrank(executor);
voteToken.setStaking(address(staking));
vm.stopPrank();

}

function test_initialization() public {
Expand Down Expand Up @@ -186,4 +190,8 @@ contract StakedTempleVoteTokenTest is StakedTempleVoteTokenTestBase {
emit Unpaused(executor);
voteToken.unpause();
}

function test_getVoteweight_voteToken() public {
/// @dev see TempleGoldStaking.t.sol
}
}
5 changes: 5 additions & 0 deletions protocol/test/forge/templegold/TempleGoldCommon.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.20;
// (tests/forge/templegold/TempleGoldCommon.t.sol)

import { TempleTest } from "../TempleTest.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

contract TempleGoldCommon is TempleTest {
address public treasury = makeAddr("treasury");
Expand All @@ -22,4 +23,8 @@ contract TempleGoldCommon is TempleTest {

string public constant NAME_ONE = "SPICE_AUCTION_TGLD_USDC";
string public constant NAME_TWO = "SPICE_AUCTION_TGLD_DAI";

function _approve(address _token, address _spender, uint256 _amount) internal {
IERC20(_token).approve(_spender, _amount);
}
}

0 comments on commit 9745d77

Please sign in to comment.