Skip to content

Commit

Permalink
Merge pull request #12 from geoffmunn/2.1.4-Osmosis-improvements
Browse files Browse the repository at this point in the history
2.1.4 osmosis improvements
  • Loading branch information
geoffmunn authored Jan 18, 2024
2 parents 477aeb4 + d4df6da commit 0be47f9
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
dist/.DS_Store
dist/.DS_Store
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ license = "MIT"
packages = [{ include = "terra_classic_sdk" }]
readme = "README.md"
repository = "https://github.com/terra-money/terra.py"
version = "2.1.3"
version = "2.1.4"

[tool.poetry.dependencies]
aiohttp = "^3.9.1"
Expand Down
26 changes: 25 additions & 1 deletion terra_classic_sdk/client/lcd/api/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ._base import BaseAsyncAPI, sync_bind

from terra_classic_sdk.client.lcd.params import PaginationOptions
from terra_classic_sdk.core.osmosis import Pool
from terra_classic_sdk.core.osmosis import Pool, PoolParams

__all__ = ["AsyncPoolAPI", "PoolAPI"]

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

return pool_details

async def osmosis_pool_params(self, pool_id: int) -> Pool:
"""Fetches the pool parameter details based on the pool ID.
This is specifically designed for Osmosis pools, and requires an Osmosis LCD to work.
Args:
pool_id (int): the pool id
Returns:
PoolParams: pool parameterinfo
"""

res = await self._c._get(f"osmosis/gamm/v1beta1/pools/{pool_id}/params")

# Load the result into a PoolParams object
param_details:PoolParams = PoolParams.from_data(res['pool'])

return param_details

async def osmosis_pools(self) -> list:
"""Fetches all the available pools.
This is specifically designed for Osmosis pools, and requires an Osmosis LCD to work.
Expand Down Expand Up @@ -69,6 +87,12 @@ def osmosis_pool(self, pool_id: int) -> Pool:

osmosis_pool.__doc__ = AsyncPoolAPI.osmosis_pool.__doc__

@sync_bind(AsyncPoolAPI.osmosis_pool_params)
def osmosis_pool_params(self, pool_id: int) -> Pool:
pass

osmosis_pool_params.__doc__ = AsyncPoolAPI.osmosis_pool_params.__doc__

@sync_bind(AsyncPoolAPI.osmosis_pools)
def osmosis_pools(self) -> list:
pass
Expand Down
3 changes: 1 addition & 2 deletions terra_classic_sdk/core/osmosis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
SwapAmountOutRoute
)

from .pools.pool import Pool
from terra_proto.osmosis.gamm.v1beta1 import PoolParams, PoolAsset
from terra_proto.osmosis.gamm.v1beta1 import Pool, PoolParams, PoolAsset

__all__ = [
"MsgJoinPool",
Expand Down
29 changes: 15 additions & 14 deletions terra_classic_sdk/core/osmosis/msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from terra_proto.osmosis.gamm.v1beta1 import MsgExitSwapShareAmountIn as MsgExitSwapShareAmountIn_pb

from terra_classic_sdk.core.osmosis.data import SwapAmountInRoute, SwapAmountOutRoute
from terra_classic_sdk.core import AccAddress, Coins, Coin
from terra_classic_sdk.core import AccAddress, Coin, Coins
from terra_classic_sdk.core.msg import Msg
from terra_classic_sdk.util.remove_none import remove_none

Expand Down Expand Up @@ -52,7 +52,7 @@ class MsgJoinPool(Msg):

type_amino = "osmosis/Msg/JoinPool"
""""""
type_url = "/osmosis.gamm.v1beta1.Msg/JoinPool"
type_url = "/osmosis.gamm.v1beta1.MsgJoinPool"
""""""
prototype = MsgJoinPool_pb
""""""
Expand Down Expand Up @@ -113,7 +113,7 @@ class MsgExitPool(Msg):

type_amino = "osmosis/Msg/JoinPool"
""""""
type_url = "/osmosis.gamm.v1beta1.Msg/ExitPool"
type_url = "/osmosis.gamm.v1beta1.MsgExitPool"
""""""
prototype = MsgExitPool_pb
""""""
Expand All @@ -130,7 +130,7 @@ def to_amino(self) -> dict:
"sender": self.sender,
"pool_id": self.pool_id,
"share_in_amount": self.share_in_amount(),
"coins": self.token_out_mins.to_amino(),
"token_out_mins": self.token_out_mins.to_amino(),
},
}

Expand All @@ -140,7 +140,7 @@ def from_data(cls, data: dict) -> MsgExitPool:
sender=data.get("sender"),
pool_id=data.get("pool_id"),
share_in_amount=data.get("share_in_amount"),
coins=Coins.from_data(data.get("funds")),
token_out_mins=Coins.from_data(data.get("token_out_mins"))
)

def to_proto(self) -> MsgExitPool_pb:
Expand Down Expand Up @@ -300,20 +300,20 @@ class MsgJoinSwapExternAmountIn(Msg):
sender: address of sender
pool_id: pool id
token_in: token to swap in
shares_out_min_amount: minimum amount of shares to swap out
share_out_min_amount: minimum amount of shares to swap out
"""

