@azuro-org/toolkit 0.1.5 → 0.1.7
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/README.md +96 -84
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,107 +10,119 @@ npm i --save @azuro-org/toolkit
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
## CLI
|
|
14
|
-
|
|
15
|
-
All dictionaries stored in [public repository](https://github.com/Azuro-protocol/public-config/tree/main/dictionaries).
|
|
16
|
-
For ease of use, the dictionaries have a version and file format.
|
|
17
|
-
|
|
18
|
-
It's easy to download dictionary files with CLI. In your package.json add script:
|
|
19
|
-
|
|
20
|
-
```json
|
|
21
|
-
"scripts": {
|
|
22
|
-
"get-dicts": "dictionaries -o {OUTPUT_DIR} -v {VERSION} -t {FILES_TYPE}"
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
- `VERSION` is the version of downloaded dictionaries. [Find the version you need here](https://github.com/Azuro-protocol/public-config/tree/main/dictionaries).
|
|
27
|
-
- `OUTPUT_DIR` is the directory where to put downloaded files.
|
|
28
|
-
- `FILES_TYPE` is the extension of downloaded files. Accepts `ts`, `js`, `maps`, `arrays`. `maps` and `arrays` are
|
|
29
|
-
json files with different output format.
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
dictionaries -o ./dist -v 2.0.0 -t ts # will download v2.0.0 typescript files to ./dist directory
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
|
|
36
13
|
## Helpers
|
|
37
14
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
15
|
+
### `aggregateOutcomesByMarkets.ts`
|
|
16
|
+
|
|
17
|
+
This helper function allows you to aggregate outcomes that are obtained from conditions by markets. This function takes
|
|
18
|
+
an array of conditions and groups outcomes by their market key. It then sorts the outcomes within each market group
|
|
19
|
+
and returns an array of market objects, each containing an array of outcomes.
|
|
20
|
+
|
|
21
|
+
Here is an example of how you can use it:
|
|
22
|
+
|
|
23
|
+
```graphql
|
|
24
|
+
query Game($id: String!) {
|
|
25
|
+
game(id: $id) {
|
|
26
|
+
liquidityPool {
|
|
27
|
+
address
|
|
28
|
+
}
|
|
29
|
+
conditions {
|
|
30
|
+
conditionId
|
|
31
|
+
coreAddress
|
|
32
|
+
outcomes {
|
|
33
|
+
outcomeId
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
50
38
|
```
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
import dictionaries from './path-to-downloaded-dictionaries'
|
|
40
|
+
```ts
|
|
41
|
+
type Conditions = {
|
|
42
|
+
conditionId: string
|
|
43
|
+
coreAddress: string
|
|
44
|
+
outcomes: {
|
|
45
|
+
outcomeId: string
|
|
46
|
+
}
|
|
47
|
+
}
|
|
62
48
|
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
aggregateOutcomesByMarkets({
|
|
50
|
+
lpAddress: game.liquidityPool.lpAddress,
|
|
51
|
+
conditions: game.conditions,
|
|
52
|
+
dictionaries, // **
|
|
53
|
+
})
|
|
65
54
|
```
|
|
66
55
|
|
|
67
|
-
|
|
56
|
+
The result will be of type
|
|
68
57
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
```ts
|
|
59
|
+
type Outcome = {
|
|
60
|
+
selectionName: string
|
|
61
|
+
conditionId: string
|
|
62
|
+
outcomeId: string
|
|
63
|
+
lpAddress: string
|
|
64
|
+
coreAddress: string
|
|
65
|
+
}
|
|
72
66
|
|
|
67
|
+
type OutcomesByMarkets = {
|
|
68
|
+
marketName: string
|
|
69
|
+
outcomes: Outcome[][] // *
|
|
70
|
+
}[]
|
|
73
71
|
```
|
|
74
|
-
import { getMarketKey, assembleMarketName } from '@azuro-org/dictionaries'
|
|
75
|
-
import dictionaries from './path-to-downloaded-dictionaries'
|
|
76
|
-
|
|
77
|
-
const outcomeId = 42
|
|
78
|
-
const marketKey = getMarketKey(outcomeId, dictionaries)
|
|
79
|
-
|
|
80
|
-
let marketName = dictionaries[marketKey] // undefined
|
|
81
72
|
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
`*` returned `outcomes` are wrapped with additional array `Outcome[][]`
|
|
74
|
+
|
|
75
|
+
`**` `dictionaries` contain a set of texts for each outcome ID used in Azuro. These texts can be used to display outcomes
|
|
76
|
+
in a user-friendly way and provide more context about what the outcome represents. Dictionaries are an important
|
|
77
|
+
component of Azuro's infrastructure as they allow for standardized and consistent outcomes across all markets and events.
|
|
78
|
+
[Read more about dictionaries](https://azuro-v2-docs.surge.sh/build-own-app/dive-deeper/dictionaries).
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
You can pass additional data in outcomes if required, the helper will add it to outcomes in the result:
|
|
83
|
+
|
|
84
|
+
```graphql {11}
|
|
85
|
+
query Game($id: String!) {
|
|
86
|
+
game(id: $id) {
|
|
87
|
+
...
|
|
88
|
+
conditions {
|
|
89
|
+
...
|
|
90
|
+
outcomes {
|
|
91
|
+
...
|
|
92
|
+
odds
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
84
96
|
}
|
|
85
97
|
```
|
|
86
98
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
getMarketName(1, dictionaries) // "Full Time Result"
|
|
94
|
-
getMarketName(42, dictionaries) // "Whole game - Winner of match Goal"
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
import { getMarketDescription } from '@azuro-org/dictionaries'
|
|
99
|
-
import dictionaries from './path-to-downloaded-dictionaries'
|
|
99
|
+
```ts
|
|
100
|
+
type MyOutcome = {
|
|
101
|
+
outcomeId: string
|
|
102
|
+
odds: string
|
|
103
|
+
}
|
|
100
104
|
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
aggregateOutcomesByMarkets<MyOutcome>({
|
|
106
|
+
lpAddress: game.liquidityPool.lpAddress,
|
|
107
|
+
conditions: game.conditions,
|
|
108
|
+
dictionaries, // ** check the note below
|
|
109
|
+
})
|
|
103
110
|
```
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
```js
|
|
108
|
-
import { assembleSelectionName } from '@azuro-org/dictionaries'
|
|
109
|
-
import dictionaries from './dist'
|
|
112
|
+
The result will be of type
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
```ts {7}
|
|
115
|
+
type Outcome = {
|
|
116
|
+
selectionName: string
|
|
117
|
+
conditionId: string
|
|
118
|
+
outcomeId: string
|
|
119
|
+
lpAddress: string
|
|
120
|
+
coreAddress: string
|
|
121
|
+
odds: string
|
|
122
|
+
}
|
|
113
123
|
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
type OutcomesByMarkets = {
|
|
125
|
+
marketName: string
|
|
126
|
+
outcomes: Outcome[][]
|
|
127
|
+
}[]
|
|
116
128
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azuro-org/toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Set of helpers to work with Azuro protocol",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/Azuro-protocol/toolkit/issues"
|
|
27
27
|
},
|
|
28
|
-
"homepage": "https://github.com/Azuro-protocol/toolkit
|
|
28
|
+
"homepage": "https://github.com/Azuro-protocol/toolkit#readme",
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@azuro-org/dictionaries": "^1.0.5"
|
|
31
31
|
},
|