diff --git a/.github/workflows/hardhat.yml b/.github/workflows/hardhat.yml index b3f226cd8..b7e6c5a18 100644 --- a/.github/workflows/hardhat.yml +++ b/.github/workflows/hardhat.yml @@ -17,6 +17,8 @@ jobs: env: ALCHEMY: ${{ secrets.ALCHEMY }} TEST_MNEMONIC: ${{ secrets.TEST_MNEMONIC }} + ARBITRUM: ${{ secrets.ARBITRUM }} + ARBITRUM_GOERLI: ${{ secrets.ARBITRUM_GOERLI }} steps: - uses: actions/checkout@v3 diff --git a/packages/contracts/deploy/Contract-addresses.md b/packages/contracts/deploy/Contract-addresses.md index 77c819670..f14f6224a 100644 --- a/packages/contracts/deploy/Contract-addresses.md +++ b/packages/contracts/deploy/Contract-addresses.md @@ -74,7 +74,7 @@ uniswapV3HedgingReactor: '0xaa5FcA49bd299E7A3fd1a4b0CB89039413D5580C' perpHedgingReactor: '0xed7a8131A77350967D0E0BF6290873F3f406567f' -# Arbitrum Goerli Addresses +# Arbitrum Goerli Addresses Beyond ## Gamma Protocol @@ -117,3 +117,47 @@ perpHedgingReactor: '0xed7a8131A77350967D0E0BF6290873F3f406567f' | UNISWAPV3Router - Auxiliary | 0xE592427A0AEce92De3Edee1F18E0157C05861564 | | USDC - Auxiliary | 0x6775842ae82bf2f0f987b10526768ad89d79536e | | WETH - Auxiliary | 0x53320bE2A35649E9B2a0f244f9E9474929d3B699 | + +## ARBITRUM GOERLI ALPHA + +OpynController: '0x11a602a5F5D823c103bb8b7184e22391Aae5F4C2' + +OpynAddressBook: '0xd6e67bF0b1Cdb34C37f31A2652812CB30746a94A' + +OpynOracle: '0x35578F5A49E1f1Cf34ed780B46A0BdABA23D4C0b' + +OpynNewCalculator: '0xcD270e755C2653e806e16dD3f78E16C89B7a1c9e' + +OpynOptionRegistry: '0x48A74b742bd97545ace8B0876F5BA7ED19DF6579' + +priceFeed: '0xDcA6c35228acb82363406CB2e7eee81B40c692aE' + +volFeed: '0x9Fc909273C6aF5b6fFd389Fa2B44492ff88a3be6' + +optionProtocol: '0x865Bd85b7275a33C87E8a7E31a125DD6338e6747' + +liquidityPool: '0x2ceDe96cd46C9B751EeB868A57FEDeD060Dbe6Bf' + +authority: '0xA524f4F9046a243c67A07dDE2D9477bf320Ed89E' + +portfolioValuesFeed: '0xbFC1eDc5c07ada83e0244b37A784486633910cD7' + +optionHandler: '0x8a265fa22aa5AF86fa763dC2cF04661bf06A52E6' + +opynInteractions: '0x5e5A98E2F7c71B159B9Ed771E4138d4B2464708c' + +normDist: '0xf63395764CAA20a54bF33fdCCdbC03b2BDc67453' + +BlackScholes: '0x8D3ac248d2598c0C43e1D48e5ad59093F9Cb1d40' + +optionsCompute: '0x8090b463afd758B59089905dc956300824cb2388' + +accounting: '0xCCc6ebF870aCcD83043e8dafaeB4366A4D1a2836' + +uniswapV3HedgingReactor: '0xE5b8F3b414a80b8C40ba438292Eb37918324d285' + +perpHedgingReactor: '0x34f5c89fC6b053728F264cd7f9F1cdFB887AEf86' + +USDC: '0x6775842ae82bf2f0f987b10526768ad89d79536e' + +WETH: '0x53320bE2A35649E9B2a0f244f9E9474929d3B699' diff --git a/packages/contracts/deploy/arbitrum-goerli/ArbitrumGoerliAlphaDeploy.ts b/packages/contracts/deploy/arbitrum-goerli/ArbitrumGoerliAlphaDeploy.ts index bab7f9539..3619beb68 100644 --- a/packages/contracts/deploy/arbitrum-goerli/ArbitrumGoerliAlphaDeploy.ts +++ b/packages/contracts/deploy/arbitrum-goerli/ArbitrumGoerliAlphaDeploy.ts @@ -496,7 +496,6 @@ export async function deployLiquidityPool( await optionRegistry.setLiquidityPool(liquidityPool.address) console.log("registry lp set") - await liquidityPool.setBidAskSpread(bidAskSpread) await pvFeed.setLiquidityPool(liquidityPool.address) await pvFeed.setProtocol(optionProtocol.address) await pvFeed.setKeeper(liquidityPool.address, true) diff --git a/packages/contracts/hardhat.config.ts b/packages/contracts/hardhat.config.ts index 65252f53d..be92ec4ce 100644 --- a/packages/contracts/hardhat.config.ts +++ b/packages/contracts/hardhat.config.ts @@ -160,13 +160,6 @@ module.exports = { accounts: process.env.DEPLOYER_PRIVATE_KEY ? [process.env.DEPLOYER_PRIVATE_KEY] : accounts, gas: 500000000 }, - arbitrumGoerli: { - url: arbitrumGoerli, - chainId: 421613, - saveDeployments: true, - accounts: process.env.DEPLOYER_PRIVATE_KEY ? [process.env.DEPLOYER_PRIVATE_KEY] : accounts, - gas: 500000000 - } }, etherscan: { apiKey: { diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 4a384c7ae..9d7e3d3b6 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -16,20 +16,18 @@ ] }, "scripts": { - "buyoption:testnet": "npx hardhat run scripts/buySample.ts --network arbitrumRinkeby", - "compile": "hardhat clean && hardhat compile && ./copyABIsToFrontend.sh", - "create-otc-order:testnet": "npx hardhat run scripts/createOTCOrder.ts --network arbitrumRinkeby", - "create-otc-strangle:testnet": "npx hardhat run scripts/createOTCStrangle.ts --network arbitrumRinkeby", + "buyoption:testnet": "npx hardhat run scripts/buySample.ts --network arbitrumGoerli", + "compile": "hardhat clean && hardhat compile && hardhat typechain && ./copyABIsToFrontend.sh", + "create-otc-order:testnet": "npx hardhat run scripts/createOTCOrder.ts --network arbitrumGoerli", + "create-otc-strangle:testnet": "npx hardhat run scripts/createOTCStrangle.ts --network arbitrumGoerli", "deploy:arbitrumGoerli": "npx hardhat run deploy/arbitrum-goerli/ArbitrumGoerliDeploy.ts --network arbitrumGoerli", "deploy:localhost": "npx hardhat deploy --network localhost --tags localhost && ./copyAddressesToFrontEnd.sh --deploy-scripts deploy/localhost", - "deploy:rinkeby": "hardhat deploy --network rinkeby --tags testnet --deploy-scripts deploy/rinkeby", "deployAlpha:arbitrumGoerli": "npx hardhat run deploy/arbitrum-goerli/ArbitrumGoerliAlphaDeploy.ts --network arbitrumGoerli", - "deployAlpha:arbitrumRinkeby": "npx hardhat run deploy/arbitrum-rinkeby/ArbitrumRinkebyAlphaDeploy.ts --network arbitrumRinkeby", "deployAlpha:mainnet": "npx hardhat run deploy/arbitrum/ArbitrumAlphaDeploy.ts --network arbitrum", "deployRangeOrderReactor:arbitrum": "npx hardhat run deploy/arbitrum/DeployRangeOrderReactor.ts --network arbitrum", "deployRangeOrderReactor:arbitrumGoerli": "npx hardhat run deploy/arbitrum/DeployRangeOrderReactor.ts --network arbitrumGoerli", - "execute-epoch:testnet": "npx hardhat run scripts/executeEpochTestnet.ts --network arbitrumRinkeby", - "fulfill:testnet": "npx hardhat run scripts/fulfill.ts --network arbitrumRinkeby", + "execute-epoch:testnet": "npx hardhat run scripts/executeEpochTestnet.ts --network arbitrumGoerli", + "fulfill:testnet": "npx hardhat run scripts/fulfill.ts --network arbitrumGoerli", "test": "hardhat test", "test-coverage": "export NODE_OPTIONS='--max-old-space-size=8192' && hardhat coverage --testfiles 'test/*.ts'" }, diff --git a/packages/contracts/test/CreateOptionProducts.ts b/packages/contracts/test/CreateOptionProducts.ts index aef7de775..b6ec68df9 100644 --- a/packages/contracts/test/CreateOptionProducts.ts +++ b/packages/contracts/test/CreateOptionProducts.ts @@ -15,7 +15,8 @@ import { tFormatUSDC, scaleNum } from "../utils/conversion-helper" -import moment from "moment" +import dayjs from "dayjs" +import utc from "dayjs/plugin/utc" import { AbiCoder } from "ethers/lib/utils" //@ts-ignore import bs from "black-scholes" @@ -69,6 +70,9 @@ import { NewWhitelist } from "../types/NewWhitelist" import { OptionExchange } from "../types/OptionExchange" import { OtokenFactory } from "../types/OtokenFactory" import { OptionCatalogue } from "../types/OptionCatalogue" + +dayjs.extend(utc) + let usd: MintableERC20 let weth: WETH let wethERC20: MintableERC20 @@ -177,11 +181,8 @@ const emptySeries = { } /* --- end variables to change --- */ -const expiration = moment.utc(expiryDate).add(3, "d").add(8, "h").valueOf() / 1000 -const expiration2 = moment.utc(expiryDate).add(1, "w").add(8, "h").valueOf() / 1000 // have another batch of options exire 1 week after the first -const expiration3 = moment.utc(expiryDate).add(2, "w").add(8, "h").valueOf() / 1000 -const invalidExpirationLong = moment.utc(invalidExpiryDateLong).add(8, "h").valueOf() / 1000 -const invalidExpirationShort = moment.utc(invalidExpiryDateShort).add(8, "h").valueOf() / 1000 +const expiration = dayjs.utc(expiryDate).add(3, "days").add(8, "hours").unix() +const expiration2 = dayjs.utc(expiryDate).add(1, "weeks").add(8, "hours").unix()// have another batch of options exire 1 week after the first const abiCode = new AbiCoder() const bcsLowerStrike = toWei("2200") diff --git a/packages/contracts/test/ExchangeActions.ts b/packages/contracts/test/ExchangeActions.ts index 7e1e95c0a..ee6f5a879 100644 --- a/packages/contracts/test/ExchangeActions.ts +++ b/packages/contracts/test/ExchangeActions.ts @@ -15,7 +15,8 @@ import { tFormatUSDC, scaleNum } from "../utils/conversion-helper" -import moment from "moment" +import dayjs from "dayjs" +import utc from "dayjs/plugin/utc" import { AbiCoder } from "ethers/lib/utils" //@ts-ignore import bs from "black-scholes" @@ -61,6 +62,9 @@ import { create } from "domain" import { NewWhitelist } from "../types/NewWhitelist" import { OptionExchange } from "../types/OptionExchange" import { OtokenFactory } from "../types/OtokenFactory" + +dayjs.extend(utc) + let usd: MintableERC20 let weth: WETH let wethERC20: MintableERC20 @@ -103,14 +107,6 @@ const invalidExpiryDateShort: string = "2022-03-01" const rfr: string = "0" // edit depending on the chain id to be tested on const chainId = 1 -const oTokenDecimalShift18 = 10000000000 -// amount of dollars OTM written options will be (both puts and calls) -// use negative numbers for ITM options -const strike = "20" - -// hardcoded value for strike price that is outside of accepted bounds -const invalidStrikeHigh = utils.parseEther("12500") -const invalidStrikeLow = utils.parseEther("200") // balances to deposit into the LP const liquidityPoolUsdcDeposit = "100000" @@ -146,11 +142,8 @@ const expiryToValue = [ /* --- end variables to change --- */ -const expiration = moment.utc(expiryDate).add(8, "h").valueOf() / 1000 -const expiration2 = moment.utc(expiryDate).add(1, "w").add(8, "h").valueOf() / 1000 // have another batch of options exire 1 week after the first -const expiration3 = moment.utc(expiryDate).add(2, "w").add(8, "h").valueOf() / 1000 -const invalidExpirationLong = moment.utc(invalidExpiryDateLong).add(8, "h").valueOf() / 1000 -const invalidExpirationShort = moment.utc(invalidExpiryDateShort).add(8, "h").valueOf() / 1000 +const expiration = dayjs.utc(expiryDate).add(8, "hours").unix() +const expiration2 = dayjs.utc(expiryDate).add(1, "weeks").add(8, "hours").unix() // have another batch of options exire 1 week after the first const abiCode = new AbiCoder() let vaultIdCounter = 1 const CALL_FLAVOR = false diff --git a/packages/contracts/test/LiquidityPool.ts b/packages/contracts/test/LiquidityPool.ts index 54482a14a..3b9af72ad 100644 --- a/packages/contracts/test/LiquidityPool.ts +++ b/packages/contracts/test/LiquidityPool.ts @@ -15,7 +15,8 @@ import { fromOpyn, toOpyn, tFormatUSDC, - scaleNum + scaleNum, + emptySeries } from "../utils/conversion-helper" import { deployOpyn } from "../utils/opyn-deployer" import Otoken from "../artifacts/contracts/packages/opyn/core/Otoken.sol/Otoken.json" @@ -120,7 +121,7 @@ const invalidStrikeHigh = utils.parseEther("12500") const invalidStrikeLow = utils.parseEther("200") // balances to deposit into the LP -const liquidityPoolUsdcDeposit = "100000" +const liquidityPoolUsdcDeposit = "500000" const minCallStrikePrice = utils.parseEther("500") const maxCallStrikePrice = utils.parseEther("10000") @@ -2108,7 +2109,7 @@ describe("Liquidity Pools", async () => { amount, pricer, true, - exchange, + catalogue, localDelta.div(amount.div(toWei("1"))), toWei("0").sub(toWei("50")) ) diff --git a/packages/contracts/test/LiquidityPoolAlpha.ts b/packages/contracts/test/LiquidityPoolAlpha.ts index fe50b42b8..bccc40cce 100644 --- a/packages/contracts/test/LiquidityPoolAlpha.ts +++ b/packages/contracts/test/LiquidityPoolAlpha.ts @@ -52,6 +52,9 @@ import { AbiCoder } from "ethers/lib/utils" dayjs.extend(utc) import { OptionCatalogue } from "../types/OptionCatalogue" + +dayjs.extend(utc) + let usd: MintableERC20 let weth: WETH let wethERC20: ERC20Interface diff --git a/packages/contracts/test/LiquidityPoolAlphaWithManager.ts b/packages/contracts/test/LiquidityPoolAlphaWithManager.ts index c83143e81..0c6e870ea 100644 --- a/packages/contracts/test/LiquidityPoolAlphaWithManager.ts +++ b/packages/contracts/test/LiquidityPoolAlphaWithManager.ts @@ -29,20 +29,6 @@ import { Volatility } from "../types/Volatility" import { VolatilityFeed } from "../types/VolatilityFeed" import { WETH } from "../types/WETH" import { deployLiquidityPool, deploySystem } from "../utils/alpha-system-deployer" -import { - fromOpyn, - fromWei, - percentDiff, - scaleNum, - tFormatEth, - tFormatUSDC, - toOpyn, - toUSDC, - toWei, - toWeiFromUSDC -} from "../utils/conversion-helper" -import { deployOpyn } from "../utils/opyn-deployer" -import { deployRage, deployRangeOrder } from "../utils/rage-deployer" import { setupTestOracle, setupOracle, diff --git a/packages/contracts/test/LiquidityPoolPerpHedgingReactor.ts b/packages/contracts/test/LiquidityPoolPerpHedgingReactor.ts index 7959e37de..ec12dac95 100644 --- a/packages/contracts/test/LiquidityPoolPerpHedgingReactor.ts +++ b/packages/contracts/test/LiquidityPoolPerpHedgingReactor.ts @@ -44,7 +44,9 @@ import { setupTestOracle, makeIssueAndBuy, makeBuy, - getSeriesWithe18Strike + getSeriesWithe18Strike, + setupTestOracle, + setupOracle } from "./helpers" import { AlphaPortfolioValuesFeed } from "../types/AlphaPortfolioValuesFeed" import { BeyondOptionHandler } from "../types/BeyondOptionHandler" diff --git a/packages/contracts/test/LiquidityPoolSellOptions.ts b/packages/contracts/test/LiquidityPoolSellOptions.ts index 1b00ad574..7669dc322 100644 --- a/packages/contracts/test/LiquidityPoolSellOptions.ts +++ b/packages/contracts/test/LiquidityPoolSellOptions.ts @@ -15,7 +15,8 @@ import { tFormatUSDC, scaleNum } from "../utils/conversion-helper" -import moment from "moment" +import dayjs from "dayjs" +import utc from "dayjs/plugin/utc" import { AbiCoder } from "ethers/lib/utils" //@ts-ignore import bs from "black-scholes" @@ -76,6 +77,7 @@ import { OptionExchange } from "../types/OptionExchange" import { OtokenFactory } from "../types/OtokenFactory" import { OptionCatalogue } from "../types/OptionCatalogue" import { AlphaOptionHandler } from "../types/AlphaOptionHandler" +dayjs.extend(utc) let usd: MintableERC20 let weth: WETH let wethERC20: MintableERC20 @@ -177,11 +179,8 @@ const expiryToValue = [ /* --- end variables to change --- */ -const expiration = moment.utc(expiryDate).add(8, "h").valueOf() / 1000 -const expiration2 = moment.utc(expiryDate).add(1, "w").add(8, "h").valueOf() / 1000 // have another batch of options exire 1 week after the first -const expiration3 = moment.utc(expiryDate).add(2, "w").add(8, "h").valueOf() / 1000 -const invalidExpirationLong = moment.utc(invalidExpiryDateLong).add(8, "h").valueOf() / 1000 -const invalidExpirationShort = moment.utc(invalidExpiryDateShort).add(8, "h").valueOf() / 1000 +const expiration = dayjs.utc(expiryDate).add(8, "hours").unix() +const expiration2 = dayjs.utc(expiryDate).add(1, "weeks").add(8, "hours").unix()// have another batch of options exire 1 week after the first const abiCode = new AbiCoder() const CALL_FLAVOR = false @@ -3857,8 +3856,7 @@ describe("Liquidity Pools hedging reactor: gamma", async () => { await pricer.setSlippageGradientMultipliers( slippageGradientMultipliers, slippageGradientMultipliers) const acSlippageGradientMultipliers = await pricer.getCallSlippageGradientMultipliers() const apSlippageGradientMultipliers = await pricer.getPutSlippageGradientMultipliers() - console.log(slippageGradientMultipliers) - console.log(acSlippageGradientMultipliers) + for (let i=0; i < slippageGradientMultipliers.length; i++) { expect(acSlippageGradientMultipliers[i]).to.equal(slippageGradientMultipliers[i]) expect(apSlippageGradientMultipliers[i]).to.equal(slippageGradientMultipliers[i]) diff --git a/packages/contracts/test/LiquidityPoolUniswapV3HedgingReactor.ts b/packages/contracts/test/LiquidityPoolUniswapV3HedgingReactor.ts index a71a5e546..9bf3c94d5 100644 --- a/packages/contracts/test/LiquidityPoolUniswapV3HedgingReactor.ts +++ b/packages/contracts/test/LiquidityPoolUniswapV3HedgingReactor.ts @@ -56,6 +56,9 @@ import { BeyondOptionHandler } from "../types/BeyondOptionHandler" import { BeyondPricer } from "../types/BeyondPricer" import { OptionExchange } from "../types/OptionExchange" import { OptionCatalogue } from "../types/OptionCatalogue" + +dayjs.extend(utc) + let usd: MintableERC20 let weth: WETH let optionRegistry: OptionRegistry @@ -80,6 +83,8 @@ let uniswapV3HedgingReactor: UniswapV3HedgingReactor let exchange: OptionExchange let pricer: BeyondPricer let authority: string +let catalogue: OptionCatalogue + /* --- variables to change --- */ diff --git a/packages/contracts/test/PerpHedgingReactorSc1.ts b/packages/contracts/test/PerpHedgingReactorSc1.ts index e9dc1cf22..2d752d938 100644 --- a/packages/contracts/test/PerpHedgingReactorSc1.ts +++ b/packages/contracts/test/PerpHedgingReactorSc1.ts @@ -213,15 +213,8 @@ describe("PerpHedgingReactor Sc1", () => { const reactorDeltaBefore = await liquidityPoolDummy.getDelta() const LpUsdcBalanceBefore = await usdcContract.balanceOf(liquidityPoolDummy.address) await liquidityPoolDummy.hedgeDelta(delta) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) - const reactorCollatBalanceAfter = ( - await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) - )[1] - const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition( - 0, - truncate(vTokenAddress) - ) + const reactorCollatBalanceAfter = (await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId))[1] + const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition(0, truncate(vTokenAddress)) const reactorDeltaAfter = await liquidityPoolDummy.getDelta() const LpUsdcBalanceAfter = await usdcContract.balanceOf(liquidityPoolDummy.address) expect(deltaHedge).to.equal(reactorDeltaAfter) @@ -375,25 +368,11 @@ describe("PerpHedgingReactor Sc1", () => { await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) )[1] const price = await priceFeed.getNormalizedRate(WETH_ADDRESS[chainId], USDC_ADDRESS[chainId]) - const collatRequired = -price - .mul(delta) - .div(toWei("1")) - .mul(await perpHedgingReactor.healthFactor()) - .div(10000) - .div(USDC_SCALE) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) + const collatRequired = -((price.mul(delta).div(toWei('1'))).mul(await perpHedgingReactor.healthFactor()).div(10000)).div(USDC_SCALE) const hedgeDeltaTx = await liquidityPoolDummy.hedgeDelta(delta) await hedgeDeltaTx.wait() - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) - const reactorCollatBalanceAfter = ( - await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) - )[1] - const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition( - 0, - truncate(vTokenAddress) - ) + const reactorCollatBalanceAfter = (await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId))[1] + const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition(0, truncate(vTokenAddress)) const reactorDeltaAfter = await liquidityPoolDummy.getDelta() const LpUsdcBalanceAfter = await usdcContract.balanceOf(liquidityPoolDummy.address) expect(reactorDeltaAfter).to.equal(reactorDeltaBefore.sub(delta)) @@ -421,25 +400,11 @@ describe("PerpHedgingReactor Sc1", () => { await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) )[1] const price = await priceFeed.getNormalizedRate(WETH_ADDRESS[chainId], USDC_ADDRESS[chainId]) - const collatRequired = -price - .mul(delta) - .div(toWei("1")) - .mul(await perpHedgingReactor.healthFactor()) - .div(10000) - .div(USDC_SCALE) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) + const collatRequired = -((price.mul(delta).div(toWei('1'))).mul(await perpHedgingReactor.healthFactor()).div(10000)).div(USDC_SCALE) const hedgeDeltaTx = await liquidityPoolDummy.hedgeDelta(delta) await hedgeDeltaTx.wait() - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) - const reactorCollatBalanceAfter = ( - await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) - )[1] - const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition( - 0, - truncate(vTokenAddress) - ) + const reactorCollatBalanceAfter = (await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId))[1] + const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition(0, truncate(vTokenAddress)) const reactorDeltaAfter = await liquidityPoolDummy.getDelta() const LpUsdcBalanceAfter = await usdcContract.balanceOf(liquidityPoolDummy.address) expect(reactorDeltaAfter).to.equal(reactorDeltaBefore.sub(delta)) @@ -476,25 +441,11 @@ describe("PerpHedgingReactor Sc1", () => { await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) )[1] const price = await priceFeed.getNormalizedRate(WETH_ADDRESS[chainId], USDC_ADDRESS[chainId]) - const collatRequired = -price - .mul(delta) - .div(toWei("1")) - .mul(await perpHedgingReactor.healthFactor()) - .div(10000) - .div(USDC_SCALE) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) + const collatRequired = -((price.mul(delta).div(toWei('1'))).mul(await perpHedgingReactor.healthFactor()).div(10000)).div(USDC_SCALE) const hedgeDeltaTx = await liquidityPoolDummy.hedgeDelta(delta) await hedgeDeltaTx.wait() - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) - const reactorCollatBalanceAfter = ( - await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) - )[1] - const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition( - 0, - truncate(vTokenAddress) - ) + const reactorCollatBalanceAfter = (await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId))[1] + const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition(0, truncate(vTokenAddress)) const reactorDeltaAfter = await liquidityPoolDummy.getDelta() const LpUsdcBalanceAfter = await usdcContract.balanceOf(liquidityPoolDummy.address) expect(reactorDeltaAfter).to.equal(reactorDeltaBefore.sub(delta)) diff --git a/packages/contracts/test/PerpHedgingReactorSc2.ts b/packages/contracts/test/PerpHedgingReactorSc2.ts index 5d20ab9d0..9ae487a82 100644 --- a/packages/contracts/test/PerpHedgingReactorSc2.ts +++ b/packages/contracts/test/PerpHedgingReactorSc2.ts @@ -213,15 +213,8 @@ describe("PerpHedgingReactor Sc2", () => { const reactorDeltaBefore = await liquidityPoolDummy.getDelta() const LpUsdcBalanceBefore = await usdcContract.balanceOf(liquidityPoolDummy.address) await liquidityPoolDummy.hedgeDelta(delta) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) - const reactorCollatBalanceAfter = ( - await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) - )[1] - const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition( - 0, - truncate(vTokenAddress) - ) + const reactorCollatBalanceAfter = (await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId))[1] + const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition(0, truncate(vTokenAddress)) const reactorDeltaAfter = await liquidityPoolDummy.getDelta() const LpUsdcBalanceAfter = await usdcContract.balanceOf(liquidityPoolDummy.address) expect(deltaHedge).to.equal(reactorDeltaAfter) @@ -253,25 +246,11 @@ describe("PerpHedgingReactor Sc2", () => { ) await rageOracle.setSqrtPriceX96(realSqrtPrice) const price = await priceFeed.getNormalizedRate(WETH_ADDRESS[chainId], USDC_ADDRESS[chainId]) - const collatRequired = price - .mul(deltaHedge.add(reactorDeltaBefore)) - .div(toWei("1")) - .mul(await perpHedgingReactor.healthFactor()) - .div(10000) - .div(USDC_SCALE) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) + const collatRequired = ((price.mul(deltaHedge.add(reactorDeltaBefore)).div(toWei('1'))).mul(await perpHedgingReactor.healthFactor()).div(10000)).div(USDC_SCALE) const hedgeDeltaTx = await liquidityPoolDummy.hedgeDelta(delta) await hedgeDeltaTx.wait() - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) - const reactorCollatBalanceAfter = ( - await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) - )[1] - const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition( - 0, - truncate(vTokenAddress) - ) + const reactorCollatBalanceAfter = (await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId))[1] + const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition(0, truncate(vTokenAddress)) const reactorDeltaAfter = await liquidityPoolDummy.getDelta() const LpUsdcBalanceAfter = await usdcContract.balanceOf(liquidityPoolDummy.address) expect(reactorDeltaAfter).to.equal(reactorDeltaBefore.sub(delta)) @@ -304,25 +283,11 @@ describe("PerpHedgingReactor Sc2", () => { ) await rageOracle.setSqrtPriceX96(realSqrtPrice) const price = await priceFeed.getNormalizedRate(WETH_ADDRESS[chainId], USDC_ADDRESS[chainId]) - const collatRequired = price - .mul(deltaHedge.add(reactorDeltaBefore)) - .div(toWei("1")) - .mul(await perpHedgingReactor.healthFactor()) - .div(10000) - .div(USDC_SCALE) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) + const collatRequired = ((price.mul(deltaHedge.add(reactorDeltaBefore)).div(toWei('1'))).mul(await perpHedgingReactor.healthFactor()).div(10000)).div(USDC_SCALE) const hedgeDeltaTx = await liquidityPoolDummy.hedgeDelta(delta) await hedgeDeltaTx.wait() - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) - const reactorCollatBalanceAfter = ( - await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) - )[1] - const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition( - 0, - truncate(vTokenAddress) - ) + const reactorCollatBalanceAfter = (await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId))[1] + const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition(0, truncate(vTokenAddress)) const reactorDeltaAfter = await liquidityPoolDummy.getDelta() const LpUsdcBalanceAfter = await usdcContract.balanceOf(liquidityPoolDummy.address) expect(reactorDeltaAfter).to.equal(reactorDeltaBefore.sub(delta)) @@ -376,25 +341,11 @@ describe("PerpHedgingReactor Sc2", () => { ) await rageOracle.setSqrtPriceX96(realSqrtPrice) const price = await priceFeed.getNormalizedRate(WETH_ADDRESS[chainId], USDC_ADDRESS[chainId]) - const collatRequired = price - .mul(deltaHedge.add(reactorDeltaBefore)) - .div(toWei("1")) - .mul(await perpHedgingReactor.healthFactor()) - .div(10000) - .div(USDC_SCALE) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) + const collatRequired = ((price.mul(deltaHedge.add(reactorDeltaBefore)).div(toWei('1'))).mul(await perpHedgingReactor.healthFactor()).div(10000)).div(USDC_SCALE) const hedgeDeltaTx = await liquidityPoolDummy.hedgeDelta(delta) await hedgeDeltaTx.wait() - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) - const reactorCollatBalanceAfter = ( - await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) - )[1] - const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition( - 0, - truncate(vTokenAddress) - ) + const reactorCollatBalanceAfter = (await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId))[1] + const reactorWethBalanceAfter = await clearingHouse.getAccountNetTokenPosition(0, truncate(vTokenAddress)) const reactorDeltaAfter = await liquidityPoolDummy.getDelta() const LpUsdcBalanceAfter = await usdcContract.balanceOf(liquidityPoolDummy.address) expect(reactorDeltaAfter).to.equal(reactorDeltaBefore.sub(delta)) @@ -442,11 +393,7 @@ describe("PerpHedgingReactor Sc2", () => { const reactorUsdcBalanceBefore = await usdcContract.balanceOf(perpHedgingReactor.address) const withdrawAmount = "10000" const newCollat = reactorCollatBalanceBefore.sub(toUSDC(withdrawAmount)) - const expectedDelta = newCollat - .mul(10000) - .mul(e18) - .div((await perpHedgingReactor.healthFactor()).mul(price.div(USDC_SCALE))) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) + const expectedDelta = newCollat.mul(10000).mul(e18).div((await perpHedgingReactor.healthFactor()).mul(price.div(USDC_SCALE))); // withdraw more than current balance await liquidityPoolDummy.withdraw(ethers.utils.parseUnits(withdrawAmount, 18)) const reactorCollatBalanceAfter = ( @@ -488,14 +435,7 @@ describe("PerpHedgingReactor Sc2", () => { )[1] const reactorUsdcBalanceBefore = await usdcContract.balanceOf(perpHedgingReactor.address) const price = await priceFeed.getNormalizedRate(WETH_ADDRESS[chainId], USDC_ADDRESS[chainId]) - const collatRequired = price - .mul(reactorDeltaBefore) - .div(toWei("1")) - .mul(await perpHedgingReactor.healthFactor()) - .div(10000) - .div(USDC_SCALE) - console.log(await clearingHouse.getAccountMarketValueAndRequiredMargin(0, true)) - console.log(await clearingHouse.getAccountNetProfit(0)) + const collatRequired = ((price.mul(reactorDeltaBefore).div(toWei('1'))).mul(await perpHedgingReactor.healthFactor()).div(10000)).div(USDC_SCALE) const tx = await liquidityPoolDummy.update() const reactorCollatBalanceAfter = ( await clearingHouseLens.getAccountCollateralInfo(accountId, collateralId) diff --git a/packages/contracts/test/SlippagePricer.ts b/packages/contracts/test/SlippagePricer.ts index ee0f145ad..e8cf1293c 100644 --- a/packages/contracts/test/SlippagePricer.ts +++ b/packages/contracts/test/SlippagePricer.ts @@ -1,7 +1,8 @@ import hre, { ethers, network } from "hardhat" import { BigNumberish, Contract, utils, Signer, BigNumber } from "ethers" import { toWei, toUSDC, scaleNum } from "../utils/conversion-helper" -import moment from "moment" +import dayjs from "dayjs" +import utc from "dayjs/plugin/utc" import { AbiCoder } from "ethers/lib/utils" //@ts-ignore import { expect } from "chai" @@ -26,6 +27,9 @@ import { deployLiquidityPool, deploySystem } from "../utils/generic-system-deplo import { BeyondPricer } from "../types/BeyondPricer" import { NewWhitelist } from "../types/NewWhitelist" import { OptionExchange } from "../types/OptionExchange" + +dayjs.extend(utc) + let usd: MintableERC20 let weth: WETH let wethERC20: MintableERC20 @@ -114,11 +118,8 @@ const expiryToValue = [ /* --- end variables to change --- */ -const expiration = moment.utc(expiryDate).add(8, "h").valueOf() / 1000 -const expiration2 = moment.utc(expiryDate).add(1, "w").add(8, "h").valueOf() / 1000 // have another batch of options exire 1 week after the first -const expiration3 = moment.utc(expiryDate).add(2, "w").add(8, "h").valueOf() / 1000 -const invalidExpirationLong = moment.utc(invalidExpiryDateLong).add(8, "h").valueOf() / 1000 -const invalidExpirationShort = moment.utc(invalidExpiryDateShort).add(8, "h").valueOf() / 1000 +const expiration = dayjs.utc(expiryDate).add(8, "hours").unix() +const expiration2 = dayjs.utc(expiryDate).add(1, "weeks").add(8, "hours").unix() // have another batch of options exire 1 week after the first const abiCode = new AbiCoder() const CALL_FLAVOR = false const PUT_FLAVOR = true diff --git a/packages/contracts/test/SpreadPricer.ts b/packages/contracts/test/SpreadPricer.ts index f20f0d243..5aa2356dc 100644 --- a/packages/contracts/test/SpreadPricer.ts +++ b/packages/contracts/test/SpreadPricer.ts @@ -1,7 +1,8 @@ import hre, { ethers, network } from "hardhat" import { BigNumberish, Contract, utils, Signer, BigNumber } from "ethers" import { toWei, toUSDC, scaleNum, fromUSDC } from "../utils/conversion-helper" -import moment from "moment" +import dayjs from "dayjs" +import utc from "dayjs/plugin/utc" import { AbiCoder } from "ethers/lib/utils" //@ts-ignore import { expect } from "chai" @@ -29,6 +30,8 @@ import { NewWhitelist } from "../types/NewWhitelist" import { OptionExchange } from "../types/OptionExchange" import { OptionCatalogue } from "../types/OptionCatalogue" +dayjs.extend(utc) + let usd: MintableERC20 let weth: WETH let wethERC20: MintableERC20 @@ -71,14 +74,6 @@ const invalidExpiryDateShort: string = "2022-03-01" const rfr: string = "0" // edit depending on the chain id to be tested on const chainId = 1 -const oTokenDecimalShift18 = 10000000000 -// amount of dollars OTM written options will be (both puts and calls) -// use negative numbers for ITM options -const strike = "20" - -// hardcoded value for strike price that is outside of accepted bounds -const invalidStrikeHigh = utils.parseEther("12500") -const invalidStrikeLow = utils.parseEther("200") // balances to deposit into the LP const liquidityPoolUsdcDeposit = "100000" @@ -118,11 +113,8 @@ const expiryToValue = [ /* --- end variables to change --- */ -const expiration = moment.utc(expiryDate).add(8, "h").valueOf() / 1000 -const expiration2 = moment.utc(expiryDate).add(1, "w").add(8, "h").valueOf() / 1000 // have another batch of options exire 1 week after the first -const expiration3 = moment.utc(expiryDate).add(2, "w").add(8, "h").valueOf() / 1000 -const invalidExpirationLong = moment.utc(invalidExpiryDateLong).add(8, "h").valueOf() / 1000 -const invalidExpirationShort = moment.utc(invalidExpiryDateShort).add(8, "h").valueOf() / 1000 +const expiration = dayjs.utc(expiryDate).add(8, "hours").unix() +const expiration2 = dayjs.utc(expiryDate).add(1, "weeks").add(8, "hours").unix() // have another batch of options exire 1 week after the first const abiCode = new AbiCoder() const CALL_FLAVOR = false const PUT_FLAVOR = true @@ -415,7 +407,6 @@ describe("Spread Pricer testing", async () => { pricer, toWei("0") ) - console.log({ quoteResponse: fromUSDC(quoteResponse[0]), localQuoteNoSpread }) expect(singleSellQuote).to.eq(quoteResponse[0].div(1000)) expect(parseFloat(fromUSDC(quoteResponse[0])) - localQuoteNoSpread).to.be.within(-0.1, 0.1) }) diff --git a/packages/contracts/utils/generic-system-deployer.ts b/packages/contracts/utils/generic-system-deployer.ts index b936c252f..0c2724673 100644 --- a/packages/contracts/utils/generic-system-deployer.ts +++ b/packages/contracts/utils/generic-system-deployer.ts @@ -5,30 +5,19 @@ import { expect } from "chai" import dayjs from "dayjs" import utc from "dayjs/plugin/utc" -import { ERC20Interface } from "../types/ERC20Interface" -import { MintableERC20 } from "../types/MintableERC20" -import { OptionRegistry } from "../types/OptionRegistry" -import { AlphaPortfolioValuesFeed, PortfolioValuesStruct } from "../types/AlphaPortfolioValuesFeed" -import { PriceFeed } from "../types/PriceFeed" -import { LiquidityPool } from "../types/LiquidityPool" -import { WETH } from "../types/WETH" -import { Protocol } from "../types/Protocol" -import { Volatility } from "../types/Volatility" import LiquidityPoolSol from "../artifacts/contracts/LiquidityPool.sol/LiquidityPool.json" import { ADDRESS_BOOK, GAMMA_CONTROLLER, MARGIN_POOL, OTOKEN_FACTORY, + UNISWAP_V3_SWAP_ROUTER, USDC_ADDRESS, - WETH_ADDRESS, USDC_OWNER_ADDRESS, - UNISWAP_V3_SWAP_ROUTER + WETH_ADDRESS } from "../test/constants" import { Accounting } from "../types/Accounting" -import { MockChainlinkAggregator } from "../types/MockChainlinkAggregator" -import { Oracle } from "../types/Oracle" -import { VolatilityFeed } from "../types/VolatilityFeed" + dayjs.extend(utc) @@ -37,6 +26,10 @@ import { OptionExchange } from "../types/OptionExchange" import { BeyondPricer } from "../types/BeyondPricer" import { OptionCatalogue } from "../types/OptionCatalogue" import { AlphaOptionHandler } from "../types/AlphaOptionHandler" +import { AlphaPortfolioValuesFeed, ERC20Interface, LiquidityPool, MintableERC20, MockChainlinkAggregator, OptionRegistry, Oracle, PriceFeed, Protocol, Volatility, VolatilityFeed, WETH } from "../types" + +dayjs.extend(utc) + const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" // edit depending on the chain id to be tested on diff --git a/packages/front-end/src/types/global.d.ts b/packages/front-end/src/types/global.d.ts new file mode 100644 index 000000000..a363ba070 --- /dev/null +++ b/packages/front-end/src/types/global.d.ts @@ -0,0 +1,3 @@ +declare module "black-scholes"; +declare module "greeks"; +declare module "implied-volatility";