type_amino = "osmosis/JoinSwapExternAmountIn"
""""""
type_url = "/osmosis.gamm.v1beta1.Msg/JoinSwapExternAmountIn"
type_url = "/osmosis.gamm.v1beta1.MsgJoinSwapExternAmountIn"
""""""
prototype = MsgJoinSwapExternAmountIn_pb
""""""

sender: AccAddress = attr.ib()
pool_id: int = attr.ib()
token_in: Coin = attr.ib(converter=Coin)
shares_out_min_amount: str = attr.ib()
token_in: Coin = attr.ib()
share_out_min_amount: str = attr.ib()

def to_amino(self) -> dict:
return {
Expand All @@ -322,7 +322,7 @@ def to_amino(self) -> dict:
"sender": self.sender,
"pool_id": self.pool_id,
"token_in": self.token_in.to_amino(),
"shares_out_min_amount": self.shares_out_min_amount,
"share_out_min_amount": self.share_out_min_amount,
},
}

Expand All @@ -332,15 +332,16 @@ def from_data(cls, data: dict) -> MsgJoinSwapExternAmountIn:
sender=data["sender"],
pool_id=data["pool_id"],
token_in=Coin.from_data(data["token_in"]),
shares_out_min_amount=data["shares_out_min_amount"],
share_out_min_amount=data["share_out_min_amount"],
)

def to_proto(self) -> MsgJoinSwapExternAmountIn_pb:
token_coin:Coin = Coin(denom=self.token_in['denom'], amount=self.token_in['amount'])
return MsgJoinSwapExternAmountIn_pb(
sender=self.sender,
pool_id=self.pool_id,
token_in=self.token_in.to_proto(),
shares_out_min_amount=self.shares_out_min_amount,
token_in = token_coin.to_proto(),
share_out_min_amount=self.share_out_min_amount,
)

@classmethod
Expand All @@ -349,7 +350,7 @@ def from_proto(cls, proto: MsgJoinSwapExternAmountIn_pb) -> MsgJoinSwapExternAmo
sender=proto.sender,
pool_id=proto.pool_id,
token_in=Coin.from_proto(proto.token_in),
shares_out_min_amount=proto.shares_out_min_amount,
share_out_min_amount=proto.share_out_min_amount,
)


Expand Down
10 changes: 8 additions & 2 deletions terra_classic_sdk/util/parse_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
)

from terra_classic_sdk.core.osmosis import (
MsgSwapExactAmountIn
MsgExitPool,
MsgJoinPool,
MsgSwapExactAmountIn,
MsgJoinSwapExternAmountIn
)

bank_msgs = [MsgSend, MsgMultiSend]
Expand Down Expand Up @@ -135,7 +138,10 @@
]

osmosis_msgs = [
MsgSwapExactAmountIn
MsgExitPool,
MsgJoinPool,
MsgJoinSwapExternAmountIn,
MsgSwapExactAmountIn,
]

parse_msg = create_demux(
Expand Down

0 comments on commit 0be47f9

Please sign in to comment.