-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: owner setters functions (#925)
* feat: owner setters * Lint * fix * testing * lint * fix * add comment * lint
- Loading branch information
1 parent
cb1bf21
commit e875084
Showing
10 changed files
with
341 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule openzeppelin-contracts
added at
045704
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.13; | ||
|
||
// contract | ||
import { Ownable } from "openzeppelin/access/Ownable.sol"; | ||
import { EIP712 } from "openzeppelin/utils/cryptography/draft-EIP712.sol"; | ||
|
||
/** | ||
* @dev ZenBullNetting contract | ||
* @notice Contract for Netting Deposits and Withdrawals in ZenBull | ||
* @author Opyn team | ||
*/ | ||
contract ZenBullNetting is Ownable, EIP712 { | ||
/// @dev typehash for signed orders | ||
bytes32 private constant _ZENBULL_NETTING_TYPEHASH = keccak256( | ||
"Order(uint256 bidId,address trader,uint256 quantity,uint256 price,bool isBuying,uint256 expiry,uint256 nonce)" | ||
); | ||
/// @dev OTC price tolerance cannot exceed 20% | ||
uint256 public constant MAX_OTC_PRICE_TOLERANCE = 2e17; // 20% | ||
/// @dev min auction TWAP | ||
uint32 public constant MIN_AUCTION_TWAP = 180 seconds; | ||
|
||
/// @dev owner sets to true when starting auction | ||
bool public isAuctionLive; | ||
|
||
/// @dev min WETH amounts to withdraw or deposit via netting | ||
uint256 public minWethAmount; | ||
/// @dev min ZenBull amounts to withdraw or deposit via netting | ||
uint256 public minBullAmount; | ||
/// @dev array index of last processed deposits | ||
uint256 public depositsIndex; | ||
/// @dev array index of last processed withdraws | ||
uint256 public withdrawsIndex; | ||
// @dev OTC price must be within this distance of the uniswap twap price | ||
uint256 public otcPriceTolerance; | ||
/// @dev twap period to use for auction calculations | ||
uint32 public auctionTwapPeriod; | ||
|
||
/// @dev order struct for a signed order from market maker | ||
struct Order { | ||
uint256 bidId; | ||
address trader; | ||
uint256 quantity; | ||
uint256 price; | ||
bool isBuying; | ||
uint256 expiry; | ||
uint256 nonce; | ||
uint8 v; | ||
bytes32 r; | ||
bytes32 s; | ||
} | ||
|
||
event SetMinBullAmount(uint256 oldAmount, uint256 newAmount); | ||
event SetMinWethAmount(uint256 oldAmount, uint256 newAmount); | ||
event SetDepositsIndex(uint256 oldDepositsIndex, uint256 newDepositsIndex); | ||
event SetWithdrawsIndex(uint256 oldWithdrawsIndex, uint256 newWithdrawsIndex); | ||
event SetAuctionTwapPeriod(uint32 previousTwap, uint32 newTwap); | ||
event SetOTCPriceTolerance(uint256 previousTolerance, uint256 newOtcPriceTolerance); | ||
event ToggledAuctionLive(bool isAuctionLive); | ||
|
||
constructor() EIP712("ZenBullNetting", "1") { | ||
otcPriceTolerance = 5e16; // 5% | ||
auctionTwapPeriod = 420 seconds; | ||
} | ||
|
||
/** | ||
* @dev view function to get the domain seperator used in signing | ||
*/ | ||
function DOMAIN_SEPARATOR() external view returns (bytes32) { | ||
return _domainSeparatorV4(); | ||
} | ||
|
||
/** | ||
* @dev toggles the value of isAuctionLive | ||
*/ | ||
function toggleAuctionLive() external onlyOwner { | ||
isAuctionLive = !isAuctionLive; | ||
emit ToggledAuctionLive(isAuctionLive); | ||
} | ||
|
||
/** | ||
* @notice set min Weth amount | ||
* @param _amount the amount to be set as minWethAmount | ||
*/ | ||
function setMinWethAmount(uint256 _amount) external onlyOwner { | ||
emit SetMinWethAmount(minWethAmount, _amount); | ||
minWethAmount = _amount; | ||
} | ||
|
||
/** | ||
* @notice set minBullAmount | ||
* @param _amount the number to be set as minBullAmount | ||
*/ | ||
function setMinBullAmount(uint256 _amount) external onlyOwner { | ||
emit SetMinBullAmount(minBullAmount, _amount); | ||
|
||
minBullAmount = _amount; | ||
} | ||
|
||
/** | ||
* @notice set the depositIndex so that we want to skip processing some deposits | ||
* @param _newDepositsIndex the new deposits index | ||
*/ | ||
function setDepositsIndex(uint256 _newDepositsIndex) external onlyOwner { | ||
emit SetDepositsIndex(depositsIndex, _newDepositsIndex); | ||
|
||
depositsIndex = _newDepositsIndex; | ||
} | ||
|
||
/** | ||
* @notice set the withdraw index so that we want to skip processing some withdraws | ||
* @param _newWithdrawsIndex the new withdraw index | ||
*/ | ||
function setWithdrawsIndex(uint256 _newWithdrawsIndex) external onlyOwner { | ||
emit SetWithdrawsIndex(withdrawsIndex, _newWithdrawsIndex); | ||
|
||
withdrawsIndex = _newWithdrawsIndex; | ||
} | ||
|
||
/** | ||
* @notice owner can set the twap period in seconds that is used for obtaining TWAP prices | ||
* @param _auctionTwapPeriod the twap period, in seconds | ||
*/ | ||
function setAuctionTwapPeriod(uint32 _auctionTwapPeriod) external onlyOwner { | ||
require(_auctionTwapPeriod >= MIN_AUCTION_TWAP, "ZBN01"); | ||
|
||
emit SetAuctionTwapPeriod(auctionTwapPeriod, _auctionTwapPeriod); | ||
|
||
auctionTwapPeriod = _auctionTwapPeriod; | ||
} | ||
|
||
/** | ||
* @notice owner can set a threshold, scaled by 1e18 that determines the maximum discount of a clearing sale price to the current uniswap twap price | ||
* @param _otcPriceTolerance the OTC price tolerance, in percent, scaled by 1e18 | ||
*/ | ||
function setOTCPriceTolerance(uint256 _otcPriceTolerance) external onlyOwner { | ||
// Tolerance cannot be more than 20% | ||
require(_otcPriceTolerance <= MAX_OTC_PRICE_TOLERANCE, "ZBN02"); | ||
|
||
emit SetOTCPriceTolerance(otcPriceTolerance, _otcPriceTolerance); | ||
|
||
otcPriceTolerance = _otcPriceTolerance; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
packages/zen-bull-netting/test/ZenBullNettingBaseSetup.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
pragma solidity ^0.8.13; | ||
|
||
pragma abicoder v2; | ||
|
||
// test dependency | ||
import "forge-std/Test.sol"; | ||
import { console } from "forge-std/console.sol"; | ||
|
||
// contracts | ||
import { ZenBullNetting } from "../src/ZenBullNetting.sol"; | ||
|
||
/** | ||
* Unit tests | ||
*/ | ||
contract ZenBullNettingBaseSetup is Test { | ||
ZenBullNetting internal zenBullNetting; | ||
|
||
uint256 public deployerPk; | ||
uint256 public ownerPk; | ||
address public deployer; | ||
address public owner; | ||
|
||
function setUp() public virtual { | ||
string memory FORK_URL = vm.envString("FORK_URL"); | ||
vm.createSelectFork(FORK_URL, 16419302); | ||
|
||
deployerPk = 0xA11CD; | ||
deployer = vm.addr(deployerPk); | ||
ownerPk = 0xB11CD; | ||
owner = vm.addr(ownerPk); | ||
|
||
vm.startPrank(deployer); | ||
zenBullNetting = new ZenBullNetting(); | ||
zenBullNetting.transferOwnership(owner); | ||
vm.stopPrank(); | ||
|
||
vm.label(deployer, "Deployer"); | ||
vm.label(owner, "Owner"); | ||
vm.label(address(zenBullNetting), "ZenBullNetting"); | ||
} | ||
|
||
function testIgnoreCoverageReport() public { } | ||
} |
Oops, something went wrong.
e875084
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
continuouscall – ./
continuouscall-git-main-opynfinance.vercel.app
www.squeeth.com
continuouscall-opynfinance.vercel.app
levbev.squeeth.com
squeeth.com
squeeth.opyn.co