Exemplo n.º 1
0
    def deploy(self, beneficiary: str):
        # ViewAuthority
        if not self.instances['ViewAuthority']:
            self.instances['ViewAuthority'] = \
                self.deploy_contract('DSGuard', gas=1_340_000)
            print(
                f"ViewAuthority address: {self.instances['ViewAuthority'].address}"
            )

        # ViewToken
        if not self.instances['ViewToken']:
            self.instances['ViewToken'] = \
                self.deploy_contract('DSToken', args=['VIEW'], gas=2_000_000)

            tx = self.instances['ViewToken'] \
                .transact({"from": self.owner}) \
                .setAuthority(self.instances['ViewAuthority'].address)
            check_succesful_tx(self.web3, tx)
            print(f"ViewToken address: {self.instances['ViewToken'].address}")

        # Seed Sale
        if not self.instances['ViewlySeedSale']:
            self.instances['ViewlySeedSale'] = \
                self.deploy_contract(
                    'ViewlySeedSale',
                    args=[self.instances['ViewToken'].address, beneficiary])

            self.authority_permit_any(
                authority=self.instances['ViewAuthority'],
                src_address=self.instances['ViewlySeedSale'].address,
                dst_address=self.instances['ViewToken'].address,
            )
            print(
                f"ViewlySeedSale address: {self.instances['ViewlySeedSale'].address}"
            )
Exemplo n.º 2
0
def performTransfer():

    project = populus.Project()

    chain_name = 'ropsten'

    with project.get_chain(chain_name) as chain:

        web3 = chain.web3

        DToken = chain.provider.get_contract('DToken')

        print("This script will perform transfer of DTokens, if you don't want to transfer tokens, please abort program")
        input_addr = input("Specify address: ")
        input_amount = input ("Specify amount: ")

        print("Token will be send: ")
        print("From: {}".format(web3.eth.defaultAccount))
        print("To: {}".format(input_addr))
        print("Value: {}".format(input_amount))

        defaultGasPrice = web3.eth.gasPrice
        print("Default Gas Price: " + str(defaultGasPrice))

        # call Token transfer as transaction
        # multiple gas price to get fast confirmations
        txhash = DToken.transact({'gasPrice': (defaultGasPrice*5)}).transfer(input_addr,int(input_amount))

        print("Transaction hash: {}".format(txhash))

        receipt = utils.check_succesful_tx(web3, txhash)
        print("Transaction was confirmed")
Exemplo n.º 3
0
    def distribute(self):
        with Timeout() as timeout:
            while not self.distribution_ended and (
                    not self.auction_ended
                    or not len(self.addresses_claimable)):
                timeout.sleep(2)

        print('Auction ended. We should have all the addresses.',
              len(self.addresses_claimable), self.addresses_claimable)

        # 82495 gas / claimTokens

        # Call the distributor contract with batches of bidder addresses
        while len(self.addresses_claimable):
            batch_number = min(self.batch_number,
                               len(self.addresses_claimable))
            batch = self.addresses_claimable[:batch_number]
            self.addresses_claimable = self.addresses_claimable[batch_number:]
            self.claimed = self.claimed + batch

            print('Distributing tokens to {0} addresses: {1}'.format(
                batch_number, batch))
            txhash = self.distributor.transact({
                'from': self.owner,
                'gas': 4000000
            }).distribute(batch)
            receipt = check_succesful_tx(self.web3, txhash)

        self.distribution_ended_checks()
Exemplo n.º 4
0
    def authority_permit_any(self, authority, src_address, dst_address):
        """  Grant *all* priviliges to a specific address or contract via
        authority proxy.

        Args:
            authority: Address of our authority contract.
            src_address:  Contract being granted priviliges.
            dest_address: Contract for which priviliges will be granted.
        """
        tx_props = {'from': self.owner}
        tx = authority.transact(tx_props).permit(src_address, dst_address,
                                                 authority.call().ANY())
        return check_succesful_tx(self.web3, tx)
