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 send_transaction(self, func_name: str, from_: str, private_key: bytes,
                      *args):
     """
     Used for sending contract transactions (executing @func_name  on a ethr contract)
     :param func_name: name of the function to invoke in the contract
     :param from_: the account from which gas payment will be taken
     :param private_key: private key matching the from_ account
     :param args: see 'send_contract_tx' for more details
     """
     return send_contract_tx(self.contract, func_name, from_, private_key,
                             *args)
 def send_transaction(self,
                      func_name: str,
                      from_: str,
                      private_key: bytes,
                      gas,
                      gas_price=None,
                      args: Tuple = None):
     """
     Used for sending contract transactions (executing @func_name  on a ethr contract)
     :param func_name: name of the function to invoke in the contract
     :param from_: the account from which gas payment will be taken
     :param private_key: private key matching the from_ account
     :param args: see 'send_contract_tx' for more details
     :param gas_price: Gas price in GWei per gas unit used
     :param gas: Gas limit per transaction. Any leftover will be refunded
     """
     return send_contract_tx(self.contract,
                             func_name,
                             from_,
                             private_key,
                             gas,
                             gas_price=gas_price,
                             args=args)
Example #4
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))