Example #1
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))
Example #2
0
def add_token(token: str):

    cfg = Config()

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

    w3 = web3_provider(cfg['eth_node'])
    account = w3.eth.account.from_key(
        "0xb84db86a570359ca8a16ad840f7495d3d8a1b799b29ae60a2032451d918f3826")

    contract = w3.eth.contract(
        address=cfg['multisig_wallet_address'],
        abi=contract_source_code['abi'],
        bytecode=contract_source_code['data']['bytecode']['object'])

    nonce = w3.eth.getTransactionCount(account.address, "pending")
    tx = contract.functions.addToken(token)
    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)
    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
    print(f"Done adding token: {tx_receipt=}")
Example #3
0
 def __init__(self, multisig_wallet: MultisigWallet, token: Token,
              private_key: bytes, account: str, config: Config):
     self.token_contract = Erc20(web3_provider(config['eth_node_address']),
                                 token, multisig_wallet.address)
     super().__init__(config=config,
                      multisig_wallet=multisig_wallet,
                      private_key=private_key,
                      account=account)
Example #4
0
    def __init__(self, contract: MultisigWallet, token: Token,
                 private_key: bytes, account: str, config: Config, **kwargs):
        super().__init__(contract, private_key, account, config, **kwargs)

        # everything is basically the same, just overload the signer and event listener
        token_contract = Erc20(web3_provider(config['eth_node_address']),
                               token, contract.address)
        self.signer = _ERC20SignerImpl(contract, token, private_key, account,
                                       config)
        self.event_listener = EthEventListener(token_contract, config)
Example #5
0
def deploy_eth():

    cfg = Config()

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

    w3 = web3_provider(cfg['eth_node_address'])
    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'],
    )

    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)
    # .transact()
    # Get transaction hash from deployed contract
    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
    print(f"Deployed at: {tx_receipt.contractAddress}")
    multisig_wallet = w3.eth.contract(address=tx_receipt.contractAddress,
                                      abi=contract_source_code['abi'])
    print("All done")
Example #6
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))