Skip to content

Commit

Permalink
Merge branch 'develop' into feature/hardhat-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Robsonsjre committed Jun 18, 2021
2 parents ca12a0d + 4f450d4 commit edffb97
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 69 deletions.
19 changes: 18 additions & 1 deletion deployments/local.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
{

"WETH": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"USDC": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
"AUSDC": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
"DAI": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
"WBTC": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
"LINK": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
"ConfigurationManager": "0x0165878A594ca255338adfa4d48449f69242Eb8F",
"EmergencyStop": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
"CapProvider": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
"PodPutBuilder": "0x9A676e781A523b5d0C0e43731313A708CB607508",
"WPodPutBuilder": "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
"PodCallBuilder": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
"WPodCallBuilder": "0x9A9f2CCfdE556A7E9Ff0848998Aa4a0CFD8863AE",
"OptionFactory": "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
"IVProvider": "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
"PriceProvider": "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
"FeePoolBuilder": "0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB",
"OptionHelper": "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8"
}
3 changes: 2 additions & 1 deletion tasks/deployWeek.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ task('deployWeek', 'Deploy a whole local test environment')
expiresIn: '31d',
initialIV: '2200000000000000000',
initialOptions: '5000',
initialStable: '5000',
optionCap: '1000000',
poolCap: '100000'
}
Expand Down Expand Up @@ -63,7 +64,7 @@ task('deployWeek', 'Deploy a whole local test environment')
const configurationManager = await ethers.getContractAt('ConfigurationManager', contentJSON.ConfigurationManager)
const ivProviderAddress = await configurationManager.getIVProvider()
const ivProvider = await ethers.getContractAt('IVProvider', ivProviderAddress)
const tx = await ivProvider.updateIV(optionAddress, defaultInitialIV, '18')
const tx = await ivProvider.updateIV(optionAddress, option.initialIV, '18')
await tx.wait(2)
}

Expand Down
166 changes: 102 additions & 64 deletions tasks/local/setupLocal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const saveJSON = require('../utils/saveJSON')
const BigNumber = require('bignumber.js')
const parseDuration = require('parse-duration')

const getTimestamp = require('../../test/util/getTimestamp')
const fs = require('fs')
const pathJoin = require('path')
Expand All @@ -9,6 +12,8 @@ task('setupLocal', 'Deploy a whole local test environment')
const path = `../../deployments/${hre.network.name}.json`
// Erasing local.json file
await saveJSON(path, '', true)
const [deployer] = await ethers.getSigners()
const deployerAddress = await deployer.getAddress()

