Skip to content

Minswap

Minswap DEX Module.

Deposit dataclass

Bases: PlutusData

Swap exact in order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
153
154
155
156
157
158
@dataclass
class Deposit(PlutusData):
    """Swap exact in order datum."""

    CONSTR_ID = 2
    minimum_lp: int

DepositV2 dataclass

Bases: PlutusData

DepositV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
365
366
367
368
369
370
371
372
@dataclass
class DepositV2(PlutusData):
    """DepositV2 order datum."""

    CONSTR_ID = 4
    deposit_amount_option: Datum
    minimum_lp: int
    killable: Union[BoolTrue, BoolFalse]

DonationV2 dataclass

Bases: PlutusData

SwapMultiRoutingV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
433
434
435
436
437
@dataclass
class DonationV2(PlutusData):
    """SwapMultiRoutingV2 order datum."""

    CONSTR_ID = 10

Expire dataclass

Bases: PlutusData

SwapMultiRoutingV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
476
477
478
479
480
481
482
@dataclass
class Expire(PlutusData):
    """SwapMultiRoutingV2 order datum."""

    CONSTR_ID = 0

    ttl: List[int]

FeeDatumHash dataclass

Bases: PlutusData

Fee datum hash.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
664
665
666
667
668
669
@dataclass
class FeeDatumHash(PlutusData):
    """Fee datum hash."""

    CONSTR_ID = 0
    fee_hash: bytes

FeeSwitchOn dataclass

Bases: PlutusData

Fee switch on.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
672
673
674
675
676
677
678
@dataclass
class FeeSwitchOn(PlutusData):
    """Fee switch on."""

    CONSTR_ID = 0
    address: PlutusFullAddress
    fee_to_datum_hash: PlutusNone

MinswapCPPState

Bases: AbstractConstantProductPoolState

