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

Fix: when exact out quote swaping gets bigInt error #334

Conversation

Diogomartf
Copy link
Contributor

@Diogomartf Diogomartf commented Jan 11, 2024

fee param on SwaprV3 needs to be uint24 type so it needed conversion.

  • improve tokens names
    • setToken (the token you set on swapbox for eg)
    • quoteToken (the token you want a quote for)
  • improve test spec
    • new test case for covering this issue

Copy link
Collaborator

@berteotti berteotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvements look good, left a few comments to improve a bit more.

src/entities/trades/swapr-v3/SwaprV3.ts Outdated Show resolved Hide resolved
const routerContract = getRouterContract()

// Swapr Algebra Contract fee param is uint24 type
const algebraFee = parseFloat(this.fee.multiply(JSBI.BigInt(1_000_000)).toFixed(1))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's turn this into a const, like

const ALGEBRA_FEE_PARTS_PER_MILLION = JSBI.BigInt(1_000_000)

or just PARTS_PER_MILLION or MILLION or _1_000_000 or _1000000

and use it here.

We have similar constants inside /constants folder, like _10000. Maybe we can create a new one there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's simplify this logic. I read .toSignificant() and .toFixed() code and we can use this:

Suggested change
const algebraFee = parseFloat(this.fee.multiply(JSBI.BigInt(1_000_000)).toFixed(1))
const algebraFee = this.fee.multiply(ALGEBRA_FEE_PARTS_PER_MILLION).toSignificant(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can turn it into a const, but I'll rather have it here next to where it's used.

)

const routes = await getRoutes(tokenIn, tokenOut, chainId)
const routes = await getRoutes(setToken, quoteToken, chainId)

const fee =
routes?.length > 0 && routes[0].pools.length > 0
? new Percent(routes[0].pools[0].fee.toString(), '1000000')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also use ALGEBRA_FEE_PARTS_PER_MILLION here, instead of '1000000'.

Copy link
Contributor Author

@Diogomartf Diogomartf Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const ALGEBRA_FEE_PARTS_PER_MILLION = JSBI.BigInt(1_000_000)

this is different then "1000000"

@Diogomartf Diogomartf force-pushed the swa-136-fix-when-exact-out-change-the-token1-quote-you-confirm-swap branch from 2c81617 to 128a29d Compare January 12, 2024 14:28

// Swapr Algebra Contract fee param is uint24 type
const algebraFee = this.fee.multiply(ALGEBRA_FEE_PARTS_PER_MILLION).toSignificant(1)
console.log('algebraFee:', algebraFee)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undesired console.log('algebraFee:', algebraFee)

Copy link
Collaborator

@berteotti berteotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good after removing console.log

@Diogomartf Diogomartf force-pushed the swa-136-fix-when-exact-out-change-the-token1-quote-you-confirm-swap branch from 128a29d to 61d55a3 Compare January 12, 2024 15:28
@Diogomartf Diogomartf merged commit f207c04 into develop Jan 12, 2024
1 check failed
berteotti pushed a commit that referenced this pull request Feb 1, 2024
* improve error message

* fee param on SwaprV3 needs to be uint24 type so it needed conversion.
- improve tokens names
- improve test spec

* small improvements
ElRodrigote pushed a commit that referenced this pull request Feb 1, 2024
* improve error message

* fee param on SwaprV3 needs to be uint24 type so it needed conversion.
- improve tokens names
- improve test spec

* small improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants