zellic-audit
Initial commit
f998fcd
raw
history blame
14.2 kB
{
"language": "Solidity",
"sources": {
"contracts/peripheral/OhmBondManager.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later\npragma solidity 0.8.15;\n\nimport {IBondSDA} from \"../interfaces/IBondSDA.sol\";\nimport {IBondTeller} from \"../interfaces/IBondTeller.sol\";\nimport {IEasyAuction} from \"../interfaces/IEasyAuction.sol\";\nimport {IERC20} from \"../interfaces/IERC20.sol\";\nimport {ITreasury} from \"../interfaces/ITreasury.sol\";\nimport {IOlympusAuthority} from \"../interfaces/IOlympusAuthority.sol\";\nimport {OlympusAccessControlled} from \"../types/OlympusAccessControlled.sol\";\n\ncontract OhmBondManager is OlympusAccessControlled {\n // ========= DATA STRUCTURES ========= //\n struct BondProtocolParameters {\n uint256 initialPrice;\n uint256 minPrice;\n uint32 debtBuffer;\n uint256 auctionTime;\n uint32 depositInterval;\n }\n\n struct GnosisAuctionParameters {\n uint256 auctionCancelTime;\n uint256 auctionTime;\n uint96 minRatioSold;\n uint256 minBuyAmount;\n uint256 minFundingThreshold;\n }\n\n // ========= STATE VARIABLES ========= //\n\n /// Tokens\n IERC20 public ohm;\n\n /// Contract Dependencies\n ITreasury public treasury;\n\n /// Market Creation Systems\n IBondSDA public fixedExpiryAuctioneer;\n IBondTeller public fixedExpiryTeller;\n IEasyAuction public gnosisEasyAuction;\n\n /// Market parameters\n BondProtocolParameters public bondProtocolParameters;\n GnosisAuctionParameters public gnosisAuctionParameters;\n\n constructor(\n address ohm_,\n address treasury_,\n address feAuctioneer_,\n address feTeller_,\n address gnosisAuction_,\n address authority_\n ) OlympusAccessControlled(IOlympusAuthority(authority_)) {\n ohm = IERC20(ohm_);\n treasury = ITreasury(treasury_);\n fixedExpiryAuctioneer = IBondSDA(feAuctioneer_);\n fixedExpiryTeller = IBondTeller(feTeller_);\n gnosisEasyAuction = IEasyAuction(gnosisAuction_);\n }\n\n // ========= MARKET CREATION ========= //\n function createBondProtocolMarket(uint256 capacity_, uint256 bondTerm_) external onlyPolicy returns (uint256) {\n _topUpOhm(capacity_);\n\n /// Encodes the information needed for creating a bond market on Bond Protocol\n bytes memory createMarketParams = abi.encode(\n ohm, // payoutToken\n ohm, // quoteToken\n address(0), // callbackAddress\n false, // capacityInQuote\n capacity_, // capacity\n bondProtocolParameters.initialPrice, // formattedInitialPrice\n bondProtocolParameters.minPrice, // formattedMinimumPrice\n bondProtocolParameters.debtBuffer, // debtBuffer\n uint48(block.timestamp + bondTerm_), // vesting\n uint48(block.timestamp + bondProtocolParameters.auctionTime), // conclusion\n bondProtocolParameters.depositInterval, // depositInterval\n int8(0) // scaleAdjustment\n );\n\n ohm.approve(address(fixedExpiryTeller), capacity_);\n uint256 marketId = fixedExpiryAuctioneer.createMarket(createMarketParams);\n\n return marketId;\n }\n\n function createGnosisAuction(uint96 capacity_, uint256 bondTerm_) external onlyPolicy returns (uint256) {\n _topUpOhm(capacity_);\n\n uint48 expiry = uint48(block.timestamp + bondTerm_);\n\n /// Create bond token\n ohm.approve(address(fixedExpiryTeller), capacity_);\n fixedExpiryTeller.deploy(ohm, expiry);\n (IERC20 bondToken, ) = fixedExpiryTeller.create(ohm, expiry, capacity_);\n\n /// Launch Gnosis Auction\n bondToken.approve(address(gnosisEasyAuction), capacity_);\n uint256 auctionId = gnosisEasyAuction.initiateAuction(\n bondToken, // auctioningToken\n ohm, // biddingToken\n block.timestamp + gnosisAuctionParameters.auctionCancelTime, // last order cancellation time\n block.timestamp + gnosisAuctionParameters.auctionTime, // auction end time\n capacity_, // auctioned amount\n capacity_ / gnosisAuctionParameters.minRatioSold, // minimum tokens bought for auction to be valid\n gnosisAuctionParameters.minBuyAmount, // minimum purchase size of auctioning token\n gnosisAuctionParameters.minFundingThreshold, // minimum funding threshold\n false, // is atomic closure allowed\n address(0), // access manager contract\n new bytes(0) // access manager contract data\n );\n\n return auctionId;\n }\n\n // ========= PARAMETER ADJUSTMENT ========= //\n function setBondProtocolParameters(\n uint256 initialPrice_,\n uint256 minPrice_,\n uint32 debtBuffer_,\n uint256 auctionTime_,\n uint32 depositInterval_\n ) external onlyPolicy {\n bondProtocolParameters = BondProtocolParameters({\n initialPrice: initialPrice_,\n minPrice: minPrice_,\n debtBuffer: debtBuffer_,\n auctionTime: auctionTime_,\n depositInterval: depositInterval_\n });\n }\n\n function setGnosisAuctionParameters(\n uint256 auctionCancelTime_,\n uint256 auctionTime_,\n uint96 minRatioSold_,\n uint256 minBuyAmount_,\n uint256 minFundingThreshold_\n ) external onlyPolicy {\n gnosisAuctionParameters = GnosisAuctionParameters({\n auctionCancelTime: auctionCancelTime_,\n auctionTime: auctionTime_,\n minRatioSold: minRatioSold_,\n minBuyAmount: minBuyAmount_,\n minFundingThreshold: minFundingThreshold_\n });\n }\n\n // ========= INTERNAL FUNCTIONS ========= //\n function _topUpOhm(uint256 amountToDeploy_) internal {\n uint256 ohmBalance = ohm.balanceOf(address(this));\n\n if (amountToDeploy_ > ohmBalance) {\n uint256 amountToMint = amountToDeploy_ - ohmBalance;\n treasury.mint(address(this), amountToMint);\n }\n }\n\n // ========= EMERGENCY FUNCTIONS ========= //\n function emergencyWithdraw(uint256 amount) external onlyPolicy {\n ohm.transfer(address(treasury), amount);\n }\n}\n"
},
"contracts/interfaces/IBondSDA.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity 0.8.15;\n\nimport {IERC20} from \"./IERC20.sol\";\n\ninterface IBondSDA {\n /// @notice Creates a new bond market\n /// @param params_ Configuration data needed for market creation\n /// @return id ID of new bond market\n function createMarket(bytes calldata params_) external returns (uint256);\n}\n"
},
"contracts/interfaces/IBondTeller.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity 0.8.15;\n\nimport {IERC20} from \"./IERC20.sol\";\n\ninterface IBondTeller {\n /// @notice Instantiates a new fixed expiry bond token\n /// @param payoutToken Token received upon bonding\n /// @param expiration Expiry timestamp for the bond\n function deploy(IERC20 payoutToken, uint48 expiration) external;\n\n /// @notice Mint bond tokens for a specific expiry\n /// @param expiration Expiry timestamp for the bond\n /// @param capacity Amount of bond tokens to mint\n function create(\n IERC20 payoutToken,\n uint48 expiration,\n uint256 capacity\n ) external returns (IERC20, uint256);\n}\n"
},
"contracts/interfaces/IEasyAuction.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity 0.8.15;\n\nimport {IERC20} from \"./IERC20.sol\";\n\ninterface IEasyAuction {\n /// @notice Initiates an auction through Gnosis Auctions\n /// @param tokenToSell The token being sold\n /// @param biddingToken The token used to bid on the sale token and set its price\n /// @param lastCancellation The last timestamp a user can cancel their bid at\n /// @param auctionEnd The timestamp the auction ends at\n /// @param auctionAmount The number of sale tokens to sell\n /// @param minimumTotalPurchased The minimum number of sale tokens that need to be sold for the auction to finalize\n /// @param minimumPurchaseAmount The minimum purchase size in bidding tokens\n /// @param minFundingThreshold The minimal funding thresholding for finalizing settlement\n /// @param isAtomicClosureAllowed Can users call settleAuctionAtomically when end date has been reached\n /// @param accessManager The contract to manage an allowlist\n /// @param accessManagerData The data for managing an allowlist\n function initiateAuction(\n IERC20 tokenToSell,\n IERC20 biddingToken,\n uint256 lastCancellation,\n uint256 auctionEnd,\n uint96 auctionAmount,\n uint96 minimumTotalPurchased,\n uint256 minimumPurchaseAmount,\n uint256 minFundingThreshold,\n bool isAtomicClosureAllowed,\n address accessManager,\n bytes calldata accessManagerData\n ) external returns (uint256);\n}\n"
},
"contracts/interfaces/IERC20.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity >=0.7.5;\n\ninterface IERC20 {\n function totalSupply() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n function allowance(address owner, address spender) external view returns (uint256);\n\n function approve(address spender, uint256 amount) external returns (bool);\n\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
},
"contracts/interfaces/ITreasury.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity >=0.7.5;\n\ninterface ITreasury {\n function deposit(\n uint256 _amount,\n address _token,\n uint256 _profit\n ) external returns (uint256);\n\n function withdraw(uint256 _amount, address _token) external;\n\n function tokenValue(address _token, uint256 _amount) external view returns (uint256 value_);\n\n function mint(address _recipient, uint256 _amount) external;\n\n function manage(address _token, uint256 _amount) external;\n\n function incurDebt(uint256 amount_, address token_) external;\n\n function repayDebtWithReserve(uint256 amount_, address token_) external;\n\n function excessReserves() external view returns (uint256);\n\n function baseSupply() external view returns (uint256);\n}\n"
},
"contracts/interfaces/IOlympusAuthority.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0\npragma solidity >=0.7.5;\n\ninterface IOlympusAuthority {\n /* ========== EVENTS ========== */\n\n event GovernorPushed(address indexed from, address indexed to, bool _effectiveImmediately);\n event GuardianPushed(address indexed from, address indexed to, bool _effectiveImmediately);\n event PolicyPushed(address indexed from, address indexed to, bool _effectiveImmediately);\n event VaultPushed(address indexed from, address indexed to, bool _effectiveImmediately);\n\n event GovernorPulled(address indexed from, address indexed to);\n event GuardianPulled(address indexed from, address indexed to);\n event PolicyPulled(address indexed from, address indexed to);\n event VaultPulled(address indexed from, address indexed to);\n\n /* ========== VIEW ========== */\n\n function governor() external view returns (address);\n\n function guardian() external view returns (address);\n\n function policy() external view returns (address);\n\n function vault() external view returns (address);\n}\n"
},
"contracts/types/OlympusAccessControlled.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-only\npragma solidity >=0.7.5;\n\nimport \"../interfaces/IOlympusAuthority.sol\";\n\nabstract contract OlympusAccessControlled {\n /* ========== EVENTS ========== */\n\n event AuthorityUpdated(IOlympusAuthority indexed authority);\n\n string UNAUTHORIZED = \"UNAUTHORIZED\"; // save gas\n\n /* ========== STATE VARIABLES ========== */\n\n IOlympusAuthority public authority;\n\n /* ========== Constructor ========== */\n\n constructor(IOlympusAuthority _authority) {\n authority = _authority;\n emit AuthorityUpdated(_authority);\n }\n\n /* ========== MODIFIERS ========== */\n\n modifier onlyGovernor() {\n require(msg.sender == authority.governor(), UNAUTHORIZED);\n _;\n }\n\n modifier onlyGuardian() {\n require(msg.sender == authority.guardian(), UNAUTHORIZED);\n _;\n }\n\n modifier onlyPolicy() {\n require(msg.sender == authority.policy(), UNAUTHORIZED);\n _;\n }\n\n modifier onlyVault() {\n require(msg.sender == authority.vault(), UNAUTHORIZED);\n _;\n }\n\n /* ========== GOV ONLY ========== */\n\n function setAuthority(IOlympusAuthority _newAuthority) external onlyGovernor {\n authority = _newAuthority;\n emit AuthorityUpdated(_newAuthority);\n }\n}\n"
}
},
"settings": {
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 800
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}