Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple contracts in operation index, big_map index #38

Merged
merged 42 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9c2bc34
WIP
droserasprout Apr 14, 2021
e93a7f5
Multiple addresses WIP
droserasprout Apr 18, 2021
91a9a80
Merge branch 'feat/tezos-domains-demo' into feat/multiple-addresses
droserasprout Apr 18, 2021
ecbf8a0
Merge branch 'master' into feat/multiple-addresses
droserasprout Apr 20, 2021
246a8e9
WIP
droserasprout Apr 21, 2021
1cca743
WIP
droserasprout Apr 21, 2021
9725b87
WIP
droserasprout Apr 21, 2021
f426f38
Merge remote-tracking branch 'origin/master' into feat/multiple-addre…
droserasprout Apr 21, 2021
81b94fd
WIP
droserasprout Apr 21, 2021
8a0e627
WIP
droserasprout Apr 21, 2021
edbbef0
WIP
droserasprout Apr 21, 2021
585186f
WIP
droserasprout Apr 22, 2021
89680a7
WIP
droserasprout Apr 22, 2021
9a4d539
WIP
droserasprout Apr 22, 2021
d8a9967
WIP
droserasprout Apr 22, 2021
ff16c94
WIP
droserasprout Apr 23, 2021
5be03dc
Merge branch 'master' into feat/multiple-addresses
droserasprout Apr 24, 2021
4d49eb6
WIP
droserasprout Apr 27, 2021
b667adb
Merge branch 'master' into feat/multiple-addresses
droserasprout Apr 27, 2021
bd338d8
Fix test
droserasprout Apr 27, 2021
f40b497
Merge branch 'master' into feat/multiple-addresses
droserasprout Apr 27, 2021
daece2b
Merge branch 'feat/multiple-addresses' into feat/bigmap-index
droserasprout Apr 27, 2021
772678f
WIP
droserasprout Apr 27, 2021
6dfea37
WIP
droserasprout Apr 27, 2021
437514e
WIP
droserasprout Apr 27, 2021
5fd3545
WIP
droserasprout Apr 27, 2021
0ba797e
WIP
droserasprout Apr 28, 2021
48ec4f1
WIP
droserasprout Apr 28, 2021
5091c9a
WIP
droserasprout Apr 28, 2021
94fba16
WIP
droserasprout Apr 28, 2021
bf06d4b
big_map WIP
droserasprout Apr 28, 2021
163fde5
Cleanup
droserasprout Apr 28, 2021
6e78976
tezos_domains_big_map demo
droserasprout Apr 29, 2021
b42197d
Fix tests
droserasprout Apr 29, 2021
eb3e702
Fix latest_block request
droserasprout Apr 29, 2021
e3e9c31
Fix rollback
droserasprout Apr 29, 2021
5e72cc2
Simplify operation handler codeged
droserasprout Apr 29, 2021
07220f6
Update README
droserasprout Apr 29, 2021
1de9791
Fix rollback
droserasprout Apr 29, 2021
54f83a4
Revert removing resolve_big_maps
droserasprout Apr 29, 2021
65095c1
Lint
droserasprout Apr 29, 2021
5d1de7c
Hasura compatibility check
droserasprout Apr 29, 2021
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
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ indexes:
hen_mainnet:
kind: operation
datasource: tzkt_mainnet
contract: HEN_minter
contracts:
- HEN_minter
handlers:
- callback: on_mint
pattern:
Expand Down Expand Up @@ -125,19 +126,21 @@ class Token(Model):
Now take a look at `handlers` module generated by `init` command. When operation group matching `pattern` block of corresponding handler at config will arrive callback will be fired. This example will simply save minted Hic Et Nunc tokens and their owners to the database:

