@pioneer-platform/uniswap-client 0.0.25 → 0.0.27

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.
Files changed (2) hide show
  1. package/lib/index.js +38 -1
  2. package/package.json +3 -1
package/lib/index.js CHANGED
@@ -62,6 +62,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
62
62
  Object.defineProperty(exports, "__esModule", { value: true });
63
63
  var TAG = " | Uniswap | ";
64
64
  var axios_1 = __importDefault(require("axios"));
65
+ // @ts-ignore
66
+ var pioneer_discovery_1 = require("@pioneer-platform/pioneer-discovery");
65
67
  var _a = require("@pioneer-platform/pioneer-caip"), caipToNetworkId = _a.caipToNetworkId, shortListSymbolToCaip = _a.shortListSymbolToCaip, ChainToNetworkId = _a.ChainToNetworkId;
66
68
  var uuid = require('uuidv4').uuid;
67
69
  var log = require('@pioneer-platform/loggerdog')();
@@ -112,10 +114,34 @@ module.exports = {
112
114
  networkSupport: function () {
113
115
  return networkSupport;
114
116
  },
117
+ assetSupport: function () {
118
+ return getAssetSupport();
119
+ },
115
120
  getQuote: function (quote) {
116
121
  return get_quote(quote);
117
122
  }
118
123
  };
124
+ var getAssetSupport = function () {
125
+ var tag = TAG + " | getAssetSupport | ";
126
+ try {
127
+ //iterate over chains
128
+ var allAssets = Object.keys(pioneer_discovery_1.assetData);
129
+ log.info(tag, "allAssets: ", allAssets);
130
+ var supportedAssets = [];
131
+ for (var i = 0; i < allAssets.length; i++) {
132
+ var asset = allAssets[i];
133
+ var networkId = caipToNetworkId(asset);
134
+ // console.log("networkId: ",networkId)
135
+ if (networkSupport.indexOf(networkId) > -1) {
136
+ supportedAssets.push(asset);
137
+ }
138
+ }
139
+ return supportedAssets;
140
+ }
141
+ catch (e) {
142
+ console.error(e);
143
+ }
144
+ };
119
145
  var get_quote = function (quote) {
120
146
  return __awaiter(this, void 0, void 0, function () {
121
147
  var tag, output, from, recipient, inputChain, outputChain, providerUrl, chainIdInt, chainId, provider, sellTokenContract, buyTokenContract, BUY_TOKEN, SELL_TOKEN, BUY_TOKEN_ADDRESS, SELL_TOKEN_ADDRESS, buyTokenAddress, symbolBuy, decimalsBuy, balance, sellTokenAddress, symbolSell, decimalsSell, FEE_AMOUNT, inputPRO, args, Protocol, QuoteIntent, CLIENT_PARAMS, tokenIn, tokenInChainId, tokenOut, tokenOutChainId, amount, tradeType, sendPortionEnabled, requestBody, response, uraQuoteResponse, calldata, value, nonce, gas, gasPrice, adjustedGasPrice, isZero, tx, e_1;
@@ -139,12 +165,20 @@ var get_quote = function (quote) {
139
165
  throw new Error("missing recipientAddress");
140
166
  if (!quote.slippage)
141
167
  throw new Error("missing slippage");
168
+ if (!networkSupport.includes(caipToNetworkId(quote.buyAsset))) {
169
+ throw new Error("unsupported buyAsset");
170
+ }
171
+ if (!networkSupport.includes(caipToNetworkId(quote.sellAsset))) {
172
+ throw new Error("unsupported sellAsset");
173
+ }
142
174
  // if(!quote.permit2) throw new Error("missing permit2, required for uniswap")
143
175
  output.txs = [];
144
176
  from = quote.senderAddress;
145
177
  recipient = quote.recipientAddress;
178
+ output.sellAsset = {};
146
179
  output.sellAsset.caip = quote.sellAsset;
147
180
  output.sellAmount = quote.sellAmount;
181
+ output.buyAsset = {};
148
182
  output.buyAsset.caip = quote.buyAsset;
149
183
  inputChain = caipToNetworkId(quote.sellAsset);
150
184
  outputChain = caipToNetworkId(quote.buyAsset);
@@ -212,7 +246,7 @@ var get_quote = function (quote) {
212
246
  tokenOutChainId: chainIdInt,
213
247
  amount: "10000000000000000000",
214
248
  tradeType: 'EXACT_INPUT',
215
- sendPortionEnabled: false,
249
+ sendPortionEnabled: true,
216
250
  };
217
251
  Protocol = void 0;
218
252
  (function (Protocol) {
@@ -252,6 +286,9 @@ var get_quote = function (quote) {
252
286
  }
253
287
  ],
254
288
  };
289
+ // const UNISWAP_GATEWAY_DNS_URL = 'https://interface.gateway.uniswap.org/v2'
290
+ log.info("requestBody: ", requestBody);
291
+ log.info("requestBody: ", JSON.stringify(requestBody));
255
292
  return [4 /*yield*/, (0, axios_1.default)({
256
293
  method: 'POST',
257
294
  url: 'https://interface.gateway.uniswap.org/v2/quote',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/uniswap-client",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "dependencies": {
@@ -9,6 +9,7 @@
9
9
  "@pioneer-platform/maya-network": "^8.3.7",
10
10
  "@pioneer-platform/pioneer-caip": "^9.2.23",
11
11
  "@pioneer-platform/pioneer-coins": "^9.2.13",
12
+ "@pioneer-platform/pioneer-discovery": "^0.0.7",
12
13
  "@types/ms": "^0.7.34",
13
14
  "@types/ms.macro": "^2.0.2",
14
15
  "@uniswap/router-sdk": "1.9.0",
@@ -30,6 +31,7 @@
30
31
  "scripts": {
31
32
  "npm": "npm i",
32
33
  "test": "npm run build && node __tests__/test-module.js",
34
+ "test-sdk": "npm run build && node __tests__/test-module-sdk.js",
33
35
  "build": "tsc -p .",
34
36
  "prepublish": "npm run build",
35
37
  "refresh": "rm -rf ./node_modules ./package-lock.json && npm install"