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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 1inch broken api - 403 error for cloud ip #189

Open
mraniki opened this issue May 9, 2023 · 1 comment
Open

馃悰 1inch broken api - 403 error for cloud ip #189

mraniki opened this issue May 9, 2023 · 1 comment
Labels
blocked dependencies Pull requests that update a dependency file

Comments

@mraniki
Copy link
Owner

mraniki commented May 9, 2023

https://discord.com/channels/730042542229422121/1100466859385561128

@mraniki mraniki added bug Something isn't working dependencies Pull requests that update a dependency file labels May 9, 2023
@mraniki
Copy link
Owner Author

mraniki commented May 15, 2023

Dropping 1inch code here until the 1inch issue is fully resolved:

1inch 馃

async def get_quote_1inch(
    self,
    asset_in_address,
    asset_out_address,
    amount=1
):
    try:
        asset_out_amount = self.w3.to_wei(amount, 'ether')
        quote_url = (
            settings.dex_1inch_url
            + str(self.chain_id)
            + "/quote?fromTokenAddress="
            + str(asset_in_address)
            + "&toTokenAddress="
            + str(asset_out_address)
            + "&amount="
            + str(asset_out_amount))
        quote_response = await self._get(
            url=quote_url,
            params=None,
            headers=settings.headers)
        self.logger.debug("quote_response %s", quote_response)
        if quote_response:
            quote_amount = quote_response['toTokenAmount']
            self.logger.debug("quote_amount %s", quote_amount)
            # quote_decimals = quote_response['fromToken']['decimals']
            quote = self.w3.from_wei(int(quote_amount), 'ether')
            # /(10 ** quote_decimals))
            return round(quote, 2)
    except Exception as e:
        self.logger.error("get_quote_1inch %s", e)

async def get_approve_1inch(self, asset_out_address):
    try:
        approval_check_URL = (
            settings.dex_1inch_url
            + str(self.chain_id)
            + "/approve/allowance?tokenAddress="
            + str(asset_out_address)
            + "&walletAddress="
            + str(self.wallet_address))
        approval_response = await self._get(
            url=approval_check_URL,
            params=None,
            headers=settings.headers)
        approval_check = approval_response['allowance']
        if (approval_check == 0):
            approval_URL = (
                settings.dex_1inch_url
                + str(self.chain_id)
                + "/approve/transaction?tokenAddress="
                + str(asset_out_address))
            approval_response = await self._get(approval_URL)
            return approval_response
    except Exception as e:
        self.logger.error("get_approve_1inch %s", e)
        return None

async def get_swap_1inch(
    self,
    asset_out_address,
    asset_in_address,
    amount
):
    swap_url = (
        settings.dex_1inch_url
        + str(self.chain_id)
        + "/swap?fromTokenAddress="
        + asset_out_address
        + "&toTokenAddress="
        + asset_in_address
        + "&amount="
        + amount
        + "&fromAddress="
        + self.wallet_address
        + "&slippage="
        + settings.dex_trading_slippage
        )
    swap_order = await self._get(
        url=swap_url,
        params=None,
        headers=settings.headers
        )
    swap_order_status = swap_order['statusCode']
    if swap_order_status != 200:
        return
    return swap_order

@mraniki mraniki added blocked and removed bug Something isn't working labels Aug 8, 2023
@mraniki mraniki changed the title 1inch 403 error for cloud ip 馃悰 1inch 403 error for cloud ip Aug 8, 2023
@mraniki mraniki changed the title 馃悰 1inch 403 error for cloud ip 馃悰 1inch broken api - 403 error for cloud ip Aug 8, 2023
@mraniki mraniki mentioned this issue Aug 17, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked dependencies Pull requests that update a dependency file
Projects
Status: No status
Development

No branches or pull requests

1 participant