@openocean.finance/openocean-sdk 0.1.61 → 0.1.63

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,91 @@
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.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["osmosis"] = 5] = "osmosis";
17
+ ChainNames[ChainNames["sifchain"] = 6] = "sifchain";
18
+ ChainNames[ChainNames["ropsten"] = 7] = "ropsten";
19
+ ChainNames[ChainNames["bsc"] = 8] = "bsc";
20
+ ChainNames[ChainNames["okex"] = 9] = "okex";
21
+ ChainNames[ChainNames["polygon"] = 10] = "polygon";
22
+ ChainNames[ChainNames["fantom"] = 11] = "fantom";
23
+ ChainNames[ChainNames["heco"] = 12] = "heco";
24
+ ChainNames[ChainNames["avax"] = 13] = "avax";
25
+ ChainNames[ChainNames["arbitrum"] = 14] = "arbitrum";
26
+ ChainNames[ChainNames["xdai"] = 15] = "xdai";
27
+ ChainNames[ChainNames["optimism"] = 16] = "optimism";
28
+ ChainNames[ChainNames["boba"] = 17] = "boba";
29
+ ChainNames[ChainNames["moonriver"] = 18] = "moonriver";
30
+ ChainNames[ChainNames["aurora"] = 19] = "aurora";
31
+ ChainNames[ChainNames["cronos"] = 20] = "cronos";
32
+ ChainNames[ChainNames["cosmos"] = 21] = "cosmos";
33
+ ChainNames[ChainNames["harmony"] = 22] = "harmony";
34
+ ChainNames[ChainNames["bsctest"] = 23] = "bsctest";
35
+ })(ChainNames = exports.ChainNames || (exports.ChainNames = {}));
36
+ var Utils = /** @class */ (function () {
37
+ function Utils() {
38
+ }
39
+ Utils.prototype.sleep = function (interval) {
40
+ return new Promise(function (resolve) {
41
+ setTimeout(resolve, interval);
42
+ });
43
+ };
44
+ Utils.prototype.getShift = function (a, b) {
45
+ return new bignumber_js_1.default(a).shiftedBy(Number(b)).toFixed();
46
+ };
47
+ Utils.prototype.decimals2Amount = function (amount, decimals) {
48
+ return this.getShift(amount, -decimals);
49
+ };
50
+ Utils.prototype.amount2Decimals = function (amount, decimals) {
51
+ return this.getFixed(this.getShift(amount, decimals), 0);
52
+ };
53
+ Utils.prototype.getFixed = function (val, fixed, trailingZeros) {
54
+ var numStr = val || '0';
55
+ if (trailingZeros) {
56
+ return new bignumber_js_1.default(numStr).toFixed(fixed);
57
+ }
58
+ return new bignumber_js_1.default(numStr).decimalPlaces(fixed).toString();
59
+ };
60
+ Utils.prototype.toFixed = function (n, k, z) {
61
+ if (isNaN(n)) {
62
+ return 0;
63
+ }
64
+ if (!k)
65
+ k = 4;
66
+ var a = Math.pow(10, k);
67
+ if (Number(n) < 0) {
68
+ a = Math.ceil(Number(n) * a) / a;
69
+ }
70
+ else {
71
+ a = Math.floor(Number(n) * a) / a;
72
+ }
73
+ if (!z) {
74
+ return a;
75
+ }
76
+ else {
77
+ return a.toFixed(k);
78
+ }
79
+ };
80
+ return Utils;
81
+ }());
82
+ exports.Utils = Utils;
83
+ exports.utils = new Utils();
84
+ function isPc() {
85
+ var userAgent = navigator.userAgent, Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
86
+ console.log('userAgent:', userAgent);
87
+ return Agents.some(function (i) {
88
+ return userAgent.includes(i);
89
+ });
90
+ }
91
+ exports.isPc = isPc;
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/openocean-sdk",
3
- "version": "0.1.61",
3
+ "version": "0.1.63",
4
4
  "description": "Openocean sdk",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@jup-ag/core": "^1.0.0-beta.27",
49
- "@openocean.finance/wallet": "^0.4.28",
49
+ "@openocean.finance/wallet": "^0.4.29",
50
50
  "@solana/buffer-layout": "^4.0.0",
51
51
  "@walletconnect/web3-provider": "^1.7.8",
52
52
  "bs58": "^4.0.1",