-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,32 @@ | ||
spec_version: 0.1 | ||
package: demo_tzbtc | ||
|
||
database: | ||
kind: sqlite | ||
path: demo_tzbtc.sqlite3 | ||
|
||
contracts: | ||
tzbtc_mainnet: | ||
address: KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn | ||
typename: tzbtc | ||
|
||
datasources: | ||
tzkt_staging: | ||
kind: tzkt | ||
url: https://staging.api.tzkt.io | ||
|
||
indexes: | ||
tzbtc_holders_mainnet: | ||
kind: operation | ||
datasource: tzkt_staging | ||
contracts: | ||
- tzbtc_mainnet | ||
handlers: | ||
- callback: on_transfer | ||
pattern: | ||
- destination: tzbtc_mainnet | ||
entrypoint: transfer | ||
- callback: on_mint | ||
pattern: | ||
- destination: tzbtc_mainnet | ||
entrypoint: mint |
Empty file.
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,14 @@ | ||
from decimal import Decimal | ||
from datetime import datetime | ||
|
||
import demo_tzbtc.models as models | ||
|
||
|
||
async def on_balance_update(address: str, balance_update: Decimal, timestamp: datetime): | ||
holder, _ = await models.Holder.get_or_create(address=address) | ||
holder.balance += balance_update # type: ignore | ||
holder.turnover += abs(balance_update) # type: ignore | ||
holder.tx_count += 1 # type: ignore | ||
holder.last_seen = timestamp # type: ignore | ||
assert holder.balance >= 0, address | ||
await holder.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,16 @@ | ||
from decimal import Decimal | ||
from typing import Optional | ||
|
||
import demo_tzbtc.models as models | ||
from demo_tzbtc.handlers.on_balance_update import on_balance_update | ||
from demo_tzbtc.types.tzbtc.parameter.mint import MintParameter | ||
from demo_tzbtc.types.tzbtc.storage import TzbtcStorage | ||
from dipdup.models import OperationData, OperationHandlerContext, OriginationContext, TransactionContext | ||
|
||
|
||
async def on_mint( | ||
ctx: OperationHandlerContext, | ||
mint: TransactionContext[MintParameter, TzbtcStorage], | ||
) -> None: | ||
amount = Decimal(mint.parameter.value) / (10 ** 8) | ||
await on_balance_update(address=mint.parameter.to, balance_update=amount, timestamp=mint.data.timestamp) |
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,15 @@ | ||
import logging | ||
|
||
from dipdup.utils import reindex | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
async def on_rollback( | ||
from_level: int, | ||
to_level: int, | ||
) -> None: | ||
if from_level - to_level == 1: | ||
return | ||
_logger.warning('Rollback event received, reindexing') | ||
await reindex() |
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,19 @@ | ||
from decimal import Decimal | ||
from typing import Optional | ||
|
||
import demo_tzbtc.models as models | ||
from demo_tzbtc.handlers.on_balance_update import on_balance_update | ||
from demo_tzbtc.types.tzbtc.parameter.transfer import TransferParameter | ||
from demo_tzbtc.types.tzbtc.storage import TzbtcStorage | ||
from dipdup.models import OperationData, OperationHandlerContext, OriginationContext, TransactionContext | ||
|
||
|
||
async def on_transfer( | ||
ctx: OperationHandlerContext, | ||
transfer: TransactionContext[TransferParameter, TzbtcStorage], | ||
) -> None: | ||
if transfer.parameter.from_ == transfer.parameter.to: | ||
return | ||
amount = Decimal(transfer.parameter.value) / (10 ** 8) | ||
await on_balance_update(address=transfer.parameter.from_, balance_update=-amount, timestamp=transfer.data.timestamp) | ||
await on_balance_update(address=transfer.parameter.to, balance_update=amount, timestamp=transfer.data.timestamp) |
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,9 @@ | ||
from tortoise import Model, fields | ||
|
||
|
||
class Holder(Model): | ||
address = fields.CharField(max_length=36, pk=True) | ||
balance = fields.DecimalField(decimal_places=8, max_digits=20, default=0) | ||
turnover = fields.DecimalField(decimal_places=8, max_digits=20, default=0) | ||
tx_count = fields.BigIntField(default=0) | ||
last_seen = fields.DatetimeField(null=True) |
Empty file.
Empty file.
Empty file.
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 @@ | ||
# generated by datamodel-codegen: | ||
# filename: mint.json | ||
|
||
from __future__ import annotations | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class MintParameter(BaseModel): | ||
to: str | ||
value: str |
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,12 @@ | ||
# generated by datamodel-codegen: | ||
# filename: transfer.json | ||
|
||
from __future__ import annotations | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class TransferParameter(BaseModel): | ||
from_: str = Field(..., alias='from') | ||
to: str | ||
value: str |
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,15 @@ | ||
# generated by datamodel-codegen: | ||
# filename: storage.json | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Dict | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class TzbtcStorage(BaseModel): | ||
big_map: Dict[str, str] | ||
bool: bool | ||
lambda_: str = Field(..., alias='lambda') | ||
nat: str |