Exemple #1
0
    def deploy(self,
               path,
               storage=None,
               network='carthagenet',
               key=None,
               github_repo_slug=None,
               github_oauth_token=None,
               dry_run=False):
        """
        Deploy contract to the specified network
        :param path: Path to the .tz file
        :param storage: Storage in JSON format (not Micheline)
        :param network:
        :param key:
        :param github_repo_slug:
        :param github_oauth_token:
        :param dry_run: Set this flag if you just want to see what would happen
        """
        ptz = pytezos.using(shell=network, key=key)
        print(
            f'Deploying contract using {ptz.key.public_key_hash()} in the {network}'
        )

        contract = get_contract(path)
        if storage is not None:
            storage = contract.storage.encode(storage)

        try:
            opg = ptz.origination(script=contract.script(
                storage=storage)).autofill().sign()
            print(f'Injecting origination operation:')
            pprint(opg.json_payload())

            if dry_run:
                pprint(opg.preapply())
                exit(0)
            else:
                opg = opg.inject(_async=False)
        except RpcError as e:
            pprint(e)
            exit(-1)
        else:
            originated_contracts = OperationResult.originated_contracts(opg)
            assert len(originated_contracts) == 1
            bcd_link = make_bcd_link(network, originated_contracts[0])
            print(f'Contract was successfully deployed: {bcd_link}')

            if github_repo_slug:
                deployment = create_deployment(github_repo_slug,
                                               github_oauth_token,
                                               environment=network)
                pprint(deployment)
                status = create_deployment_status(
                    github_repo_slug,
                    github_oauth_token,
                    deployment_id=deployment['id'],
                    state='success',
                    environment=network,
                    environment_url=bcd_link)
                pprint(status)
    def deploy_all_staking(self, file_path, meta_uri=v2_meta_uri, admin=None):
        with open(file_path) as f:
            data = json.load(f)
            duration = data["duration"]
            wrap_token = data["wrap_token"]
            reserve_contract = data["reserve_contract"]
            storages = list(
                map(lambda x: self._staking_storage(meta_uri, duration, wrap_token, reserve_contract, x["exponent"],
                                                    token=x["name"],
                                                    admin=admin),
                    data["tokens"]))
            chunk = 5
            contracts = []
            for i in range(0, len(storages), chunk):
                print(f"deploy {i} to {i + chunk}")
                local = storages[i:i + chunk]
                ops = list(map(lambda s: self.staking_contract.originate(initial_storage=s), local))

                opg = self.client.bulk(*ops).autofill().sign().inject(min_confirmations=1)
                print(f"Injected {opg['hash']}")
                deployed = OperationResult.originated_contracts(opg)
                print(f"Deployed {deployed}")
                contracts += deployed
            result = [{"contract": contract, **(data["tokens"][index])} for index, contract in enumerate(contracts)]
            print(json.dumps({"reserve_contract": reserve_contract, "contracts": result}))
Exemple #3
0
def deploy(
    _ctx,
    path: str,
    storage: Optional[str],  # pylint: disable=redefined-outer-name
    network: str,
    key: Optional[str],
    github_repo_slug: Optional[str],
    github_oauth_token: Optional[str],
    dry_run: bool,
):
    ptz = pytezos.using(shell=network, key=key)
    logger.info('Deploying contract using %s in the %s',
                ptz.key.public_key_hash(), network)

    contract = get_contract(path)
    try:
        opg = ptz.origination(script=contract.script(
            initial_storage=storage)).autofill().sign()
        logger.info('Injecting origination operation:')
        logger.info(pformat(opg.json_payload()))

        if dry_run:
            logger.info(pformat(opg.preapply()))
            sys.exit(0)
        else:
            opg = opg.inject(_async=False)
    except RpcError as e:
        logger.critical(pformat(e))
        sys.exit(-1)
    else:
        originated_contracts = OperationResult.originated_contracts(opg)
        if len(originated_contracts) != 1:
            raise Exception(
                'Operation group must has exactly one originated contract')
        bcd_link = make_bcd_link(network, originated_contracts[0])
        logger.info('Contract was successfully deployed: %s', bcd_link)

        if github_repo_slug:
            deployment = create_deployment(
                github_repo_slug,
                github_oauth_token,
                environment=network,
            )
            logger.info(pformat(deployment))
            status = create_deployment_status(
                github_repo_slug,
                github_oauth_token,
                deployment_id=deployment['id'],
                state='success',
                environment=network,
                environment_url=bcd_link,
            )
            logger.info(status)
