aftermath-ts-sdk 1.1.97 → 1.2.0-refactor.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/general/historicalData/historicalData.d.ts +1 -1
  2. package/dist/general/historicalData/historicalData.d.ts.map +1 -1
  3. package/dist/general/nfts/nftsApi.d.ts +1 -5
  4. package/dist/general/nfts/nftsApi.d.ts.map +1 -1
  5. package/dist/general/nfts/nftsApi.js +15 -29
  6. package/dist/general/nfts/nftsApiCasting.d.ts +0 -1
  7. package/dist/general/nfts/nftsApiCasting.d.ts.map +1 -1
  8. package/dist/general/nfts/nftsApiCasting.js +0 -10
  9. package/dist/general/nfts/nftsTypes.d.ts +0 -1
  10. package/dist/general/nfts/nftsTypes.d.ts.map +1 -1
  11. package/dist/general/prices/{coingecko/coinGeckoTypes.d.ts → coinGeckoTypes.d.ts} +1 -1
  12. package/dist/general/prices/coinGeckoTypes.d.ts.map +1 -0
  13. package/dist/general/providers/aftermath.d.ts.map +1 -1
  14. package/dist/general/providers/aftermath.js +1 -2
  15. package/dist/general/providers/aftermathApi.d.ts +1 -34
  16. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  17. package/dist/general/providers/aftermathApi.js +2 -90
  18. package/dist/general/types/castingTypes.d.ts +0 -7
  19. package/dist/general/types/castingTypes.d.ts.map +1 -1
  20. package/dist/general/types/configTypes.d.ts +0 -6
  21. package/dist/general/types/configTypes.d.ts.map +1 -1
  22. package/dist/general/types/generalTypes.d.ts +0 -3
  23. package/dist/general/types/generalTypes.d.ts.map +1 -1
  24. package/dist/general/types/index.d.ts +1 -0
  25. package/dist/general/types/index.d.ts.map +1 -1
  26. package/dist/general/types/index.js +1 -0
  27. package/dist/general/utils/helpers.d.ts +1 -16
  28. package/dist/general/utils/helpers.d.ts.map +1 -1
  29. package/dist/general/utils/helpers.js +2 -32
  30. package/dist/general/utils/index.d.ts +0 -1
  31. package/dist/general/utils/index.d.ts.map +1 -1
  32. package/dist/general/utils/index.js +0 -1
  33. package/dist/packages/coin/api/coinApi.d.ts +1 -12
  34. package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
  35. package/dist/packages/coin/api/coinApi.js +0 -123
  36. package/dist/packages/dca/api/dcaApi.d.ts +1 -28
  37. package/dist/packages/dca/api/dcaApi.d.ts.map +1 -1
  38. package/dist/packages/dca/api/dcaApi.js +0 -172
  39. package/dist/packages/farms/api/farmsApi.d.ts +1 -24
  40. package/dist/packages/farms/api/farmsApi.d.ts.map +1 -1
  41. package/dist/packages/farms/api/farmsApi.js +0 -69
  42. package/dist/packages/farms/api/farmsApiCasting.d.ts +2 -3
  43. package/dist/packages/farms/api/farmsApiCasting.d.ts.map +1 -1
  44. package/dist/packages/farms/api/farmsApiCasting.js +0 -45
  45. package/dist/packages/farms/api/farmsApiCastingTypes.d.ts +0 -9
  46. package/dist/packages/farms/api/farmsApiCastingTypes.d.ts.map +1 -1
  47. package/dist/packages/faucet/api/faucetApi.d.ts +0 -5
  48. package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
  49. package/dist/packages/faucet/api/faucetApi.js +2 -29
  50. package/dist/packages/faucet/faucet.d.ts +3 -2
  51. package/dist/packages/faucet/faucet.d.ts.map +1 -1
  52. package/dist/packages/faucet/faucet.js +2 -2
  53. package/dist/packages/leveragedStaking/api/leveragedStakingApi.d.ts.map +1 -1
  54. package/dist/packages/leveragedStaking/api/leveragedStakingApi.js +383 -298
  55. package/dist/packages/nftAmm/nftAmmMarket.d.ts +9 -5
  56. package/dist/packages/nftAmm/nftAmmMarket.d.ts.map +1 -1
  57. package/dist/packages/nftAmm/nftAmmMarket.js +34 -6
  58. package/dist/packages/oracle/api/oracleApi.d.ts +1 -10
  59. package/dist/packages/oracle/api/oracleApi.d.ts.map +1 -1
  60. package/dist/packages/oracle/api/oracleApi.js +0 -38
  61. package/dist/packages/perpetuals/api/perpetualsApi.d.ts +2 -58
  62. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  63. package/dist/packages/perpetuals/api/perpetualsApi.js +0 -735
  64. package/dist/packages/pools/api/poolsApi.d.ts +2 -217
  65. package/dist/packages/pools/api/poolsApi.d.ts.map +1 -1
  66. package/dist/packages/pools/api/poolsApi.js +0 -752
  67. package/dist/packages/pools/api/poolsApiCasting.d.ts +3 -15
  68. package/dist/packages/pools/api/poolsApiCasting.d.ts.map +1 -1
  69. package/dist/packages/pools/api/poolsApiCasting.js +0 -86
  70. package/dist/packages/pools/api/poolsApiCastingTypes.d.ts +1 -15
  71. package/dist/packages/pools/api/poolsApiCastingTypes.d.ts.map +1 -1
  72. package/dist/packages/pools/pools.d.ts +4 -1
  73. package/dist/packages/pools/pools.d.ts.map +1 -1
  74. package/dist/packages/pools/pools.js +5 -0
  75. package/dist/packages/router/api/routerApi.d.ts +2 -116
  76. package/dist/packages/router/api/routerApi.d.ts.map +1 -1
  77. package/dist/packages/router/api/routerApi.js +3 -345
  78. package/dist/packages/router/api/routerApiCasting.d.ts +2 -5
  79. package/dist/packages/router/api/routerApiCasting.d.ts.map +1 -1
  80. package/dist/packages/router/api/routerApiCasting.js +0 -104
  81. package/dist/packages/router/api/routerApiCastingTypes.d.ts +1 -13
  82. package/dist/packages/router/api/routerApiCastingTypes.d.ts.map +1 -1
  83. package/dist/packages/router/routerTypes.d.ts +3 -35
  84. package/dist/packages/router/routerTypes.d.ts.map +1 -1
  85. package/dist/packages/staking/api/stakingApi.d.ts +2 -50
  86. package/dist/packages/staking/api/stakingApi.d.ts.map +1 -1
  87. package/dist/packages/staking/api/stakingApi.js +0 -226
  88. package/dist/packages/staking/api/stakingApiCasting.d.ts +2 -4
  89. package/dist/packages/staking/api/stakingApiCasting.d.ts.map +1 -1
  90. package/dist/packages/staking/api/stakingApiCasting.js +0 -21
  91. package/dist/packages/staking/api/stakingApiCastingTypes.d.ts +1 -8
  92. package/dist/packages/staking/api/stakingApiCastingTypes.d.ts.map +1 -1
  93. package/dist/packages/staking/stakingTypes.d.ts +2 -0
  94. package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
  95. package/dist/packages/sui/api/suiApi.d.ts +1 -2
  96. package/dist/packages/sui/api/suiApi.d.ts.map +1 -1
  97. package/dist/packages/sui/api/suiApi.js +0 -3
  98. package/package.json +1 -1
  99. package/dist/general/dynamicGas/dynamicGasApi.d.ts +0 -15
  100. package/dist/general/dynamicGas/dynamicGasApi.d.ts.map +0 -1
  101. package/dist/general/dynamicGas/dynamicGasApi.js +0 -87
  102. package/dist/general/historicalData/historicalDataApi.d.ts +0 -9
  103. package/dist/general/historicalData/historicalDataApi.d.ts.map +0 -1
  104. package/dist/general/historicalData/historicalDataApi.js +0 -13
  105. package/dist/general/historicalData/historicalDataApiInterface.d.ts +0 -12
  106. package/dist/general/historicalData/historicalDataApiInterface.d.ts.map +0 -1
  107. package/dist/general/historicalData/historicalDataApiInterface.js +0 -2
  108. package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts +0 -13
  109. package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts.map +0 -1
  110. package/dist/general/historicalData/placeholderHistoricalDataApi.js +0 -26
  111. package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts +0 -22
  112. package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts.map +0 -1
  113. package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +0 -179
  114. package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts +0 -23
  115. package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts.map +0 -1
  116. package/dist/general/prices/coingecko/coinGeckoPricesApi.js +0 -113
  117. package/dist/general/prices/coingecko/coinGeckoTypes.d.ts.map +0 -1
  118. package/dist/general/prices/placeholder/placeholderPricesApi.d.ts +0 -20
  119. package/dist/general/prices/placeholder/placeholderPricesApi.d.ts.map +0 -1
  120. package/dist/general/prices/placeholder/placeholderPricesApi.js +0 -85
  121. package/dist/general/prices/pricesApiInterface.d.ts +0 -13
  122. package/dist/general/prices/pricesApiInterface.d.ts.map +0 -1
  123. package/dist/general/prices/pricesApiInterface.js +0 -2
  124. package/dist/general/prices/pyth/pythPricesApi.d.ts +0 -2
  125. package/dist/general/prices/pyth/pythPricesApi.d.ts.map +0 -1
  126. package/dist/general/prices/pyth/pythPricesApi.js +0 -52
  127. package/dist/general/prices/pyth/pythPricesApiHelpers.d.ts +0 -13
  128. package/dist/general/prices/pyth/pythPricesApiHelpers.d.ts.map +0 -1
  129. package/dist/general/prices/pyth/pythPricesApiHelpers.js +0 -77
  130. package/dist/general/prices/router/routerPricesApi.d.ts +0 -18
  131. package/dist/general/prices/router/routerPricesApi.d.ts.map +0 -1
  132. package/dist/general/prices/router/routerPricesApi.js +0 -126
  133. package/dist/general/utils/indexerCaller.d.ts +0 -14
  134. package/dist/general/utils/indexerCaller.d.ts.map +0 -1
  135. package/dist/general/utils/indexerCaller.js +0 -129
  136. /package/dist/general/prices/{coingecko/coinGeckoTypes.js → coinGeckoTypes.js} +0 -0
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.PythPricesApiHelpers = void 0;
13
- const pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
14
- const packages_1 = require("../../../packages");
15
- class PythPricesApiHelpers {
16
- // =========================================================================
17
- // Constructor
18
- // =========================================================================
19
- constructor(coinSymbolToCoinTypes) {
20
- this.coinSymbolToCoinTypes = coinSymbolToCoinTypes;
21
- // =========================================================================
22
- // Protected Methods
23
- // =========================================================================
24
- // =========================================================================
25
- // Fetching
26
- // =========================================================================
27
- this.fetchPriceFeeds = (coins) => __awaiter(this, void 0, void 0, function* () {
28
- const filteredPriceIds = coins.map((coin) => {
29
- const coinSymbol = packages_1.Coin.coinSymbolForCoinType({
30
- coinType: coin,
31
- coinSymbolToCoinTypes: this.coinSymbolToCoinTypes,
32
- });
33
- if (!coinSymbol)
34
- return "";
35
- const priceFeedIds = PythPricesApiHelpers.constants.priceFeedIds;
36
- if (!(coinSymbol in priceFeedIds))
37
- return "";
38
- return priceFeedIds[coinSymbol];
39
- });
40
- const onlyPriceIds = filteredPriceIds.filter((priceId) => priceId !== "");
41
- const uniquePriceIds = onlyPriceIds.filter((priceId, index) => onlyPriceIds.indexOf(priceId) === index);
42
- const uniquePriceFeeds = yield this.connection.getLatestPriceFeeds(uniquePriceIds);
43
- if (!uniquePriceFeeds)
44
- throw Error("failed to get latest prices");
45
- const priceFeeds = filteredPriceIds.map((priceId) => {
46
- const foundIndex = uniquePriceIds.indexOf(priceId);
47
- if (foundIndex >= 0)
48
- return uniquePriceFeeds[foundIndex].getPriceNoOlderThan(60);
49
- return undefined;
50
- });
51
- return priceFeeds;
52
- });
53
- this.coinSymbolToCoinTypes = coinSymbolToCoinTypes;
54
- this.connection = new pyth_sui_js_1.SuiPriceServiceConnection(PythPricesApiHelpers.constants.priceFeedsEndpoint);
55
- }
56
- }
57
- exports.PythPricesApiHelpers = PythPricesApiHelpers;
58
- // =========================================================================
59
- // Constants
60
- // =========================================================================
61
- PythPricesApiHelpers.constants = {
62
- priceFeedsEndpoint: "https://xc-mainnet.pyth.network",
63
- priceFeedIds: {
64
- usdc: "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
65
- sui: "0x23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc6574",
66
- usdt: "0x2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
67
- eth: "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ac",
68
- btc: "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b4",
69
- ftm: "0x5c6c0d2386e3352356c3ab84434fafb5ea067ac2678a38a338c4a69ddc4bdb0",
70
- avax: "0x93da3352f9f1d105fdfe4971cfa80e9dd777bfc5d0f683ebb6e1294b92137bb7",
71
- celo: "0x7d669ddcdd23d9ef1fa9a9cc022ba055ec900e91c4cb960f3c20429d4447a411",
72
- sol: "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56",
73
- matic: "0x5de33a9112c2b700b8d30b8a3402c103578ccfa2765696471cc672bd5cf6ac52",
74
- bnb: "0x2f95862b045670cd22bee3114c39763a4a08beeb663b145d283c31d7d1101c4",
75
- // glmr : ""
76
- },
77
- };
@@ -1,18 +0,0 @@
1
- import { CoinPriceInfo, CoinType, CoinsToPrice } from "../../../types";
2
- import { AftermathApi } from "../../providers";
3
- import { PricesApiInterface } from "../pricesApiInterface";
4
- export declare class RouterPricesApi implements PricesApiInterface {
5
- private readonly Provider;
6
- constructor(Provider: AftermathApi);
7
- fetchPrice: (inputs: {
8
- coin: CoinType;
9
- }) => Promise<number>;
10
- fetchCoinsToPrice: (...inputs: {
11
- coins: CoinType[];
12
- }[]) => Promise<CoinsToPrice>;
13
- fetchCoinsToPriceInfo: (...inputs: {
14
- coins: CoinType[];
15
- }[]) => Promise<Record<string, CoinPriceInfo>>;
16
- private fetchCoinsToPriceInfoInternal;
17
- }
18
- //# sourceMappingURL=routerPricesApi.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"routerPricesApi.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/router/routerPricesApi.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EAGb,QAAQ,EACR,YAAY,EAEZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,qBAAa,eAAgB,YAAW,kBAAkB;IAK7C,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,YAAY;IAc5C,UAAU,WAAkB;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,KAAG,QAAQ,MAAM,CAAC,CAMrE;IAGK,iBAAiB;eAIf,QAAQ,EAAE;kCA6BhB;IAGI,qBAAqB;eAInB,QAAQ,EAAE;mDA0DhB;IAMH,OAAO,CAAC,6BAA6B,CAgElC;CACH"}
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.RouterPricesApi = void 0;
13
- const utils_1 = require("../../utils");
14
- class RouterPricesApi {
15
- // =========================================================================
16
- // Constructor
17
- // =========================================================================
18
- constructor(Provider) {
19
- this.Provider = Provider;
20
- // =========================================================================
21
- // Fetching
22
- // =========================================================================
23
- // =========================================================================
24
- // Public
25
- // =========================================================================
26
- // =========================================================================
27
- // Interface Methods
28
- // =========================================================================
29
- this.fetchPrice = (inputs) => __awaiter(this, void 0, void 0, function* () {
30
- return Object.values(yield this.fetchCoinsToPrice({
31
- coins: [inputs.coin],
32
- }))[0];
33
- });
34
- // TODO: add single caches
35
- this.fetchCoinsToPrice = this.Provider.withCache({
36
- key: "routerPricesApi.fetchCoinsToPrice",
37
- expirationSeconds: 60,
38
- callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
39
- const { coins } = inputs;
40
- if (coins.length <= 0)
41
- return {};
42
- const prices = yield this.Provider.indexerCaller.fetchIndexer("prices", {
43
- coin_types: coins,
44
- }, undefined, undefined, undefined, true);
45
- return coins.reduce((acc, coin, index) => (Object.assign(Object.assign({}, acc), { [coin]: prices[index] <= 0 ? -1 : prices[index] })), {});
46
- }),
47
- });
48
- // TODO: add single cache by coin type ?
49
- this.fetchCoinsToPriceInfo = this.Provider.withCache({
50
- key: "routerPricesApi.fetchCoinsToPriceInfo",
51
- expirationSeconds: 60,
52
- callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
53
- const { coins } = inputs;
54
- // filter regular vs LP coins
55
- const [lpCoins, regularCoins] = yield utils_1.Helpers.bifilterAsync(coins, (coin) => __awaiter(this, void 0, void 0, function* () {
56
- return this.Provider.Pools().fetchIsLpCoinType({
57
- lpCoinType: coin,
58
- });
59
- }));
60
- // get coin price info for regular coins and calc info for LP coins
61
- const [regularCoinsToPriceInfo, lpCoinsToPrice] = yield Promise.all([
62
- this.fetchCoinsToPriceInfoInternal({ coins: regularCoins }),
63
- this.Provider.Pools().fetchLpCoinsToPrice({ lpCoins }),
64
- ]);
65
- const lpCoinsToPriceInfo = Object.entries(lpCoinsToPrice).reduce((acc, [coin, price]) => (Object.assign(Object.assign({}, acc), { [coin]: {
66
- price,
67
- priceChange24HoursPercentage: 0,
68
- } })), {});
69
- // fill in missing any price info data
70
- const missingRegularCoins = regularCoins.reduce((acc, coin) => utils_1.Helpers.addLeadingZeroesToType(coin) in
71
- regularCoinsToPriceInfo
72
- ? acc
73
- : Object.assign(Object.assign({}, acc), { [utils_1.Helpers.addLeadingZeroesToType(coin)]: {
74
- price: -1,
75
- priceChange24HoursPercentage: 0,
76
- } }), {});
77
- // merge all collected data
78
- const allInfo = Object.assign(Object.assign(Object.assign({}, missingRegularCoins), lpCoinsToPriceInfo), regularCoinsToPriceInfo);
79
- return allInfo;
80
- }),
81
- });
82
- // =========================================================================
83
- // Private (Non-Interface) Methods
84
- // =========================================================================
85
- this.fetchCoinsToPriceInfoInternal = this.Provider.withCache({
86
- key: "routerPricesApi.fetchCoinsToPriceInfoInternal",
87
- expirationSeconds: 60,
88
- callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
89
- const { coins } = inputs;
90
- if (coins.length <= 0)
91
- return {};
92
- const singleCacheKey = "routerPricesApi.fetchCoinsToPriceInfoInternal_coin";
93
- const cachedCoinsToPriceInfo = coins.reduce((acc, coin) => {
94
- const cachedData = this.Provider.getCache({
95
- key: singleCacheKey,
96
- inputs: [coin],
97
- });
98
- if (cachedData === "NO_CACHED_DATA")
99
- return acc;
100
- return Object.assign(Object.assign({}, acc), { [coin]: cachedData });
101
- }, {});
102
- const nonCachedCoins = coins.filter((coin) => !Object.keys(cachedCoinsToPriceInfo).includes(coin));
103
- const nonCachedCoinsToPrice = yield this.fetchCoinsToPrice({
104
- coins: nonCachedCoins,
105
- });
106
- const nonCachedCoinsInfo = Object.entries(nonCachedCoinsToPrice).reduce((acc, [coin, price]) => {
107
- return Object.assign(Object.assign({}, acc), { [coin]: {
108
- price,
109
- // TODO: add 24hr price change
110
- priceChange24HoursPercentage: 0,
111
- } });
112
- }, {});
113
- for (const [coin, coinsInfo] of Object.entries(nonCachedCoinsInfo)) {
114
- this.Provider.setCache({
115
- key: singleCacheKey,
116
- data: coinsInfo,
117
- inputs: [coin],
118
- expirationSeconds: 60,
119
- });
120
- }
121
- return Object.assign(Object.assign({}, cachedCoinsToPriceInfo), nonCachedCoinsInfo);
122
- }),
123
- });
124
- }
125
- }
126
- exports.RouterPricesApi = RouterPricesApi;
@@ -1,14 +0,0 @@
1
- import { ApiIndexerEventsBody, IndexerEventsWithCursor, SuiNetwork, Url } from "../../types";
2
- export declare class IndexerCaller {
3
- readonly network?: SuiNetwork | undefined;
4
- private readonly indexerUrlPrefix;
5
- private readonly indexerBaseUrl?;
6
- constructor(network?: SuiNetwork | undefined, indexerUrlPrefix?: Url);
7
- private static fetchResponseToType;
8
- private static addParamsToUrl;
9
- private static indexerBaseUrlForNetwork;
10
- private urlForIndexerCall;
11
- fetchIndexer<Output, BodyType = undefined, QueryParamsType extends Object = {}>(url: Url, body?: BodyType, queryParams?: QueryParamsType, urlPrefix?: string, signal?: AbortSignal, noNestedData?: boolean): Promise<Output>;
12
- fetchIndexerEvents<EventTypeOnChain, EventType>(url: Url, queryParams: ApiIndexerEventsBody, castingFunc: (eventOnChain: EventTypeOnChain) => EventType, signal?: AbortSignal): Promise<IndexerEventsWithCursor<EventType>>;
13
- }
14
- //# sourceMappingURL=indexerCaller.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"indexerCaller.d.ts","sourceRoot":"","sources":["../../../src/general/utils/indexerCaller.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EAEpB,uBAAuB,EAEvB,UAAU,EACV,GAAG,EACH,MAAM,aAAa,CAAC;AAGrB,qBAAa,aAAa;aAQR,OAAO,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IARlC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAM;gBAOrB,OAAO,CAAC,wBAAY,EACnB,gBAAgB,GAAE,GAAQ;mBAYvB,mBAAmB;IAUxC,OAAO,CAAC,MAAM,CAAC,cAAc;IAgC7B,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAcvC,OAAO,CAAC,iBAAiB,CAQvB;IAUW,YAAY,CACxB,MAAM,EACN,QAAQ,GAAG,SAAS,EACpB,eAAe,SAAS,MAAM,GAAG,EAAE,EAEnC,GAAG,EAAE,GAAG,EACR,IAAI,CAAC,EAAE,QAAQ,EACf,WAAW,CAAC,EAAE,eAAe,EAC7B,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,EACpB,YAAY,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,MAAM,CAAC;IAkCL,kBAAkB,CAAC,gBAAgB,EAAE,SAAS,EAC1D,GAAG,EAAE,GAAG,EACR,WAAW,EAAE,oBAAoB,EACjC,WAAW,EAAE,CAAC,YAAY,EAAE,gBAAgB,KAAK,SAAS,EAC1D,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;CAuB9C"}
@@ -1,129 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.IndexerCaller = void 0;
13
- const helpers_1 = require("./helpers");
14
- class IndexerCaller {
15
- // =========================================================================
16
- // Constructor
17
- // =========================================================================
18
- constructor(network, indexerUrlPrefix = "") {
19
- this.network = network;
20
- this.indexerUrlPrefix = indexerUrlPrefix;
21
- this.urlForIndexerCall = (url, urlPrefix) => {
22
- if (this.indexerBaseUrl === undefined)
23
- throw new Error("no indexerBaseUrl: unable to fetch data");
24
- // TODO: handle url prefixing and api calls based on network differently
25
- return `${this.indexerBaseUrl}/${urlPrefix !== null && urlPrefix !== void 0 ? urlPrefix : "af-fe"}/${this.indexerUrlPrefix === "" ? "" : this.indexerUrlPrefix + "/"}${url}`;
26
- };
27
- this.indexerBaseUrl =
28
- network === undefined
29
- ? undefined
30
- : IndexerCaller.indexerBaseUrlForNetwork(network);
31
- }
32
- // =========================================================================
33
- // Private Methods
34
- // =========================================================================
35
- static fetchResponseToType(response) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- if (!response.ok)
38
- throw new Error(yield response.text());
39
- const json = JSON.stringify(yield response.json());
40
- const output = helpers_1.Helpers.parseJsonWithBigint(json);
41
- return output;
42
- });
43
- }
44
- static addParamsToUrl(url, queryParams) {
45
- if (!queryParams || Object.keys(queryParams).length <= 0)
46
- return url;
47
- const queryParamsUrl = new URLSearchParams(Object.entries(queryParams).reduce((acc, [key, val]) => {
48
- if (val === undefined || Array.isArray(val))
49
- return acc;
50
- return Object.assign(Object.assign({}, acc), { [key]: val.toString() });
51
- }, {}));
52
- // add array args
53
- for (const [key, val] of Object.entries(queryParams)) {
54
- if (!Array.isArray(val))
55
- continue;
56
- for (const item of val) {
57
- queryParamsUrl.append(key, item.toString());
58
- }
59
- }
60
- return `${url}${queryParamsUrl.toString() !== ""
61
- ? "?" + queryParamsUrl.toString()
62
- : ""}`;
63
- }
64
- // =========================================================================
65
- // Indexer Calling
66
- // =========================================================================
67
- static indexerBaseUrlForNetwork(network) {
68
- if (network === "MAINNET")
69
- return "https://aftermath.finance";
70
- if (network === "MAINNET_STAGING")
71
- return "https://staging-api.aftermath.finance";
72
- if (network === "TESTNET")
73
- return "https://testnet.aftermath.finance";
74
- if (network === "DEVNET")
75
- return "https://staging-api.aftermath.finance";
76
- if (network === "LOCAL")
77
- return "http://localhost:8080";
78
- const safeUrl = network.slice(-1) === "/" ? network.slice(0, -1) : network;
79
- return safeUrl;
80
- }
81
- // =========================================================================
82
- // Public Methods
83
- // =========================================================================
84
- // =========================================================================
85
- // Indexer Calling
86
- // =========================================================================
87
- fetchIndexer(url, body, queryParams, urlPrefix, signal, noNestedData) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- // TODO: handle bigint sending via indexer pattern ?
90
- // this allows BigInt to be JSON serialized (as string)
91
- // (BigInt.prototype as any).toJSON = function () {
92
- // return this.toString() + "n";
93
- // };
94
- const indexerCallUrl = IndexerCaller.addParamsToUrl(this.urlForIndexerCall(url, urlPrefix), queryParams);
95
- const uncastResponse = yield (body === undefined
96
- ? fetch(indexerCallUrl, { signal })
97
- : fetch(indexerCallUrl, {
98
- method: "POST",
99
- body: JSON.stringify(body),
100
- signal,
101
- headers: {
102
- "Content-Type": "application/json",
103
- Accept: "*/*",
104
- },
105
- }));
106
- if (noNestedData) {
107
- return IndexerCaller.fetchResponseToType(uncastResponse);
108
- }
109
- const response = yield IndexerCaller.fetchResponseToType(uncastResponse);
110
- return response.data;
111
- });
112
- }
113
- fetchIndexerEvents(url, queryParams, castingFunc, signal) {
114
- var _a, _b;
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const limit = (_a = queryParams.limit) !== null && _a !== void 0 ? _a : 10;
117
- const eventsOnChain = yield this.fetchIndexer(url, undefined, {
118
- skip: (_b = queryParams.cursor) !== null && _b !== void 0 ? _b : 0,
119
- limit,
120
- }, undefined, signal);
121
- const events = eventsOnChain.map(castingFunc);
122
- return {
123
- events,
124
- nextCursor: events.length < limit ? undefined : limit,
125
- };
126
- });
127
- }
128
- }
129
- exports.IndexerCaller = IndexerCaller;