UNPKG

@augustdigital/pools

Version:

External services interactions

220 lines 8.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AugustPools = void 0; const utils_1 = require("@augustdigital/utils"); const getters_1 = require("./getters"); const ethers_1 = require("ethers"); const user_actions_1 = require("./user-actions"); const staking_1 = require("./staking"); class AugustPools extends utils_1.AugustBase { constructor(baseConfig) { super(baseConfig); } async getPools(options, initialData) { const pools = await Promise.all(Object.values(this.providers).map((rpcUrl) => { return (0, getters_1.getLendingPools)({ rpcUrl, optionalFields: { loans: options?.loans || false, loanAllocations: options?.allocations || false, }, env: this.monitoring?.env, apiKey: this.keys?.august, pools: initialData?.map((p) => ({ ...p, rpcUrl: this.providers?.[p.chainId], })), }); })); return pools.flat(); } async getPool(pool, chainId, options) { if (!this.authorized) throw new Error('Not authorized.'); if (!pool) throw new Error('Pool input parameter is undefined.'); if (!(0, ethers_1.isAddress)(pool)) throw new Error(`Pool input parameter is not an address: ${String(pool)}`); if (typeof chainId !== 'undefined') { if (!this.providers?.[chainId]) console.error('#getPool:', 'missing rpcUrl in initialization for chainId', chainId); } return await (0, getters_1.getLendingPool)({ pool, rpcUrl: chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl, optionalFields: { loans: options?.loans || true, loanAllocations: options?.allocations || true, }, env: this.monitoring?.env, apiKey: this.keys?.august, }); } async getPoolApr(pool, chainId, optionalParams) { if (!this.authorized) throw new Error('Not authorized.'); if (!pool) throw new Error('Pool input parameter is undefined.'); if (!(0, ethers_1.isAddress)(pool)) throw new Error(`Pool input parameter is not an address: ${String(pool)}`); const rpcUrl = chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl; return await (0, getters_1.getLendingPoolApr)({ pool, rpcUrl: rpcUrl, inputParams: optionalParams, apiKey: this.keys?.august, }); } async getPoolTvl(pool, chainId, optionalParams) { if (!this.authorized) throw new Error('Not authorized.'); if (!pool) throw new Error('Pool input parameter is undefined.'); if (!(0, ethers_1.isAddress)(pool)) throw new Error(`Pool input parameter is not an address: ${String(pool)}`); const rpcUrl = chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl; return await (0, getters_1.getLendingPoolTvl)({ pool, rpcUrl: rpcUrl, inputParams: optionalParams, }); } async getAvailableRedemptions(pool, options) { if (!this.authorized) throw new Error('Not authorized.'); if (!pool) throw new Error('Pool input parameter is undefined.'); if (!(0, ethers_1.isAddress)(pool)) throw new Error(`Pool input parameter is not an address: ${String(pool)}`); return await (0, getters_1.getLendingPoolAvailableRedemptions)({ pool, rpcUrl: options?.chainId ? this.providers?.[options?.chainId] : this.activeNetwork.rpcUrl, address: options?.address, apiKey: this.keys?.graph, }); } async getAllPositions(address, chainId, pools) { if (!this.authorized) throw new Error('Not authorized.'); if (!(0, ethers_1.isAddress)(address)) throw new Error(`Address parameter is not an address: ${String(address)}`); if (typeof pools !== 'undefined' && pools?.length) { return await (0, getters_1.getAllLendingPoolPositions)({ rpcUrl: chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl, address, env: this.monitoring?.env, pools: pools.map((p) => ({ ...p, rpcUrl: this.providers[p.chainId] })), apiKey: this.keys?.august, }); } if (chainId) { return await (0, getters_1.getAllLendingPoolPositions)({ rpcUrl: chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl, address, env: this.monitoring?.env, apiKey: this.keys?.august, }); } const positions = await Promise.all(Object.values(this.providers).map((rpcUrl) => { return (0, getters_1.getAllLendingPoolPositions)({ rpcUrl, address, env: this.monitoring?.env, apiKey: this.keys?.graph, }); })); return positions.flat(); } async getPoolLoans(pool, chainId) { return (0, getters_1.getLendingPoolLoans)({ pool, rpcUrl: chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl, env: this.monitoring?.env, optionalFields: { loanAllocations: true, loans: true }, apiKey: this.keys?.august, }); } async getManagementFee(pool, chainId) { return await (0, utils_1.getManagementFeePercent)((0, utils_1.createProvider)(chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl), pool); } async getStakingPositions(wallet, chainId) { if (chainId) { const positions = await (0, staking_1.getRewardsStakingPositions)({ rpcUrl: this.providers?.[chainId] || this.activeNetwork.rpcUrl, env: this.monitoring?.env, wallet, coinGeckoKey: this.keys?.coingecko, }); return positions; } const positions = await Promise.all(Object.values(this.providers).map((rpcUrl) => { return (0, staking_1.getRewardsStakingPositions)({ rpcUrl: chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl, env: this.monitoring?.env, wallet, coinGeckoKey: this.keys?.coingecko, }); })); return positions.flat(); } async getPoolsBorrowerHealthFactor(chainId) { if (chainId) { const health_factors = await (0, getters_1.getHealthFactorOfBorrowersByPool)({ rpcUrl: this.providers?.[chainId] || this.activeNetwork.rpcUrl, env: this.monitoring?.env, apiKey: this.keys?.august, }); return health_factors; } const health_factors = await Promise.all(Object.values(this.providers).map((rpcUrl) => { return (0, getters_1.getHealthFactorOfBorrowersByPool)({ rpcUrl: chainId ? this.providers?.[chainId] : this.activeNetwork.rpcUrl, env: this.monitoring?.env, apiKey: this.keys?.august, }); })); return health_factors.flat(); } async allowance(pool, signer) { const wallet = (await signer.getAddress()); return await (0, user_actions_1.allowance)(signer, { pool, wallet, wait: true }); } async approve(pool, signer, inputParams) { const wallet = (await signer.getAddress()); return await (0, user_actions_1.approve)(signer, { pool, wallet, wait: true, amount: inputParams.amount, }); } async deposit(pool, signer, inputParams) { const wallet = (await signer.getAddress()); return await (0, user_actions_1.deposit)(signer, { amount: inputParams.amount, wallet, pool: pool, wait: true, }); } async requestWithdrawal(pool, signer) { const wallet = (await signer.getAddress()); return await (0, user_actions_1.requestRedeem)(signer, { pool, wallet, wait: true }); } async withdraw(pool, signer, inputParams) { const wallet = (await signer.getAddress()); return await (0, user_actions_1.redeem)(signer, { wallet, pool, ...inputParams, wait: true }); } } exports.AugustPools = AugustPools; //# sourceMappingURL=main.js.map