Skip to content

Commit 0be47f9

Browse files
authored
Merge pull request #12 from geoffmunn/2.1.4-Osmosis-improvements
2.1.4 osmosis improvements
2 parents 477aeb4 + d4df6da commit 0be47f9

File tree

6 files changed

+52
-20
lines changed

6 files changed

+52
-20
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.DS_Store
2+
dist/.DS_Store
3+
dist/.DS_Store

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ license = "MIT"
1919
packages = [{ include = "terra_classic_sdk" }]
2020
readme = "README.md"
2121
repository = "https://github.com/terra-money/terra.py"
22-
version = "2.1.3"
22+
version = "2.1.4"
2323

2424
[tool.poetry.dependencies]
2525
aiohttp = "^3.9.1"

Diff for: terra_classic_sdk/client/lcd/api/pool.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from ._base import BaseAsyncAPI, sync_bind
44

55
from terra_classic_sdk.client.lcd.params import PaginationOptions
6-
from terra_classic_sdk.core.osmosis import Pool
6+
from terra_classic_sdk.core.osmosis import Pool, PoolParams
77

88
__all__ = ["AsyncPoolAPI", "PoolAPI"]
99

@@ -26,6 +26,24 @@ async def osmosis_pool(self, pool_id: int) -> Pool:
2626

2727
return pool_details
2828

29+
async def osmosis_pool_params(self, pool_id: int) -> Pool:
30+
"""Fetches the pool parameter details based on the pool ID.
31+
This is specifically designed for Osmosis pools, and requires an Osmosis LCD to work.
32+
33+
Args:
34+
pool_id (int): the pool id
35+
36+
Returns:
37+
PoolParams: pool parameterinfo
38+
"""
39+
40+
res = await self._c._get(f"osmosis/gamm/v1beta1/pools/{pool_id}/params")
41+
42+
# Load the result into a PoolParams object
43+
param_details:PoolParams = PoolParams.from_data(res['pool'])
44+
45+
return param_details
46+
2947
async def osmosis_pools(self) -> list:
3048
"""Fetches all the available pools.
3149
This is specifically designed for Osmosis pools, and requires an Osmosis LCD to work.
@@ -69,6 +87,12 @@ def osmosis_pool(self, pool_id: int) -> Pool:
6987

7088
osmosis_pool.__doc__ = AsyncPoolAPI.osmosis_pool.__doc__
7189

90+
@sync_bind(AsyncPoolAPI.osmosis_pool_params)
91+
def osmosis_pool_params(self, pool_id: int) -> Pool:
92+
pass
93+
94+
osmosis_pool_params.__doc__ = AsyncPoolAPI.osmosis_pool_params.__doc__
95+
7296
@sync_bind(AsyncPoolAPI.osmosis_pools)
7397
def osmosis_pools(self) -> list:
7498
pass

Diff for: terra_classic_sdk/core/osmosis/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
SwapAmountOutRoute
1717
)
1818

19-
from .pools.pool import Pool
20-
from terra_proto.osmosis.gamm.v1beta1 import PoolParams, PoolAsset
19+
from terra_proto.osmosis.gamm.v1beta1 import Pool, PoolParams, PoolAsset
2120

2221
__all__ = [
2322
"MsgJoinPool",

Diff for: terra_classic_sdk/core/osmosis/msgs.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from terra_proto.osmosis.gamm.v1beta1 import MsgExitSwapShareAmountIn as MsgExitSwapShareAmountIn_pb
2020

2121
from terra_classic_sdk.core.osmosis.data import SwapAmountInRoute, SwapAmountOutRoute
22-
from terra_classic_sdk.core import AccAddress, Coins, Coin
22+
from terra_classic_sdk.core import AccAddress, Coin, Coins
2323
from terra_classic_sdk.core.msg import Msg
2424
from terra_classic_sdk.util.remove_none import remove_none
2525

@@ -52,7 +52,7 @@ class MsgJoinPool(Msg):
5252

5353
type_amino = "osmosis/Msg/JoinPool"
5454
""""""
55-
type_url = "/osmosis.gamm.v1beta1.Msg/JoinPool"
55+
type_url = "/osmosis.gamm.v1beta1.MsgJoinPool"
5656
""""""
5757
prototype = MsgJoinPool_pb
5858
""""""
@@ -113,7 +113,7 @@ class MsgExitPool(Msg):
113113

114114
type_amino = "osmosis/Msg/JoinPool"
115115
""""""
116-
type_url = "/osmosis.gamm.v1beta1.Msg/ExitPool"
116+
type_url = "/osmosis.gamm.v1beta1.MsgExitPool"
117117
""""""
118118
prototype = MsgExitPool_pb
119119
""""""
@@ -130,7 +130,7 @@ def to_amino(self) -> dict:
130130
"sender": self.sender,
131131
"pool_id": self.pool_id,
132132
"share_in_amount": self.share_in_amount(),
133-
"coins": self.token_out_mins.to_amino(),
133+
"token_out_mins": self.token_out_mins.to_amino(),
134134
},
135135
}
136136

@@ -140,7 +140,7 @@ def from_data(cls, data: dict) -> MsgExitPool:
140140
sender=data.get("sender"),
141141
pool_id=data.get("pool_id"),
142142
share_in_amount=data.get("share_in_amount"),
143-
coins=Coins.from_data(data.get("funds")),
143+
token_out_mins=Coins.from_data(data.get("token_out_mins"))
144144
)
145145

146146
def to_proto(self) -> MsgExitPool_pb:
@@ -300,20 +300,20 @@ class MsgJoinSwapExternAmountIn(Msg):
300300
sender: address of sender
301301
pool_id: pool id
302302
token_in: token to swap in
303-
shares_out_min_amount: minimum amount of shares to swap out
303+
share_out_min_amount: minimum amount of shares to swap out
304304
"""
305305

