@railgun-community/shared-models 4.1.0 → 4.1.2

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,3 +1,4 @@
1
+ /// <reference types="../types/global" />
1
2
  export declare type Artifact = {
2
3
  zkey: ArrayLike<number>;
3
4
  wasm: Optional<ArrayLike<number>>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="../types/global" />
1
2
  import { ChainType } from './response-types';
2
3
  export declare type RelayerFeeMessageData = {
3
4
  fees: MapType<string>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="../types/global" />
1
2
  import { BigNumber } from '@ethersproject/bignumber';
2
3
  import { MerkletreeScanStatus } from './merkletree-scan';
3
4
  import { FeesSerialized } from './network-config';
@@ -0,0 +1,8 @@
1
+ import { ProviderJson } from './fallback-provider';
2
+ declare type LogError = (err: string) => void;
3
+ /**
4
+ * Health checks ProviderJson inputs, and returns an array of available RPC providers.
5
+ * Available means that they respond to getBlockNumber(), and they are +/- 100 blocks from the median.
6
+ */
7
+ export declare const getAvailableProviderJSONs: (providerJsons: ProviderJson[], logError: LogError) => Promise<ProviderJson[]>;
8
+ export {};
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
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 };
36
+ }
37
+ };
38
+ exports.__esModule = true;
39
+ exports.getAvailableProviderJSONs = void 0;
40
+ var providers_1 = require("@ethersproject/providers");
41
+ var median_1 = require("./median");
42
+ var promises_1 = require("./promises");
43
+ var BLOCK_NUMBER_TIMEOUT_MS = 1500;
44
+ /**
45
+ * Health checks ProviderJson inputs, and returns an array of available RPC providers.
46
+ * Available means that they respond to getBlockNumber(), and they are +/- 100 blocks from the median.
47
+ */
48
+ var getAvailableProviderJSONs = function (providerJsons, logError) { return __awaiter(void 0, void 0, void 0, function () {
49
+ var blockNumbers, nonZeroBlockNumbers, medianBlockNumber, lowerBoundRange, upperBoundRange;
50
+ return __generator(this, function (_a) {
51
+ switch (_a.label) {
52
+ case 0: return [4 /*yield*/, Promise.all(providerJsons.map(function (providerJson) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0: return [4 /*yield*/, getBlockNumber(providerJson.provider, logError)];
55
+ case 1: return [2 /*return*/, _a.sent()];
56
+ }
57
+ }); }); }))];
58
+ case 1:
59
+ blockNumbers = _a.sent();
60
+ nonZeroBlockNumbers = blockNumbers.filter(function (blockNumber) { return blockNumber > 0; });
61
+ medianBlockNumber = (0, median_1.getUpperBoundMedian)(nonZeroBlockNumbers);
62
+ lowerBoundRange = medianBlockNumber - 100;
63
+ upperBoundRange = medianBlockNumber + 100;
64
+ return [2 /*return*/, providerJsons.filter(function (providerJson, index) {
65
+ var blockNumber = blockNumbers[index];
66
+ if (blockNumber === 0) {
67
+ logError("RPC Health Check failed for ".concat(providerJson.provider, ": No Block Number"));
68
+ return false;
69
+ }
70
+ if (blockNumber < lowerBoundRange) {
71
+ logError("RPC Health Check failed for ".concat(providerJson.provider, ": Block Number -").concat(medianBlockNumber - blockNumber, " from median"));
72
+ return false;
73
+ }
74
+ if (blockNumber > upperBoundRange) {
75
+ logError("RPC Health Check failed for ".concat(providerJson.provider, ": Block Number +").concat(blockNumber - medianBlockNumber, " from median"));
76
+ return false;
77
+ }
78
+ return true;
79
+ })];
80
+ }
81
+ });
82
+ }); };
83
+ exports.getAvailableProviderJSONs = getAvailableProviderJSONs;
84
+ var getBlockNumber = function (provider, logError) { return __awaiter(void 0, void 0, void 0, function () {
85
+ var rpcProvider, blockNumber, err_1;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ _a.trys.push([0, 2, , 3]);
90
+ rpcProvider = new providers_1.JsonRpcProvider(provider);
91
+ return [4 /*yield*/, (0, promises_1.promiseTimeout)(rpcProvider.getBlockNumber(), BLOCK_NUMBER_TIMEOUT_MS)];
92
+ case 1:
93
+ blockNumber = _a.sent();
94
+ return [2 /*return*/, blockNumber];
95
+ case 2:
96
+ err_1 = _a.sent();
97
+ if (!(err_1 instanceof Error)) {
98
+ throw err_1;
99
+ }
100
+ logError(err_1.message);
101
+ return [2 /*return*/, 0];
102
+ case 3: return [2 /*return*/];
103
+ }
104
+ });
105
+ }); };
106
+ //# sourceMappingURL=available-rpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"available-rpc.js","sourceRoot":"","sources":["../../src/utils/available-rpc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA2D;AAE3D,mCAA+C;AAC/C,uCAA4C;AAI5C,IAAM,uBAAuB,GAAG,IAAI,CAAC;AAErC;;;GAGG;AACI,IAAM,yBAAyB,GAAG,UACvC,aAA6B,EAC7B,QAAkB;;;;oBAEa,qBAAM,OAAO,CAAC,GAAG,CAC9C,aAAa,CAAC,GAAG,CACf,UAAM,YAAY;;gCAChB,qBAAM,cAAc,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAA;gCAArD,sBAAA,SAAqD,EAAA;;yBAAA,CACxD,CACF,EAAA;;gBALK,YAAY,GAAa,SAK9B;gBAEK,mBAAmB,GAAG,YAAY,CAAC,MAAM,CAC7C,UAAA,WAAW,IAAI,OAAA,WAAW,GAAG,CAAC,EAAf,CAAe,CAC/B,CAAC;gBACI,iBAAiB,GAAG,IAAA,4BAAmB,EAAC,mBAAmB,CAAC,CAAC;gBAC7D,eAAe,GAAG,iBAAiB,GAAG,GAAG,CAAC;gBAC1C,eAAe,GAAG,iBAAiB,GAAG,GAAG,CAAC;gBAEhD,sBAAO,aAAa,CAAC,MAAM,CAAC,UAAC,YAAY,EAAE,KAAK;wBAC9C,IAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;wBACxC,IAAI,WAAW,KAAK,CAAC,EAAE;4BACrB,QAAQ,CACN,sCAA+B,YAAY,CAAC,QAAQ,sBAAmB,CACxE,CAAC;4BACF,OAAO,KAAK,CAAC;yBACd;wBACD,IAAI,WAAW,GAAG,eAAe,EAAE;4BACjC,QAAQ,CACN,sCAA+B,YAAY,CAAC,QAAQ,6BAClD,iBAAiB,GAAG,WAAW,iBACnB,CACf,CAAC;4BACF,OAAO,KAAK,CAAC;yBACd;wBACD,IAAI,WAAW,GAAG,eAAe,EAAE;4BACjC,QAAQ,CACN,sCAA+B,YAAY,CAAC,QAAQ,6BAClD,WAAW,GAAG,iBAAiB,iBACnB,CACf,CAAC;4BACF,OAAO,KAAK,CAAC;yBACd;wBACD,OAAO,IAAI,CAAC;oBACd,CAAC,CAAC,EAAC;;;KACJ,CAAC;AA5CW,QAAA,yBAAyB,6BA4CpC;AAEF,IAAM,cAAc,GAAG,UACrB,QAAgB,EAChB,QAAkB;;;;;;gBAGV,WAAW,GAAG,IAAI,2BAAe,CAAC,QAAQ,CAAC,CAAC;gBAC9B,qBAAM,IAAA,yBAAc,EACtC,WAAW,CAAC,cAAc,EAAE,EAC5B,uBAAuB,CACxB,EAAA;;gBAHK,WAAW,GAAG,SAGnB;gBACD,sBAAO,WAAW,EAAC;;;gBAEnB,IAAI,CAAC,CAAC,KAAG,YAAY,KAAK,CAAC,EAAE;oBAC3B,MAAM,KAAG,CAAC;iBACX;gBACD,QAAQ,CAAC,KAAG,CAAC,OAAO,CAAC,CAAC;gBACtB,sBAAO,CAAC,EAAC;;;;KAEZ,CAAC","sourcesContent":["import { JsonRpcProvider } from '@ethersproject/providers';\nimport { ProviderJson } from './fallback-provider';\nimport { getUpperBoundMedian } from './median';\nimport { promiseTimeout } from './promises';\n\ntype LogError = (err: string) => void;\n\nconst BLOCK_NUMBER_TIMEOUT_MS = 1500;\n\n/**\n * Health checks ProviderJson inputs, and returns an array of available RPC providers.\n * Available means that they respond to getBlockNumber(), and they are +/- 100 blocks from the median.\n */\nexport const getAvailableProviderJSONs = async (\n providerJsons: ProviderJson[],\n logError: LogError,\n): Promise<ProviderJson[]> => {\n const blockNumbers: number[] = await Promise.all(\n providerJsons.map(\n async providerJson =>\n await getBlockNumber(providerJson.provider, logError),\n ),\n );\n\n const nonZeroBlockNumbers = blockNumbers.filter(\n blockNumber => blockNumber > 0,\n );\n const medianBlockNumber = getUpperBoundMedian(nonZeroBlockNumbers);\n const lowerBoundRange = medianBlockNumber - 100;\n const upperBoundRange = medianBlockNumber + 100;\n\n return providerJsons.filter((providerJson, index) => {\n const blockNumber = blockNumbers[index];\n if (blockNumber === 0) {\n logError(\n `RPC Health Check failed for ${providerJson.provider}: No Block Number`,\n );\n return false;\n }\n if (blockNumber < lowerBoundRange) {\n logError(\n `RPC Health Check failed for ${providerJson.provider}: Block Number -${\n medianBlockNumber - blockNumber\n } from median`,\n );\n return false;\n }\n if (blockNumber > upperBoundRange) {\n logError(\n `RPC Health Check failed for ${providerJson.provider}: Block Number +${\n blockNumber - medianBlockNumber\n } from median`,\n );\n return false;\n }\n return true;\n });\n};\n\nconst getBlockNumber = async (\n provider: string,\n logError: LogError,\n): Promise<number> => {\n try {\n const rpcProvider = new JsonRpcProvider(provider);\n const blockNumber = await promiseTimeout(\n rpcProvider.getBlockNumber(),\n BLOCK_NUMBER_TIMEOUT_MS,\n );\n return blockNumber;\n } catch (err) {\n if (!(err instanceof Error)) {\n throw err;\n }\n logError(err.message);\n return 0;\n }\n};\n"]}
@@ -1,8 +1,11 @@
1
+ /// <reference types="../types/global" />
1
2
  import { BigNumber } from '@ethersproject/bignumber';
