Skip to content

Commit

Permalink
mainnet deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
aparnakr committed Feb 10, 2020
1 parent d26b411 commit e6c525d
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 98 deletions.
69 changes: 69 additions & 0 deletions ABIs/OptionsExchange.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,75 @@
"stateMutability": "payable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "seller",
"type": "address"
},
{
"indexed": false,
"name": "receiver",
"type": "address"
},
{
"indexed": false,
"name": "oTokenAddress",
"type": "address"
},
{
"indexed": false,
"name": "payoutTokenAddress",
"type": "address"
},
{
"indexed": false,
"name": "oTokensToSell",
"type": "uint256"
}
],
"name": "SellOTokens",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "buyer",
"type": "address"
},
{
"indexed": false,
"name": "receiver",
"type": "address"
},
{
"indexed": false,
"name": "oTokenAddress",
"type": "address"
},
{
"indexed": false,
"name": "paymentTokenAddress",
"type": "address"
},
{
"indexed": false,
"name": "oTokensToBuy",
"type": "uint256"
},
{
"indexed": false,
"name": "premiumPaid",
"type": "uint256"
}
],
"name": "BuyOTokens",
"type": "event"
},
{
"constant": false,
"inputs": [
Expand Down
34 changes: 32 additions & 2 deletions contracts/OptionsContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ contract OptionsContract is Ownable, ERC20 {
// The Oracle used for the contract
CompoundOracleInterface public COMPOUND_ORACLE;

string public name;
string public symbol;
uint8 public decimals;

/**
* @param _collateral The collateral asset
* @param _collExp The precision of the collateral (-18 if ETH)
Expand Down Expand Up @@ -267,6 +271,19 @@ contract OptionsContract is Ownable, ERC20 {
);
}

function setDetails(string memory _name, string memory _symbol)
public
onlyOwner
{
name = _name;
symbol = _symbol;
decimals = uint8(-1 * oTokenExchangeRate.exponent);
require(
decimals >= 0,
"1 oToken cannot protect less than the smallest unit of the asset"
);
}

/**
* @notice Can only be called by owner. Used to take out the protocol fees from the contract.
* @param _address The address to send the fee to.
Expand Down Expand Up @@ -860,6 +877,10 @@ contract OptionsContract is Ownable, ERC20 {
return stillSafe;
}

/**
* This function returns the maximum amount of oTokens that can safely be issued against the specified amount of collateral.
* @param collateralAmt The amount of collateral against which oTokens will be issued.
*/
function maxOTokensIssuable(uint256 collateralAmt)
public
view
Expand All @@ -869,6 +890,15 @@ contract OptionsContract is Ownable, ERC20 {

}

/**
* @notice This function is used to calculate the amount of tokens that can be issued.
* @dev The amount of oTokens is determined by:
* oTokensIssued <= collateralAmt * collateralToStrikePrice / (proportion * strikePrice)
* @param collateralAmt The amount of collateral
* @param proportion The proportion of the collateral to pay out. If 100% of collateral
* should be paid out, pass in Number(1, 0). The proportion might be less than 100% if
* you are calculating fees.
*/
function calculateOTokens(uint256 collateralAmt, Number memory proportion)
internal
view
Expand All @@ -878,7 +908,7 @@ contract OptionsContract is Ownable, ERC20 {
uint256 collateralToEthPrice = getPrice(address(collateral));
uint256 strikeToEthPrice = getPrice(address(strike));

// oTokensIssued <= collAmt * collateralToStrikePrice / proportion * strikePrice
// oTokensIssued <= collAmt * collateralToStrikePrice / (proportion * strikePrice)
uint256 denomVal = proportion.value.mul(strikePrice.value);
int32 denomExp = proportion.exponent + strikePrice.exponent;

Expand All @@ -904,7 +934,7 @@ contract OptionsContract is Ownable, ERC20 {
/**
* @notice This function calculates the amount of collateral to be paid out.
* @dev The amount of collateral to paid out is determined by:
* `proportion` * `strikePrice` * `oTokens` amount of collateral.
* (proportion * strikePrice * strikeToCollateralPrice * oTokens) amount of collateral.
* @param _oTokens The number of oTokens.
* @param proportion The proportion of the collateral to pay out. If 100% of collateral
* should be paid out, pass in Number(1, 0). The proportion might be less than 100% if
Expand Down
44 changes: 30 additions & 14 deletions contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,36 @@ contract Oracle {
PriceOracle = CompoundOracleInterface(_oracleAddress);
// TODO: change these addresses for mainnet
// Kovan
address cBAT = 0xd5ff020f970462816fDD31a603Cb7D120E48376E;
address cDAI = 0xe7bc397DBd069fC7d0109C0636d06888bb50668c;
cETH = 0xf92FbE0D3C0dcDAE407923b2Ac17eC223b1084E4;
address cREP = 0xFd874BE7e6733bDc6Dca9c7CDd97c225ec235D39;
address cUSDC = 0xcfC9bB230F00bFFDB560fCe2428b4E05F3442E35;
address cWBTC = 0x3659728876EfB2780f498Ce829C5b076e496E0e3;
address cZRX = 0xC014DC10A57aC78350C5fddB26Bb66f1Cb0960a0;

address BAT = 0x9dDB308C14f700d397bB26F584Ac2E303cdc7365;
address DAI = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa;
address REP = 0x4E5cB5A0CAca30d1ad27D8CD8200a907854FB518;
address USDC = 0x75B0622Cec14130172EaE9Cf166B92E5C112FaFF;
address WBTC = 0xA0A5aD2296b38Bd3e3Eb59AAEAF1589E8d9a29A9;
address ZRX = 0x29eb28bAF3B296b9F14e5e858C52269b57b4dF6E;
// address cBAT = 0xd5ff020f970462816fDD31a603Cb7D120E48376E;
// address cDAI = 0xe7bc397DBd069fC7d0109C0636d06888bb50668c;
// cETH = 0xf92FbE0D3C0dcDAE407923b2Ac17eC223b1084E4;
// address cREP = 0xFd874BE7e6733bDc6Dca9c7CDd97c225ec235D39;
// address cUSDC = 0xcfC9bB230F00bFFDB560fCe2428b4E05F3442E35;
// address cWBTC = 0x3659728876EfB2780f498Ce829C5b076e496E0e3;
// address cZRX = 0xC014DC10A57aC78350C5fddB26Bb66f1Cb0960a0;

// address BAT = 0x9dDB308C14f700d397bB26F584Ac2E303cdc7365;
// address DAI = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa;
// address REP = 0x4E5cB5A0CAca30d1ad27D8CD8200a907854FB518;
// address USDC = 0x75B0622Cec14130172EaE9Cf166B92E5C112FaFF;
// address WBTC = 0xA0A5aD2296b38Bd3e3Eb59AAEAF1589E8d9a29A9;
// address ZRX = 0x29eb28bAF3B296b9F14e5e858C52269b57b4dF6E;

// Mainnet
address cBAT = 0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E;
address cDAI = 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643;
cETH = 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5;
address cREP = 0x158079Ee67Fce2f58472A96584A73C7Ab9AC95c1;
address cUSDC = 0x39AA39c021dfbaE8faC545936693aC917d5E7563;
address cWBTC = 0xC11b1268C1A384e55C48c2391d8d480264A3A7F4;
address cZRX = 0xB3319f5D18Bc0D84dD1b4825Dcde5d5f7266d407;

address BAT = 0x0D8775F648430679A709E98d2b0Cb6250d2887EF;
address DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address REP = 0x1985365e9f78359a9B6AD760e32412f4a445E862;
address USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
address ZRX = 0xE41d2489571d322189246DaFA5ebDe1F4699F498;

isCToken[cBAT] = true;
isCToken[cDAI] = true;
Expand Down
19 changes: 15 additions & 4 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = function (deployer) {
// Rinkeby
uniswapFactoryAddr = "0xf5D915570BC477f9B8D6C0E980aA81757A3AaC36";
compoundOracleAddress = "0x332b6e69f21acdba5fb3e8dac56ff81878527e06";
// compoundOracle = await deployer.deploy(Oracle, compoundOracleAddress);
compoundOracle = await deployer.deploy(MockCompoundOracle);
compoundOracle = await deployer.deploy(Oracle, compoundOracleAddress);
// compoundOracle = await deployer.deploy(MockCompoundOracle);
} else if ((await web3.eth.net.getId()) == 42) {
await deployer.deploy(StringComparator);
await deployer.link(StringComparator, OptionsFactory);
Expand All @@ -32,6 +32,15 @@ module.exports = function (deployer) {
compoundOracleAddress = "0xc7E20CF485b8E0Bcec3e2fCc23e3aD93b1b0cB39";
// compoundOracle = await deployer.deploy(Oracle, compoundOracleAddress);
compoundOracle = await deployer.deploy(MockCompoundOracle);
} else if ((await web3.eth.net.getId()) == 1) {
// await deployer.deploy(StringComparator);
// await deployer.link(StringComparator, OptionsFactory);
// // Mainnet
// uniswapFactoryAddr = "0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95";
// compoundOracleAddress = "0x1D8aEdc9E924730DD3f9641CDb4D1B92B848b4bd";
// // compoundOracle = await deployer.deploy(Oracle, compoundOracleAddress);
// compoundOracle = await Oracle.at('0x317166AB2bF19152D16871C8Cf1B33583e26932B');
// console.log("Oracle Address ", compoundOracle.address.toString());
} else {
// For the local testnet
await deployer.deploy(StringComparator);
Expand All @@ -43,7 +52,9 @@ module.exports = function (deployer) {
}

// For all testnets / mainnets
const optionsExchange = await deployer.deploy(OptionsExchange, uniswapFactoryAddr);
await deployer.deploy(OptionsFactory, optionsExchange.address, compoundOracle.address);
// const optionsExchange = await deployer.deploy(OptionsExchange, uniswapFactoryAddr);
// console.log("Options Exchange ", optionsExchange.address.toString());
// await deployer.deploy(OptionsFactory, optionsExchange.address, compoundOracle.address);
// console.log("Options Factory ", OptionsFactory.address.toString());
})
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"compile:types": "typechain --target=truffle --outDir build/types/truffle-types \"build/contracts/*.json\"",
"build": "npm run compile:contracts && npm run compile:types",
"pretest": "npm run build",
"test": "truffle test",
"test": "truffle test --network mainnet ./test/sell-and-buy.test.ts",
"test:kovan":"truffle test --network kovan ./test/sell-and-buy.test.ts",
"test:ropsten":"truffle test --network ropsten ./test/sell-and-buy.test.ts",
"test:rinkeby": "truffle test --network rinkeby ./test/sell-and-buy.test.ts",
Expand Down
50 changes: 33 additions & 17 deletions test/oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,40 @@ contract('OptionsContract', accounts => {
// const cWBTCAddress = '0x0014F450B8Ae7708593F4A46F8fa6E5D50620F96';
// const cZRXAddress = '0x52201ff1720134bBbBB2f6BC97Bf3715490EC19B';

// Kovan Addresses
const cBATAddress = '0xd5ff020f970462816fDD31a603Cb7D120E48376E';
const cDaiAddress = '0xe7bc397DBd069fC7d0109C0636d06888bb50668c';
const cETHAddress = '0xf92FbE0D3C0dcDAE407923b2Ac17eC223b1084E4';
const cREPAddress = '0xFd874BE7e6733bDc6Dca9c7CDd97c225ec235D39';
const cUSDCAddress = '0xcfC9bB230F00bFFDB560fCe2428b4E05F3442E35';
const cWBTCAddress = '0x3659728876EfB2780f498Ce829C5b076e496E0e3';
const cZRXAddress = '0xC014DC10A57aC78350C5fddB26Bb66f1Cb0960a0';
// // Kovan Addresses
// const cBATAddress = '0xd5ff020f970462816fDD31a603Cb7D120E48376E';
// const cDaiAddress = '0xe7bc397DBd069fC7d0109C0636d06888bb50668c';
// const cETHAddress = '0xf92FbE0D3C0dcDAE407923b2Ac17eC223b1084E4';
// const cREPAddress = '0xFd874BE7e6733bDc6Dca9c7CDd97c225ec235D39';
// const cUSDCAddress = '0xcfC9bB230F00bFFDB560fCe2428b4E05F3442E35';
// const cWBTCAddress = '0x3659728876EfB2780f498Ce829C5b076e496E0e3';
// const cZRXAddress = '0xC014DC10A57aC78350C5fddB26Bb66f1Cb0960a0';

const batAddress = '0x9dDB308C14f700d397bB26F584Ac2E303cdc7365';
const daiAddress = '0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa';
const repAddress = '0x4E5cB5A0CAca30d1ad27D8CD8200a907854FB518';
const usdcAddress = '0x75B0622Cec14130172EaE9Cf166B92E5C112FaFF';
const wbtcAddress = '0xA0A5aD2296b38Bd3e3Eb59AAEAF1589E8d9a29A9';
const zrxAddress = '0x29eb28bAF3B296b9F14e5e858C52269b57b4dF6E';
// const batAddress = '0x9dDB308C14f700d397bB26F584Ac2E303cdc7365';
// const daiAddress = '0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa';
// const repAddress = '0x4E5cB5A0CAca30d1ad27D8CD8200a907854FB518';
// const usdcAddress = '0x75B0622Cec14130172EaE9Cf166B92E5C112FaFF';
// const wbtcAddress = '0xA0A5aD2296b38Bd3e3Eb59AAEAF1589E8d9a29A9';
// const zrxAddress = '0x29eb28bAF3B296b9F14e5e858C52269b57b4dF6E';

const oracleAddress = '0xcade7B301C483e9a235c957833368FE3B7CF2a2f';
const isDeployed = false;
// Mainnet Addresses
const cBATAddress = '0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E';
const cDaiAddress = '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643';
const cETHAddress = '0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5';
const cREPAddress = '0x158079Ee67Fce2f58472A96584A73C7Ab9AC95c1';
const cUSDCAddress = '0x39AA39c021dfbaE8faC545936693aC917d5E7563';
const cWBTCAddress = '0xC11b1268C1A384e55C48c2391d8d480264A3A7F4';
const cZRXAddress = '0xB3319f5D18Bc0D84dD1b4825Dcde5d5f7266d407';

const batAddress = '0x0D8775F648430679A709E98d2b0Cb6250d2887EF';
const daiAddress = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
const repAddress = '0x1985365e9f78359a9B6AD760e32412f4a445E862';
const usdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
const wbtcAddress = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599';
const zrxAddress = '0xE41d2489571d322189246DaFA5ebDe1F4699F498';

const oracleAddress = '0x0B844c32E21b47C9C03351D604d362B5201955E7';
const isDeployed = true;

let oracle: OracleInstance;

Expand All @@ -55,7 +71,7 @@ contract('OptionsContract', accounts => {
});

describe('test the prices', async () => {
xit('test all the underlying token prices', async () => {
it('test all the underlying token prices', async () => {
console.log(
'BAT Price ' + (await oracle.getPrice(batAddress)).toString()
);
Expand Down
Loading

0 comments on commit e6c525d

Please sign in to comment.