def deploySubscription():

    project = populus.Project()

    chain_name = 'ropsten'

    with project.get_chain(chain_name) as chain:

        # Load Populus contract proxy classes
        Subscription = chain.provider.get_contract_factory('Subscription')

        web3 = chain.web3
        print("Web3 provider is", web3.providers)

        # default account from populus perspective
        ownerAddr = web3.eth.defaultAccount

        print("Contracts will be deployed from: {}".format(ownerAddr))

        # defaultGasPrice = web3.eth.gasPrice
        # print("Default Gas Price: " + str(defaultGasPrice))

        # Deploy subscription contract contract
        txhash_subscribe = Subscription.deploy(transaction={"from": ownerAddr})
        print("Deploying subscription, tx hash is", txhash_subscribe)
        subscribe_receipt = utils.check_succesful_tx(web3, txhash_subscribe)
        subscribe_address = subscribe_receipt["contractAddress"]
        print("Subscription contract address is", subscribe_address)

        # Do some contract reads to see everything looks ok
        print("Some checks on deployed contract:")
        print("Subscription token owner: ",
              Subscription.call({
                  'to': subscribe_address
              }).owner())
        print("Subscription initial price: ",
              Subscription.call({
                  'to': subscribe_address
              }).subscriptionPrice())
        print("Subscription collected funds: ",
              Subscription.call({
                  'to': subscribe_address
              }).collectedFunds())
Exemplo n.º 6
0
def performTransfer():

    project = populus.Project()

    chain_name = 'ropsten'

    with project.get_chain(chain_name) as chain:

        web3 = chain.web3

        DToken = chain.provider.get_contract('DToken')

        print(
            "This script will perform transfer of DTokens, if you don't want to transfer tokens, please abort program"
        )
        input_addr = input("Specify address: ")
        input_amount = input("Specify amount: ")

        print("Token will be send: ")
        print("From: {}".format(web3.eth.defaultAccount))
        print("To: {}".format(input_addr))
        print("Value: {}".format(input_amount))

        defaultGasPrice = web3.eth.gasPrice
        print("Default Gas Price: " + str(defaultGasPrice))

        # call Token transfer as transaction
        # multiple gas price to get fast confirmations
        txhash = DToken.transact({
            'gasPrice': (defaultGasPrice * 5)
        }).transfer(input_addr, int(input_amount))

        print("Transaction hash: {}".format(txhash))

        receipt = utils.check_succesful_tx(web3, txhash)
        print("Transaction was confirmed")
