@xyo-network/gas-price-plugin 5.3.2 → 5.3.3

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 (78) hide show
  1. package/dist/neutral/Diviner.d.ts +16 -0
  2. package/dist/neutral/Diviner.d.ts.map +1 -0
  3. package/dist/neutral/Plugin.d.ts +3 -0
  4. package/dist/neutral/Plugin.d.ts.map +1 -0
  5. package/dist/neutral/Schema.d.ts +9 -0
  6. package/dist/neutral/Schema.d.ts.map +1 -0
  7. package/dist/neutral/index.d.ts +4 -0
  8. package/dist/neutral/index.d.ts.map +1 -0
  9. package/dist/neutral/index.mjs +313 -0
  10. package/dist/neutral/index.mjs.map +1 -0
  11. package/dist/neutral/lib/average.d.ts +8 -0
  12. package/dist/neutral/lib/average.d.ts.map +1 -0
  13. package/dist/neutral/lib/divineGas.d.ts +4 -0
  14. package/dist/neutral/lib/divineGas.d.ts.map +1 -0
  15. package/dist/neutral/lib/identities/index.d.ts +6 -0
  16. package/dist/neutral/lib/identities/index.d.ts.map +1 -0
  17. package/dist/neutral/lib/identities/isEthereumGasBlocknativePayload.d.ts +4 -0
  18. package/dist/neutral/lib/identities/isEthereumGasBlocknativePayload.d.ts.map +1 -0
  19. package/dist/neutral/lib/identities/isEthereumGasEtherchainV2Payload.d.ts +4 -0
  20. package/dist/neutral/lib/identities/isEthereumGasEtherchainV2Payload.d.ts.map +1 -0
  21. package/dist/neutral/lib/identities/isEthereumGasEthersPayload.d.ts +4 -0
  22. package/dist/neutral/lib/identities/isEthereumGasEthersPayload.d.ts.map +1 -0
  23. package/dist/neutral/lib/identities/isEthereumGasEtherscanPayload.d.ts +4 -0
  24. package/dist/neutral/lib/identities/isEthereumGasEtherscanPayload.d.ts.map +1 -0
  25. package/dist/neutral/lib/identities/isEthereumGasEthgasstationPayload.d.ts +4 -0
  26. package/dist/neutral/lib/identities/isEthereumGasEthgasstationPayload.d.ts.map +1 -0
  27. package/dist/neutral/lib/index.d.ts +2 -0
  28. package/dist/neutral/lib/index.d.ts.map +1 -0
  29. package/dist/neutral/lib/transforms/index.d.ts +6 -0
  30. package/dist/neutral/lib/transforms/index.d.ts.map +1 -0
  31. package/dist/neutral/lib/transforms/transformGasFromBlocknative.d.ts +4 -0
  32. package/dist/neutral/lib/transforms/transformGasFromBlocknative.d.ts.map +1 -0
  33. package/dist/neutral/lib/transforms/transformGasFromEtherchainV2.d.ts +4 -0
  34. package/dist/neutral/lib/transforms/transformGasFromEtherchainV2.d.ts.map +1 -0
  35. package/dist/neutral/lib/transforms/transformGasFromEthers.d.ts +4 -0
  36. package/dist/neutral/lib/transforms/transformGasFromEthers.d.ts.map +1 -0
  37. package/dist/neutral/lib/transforms/transformGasFromEtherscan.d.ts +4 -0
  38. package/dist/neutral/lib/transforms/transformGasFromEtherscan.d.ts.map +1 -0
  39. package/dist/neutral/lib/transforms/transformGasFromEthgasstation.d.ts +4 -0
  40. package/dist/neutral/lib/transforms/transformGasFromEthgasstation.d.ts.map +1 -0
  41. package/dist/neutral/test/index.d.ts +6 -0
  42. package/dist/neutral/test/index.d.ts.map +1 -0
  43. package/dist/neutral/test/sampleBlocknativeGas.d.ts +3 -0
  44. package/dist/neutral/test/sampleBlocknativeGas.d.ts.map +1 -0
  45. package/dist/neutral/test/sampleEtherchainGasV2.d.ts +3 -0
  46. package/dist/neutral/test/sampleEtherchainGasV2.d.ts.map +1 -0
  47. package/dist/neutral/test/sampleEthersGas.d.ts +3 -0
  48. package/dist/neutral/test/sampleEthersGas.d.ts.map +1 -0
  49. package/dist/neutral/test/sampleEtherscanGas.d.ts +3 -0
  50. package/dist/neutral/test/sampleEtherscanGas.d.ts.map +1 -0
  51. package/dist/neutral/test/sampleEthgasstationGas.d.ts +3 -0
  52. package/dist/neutral/test/sampleEthgasstationGas.d.ts.map +1 -0
  53. package/package.json +23 -15
  54. package/src/Diviner.ts +0 -26
  55. package/src/Plugin.ts +0 -15
  56. package/src/Schema.ts +0 -7
  57. package/src/index.ts +0 -3
  58. package/src/lib/average.ts +0 -48
  59. package/src/lib/divineGas.ts +0 -33
  60. package/src/lib/identities/index.ts +0 -5
  61. package/src/lib/identities/isEthereumGasBlocknativePayload.ts +0 -7
  62. package/src/lib/identities/isEthereumGasEtherchainV2Payload.ts +0 -7
  63. package/src/lib/identities/isEthereumGasEthersPayload.ts +0 -7
  64. package/src/lib/identities/isEthereumGasEtherscanPayload.ts +0 -7
  65. package/src/lib/identities/isEthereumGasEthgasstationPayload.ts +0 -7
  66. package/src/lib/index.ts +0 -1
  67. package/src/lib/transforms/index.ts +0 -5
  68. package/src/lib/transforms/transformGasFromBlocknative.ts +0 -54
  69. package/src/lib/transforms/transformGasFromEtherchainV2.ts +0 -24
  70. package/src/lib/transforms/transformGasFromEthers.ts +0 -30
  71. package/src/lib/transforms/transformGasFromEtherscan.ts +0 -34
  72. package/src/lib/transforms/transformGasFromEthgasstation.ts +0 -49
  73. package/src/test/index.ts +0 -5
  74. package/src/test/sampleBlocknativeGas.ts +0 -94
  75. package/src/test/sampleEtherchainGasV2.ts +0 -16
  76. package/src/test/sampleEthersGas.ts +0 -10
  77. package/src/test/sampleEtherscanGas.ts +0 -17
  78. package/src/test/sampleEthgasstationGas.ts +0 -21
