-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from cd-sigma/aavehealth
Aavehealth
- Loading branch information
Showing
9 changed files
with
595 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,297 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "contract ILendingPoolAddressesProvider", | ||
"name": "addressesProvider", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "ADDRESSES_PROVIDER", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract ILendingPoolAddressesProvider", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "getAllATokens", | ||
"outputs": [ | ||
{ | ||
"components": [ | ||
{ | ||
"internalType": "string", | ||
"name": "symbol", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "tokenAddress", | ||
"type": "address" | ||
} | ||
], | ||
"internalType": "struct AaveProtocolDataProvider.TokenData[]", | ||
"name": "", | ||
"type": "tuple[]" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "getAllReservesTokens", | ||
"outputs": [ | ||
{ | ||
"components": [ | ||
{ | ||
"internalType": "string", | ||
"name": "symbol", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "tokenAddress", | ||
"type": "address" | ||
} | ||
], | ||
"internalType": "struct AaveProtocolDataProvider.TokenData[]", | ||
"name": "", | ||
"type": "tuple[]" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "asset", | ||
"type": "address" | ||
} | ||
], | ||
"name": "getReserveConfigurationData", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "decimals", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "ltv", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "liquidationThreshold", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "liquidationBonus", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "reserveFactor", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
"name": "usageAsCollateralEnabled", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
"name": "borrowingEnabled", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
"name": "stableBorrowRateEnabled", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
"name": "isActive", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
"name": "isFrozen", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "asset", | ||
"type": "address" | ||
} | ||
], | ||
"name": "getReserveData", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "availableLiquidity", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "totalStableDebt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "totalVariableDebt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "liquidityRate", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "variableBorrowRate", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "stableBorrowRate", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "averageStableBorrowRate", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "liquidityIndex", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "variableBorrowIndex", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint40", | ||
"name": "lastUpdateTimestamp", | ||
"type": "uint40" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "asset", | ||
"type": "address" | ||
} | ||
], | ||
"name": "getReserveTokensAddresses", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "aTokenAddress", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "stableDebtTokenAddress", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "variableDebtTokenAddress", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "asset", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "user", | ||
"type": "address" | ||
} | ||
], | ||
"name": "getUserReserveData", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "currentATokenBalance", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "currentStableDebt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "currentVariableDebt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "principalStableDebt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "scaledVariableDebt", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "stableBorrowRate", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "liquidityRate", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint40", | ||
"name": "stableRateLastUpdated", | ||
"type": "uint40" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
"name": "usageAsCollateralEnabled", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const responseLib = require("../../lib/response.lib") | ||
const mongoLib = require("../../lib/mongo.lib") | ||
|
||
const healthFactorResolver = require("../resolvers/health.factor.resolver") | ||
const validatorUtil = require("../../util/validators.util") | ||
const positionModel = require("../../model/position.model") | ||
|
||
const resStatusEnum = require("../../enum/res.status.enum") | ||
const web3Lib = require("../../lib/web3.lib"); | ||
|
||
async function defaultHealthFactor(req, res) { | ||
try { | ||
let web3 = await web3Lib.getWebSocketWeb3Instance(process.env.ETH_NODE_WS_URL); | ||
let {address} = req.params | ||
|
||
if (validatorUtil.isEmpty(address)) { | ||
return responseLib.sendResponse(res, null, "Missing user address", resStatusEnum.VALIDATION_ERROR) | ||
} | ||
|
||
address = address.toLowerCase() | ||
|
||
const position = await mongoLib.findOneByQuery(positionModel, {owner: address}) | ||
|
||
if (validatorUtil.isEmpty(position)) { | ||
return responseLib.sendResponse(res, null, "No position found", resStatusEnum.VALIDATION_ERROR) | ||
} | ||
|
||
const healthFactor = await healthFactorResolver.defaultHealthFactor(position, web3) | ||
|
||
return responseLib.sendResponse(res, healthFactor, null, resStatusEnum.SUCCESS) | ||
|
||
} catch (error) { | ||
return responseLib.sendResponse(res, null, error, resStatusEnum.INTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
|
||
async function calculateHealthFactor(req, res) { | ||
try { | ||
let web3 = await web3Lib.getWebSocketWeb3Instance(process.env.ETH_NODE_WS_URL); | ||
let {address} = req.params | ||
let { | ||
collateralAssets = [], | ||
collateralAmounts = [], | ||
collateralPrices = [], | ||
debtAssets = [], | ||
debtAmounts = [], | ||
debtPrices = [], | ||
liquidationThresholds = [] | ||
} = req.body | ||
|
||
if (validatorUtil.isEmpty(address)) { | ||
return responseLib.sendResponse(res, null, "Missing user address", resStatusEnum.VALIDATION_ERROR) | ||
} | ||
|
||
address = address.toLowerCase() | ||
|
||
const healthFactor = await healthFactorResolver.calculateHealthFactor(web3, collateralAssets, collateralAmounts, collateralPrices, debtAssets, debtAmounts, debtPrices, liquidationThresholds) | ||
|
||
return responseLib.sendResponse(res, healthFactor, null, resStatusEnum.SUCCESS) | ||
|
||
|
||
} catch (error) { | ||
return responseLib.sendResponse(res, null, error, resStatusEnum.INTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
|
||
module.exports = { | ||
calculateHealthFactor: calculateHealthFactor, | ||
defaultHealthFactor: defaultHealthFactor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.