@centrifuge/sdk 0.0.0-alpha.5 → 0.0.0-alpha.50

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 (396) hide show
  1. package/README.md +19 -8
  2. package/dist/Centrifuge.d.ts +279 -426
  3. package/dist/Centrifuge.d.ts.map +1 -1
  4. package/dist/Centrifuge.js +642 -144
  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 +529 -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 +16 -0
  29. package/dist/abi/Currency.abi.js.map +1 -0
  30. package/dist/abi/ERC6909.abi.d.ts +3 -0
  31. package/dist/abi/ERC6909.abi.d.ts.map +1 -0
  32. package/dist/abi/ERC6909.abi.js +22 -0
  33. package/dist/abi/ERC6909.abi.js.map +1 -0
  34. package/dist/abi/GasService.abi.d.ts +3 -0
  35. package/dist/abi/GasService.abi.d.ts.map +1 -0
  36. package/dist/abi/GasService.abi.js +32 -0
  37. package/dist/abi/GasService.abi.js.map +1 -0
  38. package/dist/abi/Holdings.abi.d.ts +3 -0
  39. package/dist/abi/Holdings.abi.d.ts.map +1 -0
  40. package/dist/abi/Holdings.abi.js +43 -0
  41. package/dist/abi/Holdings.abi.js.map +1 -0
  42. package/dist/abi/Hub.abi.d.ts +3 -0
  43. package/dist/abi/Hub.abi.d.ts.map +1 -0
  44. package/dist/abi/Hub.abi.js +89 -0
  45. package/dist/abi/Hub.abi.js.map +1 -0
  46. package/dist/abi/HubRegistry.abi.d.ts +3 -0
  47. package/dist/abi/HubRegistry.abi.d.ts.map +1 -0
  48. package/dist/abi/HubRegistry.abi.js +39 -0
  49. package/dist/abi/HubRegistry.abi.js.map +1 -0
  50. package/dist/abi/MessageDispatcher.abi.d.ts +3 -0
  51. package/dist/abi/MessageDispatcher.abi.d.ts.map +1 -0
  52. package/dist/abi/MessageDispatcher.abi.js +49 -0
  53. package/dist/abi/MessageDispatcher.abi.js.map +1 -0
  54. package/dist/abi/MultiAdapter.abi.d.ts +3 -0
  55. package/dist/abi/MultiAdapter.abi.d.ts.map +1 -0
  56. package/dist/abi/MultiAdapter.abi.js +53 -0
  57. package/dist/abi/MultiAdapter.abi.js.map +1 -0
  58. package/dist/abi/PoolEscrow.abi.d.ts +3 -0
  59. package/dist/abi/PoolEscrow.abi.d.ts.map +1 -0
  60. package/dist/abi/PoolEscrow.abi.js +32 -0
  61. package/dist/abi/PoolEscrow.abi.js.map +1 -0
  62. package/dist/abi/PoolEscrowFactory.abi.d.ts +3 -0
  63. package/dist/abi/PoolEscrowFactory.abi.d.ts.map +1 -0
  64. package/dist/abi/PoolEscrowFactory.abi.js +19 -0
  65. package/dist/abi/PoolEscrowFactory.abi.js.map +1 -0
  66. package/dist/abi/RestrictionManager.abi.d.ts +3 -0
  67. package/dist/abi/RestrictionManager.abi.d.ts.map +1 -0
  68. package/dist/abi/RestrictionManager.abi.js +23 -0
  69. package/dist/abi/RestrictionManager.abi.js.map +1 -0
  70. package/dist/abi/ShareClassManager.abi.d.ts +3 -0
  71. package/dist/abi/ShareClassManager.abi.d.ts.map +1 -0
  72. package/dist/abi/ShareClassManager.abi.js +89 -0
  73. package/dist/abi/ShareClassManager.abi.js.map +1 -0
  74. package/dist/abi/Spoke.abi.d.ts +3 -0
  75. package/dist/abi/Spoke.abi.d.ts.map +1 -0
  76. package/dist/abi/Spoke.abi.js +90 -0
  77. package/dist/abi/Spoke.abi.js.map +1 -0
  78. package/dist/abi/SyncRequestManager.abi.d.ts +3 -0
  79. package/dist/abi/SyncRequestManager.abi.d.ts.map +1 -0
  80. package/dist/abi/SyncRequestManager.abi.js +61 -0
  81. package/dist/abi/SyncRequestManager.abi.js.map +1 -0
  82. package/dist/abi/Valuation.abi.d.ts +3 -0
  83. package/dist/abi/Valuation.abi.d.ts.map +1 -0
  84. package/dist/abi/Valuation.abi.js +2 -0
  85. package/dist/abi/Valuation.abi.js.map +1 -0
  86. package/dist/abi/VaultRouter.abi.d.ts +3 -0
  87. package/dist/abi/VaultRouter.abi.d.ts.map +1 -0
  88. package/dist/abi/VaultRouter.abi.js +50 -0
  89. package/dist/abi/VaultRouter.abi.js.map +1 -0
  90. package/dist/abi/index.d.ts +8696 -8
  91. package/dist/abi/index.d.ts.map +1 -1
  92. package/dist/abi/index.js +40 -16
  93. package/dist/abi/index.js.map +1 -1
  94. package/dist/config/chains.d.ts +184 -925
  95. package/dist/config/chains.d.ts.map +1 -1
  96. package/dist/config/chains.js +2 -2
  97. package/dist/config/chains.js.map +1 -1
  98. package/dist/config/protocol.d.ts +3 -0
  99. package/dist/config/protocol.d.ts.map +1 -0
  100. package/dist/config/protocol.js +7 -0
  101. package/dist/config/protocol.js.map +1 -0
  102. package/dist/entities/BalanceSheet.d.ts +48 -0
  103. package/dist/entities/BalanceSheet.d.ts.map +1 -0
  104. package/dist/entities/BalanceSheet.js +94 -0
  105. package/dist/entities/BalanceSheet.js.map +1 -0
  106. package/dist/entities/BalanceSheet.test.d.ts +2 -0
  107. package/dist/entities/BalanceSheet.test.d.ts.map +1 -0
  108. package/dist/entities/BalanceSheet.test.js +64 -0
  109. package/dist/entities/BalanceSheet.test.js.map +1 -0
  110. package/dist/entities/Entity.d.ts +8 -0
  111. package/dist/entities/Entity.d.ts.map +1 -0
  112. package/dist/{Entity.js → entities/Entity.js} +5 -3
  113. package/dist/entities/Entity.js.map +1 -0
  114. package/dist/{IndexerQueries → entities/IndexerQueries}/assetSnapshots.d.ts +14 -14
  115. package/dist/entities/IndexerQueries/assetSnapshots.d.ts.map +1 -0
  116. package/dist/{IndexerQueries → entities/IndexerQueries}/assetSnapshots.js +16 -16
  117. package/dist/entities/IndexerQueries/assetSnapshots.js.map +1 -0
  118. package/dist/{IndexerQueries → entities/IndexerQueries}/assetTransactions.d.ts +9 -6
  119. package/dist/entities/IndexerQueries/assetTransactions.d.ts.map +1 -0
  120. package/dist/{IndexerQueries → entities/IndexerQueries}/assetTransactions.js +8 -7
  121. package/dist/entities/IndexerQueries/assetTransactions.js.map +1 -0
  122. package/dist/entities/IndexerQueries/epochs.d.ts +45 -0
  123. package/dist/entities/IndexerQueries/epochs.d.ts.map +1 -0
  124. package/dist/entities/IndexerQueries/epochs.js +51 -0
  125. package/dist/entities/IndexerQueries/epochs.js.map +1 -0
  126. package/dist/{IndexerQueries → entities/IndexerQueries}/index.d.ts +24 -22
  127. package/dist/entities/IndexerQueries/index.d.ts.map +1 -0
  128. package/dist/{IndexerQueries → entities/IndexerQueries}/index.js +10 -6
  129. package/dist/entities/IndexerQueries/index.js.map +1 -0
  130. package/dist/{IndexerQueries → entities/IndexerQueries}/investorTransactions.d.ts +4 -4
  131. package/dist/entities/IndexerQueries/investorTransactions.d.ts.map +1 -0
  132. package/dist/{IndexerQueries → entities/IndexerQueries}/investorTransactions.js +4 -4
  133. package/dist/entities/IndexerQueries/investorTransactions.js.map +1 -0
  134. package/dist/{IndexerQueries → entities/IndexerQueries}/poolFeeSnapshots.d.ts +8 -8
  135. package/dist/entities/IndexerQueries/poolFeeSnapshots.d.ts.map +1 -0
  136. package/dist/{IndexerQueries → entities/IndexerQueries}/poolFeeSnapshots.js +8 -8
  137. package/dist/entities/IndexerQueries/poolFeeSnapshots.js.map +1 -0
  138. package/dist/{IndexerQueries → entities/IndexerQueries}/poolFeeTransactions.d.ts +3 -3
  139. package/dist/entities/IndexerQueries/poolFeeTransactions.d.ts.map +1 -0
  140. package/dist/{IndexerQueries → entities/IndexerQueries}/poolFeeTransactions.js +3 -3
  141. package/dist/entities/IndexerQueries/poolFeeTransactions.js.map +1 -0
  142. package/dist/{IndexerQueries → entities/IndexerQueries}/poolSnapshots.d.ts +30 -24
  143. package/dist/entities/IndexerQueries/poolSnapshots.d.ts.map +1 -0
  144. package/dist/{IndexerQueries → entities/IndexerQueries}/poolSnapshots.js +29 -23
  145. package/dist/entities/IndexerQueries/poolSnapshots.js.map +1 -0
  146. package/dist/{IndexerQueries → entities/IndexerQueries}/trancheCurrencyBalance.d.ts +15 -17
  147. package/dist/entities/IndexerQueries/trancheCurrencyBalance.d.ts.map +1 -0
  148. package/dist/entities/IndexerQueries/trancheCurrencyBalance.js +63 -0
  149. package/dist/entities/IndexerQueries/trancheCurrencyBalance.js.map +1 -0
  150. package/dist/{IndexerQueries → entities/IndexerQueries}/trancheSnapshots.d.ts +6 -6
  151. package/dist/entities/IndexerQueries/trancheSnapshots.d.ts.map +1 -0
  152. package/dist/{IndexerQueries → entities/IndexerQueries}/trancheSnapshots.js +6 -6
  153. package/dist/entities/IndexerQueries/trancheSnapshots.js.map +1 -0
  154. package/dist/entities/Investor.d.ts +33 -0
  155. package/dist/entities/Investor.d.ts.map +1 -0
  156. package/dist/entities/Investor.js +59 -0
  157. package/dist/entities/Investor.js.map +1 -0
  158. package/dist/entities/Investor.test.d.ts +2 -0
  159. package/dist/entities/Investor.test.d.ts.map +1 -0
  160. package/dist/entities/Investor.test.js +74 -0
  161. package/dist/entities/Investor.test.js.map +1 -0
  162. package/dist/entities/Pool.d.ts +155 -0
  163. package/dist/entities/Pool.d.ts.map +1 -0
  164. package/dist/entities/Pool.js +590 -0
  165. package/dist/entities/Pool.js.map +1 -0
  166. package/dist/entities/Pool.test.d.ts +2 -0
  167. package/dist/entities/Pool.test.d.ts.map +1 -0
  168. package/dist/entities/Pool.test.js +270 -0
  169. package/dist/entities/Pool.test.js.map +1 -0
  170. package/dist/entities/PoolNetwork.d.ts +73 -0
  171. package/dist/entities/PoolNetwork.d.ts.map +1 -0
  172. package/dist/entities/PoolNetwork.js +318 -0
  173. package/dist/entities/PoolNetwork.js.map +1 -0
  174. package/dist/entities/PoolNetwork.test.d.ts +2 -0
  175. package/dist/entities/PoolNetwork.test.d.ts.map +1 -0
  176. package/dist/entities/PoolNetwork.test.js +112 -0
  177. package/dist/entities/PoolNetwork.test.js.map +1 -0
  178. package/dist/{Reports → entities/Reports}/Processor.d.ts +3 -1
  179. package/dist/entities/Reports/Processor.d.ts.map +1 -0
  180. package/dist/{Reports → entities/Reports}/Processor.js +100 -22
  181. package/dist/entities/Reports/Processor.js.map +1 -0
  182. package/dist/entities/Reports/Processor.test.d.ts +2 -0
  183. package/dist/entities/Reports/Processor.test.d.ts.map +1 -0
  184. package/dist/entities/Reports/Processor.test.js +767 -0
  185. package/dist/entities/Reports/Processor.test.js.map +1 -0
  186. package/dist/entities/Reports/Reports.test.d.ts +2 -0
  187. package/dist/entities/Reports/Reports.test.d.ts.map +1 -0
  188. package/dist/entities/Reports/Reports.test.js +559 -0
  189. package/dist/entities/Reports/Reports.test.js.map +1 -0
  190. package/dist/entities/Reports/index.d.ts +21 -0
  191. package/dist/entities/Reports/index.d.ts.map +1 -0
  192. package/dist/{Reports → entities/Reports}/index.js +25 -7
  193. package/dist/entities/Reports/index.js.map +1 -0
  194. package/dist/entities/ShareClass.d.ts +196 -0
  195. package/dist/entities/ShareClass.d.ts.map +1 -0
  196. package/dist/entities/ShareClass.js +1189 -0
  197. package/dist/entities/ShareClass.js.map +1 -0
  198. package/dist/entities/ShareClass.test.d.ts +2 -0
  199. package/dist/entities/ShareClass.test.d.ts.map +1 -0
  200. package/dist/entities/ShareClass.test.js +500 -0
  201. package/dist/entities/ShareClass.test.js.map +1 -0
  202. package/dist/entities/Vault.d.ts +92 -0
  203. package/dist/entities/Vault.d.ts.map +1 -0
  204. package/dist/entities/Vault.js +434 -0
  205. package/dist/entities/Vault.js.map +1 -0
  206. package/dist/entities/Vault.test.d.ts +2 -0
  207. package/dist/entities/Vault.test.d.ts.map +1 -0
  208. package/dist/entities/Vault.test.js +306 -0
  209. package/dist/entities/Vault.test.js.map +1 -0
  210. package/dist/index.d.ts +16 -6
  211. package/dist/index.d.ts.map +1 -1
  212. package/dist/index.js +10 -6
  213. package/dist/index.js.map +1 -1
  214. package/dist/tests/forkServer.d.mts +2 -0
  215. package/dist/tests/forkServer.d.mts.map +1 -0
  216. package/dist/tests/forkServer.mjs +104 -0
  217. package/dist/tests/forkServer.mjs.map +1 -0
  218. package/dist/tests/mocks/mockAssetSnapshots.d.ts +1 -1
  219. package/dist/tests/mocks/mockAssetSnapshots.d.ts.map +1 -1
  220. package/dist/tests/mocks/mockAssetSnapshots.js +27 -27
  221. package/dist/tests/mocks/mockAssetSnapshots.js.map +1 -1
  222. package/dist/tests/mocks/mockAssetTransactions.d.ts +1 -1
  223. package/dist/tests/mocks/mockAssetTransactions.d.ts.map +1 -1
  224. package/dist/tests/mocks/mockAssetTransactions.js +24 -19
  225. package/dist/tests/mocks/mockAssetTransactions.js.map +1 -1
  226. package/dist/tests/mocks/mockEpochs.d.ts +3 -0
  227. package/dist/tests/mocks/mockEpochs.d.ts.map +1 -0
  228. package/dist/tests/mocks/mockEpochs.js +26 -0
  229. package/dist/tests/mocks/mockEpochs.js.map +1 -0
  230. package/dist/tests/mocks/mockInvestorCurrencyBalance.d.ts +1 -1
  231. package/dist/tests/mocks/mockInvestorCurrencyBalance.d.ts.map +1 -1
  232. package/dist/tests/mocks/mockInvestorCurrencyBalance.js +15 -15
  233. package/dist/tests/mocks/mockInvestorCurrencyBalance.js.map +1 -1
  234. package/dist/tests/mocks/mockInvestorTransactions.d.ts +1 -1
  235. package/dist/tests/mocks/mockInvestorTransactions.d.ts.map +1 -1
  236. package/dist/tests/mocks/mockInvestorTransactions.js +5 -5
  237. package/dist/tests/mocks/mockInvestorTransactions.js.map +1 -1
  238. package/dist/tests/mocks/mockPoolFeeSnapshot.d.ts +1 -1
  239. package/dist/tests/mocks/mockPoolFeeSnapshot.d.ts.map +1 -1
  240. package/dist/tests/mocks/mockPoolFeeSnapshot.js +29 -29
  241. package/dist/tests/mocks/mockPoolFeeSnapshot.js.map +1 -1
  242. package/dist/tests/mocks/mockPoolFeeTransactions.d.ts +3 -3
  243. package/dist/tests/mocks/mockPoolFeeTransactions.d.ts.map +1 -1
  244. package/dist/tests/mocks/mockPoolFeeTransactions.js +3 -3
  245. package/dist/tests/mocks/mockPoolFeeTransactions.js.map +1 -1
  246. package/dist/tests/mocks/mockPoolMetadata.d.ts.map +1 -1
  247. package/dist/tests/mocks/mockPoolMetadata.js +7 -17
  248. package/dist/tests/mocks/mockPoolMetadata.js.map +1 -1
  249. package/dist/tests/mocks/mockPoolSnapshots.d.ts +1 -1
  250. package/dist/tests/mocks/mockPoolSnapshots.d.ts.map +1 -1
  251. package/dist/tests/mocks/mockPoolSnapshots.js +47 -45
  252. package/dist/tests/mocks/mockPoolSnapshots.js.map +1 -1
  253. package/dist/tests/mocks/mockTrancheSnapshots.d.ts +1 -1
  254. package/dist/tests/mocks/mockTrancheSnapshots.d.ts.map +1 -1
  255. package/dist/tests/mocks/mockTrancheSnapshots.js +21 -21
  256. package/dist/tests/mocks/mockTrancheSnapshots.js.map +1 -1
  257. package/dist/tests/setup.d.ts.map +1 -1
  258. package/dist/tests/setup.js +4 -3
  259. package/dist/tests/setup.js.map +1 -1
  260. package/dist/tests/tenderly.d.ts +15 -2
  261. package/dist/tests/tenderly.d.ts.map +1 -1
  262. package/dist/tests/tenderly.js +74 -67
  263. package/dist/tests/tenderly.js.map +1 -1
  264. package/dist/tests/utils.d.ts +3 -0
  265. package/dist/tests/utils.d.ts.map +1 -0
  266. package/dist/tests/utils.js +4 -0
  267. package/dist/tests/utils.js.map +1 -0
  268. package/dist/types/holdings.d.ts +9 -0
  269. package/dist/types/holdings.d.ts.map +1 -0
  270. package/dist/types/holdings.js +10 -0
  271. package/dist/types/holdings.js.map +1 -0
  272. package/dist/types/index.d.ts +64 -0
  273. package/dist/types/index.d.ts.map +1 -1
  274. package/dist/types/poolInput.d.ts +71 -0
  275. package/dist/types/poolInput.d.ts.map +1 -0
  276. package/dist/types/poolInput.js +2 -0
  277. package/dist/types/poolInput.js.map +1 -0
  278. package/dist/types/poolMetadata.d.ts +14 -13
  279. package/dist/types/poolMetadata.d.ts.map +1 -1
  280. package/dist/types/reports.d.ts +130 -69
  281. package/dist/types/reports.d.ts.map +1 -1
  282. package/dist/types/transaction.d.ts +60 -3
  283. package/dist/types/transaction.d.ts.map +1 -1
  284. package/dist/types/transaction.js +55 -1
  285. package/dist/types/transaction.js.map +1 -1
  286. package/dist/utils/BigInt.d.ts +16 -35
  287. package/dist/utils/BigInt.d.ts.map +1 -1
  288. package/dist/utils/BigInt.js +18 -25
  289. package/dist/utils/BigInt.js.map +1 -1
  290. package/dist/utils/BigInt.test.d.ts +2 -0
  291. package/dist/utils/BigInt.test.d.ts.map +1 -0
  292. package/dist/utils/BigInt.test.js +298 -0
  293. package/dist/utils/BigInt.test.js.map +1 -0
  294. package/dist/utils/currencies.d.ts +5 -0
  295. package/dist/utils/currencies.d.ts.map +1 -0
  296. package/dist/utils/currencies.js +7 -0
  297. package/dist/utils/currencies.js.map +1 -0
  298. package/dist/utils/decimal.d.ts +2 -2
  299. package/dist/utils/decimal.d.ts.map +1 -1
  300. package/dist/utils/decimal.js.map +1 -1
  301. package/dist/utils/index.d.ts +4 -0
  302. package/dist/utils/index.d.ts.map +1 -0
  303. package/dist/utils/index.js +24 -0
  304. package/dist/utils/index.js.map +1 -0
  305. package/dist/utils/ipfs.d.ts +7 -0
  306. package/dist/utils/ipfs.d.ts.map +1 -0
  307. package/dist/utils/ipfs.js +64 -0
  308. package/dist/utils/ipfs.js.map +1 -0
  309. package/dist/utils/ipfs.test.d.ts +2 -0
  310. package/dist/utils/ipfs.test.d.ts.map +1 -0
  311. package/dist/utils/ipfs.test.js +54 -0
  312. package/dist/utils/ipfs.test.js.map +1 -0
  313. package/dist/utils/permit.d.ts +13 -0
  314. package/dist/utils/permit.d.ts.map +1 -0
  315. package/dist/utils/permit.js +82 -0
  316. package/dist/utils/permit.js.map +1 -0
  317. package/dist/utils/permit.test.d.ts +2 -0
  318. package/dist/utils/permit.test.d.ts.map +1 -0
  319. package/dist/utils/permit.test.js +22 -0
  320. package/dist/utils/permit.test.js.map +1 -0
  321. package/dist/utils/rx.d.ts +1 -1
  322. package/dist/utils/rx.d.ts.map +1 -1
  323. package/dist/utils/rx.js +4 -0
  324. package/dist/utils/rx.js.map +1 -1
  325. package/dist/utils/transaction.d.ts +15 -10
  326. package/dist/utils/transaction.d.ts.map +1 -1
  327. package/dist/utils/transaction.js +57 -21
  328. package/dist/utils/transaction.js.map +1 -1
  329. package/dist/utils/types.d.ts +39 -0
  330. package/dist/utils/types.d.ts.map +1 -0
  331. package/dist/utils/types.js +89 -0
  332. package/dist/utils/types.js.map +1 -0
  333. package/dist/utils/types.test.d.ts +2 -0
  334. package/dist/utils/types.test.d.ts.map +1 -0
  335. package/dist/utils/types.test.js +89 -0
  336. package/dist/utils/types.test.js.map +1 -0
  337. package/package.json +14 -9
  338. package/dist/Account.d.ts +0 -11
  339. package/dist/Account.d.ts.map +0 -1
  340. package/dist/Account.js +0 -46
  341. package/dist/Account.js.map +0 -1
  342. package/dist/Entity.d.ts +0 -12
  343. package/dist/Entity.d.ts.map +0 -1
  344. package/dist/Entity.js.map +0 -1
  345. package/dist/IndexerQueries/assetSnapshots.d.ts.map +0 -1
  346. package/dist/IndexerQueries/assetSnapshots.js.map +0 -1
  347. package/dist/IndexerQueries/assetTransactions.d.ts.map +0 -1
  348. package/dist/IndexerQueries/assetTransactions.js.map +0 -1
  349. package/dist/IndexerQueries/index.d.ts.map +0 -1
  350. package/dist/IndexerQueries/index.js.map +0 -1
  351. package/dist/IndexerQueries/investorTransactions.d.ts.map +0 -1
  352. package/dist/IndexerQueries/investorTransactions.js.map +0 -1
  353. package/dist/IndexerQueries/poolFeeSnapshots.d.ts.map +0 -1
  354. package/dist/IndexerQueries/poolFeeSnapshots.js.map +0 -1
  355. package/dist/IndexerQueries/poolFeeTransactions.d.ts.map +0 -1
  356. package/dist/IndexerQueries/poolFeeTransactions.js.map +0 -1
  357. package/dist/IndexerQueries/poolSnapshots.d.ts.map +0 -1
  358. package/dist/IndexerQueries/poolSnapshots.js.map +0 -1
  359. package/dist/IndexerQueries/trancheCurrencyBalance.d.ts.map +0 -1
  360. package/dist/IndexerQueries/trancheCurrencyBalance.js +0 -103
  361. package/dist/IndexerQueries/trancheCurrencyBalance.js.map +0 -1
  362. package/dist/IndexerQueries/trancheSnapshots.d.ts.map +0 -1
  363. package/dist/IndexerQueries/trancheSnapshots.js.map +0 -1
  364. package/dist/Pool.d.ts +0 -27
  365. package/dist/Pool.d.ts.map +0 -1
  366. package/dist/Pool.js +0 -76
  367. package/dist/Pool.js.map +0 -1
  368. package/dist/PoolNetwork.d.ts +0 -82
  369. package/dist/PoolNetwork.d.ts.map +0 -1
  370. package/dist/PoolNetwork.js +0 -236
  371. package/dist/PoolNetwork.js.map +0 -1
  372. package/dist/Reports/Processor.d.ts.map +0 -1
  373. package/dist/Reports/Processor.js.map +0 -1
  374. package/dist/Reports/index.d.ts +0 -27
  375. package/dist/Reports/index.d.ts.map +0 -1
  376. package/dist/Reports/index.js.map +0 -1
  377. package/dist/Vault.d.ts +0 -96
  378. package/dist/Vault.d.ts.map +0 -1
  379. package/dist/Vault.js +0 -330
  380. package/dist/Vault.js.map +0 -1
  381. package/dist/abi/CentrifugeRouter.abi.json +0 -43
  382. package/dist/abi/Currency.abi.json +0 -14
  383. package/dist/abi/Gateway.abi.json +0 -1
  384. package/dist/abi/InvestmentManager.abi.json +0 -4
  385. package/dist/abi/LiquidityPool.abi.json +0 -79
  386. package/dist/abi/PoolManager.abi.json +0 -55
  387. package/dist/abi/RestrictionManager.abi.json +0 -22
  388. package/dist/abi/Router.abi.json +0 -1
  389. package/dist/config/lp.d.ts +0 -17
  390. package/dist/config/lp.d.ts.map +0 -1
  391. package/dist/config/lp.js +0 -35
  392. package/dist/config/lp.js.map +0 -1
  393. package/dist/utils/pinToApi.d.ts +0 -2
  394. package/dist/utils/pinToApi.d.ts.map +0 -1
  395. package/dist/utils/pinToApi.js +0 -10
  396. package/dist/utils/pinToApi.js.map +0 -1
