UNPKG

@augustdigital/vaults

Version:

JS SDK for web3 interactions with the August Digital Lending Pools

161 lines 8.11 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.POOL_FUNCTIONS = exports.determineBlockSkipInternal = exports.determineBlockCutoff = exports.filterOutBySize = void 0; exports.getVaultRewards = getVaultRewards; exports.getIdleAssets = getIdleAssets; exports.buildFormattedVault = buildFormattedVault; const abis_1 = require("@augustdigital/abis"); const utils_1 = require("@augustdigital/utils"); const filterOutBySize = (usdAmount) => usdAmount > 10000; exports.filterOutBySize = filterOutBySize; const determineBlockCutoff = (chain) => { switch (chain) { case 56: return 120000; case 43114: return 120000; default: return 150000; } }; exports.determineBlockCutoff = determineBlockCutoff; const determineBlockSkipInternal = (chain) => { switch (chain) { case 43114: return 8000; case 56: return 8000; default: return 50000; } }; exports.determineBlockSkipInternal = determineBlockSkipInternal; exports.POOL_FUNCTIONS = [ 'decimals', 'asset', 'totalSupply', 'totalAssets', 'maxSupply', 'withdrawalFee', 'lagDuration', 'withdrawalsPaused' ]; function getVaultRewards(tokenizedVault) { var _a, _b; const upshiftPointRewards = (_a = tokenizedVault.rewards) === null || _a === void 0 ? void 0 : _a.filter((r) => r.text === 'Upshift Points'); const sortedPointsMultipliers = upshiftPointRewards === null || upshiftPointRewards === void 0 ? void 0 : upshiftPointRewards.sort((a, b) => new Date(b.start_datetime).getTime() - new Date(a.start_datetime).getTime()); const upshiftPointsMultipliers = sortedPointsMultipliers === null || sortedPointsMultipliers === void 0 ? void 0 : sortedPointsMultipliers.map((r) => ({ timestamp: new Date(r.start_datetime).getTime() / 1000, multiplier: r.multiplier, })); const latestUpshiftPointMultiplier = (_b = upshiftPointsMultipliers === null || upshiftPointsMultipliers === void 0 ? void 0 : upshiftPointsMultipliers[0]) === null || _b === void 0 ? void 0 : _b.multiplier; const rewards = { upshiftPoints: !!upshiftPointRewards.length ? `${latestUpshiftPointMultiplier}x Upshift Points` : '', latestUpshiftPointMultiplier, upshiftPointsMultipliers: upshiftPointsMultipliers, additionalPoints: tokenizedVault.rewards.map((r) => `${r.multiplier !== 1 ? `${r.multiplier}x` : ''} ${r.text}`), }; return rewards; } function getIdleAssets(provider, vaultAddress, underlying, totalAssets) { return __awaiter(this, void 0, void 0, function* () { let idleAssets; if (utils_1.OLD_LENDING_POOLS.includes(vaultAddress)) { const globalLoansAmount = yield (0, utils_1.createContract)({ provider, address: vaultAddress, abi: abis_1.ABI_LENDING_POOLS, }).globalLoansAmount(); idleAssets = BigInt((totalAssets).raw) - BigInt(globalLoansAmount); } else { idleAssets = yield (0, utils_1.createContract)({ provider, address: underlying, abi: abis_1.ABI_ERC20, }).balanceOf(vaultAddress); } return idleAssets; }); } function buildFormattedVault(provider, tokenizedVault, contractCalls) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f; const underlying = { address: contractCalls.asset, symbol: yield (0, utils_1.getSymbol)(provider, contractCalls.asset), decimals: contractCalls.decimals, }; if (!tokenizedVault.reported_apy) console.warn('#buildFormattedVault::reported_apy: no APY found for', tokenizedVault.receipt_token_symbol); const apy = { apy: ((_a = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _a === void 0 ? void 0 : _a.apy) * 100, explainer: (_b = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _b === void 0 ? void 0 : _b.explainer, liquidApy: ((_c = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _c === void 0 ? void 0 : _c.liquid_apy) * 100, rewardsClaimable: (_d = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _d === void 0 ? void 0 : _d.rewards_claimable, rewardsCompounded: (_e = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _e === void 0 ? void 0 : _e.rewards_compounded, underlyingApy: ((_f = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _f === void 0 ? void 0 : _f.underlying_apy) * 100, }; const strategists = tokenizedVault.subaccounts.map((s) => { var _a, _b; return ({ address: s.address, logo: (_a = s.strategist) === null || _a === void 0 ? void 0 : _a.strategist_logo, name: (_b = s.strategist) === null || _b === void 0 ? void 0 : _b.strategist_name, }); }); const platformFee = { fee: tokenizedVault.platform_fee_override.management_fee, isWaived: tokenizedVault.platform_fee_override.is_fee_waived, }; const rewards = getVaultRewards(tokenizedVault); const idleAssets = yield getIdleAssets(provider, tokenizedVault.address, contractCalls.asset, contractCalls.totalAssets); return { lagDuration: Number(contractCalls.lagDuration), address: tokenizedVault.address, name: tokenizedVault.vault_name, logoUrl: tokenizedVault.vault_logo_url, symbol: tokenizedVault.receipt_token_symbol, description: tokenizedVault.description, startDatetime: String(tokenizedVault.start_datetime), publicType: tokenizedVault.public_type, internalType: tokenizedVault.internal_type, status: tokenizedVault.status, tags: [tokenizedVault.public_type], isFeatured: tokenizedVault.is_featured, isVisible: tokenizedVault.is_visible, reserveTarget: tokenizedVault.reserve_target, reserveTolerance: tokenizedVault.reserve_tolerance, underlying, apy: apy.apy, apyBreakdown: apy, rewards, strategists, weeklyPerformanceFee: tokenizedVault.weekly_performance_fee_bps, platformFee, totalAssets: contractCalls.totalAssets, totalSupply: contractCalls.totalSupply, loansOperator: contractCalls.loansOperator, decimals: contractCalls.decimals, maxSupply: contractCalls.maxSupply, chainId: tokenizedVault.chain, maxDailyDrawdown: tokenizedVault.max_daily_drawdown || 0, risk: tokenizedVault.risk, withdrawalsPaused: contractCalls.withdrawalsPaused, idleAssets: (0, utils_1.toNormalizedBn)(idleAssets, contractCalls.decimals), }; }); } //# sourceMappingURL=utils.js.map