@alphafi/alphafi-sdk 0.0.57 → 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 (228) hide show
  1. package/dist/cjs/common/constants.d.ts +31 -0
  2. package/dist/cjs/common/constants.d.ts.map +1 -1
  3. package/dist/cjs/common/constants.js +38 -5
  4. package/dist/cjs/common/constants.js.map +1 -1
  5. package/dist/cjs/getAprs.d.ts +2 -0
  6. package/dist/cjs/getAprs.d.ts.map +1 -1
  7. package/dist/cjs/getAprs.js +251 -1
  8. package/dist/cjs/getAprs.js.map +1 -1
  9. package/dist/cjs/transactions/bluefin.d.ts.map +1 -1
  10. package/dist/cjs/transactions/bluefin.js +84 -28
  11. package/dist/cjs/transactions/bluefin.js.map +1 -1
  12. package/dist/esm/common/constants.d.ts +31 -0
  13. package/dist/esm/common/constants.d.ts.map +1 -1
  14. package/dist/esm/common/constants.js +38 -5
  15. package/dist/esm/common/constants.js.map +1 -1
  16. package/dist/esm/getAprs.d.ts +2 -0
  17. package/dist/esm/getAprs.d.ts.map +1 -1
  18. package/dist/esm/getAprs.js +249 -2
  19. package/dist/esm/getAprs.js.map +1 -1
  20. package/dist/esm/transactions/bluefin.d.ts.map +1 -1
  21. package/dist/esm/transactions/bluefin.js +84 -28
  22. package/dist/esm/transactions/bluefin.js.map +1 -1
  23. package/docs/assets/highlight.css +51 -74
  24. package/docs/assets/icons.js +17 -20
  25. package/docs/assets/main.js +5 -2163
  26. package/docs/assets/navigation.js +1 -2
  27. package/docs/assets/search.js +1 -2
  28. package/docs/assets/style.css +850 -846
  29. package/docs/functions/alphaLpBreakdown.html +1 -253
  30. package/docs/functions/cetusLpBreakdown.html +1 -253
  31. package/docs/functions/claimBlueRewardTxb.html +1 -258
  32. package/docs/functions/claimRewardTxb.html +1 -243
  33. package/docs/functions/coinAmountToXTokensDoubleAsset.html +1 -267
  34. package/docs/functions/coinAmountToXTokensSingleAsset.html +1 -260
  35. package/docs/functions/coinsInPool.html +1 -438
  36. package/docs/functions/collectRewards.html +1 -242
  37. package/docs/functions/deposit.html +1 -246
  38. package/docs/functions/depositDoubleAssetTxb.html +1 -270
  39. package/docs/functions/depositSingleAssetTxb.html +1 -263
  40. package/docs/functions/fetchAfterTransactionEvents.html +1 -328
  41. package/docs/functions/fetchAutoCompoundingEvents.html +1 -257
  42. package/docs/functions/fetchAutoCompoundingEventsGql.html +1 -251
  43. package/docs/functions/fetchCetusPools.html +1 -231
  44. package/docs/functions/fetchChainIdentifier.html +1 -233
  45. package/docs/functions/fetchCheckRatioEvents.html +1 -249
  46. package/docs/functions/fetchLiquidityChangeEvents.html +1 -257
  47. package/docs/functions/fetchMultiCategoryEvents.html +1 -348
  48. package/docs/functions/fetchMultiReceipts.html +1 -261
  49. package/docs/functions/fetchNftHolders.html +1 -233
  50. package/docs/functions/fetchPools.html +1 -230
  51. package/docs/functions/fetchPortfolioData.html +1 -243
  52. package/docs/functions/fetchProtocolData.html +1 -231
  53. package/docs/functions/fetchTVL.html +1 -253
  54. package/docs/functions/fetchUserVaultBalances.html +1 -245
  55. package/docs/functions/fetchUserVaults.html +1 -243
  56. package/docs/functions/fetchUserWalletData.html +1 -243
  57. package/docs/functions/fetchVoloExchangeRate.html +1 -251
  58. package/docs/functions/fetchWithdrawV2Events.html +1 -255
  59. package/docs/functions/getAirdropShare.html +1 -243
  60. package/docs/functions/getAllDoubleAssetVaults.html +1 -235
  61. package/docs/functions/getAllSingleAssetVaults.html +1 -235
  62. package/docs/functions/getAllVaultBalances.html +1 -265
  63. package/docs/functions/getAllVaults.html +1 -233
  64. package/docs/functions/getAlphaUnlocks.html +1 -245
  65. package/docs/functions/getAlphaVaultBalance.html +1 -255
  66. package/docs/functions/getAmounts.html +1 -272
  67. package/docs/functions/getApr.html +1 -243
  68. package/docs/functions/getAprs.html +1 -255
  69. package/docs/functions/getApy.html +1 -243
  70. package/docs/functions/getApys.html +1 -255
  71. package/docs/functions/getCetusInvestorTicksMap.html +1 -284
  72. package/docs/functions/getCetusPool.html +1 -270
  73. package/docs/functions/getCetusSqrtPriceMap.html +1 -249
  74. package/docs/functions/getCoinAmountsFromLiquidity.html +1 -273
  75. package/docs/functions/getConf.html +1 -13163
  76. package/docs/functions/getCurrentTick.html +1 -247
  77. package/docs/functions/getDistributor.html +1 -252
  78. package/docs/functions/getDoubleAssetVaultBalance.html +1 -268
  79. package/docs/functions/getDoubleAssetVaults.html +1 -253
  80. package/docs/functions/getHoldersFromTransactions.html +1 -299
  81. package/docs/functions/getInvestor.html +1 -259
  82. package/docs/functions/getInvestorPoolMap.html +1 -241
  83. package/docs/functions/getLastAutoCompoundTime.html +1 -249
  84. package/docs/functions/getLatestPrices.html +1 -253
  85. package/docs/functions/getLiquidity.html +1 -260
  86. package/docs/functions/getMultiCetusPool.html +1 -231
  87. package/docs/functions/getMultiInvestor.html +1 -231
  88. package/docs/functions/getMultiLatestPrices.html +1 -233
  89. package/docs/functions/getMultiParentPool.html +1 -231
  90. package/docs/functions/getMultiPool.html +1 -231
  91. package/docs/functions/getMultiReceipts.html +1 -243
  92. package/docs/functions/getParentPool.html +1 -266
  93. package/docs/functions/getPool.html +1 -262
  94. package/docs/functions/getPoolExchangeRate.html +1 -254
  95. package/docs/functions/getPoolExchangeRateMap.html +1 -249
  96. package/docs/functions/getPoolsWeightDistribution.html +1 -266
  97. package/docs/functions/getPositionRange.html +1 -283
  98. package/docs/functions/getPositionRanges.html +1 -289
  99. package/docs/functions/getPositionTicks.html +1 -249
  100. package/docs/functions/getPriceToTick.html +1 -264
  101. package/docs/functions/getRebalanceHistories.html +1 -269
  102. package/docs/functions/getRebalanceHistory.html +1 -255
  103. package/docs/functions/getReceipts.html +1 -268
  104. package/docs/functions/getSingleAssetVaultBalance.html +1 -268
  105. package/docs/functions/getSingleAssetVaults.html +1 -253
  106. package/docs/functions/getSuiClient.html +3 -247
  107. package/docs/functions/getSuiNodeUrl.html +3 -232
  108. package/docs/functions/getTVLs-1.html +1 -243
  109. package/docs/functions/getTickSpacing.html +1 -247
  110. package/docs/functions/getTickToPrice.html +1 -248
  111. package/docs/functions/getTvls.html +1 -259
  112. package/docs/functions/getUserTokensFromTransactions.html +1 -269
  113. package/docs/functions/getUserTokensInUsdFromTransactions.html +1 -263
  114. package/docs/functions/getVaultBalance.html +1 -277
  115. package/docs/functions/getVaultBalanceForActiveUsers.html +1 -261
  116. package/docs/functions/getVaults.html +1 -250
  117. package/docs/functions/getXTokenVaultBalanceForActiveUsers.html +1 -261
  118. package/docs/functions/getZapAmounts.html +1 -323
  119. package/docs/functions/lastAutocompoundTime.html +1 -249
  120. package/docs/functions/liquidityToTokens.html +1 -253
  121. package/docs/functions/multiLiquidityToTokens.html +1 -271
  122. package/docs/functions/multiTokensToUsd.html +1 -262
  123. package/docs/functions/multiXTokensToLiquidity.html +1 -257
  124. package/docs/functions/parseUserWalletData.html +1 -243
  125. package/docs/functions/pendingBlueRewardAmount.html +1 -256
  126. package/docs/functions/setCustomSuiClient.html +5 -251
  127. package/docs/functions/setSuiClient.html +7 -255
  128. package/docs/functions/setSuiNodeUrl.html +5 -249
  129. package/docs/functions/setWeights.html +1 -270
  130. package/docs/functions/withdraw.html +1 -249
  131. package/docs/functions/withdrawAlphaTxb.html +1 -257
  132. package/docs/functions/withdrawTxb.html +1 -260
  133. package/docs/functions/zapDepositTxb.html +1 -300
  134. package/docs/index.html +41 -587
  135. package/docs/interfaces/Coin.html +12 -474
  136. package/docs/interfaces/CoinPair.html +3 -358
  137. package/docs/interfaces/NaviVoloData.html +3 -514
  138. package/docs/interfaces/PoolData.html +8 -579
  139. package/docs/interfaces/PoolWeightDistribution.html +4 -414
  140. package/docs/interfaces/RebalanceHistoryType.html +9 -652
  141. package/docs/modules.html +198 -1430
  142. package/docs/types/AfterTransactionEventNode.html +1 -305
  143. package/docs/types/Allocator.html +1 -321
  144. package/docs/types/AlphaFiDoubleAssetVault.html +1 -258
  145. package/docs/types/AlphaFiMultiVaultBalance.html +1 -219
  146. package/docs/types/AlphaFiSingleAssetVault.html +1 -244
  147. package/docs/types/AlphaFiVault.html +1 -214
  148. package/docs/types/AlphaFiVaultBalance.html +1 -220
  149. package/docs/types/AlphaPoolType.html +1 -383
  150. package/docs/types/AlphaReceipt.html +1 -220
  151. package/docs/types/AlphaReceiptFields.html +1 -421
  152. package/docs/types/AlphaVaultBalance.html +1 -245
  153. package/docs/types/AutoBalancePoolNames.html +1 -226
  154. package/docs/types/AutoCompoundingEventNode.html +1 -230
  155. package/docs/types/BluefinInvestor.html +1 -209
  156. package/docs/types/BluefinPoolType.html +1 -440
  157. package/docs/types/BucketInvestor.html +1 -249
  158. package/docs/types/CetusInvestor.html +1 -240
  159. package/docs/types/CetusPoolType.html +1 -433
  160. package/docs/types/CetusSwapOptions.html +1 -209
  161. package/docs/types/CoinAmounts.html +1 -216
  162. package/docs/types/CoinName.html +1 -293
  163. package/docs/types/CoinType.html +1 -294
  164. package/docs/types/CommonInvestorFields.html +1 -276
  165. package/docs/types/CreatePoolOptions.html +1 -246
  166. package/docs/types/Distributor.html +1 -341
  167. package/docs/types/DoubleAssetMultiVaultBalance.html +1 -236
  168. package/docs/types/DoubleAssetPoolNames.html +1 -297
  169. package/docs/types/DoubleAssetTokenHoldings.html +1 -232
  170. package/docs/types/DoubleAssetVaultBalance.html +1 -229
  171. package/docs/types/EventCategory.html +1 -209
  172. package/docs/types/EventNode.html +1 -229
  173. package/docs/types/GetHoldersParams.html +1 -221
  174. package/docs/types/GetTokenHoldingsParams.html +1 -227
  175. package/docs/types/GetUserTokensFromTransactionsParams.html +1 -233
  176. package/docs/types/GetUserTokensInUsdFromTransactionsParams.html +1 -244
  177. package/docs/types/GetVaultBalanceForActiveUsersParams.html +1 -231
  178. package/docs/types/GetVaultBalanceParams.html +1 -217
  179. package/docs/types/HoldingsObj.html +1 -223
  180. package/docs/types/Icon.html +1 -266
  181. package/docs/types/Investor.html +1 -245
  182. package/docs/types/LiquidityChangeEventNode.html +1 -220
  183. package/docs/types/LiquidityToTokensParams.html +1 -255
  184. package/docs/types/LiquidityToUsdParams.html +1 -267
  185. package/docs/types/LoopingDebt.html +1 -258
  186. package/docs/types/LoopingPoolNames.html +1 -216
  187. package/docs/types/LpBreakdownType.html +1 -238
  188. package/docs/types/MemberPoolDataType.html +1 -276
  189. package/docs/types/MemberType.html +1 -269
  190. package/docs/types/MultiGetVaultBalancesParams.html +1 -229
  191. package/docs/types/NaviInvestor.html +1 -235
  192. package/docs/types/OtherReceiptFields.html +1 -373
  193. package/docs/types/PoolName.html +1 -214
  194. package/docs/types/PoolReceipt.html +1 -253
  195. package/docs/types/PoolType.html +1 -388
  196. package/docs/types/Receipt.html +1 -475
  197. package/docs/types/ReceiptGQL.html +1 -374
  198. package/docs/types/SingleAssetMultiVaultBalance.html +1 -232
  199. package/docs/types/SingleAssetPoolNames.html +1 -244
  200. package/docs/types/SingleAssetTokenHoldings.html +1 -228
  201. package/docs/types/SingleAssetVaultBalance.html +1 -223
  202. package/docs/types/SingleGetVaultBalancesParams.html +1 -224
  203. package/docs/types/StrategyType.html +1 -221
  204. package/docs/types/SuiNetwork.html +1 -213
  205. package/docs/types/SwapOptions.html +1 -248
  206. package/docs/types/TickSpacing.html +1 -212
  207. package/docs/types/TotalWeightType.html +1 -246
  208. package/docs/types/TransactionBlockType.html +1 -358
  209. package/docs/types/UserPoolLiquidity.html +1 -221
  210. package/docs/types/UserPoolTokenHoldings.html +1 -217
  211. package/docs/types/UserUsdHoldings.html +1 -223
  212. package/docs/types/VaultBalance.html +1 -216
  213. package/docs/types/WithdrawV2EventNode.html +1 -208
  214. package/docs/variables/bluefinPoolMap.html +1 -214
  215. package/docs/variables/cetusPoolMap.html +1 -214
  216. package/docs/variables/coinsList.html +1 -220
  217. package/docs/variables/defunctPoolsSet.html +1 -209
  218. package/docs/variables/doubleAssetPoolCoinMap.html +1 -237
  219. package/docs/variables/eventCategories.html +1 -210
  220. package/docs/variables/ignoredWalletsForDailyRevenue.html +1 -218
  221. package/docs/variables/loopingAccountAddresses.html +1 -219
  222. package/docs/variables/loopingPoolCoinMap.html +1 -233
  223. package/docs/variables/naviAssetMap.html +1 -215
  224. package/docs/variables/poolIdPoolNameMap.html +1 -218
  225. package/docs/variables/poolInfo.html +1 -319
  226. package/docs/variables/singleAssetPoolCoinMap.html +1 -229
  227. package/docs/variables/stableCoins.html +1 -207
  228. 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"}
