web3_script_tutorial icon indicating copy to clipboard operation
web3_script_tutorial copied to clipboard

讨论一下

Open cnukaus opened this issue 2 years ago • 0 comments

我把合约调用封在了一个方法里,具体的合约函数从一个字典字段传进去

一直没看到人共享太多的好脚本。你说的gm365,liangfengxiaodao是很少的几个人


async def invoke_action(
    network: str,
    action: str,
    signer,
    *args,
    wait: bool = True,
    eth_amt: int = 0,
    abi_source: str = 'api_url',
    unknown_contract: str = None,
    unknow_proxy: str = '',
    from_addr: str = None,
):
    '''
    Any action now
    args:
    abi_source, either from api, or specify directly here
    '''
    logging.info(f"VALUE PASS{args}")

    if abi_source == 'api_url':
        entrance = contract_col[action][network]['contract']
        proxy = contract_col[action][network]['proxy']
        contract_spec = env_util.init_contract(
            entrance,
            proxy,
        )

    else:
        contract_spec = env_util.w3.eth.contract(address=unknown_contract, abi=abi_source)
    tx = env_util.create_tx(
        contract_spec,
        action.split('.')[1],  # get method from action.method
        *args,
        unverified_contract=unknown_contract,
        add_from_addr=from_addr,
    )

    nonce = env_util.w3.eth.getTransactionCount(env_util.w3.toChecksumAddress(signer["address"]))
    tx.update(
        {
            "nonce": nonce,
        }
    )
    logging.info(
        f'{signer["address"]}  value{int(eth_amt * 1e18)}, USE NONCE{nonce} {json.dumps(tx)}'
    )
    env_util.write_(
        signer,
        tx,
        eth_value=int(eth_amt * 1e18),
    )

aave_dict=
{
 'aave_borrow.approveDelegation': {
        'arbitrum': {
            'contract': '0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351',
            'proxy': '0x81387c40eb75acb02757c1ae55d5936e78c9ded3',
            '1': '0xB5Ee21786D28c5Ba61661550879475976B707099',  # delegatee (fixed) , amount is unlimited , contract
            '2': 115792089237316195423570985008687907853269984665640564039457584007913129639935,  # unlimited amount fff
        },
    },
}

cnukaus avatar Mar 24 '23 14:03 cnukaus