@alphafi/alphafi-sdk 0.0.58 → 0.0.59

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 (220) hide show
  1. package/dist/cjs/common/constants.d.ts.map +1 -1
  2. package/dist/cjs/common/constants.js +2 -1
  3. package/dist/cjs/common/constants.js.map +1 -1
  4. package/dist/cjs/getAprs.d.ts +2 -0
  5. package/dist/cjs/getAprs.d.ts.map +1 -1
  6. package/dist/cjs/getAprs.js +251 -1
  7. package/dist/cjs/getAprs.js.map +1 -1
  8. package/dist/esm/common/constants.d.ts.map +1 -1
  9. package/dist/esm/common/constants.js +2 -1
  10. package/dist/esm/common/constants.js.map +1 -1
  11. package/dist/esm/getAprs.d.ts +2 -0
  12. package/dist/esm/getAprs.d.ts.map +1 -1
  13. package/dist/esm/getAprs.js +249 -2
  14. package/dist/esm/getAprs.js.map +1 -1
  15. package/docs/assets/highlight.css +51 -74
  16. package/docs/assets/icons.js +17 -20
  17. package/docs/assets/main.js +5 -2163
  18. package/docs/assets/navigation.js +1 -2
  19. package/docs/assets/search.js +1 -2
  20. package/docs/assets/style.css +850 -846
  21. package/docs/functions/alphaLpBreakdown.html +1 -253
  22. package/docs/functions/cetusLpBreakdown.html +1 -253
  23. package/docs/functions/claimBlueRewardTxb.html +1 -258
  24. package/docs/functions/claimRewardTxb.html +1 -243
  25. package/docs/functions/coinAmountToXTokensDoubleAsset.html +1 -267
  26. package/docs/functions/coinAmountToXTokensSingleAsset.html +1 -260
  27. package/docs/functions/coinsInPool.html +1 -438
  28. package/docs/functions/collectRewards.html +1 -242
  29. package/docs/functions/deposit.html +1 -246
  30. package/docs/functions/depositDoubleAssetTxb.html +1 -270
  31. package/docs/functions/depositSingleAssetTxb.html +1 -263
  32. package/docs/functions/fetchAfterTransactionEvents.html +1 -328
  33. package/docs/functions/fetchAutoCompoundingEvents.html +1 -257
  34. package/docs/functions/fetchAutoCompoundingEventsGql.html +1 -251
  35. package/docs/functions/fetchCetusPools.html +1 -231
  36. package/docs/functions/fetchChainIdentifier.html +1 -233
  37. package/docs/functions/fetchCheckRatioEvents.html +1 -249
  38. package/docs/functions/fetchLiquidityChangeEvents.html +1 -257
  39. package/docs/functions/fetchMultiCategoryEvents.html +1 -348
  40. package/docs/functions/fetchMultiReceipts.html +1 -261
  41. package/docs/functions/fetchNftHolders.html +1 -233
  42. package/docs/functions/fetchPools.html +1 -230
  43. package/docs/functions/fetchPortfolioData.html +1 -243
  44. package/docs/functions/fetchProtocolData.html +1 -231
  45. package/docs/functions/fetchTVL.html +1 -253
  46. package/docs/functions/fetchUserVaultBalances.html +1 -245
  47. package/docs/functions/fetchUserVaults.html +1 -243
  48. package/docs/functions/fetchUserWalletData.html +1 -243
  49. package/docs/functions/fetchVoloExchangeRate.html +1 -251
  50. package/docs/functions/fetchWithdrawV2Events.html +1 -255
  51. package/docs/functions/getAirdropShare.html +1 -243
  52. package/docs/functions/getAllDoubleAssetVaults.html +1 -235
  53. package/docs/functions/getAllSingleAssetVaults.html +1 -235
  54. package/docs/functions/getAllVaultBalances.html +1 -265
  55. package/docs/functions/getAllVaults.html +1 -233
  56. package/docs/functions/getAlphaUnlocks.html +1 -245
  57. package/docs/functions/getAlphaVaultBalance.html +1 -255
  58. package/docs/functions/getAmounts.html +1 -272
  59. package/docs/functions/getApr.html +1 -243
  60. package/docs/functions/getAprs.html +1 -255
  61. package/docs/functions/getApy.html +1 -243
  62. package/docs/functions/getApys.html +1 -255
  63. package/docs/functions/getCetusInvestorTicksMap.html +1 -284
  64. package/docs/functions/getCetusPool.html +1 -270
  65. package/docs/functions/getCetusSqrtPriceMap.html +1 -249
  66. package/docs/functions/getCoinAmountsFromLiquidity.html +1 -273
  67. package/docs/functions/getConf.html +1 -13163
  68. package/docs/functions/getCurrentTick.html +1 -247
  69. package/docs/functions/getDistributor.html +1 -252
  70. package/docs/functions/getDoubleAssetVaultBalance.html +1 -268
  71. package/docs/functions/getDoubleAssetVaults.html +1 -253
  72. package/docs/functions/getHoldersFromTransactions.html +1 -299
  73. package/docs/functions/getInvestor.html +1 -259
  74. package/docs/functions/getInvestorPoolMap.html +1 -241
  75. package/docs/functions/getLastAutoCompoundTime.html +1 -249
  76. package/docs/functions/getLatestPrices.html +1 -253
  77. package/docs/functions/getLiquidity.html +1 -260
  78. package/docs/functions/getMultiCetusPool.html +1 -231
  79. package/docs/functions/getMultiInvestor.html +1 -231
  80. package/docs/functions/getMultiLatestPrices.html +1 -233
  81. package/docs/functions/getMultiParentPool.html +1 -231
  82. package/docs/functions/getMultiPool.html +1 -231
  83. package/docs/functions/getMultiReceipts.html +1 -243
  84. package/docs/functions/getParentPool.html +1 -266
  85. package/docs/functions/getPool.html +1 -262
  86. package/docs/functions/getPoolExchangeRate.html +1 -254
  87. package/docs/functions/getPoolExchangeRateMap.html +1 -249
  88. package/docs/functions/getPoolsWeightDistribution.html +1 -266
  89. package/docs/functions/getPositionRange.html +1 -283
  90. package/docs/functions/getPositionRanges.html +1 -289
  91. package/docs/functions/getPositionTicks.html +1 -249
  92. package/docs/functions/getPriceToTick.html +1 -264
  93. package/docs/functions/getRebalanceHistories.html +1 -269
  94. package/docs/functions/getRebalanceHistory.html +1 -255
  95. package/docs/functions/getReceipts.html +1 -268
  96. package/docs/functions/getSingleAssetVaultBalance.html +1 -268
  97. package/docs/functions/getSingleAssetVaults.html +1 -253
  98. package/docs/functions/getSuiClient.html +3 -247
  99. package/docs/functions/getSuiNodeUrl.html +3 -232
  100. package/docs/functions/getTVLs-1.html +1 -243
  101. package/docs/functions/getTickSpacing.html +1 -247
  102. package/docs/functions/getTickToPrice.html +1 -248
  103. package/docs/functions/getTvls.html +1 -259
  104. package/docs/functions/getUserTokensFromTransactions.html +1 -269
  105. package/docs/functions/getUserTokensInUsdFromTransactions.html +1 -263
  106. package/docs/functions/getVaultBalance.html +1 -277
  107. package/docs/functions/getVaultBalanceForActiveUsers.html +1 -261
  108. package/docs/functions/getVaults.html +1 -250
  109. package/docs/functions/getXTokenVaultBalanceForActiveUsers.html +1 -261
  110. package/docs/functions/getZapAmounts.html +1 -323
  111. package/docs/functions/lastAutocompoundTime.html +1 -249
  112. package/docs/functions/liquidityToTokens.html +1 -253
  113. package/docs/functions/multiLiquidityToTokens.html +1 -271
  114. package/docs/functions/multiTokensToUsd.html +1 -262
  115. package/docs/functions/multiXTokensToLiquidity.html +1 -257
  116. package/docs/functions/parseUserWalletData.html +1 -243
  117. package/docs/functions/pendingBlueRewardAmount.html +1 -256
  118. package/docs/functions/setCustomSuiClient.html +5 -251
  119. package/docs/functions/setSuiClient.html +7 -255
  120. package/docs/functions/setSuiNodeUrl.html +5 -249
  121. package/docs/functions/setWeights.html +1 -270
  122. package/docs/functions/withdraw.html +1 -249
  123. package/docs/functions/withdrawAlphaTxb.html +1 -257
  124. package/docs/functions/withdrawTxb.html +1 -260
  125. package/docs/functions/zapDepositTxb.html +1 -300
  126. package/docs/index.html +41 -587
  127. package/docs/interfaces/Coin.html +12 -474
  128. package/docs/interfaces/CoinPair.html +3 -358
  129. package/docs/interfaces/NaviVoloData.html +3 -514
  130. package/docs/interfaces/PoolData.html +8 -579
  131. package/docs/interfaces/PoolWeightDistribution.html +4 -414
  132. package/docs/interfaces/RebalanceHistoryType.html +9 -652
  133. package/docs/modules.html +198 -1430
  134. package/docs/types/AfterTransactionEventNode.html +1 -305
  135. package/docs/types/Allocator.html +1 -321
  136. package/docs/types/AlphaFiDoubleAssetVault.html +1 -258
  137. package/docs/types/AlphaFiMultiVaultBalance.html +1 -219
  138. package/docs/types/AlphaFiSingleAssetVault.html +1 -244
  139. package/docs/types/AlphaFiVault.html +1 -214
  140. package/docs/types/AlphaFiVaultBalance.html +1 -220
  141. package/docs/types/AlphaPoolType.html +1 -383
  142. package/docs/types/AlphaReceipt.html +1 -220
  143. package/docs/types/AlphaReceiptFields.html +1 -421
  144. package/docs/types/AlphaVaultBalance.html +1 -245
  145. package/docs/types/AutoBalancePoolNames.html +1 -226
  146. package/docs/types/AutoCompoundingEventNode.html +1 -230
  147. package/docs/types/BluefinInvestor.html +1 -209
  148. package/docs/types/BluefinPoolType.html +1 -440
  149. package/docs/types/BucketInvestor.html +1 -249
  150. package/docs/types/CetusInvestor.html +1 -240
  151. package/docs/types/CetusPoolType.html +1 -433
  152. package/docs/types/CetusSwapOptions.html +1 -209
  153. package/docs/types/CoinAmounts.html +1 -216
  154. package/docs/types/CoinName.html +1 -293
  155. package/docs/types/CoinType.html +1 -294
  156. package/docs/types/CommonInvestorFields.html +1 -276
  157. package/docs/types/CreatePoolOptions.html +1 -246
  158. package/docs/types/Distributor.html +1 -341
  159. package/docs/types/DoubleAssetMultiVaultBalance.html +1 -236
  160. package/docs/types/DoubleAssetPoolNames.html +1 -297
  161. package/docs/types/DoubleAssetTokenHoldings.html +1 -232
  162. package/docs/types/DoubleAssetVaultBalance.html +1 -229
  163. package/docs/types/EventCategory.html +1 -209
  164. package/docs/types/EventNode.html +1 -229
  165. package/docs/types/GetHoldersParams.html +1 -221
  166. package/docs/types/GetTokenHoldingsParams.html +1 -227
  167. package/docs/types/GetUserTokensFromTransactionsParams.html +1 -233
  168. package/docs/types/GetUserTokensInUsdFromTransactionsParams.html +1 -244
  169. package/docs/types/GetVaultBalanceForActiveUsersParams.html +1 -231
  170. package/docs/types/GetVaultBalanceParams.html +1 -217
  171. package/docs/types/HoldingsObj.html +1 -223
  172. package/docs/types/Icon.html +1 -266
  173. package/docs/types/Investor.html +1 -245
  174. package/docs/types/LiquidityChangeEventNode.html +1 -220
  175. package/docs/types/LiquidityToTokensParams.html +1 -255
  176. package/docs/types/LiquidityToUsdParams.html +1 -267
  177. package/docs/types/LoopingDebt.html +1 -258
  178. package/docs/types/LoopingPoolNames.html +1 -216
  179. package/docs/types/LpBreakdownType.html +1 -238
  180. package/docs/types/MemberPoolDataType.html +1 -276
  181. package/docs/types/MemberType.html +1 -269
  182. package/docs/types/MultiGetVaultBalancesParams.html +1 -229
  183. package/docs/types/NaviInvestor.html +1 -235
  184. package/docs/types/OtherReceiptFields.html +1 -373
  185. package/docs/types/PoolName.html +1 -214
  186. package/docs/types/PoolReceipt.html +1 -253
  187. package/docs/types/PoolType.html +1 -388
  188. package/docs/types/Receipt.html +1 -475
  189. package/docs/types/ReceiptGQL.html +1 -374
  190. package/docs/types/SingleAssetMultiVaultBalance.html +1 -232
  191. package/docs/types/SingleAssetPoolNames.html +1 -244
  192. package/docs/types/SingleAssetTokenHoldings.html +1 -228
  193. package/docs/types/SingleAssetVaultBalance.html +1 -223
  194. package/docs/types/SingleGetVaultBalancesParams.html +1 -224
  195. package/docs/types/StrategyType.html +1 -221
  196. package/docs/types/SuiNetwork.html +1 -213
  197. package/docs/types/SwapOptions.html +1 -248
  198. package/docs/types/TickSpacing.html +1 -212
  199. package/docs/types/TotalWeightType.html +1 -246
  200. package/docs/types/TransactionBlockType.html +1 -358
  201. package/docs/types/UserPoolLiquidity.html +1 -221
  202. package/docs/types/UserPoolTokenHoldings.html +1 -217
  203. package/docs/types/UserUsdHoldings.html +1 -223
  204. package/docs/types/VaultBalance.html +1 -216
  205. package/docs/types/WithdrawV2EventNode.html +1 -208
  206. package/docs/variables/bluefinPoolMap.html +1 -214
  207. package/docs/variables/cetusPoolMap.html +1 -214
  208. package/docs/variables/coinsList.html +1 -220
  209. package/docs/variables/defunctPoolsSet.html +1 -209
  210. package/docs/variables/doubleAssetPoolCoinMap.html +1 -237
  211. package/docs/variables/eventCategories.html +1 -210
  212. package/docs/variables/ignoredWalletsForDailyRevenue.html +1 -218
  213. package/docs/variables/loopingAccountAddresses.html +1 -219
  214. package/docs/variables/loopingPoolCoinMap.html +1 -233
  215. package/docs/variables/naviAssetMap.html +1 -215
  216. package/docs/variables/poolIdPoolNameMap.html +1 -218
  217. package/docs/variables/poolInfo.html +1 -319
  218. package/docs/variables/singleAssetPoolCoinMap.html +1 -229
  219. package/docs/variables/stableCoins.html +1 -207
  220. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
