@lifi/sdk 1.2.0 → 1.3.0

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.3.0](https://github.com/lifinance/sdk/compare/v1.2.2...v1.3.0) (2022-09-05)
6
+
7
+
8
+ ### Features
9
+
10
+ * add TransactionRejected error ([#104](https://github.com/lifinance/sdk/issues/104)) ([2c180fd](https://github.com/lifinance/sdk/commit/2c180fd0cedbdf3acbf77326d69eb2a328c59170))
11
+ * **config:** set default integrator string ([#107](https://github.com/lifinance/sdk/issues/107)) ([f8ef3bf](https://github.com/lifinance/sdk/commit/f8ef3bfeff8bf0e6d5d9eec172bb7d7d86ec123f))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * duplicates for LifiErrorCodes ([#106](https://github.com/lifinance/sdk/issues/106)) ([d63a80b](https://github.com/lifinance/sdk/commit/d63a80b2106d7f18d51e9f30b49dc896f5a30019))
17
+
18
+ ### [1.2.2](https://github.com/lifinance/sdk/compare/v1.2.1...v1.2.2) (2022-08-24)
19
+
20
+ ### [1.2.1](https://github.com/lifinance/sdk/compare/v1.2.0...v1.2.1) (2022-08-22)
21
+
5
22
  ## [1.2.0](https://github.com/lifinance/sdk/compare/v1.1.6...v1.2.0) (2022-08-22)
6
23
 
7
24
 
@@ -72,7 +72,7 @@ const checkPackageUpdates = (packageName, packageVersion, disableCheck) => __awa
72
72
  }
73
73
  try {
74
74
  const pkgName = packageName !== null && packageName !== void 0 ? packageName : version_1.name;
75
- const response = yield (yield fetch(`https://unpkg.com/${pkgName}/package.json`)).json();
75
+ const response = yield (yield fetch(`https://registry.npmjs.org/${pkgName}/latest`)).json();
76
76
  const latestVersion = response.version;
77
77
  const currentVersion = packageVersion !== null && packageVersion !== void 0 ? packageVersion : version_1.version;
78
78
  if (semverCompare(latestVersion, currentVersion)) {
@@ -93,6 +93,8 @@ ConfigService.getDefaultConfig = () => {
93
93
  rpcs: ConfigService.chainIdToObject([]),
94
94
  multicallAddresses: ConfigService.chainIdToObject(undefined),
95
95
  defaultExecutionSettings: DefaultExecutionSettings,
96
- defaultRouteOptions: {},
96
+ defaultRouteOptions: {
97
+ integrator: 'lifi-sdk',
98
+ },
97
99
  };
98
100
  };
@@ -13,14 +13,15 @@ export declare enum LifiErrorCode {
13
13
  ValidationError = 1001,
14
14
  TransactionUnderpriced = 1002,
15
15
  TransactionFailed = 1003,
16
- TransactionUnprepared = 1008,
17
16
  Timeout = 1004,
18
17
  ProviderUnavailable = 1005,
19
18
  NotFound = 1006,
20
19
  ChainSwitchError = 1007,
21
- SlippageNotMet = 1008,
22
- SlippageError = 1008,
23
- GasLimitError = 1009
20
+ TransactionUnprepared = 1008,
21
+ GasLimitError = 1009,
22
+ SlippageNotMet = 1010,
23
+ SlippageError = 1011,
24
+ TransactionRejected = 1012
24
25
  }
25
26
  export declare enum MetaMaskRPCErrorCode {
26
27
  invalidInput = -32000,
@@ -18,14 +18,15 @@ var LifiErrorCode;
18
18
  LifiErrorCode[LifiErrorCode["ValidationError"] = 1001] = "ValidationError";
19
19
  LifiErrorCode[LifiErrorCode["TransactionUnderpriced"] = 1002] = "TransactionUnderpriced";
20
20
  LifiErrorCode[LifiErrorCode["TransactionFailed"] = 1003] = "TransactionFailed";
21
- LifiErrorCode[LifiErrorCode["TransactionUnprepared"] = 1008] = "TransactionUnprepared";
22
21
  LifiErrorCode[LifiErrorCode["Timeout"] = 1004] = "Timeout";
23
22
  LifiErrorCode[LifiErrorCode["ProviderUnavailable"] = 1005] = "ProviderUnavailable";
24
23
  LifiErrorCode[LifiErrorCode["NotFound"] = 1006] = "NotFound";
25
24
  LifiErrorCode[LifiErrorCode["ChainSwitchError"] = 1007] = "ChainSwitchError";
26
- LifiErrorCode[LifiErrorCode["SlippageNotMet"] = 1008] = "SlippageNotMet";
27
- LifiErrorCode[LifiErrorCode["SlippageError"] = 1008] = "SlippageError";
25
+ LifiErrorCode[LifiErrorCode["TransactionUnprepared"] = 1008] = "TransactionUnprepared";
28
26
  LifiErrorCode[LifiErrorCode["GasLimitError"] = 1009] = "GasLimitError";
27
+ LifiErrorCode[LifiErrorCode["SlippageNotMet"] = 1010] = "SlippageNotMet";
28
+ LifiErrorCode[LifiErrorCode["SlippageError"] = 1011] = "SlippageError";
29
+ LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected";
29
30
  })(LifiErrorCode = exports.LifiErrorCode || (exports.LifiErrorCode = {}));
30
31
  var MetaMaskRPCErrorCode;
31
32
  (function (MetaMaskRPCErrorCode) {
@@ -103,17 +103,20 @@ const parseError = (e, step, process) => __awaiter(void 0, void 0, void 0, funct
103
103
  return new errors_1.ProviderError(e.code, (0, eth_rpc_errors_1.getMessageFromCode)(e.code), yield (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
104
104
  }
105
105
  }
106
- if (e.code === 'CALL_EXCEPTION') {
106
+ }
107
+ switch (e.code) {
108
+ case 'CALL_EXCEPTION':
107
109
  return new errors_1.ProviderError(errors_1.LifiErrorCode.TransactionFailed, e.reason, yield (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
108
- }
109
- if (e.code === errors_1.LifiErrorCode.TransactionUnprepared) {
110
+ case 'ACTION_REJECTED':
111
+ case errors_1.MetaMaskProviderErrorCode.userRejectedRequest:
112
+ return new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionRejected, e.message, yield (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
113
+ case errors_1.LifiErrorCode.TransactionUnprepared:
110
114
  return new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionUnprepared, e.message, yield (0, exports.getTransactionNotSentMessage)(step, process), e.stack);
111
- }
112
- if (e.code === errors_1.LifiErrorCode.ValidationError) {
115
+ case errors_1.LifiErrorCode.ValidationError:
113
116
  return new errors_1.TransactionError(errors_1.LifiErrorCode.ValidationError, e.message, e.htmlMessage);
114
- }
117
+ default:
118
+ return new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message || 'Unknown error occurred.', undefined, e.stack);
115
119
  }
116
- return new errors_1.UnknownError(errors_1.LifiErrorCode.InternalError, e.message || 'Unknown error occurred.', undefined, e.stack);
117
120
  });
118
121
  exports.parseError = parseError;
119
122
  const parseBackendError = (e) => {
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "1.2.0";
2
+ export declare const version = "1.3.0";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.name = void 0;
4
4
  exports.name = '@lifi/sdk';
5
- exports.version = '1.2.0';
5
+ exports.version = '1.3.0';
package/dist/helpers.js CHANGED
@@ -65,7 +65,7 @@ export const checkPackageUpdates = (packageName, packageVersion, disableCheck) =
65
65
  }
66
66
  try {
67
67
  const pkgName = packageName !== null && packageName !== void 0 ? packageName : name;
68
- const response = yield (yield fetch(`https://unpkg.com/${pkgName}/package.json`)).json();
68
+ const response = yield (yield fetch(`https://registry.npmjs.org/${pkgName}/latest`)).json();
69
69
  const latestVersion = response.version;
70
70
  const currentVersion = packageVersion !== null && packageVersion !== void 0 ? packageVersion : version;
71
71
  if (semverCompare(latestVersion, currentVersion)) {
@@ -90,6 +90,8 @@ ConfigService.getDefaultConfig = () => {
90
90
  rpcs: ConfigService.chainIdToObject([]),
91
91
  multicallAddresses: ConfigService.chainIdToObject(undefined),
92
92
  defaultExecutionSettings: DefaultExecutionSettings,
93
- defaultRouteOptions: {},
93
+ defaultRouteOptions: {
94
+ integrator: 'lifi-sdk',
95
+ },
94
96
  };
95
97
  };
@@ -13,14 +13,15 @@ export declare enum LifiErrorCode {
13
13
  ValidationError = 1001,
14
14
  TransactionUnderpriced = 1002,
15
15
  TransactionFailed = 1003,
16
- TransactionUnprepared = 1008,
17
16
  Timeout = 1004,
18
17
  ProviderUnavailable = 1005,
19
18
  NotFound = 1006,
20
19
  ChainSwitchError = 1007,
21
- SlippageNotMet = 1008,
22
- SlippageError = 1008,
23
- GasLimitError = 1009
20
+ TransactionUnprepared = 1008,
21
+ GasLimitError = 1009,
22
+ SlippageNotMet = 1010,
23
+ SlippageError = 1011,
24
+ TransactionRejected = 1012
24
25
  }
25
26
  export declare enum MetaMaskRPCErrorCode {
26
27
  invalidInput = -32000,
@@ -15,14 +15,15 @@ export var LifiErrorCode;
15
15
  LifiErrorCode[LifiErrorCode["ValidationError"] = 1001] = "ValidationError";
16
16
  LifiErrorCode[LifiErrorCode["TransactionUnderpriced"] = 1002] = "TransactionUnderpriced";
17
17
  LifiErrorCode[LifiErrorCode["TransactionFailed"] = 1003] = "TransactionFailed";
18
- LifiErrorCode[LifiErrorCode["TransactionUnprepared"] = 1008] = "TransactionUnprepared";
19
18
  LifiErrorCode[LifiErrorCode["Timeout"] = 1004] = "Timeout";
20
19
  LifiErrorCode[LifiErrorCode["ProviderUnavailable"] = 1005] = "ProviderUnavailable";
21
20
  LifiErrorCode[LifiErrorCode["NotFound"] = 1006] = "NotFound";
22
21
  LifiErrorCode[LifiErrorCode["ChainSwitchError"] = 1007] = "ChainSwitchError";
23
- LifiErrorCode[LifiErrorCode["SlippageNotMet"] = 1008] = "SlippageNotMet";
24
- LifiErrorCode[LifiErrorCode["SlippageError"] = 1008] = "SlippageError";
22
+ LifiErrorCode[LifiErrorCode["TransactionUnprepared"] = 1008] = "TransactionUnprepared";
25
23
  LifiErrorCode[LifiErrorCode["GasLimitError"] = 1009] = "GasLimitError";
24
+ LifiErrorCode[LifiErrorCode["SlippageNotMet"] = 1010] = "SlippageNotMet";
25
+ LifiErrorCode[LifiErrorCode["SlippageError"] = 1011] = "SlippageError";
26
+ LifiErrorCode[LifiErrorCode["TransactionRejected"] = 1012] = "TransactionRejected";
26
27
  })(LifiErrorCode || (LifiErrorCode = {}));
27
28
  export var MetaMaskRPCErrorCode;
28
29
  (function (MetaMaskRPCErrorCode) {
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { getChainById } from '@lifi/types';
11
11
  import { errorCodes as MetaMaskErrorCodes, getMessageFromCode, } from 'eth-rpc-errors';
12
12
  import ChainsService from '../services/ChainsService';
13
- import { LifiError, LifiErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
13
+ import { LifiError, LifiErrorCode, MetaMaskProviderErrorCode, NotFoundError, ProviderError, RPCError, ServerError, SlippageError, TransactionError, UnknownError, ValidationError, } from './errors';
14
14
  import { formatTokenAmountOnly } from './utils';
15
15
  /**
16
16
  * Available MetaMask error codes:
@@ -95,17 +95,20 @@ export const parseError = (e, step, process) => __awaiter(void 0, void 0, void 0
95
95
  return new ProviderError(e.code, getMessageFromCode(e.code), yield getTransactionNotSentMessage(step, process), e.stack);
96
96
  }
97
97
  }
98
- if (e.code === 'CALL_EXCEPTION') {
98
+ }
99
+ switch (e.code) {
100
+ case 'CALL_EXCEPTION':
99
101
  return new ProviderError(LifiErrorCode.TransactionFailed, e.reason, yield getTransactionNotSentMessage(step, process), e.stack);
100
- }
101
- if (e.code === LifiErrorCode.TransactionUnprepared) {
102
+ case 'ACTION_REJECTED':
103
+ case MetaMaskProviderErrorCode.userRejectedRequest:
104
+ return new TransactionError(LifiErrorCode.TransactionRejected, e.message, yield getTransactionNotSentMessage(step, process), e.stack);
105
+ case LifiErrorCode.TransactionUnprepared:
102
106
  return new TransactionError(LifiErrorCode.TransactionUnprepared, e.message, yield getTransactionNotSentMessage(step, process), e.stack);
103
- }
104
- if (e.code === LifiErrorCode.ValidationError) {
107
+ case LifiErrorCode.ValidationError:
105
108
  return new TransactionError(LifiErrorCode.ValidationError, e.message, e.htmlMessage);
106
- }
109
+ default:
110
+ return new UnknownError(LifiErrorCode.InternalError, e.message || 'Unknown error occurred.', undefined, e.stack);
107
111
  }
108
- return new UnknownError(LifiErrorCode.InternalError, e.message || 'Unknown error occurred.', undefined, e.stack);
109
112
  });
110
113
  export const parseBackendError = (e) => {
111
114
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "1.2.0";
2
+ export declare const version = "1.3.0";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk';
2
- export const version = '1.2.0';
2
+ export const version = '1.3.0';
package/package.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
2
  "name": "@lifi/sdk",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
- "exports": {
9
- "require": "./dist/cjs/index.js",
10
- "import": "./dist/index.js"
11
- },
12
8
  "scripts": {
13
9
  "watch": "tsc -w -p ./tsconfig.json",
14
10
  "build": "yarn clean && tsc --project ./tsconfig.json && tsc --project ./tsconfig.cjs.json",
@@ -78,13 +74,13 @@
78
74
  "url": "https://github.com/lifinance/sdk/issues"
79
75
  },
80
76
  "dependencies": {
81
- "@ethersproject/abi": "^5.6.4",
82
- "@ethersproject/contracts": "^5.6.2",
77
+ "@ethersproject/abi": "^5.7.0",
78
+ "@ethersproject/contracts": "^5.7.0",
83
79
  "@lifi/types": "^1.5.1",
84
80
  "axios": "^0.27.2",
85
81
  "bignumber.js": "^9.1.0",
86
82
  "eth-rpc-errors": "^4.0.3",
87
- "ethers": "^5.6.9"
83
+ "ethers": "^5.7.0"
88
84
  },
89
85
  "devDependencies": {
90
86
  "@commitlint/cli": "^17.0.3",
@@ -92,10 +88,10 @@
92
88
  "@types/bip39": "^3.0.0",
93
89
  "@types/chai": "^4.3.3",
94
90
  "@types/hdkey": "^2.0.0",
95
- "@types/jest": "^28.1.7",
91
+ "@types/jest": "^28.1.8",
96
92
  "@types/websocket": "^1.0.4",
97
- "@typescript-eslint/eslint-plugin": "^5.33.1",
98
- "@typescript-eslint/parser": "^5.33.1",
93
+ "@typescript-eslint/eslint-plugin": "^5.34.0",
94
+ "@typescript-eslint/parser": "^5.34.0",
99
95
  "eslint": "^8.22.0",
100
96
  "eslint-config-prettier": "^8.3.0",
101
97
  "eslint-plugin-prettier": "^4.2.1",