The LendingPool
contract is the main contract of the protocol. It exposes all the user-oriented actions that can be invoked using either Solidity or web3 libraries. The source code can be found here.
deposit()
// Import interface for ERC20 standard
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
// ... rest of your contract ...
// Retrieve LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
LendingPool lendingPool = LendingPool(provider.getLendingPool());
// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 amount = 1000 * 1e18;
uint16 referral = 0;
// Approve LendingPool contract to move your DAI
IERC20(daiAddress).approve(provider.getLendingPoolCore(), amount);
// Deposit 1000 DAI
lendingPool.deposit(daiAddress, amount, referral);
/// Retrieve LendingPoolAddress
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
LendingPool lendingPool = LendingPool(provider.getLendingPool());
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
bool useAsCollateral = true;
/// setUserUseReserveAsCollateral method call
lendingPool.setUserUseReserveAsCollateral(daiAddress, useAsCollateral);
borrow()
/// Retrieve LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
LendingPool lendingPool = LendingPool(provider.getLendingPool());
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 amount = 1000 * 1e18;
/// 1 is stable rate, 2 is variable rate
uint256 variableRate = 2;
uint256 referral = 0;
/// Borrow method call
lendingPool.borrow(daiAddress, amount, variableRate, referral);
repay()
// Import interface for ERC20 standard (only needed if repaying onBehalfOf)
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
/// Retrieve LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
LendingPool lendingPool = LendingPool(provider.getLendingPool());
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 amount = 1000 * 1e18;
/// If repaying own loan
lendingPool.repay(daiAddress, amount, msg.sender);
/// If repaying on behalf of someone else
address userAddress = /*users_address*/;
IERC20(daiAddress).approve(provider.getLendingPoolCore(), amount); // Approve LendingPool contract
lendingPool.repay(daiAddres, amount, userAddress);
/// Retrieve the LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
LendingPool lendingPool = LendingPool(provider.getLendingPool());
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
/// swapBorrowRateMode method call
lendingPool.swapBorrowRateMode(daiAddress);
/// Retrieve the LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
LendingPool lendingPool = LendingPool(provider.getLendingPool());
/// Input variables
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
address rebalancedUser = /*address_to_rebalance*/;
/// rebalanceStableBorrowRate method call
lendingPool.rebalanceStableBorrowRate(daiAddress, rebalancedUser);
/// Import interface for ERC20 standard
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
/// Retrieve the LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
LendingPool lendingPool = LendingPool(provider.getLendingPool());
/// Input variables
address collateralAddress = /*collateral_address*/;
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
address userAddress = /*user_address_being_liquidated*/;
uint256 purchaseAmount = 100 * 1e18;
bool receiveATokens = true;
/// Approve LendingPool contract to move your DAI
IERC20(daiAddress).approve(provider.getLendingPoolCore(), purchaseAmount);
/// LiquidationCall method call
lendingPool.liquidationCall(
collateralAddress,
daiAddress,
userAddress,
purchaseAmount,
receiveATokens
);
/**
* Flash Loan of 1000 DAI.
* See the full tutorial here: <https://docs.aave.com/developers/tutorials/performing-a-flash-loan>
*/
/// Retrieve the LendingPool address
LendingPoolAddressesProvider provider = LendingPoolAddressesProvider(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)); // mainnet address, for other addresses: <https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances>
LendingPool lendingPool = LendingPool(provider.getLendingPool());
/// Input variables
/* the receiver is a contract that implements the IFLashLoanReceiver interface */
address receiver = /*contract_address*/;
address daiAddress = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); // mainnet DAI
uint256 amount = 1000 * 1e18;
// If no params are needed, use an empty params:
bytes memory params = "";
// Else encode the params like below (bytes encoded param of type `address` and `uint`)
// bytes memory params = abi.encode(address(this), 1234);
/// flashLoan method call
lendingPool.flashLoan(receiver, daiAddress, amount, params);