```python
from demo_hic_et_nunc.models import Holder, Token
from demo_hic_et_nunc.types.hen_minter.parameter.mint_objkt import MintOBJKT
from demo_hic_et_nunc.types.hen_objkts.parameter.mint import Mint
from dipdup.models import HandlerContext, OperationContext
import demo_hic_et_nunc.models as models
from demo_hic_et_nunc.types.hen_minter.parameter.mint_objkt import MintOBJKTParameter
from demo_hic_et_nunc.types.hen_minter.storage import HenMinterStorage
from demo_hic_et_nunc.types.hen_objkts.parameter.mint import MintParameter
from demo_hic_et_nunc.types.hen_objkts.storage import HenObjktsStorage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_mint(
ctx: HandlerContext,
mint_objkt: OperationContext[MintOBJKT],
mint: OperationContext[Mint],
ctx: OperationHandlerContext,
mint_objkt: OperationContext[MintOBJKTParameter, HenMinterStorage],
mint: OperationContext[MintParameter, HenObjktsStorage],
) -> None:
holder, _ = await Holder.get_or_create(address=mint.parameter.address)
token = Token(
holder, _ = await models.Holder.get_or_create(address=mint.parameter.address)
token = models.Token(
id=mint.parameter.token_id,
creator=holder,
supply=mint.parameter.amount,
Expand Down Expand Up @@ -193,19 +196,20 @@ templates:
trades:
kind: operation
datasource: tzkt_staging
contract: < dex >
contracts:
- <dex>
handlers:
- callback: on_fa12_token_to_tez
pattern:
- destination: < dex >
- destination: <dex>
entrypoint: tokenToTezPayment
- destination: < token >
- destination: <token>
entrypoint: transfer
- callback: on_fa20_tez_to_token
pattern:
- destination: < dex >
- destination: <dex>
entrypoint: tezToTokenPayment
- destination: < token >
- destination: <token>
entrypoint: transfer

indexes:
Expand Down
3 changes: 2 additions & 1 deletion src/demo_hic_et_nunc/dipdup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ indexes:
hen_mainnet:
kind: operation
datasource: tzkt_mainnet
contract: HEN_minter
contracts:
- HEN_minter
handlers:
- callback: on_mint
pattern:
Expand Down
8 changes: 4 additions & 4 deletions src/demo_hic_et_nunc/handlers/on_cancel_swap.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import demo_hic_et_nunc.models as models
from demo_hic_et_nunc.types.hen_minter.parameter.cancel_swap import CancelSwap as CancelSwapParameter
from demo_hic_et_nunc.types.hen_minter.storage import Storage as HenMinterStorage
from dipdup.models import HandlerContext, OperationContext
from demo_hic_et_nunc.types.hen_minter.parameter.cancel_swap import CancelSwapParameter
from demo_hic_et_nunc.types.hen_minter.storage import HenMinterStorage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_cancel_swap(
ctx: HandlerContext,
ctx: OperationHandlerContext,
cancel_swap: OperationContext[CancelSwapParameter, HenMinterStorage],
) -> None:
swap = await models.Swap.filter(id=int(cancel_swap.parameter.__root__)).get()
Expand Down
8 changes: 4 additions & 4 deletions src/demo_hic_et_nunc/handlers/on_collect.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import demo_hic_et_nunc.models as models
from demo_hic_et_nunc.types.hen_minter.parameter.collect import Collect as CollectParameter
from demo_hic_et_nunc.types.hen_minter.storage import Storage as HenMinterStorage
from dipdup.models import HandlerContext, OperationContext
from demo_hic_et_nunc.types.hen_minter.parameter.collect import CollectParameter
from demo_hic_et_nunc.types.hen_minter.storage import HenMinterStorage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_collect(
ctx: HandlerContext,
ctx: OperationHandlerContext,
collect: OperationContext[CollectParameter, HenMinterStorage],
) -> None:
swap = await models.Swap.filter(id=collect.parameter.swap_id).get()
Expand Down
12 changes: 6 additions & 6 deletions src/demo_hic_et_nunc/handlers/on_mint.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import demo_hic_et_nunc.models as models
from demo_hic_et_nunc.types.hen_minter.parameter.mint_objkt import MintOBJKT as MintOBJKTParameter
from demo_hic_et_nunc.types.hen_minter.storage import Storage as HenMinterStorage
from demo_hic_et_nunc.types.hen_objkts.parameter.mint import Mint as MintParameter
from demo_hic_et_nunc.types.hen_objkts.storage import Storage as HenObjktsStorage
from dipdup.models import HandlerContext, OperationContext
from demo_hic_et_nunc.types.hen_minter.parameter.mint_objkt import MintOBJKTParameter
from demo_hic_et_nunc.types.hen_minter.storage import HenMinterStorage
from demo_hic_et_nunc.types.hen_objkts.parameter.mint import MintParameter
from demo_hic_et_nunc.types.hen_objkts.storage import HenObjktsStorage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_mint(
ctx: HandlerContext,
ctx: OperationHandlerContext,
mint_objkt: OperationContext[MintOBJKTParameter, HenMinterStorage],
mint: OperationContext[MintParameter, HenObjktsStorage],
) -> None:
Expand Down
8 changes: 4 additions & 4 deletions src/demo_hic_et_nunc/handlers/on_swap.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import demo_hic_et_nunc.models as models
from demo_hic_et_nunc.types.hen_minter.parameter.swap import Swap as SwapParameter
from demo_hic_et_nunc.types.hen_minter.storage import Storage as HenMinterStorage
from dipdup.models import HandlerContext, OperationContext
from demo_hic_et_nunc.types.hen_minter.parameter.swap import SwapParameter
from demo_hic_et_nunc.types.hen_minter.storage import HenMinterStorage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_swap(
ctx: HandlerContext,
ctx: OperationHandlerContext,
swap: OperationContext[SwapParameter, HenMinterStorage],
) -> None:
holder, _ = await models.Holder.get_or_create(address=swap.data.sender_address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
from pydantic import BaseModel


class CancelSwap(BaseModel):
class CancelSwapParameter(BaseModel):
__root__: str
2 changes: 1 addition & 1 deletion src/demo_hic_et_nunc/types/hen_minter/parameter/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
from pydantic import BaseModel


class Collect(BaseModel):
class CollectParameter(BaseModel):
objkt_amount: str
swap_id: str
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import BaseModel


class MintOBJKT(BaseModel):
class MintOBJKTParameter(BaseModel):
address: str
amount: str
metadata: str
Expand Down
2 changes: 1 addition & 1 deletion src/demo_hic_et_nunc/types/hen_minter/parameter/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pydantic import BaseModel


class Swap(BaseModel):
class SwapParameter(BaseModel):
objkt_amount: str
objkt_id: str
xtz_per_objkt: str
2 changes: 1 addition & 1 deletion src/demo_hic_et_nunc/types/hen_minter/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Swaps(BaseModel):
xtz_per_objkt: str


class Storage(BaseModel):
class HenMinterStorage(BaseModel):
curate: str
genesis: str
hdao: str
Expand Down
2 changes: 1 addition & 1 deletion src/demo_hic_et_nunc/types/hen_objkts/parameter/mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pydantic import BaseModel


class Mint(BaseModel):
class MintParameter(BaseModel):
address: str
amount: str
token_id: str
Expand Down
4 changes: 2 additions & 2 deletions src/demo_hic_et_nunc/types/hen_objkts/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class LedgerItem(BaseModel):


class Key1(BaseModel):
owner: str
operator: str
owner: str
token_id: str


Expand All @@ -34,7 +34,7 @@ class TokenMetadata(BaseModel):
token_info: Dict[str, str]


class Storage(BaseModel):
class HenObjktsStorage(BaseModel):
administrator: str
all_tokens: str
ledger: List[LedgerItem]
Expand Down
6 changes: 4 additions & 2 deletions src/demo_quipuswap/dipdup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ templates:
quipuswap_fa12:
kind: operation
datasource: tzkt_staging_mainnet
contract: <dex_contract>
contracts:
- <dex_contract>
handlers:
- callback: on_fa12_token_to_tez
pattern:
Expand Down Expand Up @@ -68,7 +69,8 @@ templates:
quipuswap_fa2:
kind: operation
datasource: tzkt_staging_mainnet
contract: <dex_contract>
contracts:
- <dex_contract>
handlers:
- callback: on_fa2_token_to_tez
pattern:
Expand Down
12 changes: 6 additions & 6 deletions src/demo_quipuswap/handlers/on_fa12_divest_liquidity.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from decimal import Decimal

import demo_quipuswap.models as models
from demo_quipuswap.types.fa12_token.parameter.transfer import Transfer as TransferParameter
from demo_quipuswap.types.fa12_token.storage import Storage as Fa12TokenStorage
from demo_quipuswap.types.quipu_fa12.parameter.divest_liquidity import DivestLiquidity as DivestLiquidityParameter
from demo_quipuswap.types.quipu_fa12.storage import Storage as QuipuFa12Storage
from dipdup.models import HandlerContext, OperationContext
from demo_quipuswap.types.fa12_token.parameter.transfer import TransferParameter
from demo_quipuswap.types.fa12_token.storage import Fa12TokenStorage
from demo_quipuswap.types.quipu_fa12.parameter.divest_liquidity import DivestLiquidityParameter
from demo_quipuswap.types.quipu_fa12.storage import QuipuFa12Storage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_fa12_divest_liquidity(
ctx: HandlerContext,
ctx: OperationHandlerContext,
divest_liquidity: OperationContext[DivestLiquidityParameter, QuipuFa12Storage],
transfer: OperationContext[TransferParameter, Fa12TokenStorage],
) -> None:
Expand Down
14 changes: 7 additions & 7 deletions src/demo_quipuswap/handlers/on_fa12_invest_liquidity.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from decimal import Decimal

import demo_quipuswap.models as models
from demo_quipuswap.types.fa12_token.parameter.transfer import Transfer as TransferParameter
from demo_quipuswap.types.fa12_token.storage import Storage as Fa12TokenStorage
from demo_quipuswap.types.quipu_fa12.parameter.invest_liquidity import InvestLiquidity as InvestLiquidityParameter
from demo_quipuswap.types.quipu_fa12.storage import Storage as QuipuFa12Storage
from dipdup.models import HandlerContext, OperationContext
from demo_quipuswap.types.fa12_token.parameter.transfer import TransferParameter
from demo_quipuswap.types.fa12_token.storage import Fa12TokenStorage
from demo_quipuswap.types.quipu_fa12.parameter.invest_liquidity import InvestLiquidityParameter
from demo_quipuswap.types.quipu_fa12.storage import QuipuFa12Storage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_fa12_invest_liquidity(
ctx: HandlerContext,
ctx: OperationHandlerContext,
invest_liquidity: OperationContext[InvestLiquidityParameter, QuipuFa12Storage],
transfer: OperationContext[TransferParameter, Fa12TokenStorage],
) -> None:
Expand All @@ -26,7 +26,7 @@ async def on_fa12_invest_liquidity(

tez_qty = Decimal(invest_liquidity.data.amount) / (10 ** 6)
token_qty = Decimal(transfer.parameter.value) / (10 ** decimals)
new_shares_qty = int(storage.storage.ledger[trader].balance) + int(storage.storage.ledger[trader].frozen_balance)
new_shares_qty = int(storage.storage.ledger[trader].balance) + int(storage.storage.ledger[trader].frozen_balance) # type: ignore

price = (Decimal(storage.storage.tez_pool) / (10 ** 6)) / (Decimal(storage.storage.token_pool) / (10 ** decimals))
value = tez_qty + price * token_qty
Expand Down
12 changes: 6 additions & 6 deletions src/demo_quipuswap/handlers/on_fa12_tez_to_token.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from decimal import Decimal

import demo_quipuswap.models as models
from demo_quipuswap.types.fa12_token.parameter.transfer import Transfer as TransferParameter
from demo_quipuswap.types.fa12_token.storage import Storage as Fa12TokenStorage
from demo_quipuswap.types.quipu_fa12.parameter.tez_to_token_payment import TezToTokenPayment as TezToTokenPaymentParameter
from demo_quipuswap.types.quipu_fa12.storage import Storage as QuipuFa12Storage
from dipdup.models import HandlerContext, OperationContext
from demo_quipuswap.types.fa12_token.parameter.transfer import TransferParameter
from demo_quipuswap.types.fa12_token.storage import Fa12TokenStorage
from demo_quipuswap.types.quipu_fa12.parameter.tez_to_token_payment import TezToTokenPaymentParameter
from demo_quipuswap.types.quipu_fa12.storage import QuipuFa12Storage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_fa12_tez_to_token(
ctx: HandlerContext,
ctx: OperationHandlerContext,
tez_to_token_payment: OperationContext[TezToTokenPaymentParameter, QuipuFa12Storage],
transfer: OperationContext[TransferParameter, Fa12TokenStorage],
) -> None:
Expand Down
12 changes: 6 additions & 6 deletions src/demo_quipuswap/handlers/on_fa12_token_to_tez.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from decimal import Decimal

import demo_quipuswap.models as models
from demo_quipuswap.types.fa12_token.parameter.transfer import Transfer as TransferParameter
from demo_quipuswap.types.fa12_token.storage import Storage as Fa12TokenStorage
from demo_quipuswap.types.quipu_fa12.parameter.token_to_tez_payment import TokenToTezPayment as TokenToTezPaymentParameter
from demo_quipuswap.types.quipu_fa12.storage import Storage as QuipuFa12Storage
from dipdup.models import HandlerContext, OperationContext
from demo_quipuswap.types.fa12_token.parameter.transfer import TransferParameter
from demo_quipuswap.types.fa12_token.storage import Fa12TokenStorage
from demo_quipuswap.types.quipu_fa12.parameter.token_to_tez_payment import TokenToTezPaymentParameter
from demo_quipuswap.types.quipu_fa12.storage import QuipuFa12Storage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_fa12_token_to_tez(
ctx: HandlerContext,
ctx: OperationHandlerContext,
token_to_tez_payment: OperationContext[TokenToTezPaymentParameter, QuipuFa12Storage],
transfer: OperationContext[TransferParameter, Fa12TokenStorage],
) -> None:
Expand Down
8 changes: 4 additions & 4 deletions src/demo_quipuswap/handlers/on_fa12_withdraw_profit.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from decimal import Decimal

import demo_quipuswap.models as models
from demo_quipuswap.types.quipu_fa12.parameter.withdraw_profit import WithdrawProfit as WithdrawProfitParameter
from demo_quipuswap.types.quipu_fa12.storage import Storage as QuipuFa12Storage
from dipdup.models import HandlerContext, OperationContext
from demo_quipuswap.types.quipu_fa12.parameter.withdraw_profit import WithdrawProfitParameter
from demo_quipuswap.types.quipu_fa12.storage import QuipuFa12Storage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_fa12_withdraw_profit(
ctx: HandlerContext,
ctx: OperationHandlerContext,
withdraw_profit: OperationContext[WithdrawProfitParameter, QuipuFa12Storage],
) -> None:

Expand Down
12 changes: 6 additions & 6 deletions src/demo_quipuswap/handlers/on_fa20_divest_liquidity.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from decimal import Decimal

import demo_quipuswap.models as models
from demo_quipuswap.types.fa2_token.parameter.transfer import Transfer as TransferParameter
from demo_quipuswap.types.fa2_token.storage import Storage as Fa2TokenStorage
from demo_quipuswap.types.quipu_fa2.parameter.divest_liquidity import DivestLiquidity as DivestLiquidityParameter
from demo_quipuswap.types.quipu_fa2.storage import Storage as QuipuFa2Storage
from dipdup.models import HandlerContext, OperationContext
from demo_quipuswap.types.fa2_token.parameter.transfer import TransferParameter
from demo_quipuswap.types.fa2_token.storage import Fa2TokenStorage
from demo_quipuswap.types.quipu_fa2.parameter.divest_liquidity import DivestLiquidityParameter
from demo_quipuswap.types.quipu_fa2.storage import QuipuFa2Storage
from dipdup.models import OperationContext, OperationHandlerContext


async def on_fa20_divest_liquidity(
ctx: HandlerContext,
ctx: OperationHandlerContext,
divest_liquidity: OperationContext[DivestLiquidityParameter, QuipuFa2Storage],
transfer: OperationContext[TransferParameter, Fa2TokenStorage],
) -> None:
Expand Down
Loading