-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from skip-mev/v0.2.x
✨ Add support for wyndex pools and routers, update burn fees for Hopers
- Loading branch information
Showing
17 changed files
with
2,130 additions
and
246 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from dataclasses import dataclass | ||
from src.contract.pool.pools.terraswap import Terraswap | ||
from src.querier.queriers.cosmwasm import CosmWasmQuerier | ||
from src.contract.pool.pool import Pool | ||
from src.transaction import Swap | ||
|
||
from cosmpy.aerial.contract import create_cosmwasm_execute_msg | ||
from cosmpy.protos.cosmos.base.v1beta1.coin_pb2 import Coin | ||
from cosmpy.protos.cosmwasm.wasm.v1.tx_pb2 import MsgExecuteContract | ||
|
||
|
||
@dataclass | ||
class Wyndex(Terraswap): | ||
DEFAULT_LP_FEE: float = 0.002 | ||
DEFAULT_PROTOCOL_FEE: float = 0.001 | ||
DEFAULT_FEE_FROM_INPUT: float = False | ||
|
||
async def update_tokens(self, | ||
querier: CosmWasmQuerier) -> None: | ||
""" Update the tokens in the pool.""" | ||
payload = self.get_query_tokens_payload( | ||
contract_address=self.contract_address, | ||
querier=querier) | ||
pool_info = await querier.query_node_and_return_response( | ||
payload=payload, | ||
decoded=True | ||
) | ||
self.token1_type = list(pool_info['assets'][0]['info'].keys())[0] | ||
if self.token1_type == "token": | ||
self.token1_denom = pool_info['assets'][0]['info'][self.token1_type] | ||
elif self.token1_type == "native": | ||
self.token1_denom = pool_info['assets'][0]['info'][self.token1_type] | ||
|
||
self.token2_type = list(pool_info['assets'][1]['info'].keys())[0] | ||
if self.token2_type == "token": | ||
self.token2_denom = pool_info['assets'][1]['info'][self.token2_type] | ||
elif self.token2_type == "native": | ||
self.token2_denom = pool_info['assets'][1]['info'][self.token2_type] | ||
|
||
def get_swaps_from_message(self, | ||
msg, | ||
message_value, | ||
contracts: dict[str, Pool] = {}) -> list[Swap]: | ||
""" Return list of Swaps from the message. | ||
Expects that the pool object has already been chosen for send messages. | ||
See: get_relevant_contract method in cosmwasm decoder. | ||
""" | ||
if "swap" in msg: | ||
input_denom = msg['swap']['offer_asset']['info']['native'] | ||
return [Swap(sender=message_value.sender, | ||
contract_address=self.contract_address, | ||
input_denom=input_denom, | ||
input_amount=int(msg['swap']['offer_asset']['amount']), | ||
output_denom=self.get_other_denom(input_denom))] | ||
elif "send" in msg: | ||
input_denom=message_value.contract | ||
return [Swap(sender=message_value.sender, | ||
contract_address=self.contract_address, | ||
input_denom=input_denom, | ||
input_amount=int(msg['send']['amount']), | ||
output_denom=self.get_other_denom(input_denom))] | ||
else: | ||
return [] | ||
|
||
def _get_swap_msg(self, | ||
address: str, | ||
input_amount: int) -> MsgExecuteContract: | ||
""" Creates a MsgExecuteContract for JunoSwap's swap function.""" | ||
msg = create_cosmwasm_execute_msg( | ||
sender_address=address, | ||
contract_address=self.contract_address, | ||
args={"swap": { | ||
"offer_asset": { | ||
"amount": str(input_amount), | ||
"info": { | ||
"native": self.input_denom | ||
}}}} | ||
) | ||
msg.funds.append(Coin(amount=str(input_amount), | ||
denom=self.input_denom)) | ||
|
||
return msg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from src.contract.router.router import Router | ||
from src.contract.router.routers import TerraswapRouter, AstroportRouter, PhoenixRouter, WhiteWhaleRouter | ||
from src.contract.router.routers import TerraswapRouter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
from .terraswap import TerraswapRouter | ||
from .astroport import AstroportRouter | ||
from .phoenix import PhoenixRouter | ||
from .whitewhale import WhiteWhaleRouter | ||
from .terraswap import TerraswapRouter |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,60 @@ | ||
from dataclasses import dataclass | ||
import json | ||
from base64 import b64decode | ||
from dataclasses import dataclass, InitVar | ||
from src.contract.pool.pool import Pool | ||
|
||
from src.contract.router.router import Router | ||
from src.swap import Swap | ||
|
||
|
||
@dataclass | ||
class TerraswapRouter(Router): | ||
contracts: InitVar[dict] | ||
|
||
def __post_init__(self, contracts: dict): | ||
""" Loads the ABI for the contract, and creates a contract object.""" | ||
|
||
router_pools: dict[str, Pool] = {address: contracts[address] | ||
for address | ||
in contracts | ||
if contracts[address].protocol == self.protocol | ||
and isinstance(contracts[address], Pool) | ||
} | ||
|
||
self.pair_pool_mapping = {self._sort_and_combine_strings(pool.token1_denom, pool.token2_denom): pool.contract_address | ||
for pool | ||
in router_pools.values() | ||
} | ||
|
||
def get_swaps_from_message(self, | ||
msg, | ||
message_value, | ||
contracts: dict) -> list[Swap]: | ||
pass | ||
swaps = [] | ||
|
||
if "execute_swap_operations" in msg: | ||
operations = msg["execute_swap_operations"]["operations"] | ||
first_input_amount = int(message_value.funds[0].amount) if message_value.funds else 0 | ||
elif "send" in msg: | ||
operations_msg = json.loads(b64decode(msg['send']['msg']).decode('utf-8')) | ||
first_input_amount = int(msg["send"]["amount"]) | ||
if "execute_swap_operations" in operations_msg: | ||
operations = operations_msg["execute_swap_operations"]["operations"] | ||
else: | ||
return swaps | ||
|
||
for index, operation in enumerate(operations): | ||
input_amount = first_input_amount if index == 0 else 0 | ||
swap_info = list(operation.values())[0] | ||
input_denom = list(swap_info['offer_asset_info'].values())[0] | ||
output_denom = list(swap_info['ask_asset_info'].values())[0] | ||
contract_address = self.pair_pool_mapping[self._sort_and_combine_strings(input_denom, output_denom)] | ||
swaps.append( | ||
Swap(sender=message_value.sender, | ||
contract_address=contract_address, | ||
input_denom=input_denom, | ||
input_amount=input_amount, | ||
output_denom=output_denom) | ||
) | ||
|
||
return swaps |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.