Example #1
0
def main():

    badger = connect_badger("deploy-final.json")

    deployer = badger.deployer
    controller = badger.getController("native")
    governance = badger.devMultisig
    strategist = badger.deployer
    keeper = badger.keeper
    guardian = badger.guardian

    for (key, strategyName, isUniswap) in [
        ("native.sushiWbtcIbBtc", "StrategySushiLpOptimizer", False),
        # ("native.uniWbtcIbBtc", "StrategyUniGenericLp", True),
    ]:
        if isUniswap:
            params = sett_config.uni.uniGenericLp.params
            swap = UniswapSystem()
        else:
            params = sett_config.sushi.sushiWbtcIbBtc.params
            params.badgerTree = badger.badgerTree

            swap = SushiswapSystem()

        if swap.hasPair(registry.tokens.ibbtc, registry.tokens.wbtc):
            params.want = swap.getPair(registry.tokens.ibbtc, registry.tokens.wbtc)
        else:
            params.want = swap.createPair(
                registry.tokens.ibbtc, registry.tokens.wbtc, deployer,
            )

        # NB: Work w/ sushi team to setup sushi reward allocations.

        vault = badger.deploy_sett(
            key,
            params.want,
            controller,
            governance=governance,
            strategist=strategist,
            keeper=keeper,
            guardian=guardian,
        )
        time.sleep(sleep_between_tx)

        strategy = badger.deploy_strategy(
            key,
            strategyName,
            controller,
            params,
            governance=governance,
            strategist=strategist,
            keeper=keeper,
            guardian=guardian,
        )
        time.sleep(sleep_between_tx)

        badger.wire_up_sett(vault, strategy, controller)

        # TODO: Unpause vault.
        assert vault.paused()
Example #2
0
    def fetch_params(self):
        params = sett_config.uni.uniDiggWbtc.params

        uniswap = UniswapSystem()
        # TODO: Pull digg token addr from registry once its deployed.
        if uniswap.hasPair(self.digg.token, registry.tokens.wbtc):
            params.want = uniswap.getPair(self.digg.token,
                                          registry.tokens.wbtc)
        else:
            params.want = uniswap.createPair(
                self.digg.token,
                registry.tokens.wbtc,
                self.deployer,
            )
        want = params.want
        params.token = self.digg.token

        self.badger.deploy_logic("DiggRewardsFaucet",
                                 DiggRewardsFaucet,
                                 test=True)
        self.rewards = self.badger.deploy_digg_rewards_faucet(
            self.key, self.digg.token)

        params.geyser = self.rewards

        return (params, want)
