UNPKG

@ixily/activ

Version:

Alpha Capture Trade Idea Verification. Blockchain ownership proven trade ideas and strategies.

244 lines (241 loc) 10.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ViewsSourceGateModule = void 0; const __1 = require("../.."); const views_source_mess_module_1 = require("./views-source-mess.module"); const views_source_server_module_1 = require("./views-source-server.module"); const config_module_1 = require("./config.module"); const state = { source: 'server', }; config_module_1.ConfigModule.getConfigUpdatedStream().subscribe((config) => { if (config !== undefined) { if (config.dataSource !== undefined) { state.source = config.dataSource.publicCache.source; } } }); const listContracts = async (network = 'polygon') => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listContracts(network); } else { return views_source_mess_module_1.ViewsSourceMessModule.listContracts(); } }; const getCreator = async (contract, creatorWallet) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.getCreator(contract, creatorWallet); } else { return views_source_mess_module_1.ViewsSourceMessModule.getCreator(contract, creatorWallet); } }; const getIdeaByUniqueContractAndId = async (contract, ideaNftId) => { const keySplit = (0, __1.uniqueKeySplit)(contract); keySplit.push('' + ideaNftId); const uniqueIdeaId = (0, __1.uniqueKeyJoin)(keySplit); return getIdeaByUniqueId(uniqueIdeaId); }; const getIdeaByUniqueId = async (uniqueIdeaId) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.getIdeaByUniqueId(uniqueIdeaId); } else { return views_source_mess_module_1.ViewsSourceMessModule.getIdeaByUniqueId(uniqueIdeaId); } }; const getStrategy = async (uniqueStrategyReference) => { const { creatorAddress, strategyKey } = (0, __1.decomposeUniqueStrategyReference)(uniqueStrategyReference); const data = await __1.ProvableIdeasModule.chain.getValidatedStrategyChainWithCache(strategyKey, creatorAddress, undefined, false); return data.cache.cachedStrategy.strategy; }; const getStrategyWithCreator = async (uniqueStrategyReference) => { const { creatorAddress, strategyKey } = (0, __1.decomposeUniqueStrategyReference)(uniqueStrategyReference); // console.log('creatorAddress', creatorAddress) // console.log('strategyKey', strategyKey) const data = await __1.ProvableIdeasModule.chain.getValidatedStrategyChainWithCache(strategyKey, creatorAddress, undefined, false); if (data.cache?.cachedStrategy === undefined) { throw new Error('Strategy does not exists'); } const strategy = data.cache.cachedStrategy.strategy; const creator = __1.CONTRACT_TOOLS.queryChain.getCreatorLatestData(data.cache.cachedStrategy); return { strategy, creator, }; }; const listCreatorStrategies = async (contract, creatorWallet, page = 1, limit = 5) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listCreatorStrategies(contract, creatorWallet, page, limit); } else { return views_source_mess_module_1.ViewsSourceMessModule.listCreatorStrategies(contract, creatorWallet, page, limit); } }; const getPublicStrategyWithCreator = async (strategyUniqueKey) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.getPublicStrategyWithCreator(strategyUniqueKey); } else { return views_source_mess_module_1.ViewsSourceMessModule.getPublicStrategyWithCreator(strategyUniqueKey); } }; const listStrategiesWithAccessibleIdeasBy = async (contract, accessorWallet, page = 1, limit = 5) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listStrategiesWithAccessibleIdeasBy(contract, accessorWallet, page, limit); } else { return views_source_mess_module_1.ViewsSourceMessModule.listStrategiesWithAccessibleIdeasBy(contract, accessorWallet, page, limit); } }; const listStrategiesSubscribedToBy = async (contract, subscriberWallet, page = 1, limit = 5) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listStrategiesSubscribedToBy(contract, subscriberWallet, page, limit); } else { return views_source_mess_module_1.ViewsSourceMessModule.listStrategiesSubscribedToBy(contract, subscriberWallet, page, limit); } }; const listStrategiesPublic = async (contract, page = 1, limit = 5, network) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listStrategiesPublic(contract, page, limit, network); } else { return views_source_mess_module_1.ViewsSourceMessModule.listStrategiesPublic(contract, page, limit); } }; const listIdeasUniqueIndexesByLatest = async (contract, page = 1, limit = 5) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listIdeasUniqueIndexesByLatest(contract, page, limit); } else { return views_source_mess_module_1.ViewsSourceMessModule.listIdeasUniqueIndexesByLatest(contract, page, limit); } }; const listLatestIdeas = async (contract, page = 1, limit = 5) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listLatestIdeas(contract, page, limit); } else { return views_source_mess_module_1.ViewsSourceMessModule.listLatestIdeas(contract, page, limit); } }; const listLatestPublicIdeas = async (contract, page = 1, limit = 5, network = 'polygon') => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listLatestPublicIdeas(contract, page, limit, network); } else { return views_source_mess_module_1.ViewsSourceMessModule.listLatestPublicIdeas(contract, page, limit); } }; const listCreatorIdeas = async (contract, creatorWallet, page = 1, limit = 5, filterType = 'bypass', filterIncludeEncrypted = true, bypassPaginationAndGetAll = false) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listCreatorIdeas(contract, creatorWallet, page, limit, filterType, filterIncludeEncrypted, bypassPaginationAndGetAll); } else { return views_source_mess_module_1.ViewsSourceMessModule.listCreatorIdeas(contract, creatorWallet, page, limit, filterType, filterIncludeEncrypted, bypassPaginationAndGetAll); } }; const listOwnedIdeas = async (contract, ownerWallet, page = 1, limit = 5, filterType = 'bypass', filterIncludeEncrypted = false, bypassPaginationAndGetAll = false) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listOwnedIdeas(contract, ownerWallet, page, limit, filterType, filterIncludeEncrypted, bypassPaginationAndGetAll); } else { return views_source_mess_module_1.ViewsSourceMessModule.listOwnedIdeas(contract, ownerWallet, page, limit, filterType, filterIncludeEncrypted, bypassPaginationAndGetAll); } }; const listStrategyIdeas = async (strategyUniqueKey, page = 1, limit = 5, filterType = 'bypass', filterIncludeEncrypted = true, bypassPaginationAndGetAll = false) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listStrategyIdeas(strategyUniqueKey, page, limit, filterType, filterIncludeEncrypted, bypassPaginationAndGetAll); } else { return views_source_mess_module_1.ViewsSourceMessModule.listStrategyIdeas(strategyUniqueKey, page, limit, filterType, filterIncludeEncrypted, bypassPaginationAndGetAll); } }; const getStrategyPortfolio = async (strategyUniqueKey) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.getStrategyPortfolio(strategyUniqueKey); } else { return views_source_mess_module_1.ViewsSourceMessModule.getStrategyPortfolio(strategyUniqueKey); } }; const listStrategyRebalances = async (strategyUniqueKey, page = 1, limit = 5) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listStrategyRebalances(strategyUniqueKey, page, limit); } else { return views_source_mess_module_1.ViewsSourceMessModule.listStrategyRebalances(strategyUniqueKey, page, limit); } }; const getStrategyRebalance = async (strategyUniqueKey, rebalanceId) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.getStrategyRebalance(strategyUniqueKey, rebalanceId); } else { return views_source_mess_module_1.ViewsSourceMessModule.getStrategyRebalance(strategyUniqueKey, rebalanceId); } }; const listStrategyRebalancesInPeriod = async (strategyUniqueKey, start, end, page = 1, limit = 5) => { if (state.source === 'server') { return views_source_server_module_1.ViewsSourceServerModule.listStrategyRebalancesInPeriod(strategyUniqueKey, start, end, page, limit); } else { return views_source_mess_module_1.ViewsSourceMessModule.listStrategyRebalancesInPeriod(strategyUniqueKey, start, end, page, limit); } }; /* const listIdeaNftsByStrategy = async ( uniqueStrategyReference: string, ): Promise<v4.MyIdeaKeys[]> => { return requestor<v4.MyIdeaKeys[]>( 'GET', `/v4/strategies/${uniqueStrategyReference}/nfts`, ) } const listIdeaStagesIndexes = async ( uniqueStrategyReference: string, ideaKey: number, page: number = 1, limit: number = 5, ): Promise<number[]> => requestor<number[]>( 'GET', `/v4/strategies/${uniqueStrategyReference}/ideas/${ideaKey}/stages?page=${page}&limit=${limit}`, ) const getIdeaByNftId = async ( contract: string, nftId: string, ): Promise<v4.ITradeIdea> => requestor<v4.ITradeIdea>( 'GET', `/v4/contracts/${contract}/ideaStagesByNft/${nftId}`, ) */ exports.ViewsSourceGateModule = { listContracts, getCreator, listCreatorStrategies, listStrategiesWithAccessibleIdeasBy, listStrategiesSubscribedToBy, listStrategiesPublic, listIdeasUniqueIndexesByLatest, listLatestIdeas, listLatestPublicIdeas, listCreatorIdeas, listOwnedIdeas, getStrategy, getStrategyWithCreator, // listIdeaStagesIndexes, // listIdeasIndexes, getIdeaByUniqueContractAndId, getIdeaByUniqueId, getPublicStrategyWithCreator, listStrategyIdeas, getStrategyPortfolio, listStrategyRebalances, getStrategyRebalance, listStrategyRebalancesInPeriod, }; //# sourceMappingURL=views-source-gate.module.js.map