Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added metadata to monorepo, and also updated it reference into other package.json #1501

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ jobs:
tasks/npm-publish.sh packages/ethereum-contracts/ dev --verbose
tasks/npm-publish.sh packages/sdk-core/ dev --verbose
tasks/npm-publish.sh packages/sdk-redux/ dev --verbose
tasks/npm-publish.sh packages/metadata/ dev --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPMJS_TOKEN: ${{ secrets.NPMJS_TOKEN }}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"lint:shellcheck": "tasks/shellcheck-all-tasks.sh",
"lint:workspaces": "yarn workspaces run lint",
"build": "yarn build-essentials #synonym of build-essentials",
"build-essentials": "set -e;for i in ethereum-contracts js-sdk sdk-core sdk-redux;do yarn workspace @superfluid-finance/$i build;done",
"build-for-contracts-dev": "set -e;for i in ethereum-contracts js-sdk;do yarn workspace @superfluid-finance/$i build;done",
"build-essentials": "set -e;for i in metadata ethereum-contracts js-sdk sdk-core sdk-redux;do yarn workspace @superfluid-finance/$i build;done",
"build-for-contracts-dev": "set -e;for i in metadata ethereum-contracts js-sdk;do yarn workspace @superfluid-finance/$i build;done",
"clean": "rm -rf node_modules; rm -rf packages/*/node_modules; yarn workspace @superfluid-finance/ethereum-contracts clean",
"test": "set -e;for i in ethereum-contracts;do yarn workspace @superfluid-finance/$i test;done",
"manage-versions": "lerna version --exact --no-git-tag-version --preid rc",
Expand Down Expand Up @@ -75,6 +75,7 @@
"packages": [
"packages/solidity-semantic-money",
"packages/ethereum-contracts",
"packages/metadata",
"packages/js-sdk",
"packages/sdk-core",
"packages/sdk-redux",
Expand Down
2 changes: 1 addition & 1 deletion packages/automation-contracts/autowrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dotenv": "^16.0.3"
},
"dependencies": {
"@superfluid-finance/metadata": "git+https://github.com/superfluid-finance/metadata.git",
"@superfluid-finance/metadata": "1.1.7",
"hardhat": "^2.12.4",
"hardhat-deploy": "^0.11.22"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/automation-contracts/scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dotenv": "^16.0.3"
},
"dependencies": {
"@superfluid-finance/metadata": "git+https://github.com/superfluid-finance/metadata.git",
"@superfluid-finance/metadata": "1.1.7",
"hardhat": "^2.12.4",
"hardhat-deploy": "^0.11.22"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
},
"devDependencies": {
"@nomiclabs/hardhat-truffle5": "^2.0.7",
"@superfluid-finance/metadata": "git+https://github.com/superfluid-finance/metadata.git",
"@superfluid-finance/metadata": "1.1.7",
"async": "^3.2.4",
"csv-writer": "^1.6.0",
"ganache-time-traveler": "1.0.16",
Expand Down
2 changes: 1 addition & 1 deletion packages/js-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"cloc": "sh tasks/cloc.sh"
},
"dependencies": {
"@superfluid-finance/metadata": "git+https://github.com/superfluid-finance/metadata.git",
"@superfluid-finance/metadata": "1.1.7",
"@truffle/contract": "4.5.23",
"auto-bind": "^4.0.0",
"node-fetch": "^2.6.7"
Expand Down
3 changes: 3 additions & 0 deletions packages/metadata/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/abi.js
dist
build
14 changes: 14 additions & 0 deletions packages/metadata/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"env": {
"browser": true,
"es6": true
},
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
}
}
1 change: 1 addition & 0 deletions packages/metadata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
137 changes: 137 additions & 0 deletions packages/metadata/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Superfluid Metadata

Contains metadata around the Superfluid framework.
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.

## Making Changes

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.
If you are adding a new property, please also modify the .d.ts files in the module folder accordingly as well.

## Networks

List of EVM networks with the Superfluid protocol deployed.
Example uses

### Use in an HTML page

This example uses the jsDelivr CDN in order to always reference the latest version of the networks list.
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.

```html
<script type="module">
import networks from "https://cdn.jsdelivr.net/gh/superfluid-finance/metadata/module/networks/index.js";
// example use
const network = networks.getNetworkByChainId(networkId);
```

### Use in a nodejs project using ES modules