Exemplo n.º 7
0
def deployDemoContracts():

    project = populus.Project()

    chain_name = 'ropsten'

    with project.get_chain(chain_name) as chain:

        # Load Populus contract proxy classes
        JoyToken = chain.provider.get_contract_factory('JoyToken')
        PlatformDeposit = chain.provider.get_contract_factory('PlatformDeposit')
        JoyGameDemo = chain.provider.get_contract_factory('JoyGameDemo')

        web3 = chain.web3
        print("Web3 provider is", web3.providers)

        # default account from populus perspective
        ownerAddr = web3.eth.defaultAccount;
        print("Contracts will be deployed from: {}".format(ownerAddr))

        defaultGasPrice = web3.eth.gasPrice
        print("Default Gas Price: " + str(defaultGasPrice))
        # multiple gas price to get fast confirmations
        #txhash = DToken.transact({'gasPrice': (defaultGasPrice*5)}).transfer(input_addr,int(input_amount))

        # unlock owner account
        #timeout=100
        #print("acc locked: {}".format(is_account_locked(web3,ownerAddr)))

        # Deploy token contract
        txhash_token = JoyToken.deploy(transaction={"from": ownerAddr})
        print("deploying token, tx hash is", txhash_token)
        receipt = utils.check_succesful_tx(web3, txhash_token)
        token_address = receipt["contractAddress"]
        print("token contract address is", token_address)

        # address needed by deposit contract, it is good to different than owner
        platformReserve_address = input ("Give platform reserve address: ")

        # Deploy deposit contract with token_address
        txhash_deposit = PlatformDeposit.deploy(transaction={"from": ownerAddr}, args=[token_address, platformReserve_address])
        print("Deploying deposit contract, tx hash is", txhash_deposit)
        receipt = utils.check_succesful_tx(web3, txhash_deposit)
        deposit_address = receipt["contractAddress"]
        print("Deposit contract address is", deposit_address)

        # game developer address
        gameDev = input ("Give game developer address: ")

        txhash_game = JoyGameDemo.deploy(transaction={"from": ownerAddr}, args=[deposit_address, gameDev])
        print("Deploying game demo contract, tx hash is", txhash_game)
        receipt = utils.check_succesful_tx(web3, txhash_game)
        game_address = receipt["contractAddress"]
        print("DemoGame contract address is", game_address)

        # Do some contract reads to see everything looks ok
        print("Some checks on deployed contracts:")
        print("Token name: ", JoyToken.call({'to':token_address}).name())
        print("Token symbol: ", JoyToken.call({'to':token_address}).symbol())
        print("Token total supply is: ", JoyToken.call({'to':token_address}).totalSupply())
        print("Token decimal places: ", JoyToken.call({'to':token_address}).decimals())
        print("Deposit owner is: ", PlatformDeposit.call({'to':deposit_address}).owner())
        print("Deposit platformReserve address: ", PlatformDeposit.call({'to':deposit_address}).platformReserve())
        print("Deposit supported Token address: ", PlatformDeposit.call({'to':deposit_address}).m_supportedToken())
        print("Game developer is: ", JoyGameDemo.call({'to':game_address}).gameDev())
        print("Game contract using deposit (address): ", JoyGameDemo.call({'to':game_address}).m_playerDeposits())
Exemplo n.º 8
0
def test_auction_bid(chain, web3, owner, wallet_address, get_bidders,
                     auction_contract_fast_decline, token_contract,
                     contract_params, txnCost, auction_end_tests,
                     auction_claim_tokens_tested):
    eth = web3.eth
    auction = auction_contract_fast_decline
    (A, B) = get_bidders(2)

    # Initialize token
    token = token_contract(auction.address)

    # Try sending funds before auction starts
    with pytest.raises(tester.TransactionFailed):
        eth.sendTransaction({'from': A, 'to': auction.address, 'value': 100})

    with pytest.raises(tester.TransactionFailed):
        auction.transact({'from': A, "value": 100}).bid()

    auction.transact({'from': owner}).setup(token.address)
    token_multiplier = auction.call().token_multiplier()

    auction.transact({'from': owner}).startAuction()

    # End auction by bidding the needed amount
    missing_funds = auction.call().missingFundsToEndAuction()

    # Test fallback function
    # 76116 gas cost
    txn_hash = eth.sendTransaction({
        'from': A,
        'to': auction.address,
        'value': 100
    })
    receipt = check_succesful_tx(web3, txn_hash)

    assert auction.call().received_wei() == 100
    assert auction.call().bids(A) == 100

    missing_funds = auction.call().missingFundsToEndAuction()

    # 46528 gas cost
    txn_hash = auction.transact({'from': A, "value": missing_funds}).bid()
    receipt = check_succesful_tx(web3, txn_hash)

    assert auction.call().received_wei() == missing_funds + 100
    assert auction.call().bids(A) == missing_funds + 100

    auction.transact({'from': owner}).finalizeAuction()
    auction_end_tests(auction, B)

    # Any payable transactions should fail now
    with pytest.raises(tester.TransactionFailed):
        auction.transact({'from': A, "value": 1}).bid()
    with pytest.raises(tester.TransactionFailed):
        eth.sendTransaction({'from': A, 'to': auction.address, 'value': 1})

    auction_claim_tokens_tested(token, auction, A)

    assert auction.call().stage() == 4  # TokensDistributed

    # Any payable transactions should fail now
    with pytest.raises(tester.TransactionFailed):
        auction.transact({'from': A, "value": 100}).bid()
    with pytest.raises(tester.TransactionFailed):
        eth.sendTransaction({'from': A, 'to': auction.address, 'value': 100})