const deployedTokens = {}
const tokenList = [
Expand All @@ -32,8 +37,8 @@ task('setupLocal', 'Deploy a whole local test environment')
// 2) Setup Chainlink (Oracle) Mock
const ChainlinkFeed = await ethers.getContractFactory('MockChainlinkFeed')

const chainlinkWBTCFeed = await ChainlinkFeed.deploy(deployedTokens.WBTC, '8', '37170000000000')
const chainlinkWETHFeed = await ChainlinkFeed.deploy(deployedTokens.WETH, '8', '1270000000000')
const chainlinkWBTCFeed = await ChainlinkFeed.deploy(deployedTokens.WBTC, '8', '3717000000000')
const chainlinkWETHFeed = await ChainlinkFeed.deploy(deployedTokens.WETH, '8', '254000000000')
const chainlinkLINKFeed = await ChainlinkFeed.deploy(deployedTokens.LINK, '8', '2496201073')

await saveJSON(path, { wbtcChainlinkFeed: chainlinkWBTCFeed.address })
Expand All @@ -50,70 +55,103 @@ task('setupLocal', 'Deploy a whole local test environment')
// Set WETH price Provider
const priceProvider = await ethers.getContractAt('PriceProvider', await configurationManager.getPriceProvider())

await priceProvider.setAssetFeeds([deployedTokens.WETH], [chainlinkWETHFeed.address])
await priceProvider.setAssetFeeds([deployedTokens.LINK], [chainlinkLINKFeed.address])
await priceProvider.setAssetFeeds([deployedTokens.WETH, deployedTokens.LINK], [chainlinkWETHFeed.address, chainlinkLINKFeed.address])

const ivProviderAddress = await configurationManager.getIVProvider()
const ivProvider = await ethers.getContractAt('IVProvider', ivProviderAddress)

// Set the updater
await ivProvider.setUpdater(deployerAddress)

// 4) Deploy Test Option
const currentBlockTimestamp = await getTimestamp()

const optionWBTCAddress = await hre.run('deployNewOption', {
strike: 'USDC',
underlying: 'WBTC',
price: '18000',
expiration: (currentBlockTimestamp + 48 * 60 * 60).toString(),
cap: '2000'
})

const optionWETHAddress = await hre.run('deployNewOption', {
strike: 'USDC',
underlying: 'WETH',
price: '1500',
expiration: (currentBlockTimestamp + 48 * 60 * 60).toString(),
cap: '2000'
})

const optionLINKAddress = await hre.run('deployNewOption', {
strike: 'USDC',
underlying: 'LINK',
price: '25',
expiration: (currentBlockTimestamp + 24 * 60 * 60 * 4).toString(),
cap: '2000'
})

// 5) Create AMMPool test with this asset
const optionAMMPoolAddress = await hre.run('deployNewOptionAMMPool', {
option: optionWBTCAddress,
tokenb: deployedTokens.USDC,
initialiv: '770000000000000000', // 0.77%
cap: '500000'
})

const optionAMMETHPoolAddress = await hre.run('deployNewOptionAMMPool', {
option: optionWETHAddress,
tokenb: deployedTokens.USDC,
initialiv: '2000000000000000000',
cap: '500000'
})

const optionLINKPoolAddress = await hre.run('deployNewOptionAMMPool', {
option: optionLINKAddress,
tokenb: deployedTokens.USDC,
initialiv: '2311200000000000000',
cap: '500000'
})

// 6) Mint Strike Asset
console.log('Minting USDC strike asset')
const mockUSDC = await ethers.getContractAt('MintableERC20', deployedTokens.USDC)
await mockUSDC.mint('10000000000000000')

// // 7) Mint Options
await hre.run('mintOptions', { option: optionLINKAddress, amount: '600' })

// 8) Add Liquidity
await hre.run('addLiquidityAMM', {
pooladdress: optionLINKPoolAddress,
amounta: '500',
amountb: '11000'
})
const optionsList = [
{
strike: 'USDC',
underlying: 'WBTC',
price: '38000',
expiresIn: '20d',
initialIV: '1800000000000000000',
initialOptions: '10',
initialStable: '500000',
optionCap: '1000000',
poolCap: '100000000000'
},
{
strike: 'USDC',
underlying: 'WETH',
price: '2200',
expiresIn: '15d',
initialIV: '1760000000000000000',
initialOptions: '6',
initialStable: '11000',
optionCap: '1000000',
poolCap: '100000000000'
},
{
strike: 'USDC',
underlying: 'LINK',
price: '25',
expiresIn: '4d',
initialIV: '2700000000000000000',
initialOptions: '50',
initialStable: '5000',
optionCap: '1000000',
poolCap: '10000000000000'
}
]

const deployedOptions = []

for (const option of optionsList) {
let expiration

// If option.expiresIn is an expression, interpret it, otherwise assume it
if (typeof option.expiresIn === 'string') {
expiration = currentBlockTimestamp + (parseDuration(option.expiresIn) / 1000)
} else {
expiration = option.expiresIn
}

const optionAddress = await hre.run('deployNewOption', {
strike: option.strike,
underlying: option.underlying,
price: option.price,
expiration: expiration.toString(),
cap: option.optionCap
})

const tokenbAddress = JSON.parse(content)[option.strike]
deployedOptions.push(optionAddress)

await ivProvider.updateIV(optionAddress, option.initialIV, '18')

const poolAddress = await hre.run('deployNewOptionAMMPool', {
option: optionAddress,
tokenb: tokenbAddress,
cap: option.poolCap,
initialiv: option.initialIV
})
const mockToken = await ethers.getContractAt('MintableERC20', tokenbAddress)
const mockTokenDecimals = await mockToken.decimals()
const amountToMint = BigNumber(option.poolCap).times(BigNumber(10).pow(mockTokenDecimals))
console.log('amountToMint')
console.log(amountToMint.toString())

await mockToken.mint(amountToMint.toString())

if (option.initialOptions) {
await hre.run('mintOptions', { option: optionAddress, amount: option.initialOptions })

await hre.run('addLiquidityAMM', {
pooladdress: poolAddress,
amounta: option.initialOptions,
amountb: option.initialStable
})
}
}
console.log('deployedOptions:')
console.log(deployedOptions)
console.log('---Finish Setup Local Network----')
})
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7377,9 +7377,9 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==

normalize-url@^4.1.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.0.tgz#453354087e6ca96957bd8f5baf753f5982142129"
integrity sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==
version "4.5.1"
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.1.tgz#0dd90cf1288ee1d1313b87081c9a5932ee48518a"
integrity sha512-9UZCFRHQdNrfTpGg8+1INIg93B6zE0aXMVFkw1WFwvO4SlZywU6aLg5Of0Ap/PgcbSw4LNxvMWXMeugwMCX0AA==

npm-run-path@^2.0.0:
version "2.0.2"
Expand Down

0 comments on commit edffb97

Please sign in to comment.