Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make v1 pool refresh optional, same as v2 pools. #59

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions tinyman/v1/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,12 @@ def convert(self, amount: AssetAmount):
return AssetAmount(self.asset1, int(amount.amount * self.asset2_price))

def fetch_mint_quote(
self, amount_a: AssetAmount, amount_b: AssetAmount = None, slippage=0.05
self, amount_a: AssetAmount, amount_b: AssetAmount = None, slippage=0.05, refresh=True
gokselcoban marked this conversation as resolved.
Show resolved Hide resolved
):
amount1 = amount_a if amount_a.asset == self.asset1 else amount_b
amount2 = amount_a if amount_a.asset == self.asset2 else amount_b
self.refresh()
if refresh:
self.refresh()
if not self.exists:
raise Exception("Pool has not been bootstrapped yet!")
if self.issued_liquidity:
Expand Down Expand Up @@ -322,10 +323,11 @@ def fetch_mint_quote(
)
return quote

def fetch_burn_quote(self, liquidity_asset_in, slippage=0.05):
def fetch_burn_quote(self, liquidity_asset_in, slippage=0.05, refresh=True):
if isinstance(liquidity_asset_in, int):
liquidity_asset_in = AssetAmount(self.liquidity_asset, liquidity_asset_in)
self.refresh()
if refresh:
self.refresh()
asset1_amount = (
liquidity_asset_in.amount * self.asset1_reserves
) / self.issued_liquidity
Expand All @@ -344,10 +346,11 @@ def fetch_burn_quote(self, liquidity_asset_in, slippage=0.05):
return quote

def fetch_fixed_input_swap_quote(
self, amount_in: AssetAmount, slippage=0.05
self, amount_in: AssetAmount, slippage=0.05, refresh=True
) -> SwapQuote:
asset_in, asset_in_amount = amount_in.asset, amount_in.amount
self.refresh()
if refresh:
self.refresh()
if asset_in == self.asset1:
asset_out = self.asset2
input_supply = self.asset1_reserves
Expand Down Expand Up @@ -390,10 +393,11 @@ def fetch_fixed_input_swap_quote(
return quote

def fetch_fixed_output_swap_quote(
self, amount_out: AssetAmount, slippage=0.05
self, amount_out: AssetAmount, slippage=0.05, refresh=True
) -> SwapQuote:
asset_out, asset_out_amount = amount_out.asset, amount_out.amount
self.refresh()
if refresh:
self.refresh()
if asset_out == self.asset1:
asset_in = self.asset2
input_supply = self.asset2_reserves
Expand Down