2
3
  import { NetworkName } from '../models/network-config';
3
- import { EVMGasType, TransactionGasDetails } from '../models/response-types';
4
+ import { EVMGasType, TransactionGasDetails, TransactionGasDetailsSerialized } from '../models/response-types';
4
5
  export declare const getEVMGasTypeForTransaction: (networkName: NetworkName, sendWithPublicWallet: boolean) => EVMGasType;
5
6
  export declare const calculateGasLimit: (gasEstimate: BigNumber) => BigNumber;
6
7
  export declare const calculateGasPrice: (gasDetails: TransactionGasDetails) => BigNumber;
7
8
  export declare const calculateTotalGas: (transactionGasDetails: TransactionGasDetails) => BigNumber;
8
9
  export declare const calculateMaximumGas: (transactionGasDetails: TransactionGasDetails) => BigNumber;
10
+ export declare const serializeTransactionGasDetails: (gasDetails: TransactionGasDetails) => TransactionGasDetailsSerialized;
11
+ export declare const deserializeTransactionGasDetails: (gasDetailsSerialized: Optional<TransactionGasDetailsSerialized>) => Optional<TransactionGasDetails>;
package/dist/utils/gas.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.calculateMaximumGas = exports.calculateTotalGas = exports.calculateGasPrice = exports.calculateGasLimit = exports.getEVMGasTypeForTransaction = void 0;
3
+ exports.deserializeTransactionGasDetails = exports.serializeTransactionGasDetails = exports.calculateMaximumGas = exports.calculateTotalGas = exports.calculateGasPrice = exports.calculateGasLimit = exports.getEVMGasTypeForTransaction = void 0;
4
+ /// <reference types="../types/global" />
5
+ var bignumber_1 = require("@ethersproject/bignumber");
4
6
  var network_config_1 = require("../models/network-config");