1
  import { PoolName } from "./common/types.js";
2
2
  export declare function getApr(poolName: PoolName): Promise<number>;
3
3
  export declare function getAprs(poolNames?: PoolName[]): Promise<Record<string, number>>;
4
+ export declare function getRewardAprs(poolNames?: PoolName[]): Promise<Record<string, number>>;
4
5
  export declare function getApy(poolName: PoolName): Promise<number>;
5
6
  export declare function getApys(poolNames?: PoolName[]): Promise<Record<string, number>>;
7
+ export declare function fetchRewardAPR(poolName: PoolName, ignoreCache: boolean): Promise<number>;
6
8
  //# sourceMappingURL=getAprs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAprs.d.ts","sourceRoot":"","sources":["../../src/getAprs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,wBAAsB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAIhE;AAED,wBAAsB,OAAO,CAC3B,SAAS,CAAC,EAAE,QAAQ,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAoBjC;AAED,wBAAsB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAGhE;AAED,wBAAsB,OAAO,CAC3B,SAAS,CAAC,EAAE,QAAQ,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAYjC"}
1
+ {"version":3,"file":"getAprs.d.ts","sourceRoot":"","sources":["../../src/getAprs.ts"],"names":[],"mappings":"AAIA,OAAO,EAOL,QAAQ,EACT,MAAM,mBAAmB,CAAC;AAyB3B,wBAAsB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAIhE;AAED,wBAAsB,OAAO,CAC3B,SAAS,CAAC,EAAE,QAAQ,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAoBjC;AAED,wBAAsB,aAAa,CACjC,SAAS,CAAC,EAAE,QAAQ,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAoBjC;AAED,wBAAsB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAGhE;AAED,wBAAsB,OAAO,CAC3B,SAAS,CAAC,EAAE,QAAQ,EAAE,GACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAejC;AAaD,wBAAsB,cAAc,CAClC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,MAAM,CAAC,CA2RjB"}
@@ -1,5 +1,12 @@
1
1
  import { calculateAprForPools, fetchAutoCompoundingEvents, } from "./sui-sdk/events/fetchAutoCompoundingEvents.js";