Example #3
0
class DiggSystem:
    def __init__(self,
                 config,
                 deployer,
                 devProxyAdmin,
                 daoProxyAdmin,
                 owner=None):
        self.config = config
        self.contracts_static = []
        self.contracts_upgradeable = {}
        # These contracts adhere to the Ownable iface and belong to the
        # owner of the digg system (in prod it's the DAO). Note that this
        # is ONLY tracked on deploy as we will not modify ownership when
        # connecting to an existing system.
        self.contracts_ownable = []
        # Token is set when digg token (UFragments) is deployed.
        self.token = None

        self.logic = DotMap()
        # Store uniswap trading pairs addresses.
        # Expected key syntax is `tokenA_tokenB`.
        self.uniswap_trading_pair_addrs = DotMap()

        if rpc.is_active():
            print("RPC Active")
            self.owner = accounts.at(owner, force=True)
        else:
            print("RPC Inactive")
            # owner_key = decouple.config("DIGG_OWNER_PRIVATE_KEY")
            # self.owner = accounts.add(owner_key)

        if deployer == None:
            console.print(
                "[yellow]No deployer specified, using Owner[/yellow]")
            self.deployer = self.owner
        else:
            self.deployer = deployer
        if env_config.debug:
            print("deployer / owner", deployer, owner, self.deployer,
                  self.owner)
        #        self.owner=""
        #        self.deployer=self.owner

        self.connect_proxy_admins(devProxyAdmin, daoProxyAdmin)
        self.connect_dao()
        self.connect_multisig()

    def track_contract_static(self, contract):
        self.contracts_static.append(contract)

    def track_contract_upgradeable(self, key, contract):
        self.contracts_upgradeable[key] = contract

    def track_contract_ownable(self, contract):
        self.contracts_ownable.append(contract)

    # ===== Contract Connectors =====
    def connect_proxy_admins(self, devProxyAdmin, daoProxyAdmin):
        abi = artifacts.open_zeppelin["ProxyAdmin"]["abi"]

        self.devProxyAdmin = Contract.from_abi(
            "ProxyAdmin",
            web3.toChecksumAddress(devProxyAdmin),
            abi,
        )
        self.daoProxyAdmin = Contract.from_abi(
            "ProxyAdmin",
            web3.toChecksumAddress(daoProxyAdmin),
            abi,
        )

    def connect_centralized_oracle(self, address):
        self.centralizedOracle = connect_gnosis_safe(address)

    def connect_dao(self):
        deployer = self.deployer
        self.dao = DotMap(agent=Contract.from_abi(
            "Agent",
            badger_config.dao.agent,
            artifacts.aragon.Agent["abi"],
            deployer,
        ), )

    def connect_multisig(self):
        deployer = self.deployer

        if env_config.debug:
            print("Deploy Dev Multisig")
        self.devMultisig = connect_gnosis_safe(badger_config.multisig.address)

    def connect_uniswap_system(self):
        self.uniswap_system = UniswapSystem()

    def connect_uniswap_pair(self, pair_name, tokenA_addr, tokenB_addr):
        self.uniswap_trading_pair_addrs[
            pair_name] = self.uniswap_system.getPair(tokenA_addr, tokenB_addr)

    def connect(self, attr, BrownieArtifact, address, upgradeable=True):
        contract = BrownieArtifact.at(address)
        setattr(self, attr, contract)

        if upgradeable:
            self.track_contract_upgradeable(attr, contract)
        else:
            self.track_contract_static(contract)

    def connect_logic(self, logic):
        for name, address in logic.items():
            if env_config.debug:
                print("ConnectLogic:", name, address)
            Artifact = contract_name_to_artifact(name)
            self.logic[name] = Artifact.at(address)

    # ===== Deployers =====

    def deploy_core_logic(self):
        deployer = self.deployer
        self.logic = DotMap(
            # UFragments=UFragments.deploy({"from": deployer}),
            UFragments=UFragments.at(
                "0xfabec03b04279c6e73f27aaf25866acc844448ae"),
            UFragmentsPolicy=UFragmentsPolicy.at(
                "0x4750caa4999404cb26ff6db2d0abc09b000122e0"),
            # Timelock & Vesting: Use logic from existing badger deploy
            SimpleTimelock=SimpleTimelock.at(
                "0x4e3f56bb996ed91ba8d97ea773d3f818730d1a6f"),
            SmartVesting=SmartVesting.at(
                "0x07c0E4f4C977a29c46Fb26597ea8C9105ca50b42"),
            # DiggDistributor=DiggDistributor.deploy({"from": deployer}, publish_source=True),
        )

    def deploy_orchestrator(self):
        deployer = self.deployer
        self.orchestrator = Orchestrator.deploy(self.uFragmentsPolicy,
                                                {"from": deployer})
        self.track_contract_static(self.orchestrator)
        self.track_contract_ownable(self.orchestrator)

    def deploy_digg_policy(self):
        deployer = self.deployer
        self.uFragmentsPolicy = deploy_proxy(
            "UFragmentsPolicy",
            UFragmentsPolicy.abi,
            self.logic.UFragmentsPolicy.address,
            self.devProxyAdmin.address,
            self.logic.UFragmentsPolicy.initialize.encode_input(
                self.owner,
                self.uFragments,
                self.config.baseCpi,
            ),
            deployer,
        )
        config = self.config

        # TODO: F/u on why these values are not being set.
        self.uFragmentsPolicy.setDeviationThreshold(config.deviationThreshold,
                                                    {"from": deployer})
        self.uFragmentsPolicy.setRebaseLag(config.rebaseLag,
                                           {"from": deployer})
        self.uFragmentsPolicy.setRebaseTimingParameters(
            config.minRebaseTimeIntervalSec,
            config.rebaseWindowOffsetSec,
            config.rebaseWindowLengthSec,
            {"from": deployer},
        )

        self.track_contract_upgradeable("uFragmentsPolicy",
                                        self.uFragmentsPolicy)
        self.track_contract_ownable(self.uFragmentsPolicy)

    def deploy_digg_token(self):
        deployer = self.owner
        self.uFragments = deploy_proxy(
            "UFragments",
            UFragments.abi,
            self.logic.UFragments.address,
            self.devProxyAdmin.address,
            self.logic.UFragments.initialize.encode_input(self.owner, ),
            deployer,
        )
        self.track_contract_upgradeable("uFragments", self.uFragments)
        self.track_contract_ownable(self.uFragments)

        # Set the digg system token after deploying.
        # TODO: Move this to a better place.
        self.token = self.uFragments

    def deploy_constant_oracle(self):
        deployer = self.deployer
        self.constantOracle = ConstantOracle.deploy(
            self.cpiMedianOracle,
            {"from": deployer},
        )
        # self.constantOracle = ConstantOracle.deploy(
        #     self.cpiMedianOracle, {"from": deployer}, publish_source=True,
        # )
        self.track_contract_static(self.constantOracle)

    def deploy_cpi_median_oracle(self):
        deployer = self.deployer
        print("deploy_cpi_median_oracle", deployer)
        self.cpiMedianOracle = MedianOracle.deploy(
            self.config.cpiOracleParams.reportExpirationTimeSec,
            self.config.cpiOracleParams.reportDelaySec,
            self.config.cpiOracleParams.minimumProviders,
            {"from": deployer},
        )
        self.track_contract_static(self.cpiMedianOracle)
        self.track_contract_ownable(self.cpiMedianOracle)

    def deploy_market_median_oracle(self):
        deployer = self.deployer
        self.marketMedianOracle = MedianOracle.deploy(
            self.config.marketOracleParams.reportExpirationTimeSec,
            self.config.marketOracleParams.reportDelaySec,
            self.config.marketOracleParams.minimumProviders,
            {"from": deployer},
        )
        self.track_contract_static(self.marketMedianOracle)
        self.track_contract_ownable(self.marketMedianOracle)

    def deploy_dao_digg_timelock(self):
        deployer = self.deployer
        print(
            self.token,
            self.dao.agent,
            self.config.startTime + self.config.tokenLockParams.lockDuration,
            chain.time(),
        )
        self.daoDiggTimelock = deploy_proxy(
            "SimpleTimelock",
            SimpleTimelock.abi,
            self.logic.SimpleTimelock.address,
            self.devProxyAdmin.address,
            self.logic.SimpleTimelock.initialize.encode_input(
                self.token,
                self.dao.agent,
                self.config.startTime +
                self.config.tokenLockParams.lockDuration,
            ),
            deployer,
        )
        self.track_contract_upgradeable("daoDiggTimelock",
                                        self.daoDiggTimelock)

    def deploy_digg_team_vesting(self):
        deployer = self.deployer

        print(
            self.token,
            self.devMultisig,
            self.dao.agent,
            self.config.startTime,
            self.config.teamVestingParams.cliffDuration,
            self.config.teamVestingParams.totalDuration,
            chain.time(),
        )

        self.diggTeamVesting = deploy_proxy(
            "SmartVesting",
            SmartVesting.abi,
            self.logic.SmartVesting.address,
            self.devProxyAdmin.address,
            self.logic.SmartVesting.initialize.encode_input(
                self.token,
                self.devMultisig,
                self.dao.agent,
                self.config.startTime,
                self.config.teamVestingParams.cliffDuration,
                self.config.teamVestingParams.totalDuration,
            ),
            deployer,
        )
        self.track_contract_upgradeable("teamVesting", self.diggTeamVesting)

    def deploy_airdrop_distributor(self, root, rewardsEscrow,
                                   reclaimAllowedTimestamp):
        deployer = self.deployer

        self.diggDistributor = deploy_proxy(
            "DiggDistributor",
            DiggDistributor.abi,
            self.logic.DiggDistributor.address,
            self.devProxyAdmin.address,
            self.logic.DiggDistributor.initialize.encode_input(
                self.token, root, rewardsEscrow, reclaimAllowedTimestamp),
            deployer,
        )

        self.track_contract_upgradeable("diggDistributor",
                                        self.diggDistributor)

    def deploy_airdrop_distributor_no_initialize(self):
        deployer = self.deployer

        self.diggDistributor = deploy_proxy_uninitialized(
            "DiggDistributor",
            DiggDistributor.abi,
            self.logic.DiggDistributor.address,
            self.devProxyAdmin.address,
            deployer,
        )

        self.track_contract_upgradeable("diggDistributor",
                                        self.diggDistributor)

    def deploy_uniswap_pairs(self, test=False):
        # TODO: read these from config, hard configured for now. (Not set on init because token is lazily populated)
        pairs = [("digg_wbtc", self.token.address, registry.tokens.wbtc)]
        for (pair_name, tokenA_addr, tokenB_addr) in pairs:
            self._deploy_uniswap_pair_idempotent(pair_name,
                                                 tokenA_addr,
                                                 tokenB_addr,
                                                 test=test)

    def _deploy_uniswap_pair_idempotent(self,
                                        pair_name,
                                        tokenA_addr,
                                        tokenB_addr,
                                        test=False):
        deployer = self.deployer

        # Deploy digg/wBTC pair if not already deployed.
        if not self.uniswap_system.hasPair(tokenA_addr, tokenB_addr):
            self.uniswap_system.createPair(tokenA_addr, tokenB_addr, deployer)
        self.uniswap_trading_pair_addrs[
            pair_name] = self.uniswap_system.getPair(tokenA_addr, tokenB_addr)

        # In test mode, add liquidity to uniswap.
        if test:
            self.uniswap_system.addMaxLiquidity(tokenA_addr, tokenB_addr,
                                                deployer)

    # ===== Administrative functions =====

    # Used on DEPLOY ONLY,  ownership of ownable contracts to a new owner.
    def transfer_ownership(self, owner):
        prevOwner = self.owner
        self.owner = owner
        for contract in self.contracts_ownable:
            contract.transferOwnership(owner, {"from": prevOwner})

    # ===== Deploy for TESTING ONLY =====

    # requires the market median oracle to be deployed as this feeds it data
    def deploy_dynamic_oracle(self):
        deployer = self.deployer
        self.dynamicOracle = DynamicOracle.deploy(
            self.marketMedianOracle,
            {"from": deployer},
        )
        self.track_contract_static(self.dynamicOracle)
Example #4
0
def create_uniswap_pair(token0, token1, signer):
    uniswap = UniswapSystem()
    if not uniswap.hasPair(token0, token1):
        uniswap.createPair(token0, token1, signer)

    return uniswap.getPair(token0, token1)