Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
JavaScript library to connect with the APIs of the Aave ecosystem.
Initially, the library allows you to interact with the API of the decentralized lending marketplace ETHLend.
npm install aave-js
On the ETHLend marketplace, the user is able to be borrower or lender of crypto loans.
As a borrower, he can create a request defining the conditions of the loan, and registering it in an Ethereum smart contract.
The different loan requests stored on the Ethereum smart contracts are available for the other users to fund, acting as lenders.
Practical example:
Through the Marketplace object, it is possible to execute all the previous steps without interacting with the ETHLend client.
All the features of the API will be available after initializing the Marketplace object, using a valid API secret Key.
You can get an API secret key using directly the library as following:
import { Marketplace } from "aave-js";
const signupParams = {
email: "an-email@email.com",
name: "my-name",
password: "a-super-random-password",
organisation: "my-team-name" // Optional
}
const marketplace = new Marketplace("");
const API_SECRET_KEY = await marketplace.utils.signup(...signupParams)
You can also send an HTTP POST request to https://ethdenver-api.aave.com/auth/signup with the body:
{
"email": "an-email@email.com",
"name": "my-name",
"password": "a-super-random-password",
"organisation": "my-team-name"
}
In this early access version, the library allows to interact only with the requests in testnet version of the platform (Kovan smart contracts). Collateral call and default functionality is not available.
The library functions that only fetch information will return formatted plain data, for example the information of a loan request.
For the functions that modify the marketplace state (like creating a new request or funding one), the functions will return a transaction object prepare to submit using an external instance of the web3 library, with whatever necessary provider.
Once you have the API secret key, you can initialize the Marketplace object with:
import { Marketplace } from "aave-js";
const MY_API_SECRET_KEY = "A_VALID_API_SECRET_KEY";
const marketplace = new Marketplace(MY_API_SECRET_KEY);
During it's lifecycle, the loan request goes through the following states, that will be returned in the field state of the request data (marketplace.requests.getLoanData(requestAddress)).
// First we get the Ethereum addresses of all the loan requests
const allRequestsAddresses = await marketplace.requests.getAllAddresses();
const requestsData = [];
for (const requestAddress of allRequestsAddresses) {
const data = await marketplace.requests.getLoanData(requestAddress);
requestsData.push(data);
}
const borrowerAddress = "0x94D5E24B4c3cb244b9E48eB33AE6ccAD6b715456"; // The address to filter
const requestsAddressesByBorrower = await marketplace.requests.getLoansByBorrower(borrowerAddress);
This data will be necessary to know, for example, the symbols of the available collaterals and mediums (loan currencies) in the platform.
const metadata = await marketplace.requests.getMetadata();
// We can see the cryptocurrencies allowed as collateral
console.log(metadata.collateral);
// ... the cryptocurrencies allowed as loan currency
console.log(metadata.mediums);
// ... and the available duration range for a loan
console.log(metadata.durationRange);
First we create a loan request with the parameters we want.
const borrowerAddress = "0x94D5E24B4c3cb244b9E48eB33AE6ccAD6b715456"; // The wallet that creates the request
const collateralAmount = 10000;
const collateralType = "LEND";
const loanCurrency = "ETH";
// We get the maximum loan amount, depending on the Loan-To-Value ratio allowed
const maxLoanAmount = await marketplace
.requests
.getMaxLoanAmountFromCollateral(
collateralAmount,
collateralType,
loanCurrency);
const loanRequestParams = {
loanAmount: maxLoanAmount,
moe: loanCurrency,
collateralAmount: collateralAmount,
collateralType: collateralType,
mpr: 1.5,
duration: 4
}
const tx = await marketplace.requests.create(borrowerAddress,loanRequestParams);
await web3.eth.sendTransaction(tx);
After the creation of the loan request, as borrower we need to place the collateral in the Ethereum smart contract.
This action can be executed only if the loan request is in state WaitingForCollateral and if the price of the collateral price is correct.
If the collateral is an ERC20 token, we need to approve the marketplace smart contract first, as with place collateral, the smart contract tries to transfer the required collateral amount from the borrower wallet, to the loan request smart contract.
// loanData comes from calling await marketplace.requests.getLoanData(requestAddress);
const { loanAddress, borrower, collateralType, collateralAmount, state } = loanData;
const isCollateralPriceUpdated = await marketplace.requests.isCollateralPriceUpdated(loanAddress);
if (state === "WaitingForCollateral" && isCollateralPriceUpdated) {
const isApproved = await marketplace.utils.isTransferApproved(borrower, collateralType, collateralAmount);
if (!isApproved) {
const approveTx = await marketplace.utils.approveTransfer(collateralType, borrower);
await web3.eth.sendTransaction(approveTx);
}
const tx = await marketplace.requests.placeCollateral(loanAddress, borrowerAddress);
await web3.eth.sendTransaction(tx);
}
Like placing the collateral, if the loan currency is an ERC20 token, it's necessary to approve the marketplace smart contract first, as it will transfer the required loan amount from the lender wallet, to the loan request smart contract.
const { loanAddress, moe, loanAmount } = loanData;
const lenderAddress = "0x94D5E24B4c3cb244b9E48eB33AE6ccAD6b715456"; // The wallet that funds the request
const isApproved = await marketplace.utils.isTransferApproved(lenderAddress, moe, loanAmount);
if (!isApproved) {
const approveTx = await marketplace.utils.approveTransfer(moe, lenderAddress);
await web3.eth.sendTransaction(approveTx);
}
const tx = marketplace.requests.fund(loanAddress, lenderAddress, loanAmount);
await web3.eth.sendTransaction(tx);
const { loanAddress, borrower, moe, nextInstalmentAmount } = loanData;
const isApproved = await marketplace.utils.isTransferApproved(borrower, moe, nextInstalmentAmount);
if (!isApproved) {
const approveTx = await marketplace.utils.approveTransfer(moe, borrower);
await web3.eth.sendTransaction(approveTx);
}
const tx = marketplace.requests.payback(loanAddress, borrower);
await web3.eth.sendTransaction(tx);
If the collateral of a request is not placed within 30 minutes after the creation, it's gonna be necessary to update the collateral price.
const { loanAddress } = loanData;
const await.marketplace.requests.refreshCollateralPrice(loanAddress);
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
js wrapper for Aave ETHLend marketplace
The npm package aave-js receives a total of 0 weekly downloads. As such, aave-js popularity was classified as not popular.
We found that aave-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.