prepare_swap
Documentation for eth_defi.enzyme.uniswap_v2.prepare_swap function.
- prepare_swap(enzyme, vault, uniswap_v2, generic_adapter, token_in, token_out, swap_amount)[source]
Prepare a Uniswap v2 swap transaction for Enzyme vault.
Tells the Enzyme vault to swap some tokens
Swap from token_in to token_out
Must be transacted from the vault owner account
Note
This function is designed for unit testing, may have unrealistic slippage parameters, etc.
Example:
# Vault swaps USDC->ETH for both users # Buy ETH worth of 200 USD prepared_tx = prepare_swap( deployment, vault, uniswap_v2, generic_adapter, usdc, weth, 200 * 10**6, # 200 USD ) tx_hash = prepared_tx.transact({"from": user_1}) assert_transaction_success_with_explanation(web3, tx_hash) assert usdc.functions.balanceOf(vault.vault.address).call() == 1300 * 10**6 # USDC left assert weth.functions.balanceOf(vault.vault.address).call() == 124500872629987902 # ETH we bought 0.12450087262998791
- Parameters
enzyme (eth_defi.enzyme.deployment.EnzymeDeployment) – Enzyme deploymeent
vault (eth_defi.enzyme.vault.Vault) – Vault that needs to perform the swap
uniswap_v2 (eth_defi.uniswap_v2.deployment.UniswapV2Deployment) – Uniswap v2 deployment
generic_adapter (web3.contract.contract.Contract) – GenericAdapter contract we use for swaps
token_in (web3.contract.contract.Contract) – ERC-20 token we sell
token_out (web3.contract.contract.Contract) – ERC-20 token we buy
swap_amount (int) – Token in amount, raw
- Returns
Transaction object that can be signed and executed
- Return type
web3.contract.contract.ContractFunction