@augustdigital/sdk 3.16.5-alpha → 3.16.7-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/lib/index.js.map +1 -0
  2. package/lib/{sdk/src.ts/main.d.ts → main.d.ts} +2 -0
  3. package/lib/{sdk/src.ts/main.js → main.js} +3 -0
  4. package/lib/main.js.map +1 -0
  5. package/lib/verify.js.map +1 -0
  6. package/package.json +7 -6
  7. package/lib/abis/src.ts/AddressResolver.d.ts +0 -28
  8. package/lib/abis/src.ts/AddressResolver.js +0 -23
  9. package/lib/abis/src.ts/AddressResolver.js.map +0 -1
  10. package/lib/abis/src.ts/ChainlinkV3.d.ts +0 -87
  11. package/lib/abis/src.ts/ChainlinkV3.js +0 -117
  12. package/lib/abis/src.ts/ChainlinkV3.js.map +0 -1
  13. package/lib/abis/src.ts/ERC20.d.ts +0 -168
  14. package/lib/abis/src.ts/ERC20.js +0 -226
  15. package/lib/abis/src.ts/ERC20.js.map +0 -1
  16. package/lib/abis/src.ts/ERC20_Bytes32.d.ts +0 -135
  17. package/lib/abis/src.ts/ERC20_Bytes32.js +0 -192
  18. package/lib/abis/src.ts/ERC20_Bytes32.js.map +0 -1
  19. package/lib/abis/src.ts/ERC4626.d.ts +0 -363
  20. package/lib/abis/src.ts/ERC4626.js +0 -506
  21. package/lib/abis/src.ts/ERC4626.js.map +0 -1
  22. package/lib/abis/src.ts/ERC721.d.ts +0 -230
  23. package/lib/abis/src.ts/ERC721.js +0 -320
  24. package/lib/abis/src.ts/ERC721.js.map +0 -1
  25. package/lib/abis/src.ts/FeeOracle.d.ts +0 -120
  26. package/lib/abis/src.ts/FeeOracle.js +0 -161
  27. package/lib/abis/src.ts/FeeOracle.js.map +0 -1
  28. package/lib/abis/src.ts/LendingPool.d.ts +0 -1393
  29. package/lib/abis/src.ts/LendingPool.js +0 -1806
  30. package/lib/abis/src.ts/LendingPool.js.map +0 -1
  31. package/lib/abis/src.ts/LendingPoolV2.d.ts +0 -55
  32. package/lib/abis/src.ts/LendingPoolV2.js +0 -1832
  33. package/lib/abis/src.ts/LendingPoolV2.js.map +0 -1
  34. package/lib/abis/src.ts/LendingPoolV3.d.ts +0 -35
  35. package/lib/abis/src.ts/LendingPoolV3.js +0 -1160
  36. package/lib/abis/src.ts/LendingPoolV3.js.map +0 -1
  37. package/lib/abis/src.ts/Loan.d.ts +0 -837
  38. package/lib/abis/src.ts/Loan.js +0 -1080
  39. package/lib/abis/src.ts/Loan.js.map +0 -1
  40. package/lib/abis/src.ts/Multicall3.d.ts +0 -30
  41. package/lib/abis/src.ts/Multicall3.js +0 -94
  42. package/lib/abis/src.ts/Multicall3.js.map +0 -1
  43. package/lib/abis/src.ts/PoolAdapter.d.ts +0 -76
  44. package/lib/abis/src.ts/PoolAdapter.js +0 -412
  45. package/lib/abis/src.ts/PoolAdapter.js.map +0 -1
  46. package/lib/abis/src.ts/RewardDistributor.d.ts +0 -46
  47. package/lib/abis/src.ts/RewardDistributor.js +0 -352
  48. package/lib/abis/src.ts/RewardDistributor.js.map +0 -1
  49. package/lib/abis/src.ts/SmartAccount.d.ts +0 -16
  50. package/lib/abis/src.ts/SmartAccount.js +0 -16
  51. package/lib/abis/src.ts/SmartAccount.js.map +0 -1
  52. package/lib/abis/src.ts/TextResolver.d.ts +0 -16
  53. package/lib/abis/src.ts/TextResolver.js +0 -16
  54. package/lib/abis/src.ts/TextResolver.js.map +0 -1
  55. package/lib/abis/src.ts/UniversalResolverResolve.d.ts +0 -69
  56. package/lib/abis/src.ts/UniversalResolverResolve.js +0 -35
  57. package/lib/abis/src.ts/UniversalResolverResolve.js.map +0 -1
  58. package/lib/abis/src.ts/UniversalSignatureValidator.d.ts +0 -17
  59. package/lib/abis/src.ts/UniversalSignatureValidator.js +0 -27
  60. package/lib/abis/src.ts/UniversalSignatureValidator.js.map +0 -1
  61. package/lib/abis/src.ts/WrapperAdapter.d.ts +0 -60
  62. package/lib/abis/src.ts/WrapperAdapter.js +0 -150
  63. package/lib/abis/src.ts/WrapperAdapter.js.map +0 -1
  64. package/lib/abis/src.ts/index.d.ts +0 -19
  65. package/lib/abis/src.ts/index.js +0 -36
  66. package/lib/abis/src.ts/index.js.map +0 -1
  67. package/lib/pools/src.ts/admin-actions.d.ts +0 -0
  68. package/lib/pools/src.ts/admin-actions.js +0 -1
  69. package/lib/pools/src.ts/admin-actions.js.map +0 -1
  70. package/lib/pools/src.ts/getters-v2.d.ts +0 -0
  71. package/lib/pools/src.ts/getters-v2.js +0 -1
  72. package/lib/pools/src.ts/getters-v2.js.map +0 -1
  73. package/lib/pools/src.ts/getters.d.ts +0 -85
  74. package/lib/pools/src.ts/getters.js +0 -431
  75. package/lib/pools/src.ts/getters.js.map +0 -1
  76. package/lib/pools/src.ts/helpers.d.ts +0 -69
  77. package/lib/pools/src.ts/helpers.js +0 -634
  78. package/lib/pools/src.ts/helpers.js.map +0 -1
  79. package/lib/pools/src.ts/index.d.ts +0 -4
  80. package/lib/pools/src.ts/index.js +0 -21
  81. package/lib/pools/src.ts/index.js.map +0 -1
  82. package/lib/pools/src.ts/main.d.ts +0 -55
  83. package/lib/pools/src.ts/main.js +0 -270
  84. package/lib/pools/src.ts/main.js.map +0 -1
  85. package/lib/pools/src.ts/staking.d.ts +0 -8
  86. package/lib/pools/src.ts/staking.js +0 -116
  87. package/lib/pools/src.ts/staking.js.map +0 -1
  88. package/lib/pools/src.ts/user-actions.d.ts +0 -19
  89. package/lib/pools/src.ts/user-actions.js +0 -191
  90. package/lib/pools/src.ts/user-actions.js.map +0 -1
  91. package/lib/sdk/src.ts/index.js.map +0 -1
  92. package/lib/sdk/src.ts/main.js.map +0 -1
  93. package/lib/sdk/src.ts/verify.js.map +0 -1
  94. package/lib/services/src.ts/index.d.ts +0 -2
  95. package/lib/services/src.ts/index.js +0 -19
  96. package/lib/services/src.ts/index.js.map +0 -1
  97. package/lib/services/src.ts/slack.d.ts +0 -12
  98. package/lib/services/src.ts/slack.js +0 -57
  99. package/lib/services/src.ts/slack.js.map +0 -1
  100. package/lib/services/src.ts/subgraph.d.ts +0 -10
  101. package/lib/services/src.ts/subgraph.js +0 -460
  102. package/lib/services/src.ts/subgraph.js.map +0 -1
  103. package/lib/types/src.ts/index.d.ts +0 -8
  104. package/lib/types/src.ts/index.js +0 -24
  105. package/lib/types/src.ts/index.js.map +0 -1
  106. package/lib/types/src.ts/pools.d.ts +0 -141
  107. package/lib/types/src.ts/pools.js +0 -3
  108. package/lib/types/src.ts/pools.js.map +0 -1
  109. package/lib/types/src.ts/staking.d.ts +0 -28
  110. package/lib/types/src.ts/staking.js +0 -3
  111. package/lib/types/src.ts/staking.js.map +0 -1
  112. package/lib/types/src.ts/subgraph.d.ts +0 -45
  113. package/lib/types/src.ts/subgraph.js +0 -3
  114. package/lib/types/src.ts/subgraph.js.map +0 -1
  115. package/lib/types/src.ts/user.d.ts +0 -1
  116. package/lib/types/src.ts/user.js +0 -3
  117. package/lib/types/src.ts/user.js.map +0 -1
  118. package/lib/types/src.ts/vaults.d.ts +0 -159
  119. package/lib/types/src.ts/vaults.js +0 -3
  120. package/lib/types/src.ts/vaults.js.map +0 -1
  121. package/lib/types/src.ts/web3.d.ts +0 -19
  122. package/lib/types/src.ts/web3.js +0 -3
  123. package/lib/types/src.ts/web3.js.map +0 -1
  124. package/lib/types/src.ts/webserver.d.ts +0 -471
  125. package/lib/types/src.ts/webserver.js +0 -3
  126. package/lib/types/src.ts/webserver.js.map +0 -1
  127. package/lib/utils/src.ts/base-class.d.ts +0 -29
  128. package/lib/utils/src.ts/base-class.js +0 -48
  129. package/lib/utils/src.ts/base-class.js.map +0 -1
  130. package/lib/utils/src.ts/constants/august.d.ts +0 -57
  131. package/lib/utils/src.ts/constants/august.js +0 -61
  132. package/lib/utils/src.ts/constants/august.js.map +0 -1
  133. package/lib/utils/src.ts/constants/fallbacks.d.ts +0 -3
  134. package/lib/utils/src.ts/constants/fallbacks.js +0 -25
  135. package/lib/utils/src.ts/constants/fallbacks.js.map +0 -1
  136. package/lib/utils/src.ts/constants/index.d.ts +0 -3
  137. package/lib/utils/src.ts/constants/index.js +0 -20
  138. package/lib/utils/src.ts/constants/index.js.map +0 -1
  139. package/lib/utils/src.ts/constants/web3.d.ts +0 -25
  140. package/lib/utils/src.ts/constants/web3.js +0 -94
  141. package/lib/utils/src.ts/constants/web3.js.map +0 -1
  142. package/lib/utils/src.ts/fetcher.d.ts +0 -25
  143. package/lib/utils/src.ts/fetcher.js +0 -322
  144. package/lib/utils/src.ts/fetcher.js.map +0 -1
  145. package/lib/utils/src.ts/helpers/array.d.ts +0 -6
  146. package/lib/utils/src.ts/helpers/array.js +0 -35
  147. package/lib/utils/src.ts/helpers/array.js.map +0 -1
  148. package/lib/utils/src.ts/helpers/datetime.d.ts +0 -5
  149. package/lib/utils/src.ts/helpers/datetime.js +0 -32
  150. package/lib/utils/src.ts/helpers/datetime.js.map +0 -1
  151. package/lib/utils/src.ts/helpers/formatters.d.ts +0 -8
  152. package/lib/utils/src.ts/helpers/formatters.js +0 -114
  153. package/lib/utils/src.ts/helpers/formatters.js.map +0 -1
  154. package/lib/utils/src.ts/helpers/index.d.ts +0 -6
  155. package/lib/utils/src.ts/helpers/index.js +0 -23
  156. package/lib/utils/src.ts/helpers/index.js.map +0 -1
  157. package/lib/utils/src.ts/helpers/responses.d.ts +0 -32
  158. package/lib/utils/src.ts/helpers/responses.js +0 -238
  159. package/lib/utils/src.ts/helpers/responses.js.map +0 -1
  160. package/lib/utils/src.ts/helpers/verify-keys.d.ts +0 -2
  161. package/lib/utils/src.ts/helpers/verify-keys.js +0 -34
  162. package/lib/utils/src.ts/helpers/verify-keys.js.map +0 -1
  163. package/lib/utils/src.ts/helpers/web3.d.ts +0 -27
  164. package/lib/utils/src.ts/helpers/web3.js +0 -351
  165. package/lib/utils/src.ts/helpers/web3.js.map +0 -1
  166. package/lib/utils/src.ts/index.d.ts +0 -5
  167. package/lib/utils/src.ts/index.js +0 -22
  168. package/lib/utils/src.ts/index.js.map +0 -1
  169. package/lib/utils/src.ts/vaults.d.ts +0 -53
  170. package/lib/utils/src.ts/vaults.js +0 -167
  171. package/lib/utils/src.ts/vaults.js.map +0 -1
  172. package/lib/vaults/src.ts/admin-actions.d.ts +0 -0
  173. package/lib/vaults/src.ts/admin-actions.js +0 -1
  174. package/lib/vaults/src.ts/admin-actions.js.map +0 -1
  175. package/lib/vaults/src.ts/getters.d.ts +0 -36
  176. package/lib/vaults/src.ts/getters.js +0 -649
  177. package/lib/vaults/src.ts/getters.js.map +0 -1
  178. package/lib/vaults/src.ts/index.d.ts +0 -4
  179. package/lib/vaults/src.ts/index.js +0 -21
  180. package/lib/vaults/src.ts/index.js.map +0 -1
  181. package/lib/vaults/src.ts/main.d.ts +0 -88
  182. package/lib/vaults/src.ts/main.js +0 -497
  183. package/lib/vaults/src.ts/main.js.map +0 -1
  184. package/lib/vaults/src.ts/rpc-config.d.ts +0 -4
  185. package/lib/vaults/src.ts/rpc-config.js +0 -32
  186. package/lib/vaults/src.ts/rpc-config.js.map +0 -1
  187. package/lib/vaults/src.ts/user-actions.d.ts +0 -19
  188. package/lib/vaults/src.ts/user-actions.js +0 -191
  189. package/lib/vaults/src.ts/user-actions.js.map +0 -1
  190. package/lib/vaults/src.ts/utils.d.ts +0 -120
  191. package/lib/vaults/src.ts/utils.js +0 -438
  192. package/lib/vaults/src.ts/utils.js.map +0 -1
  193. package/lib/vaults/src.ts/vault-fetching-examples.d.ts +0 -4
  194. package/lib/vaults/src.ts/vault-fetching-examples.js +0 -40
  195. package/lib/vaults/src.ts/vault-fetching-examples.js.map +0 -1
  196. /package/lib/{sdk/src.ts/index.d.ts → index.d.ts} +0 -0
  197. /package/lib/{sdk/src.ts/index.js → index.js} +0 -0
  198. /package/lib/{sdk/src.ts/verify.d.ts → verify.d.ts} +0 -0
  199. /package/lib/{sdk/src.ts/verify.js → verify.js} +0 -0
