diff --git a/contracts/OptionsContract.sol b/contracts/OptionsContract.sol index a01202f..b28bd91 100644 --- a/contracts/OptionsContract.sol +++ b/contracts/OptionsContract.sol @@ -39,9 +39,6 @@ contract OptionsContract is Ownable, ERC20 { // 10 is 0.01 i.e. 1% incentive. Number public liquidationIncentive = Number(10, -3); - // 100 is egs. 0.1 i.e. 10%. - Number public transactionFee = Number(0, -3); - /* 500 is 0.5. Max amount that a Vault can be liquidated by i.e. max collateral that can be taken in one function call */ Number public liquidationFactor = Number(500, -3); @@ -49,7 +46,7 @@ contract OptionsContract is Ownable, ERC20 { /* 16 means 1.6. The minimum ratio of a Vault's collateral to insurance promised. The ratio is calculated as below: vault.collateral / (Vault.oTokensIssued * strikePrice) */ - Number public minCollateralizationRatio = Number(16, -1); + Number public minCollateralizationRatio = Number(10, -1); // The amount of insurance promised per oToken Number public strikePrice; @@ -99,43 +96,32 @@ contract OptionsContract is Ownable, ERC20 { /** * @param _collateral The collateral asset - * @param _collExp The precision of the collateral (-18 if ETH) * @param _underlying The asset that is being protected - * @param _underlyingExp The precision of the underlying asset * @param _oTokenExchangeExp The precision of the `amount of underlying` that 1 oToken protects * @param _strikePrice The amount of strike asset that will be paid out per oToken * @param _strikeExp The precision of the strike price. * @param _strike The asset in which the insurance is calculated * @param _expiry The time at which the insurance expires - * @param _oracleAddress The address of the oracle * @param _windowSize UNIX time. Exercise window is from `expiry - _windowSize` to `expiry`. + * @param _oracleAddress The address of the oracle */ constructor( - IERC20 _collateral, - int32 _collExp, - IERC20 _underlying, - int32 _underlyingExp, + address _collateral, + address _underlying, + address _strike, int32 _oTokenExchangeExp, uint256 _strikePrice, int32 _strikeExp, - IERC20 _strike, uint256 _expiry, - address _oracleAddress, - uint256 _windowSize + uint256 _windowSize, + address _oracleAddress ) public { require(block.timestamp < _expiry, "Can't deploy an expired contract"); require( _windowSize <= _expiry, "Exercise window can't be longer than the contract's lifespan" ); - require( - isWithinExponentRange(_collExp), - "collateral exponent not within expected range" - ); - require( - isWithinExponentRange(_underlyingExp), - "underlying exponent not within expected range" - ); + require( isWithinExponentRange(_strikeExp), "strike price exponent not within expected range" @@ -150,15 +136,24 @@ contract OptionsContract is Ownable, ERC20 { "OptionsContract: Can't use ETH as underlying." ); - collateral = _collateral; - collateralExp = _collExp; + collateral = IERC20(_collateral); + underlying = IERC20(_underlying); + strike = IERC20(_strike); + + collateralExp = getAssetExp(_collateral); + underlyingExp = getAssetExp(_underlying); + require( + isWithinExponentRange(collateralExp), + "collateral exponent not within expected range" + ); + require( + isWithinExponentRange(underlyingExp), + "underlying exponent not within expected range" + ); - underlying = _underlying; - underlyingExp = _underlyingExp; oTokenExchangeRate = Number(1, _oTokenExchangeExp); strikePrice = Number(_strikePrice, _strikeExp); - strike = _strike; expiry = _expiry; oracle = OracleInterface(_oracleAddress); @@ -203,7 +198,6 @@ contract OptionsContract is Ownable, ERC20 { event UpdateParameters( uint256 liquidationIncentive, uint256 liquidationFactor, - uint256 transactionFee, uint256 minCollateralizationRatio, address owner ); @@ -237,13 +231,11 @@ contract OptionsContract is Ownable, ERC20 { * @notice Can only be called by owner. Used to update the fees, minCollateralizationRatio, etc * @param _liquidationIncentive The incentive paid to liquidator. 10 is 0.01 i.e. 1% incentive. * @param _liquidationFactor Max amount that a Vault can be liquidated by. 500 is 0.5. - * @param _transactionFee The fees paid to our protocol every time a execution happens. 100 is egs. 0.1 i.e. 10%. * @param _minCollateralizationRatio The minimum ratio of a Vault's collateral to insurance promised. 16 means 1.6. */ function updateParameters( uint256 _liquidationIncentive, uint256 _liquidationFactor, - uint256 _transactionFee, uint256 _minCollateralizationRatio ) external onlyOwner { require( @@ -254,7 +246,6 @@ contract OptionsContract is Ownable, ERC20 { _liquidationFactor <= 1000, "Can't liquidate more than 100% of the vault" ); - require(_transactionFee <= 100, "Can't have transaction fee > 10%"); require( _minCollateralizationRatio >= 10, "Can't have minCollateralizationRatio < 1" @@ -262,13 +253,11 @@ contract OptionsContract is Ownable, ERC20 { liquidationIncentive.value = _liquidationIncentive; liquidationFactor.value = _liquidationFactor; - transactionFee.value = _transactionFee; minCollateralizationRatio.value = _minCollateralizationRatio; emit UpdateParameters( _liquidationIncentive, _liquidationFactor, - _transactionFee, _minCollateralizationRatio, owner() ); @@ -1052,6 +1041,15 @@ contract OptionsContract is Ownable, ERC20 { ); } + /** + * @dev internal function to parse token decimals for constructor + * @param _asset the asset address + */ + function getAssetExp(address _asset) internal view returns (int32) { + if (_asset == address(0)) return -18; + return -1 * int32(ERC20Detailed(_asset).decimals()); + } + /** * @notice This function gets the price ETH (wei) to asset price. * @param asset The address of the asset to get the price of diff --git a/contracts/OptionsFactory.sol b/contracts/OptionsFactory.sol index 476a4d2..7aeeb64 100644 --- a/contracts/OptionsFactory.sol +++ b/contracts/OptionsFactory.sol @@ -9,8 +9,7 @@ import "./packages/IERC20.sol"; contract OptionsFactory is Ownable { using StringComparator for string; - // keys saved in front-end -- look at the docs if needed - mapping(string => IERC20) public tokens; + mapping(address => bool) public whitelisted; address[] public optionsContracts; // The contract which interfaces with the exchange @@ -18,11 +17,7 @@ contract OptionsFactory is Ownable { address public oracleAddress; event OptionsContractCreated(address addr); - event AssetUpdated( - string indexed asset, - address indexed oldAddr, - address indexed newAddr - ); + event AssetWhitelisted(address indexed asset); /** * @param _optionsExchangeAddr: The contract which interfaces with the exchange @@ -37,63 +32,55 @@ contract OptionsFactory is Ownable { /** * @notice creates a new Option Contract - * @param _collateralType The collateral asset. Eg. "ETH" - * @param _collateralExp The number of decimals the collateral asset has - * @param _underlyingType The underlying asset. Eg. "DAI" - * @param _underlyingExp The precision of the underlying asset. Eg. (-18 if Dai) + * @param _collateral The collateral asset. Eg. "ETH" + * @param _underlying The underlying asset. Eg. "DAI" * @param _oTokenExchangeExp Units of underlying that 1 oToken protects * @param _strikePrice The amount of strike asset that will be paid out * @param _strikeExp The precision of the strike Price - * @param _strikeAsset The asset in which the insurance is calculated + * @param _strike The asset in which the insurance is calculated * @param _expiry The time at which the insurance expires * @param _windowSize UNIX time. Exercise window is from `expiry - _windowSize` to `expiry`. */ function createOptionsContract( - string calldata _collateralType, - int32 _collateralExp, - string calldata _underlyingType, - int32 _underlyingExp, + address _collateral, + address _underlying, + address _strike, int32 _oTokenExchangeExp, uint256 _strikePrice, int32 _strikeExp, - string calldata _strikeAsset, uint256 _expiry, - uint256 _windowSize + uint256 _windowSize, + string calldata _name, + string calldata _symbol ) external returns (address) { + require(whitelisted[_collateral], "Collateral not whitelisted."); + require(whitelisted[_underlying], "Underlying not whitelisted."); + require(whitelisted[_strike], "Strike not whitelisted."); + require(_expiry > block.timestamp, "Cannot create an expired option"); require(_windowSize <= _expiry, "Invalid _windowSize"); - require( - supportsAsset(_collateralType), - "Collateral type not supported" - ); - require( - supportsAsset(_underlyingType), - "Underlying type not supported" - ); - require(supportsAsset(_strikeAsset), "Strike asset type not supported"); - oToken optionsContract = new oToken( - tokens[_collateralType], - _collateralExp, - tokens[_underlyingType], - _underlyingExp, + oToken otoken = new oToken( + _collateral, + _underlying, + _strike, _oTokenExchangeExp, _strikePrice, _strikeExp, - tokens[_strikeAsset], _expiry, + _windowSize, optionsExchange, - oracleAddress, - _windowSize + oracleAddress ); - optionsContracts.push(address(optionsContract)); - emit OptionsContractCreated(address(optionsContract)); + otoken.setDetails(_name, _symbol); - // Set the owner for the options contract. - optionsContract.transferOwnership(owner()); + optionsContracts.push(address(otoken)); + emit OptionsContractCreated(address(otoken)); - return address(optionsContract); + // Set the owner for the options contract. + otoken.transferOwnership(owner()); + return address(otoken); } /** @@ -105,27 +92,10 @@ contract OptionsFactory is Ownable { /** * @notice The owner of the Factory Contract can update an asset's address, by adding it, changing the address or removing the asset - * @param _asset The ticker symbol for the asset - * @param _addr The address of the asset - */ - function updateAsset(string calldata _asset, address _addr) - external - onlyOwner - { - emit AssetUpdated(_asset, address(tokens[_asset]), _addr); - - tokens[_asset] = IERC20(_addr); - } - - /** - * @notice Check if the Factory contract supports a specific asset - * @param _asset The ticker symbol for the asset + * @param _asset The address for the asset */ - function supportsAsset(string memory _asset) public view returns (bool) { - if (_asset.compareStrings("ETH")) { - return true; - } - - return tokens[_asset] != IERC20(0); + function whitelistAsset(address _asset) external onlyOwner { + whitelisted[_asset] = true; + emit AssetWhitelisted(_asset); } } diff --git a/contracts/oToken.sol b/contracts/oToken.sol index 74f7794..0b1714e 100644 --- a/contracts/oToken.sol +++ b/contracts/oToken.sol @@ -14,9 +14,7 @@ contract oToken is OptionsContract { /** * @param _collateral The collateral asset - * @param _collExp The precision of the collateral (-18 if ETH) * @param _underlying The asset that is being protected - * @param _underlyingExp The precision of the underlying asset * @param _oTokenExchangeExp The precision of the `amount of underlying` that 1 oToken protects * @param _strikePrice The amount of strike asset that will be paid out * @param _strikeExp The precision of the strike asset (-18 if ETH) @@ -27,32 +25,28 @@ contract oToken is OptionsContract { * @param _windowSize UNIX time. Exercise window is from `expiry - _windowSize` to `expiry`. */ constructor( - IERC20 _collateral, - int32 _collExp, - IERC20 _underlying, - int32 _underlyingExp, + address _collateral, + address _underlying, + address _strike, int32 _oTokenExchangeExp, uint256 _strikePrice, int32 _strikeExp, - IERC20 _strike, uint256 _expiry, + uint256 _windowSize, OptionsExchange _optionsExchange, - address _oracleAddress, - uint256 _windowSize + address _oracleAddress ) public OptionsContract( _collateral, - _collExp, _underlying, - _underlyingExp, + _strike, _oTokenExchangeExp, _strikePrice, _strikeExp, - _strike, _expiry, - _oracleAddress, - _windowSize + _windowSize, + _oracleAddress ) { optionsExchange = _optionsExchange; diff --git a/test/add-remove-liquidate-burn.test.ts b/test/add-remove-liquidate-burn.test.ts index a1bc26c..320411f 100644 --- a/test/add-remove-liquidate-burn.test.ts +++ b/test/add-remove-liquidate-burn.test.ts @@ -1,15 +1,16 @@ import {expect} from 'chai'; import { - Erc20MintableInstance, + MockErc20Instance, MockOracleInstance, OptionsContractInstance, OptionsFactoryInstance } from '../build/types/truffle-types'; +import {ZERO_ADDRESS} from './utils/helper'; const OptionsContract = artifacts.require('OptionsContract'); const OptionsFactory = artifacts.require('OptionsFactory'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); const { time, @@ -29,8 +30,8 @@ contract('OptionsContract', accounts => { const optionsContracts: OptionsContractInstance[] = []; let optionsFactory: OptionsFactoryInstance; let compoundOracle: MockOracleInstance; - let dai: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let dai: MockErc20Instance; + let usdc: MockErc20Instance; const vault1Collateral = '20000000'; const vault1PutsOutstanding = '250000'; @@ -45,18 +46,19 @@ contract('OptionsContract', accounts => { // 1.2 Uniswap Factory // 1.3 Mock Dai contract - dai = await MintableToken.new(); + dai = await MockERC20.new('DAI', 'DAI', 18); await dai.mint(creatorAddress, '10000000'); await dai.mint(tokenHolder, '100000', {from: creatorAddress}); // 1.4 Mock Dai contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, '10000000'); // Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('DAI', dai.address); - await optionsFactory.updateAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(ZERO_ADDRESS); + await optionsFactory.whitelistAsset(dai.address); + await optionsFactory.whitelistAsset(usdc.address); // const windowSize = expiry; const now = (await time.latest()).toNumber(); @@ -64,22 +66,26 @@ contract('OptionsContract', accounts => { const windowSize = expiry; // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'DAI', - -'18', + ZERO_ADDRESS, + dai.address, + usdc.address, -'14', '9', -'15', - 'USDC', expiry, windowSize, + 'Opyn DAI:USDC option', + 'oDAI', {from: creatorAddress} ); const optionsContractAddr = optionsContractResult.logs[1].args[0]; optionsContracts.push(await OptionsContract.at(optionsContractAddr)); + await optionsContracts[0].updateParameters(10, 500, 16, { + from: creatorAddress + }); + // Open vault1, add Collateral and Mint oTokens await optionsContracts[0].openVault({ from: firstVaultOwnerAddress diff --git a/test/exercise-add-remove-liquidate-exersice.test.ts b/test/exercise-add-remove-liquidate-exersice.test.ts index c78d42a..87cb0ac 100644 --- a/test/exercise-add-remove-liquidate-exersice.test.ts +++ b/test/exercise-add-remove-liquidate-exersice.test.ts @@ -1,6 +1,6 @@ import {expect} from 'chai'; import { - Erc20MintableInstance, + MockErc20Instance, MockOracleInstance, OptionsContractInstance, OptionsFactoryInstance @@ -9,9 +9,10 @@ import { const OptionsContract = artifacts.require('OptionsContract'); const OptionsFactory = artifacts.require('OptionsFactory'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); import Reverter from './utils/reverter'; +import {ZERO_ADDRESS} from './utils/helper'; const { BN, @@ -36,8 +37,8 @@ contract('OptionsContract', accounts => { const optionsContracts: OptionsContractInstance[] = []; let optionsFactory: OptionsFactoryInstance; let compoundOracle: MockOracleInstance; - let dai: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let dai: MockErc20Instance; + let usdc: MockErc20Instance; const vault1Collateral = '20000000'; const vault1PutsOutstanding = '250000'; @@ -58,13 +59,13 @@ contract('OptionsContract', accounts => { compoundOracle = await MockOracle.deployed(); // 1.2 Mock Dai contract - dai = await MintableToken.new(); + dai = await MockERC20.new('Dai', 'Dai', 18); await dai.mint(creatorAddress, '10000000'); await dai.mint(firstExerciser, '100000', {from: creatorAddress}); await dai.mint(secondExerciser, '100000', {from: creatorAddress}); // 1.3 Mock Dai contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, '10000000'); // 2. Deploy our contracts @@ -72,28 +73,32 @@ contract('OptionsContract', accounts => { // Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('DAI', dai.address); - // TODO: deploy a mock USDC and get its address - await optionsFactory.updateAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(ZERO_ADDRESS); + await optionsFactory.whitelistAsset(dai.address); + await optionsFactory.whitelistAsset(usdc.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'DAI', - -'18', + ZERO_ADDRESS, + dai.address, + usdc.address, -'14', '9', -'15', - 'USDC', expiry, windowSize, + 'Opyn Dai:USDC Option', + 'oDAI', {from: creatorAddress} ); const optionsContractAddr = optionsContractResult.logs[1].args[0]; optionsContracts.push(await OptionsContract.at(optionsContractAddr)); + await optionsContracts[0].updateParameters(10, 500, 16, { + from: creatorAddress + }); + // Open vault1, add Collateral and Mint oTokens await optionsContracts[0].openVault({ from: firstVaultOwnerAddress @@ -576,7 +581,7 @@ contract('OptionsContract', accounts => { it('only owner should be able to update parameters', async () => { await expectRevert( - optionsContracts[0].updateParameters(0, 0, 0, 0, { + optionsContracts[0].updateParameters(0, 0, 0, { from: firstVaultOwnerAddress }), 'Ownable: caller is not the owner.' @@ -586,7 +591,6 @@ contract('OptionsContract', accounts => { it('owner should be able to update parameters', async () => { const liquidationIncentive = 20; const liquidationFactor = 1000; - const transactionFee = 10; const collateralizationRatio = 20; let currentCollateralizationRatio = await optionsContracts[0].minCollateralizationRatio(); @@ -595,7 +599,6 @@ contract('OptionsContract', accounts => { await optionsContracts[0].updateParameters( liquidationIncentive, liquidationFactor, - transactionFee, collateralizationRatio, {from: creatorAddress} ); diff --git a/test/exercise-erc20-collateral.test.ts b/test/exercise-erc20-collateral.test.ts index d0b398f..53c1ee2 100644 --- a/test/exercise-erc20-collateral.test.ts +++ b/test/exercise-erc20-collateral.test.ts @@ -1,5 +1,5 @@ import { - Erc20MintableInstance, + MockErc20Instance, OTokenInstance, OptionsFactoryInstance } from '../build/types/truffle-types'; @@ -7,7 +7,7 @@ import BN = require('bn.js'); const oToken = artifacts.require('oToken'); const OptionsFactory = artifacts.require('OptionsFactory'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); const {time, expectEvent, expectRevert} = require('@openzeppelin/test-helpers'); @@ -26,8 +26,8 @@ contract( ]) => { let otoken: OTokenInstance; let optionsFactory: OptionsFactoryInstance; - let weth: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let weth: MockErc20Instance; + let usdc: MockErc20Instance; let expiry: number; let mintAmount: BN; @@ -41,38 +41,36 @@ contract( await MockOracle.deployed(); // 1.2 Mock usdc contract - usdc = await MintableToken.new(); - weth = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); + weth = await MockERC20.new('WETH', 'WETH', 18); // 2. Deploy our contracts // Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('USDC', usdc.address); - await optionsFactory.updateAsset('WETH', weth.address); + await optionsFactory.whitelistAsset(usdc.address); + await optionsFactory.whitelistAsset(weth.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'USDC', - -6, - 'WETH', - -18, + usdc.address, + weth.address, + usdc.address, -6, 25, -5, - 'USDC', expiry, expiry, + 'Opyn Token', + 'oUSDC', {from: creatorAddress} ); const optionsContractAddr = optionsContractResult.logs[1].args[0]; otoken = await oToken.at(optionsContractAddr); // change collateral ratio to 1 - await otoken.setDetails('Opyn WETH:USDC', 'oETH', { - from: creatorAddress - }); - await otoken.updateParameters('100', '500', 0, 10, { + + await otoken.updateParameters('100', '500', 10, { from: creatorAddress }); }); diff --git a/test/exercise-eth-collateral.test.ts b/test/exercise-eth-collateral.test.ts index e0d564f..1f8b980 100644 --- a/test/exercise-eth-collateral.test.ts +++ b/test/exercise-eth-collateral.test.ts @@ -1,14 +1,15 @@ import {expect} from 'chai'; import { - Erc20MintableInstance, + MockErc20Instance, OTokenInstance, OptionsFactoryInstance } from '../build/types/truffle-types'; import BN = require('bn.js'); +import {ZERO_ADDRESS} from './utils/helper'; const oToken = artifacts.require('oToken'); const OptionsFactory = artifacts.require('OptionsFactory'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); const { time, @@ -23,7 +24,7 @@ contract( ([creatorAddress, owner1, owner2, exerciser, nonOwnerAddress]) => { let otoken: OTokenInstance; let optionsFactory: OptionsFactoryInstance; - let usdc: Erc20MintableInstance; + let usdc: MockErc20Instance; let expiry: number; let mintAmount: BN; @@ -38,36 +39,34 @@ contract( await MockOracle.deployed(); // 1.2 Mock usdc contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); // 2. Deploy our contracts // Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(usdc.address); + await optionsFactory.whitelistAsset(ZERO_ADDRESS); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'ETH', - -18, - 'USDC', - -6, + ZERO_ADDRESS, + usdc.address, + ZERO_ADDRESS, -6, 4, // strike price -9, // strike price exp - 'ETH', expiry, expiry, + 'Opyn USDC:ETH', + 'oUSDC', {from: creatorAddress} ); const optionsContractAddr = optionsContractResult.logs[1].args[0]; otoken = await oToken.at(optionsContractAddr); // change collateral ratio to 1 - await otoken.setDetails('Opyn USDC:ETH', 'oUSDC', { - from: creatorAddress - }); - await otoken.updateParameters('100', '500', 0, 10, { + await otoken.updateParameters('100', '500', 10, { from: creatorAddress }); diff --git a/test/liquidate.test.ts b/test/liquidate.test.ts index 78af1bf..8964413 100644 --- a/test/liquidate.test.ts +++ b/test/liquidate.test.ts @@ -1,6 +1,6 @@ import {expect} from 'chai'; import { - Erc20MintableInstance, + MockErc20Instance, MockOracleInstance, OptionsContractInstance, OptionsFactoryInstance @@ -9,10 +9,10 @@ import { const OptionsContract = artifacts.require('OptionsContract'); const OptionsFactory = artifacts.require('OptionsFactory'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); import Reverter from './utils/reverter'; -import {checkVault} from './utils/helper'; +import {checkVault, ZERO_ADDRESS} from './utils/helper'; const { BN, time, @@ -35,8 +35,8 @@ contract('OptionsContract', accounts => { const optionsContracts: OptionsContractInstance[] = []; let optionsFactory: OptionsFactoryInstance; let compoundOracle: MockOracleInstance; - let dai: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let dai: MockErc20Instance; + let usdc: MockErc20Instance; const vault1Collateral = '20000000'; const vault1PutsOutstanding = '250000'; @@ -53,13 +53,13 @@ contract('OptionsContract', accounts => { compoundOracle = await MockOracle.deployed(); // 1.2 Mock Dai contract - dai = await MintableToken.new(); + dai = await MockERC20.new('DAI', 'DAI', 18); await dai.mint(creatorAddress, '10000000'); await dai.mint(firstExerciser, '100000', {from: creatorAddress}); await dai.mint(secondExerciser, '100000', {from: creatorAddress}); // 1.3 Mock Dai contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, '10000000'); // 2. Deploy our contracts @@ -67,22 +67,23 @@ contract('OptionsContract', accounts => { // Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('DAI', dai.address); + await optionsFactory.whitelistAsset(ZERO_ADDRESS); + await optionsFactory.whitelistAsset(dai.address); // TODO: deploy a mock USDC and get its address - await optionsFactory.updateAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(usdc.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'DAI', - -'18', + ZERO_ADDRESS, + dai.address, + usdc.address, -'14', '9', -'15', - 'USDC', expiry, windowSize, + 'Opyn DAI:USDC', + 'oDAI', {from: creatorAddress} ); diff --git a/test/miltiple-exercise.test.ts b/test/miltiple-exercise.test.ts index aead014..8db2af4 100644 --- a/test/miltiple-exercise.test.ts +++ b/test/miltiple-exercise.test.ts @@ -1,6 +1,6 @@ import {expect} from 'chai'; import { - Erc20MintableInstance, + MockErc20Instance, MockOracleInstance, OptionsContractInstance, OptionsFactoryInstance @@ -9,8 +9,9 @@ import { const OptionsContract = artifacts.require('OptionsContract'); const OptionsFactory = artifacts.require('OptionsFactory'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); +import {ZERO_ADDRESS} from './utils/helper'; import Reverter from './utils/reverter'; const {BN, balance, time, expectEvent} = require('@openzeppelin/test-helpers'); @@ -28,8 +29,8 @@ contract('OptionsContract', accounts => { const optionsContracts: OptionsContractInstance[] = []; let optionsFactory: OptionsFactoryInstance; let compoundOracle: MockOracleInstance; - let dai: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let dai: MockErc20Instance; + let usdc: MockErc20Instance; const vault1Collateral = '20000000'; const vault1PutsOutstanding = '250000'; @@ -49,41 +50,46 @@ contract('OptionsContract', accounts => { compoundOracle = await MockOracle.deployed(); // 1.2 Mock Dai contract - dai = await MintableToken.new(); + dai = await MockERC20.new('DAI', 'DAI', 18); await dai.mint(creatorAddress, '10000000'); await dai.mint(firstExerciser, '100000', {from: creatorAddress}); await dai.mint(secondExerciser, '100000', {from: creatorAddress}); // 1.3 Mock Dai contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, '10000000'); // 2. Deploy our contracts // Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('DAI', dai.address); + await optionsFactory.whitelistAsset(ZERO_ADDRESS); + await optionsFactory.whitelistAsset(dai.address); // TODO: deploy a mock USDC and get its address - await optionsFactory.updateAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(usdc.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'DAI', - -'18', + ZERO_ADDRESS, + dai.address, + usdc.address, -'14', '9', -'15', - 'USDC', expiry, windowSize, + 'Opyn DAI:USDC', + 'oDAI', {from: creatorAddress} ); const optionsContractAddr = optionsContractResult.logs[1].args[0]; optionsContracts.push(await OptionsContract.at(optionsContractAddr)); + await optionsContracts[0].updateParameters(10, 500, 16, { + from: creatorAddress + }); + // Open vault1, add Collateral and Mint oTokens await optionsContracts[0].openVault({ from: firstVaultOwnerAddress diff --git a/test/optionsContract.test.ts b/test/optionsContract.test.ts index c95c730..3e5b972 100644 --- a/test/optionsContract.test.ts +++ b/test/optionsContract.test.ts @@ -1,6 +1,6 @@ import {expect} from 'chai'; import { - Erc20MintableInstance, + MockErc20Instance, OptionsFactoryInstance, MockOracleInstance, OptionsContractInstance @@ -9,7 +9,7 @@ import { const OptionsContract = artifacts.require('OptionsContract'); const OptionsFactory = artifacts.require('OptionsFactory'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); const truffleAssert = require('truffle-assertions'); @@ -34,9 +34,9 @@ contract('OptionsContract', accounts => { const optionsContracts: OptionsContractInstance[] = []; let optionsFactory: OptionsFactoryInstance; let oracle: MockOracleInstance; - let weth: Erc20MintableInstance; - let dai: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let weth: MockErc20Instance; + let dai: MockErc20Instance; + let usdc: MockErc20Instance; let expiry: number; let windowSize: number; @@ -49,13 +49,13 @@ contract('OptionsContract', accounts => { // 1.1 Compound Oracle oracle = await MockOracle.new(); - weth = await MintableToken.new(); + weth = await MockERC20.new('WETH', 'WETH', 18); // 1.2 Mock Dai contract - dai = await MintableToken.new(); + dai = await MockERC20.new('DAI', 'DAI', 18); await dai.mint(creatorAddress, '10000000'); // 1.3 Mock USDC contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, '10000000'); await usdc.mint(nonOwnerAddress, '10000000'); @@ -65,39 +65,44 @@ contract('OptionsContract', accounts => { // Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('WETH', weth.address); - await optionsFactory.updateAsset('DAI', dai.address); - await optionsFactory.updateAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(ZERO_ADDRESS); + await optionsFactory.whitelistAsset(weth.address); + await optionsFactory.whitelistAsset(dai.address); + await optionsFactory.whitelistAsset(usdc.address); // Create the unexpired options contract let optionsContractResult = await optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'DAI', - -'18', + ZERO_ADDRESS, + dai.address, + ZERO_ADDRESS, -'17', '90', -'18', - 'ETH', expiry, windowSize, + 'Opyn Token', + 'oDAI', {from: creatorAddress} ); let optionsContractAddr = optionsContractResult.logs[1].args[0]; optionsContracts.push(await OptionsContract.at(optionsContractAddr)); + await optionsContracts[0].updateParameters(10, 500, 16, { + from: creatorAddress + }); + optionsContractResult = await optionsFactory.createOptionsContract( - 'USDC', - -'18', - 'DAI', - -'18', + usdc.address, + dai.address, + usdc.address, -'17', '90', -'18', - 'USDC', expiry, windowSize, + 'Opyn Token', + 'oDai', {from: creatorAddress} ); @@ -107,6 +112,10 @@ contract('OptionsContract', accounts => { ); optionsContracts.push(ERC20collateralOptContract); + await optionsContracts[1].updateParameters(10, 500, 16, { + from: creatorAddress + }); + await reverter.snapshot(); }); @@ -116,16 +125,14 @@ contract('OptionsContract', accounts => { await expectRevert( OptionsContract.new( usdc.address, - -'18', dai.address, - -'18', + usdc.address, -'17', '90', -'18', - usdc.address, expiry, - oracle.address, - windowSize + windowSize, + oracle.address ), "Can't deploy an expired contract" ); @@ -135,54 +142,50 @@ contract('OptionsContract', accounts => { await expectRevert( OptionsContract.new( usdc.address, - -'18', dai.address, - -'18', + usdc.address, -'17', '90', -'18', - usdc.address, expiry, - oracle.address, - expiry + 1 + expiry + 1, + oracle.address ), "Exercise window can't be longer than the contract's lifespan" ); }); it('should revert with invalid collateral exponent range', async () => { + const wrongToken = await MockERC20.new('Wrong', 'wrong', 31); await expectRevert( OptionsContract.new( - usdc.address, - -'31', + wrongToken.address, dai.address, - -'18', + usdc.address, -'17', '90', -'18', - usdc.address, expiry, - oracle.address, - expiry + expiry, + oracle.address ), 'collateral exponent not within expected range' ); }); it('should revert with invalid underlying exponent range', async () => { + const wrongToken = await MockERC20.new('Wrong', 'wrong', 31); await expectRevert( OptionsContract.new( usdc.address, - -'18', - dai.address, - -'31', + wrongToken.address, + usdc.address, -'17', '90', -'18', - usdc.address, expiry, - oracle.address, - expiry + expiry, + oracle.address ), 'underlying exponent not within expected range' ); @@ -192,16 +195,14 @@ contract('OptionsContract', accounts => { await expectRevert( OptionsContract.new( usdc.address, - -'18', dai.address, - -'18', + usdc.address, -'17', '90', -'31', - usdc.address, expiry, - oracle.address, - expiry + expiry, + oracle.address ), 'strike price exponent not within expected range' ); @@ -211,16 +212,14 @@ contract('OptionsContract', accounts => { await expectRevert( OptionsContract.new( usdc.address, - -'18', dai.address, - -'18', + usdc.address, -'31', '90', -'18', - usdc.address, expiry, - oracle.address, - expiry + expiry, + oracle.address ), 'oToken exchange rate exponent not within expected range' ); @@ -230,16 +229,14 @@ contract('OptionsContract', accounts => { await expectRevert( OptionsContract.new( ZERO_ADDRESS, - -'18', ZERO_ADDRESS, - -'18', + ZERO_ADDRESS, -'17', '90', -'18', - ZERO_ADDRESS, expiry, - oracle.address, - expiry + expiry, + oracle.address ), "OptionsContract: Can't use ETH as underlying" ); @@ -248,16 +245,14 @@ contract('OptionsContract', accounts => { it('should create a option with eth as collateral, strike, DAI as underlying ', async () => { await OptionsContract.new( ZERO_ADDRESS, - -'18', dai.address, - -'18', + ZERO_ADDRESS, -'17', '90', -'18', - ZERO_ADDRESS, expiry, - oracle.address, - expiry + expiry, + oracle.address ); }); }); @@ -266,16 +261,14 @@ contract('OptionsContract', accounts => { it('should set detail for the valid otoken', async () => { const validOtoken = await OptionsContract.new( usdc.address, - -'18', dai.address, - -'18', + usdc.address, 1, '90', -'18', - usdc.address, expiry, - oracle.address, - expiry + expiry, + oracle.address ); await validOtoken.setDetails('Valid Otoken', 'oDAI'); const name = await validOtoken.name(); @@ -288,63 +281,53 @@ contract('OptionsContract', accounts => { before('Create a test option', async () => { option = await OptionsContract.new( ZERO_ADDRESS, - -18, usdc.address, - -6, + ZERO_ADDRESS, -6, 4, // strike price -9, // strike price exp - ZERO_ADDRESS, expiry, - oracle.address, expiry, + oracle.address, {from: creatorAddress} ); }); it('should revert when calling from other address', async () => { await expectRevert( - option.updateParameters(100, 500, 0, 10, {from: random}), + option.updateParameters(100, 500, 10, {from: random}), 'Ownable: caller is not the owner' ); }); it('should revert when trying to set liquidation incentive > 200%', async () => { await expectRevert( - option.updateParameters(201, 500, 0, 10), // + option.updateParameters(201, 500, 10), // "Can't have >20% liquidation incentive" ); }); - it('should revert when trying to set transaction fee > 10%', async () => { - await expectRevert( - option.updateParameters(100, 500, 101, 10), // - "Can't have transaction fee > 10%" - ); - }); - it('should revert when trying to set liquidation factor > 100%', async () => { await expectRevert( - option.updateParameters(100, 1001, 0, 10), // + option.updateParameters(100, 1001, 10), // "Can't liquidate more than 100% of the vault" ); }); it('should revert when trying to set collateral ratio < 1', async () => { await expectRevert( - option.updateParameters(100, 500, 0, 9), // + option.updateParameters(100, 500, 9), // "Can't have minCollateralizationRatio < 1" ); }); it('should emit UpdateParameters event ', async () => { expectEvent( - await option.updateParameters(200, 500, 0, 10), // + await option.updateParameters(200, 500, 10), // 'UpdateParameters', { liquidationIncentive: '200', liquidationFactor: '500', - transactionFee: '0', minCollateralizationRatio: '10' } ); @@ -764,26 +747,24 @@ contract('OptionsContract', accounts => { describe('#harvest', () => { const amount = '100000000'; let otoken: OptionsContractInstance; - let bonusToken: Erc20MintableInstance; + let bonusToken: MockErc20Instance; before('contract setup', async () => { const now = (await time.latest()).toNumber(); expiry = now + time.duration.days(30).toNumber(); windowSize = expiry; otoken = await OptionsContract.new( weth.address, - -'18', dai.address, - -'18', + usdc.address, -'17', '90', -'18', - usdc.address, expiry, - oracle.address, windowSize, + oracle.address, {from: creatorAddress} ); - bonusToken = await MintableToken.new(); + bonusToken = await MockERC20.new('BONUS', 'BONUS', 18); await bonusToken.mint(otoken.address, amount); }); diff --git a/test/optionsFactory.test.ts b/test/optionsFactory.test.ts index ec9c0a2..07f98e4 100644 --- a/test/optionsFactory.test.ts +++ b/test/optionsFactory.test.ts @@ -1,9 +1,12 @@ import {expect} from 'chai'; -import {OptionsFactoryInstance} from '../build/types/truffle-types'; +import { + OptionsFactoryInstance, + MockErc20Instance +} from '../build/types/truffle-types'; -const Web3Utils = require('web3-utils'); const OptionsFactory = artifacts.require('OptionsFactory'); const OptionsContract = artifacts.require('OptionsContract'); +const MockERC20 = artifacts.require('MockERC20'); import {getUnixTime, addSeconds, fromUnixTime} from 'date-fns'; @@ -13,20 +16,12 @@ const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; contract( 'OptionsFactory', - ([ - creatorAddress, - firstOwnerAddress, - DAIAddress, - BATAddress, - BATAddress2, - USDCAddress, - WEIRDToken, - random - ]) => { + ([creatorAddress, firstOwnerAddress, DAIAddress, random]) => { let optionsFactory: OptionsFactoryInstance; let expiry: number; let windowSize: number; + let dai: MockErc20Instance; before(async () => { const now = (await time.latest()).toNumber(); @@ -38,55 +33,32 @@ contract( // Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); + + dai = await MockERC20.new('DAI', 'DAI', 18); }); describe('#updateAsset()', () => { - it('should add an asset correctly', async () => { - const txInfo = await optionsFactory.updateAsset('DAI', DAIAddress); - expectEvent(txInfo, 'AssetUpdated', { - asset: Web3Utils.keccak256('DAI'), - newAddr: DAIAddress + it('should whitelist an asset', async () => { + const txInfo = await optionsFactory.whitelistAsset(ZERO_ADDRESS); + expectEvent(txInfo, 'AssetWhitelisted', { + asset: ZERO_ADDRESS }); - const supported = await optionsFactory.supportsAsset('DAI'); - + const supported = await optionsFactory.whitelisted(ZERO_ADDRESS); expect(supported).to.be.true; }); it('should add a second asset', async () => { - const txInfo = await optionsFactory.updateAsset('BAT', BATAddress); - expectEvent(txInfo, 'AssetUpdated', { - asset: Web3Utils.keccak256('BAT'), - newAddr: BATAddress + const txInfo = await optionsFactory.whitelistAsset(dai.address); + expectEvent(txInfo, 'AssetWhitelisted', { + asset: dai.address }); - const supported = await optionsFactory.supportsAsset('BAT'); - + const supported = await optionsFactory.whitelisted(dai.address); expect(supported).to.be.true; }); it('should fails if anyone but owner tries to add asset', async () => { await expectRevert( - optionsFactory.updateAsset( - 'ETH', - '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359', - {from: random} - ), - 'Ownable: caller is not the owner' - ); - }); - }); - - describe('#updateAsset()', () => { - it('should change an asset that exists correctly', async () => { - const txInfo = await optionsFactory.updateAsset('BAT', BATAddress2); - expectEvent(txInfo, 'AssetUpdated', { - asset: Web3Utils.keccak256('BAT'), - newAddr: BATAddress2 - }); - }); - - it('should revert if anyone but owner tries to change asset', async () => { - await expectRevert( - optionsFactory.updateAsset('BAT', BATAddress, {from: random}), // try change it back to BATAddr + optionsFactory.whitelistAsset(random, {from: random}), 'Ownable: caller is not the owner' ); }); @@ -98,16 +70,16 @@ contract( await expectRevert( optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'ETH', - -'18', + ZERO_ADDRESS, + ZERO_ADDRESS, + ZERO_ADDRESS, -'17', '90', -'18', - 'ETH', expiredExpiry, expiredExpiry, + 'Opyn Token', + 'oETH', {from: creatorAddress} ), 'Cannot create an expired option' @@ -119,16 +91,16 @@ contract( await expectRevert( optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'ETH', - -'18', + ZERO_ADDRESS, + ZERO_ADDRESS, + ZERO_ADDRESS, -'17', '90', -'18', - 'ETH', expiry, bigWindowSize, + 'Opyn Token', + 'oETH', {from: creatorAddress} ), 'Invalid _windowSize' @@ -138,72 +110,72 @@ contract( it('should not allow to create a new options with unsupported collateral', async () => { await expectRevert( optionsFactory.createOptionsContract( - 'WRONG', - -'18', - 'ETH', - -'18', + random, + ZERO_ADDRESS, + ZERO_ADDRESS, -'17', '90', -'18', - 'ETH', expiry, expiry, + 'Opyn Token', + 'oETH', {from: creatorAddress} ), - 'Collateral type not supported' + 'Collateral not whitelisted' ); }); it('should not allow to create a new options with unsupported underlying', async () => { await expectRevert( optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'WRONG', - -'18', + ZERO_ADDRESS, + random, + ZERO_ADDRESS, -'17', '90', -'18', - 'ETH', expiry, expiry, + 'Opyn Token', + 'oRANDOM', {from: creatorAddress} ), - 'Underlying type not supported' + 'Underlying not whitelisted' ); }); it('should not allow to create a new options with unsupported strike', async () => { await expectRevert( optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'ETH', - -'18', + ZERO_ADDRESS, + ZERO_ADDRESS, + random, -'17', '90', -'18', - 'WRONG', expiry, expiry, + 'Opyn Token', + 'oETH', {from: creatorAddress} ), - 'Strike asset type not supported' + 'Strike not whitelisted.' ); }); it('should create a new options contract correctly', async () => { const txInfo = await optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'DAI', - -'18', + ZERO_ADDRESS, + dai.address, + ZERO_ADDRESS, -'17', '90', -'18', - 'ETH', expiry, windowSize, + 'Opyn Token', + 'oDAI', {from: creatorAddress} ); @@ -218,16 +190,16 @@ contract( }); it('anyone else should be able to create a second options contract correctly', async () => { const txInfo = await optionsFactory.createOptionsContract( - 'ETH', - -'18', - 'DAI', + ZERO_ADDRESS, + dai.address, + ZERO_ADDRESS, -'18', - -'17', '90', -'18', - 'ETH', expiry, windowSize, + 'Opyn Token', + 'oDAI', {from: firstOwnerAddress} ); diff --git a/test/otoken.test.ts b/test/otoken.test.ts index 3d5c9a1..3ac770e 100644 --- a/test/otoken.test.ts +++ b/test/otoken.test.ts @@ -1,5 +1,5 @@ import { - Erc20MintableInstance, + MockErc20Instance, MockOracleInstance, OTokenInstance, MockOtokensExchangeInstance @@ -10,7 +10,7 @@ import BN = require('bn.js'); const OToken = artifacts.require('oToken'); const MockOtokensExchange = artifacts.require('MockOtokensExchange'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); const {time, expectRevert, send} = require('@openzeppelin/test-helpers'); @@ -29,8 +29,8 @@ contract('OToken', accounts => { let exchange: MockOtokensExchangeInstance; let oracle: MockOracleInstance; - let dai: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let dai: MockErc20Instance; + let usdc: MockErc20Instance; let otoken1: OTokenInstance; // erc20 collateral options let otoken2: OTokenInstance; // eth collateral options @@ -47,13 +47,13 @@ contract('OToken', accounts => { oracle = await MockOracle.new(); // 1.2 Mock Dai contract - dai = await MintableToken.new(); + dai = await MockERC20.new('DAI', 'DAI', 18); await dai.mint(creatorAddress, '10000000'); exchange = await MockOtokensExchange.new(); // 1.3 Mock USDC contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, '10000000000'); await usdc.mint(firstOwner, '10000000000'); await usdc.mint(secondOwner, '10000000000'); @@ -64,34 +64,30 @@ contract('OToken', accounts => { it('should create an ERC20 collateral option', async () => { otoken1 = await OToken.new( usdc.address, - -'18', dai.address, - -'18', + usdc.address, -'17', '90', -'18', - usdc.address, expiry, + windowSize, exchange.address, - oracle.address, - windowSize + oracle.address ); }); it('should create an ETH collateral option', async () => { otoken2 = await OToken.new( ZERO_ADDRESS, - -'18', dai.address, - -'18', + usdc.address, -'17', '90', -'18', - usdc.address, expiry, + windowSize, exchange.address, - oracle.address, - windowSize + oracle.address ); }); }); diff --git a/test/sell-and-buy.test.ts b/test/sell-and-buy.test.ts index 0995d29..22665fb 100644 --- a/test/sell-and-buy.test.ts +++ b/test/sell-and-buy.test.ts @@ -1,6 +1,6 @@ /*import {expect} from 'chai'; import { - Erc20MintableInstance, + MockErc20Instance, OTokenInstance, OptionsFactoryInstance, OptionsExchangeInstance, @@ -13,7 +13,7 @@ import { import {Address} from 'cluster'; const OptionsFactory = artifacts.require('OptionsFactory'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); const UniswapFactory = artifacts.require('UniswapFactoryInterface'); const UniswapExchange = artifacts.require('UniswapExchangeInterface'); const OptionsExchange = artifacts.require('OptionsExchange.sol'); @@ -59,8 +59,8 @@ contract('OptionsContract', accounts => { const optionsContracts: OTokenInstance[] = []; let optionsFactory: OptionsFactoryInstance; - let dai: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let dai: MockErc20Instance; + let usdc: MockErc20Instance; let uniswapFactory: UniswapFactoryInterfaceInstance; let optionsExchange: OptionsExchangeInstance; let oracle: OracleInstance; @@ -120,9 +120,9 @@ contract('OptionsContract', accounts => { if (!contractsDeployed) { oracle = await Oracle.deployed(); // 1.2 Mock Dai contract - dai = await MintableToken.at(daiAddress); + dai = await MockERC20.at(daiAddress); // 1.3 USDC contract - usdc = await MintableToken.at(usdcAddress); + usdc = await MockERC20.at(usdcAddress); // 2. Deploy our contracts // Deploy the Options Exchange @@ -434,7 +434,7 @@ contract('OptionsContract', accounts => { xit('should be able to buy oTokens with ERC20s', async () => { const paymentTokenAddr = '0x2448eE2641d78CC42D7AD76498917359D961A783'; - const paymentToken = await MintableToken.at(paymentTokenAddr); + const paymentToken = await MockERC20.at(paymentTokenAddr); // set to optionsCotnracs[0].address const oTokenAddress = optionsContractAddresses[0]; await paymentToken.approve( diff --git a/test/series/bal-put.test.ts b/test/series/bal-put.test.ts index a850b4d..047214b 100644 --- a/test/series/bal-put.test.ts +++ b/test/series/bal-put.test.ts @@ -1,7 +1,7 @@ import { OptionsFactoryInstance, OTokenInstance, - Erc20MintableInstance + MockErc20Instance } from '../../build/types/truffle-types'; import BigNumber from 'bignumber.js'; @@ -9,7 +9,7 @@ const {time, expectEvent} = require('@openzeppelin/test-helpers'); const OTokenContract = artifacts.require('oToken'); const OptionsFactory = artifacts.require('OptionsFactory'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); import Reverter from '../utils/reverter'; @@ -22,8 +22,8 @@ contract('OptionsContract: BAL put', accounts => { let optionsFactory: OptionsFactoryInstance; let oToken: OTokenInstance; - let bal: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let bal: MockErc20Instance; + let usdc: MockErc20Instance; const _name = 'Opyn BAL Put $7 08/28/20'; const _symbol = 'oBALp $7'; @@ -44,32 +44,33 @@ contract('OptionsContract: BAL put', accounts => { // oracle = MockOracle.at() // 1.2 Mock BAL contract - bal = await MintableToken.new(); + bal = await MockERC20.new('bal', 'bal', 18); await bal.mint(creatorAddress, new BigNumber(1000).times(balDigits)); // 1000 bal await bal.mint(firstOwner, new BigNumber(1000).times(balDigits)); await bal.mint(tokenHolder, new BigNumber(1000).times(balDigits)); // 1.3 Mock USDT contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, new BigNumber(7000).times(usdcDigits)); // 1000 USDC await usdc.mint(firstOwner, new BigNumber(7000).times(usdcDigits)); // 2. Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('BAL', bal.address); - await optionsFactory.updateAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(bal.address); + await optionsFactory.whitelistAsset(usdc.address); + const optionsContractResult = await optionsFactory.createOptionsContract( - 'USDC', - -6, - 'BAL', - -18, + usdc.address, + bal.address, + usdc.address, -_tokenDecimals, 7, -7, - 'USDC', expiry, windowSize, + _name, + _symbol, {from: creatorAddress} ); @@ -81,16 +82,12 @@ contract('OptionsContract: BAL put', accounts => { describe('New option parameter test', () => { it('should have basic setting', async () => { - await oToken.setDetails(_name, _symbol, { - from: creatorAddress - }); - assert.equal(await oToken.name(), String(_name), 'set name error'); assert.equal(await oToken.symbol(), String(_symbol), 'set symbol error'); }); it('should update parameters', async () => { - await oToken.updateParameters(0, 500, 0, 10, { + await oToken.updateParameters(0, 500, 10, { from: creatorAddress }); }); diff --git a/test/series/comp-put.test.ts b/test/series/comp-put.test.ts index ed50467..58f99fa 100644 --- a/test/series/comp-put.test.ts +++ b/test/series/comp-put.test.ts @@ -1,7 +1,7 @@ import { OptionsFactoryInstance, OTokenInstance, - Erc20MintableInstance + MockErc20Instance } from '../../build/types/truffle-types'; import BigNumber from 'bignumber.js'; @@ -9,7 +9,7 @@ const {time, expectRevert, expectEvent} = require('@openzeppelin/test-helpers'); const OTokenContract = artifacts.require('oToken'); const OptionsFactory = artifacts.require('OptionsFactory'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); import Reverter from '../utils/reverter'; @@ -23,8 +23,8 @@ contract('OptionsContract: COMP put', accounts => { let optionsFactory: OptionsFactoryInstance; let oComp: OTokenInstance; // let oracle: MockOracleInstance; - let comp: Erc20MintableInstance; - let usdc: Erc20MintableInstance; + let comp: MockErc20Instance; + let usdc: MockErc20Instance; const usdcAmount = '1000000000'; // 1000 USDC const compAmount = '1000000000000000000000'; // 1000 comp @@ -39,33 +39,33 @@ contract('OptionsContract: COMP put', accounts => { // 1. Deploy mock contracts // 1.2 Mock Comp contract - comp = await MintableToken.new(); + comp = await MockERC20.new('COMP', 'COMP', 18); await comp.mint(creatorAddress, compAmount); // 1000 comp await comp.mint(tokenHolder, compAmount); // 1.3 Mock USDC contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, usdcAmount); await usdc.mint(firstOwner, usdcAmount); // 2. Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('COMP', comp.address); - await optionsFactory.updateAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(comp.address); + await optionsFactory.whitelistAsset(usdc.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'USDC', - -6, - 'COMP', - -18, + usdc.address, + comp.address, + usdc.address, -6, 25, -5, - 'USDC', expiry, windowSize, + _name, + _symbol, {from: creatorAddress} ); @@ -77,16 +77,12 @@ contract('OptionsContract: COMP put', accounts => { describe('New option parameter test', () => { it('should have basic setting', async () => { - await oComp.setDetails(_name, _symbol, { - from: creatorAddress - }); - assert.equal(await oComp.name(), String(_name), 'set name error'); assert.equal(await oComp.symbol(), String(_symbol), 'set symbol error'); }); it('should update parameters', async () => { - await oComp.updateParameters('100', '500', 0, 10, {from: creatorAddress}); + await oComp.updateParameters('100', '500', 10, {from: creatorAddress}); }); it('should open empty vault', async () => { diff --git a/test/series/eth-call.test.ts b/test/series/eth-call.test.ts index 6cfb064..1f13ebe 100644 --- a/test/series/eth-call.test.ts +++ b/test/series/eth-call.test.ts @@ -1,5 +1,5 @@ import { - Erc20MintableInstance, + MockErc20Instance, OptionsContractInstance, OptionsFactoryInstance } from '../../build/types/truffle-types'; @@ -8,9 +8,9 @@ import BigNumber from 'bignumber.js'; const OptionsContract = artifacts.require('OptionsContract'); const OptionsFactory = artifacts.require('OptionsFactory'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); -import {calculateMaxOptionsToCreate} from '../utils/helper'; +import {calculateMaxOptionsToCreate, ZERO_ADDRESS} from '../utils/helper'; const {expectRevert, ether, time} = require('@openzeppelin/test-helpers'); contract( @@ -26,24 +26,22 @@ contract( ]) => { let optionContract: OptionsContractInstance; let optionsFactory: OptionsFactoryInstance; - let usdc: Erc20MintableInstance; + let usdc: MockErc20Instance; const _name = 'test call option $280'; const _symbol = 'test oETH $280'; - const _collateralType = 'ETH'; + const _collateralExp = -18; - const _underlyingType = 'USDC'; + const _underlyingExp = -6; const _oTokenExchangeExp = -6; const _strikePrice = 3571428; const _strikeExp = -15; - const _strikeAsset = 'ETH'; let _expiry: number; let _windowSize: number; const _liquidationIncentiveValue = 0; const _liquidationFactorValue = 0; - const _transactionFeeValue = 0; const _minCollateralizationRatioValue = 10; const _minCollateralizationRatioExp = -1; @@ -56,7 +54,7 @@ contract( _windowSize = _expiry; // time.duration.days(1).toNumber(); // usdc token - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); // get deployed opyn protocol contracts @@ -64,22 +62,25 @@ contract( optionsFactory = await OptionsFactory.deployed(); // add assets to the factory - await optionsFactory.updateAsset('USDC', usdc.address, { + await optionsFactory.whitelistAsset(ZERO_ADDRESS, { + from: opynDeployer + }); + await optionsFactory.whitelistAsset(usdc.address, { from: opynDeployer }); // create ETH call option const optionsContractResult = await optionsFactory.createOptionsContract( - _collateralType, - _collateralExp, - _underlyingType, - _underlyingExp, + ZERO_ADDRESS, + usdc.address, + ZERO_ADDRESS, _oTokenExchangeExp, _strikePrice, _strikeExp, - _strikeAsset, _expiry, _windowSize, + _name, + _symbol, {from: opynDeployer} ); @@ -94,7 +95,6 @@ contract( await optionContract.updateParameters( _liquidationIncentiveValue, _liquidationFactorValue, - _transactionFeeValue, _minCollateralizationRatioValue, {from: opynDeployer} ); @@ -114,7 +114,7 @@ contract( assert.equal(await optionContract.symbol(), _symbol, 'invalid symbol'); assert.equal( await optionContract.collateral(), - await optionsFactory.tokens(_collateralType), + ZERO_ADDRESS, 'invalid collateral' ); assert.equal( @@ -124,7 +124,7 @@ contract( ); assert.equal( await optionContract.underlying(), - await optionsFactory.tokens(_underlyingType), + usdc.address, 'invalid underlying' ); assert.equal( @@ -149,7 +149,7 @@ contract( ); assert.equal( await optionContract.strike(), - await optionsFactory.tokens(_strikeAsset), + ZERO_ADDRESS, 'invalid strike asset' ); assert.equal( diff --git a/test/series/eth-cusdc-put.test.ts b/test/series/eth-cusdc-put.test.ts index 224561d..e01b8cf 100644 --- a/test/series/eth-cusdc-put.test.ts +++ b/test/series/eth-cusdc-put.test.ts @@ -3,7 +3,6 @@ import { MockErc20Instance, MockCtokenInstance, MockCompoundOracleInstance, - MockOracleInstance, MockOtokensExchangeInstance, OracleInstance } from '../../build/types/truffle-types'; @@ -12,7 +11,6 @@ import BigNumber from 'bignumber.js'; const {time, expectRevert, expectEvent} = require('@openzeppelin/test-helpers'); const OTokenContract = artifacts.require('oToken'); -const OptionsContract = artifacts.require('OptionsContract'); const Oracle = artifacts.require('Oracle'); const MockCompoundOracle = artifacts.require('MockCompoundOracle'); @@ -88,17 +86,15 @@ contract('OptionsContract: ETH:cUSDC Put', accounts => { // Create the unexpired options contract oETH = await OTokenContract.new( cusdc.address, - -8, weth.address, - -18, + usdc.address, -7, 25, -6, - usdc.address, expiry, + windowSize, exchange.address, oracle.address, - windowSize, {from: creatorAddress} ); }); @@ -113,10 +109,6 @@ contract('OptionsContract: ETH:cUSDC Put', accounts => { assert.equal(await oETH.symbol(), String(_symbol), 'set symbol error'); }); - it('should update parameters', async () => { - await oETH.updateParameters('100', '500', 0, 10, {from: creatorAddress}); - }); - it('should open empty vault', async () => { await oETH.openVault({ from: creatorAddress diff --git a/test/series/eth-put.test.ts b/test/series/eth-put.test.ts index f5309fd..ae7854a 100644 --- a/test/series/eth-put.test.ts +++ b/test/series/eth-put.test.ts @@ -1,7 +1,7 @@ import { OptionsFactoryInstance, OTokenInstance, - Erc20MintableInstance + MockErc20Instance } from '../../build/types/truffle-types'; import BigNumber from 'bignumber.js'; @@ -9,7 +9,7 @@ const {time, expectRevert, expectEvent} = require('@openzeppelin/test-helpers'); const OTokenContract = artifacts.require('oToken'); const OptionsFactory = artifacts.require('OptionsFactory'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); import Reverter from '../utils/reverter'; contract('OptionsContract: ETH put', accounts => { @@ -22,9 +22,9 @@ contract('OptionsContract: ETH put', accounts => { let optionsFactory: OptionsFactoryInstance; let oETH: OTokenInstance; // let oracle: MockOracleInstance; - // let comp: Erc20MintableInstance; - let usdc: Erc20MintableInstance; - let weth: Erc20MintableInstance; + // let comp: MockErc20Instance; + let usdc: MockErc20Instance; + let weth: MockErc20Instance; const usdcAmount = '1000000000'; // 1000 USDC @@ -40,29 +40,29 @@ contract('OptionsContract: ETH put', accounts => { // 1.2 Mock Comp contract // 1.3 Mock USDC contract - usdc = await MintableToken.new(); - weth = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); + weth = await MockERC20.new('WETH', 'WETH', 18); await usdc.mint(creatorAddress, usdcAmount); await usdc.mint(firstOwner, usdcAmount); // 2. Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('USDC', usdc.address); - await optionsFactory.updateAsset('WETH', weth.address); + await optionsFactory.whitelistAsset(usdc.address); + await optionsFactory.whitelistAsset(weth.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'USDC', - -6, - 'WETH', - -18, + usdc.address, + weth.address, + usdc.address, -6, 25, -5, - 'USDC', expiry, windowSize, + _name, + _symbol, {from: creatorAddress} ); @@ -83,7 +83,7 @@ contract('OptionsContract: ETH put', accounts => { }); it('should update parameters', async () => { - await oETH.updateParameters('100', '500', 0, 10, {from: creatorAddress}); + await oETH.updateParameters('100', '500', 10, {from: creatorAddress}); }); it('should open empty vault', async () => { diff --git a/test/series/oausdt.test.ts b/test/series/oausdt.test.ts index 9546cce..044c9b0 100644 --- a/test/series/oausdt.test.ts +++ b/test/series/oausdt.test.ts @@ -1,7 +1,7 @@ import { OptionsFactoryInstance, OTokenInstance, - Erc20MintableInstance, + MockErc20Instance, MockOracleInstance } from '../../build/types/truffle-types'; @@ -16,9 +16,10 @@ const { const OTokenContract = artifacts.require('oToken'); const OptionsFactory = artifacts.require('OptionsFactory'); const MockOracle = artifacts.require('MockOracle'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); import Reverter from '../utils/reverter'; +import {ZERO_ADDRESS} from '../utils/helper'; contract('OptionsContract: Aave insurance', accounts => { const reverter = new Reverter(web3); @@ -30,8 +31,8 @@ contract('OptionsContract: Aave insurance', accounts => { let optionsFactory: OptionsFactoryInstance; let oaUSDT: OTokenInstance; let oracle: MockOracleInstance; - let ausdt: Erc20MintableInstance; - let usdt: Erc20MintableInstance; + let ausdt: MockErc20Instance; + let usdt: MockErc20Instance; const _name = 'Aave USDT insurance'; const _symbol = 'oaUSDT'; @@ -47,32 +48,33 @@ contract('OptionsContract: Aave insurance', accounts => { // oracle = MockOracle.at() // 1.2 Mock aUSDT contract - ausdt = await MintableToken.new(); + ausdt = await MockERC20.new('Aave USDC', 'aUSDC', 6); await ausdt.mint(creatorAddress, '1000000000'); // 1000 ausdt await ausdt.mint(firstOwner, '1000000000'); await ausdt.mint(tokenHolder, '1000000000'); // 1.3 Mock USDT contract - usdt = await MintableToken.new(); + usdt = await MockERC20.new('USDT', 'USDT', 6); // 2. Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.updateAsset('aUSDT', ausdt.address); - await optionsFactory.updateAsset('USDT', usdt.address); + await optionsFactory.whitelistAsset(ZERO_ADDRESS); + await optionsFactory.whitelistAsset(ausdt.address); + await optionsFactory.whitelistAsset(usdt.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'ETH', - -18, - 'aUSDT', - -6, + ZERO_ADDRESS, + ausdt.address, + usdt.address, -6, 950, -9, - 'USDT', expiry, windowSize, + _name, + _symbol, {from: creatorAddress} ); @@ -84,16 +86,14 @@ contract('OptionsContract: Aave insurance', accounts => { describe('New option parameter test', () => { it('should have basic setting', async () => { - await oaUSDT.setDetails(_name, _symbol, { - from: creatorAddress - }); - assert.equal(await oaUSDT.name(), String(_name), 'set name error'); assert.equal(await oaUSDT.symbol(), String(_symbol), 'set symbol error'); }); it('should update parameters', async () => { - // await oaUSDT.updateParameters('100', '500', 0, 16, {from: creatorAddress}); + await oaUSDT.updateParameters(10, 500, 16, { + from: creatorAddress + }); }); it('should open empty vault', async () => { diff --git a/test/series/oyDai.test.ts b/test/series/oyDai.test.ts index 2e4e124..34b6afa 100644 --- a/test/series/oyDai.test.ts +++ b/test/series/oyDai.test.ts @@ -1,6 +1,6 @@ // import {expect} from 'chai'; // import { -// Erc20MintableInstance, +// MockErc20Instance, // OTokenInstance, // OptionsFactoryInstance, // OptionsExchangeInstance, @@ -13,7 +13,7 @@ // import {Address} from 'cluster'; // const OptionsFactory = artifacts.require('OptionsFactory'); -// const MintableToken = artifacts.require('ERC20Mintable'); +// const MockERC20 = artifacts.require('MockERC20'); // const UniswapFactory = artifacts.require('UniswapFactoryInterface'); // const UniswapExchange = artifacts.require('UniswapExchangeInterface'); // const OptionsExchange = artifacts.require('OptionsExchange.sol'); @@ -57,7 +57,7 @@ // const optionsContracts: OTokenInstance[] = []; // let optionsFactory: OptionsFactoryInstance; -// let yDai: Erc20MintableInstance; +// let yDai: MockErc20Instance; // let uniswapFactory: UniswapFactoryInterfaceInstance; // let optionsExchange: OptionsExchangeInstance; // let oracle: OracleInstance; @@ -82,7 +82,7 @@ // if (!contractsDeployed) { // oracle = await Oracle.at(oracleAddress); // // 1.2 Mock Dai contract -// yDai = await MintableToken.at(yDaiAddress); +// yDai = await MockERC20.at(yDaiAddress); // // 2. Deploy our contracts // // Deploy the Options Exchange diff --git a/test/series/weth-put.test.ts b/test/series/weth-put.test.ts index a3506bc..f73dbc9 100644 --- a/test/series/weth-put.test.ts +++ b/test/series/weth-put.test.ts @@ -9,7 +9,7 @@ const {time, expectRevert, expectEvent} = require('@openzeppelin/test-helpers'); const OTokenContract = artifacts.require('oToken'); const OptionsFactory = artifacts.require('OptionsFactory'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); import Reverter from '../utils/reverter'; @@ -39,33 +39,33 @@ contract('OptionsContract: weth put', accounts => { // 1. Deploy mock contracts // 1.2 Mock weth contract - weth = await MintableToken.new(); + weth = await MockERC20.new('weth', 'weth', 18); await weth.mint(creatorAddress, wethAmount); // 1000 weth await weth.mint(tokenHolder, wethAmount); // 1.3 Mock USDC contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, usdcAmount); await usdc.mint(firstOwner, usdcAmount); // 2. Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.addAsset('WETH', weth.address); - await optionsFactory.addAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(weth.address); + await optionsFactory.whitelistAsset(usdc.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'USDC', - -6, - 'WETH', - -18, + usdc.address, + weth.address, + usdc.address, -6, 25, -5, - 'USDC', expiry, windowSize, + _name, + _symbol, {from: creatorAddress} ); @@ -85,10 +85,6 @@ contract('OptionsContract: weth put', accounts => { assert.equal(await oWeth.symbol(), String(_symbol), 'set symbol error'); }); - it('should update parameters', async () => { - await oWeth.updateParameters('100', '500', 0, 10, {from: creatorAddress}); - }); - it('should open empty vault', async () => { await oWeth.openVault({ from: creatorAddress diff --git a/test/series/yfi-put.test.ts b/test/series/yfi-put.test.ts index 4bb900c..1f9e710 100644 --- a/test/series/yfi-put.test.ts +++ b/test/series/yfi-put.test.ts @@ -9,7 +9,7 @@ const {time, expectRevert, expectEvent} = require('@openzeppelin/test-helpers'); const OTokenContract = artifacts.require('oToken'); const OptionsFactory = artifacts.require('OptionsFactory'); -const MintableToken = artifacts.require('ERC20Mintable'); +const MockERC20 = artifacts.require('MockERC20'); import Reverter from '../utils/reverter'; @@ -39,33 +39,33 @@ contract('OptionsContract: YFI put', accounts => { // 1. Deploy mock contracts // 1.2 Mock yfi contract - yfi = await MintableToken.new(); + yfi = await MockERC20.new('YFI', 'YFI', 18); await yfi.mint(creatorAddress, yfiAmount); // 1000 yfi await yfi.mint(tokenHolder, yfiAmount); // 1.3 Mock USDC contract - usdc = await MintableToken.new(); + usdc = await MockERC20.new('USDC', 'USDC', 6); await usdc.mint(creatorAddress, usdcAmount); await usdc.mint(firstOwner, usdcAmount); // 2. Deploy the Options Factory contract and add assets to it optionsFactory = await OptionsFactory.deployed(); - await optionsFactory.addAsset('YFI', yfi.address); - await optionsFactory.addAsset('USDC', usdc.address); + await optionsFactory.whitelistAsset(yfi.address); + await optionsFactory.whitelistAsset(usdc.address); // Create the unexpired options contract const optionsContractResult = await optionsFactory.createOptionsContract( - 'USDC', - -6, - 'YFI', - -18, + usdc.address, + yfi.address, + usdc.address, -6, 25, -5, - 'USDC', expiry, windowSize, + _name, + _symbol, {from: creatorAddress} ); @@ -77,18 +77,10 @@ contract('OptionsContract: YFI put', accounts => { describe('New option parameter test', () => { it('should have basic setting', async () => { - await oYfi.setDetails(_name, _symbol, { - from: creatorAddress - }); - assert.equal(await oYfi.name(), String(_name), 'set name error'); assert.equal(await oYfi.symbol(), String(_symbol), 'set symbol error'); }); - it('should update parameters', async () => { - await oYfi.updateParameters('100', '500', 0, 10, {from: creatorAddress}); - }); - it('should open empty vault', async () => { await oYfi.openVault({ from: creatorAddress diff --git a/test/testnetDeploy.test.ts b/test/testnetDeploy.test.ts index 3986e2d..dff331c 100644 --- a/test/testnetDeploy.test.ts +++ b/test/testnetDeploy.test.ts @@ -1,6 +1,6 @@ // import {expect} from 'chai'; // import { -// Erc20MintableInstance, +// MockErc20Instance, // OTokenInstance, // OptionsFactoryInstance, // OptionsExchangeInstance, @@ -13,7 +13,7 @@ // import {Address} from 'cluster'; // const OptionsFactory = artifacts.require('OptionsFactory'); -// const MintableToken = artifacts.require('ERC20Mintable'); +// const MockERC20 = artifacts.require('MockERC20'); // const UniswapFactory = artifacts.require('UniswapFactoryInterface'); // const UniswapExchange = artifacts.require('UniswapExchangeInterface'); // const OptionsExchange = artifacts.require('OptionsExchange.sol'); @@ -59,8 +59,8 @@ // const optionsContracts: OTokenInstance[] = []; // let optionsFactory: OptionsFactoryInstance; -// let dai: Erc20MintableInstance; -// let usdc: Erc20MintableInstance; +// let dai: MockErc20Instance; +// let usdc: MockErc20Instance; // let uniswapFactory: UniswapFactoryInterfaceInstance; // let optionsExchange: OptionsExchangeInstance; // let oracle: OracleInstance; @@ -118,9 +118,9 @@ // if (!contractsDeployed) { // oracle = await Oracle.deployed(); // // 1.2 Mock Dai contract -// dai = await MintableToken.at(daiAddress); +// dai = await MockERC20.at(daiAddress); // // 1.3 USDC contract -// usdc = await MintableToken.at(usdcAddress); +// usdc = await MockERC20.at(usdcAddress); // // 2. Deploy our contracts // // Deploy the Options Exchange @@ -434,7 +434,7 @@ // xit('should be able to buy oTokens with ERC20s', async () => { // const paymentTokenAddr = '0x2448eE2641d78CC42D7AD76498917359D961A783'; -// const paymentToken = await MintableToken.at(paymentTokenAddr); +// const paymentToken = await MockERC20.at(paymentTokenAddr); // // set to optionsCotnracs[0].address // const oTokenAddress = optionsContractAddresses[0]; // await paymentToken.approve( diff --git a/test/utils/helper.ts b/test/utils/helper.ts index 06adcb8..ddca452 100644 --- a/test/utils/helper.ts +++ b/test/utils/helper.ts @@ -18,3 +18,5 @@ export function calculateMaxOptionsToCreate( (minCollateralizationRatio * strikePrice) ); } + +export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';