@lifi/sdk 1.1.1 → 1.1.4

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.
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,114 +7,59 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
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;
10
+ import BigNumber from 'bignumber.js';
11
+ import ApiService from '../services/ApiService';
12
+ import { ServerError } from '../utils/errors';
13
+ import { repeatUntilDone } from '../utils/utils';
14
+ const TRANSACTION_HASH_OBSERVERS = {};
15
+ export function waitForReceivingTransaction(txHash, statusManager, processType, step) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const getStatus = () => new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
18
+ let statusResponse;
19
+ try {
20
+ statusResponse = yield ApiService.getStatus({
21
+ bridge: step.tool,
22
+ fromChain: step.action.fromChainId,
23
+ toChain: step.action.toChainId,
24
+ txHash,
25
+ });
32
26
  }
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.updatedStepMeetsSlippageConditions = exports.getSubstatusMessage = exports.getProcessMessage = exports.waitForReceivingTransaction = void 0;
43
- var bignumber_js_1 = __importDefault(require("bignumber.js"));
44
- var ApiService_1 = __importDefault(require("../services/ApiService"));
45
- var errors_1 = require("../utils/errors");
46
- var utils_1 = require("../utils/utils");
47
- var TRANSACTION_HASH_OBSERVERS = {};
48
- function waitForReceivingTransaction(txHash, statusManager, processType, step) {
49
- return __awaiter(this, void 0, void 0, function () {
50
- var getStatus, status;
51
- var _this = this;
52
- return __generator(this, function (_a) {
53
- switch (_a.label) {
54
- case 0:
55
- getStatus = function () {
56
- return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
57
- var statusResponse, e_1;
58
- return __generator(this, function (_a) {
59
- switch (_a.label) {
60
- case 0:
61
- _a.trys.push([0, 2, , 3]);
62
- return [4 /*yield*/, ApiService_1.default.getStatus({
63
- bridge: step.tool,
64
- fromChain: step.action.fromChainId,
65
- toChain: step.action.toChainId,
66
- txHash: txHash,
67
- })];
68
- case 1:
69
- statusResponse = _a.sent();
70
- return [3 /*break*/, 3];
71
- case 2:
72
- e_1 = _a.sent();
73
- console.debug('Fetching status from backend failed.', e_1);
74
- return [2 /*return*/, resolve(undefined)];
75
- case 3:
76
- switch (statusResponse.status) {
77
- case 'DONE':
78
- return [2 /*return*/, resolve(statusResponse)];
79
- case 'PENDING':
80
- statusManager === null || statusManager === void 0 ? void 0 : statusManager.updateProcess(step, processType, 'PENDING', {
81
- substatus: statusResponse.substatus,
82
- substatusMessage: statusResponse.substatusMessage ||
83
- getSubstatusMessage(statusResponse.status, statusResponse.substatus),
84
- });
85
- return [2 /*return*/, resolve(undefined)];
86
- case 'NOT_FOUND':
87
- return [2 /*return*/, resolve(undefined)];
88
- case 'FAILED':
89
- default:
90
- return [2 /*return*/, reject()];
91
- }
92
- return [2 /*return*/];
93
- }
94
- });
95
- }); });
96
- };
97
- if (!(txHash in TRANSACTION_HASH_OBSERVERS)) return [3 /*break*/, 2];
98
- return [4 /*yield*/, TRANSACTION_HASH_OBSERVERS[txHash]];
99
- case 1:
100
- status = _a.sent();
101
- return [3 /*break*/, 4];
102
- case 2:
103
- TRANSACTION_HASH_OBSERVERS[txHash] = (0, utils_1.repeatUntilDone)(getStatus, 5000);
104
- return [4 /*yield*/, TRANSACTION_HASH_OBSERVERS[txHash]];
105
- case 3:
106
- status = _a.sent();
107
- _a.label = 4;
108
- case 4:
109
- if (!status.receiving) {
110
- throw new errors_1.ServerError("Status doesn't contain receiving information.");
111
- }
112
- return [2 /*return*/, status];
27
+ catch (e) {
28
+ console.debug('Fetching status from backend failed.', e);
29
+ return resolve(undefined);
30
+ }
31
+ switch (statusResponse.status) {
32
+ case 'DONE':
33
+ return resolve(statusResponse);
34
+ case 'PENDING':
35
+ statusManager === null || statusManager === void 0 ? void 0 : statusManager.updateProcess(step, processType, 'PENDING', {
36
+ substatus: statusResponse.substatus,
37
+ substatusMessage: statusResponse.substatusMessage ||
38
+ getSubstatusMessage(statusResponse.status, statusResponse.substatus),
39
+ });
40
+ return resolve(undefined);
41
+ case 'NOT_FOUND':
42
+ return resolve(undefined);
43
+ case 'FAILED':
44
+ default:
45
+ return reject();
113
46
  }
114
- });
47
+ }));
48
+ let status;
49
+ if (txHash in TRANSACTION_HASH_OBSERVERS) {
50
+ status = yield TRANSACTION_HASH_OBSERVERS[txHash];
51
+ }
52
+ else {
53
+ TRANSACTION_HASH_OBSERVERS[txHash] = repeatUntilDone(getStatus, 5000);
54
+ status = yield TRANSACTION_HASH_OBSERVERS[txHash];
55
+ }
56
+ if (!status.receiving) {
57
+ throw new ServerError("Status doesn't contain receiving information.");
58
+ }
59
+ return status;
115
60
  });
