diff --git a/bitsharesbase/objects.py b/bitsharesbase/objects.py index 9d1c161..e0d54b8 100644 --- a/bitsharesbase/objects.py +++ b/bitsharesbase/objects.py @@ -454,5 +454,46 @@ def __init__(self, *args, **kwargs): elif id == 2: data = Block_id_predicate(o[1]) else: - raise ValueError("Unknown {}".format(self.__class__.name)) + raise ValueError("Unknown {}".format(self.__class__.__name__)) + super().__init__(data, id) + + +class LimitOrderAutoAction(Static_variant): + def __init__(self, o): + class Create_take_profit_order_action(GrapheneObject): + def __init__(self, *args, **kwargs): + kwargs.update(args[0]) + super().__init__( + OrderedDict( + [ + ("fee_asset_id", ObjectId(kwargs["fee_asset_id"], "asset")), + ("spread_percent", Uint16(kwargs["spread_percent"])), + ("size_percent", Uint16(kwargs["size_percent"])), + ( + "expiration_seconds", + Uint32(kwargs["expiration_seconds"]), + ), + ("repeat", Bool(kwargs["repeat"])), + ("extensions", Set([])), + ] + ) + ) + + id = o[0] + if id == 0: + data = Create_take_profit_order_action(o[1]) + else: + raise ValueError("Unknown {}".format(self.__class__.__name__)) super().__init__(data, id) + + +class LimitOrderCreateExtensions(Extension): + def NestedLimitOrderAutoAction(value): + if value: + return Array([LimitOrderAutoAction(o) for o in value]) + else: + return None + + sorted_options = [ + ("on_fill", NestedLimitOrderAutoAction), + ] diff --git a/bitsharesbase/objecttypes.py b/bitsharesbase/objecttypes.py index eadeedd..a271b49 100644 --- a/bitsharesbase/objecttypes.py +++ b/bitsharesbase/objecttypes.py @@ -21,4 +21,7 @@ object_type["custom_authority"] = 17 object_type["ticket"] = 18 object_type["liquidity_pool"] = 19 -object_type["OBJECT_TYPE_COUNT"] = 19 +object_type["samet_fund"] = 20 +object_type["credit_offer"] = 21 +object_type["credit_deal"] = 22 +object_type["OBJECT_TYPE_COUNT"] = 22 diff --git a/bitsharesbase/operationids.py b/bitsharesbase/operationids.py index 208ad16..0d72e80 100644 --- a/bitsharesbase/operationids.py +++ b/bitsharesbase/operationids.py @@ -65,6 +65,20 @@ "liquidity_pool_deposit", "liquidity_pool_withdraw", "liquidity_pool_exchange", + "samet_fund_create", + "samet_fund_delete", + "samet_fund_update", + "samet_fund_borrow", + "samet_fund_repay", + "credit_offer_create", + "credit_offer_delete", + "credit_offer_update", + "credit_offer_accept", + "credit_deal_repay", + "credit_deal_expired", + "liquidity_pool_update", + "credit_deal_update", + "limit_order_update", ] operations = {o: ops.index(o) for o in ops} diff --git a/bitsharesbase/operations.py b/bitsharesbase/operations.py index b437748..0c9e149 100644 --- a/bitsharesbase/operations.py +++ b/bitsharesbase/operations.py @@ -45,6 +45,8 @@ Worker_initializer, isArgsThisClass, AssertPredicate, + LimitOrderAutoAction, + LimitOrderCreateExtensions, ) from .operationids import operations @@ -386,7 +388,10 @@ def __init__(self, *args, **kwargs): ("min_to_receive", Asset(kwargs["min_to_receive"])), ("expiration", PointInTime(kwargs["expiration"])), ("fill_or_kill", Bool(kwargs["fill_or_kill"])), - ("extensions", Set([])), + ( + "extensions", + LimitOrderCreateExtensions(kwargs["extensions"]), + ), ] ) ) @@ -1226,4 +1231,104 @@ def __init__(self, *args, **kwargs): ) +class Liquidity_pool_update(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + + if kwargs.get("taker_fee_percent"): + taker_fee_percent = Optional(Uint16(kwargs["taker_fee_percent"])) + else: + taker_fee_percent = Optional(None) + + if kwargs.get("withdrawal_fee_percent"): + withdrawal_fee_percent = Optional( + Uint16(kwargs["withdrawal_fee_percent"]) + ) + else: + withdrawal_fee_percent = Optional(None) + + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("account", ObjectId(kwargs["account"], "account")), + ("pool", ObjectId(kwargs["pool"], "liquidity_pool")), + ("taker_fee_percent", taker_fee_percent), + ("withdrawal_fee_percent", withdrawal_fee_percent), + ("extensions", Set([])), + ] + ) + ) + + +class Credit_deal_update(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("account", ObjectId(kwargs["account"], "account")), + ("deal_id", ObjectId(kwargs["deal_id"], "credit_deal")), + ("auto_repay", Uint8(kwargs["auto_repay"])), + ("extensions", Set([])), + ] + ) + ) + + +class Limit_order_update(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + if len(args) == 1 and len(kwargs) == 0: + kwargs = args[0] + + if kwargs.get("new_price"): + new_price = Optional(Price(kwargs["new_price"])) + else: + new_price = Optional(None) + + if kwargs.get("delta_amount_to_sell"): + delta_amount_to_sell = Optional(Asset(kwargs["delta_amount_to_sell"])) + else: + delta_amount_to_sell = Optional(None) + + if kwargs.get("new_expiration"): + new_expiration = Optional(PointInTime(kwargs["new_expiration"])) + else: + new_expiration = Optional(None) + + if kwargs.get("on_fill"): + on_fill = Optional( + Array([LimitOrderAutoAction(o) for o in kwargs["on_fill"]]) + ) + else: + on_fill = Optional(None) + + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("seller", ObjectId(kwargs["seller"], "account")), + ("order", ObjectId(kwargs["order"], "limit_order")), + ("new_price", new_price), + ("delta_amount_to_sell", delta_amount_to_sell), + ("new_expiration", new_expiration), + ("on_fill", on_fill), + ("extensions", Set([])), + ] + ) + ) + + fill_classmaps() diff --git a/tests/test_transactions.py b/tests/test_transactions.py index bdaf72b..830ce5c 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -83,15 +83,29 @@ def test_limit_order_create(self): "min_to_receive": {"amount": 10000, "asset_id": "1.3.105"}, "expiration": "2016-05-18T09:22:05", "fill_or_kill": False, - "extensions": [], + "extensions": { + "on_fill": [ + [ + 0, + { + "fee_asset_id": "1.3.0", + "spread_percent": 100, + "size_percent": 1000, + "expiration_seconds": 3600, + "repeat": True, + "extensions": [], + }, + ] + ] + }, } ) self.cm = ( - "f68585abf4dce7c8045701016400000000000000001da08601000" - "0000000001027000000000000693d343c57000000011f75cbfd49" - "ae8d9b04af76cc0a7de8b6e30b71167db7fe8e2197ef9d858df18" - "77043493bc24ffdaaffe592357831c978fd8a296b913979f106de" - "be940d60d77b50" + "f68585abf4dce7c8045701016400000000000000001da0860100000" + "00000001027000000000000693d343c570001000100006400e80310" + "0e0000010000011f5ddffd232fd713e106aec3068646f5a74ae145e" + "08e1e13f7464885a507e808e365594f5e7c14049d9432bcf1ca2330" + "a65d1b7ab88aa08b355970ca6f23e06aa0" ) self.doit() @@ -1045,6 +1059,97 @@ def test_assert_b(self): ) self.doit(0) + def test_limit_order_update(self): + self.op = operations.Limit_order_update( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "seller": "1.2.4", + "order": "1.7.12535", + "extensions": [], + } + ) + self.cm = ( + "f68585abf4dce7c80457014d00000000000000000004f76100" + "0000000000011f06d0b4467a5916ffb3d8ef4261c0719b1fb0" + "964aa5d3fbecbfbcbc9fe1117bc20e8a2c3f87e7817b83446c" + "45deb2a0d3d5b8b0d3b22fc8076ffc8eeb1a95e928" + ) + self.doit(0) + + self.op = operations.Limit_order_update( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "seller": "1.2.4", + "order": "1.7.12535", + "new_price": { + "base": {"amount": 1123456, "asset_id": "1.3.0"}, + "quote": {"amount": 78901122, "asset_id": "1.3.0"}, + }, + "delta_amount_to_sell": {"amount": 12562, "asset_id": "1.3.0"}, + "new_expiration": "2023-12-18T09:22:05", + "on_fill": [ + [ + 0, + { + "fee_asset_id": "1.3.0", + "spread_percent": 100, + "size_percent": 1000, + "expiration_seconds": 3600, + "repeat": True, + "extensions": [], + }, + ] + ], + "extensions": [], + } + ) + self.cm = ( + "f68585abf4dce7c80457014d00000000000000000004f76101" + "80241100000000000082efb304000000000001123100000000" + "000000013d0f8065010100006400e803100e00000100000001" + "2051a24fb550e4a8ec890ad404ea0e3cf6ea449d6ba397d280" + "64f7129153dd013e27846eb6567a88d8eea7557f32ddc02cdc" + "a614c5a30130c83141c4050ffc50e2" + ) + self.doit() + + def test_liquidity_pool_update(self): + self.op = operations.Liquidity_pool_update( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "account": "1.2.4", + "pool": "1.19.13356", + "taker_fee_percent": 124, + "withdrawal_fee_percent": 125, + "extensions": [], + } + ) + self.cm = ( + "f68585abf4dce7c80457014b00000000000000000004ac6801" + "7c00017d00000001202e3f140515ce936020348f845a4c034b" + "164441049dfe0a59a6c0fe27cbef740c10fa0d315e14e77e62" + "d8dae4f45d95fef358ff79f5304a420d6fc13abfd9374b" + ) + self.doit(0) + + def test_credit_deal_update(self): + self.op = operations.Credit_deal_update( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "account": "1.2.4", + "deal_id": "1.22.2356", + "auto_repay": 24, + "extensions": [], + } + ) + self.cm = ( + "f68585abf4dce7c80457014c00000000000000000004b41218" + "0000012026b59b7796cb9ca40d92b1d339558a94aa9f70d2f6" + "d8a7b8b0155c943b89bd602a1ecc9df3143664f801f401a728" + "78cce9f064dbcfc1af65826ce68a2177a38d" + ) + self.doit() + def compareConstructedTX(self): self.maxDiff = None self.op = operations.Call_order_update(