Skip to content

Commit

Permalink
Merge pull request #41 from theeldermillenial/feat/sundaev3
Browse files Browse the repository at this point in the history
Feat/sundaev3
  • Loading branch information
theeldermillenial authored Jul 1, 2024
2 parents c32fdd4 + dbbb4d1 commit ac266d4
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.0-dev86
current_version = 0.2.0-dev91
commit = True
commit_args = --no-verify
tag = True
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cardex"
version = "0.2.0-dev86"
version = "0.2.0-dev91"
description = ""
authors = ["Elder Millenial <eldermillenial@protonmail.com>"]
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions src/cardex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cardex.dexs.amm.muesli import MuesliSwapCPPState
from cardex.dexs.amm.spectrum import SpectrumCPPState
from cardex.dexs.amm.sundae import SundaeSwapCPPState
from cardex.dexs.amm.sundae import SundaeSwapV3CPPState
from cardex.dexs.amm.vyfi import VyFiCPPState
from cardex.dexs.amm.wingriders import WingRidersCPPState
from cardex.dexs.amm.wingriders import WingRidersSSPState
Expand Down
40 changes: 40 additions & 0 deletions src/cardex/backend/dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,46 @@ def get_script_from_address(address: Address) -> ScriptReference:
return ScriptReference.model_validate(r[0])


def get_datum_from_address(address: Address) -> ScriptReference:
SCRIPT_SELECTOR = """
SELECT ENCODE(tx.hash, 'hex') as "tx_hash",
tx_out.index as "tx_index",
tx_out.address,
ENCODE(datum.hash,'hex') as "datum_hash",
ENCODE(datum.bytes,'hex') as "datum_cbor",
COALESCE (
json_build_object('lovelace',tx_out.value::TEXT)::jsonb || (
SELECT json_agg(
json_build_object(
CONCAT(encode(ma.policy, 'hex'), encode(ma.name, 'hex')),
mto.quantity::TEXT
)
)
FROM ma_tx_out mto
JOIN multi_asset ma ON (mto.ident = ma.id)
WHERE mto.tx_out_id = tx_out.id
)::jsonb,
jsonb_build_array(json_build_object('lovelace',tx_out.value::TEXT)::jsonb)
) AS "assets",
ENCODE(s.bytes, 'hex') as "script"
FROM tx_out
LEFT JOIN tx ON tx.id = tx_out.tx_id
LEFT JOIN datum ON tx_out.inline_datum_id = datum.id
LEFT JOIN block on block.id = tx.block_id
LEFT JOIN script s ON s.id = tx_out.reference_script_id
WHERE tx_out.payment_cred = %(address)b
AND tx_out.inline_datum_id IS NOT NULL
ORDER BY block.time DESC
LIMIT 1
"""
r = db_query(SCRIPT_SELECTOR, {"address": address.payment_part.payload})

if r[0]["assets"] is not None and r[0]["assets"][0]["lovelace"] is None:
r[0]["assets"] = None

return ScriptReference.model_validate(r[0])


def get_datum_from_address(
address: Address,
asset: str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/cardex/dataclasses/datums.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PlutusFullAddress(PlutusData):
"""A full address, including payment and staking keys."""

CONSTR_ID = 0
payment: PlutusPartAddress
payment: Union[PlutusPartAddress, PlutusScriptPartAddress]
stake: Union[_PlutusConstrWrapper, PlutusNone]

@classmethod
Expand Down
1 change: 1 addition & 0 deletions src/cardex/dexs/amm/amm_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def extract_pool_nft(cls, values) -> Assets:
for asset in assets
if any(asset.startswith(policy) for policy in cls.pool_policy)
]

if len(nfts) != 1:
raise InvalidPoolError(
f"{cls.__name__}: A pool must have one pool NFT token.",
Expand Down
Loading

0 comments on commit ac266d4

Please sign in to comment.