编译器
0.8.19+commit.7dd6d404
文件 1 的 42:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 2 的 42:AddressUpgradeable.sol
pragma solidity ^0.8.1;
library AddressUpgradeable {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 3 的 42:AggregatorV3Interface.sol
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(uint80 _roundId)
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
}
文件 4 的 42:AoriCall.sol
pragma solidity ^0.8.13;
import "./OpenZeppelin/ERC20.sol";
import "./OpenZeppelin/Ownable.sol";
import "./Chainlink/AggregatorV3Interface.sol";
import "./OpenZeppelin/IERC20.sol";
import "./OpenZeppelin/ReentrancyGuard.sol";
import "./AoriSeats.sol";
import "./OpenZeppelin/SafeERC20.sol";
import "./Margin/MarginManager.sol";
contract AoriCall is ERC20, ReentrancyGuard {
address public immutable factory;
address public immutable manager;
address public oracle;
uint256 public immutable strikeInUSDC;
uint256 public immutable endingTime;
uint256 public immutable duration;
IERC20 public immutable UNDERLYING;
uint256 public immutable UNDERLYING_DECIMALS;
IERC20 public immutable USDC;
uint256 public immutable USDC_DECIMALS;
uint256 public settlementPrice;
uint256 public immutable feeMultiplier;
uint256 public immutable decimalDiff;
uint256 immutable tolerance = 2 hours;
bool public hasEnded = false;
AoriSeats public immutable AORISEATSADD;
mapping (address => uint256) public optionSellers;
uint256 public immutable BPS_DIVISOR = 10000;
constructor(
address _manager,
uint256 _feeMultiplier,
uint256 _strikeInUSDC,
uint256 _duration,
IERC20 _UNDERLYING,
IERC20 _USDC,
address _oracle,
AoriSeats _AORISEATSADD,
string memory name_,
string memory symbol_
) ERC20(name_, symbol_, 18) {
factory = msg.sender;
manager = _manager;
feeMultiplier = _feeMultiplier;
strikeInUSDC = _strikeInUSDC;
duration = _duration;
endingTime = block.timestamp + duration;
UNDERLYING = _UNDERLYING;
UNDERLYING_DECIMALS = UNDERLYING.decimals();
USDC = _USDC;
USDC_DECIMALS = USDC.decimals();
decimalDiff = (10**UNDERLYING_DECIMALS) / (10**USDC_DECIMALS);
oracle = _oracle;
AORISEATSADD = _AORISEATSADD;
}
event CallMinted(uint256 optionsMinted, address minter);
event CallBuyerITMSettled(uint256 optionsRedeemed, address settler);
event CallSellerITMSettled(uint256 optionsRedeemed, address settler);
event CallSellerOTMSettled(uint256 optionsRedeemed, address settler);
event SellerRetrievedFunds(uint256 tokensRetrieved, address seller);
function setOracle(address newOracle) public returns(address) {
require(msg.sender == AORISEATSADD.owner());
oracle = newOracle;
return oracle;
}
function mintCall(uint256 quantityOfUNDERLYING, address receiver, uint256 seatId) public nonReentrant returns (uint256) {
require(UNDERLYING_DECIMALS == UNDERLYING.decimals(), "Decimal disagreement");
require(block.timestamp < endingTime, "This option has already matured");
require(UNDERLYING.balanceOf(msg.sender) >= quantityOfUNDERLYING, "Not enough of the underlying");
require(AORISEATSADD.confirmExists(seatId) && AORISEATSADD.ownerOf(seatId) != address(0x0), "Seat does not exist");
uint256 mintingFee;
uint256 refRate;
uint256 feeToSeat;
uint256 optionsToMint;
if (receiver == AORISEATSADD.ownerOf(seatId)) {
mintingFee = 0;
refRate = 0;
feeToSeat = 0;
optionsToMint = (quantityOfUNDERLYING * (10**6)) / strikeInUSDC;
SafeERC20.safeTransferFrom(UNDERLYING, msg.sender, address(this), quantityOfUNDERLYING);
_mint(receiver, optionsToMint);
} else {
mintingFee = callUNDERLYINGFeeCalculator(quantityOfUNDERLYING, AORISEATSADD.getOptionMintingFee());
refRate = (AORISEATSADD.getSeatScore(seatId) * 500) + 3500;
feeToSeat = (refRate * mintingFee) / BPS_DIVISOR;
optionsToMint = ((quantityOfUNDERLYING - mintingFee) * (10**6)) / strikeInUSDC;
SafeERC20.safeTransferFrom(UNDERLYING, msg.sender, address(this), quantityOfUNDERLYING - mintingFee);
SafeERC20.safeTransferFrom(UNDERLYING, msg.sender, Ownable(factory).owner(), mintingFee - feeToSeat);
SafeERC20.safeTransferFrom(UNDERLYING, msg.sender, AORISEATSADD.ownerOf(seatId), feeToSeat);
_mint(receiver, optionsToMint);
}
uint256 currentOptionsSold = optionSellers[msg.sender];
uint256 newOptionsSold = currentOptionsSold + optionsToMint;
optionSellers[msg.sender] = newOptionsSold;
emit CallMinted(optionsToMint, msg.sender);
return (optionsToMint);
}
function _setSettlementPrice() internal returns (uint256) {
require(block.timestamp >= endingTime, "Option has not matured");
if(hasEnded == false) {
settlementPrice = uint256(getPrice());
hasEnded = true;
}
return settlementPrice;
}
function callUNDERLYINGFeeCalculator(uint256 optionsToSettle, uint256 fee) internal view returns (uint256) {
require(UNDERLYING_DECIMALS == UNDERLYING.decimals());
uint256 txFee = (optionsToSettle * fee) / BPS_DIVISOR;
return txFee;
}
function scaleToUSDCAtStrike(uint256 optionsToSettle) internal view returns (uint256) {
uint256 tokenDecimals = 10**UNDERLYING_DECIMALS;
uint256 scaledVal = (optionsToSettle * strikeInUSDC) / tokenDecimals;
return scaledVal;
}
function buyerSettlementITM(uint256 optionsToSettle) public nonReentrant returns (uint256) {
_setSettlementPrice();
require(balanceOf(msg.sender) >= optionsToSettle, "You are attempting to settle more options than you have purhased");
require(balanceOf(msg.sender) >= 0, "You have not purchased any options");
require(settlementPrice > strikeInUSDC && settlementPrice != 0, "Option did not expire ITM");
require(optionsToSettle <= totalSupply() && optionsToSettle != 0);
uint256 profitPerOption = ((settlementPrice - strikeInUSDC) * 10**6) / settlementPrice;
uint256 UNDERLYINGOwed = (profitPerOption * optionsToSettle) / 10**6;
_burn(msg.sender, optionsToSettle);
SafeERC20.safeTransfer(UNDERLYING, msg.sender, UNDERLYINGOwed);
emit CallBuyerITMSettled(optionsToSettle, msg.sender);
return (optionsToSettle);
}
function sellerSettlementITM() public nonReentrant returns (uint256) {
_setSettlementPrice();
uint256 optionsToSettle = optionSellers[msg.sender];
require(optionsToSettle > 0);
require(settlementPrice > strikeInUSDC && hasEnded == true, "Option did not settle ITM");
uint256 UNDERLYINGToReceive = ((strikeInUSDC * 10**6) / settlementPrice) * optionsToSettle;
optionSellers[msg.sender] = 0;
SafeERC20.safeTransfer(UNDERLYING, msg.sender, UNDERLYINGToReceive / 10**6);
emit CallSellerITMSettled(optionsToSettle, msg.sender);
return optionsToSettle;
}
function sellerSettlementOTM() public nonReentrant returns (uint256) {
_setSettlementPrice();
require(optionSellers[msg.sender] > 0 && settlementPrice <= strikeInUSDC, "Option did not settle OTM or you did not sell any");
uint256 optionsSold = optionSellers[msg.sender];
optionSellers[msg.sender] = 0;
SafeERC20.safeTransfer(UNDERLYING, msg.sender, optionsSold);
emit CallSellerOTMSettled(optionsSold, msg.sender);
return optionsSold;
}
function liquidationSettlement(uint256 optionsToSettle) public nonReentrant returns (uint256) {
require(msg.sender == MarginManager(manager).vaultAdd(ERC20(address(UNDERLYING))));
_burn(msg.sender, optionsToSettle);
optionSellers[manager] -= optionsToSettle;
uint256 UNDERLYINGToReceive = (optionsToSettle * strikeInUSDC) / 10**UNDERLYING_DECIMALS;
UNDERLYING.transferFrom(address(this), manager, UNDERLYINGToReceive);
return UNDERLYINGToReceive;
}
function getPrice() public view returns (uint256) {
(, int256 price, ,uint256 updatedAt, ) = AggregatorV3Interface(oracle).latestRoundData();
require(price >= 0, "Negative Prices are not allowed");
require(block.timestamp <= updatedAt + tolerance, "Price is too stale to be trustworthy");
if (price == 0) {
return strikeInUSDC;
} else {
return (uint256(price) / (10**(8 - USDC_DECIMALS)));
}
}
function getITM() public view returns (uint256) {
if (getPrice() >= strikeInUSDC) {
return getPrice() - strikeInUSDC;
} else {
return 0;
}
}
function getOptionsSold(address seller_) public view returns (uint256) {
return optionSellers[seller_];
}
}
文件 5 的 42:AoriPut.sol
pragma solidity ^0.8.13;
import "./OpenZeppelin/ERC20.sol";
import "./OpenZeppelin/Ownable.sol";
import "./Chainlink/AggregatorV3Interface.sol";
import "./OpenZeppelin/IERC20.sol";
import "./OpenZeppelin/ReentrancyGuard.sol";
import "./AoriSeats.sol";
import "./Margin/MarginManager.sol";
contract AoriPut is ERC20, ReentrancyGuard {
address public immutable factory;
address public immutable manager;
address public oracle;
uint256 public immutable strikeInUSDC;
uint256 public immutable endingTime;
uint256 public immutable duration;
uint256 public settlementPrice;
uint256 public immutable feeMultiplier;
uint256 public immutable decimalDiff;
uint256 immutable tolerance = 2 hours;
bool public hasEnded = false;
IERC20 public immutable USDC;
IERC20 public immutable UNDERLYING;
uint256 public immutable USDC_DECIMALS;
AoriSeats public immutable AORISEATSADD;
uint256 public immutable BPS_DIVISOR = 10000;
mapping (address => uint256) optionSellers;
constructor(
address _manager,
uint256 _feeMultiplier,
uint256 _strikeInUSDC,
uint256 _duration,
IERC20 _USDC,
IERC20 _UNDERLYING,
address _oracle,
AoriSeats _AORISEATSADD,
string memory name_,
string memory symbol_
) ERC20(name_, symbol_, 18) {
factory = msg.sender;
manager = _manager;
feeMultiplier = _feeMultiplier;
strikeInUSDC = _strikeInUSDC;
duration = _duration;
USDC = _USDC;
UNDERLYING = _UNDERLYING;
USDC_DECIMALS = USDC.decimals();
endingTime = block.timestamp + duration;
oracle = _oracle;
AORISEATSADD = _AORISEATSADD;
decimalDiff = (10**decimals()) / (10**USDC_DECIMALS);
}
event PutMinted(uint256 optionsMinted, address minter);
event PutBuyerITMSettled(uint256 optionsRedeemed, address settler);
event PutSellerITMSettled(uint256 optionsRedeemed, address settler);
event PutSellerOTMSettled(uint256 optionsRedeemed, address settler);
event SellerRetrievedFunds(uint256 tokensRetrieved, address seller);
function setOracle(address newOracle) public returns(address) {
require(msg.sender == AORISEATSADD.owner());
oracle = newOracle;
return oracle;
}
function mintPut(uint256 quantityOfUSDC, address receiver, uint256 seatId) public nonReentrant returns (uint256) {
require(block.timestamp < endingTime, "This option has already matured");
require(USDC.balanceOf(msg.sender) >= quantityOfUSDC, "Not enough USDC");
require(AORISEATSADD.confirmExists(seatId) && AORISEATSADD.ownerOf(seatId) != address(0x0), "Seat does not exist");
uint256 mintingFee;
uint256 refRate;
uint256 feeToSeat;
uint256 optionsToMint;
uint256 optionsToMintScaled;
if (receiver == AORISEATSADD.ownerOf(seatId)) {
mintingFee = 0;
feeToSeat = 0;
optionsToMint = (quantityOfUSDC * 1e6) / strikeInUSDC;
optionsToMintScaled = optionsToMint * decimalDiff;
USDC.transferFrom(msg.sender, address(this), quantityOfUSDC);
_mint(receiver, optionsToMintScaled);
} else {
mintingFee = putUSDCFeeCalculator(quantityOfUSDC, AORISEATSADD.getOptionMintingFee());
refRate = (AORISEATSADD.getSeatScore(seatId) * 500) + 3500;
feeToSeat = (refRate * mintingFee) / BPS_DIVISOR;
optionsToMint = ((quantityOfUSDC - mintingFee) * 10**USDC_DECIMALS) / strikeInUSDC;
optionsToMintScaled = optionsToMint * decimalDiff;
USDC.transferFrom(msg.sender, address(this), quantityOfUSDC - mintingFee);
USDC.transferFrom(msg.sender, Ownable(factory).owner(), mintingFee - feeToSeat);
USDC.transferFrom(msg.sender, AORISEATSADD.ownerOf(seatId), feeToSeat);
_mint(receiver, optionsToMintScaled);
}
uint256 currentOptionsSold = optionSellers[msg.sender];
uint256 newOptionsSold = currentOptionsSold + optionsToMintScaled;
optionSellers[msg.sender] = newOptionsSold;
emit PutMinted(optionsToMintScaled, msg.sender);
return (optionsToMintScaled);
}
function _setSettlementPrice() internal returns (uint256) {
require(block.timestamp >= endingTime, "Option has not matured");
if(hasEnded == false) {
settlementPrice = uint256(getPrice());
hasEnded = true;
}
return settlementPrice;
}
function putUSDCFeeCalculator(uint256 quantityOfUSDC, uint256 fee) internal pure returns (uint256) {
uint256 txFee = (quantityOfUSDC * fee) / BPS_DIVISOR;
return txFee;
}
function buyerSettlementITM(uint256 optionsToSettle) public nonReentrant returns (uint256) {
_setSettlementPrice();
require(balanceOf(msg.sender) >= 0, "You have not purchased any options");
require(balanceOf(msg.sender) >= optionsToSettle, "You are attempting to settle more options than you have purhased");
require(strikeInUSDC > settlementPrice && settlementPrice != 0, "Option did not expire ITM");
require(optionsToSettle <= totalSupply() && optionsToSettle != 0);
uint256 profitPerOption = strikeInUSDC - settlementPrice;
uint256 USDCOwed = ((optionsToSettle / decimalDiff) * profitPerOption) / 10**USDC_DECIMALS;
_burn(msg.sender, optionsToSettle);
USDC.transfer(msg.sender, USDCOwed);
emit PutBuyerITMSettled(optionsToSettle, msg.sender);
return (optionsToSettle);
}
function sellerSettlementITM() public nonReentrant returns (uint256) {
_setSettlementPrice();
uint256 optionsToSettle = optionSellers[msg.sender];
require(optionsToSettle >= 0);
require(strikeInUSDC > settlementPrice && hasEnded == true, "Option did not expire OTM");
uint256 USDCToReceive = ((optionsToSettle * settlementPrice) / decimalDiff) / 10**USDC_DECIMALS;
optionSellers[msg.sender] = 0;
USDC.transfer(msg.sender, USDCToReceive);
emit PutSellerITMSettled(optionsToSettle, msg.sender);
return optionsToSettle;
}
function sellerSettlementOTM() public nonReentrant returns (uint256) {
_setSettlementPrice();
require(optionSellers[msg.sender] > 0 && settlementPrice >= strikeInUSDC, "Option did not expire OTM");
uint256 optionsSold = optionSellers[msg.sender];
optionSellers[msg.sender] = 0;
uint256 USDCOwed = ((optionsSold / decimalDiff) * strikeInUSDC) / 10**USDC_DECIMALS;
USDC.transfer(msg.sender, USDCOwed);
emit PutSellerOTMSettled(optionsSold, msg.sender);
return optionsSold;
}
function liquidationSettlement(uint256 optionsToSettle) public nonReentrant returns (uint256) {
require(msg.sender == MarginManager(manager).vaultAdd(ERC20(address(USDC))));
_burn(msg.sender, optionsToSettle);
optionSellers[manager] -= optionsToSettle;
uint256 USDCToReceive = (optionsToSettle * strikeInUSDC) / 10**USDC_DECIMALS;
USDC.transferFrom(address(this), manager, USDCToReceive);
return USDCToReceive;
}
function getPrice() public view returns (uint256) {
(, int256 price, ,uint256 updatedAt, ) = AggregatorV3Interface(oracle).latestRoundData();
require(price >= 0, "Negative Prices are not allowed");
require(block.timestamp <= updatedAt + tolerance, "Price is too stale to be trustworthy");
if (price == 0) {
return strikeInUSDC;
} else {
return (uint256(price) / (10**(8 - USDC_DECIMALS)));
}
}
function getITM() public view returns (uint256) {
if (getPrice() <= strikeInUSDC) {
return strikeInUSDC - getPrice();
} else {
return 0;
}
}
function getOptionsSold(address seller_) public view returns (uint256) {
return optionSellers[seller_];
}
}
文件 6 的 42:AoriSeats.sol
pragma solidity ^0.8.19;
import "./OpenZeppelin/ERC721Enumerable.sol";
import "./OpenZeppelin/IERC20.sol";
import "./OpenZeppelin/Ownable.sol";
import "./OpenZeppelin/ERC2981.sol";
import "./OpenZeppelin/ReentrancyGuardUpgradeable.sol";
import "./CallFactory.sol";
import "./PutFactory.sol";
import "./OrderbookFactory.sol";
contract AoriSeats is ERC721Enumerable, ERC2981, Ownable, ReentrancyGuard {
uint256 maxSeats;
uint256 public currentSeatId;
uint256 mintFee;
uint256 tradingFee;
uint256 public maxSeatScore;
uint256 public feeMultiplier;
CallFactory public CALLFACTORY;
PutFactory public PUTFACTORY;
address public minter;
address public seatRoyaltyReceiver;
uint256 public defaultSeatScore;
OrderbookFactory public ORDERBOOKFACTORY;
mapping(address => uint256) pointsTotal;
mapping(uint256 => uint256) totalVolumeBySeat;
constructor(
string memory name_,
string memory symbol_,
uint256 maxSeats_,
uint256 mintFee_,
uint256 tradingFee_,
uint256 maxSeatScore_,
uint256 feeMultiplier_
) ERC721(name_, symbol_) {
maxSeats = maxSeats_;
mintFee = mintFee_;
tradingFee = tradingFee_;
maxSeatScore = maxSeatScore_;
feeMultiplier = feeMultiplier_;
_setDefaultRoyalty(owner(), 350);
setSeatRoyaltyReceiver(owner());
setDefaultSeatScore(5);
}
event FeeSetForSeat (uint256 seatId, address SeatOwner);
event MaxSeatChange (uint256 NewMaxSeats);
event MintFeeChange (uint256 NewMintFee);
event TradingFeeChange (uint256 NewTradingFee);
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, ERC2981) returns (bool) {
return super.supportsInterface(interfaceId);
}
function setMinter(address _minter) public onlyOwner {
minter = _minter;
}
function setSeatRoyaltyReceiver(address newSeatRoyaltyReceiver) public onlyOwner {
seatRoyaltyReceiver = newSeatRoyaltyReceiver;
}
function setCallFactory(CallFactory newCALLFACTORY) public onlyOwner returns (CallFactory) {
CALLFACTORY = newCALLFACTORY;
return CALLFACTORY;
}
function setPutFactory(PutFactory newPUTFACTORY) public onlyOwner returns (PutFactory) {
PUTFACTORY = newPUTFACTORY;
return PUTFACTORY;
}
function setOrderbookFactory(OrderbookFactory newORDERBOOKFACTORY) public onlyOwner returns (OrderbookFactory) {
ORDERBOOKFACTORY = newORDERBOOKFACTORY;
return ORDERBOOKFACTORY;
}
function setBaseURI(string memory baseURI) public onlyOwner {
_setBaseURI(baseURI);
}
function setDefaultSeatScore(uint256 score) public onlyOwner returns(uint256) {
defaultSeatScore = score;
return score;
}
function mintSeat() external returns (uint256) {
require(msg.sender == minter);
uint256 currentSeatIdLocal = currentSeatId;
if (currentSeatId % 10 == 0) {
seatScore[currentSeatIdLocal] = 1;
_mint(seatRoyaltyReceiver, currentSeatIdLocal);
currentSeatIdLocal++;
}
seatScore[currentSeatIdLocal] = defaultSeatScore;
_mint(minter, currentSeatIdLocal);
currentSeatId = currentSeatIdLocal + 1;
return currentSeatIdLocal;
}
function combineSeats(uint256 seatIdOne, uint256 seatIdTwo) public returns(uint256) {
require(msg.sender == ownerOf(seatIdOne) && msg.sender == ownerOf(seatIdTwo));
uint256 newSeatScore = seatScore[seatIdOne] + seatScore[seatIdTwo];
require(newSeatScore <= maxSeatScore);
_burn(seatIdOne);
_burn(seatIdTwo);
uint256 newSeatId = currentSeatId++;
_safeMint(msg.sender, newSeatId);
seatScore[newSeatId] = newSeatScore;
return seatScore[newSeatId];
}
function separateSeats(uint256 seatId) public {
require(msg.sender == ownerOf(seatId));
uint256 currentSeatScore = seatScore[seatId];
seatScore[seatId] = 1;
_burn(seatId);
for(uint i = 0; i < currentSeatScore; i++) {
uint mintIndex = currentSeatId++;
_safeMint(msg.sender, mintIndex);
seatScore[mintIndex] = 1;
}
}
function addTakerVolume(uint256 volumeToAdd, uint256 seatId, address Orderbook_) public nonReentrant {
require(ORDERBOOKFACTORY.checkIsOrder(Orderbook_, msg.sender));
uint256 currentVolume = totalVolumeBySeat[seatId];
totalVolumeBySeat[seatId] = currentVolume + volumeToAdd;
}
function setMaxSeats(uint256 newMaxSeats) public onlyOwner returns (uint256) {
maxSeats = newMaxSeats;
emit MaxSeatChange(newMaxSeats);
return maxSeats;
}
function setFeeMultiplier(uint256 newFeeMultiplier) public onlyOwner returns (uint256) {
feeMultiplier = newFeeMultiplier;
return feeMultiplier;
}
function setMaxSeatScore(uint256 newMaxScore) public onlyOwner returns(uint256) {
require(newMaxScore > maxSeatScore);
maxSeatScore = newMaxScore;
return maxSeatScore;
}
function setMintFee(uint256 newMintFee) public onlyOwner returns (uint256) {
mintFee = newMintFee;
emit MintFeeChange(newMintFee);
return mintFee;
}
function setTradingFee(uint256 newTradingFee) public onlyOwner returns (uint256) {
tradingFee = newTradingFee;
emit TradingFeeChange(newTradingFee);
return tradingFee;
}
function setSeatIdURI(uint256 seatId, string memory _seatURI) public {
require(msg.sender == owner());
_setTokenURI(seatId, _seatURI);
}
function getOptionMintingFee() public view returns (uint256) {
return mintFee;
}
function getTradingFee() public view returns (uint256) {
return tradingFee;
}
function confirmExists(uint256 seatId) public view returns (bool) {
return _exists(seatId);
}
function getPoints(address user) public view returns (uint256) {
return pointsTotal[user];
}
function getSeatScore(uint256 seatId) public view returns (uint256) {
return seatScore[seatId];
}
function getFeeMultiplier() public view returns (uint256) {
return feeMultiplier;
}
function getSeatVolume(uint256 seatId) public view returns (uint256) {
return totalVolumeBySeat[seatId];
}
}
文件 7 的 42:Ask.sol
pragma solidity ^0.8.13;
import "./OpenZeppelin/IERC20.sol";
import "./AoriSeats.sol";
import "./OpenZeppelin/Ownable.sol";
import "./OpenZeppelin/ReentrancyGuard.sol";
import "./Chainlink/AggregatorV3Interface.sol";
contract Ask is ReentrancyGuard {
address public immutable factory;
address public immutable factoryOwner;
address public immutable maker;
uint256 public immutable USDCPerOPTION;
uint256 public immutable OPTIONSize;
uint256 public immutable fee;
uint256 public immutable feeMultiplier;
uint256 public immutable duration;
uint256 public endingTime;
AoriSeats public immutable AORISEATSADD;
bool public hasEnded = false;
bool public hasBeenFunded = false;
IERC20 public OPTION;
IERC20 public USDC;
uint256 public OPTIONDecimals = 18;
uint256 public USDCDecimals = 6;
uint256 public decimalDiff = (10**OPTIONDecimals) / (10**USDCDecimals);
uint256 public immutable BPS_DIVISOR = 10000;
uint256 public USDCFilled;
event OfferFunded(address maker, uint256 OPTIONSize, uint256 duration);
event Filled(address buyer, uint256 OPTIONAmount, uint256 AmountFilled, bool hasEnded);
event OfferCanceled(address maker, uint256 OPTIONAmount);
constructor(
IERC20 _OPTION,
IERC20 _USDC,
AoriSeats _AORISEATSADD,
address _maker,
uint256 _USDCPerOPTION,
uint256 _fee,
uint256 _feeMultiplier,
uint256 _duration,
uint256 _OPTIONSize
) {
factory = msg.sender;
factoryOwner = Ownable(factory).owner();
OPTION = _OPTION;
USDC = _USDC;
AORISEATSADD = _AORISEATSADD;
maker = _maker;
USDCPerOPTION = _USDCPerOPTION;
fee = _fee;
feeMultiplier = _feeMultiplier;
duration = _duration;
OPTIONSize = _OPTIONSize;
}
function withdrawTokens(address token) public {
require(msg.sender == factoryOwner);
if (token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
payable(factoryOwner).transfer(address(this).balance);
} else {
uint256 balance = IERC20(token).balanceOf(address(this));
safeTransfer(token, factoryOwner, balance);
}
}
function fundContract() public nonReentrant {
require(msg.sender == factory);
hasBeenFunded = true;
endingTime = block.timestamp + duration;
emit OfferFunded(maker, OPTIONSize, duration);
}
function fill(uint256 amountOfUSDC, uint256 seatId) public nonReentrant {
require(isFunded(), "no option balance");
require(msg.sender != maker && msg.sender != factory, "Cannot take one's own order");
require(!hasEnded, "offer has been previously been cancelled");
require(block.timestamp <= endingTime, "This offer has expired");
require(USDC.balanceOf(msg.sender) >= amountOfUSDC, "Not enough USDC");
require(AORISEATSADD.confirmExists(seatId) && AORISEATSADD.ownerOf(seatId) != address(0x0), "Seat does not exist");
uint256 USDCAfterFee;
uint256 OPTIONToReceive;
uint256 refRate;
if(msg.sender == AORISEATSADD.ownerOf(seatId)) {
USDCAfterFee = amountOfUSDC;
OPTIONToReceive = mulDiv(USDCAfterFee, 10**OPTIONDecimals, USDCPerOPTION);
USDC.transferFrom(msg.sender, maker, USDCAfterFee);
OPTION.transfer(msg.sender, OPTIONToReceive);
} else {
refRate = (AORISEATSADD.getSeatScore(seatId) * 500) + 3500;
uint256 seatScoreFeeInBPS = mulDiv(fee, refRate, BPS_DIVISOR);
uint256 seatTxFee = mulDiv(amountOfUSDC, seatScoreFeeInBPS, BPS_DIVISOR);
uint256 ownerTxFee = mulDiv(amountOfUSDC, fee - seatScoreFeeInBPS, BPS_DIVISOR);
USDCAfterFee = (amountOfUSDC - (ownerTxFee + seatTxFee));
OPTIONToReceive = mulDiv(USDCAfterFee, 10**OPTIONDecimals, USDCPerOPTION);
USDC.transferFrom(msg.sender, factoryOwner, ownerTxFee);
USDC.transferFrom(msg.sender, AORISEATSADD.ownerOf(seatId), seatTxFee);
USDC.transferFrom(msg.sender, maker, USDCAfterFee);
OPTION.transfer(msg.sender, OPTIONToReceive);
AORISEATSADD.addTakerVolume(amountOfUSDC, seatId, factory);
}
USDCFilled += USDCAfterFee;
if(OPTION.balanceOf(address(this)) == 0) {
hasEnded = true;
}
emit Filled(msg.sender, USDCAfterFee, amountOfUSDC, hasEnded);
}
function cancel() public nonReentrant {
require(isFunded(), "no OPTION balance");
require(msg.sender == maker);
uint256 balance = OPTION.balanceOf(address(this));
OPTION.transfer(msg.sender, balance);
hasEnded = true;
emit OfferCanceled(maker, balance);
}
function isFunded() public view returns (bool) {
if (OPTION.balanceOf(address(this)) > 0 && hasBeenFunded) {
return true;
} else {
return false;
}
}
function isFundedOverOne() public view returns (bool) {
if (OPTION.balanceOf(address(this)) > (10 ** OPTION.decimals())) {
return true;
} else {
return false;
}
}
function mulDiv(
uint256 x,
uint256 y,
uint256 z
) public pure returns (uint256) {
return (x * y) / z;
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), "safeTransfer: failed");
}
function getCurrentBalance() public view returns (uint256) {
if (OPTION.balanceOf(address(this)) >= 1) {
return OPTION.balanceOf(address(this));
} else {
return 0;
}
}
function totalUSDCWanted() public view returns (uint256) {
return (USDCPerOPTION * OPTIONSize) / 10**OPTIONDecimals;
}
}
文件 8 的 42:Bid.sol
pragma solidity ^0.8.13;
import "./OpenZeppelin/IERC20.sol";
import "./AoriSeats.sol";
import "./OpenZeppelin/Ownable.sol";
import "./OpenZeppelin/ReentrancyGuard.sol";
import "./Chainlink/AggregatorV3Interface.sol";
contract Bid is ReentrancyGuard {
address public immutable factory;
address public immutable factoryOwner;
address public immutable maker;
uint256 public immutable OPTIONPerUSDC;
uint256 public immutable USDCSize;
uint256 public immutable fee;
uint256 public immutable feeMultiplier;
uint256 public immutable duration;
uint256 public endingTime;
AoriSeats public immutable AORISEATSADD;
bool public hasEnded = false;
bool public hasBeenFunded = false;
IERC20 public USDC;
IERC20 public OPTION;
uint256 public USDCDecimals = 6;
uint256 public OPTIONDecimals = 18;
uint256 public decimalDiff = (10**OPTIONDecimals) / (10**USDCDecimals);
uint256 public immutable BPS_DIVISOR = 10000;
event OfferFunded(address maker, uint256 USDCSize, uint256 duration);
event Filled(address buyer, uint256 USDCAmount, uint256 AmountFilled, bool hasEnded);
event OfferCanceled(address maker, uint256 USDCAmount);
constructor(
IERC20 _USDC,
IERC20 _OPTION,
AoriSeats _AORISEATSADD,
address _maker,
uint256 _OPTIONPerUSDC,
uint256 _fee,
uint256 _feeMultiplier,
uint256 _duration,
uint256 _USDCSize
) {
factory = msg.sender;
factoryOwner = Ownable(factory).owner();
USDC = _USDC;
OPTION = _OPTION;
AORISEATSADD = _AORISEATSADD;
maker = _maker;
OPTIONPerUSDC = _OPTIONPerUSDC;
fee = _fee;
feeMultiplier = _feeMultiplier;
duration = _duration;
USDCSize = _USDCSize;
}
function withdrawTokens(address token) public {
require(msg.sender == factoryOwner);
if (token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
payable(factoryOwner).transfer(address(this).balance);
} else {
uint256 balance = IERC20(token).balanceOf(address(this));
safeTransfer(token, factoryOwner, balance);
}
}
function fundContract() public nonReentrant {
require(msg.sender == factory);
endingTime = endingTime + duration;
hasBeenFunded = true;
emit OfferFunded(maker, USDCSize, duration);
}
function fill(uint256 amountOfOPTION, uint256 seatId) public nonReentrant {
require(isFunded(), "no usdc balance");
require(msg.sender != maker && msg.sender != factory, "Cannot take one's own order");
require(!hasEnded, "offer has been previously been cancelled");
require(block.timestamp <= endingTime, "This offer has expired");
require(OPTION.balanceOf(msg.sender) >= amountOfOPTION, "Not enough USDC");
require(AORISEATSADD.confirmExists(seatId) && AORISEATSADD.ownerOf(seatId) != address(0x0), "Seat does not exist");
uint256 OPTIONAfterFee;
uint256 USDCToReceive;
uint256 refRate;
if(msg.sender == AORISEATSADD.ownerOf(seatId)) {
OPTIONAfterFee = amountOfOPTION;
USDCToReceive = mulDiv(OPTIONAfterFee, 10**USDCDecimals, OPTIONPerUSDC);
OPTION.transferFrom(msg.sender, maker, OPTIONAfterFee);
USDC.transfer(msg.sender, USDCToReceive);
} else {
OPTIONAfterFee = amountOfOPTION;
USDCToReceive = mulDiv(amountOfOPTION, 10**USDCDecimals, OPTIONPerUSDC);
refRate = (AORISEATSADD.getSeatScore(seatId) * 500) + 3500;
uint256 seatScoreFeeInBPS = mulDiv(fee, refRate, BPS_DIVISOR);
uint256 seatTxFee = mulDiv(USDCToReceive, seatScoreFeeInBPS, BPS_DIVISOR);
uint256 ownerTxFee = mulDiv(USDCToReceive, fee - seatScoreFeeInBPS, BPS_DIVISOR);
OPTION.transferFrom(msg.sender, maker, OPTIONAfterFee);
USDC.transfer(factoryOwner, ownerTxFee);
USDC.transfer(AORISEATSADD.ownerOf(seatId), seatTxFee);
USDC.transfer(msg.sender, USDCToReceive - (ownerTxFee + seatTxFee));
AORISEATSADD.addTakerVolume(USDCToReceive + ownerTxFee + seatTxFee, seatId, factory);
}
if(USDC.balanceOf(address(this)) == 0) {
hasEnded = true;
}
emit Filled(msg.sender, OPTIONAfterFee, amountOfOPTION, hasEnded);
}
function cancel() public nonReentrant {
require(isFunded(), "no USDC balance");
require(msg.sender == maker);
uint256 balance = USDC.balanceOf(address(this));
USDC.transfer(msg.sender, balance);
hasEnded = true;
emit OfferCanceled(maker, balance);
}
function isFunded() public view returns (bool) {
if (USDC.balanceOf(address(this)) > 0 && hasBeenFunded) {
return true;
} else {
return false;
}
}
function isFundedOverOne() public view returns (bool) {
if (USDC.balanceOf(address(this)) > (10 ** USDC.decimals())) {
return true;
} else {
return false;
}
}
function mulDiv(
uint256 x,
uint256 y,
uint256 z
) public pure returns (uint256) {
return (x * y) / z;
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), "safeTransfer: failed");
}
function getCurrentBalance() public view returns (uint256) {
if (USDC.balanceOf(address(this)) >= 1) {
return USDC.balanceOf(address(this));
} else {
return 0;
}
}
function totalUSDCWanted() public view returns (uint256) {
return (OPTIONPerUSDC * USDCSize) / 10**OPTIONDecimals;
}
}
文件 9 的 42:CallFactory.sol
pragma solidity ^0.8.13;
import "./OpenZeppelin/Ownable.sol";
import "./Interfaces/IAoriSeats.sol";
import "./AoriCall.sol";
import "./AoriSeats.sol";
import "./OpenZeppelin/IERC20.sol";
import "./Margin/MarginManager.sol";
contract CallFactory is Ownable {
mapping(address => bool) isListed;
AoriCall[] callMarkets;
address public keeper;
uint256 public fee;
AoriSeats public AORISEATSADD;
MarginManager public manager;
constructor(AoriSeats _AORISEATSADD, MarginManager _manager) {
AORISEATSADD = _AORISEATSADD;
manager = _manager;
}
event AoriCallCreated(
address AoriCallAdd,
uint256 strike,
uint256 duration,
IERC20 underlying,
IERC20 usdc,
address oracle,
string name,
string symbol
);
function setKeeper(address newKeeper) external onlyOwner returns(address) {
keeper = newKeeper;
return newKeeper;
}
function setAORISEATSADD(AoriSeats newAORISEATSADD) external onlyOwner returns(AoriSeats) {
AORISEATSADD = newAORISEATSADD;
return AORISEATSADD;
}
function createCallMarket(
uint256 strikeInUSDC,
uint256 duration,
IERC20 UNDERLYING,
IERC20 USDC,
address oracle,
string memory name_,
string memory symbol_
) public returns (AoriCall) {
require(msg.sender == keeper);
AoriCall callMarket = new AoriCall(address(manager), AoriSeats(AORISEATSADD).getFeeMultiplier(), strikeInUSDC, duration, UNDERLYING, USDC, oracle, AoriSeats(AORISEATSADD), name_, symbol_);
isListed[address(callMarket)] = true;
callMarkets.push(callMarket);
emit AoriCallCreated(address(callMarket), strikeInUSDC, duration, UNDERLYING, USDC, oracle, name_, symbol_);
return (callMarket);
}
function checkIsListed(address market) external view returns(bool) {
return isListed[market];
}
function getAORISEATSADD() external view returns(address) {
return address(AORISEATSADD);
}
function getAllCallMarkets() external view returns(AoriCall[] memory) {
return callMarkets;
}
}
文件 10 的 42:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 11 的 42:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 12 的 42:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./IERC20Metadata.sol";
import "./Context.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
constructor(string memory name_, string memory symbol_, uint8 decimals_) {
_name = name_;
_symbol = symbol_;
_decimals = decimals_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override(IERC20, IERC20Metadata) returns (uint8) {
return _decimals;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
文件 13 的 42:ERC2981.sol
pragma solidity ^0.8.0;
import "./IERC2981.sol";
import "./ERC165.sol";
abstract contract ERC2981 is IERC2981, ERC165 {
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId);
}
function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual override returns (address, uint256) {
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[tokenId];
if (royalty.receiver == address(0)) {
royalty = _defaultRoyaltyInfo;
}
uint256 royaltyAmount = (salePrice * royalty.royaltyFraction) / _feeDenominator();
return (royalty.receiver, royaltyAmount);
}
function _feeDenominator() internal pure virtual returns (uint96) {
return 10000;
}
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: invalid receiver");
_defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
}
function _deleteDefaultRoyalty() internal virtual {
delete _defaultRoyaltyInfo;
}
function _setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: Invalid parameters");
_tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
}
function _resetTokenRoyalty(uint256 tokenId) internal virtual {
delete _tokenRoyaltyInfo[tokenId];
}
}
文件 14 的 42:ERC4626.sol
pragma solidity ^0.8.0;
import "./ERC20.sol";
import "./SafeERC20.sol";
import "./IERC4626.sol";
import "./Math.sol";
abstract contract ERC4626 is ERC20, IERC4626 {
using Math for uint256;
IERC20 private immutable _asset;
uint8 private immutable _underlyingDecimals;
uint256 public totalBorrows;
constructor(IERC20 asset_, string memory _name, string memory _symbol) ERC20(_name, _symbol, 18){
(bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
_underlyingDecimals = success ? assetDecimals : 18;
_asset = asset_;
}
function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) {
(bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
abi.encodeWithSelector(IERC20Metadata.decimals.selector)
);
if (success && encodedDecimals.length >= 32) {
uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
if (returnedDecimals <= type(uint8).max) {
return (true, uint8(returnedDecimals));
}
}
return (false, 0);
}
function decimals() public view virtual override(IERC20Metadata, IERC20, ERC20) returns (uint8) {
return _underlyingDecimals + _decimalsOffset();
}
function asset() public view virtual override returns (address) {
return address(_asset);
}
function totalAssets() public view virtual override returns (uint256) {
return _asset.balanceOf(address(this)) + totalBorrows;
}
function convertToShares(uint256 assets) public view virtual override returns (uint256) {
return _convertToShares(assets, Math.Rounding.Down);
}
function convertToAssets(uint256 shares) public view virtual override returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Down);
}
function maxDeposit(address) public view virtual override returns (uint256) {
return type(uint256).max;
}
function maxMint(address) public view virtual override returns (uint256) {
return type(uint256).max;
}
function maxWithdraw(address owner) public view virtual override returns (uint256) {
return _convertToAssets(balanceOf(owner), Math.Rounding.Down);
}
function maxRedeem(address owner) public view virtual override returns (uint256) {
return balanceOf(owner);
}
function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
return _convertToShares(assets, Math.Rounding.Down);
}
function previewMint(uint256 shares) public view virtual override returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Up);
}
function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
return _convertToShares(assets, Math.Rounding.Up);
}
function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Down);
}
function deposit(uint256 assets, address receiver) public virtual override returns (uint256) {
require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max");
uint256 shares = previewDeposit(assets);
_deposit(_msgSender(), receiver, assets, shares);
return shares;
}
function mint(uint256 shares, address receiver) public virtual override returns (uint256) {
require(shares <= maxMint(receiver), "ERC4626: mint more than max");
uint256 assets = previewMint(shares);
_deposit(_msgSender(), receiver, assets, shares);
return assets;
}
function withdraw(uint256 assets, address receiver, address owner) public virtual override returns (uint256) {
require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max");
uint256 shares = previewWithdraw(assets);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return shares;
}
function redeem(uint256 shares, address receiver, address owner) public virtual override returns (uint256) {
require(shares <= maxRedeem(owner), "ERC4626: redeem more than max");
uint256 assets = previewRedeem(shares);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return assets;
}
function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {
return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
}
function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256) {
return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), rounding);
}
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual {
SafeERC20.safeTransferFrom(_asset, caller, address(this), assets);
_mint(receiver, shares);
emit Deposit(caller, receiver, assets, shares);
}
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256 shares
) internal virtual {
if (caller != owner) {
_spendAllowance(owner, caller, shares);
}
_burn(owner, shares);
SafeERC20.safeTransfer(_asset, receiver, assets);
emit Withdraw(caller, receiver, owner, assets, shares);
}
function _decimalsOffset() internal view virtual returns (uint8) {
return 0;
}
}
文件 15 的 42:ERC721.sol
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./IERC721Metadata.sol";
import "./Address.sol";
import "./Context.sol";
import "./Strings.sol";
import "./ERC165.sol";
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
string private _name;
string private _symbol;
string private _baseURI;
mapping(uint256 => address) private _owners;
mapping(address => uint256) private _balances;
mapping(uint256 => address) private _tokenApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
mapping (uint256 => string) private _tokenURIs;
mapping(uint256 => uint256) seatScore;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: address zero is not a valid owner");
return _balances[owner];
}
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _ownerOf(tokenId);
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = baseURI();
if (bytes(base).length == 0) {
return _tokenURI;
}
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
string memory seatURI = string.concat(seatScore[tokenId].toString(), ".json");
return string(abi.encodePacked(base, seatURI));
}
function baseURI() public view virtual returns (string memory) {
return _baseURI;
}
function _setBaseURI(string memory baseURI_) internal virtual {
_baseURI = baseURI_;
}
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
_tokenURIs[tokenId] = _tokenURI;
}
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not token owner or approved for all"
);
_approve(to, tokenId);
}
function getApproved(uint256 tokenId) public view virtual override returns (address) {
_requireMinted(tokenId);
return _tokenApprovals[tokenId];
}
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_transfer(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_safeTransfer(from, to, tokenId, data);
}
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
}
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _ownerOf(tokenId) != address(0);
}
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
}
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId, 1);
require(!_exists(tokenId), "ERC721: token already minted");
unchecked {
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId, 1);
}
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId, 1);
owner = ERC721.ownerOf(tokenId);
delete _tokenApprovals[tokenId];
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
unchecked {
_balances[owner] -= 1;
}
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId, 1);
}
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId, 1);
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
delete _tokenApprovals[tokenId];
unchecked {
_balances[from] -= 1;
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId, 1);
}
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "ERC721: invalid token ID");
}
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 ,
uint256 batchSize
) internal virtual {
if (batchSize > 1) {
if (from != address(0)) {
_balances[from] -= batchSize;
}
if (to != address(0)) {
_balances[to] += batchSize;
}
}
}
function _afterTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}
}
文件 16 的 42:ERC721Enumerable.sol
pragma solidity ^0.8.0;
import "./ERC721.sol";
import "./IERC721Enumerable.sol";
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
mapping(uint256 => uint256) private _ownedTokensIndex;
uint256[] private _allTokens;
mapping(uint256 => uint256) private _allTokensIndex;
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (batchSize > 1) {
revert("ERC721Enumerable: consecutive transfers not supported");
}
uint256 tokenId = firstTokenId;
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId;
_ownedTokensIndex[lastTokenId] = tokenIndex;
}
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId;
_allTokensIndex[lastTokenId] = tokenIndex;
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}
文件 17 的 42:IAoriSeats.sol
pragma solidity 0.8.19;
import "../OpenZeppelin/IERC20.sol";
interface IAoriSeats {
function setMinter(address _minter) external returns (address);
function setAORITOKEN(IERC20 newAORITOKEN) external returns (IERC20);
function setBaseURI(string memory baseURI) external returns(string memory);
function mintSeat() external returns (uint256);
function combineSeats(uint256 seatIdOne, uint256 seatIdTwo) external returns(uint256);
function separateSeats(uint256 seatId) external;
function addPoints(uint256 pointsToAdd, address userAdd) external;
function addTakerPoints(uint256 pointsToAdd, address userAdd, address Orderbook_) external;
function addTakerVolume(uint256 volumeToAdd, uint256 seatId, address Orderbook_) external;
function claimAORI(address claimer) external;
function setMaxSeats(uint256 newMaxSeats) external returns (uint256);
function setFeeMultiplier(uint256 newFeeMultiplier) external returns (uint256);
function setMaxSeatScore(uint256 newMaxScore) external returns(uint256);
function setMinFee(uint256 newMintFee) external returns (uint256);
function getOptionMintingFee() external view returns (uint256);
function confirmExists(uint256 seatId) external view returns (bool);
function getTotalPoints(address user) external view returns (uint256);
function getClaimablePoints(address user) external view returns (uint256);
function getSeatScore(uint256 seatId) external view returns (uint256);
function getmaxSeatScore() external view returns (uint256);
function getFeeMultiplier() external view returns (uint256);
function getSeatVolume(uint256 seatId) external view returns (uint256);
}
文件 18 的 42:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 19 的 42:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
function decimals() external view returns (uint8);
}
文件 20 的 42:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 21 的 42:IERC20Permit.sol
pragma solidity ^0.8.0;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
文件 22 的 42:IERC2981.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
interface IERC2981 is IERC165 {
function royaltyInfo(
uint256 tokenId,
uint256 salePrice
) external view returns (address receiver, uint256 royaltyAmount);
}
文件 23 的 42:IERC4626.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./IERC20Metadata.sol";
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
function asset() external view returns (address assetTokenAddress);
function totalAssets() external view returns (uint256 totalManagedAssets);
function convertToShares(uint256 assets) external view returns (uint256 shares);
function convertToAssets(uint256 shares) external view returns (uint256 assets);
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
function previewDeposit(uint256 assets) external view returns (uint256 shares);
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
function maxMint(address receiver) external view returns (uint256 maxShares);
function previewMint(uint256 shares) external view returns (uint256 assets);
function mint(uint256 shares, address receiver) external returns (uint256 assets);
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
function maxRedeem(address owner) external view returns (uint256 maxShares);
function previewRedeem(uint256 shares) external view returns (uint256 assets);
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}
文件 24 的 42:IERC721.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
function safeTransferFrom(address from, address to, uint256 tokenId) external;
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
文件 25 的 42:IERC721Enumerable.sol
pragma solidity ^0.8.0;
import "./IERC721.sol";
interface IERC721Enumerable is IERC721 {
function totalSupply() external view returns (uint256);
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
function tokenByIndex(uint256 index) external view returns (uint256);
}
文件 26 的 42:IERC721Metadata.sol
pragma solidity ^0.8.0;
import "./IERC721.sol";
interface IERC721Metadata is IERC721 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);
}
文件 27 的 42:IERC721Receiver.sol
pragma solidity ^0.8.0;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 28 的 42:Initializable.sol
pragma solidity ^0.8.2;
import "./AddressUpgradeable.sol";
abstract contract Initializable {
uint8 private _initialized;
bool private _initializing;
event Initialized(uint8 version);
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
}
文件 29 的 42:MarginManager.sol
pragma solidity 0.8.19;
import "../OpenZeppelin/Ownable.sol";
import "../Chainlink/AggregatorV3Interface.sol";
import "./PositionRouter.sol";
import "../OpenZeppelin/Ownable.sol";
import "../OpenZeppelin/ReentrancyGuard.sol";
import "./Vault.sol";
contract MarginManager is Ownable, ReentrancyGuard {
PositionRouter public positionRouter;
uint256 public immutable BPS_DIVISOR = 10000;
uint256 public collateralRatio;
uint256 immutable expScale = 1e18;
uint256 immutable USDCScale = 10**6;
mapping(ERC20 => bool) public whitelistedAssets;
mapping(ERC20 => Vault) public lpTokens;
mapping(ERC20 => AggregatorV3Interface) public oracles;
mapping(bytes32 => Position) public positions;
struct Position {
address account;
bool isCall;
address token;
address option;
uint256 strikeInUSDC;
uint256 optionSize;
uint256 collateral;
uint256 entryMarginRate;
uint256 lastAccrueTime;
address orderbook;
uint256 endingTime;
}
constructor(
PositionRouter _positionRouter
){
positionRouter = _positionRouter;
}
event PositionCreated(bytes32 key_, address _account, uint256 _optionSize, address _orderbook, bool _isCall);
event PositionUpdated(bytes32 key_, address _account, uint256 _optionSize, address _orderbook, bool _isCall);
function openShortPosition(
address account_,
uint256 collateral,
address orderbook,
bool isCall,
uint256 amountOfUnderlying,
uint256 seatId
) public nonReentrant returns (bytes32){
require(msg.sender == address(positionRouter));
bytes32 key;
Structs.Vars memory localVars;
address option = address(Orderbook(orderbook).OPTION());
ERC20 token;
if(isCall) {
token = ERC20(address(AoriCall(option).UNDERLYING()));
localVars.optionsMinted = lpTokens[token].mintOptions(amountOfUnderlying, option, seatId, account_, true);
key = getPositionKey(account_, localVars.optionsMinted, orderbook, true);
Position storage position = positions[key];
position.account = account_;
position.isCall = true;
position.option = option;
position.strikeInUSDC = AoriCall(option).strikeInUSDC();
position.optionSize = localVars.optionsMinted;
position.collateral = collateral;
position.entryMarginRate = positionRouter.getBorrowRate(token);
position.lastAccrueTime = block.timestamp;
position.orderbook = orderbook;
position.endingTime = AoriCall(option).endingTime();
emit PositionCreated(key, account_, position.optionSize, position.orderbook, true);
} else if(!isCall) {
token = ERC20(address(AoriPut(option).USDC()));
localVars.optionsMinted = lpTokens[token].mintOptions(amountOfUnderlying, option, seatId, account_, false);
key = getPositionKey(account_, localVars.optionsMinted, orderbook, true);
Position storage position = positions[key];
position.account = account_;
position.isCall = false;
position.option = option;
position.strikeInUSDC = AoriPut(option).strikeInUSDC();
position.optionSize = localVars.optionsMinted;
position.collateral = collateral;
position.entryMarginRate = positionRouter.getBorrowRate(token);
position.lastAccrueTime = block.timestamp;
position.orderbook = orderbook;
position.endingTime = AoriPut(option).endingTime();
emit PositionCreated(key, account_, position.optionSize, position.orderbook, false);
}
return key;
}
function settlePosition(address account, bytes32 key) public nonReentrant {
Position memory position = positions[key];
uint256 collateralMinusLoss;
ERC20 underlying;
if(position.isCall) {
AoriCall(position.option).endingTime();
require(block.timestamp >= AoriCall(position.option).endingTime(), "Option has not reached expiry");
underlying = ERC20(address(AoriCall(position.option).UNDERLYING()));
if(AoriCall(position.option).getITM() > 0) {
lpTokens[underlying].settleITMOption(position.option, true);
collateralMinusLoss = position.collateral - positionRouter.mulDiv(AoriCall(position.option).settlementPrice() - position.strikeInUSDC, position.optionSize, USDCScale);
underlying.approve(account, collateralMinusLoss);
underlying.transfer(account, collateralMinusLoss);
underlying.decreaseAllowance(account, underlying.allowance(address(this), account));
delete positions[key];
emit PositionUpdated(key, account, position.optionSize, position.orderbook, position.isCall);
} else {
lpTokens[underlying].settleOTMOption(position.option, true);
underlying.approve(account, position.collateral);
underlying.transfer(account, position.collateral);
underlying.decreaseAllowance(account, underlying.allowance(address(this), account));
delete positions[key];
emit PositionUpdated(key, account, position.optionSize, position.orderbook, position.isCall);
}
} else {
require(block.timestamp >= AoriCall(position.option).endingTime(), "Option has not reached expiry");
underlying = ERC20(address(AoriPut(position.option).USDC()));
if(AoriPut(position.option).getITM() > 0) {
lpTokens[underlying].settleITMOption(position.option, false);
collateralMinusLoss = position.collateral - positionRouter.mulDiv(position.strikeInUSDC - AoriPut(position.option).settlementPrice(), position.optionSize, expScale);
doTransferOut(underlying, account, collateralMinusLoss);
delete positions[key];
emit PositionUpdated(key, account, position.optionSize, position.orderbook, position.isCall);
} else {
lpTokens[underlying].settleOTMOption(position.option, false);
doTransferOut(underlying, account, collateralMinusLoss);
delete positions[key];
emit PositionUpdated(key, account, position.optionSize, position.orderbook, position.isCall);
}
}
}
function addCollateral(bytes32 key, uint256 collateralToAdd) public nonReentrant returns (uint256) {
Position memory position = positions[key];
ERC20 underlying;
if(position.isCall) {
underlying = ERC20(address(AoriCall(position.option).UNDERLYING()));
underlying.transferFrom(msg.sender, address(this), collateralToAdd);
position.collateral += collateralToAdd;
emit PositionUpdated(key, position.account, position.optionSize, position.orderbook, true);
} else {
underlying = ERC20(address(AoriPut(position.option).UNDERLYING()));
underlying.transferFrom(msg.sender, address(this), collateralToAdd);
position.collateral += collateralToAdd;
emit PositionUpdated(key, position.account, position.optionSize, position.orderbook, true);
}
return position.collateral;
}
function liquidatePosition(bytes32 key, uint256 fairValueOfOption, address liquidator) public returns (uint256) {
require(positionRouter.isLiquidator(msg.sender));
Position memory position = positions[key];
accruePositionInterest(key);
Structs.Vars memory localVars;
ERC20 underlying;
if(position.isCall) {
underlying = ERC20(address(AoriCall(position.option).UNDERLYING()));
require(whitelistedAssets[underlying], "Asset it not whitelisted");
(localVars.collateralVal, localVars.portfolioVal, localVars.isLiquidatable) = positionRouter.isLiquidatable(underlying, fairValueOfOption, position.optionSize, position.collateral, true);
require(localVars.isLiquidatable, "Portfolio is not liquidatable");
localVars.profit = localVars.collateralVal - localVars.portfolioVal;
localVars.profitInUnderlying = positionRouter.mulDiv(localVars.profit, 10**underlying.decimals(), positionRouter.getPrice(oracles[underlying]));
uint256 fairValueInUnderlying = positionRouter.mulDiv(fairValueOfOption, position.optionSize, positionRouter.getPrice(oracles[underlying]));
localVars.collateralToLiquidator = fairValueInUnderlying + positionRouter.mulDiv(localVars.profitInUnderlying, positionRouter.liquidatorFee(), BPS_DIVISOR);
doTransferOut(ERC20(position.option), address(lpTokens[underlying]), position.optionSize);
lpTokens[underlying].closeHedgedPosition(position.option, true, position.optionSize);
doTransferOut(underlying, liquidator, localVars.collateralToLiquidator);
doTransferOut(underlying, address(lpTokens[underlying]), position.collateral - localVars.collateralToLiquidator);
delete positions[key];
emit PositionUpdated(key, position.account, position.optionSize, position.orderbook, true);
} else {
underlying = ERC20(address(AoriPut(position.option).USDC()));
require(whitelistedAssets[underlying], "Asset it not whitelisted");
(localVars.collateralVal, localVars.portfolioVal, localVars.isLiquidatable) = positionRouter.isLiquidatable(underlying, fairValueOfOption, position.optionSize, position.collateral, false);
require(localVars.isLiquidatable, "Portfolio is not liquidatable");
localVars.profit = localVars.collateralVal - localVars.portfolioVal;
localVars.profitInUnderlying = positionRouter.mulDiv(localVars.profit, 10**USDCScale, positionRouter.getPrice(oracles[underlying]));
localVars.collateralToLiquidator = fairValueOfOption + positionRouter.mulDiv(localVars.profitInUnderlying, positionRouter.liquidatorFee(), BPS_DIVISOR);
doTransferOut(AoriPut(position.option), address(lpTokens[underlying]), position.optionSize);
lpTokens[underlying].closeHedgedPosition(position.option, true, position.optionSize);
doTransferOut(underlying, liquidator, localVars.collateralToLiquidator);
doTransferOut(underlying, address(lpTokens[underlying]), position.collateral - localVars.collateralToLiquidator);
AoriPut(position.option).liquidationSettlement(position.optionSize);
delete positions[key];
emit PositionUpdated(key, position.account, position.optionSize, position.orderbook, false);
}
}
function accruePositionInterest(bytes32 key) public returns (bool) {
Position memory position = positions[key];
ERC20 underlying;
AoriCall call;
AoriPut put;
uint256 interestOwed;
require(block.timestamp - position.lastAccrueTime > 0, "cannot accrue position interest at the moment of deployment");
if(position.isCall) {
call = AoriCall(position.option);
underlying = ERC20(address(call.UNDERLYING()));
uint256 interestFactor = ((positionRouter.getBorrowRate(underlying) + position.entryMarginRate) / 2) * (block.timestamp - position.lastAccrueTime);
interestOwed = positionRouter.mulDiv(interestFactor, position.optionSize, expScale);
doTransferOut(underlying, address(lpTokens[underlying]), interestOwed);
} else {
put = AoriPut(position.option);
underlying = ERC20(address(put.UNDERLYING()));
uint256 interestFactor = ((positionRouter.getBorrowRate(underlying) + position.entryMarginRate) / 2) * (block.timestamp - position.lastAccrueTime);
uint256 USDCUnderlying = positionRouter.mulDiv(position.optionSize, position.strikeInUSDC, expScale);
interestOwed = positionRouter.mulDiv(interestFactor, USDCUnderlying, expScale);
doTransferOut(underlying, address(lpTokens[underlying]), interestOwed);
}
if(position.collateral > interestOwed) {
position.collateral -= interestOwed;
position.lastAccrueTime = block.timestamp;
lpTokens[underlying].repaid(interestOwed);
return true;
} else {
return false;
}
}
function whitelistAsset(ERC20 token, AggregatorV3Interface oracle) public onlyOwner nonReentrant returns(ERC20) {
whitelistedAssets[token] = true;
Vault lpToken = new Vault(token, string.concat("Aori Vault for",string(token.name())), string.concat("a",string(token.name())), MarginManager(address(this)));
lpTokens[token] = lpToken;
oracles[token] = oracle;
return token;
}
function getPosition(address _account, uint256 _optionSize, address _orderbook, bool _isCall) public view returns (address, bool, address, uint256, uint256, uint256, uint256, uint256, address, uint256) {
bytes32 key = getPositionKey(_account, _optionSize, _orderbook, _isCall);
Position memory position = positions[key];
return (
position.account,
position.isCall,
position.option,
position.strikeInUSDC,
position.optionSize,
position.collateral,
position.entryMarginRate,
position.lastAccrueTime,
position.orderbook,
position.endingTime
);
}
function getPositionWithKey(bytes32 key) public view returns (address, bool, address, uint256, uint256, uint256, uint256, uint256, address, uint256) {
Position memory position = positions[key];
return (
position.account,
position.isCall,
position.option,
position.strikeInUSDC,
position.optionSize,
position.collateral,
position.entryMarginRate,
position.lastAccrueTime,
position.orderbook,
position.endingTime
);
}
function getPositionKey(address _account, uint256 _optionSize, address _orderbook, bool _isCall) public pure returns (bytes32) {
return keccak256(abi.encodePacked(
_account,
_optionSize,
_orderbook,
_isCall
));
}
function vaultAdd(ERC20 token) public view returns (address) {
require(whitelistedAssets[token], "Unsupported market");
return address(lpTokens[token]);
}
function doTransferOut(ERC20 token, address receiver, uint256 amount) internal returns (bool) {
token.approve(receiver, amount);
token.transfer(receiver, amount);
token.decreaseAllowance(receiver, token.allowance(address(this), receiver));
}
}
文件 30 的 42:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1, "Math: mulDiv overflow");
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
文件 31 的 42:Orderbook.sol
pragma solidity ^0.8.13;
import "./OpenZeppelin/Ownable.sol";
import "./AoriSeats.sol";
import "./Bid.sol";
import "./Ask.sol";
import "./AoriCall.sol";
contract Orderbook is Ownable {
address public ORDERBOOKFACTORY;
AoriSeats public immutable AORISEATSADD;
IERC20 public immutable OPTION;
IERC20 public immutable USDC;
uint256 public immutable fee_;
uint256 public duration;
uint256 public endingTime;
Ask[] public asks;
Bid[] public bids;
mapping(address => bool) isAsk;
mapping(address => bool) isBid;
constructor(
uint256 _fee,
IERC20 _OPTION,
IERC20 _USDC,
AoriSeats _AORISEATSADD,
uint256 _duration
) {
ORDERBOOKFACTORY = msg.sender;
duration = _duration;
endingTime = block.timestamp + duration;
AORISEATSADD = _AORISEATSADD;
OPTION = _OPTION;
USDC = _USDC;
fee_ = _fee;
}
event AskCreated(address ask, uint256 , uint256 duration, uint256 OPTIONSize);
event BidCreated(address bid, uint256 , uint256 duration, uint256 _USDCSize);
function createAsk(uint256 _USDCPerOPTION, uint256 _duration, uint256 _OPTIONSize) public returns (Ask) {
Ask ask = new Ask(OPTION, USDC, AORISEATSADD, msg.sender, _USDCPerOPTION, fee_, AoriSeats(AORISEATSADD).getFeeMultiplier() , _duration, _OPTIONSize);
asks.push(ask);
OPTION.transferFrom(msg.sender, address(ask), _OPTIONSize);
isAsk[address(ask)] = true;
ask.fundContract();
emit AskCreated(address(ask), _USDCPerOPTION, _duration, _OPTIONSize);
return ask;
}
function createBid(uint256 _OPTIONPerUSDC, uint256 _duration, uint256 _USDCSize) public returns (Bid) {
Bid bid = new Bid(USDC, OPTION, AORISEATSADD, msg.sender, _OPTIONPerUSDC, fee_, AoriSeats(AORISEATSADD).getFeeMultiplier() , _duration, _USDCSize);
bids.push(bid);
USDC.transferFrom(msg.sender, address(bid), _USDCSize);
isBid[address(bid)] = true;
bid.fundContract();
emit BidCreated(address(bid), _OPTIONPerUSDC, _duration, _USDCSize);
return bid;
}
function getActiveAsks() external view returns (Ask[] memory) {
Ask[] memory activeAsks = new Ask[](asks.length);
uint256 count;
for (uint256 i; i < asks.length; i++) {
Ask ask = Ask(asks[i]);
if (ask.isFunded() && !ask.hasEnded() && address(ask) != address(0)) {
activeAsks[count++] = ask;
}
}
return activeAsks;
}
function getActiveBids() external view returns (Bid[] memory) {
Bid[] memory activeBids = new Bid[](bids.length);
uint256 count;
for (uint256 i; i < bids.length; i++) {
Bid bid = Bid(bids[i]);
if (bid.isFunded() && !bid.hasEnded() && address(bid) != address(0)) {
activeBids[count++] = bid;
}
}
return activeBids;
}
function getIsAsk(address ask) external view returns (bool) {
return isAsk[ask];
}
function getIsBid(address bid) external view returns (bool) {
return isBid[bid];
}
function UNDERLYING(bool isCall) external view returns (address) {
if(isCall) {
return address(AoriCall(address(OPTION)).UNDERLYING());
} else {
return address(USDC);
}
}
}
文件 32 的 42:OrderbookFactory.sol
pragma solidity ^0.8.19;
import "./OpenZeppelin/Ownable.sol";
import "./AoriSeats.sol";
import "./OpenZeppelin/IERC20.sol";
import "./Orderbook.sol";
contract OrderbookFactory is Ownable {
mapping(address => bool) isListedOrderbook;
Orderbook[] public orderbookAdds;
address public keeper;
AoriSeats public AORISEATSADD;
constructor(AoriSeats _AORISEATSADD) {
AORISEATSADD = _AORISEATSADD;
}
event AoriOrderbookCreated(
address AoriCallMarketAdd,
uint256 fee,
IERC20 underlyingAsset
);
function setKeeper(address newKeeper) external onlyOwner returns(address) {
keeper = newKeeper;
return keeper;
}
function setAORISEATSADD(AoriSeats newAORISEATSADD) external onlyOwner returns(AoriSeats) {
AORISEATSADD = newAORISEATSADD;
return AORISEATSADD;
}
function getTradingFee() internal view returns(uint256) {
return AORISEATSADD.getTradingFee();
}
function createOrderbook(
IERC20 OPTION_,
IERC20 USDC,
uint256 _duration
) public returns (Orderbook) {
require(msg.sender == keeper);
Orderbook orderbook = new Orderbook(getTradingFee(), OPTION_, USDC, AORISEATSADD, _duration);
isListedOrderbook[address(orderbook)] = true;
orderbookAdds.push(orderbook);
emit AoriOrderbookCreated(address(orderbook), getTradingFee(), OPTION_);
return (orderbook);
}
function checkIsListedOrderbook(address Orderbook_) public view returns(bool) {
return isListedOrderbook[Orderbook_];
}
function checkIsOrder(address Orderbook_, address order_) public view returns(bool) {
require(checkIsListedOrderbook(Orderbook_), "Orderbook is not listed");
require(Orderbook(Orderbook_).getIsBid(order_) == true || Orderbook(Orderbook_).getIsAsk(order_) == true, "Is not a confirmed order");
return true;
}
function withdrawFees(IERC20 token, uint256 amount_) external onlyOwner returns(uint256) {
IERC20(token).transfer(owner(), amount_);
return amount_;
}
function getAllOrderbooks() external view returns(Orderbook[] memory) {
return orderbookAdds;
}
}
文件 33 的 42:Ownable.sol
pragma solidity ^0.8.0;
import "./Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 34 的 42:PositionRouter.sol
pragma solidity 0.8.19;
import "../OpenZeppelin/Ownable.sol";
import "./MarginManager.sol";
import "../OpenZeppelin/ERC20.sol";
import "./Vault.sol";
import "./Structs.sol";
import "../AoriCall.sol";
import "../AoriPut.sol";
import "../Orderbook.sol";
import "../CallFactory.sol";
import "../PutFactory.sol";
contract PositionRouter is Ownable {
address public callFactory;
address public putFactory;
MarginManager public manager;
uint256 immutable tolerance = 2 hours;
uint256 public immutable BPS_DIVISOR = 10000;
uint256 immutable expScale = 1e18;
uint256 immutable USDCScale = 1e6;
mapping(address => bool) public isLiquidator;
mapping(address => bool) public keeper;
uint256 public liquidatorFee;
uint256 public liquidationRatio;
uint256 public initialMarginRatio;
uint256 public liquidatorSeatId;
mapping(ERC20 => IRM) public interestRateModels;
mapping(bytes32 => Structs.OpenPositionRequest) public openPositionRequests;
bytes32[] public openPositionRequestKeys;
uint256 indexPosition;
struct IRM {
uint256 baseRate;
uint256 kinkUtil;
uint256 rateBeforeUtil;
uint256 rateAfterUtil;
}
event RequestCreated(bytes32 key, address account, uint256 index);
event OrderApproved(bytes32 key, address account, uint256 index);
event OrderDenied(uint256 index);
function initialize(
address callFactory_,
address putFactory_,
MarginManager manager_,
uint256 liquidatorFee_,
uint256 liquidationRatio_,
uint256 initialMarginRatio_,
uint256 liquidatorSeatId_,
address keeper_
) public onlyOwner {
callFactory = callFactory_;
putFactory = putFactory_;
manager = manager_;
liquidatorFee = liquidatorFee_;
liquidationRatio = liquidationRatio_;
initialMarginRatio = initialMarginRatio_;
setLiquidatorSeatId(liquidatorSeatId_);
setKeeper(keeper_);
}
function setLiquidator(address liquidator) public onlyOwner {
isLiquidator[liquidator] = true;
}
function setKeeper(address _keeper) public onlyOwner {
keeper[_keeper] = true;
}
function setLiquidatorFee(uint256 newFee) public onlyOwner returns(uint256) {
liquidatorFee = newFee;
return newFee;
}
function setLiquidatorSeatId(uint256 newLiquidatorSeatId) public onlyOwner returns(uint256) {
liquidatorSeatId = newLiquidatorSeatId;
return liquidatorSeatId;
}
function setLiquidatonThreshold(uint256 newThreshold) public onlyOwner returns(uint256) {
liquidationRatio = newThreshold;
return newThreshold;
}
function setInitialMarginRatio(uint256 newInitialMarginRatio) public onlyOwner returns(uint256) {
initialMarginRatio = newInitialMarginRatio;
return initialMarginRatio;
}
function openShortPositionRequest(
address _account,
address option,
uint256 collateral,
address orderbook,
bool isCall,
uint256 amountOfUnderlying,
uint256 seatId
)
public returns (uint256) {
require(amountOfUnderlying > 0, "Must request some borrow");
address token;
bytes32 requestKey;
uint256 optionsToMint;
uint256 currentIndex;
if(isCall) {
token = address(AoriCall(option).UNDERLYING());
require(CallFactory(callFactory).checkIsListed(option), "Not a valid call market");
require(AoriCall(option).endingTime() != 0, "Invalid maturity");
optionsToMint = mulDiv(amountOfUnderlying, USDCScale, AoriCall(option).strikeInUSDC());
ERC20(token).transferFrom(msg.sender, address(this), collateral);
currentIndex = indexPosition;
requestKey = getRequestKey(_account, indexPosition);
indexPosition++;
Structs.OpenPositionRequest storage positionRequest = openPositionRequests[requestKey];
positionRequest.account = _account;
positionRequest.collateral = collateral;
positionRequest.seatId = seatId;
positionRequest.orderbook = orderbook;
positionRequest.isCall = true;
positionRequest.amountOfUnderlying = amountOfUnderlying;
positionRequest.endingTime = AoriCall(option).endingTime();
openPositionRequestKeys.push(requestKey);
emit RequestCreated(requestKey, _account, currentIndex);
return currentIndex;
} else {
token = address(AoriPut(option).USDC());
require(PutFactory(putFactory).checkIsListed(option), "Not a valid put market");
require(AoriPut(option).endingTime() != 0, "Invalid maturity");
optionsToMint = 10**(12) * mulDiv(amountOfUnderlying, USDCScale, AoriPut(option).strikeInUSDC());
ERC20(token).transferFrom(msg.sender, address(this), collateral);
currentIndex = indexPosition;
requestKey = getRequestKey(_account, currentIndex);
indexPosition++;
Structs.OpenPositionRequest storage positionRequest = openPositionRequests[requestKey];
positionRequest.account = _account;
positionRequest.collateral = collateral;
positionRequest.seatId = seatId;
positionRequest.orderbook = orderbook;
positionRequest.isCall = false;
positionRequest.amountOfUnderlying = amountOfUnderlying;
positionRequest.endingTime = AoriPut(option).endingTime();
openPositionRequestKeys.push(requestKey);
emit RequestCreated(requestKey, _account, currentIndex);
return currentIndex;
}
}
function executeOpenPosition(uint256 indexToExecute) public returns (bytes32) {
require(keeper[msg.sender]);
bytes32 key = openPositionRequestKeys[indexToExecute];
Structs.OpenPositionRequest memory positionRequest = openPositionRequests[key];
ERC20 underlying;
if(positionRequest.isCall) {
underlying = AoriCall(address(Orderbook(positionRequest.orderbook).UNDERLYING(true)));
underlying.approve(address(manager), positionRequest.collateral);
} else if (!positionRequest.isCall){
underlying = ERC20(address(Orderbook(positionRequest.orderbook).USDC()));
underlying.approve(address(manager), positionRequest.collateral);
}
underlying.transfer(address(manager), positionRequest.collateral);
bytes32 keyToEmit = manager.openShortPosition(
positionRequest.account,
positionRequest.collateral,
positionRequest.orderbook,
positionRequest.isCall,
positionRequest.amountOfUnderlying,
positionRequest.seatId
);
emit OrderApproved(keyToEmit, positionRequest.account, indexToExecute);
delete openPositionRequestKeys[indexToExecute];
return keyToEmit;
}
function rejectIncreasePosition(uint256 indexToReject) public {
require(keeper[msg.sender]);
emit OrderDenied(indexToReject);
delete openPositionRequestKeys[indexToReject];
}
function getBorrowRate(ERC20 token) public view returns (uint256) {
require(manager.whitelistedAssets(token), "Unsupported vault");
Vault vault = manager.lpTokens(token);
uint256 util = mulDiv(vault.totalBorrows(), expScale, token.balanceOf(address(vault)) + vault.totalBorrows());
IRM memory irm = interestRateModels[token];
if (util <= irm.kinkUtil) {
return irm.baseRate + mulDiv(util, irm.rateBeforeUtil, expScale);
} else {
uint256 prePlusPost = mulDiv(irm.kinkUtil, irm.rateBeforeUtil, expScale) + mulDiv((util - irm.kinkUtil), irm.rateAfterUtil, expScale);
return (prePlusPost + irm.baseRate);
}
}
function isLiquidatable(ERC20 token, uint256 fairValueOfOption, uint256 optionSize, uint256 collateral, bool isCall) public view returns(uint256, uint256, bool) {
uint256 collateralVal;
uint256 positionVal;
uint256 liquidationThreshold;
if(isCall) {
collateralVal = mulDiv(getPrice(manager.oracles(token)), collateral, 10**token.decimals());
positionVal = mulDiv(fairValueOfOption, optionSize, expScale);
liquidationThreshold = mulDiv(positionVal, liquidationRatio, BPS_DIVISOR);
if(liquidationThreshold >= collateralVal) {
return (collateralVal, positionVal, true);
} else {
return (collateralVal, positionVal, false);
}
} else {
collateralVal = mulDiv(getPrice(manager.oracles(token)), optionSize, expScale);
positionVal = mulDiv(fairValueOfOption, optionSize, expScale);
liquidationThreshold = mulDiv(positionVal, liquidationRatio, BPS_DIVISOR);
if(liquidationThreshold >= collateralVal) {
return (collateralVal, positionVal, true);
} else {
return (collateralVal, positionVal, false);
}
}
}
function getInitialMargin(ERC20 token, uint256 fairValueInUSDCScale, uint256 optionSize, bool isCall) public view returns(uint256) {
uint256 positionVal;
if(isCall) {
positionVal = mulDiv(fairValueInUSDCScale, optionSize, expScale);
return mulDiv(positionVal, expScale, getPrice(manager.oracles(token))) + mulDiv(optionSize, initialMarginRatio, BPS_DIVISOR);
} else {
positionVal = fairValueInUSDCScale + mulDiv(getPrice(manager.oracles(token)), initialMarginRatio, BPS_DIVISOR);
return mulDiv(positionVal, optionSize, expScale);
}
}
function updateIRM(ERC20 token, uint256 _baseRate, uint256 _kinkUtil, uint256 _rateBeforeUtil, uint256 _rateAfterUtil) public onlyOwner returns (IRM memory) {
IRM memory irm;
irm.baseRate = _baseRate;
irm.kinkUtil = _kinkUtil;
irm.rateBeforeUtil = _rateBeforeUtil;
irm.rateAfterUtil = _rateAfterUtil;
interestRateModels[token] = irm;
return interestRateModels[token];
}
function getPrice(AggregatorV3Interface oracle) public view returns (uint256) {
(, int256 price, ,uint256 updatedAt, ) = oracle.latestRoundData();
require(price >= 0, "Negative Prices are not allowed");
require(block.timestamp <= updatedAt + tolerance, "Price is too stale to be trustworthy");
if (price == 0) {
return 0;
} else {
return (uint256(price) / (10**2));
}
}
function getPosition(address _account, uint256 _index) public view returns (address, uint256, uint256, address, bool, uint256, uint256) {
bytes32 key = getRequestKey(_account, _index);
Structs.OpenPositionRequest memory positionRequest = openPositionRequests[key];
return (
positionRequest.account,
positionRequest.collateral,
positionRequest.seatId,
positionRequest.orderbook,
positionRequest.isCall,
positionRequest.amountOfUnderlying,
positionRequest.endingTime
);
}
function getRequestKey(address _account, uint256 _index) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_account, _index));
}
function mulDiv(
uint256 x,
uint256 y,
uint256 z
) public pure returns (uint256) {
return (x * y) / z;
}
}
文件 35 的 42:PutFactory.sol
pragma solidity 0.8.19;
import "./OpenZeppelin/Ownable.sol";
import "./AoriSeats.sol";
import "./AoriPut.sol";
import "./OpenZeppelin/IERC20.sol";
import "./Margin/MarginManager.sol";
contract PutFactory is Ownable {
mapping(address => bool) isListed;
AoriPut[] putMarkets;
address public keeper;
uint256 public fee;
AoriSeats public AORISEATSADD;
MarginManager public manager;
constructor(AoriSeats _AORISEATSADD, MarginManager _manager) {
AORISEATSADD = _AORISEATSADD;
manager = _manager;
}
event AoriPutCreated(
IERC20 AoriPutAdd,
uint256 strike,
uint256 duration,
IERC20 USDC,
address oracle,
string name,
string symbol
);
function setKeeper(address newKeeper) public onlyOwner returns(address) {
keeper = newKeeper;
return newKeeper;
}
function setAORISEATSADD(AoriSeats newAORISEATSADD) external onlyOwner returns(AoriSeats) {
AORISEATSADD = newAORISEATSADD;
return AORISEATSADD;
}
function createPutMarket(
uint256 strikeInUSDC,
uint256 duration,
IERC20 USDC,
IERC20 UNDERLYING,
address oracle,
string memory name_,
string memory symbol_
) public returns (AoriPut) {
require(msg.sender == keeper);
AoriPut putMarket = new AoriPut(address(manager), AoriSeats(AORISEATSADD).getFeeMultiplier(), strikeInUSDC, duration, USDC, UNDERLYING, oracle, AoriSeats(AORISEATSADD), name_, symbol_);
isListed[address(putMarket)] = true;
putMarkets.push(putMarket);
emit AoriPutCreated(IERC20(address(putMarket)), strikeInUSDC, duration, USDC, oracle, name_, symbol_);
return (putMarket);
}
function checkIsListed(address market) public view returns(bool) {
return isListed[market];
}
function getAORISEATSADD() external view returns(AoriSeats) {
return AORISEATSADD;
}
function getAllPutMarkets() external view returns(AoriPut[] memory) {
return putMarkets;
}
}
文件 36 的 42:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
}
function _nonReentrantAfter() private {
_status = _NOT_ENTERED;
}
}
文件 37 的 42:ReentrancyGuardUpgradeable.sol
pragma solidity ^0.8.0;
import "./Initializable.sol";
abstract contract ReentrancyGuardUpgradeable is Initializable {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
uint256[49] private __gap;
}
文件 38 的 42:SafeERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./IERC20Permit.sol";
import "./Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 39 的 42:SignedMath.sol
pragma solidity ^0.8.0;
library SignedMath {
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
function average(int256 a, int256 b) internal pure returns (int256) {
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
function abs(int256 n) internal pure returns (uint256) {
unchecked {
return uint256(n >= 0 ? n : -n);
}
}
}
文件 40 的 42:Strings.sol
pragma solidity ^0.8.0;
import "./Math.sol";
import "./SignedMath.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
文件 41 的 42:Structs.sol
pragma solidity ^0.8.0;
import "../OpenZeppelin/ERC20.sol";
library Structs {
struct OpenPositionRequest {
address account;
uint256 collateral;
address orderbook;
bool isCall;
uint256 amountOfUnderlying;
uint256 seatId;
uint256 endingTime;
}
struct Vars {
uint256 optionsMinted;
uint256 collateralVal;
uint256 portfolioVal;
uint256 collateralToLiquidator;
uint256 profit;
uint256 profitInUnderlying;
bool isLiquidatable;
}
struct settleVars {
uint256 tokenBalBefore;
uint256 tokenDiff;
uint256 optionsSold;
}
}
文件 42 的 42:Vault.sol
pragma solidity 0.8.19;
import "../OpenZeppelin/Ownable.sol";
import "../OpenZeppelin/ERC20.sol";
import "../Chainlink/AggregatorV3Interface.sol";
import "./MarginManager.sol";
import "../AoriCall.sol";
import "../AoriPut.sol";
import "../OpenZeppelin/Ownable.sol";
import "../OpenZeppelin/ReentrancyGuard.sol";
import "../OpenZeppelin/ERC4626.sol";
import "./Structs.sol";
contract Vault is Ownable, ReentrancyGuard, ERC4626 {
ERC20 token;
MarginManager manager;
mapping(address => bool) public isSettled;
uint256 USDCScale = 10**6;
constructor(ERC20 asset, string memory name, string memory symbol, MarginManager manager_
) ERC4626(asset, name, symbol) {
manager = manager_;
token = ERC20(asset);
}
function depositAssets(uint256 assets, address receiver) public nonReentrant {
deposit(assets, receiver);
}
function withdrawAssets(uint256 assets, address receiver) public nonReentrant {
withdraw(assets, receiver, receiver);
}
function mintOptions(uint256 amountOfUnderlying, address option, uint256 seatId, address account, bool isCall) public nonReentrant returns (uint256) {
require(msg.sender == address(manager));
totalBorrows += amountOfUnderlying;
uint256 optionsMinted;
if(isCall) {
AoriCall(option).UNDERLYING().approve(option, amountOfUnderlying);
optionsMinted = AoriCall(option).mintCall(amountOfUnderlying, account, seatId);
return optionsMinted;
} else {
AoriPut(option).USDC().approve(option, amountOfUnderlying);
optionsMinted = AoriPut(option).mintPut(amountOfUnderlying, account, seatId);
return optionsMinted;
}
}
function settleITMOption(address option, bool isCall) public nonReentrant returns (uint256) {
Structs.settleVars memory vars;
if(isSettled[option]) {
return 0;
} else {
require(AoriCall(option).endingTime() <= block.timestamp || AoriPut(option).endingTime() <= block.timestamp, "Option has not expired");
vars.tokenBalBefore = token.balanceOf(address(this));
if(isCall) {
vars.optionsSold = AoriCall(option).getOptionsSold(address(this));
AoriCall(option).sellerSettlementITM();
isSettled[option] = true;
} else {
vars.optionsSold = AoriPut(option).getOptionsSold(address(this));
AoriPut(option).sellerSettlementITM();
isSettled[option] = true;
}
vars.tokenDiff = token.balanceOf(address(this)) - vars.tokenBalBefore;
totalBorrows -= vars.tokenDiff;
return vars.tokenDiff;
}
}
function settleOTMOption(address option, bool isCall) public nonReentrant returns (uint256) {
Structs.settleVars memory vars;
if(isSettled[option]) {
return 0;
} else {
if(isCall) {
vars.tokenBalBefore = token.balanceOf(address(this));
AoriCall(option).sellerSettlementOTM();
isSettled[option] = true;
} else {
vars.tokenBalBefore = token.balanceOf(address(this));
AoriPut(option).sellerSettlementOTM();
isSettled[option] = true;
}
vars.tokenDiff = token.balanceOf(address(this)) - vars.tokenBalBefore;
totalBorrows -= vars.tokenDiff;
return vars.tokenDiff;
}
}
function closeHedgedPosition(address option, bool isCall, uint256 optionsToSettle) public {
require(msg.sender == address(manager));
if(isCall) {
AoriCall(option).liquidationSettlement(optionsToSettle);
} else {
AoriPut(option).liquidationSettlement(optionsToSettle);
}
}
function repaid(uint256 assets) public returns (uint256) {
require(msg.sender == address(manager));
totalBorrows -= assets;
return assets;
}
}
{
"compilationTarget": {
"src/AoriSeats.sol": "AoriSeats"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":ds-test/=lib/forge-std/lib/ds-test/src/",
":forge-std/=lib/forge-std/src/"
]
}
[{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"uint256","name":"maxSeats_","type":"uint256"},{"internalType":"uint256","name":"mintFee_","type":"uint256"},{"internalType":"uint256","name":"tradingFee_","type":"uint256"},{"internalType":"uint256","name":"maxSeatScore_","type":"uint256"},{"internalType":"uint256","name":"feeMultiplier_","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"seatId","type":"uint256"},{"indexed":false,"internalType":"address","name":"SeatOwner","type":"address"}],"name":"FeeSetForSeat","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"NewMaxSeats","type":"uint256"}],"name":"MaxSeatChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"NewMintFee","type":"uint256"}],"name":"MintFeeChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"NewTradingFee","type":"uint256"}],"name":"TradingFeeChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"CALLFACTORY","outputs":[{"internalType":"contract CallFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ORDERBOOKFACTORY","outputs":[{"internalType":"contract OrderbookFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PUTFACTORY","outputs":[{"internalType":"contract PutFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"volumeToAdd","type":"uint256"},{"internalType":"uint256","name":"seatId","type":"uint256"},{"internalType":"address","name":"Orderbook_","type":"address"}],"name":"addTakerVolume","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"seatIdOne","type":"uint256"},{"internalType":"uint256","name":"seatIdTwo","type":"uint256"}],"name":"combineSeats","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"seatId","type":"uint256"}],"name":"confirmExists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentSeatId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultSeatScore","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFeeMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getOptionMintingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getPoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"seatId","type":"uint256"}],"name":"getSeatScore","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"seatId","type":"uint256"}],"name":"getSeatVolume","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTradingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSeatScore","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintSeat","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"seatRoyaltyReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"seatId","type":"uint256"}],"name":"separateSeats","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"baseURI","type":"string"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract CallFactory","name":"newCALLFACTORY","type":"address"}],"name":"setCallFactory","outputs":[{"internalType":"contract CallFactory","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"score","type":"uint256"}],"name":"setDefaultSeatScore","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newFeeMultiplier","type":"uint256"}],"name":"setFeeMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMaxScore","type":"uint256"}],"name":"setMaxSeatScore","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMaxSeats","type":"uint256"}],"name":"setMaxSeats","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMintFee","type":"uint256"}],"name":"setMintFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"setMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract OrderbookFactory","name":"newORDERBOOKFACTORY","type":"address"}],"name":"setOrderbookFactory","outputs":[{"internalType":"contract OrderbookFactory","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract PutFactory","name":"newPUTFACTORY","type":"address"}],"name":"setPutFactory","outputs":[{"internalType":"contract PutFactory","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"seatId","type":"uint256"},{"internalType":"string","name":"_seatURI","type":"string"}],"name":"setSeatIdURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSeatRoyaltyReceiver","type":"address"}],"name":"setSeatRoyaltyReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newTradingFee","type":"uint256"}],"name":"setTradingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]