-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from AcalaNetwork/added-homa-subql
added stats subql
- Loading branch information
Showing
25 changed files
with
515 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# These are some examples of commonly ignored file patterns. | ||
# You should customize this list as applicable to your project. | ||
# Learn more about .gitignore: | ||
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore | ||
|
||
# Node artifact files | ||
node_modules/ | ||
dist/ | ||
|
||
# lock files | ||
yarn.lock | ||
package-lock.json | ||
|
||
# Compiled Java class files | ||
*.class | ||
|
||
# Compiled Python bytecode | ||
*.py[cod] | ||
|
||
# Log files | ||
*.log | ||
|
||
# Package files | ||
*.jar | ||
|
||
# Generated files | ||
target/ | ||
dist/ | ||
src/types | ||
project.yaml | ||
|
||
# JetBrains IDE | ||
.idea/ | ||
|
||
# Unit test reports | ||
TEST*.xml | ||
|
||
# Generated by MacOS | ||
.DS_Store | ||
|
||
# Generated by Windows | ||
Thumbs.db | ||
|
||
# Applications | ||
*.app | ||
*.exe | ||
*.war | ||
|
||
# Large media files | ||
*.mp4 | ||
*.tiff | ||
*.avi | ||
*.flv | ||
*.mov | ||
*.wmv | ||
|
||
.data | ||
.yarn | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
QmR1bNNxccr9A8523Wq4WWgbDr7euY7jCBPq4gnAWuFv6N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Euphrates Subql | ||
Subql that indexes [Euphrates](https://farm.acala.network/) transactions. | ||
|
||
## Deploy | ||
publish to IPFS | ||
``` | ||
export SUBQL_ACCESS_TOKEN=<your token> | ||
subql publish | ||
``` |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
version: "3" | ||
|
||
services: | ||
postgres: | ||
image: postgres:12-alpine | ||
ports: | ||
- 5432:5432 | ||
environment: | ||
POSTGRES_PASSWORD: postgres | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
interval: 2s | ||
timeout: 5s | ||
retries: 100 | ||
|
||
subquery-node: | ||
image: onfinality/subql-node-ethereum:latest | ||
depends_on: | ||
"postgres": | ||
condition: service_healthy | ||
restart: always | ||
environment: | ||
DB_USER: postgres | ||
DB_PASS: postgres | ||
DB_DATABASE: postgres | ||
DB_HOST: postgres | ||
DB_PORT: 5432 | ||
volumes: | ||
- ./:/app | ||
command: | ||
- -f=ipfs://QmR1bNNxccr9A8523Wq4WWgbDr7euY7jCBPq4gnAWuFv6N | ||
# - -f=./app | ||
- --db-schema=euphrates | ||
- --workers=4 | ||
- --batch-size=30 | ||
- --unfinalized-blocks=false | ||
- --disable-historical | ||
- --network-endpoint=https://eth-rpc-acala.aca-api.network | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://subquery-node:3000/ready"] | ||
interval: 3s | ||
timeout: 5s | ||
retries: 10 | ||
|
||
graphql-engine: | ||
image: onfinality/subql-query:latest | ||
ports: | ||
- 3000:3000 | ||
depends_on: | ||
"postgres": | ||
condition: service_healthy | ||
"subquery-node": | ||
condition: service_healthy | ||
restart: always | ||
environment: | ||
DB_USER: postgres | ||
DB_PASS: postgres | ||
DB_DATABASE: postgres | ||
DB_HOST: postgres | ||
DB_PORT: 5432 | ||
command: | ||
- --name=app | ||
- --playground | ||
- --indexer=http://subquery-node:3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "euphrates-analytics-subql", | ||
"version": "0.0.2", | ||
"description": "Subql for Acala Euphrates", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"generate-types": "typechain --target=ethers-v5 --out-dir=./src/typechain abis/*.json", | ||
"build": "subql build", | ||
"codegen": "subql codegen && yarn generate-types", | ||
"start:docker": "docker-compose pull && docker-compose up --remove-orphans", | ||
"dev": "yarn codegen && yarn build && docker-compose pull && docker-compose up --remove-orphans", | ||
"prepack": "rm -rf dist && npm run build", | ||
"test": "jest" | ||
}, | ||
"files": [ | ||
"dist", | ||
"schema.graphql", | ||
"project.yaml" | ||
], | ||
"author": "Acala Team", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@subql/common": "latest", | ||
"@subql/types-ethereum": "latest", | ||
"@subql/validator": "latest", | ||
"abab": "^2.0.6", | ||
"assert": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@subql/cli": "latest", | ||
"@subql/node-ethereum": "latest", | ||
"@subql/testing": "latest", | ||
"@subql/types": "latest", | ||
"ethers": "^5.7.2", | ||
"typescript": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
EthereumProject, | ||
EthereumDatasourceKind, | ||
EthereumHandlerKind, | ||
} from "@subql/types-ethereum"; | ||
|
||
// Can expand the Datasource processor types via the generic param | ||
const project: EthereumProject = { | ||
specVersion: "1.0.0", | ||
version: "0.0.1", | ||
name: "euphrates analytics", | ||
description: | ||
"", | ||
runner: { | ||
node: { | ||
name: "@subql/node-ethereum", | ||
version: ">=3.0.0", | ||
}, | ||
query: { | ||
name: "@subql/query", | ||
version: "*", | ||
}, | ||
}, | ||
schema: { | ||
file: "./schema.graphql", | ||
}, | ||
network: { | ||
/** | ||
* chainId is the EVM Chain ID, for Ethereum this is 1 | ||
* https://chainlist.org/chain/1 | ||
*/ | ||
chainId: "787", | ||
/** | ||
* This endpoint must be a public non-pruned archive node | ||
* Public nodes may be rate limited, which can affect indexing speed | ||
* When developing your project we suggest getting a private API key | ||
* You can get them from OnFinality for free https://app.onfinality.io | ||
* https://documentation.onfinality.io/support/the-enhanced-api-service | ||
*/ | ||
endpoint: [ "https://eth-rpc-acala.aca-api.network" ], | ||
// dictionary: "https://gx.api.subquery.network/sq/subquery/eth-dictionary", | ||
}, | ||
dataSources: [ | ||
{ | ||
kind: EthereumDatasourceKind.Runtime, | ||
startBlock: 4440289, | ||
options: { | ||
// Must be a key of assets | ||
abi: "staking", | ||
address: "0x7Fe92EC600F15cD25253b421bc151c51b0276b7D", | ||
}, | ||
assets: new Map([["staking", { file: "./abis/Staking.json" }]]), | ||
mapping: { | ||
file: "./dist/index.js", | ||
handlers: [ | ||
{ | ||
kind: EthereumHandlerKind.Event, | ||
handler: "handleStake", | ||
filter: { | ||
topics: ["Stake(address,uint256,uint256)"], | ||
}, | ||
}, | ||
{ | ||
kind: EthereumHandlerKind.Event, | ||
handler: "handleUnstake", | ||
filter: { | ||
topics: ["Unstake(address,uint256,uint256)"], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
repository: "https://github.com/subquery/ethereum-subql-starter", | ||
}; | ||
|
||
// Must set default to the project instance | ||
export default project; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type StakeTx @entity { | ||
id: ID! | ||
type: Int! # 1: stake, 0: unstake | ||
from: String! | ||
txHash: String! | ||
blockNumber: Int! | ||
timestamp: Date! | ||
poolId: Int! | ||
amount: BigInt! # dot equivalent amount | ||
originalAmount: BigInt # original amount | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// https://github.com/subquery/subql/issues/1277#issuecomment-1404181415 | ||
import { atob } from 'abab'; | ||
global.atob = atob as any; | ||
|
||
//Exports all handler functions | ||
export * from "./mappings/mappingHandlers"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import assert from "assert"; | ||
|
||
import { | ||
StakeLog, UnstakeLog, | ||
} from "../types/abi-interfaces/Staking"; | ||
import { StakeTx } from "../types"; | ||
import { Homa__factory } from "../typechain"; | ||
|
||
const HOMA_ADDR = '0x0000000000000000000000000000000000000805'; | ||
const homa = Homa__factory.connect(HOMA_ADDR, api); | ||
|
||
export const ldotToDotAmount = async (amount: bigint): Promise<bigint> => { | ||
const exchangeRate = await homa.getExchangeRate(); | ||
return amount * exchangeRate.toBigInt() / BigInt(1e18); | ||
} | ||
|
||
export async function handleStake(log: StakeLog): Promise<void> { | ||
logger.info("new staking at block " + log.blockNumber.toString()); | ||
assert(log.args, "Require args on the logs"); | ||
|
||
const poolId = log.args.poolId.toNumber(); | ||
let amount = log.args.amount.toBigInt(); | ||
const originalAmount = amount; | ||
|
||
if (poolId === 5) { // amount is in LDOT | ||
amount = await ldotToDotAmount(amount) | ||
} | ||
|
||
const tx = StakeTx.create({ | ||
type: 1, // stake | ||
id: log.transactionHash, | ||
txHash: log.transactionHash, | ||
from: log.transaction.from, | ||
blockNumber: log.blockNumber, | ||
timestamp: new Date(Number(log.transaction.blockTimestamp * 1000n) ), | ||
poolId, | ||
amount, | ||
originalAmount, | ||
}); | ||
|
||
await tx.save(); | ||
} | ||
|
||
export async function handleUnstake(log: UnstakeLog): Promise<void> { | ||
logger.info("new unstaking at block " + log.blockNumber.toString()); | ||
assert(log.args, "Require args on the logs"); | ||
|
||
const poolId = log.args.poolId.toNumber(); | ||
let amount = log.args.amount.toBigInt(); | ||
const originalAmount = amount; | ||
|
||
if (poolId === 5) { // rawAmount is in LDOT | ||
amount = await ldotToDotAmount(amount) | ||
} | ||
|
||
const tx = StakeTx.create({ | ||
type: 0, // unstake | ||
id: log.transactionHash, | ||
txHash: log.transactionHash, | ||
from: log.transaction.from, | ||
blockNumber: log.blockNumber, | ||
timestamp: new Date(Number(log.transaction.blockTimestamp * 1000n) ), | ||
poolId, | ||
amount, | ||
originalAmount, | ||
}); | ||
|
||
await tx.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"esModuleInterop": true, | ||
"declaration": true, | ||
"importHelpers": true, | ||
"resolveJsonModule": true, | ||
"module": "commonjs", | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"target": "ESNext", | ||
"strict": true | ||
}, | ||
"include": [ | ||
"src/**/*", | ||
"node_modules/@subql/types-core/dist/global.d.ts", | ||
"node_modules/@subql/types-ethereum/dist/global.d.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,4 @@ Thumbs.db | |
*.wmv | ||
|
||
.data | ||
.yarn | ||
|
||
.DS_Store | ||
.eslintcache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
QmR1bNNxccr9A8523Wq4WWgbDr7euY7jCBPq4gnAWuFv6N | ||
QmcYcYtBE9qFghbJaqSMGMXYjR7EVUcr7StiMJhxEYnF4X |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
# Euphrates Subql | ||
Subql that indexes [Euphrates](https://farm.acala.network/) transactions. | ||
# Acala Stats Subql | ||
|
||
## Deploy | ||
publish to IPFS | ||
``` | ||
export SUBQL_ACCESS_TOKEN=<your token> | ||
subql publish | ||
``` | ||
Subquery for Acala Stats |
Oops, something went wrong.