Esempio n. 1
0
    def __init__(self, contract: MultisigWallet,
                 s20_multisig_account: SecretAccount, config: Config,
                 **kwargs):
        self.contract = contract
        self._coins = CoinHandler()
        self.config = config
        self.multisig = s20_multisig_account
        self.event_listener = EthEventListener(contract, config)

        self.logger = get_logger(
            db_name=config.db_name,
            loglevel=config.log_level,
            logger_name=config.logger_name
            or f"{self.__class__.__name__}-{self.multisig.name}")
        self.stop_signal = Event()
        self.account_num = 0
        self.sequence_lock = Lock()
        self.sequence = 0
        self.update_sequence()
        self.event_listener.register(
            self._handle,
            contract.tracked_event(),
        )
        super().__init__(group=None,
                         name="SecretManager",
                         target=self.run,
                         **kwargs)
Esempio n. 2
0
def swap_eth():

    cfg = Config()

    private_key = "b84db86a570359ca8a16ad840f7495d3d8a1b799b29ae60a2032451d918f3826"  # your private key here
    account = "0xA48e330838A6167a68d7991bf76F2E522566Da33"  # your account here

    with open('./src/contracts/ethereum/compiled/MultiSigSwapWallet.json',
              'r') as f:
        contract_source_code = json.loads(f.read())

    w3 = web3_provider(cfg['eth_node'])
    # multisig_wallet = MultisigWallet(web3_provider, config.multisig_wallet_address)
    multisig_wallet = MultisigWallet(w3, cfg['multisig_wallet_address'])

    class SwapMessage(Message):
        def args(self):
            return "secret13l72vhjngmg55ykajxdnlalktwglyqjqv9pkq4".encode(),

    m = SwapMessage()
    tx_hash = send_contract_tx(multisig_wallet.contract,
                               'swap',
                               account,
                               bytes.fromhex(private_key),
                               value=200,
                               args=m.args())
    print(repr(tx_hash))
Esempio n. 3
0
def run_bridge():  # pylint: disable=too-many-statements
    runners = []
    logger = get_logger(logger_name='runner')
    required_configs = ['MODE', 'secret_node', 'multisig_acc_addr', 'chain_id']
    cfg = Config(required=required_configs)
    try:
        configure_secretcli(cfg)
    except RuntimeError:
        logger = get_logger(logger_name='runner')
        logger.error('Failed to set up secretcli')
        sys.exit(1)

    if cfg.get('token', ''):
        signer = Pkcs11CryptoStore(store=cfg["PKCS11_MODULE"],
                                   token=cfg["token"],
                                   user_pin=cfg["user_pin"],
                                   label=cfg.get('label'))
    else:
        signer = LocalCryptoStore(private_key=bytes_from_hex(
            cfg['eth_private_key']),
                                  account=cfg['eth_address'])

    logger.info(f'Starting with ETH address {signer.address}')

    with database(db=cfg['db_name'],
                  host=cfg['db_host'],
                  password=cfg['db_password'],
                  username=cfg['db_username']):

        eth_wallet = MultisigWallet(w3, cfg['multisig_wallet_address'])

        secret_account = SecretAccount(cfg['multisig_acc_addr'],
                                       cfg['secret_key_name'])

        eth_signer = EtherSigner(eth_wallet,
                                 signer,
                                 dst_network="Secret",
                                 config=cfg)
        s20_signer = Secret20Signer(secret_account, eth_wallet, cfg)

        runners.append(eth_signer)
        runners.append(s20_signer)

        if cfg['MODE'].lower() == 'leader':
            eth_leader = EtherLeader(eth_wallet,
                                     signer,
                                     dst_network="Secret",
                                     config=cfg)

            secret_leader = SecretAccount(cfg['multisig_acc_addr'],
                                          cfg['multisig_key_name'])
            s20_leader = Secret20Leader(secret_leader,
                                        eth_wallet,
                                        src_network="Ethereum",
                                        config=cfg)

            runners.append(eth_leader)
            runners.append(s20_leader)

        run_all(runners)