@@ -2,10 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getApr = getApr;
4
4
  exports.getAprs = getAprs;
5
+ exports.getRewardAprs = getRewardAprs;
5
6
  exports.getApy = getApy;
6
7
  exports.getApys = getApys;
8
+ exports.fetchRewardAPR = fetchRewardAPR;
9
+ const tslib_1 = require("tslib");
7
10
  const fetchAutoCompoundingEvents_js_1 = require("./sui-sdk/events/fetchAutoCompoundingEvents.js");
8
11
  const maps_js_1 = require("./common/maps.js");
12
+ const decimal_js_1 = require("decimal.js");
13
+ const constants_js_1 = require("./common/constants.js");
14
+ const getReceipts_js_1 = require("./sui-sdk/functions/getReceipts.js");
15
+ const prices_js_1 = require("./utils/prices.js");
16
+ const cetus_sui_clmm_sdk_1 = require("@cetusprotocol/cetus-sui-clmm-sdk");
17
+ const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
18
+ const coins_js_1 = require("./common/coins.js");
9
19
  async function getApr(poolName) {
10
20
  const aprMap = await getAprs([poolName]);
11
21
  const apr = aprMap[poolName];
@@ -28,17 +38,40 @@ async function getAprs(poolNames) {
28
38
  }
29
39
  return aprMap;
30
40
  }
