aftermath-ts-sdk 0.0.145 → 0.0.147
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.
- package/dist/general/api/objectsApiHelpers.d.ts +1 -0
- package/dist/general/api/objectsApiHelpers.d.ts.map +1 -1
- package/dist/general/api/objectsApiHelpers.js +20 -2
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts +1 -0
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts.map +1 -1
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +23 -4
- package/dist/general/utils/helpers.d.ts +1 -0
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +8 -0
- package/dist/packages/external/cetus/cetusApi.d.ts +11 -4
- package/dist/packages/external/cetus/cetusApi.d.ts.map +1 -1
- package/dist/packages/external/cetus/cetusApi.js +9 -6
- package/dist/packages/external/cetus/cetusApiHelpers.d.ts +54 -4
- package/dist/packages/external/cetus/cetusApiHelpers.d.ts.map +1 -1
- package/dist/packages/external/cetus/cetusApiHelpers.js +120 -50
- package/dist/packages/external/turbos/turbosApi.d.ts +11 -4
- package/dist/packages/external/turbos/turbosApi.d.ts.map +1 -1
- package/dist/packages/external/turbos/turbosApi.js +9 -6
- package/dist/packages/external/turbos/turbosApiHelpers.d.ts +14 -4
- package/dist/packages/external/turbos/turbosApiHelpers.d.ts.map +1 -1
- package/dist/packages/external/turbos/turbosApiHelpers.js +76 -20
- package/dist/packages/router/api/routerApi.d.ts +2 -4
- package/dist/packages/router/api/routerApi.d.ts.map +1 -1
- package/dist/packages/router/api/routerApi.js +5 -25
- package/dist/packages/router/api/routerApiHelpers.d.ts +41 -0
- package/dist/packages/router/api/routerApiHelpers.d.ts.map +1 -0
- package/dist/packages/router/api/routerApiHelpers.js +191 -0
- package/dist/packages/router/api/routerAsyncApiHelpers.d.ts +15 -4
- package/dist/packages/router/api/routerAsyncApiHelpers.d.ts.map +1 -1
- package/dist/packages/router/api/routerAsyncApiHelpers.js +42 -9
- package/dist/packages/router/api/routerSynchronousApiHelpers.d.ts +1 -10
- package/dist/packages/router/api/routerSynchronousApiHelpers.d.ts.map +1 -1
- package/dist/packages/router/api/routerSynchronousApiHelpers.js +5 -25
- package/dist/packages/router/routerTypes.d.ts.map +1 -1
- package/dist/packages/router/utils/async/routerAsyncApiInterface.d.ts +13 -6
- package/dist/packages/router/utils/async/routerAsyncApiInterface.d.ts.map +1 -1
- package/dist/packages/router/utils/async/routerAsyncGraph.d.ts +4 -2
- package/dist/packages/router/utils/async/routerAsyncGraph.d.ts.map +1 -1
- package/dist/packages/router/utils/async/routerAsyncGraph.js +34 -34
- package/dist/packages/router/utils/synchronous/routerGraph.d.ts +13 -11
- package/dist/packages/router/utils/synchronous/routerGraph.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerGraph.js +109 -73
- package/package.json +2 -2
|
@@ -0,0 +1,191 @@
|
|
|
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.RouterApiHelpers = void 0;
|
|
13
|
+
const types_1 = require("../../../types");
|
|
14
|
+
const routerGraph_1 = require("../utils/synchronous/routerGraph");
|
|
15
|
+
const routerAsyncApiHelpers_1 = require("./routerAsyncApiHelpers");
|
|
16
|
+
const routerSynchronousApiHelpers_1 = require("./routerSynchronousApiHelpers");
|
|
17
|
+
const routerAsyncGraph_1 = require("../utils/async/routerAsyncGraph");
|
|
18
|
+
class RouterApiHelpers {
|
|
19
|
+
/////////////////////////////////////////////////////////////////////
|
|
20
|
+
//// Constructor
|
|
21
|
+
/////////////////////////////////////////////////////////////////////
|
|
22
|
+
constructor(Provider) {
|
|
23
|
+
this.Provider = Provider;
|
|
24
|
+
/////////////////////////////////////////////////////////////////////
|
|
25
|
+
//// Public Methods
|
|
26
|
+
/////////////////////////////////////////////////////////////////////
|
|
27
|
+
/////////////////////////////////////////////////////////////////////
|
|
28
|
+
//// Graph
|
|
29
|
+
/////////////////////////////////////////////////////////////////////
|
|
30
|
+
this.fetchSerializableGraph = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const pools = yield this.SynchronousHelpers.fetchAllPools(inputs);
|
|
32
|
+
return routerGraph_1.RouterGraph.createGraph({ pools });
|
|
33
|
+
});
|
|
34
|
+
/////////////////////////////////////////////////////////////////////
|
|
35
|
+
//// Routing
|
|
36
|
+
/////////////////////////////////////////////////////////////////////
|
|
37
|
+
this.fetchCompleteTradeRouteGivenAmountIn = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
if (inputs.protocols.length === 0)
|
|
39
|
+
throw new Error("no protocols set in constructor");
|
|
40
|
+
const { network, graph, coinInAmount } = inputs;
|
|
41
|
+
const coinInAmounts = RouterApiHelpers.amountsInForRouterTrade({
|
|
42
|
+
coinInAmount,
|
|
43
|
+
});
|
|
44
|
+
const asyncProtocols = inputs.protocols.filter(types_1.isRouterAsyncProtocolName);
|
|
45
|
+
const { exactMatchPools, partialMatchPools } = yield this.AsyncHelpers.fetchPossiblePools(Object.assign(Object.assign({}, inputs), { protocols: asyncProtocols }));
|
|
46
|
+
const routerGraph = new routerGraph_1.RouterGraph(network, graph);
|
|
47
|
+
if (exactMatchPools.length <= 0 && partialMatchPools.length <= 0)
|
|
48
|
+
return routerGraph.getCompleteRouteGivenAmountIn(inputs);
|
|
49
|
+
const [exactTradeResults, completeRoutesForLastPoolAsync] = yield Promise.all([
|
|
50
|
+
this.AsyncHelpers.fetchTradeResults(Object.assign(Object.assign({}, inputs), { pools: exactMatchPools, coinInAmounts })),
|
|
51
|
+
Promise.all(partialMatchPools.map((lastPool) => this.fetchCompleteTradeRoutesForLastRouteAsyncPool(Object.assign(Object.assign({}, inputs), { routerGraph,
|
|
52
|
+
coinInAmounts,
|
|
53
|
+
lastPool })))),
|
|
54
|
+
]);
|
|
55
|
+
const synchronousCompleteRoutes = routerGraph.getCompleteRoutesGivenAmountIns(Object.assign(Object.assign({}, inputs), { coinInAmounts }));
|
|
56
|
+
const allCompleteRoutes = [
|
|
57
|
+
...completeRoutesForLastPoolAsync,
|
|
58
|
+
synchronousCompleteRoutes,
|
|
59
|
+
];
|
|
60
|
+
const completeRoutes = allCompleteRoutes.filter((routes) => routes.length > 0);
|
|
61
|
+
return routerAsyncGraph_1.RouterAsyncGraph.createFinalCompleteRoute({
|
|
62
|
+
tradeResults: exactTradeResults,
|
|
63
|
+
completeRoutes: completeRoutes.length <= 0 ? undefined : completeRoutes,
|
|
64
|
+
coinInAmounts,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
this.fetchCompleteTradeRoutesForLastRouteAsyncPool = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const { routerGraph } = inputs;
|
|
69
|
+
const asyncApi = this.AsyncHelpers.protocolNamesToApi[this.AsyncHelpers.protocolNameFromPool({
|
|
70
|
+
pool: inputs.lastPool,
|
|
71
|
+
})]();
|
|
72
|
+
const lastPoolCoinInType = asyncApi.otherCoinInPool({
|
|
73
|
+
coinType: inputs.coinOutType,
|
|
74
|
+
pool: inputs.lastPool,
|
|
75
|
+
});
|
|
76
|
+
const synchronousCompleteRoutes = routerGraph.getCompleteRoutesGivenAmountIns(Object.assign(Object.assign({}, inputs), { coinOutType: lastPoolCoinInType }));
|
|
77
|
+
const lastPoolCoinInAmounts = synchronousCompleteRoutes.map((route) => route.coinOut.amount);
|
|
78
|
+
const tradeResults = yield this.AsyncHelpers.fetchTradeResults(Object.assign(Object.assign({}, inputs), { coinInType: lastPoolCoinInType, pools: [inputs.lastPool], coinInAmounts: lastPoolCoinInAmounts }));
|
|
79
|
+
const asyncCompleteRoutes = routerAsyncGraph_1.RouterAsyncGraph.completeRoutesFromTradeResults({
|
|
80
|
+
tradeResults,
|
|
81
|
+
})[0];
|
|
82
|
+
const finalCompleteRoutes = synchronousCompleteRoutes.map((syncRoute, index) => RouterApiHelpers.addFinalRouterCompleteTradeRouteToRoute({
|
|
83
|
+
startCompleteRoute: syncRoute,
|
|
84
|
+
endCompleteRoute: asyncCompleteRoutes[index],
|
|
85
|
+
}));
|
|
86
|
+
return finalCompleteRoutes.every((route) => route.routes.length === 0)
|
|
87
|
+
? []
|
|
88
|
+
: finalCompleteRoutes;
|
|
89
|
+
});
|
|
90
|
+
this.Provider = Provider;
|
|
91
|
+
this.SynchronousHelpers = new routerSynchronousApiHelpers_1.RouterSynchronousApiHelpers(Provider);
|
|
92
|
+
this.AsyncHelpers = new routerAsyncApiHelpers_1.RouterAsyncApiHelpers(Provider);
|
|
93
|
+
}
|
|
94
|
+
// public fetchCompleteTradeRouteGivenAmountIn = async (inputs: {
|
|
95
|
+
// protocols: RouterProtocolName[];
|
|
96
|
+
// network: SuiNetwork | Url;
|
|
97
|
+
// graph: RouterSerializableCompleteGraph;
|
|
98
|
+
// coinInType: CoinType;
|
|
99
|
+
// coinInAmount: Balance;
|
|
100
|
+
// coinOutType: CoinType;
|
|
101
|
+
// referrer?: SuiAddress;
|
|
102
|
+
// externalFee?: RouterExternalFee;
|
|
103
|
+
// // TODO: add options to set all these params ?
|
|
104
|
+
// // maxRouteLength?: number,
|
|
105
|
+
// }): Promise<RouterCompleteTradeRoute> => {
|
|
106
|
+
// if (inputs.protocols.length === 0)
|
|
107
|
+
// throw new Error("no protocols set in constructor");
|
|
108
|
+
// const { network, graph, coinInAmount } = inputs;
|
|
109
|
+
// const coinInAmounts = RouterApiHelpers.amountsInForRouterTrade({
|
|
110
|
+
// coinInAmount,
|
|
111
|
+
// });
|
|
112
|
+
// const tradeResults = await this.AsyncHelpers.fetchTradeResults({
|
|
113
|
+
// ...inputs,
|
|
114
|
+
// protocols: inputs.protocols.filter(isRouterAsyncProtocolName),
|
|
115
|
+
// coinInAmounts,
|
|
116
|
+
// });
|
|
117
|
+
// const routerGraph = new RouterGraph(network, graph);
|
|
118
|
+
// if (tradeResults.results.length <= 0)
|
|
119
|
+
// return routerGraph.getCompleteRouteGivenAmountIn(inputs);
|
|
120
|
+
// const synchronousCompleteRoutes =
|
|
121
|
+
// routerGraph.getCompleteRoutesGivenAmountIns({
|
|
122
|
+
// ...inputs,
|
|
123
|
+
// coinInAmounts,
|
|
124
|
+
// });
|
|
125
|
+
// return RouterAsyncGraph.createFinalCompleteRoute({
|
|
126
|
+
// tradeResults,
|
|
127
|
+
// synchronousCompleteRoutes,
|
|
128
|
+
// coinInAmounts,
|
|
129
|
+
// });
|
|
130
|
+
// };
|
|
131
|
+
/////////////////////////////////////////////////////////////////////
|
|
132
|
+
//// Transactions
|
|
133
|
+
/////////////////////////////////////////////////////////////////////
|
|
134
|
+
fetchTransactionForCompleteTradeRoute(inputs) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
return this.SynchronousHelpers.fetchBuildTransactionForCompleteTradeRoute(inputs);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.RouterApiHelpers = RouterApiHelpers;
|
|
141
|
+
/////////////////////////////////////////////////////////////////////
|
|
142
|
+
//// Constants
|
|
143
|
+
/////////////////////////////////////////////////////////////////////
|
|
144
|
+
RouterApiHelpers.constants = {
|
|
145
|
+
defaults: {
|
|
146
|
+
tradePartitionCount: 3,
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
/////////////////////////////////////////////////////////////////////
|
|
150
|
+
//// Public Static Methods
|
|
151
|
+
/////////////////////////////////////////////////////////////////////
|
|
152
|
+
/////////////////////////////////////////////////////////////////////
|
|
153
|
+
//// Helpers
|
|
154
|
+
/////////////////////////////////////////////////////////////////////
|
|
155
|
+
RouterApiHelpers.amountsInForRouterTrade = (inputs) => {
|
|
156
|
+
const { coinInAmount } = inputs;
|
|
157
|
+
const partitions = inputs.partitions ||
|
|
158
|
+
RouterApiHelpers.constants.defaults.tradePartitionCount;
|
|
159
|
+
const coinInPartitionAmount = coinInAmount / BigInt(Math.floor(partitions));
|
|
160
|
+
const coinInRemainderAmount = coinInAmount % BigInt(Math.floor(partitions));
|
|
161
|
+
const amountsIn = Array(partitions)
|
|
162
|
+
.fill(0)
|
|
163
|
+
.map((_, index) => index === 0
|
|
164
|
+
? coinInRemainderAmount + coinInPartitionAmount
|
|
165
|
+
: BigInt(1 + index) * coinInPartitionAmount);
|
|
166
|
+
return amountsIn;
|
|
167
|
+
};
|
|
168
|
+
/////////////////////////////////////////////////////////////////////
|
|
169
|
+
//// Private Methods
|
|
170
|
+
/////////////////////////////////////////////////////////////////////
|
|
171
|
+
/////////////////////////////////////////////////////////////////////
|
|
172
|
+
//// Helpers
|
|
173
|
+
/////////////////////////////////////////////////////////////////////
|
|
174
|
+
RouterApiHelpers.addFinalRouterCompleteTradeRouteToRoute = (inputs) => {
|
|
175
|
+
const { startCompleteRoute, endCompleteRoute } = inputs;
|
|
176
|
+
const totalEndRouteAmountIn = endCompleteRoute.coinIn.amount;
|
|
177
|
+
return Object.assign(Object.assign({}, startCompleteRoute), { routes: startCompleteRoute.routes.map((route) => {
|
|
178
|
+
const finalRoute = endCompleteRoute.routes[0];
|
|
179
|
+
const finalPath = finalRoute.paths[0];
|
|
180
|
+
// TODO: handle remainder amount
|
|
181
|
+
const finalCoinOutAmountForRoute = route.coinOut.amount / totalEndRouteAmountIn;
|
|
182
|
+
const spotPrice = Number(route.coinIn.amount) /
|
|
183
|
+
Number(finalCoinOutAmountForRoute);
|
|
184
|
+
return {
|
|
185
|
+
spotPrice,
|
|
186
|
+
coinIn: Object.assign({}, route.coinIn),
|
|
187
|
+
coinOut: Object.assign(Object.assign({}, finalRoute.coinOut), { amount: finalCoinOutAmountForRoute }),
|
|
188
|
+
paths: [...route.paths, finalPath],
|
|
189
|
+
};
|
|
190
|
+
}), coinOut: Object.assign({}, endCompleteRoute.coinOut), spotPrice: startCompleteRoute.spotPrice * endCompleteRoute.spotPrice });
|
|
191
|
+
};
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { AftermathApi } from "../../../general/providers/aftermathApi";
|
|
2
|
-
import { RouterAsyncProtocolName, RouterAsyncTradeResults } from "../routerTypes";
|
|
2
|
+
import { RouterAsyncProtocolName, RouterAsyncSerializablePool, RouterAsyncTradeResults } from "../routerTypes";
|
|
3
3
|
import { Balance, CoinType } from "../../../types";
|
|
4
|
+
import { RouterAsyncApiInterface } from "../utils/async/routerAsyncApiInterface";
|
|
4
5
|
export declare class RouterAsyncApiHelpers {
|
|
5
6
|
private readonly Provider;
|
|
6
|
-
|
|
7
|
+
readonly protocolNamesToApi: Record<RouterAsyncProtocolName, () => RouterAsyncApiInterface<any>>;
|
|
7
8
|
constructor(Provider: AftermathApi);
|
|
8
|
-
|
|
9
|
+
fetchPossiblePools: (inputs: {
|
|
9
10
|
protocols: RouterAsyncProtocolName[];
|
|
10
11
|
coinInType: CoinType;
|
|
11
12
|
coinOutType: CoinType;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
exactMatchPools: RouterAsyncSerializablePool[];
|
|
15
|
+
partialMatchPools: RouterAsyncSerializablePool[];
|
|
16
|
+
}>;
|
|
17
|
+
fetchTradeResults: (inputs: {
|
|
18
|
+
pools: RouterAsyncSerializablePool[];
|
|
19
|
+
coinInType: CoinType;
|
|
20
|
+
coinOutType: CoinType;
|
|
12
21
|
coinInAmounts: Balance[];
|
|
13
22
|
}) => Promise<RouterAsyncTradeResults>;
|
|
14
|
-
|
|
23
|
+
protocolNameFromPool: (inputs: {
|
|
24
|
+
pool: RouterAsyncSerializablePool;
|
|
25
|
+
}) => RouterAsyncProtocolName;
|
|
15
26
|
}
|
|
16
27
|
//# sourceMappingURL=routerAsyncApiHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerAsyncApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/packages/router/api/routerAsyncApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACN,uBAAuB,
|
|
1
|
+
{"version":3,"file":"routerAsyncApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/packages/router/api/routerAsyncApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACN,uBAAuB,EACvB,2BAA2B,EAE3B,uBAAuB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAOjF,qBAAa,qBAAqB;IAiBrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAZrC,SAAgB,kBAAkB,EAAE,MAAM,CACzC,uBAAuB,EACvB,MAAM,uBAAuB,CAAC,GAAG,CAAC,CAClC,CAGC;gBAM2B,QAAQ,EAAE,YAAY;IAQ5C,kBAAkB,WAAkB;QAC1C,SAAS,EAAE,uBAAuB,EAAE,CAAC;QACrC,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;KACtB,KAAG,QAAQ;QACX,eAAe,EAAE,2BAA2B,EAAE,CAAC;QAC/C,iBAAiB,EAAE,2BAA2B,EAAE,CAAC;KACjD,CAAC,CA8BA;IAEK,iBAAiB,WAAkB;QACzC,KAAK,EAAE,2BAA2B,EAAE,CAAC;QACrC,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;QACtB,aAAa,EAAE,OAAO,EAAE,CAAC;KACzB,KAAG,QAAQ,uBAAuB,CAAC,CAwDlC;IA4CK,oBAAoB,WAAY;QACtC,IAAI,EAAE,2BAA2B,CAAC;KAClC,KAAG,uBAAuB,CAQzB;CACF"}
|
|
@@ -13,6 +13,7 @@ exports.RouterAsyncApiHelpers = void 0;
|
|
|
13
13
|
const cetusApi_1 = require("../../external/cetus/cetusApi");
|
|
14
14
|
const rpcApiHelpers_1 = require("../../../general/api/rpcApiHelpers");
|
|
15
15
|
const turbosApi_1 = require("../../external/turbos/turbosApi");
|
|
16
|
+
const turbosTypes_1 = require("../../external/turbos/turbosTypes");
|
|
16
17
|
class RouterAsyncApiHelpers {
|
|
17
18
|
/////////////////////////////////////////////////////////////////////
|
|
18
19
|
//// Constructor
|
|
@@ -29,18 +30,47 @@ class RouterAsyncApiHelpers {
|
|
|
29
30
|
/////////////////////////////////////////////////////////////////////
|
|
30
31
|
//// Objects
|
|
31
32
|
/////////////////////////////////////////////////////////////////////
|
|
33
|
+
this.fetchPossiblePools = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const apis = inputs.protocols.map((protocol) => this.protocolNamesToApi[protocol]());
|
|
35
|
+
const allPools = (yield Promise.all(apis.map((api) => api.fetchPoolsForTrade(inputs)))).reduce((acc, pools) => {
|
|
36
|
+
return {
|
|
37
|
+
exactMatchPools: [
|
|
38
|
+
...acc.exactMatchPools,
|
|
39
|
+
...pools.exactMatchPools,
|
|
40
|
+
],
|
|
41
|
+
partialMatchPools: [
|
|
42
|
+
...acc.partialMatchPools,
|
|
43
|
+
...pools.partialMatchPools,
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
}, {
|
|
47
|
+
partialMatchPools: [],
|
|
48
|
+
exactMatchPools: [],
|
|
49
|
+
});
|
|
50
|
+
return allPools;
|
|
51
|
+
});
|
|
32
52
|
this.fetchTradeResults = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const { coinInAmounts
|
|
34
|
-
const
|
|
53
|
+
const { coinInAmounts } = inputs;
|
|
54
|
+
const protocols = inputs.pools.map((pool) => this.protocolNameFromPool({ pool }));
|
|
55
|
+
const apis = protocols.map((protocol) => this.protocolNamesToApi[protocol]());
|
|
35
56
|
const resultsOrUndefined = yield Promise.all(apis.map((api, index) => __awaiter(this, void 0, void 0, function* () {
|
|
36
57
|
try {
|
|
37
|
-
const pool =
|
|
38
|
-
const amountsOut = yield Promise.all(coinInAmounts.map((amountIn) =>
|
|
39
|
-
|
|
58
|
+
const pool = inputs.pools[index];
|
|
59
|
+
const amountsOut = yield Promise.all(coinInAmounts.map((amountIn) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
try {
|
|
61
|
+
return yield api.fetchTradeAmountOut(Object.assign(Object.assign({}, inputs), { pool, walletAddress: rpcApiHelpers_1.RpcApiHelpers.constants
|
|
62
|
+
.devInspectSigner, coinInAmount: amountIn }));
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error(e);
|
|
66
|
+
return BigInt(0);
|
|
67
|
+
}
|
|
68
|
+
})));
|
|
69
|
+
const protocol = protocols[index];
|
|
40
70
|
return {
|
|
41
71
|
pool,
|
|
42
72
|
amountsOut,
|
|
43
|
-
protocol
|
|
73
|
+
protocol,
|
|
44
74
|
};
|
|
45
75
|
}
|
|
46
76
|
catch (e) {
|
|
@@ -84,9 +114,12 @@ class RouterAsyncApiHelpers {
|
|
|
84
114
|
/////////////////////////////////////////////////////////////////////
|
|
85
115
|
//// Helpers
|
|
86
116
|
/////////////////////////////////////////////////////////////////////
|
|
87
|
-
this.
|
|
88
|
-
const {
|
|
89
|
-
|
|
117
|
+
this.protocolNameFromPool = (inputs) => {
|
|
118
|
+
const { pool } = inputs;
|
|
119
|
+
const protocolName = (0, turbosTypes_1.isTurbosPoolObject)(pool)
|
|
120
|
+
? "Turbos"
|
|
121
|
+
: "Cetus";
|
|
122
|
+
return protocolName;
|
|
90
123
|
};
|
|
91
124
|
this.Provider = Provider;
|
|
92
125
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { SuiAddress, TransactionBlock } from "@mysten/sui.js";
|
|
2
2
|
import { AftermathApi } from "../../../general/providers/aftermathApi";
|
|
3
3
|
import { RouterCompleteTradeRoute, RouterProtocolName, RouterSerializablePool } from "../routerTypes";
|
|
4
|
-
import {
|
|
4
|
+
import { CoinType, Slippage } from "../../../types";
|
|
5
5
|
export declare class RouterSynchronousApiHelpers {
|
|
6
6
|
private readonly Provider;
|
|
7
7
|
private readonly protocolNamesToApi;
|
|
8
|
-
static readonly constants: {
|
|
9
|
-
defaults: {
|
|
10
|
-
tradePartitionCount: number;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
8
|
constructor(Provider: AftermathApi);
|
|
14
9
|
fetchAllPools: (inputs: {
|
|
15
10
|
protocols: RouterProtocolName[];
|
|
@@ -22,10 +17,6 @@ export declare class RouterSynchronousApiHelpers {
|
|
|
22
17
|
completeRoute: RouterCompleteTradeRoute;
|
|
23
18
|
slippage: Slippage;
|
|
24
19
|
}): Promise<TransactionBlock>;
|
|
25
|
-
static amountsInForRouterTrade: (inputs: {
|
|
26
|
-
coinInAmount: Balance;
|
|
27
|
-
partitions?: number;
|
|
28
|
-
}) => Balance[];
|
|
29
20
|
private protocolApisFromNames;
|
|
30
21
|
}
|
|
31
22
|
//# sourceMappingURL=routerSynchronousApiHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerSynchronousApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/packages/router/api/routerSynchronousApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,UAAU,EAEV,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"routerSynchronousApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/packages/router/api/routerSynchronousApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,UAAU,EAEV,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAW,QAAQ,EAAE,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAW9E,qBAAa,2BAA2B;IAoB3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAfrC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CASjC;gBAM2B,QAAQ,EAAE,YAAY;IAQ5C,aAAa,WAAkB;QACrC,SAAS,EAAE,kBAAkB,EAAE,CAAC;KAChC,KAAG,QAAQ,sBAAsB,EAAE,CAAC,CAanC;IAMK,mBAAmB,WAAkB;QAC3C,SAAS,EAAE,kBAAkB,EAAE,CAAC;KAChC,KAAG,QAAQ,QAAQ,EAAE,CAAC,CAgBrB;IAMW,0CAA0C,CAAC,MAAM,EAAE;QAC/D,aAAa,EAAE,UAAU,CAAC;QAC1B,aAAa,EAAE,wBAAwB,CAAC;QACxC,QAAQ,EAAE,QAAQ,CAAC;KACnB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAsH7B,OAAO,CAAC,qBAAqB,CAK3B;CACF"}
|
|
@@ -125,7 +125,11 @@ class RouterSynchronousApiHelpers {
|
|
|
125
125
|
slippage,
|
|
126
126
|
referrer,
|
|
127
127
|
});
|
|
128
|
-
coinIn =
|
|
128
|
+
coinIn =
|
|
129
|
+
poolForPath.noHopsAllowed &&
|
|
130
|
+
poolForPath.protocolName !== "Cetus"
|
|
131
|
+
? undefined
|
|
132
|
+
: newCoinIn;
|
|
129
133
|
}
|
|
130
134
|
if (coinIn)
|
|
131
135
|
coinsOut.push(coinIn);
|
|
@@ -152,27 +156,3 @@ class RouterSynchronousApiHelpers {
|
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
exports.RouterSynchronousApiHelpers = RouterSynchronousApiHelpers;
|
|
155
|
-
RouterSynchronousApiHelpers.constants = {
|
|
156
|
-
defaults: {
|
|
157
|
-
tradePartitionCount: 3,
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
/////////////////////////////////////////////////////////////////////
|
|
161
|
-
//// Public Static Methods
|
|
162
|
-
/////////////////////////////////////////////////////////////////////
|
|
163
|
-
/////////////////////////////////////////////////////////////////////
|
|
164
|
-
//// Helpers
|
|
165
|
-
/////////////////////////////////////////////////////////////////////
|
|
166
|
-
RouterSynchronousApiHelpers.amountsInForRouterTrade = (inputs) => {
|
|
167
|
-
const { coinInAmount } = inputs;
|
|
168
|
-
const partitions = inputs.partitions ||
|
|
169
|
-
RouterSynchronousApiHelpers.constants.defaults.tradePartitionCount;
|
|
170
|
-
const coinInPartitionAmount = coinInAmount / BigInt(Math.floor(partitions));
|
|
171
|
-
const coinInRemainderAmount = coinInAmount % BigInt(Math.floor(partitions));
|
|
172
|
-
const amountsIn = Array(partitions)
|
|
173
|
-
.fill(0)
|
|
174
|
-
.map((_, index) => index === 0
|
|
175
|
-
? coinInRemainderAmount + coinInPartitionAmount
|
|
176
|
-
: BigInt(1 + index) * coinInPartitionAmount);
|
|
177
|
-
return amountsIn;
|
|
178
|
-
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerTypes.d.ts","sourceRoot":"","sources":["../../../src/packages/router/routerTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACN,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBA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,QAAQ,CAAC;CACnB"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { SuiAddress } from "@mysten/sui.js";
|
|
2
2
|
import { CoinType } from "../../../coin/coinTypes";
|
|
3
|
-
import { Balance, SerializedTransaction } from "../../../../types";
|
|
4
|
-
export interface RouterAsyncApiInterface<PoolType> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}) => Promise<
|
|
3
|
+
import { Balance, RouterAsyncSerializablePool, SerializedTransaction } from "../../../../types";
|
|
4
|
+
export interface RouterAsyncApiInterface<PoolType extends RouterAsyncSerializablePool> {
|
|
5
|
+
fetchPoolsForTrade: (inputs: {
|
|
6
|
+
coinInType: CoinType;
|
|
7
|
+
coinOutType: CoinType;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
partialMatchPools: PoolType[];
|
|
10
|
+
exactMatchPools: PoolType[];
|
|
11
|
+
}>;
|
|
9
12
|
fetchTradeAmountOut: (inputs: {
|
|
10
13
|
walletAddress: SuiAddress;
|
|
11
14
|
pool: PoolType;
|
|
@@ -13,6 +16,10 @@ export interface RouterAsyncApiInterface<PoolType> {
|
|
|
13
16
|
coinOutType: CoinType;
|
|
14
17
|
coinInAmount: Balance;
|
|
15
18
|
}) => Promise<Balance>;
|
|
19
|
+
otherCoinInPool: (inputs: {
|
|
20
|
+
coinType: CoinType;
|
|
21
|
+
pool: PoolType;
|
|
22
|
+
}) => CoinType;
|
|
16
23
|
fetchTradeTx: (inputs: {
|
|
17
24
|
walletAddress: SuiAddress;
|
|
18
25
|
pool: PoolType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerAsyncApiInterface.d.ts","sourceRoot":"","sources":["../../../../../src/packages/router/utils/async/routerAsyncApiInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"routerAsyncApiInterface.d.ts","sourceRoot":"","sources":["../../../../../src/packages/router/utils/async/routerAsyncApiInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EACN,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,MAAM,mBAAmB,CAAC;AAM3B,MAAM,WAAW,uBAAuB,CACvC,QAAQ,SAAS,2BAA2B;IAc5C,kBAAkB,EAAE,CAAC,MAAM,EAAE;QAC5B,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;KACtB,KAAK,OAAO,CAAC;QACb,iBAAiB,EAAE,QAAQ,EAAE,CAAC;QAC9B,eAAe,EAAE,QAAQ,EAAE,CAAC;KAC5B,CAAC,CAAC;IAMH,mBAAmB,EAAE,CAAC,MAAM,EAAE;QAC7B,aAAa,EAAE,UAAU,CAAC;QAC1B,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;QACtB,YAAY,EAAE,OAAO,CAAC;KACtB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAUvB,eAAe,EAAE,CAAC,MAAM,EAAE;QACzB,QAAQ,EAAE,QAAQ,CAAC;QACnB,IAAI,EAAE,QAAQ,CAAC;KACf,KAAK,QAAQ,CAAC;IAMf,YAAY,EAAE,CAAC,MAAM,EAAE;QACtB,aAAa,EAAE,UAAU,CAAC;QAC1B,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;QACtB,YAAY,EAAE,OAAO,CAAC;KACtB,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACrC"}
|
|
@@ -3,10 +3,12 @@ export declare class RouterAsyncGraph {
|
|
|
3
3
|
static createFinalCompleteRoute(inputs: {
|
|
4
4
|
tradeResults: RouterAsyncTradeResults;
|
|
5
5
|
coinInAmounts: Balance[];
|
|
6
|
-
|
|
6
|
+
completeRoutes?: RouterCompleteTradeRoute[][];
|
|
7
7
|
}): RouterCompleteTradeRoute;
|
|
8
|
+
static completeRoutesFromTradeResults: (inputs: {
|
|
9
|
+
tradeResults: RouterAsyncTradeResults;
|
|
10
|
+
}) => RouterCompleteTradeRoute[][];
|
|
8
11
|
private static splitTradeBetweenRoutes;
|
|
9
12
|
private static singleCompleteRouteFromMany;
|
|
10
|
-
private static completeRoutesFromTradeResults;
|
|
11
13
|
}
|
|
12
14
|
//# sourceMappingURL=routerAsyncGraph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerAsyncGraph.d.ts","sourceRoot":"","sources":["../../../../../src/packages/router/utils/async/routerAsyncGraph.ts"],"names":[],"mappings":"AACA,OAAO,EACN,OAAO,EACP,uBAAuB,EACvB,wBAAwB,EAExB,MAAM,mBAAmB,CAAC;AAM3B,qBAAa,gBAAgB;WASd,wBAAwB,CAAC,MAAM,EAAE;QAC9C,YAAY,EAAE,uBAAuB,CAAC;QACtC,aAAa,EAAE,OAAO,EAAE,CAAC;QACzB,
|
|
1
|
+
{"version":3,"file":"routerAsyncGraph.d.ts","sourceRoot":"","sources":["../../../../../src/packages/router/utils/async/routerAsyncGraph.ts"],"names":[],"mappings":"AACA,OAAO,EACN,OAAO,EACP,uBAAuB,EACvB,wBAAwB,EAExB,MAAM,mBAAmB,CAAC;AAM3B,qBAAa,gBAAgB;WASd,wBAAwB,CAAC,MAAM,EAAE;QAC9C,YAAY,EAAE,uBAAuB,CAAC;QACtC,aAAa,EAAE,OAAO,EAAE,CAAC;QACzB,cAAc,CAAC,EAAE,wBAAwB,EAAE,EAAE,CAAC;KAC9C,GAAG,wBAAwB;IAqB5B,OAAc,8BAA8B,WAAY;QACvD,YAAY,EAAE,uBAAuB,CAAC;KACtC,KAAG,wBAAwB,EAAE,EAAE,CA+C9B;IAUF,OAAO,CAAC,MAAM,CAAC,uBAAuB,CA2CpC;IAEF,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAqCxC;CACF"}
|
|
@@ -14,19 +14,48 @@ class RouterAsyncGraph {
|
|
|
14
14
|
/////////////////////////////////////////////////////////////////////
|
|
15
15
|
static createFinalCompleteRoute(inputs) {
|
|
16
16
|
const asyncCompleteRoutes = this.completeRoutesFromTradeResults(inputs);
|
|
17
|
-
const completeRoutes = inputs.
|
|
18
|
-
? [...asyncCompleteRoutes, inputs.
|
|
19
|
-
:
|
|
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(
|
|
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
|