Esempio n. 4
0
    def __init__(self, contract: MultisigWallet,
                 token_to_secret_map: Dict[str, Token],
                 s20_multisig_account: SecretAccount, config: Config,
                 **kwargs):
        self.contract = contract
        self.s20_map = token_to_secret_map
        self.config = config
        self.multisig = s20_multisig_account
        self.event_listener = EthEventListener(contract, config)

        self.logger = get_logger(
            db_name=self.config['db_name'],
            logger_name=config.get(
                'logger_name',
                f"{self.__class__.__name__}-{self.multisig.name}"))
        self.stop_signal = Event()
        self.account_num = 0
        self.sequence_lock = Lock()
        self.sequence = 0
        self.update_sequence()
        self.event_listener.register(
            self._handle,
            contract.tracked_event(),
        )
        super().__init__(group=None,
                         name="SecretManager",
                         target=self.run,
                         **kwargs)
Esempio n. 5
0
def run_bridge():  # pylint: disable=too-many-statements
    runners = []
    logger = get_logger(logger_name='runner', loglevel=config.log_level)
    try:
        configure_secretcli(config)
    except RuntimeError:
        logger = get_logger(logger_name='runner', loglevel=config.log_level)
        logger.error('Failed to set up secretcli')
        sys.exit(1)

    if config.token:
        signer = Pkcs11CryptoStore(store=config.pkcs11_module,
                                   token=config.token,
                                   user_pin=config.user_pin,
                                   label=config.label)
    else:
        signer = LocalCryptoStore(private_key=bytes_from_hex(
            config.eth_private_key),
                                  account=config.eth_address)

    logger.info(f'Starting with ETH address {signer.address}')

    uri = config.db_uri
    if not uri:
        db = config.db_name or 'test_db'
        host = config.db_host or 'localhost'
        password = config.db_password
        username = config.db_username
        uri = f"mongodb+srv://{username}:{password}@{host}/{db}?retryWrites=true&w=majority"

    with database(uri):
        eth_wallet = MultisigWallet(w3, config.multisig_wallet_address)
        secret_account = SecretAccount(config.multisig_acc_addr,
                                       config.secret_key_name)

        eth_signer = EtherSigner(eth_wallet, signer, config=config)
        s20_signer = Secret20Signer(secret_account, eth_wallet, config)

        runners.append(s20_signer)

        if config.mode.lower() == 'signer':
            runners.append(eth_signer)

        if config.mode.lower() == 'leader':
            eth_leader = EtherLeader(eth_wallet, signer, config=config)

            secret_leader = SecretAccount(config.multisig_acc_addr,
                                          config.multisig_key_name)
            s20_leader = Secret20Leader(secret_leader,
                                        eth_wallet,
                                        config=config)

            runners.append(eth_leader)
            runners.append(s20_leader)

        # run_all(runners)
        run(runners, config)
Esempio n. 6
0
def multisig_wallet(web3_provider, configuration: Config, ether_accounts):
    # erc20_contract is here only to deploy and update configuration, can be remove if not working with ERC20
    from brownie.project.IntegrationTests import MultiSigSwapWallet
    # normalize_accounts = [normalize_address(acc.address) for acc in ether_accounts]
    swap_contract = MultiSigSwapWallet.deploy(
        [acc.address for acc in ether_accounts],
        configuration['signatures_threshold'], {'from': accounts[0]})
    contract_address = str(swap_contract.address)
    return MultisigWallet(web3_provider, contract_address)
Esempio n. 7
0
def run_bridge():  # pylint: disable=too-many-statements
    runners = []
    required_configs = [
        'SRC_COIN', 'DST_COIN', 'MODE', 'private_key', 'account',
        'secret_node', 'multisig_acc_addr', 'chain_id'
    ]
    cfg = Config(required=required_configs)
    try:
        configure_secretcli(cfg)
    except RuntimeError:
        logger = get_logger(logger_name='runner')
        logger.error('Failed to set up secretcli')
        sys.exit(1)

    with database(db=cfg['db_name'],
                  host=cfg['db_host'],
                  password=cfg['db_password'],
                  username=cfg['db_username']):

        eth_wallet = MultisigWallet(w3, cfg['multisig_wallet_address'])

        private_key = bytes_from_hex(cfg['private_key'])
        account = cfg['account']

        erc20_contract = ''
        secret_account = SecretAccount(cfg['multisig_acc_addr'],
                                       cfg['secret_key_name'])

        if NETWORK_PARAMS[cfg['SRC_COIN']]['type'] == 'erc20':
            token = get_token(cfg['SRC_COIN'], cfg['network'])
            erc20_contract = Erc20(w3, token, eth_wallet.address)
            src_signer = ERC20Signer(eth_wallet, token, private_key, account,
                                     cfg)
            dst_signer = Secret20Signer(erc20_contract, secret_account, cfg)
        else:
            src_signer = EtherSigner(eth_wallet, private_key, account, cfg)
            dst_signer = Secret20Signer(eth_wallet, secret_account, cfg)

        runners.append(src_signer)
        runners.append(dst_signer)

        if cfg['MODE'].lower() == 'leader':
            src_leader = get_leader(cfg['SRC_COIN'], eth_wallet, private_key,
                                    account, cfg)
            if erc20_contract:
                dst_leader = get_leader(cfg['DST_COIN'], erc20_contract,
                                        private_key, account, cfg)
            else:
                dst_leader = get_leader(cfg['DST_COIN'], eth_wallet,
                                        private_key, account, cfg)
            runners.append(src_leader)
            runners.append(dst_leader)

        run_all(runners)
