@xyo-network/crypto-asset-plugin 5.1.3 → 5.1.4
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/package.json +19 -16
- package/dist/neutral/lib/spec/averaege.spec.d.ts +0 -2
- package/dist/neutral/lib/spec/averaege.spec.d.ts.map +0 -1
- package/dist/neutral/lib/spec/divineCoinGeckoPrices.spec.d.ts +0 -2
- package/dist/neutral/lib/spec/divineCoinGeckoPrices.spec.d.ts.map +0 -1
- package/dist/neutral/lib/spec/divinePrices.spec.d.ts +0 -2
- package/dist/neutral/lib/spec/divinePrices.spec.d.ts.map +0 -1
- package/dist/neutral/lib/spec/divineUniswapPrices.spec.d.ts +0 -2
- package/dist/neutral/lib/spec/divineUniswapPrices.spec.d.ts.map +0 -1
- package/dist/neutral/spec/Diviner.spec.d.ts +0 -2
- package/dist/neutral/spec/Diviner.spec.d.ts.map +0 -1
- package/dist/neutral/spec/Plugin.spec.d.ts +0 -2
- package/dist/neutral/spec/Plugin.spec.d.ts.map +0 -1
- package/src/lib/spec/averaege.spec.ts +0 -37
- package/src/lib/spec/divineCoinGeckoPrices.spec.ts +0 -36
- package/src/lib/spec/divinePrices.spec.ts +0 -21
- package/src/lib/spec/divineUniswapPrices.spec.ts +0 -20
- package/src/spec/Diviner.spec.ts +0 -39
- package/src/spec/Plugin.spec.ts +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/crypto-asset-plugin",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.4",
|
|
4
4
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -30,25 +30,28 @@
|
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"files": [
|
|
32
32
|
"dist",
|
|
33
|
-
"src"
|
|
33
|
+
"src",
|
|
34
|
+
"!**/*.bench.*",
|
|
35
|
+
"!**/*.spec.*",
|
|
36
|
+
"!**/*.test.*"
|
|
34
37
|
],
|
|
35
38
|
"dependencies": {
|
|
36
|
-
"@xylabs/assert": "~5.0.
|
|
37
|
-
"@xylabs/exists": "~5.0.
|
|
38
|
-
"@xyo-network/coingecko-crypto-market-payload-plugin": "~5.1.
|
|
39
|
-
"@xyo-network/crypto-asset-payload-plugin": "~5.1.
|
|
40
|
-
"@xyo-network/diviner-abstract": "~5.1.
|
|
41
|
-
"@xyo-network/diviner-model": "~5.1.
|
|
42
|
-
"@xyo-network/module-model": "~5.1.
|
|
43
|
-
"@xyo-network/payload-builder": "~5.1.
|
|
44
|
-
"@xyo-network/payload-model": "~5.1.
|
|
45
|
-
"@xyo-network/payloadset-plugin": "~5.1.
|
|
46
|
-
"@xyo-network/uniswap-crypto-market-payload-plugin": "~5.1.
|
|
39
|
+
"@xylabs/assert": "~5.0.33",
|
|
40
|
+
"@xylabs/exists": "~5.0.33",
|
|
41
|
+
"@xyo-network/coingecko-crypto-market-payload-plugin": "~5.1.4",
|
|
42
|
+
"@xyo-network/crypto-asset-payload-plugin": "~5.1.4",
|
|
43
|
+
"@xyo-network/diviner-abstract": "~5.1.23",
|
|
44
|
+
"@xyo-network/diviner-model": "~5.1.23",
|
|
45
|
+
"@xyo-network/module-model": "~5.1.23",
|
|
46
|
+
"@xyo-network/payload-builder": "~5.1.23",
|
|
47
|
+
"@xyo-network/payload-model": "~5.1.23",
|
|
48
|
+
"@xyo-network/payloadset-plugin": "~5.1.23",
|
|
49
|
+
"@xyo-network/uniswap-crypto-market-payload-plugin": "~5.1.4"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
|
-
"@xylabs/ts-scripts-yarn3": "~7.
|
|
50
|
-
"@xylabs/tsconfig": "~7.
|
|
51
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
52
|
+
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
53
|
+
"@xylabs/tsconfig": "~7.2.8",
|
|
54
|
+
"@xylabs/vitest-extended": "~5.0.33",
|
|
52
55
|
"typescript": "~5.9.2",
|
|
53
56
|
"vitest": "~3.2.4"
|
|
54
57
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"averaege.spec.d.ts","sourceRoot":"","sources":["../../../../src/lib/spec/averaege.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"divineCoinGeckoPrices.spec.d.ts","sourceRoot":"","sources":["../../../../src/lib/spec/divineCoinGeckoPrices.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"divinePrices.spec.d.ts","sourceRoot":"","sources":["../../../../src/lib/spec/divinePrices.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"divineUniswapPrices.spec.d.ts","sourceRoot":"","sources":["../../../../src/lib/spec/divineUniswapPrices.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Diviner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Plugin.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/Plugin.spec.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import type { AssetInfo, CryptoMarketAssetPayload } from '@xyo-network/crypto-asset-payload-plugin'
|
|
4
|
-
import { CryptoMarketAssetSchema } from '@xyo-network/crypto-asset-payload-plugin'
|
|
5
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
6
|
-
import {
|
|
7
|
-
describe, expect,
|
|
8
|
-
it,
|
|
9
|
-
} from 'vitest'
|
|
10
|
-
|
|
11
|
-
import { average } from '../average.ts'
|
|
12
|
-
|
|
13
|
-
const schema = CryptoMarketAssetSchema
|
|
14
|
-
|
|
15
|
-
const getPayloadWithPrice = (price: number): CryptoMarketAssetPayload => {
|
|
16
|
-
const assets: Record<string, AssetInfo> = { xyo: { value: { usd: price.toString() } } }
|
|
17
|
-
const timestamp = Date.now()
|
|
18
|
-
return new PayloadBuilder<CryptoMarketAssetPayload>({ schema }).fields({ assets, timestamp }).build()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe('average', () => {
|
|
22
|
-
it('averages numbers', async () => {
|
|
23
|
-
const payloads = await Promise.all([getPayloadWithPrice(1), getPayloadWithPrice(2), getPayloadWithPrice(3)])
|
|
24
|
-
expect(average(...payloads)?.xyo?.value?.usd).toBe('2')
|
|
25
|
-
})
|
|
26
|
-
it('handles single value', () => {
|
|
27
|
-
const payloads = getPayloadWithPrice(1)
|
|
28
|
-
expect(average(payloads)?.xyo?.value?.usd).toBe('1')
|
|
29
|
-
})
|
|
30
|
-
it('handles no values', () => {
|
|
31
|
-
expect(average()?.xyo?.value?.usd).toBeUndefined()
|
|
32
|
-
})
|
|
33
|
-
it('handles undefined values', async () => {
|
|
34
|
-
const payloads = await Promise.all([getPayloadWithPrice(1), undefined, getPayloadWithPrice(3)])
|
|
35
|
-
expect(average(...payloads)?.xyo?.value?.usd).toBe('2')
|
|
36
|
-
})
|
|
37
|
-
})
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import { assertEx } from '@xylabs/assert'
|
|
4
|
-
import {
|
|
5
|
-
describe, expect,
|
|
6
|
-
it,
|
|
7
|
-
} from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { sampleCoinGeckoPayload } from '../../test/index.ts'
|
|
10
|
-
import { divineCoinGeckoPrices } from '../divineCoinGeckoPrices.ts'
|
|
11
|
-
|
|
12
|
-
describe('divineCoinGeckoPrices', () => {
|
|
13
|
-
// eslint-disable-next-line complexity
|
|
14
|
-
it('divines prices from CoinGecko', () => {
|
|
15
|
-
const result = divineCoinGeckoPrices(sampleCoinGeckoPayload)
|
|
16
|
-
expect(result.assets).toBeObject()
|
|
17
|
-
const assets = assertEx(result.assets)
|
|
18
|
-
for (let [token, assetInfo] of Object.entries(assets)) {
|
|
19
|
-
expect(token).toBeString()
|
|
20
|
-
expect(assetInfo).toBeObject()
|
|
21
|
-
const value = assertEx(assetInfo?.value)
|
|
22
|
-
expect(value).toBeObject()
|
|
23
|
-
for (let [symbol, price] of Object.entries(value)) {
|
|
24
|
-
expect(symbol).toBeString()
|
|
25
|
-
expect(price).toBeString()
|
|
26
|
-
const parsed = Number.parseFloat(price)
|
|
27
|
-
expect(parsed).toBeNumber()
|
|
28
|
-
expect(Number.isNaN(parsed)).toBeFalse()
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
expect(result?.assets?.xyo?.value?.btc).toBe('6.28282e-7')
|
|
32
|
-
expect(result?.assets?.xyo?.value?.eth).toBe('0.00000885')
|
|
33
|
-
expect(result?.assets?.xyo?.value?.eur).toBe('0.01417995')
|
|
34
|
-
expect(result?.assets?.xyo?.value?.usd).toBe('0.01439307')
|
|
35
|
-
})
|
|
36
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
describe, expect,
|
|
5
|
-
it,
|
|
6
|
-
} from 'vitest'
|
|
7
|
-
|
|
8
|
-
import { sampleCoinGeckoPayload, sampleUniswapPayload } from '../../test/index.ts'
|
|
9
|
-
import { divinePrices } from '../divinePrices.ts'
|
|
10
|
-
|
|
11
|
-
describe('divinePrices', () => {
|
|
12
|
-
it('divines prices', () => {
|
|
13
|
-
const result = divinePrices(sampleCoinGeckoPayload, sampleUniswapPayload)
|
|
14
|
-
expect(result).toBeObject()
|
|
15
|
-
expect(result.timestamp).toBeNumber()
|
|
16
|
-
expect(result.assets.xyo?.value.btc).toBe('6.415295e-7')
|
|
17
|
-
expect(result.assets.xyo?.value.eth).toBe('0.000008908865')
|
|
18
|
-
expect(result.assets.xyo?.value.eur).toBe('0.01417995')
|
|
19
|
-
expect(result.assets.xyo?.value.usd).toBe('0.014635635000000001')
|
|
20
|
-
})
|
|
21
|
-
})
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
describe, expect,
|
|
5
|
-
it,
|
|
6
|
-
} from 'vitest'
|
|
7
|
-
|
|
8
|
-
import { sampleUniswapPayload } from '../../test/index.ts'
|
|
9
|
-
import { divineUniswapPrices } from '../divineUniswapPrices.ts'
|
|
10
|
-
|
|
11
|
-
describe('divineUniswapPrices', () => {
|
|
12
|
-
it('divines prices from Uniswap', () => {
|
|
13
|
-
const result = divineUniswapPrices(sampleUniswapPayload)
|
|
14
|
-
expect(result).toBeObject()
|
|
15
|
-
expect(result?.assets?.xyo?.value?.btc).toBe('6.54777e-7')
|
|
16
|
-
expect(result?.assets?.xyo?.value?.eth).toBe('0.00000896773')
|
|
17
|
-
expect(result?.assets?.xyo?.value?.eur).toBe(undefined)
|
|
18
|
-
expect(result?.assets?.xyo?.value?.usd).toBe('0.0148782')
|
|
19
|
-
})
|
|
20
|
-
})
|
package/src/spec/Diviner.spec.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import type { CryptoMarketAssetPayload } from '@xyo-network/crypto-asset-payload-plugin'
|
|
4
|
-
import { CryptoMarketAssetSchema } from '@xyo-network/crypto-asset-payload-plugin'
|
|
5
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
6
|
-
import {
|
|
7
|
-
describe, expect,
|
|
8
|
-
test,
|
|
9
|
-
} from 'vitest'
|
|
10
|
-
|
|
11
|
-
import { CryptoMarketAssetDiviner } from '../Diviner.ts'
|
|
12
|
-
import { sampleCoinGeckoPayload, sampleUniswapPayload } from '../test/index.ts'
|
|
13
|
-
|
|
14
|
-
const coinGeckoPayload = sampleCoinGeckoPayload
|
|
15
|
-
const uniswapPayload = sampleUniswapPayload
|
|
16
|
-
|
|
17
|
-
describe('Diviner', () => {
|
|
18
|
-
const cases: [input: string, expected: string, data: Payload[]][] = [
|
|
19
|
-
['only CoinGecko Payload', 'observation', [coinGeckoPayload]],
|
|
20
|
-
['only Uniswap Payload', 'observation', [uniswapPayload]],
|
|
21
|
-
['CoinGecko & Uniswap Payload', 'observation', [coinGeckoPayload, uniswapPayload]],
|
|
22
|
-
['no inputs', 'empty observation', []],
|
|
23
|
-
]
|
|
24
|
-
test.each(cases)('with %s returns %s', async (_input: string, _expected: string, data: Payload[]) => {
|
|
25
|
-
const diviner = await CryptoMarketAssetDiviner.create({ account: 'random' })
|
|
26
|
-
const payloads = await diviner.divine(data)
|
|
27
|
-
expect(payloads).toBeArray()
|
|
28
|
-
expect(payloads.length).toBe(1)
|
|
29
|
-
for (let payload of payloads) {
|
|
30
|
-
if (payload?.schema === CryptoMarketAssetSchema) {
|
|
31
|
-
const assetPayload = payload as CryptoMarketAssetPayload
|
|
32
|
-
expect(assetPayload).toBeObject()
|
|
33
|
-
expect(assetPayload?.assets).toBeObject()
|
|
34
|
-
expect(assetPayload?.schema).toBe(CryptoMarketAssetSchema)
|
|
35
|
-
expect(assetPayload?.timestamp).toBeNumber()
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
})
|
package/src/spec/Plugin.spec.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import '@xylabs/vitest-extended'
|
|
2
|
-
|
|
3
|
-
import { PayloadSetPluginResolver } from '@xyo-network/payloadset-plugin'
|
|
4
|
-
import {
|
|
5
|
-
describe, expect,
|
|
6
|
-
test,
|
|
7
|
-
} from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { CryptoMarketAssetPlugin } from '../Plugin.ts'
|
|
10
|
-
|
|
11
|
-
describe('CryptoMarketCoinGeckoPlugin', () => {
|
|
12
|
-
test('Add to Resolver', async () => {
|
|
13
|
-
const plugin = CryptoMarketAssetPlugin()
|
|
14
|
-
const resolver = await new PayloadSetPluginResolver().register(plugin)
|
|
15
|
-
expect(resolver.resolve(plugin.set)).toBeDefined()
|
|
16
|
-
})
|
|
17
|
-
})
|