Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
237 commits
Select commit Hold shift + click to select a range
3262817
Switch upstream GraphQL API endpoint
ankurdotb Sep 13, 2022
78071a0
ci: Update upstream API endpoints
ankurdotb Sep 14, 2022
45ddb06
Simplified get accounts query so that it doesn't break
drgomesp Sep 16, 2022
b627416
Fixed bad query
drgomesp Sep 19, 2022
27f81af
Improved error handling for graphql client
drgomesp Sep 21, 2022
158e10b
wip
drgomesp Sep 22, 2022
59e1bf5
Fixed circulating supply endpoint (still missing rewards and unbonding)
drgomesp Sep 22, 2022
b0b8081
Switch upstream GraphQL API endpoint
ankurdotb Sep 13, 2022
5dbe3e2
ci: Update upstream API endpoints
ankurdotb Sep 14, 2022
078d623
Fixed bad query
drgomesp Sep 19, 2022
6832756
Created new endpoint to update single account balance on KV for later…
drgomesp Sep 23, 2022
b191575
Added total balance as field on account balance cache
drgomesp Sep 23, 2022
88da7d3
Update bigDipperApi.ts
ankurdotb Sep 23, 2022
a50df0d
Revert "Update bigDipperApi.ts"
ankurdotb Sep 23, 2022
ed2491f
Refactoring for balance fetching from different sources
drgomesp Sep 26, 2022
935a679
Fixed account balance helper
drgomesp Sep 26, 2022
033132b
Started with new graphql query
drgomesp Sep 27, 2022
18720bb
Fixed update balance per account endpoint (temporary)
drgomesp Sep 27, 2022
39583e4
Fixed balance query checks
drgomesp Sep 27, 2022
2ec827f
Fixed circulating supply endpoint to work with new query
drgomesp Sep 27, 2022
9556b61
Fixed update all balances endpoint to feed KV (temporary endpoint)
drgomesp Sep 27, 2022
8cd17ca
Better error handling so that API doesn't crash
drgomesp Sep 27, 2022
ac8391e
Fixed all balances updater
drgomesp Sep 27, 2022
58ed4ea
Only updating missing balances (temp)
drgomesp Sep 27, 2022
871602e
Reactivating cron
drgomesp Sep 27, 2022
f5a5bf3
Removed single account balance updater temp endpoint
drgomesp Sep 28, 2022
9027ce6
Improved error logging for graphgl (workers requires a Map for loggin…
drgomesp Sep 28, 2022
97d6523
Removing duplicates from KV while procecssing
drgomesp Sep 28, 2022
c415557
Removed temporary account removal from KV
drgomesp Sep 28, 2022
d36bc4f
Better logging
drgomesp Sep 28, 2022
272d2cd
Fixed endpoint
drgomesp Sep 28, 2022
7fd96ca
Fixed endpoint
drgomesp Sep 28, 2022
77958ad
Added proper list of addresses to import (temp)
drgomesp Sep 30, 2022
4598741
Implementing requested changes from PR review
drgomesp Sep 30, 2022
1aa7d8b
Made group be random on cron
drgomesp Sep 30, 2022
2374092
Simplified record on KV
drgomesp Sep 30, 2022
a2d2395
Better naming and place for cron helper
drgomesp Sep 30, 2022
9403d2f
Better error handling
drgomesp Sep 30, 2022
a48af48
Removed unused code
drgomesp Sep 30, 2022
4b79e2f
Better yet error handling
drgomesp Sep 30, 2022
30d1978
Fixed error issue returning bad response
drgomesp Sep 30, 2022
a1b5229
Clean-up of addresses
drgomesp Oct 2, 2022
0e821e7
Reprocessing addresses
drgomesp Oct 2, 2022
84fde0b
Removed static account addresses
drgomesp Oct 2, 2022
ec730d9
Removed unecessary endpoint for processing balance groups
drgomesp Oct 3, 2022
f2d8a1c
Added check for null account on balance endpoint
drgomesp Oct 3, 2022
b83bd32
Added updated at to KV record
drgomesp Oct 3, 2022
ed201d1
Squashed commit of the following:
ankurdotb Oct 12, 2022
519f9d2
Update wrangler.toml
ankurdotb Oct 12, 2022
64c3ca7
Fixed broken trigger
ankurdotb Oct 12, 2022
a13332c
fix total delegations count per validatior
benyam7 Oct 13, 2022
3113a4e
fix totat delegators count
benyam7 Oct 13, 2022
ff56494
Merge branch 'fix-broken-api' of github.com:cheqd/data-api into fix-b…
benyam7 Oct 13, 2022
3c8b55a
fix total staked coins
benyam7 Oct 13, 2022
7a67d4d
Merge branch 'main' into fix-broken-api
benyam7 Oct 14, 2022
b66692c
Update wrangler.toml
ankurdotb Oct 14, 2022
61766fb
fix: total balance
benyam7 Oct 14, 2022
0640c16
Merge branch 'fix-broken-api' of github.com:cheqd/data-api into fix-b…
benyam7 Oct 14, 2022
86fb48f
Fix endpoint
ankurdotb Oct 14, 2022
2dc9fdb
Merge branch 'main' into fix-circulating-supply
ankurdotb Oct 14, 2022
5047784
fix total balance
benyam7 Oct 17, 2022
d7dfca0
fix circulating supply
benyam7 Oct 18, 2022
d07d0ee
chore refactor a bit
benyam7 Oct 18, 2022
74a67fb
fix node api (include unbounding/delegated free balance for totalBalance
benyam7 Oct 18, 2022
4528425
make total balance endpoint to consider unbounding balance
benyam7 Oct 18, 2022
921a886
Squashed commit of the following:
ankurdotb Oct 18, 2022
0a294b1
Merge branch 'main' into fix-circulating-supply
ankurdotb Oct 19, 2022
5f955e1
chore store account balance infos in KV
benyam7 Oct 19, 2022
168c67b
Merge branch 'fix-circulating-supply' of github.com:cheqd/data-api in…
benyam7 Oct 19, 2022
2e34644
fix total balance
benyam7 Oct 19, 2022
2573fa3
trigger cron based on current
benyam7 Oct 19, 2022
0c77937
remove CSW KV and change trigger interval for staging
benyam7 Oct 19, 2022
2597392
remove :delayed
benyam7 Oct 19, 2022
4a884e9
fix wrangler.toml
benyam7 Oct 19, 2022
61750fd
fix total balance
benyam7 Oct 19, 2022
0c07fde
decrease height by one
benyam7 Oct 20, 2022
014f3f3
lowwer chances of getting total balance to be 0
benyam7 Oct 20, 2022
11e3ffb
Fix typo in available balance
ankurdotb Oct 21, 2022
d8efedf
Fix typo in unbonding balance
ankurdotb Oct 21, 2022
cd310b6
Convert available balance to CHEQ
ankurdotb Oct 21, 2022
9b024c4
Update staging trigger to every hour
ankurdotb Oct 21, 2022
d4e36ec
get total delegations balance from node api
benyam7 Oct 21, 2022
a591b35
total unbonding balance for delegator from node api
benyam7 Oct 21, 2022
a835e11
Merge branch 'fix-circulating-supply' of github.com:cheqd/data-api in…
benyam7 Oct 21, 2022
2798e3e
fix calculate unbonding balance
benyam7 Oct 21, 2022
2ed09b8
get account balance infos from node for totalBalance
benyam7 Oct 21, 2022
89430c2
update account balance infos from node api
benyam7 Oct 21, 2022
e124c26
add a logic to calculate vesting and vested(taken form wallet app)
benyam7 Oct 21, 2022
160f271
update vesting and vested endpoints to get result from newly added logic
benyam7 Oct 21, 2022
284b746
review changes
benyam7 Oct 21, 2022
b5abbf9
fix a bug when calculating avaliable balance
benyam7 Oct 25, 2022
0439669
remove getting account details from gql
benyam7 Oct 25, 2022
997ca12
create staging KV for total delegators count
benyam7 Oct 25, 2022
8db00b9
add helper methods to do caching
benyam7 Oct 25, 2022
669143e
update total delegators count in cron
benyam7 Oct 25, 2022
3b62fff
make total delegators count read from cache if avaliable
benyam7 Oct 25, 2022
15cde45
Merge branch 'main' into cache-delegators-count
benyam7 Oct 26, 2022
1eb39bb
add preview for CSW KV for local dev
benyam7 Oct 26, 2022
3be5b5a
switch to node api for getting delegators count per validator
benyam7 Oct 26, 2022
2c4a738
refacor total delegators count a bit
benyam7 Oct 27, 2022
41b1939
remove total delegators count kv
benyam7 Oct 27, 2022
ff3791f
setup KV for active validators
benyam7 Oct 27, 2022
528a268
add a logic to add and remove validators from kv
benyam7 Oct 27, 2022
3564042
set up KV for total delegators
benyam7 Oct 27, 2022
2e0eaf8
paginate and get all delegators for a validator
benyam7 Oct 27, 2022
422b321
add a logic to add or remove delegators in KV
benyam7 Oct 27, 2022
f213e87
change total delegators to read from cache instead
benyam7 Oct 27, 2022
39a8685
set 10 as group for active validators
benyam7 Oct 27, 2022
92b388d
setup a trigger to update delegators to validators
benyam7 Oct 27, 2022
acbe811
add preview id for new KVs
benyam7 Oct 28, 2022
e7598f9
change delegators count endpoint to use paginated response
benyam7 Oct 28, 2022
846b488
update next_key after next fetch
benyam7 Oct 28, 2022
78a4162
clean up pagination key
benyam7 Oct 28, 2022
690f9b1
paginate using offset when getting delegators per validator
benyam7 Oct 31, 2022
04876f6
remove newlines and spaces from query
benyam7 Oct 31, 2022
4edeae9
paginate using offeset to get total delegated amount
benyam7 Oct 31, 2022
702a857
paginate using offest when getting total unboding amount
benyam7 Oct 31, 2022
9c6e5f8
don't export private functions
benyam7 Oct 31, 2022
8eb3e7c
move active validators from param func block
benyam7 Oct 31, 2022
4c0d066
call add and remove active validators on webtrigger
benyam7 Oct 31, 2022
2139da5
fix syntax error
benyam7 Oct 31, 2022
abc0845
fix error at: create_hashmap_of_validators_addresses_from_kv
benyam7 Oct 31, 2022
12b8910
Delete get_delegator_count_for_validator
ankurdotb Oct 31, 2022
7bb7a09
Rename PAGINATION_LIMIT
ankurdotb Oct 31, 2022
9ca40b6
Pagination limit binding
ankurdotb Oct 31, 2022
883a3fd
Standardise all node queries
ankurdotb Oct 31, 2022
29be667
Correct pagination limit
ankurdotb Oct 31, 2022
42cae93
add logs when updating total delegators
benyam7 Oct 31, 2022
e4c2144
get total supply from gql
benyam7 Oct 31, 2022
9b25dfa
Remove preview KV pairs
ankurdotb Oct 31, 2022
4add9f8
Merge branch 'cache-delegators-count' of https://github.com/cheqd/dat…
ankurdotb Oct 31, 2022
f4dbb11
Restructure URL params
ankurdotb Oct 31, 2022
907ce58
Fix missing pagination limit variable in staging
ankurdotb Oct 31, 2022
e5c1eb2
Fix typo in unbonding methods
ankurdotb Oct 31, 2022
d0e9971
Fix typo in originalVesting
ankurdotb Oct 31, 2022
3176e7b
Remove unused delayed vesting functions
ankurdotb Oct 31, 2022
475521e
Temporarily log request URL for validator delegators
ankurdotb Oct 31, 2022
a2c3061
fix adding up total delegations and unbondings
benyam7 Oct 31, 2022
fe18294
use Map instead of object literal
benyam7 Oct 31, 2022
4f558a1
Reduce staging cron to 1 hour
ankurdotb Oct 31, 2022
33071f8
create a new KV for active validators on staging
benyam7 Nov 1, 2022
70cf0be
get voting power for active validator
benyam7 Nov 2, 2022
a22519f
reuse active validators resp
benyam7 Nov 2, 2022
026f29f
store voting power as well as total delegator count for a validator i…
benyam7 Nov 2, 2022
fe84c8f
add new validator to smallest validator group in KV
benyam7 Nov 2, 2022
e45c1b2
Merge branch 'cache-delegators-count' of github.com:cheqd/data-api in…
benyam7 Nov 2, 2022
7964003
try getting delegators count for validator from kv first
benyam7 Nov 2, 2022
cde6227
cast all numeric constants to Number again.
benyam7 Nov 2, 2022
cc3c9e1
Remove total delegators
ankurdotb Nov 2, 2022
5893d5e
Cleanup BigDipper API and types
ankurdotb Nov 2, 2022
9f856fd
Remove extra ValidatorDetailResponse type
ankurdotb Nov 2, 2022
7e4c17c
Clean up balance helper function
ankurdotb Nov 2, 2022
7f23794
Rename balanceGroup to circulating
ankurdotb Nov 2, 2022
97f7eb3
Add RewardsResponse type
ankurdotb Nov 2, 2022
a2f2b5f
Rename circulating supply helper
ankurdotb Nov 2, 2022
aab5009
Remove unused function in node helper
ankurdotb Nov 2, 2022
ed2ff3e
Remove unused import in vesting
ankurdotb Nov 2, 2022
1b07555
Update delegatorCount.ts
ankurdotb Nov 2, 2022
ef05603
refactor webhook triggers
benyam7 Nov 2, 2022
f72291c
refactor circulating
benyam7 Nov 3, 2022
41a5859
refactor delegators count
benyam7 Nov 3, 2022
964dff1
cleanup vesting
benyam7 Nov 3, 2022
0b2d74e
refactor helpers: balance
benyam7 Nov 3, 2022
1cda663
refactor helpers node
benyam7 Nov 3, 2022
322d4e7
move group and address extraction to separate file
benyam7 Nov 3, 2022
24efdd0
remove old kv as we dont need pre-populated kv
benyam7 Nov 3, 2022
9ad7731
add limit optional param
benyam7 Nov 3, 2022
c669e3b
fix adding new validator to kv logic
benyam7 Nov 3, 2022
f5c7820
fix creating map logic
benyam7 Nov 3, 2022
3fda52b
remove sending arbitrage as it is causing hook to fail
benyam7 Nov 3, 2022
654f33d
remove additional check when adding validator to KV
benyam7 Nov 3, 2022
0104e55
add additional logs
benyam7 Nov 3, 2022
dcfa31e
remove old pre populated validators kv for prod
benyam7 Nov 3, 2022
75a1743
Fix imports
ankurdotb Nov 3, 2022
4484d75
Remove unncessary helper
ankurdotb Nov 3, 2022
c1202b7
Update balance.ts
ankurdotb Nov 3, 2022
ef9b9b4
Remove total delegators endpoint from README
ankurdotb Nov 3, 2022
a9abc46
Bump wrangler
ankurdotb Nov 3, 2022
6fb3cbe
Add cache cleanup scripts
ankurdotb Nov 3, 2022
797abad
catch all cron exceptions
benyam7 Nov 3, 2022
29dfa54
remove voting count
benyam7 Nov 3, 2022
ddc3528
Add circulating supply link
ankurdotb Nov 3, 2022
7832642
add more logs
benyam7 Nov 3, 2022
840db54
Merge branch 'cache-delegators-count' of github.com:cheqd/data-api in…
benyam7 Nov 3, 2022
3fef0c2
Remove active validator group binding
ankurdotb Nov 3, 2022
af77f20
add more logs
benyam7 Nov 3, 2022
6224446
Merge branch 'cache-delegators-count' of https://github.com/cheqd/dat…
ankurdotb Nov 3, 2022
7d4b935
Update readme for API changes
ankurdotb Nov 3, 2022
3ac2d66
extract delegator count
benyam7 Nov 3, 2022
714e147
Merge branch 'cache-delegators-count' of github.com:cheqd/data-api in…
benyam7 Nov 3, 2022
58a4206
Update nodeApi.ts
ankurdotb Nov 3, 2022
c85679d
Trying another logging method
ankurdotb Nov 3, 2022
f855d75
Logging using map
ankurdotb Nov 3, 2022
076fcaa
try catch api call
benyam7 Nov 4, 2022
ca8f9cf
remove unused type
benyam7 Nov 4, 2022
f036d15
add a additional cron for testing
benyam7 Nov 4, 2022
2a7cf51
run updating active validators kv on separate cron
benyam7 Nov 4, 2022
e83a309
put only one active validator on kv to lessen load
benyam7 Nov 4, 2022
aa5174d
Disable market monitoring and circulating supply triggers
ankurdotb Nov 4, 2022
ba5c115
Set triggrer to 2 mins
ankurdotb Nov 4, 2022
282f03b
Deactivate adding validators
ankurdotb Nov 4, 2022
fdded4c
Update .gitignore
ankurdotb Nov 4, 2022
7074926
Log delete stale
ankurdotb Nov 4, 2022
8f4fb0c
Update dispatch.yml
ankurdotb Nov 4, 2022
81798f3
Update validators.ts
ankurdotb Nov 4, 2022
a60edc6
Delete validators helper
ankurdotb Nov 4, 2022
c132d79
Update circulating supply groups
ankurdotb Nov 4, 2022
dacf70b
Activate circulating supply trigger
ankurdotb Nov 4, 2022
51c1433
Update group prefix
ankurdotb Nov 4, 2022
917ecd5
Remove unused functions in nodeApi
ankurdotb Nov 4, 2022
f11bac5
Removed unused BigDipper API
ankurdotb Nov 4, 2022
942dbb4
Change market monitoring functions to PascalCase
ankurdotb Nov 4, 2022
4da6e54
Set node API methods to camelCase
ankurdotb Nov 4, 2022
02cdef6
Rename circulating supply
ankurdotb Nov 4, 2022
46dab1f
Delete delegatorCount.ts
ankurdotb Nov 4, 2022
9fa497a
Rename to isValidAddress
ankurdotb Nov 4, 2022
b484db2
Rename to isValidAddress
ankurdotb Nov 4, 2022
0de1ac7
Rename to isDelayedVestingAccount
ankurdotb Nov 4, 2022
c998576
Rename to convertToLargestDenom
ankurdotb Nov 4, 2022
281a4c6
Rename to convertToMainTokenDenom
ankurdotb Nov 4, 2022
30349eb
Rename to fetchAccountBalance
ankurdotb Nov 4, 2022
d2e1269
Rename to calculateTotalUnbondingBalance
ankurdotb Nov 4, 2022
cbe77dc
Rename to extractPrefixAndKey
ankurdotb Nov 4, 2022
a2e62d5
Delete unused function
ankurdotb Nov 4, 2022
ef9371e
Rename to isContinuousVestingAccount
ankurdotb Nov 4, 2022
6afcb59
Rename to calculateVestedBalance
ankurdotb Nov 4, 2022
1c24f18
Simplify vesting account calculation
ankurdotb Nov 4, 2022
9f398f6
Update graphql.ts
ankurdotb Nov 4, 2022
cf0e44c
Update node.ts
ankurdotb Nov 4, 2022
d30d55e
Change cron triggers
ankurdotb Nov 4, 2022
51c534c
Reactivate markdown link check
ankurdotb Nov 4, 2022
95a654d
Reactivate linter
ankurdotb Nov 4, 2022
83a332d
Update pull-request.yml
ankurdotb Nov 4, 2022
b6fb54f
Fix broken links
ankurdotb Nov 4, 2022
b6b9a9e
Bump to Node 18
ankurdotb Nov 4, 2022
1d909bd
Removed unused handler
ankurdotb Nov 4, 2022
b3e5e5d
Throw error on circulating supply
ankurdotb Nov 4, 2022
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
45 changes: 45 additions & 0 deletions .github/workflows/cleanup-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Cleanup - Actions"
on:
workflow_dispatch:
inputs:
days:
description: 'Retain days'
required: true
type: string
default: 30
minimum_runs:
description: 'Minimum runs to keep for each workflow'
required: true
type: string
default: 0
delete_workflow_pattern:
description: 'Name/filename of workflow. Default is all.'
required: false
type: string
delete_workflow_by_state_pattern:
description: 'Remove workflow by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
required: true
default: All
type: choice
options:
- All
- active
- deleted
- disabled_inactivity
- disabled_manually

jobs:

delete-runs:
name: "Delete old workflow runs"
runs-on: ubuntu-latest

steps:
- uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
21 changes: 21 additions & 0 deletions .github/workflows/cleanup-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Cleanup - Cache"
on:
workflow_dispatch:
inputs:
dry-run:
description: "Dry run only?"
required: true
type: boolean
default: false

jobs:

delete-caches:
name: "Delete Actions caches"
runs-on: ubuntu-latest

steps:
- name: "Wipe Github Actions cache"
uses: easimon/wipe-cache@v1
with:
dry-run: ${{ github.event.inputs.dry-run }}
18 changes: 16 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

Expand All @@ -70,3 +70,17 @@ jobs:
WEBHOOK_URL
env:
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}

cache-purge:
name: "Purge branch Actions cache"
needs: staging-deploy
runs-on: ubuntu-latest

steps:

- name: "Delete Branch Cache Action"
uses: snnaplab/delete-branch-cache-action@v1.0.0
with:
# Specify explicitly because the ref at the time of merging will be a branch name such as 'main', 'develop'
ref: refs/pull/${{ github.event.number }}/merge
github-token: ${{ secrets.GITHUB_TOKEN }}
22 changes: 10 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ defaults:

jobs:

# md-link-check:
# name: "Broken Markdown links"
# runs-on: ubuntu-latest
md-link-check:
name: "Broken Markdown links"
runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3
steps:
- uses: actions/checkout@v3

# - name: Run Markdown link check
# uses: gaurav-nelson/github-action-markdown-link-check@v1
# with:
# config-file: '.github/linters/mlc_config.json'
# use-quiet-mode: 'yes'
- name: Run Markdown link check
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
config-file: '.github/linters/mlc_config.json'
use-quiet-mode: 'yes'

super-lint:
name: "Super Linter"
Expand All @@ -45,8 +45,6 @@ jobs:
VALIDATE_JAVASCRIPT_ES: true
VALIDATE_JSONC: true
VALIDATE_MARKDOWN: true
VALIDATE_OPENAPI: true
VALIDATE_TSX: true
VALIDATE_TYPESCRIPT_ES: true
VALIDATE_XML: true
VALIDATE_YAML: true
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
# to override config-conventional rules, specify a relative path to your rules module, actions/checkout is required for this setting!
commitlintRulesPath: "./.github/linters/.commitlint.rules.js" # default: undefined
# if the PR contains a single commit, fail if the commit message and the PR title do not match
commitTitleMatch: "false" # default: 'true'
commitTitleMatch: false # default: 'true'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### APP-SPECIFIC EXCLUSIONS ###
wrangler.dev.toml
watchlist.json
watchlist-old.json
watchlist-*.json

### GENERAL EXCLUSIONS ###

Expand Down
64 changes: 23 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## ℹ️ Overview

Cosmos SDK offers [APIs for built-in modules using gRPC, REST, and Tendermint RPC](https://docs.cosmos.network/master/core/grpc_rest.html). This project aims to provide simple REST APIs for data that default Cosmos SDK APIs can't provide.
Cosmos SDK offers [APIs for built-in modules using gRPC, REST, and Tendermint RPC](https://docs.cosmos.network/main/core/grpc_rest.html). This project aims to provide simple REST APIs for data that default Cosmos SDK APIs can't provide.

This collection of custom APIs can be deployed as a [Cloudflare Worker](https://workers.cloudflare.com/) or compatible serverless platforms.

Expand All @@ -32,7 +32,7 @@ While this figure is available from Cosmos SDK's built-in [`/cosmos/bank/v1beta1

#### Endpoint

`data-api.cheqd.io/supply/circulating`
[`data-api.cheqd.io/supply/circulating`](https://data-api.cheqd.io/supply/circulating)

#### Response

Expand All @@ -44,12 +44,7 @@ Cryptocurrency tracking websites such as [CoinMarketCap](https://coinmarketcap.c

This figure is _not_ available from any Cosmos SDK API, because the [criteria for determining circulating vs "non-circulating" accounts is defined by CoinMarketCap](https://support.coinmarketcap.com/hc/en-us/articles/360043396252-Supply-Circulating-Total-Max-).

This API calculates the circulating supply by **subtracting** the account balances of a defined list of wallet addresses ("circulating supply watchlist"). Different types of accounts defined in the watchlist are handled as follows:

1. **Base accounts and Continuous Vesting accounts**: These will always have an entry in BigDipper block explorer, since these accounts have transactions that trigger indexing.
2. **Delayed Vesting accounts**: These accounts present a complex scenario since BigDipper does _not_ index all delayed vesting accounts by default.
1. **If there have been ANY transactions involving the delayed vesting account**: Delayed vesting accounts can still stake their original vesting allowance, or the account holder may have transferred additional funds into the account. In this scenario, the account _will_ be indexed by BigDipper and the account balance can be fetched via the GraphQL API.
2. **If there have been NO transactions involving the delayed vesting account**: Delayed vesting accounts with no other transactions beyond the original creation are _not_ indexed by BigDipper. Balances for these accounts are fetched using the standard Cosmos SDK `/cosmos/bank/v1beta1/balances/<address>` REST API endpoint.
This API calculates the circulating supply by **subtracting** the account balances of a defined list of wallet addresses ("circulating supply watchlist") from the total supply.

### 🥩 Total staked supply

Expand All @@ -65,34 +60,6 @@ Overall tokens staked, in CHEQ.

Provides the overall amount staked pulled from the block explorer.

### ➕ Overall number of delegators

#### Endpoint

[`data-api.cheqd.io/staking/delegators/total`](https://data-api.cheqd.io/staking/delegators/total)

#### Response

Total number of delegators across every validator on the network.

#### Rationale

The only way to derive this figure from the Cosmos SDK APIs is by iterating over every validator and counting the number of delegators.

### 🗳 Delegator count by validator

#### Endpoint

[`data-api.cheqd.io/staking/delegators/<validator-address>`](https://data-api.cheqd.io/staking/delegators/cheqdvaloper1lg0vwuu888hu4arnt9egtqrm2662kcrtf2unrs)

#### Response

Number of delegators who delegate to a specific validator.

#### Rationale

There is no simple Cosmos SDK API to fetch the number of delegators for a given validator.

### 🔐 Vesting Account Balance

#### Endpoint
Expand Down Expand Up @@ -202,19 +169,34 @@ While our deployment uses Cloudflare Wrangler, the application itself could be m

Wrangler CLI uses [`wrangler.toml` for configuring](https://developers.cloudflare.com/workers/wrangler/configuration/) the application. If you're using this for your own purposes, you will need to replace values for `account_id`, [Cloudflare KV](https://developers.cloudflare.com/workers/learning/how-kv-works/) bindings, `route`, etc. for the application to work correctly along with your own [Cloudflare API tokens](https://developers.cloudflare.com/api/tokens/create).

For the circulating supply API endpoint, Cloudflare Workers will expect to find a Cloudflare KV namespace called `CIRCULATING_SUPPLY_WATCHLIST` with a list of addresses in the `key`. The application _only_ uses the key, so value can be anything.
#### Environment variables

The application expects these environment variables to be set on Cloudflare:

1. `TOKEN_EXPONENT`: Denominator for token (default `9` for CHEQ token).
2. `REST_API`: REST API for a Cosmos/cheqd node to target for queries.
3. `REST_API_PAGINATION_LIMIT`: Number of results to fetch in a single query, for queries that require iterating multiple times. (E.g., many account balance queries require this, to be able to get all delegations etc.)
4. `GRAPHQL_API`: GraphQL API for a BigDipper explorer instance for some queries. E.g., the GraphQL API for [cheqd's block explorer](https://explorer.cheqd.io/) is `https://explorer-gql.cheqd.io/v1/graphql`.
5. `CIRCULATING_SUPPLY_GROUPS`: Number of sub-groups the circulating supply watchlist is split into (see sample JSON file below). This is to ensure that any lookups from APIs can be spaced out.
6. `MARKET_MONITORING_API`: Upstream API for running queries from CoinGecko API (see the [market-monitoring repository](https://github.com/cheqd/market-monitoring)).
7. `WEBHOOK_URL`: Zapier webhook URL to send market monitoring data to. Since this is a secret, it's not set in plaintext in `wrangler.toml` but passed via GitHub Actions secrets.

#### Cloudflare KV bindings

Cached data for computationally-expensive queries are stored in [Cloudflare KV](https://developers.cloudflare.com/workers/learning/how-kv-works/).

Delayed vesting accounts that have never been involved in a transaction (as described above) should be prefixed with a `delayed:` prefix in the JSON file. Cloudflare allows [filtering KV pair `key`s by prefixes](https://developers.cloudflare.com/workers/runtime-apis/kv/#more-detail) when using a list operation.
1. `CIRCULATING_SUPPLY_WATCHLIST`: This KV is pre-populated with a list of addresses to monitor for circulating supply. Initially, the *value* portion of this can be set to anything, since it will get replaced when [periodic cron triggers](https://developers.cloudflare.com/workers/platform/cron-triggers) run to set the account balance breakdown for this account. In case you have a lot of accounts to monitor, we recommend prefixing the *key* with a `group_N` prefix which will stagger the API lookup across multiple cron executions.
2. `ACTIVE_VALIDATORS`: List of active validators, fetch from block explorer GraphQL API. When a cron trigger is executed, the total delegator count and update time is stored in this KV.

```jsonc
// Sample watchlist JSON file structure
[
{
"key": "cheqd1...xxx",
"value": "26-May-2022" // This can be any value
"key": "group_1:cheqd1...xxx", // Group 1 prefix
"value": "26-May-2022" // This can be any value, and will be updated with account balance breakdown periodically
},
{
"key": "delayed:cheqd1...xxx", // This is a delayed account that won't be indexed by BigDipper
"key": "group_2:cheqd1...xxx", // Group 2 prefix
"value": "26-May-2022"
}
]
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@cloudflare/workers-types": "^3.18.0",
"@types/node": "^17.0.45",
"typescript": "^4.8.4",
"wrangler": "^2.1.13"
"wrangler": "^2.1.15"
},
"private": true
}
Loading