@lifi/sdk 1.1.2 → 1.1.5

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 (96) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/Lifi.js +179 -285
  3. package/dist/allowance/index.js +56 -148
  4. package/dist/allowance/utils.js +51 -116
  5. package/dist/balances/index.js +29 -92
  6. package/dist/balances/utils.js +108 -218
  7. package/dist/cjs/Lifi.d.ts +200 -0
  8. package/dist/cjs/Lifi.js +376 -0
  9. package/dist/cjs/allowance/index.d.ts +22 -0
  10. package/dist/cjs/allowance/index.js +78 -0
  11. package/dist/cjs/allowance/utils.d.ts +14 -0
  12. package/dist/cjs/allowance/utils.js +82 -0
  13. package/dist/cjs/balances/index.d.ts +11 -0
  14. package/dist/cjs/balances/index.js +46 -0
  15. package/dist/cjs/balances/utils.d.ts +5 -0
  16. package/dist/cjs/balances/utils.js +150 -0
  17. package/dist/cjs/connectors.d.ts +6 -0
  18. package/dist/cjs/connectors.js +77 -0
  19. package/dist/cjs/execution/StatusManager.d.ts +65 -0
  20. package/dist/cjs/execution/StatusManager.js +167 -0
  21. package/dist/cjs/execution/StepExecutor.d.ts +15 -0
  22. package/dist/cjs/execution/StepExecutor.js +74 -0
  23. package/dist/cjs/execution/allowance.execute.d.ts +4 -0
  24. package/dist/cjs/execution/allowance.execute.js +97 -0
  25. package/dist/cjs/execution/balanceCheck.execute.d.ts +3 -0
  26. package/dist/cjs/execution/balanceCheck.execute.js +48 -0
  27. package/dist/cjs/execution/bridges/bridge.execute.d.ts +7 -0
  28. package/dist/cjs/execution/bridges/bridge.execute.js +154 -0
  29. package/dist/cjs/execution/exchanges/swap.execute.d.ts +7 -0
  30. package/dist/cjs/execution/exchanges/swap.execute.js +164 -0
  31. package/dist/cjs/execution/index.d.ts +1 -0
  32. package/dist/cjs/execution/index.js +17 -0
  33. package/dist/cjs/execution/stepComparison.d.ts +14 -0
  34. package/dist/cjs/execution/stepComparison.js +46 -0
  35. package/dist/cjs/execution/switchChain.d.ts +16 -0
  36. package/dist/cjs/execution/switchChain.js +58 -0
  37. package/dist/cjs/execution/utils.d.ts +6 -0
  38. package/dist/cjs/execution/utils.js +137 -0
  39. package/dist/cjs/helpers.d.ts +18 -0
  40. package/dist/cjs/helpers.js +54 -0
  41. package/dist/cjs/index.d.ts +6 -0
  42. package/dist/cjs/index.js +27 -0
  43. package/dist/cjs/services/ApiService.d.ts +15 -0
  44. package/dist/cjs/services/ApiService.js +272 -0
  45. package/dist/cjs/services/ChainsService.d.ts +11 -0
  46. package/dist/cjs/services/ChainsService.js +54 -0
  47. package/dist/cjs/services/ConfigService.d.ts +23 -0
  48. package/dist/cjs/services/ConfigService.js +98 -0
  49. package/dist/cjs/typeguards.d.ts +4 -0
  50. package/dist/cjs/typeguards.js +53 -0
  51. package/dist/cjs/types/ERC20.d.ts +22 -0
  52. package/dist/cjs/types/ERC20.js +53 -0
  53. package/dist/cjs/types/index.d.ts +4 -0
  54. package/dist/cjs/types/index.js +22 -0
  55. package/dist/cjs/types/internal.types.d.ts +85 -0
  56. package/dist/cjs/types/internal.types.js +2 -0
  57. package/dist/cjs/utils/errors.d.ts +75 -0
  58. package/dist/cjs/utils/errors.js +115 -0
  59. package/dist/cjs/utils/getProvider.d.ts +3 -0
  60. package/dist/cjs/utils/getProvider.js +11 -0
  61. package/dist/cjs/utils/multicall.d.ts +10 -0
  62. package/dist/cjs/utils/multicall.js +77 -0
  63. package/dist/cjs/utils/multicallAbi.json +313 -0
  64. package/dist/cjs/utils/parseError.d.ts +38 -0
  65. package/dist/cjs/utils/parseError.js +141 -0
  66. package/dist/cjs/utils/preRestart.d.ts +2 -0
  67. package/dist/cjs/utils/preRestart.js +31 -0
  68. package/dist/cjs/utils/utils.d.ts +26 -0
  69. package/dist/cjs/utils/utils.js +120 -0
  70. package/dist/connectors.js +50 -133
  71. package/dist/execution/StatusManager.js +34 -41
  72. package/dist/execution/StepExecutor.js +54 -123
  73. package/dist/execution/allowance.execute.js +76 -142
  74. package/dist/execution/balanceCheck.execute.js +29 -74
  75. package/dist/execution/bridges/bridge.execute.js +132 -221
  76. package/dist/execution/exchanges/swap.execute.js +142 -225
  77. package/dist/execution/index.js +1 -17
  78. package/dist/execution/stepComparison.js +22 -61
  79. package/dist/execution/switchChain.js +33 -81
  80. package/dist/execution/utils.js +60 -119
  81. package/dist/helpers.js +15 -53
  82. package/dist/index.js +6 -25
  83. package/dist/services/ApiService.js +248 -385
  84. package/dist/services/ChainsService.js +29 -89
  85. package/dist/services/ConfigService.js +47 -86
  86. package/dist/typeguards.js +13 -21
  87. package/dist/types/ERC20.js +1 -4
  88. package/dist/types/index.js +4 -22
  89. package/dist/types/internal.types.js +1 -2
  90. package/dist/utils/errors.js +47 -93
  91. package/dist/utils/getProvider.js +3 -7
  92. package/dist/utils/multicall.js +61 -117
  93. package/dist/utils/parseError.js +73 -141
  94. package/dist/utils/preRestart.js +14 -21
  95. package/dist/utils/utils.js +47 -130
  96. package/package.json +34 -11