116
61
  }
117
- exports.waitForReceivingTransaction = waitForReceivingTransaction;
118
- var processMessages = {
62
+ const processMessages = {
119
63
  TOKEN_ALLOWANCE: {
120
64
  STARTED: 'Setting token allowance.',
121
65
  PENDING: 'Waiting for token allowance.',
@@ -143,7 +87,7 @@ var processMessages = {
143
87
  },
144
88
  TRANSACTION: {},
145
89
  };
146
- var substatusMessages = {
90
+ const substatusMessages = {
147
91
  PENDING: {
148
92
  BRIDGE_NOT_AVAILABLE: 'Bridge communication is temporarily unavailable.',
149
93
  CHAIN_NOT_AVAILABLE: 'RPC communication is temporarily unavailable.',
@@ -161,26 +105,23 @@ var substatusMessages = {
161
105
  INVALID: {},
162
106
  NOT_FOUND: {},
163
107
  };
164
- function getProcessMessage(type, status) {
165
- var processMessage = processMessages[type][status];
108
+ export function getProcessMessage(type, status) {
109
+ const processMessage = processMessages[type][status];
166
110
  return processMessage;
167
111
  }
168
- exports.getProcessMessage = getProcessMessage;
169
- function getSubstatusMessage(status, substatus) {
112
+ export function getSubstatusMessage(status, substatus) {
170
113
  if (!substatus) {
171
114
  return;
172
115
  }
173
- var message = substatusMessages[status][substatus];
116
+ const message = substatusMessages[status][substatus];
174
117
  return message;
175
118
  }
176
- exports.getSubstatusMessage = getSubstatusMessage;
177
- function updatedStepMeetsSlippageConditions(oldStep, newStep) {
178
- var setSlippage = new bignumber_js_1.default(oldStep.action.slippage);
179
- var oldEstimatedToAmount = new bignumber_js_1.default(oldStep.estimate.toAmountMin);
180
- var newEstimatedToAmount = new bignumber_js_1.default(newStep.estimate.toAmountMin);
181
- var amountDifference = oldEstimatedToAmount.minus(newEstimatedToAmount);
182
- var actualSlippage = amountDifference.dividedBy(oldEstimatedToAmount);
119
+ export function updatedStepMeetsSlippageConditions(oldStep, newStep) {
120
+ const setSlippage = new BigNumber(oldStep.action.slippage);
121
+ const oldEstimatedToAmount = new BigNumber(oldStep.estimate.toAmountMin);
122
+ const newEstimatedToAmount = new BigNumber(newStep.estimate.toAmountMin);
123
+ const amountDifference = oldEstimatedToAmount.minus(newEstimatedToAmount);
124
+ const actualSlippage = amountDifference.dividedBy(oldEstimatedToAmount);
183
125
  return (newEstimatedToAmount.gte(oldEstimatedToAmount) &&
184
126
  actualSlippage.lte(setSlippage));
185
127
  }
186
- exports.updatedStepMeetsSlippageConditions = updatedStepMeetsSlippageConditions;
package/dist/helpers.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,78 +7,41 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
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 };
10
+ const ethereumRequest = (method, params) => __awaiter(void 0, void 0, void 0, function* () {
11
+ // If ethereum.request() exists, the provider is probably EIP-1193 compliant.
12
+ if (!ethereum || !ethereum.request) {
13
+ throw new Error('Provider not available.');
36
14
  }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.isSameToken = exports.getRandomNumber = exports.getEthereumPublicKeyHook = exports.getEthereumDecryptionHook = void 0;
40
- var ethereumRequest = function (method, params) { return __awaiter(void 0, void 0, void 0, function () {
41
- return __generator(this, function (_a) {
42
- // If ethereum.request() exists, the provider is probably EIP-1193 compliant.
43
- if (!ethereum || !ethereum.request) {
44
- throw new Error('Provider not available.');
45
- }
46
- return [2 /*return*/, ethereum.request({
47
- method: method,
48
- params: params,
49
- })];
15
+ return ethereum.request({
16
+ method,
17
+ params,
50
18
  });
51
- }); };
19
+ });
52
20
  /**
53
21
  * Predefined hook that decrypts calldata using EIP-1193 compliant wallet functions.
54
22
  * @param {string} walletAddress - The wallet address of the user that should decrypt the calldata.
55
23
  * @return {(encryptedData: string) => Promise<any>} A function that decrypts data using EIP-1193 compliant wallet functions.
56
24
  */
57
- var getEthereumDecryptionHook = function (walletAddress) {
58
- return function (encryptedData) {
25
+ export const getEthereumDecryptionHook = (walletAddress) => {
26
+ return (encryptedData) => {
59
27
  return ethereumRequest('eth_decrypt', [encryptedData, walletAddress]);
60
28
  };
61
29
  };
62
- exports.getEthereumDecryptionHook = getEthereumDecryptionHook;
63
30
  /**
64
31
  * Predefined hook that get the public encryption key of a user using EIP-1193 compliant wallet functions.
65
32
  * @param {string} walletAddress - The wallet address of the user.
66
33
  * @return {(walletAddress: string) => () => Promise<any>} A function that return the public encryption key using EIP-1193 compliant wallet functions.
67
34
  */
68
- var getEthereumPublicKeyHook = function (walletAddress) {
69
- return function () {
35
+ export const getEthereumPublicKeyHook = (walletAddress) => {
36
+ return () => {
70
37
  return ethereumRequest('eth_getEncryptionPublicKey', [walletAddress]);
71
38
  };
72
39
  };
73
- exports.getEthereumPublicKeyHook = getEthereumPublicKeyHook;
74
40
  /**
75
41
  * Returns a random number between min (inclusive) and max (inclusive)
76
42
  */
77
- var getRandomNumber = function (min, max) {
43
+ export const getRandomNumber = (min, max) => {
78
44
  return Math.floor(Math.random() * (max - min + 1) + min);
79
45
  };
80
- exports.getRandomNumber = getRandomNumber;
81
- var isSameToken = function (tokenA, tokenB) {
82
- return tokenA.chainId === tokenB.chainId &&
83
- tokenA.address.toLowerCase() === tokenB.address.toLowerCase();
84
- };
85
- exports.isSameToken = isSameToken;
46
+ export const isSameToken = (tokenA, tokenB) => tokenA.chainId === tokenB.chainId &&
47
+ tokenA.address.toLowerCase() === tokenB.address.toLowerCase();
package/dist/index.js CHANGED
@@ -1,27 +1,8 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
1
  // expose types and helpers
21
- var Lifi_1 = __importDefault(require("./Lifi"));
22
- __exportStar(require("./execution"), exports);
23
- __exportStar(require("./helpers"), exports);
24
- __exportStar(require("./types"), exports);
25
- __exportStar(require("./utils/errors"), exports);
2
+ import LIFI from './Lifi';
3
+ export * from './execution';
4
+ export * from './helpers';
5
+ export * from './types';
6
+ export * from './utils/errors';
26
7
  // expose sdk
27
- exports.default = Lifi_1.default;
8
+ export default LIFI;