aftermath-ts-sdk 0.0.126 → 0.0.128
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/inspectionsApiHelpers.d.ts +2 -2
- package/dist/general/api/inspectionsApiHelpers.d.ts.map +1 -1
- package/dist/general/api/inspectionsApiHelpers.js +7 -4
- package/dist/general/api/transactionsApiHelpers.d.ts.map +1 -1
- package/dist/general/api/transactionsApiHelpers.js +2 -1
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/types/castingTypes.d.ts +6 -0
- package/dist/general/types/castingTypes.d.ts.map +1 -1
- package/dist/general/types/configTypes.d.ts +24 -1
- package/dist/general/types/configTypes.d.ts.map +1 -1
- package/dist/general/utils/casting.d.ts +1 -0
- package/dist/general/utils/casting.d.ts.map +1 -1
- package/dist/general/utils/casting.js +1 -0
- package/dist/packages/capys/api/capysApiHelpers.d.ts.map +1 -1
- package/dist/packages/capys/api/capysApiHelpers.js +13 -13
- package/dist/packages/coin/api/coinApiHelpers.d.ts +7 -1
- package/dist/packages/coin/api/coinApiHelpers.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApiHelpers.js +36 -23
- package/dist/packages/external/cetus/cetusApi.d.ts +33 -0
- package/dist/packages/external/cetus/cetusApi.d.ts.map +1 -0
- package/dist/packages/external/cetus/cetusApi.js +56 -0
- package/dist/packages/external/cetus/cetusApiHelpers.d.ts +197 -0
- package/dist/packages/external/cetus/cetusApiHelpers.d.ts.map +1 -0
- package/dist/packages/external/cetus/cetusApiHelpers.js +232 -0
- package/dist/packages/external/cetus/cetusTypes.d.ts +15 -0
- package/dist/packages/external/cetus/cetusTypes.d.ts.map +1 -0
- package/dist/packages/external/cetus/cetusTypes.js +7 -0
- package/dist/packages/external/deepBook/deepBookApi.d.ts +1 -1
- package/dist/packages/external/deepBook/deepBookApi.d.ts.map +1 -1
- package/dist/packages/external/deepBook/deepBookApiHelper.d.ts.map +1 -1
- package/dist/packages/external/deepBook/deepBookApiHelper.js +5 -6
- package/dist/packages/external/deepBook/deepBookTypes.d.ts.map +1 -1
- package/dist/packages/external/nojo/nojoAmmApi.d.ts +1 -1
- package/dist/packages/external/nojo/nojoAmmApi.d.ts.map +1 -1
- package/dist/packages/external/nojo/nojoAmmTypes.d.ts.map +1 -1
- package/dist/packages/external/turbos/turbosApi.d.ts +33 -0
- package/dist/packages/external/turbos/turbosApi.d.ts.map +1 -0
- package/dist/packages/external/turbos/turbosApi.js +56 -0
- package/dist/packages/external/turbos/turbosApiHelpers.d.ts +192 -0
- package/dist/packages/external/turbos/turbosApiHelpers.d.ts.map +1 -0
- package/dist/packages/external/turbos/turbosApiHelpers.js +266 -0
- package/dist/packages/external/turbos/turbosTypes.d.ts +18 -0
- package/dist/packages/external/turbos/turbosTypes.d.ts.map +1 -0
- package/dist/packages/external/turbos/turbosTypes.js +12 -0
- package/dist/packages/faucet/api/faucetApiHelpers.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApiHelpers.js +4 -4
- package/dist/packages/nftAmm/api/nftAmmApiHelpers.js +4 -5
- package/dist/packages/pools/api/poolsApi.js +1 -1
- package/dist/packages/pools/api/poolsApiHelpers.d.ts +1 -1
- package/dist/packages/pools/api/poolsApiHelpers.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApiHelpers.js +11 -10
- package/dist/packages/referralVault/api/referralVaultApi.js +2 -2
- package/dist/packages/referralVault/api/referralVaultApiHelpers.d.ts.map +1 -1
- package/dist/packages/referralVault/api/referralVaultApiHelpers.js +6 -6
- package/dist/packages/router/api/routerApi.d.ts +18 -5
- package/dist/packages/router/api/routerApi.d.ts.map +1 -1
- package/dist/packages/router/api/routerApi.js +45 -11
- package/dist/packages/router/api/routerAsyncApiHelpers.d.ts +16 -0
- package/dist/packages/router/api/routerAsyncApiHelpers.d.ts.map +1 -0
- package/dist/packages/router/api/routerAsyncApiHelpers.js +94 -0
- package/dist/packages/router/api/{routerApiHelpers.d.ts → routerSynchronousApiHelpers.d.ts} +13 -7
- package/dist/packages/router/api/routerSynchronousApiHelpers.d.ts.map +1 -0
- package/dist/packages/router/api/{routerApiHelpers.js → routerSynchronousApiHelpers.js} +74 -26
- package/dist/packages/router/index.d.ts +1 -1
- package/dist/packages/router/index.d.ts.map +1 -1
- package/dist/packages/router/index.js +1 -1
- package/dist/packages/router/router.d.ts +0 -1
- package/dist/packages/router/router.d.ts.map +1 -1
- package/dist/packages/router/router.js +9 -5
- package/dist/packages/router/routerTypes.d.ts +27 -10
- package/dist/packages/router/routerTypes.d.ts.map +1 -1
- package/dist/packages/router/routerTypes.js +17 -0
- package/dist/packages/router/utils/async/routerAsyncApiInterface.d.ts +24 -0
- package/dist/packages/router/utils/async/routerAsyncApiInterface.d.ts.map +1 -0
- package/dist/packages/router/utils/async/routerAsyncGraph.d.ts +12 -0
- package/dist/packages/router/utils/async/routerAsyncGraph.d.ts.map +1 -0
- package/dist/packages/router/utils/async/routerAsyncGraph.js +115 -0
- package/dist/packages/router/utils/{routerApiInterface.d.ts → synchronous/interfaces/routerApiInterface.d.ts} +2 -2
- package/dist/packages/router/utils/synchronous/interfaces/routerApiInterface.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/interfaces/routerApiInterface.js +2 -0
- package/dist/packages/router/utils/{routerPoolInterface.d.ts → synchronous/interfaces/routerPoolInterface.d.ts} +5 -3
- package/dist/packages/router/utils/synchronous/interfaces/routerPoolInterface.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/interfaces/routerPoolInterface.js +32 -0
- package/dist/packages/router/utils/{routerGraph.d.ts → synchronous/routerGraph.d.ts} +30 -5
- package/dist/packages/router/utils/synchronous/routerGraph.d.ts.map +1 -0
- package/dist/packages/router/utils/{routerGraph.js → synchronous/routerGraph.js} +84 -15
- package/dist/packages/router/utils/{routerPools → synchronous/routerPools}/aftermathRouterPool.d.ts +7 -5
- package/dist/packages/router/utils/synchronous/routerPools/aftermathRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/{routerPools → synchronous/routerPools}/aftermathRouterPool.js +3 -3
- package/dist/packages/router/utils/synchronous/routerPools/cetusRouterPool.d.ts +85 -0
- package/dist/packages/router/utils/synchronous/routerPools/cetusRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/routerPools/cetusRouterPool.js +41 -0
- package/dist/packages/router/utils/{routerPools → synchronous/routerPools}/deepBookRouterPool.d.ts +7 -5
- package/dist/packages/router/utils/synchronous/routerPools/deepBookRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/{routerPools → synchronous/routerPools}/deepBookRouterPool.js +2 -2
- package/dist/packages/router/utils/{routerPools → synchronous/routerPools}/nojoRouterPool.d.ts +7 -5
- package/dist/packages/router/utils/synchronous/routerPools/nojoRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/{routerPools → synchronous/routerPools}/nojoRouterPool.js +3 -3
- package/dist/packages/router/utils/synchronous/routerPools/turbosRouterPool.d.ts +85 -0
- package/dist/packages/router/utils/synchronous/routerPools/turbosRouterPool.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/routerPools/turbosRouterPool.js +43 -0
- package/dist/packages/router/utils/synchronous/routerTest.d.ts.map +1 -0
- package/dist/packages/router/utils/synchronous/routerTest.js +124 -0
- package/dist/packages/staking/api/stakingApi.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApi.js +4 -2
- package/dist/packages/staking/api/stakingApiHelpers.js +4 -4
- package/dist/packages/staking/staking.d.ts +0 -4
- package/dist/packages/staking/staking.d.ts.map +1 -1
- package/dist/packages/staking/staking.js +1 -5
- package/package.json +1 -1
- package/dist/packages/router/api/routerApiHelpers.d.ts.map +0 -1
- package/dist/packages/router/utils/routerApiInterface.d.ts.map +0 -1
- package/dist/packages/router/utils/routerGraph.d.ts.map +0 -1
- package/dist/packages/router/utils/routerPoolInterface.d.ts.map +0 -1
- package/dist/packages/router/utils/routerPoolInterface.js +0 -24
- package/dist/packages/router/utils/routerPools/aftermathRouterPool.d.ts.map +0 -1
- package/dist/packages/router/utils/routerPools/deepBookRouterPool.d.ts.map +0 -1
- package/dist/packages/router/utils/routerPools/nojoRouterPool.d.ts.map +0 -1
- package/dist/packages/router/utils/routerTest.d.ts.map +0 -1
- package/dist/packages/router/utils/routerTest.js +0 -105
- /package/dist/packages/router/utils/{routerApiInterface.js → async/routerAsyncApiInterface.js} +0 -0
- /package/dist/packages/router/utils/{routerTest.d.ts → synchronous/routerTest.d.ts} +0 -0
|
@@ -9,15 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.RouterSynchronousApiHelpers = void 0;
|
|
13
13
|
const sui_js_1 = require("@mysten/sui.js");
|
|
14
|
-
const routerPoolInterface_1 = require("../utils/routerPoolInterface");
|
|
14
|
+
const routerPoolInterface_1 = require("../utils/synchronous/interfaces/routerPoolInterface");
|
|
15
15
|
const router_1 = require("../router");
|
|
16
16
|
const poolsApi_1 = require("../../pools/api/poolsApi");
|
|
17
17
|
const nojoAmmApi_1 = require("../../external/nojo/nojoAmmApi");
|
|
18
18
|
const deepBookApi_1 = require("../../external/deepBook/deepBookApi");
|
|
19
19
|
const utils_1 = require("../../../general/utils");
|
|
20
|
-
|
|
20
|
+
const cetusApi_1 = require("../../external/cetus/cetusApi");
|
|
21
|
+
const turbosApi_1 = require("../../external/turbos/turbosApi");
|
|
22
|
+
class RouterSynchronousApiHelpers {
|
|
21
23
|
/////////////////////////////////////////////////////////////////////
|
|
22
24
|
//// Constructor
|
|
23
25
|
/////////////////////////////////////////////////////////////////////
|
|
@@ -27,9 +29,11 @@ class RouterApiHelpers {
|
|
|
27
29
|
//// Constants
|
|
28
30
|
/////////////////////////////////////////////////////////////////////
|
|
29
31
|
this.protocolNamesToApi = {
|
|
30
|
-
Aftermath: new poolsApi_1.PoolsApi(this.Provider),
|
|
31
|
-
Nojo: new nojoAmmApi_1.NojoAmmApi(this.Provider),
|
|
32
|
-
DeepBook: new deepBookApi_1.DeepBookApi(this.Provider),
|
|
32
|
+
Aftermath: () => new poolsApi_1.PoolsApi(this.Provider),
|
|
33
|
+
Nojo: () => new nojoAmmApi_1.NojoAmmApi(this.Provider),
|
|
34
|
+
DeepBook: () => new deepBookApi_1.DeepBookApi(this.Provider),
|
|
35
|
+
Cetus: () => new cetusApi_1.CetusApi(this.Provider),
|
|
36
|
+
Turbos: () => new turbosApi_1.TurbosApi(this.Provider),
|
|
33
37
|
};
|
|
34
38
|
/////////////////////////////////////////////////////////////////////
|
|
35
39
|
//// Objects
|
|
@@ -53,11 +57,14 @@ class RouterApiHelpers {
|
|
|
53
57
|
return coins;
|
|
54
58
|
});
|
|
55
59
|
/////////////////////////////////////////////////////////////////////
|
|
60
|
+
//// Private Methods
|
|
61
|
+
/////////////////////////////////////////////////////////////////////
|
|
62
|
+
/////////////////////////////////////////////////////////////////////
|
|
56
63
|
//// Helpers
|
|
57
64
|
/////////////////////////////////////////////////////////////////////
|
|
58
65
|
this.protocolApisFromNames = (inputs) => {
|
|
59
66
|
const { protocols } = inputs;
|
|
60
|
-
return protocols.map((name) => this.protocolNamesToApi[name]);
|
|
67
|
+
return protocols.map((name) => this.protocolNamesToApi[name]());
|
|
61
68
|
};
|
|
62
69
|
this.Provider = Provider;
|
|
63
70
|
}
|
|
@@ -93,42 +100,83 @@ class RouterApiHelpers {
|
|
|
93
100
|
coin: coinInArg,
|
|
94
101
|
amounts: [tx.pure(route.coinIn.amount)],
|
|
95
102
|
});
|
|
103
|
+
// completeRoute.routes.length > 1
|
|
104
|
+
// ? tx.add({
|
|
105
|
+
// kind: "SplitCoins",
|
|
106
|
+
// coin: coinInArg,
|
|
107
|
+
// amounts: [tx.pure(route.coinIn.amount)],
|
|
108
|
+
// })
|
|
109
|
+
// : [coinInArg];
|
|
96
110
|
let coinIn = splitCoinArg;
|
|
97
111
|
for (const path of route.paths) {
|
|
98
|
-
const
|
|
112
|
+
const poolForPath = (0, routerPoolInterface_1.createRouterPool)({
|
|
99
113
|
pool: path.pool,
|
|
100
114
|
network,
|
|
101
|
-
})
|
|
115
|
+
});
|
|
116
|
+
if (!coinIn)
|
|
117
|
+
throw new Error("no coin in argument given for router trade command");
|
|
118
|
+
const newCoinIn = poolForPath.addTradeCommandToTransaction({
|
|
102
119
|
provider,
|
|
103
120
|
tx,
|
|
104
121
|
coinIn,
|
|
122
|
+
coinInAmount: route.coinIn.amount,
|
|
105
123
|
coinInType: path.coinIn.type,
|
|
106
124
|
coinOutType: path.coinOut.type,
|
|
107
125
|
expectedAmountOut: path.coinOut.amount,
|
|
108
126
|
slippage,
|
|
109
127
|
referrer,
|
|
110
128
|
});
|
|
111
|
-
coinIn = newCoinIn;
|
|
129
|
+
coinIn = poolForPath.noHopsAllowed ? undefined : newCoinIn;
|
|
112
130
|
}
|
|
113
|
-
|
|
131
|
+
if (coinIn)
|
|
132
|
+
coinsOut.push(coinIn);
|
|
114
133
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
if (coinsOut.length > 0) {
|
|
135
|
+
const coinOut = coinsOut[0];
|
|
136
|
+
// merge all coinsOut into a single coin
|
|
137
|
+
if (coinsOut.length > 1)
|
|
138
|
+
tx.mergeCoins(coinOut, coinsOut.slice(1));
|
|
139
|
+
if (externalFee) {
|
|
140
|
+
const feeAmount = externalFee.feePercentage *
|
|
141
|
+
Number(completeRoute.coinOut.amount);
|
|
142
|
+
const [feeCoin] = tx.add({
|
|
143
|
+
kind: "SplitCoins",
|
|
144
|
+
coin: coinOut,
|
|
145
|
+
amounts: [tx.pure(feeAmount)],
|
|
146
|
+
});
|
|
147
|
+
tx.transferObjects([feeCoin], tx.pure(externalFee.recipient));
|
|
148
|
+
}
|
|
149
|
+
tx.transferObjects([coinOut, coinInArg], tx.pure(walletAddress));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
tx.transferObjects([coinInArg], tx.pure(walletAddress));
|
|
128
153
|
}
|
|
129
|
-
tx.transferObjects([coinOut, coinInArg], tx.pure(walletAddress));
|
|
130
154
|
return tx;
|
|
131
155
|
});
|
|
132
156
|
}
|
|
133
157
|
}
|
|
134
|
-
exports.
|
|
158
|
+
exports.RouterSynchronousApiHelpers = RouterSynchronousApiHelpers;
|
|
159
|
+
RouterSynchronousApiHelpers.constants = {
|
|
160
|
+
defaults: {
|
|
161
|
+
tradePartitionCount: 3,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
/////////////////////////////////////////////////////////////////////
|
|
165
|
+
//// Public Static Methods
|
|
166
|
+
/////////////////////////////////////////////////////////////////////
|
|
167
|
+
/////////////////////////////////////////////////////////////////////
|
|
168
|
+
//// Helpers
|
|
169
|
+
/////////////////////////////////////////////////////////////////////
|
|
170
|
+
RouterSynchronousApiHelpers.amountsInForRouterTrade = (inputs) => {
|
|
171
|
+
const { coinInAmount } = inputs;
|
|
172
|
+
const partitions = inputs.partitions ||
|
|
173
|
+
RouterSynchronousApiHelpers.constants.defaults.tradePartitionCount;
|
|
174
|
+
const coinInPartitionAmount = coinInAmount / BigInt(Math.floor(partitions));
|
|
175
|
+
const coinInRemainderAmount = coinInAmount % BigInt(Math.floor(partitions));
|
|
176
|
+
const amountsIn = Array(partitions)
|
|
177
|
+
.fill(0)
|
|
178
|
+
.map((_, index) => index === 0
|
|
179
|
+
? coinInRemainderAmount + coinInPartitionAmount
|
|
180
|
+
: BigInt(1 + index) * coinInPartitionAmount);
|
|
181
|
+
return amountsIn;
|
|
182
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/router/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packages/router/index.ts"],"names":[],"mappings":"AAAA,cAAc,oDAAoD,CAAC;AACnE,cAAc,UAAU,CAAC"}
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./utils/routerPoolInterface"), exports);
|
|
17
|
+
__exportStar(require("./utils/synchronous/interfaces/routerPoolInterface"), exports);
|
|
18
18
|
__exportStar(require("./router"), exports);
|
|
@@ -53,7 +53,6 @@ export declare class Router extends Caller {
|
|
|
53
53
|
* @param abortSignal - Optional signal to abort passed to fetch call
|
|
54
54
|
* @returns Routes, paths, and amounts of each smaller trade within complete trade
|
|
55
55
|
*/
|
|
56
|
-
getCompleteTradeRouteGivenAmountOut(inputs: ApiRouterCompleteTradeRouteBody, abortSignal?: AbortSignal): Promise<RouterCompleteTradeRoute>;
|
|
57
56
|
/**
|
|
58
57
|
* Creates `TranscationBlock` from previously created complete trade route
|
|
59
58
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/packages/router/router.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,+BAA+B,EAC/B,6CAA6C,EAE7C,wBAAwB,EACxB,+BAA+B,EAE/B,wBAAwB,EAGxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,qBAAa,MAAO,SAAQ,MAAM;aAsBL,OAAO,CAAC;IAjBpC,gBAAuB,SAAS;QAC/B;;WAEG;;MAEF;IAMF;;;;;OAKG;gBACyB,OAAO,CAAC,oBAAkB;IAYtD;;;;OAIG;IACU,qBAAqB;IAIlC;;;;OAIG;IACU,QAAQ;IAIrB;;;;;;OAMG;IACU,kCAAkC,CAC9C,MAAM,EAAE,+BAA+B,EACvC,WAAW,CAAC,EAAE,WAAW;IAQ1B;;;;;;OAMG;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/packages/router/router.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,+BAA+B,EAC/B,6CAA6C,EAE7C,wBAAwB,EACxB,+BAA+B,EAE/B,wBAAwB,EAGxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,qBAAa,MAAO,SAAQ,MAAM;aAsBL,OAAO,CAAC;IAjBpC,gBAAuB,SAAS;QAC/B;;WAEG;;MAEF;IAMF;;;;;OAKG;gBACyB,OAAO,CAAC,oBAAkB;IAYtD;;;;OAIG;IACU,qBAAqB;IAIlC;;;;OAIG;IACU,QAAQ;IAIrB;;;;;;OAMG;IACU,kCAAkC,CAC9C,MAAM,EAAE,+BAA+B,EACvC,WAAW,CAAC,EAAE,WAAW;IAQ1B;;;;;;OAMG;IAeH;;;;;;;;;;;;;;;;OAgBG;IACU,mCAAmC,CAC/C,MAAM,EAAE,6CAA6C;CAOtD"}
|
|
@@ -81,11 +81,15 @@ class Router extends caller_1.Caller {
|
|
|
81
81
|
* @param abortSignal - Optional signal to abort passed to fetch call
|
|
82
82
|
* @returns Routes, paths, and amounts of each smaller trade within complete trade
|
|
83
83
|
*/
|
|
84
|
-
getCompleteTradeRouteGivenAmountOut(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
// public async getCompleteTradeRouteGivenAmountOut(
|
|
85
|
+
// inputs: ApiRouterCompleteTradeRouteBody,
|
|
86
|
+
// abortSignal?: AbortSignal
|
|
87
|
+
// ) {
|
|
88
|
+
// return this.fetchApi<
|
|
89
|
+
// RouterCompleteTradeRoute,
|
|
90
|
+
// ApiRouterCompleteTradeRouteBody
|
|
91
|
+
// >("trade-route", inputs, abortSignal);
|
|
92
|
+
// }
|
|
89
93
|
/////////////////////////////////////////////////////////////////////
|
|
90
94
|
//// Transactions
|
|
91
95
|
/////////////////////////////////////////////////////////////////////
|
|
@@ -4,7 +4,9 @@ import { CoinType } from "../coin/coinTypes";
|
|
|
4
4
|
import { PoolObject, PoolTradeFee } from "../pools/poolsTypes";
|
|
5
5
|
import { NojoPoolObject } from "../external/nojo/nojoAmmTypes";
|
|
6
6
|
import { DeepBookPoolObject } from "../external/deepBook/deepBookTypes";
|
|
7
|
-
import { RouterPoolInterface } from "./utils/routerPoolInterface";
|
|
7
|
+
import { RouterPoolInterface } from "./utils/synchronous/interfaces/routerPoolInterface";
|
|
8
|
+
import { CetusPoolObject } from "../external/cetus/cetusTypes";
|
|
9
|
+
import { TurbosPoolObject } from "../external/turbos/turbosTypes";
|
|
8
10
|
export type UniqueId = string;
|
|
9
11
|
/**
|
|
10
12
|
* Fee info for third party packages wanting to fee route transactions
|
|
@@ -21,8 +23,16 @@ export interface RouterExternalFee {
|
|
|
21
23
|
*/
|
|
22
24
|
feePercentage: Percentage;
|
|
23
25
|
}
|
|
24
|
-
export type RouterSerializablePool =
|
|
25
|
-
export type RouterProtocolName =
|
|
26
|
+
export type RouterSerializablePool = RouterSynchronousSerializablePool | RouterAsyncSerializablePool;
|
|
27
|
+
export type RouterProtocolName = RouterSynchronousProtocolName | RouterAsyncProtocolName;
|
|
28
|
+
export type RouterSynchronousSerializablePool = PoolObject | NojoPoolObject | DeepBookPoolObject;
|
|
29
|
+
declare const RouterSynchronousProtocolNames: readonly ["Aftermath", "Nojo", "DeepBook"];
|
|
30
|
+
export type RouterSynchronousProtocolName = (typeof RouterSynchronousProtocolNames)[number];
|
|
31
|
+
export declare const isRouterSynchronousProtocolName: (protocolName: RouterProtocolName) => protocolName is "Aftermath" | "Nojo" | "DeepBook";
|
|
32
|
+
export type RouterAsyncSerializablePool = CetusPoolObject | TurbosPoolObject;
|
|
33
|
+
declare const RouterAsyncProtocolNames: readonly ["Cetus", "Turbos"];
|
|
34
|
+
export type RouterAsyncProtocolName = (typeof RouterAsyncProtocolNames)[number];
|
|
35
|
+
export declare const isRouterAsyncProtocolName: (protocolName: RouterProtocolName) => protocolName is "Cetus" | "Turbos";
|
|
26
36
|
export type RouterCompleteTradeRoute = RouterTradeInfo & {
|
|
27
37
|
routes: RouterTradeRoute[];
|
|
28
38
|
referrer?: SuiAddress;
|
|
@@ -68,6 +78,17 @@ export interface RouterCoinNode {
|
|
|
68
78
|
coinOutThroughPoolEdges: RouterCoinOutThroughPoolEdges;
|
|
69
79
|
}
|
|
70
80
|
export type RouterCoinOutThroughPoolEdges = Record<CoinType, UniqueId[]>;
|
|
81
|
+
export interface RouterAsyncTradeResults {
|
|
82
|
+
coinInType: CoinType;
|
|
83
|
+
coinOutType: CoinType;
|
|
84
|
+
coinInAmounts: Balance[];
|
|
85
|
+
results: RouterAsyncTradeResult[];
|
|
86
|
+
}
|
|
87
|
+
export interface RouterAsyncTradeResult {
|
|
88
|
+
protocol: RouterAsyncProtocolName;
|
|
89
|
+
pool: RouterAsyncSerializablePool;
|
|
90
|
+
amountsOut: Balance[];
|
|
91
|
+
}
|
|
71
92
|
/**
|
|
72
93
|
* Details for router to construct trade route
|
|
73
94
|
*/
|
|
@@ -88,17 +109,12 @@ export type ApiRouterCompleteTradeRouteBody = {
|
|
|
88
109
|
* Fee info for third party packages wanting to fee route transactions
|
|
89
110
|
*/
|
|
90
111
|
externalFee?: RouterExternalFee;
|
|
91
|
-
} &
|
|
112
|
+
} & {
|
|
92
113
|
/**
|
|
93
114
|
* Amount of coin being given away
|
|
94
115
|
*/
|
|
95
116
|
coinInAmount: Balance;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Amount of coin expected to receive
|
|
99
|
-
*/
|
|
100
|
-
coinOutAmount: Balance;
|
|
101
|
-
});
|
|
117
|
+
};
|
|
102
118
|
/**
|
|
103
119
|
* Info to construct router trade transaction from complete route
|
|
104
120
|
*/
|
|
@@ -116,4 +132,5 @@ export interface ApiRouterTransactionForCompleteTradeRouteBody {
|
|
|
116
132
|
*/
|
|
117
133
|
slippage: Slippage;
|
|
118
134
|
}
|
|
135
|
+
export {};
|
|
119
136
|
//# sourceMappingURL=routerTypes.d.ts.map
|
|
@@ -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,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,
|
|
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,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B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B,OAAO,EAAE,sBAAsB,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,IAAI,EAAE,2BAA2B,CAAC;IAClC,UAAU,EAAE,OAAO,EAAE,CAAC;CACtB;AAMD;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC7C;;OAEG;IACH,UAAU,EAAE,QAAQ,CAAC;IACrB;;OAEG;IACH,WAAW,EAAE,QAAQ,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB;;OAEG;IACH,WAAW,CAAC,EAAE,iBAAiB,CAAC;CAChC,GAAG;IACH;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;CACtB,CAAC;AAQF;;GAEG;AACH,MAAM,WAAW,6CAA6C;IAC7D;;OAEG;IACH,aAAa,EAAE,UAAU,CAAC;IAC1B;;OAEG;IACH,aAAa,EAAE,wBAAwB,CAAC;IACxC;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;CACnB"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRouterAsyncProtocolName = exports.isRouterSynchronousProtocolName = void 0;
|
|
4
|
+
const RouterSynchronousProtocolNames = [
|
|
5
|
+
"Aftermath",
|
|
6
|
+
"Nojo",
|
|
7
|
+
"DeepBook",
|
|
8
|
+
];
|
|
9
|
+
const isRouterSynchronousProtocolName = (protocolName) => {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
return RouterSynchronousProtocolNames.includes(protocolName);
|
|
12
|
+
};
|
|
13
|
+
exports.isRouterSynchronousProtocolName = isRouterSynchronousProtocolName;
|
|
14
|
+
const RouterAsyncProtocolNames = ["Cetus", "Turbos"];
|
|
15
|
+
const isRouterAsyncProtocolName = (protocolName) => {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
return RouterAsyncProtocolNames.includes(protocolName);
|
|
18
|
+
};
|
|
19
|
+
exports.isRouterAsyncProtocolName = isRouterAsyncProtocolName;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SuiAddress } from "@mysten/sui.js";
|
|
2
|
+
import { CoinType } from "../../../coin/coinTypes";
|
|
3
|
+
import { Balance, SerializedTransaction } from "../../../../types";
|
|
4
|
+
export interface RouterAsyncApiInterface<PoolType> {
|
|
5
|
+
fetchPoolForCoinTypes: (inputs: {
|
|
6
|
+
coinType1: CoinType;
|
|
7
|
+
coinType2: CoinType;
|
|
8
|
+
}) => Promise<PoolType>;
|
|
9
|
+
fetchTradeAmountOut: (inputs: {
|
|
10
|
+
walletAddress: SuiAddress;
|
|
11
|
+
pool: PoolType;
|
|
12
|
+
coinInType: CoinType;
|
|
13
|
+
coinOutType: CoinType;
|
|
14
|
+
coinInAmount: Balance;
|
|
15
|
+
}) => Promise<Balance>;
|
|
16
|
+
fetchTradeTx: (inputs: {
|
|
17
|
+
walletAddress: SuiAddress;
|
|
18
|
+
pool: PoolType;
|
|
19
|
+
coinInType: CoinType;
|
|
20
|
+
coinOutType: CoinType;
|
|
21
|
+
coinInAmount: Balance;
|
|
22
|
+
}) => Promise<SerializedTransaction>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=routerAsyncApiInterface.d.ts.map
|
|
@@ -0,0 +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,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAMnE,MAAM,WAAW,uBAAuB,CAAC,QAAQ;IAahD,qBAAqB,EAAE,CAAC,MAAM,EAAE;QAC/B,SAAS,EAAE,QAAQ,CAAC;QACpB,SAAS,EAAE,QAAQ,CAAC;KACpB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAMxB,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;IAcvB,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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Balance, RouterAsyncTradeResults, RouterCompleteTradeRoute } from "../../../../types";
|
|
2
|
+
export declare class RouterAsyncGraph {
|
|
3
|
+
static createFinalCompleteRoute(inputs: {
|
|
4
|
+
tradeResults: RouterAsyncTradeResults;
|
|
5
|
+
coinInAmounts: Balance[];
|
|
6
|
+
synchronousCompleteRoutes?: RouterCompleteTradeRoute[];
|
|
7
|
+
}): RouterCompleteTradeRoute;
|
|
8
|
+
private static splitTradeBetweenRoutes;
|
|
9
|
+
private static singleCompleteRouteFromMany;
|
|
10
|
+
private static completeRoutesFromTradeResults;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=routerAsyncGraph.d.ts.map
|
|
@@ -0,0 +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,yBAAyB,CAAC,EAAE,wBAAwB,EAAE,CAAC;KACvD,GAAG,wBAAwB;IA6B5B,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAyCpC;IAEF,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAqCxC;IAEF,OAAO,CAAC,MAAM,CAAC,8BAA8B,CAiD3C;CACF"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouterAsyncGraph = void 0;
|
|
4
|
+
const utils_1 = require("../../../../general/utils");
|
|
5
|
+
/////////////////////////////////////////////////////////////////////
|
|
6
|
+
//// Class
|
|
7
|
+
/////////////////////////////////////////////////////////////////////
|
|
8
|
+
class RouterAsyncGraph {
|
|
9
|
+
/////////////////////////////////////////////////////////////////////
|
|
10
|
+
//// Public Static Methods
|
|
11
|
+
/////////////////////////////////////////////////////////////////////
|
|
12
|
+
/////////////////////////////////////////////////////////////////////
|
|
13
|
+
//// Graph Creation
|
|
14
|
+
/////////////////////////////////////////////////////////////////////
|
|
15
|
+
static createFinalCompleteRoute(inputs) {
|
|
16
|
+
const asyncCompleteRoutes = this.completeRoutesFromTradeResults(inputs);
|
|
17
|
+
const completeRoutes = inputs.synchronousCompleteRoutes
|
|
18
|
+
? [...asyncCompleteRoutes, inputs.synchronousCompleteRoutes]
|
|
19
|
+
: [...asyncCompleteRoutes];
|
|
20
|
+
const chosenCompleteRoutes = this.splitTradeBetweenRoutes(Object.assign(Object.assign({}, inputs), { completeRoutes }));
|
|
21
|
+
const finalCompleteRoute = this.singleCompleteRouteFromMany({
|
|
22
|
+
completeRoutes: chosenCompleteRoutes,
|
|
23
|
+
});
|
|
24
|
+
if (finalCompleteRoute.coinOut.amount <= BigInt(0))
|
|
25
|
+
throw new Error("unable to find route ");
|
|
26
|
+
return finalCompleteRoute;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.RouterAsyncGraph = RouterAsyncGraph;
|
|
30
|
+
/////////////////////////////////////////////////////////////////////
|
|
31
|
+
//// Private Static Methods
|
|
32
|
+
/////////////////////////////////////////////////////////////////////
|
|
33
|
+
/////////////////////////////////////////////////////////////////////
|
|
34
|
+
//// Helpers
|
|
35
|
+
/////////////////////////////////////////////////////////////////////
|
|
36
|
+
RouterAsyncGraph.splitTradeBetweenRoutes = (inputs) => {
|
|
37
|
+
const { completeRoutes, coinInAmounts } = inputs;
|
|
38
|
+
let chosenRouteIndexes = Array(coinInAmounts.length).fill(-1);
|
|
39
|
+
for (const _ of coinInAmounts) {
|
|
40
|
+
const incrementalAmountsOut = completeRoutes.map((route, index) => {
|
|
41
|
+
const prevChosenIndex = chosenRouteIndexes[index];
|
|
42
|
+
const prevAmountOut = prevChosenIndex < 0
|
|
43
|
+
? BigInt(0)
|
|
44
|
+
: route[prevChosenIndex].coinOut.amount;
|
|
45
|
+
const currentAmountOut = route[prevChosenIndex + 1].coinOut.amount;
|
|
46
|
+
const incrementalAmountOut = currentAmountOut - prevAmountOut;
|
|
47
|
+
return incrementalAmountOut;
|
|
48
|
+
});
|
|
49
|
+
const maxIndex = utils_1.Helpers.indexOfMax(incrementalAmountsOut);
|
|
50
|
+
chosenRouteIndexes[maxIndex] += 1;
|
|
51
|
+
}
|
|
52
|
+
const selectedCompleteRoutes = chosenRouteIndexes
|
|
53
|
+
.map((chosenIndex, routeIndex) => chosenIndex >= 0
|
|
54
|
+
? completeRoutes[routeIndex][chosenIndex]
|
|
55
|
+
: undefined)
|
|
56
|
+
.filter((route) => route !== undefined);
|
|
57
|
+
return selectedCompleteRoutes;
|
|
58
|
+
};
|
|
59
|
+
RouterAsyncGraph.singleCompleteRouteFromMany = (inputs) => {
|
|
60
|
+
const { completeRoutes } = inputs;
|
|
61
|
+
let routes = [];
|
|
62
|
+
let coinInAmount = BigInt(0);
|
|
63
|
+
let coinOutAmount = BigInt(0);
|
|
64
|
+
for (const completeRoute of completeRoutes) {
|
|
65
|
+
routes = [...routes, ...completeRoute.routes];
|
|
66
|
+
coinInAmount += completeRoute.coinIn.amount;
|
|
67
|
+
coinOutAmount += completeRoute.coinOut.amount;
|
|
68
|
+
}
|
|
69
|
+
const spotPrice = completeRoutes.reduce((acc, cur) => acc +
|
|
70
|
+
(Number(cur.coinIn.amount) / Number(coinInAmount)) *
|
|
71
|
+
cur.spotPrice, 0);
|
|
72
|
+
return {
|
|
73
|
+
routes,
|
|
74
|
+
spotPrice,
|
|
75
|
+
coinIn: {
|
|
76
|
+
type: completeRoutes[0].coinIn.type,
|
|
77
|
+
amount: coinInAmount,
|
|
78
|
+
tradeFee: BigInt(0),
|
|
79
|
+
},
|
|
80
|
+
coinOut: {
|
|
81
|
+
type: completeRoutes[0].coinOut.type,
|
|
82
|
+
amount: coinOutAmount,
|
|
83
|
+
tradeFee: BigInt(0),
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
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
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CoinType } from "
|
|
2
|
-
import { RouterSerializablePool } from "
|
|
1
|
+
import { CoinType } from "../../../../coin/coinTypes";
|
|
2
|
+
import { RouterSerializablePool } from "../../../routerTypes";
|
|
3
3
|
export interface RouterApiInterface<PoolType extends RouterSerializablePool> {
|
|
4
4
|
fetchAllPools: () => Promise<PoolType[]>;
|
|
5
5
|
fetchSupportedCoins: () => Promise<CoinType[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routerApiInterface.d.ts","sourceRoot":"","sources":["../../../../../../src/packages/router/utils/synchronous/interfaces/routerApiInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAM9D,MAAM,WAAW,kBAAkB,CAAC,QAAQ,SAAS,sBAAsB;IAS1E,aAAa,EAAE,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEzC,mBAAmB,EAAE,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;CAG/C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ObjectId, SuiAddress, TransactionArgument, TransactionBlock } from "@mysten/sui.js";
|
|
2
|
-
import { Balance, RouterProtocolName, RouterSerializablePool, Slippage, SuiNetwork, UniqueId, Url } from "
|
|
3
|
-
import { CoinType } from "
|
|
4
|
-
import { AftermathApi } from "
|
|
2
|
+
import { Balance, RouterProtocolName, RouterSerializablePool, Slippage, SuiNetwork, UniqueId, Url } from "../../../../../types";
|
|
3
|
+
import { CoinType } from "../../../../coin/coinTypes";
|
|
4
|
+
import { AftermathApi } from "../../../../../general/providers";
|
|
5
5
|
export declare function createRouterPool(inputs: {
|
|
6
6
|
pool: RouterSerializablePool;
|
|
7
7
|
network: SuiNetwork | Url;
|
|
@@ -13,6 +13,7 @@ export interface RouterPoolInterface {
|
|
|
13
13
|
readonly uid: UniqueId;
|
|
14
14
|
readonly expectedGasCostPerHop: Balance;
|
|
15
15
|
readonly coinTypes: CoinType[];
|
|
16
|
+
readonly noHopsAllowed: boolean;
|
|
16
17
|
getSpotPrice: (inputs: {
|
|
17
18
|
coinInType: CoinType;
|
|
18
19
|
coinOutType: CoinType;
|
|
@@ -27,6 +28,7 @@ export interface RouterPoolInterface {
|
|
|
27
28
|
provider: AftermathApi;
|
|
28
29
|
tx: TransactionBlock;
|
|
29
30
|
coinIn: ObjectId | TransactionArgument;
|
|
31
|
+
coinInAmount: Balance;
|
|
30
32
|
coinInType: CoinType;
|
|
31
33
|
coinOutType: CoinType;
|
|
32
34
|
expectedAmountOut: Balance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routerPoolInterface.d.ts","sourceRoot":"","sources":["../../../../../../src/packages/router/utils/synchronous/interfaces/routerPoolInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,QAAQ,EACR,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,OAAO,EACP,kBAAkB,EAClB,sBAAsB,EACtB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,GAAG,EACH,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAGtD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAahE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACxC,IAAI,EAAE,sBAAsB,CAAC;IAE7B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,QAAQ,CAAC;QACtB,QAAQ,CAAC,EAAE,UAAU,CAAC;KACtB,KAAK,OAAO,CAAC;IAEd,yBAAyB,EAAE,CAAC,MAAM,EAAE;QACnC,UAAU,EAAE,QAAQ,CAAC;QACrB,YAAY,EAAE,OAAO,CAAC;QACtB,WAAW,EAAE,QAAQ,CAAC;QACtB,aAAa,EAAE,OAAO,CAAC;KACvB,KAAK,mBAAmB,CAAC;IAE1B,wBAAwB,EAAE,CAAC,MAAM,EAAE;QAClC,UAAU,EAAE,QAAQ,CAAC;QACrB,YAAY,EAAE,OAAO,CAAC;QACtB,WAAW,EAAE,QAAQ,CAAC;QACtB,aAAa,EAAE,OAAO,CAAC;KACvB,KAAK,mBAAmB,CAAC;CAC1B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createRouterPool = void 0;
|
|
7
|
+
const aftermathRouterPool_1 = __importDefault(require("../routerPools/aftermathRouterPool"));
|
|
8
|
+
const nojoRouterPool_1 = __importDefault(require("../routerPools/nojoRouterPool"));
|
|
9
|
+
const nojoAmmTypes_1 = require("../../../../external/nojo/nojoAmmTypes");
|
|
10
|
+
const deepBookTypes_1 = require("../../../../external/deepBook/deepBookTypes");
|
|
11
|
+
const deepBookRouterPool_1 = __importDefault(require("../routerPools/deepBookRouterPool"));
|
|
12
|
+
const cetusTypes_1 = require("../../../../external/cetus/cetusTypes");
|
|
13
|
+
const cetusRouterPool_1 = __importDefault(require("../routerPools/cetusRouterPool"));
|
|
14
|
+
const turbosTypes_1 = require("../../../../external/turbos/turbosTypes");
|
|
15
|
+
const turbosRouterPool_1 = __importDefault(require("../routerPools/turbosRouterPool"));
|
|
16
|
+
/////////////////////////////////////////////////////////////////////
|
|
17
|
+
//// Creation
|
|
18
|
+
/////////////////////////////////////////////////////////////////////
|
|
19
|
+
function createRouterPool(inputs) {
|
|
20
|
+
const { pool, network } = inputs;
|
|
21
|
+
const constructedPool = (0, nojoAmmTypes_1.isNojoPoolObject)(pool)
|
|
22
|
+
? new nojoRouterPool_1.default(pool, network)
|
|
23
|
+
: (0, deepBookTypes_1.isDeepBookPoolObject)(pool)
|
|
24
|
+
? new deepBookRouterPool_1.default(pool, network)
|
|
25
|
+
: (0, turbosTypes_1.isTurbosPoolObject)(pool)
|
|
26
|
+
? new turbosRouterPool_1.default(pool, network)
|
|
27
|
+
: (0, cetusTypes_1.isCetusRouterPoolObject)(pool)
|
|
28
|
+
? new cetusRouterPool_1.default(pool, network)
|
|
29
|
+
: new aftermathRouterPool_1.default(pool, network);
|
|
30
|
+
return constructedPool;
|
|
31
|
+
}
|
|
32
|
+
exports.createRouterPool = createRouterPool;
|