@@ -1,634 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isBadVault = exports.LOANS_APR_DECIMALS = exports.determineBlockSkipInternal = exports.determineBlockCutoff = void 0;
13
- exports.getPoolsData = getPoolsData;
14
- exports.getPoolLoans = getPoolLoans;
15
- exports.getTokenizedPoolData = getTokenizedPoolData;
16
- exports.getPoolLoansData = getPoolLoansData;
17
- exports.getPoolBorrowerHealthFactor = getPoolBorrowerHealthFactor;
18
- const utils_1 = require("@augustdigital/utils");
19
- const abis_1 = require("@augustdigital/abis");
20
- const utils_2 = require("@augustdigital/utils");
21
- const ethers_1 = require("ethers");
22
- const utils_3 = require("@augustdigital/utils");
23
- const ethers_2 = require("ethers");
24
- const filterOutBySize = (usdAmount) => usdAmount > 10000;
25
- const determineBlockCutoff = (chain) => {
26
- switch (chain) {
27
- case 56:
28
- return 120000;
29
- case 43114:
30
- return 120000;
31
- default:
32
- return 150000;
33
- }
34
- };
35
- exports.determineBlockCutoff = determineBlockCutoff;
36
- const determineBlockSkipInternal = (chain) => {
37
- switch (chain) {
38
- case 43114:
39
- return 8000;
40
- case 56:
41
- return 8000;
42
- default:
43
- return 50000;
44
- }
45
- };
46
- exports.determineBlockSkipInternal = determineBlockSkipInternal;
47
- function addToTokenExposure(token, tokenExposure, isBorrow, protocol) {
48
- const usdAmount = Number((token === null || token === void 0 ? void 0 : token.price) || 0) * Number(token === null || token === void 0 ? void 0 : token.amount);
49
- const foundTokenExposure = tokenExposure.find((t) => t.symbol === (token === null || token === void 0 ? void 0 : token.symbol));
50
- if (foundTokenExposure) {
51
- foundTokenExposure.amount += usdAmount;
52
- }
53
- else {
54
- const protoReturnObj = {
55
- id: token === null || token === void 0 ? void 0 : token.id,
56
- chain: token === null || token === void 0 ? void 0 : token.chain,
57
- name: token === null || token === void 0 ? void 0 : token.name,
58
- symbol: (token === null || token === void 0 ? void 0 : token.optimized_symbol) || (token === null || token === void 0 ? void 0 : token.symbol),
59
- decimals: token === null || token === void 0 ? void 0 : token.decimals,
60
- logoUrl: token === null || token === void 0 ? void 0 : token.logo_url,
61
- amount: usdAmount,
62
- protocol: protocol,
63
- };
64
- tokenExposure.push(protoReturnObj);
65
- }
66
- }
67
- function parseLoanLevelDebank(debankRes) {
68
- var _a, _b;
69
- let positions = [];
70
- let exposure = [];
71
- try {
72
- const protocolExposures = ((_a = debankRes === null || debankRes === void 0 ? void 0 : debankRes.subaccount) === null || _a === void 0 ? void 0 : _a.positions) || [];
73
- positions = protocolExposures === null || protocolExposures === void 0 ? void 0 : protocolExposures.map((p) => ({
74
- value: p.logo_url,
75
- label: p.name,
76
- }));
77
- exposure = protocolExposures === null || protocolExposures === void 0 ? void 0 : protocolExposures.map((p) => {
78
- var _a;
79
- return (_a = p.portfolio_item_list) === null || _a === void 0 ? void 0 : _a.map((li) => {
80
- var _a, _b, _c, _d, _e, _f, _g;
81
- const extra = {
82
- value: (_a = li.pool) === null || _a === void 0 ? void 0 : _a.controller,
83
- label: (_b = li.pool) === null || _b === void 0 ? void 0 : _b.adapter_id,
84
- usd: (_c = li === null || li === void 0 ? void 0 : li.stats) === null || _c === void 0 ? void 0 : _c.asset_usd_value,
85
- };
86
- if ((_e = (_d = li.detail) === null || _d === void 0 ? void 0 : _d.supply_token_list) === null || _e === void 0 ? void 0 : _e.length) {
87
- const returnArr = (_g = (_f = li.detail) === null || _f === void 0 ? void 0 : _f.supply_token_list) === null || _g === void 0 ? void 0 : _g.map((t) => ({
88
- value: t === null || t === void 0 ? void 0 : t.id,
89
- label: t === null || t === void 0 ? void 0 : t.symbol,
90
- usd: (t === null || t === void 0 ? void 0 : t.amount) * (t === null || t === void 0 ? void 0 : t.price),
91
- }));
92
- return [...returnArr, extra];
93
- }
94
- return extra;
95
- });
96
- });
97
- exposure = (_b = exposure === null || exposure === void 0 ? void 0 : exposure.flat()) === null || _b === void 0 ? void 0 : _b.flat();
98
- const uniqueExposure = [];
99
- exposure === null || exposure === void 0 ? void 0 : exposure.forEach(function (a) {
100
- if (!this[a.value]) {
101
- if ((a === null || a === void 0 ? void 0 : a.value) === '0xa1290d69c65a6fe4df752f95823fae25cb99e5a7') {
102
- this[a.value] = Object.assign(Object.assign({}, a), { label: 'rsETH' });
103
- }
104
- else {
105
- this[a.value] = Object.assign({}, a);
106
- }
107
- uniqueExposure.push(this[a.value]);
108
- }
109
- this[a.value].usd += a.usd;
110
- }, Object.create(null));
111
- exposure = uniqueExposure;
112
- }
113
- catch (err) {
114
- console.error('#getPoolLoansData::strategies:', err);
115
- }
116
- return { exposure, positions };
117
- }
118
- function parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure) {
119
- var _a, _b;
120
- const tokenMap = {};
121
- const protocolTokenMap = {};
122
- const protocolExposures = ((_a = debankRes === null || debankRes === void 0 ? void 0 : debankRes.subaccount) === null || _a === void 0 ? void 0 : _a.positions) || [];
123
- const tokenExposures = ((_b = debankRes === null || debankRes === void 0 ? void 0 : debankRes.subaccount) === null || _b === void 0 ? void 0 : _b.tokens) || [];
124
- protocolExposures.forEach((pos) => {
125
- var _a, _b, _c;
126
- const protoReturnObj = {
127
- id: pos === null || pos === void 0 ? void 0 : pos.id,
128
- chain: pos === null || pos === void 0 ? void 0 : pos.chain,
129
- protocol: pos === null || pos === void 0 ? void 0 : pos.name,
130
- logoUrl: pos === null || pos === void 0 ? void 0 : pos.logo_url,
131
- siteUrl: pos === null || pos === void 0 ? void 0 : pos.site_url,
132
- assetUsdValue: 0,
133
- debtUsdValue: 0,
134
- netUsdValue: 0,
135
- label: (_b = (_a = pos === null || pos === void 0 ? void 0 : pos.portfolio_item_list) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.name,
136
- tokenExposure: tokenMap,
137
- protocolExposure: protocolTokenMap,
138
- address: '',
139
- };
140
- (_c = pos === null || pos === void 0 ? void 0 : pos.portfolio_item_list) === null || _c === void 0 ? void 0 : _c.forEach((item) => {
141
- var _a, _b, _c;
142
- protoReturnObj.assetUsdValue += ((_a = item === null || item === void 0 ? void 0 : item.stats) === null || _a === void 0 ? void 0 : _a.asset_usd_value) || 0;
143
- protoReturnObj.debtUsdValue += ((_b = item === null || item === void 0 ? void 0 : item.stats) === null || _b === void 0 ? void 0 : _b.debt_usd_value) || 0;
144
- protoReturnObj.netUsdValue += ((_c = item === null || item === void 0 ? void 0 : item.stats) === null || _c === void 0 ? void 0 : _c.net_usd_value) || 0;
145
- });
146
- const foundExistingProtocolExposure = protocolExposure.find((exp) => exp.id === pos.id);
147
- if (!foundExistingProtocolExposure &&
148
- filterOutBySize(protoReturnObj.netUsdValue)) {
149
- protocolExposure.push(protoReturnObj);
150
- }
151
- else if (foundExistingProtocolExposure) {
152
- foundExistingProtocolExposure.netUsdValue += protoReturnObj.netUsdValue;
153
- foundExistingProtocolExposure.debtUsdValue += protoReturnObj.debtUsdValue;
154
- foundExistingProtocolExposure.assetUsdValue +=
155
- protoReturnObj.assetUsdValue;
156
- }
157
- pos.portfolio_item_list.forEach((item) => {
158
- item.detail.supply_token_list.forEach((sup) => {
159
- if (sup === null || sup === void 0 ? void 0 : sup.protocol_id) {
160
- const existingArray = protocolTokenMap[sup.protocol_id] || [];
161
- if (!existingArray.includes(sup.symbol))
162
- existingArray.push(sup.symbol);
163
- }
164
- addToTokenExposure(sup, tokenExposure, false, pos.id);
165
- if ((sup === null || sup === void 0 ? void 0 : sup.symbol) && (sup === null || sup === void 0 ? void 0 : sup.logo_url)) {
166
- tokenMap[sup.symbol] = sup.logo_url;
167
- }
168
- });
169
- item.detail.borrow_token_list.forEach((bor) => {
170
- addToTokenExposure(bor, tokenExposure, true, pos.id);
171
- if ((bor === null || bor === void 0 ? void 0 : bor.symbol) && (bor === null || bor === void 0 ? void 0 : bor.logo_url)) {
172
- tokenMap[bor.symbol] = bor.logo_url;
173
- }
174
- });
175
- });
176
- });
177
- tokenExposures === null || tokenExposures === void 0 ? void 0 : tokenExposures.forEach((token) => {
178
- addToTokenExposure(token, tokenExposure, false);
179
- });
180
- return { tokenMap, protocolTokenMap, protocolExposures, tokenExposures };
181
- }
182
- exports.LOANS_APR_DECIMALS = 2;
183
- const isBadVault = (address) => {
184
- switch (address.toLowerCase()) {
185
- case '0x706162790b601A8514c18718d0c63C9D1268e89C'.toLowerCase():
186
- return true;
187
- case '0xd684AF965b1c17D628ee0d77cae94259c41260F4'.toLowerCase():
188
- return true;
189
- case '0xB78dAf3fD674B81ebeaaa88d711506fa069E1C5E'.toLowerCase():
190
- return true;
191
- case '0x4e2D90f0307A93b54ACA31dc606F93FE6b9132d2'.toLowerCase():
192
- return true;
193
- case '0x18a5a3D575F34e5eBa92ac99B0976dBe26f9F869'.toLowerCase():
194
- return true;
195
- default:
196
- return false;
197
- }
198
- };
199
- exports.isBadVault = isBadVault;
200
- const functionsToCall = [
201
- 'decimals',
202
- 'asset',
203
- 'totalSupply',
204
- 'totalAssets',
205
- 'maxSupply',
206
- 'withdrawalFee',
207
- ];
208
- function getPoolsData(_a) {
209
- return __awaiter(this, arguments, void 0, function* ({ env, pools, rpcUrl, tokenizedVaults, functions = functionsToCall, }) {
210
- const provider = (0, utils_2.createProvider)(rpcUrl);
211
- try {
212
- const contracts = yield Promise.all(pools.map((pool) => {
213
- const contract = (0, utils_2.createContract)({
214
- address: pool,
215
- abi: abis_1.ABI_LENDING_POOLS,
216
- provider,
217
- });
218
- return Promise.all(functions.map((f) => {
219
- return contract[f]();
220
- }));
221
- }));
222
- const formatted = contracts
223
- .map((contract) => contract.reduce((acc, curr, i) => {
224
- let val;
225
- if (functions[i] === 'totalSupply' ||
226
- functions[i] === 'totalAssets' ||
227
- functions[i] === 'globalLoansAmount' ||
228
- functions[i] === 'maxSupply') {
229
- val = (0, utils_2.toNormalizedBn)(curr, contract[0]);
230
- }
231
- else if (functions[i] === 'getTotalLoansDeployed') {
232
- val = (0, utils_2.toNormalizedBn)(curr, 0);
233
- }
234
- else if (functions[i] === 'withdrawalFee') {
235
- val = (0, utils_2.toNormalizedBn)(curr, 2);
236
- }
237
- else if (functions[i] === 'decimals') {
238
- val = Number(curr.toString());
239
- }
240
- else if (functions[i] === 'loansOperator') {
241
- val = '0x4DCb388488622e47683EAd1a147947140a31e485';
242
- }
243
- else {
244
- val = curr;
245
- }
246
- return Object.assign(Object.assign({}, acc), { [functions[i]]: val });
247
- }, {}))
248
- .reduce((acc, curr, i) => {
249
- return Object.assign(Object.assign({}, acc), { [pools[i]]: curr });
250
- }, {});
251
- const withUnderlyingAsset = yield Promise.all(Object.keys(formatted).map((key) => __awaiter(this, void 0, void 0, function* () {
252
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
253
- let symbol;
254
- let decimals = 18;
255
- const foundTokenizedVault = tokenizedVaults.find((tv) => tv.address === key);
256
- if (!foundTokenizedVault) {
257
- throw new Error(`Tokenized vault config not found for address: ${key}`);
258
- }
259
- let globalLoansAmount = (0, utils_2.toNormalizedBn)(0);
260
- let getTotalLoansDeployed = (0, utils_2.toNormalizedBn)(0);
261
- const isInternalTypeTokenizedVault = foundTokenizedVault.internal_type === 'tokenizedVault';
262
- if (!isInternalTypeTokenizedVault) {
263
- const contract = (0, utils_2.createContract)({
264
- address: key,
265
- abi: abis_1.ABI_LENDING_POOLS,
266
- provider,
267
- });
268
- const globalLoansAmountRes = yield contract.globalLoansAmount();
269
- const totalLoansDeployedRes = yield contract.getTotalLoansDeployed();
270
- globalLoansAmount = (0, utils_2.toNormalizedBn)(globalLoansAmountRes, (_a = formatted === null || formatted === void 0 ? void 0 : formatted[key]) === null || _a === void 0 ? void 0 : _a.decimals);
271
- getTotalLoansDeployed = (0, utils_2.toNormalizedBn)(totalLoansDeployedRes, 0);
272
- }
273
- if ((0, ethers_1.isAddress)((_b = formatted === null || formatted === void 0 ? void 0 : formatted[key]) === null || _b === void 0 ? void 0 : _b.asset) &&
274
- formatted[key].asset !== ethers_1.ZeroAddress) {
275
- const [fetchedSymbol, fetchedDecimals] = yield (0, utils_2.getTokenMetadata)(provider, formatted[key].asset, ['symbol', 'decimals']);
276
- symbol = fetchedSymbol;
277
- decimals = fetchedDecimals;
278
- }
279
- const isOldLendingPool = utils_2.OLD_LENDING_POOLS.includes(key);
280
- let managementFee = undefined;
281
- let idleAssets;
282
- if (!isOldLendingPool) {
283
- managementFee = yield (0, utils_1.getManagementFeePercent)(provider, key);
284
- idleAssets = yield (0, utils_2.createContract)({
285
- provider,
286
- address: formatted[key].asset,
287
- abi: abis_1.ABI_ERC20,
288
- }).balanceOf(key);
289
- }
290
- else {
291
- idleAssets =
292
- BigInt(formatted[key].totalAssets.raw) -
293
- BigInt(globalLoansAmount.raw);
294
- }
295
- const returnObj = Object.assign(Object.assign({}, formatted[key]), { idleAssets: (0, utils_2.toNormalizedBn)(idleAssets, formatted[key].decimals), getTotalLoansDeployed,
296
- globalLoansAmount, chainId: Number((yield provider.getNetwork()).chainId), address: key, managementFee: managementFee, underlying: {
297
- symbol: symbol,
298
- decimals: Number(decimals.toString()),
299
- address: formatted[key].asset,
300
- chain: Number((yield provider.getNetwork()).chainId),
301
- } });
302
- const strategistAddress = (_e = (_d = (_c = foundTokenizedVault.subaccounts) === null || _c === void 0 ? void 0 : _c.find((a) => { var _a; return !!((_a = a.strategist) === null || _a === void 0 ? void 0 : _a.id); })) === null || _d === void 0 ? void 0 : _d.address) !== null && _e !== void 0 ? _e : (_g = (_f = foundTokenizedVault.subaccounts) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.address;
303
- const strategist = foundTokenizedVault.hardcoded_strategists[0];
304
- const upshiftPointRewards = (_h = foundTokenizedVault.rewards) === null || _h === void 0 ? void 0 : _h.filter((r) => r.text === 'Upshift Points');
305
- const sortedPointsMultipliers = upshiftPointRewards === null || upshiftPointRewards === void 0 ? void 0 : upshiftPointRewards.sort((a, b) => new Date(b.start_datetime).getTime() -
306
- new Date(a.start_datetime).getTime());
307
- const upshiftPointsMultipliers = sortedPointsMultipliers === null || sortedPointsMultipliers === void 0 ? void 0 : sortedPointsMultipliers.map((r) => ({
308
- timestamp: new Date(r.start_datetime).getTime() / 1000,
309
- multiplier: r.multiplier,
310
- }));
311
- const latestUpshiftPointMultiplier = (_j = upshiftPointsMultipliers === null || upshiftPointsMultipliers === void 0 ? void 0 : upshiftPointsMultipliers[0]) === null || _j === void 0 ? void 0 : _j.multiplier;
312
- const formattedTokenizedVault = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ description: foundTokenizedVault.description, rewards: {
313
- upshift_points: !!upshiftPointRewards.length
314
- ? `${latestUpshiftPointMultiplier}x Upshift Points`
315
- : '',
316
- latestUpshiftPointMultiplier,
317
- upshift_points_multipliers: upshiftPointsMultipliers,
318
- additional_points: foundTokenizedVault.rewards.map((r) => `${r.multiplier !== 1 ? `${r.multiplier}x` : ''} ${r.text}`),
319
- }, hardcodedStrategist: strategistAddress, strategist, symbol: foundTokenizedVault.receipt_token_symbol, internalType: foundTokenizedVault.internal_type, publicType: foundTokenizedVault.public_type }, (((_k = foundTokenizedVault.platform_fee_override) === null || _k === void 0 ? void 0 : _k.management_fee) && {
320
- managementFee: (_l = foundTokenizedVault.platform_fee_override) === null || _l === void 0 ? void 0 : _l.management_fee,
321
- })), (((_m = foundTokenizedVault.platform_fee_override) === null || _m === void 0 ? void 0 : _m.is_fee_waived) && {
322
- isFeeWaived: (_o = foundTokenizedVault.platform_fee_override) === null || _o === void 0 ? void 0 : _o.is_fee_waived,
323
- })), (foundTokenizedVault.weekly_performance_fee_bps && {
324
- performanceFee: foundTokenizedVault.weekly_performance_fee_bps,
325
- })), (((_p = foundTokenizedVault.reported_apy) === null || _p === void 0 ? void 0 : _p.apy) && {
326
- apy: ((_q = foundTokenizedVault.reported_apy) === null || _q === void 0 ? void 0 : _q.apy) * 100,
327
- })), { name: foundTokenizedVault.vault_name, logoUrl: foundTokenizedVault.vault_logo_url, isFeatured: foundTokenizedVault.is_featured, isVisible: foundTokenizedVault.is_visible, risk: foundTokenizedVault.risk });
328
- return Object.assign(Object.assign(Object.assign({}, returnObj), formattedTokenizedVault), { loansOperator: strategistAddress || (returnObj === null || returnObj === void 0 ? void 0 : returnObj.loansOperator) || '' });
329
- })));
330
- if (env === 'DEV')
331
- console.log('#getPoolsData:', withUnderlyingAsset);
332
- return withUnderlyingAsset;
333
- }
334
- catch (e) {
335
- console.error('#getPoolsData:', e);
336
- }
337
- });
338
- }
339
- function getPoolLoans(_a) {
340
- return __awaiter(this, arguments, void 0, function* ({ pool, rpcUrl, env, }) {
341
- if (pool.internalType === 'tokenizedVault')
342
- return [];
343
- const provider = (0, utils_2.createProvider)(rpcUrl);
344
- let loans = [];
345
- if (BigInt(pool.getTotalLoansDeployed.raw) > BigInt(0)) {
346
- const indexArray = [
347
- ...Array(Number(pool.getTotalLoansDeployed.raw)).keys(),
348
- ];
349
- loans = yield Promise.all(indexArray.map((i) => {
350
- const poolContract = (0, utils_2.createContract)({
351
- address: pool.address,
352
- abi: abis_1.ABI_LENDING_POOLS,
353
- provider,
354
- });
355
- const loansDeployed = poolContract.loansDeployed(BigInt(i));
356
- return loansDeployed;
357
- }));
358
- }
359
- if ((pool === null || pool === void 0 ? void 0 : pool.chainId) === 1) {
360
- const loanToExclude1 = loans.findIndex((loan) => (0, ethers_2.getAddress)(loan) ===
361
- (0, ethers_2.getAddress)('0xb1dAA4956821521b53E90BA44509534b934f647f'));
362
- loans.splice(loanToExclude1, 1);
363
- }
364
- return loans;
365
- });
366
- }
367
- function getTokenizedPoolData(_a) {
368
- return __awaiter(this, arguments, void 0, function* ({ pool, rpcUrl, env, strategies, apiKey, }) {
369
- var _b, _c, _d, _e;
370
- const provider = (0, utils_2.createProvider)(rpcUrl);
371
- const network = yield provider.getNetwork();
372
- let returnObj = {
373
- apy: 0,
374
- collateral: [],
375
- loans: [],
376
- protocolExposure: [],
377
- tokenExposure: [],
378
- cefiExposure: [],
379
- };
380
- let protocolExposure = [];
381
- let tokenExposure = [];
382
- let cefiExposure = [];
383
- try {
384
- const tokenizedVault = (_b = (yield (0, utils_1.fetchTokenizedVaults)(pool.address))) === null || _b === void 0 ? void 0 : _b[0];
385
- const foundWhitelistedSubaccounts = tokenizedVault.internal_type === 'tokenizedVault'
386
- ? (_c = tokenizedVault.subaccounts) === null || _c === void 0 ? void 0 : _c.map((s) => s.address)
387
- : [];
388
- if (foundWhitelistedSubaccounts === null || foundWhitelistedSubaccounts === void 0 ? void 0 : foundWhitelistedSubaccounts.length) {
389
- const morphoApyResponses = yield Promise.all(foundWhitelistedSubaccounts === null || foundWhitelistedSubaccounts === void 0 ? void 0 : foundWhitelistedSubaccounts.map((whitelistedSubaccount) => (0, utils_1.fetchAugustPublic)(`${utils_2.WEBSERVER_ENDPOINTS.public.integrations.morpho.apy(whitelistedSubaccount, pool.address)}&chain=${Number(network.chainId)}`)));
390
- let cumulativeApy = 0;
391
- let collateral = [];
392
- if (morphoApyResponses === null || morphoApyResponses === void 0 ? void 0 : morphoApyResponses.length) {
393
- for (const res of morphoApyResponses) {
394
- if (res.status === 200) {
395
- const jsonRes = (yield res.json());
396
- cumulativeApy += jsonRes.apy * 100;
397
- collateral.push(jsonRes.token.address);
398
- }
399
- }
400
- }
401
- const uniqueBorrowers = foundWhitelistedSubaccounts;
402
- let debankBorrowerResponses = {};
403
- let cefiBorrowerResponses = {};
404
- let otcPositions = {};
405
- for (const b of uniqueBorrowers) {
406
- const debankResponse = yield (0, utils_2.fetchAugustWithKey)(apiKey, utils_2.WEBSERVER_ENDPOINTS.subaccount.debank(b));
407
- console.log('#getTokenizedPoolData::defi:', debankResponse.status, debankResponse.statusText);
408
- if (debankResponse.status === 200) {
409
- const debankRes = yield debankResponse.json();
410
- debankBorrowerResponses[b] = debankRes;
411
- parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure);
412
- }
413
- const cefiResponse = yield (0, utils_2.fetchAugustWithKey)(apiKey, utils_2.WEBSERVER_ENDPOINTS.subaccount.cefi(b));
414
- console.log('#getTokenizedPoolData::cefi:', cefiResponse.status, cefiResponse.statusText);
415
- if (cefiResponse.status === 200) {
416
- const cefiRes = (yield cefiResponse.json());
417
- cefiBorrowerResponses[b] = cefiRes;
418
- cefiExposure = cefiRes;
419
- }
420
- const otcResponse = yield (0, utils_2.fetchAugustWithKey)(apiKey, utils_2.WEBSERVER_ENDPOINTS.subaccount.otc_positions(b));
421
- console.log('#getTokenizedPoolData::otc:', otcResponse.status, otcResponse.statusText);
422
- if (otcResponse.status === 200) {
423
- const otcRes = (yield otcResponse.json());
424
- otcPositions[b] = otcRes;
425
- }
426
- }
427
- const tokenizedVaultApy = ((_d = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _d === void 0 ? void 0 : _d.apy) &&
428
- ((_e = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _e === void 0 ? void 0 : _e.apy) * 100;
429
- returnObj = {
430
- apy: tokenizedVaultApy || cumulativeApy / (morphoApyResponses === null || morphoApyResponses === void 0 ? void 0 : morphoApyResponses.length),
431
- collateral,
432
- loans: [],
433
- tokenExposure: tokenExposure.filter((t) => filterOutBySize(t.amount)),
434
- protocolExposure,
435
- cefiExposure,
436
- debankBorrowerResponses,
437
- otcPositions,
438
- vaultsSubAccWhitelist: foundWhitelistedSubaccounts || [],
439
- };
440
- }
441
- if (env === 'DEV')
442
- console.log('#getTokenizedPoolData:', returnObj);
443
- return returnObj;
444
- }
445
- catch (e) {
446
- return returnObj;
447
- }
448
- });
449
- }
450
- function getPoolLoansData(_a) {
451
- return __awaiter(this, arguments, void 0, function* ({ pool, loans, rpcUrl, env, strategies, apiKey, }) {
452
- var _b, _c;
453
- const provider = (0, utils_2.createProvider)(rpcUrl);
454
- let returnObj = {
455
- apy: 0,
456
- collateral: [],
457
- loans: [],
458
- protocolExposure: [],
459
- tokenExposure: [],
460
- cefiExposure: [],
461
- };
462
- let protocolExposure = [];
463
- let tokenExposure = [];
464
- let cefiExposure = [];
465
- let debankBorrowerResponses = {};
466
- let cefiBorrowerResponses = {};
467
- let otcPositions = {};
468
- try {
469
- if (pool.internalType === 'tokenizedVault') {
470
- const tokenizedVaultData = yield getTokenizedPoolData({
471
- pool,
472
- rpcUrl,
473
- env,
474
- strategies,
475
- apiKey,
476
- });
477
- returnObj = tokenizedVaultData;
478
- }
479
- else {
480
- const tokenizedVault = (_b = (yield (0, utils_1.fetchTokenizedVaults)(pool.address))) === null || _b === void 0 ? void 0 : _b[0];
481
- const foundWhitelistedSubaccounts = (_c = tokenizedVault.subaccounts) === null || _c === void 0 ? void 0 : _c.map((s) => s.address);
482
- let aggregateApr = BigInt(0);
483
- const collateralTokens = [];
484
- const activeLoans = (yield Promise.all(loans.map((l) => __awaiter(this, void 0, void 0, function* () {
485
- const loanContract = (0, utils_2.createContract)({
486
- provider,
487
- address: l,
488
- abi: abis_1.ABI_LOAN,
489
- });
490
- const loanState = yield loanContract.loanState();
491
- if ((0, utils_2.loanStateToReadable)(loanState) !== 'ACTIVE')
492
- return;
493
- return l;
494
- })))).filter((l) => l !== undefined);
495
- const formattedLoansArray = yield Promise.all(activeLoans.map((l) => __awaiter(this, void 0, void 0, function* () {
496
- const loanContract = (0, utils_2.createContract)({
497
- provider,
498
- address: l,
499
- abi: abis_1.ABI_LOAN,
500
- });
501
- return {
502
- borrower: yield loanContract.borrower(),
503
- loan: l,
504
- };
505
- })));
506
- const uniqueBorrowers = [
507
- ...new Set(formattedLoansArray.map((l) => l.borrower)),
508
- ];
509
- for (const borrower of uniqueBorrowers) {
510
- const debankResponse = yield (0, utils_2.fetchAugustWithKey)(apiKey, utils_2.WEBSERVER_ENDPOINTS.subaccount.debank(borrower));
511
- console.log('#getPoolLoansData::defi:', debankResponse.status, debankResponse.statusText);
512
- if (debankResponse.status === 200) {
513
- const debankRes = yield debankResponse.json();
514
- debankBorrowerResponses[borrower] = debankRes;
515
- parseVaultLevelDebank(debankRes, protocolExposure, tokenExposure);
516
- }
517
- const cefiResponse = yield (0, utils_2.fetchAugustWithKey)(apiKey, utils_2.WEBSERVER_ENDPOINTS.subaccount.cefi(borrower));
518
- console.log('#getPoolLoansData::cefi:', cefiResponse.status, cefiResponse.statusText);
519
- if (cefiResponse.status === 200) {
520
- const cefiRes = (yield cefiResponse.json());
521
- cefiBorrowerResponses[borrower] = cefiRes;
522
- cefiExposure = cefiRes;
523
- }
524
- const otcResponse = yield (0, utils_2.fetchAugustWithKey)(apiKey, utils_2.WEBSERVER_ENDPOINTS.subaccount.otc_positions(borrower));
525
- console.log('#getPoolLoansData::otc:', otcResponse.status, otcResponse.statusText);
526
- if (otcResponse.status === 200) {
527
- const otcRes = (yield otcResponse.json());
528
- otcPositions[borrower] = otcRes;
529
- }
530
- }
531
- const newLoans = (yield Promise.all(formattedLoansArray === null || formattedLoansArray === void 0 ? void 0 : formattedLoansArray.map((loanObj) => __awaiter(this, void 0, void 0, function* () {
532
- var _a, _b;
533
- const loanContract = (0, utils_2.createContract)({
534
- provider,
535
- address: loanObj.loan,
536
- abi: abis_1.ABI_LOAN,
537
- });
538
- const borrower = loanObj.borrower;
539
- const [_loanApr, _principalAmt, _collateral, _principalRepaid] = yield Promise.all([
540
- loanContract.currentApr(),
541
- loanContract.principalAmount(),
542
- loanContract.collateralToken(),
543
- loanContract.principalRepaid(),
544
- ]);
545
- aggregateApr += _loanApr || BigInt(0);
546
- if (!collateralTokens.includes(_collateral))
547
- collateralTokens.push(_collateral);
548
- const allocation = Number((0, ethers_1.formatUnits)(_principalAmt, pool === null || pool === void 0 ? void 0 : pool.decimals)) /
549
- Number((0, ethers_1.formatUnits)((_a = pool === null || pool === void 0 ? void 0 : pool.totalSupply) === null || _a === void 0 ? void 0 : _a.raw, pool === null || pool === void 0 ? void 0 : pool.decimals));
550
- const loanFeeRate = yield (0, utils_3.getLoanOracleFeeRate)(provider, 'LOAN.REPAY.INTERESTS', loanObj.loan, pool === null || pool === void 0 ? void 0 : pool.chainId);
551
- const loanApr = Number(_loanApr || 0) / 100;
552
- const loanAprAfterFees = loanApr * (1 - loanFeeRate / 100);
553
- const isIdleCapital = utils_1.IDLE_CAPITAL_BORROWER_ADDRESS.includes(borrower);
554
- const { positions, exposure } = parseLoanLevelDebank(debankBorrowerResponses[borrower]);
555
- const newLoanObj = {
556
- address: loanObj.loan,
557
- apr: loanAprAfterFees,
558
- collateral: _collateral,
559
- principal: (0, utils_2.toNormalizedBn)(_principalAmt, (_b = pool === null || pool === void 0 ? void 0 : pool.underlying) === null || _b === void 0 ? void 0 : _b.decimals),
560
- repaid: (0, utils_2.toNormalizedBn)(_principalRepaid, pool === null || pool === void 0 ? void 0 : pool.chainId),
561
- allocation,
562
- positions,
563
- exposure,
564
- borrower,
565
- augustFee: loanFeeRate,
566
- idleCapital: isIdleCapital,
567
- };
568
- return newLoanObj;
569
- })))).filter((l) => l !== undefined);
570
- const weightedAverage = newLoans.reduce((acc, { apr, allocation }) => acc + apr * allocation, 0);
571
- returnObj = {
572
- apy: pool.apy ? pool.apy : weightedAverage,
573
- collateral: collateralTokens,
574
- loans: newLoans,
575
- tokenExposure: tokenExposure.filter((t) => filterOutBySize(t.amount)),
576
- protocolExposure,
577
- cefiExposure,
578
- debankBorrowerResponses,
579
- otcPositions,
580
- vaultsSubAccWhitelist: foundWhitelistedSubaccounts || [],
581
- };
582
- }
583
- if (env === 'DEV')
584
- console.log('#getPoolLoansData:', returnObj);
585
- return returnObj;
586
- }
587
- catch (e) {
588
- return returnObj;
589
- }
590
- });
591
- }
592
- function getPoolBorrowerHealthFactor(_a) {
593
- return __awaiter(this, arguments, void 0, function* ({ pool, rpcUrl, env, apiKey, }) {
594
- const provider = (0, utils_2.createProvider)(rpcUrl);
595
- const loans = yield getPoolLoans({ pool, rpcUrl, env });
596
- const activeLoans = (yield Promise.all(loans.map((l) => __awaiter(this, void 0, void 0, function* () {
597
- const loanContract = (0, utils_2.createContract)({
598
- provider,
599
- address: l,
600
- abi: abis_1.ABI_LOAN,
601
- });
602
- const loanState = yield loanContract.loanState();
603
- if ((0, utils_2.loanStateToReadable)(loanState) !== 'ACTIVE')
604
- return;
605
- return l;
606
- })))).filter((l) => l !== undefined);
607
- const formattedLoansArray = yield Promise.all(activeLoans.map((l) => __awaiter(this, void 0, void 0, function* () {
608
- const loanContract = (0, utils_2.createContract)({
609
- provider,
610
- address: l,
611
- abi: abis_1.ABI_LOAN,
612
- });
613
- return {
614
- borrower: yield loanContract.borrower(),
615
- loan: l,
616
- };
617
- })));
618
- const uniqueBorrowers = [
619
- ...new Set(formattedLoansArray.map((l) => l.borrower)),
620
- ];
621
- let borrowerResponses = {};
622
- for (const b of uniqueBorrowers) {
623
- const response = yield (0, utils_2.fetchAugustWithKey)(apiKey, utils_2.WEBSERVER_ENDPOINTS.subaccount.health_factor(b));
624
- if (response.status === 200) {
625
- borrowerResponses[b] = yield response.json();
626
- }
627
- }
628
- formattedLoansArray === null || formattedLoansArray === void 0 ? void 0 : formattedLoansArray.map((loan) => {
629
- loan.health_factor = borrowerResponses[loan.borrower];
630
- });
631
- return formattedLoansArray;
632
- });
633
- }
634
- //# sourceMappingURL=helpers.js.map