@centrifuge/sdk 0.0.0-alpha.2 → 0.0.0-alpha.20

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 (353) hide show
  1. package/README.md +58 -0
  2. package/dist/Centrifuge.d.ts +286 -259
  3. package/dist/Centrifuge.d.ts.map +1 -1
  4. package/dist/Centrifuge.js +538 -67
  5. package/dist/Centrifuge.js.map +1 -1
  6. package/dist/Centrifuge.test.d.ts +2 -0
  7. package/dist/Centrifuge.test.d.ts.map +1 -0
  8. package/dist/Centrifuge.test.js +487 -0
  9. package/dist/Centrifuge.test.js.map +1 -0
  10. package/dist/abi/Accounting.abi.d.ts +3 -0
  11. package/dist/abi/Accounting.abi.d.ts.map +1 -0
  12. package/dist/abi/Accounting.abi.js +33 -0
  13. package/dist/abi/Accounting.abi.js.map +1 -0
  14. package/dist/abi/AsyncRequestManager.abi.d.ts +3 -0
  15. package/dist/abi/AsyncRequestManager.abi.d.ts.map +1 -0
  16. package/dist/abi/AsyncRequestManager.abi.js +78 -0
  17. package/dist/abi/AsyncRequestManager.abi.js.map +1 -0
  18. package/dist/abi/AsyncVault.abi.d.ts +3 -0
  19. package/dist/abi/AsyncVault.abi.d.ts.map +1 -0
  20. package/dist/abi/AsyncVault.abi.js +101 -0
  21. package/dist/abi/AsyncVault.abi.js.map +1 -0
  22. package/dist/abi/BalanceSheet.abi.d.ts +3 -0
  23. package/dist/abi/BalanceSheet.abi.d.ts.map +1 -0
  24. package/dist/abi/BalanceSheet.abi.js +55 -0
  25. package/dist/abi/BalanceSheet.abi.js.map +1 -0
  26. package/dist/abi/Currency.abi.d.ts +3 -0
  27. package/dist/abi/Currency.abi.d.ts.map +1 -0
  28. package/dist/abi/Currency.abi.js +15 -0
  29. package/dist/abi/Currency.abi.js.map +1 -0
  30. package/dist/abi/Holdings.abi.d.ts +3 -0
  31. package/dist/abi/Holdings.abi.d.ts.map +1 -0
  32. package/dist/abi/Holdings.abi.js +43 -0
  33. package/dist/abi/Holdings.abi.js.map +1 -0
  34. package/dist/abi/Hub.abi.d.ts +3 -0
  35. package/dist/abi/Hub.abi.d.ts.map +1 -0
  36. package/dist/abi/Hub.abi.js +88 -0
  37. package/dist/abi/Hub.abi.js.map +1 -0
  38. package/dist/abi/HubRegistry.abi.d.ts +3 -0
  39. package/dist/abi/HubRegistry.abi.d.ts.map +1 -0
  40. package/dist/abi/HubRegistry.abi.js +39 -0
  41. package/dist/abi/HubRegistry.abi.js.map +1 -0
  42. package/dist/abi/MessageDispatcher.abi.d.ts +3 -0
  43. package/dist/abi/MessageDispatcher.abi.d.ts.map +1 -0
  44. package/dist/abi/MessageDispatcher.abi.js +49 -0
  45. package/dist/abi/MessageDispatcher.abi.js.map +1 -0
  46. package/dist/abi/MultiAdapter.abi.d.ts +3 -0
  47. package/dist/abi/MultiAdapter.abi.d.ts.map +1 -0
  48. package/dist/abi/MultiAdapter.abi.js +53 -0
  49. package/dist/abi/MultiAdapter.abi.js.map +1 -0
  50. package/dist/abi/RestrictionManager.abi.d.ts +3 -0
  51. package/dist/abi/RestrictionManager.abi.d.ts.map +1 -0
  52. package/dist/abi/RestrictionManager.abi.js +23 -0
  53. package/dist/abi/RestrictionManager.abi.js.map +1 -0
  54. package/dist/abi/ShareClassManager.abi.d.ts +3 -0
  55. package/dist/abi/ShareClassManager.abi.d.ts.map +1 -0
  56. package/dist/abi/ShareClassManager.abi.js +89 -0
  57. package/dist/abi/ShareClassManager.abi.js.map +1 -0
  58. package/dist/abi/Spoke.abi.d.ts +3 -0
  59. package/dist/abi/Spoke.abi.d.ts.map +1 -0
  60. package/dist/abi/Spoke.abi.js +90 -0
  61. package/dist/abi/Spoke.abi.js.map +1 -0
  62. package/dist/abi/SyncRequestManager.abi.d.ts +3 -0
  63. package/dist/abi/SyncRequestManager.abi.d.ts.map +1 -0
  64. package/dist/abi/SyncRequestManager.abi.js +61 -0
  65. package/dist/abi/SyncRequestManager.abi.js.map +1 -0
  66. package/dist/abi/Valuation.abi.d.ts +3 -0
  67. package/dist/abi/Valuation.abi.d.ts.map +1 -0
  68. package/dist/abi/Valuation.abi.js +2 -0
  69. package/dist/abi/Valuation.abi.js.map +1 -0
  70. package/dist/abi/VaultRouter.abi.d.ts +3 -0
  71. package/dist/abi/VaultRouter.abi.d.ts.map +1 -0
  72. package/dist/abi/VaultRouter.abi.js +51 -0
  73. package/dist/abi/VaultRouter.abi.js.map +1 -0
  74. package/dist/abi/index.d.ts +8243 -8
  75. package/dist/abi/index.d.ts.map +1 -1
  76. package/dist/abi/index.js +32 -16
  77. package/dist/abi/index.js.map +1 -1
  78. package/dist/config/chains.d.ts +41 -0
  79. package/dist/config/chains.d.ts.map +1 -1
  80. package/dist/config/chains.js +11 -2
  81. package/dist/config/chains.js.map +1 -1
  82. package/dist/config/protocol.d.ts +3 -0
  83. package/dist/config/protocol.d.ts.map +1 -0
  84. package/dist/config/protocol.js +7 -0
  85. package/dist/config/protocol.js.map +1 -0
  86. package/dist/entities/Entity.d.ts +8 -0
  87. package/dist/entities/Entity.d.ts.map +1 -0
  88. package/dist/{Entity.js → entities/Entity.js} +6 -1
  89. package/dist/entities/Entity.js.map +1 -0
  90. package/dist/entities/IndexerQueries/assetSnapshots.d.ts +69 -0
  91. package/dist/entities/IndexerQueries/assetSnapshots.d.ts.map +1 -0
  92. package/dist/entities/IndexerQueries/assetSnapshots.js +91 -0
  93. package/dist/entities/IndexerQueries/assetSnapshots.js.map +1 -0
  94. package/dist/entities/IndexerQueries/assetTransactions.d.ts +93 -0
  95. package/dist/entities/IndexerQueries/assetTransactions.d.ts.map +1 -0
  96. package/dist/entities/IndexerQueries/assetTransactions.js +75 -0
  97. package/dist/entities/IndexerQueries/assetTransactions.js.map +1 -0
  98. package/dist/entities/IndexerQueries/epochs.d.ts +45 -0
  99. package/dist/entities/IndexerQueries/epochs.d.ts.map +1 -0
  100. package/dist/entities/IndexerQueries/epochs.js +51 -0
  101. package/dist/entities/IndexerQueries/epochs.js.map +1 -0
  102. package/dist/entities/IndexerQueries/index.d.ts +40 -0
  103. package/dist/entities/IndexerQueries/index.d.ts.map +1 -0
  104. package/dist/entities/IndexerQueries/index.js +45 -0
  105. package/dist/entities/IndexerQueries/index.js.map +1 -0
  106. package/dist/entities/IndexerQueries/investorTransactions.d.ts +50 -0
  107. package/dist/entities/IndexerQueries/investorTransactions.d.ts.map +1 -0
  108. package/dist/entities/IndexerQueries/investorTransactions.js +55 -0
  109. package/dist/entities/IndexerQueries/investorTransactions.js.map +1 -0
  110. package/dist/{queries → entities/IndexerQueries}/poolFeeSnapshots.d.ts +8 -8
  111. package/dist/entities/IndexerQueries/poolFeeSnapshots.d.ts.map +1 -0
  112. package/dist/{queries → entities/IndexerQueries}/poolFeeSnapshots.js +8 -8
  113. package/dist/entities/IndexerQueries/poolFeeSnapshots.js.map +1 -0
  114. package/dist/entities/IndexerQueries/poolFeeTransactions.d.ts +34 -0
  115. package/dist/entities/IndexerQueries/poolFeeTransactions.d.ts.map +1 -0
  116. package/dist/entities/IndexerQueries/poolFeeTransactions.js +37 -0
  117. package/dist/entities/IndexerQueries/poolFeeTransactions.js.map +1 -0
  118. package/dist/{queries → entities/IndexerQueries}/poolSnapshots.d.ts +30 -24
  119. package/dist/entities/IndexerQueries/poolSnapshots.d.ts.map +1 -0
  120. package/dist/{queries → entities/IndexerQueries}/poolSnapshots.js +29 -23
  121. package/dist/entities/IndexerQueries/poolSnapshots.js.map +1 -0
  122. package/dist/entities/IndexerQueries/trancheCurrencyBalance.d.ts +76 -0
  123. package/dist/entities/IndexerQueries/trancheCurrencyBalance.d.ts.map +1 -0
  124. package/dist/entities/IndexerQueries/trancheCurrencyBalance.js +63 -0
  125. package/dist/entities/IndexerQueries/trancheCurrencyBalance.js.map +1 -0
  126. package/dist/{queries → entities/IndexerQueries}/trancheSnapshots.d.ts +7 -7
  127. package/dist/entities/IndexerQueries/trancheSnapshots.d.ts.map +1 -0
  128. package/dist/{queries → entities/IndexerQueries}/trancheSnapshots.js +7 -7
  129. package/dist/entities/IndexerQueries/trancheSnapshots.js.map +1 -0
  130. package/dist/entities/Investor.d.ts +37 -0
  131. package/dist/entities/Investor.d.ts.map +1 -0
  132. package/dist/entities/Investor.js +29 -0
  133. package/dist/entities/Investor.js.map +1 -0
  134. package/dist/entities/Investor.test.d.ts +2 -0
  135. package/dist/entities/Investor.test.d.ts.map +1 -0
  136. package/dist/entities/Investor.test.js +16 -0
  137. package/dist/entities/Investor.test.js.map +1 -0
  138. package/dist/entities/Pool.d.ts +89 -0
  139. package/dist/entities/Pool.d.ts.map +1 -0
  140. package/dist/entities/Pool.js +254 -0
  141. package/dist/entities/Pool.js.map +1 -0
  142. package/dist/entities/Pool.test.d.ts +2 -0
  143. package/dist/entities/Pool.test.d.ts.map +1 -0
  144. package/dist/entities/Pool.test.js +82 -0
  145. package/dist/entities/Pool.test.js.map +1 -0
  146. package/dist/entities/PoolNetwork.d.ts +63 -0
  147. package/dist/entities/PoolNetwork.d.ts.map +1 -0
  148. package/dist/entities/PoolNetwork.js +274 -0
  149. package/dist/entities/PoolNetwork.js.map +1 -0
  150. package/dist/entities/PoolNetwork.test.d.ts +2 -0
  151. package/dist/entities/PoolNetwork.test.d.ts.map +1 -0
  152. package/dist/entities/PoolNetwork.test.js +61 -0
  153. package/dist/entities/PoolNetwork.test.js.map +1 -0
  154. package/dist/entities/Reports/Processor.d.ts +46 -0
  155. package/dist/entities/Reports/Processor.d.ts.map +1 -0
  156. package/dist/entities/Reports/Processor.js +471 -0
  157. package/dist/entities/Reports/Processor.js.map +1 -0
  158. package/dist/entities/Reports/Processor.test.d.ts +2 -0
  159. package/dist/entities/Reports/Processor.test.d.ts.map +1 -0
  160. package/dist/entities/Reports/Processor.test.js +767 -0
  161. package/dist/entities/Reports/Processor.test.js.map +1 -0
  162. package/dist/entities/Reports/Reports.test.d.ts +2 -0
  163. package/dist/entities/Reports/Reports.test.d.ts.map +1 -0
  164. package/dist/entities/Reports/Reports.test.js +559 -0
  165. package/dist/entities/Reports/Reports.test.js.map +1 -0
  166. package/dist/entities/Reports/index.d.ts +21 -0
  167. package/dist/entities/Reports/index.d.ts.map +1 -0
  168. package/dist/entities/Reports/index.js +144 -0
  169. package/dist/entities/Reports/index.js.map +1 -0
  170. package/dist/entities/ShareClass.d.ts +121 -0
  171. package/dist/entities/ShareClass.d.ts.map +1 -0
  172. package/dist/entities/ShareClass.js +679 -0
  173. package/dist/entities/ShareClass.js.map +1 -0
  174. package/dist/entities/ShareClass.test.d.ts +2 -0
  175. package/dist/entities/ShareClass.test.d.ts.map +1 -0
  176. package/dist/entities/ShareClass.test.js +126 -0
  177. package/dist/entities/ShareClass.test.js.map +1 -0
  178. package/dist/entities/Vault.d.ts +85 -0
  179. package/dist/entities/Vault.d.ts.map +1 -0
  180. package/dist/{Vault.js → entities/Vault.js} +217 -145
  181. package/dist/entities/Vault.js.map +1 -0
  182. package/dist/entities/Vault.test.d.ts +2 -0
  183. package/dist/entities/Vault.test.d.ts.map +1 -0
  184. package/dist/entities/Vault.test.js +265 -0
  185. package/dist/entities/Vault.test.js.map +1 -0
  186. package/dist/index.d.ts +16 -6
  187. package/dist/index.d.ts.map +1 -1
  188. package/dist/index.js +10 -6
  189. package/dist/index.js.map +1 -1
  190. package/dist/tests/mocks/mockAssetSnapshots.d.ts +3 -0
  191. package/dist/tests/mocks/mockAssetSnapshots.d.ts.map +1 -0
  192. package/dist/tests/mocks/mockAssetSnapshots.js +56 -0
  193. package/dist/tests/mocks/mockAssetSnapshots.js.map +1 -0
  194. package/dist/tests/mocks/mockAssetTransactions.d.ts +3 -0
  195. package/dist/tests/mocks/mockAssetTransactions.d.ts.map +1 -0
  196. package/dist/tests/mocks/mockAssetTransactions.js +86 -0
  197. package/dist/tests/mocks/mockAssetTransactions.js.map +1 -0
  198. package/dist/tests/mocks/mockEpochs.d.ts +3 -0
  199. package/dist/tests/mocks/mockEpochs.d.ts.map +1 -0
  200. package/dist/tests/mocks/mockEpochs.js +26 -0
  201. package/dist/tests/mocks/mockEpochs.js.map +1 -0
  202. package/dist/tests/mocks/mockInvestorCurrencyBalance.d.ts +3 -0
  203. package/dist/tests/mocks/mockInvestorCurrencyBalance.d.ts.map +1 -0
  204. package/dist/tests/mocks/mockInvestorCurrencyBalance.js +29 -0
  205. package/dist/tests/mocks/mockInvestorCurrencyBalance.js.map +1 -0
  206. package/dist/tests/mocks/mockInvestorTransactions.d.ts +3 -0
  207. package/dist/tests/mocks/mockInvestorTransactions.d.ts.map +1 -0
  208. package/dist/tests/mocks/mockInvestorTransactions.js +35 -0
  209. package/dist/tests/mocks/mockInvestorTransactions.js.map +1 -0
  210. package/dist/tests/mocks/mockPoolFeeSnapshot.d.ts +1 -1
  211. package/dist/tests/mocks/mockPoolFeeSnapshot.d.ts.map +1 -1
  212. package/dist/tests/mocks/mockPoolFeeSnapshot.js +29 -29
  213. package/dist/tests/mocks/mockPoolFeeSnapshot.js.map +1 -1
  214. package/dist/tests/mocks/mockPoolFeeTransactions.d.ts +11 -0
  215. package/dist/tests/mocks/mockPoolFeeTransactions.d.ts.map +1 -0
  216. package/dist/tests/mocks/mockPoolFeeTransactions.js +20 -0
  217. package/dist/tests/mocks/mockPoolFeeTransactions.js.map +1 -0
  218. package/dist/tests/mocks/mockPoolMetadata.d.ts.map +1 -1
  219. package/dist/tests/mocks/mockPoolMetadata.js +5 -15
  220. package/dist/tests/mocks/mockPoolMetadata.js.map +1 -1
  221. package/dist/tests/mocks/mockPoolSnapshots.d.ts +1 -1
  222. package/dist/tests/mocks/mockPoolSnapshots.d.ts.map +1 -1
  223. package/dist/tests/mocks/mockPoolSnapshots.js +47 -45
  224. package/dist/tests/mocks/mockPoolSnapshots.js.map +1 -1
  225. package/dist/tests/mocks/mockTrancheSnapshots.d.ts +1 -1
  226. package/dist/tests/mocks/mockTrancheSnapshots.d.ts.map +1 -1
  227. package/dist/tests/mocks/mockTrancheSnapshots.js +21 -21
  228. package/dist/tests/mocks/mockTrancheSnapshots.js.map +1 -1
  229. package/dist/tests/setup.d.ts.map +1 -1
  230. package/dist/tests/setup.js +3 -2
  231. package/dist/tests/setup.js.map +1 -1
  232. package/dist/tests/tenderly.js +1 -1
  233. package/dist/tests/tenderly.js.map +1 -1
  234. package/dist/tests/utils.d.ts +3 -0
  235. package/dist/tests/utils.d.ts.map +1 -0
  236. package/dist/tests/utils.js +4 -0
  237. package/dist/tests/utils.js.map +1 -0
  238. package/dist/types/holdings.d.ts +9 -0
  239. package/dist/types/holdings.d.ts.map +1 -0
  240. package/dist/types/holdings.js +10 -0
  241. package/dist/types/holdings.js.map +1 -0
  242. package/dist/types/index.d.ts +65 -0
  243. package/dist/types/index.d.ts.map +1 -1
  244. package/dist/types/poolInput.d.ts +71 -0
  245. package/dist/types/poolInput.d.ts.map +1 -0
  246. package/dist/types/poolInput.js +2 -0
  247. package/dist/types/poolInput.js.map +1 -0
  248. package/dist/types/poolMetadata.d.ts +13 -12
  249. package/dist/types/poolMetadata.d.ts.map +1 -1
  250. package/dist/types/reports.d.ts +336 -0
  251. package/dist/types/reports.d.ts.map +1 -0
  252. package/dist/types/reports.js +2 -0
  253. package/dist/types/reports.js.map +1 -0
  254. package/dist/types/transaction.d.ts +5 -0
  255. package/dist/types/transaction.d.ts.map +1 -1
  256. package/dist/utils/BigInt.d.ts +15 -34
  257. package/dist/utils/BigInt.d.ts.map +1 -1
  258. package/dist/utils/BigInt.js +16 -23
  259. package/dist/utils/BigInt.js.map +1 -1
  260. package/dist/utils/BigInt.test.d.ts +2 -0
  261. package/dist/utils/BigInt.test.d.ts.map +1 -0
  262. package/dist/utils/BigInt.test.js +298 -0
  263. package/dist/utils/BigInt.test.js.map +1 -0
  264. package/dist/utils/currencies.d.ts +5 -0
  265. package/dist/utils/currencies.d.ts.map +1 -0
  266. package/dist/utils/currencies.js +7 -0
  267. package/dist/utils/currencies.js.map +1 -0
  268. package/dist/utils/date.d.ts.map +1 -1
  269. package/dist/utils/date.js +5 -4
  270. package/dist/utils/date.js.map +1 -1
  271. package/dist/utils/decimal.d.ts +2 -2
  272. package/dist/utils/decimal.d.ts.map +1 -1
  273. package/dist/utils/decimal.js.map +1 -1
  274. package/dist/utils/index.d.ts +4 -0
  275. package/dist/utils/index.d.ts.map +1 -0
  276. package/dist/utils/index.js +24 -0
  277. package/dist/utils/index.js.map +1 -0
  278. package/dist/utils/ipfs.d.ts +7 -0
  279. package/dist/utils/ipfs.d.ts.map +1 -0
  280. package/dist/utils/ipfs.js +64 -0
  281. package/dist/utils/ipfs.js.map +1 -0
  282. package/dist/utils/ipfs.test.d.ts +2 -0
  283. package/dist/utils/ipfs.test.d.ts.map +1 -0
  284. package/dist/utils/ipfs.test.js +54 -0
  285. package/dist/utils/ipfs.test.js.map +1 -0
  286. package/dist/utils/rx.d.ts +1 -1
  287. package/dist/utils/rx.d.ts.map +1 -1
  288. package/dist/utils/rx.js +4 -0
  289. package/dist/utils/rx.js.map +1 -1
  290. package/dist/utils/transaction.d.ts.map +1 -1
  291. package/dist/utils/transaction.js +21 -5
  292. package/dist/utils/transaction.js.map +1 -1
  293. package/dist/utils/types.d.ts +39 -0
  294. package/dist/utils/types.d.ts.map +1 -0
  295. package/dist/utils/types.js +89 -0
  296. package/dist/utils/types.js.map +1 -0
  297. package/dist/utils/types.test.d.ts +2 -0
  298. package/dist/utils/types.test.d.ts.map +1 -0
  299. package/dist/utils/types.test.js +89 -0
  300. package/dist/utils/types.test.js.map +1 -0
  301. package/package.json +11 -6
  302. package/dist/Account.d.ts +0 -11
  303. package/dist/Account.d.ts.map +0 -1
  304. package/dist/Account.js +0 -46
  305. package/dist/Account.js.map +0 -1
  306. package/dist/Entity.d.ts +0 -12
  307. package/dist/Entity.d.ts.map +0 -1
  308. package/dist/Entity.js.map +0 -1
  309. package/dist/Pool.d.ts +0 -27
  310. package/dist/Pool.d.ts.map +0 -1
  311. package/dist/Pool.js +0 -76
  312. package/dist/Pool.js.map +0 -1
  313. package/dist/PoolNetwork.d.ts +0 -82
  314. package/dist/PoolNetwork.d.ts.map +0 -1
  315. package/dist/PoolNetwork.js +0 -235
  316. package/dist/PoolNetwork.js.map +0 -1
  317. package/dist/Reports/Processor.d.ts +0 -38
  318. package/dist/Reports/Processor.d.ts.map +0 -1
  319. package/dist/Reports/Processor.js +0 -167
  320. package/dist/Reports/Processor.js.map +0 -1
  321. package/dist/Reports/index.d.ts +0 -24
  322. package/dist/Reports/index.d.ts.map +0 -1
  323. package/dist/Reports/index.js +0 -68
  324. package/dist/Reports/index.js.map +0 -1
  325. package/dist/Reports/types.d.ts +0 -102
  326. package/dist/Reports/types.d.ts.map +0 -1
  327. package/dist/Reports/types.js +0 -2
  328. package/dist/Reports/types.js.map +0 -1
  329. package/dist/Vault.d.ts +0 -96
  330. package/dist/Vault.d.ts.map +0 -1
  331. package/dist/Vault.js.map +0 -1
  332. package/dist/abi/CentrifugeRouter.abi.json +0 -43
  333. package/dist/abi/Currency.abi.json +0 -14
  334. package/dist/abi/Gateway.abi.json +0 -1
  335. package/dist/abi/InvestmentManager.abi.json +0 -4
  336. package/dist/abi/LiquidityPool.abi.json +0 -79
  337. package/dist/abi/PoolManager.abi.json +0 -55
  338. package/dist/abi/RestrictionManager.abi.json +0 -22
  339. package/dist/abi/Router.abi.json +0 -1
  340. package/dist/config/lp.d.ts +0 -17
  341. package/dist/config/lp.d.ts.map +0 -1
  342. package/dist/config/lp.js +0 -35
  343. package/dist/config/lp.js.map +0 -1
  344. package/dist/queries/poolFeeSnapshots.d.ts.map +0 -1
  345. package/dist/queries/poolFeeSnapshots.js.map +0 -1
  346. package/dist/queries/poolSnapshots.d.ts.map +0 -1
  347. package/dist/queries/poolSnapshots.js.map +0 -1
  348. package/dist/queries/trancheSnapshots.d.ts.map +0 -1
  349. package/dist/queries/trancheSnapshots.js.map +0 -1
  350. package/dist/utils/pinToApi.d.ts +0 -2
  351. package/dist/utils/pinToApi.d.ts.map +0 -1
  352. package/dist/utils/pinToApi.js +0 -10
  353. package/dist/utils/pinToApi.js.map +0 -1
