aave_v3.loan
Documentation for eth_defi.aave_v3.loan Python module.
Aave v3 loan
Functions
|
Borrow asset from Aave v3. |
|
Pay back the asset you owned in Aave v3. |
|
Opens a loan position in Aave v3 by depositing any Aave v3 reserve token and receiving aToken back. |
|
Withdraw the deposit from Aave v3. |
- supply(aave_v3_deployment, *, token, amount, wallet_address)
Opens a loan position in Aave v3 by depositing any Aave v3 reserve token and receiving aToken back.
Example:
# build transactions to supply USDC to Aave v3 approve_fn, supply_fn = supply( aave_v3_deployment=aave_v3_deployment, token=usdc.contract, amount=amount, wallet_address=hot_wallet.address, ) # approve tx = approve_fn.build_transaction({"from": hot_wallet.address}) signed = hot_wallet.sign_transaction_with_new_nonce(tx) raw_bytes = get_tx_broadcast_data(signed_tx) tx_hash = web3.eth.send_raw_transaction(raw_bytes) assert_transaction_success_with_explanation(web3, tx_hash) # supply tx = supply_fn.build_transaction({"from": hot_wallet.address}) signed = hot_wallet_account.sign_transaction_with_new_nonce(tx) raw_bytes = get_tx_broadcast_data(signed_tx) tx_hash = web3.eth.send_raw_transaction(raw_bytes) assert_transaction_success_with_explanation(web3, tx_hash)
- Parameters
aave_v3_deployment – Instance of
eth_defi.aave_v3.deployment.AaveV3Deployment.token (web3.contract.contract.Contract) – Aave v3 reserve token you want to supply.
amount (int) – The amount of token to supply.
wallet_address (eth_typing.evm.HexAddress) – Your wallet address.
- Returns
A tuple of 2 contract functions for approve and supply transaction.
- Return type
tuple[web3.contract.contract.ContractFunction, web3.contract.contract.ContractFunction]
- withdraw(aave_v3_deployment, *, token, amount, wallet_address)
Withdraw the deposit from Aave v3.
Example:
# build transactions to withdraw all USDC you deposited from Aave v3 withdraw_fn = withdraw( aave_v3_deployment=aave_v3_deployment, token=usdc.contract, amount=MAX_AMOUNT, wallet_address=hot_wallet.address, ) tx = withdraw_fn.build_transaction({"from": hot_wallet.address}) signed = hot_wallet_account.sign_transaction_with_new_nonce(tx) raw_bytes = get_tx_broadcast_data(signed_tx) tx_hash = web3.eth.send_raw_transaction(raw_bytes) assert_transaction_success_with_explanation(web3, tx_hash)
- Parameters
aave_v3_deployment – Instance of
eth_defi.aave_v3.deployment.AaveV3Deployment.token (web3.contract.contract.Contract) – Aave v3 reserve token you want to withdraw.
amount (int) – The amount of token to withdraw. Set MAX_AMOUNT if you want to withdraw everything.
wallet_address (eth_typing.evm.HexAddress) – Your wallet address.
- Returns
Withdraw contract function.
- Return type
web3.contract.contract.ContractFunction
- borrow(aave_v3_deployment, *, token, amount, wallet_address, interest_rate_mode=AaveV3InterestRateMode.VARIABLE)
Borrow asset from Aave v3. Requires you have already supplied asset as collateral in advanced.
Example:
# build transactions to borrow WETH from Aave v3 borrow_fn = borrow( aave_v3_deployment=aave_v3_deployment, token=weth.contract, amount=amount, wallet_address=hot_wallet.address, ) tx = borrow_fn.build_transaction({"from": hot_wallet.address}) signed = hot_wallet_account.sign_transaction_with_new_nonce(tx) raw_bytes = get_tx_broadcast_data(signed_tx) tx_hash = web3.eth.send_raw_transaction(raw_bytes) assert_transaction_success_with_explanation(web3, tx_hash)
- Parameters
aave_v3_deployment – Instance of
eth_defi.aave_v3.deployment.AaveV3Deployment.token (web3.contract.contract.Contract) – Aave v3 reserve token you want to borrow.
amount (int) – The amount of token to borrow.
wallet_address (eth_typing.evm.HexAddress) – Your wallet address.
interest_rate_mode (eth_defi.aave_v3.constants.AaveV3InterestRateMode) – Stable or variable borrow rate mode, default to variable borrow rate.
- Returns
Borrow contract function.
- Return type
web3.contract.contract.ContractFunction
- repay(aave_v3_deployment, *, token, amount, wallet_address, interest_rate_mode=AaveV3InterestRateMode.VARIABLE)
Pay back the asset you owned in Aave v3.
Example:
# build transactions to pay back USDC to Aave v3 approve_fn, repay_fn = repay( aave_v3_deployment=aave_v3_deployment, token=usdc.contract, amount=amount, wallet_address=hot_wallet.address, ) # approve tx = approve_fn.build_transaction({"from": hot_wallet.address}) signed = hot_wallet.sign_transaction_with_new_nonce(tx) raw_bytes = get_tx_broadcast_data(signed_tx) tx_hash = web3.eth.send_raw_transaction(raw_bytes) assert_transaction_success_with_explanation(web3, tx_hash) # repay tx = repay_fn.build_transaction({"from": hot_wallet.address}) signed = hot_wallet_account.sign_transaction_with_new_nonce(tx) raw_bytes = get_tx_broadcast_data(signed_tx) tx_hash = web3.eth.send_raw_transaction(raw_bytes) assert_transaction_success_with_explanation(web3, tx_hash)
- Parameters
aave_v3_deployment – Instance of
eth_defi.aave_v3.deployment.AaveV3Deployment.token (web3.contract.contract.Contract) – Aave v3 reserve token you want to pay back.
amount (int) – The amount of token to pay back. Set to MAX_AMOUNT to fully repay your loan.
wallet_address (eth_typing.evm.HexAddress) – Your wallet address.
interest_rate_mode (eth_defi.aave_v3.constants.AaveV3InterestRateMode) – Stable or variable borrow rate mode, default to variable borrow rate.
- Returns
A tuple of 2 contract functions for approve and repay transaction.
- Return type
tuple[web3.contract.contract.ContractFunction, web3.contract.contract.ContractFunction]