@@ -1,15 +1,3 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,90 +7,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
8
  });
21
9
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.isNativeTokenAddress = exports.isZeroAddress = exports.loadTransactionReceipt = exports.repeatUntilDone = exports.formatTokenAmountOnly = exports.splitListIntoChunks = exports.personalizeStep = exports.sleep = exports.deepClone = void 0;
54
- var bignumber_js_1 = __importDefault(require("bignumber.js"));
55
- var ethers_1 = require("ethers");
56
- var connectors_1 = require("../connectors");
57
- var deepClone = function (src) {
10
+ import BigNumber from 'bignumber.js';
11
+ import { constants } from 'ethers';
12
+ import { getRpcProvider } from '../connectors';
13
+ export const deepClone = (src) => {
58
14
  return JSON.parse(JSON.stringify(src));
59
15
  };
60
- exports.deepClone = deepClone;
61
- var sleep = function (mills) {
62
- return new Promise(function (resolve) {
16
+ export const sleep = (mills) => {
17
+ return new Promise((resolve) => {
63
18
  setTimeout(resolve, mills);
64
19
  });
65
20
  };
66
- exports.sleep = sleep;
67
- var personalizeStep = function (signer, step) { return __awaiter(void 0, void 0, void 0, function () {
68
- var address, fromAddress, toAddress;
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
71
- case 0:
72
- if (step.action.toAddress && step.action.fromAddress) {
73
- return [2 /*return*/, step];
74
- }
75
- return [4 /*yield*/, signer.getAddress()];
76
- case 1:
77
- address = _a.sent();
78
- fromAddress = step.action.fromAddress || address;
79
- toAddress = step.action.toAddress || address;
80
- return [2 /*return*/, __assign(__assign({}, step), { action: __assign(__assign({}, step.action), { fromAddress: fromAddress, toAddress: toAddress }) })];
81
- }
82
- });
83
- }); };
84
- exports.personalizeStep = personalizeStep;
85
- var splitListIntoChunks = function (list, chunkSize) {
86
- return list.reduce(function (resultList, item, index) {
87
- var chunkIndex = Math.floor(index / chunkSize);
88
- if (!resultList[chunkIndex]) {
89
- resultList[chunkIndex] = []; // start a new chunk
90
- }
91
- resultList[chunkIndex].push(item);
92
- return resultList;
93
- }, []);
94
- };
95
- exports.splitListIntoChunks = splitListIntoChunks;
96
- var formatTokenAmountOnly = function (token, amount) {
21
+ export const personalizeStep = (signer, step) => __awaiter(void 0, void 0, void 0, function* () {
22
+ if (step.action.toAddress && step.action.fromAddress) {
23
+ return step;
24
+ }
25
+ const address = yield signer.getAddress();
26
+ const fromAddress = step.action.fromAddress || address;
27
+ const toAddress = step.action.toAddress || address;
28
+ return Object.assign(Object.assign({}, step), { action: Object.assign(Object.assign({}, step.action), { fromAddress,
29
+ toAddress }) });
30
+ });
31
+ export const splitListIntoChunks = (list, chunkSize) => list.reduce((resultList, item, index) => {
32
+ const chunkIndex = Math.floor(index / chunkSize);
33
+ if (!resultList[chunkIndex]) {
34
+ resultList[chunkIndex] = []; // start a new chunk
35
+ }
36
+ resultList[chunkIndex].push(item);
37
+ return resultList;
38
+ }, []);
39
+ export const formatTokenAmountOnly = (token, amount) => {
97
40
  if (!amount) {
98
41
  return '0.0';
99
42
  }
100
- var floated;
43
+ let floated;
101
44
  if (typeof amount === 'string') {
102
45
  if (amount === '0') {
103
46
  return '0.0';
104
47
  }
105
- floated = new bignumber_js_1.default(amount).shiftedBy(-token.decimals);
48
+ floated = new BigNumber(amount).shiftedBy(-token.decimals);
106
49
  }
107
50
  else {
108
51
  floated = amount;
@@ -111,73 +54,48 @@ var formatTokenAmountOnly = function (token, amount) {
111
54
  }
112
55
  }
113
56
  // show at least 4 decimal places and at least two non-zero digests
114
- var decimalPlaces = 3;
57
+ let decimalPlaces = 3;
115
58
  while (floated.lt(1 / Math.pow(10, decimalPlaces))) {
116
59
  decimalPlaces++;
117
60
  }
118
61
  return floated.toFixed(decimalPlaces + 1, 1);
119
62
  };
120
- exports.formatTokenAmountOnly = formatTokenAmountOnly;
121
63
  /**
122
64
  * Repeatedly calls a given asynchronous function until it resolves with a value
123
65
  * @param toRepeat The function that should be repeated
124
66
  * @param timeout The timeout in milliseconds between retries, defaults to 5000
125
67
  * @returns The result of the toRepeat function
126
68
  */
127
- var repeatUntilDone = function (toRepeat, timeout) {
128
- if (timeout === void 0) { timeout = 5000; }
129
- return __awaiter(void 0, void 0, void 0, function () {
130
- var result;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0:
134
- if (!!result) return [3 /*break*/, 4];
135
- return [4 /*yield*/, toRepeat()];
136
- case 1:
137
- result = _a.sent();
138
- if (!!result) return [3 /*break*/, 3];
139
- return [4 /*yield*/, (0, exports.sleep)(timeout)];
140
- case 2:
141
- _a.sent();
142
- _a.label = 3;
143
- case 3: return [3 /*break*/, 0];
144
- case 4: return [2 /*return*/, result];
145
- }
146
- });
147
- });
148
- };
149
- exports.repeatUntilDone = repeatUntilDone;
69
+ export const repeatUntilDone = (toRepeat, timeout = 5000) => __awaiter(void 0, void 0, void 0, function* () {
70
+ let result;
71
+ while (!result) {
72
+ result = yield toRepeat();
73
+ if (!result) {
74
+ yield sleep(timeout);
75
+ }
76
+ }
77
+ return result;
78
+ });
150
79
  /**
151
80
  * Loads a transaction receipt using the rpc for the given chain id
152
81
  * @param chainId The chain id where the transaction should be loaded from
153
82
  * @param txHash The hash of the transaction
154
83
  * @returns TransactionReceipt
155
84
  */
