aftermath-ts-sdk 0.0.174 → 0.0.176
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/prices/coingecko/coinGeckoApiHelpers.d.ts.map +1 -1
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +15 -0
- package/dist/general/providers/aftermathApi.d.ts +2 -2
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +1 -1
- package/dist/packages/router/api/routerApi.d.ts +4 -2
- package/dist/packages/router/api/routerApi.d.ts.map +1 -1
- package/dist/packages/router/api/routerApi.js +36 -3
- package/dist/packages/router/api/routerApiHelpers.d.ts +4 -10
- package/dist/packages/router/api/routerApiHelpers.d.ts.map +1 -1
- package/dist/packages/router/api/routerApiHelpers.js +26 -38
- package/dist/packages/router/api/routerAsyncApiHelpers.d.ts +3 -2
- package/dist/packages/router/api/routerAsyncApiHelpers.d.ts.map +1 -1
- package/dist/packages/router/api/routerAsyncApiHelpers.js +3 -4
- package/dist/packages/router/routerTypes.d.ts +17 -1
- package/dist/packages/router/routerTypes.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerGraph.d.ts +5 -6
- package/dist/packages/router/utils/synchronous/routerGraph.d.ts.map +1 -1
- package/dist/packages/router/utils/synchronous/routerGraph.js +14 -26
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinGeckoApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/coingecko/coinGeckoApiHelpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAE9E,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEzE,qBAAa,mBAAmB;
|
|
1
|
+
{"version":3,"file":"coinGeckoApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/coingecko/coinGeckoApiHelpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAE9E,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEzE,qBAAa,mBAAmB;IA0CnB,OAAO,CAAC,QAAQ,CAAC,eAAe;IArC5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CA+B/B;gBAM2B,eAAe,EAAE,MAAM;IAU7C,gBAAgB,QAAa,QACnC,OAAO,QAAQ,EAAE,iBAAiB,CAAC,CACnC,CAgFC;IAMK,mBAAmB,WAAkB;QAC3C,SAAS,EAAE,kBAAkB,CAAC;QAC9B,OAAO,EAAE,MAAM,CAAC;KAChB,KAAG,QAAQ,kBAAkB,CAAC,CAuB7B;IAMK,qBAAqB,WAAkB;QAC7C,YAAY,EAAE,OAAO,QAAQ,EAAE,kBAAkB,CAAC,CAAC;KACnD,KAAG,QAAQ,OAAO,QAAQ,EAAE,aAAa,CAAC,CAAC,CAwC1C;IAUF,OAAO,CAAC,OAAO,CAeb;CACF"}
|
|
@@ -149,5 +149,20 @@ CoinGeckoApiHelpers.constants = {
|
|
|
149
149
|
"wrapped-solana": [
|
|
150
150
|
"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8::coin::COIN",
|
|
151
151
|
],
|
|
152
|
+
"usd-coin-celer": [
|
|
153
|
+
"0x94e7a8e71830d2b34b3edaa195dc24c45d142584f06fa257b73af753d766e690::celer_usdc_coin::CELER_USDC_COIN",
|
|
154
|
+
],
|
|
155
|
+
"tether-usd-celer": [
|
|
156
|
+
"0x94e7a8e71830d2b34b3edaa195dc24c45d142584f06fa257b73af753d766e690::celer_usdt_coin::CELER_USDT_COIN",
|
|
157
|
+
],
|
|
158
|
+
"wrapped-moonbeam": [
|
|
159
|
+
"0x66f87084e49c38f76502d17f87d17f943f183bb94117561eb573e075fdc5ff75::coin::COIN",
|
|
160
|
+
],
|
|
161
|
+
"wrapped-fantom": [
|
|
162
|
+
"0x6081300950a4f1e2081580e919c210436a1bed49080502834950d31ee55a2396::coin::COIN",
|
|
163
|
+
],
|
|
164
|
+
celo: [
|
|
165
|
+
"0xa198f3be41cda8c07b3bf3fee02263526e535d682499806979a111e88a5a8d0f::coin::COIN",
|
|
166
|
+
],
|
|
152
167
|
},
|
|
153
168
|
};
|
|
@@ -17,7 +17,7 @@ import { SuiFrensApi } from "../../packages/suiFrens/api/suiFrensApi";
|
|
|
17
17
|
import { StakingApi } from "../../packages/staking/api/stakingApi";
|
|
18
18
|
import { NftAmmApi } from "../../packages/nftAmm/api/nftAmmApi";
|
|
19
19
|
import { ReferralVaultApi } from "../../packages/referralVault/api/referralVaultApi";
|
|
20
|
-
import { RouterProtocolName } from "../../types";
|
|
20
|
+
import { PartialRouterOptions, RouterProtocolName, RouterSynchronousOptions } from "../../types";
|
|
21
21
|
import { HistoricalDataApi } from "../historicalData/historicalDataApi";
|
|
22
22
|
import { CoinGeckoPricesApi } from "../prices/coingecko/coinGeckoPricesApi";
|
|
23
23
|
import { PlaceholderHistoricalDataApi } from "../historicalData/placeholderHistoricalDataApi";
|
|
@@ -51,11 +51,11 @@ export declare class AftermathApi {
|
|
|
51
51
|
Sui: () => SuiApi;
|
|
52
52
|
Pools: () => PoolsApi;
|
|
53
53
|
Faucet: () => FaucetApi;
|
|
54
|
-
Router: (protocols?: RouterProtocolName[]) => RouterApi;
|
|
55
54
|
SuiFrens: () => SuiFrensApi;
|
|
56
55
|
Staking: () => StakingApi;
|
|
57
56
|
NftAmm: () => NftAmmApi;
|
|
58
57
|
ReferralVault: () => ReferralVaultApi;
|
|
59
58
|
Perpetuals: () => PerpetualsApi;
|
|
59
|
+
Router: (protocols?: RouterProtocolName[], regularOptions?: PartialRouterOptions, preAsyncOptions?: Partial<RouterSynchronousOptions>) => RouterApi;
|
|
60
60
|
}
|
|
61
61
|
//# sourceMappingURL=aftermathApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aftermathApi.d.ts","sourceRoot":"","sources":["../../../src/general/providers/aftermathApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AACrF,OAAO,
|
|
1
|
+
{"version":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AwC,CAAC;AAC5E,OAAO,EAAE,4BAA4B,EAAE,MAAM,gDAAgD,CAAC;AAC9F,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAE5E,qBAAa,YAAY;aAoCP,QAAQ,EAAE,eAAe;aACzB,SAAS,EAAE,eAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;IAjClC,OAAc,OAAO;;;;;;;;;;MAwBnB;gBAOe,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,eAAe,EACzB,eAAe,CAAC,oBAAQ;IAenC,aAAa,gCAA2C;IACxD,MAAM,yBAAoC;IAC1C,WAAW,8BAAyC;IACpD,OAAO,0BAAqC;IAC5C,YAAY,+BAA0C;IACtD,GAAG,sBAAiC;IAMpC,MAAM,kBAA6B;IACnC,MAAM,kDAGkB;IACxB,cAAc,yDAGkB;IAMhC,IAAI,gBAA2B;IAC/B,GAAG,eAA0B;IAM7B,KAAK,iBAA4B;IACjC,MAAM,kBAA6B;IACnC,QAAQ,oBAA+B;IACvC,OAAO,mBAA8B;IACrC,MAAM,kBAA6B;IACnC,aAAa,yBAAoC;IACjD,UAAU,sBAAiC;IAE3C,MAAM,eACA,kBAAkB,EAAE,mBACf,oBAAoB,oBACnB,QAAQ,wBAAwB,CAAC,eACiB;CACrE"}
|
|
@@ -62,12 +62,12 @@ class AftermathApi {
|
|
|
62
62
|
// =========================================================================
|
|
63
63
|
this.Pools = () => new poolsApi_1.PoolsApi(this);
|
|
64
64
|
this.Faucet = () => new faucetApi_1.FaucetApi(this);
|
|
65
|
-
this.Router = (protocols) => new routerApi_1.RouterApi(this, protocols);
|
|
66
65
|
this.SuiFrens = () => new suiFrensApi_1.SuiFrensApi(this);
|
|
67
66
|
this.Staking = () => new stakingApi_1.StakingApi(this);
|
|
68
67
|
this.NftAmm = () => new nftAmmApi_1.NftAmmApi(this);
|
|
69
68
|
this.ReferralVault = () => new referralVaultApi_1.ReferralVaultApi(this);
|
|
70
69
|
this.Perpetuals = () => new perpetualsApi_1.PerpetualsApi(this);
|
|
70
|
+
this.Router = (protocols, regularOptions, preAsyncOptions) => new routerApi_1.RouterApi(this, protocols, regularOptions, preAsyncOptions);
|
|
71
71
|
this.provider = provider;
|
|
72
72
|
this.addresses = addresses;
|
|
73
73
|
this.coinGeckoApiKey = coinGeckoApiKey;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AftermathApi } from "../../../general/providers/aftermathApi";
|
|
2
|
-
import { Balance, CoinType, RouterExternalFee, RouterCompleteTradeRoute, Slippage, SuiNetwork, Url, RouterSerializableCompleteGraph, RouterProtocolName, UserEventsInputs, RouterAsyncSerializablePool, SynchronousProtocolsToPoolObjectIds } from "../../../types";
|
|
2
|
+
import { Balance, CoinType, RouterExternalFee, RouterCompleteTradeRoute, Slippage, SuiNetwork, Url, RouterSerializableCompleteGraph, RouterProtocolName, UserEventsInputs, RouterAsyncSerializablePool, SynchronousProtocolsToPoolObjectIds, RouterSynchronousOptions, PartialRouterOptions } from "../../../types";
|
|
3
3
|
import { SuiAddress, TransactionBlock } from "@mysten/sui.js";
|
|
4
4
|
import { DeepBookApi } from "../../external/deepBook/deepBookApi";
|
|
5
5
|
import { PoolsApi } from "../../pools/api/poolsApi";
|
|
@@ -14,8 +14,10 @@ import { BlueMoveApi } from "../../external/blueMove/blueMoveApi";
|
|
|
14
14
|
export declare class RouterApi {
|
|
15
15
|
private readonly Provider;
|
|
16
16
|
readonly protocols: RouterProtocolName[];
|
|
17
|
+
private static readonly defaultRouterOptions;
|
|
17
18
|
readonly Helpers: RouterApiHelpers;
|
|
18
|
-
|
|
19
|
+
private readonly options;
|
|
20
|
+
constructor(Provider: AftermathApi, protocols?: RouterProtocolName[], regularOptions?: PartialRouterOptions, preAsyncOptions?: Partial<RouterSynchronousOptions>);
|
|
19
21
|
Aftermath: () => PoolsApi;
|
|
20
22
|
DeepBook: () => DeepBookApi;
|
|
21
23
|
Cetus: () => CetusApi;
|
|
@@ -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;AAEvE,OAAO,EACN,OAAO,EACP,QAAQ,EACR,iBAAiB,EACjB,wBAAwB,
|
|
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;AAEvE,OAAO,EACN,OAAO,EACP,QAAQ,EACR,iBAAiB,EACjB,wBAAwB,EACxB,QAAQ,EACR,UAAU,EACV,GAAG,EACH,+BAA+B,EAC/B,kBAAkB,EAClB,gBAAgB,EAChB,2BAA2B,EAG3B,mCAAmC,EACnC,wBAAwB,EAExB,oBAAoB,EACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,qBAAa,SAAS;IAwCpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;aACT,SAAS,EAA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AC;KACnB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAQhB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB;CAGtD"}
|
|
@@ -26,7 +26,7 @@ class RouterApi {
|
|
|
26
26
|
// =========================================================================
|
|
27
27
|
// Constructor
|
|
28
28
|
// =========================================================================
|
|
29
|
-
constructor(Provider, protocols = ["Aftermath"]) {
|
|
29
|
+
constructor(Provider, protocols = ["Aftermath"], regularOptions, preAsyncOptions) {
|
|
30
30
|
this.Provider = Provider;
|
|
31
31
|
this.protocols = protocols;
|
|
32
32
|
// =========================================================================
|
|
@@ -64,7 +64,8 @@ class RouterApi {
|
|
|
64
64
|
// Coin Paths
|
|
65
65
|
// =========================================================================
|
|
66
66
|
this.supportedCoinPathsFromGraph = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
|
|
67
|
+
const maxRouteLength = this.options.regular.synchronous.maxRouteLength;
|
|
68
|
+
return routerGraph_1.RouterGraph.supportedCoinPathsFromGraph(Object.assign(Object.assign({}, inputs), { maxRouteLength }));
|
|
68
69
|
});
|
|
69
70
|
// =========================================================================
|
|
70
71
|
// Routing
|
|
@@ -72,8 +73,16 @@ class RouterApi {
|
|
|
72
73
|
this.fetchCompleteTradeRouteGivenAmountIn = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
73
74
|
return this.Helpers.fetchCompleteTradeRouteGivenAmountIn(Object.assign(Object.assign({}, inputs), { protocols: this.protocols }));
|
|
74
75
|
});
|
|
76
|
+
const optionsToSet = {
|
|
77
|
+
regular: {
|
|
78
|
+
synchronous: Object.assign(Object.assign({}, RouterApi.defaultRouterOptions.regular.synchronous), regularOptions === null || regularOptions === void 0 ? void 0 : regularOptions.synchronous),
|
|
79
|
+
async: Object.assign(Object.assign({}, RouterApi.defaultRouterOptions.regular.async), regularOptions === null || regularOptions === void 0 ? void 0 : regularOptions.async),
|
|
80
|
+
},
|
|
81
|
+
preAsync: Object.assign(Object.assign({}, RouterApi.defaultRouterOptions.preAsync), preAsyncOptions),
|
|
82
|
+
};
|
|
83
|
+
this.options = optionsToSet;
|
|
75
84
|
this.Provider = Provider;
|
|
76
|
-
this.Helpers = new routerApiHelpers_1.RouterApiHelpers(Provider);
|
|
85
|
+
this.Helpers = new routerApiHelpers_1.RouterApiHelpers(Provider, optionsToSet);
|
|
77
86
|
}
|
|
78
87
|
// public fetchCompleteTradeRouteGivenAmountOut = async (
|
|
79
88
|
// network: SuiNetwork | Url,
|
|
@@ -110,3 +119,27 @@ class RouterApi {
|
|
|
110
119
|
}
|
|
111
120
|
}
|
|
112
121
|
exports.RouterApi = RouterApi;
|
|
122
|
+
// =========================================================================
|
|
123
|
+
// Constants
|
|
124
|
+
// =========================================================================
|
|
125
|
+
RouterApi.defaultRouterOptions = {
|
|
126
|
+
regular: {
|
|
127
|
+
synchronous: {
|
|
128
|
+
maxRouteLength: 3,
|
|
129
|
+
tradePartitionCount: 2,
|
|
130
|
+
minRoutesToCheck: 5,
|
|
131
|
+
maxGasCost: BigInt(500000000), // 0.5 SUI
|
|
132
|
+
},
|
|
133
|
+
async: {
|
|
134
|
+
tradePartitionCount: 1,
|
|
135
|
+
maxAsyncPoolsPerProtocol: 2,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
preAsync: {
|
|
139
|
+
maxRouteLength: 2,
|
|
140
|
+
tradePartitionCount: 1,
|
|
141
|
+
minRoutesToCheck: 5,
|
|
142
|
+
maxGasCost: BigInt(500000000), // 0.5 SUI
|
|
143
|
+
// maxGasCost: BigInt(333_333_333), // 0.333 SUI
|
|
144
|
+
},
|
|
145
|
+
};
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { SuiAddress, TransactionBlock } from "@mysten/sui.js";
|
|
2
2
|
import { AftermathApi } from "../../../general/providers/aftermathApi";
|
|
3
|
-
import { Balance, CoinType, RouterAsyncSerializablePool, RouterCompleteTradeRoute, RouterExternalFee, RouterProtocolName, RouterSerializableCompleteGraph, Slippage, SuiNetwork, SynchronousProtocolsToPoolObjectIds, Url } from "../../../types";
|
|
3
|
+
import { Balance, CoinType, RouterAsyncSerializablePool, RouterCompleteTradeRoute, RouterExternalFee, RouterProtocolName, RouterSerializableCompleteGraph, Slippage, SuiNetwork, SynchronousProtocolsToPoolObjectIds, Url, AllRouterOptions } from "../../../types";
|
|
4
4
|
import { RouterAsyncApiHelpers } from "./routerAsyncApiHelpers";
|
|
5
5
|
import { RouterSynchronousApiHelpers } from "./routerSynchronousApiHelpers";
|
|
6
6
|
export declare class RouterApiHelpers {
|
|
7
|
-
|
|
8
|
-
defaults: {
|
|
9
|
-
tradePartitionCount: number;
|
|
10
|
-
maxAsyncPoolsPerProtocol: number;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
7
|
+
private readonly options;
|
|
13
8
|
readonly SynchronousHelpers: RouterSynchronousApiHelpers;
|
|
14
9
|
readonly AsyncHelpers: RouterAsyncApiHelpers;
|
|
15
|
-
constructor(Provider: AftermathApi);
|
|
10
|
+
constructor(Provider: AftermathApi, options: AllRouterOptions);
|
|
16
11
|
fetchCreateSerializableGraph: (inputs: {
|
|
17
12
|
asyncPools: RouterAsyncSerializablePool[];
|
|
18
13
|
synchronousProtocolsToPoolObjectIds: SynchronousProtocolsToPoolObjectIds;
|
|
@@ -33,9 +28,8 @@ export declare class RouterApiHelpers {
|
|
|
33
28
|
completeRoute: RouterCompleteTradeRoute;
|
|
34
29
|
slippage: Slippage;
|
|
35
30
|
}): Promise<TransactionBlock>;
|
|
36
|
-
|
|
31
|
+
amountsInForRouterTrade: (inputs: {
|
|
37
32
|
coinInAmount: Balance;
|
|
38
|
-
partitions?: number;
|
|
39
33
|
}) => Balance[];
|
|
40
34
|
private static addFinalRouterCompleteTradeRouteToRoute;
|
|
41
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/packages/router/api/routerApiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
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AAU,CAAC;QAC1B,aAAa,EAAE,wBAAwB,CAAC;QACxC,QAAQ,EAAE,QAAQ,CAAC;KACnB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IActB,uBAAuB,WAAY;QACzC,YAAY,EAAE,OAAO,CAAC;KACtB,KAAG,OAAO,EAAE,CAmBX;IAUF,OAAO,CAAC,MAAM,CAAC,uCAAuC,CA2CpD;CACF"}
|
|
@@ -19,7 +19,8 @@ class RouterApiHelpers {
|
|
|
19
19
|
// =========================================================================
|
|
20
20
|
// Constructor
|
|
21
21
|
// =========================================================================
|
|
22
|
-
constructor(Provider) {
|
|
22
|
+
constructor(Provider, options) {
|
|
23
|
+
this.options = options;
|
|
23
24
|
// =========================================================================
|
|
24
25
|
// Public Methods
|
|
25
26
|
// =========================================================================
|
|
@@ -39,12 +40,12 @@ class RouterApiHelpers {
|
|
|
39
40
|
if (inputs.protocols.length === 0)
|
|
40
41
|
throw new Error("no protocols set in constructor");
|
|
41
42
|
const { network, graph, coinInAmount } = inputs;
|
|
42
|
-
const coinInAmounts =
|
|
43
|
+
const coinInAmounts = this.amountsInForRouterTrade({
|
|
43
44
|
coinInAmount,
|
|
44
45
|
});
|
|
45
46
|
const asyncProtocols = inputs.protocols.filter(types_1.isRouterAsyncProtocolName);
|
|
46
47
|
const { exactMatchPools, partialMatchPools } = this.AsyncHelpers.filterPossiblePools(Object.assign(Object.assign({}, inputs), { pools: Object.values(graph.pools).filter(types_1.isRouterAsyncSerializablePool), protocols: asyncProtocols }));
|
|
47
|
-
const routerGraph = new routerGraph_1.RouterGraph(network, graph);
|
|
48
|
+
const routerGraph = new routerGraph_1.RouterGraph(network, graph, this.options.regular.synchronous);
|
|
48
49
|
if (exactMatchPools.length <= 0 && partialMatchPools.length <= 0)
|
|
49
50
|
return routerGraph.getCompleteRouteGivenAmountIn(inputs);
|
|
50
51
|
const [exactTradeResults, completeRoutesForLastPoolAsync] = yield Promise.all([
|
|
@@ -53,7 +54,8 @@ class RouterApiHelpers {
|
|
|
53
54
|
coinInAmounts,
|
|
54
55
|
lastPool })))),
|
|
55
56
|
]);
|
|
56
|
-
|
|
57
|
+
// NOTE: is this actually needed ?
|
|
58
|
+
routerGraph.updateOptions(this.options.regular.synchronous);
|
|
57
59
|
const synchronousCompleteRoutes = routerGraph.getCompleteRoutesGivenAmountIns(Object.assign(Object.assign({}, inputs), { coinInAmounts }));
|
|
58
60
|
const allCompleteRoutes = [
|
|
59
61
|
...completeRoutesForLastPoolAsync,
|
|
@@ -76,11 +78,7 @@ class RouterApiHelpers {
|
|
|
76
78
|
coinType: inputs.coinOutType,
|
|
77
79
|
pool: inputs.lastPool,
|
|
78
80
|
});
|
|
79
|
-
routerGraph.updateOptions(
|
|
80
|
-
maxRouteLength: 2,
|
|
81
|
-
tradePartitionCount: 1,
|
|
82
|
-
// maxGasCost: BigInt(333_333_333), // 0.333 SUI
|
|
83
|
-
});
|
|
81
|
+
routerGraph.updateOptions(this.options.preAsync);
|
|
84
82
|
const synchronousCompleteRoutes = routerGraph.getCompleteRoutesGivenAmountIns(Object.assign(Object.assign({}, inputs), { coinOutType: lastPoolCoinInType }));
|
|
85
83
|
const lastPoolCoinInAmounts = synchronousCompleteRoutes.map((route) => route.coinOut.amount);
|
|
86
84
|
const tradeResults = yield this.AsyncHelpers.fetchTradeResults(Object.assign(Object.assign({}, inputs), { coinInType: lastPoolCoinInType, pools: [inputs.lastPool], coinInAmounts: lastPoolCoinInAmounts }));
|
|
@@ -95,8 +93,26 @@ class RouterApiHelpers {
|
|
|
95
93
|
? []
|
|
96
94
|
: finalCompleteRoutes;
|
|
97
95
|
});
|
|
96
|
+
// =========================================================================
|
|
97
|
+
// Public Static Methods
|
|
98
|
+
// =========================================================================
|
|
99
|
+
// =========================================================================
|
|
100
|
+
// Helpers
|
|
101
|
+
// =========================================================================
|
|
102
|
+
this.amountsInForRouterTrade = (inputs) => {
|
|
103
|
+
const { coinInAmount } = inputs;
|
|
104
|
+
const partitions = this.options.regular.async.tradePartitionCount;
|
|
105
|
+
const coinInPartitionAmount = coinInAmount / BigInt(Math.floor(partitions));
|
|
106
|
+
const coinInRemainderAmount = coinInAmount % BigInt(Math.floor(partitions));
|
|
107
|
+
const amountsIn = Array(partitions)
|
|
108
|
+
.fill(0)
|
|
109
|
+
.map((_, index) => index === 0
|
|
110
|
+
? coinInRemainderAmount + coinInPartitionAmount
|
|
111
|
+
: BigInt(1 + index) * coinInPartitionAmount);
|
|
112
|
+
return amountsIn;
|
|
113
|
+
};
|
|
98
114
|
this.SynchronousHelpers = new routerSynchronousApiHelpers_1.RouterSynchronousApiHelpers(Provider);
|
|
99
|
-
this.AsyncHelpers = new routerAsyncApiHelpers_1.RouterAsyncApiHelpers(Provider);
|
|
115
|
+
this.AsyncHelpers = new routerAsyncApiHelpers_1.RouterAsyncApiHelpers(Provider, options.regular.async);
|
|
100
116
|
}
|
|
101
117
|
// public fetchCompleteTradeRouteGivenAmountIn = async (inputs: {
|
|
102
118
|
// protocols: RouterProtocolName[];
|
|
@@ -146,34 +162,6 @@ class RouterApiHelpers {
|
|
|
146
162
|
}
|
|
147
163
|
exports.RouterApiHelpers = RouterApiHelpers;
|
|
148
164
|
// =========================================================================
|
|
149
|
-
// Constants
|
|
150
|
-
// =========================================================================
|
|
151
|
-
RouterApiHelpers.constants = {
|
|
152
|
-
defaults: {
|
|
153
|
-
tradePartitionCount: 2,
|
|
154
|
-
maxAsyncPoolsPerProtocol: 2,
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
// =========================================================================
|
|
158
|
-
// Public Static Methods
|
|
159
|
-
// =========================================================================
|
|
160
|
-
// =========================================================================
|
|
161
|
-
// Helpers
|
|
162
|
-
// =========================================================================
|
|
163
|
-
RouterApiHelpers.amountsInForRouterTrade = (inputs) => {
|
|
164
|
-
const { coinInAmount } = inputs;
|
|
165
|
-
const partitions = inputs.partitions ||
|
|
166
|
-
RouterApiHelpers.constants.defaults.tradePartitionCount;
|
|
167
|
-
const coinInPartitionAmount = coinInAmount / BigInt(Math.floor(partitions));
|
|
168
|
-
const coinInRemainderAmount = coinInAmount % BigInt(Math.floor(partitions));
|
|
169
|
-
const amountsIn = Array(partitions)
|
|
170
|
-
.fill(0)
|
|
171
|
-
.map((_, index) => index === 0
|
|
172
|
-
? coinInRemainderAmount + coinInPartitionAmount
|
|
173
|
-
: BigInt(1 + index) * coinInPartitionAmount);
|
|
174
|
-
return amountsIn;
|
|
175
|
-
};
|
|
176
|
-
// =========================================================================
|
|
177
165
|
// Private Methods
|
|
178
166
|
// =========================================================================
|
|
179
167
|
// =========================================================================
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { AftermathApi } from "../../../general/providers/aftermathApi";
|
|
2
|
-
import { RouterAsyncProtocolName, RouterAsyncSerializablePool, RouterAsyncTradeResults } from "../routerTypes";
|
|
2
|
+
import { RouterAsyncOptions, RouterAsyncProtocolName, RouterAsyncSerializablePool, RouterAsyncTradeResults } from "../routerTypes";
|
|
3
3
|
import { Balance, CoinType } from "../../../types";
|
|
4
4
|
import { RouterAsyncApiInterface } from "../utils/async/routerAsyncApiInterface";
|
|
5
5
|
export declare class RouterAsyncApiHelpers {
|
|
6
6
|
private readonly Provider;
|
|
7
|
+
private readonly options;
|
|
7
8
|
readonly protocolNamesToApi: Record<RouterAsyncProtocolName, () => RouterAsyncApiInterface<any>>;
|
|
8
|
-
constructor(Provider: AftermathApi);
|
|
9
|
+
constructor(Provider: AftermathApi, options: RouterAsyncOptions);
|
|
9
10
|
fetchAllPools: (inputs: {
|
|
10
11
|
protocols: RouterAsyncProtocolName[];
|
|
11
12
|
}) => Promise<RouterAsyncSerializablePool[]>;
|
|
@@ -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,EACvB,2BAA2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U,EAAE,QAAQ,CAAC;QACrB,WAAW,EAAE,QAAQ,CAAC;QACtB,aAAa,EAAE,OAAO,EAAE,CAAC;KACzB,KAAG,QAAQ,uBAAuB,CAAC,CAqDlC;IAMK,oBAAoB,WAAY;QACtC,IAAI,EAAE,2BAA2B,CAAC;KAClC,KAAG,uBAAuB,CAgBzB;IAUF,OAAO,CAAC,qBAAqB,CAK3B;CACF"}
|
|
@@ -16,13 +16,13 @@ const turbosTypes_1 = require("../../external/turbos/turbosTypes");
|
|
|
16
16
|
const cetusTypes_1 = require("../../external/cetus/cetusTypes");
|
|
17
17
|
const deepBookApi_1 = require("../../external/deepBook/deepBookApi");
|
|
18
18
|
const deepBookTypes_1 = require("../../external/deepBook/deepBookTypes");
|
|
19
|
-
const routerApiHelpers_1 = require("./routerApiHelpers");
|
|
20
19
|
class RouterAsyncApiHelpers {
|
|
21
20
|
// =========================================================================
|
|
22
21
|
// Constructor
|
|
23
22
|
// =========================================================================
|
|
24
|
-
constructor(Provider) {
|
|
23
|
+
constructor(Provider, options) {
|
|
25
24
|
this.Provider = Provider;
|
|
25
|
+
this.options = options;
|
|
26
26
|
// =========================================================================
|
|
27
27
|
// Constants
|
|
28
28
|
// =========================================================================
|
|
@@ -42,7 +42,7 @@ class RouterAsyncApiHelpers {
|
|
|
42
42
|
});
|
|
43
43
|
this.filterPossiblePools = (inputs) => {
|
|
44
44
|
const apis = inputs.protocols.map((protocol) => this.protocolNamesToApi[protocol]());
|
|
45
|
-
const maxPools =
|
|
45
|
+
const maxPools = this.options.maxAsyncPoolsPerProtocol;
|
|
46
46
|
const allPools = apis
|
|
47
47
|
.map((api) => api.filterPoolsForTrade(inputs))
|
|
48
48
|
.reduce((acc, pools) => {
|
|
@@ -119,7 +119,6 @@ class RouterAsyncApiHelpers {
|
|
|
119
119
|
const { protocols } = inputs;
|
|
120
120
|
return protocols.map((name) => this.protocolNamesToApi[name]());
|
|
121
121
|
};
|
|
122
|
-
this.Provider = Provider;
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
124
|
exports.RouterAsyncApiHelpers = RouterAsyncApiHelpers;
|
|
@@ -71,12 +71,28 @@ export interface RouterSerializableCompleteGraph {
|
|
|
71
71
|
pools: RouterSerializablePoolsById;
|
|
72
72
|
}
|
|
73
73
|
export type RouterSupportedCoinPaths = Record<CoinType, CoinType[]>;
|
|
74
|
-
export interface
|
|
74
|
+
export interface RouterSynchronousOptions {
|
|
75
75
|
maxRouteLength: number;
|
|
76
76
|
tradePartitionCount: number;
|
|
77
77
|
minRoutesToCheck: number;
|
|
78
78
|
maxGasCost: bigint;
|
|
79
79
|
}
|
|
80
|
+
export interface RouterAsyncOptions {
|
|
81
|
+
tradePartitionCount: number;
|
|
82
|
+
maxAsyncPoolsPerProtocol: number;
|
|
83
|
+
}
|
|
84
|
+
interface RouterOptions {
|
|
85
|
+
synchronous: RouterSynchronousOptions;
|
|
86
|
+
async: RouterAsyncOptions;
|
|
87
|
+
}
|
|
88
|
+
export interface PartialRouterOptions {
|
|
89
|
+
synchronous?: Partial<RouterSynchronousOptions>;
|
|
90
|
+
async?: Partial<RouterAsyncOptions>;
|
|
91
|
+
}
|
|
92
|
+
export interface AllRouterOptions {
|
|
93
|
+
regular: RouterOptions;
|
|
94
|
+
preAsync: RouterSynchronousOptions;
|
|
95
|
+
}
|
|
80
96
|
export type RouterSerializablePoolsById = Record<UniqueId, RouterSerializablePool>;
|
|
81
97
|
export type RouterGraphCoinNodes = Record<CoinType, RouterCoinNode>;
|
|
82
98
|
export type RouterPoolsById = Record<UniqueId, RouterPoolInterface>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routerTypes.d.ts","sourceRoot":"","sources":["../../../src/packages/router/routerTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACN,aAAa,EACb,OAAO,EACP,UAAU,EACV,KAAK,EACL,QAAQ,EACR,aAAa,EACb,M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AQ,CAAC;CACnB;AAED,MAAM,MAAM,wBAAwB,GAAG,aAAa,GAAG;IACtD,aAAa,EAAE,UAAU,CAAC;CAC1B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CoinType } from "../../../coin/coinTypes";
|
|
2
|
-
import { Balance, RouterCompleteGraph, RouterCompleteTradeRoute, RouterExternalFee,
|
|
2
|
+
import { Balance, RouterCompleteGraph, RouterCompleteTradeRoute, RouterExternalFee, RouterSynchronousOptions, RouterSerializableCompleteGraph, RouterSupportedCoinPaths, RouterTradeInfo, SuiNetwork, UniqueId, Url, RouterSerializablePool } from "../../../../types";
|
|
3
3
|
import { SuiAddress } from "@mysten/sui.js";
|
|
4
4
|
type CompleteTradeRoute = {
|
|
5
5
|
routes: TradeRoute[];
|
|
@@ -14,11 +14,10 @@ type TradeInfo = RouterTradeInfo & {
|
|
|
14
14
|
estimatedGasCost: Balance;
|
|
15
15
|
};
|
|
16
16
|
export declare class RouterGraph {
|
|
17
|
-
|
|
17
|
+
private options;
|
|
18
18
|
readonly graph: RouterCompleteGraph;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
updateOptions(partialOptions: Partial<RouterOptions>): void;
|
|
19
|
+
constructor(network: SuiNetwork | Url, graph: RouterSerializableCompleteGraph, options: RouterSynchronousOptions);
|
|
20
|
+
updateOptions(partialOptions: Partial<RouterSynchronousOptions>): void;
|
|
22
21
|
getCompleteRouteGivenAmountIn(inputs: {
|
|
23
22
|
coinInType: CoinType;
|
|
24
23
|
coinInAmount: Balance;
|
|
@@ -42,7 +41,7 @@ export declare class RouterGraph {
|
|
|
42
41
|
}): RouterCompleteGraph;
|
|
43
42
|
static supportedCoinPathsFromGraph: (inputs: {
|
|
44
43
|
graph: RouterSerializableCompleteGraph;
|
|
45
|
-
maxRouteLength
|
|
44
|
+
maxRouteLength: number;
|
|
46
45
|
}) => Promise<RouterSupportedCoinPaths>;
|
|
47
46
|
private getCompleteRoute;
|
|
48
47
|
private static updateCoinNodesFromPool;
|
|
@@ -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,
|
|
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,wBAAwB,EACxB,+BAA+B,EAC/B,wBAAwB,EAExB,eAAe,EAIf,UAAU,EACV,QAAQ,EACR,GAAG,EAIH,sBAAsB,EACtB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAO5C,KAAK,kBAAkB,GAAG;IACzB,MAAM,EAAE,UAAU,EAAE,CAAC;CACrB,GAAG,SAAS,CAAC;AAEd,KAAK,UAAU,GAAG;IACjB,KAAK,EAAE,SAAS,EAAE,CAAC;CACnB,GAAG,SAAS,CAAC;AAEd,KAAK,SAAS,GAAG,SAAS,GAAG;IAC5B,OAAO,EAAE,QAAQ,CAAC;CAClB,CAAC;AAEF,KAAK,SAAS,GAAG,eAAe,GAAG;IAClC,gBAAgB,EAAE,OAAO,CAAC;CAC1B,CAAC;AAMF,qBAAa,WAAW;IAkBtB,OAAO,CAAC,OAAO;IAThB,SAAgB,KAAK,EAAE,mBAAmB,CAAC;gBAO1C,OAAO,EAAE,UAAU,GAAG,GAAG,EACzB,KAAK,EAAE,+BAA+B,EAC9B,OAAO,EAAE,wBAAwB;IASnC,aAAa,CAAC,cAAc,EAAE,OAAO,CAAC,wBAAwB,CAA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ACF,OAAO,WACZ,QAAQ,KACf,kBAAkB,CAgCnB;IAEF,OAAO,CAAC,MAAM,CAAC,sCAAsC,CAuBnD;IAEF,OAAO,CAAC,MAAM,CAAC,wCAAwC,CAiBrD;IAEF,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAM3B;IAEJ,OAAO,CAAC,MAAM,CAAC,eAAe,CAI3B;IAEH,OAAO,CAAC,MAAM,CAAC,8CAA8C,CAsD3D;IAMF,OAAO,CAAC,MAAM,CAAC,sBAAsB,CA8BnC;IAEF,OAAO,CAAC,MAAM,CAAC,cAAc,CA+B3B;CACF"}
|
|
@@ -22,16 +22,15 @@ class RouterGraph {
|
|
|
22
22
|
// Constructor
|
|
23
23
|
// =========================================================================
|
|
24
24
|
constructor(network, graph, options) {
|
|
25
|
+
this.options = options;
|
|
25
26
|
this.splitTradeBetweenRoutes = (graph, routes, coinInAmount, isGivenAmountOut, referrer) => {
|
|
26
|
-
const coinInPartitionAmount = coinInAmount /
|
|
27
|
-
|
|
28
|
-
const coinInRemainderAmount = coinInAmount %
|
|
29
|
-
BigInt(Math.floor(this.constants.tradePartitionCount));
|
|
27
|
+
const coinInPartitionAmount = coinInAmount / BigInt(Math.floor(this.options.tradePartitionCount));
|
|
28
|
+
const coinInRemainderAmount = coinInAmount % BigInt(Math.floor(this.options.tradePartitionCount));
|
|
30
29
|
let currentPools = graph.pools;
|
|
31
30
|
let currentRoutes = routes;
|
|
32
|
-
const emptyArray = Array(this.
|
|
33
|
-
const linearCutStepSize = (routes.length - this.
|
|
34
|
-
this.
|
|
31
|
+
const emptyArray = Array(this.options.tradePartitionCount).fill(undefined);
|
|
32
|
+
const linearCutStepSize = (routes.length - this.options.minRoutesToCheck) /
|
|
33
|
+
this.options.tradePartitionCount;
|
|
35
34
|
for (const [i] of emptyArray.entries()) {
|
|
36
35
|
const { updatedPools, updatedRoutes } = this.findNextRouteAndUpdatePoolsAndRoutes(helpers_1.Helpers.deepCopy(currentPools), helpers_1.Helpers.deepCopy(currentRoutes), i === 0
|
|
37
36
|
? coinInRemainderAmount + coinInPartitionAmount
|
|
@@ -81,9 +80,9 @@ class RouterGraph {
|
|
|
81
80
|
const firstUnusedRouteIndex = sortedRoutesAndPoolsByAmountOut.findIndex((route) => route.startingRoute.coinOut.amount <= BigInt(0));
|
|
82
81
|
let newEndIndex;
|
|
83
82
|
if (routeDecreaseType === "QUADRATIC") {
|
|
84
|
-
const minRouteIndexToCheck = firstUnusedRouteIndex > this.
|
|
83
|
+
const minRouteIndexToCheck = firstUnusedRouteIndex > this.options.minRoutesToCheck
|
|
85
84
|
? firstUnusedRouteIndex
|
|
86
|
-
: this.
|
|
85
|
+
: this.options.minRoutesToCheck;
|
|
87
86
|
newEndIndex = Math.floor((minRouteIndexToCheck +
|
|
88
87
|
sortedRoutesAndPoolsByAmountOut.length) /
|
|
89
88
|
2);
|
|
@@ -95,8 +94,8 @@ class RouterGraph {
|
|
|
95
94
|
}
|
|
96
95
|
const cutRoutesAndPools = sortedRoutesAndPoolsByAmountOut.slice(0, newEndIndex > sortedRoutesAndPoolsByAmountOut.length
|
|
97
96
|
? sortedRoutesAndPoolsByAmountOut.length
|
|
98
|
-
: newEndIndex < this.
|
|
99
|
-
? this.
|
|
97
|
+
: newEndIndex < this.options.minRoutesToCheck
|
|
98
|
+
? this.options.minRoutesToCheck
|
|
100
99
|
: newEndIndex);
|
|
101
100
|
return {
|
|
102
101
|
updatedPools: cutRoutesAndPools[0].updatedPools,
|
|
@@ -108,7 +107,7 @@ class RouterGraph {
|
|
|
108
107
|
const originalRoute = helpers_1.Helpers.deepCopy(route);
|
|
109
108
|
const isOverMaxGasCost = originalRoute.coinIn.amount <= BigInt(0) &&
|
|
110
109
|
RouterGraph.gasCostForRoute(originalRoute) + currentGasCost >
|
|
111
|
-
this.
|
|
110
|
+
this.options.maxGasCost;
|
|
112
111
|
let currentPools = helpers_1.Helpers.deepCopy(pools);
|
|
113
112
|
let currentCoinInAmount = coinInAmount;
|
|
114
113
|
let newRoute = Object.assign(Object.assign({}, originalRoute), { paths: [] });
|
|
@@ -184,13 +183,12 @@ class RouterGraph {
|
|
|
184
183
|
}
|
|
185
184
|
};
|
|
186
185
|
this.graph = RouterGraph.graphFromSerializable({ graph, network });
|
|
187
|
-
this.constants = Object.assign(Object.assign({}, RouterGraph.defaultOptions), options);
|
|
188
186
|
}
|
|
189
187
|
// =========================================================================
|
|
190
188
|
// Public Methods
|
|
191
189
|
// =========================================================================
|
|
192
190
|
updateOptions(partialOptions) {
|
|
193
|
-
this.
|
|
191
|
+
this.options = Object.assign(Object.assign({}, this.options), partialOptions);
|
|
194
192
|
}
|
|
195
193
|
getCompleteRouteGivenAmountIn(inputs) {
|
|
196
194
|
const result = this.getCompleteRoute(Object.assign(Object.assign({}, inputs), { isGivenAmountOut: false }));
|
|
@@ -310,7 +308,7 @@ class RouterGraph {
|
|
|
310
308
|
externalFee.feePercentage >=
|
|
311
309
|
router_1.Router.constants.maxExternalFeePercentage)
|
|
312
310
|
throw new Error(`external fee percentage exceeds max of ${router_1.Router.constants.maxExternalFeePercentage}`);
|
|
313
|
-
const routes = RouterGraph.findRoutes(helpers_1.Helpers.deepCopy(this.graph), coinInType, coinOutType, this.
|
|
311
|
+
const routes = RouterGraph.findRoutes(helpers_1.Helpers.deepCopy(this.graph), coinInType, coinOutType, this.options.maxRouteLength, isGivenAmountOut);
|
|
314
312
|
const routesAfterTrades = this.splitTradeBetweenRoutes(helpers_1.Helpers.deepCopy(this.graph), routes, coinInAmount, isGivenAmountOut, referrer);
|
|
315
313
|
const completeRoute = RouterGraph.completeRouteFromRoutes(routesAfterTrades, coinInType, coinInAmount, coinOutType);
|
|
316
314
|
const transformedRoute = isGivenAmountOut
|
|
@@ -323,20 +321,10 @@ class RouterGraph {
|
|
|
323
321
|
exports.RouterGraph = RouterGraph;
|
|
324
322
|
_a = RouterGraph;
|
|
325
323
|
// =========================================================================
|
|
326
|
-
// Public Static Constants
|
|
327
|
-
// =========================================================================
|
|
328
|
-
RouterGraph.defaultOptions = {
|
|
329
|
-
maxRouteLength: 3,
|
|
330
|
-
tradePartitionCount: 3,
|
|
331
|
-
minRoutesToCheck: 5,
|
|
332
|
-
maxGasCost: BigInt(500000000), // 0.5 SUI
|
|
333
|
-
};
|
|
334
|
-
// =========================================================================
|
|
335
324
|
// Supported Coins
|
|
336
325
|
// =========================================================================
|
|
337
326
|
// TODO: do this more efficiently
|
|
338
327
|
RouterGraph.supportedCoinPathsFromGraph = (inputs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
339
|
-
var _b;
|
|
340
328
|
const nodes = Object.values(inputs.graph.coinNodes);
|
|
341
329
|
const pools = inputs.graph.pools;
|
|
342
330
|
let startingUnhoppableCoinPaths = {};
|
|
@@ -367,7 +355,7 @@ RouterGraph.supportedCoinPathsFromGraph = (inputs) => __awaiter(void 0, void 0,
|
|
|
367
355
|
}, {});
|
|
368
356
|
const regularCoinPaths = _a.extendCoinPathsForHops({
|
|
369
357
|
startingCoinPaths,
|
|
370
|
-
maxHops:
|
|
358
|
+
maxHops: inputs.maxRouteLength,
|
|
371
359
|
});
|
|
372
360
|
const unhoppableCoinPaths = _a.extendCoinPathsForHops({
|
|
373
361
|
startingCoinPaths: startingUnhoppableCoinPaths,
|