@@ -0,0 +1,3 @@
1
+ import type { EthereumGasEthgasstationPayload } from '@xyo-network/ethgasstation-ethereum-gas-payload-plugin';
2
+ export declare const sampleEthgasstationGas: EthereumGasEthgasstationPayload;
3
+ //# sourceMappingURL=sampleEthgasstationGas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampleEthgasstationGas.d.ts","sourceRoot":"","sources":["../../../src/test/sampleEthgasstationGas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,wDAAwD,CAAA;AAG7G,eAAO,MAAM,sBAAsB,EAAE,+BAiBpC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/gas-price-plugin",
3
- "version": "5.3.2",
3
+ "version": "5.3.3",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,34 +30,35 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
- "!**/*.bench.*",
35
- "!**/*.spec.*",
36
- "!**/*.test.*"
33
+ "README.md"
37
34
  ],
35
+ "dependencies": {
36
+ "@xyo-network/blocknative-ethereum-gas-payload-plugin": "workspace:^",
37
+ "@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins": "workspace:^",
38
+ "@xyo-network/ethers-ethereum-gas-payload-plugin": "workspace:^",
39
+ "@xyo-network/etherscan-ethereum-gas-payload-plugin": "workspace:^",
40
+ "@xyo-network/ethgasstation-ethereum-gas-payload-plugin": "workspace:^",
41
+ "@xyo-network/gas-price-payload-plugin": "workspace:^"
42
+ },
38
43
  "devDependencies": {
39
44
  "@types/regression": "~2.0.6",
40
45
  "@xylabs/sdk-js": "^5.0.90",
46
+ "@xylabs/ts-scripts-common": "~7.5.10",
41
47
  "@xylabs/ts-scripts-yarn3": "~7.5.10",
42
48
  "@xylabs/tsconfig": "~7.5.10",
43
49
  "@xylabs/vitest-extended": "~5.0.90",
44
- "@xyo-network/blocknative-ethereum-gas-payload-plugin": "5.3.2",
45
- "@xyo-network/blocknative-ethereum-gas-plugin": "5.3.2",
50
+ "@xyo-network/blocknative-ethereum-gas-plugin": "5.3.3",
46
51
  "@xyo-network/diviner-abstract": "~5.3.5",
47
52
  "@xyo-network/diviner-model": "~5.3.5",
48
- "@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins": "5.3.2",
49
- "@xyo-network/etherchain-gas-ethereum-blockchain-plugins": "5.3.2",
50
- "@xyo-network/ethers-ethereum-gas-payload-plugin": "5.3.2",
51
- "@xyo-network/ethers-ethereum-gas-plugin": "5.3.2",
52
- "@xyo-network/etherscan-ethereum-gas-payload-plugin": "5.3.2",
53
- "@xyo-network/etherscan-ethereum-gas-plugin": "5.3.2",
54
- "@xyo-network/ethgasstation-ethereum-gas-payload-plugin": "5.3.2",
55
- "@xyo-network/gas-price-payload-plugin": "5.3.2",
53
+ "@xyo-network/etherchain-gas-ethereum-blockchain-plugins": "5.3.3",
54
+ "@xyo-network/ethers-ethereum-gas-plugin": "5.3.3",
55
+ "@xyo-network/etherscan-ethereum-gas-plugin": "5.3.3",
56
56
  "@xyo-network/module-model": "~5.3.5",
57
57
  "@xyo-network/payload-model": "~5.3.5",
58
58
  "@xyo-network/payloadset-plugin": "~5.3.5",
59
59
  "@xyo-network/sdk-js": "~5.3.5",
60
60
  "@xyo-network/witness-blockchain-abstract": "~5.3.5",
61
+ "ethers": "^6",
61
62
  "regression": "~2.0.1",
62
63
  "typescript": "~5.9.3",
63
64
  "vitest": "~4.1.2",
@@ -65,6 +66,13 @@
65
66
  },
