def test_deploy(test=False, deploy=True): # These should already be deployed deployer = accounts.at(decouple.config("TEST_ACCOUNT"), force=True) # deployer = accounts.at(dao_config.initialOwner, force=True) devProxyAdmin = "0x20dce41acca85e8222d6861aa6d23b6c941777bf" daoProxyAdmin = "0x11a9d034b1bbfbbdcac9cb3b86ca7d5df05140f2" console.log( "Initialize Digg System", { "deployer": deployer, "devProxyAdmin": devProxyAdmin, "daoProxyAdmin": daoProxyAdmin, }, ) if deploy: digg = deploy_digg_minimal(deployer, devProxyAdmin, daoProxyAdmin) digg.deploy_dao_digg_timelock() digg.deploy_digg_team_vesting() if test: # need some sweet liquidity for testing distribute_from_whale(whale_registry.wbtc, digg.owner) # deploy trading pairs (these deploys are always idempotent) digg.deploy_uniswap_pairs(test=test) # adds liqudity in test mode else: digg = connect_digg(digg_config.prod_json) return digg
def _distributeTokens(self, users) -> None: # Distribute full randomized percentage in first iteration. # Subsequent iterations will see a randomized percentage of # remaining distribute to create a wide distribution spectrum # and to ensure that there is enough balance to distribute. remaining = 1 # Distribute tokens from configured whales. for user in users: # Distibute a random percentage of remaining. percentage = random.random() * remaining for whale in self.whales: distribute_from_whale( whale, user, percentage=percentage, ) if self.manager.badger.digg is not None: # Explicitly distribute digg to users from ls. digg = self.manager.badger.digg balance = digg.token.balanceOf(digg.daoDiggTimelock) digg.token.transfer( user, balance * percentage, {"from": digg.daoDiggTimelock}, )
def deploy_mocks(self): deployer = self.deployer r = MockGatewayRegistry.deploy({"from": deployer}) for (tokenName, whaleConfig) in [("BTC", registry.whales.renbtc)]: token = ERC20.at(whaleConfig.token) gateway = MockGateway.deploy(token.address, {"from": deployer}) # Distribute token from whale -> deployer -> mock gateway. distribute_from_whale(whaleConfig, deployer, percentage=1.0) token.transfer(gateway, token.balanceOf(deployer), {"from": deployer}) self.mocks[tokenName] = DotMap( token=token, gateway=gateway, ) r.addGateway(tokenName, gateway.address) r.addToken(tokenName, token.address) self.mocks.registry = r
def mint(self, user): collateralAddress = self.config.emps[self.empName].collateralAddress found = False whale = None for whale in registry.whales.values(): if whale.token == collateralAddress: found = True if not found: raise Exception( f"whale for collateral address {collateralAddress} not found") distribute_from_whale(whale, user) emp = self.emp collateral = interface.IERC20(collateralAddress) userBalance = collateral.balanceOf(user) collateral.approve(emp.address, userBalance, {"from": user}) console.print( "[grey]Attempting to mint synthetic tokens from collateral[/grey]") # Mint a synthetic amount is in $, we won't try to determine the actual dollar value between # the two but rather just mint a random dollar value above the min sponsor amount and a arbitrary max. # Min sponsor amount is $100 so let's do w/ $100 - $200. syntheticAmount = random.randint(100, 200) * 10**18 # Need to ensure that we start w/ lower amounts of collateral as subsequent mints need must keep the total # position above the global collateralization ratio. rawTotalPositionCollateral = emp.rawTotalPositionCollateral() if rawTotalPositionCollateral == 0: # arbtirarily start the collateral low (1% of user balance) collateralAmount = userBalance * .01 else: cumulativeFeeMultiplier = emp.cumulativeFeeMultiplier() globalCollateralizationRatio = ( cumulativeFeeMultiplier * rawTotalPositionCollateral) / emp.totalTokensOutstanding() minCollateralAmount = (globalCollateralizationRatio * syntheticAmount) / cumulativeFeeMultiplier # collateral amount should be between the min collateral amount to keep above GCR and 5% greater. collateralAmount = random.randint(int(minCollateralAmount), int(minCollateralAmount * 1.05)) emp.create((collateralAmount, ), (syntheticAmount, ), {"from": user})