UNPKG

@ixily/activ

Version:

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

271 lines (268 loc) 12.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ViewsSourceServerModule = void 0; const __1 = require("../.."); const config_module_1 = require("./config.module"); const DEFAULT_CACHE_VIEWS_SERVER_URL = 'cache-views.ixily.io'; const state = { baseUrlServer: DEFAULT_CACHE_VIEWS_SERVER_URL, customServers: false, }; config_module_1.ConfigModule.getConfigUpdatedStream().subscribe((config) => { if (config !== undefined) { if (config.dataSource !== undefined) { if (config.dataSource.publicCache.source === 'server') { state.baseUrlServer = config.dataSource.publicCache.customServerUrl || DEFAULT_CACHE_VIEWS_SERVER_URL; if (state.baseUrlServer !== DEFAULT_CACHE_VIEWS_SERVER_URL) { state.customServers = true; } } } } }); // using fetch const requestor = async (network, method, path, body) => { const url = state.customServers ? `${state.baseUrlServer}${path}` : network === 'polygon' ? `https://${state.baseUrlServer}${path}` : `https://${network}-${state.baseUrlServer}${path}`; __1.LogModule.dev('url', url); let markAsOneError = false; let theResponse; // insecure by skipping ssl const valueAns = await fetch(url, { method, mode: 'cors', body: body !== undefined ? JSON.stringify(body) : undefined, headers: { 'Content-Type': 'application/json', }, }) .then((response) => { __1.LogModule.dev('response'); __1.LogModule.dev(response); if (response.status < 200 || response.status >= 300) { markAsOneError = true; } theResponse = response; return response.json(); }) .catch((jsonConversionError) => { __1.LogModule.dev('jsonConversionError'); __1.LogModule.dev(jsonConversionError); return theResponse?.status || theResponse; }); if (markAsOneError) { const errorMsg = valueAns?.error || (typeof valueAns === 'string' ? valueAns : JSON.stringify(valueAns)); throw new Error(errorMsg); } return valueAns; }; /* */ const listContracts = async (network = 'polygon') => requestor(network, 'GET', '/v4/contracts'); const getCreator = async (contract, creatorWallet) => { const split = (0, __1.uniqueKeySplit)(contract); return requestor(split[0], 'GET', `/v4/contracts/${contract}/creators/${creatorWallet}`); }; const getIdeaByUniqueId = async (uniqueIdeaIndex) => { const split = (0, __1.uniqueKeySplit)(uniqueIdeaIndex); return requestor(split[0], 'GET', `/v4/ideas/${uniqueIdeaIndex}`); }; const listCreatorStrategies = async (contract, creatorWallet, page = 1, limit = 5) => { const split = (0, __1.uniqueKeySplit)(contract); const paginated = await requestor(split[0], 'GET', `/v4/contracts/${contract}/creators/${creatorWallet}/strategies?page=${page}&limit=${limit}`); __1.LogModule.dev('paginated', paginated); /* const paginatedInflated: IPaging<CONTRACT_INTERFACES.ITradeIdeaStrategy> = { ...paginated, data: await Promise.all( paginated.data.map((uniqueStrategyReference) => (async (): Promise<CONTRACT_INTERFACES.ITradeIdeaStrategy> => { // console.log('uniqueStrategyReference') // console.log(uniqueStrategyReference) const { strategyKey, creatorAddress } = decomposeUniqueStrategyReference( uniqueStrategyReference as string, ) // console.log('strategyKey') // console.log(strategyKey) // console.log('creatorAddress') // console.log(creatorAddress) const chain = await ProvableIdeasModule.chain.getValidatedStrategyChainWithCache( strategyKey, creatorAddress, ) // console.log('chain') // console.log(chain) // throw new Error('dsfadfa') const stg = chain.cache.cachedStrategy.strategy stg.uniqueKey = uniqueStrategyReference return stg })(), ), ), } // console.log('paginatedInflated') // console.log(paginatedInflated) return paginatedInflated */ return paginated; }; const getPublicStrategyWithCreator = async (uniqueStrategyKey) => { const split = (0, __1.uniqueKeySplit)(uniqueStrategyKey); return requestor(split[0], 'GET', `/v4/strategies/${uniqueStrategyKey}`); }; const listStrategiesWithAccessibleIdeasBy = async (contract, accessorWallet, page = 1, limit = 5) => { const split = (0, __1.uniqueKeySplit)(contract); return requestor(split[0], 'GET', `/v4/contracts/${contract}/accessors/${accessorWallet}/strategies?page=${page}&limit=${limit}`); }; const listStrategiesSubscribedToBy = async (contract, accessorWallet, page = 1, limit = 5) => { const split = (0, __1.uniqueKeySplit)(contract); return requestor(split[0], 'GET', `/v4/contracts/${contract}/subscribers/${accessorWallet}/strategies?page=${page}&limit=${limit}`); }; const listStrategiesPublic = async (contract, page = 1, limit = 5, network = 'polygon') => { if (contract !== undefined) { const split = (0, __1.uniqueKeySplit)(contract); return requestor(split[0], 'GET', `/v4/strategies?page=${page}&limit=${limit}` + (contract !== undefined ? '&contract=' + contract : '')); } else { return requestor(network, 'GET', `/v4/strategies?page=${page}&limit=${limit}` + (contract !== undefined ? '&contract=' + contract : '')); } }; const listIdeasUniqueIndexesByLatest = async (contract, page = 1, limit = 5) => { const split = (0, __1.uniqueKeySplit)(contract); return requestor(split[0], 'GET', `/v4/contracts/${contract}/ideaIndexes?page=${page}&limit=${limit}`); }; const listLatestIdeas = async (contract, page = 1, limit = 5) => { const split = (0, __1.uniqueKeySplit)(contract); return requestor(split[0], 'GET', `/v4/contracts/${contract}/ideas?page=${page}&limit=${limit}`); }; const listLatestPublicIdeas = async (contract, page = 1, limit = 5, network = 'polygon') => { if (contract !== undefined) { const split = (0, __1.uniqueKeySplit)(contract); return requestor(split[0], 'GET', `/v4/ideas?page=${page}&limit=${limit}` + (contract !== undefined ? '&contract=' + contract : '')); } else { return requestor(network, 'GET', `/v4/ideas?page=${page}&limit=${limit}` + (contract !== undefined ? '&contract=' + contract : '')); } }; const listCreatorIdeas = async (contract, creatorWallet, page = 1, limit = 5, filterType = 'bypass', filterIncludeEncrypted = true, bypassPaginationAndGetAll = false) => { const split = (0, __1.uniqueKeySplit)(contract); const filterTypeFormat = filterType === 'bypass' ? 'bypass' : filterType.join(','); const filterIncludeEncryptedFormat = filterIncludeEncrypted ? 'true' : 'false'; const bypassPaginationAndGetAllFormat = bypassPaginationAndGetAll ? 'true' : 'false'; return requestor(split[0], 'GET', `/v4/contracts/${contract}/creators/${creatorWallet}/ideas?page=${page}&limit=${limit}&filterType=${filterTypeFormat}&filterIncludeEncrypted=${filterIncludeEncryptedFormat}&bypassPaginationAndGetAll=${bypassPaginationAndGetAllFormat}`); }; const listOwnedIdeas = async (contract, ownerWallet, page = 1, limit = 5, filterType = 'bypass', filterIncludeEncrypted = true, bypassPaginationAndGetAll = false) => { const split = (0, __1.uniqueKeySplit)(contract); const filterTypeFormat = filterType === 'bypass' ? 'bypass' : filterType.join(','); const filterIncludeEncryptedFormat = filterIncludeEncrypted ? 'true' : 'false'; const bypassPaginationAndGetAllFormat = bypassPaginationAndGetAll ? 'true' : 'false'; return requestor(split[0], 'GET', `/v4/contracts/${contract}/owners/${ownerWallet}/ideas?page=${page}&limit=${limit}&filterType=${filterTypeFormat}&filterIncludeEncrypted=${filterIncludeEncryptedFormat}&bypassPaginationAndGetAll=${bypassPaginationAndGetAllFormat}`); }; const listStrategyIdeas = async (strategyUniqueKey, page = 1, limit = 5, filterType = 'bypass', filterIncludeEncrypted = true, bypassPaginationAndGetAll = false) => { const split = (0, __1.uniqueKeySplit)(strategyUniqueKey); const filterTypeFormat = filterType === 'bypass' ? 'bypass' : filterType.join(','); const filterIncludeEncryptedFormat = filterIncludeEncrypted ? 'true' : 'false'; const bypassPaginationAndGetAllFormat = bypassPaginationAndGetAll ? 'true' : 'false'; return requestor(split[0], 'GET', `/v4/strategies/${strategyUniqueKey}/ideas?page=${page}&limit=${limit}&filterType=${filterTypeFormat}&filterIncludeEncrypted=${filterIncludeEncryptedFormat}&bypassPaginationAndGetAll=${bypassPaginationAndGetAllFormat}`); }; const getStrategyPortfolio = async (strategyUniqueKey) => { const split = (0, __1.uniqueKeySplit)(strategyUniqueKey); return requestor(split[0], 'GET', `/v4/strategies/${strategyUniqueKey}/portfolio`); }; const listStrategyRebalances = async (strategyUniqueKey, page = 1, limit = 5) => { const split = (0, __1.uniqueKeySplit)(strategyUniqueKey); return requestor(split[0], 'GET', `/v4/strategies/${strategyUniqueKey}/rebalances?page=${page}&limit=${limit}`); }; const getStrategyRebalance = async (strategyUniqueKey, rebalanceId) => { const split = (0, __1.uniqueKeySplit)(strategyUniqueKey); return requestor(split[0], 'GET', `/v4/strategies/${strategyUniqueKey}/rebalances/${rebalanceId}`); }; const listStrategyRebalancesInPeriod = async (strategyUniqueKey, startDate, endDate, page = 1, limit = 5) => { const split = (0, __1.uniqueKeySplit)(strategyUniqueKey); return requestor(split[0], 'GET', `/v4/strategies/${strategyUniqueKey}/rebalancesInPeriod?startDate=${startDate}&endDate=${endDate}&page=${page}&limit=${limit}`); }; /* const listIdeasIndexes = async ( contract: string, page: number = 1, limit: number = 5, ): Promise<number[]> => requestor<number[]>( 'GET', `/v4/contracts/${contract}/ideas?page=${page}&limit=${limit}`, ) const listIdeaNftsByStrategy = async ( uniqueStrategyReference: string, ): Promise<CONTRACT_INTERFACES.MyIdeaKeys[]> => { return requestor<CONTRACT_INTERFACES.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<CONTRACT_INTERFACES.ITradeIdea> => requestor<CONTRACT_INTERFACES.ITradeIdea>( 'GET', `/v4/contracts/${contract}/ideaStagesByNft/${nftId}`, ) */ exports.ViewsSourceServerModule = { listContracts, getCreator, listCreatorStrategies, listStrategiesWithAccessibleIdeasBy, listStrategiesSubscribedToBy, listStrategiesPublic, listIdeasUniqueIndexesByLatest, listLatestIdeas, listLatestPublicIdeas, listCreatorIdeas, listOwnedIdeas, getIdeaByUniqueId, getPublicStrategyWithCreator, listStrategyIdeas, getStrategyPortfolio, listStrategyRebalances, getStrategyRebalance, listStrategyRebalancesInPeriod, // listIdeasIndexes, // listIdeaStagesIndexes, // getIdeaByNftId, // listIdeaNftsByStrategy, }; //# sourceMappingURL=views-source-server.module.js.map