Skip to content

Commit

Permalink
merge conflict fix
Browse files Browse the repository at this point in the history
  • Loading branch information
princetonbishop committed Jun 3, 2024
2 parents 56c8cb8 + 59df72d commit 1a0e838
Show file tree
Hide file tree
Showing 11 changed files with 9,054 additions and 28,142 deletions.
4 changes: 3 additions & 1 deletion protocol/contracts/fakes/templegold/TempleGoldMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
mapping(address => bool) public authorized;

event ContractAuthorizationSet(address _contract, bool _whitelist);
error CannotCompose();

constructor(
address _layerZeroEndpoint,
Expand Down Expand Up @@ -115,8 +116,8 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
MessagingFee calldata _fee,
address _refundAddress
) external payable virtual override returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt) {
if (_sendParam.composeMsg.length > 0) { revert CannotCompose(); }
/// cast bytes32 to address
// address _to = address(uint160(uint256(_sendParam.to)));
address _to = _sendParam.to.bytes32ToAddress();
/// @dev user can cross-chain transfer to either whitelisted or self
if (msg.sender != _to) { revert ITempleGold.NonTransferrable(msg.sender, _to); }
Expand Down Expand Up @@ -167,6 +168,7 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
uint256 amountReceivedLD = _credit(toAddress, _toLD(_message.amountSD()), _origin.srcEid);

/// @dev Disallow further execution on destination by ignoring composed message
if (_message.isComposed()) { revert CannotCompose(); }

emit OFTReceived(_guid, _origin.srcEid, toAddress, amountReceivedLD);
}
Expand Down
1 change: 1 addition & 0 deletions protocol/contracts/interfaces/templegold/IAuctionBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IAuctionBase {
error InvalidEpoch();
error AuctionActive();
error InvalidOperation();
error AuctionEnded();

struct EpochInfo {
/// @notice Start time for epoch
Expand Down
1 change: 0 additions & 1 deletion protocol/contracts/interfaces/templegold/ISpiceAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface ISpiceAuction is IAuctionBase {
error MissingAuctionTokenConfig();
error NoConfig();
error RemoveAuctionConfig();
error AuctionEnded();

struct SpiceAuctionConfig {
/// @notice Duration of auction
Expand Down
17 changes: 15 additions & 2 deletions protocol/contracts/templegold/DaiGoldAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ contract DaiGoldAuction is IDaiGoldAuction, AuctionBase, TempleElevatedAccess {
}

/**
* @notice Recover auction tokens for last but not started auction
* @notice Recover auction tokens for last but not started auction.
* Any other token which is not Temple Gold can be recovered too at any time
* @dev For recovering Temple Gold, Epoch data is deleted and leftover amount is addedd to nextAuctionGoldAmount.
* so admin should recover total auction amount for epoch if that's the requirement
* @param token Token to recover
* @param to Recipient
* @param amount Amount to auction tokens
Expand All @@ -273,8 +276,18 @@ contract DaiGoldAuction is IDaiGoldAuction, AuctionBase, TempleElevatedAccess {
EpochInfo storage info = epochs[epochId];
if (info.startTime == 0) { revert InvalidOperation(); }
if (info.isActive()) { revert AuctionActive(); }
if (amount > info.totalAuctionTokenAmount) { revert CommonEventsAndErrors.InvalidAmount(token, amount); }
if (info.hasEnded()) { revert AuctionEnded(); }
uint256 _totalAuctionTokenAmount = info.totalAuctionTokenAmount;
if (amount > _totalAuctionTokenAmount) { revert CommonEventsAndErrors.InvalidAmount(token, amount); }
/// @dev Epoch data is deleted and leftover amount is addedd to nextAuctionGoldAmount.
/// so admin should recover total auction amount for epoch if that's the requirement
delete epochs[epochId];
/// @dev `nextAuctionGoldAmount` is set to 0 in `startAuction`.
/// `nextAuctionGoldAmount > 0` if there was a distribution after `auctionStart` called
/// epoch is deleted. so if amount < totalAuctionTokenAmount for epoch, add leftover to next auction amount
unchecked {
nextAuctionGoldAmount += _totalAuctionTokenAmount - amount;
}

emit CommonEventsAndErrors.TokenRecovered(to, token, amount);
templeGold.safeTransfer(to, amount);
Expand Down
4 changes: 1 addition & 3 deletions protocol/contracts/templegold/SpiceAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ contract SpiceAuction is ISpiceAuction, AuctionBase {
if (info.isActive()) { revert InvalidConfigOperation(); }
/// @dev could be that `auctionStart` is triggered but there's cooldown, which is not reached (so can delete epochInfo for _currentEpochId)
// or `auctionStart` is not triggered but `auctionConfig` is set (where _currentEpochId is not updated yet)
SpiceAuctionConfig storage config = auctionConfigs[id];
bool configSetButAuctionStartNotCalled = auctionConfigs[id+1].duration > 0;
if (!configSetButAuctionStartNotCalled) {
/// @dev unlikely because this is a DAO execution, but avoid deleting old ended auctions
Expand All @@ -129,7 +128,6 @@ contract SpiceAuction is ISpiceAuction, AuctionBase {
} else {
// `auctionStart` is not triggered but `auctionConfig` is set
id += 1;
config = auctionConfigs[id];
delete auctionConfigs[id];
emit AuctionConfigRemoved(id, 0);
}
Expand Down Expand Up @@ -170,7 +168,7 @@ contract SpiceAuction is ISpiceAuction, AuctionBase {
epochId = _currentEpochId = _currentEpochId + 1;
EpochInfo storage info = epochs[epochId];
uint128 startTime = info.startTime = uint128(block.timestamp) + config.startCooldown;
uint128 endTime = info.endTime = uint128(block.timestamp) + config.duration;
uint128 endTime = info.endTime = startTime + config.duration;
info.totalAuctionTokenAmount = epochAuctionTokenAmount;
// Keep track of total allocation auction tokens per epoch
_totalAuctionTokenAllocation[auctionToken] = totalAuctionTokenAllocation + epochAuctionTokenAmount;
Expand Down
17 changes: 6 additions & 11 deletions protocol/contracts/templegold/TempleGold.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
/// @notice Last block timestamp Temple Gold was minted
uint32 public override lastMintTimestamp;

/// @notice Deploy time for first mint amount calculation
uint32 private immutable _deployTime;

//// @notice Distribution as a percentage of 100
uint256 public constant DISTRIBUTION_DIVISOR = 100 ether;
/// @notice 1B max supply
Expand Down Expand Up @@ -73,7 +70,6 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
escrow = IDaiGoldAuction(_initArgs.escrow);
teamGnosis = _initArgs.gnosis;
_mintChainId = _initArgs.mintChainId;
_deployTime = uint32(block.timestamp);
}

/**
Expand Down Expand Up @@ -135,6 +131,8 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
if (_factor.numerator == 0 || _factor.denominator == 0) { revert CommonEventsAndErrors.ExpectedNonZero(); }
if (_factor.numerator > _factor.denominator) { revert CommonEventsAndErrors.InvalidParam(); }
vestingFactor = _factor;
/// @dev initialize
if (lastMintTimestamp == 0) { lastMintTimestamp = uint32(block.timestamp); }
emit VestingFactorSet(_factor.numerator, _factor.denominator);
}

Expand Down Expand Up @@ -250,13 +248,9 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
function _getMintAmount(VestingFactor memory vestingFactorCache) private view returns (uint256 mintAmount) {
uint32 _lastMintTimestamp = lastMintTimestamp;
uint256 totalSupplyCache = _totalDistributed;
/// @notice first time mint
if (_lastMintTimestamp == 0) {
/// @dev use deployTime for time difference. avoid getting stuck where _lastMintTimestamp is always 0 because mintAmount < 10_000
mintAmount = TempleMath.mulDivRound((block.timestamp - _deployTime) * MAX_SUPPLY, vestingFactorCache.numerator, vestingFactorCache.denominator, false);
} else {
mintAmount = TempleMath.mulDivRound((block.timestamp - _lastMintTimestamp) * (MAX_SUPPLY), vestingFactorCache.numerator, vestingFactorCache.denominator, false);
}
/// @dev if vesting factor is not set, return 0. `_lastMintTimestamp` is set when vesting factor is set
if (_lastMintTimestamp == 0) { return 0; }
mintAmount = TempleMath.mulDivRound((block.timestamp - _lastMintTimestamp) * (MAX_SUPPLY), vestingFactorCache.numerator, vestingFactorCache.denominator, false);

if (totalSupplyCache + mintAmount > MAX_SUPPLY) {
unchecked {
Expand Down Expand Up @@ -289,6 +283,7 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
MessagingFee calldata _fee,
address _refundAddress
) external payable virtual override(IOFT, OFTCore) returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt) {
if (_sendParam.composeMsg.length > 0) { revert CannotCompose(); }
/// cast bytes32 to address
address _to = _sendParam.to.bytes32ToAddress();
/// @dev user can cross-chain transfer to self
Expand Down
Loading

0 comments on commit 1a0e838

Please sign in to comment.