aftermath-ts-sdk 0.0.146 → 0.0.148

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 (57) hide show
  1. package/dist/general/api/objectsApiHelpers.d.ts +1 -0
  2. package/dist/general/api/objectsApiHelpers.d.ts.map +1 -1
  3. package/dist/general/api/objectsApiHelpers.js +20 -2
  4. package/dist/general/historicalData/historicalDataApi.d.ts +2 -1
  5. package/dist/general/historicalData/historicalDataApi.d.ts.map +1 -1
  6. package/dist/general/historicalData/historicalDataApiInterface.d.ts +10 -0
  7. package/dist/general/historicalData/historicalDataApiInterface.d.ts.map +1 -0
  8. package/dist/general/historicalData/historicalDataApiInterface.js +2 -0
  9. package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts +10 -0
  10. package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts.map +1 -0
  11. package/dist/general/historicalData/placeholderHistoricalDataApi.js +23 -0
  12. package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts +1 -0
  13. package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts.map +1 -1
  14. package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +23 -4
  15. package/dist/general/prices/placeholder/placeholderPricesApi.d.ts +1 -2
  16. package/dist/general/prices/placeholder/placeholderPricesApi.d.ts.map +1 -1
  17. package/dist/general/prices/placeholder/placeholderPricesApi.js +1 -1
  18. package/dist/general/providers/aftermathApi.d.ts +6 -4
  19. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  20. package/dist/general/providers/aftermathApi.js +8 -3
  21. package/dist/general/utils/helpers.d.ts +1 -0
  22. package/dist/general/utils/helpers.d.ts.map +1 -1
  23. package/dist/general/utils/helpers.js +8 -0
  24. package/dist/packages/external/cetus/cetusApi.d.ts +11 -4
  25. package/dist/packages/external/cetus/cetusApi.d.ts.map +1 -1
  26. package/dist/packages/external/cetus/cetusApi.js +9 -6
  27. package/dist/packages/external/cetus/cetusApiHelpers.d.ts +54 -4
  28. package/dist/packages/external/cetus/cetusApiHelpers.d.ts.map +1 -1
  29. package/dist/packages/external/cetus/cetusApiHelpers.js +120 -50
  30. package/dist/packages/external/turbos/turbosApi.d.ts +11 -4
  31. package/dist/packages/external/turbos/turbosApi.d.ts.map +1 -1
  32. package/dist/packages/external/turbos/turbosApi.js +9 -6
  33. package/dist/packages/external/turbos/turbosApiHelpers.d.ts +14 -4
  34. package/dist/packages/external/turbos/turbosApiHelpers.d.ts.map +1 -1
  35. package/dist/packages/external/turbos/turbosApiHelpers.js +76 -20
  36. package/dist/packages/router/api/routerApi.d.ts +2 -4
  37. package/dist/packages/router/api/routerApi.d.ts.map +1 -1
  38. package/dist/packages/router/api/routerApi.js +5 -25
  39. package/dist/packages/router/api/routerApiHelpers.d.ts +41 -0
  40. package/dist/packages/router/api/routerApiHelpers.d.ts.map +1 -0
  41. package/dist/packages/router/api/routerApiHelpers.js +191 -0
  42. package/dist/packages/router/api/routerAsyncApiHelpers.d.ts +15 -4
  43. package/dist/packages/router/api/routerAsyncApiHelpers.d.ts.map +1 -1
  44. package/dist/packages/router/api/routerAsyncApiHelpers.js +42 -9
  45. package/dist/packages/router/api/routerSynchronousApiHelpers.d.ts +1 -10
  46. package/dist/packages/router/api/routerSynchronousApiHelpers.d.ts.map +1 -1
  47. package/dist/packages/router/api/routerSynchronousApiHelpers.js +5 -25
  48. package/dist/packages/router/routerTypes.d.ts.map +1 -1
  49. package/dist/packages/router/utils/async/routerAsyncApiInterface.d.ts +13 -6
  50. package/dist/packages/router/utils/async/routerAsyncApiInterface.d.ts.map +1 -1
  51. package/dist/packages/router/utils/async/routerAsyncGraph.d.ts +4 -2
  52. package/dist/packages/router/utils/async/routerAsyncGraph.d.ts.map +1 -1
  53. package/dist/packages/router/utils/async/routerAsyncGraph.js +34 -34
  54. package/dist/packages/router/utils/synchronous/routerGraph.d.ts +13 -11
  55. package/dist/packages/router/utils/synchronous/routerGraph.d.ts.map +1 -1
  56. package/dist/packages/router/utils/synchronous/routerGraph.js +109 -73
  57. package/package.json +1 -1