@@ -0,0 +1,679 @@
1
+ import { catchError, combineLatest, defer, EMPTY, expand, filter, map, of, switchMap } from 'rxjs';
2
+ import { encodeFunctionData, encodePacked, getContract, parseAbi } from 'viem';
3
+ import { ABI } from '../abi/index.js';
4
+ import { AccountType } from '../types/holdings.js';
5
+ import { Balance, Price } from '../utils/BigInt.js';
6
+ import { addressToBytes32, randomUint } from '../utils/index.js';
7
+ import { repeatOnEvents } from '../utils/rx.js';
8
+ import { doTransaction } from '../utils/transaction.js';
9
+ import { AssetId, ShareClassId } from '../utils/types.js';
10
+ import { Entity } from './Entity.js';
11
+ import { PoolNetwork } from './PoolNetwork.js';
12
+ /**
13
+ * Query and interact with a share class, which allows querying total issuance, NAV per share,
14
+ * and allows interactions related to asynchronous deposits and redemptions.
15
+ */
16
+ export class ShareClass extends Entity {
17
+ pool;
18
+ id;
19
+ /** @internal */
20
+ constructor(_root, pool, id) {
21
+ const _id = id instanceof ShareClassId ? id : new ShareClassId(id);
22
+ super(_root, ['shareclass', _id.toString()]);
23
+ this.pool = pool;
24
+ this.id = _id;
25
+ }
26
+ /**
27
+ * Query the details of the share class.
28
+ * @returns The details of the share class, including name, symbol, total issuance, and NAV per share.
29
+ */
30
+ details() {
31
+ return this._query(null, () => combineLatest([this._metrics(), this._metadata()]).pipe(map(([metrics, metadata]) => {
32
+ return {
33
+ id: this.id,
34
+ name: metadata.name,
35
+ symbol: metadata.symbol,
36
+ totalIssuance: metrics.totalIssuance,
37
+ pricePerShare: metrics.pricePerShare,
38
+ nav: metrics.totalIssuance.mul(metrics.pricePerShare),
39
+ };
40
+ })));
41
+ }
42
+ navPerNetwork() {
43
+ return this._root._queryIndexer(`query ($scId: String!) {
44
+ tokenInstances(where: { tokenId: $scId }) {
45
+ items {
46
+ totalIssuance
47
+ tokenPrice
48
+ blockchain {
49
+ id
50
+ }
51
+ }
52
+ }
53
+ }`, { scId: this.id.raw }, (data) => data.tokenInstances.items.map((item) => ({
54
+ chainId: item.blockchain.id,
55
+ totalIssuance: new Balance(item.totalIssuance, 18), // TODO: Replace with pool currency decimals
56
+ pricePerShare: new Price(item.tokenPrice),
57
+ nav: new Balance(item.totalIssuance, 18).mul(new Price(item.tokenPrice)),
58
+ })));
59
+ }
60
+ /**
61
+ * Query the vaults of the share class.
62
+ * @param chainId The chain ID to query the vaults on.
63
+ * @returns The vaults of the share class on the given chain.
64
+ */
65
+ vaults(chainId) {
66
+ return this._query(null, () => new PoolNetwork(this._root, this.pool, chainId).vaults(this.id));
67
+ }
68
+ holdings() {
69
+ return this._query(null, () => this._root
70
+ ._queryIndexer(`query ($scId: String!) {
71
+ holdings(where: { tokenId: $scId }) {
72
+ items {
73
+ assetRegistrationId
74
+ }
75
+ }
76
+ }`, {
77
+ scId: this.id.raw,
78
+ })
79
+ .pipe(switchMap((res) => combineLatest(res.holdings.items.map((holding) => {
80
+ const assetId = new AssetId(holding.assetRegistrationId);
81
+ return this.holding(assetId);
82
+ })))));
83
+ }
84
+ /**
85
+ * Query a holding of the share class.
86
+ * @param assetId The asset ID
87
+ * @returns The details of the holding
88
+ */
89
+ holding(assetId) {
90
+ return this._query(['holding', assetId.toString()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ holdings: holdingsAddr, hubRegistry }) => defer(async () => {
91
+ const holdings = getContract({
92
+ address: holdingsAddr,
93
+ abi: ABI.Holdings,
94
+ client: this._root.getClient(this.pool.chainId),
95
+ });
96
+ const [valuation, amount, value, assetDecimals, isLiability, ...accounts] = await Promise.all([
97
+ holdings.read.valuation([this.pool.id.raw, this.id.raw, assetId.raw]),
98
+ holdings.read.amount([this.pool.id.raw, this.id.raw, assetId.raw]),
99
+ holdings.read.value([this.pool.id.raw, this.id.raw, assetId.raw]),
100
+ this._root.getClient(this.pool.chainId).readContract({
101
+ address: hubRegistry,
102
+ // Use inline ABI because of function overload
103
+ abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
104
+ functionName: 'decimals',
105
+ args: [assetId.raw],
106
+ }),
107
+ holdings.read.isLiability([this.pool.id.raw, this.id.raw, assetId.raw]),
108
+ ...[
109
+ AccountType.Asset,
110
+ AccountType.Equity,
111
+ AccountType.Loss,
112
+ AccountType.Gain,
113
+ AccountType.Expense,
114
+ AccountType.Liability,
115
+ ].map((kind) => holdings.read.accountId([this.pool.id.raw, this.id.raw, assetId.raw, kind])),
116
+ ]);
117
+ return {
118
+ assetId,
119
+ assetDecimals,
120
+ valuation,
121
+ amount: new Balance(amount, assetDecimals),
122
+ value: new Balance(value, 18), // TODO: Replace with pool currency decimals
123
+ isLiability,
124
+ accounts: {
125
+ [AccountType.Asset]: accounts[0] || null,
126
+ [AccountType.Equity]: accounts[1] || null,
127
+ [AccountType.Loss]: accounts[2] || null,
128
+ [AccountType.Gain]: accounts[3] || null,
129
+ [AccountType.Expense]: accounts[4] || null,
130
+ [AccountType.Liability]: accounts[5] || null,
131
+ },
132
+ };
133
+ }).pipe(repeatOnEvents(this._root, {
134
+ address: holdingsAddr,
135
+ abi: ABI.Holdings,
136
+ eventName: ['Increase', 'Decrease', 'Update', 'UpdateValuation'],
137
+ filter: (events) => {
138
+ return events.some((event) => {
139
+ return event.args.scId === this.id && event.args.assetId === assetId.raw;
140
+ });
141
+ },
142
+ }, this.pool.chainId)))));
143
+ }
144
+ investorOrder(assetId, investor) {
145
+ return this._query(['maxClaims', assetId.toString(), investor.toLowerCase()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
146
+ const contract = getContract({
147
+ address: shareClassManager,
148
+ abi: ABI.ShareClassManager,
149
+ client: this._root.getClient(this.pool.chainId),
150
+ });
151
+ const [maxDepositClaims, maxRedeemClaims] = await Promise.all([
152
+ contract.read.maxDepositClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
153
+ contract.read.maxRedeemClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
154
+ ]);
155
+ return {
156
+ maxDepositClaims,
157
+ maxRedeemClaims,
158
+ };
159
+ }).pipe(repeatOnEvents(this._root, {
160
+ address: shareClassManager,
161
+ abi: ABI.ShareClassManager,
162
+ eventName: [
163
+ 'UpdateDepositRequest',
164
+ 'UpdateRedeemRequest',
165
+ 'ClaimDeposit',
166
+ 'ClaimRedeem',
167
+ 'ApproveDeposits',
168
+ 'ApproveRedeems',
169
+ ],
170
+ filter: (events) => {
171
+ return events.some((event) => event.args.scId === this.id.raw &&
172
+ (event.args.depositAssetId === assetId.raw || event.args.payoutAssetId === assetId.raw));
173
+ },
174
+ }, this.pool.chainId)))));
175
+ }
176
+ /**
177
+ * Check if an address is a member of the share class.
178
+ * @param address Address to check
179
+ * @param chainId Chain ID of the network on which to check the member
180
+ */
181
+ member(address, chainId) {
182
+ const addr = address.toLowerCase();
183
+ return this._query(['member', addr, chainId], () => combineLatest([this._share(chainId), this._restrictionManager(chainId)]).pipe(switchMap(([share, restrictionManager]) => defer(async () => {
184
+ const res = await this._root.getClient(this.pool.chainId).readContract({
185
+ address: restrictionManager,
186
+ abi: ABI.RestrictionManager,
187
+ functionName: 'isMember',
188
+ args: [share, addr],
189
+ });
190
+ return {
191
+ isMember: res[0],
192
+ validUntil: new Date(Number(res[1]) * 1000),
193
+ };
194
+ }).pipe(repeatOnEvents(this._root, {
195
+ address: restrictionManager,
196
+ abi: ABI.RestrictionManager,
197
+ eventName: 'UpdateMember',
198
+ filter: (events) => events.some((event) => event.args.user?.toLowerCase() === addr && event.args.token?.toLowerCase() === share),
199
+ }, chainId), catchError(() => {
200
+ // Freeze-only hook doesn't have isMember function
201
+ return of({
202
+ isMember: false,
203
+ validUntil: new Date(0),
204
+ });
205
+ })))));
206
+ }
207
+ /**
208
+ * Create a holding for a registered asset in the share class.
209
+ * @param assetId - Asset ID of the asset to create a holding for
210
+ * @param valuation - Valuation of the asset
211
+ * @param isLiability - Whether the holding is a liability or not
212
+ * @param accounts - Accounts to use for the holding. An asset or expense account will be created if not provided.
213
+ * Other accounts are expected to be provided or to exist in the pool metadata.
214
+ */
215
+ createHolding(assetId, valuation, isLiability, accounts) {
216
+ const self = this;
217
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
218
+ const [{ hub }, metadata] = await Promise.all([
219
+ self._root._protocolAddresses(self.pool.chainId),
220
+ self.pool.metadata(),
221
+ ]);
222
+ let tx;
223
+ if (isLiability) {
224
+ const expenseAccount = accounts[AccountType.Expense] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.expense;
225
+ const liabilityAccount = accounts[AccountType.Liability] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.liability;
226
+ if (liabilityAccount === undefined) {
227
+ throw new Error('Missing required accounts for liability creation');
228
+ }
229
+ if (expenseAccount) {
230
+ tx = walletClient.writeContract({
231
+ address: hub,
232
+ abi: ABI.Hub,
233
+ functionName: 'initializeLiability',
234
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, expenseAccount, liabilityAccount],
235
+ });
236
+ }
237
+ else {
238
+ const newExpenseAccount = await self._getFreeAccountId();
239
+ const createAccountData = encodeFunctionData({
240
+ abi: ABI.Hub,
241
+ functionName: 'createAccount',
242
+ args: [self.pool.id.raw, newExpenseAccount, true],
243
+ });
244
+ const initHoldingData = encodeFunctionData({
245
+ abi: ABI.Hub,
246
+ functionName: 'initializeLiability',
247
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, newExpenseAccount, liabilityAccount],
248
+ });
249
+ tx = walletClient.writeContract({
250
+ address: hub,
251
+ abi: ABI.Hub,
252
+ functionName: 'multicall',
253
+ args: [[createAccountData, initHoldingData]],
254
+ });
255
+ }
256
+ }
257
+ else {
258
+ const assetAccount = accounts[AccountType.Asset] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.asset;
259
+ const equityAccount = accounts[AccountType.Equity] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.equity;
260
+ const gainAccount = accounts[AccountType.Gain] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.gain;
261
+ const lossAccount = accounts[AccountType.Loss] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.loss;
262
+ if (equityAccount === undefined || gainAccount === undefined || lossAccount === undefined) {
263
+ throw new Error('Missing required accounts for holding creation');
264
+ }
265
+ if (assetAccount) {
266
+ tx = walletClient.writeContract({
267
+ address: hub,
268
+ abi: ABI.Hub,
269
+ functionName: 'initializeHolding',
270
+ args: [
271
+ self.pool.id.raw,
272
+ self.id.raw,
273
+ assetId.raw,
274
+ valuation,
275
+ assetAccount,
276
+ equityAccount,
277
+ gainAccount,
278
+ lossAccount,
279
+ ],
280
+ });
281
+ }
282
+ else {
283
+ const newAssetAccount = await self._getFreeAccountId();
284
+ const createAccountData = encodeFunctionData({
285
+ abi: ABI.Hub,
286
+ functionName: 'createAccount',
287
+ args: [self.pool.id.raw, newAssetAccount, false],
288
+ });
289
+ const initHoldingData = encodeFunctionData({
290
+ abi: ABI.Hub,
291
+ functionName: 'initializeHolding',
292
+ args: [
293
+ self.pool.id.raw,
294
+ self.id.raw,
295
+ assetId.raw,
296
+ valuation,
297
+ newAssetAccount,
298
+ equityAccount,
299
+ gainAccount,
300
+ lossAccount,
301
+ ],
302
+ });
303
+ tx = walletClient.writeContract({
304
+ address: hub,
305
+ abi: ABI.Hub,
306
+ functionName: 'multicall',
307
+ args: [[createAccountData, initHoldingData]],
308
+ });
309
+ }
310
+ }
311
+ yield* doTransaction('Create holding', publicClient, () => tx);
312
+ }, this.pool.chainId);
313
+ }
314
+ updateSharePrice(pricePerShare) {
315
+ const self = this;
316
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
317
+ const { hub } = await self._root._protocolAddresses(self.pool.chainId);
318
+ yield* doTransaction('Update price', publicClient, () => walletClient.writeContract({
319
+ address: hub,
320
+ abi: ABI.Hub,
321
+ functionName: 'updateSharePrice',
322
+ args: [self.pool.id.raw, self.id.raw, pricePerShare.toBigInt()],
323
+ }));
324
+ }, this.pool.chainId);
325
+ }
326
+ setMaxAssetPriceAge(assetId, maxPriceAge) {
327
+ const self = this;
328
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
329
+ const { hub } = await self._root._protocolAddresses(self.pool.chainId);
330
+ yield* doTransaction('Set max asset price age', publicClient, () => walletClient.writeContract({
331
+ address: hub,
332
+ abi: ABI.Hub,
333
+ functionName: 'setMaxAssetPriceAge',
334
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, BigInt(maxPriceAge)],
335
+ }));
336
+ }, this.pool.chainId);
337
+ }
338
+ setMaxSharePriceAge(chainId, maxPriceAge) {
339
+ const self = this;
340
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
341
+ const [{ hub }, id] = await Promise.all([
342
+ self._root._protocolAddresses(self.pool.chainId),
343
+ self._root.id(chainId),
344
+ ]);
345
+ yield* doTransaction('Set max share price age', publicClient, () => walletClient.writeContract({
346
+ address: hub,
347
+ abi: ABI.Hub,
348
+ functionName: 'setMaxSharePriceAge',
349
+ args: [id, self.pool.id.raw, self.id.raw, BigInt(maxPriceAge)],
350
+ }));
351
+ }, this.pool.chainId);
352
+ }
353
+ notifyAssetPrice(assetId) {
354
+ const self = this;
355
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
356
+ const { hub } = await self._root._protocolAddresses(self.pool.chainId);
357
+ yield* doTransaction('Notify asset price', publicClient, () => walletClient.writeContract({
358
+ address: hub,
359
+ abi: ABI.Hub,
360
+ functionName: 'notifyAssetPrice',
361
+ args: [self.pool.id.raw, self.id.raw, assetId.raw],
362
+ }));
363
+ }, this.pool.chainId);
364
+ }
365
+ notifySharePrice(chainId) {
366
+ const self = this;
367
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
368
+ const [{ hub }, id] = await Promise.all([
369
+ self._root._protocolAddresses(self.pool.chainId),
370
+ self._root.id(chainId),
371
+ ]);
372
+ yield* doTransaction('Notify share price', publicClient, () => walletClient.writeContract({
373
+ address: hub,
374
+ abi: ABI.Hub,
375
+ functionName: 'notifySharePrice',
376
+ args: [self.pool.id.raw, self.id.raw, id],
377
+ }));
378
+ }, this.pool.chainId);
379
+ }
380
+ approveDeposits(assetId, assetAmount, pricePerShare) {
381
+ const self = this;
382
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
383
+ const [{ hub }, epoch, estimate] = await Promise.all([
384
+ self._root._protocolAddresses(self.pool.chainId),
385
+ self._epoch(assetId),
386
+ self._root._estimate(self.pool.chainId, { centId: assetId.centrifugeId }),
387
+ ]);
388
+ // TODO: Get asset decimals and throw if mismatch with assetAmount decimals
389
+ // const updateAssetData = encodeFunctionData({
390
+ // abi: ABI.Hub,
391
+ // functionName: 'notifyAssetPrice',
392
+ // args: [self.pool.id.raw, self.id.raw, assetId.raw],
393
+ // })
394
+ // TODO: Remove when BalanceSheet bug is fixed
395
+ const updateShareData = encodeFunctionData({
396
+ abi: ABI.Hub,
397
+ functionName: 'notifySharePrice',
398
+ args: [self.pool.id.raw, self.id.raw, 1],
399
+ });
400
+ const approveData = encodeFunctionData({
401
+ abi: ABI.Hub,
402
+ functionName: 'approveDeposits',
403
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, epoch.depositEpoch, assetAmount.toBigInt()],
404
+ });
405
+ const issueData = encodeFunctionData({
406
+ abi: ABI.Hub,
407
+ functionName: 'issueShares',
408
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, epoch.issueEpoch, pricePerShare.toBigInt()],
409
+ });
410
+ yield* doTransaction('Approve deposits', publicClient, () => walletClient.writeContract({
411
+ address: hub,
412
+ abi: ABI.Hub,
413
+ functionName: 'multicall',
414
+ args: [
415
+ [
416
+ //updateAssetData,
417
+ updateShareData,
418
+ approveData,
419
+ issueData,
420
+ ],
421
+ ],
422
+ value: estimate * 3n, // for 3 messages
423
+ }));
424
+ }, this.pool.chainId);
425
+ }
426
+ approveRedeems(assetId, shareAmount, pricePerShare) {
427
+ const self = this;
428
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
429
+ const [{ hub }, epoch, estimate] = await Promise.all([
430
+ self._root._protocolAddresses(self.pool.chainId),
431
+ self._epoch(assetId),
432
+ self._root._estimate(self.pool.chainId, { centId: assetId.centrifugeId }),
433
+ ]);
434
+ // TODO: Get share decimals and throw if mismatch with shareAmount decimals
435
+ // TODO: Remove when BalanceSheet bug is fixed
436
+ const updateShareData = encodeFunctionData({
437
+ abi: ABI.Hub,
438
+ functionName: 'notifySharePrice',
439
+ args: [self.pool.id.raw, self.id.raw, 1],
440
+ });
441
+ const approveData = encodeFunctionData({
442
+ abi: ABI.Hub,
443
+ functionName: 'approveRedeems',
444
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, epoch.redeemEpoch, shareAmount.toBigInt()],
445
+ });
446
+ const issueData = encodeFunctionData({
447
+ abi: ABI.Hub,
448
+ functionName: 'revokeShares',
449
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, epoch.revokeEpoch, pricePerShare.toBigInt()],
450
+ });
451
+ yield* doTransaction('Approve redeems', publicClient, () => walletClient.writeContract({
452
+ address: hub,
453
+ abi: ABI.Hub,
454
+ functionName: 'multicall',
455
+ args: [[updateShareData, approveData, issueData]],
456
+ value: estimate * 3n, // for 3 messages
457
+ }));
458
+ }, this.pool.chainId);
459
+ }
460
+ claimDeposit(assetId, investor) {
461
+ const self = this;
462
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
463
+ const [{ hub }, investorOrder, estimate] = await Promise.all([
464
+ self._root._protocolAddresses(self.pool.chainId),
465
+ self.investorOrder(assetId, investor),
466
+ self._root._estimate(self.pool.chainId, { centId: assetId.centrifugeId }),
467
+ ]);
468
+ yield* doTransaction('Claim deposit', publicClient, () => walletClient.writeContract({
469
+ address: hub,
470
+ abi: ABI.Hub,
471
+ functionName: 'notifyDeposit',
472
+ args: [
473
+ self.pool.id.raw,
474
+ self.id.raw,
475
+ assetId.raw,
476
+ addressToBytes32(investor),
477
+ investorOrder.maxDepositClaims,
478
+ ],
479
+ value: estimate,
480
+ }));
481
+ }, this.pool.chainId);
482
+ }
483
+ claimRedeem(assetId, investor) {
484
+ const self = this;
485
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
486
+ const [{ hub }, investorOrder, estimate] = await Promise.all([
487
+ self._root._protocolAddresses(self.pool.chainId),
488
+ self.investorOrder(assetId, investor),
489
+ self._root._estimate(self.pool.chainId, { centId: assetId.centrifugeId }),
490
+ ]);
491
+ yield* doTransaction('Claim redeem', publicClient, () => walletClient.writeContract({
492
+ address: hub,
493
+ abi: ABI.Hub,
494
+ functionName: 'notifyRedeem',
495
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, addressToBytes32(investor), investorOrder.maxRedeemClaims],
496
+ value: estimate,
497
+ }));
498
+ }, this.pool.chainId);
499
+ }
500
+ /**
501
+ * Update a member of the share class.
502
+ * @param address Address of the investor
503
+ * @param validUntil Time in seconds from Unix epoch until the investor is valid
504
+ * @param chainId Chain ID of the network on which to update the member
505
+ */
506
+ updateMember(address, validUntil, chainId) {
507
+ const self = this;
508
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
509
+ const [{ hub }, id, estimate] = await Promise.all([
510
+ self._root._protocolAddresses(self.pool.chainId),
511
+ self._root.id(chainId),
512
+ self._root._estimate(self.pool.chainId, { chainId }),
513
+ ]);
514
+ const payload = encodePacked(['uint8', 'bytes32', 'uint64'], [/* UpdateRestrictionType.Member */ 1, addressToBytes32(address), BigInt(validUntil)]);
515
+ yield* doTransaction('Update restriction', publicClient, () => walletClient.writeContract({
516
+ address: hub,
517
+ abi: ABI.Hub,
518
+ functionName: 'updateRestriction',
519
+ args: [self.pool.id.raw, self.id.raw, id, payload, 15000000n],
520
+ value: estimate,
521
+ }));
522
+ }, this.pool.chainId);
523
+ }
524
+ /** @internal */
525
+ _metadata() {
526
+ return this._query(['metadata'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
527
+ const [name, symbol] = await this._root.getClient(this.pool.chainId).readContract({
528
+ address: shareClassManager,
529
+ abi: ABI.ShareClassManager,
530
+ functionName: 'metadata',
531
+ args: [this.id.raw],
532
+ });
533
+ return {
534
+ name,
535
+ symbol,
536
+ };
537
+ }).pipe(repeatOnEvents(this._root, {
538
+ address: shareClassManager,
539
+ abi: ABI.ShareClassManager,
540
+ eventName: 'UpdateMetadata',
541
+ filter: (events) => {
542
+ return events.some((event) => {
543
+ return event.args.scId === this.id;
544
+ });
545
+ },
546
+ }, this.pool.chainId)))));
547
+ }
548
+ /** @internal */
549
+ _metrics() {
550
+ return this._query(['metrics'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
551
+ const [totalIssuance, pricePerShare] = await this._root.getClient(this.pool.chainId).readContract({
552
+ address: shareClassManager,
553
+ abi: ABI.ShareClassManager,
554
+ functionName: 'metrics',
555
+ args: [this.id.raw],
556
+ });
557
+ return {
558
+ totalIssuance: new Balance(totalIssuance, 18),
559
+ pricePerShare: new Price(pricePerShare),
560
+ };
561
+ }).pipe(repeatOnEvents(this._root, {
562
+ address: shareClassManager,
563
+ abi: ABI.ShareClassManager,
564
+ eventName: [
565
+ 'RevokeShares',
566
+ 'IssueShares',
567
+ 'RemoteIssueShares',
568
+ 'RemoteRevokeShares',
569
+ 'UpdateShareClass',
570
+ ],
571
+ filter: (events) => {
572
+ return events.some((event) => {
573
+ return event.args.scId === this.id.raw;
574
+ });
575
+ },
576
+ }, this.pool.chainId)))));
577
+ }
578
+ /** @internal */
579
+ _epoch(assetId) {
580
+ return this._query(['epoch', assetId.toString()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager, hubRegistry }) => defer(async () => {
581
+ const scm = getContract({
582
+ address: shareClassManager,
583
+ abi: ABI.ShareClassManager,
584
+ client: this._root.getClient(this.pool.chainId),
585
+ });
586
+ const [epoch, pendingDeposit, pendingRedeem, assetDecimals] = await Promise.all([
587
+ scm.read.epochId([this.id.raw, assetId.raw]),
588
+ scm.read.pendingDeposit([this.id.raw, assetId.raw]),
589
+ scm.read.pendingRedeem([this.id.raw, assetId.raw]),
590
+ this._root.getClient(this.pool.chainId).readContract({
591
+ address: hubRegistry,
592
+ // Use inline ABI because of function overload
593
+ abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
594
+ functionName: 'decimals',
595
+ args: [assetId.raw],
596
+ }),
597
+ ]);
598
+ return {
599
+ depositEpoch: epoch[0] + 1,
600
+ redeemEpoch: epoch[1] + 1,
601
+ issueEpoch: epoch[2] + 1,
602
+ revokeEpoch: epoch[3] + 1,
603
+ // TODO: Replace with assetDecimals()
604
+ pendingDeposit: new Balance(pendingDeposit, assetDecimals),
605
+ // TODO: Replace with assetDecimals()
606
+ pendingRedeem: new Balance(pendingRedeem, 18),
607
+ };
608
+ }).pipe(repeatOnEvents(this._root, {
609
+ address: shareClassManager,
610
+ abi: ABI.ShareClassManager,
611
+ eventName: [
612
+ 'ApproveDeposits',
613
+ 'ApproveRedeems',
614
+ 'IssueShares',
615
+ 'RevokeShares',
616
+ 'RemoteIssueShares',
617
+ 'RemoteRevokeShares',
618
+ 'UpdateDepositRequest',
619
+ 'UpdateRedeemRequest',
620
+ ],
621
+ filter: (events) => {
622
+ return events.some((event) => {
623
+ return event.args.scId === this.id.raw;
624
+ });
625
+ },
626
+ }, this.pool.chainId)))));
627
+ }
628
+ /** @internal */
629
+ _updateContract(chainId, target, payload) {
630
+ const self = this;
631
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
632
+ const id = await self._root.id(chainId);
633
+ const [{ hub }, estimate] = await Promise.all([
634
+ self._root._protocolAddresses(self.pool.chainId),
635
+ self._root._estimate(self.pool.chainId, { centId: id }),
636
+ ]);
637
+ yield* doTransaction('Update contract', publicClient, () => walletClient.writeContract({
638
+ address: hub,
639
+ abi: ABI.Hub,
640
+ functionName: 'updateContract',
641
+ args: [self.pool.id.raw, self.id.raw, id, addressToBytes32(target), payload, 15000000n],
642
+ value: estimate,
643
+ }));
644
+ }, this.pool.chainId);
645
+ }
646
+ /** @internal */
647
+ _share(chainId) {
648
+ return this._query(null, () => this.pool.network(chainId).pipe(switchMap((network) => network._share(this.id))));
649
+ }
650
+ /** @internal */
651
+ _restrictionManager(chainId) {
652
+ return this._query(['restrictionManager', chainId], () => this._share(chainId).pipe(switchMap((share) => defer(async () => {
653
+ const address = await this._root.getClient(this.pool.chainId).readContract({
654
+ address: share,
655
+ abi: ABI.Currency,
656
+ functionName: 'hook',
657
+ });
658
+ return address.toLowerCase();
659
+ }))));
660
+ }
661
+ /** @internal */
662
+ _getFreeAccountId() {
663
+ return this._query(null, () => this._root._protocolAddresses(this.pool.chainId).pipe(map(({ accounting }) => ({ accounting, id: null, triesLeft: 10 })), expand(({ accounting, triesLeft }) => {
664
+ const id = Number(randomUint(32));
665
+ if (triesLeft <= 0)
666
+ return EMPTY;
667
+ return defer(async () => {
668
+ const exists = await this._root.getClient(this.pool.chainId).readContract({
669
+ address: accounting,
670
+ abi: ABI.Accounting,
671
+ functionName: 'exists',
672
+ args: [this.pool.id.raw, id],
673
+ });
674
+ return { accounting, id: exists ? null : id, triesLeft: triesLeft - 1 };
675
+ });
676
+ }), filter(({ id }) => !!id), map(({ id }) => id)));
677
+ }
678
+ }
679
+ //# sourceMappingURL=ShareClass.js.map