@railgun-community/shared-models 4.1.0 → 4.1.1

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';
@@ -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,2DAAuE;AACvE,2DAA6E;AAEtE,IAAM,2BAA2B,GAAG,UACzC,WAAwB,EACxB,oBAA6B;IAErB,IAAA,iBAAiB,GAAK,+BAAc,CAAC,WAAW,CAAC,kBAAhC,CAAiC;IAE1D,IAAI,iBAAiB,KAAK,2BAAU,CAAC,KAAK,IAAI,CAAC,oBAAoB,EAAE;QACnE,wDAAwD;QACxD,iDAAiD;QACjD,OAAO,2BAAU,CAAC,KAAK,CAAC;KACzB;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAbW,QAAA,2BAA2B,+BAatC;AAEK,IAAM,iBAAiB,GAAG,UAAC,WAAsB;IACtD,sCAAsC;IACtC,OAAO,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC,CAAC;AAHW,QAAA,iBAAiB,qBAG5B;AAEK,IAAM,iBAAiB,GAAG,UAAC,UAAiC;IACjE,QAAQ,UAAU,CAAC,UAAU,EAAE;QAC7B,KAAK,2BAAU,CAAC,KAAK,CAAC;QACtB,KAAK,2BAAU,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO,UAAU,CAAC,QAAQ,CAAC;SAC5B;QACD,KAAK,2BAAU,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO,UAAU,CAAC,YAAY,CAAC;SAChC;KACF;AACH,CAAC,CAAC;AAVW,QAAA,iBAAiB,qBAU5B;AAEK,IAAM,iBAAiB,GAAG,UAC/B,qBAA4C;IAE5C,IAAM,QAAQ,GAAG,IAAA,yBAAiB,EAAC,qBAAqB,CAAC,CAAC;IAClD,IAAA,WAAW,GAAK,qBAAqB,YAA1B,CAA2B;IAC9C,OAAO,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B;AAEK,IAAM,mBAAmB,GAAG,UACjC,qBAA4C;IAE5C,IAAM,QAAQ,GAAG,IAAA,yBAAiB,EAAC,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;AACrD,2DAAuE;AACvE,2DAIkC;AAE3B,IAAM,2BAA2B,GAAG,UACzC,WAAwB,EACxB,oBAA6B;IAErB,IAAA,iBAAiB,GAAK,+BAAc,CAAC,WAAW,CAAC,kBAAhC,CAAiC;IAE1D,IAAI,iBAAiB,KAAK,2BAAU,CAAC,KAAK,IAAI,CAAC,oBAAoB,EAAE;QACnE,wDAAwD;QACxD,iDAAiD;QACjD,OAAO,2BAAU,CAAC,KAAK,CAAC;KACzB;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAbW,QAAA,2BAA2B,+BAatC;AAEK,IAAM,iBAAiB,GAAG,UAAC,WA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AoB,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"]}
@@ -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.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [