@orbs-network/twap 1.10.4 → 1.10.5
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/src/lib.d.ts +10 -2
- package/dist/src/lib.js +17 -12
- package/package.json +1 -1
package/dist/src/lib.d.ts
CHANGED
|
@@ -48,11 +48,19 @@ export declare class TWAPLib {
|
|
|
48
48
|
})[]>;
|
|
49
49
|
parseOrder(r: any): Order;
|
|
50
50
|
getToken(address: string): Promise<TokenData>;
|
|
51
|
+
findRoute(srcToken: TokenData, dstToken: TokenData, srcAmount: BN.Value): Promise<{
|
|
52
|
+
srcToken: TokenData;
|
|
53
|
+
dstToken: TokenData;
|
|
54
|
+
srcAmount: BN.Value;
|
|
55
|
+
dstAmount: BN;
|
|
56
|
+
raw: string[] | Paraswap.ParaswapRoute | Odos.OdosRoute;
|
|
57
|
+
data: string;
|
|
58
|
+
}>;
|
|
51
59
|
findSwapDataForBid(order: Order): Promise<{
|
|
52
60
|
srcToken: TokenData;
|
|
53
61
|
dstToken: TokenData;
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
srcAmount: BN.Value;
|
|
63
|
+
dstAmount: BN;
|
|
56
64
|
raw: string[] | Paraswap.ParaswapRoute | Odos.OdosRoute;
|
|
57
65
|
data: string;
|
|
58
66
|
}>;
|
package/dist/src/lib.js
CHANGED
|
@@ -241,6 +241,22 @@ class TWAPLib {
|
|
|
241
241
|
return { address, decimals, symbol };
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
|
+
findRoute(srcToken, dstToken, srcAmount) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
if (this.config.exchangeType === "OdosExchange") {
|
|
247
|
+
const route = yield odos_1.Odos.findRoute(this.config.chainId, srcToken, dstToken, srcAmount, this.config.exchangeAddress, this.config.pathfinderKey);
|
|
248
|
+
const dstAmount = route.dstAmountOut;
|
|
249
|
+
const { raw, data } = yield this.convertRouteToSwapData(route);
|
|
250
|
+
return { srcToken, dstToken, srcAmount, dstAmount, raw, data };
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
const route = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcAmount, this.config.pathfinderKey);
|
|
254
|
+
const dstAmount = (0, bignumber_js_1.default)(route.destAmount);
|
|
255
|
+
const { raw, data } = yield this.convertRouteToSwapData(route);
|
|
256
|
+
return { srcToken, dstToken, srcAmount, dstAmount, raw, data };
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
244
260
|
findSwapDataForBid(order) {
|
|
245
261
|
return __awaiter(this, void 0, void 0, function* () {
|
|
246
262
|
if (order.ask.exchange !== web3_candies_1.zeroAddress && !(0, web3_candies_1.eqIgnoreCase)(order.ask.exchange, this.config.exchangeAddress))
|
|
@@ -250,18 +266,7 @@ class TWAPLib {
|
|
|
250
266
|
this.getToken(order.ask.srcToken),
|
|
251
267
|
this.getToken(order.ask.dstToken),
|
|
252
268
|
]);
|
|
253
|
-
|
|
254
|
-
const route = yield odos_1.Odos.findRoute(this.config.chainId, srcToken, dstToken, srcNextChunkAmountIn, this.config.exchangeAddress, this.config.pathfinderKey);
|
|
255
|
-
const dstNextChunkAmountOut = route.dstAmountOut;
|
|
256
|
-
const { raw, data } = yield this.convertRouteToSwapData(route);
|
|
257
|
-
return { srcToken, dstToken, srcNextChunkAmountIn, dstNextChunkAmountOut, raw, data };
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
const route = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcNextChunkAmountIn, this.config.pathfinderKey);
|
|
261
|
-
const dstNextChunkAmountOut = (0, bignumber_js_1.default)(route.destAmount);
|
|
262
|
-
const { raw, data } = yield this.convertRouteToSwapData(route);
|
|
263
|
-
return { srcToken, dstToken, srcNextChunkAmountIn, dstNextChunkAmountOut, raw, data };
|
|
264
|
-
}
|
|
269
|
+
return this.findRoute(srcToken, dstToken, srcNextChunkAmountIn);
|
|
265
270
|
});
|
|
266
271
|
}
|
|
267
272
|
convertRouteToSwapData(route) {
|