编译器
0.8.17+commit.8df45f5f
文件 1 的 4:IAggregatorV3.sol
pragma solidity ^0.8.17;
interface IAggregatorV3 {
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);
}
文件 2 的 4:ICegaState.sol
pragma solidity ^0.8.17;
interface ICegaState {
function marketMakerAllowList(address marketMaker) external view returns (bool);
function products(string memory productName) external view returns (address);
function oracleAddresses(string memory oracleName) external view returns (address);
function oracleNames() external view returns (string[] memory);
function productNames() external view returns (string[] memory);
function feeRecipient() external view returns (address);
function isDefaultAdmin(address sender) external view returns (bool);
function isTraderAdmin(address sender) external view returns (bool);
function isOperatorAdmin(address sender) external view returns (bool);
function isServiceAdmin(address sender) external view returns (bool);
function getOracleNames() external view returns (string[] memory);
function addOracle(string memory oracleName, address oracleAddress) external;
function removeOracle(string memory oracleName) external;
function getProductNames() external view returns (string[] memory);
function addProduct(string memory productName, address product) external;
function removeProduct(string memory productName) external;
function updateMarketMakerPermission(address marketMaker, bool allow) external;
function setFeeRecipient(address _feeRecipient) external;
function moveAssetsToProduct(string memory productName, address vaultAddress, uint256 amount) external;
}
文件 3 的 4:Oracle.sol
pragma solidity ^0.8.17;
import { IAggregatorV3 } from "./interfaces/IAggregatorV3.sol";
import { ICegaState } from "./interfaces/ICegaState.sol";
import { RoundData } from "./Structs.sol";
contract Oracle is IAggregatorV3 {
event OracleCreated(address indexed cegaState, uint8 decimals, string description);
event RoundDataAdded(int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
event RoundDataUpdated(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
uint8 public decimals;
string public description;
uint256 public version = 1;
ICegaState public cegaState;
RoundData[] public oracleData;
uint80 public nextRoundId;
constructor(address _cegaState, uint8 _decimals, string memory _description) {
cegaState = ICegaState(_cegaState);
decimals = _decimals;
description = _description;
emit OracleCreated(_cegaState, _decimals, _description);
}
modifier onlyServiceAdmin() {
require(cegaState.isServiceAdmin(msg.sender), "403:SA");
_;
}
modifier onlyDefaultAdmin() {
require(cegaState.isDefaultAdmin(msg.sender), "403:DA");
_;
}
function addNextRoundData(RoundData calldata _roundData) public onlyServiceAdmin {
if (nextRoundId != 0) {
(, , , uint256 updatedAt, ) = latestRoundData();
require(updatedAt <= _roundData.startedAt, "400:P");
}
require(block.timestamp - 1 days <= _roundData.startedAt, "400:T");
oracleData.push(_roundData);
nextRoundId++;
emit RoundDataAdded(_roundData.answer, _roundData.startedAt, _roundData.updatedAt, _roundData.answeredInRound);
}
function updateRoundData(uint80 roundId, RoundData calldata _roundData) public onlyDefaultAdmin {
oracleData[roundId] = _roundData;
emit RoundDataUpdated(
roundId,
_roundData.answer,
_roundData.startedAt,
_roundData.updatedAt,
_roundData.answeredInRound
);
}
function getRoundData(
uint80 _roundId
)
public
view
override
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
{
return (
_roundId,
oracleData[_roundId].answer,
oracleData[_roundId].startedAt,
oracleData[_roundId].updatedAt,
oracleData[_roundId].answeredInRound
);
}
function latestRoundData()
public
view
override
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
{
uint80 _roundId = nextRoundId - 1;
return (
_roundId,
oracleData[_roundId].answer,
oracleData[_roundId].startedAt,
oracleData[_roundId].updatedAt,
oracleData[_roundId].answeredInRound
);
}
}
文件 4 的 4:Structs.sol
pragma solidity ^0.8.17;
enum OptionBarrierType {
None,
KnockIn
}
struct Deposit {
uint256 amount;
address receiver;
}
struct Withdrawal {
uint256 amountShares;
address receiver;
}
enum VaultStatus {
DepositsClosed,
DepositsOpen,
NotTraded,
Traded,
TradeExpired,
PayoffCalculated,
FeesCollected,
WithdrawalQueueProcessed,
Zombie
}
struct OptionBarrier {
uint256 barrierBps;
uint256 barrierAbsoluteValue;
uint256 strikeBps;
uint256 strikeAbsoluteValue;
string asset;
string oracleName;
OptionBarrierType barrierType;
}
struct FCNVaultMetadata {
uint256 vaultStart;
uint256 tradeDate;
uint256 tradeExpiry;
uint256 aprBps;
uint256 tenorInDays;
uint256 underlyingAmount;
uint256 currentAssetAmount;
uint256 totalCouponPayoff;
uint256 vaultFinalPayoff;
uint256 queuedWithdrawalsSharesAmount;
uint256 queuedWithdrawalsCount;
uint256 optionBarriersCount;
uint256 leverage;
address vaultAddress;
VaultStatus vaultStatus;
bool isKnockedIn;
OptionBarrier[] optionBarriers;
}
struct RoundData {
int256 answer;
uint256 startedAt;
uint256 updatedAt;
uint80 answeredInRound;
}
{
"compilationTarget": {
"contracts/Oracle.sol": "Oracle"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "none"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [],
"viaIR": true
}
[{"inputs":[{"internalType":"address","name":"_cegaState","type":"address"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"string","name":"_description","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"cegaState","type":"address"},{"indexed":false,"internalType":"uint8","name":"decimals","type":"uint8"},{"indexed":false,"internalType":"string","name":"description","type":"string"}],"name":"OracleCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int256","name":"answer","type":"int256"},{"indexed":false,"internalType":"uint256","name":"startedAt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"updatedAt","type":"uint256"},{"indexed":false,"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"name":"RoundDataAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint80","name":"roundId","type":"uint80"},{"indexed":false,"internalType":"int256","name":"answer","type":"int256"},{"indexed":false,"internalType":"uint256","name":"startedAt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"updatedAt","type":"uint256"},{"indexed":false,"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"name":"RoundDataUpdated","type":"event"},{"inputs":[{"components":[{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"internalType":"struct RoundData","name":"_roundData","type":"tuple"}],"name":"addNextRoundData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cegaState","outputs":[{"internalType":"contract ICegaState","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"_roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextRoundId","outputs":[{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"oracleData","outputs":[{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"components":[{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"internalType":"struct RoundData","name":"_roundData","type":"tuple"}],"name":"updateRoundData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]