Exemple #4
0
    def all(self,
            signers: dict[str, str],
            governance_token,
            tokens: list[TokenAndMetaType],
            nft: list[NftTokenAndMetaType] = [],
            threshold=1):
        originations = [
            self._fa2_origination(tokens),
            self._governance_token_origination(governance_token)
        ]
        originations.extend(
            [self._nft_origination(v) for k, v in enumerate(nft)])
        print("Deploying FA2s and nfts")
        opg = self.client.bulk(*originations).autofill().sign().inject(
            min_confirmations=1, _async=False)
        originated_contracts = OperationResult.originated_contracts(opg)
        for o in originated_contracts:
            _print_contract(o)
        fa2 = originated_contracts[0]
        governance = originated_contracts[1]
        nft_contracts = dict(
            (v["eth_contract"][2:], originated_contracts[k + 2])
            for k, v in enumerate(nft))

        print("Deploying quorum contract")
        quorum = self._originate_single_contract(
            self._quorum_origination(signers, threshold))

        minter = self._deploy_minter(quorum, tokens, fa2, {
            'tezos': governance,
            'eth': governance_token
        }, nft_contracts)
        admin_calls = self._set_tokens_minter(minter, fa2, governance,
                                              nft_contracts)
        print("Setting and confirming FA2s administrator")
        self.client.bulk(*admin_calls).autofill().sign().inject(
            min_confirmations=1)
        print(f"Nfts contracts: {nft_contracts}\n")
        print(
            f"FA2 contract: {fa2}\nGovernance token: {governance}\nQuorum contract: {quorum}\nMinter contract: {minter}"
        )
Exemple #5
0
    def post(self):

        payload = v.read_requests(request)
        try:
            sess = v.read_session(session)
        except:
            pytz = v.load_keystore()

        if payload['forge'] == True:
            pass

        contract = Contract.from_file('./smart_contracts/fa12.tz')
        op = pytz.origination(script=contract.script(
            storage={
                'ledger': {},
                'admin': payload['admin'],
                'paused': False,
                'totalSupply': payload['total_supply']
            })).autofill().sign().inject(_async=False, num_blocks_wait=2)

        return OperationResult.originated_contracts(op)
    def post(self):

        #try:
        payload = v.read_requests(request)
        pytz = v.read_session(session)

        swap = Contract.from_file('./smart_contracts/atomic_swap.tz')
        op = pytz.origination(script=swap.script(storage= { 
                'admin': pytz.key.public_key_hash(), 
                "interested_party": pytz.key.public_key_hash(), 
                'fa12' : payload['fa12'], 
                'immutable': False, 
                'tk_amount' : payload['tk_amount'], 
                'tz_amount' : payload['tz_amount']})).fill().sign().inject(_async=False, num_blocks_wait=2)

        swapkt = OperationResult.originated_contracts(op)
        fa12 = pytz.contract(payload['fa12'])
        print([pytz.key.public_key_hash(), swapkt[0]])
        r = fa12.transfer({"from" : pytz.key.public_key_hash(), "to" : swapkt[0], 'value' : payload['tk_amount']}).inject()
            
        return [v.filter_response(op), r]
Exemple #7
0
 def test_1_originate_contract(self) -> None:
     ci = ContractInterface.from_michelson(code)
     res = self.client.origination(ci.script()).autofill().sign().inject(
         time_between_blocks=self.TIME_BETWEEN_BLOCKS, min_confirmations=1)
     self.assertEqual(1, len(OperationResult.originated_contracts(res)))