aave_v3.loan

Documentation for eth_defi.aave_v3.loan Python module.

Aave v3 loan

Functions

borrow(aave_v3_deployment, *, token, amount, ...)

Borrow asset from Aave v3.

repay(aave_v3_deployment, *, token, amount, ...)

Pay back the asset you owned in Aave v3.

supply(aave_v3_deployment, *, token, amount, ...)

Opens a loan position in Aave v3 by depositing any Aave v3 reserve token and receiving aToken back.

withdraw(aave_v3_deployment, *, token, ...)

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
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
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
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
Returns

A tuple of 2 contract functions for approve and repay transaction.

Return type

tuple[web3.contract.contract.ContractFunction, web3.contract.contract.ContractFunction]