306306
type_amino = "osmosis/JoinSwapExternAmountIn"
307307
""""""
308-
type_url = "/osmosis.gamm.v1beta1.Msg/JoinSwapExternAmountIn"
308+
type_url = "/osmosis.gamm.v1beta1.MsgJoinSwapExternAmountIn"
309309
""""""
310310
prototype = MsgJoinSwapExternAmountIn_pb
311311
""""""
312312

313313
sender: AccAddress = attr.ib()
314314
pool_id: int = attr.ib()
315-
token_in: Coin = attr.ib(converter=Coin)
316-
shares_out_min_amount: str = attr.ib()
315+
token_in: Coin = attr.ib()
316+
share_out_min_amount: str = attr.ib()
317317

318318
def to_amino(self) -> dict:
319319
return {
@@ -322,7 +322,7 @@ def to_amino(self) -> dict:
322322
"sender": self.sender,
323323
"pool_id": self.pool_id,
324324
"token_in": self.token_in.to_amino(),
325-
"shares_out_min_amount": self.shares_out_min_amount,
325+
"share_out_min_amount": self.share_out_min_amount,
326326
},
327327
}
328328

@@ -332,15 +332,16 @@ def from_data(cls, data: dict) -> MsgJoinSwapExternAmountIn:
332332
sender=data["sender"],
333333
pool_id=data["pool_id"],
334334
token_in=Coin.from_data(data["token_in"]),
335-
shares_out_min_amount=data["shares_out_min_amount"],
335+
share_out_min_amount=data["share_out_min_amount"],
336336
)
337337

338338
def to_proto(self) -> MsgJoinSwapExternAmountIn_pb:
339+
token_coin:Coin = Coin(denom=self.token_in['denom'], amount=self.token_in['amount'])
339340
return MsgJoinSwapExternAmountIn_pb(
340341
sender=self.sender,
341342
pool_id=self.pool_id,
342-
token_in=self.token_in.to_proto(),
343-
shares_out_min_amount=self.shares_out_min_amount,
343+
token_in = token_coin.to_proto(),
344+
share_out_min_amount=self.share_out_min_amount,
344345
)
345346

346347
@classmethod
@@ -349,7 +350,7 @@ def from_proto(cls, proto: MsgJoinSwapExternAmountIn_pb) -> MsgJoinSwapExternAmo
349350
sender=proto.sender,
350351
pool_id=proto.pool_id,
351352
token_in=Coin.from_proto(proto.token_in),
352-
shares_out_min_amount=proto.shares_out_min_amount,
353+
share_out_min_amount=proto.share_out_min_amount,
353354
)
354355

355356

Diff for: terra_classic_sdk/util/parse_msg.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
)
6767

6868
from terra_classic_sdk.core.osmosis import (
69-
MsgSwapExactAmountIn
69+
MsgExitPool,
70+
MsgJoinPool,
71+
MsgSwapExactAmountIn,
72+
MsgJoinSwapExternAmountIn
7073
)
7174

7275
bank_msgs = [MsgSend, MsgMultiSend]
@@ -135,7 +138,10 @@
135138
]
136139

137140
osmosis_msgs = [
138-
MsgSwapExactAmountIn
141+
MsgExitPool,
142+
MsgJoinPool,
143+
MsgJoinSwapExternAmountIn,
144+
MsgSwapExactAmountIn,
139145
]
140146

141147
parse_msg = create_demux(

0 commit comments

Comments
 (0)