@openocean.finance/openocean-sdk 0.5.35 → 1.0.1

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