@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.
- package/CHANGELOG.md +11 -0
- package/dist/Lifi.js +179 -285
- package/dist/allowance/index.js +56 -148
- package/dist/allowance/utils.js +51 -116
- package/dist/balances/index.js +29 -92
- package/dist/balances/utils.js +108 -218
- package/dist/cjs/Lifi.d.ts +200 -0
- package/dist/cjs/Lifi.js +376 -0
- package/dist/cjs/allowance/index.d.ts +22 -0
- package/dist/cjs/allowance/index.js +78 -0
- package/dist/cjs/allowance/utils.d.ts +14 -0
- package/dist/cjs/allowance/utils.js +82 -0
- package/dist/cjs/balances/index.d.ts +11 -0
- package/dist/cjs/balances/index.js +46 -0
- package/dist/cjs/balances/utils.d.ts +5 -0
- package/dist/cjs/balances/utils.js +150 -0
- package/dist/cjs/connectors.d.ts +6 -0
- package/dist/cjs/connectors.js +77 -0
- package/dist/cjs/execution/StatusManager.d.ts +65 -0
- package/dist/cjs/execution/StatusManager.js +167 -0
- package/dist/cjs/execution/StepExecutor.d.ts +15 -0
- package/dist/cjs/execution/StepExecutor.js +74 -0
- package/dist/cjs/execution/allowance.execute.d.ts +4 -0
- package/dist/cjs/execution/allowance.execute.js +97 -0
- package/dist/cjs/execution/balanceCheck.execute.d.ts +3 -0
- package/dist/cjs/execution/balanceCheck.execute.js +48 -0
- package/dist/cjs/execution/bridges/bridge.execute.d.ts +7 -0
- package/dist/cjs/execution/bridges/bridge.execute.js +154 -0
- package/dist/cjs/execution/exchanges/swap.execute.d.ts +7 -0
- package/dist/cjs/execution/exchanges/swap.execute.js +164 -0
- package/dist/cjs/execution/index.d.ts +1 -0
- package/dist/cjs/execution/index.js +17 -0
- package/dist/cjs/execution/stepComparison.d.ts +14 -0
- package/dist/cjs/execution/stepComparison.js +46 -0
- package/dist/cjs/execution/switchChain.d.ts +16 -0
- package/dist/cjs/execution/switchChain.js +58 -0
- package/dist/cjs/execution/utils.d.ts +6 -0
- package/dist/cjs/execution/utils.js +137 -0
- package/dist/cjs/helpers.d.ts +18 -0
- package/dist/cjs/helpers.js +54 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/services/ApiService.d.ts +15 -0
- package/dist/cjs/services/ApiService.js +272 -0
- package/dist/cjs/services/ChainsService.d.ts +11 -0
- package/dist/cjs/services/ChainsService.js +54 -0
- package/dist/cjs/services/ConfigService.d.ts +23 -0
- package/dist/cjs/services/ConfigService.js +98 -0
- package/dist/cjs/typeguards.d.ts +4 -0
- package/dist/cjs/typeguards.js +53 -0
- package/dist/cjs/types/ERC20.d.ts +22 -0
- package/dist/cjs/types/ERC20.js +53 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/cjs/types/index.js +22 -0
- package/dist/cjs/types/internal.types.d.ts +85 -0
- package/dist/cjs/types/internal.types.js +2 -0
- package/dist/cjs/utils/errors.d.ts +75 -0
- package/dist/cjs/utils/errors.js +115 -0
- package/dist/cjs/utils/getProvider.d.ts +3 -0
- package/dist/cjs/utils/getProvider.js +11 -0
- package/dist/cjs/utils/multicall.d.ts +10 -0
- package/dist/cjs/utils/multicall.js +77 -0
- package/dist/cjs/utils/multicallAbi.json +313 -0
- package/dist/cjs/utils/parseError.d.ts +38 -0
- package/dist/cjs/utils/parseError.js +141 -0
- package/dist/cjs/utils/preRestart.d.ts +2 -0
- package/dist/cjs/utils/preRestart.js +31 -0
- package/dist/cjs/utils/utils.d.ts +26 -0
- package/dist/cjs/utils/utils.js +120 -0
- package/dist/connectors.js +50 -133
- package/dist/execution/StatusManager.js +34 -41
- package/dist/execution/StepExecutor.js +54 -123
- package/dist/execution/allowance.execute.js +76 -142
- package/dist/execution/balanceCheck.execute.js +29 -74
- package/dist/execution/bridges/bridge.execute.js +132 -221
- package/dist/execution/exchanges/swap.execute.js +142 -225
- package/dist/execution/index.js +1 -17
- package/dist/execution/stepComparison.js +22 -61
- package/dist/execution/switchChain.js +33 -81
- package/dist/execution/utils.js +60 -119
- package/dist/helpers.js +15 -53
- package/dist/index.js +6 -25
- package/dist/services/ApiService.js +248 -385
- package/dist/services/ChainsService.js +29 -89
- package/dist/services/ConfigService.js +47 -86
- package/dist/typeguards.js +13 -21
- package/dist/types/ERC20.js +1 -4
- package/dist/types/index.js +4 -22
- package/dist/types/internal.types.js +1 -2
- package/dist/utils/errors.js +47 -93
- package/dist/utils/getProvider.js +3 -7
- package/dist/utils/multicall.js +61 -117
- package/dist/utils/parseError.js +73 -141
- package/dist/utils/preRestart.js +14 -21
- package/dist/utils/utils.js +47 -130
- package/package.json +34 -11
|
@@ -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,149 +7,84 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
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.checkAllowance = void 0;
|
|
43
|
-
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
44
|
-
var ethers_1 = require("ethers");
|
|
45
|
-
var utils_1 = require("../allowance/utils");
|
|
46
|
-
var getProvider_1 = require("../utils/getProvider");
|
|
47
|
-
var parseError_1 = require("../utils/parseError");
|
|
48
|
-
var checkAllowance = function (signer, step, chain, token, amount, spenderAddress, statusManager, infiniteApproval, allowUserInteraction
|
|
10
|
+
import BigNumber from 'bignumber.js';
|
|
11
|
+
import { constants } from 'ethers';
|
|
12
|
+
import { getApproved, setApproval } from '../allowance/utils';
|
|
13
|
+
import { getProvider } from '../utils/getProvider';
|
|
14
|
+
import { parseError } from '../utils/parseError';
|
|
15
|
+
export const checkAllowance = (signer, step, chain, token, amount, spenderAddress, statusManager, infiniteApproval = false, allowUserInteraction = false
|
|
49
16
|
// eslint-disable-next-line max-params
|
|
50
|
-
) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (!new bignumber_js_1.default(amount).gt(approved)) return [3 /*break*/, 8];
|
|
77
|
-
if (!allowUserInteraction) {
|
|
78
|
-
return [2 /*return*/];
|
|
79
|
-
}
|
|
80
|
-
approvalAmount = infiniteApproval
|
|
81
|
-
? ethers_1.constants.MaxUint256.toString()
|
|
82
|
-
: amount;
|
|
83
|
-
return [4 /*yield*/, (0, utils_1.setApproval)(signer, token.address, spenderAddress, approvalAmount)
|
|
84
|
-
// update currentExecution
|
|
85
|
-
];
|
|
86
|
-
case 6:
|
|
87
|
-
approveTx = _a.sent();
|
|
88
|
-
// update currentExecution
|
|
89
|
-
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
|
|
90
|
-
txHash: approveTx.hash,
|
|
91
|
-
txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + approveTx.hash,
|
|
92
|
-
});
|
|
93
|
-
// wait for transcation
|
|
94
|
-
return [4 /*yield*/, approveTx.wait()];
|
|
95
|
-
case 7:
|
|
96
|
-
// wait for transcation
|
|
97
|
-
_a.sent();
|
|
98
|
-
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
99
|
-
return [3 /*break*/, 9];
|
|
100
|
-
case 8:
|
|
101
|
-
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
102
|
-
_a.label = 9;
|
|
103
|
-
case 9: return [3 /*break*/, 15];
|
|
104
|
-
case 10:
|
|
105
|
-
e_1 = _a.sent();
|
|
106
|
-
if (!(e_1.code === 'TRANSACTION_REPLACED' && e_1.replacement)) return [3 /*break*/, 12];
|
|
107
|
-
return [4 /*yield*/, transactionReplaced(e_1.replacement, allowanceProcess, step, chain, statusManager)];
|
|
108
|
-
case 11:
|
|
109
|
-
_a.sent();
|
|
110
|
-
return [3 /*break*/, 14];
|
|
111
|
-
case 12: return [4 /*yield*/, (0, parseError_1.parseError)(e_1, step, allowanceProcess)];
|
|
112
|
-
case 13:
|
|
113
|
-
error = _a.sent();
|
|
114
|
-
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'FAILED', {
|
|
115
|
-
error: {
|
|
116
|
-
message: error.message,
|
|
117
|
-
htmlMessage: error.htmlMessage,
|
|
118
|
-
code: error.code,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
statusManager.updateExecution(step, 'FAILED');
|
|
122
|
-
throw error;
|
|
123
|
-
case 14: return [3 /*break*/, 15];
|
|
124
|
-
case 15: return [2 /*return*/];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
exports.checkAllowance = checkAllowance;
|
|
130
|
-
var transactionReplaced = function (replacementTx, allowanceProcess, step, chain, statusManager) { return __awaiter(void 0, void 0, void 0, function () {
|
|
131
|
-
var e_2;
|
|
132
|
-
return __generator(this, function (_a) {
|
|
133
|
-
switch (_a.label) {
|
|
134
|
-
case 0:
|
|
135
|
-
_a.trys.push([0, 2, , 5]);
|
|
17
|
+
) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
// Ask user to set allowance
|
|
19
|
+
// -> set currentExecution
|
|
20
|
+
let allowanceProcess = statusManager.findOrCreateProcess('TOKEN_ALLOWANCE', step);
|
|
21
|
+
// -> check allowance
|
|
22
|
+
try {
|
|
23
|
+
if (allowanceProcess.txHash) {
|
|
24
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING');
|
|
25
|
+
yield getProvider(signer).waitForTransaction(allowanceProcess.txHash);
|
|
26
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
27
|
+
// TODO: Do we need this check?
|
|
28
|
+
}
|
|
29
|
+
else if (allowanceProcess.status === 'DONE') {
|
|
30
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const approved = yield getApproved(signer, token.address, spenderAddress);
|
|
34
|
+
if (new BigNumber(amount).gt(approved)) {
|
|
35
|
+
if (!allowUserInteraction) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const approvalAmount = infiniteApproval
|
|
39
|
+
? constants.MaxUint256.toString()
|
|
40
|
+
: amount;
|
|
41
|
+
const approveTx = yield setApproval(signer, token.address, spenderAddress, approvalAmount);
|
|
42
|
+
// update currentExecution
|
|
136
43
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
|
|
137
|
-
txHash:
|
|
138
|
-
txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' +
|
|
44
|
+
txHash: approveTx.hash,
|
|
45
|
+
txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + approveTx.hash,
|
|
139
46
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
47
|
+
// wait for transcation
|
|
48
|
+
yield approveTx.wait();
|
|
49
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
143
52
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
144
|
-
|
|
145
|
-
case 2:
|
|
146
|
-
e_2 = _a.sent();
|
|
147
|
-
if (!(e_2.code === 'TRANSACTION_REPLACED' && e_2.replacement)) return [3 /*break*/, 4];
|
|
148
|
-
return [4 /*yield*/, transactionReplaced(e_2.replacement, allowanceProcess, step, chain, statusManager)];
|
|
149
|
-
case 3:
|
|
150
|
-
_a.sent();
|
|
151
|
-
_a.label = 4;
|
|
152
|
-
case 4: throw e_2;
|
|
153
|
-
case 5: return [2 /*return*/];
|
|
53
|
+
}
|
|
154
54
|
}
|
|
155
|
-
}
|
|
156
|
-
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
// -> set status
|
|
58
|
+
if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
|
|
59
|
+
yield transactionReplaced(e.replacement, allowanceProcess, step, chain, statusManager);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const error = yield parseError(e, step, allowanceProcess);
|
|
63
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'FAILED', {
|
|
64
|
+
error: {
|
|
65
|
+
message: error.message,
|
|
66
|
+
htmlMessage: error.htmlMessage,
|
|
67
|
+
code: error.code,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
statusManager.updateExecution(step, 'FAILED');
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const transactionReplaced = (replacementTx, allowanceProcess, step, chain, statusManager) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
try {
|
|
77
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
|
|
78
|
+
txHash: replacementTx.hash,
|
|
79
|
+
txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + replacementTx.hash,
|
|
80
|
+
});
|
|
81
|
+
yield replacementTx.wait();
|
|
82
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
|
|
86
|
+
yield transactionReplaced(e.replacement, allowanceProcess, step, chain, statusManager);
|
|
87
|
+
}
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
@@ -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,79 +7,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 balances from '../balances';
|
|
12
|
+
import { ValidationError } from '../utils/errors';
|
|
13
|
+
export const balanceCheck = (signer, step) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const tokenAmount = yield balances.getTokenBalance(yield signer.getAddress(), step.action.fromToken);
|
|
15
|
+
if (tokenAmount) {
|
|
16
|
+
const currentBalance = new BigNumber(tokenAmount.amount).shiftedBy(tokenAmount.decimals);
|
|
17
|
+
const neededBalance = new BigNumber(step.action.fromAmount);
|
|
18
|
+
if (currentBalance.lt(neededBalance)) {
|
|
19
|
+
if (neededBalance.multipliedBy(1 - step.action.slippage).lte(currentBalance)) {
|
|
20
|
+
// adjust amount in slippage limits
|
|
21
|
+
step.action.fromAmount = currentBalance.toFixed(0);
|
|
32
22
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var balanceCheck = function (signer, step) { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
-
var tokenAmount, _a, _b, currentBalance, neededBalance, neeeded, current, errorMessage;
|
|
48
|
-
return __generator(this, function (_c) {
|
|
49
|
-
switch (_c.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
_b = (_a = balances_1.default).getTokenBalance;
|
|
52
|
-
return [4 /*yield*/, signer.getAddress()];
|
|
53
|
-
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent(), step.action.fromToken])];
|
|
54
|
-
case 2:
|
|
55
|
-
tokenAmount = _c.sent();
|
|
56
|
-
if (tokenAmount) {
|
|
57
|
-
currentBalance = new bignumber_js_1.default(tokenAmount.amount).shiftedBy(tokenAmount.decimals);
|
|
58
|
-
neededBalance = new bignumber_js_1.default(step.action.fromAmount);
|
|
59
|
-
if (currentBalance.lt(neededBalance)) {
|
|
60
|
-
if (neededBalance.multipliedBy(1 - step.action.slippage).lte(currentBalance)) {
|
|
61
|
-
// adjust amount in slippage limits
|
|
62
|
-
step.action.fromAmount = currentBalance.toFixed(0);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
neeeded = neededBalance.shiftedBy(-tokenAmount.decimals).toFixed();
|
|
66
|
-
current = currentBalance
|
|
67
|
-
.shiftedBy(-tokenAmount.decimals)
|
|
68
|
-
.toFixed();
|
|
69
|
-
errorMessage = "Your ".concat(tokenAmount.symbol, " balance is too low, ") +
|
|
70
|
-
"you try to transfer ".concat(neeeded, " ").concat(tokenAmount.symbol, ", ") +
|
|
71
|
-
"but your wallet only holds ".concat(current, " ").concat(tokenAmount.symbol, ". ") +
|
|
72
|
-
"No funds have been sent. ";
|
|
73
|
-
if (!currentBalance.isZero()) {
|
|
74
|
-
errorMessage +=
|
|
75
|
-
"If the problem consists, please delete this transfer and " +
|
|
76
|
-
"start a new one with a maximum of ".concat(current, " ").concat(tokenAmount.symbol, ".");
|
|
77
|
-
}
|
|
78
|
-
throw new errors_1.ValidationError('The balance is too low.', errorMessage);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
23
|
+
else {
|
|
24
|
+
const neeeded = neededBalance.shiftedBy(-tokenAmount.decimals).toFixed();
|
|
25
|
+
const current = currentBalance
|
|
26
|
+
.shiftedBy(-tokenAmount.decimals)
|
|
27
|
+
.toFixed();
|
|
28
|
+
let errorMessage = `Your ${tokenAmount.symbol} balance is too low, ` +
|
|
29
|
+
`you try to transfer ${neeeded} ${tokenAmount.symbol}, ` +
|
|
30
|
+
`but your wallet only holds ${current} ${tokenAmount.symbol}. ` +
|
|
31
|
+
`No funds have been sent. `;
|
|
32
|
+
if (!currentBalance.isZero()) {
|
|
33
|
+
errorMessage +=
|
|
34
|
+
`If the problem consists, please delete this transfer and ` +
|
|
35
|
+
`start a new one with a maximum of ${current} ${tokenAmount.symbol}.`;
|
|
81
36
|
}
|
|
82
|
-
|
|
37
|
+
throw new ValidationError('The balance is too low.', errorMessage);
|
|
38
|
+
}
|
|
83
39
|
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
exports.balanceCheck = balanceCheck;
|
|
40
|
+
}
|
|
41
|
+
});
|