@orbs-network/twap 1.6.1 → 1.7.0

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.
@@ -17,8 +17,63 @@ export interface Config {
17
17
  exchangeContract: "UniswapV2Exchange" | "ParaswapExchange";
18
18
  pathfinderKey: Paraswap.OnlyDex;
19
19
  }
20
- export declare const SpiritSwapConfig: Config;
21
- export declare const SpookySwapConfig: Config;
20
+ export declare const ChainConfigs: {
21
+ eth: {
22
+ chainId: number;
23
+ twapAddress: string;
24
+ lensAddress: string;
25
+ bidDelaySeconds: number;
26
+ minChunkSizeUsd: number;
27
+ wToken: {
28
+ address: string;
29
+ decimals: number;
30
+ symbol: string;
31
+ logoUrl: string;
32
+ };
33
+ };
34
+ ftm: {
35
+ chainId: number;
36
+ twapAddress: string;
37
+ lensAddress: string;
38
+ bidDelaySeconds: number;
39
+ minChunkSizeUsd: number;
40
+ wToken: {
41
+ address: string;
42
+ decimals: number;
43
+ symbol: string;
44
+ logoUrl: string;
45
+ };
46
+ };
47
+ poly: {
48
+ chainId: number;
49
+ twapAddress: string;
50
+ lensAddress: string;
51
+ bidDelaySeconds: number;
52
+ minChunkSizeUsd: number;
53
+ wToken: {
54
+ address: string;
55
+ decimals: number;
56
+ symbol: string;
57
+ logoUrl: string;
58
+ };
59
+ };
60
+ avax: {
61
+ chainId: number;
62
+ twapAddress: string;
63
+ lensAddress: string;
64
+ bidDelaySeconds: number;
65
+ minChunkSizeUsd: number;
66
+ wToken: {
67
+ address: string;
68
+ decimals: number;
69
+ symbol: string;
70
+ logoUrl: string;
71
+ };
72
+ };
73
+ };
74
+ export declare const Configs: {
75
+ [integration: string]: Config;
76
+ };
22
77
  export declare const nativeTokenAddresses: string[];
23
78
  export declare const isNativeAddress: (address: string) => boolean;
