Skip to content

Commit

Permalink
update deps; add prettier; run esllint and prettier (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmosites authored Mar 29, 2023
1 parent aea7f14 commit 4242841
Show file tree
Hide file tree
Showing 26 changed files with 976 additions and 739 deletions.
8 changes: 4 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coverage/
build/
node_modules/
venv/
generated/
generated/
build/
src/prices/
legacy/v2/
29 changes: 29 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"modules": true
}
},
"env": {
"es6": true,
"node": true
},
"plugins": ["prettier", "@typescript-eslint"],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"@typescript-eslint/explicit-member-accessibility": 1,
"@typescript-eslint/member-ordering": 1,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/ban-types": "off"
}
}
35 changes: 0 additions & 35 deletions .eslintrc.js

This file was deleted.

5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
generated/
build/
src/prices/
legacy/v2/
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 80,
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"bracketSpacing": true,
"trailingComma": "es5"
}
86 changes: 21 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,21 @@
# AirSwap Subgraph

AirSwap subgraph for [The Graph](https://thegraph.com/).
Latest is deployed at [3xdURMor7NCcFs1g1Ff7JjnASQcgDyGsGY3Ba5n8VRDL](https://thegraph.com/explorer/subgraphs/3xdURMor7NCcFs1g1Ff7JjnASQcgDyGsGY3Ba5n8VRDL)

**Quick Start**
Follow the official [quick start](https://thegraph.com/docs/en/cookbook/quick-start/) to develop, build, and deploy the subgraph.

**Subgraph Studio** - https://thegraph.com/explorer/subgraphs/3xdURMor7NCcFs1g1Ff7JjnASQcgDyGsGY3Ba5n8VRDL?view=Overview


# Get Started

## Build Graph

AirSwap is deployed to the following chains. Generate the `subgraph.yaml` manifest files for each chain using the commands below.

**Ethereum**

```
yarn prepare:ethereum
```

**BNB Chain**

```
yarn prepare:bnb
```

**Avalanche**

```
yarn prepare:avalanche
```

**Polygon**

```
yarn prepare:polygon
```
## Authorize, Generate and Deploy Code

After generating the subgraph.yaml file, authorize graph cli.
### Auth

```
graph auth --studio <deploy-key>
```

**Manifests**
Before running `codegen` a `subgraph.yaml` manifest needs to be generated. Each chain requires its own. Use the `prepare` script to prepare a manifest for a specific chain.

```
graph codegen
yarn prepare:[network]
```

Where `network` is `ethereum`, `bnb`, `avalanche`, or `polygon`.

### Build

```
graph build
```

### Deploy
```
graph deploy --studio airswap-v3
```

**Note:**
This subgraph uses the messari price library to get token prices in USD.

https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/prices
## Subgraph Documentation

<!-- AirSwap v3 Documentation can be found here -> https://hackmd.io/@6Vt_l5I0TP6t3O_awqTYkA/ryKJ5FIss -->

**Pricing**
This subgraph uses the [Messari Price Oracle](https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/prices) source code for asset pricing.

**Test 1**

Expand All @@ -79,6 +25,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
- Get the total daily AST transfer for Jan 18th, 2023, datetime is converted to unix timestamp.

**Query**

```
{
astDailySnapshots(where: {date: 1674000000}) {
Expand All @@ -90,6 +37,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
```

**Result**

```
{
"data": {
Expand All @@ -112,6 +60,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
- Get the total daily Swap volume for Jan 18th, 2023, datetime is converted to unix timestamp.

**Query**

```
{
dailySwapVolumes(where: {date: 1674000000}) {
Expand All @@ -123,6 +72,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
```

**Result**

```
{
"data": {
Expand All @@ -145,6 +95,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
- Get the total daily Swap fees for Jan 18th, 2023, datetime is converted to unix timestamp.

**Query**

```
{
feePerDays(where: {date: 1674000000}) {
Expand All @@ -156,6 +107,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
```

**Result**

```
{
"data": {
Expand All @@ -180,6 +132,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
- etherscan link: https://etherscan.io/tx/0xb1e3fd07c73aaeb0645c97dc291c8bb182d7edec4c8d08aabf8617a98e760a56

**Query**

```
{
swaps(
Expand Down Expand Up @@ -221,6 +174,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
```

**Result**

```
{
"data": {
Expand Down Expand Up @@ -263,7 +217,6 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
}
```


**Test 5**

**Users**
Expand All @@ -272,6 +225,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
- Get user balance and total AST transfer

**Query**

```
{
users(first: 3) {
Expand All @@ -283,6 +237,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
```

**Result**

```
{
"data": {
Expand Down Expand Up @@ -310,6 +265,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
- Get the first 3 users with total balance greater than **78000000**

**Query**

```
{
users(where: {tokenBalance_gt: "78000000"}, first: 3) {
Expand All @@ -321,6 +277,7 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
```

**Result**

```
{
"data": {
Expand All @@ -344,4 +301,3 @@ https://github.com/messari/subgraphs/tree/master/subgraphs/_reference_/src/price
}
}
```

28 changes: 15 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/subgraph-v3",
"version": "0.0.1",
"name": "@airswap/subgraph",
"version": "3.0.0",
"license": "MIT",
"private": true,
"scripts": {
Expand All @@ -14,25 +14,27 @@
"deploy:kovan": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ AirSwap/AirSwap-Kovan",
"deploy:goerli": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ AirSwap/AirSwap-Goerli",
"deploy:bnb": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ AirSwap/AirSwap-BNB",
"lint": "yarn eslint . --ext .js,.ts --fix",
"prepare:development": "mustache config/development.json subgraph.template.yaml > subgraph.yaml",
"prepare:ethereum": "mustache config/ethereum.json subgraph.template.yaml > subgraph.yaml",
"prepare:rinkeby": "mustache config/rinkeby.json subgraph.template.yaml > subgraph.yaml",
"prepare:kovan": "mustache config/kovan.json subgraph.template.yaml > subgraph.yaml",
"prepare:avalanche": "mustache config/avalanche.json subgraph.template.yaml > subgraph.yaml",
"prepare:polygon": "mustache config/polygon.json subgraph.template.yaml > subgraph.yaml",
"prepare:goerli": "mustache config/goerli.json subgraph.template.yaml > subgraph.yaml",
"prepare:bnb": "mustache config/bnb.json subgraph.template.yaml > subgraph.yaml"
"prepare:bnb": "mustache config/bnb.json subgraph.template.yaml > subgraph.yaml",
"pretty": "prettier --write \"./**/*.ts\""
},
"dependencies": {
"@graphprotocol/graph-cli": "^0.33.0",
"@graphprotocol/graph-ts": "^0.27.0",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.45.1",
"eslint": "^8.32.0",
"mustache": "^3.1.0",
"typescript": "^4.8.4",
"eslint-config-prettier": "^8.5.0",
"devDependencies": {
"@graphprotocol/graph-cli": "^0.44.0",
"@graphprotocol/graph-ts": "^0.29.3",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1"
"mustache": "^3.1.0",
"prettier": "^2.8.7",
"typescript": "^4.8.4"
}
}
8 changes: 1 addition & 7 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type Transfer @entity {
tokens: BigInt! # uint256
}


# Swap
type User @entity {
id: ID! # wallet address
Expand All @@ -33,7 +32,6 @@ type User @entity {
totalTransfers: BigInt!
}


type SwapContract @entity {
id: ID! # address of the swap contract
}
Expand Down Expand Up @@ -87,7 +85,6 @@ type DailySwapVolume @entity {
amount: BigDecimal!
}


type FeePerDay @entity {
id: ID!
date: Int!
Expand Down Expand Up @@ -143,14 +140,12 @@ type PayeeRemoved @entity {
account: Bytes! # address
}


type AstDailySnapshot @entity {
id: ID!
date: Int!
dailyTotalTransfer: BigInt!
}


type TokenTransfer @entity {
id: ID! # tx-hash
_from: User! # address
Expand All @@ -168,7 +163,6 @@ type AddToken @entity(immutable: true) {
transactionHash: Bytes!
}


type RemoveToken @entity(immutable: true) {
id: Bytes!
account: Bytes! # address
Expand All @@ -183,4 +177,4 @@ type SwapProtocolVolume @entity {

# total volume
totalVolumeUSD: BigDecimal!
}
}
Loading

0 comments on commit 4242841

Please sign in to comment.