156
- var loadTransactionReceipt = function (chainId, txHash) { return __awaiter(void 0, void 0, void 0, function () {
157
- var rpc, tx;
158
- return __generator(this, function (_a) {
159
- switch (_a.label) {
160
- case 0: return [4 /*yield*/, (0, connectors_1.getRpcProvider)(chainId)];
161
- case 1:
162
- rpc = _a.sent();
163
- return [4 /*yield*/, rpc.getTransaction(txHash)];
164
- case 2:
165
- tx = _a.sent();
166
- return [2 /*return*/, tx.wait()];
167
- }
168
- });
169
- }); };
170
- exports.loadTransactionReceipt = loadTransactionReceipt;
171
- var isZeroAddress = function (address) {
172
- if (address === ethers_1.constants.AddressZero ||
85
+ export const loadTransactionReceipt = (chainId, txHash) => __awaiter(void 0, void 0, void 0, function* () {
86
+ const rpc = yield getRpcProvider(chainId);
87
+ const tx = yield rpc.getTransaction(txHash);
88
+ return tx.wait();
89
+ });
90
+ export const isZeroAddress = (address) => {
91
+ if (address === constants.AddressZero ||
173
92
  address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
174
93
  return true;
175
94
  }
176
95
  return false;
177
96
  };
178
- exports.isZeroAddress = isZeroAddress;
179
- var isNativeTokenAddress = function (address) {
180
- if (address === ethers_1.constants.AddressZero ||
97
+ export const isNativeTokenAddress = (address) => {
98
+ if (address === constants.AddressZero ||
181
99
  address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' ||
182
100
  // CELO native token
183
101
  address === '0x471ece3750da237f93b8e339c536989b8978a438') {
@@ -185,4 +103,3 @@ var isNativeTokenAddress = function (address) {
185
103
  }
186
104
  return false;
187
105
  };
188
- exports.isNativeTokenAddress = isNativeTokenAddress;
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@lifi/sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.5",
4
4
  "description": "LI.FI Any-to-Any Cross-Chain-Swap SDK",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/index.js",
6
7
  "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "require": "./dist/cjs/index.js",
10
+ "import": "./dist/index.js"
11
+ },
7
12
  "scripts": {
8
13
  "watch": "tsc -w -p ./tsconfig.json",
9
- "build": "yarn clean && tsc --project ./tsconfig.json",
14
+ "build": "yarn clean && tsc --project ./tsconfig.json && tsc --project ./tsconfig.cjs.json",
10
15
  "clean": "node tools/cleanup",
11
16
  "package": "npm run build && npm pack",
12
17
  "test": "jest --no-cache --runInBand --forceExit",
@@ -41,6 +46,24 @@
41
46
  },
42
47
  "author": "Max Klenk <max@li.finance>",
43
48
  "license": "Apache-2.0",
49
+ "keywords": [
50
+ "sdk",
51
+ "ethereum",
52
+ "dapp",
53
+ "bridge",
54
+ "swap",
55
+ "web3",
56
+ "lifi",
57
+ "ethers",
58
+ "cross-chain",
59
+ "defi",
60
+ "web3-react",
61
+ "cross-chain-applications",
62
+ "cross-chain-bridge",
63
+ "bridge-aggregation",
64
+ "multi-chain",
65
+ "metamask"
66
+ ],
44
67
  "homepage": "https://github.com/lifinance/sdk",
45
68
  "repository": {
46
69
  "type": "git",
@@ -52,9 +75,9 @@
52
75
  "dependencies": {
53
76
  "@ethersproject/abi": "^5.6.4",
54
77
  "@ethersproject/contracts": "^5.6.2",
55
- "@lifi/types": "^1.3.0",
78
+ "@lifi/types": "^1.5.0",
56
79
  "axios": "^0.27.2",
57
- "bignumber.js": "^9.0.1",
80
+ "bignumber.js": "^9.1.0",
58
81
  "eth-rpc-errors": "^4.0.3",
59
82
  "ethers": "^5.6.9"
60
83
  },
@@ -62,13 +85,13 @@
62
85
  "@commitlint/cli": "^17.0.3",
63
86
  "@commitlint/config-conventional": "^17.0.3",
64
87
  "@types/bip39": "^3.0.0",
65
- "@types/chai": "^4.3.1",
88
+ "@types/chai": "^4.3.3",
66
89
  "@types/hdkey": "^2.0.0",
67
- "@types/jest": "^28.1.4",
90
+ "@types/jest": "^28.1.7",
68
91
  "@types/websocket": "^1.0.4",
69
- "@typescript-eslint/eslint-plugin": "^5.32.0",
70
- "@typescript-eslint/parser": "^5.32.0",
71
- "eslint": "^8.19.0",
92
+ "@typescript-eslint/eslint-plugin": "^5.33.1",
93
+ "@typescript-eslint/parser": "^5.33.1",
94
+ "eslint": "^8.22.0",
72
95
  "eslint-config-prettier": "^8.3.0",
73
96
  "eslint-plugin-prettier": "^4.2.1",
74
97
  "husky": "^8.0.1",
@@ -78,7 +101,7 @@
78
101
  "pinst": "^3.0.0",
79
102
  "prettier": "^2.7.1",
80
103
  "standard-version": "^9.5.0",
81
- "ts-jest": "^28.0.5",
104
+ "ts-jest": "^28.0.8",
82
105
  "ts-loader": "^9.3.1",
83
106
  "typescript": "^4.7.4",
84
107
  "webpack": "^5.73.0",