41
+ async function getRewardAprs(poolNames) {
42
+ await Promise.all([
43
+ (0, getReceipts_js_1.getMultiPool)(),
44
+ (0, getReceipts_js_1.getMultiCetusPool)(),
45
+ (0, getReceipts_js_1.getMultiInvestor)(),
46
+ (0, getReceipts_js_1.getMultiParentPool)(),
47
+ (0, prices_js_1.getMultiLatestPrices)(),
48
+ ]);
49
+ const aprMap = {};
50
+ if (poolNames) {
51
+ poolNames.forEach(async (pool) => {
52
+ aprMap[pool] = await fetchRewardAPR(pool, false);
53
+ });
54
+ }
55
+ else {
56
+ for (const pool of Object.keys(maps_js_1.poolInfo)) {
57
+ aprMap[pool] = await fetchRewardAPR(pool, false);
58
+ }
59
+ }
60
+ return aprMap;
61
+ }
31
62
  async function getApy(poolName) {
32
63
  const apy = convertAprToApy(await getApr(poolName));
33
64
  return apy;
34
65
  }
35
66
  async function getApys(poolNames) {
36
67
  const aprMap = await getAprs(poolNames);
68
+ const rewardAprMap = await getRewardAprs(poolNames);
69
+ // console.log(aprMap);
37
70
  // Convert each APR to APY
38
71
  const apyMap = {};
39
72
  for (const poolName in aprMap) {
40
73
  if (aprMap.hasOwnProperty(poolName)) {
41
- apyMap[poolName] = convertAprToApy(aprMap[poolName]);
74
+ apyMap[poolName] = convertAprToApy(aprMap[poolName] + rewardAprMap[poolName]);
42
75
  }
43
76
  }
44
77
  return apyMap;
@@ -53,4 +86,221 @@ function convertAprToApy(apr) {
53
86
  const apy = 100 * (Math.pow(1 + apr / 100 / n, n) - 1);
54
87
  return apy;
55
88
  }
89
+ async function fetchRewardAPR(poolName, ignoreCache) {
90
+ let apr = 0;
91
+ if (!(poolName in maps_js_1.poolInfo)) {
92
+ return 0;
93
+ }
94
+ try {
95
+ if (poolName === "ALPHA") {
96
+ const pool = await (0, getReceipts_js_1.getPool)("ALPHA", ignoreCache);
97
+ const distributor = await (0, getReceipts_js_1.getDistributor)(ignoreCache);
98
+ if (pool && distributor) {
99
+ const allocator = distributor.content.fields.pool_allocator;
100
+ const tokensInvested = Number(pool.content.fields.tokensInvested);
101
+ const target = Number(distributor.content.fields.target);
102
+ const members = allocator.fields.members.fields.contents;
103
+ let alphaMember = undefined;
104
+ for (const member of members) {
105
+ if (member.fields.key === (0, constants_js_1.getConf)().ALPHA_POOL) {
106
+ alphaMember = member;
107
+ }
108
+ }
109
+ if (alphaMember) {
110
+ const weight = Number(alphaMember.fields.value.fields.pool_data.fields.contents[0].fields
111
+ .value.fields.weight);
112
+ const totalWeightArr = allocator.fields.total_weights.fields.contents;
113
+ const totalWeight = Number(totalWeightArr[0].fields.value);
114
+ if (totalWeight === 0 || tokensInvested === 0)
115
+ return 0;
116
+ apr =
117
+ (((target / 100) * 365 * weight) / totalWeight / tokensInvested) *
118
+ (2750000 / 4250000) *
119
+ 100;
120
+ }
121
+ }
122
+ }
123
+ else if (Object.keys(maps_js_1.doubleAssetPoolCoinMap).includes(poolName)) {
124
+ const distributor = await (0, getReceipts_js_1.getDistributor)(ignoreCache);
125
+ let clmmPool;
126
+ if (maps_js_1.poolInfo[poolName].parentProtocolName == "CETUS") {
127
+ clmmPool = await (0, getReceipts_js_1.getCetusPool)(poolName, ignoreCache);
128
+ }
129
+ else {
130
+ clmmPool = await (0, getReceipts_js_1.getParentPool)(poolName, ignoreCache);
131
+ }
132
+ const pool = await (0, getReceipts_js_1.getPool)(poolName, ignoreCache);
133
+ let investor;
134
+ if (maps_js_1.poolInfo[poolName].parentProtocolName == "CETUS") {
135
+ investor = (await (0, getReceipts_js_1.getInvestor)(poolName, ignoreCache));
136
+ }
137
+ else {
138
+ investor = (await (0, getReceipts_js_1.getInvestor)(poolName, ignoreCache));
139
+ }
140
+ const tokenA = maps_js_1.doubleAssetPoolCoinMap[poolName].coin1;
141
+ const tokenB = maps_js_1.doubleAssetPoolCoinMap[poolName].coin2;
142
+ if (distributor && clmmPool && investor && pool) {
143
+ const allocator = distributor.content.fields.pool_allocator;
144
+ const members = allocator.fields.members.fields.contents;
145
+ let poolMember = undefined;
146
+ for (const member of members) {
147
+ if (member.fields.key == maps_js_1.poolInfo[poolName].poolId) {
148
+ poolMember = member;
149
+ }
150
+ }
151
+ if (poolMember) {
152
+ try {
153
+ const target = Number(distributor.content.fields.target);
154
+ const weight = Number(poolMember.fields.value.fields.pool_data.fields.contents[0].fields
155
+ .value.fields.weight);
156
+ const totalWeight = Number(allocator.fields.total_weights.fields.contents[0].fields.value);
157
+ if (totalWeight === 0)
158
+ return 0;
159
+ const [priceOfCoin0, priceOfCoin1] = await (0, prices_js_1.getLatestPrices)([
160
+ `${tokenA}/USD`,
161
+ `${tokenB}/USD`,
162
+ ], ignoreCache);
163
+ const [priceOfAlpha] = await (0, prices_js_1.getLatestPrices)(["ALPHA/USD"], ignoreCache);
164
+ if (priceOfCoin0 && priceOfCoin1) {
165
+ const liquidity = Math.floor(parseFloat(pool.content.fields.tokensInvested)).toString();
166
+ const current_sqrt_price = new bn_js_1.default(clmmPool.content.fields.current_sqrt_price);
167
+ const upperBound = 443636;
168
+ let lowerTick = Number(investor.content.fields.lower_tick);
169
+ let upperTick = Number(investor.content.fields.upper_tick);
170
+ if (lowerTick > upperBound) {
171
+ lowerTick = -~(lowerTick - 1);
172
+ }
173
+ if (upperTick > upperBound) {
174
+ upperTick = -~(upperTick - 1);
175
+ }
176
+ const upper_sqrt_price = cetus_sui_clmm_sdk_1.TickMath.tickIndexToSqrtPriceX64(upperTick);
177
+ const lower_sqrt_price = cetus_sui_clmm_sdk_1.TickMath.tickIndexToSqrtPriceX64(lowerTick);
178
+ const { coinA, coinB } = cetus_sui_clmm_sdk_1.ClmmPoolUtil.getCoinAmountFromLiquidity(new bn_js_1.default(liquidity), current_sqrt_price, lower_sqrt_price, upper_sqrt_price, false);
179
+ let amount0 = coinA;
180
+ let amount1 = coinB;
181
+ // amount0 = amount0 / 10 ** coins[tokenA as CoinName].expo;
182
+ // amount1 = amount1 / 10 ** coins[tokenB as CoinName].expo;
183
+ amount0 = amount0.div(new bn_js_1.default(10 ** coins_js_1.coinsList[tokenA].expo));
184
+ amount1 = amount1.div(new bn_js_1.default(10 ** coins_js_1.coinsList[tokenB].expo));
185
+ if (priceOfAlpha) {
186
+ const amount0Big = new decimal_js_1.Decimal(amount0.toString());
187
+ const targetBig = new decimal_js_1.Decimal(target);
188
+ const weightBig = new decimal_js_1.Decimal(weight);
189
+ const totalWeightBig = new decimal_js_1.Decimal(totalWeight);
190
+ const priceOfAlphaBig = new decimal_js_1.Decimal(priceOfAlpha);
191
+ const priceOfCoin0Big = new decimal_js_1.Decimal(priceOfCoin0);
192
+ const amount1Big = new decimal_js_1.Decimal(amount1.toString());
193
+ const priceOfCoin1Big = new decimal_js_1.Decimal(priceOfCoin1);
194
+ if (totalWeight === 0 ||
195
+ amount0Big
196
+ .mul(priceOfCoin0Big)
197
+ .add(amount1Big.mul(priceOfCoin1Big))
198
+ .isZero()) {
199
+ return 0;
200
+ }
201
+ // apr =
202
+ // (((((target / (100 * 1_000_000_000)) * 365 * weight) /
203
+ // totalWeight) *
204
+ // parseFloat(priceOfAlpha)) /
205
+ // (amount0 * Number(priceOfCoin0) +
206
+ // amount1 * Number(priceOfCoin1))) *
207
+ // (2_750_000 / 4_250_000) *
208
+ // 100;
209
+ apr = targetBig
210
+ .div(new decimal_js_1.Decimal(100).mul(new decimal_js_1.Decimal(1000000000)))
211
+ .mul(new decimal_js_1.Decimal(365))
212
+ .mul(weightBig)
213
+ .div(totalWeightBig)
214
+ .mul(priceOfAlphaBig)
215
+ .div(amount0Big
216
+ .mul(priceOfCoin0Big)
217
+ .add(amount1Big.mul(priceOfCoin1Big)))
218
+ .mul(new decimal_js_1.Decimal(2750000).div(new decimal_js_1.Decimal(4250000)))
219
+ .mul(new decimal_js_1.Decimal(100))
220
+ .toNumber();
221
+ }
222
+ }
223
+ }
224
+ catch (error) {
225
+ console.log(`Error calculating Alpha APR for pool ${poolName}`, error);
226
+ }
227
+ }
228
+ }
229
+ }
230
+ else if (Object.keys(maps_js_1.singleAssetPoolCoinMap).includes(poolName)) {
231
+ const distributor = await (0, getReceipts_js_1.getDistributor)(ignoreCache);
232
+ const pool = await (0, getReceipts_js_1.getPool)(poolName, ignoreCache);
233
+ const token = maps_js_1.singleAssetPoolCoinMap[poolName];
234
+ if (distributor && pool) {
235
+ const allocator = distributor.content.fields.pool_allocator;
236
+ const members = allocator.fields.members.fields.contents;
237
+ let poolMember = undefined;
238
+ for (const member of members) {
239
+ if (member.fields.key == maps_js_1.poolInfo[poolName].poolId) {
240
+ poolMember = member;
241
+ }
242
+ }
243
+ if (poolMember) {
244
+ try {
245
+ const target = Number(distributor.content.fields.target);
246
+ const weight = Number(poolMember.fields.value.fields.pool_data.fields.contents[0].fields
247
+ .value.fields.weight);
248
+ const totalWeight = Number(allocator.fields.total_weights.fields.contents[0].fields.value);
249
+ if (totalWeight === 0)
250
+ return 0;
251
+ const [priceOfCoin] = await (0, prices_js_1.getLatestPrices)([`${token.coin}/USD`], ignoreCache);
252
+ const [priceOfAlpha] = await (0, prices_js_1.getLatestPrices)(["ALPHA/USD"], ignoreCache);
253
+ if (priceOfCoin) {
254
+ let tokensInvested = new decimal_js_1.Decimal(pool.content.fields.tokensInvested);
255
+ // dividing by 1e9 for every token because navi scales every token's liquidity to 1e9;
256
+ if (poolName == "NAVI-LOOP-SUI-VSUI" ||
257
+ poolName == "NAVI-LOOP-USDC-USDT" ||
258
+ poolName == "NAVI-LOOP-HASUI-SUI" ||
259
+ poolName == "NAVI-LOOP-USDT-USDC") {
260
+ const investor = (await (0, getReceipts_js_1.getInvestor)(poolName, ignoreCache));
261
+ if (investor) {
262
+ const debtToSupplyRatio = new decimal_js_1.Decimal(investor.content.fields.current_debt_to_supply_ratio);
263
+ tokensInvested = tokensInvested
264
+ .mul(new decimal_js_1.Decimal(1).minus(debtToSupplyRatio.div(new decimal_js_1.Decimal(1e20))))
265
+ .div(new decimal_js_1.Decimal(1e9));
266
+ }
267
+ else {
268
+ tokensInvested = new decimal_js_1.Decimal(0);
269
+ }
270
+ }
271
+ else {
272
+ tokensInvested = tokensInvested.div(Math.pow(10, 9));
273
+ }
274
+ const liquidity = tokensInvested.toNumber();
275
+ if (priceOfAlpha) {
276
+ if (totalWeight === 0 || liquidity * Number(priceOfCoin) === 0)
277
+ return 0;
278
+ apr =
279
+ (((((target / (100 * 1000000000)) * 365 * weight) /
280
+ totalWeight) *
281
+ parseFloat(priceOfAlpha)) /
282
+ (liquidity * Number(priceOfCoin))) *
283
+ (2750000 / 4250000) *
284
+ 100;
285
+ }
286
+ }
287
+ }
288
+ catch (e) {
289
+ console.error("error in fetchRewardAPR", e);
290
+ }
291
+ }
292
+ }
293
+ }
294
+ else {
295
+ console.log("fetchRewardAPR not implemented for poolName: " + poolName);
296
+ }
297
+ }
298
+ catch (e) {
299
+ console.error("error in fetchRewardAPR", e);
300
+ }
301
+ if (!apr) {
302
+ apr = 0;
303
+ }
304
+ return apr;
305
+ }
56
306
  //# sourceMappingURL=getAprs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAprs.js","sourceRoot":"","sources":["../../src/getAprs.ts"],"names":[],"mappings":";;AAOA,wBAIC;AAED,0BAsBC;AAED,wBAGC;AAED,0BAcC;AAxDD,kGAGwD;AAExD,8CAA4C;AAErC,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;AAEM,KAAK,UAAU,OAAO,CAC3B,SAAsB;IAEtB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC3B,MAAM,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AG,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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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 +1 @@
1
- {"version":3,"file":"bluefin.d.ts","sourceRoot":"","sources":["../../../src/transactions/bluefin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAUvD,OAAO,EAAE,QAAQ,EAAW,MAAM,oBAAoB,CAAC;AAKvD,eAAO,MAAM,yBAAyB,WAC5B,MAAM,YACJ,QAAQ,aACP,OAAO,WACT;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,gBACf,WAAW,GAAG,SAAS,KACnC,OAAO,CAAC,WAAW,CAqLrB,CAAC;AAEF,eAAO,MAAM,0BAA0B,WAC7B,MAAM,YACJ,QAAQ,aACP,OAAO,WACT;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,gBACf,WAAW,GAAG,SAAS,KACnC,OAAO,CAAC,WAAW,CAuOrB,CAAC;AAEF,eAAO,MAAM,sBAAsB,WACzB,MAAM,YACJ,QAAQ,aACP,OAAO,WACT;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,gBACf,WAAW,GAAG,SAAS,KACnC,OAAO,CAAC,WAAW,CA8VrB,CAAC;AAEF,eAAO,MAAM,sBAAsB,WAC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