Esempio n. 8
0
def swap_erc():
    cfg = Config()
    TRANSFER_AMOUNT = 100
    private_key = "b84db86a570359ca8a16ad840f7495d3d8a1b799b29ae60a2032451d918f3826"  # your private key here
    address = "0xA48e330838A6167a68d7991bf76F2E522566Da33"  # your account here

    with open('./src/contracts/ethereum/abi/IERC20.json', 'r') as f:
        contract_source_code = json.loads(f.read())
    #
    w3 = web3_provider(cfg['eth_node'])
    #
    account = w3.eth.account.from_key(private_key)
    nonce = w3.eth.getTransactionCount(account.address, "pending")
    # # multisig_wallet = MultisigWallet(web3_provider, config.multisig_wallet_address)
    multisig_wallet = MultisigWallet(
        w3, "0x03A95ab8A5de93e47b3802cbA6295ebf85f4aA6f")
    #
    try:
        erc20_contract = w3.eth.contract(
            address="0xF6fF95D53E08c9660dC7820fD5A775484f77183A",
            abi=contract_source_code['abi'])
        tx = erc20_contract.functions.approve(multisig_wallet.address,
                                              TRANSFER_AMOUNT)

        raw_tx = tx.buildTransaction(transaction={
            'from': account.address,
            'gas': 3000000,
            'nonce': nonce
        })
        signed_tx = account.sign_transaction(raw_tx)
        tx_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)

        # Get transaction hash from deployed contract
        # tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
    except Exception:
        pass

    class SwapMessage(Message):
        def args(self):
            return "secret13l72vhjngmg55ykajxdnlalktwglyqjqv9pkq4".encode(
            ), TRANSFER_AMOUNT, "0xF6fF95D53E08c9660dC7820fD5A775484f77183A"

    #         return '0xA48e330838A6167a68d7991bf76F2E522566Da33', 0, 0, '0xA48e330838A6167a68d7991bf76F2E522566Da33', '0xa9059cbb00000000000000000000000055810874c137605b96e9d2b76c3089fcc325ed5d0000000000000000000000000000000000000000000000000000000000000001'

    owners = multisig_wallet.contract.functions.getOwners().call()
    print(owners)

    tokens = multisig_wallet.contract.functions.SupportedTokens().call()
    print(tokens)

    # account = w3.eth.account.from_key("0xb84db86a570359ca8a16ad840f7495d3d8a1b799b29ae60a2032451d918f3826")
    # print(f"Deploying on {cfg['network']} from address {account.address}")
    # balance = w3.eth.getBalance(account.address, "latest")
    # if balance < 1000000000000:
    #     print("You gotta have some cash dawg")
    #     return
    #
    # # Instantiate and deploy contract
    # # contract = w3.eth.contract(abi=contract_source_code['abi'], bytecode=contract_source_code['data']['bytecode']['object'])
    # # tx = contract.constructor(signer_accounts, cfg['signatures_threshold'],)
    #

    ### add token
    # tx = multisig_wallet.contract.functions.addToken('0xF6fF95D53E08c9660dC7820fD5A775484f77183A')
    # nonce = w3.eth.getTransactionCount(account.address, "pending")
    # raw_tx = tx.buildTransaction(transaction={'from': account.address, 'gas': 3000000, 'nonce': nonce})
    # #
    # signed_tx = account.sign_transaction(raw_tx)
    # #
    # tx_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)
    # #

    #tokens = multisig_wallet.contract.functions.SupportedTokens().call()
    #print(tokens)
    m = SwapMessage()
    tx_hash = send_contract_tx(multisig_wallet.contract,
                               'swapToken',
                               address,
                               bytes.fromhex(private_key),
                               1000000,
                               value=0,
                               args=m.args())
    print(repr(tx_hash))