@centrifuge/sdk 0.0.0-alpha.3 → 0.0.0-alpha.30
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.
- package/README.md +19 -8
- package/dist/Centrifuge.d.ts +275 -423
- package/dist/Centrifuge.d.ts.map +1 -1
- package/dist/Centrifuge.js +561 -132
- package/dist/Centrifuge.js.map +1 -1
- package/dist/Centrifuge.test.d.ts +2 -0
- package/dist/Centrifuge.test.d.ts.map +1 -0
- package/dist/Centrifuge.test.js +514 -0
- package/dist/Centrifuge.test.js.map +1 -0
- package/dist/abi/Accounting.abi.d.ts +3 -0
- package/dist/abi/Accounting.abi.d.ts.map +1 -0
- package/dist/abi/Accounting.abi.js +33 -0
- package/dist/abi/Accounting.abi.js.map +1 -0
- package/dist/abi/AsyncRequestManager.abi.d.ts +3 -0
- package/dist/abi/AsyncRequestManager.abi.d.ts.map +1 -0
- package/dist/abi/AsyncRequestManager.abi.js +78 -0
- package/dist/abi/AsyncRequestManager.abi.js.map +1 -0
- package/dist/abi/AsyncVault.abi.d.ts +3 -0
- package/dist/abi/AsyncVault.abi.d.ts.map +1 -0
- package/dist/abi/AsyncVault.abi.js +101 -0
- package/dist/abi/AsyncVault.abi.js.map +1 -0
- package/dist/abi/BalanceSheet.abi.d.ts +3 -0
- package/dist/abi/BalanceSheet.abi.d.ts.map +1 -0
- package/dist/abi/BalanceSheet.abi.js +55 -0
- package/dist/abi/BalanceSheet.abi.js.map +1 -0
- package/dist/abi/Currency.abi.d.ts +3 -0
- package/dist/abi/Currency.abi.d.ts.map +1 -0
- package/dist/abi/Currency.abi.js +15 -0
- package/dist/abi/Currency.abi.js.map +1 -0
- package/dist/abi/ERC6909.abi.d.ts +3 -0
- package/dist/abi/ERC6909.abi.d.ts.map +1 -0
- package/dist/abi/ERC6909.abi.js +19 -0
- package/dist/abi/ERC6909.abi.js.map +1 -0
- package/dist/abi/GasService.abi.d.ts +3 -0
- package/dist/abi/GasService.abi.d.ts.map +1 -0
- package/dist/abi/GasService.abi.js +31 -0
- package/dist/abi/GasService.abi.js.map +1 -0
- package/dist/abi/Holdings.abi.d.ts +3 -0
- package/dist/abi/Holdings.abi.d.ts.map +1 -0
- package/dist/abi/Holdings.abi.js +43 -0
- package/dist/abi/Holdings.abi.js.map +1 -0
- package/dist/abi/Hub.abi.d.ts +3 -0
- package/dist/abi/Hub.abi.d.ts.map +1 -0
- package/dist/abi/Hub.abi.js +88 -0
- package/dist/abi/Hub.abi.js.map +1 -0
- package/dist/abi/HubRegistry.abi.d.ts +3 -0
- package/dist/abi/HubRegistry.abi.d.ts.map +1 -0
- package/dist/abi/HubRegistry.abi.js +39 -0
- package/dist/abi/HubRegistry.abi.js.map +1 -0
- package/dist/abi/MessageDispatcher.abi.d.ts +3 -0
- package/dist/abi/MessageDispatcher.abi.d.ts.map +1 -0
- package/dist/abi/MessageDispatcher.abi.js +49 -0
- package/dist/abi/MessageDispatcher.abi.js.map +1 -0
- package/dist/abi/MultiAdapter.abi.d.ts +3 -0
- package/dist/abi/MultiAdapter.abi.d.ts.map +1 -0
- package/dist/abi/MultiAdapter.abi.js +53 -0
- package/dist/abi/MultiAdapter.abi.js.map +1 -0
- package/dist/abi/RestrictionManager.abi.d.ts +3 -0
- package/dist/abi/RestrictionManager.abi.d.ts.map +1 -0
- package/dist/abi/RestrictionManager.abi.js +23 -0
- package/dist/abi/RestrictionManager.abi.js.map +1 -0
- package/dist/abi/ShareClassManager.abi.d.ts +3 -0
- package/dist/abi/ShareClassManager.abi.d.ts.map +1 -0
- package/dist/abi/ShareClassManager.abi.js +89 -0
- package/dist/abi/ShareClassManager.abi.js.map +1 -0
- package/dist/abi/Spoke.abi.d.ts +3 -0
- package/dist/abi/Spoke.abi.d.ts.map +1 -0
- package/dist/abi/Spoke.abi.js +90 -0
- package/dist/abi/Spoke.abi.js.map +1 -0
- package/dist/abi/SyncRequestManager.abi.d.ts +3 -0
- package/dist/abi/SyncRequestManager.abi.d.ts.map +1 -0
- package/dist/abi/SyncRequestManager.abi.js +61 -0
- package/dist/abi/SyncRequestManager.abi.js.map +1 -0
- package/dist/abi/Valuation.abi.d.ts +3 -0
- package/dist/abi/Valuation.abi.d.ts.map +1 -0
- package/dist/abi/Valuation.abi.js +2 -0
- package/dist/abi/Valuation.abi.js.map +1 -0
- package/dist/abi/VaultRouter.abi.d.ts +3 -0
- package/dist/abi/VaultRouter.abi.d.ts.map +1 -0
- package/dist/abi/VaultRouter.abi.js +51 -0
- package/dist/abi/VaultRouter.abi.js.map +1 -0
- package/dist/abi/index.d.ts +8483 -8
- package/dist/abi/index.d.ts.map +1 -1
- package/dist/abi/index.js +36 -16
- package/dist/abi/index.js.map +1 -1
- package/dist/config/chains.d.ts +184 -925
- package/dist/config/chains.d.ts.map +1 -1
- package/dist/config/chains.js +2 -2
- package/dist/config/chains.js.map +1 -1
- package/dist/config/protocol.d.ts +3 -0
- package/dist/config/protocol.d.ts.map +1 -0
- package/dist/config/protocol.js +7 -0
- package/dist/config/protocol.js.map +1 -0
- package/dist/entities/BalanceSheet.d.ts +47 -0
- package/dist/entities/BalanceSheet.d.ts.map +1 -0
- package/dist/entities/BalanceSheet.js +94 -0
- package/dist/entities/BalanceSheet.js.map +1 -0
- package/dist/entities/BalanceSheet.test.d.ts +2 -0
- package/dist/entities/BalanceSheet.test.d.ts.map +1 -0
- package/dist/entities/BalanceSheet.test.js +44 -0
- package/dist/entities/BalanceSheet.test.js.map +1 -0
- package/dist/entities/Entity.d.ts +8 -0
- package/dist/entities/Entity.d.ts.map +1 -0
- package/dist/{Entity.js → entities/Entity.js} +5 -3
- package/dist/entities/Entity.js.map +1 -0
- package/dist/entities/IndexerQueries/assetSnapshots.d.ts +69 -0
- package/dist/entities/IndexerQueries/assetSnapshots.d.ts.map +1 -0
- package/dist/entities/IndexerQueries/assetSnapshots.js +91 -0
- package/dist/entities/IndexerQueries/assetSnapshots.js.map +1 -0
- package/dist/entities/IndexerQueries/assetTransactions.d.ts +93 -0
- package/dist/entities/IndexerQueries/assetTransactions.d.ts.map +1 -0
- package/dist/entities/IndexerQueries/assetTransactions.js +75 -0
- package/dist/entities/IndexerQueries/assetTransactions.js.map +1 -0
- package/dist/entities/IndexerQueries/epochs.d.ts +45 -0
- package/dist/entities/IndexerQueries/epochs.d.ts.map +1 -0
- package/dist/entities/IndexerQueries/epochs.js +51 -0
- package/dist/entities/IndexerQueries/epochs.js.map +1 -0
- package/dist/entities/IndexerQueries/index.d.ts +40 -0
- package/dist/entities/IndexerQueries/index.d.ts.map +1 -0
- package/dist/entities/IndexerQueries/index.js +45 -0
- package/dist/entities/IndexerQueries/index.js.map +1 -0
- package/dist/entities/IndexerQueries/investorTransactions.d.ts +50 -0
- package/dist/entities/IndexerQueries/investorTransactions.d.ts.map +1 -0
- package/dist/entities/IndexerQueries/investorTransactions.js +55 -0
- package/dist/entities/IndexerQueries/investorTransactions.js.map +1 -0
- package/dist/{queries → entities/IndexerQueries}/poolFeeSnapshots.d.ts +8 -8
- package/dist/entities/IndexerQueries/poolFeeSnapshots.d.ts.map +1 -0
- package/dist/{queries → entities/IndexerQueries}/poolFeeSnapshots.js +8 -8
- package/dist/entities/IndexerQueries/poolFeeSnapshots.js.map +1 -0
- package/dist/entities/IndexerQueries/poolFeeTransactions.d.ts +34 -0
- package/dist/entities/IndexerQueries/poolFeeTransactions.d.ts.map +1 -0
- package/dist/entities/IndexerQueries/poolFeeTransactions.js +37 -0
- package/dist/entities/IndexerQueries/poolFeeTransactions.js.map +1 -0
- package/dist/{queries → entities/IndexerQueries}/poolSnapshots.d.ts +30 -24
- package/dist/entities/IndexerQueries/poolSnapshots.d.ts.map +1 -0
- package/dist/{queries → entities/IndexerQueries}/poolSnapshots.js +29 -23
- package/dist/entities/IndexerQueries/poolSnapshots.js.map +1 -0
- package/dist/entities/IndexerQueries/trancheCurrencyBalance.d.ts +76 -0
- package/dist/entities/IndexerQueries/trancheCurrencyBalance.d.ts.map +1 -0
- package/dist/entities/IndexerQueries/trancheCurrencyBalance.js +63 -0
- package/dist/entities/IndexerQueries/trancheCurrencyBalance.js.map +1 -0
- package/dist/{queries → entities/IndexerQueries}/trancheSnapshots.d.ts +7 -7
- package/dist/entities/IndexerQueries/trancheSnapshots.d.ts.map +1 -0
- package/dist/{queries → entities/IndexerQueries}/trancheSnapshots.js +7 -7
- package/dist/entities/IndexerQueries/trancheSnapshots.js.map +1 -0
- package/dist/entities/Investor.d.ts +33 -0
- package/dist/entities/Investor.d.ts.map +1 -0
- package/dist/entities/Investor.js +59 -0
- package/dist/entities/Investor.js.map +1 -0
- package/dist/entities/Investor.test.d.ts +2 -0
- package/dist/entities/Investor.test.d.ts.map +1 -0
- package/dist/entities/Investor.test.js +16 -0
- package/dist/entities/Investor.test.js.map +1 -0
- package/dist/entities/Pool.d.ts +114 -0
- package/dist/entities/Pool.d.ts.map +1 -0
- package/dist/entities/Pool.js +297 -0
- package/dist/entities/Pool.js.map +1 -0
- package/dist/entities/Pool.test.d.ts +2 -0
- package/dist/entities/Pool.test.d.ts.map +1 -0
- package/dist/entities/Pool.test.js +91 -0
- package/dist/entities/Pool.test.js.map +1 -0
- package/dist/entities/PoolNetwork.d.ts +64 -0
- package/dist/entities/PoolNetwork.d.ts.map +1 -0
- package/dist/entities/PoolNetwork.js +248 -0
- package/dist/entities/PoolNetwork.js.map +1 -0
- package/dist/entities/PoolNetwork.test.d.ts +2 -0
- package/dist/entities/PoolNetwork.test.d.ts.map +1 -0
- package/dist/entities/PoolNetwork.test.js +64 -0
- package/dist/entities/PoolNetwork.test.js.map +1 -0
- package/dist/entities/Reports/Processor.d.ts +46 -0
- package/dist/entities/Reports/Processor.d.ts.map +1 -0
- package/dist/entities/Reports/Processor.js +471 -0
- package/dist/entities/Reports/Processor.js.map +1 -0
- package/dist/entities/Reports/Processor.test.d.ts +2 -0
- package/dist/entities/Reports/Processor.test.d.ts.map +1 -0
- package/dist/entities/Reports/Processor.test.js +767 -0
- package/dist/entities/Reports/Processor.test.js.map +1 -0
- package/dist/entities/Reports/Reports.test.d.ts +2 -0
- package/dist/entities/Reports/Reports.test.d.ts.map +1 -0
- package/dist/entities/Reports/Reports.test.js +559 -0
- package/dist/entities/Reports/Reports.test.js.map +1 -0
- package/dist/entities/Reports/index.d.ts +21 -0
- package/dist/entities/Reports/index.d.ts.map +1 -0
- package/dist/entities/Reports/index.js +144 -0
- package/dist/entities/Reports/index.js.map +1 -0
- package/dist/entities/ShareClass.d.ts +162 -0
- package/dist/entities/ShareClass.d.ts.map +1 -0
- package/dist/entities/ShareClass.js +939 -0
- package/dist/entities/ShareClass.js.map +1 -0
- package/dist/entities/ShareClass.test.d.ts +2 -0
- package/dist/entities/ShareClass.test.d.ts.map +1 -0
- package/dist/entities/ShareClass.test.js +108 -0
- package/dist/entities/ShareClass.test.js.map +1 -0
- package/dist/entities/Vault.d.ts +85 -0
- package/dist/entities/Vault.d.ts.map +1 -0
- package/dist/entities/Vault.js +385 -0
- package/dist/entities/Vault.js.map +1 -0
- package/dist/entities/Vault.test.d.ts +2 -0
- package/dist/entities/Vault.test.d.ts.map +1 -0
- package/dist/entities/Vault.test.js +271 -0
- package/dist/entities/Vault.test.js.map +1 -0
- package/dist/index.d.ts +16 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/tests/mocks/mockAssetSnapshots.d.ts +3 -0
- package/dist/tests/mocks/mockAssetSnapshots.d.ts.map +1 -0
- package/dist/tests/mocks/mockAssetSnapshots.js +56 -0
- package/dist/tests/mocks/mockAssetSnapshots.js.map +1 -0
- package/dist/tests/mocks/mockAssetTransactions.d.ts +3 -0
- package/dist/tests/mocks/mockAssetTransactions.d.ts.map +1 -0
- package/dist/tests/mocks/mockAssetTransactions.js +86 -0
- package/dist/tests/mocks/mockAssetTransactions.js.map +1 -0
- package/dist/tests/mocks/mockEpochs.d.ts +3 -0
- package/dist/tests/mocks/mockEpochs.d.ts.map +1 -0
- package/dist/tests/mocks/mockEpochs.js +26 -0
- package/dist/tests/mocks/mockEpochs.js.map +1 -0
- package/dist/tests/mocks/mockInvestorCurrencyBalance.d.ts +3 -0
- package/dist/tests/mocks/mockInvestorCurrencyBalance.d.ts.map +1 -0
- package/dist/tests/mocks/mockInvestorCurrencyBalance.js +29 -0
- package/dist/tests/mocks/mockInvestorCurrencyBalance.js.map +1 -0
- package/dist/tests/mocks/mockInvestorTransactions.d.ts +3 -0
- package/dist/tests/mocks/mockInvestorTransactions.d.ts.map +1 -0
- package/dist/tests/mocks/mockInvestorTransactions.js +35 -0
- package/dist/tests/mocks/mockInvestorTransactions.js.map +1 -0
- package/dist/tests/mocks/mockPoolFeeSnapshot.d.ts +1 -1
- package/dist/tests/mocks/mockPoolFeeSnapshot.d.ts.map +1 -1
- package/dist/tests/mocks/mockPoolFeeSnapshot.js +29 -29
- package/dist/tests/mocks/mockPoolFeeSnapshot.js.map +1 -1
- package/dist/tests/mocks/mockPoolFeeTransactions.d.ts +11 -0
- package/dist/tests/mocks/mockPoolFeeTransactions.d.ts.map +1 -0
- package/dist/tests/mocks/mockPoolFeeTransactions.js +20 -0
- package/dist/tests/mocks/mockPoolFeeTransactions.js.map +1 -0
- package/dist/tests/mocks/mockPoolMetadata.d.ts.map +1 -1
- package/dist/tests/mocks/mockPoolMetadata.js +5 -15
- package/dist/tests/mocks/mockPoolMetadata.js.map +1 -1
- package/dist/tests/mocks/mockPoolSnapshots.d.ts +1 -1
- package/dist/tests/mocks/mockPoolSnapshots.d.ts.map +1 -1
- package/dist/tests/mocks/mockPoolSnapshots.js +47 -45
- package/dist/tests/mocks/mockPoolSnapshots.js.map +1 -1
- package/dist/tests/mocks/mockTrancheSnapshots.d.ts +1 -1
- package/dist/tests/mocks/mockTrancheSnapshots.d.ts.map +1 -1
- package/dist/tests/mocks/mockTrancheSnapshots.js +21 -21
- package/dist/tests/mocks/mockTrancheSnapshots.js.map +1 -1
- package/dist/tests/setup.d.ts.map +1 -1
- package/dist/tests/setup.js +3 -2
- package/dist/tests/setup.js.map +1 -1
- package/dist/tests/tenderly.js +1 -1
- package/dist/tests/tenderly.js.map +1 -1
- package/dist/tests/utils.d.ts +3 -0
- package/dist/tests/utils.d.ts.map +1 -0
- package/dist/tests/utils.js +4 -0
- package/dist/tests/utils.js.map +1 -0
- package/dist/types/holdings.d.ts +9 -0
- package/dist/types/holdings.d.ts.map +1 -0
- package/dist/types/holdings.js +10 -0
- package/dist/types/holdings.js.map +1 -0
- package/dist/types/index.d.ts +63 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/poolInput.d.ts +71 -0
- package/dist/types/poolInput.d.ts.map +1 -0
- package/dist/types/poolInput.js +2 -0
- package/dist/types/poolInput.js.map +1 -0
- package/dist/types/poolMetadata.d.ts +13 -12
- package/dist/types/poolMetadata.d.ts.map +1 -1
- package/dist/types/reports.d.ts +336 -0
- package/dist/types/reports.d.ts.map +1 -0
- package/dist/types/reports.js +2 -0
- package/dist/types/reports.js.map +1 -0
- package/dist/types/transaction.d.ts +49 -2
- package/dist/types/transaction.d.ts.map +1 -1
- package/dist/types/transaction.js +40 -1
- package/dist/types/transaction.js.map +1 -1
- package/dist/utils/BigInt.d.ts +15 -34
- package/dist/utils/BigInt.d.ts.map +1 -1
- package/dist/utils/BigInt.js +16 -23
- package/dist/utils/BigInt.js.map +1 -1
- package/dist/utils/BigInt.test.d.ts +2 -0
- package/dist/utils/BigInt.test.d.ts.map +1 -0
- package/dist/utils/BigInt.test.js +298 -0
- package/dist/utils/BigInt.test.js.map +1 -0
- package/dist/utils/currencies.d.ts +5 -0
- package/dist/utils/currencies.d.ts.map +1 -0
- package/dist/utils/currencies.js +7 -0
- package/dist/utils/currencies.js.map +1 -0
- package/dist/utils/date.d.ts.map +1 -1
- package/dist/utils/date.js +5 -4
- package/dist/utils/date.js.map +1 -1
- package/dist/utils/decimal.d.ts +2 -2
- package/dist/utils/decimal.d.ts.map +1 -1
- package/dist/utils/decimal.js.map +1 -1
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +24 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/ipfs.d.ts +7 -0
- package/dist/utils/ipfs.d.ts.map +1 -0
- package/dist/utils/ipfs.js +64 -0
- package/dist/utils/ipfs.js.map +1 -0
- package/dist/utils/ipfs.test.d.ts +2 -0
- package/dist/utils/ipfs.test.d.ts.map +1 -0
- package/dist/utils/ipfs.test.js +54 -0
- package/dist/utils/ipfs.test.js.map +1 -0
- package/dist/utils/rx.d.ts +1 -1
- package/dist/utils/rx.d.ts.map +1 -1
- package/dist/utils/rx.js +4 -0
- package/dist/utils/rx.js.map +1 -1
- package/dist/utils/transaction.d.ts +14 -2
- package/dist/utils/transaction.d.ts.map +1 -1
- package/dist/utils/transaction.js +57 -5
- package/dist/utils/transaction.js.map +1 -1
- package/dist/utils/types.d.ts +39 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +89 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/types.test.d.ts +2 -0
- package/dist/utils/types.test.d.ts.map +1 -0
- package/dist/utils/types.test.js +89 -0
- package/dist/utils/types.test.js.map +1 -0
- package/package.json +13 -8
- package/dist/Account.d.ts +0 -11
- package/dist/Account.d.ts.map +0 -1
- package/dist/Account.js +0 -46
- package/dist/Account.js.map +0 -1
- package/dist/Entity.d.ts +0 -12
- package/dist/Entity.d.ts.map +0 -1
- package/dist/Entity.js.map +0 -1
- package/dist/Pool.d.ts +0 -27
- package/dist/Pool.d.ts.map +0 -1
- package/dist/Pool.js +0 -76
- package/dist/Pool.js.map +0 -1
- package/dist/PoolNetwork.d.ts +0 -82
- package/dist/PoolNetwork.d.ts.map +0 -1
- package/dist/PoolNetwork.js +0 -236
- package/dist/PoolNetwork.js.map +0 -1
- package/dist/Reports/Processor.d.ts +0 -38
- package/dist/Reports/Processor.d.ts.map +0 -1
- package/dist/Reports/Processor.js +0 -167
- package/dist/Reports/Processor.js.map +0 -1
- package/dist/Reports/index.d.ts +0 -24
- package/dist/Reports/index.d.ts.map +0 -1
- package/dist/Reports/index.js +0 -68
- package/dist/Reports/index.js.map +0 -1
- package/dist/Reports/types.d.ts +0 -102
- package/dist/Reports/types.d.ts.map +0 -1
- package/dist/Reports/types.js +0 -2
- package/dist/Reports/types.js.map +0 -1
- package/dist/Vault.d.ts +0 -96
- package/dist/Vault.d.ts.map +0 -1
- package/dist/Vault.js +0 -330
- package/dist/Vault.js.map +0 -1
- package/dist/abi/CentrifugeRouter.abi.json +0 -43
- package/dist/abi/Currency.abi.json +0 -14
- package/dist/abi/Gateway.abi.json +0 -1
- package/dist/abi/InvestmentManager.abi.json +0 -4
- package/dist/abi/LiquidityPool.abi.json +0 -79
- package/dist/abi/PoolManager.abi.json +0 -55
- package/dist/abi/RestrictionManager.abi.json +0 -22
- package/dist/abi/Router.abi.json +0 -1
- package/dist/config/lp.d.ts +0 -17
- package/dist/config/lp.d.ts.map +0 -1
- package/dist/config/lp.js +0 -35
- package/dist/config/lp.js.map +0 -1
- package/dist/queries/poolFeeSnapshots.d.ts.map +0 -1
- package/dist/queries/poolFeeSnapshots.js.map +0 -1
- package/dist/queries/poolSnapshots.d.ts.map +0 -1
- package/dist/queries/poolSnapshots.js.map +0 -1
- package/dist/queries/trancheSnapshots.d.ts.map +0 -1
- package/dist/queries/trancheSnapshots.js.map +0 -1
- package/dist/utils/pinToApi.d.ts +0 -2
- package/dist/utils/pinToApi.d.ts.map +0 -1
- package/dist/utils/pinToApi.js +0 -10
- package/dist/utils/pinToApi.js.map +0 -1
package/dist/Centrifuge.js
CHANGED
|
@@ -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
|
-
import { PERMIT_TYPEHASH } from './constants.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { NULL_ADDRESS, PERMIT_TYPEHASH } from './constants.js';
|
|
7
|
+
import { Investor } from './entities/Investor.js';
|
|
8
|
+
import { Pool } from './entities/Pool.js';
|
|
9
|
+
import { 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://
|
|
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
|
-
|
|
22
|
-
indexerUrl: 'https://api.
|
|
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,13 @@ export class Centrifuge {
|
|
|
43
38
|
}
|
|
44
39
|
#clients = new Map();
|
|
45
40
|
getClient(chainId) {
|
|
46
|
-
return this.#clients.get(chainId
|
|
41
|
+
return this.#clients.get(chainId);
|
|
47
42
|
}
|
|
48
43
|
get chains() {
|
|
49
44
|
return [...this.#clients.keys()];
|
|
50
45
|
}
|
|
51
46
|
getChainConfig(chainId) {
|
|
52
|
-
return this.getClient(chainId
|
|
47
|
+
return this.getClient(chainId).chain;
|
|
53
48
|
}
|
|
54
49
|
#signer = null;
|
|
55
50
|
setSigner(signer) {
|
|
@@ -58,8 +53,9 @@ export class Centrifuge {
|
|
|
58
53
|
get signer() {
|
|
59
54
|
return this.#signer;
|
|
60
55
|
}
|
|
56
|
+
#isBatching = new WeakSet();
|
|
61
57
|
constructor(config = {}) {
|
|
62
|
-
const defaultConfigForEnv = envConfig[config?.environment
|
|
58
|
+
const defaultConfigForEnv = envConfig[config?.environment || 'mainnet'];
|
|
63
59
|
this.#config = {
|
|
64
60
|
...defaultConfig,
|
|
65
61
|
...defaultConfigForEnv,
|
|
@@ -73,14 +69,178 @@ export class Centrifuge {
|
|
|
73
69
|
if (!rpcUrl) {
|
|
74
70
|
console.warn(`No rpcUrl defined for chain ${chain.id}. Using public RPC endpoint.`);
|
|
75
71
|
}
|
|
76
|
-
this.#clients.set(chain.id, createPublicClient({
|
|
72
|
+
this.#clients.set(chain.id, createPublicClient({
|
|
73
|
+
chain,
|
|
74
|
+
transport: Array.isArray(rpcUrl) ? fallback(rpcUrl.map((url) => http(url))) : http(rpcUrl),
|
|
75
|
+
batch: { multicall: true },
|
|
76
|
+
pollingInterval: this.#config.pollingInterval,
|
|
77
|
+
cacheTime: 100,
|
|
78
|
+
}));
|
|
77
79
|
});
|
|
78
80
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Create a new pool on the given chain.
|
|
83
|
+
* @param metadataInput - The metadata for the pool
|
|
84
|
+
* @param currencyCode - The currency code for the pool
|
|
85
|
+
* @param chainId - The chain ID to create the pool on
|
|
86
|
+
* @param counter - The pool counter, used to create a unique pool ID (uint48)
|
|
87
|
+
*/
|
|
88
|
+
createPool(metadataInput, currencyCode = 840, chainId, counter) {
|
|
89
|
+
const self = this;
|
|
90
|
+
return this._transact(async function* ({ walletClient, signingAddress, publicClient }) {
|
|
91
|
+
const [addresses, id] = await Promise.all([self._protocolAddresses(chainId), self.id(chainId)]);
|
|
92
|
+
const poolId = PoolId.from(id, counter ?? randomUint(48));
|
|
93
|
+
const createPoolData = encodeFunctionData({
|
|
94
|
+
abi: ABI.Hub,
|
|
95
|
+
functionName: 'createPool',
|
|
96
|
+
args: [poolId.raw, signingAddress, BigInt(currencyCode)],
|
|
97
|
+
});
|
|
98
|
+
const scIds = Array.from({ length: metadataInput.shareClasses.length }, (_, i) => ShareClassId.from(poolId, i + 1));
|
|
99
|
+
const shareClassesById = {};
|
|
100
|
+
metadataInput.shareClasses.forEach((sc, index) => {
|
|
101
|
+
shareClassesById[scIds[index].raw] = {
|
|
102
|
+
minInitialInvestment: Balance.fromFloat(sc.minInvestment, 18).toString(),
|
|
103
|
+
apyPercentage: sc.apyPercentage,
|
|
104
|
+
apy: sc.apy,
|
|
105
|
+
defaultAccounts: sc.defaultAccounts,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
const formattedMetadata = {
|
|
109
|
+
version: 1,
|
|
110
|
+
pool: {
|
|
111
|
+
name: metadataInput.poolName,
|
|
112
|
+
icon: metadataInput.poolIcon,
|
|
113
|
+
asset: {
|
|
114
|
+
class: metadataInput.assetClass,
|
|
115
|
+
subClass: metadataInput.subAssetClass,
|
|
116
|
+
},
|
|
117
|
+
issuer: {
|
|
118
|
+
name: metadataInput.issuerName,
|
|
119
|
+
repName: metadataInput.issuerRepName,
|
|
120
|
+
description: metadataInput.issuerDescription,
|
|
121
|
+
email: metadataInput.email,
|
|
122
|
+
logo: metadataInput.issuerLogo,
|
|
123
|
+
shortDescription: metadataInput.issuerShortDescription,
|
|
124
|
+
categories: metadataInput.issuerCategories,
|
|
125
|
+
},
|
|
126
|
+
poolStructure: metadataInput.poolStructure,
|
|
127
|
+
investorType: metadataInput.investorType,
|
|
128
|
+
links: {
|
|
129
|
+
executiveSummary: metadataInput.executiveSummary,
|
|
130
|
+
forum: metadataInput.forum,
|
|
131
|
+
website: metadataInput.website,
|
|
132
|
+
},
|
|
133
|
+
details: metadataInput.details,
|
|
134
|
+
status: 'open',
|
|
135
|
+
listed: metadataInput.listed ?? true,
|
|
136
|
+
poolRatings: metadataInput.poolRatings.length > 0 ? metadataInput.poolRatings : [],
|
|
137
|
+
reports: metadataInput.report
|
|
138
|
+
? [
|
|
139
|
+
{
|
|
140
|
+
author: {
|
|
141
|
+
name: metadataInput.report.author.name,
|
|
142
|
+
title: metadataInput.report.author.title,
|
|
143
|
+
avatar: metadataInput.report.author.avatar,
|
|
144
|
+
},
|
|
145
|
+
uri: metadataInput.report.uri,
|
|
146
|
+
},
|
|
147
|
+
]
|
|
148
|
+
: [],
|
|
149
|
+
},
|
|
150
|
+
shareClasses: shareClassesById,
|
|
151
|
+
onboarding: {
|
|
152
|
+
shareClasses: metadataInput.onboarding?.shareClasses || {},
|
|
153
|
+
taxInfoRequired: metadataInput.onboarding?.taxInfoRequired,
|
|
154
|
+
externalOnboardingUrl: metadataInput.onboarding?.externalOnboardingUrl,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
const cid = await self.config.pinJson(formattedMetadata);
|
|
158
|
+
const setMetadataData = encodeFunctionData({
|
|
159
|
+
abi: ABI.Hub,
|
|
160
|
+
functionName: 'setPoolMetadata',
|
|
161
|
+
args: [poolId.raw, toHex(cid)],
|
|
162
|
+
});
|
|
163
|
+
const addScData = metadataInput.shareClasses.map((sc) => encodeFunctionData({
|
|
164
|
+
abi: ABI.Hub,
|
|
165
|
+
functionName: 'addShareClass',
|
|
166
|
+
args: [
|
|
167
|
+
poolId.raw,
|
|
168
|
+
sc.tokenName,
|
|
169
|
+
sc.symbolName,
|
|
170
|
+
sc.salt?.startsWith('0x') ? sc.salt : toHex(sc.salt ?? randomUint(256), { size: 32 }),
|
|
171
|
+
],
|
|
172
|
+
}));
|
|
173
|
+
const accountIsDebitNormal = new Map();
|
|
174
|
+
const accountNumbers = [
|
|
175
|
+
...new Set(metadataInput.shareClasses.flatMap((sc) => Object.entries(sc.defaultAccounts ?? {})
|
|
176
|
+
.filter(([k, v]) => {
|
|
177
|
+
if (!v)
|
|
178
|
+
return false;
|
|
179
|
+
if (['asset', 'expense'].includes(k)) {
|
|
180
|
+
if (accountIsDebitNormal.get(v) === false)
|
|
181
|
+
throw new Error(`Account "${v}" is set as both credit normal and debit normal.`);
|
|
182
|
+
accountIsDebitNormal.set(v, true);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
if (accountIsDebitNormal.get(v) === true)
|
|
186
|
+
throw new Error(`Account "${v}" is set as both credit normal and debit normal.`);
|
|
187
|
+
accountIsDebitNormal.set(v, false);
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
})
|
|
191
|
+
.map(([, v]) => v))),
|
|
192
|
+
];
|
|
193
|
+
const createAccountsData = accountNumbers.map((account) => encodeFunctionData({
|
|
194
|
+
abi: ABI.Hub,
|
|
195
|
+
functionName: 'createAccount',
|
|
196
|
+
args: [poolId.raw, account, accountIsDebitNormal.get(account)],
|
|
197
|
+
}));
|
|
198
|
+
yield* doTransaction('Create pool', publicClient, () => {
|
|
199
|
+
return walletClient.writeContract({
|
|
200
|
+
address: addresses.hub,
|
|
201
|
+
abi: ABI.Hub,
|
|
202
|
+
functionName: 'multicall',
|
|
203
|
+
args: [[createPoolData, setMetadataData, ...addScData, ...createAccountsData]],
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}, chainId);
|
|
207
|
+
}
|
|
208
|
+
id(chainId) {
|
|
209
|
+
return this._query(['centrifugeId', chainId], () => this._protocolAddresses(chainId).pipe(switchMap(({ messageDispatcher }) => {
|
|
210
|
+
return this.getClient(chainId).readContract({
|
|
211
|
+
address: messageDispatcher,
|
|
212
|
+
abi: ABI.MessageDispatcher,
|
|
213
|
+
functionName: 'localCentrifugeId',
|
|
214
|
+
});
|
|
215
|
+
})));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get the existing pools on the different chains.
|
|
219
|
+
*/
|
|
220
|
+
pools() {
|
|
221
|
+
return this._queryIndexer(`{
|
|
222
|
+
pools {
|
|
223
|
+
items {
|
|
224
|
+
id
|
|
225
|
+
blockchain {
|
|
226
|
+
id
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}`, {}, (data) => {
|
|
231
|
+
return data.pools.items.map((pool) => {
|
|
232
|
+
const poolId = new PoolId(pool.id);
|
|
233
|
+
return new Pool(this, poolId.toString(), Number(pool.blockchain.id));
|
|
234
|
+
});
|
|
235
|
+
});
|
|
81
236
|
}
|
|
82
|
-
|
|
83
|
-
return this._query(null, () =>
|
|
237
|
+
pool(id) {
|
|
238
|
+
return this._query(null, () => this.pools().pipe(map((pools) => {
|
|
239
|
+
const pool = pools.find((pool) => pool.id.equals(id));
|
|
240
|
+
if (!pool)
|
|
241
|
+
throw new Error(`Pool with id ${id} not found`);
|
|
242
|
+
return pool;
|
|
243
|
+
})));
|
|
84
244
|
}
|
|
85
245
|
/**
|
|
86
246
|
* Get the metadata for an ERC20 token
|
|
@@ -89,18 +249,18 @@ export class Centrifuge {
|
|
|
89
249
|
*/
|
|
90
250
|
currency(address, chainId) {
|
|
91
251
|
const curAddress = address.toLowerCase();
|
|
92
|
-
|
|
93
|
-
return this._query(['currency', curAddress, cid], () => defer(async () => {
|
|
252
|
+
return this._query(['currency', curAddress, chainId], () => defer(async () => {
|
|
94
253
|
const contract = getContract({
|
|
95
254
|
address: curAddress,
|
|
96
255
|
abi: ABI.Currency,
|
|
97
|
-
client: this.getClient(
|
|
256
|
+
client: this.getClient(chainId),
|
|
98
257
|
});
|
|
99
258
|
const [decimals, name, symbol, supportsPermit] = await Promise.all([
|
|
100
259
|
contract.read.decimals(),
|
|
101
260
|
contract.read.name(),
|
|
102
261
|
contract.read.symbol(),
|
|
103
|
-
contract.read
|
|
262
|
+
contract.read
|
|
263
|
+
.PERMIT_TYPEHASH()
|
|
104
264
|
.then((hash) => hash === PERMIT_TYPEHASH)
|
|
105
265
|
.catch(() => false),
|
|
106
266
|
]);
|
|
@@ -109,11 +269,14 @@ export class Centrifuge {
|
|
|
109
269
|
decimals,
|
|
110
270
|
name,
|
|
111
271
|
symbol,
|
|
112
|
-
chainId
|
|
272
|
+
chainId,
|
|
113
273
|
supportsPermit,
|
|
114
274
|
};
|
|
115
275
|
}));
|
|
116
276
|
}
|
|
277
|
+
investor(address) {
|
|
278
|
+
return this._query(null, () => of(new Investor(this, address)));
|
|
279
|
+
}
|
|
117
280
|
/**
|
|
118
281
|
* Get the balance of an ERC20 token for a given owner.
|
|
119
282
|
* @param currency - The token address
|
|
@@ -122,16 +285,19 @@ export class Centrifuge {
|
|
|
122
285
|
*/
|
|
123
286
|
balance(currency, owner, chainId) {
|
|
124
287
|
const address = owner.toLowerCase();
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
288
|
+
return this._query(['balance', currency, owner, chainId], () => {
|
|
289
|
+
return this.currency(currency, chainId).pipe(switchMap((currencyMeta) => defer(async () => {
|
|
290
|
+
const val = await this.getClient(chainId).readContract({
|
|
291
|
+
address: currency,
|
|
292
|
+
abi: ABI.Currency,
|
|
293
|
+
functionName: 'balanceOf',
|
|
294
|
+
args: [address],
|
|
295
|
+
});
|
|
296
|
+
return {
|
|
297
|
+
balance: new Balance(val, currencyMeta.decimals),
|
|
298
|
+
currency: currencyMeta,
|
|
299
|
+
};
|
|
300
|
+
}).pipe(repeatOnEvents(this, {
|
|
135
301
|
address: currency,
|
|
136
302
|
abi: ABI.Currency,
|
|
137
303
|
eventName: 'Transfer',
|
|
@@ -140,18 +306,148 @@ export class Centrifuge {
|
|
|
140
306
|
return event.args.from?.toLowerCase() === address || event.args.to?.toLowerCase() === address;
|
|
141
307
|
});
|
|
142
308
|
},
|
|
143
|
-
},
|
|
309
|
+
}, chainId))));
|
|
144
310
|
});
|
|
145
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Get the assets that exist on a given spoke chain that have been registered on a given hub chain.
|
|
314
|
+
* @param spokeChainId - The chain ID where the assets exist
|
|
315
|
+
* @param hubChainId - The chain ID where the assets should optionally be registered
|
|
316
|
+
*/
|
|
317
|
+
assets(spokeChainId, hubChainId = spokeChainId) {
|
|
318
|
+
return this._query(null, () => combineLatest([this.id(spokeChainId), this.id(hubChainId)]).pipe(switchMap(([spokeCentId, hubCentId]) => this._queryIndexer(`query ($hubCentId: String!) {
|
|
319
|
+
assetRegistrations(where: { centrifugeId: $hubCentId, decimals_gt: 0 }) {
|
|
320
|
+
items {
|
|
321
|
+
assetId
|
|
322
|
+
name
|
|
323
|
+
symbol
|
|
324
|
+
decimals
|
|
325
|
+
asset {
|
|
326
|
+
centrifugeId
|
|
327
|
+
address
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}`, { hubCentId: String(hubCentId) }, (data) => {
|
|
332
|
+
return data.assetRegistrations.items
|
|
333
|
+
.filter((assetReg) => assetReg.asset && Number(assetReg.asset.centrifugeId) === spokeCentId)
|
|
334
|
+
.map((assetReg) => {
|
|
335
|
+
return {
|
|
336
|
+
id: new AssetId(assetReg.assetId),
|
|
337
|
+
address: assetReg.asset.address,
|
|
338
|
+
name: assetReg.name,
|
|
339
|
+
symbol: assetReg.symbol,
|
|
340
|
+
decimals: assetReg.decimals,
|
|
341
|
+
};
|
|
342
|
+
});
|
|
343
|
+
}))));
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Get the valuation addresses that can be used for holdings.
|
|
347
|
+
*/
|
|
348
|
+
valuations(chainId) {
|
|
349
|
+
return this._query(null, () => this._protocolAddresses(chainId).pipe(map(({ identityValuation }) => {
|
|
350
|
+
return {
|
|
351
|
+
identityValuation,
|
|
352
|
+
};
|
|
353
|
+
})));
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get the restriction hook addresses that can be used for share tokens.
|
|
357
|
+
*/
|
|
358
|
+
restrictionHooks(chainId) {
|
|
359
|
+
return this._query(null, () => this._protocolAddresses(chainId).pipe(map(({ freezeOnlyHook, redemptionRestrictionsHook, fullRestrictionsHook /* freelyTransferableHook */ }) => {
|
|
360
|
+
return {
|
|
361
|
+
freezeOnlyHook,
|
|
362
|
+
redemptionRestrictionsHook,
|
|
363
|
+
fullRestrictionsHook,
|
|
364
|
+
};
|
|
365
|
+
})));
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Register an asset
|
|
369
|
+
* @param originChainId - The chain ID where the asset exists
|
|
370
|
+
* @param registerOnChainId - The chain ID where the asset should be registered
|
|
371
|
+
* @param assetAddress - The address of the asset to register
|
|
372
|
+
* @param tokenId - Optional token ID for ERC6909 assets
|
|
373
|
+
*/
|
|
374
|
+
registerAsset(originChainId, registerOnChainId, assetAddress, tokenId = 0) {
|
|
375
|
+
const self = this;
|
|
376
|
+
return this._transact(async function* ({ walletClient, publicClient }) {
|
|
377
|
+
const [addresses, id, estimate] = await Promise.all([
|
|
378
|
+
self._protocolAddresses(originChainId),
|
|
379
|
+
self.id(registerOnChainId),
|
|
380
|
+
self._estimate(originChainId, { chainId: registerOnChainId }, MessageType.RegisterAsset),
|
|
381
|
+
]);
|
|
382
|
+
yield* doTransaction('Register asset', publicClient, () => walletClient.writeContract({
|
|
383
|
+
address: addresses.spoke,
|
|
384
|
+
abi: ABI.Spoke,
|
|
385
|
+
functionName: 'registerAsset',
|
|
386
|
+
args: [id, assetAddress, BigInt(tokenId)],
|
|
387
|
+
value: estimate,
|
|
388
|
+
}));
|
|
389
|
+
}, originChainId);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Get the decimals of asset
|
|
393
|
+
*/
|
|
394
|
+
assetDecimals(assetId, chainId) {
|
|
395
|
+
return this._query(['assetDecimals', assetId.toString()], () => this._protocolAddresses(chainId).pipe(switchMap(({ hubRegistry }) => this.getClient(chainId).readContract({
|
|
396
|
+
address: hubRegistry,
|
|
397
|
+
// Use inline ABI because of function overload
|
|
398
|
+
abi: parseAbi(['function decimals(uint128) view returns (uint8)']),
|
|
399
|
+
functionName: 'decimals',
|
|
400
|
+
args: [assetId.raw],
|
|
401
|
+
}))));
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Get the allowance of an ERC20 or ERC6909 token.
|
|
405
|
+
* which is the contract that moves funds into the vault on behalf of the investor.
|
|
406
|
+
* @param owner - The address of the owner
|
|
407
|
+
* @param spender - The address of the spender
|
|
408
|
+
* @param chainId - The chain ID where the asset is located
|
|
409
|
+
* @param asset - The address of the asset
|
|
410
|
+
* @param tokenId - Optional token ID for ERC6909 assets
|
|
411
|
+
* @internal
|
|
412
|
+
*/
|
|
413
|
+
_allowance(owner, spender, chainId, asset, tokenId) {
|
|
414
|
+
return this._query(['allowance', owner.toLowerCase(), spender.toLowerCase(), asset.toLowerCase(), chainId, tokenId], () => defer(async () => {
|
|
415
|
+
const client = this.getClient(chainId);
|
|
416
|
+
if (tokenId) {
|
|
417
|
+
return client.readContract({
|
|
418
|
+
address: asset,
|
|
419
|
+
abi: ABI.ERC6909,
|
|
420
|
+
functionName: 'allowance',
|
|
421
|
+
args: [owner, spender, tokenId],
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
return client.readContract({
|
|
425
|
+
address: asset,
|
|
426
|
+
abi: ABI.Currency,
|
|
427
|
+
functionName: 'allowance',
|
|
428
|
+
args: [owner, spender],
|
|
429
|
+
});
|
|
430
|
+
}).pipe(repeatOnEvents(this, {
|
|
431
|
+
address: asset,
|
|
432
|
+
abi: [ABI.Currency, ABI.ERC6909],
|
|
433
|
+
eventName: ['Approval', 'Transfer'],
|
|
434
|
+
filter: (events) => {
|
|
435
|
+
return events.some((event) => {
|
|
436
|
+
return (event.args.owner?.toLowerCase() === owner.toLowerCase() ||
|
|
437
|
+
event.args.spender?.toLowerCase() === owner.toLowerCase() ||
|
|
438
|
+
event.args.from?.toLowerCase() === owner.toLowerCase());
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
}, chainId)));
|
|
442
|
+
}
|
|
146
443
|
/**
|
|
147
444
|
* Returns an observable of all events on a given chain.
|
|
148
445
|
* @internal
|
|
149
446
|
*/
|
|
150
447
|
_events(chainId) {
|
|
151
|
-
|
|
152
|
-
return this._query(['events', cid], () => using(() => {
|
|
448
|
+
return this._query(['events', chainId], () => using(() => {
|
|
153
449
|
const subject = new Subject();
|
|
154
|
-
const unwatch = this.getClient(
|
|
450
|
+
const unwatch = this.getClient(chainId).watchEvent({
|
|
155
451
|
onLogs: (logs) => subject.next(logs),
|
|
156
452
|
});
|
|
157
453
|
return {
|
|
@@ -199,30 +495,26 @@ export class Centrifuge {
|
|
|
199
495
|
});
|
|
200
496
|
}
|
|
201
497
|
_queryIndexer(query, variables, postProcess) {
|
|
202
|
-
return this._query([query, variables], () =>
|
|
203
|
-
|
|
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
|
-
});
|
|
498
|
+
return this._query([query, variables], () =>
|
|
499
|
+
// If subscribed, refetch every 2 minutes
|
|
500
|
+
timer(0, 120_000).pipe(switchMap(() => this._getIndexerObservable(query, variables).pipe(map(postProcess ?? identity)))));
|
|
220
501
|
}
|
|
221
502
|
/**
|
|
222
503
|
* @internal
|
|
223
504
|
*/
|
|
224
505
|
_queryIPFS(hash) {
|
|
225
|
-
return this._query([hash], () =>
|
|
506
|
+
return this._query([hash], () => defer(async () => {
|
|
507
|
+
const url = getUrlFromHash(hash, this.#config.ipfsUrl);
|
|
508
|
+
if (!url) {
|
|
509
|
+
throw new Error(`Invalid IPFS hash: ${hash}`);
|
|
510
|
+
}
|
|
511
|
+
const res = await fetch(url);
|
|
512
|
+
if (!res.ok) {
|
|
513
|
+
throw new Error(`Error fetching IPFS hash ${hash}: ${res.statusText}`);
|
|
514
|
+
}
|
|
515
|
+
const data = (await res.json());
|
|
516
|
+
return data;
|
|
517
|
+
}));
|
|
226
518
|
}
|
|
227
519
|
#memoized = new Map();
|
|
228
520
|
#memoizeWith(keys, callback) {
|
|
@@ -289,10 +581,9 @@ export class Centrifuge {
|
|
|
289
581
|
* const chainId = 1
|
|
290
582
|
*
|
|
291
583
|
* // Wrap an observable that only emits one value and then completes
|
|
292
|
-
* //
|
|
293
584
|
* const query = this._query(['balance', address, tUSD, chainId], () => {
|
|
294
585
|
* return defer(() => fetchBalance(address, tUSD, chainId))
|
|
295
|
-
* }, { valueCacheTime:
|
|
586
|
+
* }, { valueCacheTime: 60_000 })
|
|
296
587
|
*
|
|
297
588
|
* // Logs the current balance and updated balances whenever a new
|
|
298
589
|
* const obs1 = query.subscribe(balance => console.log(balance))
|
|
@@ -316,14 +607,17 @@ export class Centrifuge {
|
|
|
316
607
|
* @internal
|
|
317
608
|
*/
|
|
318
609
|
_query(keys, observableCallback, options) {
|
|
610
|
+
const cache = options?.cache !== false && this.#config.cache !== false;
|
|
611
|
+
const obsCacheTime = options?.observableCacheTime ?? this.#config.pollingInterval ?? 4000;
|
|
319
612
|
function get() {
|
|
320
613
|
const sharedSubject = new Subject();
|
|
321
614
|
function createShared() {
|
|
322
615
|
const $shared = observableCallback().pipe(keys
|
|
323
616
|
? shareReplayWithDelayedReset({
|
|
324
|
-
bufferSize:
|
|
325
|
-
resetDelay:
|
|
326
|
-
|
|
617
|
+
bufferSize: cache ? 1 : 0,
|
|
618
|
+
resetDelay: cache ? obsCacheTime : 0,
|
|
619
|
+
// TODO: Fix valueCacheTime to not cause an infinite loop when the value is expired.
|
|
620
|
+
// windowTime: options?.valueCacheTime ?? Infinity,
|
|
327
621
|
})
|
|
328
622
|
: map((val) => val));
|
|
329
623
|
sharedSubject.next($shared);
|
|
@@ -343,50 +637,9 @@ export class Centrifuge {
|
|
|
343
637
|
return keys ? this.#memoizeWith(keys, get) : get();
|
|
344
638
|
}
|
|
345
639
|
/**
|
|
346
|
-
* Executes
|
|
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.
|
|
640
|
+
* Executes one or more transactions on a given chain.
|
|
388
641
|
* When subscribed to, it emits status updates as it progresses.
|
|
389
|
-
* When awaited, it returns the final confirmed if successful.
|
|
642
|
+
* When awaited, it returns the final confirmed result if successful.
|
|
390
643
|
* Will additionally prompt the user to switch chains if they're not on the correct chain.
|
|
391
644
|
*
|
|
392
645
|
* @example
|
|
@@ -413,41 +666,53 @@ export class Centrifuge {
|
|
|
413
666
|
* // { type: 'SigningTransaction', title: 'Invest' }
|
|
414
667
|
* // { type: 'TransactionPending', title: 'Invest', hash: '0x123...abc' }
|
|
415
668
|
* // { type: 'TransactionConfirmed', title: 'Invest', hash: '0x123...abc', receipt: { ... } }
|
|
669
|
+
* ```
|
|
416
670
|
*
|
|
417
671
|
* @internal
|
|
418
672
|
*/
|
|
419
|
-
|
|
420
|
-
const targetChainId = chainId ?? this.config.defaultChain;
|
|
673
|
+
_transact(transactionCallback, chainId) {
|
|
421
674
|
const self = this;
|
|
422
675
|
async function* transact() {
|
|
676
|
+
let isBatching = false;
|
|
677
|
+
if (self.#isBatching.has($tx)) {
|
|
678
|
+
isBatching = true;
|
|
679
|
+
}
|
|
423
680
|
const { signer } = self;
|
|
424
681
|
if (!signer)
|
|
425
682
|
throw new Error('Signer not set');
|
|
426
|
-
const publicClient = self.getClient(
|
|
427
|
-
const chain = self.getChainConfig(
|
|
428
|
-
|
|
429
|
-
? createWalletClient({
|
|
683
|
+
const publicClient = self.getClient(chainId);
|
|
684
|
+
const chain = self.getChainConfig(chainId);
|
|
685
|
+
let walletClient = isLocalAccount(signer)
|
|
686
|
+
? createWalletClient({
|
|
687
|
+
account: signer,
|
|
688
|
+
chain,
|
|
689
|
+
transport: http(),
|
|
690
|
+
})
|
|
430
691
|
: createWalletClient({ transport: custom(signer) });
|
|
431
|
-
const [address] = await
|
|
692
|
+
const [address] = await walletClient.getAddresses();
|
|
432
693
|
if (!address)
|
|
433
694
|
throw new Error('No account selected');
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
695
|
+
if (!isBatching) {
|
|
696
|
+
const selectedChain = await walletClient.getChainId();
|
|
697
|
+
if (selectedChain !== chainId) {
|
|
698
|
+
yield { type: 'SwitchingChain', chainId };
|
|
699
|
+
await walletClient.switchChain({ id: chainId });
|
|
700
|
+
}
|
|
438
701
|
}
|
|
439
702
|
// Re-create the wallet client with the correct chain and account
|
|
440
703
|
// Saves having to pass `account` and `chain` to every `writeContract` call
|
|
441
|
-
|
|
442
|
-
?
|
|
704
|
+
walletClient = isLocalAccount(signer)
|
|
705
|
+
? walletClient
|
|
443
706
|
: createWalletClient({ account: address, chain, transport: custom(signer) });
|
|
444
707
|
const transaction = transactionCallback({
|
|
708
|
+
isBatching,
|
|
445
709
|
signingAddress: address,
|
|
446
710
|
chain,
|
|
447
|
-
chainId
|
|
711
|
+
chainId,
|
|
448
712
|
publicClient,
|
|
449
713
|
walletClient,
|
|
450
714
|
signer,
|
|
715
|
+
root: self,
|
|
451
716
|
});
|
|
452
717
|
if (Symbol.asyncIterator in transaction) {
|
|
453
718
|
yield* transaction;
|
|
@@ -460,7 +725,171 @@ export class Centrifuge {
|
|
|
460
725
|
}
|
|
461
726
|
}
|
|
462
727
|
const $tx = defer(transact).pipe(mergeMap((d) => (isObservable(d) ? d : of(d))));
|
|
463
|
-
|
|
728
|
+
makeThenable($tx, true);
|
|
729
|
+
Object.assign($tx, {
|
|
730
|
+
chainId,
|
|
731
|
+
});
|
|
732
|
+
return $tx;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Batch multiple transactions together into a single transaction.
|
|
736
|
+
* It's not exposed, because it is somewhat limited and requires knowledge of internals.
|
|
737
|
+
* It only works when there's only a single transaction being done in the method.
|
|
738
|
+
* It only works for methods that wrap the transaction in `wrapTransaction`.
|
|
739
|
+
* It only works when the transactions are executed on the same contract on the same chain,
|
|
740
|
+
* and that contract supports multicall
|
|
741
|
+
* @internal
|
|
742
|
+
*/
|
|
743
|
+
_experimental_batch(title, transactions) {
|
|
744
|
+
const chainIds = [...new Set(transactions.map((tx) => tx.chainId))];
|
|
745
|
+
if (chainIds.length !== 1) {
|
|
746
|
+
throw new Error(`Cannot batch transactions on different chains: ${chainIds.join(', ')}`);
|
|
747
|
+
}
|
|
748
|
+
for (const tx of transactions) {
|
|
749
|
+
this.#isBatching.add(tx);
|
|
750
|
+
}
|
|
751
|
+
return this._transact((ctx) => combineLatest(transactions.map((tx) => tx.pipe(first()))).pipe(switchMap(async function* (batches_) {
|
|
752
|
+
const batches = batches_;
|
|
753
|
+
if (!batches.every((b) => b.data && b.contract)) {
|
|
754
|
+
throw new Error('Not all transactions can be batched');
|
|
755
|
+
}
|
|
756
|
+
const value = batches.reduce((acc, b) => acc + (b.value ?? 0n), 0n);
|
|
757
|
+
const data = batches.map((b) => b.data).flat();
|
|
758
|
+
const messages = batches.reduce((acc, b) => {
|
|
759
|
+
if (b.messages) {
|
|
760
|
+
Object.entries(b.messages).forEach(([cid, types]) => {
|
|
761
|
+
const chainId = Number(cid);
|
|
762
|
+
if (!acc[chainId])
|
|
763
|
+
acc[chainId] = [];
|
|
764
|
+
acc[chainId].push(...types);
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
return acc;
|
|
768
|
+
}, {});
|
|
769
|
+
const contracts = [...new Set(batches.map((b) => b.contract))];
|
|
770
|
+
if (contracts.length !== 1) {
|
|
771
|
+
throw new Error(`Cannot batch transactions to different contracts: ${contracts.join(', ')}`);
|
|
772
|
+
}
|
|
773
|
+
yield* wrapTransaction(title, ctx, { data, value, contract: contracts[0], messages });
|
|
774
|
+
})), chainIds[0]);
|
|
775
|
+
}
|
|
776
|
+
/** @internal */
|
|
777
|
+
_protocolAddresses(chainId) {
|
|
778
|
+
return this._query(['protocolAddresses'], () => this._getIndexerObservable(`{
|
|
779
|
+
deployments {
|
|
780
|
+
items {
|
|
781
|
+
accounting
|
|
782
|
+
asyncRequestManager
|
|
783
|
+
asyncVaultFactory
|
|
784
|
+
axelarAdapter
|
|
785
|
+
balanceSheet
|
|
786
|
+
centrifugeId
|
|
787
|
+
chainId
|
|
788
|
+
freezeOnlyHook
|
|
789
|
+
fullRestrictionsHook
|
|
790
|
+
gasService
|
|
791
|
+
gateway
|
|
792
|
+
globalEscrow
|
|
793
|
+
guardian
|
|
794
|
+
holdings
|
|
795
|
+
hub
|
|
796
|
+
hubRegistry
|
|
797
|
+
identityValuation
|
|
798
|
+
messageDispatcher
|
|
799
|
+
messageProcessor
|
|
800
|
+
multiAdapter
|
|
801
|
+
poolEscrowFactory
|
|
802
|
+
redemptionRestrictionsHook
|
|
803
|
+
root
|
|
804
|
+
routerEscrow
|
|
805
|
+
shareClassManager
|
|
806
|
+
spoke
|
|
807
|
+
syncDepositVaultFactory
|
|
808
|
+
syncManager
|
|
809
|
+
wormholeAdapter
|
|
810
|
+
vaultRouter
|
|
811
|
+
tokenFactory
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}`, { chainId: String(chainId) }).pipe(map((data) => {
|
|
815
|
+
if (!this.chains.includes(chainId)) {
|
|
816
|
+
throw new Error(`Chain ID "${chainId}" not supported`);
|
|
817
|
+
}
|
|
818
|
+
const deployment = data.deployments.items.find((d) => Number(d.chainId) === chainId);
|
|
819
|
+
if (!deployment) {
|
|
820
|
+
throw new Error(`No protocol contracts found for chain ID "${chainId}"`);
|
|
821
|
+
}
|
|
822
|
+
return deployment;
|
|
823
|
+
})));
|
|
824
|
+
}
|
|
825
|
+
/** @internal */
|
|
826
|
+
_getQuote(valuationAddress, baseAmount, baseAssetId, quoteAssetId, chainId) {
|
|
827
|
+
return this._query(['getQuote', baseAmount, baseAssetId.toString(), quoteAssetId.toString()], () => timer(0, 60_000).pipe(switchMap(() => this._protocolAddresses(chainId)), switchMap(({ hubRegistry }) => defer(async () => {
|
|
828
|
+
const [quote, quoteDecimals] = await Promise.all([
|
|
829
|
+
this.getClient(chainId).readContract({
|
|
830
|
+
address: valuationAddress,
|
|
831
|
+
abi: ABI.Valuation,
|
|
832
|
+
functionName: 'getQuote',
|
|
833
|
+
args: [baseAmount.toBigInt(), baseAssetId.raw, quoteAssetId.raw],
|
|
834
|
+
}),
|
|
835
|
+
this.getClient(chainId).readContract({
|
|
836
|
+
address: hubRegistry,
|
|
837
|
+
// Use inline ABI because of function overload
|
|
838
|
+
abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
|
|
839
|
+
functionName: 'decimals',
|
|
840
|
+
args: [quoteAssetId.raw],
|
|
841
|
+
}),
|
|
842
|
+
]);
|
|
843
|
+
return new Balance(quote, quoteDecimals);
|
|
844
|
+
}))));
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Estimates the gas cost needed to bridge the message from one chain to another,
|
|
848
|
+
* that results from a transaction
|
|
849
|
+
* @internal
|
|
850
|
+
*/
|
|
851
|
+
_estimate(fromChain, to, messageType) {
|
|
852
|
+
return this._query(['estimate', fromChain, to], () => this._protocolAddresses(fromChain).pipe(switchMap(({ multiAdapter, gasService }) => {
|
|
853
|
+
const types = Array.isArray(messageType) ? messageType : [messageType];
|
|
854
|
+
return combineLatest([
|
|
855
|
+
'chainId' in to ? this.id(to.chainId) : of(to.centId),
|
|
856
|
+
...types.map((type) => this.getClient(fromChain).readContract({
|
|
857
|
+
address: gasService,
|
|
858
|
+
abi: ABI.GasService,
|
|
859
|
+
functionName: 'batchGasLimit',
|
|
860
|
+
args: [type],
|
|
861
|
+
})),
|
|
862
|
+
]).pipe(switchMap(([toCentId, ...gasLimits]) => {
|
|
863
|
+
return this.getClient(fromChain).readContract({
|
|
864
|
+
address: multiAdapter,
|
|
865
|
+
abi: ABI.MultiAdapter,
|
|
866
|
+
functionName: 'estimate',
|
|
867
|
+
args: [toCentId, '0x0', gasLimits.reduce((acc, val) => acc + val, 0n)],
|
|
868
|
+
});
|
|
869
|
+
}));
|
|
870
|
+
})));
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Get the asset address and token ID for a given asset ID on a specific chain.
|
|
874
|
+
* @param assetId - The asset ID to query
|
|
875
|
+
* @param chainId - The chain ID of the Spoke where the asset was registered
|
|
876
|
+
* @internal
|
|
877
|
+
*/
|
|
878
|
+
_asset(assetId, chainId) {
|
|
879
|
+
return this._query(['asset', assetId.toString(), chainId], () => this._protocolAddresses(chainId).pipe(switchMap(async ({ spoke }) => {
|
|
880
|
+
const [assetAddress, tokenId] = await this.getClient(chainId).readContract({
|
|
881
|
+
address: spoke,
|
|
882
|
+
abi: ABI.Spoke,
|
|
883
|
+
functionName: 'idToAsset',
|
|
884
|
+
args: [assetId.raw],
|
|
885
|
+
});
|
|
886
|
+
if (assetAddress === NULL_ADDRESS)
|
|
887
|
+
throw new Error(`Asset with ID "${assetId}" not found on chain "${chainId}"`);
|
|
888
|
+
return {
|
|
889
|
+
address: assetAddress,
|
|
890
|
+
tokenId,
|
|
891
|
+
};
|
|
892
|
+
})));
|
|
464
893
|
}
|
|
465
894
|
}
|
|
466
895
|
//# sourceMappingURL=Centrifuge.js.map
|