24
79
  export declare const chainConfig: (chainId: number) => {
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.chainConfig = exports.isNativeAddress = exports.nativeTokenAddresses = exports.SpookySwapConfig = exports.SpiritSwapConfig = void 0;
6
+ exports.chainConfig = exports.isNativeAddress = exports.nativeTokenAddresses = exports.Configs = exports.ChainConfigs = void 0;
7
7
  const web3_candies_1 = require("@defi.org/web3-candies");
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
9
  const paraswap_1 = require("./paraswap");
10
- const ChainConfigs = {
10
+ exports.ChainConfigs = {
11
11
  eth: {
12
12
  chainId: 1,
13
13
  twapAddress: "",
@@ -61,6 +61,10 @@ const ChainConfigs = {
61
61
  },
62
62
  },
63
63
  };
64
+ exports.Configs = {
65
+ SpiritSwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeContract: "ParaswapExchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpiritSwap }),
66
+ SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpookySwap", exchangeAddress: "0x37F427DA0D12Fe2C80aCa09EE08e7e92A1B2B114", exchangeContract: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpookySwap }),
67
+ };
64
68
  // export const UniswapV2Config: Config = {
65
69
  // ...ChainConfigs.eth,
66
70
  // partner: "UniswapV2",
@@ -76,8 +80,6 @@ const ChainConfigs = {
76
80
  // partner: "QuickSwap",
77
81
  // exchangeAddress: "0xeFE1B6096838949156e5130604434A2a13c68C68",
78
82
  // };
79
- exports.SpiritSwapConfig = Object.assign(Object.assign({}, ChainConfigs.ftm), { partner: "SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeContract: "ParaswapExchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpiritSwap });
80
- exports.SpookySwapConfig = Object.assign(Object.assign({}, ChainConfigs.ftm), { partner: "SpookySwap", exchangeAddress: "0x37F427DA0D12Fe2C80aCa09EE08e7e92A1B2B114", exchangeContract: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpookySwap });
81
83
  exports.nativeTokenAddresses = [
82
84
  web3_candies_1.zeroAddress,
83
85
  "0x0000000000000000000000000000000000001010",
@@ -85,5 +87,5 @@ exports.nativeTokenAddresses = [
85
87
  ];
86
88
  const isNativeAddress = (address) => !!lodash_1.default.find(exports.nativeTokenAddresses, (a) => (0, web3_candies_1.eqIgnoreCase)(a, address));
87
89
  exports.isNativeAddress = isNativeAddress;
88
- const chainConfig = (chainId) => lodash_1.default.find(ChainConfigs, (c) => c.chainId === chainId);
90
+ const chainConfig = (chainId) => lodash_1.default.find(exports.ChainConfigs, (c) => c.chainId === chainId);
89
91
  exports.chainConfig = chainConfig;
package/dist/src/lib.d.ts CHANGED
@@ -20,6 +20,7 @@ export declare class TWAPLib {
20
20
  totalChunks: (srcAmount: BN.Value, srcChunkAmount: BN.Value) => number;
21
21
  fillDelayMillis: (totalChunks: BN.Value, maxDurationMillis: BN.Value) => number;
22
22
  dstMinAmountOut: (srcToken: TokenData, dstToken: TokenData, srcChunkAmount: BN.Value, limitDstPriceFor1Src: BN.Value, isMarketOrder: boolean) => BN;
23
+ dstPriceFor1Src: (srcToken: TokenData, dstToken: TokenData, srcUsdMarket: BN.Value, dstUsdMarket: BN.Value, srcChunkAmount: BN.Value, dstMinAmountOut: BN.Value) => BN;
23
24
  isMarketOrder: (order: Order) => boolean;
24
25
  orderProgress: (order: Order) => number;
25
26
  percentAboveMarket: (srcUsdMarket: BN.Value, dstUsdMarket: BN.Value, limitDstPriceFor1Src: BN.Value) => number;
@@ -38,6 +39,11 @@ export declare class TWAPLib {
38
39
  getAllOrders(): Promise<Order[]>;
39
40
  private sendTx;
40
41
  parseOrder(r: any): Order;
42
+ getToken(address: string): Promise<{
43
+ address: string;
44
+ decimals: number;
45
+ symbol: string;
46
+ }>;
41
47
  }
42
48
  export interface Order {
43
49
  id: number;
package/dist/src/lib.js CHANGED
@@ -40,10 +40,13 @@ class TWAPLib {
40
40
  ? 0
41
41
  : bignumber_js_1.default.max((0, bignumber_js_1.default)(maxDurationMillis)
42
42
  .div(totalChunks)
43
- .minus((0, bignumber_js_1.default)(this.config.bidDelaySeconds * 1000)), 0).toNumber();
43
+ .minus((0, bignumber_js_1.default)(this.config.bidDelaySeconds * 1000 * 2)), 0).toNumber();
44
44
  this.dstMinAmountOut = (srcToken, dstToken, srcChunkAmount, limitDstPriceFor1Src, isMarketOrder) => isMarketOrder
45
45
  ? (0, bignumber_js_1.default)(1)
46
46
  : bignumber_js_1.default.max(1, (0, web3_candies_1.convertDecimals)((0, bignumber_js_1.default)(srcChunkAmount).times(limitDstPriceFor1Src), srcToken.decimals, dstToken.decimals).integerValue(bignumber_js_1.default.ROUND_FLOOR));
47
+ this.dstPriceFor1Src = (srcToken, dstToken, srcUsdMarket, dstUsdMarket, srcChunkAmount, dstMinAmountOut) => (0, bignumber_js_1.default)(dstMinAmountOut).eq(1)
48
+ ? (0, bignumber_js_1.default)(srcUsdMarket).div(dstUsdMarket)
49
+ : (0, bignumber_js_1.default)(dstMinAmountOut).div((0, web3_candies_1.convertDecimals)((0, bignumber_js_1.default)(srcChunkAmount), srcToken.decimals, dstToken.decimals));
47
50
  this.isMarketOrder = (order) => order.ask.dstMinAmount.lte(1);
48
51
  this.orderProgress = (order) => parseFloat(order.srcFilledAmount.div(order.ask.srcAmount).toFixed(4));
49
52
  this.percentAboveMarket = (srcUsdMarket, dstUsdMarket, limitDstPriceFor1Src) => parseFloat((0, bignumber_js_1.default)(limitDstPriceFor1Src).div((0, bignumber_js_1.default)(srcUsdMarket).div(dstUsdMarket)).minus(1).toFixed(4));
@@ -191,24 +194,30 @@ class TWAPLib {
191
194
  deadline: Number(r.ask.deadline),
192
195
  bidDelay: Number(r.ask.bidDelay),
193
196
  fillDelay: Number(r.ask.fillDelay),
194
- maker: r.ask.maker,
195
- exchange: r.ask.exchange,
196
- srcToken: r.ask.srcToken,
197
- dstToken: r.ask.dstToken,
197
+ maker: web3_1.default.utils.toChecksumAddress(r.ask.maker),
198
+ exchange: web3_1.default.utils.toChecksumAddress(r.ask.exchange),
199
+ srcToken: web3_1.default.utils.toChecksumAddress(r.ask.srcToken),
200
+ dstToken: web3_1.default.utils.toChecksumAddress(r.ask.dstToken),
198
201
  srcAmount: (0, bignumber_js_1.default)(r.ask.srcAmount),
199
202
  srcBidAmount: (0, bignumber_js_1.default)(r.ask.srcBidAmount),
200
203
  dstMinAmount: (0, bignumber_js_1.default)(r.ask.dstMinAmount),
201
204
  },
202
205
  bid: {
203
206
  time: Number(((_a = r.bid) === null || _a === void 0 ? void 0 : _a.time) || 0),
204
- taker: ((_b = r.bid) === null || _b === void 0 ? void 0 : _b.taker) || "",
205
- exchange: ((_c = r.bid) === null || _c === void 0 ? void 0 : _c.exchange) || "",
207
+ taker: web3_1.default.utils.toChecksumAddress(((_b = r.bid) === null || _b === void 0 ? void 0 : _b.taker) || web3_candies_1.zeroAddress),
208
+ exchange: web3_1.default.utils.toChecksumAddress(((_c = r.bid) === null || _c === void 0 ? void 0 : _c.exchange) || web3_candies_1.zeroAddress),
206
209
  dstAmount: (0, bignumber_js_1.default)(((_d = r.bid) === null || _d === void 0 ? void 0 : _d.dstAmount) || web3_candies_1.zero),
207
210
  dstFee: (0, bignumber_js_1.default)(((_e = r.bid) === null || _e === void 0 ? void 0 : _e.dstFee) || web3_candies_1.zero),
208
211
  data: ((_f = r.bid) === null || _f === void 0 ? void 0 : _f.data) || "",
209
212
  },
210
213
  };
211
214
  }
215
+ getToken(address) {
216
+ return __awaiter(this, void 0, void 0, function* () {
217
+ const t = (0, web3_candies_1.erc20)("", address);
218
+ return { address, decimals: yield t.decimals(), symbol: yield t.methods.symbol().call() };
219
+ });
220
+ }
212
221
  }
213
222
  exports.TWAPLib = TWAPLib;
214
223
  var Status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/twap",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/orbs-network/twap.git"