-
Notifications
You must be signed in to change notification settings - Fork 5
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
add swap and fix donate #72
Changes from 1 commit
08d3d50
9abd3c4
4e02064
31ff9ae
5d33d59
56cd466
5404b97
1e2603e
aafd807
b9bbeb5
cb1e9aa
c4b8201
4e85141
e24a890
2fb34b3
b3ad4e1
72e8905
cf67b5d
f7cfdcf
09dbb70
4ee4e32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { AlphaRouter, SwapRoute, V3Route } from '@uniswap/smart-order-router'; | ||
import { AlphaRouter, SwapRoute, SwapType, V3Route } from '@uniswap/smart-order-router'; | ||
import { CurrencyAmount, Percent, TradeType } from '@uniswap/sdk-core'; | ||
import { useAccount, useNetwork } from 'wagmi'; | ||
import { GDToken } from '../models/constants'; | ||
|
@@ -55,14 +55,12 @@ export function useSwapRoute( | |
inputAmount, | ||
GDToken, | ||
TradeType.EXACT_INPUT, | ||
// TODO: use SwapConfig when https://github.com/Uniswap/sdk-core/issues/20 is resolved by https://github.com/Uniswap/sdk-core/pull/69 | ||
// { | ||
// type: SwapType.SWAP_ROUTER_02, | ||
// recipient: address, | ||
// slippageTolerance: slippageTolerance, | ||
// deadline: Math.floor(Date.now() / 1000 + 1800), | ||
// }, | ||
undefined, | ||
{ | ||
type: SwapType.SWAP_ROUTER_02, | ||
recipient: address, | ||
slippageTolerance: slippageTolerance, | ||
deadline: Math.floor(Date.now() / 1000 + 1800), | ||
}, | ||
{ | ||
protocols: [Protocol.V3], | ||
} | ||
|
@@ -76,16 +74,14 @@ export function useSwapRoute( | |
}); | ||
}, [address, chain?.id, signer?.provider, tokenIn, decimalAmountIn, duration, slippageTolerance]); | ||
|
||
if (!route) { | ||
if (!route || !route.methodParameters) { | ||
return { status: SwapRouteState.NO_ROUTE }; | ||
} else { | ||
// This typecast is safe because Uniswap v2 is not deployed on Celo | ||
const path = encodeRouteToPath(route.route[0].route as V3Route, false); | ||
const quote = new Decimal(route.quote.toFixed(18)); | ||
// TODO: use commented out values when https://github.com/Uniswap/sdk-core/issues/20 is resolved by https://github.com/Uniswap/sdk-core/pull/69 | ||
const rawMinimumAmountOut = | ||
route.quoteGasAndPortionAdjusted?.numerator.toString() ?? route.quoteGasAdjusted.numerator.toString(); // route.trade.minimumAmountOut(slippageTolerance).numerator.toString(); | ||
const priceImpact = new Decimal(0.005); // new Decimal(route.trade.priceImpact.toFixed(4)); | ||
const rawMinimumAmountOut = route.trade.minimumAmountOut(slippageTolerance).numerator.toString(); | ||
const priceImpact = new Decimal(route.trade.priceImpact.toFixed(4)); | ||
return { path, quote, rawMinimumAmountOut, priceImpact, status: SwapRouteState.READY }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is price impact converted here? to Decimal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was so it could be compared to a number, and also to remove trailing zeroes. It could be |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think 5%.
What does the UI specifications says? is there an alert?
@patpedrosa @decentralauren
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the example says 36%, but i don't think that's intended as the cutoff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to 5% for now, and also moved it to
models/constants.ts
so it is easier to find if you want to change it later