Skip to content

Commit

Permalink
190-Index-and-track-other-stablecoins-balances (#197)
Browse files Browse the repository at this point in the history
* fix: track transfers withdrawals and deposits on orml

* fix: skip endowments

* feat: refert to modulo filter
  • Loading branch information
filo87 authored Feb 1, 2024
1 parent e16160e commit 4192462
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export COMPOSE_PROFILES=subql
export COMPOSE_PROFILES=subql-cfg
export DB_USER=postgres
export DB_PASS=postgres
export DB_DATABASE=postgres
Expand Down
8 changes: 2 additions & 6 deletions chains-cfg/_root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dataSources:
- handler: handleBlock
kind: substrate/BlockHandler
filter:
timestamp: '1 0,12 * * *'
modulo: 300
#timestamp: '1 0,12 * * *'
# - handler: logEvents
# kind: substrate/EventHandler
- handler: handlePoolCreated
Expand Down Expand Up @@ -109,11 +110,6 @@ dataSources:
filter:
module: ormlTokens
method: Transfer
- handler: handleTokenEndowed
kind: substrate/EventHandler
filter:
module: ormlTokens
method: Endowed
- handler: handleTokenDeposited
kind: substrate/EventHandler
filter:
Expand Down
2 changes: 2 additions & 0 deletions chains-cfg/centrifuge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ network:
chainId: '0xb3db41421702df9a7fcac62b53ffeac85f7853cc4e689e0b93aeb3db18c09d82'
chaintypes:
file: ./dist/chaintypes.js
bypassBlocks:
- "3858150-4216110"
dataSources:
- kind: substrate/Runtime
startBlock: 3858140 # block first pool was created at
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ type Currency @entity {
id: ID! # chainId - currencySpec - [currencySpec]
chain: Blockchain!
decimals: Int!
name: String
symbol: String

tokenAddress: String
escrowAddress: String
Expand Down
20 changes: 0 additions & 20 deletions src/mappings/handlers/ormlTokensHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,6 @@ async function _handleTokenTransfer(event: SubstrateEvent<TokensTransferEvent>):
}
}

export const handleTokenEndowed = errorHandler(_handleTokenEndowed)
async function _handleTokenEndowed(event: SubstrateEvent<TokensEndowedDepositedWithdrawnEvent>): Promise<void> {
const [_currency, address, amount] = event.event.data
if (_currency.isTranche) return
logger.info(
`Currency endowment in ${_currency.toString()} for: ${address.toHex()} amount: ${amount.toString()} ` +
`at block ${event.block.block.header.number.toString()}`
)
const blockchain = await BlockchainService.getOrInit()
const currency = await CurrencyService.getOrInit(
blockchain.id,
_currency.type,
...currencyFormatters[_currency.type](_currency.value)
)
const toAccount = await AccountService.getOrInit(address.toHex())
const toCurrencyBalance = await CurrencyBalanceService.getOrInit(toAccount.id, currency.id)
await toCurrencyBalance.credit(amount.toBigInt())
await toCurrencyBalance.save()
}

export const handleTokenDeposited = errorHandler(_handleTokenDeposited)
async function _handleTokenDeposited(event: SubstrateEvent<TokensEndowedDepositedWithdrawnEvent>): Promise<void> {
const [_currency, address, amount] = event.event.data
Expand Down
8 changes: 6 additions & 2 deletions src/mappings/services/currencyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { WAD_DIGITS } from '../../config'
import type { TokensCurrencyId } from '../../helpers/types'

export class CurrencyService extends Currency {
static init(chainId: string, currencyId: string, decimals: number) {
static init(chainId: string, currencyId: string, decimals: number, symbol?: string, name?: string) {
const id = `${chainId}-${currencyId}`
logger.info(`Initialising new currency ${id} with ${decimals} decimals`)
const currency = new this(id, chainId, decimals)
currency.symbol = symbol
currency.name = name
return currency
}

Expand All @@ -20,7 +22,9 @@ export class CurrencyService extends Currency {
const enumPayload = formatEnumPayload(currencyType, ...currencyValue)
const assetMetadata = (await api.query.ormlAssetRegistry.metadata(enumPayload)) as Option<AssetMetadata>
const decimals = assetMetadata.isSome ? assetMetadata.unwrap().decimals.toNumber() : WAD_DIGITS
currency = this.init(chainId, currencyId, decimals)
const symbol = assetMetadata.isSome ? assetMetadata.unwrap().symbol.toUtf8() : undefined
const name = assetMetadata.isSome ? assetMetadata.unwrap().name.toUtf8() : undefined
currency = this.init(chainId, currencyId, decimals, symbol, name)
await currency.save()
}
return currency as CurrencyService
Expand Down

0 comments on commit 4192462

Please sign in to comment.