Minswap Constant Product Pool State.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
class MinswapCPPState(AbstractConstantProductPoolState):
    """Minswap Constant Product Pool State."""

    fee: int = 30
    _batcher = Assets(lovelace=2000000)
    _deposit = Assets(lovelace=2000000)
    _stake_address: ClassVar[Address] = [
        Address.from_primitive(
            "addr1zxn9efv2f6w82hagxqtn62ju4m293tqvw0uhmdl64ch8uw6j2c79gy9l76sdg0xwhd7r0c0kna0tycz4y5s6mlenh8pq6s3z70",
        ),
        Address.from_primitive(
            "addr1wxn9efv2f6w82hagxqtn62ju4m293tqvw0uhmdl64ch8uwc0h43gt",
        ),
    ]

    @classmethod
    def dex(cls) -> str:
        return "Minswap"

    @classmethod
    def order_selector(self) -> list[str]:
        return [s.encode() for s in self._stake_address]

    @classmethod
    def pool_selector(cls) -> PoolSelector:
        return PoolSelector(
            addresses=["addr1w8snz7c4974vzdpxu65ruphl3zjdvtxw8strf2c2tmqnxzgusf9xw"],
            assets=[
                "13aa2accf2e1561723aa26871e071fdf32c867cff7e7d50ad470d62f4d494e53574150",
            ],
        )

    @property
    def swap_forward(self) -> bool:
        return True

    @property
    def stake_address(self) -> Address:
        return self._stake_address[0]

    @classmethod
    def order_datum_class(self) -> type[MinswapOrderDatum]:
        return MinswapOrderDatum

    @classmethod
    def script_class(self) -> type[MinswapOrderDatum]:
        return PlutusV1Script

    @classmethod
    def pool_datum_class(self) -> type[MinswapPoolDatum]:
        return MinswapPoolDatum

    def batcher_fee(
        self,
        in_assets: Assets | None = None,
        out_assets: Assets | None = None,
        extra_assets: Assets | None = None,
    ) -> Assets:
        """Batcher fee.

        For Minswap, the batcher fee decreases linearly from 2.0 ADA to 1.5 ADA as the
        MIN in the input assets from 0 - 50,000 MIN.
        """
        MIN = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"
        if extra_assets is not None and MIN in extra_assets:
            fee_reduction = min(extra_assets[MIN] // 10**5, 500000)
        else:
            fee_reduction = 0
        return self._batcher - Assets(lovelace=fee_reduction)

    @property
    def pool_id(self) -> str:
        """A unique identifier for the pool."""
        return self.pool_nft.unit()

    @classmethod
    def pool_policy(cls) -> list[str]:
        return ["0be55d262b29f564998ff81efe21bdc0022621c12f15af08d0f2ddb1"]

    @classmethod
    def lp_policy(cls) -> list[str]:
        return ["e4214b7cce62ac6fbba385d164df48e157eae5863521b4b67ca71d86"]

    @classmethod
    def dex_policy(cls) -> list[str]:
        return ["13aa2accf2e1561723aa26871e071fdf32c867cff7e7d50ad470d62f"]

pool_id: str property

A unique identifier for the pool.

batcher_fee(in_assets: Assets | None = None, out_assets: Assets | None = None, extra_assets: Assets | None = None) -> Assets

Batcher fee.

For Minswap, the batcher fee decreases linearly from 2.0 ADA to 1.5 ADA as the MIN in the input assets from 0 - 50,000 MIN.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
def batcher_fee(
    self,
    in_assets: Assets | None = None,
    out_assets: Assets | None = None,
    extra_assets: Assets | None = None,
) -> Assets:
    """Batcher fee.

    For Minswap, the batcher fee decreases linearly from 2.0 ADA to 1.5 ADA as the
    MIN in the input assets from 0 - 50,000 MIN.
    """
    MIN = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"
    if extra_assets is not None and MIN in extra_assets:
        fee_reduction = min(extra_assets[MIN] // 10**5, 500000)
    else:
        fee_reduction = 0
    return self._batcher - Assets(lovelace=fee_reduction)

MinswapDJEDUSDCStablePoolDatum dataclass

Bases: MinswapStablePoolDatum

Pool Datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
767
768
769
770
771
772
773
774
775
776
777
778
779
780
@dataclass
class MinswapDJEDUSDCStablePoolDatum(MinswapStablePoolDatum):
    """Pool Datum."""

    CONSTR_ID = 0

    def pool_pair(self) -> Assets | None:
        """Return the asset pair associated with the pool."""
        return Assets(
            **{
                "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344": 0,
                "25c5de5f5b286073c593edfd77b48abc7a48e5a4f3d4cd9d428ff93555534443": 0,
            },
        )

pool_pair() -> Assets | None

Return the asset pair associated with the pool.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
773
774
775
776
777
778
779
780
def pool_pair(self) -> Assets | None:
    """Return the asset pair associated with the pool."""
    return Assets(
        **{
            "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344": 0,
            "25c5de5f5b286073c593edfd77b48abc7a48e5a4f3d4cd9d428ff93555534443": 0,
        },
    )

MinswapDJEDUSDCStableState

Bases: MinswapDJEDiUSDStableState

Minswap DJED/USDC Stable State.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
class MinswapDJEDUSDCStableState(MinswapDJEDiUSDStableState):
    """Minswap DJED/USDC Stable State."""

    asset_mulitipliers: list[int] = [1, 100]

    _stake_address: ClassVar[Address] = [
        Address.from_primitive(
            "addr1w93d8cuht3hvqt2qqfjqgyek3gk5d6ss2j93e5sh505m0ng8cmze2",
        ),
    ]

    @classmethod
    def pool_selector(cls) -> PoolSelector:
        return PoolSelector(
            addresses=["addr1wx8d45xlfrlxd7tctve8xgdtk59j849n00zz2pgyvv47t8sxa6t53"],
            assets=[
                "d97fa91daaf63559a253970365fb219dc4364c028e5fe0606cdbfff9555344432d444a45442d534c50",
            ],
        )

    @classmethod
    def pool_datum_class(self) -> type[MinswapDJEDUSDCStablePoolDatum]:
        return MinswapDJEDUSDCStablePoolDatum

    @classmethod
    def pool_policy(cls) -> list[str]:
        return [
            "d97fa91daaf63559a253970365fb219dc4364c028e5fe0606cdbfff9555344432d444a45442d534c50",
        ]

MinswapDJEDUSDMStablePoolDatum dataclass

Bases: MinswapStablePoolDatum

Pool Datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
783
784
785
786
787
788
789
790
791
792
793
794
795
@dataclass
class MinswapDJEDUSDMStablePoolDatum(MinswapStablePoolDatum):
    """Pool Datum."""

    CONSTR_ID = 0

    def pool_pair(self) -> Assets | None:
        return Assets(
            **{
                "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344": 0,
                "c48cbb3d5e57ed56e276bc45f99ab39abe94e6cd7ac39fb402da47ad0014df105553444d": 0,
            },
        )

MinswapDJEDiUSDStablePoolDatum dataclass

Bases: MinswapStablePoolDatum

Pool Datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
751
752
753
754
755
756
757
758
759
760
761
762
763
764
@dataclass
class MinswapDJEDiUSDStablePoolDatum(MinswapStablePoolDatum):
    """Pool Datum."""

    CONSTR_ID = 0

    def pool_pair(self) -> Assets | None:
        """Return the asset pair associated with the pool."""
        return Assets(
            **{
                "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344": 0,
                "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069555344": 0,
            },
        )

pool_pair() -> Assets | None

Return the asset pair associated with the pool.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
757
758
759
760
761
762
763
764
def pool_pair(self) -> Assets | None:
    """Return the asset pair associated with the pool."""
    return Assets(
        **{
            "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344": 0,
            "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069555344": 0,
        },
    )

MinswapDJEDiUSDStableState

Bases: AbstractCommonStableSwapPoolState, MinswapCPPState

Minswap DJED/iUSD Stable State.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
class MinswapDJEDiUSDStableState(AbstractCommonStableSwapPoolState, MinswapCPPState):
    """Minswap DJED/iUSD Stable State."""

    fee: float = 1
    _batcher = Assets(lovelace=2000000)
    _deposit = Assets(lovelace=2000000)
    _stake_address: ClassVar[Address] = [
        Address.from_primitive(
            "addr1w9xy6edqv9hkptwzewns75ehq53nk8t73je7np5vmj3emps698n9g",
        ),
    ]

    @classmethod
    def order_datum_class(cls) -> type[MinswapStableOrderDatum]:
        return MinswapStableOrderDatum

    def get_amount_out(
        self,
        asset: Assets,
        precise: bool = True,
    ) -> tuple[Assets, float]:
        out_asset, slippage = super().get_amount_out(
            asset=asset,
            precise=precise,
            fee_on_input=False,
        )

        return out_asset, slippage

    def get_amount_in(
        self,
        asset: Assets,
        precise: bool = True,
    ) -> tuple[Assets, float]:
        in_asset, slippage = super().get_amount_in(
            asset=asset,
            precise=precise,
            fee_on_input=False,
        )

        return in_asset, slippage

    @classmethod
    def post_init(cls, values: dict[str, ...]):
        """Post initialization checks.

        Args:
            values: The pool initialization parameters
        """
        super().post_init(values)
        assets = values["assets"]

        datum = cls.pool_datum_class().from_cbor(values["datum_cbor"])

        assets.root[assets.unit()] = datum.balances[0]
        assets.root[assets.unit(1)] = datum.balances[1]

        return values

    @property
    def amp(self) -> int:
        return self.pool_datum.amp

    @classmethod
    def pool_selector(cls) -> PoolSelector:
        return PoolSelector(
            addresses=["addr1wy7kkcpuf39tusnnyga5t2zcul65dwx9yqzg7sep3cjscesx2q5m5"],
            assets=[
                "5d4b6afd3344adcf37ccef5558bb87f522874578c32f17160512e398444a45442d695553442d534c50",
            ],
        )

    @classmethod
    def pool_datum_class(self) -> type[MinswapDJEDiUSDStablePoolDatum]:
        return MinswapDJEDiUSDStablePoolDatum

    @property
    def pool_id(self) -> str:
        """A unique identifier for the pool."""
        return self.pool_nft.unit()

    @classmethod
    def pool_policy(cls) -> list[str]:
        return [
            "5d4b6afd3344adcf37ccef5558bb87f522874578c32f17160512e398444a45442d695553442d534c50",
        ]

    @classmethod
    def lp_policy(cls) -> list[str] | None:
        return None

    @classmethod
    def dex_policy(cls) -> list[str] | None:
        return None

pool_id: str property

A unique identifier for the pool.

post_init(values: dict[str, ...]) classmethod

Post initialization checks.

Parameters:

Name Type Description Default
values dict[str, ...]

The pool initialization parameters

required
Source code in src/charli3_dendrite/dexs/amm/minswap.py
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
@classmethod
def post_init(cls, values: dict[str, ...]):
    """Post initialization checks.

    Args:
        values: The pool initialization parameters
    """
    super().post_init(values)
    assets = values["assets"]

    datum = cls.pool_datum_class().from_cbor(values["datum_cbor"])

    assets.root[assets.unit()] = datum.balances[0]
    assets.root[assets.unit(1)] = datum.balances[1]

    return values

MinswapOrderDatum dataclass

Bases: OrderDatum

An order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
@dataclass
class MinswapOrderDatum(OrderDatum):
    """An order datum."""

    sender: PlutusFullAddress
    receiver: PlutusFullAddress
    receiver_datum_hash: Union[ReceiverDatum, PlutusNone]
    step: Union[
        SwapExactIn,
        SwapExactOut,
        Deposit,
        Withdraw,
        ZapIn,
        StableSwapExactIn,
        StableSwapDeposit,
        StableSwapWithdraw,
        StableSwapWithdrawOneCoin,
    ]
    batcher_fee: int
    deposit: int

    @classmethod
    def create_datum(
        cls,
        address_source: Address,
        in_assets: Assets,
        out_assets: Assets,
        batcher_fee: Assets,
        deposit: Assets,
        address_target: Address | None = None,
        datum_target: PlutusData | None = None,
    ):
        """Create an order datum."""
        full_address_source = PlutusFullAddress.from_address(address_source)
        step = SwapExactIn.from_assets(out_assets)

        if address_target is None:
            address_target = address_source
            datum_target = PlutusNone()
        elif datum_target is None:
            datum_target = PlutusNone()

        full_address_target = PlutusFullAddress.from_address(address_target)

        return cls(
            full_address_source,
            full_address_target,
            datum_target,
            step,
            batcher_fee.quantity(),
            deposit.quantity(),
        )

    def address_source(self) -> Address:
        """The source address."""
        return self.sender.to_address()

    def requested_amount(self) -> Assets:
        """The requested amount."""
        if isinstance(self.step, SwapExactIn):
            return Assets(
                {self.step.desired_coin.assets.unit(): self.step.minimum_receive},
            )
        elif isinstance(self.step, SwapExactOut):
            return Assets(
                {self.step.desired_coin.assets.unit(): self.step.expected_receive},
            )
        elif isinstance(self.step, Deposit):
            return Assets({"lp": self.step.minimum_lp})
        elif isinstance(self.step, Withdraw):
            return Assets(
                {"asset_a": self.step.min_asset_a, "asset_b": self.step.min_asset_a},
            )
        elif isinstance(self.step, ZapIn):
            return Assets({self.step.desired_coin.assets.unit(): self.step.minimum_lp})

    def order_type(self) -> OrderType | None:
        """The order type."""
        order_type = None
        if isinstance(self.step, (SwapExactIn, SwapExactOut, StableSwapExactIn)):
            order_type = OrderType.swap
        elif isinstance(self.step, (Deposit, StableSwapDeposit, ZapIn)):
            order_type = OrderType.deposit
        elif isinstance(
            self.step,
            (Withdraw, StableSwapWithdraw, StableSwapWithdrawOneCoin),
        ):
            order_type = OrderType.withdraw

        return order_type

address_source() -> Address

The source address.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
232
233
234
def address_source(self) -> Address:
    """The source address."""
    return self.sender.to_address()

create_datum(address_source: Address, in_assets: Assets, out_assets: Assets, batcher_fee: Assets, deposit: Assets, address_target: Address | None = None, datum_target: PlutusData | None = None) classmethod

Create an order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
@classmethod
def create_datum(
    cls,
    address_source: Address,
    in_assets: Assets,
    out_assets: Assets,
    batcher_fee: Assets,
    deposit: Assets,
    address_target: Address | None = None,
    datum_target: PlutusData | None = None,
):
    """Create an order datum."""
    full_address_source = PlutusFullAddress.from_address(address_source)
    step = SwapExactIn.from_assets(out_assets)

    if address_target is None:
        address_target = address_source
        datum_target = PlutusNone()
    elif datum_target is None:
        datum_target = PlutusNone()

    full_address_target = PlutusFullAddress.from_address(address_target)

    return cls(
        full_address_source,
        full_address_target,
        datum_target,
        step,
        batcher_fee.quantity(),
        deposit.quantity(),
    )

order_type() -> OrderType | None

The order type.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def order_type(self) -> OrderType | None:
    """The order type."""
    order_type = None
    if isinstance(self.step, (SwapExactIn, SwapExactOut, StableSwapExactIn)):
        order_type = OrderType.swap
    elif isinstance(self.step, (Deposit, StableSwapDeposit, ZapIn)):
        order_type = OrderType.deposit
    elif isinstance(
        self.step,
        (Withdraw, StableSwapWithdraw, StableSwapWithdrawOneCoin),
    ):
        order_type = OrderType.withdraw

    return order_type

requested_amount() -> Assets

The requested amount.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
def requested_amount(self) -> Assets:
    """The requested amount."""
    if isinstance(self.step, SwapExactIn):
        return Assets(
            {self.step.desired_coin.assets.unit(): self.step.minimum_receive},
        )
    elif isinstance(self.step, SwapExactOut):
        return Assets(
            {self.step.desired_coin.assets.unit(): self.step.expected_receive},
        )
    elif isinstance(self.step, Deposit):
        return Assets({"lp": self.step.minimum_lp})
    elif isinstance(self.step, Withdraw):
        return Assets(
            {"asset_a": self.step.min_asset_a, "asset_b": self.step.min_asset_a},
        )
    elif isinstance(self.step, ZapIn):
        return Assets({self.step.desired_coin.assets.unit(): self.step.minimum_lp})

MinswapPoolDatum dataclass

Bases: PoolDatum

Pool Datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
@dataclass
class MinswapPoolDatum(PoolDatum):
    """Pool Datum."""

    CONSTR_ID = 0

    asset_a: AssetClass
    asset_b: AssetClass
    total_liquidity: int
    root_k_last: int
    fee_sharing: Union[_FeeSwitchWrapper, PlutusNone]

    def pool_pair(self) -> Assets | None:
        """Return the asset pair associated with the pool."""
        return self.asset_a.assets + self.asset_b.assets

pool_pair() -> Assets | None

Return the asset pair associated with the pool.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
701
702
703
def pool_pair(self) -> Assets | None:
    """Return the asset pair associated with the pool."""
    return self.asset_a.assets + self.asset_b.assets

MinswapStableOrderDatum dataclass

Bases: MinswapOrderDatum

MinSwap Stable Order Datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
@dataclass
class MinswapStableOrderDatum(MinswapOrderDatum):
    """MinSwap Stable Order Datum."""

    @classmethod
    def create_datum(
        cls,
        address_source: Address,
        in_assets: Assets,
        out_assets: Assets,
        batcher_fee: Assets,
        deposit: Assets,
        address_target: Address | None = None,
        datum_target: PlutusData | None = None,
    ):
        """Create an order datum."""
        full_address_source = PlutusFullAddress.from_address(address_source)
        step = StableSwapExactIn.from_assets(in_assets=in_assets, out_assets=out_assets)

        if address_target is None:
            address_target = address_source
            datum_target = PlutusNone()
        elif datum_target is None:
            datum_target = PlutusNone()

        full_address_target = PlutusFullAddress.from_address(address_target)

        return cls(
            full_address_source,
            full_address_target,
            datum_target,
            step,
            batcher_fee.quantity(),
            deposit.quantity(),
        )

create_datum(address_source: Address, in_assets: Assets, out_assets: Assets, batcher_fee: Assets, deposit: Assets, address_target: Address | None = None, datum_target: PlutusData | None = None) classmethod

Create an order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
@classmethod
def create_datum(
    cls,
    address_source: Address,
    in_assets: Assets,
    out_assets: Assets,
    batcher_fee: Assets,
    deposit: Assets,
    address_target: Address | None = None,
    datum_target: PlutusData | None = None,
):
    """Create an order datum."""
    full_address_source = PlutusFullAddress.from_address(address_source)
    step = StableSwapExactIn.from_assets(in_assets=in_assets, out_assets=out_assets)

    if address_target is None:
        address_target = address_source
        datum_target = PlutusNone()
    elif datum_target is None:
        datum_target = PlutusNone()

    full_address_target = PlutusFullAddress.from_address(address_target)

    return cls(
        full_address_source,
        full_address_target,
        datum_target,
        step,
        batcher_fee.quantity(),
        deposit.quantity(),
    )

MinswapStablePoolDatum dataclass

Bases: PlutusData

Stable Pool Datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
735
736
737
738
739
740
741
742
743
744
745
746
747
748
@dataclass
class MinswapStablePoolDatum(PlutusData):
    """Stable Pool Datum."""

    CONSTR_ID = 0

    balances: List[int]
    total_liquidity: int
    amp: int
    order_hash: bytes

    def pool_pair(self) -> Assets | None:
        """Return the asset pair associated with the pool."""
        raise NotImplementedError

pool_pair() -> Assets | None

Return the asset pair associated with the pool.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
746
747
748
def pool_pair(self) -> Assets | None:
    """Return the asset pair associated with the pool."""
    raise NotImplementedError

MinswapV2CPPState

Bases: AbstractConstantProductPoolState

Minswap Constant Product Pool State.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
class MinswapV2CPPState(AbstractConstantProductPoolState):
    """Minswap Constant Product Pool State."""

    fee: int | list[int] = [30, 30]
    _batcher = Assets(lovelace=1000000)
    _deposit = Assets(lovelace=2000000)
    _stake_address: ClassVar[Address] = [
        Address.from_primitive(
            "addr1z8p79rpkcdz8x9d6tft0x0dx5mwuzac2sa4gm8cvkw5hcn864negmna25tfcqjjxj65tnk0d0fmkza3gjdrxweaff35q0ym7k8",
        ),
    ]

    @classmethod
    def dex(cls) -> str:
        return "MinswapV2"

    @classmethod
    def order_selector(self) -> list[str]:
        return [s.encode() for s in self._stake_address]

    @classmethod
    def pool_selector(cls) -> PoolSelector:
        return PoolSelector(
            addresses=["addr1w84q0denmyep98ph3tmzwsmw0j7zau9ljmsqx6a4rvaau6ca7j5v4"],
            assets=[
                "f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c4d5350",
            ],
        )

    @property
    def swap_forward(self) -> bool:
        return True

    @property
    def stake_address(self) -> Address:
        return self._stake_address[0]

    @classmethod
    def order_datum_class(self) -> type[MinswapV2OrderDatum]:
        return MinswapV2OrderDatum

    @classmethod
    def script_class(self) -> type[PlutusV2Script]:
        return PlutusV2Script

    @classmethod
    def pool_datum_class(self) -> type[MinswapV2PoolDatum]:
        return MinswapV2PoolDatum

    def batcher_fee(
        self,
        in_assets: Assets | None = None,
        out_assets: Assets | None = None,
        extra_assets: Assets | None = None,
    ) -> Assets:
        """Batcher fee.

        For Minswap, the batcher fee decreases linearly from 2.0 ADA to 1.5 ADA as the
        MIN in the input assets from 0 - 25,000 MIN.
        """
        MIN = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"
        if extra_assets is not None and MIN in extra_assets:
            fee_reduction = min(extra_assets[MIN] // (2 * 10**5), 250000)
        else:
            fee_reduction = 0
        return self._batcher - Assets(lovelace=fee_reduction)

    @property
    def pool_id(self) -> str:
        """A unique identifier for the pool."""
        return self.lp_tokens.unit()

    @classmethod
    def lp_policy(cls) -> list[str]:
        return ["f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c"]

    @classmethod
    def dex_policy(cls) -> list[str]:
        return ["f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c4d5350"]

    @classmethod
    def post_init(cls, values):
        super().post_init(values)

        datum = MinswapV2PoolDatum.from_cbor(values["datum_cbor"])

        assets = values["assets"]
        assets.root[assets.unit()] = datum.reserve_a
        assets.root[assets.unit(1)] = datum.reserve_b

        values["fee"] = [datum.base_fee_a_numerator, datum.base_fee_b_numerator]

pool_id: str property

A unique identifier for the pool.

batcher_fee(in_assets: Assets | None = None, out_assets: Assets | None = None, extra_assets: Assets | None = None) -> Assets

Batcher fee.

For Minswap, the batcher fee decreases linearly from 2.0 ADA to 1.5 ADA as the MIN in the input assets from 0 - 25,000 MIN.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
def batcher_fee(
    self,
    in_assets: Assets | None = None,
    out_assets: Assets | None = None,
    extra_assets: Assets | None = None,
) -> Assets:
    """Batcher fee.

    For Minswap, the batcher fee decreases linearly from 2.0 ADA to 1.5 ADA as the
    MIN in the input assets from 0 - 25,000 MIN.
    """
    MIN = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"
    if extra_assets is not None and MIN in extra_assets:
        fee_reduction = min(extra_assets[MIN] // (2 * 10**5), 250000)
    else:
        fee_reduction = 0
    return self._batcher - Assets(lovelace=fee_reduction)

MinswapV2OrderDatum dataclass

Bases: OrderDatum

An order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
@dataclass
class MinswapV2OrderDatum(OrderDatum):
    """An order datum."""

    owner: Union[OAMMint, OAMSignature, OAMSpend, OAMWithdraw]
    refund_address: PlutusFullAddress
    refund_datum_hash: Union[
        SundaeV3PlutusNone,
        SundaeV3ReceiverDatumHash,
        SundaeV3ReceiverInlineDatum,
    ]
    receiver_address: PlutusFullAddress
    receiver_datum_hash: Union[
        SundaeV3PlutusNone,
        SundaeV3ReceiverDatumHash,
        SundaeV3ReceiverInlineDatum,
    ]
    lp_asset: AssetClass
    step: Union[
        SwapExactInV2,
        StopLossV2,
        OCOV2,
        SwapExactOutV2,
        DepositV2,
        WithdrawV2,
        ZapOutV2,
        PartialSwapV2,
        WithdrawImbalanceV2,
        SwapMultiRoutingV2,
        DonationV2,
    ]
    max_batcher_fee: int
    expiration_setting: Union[PlutusNone, Expire]

    @classmethod
    def create_datum(
        cls,
        address_source: Address,
        in_assets: Assets,
        out_assets: Assets,
        batcher_fee: Assets,
        deposit: Assets,
        address_target: Address | None = None,
        datum_target: PlutusData | None = None,
    ):
        """Create an order datum."""
        full_address_source = PlutusFullAddress.from_address(address_source)
        step = SwapExactInV2.from_assets(in_asset=in_assets, out_asset=out_assets)

        if address_target is None:
            address_target = address_source
            datum_target = SundaeV3PlutusNone()
        elif datum_target is None:
            datum_target = SundaeV3PlutusNone()

        full_address_target = PlutusFullAddress.from_address(address_target)

        merged_assets = in_assets + out_assets

        if merged_assets.unit() == "lovelace":
            token_a = sha3_256(bytes.fromhex("")).digest()
        else:
            token_a = sha3_256(bytes.fromhex(merged_assets.unit())).digest()
        token_b = sha3_256(bytes.fromhex(merged_assets.unit(1))).digest()
        pool_name = sha3_256(token_a + token_b).hexdigest()
        lp_asset = AssetClass.from_assets(
            Assets(
                **{
                    "f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c"
                    + pool_name: 0,
                },
            ),
        )

        return cls(
            owner=OAMSignature(address_source.payment_part.payload),
            refund_address=full_address_source,
            refund_datum_hash=datum_target,
            receiver_address=full_address_target,
            receiver_datum_hash=datum_target,
            lp_asset=lp_asset,
            step=step,
            max_batcher_fee=batcher_fee.quantity(),
            expiration_setting=PlutusNone(),
        )

    def address_source(self) -> Address:
        """The source address."""
        if isinstance(self.owner, OAMSignature):
            h = self.owner.pub_key_hash
        else:
            h = self.owner.script_hash

        return Address(payment_part=VerificationKeyHash(h))

    def requested_amount(self) -> Assets:
        """The requested amount."""
        if isinstance(self.step, SwapExactInV2):
            if isinstance(self.step.a_to_b_direction, BoolTrue):
                return Assets({"asset_a": self.step.minimum_receive})
            else:
                return Assets({"asset_b": self.step.minimum_receive})
        elif isinstance(self.step, SwapExactOutV2):
            if isinstance(self.step.a_to_b_direction, BoolTrue):
                return Assets({"asset_a": self.step.expected_receive})
            else:
                return Assets({"asset_b": self.step.expected_receive})
        elif isinstance(self.step, DepositV2):
            return Assets({"lp": self.step.minimum_lp})
        elif isinstance(self.step, WithdrawV2):
            return Assets(
                {
                    "asset_a": self.step.minimum_asset_a,
                    "asset_b": self.step.minimum_asset_b,
                },
            )
        else:
            return Assets({})

    def order_type(self) -> OrderType | None:
        """The order type."""
        order_type = None
        if isinstance(
            self.step,
            (
                SwapExactInV2,
                StopLossV2,
                OCOV2,
                SwapExactOutV2,
                PartialSwapV2,
                SwapMultiRoutingV2,
            ),
        ):
            order_type = OrderType.swap
        elif isinstance(self.step, (DepositV2, DonationV2)):
            order_type = OrderType.deposit
        elif isinstance(self.step, (WithdrawV2, ZapOutV2, WithdrawImbalanceV2)):
            order_type = OrderType.withdraw

        return order_type

address_source() -> Address

The source address.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
571
572
573
574
575
576
577
578
def address_source(self) -> Address:
    """The source address."""
    if isinstance(self.owner, OAMSignature):
        h = self.owner.pub_key_hash
    else:
        h = self.owner.script_hash

    return Address(payment_part=VerificationKeyHash(h))

create_datum(address_source: Address, in_assets: Assets, out_assets: Assets, batcher_fee: Assets, deposit: Assets, address_target: Address | None = None, datum_target: PlutusData | None = None) classmethod

Create an order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
@classmethod
def create_datum(
    cls,
    address_source: Address,
    in_assets: Assets,
    out_assets: Assets,
    batcher_fee: Assets,
    deposit: Assets,
    address_target: Address | None = None,
    datum_target: PlutusData | None = None,
):
    """Create an order datum."""
    full_address_source = PlutusFullAddress.from_address(address_source)
    step = SwapExactInV2.from_assets(in_asset=in_assets, out_asset=out_assets)

    if address_target is None:
        address_target = address_source
        datum_target = SundaeV3PlutusNone()
    elif datum_target is None:
        datum_target = SundaeV3PlutusNone()

    full_address_target = PlutusFullAddress.from_address(address_target)

    merged_assets = in_assets + out_assets

    if merged_assets.unit() == "lovelace":
        token_a = sha3_256(bytes.fromhex("")).digest()
    else:
        token_a = sha3_256(bytes.fromhex(merged_assets.unit())).digest()
    token_b = sha3_256(bytes.fromhex(merged_assets.unit(1))).digest()
    pool_name = sha3_256(token_a + token_b).hexdigest()
    lp_asset = AssetClass.from_assets(
        Assets(
            **{
                "f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c"
                + pool_name: 0,
            },
        ),
    )

    return cls(
        owner=OAMSignature(address_source.payment_part.payload),
        refund_address=full_address_source,
        refund_datum_hash=datum_target,
        receiver_address=full_address_target,
        receiver_datum_hash=datum_target,
        lp_asset=lp_asset,
        step=step,
        max_batcher_fee=batcher_fee.quantity(),
        expiration_setting=PlutusNone(),
    )

order_type() -> OrderType | None

The order type.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
def order_type(self) -> OrderType | None:
    """The order type."""
    order_type = None
    if isinstance(
        self.step,
        (
            SwapExactInV2,
            StopLossV2,
            OCOV2,
            SwapExactOutV2,
            PartialSwapV2,
            SwapMultiRoutingV2,
        ),
    ):
        order_type = OrderType.swap
    elif isinstance(self.step, (DepositV2, DonationV2)):
        order_type = OrderType.deposit
    elif isinstance(self.step, (WithdrawV2, ZapOutV2, WithdrawImbalanceV2)):
        order_type = OrderType.withdraw

    return order_type

requested_amount() -> Assets

The requested amount.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
def requested_amount(self) -> Assets:
    """The requested amount."""
    if isinstance(self.step, SwapExactInV2):
        if isinstance(self.step.a_to_b_direction, BoolTrue):
            return Assets({"asset_a": self.step.minimum_receive})
        else:
            return Assets({"asset_b": self.step.minimum_receive})
    elif isinstance(self.step, SwapExactOutV2):
        if isinstance(self.step.a_to_b_direction, BoolTrue):
            return Assets({"asset_a": self.step.expected_receive})
        else:
            return Assets({"asset_b": self.step.expected_receive})
    elif isinstance(self.step, DepositV2):
        return Assets({"lp": self.step.minimum_lp})
    elif isinstance(self.step, WithdrawV2):
        return Assets(
            {
                "asset_a": self.step.minimum_asset_a,
                "asset_b": self.step.minimum_asset_b,
            },
        )
    else:
        return Assets({})

MinswapV2PoolDatum dataclass

Bases: PoolDatum

Pool Datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
@dataclass
class MinswapV2PoolDatum(PoolDatum):
    """Pool Datum."""

    CONSTR_ID = 0

    pool_batching_stake_credential: _PlutusConstrWrapper
    asset_a: AssetClass
    asset_b: AssetClass
    total_liquidity: int
    reserve_a: int
    reserve_b: int
    base_fee_a_numerator: int
    base_fee_b_numerator: int
    fee_sharing_numerator: Union[PlutusNone, OptionalInt]
    allow_dynamic_fee: Union[BoolTrue, BoolFalse]

    def pool_pair(self) -> Assets | None:
        """Return the asset pair associated with the pool."""
        return self.asset_a.assets + self.asset_b.assets

pool_pair() -> Assets | None

Return the asset pair associated with the pool.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
730
731
732
def pool_pair(self) -> Assets | None:
    """Return the asset pair associated with the pool."""
    return self.asset_a.assets + self.asset_b.assets

OAMMint dataclass

Bases: PlutusData

SwapMultiRoutingV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
467
468
469
470
471
472
473
@dataclass
class OAMMint(PlutusData):
    """SwapMultiRoutingV2 order datum."""

    CONSTR_ID = 3

    script_hash: bytes

OAMSignature dataclass

Bases: PlutusData

SwapMultiRoutingV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
440
441
442
443
444
445
446
@dataclass
class OAMSignature(PlutusData):
    """SwapMultiRoutingV2 order datum."""

    CONSTR_ID = 0

    pub_key_hash: bytes

OAMSpend dataclass

Bases: PlutusData

SwapMultiRoutingV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
449
450
451
452
453
454
455
@dataclass
class OAMSpend(PlutusData):
    """SwapMultiRoutingV2 order datum."""

    CONSTR_ID = 1

    script_hash: bytes

OAMWithdraw dataclass

Bases: PlutusData

SwapMultiRoutingV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
458
459
460
461
462
463
464
@dataclass
class OAMWithdraw(PlutusData):
    """SwapMultiRoutingV2 order datum."""

    CONSTR_ID = 2

    script_hash: bytes

OCOV2 dataclass

Bases: PlutusData

OCO order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
343
344
345
346
347
348
349
350
351
@dataclass
class OCOV2(PlutusData):
    """OCO order datum."""

    CONSTR_ID = 2
    a_to_b_direction: Union[BoolTrue, BoolFalse]
    swap_amount_option: Union[SAOSpecificAmount, SAOAll]
    minimum_receive: int
    stop_loss_receive: int

PartialSwapV2 dataclass

Bases: PlutusData

PartialSwapV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
397
398
399
400
401
402
403
404
405
406
407
408
@dataclass
class PartialSwapV2(PlutusData):
    """PartialSwapV2 order datum."""

    CONSTR_ID = 7
    a_to_b_direction: Union[BoolTrue, BoolFalse]
    total_swap_amount: int
    io_ratio_numerator: int
    io_ratio_denominator: int
    hops: int
    minimum_swap_amount_required: int
    max_batcher_fee_each_time: int

StableSwapDeposit dataclass

Bases: PlutusData

Swap exact out order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@dataclass
class StableSwapDeposit(PlutusData):
    """Swap exact out order datum."""

    CONSTR_ID = 1
    expected_receive: int

    @classmethod
    def from_assets(cls, asset: Assets):
        """Parse an Assets object into a SwapExactOut datum."""
        assert len(asset) == 1

        return StableSwapDeposit(
            expected_receive=asset.quantity(),
        )

from_assets(asset: Assets) classmethod

Parse an Assets object into a SwapExactOut datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
89
90
91
92
93
94
95
96
@classmethod
def from_assets(cls, asset: Assets):
    """Parse an Assets object into a SwapExactOut datum."""
    assert len(asset) == 1

    return StableSwapDeposit(
        expected_receive=asset.quantity(),
    )

StableSwapExactIn dataclass

Bases: PlutusData

Swap exact in order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@dataclass
class StableSwapExactIn(PlutusData):
    """Swap exact in order datum."""

    CONSTR_ID = 0
    input_coin: int
    output_coin: int
    minimum_receive: int

    @classmethod
    def from_assets(cls, in_assets: Assets, out_assets: Assets):
        """Parse an Assets object into a SwapExactIn datum."""
        assert len(in_assets) == 1
        assert len(out_assets) == 1

        merged = in_assets + out_assets
        if in_assets.unit() == merged.unit():
            input_coin = 0
            output_coin = 1
        else:
            input_coin = 1
            output_coin = 0

        return StableSwapExactIn(
            input_coin=input_coin,
            output_coin=output_coin,
            minimum_receive=out_assets.quantity(),
        )

from_assets(in_assets: Assets, out_assets: Assets) classmethod

Parse an Assets object into a SwapExactIn datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@classmethod
def from_assets(cls, in_assets: Assets, out_assets: Assets):
    """Parse an Assets object into a SwapExactIn datum."""
    assert len(in_assets) == 1
    assert len(out_assets) == 1

    merged = in_assets + out_assets
    if in_assets.unit() == merged.unit():
        input_coin = 0
        output_coin = 1
    else:
        input_coin = 1
        output_coin = 0

    return StableSwapExactIn(
        input_coin=input_coin,
        output_coin=output_coin,
        minimum_receive=out_assets.quantity(),
    )

StableSwapWithdraw dataclass

Bases: PlutusData

Swap exact out order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
@dataclass
class StableSwapWithdraw(PlutusData):
    """Swap exact out order datum."""

    CONSTR_ID = 2
    expected_receive: List[int]

    @classmethod
    def from_assets(cls, asset: Assets):
        """Parse an Assets object into a SwapExactOut datum."""
        assert len(asset) == 2

        return StableSwapWithdraw(
            expected_receive=[asset.quantity(), asset.quantity(1)],
        )

from_assets(asset: Assets) classmethod

Parse an Assets object into a SwapExactOut datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
106
107
108
109
110
111
112
113
@classmethod
def from_assets(cls, asset: Assets):
    """Parse an Assets object into a SwapExactOut datum."""
    assert len(asset) == 2

    return StableSwapWithdraw(
        expected_receive=[asset.quantity(), asset.quantity(1)],
    )

StableSwapWithdrawOneCoin dataclass

Bases: PlutusData

Swap exact out order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@dataclass
class StableSwapWithdrawOneCoin(PlutusData):
    """Swap exact out order datum."""

    CONSTR_ID = 4
    coin: int
    expected_receive: int

    @classmethod
    def from_assets(cls, coin_index: int, asset: Assets):
        """Parse an Assets object into a SwapExactOut datum."""
        assert len(asset) == 1

        return StableSwapWithdrawOneCoin(
            expected_receive=[coin_index, asset.quantity()],
        )

from_assets(coin_index: int, asset: Assets) classmethod

Parse an Assets object into a SwapExactOut datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
124
125
126
127
128
129
130
131
@classmethod
def from_assets(cls, coin_index: int, asset: Assets):
    """Parse an Assets object into a SwapExactOut datum."""
    assert len(asset) == 1

    return StableSwapWithdrawOneCoin(
        expected_receive=[coin_index, asset.quantity()],
    )

StopLossV2 dataclass

Bases: PlutusData

Stop loss order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
333
334
335
336
337
338
339
340
@dataclass
class StopLossV2(PlutusData):
    """Stop loss order datum."""

    CONSTR_ID = 1
    a_to_b_direction: Union[BoolTrue, BoolFalse]
    swap_amount_option: Union[SAOSpecificAmount, SAOAll]
    stop_loss_receive: int

SwapExactIn dataclass

Bases: PlutusData

Swap exact in order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@dataclass
class SwapExactIn(PlutusData):
    """Swap exact in order datum."""

    CONSTR_ID = 0
    desired_coin: AssetClass
    minimum_receive: int

    @classmethod
    def from_assets(cls, asset: Assets):
        """Parse an Assets object into a SwapExactIn datum."""
        assert len(asset) == 1

        return SwapExactIn(
            desired_coin=AssetClass.from_assets(asset),
            minimum_receive=asset.quantity(),
        )

from_assets(asset: Assets) classmethod

Parse an Assets object into a SwapExactIn datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
41
42
43
44
45
46
47
48
49
@classmethod
def from_assets(cls, asset: Assets):
    """Parse an Assets object into a SwapExactIn datum."""
    assert len(asset) == 1

    return SwapExactIn(
        desired_coin=AssetClass.from_assets(asset),
        minimum_receive=asset.quantity(),
    )

SwapExactInV2 dataclass

Bases: PlutusData

Swap exact in order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
@dataclass
class SwapExactInV2(PlutusData):
    """Swap exact in order datum."""

    CONSTR_ID = 0
    a_to_b_direction: Union[BoolTrue, BoolFalse]
    swap_amount_option: Union[SAOSpecificAmount, SAOAll]
    minimum_receive: int
    killable: Union[BoolTrue, BoolFalse]

    @classmethod
    def from_assets(cls, in_asset: Assets, out_asset: Assets) -> "SwapExactInV2":
        """Parse an Assets object into a SwapExactInV2 datum."""
        assert len(in_asset) == 1

        merged_assets = in_asset + out_asset

        direction = (
            BoolTrue() if in_asset.unit() == merged_assets.unit() else BoolFalse()
        )

        option = SAOSpecificAmount(swap_amount=in_asset.quantity())

        return cls(
            a_to_b_direction=direction,
            swap_amount_option=option,
            minimum_receive=out_asset.quantity(),
            killable=BoolFalse(),
        )

from_assets(in_asset: Assets, out_asset: Assets) -> SwapExactInV2 classmethod

Parse an Assets object into a SwapExactInV2 datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
@classmethod
def from_assets(cls, in_asset: Assets, out_asset: Assets) -> "SwapExactInV2":
    """Parse an Assets object into a SwapExactInV2 datum."""
    assert len(in_asset) == 1

    merged_assets = in_asset + out_asset

    direction = (
        BoolTrue() if in_asset.unit() == merged_assets.unit() else BoolFalse()
    )

    option = SAOSpecificAmount(swap_amount=in_asset.quantity())

    return cls(
        a_to_b_direction=direction,
        swap_amount_option=option,
        minimum_receive=out_asset.quantity(),
        killable=BoolFalse(),
    )

SwapExactOut dataclass

Bases: PlutusData

Swap exact out order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@dataclass
class SwapExactOut(PlutusData):
    """Swap exact out order datum."""

    CONSTR_ID = 1
    desired_coin: AssetClass
    expected_receive: int

    @classmethod
    def from_assets(cls, asset: Assets):
        """Parse an Assets object into a SwapExactOut datum."""
        assert len(asset) == 1

        return SwapExactOut(
            desired_coin=AssetClass.from_assets(asset),
            expected_receive=asset.quantity(),
        )

from_assets(asset: Assets) classmethod

Parse an Assets object into a SwapExactOut datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
142
143
144
145
146
147
148
149
150
@classmethod
def from_assets(cls, asset: Assets):
    """Parse an Assets object into a SwapExactOut datum."""
    assert len(asset) == 1

    return SwapExactOut(
        desired_coin=AssetClass.from_assets(asset),
        expected_receive=asset.quantity(),
    )

SwapExactOutV2 dataclass

Bases: PlutusData

Swap exact out order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
354
355
356
357
358
359
360
361
362
@dataclass
class SwapExactOutV2(PlutusData):
    """Swap exact out order datum."""

    CONSTR_ID = 3
    a_to_b_direction: Union[BoolTrue, BoolFalse]
    swap_amount_option: Union[SAOSpecificAmount, SAOAll]
    expected_receive: int
    killable: Union[BoolTrue, BoolFalse]

SwapMultiRoutingV2 dataclass

Bases: PlutusData

SwapMultiRoutingV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
423
424
425
426
427
428
429
430
@dataclass
class SwapMultiRoutingV2(PlutusData):
    """SwapMultiRoutingV2 order datum."""

    CONSTR_ID = 9
    routings: List[Datum]
    swap_amount_option: Union[SAOSpecificAmount, SAOAll]
    minimum_receive: int

Withdraw dataclass

Bases: PlutusData

Swap exact in order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
161
162
163
164
165
166
167
@dataclass
class Withdraw(PlutusData):
    """Swap exact in order datum."""

    CONSTR_ID = 3
    min_asset_a: int
    min_asset_b: int

WithdrawImbalanceV2 dataclass

Bases: PlutusData

WithdrawImbalanceV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
411
412
413
414
415
416
417
418
419
420
@dataclass
class WithdrawImbalanceV2(PlutusData):
    """WithdrawImbalanceV2 order datum."""

    CONSTR_ID = 8
    withdrawal_amount_optino: Datum
    ratio_asset_a: int
    ratio_asset_b: int
    minimum_asset_a: int
    killable: Union[BoolTrue, BoolFalse]

WithdrawV2 dataclass

Bases: PlutusData

WithdrawV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
375
376
377
378
379
380
381
382
383
@dataclass
class WithdrawV2(PlutusData):
    """WithdrawV2 order datum."""

    CONSTR_ID = 5
    withdrawal_amount_option: Datum
    minimum_asset_a: int
    minimum_asset_b: int
    killable: Union[BoolTrue, BoolFalse]

ZapIn dataclass

Bases: PlutusData

Swap exact in order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
170
171
172
173
174
175
176
@dataclass
class ZapIn(PlutusData):
    """Swap exact in order datum."""

    CONSTR_ID = 4
    desired_coin: AssetClass
    minimum_lp: int

ZapOutV2 dataclass

Bases: PlutusData

ZapOutV2 order datum.

Source code in src/charli3_dendrite/dexs/amm/minswap.py
386
387
388
389
390
391
392
393
394
@dataclass
class ZapOutV2(PlutusData):
    """ZapOutV2 order datum."""

    CONSTR_ID = 6
    a_to_b_direction: Union[BoolTrue, BoolFalse]
    withdrawal_amount_option: Datum
    minimum_receive: int
    killable: Union[BoolTrue, BoolFalse]