@superfluid-finance/metadata 1.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/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ src/abi.js
2
+ dist
3
+ build
package/.eslintrc.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es6": true
5
+ },
6
+ "globals": {
7
+ "Atomics": "readonly",
8
+ "SharedArrayBuffer": "readonly"
9
+ },
10
+ "parserOptions": {
11
+ "ecmaVersion": 2018,
12
+ "sourceType": "module"
13
+ }
14
+ }
package/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # Superfluid Metadata
2
+
3
+ Contains metadata around the Superfluid framework.
4
+ The goal of this repository is to make it as easy as possible to reference contained metadata from various contexts (e.g. backend script or browser page) and independently of the tech stack used there. Convenience wrappers are provided for JS/TS, other environments can fall back to parsing plain JSON files.
5
+
6
+ ## Making Changes
7
+
8
+ When adding new changes (new addresses), add it to `networks.json` and make sure to run `./build.sh` before pushing so that both the list files in `main` and `module` are updated.
9
+ If you are adding a new property, please also modify the .d.ts files in the module folder accordingly as well.
10
+
11
+ ## Networks
12
+
13
+ List of EVM networks with the Superfluid protocol deployed.
14
+ Example uses
15
+
16
+ ### Use in an HTML page
17
+
18
+ This example uses the jsDelivr CDN in order to always reference the latest version of the networks list.
19
+ You can of course also self-host a copy or use another service, anything signalling the right mime type and with a compatible CORS policy should work.
20
+
21
+ ```html
22
+ <script type="module">
23
+ import networks from "https://cdn.jsdelivr.net/gh/superfluid-finance/metadata/module/networks/index.js";
24
+ // example use
25
+ const network = networks.getNetworkByChainId(networkId);
26
+ ```
27
+
28
+ ### Use in a nodejs project using ES modules
29
+
30
+ Nodejs has stable support for ES modules since version 14.
31
+ In order to switch a project to using ES modules by default, the package.json needs to contain a field
32
+ ```json
33
+ "type": "module"
34
+ ```
35
+ (for other ways to enable ES modules, see [the nodejs docs](https://nodejs.org/api/esm.html#enabling))
36
+
37
+ If that's the case, you can use the networks metadata like this:
38
+ ```js
39
+ import sfMeta from "@superfluid-finance/metadata";
40
+
41
+ // example use
42
+ const network = sfMeta.getNetworkByName("eth-goerli");
43
+ ```
44
+
45
+ ### Use in a nodejs project using CommonJS (legacy)
46
+
47
+ Nodejs projects still using CommonJS (if you're unsure, check [the docs](https://nodejs.org/api/packages.html#determining-module-system)), can use ES modules using the syntax of [dynamic imports](https://nodejs.org/api/esm.html#import-expressions):
48
+ ```js
49
+ import("@superfluid-finance/metadata").then(module => {
50
+ const sfMeta = module;
51
+
52
+ // example use
53
+ const network = sfMeta.getNetworkByName("eth-goerli");
54
+ }
55
+ ```
56
+
57
+ Alternative using await:
58
+ ```js
59
+ const sfMetaPromise = import("@superfluid-finance/metadata");
60
+ (async () => {
61
+ const sfMeta = (await sfMetaPromise).default;
62
+
63
+ // example use
64
+ const network = sfMeta.getNetworkByName("eth-goerli");
65
+ }
66
+ ```
67
+
68
+ ### Use in a node REPL:
69
+
70
+ The repl uses CommonJS too, thus usage looks like this:
71
+
72
+ ```js
73
+ let sfMeta
74
+ import("@superfluid-finance/metadata").then(module => sfMeta = module)
75
+ > sfMeta.networks.length
76
+ 12
77
+ > sfMeta.testnets.length
78
+ 7
79
+ > sfMeta.mainnets.length
80
+ 5
81
+ > sfMeta.mainnets.filter(n => n.nativeTokenSymbol === "ETH").map(n => n.name)
82
+ [
83
+ 'eth-goerli',
84
+ 'optimism-goerli',
85
+ 'arbitrum-goerli',
86
+ 'optimism-mainnet',
87
+ 'arbitrum-one'
88
+ ]
89
+ > m.getNetworkByChainId(10)
90
+ {
91
+ name: 'optimism-mainnet',
92
+ isTestnet: false,
93
+ networkId: 10,
94
+ chainId: 10,
95
+ shortName: 'optimism',
96
+ nativeTokenSymbol: 'ETH',
97
+ contractsV1: {
98
+ resolver: '0x743B5f46BC86caF41bE4956d9275721E0531B186',
99
+ host: '0x567c4B141ED61923967cA25Ef4906C8781069a10',
100
+ governance: '0x0170FFCC75d178d426EBad5b1a31451d00Ddbd0D',
101
+ cfaV1: '0x204C6f131bb7F258b2Ea1593f5309911d8E458eD',
102
+ idaV1: '0xc4ce5118C3B20950ee288f086cb7FC166d222D4c',
103
+ superTokenFactory: '0x8276469A443D5C6B7146BED45e2abCaD3B6adad9',
104
+ superfluidLoader: '0x8E310ce29Ab7Fa2878944A65BB0eaF97B1853d40',
105
+ toga: '0xA3c8502187fD7a7118eAD59dc811281448946C8f'
106
+ },
107
+ startBlockV1: 4300000,
108
+ logsQueryRange: 50000,
109
+ explorer: 'https://optimistic.etherscan.io',
110
+ subgraphV1: {
111
+ name: 'protocol-v1-optimism-mainnet',
112
+ hostedEndpoint: 'https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-v1-optimism-mainnet'
113
+ }
114
+ }
115
+ ```
116
+
117
+ ### Use in a bash script
118
+
119
+ With the help of [jq](https://jqlang.github.io/jq/), it's also possible to parse metadata from within a bash script.
120
+ Here's an example:
121
+
122
+ ```sh
123
+ #!/bin/bash
124
+
125
+ # exit on error or undefined var
126
+ set -eu
127
+
128
+ metadata=$(curl -f -s "https://raw.githubusercontent.com/superfluid-finance/metadata/master/networks.json")
129
+ testnets=$(echo "$metadata" | jq -r '.[] | select(.isTestnet == false).name')
130
+
131
+ for network in $testnets; do
132
+ host=$(echo "$metadata" | jq -r '.[] | select(.name == "'$network'").contractsV1.host')
133
+ native_token_wrapper=$(echo "$metadata" | jq -r '.[] | select(.name == "'$network'").nativeTokenWrapper')
134
+
135
+ echo "$network | host address: $host, native token wrapper address: $native_token_wrapper"
136
+ done
137
+ ```
package/build.sh ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env bash
2
+ # This script builds the files in the main and module directories.
3
+
4
+ rm main/networks/list.cjs
5
+ rm module/networks/list.js
6
+
7
+ touch main/networks/list.cjs
8
+ touch module/networks/list.js
9
+
10
+ cat > main/networks/list.cjs <<EOF
11
+ /* eslint-disable */
12
+ module.exports =
13
+ EOF
14
+ cat > module/networks/list.js <<EOF
15
+ /* eslint-disable */
16
+ export default
17
+ EOF
18
+
19
+ cat networks.json | tee -a main/networks/list.cjs module/networks/list.js > /dev/null
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+ # This script checks that the built files are consistent with the committed files.
3
+
4
+ set -xe
5
+
6
+ # Hash a file using sha256sum and cut the hash from the output
7
+ function hashFiles() {
8
+ sha256sum $1 | cut -d ' ' -f 1
9
+ }
10
+
11
+ # Hash the commited files
12
+ main_list_committed_hash=$(hashFiles ./main/networks/list.cjs)
13
+ module_list_committed_hash=$(hashFiles ./module/networks/list.js)
14
+
15
+ # Build the files
16
+ ./build.sh
17
+
18
+ # Hash the built files
19
+ main_list_built_hash=$(hashFiles './main/networks/list.cjs')
20
+ module_list_built_hash=$(hashFiles './module/networks/list.js')
21
+
22
+ # Compare the hashes and exit if they are not equal
23
+ if [ "$main_list_committed_hash" != "$main_list_built_hash" ] || [ "$module_list_committed_hash" != "$module_list_built_hash" ]; then
24
+ echo "The built files are not consistent with the committed files. Please run ./build.sh and commit the changes."
25
+ exit 1
26
+ fi
package/main/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ const networks = require("./networks/index.cjs");
2
+
3
+ module.exports = {
4
+ ...networks,
5
+ };
@@ -0,0 +1,21 @@
1
+ const nl = require("./list.cjs");
2
+
3
+ module.exports = {
4
+ networks: nl,
5
+
6
+ mainnets: nl.filter((e) => !e.isTestnet),
7
+
8
+ testnets: nl.filter((e) => e.isTestnet),
9
+
10
+ getNetworkByChainId: function (chainId) {
11
+ return this.networks.filter((n) => n.chainId === chainId)[0];
12
+ },
13
+
14
+ getNetworkByName: function (name) {
15
+ return this.networks.filter((n) => n.name === name)[0];
16
+ },
17
+
18
+ getNetworkByShortName: function (shortName) {
19
+ return this.networks.filter((n) => n.shortName === shortName)[0];
20
+ },
21
+ };