Skip to content

Commit cefdcdd

Browse files
Improve typechecking (#357)
1 parent e2e055b commit cefdcdd

File tree

27 files changed

+86
-64
lines changed

27 files changed

+86
-64
lines changed

src/demo_hic_et_nunc/handlers/on_collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def on_collect(
2323
)
2424
await trade.save()
2525

26-
swap.amount_left -= int(collect.parameter.objkt_amount) # type: ignore
26+
swap.amount_left -= int(collect.parameter.objkt_amount)
2727
if swap.amount_left == 0:
2828
swap.status = models.SwapStatus.FINISHED
2929
await swap.save()

src/demo_hic_et_nunc/handlers/on_swap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async def on_swap(
1111
) -> None:
1212
holder, _ = await models.Holder.get_or_create(address=swap.data.sender_address)
1313
swap_model = models.Swap(
14-
id=int(swap.storage.swap_id) - 1, # type: ignore
14+
id=int(swap.storage.swap_id) - 1,
1515
creator=holder,
1616
price=swap.parameter.xtz_per_objkt,
1717
amount=swap.parameter.objkt_amount,

src/demo_quipuswap/handlers/on_fa12_divest_liquidity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def on_fa12_divest_liquidity(
4040
share_px = (tez_qty + price * token_qty) / shares_qty
4141

4242
position.realized_pl += shares_qty * (share_px - position.avg_share_px)
43-
position.shares_qty -= shares_qty # type: ignore
43+
position.shares_qty -= shares_qty
4444
assert position.shares_qty >= 0, divest_liquidity.data.hash
4545

4646
await position.save()

src/demo_quipuswap/handlers/on_fa12_invest_liquidity.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ async def on_fa12_invest_liquidity(
2020
symbol = ctx.template_values['symbol']
2121
trader = invest_liquidity.data.sender_address
2222

23+
assert trader is not None
24+
2325
position, _ = await models.Position.get_or_create(trader=trader, symbol=symbol)
2426

2527
assert invest_liquidity.data.amount is not None
2628
tez_qty = Decimal(invest_liquidity.data.amount) / (10**6)
2729
token_qty = Decimal(transfer.parameter.value) / (10**decimals)
28-
new_shares_qty = int(storage.storage.ledger[trader].balance) + int(storage.storage.ledger[trader].frozen_balance) # type: ignore
30+
new_shares_qty = int(storage.storage.ledger[trader].balance) + int(storage.storage.ledger[trader].frozen_balance)
2931

3032
price = (Decimal(storage.storage.tez_pool) / (10**6)) / (Decimal(storage.storage.token_pool) / (10**decimals))
3133
value = tez_qty + price * token_qty
3234
share_px = value / (new_shares_qty - position.shares_qty)
3335
assert share_px > 0, invest_liquidity.data.hash
3436

3537
position.avg_share_px = (position.shares_qty * position.avg_share_px + value) / new_shares_qty
36-
position.shares_qty = new_shares_qty # type: ignore
38+
position.shares_qty = new_shares_qty
3739

3840
await position.save()

src/demo_quipuswap/handlers/on_fa12_transfer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ async def on_fa12_transfer(
1515
value = int(transfer.parameter.value)
1616

1717
from_position, _ = await models.Position.get_or_create(trader=from_address, symbol=symbol)
18-
from_position.shares_qty -= value # type: ignore
18+
from_position.shares_qty -= value
1919
assert from_position.shares_qty >= 0, transfer.data.hash
2020
await from_position.save()
2121

2222
to_position, _ = await models.Position.get_or_create(trader=to_address, symbol=symbol)
23-
to_position.shares_qty += value # type: ignore
23+
to_position.shares_qty += value
2424
assert to_position.shares_qty >= 0, transfer.data.hash
2525
await to_position.save()

src/demo_quipuswap/handlers/on_fa12_withdraw_profit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ async def on_fa12_withdraw_profit(
2020
position, _ = await models.Position.get_or_create(trader=trader, symbol=symbol)
2121
if transaction_0:
2222
assert transaction_0.amount is not None
23-
position.realized_pl += Decimal(transaction_0.amount) / (10**6) # type: ignore
23+
position.realized_pl += Decimal(transaction_0.amount) / (10**6)
2424

2525
await position.save()

src/demo_quipuswap/handlers/on_fa2_divest_liquidity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def on_fa2_divest_liquidity(
4040
share_px = (tez_qty + price * token_qty) / shares_qty
4141

4242
position.realized_pl += shares_qty * (share_px - position.avg_share_px)
43-
position.shares_qty -= shares_qty # type: ignore
43+
position.shares_qty -= shares_qty
4444
assert position.shares_qty >= 0, divest_liquidity.data.hash
4545

4646
await position.save()

src/demo_quipuswap/handlers/on_fa2_invest_liquidity.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,21 @@ async def on_fa2_invest_liquidity(
2020
symbol = ctx.template_values['symbol']
2121
trader = invest_liquidity.data.sender_address
2222

23+
assert trader is not None
24+
2325
position, _ = await models.Position.get_or_create(trader=trader, symbol=symbol)
2426

2527
assert invest_liquidity.data.amount is not None
2628
tez_qty = Decimal(invest_liquidity.data.amount) / (10**6)
2729
token_qty = sum(Decimal(tx.amount) for tx in transfer.parameter.__root__[0].txs) / (10**decimals)
28-
new_shares_qty = int(storage.storage.ledger[trader].balance) + int(storage.storage.ledger[trader].frozen_balance) # type: ignore
30+
new_shares_qty = int(storage.storage.ledger[trader].balance) + int(storage.storage.ledger[trader].frozen_balance)
2931

3032
price = (Decimal(storage.storage.tez_pool) / (10**6)) / (Decimal(storage.storage.token_pool) / (10**decimals))
3133
value = tez_qty + price * token_qty
3234
share_px = value / (new_shares_qty - position.shares_qty)
3335
assert share_px > 0, invest_liquidity.data.hash
3436

3537
position.avg_share_px = (position.shares_qty * position.avg_share_px + value) / new_shares_qty
36-
position.shares_qty = new_shares_qty # type: ignore
38+
position.shares_qty = new_shares_qty
3739

3840
await position.save()

src/demo_quipuswap/handlers/on_fa2_transfer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ async def on_fa2_transfer(
1919
to_address = transfer_tx.to_
2020
value = int(transfer_tx.amount)
2121

22-
from_position.shares_qty -= value # type: ignore
22+
from_position.shares_qty -= value
2323
assert from_position.shares_qty >= 0, transfer.data.hash
2424

2525
to_position, _ = await models.Position.get_or_create(trader=to_address, symbol=symbol)
26-
to_position.shares_qty += value # type: ignore
26+
to_position.shares_qty += value
2727
assert to_position.shares_qty >= 0, transfer.data.hash
2828
await to_position.save()
2929

src/demo_quipuswap/handlers/on_fa2_withdraw_profit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ async def on_fa2_withdraw_profit(
2121

2222
if transaction_0:
2323
assert transaction_0.amount is not None
24-
position.realized_pl += Decimal(transaction_0.amount) / (10**6) # type: ignore
24+
position.realized_pl += Decimal(transaction_0.amount) / (10**6)
2525

2626
await position.save()

0 commit comments

Comments
 (0)