Skip to content

Commit

Permalink
Merge pull request #113 from embrio-tech/main
Browse files Browse the repository at this point in the history
20240226 Sprint 28
  • Loading branch information
hieronx authored Feb 27, 2024
2 parents 76cde76 + 6528d26 commit 553929d
Show file tree
Hide file tree
Showing 30 changed files with 922 additions and 404 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export DB_HOST=localhost
export DB_PORT=5432
export SUBQL_DB_USER=$DB_USER
export SUBQL_DB_PASS=$DB_PASS
export CHAIN_ID="centrifuge-cfg"
export CHAIN_ID="demo"
30 changes: 30 additions & 0 deletions chains-cfg/_root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,33 @@ dataSources:
filter:
module: ormlTokens
method: Withdrawn
- handler: handleFeeProposed
kind: substrate/EventHandler
filter:
module: poolFees
method: Proposed
- handler: handleFeeAdded
kind: substrate/EventHandler
filter:
module: poolFees
method: Added
- handler: handleFeeRemoved
kind: substrate/EventHandler
filter:
module: poolFees
method: Removed
- handler: handleFeeCharged
kind: substrate/EventHandler
filter:
module: poolFees
method: Charged
- handler: handleFeeUncharged
kind: substrate/EventHandler
filter:
module: poolFees
method: Uncharged
- handler: handleFeePaid
kind: substrate/EventHandler
filter:
module: poolFees
method: Paid
2 changes: 1 addition & 1 deletion chains-cfg/demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ network:
file: ./dist/chaintypes.js
dataSources:
- kind: substrate/Runtime
startBlock: 1534900 #1st October 2023
startBlock: 1549700
5 changes: 5 additions & 0 deletions chains-cfg/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ network:
chainId: '0x27d6bdae3ea8fc7021792f3ccea5ee62fee37641c6f69d6e8530cfb45ef57a64'
chaintypes:
file: ./dist/chaintypes.js
dataSources:
- kind: substrate/Runtime
startBlock: 6870 # block first pool was created at
filter:
modulo: 1000
20 changes: 0 additions & 20 deletions chains-evm/eth/centrifuge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,3 @@ dataSources:
startBlock: 18721030
options:
address: '0x78E9e622A57f70F1E0Ec652A4931E4e278e58142'
- kind: ethereum/Runtime
startBlock: 11063000
options:
abi: navFeed
assets:
navFeed:
file: './abi/navfeed.abi.json'
reserve:
file: './abi/reserve.abi.json'
shelf:
file: './abi/shelf.abi.json'
pile:
file: './abi/pile.abi.json'
mapping:
file: './dist/index.js'
handlers:
- handler: handleEthBlock
kind: ethereum/BlockHandler
filter:
modulo: 3600
43 changes: 43 additions & 0 deletions chains-tinlake/centrifuge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
network:
chainId: '1'
endpoint: https://mainnet.infura.io/v3/a4ba76cd4be643618572e7467a444e3a
dictionary: https://gx.api.subquery.network/sq/subquery/eth-dictionary
dataSources:
- kind: ethereum/Runtime
startBlock: 11063000
options:
abi: navFeed
assets:
navFeed:
file: ./abi/navfeed.abi.json
reserve:
file: ./abi/reserve.abi.json
shelf:
file: ./abi/shelf.abi.json
pile:
file: ./abi/pile.abi.json
mapping:
file: ./dist/index.js
handlers:
- handler: handleEthBlock
kind: ethereum/BlockHandler
filter:
modulo: 3600
specVersion: 1.0.0
name: centrifuge-pools
version: 1.0.0
runner:
node:
name: '@subql/node-ethereum'
version: '3'
query:
name: '@subql/query'
version: '2'
description: >-
SubQuery API powered by EMBRIO.tech to query Centrifuge chain data for
analytics insights on how Centrifuge is unlocking economic opportunity for all
by connecting people to borrow and lend money transparently and
cost-effectively.
repository: https://github.com/centrifuge/pools-subql
schema:
file: ./schema.graphql
15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"description": "Subquery for the pools functionality",
"main": "dist/index.js",
"scripts": {
"postinstall": "wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O ./node_modules/.bin/yq && chmod +x ./node_modules/.bin/yq",
"build": "subql build",
"build:dev": "subql build --mode=dev",
"dev": "docker compose down -v --remove-orphans && docker compose pull && docker compose up -d",
"prepack": "rm -rf dist && subql build",
"test": "jest",
"codegen": "subql codegen",
"projectgen" : "./project-generator.sh",
"projectgen": "./project-generator.sh",
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package centrifuge-subql/src/api-interfaces --endpoint 'wss://fullnode.development.cntrfg.com' --input ./src/api-interfaces",
"generate:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --endpoint 'wss://fullnode.development.cntrfg.com' --output ./src/api-interfaces --strict",
"interface-build": "yarn generate:defs && yarn generate:meta && yarn build",
Expand All @@ -34,7 +34,7 @@
"@jest/globals": "^29.2.0",
"@polkadot/api": "^10",
"@polkadot/typegen": "^10",
"@subql/cli": "^4.2.5",
"@subql/cli": "latest",
"@subql/testing": "latest",
"@subql/types": "latest",
"@types/jest": "^29.1.2",
Expand All @@ -47,12 +47,11 @@
"husky": "^7.0.0",
"jest": "^29.2.0",
"lint-staged": "^13.2.0",
"node-fetch": "2.6.7",
"prettier": "^3.1.1",
"prettier-eslint": "^16.2.0",
"ts-jest": "^29.0.3",
"ts-node": "^8.6.2",
"typescript": "^4.1.3"
"typescript": "^5.2.2",
"yaml-merge-cli": "^1.1.5"
},
"lint-staged": {
"src/**/*.{js,ts}": [
Expand All @@ -61,9 +60,5 @@
},
"exports": {
"chaintypes": "./src/chaintypes.ts"
},
"resolutions": {
"ipfs-unixfs": "6.0.6",
"typescript": "4.9"
}
}
15 changes: 12 additions & 3 deletions project-generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ projects:
- project-centrifuge.yaml
EOF

