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

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 +153 -0
  171. package/dist/entities/ShareClass.d.ts.map +1 -0
  172. package/dist/entities/ShareClass.js +833 -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 +109 -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 +277 -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,833 @@
1
+ import { catchError, combineLatest, defer, EMPTY, expand, filter, map, of, switchMap } from 'rxjs';
2
+ import { encodeFunctionData, encodePacked, getAddress, 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
+ import { Vault } from './Vault.js';
13
+ /**
14
+ * Query and interact with a share class, which allows querying total issuance, NAV per share,
15
+ * and allows interactions related to asynchronous deposits and redemptions.
16
+ */
17
+ export class ShareClass extends Entity {
18
+ pool;
19
+ id;
20
+ /** @internal */
21
+ constructor(_root, pool, id) {
22
+ const _id = id instanceof ShareClassId ? id : new ShareClassId(id);
23
+ super(_root, ['shareclass', _id.toString()]);
24
+ this.pool = pool;
25
+ this.id = _id;
26
+ }
27
+ /**
28
+ * Query the details of the share class.
29
+ * @returns The details of the share class, including name, symbol, total issuance, and NAV per share.
30
+ */
31
+ details() {
32
+ return this._query(null, () => combineLatest([this._metrics(), this._metadata()]).pipe(map(([metrics, metadata]) => {
33
+ return {
34
+ id: this.id,
35
+ name: metadata.name,
36
+ symbol: metadata.symbol,
37
+ totalIssuance: metrics.totalIssuance,
38
+ pricePerShare: metrics.pricePerShare,
39
+ nav: metrics.totalIssuance.mul(metrics.pricePerShare),
40
+ };
41
+ })));
42
+ }
43
+ navPerNetwork() {
44
+ return this._root._queryIndexer(`query ($scId: String!) {
45
+ tokenInstances(where: { tokenId: $scId }) {
46
+ items {
47
+ totalIssuance
48
+ tokenPrice
49
+ blockchain {
50
+ id
51
+ }
52
+ }
53
+ }
54
+ }`, { scId: this.id.raw }, (data) => data.tokenInstances.items.map((item) => ({
55
+ chainId: Number(item.blockchain.id),
56
+ totalIssuance: new Balance(item.totalIssuance, 18), // TODO: Replace with pool currency decimals
57
+ pricePerShare: new Price(item.tokenPrice),
58
+ nav: new Balance(item.totalIssuance, 18).mul(new Price(item.tokenPrice)),
59
+ })));
60
+ }
61
+ /**
62
+ * Query the vaults of the share class.
63
+ * @param chainId The chain ID to query the vaults on.
64
+ * @returns The vaults of the share class on the given chain.
65
+ */
66
+ vaults(chainId) {
67
+ if (!chainId) {
68
+ return this._root._queryIndexer(`query ($scId: String!) {
69
+ vaults(where: { tokenId: $scId }) {
70
+ items {
71
+ address: id
72
+ poolId
73
+ assetAddress
74
+ tokenId
75
+ blockchain {
76
+ id
77
+ }
78
+ }
79
+ }
80
+ }`, { scId: this.id.raw }, (data) => data.vaults.items.map((item) => new Vault(this._root, new PoolNetwork(this._root, this.pool, Number(item.blockchain.id)), this, item.assetAddress, item.address)));
81
+ }
82
+ return this._query(null, () => new PoolNetwork(this._root, this.pool, chainId).vaults(this.id));
83
+ }
84
+ holdings() {
85
+ return this._query(null, () => this._root
86
+ ._queryIndexer(`query ($scId: String!) {
87
+ holdings(where: { tokenId: $scId }) {
88
+ items {
89
+ assetRegistrationId
90
+ }
91
+ }
92
+ }`, {
93
+ scId: this.id.raw,
94
+ })
95
+ .pipe(switchMap((res) => combineLatest(res.holdings.items.map((holding) => {
96
+ const assetId = new AssetId(holding.assetRegistrationId);
97
+ return this.holding(assetId);
98
+ })))));
99
+ }
100
+ /**
101
+ * Query a holding of the share class.
102
+ * @param assetId The asset ID
103
+ * @returns The details of the holding
104
+ */
105
+ holding(assetId) {
106
+ return this._query(['holding', assetId.toString()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ holdings: holdingsAddr, hubRegistry }) => defer(async () => {
107
+ const holdings = getContract({
108
+ address: holdingsAddr,
109
+ abi: ABI.Holdings,
110
+ client: this._root.getClient(this.pool.chainId),
111
+ });
112
+ const [valuation, amount, value, assetDecimals, isLiability, ...accounts] = await Promise.all([
113
+ holdings.read.valuation([this.pool.id.raw, this.id.raw, assetId.raw]),
114
+ holdings.read.amount([this.pool.id.raw, this.id.raw, assetId.raw]),
115
+ holdings.read.value([this.pool.id.raw, this.id.raw, assetId.raw]),
116
+ this._root.getClient(this.pool.chainId).readContract({
117
+ address: hubRegistry,
118
+ // Use inline ABI because of function overload
119
+ abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
120
+ functionName: 'decimals',
121
+ args: [assetId.raw],
122
+ }),
123
+ holdings.read.isLiability([this.pool.id.raw, this.id.raw, assetId.raw]),
124
+ ...[
125
+ AccountType.Asset,
126
+ AccountType.Equity,
127
+ AccountType.Loss,
128
+ AccountType.Gain,
129
+ AccountType.Expense,
130
+ AccountType.Liability,
131
+ ].map((kind) => holdings.read.accountId([this.pool.id.raw, this.id.raw, assetId.raw, kind])),
132
+ ]);
133
+ return {
134
+ assetId,
135
+ assetDecimals,
136
+ valuation,
137
+ amount: new Balance(amount, assetDecimals),
138
+ value: new Balance(value, 18), // TODO: Replace with pool currency decimals
139
+ isLiability,
140
+ accounts: {
141
+ [AccountType.Asset]: accounts[0] || null,
142
+ [AccountType.Equity]: accounts[1] || null,
143
+ [AccountType.Loss]: accounts[2] || null,
144
+ [AccountType.Gain]: accounts[3] || null,
145
+ [AccountType.Expense]: accounts[4] || null,
146
+ [AccountType.Liability]: accounts[5] || null,
147
+ },
148
+ };
149
+ }).pipe(repeatOnEvents(this._root, {
150
+ address: holdingsAddr,
151
+ abi: ABI.Holdings,
152
+ eventName: ['Increase', 'Decrease', 'Update', 'UpdateValuation'],
153
+ filter: (events) => {
154
+ return events.some((event) => {
155
+ return event.args.scId === this.id && event.args.assetId === assetId.raw;
156
+ });
157
+ },
158
+ }, this.pool.chainId)))));
159
+ }
160
+ /**
161
+ * Get the pending and approved amounts for deposits and redemptions for each asset.
162
+ */
163
+ pendingAmounts() {
164
+ return this._query(null, () =>
165
+ // TODO: Simplify when indexer includes the asset ID in the Asset entity
166
+ // can then query the asset id on { vaults { asset { id } }}
167
+ this.vaults().pipe(switchMap((vaults) => this._assetIdsByAddress(vaults.map((vault) => vault._asset)).pipe(switchMap((assetIdsByAddress) => combineLatest(vaults.map((vault) => this._epoch(assetIdsByAddress[vault._asset]))).pipe(map((epochs) => {
168
+ return epochs.map((epoch, i) => {
169
+ const vault = vaults[i];
170
+ const assetId = assetIdsByAddress[vault._asset];
171
+ return {
172
+ assetId,
173
+ chainId: vault.chainId,
174
+ ...epoch,
175
+ };
176
+ });
177
+ })))))));
178
+ }
179
+ investorOrder(assetId, investor) {
180
+ return this._query(['maxClaims', assetId.toString(), investor.toLowerCase()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
181
+ const contract = getContract({
182
+ address: shareClassManager,
183
+ abi: ABI.ShareClassManager,
184
+ client: this._root.getClient(this.pool.chainId),
185
+ });
186
+ const [maxDepositClaims, maxRedeemClaims] = await Promise.all([
187
+ contract.read.maxDepositClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
188
+ contract.read.maxRedeemClaims([this.id.raw, addressToBytes32(investor), assetId.raw]),
189
+ ]);
190
+ return {
191
+ maxDepositClaims,
192
+ maxRedeemClaims,
193
+ };
194
+ }).pipe(repeatOnEvents(this._root, {
195
+ address: shareClassManager,
196
+ abi: ABI.ShareClassManager,
197
+ eventName: [
198
+ 'UpdateDepositRequest',
199
+ 'UpdateRedeemRequest',
200
+ 'ClaimDeposit',
201
+ 'ClaimRedeem',
202
+ 'ApproveDeposits',
203
+ 'ApproveRedeems',
204
+ ],
205
+ filter: (events) => {
206
+ return events.some((event) => event.args.scId === this.id.raw &&
207
+ (event.args.depositAssetId === assetId.raw || event.args.payoutAssetId === assetId.raw));
208
+ },
209
+ }, this.pool.chainId)))));
210
+ }
211
+ /**
212
+ * Check if an address is a member of the share class.
213
+ * @param address Address to check
214
+ * @param chainId Chain ID of the network on which to check the member
215
+ */
216
+ member(address, chainId) {
217
+ const addr = address.toLowerCase();
218
+ return this._query(['member', addr, chainId], () => combineLatest([this._share(chainId), this._restrictionManager(chainId)]).pipe(switchMap(([share, restrictionManager]) => defer(async () => {
219
+ const res = await this._root.getClient(this.pool.chainId).readContract({
220
+ address: restrictionManager,
221
+ abi: ABI.RestrictionManager,
222
+ functionName: 'isMember',
223
+ args: [share, addr],
224
+ });
225
+ return {
226
+ isMember: res[0],
227
+ validUntil: new Date(Number(res[1]) * 1000),
228
+ };
229
+ }).pipe(repeatOnEvents(this._root, {
230
+ address: restrictionManager,
231
+ abi: ABI.RestrictionManager,
232
+ eventName: 'UpdateMember',
233
+ filter: (events) => events.some((event) => event.args.user?.toLowerCase() === addr && event.args.token?.toLowerCase() === share),
234
+ }, chainId), catchError(() => {
235
+ // Freeze-only hook doesn't have isMember function
236
+ return of({
237
+ isMember: false,
238
+ validUntil: new Date(0),
239
+ });
240
+ })))));
241
+ }
242
+ /**
243
+ * Create a holding for a registered asset in the share class.
244
+ * @param assetId - Asset ID of the asset to create a holding for
245
+ * @param valuation - Valuation of the asset
246
+ * @param isLiability - Whether the holding is a liability or not
247
+ * @param accounts - Accounts to use for the holding. An asset or expense account will be created if not provided.
248
+ * Other accounts are expected to be provided or to exist in the pool metadata.
249
+ */
250
+ createHolding(assetId, valuation, isLiability, accounts) {
251
+ const self = this;
252
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
253
+ const [{ hub }, metadata] = await Promise.all([
254
+ self._root._protocolAddresses(self.pool.chainId),
255
+ self.pool.metadata(),
256
+ ]);
257
+ let tx;
258
+ if (isLiability) {
259
+ const expenseAccount = accounts[AccountType.Expense] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.expense;
260
+ const liabilityAccount = accounts[AccountType.Liability] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.liability;
261
+ if (liabilityAccount === undefined) {
262
+ throw new Error('Missing required accounts for liability creation');
263
+ }
264
+ if (expenseAccount) {
265
+ tx = walletClient.writeContract({
266
+ address: hub,
267
+ abi: ABI.Hub,
268
+ functionName: 'initializeLiability',
269
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, expenseAccount, liabilityAccount],
270
+ });
271
+ }
272
+ else {
273
+ const newExpenseAccount = await self._getFreeAccountId();
274
+ const createAccountData = encodeFunctionData({
275
+ abi: ABI.Hub,
276
+ functionName: 'createAccount',
277
+ args: [self.pool.id.raw, newExpenseAccount, true],
278
+ });
279
+ const initHoldingData = encodeFunctionData({
280
+ abi: ABI.Hub,
281
+ functionName: 'initializeLiability',
282
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, valuation, newExpenseAccount, liabilityAccount],
283
+ });
284
+ tx = walletClient.writeContract({
285
+ address: hub,
286
+ abi: ABI.Hub,
287
+ functionName: 'multicall',
288
+ args: [[createAccountData, initHoldingData]],
289
+ });
290
+ }
291
+ }
292
+ else {
293
+ const assetAccount = accounts[AccountType.Asset] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.asset;
294
+ const equityAccount = accounts[AccountType.Equity] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.equity;
295
+ const gainAccount = accounts[AccountType.Gain] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.gain;
296
+ const lossAccount = accounts[AccountType.Loss] || metadata?.shareClasses?.[self.id.raw]?.defaultAccounts?.loss;
297
+ if (equityAccount === undefined || gainAccount === undefined || lossAccount === undefined) {
298
+ throw new Error('Missing required accounts for holding creation');
299
+ }
300
+ if (assetAccount) {
301
+ tx = walletClient.writeContract({
302
+ address: hub,
303
+ abi: ABI.Hub,
304
+ functionName: 'initializeHolding',
305
+ args: [
306
+ self.pool.id.raw,
307
+ self.id.raw,
308
+ assetId.raw,
309
+ valuation,
310
+ assetAccount,
311
+ equityAccount,
312
+ gainAccount,
313
+ lossAccount,
314
+ ],
315
+ });
316
+ }
317
+ else {
318
+ const newAssetAccount = await self._getFreeAccountId();
319
+ const createAccountData = encodeFunctionData({
320
+ abi: ABI.Hub,
321
+ functionName: 'createAccount',
322
+ args: [self.pool.id.raw, newAssetAccount, false],
323
+ });
324
+ const initHoldingData = encodeFunctionData({
325
+ abi: ABI.Hub,
326
+ functionName: 'initializeHolding',
327
+ args: [
328
+ self.pool.id.raw,
329
+ self.id.raw,
330
+ assetId.raw,
331
+ valuation,
332
+ newAssetAccount,
333
+ equityAccount,
334
+ gainAccount,
335
+ lossAccount,
336
+ ],
337
+ });
338
+ tx = walletClient.writeContract({
339
+ address: hub,
340
+ abi: ABI.Hub,
341
+ functionName: 'multicall',
342
+ args: [[createAccountData, initHoldingData]],
343
+ });
344
+ }
345
+ }
346
+ yield* doTransaction('Create holding', publicClient, () => tx);
347
+ }, this.pool.chainId);
348
+ }
349
+ updateSharePrice(pricePerShare) {
350
+ const self = this;
351
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
352
+ const { hub } = await self._root._protocolAddresses(self.pool.chainId);
353
+ yield* doTransaction('Update price', publicClient, () => walletClient.writeContract({
354
+ address: hub,
355
+ abi: ABI.Hub,
356
+ functionName: 'updateSharePrice',
357
+ args: [self.pool.id.raw, self.id.raw, pricePerShare.toBigInt()],
358
+ }));
359
+ }, this.pool.chainId);
360
+ }
361
+ setMaxAssetPriceAge(assetId, maxPriceAge) {
362
+ const self = this;
363
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
364
+ const { hub } = await self._root._protocolAddresses(self.pool.chainId);
365
+ yield* doTransaction('Set max asset price age', publicClient, () => walletClient.writeContract({
366
+ address: hub,
367
+ abi: ABI.Hub,
368
+ functionName: 'setMaxAssetPriceAge',
369
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, BigInt(maxPriceAge)],
370
+ }));
371
+ }, this.pool.chainId);
372
+ }
373
+ setMaxSharePriceAge(chainId, maxPriceAge) {
374
+ const self = this;
375
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
376
+ const [{ hub }, id] = await Promise.all([
377
+ self._root._protocolAddresses(self.pool.chainId),
378
+ self._root.id(chainId),
379
+ ]);
380
+ yield* doTransaction('Set max share price age', publicClient, () => walletClient.writeContract({
381
+ address: hub,
382
+ abi: ABI.Hub,
383
+ functionName: 'setMaxSharePriceAge',
384
+ args: [id, self.pool.id.raw, self.id.raw, BigInt(maxPriceAge)],
385
+ }));
386
+ }, this.pool.chainId);
387
+ }
388
+ notifyAssetPrice(assetId) {
389
+ const self = this;
390
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
391
+ const { hub } = await self._root._protocolAddresses(self.pool.chainId);
392
+ yield* doTransaction('Notify asset price', publicClient, () => walletClient.writeContract({
393
+ address: hub,
394
+ abi: ABI.Hub,
395
+ functionName: 'notifyAssetPrice',
396
+ args: [self.pool.id.raw, self.id.raw, assetId.raw],
397
+ }));
398
+ }, this.pool.chainId);
399
+ }
400
+ notifySharePrice(chainId) {
401
+ const self = this;
402
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
403
+ const [{ hub }, id] = await Promise.all([
404
+ self._root._protocolAddresses(self.pool.chainId),
405
+ self._root.id(chainId),
406
+ ]);
407
+ yield* doTransaction('Notify share price', publicClient, () => walletClient.writeContract({
408
+ address: hub,
409
+ abi: ABI.Hub,
410
+ functionName: 'notifySharePrice',
411
+ args: [self.pool.id.raw, self.id.raw, id],
412
+ }));
413
+ }, this.pool.chainId);
414
+ }
415
+ /**
416
+ * Approve deposits and issue shares for the given assets.
417
+ * @param assets - Array of assets to approve deposits and/or issue shares for
418
+ */
419
+ approveDepositsAndIssueShares(assets) {
420
+ // TODO: Also claim orders
421
+ const self = this;
422
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
423
+ const centIds = [...new Set(assets.map((a) => a.assetId.centrifugeId))];
424
+ const [{ hub }, pendingAmounts,
425
+ // ...estimates
426
+ ] = await Promise.all([
427
+ self._root._protocolAddresses(self.pool.chainId),
428
+ self.pendingAmounts(),
429
+ ...centIds.map((centId) => self._root._estimate(self.pool.chainId, { centId })),
430
+ ]);
431
+ // const estimateByCentId: Map<number, bigint> = new Map(centIds.map((centId, i) => [centId, estimates[i]!]))
432
+ const batch = [];
433
+ const estimate = 0n;
434
+ for (const asset of assets) {
435
+ const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
436
+ if (!pending) {
437
+ throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
438
+ }
439
+ let nextDepositEpoch = pending?.depositEpoch + 1;
440
+ if (asset.approveAssetAmount) {
441
+ if (asset.approveAssetAmount.gt(pending.pendingDeposit)) {
442
+ throw new Error(`Approve amount exceeds pending amount for asset "${asset.assetId.toString()}"`);
443
+ }
444
+ if (asset.approveAssetAmount.lte(0n)) {
445
+ throw new Error(`Approve amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
446
+ }
447
+ batch.push(encodeFunctionData({
448
+ abi: ABI.Hub,
449
+ functionName: 'approveDeposits',
450
+ args: [
451
+ self.pool.id.raw,
452
+ self.id.raw,
453
+ asset.assetId.raw,
454
+ nextDepositEpoch,
455
+ asset.approveAssetAmount.toBigInt(),
456
+ ],
457
+ }));
458
+ nextDepositEpoch++;
459
+ }
460
+ const nextIssueEpoch = pending.issueEpoch + 1;
461
+ if (asset.issuePricePerShare) {
462
+ if (nextIssueEpoch >= nextDepositEpoch)
463
+ throw new Error('Nothing to issue');
464
+ batch.push(...Array.from({ length: nextDepositEpoch - nextIssueEpoch }, (_, i) => encodeFunctionData({
465
+ abi: ABI.Hub,
466
+ functionName: 'issueShares',
467
+ args: [
468
+ self.pool.id.raw,
469
+ self.id.raw,
470
+ asset.assetId.raw,
471
+ nextIssueEpoch + i,
472
+ asset.issuePricePerShare.toBigInt(),
473
+ ],
474
+ })));
475
+ }
476
+ }
477
+ if (batch.length === 0) {
478
+ throw new Error('No approve or issue actions provided');
479
+ }
480
+ yield* doTransaction('Approve and issue', publicClient, () => {
481
+ if (batch.length === 1) {
482
+ return walletClient.sendTransaction({
483
+ data: batch[0],
484
+ to: hub,
485
+ value: estimate,
486
+ });
487
+ }
488
+ return walletClient.writeContract({
489
+ address: hub,
490
+ abi: ABI.Hub,
491
+ functionName: 'multicall',
492
+ args: [batch],
493
+ value: estimate,
494
+ });
495
+ });
496
+ }, this.pool.chainId);
497
+ }
498
+ /**
499
+ * Approve redeems and revoke shares for the given assets.
500
+ * @param assets - Array of assets to approve redeems and/or revoke shares for
501
+ */
502
+ approveRedeemsAndRevokeShares(assets) {
503
+ // TODO: Also claim orders
504
+ const self = this;
505
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
506
+ const centIds = [...new Set(assets.map((a) => a.assetId.centrifugeId))];
507
+ const [{ hub }, pendingAmounts,
508
+ // ...estimates
509
+ ] = await Promise.all([
510
+ self._root._protocolAddresses(self.pool.chainId),
511
+ self.pendingAmounts(),
512
+ ...centIds.map((centId) => self._root._estimate(self.pool.chainId, { centId })),
513
+ ]);
514
+ // const estimateByCentId: Map<number, bigint> = new Map(centIds.map((centId, i) => [centId, estimates[i]!]))
515
+ const batch = [];
516
+ const estimate = 0n;
517
+ for (const asset of assets) {
518
+ const pending = pendingAmounts.find((e) => e.assetId.equals(asset.assetId));
519
+ if (!pending) {
520
+ throw new Error(`No pending amount found for asset "${asset.assetId.toString()}"`);
521
+ }
522
+ let nextRedeemEpoch = pending.redeemEpoch + 1;
523
+ if (asset.approveShareAmount) {
524
+ if (asset.approveShareAmount.gt(pending.pendingRedeem)) {
525
+ throw new Error(`Share amount exceeds pending redeem for asset "${asset.assetId.toString()}"`);
526
+ }
527
+ if (asset.approveShareAmount.lte(0n)) {
528
+ throw new Error(`Share amount must be greater than 0 for asset "${asset.assetId.toString()}"`);
529
+ }
530
+ batch.push(encodeFunctionData({
531
+ abi: ABI.Hub,
532
+ functionName: 'approveRedeems',
533
+ args: [
534
+ self.pool.id.raw,
535
+ self.id.raw,
536
+ asset.assetId.raw,
537
+ nextRedeemEpoch,
538
+ asset.approveShareAmount.toBigInt(),
539
+ ],
540
+ }));
541
+ nextRedeemEpoch++;
542
+ }
543
+ const nextRevokeEpoch = pending.revokeEpoch + 1;
544
+ if (nextRevokeEpoch >= nextRedeemEpoch)
545
+ throw new Error('Nothing to revoke');
546
+ if (asset.revokePricePerShare) {
547
+ if (nextRevokeEpoch >= nextRedeemEpoch)
548
+ throw new Error('Nothing to revoke');
549
+ if (asset.revokePricePerShare.lte(0n)) {
550
+ throw new Error(`Revoke price per share must be greater than 0 for asset "${asset.assetId.toString()}"`);
551
+ }
552
+ batch.push(...Array.from({ length: nextRedeemEpoch - nextRevokeEpoch }, (_, i) => encodeFunctionData({
553
+ abi: ABI.Hub,
554
+ functionName: 'revokeShares',
555
+ args: [
556
+ self.pool.id.raw,
557
+ self.id.raw,
558
+ asset.assetId.raw,
559
+ nextRevokeEpoch + i,
560
+ asset.revokePricePerShare.toBigInt(),
561
+ ],
562
+ })));
563
+ }
564
+ }
565
+ if (batch.length === 0) {
566
+ throw new Error('No approve or revoke actions provided');
567
+ }
568
+ yield* doTransaction('Approve and revoke', publicClient, () => {
569
+ if (batch.length === 1) {
570
+ return walletClient.sendTransaction({
571
+ data: batch[0],
572
+ to: hub,
573
+ value: estimate,
574
+ });
575
+ }
576
+ return walletClient.writeContract({
577
+ address: hub,
578
+ abi: ABI.Hub,
579
+ functionName: 'multicall',
580
+ args: [batch],
581
+ value: estimate,
582
+ });
583
+ });
584
+ }, this.pool.chainId);
585
+ }
586
+ claimDeposit(assetId, investor) {
587
+ const self = this;
588
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
589
+ const [{ hub }, investorOrder, estimate] = await Promise.all([
590
+ self._root._protocolAddresses(self.pool.chainId),
591
+ self.investorOrder(assetId, investor),
592
+ self._root._estimate(self.pool.chainId, { centId: assetId.centrifugeId }),
593
+ ]);
594
+ yield* doTransaction('Claim deposit', publicClient, () => walletClient.writeContract({
595
+ address: hub,
596
+ abi: ABI.Hub,
597
+ functionName: 'notifyDeposit',
598
+ args: [
599
+ self.pool.id.raw,
600
+ self.id.raw,
601
+ assetId.raw,
602
+ addressToBytes32(investor),
603
+ investorOrder.maxDepositClaims,
604
+ ],
605
+ value: estimate,
606
+ }));
607
+ }, this.pool.chainId);
608
+ }
609
+ claimRedeem(assetId, investor) {
610
+ const self = this;
611
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
612
+ const [{ hub }, investorOrder, estimate] = await Promise.all([
613
+ self._root._protocolAddresses(self.pool.chainId),
614
+ self.investorOrder(assetId, investor),
615
+ self._root._estimate(self.pool.chainId, { centId: assetId.centrifugeId }),
616
+ ]);
617
+ yield* doTransaction('Claim redeem', publicClient, () => walletClient.writeContract({
618
+ address: hub,
619
+ abi: ABI.Hub,
620
+ functionName: 'notifyRedeem',
621
+ args: [self.pool.id.raw, self.id.raw, assetId.raw, addressToBytes32(investor), investorOrder.maxRedeemClaims],
622
+ value: estimate,
623
+ }));
624
+ }, this.pool.chainId);
625
+ }
626
+ /**
627
+ * Update a member of the share class.
628
+ * @param address Address of the investor
629
+ * @param validUntil Time in seconds from Unix epoch until the investor is valid
630
+ * @param chainId Chain ID of the network on which to update the member
631
+ */
632
+ updateMember(address, validUntil, chainId) {
633
+ const self = this;
634
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
635
+ const [{ hub }, id, estimate] = await Promise.all([
636
+ self._root._protocolAddresses(self.pool.chainId),
637
+ self._root.id(chainId),
638
+ self._root._estimate(self.pool.chainId, { chainId }),
639
+ ]);
640
+ const payload = encodePacked(['uint8', 'bytes32', 'uint64'], [/* UpdateRestrictionType.Member */ 1, addressToBytes32(address), BigInt(validUntil)]);
641
+ yield* doTransaction('Update restriction', publicClient, () => walletClient.writeContract({
642
+ address: hub,
643
+ abi: ABI.Hub,
644
+ functionName: 'updateRestriction',
645
+ args: [self.pool.id.raw, self.id.raw, id, payload, 15000000n],
646
+ value: estimate,
647
+ }));
648
+ }, this.pool.chainId);
649
+ }
650
+ /** @internal */
651
+ _assetIdsByAddress(assetAddresses) {
652
+ return this._root._queryIndexer(`query ($assetAddresses: [String!]!) {
653
+ assetRegistrations(where: { assetAddress_in: $assetAddresses }) {
654
+ items {
655
+ id
656
+ assetAddress
657
+ }
658
+ }
659
+ }`, { assetAddresses: assetAddresses.map((a) => getAddress(a)) }, (data) => {
660
+ return Object.fromEntries(data.assetRegistrations.items.map((item) => {
661
+ const assetId = new AssetId(item.id);
662
+ return [item.assetAddress.toLowerCase(), assetId];
663
+ }));
664
+ });
665
+ }
666
+ /** @internal */
667
+ _metadata() {
668
+ return this._query(['metadata'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
669
+ const [name, symbol] = await this._root.getClient(this.pool.chainId).readContract({
670
+ address: shareClassManager,
671
+ abi: ABI.ShareClassManager,
672
+ functionName: 'metadata',
673
+ args: [this.id.raw],
674
+ });
675
+ return {
676
+ name,
677
+ symbol,
678
+ };
679
+ }).pipe(repeatOnEvents(this._root, {
680
+ address: shareClassManager,
681
+ abi: ABI.ShareClassManager,
682
+ eventName: 'UpdateMetadata',
683
+ filter: (events) => {
684
+ return events.some((event) => {
685
+ return event.args.scId === this.id;
686
+ });
687
+ },
688
+ }, this.pool.chainId)))));
689
+ }
690
+ /** @internal */
691
+ _metrics() {
692
+ return this._query(['metrics'], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager }) => defer(async () => {
693
+ const [totalIssuance, pricePerShare] = await this._root.getClient(this.pool.chainId).readContract({
694
+ address: shareClassManager,
695
+ abi: ABI.ShareClassManager,
696
+ functionName: 'metrics',
697
+ args: [this.id.raw],
698
+ });
699
+ return {
700
+ totalIssuance: new Balance(totalIssuance, 18),
701
+ pricePerShare: new Price(pricePerShare),
702
+ };
703
+ }).pipe(repeatOnEvents(this._root, {
704
+ address: shareClassManager,
705
+ abi: ABI.ShareClassManager,
706
+ eventName: [
707
+ 'RevokeShares',
708
+ 'IssueShares',
709
+ 'RemoteIssueShares',
710
+ 'RemoteRevokeShares',
711
+ 'UpdateShareClass',
712
+ ],
713
+ filter: (events) => {
714
+ return events.some((event) => {
715
+ return event.args.scId === this.id.raw;
716
+ });
717
+ },
718
+ }, this.pool.chainId)))));
719
+ }
720
+ /** @internal */
721
+ _epoch(assetId) {
722
+ return this._query(['epoch', assetId.toString()], () => this._root._protocolAddresses(this.pool.chainId).pipe(switchMap(({ shareClassManager, hubRegistry }) => defer(async () => {
723
+ const scm = getContract({
724
+ address: shareClassManager,
725
+ abi: ABI.ShareClassManager,
726
+ client: this._root.getClient(this.pool.chainId),
727
+ });
728
+ const [epoch, pendingDeposit, pendingRedeem, assetDecimals] = await Promise.all([
729
+ scm.read.epochId([this.id.raw, assetId.raw]),
730
+ scm.read.pendingDeposit([this.id.raw, assetId.raw]),
731
+ scm.read.pendingRedeem([this.id.raw, assetId.raw]),
732
+ this._root.getClient(this.pool.chainId).readContract({
733
+ address: hubRegistry,
734
+ // Use inline ABI because of function overload
735
+ abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
736
+ functionName: 'decimals',
737
+ args: [assetId.raw],
738
+ }),
739
+ ]);
740
+ const depositEpoch = epoch[0];
741
+ const redeemEpoch = epoch[1];
742
+ const issueEpoch = epoch[2];
743
+ const revokeEpoch = epoch[3];
744
+ const [depositEpochAmounts, redeemEpochAmount] = await Promise.all([
745
+ Promise.all(Array.from({ length: depositEpoch - issueEpoch }).map((_, i) => scm.read.epochInvestAmounts([this.id.raw, assetId.raw, issueEpoch + i + 1]))),
746
+ Promise.all(Array.from({ length: redeemEpoch - revokeEpoch }).map((_, i) => scm.read.epochRedeemAmounts([this.id.raw, assetId.raw, revokeEpoch + i + 1]))),
747
+ ]);
748
+ const approvedDeposit = depositEpochAmounts.reduce((acc, amount) => acc + amount[1], 0n);
749
+ const approvedRedeem = redeemEpochAmount.reduce((acc, amount) => acc + amount[1], 0n);
750
+ return {
751
+ depositEpoch,
752
+ redeemEpoch,
753
+ issueEpoch,
754
+ revokeEpoch,
755
+ // TODO: Replace with assetDecimals()
756
+ pendingDeposit: new Balance(pendingDeposit, assetDecimals),
757
+ // TODO: Replace with assetDecimals()
758
+ pendingRedeem: new Balance(pendingRedeem, 18),
759
+ approvedDeposit: new Balance(approvedDeposit, assetDecimals),
760
+ approvedRedeem: new Balance(approvedRedeem, 18),
761
+ };
762
+ }).pipe(repeatOnEvents(this._root, {
763
+ address: shareClassManager,
764
+ abi: ABI.ShareClassManager,
765
+ eventName: [
766
+ 'ApproveDeposits',
767
+ 'ApproveRedeems',
768
+ 'IssueShares',
769
+ 'RevokeShares',
770
+ 'RemoteIssueShares',
771
+ 'RemoteRevokeShares',
772
+ 'UpdateDepositRequest',
773
+ 'UpdateRedeemRequest',
774
+ ],
775
+ filter: (events) => {
776
+ return events.some((event) => {
777
+ return event.args.scId === this.id.raw;
778
+ });
779
+ },
780
+ }, this.pool.chainId)))));
781
+ }
782
+ /** @internal */
783
+ _updateContract(chainId, target, payload) {
784
+ const self = this;
785
+ return this._transactSequence(async function* ({ walletClient, publicClient }) {
786
+ const id = await self._root.id(chainId);
787
+ const [{ hub }, estimate] = await Promise.all([
788
+ self._root._protocolAddresses(self.pool.chainId),
789
+ self._root._estimate(self.pool.chainId, { centId: id }),
790
+ ]);
791
+ yield* doTransaction('Update contract', publicClient, () => walletClient.writeContract({
792
+ address: hub,
793
+ abi: ABI.Hub,
794
+ functionName: 'updateContract',
795
+ args: [self.pool.id.raw, self.id.raw, id, addressToBytes32(target), payload, 15000000n],
796
+ value: estimate,
797
+ }));
798
+ }, this.pool.chainId);
799
+ }
800
+ /** @internal */
801
+ _share(chainId) {
802
+ return this._query(null, () => this.pool.network(chainId).pipe(switchMap((network) => network._share(this.id))));
803
+ }
804
+ /** @internal */
805
+ _restrictionManager(chainId) {
806
+ return this._query(['restrictionManager', chainId], () => this._share(chainId).pipe(switchMap((share) => defer(async () => {
807
+ const address = await this._root.getClient(this.pool.chainId).readContract({
808
+ address: share,
809
+ abi: ABI.Currency,
810
+ functionName: 'hook',
811
+ });
812
+ return address.toLowerCase();
813
+ }))));
814
+ }
815
+ /** @internal */
816
+ _getFreeAccountId() {
817
+ return this._query(null, () => this._root._protocolAddresses(this.pool.chainId).pipe(map(({ accounting }) => ({ accounting, id: null, triesLeft: 10 })), expand(({ accounting, triesLeft }) => {
818
+ const id = Number(randomUint(32));
819
+ if (triesLeft <= 0)
820
+ return EMPTY;
821
+ return defer(async () => {
822
+ const exists = await this._root.getClient(this.pool.chainId).readContract({
823
+ address: accounting,
824
+ abi: ABI.Accounting,
825
+ functionName: 'exists',
826
+ args: [this.pool.id.raw, id],
827
+ });
828
+ return { accounting, id: exists ? null : id, triesLeft: triesLeft - 1 };
829
+ });
830
+ }), filter(({ id }) => !!id), map(({ id }) => id)));
831
+ }
832
+ }
833
+ //# sourceMappingURL=ShareClass.js.map