Skip to content

Commit

Permalink
updates from review
Browse files Browse the repository at this point in the history
  • Loading branch information
princetonbishop committed Nov 15, 2023
1 parent e5d687b commit 994cbb4
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 270 deletions.
60 changes: 37 additions & 23 deletions protocol/contracts/interfaces/nexus/IBaseSacrifice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,44 @@ pragma solidity 0.8.19;
// Temple (interfaces/nexus/IBaseSacrifice.sol)


interface IBaseSacrifice {
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface ISacrifice {
event TokenSacrificed(address account, uint256 amount);
event PartnerSacrifice(address to, uint256 relicId, uint256 enclaveId);
event OriginTimeSet(uint64 originTime);

error FutureOriginTime(uint64 originTime);

/*
* @notice Get amount of tokens to mint a Relic
* @return Relic price
*/
function getPrice() external view returns (uint256);

/*
* @notice Set origin time.
* Origin time is the start of the linear ascending price to params.priceMaxPeriod
* @param _originTime Origin time
*/
function setOriginTime(uint64 _originTime) external;
}

interface IPartnerSacrifice is ISacrifice {
/*
* @notice Sacrifice tokens to mint a Relic
* Caller must approve contract to spend tokens. Special case for partner Relic mint
* @param enclaveId Enclave ID
* @param to Destination address
*/
function sacrifice(uint256 enclaveId, address to) external;
}

interface IBaseSacrifice is ISacrifice {

event CustomPriceSet(uint256 price);
event TokenSacrificed(address account, uint256 amount);
event PriceParamsSet(PriceParam params);
event TokenRecipientSet(address recipient);
event PartnerSacrifice(address to);

error FutureOriginTime(uint64 originTime);

struct PriceParam {
uint64 priceMaxPeriod;
Expand All @@ -26,13 +54,6 @@ interface IBaseSacrifice {
*/
function setPriceParams(PriceParam calldata _priceParams) external;

/*
* @notice Set origin time.
* Origin time is the start of the linear ascending price to params.priceMaxPeriod
* @param _originTime Origin time
*/
function setOriginTime(uint64 _originTime) external;

/*
* @notice Set custom price
* owner can reset price with 0 _price value. Custom price can be set anytime during or after params.priceMaxPeriod on
Expand All @@ -47,17 +68,10 @@ interface IBaseSacrifice {
* @param enclaveId Enclave ID
*/
function sacrifice(uint256 enclaveId) external;

/*
* @notice Sacrifice tokens to mint a Relic
* Caller must approve contract to spend tokens. Special case for partner Relic mint
* @param enclaveId Enclave ID
* @param to Destination address
*/
function sacrifice(uint256 enclaveId, address to) external;

/*
* @notice Get amount of TEMPLE tokens to mint a Relic
* @return Relic price
* @notice Sacrifice Token address
* @return Sacrifice Token address
*/
function getPrice() external view returns (uint256);
function sacrificeToken() external view returns (IERC20);
}
61 changes: 0 additions & 61 deletions protocol/contracts/interfaces/nexus/ITempleSacrificeOld.sol

This file was deleted.

6 changes: 2 additions & 4 deletions protocol/contracts/nexus/BaseSacrifice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pragma solidity 0.8.19;
// Temple (nexus/BaseSacrifice.sol)


import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IBaseSacrifice } from "../interfaces/nexus/IBaseSacrifice.sol";
import { ElevatedAccess } from "./access/ElevatedAccess.sol";
import { CommonEventsAndErrors } from "../common/CommonEventsAndErrors.sol";
Expand Down Expand Up @@ -64,9 +62,9 @@ abstract contract BaseSacrifice is IBaseSacrifice, ElevatedAccess {
* @notice Sacrifice tokens to mint a Relic
* Caller must approve contract to spend tokens
* @param enclaveId Enclave ID
* @param to Relic recipient
*/
function sacrifice(uint256 enclaveId) external virtual {}
function sacrifice(uint256 enclaveId, address to) external virtual {}
// function sacrifice(uint256 enclaveId, address to) external virtual {}

/*
* @notice Get amount of tokens to mint a Relic
Expand Down
24 changes: 19 additions & 5 deletions protocol/contracts/nexus/PartnerZeroSacrifice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ pragma solidity 0.8.19;
// Temple (nexus/PartnerZeroSacrifice.sol)

import { IRelic } from "../interfaces/nexus/IRelic.sol";
import { IPartnerSacrifice } from "../interfaces/nexus/IBaseSacrifice.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ElevatedAccess } from "./access/ElevatedAccess.sol";
import { BaseSacrifice } from "./BaseSacrifice.sol";
import { CommonEventsAndErrors } from "../common/CommonEventsAndErrors.sol";

contract PartnerZeroSacrifice is BaseSacrifice {
contract PartnerZeroSacrifice is IPartnerSacrifice, ElevatedAccess {
using SafeERC20 for IERC20;
/// @notice the Relic ERC721A token
IRelic public immutable relic;
/// @notice start time from which price increases
uint64 public originTime;

constructor(
address _relic,
Expand All @@ -21,6 +24,17 @@ contract PartnerZeroSacrifice is BaseSacrifice {
relic = IRelic(_relic);
}

/*
* @notice Set origin time.
* Origin time is the start of the linear ascending price to params.priceMaxPeriod
* @param _originTime Origin time
*/
function setOriginTime(uint64 _originTime) external override onlyElevatedAccess {
if (_originTime < block.timestamp) { revert CommonEventsAndErrors.InvalidParam(); }
originTime = _originTime;
emit OriginTimeSet(originTime);
}

/*
* @notice Get amount of TEMPLE tokens to mint a Relic
* @return Relic price
Expand All @@ -31,14 +45,14 @@ contract PartnerZeroSacrifice is BaseSacrifice {

/*
* @notice Partner's way to mint a Relic.
* Partner's proxy contract is granted access to sacrifice. Partner proxy must validate minters before calling this function.
* Also checking proxy is a contract
* Partner's proxy contract is granted access to sacrifice.
* Partner proxy must validate minters before calling this function.
* @param enclaveId Enclave ID
*/
function sacrifice(uint256 enclaveId, address to) external override onlyElevatedAccess {
if (block.timestamp < originTime) { revert FutureOriginTime(originTime); }
if (msg.sender.code.length == 0) { revert CommonEventsAndErrors.InvalidAccess(); }
uint256 relicId = relic.nextTokenId();
relic.mintRelic(to, enclaveId);
emit PartnerSacrifice(to);
emit PartnerSacrifice(to, relicId, enclaveId);
}
}
12 changes: 0 additions & 12 deletions protocol/contracts/nexus/Relic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ contract Relic is IRelic, ERC721ACustom, ERC1155Holder, ElevatedAccess {
mapping(address => bool) public override blacklistedAccounts;
/// @notice count of shards blacklisted for Relic
mapping(uint256 => uint256) public override blacklistedShardsCount;
// mapping(address => bool) public override relicMinters;
/// @notice some relic minting contracts may only mint special partner relic "enclave" Ids
mapping(address => EnumerableSet.UintSet) private relicMinterEnclaveIds;
mapping(address => EnumerableSet.UintSet) private ownerRelics;
Expand Down Expand Up @@ -118,17 +117,6 @@ contract Relic is IRelic, ERC721ACustom, ERC1155Holder, ElevatedAccess {
return _baseURI(tokenId);
}

/*
* @notice Set relic minter
* @param minter Address to mint relics
* @param allow If minter is allowed to mint
*/
// function setRelicMinter(address minter, bool allow) external override onlyElevatedAccess {
// if (minter == address(0)) { revert CommonEventsAndErrors.InvalidAddress(); }
// relicMinters[minter] = allow;
// emit RelicMinterSet(minter, allow);
// }

/*
* @notice Set relic minter's enclave Ids to mint
* @param minter Address to mint relics
Expand Down
2 changes: 0 additions & 2 deletions protocol/contracts/nexus/TempleSacrifice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ contract TempleSacrifice is ITempleSacrifice, BaseSacrifice {
/// @notice send sacrificed temple to this address
address public sacrificedTokenRecipient;

// error FutureOriginTime(uint256 originTime);

constructor(
address _relic,
address _token,
Expand Down
Loading

0 comments on commit 994cbb4

Please sign in to comment.