2
- import { poolInfo } from "./common/maps.js";
2
+ import { doubleAssetPoolCoinMap, poolInfo, singleAssetPoolCoinMap, } from "./common/maps.js";
3
+ import { Decimal } from "decimal.js";
4
+ import { getConf } from "./common/constants.js";
5
+ import { getCetusPool, getDistributor, getInvestor, getMultiCetusPool, getMultiInvestor, getMultiParentPool, getMultiPool, getParentPool, getPool, } from "./sui-sdk/functions/getReceipts.js";
6
+ import { getLatestPrices, getMultiLatestPrices } from "./utils/prices.js";
7
+ import { ClmmPoolUtil, TickMath } from "@cetusprotocol/cetus-sui-clmm-sdk";
8
+ import BN from "bn.js";
9
+ import { coinsList } from "./common/coins.js";
3
10
  export async function getApr(poolName) {
4
11
  const aprMap = await getAprs([poolName]);
5
12
  const apr = aprMap[poolName];
@@ -22,17 +29,40 @@ export async function getAprs(poolNames) {
22
29
  }
23
30
  return aprMap;
24
31
  }
32
+ export async function getRewardAprs(poolNames) {
33
+ await Promise.all([
34
+ getMultiPool(),
35
+ getMultiCetusPool(),
36
+ getMultiInvestor(),
37
+ getMultiParentPool(),
38
+ getMultiLatestPrices(),
39
+ ]);
40
+ const aprMap = {};
41
+ if (poolNames) {
42
+ poolNames.forEach(async (pool) => {
43
+ aprMap[pool] = await fetchRewardAPR(pool, false);
44
+ });
45
+ }
46
+ else {
47
+ for (const pool of Object.keys(poolInfo)) {
48
+ aprMap[pool] = await fetchRewardAPR(pool, false);
49
+ }
50
+ }
51
+ return aprMap;
52
+ }
25
53
  export async function getApy(poolName) {
26
54
  const apy = convertAprToApy(await getApr(poolName));
27
55
  return apy;
28
56
  }
