add holderCount

This commit is contained in:
Barry Gitarts 2021-03-12 12:34:34 -05:00
parent 6569d10cb5
commit cc7d6ef42a
5 changed files with 119 additions and 24 deletions

View File

@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"auth": "graph auth",
"codegen": "graph codegen",
"build": "graph build",
"clean": "shx rm -rf ./build ./src/types ./subgraph.yaml",
@ -11,7 +12,7 @@
"remove-local": "graph remove --node http://localhost:8020/ graphprotocol/erc20-subgraph",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 graphprotocol/erc20-subgraph",
"deploy:ropsten": "npm prepare:ropsten && SUBGRAPH=bgits/status-snt npm deploy",
"deploy:mainnet": "npm run prepare:mainnet && SUBGRAPH=/bgits/snt-mainnet npm run deploy",
"deploy:mainnet": "npm run prepare:mainnet && SUBGRAPH=bgits/snt-mainnet yarn deploy",
"prepare:ropsten": "NETWORK_NAME=ropsten node ./templatify.js",
"prepare:mainnet": "NETWORK_NAME=mainnet node ./templatify.js"
},

View File

@ -98,8 +98,8 @@ type Token @entity {
" If token transfers are paused "
paused: Boolean
# TODO: Number of token holders
# holderCount: BigInt!
" Number of token holders "
holderCount: BigInt!
" Total number of events (all types)"
eventCount: BigInt!

View File

@ -2,7 +2,7 @@ import { BigDecimal, Bytes, EthereumEvent } from '@graphprotocol/graph-ts'
import { Account, AccountBalance, AccountBalanceSnapshot, Token } from '../../generated/schema'
import { ZERO } from '../helpers/number'
import { ZERO, ONE } from '../helpers/number'
export function getOrCreateAccount(accountAddress: Bytes): Account {
let accountId = accountAddress.toHex()
@ -30,6 +30,9 @@ function getOrCreateAccountBalance(account: Account, token: Token): AccountBalan
newBalance.account = account.id
newBalance.token = token.id
newBalance.amount = ZERO.toBigDecimal()
// increment token count
token.holderCount = token.holderCount.plus(ONE)
token.save()
return newBalance
}

View File

@ -1,17 +1,15 @@
import { Address, log, BigDecimal, Bytes, EthereumEvent, Value, JSONValue, } from '@graphprotocol/graph-ts'
import { Transfer } from '../../generated/templates/StandardToken/ERC20'
import { Burn } from '../../generated/templates/BurnableToken/Burnable'
import { Mint } from '../../generated/templates/MintableToken/Mintable'
import { Pause, Unpause, Paused, Unpaused } from '../../generated/templates/PausableToken/Pausable'
import { Transfer } from '../../generated/StandardToken/ERC20'
import { Burn } from '../../generated/BurnableToken/Burnable'
import { Mint } from '../../generated/MintableToken/Mintable'
import { Pause, Unpause, Paused, Unpaused } from '../../generated/PausableToken/Pausable'
import { Token, BurnEvent, MintEvent, TransferEvent, PauseEvent } from '../../generated/schema'
import { ERC20 } from '../../generated/TokenRegistry/ERC20'
import { ERC20 } from '../../generated/StandardToken/ERC20'
import { toDecimal, ONE, ZERO } from '../helpers/number'
import { decodeFlags, hasBurnEvent, hasMintEvent, DEFAULT_DECIMALS } from '../helpers/token'
import { BurnableToken, MintableToken, StandardToken } from '../../generated/templates'
import { createToken, IValue } from './registry'
import {
decreaseAccountBalance,
@ -61,10 +59,10 @@ export function handleTransfer(event: Transfer): void {
'handleTransfer, token: {}',
[token.address.toString()]
)
let amount = toDecimal(event.params.value, token.decimals)
let amount = toDecimal(event.params._amount, token.decimals)
let isBurn = token.flags.includes('burnable-transfer') && event.params.to.toHex() == GENESIS_ADDRESS
let isMint = token.flags.includes('mintable-transfer') && event.params.from.toHex() == GENESIS_ADDRESS
let isBurn = token.flags.includes('burnable-transfer') && event.params._to.toHex() == GENESIS_ADDRESS
let isMint = token.flags.includes('mintable-transfer') && event.params._from.toHex() == GENESIS_ADDRESS
let isTransfer = !isBurn && !isMint
// Update token event logs
@ -76,22 +74,22 @@ export function handleTransfer(event: Transfer): void {
// )
if (isBurn) {
let eventEntity = handleBurnEvent(token, amount, event.params.from, event)
let eventEntity = handleBurnEvent(token, amount, event.params._from, event)
eventEntityId = eventEntity.id
} else if (isMint) {
let eventEntity = handleMintEvent(token, amount, event.params.to, event)
let eventEntity = handleMintEvent(token, amount, event.params._to, event)
eventEntityId = eventEntity.id
} else if (isTransfer) {
let eventEntity = handleTransferEvent(token, amount, event.params.from, event.params.to, event)
let eventEntity = handleTransferEvent(token, amount, event.params._from, event.params._to, event)
eventEntityId = eventEntity.id
}
// Updates balances of accounts
if (isTransfer || isBurn) {
let sourceAccount = getOrCreateAccount(event.params.from)
let sourceAccount = getOrCreateAccount(event.params._from)
let accountBalance = decreaseAccountBalance(sourceAccount, token as Token, amount)
accountBalance.block = event.block.number
@ -106,7 +104,7 @@ export function handleTransfer(event: Transfer): void {
}
if (isTransfer || isMint) {
let destinationAccount = getOrCreateAccount(event.params.to)
let destinationAccount = getOrCreateAccount(event.params._to)
let accountBalance = increaseAccountBalance(destinationAccount, token as Token, amount)
accountBalance.block = event.block.number

103
yarn.lock
View File

@ -230,9 +230,9 @@ asn1@~0.2.3:
dependencies:
safer-buffer "~2.1.0"
"assemblyscript@https://github.com/AssemblyScript/assemblyscript#36040d5b5312f19a025782b5e36663823494c2f3":
"assemblyscript@git+https://github.com/AssemblyScript/assemblyscript.git#36040d5b5312f19a025782b5e36663823494c2f3":
version "0.6.0"
resolved "https://github.com/AssemblyScript/assemblyscript#36040d5b5312f19a025782b5e36663823494c2f3"
resolved "git+https://github.com/AssemblyScript/assemblyscript.git#36040d5b5312f19a025782b5e36663823494c2f3"
dependencies:
"@protobufjs/utf8" "^1.1.0"
binaryen "77.0.0-nightly.20190407"
@ -966,6 +966,11 @@ fsevents@~2.1.2:
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.1.2.tgz#4c0a1fb34bc68e543b4b82a9ec392bfbda840805"
integrity sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA==
function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
gauge@~2.7.3:
version "2.7.4"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
@ -1006,7 +1011,7 @@ glob-parent@~5.1.0:
dependencies:
is-glob "^4.0.1"
glob@^7.1.2, glob@^7.1.3:
glob@^7.0.0, glob@^7.1.2, glob@^7.1.3:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
@ -1067,6 +1072,18 @@ graphql@^14.0.2:
dependencies:
iterall "^1.2.2"
handlebars@^4.5.2:
version "4.7.7"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1"
integrity sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==
dependencies:
minimist "^1.2.5"
neo-async "^2.6.0"
source-map "^0.6.1"
wordwrap "^1.0.0"
optionalDependencies:
uglify-js "^3.1.4"
har-schema@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"
@ -1095,6 +1112,13 @@ has-unicode@^2.0.0:
resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9"
integrity sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=
has@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/has/-/has-1.0.3.tgz#722d7cbfc1f6aa8241f16dd814e011e1f41e8796"
integrity sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==
dependencies:
function-bind "^1.1.1"
hash-base@^3.0.0:
version "3.0.4"
resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-3.0.4.tgz#5fc8686847ecd73499403319a6b0a3f3f6ae4918"
@ -1175,6 +1199,11 @@ ini@~1.3.0:
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
interpret@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
ip-regex@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9"
@ -1322,6 +1351,13 @@ is-circular@^1.0.2:
resolved "https://registry.yarnpkg.com/is-circular/-/is-circular-1.0.2.tgz#2e0ab4e9835f4c6b0ea2b9855a84acd501b8366c"
integrity sha512-YttjnrswnUYRVJvxCvu8z+PGMUSzC2JttP0OEXezlAEdp3EXzhf7IZ3j0gRAybJBQupedIZFhY61Tga6E0qASA==
is-core-module@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.2.0.tgz#97037ef3d52224d85163f5597b2b63d9afed981a"
integrity sha512-XRAfAdyyY5F5cOXn7hYQDqh2Xmii+DEfIcQGxK/uNwMHhIkPWO0g8msXcbzLe+MpGoR951MlqM/2iIlU4vKDdQ==
dependencies:
has "^1.0.3"
is-electron@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-electron/-/is-electron-2.2.0.tgz#8943084f09e8b731b3a7a0298a7b5d56f6b7eef0"
@ -1796,7 +1832,7 @@ minimatch@^3.0.2, minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"
minimist@^1.2.0, minimist@^1.2.5:
minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
@ -1962,6 +1998,11 @@ napi-build-utils@^1.0.1:
split2 "^3.1.0"
through2 "^3.0.0"
neo-async@^2.6.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==
node-abi@^2.7.0:
version "2.15.0"
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.15.0.tgz#51d55cc711bd9e4a24a572ace13b9231945ccb10"
@ -2111,6 +2152,11 @@ path-key@^3.0.0, path-key@^3.1.0:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
path-type@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
@ -2344,6 +2390,13 @@ readdirp@~3.3.0:
dependencies:
picomatch "^2.0.7"
rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=
dependencies:
resolve "^1.1.6"
regenerator-runtime@^0.13.4:
version "0.13.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz#d878a1d094b4306d10b9096484b33ebd55e26697"
@ -2380,6 +2433,14 @@ resolve-from@^4.0.0:
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
resolve@^1.1.6:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
dependencies:
is-core-module "^2.2.0"
path-parse "^1.0.6"
restore-cursor@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e"
@ -2482,6 +2543,23 @@ shebang-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
shelljs@^0.8.4:
version "0.8.4"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2"
integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==
dependencies:
glob "^7.0.0"
interpret "^1.0.0"
rechoir "^0.6.2"
shx@^0.3.2:
version "0.3.3"
resolved "https://registry.yarnpkg.com/shx/-/shx-0.3.3.tgz#681a88c7c10db15abe18525349ed474f0f1e7b9f"
integrity sha512-nZJ3HFWVoTSyyB+evEKjJ1STiixGztlqwKLTUNV5KqMWtGey9fTd4KU1gdZ1X9BV6215pswQ/Jew9NsuS/fNDA==
dependencies:
minimist "^1.2.3"
shelljs "^0.8.4"
signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
@ -2516,7 +2594,7 @@ source-map-support@^0.5.11:
buffer-from "^1.0.0"
source-map "^0.6.0"
source-map@^0.6.0:
source-map@^0.6.0, source-map@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
@ -2720,6 +2798,16 @@ tweetnacl@^1.0.0:
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596"
integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==
typy@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/typy/-/typy-3.3.0.tgz#ed06e93f3329c87e3cee0df892929acffeb69eaa"
integrity sha512-Du53deMF9X9pSM3gVXDjLBq14BUfZWSGKfmmR1kTlg953RaIZehfc8fQuoAiW+SRO6bJsP+59mv1tsH8vwKghg==
uglify-js@^3.1.4:
version "3.13.0"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.13.0.tgz#66ed69f7241f33f13531d3d51d5bcebf00df7f69"
integrity sha512-TWYSWa9T2pPN4DIJYbU9oAjQx+5qdV5RUDxwARg8fmJZrD/V27Zj0JngW5xg1DFz42G0uDYl2XhzF6alSzD62w==
unique-by@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unique-by/-/unique-by-1.0.0.tgz#5220c86ba7bc572fb713ad74651470cb644212bd"
@ -2795,6 +2883,11 @@ wide-align@^1.1.0:
dependencies:
string-width "^1.0.2 || 2"
wordwrap@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=
wordwrap@~0.0.2:
version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"