Nodejs has stable support for ES modules since version 14.
In order to switch a project to using ES modules by default, the package.json needs to contain a field
```json
"type": "module"
```
(for other ways to enable ES modules, see [the nodejs docs](https://nodejs.org/api/esm.html#enabling))

If that's the case, you can use the networks metadata like this:
```js
import sfMeta from "@superfluid-finance/metadata";

// example use
const network = sfMeta.getNetworkByName("eth-goerli");
```

### Use in a nodejs project using CommonJS (legacy)

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):
```js
import("@superfluid-finance/metadata").then(module => {
const sfMeta = module;

// example use
const network = sfMeta.getNetworkByName("eth-goerli");
}
```

Alternative using await:
```js
const sfMetaPromise = import("@superfluid-finance/metadata");
(async () => {
const sfMeta = (await sfMetaPromise).default;

// example use
const network = sfMeta.getNetworkByName("eth-goerli");
}
```

### Use in a node REPL:

The repl uses CommonJS too, thus usage looks like this:

```js
let sfMeta
import("@superfluid-finance/metadata").then(module => sfMeta = module)
> sfMeta.networks.length
12
> sfMeta.testnets.length
7
> sfMeta.mainnets.length
5
> sfMeta.mainnets.filter(n => n.nativeTokenSymbol === "ETH").map(n => n.name)
[
'eth-goerli',
'optimism-goerli',
'arbitrum-goerli',
'optimism-mainnet',
'arbitrum-one'
]
> m.getNetworkByChainId(10)
{
name: 'optimism-mainnet',
isTestnet: false,
networkId: 10,
chainId: 10,
shortName: 'optimism',
nativeTokenSymbol: 'ETH',
contractsV1: {
resolver: '0x743B5f46BC86caF41bE4956d9275721E0531B186',
host: '0x567c4B141ED61923967cA25Ef4906C8781069a10',
governance: '0x0170FFCC75d178d426EBad5b1a31451d00Ddbd0D',
cfaV1: '0x204C6f131bb7F258b2Ea1593f5309911d8E458eD',
idaV1: '0xc4ce5118C3B20950ee288f086cb7FC166d222D4c',
superTokenFactory: '0x8276469A443D5C6B7146BED45e2abCaD3B6adad9',
superfluidLoader: '0x8E310ce29Ab7Fa2878944A65BB0eaF97B1853d40',
toga: '0xA3c8502187fD7a7118eAD59dc811281448946C8f'
},
startBlockV1: 4300000,
logsQueryRange: 50000,
explorer: 'https://optimistic.etherscan.io',
subgraphV1: {
name: 'protocol-v1-optimism-mainnet',
hostedEndpoint: 'https://api.thegraph.com/subgraphs/name/superfluid-finance/protocol-v1-optimism-mainnet'
}
}
```

### Use in a bash script

With the help of [jq](https://jqlang.github.io/jq/), it's also possible to parse metadata from within a bash script.
Here's an example:

```sh
#!/bin/bash

# exit on error or undefined var
set -eu

metadata=$(curl -f -s "https://raw.githubusercontent.com/superfluid-finance/metadata/master/networks.json")
testnets=$(echo "$metadata" | jq -r '.[] | select(.isTestnet == false).name')

for network in $testnets; do
host=$(echo "$metadata" | jq -r '.[] | select(.name == "'$network'").contractsV1.host')
native_token_wrapper=$(echo "$metadata" | jq -r '.[] | select(.name == "'$network'").nativeTokenWrapper')

echo "$network | host address: $host, native token wrapper address: $native_token_wrapper"
done
```
19 changes: 19 additions & 0 deletions packages/metadata/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# This script builds the files in the main and module directories.

rm main/networks/list.cjs
rm module/networks/list.js

touch main/networks/list.cjs
touch module/networks/list.js

cat > main/networks/list.cjs <<EOF
/* eslint-disable */
module.exports =
EOF
cat > module/networks/list.js <<EOF
/* eslint-disable */
export default
EOF

cat networks.json | tee -a main/networks/list.cjs module/networks/list.js > /dev/null
26 changes: 26 additions & 0 deletions packages/metadata/compare-committed-against-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# This script checks that the built files are consistent with the committed files.

set -xe

# Hash a file using sha256sum and cut the hash from the output
function hashFiles() {
sha256sum $1 | cut -d ' ' -f 1
}

# Hash the commited files
main_list_committed_hash=$(hashFiles ./main/networks/list.cjs)
module_list_committed_hash=$(hashFiles ./module/networks/list.js)

# Build the files
./build.sh

# Hash the built files
main_list_built_hash=$(hashFiles './main/networks/list.cjs')
module_list_built_hash=$(hashFiles './module/networks/list.js')

# Compare the hashes and exit if they are not equal
if [ "$main_list_committed_hash" != "$main_list_built_hash" ] || [ "$module_list_committed_hash" != "$module_list_built_hash" ]; then
echo "The built files are not consistent with the committed files. Please run ./build.sh and commit the changes."
exit 1
fi
5 changes: 5 additions & 0 deletions packages/metadata/main/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const networks = require("./networks/index.cjs");

module.exports = {
...networks,
};
21 changes: 21 additions & 0 deletions packages/metadata/main/networks/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const nl = require("./list.cjs");

module.exports = {
networks: nl,

mainnets: nl.filter((e) => !e.isTestnet),

testnets: nl.filter((e) => e.isTestnet),

getNetworkByChainId: function (chainId) {
return this.networks.filter((n) => n.chainId === chainId)[0];
},

getNetworkByName: function (name) {
return this.networks.filter((n) => n.name === name)[0];
},

getNetworkByShortName: function (shortName) {
return this.networks.filter((n) => n.shortName === shortName)[0];
},
};
Loading