@@ -1,40 +1,35 @@
1
- import { concatWith, defaultIfEmpty, defer, filter, identity, isObservable, map, mergeMap, of, Subject, switchMap, using, } from 'rxjs';
1
+ import { combineLatest, concatWith, defaultIfEmpty, defer, filter, first, identity, isObservable, map, mergeMap, of, Subject, switchMap, timer, using, } from 'rxjs';
2
2
  import { fromFetch } from 'rxjs/fetch';
3
- import { createPublicClient, createWalletClient, custom, getContract, http, parseEventLogs, } from 'viem';
3
+ import { createPublicClient, createWalletClient, custom, encodeFunctionData, fallback, getContract, http, parseAbi, parseEventLogs, toHex, } from 'viem';
4
4
  import { ABI } from './abi/index.js';
5
- import { Account } from './Account.js';
6
5
  import { chains } from './config/chains.js';
7
6
  import { PERMIT_TYPEHASH } from './constants.js';
8
- import { Pool } from './Pool.js';
9
- import { Currency } from './utils/BigInt.js';
7
+ import { Investor } from './entities/Investor.js';
8
+ import { Pool } from './entities/Pool.js';
9
+ import { emptyMessage, MessageType, } from './types/transaction.js';
10
+ import { Balance } from './utils/BigInt.js';
11
+ import { randomUint } from './utils/index.js';
12
+ import { createPinning, getUrlFromHash } from './utils/ipfs.js';
10
13
  import { hashKey } from './utils/query.js';
