diff --git a/scripts/create.py b/scripts/create.py new file mode 100644 index 00000000..ddcde4e3 --- /dev/null +++ b/scripts/create.py @@ -0,0 +1,75 @@ +import click + +from brownie import OverlayV1Factory, accounts, network + + +# TODO: change +FACTORY = "0x8cCD181113c7Ae40f31D5e8178a98A1A60B55c4C" + + +def main(): + """ + Creates a new OverlayV1Market through factory + `deployMarket()` function. + """ + click.echo(f"You are using the '{network.show_active()}' network") + gov = accounts.load(click.prompt( + "Account", type=click.Choice(accounts.load()))) + + # instantiate the factory contract + factory = OverlayV1Factory.at(FACTORY) + + # assemble feed params for deployMarket + feed_factory = click.prompt("feedFactory (address)") + feed = click.prompt("feed (address)") + + # assemble risk params for deployMarket + params = [ + "k (uint256)", + "lmbda (uint256)", + "delta (uint256)", + "capPayoff (uint256)", + "capNotional (uint256)", + "capLeverage (uint256)", + "circuitBreakerWindow (uint256)", + "circuitBreakerMintTarget (uint256)", + "maintenanceMarginFraction (uint256)", + "maintenanceMarginBurnRate (uint256)", + "liquidationFeeRate (uint256)", + "tradingFeeRate (uint256)", + "minCollateral (uint256)", + "priceDriftUpperLimit (uint256)", + "averageBlockTime (uint256)" + ] + args = [click.prompt(f"{param}") for param in params] + + click.echo( + f""" + OverlayV1Market Parameters + + feedFactory (address): {feed_factory} + feed (address): {feed} + + uint256[15] params + k (uint256): {args[0]} + lmbda (uint256): {args[1]} + delta (uint256): {args[2]} + capPayoff (uint256): {args[3]} + capNotional (uint256): {args[4]} + capLeverage (uint256): {args[5]} + circuitBreakerWindow (uint256): {args[6]} + circuitBreakerMintTarget (uint256): {args[7]} + maintenanceMarginFraction (uint256): {args[8]} + maintenanceMarginBurnRate (uint256): {args[9]} + liquidationFeeRate (uint256): {args[10]} + tradingFeeRate (uint256): {args[11]} + minCollateral (uint256): {args[12]} + priceDriftUpperLimit (uint256): {args[13]} + averageBlockTime (uint256): {args[14]} + """ + ) + + if click.confirm("Deploy New Market"): + tx = factory.deployMarket(feed_factory, feed, args, {"from": gov}) + tx.info() + click.echo("Market deployed") diff --git a/scripts/deploy.py b/scripts/deploy.py new file mode 100644 index 00000000..b2dbe3aa --- /dev/null +++ b/scripts/deploy.py @@ -0,0 +1,61 @@ +import click + +from brownie import OverlayV1Token, OverlayV1Factory, accounts, network, web3 +from hexbytes import HexBytes + + +# governance multisig +# TODO: change +GOV = "0x95f972fc4D17a0D343Cd5eaD8d6DCBef5606CA66" + +# fee recipient address +# TODO: change +FEE_RECIPIENT = "0xDFafdfF09C1d63257892A8d2F56483588B99315A" + +# ROLES +ADMIN = "ADMIN" +GOVERNOR = "GOVERNOR" +MINTER = "MINTER" +BURNER = "BURNER" + + +def _role(name): + if name == ADMIN: + return HexBytes("0x00") + return web3.solidityKeccak(['string'], [name]) + + +def main(): + """ + Deploys new OverlayV1Token and OverlayV1Factory contracts. + + Grants token admin rights to the factory to enable deploying of markets + with mint and burn priveleges. Grants token admin rights to governor and + renounces all token rights for deployer. + """ + click.echo(f"You are using the '{network.show_active()}' network") + dev = accounts.load(click.prompt( + "Account", type=click.Choice(accounts.load()))) + + # deploy OVL + ovl = OverlayV1Token.deploy({"from": dev}, publish_source=True) + click.echo(f"OVL Token deployed [{ovl.address}]") + + # deploy market factory + factory = OverlayV1Factory.deploy( + ovl, FEE_RECIPIENT, {"from": dev}, publish_source=True) + click.echo(f"Factory deployed [{factory.address}]") + + # grant market factory admin role to grant minter + burner roles to markets + # on deployMarket calls + ovl.grantRole(_role(ADMIN), factory, {"from": dev}) + + # grant admin rights to gov + ovl.grantRole(_role(ADMIN), GOV, {"from": dev}) + ovl.grantRole(_role(MINTER), GOV, {"from": dev}) + ovl.grantRole(_role(GOVERNOR), GOV, {"from": dev}) + click.echo(f"OVL Token roles granted to [{GOV}]") + + # renounce admin rights so only gov has roles + ovl.renounceRole(_role(ADMIN), dev, {"from": dev}) + ovl.renounceRole(_role(MINTER), dev, {"from": dev}) diff --git a/scripts/feeds/uniswapv3/create.py b/scripts/feeds/uniswapv3/create.py new file mode 100644 index 00000000..08f12480 --- /dev/null +++ b/scripts/feeds/uniswapv3/create.py @@ -0,0 +1,46 @@ +import click + +from brownie import OverlayV1UniswapV3Factory, accounts, network + + +# TODO: change +UNIV3_FEED_FACTORY = "0x1C897298324BdAC1bB80d89E30b4D2529E98ADaE" + + +def main(): + """ + Creates a new OverlayV1UniswapV3Feed through feed factory + `deployFeed()` function. + """ + click.echo(f"You are using the '{network.show_active()}' network") + dev = accounts.load(click.prompt( + "Account", type=click.Choice(accounts.load()))) + + # instantiate the feed factory contract + feed_factory = OverlayV1UniswapV3Factory.at(UNIV3_FEED_FACTORY) + + # assemble params for deployFeed + params = ["marketBaseToken (address)", "marketQuoteToken (address)", + "marketFee (uint24)", "marketBaseAmount (uint128)", + "ovlXBaseToken (address)", "ovlXQuoteToken (address)", + "ovlXFee (uint24)"] + args = [click.prompt(f"{param}") for param in params] + + click.echo( + f""" + OverlayV1UniswapV3Feed Parameters + + marketBaseToken (address): {args[0]} + marketQuoteToken (address): {args[1]} + marketFee (uint24): {args[2]} + marketBaseAmount (uint128): {args[3]} + ovlXBaseToken (address): {args[4]} + ovlXQuoteToken (address): {args[5]} + ovlXFee (uint24): {args[6]} + """ + ) + + if click.confirm("Deploy New Feed"): + tx = feed_factory.deployFeed(*args, {"from": dev}) + tx.info() + click.echo("Uniswap V3 Feed deployed") diff --git a/scripts/feeds/uniswapv3/deploy.py b/scripts/feeds/uniswapv3/deploy.py new file mode 100644 index 00000000..de826e99 --- /dev/null +++ b/scripts/feeds/uniswapv3/deploy.py @@ -0,0 +1,34 @@ +import click + +from brownie import OverlayV1UniswapV3Factory, accounts, network + + +UNIV3_FACTORY = "0x1F98431c8aD98523631AE4a59f267346ea31F984" + + +def main(): + """ + Deploys a new OverlayV1UniswapV3Factory contract, which allows for + permissionless deployment of OverlayV1UniswapV3Feed feeds. + """ + click.echo(f"You are using the '{network.show_active()}' network") + dev = accounts.load(click.prompt( + "Account", type=click.Choice(accounts.load()))) + + # assemble constructor params + params = ["ovl (address)", "uniV3Factory (address)", + "microWindow (uint256)", "macroWindow (uint256)", + "observationCardinalityMinimum (uint16)", + "averageBlockTime (uint256)"] + args = [ + click.prompt(f"{param}") + if param != "uniV3Factory (address)" + else UNIV3_FACTORY + for param in params + ] + + # deploy feed factory + feed_factory = OverlayV1UniswapV3Factory.deploy( + *args, {"from": dev}, publish_source=True) + click.echo(f"Uniswap V3 Feed Factory deployed [{feed_factory.address}]") + click.echo("NOTE: Feed Factory is not registered in OverlayV1Factory yet!")