@@ -14,19 +14,48 @@ class RouterAsyncGraph {
14
14
  /////////////////////////////////////////////////////////////////////
15
15
  static createFinalCompleteRoute(inputs) {
16
16
  const asyncCompleteRoutes = this.completeRoutesFromTradeResults(inputs);
17
- const completeRoutes = inputs.synchronousCompleteRoutes
18
- ? [...asyncCompleteRoutes, inputs.synchronousCompleteRoutes]
19
- : [...asyncCompleteRoutes];
17
+ const completeRoutes = inputs.completeRoutes
18
+ ? [...asyncCompleteRoutes, ...inputs.completeRoutes]
19
+ : asyncCompleteRoutes;
20
20
  const chosenCompleteRoutes = this.splitTradeBetweenRoutes(Object.assign(Object.assign({}, inputs), { completeRoutes }));
21
21
  const finalCompleteRoute = this.singleCompleteRouteFromMany({
22
22
  completeRoutes: chosenCompleteRoutes,
23
23
  });
24
24
  if (finalCompleteRoute.coinOut.amount <= BigInt(0))
25
- throw new Error("unable to find route ");
25
+ throw new Error("unable to find route");
26
26
  return finalCompleteRoute;
27
27
  }
28
28
  }
29
29
  exports.RouterAsyncGraph = RouterAsyncGraph;
30
+ RouterAsyncGraph.completeRoutesFromTradeResults = (inputs) => {
31
+ const { tradeResults } = inputs;
32
+ const completeRoutes = tradeResults.results.map((result) => {
33
+ const routes = result.amountsOut.map((amountOut, amountOutIndex) => {
34
+ const path = {
35
+ pool: result.pool,
36
+ protocolName: result.protocol,
37
+ coinIn: {
38
+ type: tradeResults.coinInType,
39
+ amount: tradeResults.coinInAmounts[amountOutIndex],
40
+ tradeFee: BigInt(0),
41
+ },
42
+ coinOut: {
43
+ type: tradeResults.coinOutType,
44
+ amount: amountOut,
45
+ tradeFee: BigInt(0),
46
+ },
47
+ spotPrice: Number(tradeResults.coinInAmounts[0]) /
48
+ Number(result.amountsOut[0]),
49
+ };
50
+ return Object.assign(Object.assign({}, path), { paths: [path] });
51
+ });
52
+ const completeRoutes = routes.map((route) => {
53
+ return Object.assign({ routes: [route] }, route);
54
+ });
55
+ return completeRoutes;
56
+ });
57
+ return completeRoutes;
58
+ };
30
59
  /////////////////////////////////////////////////////////////////////
31
60
  //// Private Static Methods
32
61
  /////////////////////////////////////////////////////////////////////
@@ -35,7 +64,7 @@ exports.RouterAsyncGraph = RouterAsyncGraph;
35
64
  /////////////////////////////////////////////////////////////////////