29
57
  export async function getApys(poolNames) {
30
58
  const aprMap = await getAprs(poolNames);
59
+ const rewardAprMap = await getRewardAprs(poolNames);
60
+ // console.log(aprMap);
31
61
  // Convert each APR to APY
32
62
  const apyMap = {};
33
63
  for (const poolName in aprMap) {
34
64
  if (aprMap.hasOwnProperty(poolName)) {
35
- apyMap[poolName] = convertAprToApy(aprMap[poolName]);
65
+ apyMap[poolName] = convertAprToApy(aprMap[poolName] + rewardAprMap[poolName]);
36
66
  }
37
67
  }
38
68
  return apyMap;
@@ -47,4 +77,221 @@ function convertAprToApy(apr) {
47
77
  const apy = 100 * (Math.pow(1 + apr / 100 / n, n) - 1);
48
78
  return apy;
49
79
  }
80
+ export async function fetchRewardAPR(poolName, ignoreCache) {
81
+ let apr = 0;
82
+ if (!(poolName in poolInfo)) {
83
+ return 0;
84
+ }
85
+ try {
86
+ if (poolName === "ALPHA") {
87
+ const pool = await getPool("ALPHA", ignoreCache);
88
+ const distributor = await getDistributor(ignoreCache);
89
+ if (pool && distributor) {
90
+ const allocator = distributor.content.fields.pool_allocator;
91
+ const tokensInvested = Number(pool.content.fields.tokensInvested);
92
+ const target = Number(distributor.content.fields.target);
93
+ const members = allocator.fields.members.fields.contents;
94
+ let alphaMember = undefined;
95
+ for (const member of members) {
96
+ if (member.fields.key === getConf().ALPHA_POOL) {
97
+ alphaMember = member;
98
+ }
99
+ }
100
+ if (alphaMember) {
101
+ const weight = Number(alphaMember.fields.value.fields.pool_data.fields.contents[0].fields
102
+ .value.fields.weight);
103
+ const totalWeightArr = allocator.fields.total_weights.fields.contents;
104
+ const totalWeight = Number(totalWeightArr[0].fields.value);
105
+ if (totalWeight === 0 || tokensInvested === 0)
106
+ return 0;
107
+ apr =
108
+ (((target / 100) * 365 * weight) / totalWeight / tokensInvested) *
109
+ (2_750_000 / 4_250_000) *
110
+ 100;
111
+ }
112
+ }
113
+ }
114
+ else if (Object.keys(doubleAssetPoolCoinMap).includes(poolName)) {
115
+ const distributor = await getDistributor(ignoreCache);
116
+ let clmmPool;
117
+ if (poolInfo[poolName].parentProtocolName == "CETUS") {
118
+ clmmPool = await getCetusPool(poolName, ignoreCache);
119
+ }
120
+ else {
121
+ clmmPool = await getParentPool(poolName, ignoreCache);
122
+ }
123
+ const pool = await getPool(poolName, ignoreCache);
124
+ let investor;
125
+ if (poolInfo[poolName].parentProtocolName == "CETUS") {
126
+ investor = (await getInvestor(poolName, ignoreCache));
127
+ }
128
+ else {
129
+ investor = (await getInvestor(poolName, ignoreCache));
130
+ }
131
+ const tokenA = doubleAssetPoolCoinMap[poolName].coin1;
132
+ const tokenB = doubleAssetPoolCoinMap[poolName].coin2;
133
+ if (distributor && clmmPool && investor && pool) {
134
+ const allocator = distributor.content.fields.pool_allocator;
135
+ const members = allocator.fields.members.fields.contents;
136
+ let poolMember = undefined;
137
+ for (const member of members) {
138
+ if (member.fields.key == poolInfo[poolName].poolId) {
139
+ poolMember = member;
140
+ }
141
+ }
142
+ if (poolMember) {
143
+ try {
144
+ const target = Number(distributor.content.fields.target);
145
+ const weight = Number(poolMember.fields.value.fields.pool_data.fields.contents[0].fields
146
+ .value.fields.weight);
147
+ const totalWeight = Number(allocator.fields.total_weights.fields.contents[0].fields.value);
148
+ if (totalWeight === 0)
149
+ return 0;
150
+ const [priceOfCoin0, priceOfCoin1] = await getLatestPrices([
151
+ `${tokenA}/USD`,
152
+ `${tokenB}/USD`,
153
+ ], ignoreCache);
154
+ const [priceOfAlpha] = await getLatestPrices(["ALPHA/USD"], ignoreCache);
155
+ if (priceOfCoin0 && priceOfCoin1) {
156
+ const liquidity = Math.floor(parseFloat(pool.content.fields.tokensInvested)).toString();
157
+ const current_sqrt_price = new BN(clmmPool.content.fields.current_sqrt_price);
158
+ const upperBound = 443636;
159
+ let lowerTick = Number(investor.content.fields.lower_tick);
160
+ let upperTick = Number(investor.content.fields.upper_tick);
161
+ if (lowerTick > upperBound) {
162
+ lowerTick = -~(lowerTick - 1);
163
+ }
164
+ if (upperTick > upperBound) {
165
+ upperTick = -~(upperTick - 1);
166
+ }
167
+ const upper_sqrt_price = TickMath.tickIndexToSqrtPriceX64(upperTick);
168
+ const lower_sqrt_price = TickMath.tickIndexToSqrtPriceX64(lowerTick);
169
+ const { coinA, coinB } = ClmmPoolUtil.getCoinAmountFromLiquidity(new BN(liquidity), current_sqrt_price, lower_sqrt_price, upper_sqrt_price, false);
170
+ let amount0 = coinA;
171
+ let amount1 = coinB;
172
+ // amount0 = amount0 / 10 ** coins[tokenA as CoinName].expo;
173
+ // amount1 = amount1 / 10 ** coins[tokenB as CoinName].expo;
174
+ amount0 = amount0.div(new BN(10 ** coinsList[tokenA].expo));
175
+ amount1 = amount1.div(new BN(10 ** coinsList[tokenB].expo));
176
+ if (priceOfAlpha) {
177
+ const amount0Big = new Decimal(amount0.toString());
178
+ const targetBig = new Decimal(target);
179
+ const weightBig = new Decimal(weight);
180
+ const totalWeightBig = new Decimal(totalWeight);
181
+ const priceOfAlphaBig = new Decimal(priceOfAlpha);
182
+ const priceOfCoin0Big = new Decimal(priceOfCoin0);
183
+ const amount1Big = new Decimal(amount1.toString());
184
+ const priceOfCoin1Big = new Decimal(priceOfCoin1);
185
+ if (totalWeight === 0 ||
186
+ amount0Big
187
+ .mul(priceOfCoin0Big)
188
+ .add(amount1Big.mul(priceOfCoin1Big))
189
+ .isZero()) {
190
+ return 0;
191
+ }
192
+ // apr =
193
+ // (((((target / (100 * 1_000_000_000)) * 365 * weight) /
194
+ // totalWeight) *
195
+ // parseFloat(priceOfAlpha)) /
196
+ // (amount0 * Number(priceOfCoin0) +
197
+ // amount1 * Number(priceOfCoin1))) *
198
+ // (2_750_000 / 4_250_000) *
199
+ // 100;
200
+ apr = targetBig
201
+ .div(new Decimal(100).mul(new Decimal(1000000000)))
202
+ .mul(new Decimal(365))
203
+ .mul(weightBig)
204
+ .div(totalWeightBig)
205
+ .mul(priceOfAlphaBig)
206
+ .div(amount0Big
207
+ .mul(priceOfCoin0Big)
208
+ .add(amount1Big.mul(priceOfCoin1Big)))
209
+ .mul(new Decimal(2750000).div(new Decimal(4250000)))
210
+ .mul(new Decimal(100))
211
+ .toNumber();
212
+ }
213
+ }
214
+ }
215
+ catch (error) {
216
+ console.log(`Error calculating Alpha APR for pool ${poolName}`, error);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ else if (Object.keys(singleAssetPoolCoinMap).includes(poolName)) {
222
+ const distributor = await getDistributor(ignoreCache);
223
+ const pool = await getPool(poolName, ignoreCache);
224
+ const token = singleAssetPoolCoinMap[poolName];
225
+ if (distributor && pool) {
226
+ const allocator = distributor.content.fields.pool_allocator;
227
+ const members = allocator.fields.members.fields.contents;
228
+ let poolMember = undefined;
229
+ for (const member of members) {
230
+ if (member.fields.key == poolInfo[poolName].poolId) {
231
+ poolMember = member;
232
+ }
233
+ }
234
+ if (poolMember) {
235
+ try {
236
+ const target = Number(distributor.content.fields.target);
237
+ const weight = Number(poolMember.fields.value.fields.pool_data.fields.contents[0].fields
238
+ .value.fields.weight);
239
+ const totalWeight = Number(allocator.fields.total_weights.fields.contents[0].fields.value);
240
+ if (totalWeight === 0)
241
+ return 0;
242
+ const [priceOfCoin] = await getLatestPrices([`${token.coin}/USD`], ignoreCache);
243
+ const [priceOfAlpha] = await getLatestPrices(["ALPHA/USD"], ignoreCache);
244
+ if (priceOfCoin) {
245
+ let tokensInvested = new Decimal(pool.content.fields.tokensInvested);
246
+ // dividing by 1e9 for every token because navi scales every token's liquidity to 1e9;
247
+ if (poolName == "NAVI-LOOP-SUI-VSUI" ||
248
+ poolName == "NAVI-LOOP-USDC-USDT" ||
249
+ poolName == "NAVI-LOOP-HASUI-SUI" ||
250
+ poolName == "NAVI-LOOP-USDT-USDC") {
251
+ const investor = (await getInvestor(poolName, ignoreCache));
252
+ if (investor) {
253
+ const debtToSupplyRatio = new Decimal(investor.content.fields.current_debt_to_supply_ratio);
254
+ tokensInvested = tokensInvested
255
+ .mul(new Decimal(1).minus(debtToSupplyRatio.div(new Decimal(1e20))))
256
+ .div(new Decimal(1e9));
257
+ }
258
+ else {
259
+ tokensInvested = new Decimal(0);
260
+ }
261
+ }
262
+ else {
263
+ tokensInvested = tokensInvested.div(Math.pow(10, 9));
264
+ }
265
+ const liquidity = tokensInvested.toNumber();
266
+ if (priceOfAlpha) {
267
+ if (totalWeight === 0 || liquidity * Number(priceOfCoin) === 0)
268
+ return 0;
269
+ apr =
270
+ (((((target / (100 * 1_000_000_000)) * 365 * weight) /
271
+ totalWeight) *
272
+ parseFloat(priceOfAlpha)) /
273
+ (liquidity * Number(priceOfCoin))) *
274
+ (2_750_000 / 4_250_000) *
275
+ 100;
276
+ }
277
+ }
278
+ }
279
+ catch (e) {
280
+ console.error("error in fetchRewardAPR", e);
281
+ }
282
+ }
283
+ }
284
+ }
285
+ else {
286
+ console.log("fetchRewardAPR not implemented for poolName: " + poolName);
287
+ }
288
+ }
289
+ catch (e) {
290
+ console.error("error in fetchRewardAPR", e);
291
+ }
292
+ if (!apr) {
293
+ apr = 0;
294
+ }
295
+ return apr;
296
+ }
50
297
  //# sourceMappingURL=getAprs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAprs.js","sourceRoot":"","sources":["../../src/getAprs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,gDAAgD,CAAC;AAExD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,QAAkB;IAC7C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,CAAC,QAAQ,CAAC,C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C;YACpC,MAAM,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,GAAW;IAClC,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,gBAAgB;IACnC,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACvD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import {\n calculateAprForPools,\n fetchAutoCompoundingEvents,\n} from \"./sui-sdk/events/fetchAutoCompoundingEvents.js\";\nimport { PoolName } from \"./common/types.js\";\nimport { poolInfo } from \"./common/maps.js\";\n\nexport async function getApr(poolName: PoolName): Promise<number> {\n const aprMap = await getAprs([poolName]);\n const apr = aprMap[poolName];\n return apr;\n}\n\nexport async function getAprs(\n poolNames?: PoolName[],\n): Promise<Record<string, number>> {\n const endTime = Date.now();\n const startTime = endTime - 24 * 60 * 60 * 1000; // timestamp for 24 hours ago\n\n const events = await fetchAutoCompoundingEvents({\n startTime: startTime,\n endTime: endTime,\n poolNames: poolNames,\n });\n\n const aprMap = await calculateAprForPools(events);\n\n for (const pool of Object.keys(poolInfo)) {\n const poolName = pool as PoolName;\n if (!(poolName in aprMap)) {\n aprMap[poolName] = 0;\n }\n }\n\n return aprMap;\n}\n\nexport async function getApy(poolName: PoolName): Promise<number> {\n const apy = convertAprToApy(await getApr(poolName));\n return apy;\n}\n\nexport async function getApys(\n poolNames?: PoolName[],\n): Promise<Record<string, number>> {\n const aprMap = await getAprs(poolNames);\n\n // Convert each APR to APY\n const apyMap: Record<string, number> = {};\n for (const poolName in aprMap) {\n if (aprMap.hasOwnProperty(poolName)) {\n apyMap[poolName] = convertAprToApy(aprMap[poolName]);\n }\n }\n\n return apyMap;\n}\n\n/**\n * Converts APR to APY with compounding 6 times a day\n * @param apr - The annual percentage rate (APR) as a decimal\n * @returns The annual percentage yield (APY) as a decimal\n */\nfunction convertAprToApy(apr: number): number {\n const n = 6 * 365; // 6 times a day\n const apy = 100 * (Math.pow(1 + apr / 100 / n, n) - 1);\n return apy;\n}\n"]}
1
+ {"version":3,"file":"getAprs.js","sourceRoot":"","sources":["../../src/getAprs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,gDAAgD,CAAC;AAUxD,OAAO,EACL,sBAAsB,EACtB,QAAQ,EACR,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,OAAO,GACR,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,QAAkB;IAC7C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC7B,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,SAAsB;IAEtB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG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,EAAE,CAAC;wBACX,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;oBAC9C,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,+CAA+C,GAAG,QAAQ,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,CAAC,CAAC;IACV,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import {\n calculateAprForPools,\n fetchAutoCompoundingEvents,\n} from \"./sui-sdk/events/fetchAutoCompoundingEvents.js\";\nimport {\n Allocator,\n BluefinInvestor,\n CetusInvestor,\n CommonInvestorFields,\n MemberType,\n NaviInvestor,\n PoolName,\n} from \"./common/types.js\";\nimport {\n doubleAssetPoolCoinMap,\n poolInfo,\n singleAssetPoolCoinMap,\n} from \"./common/maps.js\";\nimport { Decimal } from \"decimal.js\";\nimport { getConf } from \"./common/constants.js\";\nimport {\n getCetusPool,\n getDistributor,\n getInvestor,\n getMultiCetusPool,\n getMultiInvestor,\n getMultiParentPool,\n getMultiPool,\n getParentPool,\n getPool,\n} from \"./sui-sdk/functions/getReceipts.js\";\nimport { getLatestPrices, getMultiLatestPrices } from \"./utils/prices.js\";\nimport { PythPriceIdPair } from \"./common/pyth.js\";\nimport { ClmmPoolUtil, TickMath } from \"@cetusprotocol/cetus-sui-clmm-sdk\";\nimport BN from \"bn.js\";\nimport { coinsList } from \"./common/coins.js\";\n\nexport async function getApr(poolName: PoolName): Promise<number> {\n const aprMap = await getAprs([poolName]);\n const apr = aprMap[poolName];\n return apr;\n}\n\nexport async function getAprs(\n poolNames?: PoolName[],\n): Promise<Record<string, number>> {\n const endTime = Date.now();\n const startTime = endTime - 24 * 60 * 60 * 1000; // timestamp for 24 hours ago\n\n const events = await fetchAutoCompoundingEvents({\n startTime: startTime,\n endTime: endTime,\n poolNames: poolNames,\n });\n\n const aprMap = await calculateAprForPools(events);\n\n for (const pool of Object.keys(poolInfo)) {\n const poolName = pool as PoolName;\n if (!(poolName in aprMap)) {\n aprMap[poolName] = 0;\n }\n }\n\n return aprMap;\n}\n\nexport async function getRewardAprs(\n poolNames?: PoolName[],\n): Promise<Record<string, number>> {\n await Promise.all([\n getMultiPool(),\n getMultiCetusPool(),\n getMultiInvestor(),\n getMultiParentPool(),\n getMultiLatestPrices(),\n ]);\n const aprMap: Record<string, number> = {};\n\n if (poolNames) {\n poolNames.forEach(async (pool) => {\n aprMap[pool] = await fetchRewardAPR(pool as PoolName, false);\n });\n } else {\n for (const pool of Object.keys(poolInfo)) {\n aprMap[pool] = await fetchRewardAPR(pool as PoolName, false);\n }\n }\n return aprMap;\n}\n\nexport async function getApy(poolName: PoolName): Promise<number> {\n const apy = convertAprToApy(await getApr(poolName));\n return apy;\n}\n\nexport async function getApys(\n poolNames?: PoolName[],\n): Promise<Record<string, number>> {\n const aprMap = await getAprs(poolNames);\n const rewardAprMap = await getRewardAprs(poolNames);\n // console.log(aprMap);\n // Convert each APR to APY\n const apyMap: Record<string, number> = {};\n for (const poolName in aprMap) {\n if (aprMap.hasOwnProperty(poolName)) {\n apyMap[poolName] = convertAprToApy(\n aprMap[poolName] + rewardAprMap[poolName],\n );\n }\n }\n\n return apyMap;\n}\n\n/**\n * Converts APR to APY with compounding 6 times a day\n * @param apr - The annual percentage rate (APR) as a decimal\n * @returns The annual percentage yield (APY) as a decimal\n */\nfunction convertAprToApy(apr: number): number {\n const n = 6 * 365; // 6 times a day\n const apy = 100 * (Math.pow(1 + apr / 100 / n, n) - 1);\n return apy;\n}\n\nexport async function fetchRewardAPR(\n poolName: PoolName,\n ignoreCache: boolean,\n): Promise<number> {\n let apr = 0;\n if (!(poolName in poolInfo)) {\n return 0;\n }\n try {\n if (poolName === \"ALPHA\") {\n const pool = await getPool(\"ALPHA\", ignoreCache);\n const distributor = await getDistributor(ignoreCache);\n if (pool && distributor) {\n const allocator: Allocator = distributor.content.fields.pool_allocator;\n const tokensInvested = Number(pool.content.fields.tokensInvested);\n const target = Number(distributor.content.fields.target);\n const members: MemberType[] = allocator.fields.members.fields.contents;\n let alphaMember: MemberType | undefined = undefined;\n for (const member of members) {\n if (member.fields.key === getConf().ALPHA_POOL) {\n alphaMember = member;\n }\n }\n if (alphaMember) {\n const weight = Number(\n alphaMember.fields.value.fields.pool_data.fields.contents[0].fields\n .value.fields.weight,\n );\n const totalWeightArr = allocator.fields.total_weights.fields.contents;\n const totalWeight = Number(totalWeightArr[0].fields.value);\n\n if (totalWeight === 0 || tokensInvested === 0) return 0;\n\n apr =\n (((target / 100) * 365 * weight) / totalWeight / tokensInvested) *\n (2_750_000 / 4_250_000) *\n 100;\n }\n }\n } else if (Object.keys(doubleAssetPoolCoinMap).includes(poolName)) {\n const distributor = await getDistributor(ignoreCache);\n let clmmPool;\n if (poolInfo[poolName].parentProtocolName == \"CETUS\") {\n clmmPool = await getCetusPool(poolName, ignoreCache);\n } else {\n clmmPool = await getParentPool(poolName, ignoreCache);\n }\n const pool = await getPool(poolName, ignoreCache);\n let investor;\n if (poolInfo[poolName].parentProtocolName == \"CETUS\") {\n investor = (await getInvestor(poolName, ignoreCache)) as CetusInvestor &\n CommonInvestorFields;\n } else {\n investor = (await getInvestor(\n poolName,\n ignoreCache,\n )) as BluefinInvestor & CommonInvestorFields;\n }\n const tokenA = doubleAssetPoolCoinMap[poolName].coin1;\n const tokenB = doubleAssetPoolCoinMap[poolName].coin2;\n\n if (distributor && clmmPool && investor && pool) {\n const allocator: Allocator = distributor.content.fields.pool_allocator;\n const members: MemberType[] = allocator.fields.members.fields.contents;\n\n let poolMember: MemberType | undefined = undefined;\n\n for (const member of members) {\n if (member.fields.key == poolInfo[poolName].poolId) {\n poolMember = member;\n }\n }\n\n if (poolMember) {\n try {\n const target = Number(distributor.content.fields.target);\n const weight = Number(\n poolMember.fields.value.fields.pool_data.fields.contents[0].fields\n .value.fields.weight,\n );\n const totalWeight = Number(\n allocator.fields.total_weights.fields.contents[0].fields.value,\n );\n\n if (totalWeight === 0) return 0;\n\n const [priceOfCoin0, priceOfCoin1] = await getLatestPrices(\n [\n `${tokenA}/USD` as PythPriceIdPair,\n `${tokenB}/USD` as PythPriceIdPair,\n ],\n ignoreCache,\n );\n const [priceOfAlpha] = await getLatestPrices(\n [\"ALPHA/USD\"],\n ignoreCache,\n );\n if (priceOfCoin0 && priceOfCoin1) {\n const liquidity = Math.floor(\n parseFloat(pool.content.fields.tokensInvested),\n ).toString();\n const current_sqrt_price = new BN(\n clmmPool.content.fields.current_sqrt_price,\n );\n const upperBound = 443636;\n let lowerTick = Number(investor.content.fields.lower_tick);\n let upperTick = Number(investor.content.fields.upper_tick);\n\n if (lowerTick > upperBound) {\n lowerTick = -~(lowerTick - 1);\n }\n if (upperTick > upperBound) {\n upperTick = -~(upperTick - 1);\n }\n const upper_sqrt_price =\n TickMath.tickIndexToSqrtPriceX64(upperTick);\n const lower_sqrt_price =\n TickMath.tickIndexToSqrtPriceX64(lowerTick);\n const { coinA, coinB } = ClmmPoolUtil.getCoinAmountFromLiquidity(\n new BN(liquidity),\n current_sqrt_price,\n lower_sqrt_price,\n upper_sqrt_price,\n false,\n );\n let amount0 = coinA;\n let amount1 = coinB;\n // amount0 = amount0 / 10 ** coins[tokenA as CoinName].expo;\n // amount1 = amount1 / 10 ** coins[tokenB as CoinName].expo;\n amount0 = amount0.div(new BN(10 ** coinsList[tokenA].expo));\n amount1 = amount1.div(new BN(10 ** coinsList[tokenB].expo));\n\n if (priceOfAlpha) {\n const amount0Big = new Decimal(amount0.toString());\n const targetBig = new Decimal(target);\n const weightBig = new Decimal(weight);\n const totalWeightBig = new Decimal(totalWeight);\n const priceOfAlphaBig = new Decimal(priceOfAlpha);\n const priceOfCoin0Big = new Decimal(priceOfCoin0);\n const amount1Big = new Decimal(amount1.toString());\n const priceOfCoin1Big = new Decimal(priceOfCoin1);\n\n if (\n totalWeight === 0 ||\n amount0Big\n .mul(priceOfCoin0Big)\n .add(amount1Big.mul(priceOfCoin1Big))\n .isZero()\n ) {\n return 0;\n }\n // apr =\n // (((((target / (100 * 1_000_000_000)) * 365 * weight) /\n // totalWeight) *\n // parseFloat(priceOfAlpha)) /\n // (amount0 * Number(priceOfCoin0) +\n // amount1 * Number(priceOfCoin1))) *\n // (2_750_000 / 4_250_000) *\n // 100;\n\n apr = targetBig\n .div(new Decimal(100).mul(new Decimal(1000000000)))\n .mul(new Decimal(365))\n .mul(weightBig)\n .div(totalWeightBig)\n .mul(priceOfAlphaBig)\n .div(\n amount0Big\n .mul(priceOfCoin0Big)\n .add(amount1Big.mul(priceOfCoin1Big)),\n )\n .mul(new Decimal(2750000).div(new Decimal(4250000)))\n .mul(new Decimal(100))\n .toNumber();\n }\n }\n } catch (error) {\n console.log(\n `Error calculating Alpha APR for pool ${poolName}`,\n error,\n );\n }\n }\n }\n } else if (Object.keys(singleAssetPoolCoinMap).includes(poolName)) {\n const distributor = await getDistributor(ignoreCache);\n const pool = await getPool(poolName, ignoreCache);\n\n const token = singleAssetPoolCoinMap[poolName];\n\n if (distributor && pool) {\n const allocator: Allocator = distributor.content.fields.pool_allocator;\n const members: MemberType[] = allocator.fields.members.fields.contents;\n\n let poolMember: MemberType | undefined = undefined;\n\n for (const member of members) {\n if (member.fields.key == poolInfo[poolName].poolId) {\n poolMember = member;\n }\n }\n\n if (poolMember) {\n try {\n const target = Number(distributor.content.fields.target);\n const weight = Number(\n poolMember.fields.value.fields.pool_data.fields.contents[0].fields\n .value.fields.weight,\n );\n const totalWeight = Number(\n allocator.fields.total_weights.fields.contents[0].fields.value,\n );\n\n if (totalWeight === 0) return 0;\n\n const [priceOfCoin] = await getLatestPrices(\n [`${token.coin}/USD` as PythPriceIdPair],\n ignoreCache,\n );\n\n const [priceOfAlpha] = await getLatestPrices(\n [\"ALPHA/USD\"],\n ignoreCache,\n );\n if (priceOfCoin) {\n let tokensInvested = new Decimal(\n pool.content.fields.tokensInvested,\n );\n // dividing by 1e9 for every token because navi scales every token's liquidity to 1e9;\n if (\n poolName == \"NAVI-LOOP-SUI-VSUI\" ||\n poolName == \"NAVI-LOOP-USDC-USDT\" ||\n poolName == \"NAVI-LOOP-HASUI-SUI\" ||\n poolName == \"NAVI-LOOP-USDT-USDC\"\n ) {\n const investor = (await getInvestor(\n poolName,\n ignoreCache,\n )) as NaviInvestor & CommonInvestorFields;\n if (investor) {\n const debtToSupplyRatio = new Decimal(\n investor.content.fields.current_debt_to_supply_ratio,\n );\n tokensInvested = tokensInvested\n .mul(\n new Decimal(1).minus(\n debtToSupplyRatio.div(new Decimal(1e20)),\n ),\n )\n .div(new Decimal(1e9));\n } else {\n tokensInvested = new Decimal(0);\n }\n } else {\n tokensInvested = tokensInvested.div(Math.pow(10, 9));\n }\n const liquidity = tokensInvested.toNumber();\n if (priceOfAlpha) {\n if (totalWeight === 0 || liquidity * Number(priceOfCoin) === 0)\n return 0;\n\n apr =\n (((((target / (100 * 1_000_000_000)) * 365 * weight) /\n totalWeight) *\n parseFloat(priceOfAlpha)) /\n (liquidity * Number(priceOfCoin))) *\n (2_750_000 / 4_250_000) *\n 100;\n }\n }\n } catch (e) {\n console.error(\"error in fetchRewardAPR\", e);\n }\n }\n }\n } else {\n console.log(\"fetchRewardAPR not implemented for poolName: \" + poolName);\n }\n } catch (e) {\n console.error(\"error in fetchRewardAPR\", e);\n }\n\n if (!apr) {\n apr = 0;\n }\n return apr;\n}\n"]}
@@ -1,26 +1,25 @@
1
1
  :root {
2
- --light-hl-0: #795e26;
3
- --dark-hl-0: #dcdcaa;
4
- --light-hl-1: #000000;
5
- --dark-hl-1: #d4d4d4;
6
- --light-hl-2: #a31515;
7
- --dark-hl-2: #ce9178;
8
- --light-hl-3: #af00db;
9
- --dark-hl-3: #c586c0;
10
- --light-hl-4: #001080;
11
- --dark-hl-4: #9cdcfe;
12
- --light-hl-5: #0000ff;
13
- --dark-hl-5: #569cd6;
14
- --light-hl-6: #0070c1;
15
- --dark-hl-6: #4fc1ff;
16
- --light-hl-7: #267f99;
17
- --dark-hl-7: #4ec9b0;
18
- --light-code-background: #ffffff;
19
- --dark-code-background: #1e1e1e;
2
+ --light-hl-0: #795E26;
3
+ --dark-hl-0: #DCDCAA;
4
+ --light-hl-1: #000000;
5
+ --dark-hl-1: #D4D4D4;
6
+ --light-hl-2: #A31515;
7
+ --dark-hl-2: #CE9178;
8
+ --light-hl-3: #AF00DB;
9
+ --dark-hl-3: #C586C0;
10
+ --light-hl-4: #001080;
11
+ --dark-hl-4: #9CDCFE;
12
+ --light-hl-5: #0000FF;
13
+ --dark-hl-5: #569CD6;
14
+ --light-hl-6: #0070C1;
15
+ --dark-hl-6: #4FC1FF;
16
+ --light-hl-7: #267F99;
17
+ --dark-hl-7: #4EC9B0;
18
+ --light-code-background: #FFFFFF;
19
+ --dark-code-background: #1E1E1E;
20
20
  }
21
21
 
22
- @media (prefers-color-scheme: light) {
23
- :root {
22
+ @media (prefers-color-scheme: light) { :root {
24
23
  --hl-0: var(--light-hl-0);
25
24
  --hl-1: var(--light-hl-1);
26
25
  --hl-2: var(--light-hl-2);
@@ -30,11 +29,9 @@
30
29
  --hl-6: var(--light-hl-6);
31
30
  --hl-7: var(--light-hl-7);
32
31
  --code-background: var(--light-code-background);
33
- }
34
- }
32
+ } }
35
33
 
36
- @media (prefers-color-scheme: dark) {
37
- :root {
34
+ @media (prefers-color-scheme: dark) { :root {
38
35
  --hl-0: var(--dark-hl-0);
39
36
  --hl-1: var(--dark-hl-1);
40
37
  --hl-2: var(--dark-hl-2);
@@ -44,58 +41,38 @@
44
41
  --hl-6: var(--dark-hl-6);
45
42
  --hl-7: var(--dark-hl-7);
46
43
  --code-background: var(--dark-code-background);
47
- }
48
- }
44
+ } }
49
45
 
50
- :root[data-theme="light"] {
51
- --hl-0: var(--light-hl-0);
52
- --hl-1: var(--light-hl-1);
53
- --hl-2: var(--light-hl-2);
54
- --hl-3: var(--light-hl-3);
55
- --hl-4: var(--light-hl-4);
56
- --hl-5: var(--light-hl-5);
57
- --hl-6: var(--light-hl-6);
58
- --hl-7: var(--light-hl-7);
59
- --code-background: var(--light-code-background);
46
+ :root[data-theme='light'] {
47
+ --hl-0: var(--light-hl-0);
48
+ --hl-1: var(--light-hl-1);
49
+ --hl-2: var(--light-hl-2);
50
+ --hl-3: var(--light-hl-3);
51
+ --hl-4: var(--light-hl-4);
52
+ --hl-5: var(--light-hl-5);
53
+ --hl-6: var(--light-hl-6);
54
+ --hl-7: var(--light-hl-7);
55
+ --code-background: var(--light-code-background);
60
56
  }
61
57
 
62
- :root[data-theme="dark"] {
63
- --hl-0: var(--dark-hl-0);
64
- --hl-1: var(--dark-hl-1);
65
- --hl-2: var(--dark-hl-2);
66
- --hl-3: var(--dark-hl-3);
67
- --hl-4: var(--dark-hl-4);
68
- --hl-5: var(--dark-hl-5);
69
- --hl-6: var(--dark-hl-6);
70
- --hl-7: var(--dark-hl-7);
71
- --code-background: var(--dark-code-background);
58
+ :root[data-theme='dark'] {
59
+ --hl-0: var(--dark-hl-0);
60
+ --hl-1: var(--dark-hl-1);
61
+ --hl-2: var(--dark-hl-2);
62
+ --hl-3: var(--dark-hl-3);
63
+ --hl-4: var(--dark-hl-4);
64
+ --hl-5: var(--dark-hl-5);
65
+ --hl-6: var(--dark-hl-6);
66
+ --hl-7: var(--dark-hl-7);
67
+ --code-background: var(--dark-code-background);
72
68
  }
73
69
 
74
- .hl-0 {
75
- color: var(--hl-0);
76
- }
77
- .hl-1 {
78
- color: var(--hl-1);
79
- }
80
- .hl-2 {
81
- color: var(--hl-2);
82
- }
83
- .hl-3 {
84
- color: var(--hl-3);
85
- }
86
- .hl-4 {
87
- color: var(--hl-4);
88
- }
89
- .hl-5 {
90
- color: var(--hl-5);
91
- }
92
- .hl-6 {
93
- color: var(--hl-6);
94
- }
95
- .hl-7 {
96
- color: var(--hl-7);
97
- }
98
- pre,
99
- code {
100
- background: var(--code-background);
101
- }
70
+ .hl-0 { color: var(--hl-0); }
71
+ .hl-1 { color: var(--hl-1); }
72
+ .hl-2 { color: var(--hl-2); }
73
+ .hl-3 { color: var(--hl-3); }
74
+ .hl-4 { color: var(--hl-4); }
75
+ .hl-5 { color: var(--hl-5); }
76
+ .hl-6 { color: var(--hl-6); }
77
+ .hl-7 { color: var(--hl-7); }
78
+ pre, code { background: var(--code-background); }
@@ -1,21 +1,18 @@
1
- (function () {
2
- addIcons();
3
- function addIcons() {
4
- if (document.readyState === "loading")
5
- return document.addEventListener("DOMContentLoaded", addIcons);
6
- const svg = document.body.appendChild(
7
- document.createElementNS("http://www.w3.org/2000/svg", "svg"),
8
- );
9
- svg.innerHTML = `<g id="icon-1" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-module)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">M</text></g><g id="icon-2" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-module)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">M</text></g><g id="icon-4" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">N</text></g><g id="icon-8" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-enum)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">E</text></g><g id="icon-16" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-property)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">P</text></g><g id="icon-32" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-variable)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">V</text></g><g id="icon-64" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">F</text></g><g id="icon-128" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-class)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">C</text></g><g id="icon-256" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">I</text></g><g id="icon-512" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-constructor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">C</text></g><g id="icon-1024" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-property)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">P</text></g><g id="icon-2048" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-method)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">M</text></g><g id="icon-4096" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">F</text></g><g id="icon-8192" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-property)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">P</text></g><g id="icon-16384" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-constructor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">C</text></g><g id="icon-32768" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-property)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">P</text></g><g id="icon-65536" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">T</text></g><g id="icon-131072" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">T</text></g><g id="icon-262144" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-accessor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">A</text></g><g id="icon-524288" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-accessor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">A</text></g><g id="icon-1048576" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-accessor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">A</text></g><g id="icon-2097152" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">T</text></g><g id="icon-4194304" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-reference)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">R</text></g><g id="icon-8388608" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-document)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><g stroke="var(--color-icon-text)" fill="none" stroke-width="1.5"><polygon points="6,5 6,19 18,19, 18,10 13,5"></polygon><line x1="9" y1="9" x2="13" y2="9"></line><line x1="9" y1="12" x2="15" y2="12"></line><line x1="9" y1="15" x2="15" y2="15"></line></g></g><g id="icon-folder" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-document)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><g stroke="var(--color-icon-text)" fill="none" stroke-width="1.5"><polygon points="5,5 10,5 12,8 19,8 19,18 5,18"></polygon></g></g><g id="icon-chevronDown" class="tsd-no-select"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-icon-text)"></path></g><g id="icon-chevronSmall" class="tsd-no-select"><path d="M1.5 5.50969L8 11.6609L14.5 5.50969L12.5466 3.66086L8 7.96494L3.45341 3.66086L1.5 5.50969Z" fill="var(--color-icon-text)"></path></g><g id="icon-checkbox" class="tsd-no-select"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></g><g id="icon-menu" class="tsd-no-select"><rect x="1" y="3" width="14" height="2" fill="var(--color-icon-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-icon-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-icon-text)"></rect></g><g id="icon-search" class="tsd-no-select"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-icon-text)"></path></g><g id="icon-anchor" class="tsd-no-select"><g stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></g></g>`;
10
- svg.style.display = "none";
11
- if (location.protocol === "file:") updateUseElements();
12
- }
1
+ (function() {
2
+ addIcons();
3
+ function addIcons() {
4
+ if (document.readyState === "loading") return document.addEventListener("DOMContentLoaded", addIcons);
5
+ const svg = document.body.appendChild(document.createElementNS("http://www.w3.org/2000/svg", "svg"));
6
+ svg.innerHTML = `<g id="icon-1" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-module)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">M</text></g><g id="icon-2" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-module)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">M</text></g><g id="icon-4" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">N</text></g><g id="icon-8" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-enum)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">E</text></g><g id="icon-16" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-property)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">P</text></g><g id="icon-32" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-variable)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">V</text></g><g id="icon-64" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">F</text></g><g id="icon-128" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-class)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">C</text></g><g id="icon-256" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">I</text></g><g id="icon-512" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-constructor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">C</text></g><g id="icon-1024" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-property)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">P</text></g><g id="icon-2048" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-method)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">M</text></g><g id="icon-4096" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">F</text></g><g id="icon-8192" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-property)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">P</text></g><g id="icon-16384" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-constructor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">C</text></g><g id="icon-32768" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-property)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">P</text></g><g id="icon-65536" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">T</text></g><g id="icon-131072" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">T</text></g><g id="icon-262144" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-accessor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">A</text></g><g id="icon-524288" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-accessor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">A</text></g><g id="icon-1048576" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-accessor)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">A</text></g><g id="icon-2097152" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-type-alias)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">T</text></g><g id="icon-4194304" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-reference)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12"></rect><text fill="var(--color-icon-text)" x="50%" y="50%" dominant-baseline="central" text-anchor="middle">R</text></g><g id="icon-8388608" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-document)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><g stroke="var(--color-icon-text)" fill="none" stroke-width="1.5"><polygon points="6,5 6,19 18,19, 18,10 13,5"></polygon><line x1="9" y1="9" x2="13" y2="9"></line><line x1="9" y1="12" x2="15" y2="12"></line><line x1="9" y1="15" x2="15" y2="15"></line></g></g><g id="icon-folder" class="tsd-no-select"><rect fill="var(--color-icon-background)" stroke="var(--color-document)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><g stroke="var(--color-icon-text)" fill="none" stroke-width="1.5"><polygon points="5,5 10,5 12,8 19,8 19,18 5,18"></polygon></g></g><g id="icon-chevronDown" class="tsd-no-select"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-icon-text)"></path></g><g id="icon-chevronSmall" class="tsd-no-select"><path d="M1.5 5.50969L8 11.6609L14.5 5.50969L12.5466 3.66086L8 7.96494L3.45341 3.66086L1.5 5.50969Z" fill="var(--color-icon-text)"></path></g><g id="icon-checkbox" class="tsd-no-select"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></g><g id="icon-menu" class="tsd-no-select"><rect x="1" y="3" width="14" height="2" fill="var(--color-icon-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-icon-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-icon-text)"></rect></g><g id="icon-search" class="tsd-no-select"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-icon-text)"></path></g><g id="icon-anchor" class="tsd-no-select"><g stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></g></g>`;
7
+ svg.style.display = "none";
8
+ if (location.protocol === "file:") updateUseElements();
9
+ }
13
10
 
14
- function updateUseElements() {
15
- document.querySelectorAll("use").forEach((el) => {
16
- if (el.getAttribute("href").includes("#icon-")) {
17
- el.setAttribute("href", el.getAttribute("href").replace(/.*#/, "#"));
18
- }
19
- });
20
- }
21
- })();
11
+ function updateUseElements() {
12
+ document.querySelectorAll("use").forEach(el => {
13
+ if (el.getAttribute("href").includes("#icon-")) {
14
+ el.setAttribute("href", el.getAttribute("href").replace(/.*#/, "#"));
15
+ }
16
+ });
17
+ }
18
+ })()