├── .circleci └── config.yml ├── .eslintrc.json ├── .gitattributes ├── .gitbook.yaml ├── .github └── pull_request_template.md ├── .gitignore ├── .prettierrc.json ├── .solcover.js ├── .solhint.json ├── .solhintignore ├── LICENSE ├── README.md ├── SUMMARY.md ├── autotask ├── README.md └── pricers-bot │ ├── build-script.js │ ├── codebuild │ ├── base-asset │ │ └── index.js │ ├── chains │ │ └── mainnet │ │ │ ├── AddressBookAbi.json │ │ │ ├── AggregatorInterfaceAbi.json │ │ │ ├── Assets.json │ │ │ ├── ChainlinkPricerAbi.json │ │ │ ├── OracleAbi.json │ │ │ └── WhitelistAbi.json │ └── derived-asset │ │ └── index.js │ ├── defender-config.js │ └── enums.js ├── ci └── e2e.sh ├── codechecks.yml ├── contracts ├── Migrations.sol ├── core │ ├── AddressBook.sol │ ├── BorrowableMarginPool.sol │ ├── Controller.sol │ ├── MarginCalculator.sol │ ├── MarginPool.sol │ ├── Oracle.sol │ ├── Otoken.sol │ ├── OtokenFactory.sol │ ├── OtokenSpawner.sol │ └── Whitelist.sol ├── external │ ├── callees │ │ └── PermitCallee.sol │ ├── canonical-weth │ │ └── WETH9.sol │ └── proxies │ │ └── PayableProxyController.sol ├── interfaces │ ├── AddressBookInterface.sol │ ├── AggregatorInterface.sol │ ├── CTokenInterface.sol │ ├── CalleeInterface.sol │ ├── ERC20Interface.sol │ ├── MarginCalculatorInterface.sol │ ├── MarginPoolInterface.sol │ ├── OpynPricerInterface.sol │ ├── OracleInterface.sol │ ├── OtokenInterface.sol │ ├── WETH9Interface.sol │ ├── WSTETHInterface.sol │ ├── WhitelistInterface.sol │ ├── YearnVaultInterface.sol │ └── ZeroXExchangeInterface.sol ├── libs │ ├── .gitkeep │ ├── Actions.sol │ ├── FixedPointInt256.sol │ ├── MarginVault.sol │ └── SignedConverter.sol ├── mocks │ ├── Mock0xERC20Proxy.sol │ ├── Mock0xExchange.sol │ ├── MockAddressBook.sol │ ├── MockCToken.sol │ ├── MockCUSDC.sol │ ├── MockChainlinkAggregator.sol │ ├── MockController.sol │ ├── MockDumbERC20.sol │ ├── MockERC20.sol │ ├── MockOracle.sol │ ├── MockOtoken.sol │ ├── MockPermitERC20.sol │ ├── MockPricer.sol │ ├── MockWSTETHToken.sol │ ├── MockWhitelistModule.sol │ └── MockYToken.sol ├── packages │ ├── BokkyPooBahsDateTimeLibrary.sol │ ├── Spawn.sol │ └── oz │ │ ├── Address.sol │ │ ├── Context.sol │ │ ├── Create2.sol │ │ ├── IERC20.sol │ │ ├── Ownable.sol │ │ ├── ReentrancyGuard.sol │ │ ├── SafeERC20.sol │ │ ├── SafeMath.sol │ │ ├── SignedSafeMath.sol │ │ ├── Strings.sol │ │ └── upgradeability │ │ ├── ERC20Upgradeable.sol │ │ ├── GSN │ │ └── ContextUpgradeable.sol │ │ ├── IERC20Upgradeable.sol │ │ ├── Initializable.sol │ │ ├── OwnableUpgradeSafe.sol │ │ ├── OwnedUpgradeabilityProxy.sol │ │ ├── Proxy.sol │ │ ├── ReentrancyGuardUpgradeSafe.sol │ │ ├── UpgradeabilityProxy.sol │ │ ├── cryptography │ │ └── ECDSAUpgradeable.sol │ │ ├── erc20-permit │ │ ├── EIP712Upgradeable.sol │ │ ├── ERC20PermitUpgradeable.sol │ │ └── IERC20PermitUpgradeable.sol │ │ ├── math │ │ └── SafeMathUpgradeable.sol │ │ └── utils │ │ └── CountersUpgradeable.sol ├── pricers │ ├── ChainlinkPricer.sol │ ├── CompoundPricer.sol │ ├── WstethPricer.sol │ └── YearnPricer.sol └── tests │ ├── ActionTester.sol │ ├── CalculatorTester.sol │ ├── CallTester.sol │ ├── CalleeAllowanceTester.sol │ ├── FixedPointInt256Tester.sol │ ├── FlashUnwrap.sol │ ├── MarginVaultTester.sol │ ├── OtokenImplV1.sol │ ├── SignedConverterTester.sol │ ├── UpgradeableContractV1.sol │ └── UpgradeableContractV2.sol ├── docs ├── contract.hbs ├── contracts-documentation │ ├── Migrations.md │ ├── core │ │ ├── AddressBook.md │ │ ├── Controller.md │ │ ├── MarginCalculator.md │ │ ├── MarginPool.md │ │ ├── Oracle.md │ │ ├── Otoken.md │ │ ├── OtokenFactory.md │ │ ├── OtokenSpawner.md │ │ └── Whitelist.md │ ├── external │ │ ├── callees │ │ │ ├── PermitCallee.md │ │ │ └── TradeCallee.md │ │ ├── canonical-weth │ │ │ └── WETH9.md │ │ └── proxies │ │ │ └── PayableProxyController.md │ ├── interfaces │ │ ├── AddressBookInterface.md │ │ ├── AggregatorInterface.md │ │ ├── CTokenInterface.md │ │ ├── CalleeInterface.md │ │ ├── ERC20Interface.md │ │ ├── MarginCalculatorInterface.md │ │ ├── MarginPoolInterface.md │ │ ├── OpynPricerInterface.md │ │ ├── OracleInterface.md │ │ ├── OtokenInterface.md │ │ ├── WETH9Interface.md │ │ ├── WSTETHInterface.md │ │ ├── WhitelistInterface.md │ │ ├── YearnVaultInterface.md │ │ └── ZeroXExchangeInterface.md │ ├── libs │ │ ├── Actions.md │ │ ├── FixedPointInt256.md │ │ ├── MarginVault.md │ │ └── SignedConverter.md │ ├── mocks │ │ ├── Mock0xERC20Proxy.md │ │ ├── Mock0xExchange.md │ │ ├── MockAddressBook.md │ │ ├── MockCToken.md │ │ ├── MockCUSDC.md │ │ ├── MockChainlinkAggregator.md │ │ ├── MockController.md │ │ ├── MockDumbERC20.md │ │ ├── MockERC20.md │ │ ├── MockOracle.md │ │ ├── MockOtoken.md │ │ ├── MockPermitERC20.md │ │ ├── MockPricer.md │ │ ├── MockWSTETHToken.md │ │ ├── MockWhitelistModule.md │ │ └── MockYToken.md │ ├── packages │ │ ├── BokkyPooBahsDateTimeLibrary.md │ │ ├── Spawn.md │ │ └── oz │ │ │ ├── Address.md │ │ │ ├── Context.md │ │ │ ├── Create2.md │ │ │ ├── IERC20.md │ │ │ ├── Ownable.md │ │ │ ├── ReentrancyGuard.md │ │ │ ├── SafeERC20.md │ │ │ ├── SafeMath.md │ │ │ ├── SignedSafeMath.md │ │ │ ├── Strings.md │ │ │ └── upgradeability │ │ │ ├── ERC20Upgradeable.md │ │ │ ├── GSN │ │ │ └── ContextUpgradeable.md │ │ │ ├── IERC20Upgradeable.md │ │ │ ├── Initializable.md │ │ │ ├── OwnableUpgradeSafe.md │ │ │ ├── OwnedUpgradeabilityProxy.md │ │ │ ├── Proxy.md │ │ │ ├── ReentrancyGuardUpgradeSafe.md │ │ │ ├── UpgradeabilityProxy.md │ │ │ ├── cryptography │ │ │ └── ECDSAUpgradeable.md │ │ │ ├── erc20-permit │ │ │ ├── EIP712Upgradeable.md │ │ │ ├── ERC20PermitUpgradeable.md │ │ │ └── IERC20PermitUpgradeable.md │ │ │ ├── math │ │ │ └── SafeMathUpgradeable.md │ │ │ └── utils │ │ │ └── CountersUpgradeable.md │ ├── pricers │ │ ├── ChainLinkPricer.md │ │ ├── CompoundPricer.md │ │ ├── WstethPricer.md │ │ └── YearnPricer.md │ └── tests │ │ ├── ActionTester.md │ │ ├── CalculatorTester.md │ │ ├── CallTester.md │ │ ├── CalleeAllowanceTester.md │ │ ├── FixedPointInt256Tester.md │ │ ├── FlashUnwrap.md │ │ ├── MarginVaultTester.md │ │ ├── OtokenImplV1.md │ │ ├── SignedConverterTester.md │ │ ├── UpgradeableContractV1.md │ │ └── UpgradeableContractV2.md ├── control-flow │ ├── Gamma.png │ ├── GammaAddressbook.png │ ├── GammaController.png │ ├── GammaFactory.png │ ├── GammaHighLevel.png │ ├── GammaOracle.png │ ├── GammaOtoken.png │ ├── GammaPool.png │ ├── GammaPricer.png │ └── GammaWhitelist.png └── uml │ ├── GammaAddressbook.png │ ├── GammaAddressbook.svg │ ├── GammaCalculator.png │ ├── GammaCalculator.svg │ ├── GammaController.png │ ├── GammaController.svg │ ├── GammaFactory.png │ ├── GammaFactory.svg │ ├── GammaOracle.png │ ├── GammaOracle.svg │ ├── GammaOtoken.png │ ├── GammaOtoken.svg │ ├── GammaPool.png │ ├── GammaPool.svg │ ├── GammaPricer.png │ ├── GammaPricer.svg │ ├── GammaUML.png │ ├── GammaUML.svg │ ├── GammaWhitelist.png │ └── GammaWhitelist.svg ├── migrations ├── 1_initial_migration.js ├── 2_deploy_contracts.js ├── 3_setup_ownership.js └── deployment-config.json ├── package-lock.json ├── package.json ├── scripts ├── README.md ├── calculateContractBytecode.js ├── controllerSetCallRestriction.js ├── dataUtils.js ├── deployCalculator.js ├── deployChainlinkPricer.js ├── deployController.js ├── deployMockERC20.js ├── deployMockPricer.js ├── deployOtokenImpl.js ├── deployPayableProxyController.js ├── deployPermitCallee.js ├── deployWstethPricer.js ├── deployYearnPricer.js ├── docs │ └── docify.js ├── local-e2e.sh ├── migrateOracle.js └── whitelistSetCallee.js ├── slither.config.json ├── specs ├── ControllerOrderOfOperations.spec ├── MarginVault.spec ├── MarginVaultHarness.sol ├── NoBankruptcy.spec ├── Privileged.spec ├── ValidBalances.spec ├── controller.spec ├── harness │ ├── ControllerHarness.sol │ ├── ControllerHarnessExtra.sol │ ├── DummyERC20A.sol │ ├── DummyERC20B.sol │ ├── DummyERC20C.sol │ ├── MarginCalculatorHarness.sol │ ├── MarginPoolHarness.sol │ ├── MarginVaultHarness.sol │ ├── OtokenHarnessA.sol │ └── OtokenHarnessB.sol ├── runMarginVault.sh └── scripts │ ├── Controller │ ├── collateralWithdrawal.sh │ ├── onlyOneVaultModified.sh │ ├── optionsWithdrawsRestricted.sh │ ├── redeem.sh │ ├── runOrderOfOperations.sh │ └── runSettleVault.sh │ ├── applyHarnesses.sh │ ├── assetIsNotOtoken.sh │ ├── callOptionsPreExpiry.sh │ ├── cantSettleUnexpiredVault.sh │ ├── onlyValidOtoken.sh │ ├── putOptionsPreExpiryCase1.sh │ ├── putOptionsPreExpiryCase2.sh │ ├── runController.sh │ ├── runMarginVault.sh │ ├── runNoBankruptcy.sh │ ├── runOrderOfOperations.sh │ ├── runPrivilegedWhitelist.sh │ ├── runValidBalances.sh │ ├── runValidCollateral.sh │ ├── validBalanceTotalCollateral.sh │ ├── validBalanceTotalLong.sh │ └── validBalanceTotalShort.sh ├── test ├── eip712.js ├── integration-tests │ ├── longCallSpreadExpireItm.test.ts │ ├── longCallSpreadExpireOtm.test.ts │ ├── longCallSpreadPreExpiry.test.ts │ ├── longPutExpireItm.test.ts │ ├── longPutExpireOtm.test.ts │ ├── longPutPreExpiry.test.ts │ ├── nakedCallExpireItm-borrowableMarginPool.test.ts │ ├── nakedCallExpireItm.test.ts │ ├── nakedCallExpireOtm-borrowableMarginPool.test.ts │ ├── nakedCallExpireOtm.test.ts │ ├── nakedCallPreExpiry-borrowableMarginPool.test.ts │ ├── nakedCallPreExpiry.test.ts │ ├── nakedMarginCallPreExpiry.test.ts │ ├── nakedMarginPutPreExpiry.test.ts │ ├── nakedPutExpireITM.test.ts │ ├── nakedPutExpireOTM.test.ts │ ├── nakedPutPreExpiry.test.ts │ ├── open-markets-borrowableMarginPool.test.ts │ ├── open-markets.test.ts │ ├── pricer-oracle.test.ts │ ├── rollover.test.ts │ ├── shortCallSpreadExpireItm.test.ts │ ├── shortCallSpreadExpireOtm.test.ts │ ├── shortCallSpreadPreExpiry.test.ts │ ├── shortPutSpreadExpireItm.test.ts │ ├── shortPutSpreadExpireOtm.test.ts │ ├── shortPutSpreadPreExpiry.test.ts │ └── yieldFarming.test.ts ├── test-engine │ ├── marginCalculatorTestEngine.test.ts │ └── testCaseGenerator.ts ├── unit-tests │ ├── Actions.test.ts │ ├── Otoken.test.ts │ ├── OtokenFactory.test.ts │ ├── PermitCallee.test.ts │ ├── Whitelist.test.ts │ ├── addressBook.test.ts │ ├── borrowableMarginPool.test.ts │ ├── chainlinkPricer.test.ts │ ├── compoundPricer.test.ts │ ├── controller.test.ts │ ├── controllerBorrowableMarginPool.test.ts │ ├── controllerNakedMargin.test.ts │ ├── fixedPointInt256.test.ts │ ├── flashUnwrap.test.ts │ ├── liquidations.test.ts │ ├── marginCalculator.test.ts │ ├── marginCalculatorNakedMargin.test.ts │ ├── marginPool.test.ts │ ├── marginVault.test.ts │ ├── oracle.test.ts │ ├── payableProxyController.test.ts │ ├── signedConverter.test.ts │ ├── weth9.test.ts │ ├── wstEthPricer.test.ts │ └── yearnPricer.test.ts └── utils.ts ├── truffle-config.js └── tsconfig.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "@typescript-eslint/parser", 3 | "parserOptions": { 4 | "ecmaVersion": 2018, 5 | "sourceType": "module" 6 | }, 7 | "extends": [ 8 | "plugin:@typescript-eslint/recommended", 9 | "plugin:prettier/recommended" 10 | ], 11 | "ignorePatterns": ["build", "**/vendor/*.js"], 12 | "plugins": ["@typescript-eslint", "import"], 13 | "env": { 14 | "es6": true 15 | }, 16 | "rules": { 17 | "prettier/prettier": "error", 18 | "@typescript-eslint/explicit-function-return-type": "off", 19 | "@typescript-eslint/no-explicit-any": "off", 20 | "@typescript-eslint/camelcase": "off", 21 | "@typescript-eslint/no-var-requires": "off", 22 | "@typescript-eslint/member-delimiter-style": ["error", { 23 | "multiline": { 24 | "delimiter": "none", 25 | "requireLast": false 26 | }, 27 | "singleline": { 28 | "delimiter": "comma", 29 | "requireLast": false 30 | } 31 | }], 32 | "react/prop-types": "off", 33 | "no-console": "warn", 34 | "no-warning-comments": "warn", 35 | "import/no-extraneous-dependencies": ["error", { "optionalDependencies": false, "peerDependencies": false }] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity -------------------------------------------------------------------------------- /.gitbook.yaml: -------------------------------------------------------------------------------- 1 | root: ./ 2 | structure: 3 | readme: README.md 4 | summary: SUMMARY.md 5 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | # Task: Feature Name: 3 | 4 | ## High Level Description 5 | 6 | Specific Changes 7 | Function x was added ... 8 | 9 | ### Code 10 | 11 | - [ ] Unit test 100% coverage 12 | - [ ] Does your code follow the naming and code documentation guidelines? 13 | 14 | ### Documentation 15 | 16 | - [ ] Is your code up to date with the spec? 17 | - [ ] Have you added your tests to the testing doc? 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | build/ 3 | coverage 4 | coverage.json 5 | .env 6 | gasReporterOutput.json 7 | .secret 8 | .infuraKey 9 | specs/.certora_config 10 | specs/.last_confs 11 | specs/.certora_build.json 12 | specs/.certora_verify 13 | .last_confs/ 14 | .certora_verify.json 15 | .certora_config/ 16 | .certora_build.json 17 | .coverage_contracts/ 18 | .coverage_artifacts/ -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "printWidth": 120, 4 | "trailingComma": "all", 5 | "singleQuote": true, 6 | "semi": false, 7 | "overrides": [ 8 | { 9 | "files": "contracts/**/*.sol", 10 | "options": { 11 | "tabWidth": 4, 12 | "singleQuote": false 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /.solcover.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | client: require('ganache-cli'), 3 | providerOptions: { 4 | mnemonic: "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat" 5 | }, 6 | silent: true, 7 | skipFiles: [ 8 | 'Migrations.sol', 9 | 'mocks/', 10 | 'packages/', 11 | 'external/canonical-weth' 12 | ] 13 | } -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "plugins": ["prettier"], 4 | "rules": { 5 | "prettier/prettier": "error", 6 | "var-name-mixedcase": "off", 7 | "mark-callable-contracts": "off", 8 | "compiler-version":["error", "0.6.10"], 9 | "not-rely-on-time": "off", 10 | "no-complex-fallback": "off", 11 | "no-inline-assembly": "off", 12 | "reason-string": "off" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.solhintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | migrations/ 3 | contracts/lib/oz/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | * contracts 3 | * [Migrations](docs/contracts-documentation/Migrations.md) 4 | * core 5 | * [AddressBook](docs/contracts-documentation/core/AddressBook.md) 6 | * [Controller](docs/contracts-documentation/core/Controller.md) 7 | * [MarginCalculator](docs/contracts-documentation/core/MarginCalculator.md) 8 | * [MarginPool](docs/contracts-documentation/core/MarginPool.md) 9 | * [Oracle](docs/contracts-documentation/core/Oracle.md) 10 | * [Otoken](docs/contracts-documentation/core/Otoken.md) 11 | * [OtokenFactory](docs/contracts-documentation/core/OtokenFactory.md) 12 | * [OtokenSpawner](docs/contracts-documentation/core/OtokenSpawner.md) 13 | * [Whitelist](docs/contracts-documentation/core/Whitelist.md) 14 | * external 15 | * callees 16 | * [PermitCallee](docs/contracts-documentation/external/callees/PermitCallee.md) 17 | * canonical-weth 18 | * [WETH9](docs/contracts-documentation/external/canonical-weth/WETH9.md) 19 | * proxies 20 | * [PayableProxyController](docs/contracts-documentation/external/proxies/PayableProxyController.md) 21 | * libs 22 | * [Actions](docs/contracts-documentation/libs/Actions.md) 23 | * [FixedPointInt256](docs/contracts-documentation/libs/FixedPointInt256.md) 24 | * [MarginVault](docs/contracts-documentation/libs/MarginVault.md) 25 | * [SignedConverter](docs/contracts-documentation/libs/SignedConverter.md) 26 | * pricers 27 | * [ChainlinkPricer](docs/contracts-documentation/pricers/ChainlinkPricer.md) 28 | * [CompoundPricer](docs/contracts-documentation/pricers/CompoundPricer.md) 29 | * [WstethPricer](docs/contracts-documentation/pricers/WstethPricer.md) 30 | * [YearnPricer](docs/contracts-documentation/pricers/YearnPricer.md) 31 | -------------------------------------------------------------------------------- /autotask/README.md: -------------------------------------------------------------------------------- 1 | # Gamma Protocol Defender Bot CLI Sync Script 2 | 3 | Helps manage bots running on OZ's defender using auto task client (https://www.npmjs.com/package/defender-autotask-client) 4 | 5 | ## Prequisites 6 | 7 | Currently, there is not way to add new bots via autotask client defender hence new bots will have to be added through the GUI for defender and pasted in the **defender-config.js** file: 8 | 9 | - Add your infura key in `.infuraKey` file 10 | - Add your dotenv key in `.env` file 11 | - You'll need the `ETHERSCAN_API`, `AUTOTASK_API_KEY`, `AUTOTASK_API_SECRET` added to the `.env` file 12 | 13 | ## Managing Base Asset using Chainlink's Pricer Bot 14 | 15 | As a pre-requisite, you need: 16 | 17 | - Get Asset addreess 18 | - Get bot key for chainlink's pricer bot 19 | 20 | Add new base asset (run the **view-bots** commands to get botkeys): 21 | 22 | ```sh 23 | $ npm run add-asset --asset=0x2xxxxxxxxxxxxxxxxx --bot=botkey 24 | ``` 25 | 26 | View assets for a bot: 27 | 28 | ```sh 29 | $ npm run view-bot --bot=botkey 30 | ``` 31 | 32 | Remove base asset for a bot: 33 | 34 | ```sh 35 | $ npm run remove-asset --asset=0xC0xxxxxxxxxxxxxxxxxxxx --bot=botkey 36 | ``` 37 | 38 | ## Managing Derived Asset Pricer Bot 39 | 40 | Add new derived asset (run the **view-bots** commands to get botkeys): 41 | 42 | ```sh 43 | $ npm run update-asset --asset=0xa276xxxxxxxxxxxxxxxxxxxxxxxxxxx --bot=2 44 | ``` 45 | 46 | Override exist asset tied to this bot: 47 | 48 | ```sh 49 | $ npm run update-asset --asset=0xa2xxxxxxxxxxxxxxxxxxxxxxxx --bot=2 --override=true 50 | ``` 51 | 52 | 53 | ## General Commands 54 | 55 | View all bots on defender: 56 | 57 | ```sh 58 | $ npm run view-bots 59 | ``` 60 | 61 | Push the changes to defender: 62 | 63 | ```sh 64 | $ npm run sync-bot --bot=botkey 65 | ``` 66 | 67 | 68 | 69 | , -------------------------------------------------------------------------------- /autotask/pricers-bot/codebuild/chains/mainnet/ChainlinkPricerAbi.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "_asset", 7 | "type": "address" 8 | }, 9 | { 10 | "internalType": "address", 11 | "name": "_aggregator", 12 | "type": "address" 13 | }, 14 | { 15 | "internalType": "address", 16 | "name": "_oracle", 17 | "type": "address" 18 | } 19 | ], 20 | "stateMutability": "nonpayable", 21 | "type": "constructor" 22 | }, 23 | { 24 | "inputs": [], 25 | "name": "aggregator", 26 | "outputs": [ 27 | { 28 | "internalType": "contract AggregatorInterface", 29 | "name": "", 30 | "type": "address" 31 | } 32 | ], 33 | "stateMutability": "view", 34 | "type": "function" 35 | }, 36 | { 37 | "inputs": [], 38 | "name": "asset", 39 | "outputs": [ 40 | { 41 | "internalType": "address", 42 | "name": "", 43 | "type": "address" 44 | } 45 | ], 46 | "stateMutability": "view", 47 | "type": "function" 48 | }, 49 | { 50 | "inputs": [], 51 | "name": "oracle", 52 | "outputs": [ 53 | { 54 | "internalType": "contract OracleInterface", 55 | "name": "", 56 | "type": "address" 57 | } 58 | ], 59 | "stateMutability": "view", 60 | "type": "function" 61 | }, 62 | { 63 | "inputs": [], 64 | "name": "getPrice", 65 | "outputs": [ 66 | { 67 | "internalType": "uint256", 68 | "name": "", 69 | "type": "uint256" 70 | } 71 | ], 72 | "stateMutability": "view", 73 | "type": "function" 74 | }, 75 | { 76 | "inputs": [ 77 | { 78 | "internalType": "uint256", 79 | "name": "_expiryTimestamp", 80 | "type": "uint256" 81 | }, 82 | { 83 | "internalType": "uint80", 84 | "name": "_roundId", 85 | "type": "uint80" 86 | } 87 | ], 88 | "name": "setExpiryPriceInOracle", 89 | "outputs": [], 90 | "stateMutability": "nonpayable", 91 | "type": "function" 92 | } 93 | ] -------------------------------------------------------------------------------- /autotask/pricers-bot/enums.js: -------------------------------------------------------------------------------- 1 | const BaseAsset = 'Base Asset'; 2 | const DerivedAsset = 'Derived Asset'; 3 | module.exports = { 4 | BaseAsset, 5 | DerivedAsset 6 | } -------------------------------------------------------------------------------- /ci/e2e.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | $(npm bin)/ganache-cli --deterministic "myth like bonus scare over problem client lizard pioneer submit female collect" --port 8545 --fork https://mainnet.infura.io/v3/$INFURA_KEY@11608387 --unlock 0xbe0eb53f46cd790cd13851d5eff43d12404d33e8 --unlock 0x638E5DA0EEbbA58c67567bcEb4Ab2dc8D34853FB > /dev/null 2>&1 & sleep 10 && node --max-old-space-size=4096 $(npm bin)/truffle test ./test/e2e/*.ts -------------------------------------------------------------------------------- /codechecks.yml: -------------------------------------------------------------------------------- 1 | checks: 2 | - name: eth-gas-reporter/codechecks -------------------------------------------------------------------------------- /contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | contract Migrations { 5 | address public owner; 6 | uint256 public last_completed_migration; 7 | 8 | constructor() public { 9 | owner = msg.sender; 10 | } 11 | 12 | modifier restricted() { 13 | if (msg.sender == owner) _; 14 | } 15 | 16 | function setCompleted(uint256 completed) public restricted { 17 | last_completed_migration = completed; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/external/callees/PermitCallee.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity =0.6.10; 5 | 6 | pragma experimental ABIEncoderV2; 7 | 8 | import {CalleeInterface} from "../../interfaces/CalleeInterface.sol"; 9 | import {IERC20PermitUpgradeable} from "../../packages/oz/upgradeability/erc20-permit/IERC20PermitUpgradeable.sol"; 10 | 11 | /** 12 | * @title PermitCallee 13 | * @author Opyn Team 14 | * @dev Contract for executing permit signature 15 | */ 16 | contract PermitCallee is CalleeInterface { 17 | function callFunction(address payable _sender, bytes memory _data) external override { 18 | ( 19 | address token, 20 | address owner, 21 | address spender, 22 | uint256 amount, 23 | uint256 deadline, 24 | uint8 v, 25 | bytes32 r, 26 | bytes32 s 27 | ) = abi.decode(_data, (address, address, address, uint256, uint256, uint8, bytes32, bytes32)); 28 | 29 | IERC20PermitUpgradeable(token).permit(owner, spender, amount, deadline, v, r, s); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/interfaces/AddressBookInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | interface AddressBookInterface { 5 | /* Getters */ 6 | 7 | function getOtokenImpl() external view returns (address); 8 | 9 | function getOtokenFactory() external view returns (address); 10 | 11 | function getWhitelist() external view returns (address); 12 | 13 | function getController() external view returns (address); 14 | 15 | function getOracle() external view returns (address); 16 | 17 | function getMarginPool() external view returns (address); 18 | 19 | function getMarginCalculator() external view returns (address); 20 | 21 | function getLiquidationManager() external view returns (address); 22 | 23 | function getAddress(bytes32 _id) external view returns (address); 24 | 25 | /* Setters */ 26 | 27 | function setOtokenImpl(address _otokenImpl) external; 28 | 29 | function setOtokenFactory(address _factory) external; 30 | 31 | function setOracleImpl(address _otokenImpl) external; 32 | 33 | function setWhitelist(address _whitelist) external; 34 | 35 | function setController(address _controller) external; 36 | 37 | function setMarginPool(address _marginPool) external; 38 | 39 | function setMarginCalculator(address _calculator) external; 40 | 41 | function setLiquidationManager(address _liquidationManager) external; 42 | 43 | function setAddress(bytes32 _id, address _newImpl) external; 44 | } 45 | -------------------------------------------------------------------------------- /contracts/interfaces/AggregatorInterface.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | /** 7 | * @dev Interface of the Chainlink aggregator 8 | */ 9 | interface AggregatorInterface { 10 | function decimals() external view returns (uint8); 11 | 12 | function description() external view returns (string memory); 13 | 14 | function version() external view returns (uint256); 15 | 16 | // getRoundData and latestRoundData should both raise "No data present" 17 | // if they do not have data to report, instead of returning unset values 18 | // which could be misinterpreted as actual reported values. 19 | function getRoundData(uint80 _roundId) 20 | external 21 | view 22 | returns ( 23 | uint80 roundId, 24 | int256 answer, 25 | uint256 startedAt, 26 | uint256 updatedAt, 27 | uint80 answeredInRound 28 | ); 29 | 30 | function latestRoundData() 31 | external 32 | view 33 | returns ( 34 | uint80 roundId, 35 | int256 answer, 36 | uint256 startedAt, 37 | uint256 updatedAt, 38 | uint80 answeredInRound 39 | ); 40 | } 41 | -------------------------------------------------------------------------------- /contracts/interfaces/CTokenInterface.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | /** 7 | * @dev Interface of Compound cToken 8 | */ 9 | interface CTokenInterface { 10 | /** 11 | * @notice Calculates the exchange rate from the underlying to the CToken 12 | * @return Calculated exchange rate scaled by 1e18 13 | */ 14 | function exchangeRateStored() external view returns (uint256); 15 | 16 | function decimals() external view returns (uint256); 17 | } 18 | -------------------------------------------------------------------------------- /contracts/interfaces/CalleeInterface.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | /** 7 | * @dev Contract interface that can be called from Controller as a call action. 8 | */ 9 | interface CalleeInterface { 10 | /** 11 | * Allows users to send this contract arbitrary data. 12 | * @param _sender The msg.sender to Controller 13 | * @param _data Arbitrary data given by the sender 14 | */ 15 | function callFunction(address payable _sender, bytes memory _data) external; 16 | } 17 | -------------------------------------------------------------------------------- /contracts/interfaces/MarginCalculatorInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | pragma experimental ABIEncoderV2; 5 | 6 | import {MarginVault} from "../libs/MarginVault.sol"; 7 | 8 | interface MarginCalculatorInterface { 9 | function addressBook() external view returns (address); 10 | 11 | function getExpiredPayoutRate(address _otoken) external view returns (uint256); 12 | 13 | function getExcessCollateral(MarginVault.Vault calldata _vault, uint256 _vaultType) 14 | external 15 | view 16 | returns (uint256 netValue, bool isExcess); 17 | 18 | function isLiquidatable( 19 | MarginVault.Vault memory _vault, 20 | uint256 _vaultType, 21 | uint256 _vaultLatestUpdate, 22 | uint256 _roundId 23 | ) 24 | external 25 | view 26 | returns ( 27 | bool, 28 | uint256, 29 | uint256 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /contracts/interfaces/MarginPoolInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | interface MarginPoolInterface { 5 | /* Getters */ 6 | function addressBook() external view returns (address); 7 | 8 | function farmer() external view returns (address); 9 | 10 | function getStoredBalance(address _asset) external view returns (uint256); 11 | 12 | function isWhitelistedOTokenBuyer(address _oTokenBuyer) external view returns (bool); 13 | 14 | function isWhitelistedOptionsVault(address _optionsVault) external view returns (bool); 15 | 16 | /* Admin-only functions */ 17 | function setFarmer(address _farmer) external; 18 | 19 | function farm( 20 | address _asset, 21 | address _receiver, 22 | uint256 _amount 23 | ) external; 24 | 25 | /* Controller-only functions */ 26 | function transferToPool( 27 | address _asset, 28 | address _user, 29 | uint256 _amount 30 | ) external; 31 | 32 | function transferToUser( 33 | address _asset, 34 | address _user, 35 | uint256 _amount 36 | ) external; 37 | 38 | function batchTransferToPool( 39 | address[] calldata _asset, 40 | address[] calldata _user, 41 | uint256[] calldata _amount 42 | ) external; 43 | 44 | function batchTransferToUser( 45 | address[] calldata _asset, 46 | address[] calldata _user, 47 | uint256[] calldata _amount 48 | ) external; 49 | } 50 | -------------------------------------------------------------------------------- /contracts/interfaces/OpynPricerInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | interface OpynPricerInterface { 5 | function getPrice() external view returns (uint256); 6 | 7 | function getHistoricalPrice(uint80 _roundId) external view returns (uint256, uint256); 8 | } 9 | -------------------------------------------------------------------------------- /contracts/interfaces/OracleInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | interface OracleInterface { 5 | function isLockingPeriodOver(address _asset, uint256 _expiryTimestamp) external view returns (bool); 6 | 7 | function isDisputePeriodOver(address _asset, uint256 _expiryTimestamp) external view returns (bool); 8 | 9 | function getExpiryPrice(address _asset, uint256 _expiryTimestamp) external view returns (uint256, bool); 10 | 11 | function getDisputer() external view returns (address); 12 | 13 | function getPricer(address _asset) external view returns (address); 14 | 15 | function getPrice(address _asset) external view returns (uint256); 16 | 17 | function getPricerLockingPeriod(address _pricer) external view returns (uint256); 18 | 19 | function getPricerDisputePeriod(address _pricer) external view returns (uint256); 20 | 21 | function getChainlinkRoundData(address _asset, uint80 _roundId) external view returns (uint256, uint256); 22 | 23 | // Non-view function 24 | 25 | function setAssetPricer(address _asset, address _pricer) external; 26 | 27 | function setLockingPeriod(address _pricer, uint256 _lockingPeriod) external; 28 | 29 | function setDisputePeriod(address _pricer, uint256 _disputePeriod) external; 30 | 31 | function setExpiryPrice( 32 | address _asset, 33 | uint256 _expiryTimestamp, 34 | uint256 _price 35 | ) external; 36 | 37 | function disputeExpiryPrice( 38 | address _asset, 39 | uint256 _expiryTimestamp, 40 | uint256 _price 41 | ) external; 42 | 43 | function setDisputer(address _disputer) external; 44 | } 45 | -------------------------------------------------------------------------------- /contracts/interfaces/OtokenInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | interface OtokenInterface { 5 | function addressBook() external view returns (address); 6 | 7 | function underlyingAsset() external view returns (address); 8 | 9 | function strikeAsset() external view returns (address); 10 | 11 | function collateralAsset() external view returns (address); 12 | 13 | function strikePrice() external view returns (uint256); 14 | 15 | function expiryTimestamp() external view returns (uint256); 16 | 17 | function isPut() external view returns (bool); 18 | 19 | function init( 20 | address _addressBook, 21 | address _underlyingAsset, 22 | address _strikeAsset, 23 | address _collateralAsset, 24 | uint256 _strikePrice, 25 | uint256 _expiry, 26 | bool _isPut 27 | ) external; 28 | 29 | function getOtokenDetails() 30 | external 31 | view 32 | returns ( 33 | address, 34 | address, 35 | address, 36 | uint256, 37 | uint256, 38 | bool 39 | ); 40 | 41 | function mintOtoken(address account, uint256 amount) external; 42 | 43 | function burnOtoken(address account, uint256 amount) external; 44 | } 45 | -------------------------------------------------------------------------------- /contracts/interfaces/WSTETHInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity =0.6.10; 3 | 4 | interface WSTETHInterface { 5 | function name() external view returns (string memory); 6 | 7 | function symbol() external view returns (string memory); 8 | 9 | function decimals() external view returns (uint8); 10 | 11 | function stEthPerToken() external view returns (uint256); 12 | } 13 | -------------------------------------------------------------------------------- /contracts/interfaces/WhitelistInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | interface WhitelistInterface { 5 | /* View functions */ 6 | 7 | function addressBook() external view returns (address); 8 | 9 | function isWhitelistedProduct( 10 | address _underlying, 11 | address _strike, 12 | address _collateral, 13 | bool _isPut 14 | ) external view returns (bool); 15 | 16 | function isWhitelistedCollateral(address _collateral) external view returns (bool); 17 | 18 | function isWhitelistedOtoken(address _otoken) external view returns (bool); 19 | 20 | function isWhitelistedCallee(address _callee) external view returns (bool); 21 | 22 | /* Admin / factory only functions */ 23 | function whitelistProduct( 24 | address _underlying, 25 | address _strike, 26 | address _collateral, 27 | bool _isPut 28 | ) external; 29 | 30 | function blacklistProduct( 31 | address _underlying, 32 | address _strike, 33 | address _collateral, 34 | bool _isPut 35 | ) external; 36 | 37 | function whitelistCollateral(address _collateral) external; 38 | 39 | function blacklistCollateral(address _collateral) external; 40 | 41 | function whitelistOtoken(address _otoken) external; 42 | 43 | function blacklistOtoken(address _otoken) external; 44 | 45 | function whitelistCallee(address _callee) external; 46 | 47 | function blacklistCallee(address _callee) external; 48 | } 49 | -------------------------------------------------------------------------------- /contracts/interfaces/YearnVaultInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.6.10; 3 | 4 | interface YearnVaultInterface { 5 | function name() external view returns (string memory); 6 | 7 | function symbol() external view returns (string memory); 8 | 9 | function decimals() external view returns (uint8); 10 | 11 | function pricePerShare() external view returns (uint256); 12 | 13 | function deposit(uint256) external; 14 | 15 | function withdraw(uint256) external; 16 | } 17 | -------------------------------------------------------------------------------- /contracts/interfaces/ZeroXExchangeInterface.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | pragma experimental ABIEncoderV2; 7 | 8 | /** 9 | * @dev ZeroX Exchange contract interface. 10 | */ 11 | interface ZeroXExchangeInterface { 12 | // solhint-disable max-line-length 13 | /// @dev Canonical order structure 14 | struct LimitOrder { 15 | address makerToken; // The ERC20 token the maker is selling and the maker is selling to the taker. 16 | address takerToken; // The ERC20 token the taker is selling and the taker is selling to the maker. 17 | uint128 makerAmount; // The amount of makerToken being sold by the maker. 18 | uint128 takerAmount; // The amount of takerToken being sold by the taker. 19 | uint128 takerTokenFeeAmount; // Amount of takerToken paid by the taker to the feeRecipient. 20 | address maker; // The address of the maker, and signer, of this order. 21 | address taker; // Allowed taker address. Set to zero to allow any taker. 22 | address sender; // Allowed address to call fillLimitOrder() (msg.sender). This is the same as taker, expect when using meta-transactions. Set to zero to allow any caller. 23 | address feeRecipient; // Recipient of maker token or taker token fees (if non-zero). 24 | bytes32 pool; // The staking pool to attribute the 0x protocol fee from this order. Set to zero to attribute to the default pool, not owned by anyone. 25 | uint64 expiry; // The Unix timestamp in seconds when this order expires. 26 | uint256 salt; // Arbitrary number to facilitate uniqueness of the order's hash. 27 | } 28 | 29 | struct Signature { 30 | uint8 signatureType; // Either 2 (EIP712) or 3 (EthSign) 31 | uint8 v; // Signature data. 32 | bytes32 r; // Signature data. 33 | bytes32 s; // Signature data. 34 | } 35 | 36 | /// @dev Executes multiple calls of fillLimitOrder. 37 | /// @param orders Array of order specifications. 38 | /// @param takerTokenFillAmounts Array of desired amounts of takerToken to sell in orders. 39 | /// @param signatures Array of proofs that orders have been created by makers. 40 | /// @return takerTokenFilledAmounts Array of amount of takerToken(s) filled. 41 | /// @return makerTokenFilledAmounts Array of amount of makerToken(s) filled. 42 | function batchFillLimitOrders( 43 | LimitOrder[] memory orders, 44 | Signature[] memory signatures, 45 | uint128[] memory takerTokenFillAmounts, 46 | bool revertIfIncomplete 47 | ) external payable returns (uint128[] memory takerTokenFilledAmounts, uint128[] memory makerTokenFilledAmounts); 48 | } 49 | -------------------------------------------------------------------------------- /contracts/libs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/contracts/libs/.gitkeep -------------------------------------------------------------------------------- /contracts/libs/SignedConverter.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | /** 7 | * @title SignedConverter 8 | * @author Opyn Team 9 | * @notice A library to convert an unsigned integer to signed integer or signed integer to unsigned integer. 10 | */ 11 | library SignedConverter { 12 | /** 13 | * @notice convert an unsigned integer to a signed integer 14 | * @param a uint to convert into a signed integer 15 | * @return converted signed integer 16 | */ 17 | function uintToInt(uint256 a) internal pure returns (int256) { 18 | require(a < 2**255, "FixedPointInt256: out of int range"); 19 | 20 | return int256(a); 21 | } 22 | 23 | /** 24 | * @notice convert a signed integer to an unsigned integer 25 | * @param a int to convert into an unsigned integer 26 | * @return converted unsigned integer 27 | */ 28 | function intToUint(int256 a) internal pure returns (uint256) { 29 | if (a < 0) { 30 | return uint256(-a); 31 | } else { 32 | return uint256(a); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /contracts/mocks/Mock0xERC20Proxy.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | pragma experimental ABIEncoderV2; 6 | 7 | import {ERC20Interface} from "../interfaces/ERC20Interface.sol"; 8 | import {SafeERC20} from "../packages/oz/SafeERC20.sol"; 9 | 10 | /** 11 | * @notice Mock 0x ERC20 Proxy 12 | 13 | */ 14 | contract Mock0xERC20Proxy { 15 | using SafeERC20 for ERC20Interface; 16 | 17 | function transferToken( 18 | address token, 19 | address from, 20 | address to, 21 | uint256 amount 22 | ) external { 23 | ERC20Interface(token).safeTransferFrom(from, to, amount); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contracts/mocks/Mock0xExchange.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | pragma experimental ABIEncoderV2; 6 | 7 | import {ZeroXExchangeInterface} from "../interfaces/ZeroXExchangeInterface.sol"; 8 | import {ERC20Interface} from "../interfaces/ERC20Interface.sol"; 9 | import {SafeERC20} from "../packages/oz/SafeERC20.sol"; 10 | import {Mock0xERC20Proxy} from "./Mock0xERC20Proxy.sol"; 11 | 12 | /** 13 | * @notice Mock 0x Exchange 14 | */ 15 | contract Mock0xExchange { 16 | using SafeERC20 for ERC20Interface; 17 | uint256 public called = 0; 18 | uint256 public takerAmount; 19 | uint256 public makerAmount; 20 | bytes public signature; 21 | uint256 public fillAmount; 22 | Mock0xERC20Proxy public proxy; 23 | 24 | constructor() public { 25 | proxy = new Mock0xERC20Proxy(); //TODO: what is this? do we need it? 26 | } 27 | 28 | function fillLimitOrder( 29 | ZeroXExchangeInterface.LimitOrder memory _order, 30 | ZeroXExchangeInterface.Signature memory _signature, 31 | uint128 _takerTokenFillAmount 32 | ) public payable returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount) { 33 | return (0, 0); 34 | } 35 | 36 | function batchFillLimitOrders( 37 | ZeroXExchangeInterface.LimitOrder[] memory _orders, 38 | ZeroXExchangeInterface.Signature[] memory _signatures, 39 | uint128[] memory _takerTokenFillAmounts, 40 | bool _revertIfIncomplete 41 | ) external payable returns (uint128[] memory takerTokenFilledAmounts, uint128[] memory makerTokenFilledAmounts) { 42 | for (uint256 i = 0; i < _orders.length; i++) { 43 | (takerTokenFilledAmounts[i], makerTokenFilledAmounts[i]) = fillLimitOrder( 44 | _orders[i], 45 | _signatures[i], 46 | _takerTokenFillAmounts[i] 47 | ); 48 | } 49 | return (takerTokenFilledAmounts, makerTokenFilledAmounts); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /contracts/mocks/MockAddressBook.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | contract MockAddressBook { 5 | address private _otokenImpl; 6 | address private _whitelist; 7 | address private _otokenFactoryImpl; 8 | address private _oracle; 9 | address private _controllerImpl; 10 | address private _oracleImpl; 11 | address private _calculatorImpl; 12 | address private _marginPool; 13 | 14 | function setOtokenImpl(address _newImpl) external { 15 | _otokenImpl = _newImpl; 16 | } 17 | 18 | function setWhitelist(address _newImpl) external { 19 | _whitelist = _newImpl; 20 | } 21 | 22 | function setOtokenFactory(address _otokenFactory) external { 23 | _otokenFactoryImpl = _otokenFactory; 24 | } 25 | 26 | function setController(address _controller) external { 27 | _controllerImpl = _controller; 28 | } 29 | 30 | function setOracle(address _oracleAddr) external { 31 | _oracleImpl = _oracleAddr; 32 | } 33 | 34 | function setMarginCalculator(address _calculator) external { 35 | _calculatorImpl = _calculator; 36 | } 37 | 38 | function setMarginPool(address _pool) external { 39 | _marginPool = _pool; 40 | } 41 | 42 | function getOtokenImpl() external view returns (address) { 43 | return _otokenImpl; 44 | } 45 | 46 | function getWhitelist() external view returns (address) { 47 | return _whitelist; 48 | } 49 | 50 | function getOtokenFactory() external view returns (address) { 51 | return _otokenFactoryImpl; 52 | } 53 | 54 | function getOracle() external view returns (address) { 55 | return _oracleImpl; 56 | } 57 | 58 | function getController() external view returns (address) { 59 | return _controllerImpl; 60 | } 61 | 62 | function getMarginCalculator() external view returns (address) { 63 | return _calculatorImpl; 64 | } 65 | 66 | function getMarginPool() external view returns (address) { 67 | return _marginPool; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /contracts/mocks/MockCToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | import {ERC20Upgradeable} from "../packages/oz/upgradeability/ERC20Upgradeable.sol"; 5 | 6 | contract MockCToken is ERC20Upgradeable { 7 | uint256 public exchangeRateStored; 8 | 9 | constructor(string memory _name, string memory _symbol) public { 10 | __ERC20_init_unchained(_name, _symbol); 11 | _setupDecimals(8); 12 | } 13 | 14 | function mint(address account, uint256 amount) public { 15 | _mint(account, amount); 16 | } 17 | 18 | function setExchangeRate(uint256 _exchangeRateStored) external { 19 | exchangeRateStored = _exchangeRateStored; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/mocks/MockCUSDC.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | import {ERC20Upgradeable} from "../packages/oz/upgradeability/ERC20Upgradeable.sol"; 5 | import {ERC20Interface} from "../interfaces/ERC20Interface.sol"; 6 | import {SafeMath} from "../packages/oz/SafeMath.sol"; 7 | 8 | contract MockCUSDC is ERC20Upgradeable { 9 | uint256 public exchangeRateStored; 10 | address public underlying; 11 | uint256 public scale = 1e18; 12 | 13 | constructor( 14 | string memory _name, 15 | string memory _symbol, 16 | address _underlying, 17 | uint256 _initExchangeRateStored 18 | ) public { 19 | __ERC20_init_unchained(_name, _symbol); 20 | _setupDecimals(8); 21 | 22 | underlying = _underlying; 23 | exchangeRateStored = _initExchangeRateStored; 24 | } 25 | 26 | function mint(uint256 amount) public returns (uint256) { 27 | uint256 numerator = scale.mul(amount); 28 | uint256 cTokenAmount = numerator.div(exchangeRateStored); 29 | _mint(msg.sender, cTokenAmount); 30 | ERC20Interface(underlying).transferFrom(msg.sender, address(this), amount); 31 | return 0; 32 | } 33 | 34 | function redeem(uint256 amount) public returns (uint256) { 35 | _burn(msg.sender, amount); 36 | uint256 underlyingAmount = amount.mul(exchangeRateStored).div(scale); 37 | ERC20Interface(underlying).transfer(msg.sender, underlyingAmount); 38 | } 39 | 40 | function setExchangeRate(uint256 _exchangeRateStored) external { 41 | exchangeRateStored = _exchangeRateStored; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /contracts/mocks/MockChainlinkAggregator.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | /** 7 | * @notice Chainlink oracle mock 8 | */ 9 | contract MockChainlinkAggregator { 10 | uint256 public decimals = 8; 11 | 12 | /// @dev mock for round timestmap 13 | mapping(uint256 => uint256) internal roundTimestamp; 14 | /// @dev mock for round price 15 | mapping(uint256 => int256) internal roundAnswer; 16 | 17 | int256 internal lastAnswer; 18 | 19 | function getRoundData(uint80 _roundId) 20 | external 21 | view 22 | returns ( 23 | uint80 roundId, 24 | int256 answer, 25 | uint256 startedAt, 26 | uint256 updatedAt, 27 | uint80 answeredInRound 28 | ) 29 | { 30 | require(roundTimestamp[_roundId] != 0, "No data present"); 31 | 32 | return (_roundId, roundAnswer[_roundId], roundTimestamp[_roundId], roundTimestamp[_roundId], _roundId); 33 | } 34 | 35 | function latestRoundData() 36 | external 37 | view 38 | returns ( 39 | uint80 roundId, 40 | int256 answer, 41 | uint256 startedAt, 42 | uint256 updatedAt, 43 | uint80 answeredInRound 44 | ) 45 | { 46 | return (1, lastAnswer, now, now, 1); 47 | } 48 | 49 | /// @dev function to mock setting round timestamp 50 | function setRoundTimestamp(uint256 _roundId, uint256 _timestamp) external { 51 | roundTimestamp[_roundId] = _timestamp; 52 | } 53 | 54 | /// @dev function to mock setting round timestamp 55 | function setRoundAnswer(uint256 _roundId, int256 _answer) external { 56 | roundAnswer[_roundId] = _answer; 57 | } 58 | 59 | function setLatestAnswer(int256 _answer) external { 60 | lastAnswer = _answer; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /contracts/mocks/MockController.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | // import "../packages/oz/upgradeability/VersionedInitializable.sol"; 7 | import "../interfaces/OtokenInterface.sol"; 8 | import "../interfaces/CalleeInterface.sol"; 9 | import "../interfaces/ERC20Interface.sol"; 10 | 11 | /** 12 | * @author Opyn Team 13 | * @notice Upgradeable Controller that can mock minting and burning calls from controller. 14 | */ 15 | contract MockController { 16 | /// @notice addressbook address 17 | address public addressBook; 18 | address public owner; 19 | 20 | /** 21 | * @dev this function is invoked by the proxy contract when this contract is added to the 22 | * AddressBook. 23 | * @param _addressBook the address of the AddressBook 24 | **/ 25 | function initialize(address _addressBook, address _owner) external { 26 | addressBook = _addressBook; 27 | owner = _owner; 28 | } 29 | 30 | /** 31 | * @dev this function is used to test if controller can mint otokens 32 | */ 33 | function testMintOtoken( 34 | address _otoken, 35 | address _account, 36 | uint256 _amount 37 | ) external { 38 | OtokenInterface(_otoken).mintOtoken(_account, _amount); 39 | } 40 | 41 | /** 42 | * @dev this function is used to test if controller can burn otokens 43 | */ 44 | function testBurnOtoken( 45 | address _otoken, 46 | address _account, 47 | uint256 _amount 48 | ) external { 49 | OtokenInterface(_otoken).burnOtoken(_account, _amount); 50 | } 51 | 52 | /** 53 | * @dev this function is used to test if controller can be the only msg.sender to the 0xcallee 54 | */ 55 | function test0xCallee(address _callee, bytes memory _data) external { 56 | CalleeInterface(_callee).callFunction(msg.sender, _data); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /contracts/mocks/MockERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | import {ERC20Upgradeable} from "../packages/oz/upgradeability/ERC20Upgradeable.sol"; 5 | 6 | contract MockERC20 is ERC20Upgradeable { 7 | constructor( 8 | string memory _name, 9 | string memory _symbol, 10 | uint8 _decimals 11 | ) public { 12 | __ERC20_init_unchained(_name, _symbol); 13 | _setupDecimals(_decimals); 14 | } 15 | 16 | function mint(address account, uint256 amount) public { 17 | _mint(account, amount); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/mocks/MockOtoken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.10; 2 | 3 | import {ERC20PermitUpgradeable} from "../packages/oz/upgradeability/erc20-permit/ERC20PermitUpgradeable.sol"; 4 | import {AddressBookInterface} from "../interfaces/AddressBookInterface.sol"; 5 | 6 | /** 7 | * SPDX-License-Identifier: UNLICENSED 8 | * @dev The Otoken inherits ERC20PermitUpgradeable because we need to use the init instead of constructor. 9 | */ 10 | contract MockOtoken is ERC20PermitUpgradeable { 11 | address public addressBook; 12 | address public controller; 13 | address public underlyingAsset; 14 | address public strikeAsset; 15 | address public collateralAsset; 16 | 17 | uint256 public strikePrice; 18 | uint256 public expiryTimestamp; 19 | 20 | bool public isPut; 21 | 22 | bool public inited = false; 23 | 24 | function init( 25 | address _addressBook, 26 | address _underlyingAsset, 27 | address _strikeAsset, 28 | address _collateralAsset, 29 | uint256 _strikePrice, 30 | uint256 _expiryTimestamp, 31 | bool _isPut 32 | ) external initializer { 33 | inited = true; 34 | controller = AddressBookInterface(_addressBook).getController(); 35 | underlyingAsset = _underlyingAsset; 36 | strikeAsset = _strikeAsset; 37 | collateralAsset = _collateralAsset; 38 | strikePrice = _strikePrice; 39 | expiryTimestamp = _expiryTimestamp; 40 | isPut = _isPut; 41 | string memory tokenName = "ETHUSDC/1597511955/200P/USDC"; 42 | string memory tokenSymbol = "oETHUSDCP"; 43 | __ERC20_init_unchained(tokenName, tokenSymbol); 44 | __ERC20Permit_init(tokenName); 45 | _setupDecimals(8); 46 | } 47 | 48 | function getOtokenDetails() 49 | external 50 | view 51 | returns ( 52 | address, 53 | address, 54 | address, 55 | uint256, 56 | uint256, 57 | bool 58 | ) 59 | { 60 | return (collateralAsset, underlyingAsset, strikeAsset, strikePrice, expiryTimestamp, isPut); 61 | } 62 | 63 | function mintOtoken(address _to, uint256 _amount) external { 64 | _mint(_to, _amount); 65 | } 66 | 67 | function burnOtoken(address account, uint256 amount) external { 68 | _burn(account, amount); 69 | } 70 | 71 | function getChainId() external view returns (uint256 chainId) { 72 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 73 | // solhint-disable-next-line no-inline-assembly 74 | assembly { 75 | chainId := chainid() 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /contracts/mocks/MockPermitERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | import {ERC20PermitUpgradeable} from "../packages/oz/upgradeability/erc20-permit/ERC20PermitUpgradeable.sol"; 5 | 6 | contract MockPermitERC20 is ERC20PermitUpgradeable { 7 | constructor( 8 | string memory _name, 9 | string memory _symbol, 10 | uint8 _decimals 11 | ) public { 12 | __ERC20_init_unchained(_name, _symbol); 13 | __ERC20Permit_init(_name); 14 | _setupDecimals(_decimals); 15 | } 16 | 17 | function mint(address account, uint256 amount) public { 18 | _mint(account, amount); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /contracts/mocks/MockPricer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | import {OracleInterface} from "../interfaces/OracleInterface.sol"; 5 | 6 | contract MockPricer { 7 | OracleInterface public oracle; 8 | 9 | uint256 internal price; 10 | address public asset; 11 | 12 | constructor(address _asset, address _oracle) public { 13 | asset = _asset; 14 | oracle = OracleInterface(_oracle); 15 | } 16 | 17 | function setPrice(uint256 _price) external { 18 | price = _price; 19 | } 20 | 21 | function getPrice() external view returns (uint256) { 22 | return price; 23 | } 24 | 25 | function setExpiryPriceInOracle(uint256 _expiryTimestamp, uint256 _price) external { 26 | oracle.setExpiryPrice(asset, _expiryTimestamp, _price); 27 | } 28 | 29 | function getHistoricalPrice(uint80 _roundId) external view returns (uint256, uint256) { 30 | return (price, now); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /contracts/mocks/MockWSTETHToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | import {ERC20Upgradeable} from "../packages/oz/upgradeability/ERC20Upgradeable.sol"; 5 | 6 | contract MockWSTETHToken is ERC20Upgradeable { 7 | uint256 public stEthPerToken; 8 | 9 | constructor(string memory _name, string memory _symbol) public { 10 | __ERC20_init_unchained(_name, _symbol); 11 | _setupDecimals(18); 12 | } 13 | 14 | function mint(address account, uint256 amount) public { 15 | _mint(account, amount); 16 | } 17 | 18 | function setStEthPerToken(uint256 _stEthPerToken) external { 19 | stEthPerToken = _stEthPerToken; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/mocks/MockWhitelistModule.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | contract MockWhitelistModule { 5 | mapping(address => bool) public _isWhitelistedOtoken; 6 | mapping(bytes32 => bool) private _isWhitelistedProduct; 7 | mapping(address => bool) private whitelistedCollateral; 8 | mapping(address => bool) private whitelistedCallee; 9 | 10 | function whitelistProduct( 11 | address _underlying, 12 | address _strike, 13 | address _collateral, 14 | bool _isPut 15 | ) external returns (bytes32 id) { 16 | id = keccak256(abi.encodePacked(_underlying, _strike, _collateral, _isPut)); 17 | 18 | _isWhitelistedProduct[id] = true; 19 | } 20 | 21 | function isWhitelistedProduct( 22 | address _underlying, 23 | address _strike, 24 | address _collateral, 25 | bool _isPut 26 | ) external view returns (bool isValid) { 27 | bytes32 id = keccak256(abi.encodePacked(_underlying, _strike, _collateral, _isPut)); 28 | return _isWhitelistedProduct[id]; 29 | } 30 | 31 | function whitelistOtoken(address _otoken) external { 32 | _isWhitelistedOtoken[_otoken] = true; 33 | } 34 | 35 | function isWhitelistedOtoken(address _otoken) external view returns (bool) { 36 | return _isWhitelistedOtoken[_otoken]; 37 | } 38 | 39 | function isWhitelistedCollateral(address _collateral) external view returns (bool) { 40 | return whitelistedCollateral[_collateral]; 41 | } 42 | 43 | function whitelistCollateral(address _collateral) external { 44 | require(!whitelistedCollateral[_collateral], "Whitelist: Collateral already whitelisted"); 45 | 46 | whitelistedCollateral[_collateral] = true; 47 | } 48 | 49 | function isWhitelistedCallee(address _callee) external view returns (bool) { 50 | return whitelistedCallee[_callee]; 51 | } 52 | 53 | function whitelistCallee(address _callee) external { 54 | whitelistedCallee[_callee] = true; 55 | } 56 | 57 | function blacklistCallee(address _callee) external { 58 | whitelistedCallee[_callee] = false; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /contracts/mocks/MockYToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity 0.6.10; 3 | 4 | import {ERC20Upgradeable} from "../packages/oz/upgradeability/ERC20Upgradeable.sol"; 5 | 6 | contract MockYToken is ERC20Upgradeable { 7 | uint256 public pricePerShare; 8 | 9 | constructor(string memory _name, string memory _symbol) public { 10 | __ERC20_init_unchained(_name, _symbol); 11 | _setupDecimals(8); 12 | } 13 | 14 | function mint(address account, uint256 amount) public { 15 | _mint(account, amount); 16 | } 17 | 18 | function setPricePerShare(uint256 _pricePerShare) external { 19 | pricePerShare = _pricePerShare; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/packages/Spawn.sol: -------------------------------------------------------------------------------- 1 | /* solhint-disable avoid-low-level-calls, indent, no-inline-assembly */ 2 | /* This contract is copied from Spawner package: https://github.com/0age/Spawner */ 3 | pragma solidity =0.6.10; 4 | 5 | /** 6 | * @title Spawn 7 | * @author 0age 8 | * @notice This contract provides creation code that is used by Spawner in order 9 | * to initialize and deploy eip-1167 minimal proxies for a given logic contract. 10 | * SPDX-License-Identifier: MIT 11 | */ 12 | // version: https://github.com/0age/Spawner/blob/1b342afda0c1ec47e6a2d65828a6ca50f0a442fe/contracts/Spawner.sol 13 | contract Spawn { 14 | constructor(address logicContract, bytes memory initializationCalldata) public payable { 15 | // delegatecall into the logic contract to perform initialization. 16 | (bool ok, ) = logicContract.delegatecall(initializationCalldata); 17 | if (!ok) { 18 | // pass along failure message from delegatecall and revert. 19 | assembly { 20 | returndatacopy(0, 0, returndatasize()) 21 | revert(0, returndatasize()) 22 | } 23 | } 24 | 25 | // place eip-1167 runtime code in memory. 26 | bytes memory runtimeCode = abi.encodePacked( 27 | bytes10(0x363d3d373d3d3d363d73), 28 | logicContract, 29 | bytes15(0x5af43d82803e903d91602b57fd5bf3) 30 | ); 31 | 32 | // return eip-1167 code to write it to spawned contract runtime. 33 | assembly { 34 | return(add(0x20, runtimeCode), 45) // eip-1167 runtime code, length 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /contracts/packages/oz/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // openzeppelin-contracts v3.1.0 3 | 4 | pragma solidity 0.6.10; 5 | 6 | /* 7 | * @dev Provides information about the current execution context, including the 8 | * sender of the transaction and its data. While these are generally available 9 | * via msg.sender and msg.data, they should not be accessed in such a direct 10 | * manner, since when dealing with GSN meta-transactions the account sending and 11 | * paying for execution may not be the actual sender (as far as an application 12 | * is concerned). 13 | * 14 | * This contract is only required for intermediate, library-like contracts. 15 | */ 16 | abstract contract Context { 17 | function _msgSender() internal view virtual returns (address payable) { 18 | return msg.sender; 19 | } 20 | 21 | function _msgData() internal view virtual returns (bytes memory) { 22 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 23 | return msg.data; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contracts/packages/oz/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // openzeppelin-contracts v3.1.0 3 | 4 | pragma solidity 0.6.10; 5 | 6 | import "./Context.sol"; 7 | 8 | /** 9 | * @dev Contract module which provides a basic access control mechanism, where 10 | * there is an account (an owner) that can be granted exclusive access to 11 | * specific functions. 12 | * 13 | * By default, the owner account will be the one that deploys the contract. This 14 | * can later be changed with {transferOwnership}. 15 | * 16 | * This module is used through inheritance. It will make available the modifier 17 | * `onlyOwner`, which can be applied to your functions to restrict their use to 18 | * the owner. 19 | */ 20 | contract Ownable is Context { 21 | address private _owner; 22 | 23 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 24 | 25 | /** 26 | * @dev Initializes the contract setting the deployer as the initial owner. 27 | */ 28 | constructor() internal { 29 | address msgSender = _msgSender(); 30 | _owner = msgSender; 31 | emit OwnershipTransferred(address(0), msgSender); 32 | } 33 | 34 | /** 35 | * @dev Returns the address of the current owner. 36 | */ 37 | function owner() public view returns (address) { 38 | return _owner; 39 | } 40 | 41 | /** 42 | * @dev Throws if called by any account other than the owner. 43 | */ 44 | modifier onlyOwner() { 45 | require(_owner == _msgSender(), "Ownable: caller is not the owner"); 46 | _; 47 | } 48 | 49 | /** 50 | * @dev Leaves the contract without owner. It will not be possible to call 51 | * `onlyOwner` functions anymore. Can only be called by the current owner. 52 | * 53 | * NOTE: Renouncing ownership will leave the contract without an owner, 54 | * thereby removing any functionality that is only available to the owner. 55 | */ 56 | function renounceOwnership() public virtual onlyOwner { 57 | emit OwnershipTransferred(_owner, address(0)); 58 | _owner = address(0); 59 | } 60 | 61 | /** 62 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 63 | * Can only be called by the current owner. 64 | */ 65 | function transferOwnership(address newOwner) public virtual onlyOwner { 66 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 67 | emit OwnershipTransferred(_owner, newOwner); 68 | _owner = newOwner; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /contracts/packages/oz/Strings.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // openzeppelin-contracts v3.1.0 3 | 4 | /* solhint-disable */ 5 | pragma solidity =0.6.10; 6 | 7 | /** 8 | * @dev String operations. 9 | */ 10 | library Strings { 11 | /** 12 | * @dev Converts a `uint256` to its ASCII `string` representation. 13 | */ 14 | function toString(uint256 value) internal pure returns (string memory) { 15 | // Inspired by OraclizeAPI's implementation - MIT licence 16 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 17 | 18 | if (value == 0) { 19 | return "0"; 20 | } 21 | uint256 temp = value; 22 | uint256 digits; 23 | while (temp != 0) { 24 | digits++; 25 | temp /= 10; 26 | } 27 | bytes memory buffer = new bytes(digits); 28 | uint256 index = digits - 1; 29 | temp = value; 30 | while (temp != 0) { 31 | buffer[index--] = bytes1(uint8(48 + (temp % 10))); 32 | temp /= 10; 33 | } 34 | return string(buffer); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/packages/oz/upgradeability/GSN/ContextUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // openzeppelin-contracts-upgradeable v3.0.0 3 | 4 | pragma solidity >=0.6.0 <0.8.0; 5 | 6 | import "../Initializable.sol"; 7 | 8 | /* 9 | * @dev Provides information about the current execution context, including the 10 | * sender of the transaction and its data. While these are generally available 11 | * via msg.sender and msg.data, they should not be accessed in such a direct 12 | * manner, since when dealing with GSN meta-transactions the account sending and 13 | * paying for execution may not be the actual sender (as far as an application 14 | * is concerned). 15 | * 16 | * This contract is only required for intermediate, library-like contracts. 17 | */ 18 | abstract contract ContextUpgradeable is Initializable { 19 | function __Context_init() internal initializer { 20 | __Context_init_unchained(); 21 | } 22 | 23 | function __Context_init_unchained() internal initializer {} 24 | 25 | function _msgSender() internal view virtual returns (address payable) { 26 | return msg.sender; 27 | } 28 | 29 | function _msgData() internal view virtual returns (bytes memory) { 30 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 31 | return msg.data; 32 | } 33 | 34 | uint256[50] private __gap; 35 | } 36 | -------------------------------------------------------------------------------- /contracts/packages/oz/upgradeability/Initializable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // openzeppelin-contracts-upgradeable v3.0.0 3 | 4 | /* solhint-disable */ 5 | pragma solidity >=0.4.24 <0.7.0; 6 | 7 | /** 8 | * @title Initializable 9 | * 10 | * @dev Helper contract to support initializer functions. To use it, replace 11 | * the constructor with a function that has the `initializer` modifier. 12 | * WARNING: Unlike constructors, initializer functions must be manually 13 | * invoked. This applies both to deploying an Initializable contract, as well 14 | * as extending an Initializable contract via inheritance. 15 | * WARNING: When used with inheritance, manual care must be taken to not invoke 16 | * a parent initializer twice, or ensure that all initializers are idempotent, 17 | * because this is not dealt with automatically as with constructors. 18 | */ 19 | contract Initializable { 20 | /** 21 | * @dev Indicates that the contract has been initialized. 22 | */ 23 | bool private initialized; 24 | 25 | /** 26 | * @dev Indicates that the contract is in the process of being initialized. 27 | */ 28 | bool private initializing; 29 | 30 | /** 31 | * @dev Modifier to use in the initializer function of a contract. 32 | */ 33 | modifier initializer() { 34 | require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized"); 35 | 36 | bool isTopLevelCall = !initializing; 37 | if (isTopLevelCall) { 38 | initializing = true; 39 | initialized = true; 40 | } 41 | 42 | _; 43 | 44 | if (isTopLevelCall) { 45 | initializing = false; 46 | } 47 | } 48 | 49 | /// @dev Returns true if and only if the function is running in the constructor 50 | function isConstructor() private view returns (bool) { 51 | // extcodesize checks the size of the code stored in an address, and 52 | // address returns the current address. Since the code is still not 53 | // deployed when running a constructor, any checks on its code size will 54 | // yield zero, making it an effective way to detect if a contract is 55 | // under construction or not. 56 | address self = address(this); 57 | uint256 cs; 58 | assembly { 59 | cs := extcodesize(self) 60 | } 61 | return cs == 0; 62 | } 63 | 64 | // Reserved storage space to allow for layout changes in the future. 65 | uint256[50] private ______gap; 66 | } 67 | -------------------------------------------------------------------------------- /contracts/packages/oz/upgradeability/Proxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | // openzeppelin-contracts-upgradeable v3.0.0 3 | 4 | pragma solidity 0.6.10; 5 | 6 | /** 7 | * @title Proxy 8 | * @dev Gives the possibility to delegate any call to a foreign implementation. 9 | */ 10 | abstract contract Proxy { 11 | /** 12 | * @dev Tells the address of the implementation where every call will be delegated. 13 | * @return address of the implementation to which it will be delegated 14 | */ 15 | function implementation() public view virtual returns (address); 16 | 17 | /** 18 | * @dev Fallback function allowing to perform a delegatecall to the given implementation. 19 | * This function will return whatever the implementation call returns 20 | */ 21 | fallback() external payable { 22 | address _impl = implementation(); 23 | require(_impl != address(0)); 24 | 25 | assembly { 26 | let ptr := mload(0x40) 27 | calldatacopy(ptr, 0, calldatasize()) 28 | let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0) 29 | let size := returndatasize() 30 | returndatacopy(ptr, 0, size) 31 | 32 | switch result 33 | case 0 { 34 | revert(ptr, size) 35 | } 36 | default { 37 | return(ptr, size) 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/packages/oz/upgradeability/ReentrancyGuardUpgradeSafe.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // openzeppelin-contracts-upgradeable v3.0.0 3 | 4 | pragma solidity ^0.6.0; 5 | 6 | import "./Initializable.sol"; 7 | 8 | /** 9 | * @dev Contract module that helps prevent reentrant calls to a function. 10 | * 11 | * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier 12 | * available, which can be applied to functions to make sure there are no nested 13 | * (reentrant) calls to them. 14 | * 15 | * Note that because there is a single `nonReentrant` guard, functions marked as 16 | * `nonReentrant` may not call one another. This can be worked around by making 17 | * those functions `private`, and then adding `external` `nonReentrant` entry 18 | * points to them. 19 | * 20 | * TIP: If you would like to learn more about reentrancy and alternative ways 21 | * to protect against it, check out our blog post 22 | * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. 23 | */ 24 | contract ReentrancyGuardUpgradeSafe is Initializable { 25 | bool private _notEntered; 26 | 27 | function __ReentrancyGuard_init() internal initializer { 28 | __ReentrancyGuard_init_unchained(); 29 | } 30 | 31 | function __ReentrancyGuard_init_unchained() internal initializer { 32 | // Storing an initial non-zero value makes deployment a bit more 33 | // expensive, but in exchange the refund on every call to nonReentrant 34 | // will be lower in amount. Since refunds are capped to a percetange of 35 | // the total transaction's gas, it is best to keep them low in cases 36 | // like this one, to increase the likelihood of the full refund coming 37 | // into effect. 38 | _notEntered = true; 39 | } 40 | 41 | /** 42 | * @dev Prevents a contract from calling itself, directly or indirectly. 43 | * Calling a `nonReentrant` function from another `nonReentrant` 44 | * function is not supported. It is possible to prevent this from happening 45 | * by making the `nonReentrant` function external, and make it call a 46 | * `private` function that does the actual work. 47 | */ 48 | modifier nonReentrant() { 49 | // On the first call to nonReentrant, _notEntered will be true 50 | require(_notEntered, "ReentrancyGuard: reentrant call"); 51 | 52 | // Any calls to nonReentrant after this point will fail 53 | _notEntered = false; 54 | 55 | _; 56 | 57 | // By storing the original value once again, a refund is triggered (see 58 | // https://eips.ethereum.org/EIPS/eip-2200) 59 | _notEntered = true; 60 | } 61 | 62 | uint256[49] private __gap; 63 | } 64 | -------------------------------------------------------------------------------- /contracts/packages/oz/upgradeability/UpgradeabilityProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | // openzeppelin-contracts-upgradeable v3.0.0 3 | 4 | pragma solidity 0.6.10; 5 | 6 | import "./Proxy.sol"; 7 | 8 | /** 9 | * @title UpgradeabilityProxy 10 | * @dev This contract represents a proxy where the implementation address to which it will delegate can be upgraded 11 | */ 12 | contract UpgradeabilityProxy is Proxy { 13 | /** 14 | * @dev This event will be emitted every time the implementation gets upgraded 15 | * @param implementation representing the address of the upgraded implementation 16 | */ 17 | event Upgraded(address indexed implementation); 18 | 19 | /// @dev Storage position of the address of the current implementation 20 | bytes32 private constant implementationPosition = keccak256("org.zeppelinos.proxy.implementation"); 21 | 22 | /** 23 | * @dev Tells the address of the current implementation 24 | * @return impl address of the current implementation 25 | */ 26 | function implementation() public view override returns (address impl) { 27 | bytes32 position = implementationPosition; 28 | assembly { 29 | impl := sload(position) 30 | } 31 | } 32 | 33 | /** 34 | * @dev Sets the address of the current implementation 35 | * @param _newImplementation address representing the new implementation to be set 36 | */ 37 | function setImplementation(address _newImplementation) internal { 38 | bytes32 position = implementationPosition; 39 | assembly { 40 | sstore(position, _newImplementation) 41 | } 42 | } 43 | 44 | /** 45 | * @dev Upgrades the implementation address 46 | * @param _newImplementation representing the address of the new implementation to be set 47 | */ 48 | function _upgradeTo(address _newImplementation) internal { 49 | address currentImplementation = implementation(); 50 | require(currentImplementation != _newImplementation); 51 | setImplementation(_newImplementation); 52 | emit Upgraded(_newImplementation); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /contracts/packages/oz/upgradeability/erc20-permit/IERC20PermitUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // openzeppelin-contracts-upgradeable v3.0.0 3 | 4 | pragma solidity >=0.6.0 <0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in 8 | * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. 9 | * 10 | * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by 11 | * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't 12 | * need to send a transaction, and thus is not required to hold Ether at all. 13 | */ 14 | interface IERC20PermitUpgradeable { 15 | /** 16 | * @dev Sets `amount` as the allowance of `spender` over `owner`'s tokens, 17 | * given `owner`'s signed approval. 18 | * 19 | * IMPORTANT: The same issues {IERC20-approve} has related to transaction 20 | * ordering also apply here. 21 | * 22 | * Emits an {Approval} event. 23 | * 24 | * Requirements: 25 | * 26 | * - `spender` cannot be the zero address. 27 | * - `deadline` must be a timestamp in the future. 28 | * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` 29 | * over the EIP712-formatted function arguments. 30 | * - the signature must use ``owner``'s current nonce (see {nonces}). 31 | * 32 | * For more information on the signature format, see the 33 | * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP 34 | * section]. 35 | */ 36 | function permit( 37 | address owner, 38 | address spender, 39 | uint256 amount, 40 | uint256 deadline, 41 | uint8 v, 42 | bytes32 r, 43 | bytes32 s 44 | ) external; 45 | 46 | /** 47 | * @dev Returns the current nonce for `owner`. This value must be 48 | * included whenever a signature is generated for {permit}. 49 | * 50 | * Every successful call to {permit} increases ``owner``'s nonce by one. This 51 | * prevents a signature from being used multiple times. 52 | */ 53 | function nonces(address owner) external view returns (uint256); 54 | 55 | /** 56 | * @dev Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. 57 | */ 58 | // solhint-disable-next-line func-name-mixedcase 59 | function DOMAIN_SEPARATOR() external view returns (bytes32); 60 | } 61 | -------------------------------------------------------------------------------- /contracts/packages/oz/upgradeability/utils/CountersUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // openzeppelin-contracts-upgradeable v3.0.0 3 | 4 | pragma solidity >=0.6.0 <0.8.0; 5 | 6 | import "../math/SafeMathUpgradeable.sol"; 7 | 8 | /** 9 | * @title Counters 10 | * @author Matt Condon (@shrugs) 11 | * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number 12 | * of elements in a mapping, issuing ERC721 ids, or counting request ids. 13 | * 14 | * Include with `using Counters for Counters.Counter;` 15 | * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath} 16 | * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never 17 | * directly accessed. 18 | */ 19 | library CountersUpgradeable { 20 | using SafeMathUpgradeable for uint256; 21 | 22 | struct Counter { 23 | // This variable should never be directly accessed by users of the library: interactions must be restricted to 24 | // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add 25 | // this feature: see https://github.com/ethereum/solidity/issues/4637 26 | uint256 _value; // default: 0 27 | } 28 | 29 | function current(Counter storage counter) internal view returns (uint256) { 30 | return counter._value; 31 | } 32 | 33 | function increment(Counter storage counter) internal { 34 | // The {SafeMath} overflow check can be skipped here, see the comment at the top 35 | counter._value += 1; 36 | } 37 | 38 | function decrement(Counter storage counter) internal { 39 | counter._value = counter._value.sub(1); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/tests/CalculatorTester.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity =0.6.10; 5 | pragma experimental ABIEncoderV2; 6 | 7 | import {MarginCalculator} from "../core/MarginCalculator.sol"; 8 | import {FixedPointInt256} from "../libs/FixedPointInt256.sol"; 9 | 10 | contract CalculatorTester is MarginCalculator { 11 | constructor(address _addressBook) public MarginCalculator(_addressBook) {} 12 | 13 | function getExpiredCashValue( 14 | address _underlying, 15 | address _strike, 16 | uint256 _expiryTimestamp, 17 | uint256 _strikePrice, 18 | bool _isPut 19 | ) external view returns (uint256) { 20 | return 21 | FixedPointInt256.toScaledUint( 22 | _getExpiredCashValue(_underlying, _strike, _expiryTimestamp, _strikePrice, _isPut), 23 | BASE, 24 | true 25 | ); 26 | } 27 | 28 | function findUpperBoundValue( 29 | address _underlying, 30 | address _strike, 31 | address _collateral, 32 | bool _isPut, 33 | uint256 _expiryTimestamp 34 | ) external view returns (uint256) { 35 | bytes32 productHash = keccak256(abi.encode(_underlying, _strike, _collateral, _isPut)); 36 | 37 | return FixedPointInt256.toScaledUint(_findUpperBoundValue(productHash, _expiryTimestamp), 27, false); 38 | } 39 | 40 | function price( 41 | uint256 _vaultCollateral, 42 | uint256 _vaultDebt, 43 | uint256 _cv, 44 | uint256 _spotPrice, 45 | uint256 _auctionStartingTime, 46 | uint256 _collateralDecimals, 47 | bool _isPut 48 | ) external view returns (uint256) { 49 | FixedPointInt256.FixedPointInt memory vaultCollateral = FixedPointInt256.fromScaledUint( 50 | _vaultCollateral, 51 | _collateralDecimals 52 | ); 53 | FixedPointInt256.FixedPointInt memory vaultDebt = FixedPointInt256.fromScaledUint(_vaultDebt, BASE); 54 | FixedPointInt256.FixedPointInt memory cv = FixedPointInt256.fromScaledUint(_cv, BASE); 55 | FixedPointInt256.FixedPointInt memory spotPrice = FixedPointInt256.fromScaledUint(_spotPrice, BASE); 56 | 57 | return 58 | _getDebtPrice(vaultCollateral, vaultDebt, cv, spotPrice, _auctionStartingTime, _collateralDecimals, _isPut); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /contracts/tests/CallTester.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | /** 7 | * @author Opyn Team 8 | * @notice Call action testing contract 9 | */ 10 | contract CallTester { 11 | event CallFunction(address sender, bytes data); 12 | 13 | function callFunction(address _sender, bytes memory _data) external { 14 | emit CallFunction(_sender, _data); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/tests/CalleeAllowanceTester.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | pragma experimental ABIEncoderV2; 7 | 8 | import {CalleeInterface} from "../interfaces/CalleeInterface.sol"; 9 | import {ERC20Interface} from "../interfaces/ERC20Interface.sol"; 10 | import {SafeERC20} from "../packages/oz/SafeERC20.sol"; 11 | 12 | /** 13 | * @author Opyn Team 14 | * @title CalleeAllowanceTester 15 | * @notice contract test if we can successfully pull weth from the payable proxy 16 | */ 17 | contract CalleeAllowanceTester is CalleeInterface { 18 | using SafeERC20 for ERC20Interface; 19 | ERC20Interface public weth; 20 | 21 | constructor(address _weth) public { 22 | weth = ERC20Interface(_weth); 23 | } 24 | 25 | // tset pull token 26 | function callFunction(address payable, bytes memory _data) external override { 27 | (address from, uint256 amount) = abi.decode(_data, (address, uint256)); 28 | 29 | weth.safeTransferFrom(from, address(this), amount); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/tests/FlashUnwrap.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | pragma experimental ABIEncoderV2; 7 | 8 | import {CalleeInterface} from "../interfaces/CalleeInterface.sol"; 9 | import {ERC20Interface} from "../interfaces/ERC20Interface.sol"; 10 | import {SafeERC20} from "../packages/oz/SafeERC20.sol"; 11 | import {WETH9} from "../external/canonical-weth/WETH9.sol"; 12 | 13 | /** 14 | * @author Opyn Team 15 | * @title FlashUnwrap 16 | * @notice contract To unwrap WETH. This is just a contract to test the Call action 17 | */ 18 | contract FlashUnwrap is CalleeInterface { 19 | using SafeERC20 for ERC20Interface; 20 | 21 | // Number of bytes in a CallFunctionData struct 22 | uint256 private constant NUM_CALLFUNCTIONDATA_BYTES = 32; 23 | 24 | WETH9 public WETH; 25 | 26 | struct CallFunctionData { 27 | uint256 amount; 28 | } 29 | 30 | constructor(address payable weth) public { 31 | WETH = WETH9(weth); 32 | } 33 | 34 | event WrappedETH(address indexed to, uint256 amount); 35 | event UnwrappedETH(address to, uint256 amount); 36 | 37 | receive() external payable {} 38 | 39 | // flash unwrap 40 | function callFunction(address payable _sender, bytes memory _data) external override { 41 | require(_data.length == NUM_CALLFUNCTIONDATA_BYTES, "FlashUnwrap: cannot parse CallFunctionData"); 42 | 43 | CallFunctionData memory cfd = abi.decode(_data, (CallFunctionData)); 44 | 45 | WETH.transferFrom(_sender, address(this), cfd.amount); 46 | WETH.withdraw(cfd.amount); 47 | 48 | _sender.transfer(cfd.amount); 49 | 50 | emit UnwrappedETH(_sender, cfd.amount); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /contracts/tests/MarginVaultTester.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.10; 2 | 3 | // SPDX-License-Identifier: UNLICENSED 4 | pragma experimental ABIEncoderV2; 5 | 6 | import {MarginVault} from "../libs/MarginVault.sol"; 7 | 8 | contract MarginVaultTester { 9 | using MarginVault for MarginVault.Vault; 10 | 11 | mapping(address => mapping(uint256 => MarginVault.Vault)) private vault; 12 | 13 | function getVault(uint256 _vaultIndex) external view returns (MarginVault.Vault memory) { 14 | return vault[msg.sender][_vaultIndex]; 15 | } 16 | 17 | function testAddShort( 18 | uint256 _vaultIndex, 19 | address _shortOtoken, 20 | uint256 _amount, 21 | uint256 _index 22 | ) external { 23 | vault[msg.sender][_vaultIndex].addShort(_shortOtoken, _amount, _index); 24 | } 25 | 26 | function testRemoveShort( 27 | uint256 _vaultIndex, 28 | address _shortOtoken, 29 | uint256 _amount, 30 | uint256 _index 31 | ) external { 32 | vault[msg.sender][_vaultIndex].removeShort(_shortOtoken, _amount, _index); 33 | } 34 | 35 | function testAddLong( 36 | uint256 _vaultIndex, 37 | address _longOtoken, 38 | uint256 _amount, 39 | uint256 _index 40 | ) external { 41 | vault[msg.sender][_vaultIndex].addLong(_longOtoken, _amount, _index); 42 | } 43 | 44 | function testRemoveLong( 45 | uint256 _vaultIndex, 46 | address _longOtoken, 47 | uint256 _amount, 48 | uint256 _index 49 | ) external { 50 | vault[msg.sender][_vaultIndex].removeLong(_longOtoken, _amount, _index); 51 | } 52 | 53 | function testAddCollateral( 54 | uint256 _vaultIndex, 55 | address _collateralAsset, 56 | uint256 _amount, 57 | uint256 _index 58 | ) external { 59 | vault[msg.sender][_vaultIndex].addCollateral(_collateralAsset, _amount, _index); 60 | } 61 | 62 | function testRemoveCollateral( 63 | uint256 _vaultIndex, 64 | address _collateralAsset, 65 | uint256 _amount, 66 | uint256 _index 67 | ) external { 68 | vault[msg.sender][_vaultIndex].removeCollateral(_collateralAsset, _amount, _index); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /contracts/tests/OtokenImplV1.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.10; 2 | 3 | import {ERC20PermitUpgradeable} from "../packages/oz/upgradeability/erc20-permit/ERC20PermitUpgradeable.sol"; 4 | import {AddressBookInterface} from "../interfaces/AddressBookInterface.sol"; 5 | 6 | /** 7 | * SPDX-License-Identifier: UNLICENSED 8 | * @dev The Otoken inherits ERC20PermitUpgradeable because we need to use the init instead of constructor 9 | * This is V1 implementation, with no getOtokenDetails() 10 | */ 11 | contract OtokenImplV1 is ERC20PermitUpgradeable { 12 | address public addressBook; 13 | address public controller; 14 | address public underlyingAsset; 15 | address public strikeAsset; 16 | address public collateralAsset; 17 | 18 | uint256 public strikePrice; 19 | uint256 public expiryTimestamp; 20 | 21 | bool public isPut; 22 | 23 | bool public inited = false; 24 | 25 | function init( 26 | address _addressBook, 27 | address _underlyingAsset, 28 | address _strikeAsset, 29 | address _collateralAsset, 30 | uint256 _strikePrice, 31 | uint256 _expiryTimestamp, 32 | bool _isPut 33 | ) external initializer { 34 | inited = true; 35 | controller = AddressBookInterface(_addressBook).getController(); 36 | underlyingAsset = _underlyingAsset; 37 | strikeAsset = _strikeAsset; 38 | collateralAsset = _collateralAsset; 39 | strikePrice = _strikePrice; 40 | expiryTimestamp = _expiryTimestamp; 41 | isPut = _isPut; 42 | string memory tokenName = "ETHUSDC/1597511955/200P/USDC"; 43 | string memory tokenSymbol = "oETHUSDCP"; 44 | __ERC20_init_unchained(tokenName, tokenSymbol); 45 | __ERC20Permit_init(tokenName); 46 | _setupDecimals(8); 47 | } 48 | 49 | function mintOtoken(address _to, uint256 _amount) external { 50 | _mint(_to, _amount); 51 | } 52 | 53 | function burnOtoken(address account, uint256 amount) external { 54 | _burn(account, amount); 55 | } 56 | 57 | function getChainId() external view returns (uint256 chainId) { 58 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 59 | // solhint-disable-next-line no-inline-assembly 60 | assembly { 61 | chainId := chainid() 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /contracts/tests/SignedConverterTester.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | pragma experimental ABIEncoderV2; 7 | 8 | import "../libs/SignedConverter.sol"; 9 | 10 | /** 11 | * @author Opyn Team 12 | * @notice SignedConverter contract tester 13 | */ 14 | contract SignedConverterTester { 15 | using SignedConverter for int256; 16 | using SignedConverter for uint256; 17 | 18 | function testFromInt(int256 a) external pure returns (uint256) { 19 | return SignedConverter.intToUint(a); 20 | } 21 | 22 | function testFromUint(uint256 a) external pure returns (int256) { 23 | return SignedConverter.uintToInt(a); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contracts/tests/UpgradeableContractV1.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | import {Initializable} from "../packages/oz/upgradeability/Initializable.sol"; 7 | 8 | /** 9 | * @author Opyn Team 10 | * @notice Upgradeable testing contract 11 | */ 12 | contract UpgradeableContractV1 is Initializable { 13 | /// @notice addressbook address 14 | address public addressBook; 15 | /// @notice owner address 16 | address public owner; 17 | 18 | /** 19 | * @dev this function is invoked by the proxy contract when this contract is added to the 20 | * AddressBook. 21 | * @param _addressBook the address of the AddressBook 22 | **/ 23 | function initialize(address _addressBook, address _owner) public initializer { 24 | addressBook = _addressBook; 25 | owner = _owner; 26 | } 27 | 28 | function getV1Version() external pure returns (uint256) { 29 | return 1; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/tests/UpgradeableContractV2.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * SPDX-License-Identifier: UNLICENSED 3 | */ 4 | pragma solidity 0.6.10; 5 | 6 | import {UpgradeableContractV1} from "./UpgradeableContractV1.sol"; 7 | 8 | /** 9 | * @author Opyn Team 10 | * @notice Upgradeable testing contract 11 | */ 12 | contract UpgradeableContractV2 is UpgradeableContractV1 { 13 | function getV2Version() external pure returns (uint256) { 14 | return 2; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/contract.hbs: -------------------------------------------------------------------------------- 1 | # `{{name}}` 2 | 3 | {{{natspec.userdoc}}} 4 | 5 | {{{natspec.devdoc}}} 6 | 7 | {{#if ownModifiers}} 8 | ## Modifiers: 9 | {{#ownModifiers}} 10 | - `{{name}}({{args}})` 11 | {{/ownModifiers}} 12 | {{/if}} 13 | 14 | {{#if ownFunctions}} 15 | ## Functions: 16 | {{#ownFunctions}} 17 | - `{{name}}({{args}}) ({{visibility}})` 18 | {{/ownFunctions}} 19 | {{/if}} 20 | 21 | {{#if ownEvents}} 22 | ## Events: 23 | {{#ownEvents}} 24 | - `{{name}}({{args}})` 25 | {{/ownEvents}} 26 | {{/if}} 27 | 28 | 29 | 30 | {{#ownModifiers}} 31 | ### Modifier `{{name}}({{args}})` 32 | {{#if natspec.userdoc}}{{natspec.userdoc}}{{/if}} 33 | {{#if natspec.devdoc}}{{natspec.devdoc}}{{/if}} 34 | 35 | {{#if natspec.params}} 36 | #### Parameters: 37 | {{#natspec.params}} 38 | - `{{param}}`: {{description}} 39 | {{/natspec.params}} 40 | {{/if}} 41 | {{/ownModifiers}} 42 | 43 | {{#ownFunctions}} 44 | ### Function `{{name}}({{args}}){{#if outputs}} → {{outputs}}{{/if}} {{visibility}}` 45 | {{#if natspec.userdoc}}{{natspec.userdoc}}{{/if}} 46 | {{#if natspec.devdoc}}{{natspec.devdoc}}{{/if}} 47 | 48 | {{#if natspec.params}} 49 | #### Parameters: 50 | {{#natspec.params}} 51 | - `{{param}}`: {{description}} 52 | {{/natspec.params}} 53 | {{/if}} 54 | {{#if natspec.returns}} 55 | #### Return Values: 56 | {{#natspec.returns}} 57 | - {{param}} {{description}} 58 | {{/natspec.returns}} 59 | {{/if}} 60 | {{/ownFunctions}} 61 | 62 | {{#ownEvents}} 63 | ### Event `{{name}}({{args}})` 64 | {{#if natspec.userdoc}}{{natspec.userdoc}}{{/if}} 65 | {{#if natspec.devdoc}}{{natspec.devdoc}}{{/if}} 66 | {{#if natspec.params}} 67 | #### Parameters: 68 | {{#natspec.params}} 69 | - `{{param}}`: {{description}} 70 | {{/natspec.params}} 71 | {{/if}} 72 | {{/ownEvents}} -------------------------------------------------------------------------------- /docs/contracts-documentation/Migrations.md: -------------------------------------------------------------------------------- 1 | # `Migrations` 2 | 3 | ## Modifiers: 4 | 5 | - `restricted()` 6 | 7 | ## Functions: 8 | 9 | - `setCompleted(uint256 completed) (public)` 10 | 11 | ### Modifier `restricted()` 12 | 13 | ### Function `setCompleted(uint256 completed) public` 14 | -------------------------------------------------------------------------------- /docs/contracts-documentation/core/OtokenSpawner.md: -------------------------------------------------------------------------------- 1 | # `OtokenSpawner` 2 | 3 | This contract spawns and initializes eip-1167 minimal proxies that 4 | 5 | point to existing logic contracts. 6 | 7 | This contract was modified from Spawner.sol 8 | 9 | https://github.com/0age/Spawner/blob/master/contracts/Spawner.sol to fit into OtokenFactory 10 | 11 | ## Functions: 12 | 13 | - `_spawn(address logicContract, bytes initializationCalldata) (internal)` 14 | 15 | - `_computeAddress(address logicContract, bytes initializationCalldata) (internal)` 16 | 17 | ### Function `_spawn(address logicContract, bytes initializationCalldata) → address internal` 18 | 19 | internal function for spawning an eip-1167 minimal proxy using `CREATE2` 20 | 21 | #### Parameters: 22 | 23 | - `logicContract`: address of the logic contract 24 | 25 | - `initializationCalldata`: calldata that will be supplied to the `DELEGATECALL` 26 | 27 | from the spawned contract to the logic contract during contract creation 28 | 29 | #### Return Values: 30 | 31 | - spawnedContract the address of the newly-spawned contract 32 | 33 | ### Function `_computeAddress(address logicContract, bytes initializationCalldata) → address target internal` 34 | 35 | internal view function for finding the address of the standard 36 | 37 | eip-1167 minimal proxy created using `CREATE2` with a given logic contract 38 | 39 | and initialization calldata payload 40 | 41 | #### Parameters: 42 | 43 | - `logicContract`: address of the logic contract 44 | 45 | - `initializationCalldata`: calldata that will be supplied to the `DELEGATECALL` 46 | 47 | from the spawned contract to the logic contract during contract creation 48 | 49 | #### Return Values: 50 | 51 | - target address of the next spawned minimal proxy contract with the 52 | 53 | given parameters. 54 | -------------------------------------------------------------------------------- /docs/contracts-documentation/external/callees/PermitCallee.md: -------------------------------------------------------------------------------- 1 | # `PermitCallee` 2 | 3 | Contract for executing permit signature 4 | 5 | ## Functions: 6 | 7 | - `callFunction(address payable _sender, bytes _data) (external)` 8 | 9 | ### Function `callFunction(address payable _sender, bytes _data) external` 10 | -------------------------------------------------------------------------------- /docs/contracts-documentation/external/callees/TradeCallee.md: -------------------------------------------------------------------------------- 1 | # `TradeCallee` 2 | 3 | callee contract to trade on 0x. 4 | 5 | ## Functions: 6 | 7 | - `constructor(address _exchange, address _weth, address _controller) (public)` 8 | 9 | - `callFunction(address payable _sender, bytes _data) (external)` 10 | 11 | - `fallback() (external)` 12 | 13 | ### Function `constructor(address _exchange, address _weth, address _controller) public` 14 | 15 | ### Function `callFunction(address payable _sender, bytes _data) external` 16 | 17 | fill 0x order 18 | 19 | #### Parameters: 20 | 21 | - `_sender`: the original sender who wants to trade on 0x 22 | 23 | - `_data`: abi-encoded order, fillamount, signature and _sender. fee payer is the address we pull weth from. 24 | 25 | ### Function `fallback() external` 26 | 27 | fallback function which allow ETH to be sent to this contract 28 | -------------------------------------------------------------------------------- /docs/contracts-documentation/external/proxies/PayableProxyController.md: -------------------------------------------------------------------------------- 1 | # `PayableProxyController` 2 | 3 | Contract for wrapping/unwrapping ETH before/after interacting with the Gamma Protocol 4 | 5 | ## Functions: 6 | 7 | - `constructor(address _controller, address _marginPool, address payable _weth) (public)` 8 | 9 | - `fallback() (external)` 10 | 11 | - `operate(struct Actions.ActionArgs[] _actions, address payable _sendEthTo) (external)` 12 | 13 | ### Function `constructor(address _controller, address _marginPool, address payable _weth) public` 14 | 15 | ### Function `fallback() external` 16 | 17 | fallback function which disallows ETH to be sent to this contract without data except when unwrapping WETH 18 | 19 | ### Function `operate(struct Actions.ActionArgs[] _actions, address payable _sendEthTo) external` 20 | 21 | execute a number of actions 22 | 23 | a wrapper for the Controller operate function, to wrap WETH and the beginning and unwrap WETH at the end of the execution 24 | 25 | #### Parameters: 26 | 27 | - `_actions`: array of actions arguments 28 | 29 | - `_sendEthTo`: address to send the remaining eth to 30 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/AddressBookInterface.md: -------------------------------------------------------------------------------- 1 | # `AddressBookInterface` 2 | 3 | ## Functions: 4 | 5 | - `getOtokenImpl() (external)` 6 | 7 | - `getOtokenFactory() (external)` 8 | 9 | - `getWhitelist() (external)` 10 | 11 | - `getController() (external)` 12 | 13 | - `getOracle() (external)` 14 | 15 | - `getMarginPool() (external)` 16 | 17 | - `getMarginCalculator() (external)` 18 | 19 | - `getLiquidationManager() (external)` 20 | 21 | - `getAddress(bytes32 _id) (external)` 22 | 23 | - `setOtokenImpl(address _otokenImpl) (external)` 24 | 25 | - `setOtokenFactory(address _factory) (external)` 26 | 27 | - `setOracleImpl(address _otokenImpl) (external)` 28 | 29 | - `setWhitelist(address _whitelist) (external)` 30 | 31 | - `setController(address _controller) (external)` 32 | 33 | - `setMarginPool(address _marginPool) (external)` 34 | 35 | - `setMarginCalculator(address _calculator) (external)` 36 | 37 | - `setLiquidationManager(address _liquidationManager) (external)` 38 | 39 | - `setAddress(bytes32 _id, address _newImpl) (external)` 40 | 41 | ### Function `getOtokenImpl() → address external` 42 | 43 | ### Function `getOtokenFactory() → address external` 44 | 45 | ### Function `getWhitelist() → address external` 46 | 47 | ### Function `getController() → address external` 48 | 49 | ### Function `getOracle() → address external` 50 | 51 | ### Function `getMarginPool() → address external` 52 | 53 | ### Function `getMarginCalculator() → address external` 54 | 55 | ### Function `getLiquidationManager() → address external` 56 | 57 | ### Function `getAddress(bytes32 _id) → address external` 58 | 59 | ### Function `setOtokenImpl(address _otokenImpl) external` 60 | 61 | ### Function `setOtokenFactory(address _factory) external` 62 | 63 | ### Function `setOracleImpl(address _otokenImpl) external` 64 | 65 | ### Function `setWhitelist(address _whitelist) external` 66 | 67 | ### Function `setController(address _controller) external` 68 | 69 | ### Function `setMarginPool(address _marginPool) external` 70 | 71 | ### Function `setMarginCalculator(address _calculator) external` 72 | 73 | ### Function `setLiquidationManager(address _liquidationManager) external` 74 | 75 | ### Function `setAddress(bytes32 _id, address _newImpl) external` 76 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/AggregatorInterface.md: -------------------------------------------------------------------------------- 1 | # `AggregatorInterface` 2 | 3 | Interface of the Chainlink aggregator 4 | 5 | ## Functions: 6 | 7 | - `decimals() (external)` 8 | 9 | - `description() (external)` 10 | 11 | - `version() (external)` 12 | 13 | - `getRoundData(uint80 _roundId) (external)` 14 | 15 | - `latestRoundData() (external)` 16 | 17 | ### Function `decimals() → uint8 external` 18 | 19 | ### Function `description() → string external` 20 | 21 | ### Function `version() → uint256 external` 22 | 23 | ### Function `getRoundData(uint80 _roundId) → uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound external` 24 | 25 | ### Function `latestRoundData() → uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound external` 26 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/CTokenInterface.md: -------------------------------------------------------------------------------- 1 | # `CTokenInterface` 2 | 3 | Interface of Compound cToken 4 | 5 | ## Functions: 6 | 7 | - `exchangeRateStored() (external)` 8 | 9 | - `decimals() (external)` 10 | 11 | ### Function `exchangeRateStored() → uint256 external` 12 | 13 | Calculates the exchange rate from the underlying to the CToken 14 | 15 | #### Return Values: 16 | 17 | - Calculated exchange rate scaled by 1e18 18 | 19 | ### Function `decimals() → uint256 external` 20 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/CalleeInterface.md: -------------------------------------------------------------------------------- 1 | # `CalleeInterface` 2 | 3 | Contract interface that can be called from Controller as a call action. 4 | 5 | ## Functions: 6 | 7 | - `callFunction(address payable _sender, bytes _data) (external)` 8 | 9 | ### Function `callFunction(address payable _sender, bytes _data) external` 10 | 11 | Allows users to send this contract arbitrary data. 12 | 13 | #### Parameters: 14 | 15 | - `_sender`: The msg.sender to Controller 16 | 17 | - `_data`: Arbitrary data given by the sender 18 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/MarginCalculatorInterface.md: -------------------------------------------------------------------------------- 1 | # `MarginCalculatorInterface` 2 | 3 | ## Functions: 4 | 5 | - `addressBook() (external)` 6 | 7 | - `getExpiredPayoutRate(address _otoken) (external)` 8 | 9 | - `getExcessCollateral(struct MarginVault.Vault _vault, uint256 _vaultType) (external)` 10 | 11 | - `isLiquidatable(struct MarginVault.Vault _vault, uint256 _vaultType, uint256 _vaultLatestUpdate, uint256 _roundId) (external)` 12 | 13 | ### Function `addressBook() → address external` 14 | 15 | ### Function `getExpiredPayoutRate(address _otoken) → uint256 external` 16 | 17 | ### Function `getExcessCollateral(struct MarginVault.Vault _vault, uint256 _vaultType) → uint256 netValue, bool isExcess external` 18 | 19 | ### Function `isLiquidatable(struct MarginVault.Vault _vault, uint256 _vaultType, uint256 _vaultLatestUpdate, uint256 _roundId) → bool, uint256, uint256 external` 20 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/MarginPoolInterface.md: -------------------------------------------------------------------------------- 1 | # `MarginPoolInterface` 2 | 3 | ## Functions: 4 | 5 | - `addressBook() (external)` 6 | 7 | - `farmer() (external)` 8 | 9 | - `getStoredBalance(address _asset) (external)` 10 | 11 | - `setFarmer(address _farmer) (external)` 12 | 13 | - `farm(address _asset, address _receiver, uint256 _amount) (external)` 14 | 15 | - `transferToPool(address _asset, address _user, uint256 _amount) (external)` 16 | 17 | - `transferToUser(address _asset, address _user, uint256 _amount) (external)` 18 | 19 | - `batchTransferToPool(address[] _asset, address[] _user, uint256[] _amount) (external)` 20 | 21 | - `batchTransferToUser(address[] _asset, address[] _user, uint256[] _amount) (external)` 22 | 23 | ### Function `addressBook() → address external` 24 | 25 | ### Function `farmer() → address external` 26 | 27 | ### Function `getStoredBalance(address _asset) → uint256 external` 28 | 29 | ### Function `setFarmer(address _farmer) external` 30 | 31 | ### Function `farm(address _asset, address _receiver, uint256 _amount) external` 32 | 33 | ### Function `transferToPool(address _asset, address _user, uint256 _amount) external` 34 | 35 | ### Function `transferToUser(address _asset, address _user, uint256 _amount) external` 36 | 37 | ### Function `batchTransferToPool(address[] _asset, address[] _user, uint256[] _amount) external` 38 | 39 | ### Function `batchTransferToUser(address[] _asset, address[] _user, uint256[] _amount) external` 40 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/OpynPricerInterface.md: -------------------------------------------------------------------------------- 1 | # `OpynPricerInterface` 2 | 3 | ## Functions: 4 | 5 | - `getPrice() (external)` 6 | 7 | - `getHistoricalPrice(uint80 _roundId) (external)` 8 | 9 | ### Function `getPrice() → uint256 external` 10 | 11 | ### Function `getHistoricalPrice(uint80 _roundId) → uint256, uint256 external` 12 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/OracleInterface.md: -------------------------------------------------------------------------------- 1 | # `OracleInterface` 2 | 3 | ## Functions: 4 | 5 | - `isLockingPeriodOver(address _asset, uint256 _expiryTimestamp) (external)` 6 | 7 | - `isDisputePeriodOver(address _asset, uint256 _expiryTimestamp) (external)` 8 | 9 | - `getExpiryPrice(address _asset, uint256 _expiryTimestamp) (external)` 10 | 11 | - `getDisputer() (external)` 12 | 13 | - `getPricer(address _asset) (external)` 14 | 15 | - `getPrice(address _asset) (external)` 16 | 17 | - `getPricerLockingPeriod(address _pricer) (external)` 18 | 19 | - `getPricerDisputePeriod(address _pricer) (external)` 20 | 21 | - `getChainlinkRoundData(address _asset, uint80 _roundId) (external)` 22 | 23 | - `setAssetPricer(address _asset, address _pricer) (external)` 24 | 25 | - `setLockingPeriod(address _pricer, uint256 _lockingPeriod) (external)` 26 | 27 | - `setDisputePeriod(address _pricer, uint256 _disputePeriod) (external)` 28 | 29 | - `setExpiryPrice(address _asset, uint256 _expiryTimestamp, uint256 _price) (external)` 30 | 31 | - `disputeExpiryPrice(address _asset, uint256 _expiryTimestamp, uint256 _price) (external)` 32 | 33 | - `setDisputer(address _disputer) (external)` 34 | 35 | ### Function `isLockingPeriodOver(address _asset, uint256 _expiryTimestamp) → bool external` 36 | 37 | ### Function `isDisputePeriodOver(address _asset, uint256 _expiryTimestamp) → bool external` 38 | 39 | ### Function `getExpiryPrice(address _asset, uint256 _expiryTimestamp) → uint256, bool external` 40 | 41 | ### Function `getDisputer() → address external` 42 | 43 | ### Function `getPricer(address _asset) → address external` 44 | 45 | ### Function `getPrice(address _asset) → uint256 external` 46 | 47 | ### Function `getPricerLockingPeriod(address _pricer) → uint256 external` 48 | 49 | ### Function `getPricerDisputePeriod(address _pricer) → uint256 external` 50 | 51 | ### Function `getChainlinkRoundData(address _asset, uint80 _roundId) → uint256, uint256 external` 52 | 53 | ### Function `setAssetPricer(address _asset, address _pricer) external` 54 | 55 | ### Function `setLockingPeriod(address _pricer, uint256 _lockingPeriod) external` 56 | 57 | ### Function `setDisputePeriod(address _pricer, uint256 _disputePeriod) external` 58 | 59 | ### Function `setExpiryPrice(address _asset, uint256 _expiryTimestamp, uint256 _price) external` 60 | 61 | ### Function `disputeExpiryPrice(address _asset, uint256 _expiryTimestamp, uint256 _price) external` 62 | 63 | ### Function `setDisputer(address _disputer) external` 64 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/OtokenInterface.md: -------------------------------------------------------------------------------- 1 | # `OtokenInterface` 2 | 3 | ## Functions: 4 | 5 | - `addressBook() (external)` 6 | 7 | - `underlyingAsset() (external)` 8 | 9 | - `strikeAsset() (external)` 10 | 11 | - `collateralAsset() (external)` 12 | 13 | - `strikePrice() (external)` 14 | 15 | - `expiryTimestamp() (external)` 16 | 17 | - `isPut() (external)` 18 | 19 | - `init(address _addressBook, address _underlyingAsset, address _strikeAsset, address _collateralAsset, uint256 _strikePrice, uint256 _expiry, bool _isPut) (external)` 20 | 21 | - `getOtokenDetails() (external)` 22 | 23 | - `mintOtoken(address account, uint256 amount) (external)` 24 | 25 | - `burnOtoken(address account, uint256 amount) (external)` 26 | 27 | ### Function `addressBook() → address external` 28 | 29 | ### Function `underlyingAsset() → address external` 30 | 31 | ### Function `strikeAsset() → address external` 32 | 33 | ### Function `collateralAsset() → address external` 34 | 35 | ### Function `strikePrice() → uint256 external` 36 | 37 | ### Function `expiryTimestamp() → uint256 external` 38 | 39 | ### Function `isPut() → bool external` 40 | 41 | ### Function `init(address _addressBook, address _underlyingAsset, address _strikeAsset, address _collateralAsset, uint256 _strikePrice, uint256 _expiry, bool _isPut) external` 42 | 43 | ### Function `getOtokenDetails() → address, address, address, uint256, uint256, bool external` 44 | 45 | ### Function `mintOtoken(address account, uint256 amount) external` 46 | 47 | ### Function `burnOtoken(address account, uint256 amount) external` 48 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/WETH9Interface.md: -------------------------------------------------------------------------------- 1 | # `WETH9Interface` 2 | 3 | ## Functions: 4 | 5 | - `deposit() (external)` 6 | 7 | - `withdraw(uint256 wad) (external)` 8 | 9 | - `totalSupply() (external)` 10 | 11 | - `approve(address guy, uint256 wad) (external)` 12 | 13 | - `transfer(address dst, uint256 wad) (external)` 14 | 15 | - `transferFrom(address src, address dst, uint256 wad) (external)` 16 | 17 | ### Function `deposit() external` 18 | 19 | ### Function `withdraw(uint256 wad) external` 20 | 21 | ### Function `totalSupply() → uint256 external` 22 | 23 | ### Function `approve(address guy, uint256 wad) → bool external` 24 | 25 | ### Function `transfer(address dst, uint256 wad) → bool external` 26 | 27 | ### Function `transferFrom(address src, address dst, uint256 wad) → bool external` 28 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/WSTETHInterface.md: -------------------------------------------------------------------------------- 1 | # `WSTETHInterface` 2 | 3 | ## Functions: 4 | 5 | - `name() (external)` 6 | 7 | - `symbol() (external)` 8 | 9 | - `decimals() (external)` 10 | 11 | - `stEthPerToken() (external)` 12 | 13 | ### Function `name() → string external` 14 | 15 | ### Function `symbol() → string external` 16 | 17 | ### Function `decimals() → uint8 external` 18 | 19 | ### Function `stEthPerToken() → uint256 external` 20 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/WhitelistInterface.md: -------------------------------------------------------------------------------- 1 | # `WhitelistInterface` 2 | 3 | ## Functions: 4 | 5 | - `addressBook() (external)` 6 | 7 | - `isWhitelistedProduct(address _underlying, address _strike, address _collateral, bool _isPut) (external)` 8 | 9 | - `isWhitelistedCollateral(address _collateral) (external)` 10 | 11 | - `isWhitelistedOtoken(address _otoken) (external)` 12 | 13 | - `isWhitelistedCallee(address _callee) (external)` 14 | 15 | - `whitelistProduct(address _underlying, address _strike, address _collateral, bool _isPut) (external)` 16 | 17 | - `blacklistProduct(address _underlying, address _strike, address _collateral, bool _isPut) (external)` 18 | 19 | - `whitelistCollateral(address _collateral) (external)` 20 | 21 | - `blacklistCollateral(address _collateral) (external)` 22 | 23 | - `whitelistOtoken(address _otoken) (external)` 24 | 25 | - `blacklistOtoken(address _otoken) (external)` 26 | 27 | - `whitelistCallee(address _callee) (external)` 28 | 29 | - `blacklistCallee(address _callee) (external)` 30 | 31 | ### Function `addressBook() → address external` 32 | 33 | ### Function `isWhitelistedProduct(address _underlying, address _strike, address _collateral, bool _isPut) → bool external` 34 | 35 | ### Function `isWhitelistedCollateral(address _collateral) → bool external` 36 | 37 | ### Function `isWhitelistedOtoken(address _otoken) → bool external` 38 | 39 | ### Function `isWhitelistedCallee(address _callee) → bool external` 40 | 41 | ### Function `whitelistProduct(address _underlying, address _strike, address _collateral, bool _isPut) external` 42 | 43 | ### Function `blacklistProduct(address _underlying, address _strike, address _collateral, bool _isPut) external` 44 | 45 | ### Function `whitelistCollateral(address _collateral) external` 46 | 47 | ### Function `blacklistCollateral(address _collateral) external` 48 | 49 | ### Function `whitelistOtoken(address _otoken) external` 50 | 51 | ### Function `blacklistOtoken(address _otoken) external` 52 | 53 | ### Function `whitelistCallee(address _callee) external` 54 | 55 | ### Function `blacklistCallee(address _callee) external` 56 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/YearnVaultInterface.md: -------------------------------------------------------------------------------- 1 | # `YearnVaultInterface` 2 | 3 | ## Functions: 4 | 5 | - `name() (external)` 6 | 7 | - `symbol() (external)` 8 | 9 | - `decimals() (external)` 10 | 11 | - `pricePerShare() (external)` 12 | 13 | - `deposit(uint256) (external)` 14 | 15 | - `withdraw(uint256) (external)` 16 | 17 | ### Function `name() → string external` 18 | 19 | ### Function `symbol() → string external` 20 | 21 | ### Function `decimals() → uint8 external` 22 | 23 | ### Function `pricePerShare() → uint256 external` 24 | 25 | ### Function `deposit(uint256) external` 26 | 27 | ### Function `withdraw(uint256) external` 28 | -------------------------------------------------------------------------------- /docs/contracts-documentation/interfaces/ZeroXExchangeInterface.md: -------------------------------------------------------------------------------- 1 | # `ZeroXExchangeInterface` 2 | 3 | ZeroX Exchange contract interface. 4 | 5 | ## Functions: 6 | 7 | - `batchFillLimitOrders(struct ZeroXExchangeInterface.LimitOrder[] orders, struct ZeroXExchangeInterface.Signature[] signatures, uint128[] takerTokenFillAmounts, bool revertIfIncomplete) (external)` 8 | 9 | ### Function `batchFillLimitOrders(struct ZeroXExchangeInterface.LimitOrder[] orders, struct ZeroXExchangeInterface.Signature[] signatures, uint128[] takerTokenFillAmounts, bool revertIfIncomplete) → uint128[] takerTokenFilledAmounts, uint128[] makerTokenFilledAmounts external` 10 | 11 | Executes multiple calls of fillLimitOrder. 12 | 13 | #### Parameters: 14 | 15 | - `orders`: Array of order specifications. 16 | 17 | - `takerTokenFillAmounts`: Array of desired amounts of takerToken to sell in orders. 18 | 19 | - `signatures`: Array of proofs that orders have been created by makers. 20 | 21 | #### Return Values: 22 | 23 | - takerTokenFilledAmounts Array of amount of takerToken(s) filled. 24 | 25 | - makerTokenFilledAmounts Array of amount of makerToken(s) filled. 26 | -------------------------------------------------------------------------------- /docs/contracts-documentation/libs/SignedConverter.md: -------------------------------------------------------------------------------- 1 | # `SignedConverter` 2 | 3 | A library to convert an unsigned integer to signed integer or signed integer to unsigned integer. 4 | 5 | ## Functions: 6 | 7 | - `uintToInt(uint256 a) (internal)` 8 | 9 | - `intToUint(int256 a) (internal)` 10 | 11 | ### Function `uintToInt(uint256 a) → int256 internal` 12 | 13 | convert an unsigned integer to a signed integer 14 | 15 | #### Parameters: 16 | 17 | - `a`: uint to convert into a signed integer 18 | 19 | #### Return Values: 20 | 21 | - converted signed integer 22 | 23 | ### Function `intToUint(int256 a) → uint256 internal` 24 | 25 | convert a signed integer to an unsigned integer 26 | 27 | #### Parameters: 28 | 29 | - `a`: int to convert into an unsigned integer 30 | 31 | #### Return Values: 32 | 33 | - converted unsigned integer 34 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/Mock0xERC20Proxy.md: -------------------------------------------------------------------------------- 1 | # `Mock0xERC20Proxy` 2 | 3 | Mock 0x ERC20 Proxy 4 | 5 | ## Functions: 6 | 7 | - `transferToken(address token, address from, address to, uint256 amount) (external)` 8 | 9 | ### Function `transferToken(address token, address from, address to, uint256 amount) external` 10 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/Mock0xExchange.md: -------------------------------------------------------------------------------- 1 | # `Mock0xExchange` 2 | 3 | Mock 0x Exchange 4 | 5 | ## Functions: 6 | 7 | - `fillLimitOrder(struct ZeroXExchangeInterface.LimitOrder _order, struct ZeroXExchangeInterface.Signature _signature, uint128 _takerTokenFillAmount) (public)` 8 | 9 | - `batchFillLimitOrders(struct ZeroXExchangeInterface.LimitOrder[] _orders, struct ZeroXExchangeInterface.Signature[] _signatures, uint128[] _takerTokenFillAmounts, bool _revertIfIncomplete) (external)` 10 | 11 | ### Function `fillLimitOrder(struct ZeroXExchangeInterface.LimitOrder _order, struct ZeroXExchangeInterface.Signature _signature, uint128 _takerTokenFillAmount) → uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount public` 12 | 13 | ### Function `batchFillLimitOrders(struct ZeroXExchangeInterface.LimitOrder[] _orders, struct ZeroXExchangeInterface.Signature[] _signatures, uint128[] _takerTokenFillAmounts, bool _revertIfIncomplete) → uint128[] takerTokenFilledAmounts, uint128[] makerTokenFilledAmounts external` 14 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockAddressBook.md: -------------------------------------------------------------------------------- 1 | # `MockAddressBook` 2 | 3 | ## Functions: 4 | 5 | - `setOtokenImpl(address _newImpl) (external)` 6 | 7 | - `setWhitelist(address _newImpl) (external)` 8 | 9 | - `setOtokenFactory(address _otokenFactory) (external)` 10 | 11 | - `setController(address _controller) (external)` 12 | 13 | - `setOracle(address _oracleAddr) (external)` 14 | 15 | - `setMarginCalculator(address _calculator) (external)` 16 | 17 | - `setMarginPool(address _pool) (external)` 18 | 19 | - `getOtokenImpl() (external)` 20 | 21 | - `getWhitelist() (external)` 22 | 23 | - `getOtokenFactory() (external)` 24 | 25 | - `getOracle() (external)` 26 | 27 | - `getController() (external)` 28 | 29 | - `getMarginCalculator() (external)` 30 | 31 | - `getMarginPool() (external)` 32 | 33 | ### Function `setOtokenImpl(address _newImpl) external` 34 | 35 | ### Function `setWhitelist(address _newImpl) external` 36 | 37 | ### Function `setOtokenFactory(address _otokenFactory) external` 38 | 39 | ### Function `setController(address _controller) external` 40 | 41 | ### Function `setOracle(address _oracleAddr) external` 42 | 43 | ### Function `setMarginCalculator(address _calculator) external` 44 | 45 | ### Function `setMarginPool(address _pool) external` 46 | 47 | ### Function `getOtokenImpl() → address external` 48 | 49 | ### Function `getWhitelist() → address external` 50 | 51 | ### Function `getOtokenFactory() → address external` 52 | 53 | ### Function `getOracle() → address external` 54 | 55 | ### Function `getController() → address external` 56 | 57 | ### Function `getMarginCalculator() → address external` 58 | 59 | ### Function `getMarginPool() → address external` 60 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockCToken.md: -------------------------------------------------------------------------------- 1 | # `MockCToken` 2 | 3 | ## Functions: 4 | 5 | - `constructor(string _name, string _symbol) (public)` 6 | 7 | - `mint(address account, uint256 amount) (public)` 8 | 9 | - `setExchangeRate(uint256 _exchangeRateStored) (external)` 10 | 11 | ### Function `constructor(string _name, string _symbol) public` 12 | 13 | ### Function `mint(address account, uint256 amount) public` 14 | 15 | ### Function `setExchangeRate(uint256 _exchangeRateStored) external` 16 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockCUSDC.md: -------------------------------------------------------------------------------- 1 | # `MockCUSDC` 2 | 3 | ## Functions: 4 | 5 | - `constructor(string _name, string _symbol, address _underlying, uint256 _initExchangeRateStored) (public)` 6 | 7 | - `mint(uint256 amount) (public)` 8 | 9 | - `redeem(uint256 amount) (public)` 10 | 11 | - `setExchangeRate(uint256 _exchangeRateStored) (external)` 12 | 13 | ### Function `constructor(string _name, string _symbol, address _underlying, uint256 _initExchangeRateStored) public` 14 | 15 | ### Function `mint(uint256 amount) → uint256 public` 16 | 17 | ### Function `redeem(uint256 amount) → uint256 public` 18 | 19 | ### Function `setExchangeRate(uint256 _exchangeRateStored) external` 20 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockChainlinkAggregator.md: -------------------------------------------------------------------------------- 1 | # `MockChainlinkAggregator` 2 | 3 | Chainlink oracle mock 4 | 5 | ## Functions: 6 | 7 | - `getRoundData(uint80 _roundId) (external)` 8 | 9 | - `latestRoundData() (external)` 10 | 11 | - `setRoundTimestamp(uint256 _roundId, uint256 _timestamp) (external)` 12 | 13 | - `setRoundAnswer(uint256 _roundId, int256 _answer) (external)` 14 | 15 | - `setLatestAnswer(int256 _answer) (external)` 16 | 17 | ### Function `getRoundData(uint80 _roundId) → uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound external` 18 | 19 | ### Function `latestRoundData() → uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound external` 20 | 21 | ### Function `setRoundTimestamp(uint256 _roundId, uint256 _timestamp) external` 22 | 23 | function to mock setting round timestamp 24 | 25 | ### Function `setRoundAnswer(uint256 _roundId, int256 _answer) external` 26 | 27 | function to mock setting round timestamp 28 | 29 | ### Function `setLatestAnswer(int256 _answer) external` 30 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockController.md: -------------------------------------------------------------------------------- 1 | # `MockController` 2 | 3 | Upgradeable Controller that can mock minting and burning calls from controller. 4 | 5 | ## Functions: 6 | 7 | - `initialize(address _addressBook, address _owner) (external)` 8 | 9 | - `testMintOtoken(address _otoken, address _account, uint256 _amount) (external)` 10 | 11 | - `testBurnOtoken(address _otoken, address _account, uint256 _amount) (external)` 12 | 13 | - `test0xCallee(address _callee, bytes _data) (external)` 14 | 15 | ### Function `initialize(address _addressBook, address _owner) external` 16 | 17 | this function is invoked by the proxy contract when this contract is added to the 18 | 19 | AddressBook. 20 | 21 | #### Parameters: 22 | 23 | - `_addressBook`: the address of the AddressBook* 24 | 25 | ### Function `testMintOtoken(address _otoken, address _account, uint256 _amount) external` 26 | 27 | this function is used to test if controller can mint otokens 28 | 29 | ### Function `testBurnOtoken(address _otoken, address _account, uint256 _amount) external` 30 | 31 | this function is used to test if controller can burn otokens 32 | 33 | ### Function `test0xCallee(address _callee, bytes _data) external` 34 | 35 | this function is used to test if controller can be the only msg.sender to the 0xcallee 36 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockDumbERC20.md: -------------------------------------------------------------------------------- 1 | # `MockDumbERC20` 2 | 3 | ERC20 Token that return false when operation failed 4 | 5 | ## Functions: 6 | 7 | - `constructor(string name_, string symbol_, uint8 decimals_) (public)` 8 | 9 | - `name() (public)` 10 | 11 | - `symbol() (public)` 12 | 13 | - `decimals() (public)` 14 | 15 | - `totalSupply() (public)` 16 | 17 | - `balanceOf(address account) (public)` 18 | 19 | - `transfer(address recipient, uint256 amount) (public)` 20 | 21 | - `allowance(address owner, address spender) (public)` 22 | 23 | - `approve(address spender, uint256 amount) (public)` 24 | 25 | - `transferFrom(address sender, address recipient, uint256 amount) (public)` 26 | 27 | - `mint(address recipient, uint256 amount) (public)` 28 | 29 | - `burn(address recipient, uint256 amount) (public)` 30 | 31 | - `setLocked(bool locked_) (public)` 32 | 33 | ### Function `constructor(string name_, string symbol_, uint8 decimals_) public` 34 | 35 | ### Function `name() → string public` 36 | 37 | ### Function `symbol() → string public` 38 | 39 | ### Function `decimals() → uint8 public` 40 | 41 | ### Function `totalSupply() → uint256 public` 42 | 43 | ### Function `balanceOf(address account) → uint256 public` 44 | 45 | ### Function `transfer(address recipient, uint256 amount) → bool public` 46 | 47 | ### Function `allowance(address owner, address spender) → uint256 public` 48 | 49 | ### Function `approve(address spender, uint256 amount) → bool public` 50 | 51 | ### Function `transferFrom(address sender, address recipient, uint256 amount) → bool public` 52 | 53 | ### Function `mint(address recipient, uint256 amount) public` 54 | 55 | ### Function `burn(address recipient, uint256 amount) public` 56 | 57 | ### Function `setLocked(bool locked_) public` 58 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockERC20.md: -------------------------------------------------------------------------------- 1 | # `MockERC20` 2 | 3 | ## Functions: 4 | 5 | - `constructor(string _name, string _symbol, uint8 _decimals) (public)` 6 | 7 | - `mint(address account, uint256 amount) (public)` 8 | 9 | ### Function `constructor(string _name, string _symbol, uint8 _decimals) public` 10 | 11 | ### Function `mint(address account, uint256 amount) public` 12 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockOtoken.md: -------------------------------------------------------------------------------- 1 | # `MockOtoken` 2 | 3 | SPDX-License-Identifier: UNLICENSED 4 | 5 | The Otoken inherits ERC20PermitUpgradeable because we need to use the init instead of constructor. 6 | 7 | ## Functions: 8 | 9 | - `init(address _addressBook, address _underlyingAsset, address _strikeAsset, address _collateralAsset, uint256 _strikePrice, uint256 _expiryTimestamp, bool _isPut) (external)` 10 | 11 | - `getOtokenDetails() (external)` 12 | 13 | - `mintOtoken(address _to, uint256 _amount) (external)` 14 | 15 | - `burnOtoken(address account, uint256 amount) (external)` 16 | 17 | - `getChainId() (external)` 18 | 19 | ### Function `init(address _addressBook, address _underlyingAsset, address _strikeAsset, address _collateralAsset, uint256 _strikePrice, uint256 _expiryTimestamp, bool _isPut) external` 20 | 21 | ### Function `getOtokenDetails() → address, address, address, uint256, uint256, bool external` 22 | 23 | ### Function `mintOtoken(address _to, uint256 _amount) external` 24 | 25 | ### Function `burnOtoken(address account, uint256 amount) external` 26 | 27 | ### Function `getChainId() → uint256 chainId external` 28 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockPermitERC20.md: -------------------------------------------------------------------------------- 1 | # `MockPermitERC20` 2 | 3 | ## Functions: 4 | 5 | - `constructor(string _name, string _symbol, uint8 _decimals) (public)` 6 | 7 | - `mint(address account, uint256 amount) (public)` 8 | 9 | ### Function `constructor(string _name, string _symbol, uint8 _decimals) public` 10 | 11 | ### Function `mint(address account, uint256 amount) public` 12 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockPricer.md: -------------------------------------------------------------------------------- 1 | # `MockPricer` 2 | 3 | ## Functions: 4 | 5 | - `constructor(address _asset, address _oracle) (public)` 6 | 7 | - `setPrice(uint256 _price) (external)` 8 | 9 | - `getPrice() (external)` 10 | 11 | - `setExpiryPriceInOracle(uint256 _expiryTimestamp, uint256 _price) (external)` 12 | 13 | - `getHistoricalPrice(uint80 _roundId) (external)` 14 | 15 | ### Function `constructor(address _asset, address _oracle) public` 16 | 17 | ### Function `setPrice(uint256 _price) external` 18 | 19 | ### Function `getPrice() → uint256 external` 20 | 21 | ### Function `setExpiryPriceInOracle(uint256 _expiryTimestamp, uint256 _price) external` 22 | 23 | ### Function `getHistoricalPrice(uint80 _roundId) → uint256, uint256 external` 24 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockWSTETHToken.md: -------------------------------------------------------------------------------- 1 | # `MockWSTETHToken` 2 | 3 | ## Functions: 4 | 5 | - `constructor(string _name, string _symbol) (public)` 6 | 7 | - `mint(address account, uint256 amount) (public)` 8 | 9 | - `setStEthPerToken(uint256 _stEthPerToken) (external)` 10 | 11 | ### Function `constructor(string _name, string _symbol) public` 12 | 13 | ### Function `mint(address account, uint256 amount) public` 14 | 15 | ### Function `setStEthPerToken(uint256 _stEthPerToken) external` 16 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockWhitelistModule.md: -------------------------------------------------------------------------------- 1 | # `MockWhitelistModule` 2 | 3 | ## Functions: 4 | 5 | - `whitelistProduct(address _underlying, address _strike, address _collateral, bool _isPut) (external)` 6 | 7 | - `isWhitelistedProduct(address _underlying, address _strike, address _collateral, bool _isPut) (external)` 8 | 9 | - `whitelistOtoken(address _otoken) (external)` 10 | 11 | - `isWhitelistedOtoken(address _otoken) (external)` 12 | 13 | - `isWhitelistedCollateral(address _collateral) (external)` 14 | 15 | - `whitelistCollateral(address _collateral) (external)` 16 | 17 | - `isWhitelistedCallee(address _callee) (external)` 18 | 19 | - `whitelistCallee(address _callee) (external)` 20 | 21 | - `blacklistCallee(address _callee) (external)` 22 | 23 | ### Function `whitelistProduct(address _underlying, address _strike, address _collateral, bool _isPut) → bytes32 id external` 24 | 25 | ### Function `isWhitelistedProduct(address _underlying, address _strike, address _collateral, bool _isPut) → bool isValid external` 26 | 27 | ### Function `whitelistOtoken(address _otoken) external` 28 | 29 | ### Function `isWhitelistedOtoken(address _otoken) → bool external` 30 | 31 | ### Function `isWhitelistedCollateral(address _collateral) → bool external` 32 | 33 | ### Function `whitelistCollateral(address _collateral) external` 34 | 35 | ### Function `isWhitelistedCallee(address _callee) → bool external` 36 | 37 | ### Function `whitelistCallee(address _callee) external` 38 | 39 | ### Function `blacklistCallee(address _callee) external` 40 | -------------------------------------------------------------------------------- /docs/contracts-documentation/mocks/MockYToken.md: -------------------------------------------------------------------------------- 1 | # `MockYToken` 2 | 3 | ## Functions: 4 | 5 | - `constructor(string _name, string _symbol) (public)` 6 | 7 | - `mint(address account, uint256 amount) (public)` 8 | 9 | - `setPricePerShare(uint256 _pricePerShare) (external)` 10 | 11 | ### Function `constructor(string _name, string _symbol) public` 12 | 13 | ### Function `mint(address account, uint256 amount) public` 14 | 15 | ### Function `setPricePerShare(uint256 _pricePerShare) external` 16 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/BokkyPooBahsDateTimeLibrary.md: -------------------------------------------------------------------------------- 1 | # `BokkyPooBahsDateTimeLibrary` 2 | 3 | ## Functions: 4 | 5 | - `_daysToDate(uint256 _days) (internal)` 6 | 7 | - `timestampToDate(uint256 timestamp) (internal)` 8 | 9 | ### Function `_daysToDate(uint256 _days) → uint256 year, uint256 month, uint256 day internal` 10 | 11 | ### Function `timestampToDate(uint256 timestamp) → uint256 year, uint256 month, uint256 day internal` 12 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/Spawn.md: -------------------------------------------------------------------------------- 1 | # `Spawn` 2 | 3 | This contract provides creation code that is used by Spawner in order 4 | 5 | to initialize and deploy eip-1167 minimal proxies for a given logic contract. 6 | 7 | SPDX-License-Identifier: MIT 8 | 9 | ## Functions: 10 | 11 | - `constructor(address logicContract, bytes initializationCalldata) (public)` 12 | 13 | ### Function `constructor(address logicContract, bytes initializationCalldata) public` 14 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/Context.md: -------------------------------------------------------------------------------- 1 | # `Context` 2 | 3 | ## Functions: 4 | 5 | - `_msgSender() (internal)` 6 | 7 | - `_msgData() (internal)` 8 | 9 | ### Function `_msgSender() → address payable internal` 10 | 11 | ### Function `_msgData() → bytes internal` 12 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/Create2.md: -------------------------------------------------------------------------------- 1 | # `Create2` 2 | 3 | Helper to make usage of the `CREATE2` EVM opcode easier and safer. 4 | 5 | `CREATE2` can be used to compute in advance the address where a smart 6 | 7 | contract will be deployed, which allows for interesting new mechanisms known 8 | 9 | as 'counterfactual interactions'. 10 | 11 | See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more 12 | 13 | information. 14 | 15 | ## Functions: 16 | 17 | - `deploy(uint256 amount, bytes32 salt, bytes bytecode) (internal)` 18 | 19 | - `computeAddress(bytes32 salt, bytes32 bytecodeHash) (internal)` 20 | 21 | - `computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) (internal)` 22 | 23 | ### Function `deploy(uint256 amount, bytes32 salt, bytes bytecode) → address internal` 24 | 25 | Deploys a contract using `CREATE2`. The address where the contract 26 | 27 | will be deployed can be known in advance via {computeAddress}. 28 | 29 | The bytecode for a contract can be obtained from Solidity with 30 | 31 | `type(contractName).creationCode`. 32 | 33 | Requirements: 34 | 35 | - `bytecode` must not be empty. 36 | 37 | - `salt` must have not been used for `bytecode` already. 38 | 39 | - the factory must have a balance of at least `amount`. 40 | 41 | - if `amount` is non-zero, `bytecode` must have a `payable` constructor. 42 | 43 | ### Function `computeAddress(bytes32 salt, bytes32 bytecodeHash) → address internal` 44 | 45 | Returns the address where a contract will be stored if deployed via {deploy}. Any change in the 46 | 47 | `bytecodeHash` or `salt` will result in a new destination address. 48 | 49 | ### Function `computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) → address internal` 50 | 51 | Returns the address where a contract will be stored if deployed via {deploy} from a contract located at 52 | 53 | `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}. 54 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/Ownable.md: -------------------------------------------------------------------------------- 1 | # `Ownable` 2 | 3 | Contract module which provides a basic access control mechanism, where 4 | 5 | there is an account (an owner) that can be granted exclusive access to 6 | 7 | specific functions. 8 | 9 | By default, the owner account will be the one that deploys the contract. This 10 | 11 | can later be changed with {transferOwnership}. 12 | 13 | This module is used through inheritance. It will make available the modifier 14 | 15 | `onlyOwner`, which can be applied to your functions to restrict their use to 16 | 17 | the owner. 18 | 19 | ## Modifiers: 20 | 21 | - `onlyOwner()` 22 | 23 | ## Functions: 24 | 25 | - `constructor() (internal)` 26 | 27 | - `owner() (public)` 28 | 29 | - `renounceOwnership() (public)` 30 | 31 | - `transferOwnership(address newOwner) (public)` 32 | 33 | ## Events: 34 | 35 | - `OwnershipTransferred(address previousOwner, address newOwner)` 36 | 37 | ### Modifier `onlyOwner()` 38 | 39 | Throws if called by any account other than the owner. 40 | 41 | ### Function `constructor() internal` 42 | 43 | Initializes the contract setting the deployer as the initial owner. 44 | 45 | ### Function `owner() → address public` 46 | 47 | Returns the address of the current owner. 48 | 49 | ### Function `renounceOwnership() public` 50 | 51 | Leaves the contract without owner. It will not be possible to call 52 | 53 | `onlyOwner` functions anymore. Can only be called by the current owner. 54 | 55 | NOTE: Renouncing ownership will leave the contract without an owner, 56 | 57 | thereby removing any functionality that is only available to the owner. 58 | 59 | ### Function `transferOwnership(address newOwner) public` 60 | 61 | Transfers ownership of the contract to a new account (`newOwner`). 62 | 63 | Can only be called by the current owner. 64 | 65 | ### Event `OwnershipTransferred(address previousOwner, address newOwner)` 66 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/ReentrancyGuard.md: -------------------------------------------------------------------------------- 1 | # `ReentrancyGuard` 2 | 3 | Contract module that helps prevent reentrant calls to a function. 4 | 5 | Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier 6 | 7 | available, which can be applied to functions to make sure there are no nested 8 | 9 | (reentrant) calls to them. 10 | 11 | Note that because there is a single `nonReentrant` guard, functions marked as 12 | 13 | `nonReentrant` may not call one another. This can be worked around by making 14 | 15 | those functions `private`, and then adding `external` `nonReentrant` entry 16 | 17 | points to them. 18 | 19 | TIP: If you would like to learn more about reentrancy and alternative ways 20 | 21 | to protect against it, check out our blog post 22 | 23 | https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. 24 | 25 | ## Modifiers: 26 | 27 | - `nonReentrant()` 28 | 29 | ## Functions: 30 | 31 | - `constructor() (internal)` 32 | 33 | ### Modifier `nonReentrant()` 34 | 35 | Prevents a contract from calling itself, directly or indirectly. 36 | 37 | Calling a `nonReentrant` function from another `nonReentrant` 38 | 39 | function is not supported. It is possible to prevent this from happening 40 | 41 | by making the `nonReentrant` function external, and make it call a 42 | 43 | `private` function that does the actual work. 44 | 45 | ### Function `constructor() internal` 46 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/SafeERC20.md: -------------------------------------------------------------------------------- 1 | # `SafeERC20` 2 | 3 | Wrappers around ERC20 operations that throw on failure (when the token 4 | 5 | contract returns false). Tokens that return no value (and instead revert or 6 | 7 | throw on failure) are also supported, non-reverting calls are assumed to be 8 | 9 | successful. 10 | 11 | To use this library you can add a `using SafeERC20 for ERC20Interface;` statement to your contract, 12 | 13 | which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 14 | 15 | ## Functions: 16 | 17 | - `safeTransfer(contract ERC20Interface token, address to, uint256 value) (internal)` 18 | 19 | - `safeTransferFrom(contract ERC20Interface token, address from, address to, uint256 value) (internal)` 20 | 21 | - `safeApprove(contract ERC20Interface token, address spender, uint256 value) (internal)` 22 | 23 | - `safeIncreaseAllowance(contract ERC20Interface token, address spender, uint256 value) (internal)` 24 | 25 | - `safeDecreaseAllowance(contract ERC20Interface token, address spender, uint256 value) (internal)` 26 | 27 | ### Function `safeTransfer(contract ERC20Interface token, address to, uint256 value) internal` 28 | 29 | ### Function `safeTransferFrom(contract ERC20Interface token, address from, address to, uint256 value) internal` 30 | 31 | ### Function `safeApprove(contract ERC20Interface token, address spender, uint256 value) internal` 32 | 33 | Deprecated. This function has issues similar to the ones found in 34 | 35 | {ERC20Interface-approve}, and its usage is discouraged. 36 | 37 | Whenever possible, use {safeIncreaseAllowance} and 38 | 39 | {safeDecreaseAllowance} instead. 40 | 41 | ### Function `safeIncreaseAllowance(contract ERC20Interface token, address spender, uint256 value) internal` 42 | 43 | ### Function `safeDecreaseAllowance(contract ERC20Interface token, address spender, uint256 value) internal` 44 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/SignedSafeMath.md: -------------------------------------------------------------------------------- 1 | # `SignedSafeMath` 2 | 3 | Signed math operations with safety checks that revert on error. 4 | 5 | ## Functions: 6 | 7 | - `mul(int256 a, int256 b) (internal)` 8 | 9 | - `div(int256 a, int256 b) (internal)` 10 | 11 | - `sub(int256 a, int256 b) (internal)` 12 | 13 | - `add(int256 a, int256 b) (internal)` 14 | 15 | ### Function `mul(int256 a, int256 b) → int256 internal` 16 | 17 | Returns the multiplication of two signed integers, reverting on 18 | 19 | overflow. 20 | 21 | Counterpart to Solidity's `*` operator. 22 | 23 | Requirements: 24 | 25 | - Multiplication cannot overflow. 26 | 27 | ### Function `div(int256 a, int256 b) → int256 internal` 28 | 29 | Returns the integer division of two signed integers. Reverts on 30 | 31 | division by zero. The result is rounded towards zero. 32 | 33 | Counterpart to Solidity's `/` operator. Note: this function uses a 34 | 35 | `revert` opcode (which leaves remaining gas untouched) while Solidity 36 | 37 | uses an invalid opcode to revert (consuming all remaining gas). 38 | 39 | Requirements: 40 | 41 | - The divisor cannot be zero. 42 | 43 | ### Function `sub(int256 a, int256 b) → int256 internal` 44 | 45 | Returns the subtraction of two signed integers, reverting on 46 | 47 | overflow. 48 | 49 | Counterpart to Solidity's `-` operator. 50 | 51 | Requirements: 52 | 53 | - Subtraction cannot overflow. 54 | 55 | ### Function `add(int256 a, int256 b) → int256 internal` 56 | 57 | Returns the addition of two signed integers, reverting on 58 | 59 | overflow. 60 | 61 | Counterpart to Solidity's `+` operator. 62 | 63 | Requirements: 64 | 65 | - Addition cannot overflow. 66 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/Strings.md: -------------------------------------------------------------------------------- 1 | # `Strings` 2 | 3 | String operations. 4 | 5 | ## Functions: 6 | 7 | - `toString(uint256 value) (internal)` 8 | 9 | ### Function `toString(uint256 value) → string internal` 10 | 11 | Converts a `uint256` to its ASCII `string` representation. 12 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/GSN/ContextUpgradeable.md: -------------------------------------------------------------------------------- 1 | # `ContextUpgradeable` 2 | 3 | ## Functions: 4 | 5 | - `__Context_init() (internal)` 6 | 7 | - `__Context_init_unchained() (internal)` 8 | 9 | - `_msgSender() (internal)` 10 | 11 | - `_msgData() (internal)` 12 | 13 | ### Function `__Context_init() internal` 14 | 15 | ### Function `__Context_init_unchained() internal` 16 | 17 | ### Function `_msgSender() → address payable internal` 18 | 19 | ### Function `_msgData() → bytes internal` 20 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/Initializable.md: -------------------------------------------------------------------------------- 1 | # `Initializable` 2 | 3 | Helper contract to support initializer functions. To use it, replace 4 | 5 | the constructor with a function that has the `initializer` modifier. 6 | 7 | WARNING: Unlike constructors, initializer functions must be manually 8 | 9 | invoked. This applies both to deploying an Initializable contract, as well 10 | 11 | as extending an Initializable contract via inheritance. 12 | 13 | WARNING: When used with inheritance, manual care must be taken to not invoke 14 | 15 | a parent initializer twice, or ensure that all initializers are idempotent, 16 | 17 | because this is not dealt with automatically as with constructors. 18 | 19 | ## Modifiers: 20 | 21 | - `initializer()` 22 | 23 | ### Modifier `initializer()` 24 | 25 | Modifier to use in the initializer function of a contract. 26 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/OwnableUpgradeSafe.md: -------------------------------------------------------------------------------- 1 | # `OwnableUpgradeSafe` 2 | 3 | Contract module which provides a basic access control mechanism, where 4 | 5 | there is an account (an owner) that can be granted exclusive access to 6 | 7 | specific functions. 8 | 9 | By default, the owner account will be the one that deploys the contract. This 10 | 11 | can later be changed with {transferOwnership}. 12 | 13 | This module is used through inheritance. It will make available the modifier 14 | 15 | `onlyOwner`, which can be applied to your functions to restrict their use to 16 | 17 | the owner. 18 | 19 | ## Modifiers: 20 | 21 | - `onlyOwner()` 22 | 23 | ## Functions: 24 | 25 | - `__Ownable_init(address _sender) (internal)` 26 | 27 | - `__Ownable_init_unchained(address _sender) (internal)` 28 | 29 | - `owner() (public)` 30 | 31 | - `renounceOwnership() (public)` 32 | 33 | - `transferOwnership(address newOwner) (public)` 34 | 35 | ## Events: 36 | 37 | - `OwnershipTransferred(address previousOwner, address newOwner)` 38 | 39 | ### Modifier `onlyOwner()` 40 | 41 | Throws if called by any account other than the owner. 42 | 43 | ### Function `__Ownable_init(address _sender) internal` 44 | 45 | Initializes the contract setting the deployer as the initial owner. 46 | 47 | ### Function `__Ownable_init_unchained(address _sender) internal` 48 | 49 | ### Function `owner() → address public` 50 | 51 | Returns the address of the current owner. 52 | 53 | ### Function `renounceOwnership() public` 54 | 55 | Leaves the contract without owner. It will not be possible to call 56 | 57 | `onlyOwner` functions anymore. Can only be called by the current owner. 58 | 59 | NOTE: Renouncing ownership will leave the contract without an owner, 60 | 61 | thereby removing any functionality that is only available to the owner. 62 | 63 | ### Function `transferOwnership(address newOwner) public` 64 | 65 | Transfers ownership of the contract to a new account (`newOwner`). 66 | 67 | Can only be called by the current owner. 68 | 69 | ### Event `OwnershipTransferred(address previousOwner, address newOwner)` 70 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/OwnedUpgradeabilityProxy.md: -------------------------------------------------------------------------------- 1 | # `OwnedUpgradeabilityProxy` 2 | 3 | This contract combines an upgradeability proxy with basic authorization control functionalities 4 | 5 | ## Modifiers: 6 | 7 | - `onlyProxyOwner()` 8 | 9 | ## Functions: 10 | 11 | - `constructor() (public)` 12 | 13 | - `proxyOwner() (public)` 14 | 15 | - `setUpgradeabilityOwner(address _newProxyOwner) (internal)` 16 | 17 | - `transferProxyOwnership(address _newOwner) (public)` 18 | 19 | - `upgradeTo(address _implementation) (public)` 20 | 21 | - `upgradeToAndCall(address _implementation, bytes _data) (public)` 22 | 23 | ## Events: 24 | 25 | - `ProxyOwnershipTransferred(address previousOwner, address newOwner)` 26 | 27 | ### Modifier `onlyProxyOwner()` 28 | 29 | Throws if called by any account other than the owner. 30 | 31 | ### Function `constructor() public` 32 | 33 | the constructor sets the original owner of the contract to the sender account. 34 | 35 | ### Function `proxyOwner() → address owner public` 36 | 37 | Tells the address of the owner 38 | 39 | #### Return Values: 40 | 41 | - owner the address of the owner 42 | 43 | ### Function `setUpgradeabilityOwner(address _newProxyOwner) internal` 44 | 45 | Sets the address of the owner 46 | 47 | #### Parameters: 48 | 49 | - `_newProxyOwner`: address of new proxy owner 50 | 51 | ### Function `transferProxyOwnership(address _newOwner) public` 52 | 53 | Allows the current owner to transfer control of the contract to a newOwner. 54 | 55 | #### Parameters: 56 | 57 | - `_newOwner`: The address to transfer ownership to. 58 | 59 | ### Function `upgradeTo(address _implementation) public` 60 | 61 | Allows the proxy owner to upgrade the current version of the proxy. 62 | 63 | #### Parameters: 64 | 65 | - `_implementation`: representing the address of the new implementation to be set. 66 | 67 | ### Function `upgradeToAndCall(address _implementation, bytes _data) public` 68 | 69 | Allows the proxy owner to upgrade the current version of the proxy and call the new implementation 70 | 71 | to initialize whatever is needed through a low level call. 72 | 73 | #### Parameters: 74 | 75 | - `_implementation`: representing the address of the new implementation to be set. 76 | 77 | - `_data`: represents the msg.data to bet sent in the low level call. This parameter may include the function 78 | 79 | signature of the implementation to be called with the needed payload 80 | 81 | ### Event `ProxyOwnershipTransferred(address previousOwner, address newOwner)` 82 | 83 | Event to show ownership has been transferred 84 | 85 | #### Parameters: 86 | 87 | - `previousOwner`: representing the address of the previous owner 88 | 89 | - `newOwner`: representing the address of the new owner 90 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/Proxy.md: -------------------------------------------------------------------------------- 1 | # `Proxy` 2 | 3 | Gives the possibility to delegate any call to a foreign implementation. 4 | 5 | ## Functions: 6 | 7 | - `implementation() (public)` 8 | 9 | - `fallback() (external)` 10 | 11 | ### Function `implementation() → address public` 12 | 13 | Tells the address of the implementation where every call will be delegated. 14 | 15 | #### Return Values: 16 | 17 | - address of the implementation to which it will be delegated 18 | 19 | ### Function `fallback() external` 20 | 21 | Fallback function allowing to perform a delegatecall to the given implementation. 22 | 23 | This function will return whatever the implementation call returns 24 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/ReentrancyGuardUpgradeSafe.md: -------------------------------------------------------------------------------- 1 | # `ReentrancyGuardUpgradeSafe` 2 | 3 | Contract module that helps prevent reentrant calls to a function. 4 | 5 | Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier 6 | 7 | available, which can be applied to functions to make sure there are no nested 8 | 9 | (reentrant) calls to them. 10 | 11 | Note that because there is a single `nonReentrant` guard, functions marked as 12 | 13 | `nonReentrant` may not call one another. This can be worked around by making 14 | 15 | those functions `private`, and then adding `external` `nonReentrant` entry 16 | 17 | points to them. 18 | 19 | TIP: If you would like to learn more about reentrancy and alternative ways 20 | 21 | to protect against it, check out our blog post 22 | 23 | https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. 24 | 25 | ## Modifiers: 26 | 27 | - `nonReentrant()` 28 | 29 | ## Functions: 30 | 31 | - `__ReentrancyGuard_init() (internal)` 32 | 33 | - `__ReentrancyGuard_init_unchained() (internal)` 34 | 35 | ### Modifier `nonReentrant()` 36 | 37 | Prevents a contract from calling itself, directly or indirectly. 38 | 39 | Calling a `nonReentrant` function from another `nonReentrant` 40 | 41 | function is not supported. It is possible to prevent this from happening 42 | 43 | by making the `nonReentrant` function external, and make it call a 44 | 45 | `private` function that does the actual work. 46 | 47 | ### Function `__ReentrancyGuard_init() internal` 48 | 49 | ### Function `__ReentrancyGuard_init_unchained() internal` 50 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/UpgradeabilityProxy.md: -------------------------------------------------------------------------------- 1 | # `UpgradeabilityProxy` 2 | 3 | This contract represents a proxy where the implementation address to which it will delegate can be upgraded 4 | 5 | ## Functions: 6 | 7 | - `implementation() (public)` 8 | 9 | - `setImplementation(address _newImplementation) (internal)` 10 | 11 | - `_upgradeTo(address _newImplementation) (internal)` 12 | 13 | ## Events: 14 | 15 | - `Upgraded(address implementation)` 16 | 17 | ### Function `implementation() → address impl public` 18 | 19 | Tells the address of the current implementation 20 | 21 | #### Return Values: 22 | 23 | - impl address of the current implementation 24 | 25 | ### Function `setImplementation(address _newImplementation) internal` 26 | 27 | Sets the address of the current implementation 28 | 29 | #### Parameters: 30 | 31 | - `_newImplementation`: address representing the new implementation to be set 32 | 33 | ### Function `_upgradeTo(address _newImplementation) internal` 34 | 35 | Upgrades the implementation address 36 | 37 | #### Parameters: 38 | 39 | - `_newImplementation`: representing the address of the new implementation to be set 40 | 41 | ### Event `Upgraded(address implementation)` 42 | 43 | This event will be emitted every time the implementation gets upgraded 44 | 45 | #### Parameters: 46 | 47 | - `implementation`: representing the address of the upgraded implementation 48 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/cryptography/ECDSAUpgradeable.md: -------------------------------------------------------------------------------- 1 | # `ECDSAUpgradeable` 2 | 3 | Elliptic Curve Digital Signature Algorithm (ECDSA) operations. 4 | 5 | These functions can be used to verify that a message was signed by the holder 6 | 7 | of the private keys of a given address. 8 | 9 | ## Functions: 10 | 11 | - `recover(bytes32 hash, bytes signature) (internal)` 12 | 13 | - `recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) (internal)` 14 | 15 | - `toEthSignedMessageHash(bytes32 hash) (internal)` 16 | 17 | ### Function `recover(bytes32 hash, bytes signature) → address internal` 18 | 19 | Returns the address that signed a hashed message (`hash`) with 20 | 21 | `signature`. This address can then be used for verification purposes. 22 | 23 | The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: 24 | 25 | this function rejects them by requiring the `s` value to be in the lower 26 | 27 | half order, and the `v` value to be either 27 or 28. 28 | 29 | IMPORTANT: `hash` _must_ be the result of a hash operation for the 30 | 31 | verification to be secure: it is possible to craft signatures that 32 | 33 | recover to arbitrary addresses for non-hashed data. A safe way to ensure 34 | 35 | this is by receiving a hash of the original message (which may otherwise 36 | 37 | be too long), and then calling {toEthSignedMessageHash} on it. 38 | 39 | ### Function `recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) → address internal` 40 | 41 | Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`, 42 | 43 | `r` and `s` signature fields separately. 44 | 45 | ### Function `toEthSignedMessageHash(bytes32 hash) → bytes32 internal` 46 | 47 | Returns an Ethereum Signed Message, created from a `hash`. This 48 | 49 | replicates the behavior of the 50 | 51 | https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`] 52 | 53 | JSON-RPC method. 54 | 55 | See {recover}. 56 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/erc20-permit/ERC20PermitUpgradeable.md: -------------------------------------------------------------------------------- 1 | # `ERC20PermitUpgradeable` 2 | 3 | Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in 4 | 5 | https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. 6 | 7 | Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by 8 | 9 | presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't 10 | 11 | need to send a transaction, and thus is not required to hold Ether at all. 12 | 13 | ## Functions: 14 | 15 | - `__ERC20Permit_init(string name) (internal)` 16 | 17 | - `__ERC20Permit_init_unchained(string name) (internal)` 18 | 19 | - `permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) (public)` 20 | 21 | - `nonces(address owner) (public)` 22 | 23 | - `DOMAIN_SEPARATOR() (external)` 24 | 25 | ### Function `__ERC20Permit_init(string name) internal` 26 | 27 | Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. 28 | 29 | It's a good idea to use the same `name` that is defined as the ERC20 token name. 30 | 31 | ### Function `__ERC20Permit_init_unchained(string name) internal` 32 | 33 | ### Function `permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public` 34 | 35 | See {IERC20Permit-permit}. 36 | 37 | ### Function `nonces(address owner) → uint256 public` 38 | 39 | See {IERC20Permit-nonces}. 40 | 41 | ### Function `DOMAIN_SEPARATOR() → bytes32 external` 42 | 43 | See {IERC20Permit-DOMAIN_SEPARATOR}. 44 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/erc20-permit/IERC20PermitUpgradeable.md: -------------------------------------------------------------------------------- 1 | # `IERC20PermitUpgradeable` 2 | 3 | Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in 4 | 5 | https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. 6 | 7 | Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by 8 | 9 | presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't 10 | 11 | need to send a transaction, and thus is not required to hold Ether at all. 12 | 13 | ## Functions: 14 | 15 | - `permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) (external)` 16 | 17 | - `nonces(address owner) (external)` 18 | 19 | - `DOMAIN_SEPARATOR() (external)` 20 | 21 | ### Function `permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external` 22 | 23 | Sets `amount` as the allowance of `spender` over `owner`'s tokens, 24 | 25 | given `owner`'s signed approval. 26 | 27 | IMPORTANT: The same issues {IERC20-approve} has related to transaction 28 | 29 | ordering also apply here. 30 | 31 | Emits an {Approval} event. 32 | 33 | Requirements: 34 | 35 | - `spender` cannot be the zero address. 36 | 37 | - `deadline` must be a timestamp in the future. 38 | 39 | - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` 40 | 41 | over the EIP712-formatted function arguments. 42 | 43 | - the signature must use ``owner``'s current nonce (see {nonces}). 44 | 45 | For more information on the signature format, see the 46 | 47 | https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP 48 | 49 | section]. 50 | 51 | ### Function `nonces(address owner) → uint256 external` 52 | 53 | Returns the current nonce for `owner`. This value must be 54 | 55 | included whenever a signature is generated for {permit}. 56 | 57 | Every successful call to {permit} increases ``owner``'s nonce by one. This 58 | 59 | prevents a signature from being used multiple times. 60 | 61 | ### Function `DOMAIN_SEPARATOR() → bytes32 external` 62 | 63 | Returns the domain separator used in the encoding of the signature for `permit`, as defined by {EIP712}. 64 | -------------------------------------------------------------------------------- /docs/contracts-documentation/packages/oz/upgradeability/utils/CountersUpgradeable.md: -------------------------------------------------------------------------------- 1 | # `CountersUpgradeable` 2 | 3 | Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number 4 | 5 | of elements in a mapping, issuing ERC721 ids, or counting request ids. 6 | 7 | Include with `using Counters for Counters.Counter;` 8 | 9 | Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath} 10 | 11 | overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never 12 | 13 | directly accessed. 14 | 15 | ## Functions: 16 | 17 | - `current(struct CountersUpgradeable.Counter counter) (internal)` 18 | 19 | - `increment(struct CountersUpgradeable.Counter counter) (internal)` 20 | 21 | - `decrement(struct CountersUpgradeable.Counter counter) (internal)` 22 | 23 | ### Function `current(struct CountersUpgradeable.Counter counter) → uint256 internal` 24 | 25 | ### Function `increment(struct CountersUpgradeable.Counter counter) internal` 26 | 27 | ### Function `decrement(struct CountersUpgradeable.Counter counter) internal` 28 | -------------------------------------------------------------------------------- /docs/contracts-documentation/pricers/ChainLinkPricer.md: -------------------------------------------------------------------------------- 1 | # `ChainLinkPricer` 2 | 3 | A Pricer contract for one asset as reported by Chainlink 4 | 5 | ## Modifiers: 6 | 7 | - `onlyBot()` 8 | 9 | ## Functions: 10 | 11 | - `constructor(address _bot, address _asset, address _aggregator, address _oracle) (public)` 12 | 13 | - `setExpiryPriceInOracle(uint256 _expiryTimestamp, uint80 _roundId) (external)` 14 | 15 | - `getPrice() (external)` 16 | 17 | - `getHistoricalPrice(uint80 _roundId) (external)` 18 | 19 | - `_scaleToBase(uint256 _price) (internal)` 20 | 21 | ### Modifier `onlyBot()` 22 | 23 | modifier to check if sender address is equal to bot address 24 | 25 | ### Function `constructor(address _bot, address _asset, address _aggregator, address _oracle) public` 26 | 27 | #### Parameters: 28 | 29 | - `_bot`: priveleged address that can call setExpiryPriceInOracle 30 | 31 | - `_asset`: asset that this pricer will get a price for 32 | 33 | - `_aggregator`: Chainlink aggregator contract for the asset 34 | 35 | - `_oracle`: Opyn Oracle address 36 | 37 | ### Function `setExpiryPriceInOracle(uint256 _expiryTimestamp, uint80 _roundId) external` 38 | 39 | set the expiry price in the oracle, can only be called by Bot address 40 | 41 | a roundId must be provided to confirm price validity, which is the first Chainlink price provided after the expiryTimestamp 42 | 43 | #### Parameters: 44 | 45 | - `_expiryTimestamp`: expiry to set a price for 46 | 47 | - `_roundId`: the first roundId after expiryTimestamp 48 | 49 | ### Function `getPrice() → uint256 external` 50 | 51 | get the live price for the asset 52 | 53 | overides the getPrice function in OpynPricerInterface 54 | 55 | #### Return Values: 56 | 57 | - price of the asset in USD, scaled by 1e8 58 | 59 | ### Function `getHistoricalPrice(uint80 _roundId) → uint256, uint256 external` 60 | 61 | get historical chainlink price 62 | 63 | #### Parameters: 64 | 65 | - `_roundId`: chainlink round id 66 | 67 | #### Return Values: 68 | 69 | - round price and timestamp 70 | 71 | ### Function `_scaleToBase(uint256 _price) → uint256 internal` 72 | 73 | scale aggregator response to base decimals (1e8) 74 | 75 | #### Parameters: 76 | 77 | - `_price`: aggregator price 78 | 79 | #### Return Values: 80 | 81 | - price scaled to 1e8 82 | -------------------------------------------------------------------------------- /docs/contracts-documentation/pricers/CompoundPricer.md: -------------------------------------------------------------------------------- 1 | # `CompoundPricer` 2 | 3 | A Pricer contract for a Compound cToken 4 | 5 | ## Functions: 6 | 7 | - `constructor(address _cToken, address _underlying, address _oracle) (public)` 8 | 9 | - `getPrice() (external)` 10 | 11 | - `setExpiryPriceInOracle(uint256 _expiryTimestamp) (external)` 12 | 13 | - `_underlyingPriceToCtokenPrice(uint256 _underlyingPrice) (internal)` 14 | 15 | ### Function `constructor(address _cToken, address _underlying, address _oracle) public` 16 | 17 | #### Parameters: 18 | 19 | - `_cToken`: cToken asset 20 | 21 | - `_underlying`: underlying asset for this cToken 22 | 23 | - `_oracle`: Opyn Oracle contract address 24 | 25 | ### Function `getPrice() → uint256 external` 26 | 27 | get the live price for the asset 28 | 29 | #### Return Values: 30 | 31 | - price of 1e8 cToken in USD, scaled by 1e8 32 | 33 | ### Function `setExpiryPriceInOracle(uint256 _expiryTimestamp) external` 34 | 35 | set the expiry price in the oracle 36 | 37 | requires that the underlying price has been set before setting a cToken price 38 | 39 | #### Parameters: 40 | 41 | - `_expiryTimestamp`: expiry to set a price for 42 | 43 | ### Function `_underlyingPriceToCtokenPrice(uint256 _underlyingPrice) → uint256 internal` 44 | 45 | convert underlying price to cToken price with the cToken to underlying exchange rate 46 | 47 | #### Parameters: 48 | 49 | - `_underlyingPrice`: price of 1 underlying token (ie 1e6 USDC, 1e18 WETH) in USD, scaled by 1e8 50 | 51 | #### Return Values: 52 | 53 | - price of 1e8 cToken in USD, scaled by 1e8 54 | -------------------------------------------------------------------------------- /docs/contracts-documentation/pricers/WstethPricer.md: -------------------------------------------------------------------------------- 1 | # `WstethPricer` 2 | 3 | A Pricer contract for a wstETH token 4 | 5 | ## Functions: 6 | 7 | - `constructor(address _wstETH, address _underlying, address _oracle) (public)` 8 | 9 | - `getPrice() (external)` 10 | 11 | - `setExpiryPriceInOracle(uint256 _expiryTimestamp) (external)` 12 | 13 | - `getHistoricalPrice(uint80) (external)` 14 | 15 | ### Function `constructor(address _wstETH, address _underlying, address _oracle) public` 16 | 17 | #### Parameters: 18 | 19 | - `_wstETH`: wstETH 20 | 21 | - `_underlying`: underlying asset for wstETH 22 | 23 | - `_oracle`: Opyn Oracle contract address 24 | 25 | ### Function `getPrice() → uint256 external` 26 | 27 | get the live price for the asset 28 | 29 | overrides the getPrice function in OpynPricerInterface 30 | 31 | #### Return Values: 32 | 33 | - price of 1 wstETH in USD, scaled by 1e8 34 | 35 | ### Function `setExpiryPriceInOracle(uint256 _expiryTimestamp) external` 36 | 37 | set the expiry price in the oracle 38 | 39 | requires that the underlying price has been set before setting a wstETH price 40 | 41 | #### Parameters: 42 | 43 | - `_expiryTimestamp`: expiry to set a price for 44 | 45 | ### Function `getHistoricalPrice(uint80) → uint256, uint256 external` 46 | -------------------------------------------------------------------------------- /docs/contracts-documentation/pricers/YearnPricer.md: -------------------------------------------------------------------------------- 1 | # `YearnPricer` 2 | 3 | A Pricer contract for a Yearn yToken 4 | 5 | ## Functions: 6 | 7 | - `constructor(address _yToken, address _underlying, address _oracle) (public)` 8 | 9 | - `getPrice() (external)` 10 | 11 | - `setExpiryPriceInOracle(uint256 _expiryTimestamp) (external)` 12 | 13 | - `getHistoricalPrice(uint80 _roundId) (external)` 14 | 15 | ### Function `constructor(address _yToken, address _underlying, address _oracle) public` 16 | 17 | #### Parameters: 18 | 19 | - `_yToken`: yToken asset 20 | 21 | - `_underlying`: underlying asset for this yToken 22 | 23 | - `_oracle`: Opyn Oracle contract address 24 | 25 | ### Function `getPrice() → uint256 external` 26 | 27 | get the live price for the asset 28 | 29 | overrides the getPrice function in OpynPricerInterface 30 | 31 | #### Return Values: 32 | 33 | - price of 1e8 yToken in USD, scaled by 1e8 34 | 35 | ### Function `setExpiryPriceInOracle(uint256 _expiryTimestamp) external` 36 | 37 | set the expiry price in the oracle 38 | 39 | requires that the underlying price has been set before setting a yToken price 40 | 41 | #### Parameters: 42 | 43 | - `_expiryTimestamp`: expiry to set a price for 44 | 45 | ### Function `getHistoricalPrice(uint80 _roundId) → uint256, uint256 external` 46 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/ActionTester.md: -------------------------------------------------------------------------------- 1 | # `ActionTester` 2 | 3 | ## Functions: 4 | 5 | - `testParseDespositAction(struct Actions.ActionArgs _args) (external)` 6 | 7 | - `getDepositArgs() (external)` 8 | 9 | - `testParseWithdrawAction(struct Actions.ActionArgs _args) (external)` 10 | 11 | - `getWithdrawArgs() (external)` 12 | 13 | - `testParseOpenVaultAction(struct Actions.ActionArgs _args) (external)` 14 | 15 | - `getOpenVaultArgs() (external)` 16 | 17 | - `testParseRedeemAction(struct Actions.ActionArgs _args) (external)` 18 | 19 | - `getRedeemArgs() (external)` 20 | 21 | - `testParseSettleVaultAction(struct Actions.ActionArgs _args) (external)` 22 | 23 | - `testParseLiquidateActions(struct Actions.ActionArgs _args) (external)` 24 | 25 | - `getSettleVaultArgs() (external)` 26 | 27 | - `testParseMintAction(struct Actions.ActionArgs _args) (external)` 28 | 29 | - `getMintArgs() (external)` 30 | 31 | - `testParseBurnAction(struct Actions.ActionArgs _args) (external)` 32 | 33 | - `getBurnArgs() (external)` 34 | 35 | - `testParseCallAction(struct Actions.ActionArgs _args) (external)` 36 | 37 | - `getCallArgs() (external)` 38 | 39 | - `getLiquidateArgs() (external)` 40 | 41 | ### Function `testParseDespositAction(struct Actions.ActionArgs _args) external` 42 | 43 | ### Function `getDepositArgs() → struct Actions.DepositArgs external` 44 | 45 | ### Function `testParseWithdrawAction(struct Actions.ActionArgs _args) external` 46 | 47 | ### Function `getWithdrawArgs() → struct Actions.WithdrawArgs external` 48 | 49 | ### Function `testParseOpenVaultAction(struct Actions.ActionArgs _args) external` 50 | 51 | ### Function `getOpenVaultArgs() → struct Actions.OpenVaultArgs external` 52 | 53 | ### Function `testParseRedeemAction(struct Actions.ActionArgs _args) external` 54 | 55 | ### Function `getRedeemArgs() → struct Actions.RedeemArgs external` 56 | 57 | ### Function `testParseSettleVaultAction(struct Actions.ActionArgs _args) external` 58 | 59 | ### Function `testParseLiquidateActions(struct Actions.ActionArgs _args) external` 60 | 61 | ### Function `getSettleVaultArgs() → struct Actions.SettleVaultArgs external` 62 | 63 | ### Function `testParseMintAction(struct Actions.ActionArgs _args) external` 64 | 65 | ### Function `getMintArgs() → struct Actions.MintArgs external` 66 | 67 | ### Function `testParseBurnAction(struct Actions.ActionArgs _args) external` 68 | 69 | ### Function `getBurnArgs() → struct Actions.BurnArgs external` 70 | 71 | ### Function `testParseCallAction(struct Actions.ActionArgs _args) external` 72 | 73 | ### Function `getCallArgs() → struct Actions.CallArgs external` 74 | 75 | ### Function `getLiquidateArgs() → struct Actions.LiquidateArgs external` 76 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/CalculatorTester.md: -------------------------------------------------------------------------------- 1 | # `CalculatorTester` 2 | 3 | ## Functions: 4 | 5 | - `constructor(address _addressBook) (public)` 6 | 7 | - `getExpiredCashValue(address _underlying, address _strike, uint256 _expiryTimestamp, uint256 _strikePrice, bool _isPut) (external)` 8 | 9 | - `findUpperBoundValue(address _underlying, address _strike, address _collateral, bool _isPut, uint256 _expiryTimestamp) (external)` 10 | 11 | - `price(uint256 _vaultCollateral, uint256 _vaultDebt, uint256 _cv, uint256 _spotPrice, uint256 _auctionStartingTime, uint256 _collateralDecimals, bool _isPut) (external)` 12 | 13 | ### Function `constructor(address _addressBook) public` 14 | 15 | ### Function `getExpiredCashValue(address _underlying, address _strike, uint256 _expiryTimestamp, uint256 _strikePrice, bool _isPut) → uint256 external` 16 | 17 | ### Function `findUpperBoundValue(address _underlying, address _strike, address _collateral, bool _isPut, uint256 _expiryTimestamp) → uint256 external` 18 | 19 | ### Function `price(uint256 _vaultCollateral, uint256 _vaultDebt, uint256 _cv, uint256 _spotPrice, uint256 _auctionStartingTime, uint256 _collateralDecimals, bool _isPut) → uint256 external` 20 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/CallTester.md: -------------------------------------------------------------------------------- 1 | # `CallTester` 2 | 3 | Call action testing contract 4 | 5 | ## Functions: 6 | 7 | - `callFunction(address _sender, bytes _data) (external)` 8 | 9 | ## Events: 10 | 11 | - `CallFunction(address sender, bytes data)` 12 | 13 | ### Function `callFunction(address _sender, bytes _data) external` 14 | 15 | ### Event `CallFunction(address sender, bytes data)` 16 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/CalleeAllowanceTester.md: -------------------------------------------------------------------------------- 1 | # `CalleeAllowanceTester` 2 | 3 | contract test if we can successfully pull weth from the payable proxy 4 | 5 | ## Functions: 6 | 7 | - `constructor(address _weth) (public)` 8 | 9 | - `callFunction(address payable, bytes _data) (external)` 10 | 11 | ### Function `constructor(address _weth) public` 12 | 13 | ### Function `callFunction(address payable, bytes _data) external` 14 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/FlashUnwrap.md: -------------------------------------------------------------------------------- 1 | # `FlashUnwrap` 2 | 3 | contract To unwrap WETH. This is just a contract to test the Call action 4 | 5 | ## Functions: 6 | 7 | - `constructor(address payable weth) (public)` 8 | 9 | - `receive() (external)` 10 | 11 | - `callFunction(address payable _sender, bytes _data) (external)` 12 | 13 | ## Events: 14 | 15 | - `WrappedETH(address to, uint256 amount)` 16 | 17 | - `UnwrappedETH(address to, uint256 amount)` 18 | 19 | ### Function `constructor(address payable weth) public` 20 | 21 | ### Function `receive() external` 22 | 23 | ### Function `callFunction(address payable _sender, bytes _data) external` 24 | 25 | ### Event `WrappedETH(address to, uint256 amount)` 26 | 27 | ### Event `UnwrappedETH(address to, uint256 amount)` 28 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/MarginVaultTester.md: -------------------------------------------------------------------------------- 1 | # `MarginVaultTester` 2 | 3 | ## Functions: 4 | 5 | - `getVault(uint256 _vaultIndex) (external)` 6 | 7 | - `testAddShort(uint256 _vaultIndex, address _shortOtoken, uint256 _amount, uint256 _index) (external)` 8 | 9 | - `testRemoveShort(uint256 _vaultIndex, address _shortOtoken, uint256 _amount, uint256 _index) (external)` 10 | 11 | - `testAddLong(uint256 _vaultIndex, address _longOtoken, uint256 _amount, uint256 _index) (external)` 12 | 13 | - `testRemoveLong(uint256 _vaultIndex, address _longOtoken, uint256 _amount, uint256 _index) (external)` 14 | 15 | - `testAddCollateral(uint256 _vaultIndex, address _collateralAsset, uint256 _amount, uint256 _index) (external)` 16 | 17 | - `testRemoveCollateral(uint256 _vaultIndex, address _collateralAsset, uint256 _amount, uint256 _index) (external)` 18 | 19 | ### Function `getVault(uint256 _vaultIndex) → struct MarginVault.Vault external` 20 | 21 | ### Function `testAddShort(uint256 _vaultIndex, address _shortOtoken, uint256 _amount, uint256 _index) external` 22 | 23 | ### Function `testRemoveShort(uint256 _vaultIndex, address _shortOtoken, uint256 _amount, uint256 _index) external` 24 | 25 | ### Function `testAddLong(uint256 _vaultIndex, address _longOtoken, uint256 _amount, uint256 _index) external` 26 | 27 | ### Function `testRemoveLong(uint256 _vaultIndex, address _longOtoken, uint256 _amount, uint256 _index) external` 28 | 29 | ### Function `testAddCollateral(uint256 _vaultIndex, address _collateralAsset, uint256 _amount, uint256 _index) external` 30 | 31 | ### Function `testRemoveCollateral(uint256 _vaultIndex, address _collateralAsset, uint256 _amount, uint256 _index) external` 32 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/OtokenImplV1.md: -------------------------------------------------------------------------------- 1 | # `OtokenImplV1` 2 | 3 | SPDX-License-Identifier: UNLICENSED 4 | 5 | The Otoken inherits ERC20PermitUpgradeable because we need to use the init instead of constructor 6 | 7 | This is V1 implementation, with no getOtokenDetails() 8 | 9 | ## Functions: 10 | 11 | - `init(address _addressBook, address _underlyingAsset, address _strikeAsset, address _collateralAsset, uint256 _strikePrice, uint256 _expiryTimestamp, bool _isPut) (external)` 12 | 13 | - `mintOtoken(address _to, uint256 _amount) (external)` 14 | 15 | - `burnOtoken(address account, uint256 amount) (external)` 16 | 17 | - `getChainId() (external)` 18 | 19 | ### Function `init(address _addressBook, address _underlyingAsset, address _strikeAsset, address _collateralAsset, uint256 _strikePrice, uint256 _expiryTimestamp, bool _isPut) external` 20 | 21 | ### Function `mintOtoken(address _to, uint256 _amount) external` 22 | 23 | ### Function `burnOtoken(address account, uint256 amount) external` 24 | 25 | ### Function `getChainId() → uint256 chainId external` 26 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/SignedConverterTester.md: -------------------------------------------------------------------------------- 1 | # `SignedConverterTester` 2 | 3 | SignedConverter contract tester 4 | 5 | ## Functions: 6 | 7 | - `testFromInt(int256 a) (external)` 8 | 9 | - `testFromUint(uint256 a) (external)` 10 | 11 | ### Function `testFromInt(int256 a) → uint256 external` 12 | 13 | ### Function `testFromUint(uint256 a) → int256 external` 14 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/UpgradeableContractV1.md: -------------------------------------------------------------------------------- 1 | # `UpgradeableContractV1` 2 | 3 | Upgradeable testing contract 4 | 5 | ## Functions: 6 | 7 | - `initialize(address _addressBook, address _owner) (public)` 8 | 9 | - `getV1Version() (external)` 10 | 11 | ### Function `initialize(address _addressBook, address _owner) public` 12 | 13 | this function is invoked by the proxy contract when this contract is added to the 14 | 15 | AddressBook. 16 | 17 | #### Parameters: 18 | 19 | - `_addressBook`: the address of the AddressBook* 20 | 21 | ### Function `getV1Version() → uint256 external` 22 | -------------------------------------------------------------------------------- /docs/contracts-documentation/tests/UpgradeableContractV2.md: -------------------------------------------------------------------------------- 1 | # `UpgradeableContractV2` 2 | 3 | Upgradeable testing contract 4 | 5 | ## Functions: 6 | 7 | - `getV2Version() (external)` 8 | 9 | ### Function `getV2Version() → uint256 external` 10 | -------------------------------------------------------------------------------- /docs/control-flow/Gamma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/Gamma.png -------------------------------------------------------------------------------- /docs/control-flow/GammaAddressbook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaAddressbook.png -------------------------------------------------------------------------------- /docs/control-flow/GammaController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaController.png -------------------------------------------------------------------------------- /docs/control-flow/GammaFactory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaFactory.png -------------------------------------------------------------------------------- /docs/control-flow/GammaHighLevel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaHighLevel.png -------------------------------------------------------------------------------- /docs/control-flow/GammaOracle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaOracle.png -------------------------------------------------------------------------------- /docs/control-flow/GammaOtoken.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaOtoken.png -------------------------------------------------------------------------------- /docs/control-flow/GammaPool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaPool.png -------------------------------------------------------------------------------- /docs/control-flow/GammaPricer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaPricer.png -------------------------------------------------------------------------------- /docs/control-flow/GammaWhitelist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/control-flow/GammaWhitelist.png -------------------------------------------------------------------------------- /docs/uml/GammaAddressbook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaAddressbook.png -------------------------------------------------------------------------------- /docs/uml/GammaCalculator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaCalculator.png -------------------------------------------------------------------------------- /docs/uml/GammaController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaController.png -------------------------------------------------------------------------------- /docs/uml/GammaFactory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaFactory.png -------------------------------------------------------------------------------- /docs/uml/GammaOracle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaOracle.png -------------------------------------------------------------------------------- /docs/uml/GammaOtoken.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaOtoken.png -------------------------------------------------------------------------------- /docs/uml/GammaPool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaPool.png -------------------------------------------------------------------------------- /docs/uml/GammaPricer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaPricer.png -------------------------------------------------------------------------------- /docs/uml/GammaUML.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaUML.png -------------------------------------------------------------------------------- /docs/uml/GammaWhitelist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/opynfinance/GammaProtocol/841f81d9d05da9d27277b5775edfbb48c4012d2a/docs/uml/GammaWhitelist.png -------------------------------------------------------------------------------- /migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require('Migrations') 2 | 3 | module.exports = function(deployer, network, accounts) { 4 | const account = accounts[0] 5 | console.log(`deploying with account ${account}`) 6 | deployer.deploy(Migrations) 7 | } 8 | -------------------------------------------------------------------------------- /migrations/3_setup_ownership.js: -------------------------------------------------------------------------------- 1 | // import contract 2 | const Whitelist = artifacts.require('Whitelist') 3 | const Oracle = artifacts.require('Oracle') 4 | const MarginPool = artifacts.require('MarginPool') 5 | const AddressBook = artifacts.require('AddressBook') 6 | const Controller = artifacts.require('Controller') 7 | 8 | // import config file 9 | const deploymentConfig = require('./deployment-config.json') 10 | 11 | module.exports = async function(deployer, network, accounts) { 12 | const [deployerAddress] = accounts 13 | 14 | // new protocol owner 15 | const newOwner = deploymentConfig.MULTISIG 16 | 17 | const addressbook = await AddressBook.deployed() 18 | const whitelist = await Whitelist.deployed() 19 | const oracle = await Oracle.deployed() 20 | const pool = await MarginPool.deployed() 21 | const controller = await Controller.at(await addressbook.getController()) 22 | 23 | // transfer ownership 24 | await addressbook.transferOwnership(newOwner, {from: deployerAddress}) 25 | await whitelist.transferOwnership(newOwner, {from: deployerAddress}) 26 | await oracle.transferOwnership(newOwner, {from: deployerAddress}) 27 | await pool.transferOwnership(newOwner, {from: deployerAddress}) 28 | await controller.transferOwnership(newOwner, {from: deployerAddress}) 29 | } 30 | -------------------------------------------------------------------------------- /migrations/deployment-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "MULTISIG": "0x543361Be968e2f59087316514eaee9e9E9A30aF7" 3 | } -------------------------------------------------------------------------------- /scripts/calculateContractBytecode.js: -------------------------------------------------------------------------------- 1 | // This simple script tells you how big your contract byte code is and how much you have until you exceed 2 | // the current block limit as defined by EIP170. 3 | 4 | const argv = require("minimist")(process.argv.slice(), { string: ["contract"] }); 5 | const contractName = argv.contract; 6 | 7 | if (!contractName) { 8 | console.log("Please enter the contract name as a parameter as `--contract `."); 9 | return; 10 | } 11 | var child = require("child_process").exec("truffle compile"); 12 | child.stdout.pipe(process.stdout); 13 | child.on("exit", function() { 14 | console.log("finished compiling 🚀!"); 15 | console.log("loading", contractName + ".json"); 16 | let obj = require("./../build/contracts/" + contractName + ".json"); 17 | 18 | const byteCodeSize = (obj.bytecode.length - 2) / 2; 19 | const remainingSize = 2 ** 14 + 2 ** 13 - (obj.bytecode.length - 2) / 2; 20 | console.log("Contract is", byteCodeSize, "bytes in size."); 21 | console.log("This leaves a total of", remainingSize, "bytes within the EIP170 limit 🔥."); 22 | 23 | process.exit(); 24 | }); -------------------------------------------------------------------------------- /scripts/controllerSetCallRestriction.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const Controller = artifacts.require('Controller.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage('Usage: --network --controller --restriction --gasPrice ') 9 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 10 | .option('controller', {describe: 'Controller contract address', type: 'string', demandOption: true}) 11 | .option('restriction', {describe: 'Set call restriction to true or false', type: 'boolean', demandOption: true}) 12 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}).argv 13 | 14 | console.log(`Executing transaction on ${options.network} 🍕`) 15 | 16 | const controller = await Controller.at(options.controller) 17 | 18 | const tx = await controller.setCallRestriction(options.restriction, {gasPrice: options.gasPrice}) 19 | 20 | console.log('Done! 🎉') 21 | console.log(`Call action restriction set to: ${await controller.callRestricted()} at TX hash ${tx.tx}`) 22 | 23 | callback() 24 | } catch (err) { 25 | callback(err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /scripts/deployCalculator.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const MarginCalculator = artifacts.require('MarginCalculator.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage('Usage: --network --gasPrice --gas --oracle ') 9 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 10 | .option('oracle', {description: 'Oracle address', type: 'string', demandOption: true}) 11 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}) 12 | .option('gas', {describe: 'Gas Limit in WEI', type: 'string', demandOption: false}).argv 13 | 14 | console.log(`Deploying MarginCalculator contract on ${options.network} 🍕`) 15 | 16 | const tx = await MarginCalculator.new(options.oracle, {gasPrice: options.gasPrice, gas: options.gas}) 17 | 18 | console.log('MarginCalculator deployed! 🎉') 19 | console.log(`Transaction hash: ${tx.transactionHash}`) 20 | console.log(`Deployed contract address: ${tx.address}`) 21 | 22 | callback() 23 | } catch (err) { 24 | callback(err) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /scripts/deployChainlinkPricer.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const ChainlinkPricer = artifacts.require('ChainlinkPricer.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage( 9 | 'Usage: --network --bot --asset --aggregator --oracle --gasPrice --gasLimit ', 10 | ) 11 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 12 | .option('bot', {describe: 'Bot address', type: 'string', demandOption: true}) 13 | .option('asset', {describe: 'Asset address', type: 'string', demandOption: true}) 14 | .option('aggregator', {describe: 'Chainlink aggregator address', type: 'string', demandOption: true}) 15 | .option('oracle', {describe: 'Oracle module address', type: 'string', demandOption: true}) 16 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}) 17 | .option('gasLimit', {describe: 'Gas Limit in WEI', type: 'string', demandOption: false}).argv 18 | 19 | console.log(`Deploying chainlink pricer contract on ${options.network} 🍕`) 20 | 21 | const tx = await ChainlinkPricer.new(options.bot, options.asset, options.aggregator, options.oracle, { 22 | gasPrice: options.gasPrice, 23 | gas: options.gasLimit, 24 | }) 25 | 26 | console.log('Chainlink pricer deployed! 🎉') 27 | console.log(`Transaction hash: ${tx.transactionHash}`) 28 | console.log(`Deployed contract address: ${tx.address}`) 29 | 30 | callback() 31 | } catch (err) { 32 | callback(err) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /scripts/deployController.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const MarginVault = artifacts.require('MarginVault.sol') 4 | const Controller = artifacts.require('Controller.sol') 5 | 6 | module.exports = async function(callback) { 7 | try { 8 | const options = yargs 9 | .usage('Usage: --network --gasPrice --gas --marginVault') 10 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 11 | .option('marginVault', {description: 'Lib MarginVault address', type: 'string', demandOption: true}) 12 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}) 13 | .option('gas', {describe: 'Gas Limit in WEI', type: 'string', demandOption: false}).argv 14 | 15 | console.log(`Deploying Controller contract on ${options.network} 🍕`) 16 | 17 | const marginVault = await MarginVault.at(options.marginVault) 18 | await Controller.link(marginVault) 19 | console.log(`Linking MarginVault done`) 20 | 21 | // deploy controller 22 | 23 | const tx = await Controller.new({gasPrice: options.gasPrice, gas: options.gas}) 24 | 25 | console.log('Controller implementation deployed! 🎉') 26 | console.log(`Transaction hash: ${tx.transactionHash}`) 27 | console.log(`Deployed contract address: ${tx.address}`) 28 | 29 | callback() 30 | } catch (err) { 31 | callback(err) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /scripts/deployMockERC20.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const ERC20 = artifacts.require('MockERC20.sol') 4 | const PermitERC20 = artifacts.require('MockPermitERC20.sol') 5 | 6 | module.exports = async function(callback) { 7 | try { 8 | const options = yargs 9 | .usage('Usage: --name --symbol --decimals --permit --gasPrice ') 10 | .option('name', {describe: 'Token Name', type: 'string', demandOption: true}) 11 | .option('symbol', {describe: 'Token Symbol', type: 'string', demandOption: true}) 12 | .option('decimals', {describe: 'Token Decimals', type: 'string', demandOption: true}) 13 | .option('permit', {describe: 'Support Permit or not', type: 'boolean', decimals: true}) 14 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}).argv 15 | 16 | console.log(`Deploying MockERC20: ${options.symbol} contract on ${options.network} 🍕`) 17 | 18 | const tx = options.permit 19 | ? await PermitERC20.new(options.name, options.symbol, options.decimals, {gasPrice: options.gasPrice}) 20 | : await ERC20.new(options.name, options.symbol, options.decimals, {gasPrice: options.gasPrice}) 21 | 22 | console.log('MockERC20 deployed! 🎉') 23 | console.log(`Transaction hash: ${tx.transactionHash}`) 24 | console.log(`Deployed contract address: ${tx.address}`) 25 | 26 | callback() 27 | } catch (err) { 28 | callback(err) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /scripts/deployMockPricer.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const MockPricer = artifacts.require('MockPricer.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage( 9 | 'Usage: --network --asset --oracle --gasPrice ', 10 | ) 11 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 12 | .option('asset', {describe: 'Asset address', type: 'string', demandOption: true}) 13 | .option('oracle', {describe: 'Oracle module address', type: 'string', demandOption: true}) 14 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}).argv 15 | 16 | console.log(`Deploying chainlink pricer contract on ${options.network} 🍕`) 17 | 18 | const tx = await MockPricer.new(options.asset, options.oracle, { 19 | gasPrice: options.gasPrice 20 | }) 21 | 22 | console.log('MockPricer deployed! 🎉') 23 | console.log(`Transaction hash: ${tx.transactionHash}`) 24 | console.log(`Deployed contract address: ${tx.address}`) 25 | 26 | callback() 27 | } catch (err) { 28 | callback(err) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /scripts/deployOtokenImpl.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const Otoken = artifacts.require('Otoken.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage('Usage: --network --gas ') 9 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 10 | .option('gas', {describe: 'Gas price in WEI', type: 'string', demandOption: false}).argv 11 | 12 | console.log(`Deploying Otoken contract on ${options.network} 🍕`) 13 | 14 | const tx = await Otoken.new({gasPrice: options.gas}) 15 | 16 | console.log('Otoken implementation deployed! 🎉') 17 | console.log(`Transaction hash: ${tx.transactionHash}`) 18 | console.log(`Deployed contract address: ${tx.address}`) 19 | 20 | callback() 21 | } catch (err) { 22 | callback(err) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /scripts/deployPayableProxyController.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const PayableProxyController = artifacts.require('PayableProxyController.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage('Usage: --network --controller --pool --weth --gasPrice ') 9 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 10 | .option('controller', {describe: 'Controller proxy address', type: 'string', demandOption: true}) 11 | .option('pool', {describe: 'Margin pool address', type: 'string', demandOption: true}) 12 | .option('weth', {describe: 'WETH token address', type: 'string', demandOption: true}) 13 | .option('gasPrice', {describe: 'Gas pricer in WEI', type: 'string', demandOption: false}).argv 14 | 15 | console.log(`Deploying payable proxy contract on ${options.network} 🍕`) 16 | 17 | const tx = await PayableProxyController.new(options.controller, options.pool, options.weth, { 18 | gasPrice: options.gasPrice, 19 | }) 20 | 21 | console.log('Payable proxy contract deployed! 🎉') 22 | console.log(`Transaction hash: ${tx.transactionHash}`) 23 | console.log(`Deployed contract address: ${tx.address}`) 24 | 25 | callback() 26 | } catch (err) { 27 | callback(err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /scripts/deployPermitCallee.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const PermitCallee = artifacts.require('PermitCallee.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage('Usage: --network --gasPrice ') 9 | .option('network', {describe: '0x exchange address', type: 'string', demandOption: true}) 10 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}).argv 11 | 12 | console.log(`Deploying Permit callee contract on ${options.network} 🍕`) 13 | 14 | const tx = await PermitCallee.new({gasPrice: options.gasPrice}) 15 | 16 | console.log('Permit callee deployed! 🎉') 17 | console.log(`Transaction hash: ${tx.transactionHash}`) 18 | console.log(`Deployed contract address: ${tx.address}`) 19 | 20 | callback() 21 | } catch (err) { 22 | callback(err) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /scripts/deployWstethPricer.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const WstethPricer = artifacts.require('WstethPricer.sol') 4 | 5 | module.exports = async function (callback) { 6 | try { 7 | const options = yargs 8 | .usage( 9 | 'Usage: --network --wstETH --underlying --oracle --gasPrice --gasLimit ', 10 | ) 11 | .option('network', { describe: 'Network name', type: 'string', demandOption: true }) 12 | .option('wstETH', { describe: 'wstETH address', type: 'string', demandOption: true }) 13 | .option('underlying', { describe: 'Underlying address', type: 'string', demandOption: true }) 14 | .option('oracle', { describe: 'Oracle module address', type: 'string', demandOption: true }) 15 | .option('gasPrice', { describe: 'Gas price in WEI', type: 'string', demandOption: false }) 16 | .option('gasLimit', { describe: 'Gas Limit in WEI', type: 'string', demandOption: false }).argv 17 | 18 | console.log(`Deploying wstETH pricer contract to ${options.network} 🍕`) 19 | 20 | const tx = await WstethPricer.new(options.wstETH, options.underlying, options.oracle, { 21 | gasPrice: options.gasPrice, 22 | gas: options.gasLimit, 23 | }) 24 | 25 | console.log('wstETH pricer deployed! 🎉') 26 | console.log(`Transaction hash: ${tx.transactionHash}`) 27 | console.log(`Deployed contract address: ${tx.address}`) 28 | 29 | callback() 30 | } catch (err) { 31 | callback(err) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /scripts/deployYearnPricer.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const YearnPricer = artifacts.require('YearnPricer.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage( 9 | 'Usage: --network --yToken --underlying --oracle --gasPrice --gasLimit ', 10 | ) 11 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 12 | .option('yToken', {describe: 'yToken address', type: 'string', demandOption: true}) 13 | .option('underlying', {describe: 'Underlying address', type: 'string', demandOption: true}) 14 | .option('oracle', {describe: 'Oracle module address', type: 'string', demandOption: true}) 15 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}) 16 | .option('gasLimit', {describe: 'Gas Limit in WEI', type: 'string', demandOption: false}).argv 17 | 18 | console.log(`Deploying yearn pricer contract on ${options.network} 🍕`) 19 | 20 | const tx = await YearnPricer.new(options.yToken, options.underlying, options.oracle, { 21 | gasPrice: options.gasPrice, 22 | gas: options.gasLimit, 23 | }) 24 | 25 | console.log('Yearn pricer deployed! 🎉') 26 | console.log(`Transaction hash: ${tx.transactionHash}`) 27 | console.log(`Deployed contract address: ${tx.address}`) 28 | 29 | callback() 30 | } catch (err) { 31 | callback(err) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /scripts/local-e2e.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export INFURA_KEY=$(cat .infuraKey) 4 | 5 | ./ci/e2e.sh && kill $(lsof -t -i:8545) -------------------------------------------------------------------------------- /scripts/whitelistSetCallee.js: -------------------------------------------------------------------------------- 1 | const yargs = require('yargs') 2 | 3 | const Whitelist = artifacts.require('Whitelist.sol') 4 | 5 | module.exports = async function(callback) { 6 | try { 7 | const options = yargs 8 | .usage('Usage: --network --whitelist --callee --gasPrice ') 9 | .option('network', {describe: 'Network name', type: 'string', demandOption: true}) 10 | .option('whitelist', {describe: 'Whitelist contract address', type: 'string', demandOption: true}) 11 | .option('callee', {describe: 'Callee contract address', type: 'string', demandOption: true}) 12 | .option('gasPrice', {describe: 'Gas price in WEI', type: 'string', demandOption: false}).argv 13 | 14 | console.log(`Executing transaction on ${options.network} 🍕`) 15 | 16 | const whitelist = await Whitelist.at(options.whitelist) 17 | 18 | const tx = await whitelist.whitelistCallee(options.callee, {gasPrice: options.gasPrice}) 19 | 20 | console.log('Done! 🎉') 21 | console.log( 22 | `Callee contract whitelisting set to: ${await whitelist.isWhitelistedCallee(options.callee)} at TX hash ${tx.tx}`, 23 | ) 24 | 25 | callback() 26 | } catch (err) { 27 | callback(err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /slither.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "detectors_to_exclude": "timestamp,naming-convention,pragma,solc-version,constable-states,calls-loop,uninitialized-local", 3 | "filter_paths": "Migrations.sol|packages|mocks|tests", 4 | "truffle_version": "5.1.32", 5 | "exclude_optimization": true, 6 | "exclude_informational": true, 7 | "exclude_low": true 8 | } -------------------------------------------------------------------------------- /specs/ControllerOrderOfOperations.spec: -------------------------------------------------------------------------------- 1 | methods { 2 | //the amount of collateral in an index in a vault of an owner. i.e., vaults[owner][index].collateralAmounts[i] 3 | getVaultCollateralAmount(address, uint256, uint256) returns uint256 envfree 4 | } 5 | 6 | rule orderOfOperations (address owner, uint256 vaultId, method f1, method f2) { 7 | if ( f1.selector > f2.selector) { 8 | assert true; 9 | } else { 10 | storage initialStorage = lastStorage; 11 | env e1; 12 | calldataarg arg1; 13 | sinvoke f1(e1, arg1); 14 | env e2; 15 | calldataarg arg2; 16 | sinvoke f2(e2, arg2); 17 | 18 | uint256 vaultCollateralAmount1 = getVaultCollateralAmount(owner, vaultId,0); 19 | 20 | sinvoke f2(e2, arg2) at initialStorage; 21 | sinvoke f1(e1, arg1); 22 | 23 | uint256 vaultCollateralAmount2 = getVaultCollateralAmount(owner, vaultId,0); 24 | // run first method and then second method and store the result 25 | // run the second method then first method and compare result 26 | assert vaultCollateralAmount1 == vaultCollateralAmount2; 27 | } 28 | } -------------------------------------------------------------------------------- /specs/Privileged.spec: -------------------------------------------------------------------------------- 1 | definition knownAsNonPrivileged(method f) returns bool = 2 | ( f.selector == isWhitelistedOtoken(address).selector || 3 | f.selector == isWhitelistedProduct(address,address,address,bool).selector || 4 | f.selector == owner().selector || 5 | f.selector == isWhitelistedCallee(address).selector || 6 | f.selector == whitelistOtoken(address).selector || 7 | f.selector == addressBook().selector || 8 | f.selector == isWhitelistedCollateral(address).selector ); 9 | 10 | 11 | 12 | rule privilegedOperation(method f, address privileged) 13 | description "$f can be called by more than one user without reverting" 14 | { 15 | env e1; 16 | calldataarg arg; 17 | require !knownAsNonPrivileged(f); 18 | require e1.msg.sender == privileged; 19 | 20 | storage initialStorage = lastStorage; 21 | invoke f(e1, arg); // privileged succeeds executing candidate privileged operation. 22 | bool firstSucceeded = !lastReverted; 23 | 24 | env e2; 25 | calldataarg arg2; 26 | require e2.msg.sender != privileged; 27 | invoke f(e2, arg2) at initialStorage; // unprivileged 28 | bool secondSucceeded = !lastReverted; 29 | 30 | assert !(firstSucceeded && secondSucceeded), "${f.selector} can be called by both ${e1.msg.sender} and ${e2.msg.sender}, so it is not privileged"; 31 | } 32 | -------------------------------------------------------------------------------- /specs/harness/ControllerHarnessExtra.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.10; 2 | 3 | pragma experimental ABIEncoderV2; 4 | 5 | import 'specs/harness/ControllerHarness.sol'; 6 | 7 | interface ExtendedERC20 { 8 | function havocTotalSupply(uint256) external; 9 | 10 | function havocVault( 11 | address owner, 12 | uint256 vaultId, 13 | uint256 i, 14 | uint256 newShortAmount, 15 | uint256 newLongAmount, 16 | uint256 newcollateralAmount 17 | ) external; 18 | } 19 | 20 | /** 21 | An additional harness over the controller to allow checking the no-bankruptcy rules. 22 | */ 23 | contract ControllerHarnessExtra is ControllerHarness { 24 | function havocVault( 25 | address owner, 26 | uint256 vaultId, 27 | uint256 i, 28 | uint256 newShortAmount, 29 | uint256 newLongAmount, 30 | uint256 newcollateralAmount 31 | ) external { 32 | MarginVault.Vault storage vault = cheapGetVault(owner, vaultId); 33 | vault.shortAmounts[i] = newShortAmount; 34 | vault.longAmounts[i] = newLongAmount; 35 | vault.collateralAmounts[i] = newcollateralAmount; 36 | } 37 | 38 | function havocTotalSpply(address oToken, uint256 newValue) external { 39 | if (oToken == anOtokenA) ExtendedERC20(anOtokenA).havocTotalSupply(newValue); 40 | else if (oToken == anOtokenB) ExtendedERC20(anOtokenB).havocTotalSupply(newValue); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /specs/harness/DummyERC20A.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | pragma solidity ^0.6.8; 3 | 4 | contract DummyERC20A { 5 | uint256 t; 6 | mapping(address => uint256) b; 7 | mapping(address => mapping(address => uint256)) a; 8 | 9 | string public name; 10 | string public symbol; 11 | uint256 public decimals; 12 | 13 | function myAddress() public returns (address) { 14 | return address(this); 15 | } 16 | 17 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 18 | uint256 c = a + b; 19 | require(c >= a); 20 | return c; 21 | } 22 | 23 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 24 | require(a >= b); 25 | return a - b; 26 | } 27 | 28 | function totalSupply() external view returns (uint256) { 29 | return t; 30 | } 31 | 32 | function balanceOf(address account) external view returns (uint256) { 33 | return b[account]; 34 | } 35 | 36 | function transfer(address recipient, uint256 amount) external returns (bool) { 37 | b[msg.sender] = sub(b[msg.sender], amount); 38 | b[recipient] = add(b[recipient], amount); 39 | return true; 40 | } 41 | 42 | function allowance(address owner, address spender) external view returns (uint256) { 43 | return a[owner][spender]; 44 | } 45 | 46 | function approve(address spender, uint256 amount) external returns (bool) { 47 | a[msg.sender][spender] = amount; 48 | return true; 49 | } 50 | 51 | function transferFrom( 52 | address sender, 53 | address recipient, 54 | uint256 amount 55 | ) external returns (bool) { 56 | b[sender] = sub(b[sender], amount); 57 | b[recipient] = add(b[recipient], amount); 58 | a[sender][msg.sender] = sub(a[sender][msg.sender], amount); 59 | return true; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /specs/harness/DummyERC20B.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | pragma solidity ^0.6.8; 3 | 4 | contract DummyERC20B { 5 | uint256 t; 6 | mapping(address => uint256) b; 7 | mapping(address => mapping(address => uint256)) a; 8 | 9 | string public name; 10 | string public symbol; 11 | uint256 public decimals; 12 | 13 | function myAddress() public returns (address) { 14 | return address(this); 15 | } 16 | 17 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 18 | uint256 c = a + b; 19 | require(c >= a); 20 | return c; 21 | } 22 | 23 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 24 | require(a >= b); 25 | return a - b; 26 | } 27 | 28 | function totalSupply() external view returns (uint256) { 29 | return t; 30 | } 31 | 32 | function balanceOf(address account) external view returns (uint256) { 33 | return b[account]; 34 | } 35 | 36 | function transfer(address recipient, uint256 amount) external returns (bool) { 37 | b[msg.sender] = sub(b[msg.sender], amount); 38 | b[recipient] = add(b[recipient], amount); 39 | return true; 40 | } 41 | 42 | function allowance(address owner, address spender) external view returns (uint256) { 43 | return a[owner][spender]; 44 | } 45 | 46 | function approve(address spender, uint256 amount) external returns (bool) { 47 | a[msg.sender][spender] = amount; 48 | return true; 49 | } 50 | 51 | function transferFrom( 52 | address sender, 53 | address recipient, 54 | uint256 amount 55 | ) external returns (bool) { 56 | b[sender] = sub(b[sender], amount); 57 | b[recipient] = add(b[recipient], amount); 58 | a[sender][msg.sender] = sub(a[sender][msg.sender], amount); 59 | return true; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /specs/harness/DummyERC20C.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | pragma solidity ^0.6.8; 3 | 4 | contract DummyERC20C { 5 | uint256 t; 6 | mapping(address => uint256) b; 7 | mapping(address => mapping(address => uint256)) a; 8 | 9 | string public name; 10 | string public symbol; 11 | uint256 public decimals; 12 | 13 | function myAddress() public returns (address) { 14 | return address(this); 15 | } 16 | 17 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 18 | uint256 c = a + b; 19 | require(c >= a); 20 | return c; 21 | } 22 | 23 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 24 | require(a >= b); 25 | return a - b; 26 | } 27 | 28 | function totalSupply() external view returns (uint256) { 29 | return t; 30 | } 31 | 32 | function balanceOf(address account) external view returns (uint256) { 33 | return b[account]; 34 | } 35 | 36 | function transfer(address recipient, uint256 amount) external returns (bool) { 37 | b[msg.sender] = sub(b[msg.sender], amount); 38 | b[recipient] = add(b[recipient], amount); 39 | return true; 40 | } 41 | 42 | function allowance(address owner, address spender) external view returns (uint256) { 43 | return a[owner][spender]; 44 | } 45 | 46 | function approve(address spender, uint256 amount) external returns (bool) { 47 | a[msg.sender][spender] = amount; 48 | return true; 49 | } 50 | 51 | function transferFrom( 52 | address sender, 53 | address recipient, 54 | uint256 amount 55 | ) external returns (bool) { 56 | b[sender] = sub(b[sender], amount); 57 | b[recipient] = add(b[recipient], amount); 58 | a[sender][msg.sender] = sub(a[sender][msg.sender], amount); 59 | return true; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /specs/harness/MarginCalculatorHarness.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.10; 2 | 3 | pragma experimental ABIEncoderV2; 4 | 5 | import '../../contracts/core/MarginCalculator.sol'; 6 | 7 | //import {MarginVault} from "../../contracts/libs/MarginVault.sol"; 8 | 9 | contract MarginCalculatorHarness { 10 | // we are assuming one short otoken, one long otoken and one collateral 11 | // mapping : collateral amount => short amount => long amount => collateralAsset 12 | mapping(uint256 => mapping(uint256 => mapping(uint256 => uint256))) internal excessCollateral; 13 | 14 | function getExcessCollateral(MarginVault.Vault memory _vault) public view returns (uint256, bool) { 15 | uint256 excess = excessCollateral[_vault.collateralAmounts[0]][_vault.shortAmounts[0]][_vault.longAmounts[0]]; 16 | if (excess >= 0) return (uint256(excess), true); 17 | else return (uint256(-excess), false); 18 | } 19 | 20 | function getExcessCollateral( 21 | uint256 shortAmounts, 22 | uint256 longAmounts, 23 | uint256 collateralAmounts 24 | ) public view returns (uint256, bool) { 25 | uint256 excess = excessCollateral[collateralAmounts][shortAmounts][longAmounts]; 26 | if (excess >= 0) return (uint256(excess), true); 27 | else return (uint256(-excess), false); 28 | } 29 | 30 | mapping(address => uint256) internal expiredPayoutRate; 31 | 32 | function getExpiredPayoutRate(address _otoken) external view returns (uint256) { 33 | return expiredPayoutRate[_otoken]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /specs/harness/MarginPoolHarness.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.10; 2 | 3 | pragma experimental ABIEncoderV2; 4 | 5 | import '../../contracts/core/MarginPool.sol'; 6 | 7 | contract MarginPoolHarness is MarginPool { 8 | constructor(address _addressBook) public MarginPool(_addressBook) {} 9 | 10 | mapping(address => uint256) internal assetBalanceHavoc; 11 | 12 | function havocSystemBalance(address _asset) public { 13 | assetBalance[_asset] = assetBalanceHavoc[_asset]; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /specs/harness/OtokenHarnessA.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | import '../../contracts/core/Otoken.sol'; 3 | 4 | contract OtokenHarnessA is Otoken { 5 | function havocTotalSupply(uint256 newVal) public { 6 | _totalSupply = newVal; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /specs/harness/OtokenHarnessB.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | import '../../contracts/core/Otoken.sol'; 3 | 4 | contract OtokenHarnessB is Otoken { 5 | function havocTotalSupply(uint256 newVal) public { 6 | _totalSupply = newVal; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /specs/runMarginVault.sh: -------------------------------------------------------------------------------- 1 | certoraRun MarginVaultHarness.sol --solc solc --verify MarginVaultHarness:MarginVault.spec --settings -assumeUnwindCond,-b=3,-enableStorageVariableUnpacking=false,-useNonLinearArithmetic --path .. --staging 2 | -------------------------------------------------------------------------------- /specs/scripts/Controller/collateralWithdrawal.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runController.sh collateralWithdrawsRestricted -------------------------------------------------------------------------------- /specs/scripts/Controller/onlyOneVaultModified.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runController.sh onlyOneVaultModified -------------------------------------------------------------------------------- /specs/scripts/Controller/optionsWithdrawsRestricted.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runController.sh optionWithdrawsRestricted -------------------------------------------------------------------------------- /specs/scripts/Controller/redeem.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runController.sh redeem -------------------------------------------------------------------------------- /specs/scripts/Controller/runOrderOfOperations.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runController.sh orderOfOperations -------------------------------------------------------------------------------- /specs/scripts/Controller/runSettleVault.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runController.sh settleVault -------------------------------------------------------------------------------- /specs/scripts/assetIsNotOtoken.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runValidBalances.sh assetIsNotOtoken -------------------------------------------------------------------------------- /specs/scripts/callOptionsPreExpiry.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runNoBankruptcy.sh putOptionsPreExpiryCase2StartingWithAllCases callOptionsPreExpiry 2 | -------------------------------------------------------------------------------- /specs/scripts/cantSettleUnexpiredVault.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runValidBalances.sh cantSettleUnexpiredVault -------------------------------------------------------------------------------- /specs/scripts/onlyValidOtoken.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runValidBalances.sh onlyValidOtoken -------------------------------------------------------------------------------- /specs/scripts/putOptionsPreExpiryCase1.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runNoBankruptcy.sh putOptionsPreExpiryCase1StartingWithAllCases -------------------------------------------------------------------------------- /specs/scripts/putOptionsPreExpiryCase2.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runNoBankruptcy.sh putOptionsPreExpiryCase2StartingWithAllCases -------------------------------------------------------------------------------- /specs/scripts/runController.sh: -------------------------------------------------------------------------------- 1 | certoraRun specs/harness/ControllerHarness.sol contracts/core/MarginPool.sol specs/harness/MarginCalculatorHarness.sol:MarginCalculatorHarness contracts/core/Whitelist.sol specs/harness/OtokenHarnessA.sol specs/harness/OtokenHarnessB.sol specs/harness/DummyERC20A.sol specs/harness/DummyERC20B.sol specs/harness/DummyERC20C.sol --link ControllerHarness:calculator=MarginCalculatorHarness ControllerHarness:pool=MarginPool ControllerHarness:anOtokenA=OtokenHarnessA ControllerHarness:anOtokenB=OtokenHarnessB ControllerHarness:dummyERC20C=DummyERC20C OtokenHarnessA:underlyingAsset=DummyERC20A OtokenHarnessA:strikeAsset=DummyERC20B OtokenHarnessA:collateralAsset=DummyERC20C OtokenHarnessB:underlyingAsset=DummyERC20A OtokenHarnessB:strikeAsset=DummyERC20B OtokenHarnessB:collateralAsset=DummyERC20C --solc solc --verify ControllerHarness:specs/controller.spec --settings -assumeUnwindCond,-optimisticReturnsize=true,-ciMode=true,-t=300,-rule=$1 --cache OpynController -------------------------------------------------------------------------------- /specs/scripts/runMarginVault.sh: -------------------------------------------------------------------------------- 1 | certoraRun specs/harness/MarginVaultHarness.sol --solc solc --verify MarginVaultHarness:specs/MarginVault.spec --settings -assumeUnwindCond,-b=3,-ciMode=true,-useNonLinearArithmetic -------------------------------------------------------------------------------- /specs/scripts/runNoBankruptcy.sh: -------------------------------------------------------------------------------- 1 | certoraRun specs/harness/ControllerHarnessExtra.sol specs/harness/MarginPoolHarness.sol specs/harness/OtokenHarnessA.sol specs/harness/OtokenHarnessB.sol specs/harness/DummyERC20A.sol specs/harness/DummyERC20B.sol specs/harness/DummyERC20C.sol --link ControllerHarnessExtra:pool=MarginPoolHarness ControllerHarnessExtra:anOtokenA=OtokenHarnessA ControllerHarnessExtra:anOtokenB=OtokenHarnessB ControllerHarnessExtra:dummyERC20C=DummyERC20C OtokenHarnessA:underlyingAsset=DummyERC20A OtokenHarnessA:strikeAsset=DummyERC20B OtokenHarnessA:collateralAsset=DummyERC20C OtokenHarnessB:underlyingAsset=DummyERC20A OtokenHarnessB:strikeAsset=DummyERC20B OtokenHarnessB:collateralAsset=DummyERC20C --verify ControllerHarnessExtra:specs/NoBankruptcy.spec --solc solc --settings -assumeUnwindCond,-b=3,-ciMode=true,-useNonLinearArithmetic,-rule=$1 --cache OpynNoBankruptcy -------------------------------------------------------------------------------- /specs/scripts/runOrderOfOperations.sh: -------------------------------------------------------------------------------- 1 | certoraRun specs/harness/ControllerHarness.sol contracts/core/MarginPool.sol specs/harness/MarginCalculatorHarness.sol:MarginCalculatorHarness contracts/core/Whitelist.sol specs/harness/OtokenHarnessA.sol specs/harness/OtokenHarnessB.sol specs/harness/DummyERC20A.sol specs/harness/DummyERC20B.sol specs/harness/DummyERC20C.sol --link ControllerHarness:calculator=MarginCalculatorHarness ControllerHarness:pool=MarginPool ControllerHarness:anOtokenA=OtokenHarnessA ControllerHarness:anOtokenB=OtokenHarnessB ControllerHarness:dummyERC20C=DummyERC20C OtokenHarnessA:underlyingAsset=DummyERC20A OtokenHarnessA:strikeAsset=DummyERC20B OtokenHarnessA:collateralAsset=DummyERC20C OtokenHarnessB:underlyingAsset=DummyERC20A OtokenHarnessB:strikeAsset=DummyERC20B OtokenHarnessB:collateralAsset=DummyERC20C --solc solc6.10 --verify ControllerHarness:specs/ControllerOrderOfOperations.spec --settings -assumeUnwindCond,-optimisticReturnsize=true,-ciMode=true,-t=300 --staging shelly/opynFullIntegration -------------------------------------------------------------------------------- /specs/scripts/runPrivilegedWhitelist.sh: -------------------------------------------------------------------------------- 1 | certoraRun contracts/core/Whitelist.sol --verify Whitelist:specs/Privileged.spec --solc solc --settings -b=4,-ciMode=true -------------------------------------------------------------------------------- /specs/scripts/runValidBalances.sh: -------------------------------------------------------------------------------- 1 | certoraRun specs/harness/ControllerHarness.sol contracts/core/MarginPool.sol contracts/core/Whitelist.sol contracts/core/Oracle.sol specs/harness/OtokenHarnessA.sol specs/harness/OtokenHarnessB.sol specs/harness/DummyERC20A.sol specs/harness/DummyERC20B.sol specs/harness/DummyERC20C.sol --link ControllerHarness:oracle=Oracle ControllerHarness:whitelist=Whitelist ControllerHarness:pool=MarginPool ControllerHarness:anOtokenA=OtokenHarnessA ControllerHarness:anOtokenB=OtokenHarnessB ControllerHarness:dummyERC20C=DummyERC20C OtokenHarnessA:underlyingAsset=DummyERC20A OtokenHarnessA:strikeAsset=DummyERC20B OtokenHarnessA:collateralAsset=DummyERC20C OtokenHarnessB:underlyingAsset=DummyERC20A OtokenHarnessB:strikeAsset=DummyERC20B OtokenHarnessB:collateralAsset=DummyERC20C --solc solc --verify ControllerHarness:specs/ValidBalances.spec --settings -assumeUnwindCond,-ciMode=true,-t=300,-optimisticReturnsize=true,-rule=$1 --cache OpynValidBalances 2 | -------------------------------------------------------------------------------- /specs/scripts/runValidCollateral.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runValidBalances.sh validBalanceTotalCollateralPostExpiry -------------------------------------------------------------------------------- /specs/scripts/validBalanceTotalCollateral.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runValidBalances.sh validBalanceTotalCollateral -------------------------------------------------------------------------------- /specs/scripts/validBalanceTotalLong.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runValidBalances.sh validBalanceTotalLong -------------------------------------------------------------------------------- /specs/scripts/validBalanceTotalShort.sh: -------------------------------------------------------------------------------- 1 | exec specs/scripts/runValidBalances.sh validBalanceTotalShort -------------------------------------------------------------------------------- /test/eip712.js: -------------------------------------------------------------------------------- 1 | const ethSigUtil = require('eth-sig-util') 2 | 3 | const EIP712Domain = [ 4 | {name: 'name', type: 'string'}, 5 | {name: 'version', type: 'string'}, 6 | {name: 'chainId', type: 'uint256'}, 7 | {name: 'verifyingContract', type: 'address'}, 8 | ] 9 | 10 | async function domainSeparator(name, version, chainId, verifyingContract) { 11 | return ( 12 | '0x' + 13 | ethSigUtil.TypedDataUtils.hashStruct( 14 | 'EIP712Domain', 15 | {name, version, chainId, verifyingContract}, 16 | {EIP712Domain}, 17 | ).toString('hex') 18 | ) 19 | } 20 | 21 | module.exports = { 22 | EIP712Domain, 23 | domainSeparator, 24 | } 25 | -------------------------------------------------------------------------------- /test/unit-tests/signedConverter.test.ts: -------------------------------------------------------------------------------- 1 | import { SignedConverterTesterInstance } from '../../build/types/truffle-types' 2 | import BigNumber from 'bignumber.js' 3 | 4 | const { expectRevert } = require('@openzeppelin/test-helpers') 5 | 6 | const SignedConverterTester = artifacts.require('SignedConverterTester.sol') 7 | 8 | contract('FixedPointInt256 lib', () => { 9 | let lib: SignedConverterTesterInstance 10 | 11 | before('set up contracts', async () => { 12 | lib = await SignedConverterTester.new() 13 | }) 14 | 15 | describe('Test type conversion', () => { 16 | it('Should convert from unsigned integer to signed integer', async () => { 17 | const uint = new BigNumber(5) 18 | const expectedInt = new BigNumber(5) 19 | 20 | assert.equal( 21 | (await lib.testFromUint(uint)).toNumber(), 22 | expectedInt.toNumber(), 23 | 'conversion from uint to int mismatch', 24 | ) 25 | }) 26 | 27 | it('It should revert converting an unsigned integer greater than 2^255 signed integer', async () => { 28 | const uint = new BigNumber(2).pow(255) 29 | await expectRevert(lib.testFromUint(uint), 'FixedPointInt256: out of int range') 30 | 31 | const uint2 = new BigNumber(2).pow(255).plus(1) 32 | await expectRevert(lib.testFromUint(uint2), 'FixedPointInt256: out of int range') 33 | }) 34 | 35 | it('Should convert max_int (2^255) - 1 from uint to int', async () => { 36 | const uint = new BigNumber(2).pow(255).minus(1) 37 | assert.equal((await lib.testFromUint(uint)).toString(), uint.toString(), 'conversion from int to uint mismatch') 38 | }) 39 | 40 | it('Should convert from signed integer to unsigned integer', async () => { 41 | const int = new BigNumber(-3) 42 | const expectedUint = new BigNumber(3) 43 | 44 | assert.equal( 45 | (await lib.testFromInt(int)).toNumber(), 46 | expectedUint.toNumber(), 47 | 'conversion from int to uint mismatch', 48 | ) 49 | }) 50 | it('Should convert from positive signed integer to unsigned integer', async () => { 51 | const int = new BigNumber(3) 52 | const expectedUint = new BigNumber(3) 53 | 54 | assert.equal( 55 | (await lib.testFromInt(int)).toNumber(), 56 | expectedUint.toNumber(), 57 | 'conversion from int to uint mismatch', 58 | ) 59 | }) 60 | }) 61 | }) 62 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "noImplicitThis": true, 5 | "noImplicitAny": true, 6 | "noImplicitReturns": true, 7 | "alwaysStrict": true, 8 | "typeRoots": [ 9 | "./node_modules/@types", 10 | "./build/types", 11 | "./node_modules/truffle-typings" 12 | ] 13 | }, 14 | "include": [ 15 | "test/**/*.ts" 16 | ], 17 | "exclude": [ 18 | "node_modules" 19 | ] 20 | } --------------------------------------------------------------------------------