5
7
  var response_types_1 = require("../models/response-types");
6
8
  var getEVMGasTypeForTransaction = function (networkName, sendWithPublicWallet) {
@@ -42,4 +44,53 @@ var calculateMaximumGas = function (transactionGasDetails) {
42
44
  return (0, exports.calculateGasLimit)(gasEstimate).mul(gasPrice);
43
45
  };
44
46
  exports.calculateMaximumGas = calculateMaximumGas;
47
+ var serializeTransactionGasDetails = function (gasDetails) {
48
+ switch (gasDetails.evmGasType) {
49
+ case response_types_1.EVMGasType.Type0:
50
+ case response_types_1.EVMGasType.Type1: {
51
+ var evmGasType = gasDetails.evmGasType, gasEstimate = gasDetails.gasEstimate, gasPrice = gasDetails.gasPrice;
52
+ return {
53
+ evmGasType: evmGasType,
54
+ gasEstimateString: gasEstimate.toHexString(),
55
+ gasPriceString: gasPrice.toHexString()
56
+ };
57
+ }
58
+ case response_types_1.EVMGasType.Type2: {
59
+ var evmGasType = gasDetails.evmGasType, gasEstimate = gasDetails.gasEstimate, maxFeePerGas = gasDetails.maxFeePerGas, maxPriorityFeePerGas = gasDetails.maxPriorityFeePerGas;
60
+ return {
61
+ evmGasType: evmGasType,
62
+ gasEstimateString: gasEstimate.toHexString(),
63
+ maxFeePerGasString: maxFeePerGas.toHexString(),
64
+ maxPriorityFeePerGasString: maxPriorityFeePerGas.toHexString()
65
+ };
66
+ }
67
+ }
68
+ };
69
+ exports.serializeTransactionGasDetails = serializeTransactionGasDetails;
70
+ var deserializeTransactionGasDetails = function (gasDetailsSerialized) {
71
+ if (!gasDetailsSerialized) {
72
+ return undefined;
73
+ }
74
+ switch (gasDetailsSerialized.evmGasType) {
75
+ case response_types_1.EVMGasType.Type0:
76
+ case response_types_1.EVMGasType.Type1: {
77
+ var evmGasType = gasDetailsSerialized.evmGasType, gasEstimateString = gasDetailsSerialized.gasEstimateString, gasPriceString = gasDetailsSerialized.gasPriceString;
78
+ return {
79
+ evmGasType: evmGasType,
80
+ gasEstimate: bignumber_1.BigNumber.from(gasEstimateString),
81
+ gasPrice: bignumber_1.BigNumber.from(gasPriceString)
82
+ };
83
+ }
84
+ case response_types_1.EVMGasType.Type2: {
85
+ var evmGasType = gasDetailsSerialized.evmGasType, gasEstimateString = gasDetailsSerialized.gasEstimateString, maxFeePerGasString = gasDetailsSerialized.maxFeePerGasString, maxPriorityFeePerGasString = gasDetailsSerialized.maxPriorityFeePerGasString;
86
+ return {
87
+ evmGasType: evmGasType,
88
+ gasEstimate: bignumber_1.BigNumber.from(gasEstimateString),
89
+ maxFeePerGas: bignumber_1.BigNumber.from(maxFeePerGasString),
90
+ maxPriorityFeePerGas: bignumber_1.BigNumber.from(maxPriorityFeePerGasString)
91
+ };
92
+ }
93
+ }
94
+ };
95
+ exports.deserializeTransactionGasDetails = deserializeTransactionGasDetails;
45
96
  //# sourceMappingURL=gas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gas.js","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;AACA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AC,qBAAqB,CAAC,CAAC;IAClD,IAAA,WAAW,GAAK,qBAAqB,YAA1B,CAA2B;IAC9C,OAAO,IAAA,yBAAiB,EAAC,WAAW,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACtD,CAAC,CAAC;AANW,QAAA,mBAAmB,uBAM9B","sourcesContent":["import { BigNumber } from '@ethersproject/bignumber';\nimport { NetworkName, NETWORK_CONFIG } from '../models/network-config';\nimport { EVMGasType, TransactionGasDetails } from '../models/response-types';\n\nexport const getEVMGasTypeForTransaction = (\n networkName: NetworkName,\n sendWithPublicWallet: boolean,\n): EVMGasType => {\n const { defaultEVMGasType } = NETWORK_CONFIG[networkName];\n\n if (defaultEVMGasType === EVMGasType.Type2 && !sendWithPublicWallet) {\n // Relayer transactions require overallBatchMinGasPrice.\n // This is only supported by type 1 transactions.\n return EVMGasType.Type1;\n }\n\n return defaultEVMGasType;\n};\n\nexport const calculateGasLimit = (gasEstimate: BigNumber): BigNumber => {\n // Gas Limit: Add 20% to gas estimate.\n return gasEstimate.mul(12000).div(10000);\n};\n\nexport const calculateGasPrice = (gasDetails: TransactionGasDetails) => {\n switch (gasDetails.evmGasType) {\n case EVMGasType.Type0:\n case EVMGasType.Type1: {\n return gasDetails.gasPrice;\n }\n case EVMGasType.Type2: {\n return gasDetails.maxFeePerGas;\n }\n }\n};\n\nexport const calculateTotalGas = (\n transactionGasDetails: TransactionGasDetails,\n) => {\n const gasPrice = calculateGasPrice(transactionGasDetails);\n const { gasEstimate } = transactionGasDetails;\n return gasEstimate.mul(gasPrice);\n};\n\nexport const calculateMaximumGas = (\n transactionGasDetails: TransactionGasDetails,\n): BigNumber => {\n const gasPrice = calculateGasPrice(transactionGasDetails);\n const { gasEstimate } = transactionGasDetails;\n return calculateGasLimit(gasEstimate).mul(gasPrice);\n};\n"]}
1
+ {"version":3,"file":"gas.js","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,sDAAqD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AAC,KAAK,CAAC,CAAC;YACb,IAAA,UAAU,GAChB,oBAAoB,WADJ,EAAE,iBAAiB,GACnC,oBAAoB,kBADe,EAAE,cAAc,GACnD,oBAAoB,eAD+B,CAC9B;YACvB,OAAO;gBACL,UAAU,YAAA;gBACV,WAAW,EAAE,qBAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC;gBAC9C,QAAQ,EAAE,qBAAS,CAAC,IAAI,CAAC,cAAc,CAAC;aACzC,CAAC;SACH;QACD,KAAK,2BAAU,CAAC,KAAK,CAAC,CAAC;YAEnB,IAAA,UAAU,GAIR,oBAAoB,WAJZ,EACV,iBAAiB,GAGf,oBAAoB,kBAHL,EACjB,kBAAkB,GAEhB,oBAAoB,mBAFJ,EAClB,0BAA0B,GACxB,oBAAoB,2BADI,CACH;YACzB,OAAO;gBACL,UAAU,YAAA;gBACV,WAAW,EAAE,qBAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC;gBAC9C,YAAY,EAAE,qBAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC;gBAChD,oBAAoB,EAAE,qBAAS,CAAC,IAAI,CAAC,0BAA0B,CAAC;aACjE,CAAC;SACH;KACF;AACH,CAAC,CAAC;AAhCW,QAAA,gCAAgC,oCAgC3C","sourcesContent":["/// <reference types=\"../types/global\" />\nimport { BigNumber } from '@ethersproject/bignumber';\nimport { NetworkName, NETWORK_CONFIG } from '../models/network-config';\nimport {\n EVMGasType,\n TransactionGasDetails,\n TransactionGasDetailsSerialized,\n} from '../models/response-types';\n\nexport const getEVMGasTypeForTransaction = (\n networkName: NetworkName,\n sendWithPublicWallet: boolean,\n): EVMGasType => {\n const { defaultEVMGasType } = NETWORK_CONFIG[networkName];\n\n if (defaultEVMGasType === EVMGasType.Type2 && !sendWithPublicWallet) {\n // Relayer transactions require overallBatchMinGasPrice.\n // This is only supported by type 1 transactions.\n return EVMGasType.Type1;\n }\n\n return defaultEVMGasType;\n};\n\nexport const calculateGasLimit = (gasEstimate: BigNumber): BigNumber => {\n // Gas Limit: Add 20% to gas estimate.\n return gasEstimate.mul(12000).div(10000);\n};\n\nexport const calculateGasPrice = (gasDetails: TransactionGasDetails) => {\n switch (gasDetails.evmGasType) {\n case EVMGasType.Type0:\n case EVMGasType.Type1: {\n return gasDetails.gasPrice;\n }\n case EVMGasType.Type2: {\n return gasDetails.maxFeePerGas;\n }\n }\n};\n\nexport const calculateTotalGas = (\n transactionGasDetails: TransactionGasDetails,\n) => {\n const gasPrice = calculateGasPrice(transactionGasDetails);\n const { gasEstimate } = transactionGasDetails;\n return gasEstimate.mul(gasPrice);\n};\n\nexport const calculateMaximumGas = (\n transactionGasDetails: TransactionGasDetails,\n): BigNumber => {\n const gasPrice = calculateGasPrice(transactionGasDetails);\n const { gasEstimate } = transactionGasDetails;\n return calculateGasLimit(gasEstimate).mul(gasPrice);\n};\n\nexport const serializeTransactionGasDetails = (\n gasDetails: TransactionGasDetails,\n): TransactionGasDetailsSerialized => {\n switch (gasDetails.evmGasType) {\n case EVMGasType.Type0:\n case EVMGasType.Type1: {\n const { evmGasType, gasEstimate, gasPrice } = gasDetails;\n return {\n evmGasType,\n gasEstimateString: gasEstimate.toHexString(),\n gasPriceString: gasPrice.toHexString(),\n };\n }\n case EVMGasType.Type2: {\n const { evmGasType, gasEstimate, maxFeePerGas, maxPriorityFeePerGas } =\n gasDetails;\n return {\n evmGasType,\n gasEstimateString: gasEstimate.toHexString(),\n maxFeePerGasString: maxFeePerGas.toHexString(),\n maxPriorityFeePerGasString: maxPriorityFeePerGas.toHexString(),\n };\n }\n }\n};\n\nexport const deserializeTransactionGasDetails = (\n gasDetailsSerialized: Optional<TransactionGasDetailsSerialized>,\n): Optional<TransactionGasDetails> => {\n if (!gasDetailsSerialized) {\n return undefined;\n }\n switch (gasDetailsSerialized.evmGasType) {\n case EVMGasType.Type0:\n case EVMGasType.Type1: {\n const { evmGasType, gasEstimateString, gasPriceString } =\n gasDetailsSerialized;\n return {\n evmGasType,\n gasEstimate: BigNumber.from(gasEstimateString),\n gasPrice: BigNumber.from(gasPriceString),\n };\n }\n case EVMGasType.Type2: {\n const {\n evmGasType,\n gasEstimateString,\n maxFeePerGasString,\n maxPriorityFeePerGasString,\n } = gasDetailsSerialized;\n return {\n evmGasType,\n gasEstimate: BigNumber.from(gasEstimateString),\n maxFeePerGas: BigNumber.from(maxFeePerGasString),\n maxPriorityFeePerGas: BigNumber.from(maxPriorityFeePerGasString),\n };\n }\n }\n};\n"]}
@@ -0,0 +1 @@
1
+ export declare const getUpperBoundMedian: (numbers: number[]) => number;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.getUpperBoundMedian = void 0;
4
+ var getUpperBoundMedian = function (numbers) {
5
+ if (!numbers.length) {
6
+ return 0;
7
+ }
8
+ var index = Math.floor(numbers.length / 2);
9
+ var sorted = numbers.sort();
10
+ return sorted[index];
11
+ };
12
+ exports.getUpperBoundMedian = getUpperBoundMedian;
13
+ //# sourceMappingURL=median.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"median.js","sourceRoot":"","sources":["../../src/utils/median.ts"],"names":[],"mappings":";;;AAAO,IAAM,mBAAmB,GAAG,UAAC,OAAiB;IACnD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,CAAC,CAAC;KACV;IACD,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,IAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAAC;AAPW,QAAA,mBAAmB,uBAO9B","sourcesContent":["export const getUpperBoundMedian = (numbers: number[]) => {\n if (!numbers.length) {\n return 0;\n }\n const index = Math.floor(numbers.length / 2);\n const sorted = numbers.sort();\n return sorted[index];\n};\n"]}
@@ -1,3 +1,4 @@
1
+ /// <reference types="../types/global" />
1
2
  import { Network } from '../models/network-config';
2
3
  import { Chain } from '../models/response-types';
3
4
  export declare const networkForChain: (chain: Chain) => Optional<Network>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="../types/global" />
1
2
  export declare const delay: (delayInMS: number) => Promise<void>;
2
3
  export declare function promiseTimeout<T>(promise: Promise<T>, ms: number, customTimeoutError?: Error): Promise<T>;
3
4
  export declare function poll<T>(fn: () => Promise<T>, passCondition: (result: T) => boolean, delayInMS: number, allowedAttempts?: number): Promise<Optional<T>>;
@@ -1,3 +1,4 @@
1
+ /// <reference types="../types/global" />
1
2
  import { PopulatedTransaction } from '@ethersproject/contracts';
2
3
  import { TransactionRequest } from '@ethersproject/providers';
3
4
  export declare const serializeUnsignedTransaction: (transaction: PopulatedTransaction) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@railgun-community/shared-models",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [