@airgap/ethereum 0.13.45-beta.3 → 0.13.45-beta.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 (82) hide show
  1. package/package.json +5 -5
  2. package/v0/index.js +10 -10
  3. package/v0/index.js.map +1 -1
  4. package/v0/protocol/BaseEthereumProtocol.d.ts +1 -0
  5. package/v0/protocol/BaseEthereumProtocol.js +872 -460
  6. package/v0/protocol/BaseEthereumProtocol.js.map +1 -1
  7. package/v0/protocol/EthereumAddress.d.ts +1 -0
  8. package/v0/protocol/EthereumAddress.js +17 -26
  9. package/v0/protocol/EthereumAddress.js.map +1 -1
  10. package/v0/protocol/EthereumClassicProtocol.js +23 -6
  11. package/v0/protocol/EthereumClassicProtocol.js.map +1 -1
  12. package/v0/protocol/EthereumCryptoClient.js +125 -66
  13. package/v0/protocol/EthereumCryptoClient.js.map +1 -1
  14. package/v0/protocol/EthereumProtocol.js +28 -9
  15. package/v0/protocol/EthereumProtocol.js.map +1 -1
  16. package/v0/protocol/EthereumProtocolOptions.d.ts +1 -1
  17. package/v0/protocol/EthereumProtocolOptions.js +117 -36
  18. package/v0/protocol/EthereumProtocolOptions.js.map +1 -1
  19. package/v0/protocol/EthereumRopstenProtocol.js +23 -6
  20. package/v0/protocol/EthereumRopstenProtocol.js.map +1 -1
  21. package/v0/protocol/clients/info-clients/EtherscanInfoClient.js +186 -86
  22. package/v0/protocol/clients/info-clients/EtherscanInfoClient.js.map +1 -1
  23. package/v0/protocol/clients/info-clients/InfoClient.js +4 -3
  24. package/v0/protocol/clients/info-clients/InfoClient.js.map +1 -1
  25. package/v0/protocol/clients/node-clients/AirGapNodeClient.js +298 -126
  26. package/v0/protocol/clients/node-clients/AirGapNodeClient.js.map +1 -1
  27. package/v0/protocol/clients/node-clients/NodeClient.js +4 -3
  28. package/v0/protocol/clients/node-clients/NodeClient.js.map +1 -1
  29. package/v0/protocol/erc20/ERC20.js +4 -4
  30. package/v0/protocol/erc20/ERC20.js.map +1 -1
  31. package/v0/protocol/erc20/GenericERC20.js +300 -161
  32. package/v0/protocol/erc20/GenericERC20.js.map +1 -1
  33. package/v0/protocol/utils/utils.js +55 -52
  34. package/v0/protocol/utils/utils.js.map +1 -1
  35. package/v0/serializer/validators/transaction-validator.js +31 -23
  36. package/v0/serializer/validators/transaction-validator.js.map +1 -1
  37. package/v0/serializer/validators/validators.js +73 -25
  38. package/v0/serializer/validators/validators.js.map +1 -1
  39. package/v1/block-explorer/EtherscanBlockExplorer.js +61 -12
  40. package/v1/block-explorer/EtherscanBlockExplorer.js.map +1 -1
  41. package/v1/clients/crypto/EthereumCryptoClient.js +124 -69
  42. package/v1/clients/crypto/EthereumCryptoClient.js.map +1 -1
  43. package/v1/clients/info/EthereumInfoClient.d.ts +1 -1
  44. package/v1/clients/info/EthereumInfoClient.js +4 -3
  45. package/v1/clients/info/EthereumInfoClient.js.map +1 -1
  46. package/v1/clients/info/EtherscanInfoClient.js +162 -84
  47. package/v1/clients/info/EtherscanInfoClient.js.map +1 -1
  48. package/v1/clients/node/HttpEthereumNodeClient.d.ts +2 -2
  49. package/v1/clients/node/HttpEthereumNodeClient.js +375 -164
  50. package/v1/clients/node/HttpEthereumNodeClient.js.map +1 -1
  51. package/v1/data/EthereumAddress.js +20 -29
  52. package/v1/data/EthereumAddress.js.map +1 -1
  53. package/v1/index.js +14 -14
  54. package/v1/index.js.map +1 -1
  55. package/v1/module/EthereumModule.js +112 -43
  56. package/v1/module/EthereumModule.js.map +1 -1
  57. package/v1/module.js +3 -2
  58. package/v1/module.js.map +1 -1
  59. package/v1/protocol/EthereumBaseProtocol.js +788 -467
  60. package/v1/protocol/EthereumBaseProtocol.js.map +1 -1
  61. package/v1/protocol/EthereumProtocol.js +46 -15
  62. package/v1/protocol/EthereumProtocol.js.map +1 -1
  63. package/v1/protocol/erc20/ERC20Protocol.js +360 -213
  64. package/v1/protocol/erc20/ERC20Protocol.js.map +1 -1
  65. package/v1/protocol/erc20/ERC20Token.d.ts +1 -1
  66. package/v1/protocol/erc20/ERC20Token.js +113 -35
  67. package/v1/protocol/erc20/ERC20Token.js.map +1 -1
  68. package/v1/serializer/v3/schemas/converter/transaction-converter.js +42 -25
  69. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
  70. package/v1/serializer/v3/serializer-companion.js +148 -71
  71. package/v1/serializer/v3/serializer-companion.js.map +1 -1
  72. package/v1/serializer/v3/validators/transaction-validator.js +17 -14
  73. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
  74. package/v1/types/crypto.d.ts +1 -1
  75. package/v1/types/protocol.d.ts +1 -1
  76. package/v1/types/transaction.d.ts +1 -1
  77. package/v1/utils/EthereumUtils.js +60 -57
  78. package/v1/utils/EthereumUtils.js.map +1 -1
  79. package/v1/utils/key.js +19 -28
  80. package/v1/utils/key.js.map +1 -1
  81. package/v1/utils/protocol.js +21 -33
  82. package/v1/utils/protocol.js.map +1 -1
@@ -1,4 +1,19 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
18
  if (k2 === undefined) k2 = k;
4
19
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -15,182 +30,306 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
30
  }) : function(o, v) {
16
31
  o["default"] = v;
17
32
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
49
+ var __generator = (this && this.__generator) || function (thisArg, body) {
50
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
51
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
52
+ function verb(n) { return function (v) { return step([n, v]); }; }
53
+ function step(op) {
54
+ if (f) throw new TypeError("Generator is already executing.");
55
+ while (_) try {
56
+ 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;
57
+ if (y = 0, t) op = [op[0] & 2, t.value];
58
+ switch (op[0]) {
59
+ case 0: case 1: t = op; break;
60
+ case 4: _.label++; return { value: op[1], done: false };
61
+ case 5: _.label++; y = op[1]; op = [0]; continue;
62
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
63
+ default:
64
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
65
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
66
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
67
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
68
+ if (t[2]) _.ops.pop();
69
+ _.trys.pop(); continue;
70
+ }
71
+ op = body.call(thisArg, _);
72
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
73
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
74
+ }
75
+ };
35
76
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
77
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
78
  };
38
79
  Object.defineProperty(exports, "__esModule", { value: true });
39
80
  exports.GenericERC20 = void 0;
40
- const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
81
+ var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
41
82
  // @ts-ignore
42
- const ethUtil = __importStar(require("@airgap/coinlib-core/dependencies/src/ethereumjs-util-5.2.0"));
43
- const errors_1 = require("@airgap/coinlib-core/errors");
44
- const coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
45
- const ICoinSubProtocol_1 = require("@airgap/coinlib-core/protocols/ICoinSubProtocol");
46
- const BaseEthereumProtocol_1 = require("../BaseEthereumProtocol");
47
- const AirGapNodeClient_1 = require("../clients/node-clients/AirGapNodeClient");
48
- const utils_1 = require("../utils/utils");
49
- const EthereumTransaction = require('@airgap/coinlib-core/dependencies/src/ethereumjs-tx-1.3.7/index');
50
- class GenericERC20 extends BaseEthereumProtocol_1.BaseEthereumProtocol {
51
- constructor(options) {
52
- super(options);
53
- this.options = options;
54
- this.isSubProtocol = true;
55
- this.subProtocolType = ICoinSubProtocol_1.SubProtocolType.TOKEN;
56
- this.contractAddress = options.config.contractAddress;
57
- this.symbol = options.config.symbol;
58
- this.name = options.config.name;
59
- this.marketSymbol = options.config.marketSymbol;
60
- this.identifier = options.config.identifier;
61
- this.decimals = options.config.decimals;
62
- }
63
- async getIsSubProtocol() {
64
- return this.isSubProtocol;
65
- }
66
- async getSubProtocolType() {
67
- return this.subProtocolType;
68
- }
69
- async getContractAddress() {
70
- return this.contractAddress;
71
- }
72
- async getBalanceOfPublicKey(publicKey) {
73
- const address = await this.getAddressFromPublicKey(publicKey);
74
- return this.getBalanceOfAddresses([address.address]);
83
+ var ethUtil = __importStar(require("@airgap/coinlib-core/dependencies/src/ethereumjs-util-5.2.0"));
84
+ var errors_1 = require("@airgap/coinlib-core/errors");
85
+ var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
86
+ var ICoinSubProtocol_1 = require("@airgap/coinlib-core/protocols/ICoinSubProtocol");
87
+ var BaseEthereumProtocol_1 = require("../BaseEthereumProtocol");
88
+ var AirGapNodeClient_1 = require("../clients/node-clients/AirGapNodeClient");
89
+ var utils_1 = require("../utils/utils");
90
+ var EthereumTransaction = require('@airgap/coinlib-core/dependencies/src/ethereumjs-tx-1.3.7/index');
91
+ var GenericERC20 = /** @class */ (function (_super) {
92
+ __extends(GenericERC20, _super);
93
+ function GenericERC20(options) {
94
+ var _this = _super.call(this, options) || this;
95
+ _this.options = options;
96
+ _this.isSubProtocol = true;
97
+ _this.subProtocolType = ICoinSubProtocol_1.SubProtocolType.TOKEN;
98
+ _this.contractAddress = options.config.contractAddress;
99
+ _this.symbol = options.config.symbol;
100
+ _this.name = options.config.name;
101
+ _this.marketSymbol = options.config.marketSymbol;
102
+ _this.identifier = options.config.identifier;
103
+ _this.decimals = options.config.decimals;
104
+ return _this;
75
105
  }
76
- async getBalanceOfAddresses(addresses) {
77
- const balances = await Promise.all(addresses.map((address) => {
78
- return this.options.nodeClient.callBalanceOf(this.contractAddress, address);
79
- }));
80
- return balances.reduce((a, b) => a.plus(b)).toString(10);
81
- }
82
- signWithPrivateKey(privateKey, transaction) {
106
+ GenericERC20.prototype.getIsSubProtocol = function () {
107
+ return __awaiter(this, void 0, void 0, function () {
108
+ return __generator(this, function (_a) {
109
+ return [2 /*return*/, this.isSubProtocol];
110
+ });
111
+ });
112
+ };
113
+ GenericERC20.prototype.getSubProtocolType = function () {
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ return __generator(this, function (_a) {
116
+ return [2 /*return*/, this.subProtocolType];
117
+ });
118
+ });
119
+ };
120
+ GenericERC20.prototype.getContractAddress = function () {
121
+ return __awaiter(this, void 0, void 0, function () {
122
+ return __generator(this, function (_a) {
123
+ return [2 /*return*/, this.contractAddress];
124
+ });
125
+ });
126
+ };
127
+ GenericERC20.prototype.getBalanceOfPublicKey = function (publicKey) {
128
+ return __awaiter(this, void 0, void 0, function () {
129
+ var address;
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
133
+ case 1:
134
+ address = _a.sent();
135
+ return [2 /*return*/, this.getBalanceOfAddresses([address.address])];
136
+ }
137
+ });
138
+ });
139
+ };
140
+ GenericERC20.prototype.getBalanceOfAddresses = function (addresses) {
141
+ return __awaiter(this, void 0, void 0, function () {
142
+ var balances;
143
+ var _this = this;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0: return [4 /*yield*/, Promise.all(addresses.map(function (address) {
147
+ return _this.options.nodeClient.callBalanceOf(_this.contractAddress, address);
148
+ }))];
149
+ case 1:
150
+ balances = _a.sent();
151
+ return [2 /*return*/, balances.reduce(function (a, b) { return a.plus(b); }).toString(10)];
152
+ }
153
+ });
154
+ });
155
+ };
156
+ GenericERC20.prototype.signWithPrivateKey = function (privateKey, transaction) {
83
157
  if (!transaction.data || transaction.data === '0x') {
84
158
  transaction.data = new AirGapNodeClient_1.EthereumRPCDataTransfer(transaction.to, transaction.value).abiEncoded(); // backwards-compatible fix
85
159
  }
86
- return super.signWithPrivateKey(privateKey, transaction);
87
- }
88
- async estimateGas(source, recipient, hexValue) {
89
- const result = await this.options.nodeClient.estimateTransferGas(this.contractAddress, source, recipient, hexValue);
90
- return result;
91
- }
92
- async estimateMaxTransactionValueFromPublicKey(publicKey, recipients, fee) {
93
- return this.getBalanceOfPublicKey(publicKey);
94
- }
95
- async estimateFeeDefaultsFromPublicKey(publicKey, recipients, values, data) {
96
- if (recipients.length !== values.length) {
97
- return Promise.reject('recipients length does not match with values');
98
- }
99
- if (recipients.length !== 1) {
100
- return Promise.reject('you cannot have 0 recipients');
101
- }
102
- const address = (await this.getAddressFromPublicKey(publicKey)).address;
103
- const estimatedGas = await this.estimateGas(address, recipients[0], utils_1.EthereumUtils.toHex(values[0]));
104
- const gasPrise = await this.options.nodeClient.getGasPrice();
105
- const feeStepFactor = new bignumber_1.default(0.5);
106
- const estimatedFee = estimatedGas.times(gasPrise);
107
- const lowFee = estimatedFee.minus(estimatedFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
108
- const mediumFee = estimatedFee;
109
- const highFee = mediumFee.plus(mediumFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
110
- return {
111
- low: lowFee.shiftedBy(-this.feeDecimals).toFixed(),
112
- medium: mediumFee.shiftedBy(-this.feeDecimals).toFixed(),
113
- high: highFee.shiftedBy(-this.feeDecimals).toFixed()
114
- };
115
- }
116
- async prepareTransactionFromPublicKey(publicKey, recipients, values, fee) {
117
- const wrappedValues = values.map((value) => new bignumber_1.default(value));
118
- const wrappedFee = new bignumber_1.default(fee);
119
- if (recipients.length !== wrappedValues.length) {
120
- throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.ERC20, 'recipients length does not match with values');
121
- }
122
- if (recipients.length !== 1) {
123
- throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.ERC20, 'you cannot have 0 recipients');
124
- }
125
- const balance = new bignumber_1.default(await this.getBalanceOfPublicKey(publicKey));
126
- if (balance.isGreaterThanOrEqualTo(wrappedValues[0])) {
127
- const address = await this.getAddressFromPublicKey(publicKey).then((address) => address.address);
128
- const ethBalance = new bignumber_1.default(await super.getBalanceOfAddresses([address]));
129
- const estimatedGas = await this.estimateGas(address, recipients[0], utils_1.EthereumUtils.toHex(wrappedValues[0].toFixed()));
130
- if (ethBalance.isGreaterThanOrEqualTo(wrappedFee)) {
131
- const txCount = await this.options.nodeClient.fetchTransactionCount(address);
132
- const gasPrice = wrappedFee.isEqualTo(0)
133
- ? new bignumber_1.default(0)
134
- : wrappedFee.div(estimatedGas).integerValue(bignumber_1.default.ROUND_CEIL);
135
- const transaction = {
136
- nonce: utils_1.EthereumUtils.toHex(txCount),
137
- gasLimit: utils_1.EthereumUtils.toHex(estimatedGas.toFixed()),
138
- gasPrice: utils_1.EthereumUtils.toHex(gasPrice.toFixed()),
139
- to: this.contractAddress,
140
- value: utils_1.EthereumUtils.toHex(new bignumber_1.default(0).toFixed()),
141
- chainId: this.options.network.extras.chainID,
142
- data: new AirGapNodeClient_1.EthereumRPCDataTransfer(recipients[0], utils_1.EthereumUtils.toHex(wrappedValues[0].toFixed())).abiEncoded()
143
- };
144
- return transaction;
145
- }
146
- else {
147
- throw new errors_1.BalanceError(coinlib_error_1.Domain.ERC20, 'not enough ETH balance');
148
- }
149
- }
150
- else {
151
- throw new errors_1.BalanceError(coinlib_error_1.Domain.ERC20, 'not enough token balance');
152
- }
153
- }
154
- getTransactionsFromAddresses(addresses, limit, cursor) {
155
- return new Promise((overallResolve, overallReject) => {
156
- const promises = [];
157
- for (const address of addresses) {
158
- promises.push(this.options.infoClient.fetchContractTransactions(this, this.contractAddress, address, limit, cursor));
160
+ return _super.prototype.signWithPrivateKey.call(this, privateKey, transaction);
161
+ };
162
+ GenericERC20.prototype.estimateGas = function (source, recipient, hexValue) {
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ var result;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0: return [4 /*yield*/, this.options.nodeClient.estimateTransferGas(this.contractAddress, source, recipient, hexValue)];
168
+ case 1:
169
+ result = _a.sent();
170
+ return [2 /*return*/, result];
171
+ }
172
+ });
173
+ });
174
+ };
175
+ GenericERC20.prototype.estimateMaxTransactionValueFromPublicKey = function (publicKey, recipients, fee) {
176
+ return __awaiter(this, void 0, void 0, function () {
177
+ return __generator(this, function (_a) {
178
+ return [2 /*return*/, this.getBalanceOfPublicKey(publicKey)];
179
+ });
180
+ });
181
+ };
182
+ GenericERC20.prototype.estimateFeeDefaultsFromPublicKey = function (publicKey, recipients, values, data) {
183
+ return __awaiter(this, void 0, void 0, function () {
184
+ var address, estimatedGas, gasPrise, feeStepFactor, estimatedFee, lowFee, mediumFee, highFee;
185
+ return __generator(this, function (_a) {
186
+ switch (_a.label) {
187
+ case 0:
188
+ if (recipients.length !== values.length) {
189
+ return [2 /*return*/, Promise.reject('recipients length does not match with values')];
190
+ }
191
+ if (recipients.length !== 1) {
192
+ return [2 /*return*/, Promise.reject('you cannot have 0 recipients')];
193
+ }
194
+ return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
195
+ case 1:
196
+ address = (_a.sent()).address;
197
+ return [4 /*yield*/, this.estimateGas(address, recipients[0], utils_1.EthereumUtils.toHex(values[0]))];
198
+ case 2:
199
+ estimatedGas = _a.sent();
200
+ return [4 /*yield*/, this.options.nodeClient.getGasPrice()];
201
+ case 3:
202
+ gasPrise = _a.sent();
203
+ feeStepFactor = new bignumber_1.default(0.5);
204
+ estimatedFee = estimatedGas.times(gasPrise);
205
+ lowFee = estimatedFee.minus(estimatedFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
206
+ mediumFee = estimatedFee;
207
+ highFee = mediumFee.plus(mediumFee.times(feeStepFactor).integerValue(bignumber_1.default.ROUND_FLOOR));
208
+ return [2 /*return*/, {
209
+ low: lowFee.shiftedBy(-this.feeDecimals).toFixed(),
210
+ medium: mediumFee.shiftedBy(-this.feeDecimals).toFixed(),
211
+ high: highFee.shiftedBy(-this.feeDecimals).toFixed()
212
+ }];
213
+ }
214
+ });
215
+ });
216
+ };
217
+ GenericERC20.prototype.prepareTransactionFromPublicKey = function (publicKey, recipients, values, fee) {
218
+ return __awaiter(this, void 0, void 0, function () {
219
+ var wrappedValues, wrappedFee, balance, _a, address, ethBalance, _b, estimatedGas, txCount, gasPrice, transaction;
220
+ return __generator(this, function (_c) {
221
+ switch (_c.label) {
222
+ case 0:
223
+ wrappedValues = values.map(function (value) { return new bignumber_1.default(value); });
224
+ wrappedFee = new bignumber_1.default(fee);
225
+ if (recipients.length !== wrappedValues.length) {
226
+ throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.ERC20, 'recipients length does not match with values');
227
+ }
228
+ if (recipients.length !== 1) {
229
+ throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.ERC20, 'you cannot have 0 recipients');
230
+ }
231
+ _a = bignumber_1.default.bind;
232
+ return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
233
+ case 1:
234
+ balance = new (_a.apply(bignumber_1.default, [void 0, _c.sent()]))();
235
+ if (!balance.isGreaterThanOrEqualTo(wrappedValues[0])) return [3 /*break*/, 8];
236
+ return [4 /*yield*/, this.getAddressFromPublicKey(publicKey).then(function (address) { return address.address; })];
237
+ case 2:
238
+ address = _c.sent();
239
+ _b = bignumber_1.default.bind;
240
+ return [4 /*yield*/, _super.prototype.getBalanceOfAddresses.call(this, [address])];
241
+ case 3:
242
+ ethBalance = new (_b.apply(bignumber_1.default, [void 0, _c.sent()]))();
243
+ return [4 /*yield*/, this.estimateGas(address, recipients[0], utils_1.EthereumUtils.toHex(wrappedValues[0].toFixed()))];
244
+ case 4:
245
+ estimatedGas = _c.sent();
246
+ if (!ethBalance.isGreaterThanOrEqualTo(wrappedFee)) return [3 /*break*/, 6];
247
+ return [4 /*yield*/, this.options.nodeClient.fetchTransactionCount(address)];
248
+ case 5:
249
+ txCount = _c.sent();
250
+ gasPrice = wrappedFee.isEqualTo(0)
251
+ ? new bignumber_1.default(0)
252
+ : wrappedFee.div(estimatedGas).integerValue(bignumber_1.default.ROUND_CEIL);
253
+ transaction = {
254
+ nonce: utils_1.EthereumUtils.toHex(txCount),
255
+ gasLimit: utils_1.EthereumUtils.toHex(estimatedGas.toFixed()),
256
+ gasPrice: utils_1.EthereumUtils.toHex(gasPrice.toFixed()),
257
+ to: this.contractAddress,
258
+ value: utils_1.EthereumUtils.toHex(new bignumber_1.default(0).toFixed()),
259
+ chainId: this.options.network.extras.chainID,
260
+ data: new AirGapNodeClient_1.EthereumRPCDataTransfer(recipients[0], utils_1.EthereumUtils.toHex(wrappedValues[0].toFixed())).abiEncoded()
261
+ };
262
+ return [2 /*return*/, transaction];
263
+ case 6: throw new errors_1.BalanceError(coinlib_error_1.Domain.ERC20, 'not enough ETH balance');
264
+ case 7: return [3 /*break*/, 9];
265
+ case 8: throw new errors_1.BalanceError(coinlib_error_1.Domain.ERC20, 'not enough token balance');
266
+ case 9: return [2 /*return*/];
267
+ }
268
+ });
269
+ });
270
+ };
271
+ GenericERC20.prototype.getTransactionsFromAddresses = function (addresses, limit, cursor) {
272
+ var _this = this;
273
+ return new Promise(function (overallResolve, overallReject) {
274
+ var promises = [];
275
+ for (var _i = 0, addresses_1 = addresses; _i < addresses_1.length; _i++) {
276
+ var address = addresses_1[_i];
277
+ promises.push(_this.options.infoClient.fetchContractTransactions(_this, _this.contractAddress, address, limit, cursor));
159
278
  }
160
279
  Promise.all(promises)
161
- .then((values) => {
162
- const page = Math.max(...values.map((txResult) => txResult.cursor.page));
163
- overallResolve(values.reduce((a, b) => {
164
- return { transactions: a.transactions.concat(b.transactions), cursor: { page } };
280
+ .then(function (values) {
281
+ var page = Math.max.apply(Math, values.map(function (txResult) { return txResult.cursor.page; }));
282
+ overallResolve(values.reduce(function (a, b) {
283
+ return { transactions: a.transactions.concat(b.transactions), cursor: { page: page } };
165
284
  }));
166
285
  })
167
286
  .catch(overallReject);
168
287
  });
169
- }
170
- async getTransactionDetailsFromSigned(signedTx) {
171
- const ethTxs = await super.getTransactionDetailsFromSigned(signedTx);
172
- if (ethTxs.length !== 1) {
173
- throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.ERC20, 'More than one ETH transaction detected.');
174
- }
175
- const ethTx = ethTxs[0];
176
- const extractedTx = new EthereumTransaction(signedTx.transaction);
177
- const tokenTransferDetails = new AirGapNodeClient_1.EthereumRPCDataTransfer(`0x${extractedTx.data.toString('hex')}`);
178
- ethTx.to = [ethUtil.toChecksumAddress(tokenTransferDetails.recipient)];
179
- ethTx.amount = new bignumber_1.default(tokenTransferDetails.amount).toString(10);
180
- return [ethTx];
181
- }
182
- async getTransactionDetails(unsignedTx) {
183
- const unsignedEthereumTx = unsignedTx;
184
- const ethTxs = await super.getTransactionDetails(unsignedEthereumTx);
185
- if (ethTxs.length !== 1) {
186
- throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.ERC20, 'More than one ETH transaction detected.');
187
- }
188
- const ethTx = ethTxs[0];
189
- const tokenTransferDetails = new AirGapNodeClient_1.EthereumRPCDataTransfer(unsignedEthereumTx.transaction.data);
190
- ethTx.to = [ethUtil.toChecksumAddress(tokenTransferDetails.recipient)];
191
- ethTx.amount = new bignumber_1.default(tokenTransferDetails.amount).toString(10);
192
- return [ethTx];
193
- }
194
- }
288
+ };
289
+ GenericERC20.prototype.getTransactionDetailsFromSigned = function (signedTx) {
290
+ return __awaiter(this, void 0, void 0, function () {
291
+ var ethTxs, ethTx, extractedTx, tokenTransferDetails;
292
+ return __generator(this, function (_a) {
293
+ switch (_a.label) {
294
+ case 0: return [4 /*yield*/, _super.prototype.getTransactionDetailsFromSigned.call(this, signedTx)];
295
+ case 1:
296
+ ethTxs = _a.sent();
297
+ if (ethTxs.length !== 1) {
298
+ throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.ERC20, 'More than one ETH transaction detected.');
299
+ }
300
+ ethTx = ethTxs[0];
301
+ extractedTx = new EthereumTransaction(signedTx.transaction);
302
+ tokenTransferDetails = new AirGapNodeClient_1.EthereumRPCDataTransfer("0x".concat(extractedTx.data.toString('hex')));
303
+ ethTx.to = [ethUtil.toChecksumAddress(tokenTransferDetails.recipient)];
304
+ ethTx.amount = new bignumber_1.default(tokenTransferDetails.amount).toString(10);
305
+ return [2 /*return*/, [ethTx]];
306
+ }
307
+ });
308
+ });
309
+ };
310
+ GenericERC20.prototype.getTransactionDetails = function (unsignedTx) {
311
+ return __awaiter(this, void 0, void 0, function () {
312
+ var unsignedEthereumTx, ethTxs, ethTx, tokenTransferDetails;
313
+ return __generator(this, function (_a) {
314
+ switch (_a.label) {
315
+ case 0:
316
+ unsignedEthereumTx = unsignedTx;
317
+ return [4 /*yield*/, _super.prototype.getTransactionDetails.call(this, unsignedEthereumTx)];
318
+ case 1:
319
+ ethTxs = _a.sent();
320
+ if (ethTxs.length !== 1) {
321
+ throw new errors_1.ConditionViolationError(coinlib_error_1.Domain.ERC20, 'More than one ETH transaction detected.');
322
+ }
323
+ ethTx = ethTxs[0];
324
+ tokenTransferDetails = new AirGapNodeClient_1.EthereumRPCDataTransfer(unsignedEthereumTx.transaction.data);
325
+ ethTx.to = [ethUtil.toChecksumAddress(tokenTransferDetails.recipient)];
326
+ ethTx.amount = new bignumber_1.default(tokenTransferDetails.amount).toString(10);
327
+ return [2 /*return*/, [ethTx]];
328
+ }
329
+ });
330
+ });
331
+ };
332
+ return GenericERC20;
333
+ }(BaseEthereumProtocol_1.BaseEthereumProtocol));
195
334
  exports.GenericERC20 = GenericERC20;
196
335
  //# sourceMappingURL=GenericERC20.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GenericERC20.js","sourceRoot":"","sources":["../../../../src/v0/protocol/erc20/GenericERC20.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mHAA0F;AAC1F,aAAa;AACb,qGAAsF;AACtF,wDAAmF;AACnF,6EAAkE;AAIlE,sFAAmG;AAKnG,kEAA8D;AAE9D,+EAAoG;AAGpG,0CAA8C;AAE9C,MAAM,mBAAmB,GAAG,OAAO,CAAC,iEAAiE,CAAC,CAAA;AAEtG,MAAa,YAAa,SAAQ,2CAA2D;IAK3F,YAA4B,OAAqC;QAC/D,KAAK,CAAC,OAAO,CAAC,CAAA;QADY,YAAO,GAAP,OAAO,CAA8B;QAJ1D,kBAAa,GAAY,IAAI,CAAA;QAC7B,oBAAe,GAAoB,kCAAe,CAAC,KAAK,CAAA;QAM7D,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,eAAe,CAAA;QAErD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAA;QACnC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAA;QAC/B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAA;QAC/C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAA;QAC3C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAA;IACzC,CAAC;IAEM,KAAK,CAAC,gBAAgB;QAC3B,OAAO,IAAI,CAAC,aAAa,CAAA;IAC3B,CAAC;IAEM,KAAK,CAAC,kBAAkB;QAC7B,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B,CAAC;IAEM,KAAK,CAAC,kBAAkB;QAC7B,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B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