@orbs-network/twap 1.8.1 → 1.8.3

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 CHANGED
@@ -2,6 +2,8 @@ import { Config, TokenData } from "./configs";
2
2
  import BN from "bignumber.js";
3
3
  import type { TWAP } from "../typechain-hardhat/contracts";
4
4
  import type { Lens } from "../typechain-hardhat/contracts/periphery";
5
+ import { Paraswap } from "./paraswap";
6
+ import ParaswapRoute = Paraswap.ParaswapRoute;
5
7
  export declare const twapAbi: any;
6
8
  export declare const lensAbi: any;
7
9
  export declare const takerAbi: any;
@@ -39,12 +41,19 @@ export declare class TWAPLib {
39
41
  getAllOrders(): Promise<Order[]>;
40
42
  parseOrder(r: any): Order;
41
43
  getToken(address: string): Promise<TokenData>;
42
- findSwapDataForBid(orderId: number): Promise<{
44
+ findSwapDataForBid(order: Order): Promise<{
43
45
  srcToken: TokenData;
44
46
  dstToken: TokenData;
45
- srcAmountIn: BN;
46
- dstAmountOut: BN;
47
- raw: any;
47
+ srcNextChunkAmountIn: BN;
48
+ dstNextChunkAmountOut: BN;
49
+ raw: string[] | Paraswap.ParaswapRoute;
50
+ data: string;
51
+ }>;
52
+ convertRouteToSwapData(route: ParaswapRoute): Promise<{
53
+ raw: string[];
54
+ data: string;
55
+ } | {
56
+ raw: Paraswap.ParaswapRoute;
48
57
  data: string;
49
58
  }>;
50
59
  }
package/dist/src/lib.js CHANGED
@@ -209,33 +209,32 @@ class TWAPLib {
209
209
  return { address, decimals: yield t.decimals(), symbol: yield t.methods.symbol().call() };
210
210
  });
211
211
  }
212
- findSwapDataForBid(orderId) {
212
+ findSwapDataForBid(order) {
213
213
  return __awaiter(this, void 0, void 0, function* () {
214
- const order = yield this.getOrder(orderId);
215
- const srcAmountIn = bignumber_js_1.default.min(order.ask.srcBidAmount, order.ask.srcAmount.minus(order.srcFilledAmount));
214
+ if (order.ask.exchange !== web3_candies_1.zeroAddress && !(0, web3_candies_1.eqIgnoreCase)(order.ask.exchange, this.config.exchangeAddress))
215
+ throw new Error(`mismatched exchange and config`);
216
+ const srcNextChunkAmountIn = bignumber_js_1.default.min(order.ask.srcBidAmount, order.ask.srcAmount.minus(order.srcFilledAmount));
216
217
  const [srcToken, dstToken] = yield Promise.all([
217
218
  this.getToken(order.ask.srcToken),
218
219
  this.getToken(order.ask.dstToken),
219
220
  ]);
220
- const route = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcAmountIn, this.config.pathfinderKey);
221
- const dstAmountOut = (0, bignumber_js_1.default)(route.destAmount);
221
+ const route = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcNextChunkAmountIn, this.config.pathfinderKey);
222
+ const dstNextChunkAmountOut = (0, bignumber_js_1.default)(route.destAmount);
223
+ const { raw, data } = yield this.convertRouteToSwapData(route);
224
+ return { srcToken, dstToken, srcNextChunkAmountIn, dstNextChunkAmountOut, raw, data };
225
+ });
226
+ }
227
+ convertRouteToSwapData(route) {
228
+ return __awaiter(this, void 0, void 0, function* () {
222
229
  switch (this.config.exchangeType) {
223
230
  case "UniswapV2Exchange":
224
231
  const path = paraswap_1.Paraswap.getDirectPath(route, this.config.pathfinderKey);
225
232
  return {
226
- srcToken,
227
- dstToken,
228
- srcAmountIn,
229
- dstAmountOut,
230
233
  raw: path,
231
234
  data: (0, web3_candies_1.web3)().eth.abi.encodeParameters(["bool", "address[]"], [true, path]),
232
235
  };
233
236
  case "ParaswapExchange":
234
237
  return {
235
- srcToken,
236
- dstToken,
237
- srcAmountIn,
238
- dstAmountOut,
239
238
  raw: route,
240
239
  data: yield paraswap_1.Paraswap.buildSwapData(route, this.config.twapAddress),
241
240
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/twap",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/orbs-network/twap.git"