@orbs-network/twap 1.7.11 → 1.7.13

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.
@@ -74,6 +74,7 @@ export declare const ChainConfigs: {
74
74
  export declare const Configs: {
75
75
  SpiritSwap: Config;
76
76
  SpookySwap: Config;
77
+ Pangolin: Config;
77
78
  };
78
79
  export declare const nativeTokenAddresses: string[];
79
80
  export declare const isNativeAddress: (address: string) => boolean;
@@ -49,8 +49,8 @@ exports.ChainConfigs = {
49
49
  },
50
50
  avax: {
51
51
  chainId: 43114,
52
- twapAddress: "",
53
- lensAddress: "",
52
+ twapAddress: "0xD63430c74C8E70D9dbdCA04C6a9E6E9E929028DA",
53
+ lensAddress: "0xD13609A8ace04D11Ea2FFE176B69dF77C6d9375E",
54
54
  bidDelaySeconds: 60,
55
55
  minChunkSizeUsd: 10,
56
56
  wToken: {
@@ -64,6 +64,7 @@ exports.ChainConfigs = {
64
64
  exports.Configs = {
65
65
  SpiritSwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpiritSwap", exchangeAddress: "0xAd19179201be5A51D1cBd3bB2fC651BB05822404", exchangeType: "ParaswapExchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpiritSwap }),
66
66
  SpookySwap: Object.assign(Object.assign({}, exports.ChainConfigs.ftm), { partner: "SpookySwap", exchangeAddress: "0x37F427DA0D12Fe2C80aCa09EE08e7e92A1B2B114", exchangeType: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.SpookySwap }),
67
+ Pangolin: Object.assign(Object.assign({}, exports.ChainConfigs.avax), { partner: "Pangolin", exchangeAddress: "0x25a0A78f5ad07b2474D3D42F1c1432178465936d", exchangeType: "UniswapV2Exchange", pathfinderKey: paraswap_1.Paraswap.OnlyDex.Pangolin }),
67
68
  };
68
69
  // export const UniswapV2Config: Config = {
69
70
  // ...ChainConfigs.eth,
package/dist/src/lib.d.ts CHANGED
@@ -41,6 +41,15 @@ export declare class TWAPLib {
41
41
  private sendTx;
42
42
  parseOrder(r: any): Order;
43
43
  getToken(address: string): Promise<TokenData>;
44
+ deployTaker(priorityFeePerGas?: BN.Value, maxFeePerGas?: BN.Value): Promise<void>;
45
+ getSwapData(orderId: number): Promise<{
46
+ srcToken: TokenData;
47
+ dstToken: TokenData;
48
+ srcAmountIn: BN;
49
+ dstAmountOut: BN;
50
+ path: any;
51
+ data: string;
52
+ }>;
44
53
  }
45
54
  export interface Order {
46
55
  id: number;
package/dist/src/lib.js CHANGED
@@ -21,6 +21,7 @@ const TWAP_json_1 = __importDefault(require("../artifacts/contracts/TWAP.sol/TWA
21
21
  const Lens_json_1 = __importDefault(require("../artifacts/contracts/periphery/Lens.sol/Lens.json"));
22
22
  const Taker_json_1 = __importDefault(require("../artifacts/contracts/periphery/Taker.sol/Taker.json"));
23
23
  const lodash_1 = __importDefault(require("lodash"));
24
+ const paraswap_1 = require("./paraswap");
24
25
  exports.twapAbi = TWAP_json_1.default.abi;
25
26
  exports.lensAbi = Lens_json_1.default.abi;
26
27
  exports.takerAbi = Taker_json_1.default.abi;
@@ -170,14 +171,9 @@ class TWAPLib {
170
171
  }
171
172
  sendTx(tx, priorityFeePerGas, maxFeePerGas, amount) {
172
173
  return __awaiter(this, void 0, void 0, function* () {
173
- let gas = 500000;
174
- try {
175
- gas = Math.max(gas, Math.floor((yield tx.estimateGas()) * 1.2));
176
- }
177
- catch (ignore) { }
178
174
  return yield tx.send({
179
175
  from: this.maker,
180
- gas,
176
+ gas: Math.floor((yield tx.estimateGas({ from: this.maker, value: amount ? (0, bignumber_js_1.default)(amount).toFixed(0) : undefined })) * 1.2),
181
177
  maxPriorityFeePerGas: priorityFeePerGas ? (0, bignumber_js_1.default)(priorityFeePerGas).toFixed(0) : undefined,
182
178
  maxFeePerGas: maxFeePerGas ? (0, bignumber_js_1.default)(maxFeePerGas).toFixed(0) : undefined,
183
179
  value: amount ? (0, bignumber_js_1.default)(amount).toFixed(0) : undefined,
@@ -222,6 +218,47 @@ class TWAPLib {
222
218
  return { address, decimals: yield t.decimals(), symbol: yield t.methods.symbol().call() };
223
219
  });
224
220
  }
221
+ // TODO
222
+ deployTaker(priorityFeePerGas, maxFeePerGas) {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ const taker = (0, web3_candies_1.contract)(exports.takerAbi, "");
225
+ yield this.sendTx(taker.deploy({ data: Taker_json_1.default.bytecode, arguments: [this.config.twapAddress, [this.maker]] }), priorityFeePerGas, maxFeePerGas);
226
+ });
227
+ }
228
+ //TODO
229
+ getSwapData(orderId) {
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ const order = yield this.getOrder(orderId);
232
+ const srcAmountIn = order.ask.srcBidAmount;
233
+ const srcToken = yield this.getToken(order.ask.srcToken);
234
+ const dstToken = yield this.getToken(order.ask.dstToken);
235
+ const paraswapRoute = yield paraswap_1.Paraswap.findRoute(this.config.chainId, srcToken, dstToken, srcAmountIn, this.config.pathfinderKey);
236
+ const dstAmountOut = (0, bignumber_js_1.default)(paraswapRoute.destAmount);
237
+ const path = paraswap_1.Paraswap.directPath(paraswapRoute, this.config.pathfinderKey);
238
+ switch (this.config.exchangeType) {
239
+ case "UniswapV2Exchange":
240
+ return {
241
+ srcToken,
242
+ dstToken,
243
+ srcAmountIn,
244
+ dstAmountOut,
245
+ path,
246
+ data: (0, web3_candies_1.web3)().eth.abi.encodeParameters(["bool", "address[]"], [false, path]),
247
+ };
248
+ case "ParaswapExchange":
249
+ return {
250
+ srcToken,
251
+ dstToken,
252
+ srcAmountIn,
253
+ dstAmountOut,
254
+ path,
255
+ data: yield paraswap_1.Paraswap.buildSwapData(paraswapRoute, this.config.twapAddress),
256
+ };
257
+ default:
258
+ throw new Error(`unhandled exchange ${this.config.exchangeType}`);
259
+ }
260
+ });
261
+ }
225
262
  }
226
263
  exports.TWAPLib = TWAPLib;
227
264
  var Status;
@@ -7,7 +7,8 @@ export declare namespace Paraswap {
7
7
  QuickSwap = "QuickSwap",
8
8
  SpiritSwap = "SpiritSwap,SpiritSwapV2",
9
9
  SpookySwap = "SpookySwap",
10
- Pangolin = "PangolinDex"
10
+ Pangolin = "PangolinDEX",
11
+ TraderJoe = "TraderJoe"
11
12
  }
12
13
  interface ParaswapRoute {
13
14
  blockNumber: number;
@@ -39,5 +40,6 @@ export declare namespace Paraswap {
39
40
  }>;
40
41
  function priceUsd(chainId: number, token: TokenData): Promise<BN>;
41
42
  function findRoute(chainId: number, src: TokenData, dst: TokenData, amountIn: BN.Value, onlyDex?: OnlyDex): Promise<ParaswapRoute>;
43
+ function directPath(route: ParaswapRoute, onlyDex: OnlyDex): any;
42
44
  function buildSwapData(paraswapRoute: ParaswapRoute, exchangeAdapter: string): Promise<string>;
43
45
  }
@@ -26,7 +26,8 @@ var Paraswap;
26
26
  OnlyDex["QuickSwap"] = "QuickSwap";
27
27
  OnlyDex["SpiritSwap"] = "SpiritSwap,SpiritSwapV2";
28
28
  OnlyDex["SpookySwap"] = "SpookySwap";
29
- OnlyDex["Pangolin"] = "PangolinDex";
29
+ OnlyDex["Pangolin"] = "PangolinDEX";
30
+ OnlyDex["TraderJoe"] = "TraderJoe";
30
31
  })(OnlyDex = Paraswap.OnlyDex || (Paraswap.OnlyDex = {}));
31
32
  function gasPrices(chainId) {
32
33
  return __awaiter(this, void 0, void 0, function* () {
@@ -69,10 +70,14 @@ var Paraswap;
69
70
  const response = yield fetch(`${URL}/prices/?${params}`);
70
71
  if (response.status < 200 || response.status >= 400)
71
72
  throw new Error(`${response.statusText}`);
72
- return (yield response.json()).priceRoute;
73
+ return (yield response.json()).priceRoute; //TODO pangolin onlyDex not working?
73
74
  });
74
75
  }
75
76
  Paraswap.findRoute = findRoute;
77
+ function directPath(route, onlyDex) {
78
+ return route.bestRoute[0].swaps[0].swapExchanges[0].data.path; // TODO find?
79
+ }
80
+ Paraswap.directPath = directPath;
76
81
  function buildSwapData(paraswapRoute, exchangeAdapter) {
77
82
  return __awaiter(this, void 0, void 0, function* () {
78
83
  const response = yield fetch(`${URL}/transactions/${paraswapRoute.network}?ignoreChecks=true`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbs-network/twap",
3
- "version": "1.7.11",
3
+ "version": "1.7.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/orbs-network/twap.git"
@@ -24,11 +24,13 @@
24
24
  "typechain": "npm run clean && hardhat typechain",
25
25
  "prebuild": "npm run prettier && npm run typechain",
26
26
  "build": "hardhat compile && solhint 'contracts/**/*.sol' && tsc",
27
- "test:logs": "for t in eth ftm poly; do DEBUG=web3-candies npm run test:$t -- --logs; done",
28
- "test": "for t in eth ftm poly; do npm run test:$t; done",
29
- "test:eth": "NETWORK=ETH BLOCK=14908980 hardhat test",
30
- "test:ftm": "NETWORK=FTM BLOCK=39838819 hardhat test",
31
- "test:poly": "NETWORK=POLY BLOCK=29194866 hardhat test"
27
+ "prepublishOnly": "npm run build",
28
+ "test:logs": "for t in eth ftm poly avax; do DEBUG=web3-candies npm run test:$t -- --logs; done",
29
+ "test": "for t in eth ftm poly avax; do npm run test:$t; done",
30
+ "test:eth": "NETWORK=ETH BLOCK=14905987 hardhat test",
31
+ "test:ftm": "NETWORK=FTM BLOCK=39800909 hardhat test",
32
+ "test:poly": "NETWORK=POLY BLOCK=29174252 hardhat test",
33
+ "test:avax": "NETWORK=AVAX BLOCK=15609313 hardhat test"
32
34
  },
33
35
  "prettier": {
34
36
  "printWidth": 120