66
67
  "peerDependencies": {
67
68
  "@xylabs/sdk-js": "^5",
69
+ "@xyo-network/diviner-abstract": "^5",
70
+ "@xyo-network/diviner-model": "^5",
71
+ "@xyo-network/module-model": "^5",
72
+ "@xyo-network/payload-model": "^5",
73
+ "@xyo-network/payloadset-plugin": "^5",
74
+ "@xyo-network/sdk-js": "^5",
75
+ "regression": "^2",
68
76
  "zod": "^4"
69
77
  },
70
78
  "publishConfig": {
package/src/Diviner.ts DELETED
@@ -1,26 +0,0 @@
1
- import { AbstractDiviner } from '@xyo-network/diviner-abstract'
2
- import type {
3
- DivinerConfig, DivinerModule, DivinerParams,
4
- } from '@xyo-network/diviner-model'
5
- import { EthereumGasSchema } from '@xyo-network/gas-price-payload-plugin'
6
- import type { AnyConfigSchema } from '@xyo-network/module-model'
7
- import type { Payload, Schema } from '@xyo-network/payload-model'
8
-
9
- import { divineGas } from './lib/index.ts'
10
- import { EthereumGasDivinerConfigSchema } from './Schema.ts'
11
-
12
- export type EthereumGasDivinerConfig = DivinerConfig<{ schema: EthereumGasDivinerConfigSchema }>
13
- export type EthereumGasDivinerParams = DivinerParams<AnyConfigSchema<EthereumGasDivinerConfig>>
14
-
15
- export class EthereumGasDiviner<TParams extends EthereumGasDivinerParams = EthereumGasDivinerParams>
16
- extends AbstractDiviner<TParams>
17
- implements DivinerModule {
18
- static override readonly configSchemas: Schema[] = [...super.configSchemas, EthereumGasDivinerConfigSchema]
19
- static override readonly defaultConfigSchema: Schema = EthereumGasDivinerConfigSchema
20
- static override readonly targetSchema: Schema = EthereumGasSchema
21
-
22
- protected override divineHandler(payloads?: Payload[]): Payload[] {
23
- const cost = divineGas(payloads ?? [])
24
- return [cost]
25
- }
26
- }
package/src/Plugin.ts DELETED
@@ -1,15 +0,0 @@
1
- import { EthereumGasSchema } from '@xyo-network/gas-price-payload-plugin'
2
- import { PayloadSetSchema } from '@xyo-network/payload-model'
3
- import { createPayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'
4
-
5
- import { EthereumGasDiviner } from './Diviner.ts'
6
-
7
- export const EthereumGasPlugin = () =>
8
- createPayloadSetDivinerPlugin<EthereumGasDiviner>(
9
- { required: { [EthereumGasSchema]: 1 }, schema: PayloadSetSchema },
10
- {
11
- diviner: async (params) => {
12
- return (await EthereumGasDiviner.create(params)) as EthereumGasDiviner
13
- },
14
- },
15
- )
package/src/Schema.ts DELETED
@@ -1,7 +0,0 @@
1
- import { asSchema } from '@xyo-network/payload-model'
2
-
3
- export type EthereumGasDivinerQuerySchema = typeof EthereumGasDivinerQuerySchema
4
- export const EthereumGasDivinerQuerySchema = asSchema('network.xyo.blockchain.ethereum.gas.diviner.query', true)
5
-
6
- export type EthereumGasDivinerConfigSchema = typeof EthereumGasDivinerConfigSchema
7
- export const EthereumGasDivinerConfigSchema = asSchema('network.xyo.blockchain.ethereum.gas.diviner.config', true)
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './Diviner.ts'
2
- export { EthereumGasPlugin as default, EthereumGasPlugin } from './Plugin.ts'
3
- export * from './Schema.ts'
@@ -1,48 +0,0 @@
1
- import { exists } from '@xylabs/sdk-js'
2
- import type { FeeData } from '@xyo-network/gas-price-payload-plugin'
3
-
4
- /**
5
- * Averages an array of numbers
6
- * @param x Averages an array of numbers
7
- * @returns The average of the array of numbers or undefined if the
8
- * array is empty or undefined
9
- */
10
-
11
- const listAverage = (x?: number[]) => (x?.length ? x.reduce((a, b) => a + b) / x.length : undefined)
12
-
13
- /**
14
- * Averages the property indicates by the supplied property
15
- * expression across the array of FeeData
16
- * @param data The array of data to average
17
- * @param propertyExpression The expression for the property to
18
- * average
19
- * @returns The average of the supplied property across the array
20
- */
21
- const averageProperty = (data: FeeData[], propertyExpression: (x: FeeData) => number | undefined) => {
22
- return listAverage(data.map(propertyExpression).filter(exists))
23
- }
24
-
25
- /**
26
- * Averages the supplied FeeData
27
- * @param input An array of FeeData or undefined
28
- * @returns The average of the supplied FeeData
29
- */
30
- export const average = (input?: (FeeData | undefined)[]): FeeData => {
31
- const data = input?.filter(exists) || []
32
- const averaged: FeeData = {
33
- baseFee: averageProperty(data, x => x.baseFee),
34
- feePerGas: {
35
- high: averageProperty(data, x => x.feePerGas.high),
36
- low: averageProperty(data, x => x.feePerGas.low),
37
- medium: averageProperty(data, x => x.feePerGas.medium),
38
- veryHigh: averageProperty(data, x => x.feePerGas.veryHigh),
39
- },
40
- priorityFeePerGas: {
41
- high: averageProperty(data, x => x.priorityFeePerGas.high),
42
- low: averageProperty(data, x => x.priorityFeePerGas.low),
43
- medium: averageProperty(data, x => x.priorityFeePerGas.medium),
44
- veryHigh: averageProperty(data, x => x.priorityFeePerGas.veryHigh),
45
- },
46
- }
47
- return averaged
48
- }
@@ -1,33 +0,0 @@
1
- import type { EthereumGasPayload, FeeData } from '@xyo-network/gas-price-payload-plugin'
2
- import { EthereumGasSchema } from '@xyo-network/gas-price-payload-plugin'
3
- import type { Payload } from '@xyo-network/payload-model'
4
- import { PayloadBuilder } from '@xyo-network/sdk-js'
5
-
6
- import { average } from './average.ts'
7
- import {
8
- isEthereumGasBlocknativePayload,
9
- isEthereumGasEtherchainV2Payload,
10
- isEthereumGasEtherscanPayload,
11
- isEthereumGasEthersPayload,
12
- isEthereumGasEthgasstationPayload,
13
- } from './identities/index.ts'
14
- import {
15
- transformGasFromBlocknative,
16
- transformGasFromEtherchainV2,
17
- transformGasFromEthers,
18
- transformGasFromEtherscan,
19
- transformGasFromEthgasstation,
20
- } from './transforms/index.ts'
21
-
22
- export const divineGas = (payloads: Payload[]): EthereumGasPayload => {
23
- const blocknative = payloads.filter(isEthereumGasBlocknativePayload).map(transformGasFromBlocknative)
24
- const etherchainV2 = payloads.filter(isEthereumGasEtherchainV2Payload).map(transformGasFromEtherchainV2)
25
- const ethers = payloads.filter(isEthereumGasEthersPayload).map(transformGasFromEthers)
26
- const etherscan = payloads.filter(isEthereumGasEtherscanPayload).map(transformGasFromEtherscan)
27
- const ethgasstation = payloads.filter(isEthereumGasEthgasstationPayload).map(transformGasFromEthgasstation)
28
- const transactionCosts: FeeData[] = [...blocknative, ...etherchainV2, ...ethers, ...etherscan, ...ethgasstation]
29
- const avg = average(transactionCosts)
30
- const timestamp = Date.now()
31
- const payload = new PayloadBuilder<EthereumGasPayload>({ schema: EthereumGasSchema }).fields({ ...avg, timestamp }).build()
32
- return payload
33
- }
@@ -1,5 +0,0 @@
1
- export * from './isEthereumGasBlocknativePayload.ts'
2
- export * from './isEthereumGasEtherchainV2Payload.ts'
3
- export * from './isEthereumGasEtherscanPayload.ts'
4
- export * from './isEthereumGasEthersPayload.ts'
5
- export * from './isEthereumGasEthgasstationPayload.ts'
@@ -1,7 +0,0 @@
1
- import type { EthereumGasBlocknativePayload } from '@xyo-network/blocknative-ethereum-gas-payload-plugin'
2
- import { EthereumGasBlocknativeSchema } from '@xyo-network/blocknative-ethereum-gas-payload-plugin'
3
- import type { Payload } from '@xyo-network/payload-model'
4
-
5
- export const isEthereumGasBlocknativePayload = (payload?: Payload | null): payload is EthereumGasBlocknativePayload => {
6
- return payload?.schema === EthereumGasBlocknativeSchema
7
- }
@@ -1,7 +0,0 @@
1
- import type { EthereumGasEtherchainV2Payload } from '@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins'
2
- import { EthereumGasEtherchainV2Schema } from '@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins'
3
- import type { Payload } from '@xyo-network/payload-model'
4
-
5
- export const isEthereumGasEtherchainV2Payload = (payload?: Payload | null): payload is EthereumGasEtherchainV2Payload => {
6
- return payload?.schema === EthereumGasEtherchainV2Schema
7
- }
@@ -1,7 +0,0 @@
1
- import type { EthereumGasEthersPayload } from '@xyo-network/ethers-ethereum-gas-payload-plugin'
2
- import { EthereumGasEthersSchema } from '@xyo-network/ethers-ethereum-gas-payload-plugin'
3
- import type { Payload } from '@xyo-network/payload-model'
4
-
5
- export const isEthereumGasEthersPayload = (payload?: Payload | null): payload is EthereumGasEthersPayload => {
6
- return payload?.schema === EthereumGasEthersSchema
7
- }
@@ -1,7 +0,0 @@
1
- import type { EthereumGasEtherscanPayload } from '@xyo-network/etherscan-ethereum-gas-payload-plugin'
2
- import { EthereumGasEtherscanSchema } from '@xyo-network/etherscan-ethereum-gas-payload-plugin'
3
- import type { Payload } from '@xyo-network/payload-model'
4
-
5
- export const isEthereumGasEtherscanPayload = (payload?: Payload | null): payload is EthereumGasEtherscanPayload => {
6
- return payload?.schema === EthereumGasEtherscanSchema
7
- }
@@ -1,7 +0,0 @@
1
- import type { EthereumGasEthgasstationPayload } from '@xyo-network/ethgasstation-ethereum-gas-payload-plugin'
2
- import { EthereumGasEthgasstationSchema } from '@xyo-network/ethgasstation-ethereum-gas-payload-plugin'
3
- import type { Payload } from '@xyo-network/payload-model'
4
-
5
- export const isEthereumGasEthgasstationPayload = (payload?: Payload | null): payload is EthereumGasEthgasstationPayload => {
6
- return payload?.schema === EthereumGasEthgasstationSchema
7
- }
package/src/lib/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './divineGas.ts'
@@ -1,5 +0,0 @@
1
- export * from './transformGasFromBlocknative.ts'
2
- export * from './transformGasFromEtherchainV2.ts'
3
- export * from './transformGasFromEthers.ts'
4
- export * from './transformGasFromEtherscan.ts'
5
- export * from './transformGasFromEthgasstation.ts'
@@ -1,54 +0,0 @@
1
- import type { EthereumGasBlocknativePayload } from '@xyo-network/blocknative-ethereum-gas-payload-plugin'
2
- import type {
3
- FeeData, FeePerGas, PriorityFeePerGas,
4
- } from '@xyo-network/gas-price-payload-plugin'
5
- import regression from 'regression'
6
-
7
- const getBaseFee = (payload: EthereumGasBlocknativePayload): number | undefined => {
8
- return payload?.blockPrices?.[0]?.baseFeePerGas
9
- }
10
-
11
- const getFeePerGas = (payload: EthereumGasBlocknativePayload): Partial<FeePerGas> => {
12
- const sorted = payload.blockPrices?.[0].estimatedPrices?.toSorted((a, b) => a.confidence - b.confidence)
13
- const trend = regression.linear([
14
- [0, sorted?.[0].price],
15
- [1, sorted?.[1].price],
16
- [2, sorted?.[2].price],
17
- [3, sorted?.[3].price],
18
- [4, sorted?.[4].price],
19
- ])
20
- const feePerGas: FeePerGas = {
21
- low: trend.predict(0.5)[1],
22
- medium: trend.predict(1.5)[1],
23
- high: trend.predict(2.5)[1],
24
- veryHigh: trend.predict(3.5)[1],
25
- }
26
- return feePerGas
27
- }
28
-
29
- const getPriorityFeePerGas = (payload: EthereumGasBlocknativePayload): Partial<PriorityFeePerGas> => {
30
- const sorted = payload.blockPrices?.[0].estimatedPrices?.toSorted((a, b) => a.confidence - b.confidence)
31
- const trend = regression.linear([
32
- [0, sorted?.[0].maxPriorityFeePerGas],
33
- [1, sorted?.[1].maxPriorityFeePerGas],
34
- [2, sorted?.[2].maxPriorityFeePerGas],
35
- [3, sorted?.[3].maxPriorityFeePerGas],
36
- [4, sorted?.[4].maxPriorityFeePerGas],
37
- ])
38
- const priorityFeePerGas: PriorityFeePerGas = {
39
- low: trend.predict(0.5)[1],
40
- medium: trend.predict(1.5)[1],
41
- high: trend.predict(2.5)[1],
42
- veryHigh: trend.predict(3.5)[1],
43
- }
44
- return priorityFeePerGas
45
- }
46
-
47
- export const transformGasFromBlocknative = (payload: EthereumGasBlocknativePayload): FeeData => {
48
- const baseFee = getBaseFee(payload)
49
- const feePerGas = getFeePerGas(payload)
50
- const priorityFeePerGas = getPriorityFeePerGas(payload)
51
- return {
52
- baseFee, feePerGas, priorityFeePerGas,
53
- }
54
- }
@@ -1,24 +0,0 @@
1
- import type { EthereumGasEtherchainV2Payload } from '@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins'
2
- import type { FeeData, FeePerGas } from '@xyo-network/gas-price-payload-plugin'
3
-
4
- const getFeePerGas = (payload: EthereumGasEtherchainV2Payload): Partial<FeePerGas> => {
5
- const {
6
- slow, standard, fast, rapid,
7
- } = payload.data
8
- const low = slow / 1_000_000_000
9
- const medium = standard / 1_000_000_000
10
- const high = fast / 1_000_000_000
11
- const veryHigh = rapid / 1_000_000_000
12
- return {
13
- high, low, medium, veryHigh,
14
- }
15
- }
16
-
17
- export const transformGasFromEtherchainV2 = (payload: EthereumGasEtherchainV2Payload): FeeData => {
18
- const baseFee = undefined
19
- const feePerGas = getFeePerGas(payload)
20
- const priorityFeePerGas = {}
21
- return {
22
- baseFee, feePerGas, priorityFeePerGas,
23
- }
24
- }
@@ -1,30 +0,0 @@
1
- import type { EthereumGasEthersPayload } from '@xyo-network/ethers-ethereum-gas-payload-plugin'
2
- import type {
3
- FeeData, FeePerGas, PriorityFeePerGas,
4
- } from '@xyo-network/gas-price-payload-plugin'
5
-
6
- const getBaseFee = (payload: EthereumGasEthersPayload): number | undefined => {
7
- const { gasPrice } = payload
8
- return gasPrice ? gasPrice / 1_000_000_000 : undefined
9
- }
10
-
11
- const getFeePerGas = (payload: EthereumGasEthersPayload): Partial<FeePerGas> => {
12
- const { maxFeePerGas } = payload
13
- const high = maxFeePerGas ? maxFeePerGas / 1_000_000_000 : undefined
14
- return { high }
15
- }
16
-
17
- const getPriorityFeePerGas = (payload: EthereumGasEthersPayload): Partial<PriorityFeePerGas> => {
18
- const { maxPriorityFeePerGas } = payload
19
- const high = maxPriorityFeePerGas ? maxPriorityFeePerGas / 1_000_000_000 : undefined
20
- return { high }
21
- }
22
-
23
- export const transformGasFromEthers = (payload: EthereumGasEthersPayload): FeeData => {
24
- const baseFee = getBaseFee(payload)
25
- const feePerGas = getFeePerGas(payload)
26
- const priorityFeePerGas = getPriorityFeePerGas(payload)
27
- return {
28
- baseFee, feePerGas, priorityFeePerGas,
29
- }
30
- }
@@ -1,34 +0,0 @@
1
- import type { EthereumGasEtherscanPayload } from '@xyo-network/etherscan-ethereum-gas-payload-plugin'
2
- import type { FeeData, FeePerGas } from '@xyo-network/gas-price-payload-plugin'
3
- import regression from 'regression'
4
-
5
- const getBaseFee = (payload: EthereumGasEtherscanPayload): number | undefined => {
6
- const { suggestBaseFee } = payload.result
7
- return Number.parseFloat(suggestBaseFee)
8
- }
9
-
10
- const getFeePerGas = (payload: EthereumGasEtherscanPayload): Partial<FeePerGas> => {
11
- const {
12
- FastGasPrice, ProposeGasPrice, SafeGasPrice,
13
- } = payload.result
14
- const low = Number.parseFloat(SafeGasPrice)
15
- const medium = Number.parseFloat(ProposeGasPrice)
16
- const high = Number.parseFloat(FastGasPrice)
17
- const veryHigh = regression.linear([
18
- [0, low],
19
- [1, medium],
20
- [2, high],
21
- ]).predict(3)[1]
22
- return {
23
- high, low, medium, veryHigh,
24
- }
25
- }
26
-
27
- export const transformGasFromEtherscan = (payload: EthereumGasEtherscanPayload): FeeData => {
28
- const baseFee = getBaseFee(payload)
29
- const feePerGas = getFeePerGas(payload)
30
- const priorityFeePerGas = {}
31
- return {
32
- baseFee, feePerGas, priorityFeePerGas,
33
- }
34
- }
@@ -1,49 +0,0 @@
1
- import type { EthereumGasEthgasstationPayload } from '@xyo-network/ethgasstation-ethereum-gas-payload-plugin'
2
- import type {
3
- FeeData, FeePerGas, PriorityFeePerGas,
4
- } from '@xyo-network/gas-price-payload-plugin'
5
- import regression from 'regression'
6
-
7
- const getBaseFee = (payload: EthereumGasEthgasstationPayload): number | undefined => {
8
- const { baseFee } = payload
9
- return baseFee
10
- }
11
-
12
- const getFeePerGas = (payload: EthereumGasEthgasstationPayload): Partial<FeePerGas> => {
13
- const {
14
- standard: medium, fast: high, instant: veryHigh,
15
- } = payload.gasPrice
16
- const trend = regression.linear([
17
- [1, medium],
18
- [2, high],
19
- [3, veryHigh],
20
- ])
21
- const low = trend.predict(0)[1]
22
- return {
23
- low, medium, high, veryHigh,
24
- }
25
- }
26
-
27
- const getPriorityFeePerGas = (payload: EthereumGasEthgasstationPayload): Partial<PriorityFeePerGas> => {
28
- const {
29
- standard: medium, fast: high, instant: veryHigh,
30
- } = payload.priorityFee
31
- const trend = regression.linear([
32
- [1, medium],
33
- [2, high],
34
- [3, veryHigh],
35
- ])
36
- const low = trend.predict(0)[1]
37
- return {
38
- low, medium, high, veryHigh,
39
- }
40
- }
41
-
42
- export const transformGasFromEthgasstation = (payload: EthereumGasEthgasstationPayload): FeeData => {
43
- const baseFee = getBaseFee(payload)
44
- const feePerGas = getFeePerGas(payload)
45
- const priorityFeePerGas = getPriorityFeePerGas(payload)
46
- return {
47
- baseFee, feePerGas, priorityFeePerGas,
48
- }
49
- }
package/src/test/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './sampleBlocknativeGas.ts'
2
- export * from './sampleEtherchainGasV2.ts'
3
- export * from './sampleEtherscanGas.ts'
4
- export * from './sampleEthersGas.ts'
5
- export * from './sampleEthgasstationGas.ts'
@@ -1,94 +0,0 @@
1
- import type { EstimatedBaseFee, EthereumGasBlocknativePayload } from '@xyo-network/blocknative-ethereum-gas-payload-plugin'
2
- import { EthereumGasBlocknativeSchema } from '@xyo-network/blocknative-ethereum-gas-payload-plugin'
3
-
4
- export const sampleBlocknativeGas: EthereumGasBlocknativePayload = {
5
- blockPrices: [
6
- {
7
- baseFeePerGas: 13.691_764_456,
8
- blockNumber: 16_028_191,
9
- estimatedPrices: [
10
- {
11
- confidence: 99,
12
- maxFeePerGas: 22.04,
13
- maxPriorityFeePerGas: 1.09,
14
- price: 14,
15
- },
16
- {
17
- confidence: 95,
18
- maxFeePerGas: 21.58,
19
- maxPriorityFeePerGas: 0.63,
20
- price: 14,
21
- },
22
- {
23
- confidence: 90,
24
- maxFeePerGas: 21.25,
25
- maxPriorityFeePerGas: 0.3,
26
- price: 13,
27
- },
28
- {
29
- confidence: 80,
30
- maxFeePerGas: 21.16,
31
- maxPriorityFeePerGas: 0.21,
32
- price: 13,
33
- },
34
- {
35
- confidence: 70,
36
- maxFeePerGas: 21.12,
37
- maxPriorityFeePerGas: 0.17,
38
- price: 13,
39
- },
40
- ],
41
- estimatedTransactionCount: 69,
42
- },
43
- ],
44
- currentBlockNumber: 16_028_190,
45
- estimatedBaseFees: [
46
- {
47
- 'pending+1': [
48
- {
49
- baseFee: 15.41,
50
- confidence: 99,
51
- },
52
- ],
53
- },
54
- {
55
- 'pending+2': [
56
- {
57
- baseFee: 17.32,
58
- confidence: 99,
59
- },
60
- ],
61
- },
62
- {
63
- 'pending+3': [
64
- {
65
- baseFee: 19.17,
66
- confidence: 99,
67
- },
68
- ],
69
- },
70
- {
71
- 'pending+4': [
72
- {
73
- baseFee: 20.12,
74
- confidence: 99,
75
- },
76
- ],
77
- },
78
- {
79
- 'pending+5': [
80
- {
81
- baseFee: 20.95,
82
- confidence: 99,
83
- },
84
- ],
85
- },
86
- ] as unknown as EstimatedBaseFee[],
87
- maxPrice: 36,
88
- msSinceLastBlock: 3643,
89
- network: 'main',
90
- schema: EthereumGasBlocknativeSchema,
91
- system: 'ethereum',
92
- timestamp: 1_668_697_958_837,
93
- unit: 'gwei',
94
- }
@@ -1,16 +0,0 @@
1
- import type { EthereumGasEtherchainV2Payload } from '@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins'
2
- import { EthereumGasEtherchainV2Schema } from '@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins'
3
-
4
- export const sampleEtherchainGasV2: EthereumGasEtherchainV2Payload = {
5
- code: 200,
6
- data: {
7
- fast: 19_803_047_330,
8
- priceUSD: 1195.77,
9
- rapid: 29_714_286_170,
10
- slow: 11_200_000_000,
11
- standard: 12_000_000_000,
12
- timestamp: 1_668_621_234_096,
13
- },
14
- schema: EthereumGasEtherchainV2Schema,
15
- timestamp: 1_668_621_240_790,
16
- }
@@ -1,10 +0,0 @@
1
- import type { EthereumGasEthersPayload } from '@xyo-network/ethers-ethereum-gas-payload-plugin'
2
- import { EthereumGasEthersSchema } from '@xyo-network/ethers-ethereum-gas-payload-plugin'
3
-
4
- export const sampleEthersGas: EthereumGasEthersPayload = {
5
- gasPrice: 13_547_863_640,
6
- maxFeePerGas: 28_395_724_162,
7
- maxPriorityFeePerGas: 1_500_000_000,
8
- schema: EthereumGasEthersSchema,
9
- timestamp: 1_668_697_958_837,
10
- }
@@ -1,17 +0,0 @@
1
- import type { EthereumGasEtherscanPayload } from '@xyo-network/etherscan-ethereum-gas-payload-plugin'
2
- import { EthereumGasEtherscanSchema } from '@xyo-network/etherscan-ethereum-gas-payload-plugin'
3
-
4
- export const sampleEtherscanGas: EthereumGasEtherscanPayload = {
5
- message: 'OK',
6
- result: {
7
- FastGasPrice: '30',
8
- LastBlock: '15990556',
9
- ProposeGasPrice: '29',
10
- SafeGasPrice: '28',
11
- gasUsedRatio: '0.416266666666667,0.5672862,0.540979033333333,0.342410966666667,0.389071233333333',
12
- suggestBaseFee: '27.616709247',
13
- },
14
- schema: EthereumGasEtherscanSchema,
15
- status: '1',
16
- timestamp: 1_668_697_958_837,
17
- }
@@ -1,21 +0,0 @@
1
- import type { EthereumGasEthgasstationPayload } from '@xyo-network/ethgasstation-ethereum-gas-payload-plugin'
2
- import { EthereumGasEthgasstationSchema } from '@xyo-network/ethgasstation-ethereum-gas-payload-plugin'
3
-
4
- export const sampleEthgasstationGas: EthereumGasEthgasstationPayload = {
5
- baseFee: 10,
6
- blockNumber: 16_028_883,
7
- blockTime: 11.88,
8
- gasPrice: {
9
- fast: 12,
10
- instant: 13,
11
- standard: 12,
12
- },
13
- nextBaseFee: 10,
14
- priorityFee: {
15
- fast: 2,
16
- instant: 2,
17
- standard: 2,
18
- },
19
- schema: EthereumGasEthgasstationSchema,
20
- timestamp: 1_668_697_958_837,
21
- }