11
14
  import { makeThenable, repeatOnEvents, shareReplayWithDelayedReset } from './utils/rx.js';
12
- import { doTransaction, isLocalAccount } from './utils/transaction.js';
15
+ import { doTransaction, isLocalAccount, wrapTransaction } from './utils/transaction.js';
16
+ import { AssetId, PoolId, ShareClassId } from './utils/types.js';
17
+ const PINNING_API_DEMO = 'https://europe-central2-peak-vista-185616.cloudfunctions.net/pinning-api-demo';
13
18
  const envConfig = {
14
19
  mainnet: {
15
- indexerUrl: 'https://subql.embrio.tech/',
16
- alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
17
- infuraKey: '8ed99a9a115349bbbc01dcf3a24edc96',
18
- defaultChain: 1,
20
+ indexerUrl: 'https://api.centrifuge.io',
19
21
  ipfsUrl: 'https://centrifuge.mypinata.cloud',
22
+ ...createPinning(PINNING_API_DEMO),
20
23
  },
21
- demo: {
22
- indexerUrl: 'https://api.subquery.network/sq/centrifuge/pools-demo-multichain',
23
- alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
24
- infuraKey: '8cd8e043ee8d4001b97a1c37e08fd9dd',
25
- defaultChain: 11155111,
26
- ipfsUrl: 'https://centrifuge.mypinata.cloud',
27
- },
28
- dev: {
29
- indexerUrl: 'https://api.subquery.network/sq/centrifuge/pools-demo-multichain',
30
- alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
31
- infuraKey: '8cd8e043ee8d4001b97a1c37e08fd9dd',
32
- defaultChain: 11155111,
24
+ testnet: {
25
+ indexerUrl: 'https://api-v3-hitz.marble.live/graphql',
33
26
  ipfsUrl: 'https://centrifuge.mypinata.cloud',
27
+ ...createPinning(PINNING_API_DEMO),
34
28
  },
35
29
  };
36
30
  const defaultConfig = {
37
31
  environment: 'mainnet',
32
+ cache: true,
38
33
  };
39
34
  export class Centrifuge {
40
35
  #config;
@@ -43,13 +38,16 @@ export class Centrifuge {
43
38
  }
44
39
  #clients = new Map();
45
40
  getClient(chainId) {
46
- return this.#clients.get(chainId ?? this.config.defaultChain);
41
+ const client = this.#clients.get(chainId);
42
+ if (!client)
43
+ throw new Error(`No client found for chain ID "${chainId}"`);
44
+ return client;
47
45
  }
48
46
  get chains() {
49
47
  return [...this.#clients.keys()];
50
48
  }
51
49
  getChainConfig(chainId) {
52
- return this.getClient(chainId ?? this.config.defaultChain).chain;
50
+ return this.getClient(chainId).chain;
53
51
  }
54
52
  #signer = null;
55
53
  setSigner(signer) {
@@ -58,8 +56,9 @@ export class Centrifuge {
58
56
  get signer() {
59
57
  return this.#signer;
60
58
  }
59
+ #isBatching = new WeakSet();
61
60
  constructor(config = {}) {
62
- const defaultConfigForEnv = envConfig[config?.environment ?? 'mainnet'];
61
+ const defaultConfigForEnv = envConfig[config?.environment || 'mainnet'];
63
62
  this.#config = {
64
63
  ...defaultConfig,
65
64
  ...defaultConfigForEnv,
@@ -73,47 +72,253 @@ export class Centrifuge {
73
72
  if (!rpcUrl) {
74
73
  console.warn(`No rpcUrl defined for chain ${chain.id}. Using public RPC endpoint.`);
75
74
  }
76
- this.#clients.set(chain.id, createPublicClient({ chain, transport: http(rpcUrl), batch: { multicall: true } }));
75
+ this.#clients.set(chain.id, createPublicClient({
76
+ chain,
77
+ transport: Array.isArray(rpcUrl)
78
+ ? fallback(rpcUrl.map((url) => http(url)), {
79
+ rank: {
80
+ interval: 30_000,
81
+ sampleCount: 5,
82
+ },
83
+ })
84
+ : http(rpcUrl),
85
+ batch: { multicall: true },
86
+ pollingInterval: this.#config.pollingInterval,
87
+ cacheTime: 100,
88
+ }));
77
89
  });
78
90
  }
79
- pool(id, metadataHash) {
80
- return this._query(null, () => of(new Pool(this, id, metadataHash)));
91
+ /**
92
+ * Create a new pool on the given chain.
93
+ * @param metadataInput - The metadata for the pool
94
+ * @param currencyCode - The currency code for the pool
95
+ * @param chainId - The chain ID to create the pool on
96
+ * @param counter - The pool counter, used to create a unique pool ID (uint48)
97
+ */
98
+ createPool(metadataInput, currencyCode = 840, chainId, counter) {
99
+ const self = this;
100
+ return this._transact(async function* ({ walletClient, signingAddress, publicClient }) {
101
+ const [addresses, id] = await Promise.all([self._protocolAddresses(chainId), self.id(chainId)]);
102
+ const poolId = PoolId.from(id, counter ?? randomUint(48));
103
+ const createPoolData = encodeFunctionData({
104
+ abi: ABI.Hub,
105
+ functionName: 'createPool',
106
+ args: [poolId.raw, signingAddress, BigInt(currencyCode)],
107
+ });
108
+ const scIds = Array.from({ length: metadataInput.shareClasses.length }, (_, i) => ShareClassId.from(poolId, i + 1));
109
+ const shareClassesById = {};
110
+ metadataInput.shareClasses.forEach((sc, index) => {
111
+ shareClassesById[scIds[index].raw] = {
112
+ minInitialInvestment: sc.minInvestment,
113
+ apyPercentage: sc.apyPercentage,
114
+ apy: sc.apy,
115
+ defaultAccounts: sc.defaultAccounts,
116
+ };
117
+ });
118
+ const formattedMetadata = {
119
+ version: 1,
120
+ pool: {
121
+ name: metadataInput.poolName,
122
+ icon: metadataInput.poolIcon,
123
+ asset: {
124
+ class: metadataInput.assetClass,
125
+ subClass: metadataInput.subAssetClass,
126
+ },
127
+ issuer: {
128
+ name: metadataInput.issuerName,
129
+ repName: metadataInput.issuerRepName,
130
+ description: metadataInput.issuerDescription,
131
+ email: metadataInput.email,
132
+ logo: metadataInput.issuerLogo,
133
+ shortDescription: metadataInput.issuerShortDescription,
134
+ categories: metadataInput.issuerCategories,
135
+ },
136
+ poolStructure: metadataInput.poolStructure,
137
+ investorType: metadataInput.investorType,
138
+ links: {
139
+ executiveSummary: metadataInput.executiveSummary,
140
+ forum: metadataInput.forum,
141
+ website: metadataInput.website,
142
+ },
143
+ details: metadataInput.details,
144
+ status: 'open',
145
+ listed: metadataInput.listed ?? true,
146
+ poolRatings: metadataInput.poolRatings.length > 0 ? metadataInput.poolRatings : [],
147
+ reports: metadataInput.report
148
+ ? [
149
+ {
150
+ author: {
151
+ name: metadataInput.report.author.name,
152
+ title: metadataInput.report.author.title,
153
+ avatar: metadataInput.report.author.avatar,
154
+ },
155
+ uri: metadataInput.report.uri,
156
+ },
157
+ ]
158
+ : [],
159
+ },
160
+ shareClasses: shareClassesById,
161
+ onboarding: {
162
+ shareClasses: metadataInput.onboarding?.shareClasses || {},
163
+ taxInfoRequired: metadataInput.onboarding?.taxInfoRequired,
164
+ externalOnboardingUrl: metadataInput.onboarding?.externalOnboardingUrl,
165
+ },
166
+ };
167
+ const cid = await self.config.pinJson(formattedMetadata);
168
+ const setMetadataData = encodeFunctionData({
169
+ abi: ABI.Hub,
170
+ functionName: 'setPoolMetadata',
171
+ args: [poolId.raw, toHex(cid)],
172
+ });
173
+ const addScData = metadataInput.shareClasses.map((sc) => encodeFunctionData({
174
+ abi: ABI.Hub,
175
+ functionName: 'addShareClass',
176
+ args: [
177
+ poolId.raw,
178
+ sc.tokenName,
179
+ sc.symbolName,
180
+ sc.salt?.startsWith('0x') ? sc.salt : toHex(sc.salt ?? randomUint(256), { size: 32 }),
181
+ ],
182
+ }));
183
+ const accountIsDebitNormal = new Map();
184
+ const accountNumbers = [
185
+ ...new Set(metadataInput.shareClasses.flatMap((sc) => Object.entries(sc.defaultAccounts ?? {})
186
+ .filter(([k, v]) => {
187
+ if (!v)
188
+ return false;
189
+ if (['asset', 'expense'].includes(k)) {
190
+ if (accountIsDebitNormal.get(v) === false)
191
+ throw new Error(`Account "${v}" is set as both credit normal and debit normal.`);
192
+ accountIsDebitNormal.set(v, true);
193
+ }
194
+ else {
195
+ if (accountIsDebitNormal.get(v) === true)
196
+ throw new Error(`Account "${v}" is set as both credit normal and debit normal.`);
197
+ accountIsDebitNormal.set(v, false);
198
+ }
199
+ return true;
200
+ })
201
+ .map(([, v]) => v))),
202
+ ];
203
+ const createAccountsData = accountNumbers.map((account) => encodeFunctionData({
204
+ abi: ABI.Hub,
205
+ functionName: 'createAccount',
206
+ args: [poolId.raw, account, accountIsDebitNormal.get(account)],
207
+ }));
208
+ yield* doTransaction('Create pool', publicClient, () => {
209
+ return walletClient.writeContract({
210
+ address: addresses.hub,
211
+ abi: ABI.Hub,
212
+ functionName: 'multicall',
213
+ args: [[createPoolData, setMetadataData, ...addScData, ...createAccountsData]],
214
+ });
215
+ });
216
+ }, chainId);
81
217
  }
82
- account(address, chainId) {
83
- return this._query(null, () => of(new Account(this, address, chainId ?? this.config.defaultChain)));
218
+ id(chainId) {
219
+ return this._query(['centrifugeId', chainId], () => this._protocolAddresses(chainId).pipe(switchMap(({ messageDispatcher }) => {
220
+ return this.getClient(chainId).readContract({
221
+ address: messageDispatcher,
222
+ abi: ABI.MessageDispatcher,
223
+ functionName: 'localCentrifugeId',
224
+ });
225
+ })));
84
226
  }
85
227
  /**
86
- * Get the metadata for an ERC20 token
228
+ * Get the existing pools on the different chains.
229
+ */
230
+ pools() {
231
+ return this._queryIndexer(`{
232
+ pools {
233
+ items {
234
+ id
235
+ blockchain {
236
+ id
237
+ }
238
+ }
239
+ }
240
+ }`, {}, (data) => {
241
+ return data.pools.items.map((pool) => {
242
+ const poolId = new PoolId(pool.id);
243
+ return new Pool(this, poolId.toString(), Number(pool.blockchain.id));
244
+ });
245
+ });
246
+ }
247
+ pool(id) {
248
+ return this._query(null, () => this.pools().pipe(map((pools) => {
249
+ const pool = pools.find((pool) => pool.id.equals(id));
250
+ if (!pool)
251
+ throw new Error(`Pool with id ${id} not found`);
252
+ return pool;
253
+ })));
254
+ }
255
+ /**
256
+ * Get the metadata for an ERC20 or ERC6909 token
87
257
  * @param address - The token address
88
258
  * @param chainId - The chain ID
89
259
  */
90
- currency(address, chainId) {
260
+ currency(address, chainId, tokenId = 0n) {
91
261
  const curAddress = address.toLowerCase();
92
- const cid = chainId ?? this.config.defaultChain;
93
- return this._query(['currency', curAddress, cid], () => defer(async () => {
94
- const contract = getContract({
95
- address: curAddress,
96
- abi: ABI.Currency,
97
- client: this.getClient(cid),
98
- });
99
- const [decimals, name, symbol, supportsPermit] = await Promise.all([
100
- contract.read.decimals(),
101
- contract.read.name(),
102
- contract.read.symbol(),
103
- contract.read.PERMIT_TYPEHASH()
104
- .then((hash) => hash === PERMIT_TYPEHASH)
105
- .catch(() => false),
106
- ]);
262
+ return this._query(['currency', curAddress, chainId, tokenId], () => defer(async () => {
263
+ let decimals, name, symbol, supportsPermit;
264
+ if (tokenId) {
265
+ const contract = getContract({
266
+ address: curAddress,
267
+ abi: ABI.ERC6909,
268
+ client: this.getClient(chainId),
269
+ });
270
+ [decimals, name, symbol] = await Promise.all([
271
+ contract.read.decimals([tokenId]),
272
+ contract.read.name([tokenId]),
273
+ contract.read.symbol([tokenId]),
274
+ ]);
275
+ supportsPermit = false;
276
+ }
277
+ else {
278
+ const contract = getContract({
279
+ address: curAddress,
280
+ abi: ABI.Currency,
281
+ client: this.getClient(chainId),
282
+ });
283
+ [decimals, name, symbol, supportsPermit] = await Promise.all([
284
+ contract.read.decimals(),
285
+ contract.read.name(),
286
+ contract.read.symbol(),
287
+ contract.read
288
+ .PERMIT_TYPEHASH()
289
+ .then((hash) => hash === PERMIT_TYPEHASH)
290
+ .catch(() => false),
291
+ ]);
292
+ }
107
293
  return {
108
294
  address: curAddress,
295
+ tokenId,
109
296
  decimals,
110
297
  name,
111
298
  symbol,
112
- chainId: cid,
299
+ chainId,
113
300
  supportsPermit,
114
301
  };
115
302
  }));
116
303
  }
304
+ /**
305
+ * Get the asset currency details for a given asset ID
306
+ * @param assetId - The asset ID to query
307
+ */
308
+ assetCurrency(assetId) {
309
+ return this._query(['asset', assetId.toString()], () => this._idToChain(assetId.centrifugeId).pipe(switchMap((chainId) => this._protocolAddresses(chainId).pipe(map(({ spoke }) => ({ chainId, spoke })))), switchMap(async ({ spoke, chainId }) => {
310
+ const [assetAddress, tokenId] = await this.getClient(chainId).readContract({
311
+ address: spoke,
312
+ abi: ABI.Spoke,
313
+ functionName: 'idToAsset',
314
+ args: [assetId.raw],
315
+ });
316
+ return this.currency(assetAddress, chainId, tokenId);
317
+ })));
318
+ }
319
+ investor(address) {
320
+ return this._query(null, () => of(new Investor(this, address)));
321
+ }
117
322
  /**
118
323
  * Get the balance of an ERC20 token for a given owner.
119
324
  * @param currency - The token address
@@ -122,16 +327,19 @@ export class Centrifuge {
122
327
  */
123
328
  balance(currency, owner, chainId) {
124
329
  const address = owner.toLowerCase();
125
- const cid = chainId ?? this.config.defaultChain;
126
- return this._query(['balance', currency, owner, cid], () => {
127
- return this.currency(currency, cid).pipe(switchMap((currencyMeta) => defer(() => this.getClient(cid)
128
- .readContract({
129
- address: currency,
130
- abi: ABI.Currency,
131
- functionName: 'balanceOf',
132
- args: [address],
133
- })
134
- .then((val) => new Currency(val, currencyMeta.decimals))).pipe(repeatOnEvents(this, {
330
+ return this._query(['balance', currency, owner, chainId], () => {
331
+ return this.currency(currency, chainId).pipe(switchMap((currencyMeta) => defer(async () => {
332
+ const val = await this.getClient(chainId).readContract({
333
+ address: currency,
334
+ abi: ABI.Currency,
335
+ functionName: 'balanceOf',
336
+ args: [address],
337
+ });
338
+ return {
339
+ balance: new Balance(val, currencyMeta.decimals),
340
+ currency: currencyMeta,
341
+ };
342
+ }).pipe(repeatOnEvents(this, {
135
343
  address: currency,
136
344
  abi: ABI.Currency,
137
345
  eventName: 'Transfer',
@@ -140,18 +348,149 @@ export class Centrifuge {
140
348
  return event.args.from?.toLowerCase() === address || event.args.to?.toLowerCase() === address;
141
349
  });
142
350
  },
143
- }, cid))));
351
+ }, chainId))));
144
352
  });
145
353
  }
354
+ /**
355
+ * Get the assets that exist on a given spoke chain that have been registered on a given hub chain.
356
+ * @param spokeChainId - The chain ID where the assets exist
357
+ * @param hubChainId - The chain ID where the assets should optionally be registered
358
+ */
359
+ assets(spokeChainId, hubChainId = spokeChainId) {
360
+ return this._query(null, () => combineLatest([this.id(spokeChainId), this.id(hubChainId)]).pipe(switchMap(([spokeCentId, hubCentId]) => this._queryIndexer(`query ($hubCentId: String!) {
361
+ assetRegistrations(where: { centrifugeId: $hubCentId, decimals_gt: 0 }) {
362
+ items {
363
+ assetId
364
+ name
365
+ symbol
366
+ decimals
367
+ asset {
368
+ centrifugeId
369
+ address
370
+ }
371
+ }
372
+ }
373
+ }`, { hubCentId: String(hubCentId) }, (data) => {
374
+ return data.assetRegistrations.items
375
+ .filter((assetReg) => assetReg.asset && Number(assetReg.asset.centrifugeId) === spokeCentId)
376
+ .map((assetReg) => {
377
+ return {
378
+ id: new AssetId(assetReg.assetId),
379
+ address: assetReg.asset.address,
380
+ name: assetReg.name,
381
+ symbol: assetReg.symbol,
382
+ decimals: assetReg.decimals,
383
+ };
384
+ });
385
+ }))));
386
+ }
387
+ /**
388
+ * Get the valuation addresses that can be used for holdings.
389
+ */
390
+ valuations(chainId) {
391
+ return this._query(null, () => this._protocolAddresses(chainId).pipe(map(({ identityValuation }) => {
392
+ return {
393
+ identityValuation,
394
+ };
395
+ })));
396
+ }
397
+ /**
398
+ * Get the restriction hook addresses that can be used for share tokens.
399
+ */
400
+ restrictionHooks(chainId) {
401
+ return this._query(null, () => this._protocolAddresses(chainId).pipe(map(({ freezeOnlyHook, redemptionRestrictionsHook, fullRestrictionsHook /* freelyTransferableHook */ }) => {
402
+ return {
403
+ freezeOnlyHook,
404
+ redemptionRestrictionsHook,
405
+ fullRestrictionsHook,
406
+ };
407
+ })));
408
+ }
409
+ /**
410
+ * Register an asset
411
+ * @param originChainId - The chain ID where the asset exists
412
+ * @param registerOnChainId - The chain ID where the asset should be registered
413
+ * @param assetAddress - The address of the asset to register
414
+ * @param tokenId - Optional token ID for ERC6909 assets
415
+ */
416
+ registerAsset(originChainId, registerOnChainId, assetAddress, tokenId = 0) {
417
+ const self = this;
418
+ return this._transact(async function* ({ walletClient, publicClient }) {
419
+ const [addresses, id, estimate] = await Promise.all([
420
+ self._protocolAddresses(originChainId),
421
+ self.id(registerOnChainId),
422
+ self._estimate(originChainId, { chainId: registerOnChainId }, MessageType.RegisterAsset),
423
+ ]);
424
+ yield* doTransaction('Register asset', publicClient, () => walletClient.writeContract({
425
+ address: addresses.spoke,
426
+ abi: ABI.Spoke,
427
+ functionName: 'registerAsset',
428
+ args: [id, assetAddress, BigInt(tokenId)],
429
+ value: estimate,
430
+ }));
431
+ }, originChainId);
432
+ }
433
+ /**
434
+ * Get the decimals of asset on the Hub side
435
+ * @internal
436
+ */
437
+ _assetDecimals(assetId, chainId) {
438
+ return this._query(['assetDecimals', assetId.toString()], () => this._protocolAddresses(chainId).pipe(switchMap(({ hubRegistry }) => this.getClient(chainId).readContract({
439
+ address: hubRegistry,
440
+ // Use inline ABI because of function overload
441
+ abi: parseAbi(['function decimals(uint128) view returns (uint8)']),
442
+ functionName: 'decimals',
443
+ args: [assetId.raw],
444
+ }))));
445
+ }
446
+ /**
447
+ * Get the allowance of an ERC20 or ERC6909 token.
448
+ * which is the contract that moves funds into the vault on behalf of the investor.
449
+ * @param owner - The address of the owner
450
+ * @param spender - The address of the spender
451
+ * @param chainId - The chain ID where the asset is located
452
+ * @param asset - The address of the asset
453
+ * @param tokenId - Optional token ID for ERC6909 assets
454
+ * @internal
455
+ */
456
+ _allowance(owner, spender, chainId, asset, tokenId) {
457
+ return this._query(['allowance', owner.toLowerCase(), spender.toLowerCase(), asset.toLowerCase(), chainId, tokenId], () => defer(async () => {
458
+ const client = this.getClient(chainId);
459
+ if (tokenId) {
460
+ return client.readContract({
461
+ address: asset,
462
+ abi: ABI.ERC6909,
463
+ functionName: 'allowance',
464
+ args: [owner, spender, tokenId],
465
+ });
466
+ }
467
+ return client.readContract({
468
+ address: asset,
469
+ abi: ABI.Currency,
470
+ functionName: 'allowance',
471
+ args: [owner, spender],
472
+ });
473
+ }).pipe(repeatOnEvents(this, {
474
+ address: asset,
475
+ abi: [ABI.Currency, ABI.ERC6909],
476
+ eventName: ['Approval', 'Transfer'],
477
+ filter: (events) => {
478
+ return events.some((event) => {
479
+ return (event.args.owner?.toLowerCase() === owner.toLowerCase() ||
480
+ event.args.spender?.toLowerCase() === owner.toLowerCase() ||
481
+ event.args.from?.toLowerCase() === owner.toLowerCase());
482
+ });
483
+ },
484
+ }, chainId)));
485
+ }
146
486
  /**
147
487
  * Returns an observable of all events on a given chain.
148
488
  * @internal
149
489
  */
150
490
  _events(chainId) {
151
- const cid = chainId ?? this.config.defaultChain;
152
- return this._query(['events', cid], () => using(() => {
491
+ return this._query(['events', chainId], () => using(() => {
153
492
  const subject = new Subject();
154
- const unwatch = this.getClient(cid).watchEvent({
493
+ const unwatch = this.getClient(chainId).watchEvent({
155
494
  onLogs: (logs) => subject.next(logs),
156
495
  });
157
496
  return {
@@ -199,30 +538,26 @@ export class Centrifuge {
199
538
  });
200
539
  }
201
540
  _queryIndexer(query, variables, postProcess) {
202
- return this._query([query, variables], () => this._getIndexerObservable(query, variables).pipe(map(postProcess ?? identity)), {
203
- valueCacheTime: 120,
204
- });
205
- }
206
- /**
207
- * @internal
208
- */
209
- _getIPFSObservable(hash) {
210
- return fromFetch(`${this.config.ipfsUrl}/ipfs/${hash}`, {
211
- method: 'GET',
212
- selector: async (res) => {
213
- if (!res.ok) {
214
- console.warn(`Failed to fetch IPFS data: ${res.statusText}`);
215
- }
216
- const data = await res.json();
217
- return data;
218
- },
219
- });
541
+ return this._query([query, variables], () =>
542
+ // If subscribed, refetch every 2 minutes
543
+ timer(0, 120_000).pipe(switchMap(() => this._getIndexerObservable(query, variables).pipe(map(postProcess ?? identity)))));
220
544
  }
221
545
  /**
222
546
  * @internal
223
547
  */
224
548
  _queryIPFS(hash) {
225
- return this._query([hash], () => this._getIPFSObservable(hash));
549
+ return this._query([hash], () => defer(async () => {
550
+ const url = getUrlFromHash(hash, this.#config.ipfsUrl);
551
+ if (!url) {
552
+ throw new Error(`Invalid IPFS hash: ${hash}`);
553
+ }
554
+ const res = await fetch(url);
555
+ if (!res.ok) {
556
+ throw new Error(`Error fetching IPFS hash ${hash}: ${res.statusText}`);
557
+ }
558
+ const data = (await res.json());
559
+ return data;
560
+ }));
226
561
  }
227
562
  #memoized = new Map();
228
563
  #memoizeWith(keys, callback) {
@@ -289,10 +624,9 @@ export class Centrifuge {
289
624
  * const chainId = 1
290
625
  *
291
626
  * // Wrap an observable that only emits one value and then completes
292
- * //
293
627
  * const query = this._query(['balance', address, tUSD, chainId], () => {
294
628
  * return defer(() => fetchBalance(address, tUSD, chainId))
295
- * }, { valueCacheTime: 60 })
629
+ * }, { valueCacheTime: 60_000 })
296
630
  *
297
631
  * // Logs the current balance and updated balances whenever a new
298
632
  * const obs1 = query.subscribe(balance => console.log(balance))
@@ -316,14 +650,17 @@ export class Centrifuge {
316
650
  * @internal
317
651
  */
318
652
  _query(keys, observableCallback, options) {
653
+ const cache = options?.cache !== false && this.#config.cache !== false;
654
+ const obsCacheTime = options?.observableCacheTime ?? this.#config.pollingInterval ?? 4000;
319
655
  function get() {
320
656
  const sharedSubject = new Subject();
321
657
  function createShared() {
322
658
  const $shared = observableCallback().pipe(keys
323
659
  ? shareReplayWithDelayedReset({
324
- bufferSize: (options?.cache ?? true) ? 1 : 0,
325
- resetDelay: (options?.cache === false ? 0 : (options?.observableCacheTime ?? 60)) * 1000,
326
- windowTime: (options?.valueCacheTime ?? Infinity) * 1000,
660
+ bufferSize: cache ? 1 : 0,
661
+ resetDelay: cache ? obsCacheTime : 0,
662
+ // TODO: Fix valueCacheTime to not cause an infinite loop when the value is expired.
663
+ // windowTime: options?.valueCacheTime ?? Infinity,
327
664
  })
328
665
  : map((val) => val));
329
666
  sharedSubject.next($shared);
@@ -343,50 +680,9 @@ export class Centrifuge {
343
680
  return keys ? this.#memoizeWith(keys, get) : get();
344
681
  }
345
682
  /**
346
- * Executes a transaction on a given chain.
347
- * When subscribed to, it emits status updates as it progresses.
348
- * When awaited, it returns the final confirmed if successful.
349
- * Will additionally prompt the user to switch chains if they're not on the correct chain.
350
- *
351
- * @example
352
- * ```ts
353
- * const tx = this._transact(
354
- * 'Transfer',
355
- * ({ walletClient }) =>
356
- * walletClient.writeContract({
357
- * address: '0xabc...123',
358
- * abi: ABI.Currency,
359
- * functionName: 'transfer',
360
- * args: ['0xdef...456', 1000000n],
361
- * }),
362
- * 1
363
- * )
364
- * tx.subscribe(status => console.log(status))
365
- *
366
- * // Results in something like the following values being emitted (assuming the user wasn't connected to mainnet):
367
- * // { type: 'SwitchingChain', chainId: 1 }
368
- * // { type: 'SigningTransaction', title: 'Transfer' }
369
- * // { type: 'TransactionPending', title: 'Transfer', hash: '0x123...abc' }
370
- * // { type: 'TransactionConfirmed', title: 'Transfer', hash: '0x123...abc', receipt: { ... } }
371
- * ```
372
- *
373
- * ```ts
374
- * const finalResult = await this._transact(...)
375
- * console.log(finalResult) // { type: 'TransactionConfirmed', title: 'Transfer', hash: '0x123...abc', receipt: { ... } }
376
- * ```
377
- *
378
- * @internal
379
- */
380
- _transact(title, transactionCallback, chainId) {
381
- return this._transactSequence(async function* (params) {
382
- const transaction = transactionCallback(params);
383
- yield* doTransaction(title, params.publicClient, () => transaction);
384
- }, chainId);
385
- }
386
- /**
387
- * Executes a sequence of transactions on a given chain.
683
+ * Executes one or more transactions on a given chain.
388
684
  * When subscribed to, it emits status updates as it progresses.
389
- * When awaited, it returns the final confirmed if successful.
685
+ * When awaited, it returns the final confirmed result if successful.
390
686
  * Will additionally prompt the user to switch chains if they're not on the correct chain.
391
687
  *
392
688
  * @example
@@ -413,41 +709,53 @@ export class Centrifuge {
413
709
  * // { type: 'SigningTransaction', title: 'Invest' }
414
710
  * // { type: 'TransactionPending', title: 'Invest', hash: '0x123...abc' }
415
711
  * // { type: 'TransactionConfirmed', title: 'Invest', hash: '0x123...abc', receipt: { ... } }
712
+ * ```
416
713
  *
417
714
  * @internal
418
715
  */
419
- _transactSequence(transactionCallback, chainId) {
420
- const targetChainId = chainId ?? this.config.defaultChain;
716
+ _transact(transactionCallback, chainId) {
421
717
  const self = this;
422
718
  async function* transact() {
719
+ let isBatching = false;
720
+ if (self.#isBatching.has($tx)) {
721
+ isBatching = true;
722
+ }
423
723
  const { signer } = self;
424
724
  if (!signer)
425
725
  throw new Error('Signer not set');
426
- const publicClient = self.getClient(targetChainId);
427
- const chain = self.getChainConfig(targetChainId);
428
- const bareWalletClient = isLocalAccount(signer)
429
- ? createWalletClient({ account: signer, chain, transport: http(self.#config.rpcUrls?.[chain.id]) })
726
+ const publicClient = self.getClient(chainId);
727
+ const chain = self.getChainConfig(chainId);
728
+ let walletClient = isLocalAccount(signer)
729
+ ? createWalletClient({
730
+ account: signer,
731
+ chain,
732
+ transport: http(),
733
+ })
430
734
  : createWalletClient({ transport: custom(signer) });
431
- const [address] = await bareWalletClient.getAddresses();
735
+ const [address] = await walletClient.getAddresses();
432
736
  if (!address)
433
737
  throw new Error('No account selected');
434
- const selectedChain = await bareWalletClient.getChainId();
435
- if (selectedChain !== targetChainId) {
436
- yield { type: 'SwitchingChain', chainId: targetChainId };
437
- await bareWalletClient.switchChain({ id: targetChainId });
738
+ if (!isBatching) {
739
+ const selectedChain = await walletClient.getChainId();
740
+ if (selectedChain !== chainId) {
741
+ yield { type: 'SwitchingChain', chainId };
742
+ await walletClient.switchChain({ id: chainId });
743
+ }
438
744
  }
439
745
  // Re-create the wallet client with the correct chain and account
440
746
  // Saves having to pass `account` and `chain` to every `writeContract` call
441
- const walletClient = isLocalAccount(signer)
442
- ? bareWalletClient
747
+ walletClient = isLocalAccount(signer)
748
+ ? walletClient
443
749
  : createWalletClient({ account: address, chain, transport: custom(signer) });
444
750
  const transaction = transactionCallback({
751
+ isBatching,
445
752
  signingAddress: address,
446
753
  chain,
447
- chainId: targetChainId,
754
+ chainId,
448
755
  publicClient,
449
756
  walletClient,
450
757
  signer,
758
+ root: self,
451
759
  });
452
760
  if (Symbol.asyncIterator in transaction) {
453
761
  yield* transaction;
@@ -460,7 +768,197 @@ export class Centrifuge {
460
768
  }
461
769
  }
462
770
  const $tx = defer(transact).pipe(mergeMap((d) => (isObservable(d) ? d : of(d))));
463
- return makeThenable($tx, true);
771
+ makeThenable($tx, true);
772
+ Object.assign($tx, {
773
+ chainId,
774
+ });
775
+ return $tx;
776
+ }
777
+ /**
778
+ * Batch multiple transactions together into a single transaction.
779
+ * It's not exposed, because it is somewhat limited and requires knowledge of internals.
780
+ * It only works when there's only a single transaction being done in the method.
781
+ * It only works for methods that wrap the transaction in `wrapTransaction`.
782
+ * It only works when the transactions are executed on the same contract on the same chain,
783
+ * and that contract supports multicall
784
+ * @internal
785
+ */
786
+ _experimental_batch(title, transactions) {
787
+ const chainIds = [...new Set(transactions.map((tx) => tx.chainId))];
788
+ if (chainIds.length !== 1) {
789
+ throw new Error(`Cannot batch transactions on different chains: ${chainIds.join(', ')}`);
790
+ }
791
+ for (const tx of transactions) {
792
+ this.#isBatching.add(tx);
793
+ }
794
+ return this._transact((ctx) => combineLatest(transactions.map((tx) => tx.pipe(first()))).pipe(switchMap(async function* (batches_) {
795
+ const batches = batches_;
796
+ if (!batches.every((b) => b.data && b.contract)) {
797
+ throw new Error('Not all transactions can be batched');
798
+ }
799
+ const value = batches.reduce((acc, b) => acc + (b.value ?? 0n), 0n);
800
+ const data = batches.map((b) => b.data).flat();
801
+ const messages = batches.reduce((acc, b) => {
802
+ if (b.messages) {
803
+ Object.entries(b.messages).forEach(([cid, types]) => {
804
+ const chainId = Number(cid);
805
+ if (!acc[chainId])
806
+ acc[chainId] = [];
807
+ acc[chainId].push(...types);
808
+ });
809
+ }
810
+ return acc;
811
+ }, {});
812
+ const contracts = [...new Set(batches.map((b) => b.contract))];
813
+ if (contracts.length !== 1) {
814
+ throw new Error(`Cannot batch transactions to different contracts: ${contracts.join(', ')}`);
815
+ }
816
+ yield* wrapTransaction(title, ctx, { data, value, contract: contracts[0], messages });
817
+ })), chainIds[0]);
818
+ }
819
+ /** @internal */
820
+ _protocolAddresses(chainId) {
821
+ return this._query(null, () => this._deployments().pipe(map((data) => {
822
+ if (!this.chains.includes(chainId)) {
823
+ throw new Error(`Chain ID "${chainId}" not supported`);
824
+ }
825
+ const deployment = data.deployments.items.find((d) => Number(d.chainId) === chainId);
826
+ if (!deployment) {
827
+ throw new Error(`No protocol contracts found for chain ID "${chainId}"`);
828
+ }
829
+ return deployment;
830
+ })));
831
+ }
832
+ /** @internal */
833
+ _getQuote(valuationAddress, baseAmount, baseAssetId, quoteAssetId, chainId) {
834
+ return this._query(['getQuote', baseAmount, baseAssetId.toString(), quoteAssetId.toString()], () => timer(0, 60_000).pipe(switchMap(() => this._protocolAddresses(chainId)), switchMap(({ hubRegistry }) => defer(async () => {
835
+ const [quote, quoteDecimals] = await Promise.all([
836
+ this.getClient(chainId).readContract({
837
+ address: valuationAddress,
838
+ abi: ABI.Valuation,
839
+ functionName: 'getQuote',
840
+ args: [baseAmount.toBigInt(), baseAssetId.raw, quoteAssetId.raw],
841
+ }),
842
+ this.getClient(chainId).readContract({
843
+ address: hubRegistry,
844
+ // Use inline ABI because of function overload
845
+ abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
846
+ functionName: 'decimals',
847
+ args: [quoteAssetId.raw],
848
+ }),
849
+ ]);
850
+ return new Balance(quote, quoteDecimals);
851
+ }))));
852
+ }
853
+ /**
854
+ * Estimates the gas cost needed to bridge the message from one chain to another,
855
+ * that results from a transaction
856
+ * @internal
857
+ */
858
+ _estimate(fromChain, to, messageType) {
859
+ return this._query(['estimate', fromChain, to, messageType], () => this._protocolAddresses(fromChain).pipe(switchMap(({ multiAdapter, gasService }) => {
860
+ const types = Array.isArray(messageType) ? messageType : [messageType];
861
+ return combineLatest([
862
+ 'chainId' in to ? this.id(to.chainId) : of(to.centId),
863
+ ...types.map((typeAndMaybeSubtype) => {
864
+ const type = typeof typeAndMaybeSubtype === 'number' ? typeAndMaybeSubtype : typeAndMaybeSubtype.type;
865
+ const subtype = typeof typeAndMaybeSubtype === 'number' ? undefined : typeAndMaybeSubtype.subtype;
866
+ const data = emptyMessage(type, subtype);
867
+ return this.getClient(fromChain).readContract({
868
+ address: gasService,
869
+ abi: ABI.GasService,
870
+ functionName: 'messageGasLimit',
871
+ args: [0, data],
872
+ });
873
+ }),
874
+ ]).pipe(switchMap(async ([toCentId, ...gasLimits]) => {
875
+ const estimate = await this.getClient(fromChain).readContract({
876
+ address: multiAdapter,
877
+ abi: ABI.MultiAdapter,
878
+ functionName: 'estimate',
879
+ args: [toCentId, '0x0', gasLimits.reduce((acc, val) => acc + val, 0n)],
880
+ });
881
+ return (estimate * 3n) / 2n; // Add 50% buffer to the estimate
882
+ }));
883
+ })));
884
+ }
885
+ /** @internal */
886
+ _maxBatchGasLimit(chainId) {
887
+ return this._query(['maxBatchGasLimit', chainId], () => this._protocolAddresses(chainId).pipe(switchMap(async ({ gasService }) => {
888
+ try {
889
+ // `batchGasLimit` was renamed to `maxBatchGasLimit`, support both for backwards compatibility,
890
+ // until all chains are updated
891
+ return await this.getClient(chainId).readContract({
892
+ address: gasService,
893
+ abi: ABI.GasService,
894
+ functionName: 'maxBatchGasLimit',
895
+ args: [0],
896
+ });
897
+ }
898
+ catch {
899
+ return await this.getClient(chainId).readContract({
900
+ address: gasService,
901
+ abi: ABI.GasService,
902
+ functionName: 'batchGasLimit',
903
+ args: [0],
904
+ });
905
+ }
906
+ })));
907
+ }
908
+ /** @internal */
909
+ _idToChain(centrifugeId) {
910
+ return this._query(null, () => this._deployments().pipe(map((data) => {
911
+ const item = data.blockchains.items.find((b) => Number(b.centrifugeId) === centrifugeId);
912
+ if (!item)
913
+ throw new Error(`Chain with Centrifuge ID "${centrifugeId}" not found`);
914
+ return Number(item.id);
915
+ })));
916
+ }
917
+ /** @internal */
918
+ _deployments() {
919
+ return this._query(['deployments'], () => this._getIndexerObservable(`{
920
+ blockchains {
921
+ items {
922
+ centrifugeId
923
+ id
924
+ }
925
+ }
926
+ deployments {
927
+ items {
928
+ accounting
929
+ asyncRequestManager
930
+ asyncVaultFactory
931
+ axelarAdapter
932
+ balanceSheet
933
+ centrifugeId
934
+ chainId
935
+ freezeOnlyHook
936
+ fullRestrictionsHook
937
+ gasService
938
+ gateway
939
+ globalEscrow
940
+ guardian
941
+ holdings
942
+ hub
943
+ hubRegistry
944
+ identityValuation
945
+ messageDispatcher
946
+ messageProcessor
947
+ multiAdapter
948
+ poolEscrowFactory
949
+ redemptionRestrictionsHook
950
+ root
951
+ routerEscrow
952
+ shareClassManager
953
+ spoke
954
+ syncDepositVaultFactory
955
+ syncManager
956
+ wormholeAdapter
957
+ vaultRouter
958
+ tokenFactory
959
+ }
960
+ }
961
+ }`));
464
962
  }
465
963
  }
466
964
  //# sourceMappingURL=Centrifuge.js.map