yq ". *=d load(\"chains-cfg/${CHAIN_ID}.yaml\")" chains-cfg/_root.yaml > project-centrifuge.yaml
#CFG
merge-yaml -i ./chains-cfg/_root.yaml ./chains-cfg/${CHAIN_ID}.yaml -o ./project-centrifuge.yaml

#EVM Chains
subdirs=$(find chains-evm -mindepth 1 -maxdepth 1 -type d)
for subdir in $subdirs; do
if [ -e "$subdir/${CHAIN_ID}.yaml" ]; then
echo "Generating EVM config for ${subdir##*/}"
yq ". *=d load(\"$subdir/${CHAIN_ID}.yaml\")" chains-evm/_root.yaml > project-${subdir##*/}.yaml
merge-yaml -i ./$subdir/${CHAIN_ID}.yaml ./chains-evm/_root.yaml -o ./project-${subdir##*/}.yaml
echo " - project-${subdir##*/}.yaml" >> subquery-multichain.yaml
fi
done
done

#TINLAKE
if [ -e "chains-tinlake/${CHAIN_ID}.yaml" ]; then
echo "Generating Tinlake config for"
merge-yaml -i ./chains-tinlake/${CHAIN_ID}.yaml -o ./project-tinlake.yaml
echo " - project-tinlake.yaml" >> subquery-multichain.yaml
fi
76 changes: 76 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,79 @@ type CurrencyBalance @entity {
type Blockchain @entity {
id: ID! #EVM chainId
}

enum PoolFeeStatus {
PROPOSED
ADDED
REMOVED
}

enum PoolFeeType {
Fixed
ChargedUpTo
}

type PoolFee @entity {
id: ID! # poolId - feeId
feeId: String!
type: PoolFeeType!
status: PoolFeeStatus!
isActive: Boolean! @index

createdAt: Date
createdAtBlockNumber: Int
createdAtEpoch: Int

pool: Pool! @index

sumChargedAmount: BigInt #Applies to Fixed ONLY
sumAccruedAmount: BigInt #Applies toChargedUpTo ONLY
sumPaidAmount: BigInt #Applies to All
pendingAmount: BigInt #Applies to All

sumChargedAmountByPeriod: BigInt #Applies to Fixed ONLY
sumAccruedAmountByPeriod: BigInt #Applies toChargedUpTo ONLY
sumPaidAmountByPeriod: BigInt #Applies to All
}

type PoolFeeSnapshot @entity {
id: ID! # poolId - feeId - blockNumber
feeId: String!
poolFee: PoolFee! @index

timestamp: Date!
blockNumber: Int!
periodStart: Date! @index

sumChargedAmount: BigInt #Applies to Fixed ONLY
sumAccruedAmount: BigInt #Applies toChargedUpTo ONLY
sumPaidAmount: BigInt #Applies to All
pendingAmount: BigInt #Applies to All

sumChargedAmountByPeriod: BigInt #Applies to Fixed ONLY
sumAccruedAmountByPeriod: BigInt #Applies toChargedUpTo ONLY
sumPaidAmountByPeriod: BigInt #Applies to All
}

enum PoolFeeTransactionType {
PROPOSED
ADDED
REMOVED
CHARGED
UNCHARGED
PAID
ACCRUED
}

type PoolFeeTransaction @entity {
id: ID! # extrinsicHash - epochNumber - transaction type
poolFee: PoolFee! @index
type: PoolFeeTransactionType!

timestamp: Date!
blockNumber: Int!
epochNumber: Int!

amount: BigInt

}
2 changes: 1 addition & 1 deletion src/@types/gobal.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {}
declare global {
function getNodeChainId(): Promise<string>
function getNodeEvmChainId(): Promise<string>
}
23 changes: 23 additions & 0 deletions src/chaintypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const definitions: OverrideBundleDefinition = {
outstandingPrincipal: 'Balance',
outstandingInterest: 'Balance',
},
PoolNav: {
navAum: 'Balance',
navFees: 'Balance',
reserve: 'Balance',
total: 'Balance',
},
},
},
],
Expand Down Expand Up @@ -48,6 +54,23 @@ const definitions: OverrideBundleDefinition = {
version: 1,
},
],
PoolsApi: [
{
methods: {
nav: {
description: 'Get active pool NAV',
params: [
{
name: 'pool_id',
type: 'u64',
},
],
type: 'Option<PoolNav>',
},
},
version: 1,
},
],
},
rpc: {
pools: {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/stateSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function _stateSnapshotter(
const entitySaves: Promise<void>[] = []
logger.info(`Performing snapshots of ${stateModel}`)
const stateEntities = (await paginatedGetter(stateModel, filterKey, filterValue)) as ResettableEntity[]
if(stateEntities.length === 0) logger.info(`No ${stateModel} to snapshot!`)
for (const stateEntity of stateEntities) {
const blockNumber = block.number
const { id, ...copyStateEntity } = stateEntity
Expand Down
Loading

0 comments on commit 553929d

Please sign in to comment.