@xyo-network/gas-price-plugin 2.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +81 -0
- package/dist/cjs/Diviner.d.ts +16 -0
- package/dist/cjs/Diviner.d.ts.map +1 -0
- package/dist/cjs/Diviner.js +29 -0
- package/dist/cjs/Diviner.js.map +1 -0
- package/dist/cjs/Plugin.d.ts +13 -0
- package/dist/cjs/Plugin.d.ts.map +1 -0
- package/dist/cjs/Plugin.js +15 -0
- package/dist/cjs/Plugin.js.map +1 -0
- package/dist/cjs/Schema.d.ts +5 -0
- package/dist/cjs/Schema.d.ts.map +1 -0
- package/dist/cjs/Schema.js +6 -0
- package/dist/cjs/Schema.js.map +1 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/average.d.ts +8 -0
- package/dist/cjs/lib/average.d.ts.map +1 -0
- package/dist/cjs/lib/average.js +48 -0
- package/dist/cjs/lib/average.js.map +1 -0
- package/dist/cjs/lib/divineGas.d.ts +6 -0
- package/dist/cjs/lib/divineGas.d.ts.map +1 -0
- package/dist/cjs/lib/divineGas.js +23 -0
- package/dist/cjs/lib/divineGas.js.map +1 -0
- package/dist/cjs/lib/identities/index.d.ts +7 -0
- package/dist/cjs/lib/identities/index.d.ts.map +1 -0
- package/dist/cjs/lib/identities/index.js +10 -0
- package/dist/cjs/lib/identities/index.js.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasBlocknativePayload.d.ts +6 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasBlocknativePayload.d.ts.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasBlocknativePayload.js +9 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasBlocknativePayload.js.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherchainV1Payload.d.ts +6 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherchainV1Payload.d.ts.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherchainV1Payload.js +9 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherchainV1Payload.js.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherchainV2Payload.d.ts +6 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherchainV2Payload.d.ts.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherchainV2Payload.js +9 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherchainV2Payload.js.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEthersPayload.d.ts +6 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEthersPayload.d.ts.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEthersPayload.js +9 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEthersPayload.js.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherscanPayload.d.ts +6 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherscanPayload.d.ts.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherscanPayload.js +9 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEtherscanPayload.js.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEthgasstationPayload.d.ts +6 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEthgasstationPayload.d.ts.map +1 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEthgasstationPayload.js +9 -0
- package/dist/cjs/lib/identities/isXyoEthereumGasEthgasstationPayload.js.map +1 -0
- package/dist/cjs/lib/index.d.ts +2 -0
- package/dist/cjs/lib/index.d.ts.map +1 -0
- package/dist/cjs/lib/index.js +5 -0
- package/dist/cjs/lib/index.js.map +1 -0
- package/dist/cjs/lib/transforms/index.d.ts +7 -0
- package/dist/cjs/lib/transforms/index.d.ts.map +1 -0
- package/dist/cjs/lib/transforms/index.js +10 -0
- package/dist/cjs/lib/transforms/index.js.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromBlocknative.d.ts +4 -0
- package/dist/cjs/lib/transforms/transformGasFromBlocknative.d.ts.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromBlocknative.js +52 -0
- package/dist/cjs/lib/transforms/transformGasFromBlocknative.js.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherchainV1.d.ts +4 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherchainV1.d.ts.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherchainV1.js +23 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherchainV1.js.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherchainV2.d.ts +4 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherchainV2.d.ts.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherchainV2.js +19 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherchainV2.js.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEthers.d.ts +4 -0
- package/dist/cjs/lib/transforms/transformGasFromEthers.d.ts.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEthers.js +25 -0
- package/dist/cjs/lib/transforms/transformGasFromEthers.js.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherscan.d.ts +4 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherscan.d.ts.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherscan.js +28 -0
- package/dist/cjs/lib/transforms/transformGasFromEtherscan.js.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEthgasstation.d.ts +4 -0
- package/dist/cjs/lib/transforms/transformGasFromEthgasstation.d.ts.map +1 -0
- package/dist/cjs/lib/transforms/transformGasFromEthgasstation.js +36 -0
- package/dist/cjs/lib/transforms/transformGasFromEthgasstation.js.map +1 -0
- package/dist/cjs/test/index.d.ts +7 -0
- package/dist/cjs/test/index.d.ts.map +1 -0
- package/dist/cjs/test/index.js +10 -0
- package/dist/cjs/test/index.js.map +1 -0
- package/dist/cjs/test/sampleBlocknativeGas.d.ts +3 -0
- package/dist/cjs/test/sampleBlocknativeGas.d.ts.map +1 -0
- package/dist/cjs/test/sampleBlocknativeGas.js +96 -0
- package/dist/cjs/test/sampleBlocknativeGas.js.map +1 -0
- package/dist/cjs/test/sampleEtherchainGasV1.d.ts +3 -0
- package/dist/cjs/test/sampleEtherchainGasV1.d.ts.map +1 -0
- package/dist/cjs/test/sampleEtherchainGasV1.js +15 -0
- package/dist/cjs/test/sampleEtherchainGasV1.js.map +1 -0
- package/dist/cjs/test/sampleEtherchainGasV2.d.ts +3 -0
- package/dist/cjs/test/sampleEtherchainGasV2.d.ts.map +1 -0
- package/dist/cjs/test/sampleEtherchainGasV2.js +18 -0
- package/dist/cjs/test/sampleEtherchainGasV2.js.map +1 -0
- package/dist/cjs/test/sampleEthersGas.d.ts +3 -0
- package/dist/cjs/test/sampleEthersGas.d.ts.map +1 -0
- package/dist/cjs/test/sampleEthersGas.js +13 -0
- package/dist/cjs/test/sampleEthersGas.js.map +1 -0
- package/dist/cjs/test/sampleEtherscanGas.d.ts +3 -0
- package/dist/cjs/test/sampleEtherscanGas.d.ts.map +1 -0
- package/dist/cjs/test/sampleEtherscanGas.js +19 -0
- package/dist/cjs/test/sampleEtherscanGas.js.map +1 -0
- package/dist/cjs/test/sampleEthgasstationGas.d.ts +3 -0
- package/dist/cjs/test/sampleEthgasstationGas.d.ts.map +1 -0
- package/dist/cjs/test/sampleEthgasstationGas.js +23 -0
- package/dist/cjs/test/sampleEthgasstationGas.js.map +1 -0
- package/dist/docs.json +4534 -0
- package/dist/esm/Diviner.d.ts +16 -0
- package/dist/esm/Diviner.d.ts.map +1 -0
- package/dist/esm/Diviner.js +19 -0
- package/dist/esm/Diviner.js.map +1 -0
- package/dist/esm/Plugin.d.ts +13 -0
- package/dist/esm/Plugin.d.ts.map +1 -0
- package/dist/esm/Plugin.js +10 -0
- package/dist/esm/Plugin.js.map +1 -0
- package/dist/esm/Schema.d.ts +5 -0
- package/dist/esm/Schema.d.ts.map +1 -0
- package/dist/esm/Schema.js +3 -0
- package/dist/esm/Schema.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/average.d.ts +8 -0
- package/dist/esm/lib/average.d.ts.map +1 -0
- package/dist/esm/lib/average.js +44 -0
- package/dist/esm/lib/average.js.map +1 -0
- package/dist/esm/lib/divineGas.d.ts +6 -0
- package/dist/esm/lib/divineGas.d.ts.map +1 -0
- package/dist/esm/lib/divineGas.js +19 -0
- package/dist/esm/lib/divineGas.js.map +1 -0
- package/dist/esm/lib/identities/index.d.ts +7 -0
- package/dist/esm/lib/identities/index.d.ts.map +1 -0
- package/dist/esm/lib/identities/index.js +7 -0
- package/dist/esm/lib/identities/index.js.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasBlocknativePayload.d.ts +6 -0
- package/dist/esm/lib/identities/isXyoEthereumGasBlocknativePayload.d.ts.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasBlocknativePayload.js +5 -0
- package/dist/esm/lib/identities/isXyoEthereumGasBlocknativePayload.js.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherchainV1Payload.d.ts +6 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherchainV1Payload.d.ts.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherchainV1Payload.js +5 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherchainV1Payload.js.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherchainV2Payload.d.ts +6 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherchainV2Payload.d.ts.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherchainV2Payload.js +5 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherchainV2Payload.js.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEthersPayload.d.ts +6 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEthersPayload.d.ts.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEthersPayload.js +5 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEthersPayload.js.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherscanPayload.d.ts +6 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherscanPayload.d.ts.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherscanPayload.js +5 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEtherscanPayload.js.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEthgasstationPayload.d.ts +6 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEthgasstationPayload.d.ts.map +1 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEthgasstationPayload.js +5 -0
- package/dist/esm/lib/identities/isXyoEthereumGasEthgasstationPayload.js.map +1 -0
- package/dist/esm/lib/index.d.ts +2 -0
- package/dist/esm/lib/index.d.ts.map +1 -0
- package/dist/esm/lib/index.js +2 -0
- package/dist/esm/lib/index.js.map +1 -0
- package/dist/esm/lib/transforms/index.d.ts +7 -0
- package/dist/esm/lib/transforms/index.d.ts.map +1 -0
- package/dist/esm/lib/transforms/index.js +7 -0
- package/dist/esm/lib/transforms/index.js.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromBlocknative.d.ts +4 -0
- package/dist/esm/lib/transforms/transformGasFromBlocknative.d.ts.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromBlocknative.js +45 -0
- package/dist/esm/lib/transforms/transformGasFromBlocknative.js.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEtherchainV1.d.ts +4 -0
- package/dist/esm/lib/transforms/transformGasFromEtherchainV1.d.ts.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEtherchainV1.js +19 -0
- package/dist/esm/lib/transforms/transformGasFromEtherchainV1.js.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEtherchainV2.d.ts +4 -0
- package/dist/esm/lib/transforms/transformGasFromEtherchainV2.d.ts.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEtherchainV2.js +15 -0
- package/dist/esm/lib/transforms/transformGasFromEtherchainV2.js.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEthers.d.ts +4 -0
- package/dist/esm/lib/transforms/transformGasFromEthers.d.ts.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEthers.js +21 -0
- package/dist/esm/lib/transforms/transformGasFromEthers.js.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEtherscan.d.ts +4 -0
- package/dist/esm/lib/transforms/transformGasFromEtherscan.d.ts.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEtherscan.js +24 -0
- package/dist/esm/lib/transforms/transformGasFromEtherscan.js.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEthgasstation.d.ts +4 -0
- package/dist/esm/lib/transforms/transformGasFromEthgasstation.d.ts.map +1 -0
- package/dist/esm/lib/transforms/transformGasFromEthgasstation.js +32 -0
- package/dist/esm/lib/transforms/transformGasFromEthgasstation.js.map +1 -0
- package/dist/esm/test/index.d.ts +7 -0
- package/dist/esm/test/index.d.ts.map +1 -0
- package/dist/esm/test/index.js +7 -0
- package/dist/esm/test/index.js.map +1 -0
- package/dist/esm/test/sampleBlocknativeGas.d.ts +3 -0
- package/dist/esm/test/sampleBlocknativeGas.d.ts.map +1 -0
- package/dist/esm/test/sampleBlocknativeGas.js +93 -0
- package/dist/esm/test/sampleBlocknativeGas.js.map +1 -0
- package/dist/esm/test/sampleEtherchainGasV1.d.ts +3 -0
- package/dist/esm/test/sampleEtherchainGasV1.d.ts.map +1 -0
- package/dist/esm/test/sampleEtherchainGasV1.js +12 -0
- package/dist/esm/test/sampleEtherchainGasV1.js.map +1 -0
- package/dist/esm/test/sampleEtherchainGasV2.d.ts +3 -0
- package/dist/esm/test/sampleEtherchainGasV2.d.ts.map +1 -0
- package/dist/esm/test/sampleEtherchainGasV2.js +15 -0
- package/dist/esm/test/sampleEtherchainGasV2.js.map +1 -0
- package/dist/esm/test/sampleEthersGas.d.ts +3 -0
- package/dist/esm/test/sampleEthersGas.d.ts.map +1 -0
- package/dist/esm/test/sampleEthersGas.js +10 -0
- package/dist/esm/test/sampleEthersGas.js.map +1 -0
- package/dist/esm/test/sampleEtherscanGas.d.ts +3 -0
- package/dist/esm/test/sampleEtherscanGas.d.ts.map +1 -0
- package/dist/esm/test/sampleEtherscanGas.js +16 -0
- package/dist/esm/test/sampleEtherscanGas.js.map +1 -0
- package/dist/esm/test/sampleEthgasstationGas.d.ts +3 -0
- package/dist/esm/test/sampleEthgasstationGas.d.ts.map +1 -0
- package/dist/esm/test/sampleEthgasstationGas.js +20 -0
- package/dist/esm/test/sampleEthgasstationGas.js.map +1 -0
- package/package.json +87 -0
- package/src/Diviner.spec.ts +131 -0
- package/src/Diviner.ts +28 -0
- package/src/Plugin.spec.ts +11 -0
- package/src/Plugin.ts +16 -0
- package/src/Schema.ts +5 -0
- package/src/index.ts +9 -0
- package/src/lib/average.spec.ts +50 -0
- package/src/lib/average.ts +47 -0
- package/src/lib/divineGas.spec.ts +78 -0
- package/src/lib/divineGas.ts +34 -0
- package/src/lib/identities/index.ts +6 -0
- package/src/lib/identities/isXyoEthereumGasBlocknativePayload.spec.ts +29 -0
- package/src/lib/identities/isXyoEthereumGasBlocknativePayload.ts +6 -0
- package/src/lib/identities/isXyoEthereumGasEtherchainV1Payload.spec.ts +29 -0
- package/src/lib/identities/isXyoEthereumGasEtherchainV1Payload.ts +6 -0
- package/src/lib/identities/isXyoEthereumGasEtherchainV2Payload.spec.ts +29 -0
- package/src/lib/identities/isXyoEthereumGasEtherchainV2Payload.ts +6 -0
- package/src/lib/identities/isXyoEthereumGasEthersPayload.spec.ts +29 -0
- package/src/lib/identities/isXyoEthereumGasEthersPayload.ts +6 -0
- package/src/lib/identities/isXyoEthereumGasEtherscanPayload.spec.ts +29 -0
- package/src/lib/identities/isXyoEthereumGasEtherscanPayload.ts +6 -0
- package/src/lib/identities/isXyoEthereumGasEthgasstationPayload.spec.ts +29 -0
- package/src/lib/identities/isXyoEthereumGasEthgasstationPayload.ts +6 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/transforms/index.ts +6 -0
- package/src/lib/transforms/transformGasFromBlocknative.spec.ts +39 -0
- package/src/lib/transforms/transformGasFromBlocknative.ts +51 -0
- package/src/lib/transforms/transformGasFromEtherchainV1.spec.ts +34 -0
- package/src/lib/transforms/transformGasFromEtherchainV1.ts +23 -0
- package/src/lib/transforms/transformGasFromEtherchainV2.spec.ts +34 -0
- package/src/lib/transforms/transformGasFromEtherchainV2.ts +18 -0
- package/src/lib/transforms/transformGasFromEthers.spec.ts +33 -0
- package/src/lib/transforms/transformGasFromEthers.ts +26 -0
- package/src/lib/transforms/transformGasFromEtherscan.spec.ts +34 -0
- package/src/lib/transforms/transformGasFromEtherscan.ts +28 -0
- package/src/lib/transforms/transformGasFromEthgasstation.spec.ts +39 -0
- package/src/lib/transforms/transformGasFromEthgasstation.ts +38 -0
- package/src/test/index.ts +6 -0
- package/src/test/sampleBlocknativeGas.ts +97 -0
- package/src/test/sampleEtherchainGasV1.ts +12 -0
- package/src/test/sampleEtherchainGasV2.ts +15 -0
- package/src/test/sampleEthersGas.ts +10 -0
- package/src/test/sampleEtherscanGas.ts +16 -0
- package/src/test/sampleEthgasstationGas.ts +20 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PayloadSetPluginResolver } from '@xyo-network/payloadset-plugin'
|
|
2
|
+
|
|
3
|
+
import { XyoEthereumGasPlugin } from './Plugin'
|
|
4
|
+
|
|
5
|
+
describe('XyoCryptoMarketCoinGeckoPlugin', () => {
|
|
6
|
+
test('Add to Resolver', () => {
|
|
7
|
+
const plugin = XyoEthereumGasPlugin()
|
|
8
|
+
const resolver = new PayloadSetPluginResolver().register(plugin)
|
|
9
|
+
expect(resolver.resolve(plugin.set)).toBeDefined()
|
|
10
|
+
})
|
|
11
|
+
})
|
package/src/Plugin.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { XyoEthereumGasSchema } from '@xyo-network/gas-price-payload-plugin'
|
|
2
|
+
import { XyoModuleParams } from '@xyo-network/module'
|
|
3
|
+
import { PayloadSetSchema } from '@xyo-network/payload'
|
|
4
|
+
import { createPayloadSetPlugin, PayloadSetDivinerPlugin } from '@xyo-network/payloadset-plugin'
|
|
5
|
+
|
|
6
|
+
import { XyoEthereumGasDiviner, XyoEthereumGasDivinerConfig } from './Diviner'
|
|
7
|
+
|
|
8
|
+
export const XyoEthereumGasPlugin = () =>
|
|
9
|
+
createPayloadSetPlugin<PayloadSetDivinerPlugin<XyoModuleParams<XyoEthereumGasDivinerConfig>>>(
|
|
10
|
+
{ required: { [XyoEthereumGasSchema]: 1 }, schema: PayloadSetSchema },
|
|
11
|
+
{
|
|
12
|
+
diviner: async (params) => {
|
|
13
|
+
return await XyoEthereumGasDiviner.create(params)
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
)
|
package/src/Schema.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type XyoEthereumGasDivinerQuerySchema = 'network.xyo.blockchain.ethereum.gas.diviner.query'
|
|
2
|
+
export const XyoEthereumGasDivinerQuerySchema: XyoEthereumGasDivinerQuerySchema = 'network.xyo.blockchain.ethereum.gas.diviner.query'
|
|
3
|
+
|
|
4
|
+
export type XyoEthereumGasDivinerConfigSchema = 'network.xyo.blockchain.ethereum.gas.diviner.config'
|
|
5
|
+
export const XyoEthereumGasDivinerConfigSchema: XyoEthereumGasDivinerConfigSchema = 'network.xyo.blockchain.ethereum.gas.diviner.config'
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { FeeData } from '@xyo-network/gas-price-payload-plugin'
|
|
2
|
+
|
|
3
|
+
import { sampleEtherchainGasV1, sampleEtherchainGasV2, sampleEtherscanGas } from '../test'
|
|
4
|
+
import { average } from './average'
|
|
5
|
+
import { transformGasFromEtherchainV1, transformGasFromEtherchainV2, transformGasFromEtherscan } from './transforms'
|
|
6
|
+
|
|
7
|
+
const results: FeeData[] = [
|
|
8
|
+
transformGasFromEtherchainV1(sampleEtherchainGasV1),
|
|
9
|
+
transformGasFromEtherchainV2(sampleEtherchainGasV2),
|
|
10
|
+
transformGasFromEtherscan(sampleEtherscanGas),
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
describe('average', () => {
|
|
14
|
+
it('averages payloads', () => {
|
|
15
|
+
const payloads = results
|
|
16
|
+
const result = average(payloads)
|
|
17
|
+
expect(result).toBeObject()
|
|
18
|
+
expect(result.baseFee).toBeNumber()
|
|
19
|
+
expect(result.feePerGas).toBeObject()
|
|
20
|
+
expect(result.feePerGas.low).toBeNumber()
|
|
21
|
+
expect(result.feePerGas.medium).toBeNumber()
|
|
22
|
+
expect(result.feePerGas.high).toBeNumber()
|
|
23
|
+
expect(result.feePerGas.veryHigh).toBeNumber()
|
|
24
|
+
expect(result.priorityFeePerGas).toBeObject()
|
|
25
|
+
expect(result.priorityFeePerGas.low).toBeNumber()
|
|
26
|
+
expect(result.priorityFeePerGas.medium).toBeNumber()
|
|
27
|
+
expect(result.priorityFeePerGas.high).toBeNumber()
|
|
28
|
+
expect(result.priorityFeePerGas.veryHigh).toBeNumber()
|
|
29
|
+
})
|
|
30
|
+
it('handles single payload', () => {
|
|
31
|
+
const payloads = [results[0]]
|
|
32
|
+
const result = average(payloads)
|
|
33
|
+
expect(result).toBeObject()
|
|
34
|
+
})
|
|
35
|
+
it('handles no values', () => {
|
|
36
|
+
const result = average()
|
|
37
|
+
expect(result).toBeObject()
|
|
38
|
+
expect(result.baseFee).toBeUndefined()
|
|
39
|
+
expect(result.feePerGas).toBeObject()
|
|
40
|
+
expect(result.feePerGas.low).toBeUndefined()
|
|
41
|
+
expect(result.feePerGas.medium).toBeUndefined()
|
|
42
|
+
expect(result.feePerGas.high).toBeUndefined()
|
|
43
|
+
expect(result.feePerGas.veryHigh).toBeUndefined()
|
|
44
|
+
expect(result.priorityFeePerGas).toBeObject()
|
|
45
|
+
expect(result.priorityFeePerGas.low).toBeUndefined()
|
|
46
|
+
expect(result.priorityFeePerGas.medium).toBeUndefined()
|
|
47
|
+
expect(result.priorityFeePerGas.high).toBeUndefined()
|
|
48
|
+
expect(result.priorityFeePerGas.veryHigh).toBeUndefined()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { exists } from '@xylabs/exists'
|
|
2
|
+
import { 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
|
+
const listAverage = (x?: number[]) => (x?.length ? x.reduce((a, b) => a + b) / x.length : undefined)
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Averages the property indicates by the supplied property
|
|
14
|
+
* expression across the array of FeeData
|
|
15
|
+
* @param data The array of data to average
|
|
16
|
+
* @param propertyExpression The expression for the property to
|
|
17
|
+
* average
|
|
18
|
+
* @returns The average of the supplied property across the array
|
|
19
|
+
*/
|
|
20
|
+
const averageProperty = (data: FeeData[], propertyExpression: (x: FeeData) => number | undefined) => {
|
|
21
|
+
return listAverage(data.map(propertyExpression).filter(exists))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Averages the supplied FeeData
|
|
26
|
+
* @param input An array of FeeData or undefined
|
|
27
|
+
* @returns The average of the supplied FeeData
|
|
28
|
+
*/
|
|
29
|
+
export const average = (input?: (FeeData | undefined)[]): FeeData => {
|
|
30
|
+
const data = input?.filter(exists) || []
|
|
31
|
+
const averaged: FeeData = {
|
|
32
|
+
baseFee: averageProperty(data, (x) => x.baseFee),
|
|
33
|
+
feePerGas: {
|
|
34
|
+
high: averageProperty(data, (x) => x.feePerGas.high),
|
|
35
|
+
low: averageProperty(data, (x) => x.feePerGas.low),
|
|
36
|
+
medium: averageProperty(data, (x) => x.feePerGas.medium),
|
|
37
|
+
veryHigh: averageProperty(data, (x) => x.feePerGas.veryHigh),
|
|
38
|
+
},
|
|
39
|
+
priorityFeePerGas: {
|
|
40
|
+
high: averageProperty(data, (x) => x.priorityFeePerGas.high),
|
|
41
|
+
low: averageProperty(data, (x) => x.priorityFeePerGas.low),
|
|
42
|
+
medium: averageProperty(data, (x) => x.priorityFeePerGas.medium),
|
|
43
|
+
veryHigh: averageProperty(data, (x) => x.priorityFeePerGas.veryHigh),
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
return averaged
|
|
47
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sampleBlocknativeGas,
|
|
3
|
+
sampleEtherchainGasV1,
|
|
4
|
+
sampleEtherchainGasV2,
|
|
5
|
+
sampleEtherscanGas,
|
|
6
|
+
sampleEthersGas,
|
|
7
|
+
sampleEthgasstationGas,
|
|
8
|
+
} from '../test'
|
|
9
|
+
import { divineGas } from './divineGas'
|
|
10
|
+
|
|
11
|
+
describe('divineGas', () => {
|
|
12
|
+
describe('with no payloads supplied', () => {
|
|
13
|
+
it('divines gas', () => {
|
|
14
|
+
const result = divineGas([])
|
|
15
|
+
expect(result).toBeObject()
|
|
16
|
+
expect(result.timestamp).toBeNumber()
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
describe('with sparse payloads supplied', () => {
|
|
20
|
+
it.each([
|
|
21
|
+
[sampleEtherchainGasV1],
|
|
22
|
+
[sampleEtherchainGasV2],
|
|
23
|
+
[sampleEtherscanGas],
|
|
24
|
+
[sampleEtherchainGasV1, sampleEtherchainGasV2],
|
|
25
|
+
[sampleEtherchainGasV2, sampleEtherscanGas],
|
|
26
|
+
[sampleEtherchainGasV1, sampleEtherscanGas],
|
|
27
|
+
])('divines gas', (...payloads) => {
|
|
28
|
+
const result = divineGas(payloads)
|
|
29
|
+
expect(result).toBeObject()
|
|
30
|
+
expect(result.timestamp).toBeNumber()
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
describe('with one of each supported payload supplied', () => {
|
|
34
|
+
it('divines gas', () => {
|
|
35
|
+
const result = divineGas([
|
|
36
|
+
sampleBlocknativeGas,
|
|
37
|
+
sampleEtherchainGasV1,
|
|
38
|
+
sampleEtherchainGasV2,
|
|
39
|
+
sampleEtherscanGas,
|
|
40
|
+
sampleEthersGas,
|
|
41
|
+
sampleEthgasstationGas,
|
|
42
|
+
])
|
|
43
|
+
expect(result).toBeObject()
|
|
44
|
+
expect(result.baseFee).toBeNumber()
|
|
45
|
+
expect(result.feePerGas).toBeObject()
|
|
46
|
+
expect(result.feePerGas.low).toBeNumber()
|
|
47
|
+
expect(result.feePerGas.medium).toBeNumber()
|
|
48
|
+
expect(result.feePerGas.high).toBeNumber()
|
|
49
|
+
expect(result.feePerGas.veryHigh).toBeNumber()
|
|
50
|
+
expect(result.priorityFeePerGas).toBeObject()
|
|
51
|
+
expect(result.priorityFeePerGas.low).toBeNumber()
|
|
52
|
+
expect(result.priorityFeePerGas.medium).toBeNumber()
|
|
53
|
+
expect(result.priorityFeePerGas.high).toBeNumber()
|
|
54
|
+
expect(result.priorityFeePerGas.veryHigh).toBeNumber()
|
|
55
|
+
expect(result.timestamp).toBeNumber()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
describe('with multiple of each supported payload supplied', () => {
|
|
59
|
+
it('divines gas', () => {
|
|
60
|
+
const result = divineGas([
|
|
61
|
+
sampleBlocknativeGas,
|
|
62
|
+
sampleBlocknativeGas,
|
|
63
|
+
sampleEtherchainGasV1,
|
|
64
|
+
sampleEtherchainGasV1,
|
|
65
|
+
sampleEtherchainGasV2,
|
|
66
|
+
sampleEtherchainGasV2,
|
|
67
|
+
sampleEtherscanGas,
|
|
68
|
+
sampleEtherscanGas,
|
|
69
|
+
sampleEthersGas,
|
|
70
|
+
sampleEthersGas,
|
|
71
|
+
sampleEthgasstationGas,
|
|
72
|
+
sampleEthgasstationGas,
|
|
73
|
+
])
|
|
74
|
+
expect(result).toBeObject()
|
|
75
|
+
expect(result.timestamp).toBeNumber()
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FeeData, XyoEthereumGasPayload, XyoEthereumGasSchema } from '@xyo-network/gas-price-payload-plugin'
|
|
2
|
+
import { XyoPayloadBuilder, XyoPayloads } from '@xyo-network/payload'
|
|
3
|
+
|
|
4
|
+
import { average } from './average'
|
|
5
|
+
import {
|
|
6
|
+
isXyoEthereumGasBlocknativePayload,
|
|
7
|
+
isXyoEthereumGasEtherchainV1Payload,
|
|
8
|
+
isXyoEthereumGasEtherchainV2Payload,
|
|
9
|
+
isXyoEthereumGasEtherscanPayload,
|
|
10
|
+
isXyoEthereumGasEthersPayload,
|
|
11
|
+
isXyoEthereumGasEthgasstationPayload,
|
|
12
|
+
} from './identities'
|
|
13
|
+
import {
|
|
14
|
+
transformGasFromBlocknative,
|
|
15
|
+
transformGasFromEtherchainV1,
|
|
16
|
+
transformGasFromEtherchainV2,
|
|
17
|
+
transformGasFromEthers,
|
|
18
|
+
transformGasFromEtherscan,
|
|
19
|
+
transformGasFromEthgasstation,
|
|
20
|
+
} from './transforms'
|
|
21
|
+
|
|
22
|
+
export const divineGas = (payloads: XyoPayloads): XyoEthereumGasPayload => {
|
|
23
|
+
const blocknative = payloads.filter(isXyoEthereumGasBlocknativePayload).map(transformGasFromBlocknative)
|
|
24
|
+
const etherchainV1 = payloads.filter(isXyoEthereumGasEtherchainV1Payload).map(transformGasFromEtherchainV1)
|
|
25
|
+
const etherchainV2 = payloads.filter(isXyoEthereumGasEtherchainV2Payload).map(transformGasFromEtherchainV2)
|
|
26
|
+
const ethers = payloads.filter(isXyoEthereumGasEthersPayload).map(transformGasFromEthers)
|
|
27
|
+
const etherscan = payloads.filter(isXyoEthereumGasEtherscanPayload).map(transformGasFromEtherscan)
|
|
28
|
+
const ethgasstation = payloads.filter(isXyoEthereumGasEthgasstationPayload).map(transformGasFromEthgasstation)
|
|
29
|
+
const transactionCosts: FeeData[] = [...blocknative, ...etherchainV1, ...etherchainV2, ...ethers, ...etherscan, ...ethgasstation]
|
|
30
|
+
const avg = average(transactionCosts)
|
|
31
|
+
const timestamp = Date.now()
|
|
32
|
+
const payload = new XyoPayloadBuilder<XyoEthereumGasPayload>({ schema: XyoEthereumGasSchema }).fields({ ...avg, timestamp }).build()
|
|
33
|
+
return payload
|
|
34
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './isXyoEthereumGasBlocknativePayload'
|
|
2
|
+
export * from './isXyoEthereumGasEtherchainV1Payload'
|
|
3
|
+
export * from './isXyoEthereumGasEtherchainV2Payload'
|
|
4
|
+
export * from './isXyoEthereumGasEtherscanPayload'
|
|
5
|
+
export * from './isXyoEthereumGasEthersPayload'
|
|
6
|
+
export * from './isXyoEthereumGasEthgasstationPayload'
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sampleBlocknativeGas } from '../../test'
|
|
2
|
+
import { isXyoEthereumGasBlocknativePayload } from './isXyoEthereumGasBlocknativePayload'
|
|
3
|
+
|
|
4
|
+
describe('isXyoEthereumGasBlocknativePayload', () => {
|
|
5
|
+
describe('returns true', () => {
|
|
6
|
+
it('when payload schema is XyoEthereumGasBlocknativeSchema', () => {
|
|
7
|
+
const result = isXyoEthereumGasBlocknativePayload(sampleBlocknativeGas)
|
|
8
|
+
expect(result).toBeTrue()
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
describe('returns false', () => {
|
|
12
|
+
it('when payload schema is not XyoEthereumGasBlocknativeSchema', () => {
|
|
13
|
+
const result = isXyoEthereumGasBlocknativePayload({ schema: 'network.xyo.debug' })
|
|
14
|
+
expect(result).toBeFalse()
|
|
15
|
+
})
|
|
16
|
+
it('when payload is missing', () => {
|
|
17
|
+
const result = isXyoEthereumGasBlocknativePayload()
|
|
18
|
+
expect(result).toBeFalse()
|
|
19
|
+
})
|
|
20
|
+
it('when payload is undefined', () => {
|
|
21
|
+
const result = isXyoEthereumGasBlocknativePayload(undefined)
|
|
22
|
+
expect(result).toBeFalse()
|
|
23
|
+
})
|
|
24
|
+
it('when payload is null', () => {
|
|
25
|
+
const result = isXyoEthereumGasBlocknativePayload(null)
|
|
26
|
+
expect(result).toBeFalse()
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { XyoEthereumGasBlocknativePayload, XyoEthereumGasBlocknativeSchema } from '@xyo-network/blocknative-ethereum-gas-payload-plugin'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
|
|
4
|
+
export const isXyoEthereumGasBlocknativePayload = (payload?: XyoPayload | null): payload is XyoEthereumGasBlocknativePayload => {
|
|
5
|
+
return payload?.schema === XyoEthereumGasBlocknativeSchema
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sampleEtherchainGasV1 } from '../../test'
|
|
2
|
+
import { isXyoEthereumGasEtherchainV1Payload } from './isXyoEthereumGasEtherchainV1Payload'
|
|
3
|
+
|
|
4
|
+
describe('isXyoEthereumGasEtherchainV1Payload', () => {
|
|
5
|
+
describe('returns true', () => {
|
|
6
|
+
it('when payload schema is XyoEthereumGasEtherchainV1Schema', () => {
|
|
7
|
+
const result = isXyoEthereumGasEtherchainV1Payload(sampleEtherchainGasV1)
|
|
8
|
+
expect(result).toBeTrue()
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
describe('returns false', () => {
|
|
12
|
+
it('when payload schema is not XyoEthereumGasEtherscanSchema', () => {
|
|
13
|
+
const result = isXyoEthereumGasEtherchainV1Payload({ schema: 'network.xyo.debug' })
|
|
14
|
+
expect(result).toBeFalse()
|
|
15
|
+
})
|
|
16
|
+
it('when payload is missing', () => {
|
|
17
|
+
const result = isXyoEthereumGasEtherchainV1Payload()
|
|
18
|
+
expect(result).toBeFalse()
|
|
19
|
+
})
|
|
20
|
+
it('when payload is undefined', () => {
|
|
21
|
+
const result = isXyoEthereumGasEtherchainV1Payload(undefined)
|
|
22
|
+
expect(result).toBeFalse()
|
|
23
|
+
})
|
|
24
|
+
it('when payload is null', () => {
|
|
25
|
+
const result = isXyoEthereumGasEtherchainV1Payload(null)
|
|
26
|
+
expect(result).toBeFalse()
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { XyoEthereumGasEtherchainV1Payload, XyoEthereumGasEtherchainV1Schema } from '@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
|
|
4
|
+
export const isXyoEthereumGasEtherchainV1Payload = (payload?: XyoPayload | null): payload is XyoEthereumGasEtherchainV1Payload => {
|
|
5
|
+
return payload?.schema === XyoEthereumGasEtherchainV1Schema
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sampleEtherchainGasV2 } from '../../test'
|
|
2
|
+
import { isXyoEthereumGasEtherchainV2Payload } from './isXyoEthereumGasEtherchainV2Payload'
|
|
3
|
+
|
|
4
|
+
describe('isXyoEthereumGasEtherchainV2Payload', () => {
|
|
5
|
+
describe('returns true', () => {
|
|
6
|
+
it('when payload schema is XyoEthereumGasEtherchainV2Schema', () => {
|
|
7
|
+
const result = isXyoEthereumGasEtherchainV2Payload(sampleEtherchainGasV2)
|
|
8
|
+
expect(result).toBeTrue()
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
describe('returns false', () => {
|
|
12
|
+
it('when payload schema is not XyoEthereumGasEtherscanSchema', () => {
|
|
13
|
+
const result = isXyoEthereumGasEtherchainV2Payload({ schema: 'network.xyo.debug' })
|
|
14
|
+
expect(result).toBeFalse()
|
|
15
|
+
})
|
|
16
|
+
it('when payload is missing', () => {
|
|
17
|
+
const result = isXyoEthereumGasEtherchainV2Payload()
|
|
18
|
+
expect(result).toBeFalse()
|
|
19
|
+
})
|
|
20
|
+
it('when payload is undefined', () => {
|
|
21
|
+
const result = isXyoEthereumGasEtherchainV2Payload(undefined)
|
|
22
|
+
expect(result).toBeFalse()
|
|
23
|
+
})
|
|
24
|
+
it('when payload is null', () => {
|
|
25
|
+
const result = isXyoEthereumGasEtherchainV2Payload(null)
|
|
26
|
+
expect(result).toBeFalse()
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { XyoEthereumGasEtherchainV2Payload, XyoEthereumGasEtherchainV2Schema } from '@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
|
|
4
|
+
export const isXyoEthereumGasEtherchainV2Payload = (payload?: XyoPayload | null): payload is XyoEthereumGasEtherchainV2Payload => {
|
|
5
|
+
return payload?.schema === XyoEthereumGasEtherchainV2Schema
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sampleEthersGas } from '../../test'
|
|
2
|
+
import { isXyoEthereumGasEthersPayload } from './isXyoEthereumGasEthersPayload'
|
|
3
|
+
|
|
4
|
+
describe('isXyoEthereumGasEthersPayload', () => {
|
|
5
|
+
describe('returns true', () => {
|
|
6
|
+
it('when payload schema is XyoEthereumGasEthersSchema', () => {
|
|
7
|
+
const result = isXyoEthereumGasEthersPayload(sampleEthersGas)
|
|
8
|
+
expect(result).toBeTrue()
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
describe('returns false', () => {
|
|
12
|
+
it('when payload schema is not XyoEthereumGasEthersSchema', () => {
|
|
13
|
+
const result = isXyoEthereumGasEthersPayload({ schema: 'network.xyo.debug' })
|
|
14
|
+
expect(result).toBeFalse()
|
|
15
|
+
})
|
|
16
|
+
it('when payload is missing', () => {
|
|
17
|
+
const result = isXyoEthereumGasEthersPayload()
|
|
18
|
+
expect(result).toBeFalse()
|
|
19
|
+
})
|
|
20
|
+
it('when payload is undefined', () => {
|
|
21
|
+
const result = isXyoEthereumGasEthersPayload(undefined)
|
|
22
|
+
expect(result).toBeFalse()
|
|
23
|
+
})
|
|
24
|
+
it('when payload is null', () => {
|
|
25
|
+
const result = isXyoEthereumGasEthersPayload(null)
|
|
26
|
+
expect(result).toBeFalse()
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { XyoEthereumGasEthersPayload, XyoEthereumGasEthersSchema } from '@xyo-network/ethers-ethereum-gas-payload-plugin'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
|
|
4
|
+
export const isXyoEthereumGasEthersPayload = (payload?: XyoPayload | null): payload is XyoEthereumGasEthersPayload => {
|
|
5
|
+
return payload?.schema === XyoEthereumGasEthersSchema
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sampleEtherscanGas } from '../../test'
|
|
2
|
+
import { isXyoEthereumGasEtherscanPayload } from './isXyoEthereumGasEtherscanPayload'
|
|
3
|
+
|
|
4
|
+
describe('isXyoEthereumGasEtherscanPayload', () => {
|
|
5
|
+
describe('returns true', () => {
|
|
6
|
+
it('when payload schema is XyoEthereumGasEtherscanSchema', () => {
|
|
7
|
+
const result = isXyoEthereumGasEtherscanPayload(sampleEtherscanGas)
|
|
8
|
+
expect(result).toBeTrue()
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
describe('returns false', () => {
|
|
12
|
+
it('when payload schema is not XyoEthereumGasEtherscanSchema', () => {
|
|
13
|
+
const result = isXyoEthereumGasEtherscanPayload({ schema: 'network.xyo.debug' })
|
|
14
|
+
expect(result).toBeFalse()
|
|
15
|
+
})
|
|
16
|
+
it('when payload is missing', () => {
|
|
17
|
+
const result = isXyoEthereumGasEtherscanPayload()
|
|
18
|
+
expect(result).toBeFalse()
|
|
19
|
+
})
|
|
20
|
+
it('when payload is undefined', () => {
|
|
21
|
+
const result = isXyoEthereumGasEtherscanPayload(undefined)
|
|
22
|
+
expect(result).toBeFalse()
|
|
23
|
+
})
|
|
24
|
+
it('when payload is null', () => {
|
|
25
|
+
const result = isXyoEthereumGasEtherscanPayload(null)
|
|
26
|
+
expect(result).toBeFalse()
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { XyoEthereumGasEtherscanPayload, XyoEthereumGasEtherscanSchema } from '@xyo-network/etherscan-ethereum-gas-payload-plugin'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
|
|
4
|
+
export const isXyoEthereumGasEtherscanPayload = (payload?: XyoPayload | null): payload is XyoEthereumGasEtherscanPayload => {
|
|
5
|
+
return payload?.schema === XyoEthereumGasEtherscanSchema
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sampleEthgasstationGas } from '../../test'
|
|
2
|
+
import { isXyoEthereumGasEthgasstationPayload } from './isXyoEthereumGasEthgasstationPayload'
|
|
3
|
+
|
|
4
|
+
describe('isXyoEthereumGasEthgasstationPayload', () => {
|
|
5
|
+
describe('returns true', () => {
|
|
6
|
+
it('when payload schema is XyoEthereumGasEthgasstationSchema', () => {
|
|
7
|
+
const result = isXyoEthereumGasEthgasstationPayload(sampleEthgasstationGas)
|
|
8
|
+
expect(result).toBeTrue()
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
describe('returns false', () => {
|
|
12
|
+
it('when payload schema is not XyoEthereumGasEthgasstationSchema', () => {
|
|
13
|
+
const result = isXyoEthereumGasEthgasstationPayload({ schema: 'network.xyo.debug' })
|
|
14
|
+
expect(result).toBeFalse()
|
|
15
|
+
})
|
|
16
|
+
it('when payload is missing', () => {
|
|
17
|
+
const result = isXyoEthereumGasEthgasstationPayload()
|
|
18
|
+
expect(result).toBeFalse()
|
|
19
|
+
})
|
|
20
|
+
it('when payload is undefined', () => {
|
|
21
|
+
const result = isXyoEthereumGasEthgasstationPayload(undefined)
|
|
22
|
+
expect(result).toBeFalse()
|
|
23
|
+
})
|
|
24
|
+
it('when payload is null', () => {
|
|
25
|
+
const result = isXyoEthereumGasEthgasstationPayload(null)
|
|
26
|
+
expect(result).toBeFalse()
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { XyoEthereumGasEthgasstationPayload, XyoEthereumGasEthgasstationSchema } from '@xyo-network/ethgasstation-ethereum-gas-payload-plugin'
|
|
2
|
+
import { XyoPayload } from '@xyo-network/payload'
|
|
3
|
+
|
|
4
|
+
export const isXyoEthereumGasEthgasstationPayload = (payload?: XyoPayload | null): payload is XyoEthereumGasEthgasstationPayload => {
|
|
5
|
+
return payload?.schema === XyoEthereumGasEthgasstationSchema
|
|
6
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './divineGas'
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './transformGasFromBlocknative'
|
|
2
|
+
export * from './transformGasFromEtherchainV1'
|
|
3
|
+
export * from './transformGasFromEtherchainV2'
|
|
4
|
+
export * from './transformGasFromEthers'
|
|
5
|
+
export * from './transformGasFromEtherscan'
|
|
6
|
+
export * from './transformGasFromEthgasstation'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
2
|
+
import { sampleBlocknativeGas } from '../../test'
|
|
3
|
+
import { transformGasFromBlocknative } from './transformGasFromBlocknative'
|
|
4
|
+
|
|
5
|
+
describe('transformGasFromEtherscan', () => {
|
|
6
|
+
it('returns values in the expected format', () => {
|
|
7
|
+
const result = transformGasFromBlocknative(sampleBlocknativeGas)
|
|
8
|
+
expect(result).toBeObject()
|
|
9
|
+
expect(result.baseFee).toBeNumber()
|
|
10
|
+
expect(result.feePerGas).toBeObject()
|
|
11
|
+
expect(result.feePerGas.low).toBeNumber()
|
|
12
|
+
expect(result.feePerGas.medium).toBeNumber()
|
|
13
|
+
expect(result.feePerGas.high).toBeNumber()
|
|
14
|
+
expect(result.feePerGas.veryHigh).toBeNumber()
|
|
15
|
+
expect(result.priorityFeePerGas).toBeObject()
|
|
16
|
+
expect(result.priorityFeePerGas.low).toBeNumber()
|
|
17
|
+
expect(result.priorityFeePerGas.medium).toBeNumber()
|
|
18
|
+
expect(result.priorityFeePerGas.high).toBeNumber()
|
|
19
|
+
expect(result.priorityFeePerGas.veryHigh).toBeNumber()
|
|
20
|
+
})
|
|
21
|
+
it('matches expected output', () => {
|
|
22
|
+
const result = transformGasFromBlocknative(sampleBlocknativeGas)
|
|
23
|
+
expect(result).toMatchObject({
|
|
24
|
+
baseFee: 13.691764456,
|
|
25
|
+
feePerGas: {
|
|
26
|
+
low: 12.95,
|
|
27
|
+
medium: 13.25,
|
|
28
|
+
high: 13.55,
|
|
29
|
+
veryHigh: 13.85,
|
|
30
|
+
},
|
|
31
|
+
priorityFeePerGas: {
|
|
32
|
+
low: 0.14,
|
|
33
|
+
medium: 0.37,
|
|
34
|
+
high: 0.6,
|
|
35
|
+
veryHigh: 0.83,
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
2
|
+
import { XyoEthereumGasBlocknativePayload } from '@xyo-network/blocknative-ethereum-gas-payload-plugin'
|
|
3
|
+
import { FeeData, FeePerGas, PriorityFeePerGas } from '@xyo-network/gas-price-payload-plugin'
|
|
4
|
+
import { linear } from 'regression'
|
|
5
|
+
|
|
6
|
+
const getBaseFee = (payload: XyoEthereumGasBlocknativePayload): number | undefined => {
|
|
7
|
+
return payload?.blockPrices?.[0]?.baseFeePerGas
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const getFeePerGas = (payload: XyoEthereumGasBlocknativePayload): Partial<FeePerGas> => {
|
|
11
|
+
const sorted = payload.blockPrices?.[0].estimatedPrices?.sort((a, b) => a.confidence - b.confidence)
|
|
12
|
+
const trend = linear([
|
|
13
|
+
[0, sorted?.[0].price],
|
|
14
|
+
[1, sorted?.[1].price],
|
|
15
|
+
[2, sorted?.[2].price],
|
|
16
|
+
[3, sorted?.[3].price],
|
|
17
|
+
[4, sorted?.[4].price],
|
|
18
|
+
])
|
|
19
|
+
const feePerGas: FeePerGas = {
|
|
20
|
+
low: trend.predict(0.5)[1],
|
|
21
|
+
medium: trend.predict(1.5)[1],
|
|
22
|
+
high: trend.predict(2.5)[1],
|
|
23
|
+
veryHigh: trend.predict(3.5)[1],
|
|
24
|
+
}
|
|
25
|
+
return feePerGas
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const getPriorityFeePerGas = (payload: XyoEthereumGasBlocknativePayload): Partial<PriorityFeePerGas> => {
|
|
29
|
+
const sorted = payload.blockPrices?.[0].estimatedPrices?.sort((a, b) => a.confidence - b.confidence)
|
|
30
|
+
const trend = linear([
|
|
31
|
+
[0, sorted?.[0].maxPriorityFeePerGas],
|
|
32
|
+
[1, sorted?.[1].maxPriorityFeePerGas],
|
|
33
|
+
[2, sorted?.[2].maxPriorityFeePerGas],
|
|
34
|
+
[3, sorted?.[3].maxPriorityFeePerGas],
|
|
35
|
+
[4, sorted?.[4].maxPriorityFeePerGas],
|
|
36
|
+
])
|
|
37
|
+
const priorityFeePerGas: PriorityFeePerGas = {
|
|
38
|
+
low: trend.predict(0.5)[1],
|
|
39
|
+
medium: trend.predict(1.5)[1],
|
|
40
|
+
high: trend.predict(2.5)[1],
|
|
41
|
+
veryHigh: trend.predict(3.5)[1],
|
|
42
|
+
}
|
|
43
|
+
return priorityFeePerGas
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const transformGasFromBlocknative = (payload: XyoEthereumGasBlocknativePayload): FeeData => {
|
|
47
|
+
const baseFee = getBaseFee(payload)
|
|
48
|
+
const feePerGas = getFeePerGas(payload)
|
|
49
|
+
const priorityFeePerGas = getPriorityFeePerGas(payload)
|
|
50
|
+
return { baseFee, feePerGas, priorityFeePerGas }
|
|
51
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
2
|
+
import { sampleEtherchainGasV1 } from '../../test'
|
|
3
|
+
import { transformGasFromEtherchainV1 } from './transformGasFromEtherchainV1'
|
|
4
|
+
|
|
5
|
+
describe('transformGasFromEtherchainV1', () => {
|
|
6
|
+
it('returns values in the expected format', () => {
|
|
7
|
+
const result = transformGasFromEtherchainV1(sampleEtherchainGasV1)
|
|
8
|
+
expect(result).toBeObject()
|
|
9
|
+
expect(result.baseFee).toBeNumber()
|
|
10
|
+
expect(result.feePerGas).toBeObject()
|
|
11
|
+
expect(result.feePerGas.low).toBeUndefined()
|
|
12
|
+
expect(result.feePerGas.medium).toBeUndefined()
|
|
13
|
+
expect(result.feePerGas.high).toBeUndefined()
|
|
14
|
+
expect(result.feePerGas.veryHigh).toBeUndefined()
|
|
15
|
+
expect(result.priorityFeePerGas).toBeObject()
|
|
16
|
+
expect(result.priorityFeePerGas.low).toBeNumber()
|
|
17
|
+
expect(result.priorityFeePerGas.medium).toBeNumber()
|
|
18
|
+
expect(result.priorityFeePerGas.high).toBeNumber()
|
|
19
|
+
expect(result.priorityFeePerGas.veryHigh).toBeNumber()
|
|
20
|
+
})
|
|
21
|
+
it('matches expected output', () => {
|
|
22
|
+
const result = transformGasFromEtherchainV1(sampleEtherchainGasV1)
|
|
23
|
+
expect(result).toMatchObject({
|
|
24
|
+
baseFee: 19.5,
|
|
25
|
+
feePerGas: {},
|
|
26
|
+
priorityFeePerGas: {
|
|
27
|
+
low: 0.1,
|
|
28
|
+
medium: 0.2,
|
|
29
|
+
high: 0.3,
|
|
30
|
+
veryHigh: 1.5,
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { XyoEthereumGasEtherchainV1Payload } from '@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins'
|
|
2
|
+
import { FeeData, PriorityFeePerGas } from '@xyo-network/gas-price-payload-plugin'
|
|
3
|
+
|
|
4
|
+
const getBaseFee = (payload: XyoEthereumGasEtherchainV1Payload): number | undefined => {
|
|
5
|
+
const { currentBaseFee } = payload
|
|
6
|
+
return currentBaseFee
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const getPriorityFeePerGas = (payload: XyoEthereumGasEtherchainV1Payload): Partial<PriorityFeePerGas> => {
|
|
10
|
+
const { fast, fastest, safeLow, standard } = payload
|
|
11
|
+
const low = safeLow
|
|
12
|
+
const medium = standard
|
|
13
|
+
const high = fast
|
|
14
|
+
const veryHigh = fastest
|
|
15
|
+
return { high, low, medium, veryHigh }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const transformGasFromEtherchainV1 = (payload: XyoEthereumGasEtherchainV1Payload): FeeData => {
|
|
19
|
+
const baseFee = getBaseFee(payload)
|
|
20
|
+
const feePerGas = {}
|
|
21
|
+
const priorityFeePerGas = getPriorityFeePerGas(payload)
|
|
22
|
+
return { baseFee, feePerGas, priorityFeePerGas }
|
|
23
|
+
}
|