@centrifuge/sdk 0.0.0-alpha.2 → 0.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/dist/Centrifuge.d.ts +286 -259
- package/dist/Centrifuge.d.ts.map +1 -1
- package/dist/Centrifuge.js +538 -67
- 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 +487 -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/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 +8243 -8
- package/dist/abi/index.d.ts.map +1 -1
- package/dist/abi/index.js +32 -16
- package/dist/abi/index.js.map +1 -1
- package/dist/config/chains.d.ts +41 -0
- package/dist/config/chains.d.ts.map +1 -1
- package/dist/config/chains.js +11 -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/Entity.d.ts +8 -0
- package/dist/entities/Entity.d.ts.map +1 -0
- package/dist/{Entity.js → entities/Entity.js} +6 -1
- 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 +37 -0
- package/dist/entities/Investor.d.ts.map +1 -0
- package/dist/entities/Investor.js +29 -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 +89 -0
- package/dist/entities/Pool.d.ts.map +1 -0
- package/dist/entities/Pool.js +254 -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 +82 -0
- package/dist/entities/Pool.test.js.map +1 -0
- package/dist/entities/PoolNetwork.d.ts +63 -0
- package/dist/entities/PoolNetwork.d.ts.map +1 -0
- package/dist/entities/PoolNetwork.js +274 -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 +61 -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 +153 -0
- package/dist/entities/ShareClass.d.ts.map +1 -0
- package/dist/entities/ShareClass.js +833 -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 +109 -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/{Vault.js → entities/Vault.js} +217 -145
- 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 +277 -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 +65 -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 +5 -0
- package/dist/types/transaction.d.ts.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.map +1 -1
- package/dist/utils/transaction.js +21 -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 +11 -6
- 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 -235
- 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.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,46 @@
|
|
|
1
|
-
import { concatWith, defaultIfEmpty, defer, filter, identity, isObservable, map, mergeMap, of, Subject, switchMap, using, } from 'rxjs';
|
|
1
|
+
import { combineLatest, concatWith, defaultIfEmpty, defer, filter, identity, isObservable, map, mergeMap, of, Subject, switchMap, 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, getContract, http, parseAbi, parseEventLogs, toHex, } from 'viem';
|
|
4
4
|
import { ABI } from './abi/index.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { chainIdToNetwork, chains } from './config/chains.js';
|
|
6
|
+
import { currencies } from './config/protocol.js';
|
|
7
7
|
import { PERMIT_TYPEHASH } from './constants.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { Investor } from './entities/Investor.js';
|
|
9
|
+
import { Pool } from './entities/Pool.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
15
|
import { doTransaction, isLocalAccount } 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://
|
|
20
|
+
indexerUrl: 'https://api-v3-hitz.marble.live/graphql',
|
|
16
21
|
alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
|
|
17
22
|
infuraKey: '8ed99a9a115349bbbc01dcf3a24edc96',
|
|
18
|
-
defaultChain: 1,
|
|
19
23
|
ipfsUrl: 'https://centrifuge.mypinata.cloud',
|
|
24
|
+
...createPinning(PINNING_API_DEMO),
|
|
20
25
|
},
|
|
21
26
|
demo: {
|
|
22
|
-
indexerUrl: 'https://api.
|
|
27
|
+
indexerUrl: 'https://api-v3-hitz.marble.live/graphql',
|
|
23
28
|
alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
|
|
24
29
|
infuraKey: '8cd8e043ee8d4001b97a1c37e08fd9dd',
|
|
25
|
-
defaultChain: 11155111,
|
|
26
30
|
ipfsUrl: 'https://centrifuge.mypinata.cloud',
|
|
31
|
+
...createPinning(PINNING_API_DEMO),
|
|
27
32
|
},
|
|
28
33
|
dev: {
|
|
29
|
-
indexerUrl: 'https://api.
|
|
34
|
+
indexerUrl: 'https://api-v3-hitz.marble.live/graphql',
|
|
30
35
|
alchemyKey: 'KNR-1LZhNqWOxZS2AN8AFeaiESBV10qZ',
|
|
31
36
|
infuraKey: '8cd8e043ee8d4001b97a1c37e08fd9dd',
|
|
32
|
-
defaultChain: 11155111,
|
|
33
37
|
ipfsUrl: 'https://centrifuge.mypinata.cloud',
|
|
38
|
+
...createPinning(PINNING_API_DEMO),
|
|
34
39
|
},
|
|
35
40
|
};
|
|
36
41
|
const defaultConfig = {
|
|
37
42
|
environment: 'mainnet',
|
|
43
|
+
cache: true,
|
|
38
44
|
};
|
|
39
45
|
export class Centrifuge {
|
|
40
46
|
#config;
|
|
@@ -43,13 +49,13 @@ export class Centrifuge {
|
|
|
43
49
|
}
|
|
44
50
|
#clients = new Map();
|
|
45
51
|
getClient(chainId) {
|
|
46
|
-
return this.#clients.get(chainId
|
|
52
|
+
return this.#clients.get(chainId);
|
|
47
53
|
}
|
|
48
54
|
get chains() {
|
|
49
55
|
return [...this.#clients.keys()];
|
|
50
56
|
}
|
|
51
57
|
getChainConfig(chainId) {
|
|
52
|
-
return this.getClient(chainId
|
|
58
|
+
return this.getClient(chainId).chain;
|
|
53
59
|
}
|
|
54
60
|
#signer = null;
|
|
55
61
|
setSigner(signer) {
|
|
@@ -73,14 +79,182 @@ export class Centrifuge {
|
|
|
73
79
|
if (!rpcUrl) {
|
|
74
80
|
console.warn(`No rpcUrl defined for chain ${chain.id}. Using public RPC endpoint.`);
|
|
75
81
|
}
|
|
76
|
-
|
|
82
|
+
if (!currencies[chain.id]) {
|
|
83
|
+
console.warn(`No config defined for chain ${chain.id}. Skipping.`);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.#clients.set(chain.id, createPublicClient({
|
|
87
|
+
chain,
|
|
88
|
+
transport: http(rpcUrl),
|
|
89
|
+
batch: { multicall: true },
|
|
90
|
+
pollingInterval: this.#config.pollingInterval,
|
|
91
|
+
cacheTime: 100,
|
|
92
|
+
}));
|
|
77
93
|
});
|
|
78
94
|
}
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Create a new pool on the given chain.
|
|
97
|
+
* @param metadataInput - The metadata for the pool
|
|
98
|
+
* @param currencyCode - The currency code for the pool
|
|
99
|
+
* @param chainId - The chain ID to create the pool on
|
|
100
|
+
* @param counter - The pool counter, used to create a unique pool ID (uint48)
|
|
101
|
+
*/
|
|
102
|
+
createPool(metadataInput, currencyCode = 840, chainId, counter) {
|
|
103
|
+
const self = this;
|
|
104
|
+
return this._transactSequence(async function* ({ walletClient, signingAddress, publicClient }) {
|
|
105
|
+
const [addresses, id] = await Promise.all([self._protocolAddresses(chainId), self.id(chainId)]);
|
|
106
|
+
const poolId = PoolId.from(id, counter ?? randomUint(48));
|
|
107
|
+
const createPoolData = encodeFunctionData({
|
|
108
|
+
abi: ABI.Hub,
|
|
109
|
+
functionName: 'createPool',
|
|
110
|
+
args: [poolId.raw, signingAddress, BigInt(currencyCode)],
|
|
111
|
+
});
|
|
112
|
+
const scIds = Array.from({ length: metadataInput.shareClasses.length }, (_, i) => ShareClassId.from(poolId, i + 1));
|
|
113
|
+
const shareClassesById = {};
|
|
114
|
+
metadataInput.shareClasses.forEach((sc, index) => {
|
|
115
|
+
shareClassesById[scIds[index].raw] = {
|
|
116
|
+
minInitialInvestment: Balance.fromFloat(sc.minInvestment, 18).toString(),
|
|
117
|
+
apyPercentage: sc.apyPercentage,
|
|
118
|
+
apy: sc.apy,
|
|
119
|
+
defaultAccounts: sc.defaultAccounts,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
const formattedMetadata = {
|
|
123
|
+
version: 1,
|
|
124
|
+
pool: {
|
|
125
|
+
name: metadataInput.poolName,
|
|
126
|
+
icon: metadataInput.poolIcon,
|
|
127
|
+
asset: {
|
|
128
|
+
class: metadataInput.assetClass,
|
|
129
|
+
subClass: metadataInput.subAssetClass,
|
|
130
|
+
},
|
|
131
|
+
issuer: {
|
|
132
|
+
name: metadataInput.issuerName,
|
|
133
|
+
repName: metadataInput.issuerRepName,
|
|
134
|
+
description: metadataInput.issuerDescription,
|
|
135
|
+
email: metadataInput.email,
|
|
136
|
+
logo: metadataInput.issuerLogo,
|
|
137
|
+
shortDescription: metadataInput.issuerShortDescription,
|
|
138
|
+
categories: metadataInput.issuerCategories,
|
|
139
|
+
},
|
|
140
|
+
poolStructure: metadataInput.poolStructure,
|
|
141
|
+
investorType: metadataInput.investorType,
|
|
142
|
+
links: {
|
|
143
|
+
executiveSummary: metadataInput.executiveSummary,
|
|
144
|
+
forum: metadataInput.forum,
|
|
145
|
+
website: metadataInput.website,
|
|
146
|
+
},
|
|
147
|
+
details: metadataInput.details,
|
|
148
|
+
status: 'open',
|
|
149
|
+
listed: metadataInput.listed ?? true,
|
|
150
|
+
poolRatings: metadataInput.poolRatings.length > 0 ? metadataInput.poolRatings : [],
|
|
151
|
+
reports: metadataInput.report
|
|
152
|
+
? [
|
|
153
|
+
{
|
|
154
|
+
author: {
|
|
155
|
+
name: metadataInput.report.author.name,
|
|
156
|
+
title: metadataInput.report.author.title,
|
|
157
|
+
avatar: metadataInput.report.author.avatar,
|
|
158
|
+
},
|
|
159
|
+
uri: metadataInput.report.uri,
|
|
160
|
+
},
|
|
161
|
+
]
|
|
162
|
+
: [],
|
|
163
|
+
},
|
|
164
|
+
shareClasses: shareClassesById,
|
|
165
|
+
onboarding: {
|
|
166
|
+
shareClasses: metadataInput.onboarding?.shareClasses || {},
|
|
167
|
+
taxInfoRequired: metadataInput.onboarding?.taxInfoRequired,
|
|
168
|
+
externalOnboardingUrl: metadataInput.onboarding?.externalOnboardingUrl,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
const cid = await self.config.pinJson(formattedMetadata);
|
|
172
|
+
const setMetadataData = encodeFunctionData({
|
|
173
|
+
abi: ABI.Hub,
|
|
174
|
+
functionName: 'setPoolMetadata',
|
|
175
|
+
args: [poolId.raw, toHex(cid)],
|
|
176
|
+
});
|
|
177
|
+
const addScData = metadataInput.shareClasses.map((sc) => encodeFunctionData({
|
|
178
|
+
abi: ABI.Hub,
|
|
179
|
+
functionName: 'addShareClass',
|
|
180
|
+
args: [
|
|
181
|
+
poolId.raw,
|
|
182
|
+
sc.tokenName,
|
|
183
|
+
sc.symbolName,
|
|
184
|
+
sc.salt?.startsWith('0x') ? sc.salt : toHex(sc.salt ?? randomUint(256), { size: 32 }),
|
|
185
|
+
],
|
|
186
|
+
}));
|
|
187
|
+
const accountIsDebitNormal = new Map();
|
|
188
|
+
const accountNumbers = [
|
|
189
|
+
...new Set(metadataInput.shareClasses.flatMap((sc) => Object.entries(sc.defaultAccounts ?? {})
|
|
190
|
+
.filter(([k, v]) => {
|
|
191
|
+
if (!v)
|
|
192
|
+
return false;
|
|
193
|
+
if (['asset', 'expense'].includes(k)) {
|
|
194
|
+
if (accountIsDebitNormal.get(v) === false)
|
|
195
|
+
throw new Error(`Account "${v}" is set as both credit normal and debit normal.`);
|
|
196
|
+
accountIsDebitNormal.set(v, true);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
if (accountIsDebitNormal.get(v) === true)
|
|
200
|
+
throw new Error(`Account "${v}" is set as both credit normal and debit normal.`);
|
|
201
|
+
accountIsDebitNormal.set(v, false);
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
})
|
|
205
|
+
.map(([, v]) => v))),
|
|
206
|
+
];
|
|
207
|
+
const createAccountsData = accountNumbers.map((account) => encodeFunctionData({
|
|
208
|
+
abi: ABI.Hub,
|
|
209
|
+
functionName: 'createAccount',
|
|
210
|
+
args: [poolId.raw, account, accountIsDebitNormal.get(account)],
|
|
211
|
+
}));
|
|
212
|
+
yield* doTransaction('Create pool', publicClient, () => {
|
|
213
|
+
return walletClient.writeContract({
|
|
214
|
+
address: addresses.hub,
|
|
215
|
+
abi: ABI.Hub,
|
|
216
|
+
functionName: 'multicall',
|
|
217
|
+
args: [[createPoolData, setMetadataData, ...addScData, ...createAccountsData]],
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}, chainId);
|
|
221
|
+
}
|
|
222
|
+
id(chainId) {
|
|
223
|
+
return this._query(['centrifugeId', chainId], () => this._protocolAddresses(chainId).pipe(switchMap(({ messageDispatcher }) => {
|
|
224
|
+
return this.getClient(chainId).readContract({
|
|
225
|
+
address: messageDispatcher,
|
|
226
|
+
abi: ABI.MessageDispatcher,
|
|
227
|
+
functionName: 'localCentrifugeId',
|
|
228
|
+
});
|
|
229
|
+
})));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get the existing pools on the different chains.
|
|
233
|
+
*/
|
|
234
|
+
pools() {
|
|
235
|
+
return this._queryIndexer(`{
|
|
236
|
+
pools {
|
|
237
|
+
items {
|
|
238
|
+
id
|
|
239
|
+
blockchain {
|
|
240
|
+
id
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}`).pipe(map((data) => {
|
|
245
|
+
return data.pools.items.map((pool) => {
|
|
246
|
+
const poolId = new PoolId(pool.id);
|
|
247
|
+
return new Pool(this, poolId.toString(), Number(pool.blockchain.id));
|
|
248
|
+
});
|
|
249
|
+
}));
|
|
81
250
|
}
|
|
82
|
-
|
|
83
|
-
return this._query(null, () =>
|
|
251
|
+
pool(id) {
|
|
252
|
+
return this._query(null, () => this.pools().pipe(map((pools) => {
|
|
253
|
+
const pool = pools.find((pool) => pool.id.equals(id));
|
|
254
|
+
if (!pool)
|
|
255
|
+
throw new Error(`Pool with id ${id} not found`);
|
|
256
|
+
return pool;
|
|
257
|
+
})));
|
|
84
258
|
}
|
|
85
259
|
/**
|
|
86
260
|
* Get the metadata for an ERC20 token
|
|
@@ -89,18 +263,18 @@ export class Centrifuge {
|
|
|
89
263
|
*/
|
|
90
264
|
currency(address, chainId) {
|
|
91
265
|
const curAddress = address.toLowerCase();
|
|
92
|
-
|
|
93
|
-
return this._query(['currency', curAddress, cid], () => defer(async () => {
|
|
266
|
+
return this._query(['currency', curAddress, chainId], () => defer(async () => {
|
|
94
267
|
const contract = getContract({
|
|
95
268
|
address: curAddress,
|
|
96
269
|
abi: ABI.Currency,
|
|
97
|
-
client: this.getClient(
|
|
270
|
+
client: this.getClient(chainId),
|
|
98
271
|
});
|
|
99
272
|
const [decimals, name, symbol, supportsPermit] = await Promise.all([
|
|
100
273
|
contract.read.decimals(),
|
|
101
274
|
contract.read.name(),
|
|
102
275
|
contract.read.symbol(),
|
|
103
|
-
contract.read
|
|
276
|
+
contract.read
|
|
277
|
+
.PERMIT_TYPEHASH()
|
|
104
278
|
.then((hash) => hash === PERMIT_TYPEHASH)
|
|
105
279
|
.catch(() => false),
|
|
106
280
|
]);
|
|
@@ -109,11 +283,14 @@ export class Centrifuge {
|
|
|
109
283
|
decimals,
|
|
110
284
|
name,
|
|
111
285
|
symbol,
|
|
112
|
-
chainId
|
|
286
|
+
chainId,
|
|
113
287
|
supportsPermit,
|
|
114
288
|
};
|
|
115
289
|
}));
|
|
116
290
|
}
|
|
291
|
+
investor(address) {
|
|
292
|
+
return this._query(null, () => of(new Investor(this, address)));
|
|
293
|
+
}
|
|
117
294
|
/**
|
|
118
295
|
* Get the balance of an ERC20 token for a given owner.
|
|
119
296
|
* @param currency - The token address
|
|
@@ -122,16 +299,19 @@ export class Centrifuge {
|
|
|
122
299
|
*/
|
|
123
300
|
balance(currency, owner, chainId) {
|
|
124
301
|
const address = owner.toLowerCase();
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
302
|
+
return this._query(['balance', currency, owner, chainId], () => {
|
|
303
|
+
return this.currency(currency, chainId).pipe(switchMap((currencyMeta) => defer(async () => {
|
|
304
|
+
const val = await this.getClient(chainId).readContract({
|
|
305
|
+
address: currency,
|
|
306
|
+
abi: ABI.Currency,
|
|
307
|
+
functionName: 'balanceOf',
|
|
308
|
+
args: [address],
|
|
309
|
+
});
|
|
310
|
+
return {
|
|
311
|
+
balance: new Balance(val, currencyMeta.decimals),
|
|
312
|
+
currency: currencyMeta,
|
|
313
|
+
};
|
|
314
|
+
}).pipe(repeatOnEvents(this, {
|
|
135
315
|
address: currency,
|
|
136
316
|
abi: ABI.Currency,
|
|
137
317
|
eventName: 'Transfer',
|
|
@@ -140,18 +320,85 @@ export class Centrifuge {
|
|
|
140
320
|
return event.args.from?.toLowerCase() === address || event.args.to?.toLowerCase() === address;
|
|
141
321
|
});
|
|
142
322
|
},
|
|
143
|
-
},
|
|
323
|
+
}, chainId))));
|
|
144
324
|
});
|
|
145
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Get the assets that exist on a given spoke chain that have been registered on a given hub chain.
|
|
328
|
+
* @param spokeChainId - The chain ID where the assets exist
|
|
329
|
+
* @param hubChainId - The chain ID where the assets should optionally be registered
|
|
330
|
+
*/
|
|
331
|
+
assets(spokeChainId, hubChainId = spokeChainId) {
|
|
332
|
+
return this._query(null, () => combineLatest([this.id(spokeChainId), this.id(hubChainId)]).pipe(switchMap(([spokeCentId, hubCentId]) => this._queryIndexer(`query ($hubCentId: String!) {
|
|
333
|
+
assetRegistrations(where: { centrifugeId: $hubCentId, decimals_gt: 0 }) {
|
|
334
|
+
items {
|
|
335
|
+
id
|
|
336
|
+
name
|
|
337
|
+
symbol
|
|
338
|
+
decimals
|
|
339
|
+
asset {
|
|
340
|
+
centrifugeId
|
|
341
|
+
address
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}`, { hubCentId: String(hubCentId) }, (data) => {
|
|
346
|
+
return data.assetRegistrations.items
|
|
347
|
+
.filter((assetReg) => Number(assetReg.asset.centrifugeId) === spokeCentId)
|
|
348
|
+
.map((assetReg) => {
|
|
349
|
+
return {
|
|
350
|
+
registeredOnCentrifugeId: hubCentId,
|
|
351
|
+
id: new AssetId(assetReg.id),
|
|
352
|
+
address: assetReg.asset.address,
|
|
353
|
+
name: assetReg.name,
|
|
354
|
+
symbol: assetReg.symbol,
|
|
355
|
+
};
|
|
356
|
+
});
|
|
357
|
+
}))));
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Register an asset
|
|
361
|
+
* @param originChainId - The chain ID where the asset exists
|
|
362
|
+
* @param registerOnChainId - The chain ID where the asset should be registered
|
|
363
|
+
* @param assetAddress - The address of the asset to register
|
|
364
|
+
* @param tokenId - Optional token ID for ERC6909 assets
|
|
365
|
+
*/
|
|
366
|
+
registerAsset(originChainId, registerOnChainId, assetAddress, tokenId = 0) {
|
|
367
|
+
const self = this;
|
|
368
|
+
return this._transactSequence(async function* ({ walletClient, publicClient }) {
|
|
369
|
+
const [addresses, id, estimate] = await Promise.all([
|
|
370
|
+
self._protocolAddresses(originChainId),
|
|
371
|
+
self.id(registerOnChainId),
|
|
372
|
+
self._estimate(originChainId, { chainId: registerOnChainId }),
|
|
373
|
+
]);
|
|
374
|
+
yield* doTransaction('Register asset', publicClient, () => walletClient.writeContract({
|
|
375
|
+
address: addresses.spoke,
|
|
376
|
+
abi: ABI.Spoke,
|
|
377
|
+
functionName: 'registerAsset',
|
|
378
|
+
args: [id, assetAddress, BigInt(tokenId)],
|
|
379
|
+
value: estimate,
|
|
380
|
+
}));
|
|
381
|
+
}, originChainId);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Get the decimals of asset
|
|
385
|
+
*/
|
|
386
|
+
assetDecimals(assetId, chainId) {
|
|
387
|
+
return this._query(['assetDecimals', assetId.toString()], () => this._protocolAddresses(chainId).pipe(switchMap(({ hubRegistry }) => this.getClient(chainId).readContract({
|
|
388
|
+
address: hubRegistry,
|
|
389
|
+
abi: parseAbi(['function decimals(uint128) view returns (uint8)']),
|
|
390
|
+
functionName: 'decimals',
|
|
391
|
+
args: [assetId.raw],
|
|
392
|
+
}))));
|
|
393
|
+
}
|
|
146
394
|
/**
|
|
147
395
|
* Returns an observable of all events on a given chain.
|
|
148
396
|
* @internal
|
|
149
397
|
*/
|
|
150
398
|
_events(chainId) {
|
|
151
|
-
|
|
152
|
-
return this._query(['events', cid], () => using(() => {
|
|
399
|
+
return this._query(['events', chainId], () => using(() => {
|
|
153
400
|
const subject = new Subject();
|
|
154
|
-
const unwatch = this.getClient(
|
|
401
|
+
const unwatch = this.getClient(chainId).watchEvent({
|
|
155
402
|
onLogs: (logs) => subject.next(logs),
|
|
156
403
|
});
|
|
157
404
|
return {
|
|
@@ -200,29 +447,25 @@ export class Centrifuge {
|
|
|
200
447
|
}
|
|
201
448
|
_queryIndexer(query, variables, postProcess) {
|
|
202
449
|
return this._query([query, variables], () => this._getIndexerObservable(query, variables).pipe(map(postProcess ?? identity)), {
|
|
203
|
-
valueCacheTime:
|
|
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
|
-
},
|
|
450
|
+
valueCacheTime: 120_000,
|
|
219
451
|
});
|
|
220
452
|
}
|
|
221
453
|
/**
|
|
222
454
|
* @internal
|
|
223
455
|
*/
|
|
224
456
|
_queryIPFS(hash) {
|
|
225
|
-
return this._query([hash], () =>
|
|
457
|
+
return this._query([hash], () => defer(async () => {
|
|
458
|
+
const url = getUrlFromHash(hash, this.#config.ipfsUrl);
|
|
459
|
+
if (!url) {
|
|
460
|
+
throw new Error(`Invalid IPFS hash: ${hash}`);
|
|
461
|
+
}
|
|
462
|
+
const res = await fetch(url);
|
|
463
|
+
if (!res.ok) {
|
|
464
|
+
throw new Error(`Error fetching IPFS hash ${hash}: ${res.statusText}`);
|
|
465
|
+
}
|
|
466
|
+
const data = (await res.json());
|
|
467
|
+
return data;
|
|
468
|
+
}));
|
|
226
469
|
}
|
|
227
470
|
#memoized = new Map();
|
|
228
471
|
#memoizeWith(keys, callback) {
|
|
@@ -289,10 +532,9 @@ export class Centrifuge {
|
|
|
289
532
|
* const chainId = 1
|
|
290
533
|
*
|
|
291
534
|
* // Wrap an observable that only emits one value and then completes
|
|
292
|
-
* //
|
|
293
535
|
* const query = this._query(['balance', address, tUSD, chainId], () => {
|
|
294
536
|
* return defer(() => fetchBalance(address, tUSD, chainId))
|
|
295
|
-
* }, { valueCacheTime:
|
|
537
|
+
* }, { valueCacheTime: 60_000 })
|
|
296
538
|
*
|
|
297
539
|
* // Logs the current balance and updated balances whenever a new
|
|
298
540
|
* const obs1 = query.subscribe(balance => console.log(balance))
|
|
@@ -316,14 +558,16 @@ export class Centrifuge {
|
|
|
316
558
|
* @internal
|
|
317
559
|
*/
|
|
318
560
|
_query(keys, observableCallback, options) {
|
|
561
|
+
const cache = options?.cache !== false && this.#config.cache !== false;
|
|
562
|
+
const obsCacheTime = options?.observableCacheTime ?? this.#config.pollingInterval ?? 4000;
|
|
319
563
|
function get() {
|
|
320
564
|
const sharedSubject = new Subject();
|
|
321
565
|
function createShared() {
|
|
322
566
|
const $shared = observableCallback().pipe(keys
|
|
323
567
|
? shareReplayWithDelayedReset({
|
|
324
|
-
bufferSize:
|
|
325
|
-
resetDelay:
|
|
326
|
-
windowTime:
|
|
568
|
+
bufferSize: cache ? 1 : 0,
|
|
569
|
+
resetDelay: cache ? obsCacheTime : 0,
|
|
570
|
+
windowTime: options?.valueCacheTime ?? Infinity,
|
|
327
571
|
})
|
|
328
572
|
: map((val) => val));
|
|
329
573
|
sharedSubject.next($shared);
|
|
@@ -413,18 +657,18 @@ export class Centrifuge {
|
|
|
413
657
|
* // { type: 'SigningTransaction', title: 'Invest' }
|
|
414
658
|
* // { type: 'TransactionPending', title: 'Invest', hash: '0x123...abc' }
|
|
415
659
|
* // { type: 'TransactionConfirmed', title: 'Invest', hash: '0x123...abc', receipt: { ... } }
|
|
660
|
+
* ```
|
|
416
661
|
*
|
|
417
662
|
* @internal
|
|
418
663
|
*/
|
|
419
664
|
_transactSequence(transactionCallback, chainId) {
|
|
420
|
-
const targetChainId = chainId ?? this.config.defaultChain;
|
|
421
665
|
const self = this;
|
|
422
666
|
async function* transact() {
|
|
423
667
|
const { signer } = self;
|
|
424
668
|
if (!signer)
|
|
425
669
|
throw new Error('Signer not set');
|
|
426
|
-
const publicClient = self.getClient(
|
|
427
|
-
const chain = self.getChainConfig(
|
|
670
|
+
const publicClient = self.getClient(chainId);
|
|
671
|
+
const chain = self.getChainConfig(chainId);
|
|
428
672
|
const bareWalletClient = isLocalAccount(signer)
|
|
429
673
|
? createWalletClient({ account: signer, chain, transport: http(self.#config.rpcUrls?.[chain.id]) })
|
|
430
674
|
: createWalletClient({ transport: custom(signer) });
|
|
@@ -432,9 +676,9 @@ export class Centrifuge {
|
|
|
432
676
|
if (!address)
|
|
433
677
|
throw new Error('No account selected');
|
|
434
678
|
const selectedChain = await bareWalletClient.getChainId();
|
|
435
|
-
if (selectedChain !==
|
|
436
|
-
yield { type: 'SwitchingChain', chainId
|
|
437
|
-
await bareWalletClient.switchChain({ id:
|
|
679
|
+
if (selectedChain !== chainId) {
|
|
680
|
+
yield { type: 'SwitchingChain', chainId };
|
|
681
|
+
await bareWalletClient.switchChain({ id: chainId });
|
|
438
682
|
}
|
|
439
683
|
// Re-create the wallet client with the correct chain and account
|
|
440
684
|
// Saves having to pass `account` and `chain` to every `writeContract` call
|
|
@@ -444,7 +688,7 @@ export class Centrifuge {
|
|
|
444
688
|
const transaction = transactionCallback({
|
|
445
689
|
signingAddress: address,
|
|
446
690
|
chain,
|
|
447
|
-
chainId
|
|
691
|
+
chainId,
|
|
448
692
|
publicClient,
|
|
449
693
|
walletClient,
|
|
450
694
|
signer,
|
|
@@ -462,5 +706,232 @@ export class Centrifuge {
|
|
|
462
706
|
const $tx = defer(transact).pipe(mergeMap((d) => (isObservable(d) ? d : of(d))));
|
|
463
707
|
return makeThenable($tx, true);
|
|
464
708
|
}
|
|
709
|
+
_protocolAddresses(chainId) {
|
|
710
|
+
return this._query(['protocolAddresses', chainId], () => {
|
|
711
|
+
const network = chainIdToNetwork[chainId];
|
|
712
|
+
const chainCurrencies = currencies[chainId];
|
|
713
|
+
if (!network || !chainCurrencies) {
|
|
714
|
+
throw new Error(`No protocol config mapping for chain id ${chainId}`);
|
|
715
|
+
}
|
|
716
|
+
const baseUrl = 'https://raw.githubusercontent.com/centrifuge/protocol-v3/refs/heads';
|
|
717
|
+
const branch = 'main';
|
|
718
|
+
const folder = 'env';
|
|
719
|
+
const url = `${baseUrl}/${branch}/${folder}/${network}.json`;
|
|
720
|
+
return fromFetch(url).pipe(switchMap((response) => {
|
|
721
|
+
if (response.ok) {
|
|
722
|
+
return response.json().then(() => {
|
|
723
|
+
// TODO: Replace temp addresses
|
|
724
|
+
return TEMP_DEPLOYMENTS.find((d) => d.network.chainId === chainId);
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
throw new Error(`Error ${response.status}`);
|
|
728
|
+
}), map((data) => ({
|
|
729
|
+
...data.contracts,
|
|
730
|
+
currencies: chainCurrencies,
|
|
731
|
+
})));
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
_getQuote(valuationAddress, baseAmount, baseAssetId, quoteAssetId, chainId) {
|
|
735
|
+
return this._query(['getQuote', baseAmount, baseAssetId.toString(), quoteAssetId.toString()], () => this._protocolAddresses(chainId).pipe(switchMap(({ hubRegistry }) => defer(async () => {
|
|
736
|
+
const [quote, quoteDecimals] = await Promise.all([
|
|
737
|
+
this.getClient(chainId).readContract({
|
|
738
|
+
address: valuationAddress,
|
|
739
|
+
abi: ABI.Valuation,
|
|
740
|
+
functionName: 'getQuote',
|
|
741
|
+
args: [baseAmount.toBigInt(), baseAssetId.raw, quoteAssetId.raw],
|
|
742
|
+
}),
|
|
743
|
+
this.getClient(chainId).readContract({
|
|
744
|
+
address: hubRegistry,
|
|
745
|
+
// Use inline ABI because of function overload
|
|
746
|
+
abi: parseAbi(['function decimals(uint256) view returns (uint8)']),
|
|
747
|
+
functionName: 'decimals',
|
|
748
|
+
args: [quoteAssetId.raw],
|
|
749
|
+
}),
|
|
750
|
+
]);
|
|
751
|
+
return new Balance(quote, quoteDecimals);
|
|
752
|
+
}))), { valueCacheTime: 120_000 });
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Estimates the gas cost needed to bridge the message from one chain to another,
|
|
756
|
+
* that results from a transaction
|
|
757
|
+
* @internal
|
|
758
|
+
*/
|
|
759
|
+
_estimate(fromChain, to) {
|
|
760
|
+
return this._query(['estimate', fromChain, to], () => combineLatest([this._protocolAddresses(fromChain), 'chainId' in to ? this.id(to.chainId) : of(to.centId)]).pipe(switchMap(([{ multiAdapter }, toCentId]) => {
|
|
761
|
+
const bytes = toHex(new Uint8Array([0x12]));
|
|
762
|
+
return this.getClient(fromChain).readContract({
|
|
763
|
+
address: multiAdapter,
|
|
764
|
+
abi: ABI.MultiAdapter,
|
|
765
|
+
functionName: 'estimate',
|
|
766
|
+
args: [toCentId, bytes, 15000000n],
|
|
767
|
+
});
|
|
768
|
+
})));
|
|
769
|
+
}
|
|
465
770
|
}
|
|
771
|
+
export const TEMP_DEPLOYMENTS = [
|
|
772
|
+
{
|
|
773
|
+
network: {
|
|
774
|
+
chainId: 11155111,
|
|
775
|
+
environment: 'testnet',
|
|
776
|
+
centrifugeId: 1,
|
|
777
|
+
network: 'ethereum',
|
|
778
|
+
etherscanUrl: 'https://api-sepolia.etherscan.io/api',
|
|
779
|
+
connectsTo: ['arbitrum-sepolia', 'base-sepolia'],
|
|
780
|
+
},
|
|
781
|
+
adapters: {
|
|
782
|
+
wormhole: {
|
|
783
|
+
wormholeId: '10002',
|
|
784
|
+
relayer: '0x7B1bD7a6b4E61c2a123AC6BC2cbfC614437D0470',
|
|
785
|
+
deploy: true,
|
|
786
|
+
},
|
|
787
|
+
axelar: {
|
|
788
|
+
axelarId: 'ethereum-sepolia',
|
|
789
|
+
gateway: '0xe432150cce91c13a887f7D836923d5597adD8E31',
|
|
790
|
+
gasService: '0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6',
|
|
791
|
+
deploy: true,
|
|
792
|
+
},
|
|
793
|
+
},
|
|
794
|
+
contracts: {
|
|
795
|
+
root: '0x6453C75B87852Eec5bDB5257C2fcb6c233F9fd0E',
|
|
796
|
+
guardian: '0x79419e5a6bDd4b709C3c02b46B20483675099619',
|
|
797
|
+
gasService: '0x588c02283dd3Ba23C0389480533Cb331C3D72E28',
|
|
798
|
+
gateway: '0x353a317bB82C69C4f7575879370D63CB372d2B83',
|
|
799
|
+
multiAdapter: '0x587Ed28F7d5d71A6254848B0870C3b21AABb0dA7',
|
|
800
|
+
messageProcessor: '0xA659572D933864965351ca84188Df993321aDD98',
|
|
801
|
+
messageDispatcher: '0x889Df3907f37ba3639432280196fC08CB3aaAD01',
|
|
802
|
+
hubRegistry: '0xEaAaedd16eD9435E3796340228CEda296F630ef3',
|
|
803
|
+
accounting: '0x99ec67Edce4058381806029BaCe7005B37F9CfB0',
|
|
804
|
+
holdings: '0x7b2D7f8f961cdc3718E455899A3779Db1b60EB7C',
|
|
805
|
+
shareClassManager: '0x7a943883873B46639c3F8FE0B81ED010CF6cEA4b',
|
|
806
|
+
hub: '0xC4f701841c8d4FC948EDF1658cE800C2790350eb',
|
|
807
|
+
identityValuation: '0x6Bcb240d3e1f1C4321ECAFFDacB45691DC03bE5D',
|
|
808
|
+
poolEscrowFactory: '0xE0bf3dAFe2b546aE18608dE988AaE1439868ce4d',
|
|
809
|
+
routerEscrow: '0xfCa8e874b908B97b034f69A57720B7Ac317eFD4E',
|
|
810
|
+
globalEscrow: '0xc9C0A8fa02F10D790E47CF7ED17A2C4A8852b15D',
|
|
811
|
+
freezeOnlyHook: '0x6C37c8536DA3Bd73D7AF4d6dE2371F6c5Bf282a4',
|
|
812
|
+
redemptionRestrictionsHook: '0xa72ecE5FcB7D559dCe839293D89992Bd20997AeB',
|
|
813
|
+
fullRestrictionsHook: '0x37FE09A48bBDae5Dbc479DE0D85F3c3D8279FbF9',
|
|
814
|
+
tokenFactory: '0xa1cbc70C7b45870b403BfF70861f70CC52EdDEAd',
|
|
815
|
+
asyncRequestManager: '0xefA2aa579b83BC2bc70DE4E84e916B7942A739f1',
|
|
816
|
+
syncManager: '0x24fB7024B7289322cFd4A03c9dd66Eebc10e4dA7',
|
|
817
|
+
asyncVaultFactory: '0x1C5F039CBe2d8bc63d9fF9d1bFdE0561a3efA5b5',
|
|
818
|
+
syncDepositVaultFactory: '0x0394C7f38c0b0e1cC9d835dD166eCB49A53f31e8',
|
|
819
|
+
spoke: '0x2e5613B4D8275AbdC82249873375EBA353431635',
|
|
820
|
+
vaultRouter: '0x9ce2423c8d6d0fEbCD596Ec94e5406782345729c',
|
|
821
|
+
balanceSheet: '0xD9c60d4318Abe64Be4d137CAc08f24B51388A1E3',
|
|
822
|
+
wormholeAdapter: '0xA77DF260E79fC0E9E2baaf5Fa7c4E8234210cCaD',
|
|
823
|
+
axelarAdapter: '0x3a10D135D00747e36eBb61Cb1554aF29f59675b5',
|
|
824
|
+
},
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
network: {
|
|
828
|
+
chainId: 421614,
|
|
829
|
+
environment: 'testnet',
|
|
830
|
+
centrifugeId: 3,
|
|
831
|
+
network: 'arbitrum',
|
|
832
|
+
etherscanUrl: 'https://api-sepolia.arbiscan.io/api',
|
|
833
|
+
catapultaNetwork: 'arbitrumSepolia',
|
|
834
|
+
connectsTo: ['sepolia', 'base-sepolia'],
|
|
835
|
+
},
|
|
836
|
+
adapters: {
|
|
837
|
+
wormhole: {
|
|
838
|
+
wormholeId: '10003',
|
|
839
|
+
relayer: '0x7B1bD7a6b4E61c2a123AC6BC2cbfC614437D0470',
|
|
840
|
+
deploy: false,
|
|
841
|
+
},
|
|
842
|
+
axelar: {
|
|
843
|
+
axelarId: 'arbitrum-sepolia',
|
|
844
|
+
gateway: '0xe1cE95479C84e9809269227C7F8524aE051Ae77a',
|
|
845
|
+
gasService: '0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6',
|
|
846
|
+
deploy: true,
|
|
847
|
+
},
|
|
848
|
+
},
|
|
849
|
+
contracts: {
|
|
850
|
+
root: '0xD494AE8313Ef5368A4f43BAa963c039984de03B9',
|
|
851
|
+
guardian: '0x424315e2d5E5F85c6d944D9035Fcefa742E89F49',
|
|
852
|
+
gasService: '0x02C1A1ff76696FBcaC93450b79F8eEd544A36908',
|
|
853
|
+
gateway: '0x27dD1C01C57063487d022dB2A094eC7E55Eeb7bA',
|
|
854
|
+
multiAdapter: '0x4331A86E0E392b0e76752cEc54c2b67eDDCB247F',
|
|
855
|
+
messageProcessor: '0xb241107eA5a60aa6C1350ce0e531EFE96f60fBc3',
|
|
856
|
+
messageDispatcher: '0x30D32a13d2f5c0877e46bBC90673A5BEA97c4A9d',
|
|
857
|
+
hubRegistry: '0x92e20B218Ecfa62DEC6BD7032519f42903b0D051',
|
|
858
|
+
accounting: '0x7d929848Ca0D31a1bB655AEAc0395E6bf7eE57F4',
|
|
859
|
+
holdings: '0xCeF47646fc6bD862e74328366159BdE7D0BaCa8f',
|
|
860
|
+
shareClassManager: '0x8d597136BEC4B3a6399F14C521E06fbaF65621fB',
|
|
861
|
+
hub: '0x158Aba13c4FaA434F2e98184598873DC8bE062c4',
|
|
862
|
+
identityValuation: '0x6BF52A347248DA28777CB6cb588ABAc62Ae61e49',
|
|
863
|
+
poolEscrowFactory: '0x8aA080b9a16b4B08043CDe0dCc42801113dD3203',
|
|
864
|
+
routerEscrow: '0x47dC1B0fb5303B3498C1e1e5950632bD4a959029',
|
|
865
|
+
globalEscrow: '0xc7bA990F4B6B7a6B66249EA2046e16EAECd248d2',
|
|
866
|
+
freezeOnlyHook: '0xe690ba6334cA1F5552354B900E9D02e6Af8f335C',
|
|
867
|
+
redemptionRestrictionsHook: '0x2c33B751159f08dd6cF471DDCEec82828Cd95dD4',
|
|
868
|
+
fullRestrictionsHook: '0x1550b00E59cfB128D4076EA8CdE061fcE2806466',
|
|
869
|
+
tokenFactory: '0xdD0c9D22536DE1b2A9bCfa19EbD167CcA93659D8',
|
|
870
|
+
asyncRequestManager: '0xa9133c5c04c4211D84976b521a63532A41C31Af6',
|
|
871
|
+
syncManager: '0xB06889CE8A4f7840eeb8EE79B1f584369fa2Aa7C',
|
|
872
|
+
asyncVaultFactory: '0x0fC93dc1e66b329E1B50e5251E3Eef707ce15728',
|
|
873
|
+
syncDepositVaultFactory: '0x1a02aa3258fef51ddD34c60f365205af9b01443B',
|
|
874
|
+
spoke: '0xBDAB5Cf95e3f3D388aF1417CFf34470864454431',
|
|
875
|
+
vaultRouter: '0x6c0036c95d27442CBB78c8E8C284B93A7687Cf03',
|
|
876
|
+
balanceSheet: '0xf0b119b61C30f9EfBF1aB976327a33c601b05917',
|
|
877
|
+
axelarAdapter: '0x63320C1716F3B598DE9053F0343249a7E43634fe',
|
|
878
|
+
wormholeAdapter: '0x0',
|
|
879
|
+
},
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
network: {
|
|
883
|
+
chainId: 84532,
|
|
884
|
+
environment: 'testnet',
|
|
885
|
+
centrifugeId: 2,
|
|
886
|
+
network: 'base',
|
|
887
|
+
catapultaNetwork: 'baseSepolia',
|
|
888
|
+
etherscanUrl: 'https://api-sepolia.basescan.org/api',
|
|
889
|
+
connectsTo: ['sepolia'],
|
|
890
|
+
},
|
|
891
|
+
adapters: {
|
|
892
|
+
wormhole: {
|
|
893
|
+
wormholeId: '10004',
|
|
894
|
+
relayer: '0x93BAD53DDfB6132b0aC8E37f6029163E63372cEE',
|
|
895
|
+
deploy: true,
|
|
896
|
+
},
|
|
897
|
+
axelar: {
|
|
898
|
+
axelarId: 'base-sepolia',
|
|
899
|
+
gateway: '0xe432150cce91c13a887f7D836923d5597adD8E31',
|
|
900
|
+
gasService: '0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6',
|
|
901
|
+
deploy: true,
|
|
902
|
+
},
|
|
903
|
+
},
|
|
904
|
+
contracts: {
|
|
905
|
+
root: '0x812D99c0bC8B7a74502871D73c401eb36039a181',
|
|
906
|
+
guardian: '0xF58d63966BabF0b0EdbD38917418756c4fa27Cca',
|
|
907
|
+
gasService: '0xBD6f23480DaA1ee28B1acfE51520Bdcf05eA880C',
|
|
908
|
+
gateway: '0x4d8C9dDB6A1B3C18E381c425d6F12438D472d900',
|
|
909
|
+
multiAdapter: '0xDd51383595f18577a5760C2726aFB3264d9C078F',
|
|
910
|
+
messageProcessor: '0x40828083cB78A165690FC81D5D13F3f7C02F1E72',
|
|
911
|
+
messageDispatcher: '0x54a74682da4A535dee99Ea936a457bF2659cBCBA',
|
|
912
|
+
hubRegistry: '0x5411368415C09A46624DA0c21af681b5A46E772a',
|
|
913
|
+
accounting: '0xdC62A9380bab5BB90954086Dc7Bb02ac95385f58',
|
|
914
|
+
holdings: '0xAEB0B9253fbB32ED05D442A3185eAB36DFCb65dF',
|
|
915
|
+
shareClassManager: '0xAFf6eB55ea716D9d2AeAA2f92dfa2fB18B6E8E53',
|
|
916
|
+
hub: '0x901eb3C1bb122C3E44C87597b8A73385e2b0986a',
|
|
917
|
+
identityValuation: '0x82a6BeC96F48Bf84a6948b1cb8b3Dd56990FC86A',
|
|
918
|
+
poolEscrowFactory: '0xea0213528de2851a5E9eEB0af41bEd8a1dD5A6ae',
|
|
919
|
+
routerEscrow: '0x1b376E6e1176dCAf5F1a95b7Fc3C81777a18dFA4',
|
|
920
|
+
globalEscrow: '0xAE3cf280db45af3Daf3db44f87Cd86F0f9cE8418',
|
|
921
|
+
freezeOnlyHook: '0xcF429dB019D0E461220f2375aB0a17E738804FA6',
|
|
922
|
+
redemptionRestrictionsHook: '0xeB38f1568881F5e9aE24Dc6c4cC72aa914A7CFb7',
|
|
923
|
+
fullRestrictionsHook: '0xF496fB53FF4EEdf402caD77a7C7E3DDDeBb8868e',
|
|
924
|
+
tokenFactory: '0x2473c4e384B587F8A246166A3f62dD61C7932b21',
|
|
925
|
+
asyncRequestManager: '0x4dc994F05aa257f34683AC53F5522D2aC80dBAce',
|
|
926
|
+
syncManager: '0xDf75Af2306f09dfECa802B7640580DE5D5e7C845',
|
|
927
|
+
asyncVaultFactory: '0x107cFf9bD6888e6D4bc7E3e66E56AE5950D73389',
|
|
928
|
+
syncDepositVaultFactory: '0x856c7173b6B7E72FaAb744049C9D9755F1c6a910',
|
|
929
|
+
spoke: '0xE86ba28E67317021ED1668Ac74f6aEcb58204D4a',
|
|
930
|
+
vaultRouter: '0xeCD41929C8bF8F81162fCDA3b3F7b355F290C8B2',
|
|
931
|
+
balanceSheet: '0xd2E92E0F3aEe2a267b62F894F652Bd0CafcFD3D8',
|
|
932
|
+
wormholeAdapter: '0x20476c2Ce241cB411A126E5cb0AA4f5881E1880a',
|
|
933
|
+
axelarAdapter: '0x7D1418c9074E2C55284Bc98525a4E8A5375DA5df',
|
|
934
|
+
},
|
|
935
|
+
},
|
|
936
|
+
];
|
|
466
937
|
//# sourceMappingURL=Centrifuge.js.map
|