36
65
  RouterAsyncGraph.splitTradeBetweenRoutes = (inputs) => {
37
66
  const { completeRoutes, coinInAmounts } = inputs;
38
- let chosenRouteIndexes = Array(coinInAmounts.length).fill(-1);
67
+ let chosenRouteIndexes = Array(completeRoutes.length).fill(-1);
39
68
  for (const _ of coinInAmounts) {
40
69
  const incrementalAmountsOut = completeRoutes.map((route, index) => {
41
70
  const prevChosenIndex = chosenRouteIndexes[index];
@@ -84,32 +113,3 @@ RouterAsyncGraph.singleCompleteRouteFromMany = (inputs) => {
84
113
  },
85
114
  };
86
115
  };
87
- RouterAsyncGraph.completeRoutesFromTradeResults = (inputs) => {
88
- const { tradeResults } = inputs;
89
- const completeRoutes = tradeResults.results.map((result) => {
90
- const routes = result.amountsOut.map((amountOut, amountOutIndex) => {
91
- const path = {
92
- pool: result.pool,
93
- protocolName: result.protocol,
94
- coinIn: {
95
- type: tradeResults.coinInType,
96
- amount: tradeResults.coinInAmounts[amountOutIndex],
97
- tradeFee: BigInt(0),
98
- },
99
- coinOut: {
100
- type: tradeResults.coinOutType,
101
- amount: amountOut,
102
- tradeFee: BigInt(0),
103
- },
104
- spotPrice: Number(tradeResults.coinInAmounts[0]) /
105
- Number(result.amountsOut[0]),
106
- };
107
- return Object.assign(Object.assign({}, path), { paths: [path] });
108
- });
109
- const completeRoutes = routes.map((route) => {
110
- return Object.assign({ routes: [route] }, route);
111
- });
112
- return completeRoutes;
113
- });
114
- return completeRoutes;
115
- };
@@ -18,17 +18,6 @@ export declare class RouterGraph {
18
18
  readonly graph: RouterCompleteGraph;
19
19
  readonly constants: RouterOptions;
20
20
  constructor(network: SuiNetwork | Url, graph: RouterSerializableCompleteGraph, options?: RouterOptions);
21
- static createGraph(inputs: {
22
- pools: RouterSerializablePool[];
23
- }): RouterSerializableCompleteGraph;
24
- static graphFromSerializable(inputs: {
25
- graph: RouterSerializableCompleteGraph;
26
- network: SuiNetwork | Url;
27
- }): RouterCompleteGraph;
28
- static supportedCoinPathsFromGraph: (inputs: {
29
- graph: RouterSerializableCompleteGraph;
30
- maxRouteLength?: number;
31
- }) => Promise<RouterSupportedCoinPaths>;
32
21
  getCompleteRouteGivenAmountIn(inputs: {
33
22
  coinInType: CoinType;
34
23
  coinInAmount: Balance;
@@ -43,6 +32,17 @@ export declare class RouterGraph {
43
32
  referrer?: SuiAddress;
44
33
  externalFee?: RouterExternalFee;
45
34
  }): RouterCompleteTradeRoute[];
35
+ static createGraph(inputs: {
36
+ pools: RouterSerializablePool[];
37
+ }): RouterSerializableCompleteGraph;
38
+ static graphFromSerializable(inputs: {
39
+ graph: RouterSerializableCompleteGraph;
40
+ network: SuiNetwork | Url;
41
+ }): RouterCompleteGraph;
42
+ static supportedCoinPathsFromGraph: (inputs: {
43
+ graph: RouterSerializableCompleteGraph;
44
+ maxRouteLength?: number;
45
+ }) => Promise<RouterSupportedCoinPaths>;
46
46
  private getCompleteRoute;
47
47
  private static updateCoinNodesFromPool;
48
48
  private static findRoutes;
@@ -58,6 +58,8 @@ export declare class RouterGraph {
58
58
  private static gasCostForRoutes;
59
59
  private static gasCostForRoute;
60
60
  private static routerCompleteTradeRouteFromCompleteTradeRoute;
61
+ private static extendCoinPathsForHops;
62
+ private static mergeCoinPaths;
61
63
  }
62
64
  export {};
63
65
  //# sourceMappingURL=routerGraph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routerGraph.d.ts","sourceRoot":"","sources":["../../../../../src/packages/router/utils/synchronous/routerGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EACN,OAAO,EACP,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,E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to find synchronous route");
65
65
  const oldRouteIndex = routes.findIndex((route) => JSON.stringify(route.paths.map((path) => path.poolUid)) ===
66
66
  JSON.stringify(cutRoutesAndPools === null || cutRoutesAndPools === void 0 ? void 0 : cutRoutesAndPools.updatedRoute.paths.map((path) => path.poolUid)));
67
67
  let updatedRoutes = helpers_1.Helpers.deepCopy(routes);
@@ -185,44 +185,6 @@ class RouterGraph {
185
185
  this.constants = Object.assign(Object.assign({}, RouterGraph.defaultOptions), options);
186
186
  }
187
187
  /////////////////////////////////////////////////////////////////////
188
- //// Public Static Methods
189
- /////////////////////////////////////////////////////////////////////
190
- /////////////////////////////////////////////////////////////////////
191
- //// Graph Creation
192
- /////////////////////////////////////////////////////////////////////
193
- static createGraph(inputs) {
194
- const poolClasses = inputs.pools.map((pool) => (0, routerPoolInterface_1.createRouterPool)({
195
- pool,
196
- network: "",
197
- }));
198
- const graph = poolClasses.reduce((graph, pool) => {
199
- const coinNodes = this.updateCoinNodesFromPool(graph.coinNodes, pool);
200
- const pools = Object.assign(Object.assign({}, graph.pools), { [pool.uid]: pool.pool });
201
- return {
202
- coinNodes,
203
- pools,
204
- };
205
- }, {
206
- coinNodes: {},
207
- pools: {},
208
- });
209
- return graph;
210
- }
211
- static graphFromSerializable(inputs) {
212
- const pools = Object.entries(inputs.graph.pools).reduce((acc, [uid, pool]) => {
213
- const poolClass = (0, routerPoolInterface_1.createRouterPool)({
214
- pool,
215
- network: inputs.network,
216
- });
217
- return Object.assign(Object.assign({}, acc), { [uid]: poolClass });
218
- }, {});
219
- const graph = {
220
- coinNodes: inputs.graph.coinNodes,
221
- pools,
222
- };
223
- return graph;
224
- }
225
- /////////////////////////////////////////////////////////////////////
226
188
  //// Public Methods
227
189
  /////////////////////////////////////////////////////////////////////
228
190
  getCompleteRouteGivenAmountIn(inputs) {
@@ -245,7 +207,7 @@ class RouterGraph {
245
207
  // );
246
208
  // }
247
209
  getCompleteRoutesGivenAmountIns(inputs) {
248
- return inputs.coinInAmounts.map((coinInAmount) => {
210
+ const completeRoutes = inputs.coinInAmounts.map((coinInAmount) => {
249
211
  try {
250
212
  return this.getCompleteRoute(Object.assign(Object.assign({}, inputs), { coinInAmount, isGivenAmountOut: false }));
251
213
  }
@@ -266,6 +228,47 @@ class RouterGraph {
266
228
  };
267
229
  }
268
230
  });
231
+ return completeRoutes.every((route) => route.routes.length === 0)
232
+ ? []
233
+ : completeRoutes;
234
+ }
235
+ /////////////////////////////////////////////////////////////////////
236
+ //// Public Static Methods
237
+ /////////////////////////////////////////////////////////////////////
238
+ /////////////////////////////////////////////////////////////////////
239
+ //// Graph Creation
240
+ /////////////////////////////////////////////////////////////////////
241
+ static createGraph(inputs) {
242
+ const poolClasses = inputs.pools.map((pool) => (0, routerPoolInterface_1.createRouterPool)({
243
+ pool,
244
+ network: "",
245
+ }));
246
+ const graph = poolClasses.reduce((graph, pool) => {
247
+ const coinNodes = this.updateCoinNodesFromPool(graph.coinNodes, pool);
248
+ const pools = Object.assign(Object.assign({}, graph.pools), { [pool.uid]: pool.pool });
249
+ return {
250
+ coinNodes,
251
+ pools,
252
+ };
253
+ }, {
254
+ coinNodes: {},
255
+ pools: {},
256
+ });
257
+ return graph;
258
+ }
259
+ static graphFromSerializable(inputs) {
260
+ const pools = Object.entries(inputs.graph.pools).reduce((acc, [uid, pool]) => {
261
+ const poolClass = (0, routerPoolInterface_1.createRouterPool)({
262
+ pool,
263
+ network: inputs.network,
264
+ });
265
+ return Object.assign(Object.assign({}, acc), { [uid]: poolClass });
266
+ }, {});
267
+ const graph = {
268
+ coinNodes: inputs.graph.coinNodes,
269
+ pools,
270
+ };
271
+ return graph;
269
272
  }
270
273
  /////////////////////////////////////////////////////////////////////
271
274
  //// Private Methods
@@ -307,8 +310,8 @@ RouterGraph.supportedCoinPathsFromGraph = (inputs) => __awaiter(void 0, void 0,
307
310
  var _b;
308
311
  const nodes = Object.values(inputs.graph.coinNodes);
309
312
  const pools = inputs.graph.pools;
310
- let unHoppableCoinPathsToAdd = [];
311
- const coinPaths = nodes.reduce((acc, node) => {
313
+ let startingUnhoppableCoinPaths = {};
314
+ const startingCoinPaths = nodes.reduce((acc, node) => {
312
315
  const coinIn = node.coin;
313
316
  const coinsOut = Object.entries(node.coinOutThroughPoolEdges)
314
317
  .filter(([coinOut, poolUids]) => {
@@ -316,43 +319,36 @@ RouterGraph.supportedCoinPathsFromGraph = (inputs) => __awaiter(void 0, void 0,
316
319
  pool: pools[uid],
317
320
  network: "",
318
321
  }).noHopsAllowed);
319
- if (unHoppablePoolUids.length > 0)
320
- unHoppableCoinPathsToAdd = [
321
- ...unHoppableCoinPathsToAdd,
322
- {
323
- coinIn,
324
- coinOut,
325
- },
326
- ];
322
+ if (unHoppablePoolUids.length > 0) {
323
+ if (coinIn in startingUnhoppableCoinPaths) {
324
+ startingUnhoppableCoinPaths = Object.assign(Object.assign({}, startingUnhoppableCoinPaths), { [coinIn]: helpers_1.Helpers.uniqueArray([
325
+ ...startingUnhoppableCoinPaths[coinIn],
326
+ coinOut,
327
+ ]) });
328
+ }
329
+ else {
330
+ startingUnhoppableCoinPaths = Object.assign(Object.assign({}, startingUnhoppableCoinPaths), { [coinIn]: [coinOut] });
331
+ }
332
+ }
327
333
  const allPoolsAreUnHoppable = unHoppablePoolUids.length === poolUids.length;
328
334
  return !allPoolsAreUnHoppable;
329
335
  })
330
336
  .map(([key]) => key);
331
337
  return Object.assign(Object.assign({}, acc), { [coinIn]: coinsOut });
332
338
  }, {});
333
- let extendedCoinPaths = helpers_1.Helpers.deepCopy(coinPaths);
334
- for (const _ of Array((_b = inputs.maxRouteLength) !== null && _b !== void 0 ? _b : RouterGraph.defaultOptions.maxRouteLength).fill(0)) {
335
- for (const [coinIn, coinsOut] of Object.entries(coinPaths)) {
336
- let newCoinsOut = [...coinsOut];
337
- for (const coinOut of coinsOut) {
338
- newCoinsOut = [...newCoinsOut, ...coinPaths[coinOut]];
339
- }
340
- extendedCoinPaths[coinIn] = helpers_1.Helpers.uniqueArray([
341
- ...newCoinsOut,
342
- ]).filter((coin) => coin !== coinIn);
343
- }
344
- }
345
- for (const coinPath of unHoppableCoinPathsToAdd) {
346
- if (coinPath.coinIn in extendedCoinPaths) {
347
- extendedCoinPaths = Object.assign(Object.assign({}, extendedCoinPaths), { [coinPath.coinIn]: helpers_1.Helpers.uniqueArray([
348
- ...extendedCoinPaths[coinPath.coinIn],
349
- coinPath.coinOut,
350
- ]) });
351
- continue;
352
- }
353
- extendedCoinPaths = Object.assign(Object.assign({}, extendedCoinPaths), { [coinPath.coinIn]: [coinPath.coinOut] });
354
- }
355
- return extendedCoinPaths;
339
+ const regularCoinPaths = _a.extendCoinPathsForHops({
340
+ startingCoinPaths,
341
+ maxHops: (_b = inputs.maxRouteLength) !== null && _b !== void 0 ? _b : RouterGraph.defaultOptions.maxRouteLength,
342
+ });
343
+ const unhoppableCoinPaths = _a.extendCoinPathsForHops({
344
+ startingCoinPaths: startingUnhoppableCoinPaths,
345
+ maxHops: 1,
346
+ });
347
+ const mergedCoinPaths = _a.mergeCoinPaths({
348
+ coinPaths1: regularCoinPaths,
349
+ coinPaths2: unhoppableCoinPaths,
350
+ });
351
+ return mergedCoinPaths;
356
352
  });
357
353
  /////////////////////////////////////////////////////////////////////
358
354
  //// Private Static Methods
@@ -573,3 +569,43 @@ RouterGraph.routerCompleteTradeRouteFromCompleteTradeRoute = (completeRoute, poo
573
569
  referrer,
574
570
  };
575
571
  };
572
+ /////////////////////////////////////////////////////////////////////
573
+ //// Supported Coins
574
+ /////////////////////////////////////////////////////////////////////
575
+ RouterGraph.extendCoinPathsForHops = (inputs) => {
576
+ const { startingCoinPaths, maxHops } = inputs;
577
+ let extendedCoinPaths = helpers_1.Helpers.deepCopy(startingCoinPaths);
578
+ // account for max possible hops
579
+ for (const _ of Array(maxHops).fill(0)) {
580
+ for (const [coinIn, coinsOut] of Object.entries(startingCoinPaths)) {
581
+ let newCoinsOut = [...coinsOut];
582
+ for (const coinOut of coinsOut) {
583
+ newCoinsOut = [
584
+ ...newCoinsOut,
585
+ ...startingCoinPaths[coinOut],
586
+ ];
587
+ }
588
+ extendedCoinPaths[coinIn] = helpers_1.Helpers.uniqueArray([
589
+ ...newCoinsOut,
590
+ ]).filter((coin) => coin !== coinIn);
591
+ }
592
+ }
593
+ return extendedCoinPaths;
594
+ };
595
+ RouterGraph.mergeCoinPaths = (inputs) => {
596
+ const { coinPaths1, coinPaths2 } = inputs;
597
+ let mergedCoinPaths = helpers_1.Helpers.deepCopy(coinPaths1);
598
+ for (const coinPath of Object.entries(coinPaths2)) {
599
+ const fromCoin = coinPath[0];
600
+ const toCoins = coinPath[1];
601
+ if (fromCoin in mergedCoinPaths) {
602
+ mergedCoinPaths = Object.assign(Object.assign({}, mergedCoinPaths), { [fromCoin]: helpers_1.Helpers.uniqueArray([
603
+ ...mergedCoinPaths[fromCoin],
604
+ ...toCoins,
605
+ ]) });
606
+ continue;
607
+ }
608
+ mergedCoinPaths = Object.assign(Object.assign({}, mergedCoinPaths), { [fromCoin]: toCoins });
609
+ }
610
+ return mergedCoinPaths;
611
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aftermath-ts-sdk",
3
- "version": "0.0.146",
3
+ "version": "0.0.148",
4
4
  "description": "Aftermath TypeScript SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",