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
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var _a;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.CetusApiHelpers = void 0;
13
14
  const sui_js_1 = require("@mysten/sui.js");
@@ -19,7 +20,7 @@ class CetusApiHelpers {
19
20
  //// Constructor
20
21
  /////////////////////////////////////////////////////////////////////
21
22
  constructor(Provider) {
22
- var _a;
23
+ var _b;
23
24
  this.Provider = Provider;
24
25
  /////////////////////////////////////////////////////////////////////
25
26
  //// Public Methods
@@ -29,84 +30,109 @@ class CetusApiHelpers {
29
30
  /////////////////////////////////////////////////////////////////////
30
31
  this.fetchAllPools = () => __awaiter(this, void 0, void 0, function* () {
31
32
  const poolsSimpleInfo = yield this.Provider.DynamicFields().fetchCastAllDynamicFieldsOfType(this.addresses.cetus.objects.poolsTable, (objectIds) => this.Provider.Objects().fetchCastObjectBatch(objectIds, CetusApiHelpers.poolFromSuiObjectResponse), () => true);
32
- return poolsSimpleInfo;
33
+ const poolsMoreInfo = yield this.Provider.Objects().fetchCastObjectBatch(poolsSimpleInfo.map((poolInfo) => poolInfo.id), (data) => {
34
+ const fields = (0, sui_js_1.getObjectFields)(data);
35
+ if (!fields)
36
+ throw new Error("no fields found on cetus pool object");
37
+ const liquidity = BigInt(fields.liquidity);
38
+ const isPaused = fields.is_pause;
39
+ return {
40
+ liquidity,
41
+ isPaused,
42
+ };
43
+ });
44
+ const usablePools = poolsSimpleInfo.filter((_, index) => !poolsMoreInfo[index].isPaused &&
45
+ poolsMoreInfo[index].liquidity > BigInt(0));
46
+ return usablePools;
33
47
  });
34
- this.fetchPoolForCoinTypes = (inputs) => __awaiter(this, void 0, void 0, function* () {
35
- const allPools = yield this.fetchAllPools();
36
- // NOTE: will there ever be more than 1 valid pool (is this unsafe ?)
37
- const foundPool = allPools.find((pool) => CetusApiHelpers.isPoolForCoinTypes(Object.assign({ pool }, inputs)));
38
- if (!foundPool)
39
- throw new Error("no cetus pools found for given coin types");
40
- return foundPool;
48
+ this.fetchPoolsForTrade = (inputs) => __awaiter(this, void 0, void 0, function* () {
49
+ const possiblePools = yield this.fetchPoolsForCoinType({
50
+ coinType: inputs.coinOutType,
51
+ });
52
+ const [exactMatchPools, partialMatchPools] = utils_1.Helpers.bifilter(possiblePools, (pool) => CetusApiHelpers.isPoolForCoinTypes({
53
+ pool,
54
+ coinType1: inputs.coinInType,
55
+ coinType2: inputs.coinOutType,
56
+ }));
57
+ return {
58
+ exactMatchPools,
59
+ partialMatchPools,
60
+ };
41
61
  });
42
62
  /////////////////////////////////////////////////////////////////////
43
63
  //// Transaction Commands
44
64
  /////////////////////////////////////////////////////////////////////
45
65
  this.tradeCoinAToCoinBTx = (inputs) => {
46
66
  const { tx, coinInId } = inputs;
67
+ const isGivenAmountIn = "coinInAmount" in inputs;
47
68
  return tx.moveCall({
48
- target: utils_1.Helpers.transactions.createTransactionTarget(this.addresses.cetus.packages.scripts, CetusApiHelpers.constants.moduleNames.poolScript, "swap_a2b"),
69
+ target: utils_1.Helpers.transactions.createTransactionTarget(this.addresses.cetus.packages.wrapper, CetusApiHelpers.constants.moduleNames.wrapper, isGivenAmountIn ? "swap_a_to_b_by_a" : "swap_a_to_b_by_b"),
49
70
  typeArguments: [inputs.coinInType, inputs.coinOutType],
50
71
  arguments: [
51
72
  tx.object(this.addresses.cetus.objects.globalConfig),
52
73
  tx.object(inputs.poolObjectId),
53
- tx.makeMoveVec({
54
- objects: [
55
- typeof coinInId === "string"
56
- ? tx.object(coinInId)
57
- : coinInId,
58
- ],
59
- }),
60
- tx.pure("coinInAmount" in inputs, "bool"),
61
- tx.pure("coinInAmount" in inputs
62
- ? inputs.coinInAmount
63
- : inputs.coinOutAmount, "u64"),
64
- tx.pure(
65
- // "coinInAmount" in inputs
66
- // ? inputs.coinInAmount
67
- // : inputs.coinOutAmount,
68
- "0", "u64"),
69
- tx.pure(BigInt("4295048016"), "u128"),
74
+ typeof coinInId === "string" ? tx.object(coinInId) : coinInId,
75
+ ...(isGivenAmountIn
76
+ ? []
77
+ : [tx.pure(inputs.coinOutAmount, "u64")]),
78
+ tx.pure(CetusApiHelpers.constants.inputs.minSqrtPriceLimit, "u128"),
70
79
  tx.object(sui_1.Sui.constants.addresses.suiClockId),
80
+ tx.object(this.addresses.pools.objects.protocolFeeVault),
81
+ tx.object(this.addresses.pools.objects.treasury),
82
+ tx.object(this.addresses.pools.objects.insuranceFund),
83
+ tx.object(this.addresses.referralVault.objects.referralVault),
71
84
  ],
72
85
  });
73
86
  };
74
87
  this.tradeCoinBToCoinATx = (inputs) => {
75
88
  const { tx, coinInId } = inputs;
89
+ const isGivenAmountIn = "coinInAmount" in inputs;
76
90
  return tx.moveCall({
77
- target: utils_1.Helpers.transactions.createTransactionTarget(this.addresses.cetus.packages.scripts, CetusApiHelpers.constants.moduleNames.poolScript, "swap_b2a"),
91
+ target: utils_1.Helpers.transactions.createTransactionTarget(this.addresses.cetus.packages.wrapper, CetusApiHelpers.constants.moduleNames.wrapper, isGivenAmountIn ? "swap_b_to_a_by_b" : "swap_b_to_a_by_a"),
78
92
  typeArguments: [inputs.coinOutType, inputs.coinInType],
79
93
  arguments: [
80
94
  tx.object(this.addresses.cetus.objects.globalConfig),
81
95
  tx.object(inputs.poolObjectId),
82
- tx.makeMoveVec({
83
- objects: [
84
- typeof coinInId === "string"
85
- ? tx.object(coinInId)
86
- : coinInId,
87
- ],
88
- }),
89
- tx.pure("coinInAmount" in inputs, "bool"),
90
- tx.pure("coinInAmount" in inputs
91
- ? inputs.coinInAmount
92
- : inputs.coinOutAmount, "u64"),
93
- tx.pure(
94
- // "coinInAmount" in inputs
95
- // ? inputs.coinInAmount
96
- // : inputs.coinOutAmount,
97
- "0", "u64"),
98
- tx.pure(BigInt("79226673515401279992447579055"), "u128"),
96
+ typeof coinInId === "string" ? tx.object(coinInId) : coinInId,
97
+ ...(isGivenAmountIn
98
+ ? []
99
+ : [tx.pure(inputs.coinOutAmount, "u64")]),
100
+ tx.pure(CetusApiHelpers.constants.inputs.maxSqrtPriceLimit, "u128"),
99
101
  tx.object(sui_1.Sui.constants.addresses.suiClockId),
102
+ tx.object(this.addresses.pools.objects.protocolFeeVault),
103
+ tx.object(this.addresses.pools.objects.treasury),
104
+ tx.object(this.addresses.pools.objects.insuranceFund),
105
+ tx.object(this.addresses.referralVault.objects.referralVault),
100
106
  ],
101
107
  });
102
108
  };
103
109
  this.tradeTx = (inputs) => {
104
110
  const { coinInType, pool } = inputs;
105
111
  const commandInputs = Object.assign(Object.assign({}, inputs), { poolObjectId: pool.id });
106
- if (CetusApiHelpers.isCoinA(coinInType, pool))
112
+ if (CetusApiHelpers.isCoinA({ pool, coinType: coinInType }))
107
113
  return this.tradeCoinAToCoinBTx(commandInputs);
108
114
  return this.tradeCoinBToCoinATx(commandInputs);
109
115
  };
116
+ this.flashTradeTx = (inputs) => {
117
+ const { tx } = inputs;
118
+ const isCoinAToCoinB = inputs.coinInType === inputs.coinTypeA;
119
+ const sqrtPriceLimit = isCoinAToCoinB
120
+ ? CetusApiHelpers.constants.inputs.minSqrtPriceLimit
121
+ : CetusApiHelpers.constants.inputs.maxSqrtPriceLimit;
122
+ return tx.moveCall({
123
+ target: utils_1.Helpers.transactions.createTransactionTarget(this.addresses.cetus.packages.clmm, CetusApiHelpers.constants.moduleNames.pool, "flash_swap"),
124
+ typeArguments: [inputs.coinTypeA, inputs.coinTypeB],
125
+ arguments: [
126
+ tx.object(inputs.poolObjectId),
127
+ tx.pure(isCoinAToCoinB, "bool"),
128
+ tx.pure("coinInAmount" in inputs, "bool"),
129
+ tx.pure("coinInAmount" in inputs
130
+ ? inputs.coinInAmount
131
+ : inputs.coinOutAmount, "u64"),
132
+ tx.pure(sqrtPriceLimit, "u128"), // sqrt_price_limit
133
+ ],
134
+ });
135
+ };
110
136
  /////////////////////////////////////////////////////////////////////
111
137
  //// Transaction Inspection Commands
112
138
  /////////////////////////////////////////////////////////////////////
@@ -175,7 +201,26 @@ class CetusApiHelpers {
175
201
  feeRate: BigInt(data.fee_rate),
176
202
  };
177
203
  });
178
- const cetus = (_a = this.Provider.addresses.externalRouter) === null || _a === void 0 ? void 0 : _a.cetus;
204
+ /////////////////////////////////////////////////////////////////////
205
+ //// Private Methods
206
+ /////////////////////////////////////////////////////////////////////
207
+ /////////////////////////////////////////////////////////////////////
208
+ //// Objects
209
+ /////////////////////////////////////////////////////////////////////
210
+ this.fetchPoolForCoinTypes = (inputs) => __awaiter(this, void 0, void 0, function* () {
211
+ const allPools = yield this.fetchAllPools();
212
+ // NOTE: will there ever be more than 1 valid pool (is this unsafe ?)
213
+ const foundPool = allPools.find((pool) => CetusApiHelpers.isPoolForCoinTypes(Object.assign({ pool }, inputs)));
214
+ if (!foundPool)
215
+ throw new Error("no cetus pools found for given coin types");
216
+ return foundPool;
217
+ });
218
+ this.fetchPoolsForCoinType = (inputs) => __awaiter(this, void 0, void 0, function* () {
219
+ const allPools = yield this.fetchAllPools();
220
+ const foundPools = allPools.filter((pool) => CetusApiHelpers.isPoolForCoinType(Object.assign({ pool }, inputs)));
221
+ return foundPools;
222
+ });
223
+ const cetus = (_b = this.Provider.addresses.externalRouter) === null || _b === void 0 ? void 0 : _b.cetus;
179
224
  const pools = this.Provider.addresses.pools;
180
225
  const referralVault = this.Provider.addresses.referralVault;
181
226
  if (!cetus || !pools || !referralVault)
@@ -192,6 +237,7 @@ class CetusApiHelpers {
192
237
  }
193
238
  }
194
239
  exports.CetusApiHelpers = CetusApiHelpers;
240
+ _a = CetusApiHelpers;
195
241
  /////////////////////////////////////////////////////////////////////
196
242
  //// Constants
197
243
  /////////////////////////////////////////////////////////////////////
@@ -199,17 +245,33 @@ CetusApiHelpers.constants = {
199
245
  moduleNames: {
200
246
  poolScript: "pool_script",
201
247
  pool: "pool",
248
+ wrapper: "cetus",
249
+ },
250
+ inputs: {
251
+ minSqrtPriceLimit: BigInt("4295048016"),
252
+ maxSqrtPriceLimit: BigInt("79226673515401279992447579055"),
202
253
  },
203
254
  };
204
255
  /////////////////////////////////////////////////////////////////////
256
+ //// Public Static Methods
257
+ /////////////////////////////////////////////////////////////////////
258
+ /////////////////////////////////////////////////////////////////////
259
+ //// Helpers
260
+ /////////////////////////////////////////////////////////////////////
261
+ CetusApiHelpers.otherCoinInPool = (inputs) => {
262
+ return _a.isCoinA(inputs)
263
+ ? inputs.pool.coinTypeB
264
+ : inputs.pool.coinTypeA;
265
+ };
266
+ /////////////////////////////////////////////////////////////////////
205
267
  //// Private Static Methods
206
268
  /////////////////////////////////////////////////////////////////////
207
269
  /////////////////////////////////////////////////////////////////////
208
270
  //// Casting
209
271
  /////////////////////////////////////////////////////////////////////
210
272
  CetusApiHelpers.poolFromSuiObjectResponse = (data) => {
211
- var _a;
212
- const content = (_a = data.data) === null || _a === void 0 ? void 0 : _a.content;
273
+ var _b;
274
+ const content = (_b = data.data) === null || _b === void 0 ? void 0 : _b.content;
213
275
  if ((content === null || content === void 0 ? void 0 : content.dataType) !== "moveObject")
214
276
  throw new Error("sui object response is not an object");
215
277
  const fields = content.fields.value.fields.value.fields;
@@ -229,4 +291,12 @@ CetusApiHelpers.isPoolForCoinTypes = (inputs) => {
229
291
  (pool.coinTypeA === utils_1.Helpers.addLeadingZeroesToType(coinType2) &&
230
292
  pool.coinTypeB === utils_1.Helpers.addLeadingZeroesToType(coinType1)));
231
293
  };
232
- CetusApiHelpers.isCoinA = (coin, pool) => utils_1.Helpers.addLeadingZeroesToType(coin) === pool.coinTypeA;
294
+ CetusApiHelpers.isPoolForCoinType = (inputs) => {
295
+ const { pool, coinType } = inputs;
296
+ return (pool.coinTypeA === utils_1.Helpers.addLeadingZeroesToType(coinType) ||
297
+ pool.coinTypeB === utils_1.Helpers.addLeadingZeroesToType(coinType));
298
+ };
299
+ CetusApiHelpers.isCoinA = (inputs) => {
300
+ const { coinType, pool } = inputs;
301
+ return utils_1.Helpers.addLeadingZeroesToType(coinType) === pool.coinTypeA;
302
+ };
@@ -9,11 +9,14 @@ export declare class TurbosApi implements RouterApiInterface<TurbosPoolObject> {
9
9
  private readonly Provider;
10
10
  readonly Helpers: TurbosApiHelpers;
11
11
  constructor(Provider: AftermathApi);
12
- fetchPoolForCoinTypes: (inputs: {
13
- coinType1: CoinType;
14
- coinType2: CoinType;
15
- }) => Promise<TurbosPoolObject>;
16
12
  fetchAllPools: () => Promise<TurbosPoolObject[]>;
13
+ fetchPoolsForTrade: (inputs: {
14
+ coinInType: CoinType;
15
+ coinOutType: CoinType;
16
+ }) => Promise<{
17
+ partialMatchPools: TurbosPoolObject[];
18
+ exactMatchPools: TurbosPoolObject[];
19
+ }>;
17
20
  fetchSupportedCoins: () => Promise<string[]>;
18
21
  fetchTradeAmountOut: (inputs: {
19
22
  walletAddress: SuiAddress;
@@ -22,6 +25,10 @@ export declare class TurbosApi implements RouterApiInterface<TurbosPoolObject> {
22
25
  coinOutType: CoinType;
23
26
  coinInAmount: Balance;
24
27
  }) => Promise<Balance>;
28
+ otherCoinInPool: (inputs: {
29
+ coinType: CoinType;
30
+ pool: TurbosPoolObject;
31
+ }) => string;
25
32
  fetchTradeTx: (inputs: {
26
33
  walletAddress: SuiAddress;
27
34
  pool: TurbosPoolObject;
@@ -1 +1 @@
1
- {"version":3,"file":"turbosApi.d.ts","sourceRoot":"","sources":["../../../../src/packages/external/turbos/turbosApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAA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A8D,CAAC;AAElG,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,qBAAa,SAAU,YAAW,kBAAkB,CAAC,gBAAgB,CAAC;IAWzD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IANrC,SAAgB,OAAO,mBAAC;gBAMK,QAAQ,EAAE,YAAY;IAa5C,aAAa,oCAGlB;IAEK,kBAAkB,WAAY;QACpC,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;KACtB,KAAG,QAAQ;QACX,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;QACtC,eAAe,EAAE,gBAAgB,EAAE,CAAC;KACpC,CAAC,CAEA;IAMK,mBAAmB,0BAQxB;IAEK,mBAAmB,WAAkB;QAC3C,aAAa,EAAE,UAAU,CAAC;QAC1B,IAAI,EAAE,gBAAgB,CAAC;QACvB,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;QACtB,YAAY,EAAE,OAAO,CAAC;KACtB,KAAG,QAAQ,OAAO,CAAC,CAGlB;IAEK,eAAe,WAAY;QACjC,QAAQ,EAAE,QAAQ,CAAC;QACnB,IAAI,EAAE,gBAAgB,CAAC;KACvB,YAEC;IAMK,YAAY,WAAY;QAC9B,aAAa,EAAE,UAAU,CAAC;QAC1B,IAAI,EAAE,gBAAgB,CAAC;QACvB,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;QACtB,YAAY,EAAE,OAAO,CAAC;KACtB,KAAG,QAAQ,qBAAqB,CAAC,CAIhC;CACF"}
@@ -24,25 +24,28 @@ class TurbosApi {
24
24
  /////////////////////////////////////////////////////////////////////
25
25
  //// Objects
26
26
  /////////////////////////////////////////////////////////////////////
27
- this.fetchPoolForCoinTypes = (inputs) => __awaiter(this, void 0, void 0, function* () {
28
- return this.Helpers.fetchPoolForCoinTypes(inputs);
29
- });
30
27
  this.fetchAllPools = () => __awaiter(this, void 0, void 0, function* () {
31
28
  const pools = yield this.Helpers.fetchAllPools();
32
29
  return pools;
33
30
  });
31
+ this.fetchPoolsForTrade = (inputs) => {
32
+ return this.Helpers.fetchPoolsForTrade(inputs);
33
+ };
34
+ /////////////////////////////////////////////////////////////////////
35
+ //// Inspections
36
+ /////////////////////////////////////////////////////////////////////
34
37
  this.fetchSupportedCoins = () => __awaiter(this, void 0, void 0, function* () {
35
38
  const pools = yield this.Helpers.fetchAllPools();
36
39
  const allCoins = pools.reduce((acc, pool) => [...acc, pool.coinTypeA, pool.coinTypeB], []);
37
40
  return utils_1.Helpers.uniqueArray(allCoins);
38
41
  });
39
- /////////////////////////////////////////////////////////////////////
40
- //// Inspections
41
- /////////////////////////////////////////////////////////////////////
42
42
  this.fetchTradeAmountOut = (inputs) => __awaiter(this, void 0, void 0, function* () {
43
43
  const tradeResult = yield this.Helpers.fetchCalcTradeResult(inputs);
44
44
  return tradeResult.amountOut;
45
45
  });
46
+ this.otherCoinInPool = (inputs) => {
47
+ return turbosApiHelpers_1.TurbosApiHelpers.otherCoinInPool(inputs);
48
+ };
46
49
  /////////////////////////////////////////////////////////////////////
47
50
  //// Transactions
48
51
  /////////////////////////////////////////////////////////////////////
@@ -12,10 +12,13 @@ export declare class TurbosApiHelpers {
12
12
  };
13
13
  constructor(Provider: AftermathApi);
14
14
  fetchAllPools: () => Promise<TurbosPoolObject[]>;
15
- fetchPoolForCoinTypes: (inputs: {
16
- coinType1: CoinType;
17
- coinType2: CoinType;
18
- }) => Promise<TurbosPoolObject>;
15
+ fetchPoolsForTrade: (inputs: {
16
+ coinInType: CoinType;
17
+ coinOutType: CoinType;
18
+ }) => Promise<{
19
+ partialMatchPools: TurbosPoolObject[];
20
+ exactMatchPools: TurbosPoolObject[];
21
+ }>;
19
22
  tradeCoinAToCoinBTx: (inputs: {
20
23
  tx: TransactionBlock;
21
24
  poolObjectId: ObjectId;
@@ -184,8 +187,15 @@ export declare class TurbosApiHelpers {
184
187
  coinOutType: CoinType;
185
188
  coinInAmount: Balance;
186
189
  }) => Promise<TurbosCalcTradeResult>;
190
+ static otherCoinInPool: (inputs: {
191
+ coinType: CoinType;
192
+ pool: TurbosPoolObject;
193
+ }) => string;
194
+ private fetchPoolForCoinTypes;
195
+ private fetchPoolsForCoinType;
187
196
  private static partialPoolFromSuiObjectResponse;
188
197
  private static isPoolForCoinTypes;
198
+ private static isPoolForCoinType;
189
199
  private static isCoinA;
190
200
  private static calcSqrtPriceLimit;
191
201
  }
@@ -1 +1 @@
1
- {"version":3,"file":"turbosApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/packages/external/turbos/turbosApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,UAAU,EAEV,mBAAmB,EACnB,gBAAgB,EAGhB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACN,OAAO,EACP,eAAe,EACf,QAAQ,EACR,cAAc,EACd,sBAAsB,EAEtB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGxE,qBAAa,gBAAgB;aA8BA,QAAQ,EAAE,YAAY;IAzBlD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAK/B;IAMF,SAAgB,SAAS,EAAE;QAC1B,MAAM,EAAE,eAAe,CAAC;QACxB,KAAK,EAAE,cAAc,CAAC;QACtB,aAAa,EAAE,sBAAsB,CAAC;KACtC,CAAC;gBAU0B,QAAQ,EAAE,YAAY;IA8B3C,aAAa,QAAa,QAAQ,gBAAgB,EAAE,CAAC,CA6B1D;IAEK,qBAAqB,WAAkB;QAC7C,SAAS,EAAE,QAAQ,CAAC;QACpB,SAAS,EAAE,QAAQ,CAAC;KACpB,+BAeC;IAMK,mBAAmB,WAAY;QACrC,EAAE,EAAE,gBAAgB,CAAC;QACrB,YAAY,EAAE,QAAQ,CAAC;QACvB,QAAQ,EAA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pB;IAEF,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAY/B;CACF"}
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var _a;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.TurbosApiHelpers = void 0;
13
14
  const sui_js_1 = require("@mysten/sui.js");
@@ -22,7 +23,7 @@ class TurbosApiHelpers {
22
23
  //// Constructor
23
24
  /////////////////////////////////////////////////////////////////////
24
25
  constructor(Provider) {
25
- var _a;
26
+ var _b;
26
27
  this.Provider = Provider;
27
28
  /////////////////////////////////////////////////////////////////////
28
29
  //// Public Methods
@@ -32,23 +33,39 @@ class TurbosApiHelpers {
32
33
  /////////////////////////////////////////////////////////////////////
33
34
  this.fetchAllPools = () => __awaiter(this, void 0, void 0, function* () {
34
35
  const poolsSimpleInfo = yield this.Provider.DynamicFields().fetchCastAllDynamicFieldsOfType(this.addresses.turbos.objects.poolsTable, (objectIds) => this.Provider.Objects().fetchCastObjectBatch(objectIds, TurbosApiHelpers.partialPoolFromSuiObjectResponse), () => true);
35
- const sqrtPrices = yield this.Provider.Objects().fetchCastObjectBatch(poolsSimpleInfo.map((poolInfo) => poolInfo.id), (data) => {
36
- var _a;
37
- const sqrtPrice = (_a = (0, sui_js_1.getObjectFields)(data)) === null || _a === void 0 ? void 0 : _a.sqrt_price;
38
- return BigInt(sqrtPrice);
36
+ const poolsMoreInfo = yield this.Provider.Objects().fetchCastObjectBatch(poolsSimpleInfo.map((poolInfo) => poolInfo.id), (data) => {
37
+ const fields = (0, sui_js_1.getObjectFields)(data);
38
+ if (!fields)
39
+ throw new Error("no fields found on turbos pool object");
40
+ const sqrtPrice = BigInt(fields.sqrt_price);
41
+ const liquidity = BigInt(fields.liquidity);
42
+ const isUnlocked = fields.unlocked;
43
+ return {
44
+ liquidity,
45
+ isUnlocked,
46
+ sqrtPrice,
47
+ };
39
48
  });
40
- const pools = poolsSimpleInfo.map((info, index) => {
41
- return Object.assign(Object.assign({}, info), { sqrtPrice: sqrtPrices[index] });
49
+ const completePools = poolsSimpleInfo.map((info, index) => {
50
+ return Object.assign(Object.assign({}, info), { sqrtPrice: poolsMoreInfo[index].sqrtPrice });
42
51
  });
43
- return pools;
52
+ const usablePools = completePools.filter((_, index) => poolsMoreInfo[index].isUnlocked &&
53
+ poolsMoreInfo[index].liquidity > BigInt(0));
54
+ return usablePools;
44
55
  });
45
- this.fetchPoolForCoinTypes = (inputs) => __awaiter(this, void 0, void 0, function* () {
46
- const allPools = yield this.fetchAllPools();
47
- // NOTE: will there ever be more than 1 valid pool (is this unsafe ?)
48
- const foundPool = allPools.find((pool) => TurbosApiHelpers.isPoolForCoinTypes(Object.assign({ pool }, inputs)));
49
- if (!foundPool)
50
- throw new Error("no turbos pools found for given coin types");
51
- return foundPool;
56
+ this.fetchPoolsForTrade = (inputs) => __awaiter(this, void 0, void 0, function* () {
57
+ const possiblePools = yield this.fetchPoolsForCoinType({
58
+ coinType: inputs.coinOutType,
59
+ });
60
+ const [exactMatchPools, partialMatchPools] = utils_1.Helpers.bifilter(possiblePools, (pool) => TurbosApiHelpers.isPoolForCoinTypes({
61
+ pool,
62
+ coinType1: inputs.coinInType,
63
+ coinType2: inputs.coinOutType,
64
+ }));
65
+ return {
66
+ exactMatchPools,
67
+ partialMatchPools,
68
+ };
52
69
  });
53
70
  /////////////////////////////////////////////////////////////////////
54
71
  //// Transaction Commands
@@ -114,7 +131,7 @@ class TurbosApiHelpers {
114
131
  this.tradeTx = (inputs) => {
115
132
  const { coinInType, pool } = inputs;
116
133
  const commandInputs = Object.assign(Object.assign(Object.assign({}, inputs), pool), { poolObjectId: pool.id });
117
- if (TurbosApiHelpers.isCoinA(coinInType, pool))
134
+ if (TurbosApiHelpers.isCoinA({ pool, coinType: coinInType }))
118
135
  return this.tradeCoinAToCoinBTx(commandInputs);
119
136
  return this.tradeCoinBToCoinATx(commandInputs);
120
137
  };
@@ -198,7 +215,26 @@ class TurbosApiHelpers {
198
215
  throw new Error("e");
199
216
  }
200
217
  });
201
- const turbos = (_a = this.Provider.addresses.externalRouter) === null || _a === void 0 ? void 0 : _a.turbos;
218
+ /////////////////////////////////////////////////////////////////////
219
+ //// Private Methods
220
+ /////////////////////////////////////////////////////////////////////
221
+ /////////////////////////////////////////////////////////////////////
222
+ //// Objects
223
+ /////////////////////////////////////////////////////////////////////
224
+ this.fetchPoolForCoinTypes = (inputs) => __awaiter(this, void 0, void 0, function* () {
225
+ const allPools = yield this.fetchAllPools();
226
+ // NOTE: will there ever be more than 1 valid pool (is this unsafe ?)
227
+ const foundPool = allPools.find((pool) => TurbosApiHelpers.isPoolForCoinTypes(Object.assign({ pool }, inputs)));
228
+ if (!foundPool)
229
+ throw new Error("no turbos pools found for given coin types");
230
+ return foundPool;
231
+ });
232
+ this.fetchPoolsForCoinType = (inputs) => __awaiter(this, void 0, void 0, function* () {
233
+ const allPools = yield this.fetchAllPools();
234
+ const foundPools = allPools.filter((pool) => TurbosApiHelpers.isPoolForCoinType(Object.assign({ pool }, inputs)));
235
+ return foundPools;
236
+ });
237
+ const turbos = (_b = this.Provider.addresses.externalRouter) === null || _b === void 0 ? void 0 : _b.turbos;
202
238
  const pools = this.Provider.addresses.pools;
203
239
  const referralVault = this.Provider.addresses.referralVault;
204
240
  if (!turbos || !pools || !referralVault)
@@ -215,6 +251,7 @@ class TurbosApiHelpers {
215
251
  }
216
252
  }
217
253
  exports.TurbosApiHelpers = TurbosApiHelpers;
254
+ _a = TurbosApiHelpers;
218
255
  /////////////////////////////////////////////////////////////////////
219
256
  //// Constants
220
257
  /////////////////////////////////////////////////////////////////////
@@ -225,14 +262,25 @@ TurbosApiHelpers.constants = {
225
262
  },
226
263
  };
227
264
  /////////////////////////////////////////////////////////////////////
265
+ //// Public Static Methods
266
+ /////////////////////////////////////////////////////////////////////
267
+ /////////////////////////////////////////////////////////////////////
268
+ //// Helpers
269
+ /////////////////////////////////////////////////////////////////////
270
+ TurbosApiHelpers.otherCoinInPool = (inputs) => {
271
+ return _a.isCoinA(inputs)
272
+ ? inputs.pool.coinTypeB
273
+ : inputs.pool.coinTypeA;
274
+ };
275
+ /////////////////////////////////////////////////////////////////////
228
276
  //// Private Static Methods
229
277
  /////////////////////////////////////////////////////////////////////
230
278
  /////////////////////////////////////////////////////////////////////
231
279
  //// Casting
232
280
  /////////////////////////////////////////////////////////////////////
233
281
  TurbosApiHelpers.partialPoolFromSuiObjectResponse = (data) => {
234
- var _a;
235
- const content = (_a = data.data) === null || _a === void 0 ? void 0 : _a.content;
282
+ var _b;
283
+ const content = (_b = data.data) === null || _b === void 0 ? void 0 : _b.content;
236
284
  if ((content === null || content === void 0 ? void 0 : content.dataType) !== "moveObject")
237
285
  throw new Error("sui object response is not an object");
238
286
  const fields = content.fields.value.fields;
@@ -254,7 +302,15 @@ TurbosApiHelpers.isPoolForCoinTypes = (inputs) => {
254
302
  (pool.coinTypeA === utils_1.Helpers.addLeadingZeroesToType(coinType2) &&
255
303
  pool.coinTypeB === utils_1.Helpers.addLeadingZeroesToType(coinType1)));
256
304
  };
257
- TurbosApiHelpers.isCoinA = (coin, pool) => utils_1.Helpers.addLeadingZeroesToType(coin) === pool.coinTypeA;
305
+ TurbosApiHelpers.isPoolForCoinType = (inputs) => {
306
+ const { pool, coinType } = inputs;
307
+ return (pool.coinTypeA === utils_1.Helpers.addLeadingZeroesToType(coinType) ||
308
+ pool.coinTypeB === utils_1.Helpers.addLeadingZeroesToType(coinType));
309
+ };
310
+ TurbosApiHelpers.isCoinA = (inputs) => {
311
+ const { coinType, pool } = inputs;
312
+ return utils_1.Helpers.addLeadingZeroesToType(coinType) === pool.coinTypeA;
313
+ };
258
314
  TurbosApiHelpers.calcSqrtPriceLimit = (inputs) => {
259
315
  const { sqrtPrice, isCoinAToCoinB } = inputs;
260
316
  const change = sqrtPrice / BigInt(100);
@@ -1,18 +1,16 @@
1
1
  import { AftermathApi } from "../../../general/providers/aftermathApi";
2
- import { RouterSynchronousApiHelpers } from "./routerSynchronousApiHelpers";
3
2
  import { Balance, CoinType, RouterExternalFee, RouterCompleteTradeRoute, SerializedTransaction, Slippage, SuiNetwork, Url, RouterSerializableCompleteGraph, RouterProtocolName } from "../../../types";
4
3
  import { SuiAddress } from "@mysten/sui.js";
5
4
  import { NojoAmmApi } from "../../external/nojo/nojoAmmApi";
6
5
  import { DeepBookApi } from "../../external/deepBook/deepBookApi";
7
6
  import { PoolsApi } from "../../pools/api/poolsApi";
8
7
  import { CetusApi } from "../../external/cetus/cetusApi";
9
- import { RouterAsyncApiHelpers } from "./routerAsyncApiHelpers";
10
8
  import { TurbosApi } from "../../external/turbos/turbosApi";
9
+ import { RouterApiHelpers } from "./routerApiHelpers";
11
10
  export declare class RouterApi {
12
11
  private readonly Provider;
13
12
  readonly protocols: RouterProtocolName[];
14
- readonly Helpers: RouterSynchronousApiHelpers;
15
- readonly AsyncHelpers: RouterAsyncApiHelpers;
13
+ readonly Helpers: RouterApiHelpers;
16
14
  constructor(Provider: AftermathApi, protocols?: RouterProtocolName[]);
17
15
  Aftermath: () => PoolsApi;
18
16
  Nojo: () => NojoAmmApi;
@@ -1 +1 @@
1
- {"version":3,"file":"routerApi.d.ts","sourceRoot":"","sources":["../../../../src/packages/router/api/routerApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EACN,OAAO,EACP,QAAQ,EACR,iBAAiB,EACjB,wBAAwB,EACxB,qBAAqB,EACrB,QAAQ,EACR,UAAU,EACV,GAAG,EACH,+BAA+B,EAC/B,kBAAkB,EAElB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,E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