@openocean.finance/openocean-sdk 1.2.34 → 1.2.36

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 (38) hide show
  1. package/lib/api/index.js +205 -0
  2. package/lib/api/vo/RequestVo.js +401 -0
  3. package/lib/asset/abi/ERC20_abi.js +119 -0
  4. package/lib/asset/abi/aggregator.js +391 -0
  5. package/lib/config/index.js +33 -0
  6. package/lib/index.d.ts +1 -1
  7. package/lib/index.js +50 -2
  8. package/lib/swapSdk/Approve.js +349 -0
  9. package/lib/swapSdk/NotoMobile.js +144 -0
  10. package/lib/swapSdk/RequestVo.js +94 -0
  11. package/lib/swapSdk/Swap.js +1159 -0
  12. package/lib/swapSdk/getAllowance.js +98 -0
  13. package/lib/swapSdk/getBalance.js +280 -0
  14. package/lib/swapSdk/index.js +257 -0
  15. package/lib/swapSdk/qrcode.js +969 -0
  16. package/lib/utils/ajx.js +153 -0
  17. package/lib/utils/index.js +367 -0
  18. package/lib/utils/web3.js +9 -0
  19. package/lib/v1/abis/ERC20.js +22 -0
  20. package/lib/v1/abis/IUniswapV2Pair.js +1434 -0
  21. package/lib/v1/constants.js +71 -0
  22. package/lib/v1/entities/currency.js +39 -0
  23. package/lib/v1/entities/fractions/currencyAmount.js +83 -0
  24. package/lib/v1/entities/fractions/fraction.js +109 -0
  25. package/lib/v1/entities/fractions/index.js +21 -0
  26. package/lib/v1/entities/fractions/percent.js +37 -0
  27. package/lib/v1/entities/fractions/price.js +90 -0
  28. package/lib/v1/entities/fractions/tokenAmount.js +43 -0
  29. package/lib/v1/entities/index.js +22 -0
  30. package/lib/v1/entities/pair.js +210 -0
  31. package/lib/v1/entities/route.js +43 -0
  32. package/lib/v1/entities/token.js +87 -0
  33. package/lib/v1/entities/trade.js +336 -0
  34. package/lib/v1/errors.js +56 -0
  35. package/lib/v1/fetcher.js +140 -0
  36. package/lib/v1/router.js +97 -0
  37. package/lib/v1/utils.js +87 -0
  38. package/package.json +2 -2
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.post = exports.get = exports.validateReq = void 0;
43
+ var class_validator_1 = require("class-validator");
44
+ var class_transformer_1 = require("class-transformer");
45
+ var axios_1 = __importDefault(require("axios"));
46
+ function validateReq(option, vo) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ var reqAllowanceVo, errors;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0:
52
+ reqAllowanceVo = (0, class_transformer_1.plainToClass)(vo, option);
53
+ return [4 /*yield*/, (0, class_validator_1.validate)(reqAllowanceVo)];
54
+ case 1:
55
+ errors = _a.sent();
56
+ if (errors.length) {
57
+ return [2 /*return*/, errors.reduce(function (o, n) {
58
+ Object.keys(n.constraints).forEach(function (key) {
59
+ o.push(n.constraints[key]);
60
+ });
61
+ return o;
62
+ }, []).join(', ')];
63
+ }
64
+ return [2 /*return*/];
65
+ }
66
+ });
67
+ });
68
+ }
69
+ exports.validateReq = validateReq;
70
+ function get(url, option, vo) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var _this = this;
73
+ return __generator(this, function (_a) {
74
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
75
+ var errors, error_1;
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0:
79
+ _a.trys.push([0, 2, , 3]);
80
+ return [4 /*yield*/, validateReq(option, vo)];
81
+ case 1:
82
+ errors = _a.sent();
83
+ if (errors) {
84
+ reject(errors);
85
+ }
86
+ else {
87
+ (0, axios_1.default)({
88
+ method: 'get',
89
+ url: "".concat(url),
90
+ params: option
91
+ })
92
+ .then(function (response) {
93
+ resolve(response.data);
94
+ })
95
+ .catch(function (error) {
96
+ reject(error ? error.message : 'An unknown error');
97
+ });
98
+ }
99
+ return [3 /*break*/, 3];
100
+ case 2:
101
+ error_1 = _a.sent();
102
+ reject(error_1 || 'An unknown error');
103
+ return [3 /*break*/, 3];
104
+ case 3: return [2 /*return*/];
105
+ }
106
+ });
107
+ }); })];
108
+ });
109
+ });
110
+ }
111
+ exports.get = get;
112
+ function post(url, option, vo) {
113
+ return __awaiter(this, void 0, void 0, function () {
114
+ var _this = this;
115
+ return __generator(this, function (_a) {
116
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
117
+ var errors, error_2;
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
+ case 0:
121
+ _a.trys.push([0, 2, , 3]);
122
+ return [4 /*yield*/, validateReq(option, vo)];
123
+ case 1:
124
+ errors = _a.sent();
125
+ if (errors) {
126
+ reject(errors);
127
+ }
128
+ else {
129
+ (0, axios_1.default)({
130
+ method: 'post',
131
+ url: "".concat(url),
132
+ data: option
133
+ })
134
+ .then(function (response) {
135
+ resolve(response.data);
136
+ })
137
+ .catch(function (error) {
138
+ reject(error ? error.message : 'An unknown error');
139
+ });
140
+ }
141
+ return [3 /*break*/, 3];
142
+ case 2:
143
+ error_2 = _a.sent();
144
+ reject(error_2 || 'An unknown error');
145
+ return [3 /*break*/, 3];
146
+ case 3: return [2 /*return*/];
147
+ }
148
+ });
149
+ }); })];
150
+ });
151
+ });
152
+ }
153
+ exports.post = post;
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WETH_ADDRESS = exports.WETH_ABI = exports.EIP_712_ORDER_TYPE = exports.confirmLater = exports.isPc = exports.utils = exports.Utils = exports.ChainNames = void 0;
7
+ var bignumber_js_1 = __importDefault(require("bignumber.js"));
8
+ var ChainNames;
9
+ (function (ChainNames) {
10
+ ChainNames[ChainNames["eth"] = 0] = "eth";
11
+ ChainNames[ChainNames["solana"] = 1] = "solana";
12
+ ChainNames[ChainNames["ont"] = 2] = "ont";
13
+ ChainNames[ChainNames["terra"] = 3] = "terra";
14
+ ChainNames[ChainNames["tron"] = 4] = "tron";
15
+ ChainNames[ChainNames["ropsten"] = 5] = "ropsten";
16
+ ChainNames[ChainNames["bsc"] = 6] = "bsc";
17
+ ChainNames[ChainNames["okex"] = 7] = "okex";
18
+ ChainNames[ChainNames["polygon"] = 8] = "polygon";
19
+ ChainNames[ChainNames["fantom"] = 9] = "fantom";
20
+ ChainNames[ChainNames["heco"] = 10] = "heco";
21
+ ChainNames[ChainNames["avax"] = 11] = "avax";
22
+ ChainNames[ChainNames["arbitrum"] = 12] = "arbitrum";
23
+ ChainNames[ChainNames["xdai"] = 13] = "xdai";
24
+ ChainNames[ChainNames["optimism"] = 14] = "optimism";
25
+ ChainNames[ChainNames["boba"] = 15] = "boba";
26
+ ChainNames[ChainNames["moonriver"] = 16] = "moonriver";
27
+ ChainNames[ChainNames["aurora"] = 17] = "aurora";
28
+ ChainNames[ChainNames["cronos"] = 18] = "cronos";
29
+ ChainNames[ChainNames["cosmos"] = 19] = "cosmos";
30
+ ChainNames[ChainNames["osmosis"] = 20] = "osmosis";
31
+ ChainNames[ChainNames["harmony"] = 21] = "harmony";
32
+ ChainNames[ChainNames["bsctest"] = 22] = "bsctest";
33
+ })(ChainNames = exports.ChainNames || (exports.ChainNames = {}));
34
+ var Utils = /** @class */ (function () {
35
+ function Utils() {
36
+ }
37
+ Utils.prototype.sleep = function (interval) {
38
+ return new Promise(function (resolve) {
39
+ setTimeout(resolve, interval);
40
+ });
41
+ };
42
+ Utils.prototype.getShift = function (a, b) {
43
+ return new bignumber_js_1.default(a).shiftedBy(Number(b)).toFixed();
44
+ };
45
+ Utils.prototype.decimals2Amount = function (amount, decimals) {
46
+ return this.getShift(amount, -decimals);
47
+ };
48
+ Utils.prototype.amount2Decimals = function (amount, decimals) {
49
+ return this.getFixed(this.getShift(amount, decimals), 0);
50
+ };
51
+ Utils.prototype.getFixed = function (val, fixed, trailingZeros) {
52
+ var numStr = val || '0';
53
+ if (trailingZeros) {
54
+ return new bignumber_js_1.default(numStr).toFixed(fixed);
55
+ }
56
+ return new bignumber_js_1.default(numStr).decimalPlaces(fixed).toString();
57
+ };
58
+ Utils.prototype.toFixed = function (n, k, z) {
59
+ if (isNaN(n)) {
60
+ return 0;
61
+ }
62
+ if (!k)
63
+ k = 4;
64
+ return new bignumber_js_1.default(n).toFixed(k, 1);
65
+ // let a = 10 ** k
66
+ // if (Number(n) < 0) {
67
+ // a = Math.ceil(Number(n) * a) / a
68
+ // } else {
69
+ // a = Math.floor(Number(n) * a) / a
70
+ // }
71
+ // if (!z) {
72
+ // return a
73
+ // } else {
74
+ // return a.toFixed(k)
75
+ // }
76
+ };
77
+ return Utils;
78
+ }());
79
+ exports.Utils = Utils;
80
+ exports.utils = new Utils();
81
+ function isPc() {
82
+ var userAgent = navigator.userAgent, Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
83
+ console.log('userAgent:', userAgent);
84
+ return Agents.some(function (i) {
85
+ return userAgent.includes(i);
86
+ });
87
+ }
88
+ exports.isPc = isPc;
89
+ function confirmLater(promise) {
90
+ return new Promise(function (resolve, reject) {
91
+ promise.on("transactionHash", resolve);
92
+ promise.on("error", reject);
93
+ function onConfirm(confNumber, receipt) {
94
+ promise.off("confirmation", onConfirm);
95
+ }
96
+ promise.on("confirmation", onConfirm);
97
+ });
98
+ }
99
+ exports.confirmLater = confirmLater;
100
+ exports.EIP_712_ORDER_TYPE = {
101
+ EIP712Domain: [
102
+ {
103
+ name: "name",
104
+ type: "string",
105
+ },
106
+ {
107
+ name: "version",
108
+ type: "string",
109
+ },
110
+ {
111
+ name: "chainId",
112
+ type: "uint256",
113
+ },
114
+ {
115
+ name: "verifyingContract",
116
+ type: "address",
117
+ },
118
+ ],
119
+ OrderComponents: [
120
+ {
121
+ name: "offerer",
122
+ type: "address",
123
+ },
124
+ {
125
+ name: "zone",
126
+ type: "address",
127
+ },
128
+ {
129
+ name: "offer",
130
+ type: "OfferItem[]",
131
+ },
132
+ {
133
+ name: "consideration",
134
+ type: "ConsiderationItem[]",
135
+ },
136
+ {
137
+ name: "orderType",
138
+ type: "uint8",
139
+ },
140
+ {
141
+ name: "startTime",
142
+ type: "uint256",
143
+ },
144
+ {
145
+ name: "endTime",
146
+ type: "uint256",
147
+ },
148
+ {
149
+ name: "zoneHash",
150
+ type: "bytes32",
151
+ },
152
+ {
153
+ name: "salt",
154
+ type: "uint256",
155
+ },
156
+ {
157
+ name: "conduitKey",
158
+ type: "bytes32",
159
+ },
160
+ {
161
+ name: "counter",
162
+ type: "uint256",
163
+ },
164
+ ],
165
+ OfferItem: [
166
+ {
167
+ name: "itemType",
168
+ type: "uint8",
169
+ },
170
+ {
171
+ name: "token",
172
+ type: "address",
173
+ },
174
+ {
175
+ name: "identifierOrCriteria",
176
+ type: "uint256",
177
+ },
178
+ {
179
+ name: "startAmount",
180
+ type: "uint256",
181
+ },
182
+ {
183
+ name: "endAmount",
184
+ type: "uint256",
185
+ },
186
+ ],
187
+ ConsiderationItem: [
188
+ {
189
+ name: "itemType",
190
+ type: "uint8",
191
+ },
192
+ {
193
+ name: "token",
194
+ type: "address",
195
+ },
196
+ {
197
+ name: "identifierOrCriteria",
198
+ type: "uint256",
199
+ },
200
+ {
201
+ name: "startAmount",
202
+ type: "uint256",
203
+ },
204
+ {
205
+ name: "endAmount",
206
+ type: "uint256",
207
+ },
208
+ {
209
+ name: "recipient",
210
+ type: "address",
211
+ },
212
+ ],
213
+ };
214
+ exports.WETH_ABI = [
215
+ {
216
+ constant: true,
217
+ inputs: [],
218
+ name: "name",
219
+ outputs: [{ name: "", type: "string" }],
220
+ payable: false,
221
+ stateMutability: "view",
222
+ type: "function",
223
+ },
224
+ {
225
+ constant: false,
226
+ inputs: [
227
+ { name: "guy", type: "address" },
228
+ { name: "wad", type: "uint256" },
229
+ ],
230
+ name: "approve",
231
+ outputs: [{ name: "", type: "bool" }],
232
+ payable: false,
233
+ stateMutability: "nonpayable",
234
+ type: "function",
235
+ },
236
+ {
237
+ constant: true,
238
+ inputs: [],
239
+ name: "totalSupply",
240
+ outputs: [{ name: "", type: "uint256" }],
241
+ payable: false,
242
+ stateMutability: "view",
243
+ type: "function",
244
+ },
245
+ {
246
+ constant: false,
247
+ inputs: [
248
+ { name: "src", type: "address" },
249
+ { name: "dst", type: "address" },
250
+ { name: "wad", type: "uint256" },
251
+ ],
252
+ name: "transferFrom",
253
+ outputs: [{ name: "", type: "bool" }],
254
+ payable: false,
255
+ stateMutability: "nonpayable",
256
+ type: "function",
257
+ },
258
+ {
259
+ constant: false,
260
+ inputs: [{ name: "wad", type: "uint256" }],
261
+ name: "withdraw",
262
+ outputs: [],
263
+ payable: false,
264
+ stateMutability: "nonpayable",
265
+ type: "function",
266
+ },
267
+ {
268
+ constant: true,
269
+ inputs: [],
270
+ name: "decimals",
271
+ outputs: [{ name: "", type: "uint8" }],
272
+ payable: false,
273
+ stateMutability: "view",
274
+ type: "function",
275
+ },
276
+ {
277
+ constant: true,
278
+ inputs: [{ name: "", type: "address" }],
279
+ name: "balanceOf",
280
+ outputs: [{ name: "", type: "uint256" }],
281
+ payable: false,
282
+ stateMutability: "view",
283
+ type: "function",
284
+ },
285
+ {
286
+ constant: true,
287
+ inputs: [],
288
+ name: "symbol",
289
+ outputs: [{ name: "", type: "string" }],
290
+ payable: false,
291
+ stateMutability: "view",
292
+ type: "function",
293
+ },
294
+ {
295
+ constant: false,
296
+ inputs: [
297
+ { name: "dst", type: "address" },
298
+ { name: "wad", type: "uint256" },
299
+ ],
300
+ name: "transfer",
301
+ outputs: [{ name: "", type: "bool" }],
302
+ payable: false,
303
+ stateMutability: "nonpayable",
304
+ type: "function",
305
+ },
306
+ {
307
+ constant: false,
308
+ inputs: [],
309
+ name: "deposit",
310
+ outputs: [],
311
+ payable: true,
312
+ stateMutability: "payable",
313
+ type: "function",
314
+ },
315
+ {
316
+ constant: true,
317
+ inputs: [
318
+ { name: "", type: "address" },
319
+ { name: "", type: "address" },
320
+ ],
321
+ name: "allowance",
322
+ outputs: [{ name: "", type: "uint256" }],
323
+ payable: false,
324
+ stateMutability: "view",
325
+ type: "function",
326
+ },
327
+ { payable: true, stateMutability: "payable", type: "fallback" },
328
+ {
329
+ anonymous: false,
330
+ inputs: [
331
+ { indexed: true, name: "src", type: "address" },
332
+ { indexed: true, name: "guy", type: "address" },
333
+ { indexed: false, name: "wad", type: "uint256" },
334
+ ],
335
+ name: "Approval",
336
+ type: "event",
337
+ },
338
+ {
339
+ anonymous: false,
340
+ inputs: [
341
+ { indexed: true, name: "src", type: "address" },
342
+ { indexed: true, name: "dst", type: "address" },
343
+ { indexed: false, name: "wad", type: "uint256" },
344
+ ],
345
+ name: "Transfer",
346
+ type: "event",
347
+ },
348
+ {
349
+ anonymous: false,
350
+ inputs: [
351
+ { indexed: true, name: "dst", type: "address" },
352
+ { indexed: false, name: "wad", type: "uint256" },
353
+ ],
354
+ name: "Deposit",
355
+ type: "event",
356
+ },
357
+ {
358
+ anonymous: false,
359
+ inputs: [
360
+ { indexed: true, name: "src", type: "address" },
361
+ { indexed: false, name: "wad", type: "uint256" },
362
+ ],
363
+ name: "Withdrawal",
364
+ type: "event",
365
+ },
366
+ ];
367
+ exports.WETH_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Web3 = exports.web3 = void 0;
7
+ var web3_1 = __importDefault(require("web3"));
8
+ exports.Web3 = web3_1.default;
9
+ exports.web3 = new web3_1.default();
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = [
4
+ {
5
+ "constant": true,
6
+ "inputs": [],
7
+ "name": "decimals",
8
+ "outputs": [{ "name": "", "type": "uint8" }],
9
+ "payable": false,
10
+ "stateMutability": "view",
11
+ "type": "function"
12
+ },
13
+ {
14
+ "constant": true,
15
+ "inputs": [{ "name": "", "type": "address" }],
16
+ "name": "balanceOf",
17
+ "outputs": [{ "name": "", "type": "uint256" }],
18
+ "payable": false,
19
+ "stateMutability": "view",
20
+ "type": "function"
21
+ }
22
+ ];