@augustdigital/sdk 3.16.4-alpha → 3.16.6-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/main.js.map +1 -0
  3. package/lib/verify.js.map +1 -0
  4. package/package.json +7 -7
  5. package/lib/abis/src.ts/AddressResolver.d.ts +0 -28
  6. package/lib/abis/src.ts/AddressResolver.js +0 -23
  7. package/lib/abis/src.ts/AddressResolver.js.map +0 -1
  8. package/lib/abis/src.ts/ChainlinkV3.d.ts +0 -87
  9. package/lib/abis/src.ts/ChainlinkV3.js +0 -117
  10. package/lib/abis/src.ts/ChainlinkV3.js.map +0 -1
  11. package/lib/abis/src.ts/ERC20.d.ts +0 -168
  12. package/lib/abis/src.ts/ERC20.js +0 -226
  13. package/lib/abis/src.ts/ERC20.js.map +0 -1
  14. package/lib/abis/src.ts/ERC20_Bytes32.d.ts +0 -135
  15. package/lib/abis/src.ts/ERC20_Bytes32.js +0 -192
  16. package/lib/abis/src.ts/ERC20_Bytes32.js.map +0 -1
  17. package/lib/abis/src.ts/ERC4626.d.ts +0 -363
  18. package/lib/abis/src.ts/ERC4626.js +0 -506
  19. package/lib/abis/src.ts/ERC4626.js.map +0 -1
  20. package/lib/abis/src.ts/ERC721.d.ts +0 -230
  21. package/lib/abis/src.ts/ERC721.js +0 -320
  22. package/lib/abis/src.ts/ERC721.js.map +0 -1
  23. package/lib/abis/src.ts/FeeOracle.d.ts +0 -120
  24. package/lib/abis/src.ts/FeeOracle.js +0 -161
  25. package/lib/abis/src.ts/FeeOracle.js.map +0 -1
  26. package/lib/abis/src.ts/LendingPool.d.ts +0 -1393
  27. package/lib/abis/src.ts/LendingPool.js +0 -1806
  28. package/lib/abis/src.ts/LendingPool.js.map +0 -1
  29. package/lib/abis/src.ts/LendingPoolV2.d.ts +0 -55
  30. package/lib/abis/src.ts/LendingPoolV2.js +0 -1832
  31. package/lib/abis/src.ts/LendingPoolV2.js.map +0 -1
  32. package/lib/abis/src.ts/LendingPoolV3.d.ts +0 -35
  33. package/lib/abis/src.ts/LendingPoolV3.js +0 -1160
  34. package/lib/abis/src.ts/LendingPoolV3.js.map +0 -1
  35. package/lib/abis/src.ts/Loan.d.ts +0 -837
  36. package/lib/abis/src.ts/Loan.js +0 -1080
  37. package/lib/abis/src.ts/Loan.js.map +0 -1
  38. package/lib/abis/src.ts/Multicall3.d.ts +0 -30
  39. package/lib/abis/src.ts/Multicall3.js +0 -94
  40. package/lib/abis/src.ts/Multicall3.js.map +0 -1
  41. package/lib/abis/src.ts/PoolAdapter.d.ts +0 -76
  42. package/lib/abis/src.ts/PoolAdapter.js +0 -412
  43. package/lib/abis/src.ts/PoolAdapter.js.map +0 -1
  44. package/lib/abis/src.ts/RewardDistributor.d.ts +0 -46
  45. package/lib/abis/src.ts/RewardDistributor.js +0 -352
  46. package/lib/abis/src.ts/RewardDistributor.js.map +0 -1
  47. package/lib/abis/src.ts/SmartAccount.d.ts +0 -16
  48. package/lib/abis/src.ts/SmartAccount.js +0 -16
  49. package/lib/abis/src.ts/SmartAccount.js.map +0 -1
  50. package/lib/abis/src.ts/TextResolver.d.ts +0 -16
  51. package/lib/abis/src.ts/TextResolver.js +0 -16
  52. package/lib/abis/src.ts/TextResolver.js.map +0 -1
  53. package/lib/abis/src.ts/UniversalResolverResolve.d.ts +0 -69
  54. package/lib/abis/src.ts/UniversalResolverResolve.js +0 -35
  55. package/lib/abis/src.ts/UniversalResolverResolve.js.map +0 -1
  56. package/lib/abis/src.ts/UniversalSignatureValidator.d.ts +0 -17
  57. package/lib/abis/src.ts/UniversalSignatureValidator.js +0 -27
  58. package/lib/abis/src.ts/UniversalSignatureValidator.js.map +0 -1
  59. package/lib/abis/src.ts/WrapperAdapter.d.ts +0 -60
  60. package/lib/abis/src.ts/WrapperAdapter.js +0 -150
  61. package/lib/abis/src.ts/WrapperAdapter.js.map +0 -1
  62. package/lib/abis/src.ts/index.d.ts +0 -19
  63. package/lib/abis/src.ts/index.js +0 -36
  64. package/lib/abis/src.ts/index.js.map +0 -1
  65. package/lib/pools/src.ts/admin-actions.d.ts +0 -0
  66. package/lib/pools/src.ts/admin-actions.js +0 -1
  67. package/lib/pools/src.ts/admin-actions.js.map +0 -1
  68. package/lib/pools/src.ts/getters-v2.d.ts +0 -0
  69. package/lib/pools/src.ts/getters-v2.js +0 -1
  70. package/lib/pools/src.ts/getters-v2.js.map +0 -1
  71. package/lib/pools/src.ts/getters.d.ts +0 -85
  72. package/lib/pools/src.ts/getters.js +0 -431
  73. package/lib/pools/src.ts/getters.js.map +0 -1
  74. package/lib/pools/src.ts/helpers.d.ts +0 -69
  75. package/lib/pools/src.ts/helpers.js +0 -634
  76. package/lib/pools/src.ts/helpers.js.map +0 -1
  77. package/lib/pools/src.ts/index.d.ts +0 -4
  78. package/lib/pools/src.ts/index.js +0 -21
  79. package/lib/pools/src.ts/index.js.map +0 -1
  80. package/lib/pools/src.ts/main.d.ts +0 -55
  81. package/lib/pools/src.ts/main.js +0 -270
  82. package/lib/pools/src.ts/main.js.map +0 -1
  83. package/lib/pools/src.ts/staking.d.ts +0 -8
  84. package/lib/pools/src.ts/staking.js +0 -116
  85. package/lib/pools/src.ts/staking.js.map +0 -1
  86. package/lib/pools/src.ts/user-actions.d.ts +0 -19
  87. package/lib/pools/src.ts/user-actions.js +0 -191
  88. package/lib/pools/src.ts/user-actions.js.map +0 -1
  89. package/lib/sdk/src.ts/index.js.map +0 -1
  90. package/lib/sdk/src.ts/main.js.map +0 -1
  91. package/lib/sdk/src.ts/verify.js.map +0 -1
  92. package/lib/services/src.ts/index.d.ts +0 -2
  93. package/lib/services/src.ts/index.js +0 -19
  94. package/lib/services/src.ts/index.js.map +0 -1
  95. package/lib/services/src.ts/slack.d.ts +0 -12
  96. package/lib/services/src.ts/slack.js +0 -57
  97. package/lib/services/src.ts/slack.js.map +0 -1
  98. package/lib/services/src.ts/subgraph.d.ts +0 -10
  99. package/lib/services/src.ts/subgraph.js +0 -460
  100. package/lib/services/src.ts/subgraph.js.map +0 -1
  101. package/lib/types/src.ts/index.d.ts +0 -8
  102. package/lib/types/src.ts/index.js +0 -24
  103. package/lib/types/src.ts/index.js.map +0 -1
  104. package/lib/types/src.ts/pools.d.ts +0 -141
  105. package/lib/types/src.ts/pools.js +0 -3
  106. package/lib/types/src.ts/pools.js.map +0 -1
  107. package/lib/types/src.ts/staking.d.ts +0 -28
  108. package/lib/types/src.ts/staking.js +0 -3
  109. package/lib/types/src.ts/staking.js.map +0 -1
  110. package/lib/types/src.ts/subgraph.d.ts +0 -45
  111. package/lib/types/src.ts/subgraph.js +0 -3
  112. package/lib/types/src.ts/subgraph.js.map +0 -1
  113. package/lib/types/src.ts/user.d.ts +0 -1
  114. package/lib/types/src.ts/user.js +0 -3
  115. package/lib/types/src.ts/user.js.map +0 -1
  116. package/lib/types/src.ts/vaults.d.ts +0 -159
  117. package/lib/types/src.ts/vaults.js +0 -3
  118. package/lib/types/src.ts/vaults.js.map +0 -1
  119. package/lib/types/src.ts/web3.d.ts +0 -19
  120. package/lib/types/src.ts/web3.js +0 -3
  121. package/lib/types/src.ts/web3.js.map +0 -1
  122. package/lib/types/src.ts/webserver.d.ts +0 -471
  123. package/lib/types/src.ts/webserver.js +0 -3
  124. package/lib/types/src.ts/webserver.js.map +0 -1
  125. package/lib/utils/src.ts/base-class.d.ts +0 -29
  126. package/lib/utils/src.ts/base-class.js +0 -48
  127. package/lib/utils/src.ts/base-class.js.map +0 -1
  128. package/lib/utils/src.ts/constants/august.d.ts +0 -57
  129. package/lib/utils/src.ts/constants/august.js +0 -61
  130. package/lib/utils/src.ts/constants/august.js.map +0 -1
  131. package/lib/utils/src.ts/constants/fallbacks.d.ts +0 -3
  132. package/lib/utils/src.ts/constants/fallbacks.js +0 -25
  133. package/lib/utils/src.ts/constants/fallbacks.js.map +0 -1
  134. package/lib/utils/src.ts/constants/index.d.ts +0 -3
  135. package/lib/utils/src.ts/constants/index.js +0 -20
  136. package/lib/utils/src.ts/constants/index.js.map +0 -1
  137. package/lib/utils/src.ts/constants/web3.d.ts +0 -25
  138. package/lib/utils/src.ts/constants/web3.js +0 -94
  139. package/lib/utils/src.ts/constants/web3.js.map +0 -1
  140. package/lib/utils/src.ts/fetcher.d.ts +0 -25
  141. package/lib/utils/src.ts/fetcher.js +0 -322
  142. package/lib/utils/src.ts/fetcher.js.map +0 -1
  143. package/lib/utils/src.ts/helpers/array.d.ts +0 -6
  144. package/lib/utils/src.ts/helpers/array.js +0 -35
  145. package/lib/utils/src.ts/helpers/array.js.map +0 -1
  146. package/lib/utils/src.ts/helpers/datetime.d.ts +0 -5
  147. package/lib/utils/src.ts/helpers/datetime.js +0 -32
  148. package/lib/utils/src.ts/helpers/datetime.js.map +0 -1
  149. package/lib/utils/src.ts/helpers/formatters.d.ts +0 -8
  150. package/lib/utils/src.ts/helpers/formatters.js +0 -114
  151. package/lib/utils/src.ts/helpers/formatters.js.map +0 -1
  152. package/lib/utils/src.ts/helpers/index.d.ts +0 -6
  153. package/lib/utils/src.ts/helpers/index.js +0 -23
  154. package/lib/utils/src.ts/helpers/index.js.map +0 -1
  155. package/lib/utils/src.ts/helpers/responses.d.ts +0 -32
  156. package/lib/utils/src.ts/helpers/responses.js +0 -238
  157. package/lib/utils/src.ts/helpers/responses.js.map +0 -1
  158. package/lib/utils/src.ts/helpers/verify-keys.d.ts +0 -2
  159. package/lib/utils/src.ts/helpers/verify-keys.js +0 -34
  160. package/lib/utils/src.ts/helpers/verify-keys.js.map +0 -1
  161. package/lib/utils/src.ts/helpers/web3.d.ts +0 -27
  162. package/lib/utils/src.ts/helpers/web3.js +0 -351
  163. package/lib/utils/src.ts/helpers/web3.js.map +0 -1
  164. package/lib/utils/src.ts/index.d.ts +0 -5
  165. package/lib/utils/src.ts/index.js +0 -22
  166. package/lib/utils/src.ts/index.js.map +0 -1
  167. package/lib/utils/src.ts/vaults.d.ts +0 -53
  168. package/lib/utils/src.ts/vaults.js +0 -167
  169. package/lib/utils/src.ts/vaults.js.map +0 -1
  170. package/lib/vaults/src.ts/admin-actions.d.ts +0 -0
  171. package/lib/vaults/src.ts/admin-actions.js +0 -1
  172. package/lib/vaults/src.ts/admin-actions.js.map +0 -1
  173. package/lib/vaults/src.ts/getters.d.ts +0 -36
  174. package/lib/vaults/src.ts/getters.js +0 -649
  175. package/lib/vaults/src.ts/getters.js.map +0 -1
  176. package/lib/vaults/src.ts/index.d.ts +0 -4
  177. package/lib/vaults/src.ts/index.js +0 -21
  178. package/lib/vaults/src.ts/index.js.map +0 -1
  179. package/lib/vaults/src.ts/main.d.ts +0 -88
  180. package/lib/vaults/src.ts/main.js +0 -497
  181. package/lib/vaults/src.ts/main.js.map +0 -1
  182. package/lib/vaults/src.ts/rpc-config.d.ts +0 -4
  183. package/lib/vaults/src.ts/rpc-config.js +0 -32
  184. package/lib/vaults/src.ts/rpc-config.js.map +0 -1
  185. package/lib/vaults/src.ts/user-actions.d.ts +0 -19
  186. package/lib/vaults/src.ts/user-actions.js +0 -191
  187. package/lib/vaults/src.ts/user-actions.js.map +0 -1
  188. package/lib/vaults/src.ts/utils.d.ts +0 -120
  189. package/lib/vaults/src.ts/utils.js +0 -438
  190. package/lib/vaults/src.ts/utils.js.map +0 -1
  191. package/lib/vaults/src.ts/vault-fetching-examples.d.ts +0 -4
  192. package/lib/vaults/src.ts/vault-fetching-examples.js +0 -40
  193. package/lib/vaults/src.ts/vault-fetching-examples.js.map +0 -1
  194. /package/lib/{sdk/src.ts/index.d.ts → index.d.ts} +0 -0
  195. /package/lib/{sdk/src.ts/index.js → index.js} +0 -0
  196. /package/lib/{sdk/src.ts/main.d.ts → main.d.ts} +0 -0
  197. /package/lib/{sdk/src.ts/main.js → main.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,649 +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.getVault = getVault;
13
- exports.getVaultLoans = getVaultLoans;
14
- exports.getVaultAllocations = getVaultAllocations;
15
- exports.getVaultAvailableRedemptions = getVaultAvailableRedemptions;
16
- exports.getVaultRedemptionHistory = getVaultRedemptionHistory;
17
- exports.getVaultPositions = getVaultPositions;
18
- exports.getVaultApy = getVaultApy;
19
- exports.getRewardsStakingPositions = getRewardsStakingPositions;
20
- const abis_1 = require("@augustdigital/abis");
21
- const utils_1 = require("@augustdigital/utils");
22
- const ethers_1 = require("ethers");
23
- const services_1 = require("@augustdigital/services");
24
- const utils_2 = require("./utils");
25
- function getVault(_a) {
26
- return __awaiter(this, arguments, void 0, function* ({ vault, loans = false, allocations = false, options, }) {
27
- var _b;
28
- const provider = (0, utils_1.createProvider)(options.rpcUrl);
29
- let returnedVault;
30
- try {
31
- if ((0, ethers_1.isAddress)(vault)) {
32
- const tokenizedVault = (_b = (yield (0, utils_1.fetchTokenizedVaults)(vault))) === null || _b === void 0 ? void 0 : _b[0];
33
- if (tokenizedVault.status === 'closed' &&
34
- tokenizedVault.is_visible === false) {
35
- console.log('#getVault::closed:', tokenizedVault.vault_name);
36
- return null;
37
- }
38
- const vaultContract = (0, utils_1.createContract)({
39
- address: vault,
40
- abi: abis_1.ABI_LENDING_POOL_V2,
41
- provider,
42
- });
43
- const vaultContractCalls = yield Promise.all(utils_2.POOL_FUNCTIONS.map((f) => {
44
- if (f === 'symbol') {
45
- return (0, utils_1.getSymbol)(provider, vault);
46
- }
47
- if (f === 'decimals') {
48
- return (0, utils_1.getDecimals)(provider, vault);
49
- }
50
- return vaultContract[f]();
51
- }));
52
- const formattedContractCalls = vaultContractCalls.reduce((acc, curr, i) => {
53
- let val;
54
- if (utils_2.POOL_FUNCTIONS[i] === 'totalSupply' ||
55
- utils_2.POOL_FUNCTIONS[i] === 'totalAssets' ||
56
- utils_2.POOL_FUNCTIONS[i] === 'globalLoansAmount' ||
57
- utils_2.POOL_FUNCTIONS[i] === 'maxSupply') {
58
- val = (0, utils_1.toNormalizedBn)(curr, vaultContractCalls[0]);
59
- }
60
- else if (utils_2.POOL_FUNCTIONS[i] === 'getTotalLoansDeployed') {
61
- val = (0, utils_1.toNormalizedBn)(curr, 0);
62
- }
63
- else if (utils_2.POOL_FUNCTIONS[i] === 'withdrawalFee') {
64
- val = (0, utils_1.toNormalizedBn)(curr, 2);
65
- }
66
- else if (utils_2.POOL_FUNCTIONS[i] === 'decimals') {
67
- val = Number(curr.toString());
68
- }
69
- else if (utils_2.POOL_FUNCTIONS[i] === 'loansOperator') {
70
- val = '0x4DCb388488622e47683EAd1a147947140a31e485';
71
- }
72
- else {
73
- val = curr;
74
- }
75
- return Object.assign(Object.assign({}, acc), { [utils_2.POOL_FUNCTIONS[i]]: val });
76
- }, {});
77
- const returnObj = yield (0, utils_2.buildFormattedVault)(provider, tokenizedVault, formattedContractCalls);
78
- returnedVault = returnObj;
79
- }
80
- }
81
- catch (err) {
82
- console.error(`#getVault::${vault}:`, err);
83
- throw new Error(`#getVault::${vault}:${err === null || err === void 0 ? void 0 : err.message}`);
84
- }
85
- if (!(0, utils_1.isBadVault)(vault)) {
86
- if (loans) {
87
- try {
88
- returnedVault = Object.assign(Object.assign({}, returnedVault), { loans: yield getVaultLoans(returnedVault, options) });
89
- }
90
- catch (e) {
91
- console.error(`getVault::${returnedVault.symbol}:`, e === null || e === void 0 ? void 0 : e.message);
92
- }
93
- }
94
- if (allocations) {
95
- try {
96
- const vaultAllocations = yield getVaultAllocations(vault, options);
97
- returnedVault = Object.assign(Object.assign({}, returnedVault), { allocations: vaultAllocations });
98
- }
99
- catch (e) {
100
- console.error(`getVault::${returnedVault.symbol}:`, e === null || e === void 0 ? void 0 : e.message);
101
- throw new Error('Failure fetching debank res');
102
- }
103
- }
104
- }
105
- return returnedVault;
106
- });
107
- }
108
- function getVaultLoans(vault, options) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- var _a, _b;
111
- const vaultAddress = typeof vault === 'string' ? vault : vault.address;
112
- const isOldLendingPool = utils_1.OLD_LENDING_POOLS.includes(vaultAddress);
113
- if (!isOldLendingPool)
114
- return [];
115
- try {
116
- let poolTotalSupply;
117
- let poolDecimals;
118
- const tokenizedVault = (_a = (yield (0, utils_1.fetchTokenizedVaults)(vaultAddress))) === null || _a === void 0 ? void 0 : _a[0];
119
- const chainId = (options === null || options === void 0 ? void 0 : options.chainId) || (tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.chain);
120
- const provider = (0, utils_1.createProvider)(options.rpcUrl);
121
- const tokenizedVaultLoans = yield (0, utils_1.fetchTokenizedVaultLoans)(vaultAddress, chainId);
122
- if (typeof vault === 'string') {
123
- const poolContract = (0, utils_1.createContract)({
124
- provider,
125
- address: vaultAddress,
126
- abi: abis_1.ABI_LENDING_POOL_V2,
127
- });
128
- [poolTotalSupply, poolDecimals] = yield Promise.all([
129
- poolContract.totalSupply(),
130
- (0, utils_1.getDecimals)(provider, vaultAddress),
131
- ]);
132
- poolTotalSupply = BigInt(poolTotalSupply).toString();
133
- poolDecimals = Number(poolDecimals);
134
- }
135
- else {
136
- poolTotalSupply = vault.totalSupply.raw;
137
- poolDecimals = vault.decimals;
138
- }
139
- const newLoans = (yield Promise.all((_b = (Array.isArray(tokenizedVaultLoans) ? tokenizedVaultLoans : [])) === null || _b === void 0 ? void 0 : _b.map((l) => __awaiter(this, void 0, void 0, function* () {
140
- const borrower = l.borrower;
141
- const allocation = l.principal_amount /
142
- Number((0, ethers_1.formatUnits)(poolTotalSupply, poolDecimals));
143
- const loanFeeRate = yield (0, utils_1.getLoanOracleFeeRate)(provider, 'LOAN.REPAY.INTERESTS', l.address, chainId);
144
- const loanApr = Number(l.apr || 0) / 100;
145
- const loanAprAfterFees = loanApr * (1 - loanFeeRate / 100);
146
- const isIdleCapital = utils_1.IDLE_CAPITAL_BORROWER_ADDRESS.includes(borrower);
147
- const newLoanObj = {
148
- vault: vaultAddress,
149
- address: l.address,
150
- lender: l.lender,
151
- borrower: l.borrower,
152
- state: l.state,
153
- totalRepaid: l.total_repaid,
154
- principalToken: l.principal_token,
155
- principalAmount: l.principal_amount,
156
- interestAmount: l.interest_amount,
157
- upcomingPayment: {
158
- amount: l.upcoming_payment.amount,
159
- dueDate: l.upcoming_payment.due_date,
160
- },
161
- apr: loanAprAfterFees,
162
- initialPrincipalAmount: l.initial_principal_amount,
163
- deployedDate: l.deployed_date,
164
- isIdleCapital,
165
- paymentInterval: l.payment_interval,
166
- allocation,
167
- };
168
- return newLoanObj;
169
- })))).filter((l) => l !== undefined);
170
- return newLoans;
171
- }
172
- catch (e) {
173
- console.error('#getVaultLoans:', e);
174
- throw new Error(`#getVaultLoans::${vault}:${e === null || e === void 0 ? void 0 : e.message}`);
175
- }
176
- });
177
- }
178
- function getVaultAllocations(vault, options) {
179
- return __awaiter(this, void 0, void 0, function* () {
180
- var _a;
181
- let protocolExposure = [];
182
- let tokenExposure = [];
183
- let cefiExposure = [];
184
- let cefiBorrowerResponses = {};
185
- let otcPositions = {};
186
- let defiPerBorrower = {};
187
- let exposurePerCategory = {
188
- supplying: [],
189
- borrowing: [],
190
- wallet: [],
191
- walletBalance: 0,
192
- cefiBalance: 0,
193
- defiBalance: 0,
194
- lending: [],
195
- loanBalance: 0,
196
- };
197
- let netValue = { value: 0 };
198
- let debankErr = false;
199
- let uniqueBorrowers;
200
- const isOldLendingPool = utils_1.OLD_LENDING_POOLS.includes(vault);
201
- const tokenizedVault = (_a = (yield (0, utils_1.fetchTokenizedVaults)(vault))) === null || _a === void 0 ? void 0 : _a[0];
202
- try {
203
- if (isOldLendingPool) {
204
- const loans = yield getVaultLoans(vault, options);
205
- uniqueBorrowers = [...new Set(loans.map((l) => l.borrower))];
206
- }
207
- else {
208
- uniqueBorrowers = tokenizedVault.subaccounts.map((s) => s.address);
209
- }
210
- }
211
- catch (e) {
212
- console.error('#getVaultAllocations::borrowers:', e);
213
- }
214
- if (vault.toLowerCase() === utils_2.VAULT_AgoraAUSD.toLowerCase()) {
215
- const debankRes = yield (0, utils_1.fetchDebankResponse)(utils_2.SUBACCOUNT_CALEB);
216
- console.log('debankRes:', debankRes);
217
- if (debankRes === false) {
218
- debankErr = true;
219
- }
220
- (0, utils_1.parseVaultLevelDebank)(debankRes, protocolExposure, tokenExposure, utils_2.SUBACCOUNT_CALEB, exposurePerCategory, netValue);
221
- const debankPerLoan = (0, utils_1.parseLoanLevelDebank)(debankRes);
222
- defiPerBorrower[utils_2.SUBACCOUNT_CALEB] = debankPerLoan;
223
- }
224
- else {
225
- for (const borrower of uniqueBorrowers) {
226
- try {
227
- const debankRes = yield (0, utils_1.fetchDebankResponse)(borrower);
228
- if (debankRes === false) {
229
- debankErr = true;
230
- }
231
- (0, utils_1.parseVaultLevelDebank)(debankRes, protocolExposure, tokenExposure, borrower, exposurePerCategory, netValue);
232
- const debankPerLoan = (0, utils_1.parseLoanLevelDebank)(debankRes);
233
- defiPerBorrower[borrower] = debankPerLoan;
234
- }
235
- catch (e) {
236
- console.error('#getVaultAllocations::debank:', e);
237
- }
238
- try {
239
- const cefiResponse = yield (0, utils_1.fetchAugustWithKey)(options.augustKey, utils_1.WEBSERVER_ENDPOINTS.subaccount.cefi(borrower));
240
- if (cefiResponse.status !== 200) {
241
- console.error('#getVaultAllocations::cefi:', cefiResponse.status, cefiResponse.statusText);
242
- }
243
- if (cefiResponse.status === 200) {
244
- const cefiRes = (yield cefiResponse.json());
245
- cefiBorrowerResponses[borrower] = cefiRes;
246
- cefiExposure = cefiRes;
247
- }
248
- }
249
- catch (e) {
250
- console.error('#getVaultAllocations::cefi:', e);
251
- }
252
- try {
253
- const otcResponse = yield (0, utils_1.fetchAugustWithKey)(options.augustKey, utils_1.WEBSERVER_ENDPOINTS.subaccount.otc_positions(borrower));
254
- if (otcResponse.status !== 200) {
255
- console.error('#getVaultAllocations::otc:', otcResponse.status, otcResponse.statusText);
256
- }
257
- if (otcResponse.status === 200) {
258
- const otcRes = (yield otcResponse.json());
259
- otcPositions[borrower] = otcRes;
260
- }
261
- }
262
- catch (e) {
263
- console.error('#getVaultAllocations::otc:', e);
264
- }
265
- }
266
- }
267
- const walletBalance = exposurePerCategory.wallet.reduce((sum, item) => sum + item.amount, 0);
268
- const defiBalance = protocolExposure.reduce((sum, item) => sum + item.netUsdValue, 0);
269
- const cefiBalance = cefiExposure.reduce((sum, item) => sum + item.value, 0);
270
- exposurePerCategory.walletBalance = walletBalance;
271
- exposurePerCategory.defiBalance = defiBalance;
272
- exposurePerCategory.cefiBalance = cefiBalance;
273
- netValue.value += cefiBalance;
274
- if (debankErr) {
275
- throw Error('failure to fetch debank response');
276
- }
277
- if (vault === '0x828BC5895b78b2fb591018Ca5bDC2064742D6D0f') {
278
- console.log('protocolExposure:', {
279
- defi: protocolExposure,
280
- cefi: cefiExposure,
281
- otc: otcPositions,
282
- tokens: tokenExposure,
283
- defiPerBorrower,
284
- exposurePerCategory,
285
- netValue: netValue.value,
286
- });
287
- }
288
- return {
289
- defi: protocolExposure,
290
- cefi: cefiExposure,
291
- otc: otcPositions,
292
- tokens: tokenExposure,
293
- defiPerBorrower,
294
- exposurePerCategory,
295
- netValue: netValue.value,
296
- };
297
- });
298
- }
299
- function getVaultAvailableRedemptions(_a) {
300
- return __awaiter(this, arguments, void 0, function* ({ vault, wallet, options, }) {
301
- var _b, _c, _d;
302
- try {
303
- const provider = (0, utils_1.createProvider)(options.rpcUrl);
304
- const tokenizedVault = (_b = (yield (0, utils_1.fetchTokenizedVaults)(vault))) === null || _b === void 0 ? void 0 : _b[0];
305
- if (!tokenizedVault) {
306
- return { availableRedemptions: [], pendingRedemptions: [] };
307
- }
308
- const poolContract = (0, utils_1.createContract)({
309
- address: vault,
310
- abi: abis_1.ABI_LENDING_POOL_V2,
311
- provider,
312
- });
313
- const { withdrawalRequesteds, withdrawalProcesseds } = yield (0, services_1.getSubgraphAllWithdrawals)(vault, provider);
314
- const decimals = yield (0, utils_1.getDecimals)(provider, vault);
315
- const availableRedemptions = [];
316
- const pendingRedemptions = [];
317
- for (const ev of withdrawalRequesteds) {
318
- if (!ev || typeof ev !== 'object') {
319
- console.warn('#getVaultAvailableRedemptions: Skipping invalid event:', ev);
320
- continue;
321
- }
322
- if (!ev.year || !ev.month || !ev.day || !ev.receiverAddr) {
323
- console.warn('#getVaultAvailableRedemptions: Skipping event with missing required properties:', ev);
324
- continue;
325
- }
326
- const fullDate = new Date(Number(ev.year), Number(ev.month) - 1, Number(ev.day));
327
- const foundRedemptionAgainstClaim = withdrawalProcesseds.find((h) => new Date(h.processedOn).toDateString() === fullDate.toDateString() &&
328
- h.receiverAddr === ev.receiverAddr);
329
- if (wallet) {
330
- if (((_c = ev === null || ev === void 0 ? void 0 : ev.receiverAddr) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === wallet.toLowerCase()) {
331
- const alreadyRedeemed = availableRedemptions.find((red) => BigInt(red.day.raw) === BigInt(ev.day) &&
332
- BigInt(red.month.raw) === BigInt(ev.month) &&
333
- BigInt(red.year.raw) === BigInt(ev.year));
334
- if (!(foundRedemptionAgainstClaim && alreadyRedeemed)) {
335
- try {
336
- const trueClaimableAmount = yield ((_d = poolContract === null || poolContract === void 0 ? void 0 : poolContract.getClaimableAmountByReceiver) === null || _d === void 0 ? void 0 : _d.call(poolContract, BigInt(ev.year), BigInt(ev.month), BigInt(ev.day), (0, ethers_1.getAddress)(wallet)));
337
- if (trueClaimableAmount > BigInt(0)) {
338
- availableRedemptions.push({
339
- id: ev.transactionHash_ || ev.id,
340
- hash: ev.transactionHash_ || ev.id,
341
- timestamp: Number(ev.timestamp_),
342
- receiver: ev.receiverAddr,
343
- day: (0, utils_1.toNormalizedBn)(ev.day, 0),
344
- month: (0, utils_1.toNormalizedBn)(ev.month, 0),
345
- year: (0, utils_1.toNormalizedBn)(ev.year, 0),
346
- amount: (0, utils_1.toNormalizedBn)(trueClaimableAmount, decimals),
347
- date: fullDate,
348
- vault,
349
- });
350
- }
351
- pendingRedemptions.push({
352
- id: ev.transactionHash_ || ev.id,
353
- hash: ev.transactionHash_ || ev.id,
354
- timestamp: Number(ev.timestamp_),
355
- receiver: ev.receiverAddr,
356
- day: (0, utils_1.toNormalizedBn)(ev.day, 0),
357
- month: (0, utils_1.toNormalizedBn)(ev.month, 0),
358
- year: (0, utils_1.toNormalizedBn)(ev.year, 0),
359
- amount: (0, utils_1.toNormalizedBn)(trueClaimableAmount || BigInt(0), decimals),
360
- date: fullDate,
361
- vault,
362
- });
363
- }
364
- catch (contractError) {
365
- console.error('#getVaultAvailableRedemptions: Contract call failed:', contractError);
366
- pendingRedemptions.push({
367
- id: ev.transactionHash_ || ev.id,
368
- hash: ev.transactionHash_ || ev.id,
369
- timestamp: Number(ev.timestamp_),
370
- receiver: ev.receiverAddr,
371
- day: (0, utils_1.toNormalizedBn)(ev.day, 0),
372
- month: (0, utils_1.toNormalizedBn)(ev.month, 0),
373
- year: (0, utils_1.toNormalizedBn)(ev.year, 0),
374
- amount: (0, utils_1.toNormalizedBn)(BigInt(0), decimals),
375
- date: fullDate,
376
- vault,
377
- });
378
- }
379
- }
380
- }
381
- }
382
- else {
383
- if (!!foundRedemptionAgainstClaim) {
384
- availableRedemptions.push({
385
- id: ev.transactionHash_ || ev.id,
386
- hash: ev.transactionHash_ || ev.id,
387
- timestamp: Number(ev.timestamp_),
388
- receiver: ev.receiverAddr,
389
- day: (0, utils_1.toNormalizedBn)(ev.day, 0),
390
- month: (0, utils_1.toNormalizedBn)(ev.month, 0),
391
- year: (0, utils_1.toNormalizedBn)(ev.year, 0),
392
- amount: (0, utils_1.toNormalizedBn)(ev.assets || BigInt(0), decimals),
393
- date: fullDate,
394
- vault,
395
- });
396
- }
397
- }
398
- }
399
- if (options.env === 'DEV')
400
- console.log('#getVaultAvailableRedemptions:', availableRedemptions.slice(0, 1));
401
- return { availableRedemptions, pendingRedemptions };
402
- }
403
- catch (e) {
404
- console.error('#getVaultAvailableRedemptions:', e);
405
- return { availableRedemptions: [], pendingRedemptions: [] };
406
- }
407
- });
408
- }
409
- function getVaultRedemptionHistory(_a) {
410
- return __awaiter(this, arguments, void 0, function* ({ vault, wallet, options, }) {
411
- var _b;
412
- try {
413
- const provider = (0, utils_1.createProvider)(options.rpcUrl);
414
- const tokenizedVault = (_b = (yield (0, utils_1.fetchTokenizedVaults)(vault))) === null || _b === void 0 ? void 0 : _b[0];
415
- if (!tokenizedVault) {
416
- return [];
417
- }
418
- const chainId = tokenizedVault.chain;
419
- const poolContract = (0, utils_1.createContract)({
420
- address: vault,
421
- abi: abis_1.ABI_LENDING_POOL_V2,
422
- provider,
423
- });
424
- let logPromises = [];
425
- const currentBlock = yield provider.getBlockNumber();
426
- let startingBlock = currentBlock - (0, utils_2.determineBlockSkipInternal)(chainId);
427
- let endBlock = currentBlock;
428
- const cutoffBlock = currentBlock - (0, utils_2.determineBlockCutoff)(chainId);
429
- while (endBlock >= cutoffBlock) {
430
- const logBloomsPromises = poolContract.queryFilter('WithdrawalProcessed', BigInt(startingBlock), BigInt(endBlock));
431
- logPromises.push(logBloomsPromises);
432
- startingBlock -= (0, utils_2.determineBlockSkipInternal)(chainId);
433
- endBlock -= (0, utils_2.determineBlockSkipInternal)(chainId);
434
- }
435
- const logs = (yield Promise.all(logPromises.flat())).flat();
436
- const iface = new ethers_1.ethers.Interface([
437
- 'event WithdrawalProcessed (uint256 assetsAmount, uint256 processedOn, address receiverAddr, uint256 requestedOn)',
438
- ]);
439
- const events = logs.map((log) => iface.parseLog(log));
440
- const decimals = yield (0, utils_1.getDecimals)(provider, vault);
441
- const redemptions = [];
442
- events === null || events === void 0 ? void 0 : events.forEach((ev) => {
443
- var _a;
444
- if (!(ev === null || ev === void 0 ? void 0 : ev.args))
445
- return;
446
- const [assetsAmount, processedOn, receiverAddr, requestedOn] = ev.args;
447
- if (wallet) {
448
- if (((_a = String(receiverAddr)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === wallet.toLowerCase()) {
449
- redemptions.push({
450
- receiver: receiverAddr,
451
- amount: (0, utils_1.toNormalizedBn)(assetsAmount, decimals),
452
- processed: new Date(Number(processedOn) * 1000),
453
- requested: new Date(Number(requestedOn) * 1000),
454
- vault,
455
- });
456
- }
457
- }
458
- else {
459
- redemptions.push({
460
- receiver: receiverAddr,
461
- amount: (0, utils_1.toNormalizedBn)(assetsAmount, decimals),
462
- processed: new Date(Number(processedOn) * 1000),
463
- requested: new Date(Number(requestedOn) * 1000),
464
- vault,
465
- });
466
- }
467
- });
468
- if (options.env === 'DEV')
469
- console.log('#getVaultRedemptionHistory:', redemptions.slice(0, 1));
470
- return redemptions;
471
- }
472
- catch (e) {
473
- console.error('#getVaultRedemptionHistory:', e);
474
- return [];
475
- }
476
- });
477
- }
478
- function getVaultPositions(_a) {
479
- return __awaiter(this, arguments, void 0, function* ({ vault, wallet, options, }) {
480
- try {
481
- const tokenizedVaults = yield (0, utils_1.fetchTokenizedVaults)(vault ? vault : undefined);
482
- if (!tokenizedVaults || tokenizedVaults.length === 0) {
483
- return [];
484
- }
485
- const promises = yield Promise.all(tokenizedVaults.map((v) => __awaiter(this, void 0, void 0, function* () {
486
- try {
487
- const provider = (0, utils_1.createProvider)(options.rpcUrl);
488
- const decimals = yield (0, utils_1.getDecimals)(provider, vault);
489
- const poolContract = (0, utils_1.createContract)({
490
- provider,
491
- abi: abis_1.ABI_LENDING_POOL_V2,
492
- address: v.address,
493
- });
494
- const bal = yield poolContract.balanceOf(wallet);
495
- const balance = (0, utils_1.toNormalizedBn)(bal || 0, decimals);
496
- const { availableRedemptions, pendingRedemptions } = yield getVaultAvailableRedemptions({
497
- vault: v.address,
498
- wallet,
499
- options,
500
- });
501
- function renderStatus() {
502
- if (availableRedemptions === null || availableRedemptions === void 0 ? void 0 : availableRedemptions.length)
503
- return 'REDEEM';
504
- if (BigInt(balance.raw) > BigInt(0))
505
- return 'STAKED';
506
- return 'PENDING';
507
- }
508
- const aggregateAvailableRedemptions = availableRedemptions === null || availableRedemptions === void 0 ? void 0 : availableRedemptions.reduce((acc, curr) => acc + BigInt(curr.amount.raw), BigInt(0));
509
- return {
510
- vault,
511
- status: renderStatus(),
512
- availableRedemptions,
513
- pendingRedemptions,
514
- redeemable: (0, utils_1.toNormalizedBn)(aggregateAvailableRedemptions, decimals),
515
- walletBalance: balance,
516
- };
517
- }
518
- catch (vaultError) {
519
- console.error(`#getVaultPositions: Error processing vault ${v.address}:`, vaultError);
520
- return {
521
- vault,
522
- status: 'PENDING',
523
- availableRedemptions: [],
524
- pendingRedemptions: [],
525
- redeemable: (0, utils_1.toNormalizedBn)(BigInt(0), 18),
526
- walletBalance: (0, utils_1.toNormalizedBn)(BigInt(0), 18),
527
- };
528
- }
529
- })));
530
- return promises.flat();
531
- }
532
- catch (e) {
533
- console.error('#getVaultPositions:', e);
534
- throw new Error(`#getVaultPositions::${vault}:${e === null || e === void 0 ? void 0 : e.message}`);
535
- }
536
- });
537
- }
538
- function getVaultApy(_a) {
539
- return __awaiter(this, arguments, void 0, function* ({ vault }) {
540
- var _b, _c;
541
- try {
542
- const tokenizedVault = (_b = (yield (0, utils_1.fetchTokenizedVaults)(vault))) === null || _b === void 0 ? void 0 : _b[0];
543
- return ((_c = tokenizedVault === null || tokenizedVault === void 0 ? void 0 : tokenizedVault.reported_apy) === null || _c === void 0 ? void 0 : _c.apy) || 0;
544
- }
545
- catch (e) {
546
- console.error('#getVaultApy:', e);
547
- throw new Error(`#getVaultApy::${vault}:${e === null || e === void 0 ? void 0 : e.message}`);
548
- }
549
- });
550
- }
551
- function getRewardsStakingPositions(_a) {
552
- return __awaiter(this, arguments, void 0, function* ({ rpcUrl, wallet, coinGeckoKey, }) {
553
- const REWARDS_CHAIN = 43114;
554
- const REWARDS_SYMBOL = 'AVAX';
555
- const REWARDS_DECIMALS = 18;
556
- const REWARDS_NAME = 'Avalanche';
557
- const APR_MULTIPLIER = 31536000;
558
- const UP_AUSD_SYMBOL = 'upAUSD';
559
- try {
560
- const provider = (0, utils_1.createProvider)(rpcUrl);
561
- const chainId = yield (0, utils_1.getChainId)(provider);
562
- if (chainId !== REWARDS_CHAIN) {
563
- console.warn('#getStakingPositions: no rewards distributor on chain_id', chainId);
564
- return [];
565
- }
566
- if (wallet && !(0, ethers_1.isAddress)(wallet)) {
567
- console.warn('#getStakingPositions: wallet passed is not a valid address', wallet);
568
- return [];
569
- }
570
- const rewardDistributorAddresses = (0, utils_1.REWARD_DISTRIBUTOR_ADDRESS)(chainId);
571
- const positions = yield Promise.all(rewardDistributorAddresses.map((contract, i) => __awaiter(this, void 0, void 0, function* () {
572
- const rewardContract = (0, utils_1.createContract)({
573
- address: contract,
574
- provider: provider,
575
- abi: abis_1.ABI_REWARD_DISTRIBUTOR,
576
- });
577
- const totalStaked = yield rewardContract.totalStaked();
578
- const rewardsPerSecond = yield rewardContract.rewardsPerSecond();
579
- const stakingTokenCalls = ['decimals', 'symbol', 'name', 'totalSupply'];
580
- const stakingTokenAddress = (yield rewardContract.stakingToken());
581
- const stakingTokenContract = (0, utils_1.createContract)({
582
- address: stakingTokenAddress,
583
- provider: provider,
584
- abi: abis_1.ABI_ERC20,
585
- });
586
- const [decimals, symbol, name, totalSupply] = yield Promise.all(stakingTokenCalls.map((staking) => stakingTokenContract[staking]()));
587
- let balance;
588
- let earned;
589
- if (wallet) {
590
- const formattedWallet = (0, ethers_1.getAddress)(wallet);
591
- balance = yield rewardContract.balanceOf(formattedWallet);
592
- earned = yield rewardContract.earned(formattedWallet);
593
- }
594
- const rewardTokenPriceInUsd = yield (0, utils_1.fetchTokenPrice)(REWARDS_SYMBOL, null, coinGeckoKey);
595
- const normalizedRewardTokenPrice = (0, utils_1.toNormalizedBn)(rewardTokenPriceInUsd);
596
- const normalizedTotalStakedInPool = (0, utils_1.toNormalizedBn)(totalStaked, decimals);
597
- const normalizedRedeemable = (0, utils_1.toNormalizedBn)(earned, REWARDS_DECIMALS);
598
- const normalizedRewardsPerSecond = (0, utils_1.toNormalizedBn)(rewardsPerSecond, REWARDS_DECIMALS);
599
- const normalizedTotalStakedBalance = (0, utils_1.toNormalizedBn)(balance, decimals);
600
- const rewardTokenPriceToMultiply = symbol === UP_AUSD_SYMBOL
601
- ? Number(normalizedRewardTokenPrice === null || normalizedRewardTokenPrice === void 0 ? void 0 : normalizedRewardTokenPrice.normalized)
602
- : 1;
603
- const STAKED_APR = ((Number(normalizedRewardsPerSecond === null || normalizedRewardsPerSecond === void 0 ? void 0 : normalizedRewardsPerSecond.normalized) *
604
- APR_MULTIPLIER *
605
- rewardTokenPriceToMultiply) /
606
- (Number(normalizedTotalStakedInPool === null || normalizedTotalStakedInPool === void 0 ? void 0 : normalizedTotalStakedInPool.normalized) * Number(1))) *
607
- 100;
608
- const MAX_APR = ((Number(normalizedRewardsPerSecond === null || normalizedRewardsPerSecond === void 0 ? void 0 : normalizedRewardsPerSecond.normalized) *
609
- APR_MULTIPLIER *
610
- rewardTokenPriceToMultiply) /
611
- (Number(normalizedTotalStakedInPool === null || normalizedTotalStakedInPool === void 0 ? void 0 : normalizedTotalStakedInPool.normalized) * Number(1))) *
612
- 100;
613
- const activePosition = {
614
- id: String(i),
615
- rewardToken: {
616
- decimals: REWARDS_DECIMALS,
617
- symbol: REWARDS_SYMBOL,
618
- address: ethers_1.ZeroAddress,
619
- chain: REWARDS_CHAIN,
620
- redeemable: normalizedRedeemable,
621
- usd: normalizedRewardTokenPrice,
622
- name: REWARDS_NAME,
623
- },
624
- stakingToken: {
625
- decimals: Number(decimals),
626
- symbol: symbol,
627
- address: stakingTokenAddress,
628
- chain: REWARDS_CHAIN,
629
- totalStaked: normalizedTotalStakedBalance,
630
- usd: normalizedRewardTokenPrice,
631
- totalSupply: normalizedTotalStakedInPool,
632
- name: name,
633
- },
634
- rewardDistributor: contract,
635
- rewardPerSecond: (0, utils_1.toNormalizedBn)(rewardsPerSecond),
636
- apy: STAKED_APR,
637
- maxApy: MAX_APR,
638
- chainId: REWARDS_CHAIN,
639
- };
640
- return activePosition;
641
- })));
642
- return positions;
643
- }
644
- catch (e) {
645
- console.error('#getStakingPositions:', e);
646
- }
647
- });
648
- }
649
- //# sourceMappingURL=getters.js.map