예제 #1
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)
예제 #2
0
def configure_db():

    with database("test_db", "cluster0.dka2m.mongodb.net", "leader",
                  "6FXQ3gHXQQAkbpmI"):
        # TokenPairing(src_network="Ethereum", src_coin="ETH", src_address="native",
        #              dst_network="Secret", dst_coin="secret-ETH", dst_address="secret1nk5c3agzt3ytpkl8csfhf4e3qwleauex9ay69t").save()
        TokenPairing.objects().get(
            src_network="Ethereum", dst_coin="secret-TUSD").update(
                src_address="0x1cB0906955623920c86A3963593a02a405Bb97fC")
예제 #3
0
def configure_db():

    with database():
        # TokenPairing(src_network="Ethereum", src_coin="ETH", src_address="native",
        #              dst_network="Secret", dst_coin="secret-ETH", dst_address="secret1nk5c3agzt3ytpkl8csfhf4e3qwleauex9ay69t").save()
        TokenPairing.objects().get(
            src_network="Ethereum",
            dst_address="secret13lj8gqvdfn45d03lfrrl087dje5d6unzus2usv",
            dst_coin="secret-YEENUS").delete()
예제 #4
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)
예제 #5
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)
예제 #6
0
def test_coins():
    import os
    uri = os.environ.get("db_uri")
    with database(uri):
        coins = CoinHandler()
        print(f'coins in handler: {list(coins.keys())}')
        for addr in [
                '0xb7792dfef59e58219a63fd3d328220cc8a5bc420',
                '0xB7792dfeF59E58219A63fD3D328220cc8A5Bc420', 'bob'
        ]:
            print(f'Getting coin for address: {addr}')
            try:
                c = coins[addr]
                print(f'{c.scrt_address=}, {c.symbol=}, {c.decimals=}')
            except KeyError:
                assert (addr == 'bob')
예제 #7
0
def deploy_scrt():

    # docker exec -it secretdev secretcli tx compute store "/token.wasm.gz" --from a --gas 2000000 -b block -y
    #
    # docker exec -it secretdev secretcli tx compute store "/swap.wasm.gz" --from a --gas 2000000 -b block -y
    # 0xd475b764D1B2DCa1FE598247e5D49205E6Ac5E8e
    multisig_account = config.multisig_acc_addr
    deployer = "secret18839huzvv5v6v0z3tm6um2ascnt6vrqfsp8d4g"

    tokens = [{
        "address": "0x1cB0906955623920c86A3963593a02a405Bb97fC",
        "name": "True USD",
        "decimals": 18,
        "symbol": "TUSD"
    }, {
        "address": "0xF6fF95D53E08c9660dC7820fD5A775484f77183A",
        "name": "YEENUS",
        "decimals": 8,
        "symbol": "YNUS"
    }, {
        "address": "native",
        "name": "Ethereum",
        "decimals": 15,
        "symbol": "ETH"
    }]

    swap_contract, swap_contract_hash = init_swap_contract(deployer)
    # swap_contract = "secret1u8mgmspdeakpf7u8leq68d5xtkykskwrytevyn"
    # swap_contract_hash = "5C36ABD74F5959DD9E8BCECB2EA308BEFEAFF2A50B9BCBD2338C079266F9F0BF"
    print(f"Swap contract deployed at: {swap_contract}")
    for token in tokens:

        config.token_contract_addr = token

        scrt_token, scrt_token_code = init_token_contract(
            deployer, token["decimals"], f'S{token["symbol"]}',
            f'Secret {token["name"]}', swap_contract)
        add_minter(scrt_token, deployer)
        print(f"Secret {token['name']}, Deployed at: {scrt_token}")
        add_to_whitelist(swap_contract, scrt_token, scrt_token_code,
                         pow(10, token["decimals"]))

        import os
        uri = os.environ.get("db_uri")
        with database(uri):
            try:
                TokenPairing.objects().get(
                    src_network="Ethereum",
                    src_address=token["address"]).update(
                        dst_address=scrt_token)
                print("Updated DB record")
            except:
                print("Added new pair to db")
                TokenPairing(src_network="Ethereum",
                             src_coin=token["name"],
                             src_address=token["address"],
                             dst_network="Secret",
                             dst_coin=f"secret-{token['name']}",
                             dst_address=scrt_token,
                             decimals=18,
                             name="Ethereum").save()

    change_owner(swap_contract, config.multisig_acc_addr)